summaryrefslogtreecommitdiffabout
path: root/microkde/kdatetbl.cpp
authorzautrix <zautrix>2005-10-27 23:22:36 (UTC)
committer zautrix <zautrix>2005-10-27 23:22:36 (UTC)
commitcbda16d4966c7483d20d1b6b5a64c8af367ea732 (patch) (unidiff)
tree47099fd5b318c47eb1d8fff3d8a3eef6e34f6f23 /microkde/kdatetbl.cpp
parentd6d384e50cfd511866958e58cdd3adeb35ed1c4e (diff)
downloadkdepimpi-cbda16d4966c7483d20d1b6b5a64c8af367ea732.zip
kdepimpi-cbda16d4966c7483d20d1b6b5a64c8af367ea732.tar.gz
kdepimpi-cbda16d4966c7483d20d1b6b5a64c8af367ea732.tar.bz2
us fix
Diffstat (limited to 'microkde/kdatetbl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdatetbl.cpp32
1 files changed, 10 insertions, 22 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index 4271b55..353f78d 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -1,667 +1,655 @@
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 setFont( KGlobalSettings::generalFont() ); 84 setFont( KGlobalSettings::generalFont() );
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 mMarkCurrent = false;
99 setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth 99 setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth
100} 100}
101 101
102void 102void
103KDateTable::paintCell(QPainter *painter, int row, int col) 103KDateTable::paintCell(QPainter *painter, int row, int col)
104{ 104{
105 QRect rect; 105 QRect rect;
106 QString text; 106 QString text;
107 QPen pen; 107 QPen pen;
108 int w=cellWidth(); 108 int w=cellWidth();
109 int h=cellHeight(); 109 int h=cellHeight();
110 int pos; 110 int pos;
111 QBrush brushBlue(blue); 111 QBrush brushBlue(blue);
112 QBrush brushLightblue(QColor(220,245,255)); 112 QBrush brushLightblue(QColor(220,245,255));
113 QFont _font=font(); 113 QFont _font=font();
114 // ----- 114 // -----
115 if(row==0) 115 if(row==0)
116 { // we are drawing the headline 116 { // we are drawing the headline
117 _font.setBold(true); 117 _font.setBold(true);
118 painter->setFont(_font); 118 painter->setFont(_font);
119 bool normalday = true; 119 bool normalday = true;
120 QString daystr; 120 QString daystr;
121 if (KGlobal::locale()->weekStartsMonday()) 121 if (KGlobal::locale()->weekStartsMonday())
122 { 122 {
123 daystr = KGlobal::locale()->weekDayName(col+1, true); 123 daystr = KGlobal::locale()->weekDayName(col+1, true);
124 if (col == 5 || col == 6) 124 if (col == 5 || col == 6)
125 normalday = false; 125 normalday = false;
126 } else { 126 } else {
127 daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true); 127 daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true);
128 if (col == 0 || col == 6) 128 if (col == 0 || col == 6)
129 normalday = false; 129 normalday = false;
130 } 130 }
131 if (!normalday) 131 if (!normalday)
132 { 132 {
133 painter->setPen(QColor(220,245,255)); 133 painter->setPen(QColor(220,245,255));
134 painter->setBrush(brushLightblue); 134 painter->setBrush(brushLightblue);
135 painter->drawRect(0, 0, w, h); 135 painter->drawRect(0, 0, w, h);
136 painter->setPen(blue); 136 painter->setPen(blue);
137 } else { 137 } else {
138 painter->setPen(blue); 138 painter->setPen(blue);
139 painter->setBrush(brushBlue); 139 painter->setBrush(brushBlue);
140 painter->drawRect(0, 0, w, h); 140 painter->drawRect(0, 0, w, h);
141 painter->setPen(white); 141 painter->setPen(white);
142 } 142 }
143 painter->drawText(0, 0, w, h-1, AlignCenter, 143 painter->drawText(0, 0, w, h-1, AlignCenter,
144 daystr, -1, &rect); 144 daystr, -1, &rect);
145 painter->setPen(black); 145 painter->setPen(black);
146 painter->moveTo(0, h-1); 146 painter->moveTo(0, h-1);
147 painter->lineTo(w-1, h-1); 147 painter->lineTo(w-1, h-1);
148 // ----- draw the weekday: 148 // ----- draw the weekday:
149 } else { 149 } else {
150 painter->setFont(_font); 150 painter->setFont(_font);
151 pos=7*(row-1)+col; 151 pos=7*(row-1)+col;
152 if (KGlobal::locale()->weekStartsMonday()) 152 if (KGlobal::locale()->weekStartsMonday())
153 pos++; 153 pos++;
154 if(pos<firstday || (firstday+numdays<=pos)) 154 if(pos<firstday || (firstday+numdays<=pos))
155 { // we are either 155 { // we are either
156 // ° painting a day of the previous month or 156 // ° painting a day of the previous month or
157 // ° painting a day of the following month 157 // ° painting a day of the following month
158 if(pos<firstday) 158 if(pos<firstday)
159 { // previous month 159 { // previous month
160 text.setNum(numDaysPrevMonth+pos-firstday+1); 160 text.setNum(numDaysPrevMonth+pos-firstday+1);
161 } else { // following month 161 } else { // following month
162 text.setNum(pos-firstday-numdays+1); 162 text.setNum(pos-firstday-numdays+1);
163 } 163 }
164 painter->setPen(gray); 164 painter->setPen(gray);
165 } else { // paint a day of the current month 165 } else { // paint a day of the current month
166 text.setNum(pos-firstday+1); 166 text.setNum(pos-firstday+1);
167 painter->setPen(black); 167 painter->setPen(black);
168 } 168 }
169 169
170 pen=painter->pen(); 170 pen=painter->pen();
171 if(firstday+date.day()-1==pos) 171 if(firstday+date.day()-1==pos)
172 { 172 {
173 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) 173 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
174 painter->setPen(green); 174 painter->setPen(green);
175 else 175 else
176 painter->setPen(red); 176 painter->setPen(red);
177 if(hasFocus()) 177 if(hasFocus())
178 { 178 {
179 painter->setBrush(darkRed); 179 painter->setBrush(darkRed);
180 pen=white; 180 pen=white;
181 } else { 181 } else {
182 painter->setBrush(darkGray); 182 painter->setBrush(darkGray);
183 pen=white; 183 pen=white;
184 } 184 }
185 } else { 185 } else {
186 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) 186 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
187 { 187 {
188 painter->setPen(green); 188 painter->setPen(green);
189 painter->setBrush(darkGreen); 189 painter->setBrush(darkGreen);
190 pen=white; 190 pen=white;
191 } else { 191 } else {
192 painter->setBrush(QColor(220,245,255)); 192 painter->setBrush(QColor(220,245,255));
193 painter->setPen(QColor(220,245,255)); 193 painter->setPen(QColor(220,245,255));
194 } 194 }
195 } 195 }
196 painter->drawRect(0, 0, w, h); 196 painter->drawRect(0, 0, w, h);
197 painter->setPen(pen); 197 painter->setPen(pen);
198 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect); 198 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
199 } 199 }
200 /* 200 /*
201 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); 201 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
202 if(rect.height()>maxCell.height()) { 202 if(rect.height()>maxCell.height()) {
203 maxCell.setHeight(rect.height()); 203 maxCell.setHeight(rect.height());
204 } 204 }
205 */ 205 */
206} 206}
207 207
208void 208void
209KDateTable::keyPressEvent( QKeyEvent *e ) 209KDateTable::keyPressEvent( QKeyEvent *e )
210{ 210{
211 /* 211 /*
212 // not working properly 212 // not working properly
213 if ( e->key() == Qt::Key_Prior ) { 213 if ( e->key() == Qt::Key_Prior ) {
214 if ( date.month() == 1 ) { 214 if ( date.month() == 1 ) {
215 KNotifyClient::beep(); 215 KNotifyClient::beep();
216 return; 216 return;
217 } 217 }
218 int day = date.day(); 218 int day = date.day();
219 if ( day > 27 ) 219 if ( day > 27 )
220 while ( !QDate::isValid( date.year(), date.month()-1, day ) ) 220 while ( !QDate::isValid( date.year(), date.month()-1, day ) )
221 day--; 221 day--;
222 setDate(QDate(date.year(), date.month()-1, day)); 222 setDate(QDate(date.year(), date.month()-1, day));
223 return; 223 return;
224 } 224 }
225 if ( e->key() == Qt::Key_Next ) { 225 if ( e->key() == Qt::Key_Next ) {
226 if ( date.month() == 12 ) { 226 if ( date.month() == 12 ) {
227 KNotifyClient::beep(); 227 KNotifyClient::beep();
228 return; 228 return;
229 } 229 }
230 int day = date.day(); 230 int day = date.day();
231 if ( day > 27 ) 231 if ( day > 27 )
232 while ( !QDate::isValid( date.year(), date.month()+1, day ) ) 232 while ( !QDate::isValid( date.year(), date.month()+1, day ) )
233 day--; 233 day--;
234 setDate(QDate(date.year(), date.month()+1, day)); 234 setDate(QDate(date.year(), date.month()+1, day));
235 return; 235 return;
236 } 236 }
237 */ 237 */
238 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; 238 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
239 239
240 int temp=firstday+date.day()-dayoff; 240 int temp=firstday+date.day()-dayoff;
241 int pos = temp; 241 int pos = temp;
242 bool irgnore = true; 242 bool irgnore = true;
243 int add = 0;
243 if ( e->state() != Qt::ControlButton ) { 244 if ( e->state() != Qt::ControlButton ) {
244 if ( e->key() == Qt::Key_Up ) { 245 if ( e->key() == Qt::Key_Up ) {
245 pos -= 7; 246 add -= 7;
246 irgnore = false; 247 irgnore = false;
247 } 248 }
248 if ( e->key() == Qt::Key_Down ) { 249 if ( e->key() == Qt::Key_Down ) {
249 pos += 7; 250 add += 7;
250 irgnore = false; 251 irgnore = false;
251 } 252 }
252 if ( e->key() == Qt::Key_Left ) { 253 if ( e->key() == Qt::Key_Left ) {
253 pos--; 254 --add;
254 irgnore = false; 255 irgnore = false;
255 } 256 }
256 if ( e->key() == Qt::Key_Right ) { 257 if ( e->key() == Qt::Key_Right ) {
257 pos++; 258 ++add;
258 irgnore = false; 259 irgnore = false;
259 } 260 }
260 } 261 }
261 if ( irgnore ) 262 if ( irgnore ) {
262 e->ignore(); 263 e->ignore();
263
264 if(pos+dayoff<=firstday)
265 { // this day is in the previous month
266 KNotifyClient::beep();
267 return;
268 }
269 if(firstday+numdays<pos+dayoff)
270 { // this date is in the next month
271 KNotifyClient::beep(i18n( "Month not long enough" ));
272 return;
273 }
274
275 if ( pos == temp )
276 return; 264 return;
265 }
277 266
278 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); 267 pos += add;
268 setDate(date.addDays( add ));
279 updateCell(temp/7+1, temp%7); // Update the previously selected cell 269 updateCell(temp/7+1, temp%7); // Update the previously selected cell
280 updateCell(pos/7+1, pos%7); // Update the selected cell 270 updateCell(pos/7+1, pos%7); // Update the selected cell
281 assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); 271
282
283
284} 272}
285 273
286void 274void
287KDateTable::viewportResizeEvent(QResizeEvent * e) 275KDateTable::viewportResizeEvent(QResizeEvent * e)
288{ 276{
289 QGridView::viewportResizeEvent(e); 277 QGridView::viewportResizeEvent(e);
290 278
291 setCellWidth(viewport()->width()/7); 279 setCellWidth(viewport()->width()/7);
292 setCellHeight(viewport()->height()/7); 280 setCellHeight(viewport()->height()/7);
293} 281}
294 282
295void 283void
296KDateTable::setFontSize(int size) 284KDateTable::setFontSize(int size)
297{ 285{
298 int count; 286 int count;
299 QRect rect; 287 QRect rect;
300 // ----- store rectangles: 288 // ----- store rectangles:
301 fontsize=size; 289 fontsize=size;
302 QFont _font = font(); 290 QFont _font = font();
303 _font.setPointSize(fontsize); 291 _font.setPointSize(fontsize);
304 setFont( _font ); 292 setFont( _font );
305 _font.setBold( true ); 293 _font.setBold( true );
306 QFontMetrics metrics(_font); 294 QFontMetrics metrics(_font);
307 295
308 // ----- find largest day name: 296 // ----- find largest day name:
309 maxCell.setWidth(0); 297 maxCell.setWidth(0);
310 maxCell.setHeight(0); 298 maxCell.setHeight(0);
311 for(count=0; count<7; ++count) 299 for(count=0; count<7; ++count)
312 { 300 {
313 rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true)); 301 rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true));
314 maxCell.setWidth(QMAX(maxCell.width(), rect.width())); 302 maxCell.setWidth(QMAX(maxCell.width(), rect.width()));
315 maxCell.setHeight(QMAX(maxCell.height(), rect.height())); 303 maxCell.setHeight(QMAX(maxCell.height(), rect.height()));
316 } 304 }
317 // ----- compare with a real wide number and add some space: 305 // ----- compare with a real wide number and add some space:
318 rect=metrics.boundingRect(QString::fromLatin1("88")); 306 rect=metrics.boundingRect(QString::fromLatin1("88"));
319 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width())); 307 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width()));
320#ifdef DESKTOP_VERSION 308#ifdef DESKTOP_VERSION
321 maxCell.setHeight(QMAX(maxCell.height()+8, rect.height())); 309 maxCell.setHeight(QMAX(maxCell.height()+8, rect.height()));
322#else 310#else
323 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height())); 311 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height()));
324#endif 312#endif
325 if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) { 313 if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) {
326 maxCell.setHeight(maxCell.width() * 1000 / 1900 ); 314 maxCell.setHeight(maxCell.width() * 1000 / 1900 );
327 //qDebug("setmax "); 315 //qDebug("setmax ");
328 } 316 }
329} 317}
330 318
331void 319void
332KDateTable::contentsMousePressEvent(QMouseEvent *e) 320KDateTable::contentsMousePressEvent(QMouseEvent *e)
333{ 321{
334 if(e->type()!=QEvent::MouseButtonPress) 322 if(e->type()!=QEvent::MouseButtonPress)
335 { // the KDatePicker only reacts on mouse press events: 323 { // the KDatePicker only reacts on mouse press events:
336 return; 324 return;
337 } 325 }
338 if(!isEnabled()) 326 if(!isEnabled())
339 { 327 {
340 KNotifyClient::beep(); 328 KNotifyClient::beep();
341 return; 329 return;
342 } 330 }
343 331
344 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; 332 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
345 // ----- 333 // -----
346 int row, col, pos, temp; 334 int row, col, pos, temp;
347 QPoint mouseCoord; 335 QPoint mouseCoord;
348 // ----- 336 // -----
349 mouseCoord = e->pos(); 337 mouseCoord = e->pos();
350 row=rowAt(mouseCoord.y()); 338 row=rowAt(mouseCoord.y());
351 col=columnAt(mouseCoord.x()); 339 col=columnAt(mouseCoord.x());
352 if(row<0 || col<0) 340 if(row<0 || col<0)
353 { // the user clicked on the frame of the table 341 { // the user clicked on the frame of the table
354 return; 342 return;
355 } 343 }
356 pos=7*(row-1)+col+1; 344 pos=7*(row-1)+col+1;
357#if 0 345#if 0
358 if(pos+dayoff<=firstday) 346 if(pos+dayoff<=firstday)
359 { // this day is in the previous month 347 { // this day is in the previous month
360 KNotifyClient::beep(); 348 KNotifyClient::beep();
361 return; 349 return;
362 } 350 }
363 if(firstday+numdays<pos+dayoff) 351 if(firstday+numdays<pos+dayoff)
364 { // this date is in the next month 352 { // this date is in the next month
365 KNotifyClient::beep(); 353 KNotifyClient::beep();
366 return; 354 return;
367 } 355 }
368#endif 356#endif
369 temp=firstday+date.day()-dayoff-1; 357 temp=firstday+date.day()-dayoff-1;
370 QDate da = QDate(date.year(), date.month(),1); 358 QDate da = QDate(date.year(), date.month(),1);
371 setDate(da.addDays( pos-firstday+dayoff-1)); 359 setDate(da.addDays( pos-firstday+dayoff-1));
372 updateCell(temp/7+1, temp%7); // Update the previously selected cell 360 updateCell(temp/7+1, temp%7); // Update the previously selected cell
373 updateCell(row, col); // Update the selected cell 361 updateCell(row, col); // Update the selected cell
374 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); 362 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
375 emit(tableClicked()); 363 emit(tableClicked());
376} 364}
377 365
378bool 366bool
379KDateTable::setDate(const QDate& date_) 367KDateTable::setDate(const QDate& date_)
380{ 368{
381 bool changed=false; 369 bool changed=false;
382 QDate temp; 370 QDate temp;
383 mMarkCurrent = false; 371 mMarkCurrent = false;
384 // ----- 372 // -----
385 if(!date_.isValid()) 373 if(!date_.isValid())
386 { 374 {
387 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl; 375 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
388 return false; 376 return false;
389 } 377 }
390 if(date!=date_) 378 if(date!=date_)
391 { 379 {
392 date=date_; 380 date=date_;
393 changed=true; 381 changed=true;
394 } 382 }
395 mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() ); 383 mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() );
396 temp.setYMD(date.year(), date.month(), 1); 384 temp.setYMD(date.year(), date.month(), 1);
397 firstday=temp.dayOfWeek(); 385 firstday=temp.dayOfWeek();
398 if(firstday==1) firstday=8; 386 if(firstday==1) firstday=8;
399 numdays=date.daysInMonth(); 387 numdays=date.daysInMonth();
400 if(date.month()==1) 388 if(date.month()==1)
401 { // set to december of previous year 389 { // set to december of previous year
402 temp.setYMD(date.year()-1, 12, 1); 390 temp.setYMD(date.year()-1, 12, 1);
403 } else { // set to previous month 391 } else { // set to previous month
404 temp.setYMD(date.year(), date.month()-1, 1); 392 temp.setYMD(date.year(), date.month()-1, 1);
405 } 393 }
406 numDaysPrevMonth=temp.daysInMonth(); 394 numDaysPrevMonth=temp.daysInMonth();
407 if(changed) 395 if(changed)
408 { 396 {
409 repaintContents(false); 397 repaintContents(false);
410 } 398 }
411 emit(dateChanged(date)); 399 emit(dateChanged(date));
412 return true; 400 return true;
413} 401}
414 402
415const QDate& 403const QDate&
416KDateTable::getDate() const 404KDateTable::getDate() const
417{ 405{
418 return date; 406 return date;
419} 407}
420 408
421void KDateTable::focusInEvent( QFocusEvent *e ) 409void KDateTable::focusInEvent( QFocusEvent *e )
422{ 410{
423 repaintContents(false); 411 repaintContents(false);
424 QGridView::focusInEvent( e ); 412 QGridView::focusInEvent( e );
425} 413}
426 414
427void KDateTable::focusOutEvent( QFocusEvent *e ) 415void KDateTable::focusOutEvent( QFocusEvent *e )
428{ 416{
429 repaintContents(false); 417 repaintContents(false);
430 QGridView::focusOutEvent( e ); 418 QGridView::focusOutEvent( e );
431} 419}
432 420
433QSize 421QSize
434KDateTable::sizeHint() const 422KDateTable::sizeHint() const
435{ 423{
436 if(maxCell.height()>0 && maxCell.width()>0) 424 if(maxCell.height()>0 && maxCell.width()>0)
437 { 425 {
438 return QSize((maxCell.width()+2)*numCols()+2*frameWidth(), 426 return QSize((maxCell.width()+2)*numCols()+2*frameWidth(),
439 (maxCell.height()+4)*numRows()+2*frameWidth()); 427 (maxCell.height()+4)*numRows()+2*frameWidth());
440 } else { 428 } else {
441 return QSize(-1, -1); 429 return QSize(-1, -1);
442 } 430 }
443} 431}
444 432
445KDateInternalMonthPicker::KDateInternalMonthPicker 433KDateInternalMonthPicker::KDateInternalMonthPicker
446(QWidget* parent, const char* name) 434(QWidget* parent, const char* name)
447 : QGridView(parent, name), 435 : QGridView(parent, name),
448 result(0) // invalid 436 result(0) // invalid
449{ 437{
450 QRect rect; 438 QRect rect;
451 QFont font; 439 QFont font;
452 // ----- 440 // -----
453 activeCol = -1; 441 activeCol = -1;
454 activeRow = -1; 442 activeRow = -1;
455 font=KGlobalSettings::generalFont(); 443 font=KGlobalSettings::generalFont();
456 int fontsize = 10; 444 int fontsize = 10;
457 int add = 2; 445 int add = 2;
458 if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) 446 if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 )
459 add += 8; 447 add += 8;
460 if ( QApplication::desktop()->width() > 640 ) 448 if ( QApplication::desktop()->width() > 640 )
461 add += 6; 449 add += 6;
462 font.setPointSize(fontsize+add); 450 font.setPointSize(fontsize+add);
463 setFont(font); 451 setFont(font);
464 setHScrollBarMode(AlwaysOff); 452 setHScrollBarMode(AlwaysOff);
465 setVScrollBarMode(AlwaysOff); 453 setVScrollBarMode(AlwaysOff);
466 setFrameStyle(QFrame::NoFrame); 454 setFrameStyle(QFrame::NoFrame);
467 setNumRows(4); 455 setNumRows(4);
468 setNumCols(3); 456 setNumCols(3);
469 // enable to find drawing failures: 457 // enable to find drawing failures:
470 // setTableFlags(Tbl_clipCellPainting); 458 // setTableFlags(Tbl_clipCellPainting);
471#if 0 459#if 0
472 viewport()->setEraseColor(lightGray); // for consistency with the datepicker 460 viewport()->setEraseColor(lightGray); // for consistency with the datepicker
473#endif 461#endif
474 // ----- find the preferred size 462 // ----- find the preferred size
475 // (this is slow, possibly, but unfortunatly it is needed here): 463 // (this is slow, possibly, but unfortunatly it is needed here):
476 QFontMetrics metrics(font); 464 QFontMetrics metrics(font);
477 for(int i=1; i <= 12; ++i) 465 for(int i=1; i <= 12; ++i)
478 { 466 {
479 rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); 467 rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false));
480 if(max.width()<rect.width()) max.setWidth(rect.width()); 468 if(max.width()<rect.width()) max.setWidth(rect.width());
481 if(max.height()<rect.height()) max.setHeight(rect.height()); 469 if(max.height()<rect.height()) max.setHeight(rect.height());
482 } 470 }
483 471
484} 472}
485 473
486QSize 474QSize
487KDateInternalMonthPicker::sizeHint() const 475KDateInternalMonthPicker::sizeHint() const
488{ 476{
489 return QSize((max.width()+6)*numCols()+2*frameWidth(), 477 return QSize((max.width()+6)*numCols()+2*frameWidth(),
490 (max.height()+6)*numRows()+2*frameWidth()); 478 (max.height()+6)*numRows()+2*frameWidth());
491} 479}
492 480
493int 481int
494KDateInternalMonthPicker::getResult() const 482KDateInternalMonthPicker::getResult() const
495{ 483{
496 return result; 484 return result;
497} 485}
498 486
499void 487void
500KDateInternalMonthPicker::setupPainter(QPainter *p) 488KDateInternalMonthPicker::setupPainter(QPainter *p)
501{ 489{
502 p->setPen(black); 490 p->setPen(black);
503} 491}
504 492
505void 493void
506KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*) 494KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*)
507{ 495{
508 setCellWidth(width()/3); 496 setCellWidth(width()/3);
509 setCellHeight(height()/4); 497 setCellHeight(height()/4);
510} 498}
511 499
512void 500void
513KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col) 501KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col)
514{ 502{
515 int index; 503 int index;
516 QString text; 504 QString text;
517 // ----- find the number of the cell: 505 // ----- find the number of the cell:
518 index=3*row+col+1; 506 index=3*row+col+1;
519 text=KGlobal::locale()->monthName(index, false); 507 text=KGlobal::locale()->monthName(index, false);
520 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); 508 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
521 if ( activeCol == col && activeRow == row ) 509 if ( activeCol == col && activeRow == row )
522 painter->drawRect( 0, 0, cellWidth(), cellHeight() ); 510 painter->drawRect( 0, 0, cellWidth(), cellHeight() );
523} 511}
524 512
525void 513void
526KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e) 514KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e)
527{ 515{
528 if(!isEnabled() || e->button() != LeftButton) 516 if(!isEnabled() || e->button() != LeftButton)
529 { 517 {
530 KNotifyClient::beep(); 518 KNotifyClient::beep();
531 return; 519 return;
532 } 520 }
533 // ----- 521 // -----
534 int row, col; 522 int row, col;
535 QPoint mouseCoord; 523 QPoint mouseCoord;
536 // ----- 524 // -----
537 mouseCoord = e->pos(); 525 mouseCoord = e->pos();
538 row=rowAt(mouseCoord.y()); 526 row=rowAt(mouseCoord.y());
539 col=columnAt(mouseCoord.x()); 527 col=columnAt(mouseCoord.x());
540 528
541 if(row<0 || col<0) 529 if(row<0 || col<0)
542 { // the user clicked on the frame of the table 530 { // the user clicked on the frame of the table
543 activeCol = -1; 531 activeCol = -1;
544 activeRow = -1; 532 activeRow = -1;
545 } else { 533 } else {
546 activeCol = col; 534 activeCol = col;
547 activeRow = row; 535 activeRow = row;
548 updateCell( row, col /*, false */ ); 536 updateCell( row, col /*, false */ );
549 } 537 }
550} 538}
551 539
552void 540void
553KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e) 541KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e)
554{ 542{
555 if (e->state() & LeftButton) 543 if (e->state() & LeftButton)
556 { 544 {
557 int row, col; 545 int row, col;
558 QPoint mouseCoord; 546 QPoint mouseCoord;
559 // ----- 547 // -----
560 mouseCoord = e->pos(); 548 mouseCoord = e->pos();
561 row=rowAt(mouseCoord.y()); 549 row=rowAt(mouseCoord.y());
562 col=columnAt(mouseCoord.x()); 550 col=columnAt(mouseCoord.x());
563 int tmpRow = -1, tmpCol = -1; 551 int tmpRow = -1, tmpCol = -1;
564 if(row<0 || col<0) 552 if(row<0 || col<0)
565 { // the user clicked on the frame of the table 553 { // the user clicked on the frame of the table
566 if ( activeCol > -1 ) 554 if ( activeCol > -1 )
567 { 555 {
568 tmpRow = activeRow; 556 tmpRow = activeRow;
569 tmpCol = activeCol; 557 tmpCol = activeCol;
570 } 558 }
571 activeCol = -1; 559 activeCol = -1;
572 activeRow = -1; 560 activeRow = -1;
573 } else { 561 } else {
574 bool differentCell = (activeRow != row || activeCol != col); 562 bool differentCell = (activeRow != row || activeCol != col);
575 if ( activeCol > -1 && differentCell) 563 if ( activeCol > -1 && differentCell)
576 { 564 {
577 tmpRow = activeRow; 565 tmpRow = activeRow;
578 tmpCol = activeCol; 566 tmpCol = activeCol;
579 } 567 }
580 if ( differentCell) 568 if ( differentCell)
581 { 569 {
582 activeRow = row; 570 activeRow = row;
583 activeCol = col; 571 activeCol = col;
584 updateCell( row, col /*, false */ ); // mark the new active cell 572 updateCell( row, col /*, false */ ); // mark the new active cell
585 } 573 }
586 } 574 }
587 if ( tmpRow > -1 ) // repaint the former active cell 575 if ( tmpRow > -1 ) // repaint the former active cell
588 updateCell( tmpRow, tmpCol /*, true */ ); 576 updateCell( tmpRow, tmpCol /*, true */ );
589 } 577 }
590} 578}
591 579
592void 580void
593KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e) 581KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e)
594{ 582{
595 if(!isEnabled()) 583 if(!isEnabled())
596 { 584 {
597 return; 585 return;
598 } 586 }
599 // ----- 587 // -----
600 int row, col, pos; 588 int row, col, pos;
601 QPoint mouseCoord; 589 QPoint mouseCoord;
602 // ----- 590 // -----
603 mouseCoord = e->pos(); 591 mouseCoord = e->pos();
604 row=rowAt(mouseCoord.y()); 592 row=rowAt(mouseCoord.y());
605 col=columnAt(mouseCoord.x()); 593 col=columnAt(mouseCoord.x());
606 if(row<0 || col<0) 594 if(row<0 || col<0)
607 { // the user clicked on the frame of the table 595 { // the user clicked on the frame of the table
608 emit(closeMe(0)); 596 emit(closeMe(0));
609 } 597 }
610 pos=3*row+col+1; 598 pos=3*row+col+1;
611 result=pos; 599 result=pos;
612 emit(closeMe(1)); 600 emit(closeMe(1));
613} 601}
614 602
615 603
616 604
617KDateInternalYearSelector::KDateInternalYearSelector 605KDateInternalYearSelector::KDateInternalYearSelector
618(int fontsize, QWidget* parent, const char* name) 606(int fontsize, QWidget* parent, const char* name)
619 : QLineEdit(parent, name), 607 : QLineEdit(parent, name),
620 val(new QIntValidator(this)), 608 val(new QIntValidator(this)),
621 result(0) 609 result(0)
622{ 610{
623 QFont font; 611 QFont font;
624 // ----- 612 // -----
625 font=KGlobalSettings::generalFont(); 613 font=KGlobalSettings::generalFont();
626 font.setPointSize(fontsize); 614 font.setPointSize(fontsize);
627 setFont(font); 615 setFont(font);
628#if 0 616#if 0
629 setFrameStyle(QFrame::NoFrame); 617 setFrameStyle(QFrame::NoFrame);
630#endif 618#endif
631 // we have to respect the limits of QDate here, I fear: 619 // we have to respect the limits of QDate here, I fear:
632 val->setRange(0, 8000); 620 val->setRange(0, 8000);
633 setValidator(val); 621 setValidator(val);
634 connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot())); 622 connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot()));
635} 623}
636 624
637void 625void
638KDateInternalYearSelector::yearEnteredSlot() 626KDateInternalYearSelector::yearEnteredSlot()
639{ 627{
640 bool ok; 628 bool ok;
641 int year; 629 int year;
642 QDate date; 630 QDate date;
643 // ----- check if this is a valid year: 631 // ----- check if this is a valid year:
644 year=text().toInt(&ok); 632 year=text().toInt(&ok);
645 if(!ok) 633 if(!ok)
646 { 634 {
647 KNotifyClient::beep(); 635 KNotifyClient::beep();
648 return; 636 return;
649 } 637 }
650 date.setYMD(year, 1, 1); 638 date.setYMD(year, 1, 1);
651 if(!date.isValid()) 639 if(!date.isValid())
652 { 640 {
653 KNotifyClient::beep(); 641 KNotifyClient::beep();
654 return; 642 return;
655 } 643 }
656 result=year; 644 result=year;
657 emit(closeMe(1)); 645 emit(closeMe(1));
658} 646}
659 647
660int 648int
661KDateInternalYearSelector::getYear() 649KDateInternalYearSelector::getYear()
662{ 650{
663 return result; 651 return result;
664} 652}
665 653
666void 654void
667KDateInternalYearSelector::setYear(int year) 655KDateInternalYearSelector::setYear(int year)