summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-17 12:38:04 (UTC)
committer zautrix <zautrix>2004-09-17 12:38:04 (UTC)
commit053b3550aa2b987d7aeaf74cc458754d7e80a67b (patch) (unidiff)
tree4190b96b6b581c18943ac7e1cdd5cbca96741eae
parentdd33ac512eb4b4b647fb3423f7cdb39ec322221b (diff)
downloadkdepimpi-053b3550aa2b987d7aeaf74cc458754d7e80a67b.zip
kdepimpi-053b3550aa2b987d7aeaf74cc458754d7e80a67b.tar.gz
kdepimpi-053b3550aa2b987d7aeaf74cc458754d7e80a67b.tar.bz2
Better datepicker
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdatetbl.cpp28
-rw-r--r--microkde/kdatetbl.h1
2 files changed, 21 insertions, 8 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index 0a2d1f5..146291b 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -1,735 +1,747 @@
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/////////////////// KDateTable widget class ////////////////////// 21/////////////////// KDateTable widget class //////////////////////
22// 22//
23// Copyright (C) 1997 Tim D. Gilman 23// Copyright (C) 1997 Tim D. Gilman
24// (C) 1998-2001 Mirko Boehm 24// (C) 1998-2001 Mirko Boehm
25// Written using Qt (http://www.troll.no) for the 25// Written using Qt (http://www.troll.no) for the
26// KDE project (http://www.kde.org) 26// KDE project (http://www.kde.org)
27// 27//
28// This is a support class for the KDatePicker class. It just 28// This is a support class for the KDatePicker class. It just
29// draws the calender table without titles, but could theoretically 29// draws the calender table without titles, but could theoretically
30// be used as a standalone. 30// be used as a standalone.
31// 31//
32// When a date is selected by the user, it emits a signal: 32// When a date is selected by the user, it emits a signal:
33// dateSelected(QDate) 33// dateSelected(QDate)
34 34
35#include <kglobal.h> 35#include <kglobal.h>
36#include <kglobalsettings.h> 36#include <kglobalsettings.h>
37#include <kapplication.h> 37#include <kapplication.h>
38#include <klocale.h> 38#include <klocale.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <knotifyclient.h> 40#include <knotifyclient.h>
41#include "kdatetbl.h" 41#include "kdatetbl.h"
42#include <qdatetime.h> 42#include <qdatetime.h>
43#include <qstring.h> 43#include <qstring.h>
44#include <qpen.h> 44#include <qpen.h>
45#include <qpainter.h> 45#include <qpainter.h>
46#include <qdialog.h> 46#include <qdialog.h>
47#include <assert.h> 47#include <assert.h>
48#include <qapplication.h> 48#include <qapplication.h>
49 49
50KDateValidator::KDateValidator(QWidget* parent, const char* name) 50KDateValidator::KDateValidator(QWidget* parent, const char* name)
51 : QValidator(parent, name) 51 : QValidator(parent, name)
52{ 52{
53} 53}
54 54
55QValidator::State 55QValidator::State
56KDateValidator::validate(QString& text, int&) const 56KDateValidator::validate(QString& text, int&) const
57{ 57{
58 QDate temp; 58 QDate temp;
59 // ----- everything is tested in date(): 59 // ----- everything is tested in date():
60 return date(text, temp); 60 return date(text, temp);
61} 61}
62 62
63QValidator::State 63QValidator::State
64KDateValidator::date(const QString& text, QDate& d) const 64KDateValidator::date(const QString& text, QDate& d) const
65{ 65{
66 QDate tmp = KGlobal::locale()->readDate(text); 66 QDate tmp = KGlobal::locale()->readDate(text);
67 if (!tmp.isNull()) 67 if (!tmp.isNull())
68 { 68 {
69 d = tmp; 69 d = tmp;
70 return Acceptable; 70 return Acceptable;
71 } else 71 } else
72 return Valid; 72 return Valid;
73} 73}
74 74
75void 75void
76KDateValidator::fixup( QString& ) const 76KDateValidator::fixup( QString& ) const
77{ 77{
78 78
79} 79}
80 80
81KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f) 81KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f)
82 : QGridView(parent, name, f) 82 : QGridView(parent, name, f)
83{ 83{
84 setFontSize(10); 84 setFontSize(10);
85 if(!date_.isValid()) 85 if(!date_.isValid())
86 { 86 {
87 date_=QDate::currentDate(); 87 date_=QDate::currentDate();
88 } 88 }
89 setFocusPolicy( QWidget::StrongFocus ); 89 setFocusPolicy( QWidget::StrongFocus );
90 setNumRows(7); // 6 weeks max + headline 90 setNumRows(7); // 6 weeks max + headline
91 setNumCols(7); // 7 days a week 91 setNumCols(7); // 7 days a week
92 setHScrollBarMode(AlwaysOff); 92 setHScrollBarMode(AlwaysOff);
93 setVScrollBarMode(AlwaysOff); 93 setVScrollBarMode(AlwaysOff);
94 viewport()->setBackgroundColor(QColor(220,245,255)); 94 viewport()->setBackgroundColor(QColor(220,245,255));
95#if 0 95#if 0
96 viewport()->setEraseColor(lightGray); 96 viewport()->setEraseColor(lightGray);
97#endif 97#endif
98 mMarkCurrent = false;
98 setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth 99 setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth
99} 100}
100 101
101void 102void
102KDateTable::paintCell(QPainter *painter, int row, int col) 103KDateTable::paintCell(QPainter *painter, int row, int col)
103{ 104{
104 QRect rect; 105 QRect rect;
105 QString text; 106 QString text;
106 QPen pen; 107 QPen pen;
107 int w=cellWidth(); 108 int w=cellWidth();
108 int h=cellHeight(); 109 int h=cellHeight();
109 int pos; 110 int pos;
110 QBrush brushBlue(blue); 111 QBrush brushBlue(blue);
111 QBrush brushLightblue(QColor(220,245,255)); 112 QBrush brushLightblue(QColor(220,245,255));
112 QFont font=KGlobalSettings::generalFont(); 113 QFont font=KGlobalSettings::generalFont();
113 // ----- 114 // -----
114 font.setPointSize(fontsize); 115 font.setPointSize(fontsize);
115 if(row==0) 116 if(row==0)
116 { // we are drawing the headline 117 { // we are drawing the headline
117 font.setBold(true); 118 font.setBold(true);
118 painter->setFont(font); 119 painter->setFont(font);
119 bool normalday = true; 120 bool normalday = true;
120 QString daystr; 121 QString daystr;
121 if (KGlobal::locale()->weekStartsMonday()) 122 if (KGlobal::locale()->weekStartsMonday())
122 { 123 {
123 daystr = KGlobal::locale()->weekDayName(col+1, true); 124 daystr = KGlobal::locale()->weekDayName(col+1, true);
124 if (col == 5 || col == 6) 125 if (col == 5 || col == 6)
125 normalday = false; 126 normalday = false;
126 } else { 127 } else {
127 daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true); 128 daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true);
128 if (col == 0 || col == 6) 129 if (col == 0 || col == 6)
129 normalday = false; 130 normalday = false;
130 } 131 }
131 if (!normalday) 132 if (!normalday)
132 { 133 {
133 painter->setPen(QColor(220,245,255)); 134 painter->setPen(QColor(220,245,255));
134 painter->setBrush(brushLightblue); 135 painter->setBrush(brushLightblue);
135 painter->drawRect(0, 0, w, h); 136 painter->drawRect(0, 0, w, h);
136 painter->setPen(blue); 137 painter->setPen(blue);
137 } else { 138 } else {
138 painter->setPen(blue); 139 painter->setPen(blue);
139 painter->setBrush(brushBlue); 140 painter->setBrush(brushBlue);
140 painter->drawRect(0, 0, w, h); 141 painter->drawRect(0, 0, w, h);
141 painter->setPen(white); 142 painter->setPen(white);
142 } 143 }
143 painter->drawText(0, 0, w, h-1, AlignCenter, 144 painter->drawText(0, 0, w, h-1, AlignCenter,
144 daystr, -1, &rect); 145 daystr, -1, &rect);
145 painter->setPen(black); 146 painter->setPen(black);
146 painter->moveTo(0, h-1); 147 painter->moveTo(0, h-1);
147 painter->lineTo(w-1, h-1); 148 painter->lineTo(w-1, h-1);
148 // ----- draw the weekday: 149 // ----- draw the weekday:
149 } else { 150 } else {
150 painter->setFont(font); 151 painter->setFont(font);
151 pos=7*(row-1)+col; 152 pos=7*(row-1)+col;
152 if (KGlobal::locale()->weekStartsMonday()) 153 if (KGlobal::locale()->weekStartsMonday())
153 pos++; 154 pos++;
154 if(pos<firstday || (firstday+numdays<=pos)) 155 if(pos<firstday || (firstday+numdays<=pos))
155 { // we are either 156 { // we are either
156 // ° painting a day of the previous month or 157 // ° painting a day of the previous month or
157 // ° painting a day of the following month 158 // ° painting a day of the following month
158 if(pos<firstday) 159 if(pos<firstday)
159 { // previous month 160 { // previous month
160 text.setNum(numDaysPrevMonth+pos-firstday+1); 161 text.setNum(numDaysPrevMonth+pos-firstday+1);
161 } else { // following month 162 } else { // following month
162 text.setNum(pos-firstday-numdays+1); 163 text.setNum(pos-firstday-numdays+1);
163 } 164 }
164 painter->setPen(gray); 165 painter->setPen(gray);
165 } else { // paint a day of the current month 166 } else { // paint a day of the current month
166 text.setNum(pos-firstday+1); 167 text.setNum(pos-firstday+1);
167 painter->setPen(black); 168 painter->setPen(black);
168 } 169 }
169 170
170 pen=painter->pen(); 171 pen=painter->pen();
171 if(firstday+date.day()-1==pos) 172 if(firstday+date.day()-1==pos)
172 { 173 {
174 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
175 painter->setPen(green);
176 else
177 painter->setPen(red);
173 if(hasFocus()) 178 if(hasFocus())
174 { // draw the currently selected date 179 {
175 painter->setPen(red); 180 painter->setBrush(darkRed);
176 painter->setBrush(darkRed); 181 pen=white;
177 pen=white;
178 } else { 182 } else {
179 painter->setPen(darkGray);
180 painter->setBrush(darkGray); 183 painter->setBrush(darkGray);
181 pen=white; 184 pen=white;
182 } 185 }
183 } else { 186 } else {
184 painter->setBrush(QColor(220,245,255)); 187 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
185 painter->setPen(QColor(220,245,255)); 188 {
186 } 189 painter->setPen(green);
190 painter->setBrush(darkGreen);
191 pen=white;
192 } else {
193 painter->setBrush(QColor(220,245,255));
194 painter->setPen(QColor(220,245,255));
195 }
196 }
187 painter->drawRect(0, 0, w, h); 197 painter->drawRect(0, 0, w, h);
188 painter->setPen(pen); 198 painter->setPen(pen);
189 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect); 199 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
190 } 200 }
191 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); 201 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
192 if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height()); 202 if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height());
193} 203}
194 204
195void 205void
196KDateTable::keyPressEvent( QKeyEvent *e ) 206KDateTable::keyPressEvent( QKeyEvent *e )
197{ 207{
198 /* 208 /*
199 // not working properly 209 // not working properly
200 if ( e->key() == Qt::Key_Prior ) { 210 if ( e->key() == Qt::Key_Prior ) {
201 if ( date.month() == 1 ) { 211 if ( date.month() == 1 ) {
202 KNotifyClient::beep(); 212 KNotifyClient::beep();
203 return; 213 return;
204 } 214 }
205 int day = date.day(); 215 int day = date.day();
206 if ( day > 27 ) 216 if ( day > 27 )
207 while ( !QDate::isValid( date.year(), date.month()-1, day ) ) 217 while ( !QDate::isValid( date.year(), date.month()-1, day ) )
208 day--; 218 day--;
209 setDate(QDate(date.year(), date.month()-1, day)); 219 setDate(QDate(date.year(), date.month()-1, day));
210 return; 220 return;
211 } 221 }
212 if ( e->key() == Qt::Key_Next ) { 222 if ( e->key() == Qt::Key_Next ) {
213 if ( date.month() == 12 ) { 223 if ( date.month() == 12 ) {
214 KNotifyClient::beep(); 224 KNotifyClient::beep();
215 return; 225 return;
216 } 226 }
217 int day = date.day(); 227 int day = date.day();
218 if ( day > 27 ) 228 if ( day > 27 )
219 while ( !QDate::isValid( date.year(), date.month()+1, day ) ) 229 while ( !QDate::isValid( date.year(), date.month()+1, day ) )
220 day--; 230 day--;
221 setDate(QDate(date.year(), date.month()+1, day)); 231 setDate(QDate(date.year(), date.month()+1, day));
222 return; 232 return;
223 } 233 }
224 */ 234 */
225 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; 235 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
226 236
227 int temp=firstday+date.day()-dayoff; 237 int temp=firstday+date.day()-dayoff;
228 int pos = temp; 238 int pos = temp;
229 bool irgnore = true; 239 bool irgnore = true;
230 if ( e->state() != Qt::ControlButton ) { 240 if ( e->state() != Qt::ControlButton ) {
231 if ( e->key() == Qt::Key_Up ) { 241 if ( e->key() == Qt::Key_Up ) {
232 pos -= 7; 242 pos -= 7;
233 irgnore = false; 243 irgnore = false;
234 } 244 }
235 if ( e->key() == Qt::Key_Down ) { 245 if ( e->key() == Qt::Key_Down ) {
236 pos += 7; 246 pos += 7;
237 irgnore = false; 247 irgnore = false;
238 } 248 }
239 if ( e->key() == Qt::Key_Left ) { 249 if ( e->key() == Qt::Key_Left ) {
240 pos--; 250 pos--;
241 irgnore = false; 251 irgnore = false;
242 } 252 }
243 if ( e->key() == Qt::Key_Right ) { 253 if ( e->key() == Qt::Key_Right ) {
244 pos++; 254 pos++;
245 irgnore = false; 255 irgnore = false;
246 } 256 }
247 } 257 }
248 if ( irgnore ) 258 if ( irgnore )
249 e->ignore(); 259 e->ignore();
250 260
251 if(pos+dayoff<=firstday) 261 if(pos+dayoff<=firstday)
252 { // this day is in the previous month 262 { // this day is in the previous month
253 KNotifyClient::beep(); 263 KNotifyClient::beep();
254 return; 264 return;
255 } 265 }
256 if(firstday+numdays<pos+dayoff) 266 if(firstday+numdays<pos+dayoff)
257 { // this date is in the next month 267 { // this date is in the next month
258 KNotifyClient::beep(i18n( "Month not long enough" )); 268 KNotifyClient::beep(i18n( "Month not long enough" ));
259 return; 269 return;
260 } 270 }
261 271
262 if ( pos == temp ) 272 if ( pos == temp )
263 return; 273 return;
264 274
265 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); 275 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff));
266 updateCell(temp/7+1, temp%7); // Update the previously selected cell 276 updateCell(temp/7+1, temp%7); // Update the previously selected cell
267 updateCell(pos/7+1, pos%7); // Update the selected cell 277 updateCell(pos/7+1, pos%7); // Update the selected cell
268 assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); 278 assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
269 279
270 280
271} 281}
272 282
273void 283void
274KDateTable::viewportResizeEvent(QResizeEvent * e) 284KDateTable::viewportResizeEvent(QResizeEvent * e)
275{ 285{
276 QGridView::viewportResizeEvent(e); 286 QGridView::viewportResizeEvent(e);
277 287
278 setCellWidth(viewport()->width()/7); 288 setCellWidth(viewport()->width()/7);
279 setCellHeight(viewport()->height()/7); 289 setCellHeight(viewport()->height()/7);
280} 290}
281 291
282void 292void
283KDateTable::setFontSize(int size) 293KDateTable::setFontSize(int size)
284{ 294{
285 int count; 295 int count;
286 QRect rect; 296 QRect rect;
287 // ----- store rectangles: 297 // ----- store rectangles:
288 fontsize=size; 298 fontsize=size;
289 QFont font = KGlobalSettings::generalFont(); 299 QFont font = KGlobalSettings::generalFont();
290 font.setPointSize(fontsize); 300 font.setPointSize(fontsize);
291 font.setBold( true ); 301 font.setBold( true );
292 QFontMetrics metrics(font); 302 QFontMetrics metrics(font);
293 303
294 // ----- find largest day name: 304 // ----- find largest day name:
295 maxCell.setWidth(0); 305 maxCell.setWidth(0);
296 maxCell.setHeight(0); 306 maxCell.setHeight(0);
297 for(count=0; count<7; ++count) 307 for(count=0; count<7; ++count)
298 { 308 {
299 rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true)); 309 rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true));
300 maxCell.setWidth(QMAX(maxCell.width(), rect.width())); 310 maxCell.setWidth(QMAX(maxCell.width(), rect.width()));
301 maxCell.setHeight(QMAX(maxCell.height(), rect.height())); 311 maxCell.setHeight(QMAX(maxCell.height(), rect.height()));
302 } 312 }
303 // ----- compare with a real wide number and add some space: 313 // ----- compare with a real wide number and add some space:
304 rect=metrics.boundingRect(QString::fromLatin1("88")); 314 rect=metrics.boundingRect(QString::fromLatin1("88"));
305 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width())); 315 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width()));
306 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height())); 316 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height()));
307 if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) 317 if ( maxCell.width() * 1000 / maxCell.height() > 1900 )
308 maxCell.setHeight(maxCell.width() * 1000 / 1900 ); 318 maxCell.setHeight(maxCell.width() * 1000 / 1900 );
309} 319}
310 320
311void 321void
312KDateTable::contentsMousePressEvent(QMouseEvent *e) 322KDateTable::contentsMousePressEvent(QMouseEvent *e)
313{ 323{
314 if(e->type()!=QEvent::MouseButtonPress) 324 if(e->type()!=QEvent::MouseButtonPress)
315 { // the KDatePicker only reacts on mouse press events: 325 { // the KDatePicker only reacts on mouse press events:
316 return; 326 return;
317 } 327 }
318 if(!isEnabled()) 328 if(!isEnabled())
319 { 329 {
320 KNotifyClient::beep(); 330 KNotifyClient::beep();
321 return; 331 return;
322 } 332 }
323 333
324 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; 334 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
325 // ----- 335 // -----
326 int row, col, pos, temp; 336 int row, col, pos, temp;
327 QPoint mouseCoord; 337 QPoint mouseCoord;
328 // ----- 338 // -----
329 mouseCoord = e->pos(); 339 mouseCoord = e->pos();
330 row=rowAt(mouseCoord.y()); 340 row=rowAt(mouseCoord.y());
331 col=columnAt(mouseCoord.x()); 341 col=columnAt(mouseCoord.x());
332 if(row<0 || col<0) 342 if(row<0 || col<0)
333 { // the user clicked on the frame of the table 343 { // the user clicked on the frame of the table
334 return; 344 return;
335 } 345 }
336 pos=7*(row-1)+col+1; 346 pos=7*(row-1)+col+1;
337 if(pos+dayoff<=firstday) 347 if(pos+dayoff<=firstday)
338 { // this day is in the previous month 348 { // this day is in the previous month
339 KNotifyClient::beep(); 349 KNotifyClient::beep();
340 return; 350 return;
341 } 351 }
342 if(firstday+numdays<pos+dayoff) 352 if(firstday+numdays<pos+dayoff)
343 { // this date is in the next month 353 { // this date is in the next month
344 KNotifyClient::beep(); 354 KNotifyClient::beep();
345 return; 355 return;
346 } 356 }
347 temp=firstday+date.day()-dayoff-1; 357 temp=firstday+date.day()-dayoff-1;
348 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); 358 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff));
349 updateCell(temp/7+1, temp%7); // Update the previously selected cell 359 updateCell(temp/7+1, temp%7); // Update the previously selected cell
350 updateCell(row, col); // Update the selected cell 360 updateCell(row, col); // Update the selected cell
351 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); 361 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
352 emit(tableClicked()); 362 emit(tableClicked());
353} 363}
354 364
355bool 365bool
356KDateTable::setDate(const QDate& date_) 366KDateTable::setDate(const QDate& date_)
357{ 367{
358 bool changed=false; 368 bool changed=false;
359 QDate temp; 369 QDate temp;
370 mMarkCurrent = false;
360 // ----- 371 // -----
361 if(!date_.isValid()) 372 if(!date_.isValid())
362 { 373 {
363 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl; 374 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
364 return false; 375 return false;
365 } 376 }
366 if(date!=date_) 377 if(date!=date_)
367 { 378 {
368 date=date_; 379 date=date_;
369 changed=true; 380 changed=true;
370 } 381 }
382 mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() );
371 temp.setYMD(date.year(), date.month(), 1); 383 temp.setYMD(date.year(), date.month(), 1);
372 firstday=temp.dayOfWeek(); 384 firstday=temp.dayOfWeek();
373 if(firstday==1) firstday=8; 385 if(firstday==1) firstday=8;
374 numdays=date.daysInMonth(); 386 numdays=date.daysInMonth();
375 if(date.month()==1) 387 if(date.month()==1)
376 { // set to december of previous year 388 { // set to december of previous year
377 temp.setYMD(date.year()-1, 12, 1); 389 temp.setYMD(date.year()-1, 12, 1);
378 } else { // set to previous month 390 } else { // set to previous month
379 temp.setYMD(date.year(), date.month()-1, 1); 391 temp.setYMD(date.year(), date.month()-1, 1);
380 } 392 }
381 numDaysPrevMonth=temp.daysInMonth(); 393 numDaysPrevMonth=temp.daysInMonth();
382 if(changed) 394 if(changed)
383 { 395 {
384 repaintContents(false); 396 repaintContents(false);
385 } 397 }
386 emit(dateChanged(date)); 398 emit(dateChanged(date));
387 return true; 399 return true;
388} 400}
389 401
390const QDate& 402const QDate&
391KDateTable::getDate() const 403KDateTable::getDate() const
392{ 404{
393 return date; 405 return date;
394} 406}
395 407
396void KDateTable::focusInEvent( QFocusEvent *e ) 408void KDateTable::focusInEvent( QFocusEvent *e )
397{ 409{
398 repaintContents(false); 410 repaintContents(false);
399 QGridView::focusInEvent( e ); 411 QGridView::focusInEvent( e );
400} 412}
401 413
402void KDateTable::focusOutEvent( QFocusEvent *e ) 414void KDateTable::focusOutEvent( QFocusEvent *e )
403{ 415{
404 repaintContents(false); 416 repaintContents(false);
405 QGridView::focusOutEvent( e ); 417 QGridView::focusOutEvent( e );
406} 418}
407 419
408QSize 420QSize
409KDateTable::sizeHint() const 421KDateTable::sizeHint() const
410{ 422{
411 if(maxCell.height()>0 && maxCell.width()>0) 423 if(maxCell.height()>0 && maxCell.width()>0)
412 { 424 {
413 return QSize((maxCell.width()+2)*numCols()+2*frameWidth(), 425 return QSize((maxCell.width()+2)*numCols()+2*frameWidth(),
414 (maxCell.height()+4)*numRows()+2*frameWidth()); 426 (maxCell.height()+4)*numRows()+2*frameWidth());
415 } else { 427 } else {
416 return QSize(-1, -1); 428 return QSize(-1, -1);
417 } 429 }
418} 430}
419 431
420KDateInternalMonthPicker::KDateInternalMonthPicker 432KDateInternalMonthPicker::KDateInternalMonthPicker
421(int fontsize, QWidget* parent, const char* name) 433(int fontsize, QWidget* parent, const char* name)
422 : QGridView(parent, name), 434 : QGridView(parent, name),
423 result(0) // invalid 435 result(0) // invalid
424{ 436{
425 QRect rect; 437 QRect rect;
426 QFont font; 438 QFont font;
427 // ----- 439 // -----
428 activeCol = -1; 440 activeCol = -1;
429 activeRow = -1; 441 activeRow = -1;
430 font=KGlobalSettings::generalFont(); 442 font=KGlobalSettings::generalFont();
431 font.setPointSize(fontsize); 443 font.setPointSize(fontsize);
432 setFont(font); 444 setFont(font);
433 setHScrollBarMode(AlwaysOff); 445 setHScrollBarMode(AlwaysOff);
434 setVScrollBarMode(AlwaysOff); 446 setVScrollBarMode(AlwaysOff);
435 setFrameStyle(QFrame::NoFrame); 447 setFrameStyle(QFrame::NoFrame);
436 setNumRows(4); 448 setNumRows(4);
437 setNumCols(3); 449 setNumCols(3);
438 // enable to find drawing failures: 450 // enable to find drawing failures:
439 // setTableFlags(Tbl_clipCellPainting); 451 // setTableFlags(Tbl_clipCellPainting);
440#if 0 452#if 0
441 viewport()->setEraseColor(lightGray); // for consistency with the datepicker 453 viewport()->setEraseColor(lightGray); // for consistency with the datepicker
442#endif 454#endif
443 // ----- find the preferred size 455 // ----- find the preferred size
444 // (this is slow, possibly, but unfortunatly it is needed here): 456 // (this is slow, possibly, but unfortunatly it is needed here):
445 QFontMetrics metrics(font); 457 QFontMetrics metrics(font);
446 for(int i=1; i <= 12; ++i) 458 for(int i=1; i <= 12; ++i)
447 { 459 {
448 rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); 460 rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false));
449 if(max.width()<rect.width()) max.setWidth(rect.width()); 461 if(max.width()<rect.width()) max.setWidth(rect.width());
450 if(max.height()<rect.height()) max.setHeight(rect.height()); 462 if(max.height()<rect.height()) max.setHeight(rect.height());
451 } 463 }
452 464
453} 465}
454 466
455QSize 467QSize
456KDateInternalMonthPicker::sizeHint() const 468KDateInternalMonthPicker::sizeHint() const
457{ 469{
458 return QSize((max.width()+6)*numCols()+2*frameWidth(), 470 return QSize((max.width()+6)*numCols()+2*frameWidth(),
459 (max.height()+6)*numRows()+2*frameWidth()); 471 (max.height()+6)*numRows()+2*frameWidth());
460} 472}
461 473
462int 474int
463KDateInternalMonthPicker::getResult() const 475KDateInternalMonthPicker::getResult() const
464{ 476{
465 return result; 477 return result;
466} 478}
467 479
468void 480void
469KDateInternalMonthPicker::setupPainter(QPainter *p) 481KDateInternalMonthPicker::setupPainter(QPainter *p)
470{ 482{
471 p->setPen(black); 483 p->setPen(black);
472} 484}
473 485
474void 486void
475KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*) 487KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*)
476{ 488{
477 setCellWidth(width()/3); 489 setCellWidth(width()/3);
478 setCellHeight(height()/4); 490 setCellHeight(height()/4);
479} 491}
480 492
481void 493void
482KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col) 494KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col)
483{ 495{
484 int index; 496 int index;
485 QString text; 497 QString text;
486 // ----- find the number of the cell: 498 // ----- find the number of the cell:
487 index=3*row+col+1; 499 index=3*row+col+1;
488 text=KGlobal::locale()->monthName(index, false); 500 text=KGlobal::locale()->monthName(index, false);
489 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); 501 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
490 if ( activeCol == col && activeRow == row ) 502 if ( activeCol == col && activeRow == row )
491 painter->drawRect( 0, 0, cellWidth(), cellHeight() ); 503 painter->drawRect( 0, 0, cellWidth(), cellHeight() );
492} 504}
493 505
494void 506void
495KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e) 507KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e)
496{ 508{
497 if(!isEnabled() || e->button() != LeftButton) 509 if(!isEnabled() || e->button() != LeftButton)
498 { 510 {
499 KNotifyClient::beep(); 511 KNotifyClient::beep();
500 return; 512 return;
501 } 513 }
502 // ----- 514 // -----
503 int row, col; 515 int row, col;
504 QPoint mouseCoord; 516 QPoint mouseCoord;
505 // ----- 517 // -----
506 mouseCoord = e->pos(); 518 mouseCoord = e->pos();
507 row=rowAt(mouseCoord.y()); 519 row=rowAt(mouseCoord.y());
508 col=columnAt(mouseCoord.x()); 520 col=columnAt(mouseCoord.x());
509 521
510 if(row<0 || col<0) 522 if(row<0 || col<0)
511 { // the user clicked on the frame of the table 523 { // the user clicked on the frame of the table
512 activeCol = -1; 524 activeCol = -1;
513 activeRow = -1; 525 activeRow = -1;
514 } else { 526 } else {
515 activeCol = col; 527 activeCol = col;
516 activeRow = row; 528 activeRow = row;
517 updateCell( row, col /*, false */ ); 529 updateCell( row, col /*, false */ );
518 } 530 }
519} 531}
520 532
521void 533void
522KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e) 534KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e)
523{ 535{
524 if (e->state() & LeftButton) 536 if (e->state() & LeftButton)
525 { 537 {
526 int row, col; 538 int row, col;
527 QPoint mouseCoord; 539 QPoint mouseCoord;
528 // ----- 540 // -----
529 mouseCoord = e->pos(); 541 mouseCoord = e->pos();
530 row=rowAt(mouseCoord.y()); 542 row=rowAt(mouseCoord.y());
531 col=columnAt(mouseCoord.x()); 543 col=columnAt(mouseCoord.x());
532 int tmpRow = -1, tmpCol = -1; 544 int tmpRow = -1, tmpCol = -1;
533 if(row<0 || col<0) 545 if(row<0 || col<0)
534 { // the user clicked on the frame of the table 546 { // the user clicked on the frame of the table
535 if ( activeCol > -1 ) 547 if ( activeCol > -1 )
536 { 548 {
537 tmpRow = activeRow; 549 tmpRow = activeRow;
538 tmpCol = activeCol; 550 tmpCol = activeCol;
539 } 551 }
540 activeCol = -1; 552 activeCol = -1;
541 activeRow = -1; 553 activeRow = -1;
542 } else { 554 } else {
543 bool differentCell = (activeRow != row || activeCol != col); 555 bool differentCell = (activeRow != row || activeCol != col);
544 if ( activeCol > -1 && differentCell) 556 if ( activeCol > -1 && differentCell)
545 { 557 {
546 tmpRow = activeRow; 558 tmpRow = activeRow;
547 tmpCol = activeCol; 559 tmpCol = activeCol;
548 } 560 }
549 if ( differentCell) 561 if ( differentCell)
550 { 562 {
551 activeRow = row; 563 activeRow = row;
552 activeCol = col; 564 activeCol = col;
553 updateCell( row, col /*, false */ ); // mark the new active cell 565 updateCell( row, col /*, false */ ); // mark the new active cell
554 } 566 }
555 } 567 }
556 if ( tmpRow > -1 ) // repaint the former active cell 568 if ( tmpRow > -1 ) // repaint the former active cell
557 updateCell( tmpRow, tmpCol /*, true */ ); 569 updateCell( tmpRow, tmpCol /*, true */ );
558 } 570 }
559} 571}
560 572
561void 573void
562KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e) 574KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e)
563{ 575{
564 if(!isEnabled()) 576 if(!isEnabled())
565 { 577 {
566 return; 578 return;
567 } 579 }
568 // ----- 580 // -----
569 int row, col, pos; 581 int row, col, pos;
570 QPoint mouseCoord; 582 QPoint mouseCoord;
571 // ----- 583 // -----
572 mouseCoord = e->pos(); 584 mouseCoord = e->pos();
573 row=rowAt(mouseCoord.y()); 585 row=rowAt(mouseCoord.y());
574 col=columnAt(mouseCoord.x()); 586 col=columnAt(mouseCoord.x());
575 if(row<0 || col<0) 587 if(row<0 || col<0)
576 { // the user clicked on the frame of the table 588 { // the user clicked on the frame of the table
577 emit(closeMe(0)); 589 emit(closeMe(0));
578 } 590 }
579 pos=3*row+col+1; 591 pos=3*row+col+1;
580 result=pos; 592 result=pos;
581 emit(closeMe(1)); 593 emit(closeMe(1));
582} 594}
583 595
584 596
585 597
586KDateInternalYearSelector::KDateInternalYearSelector 598KDateInternalYearSelector::KDateInternalYearSelector
587(int fontsize, QWidget* parent, const char* name) 599(int fontsize, QWidget* parent, const char* name)
588 : QLineEdit(parent, name), 600 : QLineEdit(parent, name),
589 val(new QIntValidator(this)), 601 val(new QIntValidator(this)),
590 result(0) 602 result(0)
591{ 603{
592 QFont font; 604 QFont font;
593 // ----- 605 // -----
594 font=KGlobalSettings::generalFont(); 606 font=KGlobalSettings::generalFont();
595 font.setPointSize(fontsize); 607 font.setPointSize(fontsize);
596 setFont(font); 608 setFont(font);
597#if 0 609#if 0
598 setFrameStyle(QFrame::NoFrame); 610 setFrameStyle(QFrame::NoFrame);
599#endif 611#endif
600 // we have to respect the limits of QDate here, I fear: 612 // we have to respect the limits of QDate here, I fear:
601 val->setRange(0, 8000); 613 val->setRange(0, 8000);
602 setValidator(val); 614 setValidator(val);
603 connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot())); 615 connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot()));
604} 616}
605 617
606void 618void
607KDateInternalYearSelector::yearEnteredSlot() 619KDateInternalYearSelector::yearEnteredSlot()
608{ 620{
609 bool ok; 621 bool ok;
610 int year; 622 int year;
611 QDate date; 623 QDate date;
612 // ----- check if this is a valid year: 624 // ----- check if this is a valid year:
613 year=text().toInt(&ok); 625 year=text().toInt(&ok);
614 if(!ok) 626 if(!ok)
615 { 627 {
616 KNotifyClient::beep(); 628 KNotifyClient::beep();
617 return; 629 return;
618 } 630 }
619 date.setYMD(year, 1, 1); 631 date.setYMD(year, 1, 1);
620 if(!date.isValid()) 632 if(!date.isValid())
621 { 633 {
622 KNotifyClient::beep(); 634 KNotifyClient::beep();
623 return; 635 return;
624 } 636 }
625 result=year; 637 result=year;
626 emit(closeMe(1)); 638 emit(closeMe(1));
627} 639}
628 640
629int 641int
630KDateInternalYearSelector::getYear() 642KDateInternalYearSelector::getYear()
631{ 643{
632 return result; 644 return result;
633} 645}
634 646
635void 647void
636KDateInternalYearSelector::setYear(int year) 648KDateInternalYearSelector::setYear(int year)
637{ 649{
638 QString temp; 650 QString temp;
639 // ----- 651 // -----
640 temp.setNum(year); 652 temp.setNum(year);
641 setText(temp); 653 setText(temp);
642} 654}
643 655
644KPopupFrame::KPopupFrame(QWidget* parent, const char* name) 656KPopupFrame::KPopupFrame(QWidget* parent, const char* name)
645 : QFrame(parent, name, WType_Popup), 657 : QFrame(parent, name, WType_Popup),
646 result(0), // rejected 658 result(0), // rejected
647 main(0) 659 main(0)
648{ 660{
649 setFrameStyle(QFrame::Box|QFrame::Raised); 661 setFrameStyle(QFrame::Box|QFrame::Raised);
650 setMidLineWidth(2); 662 setMidLineWidth(2);
651} 663}
652 664
653void 665void
654KPopupFrame::keyPressEvent(QKeyEvent* e) 666KPopupFrame::keyPressEvent(QKeyEvent* e)
655{ 667{
656 if(e->key()==Key_Escape) 668 if(e->key()==Key_Escape)
657 { 669 {
658 result=0; // rejected 670 result=0; // rejected
659 qApp->exit_loop(); 671 qApp->exit_loop();
660 } 672 }
661} 673}
662 674
663void 675void
664KPopupFrame::close(int r) 676KPopupFrame::close(int r)
665{ 677{
666 result=r; 678 result=r;
667 qApp->exit_loop(); 679 qApp->exit_loop();
668} 680}
669 681
670void 682void
671KPopupFrame::setMainWidget(QWidget* m) 683KPopupFrame::setMainWidget(QWidget* m)
672{ 684{
673 main=m; 685 main=m;
674 if(main!=0) 686 if(main!=0)
675 { 687 {
676 resize(main->width()+2*frameWidth(), main->height()+2*frameWidth()); 688 resize(main->width()+2*frameWidth(), main->height()+2*frameWidth());
677 } 689 }
678} 690}
679 691
680void 692void
681KPopupFrame::resizeEvent(QResizeEvent*) 693KPopupFrame::resizeEvent(QResizeEvent*)
682{ 694{
683 if(main!=0) 695 if(main!=0)
684 { 696 {
685 main->setGeometry(frameWidth(), frameWidth(), 697 main->setGeometry(frameWidth(), frameWidth(),
686 width()-2*frameWidth(), height()-2*frameWidth()); 698 width()-2*frameWidth(), height()-2*frameWidth());
687 } 699 }
688} 700}
689 701
690void 702void
691KPopupFrame::popup(const QPoint &pos) 703KPopupFrame::popup(const QPoint &pos)
692{ 704{
693 // Make sure the whole popup is visible. 705 // Make sure the whole popup is visible.
694 QRect d = QApplication::desktop()->frameGeometry(); 706 QRect d = QApplication::desktop()->frameGeometry();
695 int x = pos.x(); 707 int x = pos.x();
696 int y = pos.y(); 708 int y = pos.y();
697 int w = width(); 709 int w = width();
698 int h = height(); 710 int h = height();
699 if (x+w > d.x()+d.width()) 711 if (x+w > d.x()+d.width())
700 x = d.width() - w; 712 x = d.width() - w;
701 if (y+h > d.y()+d.height()) 713 if (y+h > d.y()+d.height())
702 y = d.height() - h; 714 y = d.height() - h;
703 if (x < d.x()) 715 if (x < d.x())
704 x = 0; 716 x = 0;
705 if (y < d.y()) 717 if (y < d.y())
706 y = 0; 718 y = 0;
707 719
708 // Pop the thingy up. 720 // Pop the thingy up.
709 move(x, y); 721 move(x, y);
710 show(); 722 show();
711} 723}
712 724
713int 725int
714KPopupFrame::exec(QPoint pos) 726KPopupFrame::exec(QPoint pos)
715{ 727{
716 popup(pos); 728 popup(pos);
717 repaint(); 729 repaint();
718 qApp->enter_loop(); 730 qApp->enter_loop();
719 hide(); 731 hide();
720 return result; 732 return result;
721} 733}
722 734
723int 735int
724KPopupFrame::exec(int x, int y) 736KPopupFrame::exec(int x, int y)
725{ 737{
726 return exec(QPoint(x, y)); 738 return exec(QPoint(x, y));
727} 739}
728 740
729void KPopupFrame::virtual_hook( int, void* ) 741void KPopupFrame::virtual_hook( int, void* )
730{ /*BASE::virtual_hook( id, data );*/ } 742{ /*BASE::virtual_hook( id, data );*/ }
731 743
732void KDateTable::virtual_hook( int, void* ) 744void KDateTable::virtual_hook( int, void* )
733{ /*BASE::virtual_hook( id, data );*/ } 745{ /*BASE::virtual_hook( id, data );*/ }
734 746
735//#include "kdatetbl.moc" 747//#include "kdatetbl.moc"
diff --git a/microkde/kdatetbl.h b/microkde/kdatetbl.h
index df7b7ef..b4d3e16 100644
--- a/microkde/kdatetbl.h
+++ b/microkde/kdatetbl.h
@@ -1,308 +1,309 @@
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#ifndef KDATETBL_H 20#ifndef KDATETBL_H
21#define KDATETBL_H 21#define KDATETBL_H
22 22
23#include <qvalidator.h> 23#include <qvalidator.h>
24#include <qgridview.h> 24#include <qgridview.h>
25#include <qlineedit.h> 25#include <qlineedit.h>
26#include <qdatetime.h> 26#include <qdatetime.h>
27 27
28/** 28/**
29* A table containing month names. It is used to pick a month directly. 29* A table containing month names. It is used to pick a month directly.
30* @internal 30* @internal
31* @version $Id$ 31* @version $Id$
32* @author Tim Gilman, Mirko Boehm 32* @author Tim Gilman, Mirko Boehm
33*/ 33*/
34class KDateInternalMonthPicker : public QGridView 34class KDateInternalMonthPicker : public QGridView
35{ 35{
36 Q_OBJECT 36 Q_OBJECT
37protected: 37protected:
38 /** 38 /**
39 * Store the month that has been clicked [1..12]. 39 * Store the month that has been clicked [1..12].
40 */ 40 */
41 int result; 41 int result;
42 /** 42 /**
43 * the cell under mouse cursor when LBM is pressed 43 * the cell under mouse cursor when LBM is pressed
44 */ 44 */
45 short int activeCol; 45 short int activeCol;
46 short int activeRow; 46 short int activeRow;
47 /** 47 /**
48 * Contains the largest rectangle needed by the month names. 48 * Contains the largest rectangle needed by the month names.
49 */ 49 */
50 QRect max; 50 QRect max;
51signals: 51signals:
52 /** 52 /**
53 * This is send from the mouse click event handler. 53 * This is send from the mouse click event handler.
54 */ 54 */
55 void closeMe(int); 55 void closeMe(int);
56public: 56public:
57 /** 57 /**
58 * The constructor. 58 * The constructor.
59 */ 59 */
60 KDateInternalMonthPicker(int fontsize, QWidget* parent, const char* name=0); 60 KDateInternalMonthPicker(int fontsize, QWidget* parent, const char* name=0);
61 /** 61 /**
62 * The size hint. 62 * The size hint.
63 */ 63 */
64 QSize sizeHint() const; 64 QSize sizeHint() const;
65 /** 65 /**
66 * Return the result. 0 means no selection (reject()), 1..12 are the 66 * Return the result. 0 means no selection (reject()), 1..12 are the
67 * months. 67 * months.
68 */ 68 */
69 int getResult() const; 69 int getResult() const;
70protected: 70protected:
71 /** 71 /**
72 * Set up the painter. 72 * Set up the painter.
73 */ 73 */
74 void setupPainter(QPainter *p); 74 void setupPainter(QPainter *p);
75 /** 75 /**
76 * The resize event. 76 * The resize event.
77 */ 77 */
78 void viewportResizeEvent(QResizeEvent*); 78 void viewportResizeEvent(QResizeEvent*);
79 /** 79 /**
80 * Paint a cell. This simply draws the month names in it. 80 * Paint a cell. This simply draws the month names in it.
81 */ 81 */
82 virtual void paintCell(QPainter* painter, int row, int col); 82 virtual void paintCell(QPainter* painter, int row, int col);
83 /** 83 /**
84 * Catch mouse click and move events to paint a rectangle around the item. 84 * Catch mouse click and move events to paint a rectangle around the item.
85 */ 85 */
86 void contentsMousePressEvent(QMouseEvent *e); 86 void contentsMousePressEvent(QMouseEvent *e);
87 void contentsMouseMoveEvent(QMouseEvent *e); 87 void contentsMouseMoveEvent(QMouseEvent *e);
88 /** 88 /**
89 * Emit monthSelected(int) when a cell has been released. 89 * Emit monthSelected(int) when a cell has been released.
90 */ 90 */
91 void contentsMouseReleaseEvent(QMouseEvent *e); 91 void contentsMouseReleaseEvent(QMouseEvent *e);
92 92
93private: 93private:
94 class KDateInternalMonthPrivate; 94 class KDateInternalMonthPrivate;
95 KDateInternalMonthPrivate *d; 95 KDateInternalMonthPrivate *d;
96}; 96};
97 97
98/** Year selection widget. 98/** Year selection widget.
99* @internal 99* @internal
100* @version $Id$ 100* @version $Id$
101* @author Tim Gilman, Mirko Boehm 101* @author Tim Gilman, Mirko Boehm
102*/ 102*/
103class KDateInternalYearSelector : public QLineEdit 103class KDateInternalYearSelector : public QLineEdit
104{ 104{
105 Q_OBJECT 105 Q_OBJECT
106protected: 106protected:
107 QIntValidator *val; 107 QIntValidator *val;
108 int result; 108 int result;
109public slots: 109public slots:
110 void yearEnteredSlot(); 110 void yearEnteredSlot();
111signals: 111signals:
112 void closeMe(int); 112 void closeMe(int);
113public: 113public:
114 KDateInternalYearSelector(int fontsize, 114 KDateInternalYearSelector(int fontsize,
115 QWidget* parent=0, 115 QWidget* parent=0,
116 const char* name=0); 116 const char* name=0);
117 int getYear(); 117 int getYear();
118 void setYear(int year); 118 void setYear(int year);
119 119
120private: 120private:
121 class KDateInternalYearPrivate; 121 class KDateInternalYearPrivate;
122 KDateInternalYearPrivate *d; 122 KDateInternalYearPrivate *d;
123}; 123};
124 124
125/** 125/**
126 * Frame with popup menu behaviour. 126 * Frame with popup menu behaviour.
127 * @author Tim Gilman, Mirko Boehm 127 * @author Tim Gilman, Mirko Boehm
128 * @version $Id$ 128 * @version $Id$
129 */ 129 */
130class KPopupFrame : public QFrame 130class KPopupFrame : public QFrame
131{ 131{
132 Q_OBJECT 132 Q_OBJECT
133protected: 133protected:
134 /** 134 /**
135 * The result. It is returned from exec() when the popup window closes. 135 * The result. It is returned from exec() when the popup window closes.
136 */ 136 */
137 int result; 137 int result;
138 /** 138 /**
139 * Catch key press events. 139 * Catch key press events.
140 */ 140 */
141 void keyPressEvent(QKeyEvent* e); 141 void keyPressEvent(QKeyEvent* e);
142 /** 142 /**
143 * The only subwidget that uses the whole dialog window. 143 * The only subwidget that uses the whole dialog window.
144 */ 144 */
145 QWidget *main; 145 QWidget *main;
146public slots: 146public slots:
147 /** 147 /**
148 * Close the popup window. This is called from the main widget, usually. 148 * Close the popup window. This is called from the main widget, usually.
149 * @p r is the result returned from exec(). 149 * @p r is the result returned from exec().
150 */ 150 */
151 void close(int r); 151 void close(int r);
152public: 152public:
153 /** 153 /**
154 * The contructor. Creates a dialog without buttons. 154 * The contructor. Creates a dialog without buttons.
155 */ 155 */
156 KPopupFrame(QWidget* parent=0, const char* name=0); 156 KPopupFrame(QWidget* parent=0, const char* name=0);
157 /** 157 /**
158 * Set the main widget. You cannot set the main widget from the constructor, 158 * Set the main widget. You cannot set the main widget from the constructor,
159 * since it must be a child of the frame itselfes. 159 * since it must be a child of the frame itselfes.
160 * Be careful: the size is set to the main widgets size. It is up to you to 160 * Be careful: the size is set to the main widgets size. It is up to you to
161 * set the main widgets correct size before setting it as the main 161 * set the main widgets correct size before setting it as the main
162 * widget. 162 * widget.
163 */ 163 */
164 void setMainWidget(QWidget* m); 164 void setMainWidget(QWidget* m);
165 /** 165 /**
166 * The resize event. Simply resizes the main widget to the whole 166 * The resize event. Simply resizes the main widget to the whole
167 * widgets client size. 167 * widgets client size.
168 */ 168 */
169 void resizeEvent(QResizeEvent*); 169 void resizeEvent(QResizeEvent*);
170 /** 170 /**
171 * Open the popup window at position pos. 171 * Open the popup window at position pos.
172 */ 172 */
173 void popup(const QPoint &pos); 173 void popup(const QPoint &pos);
174 /** 174 /**
175 * Execute the popup window. 175 * Execute the popup window.
176 */ 176 */
177 int exec(QPoint p); 177 int exec(QPoint p);
178 /** 178 /**
179 * Dito. 179 * Dito.
180 */ 180 */
181 int exec(int x, int y); 181 int exec(int x, int y);
182 182
183private: 183private:
184 184
185 virtual bool close(bool alsoDelete) { return QFrame::close(alsoDelete); } 185 virtual bool close(bool alsoDelete) { return QFrame::close(alsoDelete); }
186protected: 186protected:
187 virtual void virtual_hook( int id, void* data ); 187 virtual void virtual_hook( int id, void* data );
188private: 188private:
189 class KPopupFramePrivate; 189 class KPopupFramePrivate;
190 KPopupFramePrivate *d; 190 KPopupFramePrivate *d;
191}; 191};
192 192
193/** 193/**
194* Validates user-entered dates. 194* Validates user-entered dates.
195*/ 195*/
196class KDateValidator : public QValidator 196class KDateValidator : public QValidator
197{ 197{
198public: 198public:
199 KDateValidator(QWidget* parent=0, const char* name=0); 199 KDateValidator(QWidget* parent=0, const char* name=0);
200 virtual State validate(QString&, int&) const; 200 virtual State validate(QString&, int&) const;
201 virtual void fixup ( QString & input ) const; 201 virtual void fixup ( QString & input ) const;
202 State date(const QString&, QDate&) const; 202 State date(const QString&, QDate&) const;
203}; 203};
204 204
205/** 205/**
206 * Date selection table. 206 * Date selection table.
207 * This is a support class for the KDatePicker class. It just 207 * This is a support class for the KDatePicker class. It just
208 * draws the calender table without titles, but could theoretically 208 * draws the calender table without titles, but could theoretically
209 * be used as a standalone. 209 * be used as a standalone.
210 * 210 *
211 * When a date is selected by the user, it emits a signal: 211 * When a date is selected by the user, it emits a signal:
212 * dateSelected(QDate) 212 * dateSelected(QDate)
213 * 213 *
214 * @internal 214 * @internal
215 * @version $Id$ 215 * @version $Id$
216 * @author Tim Gilman, Mirko Boehm 216 * @author Tim Gilman, Mirko Boehm
217 */ 217 */
218class KDateTable : public QGridView 218class KDateTable : public QGridView
219{ 219{
220 Q_OBJECT 220 Q_OBJECT
221public: 221public:
222 /** 222 /**
223 * The constructor. 223 * The constructor.
224 */ 224 */
225 KDateTable(QWidget *parent=0, 225 KDateTable(QWidget *parent=0,
226 QDate date=QDate::currentDate(), 226 QDate date=QDate::currentDate(),
227 const char* name=0, WFlags f=0); 227 const char* name=0, WFlags f=0);
228 /** 228 /**
229 * Returns a recommended size for the widget. 229 * Returns a recommended size for the widget.
230 * To save some time, the size of the largest used cell content is 230 * To save some time, the size of the largest used cell content is
231 * calculated in each paintCell() call, since all calculations have 231 * calculated in each paintCell() call, since all calculations have
232 * to be done there anyway. The size is stored in maxCell. The 232 * to be done there anyway. The size is stored in maxCell. The
233 * sizeHint() simply returns a multiple of maxCell. 233 * sizeHint() simply returns a multiple of maxCell.
234 */ 234 */
235 virtual QSize sizeHint() const; 235 virtual QSize sizeHint() const;
236 /** 236 /**
237 * Set the font size of the date table. 237 * Set the font size of the date table.
238 */ 238 */
239 void setFontSize(int size); 239 void setFontSize(int size);
240 /** 240 /**
241 * Select and display this date. 241 * Select and display this date.
242 */ 242 */
243 bool setDate(const QDate&); 243 bool setDate(const QDate&);
244 const QDate& getDate() const; 244 const QDate& getDate() const;
245 245
246 246
247protected: 247protected:
248 bool mMarkCurrent;
248 /** 249 /**
249 * Paint a cell. 250 * Paint a cell.
250 */ 251 */
251 virtual void paintCell(QPainter*, int, int); 252 virtual void paintCell(QPainter*, int, int);
252 /** 253 /**
253 * Handle the resize events. 254 * Handle the resize events.
254 */ 255 */
255 virtual void viewportResizeEvent(QResizeEvent *); 256 virtual void viewportResizeEvent(QResizeEvent *);
256 /** 257 /**
257 * React on mouse clicks that select a date. 258 * React on mouse clicks that select a date.
258 */ 259 */
259 virtual void contentsMousePressEvent(QMouseEvent *); 260 virtual void contentsMousePressEvent(QMouseEvent *);
260 virtual void keyPressEvent( QKeyEvent *e ); 261 virtual void keyPressEvent( QKeyEvent *e );
261 virtual void focusInEvent( QFocusEvent *e ); 262 virtual void focusInEvent( QFocusEvent *e );
262 virtual void focusOutEvent( QFocusEvent *e ); 263 virtual void focusOutEvent( QFocusEvent *e );
263 /** 264 /**
264 * The font size of the displayed text. 265 * The font size of the displayed text.
265 */ 266 */
266 int fontsize; 267 int fontsize;
267 /** 268 /**
268 * The currently selected date. 269 * The currently selected date.
269 */ 270 */
270 QDate date; 271 QDate date;
271 /** 272 /**
272 * The day of the first day in the month [1..7]. 273 * The day of the first day in the month [1..7].
273 */ 274 */
274 int firstday; 275 int firstday;
275 /** 276 /**
276 * The number of days in the current month. 277 * The number of days in the current month.
277 */ 278 */
278 int numdays; 279 int numdays;
279 /** 280 /**
280 * The number of days in the previous month. 281 * The number of days in the previous month.
281 */ 282 */
282 int numDaysPrevMonth; 283 int numDaysPrevMonth;
283 /** 284 /**
284 * unused 285 * unused
285 */ 286 */
286 bool unused_hasSelection; 287 bool unused_hasSelection;
287 /** 288 /**
288 * Save the size of the largest used cell content. 289 * Save the size of the largest used cell content.
289 */ 290 */
290 QRect maxCell; 291 QRect maxCell;
291signals: 292signals:
292 /** 293 /**
293 * The selected date changed. 294 * The selected date changed.
294 */ 295 */
295 void dateChanged(QDate); 296 void dateChanged(QDate);
296 /** 297 /**
297 * A date has been selected by clicking on the table. 298 * A date has been selected by clicking on the table.
298 */ 299 */
299 void tableClicked(); 300 void tableClicked();
300 301
301protected: 302protected:
302 virtual void virtual_hook( int id, void* data ); 303 virtual void virtual_hook( int id, void* data );
303private: 304private:
304 class KDateTablePrivate; 305 class KDateTablePrivate;
305 KDateTablePrivate *d; 306 KDateTablePrivate *d;
306}; 307};
307 308
308#endif // KDATETBL_H 309#endif // KDATETBL_H