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