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