|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the plugins of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qaccessiblecompat.h" |
|
43 #include "q3widgetstack.h" |
|
44 |
|
45 #include <q3listview.h> |
|
46 #include <q3textedit.h> |
|
47 #include <q3iconview.h> |
|
48 #include <q3listbox.h> |
|
49 |
|
50 QT_BEGIN_NAMESPACE |
|
51 |
|
52 /*! |
|
53 \fn Q3AccessibleScrollView::Q3AccessibleScrollView(QWidget* widget, Role role) |
|
54 |
|
55 Constructs a Q3AccessibleScrollView object for a \a widget. |
|
56 The \a role is propagated to the QAccessibleWidget constructor. |
|
57 */ |
|
58 Q3AccessibleScrollView::Q3AccessibleScrollView(QWidget *w, Role role) |
|
59 : QAccessibleWidget(w, role) |
|
60 { |
|
61 } |
|
62 |
|
63 /*! |
|
64 Returns the ID of the item at viewport position \a x, \a y. |
|
65 */ |
|
66 int Q3AccessibleScrollView::itemAt(int /*x*/, int /*y*/) const |
|
67 { |
|
68 return 0; |
|
69 } |
|
70 |
|
71 /*! |
|
72 Returns the location in viewport coordinates of the item with ID \a |
|
73 item. |
|
74 */ |
|
75 QRect Q3AccessibleScrollView::itemRect(int /*item*/) const |
|
76 { |
|
77 return QRect(); |
|
78 } |
|
79 |
|
80 /*! |
|
81 Returns the number of items in the scroll view. |
|
82 */ |
|
83 int Q3AccessibleScrollView::itemCount() const |
|
84 { |
|
85 return 0; |
|
86 } |
|
87 |
|
88 /*! |
|
89 \class QAccessibleListView |
|
90 \brief The QAccessibleListView class implements the QAccessibleInterface for list views. |
|
91 \internal |
|
92 */ |
|
93 |
|
94 static Q3ListViewItem *findLVItem(Q3ListView* listView, int child) |
|
95 { |
|
96 int id = 1; |
|
97 Q3ListViewItemIterator it(listView); |
|
98 Q3ListViewItem *item = it.current(); |
|
99 while (item && id < child) { |
|
100 ++it; |
|
101 ++id; |
|
102 item = it.current(); |
|
103 } |
|
104 return item; |
|
105 } |
|
106 |
|
107 /*! |
|
108 \fn QAccessibleListView::QAccessibleListView(QWidget* widget) |
|
109 |
|
110 Constructs a QAccessibleListView object for a \a widget. |
|
111 */ |
|
112 QAccessibleListView::QAccessibleListView(QWidget *o) |
|
113 : Q3AccessibleScrollView(o, Tree) |
|
114 { |
|
115 } |
|
116 |
|
117 /*! Returns the list view. */ |
|
118 Q3ListView *QAccessibleListView::listView() const |
|
119 { |
|
120 Q_ASSERT(widget()->inherits("Q3ListView")); |
|
121 return (Q3ListView*)widget(); |
|
122 } |
|
123 |
|
124 /*! \reimp */ |
|
125 int QAccessibleListView::itemAt(int x, int y) const |
|
126 { |
|
127 Q3ListViewItem *item = listView()->itemAt(QPoint(x, y)); |
|
128 if (!item) |
|
129 return 0; |
|
130 |
|
131 Q3ListViewItemIterator it(listView()); |
|
132 int c = 1; |
|
133 while (it.current()) { |
|
134 if (it.current() == item) |
|
135 return c; |
|
136 ++c; |
|
137 ++it; |
|
138 } |
|
139 return 0; |
|
140 } |
|
141 |
|
142 /*! \reimp */ |
|
143 QRect QAccessibleListView::itemRect(int child) const |
|
144 { |
|
145 Q3ListViewItem *item = findLVItem(listView(), child); |
|
146 if (!item) |
|
147 return QRect(); |
|
148 return listView()->itemRect(item); |
|
149 } |
|
150 |
|
151 /*! \reimp */ |
|
152 int QAccessibleListView::itemCount() const |
|
153 { |
|
154 Q3ListViewItemIterator it(listView()); |
|
155 int c = 0; |
|
156 while (it.current()) { |
|
157 ++c; |
|
158 ++it; |
|
159 } |
|
160 |
|
161 return c; |
|
162 } |
|
163 |
|
164 /*! \reimp */ |
|
165 QString QAccessibleListView::text(Text t, int child) const |
|
166 { |
|
167 if (!child || t != Name) |
|
168 return Q3AccessibleScrollView::text(t, child); |
|
169 |
|
170 Q3ListViewItem *item = findLVItem(listView(), child); |
|
171 if (!item) |
|
172 return QString(); |
|
173 return item->text(0); |
|
174 } |
|
175 |
|
176 /*! \reimp */ |
|
177 QAccessible::Role QAccessibleListView::role(int child) const |
|
178 { |
|
179 if (!child) |
|
180 return Q3AccessibleScrollView::role(child); |
|
181 return TreeItem; |
|
182 } |
|
183 |
|
184 /*! \reimp */ |
|
185 QAccessible::State QAccessibleListView::state(int child) const |
|
186 { |
|
187 State state = Q3AccessibleScrollView::state(child); |
|
188 Q3ListViewItem *item; |
|
189 if (!child || !(item = findLVItem(listView(), child))) |
|
190 return state; |
|
191 |
|
192 if (item->isSelectable()) { |
|
193 if (listView()->selectionMode() == Q3ListView::Multi) |
|
194 state |= MultiSelectable; |
|
195 else if (listView()->selectionMode() == Q3ListView::Extended) |
|
196 state |= ExtSelectable; |
|
197 else if (listView()->selectionMode() == Q3ListView::Single) |
|
198 state |= Selectable; |
|
199 if (item->isSelected()) |
|
200 state |= Selected; |
|
201 } |
|
202 if (listView()->focusPolicy() != Qt::NoFocus) { |
|
203 state |= Focusable; |
|
204 if (item == listView()->currentItem()) |
|
205 state |= Focused; |
|
206 } |
|
207 if (item->childCount()) { |
|
208 if (item->isOpen()) |
|
209 state |= Expanded; |
|
210 else |
|
211 state |= Collapsed; |
|
212 } |
|
213 if (!listView()->itemRect(item).isValid()) |
|
214 state |= Invisible; |
|
215 |
|
216 if (item->rtti() == Q3CheckListItem::RTTI) { |
|
217 if (((Q3CheckListItem*)item)->isOn()) |
|
218 state|=Checked; |
|
219 } |
|
220 return state; |
|
221 } |
|
222 |
|
223 /* \reimp |
|
224 QAccessibleInterface *QAccessibleListView::focusChild(int *child) const |
|
225 { |
|
226 Q3ListViewItem *item = listView()->currentItem(); |
|
227 if (!item) |
|
228 return 0; |
|
229 |
|
230 Q3ListViewItemIterator it(listView()); |
|
231 int c = 1; |
|
232 while (it.current()) { |
|
233 if (it.current() == item) { |
|
234 *child = c; |
|
235 return (QAccessibleInterface*)this; |
|
236 } |
|
237 ++c; |
|
238 ++it; |
|
239 } |
|
240 return 0; |
|
241 } |
|
242 */ |
|
243 /* \reimp |
|
244 bool QAccessibleListView::setFocus(int child) |
|
245 { |
|
246 bool res = Q3AccessibleScrollView::setFocus(0); |
|
247 if (!child || !res) |
|
248 return res; |
|
249 |
|
250 Q3ListViewItem *item = findLVItem(listView(), child); |
|
251 if (!item) |
|
252 return false; |
|
253 listView()->setCurrentItem(item); |
|
254 return true; |
|
255 }*/ |
|
256 |
|
257 /*! \internal */ |
|
258 bool QAccessibleListView::setSelected(int child, bool on, bool extend) |
|
259 { |
|
260 if (!child || (extend && |
|
261 listView()->selectionMode() != Q3ListView::Extended && |
|
262 listView()->selectionMode() != Q3ListView::Multi)) |
|
263 return false; |
|
264 |
|
265 Q3ListViewItem *item = findLVItem(listView(), child); |
|
266 if (!item) |
|
267 return false; |
|
268 if (!extend) { |
|
269 listView()->setSelected(item, on); |
|
270 } else { |
|
271 Q3ListViewItem *current = listView()->currentItem(); |
|
272 if (!current) |
|
273 return false; |
|
274 bool down = item->itemPos() > current->itemPos(); |
|
275 Q3ListViewItemIterator it(current); |
|
276 while (it.current()) { |
|
277 listView()->setSelected(it.current(), on); |
|
278 if (it.current() == item) |
|
279 break; |
|
280 if (down) |
|
281 ++it; |
|
282 else |
|
283 --it; |
|
284 } |
|
285 } |
|
286 return true; |
|
287 } |
|
288 |
|
289 /*! \internal */ |
|
290 void QAccessibleListView::clearSelection() |
|
291 { |
|
292 listView()->clearSelection(); |
|
293 } |
|
294 |
|
295 /*! \internal */ |
|
296 QVector<int> QAccessibleListView::selection() const |
|
297 { |
|
298 QVector<int> array; |
|
299 uint size = 0; |
|
300 int id = 1; |
|
301 array.resize(size); |
|
302 Q3ListViewItemIterator it(listView()); |
|
303 while (it.current()) { |
|
304 if (it.current()->isSelected()) { |
|
305 ++size; |
|
306 array.resize(size); |
|
307 array[(int)size-1] = id; |
|
308 } |
|
309 ++it; |
|
310 ++id; |
|
311 } |
|
312 return array; |
|
313 } |
|
314 |
|
315 /*! |
|
316 \class QAccessibleIconView |
|
317 \brief The QAccessibleIconView class implements the QAccessibleInterface for icon views. |
|
318 \internal |
|
319 */ |
|
320 |
|
321 static Q3IconViewItem *findIVItem(Q3IconView *iconView, int child) |
|
322 { |
|
323 int id = 1; |
|
324 Q3IconViewItem *item = iconView->firstItem(); |
|
325 while (item && id < child) { |
|
326 item = item->nextItem(); |
|
327 ++id; |
|
328 } |
|
329 |
|
330 return item; |
|
331 } |
|
332 |
|
333 /*! |
|
334 \fn QAccessibleIconView::QAccessibleIconView(QWidget* widget) |
|
335 |
|
336 Constructs a QAccessibleIconView object for a \a widget. |
|
337 */ |
|
338 QAccessibleIconView::QAccessibleIconView(QWidget *o) |
|
339 : Q3AccessibleScrollView(o, List) |
|
340 { |
|
341 Q_ASSERT(widget()->inherits("Q3IconView")); |
|
342 } |
|
343 |
|
344 /*! Returns the icon view. */ |
|
345 Q3IconView *QAccessibleIconView::iconView() const |
|
346 { |
|
347 return (Q3IconView*)widget(); |
|
348 } |
|
349 |
|
350 /*! \internal */ |
|
351 int QAccessibleIconView::itemAt(int x, int y) const |
|
352 { |
|
353 Q3IconViewItem *item = iconView()->findItem(QPoint(x, y)); |
|
354 return iconView()->index(item) + 1; |
|
355 } |
|
356 |
|
357 /*! \internal */ |
|
358 QRect QAccessibleIconView::itemRect(int child) const |
|
359 { |
|
360 Q3IconViewItem *item = findIVItem(iconView(), child); |
|
361 |
|
362 if (!item) |
|
363 return QRect(); |
|
364 return item->rect(); |
|
365 } |
|
366 |
|
367 /*! \internal */ |
|
368 int QAccessibleIconView::itemCount() const |
|
369 { |
|
370 return iconView()->count(); |
|
371 } |
|
372 |
|
373 /*! \internal */ |
|
374 QString QAccessibleIconView::text(Text t, int child) const |
|
375 { |
|
376 if (!child || t != Name) |
|
377 return Q3AccessibleScrollView::text(t, child); |
|
378 |
|
379 Q3IconViewItem *item = findIVItem(iconView(), child); |
|
380 if (!item) |
|
381 return QString(); |
|
382 return item->text(); |
|
383 } |
|
384 |
|
385 /*! \internal */ |
|
386 QAccessible::Role QAccessibleIconView::role(int child) const |
|
387 { |
|
388 if (!child) |
|
389 return Q3AccessibleScrollView::role(child); |
|
390 return ListItem; |
|
391 } |
|
392 |
|
393 /*! \internal */ |
|
394 QAccessible::State QAccessibleIconView::state(int child) const |
|
395 { |
|
396 State state = Q3AccessibleScrollView::state(child); |
|
397 Q3IconViewItem *item; |
|
398 if (!child || !(item = findIVItem(iconView(), child))) |
|
399 return state; |
|
400 |
|
401 if (item->isSelectable()) { |
|
402 if (iconView()->selectionMode() == Q3IconView::Multi) |
|
403 state |= MultiSelectable; |
|
404 else if (iconView()->selectionMode() == Q3IconView::Extended) |
|
405 state |= ExtSelectable; |
|
406 else if (iconView()->selectionMode() == Q3IconView::Single) |
|
407 state |= Selectable; |
|
408 if (item->isSelected()) |
|
409 state |= Selected; |
|
410 } |
|
411 if (iconView()->itemsMovable()) |
|
412 state |= Movable; |
|
413 if (iconView()->focusPolicy() != Qt::NoFocus) { |
|
414 state |= Focusable; |
|
415 if (item == iconView()->currentItem()) |
|
416 state |= Focused; |
|
417 } |
|
418 |
|
419 return state; |
|
420 } |
|
421 |
|
422 /* \reimp |
|
423 QAccessibleInterface *QAccessibleIconView::focusChild(int *child) const |
|
424 { |
|
425 Q3IconViewItem *item = iconView()->currentItem(); |
|
426 if (!item) |
|
427 return 0; |
|
428 |
|
429 *child = iconView()->index(item); |
|
430 return (QAccessibleInterface*)this; |
|
431 } |
|
432 */ |
|
433 /* \reimp |
|
434 bool QAccessibleIconView::setFocus(int child) |
|
435 { |
|
436 bool res = Q3AccessibleScrollView::setFocus(0); |
|
437 if (!child || !res) |
|
438 return res; |
|
439 |
|
440 Q3IconViewItem *item = findIVItem(iconView(), child); |
|
441 if (!item) |
|
442 return false; |
|
443 iconView()->setCurrentItem(item); |
|
444 return true; |
|
445 }*/ |
|
446 |
|
447 /*! \internal */ |
|
448 bool QAccessibleIconView::setSelected(int child, bool on, bool extend) |
|
449 { |
|
450 if (!child || (extend && |
|
451 iconView()->selectionMode() != Q3IconView::Extended && |
|
452 iconView()->selectionMode() != Q3IconView::Multi)) |
|
453 return false; |
|
454 |
|
455 Q3IconViewItem *item = findIVItem(iconView(), child); |
|
456 if (!item) |
|
457 return false; |
|
458 if (!extend) { |
|
459 iconView()->setSelected(item, on, true); |
|
460 } else { |
|
461 Q3IconViewItem *current = iconView()->currentItem(); |
|
462 if (!current) |
|
463 return false; |
|
464 bool down = false; |
|
465 Q3IconViewItem *temp = current; |
|
466 while ((temp = temp->nextItem())) { |
|
467 if (temp == item) { |
|
468 down = true; |
|
469 break; |
|
470 } |
|
471 } |
|
472 temp = current; |
|
473 if (down) { |
|
474 while ((temp = temp->nextItem())) { |
|
475 iconView()->setSelected(temp, on, true); |
|
476 if (temp == item) |
|
477 break; |
|
478 } |
|
479 } else { |
|
480 while ((temp = temp->prevItem())) { |
|
481 iconView()->setSelected(temp, on, true); |
|
482 if (temp == item) |
|
483 break; |
|
484 } |
|
485 } |
|
486 } |
|
487 return true; |
|
488 } |
|
489 |
|
490 /*! \internal */ |
|
491 void QAccessibleIconView::clearSelection() |
|
492 { |
|
493 iconView()->clearSelection(); |
|
494 } |
|
495 |
|
496 /*! \internal */ |
|
497 QVector<int> QAccessibleIconView::selection() const |
|
498 { |
|
499 QVector<int> array; |
|
500 uint size = 0; |
|
501 int id = 1; |
|
502 array.resize(iconView()->count()); |
|
503 Q3IconViewItem *item = iconView()->firstItem(); |
|
504 while (item) { |
|
505 if (item->isSelected()) { |
|
506 ++size; |
|
507 array[(int)size-1] = id; |
|
508 } |
|
509 item = item->nextItem(); |
|
510 ++id; |
|
511 } |
|
512 array.resize(size); |
|
513 return array; |
|
514 } |
|
515 |
|
516 |
|
517 /*! |
|
518 \class Q3AccessibleTextEdit |
|
519 \brief The Q3AccessibleTextEdit class implements the QAccessibleInterface for richtext editors. |
|
520 \internal |
|
521 */ |
|
522 |
|
523 /*! |
|
524 \fn Q3AccessibleTextEdit::Q3AccessibleTextEdit(QWidget* widget) |
|
525 |
|
526 Constructs a Q3AccessibleTextEdit object for a \a widget. |
|
527 */ |
|
528 Q3AccessibleTextEdit::Q3AccessibleTextEdit(QWidget *o) |
|
529 : Q3AccessibleScrollView(o, Pane) |
|
530 { |
|
531 Q_ASSERT(widget()->inherits("Q3TextEdit")); |
|
532 } |
|
533 |
|
534 /*! Returns the text edit. */ |
|
535 Q3TextEdit *Q3AccessibleTextEdit::textEdit() const |
|
536 { |
|
537 |
|
538 return (Q3TextEdit*)widget(); |
|
539 } |
|
540 |
|
541 /*! \reimp */ |
|
542 int Q3AccessibleTextEdit::itemAt(int x, int y) const |
|
543 { |
|
544 int p; |
|
545 QPoint cp = textEdit()->viewportToContents(QPoint(x,y)); |
|
546 textEdit()->charAt(cp , &p); |
|
547 return p + 1; |
|
548 } |
|
549 |
|
550 /*! \reimp */ |
|
551 QRect Q3AccessibleTextEdit::itemRect(int item) const |
|
552 { |
|
553 QRect rect = textEdit()->paragraphRect(item - 1); |
|
554 if (!rect.isValid()) |
|
555 return QRect(); |
|
556 QPoint ntl = textEdit()->contentsToViewport(QPoint(rect.x(), rect.y())); |
|
557 return QRect(ntl.x(), ntl.y(), rect.width(), rect.height()); |
|
558 } |
|
559 |
|
560 /*! \reimp */ |
|
561 int Q3AccessibleTextEdit::itemCount() const |
|
562 { |
|
563 return textEdit()->paragraphs(); |
|
564 } |
|
565 |
|
566 /*! \reimp */ |
|
567 QString Q3AccessibleTextEdit::text(Text t, int child) const |
|
568 { |
|
569 if (t == Name && child > 0) |
|
570 return textEdit()->text(child - 1); |
|
571 if (t == Value) { |
|
572 if (child > 0) |
|
573 return textEdit()->text(child - 1); |
|
574 else |
|
575 return textEdit()->text(); |
|
576 } |
|
577 |
|
578 return Q3AccessibleScrollView::text(t, child); |
|
579 } |
|
580 |
|
581 /*! \reimp */ |
|
582 void Q3AccessibleTextEdit::setText(Text t, int control, const QString &text) |
|
583 { |
|
584 if (t != Value || control) { |
|
585 Q3AccessibleScrollView::setText(t, control, text); |
|
586 return; |
|
587 } |
|
588 textEdit()->setText(text); |
|
589 } |
|
590 |
|
591 /*! \reimp */ |
|
592 QAccessible::Role Q3AccessibleTextEdit::role(int child) const |
|
593 { |
|
594 if (child) |
|
595 return EditableText; |
|
596 return Q3AccessibleScrollView::role(child); |
|
597 } |
|
598 |
|
599 /*! |
|
600 \class QAccessibleWidgetStack |
|
601 \brief The QAccessibleWidgetStack class implements the QAccessibleInterface for widget stacks. |
|
602 |
|
603 \ingroup accessibility |
|
604 \internal |
|
605 */ |
|
606 |
|
607 /*! |
|
608 \fn QAccessibleWidgetStack::QAccessibleWidgetStack(QWidget* widget) |
|
609 |
|
610 Creates a QAccessibleWidgetStack object for a \a widget. |
|
611 */ |
|
612 QAccessibleWidgetStack::QAccessibleWidgetStack(QWidget *w) |
|
613 : QAccessibleWidget(w, LayeredPane) |
|
614 { |
|
615 Q_ASSERT(widgetStack()); |
|
616 setDescription(QLatin1String("This is a widgetstack")); |
|
617 } |
|
618 |
|
619 /*! Returns the widget stack. */ |
|
620 Q3WidgetStack *QAccessibleWidgetStack::widgetStack() const |
|
621 { |
|
622 return qobject_cast<Q3WidgetStack*>(object()); |
|
623 } |
|
624 |
|
625 /*! \reimp */ |
|
626 int QAccessibleWidgetStack::childCount() const |
|
627 { |
|
628 // a widget stack has always only one accessible widget |
|
629 return 1; |
|
630 } |
|
631 |
|
632 /*! \reimp */ |
|
633 int QAccessibleWidgetStack::indexOfChild(const QAccessibleInterface *child) const |
|
634 { |
|
635 QObject *childObject = child ? child->object() : 0; |
|
636 if (childObject != widgetStack()->visibleWidget()) |
|
637 return -1; |
|
638 return 1; |
|
639 } |
|
640 |
|
641 /*! \reimp */ |
|
642 int QAccessibleWidgetStack::childAt(int, int) const |
|
643 { |
|
644 QWidget *curPage = widgetStack()->visibleWidget(); |
|
645 if (!curPage) |
|
646 return 0; |
|
647 return 1; |
|
648 } |
|
649 |
|
650 /*! \reimp */ |
|
651 int QAccessibleWidgetStack::navigate(RelationFlag rel, int entry, |
|
652 QAccessibleInterface **target) const |
|
653 { |
|
654 *target = 0; |
|
655 QObject *targetObject = 0; |
|
656 switch (rel) { |
|
657 // Hierarchical |
|
658 case Child: |
|
659 if (entry != 1) |
|
660 return -1; |
|
661 targetObject = widgetStack()->visibleWidget(); |
|
662 break; |
|
663 default: |
|
664 return QAccessibleWidget::navigate(rel, entry, target); |
|
665 } |
|
666 *target = QAccessible::queryAccessibleInterface(targetObject); |
|
667 return *target ? 0 : -1; |
|
668 } |
|
669 |
|
670 /*! |
|
671 \class QAccessibleListBox |
|
672 \brief The QAccessibleListBox class implements the QAccessibleInterface for list boxes. |
|
673 |
|
674 \ingroup accessibility |
|
675 \internal |
|
676 */ |
|
677 |
|
678 /*! |
|
679 \fn QAccessibleListBox::QAccessibleListBox(QWidget* widget) |
|
680 |
|
681 Constructs a QAccessibleListBox object for a \a widget. |
|
682 */ |
|
683 QAccessibleListBox::QAccessibleListBox(QWidget *o) |
|
684 : Q3AccessibleScrollView(o, List) |
|
685 { |
|
686 Q_ASSERT(widget()->inherits("Q3ListBox")); |
|
687 } |
|
688 |
|
689 /*! Returns the list box. */ |
|
690 Q3ListBox *QAccessibleListBox::listBox() const |
|
691 { |
|
692 return (Q3ListBox*)widget(); |
|
693 } |
|
694 |
|
695 /*! \reimp */ |
|
696 int QAccessibleListBox::itemAt(int x, int y) const |
|
697 { |
|
698 Q3ListBoxItem *item = listBox()->itemAt(QPoint(x, y)); |
|
699 return listBox()->index(item) + 1; |
|
700 } |
|
701 |
|
702 /*! \reimp */ |
|
703 QRect QAccessibleListBox::itemRect(int item) const |
|
704 { |
|
705 return listBox()->itemRect(listBox()->item(item-1)); |
|
706 } |
|
707 |
|
708 /*! \reimp */ |
|
709 int QAccessibleListBox::itemCount() const |
|
710 { |
|
711 return listBox()->count(); |
|
712 } |
|
713 |
|
714 /*! \reimp */ |
|
715 QString QAccessibleListBox::text(Text t, int child) const |
|
716 { |
|
717 if (!child || t != Name) |
|
718 return Q3AccessibleScrollView::text(t, child); |
|
719 |
|
720 Q3ListBoxItem *item = listBox()->item(child - 1); |
|
721 if (item) |
|
722 return item->text(); |
|
723 return QString(); |
|
724 } |
|
725 |
|
726 /*! \reimp */ |
|
727 QAccessible::Role QAccessibleListBox::role(int child) const |
|
728 { |
|
729 if (!child) |
|
730 return Q3AccessibleScrollView::role(child); |
|
731 return ListItem; |
|
732 } |
|
733 |
|
734 /*! \reimp */ |
|
735 QAccessible::State QAccessibleListBox::state(int child) const |
|
736 { |
|
737 State state = Q3AccessibleScrollView::state(child); |
|
738 Q3ListBoxItem *item; |
|
739 if (!child || !(item = listBox()->item(child - 1))) |
|
740 return state; |
|
741 |
|
742 if (item->isSelectable()) { |
|
743 if (listBox()->selectionMode() == Q3ListBox::Multi) |
|
744 state |= MultiSelectable; |
|
745 else if (listBox()->selectionMode() == Q3ListBox::Extended) |
|
746 state |= ExtSelectable; |
|
747 else if (listBox()->selectionMode() == Q3ListBox::Single) |
|
748 state |= Selectable; |
|
749 if (item->isSelected()) |
|
750 state |= Selected; |
|
751 } |
|
752 if (listBox()->focusPolicy() != Qt::NoFocus) { |
|
753 state |= Focusable; |
|
754 if (item->isCurrent()) |
|
755 state |= Focused; |
|
756 } |
|
757 if (!listBox()->itemVisible(item)) |
|
758 state |= Invisible; |
|
759 |
|
760 return state; |
|
761 } |
|
762 |
|
763 /* \reimp |
|
764 bool QAccessibleListBox::setFocus(int child) |
|
765 { |
|
766 bool res = Q3AccessibleScrollView::setFocus(0); |
|
767 if (!child || !res) |
|
768 return res; |
|
769 |
|
770 Q3ListBoxItem *item = listBox()->item(child -1); |
|
771 if (!item) |
|
772 return false; |
|
773 listBox()->setCurrentItem(item); |
|
774 return true; |
|
775 }*/ |
|
776 |
|
777 /*! |
|
778 Selects the item with index \a child if \a on is true; otherwise |
|
779 unselects it. If \a extend is true and the selection mode is not |
|
780 \c Single and there is an existing selection, the selection is |
|
781 extended to include all the items from the existing selection up |
|
782 to and including the item with index \a child. Returns true if a |
|
783 selection was made or extended; otherwise returns false. |
|
784 |
|
785 \sa selection() clearSelection() |
|
786 */ |
|
787 bool QAccessibleListBox::setSelected(int child, bool on, bool extend) |
|
788 { |
|
789 if (!child || (extend && |
|
790 listBox()->selectionMode() != Q3ListBox::Extended && |
|
791 listBox()->selectionMode() != Q3ListBox::Multi)) |
|
792 return false; |
|
793 |
|
794 Q3ListBoxItem *item = listBox()->item(child -1); |
|
795 if (!item) |
|
796 return false; |
|
797 if (!extend) { |
|
798 listBox()->setSelected(item, on); |
|
799 } else { |
|
800 int current = listBox()->currentItem(); |
|
801 bool down = child > current; |
|
802 for (int i = current; i != child;) { |
|
803 down ? i++ : i--; |
|
804 listBox()->setSelected(i, on); |
|
805 } |
|
806 |
|
807 } |
|
808 return true; |
|
809 } |
|
810 |
|
811 /*! |
|
812 Sets all the items in the list box to be unselected. |
|
813 |
|
814 \sa setSelected() selection() |
|
815 */ |
|
816 void QAccessibleListBox::clearSelection() |
|
817 { |
|
818 listBox()->clearSelection(); |
|
819 } |
|
820 |
|
821 /*! |
|
822 Returns a (possibly empty) list of indexes of the items selected |
|
823 in the list box. |
|
824 |
|
825 \sa setSelected() clearSelection() |
|
826 */ |
|
827 QVector<int> QAccessibleListBox::selection() const |
|
828 { |
|
829 QVector<int> array; |
|
830 uint size = 0; |
|
831 const uint c = listBox()->count(); |
|
832 array.resize(c); |
|
833 for (uint i = 0; i < c; ++i) { |
|
834 if (listBox()->isSelected(i)) { |
|
835 ++size; |
|
836 array[(int)size-1] = i+1; |
|
837 } |
|
838 } |
|
839 array.resize(size); |
|
840 return array; |
|
841 } |
|
842 |
|
843 QT_END_NAMESPACE |