⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qabstractspinbox.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include <qplatformdefs.h>#include <private/qabstractspinbox_p.h>#include <private/qdatetime_p.h>#include <private/qlineedit_p.h>#include <qabstractspinbox.h>#ifndef QT_NO_SPINBOX#include <qapplication.h>#include <qclipboard.h>#include <qdatetime.h>#include <qdatetimeedit.h>#include <qevent.h>#include <qmenu.h>#include <qpainter.h>#include <qpalette.h>#include <qstylepainter.h>#include <qdebug.h>#if defined(Q_WS_X11)#include <limits.h>#endifstatic const int thresholdTime = 500; // ### Qt 4.1: make this a stylehint//#define QABSTRACTSPINBOX_QSBDEBUG#ifdef QABSTRACTSPINBOX_QSBDEBUG#  define QASBDEBUG qDebug#else#  define QASBDEBUG if (false) qDebug#endif/*!    \class QAbstractSpinBox    \brief The QAbstractSpinBox class provides a spinbox and a line edit to    display values.    \ingroup abstractwidgets    The class is designed as a common super class for widgets like    QSpinBox, QDoubleSpinBox and QDateTimeEdit    Here are the main properties of the class:    \list 1    \i \l text: The text that is displayed in the QAbstractSpinBox.    \i \l alignment: The alignment of the text in the QAbstractSpinBox.    \i \l wrapping: Whether the QAbstractSpinBox wraps from the    minimum value to the maximum value and vica versa.    \endlist    QAbstractSpinBox provides a virtual stepBy() function that is    called whenever the user triggers a step. This function takes an    integer value to signify how many steps were taken. E.g. Pressing    Qt::Key_Down will trigger a call to stepBy(-1).    QAbstractSpinBox also provide a virtual function stepEnabled() to    determine whether stepping up/down is allowed at any point. This    function returns a bitset of StepEnabled.    \sa QAbstractSlider, QSpinBox, QDoubleSpinBox, QDateTimeEdit,        {Spin Boxes Example}*//*!    \enum QAbstractSpinBox::StepEnabledFlag    \value StepNone    \value StepUpEnabled    \value StepDownEnabled*//*!  \fn void QAbstractSpinBox::editingFinished()  This signal is emitted editing is finished. This happens when the  spinbox loses focus and when enter is pressed.*//*!    Constructs an abstract spinbox with the given \a parent with default    \l wrapping, and \l alignment properties.*/QAbstractSpinBox::QAbstractSpinBox(QWidget *parent)    : QWidget(*new QAbstractSpinBoxPrivate, parent, 0){    Q_D(QAbstractSpinBox);    d->init();}/*!    \internal*/QAbstractSpinBox::QAbstractSpinBox(QAbstractSpinBoxPrivate &dd, QWidget *parent)    : QWidget(dd, parent, 0){    Q_D(QAbstractSpinBox);    d->init();}/*!    Called when the QAbstractSpinBox is destroyed.*/QAbstractSpinBox::~QAbstractSpinBox(){}/*!    \enum QAbstractSpinBox::ButtonSymbols    This enum type describes the symbols that can be displayed on the buttons    in a spin box.    \inlineimage qspinbox-updown.png    \inlineimage qspinbox-plusminus.png    \value UpDownArrows Little arrows in the classic style.    \value PlusMinus \bold{+} and \bold{-} symbols.    \value NoButtons Don't display buttons.    \sa QAbstractSpinBox::buttonSymbols*//*!    \property QAbstractSpinBox::buttonSymbols    \brief the current button symbol mode    The possible values can be either \c UpDownArrows or \c PlusMinus.    The default is \c UpDownArrows.    Note that some styles might render PlusMinus and UpDownArrows    identically.    \sa ButtonSymbols*/QAbstractSpinBox::ButtonSymbols QAbstractSpinBox::buttonSymbols() const{    Q_D(const QAbstractSpinBox);    return d->buttonSymbols;}void QAbstractSpinBox::setButtonSymbols(ButtonSymbols buttonSymbols){    Q_D(QAbstractSpinBox);    if (d->buttonSymbols != buttonSymbols) {        d->buttonSymbols = buttonSymbols;        update();    }}/*!    \property QAbstractSpinBox::text    \brief the spin box's text, including any prefix and suffix    There is no default text.*/QString QAbstractSpinBox::text() const{    return lineEdit()->displayText();}/*!    \property QAbstractSpinBox::specialValueText    \brief the special-value text    If set, the spin box will display this text instead of a numeric    value whenever the current value is equal to minimum(). Typical use    is to indicate that this choice has a special (default) meaning.    For example, if your spin box allows the user to choose a scale factor    (or zoom level) for displaying an image, and your application is able    to automatically choose one that will enable the image to fit completely    within the display window, you can set up the spin box like this:    \quotefromfile widgets/spinboxes/window.cpp    \skipto zoomSpinBox    \printuntil setValue    The user will then be able to choose a scale from 1% to 1000%    or select "Auto" to leave it up to the application to choose. Your code    must then interpret the spin box value of 0 as a request from the user    to scale the image to fit inside the window.    All values are displayed with the prefix and suffix (if set), \e    except for the special value, which only shows the special value    text. This special text is passed in the QSpinBox::valueChanged()    signal that passes a QString.    To turn off the special-value text display, call this function    with an empty string. The default is no special-value text, i.e.    the numeric value is shown as usual.    If no special-value text is set, specialValueText() returns an    empty string.*/QString QAbstractSpinBox::specialValueText() const{    Q_D(const QAbstractSpinBox);    return d->specialValueText;}void QAbstractSpinBox::setSpecialValueText(const QString &specialValueText){    Q_D(QAbstractSpinBox);    d->specialValueText = specialValueText;    d->clearCache();    d->updateEdit();}/*!    \property QAbstractSpinBox::wrapping    \brief whether the spin box is circular.    If wrapping is true stepping up from maximum() value will take you    to the minimum() value and vica versa. Wrapping only make sense if    you have minimum() and maximum() values set.    \code        QSpinBox *spinBox = new QSpinBox(this);        spinBox->setRange(0, 100);        spinBox->setWrapping(true);        spinBox->setValue(100);        spinBox->stepBy(1);        // value is 0    \endcode    \sa QSpinBox::minimum(), QSpinBox::maximum()*/bool QAbstractSpinBox::wrapping() const{    Q_D(const QAbstractSpinBox);    return d->wrapping;}void QAbstractSpinBox::setWrapping(bool wrapping){    Q_D(QAbstractSpinBox);    d->wrapping = wrapping;}/*!    \property QAbstractSpinBox::readOnly    \brief whether the spin box is read only.    In read-only mode, the user can still copy the text to the    clipboard, or drag and drop the text;    but cannot edit it.    The QLineEdit in the QAbstractSpinBox does not show a cursor in    read-only mode.    \sa QLineEdit::readOnly*/bool QAbstractSpinBox::isReadOnly() const{    Q_D(const QAbstractSpinBox);    return d->readOnly;}void QAbstractSpinBox::setReadOnly(bool enable){    Q_D(QAbstractSpinBox);    d->readOnly = enable;    d->edit->setReadOnly(enable);    update();}/*!    \property QAbstractSpinBox::keyboardTracking    \brief whether keyboard tracking is enabled for the spinbox.    \since 4.3    If keyboard tracking is enabled (the default), the spinbox    emits the valueChanged() signal while the new value is being    entered from the keyboard.    E.g. when the user enters the value 600 by typing 6, 0, and 0,    the spinbox emits 3 signals with the values 6, 60, and 600    respectively.    If keyboard tracking is disabled, the spinbox doesn't emit the    valueChanged() signal while typing. It emits the signal later,    when the return key is pressed, when keyboard focus is lost, or    when other spinbox functionality is used, e.g. pressing an arrow    key.*/bool QAbstractSpinBox::keyboardTracking() const{    Q_D(const QAbstractSpinBox);    return d->keyboardTracking;}void QAbstractSpinBox::setKeyboardTracking(bool enable){    Q_D(QAbstractSpinBox);    d->keyboardTracking = enable;}/*!    \property QAbstractSpinBox::frame    \brief whether the spin box draws itself with a frame    If enabled (the default) the spin box draws itself inside a frame,    otherwise the spin box draws itself without any frame.*/bool QAbstractSpinBox::hasFrame() const{    Q_D(const QAbstractSpinBox);    return d->frame;}void QAbstractSpinBox::setFrame(bool enable){    Q_D(QAbstractSpinBox);    d->frame = enable;    update();    d->updateEditFieldGeometry();}/*!    \property QAbstractSpinBox::accelerated    \brief whether the spin box will accelerate the frequency of the steps when    pressing the step Up/Down buttons.    \since 4.2    If enabled the spin box will increase/decrease the value faster    the longer you hold the button down.*/void QAbstractSpinBox::setAccelerated(bool accelerate){    Q_D(QAbstractSpinBox);    d->accelerate = accelerate;}bool QAbstractSpinBox::isAccelerated() const{    Q_D(const QAbstractSpinBox);    return d->accelerate;}/*!    \enum QAbstractSpinBox::CorrectionMode    This enum type describes the mode the spinbox will use to correct    an \l{QValidator::}{Intermediate} value if editing finishes.    \value CorrectToPreviousValue The spinbox will revert to the last                                  valid value.    \value CorrectToNearestValue The spinbox will revert to the nearest                                 valid value.    \sa correctionMode*//*!    \property QAbstractSpinBox::correctionMode    \brief the mode to correct an \l{QValidator::}{Intermediate}           value if editing finishes    \since 4.2    The default mode is QAbstractSpinBox::CorrectToPreviousValue.    \sa acceptableInput, validate(), fixup()*/void QAbstractSpinBox::setCorrectionMode(CorrectionMode correctionMode){    Q_D(QAbstractSpinBox);    d->correctionMode = correctionMode;}QAbstractSpinBox::CorrectionMode QAbstractSpinBox::correctionMode() const{    Q_D(const QAbstractSpinBox);    return d->correctionMode;}/*!  \property QAbstractSpinBox::acceptableInput  \brief whether the input satisfies the current validation  \since 4.2  \sa validate(), fixup(), correctionMode*/bool QAbstractSpinBox::hasAcceptableInput() const{    Q_D(const QAbstractSpinBox);    return d->edit->hasAcceptableInput();}/*!    \property QAbstractSpinBox::alignment    \brief the alignment of the spin box    Possible Values are Qt::AlignLeft, Qt::AlignRight, and Qt::AlignHCenter.    By default, the alignment is Qt::AlignLeft    Attempting to set the alignment to an illegal flag combination    does nothing.    \sa Qt::Alignment*/Qt::Alignment QAbstractSpinBox::alignment() const{    Q_D(const QAbstractSpinBox);    return (Qt::Alignment)d->edit->alignment();}void QAbstractSpinBox::setAlignment(Qt::Alignment flag){    Q_D(QAbstractSpinBox);    d->edit->setAlignment(flag);}/*!    Selects all the text in the spinbox except the prefix and suffix.*/void QAbstractSpinBox::selectAll(){    Q_D(QAbstractSpinBox);    if (!d->specialValue()) {        const int tmp = d->edit->displayText().size() - d->suffix.size();        d->edit->setSelection(tmp, -(tmp - d->prefix.size()));    } else {        d->edit->selectAll();    }}/*!    Clears the lineedit of all text but prefix and suffix.*/void QAbstractSpinBox::clear(){    Q_D(QAbstractSpinBox);    d->edit->setText(d->prefix + d->suffix);    d->edit->setCursorPosition(d->prefix.size());}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -