kalarm/lib
timeedit.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kalarm.h"
00022
00023 #include <tdeglobal.h>
00024 #include <tdelocale.h>
00025
00026 #include "combobox.h"
00027 #include "timespinbox.h"
00028 #include "timeedit.moc"
00029
00030
00031 TimeEdit::TimeEdit(TQWidget* parent, const char* name)
00032 : TQHBox(parent, name),
00033 mAmPm(0),
00034 mAmIndex(-1),
00035 mPmIndex(-1),
00036 mReadOnly(false)
00037 {
00038 bool use12hour = TDEGlobal::locale()->use12Clock();
00039 mSpinBox = new TimeSpinBox(!use12hour, this);
00040 mSpinBox->setFixedSize(mSpinBox->sizeHint());
00041 connect(mSpinBox, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotValueChanged(int)));
00042 if (use12hour)
00043 {
00044 mAmPm = new ComboBox(this);
00045 setAmPmCombo(1, 1);
00046 mAmPm->setFixedSize(mAmPm->sizeHint());
00047 connect(mAmPm, TQT_SIGNAL(highlighted(int)), TQT_SLOT(slotAmPmChanged(int)));
00048 }
00049 }
00050
00051 void TimeEdit::setReadOnly(bool ro)
00052 {
00053 if (ro != mReadOnly)
00054 {
00055 mReadOnly = ro;
00056 mSpinBox->setReadOnly(ro);
00057 if (mAmPm)
00058 mAmPm->setReadOnly(ro);
00059 }
00060 }
00061
00062 int TimeEdit::value() const
00063 {
00064 return mSpinBox->value();
00065 }
00066
00067 bool TimeEdit::isValid() const
00068 {
00069 return mSpinBox->isValid();
00070 }
00071
00072
00073
00074
00075
00076
00077 void TimeEdit::setValid(bool valid)
00078 {
00079 bool oldValid = mSpinBox->isValid();
00080 if ((valid && !oldValid) || (!valid && oldValid))
00081 {
00082 mSpinBox->setValid(valid);
00083 if (mAmPm)
00084 mAmPm->setCurrentItem(0);
00085 }
00086 }
00087
00088
00089
00090
00091 void TimeEdit::setValue(int minutes)
00092 {
00093 if (mAmPm)
00094 {
00095 int i = (minutes >= 720) ? mPmIndex : mAmIndex;
00096 mAmPm->setCurrentItem(i >= 0 ? i : 0);
00097 }
00098 mSpinBox->setValue(minutes);
00099 }
00100
00101 bool TimeEdit::wrapping() const
00102 {
00103 return mSpinBox->wrapping();
00104 }
00105
00106 void TimeEdit::setWrapping(bool on)
00107 {
00108 mSpinBox->setWrapping(on);
00109 }
00110
00111 int TimeEdit::minValue() const
00112 {
00113 return mSpinBox->minValue();
00114 }
00115
00116 int TimeEdit::maxValue() const
00117 {
00118 return mSpinBox->maxValue();
00119 }
00120
00121 void TimeEdit::setMinValue(int minutes)
00122 {
00123 if (mAmPm)
00124 setAmPmCombo((minutes < 720 ? 1 : 0), -1);
00125 mSpinBox->setMinValue(minutes);
00126 }
00127
00128 void TimeEdit::setMaxValue(int minutes)
00129 {
00130 if (mAmPm)
00131 setAmPmCombo(-1, (minutes < 720 ? 0 : 1));
00132 mSpinBox->setMaxValue(minutes);
00133 }
00134
00135
00136
00137
00138 void TimeEdit::slotValueChanged(int value)
00139 {
00140 if (mAmPm)
00141 {
00142 bool pm = (mAmPm->currentItem() == mPmIndex);
00143 if (pm && value < 720)
00144 mAmPm->setCurrentItem(mAmIndex);
00145 else if (!pm && value >= 720)
00146 mAmPm->setCurrentItem(mPmIndex);
00147 }
00148 emit valueChanged(value);
00149 }
00150
00151
00152
00153
00154
00155 void TimeEdit::slotAmPmChanged(int item)
00156 {
00157 if (mAmPm)
00158 {
00159 int value = mSpinBox->value();
00160 if (item == mPmIndex && value < 720)
00161 mSpinBox->setValue(value + 720);
00162 else if (item != mPmIndex && value >= 720)
00163 mSpinBox->setValue(value - 720);
00164 }
00165 }
00166
00167
00168
00169
00170 void TimeEdit::setAmPmCombo(int am, int pm)
00171 {
00172 if (am > 0 && mAmIndex < 0)
00173 {
00174
00175 mAmIndex = 0;
00176 mAmPm->insertItem(TDEGlobal::locale()->translate("am"), mAmIndex);
00177 if (mPmIndex >= 0)
00178 mPmIndex = 1;
00179 mAmPm->setCurrentItem(mPmIndex >= 0 ? mPmIndex : mAmIndex);
00180 }
00181 else if (am == 0 && mAmIndex >= 0)
00182 {
00183
00184 mAmPm->removeItem(mAmIndex);
00185 mAmIndex = -1;
00186 if (mPmIndex >= 0)
00187 mPmIndex = 0;
00188 mAmPm->setCurrentItem(mPmIndex);
00189 }
00190
00191 if (pm > 0 && mPmIndex < 0)
00192 {
00193
00194 mPmIndex = mAmIndex + 1;
00195 mAmPm->insertItem(TDEGlobal::locale()->translate("pm"), mPmIndex);
00196 if (mAmIndex < 0)
00197 mAmPm->setCurrentItem(mPmIndex);
00198 }
00199 else if (pm == 0 && mPmIndex >= 0)
00200 {
00201
00202 mAmPm->removeItem(mPmIndex);
00203 mPmIndex = -1;
00204 mAmPm->setCurrentItem(mAmIndex);
00205 }
00206 }
|