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

📄 qabstractslider.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** 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 <qapplication.h>#include "qabstractslider.h"#include "qevent.h"#include "qabstractslider_p.h"#include "qdebug.h"#ifndef QT_NO_ACCESSIBILITY#include "qaccessible.h"#endif#include <limits.h>/*!    \class QAbstractSlider    \brief The QAbstractSlider class provides an integer value within a range.    \ingroup abstractwidgets    The class is designed as a common super class for widgets like    QScrollBar, QSlider and QDial.    Here are the main properties of the class:    \list 1    \i \l value: The bounded integer that QAbstractSlider maintains.    \i \l minimum: The lowest possible value.    \i \l maximum: The highest possible value.    \i \l singleStep: The smaller of two natural steps that an    abstract sliders provides and typically corresponds to the user    pressing an arrow key.    \i \l pageStep: The larger of two natural steps that an abstract    slider provides and typically corresponds to the user pressing    PageUp or PageDown.    \i \l tracking: Whether slider tracking is enabled.    \i \l sliderPosition: The current position of the slider. If \l    tracking is enabled (the default), this is identical to \l value.    \endlist    Unity (1) may be viewed as a third step size. setValue() lets you    set the current value to any integer in the allowed range, not    just minimum() + \e n * singleStep() for integer values of \e n.    Some widgets may allow the user to set any value at all; others    may just provide multiples of singleStep() or pageStep().    QAbstractSlider emits a comprehensive set of signals:    \table    \header \i Signal \i Emitted when    \row \i \l valueChanged()         \i the value has changed. The \l tracking            determines whether this signal is emitted during user            interaction.    \row \i \l sliderPressed()         \i the user starts to drag the slider.    \row \i \l sliderMoved()         \i the user drags the slider.    \row \i \l sliderReleased()         \i the user releases the slider.    \row \i \l actionTriggered()         \i a slider action was triggerd.    \row \i \l rangeChanged()         \i a the range has changed.    \endtable    QAbstractSlider provides a virtual sliderChange() function that is    well suited for updating the on-screen representation of    sliders. By calling triggerAction(), subclasses trigger slider    actions. Two helper functions QStyle::sliderPositionFromValue() and    QStyle::sliderValueFromPosition() help subclasses and styles to map    screen coordinates to logical range values.    \sa QAbstractSpinBox, QSlider, QDial, QScrollBar, {Sliders Example}*//*!    \enum QAbstractSlider::SliderAction    \value SliderNoAction    \value SliderSingleStepAdd    \value SliderSingleStepSub    \value SliderPageStepAdd    \value SliderPageStepSub    \value SliderToMinimum    \value SliderToMaximum    \value SliderMove*//*!    \fn void QAbstractSlider::valueChanged(int value)    This signal is emitted when the slider value has changed, with the    new slider \a value as argument.*//*!    \fn void QAbstractSlider::sliderPressed()    This signal is emitted when the user presses the slider with the    mouse, or programmatically when setSliderDown(true) is called.    \sa sliderReleased(), sliderMoved(), isSliderDown()*//*!    \fn void QAbstractSlider::sliderMoved(int value)    This signal is emitted when sliderDown is true and the slider moves. This    usually happens when the user is dragging the slider. The \a value    is the new slider position.    This signal is emitted even when tracking is turned off.    \sa setTracking(), valueChanged(), isSliderDown(),    sliderPressed(), sliderReleased()*//*!    \fn void QAbstractSlider::sliderReleased()    This signal is emitted when the user releases the slider with the    mouse, or programmatically when setSliderDown(false) is called.    \sa sliderPressed() sliderMoved() sliderDown*//*!    \fn void QAbstractSlider::rangeChanged(int min, int max)    This signal is emitted when the slider range has changed, with \a    min being the new minimum, and \a max being the new maximum.    \sa minimum, maximum*//*!    \fn void QAbstractSlider::actionTriggered(int action)    This signal is emitted when the slider action \a action is    triggered. Actions are \l SliderSingleStepAdd, \l    SliderSingleStepSub, \l SliderPageStepAdd, \l SliderPageStepSub,    \l SliderToMinimum, \l SliderToMaximum, and \l SliderMove.    When the signal is emitted, the \l sliderPosition has been    adjusted according to the action, but the \l value has not yet    been propagated (meaning the valueChanged() signal was not yet    emitted), and the visual display has not been updated. In slots    connected to this signal you can thus safely adjust any action by    calling setSliderPosition() yourself, based on both the action and    the slider's value.    \sa triggerAction()*//*!    \enum QAbstractSlider::SliderChange    \value SliderRangeChange    \value SliderOrientationChange    \value SliderStepsChange    \value SliderValueChange*/QAbstractSliderPrivate::QAbstractSliderPrivate()    : minimum(0), maximum(99), singleStep(1), pageStep(10),      value(0), position(0), pressValue(-1), tracking(true), blocktracking(false), pressed(false),      invertedAppearance(false), invertedControls(false),      orientation(Qt::Horizontal), repeatAction(QAbstractSlider::SliderNoAction){}QAbstractSliderPrivate::~QAbstractSliderPrivate(){}/*!    Sets the slider's minimum to \a min and its maximum to \a max.    If \a max is smaller than \a min, \a min becomes the only legal    value.    \sa minimum maximum*/void QAbstractSlider::setRange(int min, int max){    Q_D(QAbstractSlider);    int oldMin = d->minimum;    int oldMax = d->maximum;    d->minimum = min;    d->maximum = qMax(min, max);    if (oldMin != d->minimum || oldMax != d->maximum) {        sliderChange(SliderRangeChange);        emit rangeChanged(d->minimum, d->maximum);        setValue(d->value); // re-bound    }}void QAbstractSliderPrivate::setSteps(int single, int page){    Q_Q(QAbstractSlider);    singleStep = qAbs(single);    pageStep = qAbs(page);    q->sliderChange(QAbstractSlider::SliderStepsChange);}/*!    Constructs an abstract slider.    The \a parent arguments is sent to the QWidget constructor.    The \l minimum defaults to 0, the \l maximum to 99, with a \l    singleStep size of 1 and a \l pageStep size of 10, and an initial    \l value of 0.*/QAbstractSlider::QAbstractSlider(QWidget *parent)    :QWidget(*new QAbstractSliderPrivate, parent, 0){}/*! \internal */QAbstractSlider::QAbstractSlider(QAbstractSliderPrivate &dd, QWidget *parent)    :QWidget(dd, parent, 0){}/*!    Destroys the slider.*/QAbstractSlider::~QAbstractSlider(){}/*!    \property QAbstractSlider::orientation    \brief the orientation of the slider    The orientation must be \l Qt::Vertical (the default) or \l    Qt::Horizontal.*/void QAbstractSlider::setOrientation(Qt::Orientation orientation){    Q_D(QAbstractSlider);    if (d->orientation == orientation)        return;    d->orientation = orientation;    if (!testAttribute(Qt::WA_WState_OwnSizePolicy)) {        QSizePolicy sp = sizePolicy();        sp.transpose();        setSizePolicy(sp);        setAttribute(Qt::WA_WState_OwnSizePolicy, false);    }    update();    updateGeometry();}Qt::Orientation QAbstractSlider::orientation() const{    Q_D(const QAbstractSlider);    return d->orientation;}/*!    \property QAbstractSlider::minimum    \brief the sliders's minimum value    When setting this property, the \l maximum is adjusted if    necessary to ensure that the range remains valid. Also the    slider's current value is adjusted to be within the new range.*/void QAbstractSlider::setMinimum(int min){    Q_D(QAbstractSlider);    setRange(min, qMax(d->maximum, min));}int QAbstractSlider::minimum() const{    Q_D(const QAbstractSlider);    return d->minimum;}/*!    \property QAbstractSlider::maximum    \brief the slider's maximum value    When setting this property, the \l minimum is adjusted if    necessary to ensure that the range remains valid.  Also the    slider's current value is adjusted to be within the new range.*/void QAbstractSlider::setMaximum(int max){    Q_D(QAbstractSlider);    setRange(qMin(d->minimum, max), max);}int QAbstractSlider::maximum() const{    Q_D(const QAbstractSlider);    return d->maximum;}/*!    \property QAbstractSlider::singleStep    \brief the single step.    The smaller of two natural steps that an    abstract sliders provides and typically corresponds to the user    pressing an arrow key.    \sa pageStep*/void QAbstractSlider::setSingleStep(int step){    Q_D(QAbstractSlider);    d->setSteps(step, d->pageStep);}int QAbstractSlider::singleStep() const{    Q_D(const QAbstractSlider);    return d->singleStep;}/*!    \property QAbstractSlider::pageStep    \brief the page step.    The larger of two natural steps that an abstract slider provides    and typically corresponds to the user pressing PageUp or PageDown.    \sa singleStep*/void QAbstractSlider::setPageStep(int step){    Q_D(QAbstractSlider);    d->setSteps(d->singleStep, step);}int QAbstractSlider::pageStep() const{    Q_D(const QAbstractSlider);    return d->pageStep;}/*!    \property QAbstractSlider::tracking    \brief whether slider tracking is enabled    If tracking is enabled (the default), the slider emits the    valueChanged() signal while the slider is being dragged. If    tracking is disabled, the slider emits the valueChanged() signal    only when the user releases the slider.    \sa sliderDown*/void QAbstractSlider::setTracking(bool enable){    Q_D(QAbstractSlider);    d->tracking = enable;}bool QAbstractSlider::hasTracking() const{    Q_D(const QAbstractSlider);    return d->tracking;}/*!    \property QAbstractSlider::sliderDown    \brief whether the slider is pressed down.    The property is set by subclasses in order to let the abstract    slider know whether or not \l tracking has any effect.    Changing the slider down property emits the sliderPressed() and    sliderReleased() signals.*/void QAbstractSlider::setSliderDown(bool down){    Q_D(QAbstractSlider);    bool doEmit = d->pressed != down;    d->pressed = down;    if (doEmit) {        if (down)            emit sliderPressed();

⌨️ 快捷键说明

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