22 #include "repetitionbutton.moc"
34 #include <QVBoxLayout>
35 #include <QHBoxLayout>
38 using namespace KCalCore;
54 mWaitForInit(waitForInitialisation),
59 connect(
this, SIGNAL(clicked()), SLOT(slotPressed()));
65 setChecked(mRepetition);
74 mMaxDuration = maxDuration;
76 setChecked(mRepetition);
87 mDialog =
new RepetitionDlg(i18nc(
"@title:window",
"Alarm Sub-Repetition"), mReadOnly,
this);
88 mDialog->
set(mRepetition, mDateOnly, mMaxDuration);
89 if (waitForInitialisation)
101 mRepetition = (maxDuration > 0 && repetition.intervalMinutes() > maxDuration)
103 mMaxDuration = maxDuration;
104 mDateOnly = dateOnly;
107 mDialog->
set(mRepetition, dateOnly, maxDuration);
111 setChecked(mRepetition);
121 void RepetitionButton::displayDialog()
129 else if (mDialog->exec() == QDialog::Accepted)
134 setChecked(mRepetition);
157 setButtons(Ok|Cancel);
158 int spacing = spacingHint();
161 QVBoxLayout* topLayout =
new QVBoxLayout(page);
162 topLayout->setMargin(0);
163 topLayout->setSpacing(spacing);
165 mTimeSelector =
new TimeSelector(i18nc(
"@option:check Repeat every 10 minutes",
"Repeat every"),
166 i18nc(
"@info:whatsthis",
"Instead of the alarm triggering just once at each recurrence, "
167 "checking this option makes the alarm trigger multiple times at each recurrence."),
168 i18nc(
"@info:whatsthis",
"Enter the time between repetitions of the alarm"),
170 mTimeSelector->setFixedSize(mTimeSelector->sizeHint());
172 connect(mTimeSelector, SIGNAL(valueChanged(KCalCore::Duration)), SLOT(intervalChanged(KCalCore::Duration)));
174 connect(mTimeSelector, SIGNAL(valueChanged(KCal::Duration)), SLOT(intervalChanged(KCal::Duration)));
176 connect(mTimeSelector, SIGNAL(toggled(
bool)), SLOT(repetitionToggled(
bool)));
177 topLayout->addWidget(mTimeSelector, 0, Qt::AlignLeft);
180 topLayout->addWidget(mButtonBox);
182 connect(mButtonGroup, SIGNAL(buttonSet(QAbstractButton*)), SLOT(typeClicked()));
184 QVBoxLayout* vlayout =
new QVBoxLayout(mButtonBox);
185 vlayout->setMargin(marginHint());
186 vlayout->setSpacing(spacing);
187 QHBoxLayout* layout =
new QHBoxLayout();
188 layout->setMargin(0);
189 vlayout->addLayout(layout);
190 mCountButton =
new RadioButton(i18nc(
"@option:radio",
"Number of repetitions:"), mButtonBox);
191 mCountButton->setFixedSize(mCountButton->sizeHint());
192 mCountButton->setWhatsThis(i18nc(
"@info:whatsthis",
"Check to specify the number of times the alarm should repeat after each recurrence"));
194 layout->addWidget(mCountButton);
196 mCount->setFixedSize(mCount->sizeHint());
197 mCount->setSingleShiftStep(10);
198 mCount->setSelectOnStep(
false);
199 connect(mCount, SIGNAL(valueChanged(
int)), SLOT(countChanged(
int)));
200 mCount->setWhatsThis(i18nc(
"@info:whatsthis",
"Enter the number of times to trigger the alarm after its initial occurrence"));
201 layout->addWidget(mCount);
203 layout->addStretch();
205 layout =
new QHBoxLayout();
206 layout->setMargin(0);
207 vlayout->addLayout(layout);
208 mDurationButton =
new RadioButton(i18nc(
"@option:radio",
"Duration:"), mButtonBox);
209 mDurationButton->setFixedSize(mDurationButton->sizeHint());
210 mDurationButton->setWhatsThis(i18nc(
"@info:whatsthis",
"Check to specify how long the alarm is to be repeated"));
211 mButtonGroup->
addButton(mDurationButton);
212 layout->addWidget(mDurationButton);
214 mDuration->setFixedSize(mDuration->sizeHint());
216 connect(mDuration, SIGNAL(valueChanged(KCalCore::Duration)), SLOT(durationChanged(KCalCore::Duration)));
218 connect(mDuration, SIGNAL(valueChanged(KCal::Duration)), SLOT(durationChanged(KCal::Duration)));
220 mDuration->setWhatsThis(i18nc(
"@info:whatsthis",
"Enter the length of time to repeat the alarm"));
221 layout->addWidget(mDuration);
223 layout->addStretch();
225 mCountButton->setChecked(
true);
226 repetitionToggled(
false);
235 if (dateOnly != mDateOnly)
237 mDateOnly = dateOnly;
241 mMaxDuration = maxDuration;
244 int maxhm = (mMaxDuration > 0) ? mMaxDuration : 9999;
245 int maxdw = (mMaxDuration > 0) ? mMaxDuration / 1440 : 9999;
251 mTimeSelector->
setPeriod(repetition.interval(), mDateOnly, units);
252 if (!mMaxDuration || !repetition)
257 repetitionToggled(on);
259 intervalChanged(repetition.interval());
260 mCount->setValue(repetition.count());
261 mDuration->
setPeriod(repetition.duration(), mDateOnly, units);
262 mCountButton->setChecked(
true);
264 mTimeSelector->setEnabled(mMaxDuration);
272 ro = ro || mReadOnly;
275 mCount->setReadOnly(ro);
286 Duration interval = mTimeSelector->
period();
289 if (mCountButton->isChecked())
290 count = mCount->value();
291 else if (mDurationButton->isChecked())
292 count = mDuration->
period().asSeconds() / interval.asSeconds();
294 return Repetition(interval, count);
301 void RepetitionDlg::intervalChanged(
const Duration& interval)
303 if (mTimeSelector->
isChecked() && interval.asSeconds() > 0)
305 mCount->setRange(1, (mMaxDuration >= 0 ? mMaxDuration / (interval.asSeconds()/60) :
MAX_COUNT));
306 if (mCountButton->isChecked())
307 countChanged(mCount->value());
309 durationChanged(mDuration->
period());
317 void RepetitionDlg::countChanged(
int count)
319 Duration interval = mTimeSelector->
period();
322 bool blocked = mDuration->signalsBlocked();
323 mDuration->blockSignals(
true);
324 mDuration->
setPeriod(interval * count, mDateOnly,
326 mDuration->blockSignals(blocked);
334 void RepetitionDlg::durationChanged(
const Duration& duration)
336 Duration interval = mTimeSelector->
period();
339 bool blocked = mCount->signalsBlocked();
340 mCount->blockSignals(
true);
341 mCount->setValue(duration.asSeconds() / interval.asSeconds());
342 mCount->blockSignals(blocked);
349 void RepetitionDlg::repetitionToggled(
bool on)
351 if (mMaxDuration == 0)
353 mButtonBox->setEnabled(on);
354 mCount->setEnabled(on && mCountButton->isChecked());
355 mDuration->setEnabled(on && mDurationButton->isChecked());
361 void RepetitionDlg::typeClicked()
365 mCount->setEnabled(mCountButton->isChecked());
366 mDuration->setEnabled(mDurationButton->isChecked());
void setMaximum(int hourmin, int days)
Repetition repetition() const
KCal::Duration period() const
void setPeriod(const KCal::Duration &period, bool dateOnly, Units defaultUnits)
virtual void setReadOnly(bool readOnly)
RepetitionDlg(const QString &caption, bool readOnly, QWidget *parent=0)
void setDateOnly(bool dateOnly=true)
void setDateOnly(bool dateOnly)
void setPeriod(const KCal::Duration &, bool dateOnly, TimePeriod::Units defaultUnits)
void set(const Repetition &, bool dateOnly=false, int maxDuration=-1)
void setMaximum(int hourmin, int days)
KCal::Duration period() const