~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/plugins/accessible/widgets/rangecontrols.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the accessibility module of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "rangecontrols.h"
 
30
 
 
31
#include <qslider.h>
 
32
#include <qdial.h>
 
33
#include <qspinbox.h>
 
34
#include <qscrollbar.h>
 
35
#include <qstyle.h>
 
36
#include <qstyleoption.h>
 
37
 
 
38
QString Q_GUI_EXPORT qt_accStripAmp(const QString &text);
 
39
 
 
40
/*!
 
41
  \class QAccessibleSpinBox qaccessiblewidget.h
 
42
  \brief The QAccessibleSpinBox class implements the QAccessibleInterface for spinbox widgets.
 
43
  \internal
 
44
 
 
45
  \ingroup accessibility
 
46
*/
 
47
 
 
48
/*!
 
49
    \enum QAccessibleSpinBox::SpinBoxElements
 
50
 
 
51
    This enum identifies the components of the spin box.
 
52
 
 
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)
 
57
*/
 
58
 
 
59
/*!
 
60
  Constructs a QAccessibleSpinWidget object for \a w.
 
61
*/
 
62
QAccessibleSpinBox::QAccessibleSpinBox(QWidget *w)
 
63
: QAccessibleWidget(w, SpinBox)
 
64
{
 
65
    Q_ASSERT(spinBox());
 
66
    addControllingSignal("valueChanged(int)");
 
67
    addControllingSignal("valueChanged(QString)");
 
68
}
 
69
 
 
70
/*!
 
71
    Returns the underlying QSpinBox.
 
72
*/
 
73
QSpinBox *QAccessibleSpinBox::spinBox() const
 
74
{
 
75
    return qobject_cast<QSpinBox*>(object());
 
76
}
 
77
 
 
78
/*! \reimp */
 
79
int QAccessibleSpinBox::childCount() const
 
80
{
 
81
    return ValueDown;
 
82
}
 
83
 
 
84
/*! \reimp */
 
85
QRect QAccessibleSpinBox::rect(int child) const
 
86
{
 
87
    QRect rect;
 
88
    QStyleOptionComplex so;
 
89
    so.rect = widget()->rect();
 
90
    switch(child) {
 
91
    case Editor:
 
92
        rect = widget()->style()->subControlRect(QStyle::CC_SpinBox, &so,
 
93
                                                 QStyle::SC_SpinBoxEditField, widget());
 
94
        break;
 
95
    case ValueUp:
 
96
        rect = widget()->style()->subControlRect(QStyle::CC_SpinBox, &so,
 
97
                                                 QStyle::SC_SpinBoxUp, widget());
 
98
        break;
 
99
    case ValueDown:
 
100
        rect = widget()->style()->subControlRect(QStyle::CC_SpinBox, &so,
 
101
                                                 QStyle::SC_SpinBoxDown, widget());
 
102
        break;
 
103
    default:
 
104
        rect = so.rect;
 
105
        break;
 
106
    }
 
107
    QPoint tl = widget()->mapToGlobal(QPoint(0, 0));
 
108
    return QRect(tl.x() + rect.x(), tl.y() + rect.y(), rect.width(), rect.height());
 
109
}
 
110
 
 
111
/*! \reimp */
 
112
int QAccessibleSpinBox::navigate(RelationFlag rel, int entry, QAccessibleInterface **target) const
 
113
{
 
114
    *target = 0;
 
115
 
 
116
    if (entry) switch (rel) {
 
117
    case Child:
 
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;
 
127
    default:
 
128
        break;
 
129
    }
 
130
    return QAccessibleWidget::navigate(rel, entry, target);
 
131
}
 
132
 
 
133
/*! \reimp */
 
134
QString QAccessibleSpinBox::text(Text t, int child) const
 
135
{
 
136
    switch (t) {
 
137
    case Name:
 
138
        switch (child) {
 
139
        case ValueUp:
 
140
            return QSpinBox::tr("More");
 
141
        case ValueDown:
 
142
            return QSpinBox::tr("Less");
 
143
        }
 
144
        break;
 
145
    case Value:
 
146
        if (child == Editor || child == SpinBoxSelf)
 
147
            return spinBox()->text();
 
148
        break;
 
149
    default:
 
150
        break;
 
151
    }
 
152
    return QAccessibleWidget::text(t, 0);
 
153
}
 
154
 
 
155
/*! \reimp */
 
