Qt 4.8
Functions
qaccessiblewidgets.cpp File Reference
#include "qaccessiblewidgets.h"
#include "qabstracttextdocumentlayout.h"
#include "qapplication.h"
#include "qclipboard.h"
#include "qtextedit.h"
#include "private/qtextedit_p.h"
#include "qtextdocument.h"
#include "qtextobject.h"
#include "qplaintextedit.h"
#include "qscrollbar.h"
#include "qdebug.h"
#include <QApplication>
#include <QStackedWidget>
#include <QToolBox>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QWorkspace>
#include <QDialogButtonBox>
#include <limits.h>
#include <QRubberBand>
#include <QTextBrowser>
#include <QCalendarWidget>
#include <QAbstractItemView>
#include <QDockWidget>
#include <QMainWindow>
#include <QAbstractButton>
#include <private/qdockwidget_p.h>
#include <QtGui/QFocusFrame>

Go to the source code of this file.

Functions

QList< QWidget * > childWidgets (const QWidget *widget, bool includeTopLevel)
 
static int distance (QWidget *source, QWidget *target, QAccessible::RelationFlag relation)
 
static QWidgetmdiAreaNavigate (QWidget *area, QAccessible::RelationFlag relation, int entry)
 
QString Q_GUI_EXPORT qt_accHotKey (const QString &text)
 
QString Q_GUI_EXPORT qt_accStripAmp (const QString &text)
 
static QTextBlock qTextBlockAt (const QTextDocument *doc, int pos)
 
static int qTextBlockPosition (QTextBlock block)
 

Function Documentation

◆ childWidgets()

QList<QWidget*> childWidgets ( const QWidget widget,
bool  includeTopLevel 
)

Definition at line 80 of file qaccessiblewidgets.cpp.

Referenced by QAccessibleMainWindow::childAt(), QAccessibleMainWindow::childCount(), QAccessibleMainWindow::indexOfChild(), and QAccessibleMainWindow::navigate().

81 {
82  if (widget == 0)
83  return QList<QWidget*>();
84  QList<QObject*> list = widget->children();
85  QList<QWidget*> widgets;
86  for (int i = 0; i < list.size(); ++i) {
87  QWidget *w = qobject_cast<QWidget *>(list.at(i));
88  if (!w)
89  continue;
90  QString objectName = w->objectName();
91  if ((includeTopLevel || !w->isWindow())
92  && !qobject_cast<QFocusFrame*>(w)
93  && !qobject_cast<QMenu*>(w)
94  && objectName != QLatin1String("qt_rubberband")
95  && objectName != QLatin1String("qt_qmainwindow_extended_splitter")) {
96  widgets.append(w);
97  }
98  }
99  return widgets;
100 }
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QString objectName() const
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197

◆ distance()

static int distance ( QWidget source,
QWidget target,
QAccessible::RelationFlag  relation 
)
inlinestatic

Definition at line 102 of file qaccessiblewidgets.cpp.

Referenced by QDeclarativeTimeLine::accelDistance(), QListViewPrivate::closestIndex(), QIconLoaderEngine::entryForSize(), QGraphicsScenePrivate::findClosestTouchPointId(), QApplicationPrivate::findClosestTouchPointId(), findEncoding(), QDeclarativePathViewPrivate::handleMousePressEvent(), mdiAreaNavigate(), QTextEditPrivate::pageUpDown(), QSwipeGestureRecognizer::recognize(), QMacPrintEngine::setProperty(), QDeclarativePathViewPrivate::snapToCurrent(), and QDeclarativePathViewPrivate::updateHighlight().

104 {
105  if (!source || !target)
106  return -1;
107 
108  int returnValue = -1;
109  switch (relation) {
110  case QAccessible::Up:
111  if (target->y() <= source->y())
112  returnValue = source->y() - target->y();
113  break;
114  case QAccessible::Down:
115  if (target->y() >= source->y() + source->height())
116  returnValue = target->y() - (source->y() + source->height());
117  break;
118  case QAccessible::Right:
119  if (target->x() >= source->x() + source->width())
120  returnValue = target->x() - (source->x() + source->width());
121  break;
122  case QAccessible::Left:
123  if (target->x() <= source->x())
124  returnValue = source->x() - target->x();
125  break;
126  default:
127  break;
128  }
129  return returnValue;
130 }
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
int x
the x coordinate of the widget relative to its parent including any window frame
Definition: qwidget.h:161
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
int y
the y coordinate of the widget relative to its parent and including any window frame ...
Definition: qwidget.h:162

◆ mdiAreaNavigate()

static QWidget* mdiAreaNavigate ( QWidget area,
QAccessible::RelationFlag  relation,
int  entry 
)
inlinestatic

Definition at line 132 of file qaccessiblewidgets.cpp.

Referenced by QAccessibleMdiArea::navigate(), QAccessibleMdiSubWindow::navigate(), and QAccessibleWorkspace::navigate().

