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