156
QAccessible::Role QAccessibleSpinBox::role(int child) const
 
157
{
 
158
    switch(child) {
 
159
    case Editor:
 
160
        return EditableText;
 
161
    case ValueUp:
 
162
    case ValueDown:
 
163
        return PushButton;
 
164
    default:
 
165
        break;
 
166
    }
 
167
    return QAccessibleWidget::role(child);
 
168
}
 
169
 
 
170
/*! \reimp */
 
171
QAccessible::State QAccessibleSpinBox::state(int child) const
 
172
{
 
173
    State state = QAccessibleWidget::state(child);
 
174
    switch(child) {
 
175
    case ValueUp:
 
176
        if (spinBox()->value() >= spinBox()->maximum())
 
177
            state |= Unavailable;
 
178
        return state;
 
179
    case ValueDown:
 
180
        if (spinBox()->value() <= spinBox()->minimum())
 
181
            state |= Unavailable;
 
182
        return state;
 
183
    default:
 
184
        break;
 
185
    }
 
186
    return state;
 
187
}
 
188
 
 
189
/*! \reimp */
 
190
bool QAccessibleSpinBox::doAction(int action, int /*child*/, const QVariantList &params)
 
191
{
 
192
    if (!widget()->isEnabled())
 
193
        return false;
 
194
 
 
195
/* // ### vohi - what's that code?
 
196
    if (action == Press) switch(child) {
 
197
    case ValueUp:
 
198
        if (spinBox()->value() >= spinBox()->maxValue())
 
199
            return false;
 
200
        spinBox()->stepUp();
 
201
        return true;
 
202
    case ValueDown:
 
203
        if (spinBox()->value() <= spinBox()->minValue())
 
204
            return false;
 
205
        spinBox()->stepDown();
 
206
        return true;
 
207
    default:
 
208
        break;
 
209
    }
 
210
    */
 
211
    return QAccessibleWidget::doAction(action, 0, params);
 
212
}
 
213
 
 
214
/*!
 
215
  \class QAccessibleScrollBar qaccessiblewidget.h
 
216
  \brief The QAccessibleScrollBar class implements the QAccessibleInterface for scroll bars.
 
217
  \internal
 
218
 
 
219
  \ingroup accessibility
 
220
*/
 
221
 
 
222
/*!
 
223
    \enum QAccessibleScrollBar::ScrollBarElements
 
224
 
 
225
    This enum identifies the components of the scroll bar.
 
226
 
 
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.
 
233
*/
 
234
 
 
235
/*!
 
236
  Constructs a QAccessibleScrollBar object for \a w.
 
237
  \a name is propagated to the QAccessibleWidget constructor.
 
238
*/
 
239
QAccessibleScrollBar::QAccessibleScrollBar(QWidget *w, const QString &name)
 
240
: QAccessibleWidget(w, ScrollBar, name)
 
241
{
 
242
    Q_ASSERT(scrollBar());
 
243
    addControllingSignal("valueChanged(int)");
 
244
}
 
245
 
 
246
/*! Returns the scroll bar. */
 
247
QScrollBar *QAccessibleScrollBar::scrollBar() const
 
248
{
 
249
    return qobject_cast<QScrollBar*>(object());
 
250
}
 
251
 
 
252
/*! \reimp */
 
253
QRect QAccessibleScrollBar::rect(int child) const
 
254
{
 
255
    QRect rect;
 
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());
 
260
    switch (child) {
 
261
    case LineUp:
 
262
        rect = QRect(0, 0, sz, sz);
 
263
        break;
 
264
    case PageUp:
 
265
        if (scrollBar()->orientation() == Qt::Vertical)
 
266
            rect = QRect(0, sz, sz, srect.y() - sz);
 
267
        else
 
268
            rect = QRect(sz, 0, srect.x() - sz, sz);
 
269
        break;
 
270
    case Position:
 
271
        rect = srect;
 
272
        break;
 
273
    case PageDown:
 
274
        if (scrollBar()->orientation() == Qt::Vertical)
 
275
            rect = QRect(0, srect.bottom(), sz, scrollBar()->rect().height() - srect.bottom() - sz);
 
276
        else
 
277
            rect = QRect(srect.right(), 0, scrollBar()->rect().width() - srect.right() - sz, sz) ;
 
278
        break;
 
279
    case LineDown:
 
280
        if (scrollBar()->orientation() == Qt::Vertical)
 
281
            rect = QRect(0, scrollBar()->rect().height() - sz, sz, sz);
 
282
        else
 
283
            rect = QRect(scrollBar()->rect().width() - sz, 0, sz, sz);
 
284
        break;
 
285
    default:
 
286
        return QAccessibleWidget::rect(child);
 
287
    }
 
