• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm

  • sources
  • kde-4.14
  • kdepim
  • kalarm
templatepickdlg.cpp
Go to the documentation of this file.
1 /*
2  * templatepickdlg.cpp - dialog to choose an alarm template
3  * Program: kalarm
4  * Copyright © 2004,2006-2010 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h"
22 #include "templatepickdlg.h"
23 
24 #ifndef USE_AKONADI
25 #include "eventlistmodel.h"
26 #include "templatelistfiltermodel.h"
27 #endif
28 #include "functions.h"
29 #include "shellprocess.h"
30 #include "templatelistview.h"
31 
32 #include <klocale.h>
33 #include <kdebug.h>
34 
35 #include <QVBoxLayout>
36 #include <QResizeEvent>
37 
38 static const char TMPL_PICK_DIALOG_NAME[] = "TemplatePickDialog";
39 
40 
41 TemplatePickDlg::TemplatePickDlg(KAEvent::Actions type, QWidget* parent)
42  : KDialog(parent)
43 {
44  QWidget* topWidget = new QWidget(this);
45  setMainWidget(topWidget);
46  setCaption(i18nc("@title:window", "Choose Alarm Template"));
47  setButtons(Ok|Cancel);
48  setDefaultButton(Ok);
49  QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
50  topLayout->setMargin(0);
51  topLayout->setSpacing(spacingHint());
52 
53  // Display the list of templates, but exclude command alarms if in kiosk mode.
54  KAEvent::Actions shown = KAEvent::ACT_ALL;
55  if (!ShellProcess::authorised())
56  {
57  type = static_cast<KAEvent::Actions>(type & ~KAEvent::ACT_COMMAND);
58  shown = static_cast<KAEvent::Actions>(shown & ~KAEvent::ACT_COMMAND);
59  }
60 #ifdef USE_AKONADI
61  mListFilterModel = new TemplateListModel(this);
62  mListFilterModel->setAlarmActionsEnabled(type);
63  mListFilterModel->setAlarmActionFilter(shown);
64 #else
65  mListFilterModel = new TemplateListFilterModel(EventListModel::templates());
66  mListFilterModel->setTypesEnabled(type);
67  mListFilterModel->setTypeFilter(shown);
68 #endif
69  mListView = new TemplateListView(topWidget);
70  mListView->setModel(mListFilterModel);
71 #ifdef USE_AKONADI
72  mListView->sortByColumn(TemplateListModel::TemplateNameColumn, Qt::AscendingOrder);
73 #else
74  mListView->sortByColumn(TemplateListFilterModel::TemplateNameColumn, Qt::AscendingOrder);
75 #endif
76  mListView->setSelectionMode(QAbstractItemView::SingleSelection);
77  mListView->setWhatsThis(i18nc("@info:whatsthis", "Select a template to base the new alarm on."));
78  connect(mListView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(slotSelectionChanged()));
79  // Require a real double click (even if KDE is in single-click mode) to accept the selection
80  connect(mListView, SIGNAL(doubleClicked(QModelIndex)), SLOT(accept()));
81  topLayout->addWidget(mListView);
82 
83  slotSelectionChanged(); // enable or disable the OK button
84 
85  QSize s;
86  if (KAlarm::readConfigWindowSize(TMPL_PICK_DIALOG_NAME, s))
87  resize(s);
88 }
89 
90 /******************************************************************************
91 * Return the currently selected alarm template, or 0 if none.
92 */
93 #ifdef USE_AKONADI
94 KAEvent TemplatePickDlg::selectedTemplate() const
95 #else
96 const KAEvent* TemplatePickDlg::selectedTemplate() const
97 #endif
98 {
99  return mListView->selectedEvent();
100 }
101 
102 /******************************************************************************
103 * Called when the template selection changes.
104 * Enable/disable the OK button depending on whether anything is selected.
105 */
106 void TemplatePickDlg::slotSelectionChanged()
107 {
108  bool enable = !mListView->selectionModel()->selectedRows().isEmpty();
109  if (enable)
110  enable = mListView->model()->flags(mListView->selectedIndex()) & Qt::ItemIsEnabled;
111  enableButtonOk(enable);
112 }
113 
114 /******************************************************************************
115 * Called when the dialog's size has changed.
116 * Records the new size in the config file.
117 */
118 void TemplatePickDlg::resizeEvent(QResizeEvent* re)
119 {
120  if (isVisible())
121  KAlarm::writeConfigWindowSize(TMPL_PICK_DIALOG_NAME, re->size());
122  KDialog::resizeEvent(re);
123 }
124 
125 #include "moc_templatepickdlg.cpp"
126 // vim: et sw=4:
QModelIndex
QResizeEvent
TemplateListView::setModel
virtual void setModel(QAbstractItemModel *)
Definition: templatelistview.cpp:46
QWidget
QAbstractItemView::setSelectionMode
void setSelectionMode(QAbstractItemView::SelectionMode mode)
TemplateListFilterModel::TemplateNameColumn
Definition: templatelistfiltermodel.h:34
QAbstractItemView::selectionModel
QItemSelectionModel * selectionModel() const
templatelistfiltermodel.h
ShellProcess::authorised
static bool authorised()
TMPL_PICK_DIALOG_NAME
static const char TMPL_PICK_DIALOG_NAME[]
Definition: templatepickdlg.cpp:38
KDialog
QTreeView::sortByColumn
void sortByColumn(int column, Qt::SortOrder order)
TemplateListModel
Definition: itemlistmodel.h:133
TemplateListFilterModel::setTypeFilter
void setTypeFilter(KAEvent::Actions)
Definition: templatelistfiltermodel.cpp:34
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
TemplateListView
Definition: templatelistview.h:29
templatepickdlg.h
QItemSelectionModel::selectedRows
QModelIndexList selectedRows(int column) const
TemplatePickDlg::TemplatePickDlg
TemplatePickDlg(KAEvent::Actions, QWidget *parent=0)
Definition: templatepickdlg.cpp:41
eventlistmodel.h
QVBoxLayout
TemplateListModel::TemplateNameColumn
Definition: itemlistmodel.h:138
QLayout::setMargin
void setMargin(int margin)
TemplatePickDlg::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: templatepickdlg.cpp:118
QResizeEvent::size
const QSize & size() const
QSize
EventListModel::templates
static EventListModel * templates()
Definition: eventlistmodel.cpp:68
QItemSelection
EventListView::selectedIndex
QModelIndex selectedIndex() const
Definition: eventlistview.cpp:110
QWidget::setWhatsThis
void setWhatsThis(const QString &)
TemplatePickDlg::selectedTemplate
const KAEvent * selectedTemplate() const
Definition: templatepickdlg.cpp:96
functions.h
miscellaneous functions
kalarm.h
TemplateListFilterModel::setTypesEnabled
void setTypesEnabled(KAEvent::Actions)
Definition: templatelistfiltermodel.cpp:43
QAbstractItemModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
shellprocess.h
TemplateListFilterModel
Definition: templatelistfiltermodel.h:29
QAbstractItemView::model
QAbstractItemModel * model() const
QBoxLayout::setSpacing
void setSpacing(int spacing)
templatelistview.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal