kalarm

reminder.cpp

00001 /*
00002  *  reminder.cpp  -  reminder setting widget
00003  *  Program:  kalarm
00004  *  Copyright (C) 2003 - 2005 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "kalarm.h"
00022 
00023 #include <qlayout.h>
00024 #include <qwhatsthis.h>
00025 
00026 #include <kglobal.h>
00027 #include <klocale.h>
00028 #include <kdialog.h>
00029 #include <kdebug.h>
00030 
00031 #include "preferences.h"
00032 #include "checkbox.h"
00033 #include "timeselector.h"
00034 #include "reminder.moc"
00035 
00036 
00037 // Collect these widget labels together to ensure consistent wording and
00038 // translations across different modules.
00039 QString Reminder::i18n_first_recurrence_only()   { return i18n("Reminder for first recurrence only"); }
00040 QString Reminder::i18n_u_first_recurrence_only() { return i18n("Reminder for first rec&urrence only"); }
00041 
00042 
00043 Reminder::Reminder(const QString& caption, const QString& reminderWhatsThis, const QString& valueWhatsThis,
00044                    bool allowHourMinute, bool showOnceOnly, QWidget* parent, const char* name)
00045     : QFrame(parent, name),
00046       mReadOnly(false),
00047       mOnceOnlyEnabled(showOnceOnly)
00048 {
00049     setFrameStyle(QFrame::NoFrame);
00050     QVBoxLayout* topLayout = new QVBoxLayout(this, 0, KDialog::spacingHint());
00051 
00052     mTime = new TimeSelector(caption, i18n("in advance"), reminderWhatsThis,
00053                            valueWhatsThis, allowHourMinute, this, "timeOption");
00054     mTime->setFixedSize(mTime->sizeHint());
00055     connect(mTime, SIGNAL(toggled(bool)), SLOT(slotReminderToggled(bool)));
00056     topLayout->addWidget(mTime);
00057 
00058     if (showOnceOnly)
00059     {
00060         QBoxLayout* layout = new QHBoxLayout(topLayout, KDialog::spacingHint());
00061         layout->addSpacing(3*KDialog::spacingHint());
00062         mOnceOnly = new CheckBox(i18n_u_first_recurrence_only(), this);
00063         mOnceOnly->setFixedSize(mOnceOnly->sizeHint());
00064         QWhatsThis::add(mOnceOnly, i18n("Display the reminder only before the first time the alarm is scheduled"));
00065         layout->addWidget(mOnceOnly);
00066         layout->addStretch();
00067     }
00068     else
00069         mOnceOnly = 0;
00070 }
00071 
00072 /******************************************************************************
00073 *  Set the read-only status.
00074 */
00075 void Reminder::setReadOnly(bool ro)
00076 {
00077     if ((int)ro != (int)mReadOnly)
00078     {
00079         mReadOnly = ro;
00080         mTime->setReadOnly(mReadOnly);
00081         if (mOnceOnly)
00082             mOnceOnly->setReadOnly(mReadOnly);
00083     }
00084 }
00085 
00086 bool Reminder::isReminder() const
00087 {
00088     return mTime->isChecked();
00089 }
00090 
00091 bool Reminder::isOnceOnly() const
00092 {
00093     return mOnceOnly  &&  mOnceOnly->isEnabled()  &&  mOnceOnly->isChecked();
00094 }
00095 
00096 void Reminder::setOnceOnly(bool onceOnly)
00097 {
00098     if (mOnceOnly)
00099         mOnceOnly->setChecked(onceOnly);
00100 }
00101 
00102 /******************************************************************************
00103 *  Specify whether the once-only checkbox is allowed to be enabled.
00104 */
00105 void Reminder::enableOnceOnly(bool enable)
00106 {
00107     if (mOnceOnly)
00108     {
00109         mOnceOnlyEnabled = enable;
00110         mOnceOnly->setEnabled(enable && mTime->isChecked());
00111     }
00112 }
00113 
00114 void Reminder::setMaximum(int hourmin, int days)
00115 {
00116     mTime->setMaximum(hourmin, days);
00117 }
00118 
00119 /******************************************************************************
00120  * Get the specified number of minutes in advance of the main alarm the
00121  * reminder is to be.
00122  */
00123 int Reminder::minutes() const
00124 {
00125     return mTime->minutes();
00126 }
00127 
00128 /******************************************************************************
00129 *  Initialise the controls with a specified reminder time.
00130 */
00131 void Reminder::setMinutes(int minutes, bool dateOnly)
00132 {
00133     mTime->setMinutes(minutes, dateOnly, Preferences::defaultReminderUnits());
00134 }
00135 
00136 /******************************************************************************
00137 *  Set the advance reminder units to days if "Any time" is checked.
00138 */
00139 void Reminder::setDateOnly(bool dateOnly)
00140 {
00141     mTime->setDateOnly(dateOnly);
00142 }
00143 
00144 /******************************************************************************
00145 *  Set the input focus on the count field.
00146 */
00147 void Reminder::setFocusOnCount()
00148 {
00149     mTime->setFocusOnCount();
00150 }
00151 
00152 /******************************************************************************
00153 *  Called when the Reminder checkbox is toggled.
00154 */
00155 void Reminder::slotReminderToggled(bool on)
00156 {
00157     if (mOnceOnly)
00158         mOnceOnly->setEnabled(on && mOnceOnlyEnabled);
00159 }
KDE Home | KDE Accessibility Home | Description of Access Keys