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