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

kalarm

timeselector.cpp

Go to the documentation of this file.
00001 /*
00002  *  timeselector.cpp  -  widget to optionally set a time period
00003  *  Program:  kalarm
00004  *  Copyright © 2004,2005,2007 by David Jarvie <djarvie@kde.org>
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 <QLabel>
00024 #include <QVBoxLayout>
00025 #include <QHBoxLayout>
00026 
00027 #include <klocale.h>
00028 #include <kdialog.h>
00029 #include <khbox.h>
00030 #include <kdebug.h>
00031 
00032 #include "checkbox.h"
00033 #include "timeselector.moc"
00034 
00035 using namespace KCal;
00036 
00037 
00038 TimeSelector::TimeSelector(const QString& selectText, const QString& postfix, const QString& selectWhatsThis,
00039                            const QString& valueWhatsThis, bool allowHourMinute, QWidget* parent)
00040     : QFrame(parent),
00041       mLabel(0),
00042       mReadOnly(false)
00043 {
00044     QHBoxLayout* layout = new QHBoxLayout(this);
00045     layout->setMargin(0);
00046     layout->setSpacing(KDialog::spacingHint());
00047     mSelect = new CheckBox(selectText, this);
00048     mSelect->setFixedSize(mSelect->sizeHint());
00049     connect(mSelect, SIGNAL(toggled(bool)), SLOT(selectToggled(bool)));
00050     mSelect->setWhatsThis(selectWhatsThis);
00051     layout->addWidget(mSelect);
00052 
00053     KHBox* box = new KHBox(this);    // to group widgets for QWhatsThis text
00054     box->setSpacing(KDialog::spacingHint());
00055     layout->addWidget(box);
00056     mPeriod = new TimePeriod(allowHourMinute, box);
00057     mPeriod->setFixedSize(mPeriod->sizeHint());
00058     mPeriod->setSelectOnStep(false);
00059     connect(mPeriod, SIGNAL(valueChanged(const KCal::Duration&)), SLOT(periodChanged(const KCal::Duration&)));
00060     mSelect->setFocusWidget(mPeriod);
00061     mPeriod->setEnabled(false);
00062 
00063     if (!postfix.isEmpty())
00064     {
00065         mLabel = new QLabel(postfix, box);
00066         box->setWhatsThis(valueWhatsThis);
00067         mLabel->setEnabled(false);
00068     }
00069     layout->addStretch();
00070 }
00071 
00072 /******************************************************************************
00073 *  Set the read-only status.
00074 */
00075 void TimeSelector::setReadOnly(bool ro)
00076 {
00077     if ((int)ro != (int)mReadOnly)
00078     {
00079         mReadOnly = ro;
00080         mSelect->setReadOnly(mReadOnly);
00081         mPeriod->setReadOnly(mReadOnly);
00082     }
00083 }
00084 
00085 bool TimeSelector::isChecked() const
00086 {
00087     return mSelect->isChecked();
00088 }
00089 
00090 void TimeSelector::setChecked(bool on)
00091 {
00092     if (on != mSelect->isChecked())
00093     {
00094         mSelect->setChecked(on);
00095         emit valueChanged(period());
00096     }
00097 }
00098 
00099 void TimeSelector::setMaximum(int hourmin, int days)
00100 {
00101     mPeriod->setMaximum(hourmin, days);
00102 }
00103 
00104 void TimeSelector::setDateOnly(bool dateOnly)
00105 {
00106     mPeriod->setDateOnly(dateOnly);
00107 }
00108 
00109 /******************************************************************************
00110  * Get the specified number of minutes.
00111  * Reply = 0 if unselected.
00112  */
00113 Duration TimeSelector::period() const
00114 {
00115     return mSelect->isChecked() ? mPeriod->period() : Duration(0);
00116 }
00117 
00118 /******************************************************************************
00119 *  Initialise the controls with a specified time period.
00120 *  If minutes = 0, it will be deselected.
00121 *  The time unit combo-box is initialised to 'defaultUnits', but if 'dateOnly'
00122 *  is true, it will never be initialised to hours/minutes.
00123 */
00124 void TimeSelector::setPeriod(const Duration& period, bool dateOnly, TimePeriod::Units defaultUnits)
00125 {
00126     mSelect->setChecked(period);
00127     mPeriod->setEnabled(period);
00128     if (mLabel)
00129         mLabel->setEnabled(period);
00130     mPeriod->setPeriod(period, dateOnly, defaultUnits);
00131 }
00132 
00133 /******************************************************************************
00134 *  Set the input focus on the count field.
00135 */
00136 void TimeSelector::setFocusOnCount()
00137 {
00138     mPeriod->setFocusOnCount();
00139 }
00140 
00141 /******************************************************************************
00142 *  Called when the TimeSelector checkbox is toggled.
00143 */
00144 void TimeSelector::selectToggled(bool on)
00145 {
00146     mPeriod->setEnabled(on);
00147     if (mLabel)
00148         mLabel->setEnabled(on);
00149     if (on)
00150         mPeriod->setFocus();
00151     emit toggled(on);
00152     emit valueChanged(period());
00153 }
00154 
00155 /******************************************************************************
00156 *  Called when the period value changes.
00157 */
00158 void TimeSelector::periodChanged(const KCal::Duration& period)
00159 {
00160     if (mSelect->isChecked())
00161         emit valueChanged(period);
00162 }

kalarm

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

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal