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