Qt 4.8
qabstractspinbox.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <qplatformdefs.h>
43 #include <private/qabstractspinbox_p.h>
44 #include <private/qdatetime_p.h>
45 #include <private/qlineedit_p.h>
46 #include <qabstractspinbox.h>
47 
48 #ifndef QT_NO_SPINBOX
49 
50 #include <qapplication.h>
51 #include <qclipboard.h>
52 #include <qdatetime.h>
53 #include <qdatetimeedit.h>
54 #include <qevent.h>
55 #include <qmenu.h>
56 #include <qpainter.h>
57 #include <qpalette.h>
58 #include <qstylepainter.h>
59 #include <qdebug.h>
60 #ifndef QT_NO_ACCESSIBILITY
61 # include <qaccessible.h>
62 #endif
63 
64 #if defined(Q_WS_X11)
65 #include <limits.h>
66 #endif
67 
68 #if defined(Q_OS_SYMBIAN)
69 #include <w32std.h>
70 #include <private/qt_s60_p.h>
71 #endif
72 
73 //#define QABSTRACTSPINBOX_QSBDEBUG
74 #ifdef QABSTRACTSPINBOX_QSBDEBUG
75 # define QASBDEBUG qDebug
76 #else
77 # define QASBDEBUG if (false) qDebug
78 #endif
79 
81 
145  : QWidget(*new QAbstractSpinBoxPrivate, parent, 0)
146 {
148  d->init();
149 }
150 
155  : QWidget(dd, parent, 0)
156 {
158  d->init();
159 }
160 
166 {
167 }
168 
206 {
207  Q_D(const QAbstractSpinBox);
208  return d->buttonSymbols;
209 }
210 
212 {
214  if (d->buttonSymbols != buttonSymbols) {
215  d->buttonSymbols = buttonSymbols;
216  d->updateEditFieldGeometry();
217  update();
218  }
219 }
220 
233 {
234  return lineEdit()->displayText();
235 }
236 
237 
275 {
276  Q_D(const QAbstractSpinBox);
277  return d->specialValueText;
278 }
279 
281 {
283 
284  d->specialValueText = specialValueText;
285  d->cachedSizeHint = QSize(); // minimumSizeHint doesn't care about specialValueText
286  d->clearCache();
287  d->updateEdit();
288 }
289 
307 bool QAbstractSpinBox::wrapping() const
308 {
309  Q_D(const QAbstractSpinBox);
310  return d->wrapping;
311 }
312 
314 {
316  d->wrapping = wrapping;
317 }
318 
319 
338 {
339  Q_D(const QAbstractSpinBox);
340  return d->readOnly;
341 }
342 
344 {
346  d->readOnly = enable;
347  d->edit->setReadOnly(enable);
348  update();
349 }
350 
375 {
376  Q_D(const QAbstractSpinBox);
377  return d->keyboardTracking;
378 }
379 
381 {
383  d->keyboardTracking = enable;
384 }
385 
398 {
399  Q_D(const QAbstractSpinBox);
400  return d->frame;
401 }
402 
403 
404 void QAbstractSpinBox::setFrame(bool enable)
405 {
407  d->frame = enable;
408  update();
409  d->updateEditFieldGeometry();
410 }
411 
425 void QAbstractSpinBox::setAccelerated(bool accelerate)
426 {
428  d->accelerate = accelerate;
429 
430 }
432 {
433  Q_D(const QAbstractSpinBox);
434  return d->accelerate;
435 }
436 
469 {
471  d->correctionMode = correctionMode;
472 
473 }
475 {
476  Q_D(const QAbstractSpinBox);
477  return d->correctionMode;
478 }
479 
480 
493 {
494  Q_D(const QAbstractSpinBox);
495  return d->edit->hasAcceptableInput();
496 }
497 
515 Qt::Alignment QAbstractSpinBox::alignment() const
516 {
517  Q_D(const QAbstractSpinBox);
518 
519  return (Qt::Alignment)d->edit->alignment();
520 }
521 
522 void QAbstractSpinBox::setAlignment(Qt::Alignment flag)
523 {
525 
526  d->edit->setAlignment(flag);
527 }
528 
534 {
536 
537 
538  if (!d->specialValue()) {
539  const int tmp = d->edit->displayText().size() - d->suffix.size();
540  d->edit->setSelection(tmp, -(tmp - d->prefix.size()));
541  } else {
542  d->edit->selectAll();
543  }
544 }
545 
551 {
553 
554  d->edit->setText(d->prefix + d->suffix);
555  d->edit->setCursorPosition(d->prefix.size());
556  d->cleared = true;
557 }
558 
577 QAbstractSpinBox::StepEnabled QAbstractSpinBox::stepEnabled() const
578 {
579  Q_D(const QAbstractSpinBox);
580  if (d->readOnly || d->type == QVariant::Invalid)
581  return StepNone;
582  if (d->wrapping)
583  return StepEnabled(StepUpEnabled | StepDownEnabled);
584  StepEnabled ret = StepNone;
585  if (d->variantCompare(d->value, d->maximum) < 0) {
586  ret |= StepUpEnabled;
587  }
588  if (d->variantCompare(d->value, d->minimum) > 0) {
589  ret |= StepDownEnabled;
590  }
591  return ret;
592 }
593 
601 QValidator::State QAbstractSpinBox::validate(QString & /* input */, int & /* pos */) const
602 {
603  return QValidator::Acceptable;
604 }
605 
613 void QAbstractSpinBox::fixup(QString & /* input */) const
614 {
615 }
616 
624 {
625  stepBy(1);
626 }
627 
635 {
636  stepBy(-1);
637 }
652 {
654 
655  const QVariant old = d->value;
656  QString tmp = d->edit->displayText();
657  int cursorPos = d->edit->cursorPosition();
658  bool dontstep = false;
660  if (d->pendingEmit) {
661  dontstep = validate(tmp, cursorPos) != QValidator::Acceptable;
662  d->cleared = false;
663  d->interpret(NeverEmit);
664  if (d->value != old)
665  e = AlwaysEmit;
666  }
667  if (!dontstep) {
668  d->setValue(d->bound(d->value + (d->singleStep * steps), old, steps), e);
669  } else if (e == AlwaysEmit) {
670  d->emitSignals(e, old);
671  }
672  selectAll();
673 }
674 
680 {
681  Q_D(const QAbstractSpinBox);
682 
683  return d->edit;
684 }
685 
686 
700 {
702 
703  if (!lineEdit) {
704  Q_ASSERT(lineEdit);
705  return;
706  }
707  delete d->edit;
708  d->edit = lineEdit;
709  if (!d->edit->validator())
710  d->edit->setValidator(d->validator);
711 
712  if (d->edit->parent() != this)
713  d->edit->setParent(this);
714 
715  d->edit->setFrame(false);
716  d->edit->setFocusProxy(this);
717  d->edit->setAcceptDrops(false);
718 
719  if (d->type != QVariant::Invalid) {
720  connect(d->edit, SIGNAL(textChanged(QString)),
721  this, SLOT(_q_editorTextChanged(QString)));
722  connect(d->edit, SIGNAL(cursorPositionChanged(int,int)),
723  this, SLOT(_q_editorCursorPositionChanged(int,int)));
724  }
725  d->updateEditFieldGeometry();
726  d->edit->setContextMenuPolicy(Qt::NoContextMenu);
727 
728  if (isVisible())
729  d->edit->show();
730  if (isVisible())
731  d->updateEdit();
732 }
733 
734 
741 {
743  d->interpret(EmitIfChanged);
744 }
745 
746 /*
747  Reimplemented in 4.6, so be careful.
748  */
753 {
754  Q_D(const QAbstractSpinBox);
755  return d->edit->inputMethodQuery(query);
756 }
757 
763 {
765  switch (event->type()) {
766  case QEvent::FontChange:
767  case QEvent::StyleChange:
768  d->cachedSizeHint = d->cachedMinimumSizeHint = QSize();
769  break;
772  d->updateEditFieldGeometry();
773  break;
774  case QEvent::HoverEnter:
775  case QEvent::HoverLeave:
776  case QEvent::HoverMove:
777  if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
778  d->updateHoverControl(he->pos());
779  break;
781  if (d->edit->event(event))
782  return true;
783  break;
784 #ifdef QT_KEYPAD_NAVIGATION
785  case QEvent::EnterEditFocus:
786  case QEvent::LeaveEditFocus:
787  if (QApplication::keypadNavigationEnabled()) {
788  const bool b = d->edit->event(event);
789  d->edit->setSelection(d->edit->displayText().size() - d->suffix.size(),0);
790  if (event->type() == QEvent::LeaveEditFocus)
792  if (b)
793  return true;
794  }
795  break;
796 #endif
797  case QEvent::InputMethod:
798  return d->edit->event(event);
799  default:
800  break;
801  }
802  return QWidget::event(event);
803 }
804 
810 {
812  d->reset();
813 
814  if (d->ignoreUpdateEdit) {
815  d->ignoreUpdateEdit = false;
816  } else {
817  d->updateEdit();
818  }
819 }
820 
826 {
828 
829  switch (event->type()) {
830  case QEvent::StyleChange:
831  d->spinClickTimerInterval = style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, 0, this);
832  d->spinClickThresholdTimerInterval =
834  d->reset();
835  d->updateEditFieldGeometry();
836  break;
838  if (!isEnabled()) {
839  d->reset();
840  }
841  break;
843  if (!isActiveWindow()){
844  d->reset();
845  if (d->pendingEmit) // pendingEmit can be true even if it hasn't changed.
846  d->interpret(EmitIfChanged); // E.g. 10 to 10.0
847  }
848  break;
849  default:
850  break;
851  }
852  QWidget::changeEvent(event);
853 }
854 
860 {
862  QWidget::resizeEvent(event);
863 
864  d->updateEditFieldGeometry();
865  update();
866 }
867 
873 {
874  Q_D(const QAbstractSpinBox);
875  if (d->cachedSizeHint.isEmpty()) {
876  ensurePolished();
877 
878  const QFontMetrics fm(fontMetrics());
879  int h = d->edit->sizeHint().height();
880  int w = 0;
881  QString s;
882  s = d->prefix + d->textFromValue(d->minimum) + d->suffix + QLatin1Char(' ');
883  s.truncate(18);
884  w = qMax(w, fm.width(s));
885  s = d->prefix + d->textFromValue(d->maximum) + d->suffix + QLatin1Char(' ');
886  s.truncate(18);
887  w = qMax(w, fm.width(s));
888  if (d->specialValueText.size()) {
889  s = d->specialValueText;
890  w = qMax(w, fm.width(s));
891  }
892  w += 2; // cursor blinking space
893 
895  initStyleOption(&opt);
896  QSize hint(w, h);
897  QSize extra(35, 6);
898  opt.rect.setSize(hint + extra);
899  extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
901  // get closer to final result by repeating the calculation
902  opt.rect.setSize(hint + extra);
903  extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
905  hint += extra;
906 
907  opt.rect = rect();
908  d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this)
910  }
911  return d->cachedSizeHint;
912 }
913 
919 {
920  Q_D(const QAbstractSpinBox);
921  if (d->cachedMinimumSizeHint.isEmpty()) {
922  ensurePolished();
923 
924  const QFontMetrics fm(fontMetrics());
925  int h = d->edit->minimumSizeHint().height();
926  int w = fm.width(QLatin1String("1000"));
927  w += 2; // cursor blinking space
928 
930  initStyleOption(&opt);
931  QSize hint(w, h);
932  QSize extra(35, 6);
933  opt.rect.setSize(hint + extra);
934  extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
936  // get closer to final result by repeating the calculation
937  opt.rect.setSize(hint + extra);
938  extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
940  hint += extra;
941 
942  opt.rect = rect();
943 
944  d->cachedMinimumSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this)
946  }
947  return d->cachedMinimumSizeHint;
948 }
949 
955 {
957  initStyleOption(&opt);
958  QStylePainter p(this);
960 }
961 
988 {
990 
991  if (!event->text().isEmpty() && d->edit->cursorPosition() < d->prefix.size())
992  d->edit->setCursorPosition(d->prefix.size());
993 
994  int steps = 1;
995  bool isPgUpOrDown = false;
996  switch (event->key()) {
997  case Qt::Key_PageUp:
998  case Qt::Key_PageDown:
999  steps *= 10;
1000  isPgUpOrDown = true;
1001  case Qt::Key_Up:
1002  case Qt::Key_Down: {
1003 #ifdef QT_KEYPAD_NAVIGATION
1004  if (QApplication::keypadNavigationEnabled()) {
1005  // Reserve up/down for nav - use left/right for edit.
1006  if (!hasEditFocus() && (event->key() == Qt::Key_Up
1007  || event->key() == Qt::Key_Down)) {
1008  event->ignore();
1009  return;
1010  }
1011  }
1012 #endif
1013  event->accept();
1014  const bool up = (event->key() == Qt::Key_PageUp || event->key() == Qt::Key_Up);
1015  if (!(stepEnabled() & (up ? StepUpEnabled : StepDownEnabled)))
1016  return;
1017  if (!up)
1018  steps *= -1;
1020  d->buttonState = (Keyboard | (up ? Up : Down));
1021  }
1022  if (d->spinClickTimerId == -1)
1023  stepBy(steps);
1024  if(event->isAutoRepeat() && !isPgUpOrDown) {
1025  if(d->spinClickThresholdTimerId == -1 && d->spinClickTimerId == -1) {
1026  d->updateState(up, true);
1027  }
1028  }
1029 #ifndef QT_NO_ACCESSIBILITY
1031 #endif
1032  return;
1033  }
1034 #ifdef QT_KEYPAD_NAVIGATION
1035  case Qt::Key_Left:
1036  case Qt::Key_Right:
1037  if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
1038  event->ignore();
1039  return;
1040  }
1041  break;
1042  case Qt::Key_Back:
1043  if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
1044  event->ignore();
1045  return;
1046  }
1047  break;
1048 #endif
1049  case Qt::Key_Enter:
1050  case Qt::Key_Return:
1051  d->edit->d_func()->control->clearUndo();
1052  d->interpret(d->keyboardTracking ? AlwaysEmit : EmitIfChanged);
1053  selectAll();
1054  event->ignore();
1056  return;
1057 
1058 #ifdef QT_KEYPAD_NAVIGATION
1059  case Qt::Key_Select:
1060  if (QApplication::keypadNavigationEnabled()) {
1061  // Toggles between left/right moving cursor and inc/dec.
1062  setEditFocus(!hasEditFocus());
1063  }
1064  return;
1065 #endif
1066 
1067 #ifdef Q_WS_X11 // only X11
1068  case Qt::Key_U:
1069  if (event->modifiers() & Qt::ControlModifier) {
1070  event->accept();
1071  if (!isReadOnly())
1072  clear();
1073  return;
1074  }
1075  break;
1076 #endif
1077 
1078  case Qt::Key_End:
1079  case Qt::Key_Home:
1080  if (event->modifiers() & Qt::ShiftModifier) {
1081  int currentPos = d->edit->cursorPosition();
1082  const QString text = d->edit->displayText();
1083  if (event->key() == Qt::Key_End) {
1084  if ((currentPos == 0 && !d->prefix.isEmpty()) || text.size() - d->suffix.size() <= currentPos) {
1085  break; // let lineedit handle this
1086  } else {
1087  d->edit->setSelection(currentPos, text.size() - d->suffix.size() - currentPos);
1088  }
1089  } else {
1090  if ((currentPos == text.size() && !d->suffix.isEmpty()) || currentPos <= d->prefix.size()) {
1091  break; // let lineedit handle this
1092  } else {
1093  d->edit->setSelection(currentPos, d->prefix.size() - currentPos);
1094  }
1095  }
1096  event->accept();
1097  return;
1098  }
1099  break;
1100 
1101  default:
1102 #ifndef QT_NO_SHORTCUT
1103  if (event == QKeySequence::SelectAll) {
1104  selectAll();
1105  event->accept();
1106  return;
1107  }
1108 #endif
1109  break;
1110  }
1111 
1112  d->edit->event(event);
1113  if (!isVisible())
1114  d->ignoreUpdateEdit = true;
1115 }
1116 
1122 {
1124 
1125  if (d->buttonState & Keyboard && !event->isAutoRepeat()) {
1126  d->reset();
1127  } else {
1128  d->edit->event(event);
1129  }
1130 }
1131 
1136 #ifndef QT_NO_WHEELEVENT
1138 {
1139  const int steps = (event->delta() > 0 ? 1 : -1);
1140  if (stepEnabled() & (steps > 0 ? StepUpEnabled : StepDownEnabled))
1141  stepBy(event->modifiers() & Qt::ControlModifier ? steps * 10 : steps);
1142  event->accept();
1143 }
1144 #endif
1145 
1146 
1151 {
1153 
1154  d->edit->event(event);
1155  if (event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason) {
1156  selectAll();
1157  }
1158  QWidget::focusInEvent(event);
1159 }
1160 
1166 {
1168 
1169  if (d->pendingEmit)
1170  d->interpret(EmitIfChanged);
1171 
1172  d->reset();
1173  d->edit->event(event);
1174  d->updateEdit();
1175  QWidget::focusOutEvent(event);
1176 
1177 #ifdef QT_KEYPAD_NAVIGATION
1178  // editingFinished() is already emitted on LeaveEditFocus
1179  if (!QApplication::keypadNavigationEnabled())
1180 #endif
1182 }
1183 
1189 {
1191 
1192  d->reset();
1193  if (d->pendingEmit)
1194  d->interpret(EmitIfChanged);
1195  QWidget::closeEvent(event);
1196 }
1197 
1203 {
1205  d->reset();
1206  if (d->pendingEmit)
1207  d->interpret(EmitIfChanged);
1208  QWidget::hideEvent(event);
1209 }
1210 
1211 
1228  int ret = 30;
1229 #if defined(Q_OS_SYMBIAN)
1230  TTimeIntervalMicroSeconds32 initialTime;
1231  TTimeIntervalMicroSeconds32 time;
1232  S60->wsSession().GetKeyboardRepeatRate(initialTime, time);
1233  ret = time.Int() / 1000; // msecs
1234 #elif defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
1235  DWORD time;
1236  if (SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &time, 0) != FALSE)
1237  ret = static_cast<int>(1000 / static_cast<int>(time)); // msecs
1238 #endif
1239  return ret; // msecs
1240 }
1241 
1247 {
1249 
1250  bool doStep = false;
1251  if (event->timerId() == d->spinClickThresholdTimerId) {
1252  killTimer(d->spinClickThresholdTimerId);
1253  d->spinClickThresholdTimerId = -1;
1254  d->effectiveSpinRepeatRate = d->buttonState & Keyboard
1256  : d->spinClickTimerInterval;
1257  d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate);
1258  doStep = true;
1259  } else if (event->timerId() == d->spinClickTimerId) {
1260  if (d->accelerate) {
1261  d->acceleration = d->acceleration + (int)(d->effectiveSpinRepeatRate * 0.05);
1262  if (d->effectiveSpinRepeatRate - d->acceleration >= 10) {
1263  killTimer(d->spinClickTimerId);
1264  d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate - d->acceleration);
1265  }
1266  }
1267  doStep = true;
1268  }
1269 
1270  if (doStep) {
1271  const StepEnabled st = stepEnabled();
1272  if (d->buttonState & Up) {
1273  if (!(st & StepUpEnabled)) {
1274  d->reset();
1275  } else {
1276  stepBy(1);
1277  }
1278  } else if (d->buttonState & Down) {
1279  if (!(st & StepDownEnabled)) {
1280  d->reset();
1281  } else {
1282  stepBy(-1);
1283  }
1284  }
1285  return;
1286  }
1287  QWidget::timerEvent(event);
1288  return;
1289 }
1290 
1296 {
1297 #ifdef QT_NO_CONTEXTMENU
1298  Q_UNUSED(event);
1299 #else
1301 
1302  QPointer<QMenu> menu = d->edit->createStandardContextMenu();
1303  if (!menu)
1304  return;
1305 
1306  d->reset();
1307 
1308  QAction *selAll = new QAction(tr("&Select All"), menu);
1309  menu->insertAction(d->edit->d_func()->selectAllAction,
1310  selAll);
1311  menu->removeAction(d->edit->d_func()->selectAllAction);
1312  menu->addSeparator();
1313  const uint se = stepEnabled();
1314  QAction *up = menu->addAction(tr("&Step up"));
1315  up->setEnabled(se & StepUpEnabled);
1316  QAction *down = menu->addAction(tr("Step &down"));
1317  down->setEnabled(se & StepDownEnabled);
1318  menu->addSeparator();
1319 
1320  const QPointer<QAbstractSpinBox> that = this;
1321  const QPoint pos = (event->reason() == QContextMenuEvent::Mouse)
1322  ? event->globalPos() : mapToGlobal(QPoint(event->pos().x(), 0)) + QPoint(width() / 2, height() / 2);
1323  const QAction *action = menu->exec(pos);
1324  delete static_cast<QMenu *>(menu);
1325  if (that && action) {
1326  if (action == up) {
1327  stepBy(1);
1328  } else if (action == down) {
1329  stepBy(-1);
1330  } else if (action == selAll) {
1331  selectAll();
1332  }
1333  }
1334  event->accept();
1335 #endif // QT_NO_CONTEXTMENU
1336 }
1337 
1343 {
1345 
1346  d->updateHoverControl(event->pos());
1347 
1348  // If we have a timer ID, update the state
1349  if (d->spinClickTimerId != -1 && d->buttonSymbols != NoButtons) {
1350  const StepEnabled se = stepEnabled();
1351  if ((se & StepUpEnabled) && d->hoverControl == QStyle::SC_SpinBoxUp)
1352  d->updateState(true);
1353  else if ((se & StepDownEnabled) && d->hoverControl == QStyle::SC_SpinBoxDown)
1354  d->updateState(false);
1355  else
1356  d->reset();
1357  event->accept();
1358  }
1359 }
1360 
1366 {
1368 
1369  if (event->button() != Qt::LeftButton || d->buttonState != None) {
1370  return;
1371  }
1372 
1373  d->updateHoverControl(event->pos());
1374  event->accept();
1375 
1376  const StepEnabled se = (d->buttonSymbols == NoButtons) ? StepEnabled(StepNone) : stepEnabled();
1377  if ((se & StepUpEnabled) && d->hoverControl == QStyle::SC_SpinBoxUp) {
1378  d->updateState(true);
1379  } else if ((se & StepDownEnabled) && d->hoverControl == QStyle::SC_SpinBoxDown) {
1380  d->updateState(false);
1381  } else {
1382  event->ignore();
1383  }
1384 }
1385 
1390 {
1392 
1393  if ((d->buttonState & Mouse) != 0)
1394  d->reset();
1395  event->accept();
1396 }
1397 
1398 // --- QAbstractSpinBoxPrivate ---
1399 
1406  : edit(0), type(QVariant::Invalid), spinClickTimerId(-1),
1407  spinClickTimerInterval(100), spinClickThresholdTimerId(-1), spinClickThresholdTimerInterval(-1),
1408  effectiveSpinRepeatRate(1), buttonState(None), cachedText(QLatin1String("\x01")),
1409  cachedState(QValidator::Invalid), pendingEmit(false), readOnly(false), wrapping(false),
1410  ignoreCursorPositionChanged(false), frame(true), accelerate(false), keyboardTracking(true),
1411  cleared(false), ignoreUpdateEdit(false), correctionMode(QAbstractSpinBox::CorrectToPreviousValue),
1412  acceleration(0), hoverControl(QStyle::SC_None), buttonSymbols(QAbstractSpinBox::UpDownArrows), validator(0)
1413 {
1414 }
1415 
1416 /*
1417  \internal
1418  Called when the QAbstractSpinBoxPrivate is destroyed
1419 */
1421 {
1422 }
1423 
1433 {
1435  QRect lastHoverRect = hoverRect;
1436  QStyle::SubControl lastHoverControl = hoverControl;
1437  bool doesHover = q->testAttribute(Qt::WA_Hover);
1438  if (lastHoverControl != newHoverControl(pos) && doesHover) {
1439  q->update(lastHoverRect);
1440  q->update(hoverRect);
1441  return true;
1442  }
1443  return !doesHover;
1444 }
1445 
1455 {
1457 
1458  QStyleOptionSpinBox opt;
1459  q->initStyleOption(&opt);
1461  hoverControl = q->style()->hitTestComplexControl(QStyle::CC_SpinBox, &opt, pos, q);
1462  hoverRect = q->style()->subControlRect(QStyle::CC_SpinBox, &opt, hoverControl, q);
1463  return hoverControl;
1464 }
1465 
1475 {
1476  QString text = t;
1477  if (specialValueText.size() == 0 || text != specialValueText) {
1478  int from = 0;
1479  int size = text.size();
1480  bool changed = false;
1481  if (prefix.size() && text.startsWith(prefix)) {
1482  from += prefix.size();
1483  size -= from;
1484  changed = true;
1485  }
1486  if (suffix.size() && text.endsWith(suffix)) {
1487  size -= suffix.size();
1488  changed = true;
1489  }
1490  if (changed)
1491  text = text.mid(from, size);
1492  }
1493 
1494  const int s = text.size();
1495  text = text.trimmed();
1496  if (pos)
1497  (*pos) -= (s - text.size());
1498  return text;
1499 
1500 }
1501 
1503 {
1505  QStyleOptionSpinBox opt;
1506  q->initStyleOption(&opt);
1508  edit->setGeometry(q->style()->subControlRect(QStyle::CC_SpinBox, &opt,
1510 }
1520 {
1521  return (value == minimum && !specialValueText.isEmpty());
1522 }
1523 
1530 {
1531 }
1532 
1544 {
1546 
1547  if (keyboardTracking) {
1548  QString tmp = t;
1549  int pos = edit->cursorPosition();
1550  QValidator::State state = q->validate(tmp, pos);
1551  if (state == QValidator::Acceptable) {
1552  const QVariant v = valueFromText(tmp);
1553  setValue(v, EmitIfChanged, tmp != t);
1554  pendingEmit = false;
1555  } else {
1556  pendingEmit = true;
1557  }
1558  } else {
1559  pendingEmit = true;
1560  }
1561 }
1562 
1577 {
1580 
1581  bool allowSelection = true;
1582  int pos = -1;
1583  if (newpos < prefix.size() && newpos != 0) {
1584  if (oldpos == 0) {
1585  allowSelection = false;
1586  pos = prefix.size();
1587  } else {
1588  pos = oldpos;
1589  }
1590  } else if (newpos > edit->text().size() - suffix.size()
1591  && newpos != edit->text().size()) {
1592  if (oldpos == edit->text().size()) {
1593  pos = edit->text().size() - suffix.size();
1594  allowSelection = false;
1595  } else {
1596  pos = edit->text().size();
1597  }
1598  }
1599  if (pos != -1) {
1600  const int selSize = edit->selectionStart() >= 0 && allowSelection
1601  ? (edit->selectedText().size()
1602  * (newpos < pos ? -1 : 1)) - newpos + pos
1603  : 0;
1604 
1605  const bool wasBlocked = edit->blockSignals(true);
1606  if (selSize != 0) {
1607  edit->setSelection(pos - selSize, selSize);
1608  } else {
1609  edit->setCursorPosition(pos);
1610  }
1611  edit->blockSignals(wasBlocked);
1612  }
1614  }
1615 }
1616 
1627 {
1629 
1630  q->setLineEdit(new QLineEdit(q));
1631  edit->setObjectName(QLatin1String("qt_spinbox_lineedit"));
1632  validator = new QSpinBoxValidator(q, this);
1634 
1635  QStyleOptionSpinBox opt;
1636  q->initStyleOption(&opt);
1637  spinClickTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, &opt, q);
1639  q->setFocusPolicy(Qt::WheelFocus);
1641  q->setAttribute(Qt::WA_InputMethodEnabled);
1642 
1643  q->setAttribute(Qt::WA_MacShowFocusRect);
1644 }
1645 
1657 {
1659 
1660  buttonState = None;
1661  if (q) {
1662  if (spinClickTimerId != -1)
1663  q->killTimer(spinClickTimerId);
1664  if (spinClickThresholdTimerId != -1)
1665  q->killTimer(spinClickThresholdTimerId);
1667  acceleration = 0;
1668  q->update();
1669  }
1670 }
1671 
1681 void QAbstractSpinBoxPrivate::updateState(bool up, bool fromKeyboard /* = false */)
1682 {
1684  if ((up && (buttonState & Up)) || (!up && (buttonState & Down)))
1685  return;
1686  reset();
1687  if (q && (q->stepEnabled() & (up ? QAbstractSpinBox::StepUpEnabled
1690  buttonState = (up ? Up : Down) | (fromKeyboard ? Keyboard : Mouse);
1691  q->stepBy(up ? 1 : -1);
1692 #ifndef QT_NO_ACCESSIBILITY
1694 #endif
1695  }
1696 }
1697 
1698 
1707 {
1708  if (!option)
1709  return;
1710 
1711  Q_D(const QAbstractSpinBox);
1712  option->initFrom(this);
1714  option->buttonSymbols = d->buttonSymbols;
1716  if (d->buttonSymbols != QAbstractSpinBox::NoButtons) {
1718  if (d->buttonState & Up) {
1720  } else if (d->buttonState & Down) {
1722  }
1723  }
1724 
1725  if (d->buttonState) {
1726  option->state |= QStyle::State_Sunken;
1727  } else {
1728  option->activeSubControls = d->hoverControl;
1729  }
1730 
1731  option->stepEnabled = style()->styleHint(QStyle::SH_SpinControls_DisableOnBounds)
1732  ? stepEnabled()
1734 
1735  option->frame = d->frame;
1736  if (d->readOnly)
1737  option->state |= QStyle::State_ReadOnly;
1738 }
1739 
1751 QVariant QAbstractSpinBoxPrivate::bound(const QVariant &val, const QVariant &old, int steps) const
1752 {
1753  QVariant v = val;
1754  if (!wrapping || steps == 0 || old.isNull()) {
1755  if (variantCompare(v, minimum) < 0) {
1756  v = wrapping ? maximum : minimum;
1757  }
1758  if (variantCompare(v, maximum) > 0) {
1759  v = wrapping ? minimum : maximum;
1760  }
1761  } else {
1762  const bool wasMin = old == minimum;
1763  const bool wasMax = old == maximum;
1764  const int oldcmp = variantCompare(v, old);
1765  const int maxcmp = variantCompare(v, maximum);
1766  const int mincmp = variantCompare(v, minimum);
1767  const bool wrapped = (oldcmp > 0 && steps < 0) || (oldcmp < 0 && steps > 0);
1768  if (maxcmp > 0) {
1769  v = ((wasMax && !wrapped && steps > 0) || (steps < 0 && !wasMin && wrapped))
1770  ? minimum : maximum;
1771  } else if (wrapped && (maxcmp > 0 || mincmp < 0)) {
1772  v = ((wasMax && steps > 0) || (!wasMin && steps < 0)) ? minimum : maximum;
1773  } else if (mincmp < 0) {
1774  v = (!wasMax && !wasMin ? minimum : maximum);
1775  }
1776  }
1777 
1778  return v;
1779 }
1780 
1792  bool doUpdate)
1793 {
1795  const QVariant old = value;
1796  value = bound(val);
1797  pendingEmit = false;
1798  cleared = false;
1799  if (doUpdate) {
1800  updateEdit();
1801  }
1802  q->update();
1803 
1804  if (ep == AlwaysEmit || (ep == EmitIfChanged && old != value)) {
1805  emitSignals(ep, old);
1806  }
1807 }
1808 
1819 {
1821  if (type == QVariant::Invalid)
1822  return;
1824  if (newText == edit->displayText() || cleared)
1825  return;
1826 
1827  const bool empty = edit->text().isEmpty();
1828  int cursor = edit->cursorPosition();
1829  int selsize = edit->selectedText().size();
1830  const bool sb = edit->blockSignals(true);
1831  edit->setText(newText);
1832 
1833  if (!specialValue()) {
1834  cursor = qBound(prefix.size(), cursor, edit->displayText().size() - suffix.size());
1835 
1836  if (selsize > 0) {
1837  edit->setSelection(cursor, selsize);
1838  } else {
1839  edit->setCursorPosition(empty ? prefix.size() : cursor);
1840  }
1841  }
1842  edit->blockSignals(sb);
1843  q->update();
1844 }
1845 
1856 {
1858 
1859  clearCache();
1860  minimum = min;
1861  maximum = (variantCompare(min, max) < 0 ? max : min);
1862  cachedSizeHint = QSize(); // minimumSizeHint doesn't care about min/max
1863 
1864  reset();
1865  if (!(bound(value) == value)) {
1867  } else if (value == minimum && !specialValueText.isEmpty()) {
1868  updateEdit();
1869  }
1870 
1871  q->updateGeometry();
1872 }
1873 
1884 {
1885  QVariant ret;
1886  switch (type) {
1887  case QVariant::Int: ret = QVariant((int)0); break;
1888  case QVariant::Double: ret = QVariant((double)0.0); break;
1889  default: break;
1890  }
1891  return ret;
1892 }
1893 
1909 {
1910  return QString();
1911 }
1912 
1928 {
1929  return QVariant();
1930 }
1942 {
1944  if (type == QVariant::Invalid || cleared)
1945  return;
1946 
1947  QVariant v = getZeroVariant();
1948  bool doInterpret = true;
1949  QString tmp = edit->displayText();
1950  int pos = edit->cursorPosition();
1951  const int oldpos = pos;
1952 
1953  if (q->validate(tmp, pos) != QValidator::Acceptable) {
1954  const QString copy = tmp;
1955  q->fixup(tmp);
1956  QASBDEBUG() << "QAbstractSpinBoxPrivate::interpret() text '"
1957  << edit->displayText()
1958  << "' >> '" << copy << '\''
1959  << "' >> '" << tmp << '\'';
1960 
1961  doInterpret = tmp != copy && (q->validate(tmp, pos) == QValidator::Acceptable);
1962  if (!doInterpret) {
1964  ? variantBound(minimum, v, maximum) : value);
1965  }
1966  }
1967  if (doInterpret) {
1968  v = valueFromText(tmp);
1969  }
1970  clearCache();
1971  setValue(v, ep, true);
1972  if (oldpos != pos)
1973  edit->setCursorPosition(pos);
1974 }
1975 
1977 {
1978  cachedText.clear();
1979  cachedValue.clear();
1981 }
1982 
1983 
1984 // --- QSpinBoxValidator ---
1985 
1992  : QValidator(qp), qptr(qp), dptr(dp)
1993 {
1994  setObjectName(QLatin1String("qt_spinboxvalidator"));
1995 }
1996 
2008 {
2009  if (dptr->specialValueText.size() > 0 && input == dptr->specialValueText)
2010  return QValidator::Acceptable;
2011 
2012  if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix)) {
2013  input.prepend(dptr->prefix);
2014  pos += dptr->prefix.length();
2015  }
2016 
2017  if (!dptr->suffix.isEmpty() && !input.endsWith(dptr->suffix))
2018  input.append(dptr->suffix);
2019 
2020  return qptr->validate(input, pos);
2021 }
2031 {
2032  qptr->fixup(input);
2033 }
2034 
2035 // --- global ---
2036 
2045 QVariant operator+(const QVariant &arg1, const QVariant &arg2)
2046 {
2047  QVariant ret;
2048  if (arg1.type() != arg2.type())
2049  qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)",
2050  arg1.typeName(), arg2.typeName(), __FILE__, __LINE__);
2051  switch (arg1.type()) {
2052  case QVariant::Int: ret = QVariant(arg1.toInt() + arg2.toInt()); break;
2053  case QVariant::Double: ret = QVariant(arg1.toDouble() + arg2.toDouble()); break;
2054  case QVariant::DateTime: {
2055  QDateTime a2 = arg2.toDateTime();
2056  QDateTime a1 = arg1.toDateTime().addDays(QDATETIMEEDIT_DATETIME_MIN.daysTo(a2));
2057  a1.setTime(a1.time().addMSecs(QTime().msecsTo(a2.time())));
2058  ret = QVariant(a1);
2059  }
2060  default: break;
2061  }
2062  return ret;
2063 }
2064 
2065 
2074 QVariant operator-(const QVariant &arg1, const QVariant &arg2)
2075 {
2076  QVariant ret;
2077  if (arg1.type() != arg2.type())
2078  qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)",
2079  arg1.typeName(), arg2.typeName(), __FILE__, __LINE__);
2080  switch (arg1.type()) {
2081  case QVariant::Int: ret = QVariant(arg1.toInt() - arg2.toInt()); break;
2082  case QVariant::Double: ret = QVariant(arg1.toDouble() - arg2.toDouble()); break;
2083  case QVariant::DateTime: {
2084  QDateTime a1 = arg1.toDateTime();
2085  QDateTime a2 = arg2.toDateTime();
2086  int days = a2.daysTo(a1);
2087  int secs = a2.secsTo(a1);
2088  int msecs = qMax(0, a1.time().msec() - a2.time().msec());
2089  if (days < 0 || secs < 0 || msecs < 0) {
2090  ret = arg1;
2091  } else {
2092  QDateTime dt = a2.addDays(days).addSecs(secs);
2093  if (msecs > 0)
2094  dt.setTime(dt.time().addMSecs(msecs));
2095  ret = QVariant(dt);
2096  }
2097  }
2098  default: break;
2099  }
2100  return ret;
2101 }
2102 
2111 QVariant operator*(const QVariant &arg1, double multiplier)
2112 {
2113  QVariant ret;
2114 
2115  switch (arg1.type()) {
2116  case QVariant::Int: ret = QVariant((int)(arg1.toInt() * multiplier)); break;
2117  case QVariant::Double: ret = QVariant(arg1.toDouble() * multiplier); break;
2118  case QVariant::DateTime: {
2119  double days = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDateTime().date()) * multiplier;
2120  int daysInt = (int)days;
2121  days -= daysInt;
2122  long msecs = (long)((QDATETIMEEDIT_TIME_MIN.msecsTo(arg1.toDateTime().time()) * multiplier)
2123  + (days * (24 * 3600 * 1000)));
2124  ret = QDateTime(QDate().addDays(int(days)), QTime().addMSecs(msecs));
2125  break;
2126  }
2127  default: ret = arg1; break;
2128  }
2129 
2130  return ret;
2131 }
2132 
2133 
2134 
2135 double operator/(const QVariant &arg1, const QVariant &arg2)
2136 {
2137  double a1 = 0;
2138  double a2 = 0;
2139 
2140  switch (arg1.type()) {
2141  case QVariant::Int:
2142  a1 = (double)arg1.toInt();
2143  a2 = (double)arg2.toInt();
2144  break;
2145  case QVariant::Double:
2146  a1 = arg1.toDouble();
2147  a2 = arg2.toDouble();
2148  break;
2149  case QVariant::DateTime:
2150  a1 = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDate());
2151  a2 = QDATETIMEEDIT_DATE_MIN.daysTo(arg2.toDate());
2152  a1 += (double)QDATETIMEEDIT_TIME_MIN.msecsTo(arg1.toDateTime().time()) / (long)(3600 * 24 * 1000);
2153  a2 += (double)QDATETIMEEDIT_TIME_MIN.msecsTo(arg2.toDateTime().time()) / (long)(3600 * 24 * 1000);
2154  default: break;
2155  }
2156 
2157  return (a1 != 0 && a2 != 0) ? (a1 / a2) : 0.0;
2158 }
2159 
2161 {
2162  switch (arg2.type()) {
2163  case QVariant::Date:
2164  Q_ASSERT_X(arg1.type() == QVariant::Date, "QAbstractSpinBoxPrivate::variantCompare",
2165  qPrintable(QString::fromAscii("Internal error 1 (%1)").
2166  arg(QString::fromAscii(arg1.typeName()))));
2167  if (arg1.toDate() == arg2.toDate()) {
2168  return 0;
2169  } else if (arg1.toDate() < arg2.toDate()) {
2170  return -1;
2171  } else {
2172  return 1;
2173  }
2174  case QVariant::Time:
2175  Q_ASSERT_X(arg1.type() == QVariant::Time, "QAbstractSpinBoxPrivate::variantCompare",
2176  qPrintable(QString::fromAscii("Internal error 2 (%1)").
2177  arg(QString::fromAscii(arg1.typeName()))));
2178  if (arg1.toTime() == arg2.toTime()) {
2179  return 0;
2180  } else if (arg1.toTime() < arg2.toTime()) {
2181  return -1;
2182  } else {
2183  return 1;
2184  }
2185 
2186 
2187  case QVariant::DateTime:
2188  if (arg1.toDateTime() == arg2.toDateTime()) {
2189  return 0;
2190  } else if (arg1.toDateTime() < arg2.toDateTime()) {
2191  return -1;
2192  } else {
2193  return 1;
2194  }
2195  case QVariant::Int:
2196  if (arg1.toInt() == arg2.toInt()) {
2197  return 0;
2198  } else if (arg1.toInt() < arg2.toInt()) {
2199  return -1;
2200  } else {
2201  return 1;
2202  }
2203  case QVariant::Double:
2204  if (arg1.toDouble() == arg2.toDouble()) {
2205  return 0;
2206  } else if (arg1.toDouble() < arg2.toDouble()) {
2207  return -1;
2208  } else {
2209  return 1;
2210  }
2211  case QVariant::Invalid:
2212  if (arg2.type() == QVariant::Invalid)
2213  return 0;
2214  default:
2215  Q_ASSERT_X(0, "QAbstractSpinBoxPrivate::variantCompare",
2216  qPrintable(QString::fromAscii("Internal error 3 (%1 %2)").
2217  arg(QString::fromAscii(arg1.typeName())).
2218  arg(QString::fromAscii(arg2.typeName()))));
2219  }
2220  return -2;
2221 }
2222 
2224  const QVariant &value,
2225  const QVariant &max)
2226 {
2227  Q_ASSERT(variantCompare(min, max) <= 0);
2228  if (variantCompare(min, value) < 0) {
2229  const int compMax = variantCompare(value, max);
2230  return (compMax < 0 ? value : max);
2231  } else {
2232  return min;
2233  }
2234 }
2235 
2236 
2238 
2239 #include "moc_qabstractspinbox.cpp"
2240 
2241 #endif // QT_NO_SPINBOX
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QDateTime addSecs(int secs) const
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or...
Definition: qdatetime.cpp:2869
QPoint pos() const
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
QSize minimumSizeHint() const
Reimplemented Function
double d
Definition: qnumeric_p.h:62
int daysTo(const QDateTime &) const
Returns the number of days from this datetime to the other datetime.
Definition: qdatetime.cpp:2894
void focusInEvent(QFocusEvent *event)
Reimplemented Function
ButtonSymbols buttonSymbols() const
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
bool isAccelerated() const
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
virtual StepEnabled stepEnabled() const
Virtual function that determines whether stepping up and down is legal at any given time...
int selectionStart() const
selectionStart() returns the index of the first selected character in the line edit or -1 if no text ...
Definition: qlineedit.cpp:1039
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
The QKeyEvent class describes a key event.
Definition: qevent.h:224
virtual QString textFromValue(const QVariant &n) const
Virtual method called that calls the public textFromValue() functions in the subclasses.
int type
Definition: qmetatype.cpp:239
void hideEvent(QHideEvent *event)
Reimplemented Function
void mouseReleaseEvent(QMouseEvent *event)
Reimplemented Function
virtual QStyle::SubControl newHoverControl(const QPoint &pos)
Returns the hover control at pos.
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
virtual void fixup(QString &input) const
This virtual function is called by the QAbstractSpinBox if the input is not validated to QValidator::...
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
void initStyleOption(QStyleOptionSpinBox *option) const
Initialize option with the values from this QSpinBox.
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
QSpinBoxValidator(QAbstractSpinBox *qptr, QAbstractSpinBoxPrivate *dptr)
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
bool updateHoverControl(const QPoint &pos)
Updates the old and new hover control.
void init()
Initialises the QAbstractSpinBoxPrivate object.
The QWheelEvent class contains parameters that describe a wheel event.
Definition: qevent.h:139
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
virtual void stepBy(int steps)
Virtual function that is called whenever the user triggers a step.
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=0) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
static int getKeyboardAutoRepeatRate()
Used when acceleration is turned on.
bool isVisible() const
Definition: qwidget.h:1005
const QPoint & pos() const
Returns the position of the mouse pointer relative to the widget that received the event...
Definition: qevent.h:412
static QSize globalStrut()
static int variantCompare(const QVariant &arg1, const QVariant &arg2)
EmitPolicy
QVariant operator-(const QVariant &arg1, const QVariant &arg2)
Subtracts two variants and returns the result.
The QHoverEvent class contains parameters that describe a mouse event.
Definition: qevent.h:125
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString & prepend(QChar c)
Definition: qstring.h:261
#define SLOT(a)
Definition: qobjectdefs.h:226
virtual void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
Definition: qobject.cpp:1294
virtual QVariant valueFromText(const QString &input) const
Virtual method called that calls the public valueFromText() functions in the subclasses.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QValidator::State validate(QString &input, int &) const
Checks for specialValueText, prefix, suffix and calls the virtual QAbstractSpinBox::validate function...
QAbstractSpinBox(QWidget *parent=0)
Constructs an abstract spinbox with the given parent with default wrapping , and alignment properties...
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
void interpretText()
This function interprets the text of the spin box.
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
void keyPressEvent(QKeyEvent *event)
This function handles keyboard input.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
bool readOnly
whether the spin box is read only.
virtual void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition: qwidget.cpp:9587
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
void wheelEvent(QWheelEvent *event)
Reimplemented Function
The QDate class provides date functions.
Definition: qdatetime.h:55
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setLineEdit(QLineEdit *edit)
Sets the line edit of the spinbox to be lineEdit instead of the current line edit widget...
int msec() const
Returns the millisecond part (0 to 999) of the time.
Definition: qdatetime.cpp:1611
QAbstractSpinBox::StepEnabled stepEnabled
which buttons of the spin box that are enabled
Definition: qstyleoption.h:736
void mouseMoveEvent(QMouseEvent *event)
Reimplemented Function
virtual void updateEditFieldGeometry()
void setSpecialValueText(const QString &txt)
QStyle::SubControls activeSubControls
This variable holds a bitwise OR of the sub-controls that are active for the complex control...
Definition: qstyleoption.h:694
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
bool isActiveWindow() const
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString specialValueText() const
#define QDATETIMEEDIT_TIME_MIN
Definition: qdatetime_p.h:67
void mousePressEvent(QMouseEvent *event)
Reimplemented Function
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void setReadOnly(bool r)
int height() const
ButtonSymbols
This enum type describes the symbols that can be displayed on the buttons in a spin box...
bool frame
whether the spin box has a frame
Definition: qstyleoption.h:737
virtual void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition: qwidget.cpp:9457
void setEnabled(bool)
Definition: qaction.cpp:1192
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
QStyle * style() const
Definition: qwidget.cpp:2742
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
static QVariant variantBound(const QVariant &min, const QVariant &value, const QVariant &max)
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
void stepUp()
Steps up by one linestep Calling this slot is analogous to calling stepBy(1);.
void reset()
Resets the state of the spinbox.
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void changeEvent(QEvent *event)
Reimplemented Function
void setAccelerated(bool on)
void keyReleaseEvent(QKeyEvent *event)
Reimplemented Function
The QTime class provides clock time functions.
Definition: qdatetime.h:148
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QValidator class provides validation of input text.
Definition: qvalidator.h:60
CorrectionMode
This enum type describes the mode the spinbox will use to correct an QValidator::Intermediate value i...
virtual void interpret(EmitPolicy ep)
Interprets text and emits signals.
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
bool frame
whether the spin box draws itself with a frame
QStyle::SubControl hoverControl
QValidator::State cachedState
Qt::Alignment alignment() const
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void _q_editorTextChanged(const QString &)
Slot connected to the line edit&#39;s textChanged(const QString &) signal.
void setTime(const QTime &time)
Sets the time part of this datetime to time.
Definition: qdatetime.cpp:2416
void stepDown()
Steps down by one linestep Calling this slot is analogous to calling stepBy(-1);. ...
int width() const
QString text
the line edit&#39;s text
Definition: qlineedit.h:72
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
The QStyleOptionSpinBox class is used to describe the parameters necessary for drawing a spin box...
Definition: qstyleoption.h:729
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
#define emit
Definition: qobjectdefs.h:76
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
void setSelection(int, int)
Selects text from position start and for length characters.
Definition: qlineedit.cpp:1106
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:388
int secsTo(const QDateTime &) const
Returns the number of seconds from this datetime to the other datetime.
Definition: qdatetime.cpp:2914
bool wrapping() const
void setValidator(const QValidator *)
Sets this line edit to only accept input that the validator, v, will accept.
Definition: qlineedit.cpp:627
void selectAll()
Selects all the text in the spinbox except the prefix and suffix.
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
Q_CORE_EXPORT void qWarning(const char *,...)
~QAbstractSpinBox()
Called when the QAbstractSpinBox is destroyed.
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:448
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition: qmenu.cpp:1583
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
void editingFinished()
This signal is emitted editing is finished.
unsigned int uint
Definition: qglobal.h:996
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void updateState(bool up, bool fromKeyboard=false)
Updates the state of the spinbox.
double operator/(const QVariant &arg1, const QVariant &arg2)
#define FALSE
Synonym for false.
Definition: qglobal.h:1019
void fixup(QString &) const
Calls the virtual QAbstractSpinBox::fixup function.
void resizeEvent(QResizeEvent *event)
Reimplemented Function
The QAbstractSpinBox class provides a spinbox and a line edit to display values.
void focusOutEvent(QFocusEvent *event)
Reimplemented Function
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
QString stripped(const QString &text, int *pos=0) const
Strips any prefix/suffix from text.
virtual void setRange(const QVariant &min, const QVariant &max)
Convenience function to set min/max values.
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
bool isReadOnly() const
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
QLineEdit * lineEdit() const
This function returns a pointer to the line edit of the spin box.
QVariant operator*(const QVariant &arg1, double multiplier)
Multiplies arg1 by multiplier and returns the result.
QRect rect() const
QSpinBoxValidator * validator
bool hasAcceptableInput() const
bool isEnabled() const
Definition: qwidget.h:948
#define None
QString text() const
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
void setButtonSymbols(ButtonSymbols bs)
virtual void updateEdit()
Updates the line edit to reflect the current value of the spin box.
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
QAction * exec()
Executes this menu synchronously.
Definition: qmenu.cpp:2101
virtual QValidator::State validate(QString &input, int &pos) const
This virtual function is called by the QAbstractSpinBox to determine whether input is valid...
void setText(const QString &)
Definition: qlineedit.cpp:401
virtual void emitSignals(EmitPolicy ep, const QVariant &old)
#define QDATETIMEEDIT_DATE_MIN
Definition: qdatetime_p.h:69
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
InputMethodQuery
Definition: qnamespace.h:1541
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QAbstractSpinBox::ButtonSymbols buttonSymbols
the type of button symbols to draw for the spin box
Definition: qstyleoption.h:735
QDate toDate() const
Returns the variant as a QDate if the variant has type() Date , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2311
QString selectedText
the selected text
Definition: qlineedit.h:81
QSize sizeHint() const
Reimplemented Function
void clear()
Convert this variant to type Invalid and free up any resources used.
Definition: qvariant.cpp:1993
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QDateTime addDays(int days) const
Returns a QDateTime object containing a datetime ndays days later than the datetime of this object (o...
Definition: qdatetime.cpp:2783
QString & append(QChar c)
Definition: qstring.cpp:1777
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
virtual QVariant bound(const QVariant &val, const QVariant &old=QVariant(), int steps=0) const
Bounds val to be within minimum and maximum.
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
bool hasSelectedText
whether there is any text selected
Definition: qlineedit.h:80
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
virtual void _q_editorCursorPositionChanged(int oldpos, int newpos)
Virtual slot connected to the line edit&#39;s cursorPositionChanged(int, int) signal. ...
virtual void hideEvent(QHideEvent *)
This event handler can be reimplemented in a subclass to receive widget hide events.
Definition: qwidget.cpp:9864
QAbstractSpinBox * qptr
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
#define QASBDEBUG
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
QAbstractSpinBox::CorrectionMode correctionMode
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
virtual void clearCache() const
void removeAction(QAction *action)
Removes the action action from this widget&#39;s list of actions.
Definition: qwidget.cpp:3386
#define st(var, type, card)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
virtual void closeEvent(QCloseEvent *)
This event handler is called with the given event when Qt receives a window close request for a top-l...
Definition: qwidget.cpp:9626
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
void setCorrectionMode(CorrectionMode cm)
void contextMenuEvent(QContextMenuEvent *event)
Reimplemented Function
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
void insertAction(QAction *before, QAction *action)
Inserts the action action to this widget&#39;s list of actions, before the action before.
Definition: qwidget.cpp:3342
State
This enum type defines the states in which a validated string can exist.
Definition: qvalidator.h:67
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isAutoRepeat() const
Returns true if this event comes from an auto-repeating key; returns false if it comes from an initia...
Definition: qevent.h:237
Qt::FocusReason reason()
Definition: qevent.cpp:1197
void setValue(const QVariant &val, EmitPolicy ep, bool updateEdit=true)
Sets the value of the spin box to val.
void showEvent(QShowEvent *event)
Reimplemented Function
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
QVariant inputMethodQuery(Qt::InputMethodQuery) const
Reimplemented Function
QTime addMSecs(int ms) const
Returns a QTime object containing a time ms milliseconds later than the time of this object (or earli...
Definition: qdatetime.cpp:1803
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget...
Definition: qstylepainter.h:55
void paintEvent(QPaintEvent *event)
Reimplemented Function
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
QVariant operator+(const QVariant &arg1, const QVariant &arg2)
Adds two variants together and returns the result.
virtual QVariant getZeroVariant() const
Convenience function to get a variant of the right type.
QTime toTime() const
Returns the variant as a QTime if the variant has type() Time , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2330
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition: qevent.h:413
bool event(QEvent *event)
Reimplemented Function
void setCursorPosition(int)
Definition: qlineedit.cpp:758
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &opt)
Use the widget&#39;s style to draw a complex control cc specified by the QStyleOptionComplex option...
Definition: qstylepainter.h:92
void setKeyboardTracking(bool kt)
virtual void clear()
Clears the lineedit of all text but prefix and suffix.
void timerEvent(QTimerEvent *event)
Reimplemented Function
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
#define QDATETIMEEDIT_DATETIME_MIN
Definition: qdatetime_p.h:72
void closeEvent(QCloseEvent *event)
Reimplemented Function
bool keyboardTracking() const
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define qPrintable(string)
Definition: qglobal.h:1750
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void setWrapping(bool w)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
virtual void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition: qwidget.cpp:9431
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool specialValue() const
Returns true if a specialValueText has been set and the current value is minimum. ...
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
The QCloseEvent class contains parameters that describe a close event.
Definition: qevent.h:364
QString displayText
the displayed text
Definition: qlineedit.h:76
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
Definition: qstyleoption.h:693
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
CorrectionMode correctionMode() const
int cursorPosition
the current cursor position for this line edit
Definition: qlineedit.h:77
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
void setAlignment(Qt::Alignment flag)
#define text
Definition: qobjectdefs.h:80
QAbstractSpinBoxPrivate * dptr
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650