26 #include "timeperiod.moc"
31 #include <QStackedWidget>
34 using namespace KCalCore;
41 QString TimePeriod::i18n_minutes() {
return i18nc(
"@item:inlistbox Time units",
"minutes"); }
42 QString TimePeriod::i18n_hours_mins() {
return i18nc(
"@item:inlistbox Time units",
"hours/minutes"); }
43 QString TimePeriod::i18n_days() {
return i18nc(
"@item:inlistbox Time units",
"days"); }
44 QString TimePeriod::i18n_weeks() {
return i18nc(
"@item:inlistbox Time units",
"weeks"); }
56 mNoHourMinute(!allowHourMinute),
59 setSpacing(KDialog::spacingHint());
61 mSpinStack =
new QStackedWidget(
this);
62 mSpinBox =
new SpinBox(mSpinStack);
66 connect(mSpinBox, SIGNAL(
valueChanged(
int)), SLOT(slotDaysChanged(
int)));
67 mSpinStack->addWidget(mSpinBox);
69 mTimeSpinBox =
new TimeSpinBox(0, 99999, mSpinStack);
71 connect(mTimeSpinBox, SIGNAL(
valueChanged(
int)), SLOT(slotTimeChanged(
int)));
72 mSpinStack->addWidget(mTimeSpinBox);
74 mSpinStack->setFixedSize(mSpinBox->sizeHint().expandedTo(mTimeSpinBox->
sizeHint()));
75 mHourMinuteRaised = mNoHourMinute;
76 showHourMin(!mNoHourMinute);
79 mUnitsCombo->setEditable(
false);
85 mUnitsCombo->addItem(i18n_minutes());
86 mUnitsCombo->addItem(i18n_hours_mins());
88 mUnitsCombo->addItem(i18n_days());
89 mUnitsCombo->addItem(i18n_weeks());
90 mMaxUnitShown =
Weeks;
91 mUnitsCombo->setFixedSize(mUnitsCombo->sizeHint());
92 connect(mUnitsCombo, SIGNAL(activated(
int)), SLOT(slotUnitsSelected(
int)));
94 setFocusProxy(mUnitsCombo);
95 setTabOrder(mUnitsCombo, mSpinStack);
124 mSpinStack->setFocus();
133 Duration oldmins =
period();
140 mMaxDays = (days >= 0) ? days : 0;
141 adjustDayWeekShown();
155 switch (mUnitsCombo->currentIndex() + mDateOnlyOffset)
158 return Duration(mTimeSpinBox->
value() * 60, Duration::Seconds);
160 return Duration(mSpinBox->value() * 60, Duration::Seconds);
165 return Duration(mSpinBox->value() * factor, Duration::Days);
177 Duration oldinterval =
period();
178 if (!dateOnly && mNoHourMinute)
183 int count = perod.value();
199 if (item < mDateOnlyOffset)
200 item = mDateOnlyOffset;
201 else if (item > mMaxUnitShown)
202 item = mMaxUnitShown;
203 mUnitsCombo->setCurrentIndex(item - mDateOnlyOffset);
207 mSpinBox->setValue(count);
213 if (item < mDateOnlyOffset)
214 item = mDateOnlyOffset;
215 else if (item > mMaxUnitShown)
216 item = mMaxUnitShown;
217 mUnitsCombo->setCurrentIndex(item - mDateOnlyOffset);
218 if ((dateOnly && !mDateOnlyOffset) || (!dateOnly && mDateOnlyOffset))
224 Duration newinterval =
period();
225 if (newinterval != oldinterval)
235 Duration oldinterval = 0;
238 int index = mUnitsCombo->currentIndex();
242 if (!dateOnly && mDateOnlyOffset)
245 mUnitsCombo->insertItem(0, i18n_minutes());
246 mUnitsCombo->insertItem(1, i18n_hours_mins());
248 adjustDayWeekShown();
249 mUnitsCombo->setCurrentIndex(index += 2);
251 else if (dateOnly && !mDateOnlyOffset)
254 mUnitsCombo->removeItem(0);
255 mUnitsCombo->removeItem(0);
261 adjustDayWeekShown();
262 mUnitsCombo->setCurrentIndex(index);
267 mUnitsCombo->setCurrentIndex(
Days - mDateOnlyOffset);
268 mSpinBox->setValue(perod.asDays());
276 Duration newinterval =
period();
277 if (newinterval != oldinterval)
286 void TimePeriod::adjustDayWeekShown()
289 if (newMaxUnitShown > mMaxUnitShown)
291 if (mMaxUnitShown <
Days)
292 mUnitsCombo->addItem(i18n_days());
293 if (newMaxUnitShown ==
Weeks)
294 mUnitsCombo->addItem(i18n_weeks());
296 else if (newMaxUnitShown < mMaxUnitShown)
298 if (mMaxUnitShown ==
Weeks)
299 mUnitsCombo->removeItem(
Weeks - mDateOnlyOffset);
300 if (newMaxUnitShown <
Days)
301 mUnitsCombo->removeItem(
Days - mDateOnlyOffset);
303 mMaxUnitShown = newMaxUnitShown;
310 void TimePeriod::setUnitRange()
313 switch (static_cast<Units>(mUnitsCombo->currentIndex() + mDateOnlyOffset))
316 maxval = mMaxDays / 7;
319 mUnitsCombo->setCurrentIndex(
Days - mDateOnlyOffset);
322 maxval = mMaxDays ? mMaxDays : 1;
325 maxval = mTimeSpinBox->
maximum();
339 Units oldUnits =
static_cast<Units>(mUnitsCombo->currentIndex() + mDateOnlyOffset);
340 if (units == oldUnits)
346 mSpinBox->setValue(mTimeSpinBox->
value());
349 mTimeSpinBox->
setValue(mSpinBox->value());
350 if (units >= mDateOnlyOffset && units <= mMaxUnitShown)
352 int item = units - mDateOnlyOffset;
353 mUnitsCombo->setCurrentIndex(item);
354 slotUnitsSelected(item);
363 return static_cast<Units>(mUnitsCombo->currentIndex() + mDateOnlyOffset);
369 void TimePeriod::slotUnitsSelected(
int index)
379 void TimePeriod::slotDaysChanged(
int)
381 if (!mHourMinuteRaised)
388 void TimePeriod::slotTimeChanged(
int)
390 if (mHourMinuteRaised)
397 void TimePeriod::showHourMin(
bool hourMinute)
399 if (hourMinute != mHourMinuteRaised)
401 mHourMinuteRaised = hourMinute;
404 mSpinStack->setCurrentWidget(mTimeSpinBox);
405 mSpinStack->setFocusProxy(mTimeSpinBox);
409 mSpinStack->setCurrentWidget(mSpinBox);
410 mSpinStack->setFocusProxy(mSpinBox);
422 mUnitsCombo->setWhatsThis(units);
423 mSpinBox->setWhatsThis(dayWeek);
424 mTimeSpinBox->setWhatsThis(hourMin.isNull() ? dayWeek : hourMin);
void setSelectOnStep(bool select)
Sets whether the editor text is to be selected whenever spin buttons are clicked. ...
Units
Units for the time period.
KCal::Duration period() const
Gets the entered time period.
void setPeriod(const KCal::Duration &period, bool dateOnly, Units defaultUnits)
Initialises the time period value.
void valueChanged(const KCal::Duration &period)
This signal is emitted whenever the value held in the widget changes.
Hours/minutes time entry widget.
void setFocusOnCount()
Sets the input focus to the count field.
void setSingleStep(int step)
Sets the unshifted step increment, i.e.
void setSelectOnStep(bool sel)
Sets whether the spin box value text should be selected when its value is stepped.
TimePeriod(bool allowMinute, QWidget *parent)
Constructor.
int maximum() const
Returns the maximum value of the spin box.
void setUnits(Units units)
Sets the time units.
virtual QSize sizeHint() const
virtual void setReadOnly(bool readOnly)
Sets whether the spin box can be changed by the user.
void setRange(int minValue, int maxValue)
Sets the minimum and maximum values of the spin box.
void setWhatsThises(const QString &units, const QString &dayWeek, const QString &hourMin=QString())
Sets separate WhatsThis texts for the count spin boxes and the units combo box.
virtual void setReadOnly(bool readOnly)
Sets whether the combo box is read-only for the user.
int value() const
Returns the current value of the spin box.
Spin box with accelerated shift key stepping and read-only option.
virtual void setValue(int minutes)
Sets the value of the spin box.
void setRange(int minValue, int maxValue)
Sets the minimum and maximum values of the spin box.
virtual void setReadOnly(bool readOnly)
Sets whether the widget is read-only for the user.
void setSelectOnStep(bool sel)
Sets whether the spin box value text should be selected when its value is stepped.
void setSingleShiftStep(int step)
Sets the shifted step increment, i.e.
void setDateOnly(bool dateOnly)
Enables or disables minutes and hours/minutes units in the combo box.
int maximum() const
Returns the maximum value of the spin box.
A KComboBox with read-only option.
void setMaximum(int hourmin, int days)
Sets the maximum values for the minutes and hours/minutes, and days/weeks spin boxes.
Units units() const
Gets the currently selected time units.
virtual void setReadOnly(bool readOnly)
Sets whether the spin box can be changed by the user.
static const int maxMinutes