📄 rangecontrols.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the plugins 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 "rangecontrols.h"#include <qslider.h>#include <qdial.h>#include <qspinbox.h>#include <qscrollbar.h>#include <qstyle.h>#include <qstyleoption.h>#include <qdebug.h>#include <qglobal.h>#include <QDoubleSpinBox>#include <QDial>#include <private/qmath_p.h>#ifndef QT_NO_ACCESSIBILITYextern QString Q_GUI_EXPORT qt_accStripAmp(const QString &text);#ifndef QT_NO_SCROLLBARextern QStyleOptionSlider Q_GUI_EXPORT qt_qscrollbarStyleOption(QScrollBar *scrollBar);#endif#ifndef QT_NO_SLIDERextern QStyleOptionSlider Q_GUI_EXPORT qt_qsliderStyleOption(QSlider *slider);#endif#ifndef QT_NO_SPINBOXQAccessibleAbstractSpinBox::QAccessibleAbstractSpinBox(QWidget *w): QAccessibleWidgetEx(w, SpinBox){ Q_ASSERT(abstractSpinBox());}/*! Returns the underlying QAbstractSpinBox.*/QAbstractSpinBox *QAccessibleAbstractSpinBox::abstractSpinBox() const{ return qobject_cast<QAbstractSpinBox*>(object());}/*! \reimp */int QAccessibleAbstractSpinBox::childCount() const{ if (!abstractSpinBox()->isVisible()) return 0; return ValueDown;}/*! \reimp */QRect QAccessibleAbstractSpinBox::rect(int child) const{ QRect rect; if (!abstractSpinBox()->isVisible()) return rect; QStyleOptionSpinBox so; so.rect = widget()->rect(); switch(child) { case Editor: rect = widget()->style()->subControlRect(QStyle::CC_SpinBox, &so, QStyle::SC_SpinBoxEditField, widget()); break; case ValueUp: rect = widget()->style()->subControlRect(QStyle::CC_SpinBox, &so, QStyle::SC_SpinBoxUp, widget()); break; case ValueDown: rect = widget()->style()->subControlRect(QStyle::CC_SpinBox, &so, QStyle::SC_SpinBoxDown, widget()); break; default: rect = so.rect; break; } QPoint tl = widget()->mapToGlobal(QPoint(0, 0)); return QRect(tl.x() + rect.x(), tl.y() + rect.y(), rect.width(), rect.height());}/*! \reimp */int QAccessibleAbstractSpinBox::navigate(RelationFlag rel, int entry, QAccessibleInterface **target) const{ *target = 0; if (entry) switch (rel) { case Child: return entry <= childCount() ? entry : -1; case QAccessible::Left: return (entry == ValueUp || entry == ValueDown) ? Editor : -1; case QAccessible::Right: return entry == Editor ? ValueUp : -1; case QAccessible::Up: return entry == ValueDown ? ValueUp : -1; case QAccessible::Down: return entry == ValueUp ? ValueDown : -1; default: break; } return QAccessibleWidgetEx::navigate(rel, entry, target);}/*! \reimp */QString QAccessibleAbstractSpinBox::text(Text t, int child) const{ if (!abstractSpinBox()->isVisible()) return QString(); switch (t) { case Name: switch (child) { case ValueUp: return QSpinBox::tr("More"); case ValueDown: return QSpinBox::tr("Less"); } break; case Value: if (child == Editor || child == SpinBoxSelf) return abstractSpinBox()->text(); break; default: break; } return QAccessibleWidgetEx::text(t, 0);}/*! \reimp */QAccessible::Role QAccessibleAbstractSpinBox::role(int child) const{ switch(child) { case Editor: return EditableText; case ValueUp: case ValueDown: return PushButton; default: break; } return QAccessibleWidgetEx::role(child);}/*! \reimp */bool QAccessibleAbstractSpinBox::doAction(int action, int child, const QVariantList ¶ms){ if (!widget()->isEnabled()) return false; if (action == Press) { switch(child) { case ValueUp: abstractSpinBox()->stepUp(); return true; case ValueDown: abstractSpinBox()->stepDown(); return true; default: break; } } return QAccessibleWidgetEx::doAction(action, 0, params);}QVariant QAccessibleAbstractSpinBox::currentValue(){ QVariant result = abstractSpinBox()->property("value"); QVariant::Type type = result.type(); // IA2 only allows numeric types if (type == QVariant::Int || type == QVariant::UInt || type == QVariant::LongLong || type == QVariant::ULongLong || type == QVariant::Double) return result; return QVariant();}void QAccessibleAbstractSpinBox::setCurrentValue(const QVariant &value){ abstractSpinBox()->setProperty("setValue", value);}QVariant QAccessibleAbstractSpinBox::maximumValue(){ return abstractSpinBox()->property("maximum");}QVariant QAccessibleAbstractSpinBox::minimumValue(){ return abstractSpinBox()->property("minimum");}QVariant QAccessibleAbstractSpinBox::invokeMethodEx(Method method, int child, const QVariantList ¶ms){ switch (method) { case ListSupportedMethods: { QSet<QAccessible::Method> set; set << ListSupportedMethods; return qVariantFromValue(set | qvariant_cast<QSet<QAccessible::Method> >( QAccessibleWidgetEx::invokeMethodEx(method, child, params))); } default: return QAccessibleWidgetEx::invokeMethodEx(method, child, params); }}/*! \class QAccessibleSpinBox qaccessiblewidget.h \brief The QAccessibleSpinBox class implements the QAccessibleInterface for spinbox widgets. \internal \ingroup accessibility*//*! \enum QAccessibleAbstractSpinBox::SpinBoxElements This enum identifies the components of the spin box. \value SpinBoxSelf The spin box as a whole \value Editor The line edit sub-widget. \value ValueUp The up sub-widget (i.e. the up arrow or + button) \value ValueDown The down sub-widget (i.e. the down arrow or - button)*//*! Constructs a QAccessibleSpinWidget object for \a w.*/QAccessibleSpinBox::QAccessibleSpinBox(QWidget *w): QAccessibleAbstractSpinBox(w){ Q_ASSERT(spinBox()); addControllingSignal(QLatin1String("valueChanged(int)")); addControllingSignal(QLatin1String("valueChanged(QString)"));}/*! Returns the underlying QSpinBox.*/QSpinBox *QAccessibleSpinBox::spinBox() const{ return qobject_cast<QSpinBox*>(object());}/*! \reimp */QAccessible::State QAccessibleSpinBox::state(int child) const{ State state = QAccessibleAbstractSpinBox::state(child); switch(child) { case ValueUp: if (spinBox()->value() >= spinBox()->maximum()) state |= Unavailable; return state; case ValueDown: if (spinBox()->value() <= spinBox()->minimum()) state |= Unavailable; return state; default: break; } return state;}/*! \reimp */bool QAccessibleSpinBox::doAction(int action, int child, const QVariantList ¶ms){ if (!widget()->isEnabled()) return false; if (action == Press) { switch(child) { case ValueUp: if (spinBox()->value() >= spinBox()->maximum()) return false; spinBox()->stepUp(); return true; case ValueDown: if (spinBox()->value() <= spinBox()->minimum()) return false; spinBox()->stepDown(); return true; default: break; } } return QAccessibleAbstractSpinBox::doAction(action, 0, params);}// ================================== QAccessibleDoubleSpinBox ==================================QAccessibleDoubleSpinBox::QAccessibleDoubleSpinBox(QWidget *widget) : QAccessibleWidgetEx(widget, SpinBox){ Q_ASSERT(qobject_cast<QDoubleSpinBox *>(widget)); addControllingSignal(QLatin1String("valueChanged(double)")); addControllingSignal(QLatin1String("valueChanged(QString)"));}/*! Returns the underlying QDoubleSpinBox.*/QDoubleSpinBox *QAccessibleDoubleSpinBox::doubleSpinBox() const{ return static_cast<QDoubleSpinBox*>(object());}/*! \reimp */int QAccessibleDoubleSpinBox::childCount() const{ if (!doubleSpinBox()->isVisible()) return 0; return ValueDown;}/*! \reimp */QRect QAccessibleDoubleSpinBox::rect(int child) const{ QRect rect; if (!doubleSpinBox()->isVisible()) return rect; QStyleOptionSpinBox spinBoxOption; spinBoxOption.initFrom(doubleSpinBox()); switch (child) { case Editor: rect = doubleSpinBox()->style()->subControlRect(QStyle::CC_SpinBox, &spinBoxOption, QStyle::SC_SpinBoxEditField, doubleSpinBox()); break; case ValueUp: rect = doubleSpinBox()->style()->subControlRect(QStyle::CC_SpinBox, &spinBoxOption, QStyle::SC_SpinBoxUp, doubleSpinBox()); break; case ValueDown: rect = doubleSpinBox()->style()->subControlRect(QStyle::CC_SpinBox, &spinBoxOption, QStyle::SC_SpinBoxDown, doubleSpinBox()); break; default: rect = spinBoxOption.rect; break; } const QPoint globalPos = doubleSpinBox()->mapToGlobal(QPoint(0, 0)); return QRect(globalPos.x() + rect.x(), globalPos.y() + rect.y(), rect.width(), rect.height());}/*! \reimp */int QAccessibleDoubleSpinBox::navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const{ if (entry <= 0) return QAccessibleWidgetEx::navigate(relation, entry, target); *target = 0; switch (relation) { case Child: return entry <= childCount() ? entry : -1; case QAccessible::Left: return (entry == ValueUp || entry == ValueDown) ? Editor : -1; case QAccessible::Right: return entry == Editor ? ValueUp : -1; case QAccessible::Up: return entry == ValueDown ? ValueUp : -1; case QAccessible::Down: return entry == ValueUp ? ValueDown : -1; default: break; } return QAccessibleWidgetEx::navigate(relation, entry, target);}QVariant QAccessibleDoubleSpinBox::invokeMethodEx(QAccessible::Method, int, const QVariantList &){ return QVariant();}/*! \reimp */QString QAccessibleDoubleSpinBox::text(Text textType, int child) const{ if (!doubleSpinBox()->isVisible()) return QString(); switch (textType) { case Name: if (child == ValueUp) return QDoubleSpinBox::tr("More"); else if (child == ValueDown) return QDoubleSpinBox::tr("Less"); break; case Value: if (child == Editor || child == SpinBoxSelf) return doubleSpinBox()->textFromValue(doubleSpinBox()->value()); break; default: break; } return QAccessibleWidgetEx::text(textType, 0);}/*! \reimp */QAccessible::Role QAccessibleDoubleSpinBox::role(int child) const{ switch (child) { case Editor: return EditableText; case ValueUp: case ValueDown: return PushButton; default: break; } return QAccessibleWidgetEx::role(child);}/*! \reimp */QAccessible::State QAccessibleDoubleSpinBox::state(int child) const{ State state = QAccessibleWidgetEx::state(child); switch (child) { case ValueUp: if (doubleSpinBox()->value() >= doubleSpinBox()->maximum()) state |= Unavailable; break; case ValueDown: if (doubleSpinBox()->value() <= doubleSpinBox()->minimum()) state |= Unavailable; break; default: break; } return state;}#endif // QT_NO_SPINBOX#ifndef QT_NO_SCROLLBAR/*! \class QAccessibleScrollBar qaccessiblewidget.h \brief The QAccessibleScrollBar class implements the QAccessibleInterface for scroll bars. \internal \ingroup accessibility*//*! \enum QAccessibleScrollBar::ScrollBarElements This enum identifies the components of the scroll bar. \value ScrollBarSelf The scroll bar as a whole. \value LineUp The up arrow button. \value PageUp The area between the position and the up arrow button. \value Position The position marking rectangle. \value PageDown The area between the position and the down arrow button. \value LineDown The down arrow button.*//*! Constructs a QAccessibleScrollBar object for \a w. \a name is propagated to the QAccessibleWidgetEx constructor.*/QAccessibleScrollBar::QAccessibleScrollBar(QWidget *w): QAccessibleAbstractSlider(w, ScrollBar){ Q_ASSERT(scrollBar()); addControllingSignal(QLatin1String("valueChanged(int)"));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -