-rw-r--r-- | libkdepim/kdatepicker.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp index 6e5ec0f..3fe139c 100644 --- a/libkdepim/kdatepicker.cpp +++ b/libkdepim/kdatepicker.cpp | |||
@@ -1,472 +1,472 @@ | |||
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 | #include "kdatepicker.h" | 21 | #include "kdatepicker.h" |
22 | #include <kglobal.h> | 22 | #include <kglobal.h> |
23 | #include <kapplication.h> | 23 | #include <kapplication.h> |
24 | #include <klocale.h> | 24 | #include <klocale.h> |
25 | #include <kiconloader.h> | 25 | #include <kiconloader.h> |
26 | #include <qframe.h> | 26 | #include <qframe.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qdialog.h> | 28 | #include <qdialog.h> |
29 | #include <qtoolbutton.h> | 29 | #include <qtoolbutton.h> |
30 | #include <qfont.h> | 30 | #include <qfont.h> |
31 | #include <qapplication.h> | 31 | #include <qapplication.h> |
32 | #include <qlineedit.h> | 32 | #include <qlineedit.h> |
33 | #include <qvalidator.h> | 33 | #include <qvalidator.h> |
34 | #include <kdebug.h> | 34 | #include <kdebug.h> |
35 | #include <knotifyclient.h> | 35 | #include <knotifyclient.h> |
36 | #include "kdatetbl.h" | 36 | #include "kdatetbl.h" |
37 | #include "kdateedit.h" | 37 | #include "kdateedit.h" |
38 | #include "kdatepicker.moc" | 38 | //#include "kdatepicker.moc" |
39 | 39 | ||
40 | 40 | ||
41 | KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) | 41 | KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) |
42 | : QFrame(parent,name), | 42 | : QFrame(parent,name), |
43 | yearForward(new QToolButton(this)), | 43 | yearForward(new QToolButton(this)), |
44 | yearBackward(new QToolButton(this)), | 44 | yearBackward(new QToolButton(this)), |
45 | monthForward(new QToolButton(this)), | 45 | monthForward(new QToolButton(this)), |
46 | monthBackward(new QToolButton(this)), | 46 | monthBackward(new QToolButton(this)), |
47 | selectMonth(new QToolButton(this)), | 47 | selectMonth(new QToolButton(this)), |
48 | selectYear(new QToolButton(this)), | 48 | selectYear(new QToolButton(this)), |
49 | //line(new QLineEdit(this)), | 49 | //line(new QLineEdit(this)), |
50 | val(new KDateValidator(this)) | 50 | val(new KDateValidator(this)) |
51 | //table(new KDateTable(this)), | 51 | //table(new KDateTable(this)), |
52 | //fontsize(1) | 52 | //fontsize(1) |
53 | { | 53 | { |
54 | // ----- | 54 | // ----- |
55 | int size = 12; | 55 | int size = 12; |
56 | if ( QApplication::desktop()->width() >= 480 ) | 56 | if ( QApplication::desktop()->width() >= 480 ) |
57 | size = 18; | 57 | size = 18; |
58 | fontsize = size; | 58 | fontsize = size; |
59 | setFont ( QFont("helvetica",size) ); | 59 | setFont ( QFont("helvetica",size) ); |
60 | table = new KDateTable(this); | 60 | table = new KDateTable(this); |
61 | setFontSize(size); | 61 | setFontSize(size); |
62 | //line->setValidator(val); | 62 | //line->setValidator(val); |
63 | lineDate = new KDateEdit( this, "dateediipicker", true ); | 63 | lineDate = new KDateEdit( this, "dateediipicker", true ); |
64 | yearForward->setPixmap(SmallIcon("2rightarrowB")); | 64 | yearForward->setPixmap(SmallIcon("2rightarrowB")); |
65 | yearBackward->setPixmap(SmallIcon("2leftarrowB")); | 65 | yearBackward->setPixmap(SmallIcon("2leftarrowB")); |
66 | monthForward->setPixmap(SmallIcon("1rightarrowB")); | 66 | monthForward->setPixmap(SmallIcon("1rightarrowB")); |
67 | monthBackward->setPixmap(SmallIcon("1leftarrowB")); | 67 | monthBackward->setPixmap(SmallIcon("1leftarrowB")); |
68 | 68 | ||
69 | setDate(dt); // set button texts | 69 | setDate(dt); // set button texts |
70 | connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); | 70 | connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); |
71 | connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); | 71 | connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); |
72 | connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); | 72 | connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); |
73 | connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); | 73 | connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); |
74 | connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); | 74 | connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); |
75 | connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); | 75 | connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); |
76 | connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); | 76 | connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); |
77 | connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); | 77 | connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); |
78 | //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); | 78 | //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); |
79 | connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); | 79 | connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); |
80 | connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); | 80 | connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); |
81 | table->setFocus(); | 81 | table->setFocus(); |
82 | 82 | ||
83 | } | 83 | } |
84 | 84 | ||
85 | KDatePicker::~KDatePicker() | 85 | KDatePicker::~KDatePicker() |
86 | { | 86 | { |
87 | } | 87 | } |
88 | 88 | ||
89 | void | 89 | void |
90 | KDatePicker::resizeEvent(QResizeEvent*) | 90 | KDatePicker::resizeEvent(QResizeEvent*) |
91 | { | 91 | { |
92 | QWidget *buttons[] = { | 92 | QWidget *buttons[] = { |
93 | yearBackward, | 93 | yearBackward, |
94 | monthBackward, | 94 | monthBackward, |
95 | selectMonth, | 95 | selectMonth, |
96 | selectYear, | 96 | selectYear, |
97 | monthForward, | 97 | monthForward, |
98 | yearForward }; | 98 | yearForward }; |
99 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); | 99 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); |
100 | QSize sizes[NoOfButtons]; | 100 | QSize sizes[NoOfButtons]; |
101 | int buttonHeight=0; | 101 | int buttonHeight=0; |
102 | int count; | 102 | int count; |
103 | int w; | 103 | int w; |
104 | int x=0; | 104 | int x=0; |
105 | // ----- calculate button row height: | 105 | // ----- calculate button row height: |
106 | for(count=0; count<NoOfButtons; ++count) { | 106 | for(count=0; count<NoOfButtons; ++count) { |
107 | int xS = buttons[count]->sizeHint().width(); | 107 | int xS = buttons[count]->sizeHint().width(); |
108 | int yS = buttons[count]->sizeHint().height(); | 108 | int yS = buttons[count]->sizeHint().height(); |
109 | sizes[count]=QSize ( xS+10, yS ); | 109 | sizes[count]=QSize ( xS+10, yS ); |
110 | buttonHeight=QMAX(buttonHeight, sizes[count].height()); | 110 | buttonHeight=QMAX(buttonHeight, sizes[count].height()); |
111 | } | 111 | } |
112 | buttonHeight += 10; | 112 | buttonHeight += 10; |
113 | // ----- calculate size of the month button: | 113 | // ----- calculate size of the month button: |
114 | w=0; | 114 | w=0; |
115 | for(count=0; count<NoOfButtons; ++count) { | 115 | for(count=0; count<NoOfButtons; ++count) { |
116 | if(buttons[count]!=selectMonth) | 116 | if(buttons[count]!=selectMonth) |
117 | { | 117 | { |
118 | w+=sizes[count].width(); | 118 | w+=sizes[count].width(); |
119 | } else { | 119 | } else { |
120 | x=count; | 120 | x=count; |
121 | } | 121 | } |
122 | } | 122 | } |
123 | sizes[x].setWidth(width()-w); // stretch the month button | 123 | sizes[x].setWidth(width()-w); // stretch the month button |
124 | // ----- place the buttons: | 124 | // ----- place the buttons: |
125 | x=0; | 125 | x=0; |
126 | for(count=0; count<NoOfButtons; ++count) | 126 | for(count=0; count<NoOfButtons; ++count) |
127 | { | 127 | { |
128 | w=sizes[count].width(); | 128 | w=sizes[count].width(); |
129 | buttons[count]->setGeometry(x, 0, w, buttonHeight); | 129 | buttons[count]->setGeometry(x, 0, w, buttonHeight); |
130 | x+=w; | 130 | x+=w; |
131 | } | 131 | } |
132 | // ----- place the line edit for direct input: | 132 | // ----- place the line edit for direct input: |
133 | sizes[0]=lineDate->sizeHint(); | 133 | sizes[0]=lineDate->sizeHint(); |
134 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 134 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); |
135 | lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 135 | lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); |
136 | // ----- adjust the table: | 136 | // ----- adjust the table: |
137 | table->setGeometry(0, buttonHeight, width(), | 137 | table->setGeometry(0, buttonHeight, width(), |
138 | height()-buttonHeight-sizes[0].height()); | 138 | height()-buttonHeight-sizes[0].height()); |
139 | } | 139 | } |
140 | 140 | ||
141 | void | 141 | void |
142 | KDatePicker::dateChangedSlot(QDate date) | 142 | KDatePicker::dateChangedSlot(QDate date) |
143 | { | 143 | { |
144 | lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); | 144 | lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); |
145 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 145 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
146 | emit(dateChanged(date)); | 146 | emit(dateChanged(date)); |
147 | } | 147 | } |
148 | 148 | ||
149 | void | 149 | void |
150 | KDatePicker::tableClickedSlot() | 150 | KDatePicker::tableClickedSlot() |
151 | { | 151 | { |
152 | 152 | ||
153 | emit(dateSelected(table->getDate())); | 153 | emit(dateSelected(table->getDate())); |
154 | emit(tableClicked()); | 154 | emit(tableClicked()); |
155 | } | 155 | } |
156 | 156 | ||
157 | const QDate& | 157 | const QDate& |
158 | KDatePicker::getDate() const | 158 | KDatePicker::getDate() const |
159 | { | 159 | { |
160 | return table->getDate(); | 160 | return table->getDate(); |
161 | } | 161 | } |
162 | 162 | ||
163 | const QDate & | 163 | const QDate & |
164 | KDatePicker::date() const | 164 | KDatePicker::date() const |
165 | { | 165 | { |
166 | return table->getDate(); | 166 | return table->getDate(); |
167 | } | 167 | } |
168 | 168 | ||
169 | void KDatePicker::slotSetDate( QDate date ) | 169 | void KDatePicker::slotSetDate( QDate date ) |
170 | { | 170 | { |
171 | 171 | ||
172 | if(date.isValid()) { | 172 | if(date.isValid()) { |
173 | QString temp; | 173 | QString temp; |
174 | // ----- | 174 | // ----- |
175 | table->setDate(date); | 175 | table->setDate(date); |
176 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); | 176 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); |
177 | temp.setNum(date.year()); | 177 | temp.setNum(date.year()); |
178 | selectYear->setText(temp); | 178 | selectYear->setText(temp); |
179 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 179 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
180 | lineDate->setDate( date ); | 180 | lineDate->setDate( date ); |
181 | } | 181 | } |
182 | 182 | ||
183 | } | 183 | } |
184 | bool | 184 | bool |
185 | KDatePicker::setDate(const QDate& date) | 185 | KDatePicker::setDate(const QDate& date) |
186 | { | 186 | { |
187 | table->setFocus(); | 187 | table->setFocus(); |
188 | if(date.isValid()) { | 188 | if(date.isValid()) { |
189 | QString temp; | 189 | QString temp; |
190 | // ----- | 190 | // ----- |
191 | table->setDate(date); | 191 | table->setDate(date); |
192 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); | 192 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); |
193 | temp.setNum(date.year()); | 193 | temp.setNum(date.year()); |
194 | selectYear->setText(temp); | 194 | selectYear->setText(temp); |
195 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 195 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
196 | lineDate->setDate( date ); | 196 | lineDate->setDate( date ); |
197 | return true; | 197 | return true; |
198 | } else { | 198 | } else { |
199 | 199 | ||
200 | return false; | 200 | return false; |
201 | } | 201 | } |
202 | 202 | ||
203 | 203 | ||
204 | } | 204 | } |
205 | 205 | ||
206 | void | 206 | void |
207 | KDatePicker::monthForwardClicked() | 207 | KDatePicker::monthForwardClicked() |
208 | { | 208 | { |
209 | QDate temp=table->getDate(); | 209 | QDate temp=table->getDate(); |
210 | int day=temp.day(); | 210 | int day=temp.day(); |
211 | // ----- | 211 | // ----- |
212 | if(temp.month()==12) { | 212 | if(temp.month()==12) { |
213 | temp.setYMD(temp.year()+1, 1, 1); | 213 | temp.setYMD(temp.year()+1, 1, 1); |
214 | } else { | 214 | } else { |
215 | temp.setYMD(temp.year(), temp.month()+1, 1); | 215 | temp.setYMD(temp.year(), temp.month()+1, 1); |
216 | } | 216 | } |
217 | if(temp.daysInMonth()<day) { | 217 | if(temp.daysInMonth()<day) { |
218 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); | 218 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); |
219 | } else { | 219 | } else { |
220 | temp.setYMD(temp.year(), temp.month(), day); | 220 | temp.setYMD(temp.year(), temp.month(), day); |
221 | } | 221 | } |
222 | // assert(temp.isValid()); | 222 | // assert(temp.isValid()); |
223 | setDate(temp); | 223 | setDate(temp); |
224 | } | 224 | } |
225 | 225 | ||
226 | void | 226 | void |
227 | KDatePicker::monthBackwardClicked() | 227 | KDatePicker::monthBackwardClicked() |
228 | { | 228 | { |
229 | QDate temp=table->getDate(); | 229 | QDate temp=table->getDate(); |
230 | int day=temp.day(); | 230 | int day=temp.day(); |
231 | // ----- | 231 | // ----- |
232 | if(temp.month()==1) | 232 | if(temp.month()==1) |
233 | { | 233 | { |
234 | temp.setYMD(temp.year()-1, 12, 1); | 234 | temp.setYMD(temp.year()-1, 12, 1); |
235 | } else { | 235 | } else { |
236 | temp.setYMD(temp.year(), temp.month()-1, 1); | 236 | temp.setYMD(temp.year(), temp.month()-1, 1); |
237 | } | 237 | } |
238 | if(temp.daysInMonth()<day) | 238 | if(temp.daysInMonth()<day) |
239 | { | 239 | { |
240 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); | 240 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); |
241 | } else { | 241 | } else { |
242 | temp.setYMD(temp.year(), temp.month(), day); | 242 | temp.setYMD(temp.year(), temp.month(), day); |
243 | } | 243 | } |
244 | // assert(temp.isValid()); | 244 | // assert(temp.isValid()); |
245 | setDate(temp); | 245 | setDate(temp); |
246 | } | 246 | } |
247 | 247 | ||
248 | void | 248 | void |
249 | KDatePicker::yearForwardClicked() | 249 | KDatePicker::yearForwardClicked() |
250 | { | 250 | { |
251 | QDate temp=table->getDate(); | 251 | QDate temp=table->getDate(); |
252 | int day=temp.day(); | 252 | int day=temp.day(); |
253 | // ----- | 253 | // ----- |
254 | temp.setYMD(temp.year()+1, temp.month(), 1); | 254 | temp.setYMD(temp.year()+1, temp.month(), 1); |
255 | if(temp.daysInMonth()<day) | 255 | if(temp.daysInMonth()<day) |
256 | { | 256 | { |
257 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); | 257 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); |
258 | } else { | 258 | } else { |
259 | temp.setYMD(temp.year(), temp.month(), day); | 259 | temp.setYMD(temp.year(), temp.month(), day); |
260 | } | 260 | } |
261 | // assert(temp.isValid()); | 261 | // assert(temp.isValid()); |
262 | setDate(temp); | 262 | setDate(temp); |
263 | } | 263 | } |
264 | 264 | ||
265 | void | 265 | void |
266 | KDatePicker::yearBackwardClicked() | 266 | KDatePicker::yearBackwardClicked() |
267 | { | 267 | { |
268 | QDate temp=table->getDate(); | 268 | QDate temp=table->getDate(); |
269 | int day=temp.day(); | 269 | int day=temp.day(); |
270 | // ----- | 270 | // ----- |
271 | temp.setYMD(temp.year()-1, temp.month(), 1); | 271 | temp.setYMD(temp.year()-1, temp.month(), 1); |
272 | if(temp.daysInMonth()<day) | 272 | if(temp.daysInMonth()<day) |
273 | { | 273 | { |
274 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); | 274 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); |
275 | } else { | 275 | } else { |
276 | temp.setYMD(temp.year(), temp.month(), day); | 276 | temp.setYMD(temp.year(), temp.month(), day); |
277 | } | 277 | } |
278 | // assert(temp.isValid()); | 278 | // assert(temp.isValid()); |
279 | setDate(temp); | 279 | setDate(temp); |
280 | } | 280 | } |
281 | 281 | ||
282 | void | 282 | void |
283 | KDatePicker::selectMonthClicked() | 283 | KDatePicker::selectMonthClicked() |
284 | { | 284 | { |
285 | int month; | 285 | int month; |
286 | KPopupFrame* popup = new KPopupFrame(this); | 286 | KPopupFrame* popup = new KPopupFrame(this); |
287 | KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(fontsize, popup); | 287 | KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(fontsize, popup); |
288 | // ----- | 288 | // ----- |
289 | picker->resize(picker->sizeHint()); | 289 | picker->resize(picker->sizeHint()); |
290 | popup->setMainWidget(picker); | 290 | popup->setMainWidget(picker); |
291 | picker->setFocus(); | 291 | picker->setFocus(); |
292 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); | 292 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); |
293 | if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height())))) | 293 | if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height())))) |
294 | { | 294 | { |
295 | QDate date; | 295 | QDate date; |
296 | int day; | 296 | int day; |
297 | // ----- | 297 | // ----- |
298 | month=picker->getResult(); | 298 | month=picker->getResult(); |
299 | date=table->getDate(); | 299 | date=table->getDate(); |
300 | day=date.day(); | 300 | day=date.day(); |
301 | // ----- construct a valid date in this month: | 301 | // ----- construct a valid date in this month: |
302 | date.setYMD(date.year(), month, 1); | 302 | date.setYMD(date.year(), month, 1); |
303 | date.setYMD(date.year(), month, QMIN(day, date.daysInMonth())); | 303 | date.setYMD(date.year(), month, QMIN(day, date.daysInMonth())); |
304 | // ----- set this month | 304 | // ----- set this month |
305 | setDate(date); | 305 | setDate(date); |
306 | } else { | 306 | } else { |
307 | KNotifyClient::beep(); | 307 | KNotifyClient::beep(); |
308 | } | 308 | } |
309 | delete popup; | 309 | delete popup; |
310 | } | 310 | } |
311 | 311 | ||
312 | void | 312 | void |
313 | KDatePicker::selectYearClicked() | 313 | KDatePicker::selectYearClicked() |
314 | { | 314 | { |
315 | int year; | 315 | int year; |
316 | KPopupFrame* popup = new KPopupFrame(this); | 316 | KPopupFrame* popup = new KPopupFrame(this); |
317 | KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup); | 317 | KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup); |
318 | // ----- | 318 | // ----- |
319 | picker->resize(picker->sizeHint()); | 319 | picker->resize(picker->sizeHint()); |
320 | popup->setMainWidget(picker); | 320 | popup->setMainWidget(picker); |
321 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); | 321 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); |
322 | picker->setFocus(); | 322 | picker->setFocus(); |
323 | if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height())))) | 323 | if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height())))) |
324 | { | 324 | { |
325 | QDate date; | 325 | QDate date; |
326 | int day; | 326 | int day; |
327 | // ----- | 327 | // ----- |
328 | year=picker->getYear(); | 328 | year=picker->getYear(); |
329 | date=table->getDate(); | 329 | date=table->getDate(); |
330 | day=date.day(); | 330 | day=date.day(); |
331 | // ----- construct a valid date in this month: | 331 | // ----- construct a valid date in this month: |
332 | date.setYMD(year, date.month(), 1); | 332 | date.setYMD(year, date.month(), 1); |
333 | date.setYMD(year, date.month(), QMIN(day, date.daysInMonth())); | 333 | date.setYMD(year, date.month(), QMIN(day, date.daysInMonth())); |
334 | // ----- set this month | 334 | // ----- set this month |
335 | setDate(date); | 335 | setDate(date); |
336 | } else { | 336 | } else { |
337 | KNotifyClient::beep(); | 337 | KNotifyClient::beep(); |
338 | } | 338 | } |
339 | delete popup; | 339 | delete popup; |
340 | } | 340 | } |
341 | 341 | ||
342 | void | 342 | void |
343 | KDatePicker::setEnabled(bool enable) | 343 | KDatePicker::setEnabled(bool enable) |
344 | { | 344 | { |
345 | QWidget *widgets[]= { | 345 | QWidget *widgets[]= { |
346 | yearForward, yearBackward, monthForward, monthBackward, | 346 | yearForward, yearBackward, monthForward, monthBackward, |
347 | selectMonth, selectYear, | 347 | selectMonth, selectYear, |
348 | lineDate, table }; | 348 | lineDate, table }; |
349 | const int Size=sizeof(widgets)/sizeof(widgets[0]); | 349 | const int Size=sizeof(widgets)/sizeof(widgets[0]); |
350 | int count; | 350 | int count; |
351 | // ----- | 351 | // ----- |
352 | for(count=0; count<Size; ++count) | 352 | for(count=0; count<Size; ++count) |
353 | { | 353 | { |
354 | widgets[count]->setEnabled(enable); | 354 | widgets[count]->setEnabled(enable); |
355 | } | 355 | } |
356 | } | 356 | } |
357 | 357 | ||
358 | void | 358 | void |
359 | KDatePicker::lineEnterPressed() | 359 | KDatePicker::lineEnterPressed() |
360 | { | 360 | { |
361 | QDate temp; | 361 | QDate temp; |
362 | // ----- | 362 | // ----- |
363 | temp = lineDate->date(); | 363 | temp = lineDate->date(); |
364 | //if(val->date(line->text(), temp)==QValidator::Acceptable) | 364 | //if(val->date(line->text(), temp)==QValidator::Acceptable) |
365 | //{ | 365 | //{ |
366 | emit(dateEntered(temp)); | 366 | emit(dateEntered(temp)); |
367 | setDate(temp); | 367 | setDate(temp); |
368 | // } else { | 368 | // } else { |
369 | // KNotifyClient::beep(); | 369 | // KNotifyClient::beep(); |
370 | // } | 370 | // } |
371 | } | 371 | } |
372 | 372 | ||
373 | QSize | 373 | QSize |
374 | KDatePicker::sizeHint() const | 374 | KDatePicker::sizeHint() const |
375 | { | 375 | { |
376 | QSize tableSize=table->sizeHint(); | 376 | QSize tableSize=table->sizeHint(); |
377 | QWidget *buttons[]={ | 377 | QWidget *buttons[]={ |
378 | yearBackward, | 378 | yearBackward, |
379 | monthBackward, | 379 | monthBackward, |
380 | selectMonth, | 380 | selectMonth, |
381 | selectYear, | 381 | selectYear, |
382 | monthForward, | 382 | monthForward, |
383 | yearForward }; | 383 | yearForward }; |
384 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); | 384 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); |
385 | QSize sizes[NoOfButtons]; | 385 | QSize sizes[NoOfButtons]; |
386 | int cx=0, cy=0, count; | 386 | int cx=0, cy=0, count; |
387 | // ----- store the size hints: | 387 | // ----- store the size hints: |
388 | for(count=0; count<NoOfButtons; ++count) | 388 | for(count=0; count<NoOfButtons; ++count) |
389 | { | 389 | { |
390 | sizes[count]=buttons[count]->sizeHint(); | 390 | sizes[count]=buttons[count]->sizeHint(); |
391 | if(buttons[count]==selectMonth) | 391 | if(buttons[count]==selectMonth) |
392 | { | 392 | { |
393 | cx+=maxMonthRect.width()+15; | 393 | cx+=maxMonthRect.width()+15; |
394 | } else { | 394 | } else { |
395 | cx+=sizes[count].width()+15; | 395 | cx+=sizes[count].width()+15; |
396 | } | 396 | } |
397 | cy=QMAX(sizes[count].height(), cy); | 397 | cy=QMAX(sizes[count].height(), cy); |
398 | } | 398 | } |
399 | // ----- calculate width hint: | 399 | // ----- calculate width hint: |
400 | cx=QMAX(cx, tableSize.width()); // line edit ignored | 400 | cx=QMAX(cx, tableSize.width()); // line edit ignored |
401 | if ( cx > QApplication::desktop()->width() -5 ) | 401 | if ( cx > QApplication::desktop()->width() -5 ) |
402 | cx = QApplication::desktop()->width() -5; | 402 | cx = QApplication::desktop()->width() -5; |
403 | // ----- calculate height hint: | 403 | // ----- calculate height hint: |
404 | cy+=tableSize.height()+lineDate->sizeHint().height(); | 404 | cy+=tableSize.height()+lineDate->sizeHint().height(); |
405 | 405 | ||
406 | return QSize(cx, cy); | 406 | return QSize(cx, cy); |
407 | } | 407 | } |
408 | 408 | ||
409 | void | 409 | void |
410 | KDatePicker::setFontSize(int s) | 410 | KDatePicker::setFontSize(int s) |
411 | { | 411 | { |
412 | QWidget *buttons[]= { | 412 | QWidget *buttons[]= { |
413 | // yearBackward, | 413 | // yearBackward, |
414 | // monthBackward, | 414 | // monthBackward, |
415 | selectMonth, | 415 | selectMonth, |
416 | selectYear, | 416 | selectYear, |
417 | // monthForward, | 417 | // monthForward, |
418 | // yearForward | 418 | // yearForward |
419 | }; | 419 | }; |
420 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); | 420 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); |
421 | int count; | 421 | int count; |
422 | QFont font; | 422 | QFont font; |
423 | QRect r; | 423 | QRect r; |
424 | // ----- | 424 | // ----- |
425 | fontsize=s; | 425 | fontsize=s; |
426 | for(count=0; count<NoOfButtons; ++count) | 426 | for(count=0; count<NoOfButtons; ++count) |
427 | { | 427 | { |
428 | font=buttons[count]->font(); | 428 | font=buttons[count]->font(); |
429 | font.setPointSize(s); | 429 | font.setPointSize(s); |
430 | buttons[count]->setFont(font); | 430 | buttons[count]->setFont(font); |
431 | } | 431 | } |
432 | QFontMetrics metrics(selectMonth->fontMetrics()); | 432 | QFontMetrics metrics(selectMonth->fontMetrics()); |
433 | for(int i=1; i <= 12; ++i) | 433 | for(int i=1; i <= 12; ++i) |
434 | { // maxMonthRect is used by sizeHint() | 434 | { // maxMonthRect is used by sizeHint() |
435 | r=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); | 435 | r=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); |
436 | maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width())); | 436 | maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width())); |
437 | maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height())); | 437 | maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height())); |
438 | } | 438 | } |
439 | table->setFontSize(s); | 439 | table->setFontSize(s); |
440 | } | 440 | } |
441 | 441 | ||
442 | void KDatePicker::virtual_hook( int id, void* data ) | 442 | void KDatePicker::virtual_hook( int id, void* data ) |
443 | { /*BASE::virtual_hook( id, data );*/ } | 443 | { /*BASE::virtual_hook( id, data );*/ } |
444 | 444 | ||
445 | void KDatePicker::keyPressEvent ( QKeyEvent * e ) | 445 | void KDatePicker::keyPressEvent ( QKeyEvent * e ) |
446 | { | 446 | { |
447 | switch ( e->key() ) { | 447 | switch ( e->key() ) { |
448 | case Qt::Key_Right: | 448 | case Qt::Key_Right: |
449 | monthForwardClicked(); | 449 | monthForwardClicked(); |
450 | break; | 450 | break; |
451 | case Qt::Key_Left: | 451 | case Qt::Key_Left: |
452 | monthBackwardClicked(); | 452 | monthBackwardClicked(); |
453 | break; | 453 | break; |
454 | 454 | ||
455 | case Qt::Key_Down: | 455 | case Qt::Key_Down: |
456 | yearForwardClicked(); | 456 | yearForwardClicked(); |
457 | 457 | ||
458 | break; | 458 | break; |
459 | 459 | ||
460 | case Qt::Key_Up: | 460 | case Qt::Key_Up: |
461 | yearBackwardClicked(); | 461 | yearBackwardClicked(); |
462 | break; | 462 | break; |
463 | 463 | ||
464 | case Qt::Key_Return: | 464 | case Qt::Key_Return: |
465 | tableClickedSlot(); | 465 | tableClickedSlot(); |
466 | break; | 466 | break; |
467 | 467 | ||
468 | default: | 468 | default: |
469 | break; | 469 | break; |
470 | } | 470 | } |
471 | 471 | ||
472 | } | 472 | } |