author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /korganizer/ktimeedit.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
-rw-r--r-- | korganizer/ktimeedit.cpp | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/korganizer/ktimeedit.cpp b/korganizer/ktimeedit.cpp index df9b2fc..e2ae4a6 100644 --- a/korganizer/ktimeedit.cpp +++ b/korganizer/ktimeedit.cpp | |||
@@ -1,474 +1,477 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 1999 Preston Brown, Ian Dawes | 3 | Copyright (c) 1999 Preston Brown, Ian Dawes |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program 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 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qkeycode.h> | 24 | #include <qnamespace.h> |
25 | #include <qcombobox.h> | 25 | #include <qcombobox.h> |
26 | #include <qdatetime.h> | 26 | #include <qdatetime.h> |
27 | #include <qlineedit.h> | 27 | #include <qlineedit.h> |
28 | #include <qlistbox.h> | 28 | #include <q3listbox.h> |
29 | #include <qapplication.h> | 29 | #include <qapplication.h> |
30 | #include <QDesktopWidget> | ||
31 | //Added by qt3to4: | ||
32 | #include <QKeyEvent> | ||
30 | 33 | ||
31 | #include <kmessagebox.h> | 34 | #include <kmessagebox.h> |
32 | #include <kglobal.h> | 35 | #include <kglobal.h> |
33 | #include <kdebug.h> | 36 | #include <kdebug.h> |
34 | #include <klocale.h> | 37 | #include <klocale.h> |
35 | #include <kpimglobalprefs.h> | 38 | #include <kpimglobalprefs.h> |
36 | 39 | ||
37 | #include "ktimeedit.h" | 40 | #include "ktimeedit.h" |
38 | #include "koprefs.h" | 41 | #include "koprefs.h" |
39 | #include <qvalidator.h> | 42 | #include <qvalidator.h> |
40 | 43 | ||
41 | // Validator for a time value with only hours and minutes (no seconds) | 44 | // Validator for a time value with only hours and minutes (no seconds) |
42 | // Mostly locale aware. Author: David Faure <faure@kde.org> | 45 | // Mostly locale aware. Author: David Faure <faure@kde.org> |
43 | 46 | ||
44 | // KTimeWidget/QTimeEdit provide nicer editing, but don't provide a combobox. | 47 | // KTimeWidget/QTimeEdit provide nicer editing, but don't provide a combobox. |
45 | // Difficult to get all in one... | 48 | // Difficult to get all in one... |
46 | // But Qt-3.2 will offer QLineEdit::setMask, so a "99:99" mask would help. | 49 | // But Qt-3.2 will offer QLineEdit::setMask, so a "99:99" mask would help. |
47 | KOTimeEdit::KOTimeEdit(QWidget *parent, QTime qt, const char *name) | 50 | KOTimeEdit::KOTimeEdit(QWidget *parent, QTime qt, const char *name) |
48 | : QComboBox(TRUE, parent, name) | 51 | : Q3ComboBox(TRUE, parent, name) |
49 | { | 52 | { |
50 | setInsertionPolicy(NoInsertion); | 53 | setInsertionPolicy(NoInsertion); |
51 | mFlagKeyPressed = false; | 54 | mFlagKeyPressed = false; |
52 | if ( QApplication::desktop()->height() <= 480 ) { | 55 | if ( QApplication::desktop()->height() <= 480 ) { |
53 | setSizeLimit ( 6 ); | 56 | setSizeLimit ( 6 ); |
54 | } else { | 57 | } else { |
55 | setSizeLimit ( 12 ); | 58 | setSizeLimit ( 12 ); |
56 | } | 59 | } |
57 | mTime = qt; | 60 | mTime = qt; |
58 | 61 | ||
59 | // mNoTimeString = i18n("No Time"); | 62 | // mNoTimeString = i18n("No Time"); |
60 | // insertItem( mNoTimeString ); | 63 | // insertItem( mNoTimeString ); |
61 | 64 | ||
62 | // Fill combo box with selection of times in localized format. | 65 | // Fill combo box with selection of times in localized format. |
63 | QTime timeEntry(0,0,0); | 66 | QTime timeEntry(0,0,0); |
64 | do { | 67 | do { |
65 | insertItem(KGlobal::locale()->formatTime(timeEntry)); | 68 | insertItem(KGlobal::locale()->formatTime(timeEntry)); |
66 | timeEntry = timeEntry.addSecs(60*15); | 69 | timeEntry = timeEntry.addSecs(60*15); |
67 | } while (!timeEntry.isNull()); | 70 | } while ( !( timeEntry.hour() || timeEntry.minute() ) ); |
68 | // Add end of day. | 71 | // Add end of day. |
69 | insertItem( KGlobal::locale()->formatTime( QTime( 23, 59, 59 ) ) ); | 72 | insertItem( KGlobal::locale()->formatTime( QTime( 23, 59, 59 ) ) ); |
70 | 73 | ||
71 | updateText(); | 74 | updateText(); |
72 | setFocusPolicy(QWidget::StrongFocus); | 75 | setFocusPolicy(Qt::StrongFocus); |
73 | 76 | ||
74 | connect(this, SIGNAL(activated(int)), this, SLOT(activ(int))); | 77 | connect(this, SIGNAL(activated(int)), this, SLOT(activ(int))); |
75 | connect(this, SIGNAL(highlighted(int)), this, SLOT(hilit(int))); | 78 | connect(this, SIGNAL(highlighted(int)), this, SLOT(hilit(int))); |
76 | connect(this,SIGNAL(textChanged(const QString&)),this,SLOT(changedText())); | 79 | connect(this,SIGNAL(textChanged(const QString&)),this,SLOT(changedText())); |
77 | QFontMetrics fm ( font() ); | 80 | QFontMetrics fm ( font() ); |
78 | QString timeString = "24:00"; | 81 | QString timeString = "24:00"; |
79 | if ( KPimGlobalPrefs::instance()->mPreferredTime == 1 ) | 82 | if ( KPimGlobalPrefs::instance()->mPreferredTime == 1 ) |
80 | timeString = "02:00pm"; | 83 | timeString = "02:00pm"; |
81 | int addSpace = 32; | 84 | int addSpace = 32; |
82 | if ( QApplication::desktop()->width() > 320 ) | 85 | if ( QApplication::desktop()->width() > 320 ) |
83 | timeString += ":00"; | 86 | timeString += ":00"; |
84 | setFixedWidth(fm.width( timeString ) + 32 ); | 87 | setFixedWidth(fm.width( timeString ) + 32 ); |
85 | 88 | ||
86 | // Highlight Background and Textcolor change from default | 89 | // Highlight Background and Textcolor change from default |
87 | QPalette palette = QWidget::palette(); | 90 | QPalette palette = QWidget::palette(); |
88 | unsigned char red, green, blue; | 91 | unsigned char red, green, blue; |
89 | red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; | 92 | red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; |
90 | green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; | 93 | green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; |
91 | blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; | 94 | blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; |
92 | palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); | 95 | palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); |
93 | palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); | 96 | palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); |
94 | setPalette( palette ); | 97 | setPalette( palette ); |
95 | } | 98 | } |
96 | 99 | ||
97 | KOTimeEdit::~KOTimeEdit() | 100 | KOTimeEdit::~KOTimeEdit() |
98 | { | 101 | { |
99 | } | 102 | } |
100 | 103 | ||
101 | bool KOTimeEdit::hasTime() const | 104 | bool KOTimeEdit::hasTime() const |
102 | { | 105 | { |
103 | // Can't happen | 106 | // Can't happen |
104 | if ( currentText().isEmpty() ) return false; | 107 | if ( currentText().isEmpty() ) return false; |
105 | //if ( currentText() == mNoTimeString ) return false; | 108 | //if ( currentText() == mNoTimeString ) return false; |
106 | 109 | ||
107 | return true; // always | 110 | return true; // always |
108 | } | 111 | } |
109 | 112 | ||
110 | QTime KOTimeEdit::getTime() const | 113 | QTime KOTimeEdit::getTime() const |
111 | { | 114 | { |
112 | return KGlobal::locale()->readTime(currentText()); | 115 | return KGlobal::locale()->readTime(currentText()); |
113 | } | 116 | } |
114 | /* | 117 | /* |
115 | QSizePolicy KOTimeEdit::sizePolicy() const | 118 | QSizePolicy KOTimeEdit::sizePolicy() const |
116 | { | 119 | { |
117 | // Set size policy to Fixed, because edit cannot contain more text than the | 120 | // Set size policy to Fixed, because edit cannot contain more text than the |
118 | // string representing the time. It doesn't make sense to provide more space. | 121 | // string representing the time. It doesn't make sense to provide more space. |
119 | QSizePolicy sizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); | 122 | QSizePolicy sizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); |
120 | 123 | ||
121 | return sizePolicy; | 124 | return sizePolicy; |
122 | } | 125 | } |
123 | */ | 126 | */ |
124 | void KOTimeEdit::setTime(QTime newTime) | 127 | void KOTimeEdit::setTime(QTime newTime) |
125 | { | 128 | { |
126 | if ( mTime != newTime ) | 129 | if ( mTime != newTime ) |
127 | { | 130 | { |
128 | mTime = newTime; | 131 | mTime = newTime; |
129 | updateText(); | 132 | updateText(); |
130 | } | 133 | } |
131 | 134 | ||
132 | } | 135 | } |
133 | 136 | ||
134 | void KOTimeEdit::activ(int i) | 137 | void KOTimeEdit::activ(int i) |
135 | { | 138 | { |
136 | // The last entry, 23:59, is a special case | 139 | // The last entry, 23:59, is a special case |
137 | if( i == count() - 1 ) | 140 | if( i == count() - 1 ) |
138 | mTime = QTime( 23, 59, 0 ); | 141 | mTime = QTime( 23, 59, 0 ); |
139 | else | 142 | else |
140 | mTime = QTime(0,0,0).addSecs(i*15*60); | 143 | mTime = QTime(0,0,0).addSecs(i*15*60); |
141 | emit timeChanged(mTime); | 144 | emit timeChanged(mTime); |
142 | } | 145 | } |
143 | 146 | ||
144 | void KOTimeEdit::hilit(int ) | 147 | void KOTimeEdit::hilit(int ) |
145 | { | 148 | { |
146 | // we don't currently need to do anything here. | 149 | // we don't currently need to do anything here. |
147 | } | 150 | } |
148 | 151 | ||
149 | void KOTimeEdit::addTime(QTime qt, bool update) | 152 | void KOTimeEdit::addTime(QTime qt, bool update) |
150 | { | 153 | { |
151 | // Calculate the new time. | 154 | // Calculate the new time. |
152 | //qDebug("add h %d min %d ", qt.hour(),qt.minute() ); | 155 | //qDebug("add h %d min %d ", qt.hour(),qt.minute() ); |
153 | mTime = mTime.addSecs(qt.minute()*60+qt.hour()*3600); | 156 | mTime = mTime.addSecs(qt.minute()*60+qt.hour()*3600); |
154 | // if ( update ) | 157 | // if ( update ) |
155 | updateText(); | 158 | updateText(); |
156 | emit timeChanged(mTime); | 159 | emit timeChanged(mTime); |
157 | } | 160 | } |
158 | 161 | ||
159 | void KOTimeEdit::subTime(QTime qt, bool update) | 162 | void KOTimeEdit::subTime(QTime qt, bool update) |
160 | { | 163 | { |
161 | int h, m; | 164 | int h, m; |
162 | //qDebug("sub h %d min %d ", qt.hour(),qt.minute() ); | 165 | //qDebug("sub h %d min %d ", qt.hour(),qt.minute() ); |
163 | 166 | ||
164 | mTime = mTime.addSecs(-(qt.minute()*60+qt.hour()*3600)); | 167 | mTime = mTime.addSecs(-(qt.minute()*60+qt.hour()*3600)); |
165 | // store the newly calculated time. | 168 | // store the newly calculated time. |
166 | // mTime.setHMS(h, m, 0); | 169 | // mTime.setHMS(h, m, 0); |
167 | //if ( update ) | 170 | //if ( update ) |
168 | updateText(); | 171 | updateText(); |
169 | emit timeChanged(mTime); | 172 | emit timeChanged(mTime); |
170 | } | 173 | } |
171 | 174 | ||
172 | // void KOTimeEdit::mouseReleaseEvent ( QMouseEvent * ) | 175 | // void KOTimeEdit::mouseReleaseEvent ( QMouseEvent * ) |
173 | // { | 176 | // { |
174 | // qDebug("mouseReleaseEvent ( QMouseEvent * ) "); | 177 | // qDebug("mouseReleaseEvent ( QMouseEvent * ) "); |
175 | // } | 178 | // } |
176 | 179 | ||
177 | // void KOTimeEdit::focusInEvent ( QFocusEvent * ) | 180 | // void KOTimeEdit::focusInEvent ( QFocusEvent * ) |
178 | // { | 181 | // { |
179 | // qDebug("focusInEvent ( QFocusEvent * ) "); | 182 | // qDebug("focusInEvent ( QFocusEvent * ) "); |
180 | // } | 183 | // } |
181 | 184 | ||
182 | void KOTimeEdit::keyReleaseEvent(QKeyEvent *e) | 185 | void KOTimeEdit::keyReleaseEvent(QKeyEvent *e) |
183 | { | 186 | { |
184 | if ( !e->isAutoRepeat() ) { | 187 | if ( !e->isAutoRepeat() ) { |
185 | mFlagKeyPressed = false; | 188 | mFlagKeyPressed = false; |
186 | } | 189 | } |
187 | 190 | ||
188 | } | 191 | } |
189 | void KOTimeEdit::setSelect( int from, int to ) | 192 | void KOTimeEdit::setSelect( int from, int to ) |
190 | { | 193 | { |
191 | if ( KOPrefs::instance()->mHightlightDateTimeEdit) | 194 | if ( KOPrefs::instance()->mHightlightDateTimeEdit) |
192 | lineEdit()->setSelection( from , to ); | 195 | lineEdit()->setSelection( from , to ); |
193 | } | 196 | } |
194 | 197 | ||
195 | 198 | ||
196 | void KOTimeEdit::keyPressEvent(QKeyEvent *e) | 199 | void KOTimeEdit::keyPressEvent(QKeyEvent *e) |
197 | { | 200 | { |
198 | 201 | ||
199 | qApp->processEvents(); | 202 | qApp->processEvents(); |
200 | bool hour12Format = ( KPimGlobalPrefs::instance()->mPreferredTime == 1 ); | 203 | bool hour12Format = ( KPimGlobalPrefs::instance()->mPreferredTime == 1 ); |
201 | int maxpos = hour12Format?7:5; | 204 | int maxpos = hour12Format?7:5; |
202 | if ( e->isAutoRepeat() && !mFlagKeyPressed ) { | 205 | if ( e->isAutoRepeat() && !mFlagKeyPressed ) { |
203 | e->ignore(); | 206 | e->ignore(); |
204 | // qDebug(" ignore %d",e->isAutoRepeat() ); | 207 | // qDebug(" ignore %d",e->isAutoRepeat() ); |
205 | return; | 208 | return; |
206 | } | 209 | } |
207 | if (! e->isAutoRepeat() ) { | 210 | if (! e->isAutoRepeat() ) { |
208 | mFlagKeyPressed = true; | 211 | mFlagKeyPressed = true; |
209 | } | 212 | } |
210 | // Tap -> Focus Next Widget | 213 | // Tap -> Focus Next Widget |
211 | if ( e->key() == Key_Tab ) { | 214 | if ( e->key() == Qt::Key_Tab ) { |
212 | QComboBox::keyPressEvent(e); | 215 | Q3ComboBox::keyPressEvent(e); |
213 | return; | 216 | return; |
214 | } | 217 | } |
215 | 218 | ||
216 | // save Text from QLineEdit and CursorPosition | 219 | // save Text from QLineEdit and CursorPosition |
217 | QString text = lineEdit()->text(); | 220 | QString text = lineEdit()->text(); |
218 | int cpos = lineEdit()->cursorPosition(); | 221 | int cpos = lineEdit()->cursorPosition(); |
219 | // qDebug("cpos %d ", cpos); | 222 | // qDebug("cpos %d ", cpos); |
220 | 223 | ||
221 | // Switch for arrows, backspace and escape | 224 | // Switch for arrows, backspace and escape |
222 | switch(e->key()) { | 225 | switch(e->key()) { |
223 | case Key_Escape: | 226 | case Qt::Key_Escape: |
224 | lineEdit()->deselect(); | 227 | lineEdit()->deselect(); |
225 | case Key_Tab: | 228 | case Qt::Key_Tab: |
226 | QComboBox::keyPressEvent(e); | 229 | Q3ComboBox::keyPressEvent(e); |
227 | break; | 230 | break; |
228 | case Key_Up: | 231 | case Qt::Key_Up: |
229 | if ( e->state () == Qt::ControlButton ) { | 232 | if ( e->state () == Qt::ControlButton ) { |
230 | addTime(QTime(0,15,0), false ); | 233 | addTime(QTime(0,15,0), false ); |
231 | lineEdit()->setCursorPosition(3); | 234 | lineEdit()->setCursorPosition(3); |
232 | setSelect( 3 , 2 ); | 235 | setSelect( 3 , 2 ); |
233 | } | 236 | } |
234 | else | 237 | else |
235 | if ( e->state () == Qt::ShiftButton ) { | 238 | if ( e->state () == Qt::ShiftButton ) { |
236 | addTime(QTime(1,0,0), false ); | 239 | addTime(QTime(1,0,0), false ); |
237 | lineEdit()->setCursorPosition(0); | 240 | lineEdit()->setCursorPosition(0); |
238 | setSelect( 0 , 2 ); | 241 | setSelect( 0 , 2 ); |
239 | } | 242 | } |
240 | else | 243 | else |
241 | // switch time up, cursor location depend | 244 | // switch time up, cursor location depend |
242 | switch (cpos) { | 245 | switch (cpos) { |
243 | case 7: | 246 | case 7: |
244 | case 6: | 247 | case 6: |
245 | case 5: | 248 | case 5: |
246 | if(!hour12Format) { | 249 | if(!hour12Format) { |
247 | lineEdit()->setCursorPosition(cpos = 4); | 250 | lineEdit()->setCursorPosition(cpos = 4); |
248 | } else { | 251 | } else { |
249 | addTime(QTime(12,0,0), false ); | 252 | addTime(QTime(12,0,0), false ); |
250 | setSelect ( 5 , 2 ); | 253 | setSelect ( 5 , 2 ); |
251 | break; | 254 | break; |
252 | } | 255 | } |
253 | case 4: | 256 | case 4: |
254 | addTime(QTime(0,1,0), false ); | 257 | addTime(QTime(0,1,0), false ); |
255 | setSelect ( cpos , 1 ); | 258 | setSelect ( cpos , 1 ); |
256 | break; | 259 | break; |
257 | case 3: | 260 | case 3: |
258 | addTime(QTime(0,10,0), false ); | 261 | addTime(QTime(0,10,0), false ); |
259 | setSelect ( cpos , 1 ); | 262 | setSelect ( cpos , 1 ); |
260 | break; | 263 | break; |
261 | case 2: | 264 | case 2: |
262 | lineEdit()->setCursorPosition(--cpos); | 265 | lineEdit()->setCursorPosition(--cpos); |
263 | case 1: | 266 | case 1: |
264 | case 0: | 267 | case 0: |
265 | addTime(QTime(1,0,0), false ); | 268 | addTime(QTime(1,0,0), false ); |
266 | setSelect ( 0, 2 ); | 269 | setSelect ( 0, 2 ); |
267 | break; | 270 | break; |
268 | } | 271 | } |
269 | break; | 272 | break; |
270 | case Key_Down: | 273 | case Qt::Key_Down: |
271 | if ( e->state () == Qt::ControlButton ) { | 274 | if ( e->state () == Qt::ControlButton ) { |
272 | subTime(QTime(0,15,0), false ); | 275 | subTime(QTime(0,15,0), false ); |
273 | lineEdit()->setCursorPosition(3); | 276 | lineEdit()->setCursorPosition(3); |
274 | setSelect( 3 , 2 ); | 277 | setSelect( 3 , 2 ); |
275 | } | 278 | } |
276 | else | 279 | else |
277 | if ( e->state () == Qt::ShiftButton ) { | 280 | if ( e->state () == Qt::ShiftButton ) { |
278 | subTime(QTime(1,0,0), false ); | 281 | subTime(QTime(1,0,0), false ); |
279 | lineEdit()->setCursorPosition(0); | 282 | lineEdit()->setCursorPosition(0); |
280 | setSelect( 0 , 2 ); | 283 | setSelect( 0 , 2 ); |
281 | } | 284 | } |
282 | else | 285 | else |
283 | // switch time down, cursor location depend | 286 | // switch time down, cursor location depend |
284 | switch (cpos) { | 287 | switch (cpos) { |
285 | case 7: | 288 | case 7: |
286 | case 6: | 289 | case 6: |
287 | case 5: | 290 | case 5: |
288 | if(!hour12Format) { | 291 | if(!hour12Format) { |
289 | lineEdit()->setCursorPosition(cpos = 4); | 292 | lineEdit()->setCursorPosition(cpos = 4); |
290 | } else { | 293 | } else { |
291 | subTime(QTime(12,0,0), false ); | 294 | subTime(QTime(12,0,0), false ); |
292 | setSelect ( 5 , 2 ); | 295 | setSelect ( 5 , 2 ); |
293 | break; | 296 | break; |
294 | } | 297 | } |
295 | case 4: | 298 | case 4: |
296 | subTime(QTime(0,1,0), false ); | 299 | subTime(QTime(0,1,0), false ); |
297 | setSelect ( cpos , 1 ); | 300 | setSelect ( cpos , 1 ); |
298 | break; | 301 | break; |
299 | case 3: | 302 | case 3: |
300 | subTime(QTime(0,10,0), false ); | 303 | subTime(QTime(0,10,0), false ); |
301 | setSelect ( cpos , 1 ); | 304 | setSelect ( cpos , 1 ); |
302 | break; | 305 | break; |
303 | case 2: | 306 | case 2: |
304 | lineEdit()->setCursorPosition(--cpos); | 307 | lineEdit()->setCursorPosition(--cpos); |
305 | case 1: | 308 | case 1: |
306 | case 0: | 309 | case 0: |
307 | subTime(QTime(1,0,0), false ); | 310 | subTime(QTime(1,0,0), false ); |
308 | setSelect ( 0 , 2 ); | 311 | setSelect ( 0 , 2 ); |
309 | break; | 312 | break; |
310 | } | 313 | } |
311 | break; | 314 | break; |
312 | // set cursor to correct place | 315 | // set cursor to correct place |
313 | case Key_Left: | 316 | case Qt::Key_Left: |
314 | if ( cpos == 3 ) | 317 | if ( cpos == 3 ) |
315 | --cpos; | 318 | --cpos; |
316 | if ( cpos > 0) { | 319 | if ( cpos > 0) { |
317 | lineEdit()->setCursorPosition(--cpos); | 320 | lineEdit()->setCursorPosition(--cpos); |
318 | setSelect ( cpos , 1 ); | 321 | setSelect ( cpos , 1 ); |
319 | } | 322 | } |
320 | else | 323 | else |
321 | setSelect ( 0 , 1 ); | 324 | setSelect ( 0 , 1 ); |
322 | break; | 325 | break; |
323 | // set cursor to correct place | 326 | // set cursor to correct place |
324 | case Key_Right: | 327 | case Qt::Key_Right: |
325 | if ( cpos == 1 ) | 328 | if ( cpos == 1 ) |
326 | ++cpos; | 329 | ++cpos; |
327 | if ( cpos < maxpos ) { | 330 | if ( cpos < maxpos ) { |
328 | lineEdit()->setCursorPosition(++cpos); | 331 | lineEdit()->setCursorPosition(++cpos); |
329 | setSelect ( cpos , 1 ); | 332 | setSelect ( cpos , 1 ); |
330 | } | 333 | } |
331 | break; | 334 | break; |
332 | // rest | 335 | // rest |
333 | case Key_Prior: | 336 | case Qt::Key_Prior: |
334 | subTime(QTime(1,0,0)); | 337 | subTime(QTime(1,0,0)); |
335 | break; | 338 | break; |
336 | case Key_Next: | 339 | case Qt::Key_Next: |
337 | addTime(QTime(1,0,0)); | 340 | addTime(QTime(1,0,0)); |
338 | break; | 341 | break; |
339 | case Key_Backspace: | 342 | case Qt::Key_Backspace: |
340 | if ( cpos > 0) { | 343 | if ( cpos > 0) { |
341 | if ( cpos == 3 ) | 344 | if ( cpos == 3 ) |
342 | --cpos; | 345 | --cpos; |
343 | if ( cpos > 5) | 346 | if ( cpos > 5) |
344 | cpos = 5; | 347 | cpos = 5; |
345 | text.at( cpos-1 ) = '0'; | 348 | text[ cpos-1 ] = '0'; |
346 | lineEdit()->setText( text ); | 349 | lineEdit()->setText( text ); |
347 | lineEdit()->setCursorPosition(--cpos); | 350 | lineEdit()->setCursorPosition(--cpos); |
348 | setSelect ( cpos , 1 ); | 351 | setSelect ( cpos , 1 ); |
349 | changedText(); | 352 | changedText(); |
350 | } | 353 | } |
351 | break; | 354 | break; |
352 | } // switch arrows | 355 | } // switch arrows |
353 | 356 | ||
354 | // if cursor at string end, alltext market and keyEvent don't ArrowLeft -> deselect and cpos | 357 | // if cursor at string end, alltext market and keyEvent don't ArrowLeft -> deselect and cpos |
355 | if( cpos > 4 && lineEdit()->markedText().length() == 5 && e->key() != Key_Left ) { | 358 | if( cpos > 4 && lineEdit()->markedText().length() == 5 && e->key() != Qt::Key_Left ) { |
356 | lineEdit()->deselect(); | 359 | lineEdit()->deselect(); |
357 | cpos = 0; | 360 | cpos = 0; |
358 | lineEdit()->setCursorPosition(cpos); | 361 | lineEdit()->setCursorPosition(cpos); |
359 | setSelect(cpos , 1); | 362 | setSelect(cpos , 1); |
360 | } | 363 | } |
361 | 364 | ||
362 | if ( cpos == 2 ) { | 365 | if ( cpos == 2 ) { |
363 | lineEdit()->setCursorPosition(++cpos); | 366 | lineEdit()->setCursorPosition(++cpos); |
364 | } | 367 | } |
365 | 368 | ||
366 | // num keys when cursorPos preEnd | 369 | // num keys when cursorPos preEnd |
367 | if ( cpos < 5 ) { | 370 | if ( cpos < 5 ) { |
368 | // switch another keys | 371 | // switch another keys |
369 | switch(e->key()) { | 372 | switch(e->key()) { |
370 | case Key_Delete: | 373 | case Qt::Key_Delete: |
371 | text.at( cpos ) = '0'; | 374 | text[ cpos ] = '0'; |
372 | lineEdit()->setText( text ); | 375 | lineEdit()->setText( text ); |
373 | lineEdit()->setCursorPosition(cpos); | 376 | lineEdit()->setCursorPosition(cpos); |
374 | setSelect ( cpos , 1 ); | 377 | setSelect ( cpos , 1 ); |
375 | changedText(); | 378 | changedText(); |
376 | break; | 379 | break; |
377 | case Key_9: | 380 | case Qt::Key_9: |
378 | case Key_8: | 381 | case Qt::Key_8: |
379 | case Key_7: | 382 | case Qt::Key_7: |
380 | case Key_6: | 383 | case Qt::Key_6: |
381 | if ( !(cpos == 1 || cpos == 4) ) | 384 | if ( !(cpos == 1 || cpos == 4) ) |
382 | return; | 385 | return; |
383 | if ( cpos == 1 && text.at( 0 ) > '1') | 386 | if ( cpos == 1 && text.at( 0 ) > '1') |
384 | text.at( 0 ) = '1'; | 387 | text[ 0 ] = '1'; |
385 | case Key_5: | 388 | case Qt::Key_5: |
386 | case Key_4: | 389 | case Qt::Key_4: |
387 | case Key_3: | 390 | case Qt::Key_3: |
388 | if ( cpos < 1 ) | 391 | if ( cpos < 1 ) |
389 | return; | 392 | return; |
390 | if ( hour12Format && cpos == 1 ) | 393 | if ( hour12Format && cpos == 1 ) |
391 | return; | 394 | return; |
392 | case Key_2: | 395 | case Qt::Key_2: |
393 | if ( hour12Format && cpos == 0 ) | 396 | if ( hour12Format && cpos == 0 ) |
394 | return; | 397 | return; |
395 | if ( cpos == 0 && text.at( 1 ) > '3') | 398 | if ( cpos == 0 && text.at( 1 ) > '3') |
396 | text.at( 1 ) = '3'; | 399 | text[ 1 ] = '3'; |
397 | case Key_1: | 400 | case Qt::Key_1: |
398 | case Key_0: | 401 | case Qt::Key_0: |
399 | if ( hour12Format ) { | 402 | if ( hour12Format ) { |
400 | if ( e->key() == Key_0 && cpos == 1 && text.at( 0 ) == '0' ) | 403 | if ( e->key() == Qt::Key_0 && cpos == 1 && text.at( 0 ) == '0' ) |
401 | return; | 404 | return; |
402 | if ( e->key() == Key_0 && cpos == 0 && text.at( 1 ) == '0' ) | 405 | if ( e->key() == Qt::Key_0 && cpos == 0 && text.at( 1 ) == '0' ) |
403 | text.at( 1 ) = '1'; | 406 | text[ 1 ] = '1'; |
404 | } | 407 | } |
405 | text.at( cpos ) = QChar ( e->key() ); | 408 | text[ cpos ] = QChar ( e->key() ); |
406 | lineEdit()->setText( text ); | 409 | lineEdit()->setText( text ); |
407 | if ( cpos == 1 ) | 410 | if ( cpos == 1 ) |
408 | ++cpos; | 411 | ++cpos; |
409 | if ( cpos < 5) | 412 | if ( cpos < 5) |
410 | lineEdit()->setCursorPosition(++cpos); | 413 | lineEdit()->setCursorPosition(++cpos); |
411 | setSelect( cpos , 1 ); | 414 | setSelect( cpos , 1 ); |
412 | changedText(); | 415 | changedText(); |
413 | break; | 416 | break; |
414 | case Key_Home: | 417 | case Qt::Key_Home: |
415 | lineEdit()->setCursorPosition(0); | 418 | lineEdit()->setCursorPosition(0); |
416 | setSelect( cpos , 1 ); | 419 | setSelect( cpos , 1 ); |
417 | break; | 420 | break; |
418 | case Key_End: | 421 | case Qt::Key_End: |
419 | lineEdit()->setCursorPosition(5); | 422 | lineEdit()->setCursorPosition(5); |
420 | lineEdit()->deselect(); | 423 | lineEdit()->deselect(); |
421 | break; | 424 | break; |
422 | default: | 425 | default: |
423 | // QComboBox::keyPressEvent(e); | 426 | // QComboBox::keyPressEvent(e); |
424 | break; | 427 | break; |
425 | } // switch num keys | 428 | } // switch num keys |
426 | } else if ( cpos == 5 ) {// if cpos < 5 | 429 | } else if ( cpos == 5 ) {// if cpos < 5 |
427 | if ( hour12Format ) { | 430 | if ( hour12Format ) { |
428 | if ( e->key() == Key_A ) { | 431 | if ( e->key() == Qt::Key_A ) { |
429 | text.at( 5 ) = 'a'; | 432 | text[ 5 ] = 'a'; |
430 | lineEdit()->setText( text ); | 433 | lineEdit()->setText( text ); |
431 | lineEdit()->setCursorPosition(5); | 434 | lineEdit()->setCursorPosition(5); |
432 | 435 | ||
433 | } else if ( e->key() == Key_P ) { | 436 | } else if ( e->key() == Qt::Key_P ) { |
434 | text.at( 5 ) = 'p'; | 437 | text[ 5 ] = 'p'; |
435 | lineEdit()->setText( text ); | 438 | lineEdit()->setText( text ); |
436 | lineEdit()->setCursorPosition(5); | 439 | lineEdit()->setCursorPosition(5); |
437 | 440 | ||
438 | } | 441 | } |
439 | } | 442 | } |
440 | } | 443 | } |
441 | 444 | ||
442 | 445 | ||
443 | } | 446 | } |
444 | 447 | ||
445 | void KOTimeEdit::updateText() | 448 | void KOTimeEdit::updateText() |
446 | { | 449 | { |
447 | listBox()->blockSignals( true ); | 450 | listBox()->blockSignals( true ); |
448 | blockSignals( true ); | 451 | blockSignals( true ); |
449 | QString s = KGlobal::locale()->formatTime(mTime); | 452 | QString s = KGlobal::locale()->formatTime(mTime); |
450 | // Set the text but without emitting signals, nor losing the cursor position | 453 | // Set the text but without emitting signals, nor losing the cursor position |
451 | QLineEdit *line = lineEdit(); | 454 | QLineEdit *line = lineEdit(); |
452 | line->blockSignals(true); | 455 | line->blockSignals(true); |
453 | int pos = line->cursorPosition(); | 456 | int pos = line->cursorPosition(); |
454 | setCurrentItem((mTime.hour()*4)+(mTime.minute()/15)); | 457 | setCurrentItem((mTime.hour()*4)+(mTime.minute()/15)); |
455 | line->setText(s); | 458 | line->setText(s); |
456 | line->setCursorPosition(pos); | 459 | line->setCursorPosition(pos); |
457 | line->blockSignals(false); | 460 | line->blockSignals(false); |
458 | blockSignals( false ); | 461 | blockSignals( false ); |
459 | listBox()->blockSignals( false ); | 462 | listBox()->blockSignals( false ); |
460 | 463 | ||
461 | } | 464 | } |
462 | 465 | ||
463 | void KOTimeEdit::changedText() | 466 | void KOTimeEdit::changedText() |
464 | { | 467 | { |
465 | int pos = lineEdit()->cursorPosition(); | 468 | int pos = lineEdit()->cursorPosition(); |
466 | mTime = getTime(); | 469 | mTime = getTime(); |
467 | blockSignals( true ); | 470 | blockSignals( true ); |
468 | QString text = lineEdit()->text(); | 471 | QString text = lineEdit()->text(); |
469 | setCurrentItem((mTime.hour()*4)+(mTime.minute()/15)); | 472 | setCurrentItem((mTime.hour()*4)+(mTime.minute()/15)); |
470 | lineEdit()->setText(text); | 473 | lineEdit()->setText(text); |
471 | blockSignals( false ); | 474 | blockSignals( false ); |
472 | emit timeChanged(mTime); | 475 | emit timeChanged(mTime); |
473 | lineEdit()->setCursorPosition(pos); | 476 | lineEdit()->setCursorPosition(pos); |
474 | } | 477 | } |