summaryrefslogtreecommitdiffabout
path: root/microkde/kdatetbl.cpp
authorzautrix <zautrix>2005-02-08 14:12:31 (UTC)
committer zautrix <zautrix>2005-02-08 14:12:31 (UTC)
commit41111b332c2a5f1b2ec152df309b9199f5e9c921 (patch) (unidiff)
tree3a2e5c5a25cdb52f542b2fe84a03f94599be2fe3 /microkde/kdatetbl.cpp
parent9927a063f34bb826a4b5f7f7029308c9c66acbce (diff)
downloadkdepimpi-41111b332c2a5f1b2ec152df309b9199f5e9c921.zip
kdepimpi-41111b332c2a5f1b2ec152df309b9199f5e9c921.tar.gz
kdepimpi-41111b332c2a5f1b2ec152df309b9199f5e9c921.tar.bz2
fixes
Diffstat (limited to 'microkde/kdatetbl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdatetbl.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index fce0e5a..e827412 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -1,915 +1,929 @@
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 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=KGlobalSettings::generalFont(); 113 QFont font=KGlobalSettings::generalFont();
114 // ----- 114 // -----
115 font.setPointSize(fontsize); 115 font.setPointSize(fontsize);
116 if(row==0) 116 if(row==0)
117 { // we are drawing the headline 117 { // we are drawing the headline
118 font.setBold(true); 118 font.setBold(true);
119 painter->setFont(font); 119 painter->setFont(font);
120 bool normalday = true; 120 bool normalday = true;
121 QString daystr; 121 QString daystr;
122 if (KGlobal::locale()->weekStartsMonday()) 122 if (KGlobal::locale()->weekStartsMonday())
123 { 123 {
124 daystr = KGlobal::locale()->weekDayName(col+1, true); 124 daystr = KGlobal::locale()->weekDayName(col+1, true);
125 if (col == 5 || col == 6) 125 if (col == 5 || col == 6)
126 normalday = false; 126 normalday = false;
127 } else { 127 } else {
128 daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true); 128 daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true);
129 if (col == 0 || col == 6) 129 if (col == 0 || col == 6)
130 normalday = false; 130 normalday = false;
131 } 131 }
132 if (!normalday) 132 if (!normalday)
133 { 133 {
134 painter->setPen(QColor(220,245,255)); 134 painter->setPen(QColor(220,245,255));
135 painter->setBrush(brushLightblue); 135 painter->setBrush(brushLightblue);
136 painter->drawRect(0, 0, w, h); 136 painter->drawRect(0, 0, w, h);
137 painter->setPen(blue); 137 painter->setPen(blue);
138 } else { 138 } else {
139 painter->setPen(blue); 139 painter->setPen(blue);
140 painter->setBrush(brushBlue); 140 painter->setBrush(brushBlue);
141 painter->drawRect(0, 0, w, h); 141 painter->drawRect(0, 0, w, h);
142 painter->setPen(white); 142 painter->setPen(white);
143 } 143 }
144 painter->drawText(0, 0, w, h-1, AlignCenter, 144 painter->drawText(0, 0, w, h-1, AlignCenter,
145 daystr, -1, &rect); 145 daystr, -1, &rect);
146 painter->setPen(black); 146 painter->setPen(black);
147 painter->moveTo(0, h-1); 147 painter->moveTo(0, h-1);
148 painter->lineTo(w-1, h-1); 148 painter->lineTo(w-1, h-1);
149 // ----- draw the weekday: 149 // ----- draw the weekday:
150 } else { 150 } else {
151 painter->setFont(font); 151 painter->setFont(font);
152 pos=7*(row-1)+col; 152 pos=7*(row-1)+col;
153 if (KGlobal::locale()->weekStartsMonday()) 153 if (KGlobal::locale()->weekStartsMonday())
154 pos++; 154 pos++;
155 if(pos<firstday || (firstday+numdays<=pos)) 155 if(pos<firstday || (firstday+numdays<=pos))
156 { // we are either 156 { // we are either
157 // ° painting a day of the previous month or 157 // ° painting a day of the previous month or
158 // ° painting a day of the following month 158 // ° painting a day of the following month
159 if(pos<firstday) 159 if(pos<firstday)
160 { // previous month 160 { // previous month
161 text.setNum(numDaysPrevMonth+pos-firstday+1); 161 text.setNum(numDaysPrevMonth+pos-firstday+1);
162 } else { // following month 162 } else { // following month
163 text.setNum(pos-firstday-numdays+1); 163 text.setNum(pos-firstday-numdays+1);
164 } 164 }
165 painter->setPen(gray); 165 painter->setPen(gray);
166 } else { // paint a day of the current month 166 } else { // paint a day of the current month
167 text.setNum(pos-firstday+1); 167 text.setNum(pos-firstday+1);
168 painter->setPen(black); 168 painter->setPen(black);
169 } 169 }
170 170
171 pen=painter->pen(); 171 pen=painter->pen();
172 if(firstday+date.day()-1==pos) 172 if(firstday+date.day()-1==pos)
173 { 173 {
174 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) 174 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
175 painter->setPen(green); 175 painter->setPen(green);
176 else 176 else
177 painter->setPen(red); 177 painter->setPen(red);
178 if(hasFocus()) 178 if(hasFocus())
179 { 179 {
180 painter->setBrush(darkRed); 180 painter->setBrush(darkRed);
181 pen=white; 181 pen=white;
182 } else { 182 } else {
183 painter->setBrush(darkGray); 183 painter->setBrush(darkGray);
184 pen=white; 184 pen=white;
185 } 185 }
186 } else { 186 } else {
187 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) 187 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
188 { 188 {
189 painter->setPen(green); 189 painter->setPen(green);
190 painter->setBrush(darkGreen); 190 painter->setBrush(darkGreen);
191 pen=white; 191 pen=white;
192 } else { 192 } else {
193 painter->setBrush(QColor(220,245,255)); 193 painter->setBrush(QColor(220,245,255));
194 painter->setPen(QColor(220,245,255)); 194 painter->setPen(QColor(220,245,255));
195 } 195 }
196 } 196 }
197 painter->drawRect(0, 0, w, h); 197 painter->drawRect(0, 0, w, h);
198 painter->setPen(pen); 198 painter->setPen(pen);
199 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect); 199 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
200 } 200 }
201 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); 201 /*
202 if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height()); 202 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
203 if(rect.height()>maxCell.height()) {
204 maxCell.setHeight(rect.height());
205 }
206 */
203} 207}
204 208
205void 209void
206KDateTable::keyPressEvent( QKeyEvent *e ) 210KDateTable::keyPressEvent( QKeyEvent *e )
207{ 211{
208 /* 212 /*
209 // not working properly 213 // not working properly
210 if ( e->key() == Qt::Key_Prior ) { 214 if ( e->key() == Qt::Key_Prior ) {
211 if ( date.month() == 1 ) { 215 if ( date.month() == 1 ) {
212 KNotifyClient::beep(); 216 KNotifyClient::beep();
213 return; 217 return;
214 } 218 }
215 int day = date.day(); 219 int day = date.day();
216 if ( day > 27 ) 220 if ( day > 27 )
217 while ( !QDate::isValid( date.year(), date.month()-1, day ) ) 221 while ( !QDate::isValid( date.year(), date.month()-1, day ) )
218 day--; 222 day--;
219 setDate(QDate(date.year(), date.month()-1, day)); 223 setDate(QDate(date.year(), date.month()-1, day));
220 return; 224 return;
221 } 225 }
222 if ( e->key() == Qt::Key_Next ) { 226 if ( e->key() == Qt::Key_Next ) {
223 if ( date.month() == 12 ) { 227 if ( date.month() == 12 ) {
224 KNotifyClient::beep(); 228 KNotifyClient::beep();
225 return; 229 return;
226 } 230 }
227 int day = date.day(); 231 int day = date.day();
228 if ( day > 27 ) 232 if ( day > 27 )
229 while ( !QDate::isValid( date.year(), date.month()+1, day ) ) 233 while ( !QDate::isValid( date.year(), date.month()+1, day ) )
230 day--; 234 day--;
231 setDate(QDate(date.year(), date.month()+1, day)); 235 setDate(QDate(date.year(), date.month()+1, day));
232 return; 236 return;
233 } 237 }
234 */ 238 */
235 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; 239 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
236 240
237 int temp=firstday+date.day()-dayoff; 241 int temp=firstday+date.day()-dayoff;
238 int pos = temp; 242 int pos = temp;
239 bool irgnore = true; 243 bool irgnore = true;
240 if ( e->state() != Qt::ControlButton ) { 244 if ( e->state() != Qt::ControlButton ) {
241 if ( e->key() == Qt::Key_Up ) { 245 if ( e->key() == Qt::Key_Up ) {
242 pos -= 7; 246 pos -= 7;
243 irgnore = false; 247 irgnore = false;
244 } 248 }
245 if ( e->key() == Qt::Key_Down ) { 249 if ( e->key() == Qt::Key_Down ) {
246 pos += 7; 250 pos += 7;
247 irgnore = false; 251 irgnore = false;
248 } 252 }
249 if ( e->key() == Qt::Key_Left ) { 253 if ( e->key() == Qt::Key_Left ) {
250 pos--; 254 pos--;
251 irgnore = false; 255 irgnore = false;
252 } 256 }
253 if ( e->key() == Qt::Key_Right ) { 257 if ( e->key() == Qt::Key_Right ) {
254 pos++; 258 pos++;
255 irgnore = false; 259 irgnore = false;
256 } 260 }
257 } 261 }
258 if ( irgnore ) 262 if ( irgnore )
259 e->ignore(); 263 e->ignore();
260 264
261 if(pos+dayoff<=firstday) 265 if(pos+dayoff<=firstday)
262 { // this day is in the previous month 266 { // this day is in the previous month
263 KNotifyClient::beep(); 267 KNotifyClient::beep();
264 return; 268 return;
265 } 269 }
266 if(firstday+numdays<pos+dayoff) 270 if(firstday+numdays<pos+dayoff)
267 { // this date is in the next month 271 { // this date is in the next month
268 KNotifyClient::beep(i18n( "Month not long enough" )); 272 KNotifyClient::beep(i18n( "Month not long enough" ));
269 return; 273 return;
270 } 274 }
271 275
272 if ( pos == temp ) 276 if ( pos == temp )
273 return; 277 return;
274 278
275 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); 279 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff));
276 updateCell(temp/7+1, temp%7); // Update the previously selected cell 280 updateCell(temp/7+1, temp%7); // Update the previously selected cell
277 updateCell(pos/7+1, pos%7); // Update the selected cell 281 updateCell(pos/7+1, pos%7); // Update the selected cell
278 assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); 282 assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
279 283
280 284
281} 285}
282 286
283void 287void
284KDateTable::viewportResizeEvent(QResizeEvent * e) 288KDateTable::viewportResizeEvent(QResizeEvent * e)
285{ 289{
286 QGridView::viewportResizeEvent(e); 290 QGridView::viewportResizeEvent(e);
287 291
288 setCellWidth(viewport()->width()/7); 292 setCellWidth(viewport()->width()/7);
289 setCellHeight(viewport()->height()/7); 293 setCellHeight(viewport()->height()/7);
290} 294}
291 295
292void 296void
293KDateTable::setFontSize(int size) 297KDateTable::setFontSize(int size)
294{ 298{
295 int count; 299 int count;
296 QRect rect; 300 QRect rect;
297 // ----- store rectangles: 301 // ----- store rectangles:
298 fontsize=size; 302 fontsize=size;
299 QFont font = KGlobalSettings::generalFont(); 303 QFont font = KGlobalSettings::generalFont();
300 font.setPointSize(fontsize); 304 font.setPointSize(fontsize);
301 font.setBold( true ); 305 font.setBold( true );
302 QFontMetrics metrics(font); 306 QFontMetrics metrics(font);
303 307
304 // ----- find largest day name: 308 // ----- find largest day name:
305 maxCell.setWidth(0); 309 maxCell.setWidth(0);
306 maxCell.setHeight(0); 310 maxCell.setHeight(0);
307 for(count=0; count<7; ++count) 311 for(count=0; count<7; ++count)
308 { 312 {
309 rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true)); 313 rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true));
310 maxCell.setWidth(QMAX(maxCell.width(), rect.width())); 314 maxCell.setWidth(QMAX(maxCell.width(), rect.width()));
311 maxCell.setHeight(QMAX(maxCell.height(), rect.height())); 315 maxCell.setHeight(QMAX(maxCell.height(), rect.height()));
312 } 316 }
313 // ----- compare with a real wide number and add some space: 317 // ----- compare with a real wide number and add some space:
314 rect=metrics.boundingRect(QString::fromLatin1("88")); 318 rect=metrics.boundingRect(QString::fromLatin1("88"));
315 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width())); 319 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width()));
320#ifdef DESKTOP_VERSION
321 maxCell.setHeight(QMAX(maxCell.height()+8, rect.height()));
322#else
316 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height())); 323 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height()));
317 if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) 324#endif
325 if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) {
318 maxCell.setHeight(maxCell.width() * 1000 / 1900 ); 326 maxCell.setHeight(maxCell.width() * 1000 / 1900 );
327 qDebug("setmax ");
328 }
319} 329}
320 330
321void 331void
322KDateTable::contentsMousePressEvent(QMouseEvent *e) 332KDateTable::contentsMousePressEvent(QMouseEvent *e)
323{ 333{
324 if(e->type()!=QEvent::MouseButtonPress) 334 if(e->type()!=QEvent::MouseButtonPress)
325 { // the KDatePicker only reacts on mouse press events: 335 { // the KDatePicker only reacts on mouse press events:
326 return; 336 return;
327 } 337 }
328 if(!isEnabled()) 338 if(!isEnabled())
329 { 339 {
330 KNotifyClient::beep(); 340 KNotifyClient::beep();
331 return; 341 return;
332 } 342 }
333 343
334 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; 344 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
335 // ----- 345 // -----
336 int row, col, pos, temp; 346 int row, col, pos, temp;
337 QPoint mouseCoord; 347 QPoint mouseCoord;
338 // ----- 348 // -----
339 mouseCoord = e->pos(); 349 mouseCoord = e->pos();
340 row=rowAt(mouseCoord.y()); 350 row=rowAt(mouseCoord.y());
341 col=columnAt(mouseCoord.x()); 351 col=columnAt(mouseCoord.x());
342 if(row<0 || col<0) 352 if(row<0 || col<0)
343 { // the user clicked on the frame of the table 353 { // the user clicked on the frame of the table
344 return; 354 return;
345 } 355 }
346 pos=7*(row-1)+col+1; 356 pos=7*(row-1)+col+1;
347#if 0 357#if 0
348 if(pos+dayoff<=firstday) 358 if(pos+dayoff<=firstday)
349 { // this day is in the previous month 359 { // this day is in the previous month
350 KNotifyClient::beep(); 360 KNotifyClient::beep();
351 return; 361 return;
352 } 362 }
353 if(firstday+numdays<pos+dayoff) 363 if(firstday+numdays<pos+dayoff)
354 { // this date is in the next month 364 { // this date is in the next month
355 KNotifyClient::beep(); 365 KNotifyClient::beep();
356 return; 366 return;
357 } 367 }
358#endif 368#endif
359 temp=firstday+date.day()-dayoff-1; 369 temp=firstday+date.day()-dayoff-1;
360 QDate da = QDate(date.year(), date.month(),1); 370 QDate da = QDate(date.year(), date.month(),1);
361 setDate(da.addDays( pos-firstday+dayoff-1)); 371 setDate(da.addDays( pos-firstday+dayoff-1));
362 updateCell(temp/7+1, temp%7); // Update the previously selected cell 372 updateCell(temp/7+1, temp%7); // Update the previously selected cell
363 updateCell(row, col); // Update the selected cell 373 updateCell(row, col); // Update the selected cell
364 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); 374 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
365 emit(tableClicked()); 375 emit(tableClicked());
366} 376}
367 377
368bool 378bool
369KDateTable::setDate(const QDate& date_) 379KDateTable::setDate(const QDate& date_)
370{ 380{
371 bool changed=false; 381 bool changed=false;
372 QDate temp; 382 QDate temp;
373 mMarkCurrent = false; 383 mMarkCurrent = false;
374 // ----- 384 // -----
375 if(!date_.isValid()) 385 if(!date_.isValid())
376 { 386 {
377 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl; 387 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
378 return false; 388 return false;
379 } 389 }
380 if(date!=date_) 390 if(date!=date_)
381 { 391 {
382 date=date_; 392 date=date_;
383 changed=true; 393 changed=true;
384 } 394 }
385 mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() ); 395 mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() );
386 temp.setYMD(date.year(), date.month(), 1); 396 temp.setYMD(date.year(), date.month(), 1);
387 firstday=temp.dayOfWeek(); 397 firstday=temp.dayOfWeek();
388 if(firstday==1) firstday=8; 398 if(firstday==1) firstday=8;
389 numdays=date.daysInMonth(); 399 numdays=date.daysInMonth();
390 if(date.month()==1) 400 if(date.month()==1)
391 { // set to december of previous year 401 { // set to december of previous year
392 temp.setYMD(date.year()-1, 12, 1); 402 temp.setYMD(date.year()-1, 12, 1);
393 } else { // set to previous month 403 } else { // set to previous month
394 temp.setYMD(date.year(), date.month()-1, 1); 404 temp.setYMD(date.year(), date.month()-1, 1);
395 } 405 }
396 numDaysPrevMonth=temp.daysInMonth(); 406 numDaysPrevMonth=temp.daysInMonth();
397 if(changed) 407 if(changed)
398 { 408 {
399 repaintContents(false); 409 repaintContents(false);
400 } 410 }
401 emit(dateChanged(date)); 411 emit(dateChanged(date));
402 return true; 412 return true;
403} 413}
404 414
405const QDate& 415const QDate&
406KDateTable::getDate() const 416KDateTable::getDate() const
407{ 417{
408 return date; 418 return date;
409} 419}
410 420
411void KDateTable::focusInEvent( QFocusEvent *e ) 421void KDateTable::focusInEvent( QFocusEvent *e )
412{ 422{
413 repaintContents(false); 423 repaintContents(false);
414 QGridView::focusInEvent( e ); 424 QGridView::focusInEvent( e );
415} 425}
416 426
417void KDateTable::focusOutEvent( QFocusEvent *e ) 427void KDateTable::focusOutEvent( QFocusEvent *e )
418{ 428{
419 repaintContents(false); 429 repaintContents(false);
420 QGridView::focusOutEvent( e ); 430 QGridView::focusOutEvent( e );
421} 431}
422 432
423QSize 433QSize
424KDateTable::sizeHint() const 434KDateTable::sizeHint() const
425{ 435{
426 if(maxCell.height()>0 && maxCell.width()>0) 436 if(maxCell.height()>0 && maxCell.width()>0)
427 { 437 {
428 return QSize((maxCell.width()+2)*numCols()+2*frameWidth(), 438 return QSize((maxCell.width()+2)*numCols()+2*frameWidth(),
429 (maxCell.height()+4)*numRows()+2*frameWidth()); 439 (maxCell.height()+4)*numRows()+2*frameWidth());
430 } else { 440 } else {
431 return QSize(-1, -1); 441 return QSize(-1, -1);
432 } 442 }
433} 443}
434 444
435KDateInternalMonthPicker::KDateInternalMonthPicker 445KDateInternalMonthPicker::KDateInternalMonthPicker
436(int fontsize, QWidget* parent, const char* name) 446(int fontsize, QWidget* parent, const char* name)
437 : QGridView(parent, name), 447 : QGridView(parent, name),
438 result(0) // invalid 448 result(0) // invalid
439{ 449{
440 QRect rect; 450 QRect rect;
441 QFont font; 451 QFont font;
442 // ----- 452 // -----
443 activeCol = -1; 453 activeCol = -1;
444 activeRow = -1; 454 activeRow = -1;
445 font=KGlobalSettings::generalFont(); 455 font=KGlobalSettings::generalFont();
446 font.setPointSize(fontsize); 456 //font.setPointSize(fontsize);
447 setFont(font); 457 setFont(font);
448 setHScrollBarMode(AlwaysOff); 458 setHScrollBarMode(AlwaysOff);
449 setVScrollBarMode(AlwaysOff); 459 setVScrollBarMode(AlwaysOff);
450 setFrameStyle(QFrame::NoFrame); 460 setFrameStyle(QFrame::NoFrame);
451 setNumRows(4); 461 setNumRows(4);
452 setNumCols(3); 462 setNumCols(3);
453 // enable to find drawing failures: 463 // enable to find drawing failures:
454 // setTableFlags(Tbl_clipCellPainting); 464 // setTableFlags(Tbl_clipCellPainting);
455#if 0 465#if 0
456 viewport()->setEraseColor(lightGray); // for consistency with the datepicker 466 viewport()->setEraseColor(lightGray); // for consistency with the datepicker
457#endif 467#endif
458 // ----- find the preferred size 468 // ----- find the preferred size
459 // (this is slow, possibly, but unfortunatly it is needed here): 469 // (this is slow, possibly, but unfortunatly it is needed here):
460 QFontMetrics metrics(font); 470 QFontMetrics metrics(font);
461 for(int i=1; i <= 12; ++i) 471 for(int i=1; i <= 12; ++i)
462 { 472 {
463 rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); 473 rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false));
464 if(max.width()<rect.width()) max.setWidth(rect.width()); 474 if(max.width()<rect.width()) max.setWidth(rect.width());
465 if(max.height()<rect.height()) max.setHeight(rect.height()); 475 if(max.height()<rect.height()) max.setHeight(rect.height());
466 } 476 }
467 477
468} 478}
469 479
470QSize 480QSize
471KDateInternalMonthPicker::sizeHint() const 481KDateInternalMonthPicker::sizeHint() const
472{ 482{
473 return QSize((max.width()+6)*numCols()+2*frameWidth(), 483 return QSize((max.width()+6)*numCols()+2*frameWidth(),
474 (max.height()+6)*numRows()+2*frameWidth()); 484 (max.height()+6)*numRows()+2*frameWidth());
475} 485}
476 486
477int 487int
478KDateInternalMonthPicker::getResult() const 488KDateInternalMonthPicker::getResult() const
479{ 489{
480 return result; 490 return result;
481} 491}
482 492
483void 493void
484KDateInternalMonthPicker::setupPainter(QPainter *p) 494KDateInternalMonthPicker::setupPainter(QPainter *p)
485{ 495{
486 p->setPen(black); 496 p->setPen(black);
487} 497}
488 498
489void 499void
490KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*) 500KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*)
491{ 501{
492 setCellWidth(width()/3); 502 setCellWidth(width()/3);
493 setCellHeight(height()/4); 503 setCellHeight(height()/4);
494} 504}
495 505
496void 506void
497KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col) 507KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col)
498{ 508{
499 int index; 509 int index;
500 QString text; 510 QString text;
501 // ----- find the number of the cell: 511 // ----- find the number of the cell:
502 index=3*row+col+1; 512 index=3*row+col+1;
503 text=KGlobal::locale()->monthName(index, false); 513 text=KGlobal::locale()->monthName(index, false);
504 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); 514 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
505 if ( activeCol == col && activeRow == row ) 515 if ( activeCol == col && activeRow == row )
506 painter->drawRect( 0, 0, cellWidth(), cellHeight() ); 516 painter->drawRect( 0, 0, cellWidth(), cellHeight() );
507} 517}
508 518
509void 519void
510KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e) 520KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e)
511{ 521{
512 if(!isEnabled() || e->button() != LeftButton) 522 if(!isEnabled() || e->button() != LeftButton)
513 { 523 {
514 KNotifyClient::beep(); 524 KNotifyClient::beep();
515 return; 525 return;
516 } 526 }
517 // ----- 527 // -----
518 int row, col; 528 int row, col;
519 QPoint mouseCoord; 529 QPoint mouseCoord;
520 // ----- 530 // -----
521 mouseCoord = e->pos(); 531 mouseCoord = e->pos();
522 row=rowAt(mouseCoord.y()); 532 row=rowAt(mouseCoord.y());
523 col=columnAt(mouseCoord.x()); 533 col=columnAt(mouseCoord.x());
524 534
525 if(row<0 || col<0) 535 if(row<0 || col<0)
526 { // the user clicked on the frame of the table 536 { // the user clicked on the frame of the table
527 activeCol = -1; 537 activeCol = -1;
528 activeRow = -1; 538 activeRow = -1;
529 } else { 539 } else {
530 activeCol = col; 540 activeCol = col;
531 activeRow = row; 541 activeRow = row;
532 updateCell( row, col /*, false */ ); 542 updateCell( row, col /*, false */ );
533 } 543 }
534} 544}
535 545
536void 546void
537KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e) 547KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e)
538{ 548{
539 if (e->state() & LeftButton) 549 if (e->state() & LeftButton)
540 { 550 {
541 int row, col; 551 int row, col;
542 QPoint mouseCoord; 552 QPoint mouseCoord;
543 // ----- 553 // -----
544 mouseCoord = e->pos(); 554 mouseCoord = e->pos();
545 row=rowAt(mouseCoord.y()); 555 row=rowAt(mouseCoord.y());
546 col=columnAt(mouseCoord.x()); 556 col=columnAt(mouseCoord.x());
547 int tmpRow = -1, tmpCol = -1; 557 int tmpRow = -1, tmpCol = -1;
548 if(row<0 || col<0) 558 if(row<0 || col<0)
549 { // the user clicked on the frame of the table 559 { // the user clicked on the frame of the table
550 if ( activeCol > -1 ) 560 if ( activeCol > -1 )
551 { 561 {
552 tmpRow = activeRow; 562 tmpRow = activeRow;
553 tmpCol = activeCol; 563 tmpCol = activeCol;
554 } 564 }
555 activeCol = -1; 565 activeCol = -1;
556 activeRow = -1; 566 activeRow = -1;
557 } else { 567 } else {
558 bool differentCell = (activeRow != row || activeCol != col); 568 bool differentCell = (activeRow != row || activeCol != col);
559 if ( activeCol > -1 && differentCell) 569 if ( activeCol > -1 && differentCell)
560 { 570 {
561 tmpRow = activeRow; 571 tmpRow = activeRow;
562 tmpCol = activeCol; 572 tmpCol = activeCol;
563 } 573 }
564 if ( differentCell) 574 if ( differentCell)
565 { 575 {
566 activeRow = row; 576 activeRow = row;
567 activeCol = col; 577 activeCol = col;
568 updateCell( row, col /*, false */ ); // mark the new active cell 578 updateCell( row, col /*, false */ ); // mark the new active cell
569 } 579 }
570 } 580 }
571 if ( tmpRow > -1 ) // repaint the former active cell 581 if ( tmpRow > -1 ) // repaint the former active cell
572 updateCell( tmpRow, tmpCol /*, true */ ); 582 updateCell( tmpRow, tmpCol /*, true */ );
573 } 583 }
574} 584}
575 585
576void 586void
577KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e) 587KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e)
578{ 588{
579 if(!isEnabled()) 589 if(!isEnabled())
580 { 590 {
581 return; 591 return;
582 } 592 }
583 // ----- 593 // -----
584 int row, col, pos; 594 int row, col, pos;
585 QPoint mouseCoord; 595 QPoint mouseCoord;
586 // ----- 596 // -----
587 mouseCoord = e->pos(); 597 mouseCoord = e->pos();
588 row=rowAt(mouseCoord.y()); 598 row=rowAt(mouseCoord.y());
589 col=columnAt(mouseCoord.x()); 599 col=columnAt(mouseCoord.x());
590 if(row<0 || col<0) 600 if(row<0 || col<0)
591 { // the user clicked on the frame of the table 601 { // the user clicked on the frame of the table
592 emit(closeMe(0)); 602 emit(closeMe(0));
593 } 603 }
594 pos=3*row+col+1; 604 pos=3*row+col+1;
595 result=pos; 605 result=pos;
596 emit(closeMe(1)); 606 emit(closeMe(1));
597} 607}
598 608
599 609
600 610
601KDateInternalYearSelector::KDateInternalYearSelector 611KDateInternalYearSelector::KDateInternalYearSelector
602(int fontsize, QWidget* parent, const char* name) 612(int fontsize, QWidget* parent, const char* name)
603 : QLineEdit(parent, name), 613 : QLineEdit(parent, name),
604 val(new QIntValidator(this)), 614 val(new QIntValidator(this)),
605 result(0) 615 result(0)
606{ 616{
607 QFont font; 617 QFont font;
608 // ----- 618 // -----
609 font=KGlobalSettings::generalFont(); 619 font=KGlobalSettings::generalFont();
610 font.setPointSize(fontsize); 620 font.setPointSize(fontsize);
611 setFont(font); 621 setFont(font);
612#if 0 622#if 0
613 setFrameStyle(QFrame::NoFrame); 623 setFrameStyle(QFrame::NoFrame);
614#endif 624#endif
615 // we have to respect the limits of QDate here, I fear: 625 // we have to respect the limits of QDate here, I fear:
616 val->setRange(0, 8000); 626 val->setRange(0, 8000);
617 setValidator(val); 627 setValidator(val);
618 connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot())); 628 connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot()));
619} 629}
620 630
621void 631void
622KDateInternalYearSelector::yearEnteredSlot() 632KDateInternalYearSelector::yearEnteredSlot()
623{ 633{
624 bool ok; 634 bool ok;
625 int year; 635 int year;
626 QDate date; 636 QDate date;
627 // ----- check if this is a valid year: 637 // ----- check if this is a valid year:
628 year=text().toInt(&ok); 638 year=text().toInt(&ok);
629 if(!ok) 639 if(!ok)
630 { 640 {
631 KNotifyClient::beep(); 641 KNotifyClient::beep();
632 return; 642 return;
633 } 643 }
634 date.setYMD(year, 1, 1); 644 date.setYMD(year, 1, 1);
635 if(!date.isValid()) 645 if(!date.isValid())
636 { 646 {
637 KNotifyClient::beep(); 647 KNotifyClient::beep();
638 return; 648 return;
639 } 649 }
640 result=year; 650 result=year;
641 emit(closeMe(1)); 651 emit(closeMe(1));
642} 652}
643 653
644int 654int
645KDateInternalYearSelector::getYear() 655KDateInternalYearSelector::getYear()
646{ 656{
647 return result; 657 return result;
648} 658}
649 659
650void 660void
651KDateInternalYearSelector::setYear(int year) 661KDateInternalYearSelector::setYear(int year)
652{ 662{
653 QString temp; 663 QString temp;
654 // ----- 664 // -----
655 temp.setNum(year); 665 temp.setNum(year);
656 setText(temp); 666 setText(temp);
657} 667}
658 668
659KPopupFrame::KPopupFrame(QWidget* parent, const char* name) 669KPopupFrame::KPopupFrame(QWidget* parent, const char* name)
660 : QFrame(parent, name, WType_Popup), 670 : QFrame(parent, name, WType_Popup),
661 result(0), // rejected 671 result(0), // rejected
662 main(0) 672 main(0)
663{ 673{
664 setFrameStyle(QFrame::Box|QFrame::Raised); 674 setFrameStyle(QFrame::Box|QFrame::Raised);
665 setMidLineWidth(2); 675 setMidLineWidth(2);
666} 676}
667 677
668void 678void
669KPopupFrame::keyPressEvent(QKeyEvent* e) 679KPopupFrame::keyPressEvent(QKeyEvent* e)
670{ 680{
671 if(e->key()==Key_Escape) 681 if(e->key()==Key_Escape)
672 { 682 {
673 result=0; // rejected 683 result=0; // rejected
674 qApp->exit_loop(); 684 qApp->exit_loop();
675 } 685 }
676} 686}
677 687
678void 688void
679KPopupFrame::close(int r) 689KPopupFrame::close(int r)
680{ 690{
681 result=r; 691 result=r;
682 qApp->exit_loop(); 692 qApp->exit_loop();
683} 693}
684 694
685void 695void
686KPopupFrame::setMainWidget(QWidget* m) 696KPopupFrame::setMainWidget(QWidget* m)
687{ 697{
688 main=m; 698 main=m;
689 if(main!=0) 699 if(main!=0)
690 { 700 {
691 resize(main->width()+2*frameWidth(), main->height()+2*frameWidth()); 701 resize(main->width()+2*frameWidth(), main->height()+2*frameWidth());
692 } 702 }
693} 703}
694 704
695void 705void
696KPopupFrame::resizeEvent(QResizeEvent*) 706KPopupFrame::resizeEvent(QResizeEvent*)
697{ 707{
698 if(main!=0) 708 if(main!=0)
699 { 709 {
700 main->setGeometry(frameWidth(), frameWidth(), 710 main->setGeometry(frameWidth(), frameWidth(),
701 width()-2*frameWidth(), height()-2*frameWidth()); 711 width()-2*frameWidth(), height()-2*frameWidth());
702 } 712 }
703} 713}
704 714
705void 715void
706KPopupFrame::popup(const QPoint &pos) 716KPopupFrame::popup(const QPoint &pos)
707{ 717{
708 // Make sure the whole popup is visible. 718 // Make sure the whole popup is visible.
709 QRect d = QApplication::desktop()->frameGeometry(); 719 QRect d = QApplication::desktop()->frameGeometry();
710 int x = pos.x(); 720 int x = pos.x();
711 int y = pos.y(); 721 int y = pos.y();
712 int w = width(); 722 int w = width();
713 int h = height(); 723 int h = height();
714 if (x+w > d.x()+d.width()) 724 if (x+w > d.x()+d.width())
715 x = d.width() - w; 725 x = d.width() - w;
716 if (y+h > d.y()+d.height()) 726 if (y+h > d.y()+d.height())
717 y = d.height() - h; 727 y = d.height() - h;
718 if (x < d.x()) 728 if (x < d.x())
719 x = 0; 729 x = 0;
720 if (y < d.y()) 730 if (y < d.y())
721 y = 0; 731 y = 0;
722 732
723 // Pop the thingy up. 733 // Pop the thingy up.
724 move(x, y); 734 move(x, y);
725 show(); 735 show();
726} 736}
727 737
728int 738int
729KPopupFrame::exec(QPoint pos) 739KPopupFrame::exec(QPoint pos)
730{ 740{
731 popup(pos); 741 popup(pos);
732 repaint(); 742 repaint();
733 qApp->enter_loop(); 743 qApp->enter_loop();
734 hide(); 744 hide();
735 return result; 745 return result;
736} 746}
737 747
738int 748int
739KPopupFrame::exec(int x, int y) 749KPopupFrame::exec(int x, int y)
740{ 750{
741 return exec(QPoint(x, y)); 751 return exec(QPoint(x, y));
742} 752}
743 753
744void KPopupFrame::virtual_hook( int, void* ) 754void KPopupFrame::virtual_hook( int, void* )
745{ /*BASE::virtual_hook( id, data );*/ } 755{ /*BASE::virtual_hook( id, data );*/ }
746 756
747void KDateTable::virtual_hook( int, void* ) 757void KDateTable::virtual_hook( int, void* )
748{ /*BASE::virtual_hook( id, data );*/ } 758{ /*BASE::virtual_hook( id, data );*/ }
749 759
750//#include "kdatetbl.moc" 760//#include "kdatetbl.moc"
751 761
752 762
753KDateInternalWeekPicker::KDateInternalWeekPicker 763KDateInternalWeekPicker::KDateInternalWeekPicker
754(int fontsize, QWidget* parent, const char* name) 764(int fontsize, QWidget* parent, const char* name)
755 : QGridView(parent, name), 765 : QGridView(parent, name),
756 result(0) // invalid 766 result(0) // invalid
757{ 767{
758 QRect rect; 768 QRect rect;
759 QFont font; 769 QFont font;
760 // ----- 770 // -----
761 activeCol = -1; 771 activeCol = -1;
762 activeRow = -1; 772 activeRow = -1;
763 font=KGlobalSettings::generalFont(); 773 font=KGlobalSettings::generalFont();
764 font.setPointSize(fontsize); 774 //font.setPointSize(fontsize);
765 setFont(font); 775 setFont(font);
766 setHScrollBarMode(AlwaysOff); 776 setHScrollBarMode(AlwaysOff);
767 setVScrollBarMode(AlwaysOff); 777 setVScrollBarMode(AlwaysOff);
768 setFrameStyle(QFrame::NoFrame); 778 setFrameStyle(QFrame::NoFrame);
769 setNumRows(13); 779 setNumRows(13);
770 setNumCols(4); 780 setNumCols(4);
771 // enable to find drawing failures: 781 // enable to find drawing failures:
772 // setTableFlags(Tbl_clipCellPainting); 782 // setTableFlags(Tbl_clipCellPainting);
773#if 0 783#if 0
774 viewport()->setEraseColor(lightGray); // for consistency with the datepicker 784 viewport()->setEraseColor(lightGray); // for consistency with the datepicker
775#endif 785#endif
776 // ----- find the preferred size 786 // ----- find the preferred size
777 // (this is slow, possibly, but unfortunatly it is needed here): 787 // (this is slow, possibly, but unfortunatly it is needed here):
778 QFontMetrics metrics(font); 788 QFontMetrics metrics(font);
779 for(int i=1; i <= 52; ++i) 789 for(int i=1; i <= 52; ++i)
780 { 790 {
781 rect=metrics.boundingRect(QString::number( i )); 791 rect=metrics.boundingRect(QString::number( i ));
782 if(max.width()<rect.width()) max.setWidth(rect.width()); 792 if(max.width()<rect.width()) max.setWidth(rect.width());
783 if(max.height()<rect.height()) max.setHeight(rect.height()); 793 if(max.height()<rect.height()) max.setHeight(rect.height());
784 } 794 }
785 795 if ( QApplication::desktop()->width() > 640 ) {
796
797 max.setWidth(max.width()+6);
798 max.setHeight(max.height()+8);
799 }
786} 800}
787 801
788QSize 802QSize
789KDateInternalWeekPicker::sizeHint() const 803KDateInternalWeekPicker::sizeHint() const
790{ 804{
791 return QSize((max.width()+6)*numCols()+2*frameWidth(), 805 return QSize((max.width()+6)*numCols()+2*frameWidth(),
792 (max.height()+6)*numRows()+2*frameWidth()); 806 (max.height()+6)*numRows()+2*frameWidth());
793} 807}
794 808
795int 809int
796KDateInternalWeekPicker::getResult() const 810KDateInternalWeekPicker::getResult() const
797{ 811{
798 return result; 812 return result;
799} 813}
800 814
801void 815void
802KDateInternalWeekPicker::setupPainter(QPainter *p) 816KDateInternalWeekPicker::setupPainter(QPainter *p)
803{ 817{
804 p->setPen(black); 818 p->setPen(black);
805} 819}
806 820
807void 821void
808KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*) 822KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*)
809{ 823{
810 setCellWidth(width()/4); 824 setCellWidth(width()/4);
811 setCellHeight(height()/13); 825 setCellHeight(height()/13);
812} 826}
813 827
814void 828void
815KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col) 829KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col)
816{ 830{
817 int index; 831 int index;
818 QString text; 832 QString text;
819 // ----- find the number of the cell: 833 // ----- find the number of the cell:
820 index=4*row+col+1; 834 index=4*row+col+1;
821 text=QString::number( index ); 835 text=QString::number( index );
822 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); 836 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
823 if ( activeCol == col && activeRow == row ) 837 if ( activeCol == col && activeRow == row )
824 painter->drawRect( 0, 0, cellWidth(), cellHeight() ); 838 painter->drawRect( 0, 0, cellWidth(), cellHeight() );
825} 839}
826 840
827void 841void
828KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e) 842KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e)
829{ 843{
830 if(!isEnabled() || e->button() != LeftButton) 844 if(!isEnabled() || e->button() != LeftButton)
831 { 845 {
832 KNotifyClient::beep(); 846 KNotifyClient::beep();
833 return; 847 return;
834 } 848 }
835 // ----- 849 // -----
836 int row, col; 850 int row, col;
837 QPoint mouseCoord; 851 QPoint mouseCoord;
838 // ----- 852 // -----
839 mouseCoord = e->pos(); 853 mouseCoord = e->pos();
840 row=rowAt(mouseCoord.y()); 854 row=rowAt(mouseCoord.y());
841 col=columnAt(mouseCoord.x()); 855 col=columnAt(mouseCoord.x());
842 856
843 if(row<0 || col<0) 857 if(row<0 || col<0)
844 { // the user clicked on the frame of the table 858 { // the user clicked on the frame of the table
845 activeCol = -1; 859 activeCol = -1;
846 activeRow = -1; 860 activeRow = -1;
847 } else { 861 } else {
848 activeCol = col; 862 activeCol = col;
849 activeRow = row; 863 activeRow = row;
850 updateCell( row, col /*, false */ ); 864 updateCell( row, col /*, false */ );
851 } 865 }
852} 866}
853 867
854void 868void
855KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e) 869KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e)
856{ 870{
857 if (e->state() & LeftButton) 871 if (e->state() & LeftButton)
858 { 872 {
859 int row, col; 873 int row, col;
860 QPoint mouseCoord; 874 QPoint mouseCoord;
861 // ----- 875 // -----
862 mouseCoord = e->pos(); 876 mouseCoord = e->pos();
863 row=rowAt(mouseCoord.y()); 877 row=rowAt(mouseCoord.y());
864 col=columnAt(mouseCoord.x()); 878 col=columnAt(mouseCoord.x());
865 int tmpRow = -1, tmpCol = -1; 879 int tmpRow = -1, tmpCol = -1;
866 if(row<0 || col<0) 880 if(row<0 || col<0)
867 { // the user clicked on the frame of the table 881 { // the user clicked on the frame of the table
868 if ( activeCol > -1 ) 882 if ( activeCol > -1 )
869 { 883 {
870 tmpRow = activeRow; 884 tmpRow = activeRow;
871 tmpCol = activeCol; 885 tmpCol = activeCol;
872 } 886 }
873 activeCol = -1; 887 activeCol = -1;
874 activeRow = -1; 888 activeRow = -1;
875 } else { 889 } else {
876 bool differentCell = (activeRow != row || activeCol != col); 890 bool differentCell = (activeRow != row || activeCol != col);
877 if ( activeCol > -1 && differentCell) 891 if ( activeCol > -1 && differentCell)
878 { 892 {
879 tmpRow = activeRow; 893 tmpRow = activeRow;
880 tmpCol = activeCol; 894 tmpCol = activeCol;
881 } 895 }
882 if ( differentCell) 896 if ( differentCell)
883 { 897 {
884 activeRow = row; 898 activeRow = row;
885 activeCol = col; 899 activeCol = col;
886 updateCell( row, col /*, false */ ); // mark the new active cell 900 updateCell( row, col /*, false */ ); // mark the new active cell
887 } 901 }
888 } 902 }
889 if ( tmpRow > -1 ) // repaint the former active cell 903 if ( tmpRow > -1 ) // repaint the former active cell
890 updateCell( tmpRow, tmpCol /*, true */ ); 904 updateCell( tmpRow, tmpCol /*, true */ );
891 } 905 }
892} 906}
893 907
894void 908void
895KDateInternalWeekPicker::contentsMouseReleaseEvent(QMouseEvent *e) 909KDateInternalWeekPicker::contentsMouseReleaseEvent(QMouseEvent *e)
896{ 910{
897 if(!isEnabled()) 911 if(!isEnabled())
898 { 912 {
899 return; 913 return;
900 } 914 }
901 // ----- 915 // -----
902 int row, col, pos; 916 int row, col, pos;
903 QPoint mouseCoord; 917 QPoint mouseCoord;
904 // ----- 918 // -----
905 mouseCoord = e->pos(); 919 mouseCoord = e->pos();
906 row=rowAt(mouseCoord.y()); 920 row=rowAt(mouseCoord.y());
907 col=columnAt(mouseCoord.x()); 921 col=columnAt(mouseCoord.x());
908 if(row<0 || col<0) 922 if(row<0 || col<0)
909 { // the user clicked on the frame of the table 923 { // the user clicked on the frame of the table
910 emit(closeMe(0)); 924 emit(closeMe(0));
911 } 925 }
912 pos=4*row+col+1; 926 pos=4*row+col+1;
913 result=pos; 927 result=pos;
914 emit(closeMe(1)); 928 emit(closeMe(1));
915} 929}