Simplify QAccessibleDial and make it inherit QAccessibleAbstractSlider.
This adds the value interface and removes the children of the dial. Change-Id: I47eac77c01dce36db077f553054ef37353242f77 Reviewed-on: http://codereview.qt-project.org/4821 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
This commit is contained in:
parent
a8dc1b15dc
commit
eddd87826e
@ -380,123 +380,18 @@ QAbstractSlider *QAccessibleAbstractSlider::abstractSlider() const
|
||||
#ifndef QT_NO_DIAL
|
||||
// ======================================= QAccessibleDial ======================================
|
||||
QAccessibleDial::QAccessibleDial(QWidget *widget)
|
||||
: QAccessibleWidget(widget, Dial)
|
||||
: QAccessibleAbstractSlider(widget, Dial)
|
||||
{
|
||||
Q_ASSERT(qobject_cast<QDial *>(widget));
|
||||
addControllingSignal(QLatin1String("valueChanged(int)"));
|
||||
}
|
||||
|
||||
QRect QAccessibleDial::rect(int child) const
|
||||
QString QAccessibleDial::text(Text textType, int) const
|
||||
{
|
||||
QRect rect;
|
||||
if (!dial()->isVisible())
|
||||
return rect;
|
||||
switch (child) {
|
||||
case Self:
|
||||
return QAccessibleWidget::rect(child);
|
||||
case SpeedoMeter: {
|
||||
// Mixture from qcommonstyle.cpp (focus rect).
|
||||
int width = dial()->width();
|
||||
int height = dial()->height();
|
||||
qreal radius = qMin(width, height) / 2.0;
|
||||
qreal delta = radius / 6.0;
|
||||
qreal dx = delta + (width - 2 * radius) / 2.0;
|
||||
qreal dy = delta + (height - 2 * radius) / 2.0;
|
||||
rect = QRect(int(dx), int(dy), int(radius * 2 - 2 * delta), int(radius * 2 - 2 * delta));
|
||||
if (dial()->notchesVisible()) {
|
||||
rect.translate(int(-radius / 6), int(-radius / 6));
|
||||
rect.setWidth(rect.width() + int(radius / 3));
|
||||
rect.setHeight(rect.height() + int(radius / 3));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SliderHandle: {
|
||||
// Mixture from qcommonstyle.cpp and qdial.cpp.
|
||||
int sliderValue = !dial()->invertedAppearance() ? dial()->value()
|
||||
: (dial()->maximum() - dial()->value());
|
||||
qreal angle = 0;
|
||||
if (dial()->maximum() == dial()->minimum()) {
|
||||
angle = Q_PI / 2;
|
||||
} else if (dial()->wrapping()) {
|
||||
angle = Q_PI * 3 / 2 - (sliderValue - dial()->minimum()) * 2 * Q_PI
|
||||
/ (dial()->maximum() - dial()->minimum());
|
||||
} else {
|
||||
angle = (Q_PI * 8 - (sliderValue - dial()->minimum()) * 10 * Q_PI
|
||||
/ (dial()->maximum() - dial()->minimum())) / 6;
|
||||
}
|
||||
|
||||
int width = dial()->rect().width();
|
||||
int height = dial()->rect().height();
|
||||
int radius = qMin(width, height) / 2;
|
||||
int xc = width / 2;
|
||||
int yc = height / 2;
|
||||
int bigLineSize = radius / 6;
|
||||
if (bigLineSize < 4)
|
||||
bigLineSize = 4;
|
||||
if (bigLineSize > radius / 2)
|
||||
bigLineSize = radius / 2;
|
||||
int len = radius - bigLineSize - 5;
|
||||
if (len < 5)
|
||||
len = 5;
|
||||
int back = len / 2;
|
||||
|
||||
QPolygonF arrow(3);
|
||||
arrow[0] = QPointF(0.5 + xc + len * qCos(angle),
|
||||
0.5 + yc - len * qSin(angle));
|
||||
arrow[1] = QPointF(0.5 + xc + back * qCos(angle + Q_PI * 5 / 6),
|
||||
0.5 + yc - back * qSin(angle + Q_PI * 5 / 6));
|
||||
arrow[2] = QPointF(0.5 + xc + back * qCos(angle - Q_PI * 5 / 6),
|
||||
0.5 + yc - back * qSin(angle - Q_PI * 5 / 6));
|
||||
rect = arrow.boundingRect().toRect();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return QRect();
|
||||
}
|
||||
|
||||
QPoint globalPos = dial()->mapToGlobal(QPoint(0,0));
|
||||
return QRect(globalPos.x() + rect.x(), globalPos.y() + rect.y(), rect.width(), rect.height());
|
||||
}
|
||||
|
||||
int QAccessibleDial::childCount() const
|
||||
{
|
||||
return SliderHandle;
|
||||
}
|
||||
|
||||
QString QAccessibleDial::text(Text textType, int child) const
|
||||
{
|
||||
if (textType == Value && child >= Self && child <= SliderHandle)
|
||||
if (textType == Value)
|
||||
return QString::number(dial()->value());
|
||||
if (textType == Name) {
|
||||
switch (child) {
|
||||
case Self:
|
||||
if (!widget()->accessibleName().isEmpty())
|
||||
return widget()->accessibleName();
|
||||
return QDial::tr("QDial");
|
||||
case SpeedoMeter:
|
||||
return QDial::tr("SpeedoMeter");
|
||||
case SliderHandle:
|
||||
return QDial::tr("SliderHandle");
|
||||
}
|
||||
}
|
||||
return QAccessibleWidget::text(textType, child);
|
||||
}
|
||||
|
||||
QAccessible::Role QAccessibleDial::role(int child) const
|
||||
{
|
||||
if (child == SpeedoMeter)
|
||||
return Slider;
|
||||
else if (child == SliderHandle)
|
||||
return Indicator;
|
||||
return QAccessibleWidget::role(child);
|
||||
}
|
||||
|
||||
QAccessible::State QAccessibleDial::state(int child) const
|
||||
{
|
||||
const State parentState = QAccessibleWidget::state(0);
|
||||
if (child == SliderHandle)
|
||||
return parentState | HotTracked;
|
||||
return parentState;
|
||||
return QAccessibleAbstractSlider::text(textType, 0);
|
||||
}
|
||||
|
||||
QVariant QAccessibleDial::invokeMethod(Method, int, const QVariantList &)
|
||||
|
@ -151,22 +151,12 @@ protected:
|
||||
#endif // QT_NO_SLIDER
|
||||
|
||||
#ifndef QT_NO_DIAL
|
||||
class QAccessibleDial : public QAccessibleWidget
|
||||
class QAccessibleDial : public QAccessibleAbstractSlider
|
||||
{
|
||||
public:
|
||||
explicit QAccessibleDial(QWidget *w);
|
||||
|
||||
enum DialElements {
|
||||
Self = 0,
|
||||
SpeedoMeter,
|
||||
SliderHandle
|
||||
};
|
||||
|
||||
int childCount() const;
|
||||
QRect rect(int child) const;
|
||||
QString text(Text textType, int child) const;
|
||||
Role role(int child) const;
|
||||
State state(int child) const;
|
||||
QVariant invokeMethod(Method method, int child, const QVariantList ¶ms);
|
||||
|
||||
protected:
|
||||
|
@ -845,11 +845,11 @@ void tst_QAccessibility::accessibleName()
|
||||
QString name = tr("Widget Name %1").arg(i);
|
||||
child->setAccessibleName(name);
|
||||
QAccessibleInterface *acc = QAccessible::queryAccessibleInterface(child);
|
||||
QCOMPARE(acc->text(QAccessible::Name, 0), name);
|
||||
QCOMPARE(acc->text(QAccessible::Name), name);
|
||||
|
||||
QString desc = tr("Widget Description %1").arg(i);
|
||||
child->setAccessibleDescription(desc);
|
||||
QCOMPARE(acc->text(QAccessible::Description, 0), desc);
|
||||
QCOMPARE(acc->text(QAccessible::Description), desc);
|
||||
|
||||
}
|
||||
|
||||
@ -2350,43 +2350,32 @@ void tst_QAccessibility::dialTest()
|
||||
{
|
||||
{
|
||||
QDial dial;
|
||||
dial.setValue(20);
|
||||
QCOMPARE(dial.value(), 20);
|
||||
dial.setMinimum(23);
|
||||
dial.setMaximum(121);
|
||||
dial.setValue(42);
|
||||
QCOMPARE(dial.value(), 42);
|
||||
dial.show();
|
||||
#if defined(Q_OS_UNIX)
|
||||
QCoreApplication::processEvents();
|
||||
QTest::qWait(100);
|
||||
#endif
|
||||
|
||||
QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&dial);
|
||||
QVERIFY(interface);
|
||||
|
||||
// Child count; 1 = SpeedoMeter, 2 = SliderHandle.
|
||||
QCOMPARE(interface->childCount(), 2);
|
||||
|
||||
QCOMPARE(interface->role(0), QAccessible::Dial);
|
||||
QCOMPARE(interface->role(1), QAccessible::Slider);
|
||||
QCOMPARE(interface->role(2), QAccessible::Indicator);
|
||||
QCOMPARE(interface->childCount(), 0);
|
||||
|
||||
QCOMPARE(interface->text(QAccessible::Value, 0), QString::number(dial.value()));
|
||||
QCOMPARE(interface->text(QAccessible::Value, 1), QString::number(dial.value()));
|
||||
QCOMPARE(interface->text(QAccessible::Value, 2), QString::number(dial.value()));
|
||||
QCOMPARE(interface->text(QAccessible::Name, 0), QLatin1String("QDial"));
|
||||
QCOMPARE(interface->text(QAccessible::Name, 1), QLatin1String("SpeedoMeter"));
|
||||
QCOMPARE(interface->text(QAccessible::Name, 2), QLatin1String("SliderHandle"));
|
||||
QCOMPARE(interface->text(QAccessible::Name, 3), QLatin1String(""));
|
||||
|
||||
QCOMPARE(interface->state(1), interface->state(0));
|
||||
QCOMPARE(interface->state(2), interface->state(0) | QAccessible::HotTracked);
|
||||
|
||||
// Rect
|
||||
QCOMPARE(interface->rect(0), dial.geometry());
|
||||
QVERIFY(interface->rect(1).isValid());
|
||||
QVERIFY(dial.geometry().contains(interface->rect(1)));
|
||||
QVERIFY(interface->rect(2).isValid());
|
||||
QVERIFY(interface->rect(1).contains(interface->rect(2)));
|
||||
QVERIFY(!interface->rect(3).isValid());
|
||||
QCOMPARE(interface->rect(), dial.geometry());
|
||||
|
||||
QAccessibleValueInterface *valueIface = interface->valueInterface();
|
||||
QVERIFY(valueIface != 0);
|
||||
QCOMPARE(valueIface->minimumValue().toInt(), dial.minimum());
|
||||
QCOMPARE(valueIface->maximumValue().toInt(), dial.maximum());
|
||||
QCOMPARE(valueIface->currentValue().toInt(), 42);
|
||||
dial.setValue(50);
|
||||
QCOMPARE(valueIface->currentValue().toInt(), dial.value());
|
||||
dial.setValue(0);
|
||||
QCOMPARE(valueIface->currentValue().toInt(), dial.value());
|
||||
dial.setValue(100);
|
||||
QCOMPARE(valueIface->currentValue().toInt(), dial.value());
|
||||
valueIface->setCurrentValue(77);
|
||||
QCOMPARE(77, dial.value());
|
||||
}
|
||||
QTestAccessibility::clearEvents();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user