288
 
 
289
    QPoint tp = scrollBar()->mapToGlobal(QPoint(0,0));
 
290
    return QRect(tp.x() + rect.x(), tp.y() + rect.y(), rect.width(), rect.height());
 
291
}
 
292
 
 
293
/*! \reimp */
 
294
int QAccessibleScrollBar::childCount() const
 
295
{
 
296
    return LineDown;
 
297
}
 
298
 
 
299
/*! \reimp */
 
300
QString        QAccessibleScrollBar::text(Text t, int child) const
 
301
{
 
302
    switch (t) {
 
303
    case Value:
 
304
        if (!child || child == Position)
 
305
            return QString::number(scrollBar()->value());
 
306
        return QString();
 
307
    case Name:
 
308
        switch (child) {
 
309
        case LineUp:
 
310
            return QScrollBar::tr("Line up");
 
311
        case PageUp:
 
312
            return QScrollBar::tr("Page up");
 
313
        case Position:
 
314
            return QScrollBar::tr("Position");
 
315
        case PageDown:
 
316
            return QScrollBar::tr("Page down");
 
317
        case LineDown:
 
318
            return QScrollBar::tr("Line down");
 
319
        }
 
320
        break;
 
321
    default:
 
322
        break;
 
323
    }
 
324
    return QAccessibleWidget::text(t, child);
 
325
}
 
326
 
 
327
/*! \reimp */
 
328
QAccessible::Role QAccessibleScrollBar::role(int child) const
 
329
{
 
330
    switch (child) {
 
331
    case LineUp:
 
332
    case PageUp:
 
333
    case PageDown:
 
334
    case LineDown:
 
335
        return PushButton;
 
336
    case Position:
 
337
        return Indicator;
 
338
    default:
 
339
        return ScrollBar;
 
340
    }
 
341
}
 
342
 
 
343
/*! \reimp */
 
344
bool QAccessibleScrollBar::doAction(int /*action*/, int /*child*/, const QVariantList &/*params*/)
 
345
{
 
346
/*
 
347
    if (action == Press) switch (child) {
 
348
    case LineUp:
 
349
        scrollBar()->subtractLine();
 
350
        return true;
 
351
    case PageUp:
 
352
        scrollBar()->subtractPage();
 
353
        return true;
 
354
    case PageDown:
 
355
        scrollBar()->addPage();
 
356
        return true;
 
357
    case LineDown:
 
358
        scrollBar()->addLine();
 
359
        return true;
 
360
    }
 
361
*/
 
362
    return false;
 
363
}
 
364
 
 
365
/*!
 
366
  \class QAccessibleSlider qaccessiblewidget.h
 
367
  \brief The QAccessibleSlider class implements the QAccessibleInterface for sliders.
 
368
  \internal
 
369
 
 
370
  \ingroup accessibility
 
371
*/
 
372
 
 
373
/*!
 
374
    \enum QAccessibleSlider::SliderElements
 
375
 
 
376
    This enum identifies the components of the slider.
 
377
 
 
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.
 
382
*/
 
383
 
 
384
/*!
 
385
  Constructs a QAccessibleScrollBar object for \a w.
 
386
  \a name is propagated to the QAccessibleWidget constructor.
 
387
*/
 
388
QAccessibleSlider::QAccessibleSlider(QWidget *w, const QString &name)
 
389
: QAccessibleWidget(w, Slider, name)
 
390
{
 
391
    Q_ASSERT(slider());
 
392
    addControllingSignal("valueChanged(int)");
 
393
}
 
394
 
 
395
/*! Returns the slider. */
 
396
QSlider *QAccessibleSlider::slider() const
 
397
{
 
398
    return qobject_cast<QSlider*>(object());
 
399
}
 
400
 
 
401
/*! \reimp */
 
402
QRect QAccessibleSlider::rect(int child) const
 
403
{
 
404
    QRect rect;
 
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());
 
