Qt 4.8
qaccessiblecompat.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
51 
59 : QAccessibleWidget(w, role)
60 {
61 }
62 
66 int Q3AccessibleScrollView::itemAt(int /*x*/, int /*y*/) const
67 {
68  return 0;
69 }
70 
76 {
77  return QRect();
78 }
79 
84 {
85  return 0;
86 }
87 
97 static Q3ListViewItem *findLVItem(Q3ListView* listView, int child)
98 {
99  int id = 1;
100  Q3ListViewItemIterator it(listView);
101  Q3ListViewItem *item = it.current();
102  while (item && id < child) {
103  ++it;
104  ++id;
105  item = it.current();
106  }
107  return item;
108 }
109 
117 {
118 }
119 
121 Q3ListView *QAccessibleListView::listView() const
122 {
123  Q_ASSERT(widget()->inherits("Q3ListView"));
124  return (Q3ListView*)widget();
125 }
126 
128 int QAccessibleListView::itemAt(int x, int y) const
129 {
130  Q3ListViewItem *item = listView()->itemAt(QPoint(x, y));
131  if (!item)
132  return 0;
133 
134  Q3ListViewItemIterator it(listView());
135  int c = 1;
136  while (it.current()) {
137  if (it.current() == item)
138  return c;
139  ++c;
140  ++it;
141  }
142  return 0;
143 }
144 
147 {
148  Q3ListViewItem *item = findLVItem(listView(), child);
149  if (!item)
150  return QRect();
151  return listView()->itemRect(item);
152 }
153 
156 {
157  Q3ListViewItemIterator it(listView());
158  int c = 0;
159  while (it.current()) {
160  ++c;
161  ++it;
162  }
163 
164  return c;
165 }
166 
169 {
170  if (!child || t != Name)
171  return Q3AccessibleScrollView::text(t, child);
172 
173  Q3ListViewItem *item = findLVItem(listView(), child);
174  if (!item)
175  return QString();
176  return item->text(0);
177 }
178 
181 {
182  if (!child)
183  return Q3AccessibleScrollView::role(child);
184  return TreeItem;
185 }
186 
189 {
191  Q3ListViewItem *item;
192  if (!child || !(item = findLVItem(listView(), child)))
193  return state;
194 
195  if (item->isSelectable()) {
196  if (listView()->selectionMode() == Q3ListView::Multi)
197  state |= MultiSelectable;
198  else if (listView()->selectionMode() == Q3ListView::Extended)
199  state |= ExtSelectable;
200  else if (listView()->selectionMode() == Q3ListView::Single)
201  state |= Selectable;
202  if (item->isSelected())
203  state |= Selected;
204  }
205  if (listView()->focusPolicy() != Qt::NoFocus) {
206  state |= Focusable;
207  if (item == listView()->currentItem())
208  state |= Focused;
209  }
210  if (item->childCount()) {
211  if (item->isOpen())
212  state |= Expanded;
213  else
214  state |= Collapsed;
215  }
216  if (!listView()->itemRect(item).isValid())
217  state |= Invisible;
218 
219  if (item->rtti() == Q3CheckListItem::RTTI) {
220  if (((Q3CheckListItem*)item)->isOn())
221  state|=Checked;
222  }
223  return state;
224 }
225 
226 /* \reimp
227 QAccessibleInterface *QAccessibleListView::focusChild(int *child) const
228 {
229  Q3ListViewItem *item = listView()->currentItem();
230  if (!item)
231  return 0;
232 
233  Q3ListViewItemIterator it(listView());
234  int c = 1;
235  while (it.current()) {
236  if (it.current() == item) {
237  *child = c;
238  return (QAccessibleInterface*)this;
239  }
240  ++c;
241  ++it;
242  }
243  return 0;
244 }
245 */
246 /* \reimp
247 bool QAccessibleListView::setFocus(int child)
248 {
249  bool res = Q3AccessibleScrollView::setFocus(0);
250  if (!child || !res)
251  return res;
252 
253  Q3ListViewItem *item = findLVItem(listView(), child);
254  if (!item)
255  return false;
256  listView()->setCurrentItem(item);
257  return true;
258 }*/
259 
261 bool QAccessibleListView::setSelected(int child, bool on, bool extend)
262 {
263  if (!child || (extend &&
264  listView()->selectionMode() != Q3ListView::Extended &&
265  listView()->selectionMode() != Q3ListView::Multi))
266  return false;
267 
268  Q3ListViewItem *item = findLVItem(listView(), child);
269  if (!item)
270  return false;
271  if (!extend) {
272  listView()->setSelected(item, on);
273  } else {
274  Q3ListViewItem *current = listView()->currentItem();
275  if (!current)
276  return false;
277  bool down = item->itemPos() > current->itemPos();
278  Q3ListViewItemIterator it(current);
279  while (it.current()) {
280  listView()->setSelected(it.current(), on);
281  if (it.current() == item)
282  break;
283  if (down)
284  ++it;
285  else
286  --it;
287  }
288  }
289  return true;
290 }
291 
294 {
295  listView()->clearSelection();
296 }
297 
300 {
301  QVector<int> array;
302  uint size = 0;
303  int id = 1;
304  array.resize(size);
305  Q3ListViewItemIterator it(listView());
306  while (it.current()) {
307  if (it.current()->isSelected()) {
308  ++size;
309  array.resize(size);
310  array[(int)size-1] = id;
311  }
312  ++it;
313  ++id;
314  }
315  return array;
316 }
317 
327 static Q3IconViewItem *findIVItem(Q3IconView *iconView, int child)
328 {
329  int id = 1;
330  Q3IconViewItem *item = iconView->firstItem();
331  while (item && id < child) {
332  item = item->nextItem();
333  ++id;
334  }
335 
336  return item;
337 }
338 
346 {
347  Q_ASSERT(widget()->inherits("Q3IconView"));
348 }
349 
351 Q3IconView *QAccessibleIconView::iconView() const
352 {
353  return (Q3IconView*)widget();
354 }
355 
357 int QAccessibleIconView::itemAt(int x, int y) const
358 {
359  Q3IconViewItem *item = iconView()->findItem(QPoint(x, y));
360  return iconView()->index(item) + 1;
361 }
362 
365 {
366  Q3IconViewItem *item = findIVItem(iconView(), child);
367 
368  if (!item)
369  return QRect();
370  return item->rect();
371 }
372 
375 {
376  return iconView()->count();
377 }
378 
381 {
382  if (!child || t != Name)
383  return Q3AccessibleScrollView::text(t, child);
384 
385  Q3IconViewItem *item = findIVItem(iconView(), child);
386  if (!item)
387  return QString();
388  return item->text();
389 }
390 
393 {
394  if (!child)
395  return Q3AccessibleScrollView::role(child);
396  return ListItem;
397 }
398 
401 {
403  Q3IconViewItem *item;
404  if (!child || !(item = findIVItem(iconView(), child)))
405  return state;
406 
407  if (item->isSelectable()) {
408  if (iconView()->selectionMode() == Q3IconView::Multi)
409  state |= MultiSelectable;
410  else if (iconView()->selectionMode() == Q3IconView::Extended)
411  state |= ExtSelectable;
412  else if (iconView()->selectionMode() == Q3IconView::Single)
413  state |= Selectable;
414  if (item->isSelected())
415  state |= Selected;
416  }
417  if (iconView()->itemsMovable())
418  state |= Movable;
419  if (iconView()->focusPolicy() != Qt::NoFocus) {
420  state |= Focusable;
421  if (item == iconView()->currentItem())
422  state |= Focused;
423  }
424 
425  return state;
426 }
427 
428 /* \reimp
429 QAccessibleInterface *QAccessibleIconView::focusChild(int *child) const
430 {
431  Q3IconViewItem *item = iconView()->currentItem();
432  if (!item)
433  return 0;
434 
435  *child = iconView()->index(item);
436  return (QAccessibleInterface*)this;
437 }
438 */
439 /* \reimp
440 bool QAccessibleIconView::setFocus(int child)
441 {
442  bool res = Q3AccessibleScrollView::setFocus(0);
443  if (!child || !res)
444  return res;
445 
446  Q3IconViewItem *item = findIVItem(iconView(), child);
447  if (!item)
448  return false;
449  iconView()->setCurrentItem(item);
450  return true;
451 }*/
452 
454 bool QAccessibleIconView::setSelected(int child, bool on, bool extend)
455 {
456  if (!child || (extend &&
457  iconView()->selectionMode() != Q3IconView::Extended &&
458  iconView()->selectionMode() != Q3IconView::Multi))
459  return false;
460 
461  Q3IconViewItem *item = findIVItem(iconView(), child);
462  if (!item)
463  return false;
464  if (!extend) {
465  iconView()->setSelected(item, on, true);
466  } else {
467  Q3IconViewItem *current = iconView()->currentItem();
468  if (!current)
469  return false;
470  bool down = false;
471  Q3IconViewItem *temp = current;
472  while ((temp = temp->nextItem())) {
473  if (temp == item) {
474  down = true;
475  break;
476  }
477  }
478  temp = current;
479  if (down) {
480  while ((temp = temp->nextItem())) {
481  iconView()->setSelected(temp, on, true);
482  if (temp == item)
483  break;
484  }
485  } else {
486  while ((temp = temp->prevItem())) {
487  iconView()->setSelected(temp, on, true);
488  if (temp == item)
489  break;
490  }
491  }
492  }
493  return true;
494 }
495 
498 {
499  iconView()->clearSelection();
500 }
501 
504 {
505  QVector<int> array;
506  uint size = 0;
507  int id = 1;
508  array.resize(iconView()->count());
509  Q3IconViewItem *item = iconView()->firstItem();
510  while (item) {
511  if (item->isSelected()) {
512  ++size;
513  array[(int)size-1] = id;
514  }
515  item = item->nextItem();
516  ++id;
517  }
518  array.resize(size);
519  return array;
520 }
521 
522 
539 {
540  Q_ASSERT(widget()->inherits("Q3TextEdit"));
541 }
542 
545 {
546 
547  return (Q3TextEdit*)widget();
548 }
549 
551 int Q3AccessibleTextEdit::itemAt(int x, int y) const
552 {
553  int p;
554  QPoint cp = textEdit()->viewportToContents(QPoint(x,y));
555  textEdit()->charAt(cp , &p);
556  return p + 1;
557 }
558 
561 {
562  QRect rect = textEdit()->paragraphRect(item - 1);
563  if (!rect.isValid())
564  return QRect();
565  QPoint ntl = textEdit()->contentsToViewport(QPoint(rect.x(), rect.y()));
566  return QRect(ntl.x(), ntl.y(), rect.width(), rect.height());
567 }
568 
571 {
572  return textEdit()->paragraphs();
573 }
574 
577 {
578  if (t == Name && child > 0)
579  return textEdit()->text(child - 1);
580  if (t == Value) {
581  if (child > 0)
582  return textEdit()->text(child - 1);
583  else
584  return textEdit()->text();
585  }
586 
587  return Q3AccessibleScrollView::text(t, child);
588 }
589 
591 void Q3AccessibleTextEdit::setText(Text t, int control, const QString &text)
592 {
593  if (t != Value || control) {
594  Q3AccessibleScrollView::setText(t, control, text);
595  return;
596  }
597  textEdit()->setText(text);
598 }
599 
602 {
603  if (child)
604  return EditableText;
605  return Q3AccessibleScrollView::role(child);
606 }
607 
626 {
628  setDescription(QLatin1String("This is a widgetstack"));
629 }
630 
633 {
634  return qobject_cast<Q3WidgetStack*>(object());
635 }
636 
639 {
640  // a widget stack has always only one accessible widget
641  return 1;
642 }
643 
646 {
647  QObject *childObject = child ? child->object() : 0;
648  if (childObject != widgetStack()->visibleWidget())
649  return -1;
650  return 1;
651 }
652 
655 {
656  QWidget *curPage = widgetStack()->visibleWidget();
657  if (!curPage)
658  return 0;
659  return 1;
660 }
661 
664  QAccessibleInterface **target) const
665 {
666  *target = 0;
667  QObject *targetObject = 0;
668  switch (rel) {
669  // Hierarchical
670  case Child:
671  if (entry != 1)
672  return -1;
673  targetObject = widgetStack()->visibleWidget();
674  break;
675  default:
676  return QAccessibleWidget::navigate(rel, entry, target);
677  }
678  *target = QAccessible::queryAccessibleInterface(targetObject);
679  return *target ? 0 : -1;
680 }
681 
700 {
701  Q_ASSERT(widget()->inherits("Q3ListBox"));
702 }
703 
705 Q3ListBox *QAccessibleListBox::listBox() const
706 {
707  return (Q3ListBox*)widget();
708 }
709 
711 int QAccessibleListBox::itemAt(int x, int y) const
712 {
713  Q3ListBoxItem *item = listBox()->itemAt(QPoint(x, y));
714  return listBox()->index(item) + 1;
715 }
716 
719 {
720  return listBox()->itemRect(listBox()->item(item-1));
721 }
722 
725 {
726  return listBox()->count();
727 }
728 
731 {
732  if (!child || t != Name)
733  return Q3AccessibleScrollView::text(t, child);
734 
735  Q3ListBoxItem *item = listBox()->item(child - 1);
736  if (item)
737  return item->text();
738  return QString();
739 }
740 
743 {
744  if (!child)
745  return Q3AccessibleScrollView::role(child);
746  return ListItem;
747 }
748 
751 {
753  Q3ListBoxItem *item;
754  if (!child || !(item = listBox()->item(child - 1)))
755  return state;
756 
757  if (item->isSelectable()) {
758  if (listBox()->selectionMode() == Q3ListBox::Multi)
759  state |= MultiSelectable;
760  else if (listBox()->selectionMode() == Q3ListBox::Extended)
761  state |= ExtSelectable;
762  else if (listBox()->selectionMode() == Q3ListBox::Single)
763  state |= Selectable;
764  if (item->isSelected())
765  state |= Selected;
766  }
767  if (listBox()->focusPolicy() != Qt::NoFocus) {
768  state |= Focusable;
769  if (item->isCurrent())
770  state |= Focused;
771  }
772  if (!listBox()->itemVisible(item))
773  state |= Invisible;
774 
775  return state;
776 }
777 
778 /* \reimp
779 bool QAccessibleListBox::setFocus(int child)
780 {
781  bool res = Q3AccessibleScrollView::setFocus(0);
782  if (!child || !res)
783  return res;
784 
785  Q3ListBoxItem *item = listBox()->item(child -1);
786  if (!item)
787  return false;
788  listBox()->setCurrentItem(item);
789  return true;
790 }*/
791 
802 bool QAccessibleListBox::setSelected(int child, bool on, bool extend)
803 {
804  if (!child || (extend &&
805  listBox()->selectionMode() != Q3ListBox::Extended &&
806  listBox()->selectionMode() != Q3ListBox::Multi))
807  return false;
808 
809  Q3ListBoxItem *item = listBox()->item(child -1);
810  if (!item)
811  return false;
812  if (!extend) {
813  listBox()->setSelected(item, on);
814  } else {
815  int current = listBox()->currentItem();
816  bool down = child > current;
817  for (int i = current; i != child;) {
818  down ? i++ : i--;
819  listBox()->setSelected(i, on);
820  }
821 
822  }
823  return true;
824 }
825 
832 {
833  listBox()->clearSelection();
834 }
835 
843 {
844  QVector<int> array;
845  uint size = 0;
846  const uint c = listBox()->count();
847  array.resize(c);
848  for (uint i = 0; i < c; ++i) {
849  if (listBox()->isSelected(i)) {
850  ++size;
851  array[(int)size-1] = i+1;
852  }
853  }
854  array.resize(size);
855  return array;
856 }
857 
T qobject_cast(QObject *object)
Definition: qobject.h:375
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Q3AccessibleTextEdit(QWidget *o)
Constructs a Q3AccessibleTextEdit object for a widget.
int itemCount() const
Reimplemented Function
int childCount() const
Reimplemented Function
bool setSelected(int child, bool on, bool extend)
Selects the item with index child if on is true; otherwise unselects it.
QVector< int > selection() const
Returns a (possibly empty) list of indexes of the items selected in the list box. ...
#define it(className, varName)
QRect itemRect(int item) const
void setText(Text t, int child, const QString &text)
Reimplemented Function
QAccessibleListBox(QWidget *o)
Constructs a QAccessibleListBox object for a widget.
Q3IconView * iconView() const
Returns the icon view.
Role
This enum defines the role of an accessible object.
Definition: qaccessible.h:188
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
State state(int child) const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int itemCount() const
Reimplemented Function
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int childAt(int x, int y) const
Reimplemented Function
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual QObject * object() const =0
Returns a pointer to the QObject this interface implementation provides information for...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QWidget * widget() const
Returns the associated widget.
QString text(Text t, int child) const
Reimplemented Function
void clearSelection()
Sets all the items in the list box to be unselected.
void setText(Text t, int control, const QString &text)
Reimplemented Function
int itemAt(int x, int y) const
Reimplemented Function
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
Q3TextEdit * textEdit() const
Returns the text edit.
Role role(int child) const
Reimplemented Function
Q3AccessibleScrollView(QWidget *w, Role role)
Constructs a Q3AccessibleScrollView object for a widget.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QRect itemRect(int item) const
Reimplemented Function
QRect rect(int child) const
Reimplemented Function
void setDescription(const QString &desc)
Sets the description of this interface implementation to desc.
RelationFlag
This enum type defines bit flags that can be combined to indicate the relationship between two access...
Definition: qaccessible.h:268
virtual int itemAt(int x, int y) const
Returns the ID of the item at viewport position x, y.
QRect itemRect(int item) const
Reimplemented Function
unsigned int uint
Definition: qglobal.h:996
int itemCount() const
Reimplemented Function
Role role(int child) const
Reimplemented Function
The State element defines configurations of objects and properties.
bool setSelected(int child, bool on, bool extend)
int itemAt(int x, int y) const
Reimplemented Function
QString text(Text t, int child) const
static Q3IconViewItem * findIVItem(Q3IconView *iconView, int child)
State state(int child) const
Reimplemented Function
int itemAt(int x, int y) const
Reimplemented Function
The QAccessibleWidget class implements the QAccessibleInterface for QWidgets.
static QAccessibleInterface * queryAccessibleInterface(QObject *)
If a QAccessibleInterface implementation exists for the given object, this function returns a pointer...
QAccessibleIconView(QWidget *o)
Constructs a QAccessibleIconView object for a widget.
virtual QRect itemRect(int item) const
Returns the location in viewport coordinates of the item with ID item.
QVector< int > selection() const
int itemAt(int x, int y) const
Q3WidgetStack * widgetStack() const
Returns the widget stack.
Role role(int child) const
Reimplemented Function
Role role(int child) const
Reimplemented Function
State
Definition: qaudio.h:59
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
The QAccessibleInterface class defines an interface that exposes information about accessible objects...
Definition: qaccessible.h:370
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
Q3ListBox * listBox() const
Returns the list box.
Role role(int child) const
State state(int child) const
Reimplemented Function
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool setSelected(int child, bool on, bool extend)
QString text(Text t, int child) const
Reimplemented Function
int navigate(RelationFlag rel, int entry, QAccessibleInterface **target) const
Reimplemented Function
QObject * object() const
Reimplemented Function
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
Q3ListView * listView() const
Returns the list view.
static Q3ListViewItem * findLVItem(Q3ListView *listView, int child)
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QVector< int > selection() const
QAccessibleWidgetStack(QWidget *o)
Creates a QAccessibleWidgetStack object for a widget.
QAccessibleListView(QWidget *o)
Constructs a QAccessibleListView object for a widget.
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
virtual int itemCount() const
Returns the number of items in the scroll view.
int navigate(RelationFlag rel, int entry, QAccessibleInterface **target) const
Reimplemented Function
QRect itemRect(int item) const
Reimplemented Function
int indexOfChild(const QAccessibleInterface *) const
Reimplemented Function
QString text(Text t, int child) const
Reimplemented Function
The Text item allows you to add formatted text to a scene.
QString text(Text t, int child) const
Reimplemented Function
State state(int child) const
Reimplemented Function