kalarm
templatepickdlg.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kalarm.h"
00022
00023 #include <QVBoxLayout>
00024 #include <QResizeEvent>
00025
00026 #include <klocale.h>
00027 #include <kdebug.h>
00028
00029 #include "eventlistmodel.h"
00030 #include "functions.h"
00031 #include "shellprocess.h"
00032 #include "templatelistfiltermodel.h"
00033 #include "templatelistview.h"
00034 #include "templatepickdlg.moc"
00035
00036 static const char TMPL_PICK_DIALOG_NAME[] = "TemplatePickDialog";
00037
00038
00039 TemplatePickDlg::TemplatePickDlg(QWidget* parent)
00040 : KDialog(parent)
00041 {
00042 QWidget* topWidget = new QWidget(this);
00043 setMainWidget(topWidget);
00044 setCaption(i18nc("@title:window", "Choose Alarm Template"));
00045 setButtons(Ok|Cancel);
00046 setDefaultButton(Ok);
00047 QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
00048 topLayout->setMargin(0);
00049 topLayout->setSpacing(spacingHint());
00050
00051
00052 bool includeCmdAlarms = ShellProcess::authorised();
00053 mListFilterModel = new TemplateListFilterModel(EventListModel::templates());
00054 mListFilterModel->setTypeFilter(!includeCmdAlarms);
00055 mListView = new TemplateListView(topWidget);
00056 mListView->setModel(mListFilterModel);
00057 mListView->sortByColumn(TemplateListFilterModel::TemplateNameColumn, Qt::AscendingOrder);
00058 mListView->setSelectionMode(QAbstractItemView::SingleSelection);
00059 mListView->setWhatsThis(i18nc("@info:whatsthis", "Select a template to base the new alarm on."));
00060 connect(mListView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), SLOT(slotSelectionChanged()));
00061
00062 connect(mListView, SIGNAL(doubleClicked(const QModelIndex&)), SLOT(accept()));
00063 topLayout->addWidget(mListView);
00064
00065 slotSelectionChanged();
00066
00067 QSize s;
00068 if (KAlarm::readConfigWindowSize(TMPL_PICK_DIALOG_NAME, s))
00069 resize(s);
00070 }
00071
00072
00073
00074
00075 const KAEvent* TemplatePickDlg::selectedTemplate() const
00076 {
00077 return mListView->selectedEvent();
00078 }
00079
00080
00081
00082
00083
00084 void TemplatePickDlg::slotSelectionChanged()
00085 {
00086 enableButtonOk(!mListView->selectionModel()->selectedRows().isEmpty());
00087 }
00088
00089
00090
00091
00092
00093 void TemplatePickDlg::resizeEvent(QResizeEvent* re)
00094 {
00095 if (isVisible())
00096 KAlarm::writeConfigWindowSize(TMPL_PICK_DIALOG_NAME, re->size());
00097 KDialog::resizeEvent(re);
00098 }