410
    switch (child) {
 
411
    case PageLeft:
 
412
        if (slider()->orientation() == Qt::Vertical)
 
413
            rect = QRect(0, 0, slider()->width(), srect.y());
 
414
        else
 
415
            rect = QRect(0, 0, srect.x(), slider()->height());
 
416
        break;
 
417
    case Position:
 
418
        rect = srect;
 
419
        break;
 
420
    case PageRight:
 
421
        if (slider()->orientation() == Qt::Vertical)
 
422
            rect = QRect(0, srect.y() + srect.height(), slider()->width(), slider()->height()- srect.y() - srect.height());
 
423
        else
 
424
            rect = QRect(srect.x() + srect.width(), 0, slider()->width() - srect.x() - srect.width(), slider()->height());
 
425
        break;
 
426
    default:
 
427
        return QAccessibleWidget::rect(child);
 
428
    }
 
429
 
 
430
    QPoint tp = slider()->mapToGlobal(QPoint(0,0));
 
431
    return QRect(tp.x() + rect.x(), tp.y() + rect.y(), rect.width(), rect.height());
 
432
}
 
433
 
 
434
/*! \reimp */
 
435
int QAccessibleSlider::childCount() const
 
436
{
 
437
    return PageRight;
 
438
}
 
439
 
 
440
/*! \reimp */
 
441
QString        QAccessibleSlider::text(Text t, int child) const
 
442
{
 
443
    switch (t) {
 
444
    case Value:
 
445
        if (!child || child == 2)
 
446
            return QString::number(slider()->value());
 
447
        return QString();
 
448
    case Name:
 
449
        switch (child) {
 
450
        case PageLeft:
 
451
            return slider()->orientation() == Qt::Horizontal ?
 
452
                QSlider::tr("Page left") : QSlider::tr("Page up");
 
453
        case Position:
 
454
            return QSlider::tr("Position");
 
455
        case PageRight:
 
456
            return slider()->orientation() == Qt::Horizontal ?
 
457
                QSlider::tr("Page right") : QSlider::tr("Page down");
 
458
        }
 
459
        break;
 
460
    default:
 
461
        break;
 
462
    }
 
463
    return QAccessibleWidget::text(t, child);
 
464
}
 
465
 
 
466
/*! \reimp */
 
467
QAccessible::Role QAccessibleSlider::role(int child) const
 
468
{
 
469
    switch (child) {
 
470
    case PageLeft:
 
471
    case PageRight:
 
472
        return PushButton;
 
473
    case Position:
 
474
        return Indicator;
 
475
    default:
 
476
        return Slider;
 
477
    }
 
478
}
 
479
 
 
480
/*!
 
481
    \fn int QAccessibleSlider::defaultAction(int child) const
 
482
 
 
483
    Returns the default action for the given \a child. The base class
 
484
    implementation returns 0.
 
485
*/
 
486
int QAccessibleSlider::defaultAction(int /*child*/) const
 
487
{
 
488
/*
 
489
    switch (child) {
 
490
    case SliderSelf:
 
491
        return SetFocus;
 
492
    case PageLeft:
 
493
        return Press;
 
494
    case PageRight:
 
495
        return Press;
 
496
    }
 
497
*/
 
498
    return 0;
 
499
}
 
500
 
 
501
/*! \internal */
 
502
QString QAccessibleSlider::actionText(int /*action*/, Text /*t*/, int /*child*/) const
 
503
{
 
504
    return QString("");
 
505
}
 
506
 
 
507
/*! \reimp */
 
508
bool QAccessibleSlider::doAction(int /*action*/, int /*child*/, const QVariantList &/*params*/)
 
509
{
 
510
/*
 
511
    switch(child) {
 
512
    case SliderSelf:
 
513
        if (action == SetFocus) {
 
514
            slider()->setFocus();
 
515
            return true;
 
516
        }
 
517
        break;
 
518
    case PageLeft:
 
519
        if (action == Press) {
 
520
            slider()->subtractPage();
 
521
            return true;
 
522
        }
 
523
        break;
 
524
    case Position:
 
525
        if (action == Increase) {
 
526
            slider()->addLine();
 
527
            return true;
 
528
        } else if (action == Decrease) {
 
529
            slider()->subtractLine();
 
530
            return true;
 
531
        }
 
532
        break;
 
533
    case PageRight:
 
534
        if (action == Press) {
 
535
            slider()->addPage();
 
536
            return true;
 
537
        }
 
538
        break;
 
539
    }
 
540
*/
 
541
    return false;
 
542
}