• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

kdatewidget.cpp

00001 /*  This file is part of the KDE libraries
00002     Copyright (C) 2001 Waldo Bastian (bastian@kde.org)
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 */
00018 
00019 
00020 #include <tqpopupmenu.h>
00021 #include <tqcombobox.h>
00022 #include <tqlayout.h>
00023 #include <tqlineedit.h>
00024 
00025 #include "knuminput.h"
00026 #include "tdeglobal.h"
00027 #include "tdelocale.h"
00028 #include "kcalendarsystem.h"
00029 //#include "kdatepicker.h"
00030 #include "kdialog.h"
00031 
00032 #include "kdatewidget.h"
00033 
00034 class KDateWidgetSpinBox : public TQSpinBox
00035 {
00036 public:
00037   KDateWidgetSpinBox(int min, int max, TQWidget *parent)
00038     : TQSpinBox(min, max, 1, parent)
00039   {
00040      editor()->setAlignment(TQt::AlignRight);
00041   }
00042 };
00043 
00044 class KDateWidget::KDateWidgetPrivate
00045 {
00046 public:
00047    KDateWidgetSpinBox *m_day;
00048    TQComboBox *m_month;
00049    KDateWidgetSpinBox *m_year;
00050    TQDate m_dat;
00051 };
00052 
00053 
00054 KDateWidget::KDateWidget( TQWidget *parent, const char *name )
00055   : TQWidget( parent, name )
00056 {
00057   init(TQDate());
00058   setDate(TQDate());
00059 }
00060 
00061 // ### HPB change TQDate to const TQDate & in KDE 4.0
00062 KDateWidget::KDateWidget( TQDate date, TQWidget *parent,
00063                 const char *name )
00064   : TQWidget( parent, name )
00065 {
00066   init(date);
00067   setDate(date);
00068 }
00069 
00070 // ### CFM Repaced by init(const TQDate&). Can be safely removed
00071 //     when no risk of BIC
00072 void KDateWidget::init()
00073 {
00074   d = new KDateWidgetPrivate;
00075   TDELocale *locale = TDEGlobal::locale();
00076   TQHBoxLayout *layout = new TQHBoxLayout(this, 0, KDialog::spacingHint());
00077   layout->setAutoAdd(true);
00078   d->m_day = new KDateWidgetSpinBox(1, 1, this);
00079   d->m_month = new TQComboBox(false, this);
00080   for (int i = 1; ; ++i)
00081   {
00082     TQString str = locale->calendar()->monthName(i,
00083        locale->calendar()->year(TQDate()));
00084     if (str.isNull()) break;
00085     d->m_month->insertItem(str);
00086   }
00087 
00088   d->m_year = new KDateWidgetSpinBox(locale->calendar()->minValidYear(),
00089                      locale->calendar()->maxValidYear(), this);
00090 
00091   connect(d->m_day, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotDateChanged()));
00092   connect(d->m_month, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotDateChanged()));
00093   connect(d->m_year, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotDateChanged()));
00094 }
00095 
00096 void KDateWidget::init(const TQDate& date)
00097 {
00098   d = new KDateWidgetPrivate;
00099   TDELocale *locale = TDEGlobal::locale();
00100   TQHBoxLayout *layout = new TQHBoxLayout(this, 0, KDialog::spacingHint());
00101   layout->setAutoAdd(true);
00102   d->m_day = new KDateWidgetSpinBox(1, 1, this);
00103   d->m_month = new TQComboBox(false, this);
00104   for (int i = 1; ; ++i)
00105   {
00106     TQString str = locale->calendar()->monthName(i,
00107        locale->calendar()->year(date));
00108     if (str.isNull()) break;
00109     d->m_month->insertItem(str);
00110   }
00111 
00112   d->m_year = new KDateWidgetSpinBox(locale->calendar()->minValidYear(),
00113                      locale->calendar()->maxValidYear(), this);
00114 
00115   connect(d->m_day, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotDateChanged()));
00116   connect(d->m_month, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotDateChanged()));
00117   connect(d->m_year, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotDateChanged()));
00118 }
00119 
00120 KDateWidget::~KDateWidget()
00121 {
00122   delete d;
00123 }
00124 
00125 // ### HPB change TQDate to const TQDate & in KDE 4.0
00126 void KDateWidget::setDate( TQDate date )
00127 {
00128   const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
00129 
00130   d->m_day->blockSignals(true);
00131   d->m_month->blockSignals(true);
00132   d->m_year->blockSignals(true);
00133 
00134   d->m_day->setMaxValue(calendar->daysInMonth(date));
00135   d->m_day->setValue(calendar->day(date));
00136   d->m_month->setCurrentItem(calendar->month(date)-1);
00137   d->m_year->setValue(calendar->year(date));
00138 
00139   d->m_day->blockSignals(false);
00140   d->m_month->blockSignals(false);
00141   d->m_year->blockSignals(false);
00142 
00143   d->m_dat = date;
00144   emit changed(d->m_dat);
00145 }
00146 
00147 TQDate KDateWidget::date() const
00148 {
00149   return d->m_dat;
00150 }
00151 
00152 void KDateWidget::slotDateChanged( )
00153 {
00154   const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
00155 
00156   TQDate date;
00157   int y,m,day;
00158 
00159   y = d->m_year->value();
00160   y = TQMIN(TQMAX(y, calendar->minValidYear()), calendar->maxValidYear());
00161 
00162   calendar->setYMD(date, y, 1, 1);
00163   m = d->m_month->currentItem()+1;
00164   m = TQMIN(TQMAX(m,1), calendar->monthsInYear(date));
00165 
00166   calendar->setYMD(date, y, m, 1);
00167   day = d->m_day->value();
00168   day = TQMIN(TQMAX(day,1), calendar->daysInMonth(date));
00169 
00170   calendar->setYMD(date, y, m, day);
00171   setDate(date);
00172 }
00173 
00174 void KDateWidget::virtual_hook( int, void* )
00175 { /*BASE::virtual_hook( id, data );*/ }
00176 
00177 #include "kdatewidget.moc"

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.7.1
This website is maintained by Timothy Pearson.