|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the plugins of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
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 |
|
49 QT_BEGIN_NAMESPACE |
|
50 |
|
51 Q3AccessibleHeader::Q3AccessibleHeader(QWidget *w) |
|
52 : QAccessibleWidget(w) |
|
53 { |
|
54 Q_ASSERT(header()); |
|
55 addControllingSignal(QLatin1String("clicked(int)")); |
|
56 } |
|
57 |
|
58 /*! Returns the Q3Header. */ |
|
59 Q3Header *Q3AccessibleHeader::header() const |
|
60 { |
|
61 return qobject_cast<Q3Header*>(object()); |
|
62 } |
|
63 |
|
64 /*! \reimp */ |
|
65 QRect 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 */ |
|
73 int Q3AccessibleHeader::childCount() const |
|
74 { |
|
75 return header()->count(); |
|
76 } |
|
77 |
|
78 /*! \reimp */ |
|
79 QString 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 */ |
|
108 QAccessible::Role Q3AccessibleHeader::role(int) const |
|
109 { |
|
110 return (header()->orientation() == Qt::Horizontal) ? ColumnHeader : RowHeader; |
|
111 } |
|
112 |
|
113 /*! \reimp */ |
|
114 QAccessible::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 */ |
|
143 Q3AccessibleTitleBar::Q3AccessibleTitleBar(QWidget *w) |
|
144 : QAccessibleWidget(w, TitleBar) |
|
145 { |
|
146 Q_ASSERT(titleBar()); |
|
147 } |
|
148 |
|
149 /*! |
|
150 Returns the title bar. |
|
151 */ |
|
152 Q3TitleBar *Q3AccessibleTitleBar::titleBar() const |
|
153 { |
|
154 return qobject_cast<Q3TitleBar*>(object()); |
|
155 } |
|
156 |
|
157 /*! \reimp */ |
|
158 QRect 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 |
|
196 int 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 */ |
|
222 int 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 */ |
|
235 QString 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 window 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 */ |
|
295 QAccessible::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 */ |
|
310 QAccessible::State Q3AccessibleTitleBar::state(int child) const |
|
311 { |
|
312 return QAccessibleWidget::state(child); |
|
313 } |
|
314 |
|
315 /*! \reimp */ |
|
316 bool 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 |
|
340 QT_END_NAMESPACE |