summaryrefslogtreecommitdiffabout
Unidiff
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
@@ -2,465 +2,477 @@
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}
diff --git a/microkde/kdatetbl.h b/microkde/kdatetbl.h
index df7b7ef..b4d3e16 100644
--- a/microkde/kdatetbl.h
+++ b/microkde/kdatetbl.h
@@ -152,157 +152,158 @@ public slots:
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