-rw-r--r-- | microkde/kdatetbl.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp index 990cfb9..a9924ba 100644 --- a/microkde/kdatetbl.cpp +++ b/microkde/kdatetbl.cpp | |||
@@ -1,937 +1,937 @@ | |||
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 | ||
50 | KDateValidator::KDateValidator(QWidget* parent, const char* name) | 50 | KDateValidator::KDateValidator(QWidget* parent, const char* name) |
51 | : QValidator(parent, name) | 51 | : QValidator(parent, name) |
52 | { | 52 | { |
53 | } | 53 | } |
54 | 54 | ||
55 | QValidator::State | 55 | QValidator::State |
56 | KDateValidator::validate(QString& text, int&) const | 56 | KDateValidator::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 | ||
63 | QValidator::State | 63 | QValidator::State |
64 | KDateValidator::date(const QString& text, QDate& d) const | 64 | KDateValidator::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 | ||
75 | void | 75 | void |
76 | KDateValidator::fixup( QString& ) const | 76 | KDateValidator::fixup( QString& ) const |
77 | { | 77 | { |
78 | 78 | ||
79 | } | 79 | } |
80 | 80 | ||
81 | KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f) | 81 | KDateTable::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 | ||
102 | void | 102 | void |
103 | KDateTable::paintCell(QPainter *painter, int row, int col) | 103 | KDateTable::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 | ||
208 | void | 208 | void |
209 | KDateTable::keyPressEvent( QKeyEvent *e ) | 209 | KDateTable::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 | ||
286 | void | 286 | void |
287 | KDateTable::viewportResizeEvent(QResizeEvent * e) | 287 | KDateTable::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 | ||
295 | void | 295 | void |
296 | KDateTable::setFontSize(int size) | 296 | KDateTable::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 | ||
331 | void | 331 | void |
332 | KDateTable::contentsMousePressEvent(QMouseEvent *e) | 332 | KDateTable::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 | ||
378 | bool | 378 | bool |
379 | KDateTable::setDate(const QDate& date_) | 379 | KDateTable::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 | ||
415 | const QDate& | 415 | const QDate& |
416 | KDateTable::getDate() const | 416 | KDateTable::getDate() const |
417 | { | 417 | { |
418 | return date; | 418 | return date; |
419 | } | 419 | } |
420 | 420 | ||
421 | void KDateTable::focusInEvent( QFocusEvent *e ) | 421 | void KDateTable::focusInEvent( QFocusEvent *e ) |
422 | { | 422 | { |
423 | repaintContents(false); | 423 | repaintContents(false); |
424 | QGridView::focusInEvent( e ); | 424 | QGridView::focusInEvent( e ); |
425 | } | 425 | } |
426 | 426 | ||
427 | void KDateTable::focusOutEvent( QFocusEvent *e ) | 427 | void KDateTable::focusOutEvent( QFocusEvent *e ) |
428 | { | 428 | { |
429 | repaintContents(false); | 429 | repaintContents(false); |
430 | QGridView::focusOutEvent( e ); | 430 | QGridView::focusOutEvent( e ); |
431 | } | 431 | } |
432 | 432 | ||
433 | QSize | 433 | QSize |
434 | KDateTable::sizeHint() const | 434 | KDateTable::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 | ||
445 | KDateInternalMonthPicker::KDateInternalMonthPicker | 445 | KDateInternalMonthPicker::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 += 6; | 459 | add += 8; |
460 | font.setPointSize(fontsize+add); | 460 | font.setPointSize(fontsize+add); |
461 | setFont(font); | 461 | setFont(font); |
462 | setHScrollBarMode(AlwaysOff); | 462 | setHScrollBarMode(AlwaysOff); |
463 | setVScrollBarMode(AlwaysOff); | 463 | setVScrollBarMode(AlwaysOff); |
464 | setFrameStyle(QFrame::NoFrame); | 464 | setFrameStyle(QFrame::NoFrame); |
465 | setNumRows(4); | 465 | setNumRows(4); |
466 | setNumCols(3); | 466 | setNumCols(3); |
467 | // enable to find drawing failures: | 467 | // enable to find drawing failures: |
468 | // setTableFlags(Tbl_clipCellPainting); | 468 | // setTableFlags(Tbl_clipCellPainting); |
469 | #if 0 | 469 | #if 0 |
470 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker | 470 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker |
471 | #endif | 471 | #endif |
472 | // ----- find the preferred size | 472 | // ----- find the preferred size |
473 | // (this is slow, possibly, but unfortunatly it is needed here): | 473 | // (this is slow, possibly, but unfortunatly it is needed here): |
474 | QFontMetrics metrics(font); | 474 | QFontMetrics metrics(font); |
475 | for(int i=1; i <= 12; ++i) | 475 | for(int i=1; i <= 12; ++i) |
476 | { | 476 | { |
477 | rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); | 477 | rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); |
478 | if(max.width()<rect.width()) max.setWidth(rect.width()); | 478 | if(max.width()<rect.width()) max.setWidth(rect.width()); |
479 | if(max.height()<rect.height()) max.setHeight(rect.height()); | 479 | if(max.height()<rect.height()) max.setHeight(rect.height()); |
480 | } | 480 | } |
481 | 481 | ||
482 | } | 482 | } |
483 | 483 | ||
484 | QSize | 484 | QSize |
485 | KDateInternalMonthPicker::sizeHint() const | 485 | KDateInternalMonthPicker::sizeHint() const |
486 | { | 486 | { |
487 | return QSize((max.width()+6)*numCols()+2*frameWidth(), | 487 | return QSize((max.width()+6)*numCols()+2*frameWidth(), |
488 | (max.height()+6)*numRows()+2*frameWidth()); | 488 | (max.height()+6)*numRows()+2*frameWidth()); |
489 | } | 489 | } |
490 | 490 | ||
491 | int | 491 | int |
492 | KDateInternalMonthPicker::getResult() const | 492 | KDateInternalMonthPicker::getResult() const |
493 | { | 493 | { |
494 | return result; | 494 | return result; |
495 | } | 495 | } |
496 | 496 | ||
497 | void | 497 | void |
498 | KDateInternalMonthPicker::setupPainter(QPainter *p) | 498 | KDateInternalMonthPicker::setupPainter(QPainter *p) |
499 | { | 499 | { |
500 | p->setPen(black); | 500 | p->setPen(black); |
501 | } | 501 | } |
502 | 502 | ||
503 | void | 503 | void |
504 | KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*) | 504 | KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*) |
505 | { | 505 | { |
506 | setCellWidth(width()/3); | 506 | setCellWidth(width()/3); |
507 | setCellHeight(height()/4); | 507 | setCellHeight(height()/4); |
508 | } | 508 | } |
509 | 509 | ||
510 | void | 510 | void |
511 | KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col) | 511 | KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col) |
512 | { | 512 | { |
513 | int index; | 513 | int index; |
514 | QString text; | 514 | QString text; |
515 | // ----- find the number of the cell: | 515 | // ----- find the number of the cell: |
516 | index=3*row+col+1; | 516 | index=3*row+col+1; |
517 | text=KGlobal::locale()->monthName(index, false); | 517 | text=KGlobal::locale()->monthName(index, false); |
518 | painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); | 518 | painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); |
519 | if ( activeCol == col && activeRow == row ) | 519 | if ( activeCol == col && activeRow == row ) |
520 | painter->drawRect( 0, 0, cellWidth(), cellHeight() ); | 520 | painter->drawRect( 0, 0, cellWidth(), cellHeight() ); |
521 | } | 521 | } |
522 | 522 | ||
523 | void | 523 | void |
524 | KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e) | 524 | KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e) |
525 | { | 525 | { |
526 | if(!isEnabled() || e->button() != LeftButton) | 526 | if(!isEnabled() || e->button() != LeftButton) |
527 | { | 527 | { |
528 | KNotifyClient::beep(); | 528 | KNotifyClient::beep(); |
529 | return; | 529 | return; |
530 | } | 530 | } |
531 | // ----- | 531 | // ----- |
532 | int row, col; | 532 | int row, col; |
533 | QPoint mouseCoord; | 533 | QPoint mouseCoord; |
534 | // ----- | 534 | // ----- |
535 | mouseCoord = e->pos(); | 535 | mouseCoord = e->pos(); |
536 | row=rowAt(mouseCoord.y()); | 536 | row=rowAt(mouseCoord.y()); |
537 | col=columnAt(mouseCoord.x()); | 537 | col=columnAt(mouseCoord.x()); |
538 | 538 | ||
539 | if(row<0 || col<0) | 539 | if(row<0 || col<0) |
540 | { // the user clicked on the frame of the table | 540 | { // the user clicked on the frame of the table |
541 | activeCol = -1; | 541 | activeCol = -1; |
542 | activeRow = -1; | 542 | activeRow = -1; |
543 | } else { | 543 | } else { |
544 | activeCol = col; | 544 | activeCol = col; |
545 | activeRow = row; | 545 | activeRow = row; |
546 | updateCell( row, col /*, false */ ); | 546 | updateCell( row, col /*, false */ ); |
547 | } | 547 | } |
548 | } | 548 | } |
549 | 549 | ||
550 | void | 550 | void |
551 | KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e) | 551 | KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e) |
552 | { | 552 | { |
553 | if (e->state() & LeftButton) | 553 | if (e->state() & LeftButton) |
554 | { | 554 | { |
555 | int row, col; | 555 | int row, col; |
556 | QPoint mouseCoord; | 556 | QPoint mouseCoord; |
557 | // ----- | 557 | // ----- |
558 | mouseCoord = e->pos(); | 558 | mouseCoord = e->pos(); |
559 | row=rowAt(mouseCoord.y()); | 559 | row=rowAt(mouseCoord.y()); |
560 | col=columnAt(mouseCoord.x()); | 560 | col=columnAt(mouseCoord.x()); |
561 | int tmpRow = -1, tmpCol = -1; | 561 | int tmpRow = -1, tmpCol = -1; |
562 | if(row<0 || col<0) | 562 | if(row<0 || col<0) |
563 | { // the user clicked on the frame of the table | 563 | { // the user clicked on the frame of the table |
564 | if ( activeCol > -1 ) | 564 | if ( activeCol > -1 ) |
565 | { | 565 | { |
566 | tmpRow = activeRow; | 566 | tmpRow = activeRow; |
567 | tmpCol = activeCol; | 567 | tmpCol = activeCol; |
568 | } | 568 | } |
569 | activeCol = -1; | 569 | activeCol = -1; |
570 | activeRow = -1; | 570 | activeRow = -1; |
571 | } else { | 571 | } else { |
572 | bool differentCell = (activeRow != row || activeCol != col); | 572 | bool differentCell = (activeRow != row || activeCol != col); |
573 | if ( activeCol > -1 && differentCell) | 573 | if ( activeCol > -1 && differentCell) |
574 | { | 574 | { |
575 | tmpRow = activeRow; | 575 | tmpRow = activeRow; |
576 | tmpCol = activeCol; | 576 | tmpCol = activeCol; |
577 | } | 577 | } |
578 | if ( differentCell) | 578 | if ( differentCell) |
579 | { | 579 | { |
580 | activeRow = row; | 580 | activeRow = row; |
581 | activeCol = col; | 581 | activeCol = col; |
582 | updateCell( row, col /*, false */ ); // mark the new active cell | 582 | updateCell( row, col /*, false */ ); // mark the new active cell |
583 | } | 583 | } |
584 | } | 584 | } |
585 | if ( tmpRow > -1 ) // repaint the former active cell | 585 | if ( tmpRow > -1 ) // repaint the former active cell |
586 | updateCell( tmpRow, tmpCol /*, true */ ); | 586 | updateCell( tmpRow, tmpCol /*, true */ ); |
587 | } | 587 | } |
588 | } | 588 | } |
589 | 589 | ||
590 | void | 590 | void |
591 | KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e) | 591 | KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e) |
592 | { | 592 | { |
593 | if(!isEnabled()) | 593 | if(!isEnabled()) |
594 | { | 594 | { |
595 | return; | 595 | return; |
596 | } | 596 | } |
597 | // ----- | 597 | // ----- |
598 | int row, col, pos; | 598 | int row, col, pos; |
599 | QPoint mouseCoord; | 599 | QPoint mouseCoord; |
600 | // ----- | 600 | // ----- |
601 | mouseCoord = e->pos(); | 601 | mouseCoord = e->pos(); |
602 | row=rowAt(mouseCoord.y()); | 602 | row=rowAt(mouseCoord.y()); |
603 | col=columnAt(mouseCoord.x()); | 603 | col=columnAt(mouseCoord.x()); |
604 | if(row<0 || col<0) | 604 | if(row<0 || col<0) |
605 | { // the user clicked on the frame of the table | 605 | { // the user clicked on the frame of the table |
606 | emit(closeMe(0)); | 606 | emit(closeMe(0)); |
607 | } | 607 | } |
608 | pos=3*row+col+1; | 608 | pos=3*row+col+1; |
609 | result=pos; | 609 | result=pos; |
610 | emit(closeMe(1)); | 610 | emit(closeMe(1)); |
611 | } | 611 | } |
612 | 612 | ||
613 | 613 | ||
614 | 614 | ||
615 | KDateInternalYearSelector::KDateInternalYearSelector | 615 | KDateInternalYearSelector::KDateInternalYearSelector |
616 | (int fontsize, QWidget* parent, const char* name) | 616 | (int fontsize, QWidget* parent, const char* name) |
617 | : QLineEdit(parent, name), | 617 | : QLineEdit(parent, name), |
618 | val(new QIntValidator(this)), | 618 | val(new QIntValidator(this)), |
619 | result(0) | 619 | result(0) |
620 | { | 620 | { |
621 | QFont font; | 621 | QFont font; |
622 | // ----- | 622 | // ----- |
623 | font=KGlobalSettings::generalFont(); | 623 | font=KGlobalSettings::generalFont(); |
624 | font.setPointSize(fontsize); | 624 | font.setPointSize(fontsize); |
625 | setFont(font); | 625 | setFont(font); |
626 | #if 0 | 626 | #if 0 |
627 | setFrameStyle(QFrame::NoFrame); | 627 | setFrameStyle(QFrame::NoFrame); |
628 | #endif | 628 | #endif |
629 | // we have to respect the limits of QDate here, I fear: | 629 | // we have to respect the limits of QDate here, I fear: |
630 | val->setRange(0, 8000); | 630 | val->setRange(0, 8000); |
631 | setValidator(val); | 631 | setValidator(val); |
632 | connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot())); | 632 | connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot())); |
633 | } | 633 | } |
634 | 634 | ||
635 | void | 635 | void |
636 | KDateInternalYearSelector::yearEnteredSlot() | 636 | KDateInternalYearSelector::yearEnteredSlot() |
637 | { | 637 | { |
638 | bool ok; | 638 | bool ok; |
639 | int year; | 639 | int year; |
640 | QDate date; | 640 | QDate date; |
641 | // ----- check if this is a valid year: | 641 | // ----- check if this is a valid year: |
642 | year=text().toInt(&ok); | 642 | year=text().toInt(&ok); |
643 | if(!ok) | 643 | if(!ok) |
644 | { | 644 | { |
645 | KNotifyClient::beep(); | 645 | KNotifyClient::beep(); |
646 | return; | 646 | return; |
647 | } | 647 | } |
648 | date.setYMD(year, 1, 1); | 648 | date.setYMD(year, 1, 1); |
649 | if(!date.isValid()) | 649 | if(!date.isValid()) |
650 | { | 650 | { |
651 | KNotifyClient::beep(); | 651 | KNotifyClient::beep(); |
652 | return; | 652 | return; |
653 | } | 653 | } |
654 | result=year; | 654 | result=year; |
655 | emit(closeMe(1)); | 655 | emit(closeMe(1)); |
656 | } | 656 | } |
657 | 657 | ||
658 | int | 658 | int |
659 | KDateInternalYearSelector::getYear() | 659 | KDateInternalYearSelector::getYear() |
660 | { | 660 | { |
661 | return result; | 661 | return result; |
662 | } | 662 | } |
663 | 663 | ||
664 | void | 664 | void |
665 | KDateInternalYearSelector::setYear(int year) | 665 | KDateInternalYearSelector::setYear(int year) |
666 | { | 666 | { |
667 | QString temp; | 667 | QString temp; |
668 | // ----- | 668 | // ----- |
669 | temp.setNum(year); | 669 | temp.setNum(year); |
670 | setText(temp); | 670 | setText(temp); |
671 | } | 671 | } |
672 | 672 | ||
673 | KPopupFrame::KPopupFrame(QWidget* parent, const char* name) | 673 | KPopupFrame::KPopupFrame(QWidget* parent, const char* name) |
674 | : QFrame(parent, name, WType_Popup), | 674 | : QFrame(parent, name, WType_Popup), |
675 | result(0), // rejected | 675 | result(0), // rejected |
676 | main(0) | 676 | main(0) |
677 | { | 677 | { |
678 | setFrameStyle(QFrame::Box|QFrame::Raised); | 678 | setFrameStyle(QFrame::Box|QFrame::Raised); |
679 | setMidLineWidth(2); | 679 | setMidLineWidth(2); |
680 | } | 680 | } |
681 | 681 | ||
682 | void | 682 | void |
683 | KPopupFrame::keyPressEvent(QKeyEvent* e) | 683 | KPopupFrame::keyPressEvent(QKeyEvent* e) |
684 | { | 684 | { |
685 | if(e->key()==Key_Escape) | 685 | if(e->key()==Key_Escape) |
686 | { | 686 | { |
687 | result=0; // rejected | 687 | result=0; // rejected |
688 | qApp->exit_loop(); | 688 | qApp->exit_loop(); |
689 | } | 689 | } |
690 | } | 690 | } |
691 | 691 | ||
692 | void | 692 | void |
693 | KPopupFrame::close(int r) | 693 | KPopupFrame::close(int r) |
694 | { | 694 | { |
695 | result=r; | 695 | result=r; |
696 | qApp->exit_loop(); | 696 | qApp->exit_loop(); |
697 | } | 697 | } |
698 | 698 | ||
699 | void | 699 | void |
700 | KPopupFrame::setMainWidget(QWidget* m) | 700 | KPopupFrame::setMainWidget(QWidget* m) |
701 | { | 701 | { |
702 | main=m; | 702 | main=m; |
703 | if(main!=0) | 703 | if(main!=0) |
704 | { | 704 | { |
705 | resize(main->width()+2*frameWidth(), main->height()+2*frameWidth()); | 705 | resize(main->width()+2*frameWidth(), main->height()+2*frameWidth()); |
706 | } | 706 | } |
707 | } | 707 | } |
708 | 708 | ||
709 | void | 709 | void |
710 | KPopupFrame::resizeEvent(QResizeEvent*) | 710 | KPopupFrame::resizeEvent(QResizeEvent*) |
711 | { | 711 | { |
712 | if(main!=0) | 712 | if(main!=0) |
713 | { | 713 | { |
714 | main->setGeometry(frameWidth(), frameWidth(), | 714 | main->setGeometry(frameWidth(), frameWidth(), |
715 | width()-2*frameWidth(), height()-2*frameWidth()); | 715 | width()-2*frameWidth(), height()-2*frameWidth()); |
716 | } | 716 | } |
717 | } | 717 | } |
718 | 718 | ||
719 | void | 719 | void |
720 | KPopupFrame::popup(const QPoint &pos) | 720 | KPopupFrame::popup(const QPoint &pos) |
721 | { | 721 | { |
722 | // Make sure the whole popup is visible. | 722 | // Make sure the whole popup is visible. |
723 | QRect d = QApplication::desktop()->frameGeometry(); | 723 | QRect d = QApplication::desktop()->frameGeometry(); |
724 | int x = pos.x(); | 724 | int x = pos.x(); |
725 | int y = pos.y(); | 725 | int y = pos.y(); |
726 | int w = width(); | 726 | int w = width(); |
727 | int h = height(); | 727 | int h = height(); |
728 | if (x+w > d.x()+d.width()) | 728 | if (x+w > d.x()+d.width()) |
729 | x = d.width() - w; | 729 | x = d.width() - w; |
730 | if (y+h > d.y()+d.height()) | 730 | if (y+h > d.y()+d.height()) |
731 | y = d.height() - h; | 731 | y = d.height() - h; |
732 | if (x < d.x()) | 732 | if (x < d.x()) |
733 | x = 0; | 733 | x = 0; |
734 | if (y < d.y()) | 734 | if (y < d.y()) |
735 | y = 0; | 735 | y = 0; |
736 | 736 | ||
737 | // Pop the thingy up. | 737 | // Pop the thingy up. |
738 | move(x, y); | 738 | move(x, y); |
739 | show(); | 739 | show(); |
740 | } | 740 | } |
741 | 741 | ||
742 | int | 742 | int |
743 | KPopupFrame::exec(QPoint pos) | 743 | KPopupFrame::exec(QPoint pos) |
744 | { | 744 | { |
745 | popup(pos); | 745 | popup(pos); |
746 | repaint(); | 746 | repaint(); |
747 | qApp->enter_loop(); | 747 | qApp->enter_loop(); |
748 | hide(); | 748 | hide(); |
749 | return result; | 749 | return result; |
750 | } | 750 | } |
751 | 751 | ||
752 | int | 752 | int |
753 | KPopupFrame::exec(int x, int y) | 753 | KPopupFrame::exec(int x, int y) |
754 | { | 754 | { |
755 | return exec(QPoint(x, y)); | 755 | return exec(QPoint(x, y)); |
756 | } | 756 | } |
757 | 757 | ||
758 | void KPopupFrame::virtual_hook( int, void* ) | 758 | void KPopupFrame::virtual_hook( int, void* ) |
759 | { /*BASE::virtual_hook( id, data );*/ } | 759 | { /*BASE::virtual_hook( id, data );*/ } |
760 | 760 | ||
761 | void KDateTable::virtual_hook( int, void* ) | 761 | void KDateTable::virtual_hook( int, void* ) |
762 | { /*BASE::virtual_hook( id, data );*/ } | 762 | { /*BASE::virtual_hook( id, data );*/ } |
763 | 763 | ||
764 | //#include "kdatetbl.moc" | 764 | //#include "kdatetbl.moc" |
765 | 765 | ||
766 | 766 | ||
767 | KDateInternalWeekPicker::KDateInternalWeekPicker | 767 | KDateInternalWeekPicker::KDateInternalWeekPicker |
768 | (QWidget* parent, const char* name) | 768 | (QWidget* parent, const char* name) |
769 | : QGridView(parent, name), | 769 | : QGridView(parent, name), |
770 | result(0) // invalid | 770 | result(0) // invalid |
771 | { | 771 | { |
772 | QRect rect; | 772 | QRect rect; |
773 | QFont font; | 773 | QFont font; |
774 | // ----- | 774 | // ----- |
775 | activeCol = -1; | 775 | activeCol = -1; |
776 | activeRow = -1; | 776 | activeRow = -1; |
777 | font=KGlobalSettings::generalFont(); | 777 | font=KGlobalSettings::generalFont(); |
778 | int fontsize = 10; | 778 | int fontsize = 10; |
779 | int add = 2; | 779 | int add = 2; |
780 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) | 780 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) |
781 | add += 4; | 781 | add += 6; |
782 | font.setPointSize(fontsize+add); | 782 | font.setPointSize(fontsize+add); |
783 | setFont(font); | 783 | setFont(font); |
784 | setHScrollBarMode(AlwaysOff); | 784 | setHScrollBarMode(AlwaysOff); |
785 | setVScrollBarMode(AlwaysOff); | 785 | setVScrollBarMode(AlwaysOff); |
786 | setFrameStyle(QFrame::NoFrame); | 786 | setFrameStyle(QFrame::NoFrame); |
787 | setNumRows(13); | 787 | setNumRows(13); |
788 | setNumCols(4); | 788 | setNumCols(4); |
789 | // enable to find drawing failures: | 789 | // enable to find drawing failures: |
790 | // setTableFlags(Tbl_clipCellPainting); | 790 | // setTableFlags(Tbl_clipCellPainting); |
791 | #if 0 | 791 | #if 0 |
792 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker | 792 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker |
793 | #endif | 793 | #endif |
794 | // ----- find the preferred size | 794 | // ----- find the preferred size |
795 | // (this is slow, possibly, but unfortunatly it is needed here): | 795 | // (this is slow, possibly, but unfortunatly it is needed here): |
796 | QFontMetrics metrics(font); | 796 | QFontMetrics metrics(font); |
797 | for(int i=1; i <= 52; ++i) | 797 | for(int i=1; i <= 52; ++i) |
798 | { | 798 | { |
799 | rect=metrics.boundingRect(QString::number( i )); | 799 | rect=metrics.boundingRect(QString::number( i )); |
800 | if(max.width()<rect.width()) max.setWidth(rect.width()); | 800 | if(max.width()<rect.width()) max.setWidth(rect.width()); |
801 | if(max.height()<rect.height()) max.setHeight(rect.height()); | 801 | if(max.height()<rect.height()) max.setHeight(rect.height()); |
802 | } | 802 | } |
803 | if ( QApplication::desktop()->width() > 640 ) { | 803 | if ( QApplication::desktop()->width() > 640 ) { |
804 | 804 | ||
805 | max.setWidth(max.width()+6); | 805 | max.setWidth(max.width()+6); |
806 | max.setHeight(max.height()+8); | 806 | max.setHeight(max.height()+8); |
807 | } | 807 | } |
808 | } | 808 | } |
809 | 809 | ||
810 | QSize | 810 | QSize |
811 | KDateInternalWeekPicker::sizeHint() const | 811 | KDateInternalWeekPicker::sizeHint() const |
812 | { | 812 | { |
813 | return QSize((max.width()+6)*numCols()+2*frameWidth(), | 813 | return QSize((max.width()+6)*numCols()+2*frameWidth(), |
814 | (max.height()+6)*numRows()+2*frameWidth()); | 814 | (max.height()+6)*numRows()+2*frameWidth()); |
815 | } | 815 | } |
816 | 816 | ||
817 | int | 817 | int |
818 | KDateInternalWeekPicker::getResult() const | 818 | KDateInternalWeekPicker::getResult() const |
819 | { | 819 | { |
820 | return result; | 820 | return result; |
821 | } | 821 | } |
822 | 822 | ||
823 | void | 823 | void |
824 | KDateInternalWeekPicker::setupPainter(QPainter *p) | 824 | KDateInternalWeekPicker::setupPainter(QPainter *p) |
825 | { | 825 | { |
826 | p->setPen(black); | 826 | p->setPen(black); |
827 | } | 827 | } |
828 | 828 | ||
829 | void | 829 | void |
830 | KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*) | 830 | KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*) |
831 | { | 831 | { |
832 | setCellWidth(width()/4); | 832 | setCellWidth(width()/4); |
833 | setCellHeight(height()/13); | 833 | setCellHeight(height()/13); |
834 | } | 834 | } |
835 | 835 | ||
836 | void | 836 | void |
837 | KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col) | 837 | KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col) |
838 | { | 838 | { |
839 | int index; | 839 | int index; |
840 | QString text; | 840 | QString text; |
841 | // ----- find the number of the cell: | 841 | // ----- find the number of the cell: |
842 | index=4*row+col+1; | 842 | index=4*row+col+1; |
843 | text=QString::number( index ); | 843 | text=QString::number( index ); |
844 | painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); | 844 | painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); |
845 | if ( activeCol == col && activeRow == row ) | 845 | if ( activeCol == col && activeRow == row ) |
846 | painter->drawRect( 0, 0, cellWidth(), cellHeight() ); | 846 | painter->drawRect( 0, 0, cellWidth(), cellHeight() ); |
847 | } | 847 | } |
848 | 848 | ||
849 | void | 849 | void |
850 | KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e) | 850 | KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e) |
851 | { | 851 | { |
852 | if(!isEnabled() || e->button() != LeftButton) | 852 | if(!isEnabled() || e->button() != LeftButton) |
853 | { | 853 | { |
854 | KNotifyClient::beep(); | 854 | KNotifyClient::beep(); |
855 | return; | 855 | return; |
856 | } | 856 | } |
857 | // ----- | 857 | // ----- |
858 | int row, col; | 858 | int row, col; |
859 | QPoint mouseCoord; | 859 | QPoint mouseCoord; |
860 | // ----- | 860 | // ----- |
861 | mouseCoord = e->pos(); | 861 | mouseCoord = e->pos(); |
862 | row=rowAt(mouseCoord.y()); | 862 | row=rowAt(mouseCoord.y()); |
863 | col=columnAt(mouseCoord.x()); | 863 | col=columnAt(mouseCoord.x()); |
864 | 864 | ||
865 | if(row<0 || col<0) | 865 | if(row<0 || col<0) |
866 | { // the user clicked on the frame of the table | 866 | { // the user clicked on the frame of the table |
867 | activeCol = -1; | 867 | activeCol = -1; |
868 | activeRow = -1; | 868 | activeRow = -1; |
869 | } else { | 869 | } else { |
870 | activeCol = col; | 870 | activeCol = col; |
871 | activeRow = row; | 871 | activeRow = row; |
872 | updateCell( row, col /*, false */ ); | 872 | updateCell( row, col /*, false */ ); |
873 | } | 873 | } |
874 | } | 874 | } |
875 | 875 | ||
876 | void | 876 | void |
877 | KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e) | 877 | KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e) |
878 | { | 878 | { |
879 | if (e->state() & LeftButton) | 879 | if (e->state() & LeftButton) |
880 | { | 880 | { |
881 | int row, col; | 881 | int row, col; |
882 | QPoint mouseCoord; | 882 | QPoint mouseCoord; |
883 | // ----- | 883 | // ----- |
884 | mouseCoord = e->pos(); | 884 | mouseCoord = e->pos(); |
885 | row=rowAt(mouseCoord.y()); | 885 | row=rowAt(mouseCoord.y()); |
886 | col=columnAt(mouseCoord.x()); | 886 | col=columnAt(mouseCoord.x()); |
887 | int tmpRow = -1, tmpCol = -1; | 887 | int tmpRow = -1, tmpCol = -1; |
888 | if(row<0 || col<0) | 888 | if(row<0 || col<0) |
889 | { // the user clicked on the frame of the table | 889 | { // the user clicked on the frame of the table |
890 | if ( activeCol > -1 ) | 890 | if ( activeCol > -1 ) |
891 | { | 891 | { |
892 | tmpRow = activeRow; | 892 | tmpRow = activeRow; |
893 | tmpCol = activeCol; | 893 | tmpCol = activeCol; |
894 | } | 894 | } |
895 | activeCol = -1; | 895 | activeCol = -1; |
896 | activeRow = -1; | 896 | activeRow = -1; |
897 | } else { | 897 | } else { |
898 | bool differentCell = (activeRow != row || activeCol != col); | 898 | bool differentCell = (activeRow != row || activeCol != col); |
899 | if ( activeCol > -1 && differentCell) | 899 | if ( activeCol > -1 && differentCell) |
900 | { | 900 | { |
901 | tmpRow = activeRow; | 901 | tmpRow = activeRow; |
902 | tmpCol = activeCol; | 902 | tmpCol = activeCol; |
903 | } | 903 | } |
904 | if ( differentCell) | 904 | if ( differentCell) |
905 | { | 905 | { |
906 | activeRow = row; | 906 | activeRow = row; |
907 | activeCol = col; | 907 | activeCol = col; |
908 | updateCell( row, col /*, false */ ); // mark the new active cell | 908 | updateCell( row, col /*, false */ ); // mark the new active cell |
909 | } | 909 | } |
910 | } | 910 | } |
911 | if ( tmpRow > -1 ) // repaint the former active cell | 911 | if ( tmpRow > -1 ) // repaint the former active cell |
912 | updateCell( tmpRow, tmpCol /*, true */ ); | 912 | updateCell( tmpRow, tmpCol /*, true */ ); |
913 | } | 913 | } |
914 | } | 914 | } |
915 | 915 | ||
916 | void | 916 | void |
917 | KDateInternalWeekPicker::contentsMouseReleaseEvent(QMouseEvent *e) | 917 | KDateInternalWeekPicker::contentsMouseReleaseEvent(QMouseEvent *e) |
918 | { | 918 | { |
919 | if(!isEnabled()) | 919 | if(!isEnabled()) |
920 | { | 920 | { |
921 | return; | 921 | return; |
922 | } | 922 | } |
923 | // ----- | 923 | // ----- |
924 | int row, col, pos; | 924 | int row, col, pos; |
925 | QPoint mouseCoord; | 925 | QPoint mouseCoord; |
926 | // ----- | 926 | // ----- |
927 | mouseCoord = e->pos(); | 927 | mouseCoord = e->pos(); |
928 | row=rowAt(mouseCoord.y()); | 928 | row=rowAt(mouseCoord.y()); |
929 | col=columnAt(mouseCoord.x()); | 929 | col=columnAt(mouseCoord.x()); |
930 | if(row<0 || col<0) | 930 | if(row<0 || col<0) |
931 | { // the user clicked on the frame of the table | 931 | { // the user clicked on the frame of the table |
932 | emit(closeMe(0)); | 932 | emit(closeMe(0)); |
933 | } | 933 | } |
934 | pos=4*row+col+1; | 934 | pos=4*row+col+1; |
935 | result=pos; | 935 | result=pos; |
936 | emit(closeMe(1)); | 936 | emit(closeMe(1)); |
937 | } | 937 | } |