-rw-r--r-- | libkdepim/kdateedit.cpp | 1 | ||||
-rw-r--r-- | microkde/kdialogbase.cpp | 7 |
2 files changed, 6 insertions, 2 deletions
diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp index 946fc0d..3d9e690 100644 --- a/libkdepim/kdateedit.cpp +++ b/libkdepim/kdateedit.cpp | |||
@@ -1,469 +1,470 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkdepim. | 2 | This file is part of libkdepim. |
3 | 3 | ||
4 | Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or | 8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | 9 | (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, | 11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. | 14 | GNU General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | 17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | 19 | ||
20 | As a special exception, permission is given to link this program | 20 | As a special exception, permission is given to link this program |
21 | with any edition of Qt, and distribute the resulting executable, | 21 | with any edition of Qt, and distribute the resulting executable, |
22 | without including the source code for Qt in the source distribution. | 22 | without including the source code for Qt in the source distribution. |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <qapplication.h> | 25 | #include <qapplication.h> |
26 | #include <qevent.h> | 26 | #include <qevent.h> |
27 | #include <qlineedit.h> | 27 | #include <qlineedit.h> |
28 | #include <qpixmap.h> | 28 | #include <qpixmap.h> |
29 | #include <qpushbutton.h> | 29 | #include <qpushbutton.h> |
30 | 30 | ||
31 | #include <kdatepicker.h> | 31 | #include <kdatepicker.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <kglobal.h> | 33 | #include <kglobal.h> |
34 | #include <kiconloader.h> | 34 | #include <kiconloader.h> |
35 | #include <klocale.h> | 35 | #include <klocale.h> |
36 | #include <kmessagebox.h> | 36 | #include <kmessagebox.h> |
37 | #include <knotifyclient.h> | 37 | #include <knotifyclient.h> |
38 | #include <qpalette.h> | 38 | #include <qpalette.h> |
39 | 39 | ||
40 | #include "kdateedit.h" | 40 | #include "kdateedit.h" |
41 | //#include "kdateedit.moc" | 41 | //#include "kdateedit.moc" |
42 | 42 | ||
43 | KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) | 43 | KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) |
44 | : QHBox(parent, name) | 44 | : QHBox(parent, name) |
45 | { | 45 | { |
46 | dateFormShort = true; | 46 | dateFormShort = true; |
47 | withoutDp = withoutDP; | 47 | withoutDp = withoutDP; |
48 | mDateEdit = new QLineEdit(this); | 48 | mDateEdit = new QLineEdit(this); |
49 | mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort)); | 49 | mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort)); |
50 | setFocusProxy(mDateEdit); | 50 | setFocusProxy(mDateEdit); |
51 | mDateEdit->installEventFilter(this); | 51 | mDateEdit->installEventFilter(this); |
52 | 52 | ||
53 | // Highlight Background and Textcolor | 53 | // Highlight Background and Textcolor |
54 | QPalette palette = QWidget::palette(); | 54 | QPalette palette = QWidget::palette(); |
55 | unsigned char red, green, blue; | 55 | unsigned char red, green, blue; |
56 | red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; | 56 | red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; |
57 | green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; | 57 | green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; |
58 | blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; | 58 | blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; |
59 | palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); | 59 | palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); |
60 | palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); | 60 | palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); |
61 | mDateEdit->setPalette( palette ); | 61 | mDateEdit->setPalette( palette ); |
62 | 62 | ||
63 | if ( withoutDP ) { | 63 | if ( withoutDP ) { |
64 | mDateFrame = 0; | 64 | mDateFrame = 0; |
65 | mDateButton = 0; | 65 | mDateButton = 0; |
66 | mDatePicker = 0; | 66 | mDatePicker = 0; |
67 | } else { | 67 | } else { |
68 | QPixmap pixmap = SmallIcon("smallcal"); | 68 | QPixmap pixmap = SmallIcon("smallcal"); |
69 | mDateButton = new QPushButton(this); | 69 | mDateButton = new QPushButton(this); |
70 | mDateButton->setPixmap(pixmap); | 70 | mDateButton->setPixmap(pixmap); |
71 | 71 | ||
72 | mDateFrame = new QVBox(0,0,WType_Popup); | 72 | mDateFrame = new QVBox(0,0,WType_Popup); |
73 | // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); | 73 | // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); |
74 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); | 74 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); |
75 | mDateFrame->setLineWidth(3); | 75 | mDateFrame->setLineWidth(3); |
76 | mDateFrame->hide(); | 76 | mDateFrame->hide(); |
77 | 77 | ||
78 | mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); | 78 | mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); |
79 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); | 79 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); |
80 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); | 80 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); |
81 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); | 81 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); |
82 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); | 82 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); |
83 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); | 83 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); |
84 | connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); | 84 | connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); |
85 | mDateButton->setFocusPolicy( QWidget::NoFocus ); | 85 | mDateButton->setFocusPolicy( QWidget::NoFocus ); |
86 | mDateButton->setAutoDefault( false ); | ||
86 | //mDateFrame->resize( 400, 300 ); | 87 | //mDateFrame->resize( 400, 300 ); |
87 | 88 | ||
88 | } | 89 | } |
89 | connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); | 90 | connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); |
90 | connect(mDateEdit,SIGNAL(textChanged(const QString &)), | 91 | connect(mDateEdit,SIGNAL(textChanged(const QString &)), |
91 | SLOT(textChanged(const QString &))); | 92 | SLOT(textChanged(const QString &))); |
92 | 93 | ||
93 | // Create the keyword list. This will be used to match against when the user | 94 | // Create the keyword list. This will be used to match against when the user |
94 | // enters information. | 95 | // enters information. |
95 | mKeywordMap[i18n("tomorrow")] = 1; | 96 | mKeywordMap[i18n("tomorrow")] = 1; |
96 | mKeywordMap[i18n("today")] = 0; | 97 | mKeywordMap[i18n("today")] = 0; |
97 | mKeywordMap[i18n("yesterday")] = -1; | 98 | mKeywordMap[i18n("yesterday")] = -1; |
98 | 99 | ||
99 | /* | 100 | /* |
100 | * This loop uses some math tricks to figure out the offset in days | 101 | * This loop uses some math tricks to figure out the offset in days |
101 | * to the next date the given day of the week occurs. There | 102 | * to the next date the given day of the week occurs. There |
102 | * are two cases, that the new day is >= the current day, which means | 103 | * are two cases, that the new day is >= the current day, which means |
103 | * the new day has not occured yet or that the new day < the current day, | 104 | * the new day has not occured yet or that the new day < the current day, |
104 | * which means the new day is already passed (so we need to find the | 105 | * which means the new day is already passed (so we need to find the |
105 | * day in the next week). | 106 | * day in the next week). |
106 | */ | 107 | */ |
107 | QString dayName; | 108 | QString dayName; |
108 | int currentDay = QDate::currentDate().dayOfWeek(); | 109 | int currentDay = QDate::currentDate().dayOfWeek(); |
109 | for (int i = 1; i <= 7; ++i) | 110 | for (int i = 1; i <= 7; ++i) |
110 | { | 111 | { |
111 | dayName = KGlobal::locale()->weekDayName(i).lower(); | 112 | dayName = KGlobal::locale()->weekDayName(i).lower(); |
112 | if (i >= currentDay) | 113 | if (i >= currentDay) |
113 | mKeywordMap[dayName] = i - currentDay; | 114 | mKeywordMap[dayName] = i - currentDay; |
114 | else | 115 | else |
115 | mKeywordMap[dayName] = 7 - currentDay + i; | 116 | mKeywordMap[dayName] = 7 - currentDay + i; |
116 | } | 117 | } |
117 | 118 | ||
118 | mTextChanged = false; | 119 | mTextChanged = false; |
119 | mHandleInvalid = false; | 120 | mHandleInvalid = false; |
120 | // QWidget::setTabOrder( mDateEdit, mDateButton ); | 121 | // QWidget::setTabOrder( mDateEdit, mDateButton ); |
121 | } | 122 | } |
122 | 123 | ||
123 | KDateEdit::~KDateEdit() | 124 | KDateEdit::~KDateEdit() |
124 | { | 125 | { |
125 | delete mDateFrame; | 126 | delete mDateFrame; |
126 | } | 127 | } |
127 | void KDateEdit::clear() | 128 | void KDateEdit::clear() |
128 | { | 129 | { |
129 | bool b = mDateEdit->signalsBlocked(); | 130 | bool b = mDateEdit->signalsBlocked(); |
130 | mDateEdit->blockSignals(true); | 131 | mDateEdit->blockSignals(true); |
131 | mDateEdit->setText(""); | 132 | mDateEdit->setText(""); |
132 | mDateEdit->blockSignals(b); | 133 | mDateEdit->blockSignals(b); |
133 | } | 134 | } |
134 | void KDateEdit::setDate(QDate newDate) | 135 | void KDateEdit::setDate(QDate newDate) |
135 | { | 136 | { |
136 | if (!newDate.isValid() && !mHandleInvalid) | 137 | if (!newDate.isValid() && !mHandleInvalid) |
137 | return; | 138 | return; |
138 | if ( readDate() == newDate ) | 139 | if ( readDate() == newDate ) |
139 | return; | 140 | return; |
140 | QString dateString = ""; | 141 | QString dateString = ""; |
141 | if(newDate.isValid()) | 142 | if(newDate.isValid()) |
142 | dateString = KGlobal::locale()->formatDate( newDate, dateFormShort ); | 143 | dateString = KGlobal::locale()->formatDate( newDate, dateFormShort ); |
143 | 144 | ||
144 | mTextChanged = false; | 145 | mTextChanged = false; |
145 | 146 | ||
146 | // We do not want to generate a signal here, since we explicity setting | 147 | // We do not want to generate a signal here, since we explicity setting |
147 | // the date | 148 | // the date |
148 | bool b = mDateEdit->signalsBlocked(); | 149 | bool b = mDateEdit->signalsBlocked(); |
149 | mDateEdit->blockSignals(true); | 150 | mDateEdit->blockSignals(true); |
150 | mDateEdit->setText(dateString); | 151 | mDateEdit->setText(dateString); |
151 | mDateEdit->blockSignals(b); | 152 | mDateEdit->blockSignals(b); |
152 | } | 153 | } |
153 | 154 | ||
154 | void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort) | 155 | void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort) |
155 | { | 156 | { |
156 | QString dateForm = dateFormShort ? | 157 | QString dateForm = dateFormShort ? |
157 | KGlobal::locale()->dateFormatShort() : | 158 | KGlobal::locale()->dateFormatShort() : |
158 | KGlobal::locale()->dateFormat(); | 159 | KGlobal::locale()->dateFormat(); |
159 | 160 | ||
160 | int begin = dateForm.find("%"); | 161 | int begin = dateForm.find("%"); |
161 | int space = 0; | 162 | int space = 0; |
162 | int allStrLength = 0; | 163 | int allStrLength = 0; |
163 | int strLength = 0; | 164 | int strLength = 0; |
164 | int repeat = 0; | 165 | int repeat = 0; |
165 | 166 | ||
166 | // witch? Day, Month or Year switch? | 167 | // witch? Day, Month or Year switch? |
167 | while(1){ | 168 | while(1){ |
168 | switch ( dateForm.at(begin + 1).latin1() ) | 169 | switch ( dateForm.at(begin + 1).latin1() ) |
169 | { | 170 | { |
170 | case 'd':// 16 (month day) | 171 | case 'd':// 16 (month day) |
171 | strLength = 2; //Ok | 172 | strLength = 2; //Ok |
172 | break; | 173 | break; |
173 | case 'm':// 01 (month) | 174 | case 'm':// 01 (month) |
174 | strLength = 2; //Ok | 175 | strLength = 2; //Ok |
175 | break; | 176 | break; |
176 | case 'a':// Mon (Weekday) | 177 | case 'a':// Mon (Weekday) |
177 | strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); | 178 | strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); |
178 | break; | 179 | break; |
179 | case 'A':// Monday (Weekday) | 180 | case 'A':// Monday (Weekday) |
180 | strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); | 181 | strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); |
181 | break; | 182 | break; |
182 | case 'b':// Jan (monthName) | 183 | case 'b':// Jan (monthName) |
183 | strLength = KGlobal::locale()->monthName(date.month(), true).length(); | 184 | strLength = KGlobal::locale()->monthName(date.month(), true).length(); |
184 | break; | 185 | break; |
185 | case 'B':// January (monthName) | 186 | case 'B':// January (monthName) |
186 | strLength = KGlobal::locale()->monthName(date.month(), false).length(); | 187 | strLength = KGlobal::locale()->monthName(date.month(), false).length(); |
187 | break; | 188 | break; |
188 | case 'y':// 04 (year short) | 189 | case 'y':// 04 (year short) |
189 | strLength = 2; //Ok | 190 | strLength = 2; //Ok |
190 | break; | 191 | break; |
191 | case 'Y':// 2004 (year) | 192 | case 'Y':// 2004 (year) |
192 | strLength = 4; //Ok | 193 | strLength = 4; //Ok |
193 | break; | 194 | break; |
194 | default: | 195 | default: |
195 | break; | 196 | break; |
196 | } | 197 | } |
197 | space = begin - (repeat++ * 2); | 198 | space = begin - (repeat++ * 2); |
198 | // all select? then dayswitch | 199 | // all select? then dayswitch |
199 | if( (mDateEdit->text().length() == mDateEdit->markedText().length() ) && | 200 | if( (mDateEdit->text().length() == mDateEdit->markedText().length() ) && |
200 | ( (dateForm.at(begin + 1).latin1() == 'd') || | 201 | ( (dateForm.at(begin + 1).latin1() == 'd') || |
201 | (dateForm.at(begin + 1).latin1() == 'a') || | 202 | (dateForm.at(begin + 1).latin1() == 'a') || |
202 | (dateForm.at(begin + 1).latin1() == 'A') ) ) { | 203 | (dateForm.at(begin + 1).latin1() == 'A') ) ) { |
203 | break; | 204 | break; |
204 | } | 205 | } |
205 | // mDateEdit-StringPos == CursorPosition(cpos) then break and set date | 206 | // mDateEdit-StringPos == CursorPosition(cpos) then break and set date |
206 | if( ( (space + allStrLength) <= *cpos && *cpos <= (space + allStrLength + strLength) ) || *cpos < begin ) { | 207 | if( ( (space + allStrLength) <= *cpos && *cpos <= (space + allStrLength + strLength) ) || *cpos < begin ) { |
207 | break; | 208 | break; |
208 | } | 209 | } |
209 | allStrLength += strLength; | 210 | allStrLength += strLength; |
210 | begin = dateForm.find("%", begin +1); | 211 | begin = dateForm.find("%", begin +1); |
211 | } | 212 | } |
212 | 213 | ||
213 | // set date | 214 | // set date |
214 | switch ( dateForm.at(begin + 1).latin1() ) { | 215 | switch ( dateForm.at(begin + 1).latin1() ) { |
215 | case 'd': | 216 | case 'd': |
216 | case 'a': | 217 | case 'a': |
217 | case 'A': | 218 | case 'A': |
218 | if(key == Key_Up) { | 219 | if(key == Key_Up) { |
219 | setDate( date.addDays( 1 ) ); | 220 | setDate( date.addDays( 1 ) ); |
220 | } | 221 | } |
221 | else if(key == Key_Down) { | 222 | else if(key == Key_Down) { |
222 | setDate( date.addDays( -1 ) ); | 223 | setDate( date.addDays( -1 ) ); |
223 | } | 224 | } |
224 | maxDay = readDate().day(); | 225 | maxDay = readDate().day(); |
225 | break; | 226 | break; |
226 | case 'm': | 227 | case 'm': |
227 | case 'b': | 228 | case 'b': |
228 | case 'B': | 229 | case 'B': |
229 | if(key == Key_Up) { | 230 | if(key == Key_Up) { |
230 | int year = ((date.month()+1)>12)?date.year()+1:date.year(); | 231 | int year = ((date.month()+1)>12)?date.year()+1:date.year(); |
231 | int month = ((date.month()+1)>12)?1:date.month()+1; | 232 | int month = ((date.month()+1)>12)?1:date.month()+1; |
232 | int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; | 233 | int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; |
233 | setDate( QDate( year, month, day ) ); | 234 | setDate( QDate( year, month, day ) ); |
234 | } else if(key == Key_Down) { | 235 | } else if(key == Key_Down) { |
235 | int year = ((date.month()-1)<1)?date.year()-1:date.year(); | 236 | int year = ((date.month()-1)<1)?date.year()-1:date.year(); |
236 | int month = ((date.month()-1)<1)?12:date.month()-1; | 237 | int month = ((date.month()-1)<1)?12:date.month()-1; |
237 | int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; | 238 | int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; |
238 | setDate( QDate( year, month, day ) ); | 239 | setDate( QDate( year, month, day ) ); |
239 | } | 240 | } |
240 | break; | 241 | break; |
241 | case 'y': | 242 | case 'y': |
242 | case 'Y': | 243 | case 'Y': |
243 | if(key == Key_Up) { | 244 | if(key == Key_Up) { |
244 | setDate( QDate( date.year() + 1, date.month() , date.day()) ); | 245 | setDate( QDate( date.year() + 1, date.month() , date.day()) ); |
245 | } | 246 | } |
246 | else if(key == Key_Down) { | 247 | else if(key == Key_Down) { |
247 | setDate( QDate( date.year() - 1, date.month() , date.day()) ); | 248 | setDate( QDate( date.year() - 1, date.month() , date.day()) ); |
248 | } | 249 | } |
249 | break; | 250 | break; |
250 | /* default: | 251 | /* default: |
251 | if(key == Key_Up) { | 252 | if(key == Key_Up) { |
252 | setDate( date.addDays( 1 ) ); | 253 | setDate( date.addDays( 1 ) ); |
253 | } else if(key == Key_Down) { | 254 | } else if(key == Key_Down) { |
254 | setDate( date.addDays( -1 ) ); | 255 | setDate( date.addDays( -1 ) ); |
255 | } | 256 | } |
256 | break;*/ | 257 | break;*/ |
257 | } | 258 | } |
258 | 259 | ||
259 | date = readDate(); | 260 | date = readDate(); |
260 | begin = dateForm.find("%"); | 261 | begin = dateForm.find("%"); |
261 | int allSelectStrLength = 0; | 262 | int allSelectStrLength = 0; |
262 | int selectStrLength = 0; | 263 | int selectStrLength = 0; |
263 | 264 | ||
264 | // set selection do new date an set cursor at end of selection | 265 | // set selection do new date an set cursor at end of selection |
265 | for(int i = 0; i < repeat; i++){ | 266 | for(int i = 0; i < repeat; i++){ |
266 | switch ( dateForm.at(begin + 1).latin1() ) | 267 | switch ( dateForm.at(begin + 1).latin1() ) |
267 | { | 268 | { |
268 | case 'd':// 16 (month day) | 269 | case 'd':// 16 (month day) |
269 | selectStrLength = 2; //Ok | 270 | selectStrLength = 2; //Ok |
270 | break; | 271 | break; |
271 | case 'm':// 01 (month) | 272 | case 'm':// 01 (month) |
272 | selectStrLength = 2; //Ok | 273 | selectStrLength = 2; //Ok |
273 | break; | 274 | break; |
274 | case 'a':// Mon (Weekday short) | 275 | case 'a':// Mon (Weekday short) |
275 | selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); | 276 | selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); |
276 | break; | 277 | break; |
277 | case 'A':// Monday (Weekday) | 278 | case 'A':// Monday (Weekday) |
278 | selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); | 279 | selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); |
279 | break; | 280 | break; |
280 | case 'b':// Jan (monthName short) | 281 | case 'b':// Jan (monthName short) |
281 | selectStrLength = KGlobal::locale()->monthName(date.month(), true).length(); | 282 | selectStrLength = KGlobal::locale()->monthName(date.month(), true).length(); |
282 | break; | 283 | break; |
283 | case 'B':// January (monthName) | 284 | case 'B':// January (monthName) |
284 | selectStrLength = KGlobal::locale()->monthName(date.month(), false).length(); | 285 | selectStrLength = KGlobal::locale()->monthName(date.month(), false).length(); |
285 | break; | 286 | break; |
286 | case 'y':// 04 (year short) | 287 | case 'y':// 04 (year short) |
287 | selectStrLength = 2; //Ok | 288 | selectStrLength = 2; //Ok |
288 | break; | 289 | break; |
289 | case 'Y':// 2004 (year) | 290 | case 'Y':// 2004 (year) |
290 | selectStrLength = 4; //Ok | 291 | selectStrLength = 4; //Ok |
291 | break; | 292 | break; |
292 | default: | 293 | default: |
293 | break; | 294 | break; |
294 | } | 295 | } |
295 | space = begin - (i * 2); | 296 | space = begin - (i * 2); |
296 | allSelectStrLength += selectStrLength; | 297 | allSelectStrLength += selectStrLength; |
297 | begin = dateForm.find("%", begin +1); | 298 | begin = dateForm.find("%", begin +1); |
298 | } | 299 | } |
299 | // set selection from begin of date | 300 | // set selection from begin of date |
300 | setSelect( space + allSelectStrLength - selectStrLength , selectStrLength); | 301 | setSelect( space + allSelectStrLength - selectStrLength , selectStrLength); |
301 | *cpos = space + allSelectStrLength; | 302 | *cpos = space + allSelectStrLength; |
302 | emit(dateChanged(date)); | 303 | emit(dateChanged(date)); |
303 | 304 | ||
304 | return; | 305 | return; |
305 | } | 306 | } |
306 | 307 | ||
307 | void KDateEdit::setHandleInvalid(bool handleInvalid) | 308 | void KDateEdit::setHandleInvalid(bool handleInvalid) |
308 | { | 309 | { |
309 | mHandleInvalid = handleInvalid; | 310 | mHandleInvalid = handleInvalid; |
310 | } | 311 | } |
311 | 312 | ||
312 | void KDateEdit::setEnabled(bool on) | 313 | void KDateEdit::setEnabled(bool on) |
313 | { | 314 | { |
314 | mDateEdit->setEnabled(on); | 315 | mDateEdit->setEnabled(on); |
315 | mDateButton->setEnabled(on); | 316 | mDateButton->setEnabled(on); |
316 | } | 317 | } |
317 | 318 | ||
318 | QDate KDateEdit::date() const | 319 | QDate KDateEdit::date() const |
319 | { | 320 | { |
320 | QDate date = readDate(); | 321 | QDate date = readDate(); |
321 | 322 | ||
322 | if (date.isValid() || mHandleInvalid) { | 323 | if (date.isValid() || mHandleInvalid) { |
323 | return date; | 324 | return date; |
324 | } else { | 325 | } else { |
325 | KNotifyClient::beep(); | 326 | KNotifyClient::beep(); |
326 | return QDate::currentDate(); | 327 | return QDate::currentDate(); |
327 | } | 328 | } |
328 | } | 329 | } |
329 | 330 | ||
330 | void KDateEdit::keyPressEvent(QKeyEvent *e) | 331 | void KDateEdit::keyPressEvent(QKeyEvent *e) |
331 | { | 332 | { |
332 | QDate date = readDate(); | 333 | QDate date = readDate(); |
333 | int cpos = mDateEdit->cursorPosition(); | 334 | int cpos = mDateEdit->cursorPosition(); |
334 | 335 | ||
335 | switch(e->key()) | 336 | switch(e->key()) |
336 | { | 337 | { |
337 | case Key_Escape: | 338 | case Key_Escape: |
338 | mDateEdit->deselect(); | 339 | mDateEdit->deselect(); |
339 | case Key_Tab: | 340 | case Key_Tab: |
340 | QHBox::keyPressEvent(e); | 341 | QHBox::keyPressEvent(e); |
341 | break; | 342 | break; |
342 | case Key_Up: | 343 | case Key_Up: |
343 | // when date invalid then set to currend and return | 344 | // when date invalid then set to currend and return |
344 | if(!date.isValid()) { | 345 | if(!date.isValid()) { |
345 | date = QDate::currentDate(); | 346 | date = QDate::currentDate(); |
346 | setDate(date); | 347 | setDate(date); |
347 | mDateEdit->setCursorPosition(cpos); | 348 | mDateEdit->setCursorPosition(cpos); |
348 | emit(dateChanged(date)); | 349 | emit(dateChanged(date)); |
349 | QString text = i18n( "You entered an invalid date!\n Date changed to current date." ); | 350 | QString text = i18n( "You entered an invalid date!\n Date changed to current date." ); |
350 | KMessageBox::information( 0, text ); | 351 | KMessageBox::information( 0, text ); |
351 | return; | 352 | return; |
352 | } | 353 | } |
353 | setDate(date, &cpos, Key_Up, dateFormShort); | 354 | setDate(date, &cpos, Key_Up, dateFormShort); |
354 | break; | 355 | break; |
355 | case Key_Down: | 356 | case Key_Down: |
356 | // when date invalid then set to current and return | 357 | // when date invalid then set to current and return |
357 | if(!date.isValid()) { | 358 | if(!date.isValid()) { |
358 | date = QDate::currentDate(); | 359 | date = QDate::currentDate(); |
359 | setDate(date); | 360 | setDate(date); |
360 | mDateEdit->setCursorPosition(cpos); | 361 | mDateEdit->setCursorPosition(cpos); |
361 | emit(dateChanged(date)); | 362 | emit(dateChanged(date)); |
362 | QString text = i18n( "You entered an invalid date!\n Date changed to current date." ); | 363 | QString text = i18n( "You entered an invalid date!\n Date changed to current date." ); |
363 | KMessageBox::information( 0, text ); | 364 | KMessageBox::information( 0, text ); |
364 | return; | 365 | return; |
365 | } | 366 | } |
366 | setDate(date, &cpos, Key_Down, dateFormShort); | 367 | setDate(date, &cpos, Key_Down, dateFormShort); |
367 | break; | 368 | break; |
368 | default: | 369 | default: |
369 | QHBox::keyPressEvent(e); | 370 | QHBox::keyPressEvent(e); |
370 | break; | 371 | break; |
371 | } // switch | 372 | } // switch |
372 | mDateEdit->setCursorPosition(cpos); | 373 | mDateEdit->setCursorPosition(cpos); |
373 | } | 374 | } |
374 | 375 | ||
375 | void KDateEdit::setSelect( int from, int to ) | 376 | void KDateEdit::setSelect( int from, int to ) |
376 | { | 377 | { |
377 | // return; | 378 | // return; |
378 | mDateEdit->setSelection( from , to ); | 379 | mDateEdit->setSelection( from , to ); |
379 | } | 380 | } |
380 | 381 | ||
381 | void KDateEdit::toggleDatePicker() | 382 | void KDateEdit::toggleDatePicker() |
382 | { | 383 | { |
383 | if( mDateFrame->isVisible() ) { | 384 | if( mDateFrame->isVisible() ) { |
384 | mDateFrame->hide(); | 385 | mDateFrame->hide(); |
385 | } else { | 386 | } else { |
386 | QPoint tmpPoint = mapToGlobal(mDateButton->geometry().bottomRight()); | 387 | QPoint tmpPoint = mapToGlobal(mDateButton->geometry().bottomRight()); |
387 | QSize datepickersize = mDatePicker->sizeHint(); | 388 | QSize datepickersize = mDatePicker->sizeHint(); |
388 | 389 | ||
389 | if ( tmpPoint.x() < 7+datepickersize.width() ) tmpPoint.setX( 7+datepickersize.width() ); | 390 | if ( tmpPoint.x() < 7+datepickersize.width() ) tmpPoint.setX( 7+datepickersize.width() ); |
390 | 391 | ||
391 | int h = QApplication::desktop()->height(); | 392 | int h = QApplication::desktop()->height(); |
392 | 393 | ||
393 | if ( tmpPoint.y() + datepickersize.height() > h ) tmpPoint.setY( h - datepickersize.height() ); | 394 | if ( tmpPoint.y() + datepickersize.height() > h ) tmpPoint.setY( h - datepickersize.height() ); |
394 | 395 | ||
395 | mDateFrame->setGeometry(tmpPoint.x()-datepickersize.width()-7, tmpPoint.y(), | 396 | mDateFrame->setGeometry(tmpPoint.x()-datepickersize.width()-7, tmpPoint.y(), |
396 | datepickersize.width()+2*mDateFrame->lineWidth(), datepickersize.height()+2*mDateFrame->lineWidth()); | 397 | datepickersize.width()+2*mDateFrame->lineWidth(), datepickersize.height()+2*mDateFrame->lineWidth()); |
397 | 398 | ||
398 | QDate date = readDate(); | 399 | QDate date = readDate(); |
399 | if(date.isValid()) { | 400 | if(date.isValid()) { |
400 | mDatePicker->setDate(date); | 401 | mDatePicker->setDate(date); |
401 | } else { | 402 | } else { |
402 | mDatePicker->setDate(QDate::currentDate()); | 403 | mDatePicker->setDate(QDate::currentDate()); |
403 | } | 404 | } |
404 | mDateFrame->show(); | 405 | mDateFrame->show(); |
405 | } | 406 | } |
406 | } | 407 | } |
407 | 408 | ||
408 | 409 | ||
409 | void KDateEdit::lineEnterPressed() | 410 | void KDateEdit::lineEnterPressed() |
410 | { | 411 | { |
411 | QDate date = readDate(); | 412 | QDate date = readDate(); |
412 | 413 | ||
413 | if(date.isValid()) | 414 | if(date.isValid()) |
414 | { | 415 | { |
415 | // Update the edit. This is needed if the user has entered a | 416 | // Update the edit. This is needed if the user has entered a |
416 | // word rather than the actual date. | 417 | // word rather than the actual date. |
417 | setDate(date); | 418 | setDate(date); |
418 | emit(dateChanged(date)); | 419 | emit(dateChanged(date)); |
419 | emit returnPressed(); | 420 | emit returnPressed(); |
420 | } | 421 | } |
421 | else | 422 | else |
422 | { | 423 | { |
423 | if ( withoutDp ) { | 424 | if ( withoutDp ) { |
424 | KNotifyClient::beep(); | 425 | KNotifyClient::beep(); |
425 | } else { | 426 | } else { |
426 | if ( !mDateEdit->text().isEmpty() ) { | 427 | if ( !mDateEdit->text().isEmpty() ) { |
427 | mTextChanged = false; | 428 | mTextChanged = false; |
428 | QString text = i18n( "You entered an invalid date!\n Will use current date instead." ); | 429 | QString text = i18n( "You entered an invalid date!\n Will use current date instead." ); |
429 | if ( isVisible() ) | 430 | if ( isVisible() ) |
430 | if ( KMessageBox::warningContinueCancel( 0, text ) == KMessageBox::Continue ) { | 431 | if ( KMessageBox::warningContinueCancel( 0, text ) == KMessageBox::Continue ) { |
431 | setDate( QDate::currentDate() ); | 432 | setDate( QDate::currentDate() ); |
432 | emit dateChanged( QDate::currentDate() ); | 433 | emit dateChanged( QDate::currentDate() ); |
433 | } | 434 | } |
434 | } | 435 | } |
435 | } | 436 | } |
436 | } | 437 | } |
437 | } | 438 | } |
438 | 439 | ||
439 | bool KDateEdit::inputIsValid() | 440 | bool KDateEdit::inputIsValid() |
440 | { | 441 | { |
441 | return readDate().isValid(); | 442 | return readDate().isValid(); |
442 | } | 443 | } |
443 | 444 | ||
444 | QDate KDateEdit::readDate() const | 445 | QDate KDateEdit::readDate() const |
445 | { | 446 | { |
446 | QString text = mDateEdit->text(); | 447 | QString text = mDateEdit->text(); |
447 | QDate date; | 448 | QDate date; |
448 | 449 | ||
449 | if (mKeywordMap.contains(text.lower())) | 450 | if (mKeywordMap.contains(text.lower())) |
450 | { | 451 | { |
451 | date = QDate::currentDate().addDays(mKeywordMap[text.lower()]); | 452 | date = QDate::currentDate().addDays(mKeywordMap[text.lower()]); |
452 | } | 453 | } |
453 | else | 454 | else |
454 | { | 455 | { |
455 | date = KGlobal::locale()->readDate(text); | 456 | date = KGlobal::locale()->readDate(text); |
456 | } | 457 | } |
457 | 458 | ||
458 | return date; | 459 | return date; |
459 | } | 460 | } |
460 | 461 | ||
461 | bool KDateEdit::eventFilter(QObject *, QEvent *e) | 462 | bool KDateEdit::eventFilter(QObject *, QEvent *e) |
462 | { | 463 | { |
463 | // We only process the focus out event if the text has changed | 464 | // We only process the focus out event if the text has changed |
464 | // since we got focus | 465 | // since we got focus |
465 | if ((e->type() == QEvent::FocusOut) ) | 466 | if ((e->type() == QEvent::FocusOut) ) |
466 | { | 467 | { |
467 | if ( mTextChanged ) { | 468 | if ( mTextChanged ) { |
468 | lineEnterPressed(); | 469 | lineEnterPressed(); |
469 | mTextChanged = false; | 470 | mTextChanged = false; |
diff --git a/microkde/kdialogbase.cpp b/microkde/kdialogbase.cpp index d1f7630..801094a 100644 --- a/microkde/kdialogbase.cpp +++ b/microkde/kdialogbase.cpp | |||
@@ -1,289 +1,292 @@ | |||
1 | #include <qtabwidget.h> | 1 | #include <qtabwidget.h> |
2 | #include <qpushbutton.h> | 2 | #include <qpushbutton.h> |
3 | #include <qlayout.h> | 3 | #include <qlayout.h> |
4 | #include <qframe.h> | 4 | #include <qframe.h> |
5 | 5 | ||
6 | 6 | ||
7 | #include "klocale.h" | 7 | #include "klocale.h" |
8 | #include "kdebug.h" | 8 | #include "kdebug.h" |
9 | 9 | ||
10 | #include "kdialogbase.h" | 10 | #include "kdialogbase.h" |
11 | 11 | ||
12 | KDialogBase::KDialogBase() | 12 | KDialogBase::KDialogBase() |
13 | { | 13 | { |
14 | } | 14 | } |
15 | 15 | ||
16 | KDialogBase::KDialogBase( QWidget *parent, const char *name, bool modal, | 16 | KDialogBase::KDialogBase( QWidget *parent, const char *name, bool modal, |
17 | const QString &caption, | 17 | const QString &caption, |
18 | int buttonMask, ButtonCode defaultButton, | 18 | int buttonMask, ButtonCode defaultButton, |
19 | bool separator, | 19 | bool separator, |
20 | const QString &user1, | 20 | const QString &user1, |
21 | const QString &user2, | 21 | const QString &user2, |
22 | const QString &user3) : | 22 | const QString &user3) : |
23 | KDialog( parent, name, modal ) | 23 | KDialog( parent, name, modal ) |
24 | { | 24 | { |
25 | init( caption, buttonMask, user1, user2 ); | 25 | init( caption, buttonMask, user1, user2 ); |
26 | if (findButton( defaultButton ) ) | 26 | if (findButton( defaultButton ) ) { |
27 | (findButton( defaultButton ) )->setFocus(); | 27 | (findButton( defaultButton ) )->setFocus(); |
28 | (findButton( defaultButton ) )->setDefault( true ); | ||
29 | } | ||
28 | 30 | ||
29 | } | 31 | } |
30 | 32 | ||
31 | KDialogBase::KDialogBase( int dialogFace, const QString &caption, | 33 | KDialogBase::KDialogBase( int dialogFace, const QString &caption, |
32 | int buttonMask, ButtonCode defaultButton, | 34 | int buttonMask, ButtonCode defaultButton, |
33 | QWidget *parent, const char *name, bool modal, | 35 | QWidget *parent, const char *name, bool modal, |
34 | bool separator, | 36 | bool separator, |
35 | const QString &user1, | 37 | const QString &user1, |
36 | const QString &user2, | 38 | const QString &user2, |
37 | const QString &user3) : | 39 | const QString &user3) : |
38 | KDialog( parent, name, modal ) | 40 | KDialog( parent, name, modal ) |
39 | { | 41 | { |
40 | init( caption, buttonMask, user1, user2 ); | 42 | init( caption, buttonMask, user1, user2 ); |
41 | if (findButton( defaultButton ) ) | 43 | if (findButton( defaultButton ) ) |
42 | (findButton( defaultButton ) )->setFocus(); | 44 | (findButton( defaultButton ) )->setFocus(); |
43 | 45 | ||
44 | } | 46 | } |
45 | 47 | ||
46 | KDialogBase::~KDialogBase() | 48 | KDialogBase::~KDialogBase() |
47 | { | 49 | { |
48 | } | 50 | } |
49 | 51 | ||
50 | void KDialogBase::init( const QString &caption, int buttonMask, | 52 | void KDialogBase::init( const QString &caption, int buttonMask, |
51 | const QString &user1 ,const QString &user2 ) | 53 | const QString &user1 ,const QString &user2 ) |
52 | { | 54 | { |
53 | mMainWidget = 0; | 55 | mMainWidget = 0; |
54 | mTabWidget = 0; | 56 | mTabWidget = 0; |
55 | mPlainPage = 0; | 57 | mPlainPage = 0; |
56 | mTopLayout = 0; | 58 | mTopLayout = 0; |
57 | if ( !caption.isEmpty() ) { | 59 | if ( !caption.isEmpty() ) { |
58 | setCaption( caption ); | 60 | setCaption( caption ); |
59 | } | 61 | } |
60 | 62 | ||
61 | if ( buttonMask & User1 ) { | 63 | if ( buttonMask & User1 ) { |
62 | mUser1Button = new QPushButton( user1, this ); | 64 | mUser1Button = new QPushButton( user1, this ); |
63 | connect( mUser1Button, SIGNAL( clicked() ), SLOT( slotUser1() ) ); | 65 | connect( mUser1Button, SIGNAL( clicked() ), SLOT( slotUser1() ) ); |
64 | } else { | 66 | } else { |
65 | mUser1Button = 0; | 67 | mUser1Button = 0; |
66 | } | 68 | } |
67 | if ( buttonMask & User2 ) { | 69 | if ( buttonMask & User2 ) { |
68 | mUser2Button = new QPushButton( user2, this ); | 70 | mUser2Button = new QPushButton( user2, this ); |
69 | connect( mUser2Button, SIGNAL( clicked() ), SLOT( slotUser2() ) ); | 71 | connect( mUser2Button, SIGNAL( clicked() ), SLOT( slotUser2() ) ); |
70 | } else { | 72 | } else { |
71 | mUser2Button = 0; | 73 | mUser2Button = 0; |
72 | } | 74 | } |
73 | 75 | ||
74 | if ( buttonMask & Ok ) { | 76 | if ( buttonMask & Ok ) { |
75 | mOkButton = new QPushButton( i18n("Ok"), this ); | 77 | mOkButton = new QPushButton( i18n("Ok"), this ); |
76 | connect( mOkButton, SIGNAL( clicked() ), SLOT( slotOk() ) ); | 78 | connect( mOkButton, SIGNAL( clicked() ), SLOT( slotOk() ) ); |
79 | mOkButton->setDefault( true ); | ||
77 | } else { | 80 | } else { |
78 | mOkButton = 0; | 81 | mOkButton = 0; |
79 | } | 82 | } |
80 | if ( buttonMask & Default ) { | 83 | if ( buttonMask & Default ) { |
81 | mDefaultButton = new QPushButton( i18n("Default"), this ); | 84 | mDefaultButton = new QPushButton( i18n("Default"), this ); |
82 | connect( mDefaultButton, SIGNAL( clicked() ), SIGNAL( defaultClicked() ) ); | 85 | connect( mDefaultButton, SIGNAL( clicked() ), SIGNAL( defaultClicked() ) ); |
83 | } else { | 86 | } else { |
84 | mDefaultButton = 0; | 87 | mDefaultButton = 0; |
85 | } | 88 | } |
86 | 89 | ||
87 | if ( buttonMask & Apply ) { | 90 | if ( buttonMask & Apply ) { |
88 | mApplyButton = new QPushButton( i18n("Apply"), this ); | 91 | mApplyButton = new QPushButton( i18n("Apply"), this ); |
89 | connect( mApplyButton, SIGNAL( clicked() ), SLOT( slotApply() ) ); | 92 | connect( mApplyButton, SIGNAL( clicked() ), SLOT( slotApply() ) ); |
90 | } else { | 93 | } else { |
91 | mApplyButton = 0; | 94 | mApplyButton = 0; |
92 | } | 95 | } |
93 | 96 | ||
94 | if ( buttonMask & Cancel ) { | 97 | if ( buttonMask & Cancel ) { |
95 | mCancelButton = new QPushButton( i18n("Cancel"), this ); | 98 | mCancelButton = new QPushButton( i18n("Cancel"), this ); |
96 | connect( mCancelButton, SIGNAL( clicked() ), SLOT( slotCancel() ) ); | 99 | connect( mCancelButton, SIGNAL( clicked() ), SLOT( slotCancel() ) ); |
97 | } else { | 100 | } else { |
98 | mCancelButton = 0; | 101 | mCancelButton = 0; |
99 | } | 102 | } |
100 | 103 | ||
101 | if ( buttonMask & Close ) { | 104 | if ( buttonMask & Close ) { |
102 | mCloseButton = new QPushButton( i18n("Close"), this ); | 105 | mCloseButton = new QPushButton( i18n("Close"), this ); |
103 | connect( mCloseButton, SIGNAL( clicked() ), SLOT( slotClose() ) ); | 106 | connect( mCloseButton, SIGNAL( clicked() ), SLOT( slotClose() ) ); |
104 | } else { | 107 | } else { |
105 | mCloseButton = 0; | 108 | mCloseButton = 0; |
106 | } | 109 | } |
107 | } | 110 | } |
108 | 111 | ||
109 | QTabWidget *KDialogBase::tabWidget() | 112 | QTabWidget *KDialogBase::tabWidget() |
110 | { | 113 | { |
111 | if ( !mTabWidget ) { | 114 | if ( !mTabWidget ) { |
112 | mTabWidget = new QTabWidget( this ); | 115 | mTabWidget = new QTabWidget( this ); |
113 | setMainWidget( mTabWidget ); | 116 | setMainWidget( mTabWidget ); |
114 | } | 117 | } |
115 | return mTabWidget; | 118 | return mTabWidget; |
116 | } | 119 | } |
117 | 120 | ||
118 | void KDialogBase::hideButtons() | 121 | void KDialogBase::hideButtons() |
119 | { | 122 | { |
120 | if ( mUser1Button ) mUser1Button->hide() ; | 123 | if ( mUser1Button ) mUser1Button->hide() ; |
121 | if ( mUser2Button ) mUser2Button->hide() ; | 124 | if ( mUser2Button ) mUser2Button->hide() ; |
122 | if ( mOkButton ) mOkButton->hide() ; | 125 | if ( mOkButton ) mOkButton->hide() ; |
123 | if ( mApplyButton ) mApplyButton->hide() ; | 126 | if ( mApplyButton ) mApplyButton->hide() ; |
124 | if ( mDefaultButton ) mDefaultButton->hide(); | 127 | if ( mDefaultButton ) mDefaultButton->hide(); |
125 | if ( mCancelButton ) mCancelButton->hide() ; | 128 | if ( mCancelButton ) mCancelButton->hide() ; |
126 | if ( mCloseButton ) mCloseButton->hide() ; | 129 | if ( mCloseButton ) mCloseButton->hide() ; |
127 | 130 | ||
128 | } | 131 | } |
129 | void KDialogBase::initLayout() | 132 | void KDialogBase::initLayout() |
130 | { | 133 | { |
131 | 134 | ||
132 | delete mTopLayout; | 135 | delete mTopLayout; |
133 | mTopLayout = new QVBoxLayout( this ); | 136 | mTopLayout = new QVBoxLayout( this ); |
134 | mTopLayout->setMargin( marginHint() ); | 137 | mTopLayout->setMargin( marginHint() ); |
135 | mTopLayout->setSpacing( spacingHint() ); | 138 | mTopLayout->setSpacing( spacingHint() ); |
136 | 139 | ||
137 | mTopLayout->addWidget( mMainWidget ); | 140 | mTopLayout->addWidget( mMainWidget ); |
138 | 141 | ||
139 | QBoxLayout *buttonLayout = new QHBoxLayout; | 142 | QBoxLayout *buttonLayout = new QHBoxLayout; |
140 | mTopLayout->addLayout( buttonLayout ); | 143 | mTopLayout->addLayout( buttonLayout ); |
141 | 144 | ||
142 | if ( mUser1Button ) buttonLayout->addWidget( mUser1Button ); | 145 | if ( mUser1Button ) buttonLayout->addWidget( mUser1Button ); |
143 | if ( mUser2Button ) buttonLayout->addWidget( mUser2Button ); | 146 | if ( mUser2Button ) buttonLayout->addWidget( mUser2Button ); |
144 | if ( mOkButton ) buttonLayout->addWidget( mOkButton ); | 147 | if ( mOkButton ) buttonLayout->addWidget( mOkButton ); |
145 | if ( mApplyButton ) buttonLayout->addWidget( mApplyButton ); | 148 | if ( mApplyButton ) buttonLayout->addWidget( mApplyButton ); |
146 | if ( mDefaultButton ) buttonLayout->addWidget( mDefaultButton ); | 149 | if ( mDefaultButton ) buttonLayout->addWidget( mDefaultButton ); |
147 | if ( mCancelButton ) buttonLayout->addWidget( mCancelButton ); | 150 | if ( mCancelButton ) buttonLayout->addWidget( mCancelButton ); |
148 | if ( mCloseButton ) buttonLayout->addWidget( mCloseButton ); | 151 | if ( mCloseButton ) buttonLayout->addWidget( mCloseButton ); |
149 | } | 152 | } |
150 | 153 | ||
151 | QFrame *KDialogBase::addPage( const QString &name ) | 154 | QFrame *KDialogBase::addPage( const QString &name ) |
152 | { | 155 | { |
153 | // kdDebug() << "KDialogBase::addPage(): " << name << endl; | 156 | // kdDebug() << "KDialogBase::addPage(): " << name << endl; |
154 | QFrame *frame = new QFrame( tabWidget() ); | 157 | QFrame *frame = new QFrame( tabWidget() ); |
155 | tabWidget()->addTab( frame, name ); | 158 | tabWidget()->addTab( frame, name ); |
156 | return frame; | 159 | return frame; |
157 | } | 160 | } |
158 | 161 | ||
159 | QFrame *KDialogBase::addPage( const QString &name, int, const QPixmap & ) | 162 | QFrame *KDialogBase::addPage( const QString &name, int, const QPixmap & ) |
160 | { | 163 | { |
161 | return addPage( name ); | 164 | return addPage( name ); |
162 | } | 165 | } |
163 | 166 | ||
164 | 167 | ||
165 | void KDialogBase::setMainWidget( QWidget *widget ) | 168 | void KDialogBase::setMainWidget( QWidget *widget ) |
166 | { | 169 | { |
167 | kdDebug() << "KDialogBase::setMainWidget()" << endl; | 170 | kdDebug() << "KDialogBase::setMainWidget()" << endl; |
168 | 171 | ||
169 | mMainWidget = widget; | 172 | mMainWidget = widget; |
170 | initLayout(); | 173 | initLayout(); |
171 | } | 174 | } |
172 | 175 | ||
173 | void KDialogBase::setButtonText( ButtonCode id, const QString &text ) | 176 | void KDialogBase::setButtonText( ButtonCode id, const QString &text ) |
174 | { | 177 | { |
175 | QPushButton *button = findButton( id ); | 178 | QPushButton *button = findButton( id ); |
176 | if ( button ) { | 179 | if ( button ) { |
177 | button->setText( text ); | 180 | button->setText( text ); |
178 | } | 181 | } |
179 | } | 182 | } |
180 | 183 | ||
181 | void KDialogBase::enableButton( ButtonCode id, bool state ) | 184 | void KDialogBase::enableButton( ButtonCode id, bool state ) |
182 | { | 185 | { |
183 | QPushButton *button = findButton( id ); | 186 | QPushButton *button = findButton( id ); |
184 | if ( button ) { | 187 | if ( button ) { |
185 | button->setEnabled( state ); | 188 | button->setEnabled( state ); |
186 | } | 189 | } |
187 | } | 190 | } |
188 | 191 | ||
189 | QPushButton *KDialogBase::findButton( ButtonCode id ) | 192 | QPushButton *KDialogBase::findButton( ButtonCode id ) |
190 | { | 193 | { |
191 | QPushButton *button = 0; | 194 | QPushButton *button = 0; |
192 | switch ( id ) { | 195 | switch ( id ) { |
193 | case Ok: | 196 | case Ok: |
194 | button = mOkButton; | 197 | button = mOkButton; |
195 | break; | 198 | break; |
196 | case Apply: | 199 | case Apply: |
197 | button = mApplyButton; | 200 | button = mApplyButton; |
198 | break; | 201 | break; |
199 | case User1: | 202 | case User1: |
200 | button = mUser1Button; | 203 | button = mUser1Button; |
201 | break; | 204 | break; |
202 | case User2: | 205 | case User2: |
203 | button = mUser2Button; | 206 | button = mUser2Button; |
204 | break; | 207 | break; |
205 | case Cancel: | 208 | case Cancel: |
206 | button = mCancelButton; | 209 | button = mCancelButton; |
207 | break; | 210 | break; |
208 | case Default: | 211 | case Default: |
209 | button = mDefaultButton; | 212 | button = mDefaultButton; |
210 | break; | 213 | break; |
211 | case Close: | 214 | case Close: |
212 | button = mCloseButton; | 215 | button = mCloseButton; |
213 | break; | 216 | break; |
214 | default: | 217 | default: |
215 | break; | 218 | break; |
216 | } | 219 | } |
217 | return button; | 220 | return button; |
218 | } | 221 | } |
219 | 222 | ||
220 | void KDialogBase::enableButtonOK( bool state ) | 223 | void KDialogBase::enableButtonOK( bool state ) |
221 | { | 224 | { |
222 | enableButton( Ok, state ); | 225 | enableButton( Ok, state ); |
223 | } | 226 | } |
224 | 227 | ||
225 | void KDialogBase::enableButtonApply( bool state ) | 228 | void KDialogBase::enableButtonApply( bool state ) |
226 | { | 229 | { |
227 | enableButton( Apply, state ); | 230 | enableButton( Apply, state ); |
228 | } | 231 | } |
229 | 232 | ||
230 | void KDialogBase::showButton( ButtonCode id, bool show ) | 233 | void KDialogBase::showButton( ButtonCode id, bool show ) |
231 | { | 234 | { |
232 | QPushButton *button = findButton( id ); | 235 | QPushButton *button = findButton( id ); |
233 | if ( button ) { | 236 | if ( button ) { |
234 | if ( show ) button->show(); | 237 | if ( show ) button->show(); |
235 | else button->hide(); | 238 | else button->hide(); |
236 | } | 239 | } |
237 | } | 240 | } |
238 | 241 | ||
239 | int KDialogBase::pageIndex( QWidget *widget ) const | 242 | int KDialogBase::pageIndex( QWidget *widget ) const |
240 | { | 243 | { |
241 | return 0; | 244 | return 0; |
242 | } | 245 | } |
243 | 246 | ||
244 | 247 | ||
245 | bool KDialogBase::showPage( int index ) | 248 | bool KDialogBase::showPage( int index ) |
246 | { | 249 | { |
247 | tabWidget()->setCurrentPage( index );return false; | 250 | tabWidget()->setCurrentPage( index );return false; |
248 | } | 251 | } |
249 | 252 | ||
250 | QFrame *KDialogBase::plainPage() | 253 | QFrame *KDialogBase::plainPage() |
251 | { | 254 | { |
252 | if ( !mPlainPage ) { | 255 | if ( !mPlainPage ) { |
253 | mPlainPage = new QFrame( this ); | 256 | mPlainPage = new QFrame( this ); |
254 | setMainWidget( mPlainPage ); | 257 | setMainWidget( mPlainPage ); |
255 | } | 258 | } |
256 | return mPlainPage; | 259 | return mPlainPage; |
257 | } | 260 | } |
258 | 261 | ||
259 | void KDialogBase::slotOk() | 262 | void KDialogBase::slotOk() |
260 | { | 263 | { |
261 | emit okClicked(); | 264 | emit okClicked(); |
262 | accept(); | 265 | accept(); |
263 | } | 266 | } |
264 | 267 | ||
265 | void KDialogBase::slotApply() | 268 | void KDialogBase::slotApply() |
266 | { | 269 | { |
267 | emit applyClicked(); | 270 | emit applyClicked(); |
268 | } | 271 | } |
269 | 272 | ||
270 | void KDialogBase::slotCancel() | 273 | void KDialogBase::slotCancel() |
271 | { | 274 | { |
272 | emit cancelClicked(); | 275 | emit cancelClicked(); |
273 | reject(); | 276 | reject(); |
274 | } | 277 | } |
275 | 278 | ||
276 | void KDialogBase::slotClose() | 279 | void KDialogBase::slotClose() |
277 | { | 280 | { |
278 | emit closeClicked(); | 281 | emit closeClicked(); |
279 | reject(); | 282 | reject(); |
280 | } | 283 | } |
281 | 284 | ||
282 | void KDialogBase::slotUser1() | 285 | void KDialogBase::slotUser1() |
283 | { | 286 | { |
284 | emit user1Clicked(); | 287 | emit user1Clicked(); |
285 | } | 288 | } |
286 | void KDialogBase::slotUser2() | 289 | void KDialogBase::slotUser2() |
287 | { | 290 | { |
288 | emit user2Clicked(); | 291 | emit user2Clicked(); |
289 | } | 292 | } |