kalarm
latecancel.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 <QStackedWidget>
00024 #include <QVBoxLayout>
00025 #include <QHBoxLayout>
00026
00027 #include <klocale.h>
00028 #include <kdialog.h>
00029 #include <kcal/duration.h>
00030
00031 #include "checkbox.h"
00032 #include "latecancel.moc"
00033
00034
00035
00036
00037 QString LateCancelSelector::i18n_chk_CancelIfLate() { return i18nc("@option:check", "Cancel if late"); }
00038 QString LateCancelSelector::i18n_chk_AutoCloseWin() { return i18nc("@option:check", "Auto-close window after this time"); }
00039 QString LateCancelSelector::i18n_chk_AutoCloseWinLC() { return i18nc("@option:check", "Auto-close window after late-cancellation time"); }
00040
00041
00042 LateCancelSelector::LateCancelSelector(bool allowHourMinute, QWidget* parent)
00043 : QFrame(parent),
00044 mDateOnly(false),
00045 mReadOnly(false),
00046 mAutoCloseShown(false)
00047 {
00048 QString whatsThis = i18nc("@info:whatsthis",
00049 "<para>If checked, the alarm will be canceled if it cannot be triggered within the "
00050 "specified period after its scheduled time. Possible reasons for not triggering "
00051 "include your being logged off, X not running, or <application>KAlarm</application> not running.</para>"
00052 "<para>If unchecked, the alarm will be triggered at the first opportunity after "
00053 "its scheduled time, regardless of how late it is.</para>");
00054
00055 QVBoxLayout* topLayout = new QVBoxLayout(this);
00056 topLayout->setMargin(0);
00057 topLayout->setSpacing(KDialog::spacingHint());
00058
00059 mStack = new QStackedWidget(this);
00060 topLayout->addWidget(mStack, 0, Qt::AlignLeft);
00061 mCheckboxFrame = new QFrame();
00062 mStack->addWidget(mCheckboxFrame);
00063 QHBoxLayout* hlayout = new QHBoxLayout(mCheckboxFrame);
00064 hlayout->setMargin(0);
00065 mCheckbox = new CheckBox(i18n_chk_CancelIfLate(), mCheckboxFrame);
00066 connect(mCheckbox, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
00067 mCheckbox->setWhatsThis(whatsThis);
00068 hlayout->addWidget(mCheckbox, 0, Qt::AlignLeft);
00069
00070 mTimeSelectorFrame = new QFrame();
00071 mStack->addWidget(mTimeSelectorFrame);
00072 hlayout = new QHBoxLayout(mTimeSelectorFrame);
00073 hlayout->setMargin(0);
00074 mTimeSelector = new TimeSelector(i18nc("@option:check Cancel if late by 10 minutes", "Cancel if late by"), QString(),
00075 whatsThis, i18nc("@info:whatsthis", "Enter how late will cause the alarm to be canceled"),
00076 allowHourMinute, mTimeSelectorFrame);
00077 connect(mTimeSelector, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
00078 hlayout->addWidget(mTimeSelector, 0, Qt::AlignLeft);
00079
00080 hlayout = new QHBoxLayout();
00081 hlayout->setMargin(0);
00082 hlayout->addSpacing(3*KDialog::spacingHint());
00083 topLayout->addLayout(hlayout);
00084 mAutoClose = new CheckBox(i18n_chk_AutoCloseWin(), this);
00085 mAutoClose->setWhatsThis(i18nc("@info:whatsthis", "Automatically close the alarm window after the expiry of the late-cancellation period"));
00086 hlayout->addWidget(mAutoClose);
00087 hlayout->addStretch();
00088
00089 mAutoClose->hide();
00090 mAutoClose->setEnabled(false);
00091 }
00092
00093
00094
00095
00096 void LateCancelSelector::setReadOnly(bool ro)
00097 {
00098 if ((int)ro != (int)mReadOnly)
00099 {
00100 mReadOnly = ro;
00101 mCheckbox->setReadOnly(mReadOnly);
00102 mTimeSelector->setReadOnly(mReadOnly);
00103 mAutoClose->setReadOnly(mReadOnly);
00104 }
00105 }
00106
00107 int LateCancelSelector::minutes() const
00108 {
00109 return mTimeSelector->period().asSeconds() / 60;
00110 }
00111
00112 void LateCancelSelector::setMinutes(int minutes, bool dateOnly, TimePeriod::Units defaultUnits)
00113 {
00114 slotToggled(minutes);
00115 KCal::Duration period;
00116 if (minutes % (24*60))
00117 period = KCal::Duration(minutes * 60, KCal::Duration::Seconds);
00118 else
00119 period = KCal::Duration(minutes / (24*60), KCal::Duration::Days);
00120 mTimeSelector->setPeriod(period, dateOnly, defaultUnits);
00121 }
00122
00123 void LateCancelSelector::setDateOnly(bool dateOnly)
00124 {
00125 if (dateOnly != mDateOnly)
00126 {
00127 mDateOnly = dateOnly;
00128 if (mTimeSelector->isChecked())
00129 mTimeSelector->setDateOnly(dateOnly);
00130 }
00131 }
00132
00133 void LateCancelSelector::showAutoClose(bool show)
00134 {
00135 if (show)
00136 mAutoClose->show();
00137 else
00138 mAutoClose->hide();
00139 mAutoCloseShown = show;
00140 updateGeometry();
00141 }
00142
00143 bool LateCancelSelector::isAutoClose() const
00144 {
00145 return mAutoCloseShown && mAutoClose->isEnabled() && mAutoClose->isChecked();
00146 }
00147
00148 void LateCancelSelector::setAutoClose(bool autoClose)
00149 {
00150 mAutoClose->setChecked(autoClose);
00151 }
00152
00153
00154
00155
00156 void LateCancelSelector::slotToggled(bool on)
00157 {
00158 mCheckbox->setChecked(on);
00159 mTimeSelector->setChecked(on);
00160 if (on)
00161 {
00162 mTimeSelector->setDateOnly(mDateOnly);
00163 mStack->setCurrentWidget(mTimeSelectorFrame);
00164 }
00165 else
00166 mStack->setCurrentWidget(mCheckboxFrame);
00167 mAutoClose->setEnabled(on);
00168 }