00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "q3simplewidgets.h"
00025
00026 #include <q3groupbox.h>
00027 #include <qlabel.h>
00028
00029 QString Q_GUI_EXPORT qt_accStripAmp(const QString &text);
00030
00031 Q3AccessibleDisplay::Q3AccessibleDisplay(QWidget *w, Role role)
00032 : QAccessibleWidget(w, role)
00033 {
00034 }
00035
00037 QAccessible::Role Q3AccessibleDisplay::role(int child) const
00038 {
00039 QLabel *l = qobject_cast<QLabel*>(object());
00040 if (l) {
00041 if (l->pixmap() || l->picture())
00042 return Graphic;
00043 if (l->picture())
00044 return Graphic;
00045 if (l->movie())
00046 return Animation;
00047 }
00048 return QAccessibleWidget::role(child);
00049 }
00050
00052 QString Q3AccessibleDisplay::text(Text t, int child) const
00053 {
00054 QString str;
00055 switch (t) {
00056 case Name:
00057 if (qobject_cast<QLabel*>(object())) {
00058 str = qobject_cast<QLabel*>(object())->text();
00059 } else if (qobject_cast<Q3GroupBox*>(object())) {
00060 str = qobject_cast<Q3GroupBox*>(object())->title();
00061 }
00062 break;
00063 default:
00064 break;
00065 }
00066 if (str.isEmpty())
00067 str = QAccessibleWidget::text(t, child);;
00068 return qt_accStripAmp(str);
00069 }
00070
00072 QAccessible::Relation Q3AccessibleDisplay::relationTo(int child, const QAccessibleInterface *other,
00073 int otherChild) const
00074 {
00075 Relation relation = QAccessibleWidget::relationTo(child, other, otherChild);
00076 if (child || otherChild)
00077 return relation;
00078
00079 QObject *o = other->object();
00080 QLabel *label = qobject_cast<QLabel*>(object());
00081 Q3GroupBox *groupbox = qobject_cast<Q3GroupBox*>(object());
00082 if (label) {
00083 if (o == label->buddy())
00084 relation |= Label;
00085 } else if (groupbox && !groupbox->title().isEmpty()) {
00086 if (groupbox->children().contains(o))
00087 relation |= Label;
00088 }
00089 return relation;
00090 }
00091
00093 int Q3AccessibleDisplay::navigate(RelationFlag rel, int entry, QAccessibleInterface **target) const
00094 {
00095 *target = 0;
00096 if (rel == Labelled) {
00097 QObject *targetObject = 0;
00098 QLabel *label = qobject_cast<QLabel*>(object());
00099 Q3GroupBox *groupbox = qobject_cast<Q3GroupBox*>(object());
00100 if (label) {
00101 if (entry == 1)
00102 targetObject = label->buddy();
00103 } else if (groupbox && !groupbox->title().isEmpty()) {
00104 rel = Child;
00105 }
00106 *target = QAccessible::queryAccessibleInterface(targetObject);
00107 if (*target)
00108 return 0;
00109 }
00110 return QAccessibleWidget::navigate(rel, entry, target);
00111 }
00112