21
21
#include "kalarm.h"
26
23
#include "combobox.h"
27
24
#include "timespinbox.h"
28
25
#include "timeedit.moc"
31
31
TimeEdit::TimeEdit(QWidget* parent)
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)));
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)));
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)));
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)));
51
51
void TimeEdit::setReadOnly(bool ro)
56
mSpinBox->setReadOnly(ro);
58
mAmPm->setReadOnly(ro);
56
mSpinBox->setReadOnly(ro);
58
mAmPm->setReadOnly(ro);
62
62
int TimeEdit::value() const
64
return mSpinBox->value();
64
return mSpinBox->value();
67
67
bool TimeEdit::isValid() const
69
return mSpinBox->isValid();
69
return mSpinBox->isValid();
72
72
/******************************************************************************
77
77
void TimeEdit::setValid(bool valid)
79
bool oldValid = mSpinBox->isValid();
80
if ((valid && !oldValid)
81
|| (!valid && oldValid))
83
mSpinBox->setValid(valid);
85
mAmPm->setCurrentIndex(0);
79
bool oldValid = mSpinBox->isValid();
80
if ((valid && !oldValid)
81
|| (!valid && oldValid))
83
mSpinBox->setValid(valid);
85
mAmPm->setCurrentIndex(0);
89
89
/******************************************************************************
92
92
void TimeEdit::setValue(int minutes)
96
int i = (minutes >= 720) ? mPmIndex : mAmIndex;
97
mAmPm->setCurrentIndex(i >= 0 ? i : 0);
99
mSpinBox->setValue(minutes);
96
int i = (minutes >= 720) ? mPmIndex : mAmIndex;
97
mAmPm->setCurrentIndex(i >= 0 ? i : 0);
99
mSpinBox->setValue(minutes);
102
102
bool TimeEdit::wrapping() const
104
return mSpinBox->wrapping();
104
return mSpinBox->wrapping();
107
107
void TimeEdit::setWrapping(bool on)
109
mSpinBox->setWrapping(on);
109
mSpinBox->setWrapping(on);
112
112
int TimeEdit::minimum() const
114
return mSpinBox->minimum();
114
return mSpinBox->minimum();
117
117
int TimeEdit::maximum() const
119
return mSpinBox->maximum();
119
return mSpinBox->maximum();
122
122
void TimeEdit::setMinimum(int minutes)
125
setAmPmCombo((minutes < 720 ? 1 : 0), -1); // insert/remove "am" in combo box
126
mSpinBox->setMinimum(minutes);
125
setAmPmCombo((minutes < 720 ? 1 : 0), -1); // insert/remove "am" in combo box
126
mSpinBox->setMinimum(minutes);
129
129
void TimeEdit::setMaximum(int minutes)
132
setAmPmCombo(-1, (minutes < 720 ? 0 : 1)); // insert/remove "pm" in combo box
133
mSpinBox->setMaximum(minutes);
132
setAmPmCombo(-1, (minutes < 720 ? 0 : 1)); // insert/remove "pm" in combo box
133
mSpinBox->setMaximum(minutes);
136
136
/******************************************************************************
139
139
void TimeEdit::slotValueChanged(int value)
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);
149
emit valueChanged(value);
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);
149
emit valueChanged(value);
152
152
/******************************************************************************
156
156
void TimeEdit::slotAmPmChanged(int item)
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);
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);
168
168
/******************************************************************************
171
171
void TimeEdit::setAmPmCombo(int am, int pm)
173
if (am > 0 && mAmIndex < 0)
177
mAmPm->insertItem(mAmIndex, i18nc("@item:inlistbox Morning, as in 2am", "am"));
180
mAmPm->setCurrentIndex(mPmIndex >= 0 ? mPmIndex : mAmIndex);
182
else if (am == 0 && mAmIndex >= 0)
185
mAmPm->removeItem(mAmIndex);
189
mAmPm->setCurrentIndex(mPmIndex);
173
if (am > 0 && mAmIndex < 0)
177
mAmPm->insertItem(mAmIndex, i18nc("@item:inlistbox Morning, as in 2am", "am"));
180
mAmPm->setCurrentIndex(mPmIndex >= 0 ? mPmIndex : mAmIndex);
182
else if (am == 0 && mAmIndex >= 0)
185
mAmPm->removeItem(mAmIndex);
189
mAmPm->setCurrentIndex(mPmIndex);
192
if (pm > 0 && mPmIndex < 0)
195
mPmIndex = mAmIndex + 1;
196
mAmPm->insertItem(mPmIndex, i18nc("@item:inlistbox Afternoon, as in 2pm", "pm"));
198
mAmPm->setCurrentIndex(mPmIndex);
200
else if (pm == 0 && mPmIndex >= 0)
203
mAmPm->removeItem(mPmIndex);
205
mAmPm->setCurrentIndex(mAmIndex);
192
if (pm > 0 && mPmIndex < 0)
195
mPmIndex = mAmIndex + 1;
196
mAmPm->insertItem(mPmIndex, i18nc("@item:inlistbox Afternoon, as in 2pm", "pm"));
198
mAmPm->setCurrentIndex(mPmIndex);
200
else if (pm == 0 && mPmIndex >= 0)
203
mAmPm->removeItem(mPmIndex);
205
mAmPm->setCurrentIndex(mAmIndex);