kalarm
timeselector.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 <qlayout.h>
00024 #include <qlabel.h>
00025 #include <qhbox.h>
00026 #include <qwhatsthis.h>
00027
00028 #include <klocale.h>
00029 #include <kdialog.h>
00030 #include <kdebug.h>
00031
00032 #include "checkbox.h"
00033 #include "timeselector.moc"
00034
00035
00036 TimeSelector::TimeSelector(const QString& selectText, const QString& postfix, const QString& selectWhatsThis,
00037 const QString& valueWhatsThis, bool allowHourMinute, QWidget* parent, const char* name)
00038 : QFrame(parent, name),
00039 mLabel(0),
00040 mReadOnly(false)
00041 {
00042 setFrameStyle(QFrame::NoFrame);
00043 QVBoxLayout* topLayout = new QVBoxLayout(this, 0, KDialog::spacingHint());
00044 QHBoxLayout* layout = new QHBoxLayout(topLayout, KDialog::spacingHint());
00045 mSelect = new CheckBox(selectText, this);
00046 mSelect->setFixedSize(mSelect->sizeHint());
00047 connect(mSelect, SIGNAL(toggled(bool)), SLOT(selectToggled(bool)));
00048 QWhatsThis::add(mSelect, selectWhatsThis);
00049 layout->addWidget(mSelect);
00050
00051 QHBox* box = new QHBox(this);
00052 box->setSpacing(KDialog::spacingHint());
00053 layout->addWidget(box);
00054 mPeriod = new TimePeriod(allowHourMinute, box);
00055 mPeriod->setFixedSize(mPeriod->sizeHint());
00056 mPeriod->setSelectOnStep(false);
00057 connect(mPeriod, SIGNAL(valueChanged(int)), SLOT(periodChanged(int)));
00058 mSelect->setFocusWidget(mPeriod);
00059 mPeriod->setEnabled(false);
00060
00061 if (!postfix.isEmpty())
00062 {
00063 mLabel = new QLabel(postfix, box);
00064 QWhatsThis::add(box, valueWhatsThis);
00065 mLabel->setEnabled(false);
00066 }
00067 }
00068
00069
00070
00071
00072 void TimeSelector::setReadOnly(bool ro)
00073 {
00074 if ((int)ro != (int)mReadOnly)
00075 {
00076 mReadOnly = ro;
00077 mSelect->setReadOnly(mReadOnly);
00078 mPeriod->setReadOnly(mReadOnly);
00079 }
00080 }
00081
00082 bool TimeSelector::isChecked() const
00083 {
00084 return mSelect->isChecked();
00085 }
00086
00087 void TimeSelector::setChecked(bool on)
00088 {
00089 if (on != mSelect->isChecked())
00090 {
00091 mSelect->setChecked(on);
00092 emit valueChanged(minutes());
00093 }
00094 }
00095
00096 void TimeSelector::setMaximum(int hourmin, int days)
00097 {
00098 mPeriod->setMaximum(hourmin, days);
00099 }
00100
00101 void TimeSelector::setDateOnly(bool dateOnly)
00102 {
00103 mPeriod->setDateOnly(dateOnly);
00104 }
00105
00106
00107
00108
00109
00110 int TimeSelector::minutes() const
00111 {
00112 return mSelect->isChecked() ? mPeriod->minutes() : 0;
00113 }
00114
00115
00116
00117
00118
00119
00120
00121 void TimeSelector::setMinutes(int minutes, bool dateOnly, TimePeriod::Units defaultUnits)
00122 {
00123 mSelect->setChecked(minutes);
00124 mPeriod->setEnabled(minutes);
00125 if (mLabel)
00126 mLabel->setEnabled(minutes);
00127 mPeriod->setMinutes(minutes, dateOnly, defaultUnits);
00128 }
00129
00130
00131
00132
00133 void TimeSelector::setFocusOnCount()
00134 {
00135 mPeriod->setFocusOnCount();
00136 }
00137
00138
00139
00140
00141 void TimeSelector::selectToggled(bool on)
00142 {
00143 mPeriod->setEnabled(on);
00144 if (mLabel)
00145 mLabel->setEnabled(on);
00146 if (on)
00147 mPeriod->setFocus();
00148 emit toggled(on);
00149 emit valueChanged(minutes());
00150 }
00151
00152
00153
00154
00155 void TimeSelector::periodChanged(int minutes)
00156 {
00157 if (mSelect->isChecked())
00158 emit valueChanged(minutes);
00159 }
|