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

kalarm/lib

  • sources
  • kde-4.12
  • kdepim
  • kalarm
  • lib
timeedit.cpp
Go to the documentation of this file.
1 /*
2  * timeedit.cpp - time-of-day edit widget, with AM/PM shown depending on locale
3  * Program: kalarm
4  * Copyright © 2001-2006 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 "combobox.h"
24 #include "timespinbox.h"
25 #include "timeedit.moc"
26 
27 #include <kglobal.h>
28 #include <klocale.h>
29 
30 
31 TimeEdit::TimeEdit(QWidget* parent)
32  : KHBox(parent),
33  mAmPm(0),
34  mAmIndex(-1),
35  mPmIndex(-1),
36  mReadOnly(false)
37 {
38  bool use12hour = KGlobal::locale()->use12Clock();
39  mSpinBox = new TimeSpinBox(!use12hour, this);
40  mSpinBox->setFixedSize(mSpinBox->sizeHint());
41  connect(mSpinBox, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
42  if (use12hour)
43  {
44  mAmPm = new ComboBox(this);
45  setAmPmCombo(1, 1); // add "am" and "pm" options to the combo box
46  mAmPm->setFixedSize(mAmPm->sizeHint());
47  connect(mAmPm, SIGNAL(highlighted(int)), SLOT(slotAmPmChanged(int)));
48  }
49 }
50 
51 void TimeEdit::setReadOnly(bool ro)
52 {
53  if (ro != mReadOnly)
54  {
55  mReadOnly = ro;
56  mSpinBox->setReadOnly(ro);
57  if (mAmPm)
58  mAmPm->setReadOnly(ro);
59  }
60 }
61 
62 int TimeEdit::value() const
63 {
64  return mSpinBox->value();
65 }
66 
67 bool TimeEdit::isValid() const
68 {
69  return mSpinBox->isValid();
70 }
71 
72 /******************************************************************************
73  * Set the edit value as valid or invalid.
74  * If newly invalid, the value is displayed as asterisks.
75  * If newly valid, the value is set to the minimum value.
76  */
77 void TimeEdit::setValid(bool valid)
78 {
79  bool oldValid = mSpinBox->isValid();
80  if ((valid && !oldValid)
81  || (!valid && oldValid))
82  {
83  mSpinBox->setValid(valid);
84  if (mAmPm)
85  mAmPm->setCurrentIndex(0);
86  }
87 }
88 
89 /******************************************************************************
90  * Set the widget's value.
91  */
92 void TimeEdit::setValue(int minutes)
93 {
94  if (mAmPm)
95  {
96  int i = (minutes >= 720) ? mPmIndex : mAmIndex;
97  mAmPm->setCurrentIndex(i >= 0 ? i : 0);
98  }
99  mSpinBox->setValue(minutes);
100 }
101 
102 bool TimeEdit::wrapping() const
103 {
104  return mSpinBox->wrapping();
105 }
106 
107 void TimeEdit::setWrapping(bool on)
108 {
109  mSpinBox->setWrapping(on);
110 }
111 
112 int TimeEdit::minimum() const
113 {
114  return mSpinBox->minimum();
115 }
116 
117 int TimeEdit::maximum() const
118 {
119  return mSpinBox->maximum();
120 }
121 
122 void TimeEdit::setMinimum(int minutes)
123 {
124  if (mAmPm)
125  setAmPmCombo((minutes < 720 ? 1 : 0), -1); // insert/remove "am" in combo box
126  mSpinBox->setMinimum(minutes);
127 }
128 
129 void TimeEdit::setMaximum(int minutes)
130 {
131  if (mAmPm)
132  setAmPmCombo(-1, (minutes < 720 ? 0 : 1)); // insert/remove "pm" in combo box
133  mSpinBox->setMaximum(minutes);
134 }
135 
136 /******************************************************************************
137  * Called when the spin box value has changed.
138  */
139 void TimeEdit::slotValueChanged(int value)
140 {
141  if (mAmPm)
142  {
143  bool pm = (mAmPm->currentIndex() == mPmIndex);
144  if (pm && value < 720)
145  mAmPm->setCurrentIndex(mAmIndex);
146  else if (!pm && value >= 720)
147  mAmPm->setCurrentIndex(mPmIndex);
148  }
149  emit valueChanged(value);
150 }
151 
152 /******************************************************************************
153  * Called when a new selection has been made by the user in the AM/PM combo box.
154  * Adjust the current time value by 12 hours.
155  */
156 void TimeEdit::slotAmPmChanged(int item)
157 {
158  if (mAmPm)
159  {
160  int value = mSpinBox->value();
161  if (item == mPmIndex && value < 720)
162  mSpinBox->setValue(value + 720);
163  else if (item != mPmIndex && value >= 720)
164  mSpinBox->setValue(value - 720);
165  }
166 }
167 
168 /******************************************************************************
169  * Set up the AM/PM combo box to contain the specified items.
170  */
171 void TimeEdit::setAmPmCombo(int am, int pm)
172 {
173  if (am > 0 && mAmIndex < 0)
174  {
175  // Insert "am"
176  mAmIndex = 0;
177  mAmPm->insertItem(mAmIndex, i18nc("@item:inlistbox Morning, as in 2am", "am"));
178  if (mPmIndex >= 0)
179  mPmIndex = 1;
180  mAmPm->setCurrentIndex(mPmIndex >= 0 ? mPmIndex : mAmIndex);
181  }
182  else if (am == 0 && mAmIndex >= 0)
183  {
184  // Remove "am"
185  mAmPm->removeItem(mAmIndex);
186  mAmIndex = -1;
187  if (mPmIndex >= 0)
188  mPmIndex = 0;
189  mAmPm->setCurrentIndex(mPmIndex);
190  }
191 
192  if (pm > 0 && mPmIndex < 0)
193  {
194  // Insert "pm"
195  mPmIndex = mAmIndex + 1;
196  mAmPm->insertItem(mPmIndex, i18nc("@item:inlistbox Afternoon, as in 2pm", "pm"));
197  if (mAmIndex < 0)
198  mAmPm->setCurrentIndex(mPmIndex);
199  }
200  else if (pm == 0 && mPmIndex >= 0)
201  {
202  // Remove "pm"
203  mAmPm->removeItem(mPmIndex);
204  mPmIndex = -1;
205  mAmPm->setCurrentIndex(mAmIndex);
206  }
207 }
208 
209 // vim: et sw=4:
TimeSpinBox::setValid
void setValid(bool)
Sets the spin box as holding a valid or invalid value.
Definition: timespinbox.cpp:172
TimeSpinBox
Hours/minutes time entry widget.
Definition: timespinbox.h:45
TimeEdit::setReadOnly
virtual void setReadOnly(bool readOnly)
Sets whether the widget is read-only for the user.
Definition: timeedit.cpp:51
QWidget
TimeEdit::isValid
bool isValid() const
Returns true if the widget contains a valid value.
Definition: timeedit.cpp:67
TimeEdit::minimum
int minimum() const
Returns the minimum value of the widget in minutes.
Definition: timeedit.cpp:112
TimeEdit::maximum
int maximum() const
Returns the maximum value of the widget in minutes.
Definition: timeedit.cpp:117
TimeSpinBox::isValid
bool isValid() const
Returns true if the spin box holds a valid value.
Definition: timespinbox.cpp:237
TimeEdit::setMinimum
void setMinimum(int minutes)
Sets the minimum value of the widget.
Definition: timeedit.cpp:122
SpinBox2::setWrapping
void setWrapping(bool on)
Sets whether it is possible to step the value from the highest value to the lowest value and vice ver...
Definition: spinbox2.cpp:137
TimeSpinBox::sizeHint
virtual QSize sizeHint() const
Definition: timespinbox.cpp:247
SpinBox2::setReadOnly
virtual void setReadOnly(bool readOnly)
Sets whether the spin box can be changed by the user.
Definition: spinbox2.cpp:109
TimeSpinBox::setMinimum
virtual void setMinimum(int minutes)
Sets the maximum value which can be held in the spin box.
Definition: timespinbox.cpp:194
ComboBox::setReadOnly
virtual void setReadOnly(bool readOnly)
Sets whether the combo box is read-only for the user.
Definition: combobox.cpp:33
SpinBox2::wrapping
bool wrapping() const
Returns whether it is possible to step the value from the highest value to the lowest value and vice ...
Definition: spinbox2.h:116
SpinBox2::value
int value() const
Returns the current value of the spin box.
Definition: spinbox2.h:142
TimeEdit::setWrapping
void setWrapping(bool on)
Sets whether it is possible to step the value from the highest value to the lowest value and vice ver...
Definition: timeedit.cpp:107
TimeSpinBox::setValue
virtual void setValue(int minutes)
Sets the value of the spin box.
Definition: timespinbox.cpp:203
TimeEdit::valueChanged
void valueChanged(int minutes)
This signal is emitted every time the value of the widget changes (for whatever reason).
TimeEdit::setValue
virtual void setValue(int minutes)
Sets the value of the widget.
Definition: timeedit.cpp:92
SpinBox2::maximum
int maximum() const
Returns the maximum value of the spin box.
Definition: spinbox2.h:134
combobox.h
TimeEdit::setValid
void setValid(bool valid)
Sets whether the edit value is valid.
Definition: timeedit.cpp:77
KHBox
ComboBox
A KComboBox with read-only option.
Definition: combobox.h:39
TimeEdit::TimeEdit
TimeEdit(QWidget *parent=0)
Constructor.
Definition: timeedit.cpp:31
TimeEdit::value
int value() const
Returns the entered time as a value in minutes.
Definition: timeedit.cpp:62
TimeSpinBox::setMaximum
virtual void setMaximum(int minutes)
Sets the maximum value which can be held in the spin box.
Definition: timespinbox.h:83
timespinbox.h
TimeEdit::setMaximum
void setMaximum(int minutes)
Sets the maximum value of the widget.
Definition: timeedit.cpp:129
SpinBox2::minimum
int minimum() const
Returns the minimum value of the spin box.
Definition: spinbox2.h:132
TimeEdit::wrapping
bool wrapping() const
Returns true if it is possible to step the value from the highest value to the lowest value and vice ...
Definition: timeedit.cpp:102
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm/lib

Skip menu "kalarm/lib"
  • 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