source: branches/4.5.1/src/plugins/accessible/compat/q3complexwidgets.cpp@ 921

Last change on this file since 921 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "q3complexwidgets.h"
43
44#include <q3header.h>
45#include <private/q3titlebar_p.h>
46
47#include <qapplication.h>
48
49QT_BEGIN_NAMESPACE
50
51Q3AccessibleHeader::Q3AccessibleHeader(QWidget *w)
52 : QAccessibleWidget(w)
53{
54 Q_ASSERT(header());
55 addControllingSignal(QLatin1String("clicked(int)"));
56}
57
58/*! Returns the Q3Header. */
59Q3Header *Q3AccessibleHeader::header() const
60{
61 return qobject_cast<Q3Header*>(object());
62}
63
64/*! \reimp */
65QRect Q3AccessibleHeader::rect(int child) const
66{
67 QPoint zero = header()->mapToGlobal(QPoint(0, 0));
68 QRect sect = header()->sectionRect(child - 1);
69 return QRect(sect.x() + zero.x(), sect.y() + zero.y(), sect.width(), sect.height());
70}
71
72/*! \reimp */
73int Q3AccessibleHeader::childCount() const
74{
75 return header()->count();
76}
77
78/*! \reimp */
79QString Q3AccessibleHeader::text(Text t, int child) const
80{
81 QString str;
82
83 if (child <= childCount()) {
84 switch (t) {
85 case Name:
86 str = header()->label(child - 1);
87 break;
88 case Description: {
89 QAccessibleEvent event(QEvent::AccessibilityDescription, child);
90 if (QApplication::sendEvent(widget(), &event))
91 str = event.value();
92 break; }
93 case Help: {
94 QAccessibleEvent event(QEvent::AccessibilityHelp, child);
95 if (QApplication::sendEvent(widget(), &event))
96 str = event.value();
97 break; }
98 default:
99 break;
100 }
101 }
102 if (str.isEmpty())
103 str = QAccessibleWidget::text(t, child);;
104 return str;
105}
106
107/*! \reimp */
108QAccessible::Role Q3AccessibleHeader::role(int) const
109{
110 return (header()->orientation() == Qt::Horizontal) ? ColumnHeader : RowHeader;
111}
112
113/*! \reimp */
114QAccessible::State Q3AccessibleHeader::state(int child) const
115{
116 State state = QAccessibleWidget::state(child);
117
118 int section = child ? child - 1 : -1;
119 if (!header()->isClickEnabled(section))
120 state |= Unavailable;
121 else
122 state |= Selectable;
123 if (child && section == header()->sortIndicatorSection())
124 state |= Selected;
125 if (header()->isResizeEnabled(section))
126 state |= Sizeable;
127 if (child && header()->isMovingEnabled())
128 state |= Movable;
129 return state;
130}
131
132/*!
133 \class Q3AccessibleTitleBar
134 \brief The Q3AccessibleTitleBar class implements the QAccessibleInterface for title bars.
135 \internal
136
137 \ingroup accessibility
138*/
139
140/*!
141 Constructs a Q3AccessibleTitleBar object for \a w.
142*/
143Q3AccessibleTitleBar::Q3AccessibleTitleBar(QWidget *w)
144: QAccessibleWidget(w, TitleBar)
145{
146 Q_ASSERT(titleBar());
147}
148
149/*!
150 Returns the title bar.
151*/
152Q3TitleBar *Q3AccessibleTitleBar::titleBar() const
153{
154 return qobject_cast<Q3TitleBar*>(object());
155}
156
157/*! \reimp */
158QRect Q3AccessibleTitleBar::rect(int child) const
159{
160 if (!child)
161 return QAccessibleWidget::rect(child);
162
163 QStyle::SubControl sc;
164 switch (child) {
165 case 1:
166 sc = QStyle::SC_TitleBarSysMenu;
167 break;
168 case 2:
169 sc = QStyle::SC_TitleBarLabel;
170 break;
171 case 3:
172 sc = QStyle::SC_TitleBarMinButton;
173 break;
174 case 4:
175 sc = QStyle::SC_TitleBarMaxButton;
176 break;
177 case 5:
178 sc = QStyle::SC_TitleBarCloseButton;
179 break;
180 default:
181 sc = QStyle::SC_None;
182 break;
183 }
184
185 QRect r;
186 if (sc != QStyle::SC_None) {
187 QStyleOptionTitleBar option;
188 r = titleBar()->style()->subControlRect(QStyle::CC_TitleBar, &option, sc, titleBar());
189 }
190
191 QPoint tp = titleBar()->mapToGlobal(QPoint(0,0));
192 return QRect(tp.x() + r.x(), tp.y() + r.y(), r.width(), r.height());
193}
194
195/* \reimp
196int Q3AccessibleTitleBar::navigate(NavDirection direction, int startControl) const
197{
198 if (direction != NavFirstChild && direction != NavLastChild && direction != NavFocusChild && !startControl)
199 return QAccessibleWidget::navigate(direction, startControl);
200
201 switch (direction) {
202 case NavFirstChild:
203 return 1;
204 break;
205 case NavLastChild:
206 return childCount();
207 break;
208 case NavNext:
209 case NavRight:
210 return startControl + 1 > childCount() ? -1 : startControl + 1;
211 case NavPrevious:
212 case NavLeft:
213 return startControl -1 < 1 ? -1 : startControl - 1;
214 default:
215 break;
216 }
217 return -1;
218}
219*/
220
221/*! \reimp */
222int Q3AccessibleTitleBar::childCount() const
223{
224 if (!(titleBar()->windowFlags() & Qt::WStyle_SysMenu))
225 return 0;
226 int control = 3;
227 if (!(titleBar()->windowFlags() & Qt::WStyle_Minimize))
228 ++control;
229 if (!(titleBar()->windowFlags() & Qt::WStyle_Maximize))
230 ++control;
231 return control;
232}
233
234/*! \reimp */
235QString Q3AccessibleTitleBar::text(Text t, int child) const
236{
237 QString str = QAccessibleWidget::text(t, child);
238 if (str.size())
239 return str;
240
241 QWidget *window = titleBar()->window();
242 switch (t) {
243 case Name:
244 switch (child) {
245 case 1:
246 return Q3TitleBar::tr("System");
247 case 3:
248 if (window && window->isMinimized())
249 return Q3TitleBar::tr("Restore up");
250 return Q3TitleBar::tr("Minimize");
251 case 4:
252 if (window && window->isMaximized())
253 return Q3TitleBar::tr("Restore down");
254 return Q3TitleBar::tr("Maximize");
255 case 5:
256 return Q3TitleBar::tr("Close");
257 default:
258 break;
259 }
260 break;
261 case Value:
262 if (!child || child == 2)
263 return window ? window->windowTitle() : QString();
264 break;
265/*
266 case DefaultAction:
267 if (child > 2)
268 return Q3TitleBar::tr("Press");
269 break;
270*/
271 case Description:
272 switch (child) {
273 case 1:
274 return Q3TitleBar::tr("Contains commands to manipulate the window");
275 case 3:
276 if (window && window->isMinimized())
277 return Q3TitleBar::tr("Puts a minimized back to normal");
278 return Q3TitleBar::tr("Moves the window out of the way");
279 case 4:
280 if (window && window->isMaximized())
281 return Q3TitleBar::tr("Puts a maximized window back to normal");
282 return Q3TitleBar::tr("Makes the window full screen");
283 case 5:
284 return Q3TitleBar::tr("Closes the window");
285 default:
286 return Q3TitleBar::tr("Displays the name of the window and contains controls to manipulate it");
287 }
288 default:
289 break;
290 }
291 return str;
292}
293
294/*! \reimp */
295QAccessible::Role Q3AccessibleTitleBar::role(int child) const
296{
297 switch (child)
298 {
299 case 1:
300 case 3:
301 case 4:
302 case 5:
303 return PushButton;
304 default:
305 return TitleBar;
306 }
307}
308
309/*! \reimp */
310QAccessible::State Q3AccessibleTitleBar::state(int child) const
311{
312 return QAccessibleWidget::state(child);
313}
314
315/*! \reimp */
316bool Q3AccessibleTitleBar::doAction(int, int child, const QVariantList &)
317{
318 switch (child) {
319 case 3:
320 if (titleBar()->window()->isMinimized())
321 titleBar()->window()->showNormal();
322 else
323 titleBar()->window()->showMinimized();
324 return true;
325 case 4:
326 if (titleBar()->window()->isMaximized())
327 titleBar()->window()->showNormal();
328 else
329 titleBar()->window()->showMaximized();
330 return true;
331 case 5:
332 titleBar()->window()->close();
333 return true;
334 default:
335 break;
336 }
337 return false;
338}
339
340QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.