Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qabstractspinbox.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | QAbstractSpinBox::QAbstractSpinBox(QWidget *parent) | - | ||||||||||||||||||
7 | : QWidget(*new QAbstractSpinBoxPrivate, parent, 0) | - | ||||||||||||||||||
8 | { | - | ||||||||||||||||||
9 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
10 | d->init(); | - | ||||||||||||||||||
11 | } | - | ||||||||||||||||||
12 | - | |||||||||||||||||||
13 | - | |||||||||||||||||||
14 | - | |||||||||||||||||||
15 | - | |||||||||||||||||||
16 | QAbstractSpinBox::QAbstractSpinBox(QAbstractSpinBoxPrivate &dd, QWidget *parent) | - | ||||||||||||||||||
17 | : QWidget(dd, parent, 0) | - | ||||||||||||||||||
18 | { | - | ||||||||||||||||||
19 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
20 | d->init(); | - | ||||||||||||||||||
21 | } | - | ||||||||||||||||||
22 | - | |||||||||||||||||||
23 | - | |||||||||||||||||||
24 | - | |||||||||||||||||||
25 | - | |||||||||||||||||||
26 | - | |||||||||||||||||||
27 | QAbstractSpinBox::~QAbstractSpinBox() | - | ||||||||||||||||||
28 | { | - | ||||||||||||||||||
29 | } | - | ||||||||||||||||||
30 | QAbstractSpinBox::ButtonSymbols QAbstractSpinBox::buttonSymbols() const | - | ||||||||||||||||||
31 | { | - | ||||||||||||||||||
32 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
33 | return d->buttonSymbols; | - | ||||||||||||||||||
34 | } | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | void QAbstractSpinBox::setButtonSymbols(ButtonSymbols buttonSymbols) | - | ||||||||||||||||||
37 | { | - | ||||||||||||||||||
38 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
39 | if (d->buttonSymbols != buttonSymbols) { | - | ||||||||||||||||||
40 | d->buttonSymbols = buttonSymbols; | - | ||||||||||||||||||
41 | d->updateEditFieldGeometry(); | - | ||||||||||||||||||
42 | update(); | - | ||||||||||||||||||
43 | } | - | ||||||||||||||||||
44 | } | - | ||||||||||||||||||
45 | QString QAbstractSpinBox::text() const | - | ||||||||||||||||||
46 | { | - | ||||||||||||||||||
47 | return lineEdit()->displayText(); | - | ||||||||||||||||||
48 | } | - | ||||||||||||||||||
49 | QString QAbstractSpinBox::specialValueText() const | - | ||||||||||||||||||
50 | { | - | ||||||||||||||||||
51 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
52 | return d->specialValueText; | - | ||||||||||||||||||
53 | } | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | void QAbstractSpinBox::setSpecialValueText(const QString &specialValueText) | - | ||||||||||||||||||
56 | { | - | ||||||||||||||||||
57 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | d->specialValueText = specialValueText; | - | ||||||||||||||||||
60 | d->cachedSizeHint = QSize(); | - | ||||||||||||||||||
61 | d->clearCache(); | - | ||||||||||||||||||
62 | d->updateEdit(); | - | ||||||||||||||||||
63 | } | - | ||||||||||||||||||
64 | bool QAbstractSpinBox::wrapping() const | - | ||||||||||||||||||
65 | { | - | ||||||||||||||||||
66 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
67 | return d->wrapping; | - | ||||||||||||||||||
68 | } | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | void QAbstractSpinBox::setWrapping(bool wrapping) | - | ||||||||||||||||||
71 | { | - | ||||||||||||||||||
72 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
73 | d->wrapping = wrapping; | - | ||||||||||||||||||
74 | } | - | ||||||||||||||||||
75 | bool QAbstractSpinBox::isReadOnly() const | - | ||||||||||||||||||
76 | { | - | ||||||||||||||||||
77 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
78 | return d->readOnly; | - | ||||||||||||||||||
79 | } | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | void QAbstractSpinBox::setReadOnly(bool enable) | - | ||||||||||||||||||
82 | { | - | ||||||||||||||||||
83 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
84 | d->readOnly = enable; | - | ||||||||||||||||||
85 | d->edit->setReadOnly(enable); | - | ||||||||||||||||||
86 | QEvent event(QEvent::ReadOnlyChange); | - | ||||||||||||||||||
87 | QApplication::sendEvent(this, &event); | - | ||||||||||||||||||
88 | update(); | - | ||||||||||||||||||
89 | } | - | ||||||||||||||||||
90 | bool QAbstractSpinBox::keyboardTracking() const | - | ||||||||||||||||||
91 | { | - | ||||||||||||||||||
92 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
93 | return d->keyboardTracking; | - | ||||||||||||||||||
94 | } | - | ||||||||||||||||||
95 | - | |||||||||||||||||||
96 | void QAbstractSpinBox::setKeyboardTracking(bool enable) | - | ||||||||||||||||||
97 | { | - | ||||||||||||||||||
98 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
99 | d->keyboardTracking = enable; | - | ||||||||||||||||||
100 | } | - | ||||||||||||||||||
101 | bool QAbstractSpinBox::hasFrame() const | - | ||||||||||||||||||
102 | { | - | ||||||||||||||||||
103 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
104 | return d->frame; | - | ||||||||||||||||||
105 | } | - | ||||||||||||||||||
106 | - | |||||||||||||||||||
107 | - | |||||||||||||||||||
108 | void QAbstractSpinBox::setFrame(bool enable) | - | ||||||||||||||||||
109 | { | - | ||||||||||||||||||
110 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
111 | d->frame = enable; | - | ||||||||||||||||||
112 | update(); | - | ||||||||||||||||||
113 | d->updateEditFieldGeometry(); | - | ||||||||||||||||||
114 | } | - | ||||||||||||||||||
115 | void QAbstractSpinBox::setAccelerated(bool accelerate) | - | ||||||||||||||||||
116 | { | - | ||||||||||||||||||
117 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
118 | d->accelerate = accelerate; | - | ||||||||||||||||||
119 | - | |||||||||||||||||||
120 | } | - | ||||||||||||||||||
121 | bool QAbstractSpinBox::isAccelerated() const | - | ||||||||||||||||||
122 | { | - | ||||||||||||||||||
123 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
124 | return d->accelerate; | - | ||||||||||||||||||
125 | } | - | ||||||||||||||||||
126 | bool QAbstractSpinBox::isGroupSeparatorShown() const | - | ||||||||||||||||||
127 | { | - | ||||||||||||||||||
128 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
129 | return d->showGroupSeparator; | - | ||||||||||||||||||
130 | } | - | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | void QAbstractSpinBox::setGroupSeparatorShown(bool shown) | - | ||||||||||||||||||
133 | { | - | ||||||||||||||||||
134 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
135 | if (d->showGroupSeparator == shown) | - | ||||||||||||||||||
136 | return; | - | ||||||||||||||||||
137 | d->showGroupSeparator = shown; | - | ||||||||||||||||||
138 | d->setValue(d->value, EmitIfChanged); | - | ||||||||||||||||||
139 | updateGeometry(); | - | ||||||||||||||||||
140 | } | - | ||||||||||||||||||
141 | void QAbstractSpinBox::setCorrectionMode(CorrectionMode correctionMode) | - | ||||||||||||||||||
142 | { | - | ||||||||||||||||||
143 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
144 | d->correctionMode = correctionMode; | - | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | } | - | ||||||||||||||||||
147 | QAbstractSpinBox::CorrectionMode QAbstractSpinBox::correctionMode() const | - | ||||||||||||||||||
148 | { | - | ||||||||||||||||||
149 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
150 | return d->correctionMode; | - | ||||||||||||||||||
151 | } | - | ||||||||||||||||||
152 | bool QAbstractSpinBox::hasAcceptableInput() const | - | ||||||||||||||||||
153 | { | - | ||||||||||||||||||
154 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
155 | return d->edit->hasAcceptableInput(); | - | ||||||||||||||||||
156 | } | - | ||||||||||||||||||
157 | Qt::Alignment QAbstractSpinBox::alignment() const | - | ||||||||||||||||||
158 | { | - | ||||||||||||||||||
159 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | return (Qt::Alignment)d->edit->alignment(); | - | ||||||||||||||||||
162 | } | - | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | void QAbstractSpinBox::setAlignment(Qt::Alignment flag) | - | ||||||||||||||||||
165 | { | - | ||||||||||||||||||
166 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | d->edit->setAlignment(flag); | - | ||||||||||||||||||
169 | } | - | ||||||||||||||||||
170 | - | |||||||||||||||||||
171 | - | |||||||||||||||||||
172 | - | |||||||||||||||||||
173 | - | |||||||||||||||||||
174 | - | |||||||||||||||||||
175 | void QAbstractSpinBox::selectAll() | - | ||||||||||||||||||
176 | { | - | ||||||||||||||||||
177 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | - | |||||||||||||||||||
180 | if (!d->specialValue()) { | - | ||||||||||||||||||
181 | const int tmp = d->edit->displayText().size() - d->suffix.size(); | - | ||||||||||||||||||
182 | d->edit->setSelection(tmp, -(tmp - d->prefix.size())); | - | ||||||||||||||||||
183 | } else { | - | ||||||||||||||||||
184 | d->edit->selectAll(); | - | ||||||||||||||||||
185 | } | - | ||||||||||||||||||
186 | } | - | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | - | |||||||||||||||||||
189 | - | |||||||||||||||||||
190 | - | |||||||||||||||||||
191 | - | |||||||||||||||||||
192 | void QAbstractSpinBox::clear() | - | ||||||||||||||||||
193 | { | - | ||||||||||||||||||
194 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
195 | - | |||||||||||||||||||
196 | d->edit->setText(d->prefix + d->suffix); | - | ||||||||||||||||||
197 | d->edit->setCursorPosition(d->prefix.size()); | - | ||||||||||||||||||
198 | d->cleared = true; | - | ||||||||||||||||||
199 | } | - | ||||||||||||||||||
200 | QAbstractSpinBox::StepEnabled QAbstractSpinBox::stepEnabled() const | - | ||||||||||||||||||
201 | { | - | ||||||||||||||||||
202 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
203 | if (d->readOnly || d->type == QVariant::Invalid) | - | ||||||||||||||||||
204 | return StepNone; | - | ||||||||||||||||||
205 | if (d->wrapping) | - | ||||||||||||||||||
206 | return StepEnabled(StepUpEnabled | StepDownEnabled); | - | ||||||||||||||||||
207 | StepEnabled ret = StepNone; | - | ||||||||||||||||||
208 | if (d->variantCompare(d->value, d->maximum) < 0) { | - | ||||||||||||||||||
209 | ret |= StepUpEnabled; | - | ||||||||||||||||||
210 | } | - | ||||||||||||||||||
211 | if (d->variantCompare(d->value, d->minimum) > 0) { | - | ||||||||||||||||||
212 | ret |= StepDownEnabled; | - | ||||||||||||||||||
213 | } | - | ||||||||||||||||||
214 | return ret; | - | ||||||||||||||||||
215 | } | - | ||||||||||||||||||
216 | QValidator::State QAbstractSpinBox::validate(QString & , int & ) const | - | ||||||||||||||||||
217 | { | - | ||||||||||||||||||
218 | return QValidator::Acceptable; | - | ||||||||||||||||||
219 | } | - | ||||||||||||||||||
220 | void QAbstractSpinBox::fixup(QString & ) const | - | ||||||||||||||||||
221 | { | - | ||||||||||||||||||
222 | } | - | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | - | |||||||||||||||||||
225 | - | |||||||||||||||||||
226 | - | |||||||||||||||||||
227 | - | |||||||||||||||||||
228 | - | |||||||||||||||||||
229 | - | |||||||||||||||||||
230 | void QAbstractSpinBox::stepUp() | - | ||||||||||||||||||
231 | { | - | ||||||||||||||||||
232 | stepBy(1); | - | ||||||||||||||||||
233 | } | - | ||||||||||||||||||
234 | - | |||||||||||||||||||
235 | - | |||||||||||||||||||
236 | - | |||||||||||||||||||
237 | - | |||||||||||||||||||
238 | - | |||||||||||||||||||
239 | - | |||||||||||||||||||
240 | - | |||||||||||||||||||
241 | void QAbstractSpinBox::stepDown() | - | ||||||||||||||||||
242 | { | - | ||||||||||||||||||
243 | stepBy(-1); | - | ||||||||||||||||||
244 | } | - | ||||||||||||||||||
245 | void QAbstractSpinBox::stepBy(int steps) | - | ||||||||||||||||||
246 | { | - | ||||||||||||||||||
247 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
248 | - | |||||||||||||||||||
249 | const QVariant old = d->value; | - | ||||||||||||||||||
250 | QString tmp = d->edit->displayText(); | - | ||||||||||||||||||
251 | int cursorPos = d->edit->cursorPosition(); | - | ||||||||||||||||||
252 | bool dontstep = false; | - | ||||||||||||||||||
253 | EmitPolicy e = EmitIfChanged; | - | ||||||||||||||||||
254 | if (d->pendingEmit) { | - | ||||||||||||||||||
255 | dontstep = validate(tmp, cursorPos) != QValidator::Acceptable; | - | ||||||||||||||||||
256 | d->cleared = false; | - | ||||||||||||||||||
257 | d->interpret(NeverEmit); | - | ||||||||||||||||||
258 | if (d->value != old) | - | ||||||||||||||||||
259 | e = AlwaysEmit; | - | ||||||||||||||||||
260 | } | - | ||||||||||||||||||
261 | if (!dontstep) { | - | ||||||||||||||||||
262 | d->setValue(d->bound(d->value + (d->singleStep * steps), old, steps), e); | - | ||||||||||||||||||
263 | } else if (e == AlwaysEmit) { | - | ||||||||||||||||||
264 | d->emitSignals(e, old); | - | ||||||||||||||||||
265 | } | - | ||||||||||||||||||
266 | selectAll(); | - | ||||||||||||||||||
267 | } | - | ||||||||||||||||||
268 | - | |||||||||||||||||||
269 | - | |||||||||||||||||||
270 | - | |||||||||||||||||||
271 | - | |||||||||||||||||||
272 | - | |||||||||||||||||||
273 | QLineEdit *QAbstractSpinBox::lineEdit() const | - | ||||||||||||||||||
274 | { | - | ||||||||||||||||||
275 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | return d->edit; | - | ||||||||||||||||||
278 | } | - | ||||||||||||||||||
279 | void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit) | - | ||||||||||||||||||
280 | { | - | ||||||||||||||||||
281 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | if (!lineEdit) { | - | ||||||||||||||||||
284 | ((!(lineEdit)) ? qt_assert("lineEdit",__FILE__,671677) : qt_noop()); | - | ||||||||||||||||||
285 | return; | - | ||||||||||||||||||
286 | } | - | ||||||||||||||||||
287 | delete d->edit; | - | ||||||||||||||||||
288 | d->edit = lineEdit; | - | ||||||||||||||||||
289 | if (!d->edit->validator()) | - | ||||||||||||||||||
290 | d->edit->setValidator(d->validator); | - | ||||||||||||||||||
291 | - | |||||||||||||||||||
292 | if (d->edit->parent() != this) | - | ||||||||||||||||||
293 | d->edit->setParent(this); | - | ||||||||||||||||||
294 | - | |||||||||||||||||||
295 | d->edit->setFrame(false); | - | ||||||||||||||||||
296 | d->edit->setFocusProxy(this); | - | ||||||||||||||||||
297 | d->edit->setAcceptDrops(false); | - | ||||||||||||||||||
298 | - | |||||||||||||||||||
299 | if (d->type != QVariant::Invalid) { | - | ||||||||||||||||||
300 | connect(d->edit, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "687""693"), | - | ||||||||||||||||||
301 | this, qFlagLocation("1""_q_editorTextChanged(QString)" "\0" __FILE__ ":" "688""694")); | - | ||||||||||||||||||
302 | connect(d->edit, qFlagLocation("2""cursorPositionChanged(int,int)" "\0" __FILE__ ":" "689""695"), | - | ||||||||||||||||||
303 | this, qFlagLocation("1""_q_editorCursorPositionChanged(int,int)" "\0" __FILE__ ":" "690""696")); | - | ||||||||||||||||||
304 | } | - | ||||||||||||||||||
305 | d->updateEditFieldGeometry(); | - | ||||||||||||||||||
306 | d->edit->setContextMenuPolicy(Qt::NoContextMenu); | - | ||||||||||||||||||
307 | d->edit->d_func()->control->setAccessibleObject(this); | - | ||||||||||||||||||
308 | - | |||||||||||||||||||
309 | if (isVisible()) | - | ||||||||||||||||||
310 | d->edit->show(); | - | ||||||||||||||||||
311 | if (isVisible()) | - | ||||||||||||||||||
312 | d->updateEdit(); | - | ||||||||||||||||||
313 | } | - | ||||||||||||||||||
314 | - | |||||||||||||||||||
315 | - | |||||||||||||||||||
316 | - | |||||||||||||||||||
317 | - | |||||||||||||||||||
318 | - | |||||||||||||||||||
319 | - | |||||||||||||||||||
320 | - | |||||||||||||||||||
321 | void QAbstractSpinBox::interpretText() | - | ||||||||||||||||||
322 | { | - | ||||||||||||||||||
323 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
324 | d->interpret(EmitIfChanged); | - | ||||||||||||||||||
325 | } | - | ||||||||||||||||||
326 | - | |||||||||||||||||||
327 | - | |||||||||||||||||||
328 | - | |||||||||||||||||||
329 | - | |||||||||||||||||||
330 | - | |||||||||||||||||||
331 | - | |||||||||||||||||||
332 | - | |||||||||||||||||||
333 | QVariant QAbstractSpinBox::inputMethodQuery(Qt::InputMethodQuery query) const | - | ||||||||||||||||||
334 | { | - | ||||||||||||||||||
335 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
336 | const QVariant lineEditValue = d->edit->inputMethodQuery(query); | - | ||||||||||||||||||
337 | switch (query) { | - | ||||||||||||||||||
338 | case Qt::ImHints: | - | ||||||||||||||||||
339 | if (const int hints = inputMethodHints()) | - | ||||||||||||||||||
340 | return QVariant(hints | lineEditValue.toInt()); | - | ||||||||||||||||||
341 | break; | - | ||||||||||||||||||
342 | default: | - | ||||||||||||||||||
343 | break; | - | ||||||||||||||||||
344 | } | - | ||||||||||||||||||
345 | return lineEditValue; | - | ||||||||||||||||||
346 | } | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | - | |||||||||||||||||||
349 | - | |||||||||||||||||||
350 | - | |||||||||||||||||||
351 | - | |||||||||||||||||||
352 | bool QAbstractSpinBox::event(QEvent *event) | - | ||||||||||||||||||
353 | { | - | ||||||||||||||||||
354 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
355 | switch (event->type()) { | - | ||||||||||||||||||
356 | case QEvent::FontChange: | - | ||||||||||||||||||
357 | case QEvent::StyleChange: | - | ||||||||||||||||||
358 | d->cachedSizeHint = d->cachedMinimumSizeHint = QSize(); | - | ||||||||||||||||||
359 | break; | - | ||||||||||||||||||
360 | case QEvent::ApplicationLayoutDirectionChange: | - | ||||||||||||||||||
361 | case QEvent::LayoutDirectionChange: | - | ||||||||||||||||||
362 | d->updateEditFieldGeometry(); | - | ||||||||||||||||||
363 | break; | - | ||||||||||||||||||
364 | case QEvent::HoverEnter: | - | ||||||||||||||||||
365 | case QEvent::HoverLeave: | - | ||||||||||||||||||
366 | case QEvent::HoverMove: | - | ||||||||||||||||||
367 | d->updateHoverControl(static_cast<const QHoverEvent *>(event)->pos()); | - | ||||||||||||||||||
368 | break; | - | ||||||||||||||||||
369 | case QEvent::ShortcutOverride: | - | ||||||||||||||||||
370 | if (d->edit->event(event)) | - | ||||||||||||||||||
371 | return true; | - | ||||||||||||||||||
372 | break; | - | ||||||||||||||||||
373 | case QEvent::InputMethod: | - | ||||||||||||||||||
374 | return d->edit->event(event); | - | ||||||||||||||||||
375 | default: | - | ||||||||||||||||||
376 | break; | - | ||||||||||||||||||
377 | } | - | ||||||||||||||||||
378 | return QWidget::event(event); | - | ||||||||||||||||||
379 | } | - | ||||||||||||||||||
380 | - | |||||||||||||||||||
381 | - | |||||||||||||||||||
382 | - | |||||||||||||||||||
383 | - | |||||||||||||||||||
384 | - | |||||||||||||||||||
385 | void QAbstractSpinBox::showEvent(QShowEvent *) | - | ||||||||||||||||||
386 | { | - | ||||||||||||||||||
387 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
388 | d->reset(); | - | ||||||||||||||||||
389 | - | |||||||||||||||||||
390 | if (d->ignoreUpdateEdit) { | - | ||||||||||||||||||
391 | d->ignoreUpdateEdit = false; | - | ||||||||||||||||||
392 | } else { | - | ||||||||||||||||||
393 | d->updateEdit(); | - | ||||||||||||||||||
394 | } | - | ||||||||||||||||||
395 | } | - | ||||||||||||||||||
396 | - | |||||||||||||||||||
397 | - | |||||||||||||||||||
398 | - | |||||||||||||||||||
399 | - | |||||||||||||||||||
400 | - | |||||||||||||||||||
401 | void QAbstractSpinBox::changeEvent(QEvent *event) | - | ||||||||||||||||||
402 | { | - | ||||||||||||||||||
403 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
404 | - | |||||||||||||||||||
405 | switch (event->type()) { | - | ||||||||||||||||||
406 | case QEvent::StyleChange: | - | ||||||||||||||||||
407 | d->spinClickTimerInterval = style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, 0, this); | - | ||||||||||||||||||
408 | d->spinClickThresholdTimerInterval = | - | ||||||||||||||||||
409 | style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatThreshold, 0, this); | - | ||||||||||||||||||
410 | d->reset(); | - | ||||||||||||||||||
411 | d->updateEditFieldGeometry(); | - | ||||||||||||||||||
412 | break; | - | ||||||||||||||||||
413 | case QEvent::EnabledChange: | - | ||||||||||||||||||
414 | if (!isEnabled()) { | - | ||||||||||||||||||
415 | d->reset(); | - | ||||||||||||||||||
416 | } | - | ||||||||||||||||||
417 | break; | - | ||||||||||||||||||
418 | case QEvent::ActivationChange: | - | ||||||||||||||||||
419 | if (!isActiveWindow()){ | - | ||||||||||||||||||
420 | d->reset(); | - | ||||||||||||||||||
421 | if (d->pendingEmit) | - | ||||||||||||||||||
422 | d->interpret(EmitIfChanged); | - | ||||||||||||||||||
423 | } | - | ||||||||||||||||||
424 | break; | - | ||||||||||||||||||
425 | default: | - | ||||||||||||||||||
426 | break; | - | ||||||||||||||||||
427 | } | - | ||||||||||||||||||
428 | QWidget::changeEvent(event); | - | ||||||||||||||||||
429 | } | - | ||||||||||||||||||
430 | - | |||||||||||||||||||
431 | - | |||||||||||||||||||
432 | - | |||||||||||||||||||
433 | - | |||||||||||||||||||
434 | - | |||||||||||||||||||
435 | void QAbstractSpinBox::resizeEvent(QResizeEvent *event) | - | ||||||||||||||||||
436 | { | - | ||||||||||||||||||
437 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
438 | QWidget::resizeEvent(event); | - | ||||||||||||||||||
439 | - | |||||||||||||||||||
440 | d->updateEditFieldGeometry(); | - | ||||||||||||||||||
441 | update(); | - | ||||||||||||||||||
442 | } | - | ||||||||||||||||||
443 | - | |||||||||||||||||||
444 | - | |||||||||||||||||||
445 | - | |||||||||||||||||||
446 | - | |||||||||||||||||||
447 | - | |||||||||||||||||||
448 | QSize QAbstractSpinBox::sizeHint() const | - | ||||||||||||||||||
449 | { | - | ||||||||||||||||||
450 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
451 | if (d->cachedSizeHint.isEmpty()) { | - | ||||||||||||||||||
452 | ensurePolished(); | - | ||||||||||||||||||
453 | - | |||||||||||||||||||
454 | const QFontMetrics fm(fontMetrics()); | - | ||||||||||||||||||
455 | int h = d->edit->sizeHint().height(); | - | ||||||||||||||||||
456 | int w = 0; | - | ||||||||||||||||||
457 | QString s; | - | ||||||||||||||||||
458 | QString fixedContent = d->prefix + d->suffix + QLatin1Char(' '); | - | ||||||||||||||||||
459 | s = d->textFromValue(d->minimum); | - | ||||||||||||||||||
460 | s.truncate(18); | - | ||||||||||||||||||
461 | s += fixedContent; | - | ||||||||||||||||||
462 | w = qMax(w, fm.width(s)); | - | ||||||||||||||||||
463 | s = d->textFromValue(d->maximum); | - | ||||||||||||||||||
464 | s.truncate(18); | - | ||||||||||||||||||
465 | s += fixedContent; | - | ||||||||||||||||||
466 | w = qMax(w, fm.width(s)); | - | ||||||||||||||||||
467 | - | |||||||||||||||||||
468 | if (d->specialValueText.size()) { | - | ||||||||||||||||||
469 | s = d->specialValueText; | - | ||||||||||||||||||
470 | w = qMax(w, fm.width(s)); | - | ||||||||||||||||||
471 | } | - | ||||||||||||||||||
472 | w += 2; | - | ||||||||||||||||||
473 | - | |||||||||||||||||||
474 | QStyleOptionSpinBox opt; | - | ||||||||||||||||||
475 | initStyleOption(&opt); | - | ||||||||||||||||||
476 | QSize hint(w, h); | - | ||||||||||||||||||
477 | d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this) | - | ||||||||||||||||||
478 | .expandedTo(QApplication::globalStrut()); | - | ||||||||||||||||||
479 | } | - | ||||||||||||||||||
480 | return d->cachedSizeHint; | - | ||||||||||||||||||
481 | } | - | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | - | |||||||||||||||||||
484 | - | |||||||||||||||||||
485 | - | |||||||||||||||||||
486 | - | |||||||||||||||||||
487 | QSize QAbstractSpinBox::minimumSizeHint() const | - | ||||||||||||||||||
488 | { | - | ||||||||||||||||||
489 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
490 | if (d->cachedMinimumSizeHint.isEmpty()) { | - | ||||||||||||||||||
491 | - | |||||||||||||||||||
492 | ensurePolished(); | - | ||||||||||||||||||
493 | - | |||||||||||||||||||
494 | const QFontMetrics fm(fontMetrics()); | - | ||||||||||||||||||
495 | int h = d->edit->minimumSizeHint().height(); | - | ||||||||||||||||||
496 | int w = 0; | - | ||||||||||||||||||
497 | - | |||||||||||||||||||
498 | QString s; | - | ||||||||||||||||||
499 | QString fixedContent = d->prefix + QLatin1Char(' '); | - | ||||||||||||||||||
500 | s = d->textFromValue(d->minimum); | - | ||||||||||||||||||
501 | s.truncate(18); | - | ||||||||||||||||||
502 | s += fixedContent; | - | ||||||||||||||||||
503 | w = qMax(w, fm.width(s)); | - | ||||||||||||||||||
504 | s = d->textFromValue(d->maximum); | - | ||||||||||||||||||
505 | s.truncate(18); | - | ||||||||||||||||||
506 | s += fixedContent; | - | ||||||||||||||||||
507 | w = qMax(w, fm.width(s)); | - | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | if (d->specialValueText.size()) { | - | ||||||||||||||||||
510 | s = d->specialValueText; | - | ||||||||||||||||||
511 | w = qMax(w, fm.width(s)); | - | ||||||||||||||||||
512 | } | - | ||||||||||||||||||
513 | w += 2; | - | ||||||||||||||||||
514 | - | |||||||||||||||||||
515 | QStyleOptionSpinBox opt; | - | ||||||||||||||||||
516 | initStyleOption(&opt); | - | ||||||||||||||||||
517 | QSize hint(w, h); | - | ||||||||||||||||||
518 | - | |||||||||||||||||||
519 | d->cachedMinimumSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this) | - | ||||||||||||||||||
520 | .expandedTo(QApplication::globalStrut()); | - | ||||||||||||||||||
521 | } | - | ||||||||||||||||||
522 | return d->cachedMinimumSizeHint; | - | ||||||||||||||||||
523 | } | - | ||||||||||||||||||
524 | - | |||||||||||||||||||
525 | - | |||||||||||||||||||
526 | - | |||||||||||||||||||
527 | - | |||||||||||||||||||
528 | - | |||||||||||||||||||
529 | void QAbstractSpinBox::paintEvent(QPaintEvent *) | - | ||||||||||||||||||
530 | { | - | ||||||||||||||||||
531 | QStyleOptionSpinBox opt; | - | ||||||||||||||||||
532 | initStyleOption(&opt); | - | ||||||||||||||||||
533 | QStylePainter p(this); | - | ||||||||||||||||||
534 | p.drawComplexControl(QStyle::CC_SpinBox, opt); | - | ||||||||||||||||||
535 | } | - | ||||||||||||||||||
536 | void QAbstractSpinBox::keyPressEvent(QKeyEvent *event) | - | ||||||||||||||||||
537 | { | - | ||||||||||||||||||
538 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
539 | - | |||||||||||||||||||
540 | if (!event->text().isEmpty() && d->edit->cursorPosition() < d->prefix.size()) | - | ||||||||||||||||||
541 | d->edit->setCursorPosition(d->prefix.size()); | - | ||||||||||||||||||
542 | - | |||||||||||||||||||
543 | int steps = 1; | - | ||||||||||||||||||
544 | bool isPgUpOrDown = false; | - | ||||||||||||||||||
545 | switch (event->key()) { | - | ||||||||||||||||||
546 | case Qt::Key_PageUp: | - | ||||||||||||||||||
547 | case Qt::Key_PageDown: | - | ||||||||||||||||||
548 | steps *= 10; | - | ||||||||||||||||||
549 | isPgUpOrDown = true; | - | ||||||||||||||||||
550 | case Qt::Key_Up: | - | ||||||||||||||||||
551 | case Qt::Key_Down: { | - | ||||||||||||||||||
552 | event->accept(); | - | ||||||||||||||||||
553 | const bool up = (event->key() == Qt::Key_PageUp || event->key() == Qt::Key_Up); | - | ||||||||||||||||||
554 | if (!(stepEnabled() & (up ? StepUpEnabled : StepDownEnabled))) | - | ||||||||||||||||||
555 | return; | - | ||||||||||||||||||
556 | if (!up) | - | ||||||||||||||||||
557 | steps *= -1; | - | ||||||||||||||||||
558 | if (style()->styleHint(QStyle::SH_SpinBox_AnimateButton, 0, this)) { | - | ||||||||||||||||||
559 | d->buttonState = (Keyboard | (up ? Up : Down)); | - | ||||||||||||||||||
560 | } | - | ||||||||||||||||||
561 | if (d->spinClickTimerId == -1) | - | ||||||||||||||||||
562 | stepBy(steps); | - | ||||||||||||||||||
563 | if(event->isAutoRepeat() && !isPgUpOrDown) { | - | ||||||||||||||||||
564 | if(d->spinClickThresholdTimerId == -1 && d->spinClickTimerId == -1) { | - | ||||||||||||||||||
565 | d->updateState(up, true); | - | ||||||||||||||||||
566 | } | - | ||||||||||||||||||
567 | } | - | ||||||||||||||||||
568 | - | |||||||||||||||||||
569 | QAccessibleValueChangeEvent event(this, d->value); | - | ||||||||||||||||||
570 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||
571 | - | |||||||||||||||||||
572 | return; | - | ||||||||||||||||||
573 | } | - | ||||||||||||||||||
574 | case Qt::Key_Enter: | - | ||||||||||||||||||
575 | case Qt::Key_Return: | - | ||||||||||||||||||
576 | d->edit->d_func()->control->clearUndo(); | - | ||||||||||||||||||
577 | d->interpret(d->keyboardTracking ? AlwaysEmit : EmitIfChanged); | - | ||||||||||||||||||
578 | selectAll(); | - | ||||||||||||||||||
579 | event->ignore(); | - | ||||||||||||||||||
580 | editingFinished(); | - | ||||||||||||||||||
581 | d->edit->returnPressed(); | - | ||||||||||||||||||
582 | return; | - | ||||||||||||||||||
583 | case Qt::Key_U: | - | ||||||||||||||||||
584 | if (event->modifiers() & Qt::ControlModifier | - | ||||||||||||||||||
585 | && QGuiApplication::platformName() == QLatin1String("xcb")) { | - | ||||||||||||||||||
586 | event->accept(); | - | ||||||||||||||||||
587 | if (!isReadOnly()) | - | ||||||||||||||||||
588 | clear(); | - | ||||||||||||||||||
589 | return; | - | ||||||||||||||||||
590 | } | - | ||||||||||||||||||
591 | break; | - | ||||||||||||||||||
592 | - | |||||||||||||||||||
593 | case Qt::Key_End: | - | ||||||||||||||||||
594 | case Qt::Key_Home: | - | ||||||||||||||||||
595 | if (event->modifiers() & Qt::ShiftModifier) { | - | ||||||||||||||||||
596 | int currentPos = d->edit->cursorPosition(); | - | ||||||||||||||||||
597 | const QString text = d->edit->displayText(); | - | ||||||||||||||||||
598 | if (event->key() == Qt::Key_End) { | - | ||||||||||||||||||
599 | if ((currentPos == 0 && !d->prefix.isEmpty()) || text.size() - d->suffix.size() <= currentPos) { | - | ||||||||||||||||||
600 | break; | - | ||||||||||||||||||
601 | } else { | - | ||||||||||||||||||
602 | d->edit->setSelection(currentPos, text.size() - d->suffix.size() - currentPos); | - | ||||||||||||||||||
603 | } | - | ||||||||||||||||||
604 | } else { | - | ||||||||||||||||||
605 | if ((currentPos == text.size() && !d->suffix.isEmpty()) || currentPos <= d->prefix.size()) { | - | ||||||||||||||||||
606 | break; | - | ||||||||||||||||||
607 | } else { | - | ||||||||||||||||||
608 | d->edit->setSelection(currentPos, d->prefix.size() - currentPos); | - | ||||||||||||||||||
609 | } | - | ||||||||||||||||||
610 | } | - | ||||||||||||||||||
611 | event->accept(); | - | ||||||||||||||||||
612 | return; | - | ||||||||||||||||||
613 | } | - | ||||||||||||||||||
614 | break; | - | ||||||||||||||||||
615 | - | |||||||||||||||||||
616 | default: | - | ||||||||||||||||||
617 | - | |||||||||||||||||||
618 | if (event == QKeySequence::SelectAll) { | - | ||||||||||||||||||
619 | selectAll(); | - | ||||||||||||||||||
620 | event->accept(); | - | ||||||||||||||||||
621 | return; | - | ||||||||||||||||||
622 | } | - | ||||||||||||||||||
623 | - | |||||||||||||||||||
624 | break; | - | ||||||||||||||||||
625 | } | - | ||||||||||||||||||
626 | - | |||||||||||||||||||
627 | d->edit->event(event); | - | ||||||||||||||||||
628 | if (!d->edit->text().isEmpty()) | - | ||||||||||||||||||
629 | d->cleared = false; | - | ||||||||||||||||||
630 | if (!isVisible()) | - | ||||||||||||||||||
631 | d->ignoreUpdateEdit = true; | - | ||||||||||||||||||
632 | } | - | ||||||||||||||||||
633 | - | |||||||||||||||||||
634 | - | |||||||||||||||||||
635 | - | |||||||||||||||||||
636 | - | |||||||||||||||||||
637 | - | |||||||||||||||||||
638 | void QAbstractSpinBox::keyReleaseEvent(QKeyEvent *event) | - | ||||||||||||||||||
639 | { | - | ||||||||||||||||||
640 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
641 | - | |||||||||||||||||||
642 | if (d->buttonState & Keyboard && !event->isAutoRepeat()) { | - | ||||||||||||||||||
643 | d->reset(); | - | ||||||||||||||||||
644 | } else { | - | ||||||||||||||||||
645 | d->edit->event(event); | - | ||||||||||||||||||
646 | } | - | ||||||||||||||||||
647 | } | - | ||||||||||||||||||
648 | - | |||||||||||||||||||
649 | - | |||||||||||||||||||
650 | - | |||||||||||||||||||
651 | - | |||||||||||||||||||
652 | - | |||||||||||||||||||
653 | - | |||||||||||||||||||
654 | void QAbstractSpinBox::wheelEvent(QWheelEvent *event) | - | ||||||||||||||||||
655 | { | - | ||||||||||||||||||
656 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
657 | d->wheelDeltaRemainder += event->angleDelta().y(); | - | ||||||||||||||||||
658 | const int steps = d->wheelDeltaRemainder / 120; | - | ||||||||||||||||||
659 | d->wheelDeltaRemainder -= steps * 120; | - | ||||||||||||||||||
660 | if (stepEnabled() & (steps > 0 ? StepUpEnabled : StepDownEnabled)) | - | ||||||||||||||||||
661 | stepBy(event->modifiers() & Qt::ControlModifier ? steps * 10 : steps); | - | ||||||||||||||||||
662 | event->accept(); | - | ||||||||||||||||||
663 | } | - | ||||||||||||||||||
664 | - | |||||||||||||||||||
665 | - | |||||||||||||||||||
666 | - | |||||||||||||||||||
667 | - | |||||||||||||||||||
668 | - | |||||||||||||||||||
669 | - | |||||||||||||||||||
670 | void QAbstractSpinBox::focusInEvent(QFocusEvent *event) | - | ||||||||||||||||||
671 | { | - | ||||||||||||||||||
672 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
673 | - | |||||||||||||||||||
674 | d->edit->event(event); | - | ||||||||||||||||||
675 | if (event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason) { | - | ||||||||||||||||||
676 | selectAll(); | - | ||||||||||||||||||
677 | } | - | ||||||||||||||||||
678 | QWidget::focusInEvent(event); | - | ||||||||||||||||||
679 | } | - | ||||||||||||||||||
680 | - | |||||||||||||||||||
681 | - | |||||||||||||||||||
682 | - | |||||||||||||||||||
683 | - | |||||||||||||||||||
684 | - | |||||||||||||||||||
685 | void QAbstractSpinBox::focusOutEvent(QFocusEvent *event) | - | ||||||||||||||||||
686 | { | - | ||||||||||||||||||
687 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
688 | - | |||||||||||||||||||
689 | if (d->pendingEmit) | - | ||||||||||||||||||
690 | d->interpret(EmitIfChanged); | - | ||||||||||||||||||
691 | - | |||||||||||||||||||
692 | d->reset(); | - | ||||||||||||||||||
693 | d->edit->event(event); | - | ||||||||||||||||||
694 | d->updateEdit(); | - | ||||||||||||||||||
695 | QWidget::focusOutEvent(event); | - | ||||||||||||||||||
696 | - | |||||||||||||||||||
697 | - | |||||||||||||||||||
698 | - | |||||||||||||||||||
699 | - | |||||||||||||||||||
700 | - | |||||||||||||||||||
701 | editingFinished(); | - | ||||||||||||||||||
702 | } | - | ||||||||||||||||||
703 | - | |||||||||||||||||||
704 | - | |||||||||||||||||||
705 | - | |||||||||||||||||||
706 | - | |||||||||||||||||||
707 | - | |||||||||||||||||||
708 | void QAbstractSpinBox::closeEvent(QCloseEvent *event) | - | ||||||||||||||||||
709 | { | - | ||||||||||||||||||
710 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
711 | - | |||||||||||||||||||
712 | d->reset(); | - | ||||||||||||||||||
713 | if (d->pendingEmit) | - | ||||||||||||||||||
714 | d->interpret(EmitIfChanged); | - | ||||||||||||||||||
715 | QWidget::closeEvent(event); | - | ||||||||||||||||||
716 | } | - | ||||||||||||||||||
717 | - | |||||||||||||||||||
718 | - | |||||||||||||||||||
719 | - | |||||||||||||||||||
720 | - | |||||||||||||||||||
721 | - | |||||||||||||||||||
722 | void QAbstractSpinBox::hideEvent(QHideEvent *event) | - | ||||||||||||||||||
723 | { | - | ||||||||||||||||||
724 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
725 | d->reset(); | - | ||||||||||||||||||
726 | if (d->pendingEmit) | - | ||||||||||||||||||
727 | d->interpret(EmitIfChanged); | - | ||||||||||||||||||
728 | QWidget::hideEvent(event); | - | ||||||||||||||||||
729 | } | - | ||||||||||||||||||
730 | - | |||||||||||||||||||
731 | - | |||||||||||||||||||
732 | - | |||||||||||||||||||
733 | - | |||||||||||||||||||
734 | - | |||||||||||||||||||
735 | - | |||||||||||||||||||
736 | void QAbstractSpinBox::timerEvent(QTimerEvent *event) | - | ||||||||||||||||||
737 | { | - | ||||||||||||||||||
738 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
739 | - | |||||||||||||||||||
740 | bool doStep = false; | - | ||||||||||||||||||
741 | if (event->timerId() == d->spinClickThresholdTimerId) { | - | ||||||||||||||||||
742 | killTimer(d->spinClickThresholdTimerId); | - | ||||||||||||||||||
743 | d->spinClickThresholdTimerId = -1; | - | ||||||||||||||||||
744 | d->effectiveSpinRepeatRate = d->buttonState & Keyboard | - | ||||||||||||||||||
745 | ? QGuiApplication::styleHints()->keyboardAutoRepeatRate() | - | ||||||||||||||||||
746 | : d->spinClickTimerInterval; | - | ||||||||||||||||||
747 | d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate); | - | ||||||||||||||||||
748 | doStep = true; | - | ||||||||||||||||||
749 | } else if (event->timerId() == d->spinClickTimerId) { | - | ||||||||||||||||||
750 | if (d->accelerate) { | - | ||||||||||||||||||
751 | d->acceleration = d->acceleration + (int)(d->effectiveSpinRepeatRate * 0.05); | - | ||||||||||||||||||
752 | if (d->effectiveSpinRepeatRate - d->acceleration >= 10) { | - | ||||||||||||||||||
753 | killTimer(d->spinClickTimerId); | - | ||||||||||||||||||
754 | d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate - d->acceleration); | - | ||||||||||||||||||
755 | } | - | ||||||||||||||||||
756 | } | - | ||||||||||||||||||
757 | doStep = true; | - | ||||||||||||||||||
758 | } | - | ||||||||||||||||||
759 | - | |||||||||||||||||||
760 | if (doStep) { | - | ||||||||||||||||||
761 | const StepEnabled st = stepEnabled(); | - | ||||||||||||||||||
762 | if (d->buttonState & Up) { | - | ||||||||||||||||||
763 | if (!(st & StepUpEnabled)) { | - | ||||||||||||||||||
764 | d->reset(); | - | ||||||||||||||||||
765 | } else { | - | ||||||||||||||||||
766 | stepBy(1); | - | ||||||||||||||||||
767 | } | - | ||||||||||||||||||
768 | } else if (d->buttonState & Down) { | - | ||||||||||||||||||
769 | if (!(st & StepDownEnabled)) { | - | ||||||||||||||||||
770 | d->reset(); | - | ||||||||||||||||||
771 | } else { | - | ||||||||||||||||||
772 | stepBy(-1); | - | ||||||||||||||||||
773 | } | - | ||||||||||||||||||
774 | } | - | ||||||||||||||||||
775 | return; | - | ||||||||||||||||||
776 | } | - | ||||||||||||||||||
777 | QWidget::timerEvent(event); | - | ||||||||||||||||||
778 | return; | - | ||||||||||||||||||
779 | } | - | ||||||||||||||||||
780 | - | |||||||||||||||||||
781 | - | |||||||||||||||||||
782 | - | |||||||||||||||||||
783 | - | |||||||||||||||||||
784 | - | |||||||||||||||||||
785 | void QAbstractSpinBox::contextMenuEvent(QContextMenuEvent *event) | - | ||||||||||||||||||
786 | { | - | ||||||||||||||||||
787 | - | |||||||||||||||||||
788 | - | |||||||||||||||||||
789 | - | |||||||||||||||||||
790 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
791 | - | |||||||||||||||||||
792 | QPointer<QMenu> menu = d->edit->createStandardContextMenu(); | - | ||||||||||||||||||
793 | if (!menu) | - | ||||||||||||||||||
794 | return; | - | ||||||||||||||||||
795 | - | |||||||||||||||||||
796 | d->reset(); | - | ||||||||||||||||||
797 | - | |||||||||||||||||||
798 | QAction *selAll = new QAction(tr("&Select All"), menu); | - | ||||||||||||||||||
799 | menu->insertAction(d->edit->d_func()->selectAllAction, | - | ||||||||||||||||||
800 | selAll); | - | ||||||||||||||||||
801 | menu->removeAction(d->edit->d_func()->selectAllAction); | - | ||||||||||||||||||
802 | menu->addSeparator(); | - | ||||||||||||||||||
803 | const uint se = stepEnabled(); | - | ||||||||||||||||||
804 | QAction *up = menu->addAction(tr("&Step up")); | - | ||||||||||||||||||
805 | up->setEnabled(se & StepUpEnabled); | - | ||||||||||||||||||
806 | QAction *down = menu->addAction(tr("Step &down")); | - | ||||||||||||||||||
807 | down->setEnabled(se & StepDownEnabled); | - | ||||||||||||||||||
808 | menu->addSeparator(); | - | ||||||||||||||||||
809 | - | |||||||||||||||||||
810 | const QPointer<QAbstractSpinBox> that = this; | - | ||||||||||||||||||
811 | const QPoint pos = (event->reason() == QContextMenuEvent::Mouse) | - | ||||||||||||||||||
812 | ? event->globalPos() : mapToGlobal(QPoint(event->pos().x(), 0)) + QPoint(width() / 2, height() / 2); | - | ||||||||||||||||||
813 | const QAction *action = menu->exec(pos); | - | ||||||||||||||||||
814 | delete static_cast<QMenu *>(menu); | - | ||||||||||||||||||
815 | if (that && action) { | - | ||||||||||||||||||
816 | if (action == up) { | - | ||||||||||||||||||
817 | stepBy(1); | - | ||||||||||||||||||
818 | } else if (action == down) { | - | ||||||||||||||||||
819 | stepBy(-1); | - | ||||||||||||||||||
820 | } else if (action == selAll) { | - | ||||||||||||||||||
821 | selectAll(); | - | ||||||||||||||||||
822 | } | - | ||||||||||||||||||
823 | } | - | ||||||||||||||||||
824 | event->accept(); | - | ||||||||||||||||||
825 | - | |||||||||||||||||||
826 | } | - | ||||||||||||||||||
827 | - | |||||||||||||||||||
828 | - | |||||||||||||||||||
829 | - | |||||||||||||||||||
830 | - | |||||||||||||||||||
831 | - | |||||||||||||||||||
832 | void QAbstractSpinBox::mouseMoveEvent(QMouseEvent *event) | - | ||||||||||||||||||
833 | { | - | ||||||||||||||||||
834 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
835 | - | |||||||||||||||||||
836 | d->updateHoverControl(event->pos()); | - | ||||||||||||||||||
837 | - | |||||||||||||||||||
838 | - | |||||||||||||||||||
839 | if (d->spinClickTimerId != -1 && d->buttonSymbols != NoButtons) { | - | ||||||||||||||||||
840 | const StepEnabled se = stepEnabled(); | - | ||||||||||||||||||
841 | if ((se & StepUpEnabled) && d->hoverControl == QStyle::SC_SpinBoxUp) | - | ||||||||||||||||||
842 | d->updateState(true); | - | ||||||||||||||||||
843 | else if ((se & StepDownEnabled) && d->hoverControl == QStyle::SC_SpinBoxDown) | - | ||||||||||||||||||
844 | d->updateState(false); | - | ||||||||||||||||||
845 | else | - | ||||||||||||||||||
846 | d->reset(); | - | ||||||||||||||||||
847 | event->accept(); | - | ||||||||||||||||||
848 | } | - | ||||||||||||||||||
849 | } | - | ||||||||||||||||||
850 | - | |||||||||||||||||||
851 | - | |||||||||||||||||||
852 | - | |||||||||||||||||||
853 | - | |||||||||||||||||||
854 | - | |||||||||||||||||||
855 | void QAbstractSpinBox::mousePressEvent(QMouseEvent *event) | - | ||||||||||||||||||
856 | { | - | ||||||||||||||||||
857 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
858 | - | |||||||||||||||||||
859 | if (event->button() != Qt::LeftButton || d->buttonState != None) { | - | ||||||||||||||||||
860 | return; | - | ||||||||||||||||||
861 | } | - | ||||||||||||||||||
862 | - | |||||||||||||||||||
863 | d->updateHoverControl(event->pos()); | - | ||||||||||||||||||
864 | event->accept(); | - | ||||||||||||||||||
865 | - | |||||||||||||||||||
866 | const StepEnabled se = (d->buttonSymbols == NoButtons) ? StepEnabled(StepNone) : stepEnabled(); | - | ||||||||||||||||||
867 | if ((se & StepUpEnabled) && d->hoverControl == QStyle::SC_SpinBoxUp) { | - | ||||||||||||||||||
868 | d->updateState(true); | - | ||||||||||||||||||
869 | } else if ((se & StepDownEnabled) && d->hoverControl == QStyle::SC_SpinBoxDown) { | - | ||||||||||||||||||
870 | d->updateState(false); | - | ||||||||||||||||||
871 | } else { | - | ||||||||||||||||||
872 | event->ignore(); | - | ||||||||||||||||||
873 | } | - | ||||||||||||||||||
874 | } | - | ||||||||||||||||||
875 | - | |||||||||||||||||||
876 | - | |||||||||||||||||||
877 | - | |||||||||||||||||||
878 | - | |||||||||||||||||||
879 | void QAbstractSpinBox::mouseReleaseEvent(QMouseEvent *event) | - | ||||||||||||||||||
880 | { | - | ||||||||||||||||||
881 | QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
882 | - | |||||||||||||||||||
883 | if ((d->buttonState & Mouse) != 0) | - | ||||||||||||||||||
884 | d->reset(); | - | ||||||||||||||||||
885 | event->accept(); | - | ||||||||||||||||||
886 | } | - | ||||||||||||||||||
887 | QAbstractSpinBoxPrivate::QAbstractSpinBoxPrivate() | - | ||||||||||||||||||
888 | : edit(0), type(QVariant::Invalid), spinClickTimerId(-1), | - | ||||||||||||||||||
889 | spinClickTimerInterval(100), spinClickThresholdTimerId(-1), spinClickThresholdTimerInterval(-1), | - | ||||||||||||||||||
890 | effectiveSpinRepeatRate(1), buttonState(None), cachedText(QLatin1String("\x01")), | - | ||||||||||||||||||
891 | cachedState(QValidator::Invalid), pendingEmit(false), readOnly(false), wrapping(false), | - | ||||||||||||||||||
892 | ignoreCursorPositionChanged(false), frame(true), accelerate(false), keyboardTracking(true), | - | ||||||||||||||||||
893 | cleared(false), ignoreUpdateEdit(false), correctionMode(QAbstractSpinBox::CorrectToPreviousValue), | - | ||||||||||||||||||
894 | acceleration(0), hoverControl(QStyle::SC_None), buttonSymbols(QAbstractSpinBox::UpDownArrows), validator(0), | - | ||||||||||||||||||
895 | showGroupSeparator(0), wheelDeltaRemainder(0) | - | ||||||||||||||||||
896 | { | - | ||||||||||||||||||
897 | } | - | ||||||||||||||||||
898 | - | |||||||||||||||||||
899 | - | |||||||||||||||||||
900 | - | |||||||||||||||||||
901 | - | |||||||||||||||||||
902 | - | |||||||||||||||||||
903 | QAbstractSpinBoxPrivate::~QAbstractSpinBoxPrivate() | - | ||||||||||||||||||
904 | { | - | ||||||||||||||||||
905 | } | - | ||||||||||||||||||
906 | - | |||||||||||||||||||
907 | - | |||||||||||||||||||
908 | - | |||||||||||||||||||
909 | - | |||||||||||||||||||
910 | - | |||||||||||||||||||
911 | - | |||||||||||||||||||
912 | bool QAbstractSpinBoxPrivate::updateHoverControl(const QPoint &pos) | - | ||||||||||||||||||
913 | { | - | ||||||||||||||||||
914 | QAbstractSpinBox * const q = q_func(); | - | ||||||||||||||||||
915 | QRect lastHoverRect = hoverRect; | - | ||||||||||||||||||
916 | QStyle::SubControl lastHoverControl = hoverControl; | - | ||||||||||||||||||
917 | bool doesHover = q->testAttribute(Qt::WA_Hover); | - | ||||||||||||||||||
918 | if (lastHoverControl != newHoverControl(pos) && doesHover) { | - | ||||||||||||||||||
919 | q->update(lastHoverRect); | - | ||||||||||||||||||
920 | q->update(hoverRect); | - | ||||||||||||||||||
921 | return true; | - | ||||||||||||||||||
922 | } | - | ||||||||||||||||||
923 | return !doesHover; | - | ||||||||||||||||||
924 | } | - | ||||||||||||||||||
925 | - | |||||||||||||||||||
926 | - | |||||||||||||||||||
927 | - | |||||||||||||||||||
928 | - | |||||||||||||||||||
929 | - | |||||||||||||||||||
930 | - | |||||||||||||||||||
931 | QStyle::SubControl QAbstractSpinBoxPrivate::newHoverControl(const QPoint &pos) | - | ||||||||||||||||||
932 | { | - | ||||||||||||||||||
933 | QAbstractSpinBox * const q = q_func(); | - | ||||||||||||||||||
934 | - | |||||||||||||||||||
935 | QStyleOptionSpinBox opt; | - | ||||||||||||||||||
936 | q->initStyleOption(&opt); | - | ||||||||||||||||||
937 | opt.subControls = QStyle::SC_All; | - | ||||||||||||||||||
938 | hoverControl = q->style()->hitTestComplexControl(QStyle::CC_SpinBox, &opt, pos, q); | - | ||||||||||||||||||
939 | hoverRect = q->style()->subControlRect(QStyle::CC_SpinBox, &opt, hoverControl, q); | - | ||||||||||||||||||
940 | return hoverControl; | - | ||||||||||||||||||
941 | } | - | ||||||||||||||||||
942 | - | |||||||||||||||||||
943 | - | |||||||||||||||||||
944 | - | |||||||||||||||||||
945 | - | |||||||||||||||||||
946 | - | |||||||||||||||||||
947 | - | |||||||||||||||||||
948 | QString QAbstractSpinBoxPrivate::stripped(const QString &t, int *pos) const | - | ||||||||||||||||||
949 | { | - | ||||||||||||||||||
950 | QStringQStringRef text= t;(&t); | - | ||||||||||||||||||
951 | if (specialValueText.size() == 0
| 0 | ||||||||||||||||||
952 | int from = 0; | - | ||||||||||||||||||
953 | int size = text.size(); | - | ||||||||||||||||||
954 | bool changed = false; | - | ||||||||||||||||||
955 | if (prefix.size()
| 0 | ||||||||||||||||||
956 | from += prefix.size(); | - | ||||||||||||||||||
957 | size -= from; | - | ||||||||||||||||||
958 | changed = true; | - | ||||||||||||||||||
959 | } never executed: end of block | 0 | ||||||||||||||||||
960 | if (suffix.size()
| 0 | ||||||||||||||||||
961 | size -= suffix.size(); | - | ||||||||||||||||||
962 | changed = true; | - | ||||||||||||||||||
963 | } never executed: end of block | 0 | ||||||||||||||||||
964 | if (changed
| 0 | ||||||||||||||||||
965 | text = text.mid(from, size); never executed: text = text.mid(from, size); | 0 | ||||||||||||||||||
966 | } never executed: end of block | 0 | ||||||||||||||||||
967 | - | |||||||||||||||||||
968 | const int s = text.size(); | - | ||||||||||||||||||
969 | text = text.trimmed(); | - | ||||||||||||||||||
970 | if (pos
| 0 | ||||||||||||||||||
971 | (* never executed: pos) -= (s - text.size());(*pos) -= (s - text.size()); never executed: (*pos) -= (s - text.size()); | 0 | ||||||||||||||||||
972 | return never executed: text;.toString();return text.toString(); never executed: return text.toString(); | 0 | ||||||||||||||||||
973 | - | |||||||||||||||||||
974 | } | - | ||||||||||||||||||
975 | - | |||||||||||||||||||
976 | void QAbstractSpinBoxPrivate::updateEditFieldGeometry() | - | ||||||||||||||||||
977 | { | - | ||||||||||||||||||
978 | QAbstractSpinBox * const q = q_func(); | - | ||||||||||||||||||
979 | QStyleOptionSpinBox opt; | - | ||||||||||||||||||
980 | q->initStyleOption(&opt); | - | ||||||||||||||||||
981 | opt.subControls = QStyle::SC_SpinBoxEditField; | - | ||||||||||||||||||
982 | edit->setGeometry(q->style()->subControlRect(QStyle::CC_SpinBox, &opt, | - | ||||||||||||||||||
983 | QStyle::SC_SpinBoxEditField, q)); | - | ||||||||||||||||||
984 | } | - | ||||||||||||||||||
985 | - | |||||||||||||||||||
986 | - | |||||||||||||||||||
987 | - | |||||||||||||||||||
988 | - | |||||||||||||||||||
989 | - | |||||||||||||||||||
990 | bool QAbstractSpinBoxPrivate::specialValue() const | - | ||||||||||||||||||
991 | { | - | ||||||||||||||||||
992 | return (value == minimum && !specialValueText.isEmpty()); | - | ||||||||||||||||||
993 | } | - | ||||||||||||||||||
994 | - | |||||||||||||||||||
995 | - | |||||||||||||||||||
996 | - | |||||||||||||||||||
997 | - | |||||||||||||||||||
998 | - | |||||||||||||||||||
999 | - | |||||||||||||||||||
1000 | void QAbstractSpinBoxPrivate::emitSignals(EmitPolicy, const QVariant &) | - | ||||||||||||||||||
1001 | { | - | ||||||||||||||||||
1002 | } | - | ||||||||||||||||||
1003 | void QAbstractSpinBoxPrivate::_q_editorTextChanged(const QString &t) | - | ||||||||||||||||||
1004 | { | - | ||||||||||||||||||
1005 | QAbstractSpinBox * const q = q_func(); | - | ||||||||||||||||||
1006 | - | |||||||||||||||||||
1007 | if (keyboardTracking) { | - | ||||||||||||||||||
1008 | QString tmp = t; | - | ||||||||||||||||||
1009 | int pos = edit->cursorPosition(); | - | ||||||||||||||||||
1010 | QValidator::State state = q->validate(tmp, pos); | - | ||||||||||||||||||
1011 | if (state == QValidator::Acceptable) { | - | ||||||||||||||||||
1012 | const QVariant v = valueFromText(tmp); | - | ||||||||||||||||||
1013 | setValue(v, EmitIfChanged, tmp != t); | - | ||||||||||||||||||
1014 | pendingEmit = false; | - | ||||||||||||||||||
1015 | } else { | - | ||||||||||||||||||
1016 | pendingEmit = true; | - | ||||||||||||||||||
1017 | } | - | ||||||||||||||||||
1018 | } else { | - | ||||||||||||||||||
1019 | pendingEmit = true; | - | ||||||||||||||||||
1020 | } | - | ||||||||||||||||||
1021 | } | - | ||||||||||||||||||
1022 | void QAbstractSpinBoxPrivate::_q_editorCursorPositionChanged(int oldpos, int newpos) | - | ||||||||||||||||||
1023 | { | - | ||||||||||||||||||
1024 | if (!edit->hasSelectedText() && !ignoreCursorPositionChanged && !specialValue()) { | - | ||||||||||||||||||
1025 | ignoreCursorPositionChanged = true; | - | ||||||||||||||||||
1026 | - | |||||||||||||||||||
1027 | bool allowSelection = true; | - | ||||||||||||||||||
1028 | int pos = -1; | - | ||||||||||||||||||
1029 | if (newpos < prefix.size() && newpos != 0) { | - | ||||||||||||||||||
1030 | if (oldpos == 0) { | - | ||||||||||||||||||
1031 | allowSelection = false; | - | ||||||||||||||||||
1032 | pos = prefix.size(); | - | ||||||||||||||||||
1033 | } else { | - | ||||||||||||||||||
1034 | pos = oldpos; | - | ||||||||||||||||||
1035 | } | - | ||||||||||||||||||
1036 | } else if (newpos > edit->text().size() - suffix.size() | - | ||||||||||||||||||
1037 | && newpos != edit->text().size()) { | - | ||||||||||||||||||
1038 | if (oldpos == edit->text().size()) { | - | ||||||||||||||||||
1039 | pos = edit->text().size() - suffix.size(); | - | ||||||||||||||||||
1040 | allowSelection = false; | - | ||||||||||||||||||
1041 | } else { | - | ||||||||||||||||||
1042 | pos = edit->text().size(); | - | ||||||||||||||||||
1043 | } | - | ||||||||||||||||||
1044 | } | - | ||||||||||||||||||
1045 | if (pos != -1) { | - | ||||||||||||||||||
1046 | const int selSize = edit->selectionStart() >= 0 && allowSelection | - | ||||||||||||||||||
1047 | ? (edit->selectedText().size() | - | ||||||||||||||||||
1048 | * (newpos < pos ? -1 : 1)) - newpos + pos | - | ||||||||||||||||||
1049 | : 0; | - | ||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | const QSignalBlocker blocker(edit); | - | ||||||||||||||||||
1052 | if (selSize != 0) { | - | ||||||||||||||||||
1053 | edit->setSelection(pos - selSize, selSize); | - | ||||||||||||||||||
1054 | } else { | - | ||||||||||||||||||
1055 | edit->setCursorPosition(pos); | - | ||||||||||||||||||
1056 | } | - | ||||||||||||||||||
1057 | } | - | ||||||||||||||||||
1058 | ignoreCursorPositionChanged = false; | - | ||||||||||||||||||
1059 | } | - | ||||||||||||||||||
1060 | } | - | ||||||||||||||||||
1061 | - | |||||||||||||||||||
1062 | - | |||||||||||||||||||
1063 | - | |||||||||||||||||||
1064 | - | |||||||||||||||||||
1065 | - | |||||||||||||||||||
1066 | - | |||||||||||||||||||
1067 | - | |||||||||||||||||||
1068 | void QAbstractSpinBoxPrivate::init() | - | ||||||||||||||||||
1069 | { | - | ||||||||||||||||||
1070 | QAbstractSpinBox * const q = q_func(); | - | ||||||||||||||||||
1071 | - | |||||||||||||||||||
1072 | q->setLineEdit(new QLineEdit(q)); | - | ||||||||||||||||||
1073 | edit->setObjectName(QLatin1String("qt_spinbox_lineedit")); | - | ||||||||||||||||||
1074 | validator = new QSpinBoxValidator(q, this); | - | ||||||||||||||||||
1075 | edit->setValidator(validator); | - | ||||||||||||||||||
1076 | - | |||||||||||||||||||
1077 | QStyleOptionSpinBox opt; | - | ||||||||||||||||||
1078 | q->initStyleOption(&opt); | - | ||||||||||||||||||
1079 | spinClickTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, &opt, q); | - | ||||||||||||||||||
1080 | spinClickThresholdTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatThreshold, &opt, q); | - | ||||||||||||||||||
1081 | q->setFocusPolicy(Qt::WheelFocus); | - | ||||||||||||||||||
1082 | q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, QSizePolicy::SpinBox)); | - | ||||||||||||||||||
1083 | q->setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||
1084 | - | |||||||||||||||||||
1085 | q->setAttribute(Qt::WA_MacShowFocusRect); | - | ||||||||||||||||||
1086 | } | - | ||||||||||||||||||
1087 | void QAbstractSpinBoxPrivate::reset() | - | ||||||||||||||||||
1088 | { | - | ||||||||||||||||||
1089 | QAbstractSpinBox * const q = q_func(); | - | ||||||||||||||||||
1090 | - | |||||||||||||||||||
1091 | buttonState = None; | - | ||||||||||||||||||
1092 | if (q) { | - | ||||||||||||||||||
1093 | if (spinClickTimerId != -1) | - | ||||||||||||||||||
1094 | q->killTimer(spinClickTimerId); | - | ||||||||||||||||||
1095 | if (spinClickThresholdTimerId != -1) | - | ||||||||||||||||||
1096 | q->killTimer(spinClickThresholdTimerId); | - | ||||||||||||||||||
1097 | spinClickTimerId = spinClickThresholdTimerId = -1; | - | ||||||||||||||||||
1098 | acceleration = 0; | - | ||||||||||||||||||
1099 | q->update(); | - | ||||||||||||||||||
1100 | } | - | ||||||||||||||||||
1101 | } | - | ||||||||||||||||||
1102 | - | |||||||||||||||||||
1103 | - | |||||||||||||||||||
1104 | - | |||||||||||||||||||
1105 | - | |||||||||||||||||||
1106 | - | |||||||||||||||||||
1107 | - | |||||||||||||||||||
1108 | - | |||||||||||||||||||
1109 | void QAbstractSpinBoxPrivate::updateState(bool up, bool fromKeyboard ) | - | ||||||||||||||||||
1110 | { | - | ||||||||||||||||||
1111 | QAbstractSpinBox * const q = q_func(); | - | ||||||||||||||||||
1112 | if ((up && (buttonState & Up)) || (!up && (buttonState & Down))) | - | ||||||||||||||||||
1113 | return; | - | ||||||||||||||||||
1114 | reset(); | - | ||||||||||||||||||
1115 | if (q && (q->stepEnabled() & (up ? QAbstractSpinBox::StepUpEnabled | - | ||||||||||||||||||
1116 | : QAbstractSpinBox::StepDownEnabled))) { | - | ||||||||||||||||||
1117 | spinClickThresholdTimerId = q->startTimer(spinClickThresholdTimerInterval); | - | ||||||||||||||||||
1118 | buttonState = (up ? Up : Down) | (fromKeyboard ? Keyboard : Mouse); | - | ||||||||||||||||||
1119 | q->stepBy(up ? 1 : -1); | - | ||||||||||||||||||
1120 | - | |||||||||||||||||||
1121 | QAccessibleValueChangeEvent event(q, value); | - | ||||||||||||||||||
1122 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||
1123 | - | |||||||||||||||||||
1124 | } | - | ||||||||||||||||||
1125 | } | - | ||||||||||||||||||
1126 | void QAbstractSpinBox::initStyleOption(QStyleOptionSpinBox *option) const | - | ||||||||||||||||||
1127 | { | - | ||||||||||||||||||
1128 | if (!option) | - | ||||||||||||||||||
1129 | return; | - | ||||||||||||||||||
1130 | - | |||||||||||||||||||
1131 | const QAbstractSpinBoxPrivate * const d = d_func(); | - | ||||||||||||||||||
1132 | option->initFrom(this); | - | ||||||||||||||||||
1133 | option->activeSubControls = QStyle::SC_None; | - | ||||||||||||||||||
1134 | option->buttonSymbols = d->buttonSymbols; | - | ||||||||||||||||||
1135 | option->subControls = QStyle::SC_SpinBoxFrame | QStyle::SC_SpinBoxEditField; | - | ||||||||||||||||||
1136 | if (d->buttonSymbols != QAbstractSpinBox::NoButtons) { | - | ||||||||||||||||||
1137 | option->subControls |= QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown; | - | ||||||||||||||||||
1138 | if (d->buttonState & Up) { | - | ||||||||||||||||||
1139 | option->activeSubControls = QStyle::SC_SpinBoxUp; | - | ||||||||||||||||||
1140 | } else if (d->buttonState & Down) { | - | ||||||||||||||||||
1141 | option->activeSubControls = QStyle::SC_SpinBoxDown; | - | ||||||||||||||||||
1142 | } | - | ||||||||||||||||||
1143 | } | - | ||||||||||||||||||
1144 | - | |||||||||||||||||||
1145 | if (d->buttonState) { | - | ||||||||||||||||||
1146 | option->state |= QStyle::State_Sunken; | - | ||||||||||||||||||
1147 | } else { | - | ||||||||||||||||||
1148 | option->activeSubControls = d->hoverControl; | - | ||||||||||||||||||
1149 | } | - | ||||||||||||||||||
1150 | - | |||||||||||||||||||
1151 | option->stepEnabled = style()->styleHint(QStyle::SH_SpinControls_DisableOnBounds) | - | ||||||||||||||||||
1152 | ? stepEnabled() | - | ||||||||||||||||||
1153 | : (QAbstractSpinBox::StepDownEnabled|QAbstractSpinBox::StepUpEnabled); | - | ||||||||||||||||||
1154 | - | |||||||||||||||||||
1155 | option->frame = d->frame; | - | ||||||||||||||||||
1156 | } | - | ||||||||||||||||||
1157 | QVariant QAbstractSpinBoxPrivate::bound(const QVariant &val, const QVariant &old, int steps) const | - | ||||||||||||||||||
1158 | { | - | ||||||||||||||||||
1159 | QVariant v = val; | - | ||||||||||||||||||
1160 | if (!wrapping || steps == 0 || old.isNull()) { | - | ||||||||||||||||||
1161 | if (variantCompare(v, minimum) < 0) { | - | ||||||||||||||||||
1162 | v = wrapping ? maximum : minimum; | - | ||||||||||||||||||
1163 | } | - | ||||||||||||||||||
1164 | if (variantCompare(v, maximum) > 0) { | - | ||||||||||||||||||
1165 | v = wrapping ? minimum : maximum; | - | ||||||||||||||||||
1166 | } | - | ||||||||||||||||||
1167 | } else { | - | ||||||||||||||||||
1168 | const bool wasMin = old == minimum; | - | ||||||||||||||||||
1169 | const bool wasMax = old == maximum; | - | ||||||||||||||||||
1170 | const int oldcmp = variantCompare(v, old); | - | ||||||||||||||||||
1171 | const int maxcmp = variantCompare(v, maximum); | - | ||||||||||||||||||
1172 | const int mincmp = variantCompare(v, minimum); | - | ||||||||||||||||||
1173 | const bool wrapped = (oldcmp > 0 && steps < 0) || (oldcmp < 0 && steps > 0); | - | ||||||||||||||||||
1174 | if (maxcmp > 0) { | - | ||||||||||||||||||
1175 | v = ((wasMax && !wrapped && steps > 0) || (steps < 0 && !wasMin && wrapped)) | - | ||||||||||||||||||
1176 | ? minimum : maximum; | - | ||||||||||||||||||
1177 | } else if (wrapped && (maxcmp > 0 || mincmp < 0)) { | - | ||||||||||||||||||
1178 | v = ((wasMax && steps > 0) || (!wasMin && steps < 0)) ? minimum : maximum; | - | ||||||||||||||||||
1179 | } else if (mincmp < 0) { | - | ||||||||||||||||||
1180 | v = (!wasMax && !wasMin ? minimum : maximum); | - | ||||||||||||||||||
1181 | } | - | ||||||||||||||||||
1182 | } | - | ||||||||||||||||||
1183 | - | |||||||||||||||||||
1184 | return v; | - | ||||||||||||||||||
1185 | } | - | ||||||||||||||||||
1186 | void QAbstractSpinBoxPrivate::setValue(const QVariant &val, EmitPolicy ep, | - | ||||||||||||||||||
1187 | bool doUpdate) | - | ||||||||||||||||||
1188 | { | - | ||||||||||||||||||
1189 | QAbstractSpinBox * const q = q_func(); | - | ||||||||||||||||||
1190 | const QVariant old = value; | - | ||||||||||||||||||
1191 | value = bound(val); | - | ||||||||||||||||||
1192 | pendingEmit = false; | - | ||||||||||||||||||
1193 | cleared = false; | - | ||||||||||||||||||
1194 | if (doUpdate) { | - | ||||||||||||||||||
1195 | updateEdit(); | - | ||||||||||||||||||
1196 | } | - | ||||||||||||||||||
1197 | q->update(); | - | ||||||||||||||||||
1198 | - | |||||||||||||||||||
1199 | if (ep == AlwaysEmit || (ep == EmitIfChanged && old != value)) { | - | ||||||||||||||||||
1200 | emitSignals(ep, old); | - | ||||||||||||||||||
1201 | } | - | ||||||||||||||||||
1202 | } | - | ||||||||||||||||||
1203 | - | |||||||||||||||||||
1204 | - | |||||||||||||||||||
1205 | - | |||||||||||||||||||
1206 | - | |||||||||||||||||||
1207 | - | |||||||||||||||||||
1208 | - | |||||||||||||||||||
1209 | - | |||||||||||||||||||
1210 | void QAbstractSpinBoxPrivate::updateEdit() | - | ||||||||||||||||||
1211 | { | - | ||||||||||||||||||
1212 | QAbstractSpinBox * const q = q_func(); | - | ||||||||||||||||||
1213 | if (type == QVariant::Invalid) | - | ||||||||||||||||||
1214 | return; | - | ||||||||||||||||||
1215 | const QString newText = specialValue() ? specialValueText : prefix + textFromValue(value) + suffix; | - | ||||||||||||||||||
1216 | if (newText == edit->displayText() || cleared) | - | ||||||||||||||||||
1217 | return; | - | ||||||||||||||||||
1218 | - | |||||||||||||||||||
1219 | const bool empty = edit->text().isEmpty(); | - | ||||||||||||||||||
1220 | int cursor = edit->cursorPosition(); | - | ||||||||||||||||||
1221 | int selsize = edit->selectedText().size(); | - | ||||||||||||||||||
1222 | const QSignalBlocker blocker(edit); | - | ||||||||||||||||||
1223 | edit->setText(newText); | - | ||||||||||||||||||
1224 | - | |||||||||||||||||||
1225 | if (!specialValue()) { | - | ||||||||||||||||||
1226 | cursor = qBound(prefix.size(), cursor, edit->displayText().size() - suffix.size()); | - | ||||||||||||||||||
1227 | - | |||||||||||||||||||
1228 | if (selsize > 0) { | - | ||||||||||||||||||
1229 | edit->setSelection(cursor, selsize); | - | ||||||||||||||||||
1230 | } else { | - | ||||||||||||||||||
1231 | edit->setCursorPosition(empty ? prefix.size() : cursor); | - | ||||||||||||||||||
1232 | } | - | ||||||||||||||||||
1233 | } | - | ||||||||||||||||||
1234 | q->update(); | - | ||||||||||||||||||
1235 | } | - | ||||||||||||||||||
1236 | - | |||||||||||||||||||
1237 | - | |||||||||||||||||||
1238 | - | |||||||||||||||||||
1239 | - | |||||||||||||||||||
1240 | - | |||||||||||||||||||
1241 | - | |||||||||||||||||||
1242 | - | |||||||||||||||||||
1243 | void QAbstractSpinBoxPrivate::setRange(const QVariant &min, const QVariant &max) | - | ||||||||||||||||||
1244 | { | - | ||||||||||||||||||
1245 | QAbstractSpinBox * const q = q_func(); | - | ||||||||||||||||||
1246 | - | |||||||||||||||||||
1247 | clearCache(); | - | ||||||||||||||||||
1248 | minimum = min; | - | ||||||||||||||||||
1249 | maximum = (variantCompare(min, max) < 0 ? max : min); | - | ||||||||||||||||||
1250 | cachedSizeHint = QSize(); | - | ||||||||||||||||||
1251 | cachedMinimumSizeHint = QSize(); | - | ||||||||||||||||||
1252 | - | |||||||||||||||||||
1253 | reset(); | - | ||||||||||||||||||
1254 | if (!(bound(value) == value)) { | - | ||||||||||||||||||
1255 | setValue(bound(value), EmitIfChanged); | - | ||||||||||||||||||
1256 | } else if (value == minimum && !specialValueText.isEmpty()) { | - | ||||||||||||||||||
1257 | updateEdit(); | - | ||||||||||||||||||
1258 | } | - | ||||||||||||||||||
1259 | - | |||||||||||||||||||
1260 | q->updateGeometry(); | - | ||||||||||||||||||
1261 | } | - | ||||||||||||||||||
1262 | - | |||||||||||||||||||
1263 | - | |||||||||||||||||||
1264 | - | |||||||||||||||||||
1265 | - | |||||||||||||||||||
1266 | - | |||||||||||||||||||
1267 | - | |||||||||||||||||||
1268 | - | |||||||||||||||||||
1269 | QVariant QAbstractSpinBoxPrivate::getZeroVariant() const | - | ||||||||||||||||||
1270 | { | - | ||||||||||||||||||
1271 | QVariant ret; | - | ||||||||||||||||||
1272 | switch (type) { | - | ||||||||||||||||||
1273 | case QVariant::Int: ret = QVariant((int)0); break; | - | ||||||||||||||||||
1274 | case QVariant::Double: ret = QVariant((double)0.0); break; | - | ||||||||||||||||||
1275 | default: break; | - | ||||||||||||||||||
1276 | } | - | ||||||||||||||||||
1277 | return ret; | - | ||||||||||||||||||
1278 | } | - | ||||||||||||||||||
1279 | QString QAbstractSpinBoxPrivate::textFromValue(const QVariant &) const | - | ||||||||||||||||||
1280 | { | - | ||||||||||||||||||
1281 | return QString(); | - | ||||||||||||||||||
1282 | } | - | ||||||||||||||||||
1283 | QVariant QAbstractSpinBoxPrivate::valueFromText(const QString &) const | - | ||||||||||||||||||
1284 | { | - | ||||||||||||||||||
1285 | return QVariant(); | - | ||||||||||||||||||
1286 | } | - | ||||||||||||||||||
1287 | - | |||||||||||||||||||
1288 | - | |||||||||||||||||||
1289 | - | |||||||||||||||||||
1290 | - | |||||||||||||||||||
1291 | - | |||||||||||||||||||
1292 | - | |||||||||||||||||||
1293 | - | |||||||||||||||||||
1294 | void QAbstractSpinBoxPrivate::interpret(EmitPolicy ep) | - | ||||||||||||||||||
1295 | { | - | ||||||||||||||||||
1296 | QAbstractSpinBox * const q = q_func(); | - | ||||||||||||||||||
1297 | if (type == QVariant::Invalid || cleared) | - | ||||||||||||||||||
1298 | return; | - | ||||||||||||||||||
1299 | - | |||||||||||||||||||
1300 | QVariant v = getZeroVariant(); | - | ||||||||||||||||||
1301 | bool doInterpret = true; | - | ||||||||||||||||||
1302 | QString tmp = edit->displayText(); | - | ||||||||||||||||||
1303 | int pos = edit->cursorPosition(); | - | ||||||||||||||||||
1304 | const int oldpos = pos; | - | ||||||||||||||||||
1305 | - | |||||||||||||||||||
1306 | if (q->validate(tmp, pos) != QValidator::Acceptable) { | - | ||||||||||||||||||
1307 | const QString copy = tmp; | - | ||||||||||||||||||
1308 | q->fixup(tmp); | - | ||||||||||||||||||
1309 | if (false) QMessageLogger(__FILE__, 18521858, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" dead code: QMessageLogger(__FILE__, 1858, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" << edit->displayText() << "' >> '" << copy << '\'' << "' >> '" << tmp << '\''; | - | ||||||||||||||||||
1310 | << edit->displayText() dead code: QMessageLogger(__FILE__, 1858, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" << edit->displayText() << "' >> '" << copy << '\'' << "' >> '" << tmp << '\''; | - | ||||||||||||||||||
1311 | << "' >> '" << copy << '\'' dead code: QMessageLogger(__FILE__, 1858, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" << edit->displayText() << "' >> '" << copy << '\'' << "' >> '" << tmp << '\''; | - | ||||||||||||||||||
1312 | << "' >> '" << tmp << '\''; dead code: QMessageLogger(__FILE__, 1858, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" << edit->displayText() << "' >> '" << copy << '\'' << "' >> '" << tmp << '\''; | - | ||||||||||||||||||
1313 | - | |||||||||||||||||||
1314 | doInterpret = tmp != copy && (q->validate(tmp, pos) == QValidator::Acceptable); | - | ||||||||||||||||||
1315 | if (!doInterpret) { | - | ||||||||||||||||||
1316 | v = (correctionMode == QAbstractSpinBox::CorrectToNearestValue | - | ||||||||||||||||||
1317 | ? variantBound(minimum, v, maximum) : value); | - | ||||||||||||||||||
1318 | } | - | ||||||||||||||||||
1319 | } | - | ||||||||||||||||||
1320 | if (doInterpret) { | - | ||||||||||||||||||
1321 | v = valueFromText(tmp); | - | ||||||||||||||||||
1322 | } | - | ||||||||||||||||||
1323 | clearCache(); | - | ||||||||||||||||||
1324 | setValue(v, ep, true); | - | ||||||||||||||||||
1325 | if (oldpos != pos) | - | ||||||||||||||||||
1326 | edit->setCursorPosition(pos); | - | ||||||||||||||||||
1327 | } | - | ||||||||||||||||||
1328 | - | |||||||||||||||||||
1329 | void QAbstractSpinBoxPrivate::clearCache() const | - | ||||||||||||||||||
1330 | { | - | ||||||||||||||||||
1331 | cachedText.clear(); | - | ||||||||||||||||||
1332 | cachedValue.clear(); | - | ||||||||||||||||||
1333 | cachedState = QValidator::Acceptable; | - | ||||||||||||||||||
1334 | } | - | ||||||||||||||||||
1335 | QSpinBoxValidator::QSpinBoxValidator(QAbstractSpinBox *qp, QAbstractSpinBoxPrivate *dp) | - | ||||||||||||||||||
1336 | : QValidator(qp), qptr(qp), dptr(dp) | - | ||||||||||||||||||
1337 | { | - | ||||||||||||||||||
1338 | setObjectName(QLatin1String("qt_spinboxvalidator")); | - | ||||||||||||||||||
1339 | } | - | ||||||||||||||||||
1340 | QValidator::State QSpinBoxValidator::validate(QString &input, int &pos) const | - | ||||||||||||||||||
1341 | { | - | ||||||||||||||||||
1342 | if (dptr->specialValueText.size() > 0 && input == dptr->specialValueText) | - | ||||||||||||||||||
1343 | return QValidator::Acceptable; | - | ||||||||||||||||||
1344 | - | |||||||||||||||||||
1345 | if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix)) { | - | ||||||||||||||||||
1346 | input.prepend(dptr->prefix); | - | ||||||||||||||||||
1347 | pos += dptr->prefix.length(); | - | ||||||||||||||||||
1348 | } | - | ||||||||||||||||||
1349 | - | |||||||||||||||||||
1350 | if (!dptr->suffix.isEmpty() && !input.endsWith(dptr->suffix)) | - | ||||||||||||||||||
1351 | input.append(dptr->suffix); | - | ||||||||||||||||||
1352 | - | |||||||||||||||||||
1353 | return qptr->validate(input, pos); | - | ||||||||||||||||||
1354 | } | - | ||||||||||||||||||
1355 | - | |||||||||||||||||||
1356 | - | |||||||||||||||||||
1357 | - | |||||||||||||||||||
1358 | - | |||||||||||||||||||
1359 | - | |||||||||||||||||||
1360 | void QSpinBoxValidator::fixup(QString &input) const | - | ||||||||||||||||||
1361 | { | - | ||||||||||||||||||
1362 | qptr->fixup(input); | - | ||||||||||||||||||
1363 | } | - | ||||||||||||||||||
1364 | QVariant operator+(const QVariant &arg1, const QVariant &arg2) | - | ||||||||||||||||||
1365 | { | - | ||||||||||||||||||
1366 | QVariant ret; | - | ||||||||||||||||||
1367 | if (__builtin_expect(!!(
| 0 | ||||||||||||||||||
1368 | QMessageLogger(__FILE__, 19361942, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", never executed: QMessageLogger(__FILE__, 1942, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, 1943); | 0 | ||||||||||||||||||
1369 | arg1.typeName(), arg2.typeName(), __FILE__, 19371943); never executed: QMessageLogger(__FILE__, 1942, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, 1943); | 0 | ||||||||||||||||||
1370 | switch (arg1.type()) { | - | ||||||||||||||||||
1371 | case never executed: QVariant::Int:case QVariant::Int: never executed: {case QVariant::Int: | 0 | ||||||||||||||||||
1372 | const int int1 = arg1.toInt(); | - | ||||||||||||||||||
1373 | const int int2 = arg2.toInt(); | - | ||||||||||||||||||
1374 | if (int1 > 0
| 0 | ||||||||||||||||||
1375 | - | |||||||||||||||||||
1376 | ret = QVariant(2147483647); | - | ||||||||||||||||||
1377 | } never executed: else if (int1 < 0end of block
| 0 | ||||||||||||||||||
1378 | - | |||||||||||||||||||
1379 | ret = QVariant((-2147483647 - 1)); | - | ||||||||||||||||||
1380 | } never executed: else {end of block | 0 | ||||||||||||||||||
1381 | ret = QVariant(int1 + int2); | - | ||||||||||||||||||
1382 | } never executed: end of block | 0 | ||||||||||||||||||
1383 | break; never executed: break; | 0 | ||||||||||||||||||
1384 | } | - | ||||||||||||||||||
1385 | case never executed: QVariant::Double:case QVariant::Double: never executed: ret = QVariant(arg1.toDouble() + arg2.toDouble()); break;case QVariant::Double: never executed: break; | 0 | ||||||||||||||||||
1386 | case never executed: QVariant::DateTime:case QVariant::DateTime: never executed: {case QVariant::DateTime: | 0 | ||||||||||||||||||
1387 | QDateTime a2 = arg2.toDateTime(); | - | ||||||||||||||||||
1388 | QDateTime a1 = arg1.toDateTime().addDays(QDateTime(QDate(100, 1, 1), QTime(0, 0, 0, 0)).daysTo(a2)); | - | ||||||||||||||||||
1389 | a1.setTime(a1.time().addMSecs(QTime().msecsTo(a2.time()))); | - | ||||||||||||||||||
1390 | ret = QVariant(a1); | - | ||||||||||||||||||
1391 | } | - | ||||||||||||||||||
1392 | default never executed: :default: never executed: default: code before this statement never executed: break;default: never executed: break; | 0 | ||||||||||||||||||
1393 | } | - | ||||||||||||||||||
1394 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||
1395 | } | - | ||||||||||||||||||
1396 | - | |||||||||||||||||||
1397 | - | |||||||||||||||||||
1398 | - | |||||||||||||||||||
1399 | - | |||||||||||||||||||
1400 | - | |||||||||||||||||||
1401 | - | |||||||||||||||||||
1402 | - | |||||||||||||||||||
1403 | QVariant operator-(const QVariant &arg1, const QVariant &arg2) | - | ||||||||||||||||||
1404 | { | - | ||||||||||||||||||
1405 | QVariant ret; | - | ||||||||||||||||||
1406 | if (__builtin_expect(!!(
| 0 | ||||||||||||||||||
1407 | QMessageLogger(__FILE__, 19751981, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", never executed: QMessageLogger(__FILE__, 1981, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, 1982); | 0 | ||||||||||||||||||
1408 | arg1.typeName(), arg2.typeName(), __FILE__, 19761982); never executed: QMessageLogger(__FILE__, 1981, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, 1982); | 0 | ||||||||||||||||||
1409 | switch (arg1.type()) { | - | ||||||||||||||||||
1410 | case never executed: QVariant::Int:case QVariant::Int: never executed: ret = QVariant(arg1.toInt() - arg2.toInt()); break;case QVariant::Int: never executed: break; | 0 | ||||||||||||||||||
1411 | case never executed: QVariant::Double:case QVariant::Double: never executed: ret = QVariant(arg1.toDouble() - arg2.toDouble()); break;case QVariant::Double: never executed: break; | 0 | ||||||||||||||||||
1412 | case never executed: QVariant::DateTime:case QVariant::DateTime: never executed: {case QVariant::DateTime: | 0 | ||||||||||||||||||
1413 | QDateTime a1 = arg1.toDateTime(); | - | ||||||||||||||||||
1414 | QDateTime a2 = arg2.toDateTime(); | - | ||||||||||||||||||
1415 | int days = a2.daysTo(a1); | - | ||||||||||||||||||
1416 | int secs = a2.secsTo(a1); | - | ||||||||||||||||||
1417 | int msecs = qMax(0, a1.time().msec() - a2.time().msec()); | - | ||||||||||||||||||
1418 | if (days < 0
| 0 | ||||||||||||||||||
1419 | ret = arg1; | - | ||||||||||||||||||
1420 | } never executed: else {end of block | 0 | ||||||||||||||||||
1421 | QDateTime dt = a2.addDays(days).addSecs(secs); | - | ||||||||||||||||||
1422 | if (msecs > 0
| 0 | ||||||||||||||||||
1423 | dt.setTime(dt.time().addMSecs(msecs)); never executed: dt.setTime(dt.time().addMSecs(msecs)); | 0 | ||||||||||||||||||
1424 | ret = QVariant(dt); | - | ||||||||||||||||||
1425 | } never executed: end of block | 0 | ||||||||||||||||||
1426 | } | - | ||||||||||||||||||
1427 | default never executed: :default: never executed: default: code before this statement never executed: break;default: never executed: break; | 0 | ||||||||||||||||||
1428 | } | - | ||||||||||||||||||
1429 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||
1430 | } | - | ||||||||||||||||||
1431 | - | |||||||||||||||||||
1432 | - | |||||||||||||||||||
1433 | - | |||||||||||||||||||
1434 | - | |||||||||||||||||||
1435 | - | |||||||||||||||||||
1436 | - | |||||||||||||||||||
1437 | QVariant operator*(const QVariant &arg1, double multiplier) | - | ||||||||||||||||||
1438 | { | - | ||||||||||||||||||
1439 | QVariant ret; | - | ||||||||||||||||||
1440 | - | |||||||||||||||||||
1441 | switch (arg1.type()) { | - | ||||||||||||||||||
1442 | case QVariant::Int: | - | ||||||||||||||||||
1443 | ret = static_cast<int>(qBound<double>((-2147483647 - 1), arg1.toInt() * multiplier, 2147483647)); | - | ||||||||||||||||||
1444 | break; | - | ||||||||||||||||||
1445 | case QVariant::Double: ret = QVariant(arg1.toDouble() * multiplier); break; | - | ||||||||||||||||||
1446 | case QVariant::DateTime: { | - | ||||||||||||||||||
1447 | double days = QDate(100, 1, 1).daysTo(arg1.toDateTime().date()) * multiplier; | - | ||||||||||||||||||
1448 | int daysInt = (int)days; | - | ||||||||||||||||||
1449 | days -= daysInt; | - | ||||||||||||||||||
1450 | long msecs = (long)((QTime(0, 0, 0, 0).msecsTo(arg1.toDateTime().time()) * multiplier) | - | ||||||||||||||||||
1451 | + (days * (24 * 3600 * 1000))); | - | ||||||||||||||||||
1452 | ret = QDateTime(QDate().addDays(int(days)), QTime().addMSecs(msecs)); | - | ||||||||||||||||||
1453 | break; | - | ||||||||||||||||||
1454 | } | - | ||||||||||||||||||
1455 | default: ret = arg1; break; | - | ||||||||||||||||||
1456 | } | - | ||||||||||||||||||
1457 | - | |||||||||||||||||||
1458 | return ret; | - | ||||||||||||||||||
1459 | } | - | ||||||||||||||||||
1460 | - | |||||||||||||||||||
1461 | - | |||||||||||||||||||
1462 | - | |||||||||||||||||||
1463 | double operator/(const QVariant &arg1, const QVariant &arg2) | - | ||||||||||||||||||
1464 | { | - | ||||||||||||||||||
1465 | double a1 = 0; | - | ||||||||||||||||||
1466 | double a2 = 0; | - | ||||||||||||||||||
1467 | - | |||||||||||||||||||
1468 | switch (arg1.type()) { | - | ||||||||||||||||||
1469 | case QVariant::Int: | - | ||||||||||||||||||
1470 | a1 = (double)arg1.toInt(); | - | ||||||||||||||||||
1471 | a2 = (double)arg2.toInt(); | - | ||||||||||||||||||
1472 | break; | - | ||||||||||||||||||
1473 | case QVariant::Double: | - | ||||||||||||||||||
1474 | a1 = arg1.toDouble(); | - | ||||||||||||||||||
1475 | a2 = arg2.toDouble(); | - | ||||||||||||||||||
1476 | break; | - | ||||||||||||||||||
1477 | case QVariant::DateTime: | - | ||||||||||||||||||
1478 | a1 = QDate(100, 1, 1).daysTo(arg1.toDate()); | - | ||||||||||||||||||
1479 | a2 = QDate(100, 1, 1).daysTo(arg2.toDate()); | - | ||||||||||||||||||
1480 | a1 += (double)QTime(0, 0, 0, 0).msecsTo(arg1.toDateTime().time()) / (long)(3600 * 24 * 1000); | - | ||||||||||||||||||
1481 | a2 += (double)QTime(0, 0, 0, 0).msecsTo(arg2.toDateTime().time()) / (long)(3600 * 24 * 1000); | - | ||||||||||||||||||
1482 | default: break; | - | ||||||||||||||||||
1483 | } | - | ||||||||||||||||||
1484 | - | |||||||||||||||||||
1485 | return (a1 != 0 && a2 != 0) ? (a1 / a2) : 0.0; | - | ||||||||||||||||||
1486 | } | - | ||||||||||||||||||
1487 | - | |||||||||||||||||||
1488 | int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant &arg2) | - | ||||||||||||||||||
1489 | { | - | ||||||||||||||||||
1490 | switch (arg2.type()) { | - | ||||||||||||||||||
1491 | case QVariant::Date: | - | ||||||||||||||||||
1492 | ((!(arg1.type() == QVariant::Date)) ? qt_assert_x("QAbstractSpinBoxPrivate::variantCompare", QString(QString::fromLatin1("Internal error 1 (%1)"). arg(QString::fromLatin1(arg1.typeName()))).toLocal8Bit().constData(), | - | ||||||||||||||||||
1493 | - | |||||||||||||||||||
1494 | __FILE__ | - | ||||||||||||||||||
1495 | , | - | ||||||||||||||||||
1496 | - | |||||||||||||||||||
1497 | 20622068 | - | ||||||||||||||||||
1498 | ) : qt_noop()) | - | ||||||||||||||||||
1499 | - | |||||||||||||||||||
1500 | ; | - | ||||||||||||||||||
1501 | if (arg1.toDate() == arg2.toDate()) { | - | ||||||||||||||||||
1502 | return 0; | - | ||||||||||||||||||
1503 | } else if (arg1.toDate() < arg2.toDate()) { | - | ||||||||||||||||||
1504 | return -1; | - | ||||||||||||||||||
1505 | } else { | - | ||||||||||||||||||
1506 | return 1; | - | ||||||||||||||||||
1507 | } | - | ||||||||||||||||||
1508 | case QVariant::Time: | - | ||||||||||||||||||
1509 | ((!(arg1.type() == QVariant::Time)) ? qt_assert_x("QAbstractSpinBoxPrivate::variantCompare", QString(QString::fromLatin1("Internal error 2 (%1)"). arg(QString::fromLatin1(arg1.typeName()))).toLocal8Bit().constData(), | - | ||||||||||||||||||
1510 | - | |||||||||||||||||||
1511 | __FILE__ | - | ||||||||||||||||||
1512 | , | - | ||||||||||||||||||
1513 | - | |||||||||||||||||||
1514 | 20732079 | - | ||||||||||||||||||
1515 | ) : qt_noop()) | - | ||||||||||||||||||
1516 | - | |||||||||||||||||||
1517 | ; | - | ||||||||||||||||||
1518 | if (arg1.toTime() == arg2.toTime()) { | - | ||||||||||||||||||
1519 | return 0; | - | ||||||||||||||||||
1520 | } else if (arg1.toTime() < arg2.toTime()) { | - | ||||||||||||||||||
1521 | return -1; | - | ||||||||||||||||||
1522 | } else { | - | ||||||||||||||||||
1523 | return 1; | - | ||||||||||||||||||
1524 | } | - | ||||||||||||||||||
1525 | - | |||||||||||||||||||
1526 | - | |||||||||||||||||||
1527 | case QVariant::DateTime: | - | ||||||||||||||||||
1528 | if (arg1.toDateTime() == arg2.toDateTime()) { | - | ||||||||||||||||||
1529 | return 0; | - | ||||||||||||||||||
1530 | } else if (arg1.toDateTime() < arg2.toDateTime()) { | - | ||||||||||||||||||
1531 | return -1; | - | ||||||||||||||||||
1532 | } else { | - | ||||||||||||||||||
1533 | return 1; | - | ||||||||||||||||||
1534 | } | - | ||||||||||||||||||
1535 | case QVariant::Int: | - | ||||||||||||||||||
1536 | if (arg1.toInt() == arg2.toInt()) { | - | ||||||||||||||||||
1537 | return 0; | - | ||||||||||||||||||
1538 | } else if (arg1.toInt() < arg2.toInt()) { | - | ||||||||||||||||||
1539 | return -1; | - | ||||||||||||||||||
1540 | } else { | - | ||||||||||||||||||
1541 | return 1; | - | ||||||||||||||||||
1542 | } | - | ||||||||||||||||||
1543 | case QVariant::Double: | - | ||||||||||||||||||
1544 | if (arg1.toDouble() == arg2.toDouble()) { | - | ||||||||||||||||||
1545 | return 0; | - | ||||||||||||||||||
1546 | } else if (arg1.toDouble() < arg2.toDouble()) { | - | ||||||||||||||||||
1547 | return -1; | - | ||||||||||||||||||
1548 | } else { | - | ||||||||||||||||||
1549 | return 1; | - | ||||||||||||||||||
1550 | } | - | ||||||||||||||||||
1551 | case QVariant::Invalid: | - | ||||||||||||||||||
1552 | if (arg2.type() == QVariant::Invalid) | - | ||||||||||||||||||
1553 | return 0; | - | ||||||||||||||||||
1554 | default: | - | ||||||||||||||||||
1555 | ((!(0)) ? qt_assert_x("QAbstractSpinBoxPrivate::variantCompare", QString(QString::fromLatin1("Internal error 3 (%1 %2)"). arg(QString::fromLatin1(arg1.typeName())). arg(QString::fromLatin1(arg2.typeName()))).toLocal8Bit().constData(), | - | ||||||||||||||||||
1556 | - | |||||||||||||||||||
1557 | - | |||||||||||||||||||
1558 | __FILE__ | - | ||||||||||||||||||
1559 | , | - | ||||||||||||||||||
1560 | - | |||||||||||||||||||
1561 | - | |||||||||||||||||||
1562 | 21142120 | - | ||||||||||||||||||
1563 | ) : qt_noop()) | - | ||||||||||||||||||
1564 | - | |||||||||||||||||||
1565 | - | |||||||||||||||||||
1566 | ; | - | ||||||||||||||||||
1567 | } | - | ||||||||||||||||||
1568 | return -2; | - | ||||||||||||||||||
1569 | } | - | ||||||||||||||||||
1570 | - | |||||||||||||||||||
1571 | QVariant QAbstractSpinBoxPrivate::variantBound(const QVariant &min, | - | ||||||||||||||||||
1572 | const QVariant &value, | - | ||||||||||||||||||
1573 | const QVariant &max) | - | ||||||||||||||||||
1574 | { | - | ||||||||||||||||||
1575 | ((!(variantCompare(min, max) <= 0)) ? qt_assert("variantCompare(min, max) <= 0",__FILE__,21232129) : qt_noop()); | - | ||||||||||||||||||
1576 | if (variantCompare(min, value) < 0) { | - | ||||||||||||||||||
1577 | const int compMax = variantCompare(value, max); | - | ||||||||||||||||||
1578 | return (compMax < 0 ? value : max); | - | ||||||||||||||||||
1579 | } else { | - | ||||||||||||||||||
1580 | return min; | - | ||||||||||||||||||
1581 | } | - | ||||||||||||||||||
1582 | } | - | ||||||||||||||||||
1583 | - | |||||||||||||||||||
1584 | - | |||||||||||||||||||
1585 | - | |||||||||||||||||||
1586 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |