24 #include <tqwhatsthis.h>
28 #include <tdelocale.h>
30 #include "buttongroup.h"
31 #include "radiobutton.h"
33 #include "timeperiod.h"
34 #include "timeselector.h"
35 #include "repetition.moc"
43 RepetitionButton::RepetitionButton(
const TQString& caption,
bool waitForInitialisation, TQWidget* parent,
const char* name)
44 : TQPushButton(caption, parent, name),
50 mWaitForInit(waitForInitialisation),
53 setToggleButton(
true);
55 connect(
this, TQ_SIGNAL(clicked()), TQ_SLOT(slotPressed()));
58 void RepetitionButton::set(
int interval,
int count)
62 setOn(mInterval && mCount);
68 void RepetitionButton::set(
int interval,
int count,
bool dateOnly,
int maxDuration)
72 mMaxDuration = maxDuration;
74 setOn(mInterval && mCount);
82 void RepetitionButton::activate(
bool waitForInitialisation)
85 mDialog =
new RepetitionDlg(i18n(
"Alarm Sub-Repetition"), mReadOnly,
this);
86 mDialog->set(mInterval, mCount, mDateOnly, mMaxDuration);
87 if (waitForInitialisation)
88 emit needsInitialisation();
97 void RepetitionButton::initialise(
int interval,
int count,
bool dateOnly,
int maxDuration)
99 if (maxDuration > 0 && interval > maxDuration)
102 mInterval = interval;
103 mMaxDuration = maxDuration;
104 mDateOnly = dateOnly;
107 mDialog->set(interval, count, dateOnly, maxDuration);
111 setOn(mInterval && mCount);
121 void RepetitionButton::displayDialog()
123 kdDebug(5950) <<
"RepetitionButton::displayDialog()" << endl;
127 mDialog->setReadOnly(
true);
130 else if (mDialog->exec() == TQDialog::Accepted)
132 mCount = mDialog->count();
133 mInterval = mDialog->interval();
136 setOn(mInterval && mCount);
149 static const int MAX_COUNT = 9999;
152 RepetitionDlg::RepetitionDlg(
const TQString& caption,
bool readOnly, TQWidget* parent,
const char* name)
153 : KDialogBase(parent, name, true, caption, Ok|Cancel),
158 int spacing = spacingHint();
159 TQWidget* page =
new TQWidget(
this);
161 TQVBoxLayout* topLayout =
new TQVBoxLayout(page, 0, spacing);
163 mTimeSelector =
new TimeSelector(i18n(
"Repeat every 10 minutes",
"&Repeat every"), TQString(),
164 i18n(
"Instead of the alarm triggering just once at each recurrence, "
165 "checking this option makes the alarm trigger multiple times at each recurrence."),
166 i18n(
"Enter the time between repetitions of the alarm"),
168 mTimeSelector->setFixedSize(mTimeSelector->sizeHint());
169 connect(mTimeSelector, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(intervalChanged(
int)));
170 connect(mTimeSelector, TQ_SIGNAL(toggled(
bool)), TQ_SLOT(repetitionToggled(
bool)));
171 topLayout->addWidget(mTimeSelector, 0, TQt::AlignAuto);
173 mButtonGroup =
new ButtonGroup(page,
"buttonGroup");
174 connect(mButtonGroup, TQ_SIGNAL(buttonSet(
int)), TQ_SLOT(typeClicked()));
175 topLayout->addWidget(mButtonGroup);
177 TQBoxLayout* vlayout =
new TQVBoxLayout(mButtonGroup, marginHint(), spacing);
178 TQBoxLayout* layout =
new TQHBoxLayout(vlayout, spacing);
179 mCountButton =
new RadioButton(i18n(
"&Number of repetitions:"), mButtonGroup);
180 mCountButton->setFixedSize(mCountButton->sizeHint());
181 TQWhatsThis::add(mCountButton,
182 i18n(
"Check to specify the number of times the alarm should repeat after each recurrence"));
183 layout->addWidget(mCountButton);
184 mCount =
new SpinBox(1, MAX_COUNT, 1, mButtonGroup);
185 mCount->setFixedSize(mCount->sizeHint());
186 mCount->setLineShiftStep(10);
187 mCount->setSelectOnStep(
false);
188 connect(mCount, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(countChanged(
int)));
189 TQWhatsThis::add(mCount,
190 i18n(
"Enter the number of times to trigger the alarm after its initial occurrence"));
191 layout->addWidget(mCount);
192 mCountButton->setFocusWidget(mCount);
193 layout->addStretch();
195 layout =
new TQHBoxLayout(vlayout, spacing);
196 mDurationButton =
new RadioButton(i18n(
"&Duration:"), mButtonGroup);
197 mDurationButton->setFixedSize(mDurationButton->sizeHint());
198 TQWhatsThis::add(mDurationButton,
199 i18n(
"Check to specify how long the alarm is to be repeated"));
200 layout->addWidget(mDurationButton);
201 mDuration =
new TimePeriod(
true, mButtonGroup);
202 mDuration->setFixedSize(mDuration->sizeHint());
203 connect(mDuration, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(durationChanged(
int)));
204 TQWhatsThis::add(mDuration,
205 i18n(
"Enter the length of time to repeat the alarm"));
206 layout->addWidget(mDuration);
207 mDurationButton->setFocusWidget(mDuration);
208 layout->addStretch();
210 mCountButton->setChecked(
true);
211 repetitionToggled(
false);
212 setReadOnly(mReadOnly);
218 void RepetitionDlg::set(
int interval,
int count,
bool dateOnly,
int maxDuration)
224 if (dateOnly != mDateOnly)
226 mDateOnly = dateOnly;
227 mTimeSelector->setDateOnly(mDateOnly);
228 mDuration->setDateOnly(mDateOnly);
230 mMaxDuration = maxDuration;
233 int maxhm = (mMaxDuration > 0) ? mMaxDuration : 9999;
234 int maxdw = (mMaxDuration > 0) ? mMaxDuration / 1440 : 9999;
235 mTimeSelector->setMaximum(maxhm, maxdw);
236 mDuration->setMaximum(maxhm, maxdw);
239 TimePeriod::Units units = mDateOnly ? TimePeriod::DAYS : TimePeriod::HOURS_MINUTES;
240 mTimeSelector->setMinutes(interval, mDateOnly, units);
241 if (!mMaxDuration || !count)
242 mTimeSelector->setChecked(
false);
245 bool on = mTimeSelector->isChecked();
246 repetitionToggled(on);
248 intervalChanged(interval);
249 mCount->setValue(count);
250 mDuration->setMinutes(count * interval, mDateOnly, units);
251 mCountButton->setChecked(
true);
253 mTimeSelector->setEnabled(mMaxDuration);
259 void RepetitionDlg::setReadOnly(
bool ro)
261 ro = ro || mReadOnly;
262 mTimeSelector->setReadOnly(ro);
263 mCountButton->setReadOnly(ro);
264 mCount->setReadOnly(ro);
265 mDurationButton->setReadOnly(ro);
266 mDuration->setReadOnly(ro);
272 int RepetitionDlg::interval()
const
274 return mTimeSelector->minutes();
280 int RepetitionDlg::count()
const
282 int interval = mTimeSelector->minutes();
285 if (mCountButton->isOn())
286 return mCount->value();
287 if (mDurationButton->isOn())
288 return mDuration->minutes() / interval;
297 void RepetitionDlg::intervalChanged(
int minutes)
299 if (mTimeSelector->isChecked() && minutes > 0)
301 mCount->setRange(1, (mMaxDuration >= 0 ? mMaxDuration / minutes : MAX_COUNT));
302 if (mCountButton->isOn())
303 countChanged(mCount->value());
305 durationChanged(mDuration->minutes());
313 void RepetitionDlg::countChanged(
int count)
315 int interval = mTimeSelector->minutes();
318 bool blocked = mDuration->signalsBlocked();
319 mDuration->blockSignals(
true);
320 mDuration->setMinutes(count * interval, mDateOnly,
321 (mDateOnly ? TimePeriod::DAYS : TimePeriod::HOURS_MINUTES));
322 mDuration->blockSignals(blocked);
330 void RepetitionDlg::durationChanged(
int minutes)
332 int interval = mTimeSelector->minutes();
335 bool blocked = mCount->signalsBlocked();
336 mCount->blockSignals(
true);
337 mCount->setValue(minutes / interval);
338 mCount->blockSignals(blocked);
345 void RepetitionDlg::repetitionToggled(
bool on)
347 if (mMaxDuration == 0)
349 mButtonGroup->setEnabled(on);
350 mCount->setEnabled(on && mCountButton->isOn());
351 mDuration->setEnabled(on && mDurationButton->isOn());
357 void RepetitionDlg::typeClicked()
359 if (mTimeSelector->isChecked())
361 mCount->setEnabled(mCountButton->isOn());
362 mDuration->setEnabled(mDurationButton->isOn());