134 {
135 #if defined(QT_NO_MDIAREA) && defined(QT_NO_WORKSPACE)
136  Q_UNUSED(area);
137 #endif
138 #ifndef QT_NO_MDIAREA
139  const QMdiArea *mdiArea = qobject_cast<QMdiArea *>(area);
140 #endif
141 #ifndef QT_NO_WORKSPACE
142  const QWorkspace *workspace = qobject_cast<QWorkspace *>(area);
143 #endif
144  if (true
145 #ifndef QT_NO_MDIAREA
146  && !mdiArea
147 #endif
148 #ifndef QT_NO_WORKSPACE
149  && !workspace
150 #endif
151  )
152  return 0;
153 
154  QWidgetList windows;
155 #ifndef QT_NO_MDIAREA
156  if (mdiArea) {
157  foreach (QMdiSubWindow *window, mdiArea->subWindowList())
158  windows.append(window);
159  } else
160 #endif
161  {
162 #ifndef QT_NO_WORKSPACE
163  foreach (QWidget *window, workspace->windowList())
164  windows.append(window->parentWidget());
165 #endif
166  }
167 
168  if (windows.isEmpty() || entry < 1 || entry > windows.count())
169  return 0;
170 
171  QWidget *source = windows.at(entry - 1);
172  QMap<int, QWidget *> candidates;
173  foreach (QWidget *window, windows) {
174  if (source == window)
175  continue;
176  int candidateDistance = distance(source, window, relation);
177  if (candidateDistance >= 0)
178  candidates.insert(candidateDistance, window);
179  }
180 
181  int minimumDistance = INT_MAX;
182  QWidget *target = 0;
183  foreach (QWidget *candidate, candidates) {
184  switch (relation) {
185  case QAccessible::Up:
186  case QAccessible::Down:
187  if (qAbs(candidate->x() - source->x()) < minimumDistance) {
188  target = candidate;
189  minimumDistance = qAbs(candidate->x() - source->x());
190  }
191  break;
192  case QAccessible::Left:
193  case QAccessible::Right:
194  if (qAbs(candidate->y() - source->y()) < minimumDistance) {
195  target = candidate;
196  minimumDistance = qAbs(candidate->y() - source->y());
197  }
198  break;
199  default:
200  break;
201  }
202  if (minimumDistance == 0)
203  break;
204  }
205 
206 #ifndef QT_NO_WORKSPACE
207  if (workspace) {
208  foreach (QWidget *widget, workspace->windowList()) {
209  if (widget->parentWidget() == target)
210  target = widget;
211  }
212  }
213 #endif
214  return target;
215 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
#define QT_NO_WORKSPACE
QPointer< QWidget > widget
#define QT_NO_MDIAREA
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
T * qobject_cast(QObject *object)
Definition: qobject.h:375
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
int x
the x coordinate of the widget relative to its parent including any window frame
Definition: qwidget.h:161
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QWorkspace widget provides a workspace window that can be used in an MDI application.
Definition: qworkspace.h:60
NSWindow * window
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QMdiArea widget provides an area in which MDI windows are displayed.
Definition: qmdiarea.h:59
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QMdiSubWindow * > subWindowList(WindowOrder order=CreationOrder) const
Returns a list of all subwindows in the MDI area.
Definition: qmdiarea.cpp:1888
static int distance(QWidget *source, QWidget *target, QAccessible::RelationFlag relation)
int y
the y coordinate of the widget relative to its parent and including any window frame ...
Definition: qwidget.h:162
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
#define INT_MAX
The QMdiSubWindow class provides a subwindow class for QMdiArea.
Definition: qmdisubwindow.h:60
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ qt_accHotKey()

QString Q_GUI_EXPORT qt_accHotKey ( const QString text)

Definition at line 145 of file qaccessiblewidget.cpp.

146 {
147  int ampIndex = qt_accAmpIndex(text);
148  if (ampIndex != -1)
149  return (QString)QKeySequence(Qt::ALT) + text.at(ampIndex + 1);
150 
151  return QString();
152 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QString class provides a Unicode character string.
Definition: qstring.h:83
static int qt_accAmpIndex(const QString &text)
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72

◆ qt_accStripAmp()

QString Q_GUI_EXPORT qt_accStripAmp ( const QString text)

Definition at line 135 of file qaccessiblewidget.cpp.

Referenced by QAccessibleTitleBar::text().

136 {
137  QString newText(text);
138  int ampIndex = qt_accAmpIndex(newText);
139  if (ampIndex != -1)
140  newText.remove(ampIndex, 1);
141 
142  return newText.replace(QLatin1String("&&"), QLatin1String("&"));
143 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static int qt_accAmpIndex(const QString &text)

◆ qTextBlockAt()

static QTextBlock qTextBlockAt ( const QTextDocument doc,
int  pos 
)
static

Definition at line 228 of file qaccessiblewidgets.cpp.

Referenced by QAccessibleTextEdit::rect(), QAccessibleTextEdit::setText(), and QAccessibleTextEdit::text().

229 {
230  Q_ASSERT(pos >= 0);
231 
232  QTextBlock block = doc->begin();
233  int i = 0;
234  while (block.isValid() && i < pos) {
235  block = block.next();
236  ++i;
237  }
238  return block;
239 }
QTextBlock begin() const
Returns the document&#39;s first text block.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208

◆ qTextBlockPosition()

static int qTextBlockPosition ( QTextBlock  block)
static

Definition at line 241 of file qaccessiblewidgets.cpp.

Referenced by QAccessibleTextEdit::childAt().

242 {
243  int child = 0;
244  while (block.isValid()) {
245  block = block.previous();
246  ++child;
247  }
248 
249  return child;
250 }
QTextBlock previous() const
Returns the text block in the document before this block, or an empty text block if this is the first...
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208