23 #include <tqwidgetstack.h>
24 #include <tqwhatsthis.h>
26 #include <tdelocale.h>
31 #include "timespinbox.h"
32 #include "timeperiod.moc"
37 TQString TimePeriod::i18n_minutes() {
return i18n(
"minutes"); }
38 TQString TimePeriod::i18n_Minutes() {
return i18n(
"Minutes"); }
39 TQString TimePeriod::i18n_hours_mins() {
return i18n(
"hours/minutes"); }
40 TQString TimePeriod::i18n_Hours_Mins() {
return i18n(
"Hours/Minutes"); }
41 TQString TimePeriod::i18n_days() {
return i18n(
"days"); }
42 TQString TimePeriod::i18n_Days() {
return i18n(
"Days"); }
43 TQString TimePeriod::i18n_weeks() {
return i18n(
"weeks"); }
44 TQString TimePeriod::i18n_Weeks() {
return i18n(
"Weeks"); }
46 static const int maxMinutes = 1000*60-1;
54 : TQHBox(parent, name),
56 mNoHourMinute(!allowHourMinute),
59 setSpacing(KDialog::spacingHint());
61 mSpinStack =
new TQWidgetStack(
this);
62 mSpinBox =
new SpinBox(mSpinStack);
66 connect(mSpinBox, TQ_SIGNAL(
valueChanged(
int)), TQ_SLOT(slotDaysChanged(
int)));
67 mSpinStack->addWidget(mSpinBox, 0);
69 mTimeSpinBox =
new TimeSpinBox(0, 99999, mSpinStack);
70 mTimeSpinBox->
setRange(1, maxMinutes);
71 connect(mTimeSpinBox, TQ_SIGNAL(
valueChanged(
int)), TQ_SLOT(slotTimeChanged(
int)));
72 mSpinStack->addWidget(mTimeSpinBox, 1);
74 mSpinStack->setFixedSize(mSpinBox->sizeHint().expandedTo(mTimeSpinBox->sizeHint()));
75 mHourMinuteRaised = mNoHourMinute;
76 showHourMin(!mNoHourMinute);
78 mUnitsCombo =
new ComboBox(
false,
this);
84 mUnitsCombo->insertItem(i18n_minutes());
85 mUnitsCombo->insertItem(i18n_hours_mins());
87 mUnitsCombo->insertItem(i18n_days());
88 mUnitsCombo->insertItem(i18n_weeks());
89 mMaxUnitShown = WEEKS;
90 mUnitsCombo->setFixedSize(mUnitsCombo->sizeHint());
91 connect(mUnitsCombo, TQ_SIGNAL(activated(
int)), TQ_SLOT(slotUnitsSelected(
int)));
93 setFocusProxy(mUnitsCombo);
94 setTabOrder(mUnitsCombo, mSpinStack);
123 mSpinStack->setFocus();
135 if (hourmin > maxMinutes)
136 hourmin = maxMinutes;
139 mMaxDays = (days >= 0) ? days : 0;
140 adjustDayWeekShown();
154 switch (mUnitsCombo->currentItem() + mDateOnlyOffset)
157 return mTimeSpinBox->
value();
158 case MINUTES: factor = 1;
break;
159 case DAYS: factor = 24*60;
break;
160 case WEEKS: factor = 7*24*60;
break;
162 return mSpinBox->value() * factor;
173 if (!dateOnly && mNoHourMinute)
180 item = (defaultUnits == MINUTES && count <= mSpinBox->
maxValue()) ? MINUTES : HOURS_MINUTES;
181 else if (mins % (7*24*60))
184 count = mins / (24*60);
189 count = mins / (7*24*60);
191 if (item < mDateOnlyOffset)
192 item = mDateOnlyOffset;
193 else if (item > mMaxUnitShown)
194 item = mMaxUnitShown;
195 mUnitsCombo->setCurrentItem(item - mDateOnlyOffset);
196 if (item == HOURS_MINUTES)
199 mSpinBox->setValue(count);
205 if (item < mDateOnlyOffset)
206 item = mDateOnlyOffset;
207 else if (item > mMaxUnitShown)
208 item = mMaxUnitShown;
209 mUnitsCombo->setCurrentItem(item - mDateOnlyOffset);
210 if ((dateOnly && !mDateOnlyOffset) || (!dateOnly && mDateOnlyOffset))
213 showHourMin(item == HOURS_MINUTES && !mNoHourMinute);
216 if (newmins != oldmins)
229 int index = mUnitsCombo->currentItem();
230 Units units =
static_cast<Units>(index + mDateOnlyOffset);
233 if (!dateOnly && mDateOnlyOffset)
236 mUnitsCombo->insertItem(i18n_minutes(), 0);
237 mUnitsCombo->insertItem(i18n_hours_mins(), 1);
239 adjustDayWeekShown();
240 mUnitsCombo->setCurrentItem(index += 2);
242 else if (dateOnly && !mDateOnlyOffset)
245 mUnitsCombo->removeItem(0);
246 mUnitsCombo->removeItem(0);
252 adjustDayWeekShown();
253 mUnitsCombo->setCurrentItem(index);
254 if (units == HOURS_MINUTES || units == MINUTES)
258 mUnitsCombo->setCurrentItem(DAYS - mDateOnlyOffset);
259 mSpinBox->setValue((mins + 1439) / 1440);
268 if (newmins != oldmins)
277 void TimePeriod::adjustDayWeekShown()
279 Units newMaxUnitShown = (mMaxDays >= 7) ? WEEKS : (mMaxDays || mDateOnlyOffset) ? DAYS : HOURS_MINUTES;
280 if (newMaxUnitShown > mMaxUnitShown)
282 if (mMaxUnitShown < DAYS)
283 mUnitsCombo->insertItem(i18n_days());
284 if (newMaxUnitShown == WEEKS)
285 mUnitsCombo->insertItem(i18n_weeks());
287 else if (newMaxUnitShown < mMaxUnitShown)
289 if (mMaxUnitShown == WEEKS)
290 mUnitsCombo->removeItem(WEEKS - mDateOnlyOffset);
291 if (newMaxUnitShown < DAYS)
292 mUnitsCombo->removeItem(DAYS - mDateOnlyOffset);
294 mMaxUnitShown = newMaxUnitShown;
301 void TimePeriod::setUnitRange()
304 switch (
static_cast<Units>(mUnitsCombo->currentItem() + mDateOnlyOffset))
307 maxval = mMaxDays / 7;
310 mUnitsCombo->setCurrentItem(DAYS - mDateOnlyOffset);
313 maxval = mMaxDays ? mMaxDays : 1;
328 void TimePeriod::slotUnitsSelected(
int index)
331 showHourMin(index + mDateOnlyOffset == HOURS_MINUTES);
338 void TimePeriod::slotDaysChanged(
int)
340 if (!mHourMinuteRaised)
347 void TimePeriod::slotTimeChanged(
int value)
349 if (mHourMinuteRaised)
356 void TimePeriod::showHourMin(
bool hourMinute)
358 if (hourMinute != mHourMinuteRaised)
360 mHourMinuteRaised = hourMinute;
363 mSpinStack->raiseWidget(mTimeSpinBox);
364 mSpinStack->setFocusProxy(mTimeSpinBox);
368 mSpinStack->raiseWidget(mSpinBox);
369 mSpinStack->setFocusProxy(mSpinBox);
381 TQWhatsThis::add(mUnitsCombo, units);
382 TQWhatsThis::add(mSpinBox, dayWeek);
383 TQWhatsThis::add(mTimeSpinBox, (hourMin.isNull() ? dayWeek : hourMin));
A TQComboBox with read-only option.
virtual void setReadOnly(bool readOnly)
Sets whether the combo box is read-only for the user.
void setRange(int minValue, int maxValue)
Sets the minimum and maximum values of the spin box.
void setSelectOnStep(bool sel)
Sets whether the spin box value text should be selected when its value is stepped.
int maxValue() const
Returns the maximum value of the spin box.
virtual void setReadOnly(bool readOnly)
Sets whether the spin box can be changed by the user.
int value() const
Returns the current value of the spin box.
Spin box with accelerated shift key stepping and read-only option.
void setLineShiftStep(int step)
Sets the shifted step increment, i.e.
int maxValue() const
Returns the maximum value of the spin box.
void setSelectOnStep(bool sel)
Sets whether the spin box value text should be selected when its value is stepped.
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 setLineStep(int step)
Sets the unshifted step increment, i.e.
void setMinutes(int minutes, bool dateOnly, Units defaultUnits)
Initialises the time period value.
void setWhatsThis(const TQString &units, const TQString &dayWeek, const TQString &hourMin=TQString())
Sets separate WhatsThis texts for the count spin boxes and the units combo box.
TimePeriod(bool allowMinute, TQWidget *parent, const char *name=0)
Constructor.
void setSelectOnStep(bool select)
Sets whether the editor text is to be selected whenever spin buttons are clicked.
void valueChanged(int minutes)
This signal is emitted whenever the value held in the widget changes.
virtual void setReadOnly(bool readOnly)
Sets whether the widget is read-only for the user.
Units
Units for the time period.
void setMaximum(int hourmin, int days)
Sets the maximum values for the minutes and hours/minutes, and days/weeks spin boxes.
int minutes() const
Gets the entered time period expressed in minutes.
void setDateOnly(bool dateOnly)
Enables or disables minutes and hours/minutes units in the combo box.
void setFocusOnCount()
Sets the input focus to the count field.
Hours/minutes time entry widget.
virtual void setValue(int minutes)
Sets the value of the spin box.