| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qabstractspinbox.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||||||||||||||
| 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 The Qt Company. For licensing terms | - | ||||||||||||||||||||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free | - | ||||||||||||||||||||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||||||||||||||
| 34 | #include <qplatformdefs.h> | - | ||||||||||||||||||||||||||||||||||||
| 35 | #include <private/qabstractspinbox_p.h> | - | ||||||||||||||||||||||||||||||||||||
| 36 | #include <private/qdatetimeparser_p.h> | - | ||||||||||||||||||||||||||||||||||||
| 37 | #include <private/qlineedit_p.h> | - | ||||||||||||||||||||||||||||||||||||
| 38 | #include <qabstractspinbox.h> | - | ||||||||||||||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||||||||||||||
| 40 | #ifndef QT_NO_SPINBOX | - | ||||||||||||||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||||||||||||||
| 42 | #include <qapplication.h> | - | ||||||||||||||||||||||||||||||||||||
| 43 | #include <qstylehints.h> | - | ||||||||||||||||||||||||||||||||||||
| 44 | #include <qclipboard.h> | - | ||||||||||||||||||||||||||||||||||||
| 45 | #include <qdatetime.h> | - | ||||||||||||||||||||||||||||||||||||
| 46 | #include <qdatetimeedit.h> | - | ||||||||||||||||||||||||||||||||||||
| 47 | #include <qevent.h> | - | ||||||||||||||||||||||||||||||||||||
| 48 | #include <qmenu.h> | - | ||||||||||||||||||||||||||||||||||||
| 49 | #include <qpainter.h> | - | ||||||||||||||||||||||||||||||||||||
| 50 | #include <qpalette.h> | - | ||||||||||||||||||||||||||||||||||||
| 51 | #include <qstylepainter.h> | - | ||||||||||||||||||||||||||||||||||||
| 52 | #include <qdebug.h> | - | ||||||||||||||||||||||||||||||||||||
| 53 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||||||||
| 54 | # include <qaccessible.h> | - | ||||||||||||||||||||||||||||||||||||
| 55 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||||||||||||||
| 58 | //#define QABSTRACTSPINBOX_QSBDEBUG | - | ||||||||||||||||||||||||||||||||||||
| 59 | #ifdef QABSTRACTSPINBOX_QSBDEBUG | - | ||||||||||||||||||||||||||||||||||||
| 60 | # define QASBDEBUG qDebug | - | ||||||||||||||||||||||||||||||||||||
| 61 | #else | - | ||||||||||||||||||||||||||||||||||||
| 62 | # define QASBDEBUG if (false) qDebug | - | ||||||||||||||||||||||||||||||||||||
| 63 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||||||||||||||
| 65 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||||||||||||||
| 67 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 68 | \class QAbstractSpinBox | - | ||||||||||||||||||||||||||||||||||||
| 69 | \brief The QAbstractSpinBox class provides a spinbox and a line edit to | - | ||||||||||||||||||||||||||||||||||||
| 70 | display values. | - | ||||||||||||||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||||||||||||||
| 72 | \ingroup abstractwidgets | - | ||||||||||||||||||||||||||||||||||||
| 73 | \inmodule QtWidgets | - | ||||||||||||||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||||||||||||||
| 75 | The class is designed as a common super class for widgets like | - | ||||||||||||||||||||||||||||||||||||
| 76 | QSpinBox, QDoubleSpinBox and QDateTimeEdit | - | ||||||||||||||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||||||||||||||
| 78 | Here are the main properties of the class: | - | ||||||||||||||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||||||||||||||
| 80 | \list 1 | - | ||||||||||||||||||||||||||||||||||||
| 81 | - | |||||||||||||||||||||||||||||||||||||
| 82 | \li \l text: The text that is displayed in the QAbstractSpinBox. | - | ||||||||||||||||||||||||||||||||||||
| 83 | - | |||||||||||||||||||||||||||||||||||||
| 84 | \li \l alignment: The alignment of the text in the QAbstractSpinBox. | - | ||||||||||||||||||||||||||||||||||||
| 85 | - | |||||||||||||||||||||||||||||||||||||
| 86 | \li \l wrapping: Whether the QAbstractSpinBox wraps from the | - | ||||||||||||||||||||||||||||||||||||
| 87 | minimum value to the maximum value and vica versa. | - | ||||||||||||||||||||||||||||||||||||
| 88 | - | |||||||||||||||||||||||||||||||||||||
| 89 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 90 | - | |||||||||||||||||||||||||||||||||||||
| 91 | QAbstractSpinBox provides a virtual stepBy() function that is | - | ||||||||||||||||||||||||||||||||||||
| 92 | called whenever the user triggers a step. This function takes an | - | ||||||||||||||||||||||||||||||||||||
| 93 | integer value to signify how many steps were taken. E.g. Pressing | - | ||||||||||||||||||||||||||||||||||||
| 94 | Qt::Key_Down will trigger a call to stepBy(-1). | - | ||||||||||||||||||||||||||||||||||||
| 95 | - | |||||||||||||||||||||||||||||||||||||
| 96 | QAbstractSpinBox also provide a virtual function stepEnabled() to | - | ||||||||||||||||||||||||||||||||||||
| 97 | determine whether stepping up/down is allowed at any point. This | - | ||||||||||||||||||||||||||||||||||||
| 98 | function returns a bitset of StepEnabled. | - | ||||||||||||||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||||||||||||||
| 100 | \sa QAbstractSlider, QSpinBox, QDoubleSpinBox, QDateTimeEdit, | - | ||||||||||||||||||||||||||||||||||||
| 101 | {Spin Boxes Example} | - | ||||||||||||||||||||||||||||||||||||
| 102 | */ | - | ||||||||||||||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||||||||||||||
| 104 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 105 | \enum QAbstractSpinBox::StepEnabledFlag | - | ||||||||||||||||||||||||||||||||||||
| 106 | - | |||||||||||||||||||||||||||||||||||||
| 107 | \value StepNone | - | ||||||||||||||||||||||||||||||||||||
| 108 | \value StepUpEnabled | - | ||||||||||||||||||||||||||||||||||||
| 109 | \value StepDownEnabled | - | ||||||||||||||||||||||||||||||||||||
| 110 | */ | - | ||||||||||||||||||||||||||||||||||||
| 111 | - | |||||||||||||||||||||||||||||||||||||
| 112 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 113 | \fn void QAbstractSpinBox::editingFinished() | - | ||||||||||||||||||||||||||||||||||||
| 114 | - | |||||||||||||||||||||||||||||||||||||
| 115 | This signal is emitted editing is finished. This happens when the | - | ||||||||||||||||||||||||||||||||||||
| 116 | spinbox loses focus and when enter is pressed. | - | ||||||||||||||||||||||||||||||||||||
| 117 | */ | - | ||||||||||||||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||||||||||||||
| 119 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 120 | Constructs an abstract spinbox with the given \a parent with default | - | ||||||||||||||||||||||||||||||||||||
| 121 | \l wrapping, and \l alignment properties. | - | ||||||||||||||||||||||||||||||||||||
| 122 | */ | - | ||||||||||||||||||||||||||||||||||||
| 123 | - | |||||||||||||||||||||||||||||||||||||
| 124 | QAbstractSpinBox::QAbstractSpinBox(QWidget *parent) | - | ||||||||||||||||||||||||||||||||||||
| 125 | : QWidget(*new QAbstractSpinBoxPrivate, parent, 0) | - | ||||||||||||||||||||||||||||||||||||
| 126 | { | - | ||||||||||||||||||||||||||||||||||||
| 127 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 128 | d->init(); | - | ||||||||||||||||||||||||||||||||||||
| 129 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||||||||||||||
| 131 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 132 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 133 | */ | - | ||||||||||||||||||||||||||||||||||||
| 134 | QAbstractSpinBox::QAbstractSpinBox(QAbstractSpinBoxPrivate &dd, QWidget *parent) | - | ||||||||||||||||||||||||||||||||||||
| 135 | : QWidget(dd, parent, 0) | - | ||||||||||||||||||||||||||||||||||||
| 136 | { | - | ||||||||||||||||||||||||||||||||||||
| 137 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 138 | d->init(); | - | ||||||||||||||||||||||||||||||||||||
| 139 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 140 | - | |||||||||||||||||||||||||||||||||||||
| 141 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 142 | Called when the QAbstractSpinBox is destroyed. | - | ||||||||||||||||||||||||||||||||||||
| 143 | */ | - | ||||||||||||||||||||||||||||||||||||
| 144 | - | |||||||||||||||||||||||||||||||||||||
| 145 | QAbstractSpinBox::~QAbstractSpinBox() | - | ||||||||||||||||||||||||||||||||||||
| 146 | { | - | ||||||||||||||||||||||||||||||||||||
| 147 | } | - | ||||||||||||||||||||||||||||||||||||
| 148 | - | |||||||||||||||||||||||||||||||||||||
| 149 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 150 | \enum QAbstractSpinBox::ButtonSymbols | - | ||||||||||||||||||||||||||||||||||||
| 151 | - | |||||||||||||||||||||||||||||||||||||
| 152 | This enum type describes the symbols that can be displayed on the buttons | - | ||||||||||||||||||||||||||||||||||||
| 153 | in a spin box. | - | ||||||||||||||||||||||||||||||||||||
| 154 | - | |||||||||||||||||||||||||||||||||||||
| 155 | \inlineimage qspinbox-updown.png | - | ||||||||||||||||||||||||||||||||||||
| 156 | \inlineimage qspinbox-plusminus.png | - | ||||||||||||||||||||||||||||||||||||
| 157 | - | |||||||||||||||||||||||||||||||||||||
| 158 | \value UpDownArrows Little arrows in the classic style. | - | ||||||||||||||||||||||||||||||||||||
| 159 | \value PlusMinus \b{+} and \b{-} symbols. | - | ||||||||||||||||||||||||||||||||||||
| 160 | \value NoButtons Don't display buttons. | - | ||||||||||||||||||||||||||||||||||||
| 161 | - | |||||||||||||||||||||||||||||||||||||
| 162 | \sa QAbstractSpinBox::buttonSymbols | - | ||||||||||||||||||||||||||||||||||||
| 163 | */ | - | ||||||||||||||||||||||||||||||||||||
| 164 | - | |||||||||||||||||||||||||||||||||||||
| 165 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 166 | \property QAbstractSpinBox::buttonSymbols | - | ||||||||||||||||||||||||||||||||||||
| 167 | - | |||||||||||||||||||||||||||||||||||||
| 168 | \brief the current button symbol mode | - | ||||||||||||||||||||||||||||||||||||
| 169 | - | |||||||||||||||||||||||||||||||||||||
| 170 | The possible values can be either \c UpDownArrows or \c PlusMinus. | - | ||||||||||||||||||||||||||||||||||||
| 171 | The default is \c UpDownArrows. | - | ||||||||||||||||||||||||||||||||||||
| 172 | - | |||||||||||||||||||||||||||||||||||||
| 173 | Note that some styles might render PlusMinus and UpDownArrows | - | ||||||||||||||||||||||||||||||||||||
| 174 | identically. | - | ||||||||||||||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||||||||||||||
| 176 | \sa ButtonSymbols | - | ||||||||||||||||||||||||||||||||||||
| 177 | */ | - | ||||||||||||||||||||||||||||||||||||
| 178 | - | |||||||||||||||||||||||||||||||||||||
| 179 | QAbstractSpinBox::ButtonSymbols QAbstractSpinBox::buttonSymbols() const | - | ||||||||||||||||||||||||||||||||||||
| 180 | { | - | ||||||||||||||||||||||||||||||||||||
| 181 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 182 | return d->buttonSymbols; never executed: return d->buttonSymbols; | 0 | ||||||||||||||||||||||||||||||||||||
| 183 | } | - | ||||||||||||||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||||||||||||||
| 185 | void QAbstractSpinBox::setButtonSymbols(ButtonSymbols buttonSymbols) | - | ||||||||||||||||||||||||||||||||||||
| 186 | { | - | ||||||||||||||||||||||||||||||||||||
| 187 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 188 | if (d->buttonSymbols != buttonSymbols) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 189 | d->buttonSymbols = buttonSymbols; | - | ||||||||||||||||||||||||||||||||||||
| 190 | d->updateEditFieldGeometry(); | - | ||||||||||||||||||||||||||||||||||||
| 191 | update(); | - | ||||||||||||||||||||||||||||||||||||
| 192 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 193 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 194 | - | |||||||||||||||||||||||||||||||||||||
| 195 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 196 | \property QAbstractSpinBox::text | - | ||||||||||||||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||||||||||||||
| 198 | \brief the spin box's text, including any prefix and suffix | - | ||||||||||||||||||||||||||||||||||||
| 199 | - | |||||||||||||||||||||||||||||||||||||
| 200 | There is no default text. | - | ||||||||||||||||||||||||||||||||||||
| 201 | */ | - | ||||||||||||||||||||||||||||||||||||
| 202 | - | |||||||||||||||||||||||||||||||||||||
| 203 | QString QAbstractSpinBox::text() const | - | ||||||||||||||||||||||||||||||||||||
| 204 | { | - | ||||||||||||||||||||||||||||||||||||
| 205 | return lineEdit()->displayText(); never executed: return lineEdit()->displayText(); | 0 | ||||||||||||||||||||||||||||||||||||
| 206 | } | - | ||||||||||||||||||||||||||||||||||||
| 207 | - | |||||||||||||||||||||||||||||||||||||
| 208 | - | |||||||||||||||||||||||||||||||||||||
| 209 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 210 | \property QAbstractSpinBox::specialValueText | - | ||||||||||||||||||||||||||||||||||||
| 211 | \brief the special-value text | - | ||||||||||||||||||||||||||||||||||||
| 212 | - | |||||||||||||||||||||||||||||||||||||
| 213 | If set, the spin box will display this text instead of a numeric | - | ||||||||||||||||||||||||||||||||||||
| 214 | value whenever the current value is equal to minimum(). Typical use | - | ||||||||||||||||||||||||||||||||||||
| 215 | is to indicate that this choice has a special (default) meaning. | - | ||||||||||||||||||||||||||||||||||||
| 216 | - | |||||||||||||||||||||||||||||||||||||
| 217 | For example, if your spin box allows the user to choose a scale factor | - | ||||||||||||||||||||||||||||||||||||
| 218 | (or zoom level) for displaying an image, and your application is able | - | ||||||||||||||||||||||||||||||||||||
| 219 | to automatically choose one that will enable the image to fit completely | - | ||||||||||||||||||||||||||||||||||||
| 220 | within the display window, you can set up the spin box like this: | - | ||||||||||||||||||||||||||||||||||||
| 221 | - | |||||||||||||||||||||||||||||||||||||
| 222 | \snippet widgets/spinboxes/window.cpp 3 | - | ||||||||||||||||||||||||||||||||||||
| 223 | - | |||||||||||||||||||||||||||||||||||||
| 224 | The user will then be able to choose a scale from 1% to 1000% | - | ||||||||||||||||||||||||||||||||||||
| 225 | or select "Auto" to leave it up to the application to choose. Your code | - | ||||||||||||||||||||||||||||||||||||
| 226 | must then interpret the spin box value of 0 as a request from the user | - | ||||||||||||||||||||||||||||||||||||
| 227 | to scale the image to fit inside the window. | - | ||||||||||||||||||||||||||||||||||||
| 228 | - | |||||||||||||||||||||||||||||||||||||
| 229 | All values are displayed with the prefix and suffix (if set), \e | - | ||||||||||||||||||||||||||||||||||||
| 230 | except for the special value, which only shows the special value | - | ||||||||||||||||||||||||||||||||||||
| 231 | text. This special text is passed in the QSpinBox::valueChanged() | - | ||||||||||||||||||||||||||||||||||||
| 232 | signal that passes a QString. | - | ||||||||||||||||||||||||||||||||||||
| 233 | - | |||||||||||||||||||||||||||||||||||||
| 234 | To turn off the special-value text display, call this function | - | ||||||||||||||||||||||||||||||||||||
| 235 | with an empty string. The default is no special-value text, i.e. | - | ||||||||||||||||||||||||||||||||||||
| 236 | the numeric value is shown as usual. | - | ||||||||||||||||||||||||||||||||||||
| 237 | - | |||||||||||||||||||||||||||||||||||||
| 238 | If no special-value text is set, specialValueText() returns an | - | ||||||||||||||||||||||||||||||||||||
| 239 | empty string. | - | ||||||||||||||||||||||||||||||||||||
| 240 | */ | - | ||||||||||||||||||||||||||||||||||||
| 241 | - | |||||||||||||||||||||||||||||||||||||
| 242 | QString QAbstractSpinBox::specialValueText() const | - | ||||||||||||||||||||||||||||||||||||
| 243 | { | - | ||||||||||||||||||||||||||||||||||||
| 244 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 245 | return d->specialValueText; never executed: return d->specialValueText; | 0 | ||||||||||||||||||||||||||||||||||||
| 246 | } | - | ||||||||||||||||||||||||||||||||||||
| 247 | - | |||||||||||||||||||||||||||||||||||||
| 248 | void QAbstractSpinBox::setSpecialValueText(const QString &specialValueText) | - | ||||||||||||||||||||||||||||||||||||
| 249 | { | - | ||||||||||||||||||||||||||||||||||||
| 250 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 251 | - | |||||||||||||||||||||||||||||||||||||
| 252 | d->specialValueText = specialValueText; | - | ||||||||||||||||||||||||||||||||||||
| 253 | d->cachedSizeHint = QSize(); // minimumSizeHint doesn't care about specialValueText | - | ||||||||||||||||||||||||||||||||||||
| 254 | d->clearCache(); | - | ||||||||||||||||||||||||||||||||||||
| 255 | d->updateEdit(); | - | ||||||||||||||||||||||||||||||||||||
| 256 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 257 | - | |||||||||||||||||||||||||||||||||||||
| 258 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 259 | \property QAbstractSpinBox::wrapping | - | ||||||||||||||||||||||||||||||||||||
| 260 | - | |||||||||||||||||||||||||||||||||||||
| 261 | \brief whether the spin box is circular. | - | ||||||||||||||||||||||||||||||||||||
| 262 | - | |||||||||||||||||||||||||||||||||||||
| 263 | If wrapping is true stepping up from maximum() value will take you | - | ||||||||||||||||||||||||||||||||||||
| 264 | to the minimum() value and vica versa. Wrapping only make sense if | - | ||||||||||||||||||||||||||||||||||||
| 265 | you have minimum() and maximum() values set. | - | ||||||||||||||||||||||||||||||||||||
| 266 | - | |||||||||||||||||||||||||||||||||||||
| 267 | \snippet code/src_gui_widgets_qabstractspinbox.cpp 0 | - | ||||||||||||||||||||||||||||||||||||
| 268 | - | |||||||||||||||||||||||||||||||||||||
| 269 | \sa QSpinBox::minimum(), QSpinBox::maximum() | - | ||||||||||||||||||||||||||||||||||||
| 270 | */ | - | ||||||||||||||||||||||||||||||||||||
| 271 | - | |||||||||||||||||||||||||||||||||||||
| 272 | bool QAbstractSpinBox::wrapping() const | - | ||||||||||||||||||||||||||||||||||||
| 273 | { | - | ||||||||||||||||||||||||||||||||||||
| 274 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 275 | return d->wrapping; never executed: return d->wrapping; | 0 | ||||||||||||||||||||||||||||||||||||
| 276 | } | - | ||||||||||||||||||||||||||||||||||||
| 277 | - | |||||||||||||||||||||||||||||||||||||
| 278 | void QAbstractSpinBox::setWrapping(bool wrapping) | - | ||||||||||||||||||||||||||||||||||||
| 279 | { | - | ||||||||||||||||||||||||||||||||||||
| 280 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 281 | d->wrapping = wrapping; | - | ||||||||||||||||||||||||||||||||||||
| 282 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 283 | - | |||||||||||||||||||||||||||||||||||||
| 284 | - | |||||||||||||||||||||||||||||||||||||
| 285 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 286 | \property QAbstractSpinBox::readOnly | - | ||||||||||||||||||||||||||||||||||||
| 287 | \brief whether the spin box is read only. | - | ||||||||||||||||||||||||||||||||||||
| 288 | - | |||||||||||||||||||||||||||||||||||||
| 289 | In read-only mode, the user can still copy the text to the | - | ||||||||||||||||||||||||||||||||||||
| 290 | clipboard, or drag and drop the text; | - | ||||||||||||||||||||||||||||||||||||
| 291 | but cannot edit it. | - | ||||||||||||||||||||||||||||||||||||
| 292 | - | |||||||||||||||||||||||||||||||||||||
| 293 | The QLineEdit in the QAbstractSpinBox does not show a cursor in | - | ||||||||||||||||||||||||||||||||||||
| 294 | read-only mode. | - | ||||||||||||||||||||||||||||||||||||
| 295 | - | |||||||||||||||||||||||||||||||||||||
| 296 | \sa QLineEdit::readOnly | - | ||||||||||||||||||||||||||||||||||||
| 297 | */ | - | ||||||||||||||||||||||||||||||||||||
| 298 | - | |||||||||||||||||||||||||||||||||||||
| 299 | bool QAbstractSpinBox::isReadOnly() const | - | ||||||||||||||||||||||||||||||||||||
| 300 | { | - | ||||||||||||||||||||||||||||||||||||
| 301 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 302 | return d->readOnly; never executed: return d->readOnly; | 0 | ||||||||||||||||||||||||||||||||||||
| 303 | } | - | ||||||||||||||||||||||||||||||||||||
| 304 | - | |||||||||||||||||||||||||||||||||||||
| 305 | void QAbstractSpinBox::setReadOnly(bool enable) | - | ||||||||||||||||||||||||||||||||||||
| 306 | { | - | ||||||||||||||||||||||||||||||||||||
| 307 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 308 | d->readOnly = enable; | - | ||||||||||||||||||||||||||||||||||||
| 309 | d->edit->setReadOnly(enable); | - | ||||||||||||||||||||||||||||||||||||
| 310 | QEvent event(QEvent::ReadOnlyChange); | - | ||||||||||||||||||||||||||||||||||||
| 311 | QApplication::sendEvent(this, &event); | - | ||||||||||||||||||||||||||||||||||||
| 312 | update(); | - | ||||||||||||||||||||||||||||||||||||
| 313 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 314 | - | |||||||||||||||||||||||||||||||||||||
| 315 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 316 | \property QAbstractSpinBox::keyboardTracking | - | ||||||||||||||||||||||||||||||||||||
| 317 | \brief whether keyboard tracking is enabled for the spinbox. | - | ||||||||||||||||||||||||||||||||||||
| 318 | \since 4.3 | - | ||||||||||||||||||||||||||||||||||||
| 319 | - | |||||||||||||||||||||||||||||||||||||
| 320 | If keyboard tracking is enabled (the default), the spinbox | - | ||||||||||||||||||||||||||||||||||||
| 321 | emits the valueChanged() signal while the new value is being | - | ||||||||||||||||||||||||||||||||||||
| 322 | entered from the keyboard. | - | ||||||||||||||||||||||||||||||||||||
| 323 | - | |||||||||||||||||||||||||||||||||||||
| 324 | E.g. when the user enters the value 600 by typing 6, 0, and 0, | - | ||||||||||||||||||||||||||||||||||||
| 325 | the spinbox emits 3 signals with the values 6, 60, and 600 | - | ||||||||||||||||||||||||||||||||||||
| 326 | respectively. | - | ||||||||||||||||||||||||||||||||||||
| 327 | - | |||||||||||||||||||||||||||||||||||||
| 328 | If keyboard tracking is disabled, the spinbox doesn't emit the | - | ||||||||||||||||||||||||||||||||||||
| 329 | valueChanged() signal while typing. It emits the signal later, | - | ||||||||||||||||||||||||||||||||||||
| 330 | when the return key is pressed, when keyboard focus is lost, or | - | ||||||||||||||||||||||||||||||||||||
| 331 | when other spinbox functionality is used, e.g. pressing an arrow | - | ||||||||||||||||||||||||||||||||||||
| 332 | key. | - | ||||||||||||||||||||||||||||||||||||
| 333 | */ | - | ||||||||||||||||||||||||||||||||||||
| 334 | - | |||||||||||||||||||||||||||||||||||||
| 335 | bool QAbstractSpinBox::keyboardTracking() const | - | ||||||||||||||||||||||||||||||||||||
| 336 | { | - | ||||||||||||||||||||||||||||||||||||
| 337 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 338 | return d->keyboardTracking; never executed: return d->keyboardTracking; | 0 | ||||||||||||||||||||||||||||||||||||
| 339 | } | - | ||||||||||||||||||||||||||||||||||||
| 340 | - | |||||||||||||||||||||||||||||||||||||
| 341 | void QAbstractSpinBox::setKeyboardTracking(bool enable) | - | ||||||||||||||||||||||||||||||||||||
| 342 | { | - | ||||||||||||||||||||||||||||||||||||
| 343 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 344 | d->keyboardTracking = enable; | - | ||||||||||||||||||||||||||||||||||||
| 345 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 346 | - | |||||||||||||||||||||||||||||||||||||
| 347 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 348 | \property QAbstractSpinBox::frame | - | ||||||||||||||||||||||||||||||||||||
| 349 | \brief whether the spin box draws itself with a frame | - | ||||||||||||||||||||||||||||||||||||
| 350 | - | |||||||||||||||||||||||||||||||||||||
| 351 | If enabled (the default) the spin box draws itself inside a frame, | - | ||||||||||||||||||||||||||||||||||||
| 352 | otherwise the spin box draws itself without any frame. | - | ||||||||||||||||||||||||||||||||||||
| 353 | */ | - | ||||||||||||||||||||||||||||||||||||
| 354 | - | |||||||||||||||||||||||||||||||||||||
| 355 | bool QAbstractSpinBox::hasFrame() const | - | ||||||||||||||||||||||||||||||||||||
| 356 | { | - | ||||||||||||||||||||||||||||||||||||
| 357 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 358 | return d->frame; never executed: return d->frame; | 0 | ||||||||||||||||||||||||||||||||||||
| 359 | } | - | ||||||||||||||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||||||||||||||
| 361 | - | |||||||||||||||||||||||||||||||||||||
| 362 | void QAbstractSpinBox::setFrame(bool enable) | - | ||||||||||||||||||||||||||||||||||||
| 363 | { | - | ||||||||||||||||||||||||||||||||||||
| 364 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 365 | d->frame = enable; | - | ||||||||||||||||||||||||||||||||||||
| 366 | update(); | - | ||||||||||||||||||||||||||||||||||||
| 367 | d->updateEditFieldGeometry(); | - | ||||||||||||||||||||||||||||||||||||
| 368 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 369 | - | |||||||||||||||||||||||||||||||||||||
| 370 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 371 | \property QAbstractSpinBox::accelerated | - | ||||||||||||||||||||||||||||||||||||
| 372 | \brief whether the spin box will accelerate the frequency of the steps when | - | ||||||||||||||||||||||||||||||||||||
| 373 | pressing the step Up/Down buttons. | - | ||||||||||||||||||||||||||||||||||||
| 374 | \since 4.2 | - | ||||||||||||||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||||||||||||||
| 376 | If enabled the spin box will increase/decrease the value faster | - | ||||||||||||||||||||||||||||||||||||
| 377 | the longer you hold the button down. | - | ||||||||||||||||||||||||||||||||||||
| 378 | */ | - | ||||||||||||||||||||||||||||||||||||
| 379 | - | |||||||||||||||||||||||||||||||||||||
| 380 | void QAbstractSpinBox::setAccelerated(bool accelerate) | - | ||||||||||||||||||||||||||||||||||||
| 381 | { | - | ||||||||||||||||||||||||||||||||||||
| 382 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 383 | d->accelerate = accelerate; | - | ||||||||||||||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||||||||||||||
| 385 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 386 | bool QAbstractSpinBox::isAccelerated() const | - | ||||||||||||||||||||||||||||||||||||
| 387 | { | - | ||||||||||||||||||||||||||||||||||||
| 388 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 389 | return d->accelerate; never executed: return d->accelerate; | 0 | ||||||||||||||||||||||||||||||||||||
| 390 | } | - | ||||||||||||||||||||||||||||||||||||
| 391 | - | |||||||||||||||||||||||||||||||||||||
| 392 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 393 | \property QAbstractSpinBox::showGroupSeparator | - | ||||||||||||||||||||||||||||||||||||
| 394 | \since 5.3 | - | ||||||||||||||||||||||||||||||||||||
| 395 | - | |||||||||||||||||||||||||||||||||||||
| 396 | - | |||||||||||||||||||||||||||||||||||||
| 397 | This property holds whether a thousands separator is enabled. By default this | - | ||||||||||||||||||||||||||||||||||||
| 398 | property is false. | - | ||||||||||||||||||||||||||||||||||||
| 399 | */ | - | ||||||||||||||||||||||||||||||||||||
| 400 | bool QAbstractSpinBox::isGroupSeparatorShown() const | - | ||||||||||||||||||||||||||||||||||||
| 401 | { | - | ||||||||||||||||||||||||||||||||||||
| 402 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 403 | return d->showGroupSeparator; never executed: return d->showGroupSeparator; | 0 | ||||||||||||||||||||||||||||||||||||
| 404 | } | - | ||||||||||||||||||||||||||||||||||||
| 405 | - | |||||||||||||||||||||||||||||||||||||
| 406 | void QAbstractSpinBox::setGroupSeparatorShown(bool shown) | - | ||||||||||||||||||||||||||||||||||||
| 407 | { | - | ||||||||||||||||||||||||||||||||||||
| 408 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 409 | if (d->showGroupSeparator == shown)
| 0 | ||||||||||||||||||||||||||||||||||||
| 410 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 411 | d->showGroupSeparator = shown; | - | ||||||||||||||||||||||||||||||||||||
| 412 | d->setValue(d->value, EmitIfChanged); | - | ||||||||||||||||||||||||||||||||||||
| 413 | updateGeometry(); | - | ||||||||||||||||||||||||||||||||||||
| 414 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 415 | - | |||||||||||||||||||||||||||||||||||||
| 416 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 417 | \enum QAbstractSpinBox::CorrectionMode | - | ||||||||||||||||||||||||||||||||||||
| 418 | - | |||||||||||||||||||||||||||||||||||||
| 419 | This enum type describes the mode the spinbox will use to correct | - | ||||||||||||||||||||||||||||||||||||
| 420 | an \l{QValidator::}{Intermediate} value if editing finishes. | - | ||||||||||||||||||||||||||||||||||||
| 421 | - | |||||||||||||||||||||||||||||||||||||
| 422 | \value CorrectToPreviousValue The spinbox will revert to the last | - | ||||||||||||||||||||||||||||||||||||
| 423 | valid value. | - | ||||||||||||||||||||||||||||||||||||
| 424 | - | |||||||||||||||||||||||||||||||||||||
| 425 | \value CorrectToNearestValue The spinbox will revert to the nearest | - | ||||||||||||||||||||||||||||||||||||
| 426 | valid value. | - | ||||||||||||||||||||||||||||||||||||
| 427 | - | |||||||||||||||||||||||||||||||||||||
| 428 | \sa correctionMode | - | ||||||||||||||||||||||||||||||||||||
| 429 | */ | - | ||||||||||||||||||||||||||||||||||||
| 430 | - | |||||||||||||||||||||||||||||||||||||
| 431 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 432 | \property QAbstractSpinBox::correctionMode | - | ||||||||||||||||||||||||||||||||||||
| 433 | \brief the mode to correct an \l{QValidator::}{Intermediate} | - | ||||||||||||||||||||||||||||||||||||
| 434 | value if editing finishes | - | ||||||||||||||||||||||||||||||||||||
| 435 | \since 4.2 | - | ||||||||||||||||||||||||||||||||||||
| 436 | - | |||||||||||||||||||||||||||||||||||||
| 437 | The default mode is QAbstractSpinBox::CorrectToPreviousValue. | - | ||||||||||||||||||||||||||||||||||||
| 438 | - | |||||||||||||||||||||||||||||||||||||
| 439 | \sa acceptableInput, validate(), fixup() | - | ||||||||||||||||||||||||||||||||||||
| 440 | */ | - | ||||||||||||||||||||||||||||||||||||
| 441 | void QAbstractSpinBox::setCorrectionMode(CorrectionMode correctionMode) | - | ||||||||||||||||||||||||||||||||||||
| 442 | { | - | ||||||||||||||||||||||||||||||||||||
| 443 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 444 | d->correctionMode = correctionMode; | - | ||||||||||||||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||||||||||||||
| 446 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 447 | QAbstractSpinBox::CorrectionMode QAbstractSpinBox::correctionMode() const | - | ||||||||||||||||||||||||||||||||||||
| 448 | { | - | ||||||||||||||||||||||||||||||||||||
| 449 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 450 | return d->correctionMode; never executed: return d->correctionMode; | 0 | ||||||||||||||||||||||||||||||||||||
| 451 | } | - | ||||||||||||||||||||||||||||||||||||
| 452 | - | |||||||||||||||||||||||||||||||||||||
| 453 | - | |||||||||||||||||||||||||||||||||||||
| 454 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 455 | \property QAbstractSpinBox::acceptableInput | - | ||||||||||||||||||||||||||||||||||||
| 456 | \brief whether the input satisfies the current validation | - | ||||||||||||||||||||||||||||||||||||
| 457 | \since 4.2 | - | ||||||||||||||||||||||||||||||||||||
| 458 | - | |||||||||||||||||||||||||||||||||||||
| 459 | \sa validate(), fixup(), correctionMode | - | ||||||||||||||||||||||||||||||||||||
| 460 | */ | - | ||||||||||||||||||||||||||||||||||||
| 461 | - | |||||||||||||||||||||||||||||||||||||
| 462 | bool QAbstractSpinBox::hasAcceptableInput() const | - | ||||||||||||||||||||||||||||||||||||
| 463 | { | - | ||||||||||||||||||||||||||||||||||||
| 464 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 465 | return d->edit->hasAcceptableInput(); never executed: return d->edit->hasAcceptableInput(); | 0 | ||||||||||||||||||||||||||||||||||||
| 466 | } | - | ||||||||||||||||||||||||||||||||||||
| 467 | - | |||||||||||||||||||||||||||||||||||||
| 468 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 469 | \property QAbstractSpinBox::alignment | - | ||||||||||||||||||||||||||||||||||||
| 470 | \brief the alignment of the spin box | - | ||||||||||||||||||||||||||||||||||||
| 471 | - | |||||||||||||||||||||||||||||||||||||
| 472 | Possible Values are Qt::AlignLeft, Qt::AlignRight, and Qt::AlignHCenter. | - | ||||||||||||||||||||||||||||||||||||
| 473 | - | |||||||||||||||||||||||||||||||||||||
| 474 | By default, the alignment is Qt::AlignLeft | - | ||||||||||||||||||||||||||||||||||||
| 475 | - | |||||||||||||||||||||||||||||||||||||
| 476 | Attempting to set the alignment to an illegal flag combination | - | ||||||||||||||||||||||||||||||||||||
| 477 | does nothing. | - | ||||||||||||||||||||||||||||||||||||
| 478 | - | |||||||||||||||||||||||||||||||||||||
| 479 | \sa Qt::Alignment | - | ||||||||||||||||||||||||||||||||||||
| 480 | */ | - | ||||||||||||||||||||||||||||||||||||
| 481 | - | |||||||||||||||||||||||||||||||||||||
| 482 | Qt::Alignment QAbstractSpinBox::alignment() const | - | ||||||||||||||||||||||||||||||||||||
| 483 | { | - | ||||||||||||||||||||||||||||||||||||
| 484 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 485 | - | |||||||||||||||||||||||||||||||||||||
| 486 | return (Qt::Alignment)d->edit->alignment(); never executed: return (Qt::Alignment)d->edit->alignment(); | 0 | ||||||||||||||||||||||||||||||||||||
| 487 | } | - | ||||||||||||||||||||||||||||||||||||
| 488 | - | |||||||||||||||||||||||||||||||||||||
| 489 | void QAbstractSpinBox::setAlignment(Qt::Alignment flag) | - | ||||||||||||||||||||||||||||||||||||
| 490 | { | - | ||||||||||||||||||||||||||||||||||||
| 491 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 492 | - | |||||||||||||||||||||||||||||||||||||
| 493 | d->edit->setAlignment(flag); | - | ||||||||||||||||||||||||||||||||||||
| 494 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 495 | - | |||||||||||||||||||||||||||||||||||||
| 496 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 497 | Selects all the text in the spinbox except the prefix and suffix. | - | ||||||||||||||||||||||||||||||||||||
| 498 | */ | - | ||||||||||||||||||||||||||||||||||||
| 499 | - | |||||||||||||||||||||||||||||||||||||
| 500 | void QAbstractSpinBox::selectAll() | - | ||||||||||||||||||||||||||||||||||||
| 501 | { | - | ||||||||||||||||||||||||||||||||||||
| 502 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 503 | - | |||||||||||||||||||||||||||||||||||||
| 504 | - | |||||||||||||||||||||||||||||||||||||
| 505 | if (!d->specialValue()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 506 | const int tmp = d->edit->displayText().size() - d->suffix.size(); | - | ||||||||||||||||||||||||||||||||||||
| 507 | d->edit->setSelection(tmp, -(tmp - d->prefix.size())); | - | ||||||||||||||||||||||||||||||||||||
| 508 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 509 | d->edit->selectAll(); | - | ||||||||||||||||||||||||||||||||||||
| 510 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 511 | } | - | ||||||||||||||||||||||||||||||||||||
| 512 | - | |||||||||||||||||||||||||||||||||||||
| 513 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 514 | Clears the lineedit of all text but prefix and suffix. | - | ||||||||||||||||||||||||||||||||||||
| 515 | */ | - | ||||||||||||||||||||||||||||||||||||
| 516 | - | |||||||||||||||||||||||||||||||||||||
| 517 | void QAbstractSpinBox::clear() | - | ||||||||||||||||||||||||||||||||||||
| 518 | { | - | ||||||||||||||||||||||||||||||||||||
| 519 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 520 | - | |||||||||||||||||||||||||||||||||||||
| 521 | d->edit->setText(d->prefix + d->suffix); | - | ||||||||||||||||||||||||||||||||||||
| 522 | d->edit->setCursorPosition(d->prefix.size()); | - | ||||||||||||||||||||||||||||||||||||
| 523 | d->cleared = true; | - | ||||||||||||||||||||||||||||||||||||
| 524 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 525 | - | |||||||||||||||||||||||||||||||||||||
| 526 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 527 | Virtual function that determines whether stepping up and down is | - | ||||||||||||||||||||||||||||||||||||
| 528 | legal at any given time. | - | ||||||||||||||||||||||||||||||||||||
| 529 | - | |||||||||||||||||||||||||||||||||||||
| 530 | The up arrow will be painted as disabled unless (stepEnabled() & | - | ||||||||||||||||||||||||||||||||||||
| 531 | StepUpEnabled) != 0. | - | ||||||||||||||||||||||||||||||||||||
| 532 | - | |||||||||||||||||||||||||||||||||||||
| 533 | The default implementation will return (StepUpEnabled| | - | ||||||||||||||||||||||||||||||||||||
| 534 | StepDownEnabled) if wrapping is turned on. Else it will return | - | ||||||||||||||||||||||||||||||||||||
| 535 | StepDownEnabled if value is > minimum() or'ed with StepUpEnabled if | - | ||||||||||||||||||||||||||||||||||||
| 536 | value < maximum(). | - | ||||||||||||||||||||||||||||||||||||
| 537 | - | |||||||||||||||||||||||||||||||||||||
| 538 | If you subclass QAbstractSpinBox you will need to reimplement this function. | - | ||||||||||||||||||||||||||||||||||||
| 539 | - | |||||||||||||||||||||||||||||||||||||
| 540 | \sa QSpinBox::minimum(), QSpinBox::maximum(), wrapping() | - | ||||||||||||||||||||||||||||||||||||
| 541 | */ | - | ||||||||||||||||||||||||||||||||||||
| 542 | - | |||||||||||||||||||||||||||||||||||||
| 543 | - | |||||||||||||||||||||||||||||||||||||
| 544 | QAbstractSpinBox::StepEnabled QAbstractSpinBox::stepEnabled() const | - | ||||||||||||||||||||||||||||||||||||
| 545 | { | - | ||||||||||||||||||||||||||||||||||||
| 546 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 547 | if (d->readOnly || d->type == QVariant::Invalid)
| 0 | ||||||||||||||||||||||||||||||||||||
| 548 | return StepNone; never executed: return StepNone; | 0 | ||||||||||||||||||||||||||||||||||||
| 549 | if (d->wrapping)
| 0 | ||||||||||||||||||||||||||||||||||||
| 550 | return StepEnabled(StepUpEnabled | StepDownEnabled); never executed: return StepEnabled(StepUpEnabled | StepDownEnabled); | 0 | ||||||||||||||||||||||||||||||||||||
| 551 | StepEnabled ret = StepNone; | - | ||||||||||||||||||||||||||||||||||||
| 552 | if (d->variantCompare(d->value, d->maximum) < 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 553 | ret |= StepUpEnabled; | - | ||||||||||||||||||||||||||||||||||||
| 554 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 555 | if (d->variantCompare(d->value, d->minimum) > 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 556 | ret |= StepDownEnabled; | - | ||||||||||||||||||||||||||||||||||||
| 557 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 558 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||||||||||||||
| 559 | } | - | ||||||||||||||||||||||||||||||||||||
| 560 | - | |||||||||||||||||||||||||||||||||||||
| 561 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 562 | This virtual function is called by the QAbstractSpinBox to | - | ||||||||||||||||||||||||||||||||||||
| 563 | determine whether \a input is valid. The \a pos parameter indicates | - | ||||||||||||||||||||||||||||||||||||
| 564 | the position in the string. Reimplemented in the various | - | ||||||||||||||||||||||||||||||||||||
| 565 | subclasses. | - | ||||||||||||||||||||||||||||||||||||
| 566 | */ | - | ||||||||||||||||||||||||||||||||||||
| 567 | - | |||||||||||||||||||||||||||||||||||||
| 568 | QValidator::State QAbstractSpinBox::validate(QString & /* input */, int & /* pos */) const | - | ||||||||||||||||||||||||||||||||||||
| 569 | { | - | ||||||||||||||||||||||||||||||||||||
| 570 | return QValidator::Acceptable; never executed: return QValidator::Acceptable; | 0 | ||||||||||||||||||||||||||||||||||||
| 571 | } | - | ||||||||||||||||||||||||||||||||||||
| 572 | - | |||||||||||||||||||||||||||||||||||||
| 573 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 574 | This virtual function is called by the QAbstractSpinBox if the | - | ||||||||||||||||||||||||||||||||||||
| 575 | \a input is not validated to QValidator::Acceptable when Return is | - | ||||||||||||||||||||||||||||||||||||
| 576 | pressed or interpretText() is called. It will try to change the | - | ||||||||||||||||||||||||||||||||||||
| 577 | text so it is valid. Reimplemented in the various subclasses. | - | ||||||||||||||||||||||||||||||||||||
| 578 | */ | - | ||||||||||||||||||||||||||||||||||||
| 579 | - | |||||||||||||||||||||||||||||||||||||
| 580 | void QAbstractSpinBox::fixup(QString & /* input */) const | - | ||||||||||||||||||||||||||||||||||||
| 581 | { | - | ||||||||||||||||||||||||||||||||||||
| 582 | } | - | ||||||||||||||||||||||||||||||||||||
| 583 | - | |||||||||||||||||||||||||||||||||||||
| 584 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 585 | Steps up by one linestep | - | ||||||||||||||||||||||||||||||||||||
| 586 | Calling this slot is analogous to calling stepBy(1); | - | ||||||||||||||||||||||||||||||||||||
| 587 | \sa stepBy(), stepDown() | - | ||||||||||||||||||||||||||||||||||||
| 588 | */ | - | ||||||||||||||||||||||||||||||||||||
| 589 | - | |||||||||||||||||||||||||||||||||||||
| 590 | void QAbstractSpinBox::stepUp() | - | ||||||||||||||||||||||||||||||||||||
| 591 | { | - | ||||||||||||||||||||||||||||||||||||
| 592 | stepBy(1); | - | ||||||||||||||||||||||||||||||||||||
| 593 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 594 | - | |||||||||||||||||||||||||||||||||||||
| 595 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 596 | Steps down by one linestep | - | ||||||||||||||||||||||||||||||||||||
| 597 | Calling this slot is analogous to calling stepBy(-1); | - | ||||||||||||||||||||||||||||||||||||
| 598 | \sa stepBy(), stepUp() | - | ||||||||||||||||||||||||||||||||||||
| 599 | */ | - | ||||||||||||||||||||||||||||||||||||
| 600 | - | |||||||||||||||||||||||||||||||||||||
| 601 | void QAbstractSpinBox::stepDown() | - | ||||||||||||||||||||||||||||||||||||
| 602 | { | - | ||||||||||||||||||||||||||||||||||||
| 603 | stepBy(-1); | - | ||||||||||||||||||||||||||||||||||||
| 604 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 605 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 606 | Virtual function that is called whenever the user triggers a step. | - | ||||||||||||||||||||||||||||||||||||
| 607 | The \a steps parameter indicates how many steps were taken, e.g. | - | ||||||||||||||||||||||||||||||||||||
| 608 | Pressing Qt::Key_Down will trigger a call to stepBy(-1), | - | ||||||||||||||||||||||||||||||||||||
| 609 | whereas pressing Qt::Key_Prior will trigger a call to | - | ||||||||||||||||||||||||||||||||||||
| 610 | stepBy(10). | - | ||||||||||||||||||||||||||||||||||||
| 611 | - | |||||||||||||||||||||||||||||||||||||
| 612 | If you subclass QAbstractSpinBox you must reimplement this | - | ||||||||||||||||||||||||||||||||||||
| 613 | function. Note that this function is called even if the resulting | - | ||||||||||||||||||||||||||||||||||||
| 614 | value will be outside the bounds of minimum and maximum. It's this | - | ||||||||||||||||||||||||||||||||||||
| 615 | function's job to handle these situations. | - | ||||||||||||||||||||||||||||||||||||
| 616 | */ | - | ||||||||||||||||||||||||||||||||||||
| 617 | - | |||||||||||||||||||||||||||||||||||||
| 618 | void QAbstractSpinBox::stepBy(int steps) | - | ||||||||||||||||||||||||||||||||||||
| 619 | { | - | ||||||||||||||||||||||||||||||||||||
| 620 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 621 | - | |||||||||||||||||||||||||||||||||||||
| 622 | const QVariant old = d->value; | - | ||||||||||||||||||||||||||||||||||||
| 623 | QString tmp = d->edit->displayText(); | - | ||||||||||||||||||||||||||||||||||||
| 624 | int cursorPos = d->edit->cursorPosition(); | - | ||||||||||||||||||||||||||||||||||||
| 625 | bool dontstep = false; | - | ||||||||||||||||||||||||||||||||||||
| 626 | EmitPolicy e = EmitIfChanged; | - | ||||||||||||||||||||||||||||||||||||
| 627 | if (d->pendingEmit) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 628 | dontstep = validate(tmp, cursorPos) != QValidator::Acceptable; | - | ||||||||||||||||||||||||||||||||||||
| 629 | d->cleared = false; | - | ||||||||||||||||||||||||||||||||||||
| 630 | d->interpret(NeverEmit); | - | ||||||||||||||||||||||||||||||||||||
| 631 | if (d->value != old)
| 0 | ||||||||||||||||||||||||||||||||||||
| 632 | e = AlwaysEmit; never executed: e = AlwaysEmit; | 0 | ||||||||||||||||||||||||||||||||||||
| 633 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 634 | if (!dontstep) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 635 | d->setValue(d->bound(d->value + (d->singleStep * steps), old, steps), e); | - | ||||||||||||||||||||||||||||||||||||
| 636 | } else if (e == AlwaysEmit) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
| 637 | d->emitSignals(e, old); | - | ||||||||||||||||||||||||||||||||||||
| 638 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 639 | selectAll(); | - | ||||||||||||||||||||||||||||||||||||
| 640 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 641 | - | |||||||||||||||||||||||||||||||||||||
| 642 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 643 | This function returns a pointer to the line edit of the spin box. | - | ||||||||||||||||||||||||||||||||||||
| 644 | */ | - | ||||||||||||||||||||||||||||||||||||
| 645 | - | |||||||||||||||||||||||||||||||||||||
| 646 | QLineEdit *QAbstractSpinBox::lineEdit() const | - | ||||||||||||||||||||||||||||||||||||
| 647 | { | - | ||||||||||||||||||||||||||||||||||||
| 648 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 649 | - | |||||||||||||||||||||||||||||||||||||
| 650 | return d->edit; never executed: return d->edit; | 0 | ||||||||||||||||||||||||||||||||||||
| 651 | } | - | ||||||||||||||||||||||||||||||||||||
| 652 | - | |||||||||||||||||||||||||||||||||||||
| 653 | - | |||||||||||||||||||||||||||||||||||||
| 654 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 655 | \fn void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit) | - | ||||||||||||||||||||||||||||||||||||
| 656 | - | |||||||||||||||||||||||||||||||||||||
| 657 | Sets the line edit of the spinbox to be \a lineEdit instead of the | - | ||||||||||||||||||||||||||||||||||||
| 658 | current line edit widget. \a lineEdit can not be 0. | - | ||||||||||||||||||||||||||||||||||||
| 659 | - | |||||||||||||||||||||||||||||||||||||
| 660 | QAbstractSpinBox takes ownership of the new lineEdit | - | ||||||||||||||||||||||||||||||||||||
| 661 | - | |||||||||||||||||||||||||||||||||||||
| 662 | If QLineEdit::validator() for the \a lineEdit returns 0, the internal | - | ||||||||||||||||||||||||||||||||||||
| 663 | validator of the spinbox will be set on the line edit. | - | ||||||||||||||||||||||||||||||||||||
| 664 | */ | - | ||||||||||||||||||||||||||||||||||||
| 665 | - | |||||||||||||||||||||||||||||||||||||
| 666 | void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit) | - | ||||||||||||||||||||||||||||||||||||
| 667 | { | - | ||||||||||||||||||||||||||||||||||||
| 668 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 669 | - | |||||||||||||||||||||||||||||||||||||
| 670 | if (!lineEdit) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 671 | Q_ASSERT(lineEdit); | - | ||||||||||||||||||||||||||||||||||||
| 672 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 673 | } | - | ||||||||||||||||||||||||||||||||||||
| 674 | delete d->edit; | - | ||||||||||||||||||||||||||||||||||||
| 675 | d->edit = lineEdit; | - | ||||||||||||||||||||||||||||||||||||
| 676 | if (!d->edit->validator())
| 0 | ||||||||||||||||||||||||||||||||||||
| 677 | d->edit->setValidator(d->validator); never executed: d->edit->setValidator(d->validator); | 0 | ||||||||||||||||||||||||||||||||||||
| 678 | - | |||||||||||||||||||||||||||||||||||||
| 679 | if (d->edit->parent() != this)
| 0 | ||||||||||||||||||||||||||||||||||||
| 680 | d->edit->setParent(this); never executed: d->edit->setParent(this); | 0 | ||||||||||||||||||||||||||||||||||||
| 681 | - | |||||||||||||||||||||||||||||||||||||
| 682 | d->edit->setFrame(false); | - | ||||||||||||||||||||||||||||||||||||
| 683 | d->edit->setFocusProxy(this); | - | ||||||||||||||||||||||||||||||||||||
| 684 | d->edit->setAcceptDrops(false); | - | ||||||||||||||||||||||||||||||||||||
| 685 | - | |||||||||||||||||||||||||||||||||||||
| 686 | if (d->type != QVariant::Invalid) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 687 | connect(d->edit, SIGNAL(textChanged(QString)), | - | ||||||||||||||||||||||||||||||||||||
| 688 | this, SLOT(_q_editorTextChanged(QString))); | - | ||||||||||||||||||||||||||||||||||||
| 689 | connect(d->edit, SIGNAL(cursorPositionChanged(int,int)), | - | ||||||||||||||||||||||||||||||||||||
| 690 | this, SLOT(_q_editorCursorPositionChanged(int,int))); | - | ||||||||||||||||||||||||||||||||||||
| 691 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 692 | d->updateEditFieldGeometry(); | - | ||||||||||||||||||||||||||||||||||||
| 693 | d->edit->setContextMenuPolicy(Qt::NoContextMenu); | - | ||||||||||||||||||||||||||||||||||||
| 694 | d->edit->d_func()->control->setAccessibleObject(this); | - | ||||||||||||||||||||||||||||||||||||
| 695 | - | |||||||||||||||||||||||||||||||||||||
| 696 | if (isVisible())
| 0 | ||||||||||||||||||||||||||||||||||||
| 697 | d->edit->show(); never executed: d->edit->show(); | 0 | ||||||||||||||||||||||||||||||||||||
| 698 | if (isVisible())
| 0 | ||||||||||||||||||||||||||||||||||||
| 699 | d->updateEdit(); never executed: d->updateEdit(); | 0 | ||||||||||||||||||||||||||||||||||||
| 700 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 701 | - | |||||||||||||||||||||||||||||||||||||
| 702 | - | |||||||||||||||||||||||||||||||||||||
| 703 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 704 | This function interprets the text of the spin box. If the value | - | ||||||||||||||||||||||||||||||||||||
| 705 | has changed since last interpretation it will emit signals. | - | ||||||||||||||||||||||||||||||||||||
| 706 | */ | - | ||||||||||||||||||||||||||||||||||||
| 707 | - | |||||||||||||||||||||||||||||||||||||
| 708 | void QAbstractSpinBox::interpretText() | - | ||||||||||||||||||||||||||||||||||||
| 709 | { | - | ||||||||||||||||||||||||||||||||||||
| 710 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 711 | d->interpret(EmitIfChanged); | - | ||||||||||||||||||||||||||||||||||||
| 712 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 713 | - | |||||||||||||||||||||||||||||||||||||
| 714 | /* | - | ||||||||||||||||||||||||||||||||||||
| 715 | Reimplemented in 4.6, so be careful. | - | ||||||||||||||||||||||||||||||||||||
| 716 | */ | - | ||||||||||||||||||||||||||||||||||||
| 717 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 718 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 719 | */ | - | ||||||||||||||||||||||||||||||||||||
| 720 | QVariant QAbstractSpinBox::inputMethodQuery(Qt::InputMethodQuery query) const | - | ||||||||||||||||||||||||||||||||||||
| 721 | { | - | ||||||||||||||||||||||||||||||||||||
| 722 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 723 | const QVariant lineEditValue = d->edit->inputMethodQuery(query); | - | ||||||||||||||||||||||||||||||||||||
| 724 | switch (query) { | - | ||||||||||||||||||||||||||||||||||||
| 725 | case Qt::ImHints: never executed: case Qt::ImHints: | 0 | ||||||||||||||||||||||||||||||||||||
| 726 | if (const int hints = inputMethodHints())
| 0 | ||||||||||||||||||||||||||||||||||||
| 727 | return QVariant(hints | lineEditValue.toInt()); never executed: return QVariant(hints | lineEditValue.toInt()); | 0 | ||||||||||||||||||||||||||||||||||||
| 728 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 729 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||
| 730 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 731 | } | - | ||||||||||||||||||||||||||||||||||||
| 732 | return lineEditValue; never executed: return lineEditValue; | 0 | ||||||||||||||||||||||||||||||||||||
| 733 | } | - | ||||||||||||||||||||||||||||||||||||
| 734 | - | |||||||||||||||||||||||||||||||||||||
| 735 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 736 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 737 | */ | - | ||||||||||||||||||||||||||||||||||||
| 738 | - | |||||||||||||||||||||||||||||||||||||
| 739 | bool QAbstractSpinBox::event(QEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 740 | { | - | ||||||||||||||||||||||||||||||||||||
| 741 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 742 | switch (event->type()) { | - | ||||||||||||||||||||||||||||||||||||
| 743 | case QEvent::FontChange: never executed: case QEvent::FontChange: | 0 | ||||||||||||||||||||||||||||||||||||
| 744 | case QEvent::StyleChange: never executed: case QEvent::StyleChange: | 0 | ||||||||||||||||||||||||||||||||||||
| 745 | d->cachedSizeHint = d->cachedMinimumSizeHint = QSize(); | - | ||||||||||||||||||||||||||||||||||||
| 746 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 747 | case QEvent::ApplicationLayoutDirectionChange: never executed: case QEvent::ApplicationLayoutDirectionChange: | 0 | ||||||||||||||||||||||||||||||||||||
| 748 | case QEvent::LayoutDirectionChange: never executed: case QEvent::LayoutDirectionChange: | 0 | ||||||||||||||||||||||||||||||||||||
| 749 | d->updateEditFieldGeometry(); | - | ||||||||||||||||||||||||||||||||||||
| 750 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 751 | case QEvent::HoverEnter: never executed: case QEvent::HoverEnter: | 0 | ||||||||||||||||||||||||||||||||||||
| 752 | case QEvent::HoverLeave: never executed: case QEvent::HoverLeave: | 0 | ||||||||||||||||||||||||||||||||||||
| 753 | case QEvent::HoverMove: never executed: case QEvent::HoverMove: | 0 | ||||||||||||||||||||||||||||||||||||
| 754 | d->updateHoverControl(static_cast<const QHoverEvent *>(event)->pos()); | - | ||||||||||||||||||||||||||||||||||||
| 755 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 756 | case QEvent::ShortcutOverride: never executed: case QEvent::ShortcutOverride: | 0 | ||||||||||||||||||||||||||||||||||||
| 757 | if (d->edit->event(event))
| 0 | ||||||||||||||||||||||||||||||||||||
| 758 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||||||||
| 759 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 760 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
| 761 | case QEvent::EnterEditFocus: | - | ||||||||||||||||||||||||||||||||||||
| 762 | case QEvent::LeaveEditFocus: | - | ||||||||||||||||||||||||||||||||||||
| 763 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||||||||||||||
| 764 | const bool b = d->edit->event(event); | - | ||||||||||||||||||||||||||||||||||||
| 765 | d->edit->setSelection(d->edit->displayText().size() - d->suffix.size(),0); | - | ||||||||||||||||||||||||||||||||||||
| 766 | if (event->type() == QEvent::LeaveEditFocus) | - | ||||||||||||||||||||||||||||||||||||
| 767 | emit editingFinished(); | - | ||||||||||||||||||||||||||||||||||||
| 768 | if (b) | - | ||||||||||||||||||||||||||||||||||||
| 769 | return true; | - | ||||||||||||||||||||||||||||||||||||
| 770 | } | - | ||||||||||||||||||||||||||||||||||||
| 771 | break; | - | ||||||||||||||||||||||||||||||||||||
| 772 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 773 | case QEvent::InputMethod: never executed: case QEvent::InputMethod: | 0 | ||||||||||||||||||||||||||||||||||||
| 774 | return d->edit->event(event); never executed: return d->edit->event(event); | 0 | ||||||||||||||||||||||||||||||||||||
| 775 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||
| 776 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 777 | } | - | ||||||||||||||||||||||||||||||||||||
| 778 | return QWidget::event(event); never executed: return QWidget::event(event); | 0 | ||||||||||||||||||||||||||||||||||||
| 779 | } | - | ||||||||||||||||||||||||||||||||||||
| 780 | - | |||||||||||||||||||||||||||||||||||||
| 781 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 782 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 783 | */ | - | ||||||||||||||||||||||||||||||||||||
| 784 | - | |||||||||||||||||||||||||||||||||||||
| 785 | void QAbstractSpinBox::showEvent(QShowEvent *) | - | ||||||||||||||||||||||||||||||||||||
| 786 | { | - | ||||||||||||||||||||||||||||||||||||
| 787 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 788 | d->reset(); | - | ||||||||||||||||||||||||||||||||||||
| 789 | - | |||||||||||||||||||||||||||||||||||||
| 790 | if (d->ignoreUpdateEdit) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 791 | d->ignoreUpdateEdit = false; | - | ||||||||||||||||||||||||||||||||||||
| 792 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 793 | d->updateEdit(); | - | ||||||||||||||||||||||||||||||||||||
| 794 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 795 | } | - | ||||||||||||||||||||||||||||||||||||
| 796 | - | |||||||||||||||||||||||||||||||||||||
| 797 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 798 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 799 | */ | - | ||||||||||||||||||||||||||||||||||||
| 800 | - | |||||||||||||||||||||||||||||||||||||
| 801 | void QAbstractSpinBox::changeEvent(QEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 802 | { | - | ||||||||||||||||||||||||||||||||||||
| 803 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 804 | - | |||||||||||||||||||||||||||||||||||||
| 805 | switch (event->type()) { | - | ||||||||||||||||||||||||||||||||||||
| 806 | case QEvent::StyleChange: never executed: case QEvent::StyleChange: | 0 | ||||||||||||||||||||||||||||||||||||
| 807 | d->spinClickTimerInterval = style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, 0, this); | - | ||||||||||||||||||||||||||||||||||||
| 808 | d->spinClickThresholdTimerInterval = | - | ||||||||||||||||||||||||||||||||||||
| 809 | style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatThreshold, 0, this); | - | ||||||||||||||||||||||||||||||||||||
| 810 | d->reset(); | - | ||||||||||||||||||||||||||||||||||||
| 811 | d->updateEditFieldGeometry(); | - | ||||||||||||||||||||||||||||||||||||
| 812 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 813 | case QEvent::EnabledChange: never executed: case QEvent::EnabledChange: | 0 | ||||||||||||||||||||||||||||||||||||
| 814 | if (!isEnabled()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 815 | d->reset(); | - | ||||||||||||||||||||||||||||||||||||
| 816 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 817 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 818 | case QEvent::ActivationChange: never executed: case QEvent::ActivationChange: | 0 | ||||||||||||||||||||||||||||||||||||
| 819 | if (!isActiveWindow()){
| 0 | ||||||||||||||||||||||||||||||||||||
| 820 | d->reset(); | - | ||||||||||||||||||||||||||||||||||||
| 821 | if (d->pendingEmit) // pendingEmit can be true even if it hasn't changed.
| 0 | ||||||||||||||||||||||||||||||||||||
| 822 | d->interpret(EmitIfChanged); // E.g. 10 to 10.0 never executed: d->interpret(EmitIfChanged); | 0 | ||||||||||||||||||||||||||||||||||||
| 823 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 824 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 825 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||
| 826 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 827 | } | - | ||||||||||||||||||||||||||||||||||||
| 828 | QWidget::changeEvent(event); | - | ||||||||||||||||||||||||||||||||||||
| 829 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 830 | - | |||||||||||||||||||||||||||||||||||||
| 831 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 832 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 833 | */ | - | ||||||||||||||||||||||||||||||||||||
| 834 | - | |||||||||||||||||||||||||||||||||||||
| 835 | void QAbstractSpinBox::resizeEvent(QResizeEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 836 | { | - | ||||||||||||||||||||||||||||||||||||
| 837 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 838 | QWidget::resizeEvent(event); | - | ||||||||||||||||||||||||||||||||||||
| 839 | - | |||||||||||||||||||||||||||||||||||||
| 840 | d->updateEditFieldGeometry(); | - | ||||||||||||||||||||||||||||||||||||
| 841 | update(); | - | ||||||||||||||||||||||||||||||||||||
| 842 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 843 | - | |||||||||||||||||||||||||||||||||||||
| 844 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 845 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 846 | */ | - | ||||||||||||||||||||||||||||||||||||
| 847 | - | |||||||||||||||||||||||||||||||||||||
| 848 | QSize QAbstractSpinBox::sizeHint() const | - | ||||||||||||||||||||||||||||||||||||
| 849 | { | - | ||||||||||||||||||||||||||||||||||||
| 850 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 851 | if (d->cachedSizeHint.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 852 | ensurePolished(); | - | ||||||||||||||||||||||||||||||||||||
| 853 | - | |||||||||||||||||||||||||||||||||||||
| 854 | const QFontMetrics fm(fontMetrics()); | - | ||||||||||||||||||||||||||||||||||||
| 855 | int h = d->edit->sizeHint().height(); | - | ||||||||||||||||||||||||||||||||||||
| 856 | int w = 0; | - | ||||||||||||||||||||||||||||||||||||
| 857 | QString s; | - | ||||||||||||||||||||||||||||||||||||
| 858 | QString fixedContent = d->prefix + d->suffix + QLatin1Char(' '); | - | ||||||||||||||||||||||||||||||||||||
| 859 | s = d->textFromValue(d->minimum); | - | ||||||||||||||||||||||||||||||||||||
| 860 | s.truncate(18); | - | ||||||||||||||||||||||||||||||||||||
| 861 | s += fixedContent; | - | ||||||||||||||||||||||||||||||||||||
| 862 | w = qMax(w, fm.width(s)); | - | ||||||||||||||||||||||||||||||||||||
| 863 | s = d->textFromValue(d->maximum); | - | ||||||||||||||||||||||||||||||||||||
| 864 | s.truncate(18); | - | ||||||||||||||||||||||||||||||||||||
| 865 | s += fixedContent; | - | ||||||||||||||||||||||||||||||||||||
| 866 | w = qMax(w, fm.width(s)); | - | ||||||||||||||||||||||||||||||||||||
| 867 | - | |||||||||||||||||||||||||||||||||||||
| 868 | if (d->specialValueText.size()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 869 | s = d->specialValueText; | - | ||||||||||||||||||||||||||||||||||||
| 870 | w = qMax(w, fm.width(s)); | - | ||||||||||||||||||||||||||||||||||||
| 871 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 872 | w += 2; // cursor blinking space | - | ||||||||||||||||||||||||||||||||||||
| 873 | - | |||||||||||||||||||||||||||||||||||||
| 874 | QStyleOptionSpinBox opt; | - | ||||||||||||||||||||||||||||||||||||
| 875 | initStyleOption(&opt); | - | ||||||||||||||||||||||||||||||||||||
| 876 | QSize hint(w, h); | - | ||||||||||||||||||||||||||||||||||||
| 877 | d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this) | - | ||||||||||||||||||||||||||||||||||||
| 878 | .expandedTo(QApplication::globalStrut()); | - | ||||||||||||||||||||||||||||||||||||
| 879 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 880 | return d->cachedSizeHint; never executed: return d->cachedSizeHint; | 0 | ||||||||||||||||||||||||||||||||||||
| 881 | } | - | ||||||||||||||||||||||||||||||||||||
| 882 | - | |||||||||||||||||||||||||||||||||||||
| 883 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 884 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 885 | */ | - | ||||||||||||||||||||||||||||||||||||
| 886 | - | |||||||||||||||||||||||||||||||||||||
| 887 | QSize QAbstractSpinBox::minimumSizeHint() const | - | ||||||||||||||||||||||||||||||||||||
| 888 | { | - | ||||||||||||||||||||||||||||||||||||
| 889 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 890 | if (d->cachedMinimumSizeHint.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 891 | //Use the prefix and range to calculate the minimumSizeHint | - | ||||||||||||||||||||||||||||||||||||
| 892 | ensurePolished(); | - | ||||||||||||||||||||||||||||||||||||
| 893 | - | |||||||||||||||||||||||||||||||||||||
| 894 | const QFontMetrics fm(fontMetrics()); | - | ||||||||||||||||||||||||||||||||||||
| 895 | int h = d->edit->minimumSizeHint().height(); | - | ||||||||||||||||||||||||||||||||||||
| 896 | int w = 0; | - | ||||||||||||||||||||||||||||||||||||
| 897 | - | |||||||||||||||||||||||||||||||||||||
| 898 | QString s; | - | ||||||||||||||||||||||||||||||||||||
| 899 | QString fixedContent = d->prefix + QLatin1Char(' '); | - | ||||||||||||||||||||||||||||||||||||
| 900 | s = d->textFromValue(d->minimum); | - | ||||||||||||||||||||||||||||||||||||
| 901 | s.truncate(18); | - | ||||||||||||||||||||||||||||||||||||
| 902 | s += fixedContent; | - | ||||||||||||||||||||||||||||||||||||
| 903 | w = qMax(w, fm.width(s)); | - | ||||||||||||||||||||||||||||||||||||
| 904 | s = d->textFromValue(d->maximum); | - | ||||||||||||||||||||||||||||||||||||
| 905 | s.truncate(18); | - | ||||||||||||||||||||||||||||||||||||
| 906 | s += fixedContent; | - | ||||||||||||||||||||||||||||||||||||
| 907 | w = qMax(w, fm.width(s)); | - | ||||||||||||||||||||||||||||||||||||
| 908 | - | |||||||||||||||||||||||||||||||||||||
| 909 | if (d->specialValueText.size()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 910 | s = d->specialValueText; | - | ||||||||||||||||||||||||||||||||||||
| 911 | w = qMax(w, fm.width(s)); | - | ||||||||||||||||||||||||||||||||||||
| 912 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 913 | w += 2; // cursor blinking space | - | ||||||||||||||||||||||||||||||||||||
| 914 | - | |||||||||||||||||||||||||||||||||||||
| 915 | QStyleOptionSpinBox opt; | - | ||||||||||||||||||||||||||||||||||||
| 916 | initStyleOption(&opt); | - | ||||||||||||||||||||||||||||||||||||
| 917 | QSize hint(w, h); | - | ||||||||||||||||||||||||||||||||||||
| 918 | - | |||||||||||||||||||||||||||||||||||||
| 919 | d->cachedMinimumSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this) | - | ||||||||||||||||||||||||||||||||||||
| 920 | .expandedTo(QApplication::globalStrut()); | - | ||||||||||||||||||||||||||||||||||||
| 921 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 922 | return d->cachedMinimumSizeHint; never executed: return d->cachedMinimumSizeHint; | 0 | ||||||||||||||||||||||||||||||||||||
| 923 | } | - | ||||||||||||||||||||||||||||||||||||
| 924 | - | |||||||||||||||||||||||||||||||||||||
| 925 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 926 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 927 | */ | - | ||||||||||||||||||||||||||||||||||||
| 928 | - | |||||||||||||||||||||||||||||||||||||
| 929 | void QAbstractSpinBox::paintEvent(QPaintEvent *) | - | ||||||||||||||||||||||||||||||||||||
| 930 | { | - | ||||||||||||||||||||||||||||||||||||
| 931 | QStyleOptionSpinBox opt; | - | ||||||||||||||||||||||||||||||||||||
| 932 | initStyleOption(&opt); | - | ||||||||||||||||||||||||||||||||||||
| 933 | QStylePainter p(this); | - | ||||||||||||||||||||||||||||||||||||
| 934 | p.drawComplexControl(QStyle::CC_SpinBox, opt); | - | ||||||||||||||||||||||||||||||||||||
| 935 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 936 | - | |||||||||||||||||||||||||||||||||||||
| 937 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 938 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 939 | - | |||||||||||||||||||||||||||||||||||||
| 940 | This function handles keyboard input. | - | ||||||||||||||||||||||||||||||||||||
| 941 | - | |||||||||||||||||||||||||||||||||||||
| 942 | The following keys are handled specifically: | - | ||||||||||||||||||||||||||||||||||||
| 943 | \table | - | ||||||||||||||||||||||||||||||||||||
| 944 | \row \li Enter/Return | - | ||||||||||||||||||||||||||||||||||||
| 945 | \li This will reinterpret the text and emit a signal even if the value has not changed | - | ||||||||||||||||||||||||||||||||||||
| 946 | since last time a signal was emitted. | - | ||||||||||||||||||||||||||||||||||||
| 947 | \row \li Up | - | ||||||||||||||||||||||||||||||||||||
| 948 | \li This will invoke stepBy(1) | - | ||||||||||||||||||||||||||||||||||||
| 949 | \row \li Down | - | ||||||||||||||||||||||||||||||||||||
| 950 | \li This will invoke stepBy(-1) | - | ||||||||||||||||||||||||||||||||||||
| 951 | \row \li Page up | - | ||||||||||||||||||||||||||||||||||||
| 952 | \li This will invoke stepBy(10) | - | ||||||||||||||||||||||||||||||||||||
| 953 | \row \li Page down | - | ||||||||||||||||||||||||||||||||||||
| 954 | \li This will invoke stepBy(-10) | - | ||||||||||||||||||||||||||||||||||||
| 955 | \endtable | - | ||||||||||||||||||||||||||||||||||||
| 956 | */ | - | ||||||||||||||||||||||||||||||||||||
| 957 | - | |||||||||||||||||||||||||||||||||||||
| 958 | - | |||||||||||||||||||||||||||||||||||||
| 959 | void QAbstractSpinBox::keyPressEvent(QKeyEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 960 | { | - | ||||||||||||||||||||||||||||||||||||
| 961 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 962 | - | |||||||||||||||||||||||||||||||||||||
| 963 | if (!event->text().isEmpty() && d->edit->cursorPosition() < d->prefix.size())
| 0 | ||||||||||||||||||||||||||||||||||||
| 964 | d->edit->setCursorPosition(d->prefix.size()); never executed: d->edit->setCursorPosition(d->prefix.size()); | 0 | ||||||||||||||||||||||||||||||||||||
| 965 | - | |||||||||||||||||||||||||||||||||||||
| 966 | int steps = 1; | - | ||||||||||||||||||||||||||||||||||||
| 967 | bool isPgUpOrDown = false; | - | ||||||||||||||||||||||||||||||||||||
| 968 | switch (event->key()) { | - | ||||||||||||||||||||||||||||||||||||
| 969 | case Qt::Key_PageUp: never executed: case Qt::Key_PageUp: | 0 | ||||||||||||||||||||||||||||||||||||
| 970 | case Qt::Key_PageDown: never executed: case Qt::Key_PageDown: | 0 | ||||||||||||||||||||||||||||||||||||
| 971 | steps *= 10; | - | ||||||||||||||||||||||||||||||||||||
| 972 | isPgUpOrDown = true; | - | ||||||||||||||||||||||||||||||||||||
| 973 | case Qt::Key_Up: code before this statement never executed: case Qt::Key_Up:never executed: case Qt::Key_Up: | 0 | ||||||||||||||||||||||||||||||||||||
| 974 | case Qt::Key_Down: { never executed: case Qt::Key_Down: | 0 | ||||||||||||||||||||||||||||||||||||
| 975 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
| 976 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||||||||||||||
| 977 | // Reserve up/down for nav - use left/right for edit. | - | ||||||||||||||||||||||||||||||||||||
| 978 | if (!hasEditFocus() && (event->key() == Qt::Key_Up | - | ||||||||||||||||||||||||||||||||||||
| 979 | || event->key() == Qt::Key_Down)) { | - | ||||||||||||||||||||||||||||||||||||
| 980 | event->ignore(); | - | ||||||||||||||||||||||||||||||||||||
| 981 | return; | - | ||||||||||||||||||||||||||||||||||||
| 982 | } | - | ||||||||||||||||||||||||||||||||||||
| 983 | } | - | ||||||||||||||||||||||||||||||||||||
| 984 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 985 | event->accept(); | - | ||||||||||||||||||||||||||||||||||||
| 986 | const bool up = (event->key() == Qt::Key_PageUp || event->key() == Qt::Key_Up);
| 0 | ||||||||||||||||||||||||||||||||||||
| 987 | if (!(stepEnabled() & (up ? StepUpEnabled : StepDownEnabled)))
| 0 | ||||||||||||||||||||||||||||||||||||
| 988 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 989 | if (!up)
| 0 | ||||||||||||||||||||||||||||||||||||
| 990 | steps *= -1; never executed: steps *= -1; | 0 | ||||||||||||||||||||||||||||||||||||
| 991 | if (style()->styleHint(QStyle::SH_SpinBox_AnimateButton, 0, this)) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 992 | d->buttonState = (Keyboard | (up ? Up : Down)); | - | ||||||||||||||||||||||||||||||||||||
| 993 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 994 | if (d->spinClickTimerId == -1)
| 0 | ||||||||||||||||||||||||||||||||||||
| 995 | stepBy(steps); never executed: stepBy(steps); | 0 | ||||||||||||||||||||||||||||||||||||
| 996 | if(event->isAutoRepeat() && !isPgUpOrDown) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 997 | if(d->spinClickThresholdTimerId == -1 && d->spinClickTimerId == -1) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 998 | d->updateState(up, true); | - | ||||||||||||||||||||||||||||||||||||
| 999 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1000 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1001 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||||||||
| 1002 | QAccessibleValueChangeEvent event(this, d->value); | - | ||||||||||||||||||||||||||||||||||||
| 1003 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||||||||||||||||||||
| 1004 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1005 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1006 | } | - | ||||||||||||||||||||||||||||||||||||
| 1007 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
| 1008 | case Qt::Key_Left: | - | ||||||||||||||||||||||||||||||||||||
| 1009 | case Qt::Key_Right: | - | ||||||||||||||||||||||||||||||||||||
| 1010 | if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { | - | ||||||||||||||||||||||||||||||||||||
| 1011 | event->ignore(); | - | ||||||||||||||||||||||||||||||||||||
| 1012 | return; | - | ||||||||||||||||||||||||||||||||||||
| 1013 | } | - | ||||||||||||||||||||||||||||||||||||
| 1014 | break; | - | ||||||||||||||||||||||||||||||||||||
| 1015 | case Qt::Key_Back: | - | ||||||||||||||||||||||||||||||||||||
| 1016 | if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { | - | ||||||||||||||||||||||||||||||||||||
| 1017 | event->ignore(); | - | ||||||||||||||||||||||||||||||||||||
| 1018 | return; | - | ||||||||||||||||||||||||||||||||||||
| 1019 | } | - | ||||||||||||||||||||||||||||||||||||
| 1020 | break; | - | ||||||||||||||||||||||||||||||||||||
| 1021 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1022 | case Qt::Key_Enter: never executed: case Qt::Key_Enter: | 0 | ||||||||||||||||||||||||||||||||||||
| 1023 | case Qt::Key_Return: never executed: case Qt::Key_Return: | 0 | ||||||||||||||||||||||||||||||||||||
| 1024 | d->edit->d_func()->control->clearUndo(); | - | ||||||||||||||||||||||||||||||||||||
| 1025 | d->interpret(d->keyboardTracking ? AlwaysEmit : EmitIfChanged); | - | ||||||||||||||||||||||||||||||||||||
| 1026 | selectAll(); | - | ||||||||||||||||||||||||||||||||||||
| 1027 | event->ignore(); | - | ||||||||||||||||||||||||||||||||||||
| 1028 | emit editingFinished(); | - | ||||||||||||||||||||||||||||||||||||
| 1029 | emit d->edit->returnPressed(); | - | ||||||||||||||||||||||||||||||||||||
| 1030 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1031 | - | |||||||||||||||||||||||||||||||||||||
| 1032 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
| 1033 | case Qt::Key_Select: | - | ||||||||||||||||||||||||||||||||||||
| 1034 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||||||||||||||
| 1035 | // Toggles between left/right moving cursor and inc/dec. | - | ||||||||||||||||||||||||||||||||||||
| 1036 | setEditFocus(!hasEditFocus()); | - | ||||||||||||||||||||||||||||||||||||
| 1037 | } | - | ||||||||||||||||||||||||||||||||||||
| 1038 | return; | - | ||||||||||||||||||||||||||||||||||||
| 1039 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1040 | - | |||||||||||||||||||||||||||||||||||||
| 1041 | case Qt::Key_U: never executed: case Qt::Key_U: | 0 | ||||||||||||||||||||||||||||||||||||
| 1042 | if (event->modifiers() & Qt::ControlModifier
| 0 | ||||||||||||||||||||||||||||||||||||
| 1043 | && QGuiApplication::platformName() == QLatin1String("xcb")) { // only X11
| 0 | ||||||||||||||||||||||||||||||||||||
| 1044 | event->accept(); | - | ||||||||||||||||||||||||||||||||||||
| 1045 | if (!isReadOnly())
| 0 | ||||||||||||||||||||||||||||||||||||
| 1046 | clear(); never executed: clear(); | 0 | ||||||||||||||||||||||||||||||||||||
| 1047 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1048 | } | - | ||||||||||||||||||||||||||||||||||||
| 1049 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 1050 | - | |||||||||||||||||||||||||||||||||||||
| 1051 | case Qt::Key_End: never executed: case Qt::Key_End: | 0 | ||||||||||||||||||||||||||||||||||||
| 1052 | case Qt::Key_Home: never executed: case Qt::Key_Home: | 0 | ||||||||||||||||||||||||||||||||||||
| 1053 | if (event->modifiers() & Qt::ShiftModifier) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1054 | int currentPos = d->edit->cursorPosition(); | - | ||||||||||||||||||||||||||||||||||||
| 1055 | const QString text = d->edit->displayText(); | - | ||||||||||||||||||||||||||||||||||||
| 1056 | if (event->key() == Qt::Key_End) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1057 | if ((currentPos == 0 && !d->prefix.isEmpty()) || text.size() - d->suffix.size() <= currentPos) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1058 | break; // let lineedit handle this never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 1059 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 1060 | d->edit->setSelection(currentPos, text.size() - d->suffix.size() - currentPos); | - | ||||||||||||||||||||||||||||||||||||
| 1061 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1062 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 1063 | if ((currentPos == text.size() && !d->suffix.isEmpty()) || currentPos <= d->prefix.size()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1064 | break; // let lineedit handle this never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 1065 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 1066 | d->edit->setSelection(currentPos, d->prefix.size() - currentPos); | - | ||||||||||||||||||||||||||||||||||||
| 1067 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1068 | } | - | ||||||||||||||||||||||||||||||||||||
| 1069 | event->accept(); | - | ||||||||||||||||||||||||||||||||||||
| 1070 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1071 | } | - | ||||||||||||||||||||||||||||||||||||
| 1072 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 1073 | - | |||||||||||||||||||||||||||||||||||||
| 1074 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||
| 1075 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||||||||
| 1076 | if (event == QKeySequence::SelectAll) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1077 | selectAll(); | - | ||||||||||||||||||||||||||||||||||||
| 1078 | event->accept(); | - | ||||||||||||||||||||||||||||||||||||
| 1079 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1080 | } | - | ||||||||||||||||||||||||||||||||||||
| 1081 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1082 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 1083 | } | - | ||||||||||||||||||||||||||||||||||||
| 1084 | - | |||||||||||||||||||||||||||||||||||||
| 1085 | d->edit->event(event); | - | ||||||||||||||||||||||||||||||||||||
| 1086 | if (!d->edit->text().isEmpty())
| 0 | ||||||||||||||||||||||||||||||||||||
| 1087 | d->cleared = false; never executed: d->cleared = false; | 0 | ||||||||||||||||||||||||||||||||||||
| 1088 | if (!isVisible())
| 0 | ||||||||||||||||||||||||||||||||||||
| 1089 | d->ignoreUpdateEdit = true; never executed: d->ignoreUpdateEdit = true; | 0 | ||||||||||||||||||||||||||||||||||||
| 1090 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1091 | - | |||||||||||||||||||||||||||||||||||||
| 1092 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1093 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 1094 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1095 | - | |||||||||||||||||||||||||||||||||||||
| 1096 | void QAbstractSpinBox::keyReleaseEvent(QKeyEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 1097 | { | - | ||||||||||||||||||||||||||||||||||||
| 1098 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1099 | - | |||||||||||||||||||||||||||||||||||||
| 1100 | if (d->buttonState & Keyboard && !event->isAutoRepeat()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1101 | d->reset(); | - | ||||||||||||||||||||||||||||||||||||
| 1102 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1103 | d->edit->event(event); | - | ||||||||||||||||||||||||||||||||||||
| 1104 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1105 | } | - | ||||||||||||||||||||||||||||||||||||
| 1106 | - | |||||||||||||||||||||||||||||||||||||
| 1107 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1108 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 1109 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1110 | - | |||||||||||||||||||||||||||||||||||||
| 1111 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||||||||||||||||||||
| 1112 | void QAbstractSpinBox::wheelEvent(QWheelEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 1113 | { | - | ||||||||||||||||||||||||||||||||||||
| 1114 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1115 | d->wheelDeltaRemainder += event->angleDelta().y(); | - | ||||||||||||||||||||||||||||||||||||
| 1116 | const int steps = d->wheelDeltaRemainder / 120; | - | ||||||||||||||||||||||||||||||||||||
| 1117 | d->wheelDeltaRemainder -= steps * 120; | - | ||||||||||||||||||||||||||||||||||||
| 1118 | if (stepEnabled() & (steps > 0 ? StepUpEnabled : StepDownEnabled))
| 0 | ||||||||||||||||||||||||||||||||||||
| 1119 | stepBy(event->modifiers() & Qt::ControlModifier ? steps * 10 : steps); never executed: stepBy(event->modifiers() & Qt::ControlModifier ? steps * 10 : steps); | 0 | ||||||||||||||||||||||||||||||||||||
| 1120 | event->accept(); | - | ||||||||||||||||||||||||||||||||||||
| 1121 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1122 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1123 | - | |||||||||||||||||||||||||||||||||||||
| 1124 | - | |||||||||||||||||||||||||||||||||||||
| 1125 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1126 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 1127 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1128 | void QAbstractSpinBox::focusInEvent(QFocusEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 1129 | { | - | ||||||||||||||||||||||||||||||||||||
| 1130 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1131 | - | |||||||||||||||||||||||||||||||||||||
| 1132 | d->edit->event(event); | - | ||||||||||||||||||||||||||||||||||||
| 1133 | if (event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1134 | selectAll(); | - | ||||||||||||||||||||||||||||||||||||
| 1135 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1136 | QWidget::focusInEvent(event); | - | ||||||||||||||||||||||||||||||||||||
| 1137 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1138 | - | |||||||||||||||||||||||||||||||||||||
| 1139 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1140 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 1141 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1142 | - | |||||||||||||||||||||||||||||||||||||
| 1143 | void QAbstractSpinBox::focusOutEvent(QFocusEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 1144 | { | - | ||||||||||||||||||||||||||||||||||||
| 1145 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1146 | - | |||||||||||||||||||||||||||||||||||||
| 1147 | if (d->pendingEmit)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1148 | d->interpret(EmitIfChanged); never executed: d->interpret(EmitIfChanged); | 0 | ||||||||||||||||||||||||||||||||||||
| 1149 | - | |||||||||||||||||||||||||||||||||||||
| 1150 | d->reset(); | - | ||||||||||||||||||||||||||||||||||||
| 1151 | d->edit->event(event); | - | ||||||||||||||||||||||||||||||||||||
| 1152 | d->updateEdit(); | - | ||||||||||||||||||||||||||||||||||||
| 1153 | QWidget::focusOutEvent(event); | - | ||||||||||||||||||||||||||||||||||||
| 1154 | - | |||||||||||||||||||||||||||||||||||||
| 1155 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
| 1156 | // editingFinished() is already emitted on LeaveEditFocus | - | ||||||||||||||||||||||||||||||||||||
| 1157 | if (!QApplication::keypadNavigationEnabled()) | - | ||||||||||||||||||||||||||||||||||||
| 1158 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1159 | emit editingFinished(); | - | ||||||||||||||||||||||||||||||||||||
| 1160 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1161 | - | |||||||||||||||||||||||||||||||||||||
| 1162 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1163 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 1164 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1165 | - | |||||||||||||||||||||||||||||||||||||
| 1166 | void QAbstractSpinBox::closeEvent(QCloseEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 1167 | { | - | ||||||||||||||||||||||||||||||||||||
| 1168 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1169 | - | |||||||||||||||||||||||||||||||||||||
| 1170 | d->reset(); | - | ||||||||||||||||||||||||||||||||||||
| 1171 | if (d->pendingEmit)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1172 | d->interpret(EmitIfChanged); never executed: d->interpret(EmitIfChanged); | 0 | ||||||||||||||||||||||||||||||||||||
| 1173 | QWidget::closeEvent(event); | - | ||||||||||||||||||||||||||||||||||||
| 1174 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1175 | - | |||||||||||||||||||||||||||||||||||||
| 1176 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1177 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 1178 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1179 | - | |||||||||||||||||||||||||||||||||||||
| 1180 | void QAbstractSpinBox::hideEvent(QHideEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 1181 | { | - | ||||||||||||||||||||||||||||||||||||
| 1182 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1183 | d->reset(); | - | ||||||||||||||||||||||||||||||||||||
| 1184 | if (d->pendingEmit)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1185 | d->interpret(EmitIfChanged); never executed: d->interpret(EmitIfChanged); | 0 | ||||||||||||||||||||||||||||||||||||
| 1186 | QWidget::hideEvent(event); | - | ||||||||||||||||||||||||||||||||||||
| 1187 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1188 | - | |||||||||||||||||||||||||||||||||||||
| 1189 | - | |||||||||||||||||||||||||||||||||||||
| 1190 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1191 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 1192 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1193 | - | |||||||||||||||||||||||||||||||||||||
| 1194 | void QAbstractSpinBox::timerEvent(QTimerEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 1195 | { | - | ||||||||||||||||||||||||||||||||||||
| 1196 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1197 | - | |||||||||||||||||||||||||||||||||||||
| 1198 | bool doStep = false; | - | ||||||||||||||||||||||||||||||||||||
| 1199 | if (event->timerId() == d->spinClickThresholdTimerId) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1200 | killTimer(d->spinClickThresholdTimerId); | - | ||||||||||||||||||||||||||||||||||||
| 1201 | d->spinClickThresholdTimerId = -1; | - | ||||||||||||||||||||||||||||||||||||
| 1202 | d->effectiveSpinRepeatRate = d->buttonState & Keyboard
| 0 | ||||||||||||||||||||||||||||||||||||
| 1203 | ? QGuiApplication::styleHints()->keyboardAutoRepeatRate() | - | ||||||||||||||||||||||||||||||||||||
| 1204 | : d->spinClickTimerInterval; | - | ||||||||||||||||||||||||||||||||||||
| 1205 | d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate); | - | ||||||||||||||||||||||||||||||||||||
| 1206 | doStep = true; | - | ||||||||||||||||||||||||||||||||||||
| 1207 | } else if (event->timerId() == d->spinClickTimerId) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
| 1208 | if (d->accelerate) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1209 | d->acceleration = d->acceleration + (int)(d->effectiveSpinRepeatRate * 0.05); | - | ||||||||||||||||||||||||||||||||||||
| 1210 | if (d->effectiveSpinRepeatRate - d->acceleration >= 10) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1211 | killTimer(d->spinClickTimerId); | - | ||||||||||||||||||||||||||||||||||||
| 1212 | d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate - d->acceleration); | - | ||||||||||||||||||||||||||||||||||||
| 1213 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1214 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1215 | doStep = true; | - | ||||||||||||||||||||||||||||||||||||
| 1216 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1217 | - | |||||||||||||||||||||||||||||||||||||
| 1218 | if (doStep) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1219 | const StepEnabled st = stepEnabled(); | - | ||||||||||||||||||||||||||||||||||||
| 1220 | if (d->buttonState & Up) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1221 | if (!(st & StepUpEnabled)) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1222 | d->reset(); | - | ||||||||||||||||||||||||||||||||||||
| 1223 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1224 | stepBy(1); | - | ||||||||||||||||||||||||||||||||||||
| 1225 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1226 | } else if (d->buttonState & Down) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1227 | if (!(st & StepDownEnabled)) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1228 | d->reset(); | - | ||||||||||||||||||||||||||||||||||||
| 1229 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1230 | stepBy(-1); | - | ||||||||||||||||||||||||||||||||||||
| 1231 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1232 | } | - | ||||||||||||||||||||||||||||||||||||
| 1233 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1234 | } | - | ||||||||||||||||||||||||||||||||||||
| 1235 | QWidget::timerEvent(event); | - | ||||||||||||||||||||||||||||||||||||
| 1236 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1237 | } | - | ||||||||||||||||||||||||||||||||||||
| 1238 | - | |||||||||||||||||||||||||||||||||||||
| 1239 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1240 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 1241 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1242 | - | |||||||||||||||||||||||||||||||||||||
| 1243 | void QAbstractSpinBox::contextMenuEvent(QContextMenuEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 1244 | { | - | ||||||||||||||||||||||||||||||||||||
| 1245 | #ifdef QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||||||||||||||
| 1246 | Q_UNUSED(event); | - | ||||||||||||||||||||||||||||||||||||
| 1247 | #else | - | ||||||||||||||||||||||||||||||||||||
| 1248 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1249 | - | |||||||||||||||||||||||||||||||||||||
| 1250 | QPointer<QMenu> menu = d->edit->createStandardContextMenu(); | - | ||||||||||||||||||||||||||||||||||||
| 1251 | if (!menu)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1252 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1253 | - | |||||||||||||||||||||||||||||||||||||
| 1254 | d->reset(); | - | ||||||||||||||||||||||||||||||||||||
| 1255 | - | |||||||||||||||||||||||||||||||||||||
| 1256 | QAction *selAll = new QAction(tr("&Select All"), menu); | - | ||||||||||||||||||||||||||||||||||||
| 1257 | menu->insertAction(d->edit->d_func()->selectAllAction, | - | ||||||||||||||||||||||||||||||||||||
| 1258 | selAll); | - | ||||||||||||||||||||||||||||||||||||
| 1259 | menu->removeAction(d->edit->d_func()->selectAllAction); | - | ||||||||||||||||||||||||||||||||||||
| 1260 | menu->addSeparator(); | - | ||||||||||||||||||||||||||||||||||||
| 1261 | const uint se = stepEnabled(); | - | ||||||||||||||||||||||||||||||||||||
| 1262 | QAction *up = menu->addAction(tr("&Step up")); | - | ||||||||||||||||||||||||||||||||||||
| 1263 | up->setEnabled(se & StepUpEnabled); | - | ||||||||||||||||||||||||||||||||||||
| 1264 | QAction *down = menu->addAction(tr("Step &down")); | - | ||||||||||||||||||||||||||||||||||||
| 1265 | down->setEnabled(se & StepDownEnabled); | - | ||||||||||||||||||||||||||||||||||||
| 1266 | menu->addSeparator(); | - | ||||||||||||||||||||||||||||||||||||
| 1267 | - | |||||||||||||||||||||||||||||||||||||
| 1268 | const QPointer<QAbstractSpinBox> that = this; | - | ||||||||||||||||||||||||||||||||||||
| 1269 | const QPoint pos = (event->reason() == QContextMenuEvent::Mouse)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1270 | ? event->globalPos() : mapToGlobal(QPoint(event->pos().x(), 0)) + QPoint(width() / 2, height() / 2); | - | ||||||||||||||||||||||||||||||||||||
| 1271 | const QAction *action = menu->exec(pos); | - | ||||||||||||||||||||||||||||||||||||
| 1272 | delete static_cast<QMenu *>(menu); | - | ||||||||||||||||||||||||||||||||||||
| 1273 | if (that && action) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1274 | if (action == up) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1275 | stepBy(1); | - | ||||||||||||||||||||||||||||||||||||
| 1276 | } else if (action == down) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
| 1277 | stepBy(-1); | - | ||||||||||||||||||||||||||||||||||||
| 1278 | } else if (action == selAll) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
| 1279 | selectAll(); | - | ||||||||||||||||||||||||||||||||||||
| 1280 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1281 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1282 | event->accept(); | - | ||||||||||||||||||||||||||||||||||||
| 1283 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||||||||||||||
| 1284 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1285 | - | |||||||||||||||||||||||||||||||||||||
| 1286 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1287 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 1288 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1289 | - | |||||||||||||||||||||||||||||||||||||
| 1290 | void QAbstractSpinBox::mouseMoveEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 1291 | { | - | ||||||||||||||||||||||||||||||||||||
| 1292 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1293 | - | |||||||||||||||||||||||||||||||||||||
| 1294 | d->updateHoverControl(event->pos()); | - | ||||||||||||||||||||||||||||||||||||
| 1295 | - | |||||||||||||||||||||||||||||||||||||
| 1296 | // If we have a timer ID, update the state | - | ||||||||||||||||||||||||||||||||||||
| 1297 | if (d->spinClickTimerId != -1 && d->buttonSymbols != NoButtons) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1298 | const StepEnabled se = stepEnabled(); | - | ||||||||||||||||||||||||||||||||||||
| 1299 | if ((se & StepUpEnabled) && d->hoverControl == QStyle::SC_SpinBoxUp)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1300 | d->updateState(true); never executed: d->updateState(true); | 0 | ||||||||||||||||||||||||||||||||||||
| 1301 | else if ((se & StepDownEnabled) && d->hoverControl == QStyle::SC_SpinBoxDown)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1302 | d->updateState(false); never executed: d->updateState(false); | 0 | ||||||||||||||||||||||||||||||||||||
| 1303 | else | - | ||||||||||||||||||||||||||||||||||||
| 1304 | d->reset(); never executed: d->reset(); | 0 | ||||||||||||||||||||||||||||||||||||
| 1305 | event->accept(); | - | ||||||||||||||||||||||||||||||||||||
| 1306 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1307 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1308 | - | |||||||||||||||||||||||||||||||||||||
| 1309 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1310 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 1311 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1312 | - | |||||||||||||||||||||||||||||||||||||
| 1313 | void QAbstractSpinBox::mousePressEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 1314 | { | - | ||||||||||||||||||||||||||||||||||||
| 1315 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1316 | - | |||||||||||||||||||||||||||||||||||||
| 1317 | if (event->button() != Qt::LeftButton || d->buttonState != None) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1318 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1319 | } | - | ||||||||||||||||||||||||||||||||||||
| 1320 | - | |||||||||||||||||||||||||||||||||||||
| 1321 | d->updateHoverControl(event->pos()); | - | ||||||||||||||||||||||||||||||||||||
| 1322 | event->accept(); | - | ||||||||||||||||||||||||||||||||||||
| 1323 | - | |||||||||||||||||||||||||||||||||||||
| 1324 | const StepEnabled se = (d->buttonSymbols == NoButtons) ? StepEnabled(StepNone) : stepEnabled();
| 0 | ||||||||||||||||||||||||||||||||||||
| 1325 | if ((se & StepUpEnabled) && d->hoverControl == QStyle::SC_SpinBoxUp) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1326 | d->updateState(true); | - | ||||||||||||||||||||||||||||||||||||
| 1327 | } else if ((se & StepDownEnabled) && d->hoverControl == QStyle::SC_SpinBoxDown) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
| 1328 | d->updateState(false); | - | ||||||||||||||||||||||||||||||||||||
| 1329 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1330 | event->ignore(); | - | ||||||||||||||||||||||||||||||||||||
| 1331 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1332 | } | - | ||||||||||||||||||||||||||||||||||||
| 1333 | - | |||||||||||||||||||||||||||||||||||||
| 1334 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1335 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 1336 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1337 | void QAbstractSpinBox::mouseReleaseEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 1338 | { | - | ||||||||||||||||||||||||||||||||||||
| 1339 | Q_D(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1340 | - | |||||||||||||||||||||||||||||||||||||
| 1341 | if ((d->buttonState & Mouse) != 0)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1342 | d->reset(); never executed: d->reset(); | 0 | ||||||||||||||||||||||||||||||||||||
| 1343 | event->accept(); | - | ||||||||||||||||||||||||||||||||||||
| 1344 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1345 | - | |||||||||||||||||||||||||||||||||||||
| 1346 | // --- QAbstractSpinBoxPrivate --- | - | ||||||||||||||||||||||||||||||||||||
| 1347 | - | |||||||||||||||||||||||||||||||||||||
| 1348 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1349 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1350 | Constructs a QAbstractSpinBoxPrivate object | - | ||||||||||||||||||||||||||||||||||||
| 1351 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1352 | - | |||||||||||||||||||||||||||||||||||||
| 1353 | QAbstractSpinBoxPrivate::QAbstractSpinBoxPrivate() | - | ||||||||||||||||||||||||||||||||||||
| 1354 | : edit(0), type(QVariant::Invalid), spinClickTimerId(-1), | - | ||||||||||||||||||||||||||||||||||||
| 1355 | spinClickTimerInterval(100), spinClickThresholdTimerId(-1), spinClickThresholdTimerInterval(-1), | - | ||||||||||||||||||||||||||||||||||||
| 1356 | effectiveSpinRepeatRate(1), buttonState(None), cachedText(QLatin1String("\x01")), | - | ||||||||||||||||||||||||||||||||||||
| 1357 | cachedState(QValidator::Invalid), pendingEmit(false), readOnly(false), wrapping(false), | - | ||||||||||||||||||||||||||||||||||||
| 1358 | ignoreCursorPositionChanged(false), frame(true), accelerate(false), keyboardTracking(true), | - | ||||||||||||||||||||||||||||||||||||
| 1359 | cleared(false), ignoreUpdateEdit(false), correctionMode(QAbstractSpinBox::CorrectToPreviousValue), | - | ||||||||||||||||||||||||||||||||||||
| 1360 | acceleration(0), hoverControl(QStyle::SC_None), buttonSymbols(QAbstractSpinBox::UpDownArrows), validator(0), | - | ||||||||||||||||||||||||||||||||||||
| 1361 | showGroupSeparator(0), wheelDeltaRemainder(0) | - | ||||||||||||||||||||||||||||||||||||
| 1362 | { | - | ||||||||||||||||||||||||||||||||||||
| 1363 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1364 | - | |||||||||||||||||||||||||||||||||||||
| 1365 | /* | - | ||||||||||||||||||||||||||||||||||||
| 1366 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1367 | Called when the QAbstractSpinBoxPrivate is destroyed | - | ||||||||||||||||||||||||||||||||||||
| 1368 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1369 | QAbstractSpinBoxPrivate::~QAbstractSpinBoxPrivate() | - | ||||||||||||||||||||||||||||||||||||
| 1370 | { | - | ||||||||||||||||||||||||||||||||||||
| 1371 | } | - | ||||||||||||||||||||||||||||||||||||
| 1372 | - | |||||||||||||||||||||||||||||||||||||
| 1373 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1374 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1375 | Updates the old and new hover control. Does nothing if the hover | - | ||||||||||||||||||||||||||||||||||||
| 1376 | control has not changed. | - | ||||||||||||||||||||||||||||||||||||
| 1377 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1378 | bool QAbstractSpinBoxPrivate::updateHoverControl(const QPoint &pos) | - | ||||||||||||||||||||||||||||||||||||
| 1379 | { | - | ||||||||||||||||||||||||||||||||||||
| 1380 | Q_Q(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1381 | QRect lastHoverRect = hoverRect; | - | ||||||||||||||||||||||||||||||||||||
| 1382 | QStyle::SubControl lastHoverControl = hoverControl; | - | ||||||||||||||||||||||||||||||||||||
| 1383 | bool doesHover = q->testAttribute(Qt::WA_Hover); | - | ||||||||||||||||||||||||||||||||||||
| 1384 | if (lastHoverControl != newHoverControl(pos) && doesHover) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1385 | q->update(lastHoverRect); | - | ||||||||||||||||||||||||||||||||||||
| 1386 | q->update(hoverRect); | - | ||||||||||||||||||||||||||||||||||||
| 1387 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||||||||
| 1388 | } | - | ||||||||||||||||||||||||||||||||||||
| 1389 | return !doesHover; never executed: return !doesHover; | 0 | ||||||||||||||||||||||||||||||||||||
| 1390 | } | - | ||||||||||||||||||||||||||||||||||||
| 1391 | - | |||||||||||||||||||||||||||||||||||||
| 1392 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1393 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1394 | Returns the hover control at \a pos. | - | ||||||||||||||||||||||||||||||||||||
| 1395 | This will update the hoverRect and hoverControl. | - | ||||||||||||||||||||||||||||||||||||
| 1396 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1397 | QStyle::SubControl QAbstractSpinBoxPrivate::newHoverControl(const QPoint &pos) | - | ||||||||||||||||||||||||||||||||||||
| 1398 | { | - | ||||||||||||||||||||||||||||||||||||
| 1399 | Q_Q(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1400 | - | |||||||||||||||||||||||||||||||||||||
| 1401 | QStyleOptionSpinBox opt; | - | ||||||||||||||||||||||||||||||||||||
| 1402 | q->initStyleOption(&opt); | - | ||||||||||||||||||||||||||||||||||||
| 1403 | opt.subControls = QStyle::SC_All; | - | ||||||||||||||||||||||||||||||||||||
| 1404 | hoverControl = q->style()->hitTestComplexControl(QStyle::CC_SpinBox, &opt, pos, q); | - | ||||||||||||||||||||||||||||||||||||
| 1405 | hoverRect = q->style()->subControlRect(QStyle::CC_SpinBox, &opt, hoverControl, q); | - | ||||||||||||||||||||||||||||||||||||
| 1406 | return hoverControl; never executed: return hoverControl; | 0 | ||||||||||||||||||||||||||||||||||||
| 1407 | } | - | ||||||||||||||||||||||||||||||||||||
| 1408 | - | |||||||||||||||||||||||||||||||||||||
| 1409 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1410 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1411 | Strips any prefix/suffix from \a text. | - | ||||||||||||||||||||||||||||||||||||
| 1412 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1413 | - | |||||||||||||||||||||||||||||||||||||
| 1414 | QString QAbstractSpinBoxPrivate::stripped(const QString &t, int *pos) const | - | ||||||||||||||||||||||||||||||||||||
| 1415 | { | - | ||||||||||||||||||||||||||||||||||||
| 1416 | QString text = t; | - | ||||||||||||||||||||||||||||||||||||
| 1417 | if (specialValueText.size() == 0 || text != specialValueText) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1418 | int from = 0; | - | ||||||||||||||||||||||||||||||||||||
| 1419 | int size = text.size(); | - | ||||||||||||||||||||||||||||||||||||
| 1420 | bool changed = false; | - | ||||||||||||||||||||||||||||||||||||
| 1421 | if (prefix.size() && text.startsWith(prefix)) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1422 | from += prefix.size(); | - | ||||||||||||||||||||||||||||||||||||
| 1423 | size -= from; | - | ||||||||||||||||||||||||||||||||||||
| 1424 | changed = true; | - | ||||||||||||||||||||||||||||||||||||
| 1425 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1426 | if (suffix.size() && text.endsWith(suffix)) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1427 | size -= suffix.size(); | - | ||||||||||||||||||||||||||||||||||||
| 1428 | changed = true; | - | ||||||||||||||||||||||||||||||||||||
| 1429 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1430 | if (changed)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1431 | text = text.mid(from, size); never executed: text = text.mid(from, size); | 0 | ||||||||||||||||||||||||||||||||||||
| 1432 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1433 | - | |||||||||||||||||||||||||||||||||||||
| 1434 | const int s = text.size(); | - | ||||||||||||||||||||||||||||||||||||
| 1435 | text = text.trimmed(); | - | ||||||||||||||||||||||||||||||||||||
| 1436 | if (pos)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1437 | (*pos) -= (s - text.size()); never executed: (*pos) -= (s - text.size()); | 0 | ||||||||||||||||||||||||||||||||||||
| 1438 | return text; never executed: return text; | 0 | ||||||||||||||||||||||||||||||||||||
| 1439 | - | |||||||||||||||||||||||||||||||||||||
| 1440 | } | - | ||||||||||||||||||||||||||||||||||||
| 1441 | - | |||||||||||||||||||||||||||||||||||||
| 1442 | void QAbstractSpinBoxPrivate::updateEditFieldGeometry() | - | ||||||||||||||||||||||||||||||||||||
| 1443 | { | - | ||||||||||||||||||||||||||||||||||||
| 1444 | Q_Q(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1445 | QStyleOptionSpinBox opt; | - | ||||||||||||||||||||||||||||||||||||
| 1446 | q->initStyleOption(&opt); | - | ||||||||||||||||||||||||||||||||||||
| 1447 | opt.subControls = QStyle::SC_SpinBoxEditField; | - | ||||||||||||||||||||||||||||||||||||
| 1448 | edit->setGeometry(q->style()->subControlRect(QStyle::CC_SpinBox, &opt, | - | ||||||||||||||||||||||||||||||||||||
| 1449 | QStyle::SC_SpinBoxEditField, q)); | - | ||||||||||||||||||||||||||||||||||||
| 1450 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1451 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1452 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1453 | Returns \c true if a specialValueText has been set and the current value is minimum. | - | ||||||||||||||||||||||||||||||||||||
| 1454 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1455 | - | |||||||||||||||||||||||||||||||||||||
| 1456 | bool QAbstractSpinBoxPrivate::specialValue() const | - | ||||||||||||||||||||||||||||||||||||
| 1457 | { | - | ||||||||||||||||||||||||||||||||||||
| 1458 | return (value == minimum && !specialValueText.isEmpty()); never executed: return (value == minimum && !specialValueText.isEmpty());
| 0 | ||||||||||||||||||||||||||||||||||||
| 1459 | } | - | ||||||||||||||||||||||||||||||||||||
| 1460 | - | |||||||||||||||||||||||||||||||||||||
| 1461 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1462 | \internal Virtual function that emits signals when the value | - | ||||||||||||||||||||||||||||||||||||
| 1463 | changes. Reimplemented in the different subclasses. | - | ||||||||||||||||||||||||||||||||||||
| 1464 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1465 | - | |||||||||||||||||||||||||||||||||||||
| 1466 | void QAbstractSpinBoxPrivate::emitSignals(EmitPolicy, const QVariant &) | - | ||||||||||||||||||||||||||||||||||||
| 1467 | { | - | ||||||||||||||||||||||||||||||||||||
| 1468 | } | - | ||||||||||||||||||||||||||||||||||||
| 1469 | - | |||||||||||||||||||||||||||||||||||||
| 1470 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1471 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1472 | - | |||||||||||||||||||||||||||||||||||||
| 1473 | Slot connected to the line edit's textChanged(const QString &) | - | ||||||||||||||||||||||||||||||||||||
| 1474 | signal. | - | ||||||||||||||||||||||||||||||||||||
| 1475 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1476 | - | |||||||||||||||||||||||||||||||||||||
| 1477 | void QAbstractSpinBoxPrivate::_q_editorTextChanged(const QString &t) | - | ||||||||||||||||||||||||||||||||||||
| 1478 | { | - | ||||||||||||||||||||||||||||||||||||
| 1479 | Q_Q(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1480 | - | |||||||||||||||||||||||||||||||||||||
| 1481 | if (keyboardTracking) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1482 | QString tmp = t; | - | ||||||||||||||||||||||||||||||||||||
| 1483 | int pos = edit->cursorPosition(); | - | ||||||||||||||||||||||||||||||||||||
| 1484 | QValidator::State state = q->validate(tmp, pos); | - | ||||||||||||||||||||||||||||||||||||
| 1485 | if (state == QValidator::Acceptable) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1486 | const QVariant v = valueFromText(tmp); | - | ||||||||||||||||||||||||||||||||||||
| 1487 | setValue(v, EmitIfChanged, tmp != t); | - | ||||||||||||||||||||||||||||||||||||
| 1488 | pendingEmit = false; | - | ||||||||||||||||||||||||||||||||||||
| 1489 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1490 | pendingEmit = true; | - | ||||||||||||||||||||||||||||||||||||
| 1491 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1492 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 1493 | pendingEmit = true; | - | ||||||||||||||||||||||||||||||||||||
| 1494 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1495 | } | - | ||||||||||||||||||||||||||||||||||||
| 1496 | - | |||||||||||||||||||||||||||||||||||||
| 1497 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1498 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1499 | - | |||||||||||||||||||||||||||||||||||||
| 1500 | Virtual slot connected to the line edit's | - | ||||||||||||||||||||||||||||||||||||
| 1501 | cursorPositionChanged(int, int) signal. Will move the cursor to a | - | ||||||||||||||||||||||||||||||||||||
| 1502 | valid position if the new one is invalid. E.g. inside the prefix. | - | ||||||||||||||||||||||||||||||||||||
| 1503 | Reimplemented in Q[Date|Time|DateTime]EditPrivate to account for | - | ||||||||||||||||||||||||||||||||||||
| 1504 | the different sections etc. | - | ||||||||||||||||||||||||||||||||||||
| 1505 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1506 | - | |||||||||||||||||||||||||||||||||||||
| 1507 | void QAbstractSpinBoxPrivate::_q_editorCursorPositionChanged(int oldpos, int newpos) | - | ||||||||||||||||||||||||||||||||||||
| 1508 | { | - | ||||||||||||||||||||||||||||||||||||
| 1509 | if (!edit->hasSelectedText() && !ignoreCursorPositionChanged && !specialValue()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1510 | ignoreCursorPositionChanged = true; | - | ||||||||||||||||||||||||||||||||||||
| 1511 | - | |||||||||||||||||||||||||||||||||||||
| 1512 | bool allowSelection = true; | - | ||||||||||||||||||||||||||||||||||||
| 1513 | int pos = -1; | - | ||||||||||||||||||||||||||||||||||||
| 1514 | if (newpos < prefix.size() && newpos != 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1515 | if (oldpos == 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1516 | allowSelection = false; | - | ||||||||||||||||||||||||||||||||||||
| 1517 | pos = prefix.size(); | - | ||||||||||||||||||||||||||||||||||||
| 1518 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1519 | pos = oldpos; | - | ||||||||||||||||||||||||||||||||||||
| 1520 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1521 | } else if (newpos > edit->text().size() - suffix.size()
| 0 | ||||||||||||||||||||||||||||||||||||
| 1522 | && newpos != edit->text().size()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1523 | if (oldpos == edit->text().size()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1524 | pos = edit->text().size() - suffix.size(); | - | ||||||||||||||||||||||||||||||||||||
| 1525 | allowSelection = false; | - | ||||||||||||||||||||||||||||||||||||
| 1526 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1527 | pos = edit->text().size(); | - | ||||||||||||||||||||||||||||||||||||
| 1528 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1529 | } | - | ||||||||||||||||||||||||||||||||||||
| 1530 | if (pos != -1) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1531 | const int selSize = edit->selectionStart() >= 0 && allowSelection
| 0 | ||||||||||||||||||||||||||||||||||||
| 1532 | ? (edit->selectedText().size() | - | ||||||||||||||||||||||||||||||||||||
| 1533 | * (newpos < pos ? -1 : 1)) - newpos + pos | - | ||||||||||||||||||||||||||||||||||||
| 1534 | : 0; | - | ||||||||||||||||||||||||||||||||||||
| 1535 | - | |||||||||||||||||||||||||||||||||||||
| 1536 | const QSignalBlocker blocker(edit); | - | ||||||||||||||||||||||||||||||||||||
| 1537 | if (selSize != 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1538 | edit->setSelection(pos - selSize, selSize); | - | ||||||||||||||||||||||||||||||||||||
| 1539 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1540 | edit->setCursorPosition(pos); | - | ||||||||||||||||||||||||||||||||||||
| 1541 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1542 | } | - | ||||||||||||||||||||||||||||||||||||
| 1543 | ignoreCursorPositionChanged = false; | - | ||||||||||||||||||||||||||||||||||||
| 1544 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1545 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1546 | - | |||||||||||||||||||||||||||||||||||||
| 1547 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1548 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1549 | - | |||||||||||||||||||||||||||||||||||||
| 1550 | Initialises the QAbstractSpinBoxPrivate object. | - | ||||||||||||||||||||||||||||||||||||
| 1551 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1552 | - | |||||||||||||||||||||||||||||||||||||
| 1553 | void QAbstractSpinBoxPrivate::init() | - | ||||||||||||||||||||||||||||||||||||
| 1554 | { | - | ||||||||||||||||||||||||||||||||||||
| 1555 | Q_Q(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1556 | - | |||||||||||||||||||||||||||||||||||||
| 1557 | q->setLineEdit(new QLineEdit(q)); | - | ||||||||||||||||||||||||||||||||||||
| 1558 | edit->setObjectName(QLatin1String("qt_spinbox_lineedit")); | - | ||||||||||||||||||||||||||||||||||||
| 1559 | validator = new QSpinBoxValidator(q, this); | - | ||||||||||||||||||||||||||||||||||||
| 1560 | edit->setValidator(validator); | - | ||||||||||||||||||||||||||||||||||||
| 1561 | - | |||||||||||||||||||||||||||||||||||||
| 1562 | QStyleOptionSpinBox opt; | - | ||||||||||||||||||||||||||||||||||||
| 1563 | q->initStyleOption(&opt); | - | ||||||||||||||||||||||||||||||||||||
| 1564 | spinClickTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, &opt, q); | - | ||||||||||||||||||||||||||||||||||||
| 1565 | spinClickThresholdTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatThreshold, &opt, q); | - | ||||||||||||||||||||||||||||||||||||
| 1566 | q->setFocusPolicy(Qt::WheelFocus); | - | ||||||||||||||||||||||||||||||||||||
| 1567 | q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, QSizePolicy::SpinBox)); | - | ||||||||||||||||||||||||||||||||||||
| 1568 | q->setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||||||||||||||||||||
| 1569 | - | |||||||||||||||||||||||||||||||||||||
| 1570 | q->setAttribute(Qt::WA_MacShowFocusRect); | - | ||||||||||||||||||||||||||||||||||||
| 1571 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1572 | - | |||||||||||||||||||||||||||||||||||||
| 1573 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1574 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1575 | - | |||||||||||||||||||||||||||||||||||||
| 1576 | Resets the state of the spinbox. E.g. the state is set to | - | ||||||||||||||||||||||||||||||||||||
| 1577 | (Keyboard|Up) if Key up is currently pressed. | - | ||||||||||||||||||||||||||||||||||||
| 1578 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1579 | - | |||||||||||||||||||||||||||||||||||||
| 1580 | void QAbstractSpinBoxPrivate::reset() | - | ||||||||||||||||||||||||||||||||||||
| 1581 | { | - | ||||||||||||||||||||||||||||||||||||
| 1582 | Q_Q(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1583 | - | |||||||||||||||||||||||||||||||||||||
| 1584 | buttonState = None; | - | ||||||||||||||||||||||||||||||||||||
| 1585 | if (q) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1586 | if (spinClickTimerId != -1)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1587 | q->killTimer(spinClickTimerId); never executed: q->killTimer(spinClickTimerId); | 0 | ||||||||||||||||||||||||||||||||||||
| 1588 | if (spinClickThresholdTimerId != -1)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1589 | q->killTimer(spinClickThresholdTimerId); never executed: q->killTimer(spinClickThresholdTimerId); | 0 | ||||||||||||||||||||||||||||||||||||
| 1590 | spinClickTimerId = spinClickThresholdTimerId = -1; | - | ||||||||||||||||||||||||||||||||||||
| 1591 | acceleration = 0; | - | ||||||||||||||||||||||||||||||||||||
| 1592 | q->update(); | - | ||||||||||||||||||||||||||||||||||||
| 1593 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1594 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1595 | - | |||||||||||||||||||||||||||||||||||||
| 1596 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1597 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1598 | - | |||||||||||||||||||||||||||||||||||||
| 1599 | Updates the state of the spinbox. | - | ||||||||||||||||||||||||||||||||||||
| 1600 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1601 | - | |||||||||||||||||||||||||||||||||||||
| 1602 | void QAbstractSpinBoxPrivate::updateState(bool up, bool fromKeyboard /* = false */) | - | ||||||||||||||||||||||||||||||||||||
| 1603 | { | - | ||||||||||||||||||||||||||||||||||||
| 1604 | Q_Q(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1605 | if ((up && (buttonState & Up)) || (!up && (buttonState & Down)))
| 0 | ||||||||||||||||||||||||||||||||||||
| 1606 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1607 | reset(); | - | ||||||||||||||||||||||||||||||||||||
| 1608 | if (q && (q->stepEnabled() & (up ? QAbstractSpinBox::StepUpEnabled
| 0 | ||||||||||||||||||||||||||||||||||||
| 1609 | : QAbstractSpinBox::StepDownEnabled))) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1610 | spinClickThresholdTimerId = q->startTimer(spinClickThresholdTimerInterval); | - | ||||||||||||||||||||||||||||||||||||
| 1611 | buttonState = (up ? Up : Down) | (fromKeyboard ? Keyboard : Mouse);
| 0 | ||||||||||||||||||||||||||||||||||||
| 1612 | q->stepBy(up ? 1 : -1); | - | ||||||||||||||||||||||||||||||||||||
| 1613 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||||||||
| 1614 | QAccessibleValueChangeEvent event(q, value); | - | ||||||||||||||||||||||||||||||||||||
| 1615 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||||||||||||||||||||
| 1616 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1617 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1618 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1619 | - | |||||||||||||||||||||||||||||||||||||
| 1620 | - | |||||||||||||||||||||||||||||||||||||
| 1621 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1622 | Initialize \a option with the values from this QSpinBox. This method | - | ||||||||||||||||||||||||||||||||||||
| 1623 | is useful for subclasses when they need a QStyleOptionSpinBox, but don't want | - | ||||||||||||||||||||||||||||||||||||
| 1624 | to fill in all the information themselves. | - | ||||||||||||||||||||||||||||||||||||
| 1625 | - | |||||||||||||||||||||||||||||||||||||
| 1626 | \sa QStyleOption::initFrom() | - | ||||||||||||||||||||||||||||||||||||
| 1627 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1628 | void QAbstractSpinBox::initStyleOption(QStyleOptionSpinBox *option) const | - | ||||||||||||||||||||||||||||||||||||
| 1629 | { | - | ||||||||||||||||||||||||||||||||||||
| 1630 | if (!option)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1631 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1632 | - | |||||||||||||||||||||||||||||||||||||
| 1633 | Q_D(const QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1634 | option->initFrom(this); | - | ||||||||||||||||||||||||||||||||||||
| 1635 | option->activeSubControls = QStyle::SC_None; | - | ||||||||||||||||||||||||||||||||||||
| 1636 | option->buttonSymbols = d->buttonSymbols; | - | ||||||||||||||||||||||||||||||||||||
| 1637 | option->subControls = QStyle::SC_SpinBoxFrame | QStyle::SC_SpinBoxEditField; | - | ||||||||||||||||||||||||||||||||||||
| 1638 | if (d->buttonSymbols != QAbstractSpinBox::NoButtons) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1639 | option->subControls |= QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown; | - | ||||||||||||||||||||||||||||||||||||
| 1640 | if (d->buttonState & Up) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1641 | option->activeSubControls = QStyle::SC_SpinBoxUp; | - | ||||||||||||||||||||||||||||||||||||
| 1642 | } else if (d->buttonState & Down) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
| 1643 | option->activeSubControls = QStyle::SC_SpinBoxDown; | - | ||||||||||||||||||||||||||||||||||||
| 1644 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1645 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1646 | - | |||||||||||||||||||||||||||||||||||||
| 1647 | if (d->buttonState) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1648 | option->state |= QStyle::State_Sunken; | - | ||||||||||||||||||||||||||||||||||||
| 1649 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1650 | option->activeSubControls = d->hoverControl; | - | ||||||||||||||||||||||||||||||||||||
| 1651 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1652 | - | |||||||||||||||||||||||||||||||||||||
| 1653 | option->stepEnabled = style()->styleHint(QStyle::SH_SpinControls_DisableOnBounds)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1654 | ? stepEnabled() | - | ||||||||||||||||||||||||||||||||||||
| 1655 | : (QAbstractSpinBox::StepDownEnabled|QAbstractSpinBox::StepUpEnabled); | - | ||||||||||||||||||||||||||||||||||||
| 1656 | - | |||||||||||||||||||||||||||||||||||||
| 1657 | option->frame = d->frame; | - | ||||||||||||||||||||||||||||||||||||
| 1658 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1659 | - | |||||||||||||||||||||||||||||||||||||
| 1660 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1661 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1662 | - | |||||||||||||||||||||||||||||||||||||
| 1663 | Bounds \a val to be within minimum and maximum. Also tries to be | - | ||||||||||||||||||||||||||||||||||||
| 1664 | clever about setting it at min and max depending on what it was | - | ||||||||||||||||||||||||||||||||||||
| 1665 | and what direction it was changed etc. | - | ||||||||||||||||||||||||||||||||||||
| 1666 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1667 | - | |||||||||||||||||||||||||||||||||||||
| 1668 | QVariant QAbstractSpinBoxPrivate::bound(const QVariant &val, const QVariant &old, int steps) const | - | ||||||||||||||||||||||||||||||||||||
| 1669 | { | - | ||||||||||||||||||||||||||||||||||||
| 1670 | QVariant v = val; | - | ||||||||||||||||||||||||||||||||||||
| 1671 | if (!wrapping || steps == 0 || old.isNull()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1672 | if (variantCompare(v, minimum) < 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1673 | v = wrapping ? maximum : minimum;
| 0 | ||||||||||||||||||||||||||||||||||||
| 1674 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1675 | if (variantCompare(v, maximum) > 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1676 | v = wrapping ? minimum : maximum;
| 0 | ||||||||||||||||||||||||||||||||||||
| 1677 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1678 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1679 | const bool wasMin = old == minimum; | - | ||||||||||||||||||||||||||||||||||||
| 1680 | const bool wasMax = old == maximum; | - | ||||||||||||||||||||||||||||||||||||
| 1681 | const int oldcmp = variantCompare(v, old); | - | ||||||||||||||||||||||||||||||||||||
| 1682 | const int maxcmp = variantCompare(v, maximum); | - | ||||||||||||||||||||||||||||||||||||
| 1683 | const int mincmp = variantCompare(v, minimum); | - | ||||||||||||||||||||||||||||||||||||
| 1684 | const bool wrapped = (oldcmp > 0 && steps < 0) || (oldcmp < 0 && steps > 0);
| 0 | ||||||||||||||||||||||||||||||||||||
| 1685 | if (maxcmp > 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1686 | v = ((wasMax && !wrapped && steps > 0) || (steps < 0 && !wasMin && wrapped))
| 0 | ||||||||||||||||||||||||||||||||||||
| 1687 | ? minimum : maximum; | - | ||||||||||||||||||||||||||||||||||||
| 1688 | } else if (wrapped && (maxcmp > 0 || mincmp < 0)) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
| 1689 | v = ((wasMax && steps > 0) || (!wasMin && steps < 0)) ? minimum : maximum;
| 0 | ||||||||||||||||||||||||||||||||||||
| 1690 | } else if (mincmp < 0) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
| 1691 | v = (!wasMax && !wasMin ? minimum : maximum);
| 0 | ||||||||||||||||||||||||||||||||||||
| 1692 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1693 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1694 | - | |||||||||||||||||||||||||||||||||||||
| 1695 | return v; never executed: return v; | 0 | ||||||||||||||||||||||||||||||||||||
| 1696 | } | - | ||||||||||||||||||||||||||||||||||||
| 1697 | - | |||||||||||||||||||||||||||||||||||||
| 1698 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1699 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1700 | - | |||||||||||||||||||||||||||||||||||||
| 1701 | Sets the value of the spin box to \a val. Depending on the value | - | ||||||||||||||||||||||||||||||||||||
| 1702 | of \a ep it will also emit signals. | - | ||||||||||||||||||||||||||||||||||||
| 1703 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1704 | - | |||||||||||||||||||||||||||||||||||||
| 1705 | void QAbstractSpinBoxPrivate::setValue(const QVariant &val, EmitPolicy ep, | - | ||||||||||||||||||||||||||||||||||||
| 1706 | bool doUpdate) | - | ||||||||||||||||||||||||||||||||||||
| 1707 | { | - | ||||||||||||||||||||||||||||||||||||
| 1708 | Q_Q(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1709 | const QVariant old = value; | - | ||||||||||||||||||||||||||||||||||||
| 1710 | value = bound(val); | - | ||||||||||||||||||||||||||||||||||||
| 1711 | pendingEmit = false; | - | ||||||||||||||||||||||||||||||||||||
| 1712 | cleared = false; | - | ||||||||||||||||||||||||||||||||||||
| 1713 | if (doUpdate) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1714 | updateEdit(); | - | ||||||||||||||||||||||||||||||||||||
| 1715 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1716 | q->update(); | - | ||||||||||||||||||||||||||||||||||||
| 1717 | - | |||||||||||||||||||||||||||||||||||||
| 1718 | if (ep == AlwaysEmit || (ep == EmitIfChanged && old != value)) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1719 | emitSignals(ep, old); | - | ||||||||||||||||||||||||||||||||||||
| 1720 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1721 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1722 | - | |||||||||||||||||||||||||||||||||||||
| 1723 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1724 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1725 | - | |||||||||||||||||||||||||||||||||||||
| 1726 | Updates the line edit to reflect the current value of the spin box. | - | ||||||||||||||||||||||||||||||||||||
| 1727 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1728 | - | |||||||||||||||||||||||||||||||||||||
| 1729 | void QAbstractSpinBoxPrivate::updateEdit() | - | ||||||||||||||||||||||||||||||||||||
| 1730 | { | - | ||||||||||||||||||||||||||||||||||||
| 1731 | Q_Q(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1732 | if (type == QVariant::Invalid)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1733 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1734 | const QString newText = specialValue() ? specialValueText : prefix + textFromValue(value) + suffix;
| 0 | ||||||||||||||||||||||||||||||||||||
| 1735 | if (newText == edit->displayText() || cleared)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1736 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1737 | - | |||||||||||||||||||||||||||||||||||||
| 1738 | const bool empty = edit->text().isEmpty(); | - | ||||||||||||||||||||||||||||||||||||
| 1739 | int cursor = edit->cursorPosition(); | - | ||||||||||||||||||||||||||||||||||||
| 1740 | int selsize = edit->selectedText().size(); | - | ||||||||||||||||||||||||||||||||||||
| 1741 | const QSignalBlocker blocker(edit); | - | ||||||||||||||||||||||||||||||||||||
| 1742 | edit->setText(newText); | - | ||||||||||||||||||||||||||||||||||||
| 1743 | - | |||||||||||||||||||||||||||||||||||||
| 1744 | if (!specialValue()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1745 | cursor = qBound(prefix.size(), cursor, edit->displayText().size() - suffix.size()); | - | ||||||||||||||||||||||||||||||||||||
| 1746 | - | |||||||||||||||||||||||||||||||||||||
| 1747 | if (selsize > 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1748 | edit->setSelection(cursor, selsize); | - | ||||||||||||||||||||||||||||||||||||
| 1749 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1750 | edit->setCursorPosition(empty ? prefix.size() : cursor); | - | ||||||||||||||||||||||||||||||||||||
| 1751 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1752 | } | - | ||||||||||||||||||||||||||||||||||||
| 1753 | q->update(); | - | ||||||||||||||||||||||||||||||||||||
| 1754 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1755 | - | |||||||||||||||||||||||||||||||||||||
| 1756 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1757 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1758 | - | |||||||||||||||||||||||||||||||||||||
| 1759 | Convenience function to set min/max values. | - | ||||||||||||||||||||||||||||||||||||
| 1760 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1761 | - | |||||||||||||||||||||||||||||||||||||
| 1762 | void QAbstractSpinBoxPrivate::setRange(const QVariant &min, const QVariant &max) | - | ||||||||||||||||||||||||||||||||||||
| 1763 | { | - | ||||||||||||||||||||||||||||||||||||
| 1764 | Q_Q(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1765 | - | |||||||||||||||||||||||||||||||||||||
| 1766 | clearCache(); | - | ||||||||||||||||||||||||||||||||||||
| 1767 | minimum = min; | - | ||||||||||||||||||||||||||||||||||||
| 1768 | maximum = (variantCompare(min, max) < 0 ? max : min);
| 0 | ||||||||||||||||||||||||||||||||||||
| 1769 | cachedSizeHint = QSize(); | - | ||||||||||||||||||||||||||||||||||||
| 1770 | cachedMinimumSizeHint = QSize(); // minimumSizeHint cares about min/max | - | ||||||||||||||||||||||||||||||||||||
| 1771 | - | |||||||||||||||||||||||||||||||||||||
| 1772 | reset(); | - | ||||||||||||||||||||||||||||||||||||
| 1773 | if (!(bound(value) == value)) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1774 | setValue(bound(value), EmitIfChanged); | - | ||||||||||||||||||||||||||||||||||||
| 1775 | } else if (value == minimum && !specialValueText.isEmpty()) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
| 1776 | updateEdit(); | - | ||||||||||||||||||||||||||||||||||||
| 1777 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1778 | - | |||||||||||||||||||||||||||||||||||||
| 1779 | q->updateGeometry(); | - | ||||||||||||||||||||||||||||||||||||
| 1780 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1781 | - | |||||||||||||||||||||||||||||||||||||
| 1782 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1783 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1784 | - | |||||||||||||||||||||||||||||||||||||
| 1785 | Convenience function to get a variant of the right type. | - | ||||||||||||||||||||||||||||||||||||
| 1786 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1787 | - | |||||||||||||||||||||||||||||||||||||
| 1788 | QVariant QAbstractSpinBoxPrivate::getZeroVariant() const | - | ||||||||||||||||||||||||||||||||||||
| 1789 | { | - | ||||||||||||||||||||||||||||||||||||
| 1790 | QVariant ret; | - | ||||||||||||||||||||||||||||||||||||
| 1791 | switch (type) { | - | ||||||||||||||||||||||||||||||||||||
| 1792 | case QVariant::Int: ret = QVariant((int)0); break; never executed: break;never executed: case QVariant::Int: | 0 | ||||||||||||||||||||||||||||||||||||
| 1793 | case QVariant::Double: ret = QVariant((double)0.0); break; never executed: break;never executed: case QVariant::Double: | 0 | ||||||||||||||||||||||||||||||||||||
| 1794 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||
| 1795 | } | - | ||||||||||||||||||||||||||||||||||||
| 1796 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||||||||||||||
| 1797 | } | - | ||||||||||||||||||||||||||||||||||||
| 1798 | - | |||||||||||||||||||||||||||||||||||||
| 1799 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1800 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1801 | - | |||||||||||||||||||||||||||||||||||||
| 1802 | Virtual method called that calls the public textFromValue() | - | ||||||||||||||||||||||||||||||||||||
| 1803 | functions in the subclasses. Needed to change signature from | - | ||||||||||||||||||||||||||||||||||||
| 1804 | QVariant to int/double/QDateTime etc. Used when needing to display | - | ||||||||||||||||||||||||||||||||||||
| 1805 | a value textually. | - | ||||||||||||||||||||||||||||||||||||
| 1806 | - | |||||||||||||||||||||||||||||||||||||
| 1807 | This method is reimeplemented in the various subclasses. | - | ||||||||||||||||||||||||||||||||||||
| 1808 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1809 | - | |||||||||||||||||||||||||||||||||||||
| 1810 | QString QAbstractSpinBoxPrivate::textFromValue(const QVariant &) const | - | ||||||||||||||||||||||||||||||||||||
| 1811 | { | - | ||||||||||||||||||||||||||||||||||||
| 1812 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||||||||||||||
| 1813 | } | - | ||||||||||||||||||||||||||||||||||||
| 1814 | - | |||||||||||||||||||||||||||||||||||||
| 1815 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1816 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1817 | - | |||||||||||||||||||||||||||||||||||||
| 1818 | Virtual method called that calls the public valueFromText() | - | ||||||||||||||||||||||||||||||||||||
| 1819 | functions in the subclasses. Needed to change signature from | - | ||||||||||||||||||||||||||||||||||||
| 1820 | QVariant to int/double/QDateTime etc. Used when needing to | - | ||||||||||||||||||||||||||||||||||||
| 1821 | interpret a string as another type. | - | ||||||||||||||||||||||||||||||||||||
| 1822 | - | |||||||||||||||||||||||||||||||||||||
| 1823 | This method is reimeplemented in the various subclasses. | - | ||||||||||||||||||||||||||||||||||||
| 1824 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1825 | - | |||||||||||||||||||||||||||||||||||||
| 1826 | QVariant QAbstractSpinBoxPrivate::valueFromText(const QString &) const | - | ||||||||||||||||||||||||||||||||||||
| 1827 | { | - | ||||||||||||||||||||||||||||||||||||
| 1828 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||||||||||||||
| 1829 | } | - | ||||||||||||||||||||||||||||||||||||
| 1830 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1831 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1832 | - | |||||||||||||||||||||||||||||||||||||
| 1833 | Interprets text and emits signals. Called when the spinbox needs | - | ||||||||||||||||||||||||||||||||||||
| 1834 | to interpret the text on the lineedit. | - | ||||||||||||||||||||||||||||||||||||
| 1835 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1836 | - | |||||||||||||||||||||||||||||||||||||
| 1837 | void QAbstractSpinBoxPrivate::interpret(EmitPolicy ep) | - | ||||||||||||||||||||||||||||||||||||
| 1838 | { | - | ||||||||||||||||||||||||||||||||||||
| 1839 | Q_Q(QAbstractSpinBox); | - | ||||||||||||||||||||||||||||||||||||
| 1840 | if (type == QVariant::Invalid || cleared)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1841 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1842 | - | |||||||||||||||||||||||||||||||||||||
| 1843 | QVariant v = getZeroVariant(); | - | ||||||||||||||||||||||||||||||||||||
| 1844 | bool doInterpret = true; | - | ||||||||||||||||||||||||||||||||||||
| 1845 | QString tmp = edit->displayText(); | - | ||||||||||||||||||||||||||||||||||||
| 1846 | int pos = edit->cursorPosition(); | - | ||||||||||||||||||||||||||||||||||||
| 1847 | const int oldpos = pos; | - | ||||||||||||||||||||||||||||||||||||
| 1848 | - | |||||||||||||||||||||||||||||||||||||
| 1849 | if (q->validate(tmp, pos) != QValidator::Acceptable) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1850 | const QString copy = tmp; | - | ||||||||||||||||||||||||||||||||||||
| 1851 | q->fixup(tmp); | - | ||||||||||||||||||||||||||||||||||||
| 1852 | QASBDEBUG() << "QAbstractSpinBoxPrivate::interpret() text '" dead code: QMessageLogger(__FILE__, 1852, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" << edit->displayText() << "' >> '" << copy << '\'' << "' >> '" << tmp << '\''; | - | ||||||||||||||||||||||||||||||||||||
| 1853 | << edit->displayText() dead code: QMessageLogger(__FILE__, 1852, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" << edit->displayText() << "' >> '" << copy << '\'' << "' >> '" << tmp << '\''; | - | ||||||||||||||||||||||||||||||||||||
| 1854 | << "' >> '" << copy << '\'' dead code: QMessageLogger(__FILE__, 1852, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" << edit->displayText() << "' >> '" << copy << '\'' << "' >> '" << tmp << '\''; | - | ||||||||||||||||||||||||||||||||||||
| 1855 | << "' >> '" << tmp << '\''; dead code: QMessageLogger(__FILE__, 1852, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" << edit->displayText() << "' >> '" << copy << '\'' << "' >> '" << tmp << '\''; | - | ||||||||||||||||||||||||||||||||||||
| 1856 | - | |||||||||||||||||||||||||||||||||||||
| 1857 | doInterpret = tmp != copy && (q->validate(tmp, pos) == QValidator::Acceptable);
| 0 | ||||||||||||||||||||||||||||||||||||
| 1858 | if (!doInterpret) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1859 | v = (correctionMode == QAbstractSpinBox::CorrectToNearestValue
| 0 | ||||||||||||||||||||||||||||||||||||
| 1860 | ? variantBound(minimum, v, maximum) : value); | - | ||||||||||||||||||||||||||||||||||||
| 1861 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1862 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1863 | if (doInterpret) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1864 | v = valueFromText(tmp); | - | ||||||||||||||||||||||||||||||||||||
| 1865 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1866 | clearCache(); | - | ||||||||||||||||||||||||||||||||||||
| 1867 | setValue(v, ep, true); | - | ||||||||||||||||||||||||||||||||||||
| 1868 | if (oldpos != pos)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1869 | edit->setCursorPosition(pos); never executed: edit->setCursorPosition(pos); | 0 | ||||||||||||||||||||||||||||||||||||
| 1870 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1871 | - | |||||||||||||||||||||||||||||||||||||
| 1872 | void QAbstractSpinBoxPrivate::clearCache() const | - | ||||||||||||||||||||||||||||||||||||
| 1873 | { | - | ||||||||||||||||||||||||||||||||||||
| 1874 | cachedText.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 1875 | cachedValue.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 1876 | cachedState = QValidator::Acceptable; | - | ||||||||||||||||||||||||||||||||||||
| 1877 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1878 | - | |||||||||||||||||||||||||||||||||||||
| 1879 | - | |||||||||||||||||||||||||||||||||||||
| 1880 | // --- QSpinBoxValidator --- | - | ||||||||||||||||||||||||||||||||||||
| 1881 | - | |||||||||||||||||||||||||||||||||||||
| 1882 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1883 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1884 | Constructs a QSpinBoxValidator object | - | ||||||||||||||||||||||||||||||||||||
| 1885 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1886 | - | |||||||||||||||||||||||||||||||||||||
| 1887 | QSpinBoxValidator::QSpinBoxValidator(QAbstractSpinBox *qp, QAbstractSpinBoxPrivate *dp) | - | ||||||||||||||||||||||||||||||||||||
| 1888 | : QValidator(qp), qptr(qp), dptr(dp) | - | ||||||||||||||||||||||||||||||||||||
| 1889 | { | - | ||||||||||||||||||||||||||||||||||||
| 1890 | setObjectName(QLatin1String("qt_spinboxvalidator")); | - | ||||||||||||||||||||||||||||||||||||
| 1891 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1892 | - | |||||||||||||||||||||||||||||||||||||
| 1893 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1894 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1895 | - | |||||||||||||||||||||||||||||||||||||
| 1896 | Checks for specialValueText, prefix, suffix and calls | - | ||||||||||||||||||||||||||||||||||||
| 1897 | the virtual QAbstractSpinBox::validate function. | - | ||||||||||||||||||||||||||||||||||||
| 1898 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1899 | - | |||||||||||||||||||||||||||||||||||||
| 1900 | QValidator::State QSpinBoxValidator::validate(QString &input, int &pos) const | - | ||||||||||||||||||||||||||||||||||||
| 1901 | { | - | ||||||||||||||||||||||||||||||||||||
| 1902 | if (dptr->specialValueText.size() > 0 && input == dptr->specialValueText)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1903 | return QValidator::Acceptable; never executed: return QValidator::Acceptable; | 0 | ||||||||||||||||||||||||||||||||||||
| 1904 | - | |||||||||||||||||||||||||||||||||||||
| 1905 | if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix)) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1906 | input.prepend(dptr->prefix); | - | ||||||||||||||||||||||||||||||||||||
| 1907 | pos += dptr->prefix.length(); | - | ||||||||||||||||||||||||||||||||||||
| 1908 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1909 | - | |||||||||||||||||||||||||||||||||||||
| 1910 | if (!dptr->suffix.isEmpty() && !input.endsWith(dptr->suffix))
| 0 | ||||||||||||||||||||||||||||||||||||
| 1911 | input.append(dptr->suffix); never executed: input.append(dptr->suffix); | 0 | ||||||||||||||||||||||||||||||||||||
| 1912 | - | |||||||||||||||||||||||||||||||||||||
| 1913 | return qptr->validate(input, pos); never executed: return qptr->validate(input, pos); | 0 | ||||||||||||||||||||||||||||||||||||
| 1914 | } | - | ||||||||||||||||||||||||||||||||||||
| 1915 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1916 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1917 | Calls the virtual QAbstractSpinBox::fixup function. | - | ||||||||||||||||||||||||||||||||||||
| 1918 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1919 | - | |||||||||||||||||||||||||||||||||||||
| 1920 | void QSpinBoxValidator::fixup(QString &input) const | - | ||||||||||||||||||||||||||||||||||||
| 1921 | { | - | ||||||||||||||||||||||||||||||||||||
| 1922 | qptr->fixup(input); | - | ||||||||||||||||||||||||||||||||||||
| 1923 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1924 | - | |||||||||||||||||||||||||||||||||||||
| 1925 | // --- global --- | - | ||||||||||||||||||||||||||||||||||||
| 1926 | - | |||||||||||||||||||||||||||||||||||||
| 1927 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1928 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1929 | Adds two variants together and returns the result. | - | ||||||||||||||||||||||||||||||||||||
| 1930 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1931 | - | |||||||||||||||||||||||||||||||||||||
| 1932 | QVariant operator+(const QVariant &arg1, const QVariant &arg2) | - | ||||||||||||||||||||||||||||||||||||
| 1933 | { | - | ||||||||||||||||||||||||||||||||||||
| 1934 | QVariant ret; | - | ||||||||||||||||||||||||||||||||||||
| 1935 | if (arg1.type() != arg2.type())
| 0 | ||||||||||||||||||||||||||||||||||||
| 1936 | qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", never executed: QMessageLogger(__FILE__, 1936, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, 1937); | 0 | ||||||||||||||||||||||||||||||||||||
| 1937 | arg1.typeName(), arg2.typeName(), __FILE__, __LINE__); never executed: QMessageLogger(__FILE__, 1936, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, 1937); | 0 | ||||||||||||||||||||||||||||||||||||
| 1938 | switch (arg1.type()) { | - | ||||||||||||||||||||||||||||||||||||
| 1939 | case QVariant::Int: { never executed: case QVariant::Int: | 0 | ||||||||||||||||||||||||||||||||||||
| 1940 | const int int1 = arg1.toInt(); | - | ||||||||||||||||||||||||||||||||||||
| 1941 | const int int2 = arg2.toInt(); | - | ||||||||||||||||||||||||||||||||||||
| 1942 | if (int1 > 0 && (int2 >= INT_MAX - int1)) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1943 | // The increment overflows | - | ||||||||||||||||||||||||||||||||||||
| 1944 | ret = QVariant(INT_MAX); | - | ||||||||||||||||||||||||||||||||||||
| 1945 | } else if (int1 < 0 && (int2 <= INT_MIN - int1)) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
| 1946 | // The increment underflows | - | ||||||||||||||||||||||||||||||||||||
| 1947 | ret = QVariant(INT_MIN); | - | ||||||||||||||||||||||||||||||||||||
| 1948 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1949 | ret = QVariant(int1 + int2); | - | ||||||||||||||||||||||||||||||||||||
| 1950 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1951 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 1952 | } | - | ||||||||||||||||||||||||||||||||||||
| 1953 | case QVariant::Double: ret = QVariant(arg1.toDouble() + arg2.toDouble()); break; never executed: break;never executed: case QVariant::Double: | 0 | ||||||||||||||||||||||||||||||||||||
| 1954 | case QVariant::DateTime: { never executed: case QVariant::DateTime: | 0 | ||||||||||||||||||||||||||||||||||||
| 1955 | QDateTime a2 = arg2.toDateTime(); | - | ||||||||||||||||||||||||||||||||||||
| 1956 | QDateTime a1 = arg1.toDateTime().addDays(QDATETIMEEDIT_DATETIME_MIN.daysTo(a2)); | - | ||||||||||||||||||||||||||||||||||||
| 1957 | a1.setTime(a1.time().addMSecs(QTime().msecsTo(a2.time()))); | - | ||||||||||||||||||||||||||||||||||||
| 1958 | ret = QVariant(a1); | - | ||||||||||||||||||||||||||||||||||||
| 1959 | } | - | ||||||||||||||||||||||||||||||||||||
| 1960 | default: break; never executed: break;code before this statement never executed: default:never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||
| 1961 | } | - | ||||||||||||||||||||||||||||||||||||
| 1962 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||||||||||||||
| 1963 | } | - | ||||||||||||||||||||||||||||||||||||
| 1964 | - | |||||||||||||||||||||||||||||||||||||
| 1965 | - | |||||||||||||||||||||||||||||||||||||
| 1966 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1967 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 1968 | Subtracts two variants and returns the result. | - | ||||||||||||||||||||||||||||||||||||
| 1969 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1970 | - | |||||||||||||||||||||||||||||||||||||
| 1971 | QVariant operator-(const QVariant &arg1, const QVariant &arg2) | - | ||||||||||||||||||||||||||||||||||||
| 1972 | { | - | ||||||||||||||||||||||||||||||||||||
| 1973 | QVariant ret; | - | ||||||||||||||||||||||||||||||||||||
| 1974 | if (arg1.type() != arg2.type())
| 0 | ||||||||||||||||||||||||||||||||||||
| 1975 | qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", never executed: QMessageLogger(__FILE__, 1975, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, 1976); | 0 | ||||||||||||||||||||||||||||||||||||
| 1976 | arg1.typeName(), arg2.typeName(), __FILE__, __LINE__); never executed: QMessageLogger(__FILE__, 1975, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, 1976); | 0 | ||||||||||||||||||||||||||||||||||||
| 1977 | switch (arg1.type()) { | - | ||||||||||||||||||||||||||||||||||||
| 1978 | case QVariant::Int: ret = QVariant(arg1.toInt() - arg2.toInt()); break; never executed: break;never executed: case QVariant::Int: | 0 | ||||||||||||||||||||||||||||||||||||
| 1979 | case QVariant::Double: ret = QVariant(arg1.toDouble() - arg2.toDouble()); break; never executed: break;never executed: case QVariant::Double: | 0 | ||||||||||||||||||||||||||||||||||||
| 1980 | case QVariant::DateTime: { never executed: case QVariant::DateTime: | 0 | ||||||||||||||||||||||||||||||||||||
| 1981 | QDateTime a1 = arg1.toDateTime(); | - | ||||||||||||||||||||||||||||||||||||
| 1982 | QDateTime a2 = arg2.toDateTime(); | - | ||||||||||||||||||||||||||||||||||||
| 1983 | int days = a2.daysTo(a1); | - | ||||||||||||||||||||||||||||||||||||
| 1984 | int secs = a2.secsTo(a1); | - | ||||||||||||||||||||||||||||||||||||
| 1985 | int msecs = qMax(0, a1.time().msec() - a2.time().msec()); | - | ||||||||||||||||||||||||||||||||||||
| 1986 | if (days < 0 || secs < 0 || msecs < 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 1987 | ret = arg1; | - | ||||||||||||||||||||||||||||||||||||
| 1988 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1989 | QDateTime dt = a2.addDays(days).addSecs(secs); | - | ||||||||||||||||||||||||||||||||||||
| 1990 | if (msecs > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1991 | dt.setTime(dt.time().addMSecs(msecs)); never executed: dt.setTime(dt.time().addMSecs(msecs)); | 0 | ||||||||||||||||||||||||||||||||||||
| 1992 | ret = QVariant(dt); | - | ||||||||||||||||||||||||||||||||||||
| 1993 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1994 | } | - | ||||||||||||||||||||||||||||||||||||
| 1995 | default: break; never executed: break;code before this statement never executed: default:never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||
| 1996 | } | - | ||||||||||||||||||||||||||||||||||||
| 1997 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||||||||||||||
| 1998 | } | - | ||||||||||||||||||||||||||||||||||||
| 1999 | - | |||||||||||||||||||||||||||||||||||||
| 2000 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2001 | \internal | - | ||||||||||||||||||||||||||||||||||||
| 2002 | Multiplies \a arg1 by \a multiplier and returns the result. | - | ||||||||||||||||||||||||||||||||||||
| 2003 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2004 | - | |||||||||||||||||||||||||||||||||||||
| 2005 | QVariant operator*(const QVariant &arg1, double multiplier) | - | ||||||||||||||||||||||||||||||||||||
| 2006 | { | - | ||||||||||||||||||||||||||||||||||||
| 2007 | QVariant ret; | - | ||||||||||||||||||||||||||||||||||||
| 2008 | - | |||||||||||||||||||||||||||||||||||||
| 2009 | switch (arg1.type()) { | - | ||||||||||||||||||||||||||||||||||||
| 2010 | case QVariant::Int: never executed: case QVariant::Int: | 0 | ||||||||||||||||||||||||||||||||||||
| 2011 | ret = static_cast<int>(qBound<double>(INT_MIN, arg1.toInt() * multiplier, INT_MAX)); | - | ||||||||||||||||||||||||||||||||||||
| 2012 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 2013 | case QVariant::Double: ret = QVariant(arg1.toDouble() * multiplier); break; never executed: break;never executed: case QVariant::Double: | 0 | ||||||||||||||||||||||||||||||||||||
| 2014 | case QVariant::DateTime: { never executed: case QVariant::DateTime: | 0 | ||||||||||||||||||||||||||||||||||||
| 2015 | double days = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDateTime().date()) * multiplier; | - | ||||||||||||||||||||||||||||||||||||
| 2016 | int daysInt = (int)days; | - | ||||||||||||||||||||||||||||||||||||
| 2017 | days -= daysInt; | - | ||||||||||||||||||||||||||||||||||||
| 2018 | long msecs = (long)((QDATETIMEEDIT_TIME_MIN.msecsTo(arg1.toDateTime().time()) * multiplier) | - | ||||||||||||||||||||||||||||||||||||
| 2019 | + (days * (24 * 3600 * 1000))); | - | ||||||||||||||||||||||||||||||||||||
| 2020 | ret = QDateTime(QDate().addDays(int(days)), QTime().addMSecs(msecs)); | - | ||||||||||||||||||||||||||||||||||||
| 2021 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 2022 | } | - | ||||||||||||||||||||||||||||||||||||
| 2023 | default: ret = arg1; break; never executed: break;never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||
| 2024 | } | - | ||||||||||||||||||||||||||||||||||||
| 2025 | - | |||||||||||||||||||||||||||||||||||||
| 2026 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||||||||||||||
| 2027 | } | - | ||||||||||||||||||||||||||||||||||||
| 2028 | - | |||||||||||||||||||||||||||||||||||||
| 2029 | - | |||||||||||||||||||||||||||||||||||||
| 2030 | - | |||||||||||||||||||||||||||||||||||||
| 2031 | double operator/(const QVariant &arg1, const QVariant &arg2) | - | ||||||||||||||||||||||||||||||||||||
| 2032 | { | - | ||||||||||||||||||||||||||||||||||||
| 2033 | double a1 = 0; | - | ||||||||||||||||||||||||||||||||||||
| 2034 | double a2 = 0; | - | ||||||||||||||||||||||||||||||||||||
| 2035 | - | |||||||||||||||||||||||||||||||||||||
| 2036 | switch (arg1.type()) { | - | ||||||||||||||||||||||||||||||||||||
| 2037 | case QVariant::Int: never executed: case QVariant::Int: | 0 | ||||||||||||||||||||||||||||||||||||
| 2038 | a1 = (double)arg1.toInt(); | - | ||||||||||||||||||||||||||||||||||||
| 2039 | a2 = (double)arg2.toInt(); | - | ||||||||||||||||||||||||||||||||||||
| 2040 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 2041 | case QVariant::Double: never executed: case QVariant::Double: | 0 | ||||||||||||||||||||||||||||||||||||
| 2042 | a1 = arg1.toDouble(); | - | ||||||||||||||||||||||||||||||||||||
| 2043 | a2 = arg2.toDouble(); | - | ||||||||||||||||||||||||||||||||||||
| 2044 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 2045 | case QVariant::DateTime: never executed: case QVariant::DateTime: | 0 | ||||||||||||||||||||||||||||||||||||
| 2046 | a1 = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDate()); | - | ||||||||||||||||||||||||||||||||||||
| 2047 | a2 = QDATETIMEEDIT_DATE_MIN.daysTo(arg2.toDate()); | - | ||||||||||||||||||||||||||||||||||||
| 2048 | a1 += (double)QDATETIMEEDIT_TIME_MIN.msecsTo(arg1.toDateTime().time()) / (long)(3600 * 24 * 1000); | - | ||||||||||||||||||||||||||||||||||||
| 2049 | a2 += (double)QDATETIMEEDIT_TIME_MIN.msecsTo(arg2.toDateTime().time()) / (long)(3600 * 24 * 1000); | - | ||||||||||||||||||||||||||||||||||||
| 2050 | default: break; never executed: break;code before this statement never executed: default:never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||
| 2051 | } | - | ||||||||||||||||||||||||||||||||||||
| 2052 | - | |||||||||||||||||||||||||||||||||||||
| 2053 | return (a1 != 0 && a2 != 0) ? (a1 / a2) : 0.0; never executed: return (a1 != 0 && a2 != 0) ? (a1 / a2) : 0.0;
| 0 | ||||||||||||||||||||||||||||||||||||
| 2054 | } | - | ||||||||||||||||||||||||||||||||||||
| 2055 | - | |||||||||||||||||||||||||||||||||||||
| 2056 | int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant &arg2) | - | ||||||||||||||||||||||||||||||||||||
| 2057 | { | - | ||||||||||||||||||||||||||||||||||||
| 2058 | switch (arg2.type()) { | - | ||||||||||||||||||||||||||||||||||||
| 2059 | case QVariant::Date: never executed: case QVariant::Date: | 0 | ||||||||||||||||||||||||||||||||||||
| 2060 | Q_ASSERT_X(arg1.type() == QVariant::Date, "QAbstractSpinBoxPrivate::variantCompare", | - | ||||||||||||||||||||||||||||||||||||
| 2061 | qPrintable(QString::fromLatin1("Internal error 1 (%1)"). | - | ||||||||||||||||||||||||||||||||||||
| 2062 | arg(QString::fromLatin1(arg1.typeName())))); | - | ||||||||||||||||||||||||||||||||||||
| 2063 | if (arg1.toDate() == arg2.toDate()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 2064 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 2065 | } else if (arg1.toDate() < arg2.toDate()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 2066 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||
| 2067 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 2068 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||||||||
| 2069 | } | - | ||||||||||||||||||||||||||||||||||||
| 2070 | case QVariant::Time: never executed: case QVariant::Time: | 0 | ||||||||||||||||||||||||||||||||||||
| 2071 | Q_ASSERT_X(arg1.type() == QVariant::Time, "QAbstractSpinBoxPrivate::variantCompare", | - | ||||||||||||||||||||||||||||||||||||
| 2072 | qPrintable(QString::fromLatin1("Internal error 2 (%1)"). | - | ||||||||||||||||||||||||||||||||||||
| 2073 | arg(QString::fromLatin1(arg1.typeName())))); | - | ||||||||||||||||||||||||||||||||||||
| 2074 | if (arg1.toTime() == arg2.toTime()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 2075 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 2076 | } else if (arg1.toTime() < arg2.toTime()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 2077 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||
| 2078 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 2079 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||||||||
| 2080 | } | - | ||||||||||||||||||||||||||||||||||||
| 2081 | - | |||||||||||||||||||||||||||||||||||||
| 2082 | - | |||||||||||||||||||||||||||||||||||||
| 2083 | case QVariant::DateTime: never executed: case QVariant::DateTime: | 0 | ||||||||||||||||||||||||||||||||||||
| 2084 | if (arg1.toDateTime() == arg2.toDateTime()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 2085 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 2086 | } else if (arg1.toDateTime() < arg2.toDateTime()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 2087 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||
| 2088 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 2089 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||||||||
| 2090 | } | - | ||||||||||||||||||||||||||||||||||||
| 2091 | case QVariant::Int: never executed: case QVariant::Int: | 0 | ||||||||||||||||||||||||||||||||||||
| 2092 | if (arg1.toInt() == arg2.toInt()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 2093 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 2094 | } else if (arg1.toInt() < arg2.toInt()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 2095 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||
| 2096 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 2097 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||||||||
| 2098 | } | - | ||||||||||||||||||||||||||||||||||||
| 2099 | case QVariant::Double: never executed: case QVariant::Double: | 0 | ||||||||||||||||||||||||||||||||||||
| 2100 | if (arg1.toDouble() == arg2.toDouble()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 2101 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 2102 | } else if (arg1.toDouble() < arg2.toDouble()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 2103 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||
| 2104 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 2105 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||||||||
| 2106 | } | - | ||||||||||||||||||||||||||||||||||||
| 2107 | case QVariant::Invalid: never executed: case QVariant::Invalid: | 0 | ||||||||||||||||||||||||||||||||||||
| 2108 | if (arg2.type() == QVariant::Invalid)
| 0 | ||||||||||||||||||||||||||||||||||||
| 2109 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 2110 | default: code before this statement never executed: default:never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||
| 2111 | Q_ASSERT_X(0, "QAbstractSpinBoxPrivate::variantCompare", | - | ||||||||||||||||||||||||||||||||||||
| 2112 | qPrintable(QString::fromLatin1("Internal error 3 (%1 %2)"). | - | ||||||||||||||||||||||||||||||||||||
| 2113 | arg(QString::fromLatin1(arg1.typeName())). | - | ||||||||||||||||||||||||||||||||||||
| 2114 | arg(QString::fromLatin1(arg2.typeName())))); | - | ||||||||||||||||||||||||||||||||||||
| 2115 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 2116 | return -2; never executed: return -2; | 0 | ||||||||||||||||||||||||||||||||||||
| 2117 | } | - | ||||||||||||||||||||||||||||||||||||
| 2118 | - | |||||||||||||||||||||||||||||||||||||
| 2119 | QVariant QAbstractSpinBoxPrivate::variantBound(const QVariant &min, | - | ||||||||||||||||||||||||||||||||||||
| 2120 | const QVariant &value, | - | ||||||||||||||||||||||||||||||||||||
| 2121 | const QVariant &max) | - | ||||||||||||||||||||||||||||||||||||
| 2122 | { | - | ||||||||||||||||||||||||||||||||||||
| 2123 | Q_ASSERT(variantCompare(min, max) <= 0); | - | ||||||||||||||||||||||||||||||||||||
| 2124 | if (variantCompare(min, value) < 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 2125 | const int compMax = variantCompare(value, max); | - | ||||||||||||||||||||||||||||||||||||
| 2126 | return (compMax < 0 ? value : max); never executed: return (compMax < 0 ? value : max);
| 0 | ||||||||||||||||||||||||||||||||||||
| 2127 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 2128 | return min; never executed: return min; | 0 | ||||||||||||||||||||||||||||||||||||
| 2129 | } | - | ||||||||||||||||||||||||||||||||||||
| 2130 | } | - | ||||||||||||||||||||||||||||||||||||
| 2131 | - | |||||||||||||||||||||||||||||||||||||
| 2132 | - | |||||||||||||||||||||||||||||||||||||
| 2133 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||||||||
| 2134 | - | |||||||||||||||||||||||||||||||||||||
| 2135 | #include "moc_qabstractspinbox.cpp" | - | ||||||||||||||||||||||||||||||||||||
| 2136 | - | |||||||||||||||||||||||||||||||||||||
| 2137 | #endif // QT_NO_SPINBOX | - | ||||||||||||||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |