1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the documentation of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
20 ** * Neither the name of The Qt Company Ltd nor the names of its
21 ** contributors may be used to endorse or promote products derived
22 ** from this software without specific prior written permission.
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
43 QAccessibleSlider::QAccessibleSlider(QWidget *w)
44 : QAccessibleAbstractSlider(w)
47 addControllingSignal(QLatin1String("valueChanged(int)"));
51 QSlider *QAccessibleSlider::slider() const
53 return qobject_cast<QSlider*>(object());
57 QRect QAccessibleSlider::rect(int child) const
61 if (!slider()->isVisible())
63 const QStyleOptionSlider option = qt_qsliderStyleOption(slider());
64 QRect srect = slider()->style()->subControlRect(QStyle::CC_Slider, &option,
65 QStyle::SC_SliderHandle, slider());
70 if (slider()->orientation() == Qt::Vertical)
71 rect = QRect(0, 0, slider()->width(), srect.y());
73 rect = QRect(0, 0, srect.x(), slider()->height());
79 if (slider()->orientation() == Qt::Vertical)
80 rect = QRect(0, srect.y() + srect.height(), slider()->width(), slider()->height()- srect.y() - srect.height());
82 rect = QRect(srect.x() + srect.width(), 0, slider()->width() - srect.x() - srect.width(), slider()->height());
85 return QAccessibleAbstractSlider::rect(child);
89 QPoint tp = slider()->mapToGlobal(QPoint(0,0));
90 return QRect(tp.x() + rect.x(), tp.y() + rect.y(), rect.width(), rect.height());
94 int QAccessibleSlider::childCount() const
96 if (!slider()->isVisible())
102 QString QAccessibleSlider::text(Text t, int child) const
104 if (!slider()->isVisible())
108 if (!child || child == 2)
109 return QString::number(slider()->value());
114 return slider()->orientation() == Qt::Horizontal ?
115 QSlider::tr("Page left") : QSlider::tr("Page up");
117 return QSlider::tr("Position");
119 return slider()->orientation() == Qt::Horizontal ?
120 QSlider::tr("Page right") : QSlider::tr("Page down");
126 return QAccessibleAbstractSlider::text(t, child);
131 QAccessible::Role QAccessibleSlider::role(int child) const
146 QAccessible::State QAccessibleSlider::state(int child) const
148 const State parentState = QAccessibleAbstractSlider::state(0);
154 // Inherit the Invisible state from parent.
155 State state = parentState & QAccessible::Invisible;
157 // Disable left/right if we are at the minimum/maximum.
158 const QSlider * const slider = QAccessibleSlider::slider();
162 if (slider->value() <= slider->minimum())
163 state |= Unavailable;
166 if (slider->value() >= slider->maximum())
167 state |= Unavailable;
178 int QAccessibleSlider::defaultAction(int child) const
192 // Name, Description, Value, Help, Accelerator
193 static const char * const actionTexts[][5] =
195 {"Press", "Decreases the value of the slider", "", "", "Ctrl+L"},
196 {"Press", "Increaces the value of the slider", "", "", "Ctrl+R"}
199 QString QAccessibleSlider::actionText(int action, Text text, int child) const
201 if (action != Press || child < 1 || child > 2)
202 return QAccessibleAbstractSlider::actionText(action, text, child);
204 return actionTexts[child - 1][t];
207 bool QAccessibleSlider::doAction(int action, int child)
209 if (action != Press || child < 1 || child > 2)
212 if (child == PageLeft)
213 slider()->setValue(slider()->value() - slider()->pageStep());
215 slider()->setValue(slider()->value() + slider()->pageStep());
218 QAccessibleAbstractSlider::QAccessibleAbstractSlider(QWidget *w, Role r)
219 : QAccessibleWidgetEx(w, r)
221 Q_ASSERT(qobject_cast<QAbstractSlider *>(w));
224 QVariant QAccessibleAbstractSlider::invokeMethodEx(Method method, int child, const QVariantList ¶ms)
227 case ListSupportedMethods: {
228 QSet<QAccessible::Method> set;
229 set << ListSupportedMethods;
230 return QVariant::fromValue(set | qvariant_cast<QSet<QAccessible::Method> >(
231 QAccessibleWidgetEx::invokeMethodEx(method, child, params)));
234 return QAccessibleWidgetEx::invokeMethodEx(method, child, params);
238 QVariant QAccessibleAbstractSlider::currentValue()
240 return abstractSlider()->value();
243 void QAccessibleAbstractSlider::setCurrentValue(const QVariant &value)
245 abstractSlider()->setValue(value.toInt());
248 QVariant QAccessibleAbstractSlider::maximumValue()
250 return abstractSlider()->maximum();
253 QVariant QAccessibleAbstractSlider::minimumValue()
255 return abstractSlider()->minimum();
258 QAbstractSlider *QAccessibleAbstractSlider::abstractSlider() const
260 return static_cast<QAbstractSlider *>(object());