-rw-r--r-- | korganizer/navigatorbar.cpp | 10 | ||||
-rw-r--r-- | libkdepim/kdatepicker.cpp | 8 |
2 files changed, 13 insertions, 5 deletions
diff --git a/korganizer/navigatorbar.cpp b/korganizer/navigatorbar.cpp index 2b8fd4f..7ba97c8 100644 --- a/korganizer/navigatorbar.cpp +++ b/korganizer/navigatorbar.cpp | |||
@@ -1,200 +1,206 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | 9 | (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, | 11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. | 14 | GNU General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | 17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | 19 | ||
20 | As a special exception, permission is given to link this program | 20 | As a special exception, permission is given to link this program |
21 | with any edition of Qt, and distribute the resulting executable, | 21 | with any edition of Qt, and distribute the resulting executable, |
22 | without including the source code for Qt in the source distribution. | 22 | without including the source code for Qt in the source distribution. |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <qstring.h> | 25 | #include <qstring.h> |
26 | #include <qtooltip.h> | 26 | #include <qtooltip.h> |
27 | #include <qpushbutton.h> | 27 | #include <qpushbutton.h> |
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qframe.h> | 29 | #include <qframe.h> |
30 | #include <qlabel.h> | 30 | #include <qlabel.h> |
31 | #include <qpopupmenu.h> | 31 | #include <qpopupmenu.h> |
32 | #include <qapplication.h> | 32 | #include <qapplication.h> |
33 | 33 | ||
34 | #include <kdebug.h> | 34 | #include <kdebug.h> |
35 | #include <klocale.h> | 35 | #include <klocale.h> |
36 | #include <kglobal.h> | 36 | #include <kglobal.h> |
37 | #include <kiconloader.h> | 37 | #include <kiconloader.h> |
38 | #include "libkdepim/kdatepicker.h" | 38 | #include "libkdepim/kdatepicker.h" |
39 | #include <knotifyclient.h> | 39 | #include <knotifyclient.h> |
40 | #include "kdatetbl.h" | 40 | #include "kdatetbl.h" |
41 | 41 | ||
42 | #include "koglobals.h" | 42 | #include "koglobals.h" |
43 | #include <kglobalsettings.h> | 43 | #include <kglobalsettings.h> |
44 | #include "koprefs.h" | 44 | #include "koprefs.h" |
45 | #ifndef KORG_NOPLUGINS | 45 | #ifndef KORG_NOPLUGINS |
46 | #include "kocore.h" | 46 | #include "kocore.h" |
47 | #endif | 47 | #endif |
48 | 48 | ||
49 | #include <kcalendarsystem.h> | 49 | #include <kcalendarsystem.h> |
50 | 50 | ||
51 | #include "navigatorbar.h" | 51 | #include "navigatorbar.h" |
52 | 52 | ||
53 | NavigatorBar::NavigatorBar( const QDate & date, QWidget *parent, const char *name ) | 53 | NavigatorBar::NavigatorBar( const QDate & date, QWidget *parent, const char *name ) |
54 | : QWidget( parent, name ) | 54 | : QWidget( parent, name ) |
55 | { | 55 | { |
56 | QBoxLayout *topLayout = new QHBoxLayout( this ); | 56 | QBoxLayout *topLayout = new QHBoxLayout( this ); |
57 | 57 | ||
58 | // Set up the control buttons and date label | 58 | // Set up the control buttons and date label |
59 | mCtrlFrame = new QFrame( this ); | 59 | mCtrlFrame = new QFrame( this ); |
60 | mCtrlFrame->setFrameStyle(QFrame::Panel|QFrame::Raised); | 60 | mCtrlFrame->setFrameStyle(QFrame::Panel|QFrame::Raised); |
61 | mCtrlFrame->setLineWidth(1); | 61 | mCtrlFrame->setLineWidth(1); |
62 | 62 | ||
63 | topLayout->addWidget( mCtrlFrame ); | 63 | topLayout->addWidget( mCtrlFrame ); |
64 | 64 | ||
65 | QFont tfont = KGlobalSettings::generalFont();//font(); | 65 | QFont tfont = KGlobalSettings::generalFont();//font(); |
66 | if ( QApplication::desktop()->width() >= 480 ) | 66 | int add = 0; |
67 | tfont.setPointSize(tfont.pointSize()+2); | 67 | if ( QApplication::desktop()->width() >= 480 ) { |
68 | add = 2; | ||
69 | if ( QString ( name ) == QString("useBigPixmaps") ) | ||
70 | add += 2; | ||
71 | } | ||
72 | if ( add ) | ||
73 | tfont.setPointSize(tfont.pointSize()+add); | ||
68 | tfont.setBold(true); | 74 | tfont.setBold(true); |
69 | 75 | ||
70 | bool isRTL = KOGlobals::self()->reverseLayout(); | 76 | bool isRTL = KOGlobals::self()->reverseLayout(); |
71 | #ifndef DESKTOP_VERSION | 77 | #ifndef DESKTOP_VERSION |
72 | bool isDesktop = false; | 78 | bool isDesktop = false; |
73 | #else | 79 | #else |
74 | bool isDesktop = true; | 80 | bool isDesktop = true; |
75 | #endif | 81 | #endif |
76 | if ( QString ( name ) == QString("useBigPixmaps") && QApplication::desktop()->width() > 320 ) | 82 | if ( QString ( name ) == QString("useBigPixmaps") && QApplication::desktop()->width() > 320 ) |
77 | isDesktop = true; | 83 | isDesktop = true; |
78 | // Create backward navigation buttons | 84 | // Create backward navigation buttons |
79 | mPrevYear = new QPushButton( mCtrlFrame ); | 85 | mPrevYear = new QPushButton( mCtrlFrame ); |
80 | mPrevYear->setPixmap( SmallIcon( isDesktop ? "2leftarrowB" : "2leftarrow" ) ); | 86 | mPrevYear->setPixmap( SmallIcon( isDesktop ? "2leftarrowB" : "2leftarrow" ) ); |
81 | QToolTip::add( mPrevYear, i18n("Previous Year") ); | 87 | QToolTip::add( mPrevYear, i18n("Previous Year") ); |
82 | 88 | ||
83 | mPrevMonth = new QPushButton( mCtrlFrame ); | 89 | mPrevMonth = new QPushButton( mCtrlFrame ); |
84 | mPrevMonth->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") ); | 90 | mPrevMonth->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") ); |
85 | QToolTip::add( mPrevMonth, i18n("Previous Month") ); | 91 | QToolTip::add( mPrevMonth, i18n("Previous Month") ); |
86 | 92 | ||
87 | // Create forward navigation buttons | 93 | // Create forward navigation buttons |
88 | mNextMonth = new QPushButton( mCtrlFrame ); | 94 | mNextMonth = new QPushButton( mCtrlFrame ); |
89 | mNextMonth->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") ); | 95 | mNextMonth->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") ); |
90 | QToolTip::add( mNextMonth, i18n("Next Month") ); | 96 | QToolTip::add( mNextMonth, i18n("Next Month") ); |
91 | 97 | ||
92 | mNextYear = new QPushButton( mCtrlFrame ); | 98 | mNextYear = new QPushButton( mCtrlFrame ); |
93 | mNextYear->setPixmap( SmallIcon( isDesktop ? "2rightarrowB": "2rightarrow") ); | 99 | mNextYear->setPixmap( SmallIcon( isDesktop ? "2rightarrowB": "2rightarrow") ); |
94 | QToolTip::add( mNextYear, i18n("Next Year") ); | 100 | QToolTip::add( mNextYear, i18n("Next Year") ); |
95 | mSelectMonth = new QPushButton( mCtrlFrame ); | 101 | mSelectMonth = new QPushButton( mCtrlFrame ); |
96 | // Create month name label | 102 | // Create month name label |
97 | //selectMonth->setFont( tfont ); | 103 | //selectMonth->setFont( tfont ); |
98 | // selectMonth->setAlignment( AlignCenter ); | 104 | // selectMonth->setAlignment( AlignCenter ); |
99 | //mDateLabel = new QLabel( selectMonth ); | 105 | //mDateLabel = new QLabel( selectMonth ); |
100 | //mDateLabel->setFont( tfont ); | 106 | //mDateLabel->setFont( tfont ); |
101 | //mDateLabel->setAlignment( AlignCenter ); | 107 | //mDateLabel->setAlignment( AlignCenter ); |
102 | if ( QString ( name ) == QString("useBigPixmaps") ) { | 108 | if ( QString ( name ) == QString("useBigPixmaps") ) { |
103 | mNextMonth->setFlat( true); | 109 | mNextMonth->setFlat( true); |
104 | mNextYear->setFlat( true); | 110 | mNextYear->setFlat( true); |
105 | mSelectMonth->setFlat( true); | 111 | mSelectMonth->setFlat( true); |
106 | mPrevYear->setFlat( true); | 112 | mPrevYear->setFlat( true); |
107 | mPrevMonth->setFlat( true); | 113 | mPrevMonth->setFlat( true); |
108 | } | 114 | } |
109 | mSelectMonth->setFont( tfont ); | 115 | mSelectMonth->setFont( tfont ); |
110 | // Set minimum width to width of widest month name label | 116 | // Set minimum width to width of widest month name label |
111 | int i; | 117 | int i; |
112 | int maxwidth = 0; | 118 | int maxwidth = 0; |
113 | QFontMetrics fm ( mSelectMonth->font() ); | 119 | QFontMetrics fm ( mSelectMonth->font() ); |
114 | int width = fm.width("September '00" ); | 120 | int width = fm.width("September '00" ); |
115 | // for( i = 1; i <= KOGlobals::self()->calendarSystem()->monthsInYear(date); | 121 | // for( i = 1; i <= KOGlobals::self()->calendarSystem()->monthsInYear(date); |
116 | // ++i ) { | 122 | // ++i ) { |
117 | // //int width = fm.width( KOGlobals::self()->calendarSystem()->monthName(i, | 123 | // //int width = fm.width( KOGlobals::self()->calendarSystem()->monthName(i, |
118 | // // KOGlobals::self()->calendarSystem()->year(date) ) + " 2000" ); | 124 | // // KOGlobals::self()->calendarSystem()->year(date) ) + " 2000" ); |
119 | // int width = fm.width("September 2000" ); | 125 | // int width = fm.width("September 2000" ); |
120 | // if ( width > maxwidth ) maxwidth = width; | 126 | // if ( width > maxwidth ) maxwidth = width; |
121 | // } | 127 | // } |
122 | maxwidth = width+2; | 128 | maxwidth = width+2; |
123 | int size = fm.height()+2; | 129 | int size = fm.height()+2; |
124 | if ( QApplication::desktop()->width() >= 480 ) { | 130 | if ( QApplication::desktop()->width() >= 480 ) { |
125 | size += 6; | 131 | size += 6; |
126 | maxwidth+= 6; | 132 | maxwidth+= 6; |
127 | } | 133 | } |
128 | 134 | ||
129 | mSelectMonth->setFixedWidth( maxwidth ); | 135 | mSelectMonth->setFixedWidth( maxwidth ); |
130 | mSelectMonth->setFixedHeight( size ); | 136 | mSelectMonth->setFixedHeight( size ); |
131 | mPrevYear->setFixedHeight( size ); | 137 | mPrevYear->setFixedHeight( size ); |
132 | mPrevMonth->setFixedHeight( size ); | 138 | mPrevMonth->setFixedHeight( size ); |
133 | mNextMonth->setFixedHeight( size ); | 139 | mNextMonth->setFixedHeight( size ); |
134 | mNextYear->setFixedHeight ( size ); | 140 | mNextYear->setFixedHeight ( size ); |
135 | // set up control frame layout | 141 | // set up control frame layout |
136 | QBoxLayout *ctrlLayout = new QHBoxLayout( mCtrlFrame, 1 ); | 142 | QBoxLayout *ctrlLayout = new QHBoxLayout( mCtrlFrame, 1 ); |
137 | ctrlLayout->addWidget( mPrevYear, 3 ); | 143 | ctrlLayout->addWidget( mPrevYear, 3 ); |
138 | ctrlLayout->addWidget( mPrevMonth, 3 ); | 144 | ctrlLayout->addWidget( mPrevMonth, 3 ); |
139 | //ctrlLayout->addStretch( 1 ); | 145 | //ctrlLayout->addStretch( 1 ); |
140 | // ctrlLayout->addSpacing( 1 ); | 146 | // ctrlLayout->addSpacing( 1 ); |
141 | // ctrlLayout->addWidget( mDateLabel ); | 147 | // ctrlLayout->addWidget( mDateLabel ); |
142 | ctrlLayout->addWidget( mSelectMonth ); | 148 | ctrlLayout->addWidget( mSelectMonth ); |
143 | // ctrlLayout->addSpacing( 1 ); | 149 | // ctrlLayout->addSpacing( 1 ); |
144 | // ctrlLayout->addStretch( 1 ); | 150 | // ctrlLayout->addStretch( 1 ); |
145 | ctrlLayout->addWidget( mNextMonth, 3 ); | 151 | ctrlLayout->addWidget( mNextMonth, 3 ); |
146 | ctrlLayout->addWidget( mNextYear, 3 ); | 152 | ctrlLayout->addWidget( mNextYear, 3 ); |
147 | 153 | ||
148 | connect( mPrevYear, SIGNAL( clicked() ), SIGNAL( goPrevYear() ) ); | 154 | connect( mPrevYear, SIGNAL( clicked() ), SIGNAL( goPrevYear() ) ); |
149 | connect( mPrevMonth, SIGNAL( clicked() ), SIGNAL( goPrevMonth() ) ); | 155 | connect( mPrevMonth, SIGNAL( clicked() ), SIGNAL( goPrevMonth() ) ); |
150 | connect( mNextMonth, SIGNAL( clicked() ), SIGNAL( goNextMonth() ) ); | 156 | connect( mNextMonth, SIGNAL( clicked() ), SIGNAL( goNextMonth() ) ); |
151 | connect( mNextYear, SIGNAL( clicked() ), SIGNAL( goNextYear() ) ); | 157 | connect( mNextYear, SIGNAL( clicked() ), SIGNAL( goNextYear() ) ); |
152 | connect( mSelectMonth, SIGNAL( clicked() ),SLOT( selectMonth() ) ); | 158 | connect( mSelectMonth, SIGNAL( clicked() ),SLOT( selectMonth() ) ); |
153 | mPrevYear->setFocusPolicy(NoFocus); | 159 | mPrevYear->setFocusPolicy(NoFocus); |
154 | mPrevMonth->setFocusPolicy(NoFocus); | 160 | mPrevMonth->setFocusPolicy(NoFocus); |
155 | mNextMonth->setFocusPolicy(NoFocus); | 161 | mNextMonth->setFocusPolicy(NoFocus); |
156 | mNextYear->setFocusPolicy(NoFocus); | 162 | mNextYear->setFocusPolicy(NoFocus); |
157 | mSelectMonth->setFocusPolicy(NoFocus); | 163 | mSelectMonth->setFocusPolicy(NoFocus); |
158 | setSizePolicy( QSizePolicy ( QSizePolicy::Expanding ,QSizePolicy::Fixed ) ); | 164 | setSizePolicy( QSizePolicy ( QSizePolicy::Expanding ,QSizePolicy::Fixed ) ); |
159 | 165 | ||
160 | } | 166 | } |
161 | 167 | ||
162 | NavigatorBar::~NavigatorBar() | 168 | NavigatorBar::~NavigatorBar() |
163 | { | 169 | { |
164 | } | 170 | } |
165 | 171 | ||
166 | void NavigatorBar::selectMonth() | 172 | void NavigatorBar::selectMonth() |
167 | { | 173 | { |
168 | 174 | ||
169 | int month; | 175 | int month; |
170 | KPopupFrame* popup = new KPopupFrame(this); | 176 | KPopupFrame* popup = new KPopupFrame(this); |
171 | KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup); | 177 | KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup); |
172 | // ----- | 178 | // ----- |
173 | picker->resize(picker->sizeHint()); | 179 | picker->resize(picker->sizeHint()); |
174 | popup->setMainWidget(picker); | 180 | popup->setMainWidget(picker); |
175 | picker->setFocus(); | 181 | picker->setFocus(); |
176 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); | 182 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); |
177 | if(popup->exec(mSelectMonth->mapToGlobal(QPoint(0, mSelectMonth->height())))) | 183 | if(popup->exec(mSelectMonth->mapToGlobal(QPoint(0, mSelectMonth->height())))) |
178 | { | 184 | { |
179 | month = picker->getResult(); | 185 | month = picker->getResult(); |
180 | emit monthSelected ( month ); | 186 | emit monthSelected ( month ); |
181 | } else { | 187 | } else { |
182 | KNotifyClient::beep(); | 188 | KNotifyClient::beep(); |
183 | } | 189 | } |
184 | delete popup; | 190 | delete popup; |
185 | } | 191 | } |
186 | void NavigatorBar::selectDates( const KCal::DateList &dateList ) | 192 | void NavigatorBar::selectDates( const KCal::DateList &dateList ) |
187 | { | 193 | { |
188 | if (dateList.count() > 0) { | 194 | if (dateList.count() > 0) { |
189 | QDate date = dateList.first(); | 195 | QDate date = dateList.first(); |
190 | 196 | ||
191 | const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); | 197 | const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); |
192 | 198 | ||
193 | // compute the label at the top of the navigator | 199 | // compute the label at the top of the navigator |
194 | QString dtstr = i18n(calSys->monthName( date )) + " '" + | 200 | QString dtstr = i18n(calSys->monthName( date )) + " '" + |
195 | QString::number( calSys->year( date ) ).right(2); | 201 | QString::number( calSys->year( date ) ).right(2); |
196 | 202 | ||
197 | mSelectMonth->setText( dtstr ); | 203 | mSelectMonth->setText( dtstr ); |
198 | } | 204 | } |
199 | } | 205 | } |
200 | 206 | ||
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp index d6e9b51..c13734f 100644 --- a/libkdepim/kdatepicker.cpp +++ b/libkdepim/kdatepicker.cpp | |||
@@ -1,474 +1,476 @@ | |||
1 | /* -*- C++ -*- | 1 | /* -*- C++ -*- |
2 | This file is part of the KDE libraries | 2 | This file is part of the KDE libraries |
3 | Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org) | 3 | Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org) |
4 | (C) 1998-2001 Mirko Boehm (mirko@kde.org) | 4 | (C) 1998-2001 Mirko Boehm (mirko@kde.org) |
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include "kdatepicker.h" | 21 | #include "kdatepicker.h" |
22 | #include <kglobal.h> | 22 | #include <kglobal.h> |
23 | #include <kapplication.h> | 23 | #include <kapplication.h> |
24 | #include <klocale.h> | 24 | #include <klocale.h> |
25 | #include <kiconloader.h> | 25 | #include <kiconloader.h> |
26 | #include <qframe.h> | 26 | #include <qframe.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qdialog.h> | 28 | #include <qdialog.h> |
29 | #include <qtoolbutton.h> | 29 | #include <qtoolbutton.h> |
30 | #include <qfont.h> | 30 | #include <qfont.h> |
31 | #include <qapplication.h> | 31 | #include <qapplication.h> |
32 | #include <qlineedit.h> | 32 | #include <qlineedit.h> |
33 | #include <qvalidator.h> | 33 | #include <qvalidator.h> |
34 | #include <kdebug.h> | 34 | #include <kdebug.h> |
35 | #include <knotifyclient.h> | 35 | #include <knotifyclient.h> |
36 | #include <kglobalsettings.h> | 36 | #include <kglobalsettings.h> |
37 | #include "kdatetbl.h" | 37 | #include "kdatetbl.h" |
38 | #include "kdateedit.h" | 38 | #include "kdateedit.h" |
39 | //#include "kdatepicker.moc" | 39 | //#include "kdatepicker.moc" |
40 | 40 | ||
41 | 41 | ||
42 | KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) | 42 | KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) |
43 | : QFrame(parent,name), | 43 | : QFrame(parent,name), |
44 | yearForward(new QToolButton(this)), | 44 | yearForward(new QToolButton(this)), |
45 | yearBackward(new QToolButton(this)), | 45 | yearBackward(new QToolButton(this)), |
46 | monthForward(new QToolButton(this)), | 46 | monthForward(new QToolButton(this)), |
47 | monthBackward(new QToolButton(this)), | 47 | monthBackward(new QToolButton(this)), |
48 | selectMonth(new QToolButton(this)), | 48 | selectMonth(new QToolButton(this)), |
49 | selectYear(new QToolButton(this)), | 49 | selectYear(new QToolButton(this)), |
50 | //line(new QLineEdit(this)), | 50 | //line(new QLineEdit(this)), |
51 | val(new KDateValidator(this)) | 51 | val(new KDateValidator(this)) |
52 | //table(new KDateTable(this)), | 52 | //table(new KDateTable(this)), |
53 | //fontsize(1) | 53 | //fontsize(1) |
54 | { | 54 | { |
55 | setFont ( KGlobalSettings::generalFont() ); | 55 | QFont fo = KGlobalSettings::generalFont(); |
56 | table = new KDateTable(this); | ||
57 | int add = 2; | 56 | int add = 2; |
58 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) | 57 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) |
59 | add += 4; | 58 | add += 4; |
60 | setFontSize(font().pointSize()+add); | 59 | fo.setPointSize(fo.pointSize()+add ); |
60 | setFont( fo ); | ||
61 | table = new KDateTable(this); | ||
62 | setFontSize(font().pointSize()); | ||
61 | //line->setValidator(val); | 63 | //line->setValidator(val); |
62 | lineDate = new KDateEdit( this, "dateediipicker", true ); | 64 | lineDate = new KDateEdit( this, "dateediipicker", true ); |
63 | yearForward->setPixmap(SmallIcon("2rightarrowB")); | 65 | yearForward->setPixmap(SmallIcon("2rightarrowB")); |
64 | yearBackward->setPixmap(SmallIcon("2leftarrowB")); | 66 | yearBackward->setPixmap(SmallIcon("2leftarrowB")); |
65 | monthForward->setPixmap(SmallIcon("1rightarrowB")); | 67 | monthForward->setPixmap(SmallIcon("1rightarrowB")); |
66 | monthBackward->setPixmap(SmallIcon("1leftarrowB")); | 68 | monthBackward->setPixmap(SmallIcon("1leftarrowB")); |
67 | setDate(dt); // set button texts | 69 | setDate(dt); // set button texts |
68 | connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); | 70 | connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); |
69 | connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); | 71 | connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); |
70 | connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); | 72 | connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); |
71 | connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); | 73 | connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); |
72 | connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); | 74 | connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); |
73 | connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); | 75 | connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); |
74 | connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); | 76 | connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); |
75 | connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); | 77 | connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); |
76 | //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); | 78 | //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); |
77 | connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); | 79 | connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); |
78 | connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); | 80 | connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); |
79 | table->setFocus(); | 81 | table->setFocus(); |
80 | 82 | ||
81 | } | 83 | } |
82 | 84 | ||
83 | KDatePicker::~KDatePicker() | 85 | KDatePicker::~KDatePicker() |
84 | { | 86 | { |
85 | } | 87 | } |
86 | 88 | ||
87 | void | 89 | void |
88 | KDatePicker::resizeEvent(QResizeEvent*) | 90 | KDatePicker::resizeEvent(QResizeEvent*) |
89 | { | 91 | { |
90 | QWidget *buttons[] = { | 92 | QWidget *buttons[] = { |
91 | yearBackward, | 93 | yearBackward, |
92 | monthBackward, | 94 | monthBackward, |
93 | selectMonth, | 95 | selectMonth, |
94 | selectYear, | 96 | selectYear, |
95 | monthForward, | 97 | monthForward, |
96 | yearForward }; | 98 | yearForward }; |
97 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); | 99 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); |
98 | QSize sizes[NoOfButtons]; | 100 | QSize sizes[NoOfButtons]; |
99 | int buttonHeight=0; | 101 | int buttonHeight=0; |
100 | int count; | 102 | int count; |
101 | int w; | 103 | int w; |
102 | int x=0; | 104 | int x=0; |
103 | // ----- calculate button row height: | 105 | // ----- calculate button row height: |
104 | for(count=0; count<NoOfButtons; ++count) { | 106 | for(count=0; count<NoOfButtons; ++count) { |
105 | int xS = buttons[count]->sizeHint().width(); | 107 | int xS = buttons[count]->sizeHint().width(); |
106 | int yS = buttons[count]->sizeHint().height(); | 108 | int yS = buttons[count]->sizeHint().height(); |
107 | if ( QApplication::desktop()->width() < 320 ) | 109 | if ( QApplication::desktop()->width() < 320 ) |
108 | sizes[count]=QSize ( xS+4, yS ); | 110 | sizes[count]=QSize ( xS+4, yS ); |
109 | else | 111 | else |
110 | sizes[count]=QSize ( xS+10, yS ); | 112 | sizes[count]=QSize ( xS+10, yS ); |
111 | 113 | ||
112 | buttonHeight=QMAX(buttonHeight, sizes[count].height()); | 114 | buttonHeight=QMAX(buttonHeight, sizes[count].height()); |
113 | } | 115 | } |
114 | buttonHeight += 10; | 116 | buttonHeight += 10; |
115 | // ----- calculate size of the month button: | 117 | // ----- calculate size of the month button: |
116 | w=0; | 118 | w=0; |
117 | for(count=0; count<NoOfButtons; ++count) { | 119 | for(count=0; count<NoOfButtons; ++count) { |
118 | if(buttons[count]!=selectMonth) | 120 | if(buttons[count]!=selectMonth) |
119 | { | 121 | { |
120 | w+=sizes[count].width(); | 122 | w+=sizes[count].width(); |
121 | } else { | 123 | } else { |
122 | x=count; | 124 | x=count; |
123 | } | 125 | } |
124 | } | 126 | } |
125 | sizes[x].setWidth(width()-w); // stretch the month button | 127 | sizes[x].setWidth(width()-w); // stretch the month button |
126 | // ----- place the buttons: | 128 | // ----- place the buttons: |
127 | x=0; | 129 | x=0; |
128 | for(count=0; count<NoOfButtons; ++count) | 130 | for(count=0; count<NoOfButtons; ++count) |
129 | { | 131 | { |
130 | w=sizes[count].width(); | 132 | w=sizes[count].width(); |
131 | buttons[count]->setGeometry(x, 0, w, buttonHeight); | 133 | buttons[count]->setGeometry(x, 0, w, buttonHeight); |
132 | x+=w; | 134 | x+=w; |
133 | } | 135 | } |
134 | // ----- place the line edit for direct input: | 136 | // ----- place the line edit for direct input: |
135 | sizes[0]=lineDate->sizeHint(); | 137 | sizes[0]=lineDate->sizeHint(); |
136 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 138 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); |
137 | lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 139 | lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); |
138 | // ----- adjust the table: | 140 | // ----- adjust the table: |
139 | table->setGeometry(0, buttonHeight, width(), | 141 | table->setGeometry(0, buttonHeight, width(), |
140 | height()-buttonHeight-sizes[0].height()); | 142 | height()-buttonHeight-sizes[0].height()); |
141 | } | 143 | } |
142 | 144 | ||
143 | void | 145 | void |
144 | KDatePicker::dateChangedSlot(QDate date) | 146 | KDatePicker::dateChangedSlot(QDate date) |
145 | { | 147 | { |
146 | lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); | 148 | lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); |
147 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 149 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
148 | emit(dateChanged(date)); | 150 | emit(dateChanged(date)); |
149 | } | 151 | } |
150 | 152 | ||
151 | void | 153 | void |
152 | KDatePicker::tableClickedSlot() | 154 | KDatePicker::tableClickedSlot() |
153 | { | 155 | { |
154 | 156 | ||
155 | emit(dateSelected(table->getDate())); | 157 | emit(dateSelected(table->getDate())); |
156 | emit(tableClicked()); | 158 | emit(tableClicked()); |
157 | } | 159 | } |
158 | 160 | ||
159 | const QDate& | 161 | const QDate& |
160 | KDatePicker::getDate() const | 162 | KDatePicker::getDate() const |
161 | { | 163 | { |
162 | return table->getDate(); | 164 | return table->getDate(); |
163 | } | 165 | } |
164 | 166 | ||
165 | const QDate & | 167 | const QDate & |
166 | KDatePicker::date() const | 168 | KDatePicker::date() const |
167 | { | 169 | { |
168 | return table->getDate(); | 170 | return table->getDate(); |
169 | } | 171 | } |
170 | 172 | ||
171 | void KDatePicker::slotSetDate( QDate date ) | 173 | void KDatePicker::slotSetDate( QDate date ) |
172 | { | 174 | { |
173 | 175 | ||
174 | if(date.isValid()) { | 176 | if(date.isValid()) { |
175 | QString temp; | 177 | QString temp; |
176 | // ----- | 178 | // ----- |
177 | table->setDate(date); | 179 | table->setDate(date); |
178 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); | 180 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); |
179 | temp.setNum(date.year()); | 181 | temp.setNum(date.year()); |
180 | selectYear->setText(temp); | 182 | selectYear->setText(temp); |
181 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 183 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
182 | lineDate->setDate( date ); | 184 | lineDate->setDate( date ); |
183 | } | 185 | } |
184 | 186 | ||
185 | } | 187 | } |
186 | bool | 188 | bool |
187 | KDatePicker::setDate(const QDate& date) | 189 | KDatePicker::setDate(const QDate& date) |
188 | { | 190 | { |
189 | table->setFocus(); | 191 | table->setFocus(); |
190 | if(date.isValid()) { | 192 | if(date.isValid()) { |
191 | QString temp; | 193 | QString temp; |
192 | // ----- | 194 | // ----- |
193 | table->setDate(date); | 195 | table->setDate(date); |
194 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); | 196 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); |
195 | temp.setNum(date.year()); | 197 | temp.setNum(date.year()); |
196 | selectYear->setText(temp); | 198 | selectYear->setText(temp); |
197 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 199 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
198 | lineDate->setDate( date ); | 200 | lineDate->setDate( date ); |
199 | return true; | 201 | return true; |
200 | } else { | 202 | } else { |
201 | 203 | ||
202 | return false; | 204 | return false; |
203 | } | 205 | } |
204 | 206 | ||
205 | 207 | ||
206 | } | 208 | } |
207 | 209 | ||
208 | void | 210 | void |
209 | KDatePicker::monthForwardClicked() | 211 | KDatePicker::monthForwardClicked() |
210 | { | 212 | { |
211 | QDate temp=table->getDate(); | 213 | QDate temp=table->getDate(); |
212 | int day=temp.day(); | 214 | int day=temp.day(); |
213 | // ----- | 215 | // ----- |
214 | if(temp.month()==12) { | 216 | if(temp.month()==12) { |
215 | temp.setYMD(temp.year()+1, 1, 1); | 217 | temp.setYMD(temp.year()+1, 1, 1); |
216 | } else { | 218 | } else { |
217 | temp.setYMD(temp.year(), temp.month()+1, 1); | 219 | temp.setYMD(temp.year(), temp.month()+1, 1); |
218 | } | 220 | } |
219 | if(temp.daysInMonth()<day) { | 221 | if(temp.daysInMonth()<day) { |
220 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); | 222 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); |
221 | } else { | 223 | } else { |
222 | temp.setYMD(temp.year(), temp.month(), day); | 224 | temp.setYMD(temp.year(), temp.month(), day); |
223 | } | 225 | } |
224 | // assert(temp.isValid()); | 226 | // assert(temp.isValid()); |
225 | setDate(temp); | 227 | setDate(temp); |
226 | } | 228 | } |
227 | 229 | ||
228 | void | 230 | void |
229 | KDatePicker::monthBackwardClicked() | 231 | KDatePicker::monthBackwardClicked() |
230 | { | 232 | { |
231 | QDate temp=table->getDate(); | 233 | QDate temp=table->getDate(); |
232 | int day=temp.day(); | 234 | int day=temp.day(); |
233 | // ----- | 235 | // ----- |
234 | if(temp.month()==1) | 236 | if(temp.month()==1) |
235 | { | 237 | { |
236 | temp.setYMD(temp.year()-1, 12, 1); | 238 | temp.setYMD(temp.year()-1, 12, 1); |
237 | } else { | 239 | } else { |
238 | temp.setYMD(temp.year(), temp.month()-1, 1); | 240 | temp.setYMD(temp.year(), temp.month()-1, 1); |
239 | } | 241 | } |
240 | if(temp.daysInMonth()<day) | 242 | if(temp.daysInMonth()<day) |
241 | { | 243 | { |
242 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); | 244 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); |
243 | } else { | 245 | } else { |
244 | temp.setYMD(temp.year(), temp.month(), day); | 246 | temp.setYMD(temp.year(), temp.month(), day); |
245 | } | 247 | } |
246 | // assert(temp.isValid()); | 248 | // assert(temp.isValid()); |
247 | setDate(temp); | 249 | setDate(temp); |
248 | } | 250 | } |
249 | 251 | ||
250 | void | 252 | void |
251 | KDatePicker::yearForwardClicked() | 253 | KDatePicker::yearForwardClicked() |
252 | { | 254 | { |
253 | QDate temp=table->getDate(); | 255 | QDate temp=table->getDate(); |
254 | int day=temp.day(); | 256 | int day=temp.day(); |
255 | // ----- | 257 | // ----- |
256 | temp.setYMD(temp.year()+1, temp.month(), 1); | 258 | temp.setYMD(temp.year()+1, temp.month(), 1); |
257 | if(temp.daysInMonth()<day) | 259 | if(temp.daysInMonth()<day) |
258 | { | 260 | { |
259 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); | 261 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); |
260 | } else { | 262 | } else { |
261 | temp.setYMD(temp.year(), temp.month(), day); | 263 | temp.setYMD(temp.year(), temp.month(), day); |
262 | } | 264 | } |
263 | // assert(temp.isValid()); | 265 | // assert(temp.isValid()); |
264 | setDate(temp); | 266 | setDate(temp); |
265 | } | 267 | } |
266 | 268 | ||
267 | void | 269 | void |
268 | KDatePicker::yearBackwardClicked() | 270 | KDatePicker::yearBackwardClicked() |
269 | { | 271 | { |
270 | QDate temp=table->getDate(); | 272 | QDate temp=table->getDate(); |
271 | int day=temp.day(); | 273 | int day=temp.day(); |
272 | // ----- | 274 | // ----- |
273 | temp.setYMD(temp.year()-1, temp.month(), 1); | 275 | temp.setYMD(temp.year()-1, temp.month(), 1); |
274 | if(temp.daysInMonth()<day) | 276 | if(temp.daysInMonth()<day) |
275 | { | 277 | { |
276 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); | 278 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); |
277 | } else { | 279 | } else { |
278 | temp.setYMD(temp.year(), temp.month(), day); | 280 | temp.setYMD(temp.year(), temp.month(), day); |
279 | } | 281 | } |
280 | // assert(temp.isValid()); | 282 | // assert(temp.isValid()); |
281 | setDate(temp); | 283 | setDate(temp); |
282 | } | 284 | } |
283 | 285 | ||
284 | void | 286 | void |
285 | KDatePicker::selectMonthClicked() | 287 | KDatePicker::selectMonthClicked() |
286 | { | 288 | { |
287 | int month; | 289 | int month; |
288 | KPopupFrame* popup = new KPopupFrame(this); | 290 | KPopupFrame* popup = new KPopupFrame(this); |
289 | KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup); | 291 | KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup); |
290 | // ----- | 292 | // ----- |
291 | picker->resize(picker->sizeHint()); | 293 | picker->resize(picker->sizeHint()); |
292 | popup->setMainWidget(picker); | 294 | popup->setMainWidget(picker); |
293 | picker->setFocus(); | 295 | picker->setFocus(); |
294 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); | 296 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); |
295 | if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height())))) | 297 | if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height())))) |
296 | { | 298 | { |
297 | QDate date; | 299 | QDate date; |
298 | int day; | 300 | int day; |
299 | // ----- | 301 | // ----- |
300 | month=picker->getResult(); | 302 | month=picker->getResult(); |
301 | date=table->getDate(); | 303 | date=table->getDate(); |
302 | day=date.day(); | 304 | day=date.day(); |
303 | // ----- construct a valid date in this month: | 305 | // ----- construct a valid date in this month: |
304 | date.setYMD(date.year(), month, 1); | 306 | date.setYMD(date.year(), month, 1); |
305 | date.setYMD(date.year(), month, QMIN(day, date.daysInMonth())); | 307 | date.setYMD(date.year(), month, QMIN(day, date.daysInMonth())); |
306 | // ----- set this month | 308 | // ----- set this month |
307 | setDate(date); | 309 | setDate(date); |
308 | } else { | 310 | } else { |
309 | KNotifyClient::beep(); | 311 | KNotifyClient::beep(); |
310 | } | 312 | } |
311 | delete popup; | 313 | delete popup; |
312 | } | 314 | } |
313 | 315 | ||
314 | void | 316 | void |
315 | KDatePicker::selectYearClicked() | 317 | KDatePicker::selectYearClicked() |
316 | { | 318 | { |
317 | int year; | 319 | int year; |
318 | KPopupFrame* popup = new KPopupFrame(this); | 320 | KPopupFrame* popup = new KPopupFrame(this); |
319 | KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup); | 321 | KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup); |
320 | // ----- | 322 | // ----- |
321 | picker->resize(picker->sizeHint()); | 323 | picker->resize(picker->sizeHint()); |
322 | popup->setMainWidget(picker); | 324 | popup->setMainWidget(picker); |
323 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); | 325 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); |
324 | picker->setFocus(); | 326 | picker->setFocus(); |
325 | if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height())))) | 327 | if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height())))) |
326 | { | 328 | { |
327 | QDate date; | 329 | QDate date; |
328 | int day; | 330 | int day; |
329 | // ----- | 331 | // ----- |
330 | year=picker->getYear(); | 332 | year=picker->getYear(); |
331 | date=table->getDate(); | 333 | date=table->getDate(); |
332 | day=date.day(); | 334 | day=date.day(); |
333 | // ----- construct a valid date in this month: | 335 | // ----- construct a valid date in this month: |
334 | date.setYMD(year, date.month(), 1); | 336 | date.setYMD(year, date.month(), 1); |
335 | date.setYMD(year, date.month(), QMIN(day, date.daysInMonth())); | 337 | date.setYMD(year, date.month(), QMIN(day, date.daysInMonth())); |
336 | // ----- set this month | 338 | // ----- set this month |
337 | setDate(date); | 339 | setDate(date); |
338 | } else { | 340 | } else { |
339 | KNotifyClient::beep(); | 341 | KNotifyClient::beep(); |
340 | } | 342 | } |
341 | delete popup; | 343 | delete popup; |
342 | } | 344 | } |
343 | 345 | ||
344 | void | 346 | void |
345 | KDatePicker::setEnabled(bool enable) | 347 | KDatePicker::setEnabled(bool enable) |
346 | { | 348 | { |
347 | QWidget *widgets[]= { | 349 | QWidget *widgets[]= { |
348 | yearForward, yearBackward, monthForward, monthBackward, | 350 | yearForward, yearBackward, monthForward, monthBackward, |
349 | selectMonth, selectYear, | 351 | selectMonth, selectYear, |
350 | lineDate, table }; | 352 | lineDate, table }; |
351 | const int Size=sizeof(widgets)/sizeof(widgets[0]); | 353 | const int Size=sizeof(widgets)/sizeof(widgets[0]); |
352 | int count; | 354 | int count; |
353 | // ----- | 355 | // ----- |
354 | for(count=0; count<Size; ++count) | 356 | for(count=0; count<Size; ++count) |
355 | { | 357 | { |
356 | widgets[count]->setEnabled(enable); | 358 | widgets[count]->setEnabled(enable); |
357 | } | 359 | } |
358 | } | 360 | } |
359 | 361 | ||
360 | void | 362 | void |
361 | KDatePicker::lineEnterPressed() | 363 | KDatePicker::lineEnterPressed() |
362 | { | 364 | { |
363 | QDate temp; | 365 | QDate temp; |
364 | // ----- | 366 | // ----- |
365 | temp = lineDate->date(); | 367 | temp = lineDate->date(); |
366 | //if(val->date(line->text(), temp)==QValidator::Acceptable) | 368 | //if(val->date(line->text(), temp)==QValidator::Acceptable) |
367 | //{ | 369 | //{ |
368 | emit(dateEntered(temp)); | 370 | emit(dateEntered(temp)); |
369 | setDate(temp); | 371 | setDate(temp); |
370 | // } else { | 372 | // } else { |
371 | // KNotifyClient::beep(); | 373 | // KNotifyClient::beep(); |
372 | // } | 374 | // } |
373 | } | 375 | } |
374 | 376 | ||
375 | QSize | 377 | QSize |
376 | KDatePicker::sizeHint() const | 378 | KDatePicker::sizeHint() const |
377 | { | 379 | { |
378 | QSize tableSize=table->sizeHint(); | 380 | QSize tableSize=table->sizeHint(); |
379 | QWidget *buttons[]={ | 381 | QWidget *buttons[]={ |
380 | yearBackward, | 382 | yearBackward, |
381 | monthBackward, | 383 | monthBackward, |
382 | selectMonth, | 384 | selectMonth, |
383 | selectYear, | 385 | selectYear, |
384 | monthForward, | 386 | monthForward, |
385 | yearForward }; | 387 | yearForward }; |
386 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); | 388 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); |
387 | QSize sizes[NoOfButtons]; | 389 | QSize sizes[NoOfButtons]; |
388 | int cx=0, cy=0, count; | 390 | int cx=0, cy=0, count; |
389 | // ----- store the size hints: | 391 | // ----- store the size hints: |
390 | for(count=0; count<NoOfButtons; ++count) | 392 | for(count=0; count<NoOfButtons; ++count) |
391 | { | 393 | { |
392 | sizes[count]=buttons[count]->sizeHint(); | 394 | sizes[count]=buttons[count]->sizeHint(); |
393 | if(buttons[count]==selectMonth) | 395 | if(buttons[count]==selectMonth) |
394 | { | 396 | { |
395 | cx+=maxMonthRect.width()+15; | 397 | cx+=maxMonthRect.width()+15; |
396 | } else { | 398 | } else { |
397 | cx+=sizes[count].width()+15; | 399 | cx+=sizes[count].width()+15; |
398 | } | 400 | } |
399 | cy=QMAX(sizes[count].height(), cy); | 401 | cy=QMAX(sizes[count].height(), cy); |
400 | } | 402 | } |
401 | // ----- calculate width hint: | 403 | // ----- calculate width hint: |
402 | cx=QMAX(cx, tableSize.width()); // line edit ignored | 404 | cx=QMAX(cx, tableSize.width()); // line edit ignored |
403 | if ( cx > QApplication::desktop()->width() -5 ) | 405 | if ( cx > QApplication::desktop()->width() -5 ) |
404 | cx = QApplication::desktop()->width() -5; | 406 | cx = QApplication::desktop()->width() -5; |
405 | // ----- calculate height hint: | 407 | // ----- calculate height hint: |
406 | cy+=tableSize.height()+lineDate->sizeHint().height(); | 408 | cy+=tableSize.height()+lineDate->sizeHint().height(); |
407 | 409 | ||
408 | return QSize(cx, cy); | 410 | return QSize(cx, cy); |
409 | } | 411 | } |
410 | 412 | ||
411 | void | 413 | void |
412 | KDatePicker::setFontSize(int s) | 414 | KDatePicker::setFontSize(int s) |
413 | { | 415 | { |
414 | QWidget *buttons[]= { | 416 | QWidget *buttons[]= { |
415 | // yearBackward, | 417 | // yearBackward, |
416 | // monthBackward, | 418 | // monthBackward, |
417 | selectMonth, | 419 | selectMonth, |
418 | selectYear, | 420 | selectYear, |
419 | // monthForward, | 421 | // monthForward, |
420 | // yearForward | 422 | // yearForward |
421 | }; | 423 | }; |
422 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); | 424 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); |
423 | int count; | 425 | int count; |
424 | QFont font; | 426 | QFont font; |
425 | QRect r; | 427 | QRect r; |
426 | // ----- | 428 | // ----- |
427 | fontsize=s; | 429 | fontsize=s; |
428 | for(count=0; count<NoOfButtons; ++count) | 430 | for(count=0; count<NoOfButtons; ++count) |
429 | { | 431 | { |
430 | font=buttons[count]->font(); | 432 | font=buttons[count]->font(); |
431 | font.setPointSize(s); | 433 | font.setPointSize(s); |
432 | buttons[count]->setFont(font); | 434 | buttons[count]->setFont(font); |
433 | } | 435 | } |
434 | QFontMetrics metrics(selectMonth->fontMetrics()); | 436 | QFontMetrics metrics(selectMonth->fontMetrics()); |
435 | for(int i=1; i <= 12; ++i) | 437 | for(int i=1; i <= 12; ++i) |
436 | { // maxMonthRect is used by sizeHint() | 438 | { // maxMonthRect is used by sizeHint() |
437 | r=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); | 439 | r=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); |
438 | maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width())); | 440 | maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width())); |
439 | maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height())); | 441 | maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height())); |
440 | } | 442 | } |
441 | table->setFontSize(s); | 443 | table->setFontSize(s); |
442 | } | 444 | } |
443 | 445 | ||
444 | void KDatePicker::virtual_hook( int id, void* data ) | 446 | void KDatePicker::virtual_hook( int id, void* data ) |
445 | { /*BASE::virtual_hook( id, data );*/ } | 447 | { /*BASE::virtual_hook( id, data );*/ } |
446 | 448 | ||
447 | void KDatePicker::keyPressEvent ( QKeyEvent * e ) | 449 | void KDatePicker::keyPressEvent ( QKeyEvent * e ) |
448 | { | 450 | { |
449 | switch ( e->key() ) { | 451 | switch ( e->key() ) { |
450 | case Qt::Key_Right: | 452 | case Qt::Key_Right: |
451 | monthForwardClicked(); | 453 | monthForwardClicked(); |
452 | break; | 454 | break; |
453 | case Qt::Key_Left: | 455 | case Qt::Key_Left: |
454 | monthBackwardClicked(); | 456 | monthBackwardClicked(); |
455 | break; | 457 | break; |
456 | 458 | ||
457 | case Qt::Key_Down: | 459 | case Qt::Key_Down: |
458 | yearForwardClicked(); | 460 | yearForwardClicked(); |
459 | 461 | ||
460 | break; | 462 | break; |
461 | 463 | ||
462 | case Qt::Key_Up: | 464 | case Qt::Key_Up: |
463 | yearBackwardClicked(); | 465 | yearBackwardClicked(); |
464 | break; | 466 | break; |
465 | 467 | ||
466 | case Qt::Key_Return: | 468 | case Qt::Key_Return: |
467 | tableClickedSlot(); | 469 | tableClickedSlot(); |
468 | break; | 470 | break; |
469 | 471 | ||
470 | default: | 472 | default: |
471 | break; | 473 | break; |
472 | } | 474 | } |
473 | 475 | ||
474 | } | 476 | } |