1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the accessibility module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "rangecontrols.h"
34
#include <qscrollbar.h>
36
#include <qstyleoption.h>
38
QString Q_GUI_EXPORT qt_accStripAmp(const QString &text);
41
\class QAccessibleSpinBox qaccessiblewidget.h
42
\brief The QAccessibleSpinBox class implements the QAccessibleInterface for spinbox widgets.
45
\ingroup accessibility
49
\enum QAccessibleSpinBox::SpinBoxElements
51
This enum identifies the components of the spin box.
53
\value SpinBoxSelf The spin box as a whole
54
\value Editor The line edit sub-widget.
55
\value ValueUp The up sub-widget (i.e. the up arrow or + button)
56
\value ValueDown The down sub-widget (i.e. the down arrow or - button)
60
Constructs a QAccessibleSpinWidget object for \a w.
62
QAccessibleSpinBox::QAccessibleSpinBox(QWidget *w)
63
: QAccessibleWidget(w, SpinBox)
66
addControllingSignal("valueChanged(int)");
67
addControllingSignal("valueChanged(QString)");
71
Returns the underlying QSpinBox.
73
QSpinBox *QAccessibleSpinBox::spinBox() const
75
return qobject_cast<QSpinBox*>(object());
79
int QAccessibleSpinBox::childCount() const
85
QRect QAccessibleSpinBox::rect(int child) const
88
QStyleOptionComplex so;
89
so.rect = widget()->rect();
92
rect = widget()->style()->subControlRect(QStyle::CC_SpinBox, &so,
93
QStyle::SC_SpinBoxEditField, widget());
96
rect = widget()->style()->subControlRect(QStyle::CC_SpinBox, &so,
97
QStyle::SC_SpinBoxUp, widget());
100
rect = widget()->style()->subControlRect(QStyle::CC_SpinBox, &so,
101
QStyle::SC_SpinBoxDown, widget());
107
QPoint tl = widget()->mapToGlobal(QPoint(0, 0));
108
return QRect(tl.x() + rect.x(), tl.y() + rect.y(), rect.width(), rect.height());
112
int QAccessibleSpinBox::navigate(RelationFlag rel, int entry, QAccessibleInterface **target) const
116
if (entry) switch (rel) {
118
return entry <= childCount() ? entry : -1;
119
case QAccessible::Left:
120
return (entry == ValueUp || entry == ValueDown) ? Editor : -1;
121
case QAccessible::Right:
122
return entry == Editor ? ValueUp : -1;
123
case QAccessible::Up:
124
return entry == ValueDown ? ValueUp : -1;
125
case QAccessible::Down:
126
return entry == ValueUp ? ValueDown : -1;
130
return QAccessibleWidget::navigate(rel, entry, target);
134
QString QAccessibleSpinBox::text(Text t, int child) const
140
return QSpinBox::tr("More");
142
return QSpinBox::tr("Less");
146
if (child == Editor || child == SpinBoxSelf)
147
return spinBox()->text();
152
return QAccessibleWidget::text(t, 0);
156
QAccessible::Role QAccessibleSpinBox::role(int child) const
167
return QAccessibleWidget::role(child);
171
QAccessible::State QAccessibleSpinBox::state(int child) const
173
State state = QAccessibleWidget::state(child);
176
if (spinBox()->value() >= spinBox()->maximum())
177
state |= Unavailable;
180
if (spinBox()->value() <= spinBox()->minimum())
181
state |= Unavailable;
190
bool QAccessibleSpinBox::doAction(int action, int /*child*/, const QVariantList ¶ms)
192
if (!widget()->isEnabled())
195
/* // ### vohi - what's that code?
196
if (action == Press) switch(child) {
198
if (spinBox()->value() >= spinBox()->maxValue())
203
if (spinBox()->value() <= spinBox()->minValue())
205
spinBox()->stepDown();
211
return QAccessibleWidget::doAction(action, 0, params);
215
\class QAccessibleScrollBar qaccessiblewidget.h
216
\brief The QAccessibleScrollBar class implements the QAccessibleInterface for scroll bars.
219
\ingroup accessibility
223
\enum QAccessibleScrollBar::ScrollBarElements
225
This enum identifies the components of the scroll bar.
227
\value ScrollBarSelf The scroll bar as a whole.
228
\value LineUp The up arrow button.
229
\value PageUp The area between the position and the up arrow button.
230
\value Position The position marking rectangle.
231
\value PageDown The area between the position and the down arrow button.
232
\value LineDown The down arrow button.
236
Constructs a QAccessibleScrollBar object for \a w.
237
\a name is propagated to the QAccessibleWidget constructor.
239
QAccessibleScrollBar::QAccessibleScrollBar(QWidget *w, const QString &name)
240
: QAccessibleWidget(w, ScrollBar, name)
242
Q_ASSERT(scrollBar());
243
addControllingSignal("valueChanged(int)");
246
/*! Returns the scroll bar. */
247
QScrollBar *QAccessibleScrollBar::scrollBar() const
249
return qobject_cast<QScrollBar*>(object());
253
QRect QAccessibleScrollBar::rect(int child) const
256
QStyleOptionSlider option;
257
QRect srect = scrollBar()->style()->subControlRect(QStyle::CC_Slider, &option,
258
QStyle::SC_SliderHandle, scrollBar());
259
int sz = scrollBar()->style()->pixelMetric(QStyle::PM_ScrollBarExtent, &option, scrollBar());
262
rect = QRect(0, 0, sz, sz);
265
if (scrollBar()->orientation() == Qt::Vertical)
266
rect = QRect(0, sz, sz, srect.y() - sz);
268
rect = QRect(sz, 0, srect.x() - sz, sz);
274
if (scrollBar()->orientation() == Qt::Vertical)
275
rect = QRect(0, srect.bottom(), sz, scrollBar()->rect().height() - srect.bottom() - sz);
277
rect = QRect(srect.right(), 0, scrollBar()->rect().width() - srect.right() - sz, sz) ;
280
if (scrollBar()->orientation() == Qt::Vertical)
281
rect = QRect(0, scrollBar()->rect().height() - sz, sz, sz);
283
rect = QRect(scrollBar()->rect().width() - sz, 0, sz, sz);
286
return QAccessibleWidget::rect(child);
289
QPoint tp = scrollBar()->mapToGlobal(QPoint(0,0));
290
return QRect(tp.x() + rect.x(), tp.y() + rect.y(), rect.width(), rect.height());
294
int QAccessibleScrollBar::childCount() const
300
QString QAccessibleScrollBar::text(Text t, int child) const
304
if (!child || child == Position)
305
return QString::number(scrollBar()->value());
310
return QScrollBar::tr("Line up");
312
return QScrollBar::tr("Page up");
314
return QScrollBar::tr("Position");
316
return QScrollBar::tr("Page down");
318
return QScrollBar::tr("Line down");
324
return QAccessibleWidget::text(t, child);
328
QAccessible::Role QAccessibleScrollBar::role(int child) const
344
bool QAccessibleScrollBar::doAction(int /*action*/, int /*child*/, const QVariantList &/*params*/)
347
if (action == Press) switch (child) {
349
scrollBar()->subtractLine();
352
scrollBar()->subtractPage();
355
scrollBar()->addPage();
358
scrollBar()->addLine();
366
\class QAccessibleSlider qaccessiblewidget.h
367
\brief The QAccessibleSlider class implements the QAccessibleInterface for sliders.
370
\ingroup accessibility
374
\enum QAccessibleSlider::SliderElements
376
This enum identifies the components of the slider.
378
\value SliderSelf The slider as a whole.
379
\value PageLeft The area to the left of the position.
380
\value Position The position indicator.
381
\value PageRight The area to the right of the position.
385
Constructs a QAccessibleScrollBar object for \a w.
386
\a name is propagated to the QAccessibleWidget constructor.
388
QAccessibleSlider::QAccessibleSlider(QWidget *w, const QString &name)
389
: QAccessibleWidget(w, Slider, name)
392
addControllingSignal("valueChanged(int)");
395
/*! Returns the slider. */
396
QSlider *QAccessibleSlider::slider() const
398
return qobject_cast<QSlider*>(object());
402
QRect QAccessibleSlider::rect(int child) const
405
QStyleOptionSlider option;
406
option.init(slider());
407
option.orientation = slider()->orientation();
408
QRect srect = slider()->style()->subControlRect(QStyle::CC_Slider, &option,
409
QStyle::SC_SliderHandle, slider());
412
if (slider()->orientation() == Qt::Vertical)
413
rect = QRect(0, 0, slider()->width(), srect.y());
415
rect = QRect(0, 0, srect.x(), slider()->height());
421
if (slider()->orientation() == Qt::Vertical)
422
rect = QRect(0, srect.y() + srect.height(), slider()->width(), slider()->height()- srect.y() - srect.height());
424
rect = QRect(srect.x() + srect.width(), 0, slider()->width() - srect.x() - srect.width(), slider()->height());
427
return QAccessibleWidget::rect(child);
430
QPoint tp = slider()->mapToGlobal(QPoint(0,0));
431
return QRect(tp.x() + rect.x(), tp.y() + rect.y(), rect.width(), rect.height());
435
int QAccessibleSlider::childCount() const
441
QString QAccessibleSlider::text(Text t, int child) const
445
if (!child || child == 2)
446
return QString::number(slider()->value());
451
return slider()->orientation() == Qt::Horizontal ?
452
QSlider::tr("Page left") : QSlider::tr("Page up");
454
return QSlider::tr("Position");
456
return slider()->orientation() == Qt::Horizontal ?
457
QSlider::tr("Page right") : QSlider::tr("Page down");
463
return QAccessibleWidget::text(t, child);
467
QAccessible::Role QAccessibleSlider::role(int child) const
481
\fn int QAccessibleSlider::defaultAction(int child) const
483
Returns the default action for the given \a child. The base class
484
implementation returns 0.
486
int QAccessibleSlider::defaultAction(int /*child*/) const
502
QString QAccessibleSlider::actionText(int /*action*/, Text /*t*/, int /*child*/) const
508
bool QAccessibleSlider::doAction(int /*action*/, int /*child*/, const QVariantList &/*params*/)
513
if (action == SetFocus) {
514
slider()->setFocus();
519
if (action == Press) {
520
slider()->subtractPage();
525
if (action == Increase) {
528
} else if (action == Decrease) {
529
slider()->subtractLine();
534
if (action == Press) {