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