Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/widgets/qabstractspinbox.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5858#include <qstylepainter.h>
    5959#include <qdebug.h>
     60#ifndef QT_NO_ACCESSIBILITY
     61# include <qaccessible.h>
     62#endif
    6063
    6164#if defined(Q_WS_X11)
    6265#include <limits.h>
     66#endif
     67
     68#if defined(Q_OS_SYMBIAN)
     69#include <W32STD.H>
     70#include <private/qt_s60_p.h>
    6371#endif
    6472
     
    194202    if (d->buttonSymbols != buttonSymbols) {
    195203        d->buttonSymbols = buttonSymbols;
     204        d->updateEditFieldGeometry();
    196205        update();
    197206    }
     
    660669
    661670    d->edit->setFrame(false);
    662     d->edit->setAttribute(Qt::WA_InputMethodEnabled, false);
    663671    d->edit->setFocusProxy(this);
    664672    d->edit->setAcceptDrops(false);
     
    689697    Q_D(QAbstractSpinBox);
    690698    d->interpret(EmitIfChanged);
     699}
     700
     701/*
     702    Reimplemented in 4.6, so be careful.
     703 */
     704/*!
     705    \reimp
     706*/
     707QVariant QAbstractSpinBox::inputMethodQuery(Qt::InputMethodQuery query) const
     708{
     709    Q_D(const QAbstractSpinBox);
     710    return d->edit->inputMethodQuery(query);
    691711}
    692712
     
    925945
    926946    int steps = 1;
     947    bool isPgUpOrDown = false;
    927948    switch (event->key()) {
    928949    case Qt::Key_PageUp:
    929950    case Qt::Key_PageDown:
    930951        steps *= 10;
     952        isPgUpOrDown = true;
    931953    case Qt::Key_Up:
    932954    case Qt::Key_Down: {
     
    950972            d->buttonState = (Keyboard | (up ? Up : Down));
    951973        }
    952         stepBy(steps);
     974        if (d->spinClickTimerId == -1)
     975            stepBy(steps);
     976        if(event->isAutoRepeat() && !isPgUpOrDown) {
     977            if(d->spinClickThresholdTimerId == -1 && d->spinClickTimerId == -1) {
     978                d->updateState(up, true);
     979            }
     980        }
     981#ifndef QT_NO_ACCESSIBILITY
     982        QAccessible::updateAccessibility(this, 0, QAccessible::ValueChanged);
     983#endif
    953984        return;
    954985    }
     
    9701001    case Qt::Key_Enter:
    9711002    case Qt::Key_Return:
    972         d->edit->d_func()->modifiedState = d->edit->d_func()->undoState = 0;
     1003        d->edit->d_func()->control->clearUndo();
    9731004        d->interpret(d->keyboardTracking ? AlwaysEmit : EmitIfChanged);
    9741005        selectAll();
     
    10441075    Q_D(QAbstractSpinBox);
    10451076
    1046     if (d->buttonState & Keyboard && !event->isAutoRepeat()
    1047         && style()->styleHint(QStyle::SH_SpinBox_AnimateButton, 0, this)) {
     1077    if (d->buttonState & Keyboard && !event->isAutoRepeat())  {
    10481078        d->reset();
    10491079    } else {
     
    11311161}
    11321162
     1163
     1164/*!
     1165    \internal
     1166
     1167    Used when acceleration is turned on. We need to get the
     1168    keyboard auto repeat rate from OS. This value is used as
     1169    argument when starting acceleration related timers.
     1170
     1171    Every platform should, either, use native calls to obtain
     1172    the value or hard code some reasonable rate.
     1173
     1174    Remember that time value should be given in msecs.
     1175*/
     1176static int getKeyboardAutoRepeatRate() {
     1177    int ret = 30;
     1178#if defined(Q_OS_SYMBIAN)
     1179    TTimeIntervalMicroSeconds32 initialTime;
     1180    TTimeIntervalMicroSeconds32 time;
     1181    S60->wsSession().GetKeyboardRepeatRate(initialTime, time);
     1182    ret = time.Int() / 1000; // msecs
     1183#elif defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
     1184    DWORD time;
     1185    if (SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &time, 0) != FALSE)
     1186        ret = static_cast<int>(1000 / static_cast<int>(time)); // msecs
     1187#endif
     1188    return ret; // msecs
     1189}
     1190
    11331191/*!
    11341192    \reimp
     
    11431201        killTimer(d->spinClickThresholdTimerId);
    11441202        d->spinClickThresholdTimerId = -1;
    1145         d->spinClickTimerId = startTimer(d->spinClickTimerInterval);
     1203        d->effectiveSpinRepeatRate = d->buttonState & Keyboard
     1204                                     ? getKeyboardAutoRepeatRate()
     1205                                     : d->spinClickTimerInterval;
     1206        d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate);
    11461207        doStep = true;
    11471208    } else if (event->timerId() == d->spinClickTimerId) {
    11481209        if (d->accelerate) {
    1149             d->acceleration = d->acceleration + (int)(d->spinClickTimerInterval * 0.05);
    1150             if (d->spinClickTimerInterval - d->acceleration >= 10) {
     1210            d->acceleration = d->acceleration + (int)(d->effectiveSpinRepeatRate * 0.05);
     1211            if (d->effectiveSpinRepeatRate - d->acceleration >= 10) {
    11511212                killTimer(d->spinClickTimerId);
    1152                 d->spinClickTimerId = startTimer(d->spinClickTimerInterval - d->acceleration);
     1213                d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate - d->acceleration);
    11531214            }
    11541215        }
     
    12911352    : edit(0), type(QVariant::Invalid), spinClickTimerId(-1),
    12921353      spinClickTimerInterval(100), spinClickThresholdTimerId(-1), spinClickThresholdTimerInterval(-1),
    1293       buttonState(None), cachedText(QLatin1String("\x01")), cachedState(QValidator::Invalid),
    1294       pendingEmit(false), readOnly(false), wrapping(false),
     1354      effectiveSpinRepeatRate(1), buttonState(None), cachedText(QLatin1String("\x01")),
     1355      cachedState(QValidator::Invalid), pendingEmit(false), readOnly(false), wrapping(false),
    12951356      ignoreCursorPositionChanged(false), frame(true), accelerate(false), keyboardTracking(true),
    12961357      cleared(false), ignoreUpdateEdit(false), correctionMode(QAbstractSpinBox::CorrectToPreviousValue),
     
    15371598*/
    15381599
    1539 void QAbstractSpinBoxPrivate::updateState(bool up)
     1600void QAbstractSpinBoxPrivate::updateState(bool up, bool fromKeyboard /* = false */)
    15401601{
    15411602    Q_Q(QAbstractSpinBox);
     
    15461607                                  : QAbstractSpinBox::StepDownEnabled))) {
    15471608        spinClickThresholdTimerId = q->startTimer(spinClickThresholdTimerInterval);
    1548         buttonState = (up ? (Mouse | Up) : (Mouse | Down));
     1609        buttonState = (up ? Up : Down) | (fromKeyboard ? Keyboard : Mouse);
    15491610        q->stepBy(up ? 1 : -1);
     1611#ifndef QT_NO_ACCESSIBILITY
     1612        QAccessible::updateAccessibility(q, 0, QAccessible::ValueChanged);
     1613#endif
    15501614    }
    15511615}
     
    15681632    option->activeSubControls = QStyle::SC_None;
    15691633    option->buttonSymbols = d->buttonSymbols;
    1570     option->subControls = QStyle::SC_SpinBoxFrame;
     1634    option->subControls = QStyle::SC_SpinBoxFrame | QStyle::SC_SpinBoxEditField;
    15711635    if (d->buttonSymbols != QAbstractSpinBox::NoButtons) {
    15721636        option->subControls |= QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown;
     
    16961760void QAbstractSpinBoxPrivate::setRange(const QVariant &min, const QVariant &max)
    16971761{
     1762    Q_Q(QAbstractSpinBox);
     1763
    16981764    clearCache();
    16991765    minimum = min;
     
    17071773        updateEdit();
    17081774    }
     1775
     1776    q->updateGeometry();
    17091777}
    17101778
     
    17811849        QASBDEBUG() << "QAbstractSpinBoxPrivate::interpret() text '"
    17821850                    << edit->displayText()
    1783                     << "' >> '" << copy << "'"
    1784                     << "' >> '" << tmp << "'";
     1851                    << "' >> '" << copy << '\''
     1852                    << "' >> '" << tmp << '\'';
    17851853
    17861854        doInterpret = tmp != copy && (q->validate(tmp, pos) == QValidator::Acceptable);
     
    18321900        return QValidator::Acceptable;
    18331901
    1834     if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix))
     1902    if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix)) {
    18351903        input.prepend(dptr->prefix);
     1904        pos += dptr->prefix.length();
     1905    }
    18361906
    18371907    if (!dptr->suffix.isEmpty() && !input.endsWith(dptr->suffix))
Note: See TracChangeset for help on using the changeset viewer.