summaryrefslogtreecommitdiffabout
path: root/libkdepim/kdatepicker.cpp
Unidiff
Diffstat (limited to 'libkdepim/kdatepicker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kdatepicker.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp
index 68ef943..28b65cf 100644
--- a/libkdepim/kdatepicker.cpp
+++ b/libkdepim/kdatepicker.cpp
@@ -1,139 +1,143 @@
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 <q3frame.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//Added by qt3to4:
35#include <QResizeEvent>
36#include <QKeyEvent>
37#include <QDesktopWidget>
34#include <kdebug.h> 38#include <kdebug.h>
35#include <knotifyclient.h> 39#include <knotifyclient.h>
36#include <kglobalsettings.h> 40#include <kglobalsettings.h>
37#include "kdatetbl.h" 41#include "kdatetbl.h"
38#include "kdateedit.h" 42#include "kdateedit.h"
39//#include "kdatepicker.moc" 43//#include "kdatepicker.moc"
40 44
41 45
42KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) 46KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name)
43 : QFrame(parent,name), 47 : Q3Frame(parent,name),
44 yearForward(new QToolButton(this)), 48 yearForward(new QToolButton(this)),
45 yearBackward(new QToolButton(this)), 49 yearBackward(new QToolButton(this)),
46 monthForward(new QToolButton(this)), 50 monthForward(new QToolButton(this)),
47 monthBackward(new QToolButton(this)), 51 monthBackward(new QToolButton(this)),
48 selectMonth(new QToolButton(this)), 52 selectMonth(new QToolButton(this)),
49 selectYear(new QToolButton(this)), 53 selectYear(new QToolButton(this)),
50 todayBut(new QToolButton(this)), 54 todayBut(new QToolButton(this)),
51 //line(new QLineEdit(this)), 55 //line(new QLineEdit(this)),
52 val(new KDateValidator(this)) 56 val(new KDateValidator(this))
53 //table(new KDateTable(this)), 57 //table(new KDateTable(this)),
54 //fontsize(1) 58 //fontsize(1)
55{ 59{
56 QFont fo = KGlobalSettings::generalFont(); 60 QFont fo = KGlobalSettings::generalFont();
57 int add = 2; 61 int add = 2;
58 if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) 62 if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 )
59 add += 4; 63 add += 4;
60 fo.setPointSize(fo.pointSize()+add ); 64 fo.setPointSize(fo.pointSize()+add );
61 setFont( fo ); 65 setFont( fo );
62 table = new KDateTable(this); 66 table = new KDateTable(this);
63 setFontSize(font().pointSize()); 67 setFontSize(font().pointSize());
64 //line->setValidator(val); 68 //line->setValidator(val);
65 lineDate = new KDateEdit( this, "dateediipicker", true ); 69 lineDate = new KDateEdit( this, "dateediipicker", true );
66 yearForward->setPixmap(SmallIcon("3rightarrowB")); 70 yearForward->setPixmap(SmallIcon("3rightarrowB"));
67 yearBackward->setPixmap(SmallIcon("3leftarrowB")); 71 yearBackward->setPixmap(SmallIcon("3leftarrowB"));
68 monthForward->setPixmap(SmallIcon("2rightarrowB")); 72 monthForward->setPixmap(SmallIcon("2rightarrowB"));
69 monthBackward->setPixmap(SmallIcon("2leftarrowB")); 73 monthBackward->setPixmap(SmallIcon("2leftarrowB"));
70 todayBut->setPixmap(SmallIcon("today")); 74 todayBut->setPixmap(SmallIcon("today"));
71 setDate(dt); // set button texts 75 setDate(dt); // set button texts
72 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); 76 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate)));
73 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); 77 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot()));
74 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); 78 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked()));
75 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); 79 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()));
76 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); 80 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked()));
77 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); 81 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked()));
78 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); 82 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked()));
79 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); 83 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked()));
80 connect(todayBut, SIGNAL(clicked()), SLOT(goToday())); 84 connect(todayBut, SIGNAL(clicked()), SLOT(goToday()));
81 //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); 85 //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
82 connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); 86 connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate)));
83 connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); 87 connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
84 table->setFocus(); 88 table->setFocus();
85 89
86} 90}
87 91
88KDatePicker::~KDatePicker() 92KDatePicker::~KDatePicker()
89{ 93{
90} 94}
91 95
92void 96void
93KDatePicker::resizeEvent(QResizeEvent*) 97KDatePicker::resizeEvent(QResizeEvent*)
94{ 98{
95 QWidget *buttons[] = { 99 QWidget *buttons[] = {
96 yearBackward, 100 yearBackward,
97 monthBackward, 101 monthBackward,
98 selectMonth, 102 selectMonth,
99 selectYear, 103 selectYear,
100 monthForward, 104 monthForward,
101 yearForward }; 105 yearForward };
102 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); 106 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
103 QSize sizes[NoOfButtons]; 107 QSize sizes[NoOfButtons];
104 int buttonHeight=0; 108 int buttonHeight=0;
105 int count; 109 int count;
106 int w; 110 int w;
107 int x=0; 111 int x=0;
108 // ----- calculate button row height: 112 // ----- calculate button row height:
109 for(count=0; count<NoOfButtons; ++count) { 113 for(count=0; count<NoOfButtons; ++count) {
110 int xS = buttons[count]->sizeHint().width(); 114 int xS = buttons[count]->sizeHint().width();
111 int yS = buttons[count]->sizeHint().height(); 115 int yS = buttons[count]->sizeHint().height();
112 if ( QApplication::desktop()->width() < 320 ) 116 if ( QApplication::desktop()->width() < 320 )
113 sizes[count]=QSize ( xS+4, yS ); 117 sizes[count]=QSize ( xS+4, yS );
114 else 118 else
115 sizes[count]=QSize ( xS+10, yS ); 119 sizes[count]=QSize ( xS+10, yS );
116 120
117 buttonHeight=QMAX(buttonHeight, sizes[count].height()); 121 buttonHeight=QMAX(buttonHeight, sizes[count].height());
118 } 122 }
119 buttonHeight += 10; 123 buttonHeight += 10;
120 // ----- calculate size of the month button: 124 // ----- calculate size of the month button:
121 w=0; 125 w=0;
122 for(count=0; count<NoOfButtons; ++count) { 126 for(count=0; count<NoOfButtons; ++count) {
123 if(buttons[count]!=selectMonth) 127 if(buttons[count]!=selectMonth)
124 { 128 {
125 w+=sizes[count].width(); 129 w+=sizes[count].width();
126 } else { 130 } else {
127 x=count; 131 x=count;
128 } 132 }
129 } 133 }
130 sizes[x].setWidth(width()-w); // stretch the month button 134 sizes[x].setWidth(width()-w); // stretch the month button
131 // ----- place the buttons: 135 // ----- place the buttons:
132 x=0; 136 x=0;
133 for(count=0; count<NoOfButtons; ++count) 137 for(count=0; count<NoOfButtons; ++count)
134 { 138 {
135 w=sizes[count].width(); 139 w=sizes[count].width();
136 buttons[count]->setGeometry(x, 0, w, buttonHeight); 140 buttons[count]->setGeometry(x, 0, w, buttonHeight);
137 x+=w; 141 x+=w;
138 } 142 }
139 // ----- place the line edit for direct input: 143 // ----- place the line edit for direct input: