Qt 4.8
Classes | Functions
qaccessiblewidget.cpp File Reference
#include "qaccessiblewidget.h"
#include "qaction.h"
#include "qapplication.h"
#include "qgroupbox.h"
#include "qlabel.h"
#include "qtooltip.h"
#include "qwhatsthis.h"
#include "qwidget.h"
#include "qdebug.h"
#include <qmath.h>
#include <QRubberBand>
#include <QtGui/QFocusFrame>
#include <QtGui/QMenu>
#include <private/qobject_p.h>

Go to the source code of this file.

Classes

class  QAccessibleWidgetPrivate
 
class  QACConnectionObject
 

Functions

static QString buddyString (const QWidget *widget)
 
static QList< QWidget * > childWidgets (const QWidget *widget)
 
static bool isAncestor (const QObject *obj, const QObject *child)
 
static int qt_accAmpIndex (const QString &text)
 
QString Q_GUI_EXPORT qt_accHotKey (const QString &text)
 
QString Q_GUI_EXPORT qt_accStripAmp (const QString &text)
 
QString qt_setWindowTitle_helperHelper (const QString &, const QWidget *)
 Returns a modified window title with the [*] place holder replaced according to the rules described in QWidget::setWindowTitle. More...
 

Function Documentation

◆ buddyString()

static QString buddyString ( const QWidget widget)
static

Definition at line 78 of file qaccessiblewidget.cpp.

Referenced by QAccessibleWidget::text().

79 {
80  if (!widget)
81  return QString();
82  QWidget *parent = widget->parentWidget();
83  if (!parent)
84  return QString();
85 #ifndef QT_NO_SHORTCUT
86  QObjectList ol = parent->children();
87  for (int i = 0; i < ol.size(); ++i) {
88  QLabel *label = qobject_cast<QLabel*>(ol.at(i));
89  if (label && label->buddy() == widget)
90  return label->text();
91  }
92 #endif
93 
94 #ifndef QT_NO_GROUPBOX
95  QGroupBox *groupbox = qobject_cast<QGroupBox*>(parent);
96  if (groupbox)
97  return groupbox->title();
98 #endif
99 
100  return QString();
101 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
QPointer< QWidget > widget
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QWidget * buddy() const
Returns this label&#39;s buddy, or 0 if no buddy is currently set.
Definition: qlabel.cpp:1319
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QGroupBox widget provides a group box frame with a title.
Definition: qgroupbox.h:57
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QLabel widget provides a text or image display.
Definition: qlabel.h:55
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
QString title
the group box title text
Definition: qgroupbox.h:61
QString text
the label&#39;s text
Definition: qlabel.h:58

◆ childWidgets()

static QList<QWidget*> childWidgets ( const QWidget widget)
static

Definition at line 61 of file qaccessiblewidget.cpp.

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

62 {
63  QList<QObject*> list = widget->children();
64  QList<QWidget*> widgets;
65  for (int i = 0; i < list.size(); ++i) {
66  QWidget *w = qobject_cast<QWidget *>(list.at(i));
67  if (w && !w->isWindow()
68  && !qobject_cast<QFocusFrame*>(w)
69 #if !defined(QT_NO_MENU)
70  && !qobject_cast<QMenu*>(w)
71 #endif
72  && w->objectName() != QLatin1String("qt_rubberband"))
73  widgets.append(w);
74  }
75  return widgets;
76 }
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
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
#define QT_NO_MENU
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
The QFocusFrame widget provides a focus frame which can be outside of a widget&#39;s normal paintable are...
Definition: qfocusframe.h:56
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ isAncestor()

static bool isAncestor ( const QObject obj,
const QObject child 
)
inlinestatic

Definition at line 367 of file qaccessiblewidget.cpp.

Referenced by QAccessibleWidget::navigate(), and QAccessibleWidget::relationTo().

368 {
369  while (child) {
370  if (child == obj)
371  return true;
372  child = child->parent();
373  }
374  return false;
375 }
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273

◆ qt_accAmpIndex()

static int qt_accAmpIndex ( const QString text)
static

Definition at line 106 of file qaccessiblewidget.cpp.

Referenced by qt_accHotKey(), and qt_accStripAmp().

107 {
108 #ifndef QT_NO_SHORTCUT
109  if (text.isEmpty())
110  return -1;
111 
112  int fa = 0;
113  QChar ac;
114  while ((fa = text.indexOf(QLatin1Char('&'), fa)) != -1) {
115  ++fa;
116  if (fa < text.length()) {
117  // ignore "&&"
118  if (text.at(fa) == QLatin1Char('&')) {
119  ++fa;
120  continue;
121  } else {
122  return fa - 1;
123  break;
124  }
125  }
126  }
127 
128  return -1;
129 #else
130  Q_UNUSED(text);
131  return -1;
132 #endif
133 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
#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
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ qt_accHotKey()

QString Q_GUI_EXPORT qt_accHotKey ( const QString text)

Definition at line 145 of file qaccessiblewidget.cpp.

Referenced by QAccessibleButton::text(), QAccessibleWidget::text(), QAccessibleMenuBar::text(), and QAccessibleMenuItem::text().

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 QAccessibleMenu::text(), QAccessibleButton::text(), QAccessibleWidget::text(), QAccessibleMenuBar::text(), QAccessibleToolButton::text(), QAccessibleDisplay::text(), QAccessibleMenuItem::text(), QAccessibleGroupBox::text(), QAccessibleLineEdit::text(), QAccessibleTabBar::text(), and 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)

◆ qt_setWindowTitle_helperHelper()

QString qt_setWindowTitle_helperHelper ( const QString title,
const QWidget widget 
)

Returns a modified window title with the [*] place holder replaced according to the rules described in QWidget::setWindowTitle.

This function assumes that "[*]" can be quoted by another "[*]", so it will replace two place holders by one and a single last one by either "*" or nothing depending on the modified flag.

Warning
This function is not part of the public interface.

Definition at line 6240 of file qwidget.cpp.

Referenced by QAccessibleWidget::indexOfChild(), tabTextFor(), and QAccessibleWidget::text().

6241 {
6242  Q_ASSERT(widget);
6243 
6244 #ifdef QT_EVAL
6245  extern QString qt_eval_adapt_window_title(const QString &title);
6246  QString cap = qt_eval_adapt_window_title(title);
6247 #else
6248  QString cap = title;
6249 #endif
6250 
6251  if (cap.isEmpty())
6252  return cap;
6253 
6254  QLatin1String placeHolder("[*]");
6255  int placeHolderLength = 3; // QLatin1String doesn't have length()
6256 
6257  int index = cap.indexOf(placeHolder);
6258 
6259  // here the magic begins
6260  while (index != -1) {
6261  index += placeHolderLength;
6262  int count = 1;
6263  while (cap.indexOf(placeHolder, index) == index) {
6264  ++count;
6265  index += placeHolderLength;
6266  }
6267 
6268  if (count%2) { // odd number of [*] -> replace last one
6269  int lastIndex = cap.lastIndexOf(placeHolder, index - 1);
6270  if (widget->isWindowModified()
6271  && widget->style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, widget))
6272  cap.replace(lastIndex, 3, QWidget::tr("*"));
6273  else
6274  cap.remove(lastIndex, 3);
6275  }
6276 
6277  index = cap.indexOf(placeHolder, index);
6278  }
6279 
6280  cap.replace(QLatin1String("[*][*]"), placeHolder);
6281 
6282  return cap;
6283 }
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QStyle * style() const
Definition: qwidget.cpp:2742
bool isWindowModified() const
Definition: qwidget.cpp:11554
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
quint16 index
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867