src/plugins/accessible/compat/q3simplewidgets.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the plugins of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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 

Generated on Thu Mar 15 11:57:33 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1