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

kalarm

  • sources
  • kde-4.12
  • kdepim
  • kalarm
timeselector.cpp
Go to the documentation of this file.
1 /*
2  * timeselector.cpp - widget to optionally set a time period
3  * Program: kalarm
4  * Copyright © 2004,2005,2007,2009-2011 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 
23 #include "checkbox.h"
24 #include "combobox.h"
25 #include "timeselector.moc"
26 
27 #include <klocale.h>
28 #include <kdialog.h>
29 #include <khbox.h>
30 #include <kdebug.h>
31 
32 #include <QVBoxLayout>
33 #include <QHBoxLayout>
34 
35 #ifdef USE_AKONADI
36 using namespace KCalCore;
37 #else
38 using namespace KCal;
39 #endif
40 
41 
42 TimeSelector::TimeSelector(const QString& selectText, const QString& selectWhatsThis,
43  const QString& valueWhatsThis, bool allowHourMinute, QWidget* parent)
44  : QFrame(parent),
45  mSignWidget(0),
46  mReadOnly(false)
47 {
48  QHBoxLayout* layout = new QHBoxLayout(this);
49  layout->setMargin(0);
50  layout->setSpacing(KDialog::spacingHint());
51  mSelect = new CheckBox(selectText, this);
52  mSelect->setFixedSize(mSelect->sizeHint());
53  connect(mSelect, SIGNAL(toggled(bool)), SLOT(selectToggled(bool)));
54  mSelect->setWhatsThis(selectWhatsThis);
55  layout->addWidget(mSelect);
56 
57  KHBox* box = new KHBox(this); // to group widgets for QWhatsThis text
58  box->setSpacing(KDialog::spacingHint());
59  layout->addWidget(box);
60  mPeriod = new TimePeriod(allowHourMinute, box);
61  mPeriod->setFixedSize(mPeriod->sizeHint());
62  mPeriod->setSelectOnStep(false);
63 #ifdef USE_AKONADI
64  connect(mPeriod, SIGNAL(valueChanged(KCalCore::Duration)), SLOT(periodChanged(KCalCore::Duration)));
65 #else
66  connect(mPeriod, SIGNAL(valueChanged(KCal::Duration)), SLOT(periodChanged(KCal::Duration)));
67 #endif
68  mSelect->setFocusWidget(mPeriod);
69  mPeriod->setEnabled(false);
70 
71  box->setWhatsThis(valueWhatsThis);
72  layout->addStretch();
73 }
74 
75 /******************************************************************************
76 * Create a ComboBox used to select the time period's sign.
77 * The caller is responsible for populating the ComboBox and handling its value.
78 */
79 ComboBox* TimeSelector::createSignCombo()
80 {
81  delete mSignWidget;
82  mSignWidget = new ComboBox(mPeriod->parentWidget());
83  mSignWidget->setEnabled(mPeriod->isEnabled());
84  return mSignWidget;
85 }
86 
87 /******************************************************************************
88 * Set the read-only status.
89 */
90 void TimeSelector::setReadOnly(bool ro)
91 {
92  if ((int)ro != (int)mReadOnly)
93  {
94  mReadOnly = ro;
95  mSelect->setReadOnly(mReadOnly);
96  mPeriod->setReadOnly(mReadOnly);
97  if (mSignWidget)
98  mSignWidget->setReadOnly(mReadOnly);
99  }
100 }
101 
102 bool TimeSelector::isChecked() const
103 {
104  return mSelect->isChecked();
105 }
106 
107 void TimeSelector::setChecked(bool on)
108 {
109  if (on != mSelect->isChecked())
110  {
111  mSelect->setChecked(on);
112  emit valueChanged(period());
113  }
114 }
115 
116 void TimeSelector::setMaximum(int hourmin, int days)
117 {
118  mPeriod->setMaximum(hourmin, days);
119 }
120 
121 void TimeSelector::setDateOnly(bool dateOnly)
122 {
123  mPeriod->setDateOnly(dateOnly);
124 }
125 
126 /******************************************************************************
127  * Get the specified number of minutes.
128  * Reply = 0 if unselected.
129  */
130 Duration TimeSelector::period() const
131 {
132  return mSelect->isChecked() ? mPeriod->period() : Duration(0);
133 }
134 
135 /******************************************************************************
136 * Initialise the controls with a specified time period.
137 * If minutes = 0, it will be deselected.
138 * The time unit combo-box is initialised to 'defaultUnits', but if 'dateOnly'
139 * is true, it will never be initialised to hours/minutes.
140 */
141 void TimeSelector::setPeriod(const Duration& period, bool dateOnly, TimePeriod::Units defaultUnits)
142 {
143  mSelect->setChecked(period);
144  mPeriod->setEnabled(period);
145  if (mSignWidget)
146  mSignWidget->setEnabled(period);
147  mPeriod->setPeriod(period, dateOnly, defaultUnits);
148 }
149 
150 /******************************************************************************
151 * Set the input focus on the count field.
152 */
153 void TimeSelector::setFocusOnCount()
154 {
155  mPeriod->setFocusOnCount();
156 }
157 
158 /******************************************************************************
159 * Called when the TimeSelector checkbox is toggled.
160 */
161 void TimeSelector::selectToggled(bool on)
162 {
163  mPeriod->setEnabled(on);
164  if (mSignWidget)
165  mSignWidget->setEnabled(on);
166  if (on)
167  mPeriod->setFocus();
168  emit toggled(on);
169  emit valueChanged(period());
170 }
171 
172 /******************************************************************************
173 * Called when the period value changes.
174 */
175 void TimeSelector::periodChanged(const Duration& period)
176 {
177  if (mSelect->isChecked())
178  emit valueChanged(period);
179 }
180 
181 // vim: et sw=4:
CheckBox::setReadOnly
virtual void setReadOnly(bool readOnly)
TimePeriod::setSelectOnStep
void setSelectOnStep(bool select)
TimeSelector::setMaximum
void setMaximum(int hourmin, int days)
Definition: timeselector.cpp:116
TimeSelector::isChecked
bool isChecked() const
Definition: timeselector.cpp:102
TimePeriod::Units
Units
TimePeriod::period
KCal::Duration period() const
TimeSelector::valueChanged
void valueChanged(const KCal::Duration &)
TimePeriod::setPeriod
void setPeriod(const KCal::Duration &period, bool dateOnly, Units defaultUnits)
TimePeriod::setFocusOnCount
void setFocusOnCount()
CheckBox::setFocusWidget
void setFocusWidget(QWidget *widget, bool enable=true)
TimeSelector::setReadOnly
void setReadOnly(bool)
Definition: timeselector.cpp:90
TimeSelector::setChecked
void setChecked(bool on)
Definition: timeselector.cpp:107
QWidget
checkbox.h
TimeSelector::periodChanged
void periodChanged(const KCal::Duration &)
Definition: timeselector.cpp:175
TimeSelector::toggled
void toggled(bool)
TimeSelector::setFocusOnCount
void setFocusOnCount()
Definition: timeselector.cpp:153
CheckBox
TimePeriod
ComboBox::setReadOnly
virtual void setReadOnly(bool readOnly)
TimeSelector::selectToggled
void selectToggled(bool)
Definition: timeselector.cpp:161
TimePeriod::setReadOnly
virtual void setReadOnly(bool readOnly)
TimeSelector::TimeSelector
TimeSelector(const QString &selectText, const QString &selectWhatsThis, const QString &valueWhatsThis, bool allowHourMinute, QWidget *parent)
Definition: timeselector.cpp:42
TimeSelector::setDateOnly
void setDateOnly(bool dateOnly=true)
Definition: timeselector.cpp:121
TimePeriod::setDateOnly
void setDateOnly(bool dateOnly)
kalarm.h
combobox.h
TimeSelector::setPeriod
void setPeriod(const KCal::Duration &, bool dateOnly, TimePeriod::Units defaultUnits)
Definition: timeselector.cpp:141
KHBox
ComboBox
TimeSelector::createSignCombo
ComboBox * createSignCombo()
Definition: timeselector.cpp:79
TimePeriod::setMaximum
void setMaximum(int hourmin, int days)
QFrame
TimeSelector::period
KCal::Duration period() const
Definition: timeselector.cpp:130
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:10 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

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