summaryrefslogtreecommitdiffabout
path: root/libkdepim/kdatepicker.cpp
authorzautrix <zautrix>2005-02-08 16:24:18 (UTC)
committer zautrix <zautrix>2005-02-08 16:24:18 (UTC)
commit78c70cfbbe79243d8b0ec40f8f6438c99046e12b (patch) (unidiff)
tree382bc11ad3b56f72b8f84414e1da5e5ea871204b /libkdepim/kdatepicker.cpp
parent584ed7893497b2adad5ba6c3e914d90b76973b92 (diff)
downloadkdepimpi-78c70cfbbe79243d8b0ec40f8f6438c99046e12b.zip
kdepimpi-78c70cfbbe79243d8b0ec40f8f6438c99046e12b.tar.gz
kdepimpi-78c70cfbbe79243d8b0ec40f8f6438c99046e12b.tar.bz2
fix
Diffstat (limited to 'libkdepim/kdatepicker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kdatepicker.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp
index 2be9c9e..d6e9b51 100644
--- a/libkdepim/kdatepicker.cpp
+++ b/libkdepim/kdatepicker.cpp
@@ -9,97 +9,100 @@
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 <kglobalsettings.h> 36#include <kglobalsettings.h>
37#include "kdatetbl.h" 37#include "kdatetbl.h"
38#include "kdateedit.h" 38#include "kdateedit.h"
39//#include "kdatepicker.moc" 39//#include "kdatepicker.moc"
40 40
41 41
42KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) 42KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name)
43 : QFrame(parent,name), 43 : QFrame(parent,name),
44 yearForward(new QToolButton(this)), 44 yearForward(new QToolButton(this)),
45 yearBackward(new QToolButton(this)), 45 yearBackward(new QToolButton(this)),
46 monthForward(new QToolButton(this)), 46 monthForward(new QToolButton(this)),
47 monthBackward(new QToolButton(this)), 47 monthBackward(new QToolButton(this)),
48 selectMonth(new QToolButton(this)), 48 selectMonth(new QToolButton(this)),
49 selectYear(new QToolButton(this)), 49 selectYear(new QToolButton(this)),
50 //line(new QLineEdit(this)), 50 //line(new QLineEdit(this)),
51 val(new KDateValidator(this)) 51 val(new KDateValidator(this))
52 //table(new KDateTable(this)), 52 //table(new KDateTable(this)),
53 //fontsize(1) 53 //fontsize(1)
54{ 54{
55 setFont ( KGlobalSettings::generalFont() ); 55 setFont ( KGlobalSettings::generalFont() );
56 table = new KDateTable(this); 56 table = new KDateTable(this);
57 setFontSize(font().pointSize()+2); 57 int add = 2;
58 if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 )
59 add += 4;
60 setFontSize(font().pointSize()+add);
58 //line->setValidator(val); 61 //line->setValidator(val);
59 lineDate = new KDateEdit( this, "dateediipicker", true ); 62 lineDate = new KDateEdit( this, "dateediipicker", true );
60 yearForward->setPixmap(SmallIcon("2rightarrowB")); 63 yearForward->setPixmap(SmallIcon("2rightarrowB"));
61 yearBackward->setPixmap(SmallIcon("2leftarrowB")); 64 yearBackward->setPixmap(SmallIcon("2leftarrowB"));
62 monthForward->setPixmap(SmallIcon("1rightarrowB")); 65 monthForward->setPixmap(SmallIcon("1rightarrowB"));
63 monthBackward->setPixmap(SmallIcon("1leftarrowB")); 66 monthBackward->setPixmap(SmallIcon("1leftarrowB"));
64 setDate(dt); // set button texts 67 setDate(dt); // set button texts
65 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); 68 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate)));
66 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); 69 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot()));
67 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); 70 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked()));
68 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); 71 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()));
69 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); 72 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked()));
70 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); 73 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked()));
71 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); 74 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked()));
72 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); 75 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked()));
73 //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); 76 //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
74 connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); 77 connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate)));
75 connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); 78 connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
76 table->setFocus(); 79 table->setFocus();
77 80
78} 81}
79 82
80KDatePicker::~KDatePicker() 83KDatePicker::~KDatePicker()
81{ 84{
82} 85}
83 86
84void 87void
85KDatePicker::resizeEvent(QResizeEvent*) 88KDatePicker::resizeEvent(QResizeEvent*)
86{ 89{
87 QWidget *buttons[] = { 90 QWidget *buttons[] = {
88 yearBackward, 91 yearBackward,
89 monthBackward, 92 monthBackward,
90 selectMonth, 93 selectMonth,
91 selectYear, 94 selectYear,
92 monthForward, 95 monthForward,
93 yearForward }; 96 yearForward };
94 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); 97 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
95 QSize sizes[NoOfButtons]; 98 QSize sizes[NoOfButtons];
96 int buttonHeight=0; 99 int buttonHeight=0;
97 int count; 100 int count;
98 int w; 101 int w;
99 int x=0; 102 int x=0;
100 // ----- calculate button row height: 103 // ----- calculate button row height:
101 for(count=0; count<NoOfButtons; ++count) { 104 for(count=0; count<NoOfButtons; ++count) {
102 int xS = buttons[count]->sizeHint().width(); 105 int xS = buttons[count]->sizeHint().width();
103 int yS = buttons[count]->sizeHint().height(); 106 int yS = buttons[count]->sizeHint().height();
104 if ( QApplication::desktop()->width() < 320 ) 107 if ( QApplication::desktop()->width() < 320 )
105 sizes[count]=QSize ( xS+4, yS ); 108 sizes[count]=QSize ( xS+4, yS );
@@ -238,97 +241,97 @@ KDatePicker::monthBackwardClicked()
238 { 241 {
239 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 242 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
240 } else { 243 } else {
241 temp.setYMD(temp.year(), temp.month(), day); 244 temp.setYMD(temp.year(), temp.month(), day);
242 } 245 }
243 // assert(temp.isValid()); 246 // assert(temp.isValid());
244 setDate(temp); 247 setDate(temp);
245} 248}
246 249
247void 250void
248KDatePicker::yearForwardClicked() 251KDatePicker::yearForwardClicked()
249{ 252{
250 QDate temp=table->getDate(); 253 QDate temp=table->getDate();
251 int day=temp.day(); 254 int day=temp.day();
252 // ----- 255 // -----
253 temp.setYMD(temp.year()+1, temp.month(), 1); 256 temp.setYMD(temp.year()+1, temp.month(), 1);
254 if(temp.daysInMonth()<day) 257 if(temp.daysInMonth()<day)
255 { 258 {
256 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 259 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
257 } else { 260 } else {
258 temp.setYMD(temp.year(), temp.month(), day); 261 temp.setYMD(temp.year(), temp.month(), day);
259 } 262 }
260 // assert(temp.isValid()); 263 // assert(temp.isValid());
261 setDate(temp); 264 setDate(temp);
262} 265}
263 266
264void 267void
265KDatePicker::yearBackwardClicked() 268KDatePicker::yearBackwardClicked()
266{ 269{
267 QDate temp=table->getDate(); 270 QDate temp=table->getDate();
268 int day=temp.day(); 271 int day=temp.day();
269 // ----- 272 // -----
270 temp.setYMD(temp.year()-1, temp.month(), 1); 273 temp.setYMD(temp.year()-1, temp.month(), 1);
271 if(temp.daysInMonth()<day) 274 if(temp.daysInMonth()<day)
272 { 275 {
273 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 276 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
274 } else { 277 } else {
275 temp.setYMD(temp.year(), temp.month(), day); 278 temp.setYMD(temp.year(), temp.month(), day);
276 } 279 }
277 // assert(temp.isValid()); 280 // assert(temp.isValid());
278 setDate(temp); 281 setDate(temp);
279} 282}
280 283
281void 284void
282KDatePicker::selectMonthClicked() 285KDatePicker::selectMonthClicked()
283{ 286{
284 int month; 287 int month;
285 KPopupFrame* popup = new KPopupFrame(this); 288 KPopupFrame* popup = new KPopupFrame(this);
286 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(fontsize, popup); 289 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup);
287 // ----- 290 // -----
288 picker->resize(picker->sizeHint()); 291 picker->resize(picker->sizeHint());
289 popup->setMainWidget(picker); 292 popup->setMainWidget(picker);
290 picker->setFocus(); 293 picker->setFocus();
291 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 294 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
292 if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height())))) 295 if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height()))))
293 { 296 {
294 QDate date; 297 QDate date;
295 int day; 298 int day;
296 // ----- 299 // -----
297 month=picker->getResult(); 300 month=picker->getResult();
298 date=table->getDate(); 301 date=table->getDate();
299 day=date.day(); 302 day=date.day();
300 // ----- construct a valid date in this month: 303 // ----- construct a valid date in this month:
301 date.setYMD(date.year(), month, 1); 304 date.setYMD(date.year(), month, 1);
302 date.setYMD(date.year(), month, QMIN(day, date.daysInMonth())); 305 date.setYMD(date.year(), month, QMIN(day, date.daysInMonth()));
303 // ----- set this month 306 // ----- set this month
304 setDate(date); 307 setDate(date);
305 } else { 308 } else {
306 KNotifyClient::beep(); 309 KNotifyClient::beep();
307 } 310 }
308 delete popup; 311 delete popup;
309} 312}
310 313
311void 314void
312KDatePicker::selectYearClicked() 315KDatePicker::selectYearClicked()
313{ 316{
314 int year; 317 int year;
315 KPopupFrame* popup = new KPopupFrame(this); 318 KPopupFrame* popup = new KPopupFrame(this);
316 KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup); 319 KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup);
317 // ----- 320 // -----
318 picker->resize(picker->sizeHint()); 321 picker->resize(picker->sizeHint());
319 popup->setMainWidget(picker); 322 popup->setMainWidget(picker);
320 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 323 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
321 picker->setFocus(); 324 picker->setFocus();
322 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height())))) 325 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height()))))
323 { 326 {
324 QDate date; 327 QDate date;
325 int day; 328 int day;
326 // ----- 329 // -----
327 year=picker->getYear(); 330 year=picker->getYear();
328 date=table->getDate(); 331 date=table->getDate();
329 day=date.day(); 332 day=date.day();
330 // ----- construct a valid date in this month: 333 // ----- construct a valid date in this month:
331 date.setYMD(year, date.month(), 1); 334 date.setYMD(year, date.month(), 1);
332 date.setYMD(year, date.month(), QMIN(day, date.daysInMonth())); 335 date.setYMD(year, date.month(), QMIN(day, date.daysInMonth()));
333 // ----- set this month 336 // ----- set this month
334 setDate(date); 337 setDate(date);