• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm

  • sources
  • kde-4.14
  • kdepim
  • kalarm
latecancel.cpp
Go to the documentation of this file.
1 /*
2  * latecancel.cpp - widget to specify cancellation if late
3  * Program: kalarm
4  * Copyright © 2004,2005,2007-2011 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h"
22 #include "latecancel.h"
23 
24 #include "checkbox.h"
25 
26 #ifdef USE_AKONADI
27 #include <kcalcore/duration.h>
28 using namespace KCalCore;
29 #else
30 #include <kcal/duration.h>
31 using namespace KCal;
32 #endif
33 
34 #include <klocale.h>
35 #include <kdialog.h>
36 
37 #include <QStackedWidget>
38 #include <QVBoxLayout>
39 #include <QHBoxLayout>
40 
41 
42 // Collect these widget labels together to ensure consistent wording and
43 // translations across different modules.
44 QString LateCancelSelector::i18n_chk_CancelIfLate() { return i18nc("@option:check", "Cancel if late"); }
45 QString LateCancelSelector::i18n_chk_AutoCloseWin() { return i18nc("@option:check", "Auto-close window after this time"); }
46 QString LateCancelSelector::i18n_chk_AutoCloseWinLC() { return i18nc("@option:check", "Auto-close window after late-cancellation time"); }
47 
48 
49 LateCancelSelector::LateCancelSelector(bool allowHourMinute, QWidget* parent)
50  : QFrame(parent),
51  mDateOnly(false),
52  mReadOnly(false),
53  mAutoCloseShown(false)
54 {
55  QString whatsThis = i18nc("@info:whatsthis",
56  "<para>If checked, the alarm will be canceled if it cannot be triggered within the "
57  "specified period after its scheduled time. Possible reasons for not triggering "
58  "include your being logged off, X not running, or <application>KAlarm</application> not running.</para>"
59  "<para>If unchecked, the alarm will be triggered at the first opportunity after "
60  "its scheduled time, regardless of how late it is.</para>");
61 
62  QVBoxLayout* topLayout = new QVBoxLayout(this);
63  topLayout->setMargin(0);
64  topLayout->setSpacing(KDialog::spacingHint());
65 
66  mStack = new QStackedWidget(this);
67  topLayout->addWidget(mStack, 0, Qt::AlignLeft);
68  mCheckboxFrame = new QFrame();
69  mStack->addWidget(mCheckboxFrame);
70  QHBoxLayout* hlayout = new QHBoxLayout(mCheckboxFrame);
71  hlayout->setMargin(0);
72  mCheckbox = new CheckBox(i18n_chk_CancelIfLate(), mCheckboxFrame);
73  connect(mCheckbox, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
74  connect(mCheckbox, SIGNAL(toggled(bool)), SIGNAL(changed()));
75  mCheckbox->setWhatsThis(whatsThis);
76  hlayout->addWidget(mCheckbox, 0, Qt::AlignLeft);
77 
78  mTimeSelectorFrame = new QFrame();
79  mStack->addWidget(mTimeSelectorFrame);
80  hlayout = new QHBoxLayout(mTimeSelectorFrame);
81  hlayout->setMargin(0);
82  mTimeSelector = new TimeSelector(i18nc("@option:check Cancel if late by 10 minutes", "Cancel if late by"),
83  whatsThis, i18nc("@info:whatsthis", "Enter how late will cause the alarm to be canceled"),
84  allowHourMinute, mTimeSelectorFrame);
85  connect(mTimeSelector, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
86 #ifdef USE_AKONADI
87  connect(mTimeSelector, SIGNAL(valueChanged(KCalCore::Duration)), SIGNAL(changed()));
88 #else
89  connect(mTimeSelector, SIGNAL(valueChanged(KCal::Duration)), SIGNAL(changed()));
90 #endif
91  hlayout->addWidget(mTimeSelector, 0, Qt::AlignLeft);
92 
93  hlayout = new QHBoxLayout();
94  hlayout->setMargin(0);
95  hlayout->addSpacing(3*KDialog::spacingHint());
96  topLayout->addLayout(hlayout);
97  mAutoClose = new CheckBox(i18n_chk_AutoCloseWin(), this);
98  connect(mAutoClose, SIGNAL(toggled(bool)), SIGNAL(changed()));
99  mAutoClose->setWhatsThis(i18nc("@info:whatsthis", "Automatically close the alarm window after the expiry of the late-cancellation period"));
100  hlayout->addWidget(mAutoClose);
101  hlayout->addStretch();
102 
103  mAutoClose->hide();
104  mAutoClose->setEnabled(false);
105 }
106 
107 /******************************************************************************
108 * Set the read-only status.
109 */
110 void LateCancelSelector::setReadOnly(bool ro)
111 {
112  if ((int)ro != (int)mReadOnly)
113  {
114  mReadOnly = ro;
115  mCheckbox->setReadOnly(mReadOnly);
116  mTimeSelector->setReadOnly(mReadOnly);
117  mAutoClose->setReadOnly(mReadOnly);
118  }
119 }
120 
121 int LateCancelSelector::minutes() const
122 {
123  return mTimeSelector->period().asSeconds() / 60;
124 }
125 
126 void LateCancelSelector::setMinutes(int minutes, bool dateOnly, TimePeriod::Units defaultUnits)
127 {
128  slotToggled(minutes);
129  Duration period;
130  if (minutes % (24*60))
131  period = Duration(minutes * 60, Duration::Seconds);
132  else
133  period = Duration(minutes / (24*60), Duration::Days);
134  mTimeSelector->setPeriod(period, dateOnly, defaultUnits);
135 }
136 
137 void LateCancelSelector::setDateOnly(bool dateOnly)
138 {
139  if (dateOnly != mDateOnly)
140  {
141  mDateOnly = dateOnly;
142  if (mTimeSelector->isChecked()) // don't change when it's not visible
143  mTimeSelector->setDateOnly(dateOnly);
144  }
145 }
146 
147 void LateCancelSelector::showAutoClose(bool show)
148 {
149  if (show)
150  mAutoClose->show();
151  else
152  mAutoClose->hide();
153  mAutoCloseShown = show;
154  updateGeometry();
155 }
156 
157 bool LateCancelSelector::isAutoClose() const
158 {
159  return mAutoCloseShown && mAutoClose->isEnabled() && mAutoClose->isChecked();
160 }
161 
162 void LateCancelSelector::setAutoClose(bool autoClose)
163 {
164  mAutoClose->setChecked(autoClose);
165 }
166 
167 /******************************************************************************
168 * Called when either of the checkboxes is toggled.
169 */
170 void LateCancelSelector::slotToggled(bool on)
171 {
172  mCheckbox->setChecked(on);
173  mTimeSelector->setChecked(on);
174  if (on)
175  {
176  mTimeSelector->setDateOnly(mDateOnly);
177  mStack->setCurrentWidget(mTimeSelectorFrame);
178  }
179  else
180  mStack->setCurrentWidget(mCheckboxFrame);
181  mAutoClose->setEnabled(on);
182 }
183 #include "moc_latecancel.cpp"
184 // vim: et sw=4:
QFrame::QFrame
QFrame(QWidget *parent, QFlags< Qt::WindowType > f)
CheckBox::setReadOnly
virtual void setReadOnly(bool readOnly)
QWidget
TimeSelector::isChecked
bool isChecked() const
Definition: timeselector.cpp:101
TimePeriod::Units
Units
QWidget::updateGeometry
void updateGeometry()
LateCancelSelector::LateCancelSelector
LateCancelSelector(bool allowHourMinute, QWidget *parent)
Definition: latecancel.cpp:49
LateCancelSelector::i18n_chk_CancelIfLate
static QString i18n_chk_CancelIfLate()
Definition: latecancel.cpp:44
TimeSelector::setReadOnly
void setReadOnly(bool)
Definition: timeselector.cpp:89
TimeSelector::setChecked
void setChecked(bool on)
Definition: timeselector.cpp:106
LateCancelSelector::showAutoClose
void showAutoClose(bool show)
Definition: latecancel.cpp:147
latecancel.h
QHBoxLayout
QBoxLayout::addSpacing
void addSpacing(int size)
checkbox.h
LateCancelSelector::changed
void changed()
QWidget::setEnabled
void setEnabled(bool)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QStackedWidget::setCurrentWidget
void setCurrentWidget(QWidget *widget)
CheckBox
QVBoxLayout
LateCancelSelector::i18n_chk_AutoCloseWin
static QString i18n_chk_AutoCloseWin()
Definition: latecancel.cpp:45
QStackedWidget
QString
QWidget::hide
void hide()
QLayout::setMargin
void setMargin(int margin)
QFrame
LateCancelSelector::setReadOnly
void setReadOnly(bool)
Definition: latecancel.cpp:110
LateCancelSelector::setDateOnly
void setDateOnly(bool dateOnly)
Definition: latecancel.cpp:137
QAbstractButton::isChecked
bool isChecked() const
QWidget::whatsThis
QString whatsThis() const
LateCancelSelector::minutes
int minutes() const
Definition: latecancel.cpp:121
TimeSelector::setDateOnly
void setDateOnly(bool dateOnly=true)
Definition: timeselector.cpp:120
QBoxLayout::addStretch
void addStretch(int stretch)
LateCancelSelector::i18n_chk_AutoCloseWinLC
static QString i18n_chk_AutoCloseWinLC()
Definition: latecancel.cpp:46
LateCancelSelector::isAutoClose
bool isAutoClose() const
Definition: latecancel.cpp:157
kalarm.h
TimeSelector
Definition: timeselector.h:31
TimeSelector::setPeriod
void setPeriod(const KCal::Duration &, bool dateOnly, TimePeriod::Units defaultUnits)
Definition: timeselector.cpp:140
QWidget::show
void show()
LateCancelSelector::setMinutes
void setMinutes(int Minutes, bool dateOnly, TimePeriod::Units defaultUnits)
Definition: latecancel.cpp:126
QStackedWidget::addWidget
int addWidget(QWidget *widget)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QBoxLayout::setSpacing
void setSpacing(int spacing)
LateCancelSelector::setAutoClose
void setAutoClose(bool autoClose)
Definition: latecancel.cpp:162
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
TimeSelector::period
KCal::Duration period() const
Definition: timeselector.cpp:129
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal