-rw-r--r-- | libkdepim/kdatepicker.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp index d6e9b51..c13734f 100644 --- a/libkdepim/kdatepicker.cpp +++ b/libkdepim/kdatepicker.cpp | |||
@@ -1,252 +1,254 @@ | |||
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 <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 | ||
42 | KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) | 42 | KDatePicker::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 | QFont fo = KGlobalSettings::generalFont(); |
56 | table = new KDateTable(this); | ||
57 | int add = 2; | 56 | int add = 2; |
58 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) | 57 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) |
59 | add += 4; | 58 | add += 4; |
60 | setFontSize(font().pointSize()+add); | 59 | fo.setPointSize(fo.pointSize()+add ); |
60 | setFont( fo ); | ||
61 | table = new KDateTable(this); | ||
62 | setFontSize(font().pointSize()); | ||
61 | //line->setValidator(val); | 63 | //line->setValidator(val); |
62 | lineDate = new KDateEdit( this, "dateediipicker", true ); | 64 | lineDate = new KDateEdit( this, "dateediipicker", true ); |
63 | yearForward->setPixmap(SmallIcon("2rightarrowB")); | 65 | yearForward->setPixmap(SmallIcon("2rightarrowB")); |
64 | yearBackward->setPixmap(SmallIcon("2leftarrowB")); | 66 | yearBackward->setPixmap(SmallIcon("2leftarrowB")); |
65 | monthForward->setPixmap(SmallIcon("1rightarrowB")); | 67 | monthForward->setPixmap(SmallIcon("1rightarrowB")); |
66 | monthBackward->setPixmap(SmallIcon("1leftarrowB")); | 68 | monthBackward->setPixmap(SmallIcon("1leftarrowB")); |
67 | setDate(dt); // set button texts | 69 | setDate(dt); // set button texts |
68 | connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); | 70 | connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); |
69 | connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); | 71 | connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); |
70 | connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); | 72 | connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); |
71 | connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); | 73 | connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); |
72 | connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); | 74 | connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); |
73 | connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); | 75 | connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); |
74 | connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); | 76 | connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); |
75 | connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); | 77 | connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); |
76 | //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); | 78 | //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); |
77 | connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); | 79 | connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); |
78 | connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); | 80 | connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); |
79 | table->setFocus(); | 81 | table->setFocus(); |
80 | 82 | ||
81 | } | 83 | } |
82 | 84 | ||
83 | KDatePicker::~KDatePicker() | 85 | KDatePicker::~KDatePicker() |
84 | { | 86 | { |
85 | } | 87 | } |
86 | 88 | ||
87 | void | 89 | void |
88 | KDatePicker::resizeEvent(QResizeEvent*) | 90 | KDatePicker::resizeEvent(QResizeEvent*) |
89 | { | 91 | { |
90 | QWidget *buttons[] = { | 92 | QWidget *buttons[] = { |
91 | yearBackward, | 93 | yearBackward, |
92 | monthBackward, | 94 | monthBackward, |
93 | selectMonth, | 95 | selectMonth, |
94 | selectYear, | 96 | selectYear, |
95 | monthForward, | 97 | monthForward, |
96 | yearForward }; | 98 | yearForward }; |
97 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); | 99 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); |
98 | QSize sizes[NoOfButtons]; | 100 | QSize sizes[NoOfButtons]; |
99 | int buttonHeight=0; | 101 | int buttonHeight=0; |
100 | int count; | 102 | int count; |
101 | int w; | 103 | int w; |
102 | int x=0; | 104 | int x=0; |
103 | // ----- calculate button row height: | 105 | // ----- calculate button row height: |
104 | for(count=0; count<NoOfButtons; ++count) { | 106 | for(count=0; count<NoOfButtons; ++count) { |
105 | int xS = buttons[count]->sizeHint().width(); | 107 | int xS = buttons[count]->sizeHint().width(); |
106 | int yS = buttons[count]->sizeHint().height(); | 108 | int yS = buttons[count]->sizeHint().height(); |
107 | if ( QApplication::desktop()->width() < 320 ) | 109 | if ( QApplication::desktop()->width() < 320 ) |
108 | sizes[count]=QSize ( xS+4, yS ); | 110 | sizes[count]=QSize ( xS+4, yS ); |
109 | else | 111 | else |
110 | sizes[count]=QSize ( xS+10, yS ); | 112 | sizes[count]=QSize ( xS+10, yS ); |
111 | 113 | ||
112 | buttonHeight=QMAX(buttonHeight, sizes[count].height()); | 114 | buttonHeight=QMAX(buttonHeight, sizes[count].height()); |
113 | } | 115 | } |
114 | buttonHeight += 10; | 116 | buttonHeight += 10; |
115 | // ----- calculate size of the month button: | 117 | // ----- calculate size of the month button: |
116 | w=0; | 118 | w=0; |
117 | for(count=0; count<NoOfButtons; ++count) { | 119 | for(count=0; count<NoOfButtons; ++count) { |
118 | if(buttons[count]!=selectMonth) | 120 | if(buttons[count]!=selectMonth) |
119 | { | 121 | { |
120 | w+=sizes[count].width(); | 122 | w+=sizes[count].width(); |
121 | } else { | 123 | } else { |
122 | x=count; | 124 | x=count; |
123 | } | 125 | } |
124 | } | 126 | } |
125 | sizes[x].setWidth(width()-w); // stretch the month button | 127 | sizes[x].setWidth(width()-w); // stretch the month button |
126 | // ----- place the buttons: | 128 | // ----- place the buttons: |
127 | x=0; | 129 | x=0; |
128 | for(count=0; count<NoOfButtons; ++count) | 130 | for(count=0; count<NoOfButtons; ++count) |
129 | { | 131 | { |
130 | w=sizes[count].width(); | 132 | w=sizes[count].width(); |
131 | buttons[count]->setGeometry(x, 0, w, buttonHeight); | 133 | buttons[count]->setGeometry(x, 0, w, buttonHeight); |
132 | x+=w; | 134 | x+=w; |
133 | } | 135 | } |
134 | // ----- place the line edit for direct input: | 136 | // ----- place the line edit for direct input: |
135 | sizes[0]=lineDate->sizeHint(); | 137 | sizes[0]=lineDate->sizeHint(); |
136 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 138 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); |
137 | lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 139 | lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); |
138 | // ----- adjust the table: | 140 | // ----- adjust the table: |
139 | table->setGeometry(0, buttonHeight, width(), | 141 | table->setGeometry(0, buttonHeight, width(), |
140 | height()-buttonHeight-sizes[0].height()); | 142 | height()-buttonHeight-sizes[0].height()); |
141 | } | 143 | } |
142 | 144 | ||
143 | void | 145 | void |
144 | KDatePicker::dateChangedSlot(QDate date) | 146 | KDatePicker::dateChangedSlot(QDate date) |
145 | { | 147 | { |
146 | lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); | 148 | lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); |
147 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 149 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
148 | emit(dateChanged(date)); | 150 | emit(dateChanged(date)); |
149 | } | 151 | } |
150 | 152 | ||
151 | void | 153 | void |
152 | KDatePicker::tableClickedSlot() | 154 | KDatePicker::tableClickedSlot() |
153 | { | 155 | { |
154 | 156 | ||
155 | emit(dateSelected(table->getDate())); | 157 | emit(dateSelected(table->getDate())); |
156 | emit(tableClicked()); | 158 | emit(tableClicked()); |
157 | } | 159 | } |
158 | 160 | ||
159 | const QDate& | 161 | const QDate& |
160 | KDatePicker::getDate() const | 162 | KDatePicker::getDate() const |
161 | { | 163 | { |
162 | return table->getDate(); | 164 | return table->getDate(); |
163 | } | 165 | } |
164 | 166 | ||
165 | const QDate & | 167 | const QDate & |
166 | KDatePicker::date() const | 168 | KDatePicker::date() const |
167 | { | 169 | { |
168 | return table->getDate(); | 170 | return table->getDate(); |
169 | } | 171 | } |
170 | 172 | ||
171 | void KDatePicker::slotSetDate( QDate date ) | 173 | void KDatePicker::slotSetDate( QDate date ) |
172 | { | 174 | { |
173 | 175 | ||
174 | if(date.isValid()) { | 176 | if(date.isValid()) { |
175 | QString temp; | 177 | QString temp; |
176 | // ----- | 178 | // ----- |
177 | table->setDate(date); | 179 | table->setDate(date); |
178 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); | 180 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); |
179 | temp.setNum(date.year()); | 181 | temp.setNum(date.year()); |
180 | selectYear->setText(temp); | 182 | selectYear->setText(temp); |
181 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 183 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
182 | lineDate->setDate( date ); | 184 | lineDate->setDate( date ); |
183 | } | 185 | } |
184 | 186 | ||
185 | } | 187 | } |
186 | bool | 188 | bool |
187 | KDatePicker::setDate(const QDate& date) | 189 | KDatePicker::setDate(const QDate& date) |
188 | { | 190 | { |
189 | table->setFocus(); | 191 | table->setFocus(); |
190 | if(date.isValid()) { | 192 | if(date.isValid()) { |
191 | QString temp; | 193 | QString temp; |
192 | // ----- | 194 | // ----- |
193 | table->setDate(date); | 195 | table->setDate(date); |
194 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); | 196 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); |
195 | temp.setNum(date.year()); | 197 | temp.setNum(date.year()); |
196 | selectYear->setText(temp); | 198 | selectYear->setText(temp); |
197 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 199 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
198 | lineDate->setDate( date ); | 200 | lineDate->setDate( date ); |
199 | return true; | 201 | return true; |
200 | } else { | 202 | } else { |
201 | 203 | ||
202 | return false; | 204 | return false; |
203 | } | 205 | } |
204 | 206 | ||
205 | 207 | ||
206 | } | 208 | } |
207 | 209 | ||
208 | void | 210 | void |
209 | KDatePicker::monthForwardClicked() | 211 | KDatePicker::monthForwardClicked() |
210 | { | 212 | { |
211 | QDate temp=table->getDate(); | 213 | QDate temp=table->getDate(); |
212 | int day=temp.day(); | 214 | int day=temp.day(); |
213 | // ----- | 215 | // ----- |
214 | if(temp.month()==12) { | 216 | if(temp.month()==12) { |
215 | temp.setYMD(temp.year()+1, 1, 1); | 217 | temp.setYMD(temp.year()+1, 1, 1); |
216 | } else { | 218 | } else { |
217 | temp.setYMD(temp.year(), temp.month()+1, 1); | 219 | temp.setYMD(temp.year(), temp.month()+1, 1); |
218 | } | 220 | } |
219 | if(temp.daysInMonth()<day) { | 221 | if(temp.daysInMonth()<day) { |
220 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); | 222 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); |
221 | } else { | 223 | } else { |
222 | temp.setYMD(temp.year(), temp.month(), day); | 224 | temp.setYMD(temp.year(), temp.month(), day); |
223 | } | 225 | } |
224 | // assert(temp.isValid()); | 226 | // assert(temp.isValid()); |
225 | setDate(temp); | 227 | setDate(temp); |
226 | } | 228 | } |
227 | 229 | ||
228 | void | 230 | void |
229 | KDatePicker::monthBackwardClicked() | 231 | KDatePicker::monthBackwardClicked() |
230 | { | 232 | { |
231 | QDate temp=table->getDate(); | 233 | QDate temp=table->getDate(); |
232 | int day=temp.day(); | 234 | int day=temp.day(); |
233 | // ----- | 235 | // ----- |
234 | if(temp.month()==1) | 236 | if(temp.month()==1) |
235 | { | 237 | { |
236 | temp.setYMD(temp.year()-1, 12, 1); | 238 | temp.setYMD(temp.year()-1, 12, 1); |
237 | } else { | 239 | } else { |
238 | temp.setYMD(temp.year(), temp.month()-1, 1); | 240 | temp.setYMD(temp.year(), temp.month()-1, 1); |
239 | } | 241 | } |
240 | if(temp.daysInMonth()<day) | 242 | if(temp.daysInMonth()<day) |
241 | { | 243 | { |
242 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); | 244 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); |
243 | } else { | 245 | } else { |
244 | temp.setYMD(temp.year(), temp.month(), day); | 246 | temp.setYMD(temp.year(), temp.month(), day); |
245 | } | 247 | } |
246 | // assert(temp.isValid()); | 248 | // assert(temp.isValid()); |
247 | setDate(temp); | 249 | setDate(temp); |
248 | } | 250 | } |
249 | 251 | ||
250 | void | 252 | void |
251 | KDatePicker::yearForwardClicked() | 253 | KDatePicker::yearForwardClicked() |
252 | { | 254 | { |