author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
child 5 | d3bac044e0f0 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module 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 "qapplication.h" |
|
43 |
#include "qapplication_p.h" |
|
44 |
#include "qbrush.h" |
|
45 |
#include "qcursor.h" |
|
46 |
#include "qdesktopwidget.h" |
|
47 |
#include "qevent.h" |
|
48 |
#include "qhash.h" |
|
49 |
#include "qlayout.h" |
|
50 |
#include "qmenu.h" |
|
51 |
#include "qmetaobject.h" |
|
52 |
#include "qpixmap.h" |
|
53 |
#include "qpointer.h" |
|
54 |
#include "qstack.h" |
|
55 |
#include "qstyle.h" |
|
56 |
#include "qstylefactory.h" |
|
57 |
#include "qvariant.h" |
|
58 |
#include "qwidget.h" |
|
59 |
#include "qstyleoption.h" |
|
60 |
#ifndef QT_NO_ACCESSIBILITY |
|
61 |
# include "qaccessible.h" |
|
62 |
#endif |
|
63 |
#if defined(Q_WS_WIN) |
|
64 |
# include "qt_windows.h" |
|
65 |
#endif |
|
66 |
#ifdef Q_WS_MAC |
|
67 |
# include "qt_mac_p.h" |
|
68 |
# include "qt_cocoa_helpers_mac_p.h" |
|
69 |
# include "qmainwindow.h" |
|
70 |
#endif |
|
71 |
#if defined(Q_WS_QWS) |
|
72 |
# include "qwsdisplay_qws.h" |
|
73 |
# include "qwsmanager_qws.h" |
|
74 |
# include "qpaintengine.h" // for PorterDuff |
|
75 |
# include "private/qwindowsurface_qws_p.h" |
|
76 |
#endif |
|
77 |
#include "qpainter.h" |
|
78 |
#include "qtooltip.h" |
|
79 |
#include "qwhatsthis.h" |
|
80 |
#include "qdebug.h" |
|
81 |
#include "private/qstylesheetstyle_p.h" |
|
82 |
#include "private/qstyle_p.h" |
|
83 |
#include "private/qinputcontext_p.h" |
|
84 |
#include "qfileinfo.h" |
|
85 |
#include "private/qsoftkeymanager_p.h" |
|
86 |
||
87 |
#if defined (Q_WS_WIN) |
|
88 |
# include <private/qwininputcontext_p.h> |
|
89 |
#endif |
|
90 |
||
91 |
#if defined(Q_WS_X11) |
|
92 |
# include <private/qpaintengine_x11_p.h> |
|
93 |
# include "qx11info_x11.h" |
|
94 |
#endif |
|
95 |
||
96 |
#include <private/qgraphicseffect_p.h> |
|
97 |
#include <private/qwindowsurface_p.h> |
|
98 |
#include <private/qbackingstore_p.h> |
|
99 |
#ifdef Q_WS_MAC |
|
100 |
# include <private/qpaintengine_mac_p.h> |
|
101 |
#endif |
|
102 |
#include <private/qpaintengine_raster_p.h> |
|
103 |
||
104 |
#if defined(Q_OS_SYMBIAN) |
|
105 |
#include "private/qt_s60_p.h" |
|
106 |
#endif |
|
107 |
||
108 |
#include "qwidget_p.h" |
|
109 |
#include "qaction_p.h" |
|
110 |
#include "qlayout_p.h" |
|
111 |
#include "QtGui/qgraphicsproxywidget.h" |
|
112 |
#include "QtGui/qgraphicsscene.h" |
|
113 |
#include "private/qgraphicsproxywidget_p.h" |
|
114 |
#include "QtGui/qabstractscrollarea.h" |
|
115 |
#include "private/qabstractscrollarea_p.h" |
|
116 |
#include "private/qevent_p.h" |
|
117 |
||
118 |
#include "private/qgraphicssystem_p.h" |
|
119 |
#include "private/qgesturemanager_p.h" |
|
120 |
||
121 |
// widget/widget data creation count |
|
122 |
//#define QWIDGET_EXTRA_DEBUG |
|
123 |
//#define ALIEN_DEBUG |
|
124 |
||
125 |
QT_BEGIN_NAMESPACE |
|
126 |
||
127 |
#if !defined(Q_WS_QWS) |
|
128 |
static bool qt_enable_backingstore = true; |
|
129 |
#endif |
|
130 |
#ifdef Q_WS_X11 |
|
131 |
// for compatibility with Qt 4.0 |
|
132 |
Q_GUI_EXPORT void qt_x11_set_global_double_buffer(bool enable) |
|
133 |
{ |
|
134 |
qt_enable_backingstore = enable; |
|
135 |
} |
|
136 |
#endif |
|
137 |
||
138 |
static inline bool qRectIntersects(const QRect &r1, const QRect &r2) |
|
139 |
{ |
|
140 |
return (qMax(r1.left(), r2.left()) <= qMin(r1.right(), r2.right()) && |
|
141 |
qMax(r1.top(), r2.top()) <= qMin(r1.bottom(), r2.bottom())); |
|
142 |
} |
|
143 |
||
144 |
static inline bool hasBackingStoreSupport() |
|
145 |
{ |
|
146 |
#ifdef Q_WS_MAC |
|
147 |
return QApplicationPrivate::graphicsSystem() != 0; |
|
148 |
#else |
|
149 |
return true; |
|
150 |
#endif |
|
151 |
} |
|
152 |
||
153 |
#ifdef Q_WS_MAC |
|
154 |
# define QT_NO_PAINT_DEBUG |
|
155 |
#endif |
|
156 |
||
157 |
extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp |
|
158 |
extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp |
|
159 |
||
160 |
QWidgetPrivate::QWidgetPrivate(int version) |
|
161 |
: QObjectPrivate(version) |
|
162 |
, extra(0) |
|
163 |
, focus_next(0) |
|
164 |
, focus_prev(0) |
|
165 |
, focus_child(0) |
|
166 |
, layout(0) |
|
167 |
, needsFlush(0) |
|
168 |
, redirectDev(0) |
|
169 |
, widgetItem(0) |
|
170 |
, extraPaintEngine(0) |
|
171 |
, polished(0) |
|
172 |
, graphicsEffect(0) |
|
173 |
#if !defined(QT_NO_IM) |
|
174 |
, imHints(Qt::ImhNone) |
|
175 |
#endif |
|
176 |
, inheritedFontResolveMask(0) |
|
177 |
, inheritedPaletteResolveMask(0) |
|
178 |
, leftmargin(0) |
|
179 |
, topmargin(0) |
|
180 |
, rightmargin(0) |
|
181 |
, bottommargin(0) |
|
182 |
, leftLayoutItemMargin(0) |
|
183 |
, topLayoutItemMargin(0) |
|
184 |
, rightLayoutItemMargin(0) |
|
185 |
, bottomLayoutItemMargin(0) |
|
186 |
, hd(0) |
|
187 |
, size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred) |
|
188 |
, fg_role(QPalette::NoRole) |
|
189 |
, bg_role(QPalette::NoRole) |
|
190 |
, dirtyOpaqueChildren(1) |
|
191 |
, isOpaque(0) |
|
192 |
, inDirtyList(0) |
|
193 |
, isScrolled(0) |
|
194 |
, isMoved(0) |
|
195 |
, usesDoubleBufferedGLContext(0) |
|
196 |
#if defined(Q_WS_X11) |
|
197 |
, picture(0) |
|
198 |
#elif defined(Q_WS_WIN) |
|
199 |
, noPaintOnScreen(0) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
, nativeGesturePanEnabled(0) |
0 | 201 |
#elif defined(Q_WS_MAC) |
202 |
, needWindowChange(0) |
|
203 |
, isGLWidget(0) |
|
204 |
, window_event(0) |
|
205 |
, qd_hd(0) |
|
206 |
#endif |
|
207 |
{ |
|
208 |
if (!qApp) { |
|
209 |
qFatal("QWidget: Must construct a QApplication before a QPaintDevice"); |
|
210 |
return; |
|
211 |
} |
|
212 |
||
213 |
if (version != QObjectPrivateVersion) |
|
214 |
qFatal("Cannot mix incompatible Qt libraries"); |
|
215 |
||
216 |
isWidget = true; |
|
217 |
memset(high_attributes, 0, sizeof(high_attributes)); |
|
218 |
#ifdef QWIDGET_EXTRA_DEBUG |
|
219 |
static int count = 0; |
|
220 |
qDebug() << "widgets" << ++count; |
|
221 |
#endif |
|
222 |
} |
|
223 |
||
224 |
||
225 |
QWidgetPrivate::~QWidgetPrivate() |
|
226 |
{ |
|
227 |
if (widgetItem) |
|
228 |
widgetItem->wid = 0; |
|
229 |
||
230 |
if (extra) |
|
231 |
deleteExtra(); |
|
232 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
233 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 234 |
delete graphicsEffect; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
235 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 236 |
} |
237 |
||
238 |
QWindowSurface *QWidgetPrivate::createDefaultWindowSurface() |
|
239 |
{ |
|
240 |
Q_Q(QWidget); |
|
241 |
if (QApplicationPrivate::graphicsSystem()) |
|
242 |
return QApplicationPrivate::graphicsSystem()->createWindowSurface(q); |
|
243 |
return createDefaultWindowSurface_sys(); |
|
244 |
} |
|
245 |
||
246 |
/*! |
|
247 |
\internal |
|
248 |
*/ |
|
249 |
void QWidgetPrivate::scrollChildren(int dx, int dy) |
|
250 |
{ |
|
251 |
Q_Q(QWidget); |
|
252 |
if (q->children().size() > 0) { // scroll children |
|
253 |
QPoint pd(dx, dy); |
|
254 |
QObjectList childObjects = q->children(); |
|
255 |
for (int i = 0; i < childObjects.size(); ++i) { // move all children |
|
256 |
QWidget *w = qobject_cast<QWidget*>(childObjects.at(i)); |
|
257 |
if (w && !w->isWindow()) { |
|
258 |
QPoint oldp = w->pos(); |
|
259 |
QRect r(w->pos() + pd, w->size()); |
|
260 |
w->data->crect = r; |
|
261 |
#ifndef Q_WS_QWS |
|
262 |
if (w->testAttribute(Qt::WA_WState_Created)) |
|
263 |
w->d_func()->setWSGeometry(); |
|
264 |
#endif |
|
265 |
w->d_func()->setDirtyOpaqueRegion(); |
|
266 |
QMoveEvent e(r.topLeft(), oldp); |
|
267 |
QApplication::sendEvent(w, &e); |
|
268 |
} |
|
269 |
} |
|
270 |
} |
|
271 |
} |
|
272 |
||
273 |
QInputContext *QWidgetPrivate::inputContext() const |
|
274 |
{ |
|
275 |
#ifndef QT_NO_IM |
|
276 |
if (ic) |
|
277 |
return ic; |
|
278 |
#endif |
|
279 |
return qApp->inputContext(); |
|
280 |
} |
|
281 |
||
282 |
/*! |
|
283 |
This function returns the QInputContext for this widget. By |
|
284 |
default the input context is inherited from the widgets |
|
285 |
parent. For toplevels it is inherited from QApplication. |
|
286 |
||
287 |
You can override this and set a special input context for this |
|
288 |
widget by using the setInputContext() method. |
|
289 |
||
290 |
\sa setInputContext() |
|
291 |
*/ |
|
292 |
QInputContext *QWidget::inputContext() |
|
293 |
{ |
|
294 |
Q_D(QWidget); |
|
295 |
if (!testAttribute(Qt::WA_InputMethodEnabled)) |
|
296 |
return 0; |
|
297 |
||
298 |
return d->inputContext(); |
|
299 |
} |
|
300 |
||
301 |
/*! |
|
302 |
This function sets the input context \a context |
|
303 |
on this widget. |
|
304 |
||
305 |
\sa inputContext() |
|
306 |
*/ |
|
307 |
void QWidget::setInputContext(QInputContext *context) |
|
308 |
{ |
|
309 |
Q_D(QWidget); |
|
310 |
if (!testAttribute(Qt::WA_InputMethodEnabled)) |
|
311 |
return; |
|
312 |
#ifndef QT_NO_IM |
|
313 |
if (d->ic) |
|
314 |
delete d->ic; |
|
315 |
d->ic = context; |
|
316 |
#endif |
|
317 |
} |
|
318 |
||
319 |
||
320 |
/*! |
|
321 |
\obsolete |
|
322 |
||
323 |
This function can be called on the widget that currently has focus |
|
324 |
to reset the input method operating on it. |
|
325 |
||
326 |
This function is providing for convenience, instead you should use |
|
327 |
\l{QInputContext::}{reset()} on the input context that was |
|
328 |
returned by inputContext(). |
|
329 |
||
330 |
\sa QInputContext, inputContext(), QInputContext::reset() |
|
331 |
*/ |
|
332 |
void QWidget::resetInputContext() |
|
333 |
{ |
|
334 |
if (!hasFocus()) |
|
335 |
return; |
|
336 |
#ifndef QT_NO_IM |
|
337 |
QInputContext *qic = this->inputContext(); |
|
338 |
if(qic) |
|
339 |
qic->reset(); |
|
340 |
#endif // QT_NO_IM |
|
341 |
} |
|
342 |
||
343 |
#ifdef QT_KEYPAD_NAVIGATION |
|
344 |
QPointer<QWidget> QWidgetPrivate::editingWidget; |
|
345 |
||
346 |
/*! |
|
347 |
Returns true if this widget currently has edit focus; otherwise false. |
|
348 |
||
349 |
This feature is only available in Qt for Embedded Linux. |
|
350 |
||
351 |
\sa setEditFocus(), QApplication::keypadNavigationEnabled() |
|
352 |
*/ |
|
353 |
bool QWidget::hasEditFocus() const |
|
354 |
{ |
|
355 |
const QWidget* w = this; |
|
356 |
while (w->d_func()->extra && w->d_func()->extra->focus_proxy) |
|
357 |
w = w->d_func()->extra->focus_proxy; |
|
358 |
return QWidgetPrivate::editingWidget == w; |
|
359 |
} |
|
360 |
||
361 |
/*! |
|
362 |
\fn void QWidget::setEditFocus(bool enable) |
|
363 |
||
364 |
If \a enable is true, make this widget have edit focus, in which |
|
365 |
case Qt::Key_Up and Qt::Key_Down will be delivered to the widget |
|
366 |
normally; otherwise, Qt::Key_Up and Qt::Key_Down are used to |
|
367 |
change focus. |
|
368 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
This feature is only available in Qt for Embedded Linux and Qt |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
370 |
for Symbian. |
0 | 371 |
|
372 |
\sa hasEditFocus(), QApplication::keypadNavigationEnabled() |
|
373 |
*/ |
|
374 |
void QWidget::setEditFocus(bool on) |
|
375 |
{ |
|
376 |
QWidget *f = this; |
|
377 |
while (f->d_func()->extra && f->d_func()->extra->focus_proxy) |
|
378 |
f = f->d_func()->extra->focus_proxy; |
|
379 |
||
380 |
if (QWidgetPrivate::editingWidget && QWidgetPrivate::editingWidget != f) |
|
381 |
QWidgetPrivate::editingWidget->setEditFocus(false); |
|
382 |
||
383 |
if (on && !f->hasFocus()) |
|
384 |
f->setFocus(); |
|
385 |
||
386 |
if ((!on && !QWidgetPrivate::editingWidget) |
|
387 |
|| (on && QWidgetPrivate::editingWidget == f)) { |
|
388 |
return; |
|
389 |
} |
|
390 |
||
391 |
if (!on && QWidgetPrivate::editingWidget == f) { |
|
392 |
QWidgetPrivate::editingWidget = 0; |
|
393 |
QEvent event(QEvent::LeaveEditFocus); |
|
394 |
QApplication::sendEvent(f, &event); |
|
395 |
QApplication::sendEvent(f->style(), &event); |
|
396 |
} else if (on) { |
|
397 |
QWidgetPrivate::editingWidget = f; |
|
398 |
QEvent event(QEvent::EnterEditFocus); |
|
399 |
QApplication::sendEvent(f, &event); |
|
400 |
QApplication::sendEvent(f->style(), &event); |
|
401 |
} |
|
402 |
} |
|
403 |
#endif |
|
404 |
||
405 |
/*! |
|
406 |
\property QWidget::autoFillBackground |
|
407 |
\brief whether the widget background is filled automatically |
|
408 |
\since 4.1 |
|
409 |
||
410 |
If enabled, this property will cause Qt to fill the background of the |
|
411 |
widget before invoking the paint event. The color used is defined by the |
|
412 |
QPalette::Window color role from the widget's \l{QPalette}{palette}. |
|
413 |
||
414 |
In addition, Windows are always filled with QPalette::Window, unless the |
|
415 |
WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set. |
|
416 |
||
417 |
This property cannot be turned off (i.e., set to false) if a widget's |
|
418 |
parent has a static gradient for its background. |
|
419 |
||
420 |
\warning Use this property with caution in conjunction with |
|
421 |
\l{Qt Style Sheets}. When a widget has a style sheet with a valid |
|
422 |
background or a border-image, this property is automatically disabled. |
|
423 |
||
424 |
By default, this property is false. |
|
425 |
||
426 |
\sa Qt::WA_OpaquePaintEvent, Qt::WA_NoSystemBackground, |
|
427 |
{QWidget#Transparency and Double Buffering}{Transparency and Double Buffering} |
|
428 |
*/ |
|
429 |
bool QWidget::autoFillBackground() const |
|
430 |
{ |
|
431 |
Q_D(const QWidget); |
|
432 |
return d->extra && d->extra->autoFillBackground; |
|
433 |
} |
|
434 |
||
435 |
void QWidget::setAutoFillBackground(bool enabled) |
|
436 |
{ |
|
437 |
Q_D(QWidget); |
|
438 |
if (!d->extra) |
|
439 |
d->createExtra(); |
|
440 |
if (d->extra->autoFillBackground == enabled) |
|
441 |
return; |
|
442 |
||
443 |
d->extra->autoFillBackground = enabled; |
|
444 |
d->updateIsOpaque(); |
|
445 |
update(); |
|
446 |
d->updateIsOpaque(); |
|
447 |
} |
|
448 |
||
449 |
/*! |
|
450 |
\class QWidget |
|
451 |
\brief The QWidget class is the base class of all user interface objects. |
|
452 |
||
453 |
\ingroup basicwidgets |
|
454 |
||
455 |
||
456 |
The widget is the atom of the user interface: it receives mouse, keyboard |
|
457 |
and other events from the window system, and paints a representation of |
|
458 |
itself on the screen. Every widget is rectangular, and they are sorted in a |
|
459 |
Z-order. A widget is clipped by its parent and by the widgets in front of |
|
460 |
it. |
|
461 |
||
462 |
A widget that is not embedded in a parent widget is called a window. |
|
463 |
Usually, windows have a frame and a title bar, although it is also possible |
|
464 |
to create windows without such decoration using suitable |
|
465 |
\l{Qt::WindowFlags}{window flags}). In Qt, QMainWindow and the various |
|
466 |
subclasses of QDialog are the most common window types. |
|
467 |
||
468 |
Every widget's constructor accepts one or two standard arguments: |
|
469 |
||
470 |
\list 1 |
|
471 |
\i \c{QWidget *parent = 0} is the parent of the new widget. If it is 0 |
|
472 |
(the default), the new widget will be a window. If not, it will be |
|
473 |
a child of \e parent, and be constrained by \e parent's geometry |
|
474 |
(unless you specify Qt::Window as window flag). |
|
475 |
\i \c{Qt::WindowFlags f = 0} (where available) sets the window flags; |
|
476 |
the default is suitable for almost all widgets, but to get, for |
|
477 |
example, a window without a window system frame, you must use |
|
478 |
special flags. |
|
479 |
\endlist |
|
480 |
||
481 |
QWidget has many member functions, but some of them have little direct |
|
482 |
functionality; for example, QWidget has a font property, but never uses |
|
483 |
this itself. There are many subclasses which provide real functionality, |
|
484 |
such as QLabel, QPushButton, QListWidget, and QTabWidget. |
|
485 |
||
486 |
||
487 |
\section1 Top-Level and Child Widgets |
|
488 |
||
489 |
A widget without a parent widget is always an independent window (top-level |
|
490 |
widget). For these widgets, setWindowTitle() and setWindowIcon() set the |
|
491 |
title bar and icon respectively. |
|
492 |
||
493 |
Non-window widgets are child widgets, displayed within their parent |
|
494 |
widgets. Most widgets in Qt are mainly useful as child widgets. For |
|
495 |
example, it is possible to display a button as a top-level window, but most |
|
496 |
people prefer to put their buttons inside other widgets, such as QDialog. |
|
497 |
||
498 |
\image parent-child-widgets.png A parent widget containing various child widgets. |
|
499 |
||
500 |
The diagram above shows a QGroupBox widget being used to hold various child |
|
501 |
widgets in a layout provided by QGridLayout. The QLabel child widgets have |
|
502 |
been outlined to indicate their full sizes. |
|
503 |
||
504 |
If you want to use a QWidget to hold child widgets you will usually want to |
|
505 |
add a layout to the parent QWidget. See \l{Layout Management} for more |
|
506 |
information. |
|
507 |
||
508 |
||
509 |
\section1 Composite Widgets |
|
510 |
||
511 |
When a widget is used as a container to group a number of child widgets, it |
|
512 |
is known as a composite widget. These can be created by constructing a |
|
513 |
widget with the required visual properties - a QFrame, for example - and |
|
514 |
adding child widgets to it, usually managed by a layout. The above diagram |
|
515 |
shows such a composite widget that was created using \l{Qt Designer}. |
|
516 |
||
517 |
Composite widgets can also be created by subclassing a standard widget, |
|
518 |
such as QWidget or QFrame, and adding the necessary layout and child |
|
519 |
widgets in the constructor of the subclass. Many of the \l{Qt Examples} |
|
520 |
{examples provided with Qt} use this approach, and it is also covered in |
|
521 |
the Qt \l{Tutorials}. |
|
522 |
||
523 |
||
524 |
\section1 Custom Widgets and Painting |
|
525 |
||
526 |
Since QWidget is a subclass of QPaintDevice, subclasses can be used to |
|
527 |
display custom content that is composed using a series of painting |
|
528 |
operations with an instance of the QPainter class. This approach contrasts |
|
529 |
with the canvas-style approach used by the \l{Graphics View} |
|
530 |
{Graphics View Framework} where items are added to a scene by the |
|
531 |
application and are rendered by the framework itself. |
|
532 |
||
533 |
Each widget performs all painting operations from within its paintEvent() |
|
534 |
function. This is called whenever the widget needs to be redrawn, either |
|
535 |
as a result of some external change or when requested by the application. |
|
536 |
||
537 |
The \l{widgets/analogclock}{Analog Clock example} shows how a simple widget |
|
538 |
can handle paint events. |
|
539 |
||
540 |
||
541 |
\section1 Size Hints and Size Policies |
|
542 |
||
543 |
When implementing a new widget, it is almost always useful to reimplement |
|
544 |
sizeHint() to provide a reasonable default size for the widget and to set |
|
545 |
the correct size policy with setSizePolicy(). |
|
546 |
||
547 |
By default, composite widgets which do not provide a size hint will be |
|
548 |
sized according to the space requirements of their child widgets. |
|
549 |
||
550 |
The size policy lets you supply good default behavior for the layout |
|
551 |
management system, so that other widgets can contain and manage yours |
|
552 |
easily. The default size policy indicates that the size hint represents |
|
553 |
the preferred size of the widget, and this is often good enough for many |
|
554 |
widgets. |
|
555 |
||
556 |
\note The size of top-level widgets are constrained to 2/3 of the desktop's |
|
557 |
height and width. You can resize() the widget manually if these bounds are |
|
558 |
inadequate. |
|
559 |
||
560 |
||
561 |
\section1 Events |
|
562 |
||
563 |
Widgets respond to events that are typically caused by user actions. Qt |
|
564 |
delivers events to widgets by calling specific event handler functions with |
|
565 |
instances of QEvent subclasses containing information about each event. |
|
566 |
||
567 |
If your widget only contains child widgets, you probably do not need to |
|
568 |
implement any event handlers. If you want to detect a mouse click in a |
|
569 |
child widget call the child's underMouse() function inside the widget's |
|
570 |
mousePressEvent(). |
|
571 |
||
572 |
The \l{widgets/scribble}{Scribble example} implements a wider set of |
|
573 |
events to handle mouse movement, button presses, and window resizing. |
|
574 |
||
575 |
You will need to supply the behavior and content for your own widgets, but |
|
576 |
here is a brief overview of the events that are relevant to QWidget, |
|
577 |
starting with the most common ones: |
|
578 |
||
579 |
\list |
|
580 |
\i paintEvent() is called whenever the widget needs to be repainted. |
|
581 |
Every widget displaying custom content must implement it. Painting |
|
582 |
using a QPainter can only take place in a paintEvent() or a |
|
583 |
function called by a paintEvent(). |
|
584 |
\i resizeEvent() is called when the widget has been resized. |
|
585 |
\i mousePressEvent() is called when a mouse button is pressed while |
|
586 |
the mouse cursor is inside the widget, or when the widget has |
|
587 |
grabbed the mouse using grabMouse(). Pressing the mouse without |
|
588 |
releasing it is effectively the same as calling grabMouse(). |
|
589 |
\i mouseReleaseEvent() is called when a mouse button is released. A |
|
590 |
widget receives mouse release events when it has received the |
|
591 |
corresponding mouse press event. This means that if the user |
|
592 |
presses the mouse inside \e your widget, then drags the mouse |
|
593 |
somewhere else before releasing the mouse button, \e your widget |
|
594 |
receives the release event. There is one exception: if a popup menu |
|
595 |
appears while the mouse button is held down, this popup immediately |
|
596 |
steals the mouse events. |
|
597 |
\i mouseDoubleClickEvent() is called when the user double-clicks in |
|
598 |
the widget. If the user double-clicks, the widget receives a mouse |
|
599 |
press event, a mouse release event and finally this event instead |
|
600 |
of a second mouse press event. (Some mouse move events may also be |
|
601 |
received if the mouse is not held steady during this operation.) It |
|
602 |
is \e{not possible} to distinguish a click from a double-click |
|
603 |
until the second click arrives. (This is one reason why most GUI |
|
604 |
books recommend that double-clicks be an extension of |
|
605 |
single-clicks, rather than trigger a different action.) |
|
606 |
\endlist |
|
607 |
||
608 |
Widgets that accept keyboard input need to reimplement a few more event |
|
609 |
handlers: |
|
610 |
||
611 |
\list |
|
612 |
\i keyPressEvent() is called whenever a key is pressed, and again when |
|
613 |
a key has been held down long enough for it to auto-repeat. The |
|
614 |
\key Tab and \key Shift+Tab keys are only passed to the widget if |
|
615 |
they are not used by the focus-change mechanisms. To force those |
|
616 |
keys to be processed by your widget, you must reimplement |
|
617 |
QWidget::event(). |
|
618 |
\i focusInEvent() is called when the widget gains keyboard focus |
|
619 |
(assuming you have called setFocusPolicy()). Well-behaved widgets |
|
620 |
indicate that they own the keyboard focus in a clear but discreet |
|
621 |
way. |
|
622 |
\i focusOutEvent() is called when the widget loses keyboard focus. |
|
623 |
\endlist |
|
624 |
||
625 |
You may be required to also reimplement some of the less common event |
|
626 |
handlers: |
|
627 |
||
628 |
\list |
|
629 |
\i mouseMoveEvent() is called whenever the mouse moves while a mouse |
|
630 |
button is held down. This can be useful during drag and drop |
|
631 |
operations. If you call setMouseTracking(true), you get mouse move |
|
632 |
events even when no buttons are held down. (See also the \l{Drag |
|
633 |
and Drop} guide.) |
|
634 |
\i keyReleaseEvent() is called whenever a key is released and while it |
|
635 |
is held down (if the key is auto-repeating). In that case, the |
|
636 |
widget will receive a pair of key release and key press event for |
|
637 |
every repeat. The \key Tab and \key Shift+Tab keys are only passed |
|
638 |
to the widget if they are not used by the focus-change mechanisms. |
|
639 |
To force those keys to be processed by your widget, you must |
|
640 |
reimplement QWidget::event(). |
|
641 |
\i wheelEvent() is called whenever the user turns the mouse wheel |
|
642 |
while the widget has the focus. |
|
643 |
\i enterEvent() is called when the mouse enters the widget's screen |
|
644 |
space. (This excludes screen space owned by any of the widget's |
|
645 |
children.) |
|
646 |
\i leaveEvent() is called when the mouse leaves the widget's screen |
|
647 |
space. If the mouse enters a child widget it will not cause a |
|
648 |
leaveEvent(). |
|
649 |
\i moveEvent() is called when the widget has been moved relative to |
|
650 |
its parent. |
|
651 |
\i closeEvent() is called when the user closes the widget (or when |
|
652 |
close() is called). |
|
653 |
\endlist |
|
654 |
||
655 |
There are also some rather obscure events described in the documentation |
|
656 |
for QEvent::Type. To handle these events, you need to reimplement event() |
|
657 |
directly. |
|
658 |
||
659 |
The default implementation of event() handles \key Tab and \key Shift+Tab |
|
660 |
(to move the keyboard focus), and passes on most of the other events to |
|
661 |
one of the more specialized handlers above. |
|
662 |
||
663 |
Events and the mechanism used to deliver them are covered in the |
|
664 |
\l{Events and Event Filters} document. |
|
665 |
||
666 |
\section1 Groups of Functions and Properties |
|
667 |
||
668 |
\table |
|
669 |
\header \i Context \i Functions and Properties |
|
670 |
||
671 |
\row \i Window functions \i |
|
672 |
show(), |
|
673 |
hide(), |
|
674 |
raise(), |
|
675 |
lower(), |
|
676 |
close(). |
|
677 |
||
678 |
\row \i Top-level windows \i |
|
679 |
\l windowModified, \l windowTitle, \l windowIcon, \l windowIconText, |
|
680 |
\l isActiveWindow, activateWindow(), \l minimized, showMinimized(), |
|
681 |
\l maximized, showMaximized(), \l fullScreen, showFullScreen(), |
|
682 |
showNormal(). |
|
683 |
||
684 |
\row \i Window contents \i |
|
685 |
update(), |
|
686 |
repaint(), |
|
687 |
scroll(). |
|
688 |
||
689 |
\row \i Geometry \i |
|
690 |
\l pos, x(), y(), \l rect, \l size, width(), height(), move(), resize(), |
|
691 |
\l sizePolicy, sizeHint(), minimumSizeHint(), |
|
692 |
updateGeometry(), layout(), |
|
693 |
\l frameGeometry, \l geometry, \l childrenRect, \l childrenRegion, |
|
694 |
adjustSize(), |
|
695 |
mapFromGlobal(), mapToGlobal(), |
|
696 |
mapFromParent(), mapToParent(), |
|
697 |
\l maximumSize, \l minimumSize, \l sizeIncrement, |
|
698 |
\l baseSize, setFixedSize() |
|
699 |
||
700 |
\row \i Mode \i |
|
701 |
\l visible, isVisibleTo(), |
|
702 |
\l enabled, isEnabledTo(), |
|
703 |
\l modal, |
|
704 |
isWindow(), |
|
705 |
\l mouseTracking, |
|
706 |
\l updatesEnabled, |
|
707 |
visibleRegion(). |
|
708 |
||
709 |
\row \i Look and feel \i |
|
710 |
style(), |
|
711 |
setStyle(), |
|
712 |
\l styleSheet, |
|
713 |
\l cursor, |
|
714 |
\l font, |
|
715 |
\l palette, |
|
716 |
backgroundRole(), setBackgroundRole(), |
|
717 |
fontInfo(), fontMetrics(). |
|
718 |
||
719 |
\row \i Keyboard focus functions \i |
|
720 |
\l focus, \l focusPolicy, |
|
721 |
setFocus(), clearFocus(), setTabOrder(), setFocusProxy(), |
|
722 |
focusNextChild(), focusPreviousChild(). |
|
723 |
||
724 |
\row \i Mouse and keyboard grabbing \i |
|
725 |
grabMouse(), releaseMouse(), |
|
726 |
grabKeyboard(), releaseKeyboard(), |
|
727 |
mouseGrabber(), keyboardGrabber(). |
|
728 |
||
729 |
\row \i Event handlers \i |
|
730 |
event(), |
|
731 |
mousePressEvent(), |
|
732 |
mouseReleaseEvent(), |
|
733 |
mouseDoubleClickEvent(), |
|
734 |
mouseMoveEvent(), |
|
735 |
keyPressEvent(), |
|
736 |
keyReleaseEvent(), |
|
737 |
focusInEvent(), |
|
738 |
focusOutEvent(), |
|
739 |
wheelEvent(), |
|
740 |
enterEvent(), |
|
741 |
leaveEvent(), |
|
742 |
paintEvent(), |
|
743 |
moveEvent(), |
|
744 |
resizeEvent(), |
|
745 |
closeEvent(), |
|
746 |
dragEnterEvent(), |
|
747 |
dragMoveEvent(), |
|
748 |
dragLeaveEvent(), |
|
749 |
dropEvent(), |
|
750 |
childEvent(), |
|
751 |
showEvent(), |
|
752 |
hideEvent(), |
|
753 |
customEvent(). |
|
754 |
changeEvent(), |
|
755 |
||
756 |
\row \i System functions \i |
|
757 |
parentWidget(), window(), setParent(), winId(), |
|
758 |
find(), metric(). |
|
759 |
||
760 |
\row \i Interactive help \i |
|
761 |
setToolTip(), setWhatsThis() |
|
762 |
||
763 |
\endtable |
|
764 |
||
765 |
||
766 |
\section1 Widget Style Sheets |
|
767 |
||
768 |
In addition to the standard widget styles for each platform, widgets can |
|
769 |
also be styled according to rules specified in a \l{styleSheet} |
|
770 |
{style sheet}. This feature enables you to customize the appearance of |
|
771 |
specific widgets to provide visual cues to users about their purpose. For |
|
772 |
example, a button could be styled in a particular way to indicate that it |
|
773 |
performs a destructive action. |
|
774 |
||
775 |
The use of widget style sheets is described in more detail in the |
|
776 |
\l{Qt Style Sheets} document. |
|
777 |
||
778 |
||
779 |
\section1 Transparency and Double Buffering |
|
780 |
||
781 |
Since Qt 4.0, QWidget automatically double-buffers its painting, so there |
|
782 |
is no need to write double-buffering code in paintEvent() to avoid |
|
783 |
flicker. |
|
784 |
||
785 |
Since Qt 4.1, the Qt::WA_ContentsPropagated widget attribute has been |
|
786 |
deprecated. Instead, the contents of parent widgets are propagated by |
|
787 |
default to each of their children as long as Qt::WA_PaintOnScreen is not |
|
788 |
set. Custom widgets can be written to take advantage of this feature by |
|
789 |
updating irregular regions (to create non-rectangular child widgets), or |
|
790 |
painting with colors that have less than full alpha component. The |
|
791 |
following diagram shows how attributes and properties of a custom widget |
|
792 |
can be fine-tuned to achieve different effects. |
|
793 |
||
794 |
\image propagation-custom.png |
|
795 |
||
796 |
In the above diagram, a semi-transparent rectangular child widget with an |
|
797 |
area removed is constructed and added to a parent widget (a QLabel showing |
|
798 |
a pixmap). Then, different properties and widget attributes are set to |
|
799 |
achieve different effects: |
|
800 |
||
801 |
\list |
|
802 |
\i The left widget has no additional properties or widget attributes |
|
803 |
set. This default state suits most custom widgets using |
|
804 |
transparency, are irregularly-shaped, or do not paint over their |
|
805 |
entire area with an opaque brush. |
|
806 |
\i The center widget has the \l autoFillBackground property set. This |
|
807 |
property is used with custom widgets that rely on the widget to |
|
808 |
supply a default background, and do not paint over their entire |
|
809 |
area with an opaque brush. |
|
810 |
\i The right widget has the Qt::WA_OpaquePaintEvent widget attribute |
|
811 |
set. This indicates that the widget will paint over its entire area |
|
812 |
with opaque colors. The widget's area will initially be |
|
813 |
\e{uninitialized}, represented in the diagram with a red diagonal |
|
814 |
grid pattern that shines through the overpainted area. The |
|
815 |
Qt::WA_OpaquePaintArea attribute is useful for widgets that need to |
|
816 |
paint their own specialized contents quickly and do not need a |
|
817 |
default filled background. |
|
818 |
\endlist |
|
819 |
||
820 |
To rapidly update custom widgets with simple background colors, such as |
|
821 |
real-time plotting or graphing widgets, it is better to define a suitable |
|
822 |
background color (using setBackgroundRole() with the |
|
823 |
QPalette::Window role), set the \l autoFillBackground property, and only |
|
824 |
implement the necessary drawing functionality in the widget's paintEvent(). |
|
825 |
||
826 |
To rapidly update custom widgets that constantly paint over their entire |
|
827 |
areas with opaque content, e.g., video streaming widgets, it is better to |
|
828 |
set the widget's Qt::WA_OpaquePaintEvent, avoiding any unnecessary overhead |
|
829 |
associated with repainting the widget's background. |
|
830 |
||
831 |
If a widget has both the Qt::WA_OpaquePaintEvent widget attribute \e{and} |
|
832 |
the \l autoFillBackground property set, the Qt::WA_OpaquePaintEvent |
|
833 |
attribute takes precedence. Depending on your requirements, you should |
|
834 |
choose either one of them. |
|
835 |
||
836 |
Since Qt 4.1, the contents of parent widgets are also propagated to |
|
837 |
standard Qt widgets. This can lead to some unexpected results if the |
|
838 |
parent widget is decorated in a non-standard way, as shown in the diagram |
|
839 |
below. |
|
840 |
||
841 |
\image propagation-standard.png |
|
842 |
||
843 |
The scope for customizing the painting behavior of standard Qt widgets, |
|
844 |
without resorting to subclassing, is slightly less than that possible for |
|
845 |
custom widgets. Usually, the desired appearance of a standard widget can be |
|
846 |
achieved by setting its \l autoFillBackground property. |
|
847 |
||
848 |
||
849 |
\section1 Creating Translucent Windows |
|
850 |
||
851 |
Since Qt 4.5, it has been possible to create windows with translucent regions |
|
852 |
on window systems that support compositing. |
|
853 |
||
854 |
To enable this feature in a top-level widget, set its Qt::WA_TranslucentBackground |
|
855 |
attribute with setAttribute() and ensure that its background is painted with |
|
856 |
non-opaque colors in the regions you want to be partially transparent. |
|
857 |
||
858 |
Platform notes: |
|
859 |
||
860 |
\list |
|
861 |
\o X11: This feature relies on the use of an X server that supports ARGB visuals |
|
862 |
and a compositing window manager. |
|
863 |
\o Windows: The widget needs to have the Qt::FramelessWindowHint window flag set |
|
864 |
for the translucency to work. |
|
865 |
\endlist |
|
866 |
||
867 |
||
868 |
\section1 Native Widgets vs Alien Widgets |
|
869 |
||
870 |
Introduced in Qt 4.4, alien widgets are widgets unknown to the windowing |
|
871 |
system. They do not have a native window handle associated with them. This |
|
872 |
feature significantly speeds up widget painting, resizing, and removes flicker. |
|
873 |
||
874 |
Should you require the old behavior with native windows, you can choose |
|
875 |
one of the following options: |
|
876 |
||
877 |
\list 1 |
|
878 |
\i Use the \c{QT_USE_NATIVE_WINDOWS=1} in your environment. |
|
879 |
\i Set the Qt::AA_NativeWindows attribute on your application. All |
|
880 |
widgets will be native widgets. |
|
881 |
\i Set the Qt::WA_NativeWindow attribute on widgets: The widget itself |
|
882 |
and all of its ancestors will become native (unless |
|
883 |
Qt::WA_DontCreateNativeAncestors is set). |
|
884 |
\i Call QWidget::winId to enforce a native window (this implies 3). |
|
885 |
\i Set the Qt::WA_PaintOnScreen attribute to enforce a native window |
|
886 |
(this implies 3). |
|
887 |
\endlist |
|
888 |
||
889 |
\sa QEvent, QPainter, QGridLayout, QBoxLayout |
|
890 |
||
891 |
\section1 Softkeys |
|
892 |
||
893 |
Since Qt 4.6, Softkeys are usually physical keys on a device that have a corresponding label or |
|
894 |
other visual representation on the screen that is generally located next to its |
|
895 |
physical counterpart. They are most often found on mobile phone platforms. In |
|
896 |
modern touch based user interfaces it is also possible to have softkeys that do |
|
897 |
not correspond to any physical keys. Softkeys differ from other onscreen labels |
|
898 |
in that they are contextual. |
|
899 |
||
900 |
In Qt, contextual softkeys are added to a widget by calling addAction() and |
|
901 |
passing a \c QAction with a softkey role set on it. When the widget |
|
902 |
containing the softkey actions has focus, its softkeys should appear in |
|
903 |
the user interface. Softkeys are discovered by traversing the widget |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
904 |
hierarchy so it is possible to define a single set of softkeys that are |
0 | 905 |
present at all times by calling addAction() for a given top level widget. |
906 |
||
907 |
On some platforms, this concept overlaps with \c QMenuBar such that if no |
|
908 |
other softkeys are found and the top level widget is a QMainWindow containing |
|
909 |
a QMenuBar, the menubar actions may appear on one of the softkeys. |
|
910 |
||
911 |
Note: Currently softkeys are only supported on the Symbian Platform. |
|
912 |
||
913 |
\sa addAction(), QAction, QMenuBar |
|
914 |
||
915 |
*/ |
|
916 |
||
917 |
QWidgetMapper *QWidgetPrivate::mapper = 0; // widget with wid |
|
918 |
QWidgetSet *QWidgetPrivate::allWidgets = 0; // widgets with no wid |
|
919 |
||
920 |
||
921 |
/***************************************************************************** |
|
922 |
QWidget utility functions |
|
923 |
*****************************************************************************/ |
|
924 |
||
925 |
QRegion qt_dirtyRegion(QWidget *widget) |
|
926 |
{ |
|
927 |
if (!widget) |
|
928 |
return QRegion(); |
|
929 |
||
930 |
QWidgetBackingStore *bs = qt_widget_private(widget)->maybeBackingStore(); |
|
931 |
if (!bs) |
|
932 |
return QRegion(); |
|
933 |
||
934 |
return bs->dirtyRegion(widget); |
|
935 |
} |
|
936 |
||
937 |
/***************************************************************************** |
|
938 |
QWidget member functions |
|
939 |
*****************************************************************************/ |
|
940 |
||
941 |
/* |
|
942 |
Widget state flags: |
|
943 |
\list |
|
944 |
\i Qt::WA_WState_Created The widget has a valid winId(). |
|
945 |
\i Qt::WA_WState_Visible The widget is currently visible. |
|
946 |
\i Qt::WA_WState_Hidden The widget is hidden, i.e. it won't |
|
947 |
become visible unless you call show() on it. Qt::WA_WState_Hidden |
|
948 |
implies !Qt::WA_WState_Visible. |
|
949 |
\i Qt::WA_WState_CompressKeys Compress keyboard events. |
|
950 |
\i Qt::WA_WState_BlockUpdates Repaints and updates are disabled. |
|
951 |
\i Qt::WA_WState_InPaintEvent Currently processing a paint event. |
|
952 |
\i Qt::WA_WState_Reparented The widget has been reparented. |
|
953 |
\i Qt::WA_WState_ConfigPending A configuration (resize/move) event is pending. |
|
954 |
\i Qt::WA_WState_DND (Deprecated) The widget supports drag and drop, see setAcceptDrops(). |
|
955 |
\endlist |
|
956 |
*/ |
|
957 |
||
958 |
struct QWidgetExceptionCleaner |
|
959 |
{ |
|
960 |
/* this cleans up when the constructor throws an exception */ |
|
961 |
static inline void cleanup(QWidget *that, QWidgetPrivate *d) |
|
962 |
{ |
|
963 |
#ifdef QT_NO_EXCEPTIONS |
|
964 |
Q_UNUSED(that); |
|
965 |
Q_UNUSED(d); |
|
966 |
#else |
|
967 |
QWidgetPrivate::allWidgets->remove(that); |
|
968 |
if (d->focus_next != that) { |
|
969 |
if (d->focus_next) |
|
970 |
d->focus_next->d_func()->focus_prev = d->focus_prev; |
|
971 |
if (d->focus_prev) |
|
972 |
d->focus_prev->d_func()->focus_next = d->focus_next; |
|
973 |
} |
|
974 |
#endif |
|
975 |
} |
|
976 |
}; |
|
977 |
||
978 |
/*! |
|
979 |
Constructs a widget which is a child of \a parent, with widget |
|
980 |
flags set to \a f. |
|
981 |
||
982 |
If \a parent is 0, the new widget becomes a window. If |
|
983 |
\a parent is another widget, this widget becomes a child window |
|
984 |
inside \a parent. The new widget is deleted when its \a parent is |
|
985 |
deleted. |
|
986 |
||
987 |
The widget flags argument, \a f, is normally 0, but it can be set |
|
988 |
to customize the frame of a window (i.e. \a |
|
989 |
parent must be 0). To customize the frame, use a value composed |
|
990 |
from the bitwise OR of any of the \l{Qt::WindowFlags}{window flags}. |
|
991 |
||
992 |
If you add a child widget to an already visible widget you must |
|
993 |
explicitly show the child to make it visible. |
|
994 |
||
995 |
Note that the X11 version of Qt may not be able to deliver all |
|
996 |
combinations of style flags on all systems. This is because on |
|
997 |
X11, Qt can only ask the window manager, and the window manager |
|
998 |
can override the application's settings. On Windows, Qt can set |
|
999 |
whatever flags you want. |
|
1000 |
||
1001 |
\sa windowFlags |
|
1002 |
*/ |
|
1003 |
||
1004 |
QWidget::QWidget(QWidget *parent, Qt::WindowFlags f) |
|
1005 |
: QObject(*new QWidgetPrivate, 0), QPaintDevice() |
|
1006 |
{ |
|
1007 |
QT_TRY { |
|
1008 |
d_func()->init(parent, f); |
|
1009 |
} QT_CATCH(...) { |
|
1010 |
QWidgetExceptionCleaner::cleanup(this, d_func()); |
|
1011 |
QT_RETHROW; |
|
1012 |
} |
|
1013 |
} |
|
1014 |
||
1015 |
#ifdef QT3_SUPPORT |
|
1016 |
/*! |
|
1017 |
\overload |
|
1018 |
\obsolete |
|
1019 |
*/ |
|
1020 |
QWidget::QWidget(QWidget *parent, const char *name, Qt::WindowFlags f) |
|
1021 |
: QObject(*new QWidgetPrivate, 0), QPaintDevice() |
|
1022 |
{ |
|
1023 |
QT_TRY { |
|
1024 |
d_func()->init(parent , f); |
|
1025 |
setObjectName(QString::fromAscii(name)); |
|
1026 |
} QT_CATCH(...) { |
|
1027 |
QWidgetExceptionCleaner::cleanup(this, d_func()); |
|
1028 |
QT_RETHROW; |
|
1029 |
} |
|
1030 |
} |
|
1031 |
#endif |
|
1032 |
||
1033 |
/*! \internal |
|
1034 |
*/ |
|
1035 |
QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WindowFlags f) |
|
1036 |
: QObject(dd, 0), QPaintDevice() |
|
1037 |
{ |
|
1038 |
Q_D(QWidget); |
|
1039 |
QT_TRY { |
|
1040 |
d->init(parent, f); |
|
1041 |
} QT_CATCH(...) { |
|
1042 |
QWidgetExceptionCleaner::cleanup(this, d_func()); |
|
1043 |
QT_RETHROW; |
|
1044 |
} |
|
1045 |
} |
|
1046 |
||
1047 |
/*! |
|
1048 |
\internal |
|
1049 |
*/ |
|
1050 |
int QWidget::devType() const |
|
1051 |
{ |
|
1052 |
return QInternal::Widget; |
|
1053 |
} |
|
1054 |
||
1055 |
||
1056 |
//### w is a "this" ptr, passed as a param because QWorkspace needs special logic |
|
1057 |
void QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w) |
|
1058 |
{ |
|
1059 |
bool customize = (flags & (Qt::CustomizeWindowHint |
|
1060 |
| Qt::FramelessWindowHint |
|
1061 |
| Qt::WindowTitleHint |
|
1062 |
| Qt::WindowSystemMenuHint |
|
1063 |
| Qt::WindowMinimizeButtonHint |
|
1064 |
| Qt::WindowMaximizeButtonHint |
|
1065 |
| Qt::WindowCloseButtonHint |
|
1066 |
| Qt::WindowContextHelpButtonHint)); |
|
1067 |
||
1068 |
uint type = (flags & Qt::WindowType_Mask); |
|
1069 |
||
1070 |
if ((type == Qt::Widget || type == Qt::SubWindow) && w && !w->parent()) { |
|
1071 |
type = Qt::Window; |
|
1072 |
flags |= Qt::Window; |
|
1073 |
} |
|
1074 |
||
1075 |
if (flags & Qt::CustomizeWindowHint) { |
|
1076 |
// modify window flags to make them consistent. |
|
1077 |
// Only enable this on non-Mac platforms. Since the old way of doing this would |
|
1078 |
// interpret WindowSystemMenuHint as a close button and we can't change that behavior |
|
1079 |
// we can't just add this in. |
|
1080 |
#ifndef Q_WS_MAC |
|
1081 |
if (flags & (Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint)) { |
|
1082 |
flags |= Qt::WindowSystemMenuHint; |
|
1083 |
#else |
|
1084 |
if (flags & (Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint |
|
1085 |
| Qt::WindowSystemMenuHint)) { |
|
1086 |
#endif |
|
1087 |
flags |= Qt::WindowTitleHint; |
|
1088 |
flags &= ~Qt::FramelessWindowHint; |
|
1089 |
} |
|
1090 |
} else if (customize && !(flags & Qt::FramelessWindowHint)) { |
|
1091 |
// if any of the window hints that affect the titlebar are set |
|
1092 |
// and the window is supposed to have frame, we add a titlebar |
|
1093 |
// and system menu by default. |
|
1094 |
flags |= Qt::WindowSystemMenuHint; |
|
1095 |
flags |= Qt::WindowTitleHint; |
|
1096 |
} |
|
1097 |
if (customize) |
|
1098 |
; // don't modify window flags if the user explicitely set them. |
|
1099 |
else if (type == Qt::Dialog || type == Qt::Sheet) |
|
1100 |
#ifndef Q_WS_WINCE |
|
1101 |
flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint | Qt::WindowCloseButtonHint; |
|
1102 |
#else |
|
1103 |
flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; |
|
1104 |
#endif |
|
1105 |
else if (type == Qt::Tool) |
|
1106 |
flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; |
|
1107 |
else |
|
1108 |
flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint; |
|
1109 |
||
1110 |
||
1111 |
} |
|
1112 |
||
1113 |
void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) |
|
1114 |
{ |
|
1115 |
Q_Q(QWidget); |
|
1116 |
if (QApplication::type() == QApplication::Tty) |
|
1117 |
qFatal("QWidget: Cannot create a QWidget when no GUI is being used"); |
|
1118 |
||
1119 |
Q_ASSERT(allWidgets); |
|
1120 |
allWidgets->insert(q); |
|
1121 |
||
1122 |
QWidget *desktopWidget = 0; |
|
1123 |
if (parentWidget && parentWidget->windowType() == Qt::Desktop) { |
|
1124 |
desktopWidget = parentWidget; |
|
1125 |
parentWidget = 0; |
|
1126 |
} |
|
1127 |
||
1128 |
q->data = &data; |
|
1129 |
||
1130 |
#ifndef QT_NO_THREAD |
|
1131 |
if (!parent) { |
|
1132 |
Q_ASSERT_X(q->thread() == qApp->thread(), "QWidget", |
|
1133 |
"Widgets must be created in the GUI thread."); |
|
1134 |
} |
|
1135 |
#endif |
|
1136 |
||
1137 |
#if defined(Q_WS_X11) |
|
1138 |
if (desktopWidget) { |
|
1139 |
// make sure the widget is created on the same screen as the |
|
1140 |
// programmer specified desktop widget |
|
1141 |
xinfo = desktopWidget->d_func()->xinfo; |
|
1142 |
} |
|
1143 |
#else |
|
1144 |
Q_UNUSED(desktopWidget); |
|
1145 |
#endif |
|
1146 |
||
1147 |
data.fstrut_dirty = true; |
|
1148 |
||
1149 |
data.winid = 0; |
|
1150 |
data.widget_attributes = 0; |
|
1151 |
data.window_flags = f; |
|
1152 |
data.window_state = 0; |
|
1153 |
data.focus_policy = 0; |
|
1154 |
data.context_menu_policy = Qt::DefaultContextMenu; |
|
1155 |
data.window_modality = Qt::NonModal; |
|
1156 |
||
1157 |
data.sizehint_forced = 0; |
|
1158 |
data.is_closing = 0; |
|
1159 |
data.in_show = 0; |
|
1160 |
data.in_set_window_state = 0; |
|
1161 |
data.in_destructor = false; |
|
1162 |
||
1163 |
// Widgets with Qt::MSWindowsOwnDC (typically QGLWidget) must have a window handle. |
|
1164 |
if (f & Qt::MSWindowsOwnDC) |
|
1165 |
q->setAttribute(Qt::WA_NativeWindow); |
|
1166 |
||
1167 |
q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in adjustQuitOnCloseAttribute() |
|
1168 |
adjustQuitOnCloseAttribute(); |
|
1169 |
||
1170 |
q->setAttribute(Qt::WA_WState_Hidden); |
|
1171 |
||
1172 |
//give potential windows a bigger "pre-initial" size; create_sys() will give them a new size later |
|
1173 |
data.crect = parentWidget ? QRect(0,0,100,30) : QRect(0,0,640,480); |
|
1174 |
||
1175 |
focus_next = focus_prev = q; |
|
1176 |
||
1177 |
if ((f & Qt::WindowType_Mask) == Qt::Desktop) |
|
1178 |
q->create(); |
|
1179 |
else if (parentWidget) |
|
1180 |
q->setParent(parentWidget, data.window_flags); |
|
1181 |
else { |
|
1182 |
adjustFlags(data.window_flags, q); |
|
1183 |
resolveLayoutDirection(); |
|
1184 |
// opaque system background? |
|
1185 |
const QBrush &background = q->palette().brush(QPalette::Window); |
|
1186 |
setOpaque(q->isWindow() && background.style() != Qt::NoBrush && background.isOpaque()); |
|
1187 |
} |
|
1188 |
data.fnt = QFont(data.fnt, q); |
|
1189 |
#if defined(Q_WS_X11) |
|
1190 |
data.fnt.x11SetScreen(xinfo.screen()); |
|
1191 |
#endif // Q_WS_X11 |
|
1192 |
||
1193 |
q->setAttribute(Qt::WA_PendingMoveEvent); |
|
1194 |
q->setAttribute(Qt::WA_PendingResizeEvent); |
|
1195 |
||
1196 |
if (++QWidgetPrivate::instanceCounter > QWidgetPrivate::maxInstances) |
|
1197 |
QWidgetPrivate::maxInstances = QWidgetPrivate::instanceCounter; |
|
1198 |
||
1199 |
if (QApplicationPrivate::app_compile_version < 0x040200 |
|
1200 |
|| QApplicationPrivate::testAttribute(Qt::AA_ImmediateWidgetCreation)) |
|
1201 |
q->create(); |
|
1202 |
||
1203 |
||
1204 |
QEvent e(QEvent::Create); |
|
1205 |
QApplication::sendEvent(q, &e); |
|
1206 |
QApplication::postEvent(q, new QEvent(QEvent::PolishRequest)); |
|
1207 |
||
1208 |
extraPaintEngine = 0; |
|
1209 |
} |
|
1210 |
||
1211 |
||
1212 |
||
1213 |
void QWidgetPrivate::createRecursively() |
|
1214 |
{ |
|
1215 |
Q_Q(QWidget); |
|
1216 |
q->create(0, true, true); |
|
1217 |
for (int i = 0; i < children.size(); ++i) { |
|
1218 |
QWidget *child = qobject_cast<QWidget *>(children.at(i)); |
|
1219 |
if (child && !child->isHidden() && !child->isWindow() && !child->testAttribute(Qt::WA_WState_Created)) |
|
1220 |
child->d_func()->createRecursively(); |
|
1221 |
} |
|
1222 |
} |
|
1223 |
||
1224 |
||
1225 |
||
1226 |
||
1227 |
/*! |
|
1228 |
Creates a new widget window if \a window is 0, otherwise sets the |
|
1229 |
widget's window to \a window. |
|
1230 |
||
1231 |
Initializes the window (sets the geometry etc.) if \a |
|
1232 |
initializeWindow is true. If \a initializeWindow is false, no |
|
1233 |
initialization is performed. This parameter only makes sense if \a |
|
1234 |
window is a valid window. |
|
1235 |
||
1236 |
Destroys the old window if \a destroyOldWindow is true. If \a |
|
1237 |
destroyOldWindow is false, you are responsible for destroying the |
|
1238 |
window yourself (using platform native code). |
|
1239 |
||
1240 |
The QWidget constructor calls create(0,true,true) to create a |
|
1241 |
window for this widget. |
|
1242 |
*/ |
|
1243 |
||
1244 |
void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow) |
|
1245 |
{ |
|
1246 |
Q_D(QWidget); |
|
1247 |
if (testAttribute(Qt::WA_WState_Created) && window == 0 && internalWinId()) |
|
1248 |
return; |
|
1249 |
||
1250 |
if (d->data.in_destructor) |
|
1251 |
return; |
|
1252 |
||
1253 |
Qt::WindowType type = windowType(); |
|
1254 |
Qt::WindowFlags &flags = data->window_flags; |
|
1255 |
||
1256 |
if ((type == Qt::Widget || type == Qt::SubWindow) && !parentWidget()) { |
|
1257 |
type = Qt::Window; |
|
1258 |
flags |= Qt::Window; |
|
1259 |
} |
|
1260 |
||
1261 |
if (QWidget *parent = parentWidget()) { |
|
1262 |
if (type & Qt::Window) { |
|
1263 |
if (!parent->testAttribute(Qt::WA_WState_Created)) |
|
1264 |
parent->createWinId(); |
|
1265 |
} else if (testAttribute(Qt::WA_NativeWindow) && !parent->internalWinId() |
|
1266 |
&& !testAttribute(Qt::WA_DontCreateNativeAncestors)) { |
|
1267 |
// We're about to create a native child widget that doesn't have a native parent; |
|
1268 |
// enforce a native handle for the parent unless the Qt::WA_DontCreateNativeAncestors |
|
1269 |
// attribute is set. |
|
1270 |
d->createWinId(window); |
|
1271 |
// Nothing more to do. |
|
1272 |
Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
|
1273 |
Q_ASSERT(internalWinId()); |
|
1274 |
return; |
|
1275 |
} |
|
1276 |
} |
|
1277 |
||
1278 |
#ifdef QT3_SUPPORT |
|
1279 |
if (flags & Qt::WStaticContents) |
|
1280 |
setAttribute(Qt::WA_StaticContents); |
|
1281 |
if (flags & Qt::WDestructiveClose) |
|
1282 |
setAttribute(Qt::WA_DeleteOnClose); |
|
1283 |
if (flags & Qt::WShowModal) |
|
1284 |
setWindowModality(Qt::ApplicationModal); |
|
1285 |
if (flags & Qt::WMouseNoMask) |
|
1286 |
setAttribute(Qt::WA_MouseNoMask); |
|
1287 |
if (flags & Qt::WGroupLeader) |
|
1288 |
setAttribute(Qt::WA_GroupLeader); |
|
1289 |
if (flags & Qt::WNoMousePropagation) |
|
1290 |
setAttribute(Qt::WA_NoMousePropagation); |
|
1291 |
#endif |
|
1292 |
||
1293 |
static int paintOnScreenEnv = -1; |
|
1294 |
if (paintOnScreenEnv == -1) |
|
1295 |
paintOnScreenEnv = qgetenv("QT_ONSCREEN_PAINT").toInt() > 0 ? 1 : 0; |
|
1296 |
if (paintOnScreenEnv == 1) |
|
1297 |
setAttribute(Qt::WA_PaintOnScreen); |
|
1298 |
||
1299 |
if (QApplicationPrivate::testAttribute(Qt::AA_NativeWindows)) |
|
1300 |
setAttribute(Qt::WA_NativeWindow); |
|
1301 |
||
1302 |
#ifdef ALIEN_DEBUG |
|
1303 |
qDebug() << "QWidget::create:" << this << "parent:" << parentWidget() |
|
1304 |
<< "Alien?" << !testAttribute(Qt::WA_NativeWindow); |
|
1305 |
#endif |
|
1306 |
||
1307 |
#if defined (Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP) |
|
1308 |
// Unregister the dropsite (if already registered) before we |
|
1309 |
// re-create the widget with a native window. |
|
1310 |
if (testAttribute(Qt::WA_WState_Created) && !internalWinId() && testAttribute(Qt::WA_NativeWindow) |
|
1311 |
&& d->extra && d->extra->dropTarget) { |
|
1312 |
d->registerDropSite(false); |
|
1313 |
} |
|
1314 |
#endif // defined (Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP) |
|
1315 |
||
1316 |
d->updateIsOpaque(); |
|
1317 |
||
1318 |
setAttribute(Qt::WA_WState_Created); // set created flag |
|
1319 |
d->create_sys(window, initializeWindow, destroyOldWindow); |
|
1320 |
||
1321 |
// a real toplevel window needs a backing store |
|
1322 |
if (isWindow() && windowType() != Qt::Desktop) { |
|
1323 |
delete d->topData()->backingStore; |
|
1324 |
// QWidgetBackingStore will check this variable, hence it must be 0 |
|
1325 |
d->topData()->backingStore = 0; |
|
1326 |
if (hasBackingStoreSupport()) |
|
1327 |
d->topData()->backingStore = new QWidgetBackingStore(this); |
|
1328 |
} |
|
1329 |
||
1330 |
d->setModal_sys(); |
|
1331 |
||
1332 |
if (!isWindow() && parentWidget() && parentWidget()->testAttribute(Qt::WA_DropSiteRegistered)) |
|
1333 |
setAttribute(Qt::WA_DropSiteRegistered, true); |
|
1334 |
||
1335 |
#ifdef QT_EVAL |
|
1336 |
extern void qt_eval_init_widget(QWidget *w); |
|
1337 |
qt_eval_init_widget(this); |
|
1338 |
#endif |
|
1339 |
||
1340 |
// need to force the resting of the icon after changing parents |
|
1341 |
if (testAttribute(Qt::WA_SetWindowIcon)) |
|
1342 |
d->setWindowIcon_sys(true); |
|
1343 |
if (isWindow() && !d->topData()->iconText.isEmpty()) |
|
1344 |
d->setWindowIconText_helper(d->topData()->iconText); |
|
1345 |
if (isWindow() && !d->topData()->caption.isEmpty()) |
|
1346 |
d->setWindowTitle_helper(d->topData()->caption); |
|
1347 |
if (windowType() != Qt::Desktop) { |
|
1348 |
d->updateSystemBackground(); |
|
1349 |
||
1350 |
if (isWindow() && !testAttribute(Qt::WA_SetWindowIcon)) |
|
1351 |
d->setWindowIcon_sys(); |
|
1352 |
} |
|
1353 |
} |
|
1354 |
||
1355 |
/*! |
|
1356 |
Destroys the widget. |
|
1357 |
||
1358 |
All this widget's children are deleted first. The application |
|
1359 |
exits if this widget is the main widget. |
|
1360 |
*/ |
|
1361 |
||
1362 |
QWidget::~QWidget() |
|
1363 |
{ |
|
1364 |
Q_D(QWidget); |
|
1365 |
d->data.in_destructor = true; |
|
1366 |
||
1367 |
#if defined (QT_CHECK_STATE) |
|
1368 |
if (paintingActive()) |
|
1369 |
qWarning("QWidget: %s (%s) deleted while being painted", className(), name()); |
|
1370 |
#endif |
|
1371 |
||
1372 |
// force acceptDrops false before winId is destroyed. |
|
1373 |
d->registerDropSite(false); |
|
1374 |
||
1375 |
#ifndef QT_NO_ACTION |
|
1376 |
// remove all actions from this widget |
|
1377 |
for (int i = 0; i < d->actions.size(); ++i) { |
|
1378 |
QActionPrivate *apriv = d->actions.at(i)->d_func(); |
|
1379 |
apriv->widgets.removeAll(this); |
|
1380 |
} |
|
1381 |
d->actions.clear(); |
|
1382 |
#endif |
|
1383 |
||
1384 |
#ifndef QT_NO_SHORTCUT |
|
1385 |
// Remove all shortcuts grabbed by this |
|
1386 |
// widget, unless application is closing |
|
1387 |
if (!QApplicationPrivate::is_app_closing && testAttribute(Qt::WA_GrabbedShortcut)) |
|
1388 |
qApp->d_func()->shortcutMap.removeShortcut(0, this, QKeySequence()); |
|
1389 |
#endif |
|
1390 |
||
1391 |
// delete layout while we still are a valid widget |
|
1392 |
delete d->layout; |
|
1393 |
// Remove myself from focus list |
|
1394 |
||
1395 |
Q_ASSERT(d->focus_next->d_func()->focus_prev == this); |
|
1396 |
Q_ASSERT(d->focus_prev->d_func()->focus_next == this); |
|
1397 |
||
1398 |
if (d->focus_next != this) { |
|
1399 |
d->focus_next->d_func()->focus_prev = d->focus_prev; |
|
1400 |
d->focus_prev->d_func()->focus_next = d->focus_next; |
|
1401 |
d->focus_next = d->focus_prev = 0; |
|
1402 |
} |
|
1403 |
||
1404 |
#ifdef QT3_SUPPORT |
|
1405 |
if (QApplicationPrivate::main_widget == this) { // reset main widget |
|
1406 |
QApplicationPrivate::main_widget = 0; |
|
1407 |
QApplication::quit(); |
|
1408 |
} |
|
1409 |
#endif |
|
1410 |
||
1411 |
QT_TRY { |
|
1412 |
clearFocus(); |
|
1413 |
} QT_CATCH(...) { |
|
1414 |
// swallow this problem because we are in a destructor |
|
1415 |
} |
|
1416 |
||
1417 |
d->setDirtyOpaqueRegion(); |
|
1418 |
||
1419 |
if (isWindow() && isVisible() && internalWinId()) { |
|
1420 |
QT_TRY { |
|
1421 |
d->close_helper(QWidgetPrivate::CloseNoEvent); |
|
1422 |
} QT_CATCH(...) { |
|
1423 |
// if we're out of memory, at least hide the window. |
|
1424 |
QT_TRY { |
|
1425 |
hide(); |
|
1426 |
} QT_CATCH(...) { |
|
1427 |
// and if that also doesn't work, then give up |
|
1428 |
} |
|
1429 |
} |
|
1430 |
} |
|
1431 |
||
1432 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) |
|
1433 |
else if (!internalWinId() && isVisible()) { |
|
1434 |
qApp->d_func()->sendSyntheticEnterLeave(this); |
|
1435 |
#ifdef Q_WS_QWS |
|
1436 |
} else if (isVisible()) { |
|
1437 |
qApp->d_func()->sendSyntheticEnterLeave(this); |
|
1438 |
#endif |
|
1439 |
} |
|
1440 |
#endif |
|
1441 |
||
1442 |
if (QWidgetBackingStore *bs = d->maybeBackingStore()) { |
|
1443 |
bs->removeDirtyWidget(this); |
|
1444 |
if (testAttribute(Qt::WA_StaticContents)) |
|
1445 |
bs->removeStaticWidget(this); |
|
1446 |
} |
|
1447 |
||
1448 |
delete d->needsFlush; |
|
1449 |
d->needsFlush = 0; |
|
1450 |
||
1451 |
// set all QPointers for this object to zero |
|
1452 |
QObjectPrivate::clearGuards(this); |
|
1453 |
||
1454 |
if (d->declarativeData) { |
|
1455 |
d->declarativeData->destroyed(this); |
|
1456 |
d->declarativeData = 0; // don't activate again in ~QObject |
|
1457 |
} |
|
1458 |
||
1459 |
if (!d->children.isEmpty()) |
|
1460 |
d->deleteChildren(); |
|
1461 |
||
1462 |
QApplication::removePostedEvents(this); |
|
1463 |
||
1464 |
QT_TRY { |
|
1465 |
destroy(); // platform-dependent cleanup |
|
1466 |
} QT_CATCH(...) { |
|
1467 |
// if this fails we can't do anything about it but at least we are not allowed to throw. |
|
1468 |
} |
|
1469 |
--QWidgetPrivate::instanceCounter; |
|
1470 |
||
1471 |
if (QWidgetPrivate::allWidgets) // might have been deleted by ~QApplication |
|
1472 |
QWidgetPrivate::allWidgets->remove(this); |
|
1473 |
||
1474 |
QEvent e(QEvent::Destroy); |
|
1475 |
QCoreApplication::sendEvent(this, &e); |
|
1476 |
} |
|
1477 |
||
1478 |
int QWidgetPrivate::instanceCounter = 0; // Current number of widget instances |
|
1479 |
int QWidgetPrivate::maxInstances = 0; // Maximum number of widget instances |
|
1480 |
||
1481 |
void QWidgetPrivate::setWinId(WId id) // set widget identifier |
|
1482 |
{ |
|
1483 |
Q_Q(QWidget); |
|
1484 |
// the user might create a widget with Qt::Desktop window |
|
1485 |
// attribute (or create another QDesktopWidget instance), which |
|
1486 |
// will have the same windowid (the root window id) as the |
|
1487 |
// qt_desktopWidget. We should not add the second desktop widget |
|
1488 |
// to the mapper. |
|
1489 |
bool userDesktopWidget = qt_desktopWidget != 0 && qt_desktopWidget != q && q->windowType() == Qt::Desktop; |
|
1490 |
if (mapper && data.winid && !userDesktopWidget) { |
|
1491 |
mapper->remove(data.winid); |
|
1492 |
} |
|
1493 |
||
1494 |
const WId oldWinId = data.winid; |
|
1495 |
||
1496 |
data.winid = id; |
|
1497 |
#if defined(Q_WS_X11) |
|
1498 |
hd = id; // X11: hd == ident |
|
1499 |
#endif |
|
1500 |
if (mapper && id && !userDesktopWidget) { |
|
1501 |
mapper->insert(data.winid, q); |
|
1502 |
} |
|
1503 |
||
1504 |
if(oldWinId != id) { |
|
1505 |
// Do not emit an event when the old winId is destroyed. This only |
|
1506 |
// happens (a) during widget destruction, and (b) immediately prior |
|
1507 |
// to creation of a new winId, for example as a result of re-parenting. |
|
1508 |
if(id != 0) { |
|
1509 |
QEvent e(QEvent::WinIdChange); |
|
1510 |
QCoreApplication::sendEvent(q, &e); |
|
1511 |
} |
|
1512 |
} |
|
1513 |
} |
|
1514 |
||
1515 |
void QWidgetPrivate::createTLExtra() |
|
1516 |
{ |
|
1517 |
if (!extra) |
|
1518 |
createExtra(); |
|
1519 |
if (!extra->topextra) { |
|
1520 |
QTLWExtra* x = extra->topextra = new QTLWExtra; |
|
1521 |
x->icon = 0; |
|
1522 |
x->iconPixmap = 0; |
|
1523 |
x->backingStore = 0; |
|
1524 |
x->windowSurface = 0; |
|
1525 |
x->sharedPainter = 0; |
|
1526 |
x->incw = x->inch = 0; |
|
1527 |
x->basew = x->baseh = 0; |
|
1528 |
x->frameStrut.setCoords(0, 0, 0, 0); |
|
1529 |
x->normalGeometry = QRect(0,0,-1,-1); |
|
1530 |
x->savedFlags = 0; |
|
1531 |
x->opacity = 255; |
|
1532 |
x->posFromMove = false; |
|
1533 |
x->sizeAdjusted = false; |
|
1534 |
x->inTopLevelResize = false; |
|
1535 |
x->inRepaint = false; |
|
1536 |
x->embedded = 0; |
|
1537 |
createTLSysExtra(); |
|
1538 |
#ifdef QWIDGET_EXTRA_DEBUG |
|
1539 |
static int count = 0; |
|
1540 |
qDebug() << "tlextra" << ++count; |
|
1541 |
#endif |
|
1542 |
} |
|
1543 |
} |
|
1544 |
||
1545 |
/*! |
|
1546 |
\internal |
|
1547 |
Creates the widget extra data. |
|
1548 |
*/ |
|
1549 |
||
1550 |
void QWidgetPrivate::createExtra() |
|
1551 |
{ |
|
1552 |
if (!extra) { // if not exists |
|
1553 |
extra = new QWExtra; |
|
1554 |
extra->glContext = 0; |
|
1555 |
extra->topextra = 0; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1556 |
#ifndef QT_NO_GRAPHICSVIEW |
0 | 1557 |
extra->proxyWidget = 0; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1558 |
#endif |
0 | 1559 |
#ifndef QT_NO_CURSOR |
1560 |
extra->curs = 0; |
|
1561 |
#endif |
|
1562 |
extra->minw = 0; |
|
1563 |
extra->minh = 0; |
|
1564 |
extra->maxw = QWIDGETSIZE_MAX; |
|
1565 |
extra->maxh = QWIDGETSIZE_MAX; |
|
1566 |
extra->customDpiX = 0; |
|
1567 |
extra->customDpiY = 0; |
|
1568 |
extra->explicitMinSize = 0; |
|
1569 |
extra->explicitMaxSize = 0; |
|
1570 |
extra->autoFillBackground = 0; |
|
1571 |
extra->nativeChildrenForced = 0; |
|
1572 |
extra->inRenderWithPainter = 0; |
|
1573 |
extra->hasMask = 0; |
|
1574 |
createSysExtra(); |
|
1575 |
#ifdef QWIDGET_EXTRA_DEBUG |
|
1576 |
static int count = 0; |
|
1577 |
qDebug() << "extra" << ++count; |
|
1578 |
#endif |
|
1579 |
} |
|
1580 |
} |
|
1581 |
||
1582 |
||
1583 |
/*! |
|
1584 |
\internal |
|
1585 |
Deletes the widget extra data. |
|
1586 |
*/ |
|
1587 |
||
1588 |
void QWidgetPrivate::deleteExtra() |
|
1589 |
{ |
|
1590 |
if (extra) { // if exists |
|
1591 |
#ifndef QT_NO_CURSOR |
|
1592 |
delete extra->curs; |
|
1593 |
#endif |
|
1594 |
deleteSysExtra(); |
|
1595 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
1596 |
// dereference the stylesheet style |
|
1597 |
if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(extra->style)) |
|
1598 |
proxy->deref(); |
|
1599 |
#endif |
|
1600 |
if (extra->topextra) { |
|
1601 |
deleteTLSysExtra(); |
|
1602 |
delete extra->topextra->backingStore; |
|
1603 |
delete extra->topextra->icon; |
|
1604 |
delete extra->topextra->iconPixmap; |
|
1605 |
#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER) |
|
1606 |
delete extra->topextra->qwsManager; |
|
1607 |
#endif |
|
1608 |
delete extra->topextra->windowSurface; |
|
1609 |
delete extra->topextra; |
|
1610 |
} |
|
1611 |
delete extra; |
|
1612 |
// extra->xic destroyed in QWidget::destroy() |
|
1613 |
extra = 0; |
|
1614 |
} |
|
1615 |
} |
|
1616 |
||
1617 |
/* |
|
1618 |
Returns true if there are widgets above this which overlap with |
|
1619 |
\a rect, which is in parent's coordinate system (same as crect). |
|
1620 |
*/ |
|
1621 |
||
1622 |
bool QWidgetPrivate::isOverlapped(const QRect &rect) const |
|
1623 |
{ |
|
1624 |
Q_Q(const QWidget); |
|
1625 |
||
1626 |
const QWidget *w = q; |
|
1627 |
QRect r = rect; |
|
1628 |
while (w) { |
|
1629 |
if (w->isWindow()) |
|
1630 |
return false; |
|
1631 |
QWidgetPrivate *pd = w->parentWidget()->d_func(); |
|
1632 |
bool above = false; |
|
1633 |
for (int i = 0; i < pd->children.size(); ++i) { |
|
1634 |
QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i)); |
|
1635 |
if (!sibling || !sibling->isVisible() || sibling->isWindow()) |
|
1636 |
continue; |
|
1637 |
if (!above) { |
|
1638 |
above = (sibling == w); |
|
1639 |
continue; |
|
1640 |
} |
|
1641 |
||
1642 |
if (qRectIntersects(sibling->d_func()->effectiveRectFor(sibling->data->crect), r)) { |
|
1643 |
const QWExtra *siblingExtra = sibling->d_func()->extra; |
|
1644 |
if (siblingExtra && siblingExtra->hasMask && !sibling->d_func()->graphicsEffect |
|
1645 |
&& !siblingExtra->mask.translated(sibling->data->crect.topLeft()).intersects(r)) { |
|
1646 |
continue; |
|
1647 |
} |
|
1648 |
return true; |
|
1649 |
} |
|
1650 |
} |
|
1651 |
w = w->parentWidget(); |
|
1652 |
r.translate(pd->data.crect.topLeft()); |
|
1653 |
} |
|
1654 |
return false; |
|
1655 |
} |
|
1656 |
||
1657 |
void QWidgetPrivate::syncBackingStore() |
|
1658 |
{ |
|
1659 |
if (paintOnScreen()) { |
|
1660 |
repaint_sys(dirty); |
|
1661 |
dirty = QRegion(); |
|
1662 |
} else if (QWidgetBackingStore *bs = maybeBackingStore()) { |
|
1663 |
bs->sync(); |
|
1664 |
} |
|
1665 |
} |
|
1666 |
||
1667 |
void QWidgetPrivate::syncBackingStore(const QRegion ®ion) |
|
1668 |
{ |
|
1669 |
if (paintOnScreen()) |
|
1670 |
repaint_sys(region); |
|
1671 |
else if (QWidgetBackingStore *bs = maybeBackingStore()) |
|
1672 |
bs->sync(q_func(), region); |
|
1673 |
} |
|
1674 |
||
1675 |
void QWidgetPrivate::setUpdatesEnabled_helper(bool enable) |
|
1676 |
{ |
|
1677 |
Q_Q(QWidget); |
|
1678 |
||
1679 |
if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->updatesEnabled()) |
|
1680 |
return; // nothing we can do |
|
1681 |
||
1682 |
if (enable != q->testAttribute(Qt::WA_UpdatesDisabled)) |
|
1683 |
return; // nothing to do |
|
1684 |
||
1685 |
q->setAttribute(Qt::WA_UpdatesDisabled, !enable); |
|
1686 |
if (enable) |
|
1687 |
q->update(); |
|
1688 |
||
1689 |
Qt::WidgetAttribute attribute = enable ? Qt::WA_ForceUpdatesDisabled : Qt::WA_UpdatesDisabled; |
|
1690 |
for (int i = 0; i < children.size(); ++i) { |
|
1691 |
QWidget *w = qobject_cast<QWidget *>(children.at(i)); |
|
1692 |
if (w && !w->isWindow() && !w->testAttribute(attribute)) |
|
1693 |
w->d_func()->setUpdatesEnabled_helper(enable); |
|
1694 |
} |
|
1695 |
} |
|
1696 |
||
1697 |
/*! |
|
1698 |
\internal |
|
1699 |
||
1700 |
Propagate this widget's palette to all children, except style sheet |
|
1701 |
widgets, and windows that don't enable window propagation (palettes don't |
|
1702 |
normally propagate to windows). |
|
1703 |
*/ |
|
1704 |
void QWidgetPrivate::propagatePaletteChange() |
|
1705 |
{ |
|
1706 |
Q_Q(QWidget); |
|
1707 |
// Propagate a new inherited mask to all children. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1708 |
#ifndef QT_NO_GRAPHICSVIEW |
0 | 1709 |
if (!q->parentWidget() && extra && extra->proxyWidget) { |
1710 |
QGraphicsProxyWidget *p = extra->proxyWidget; |
|
1711 |
inheritedPaletteResolveMask = p->d_func()->inheritedPaletteResolveMask | p->palette().resolve(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1712 |
} else |
0 | 1713 |
#endif //QT_NO_GRAPHICSVIEW |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1714 |
if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) { |
0 | 1715 |
inheritedPaletteResolveMask = 0; |
1716 |
} |
|
1717 |
int mask = data.pal.resolve() | inheritedPaletteResolveMask; |
|
1718 |
||
1719 |
QEvent pc(QEvent::PaletteChange); |
|
1720 |
QApplication::sendEvent(q, &pc); |
|
1721 |
for (int i = 0; i < children.size(); ++i) { |
|
1722 |
QWidget *w = qobject_cast<QWidget*>(children.at(i)); |
|
1723 |
if (w && !w->testAttribute(Qt::WA_StyleSheet) |
|
1724 |
&& (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) { |
|
1725 |
QWidgetPrivate *wd = w->d_func(); |
|
1726 |
wd->inheritedPaletteResolveMask = mask; |
|
1727 |
wd->resolvePalette(); |
|
1728 |
} |
|
1729 |
} |
|
1730 |
#if defined(QT3_SUPPORT) |
|
1731 |
q->paletteChange(q->palette()); // compatibility |
|
1732 |
#endif |
|
1733 |
} |
|
1734 |
||
1735 |
/* |
|
1736 |
Returns the widget's clipping rectangle. |
|
1737 |
*/ |
|
1738 |
QRect QWidgetPrivate::clipRect() const |
|
1739 |
{ |
|
1740 |
Q_Q(const QWidget); |
|
1741 |
const QWidget * w = q; |
|
1742 |
if (!w->isVisible()) |
|
1743 |
return QRect(); |
|
1744 |
QRect r = effectiveRectFor(q->rect()); |
|
1745 |
int ox = 0; |
|
1746 |
int oy = 0; |
|
1747 |
while (w |
|
1748 |
&& w->isVisible() |
|
1749 |
&& !w->isWindow() |
|
1750 |
&& w->parentWidget()) { |
|
1751 |
ox -= w->x(); |
|
1752 |
oy -= w->y(); |
|
1753 |
w = w->parentWidget(); |
|
1754 |
r &= QRect(ox, oy, w->width(), w->height()); |
|
1755 |
} |
|
1756 |
return r; |
|
1757 |
} |
|
1758 |
||
1759 |
/* |
|
1760 |
Returns the widget's clipping region (without siblings). |
|
1761 |
*/ |
|
1762 |
QRegion QWidgetPrivate::clipRegion() const |
|
1763 |
{ |
|
1764 |
Q_Q(const QWidget); |
|
1765 |
if (!q->isVisible()) |
|
1766 |
return QRegion(); |
|
1767 |
QRegion r(q->rect()); |
|
1768 |
const QWidget * w = q; |
|
1769 |
const QWidget *ignoreUpTo; |
|
1770 |
int ox = 0; |
|
1771 |
int oy = 0; |
|
1772 |
while (w |
|
1773 |
&& w->isVisible() |
|
1774 |
&& !w->isWindow() |
|
1775 |
&& w->parentWidget()) { |
|
1776 |
ox -= w->x(); |
|
1777 |
oy -= w->y(); |
|
1778 |
ignoreUpTo = w; |
|
1779 |
w = w->parentWidget(); |
|
1780 |
r &= QRegion(ox, oy, w->width(), w->height()); |
|
1781 |
||
1782 |
int i = 0; |
|
1783 |
while(w->d_func()->children.at(i++) != static_cast<const QObject *>(ignoreUpTo)) |
|
1784 |
; |
|
1785 |
for ( ; i < w->d_func()->children.size(); ++i) { |
|
1786 |
if(QWidget *sibling = qobject_cast<QWidget *>(w->d_func()->children.at(i))) { |
|
1787 |
if(sibling->isVisible() && !sibling->isWindow()) { |
|
1788 |
QRect siblingRect(ox+sibling->x(), oy+sibling->y(), |
|
1789 |
sibling->width(), sibling->height()); |
|
1790 |
if (qRectIntersects(siblingRect, q->rect())) |
|
1791 |
r -= QRegion(siblingRect); |
|
1792 |
} |
|
1793 |
} |
|
1794 |
} |
|
1795 |
} |
|
1796 |
return r; |
|
1797 |
} |
|
1798 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1799 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 1800 |
void QWidgetPrivate::invalidateGraphicsEffectsRecursively() |
1801 |
{ |
|
1802 |
Q_Q(QWidget); |
|
1803 |
QWidget *w = q; |
|
1804 |
do { |
|
1805 |
if (w->graphicsEffect()) { |
|
1806 |
QWidgetEffectSourcePrivate *sourced = |
|
1807 |
static_cast<QWidgetEffectSourcePrivate *>(w->graphicsEffect()->source()->d_func()); |
|
1808 |
if (!sourced->updateDueToGraphicsEffect) |
|
1809 |
w->graphicsEffect()->source()->d_func()->invalidateCache(); |
|
1810 |
} |
|
1811 |
w = w->parentWidget(); |
|
1812 |
} while (w); |
|
1813 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1814 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 1815 |
|
1816 |
void QWidgetPrivate::setDirtyOpaqueRegion() |
|
1817 |
{ |
|
1818 |
Q_Q(QWidget); |
|
1819 |
||
1820 |
dirtyOpaqueChildren = true; |
|
1821 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1822 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 1823 |
invalidateGraphicsEffectsRecursively(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1824 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 1825 |
|
1826 |
if (q->isWindow()) |
|
1827 |
return; |
|
1828 |
||
1829 |
QWidget *parent = q->parentWidget(); |
|
1830 |
if (!parent) |
|
1831 |
return; |
|
1832 |
||
1833 |
// TODO: instead of setting dirtyflag, manipulate the dirtyregion directly? |
|
1834 |
QWidgetPrivate *pd = parent->d_func(); |
|
1835 |
if (!pd->dirtyOpaqueChildren) |
|
1836 |
pd->setDirtyOpaqueRegion(); |
|
1837 |
} |
|
1838 |
||
1839 |
const QRegion &QWidgetPrivate::getOpaqueChildren() const |
|
1840 |
{ |
|
1841 |
if (!dirtyOpaqueChildren) |
|
1842 |
return opaqueChildren; |
|
1843 |
||
1844 |
QWidgetPrivate *that = const_cast<QWidgetPrivate*>(this); |
|
1845 |
that->opaqueChildren = QRegion(); |
|
1846 |
||
1847 |
for (int i = 0; i < children.size(); ++i) { |
|
1848 |
QWidget *child = qobject_cast<QWidget *>(children.at(i)); |
|
1849 |
if (!child || !child->isVisible() || child->isWindow()) |
|
1850 |
continue; |
|
1851 |
||
1852 |
const QPoint offset = child->geometry().topLeft(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1853 |
QWidgetPrivate *childd = child->d_func(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1854 |
QRegion r = childd->isOpaque ? child->rect() : childd->getOpaqueChildren(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1855 |
if (childd->extra && childd->extra->hasMask) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1856 |
r &= childd->extra->mask; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1857 |
if (r.isEmpty()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1858 |
continue; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1859 |
r.translate(offset); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1860 |
that->opaqueChildren += r; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1861 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1862 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1863 |
that->opaqueChildren &= q_func()->rect(); |
0 | 1864 |
that->dirtyOpaqueChildren = false; |
1865 |
||
1866 |
return that->opaqueChildren; |
|
1867 |
} |
|
1868 |
||
1869 |
void QWidgetPrivate::subtractOpaqueChildren(QRegion &source, const QRect &clipRect) const |
|
1870 |
{ |
|
1871 |
if (children.isEmpty() || clipRect.isEmpty()) |
|
1872 |
return; |
|
1873 |
||
1874 |
const QRegion &r = getOpaqueChildren(); |
|
1875 |
if (!r.isEmpty()) |
|
1876 |
source -= (r & clipRect); |
|
1877 |
} |
|
1878 |
||
1879 |
//subtract any relatives that are higher up than me --- this is too expensive !!! |
|
1880 |
void QWidgetPrivate::subtractOpaqueSiblings(QRegion &sourceRegion, bool *hasDirtySiblingsAbove, |
|
1881 |
bool alsoNonOpaque) const |
|
1882 |
{ |
|
1883 |
Q_Q(const QWidget); |
|
1884 |
static int disableSubtractOpaqueSiblings = qgetenv("QT_NO_SUBTRACTOPAQUESIBLINGS").toInt(); |
|
1885 |
if (disableSubtractOpaqueSiblings || q->isWindow()) |
|
1886 |
return; |
|
1887 |
||
1888 |
QRect clipBoundingRect; |
|
1889 |
bool dirtyClipBoundingRect = true; |
|
1890 |
||
1891 |
QRegion parentClip; |
|
1892 |
bool dirtyParentClip = true; |
|
1893 |
||
1894 |
QPoint parentOffset = data.crect.topLeft(); |
|
1895 |
||
1896 |
const QWidget *w = q; |
|
1897 |
||
1898 |
while (w) { |
|
1899 |
if (w->isWindow()) |
|
1900 |
break; |
|
1901 |
QWidgetPrivate *pd = w->parentWidget()->d_func(); |
|
1902 |
const int myIndex = pd->children.indexOf(const_cast<QWidget *>(w)); |
|
1903 |
const QRect widgetGeometry = w->d_func()->effectiveRectFor(w->data->crect); |
|
1904 |
for (int i = myIndex + 1; i < pd->children.size(); ++i) { |
|
1905 |
QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i)); |
|
1906 |
if (!sibling || !sibling->isVisible() || sibling->isWindow()) |
|
1907 |
continue; |
|
1908 |
||
1909 |
const QRect siblingGeometry = sibling->d_func()->effectiveRectFor(sibling->data->crect); |
|
1910 |
if (!qRectIntersects(siblingGeometry, widgetGeometry)) |
|
1911 |
continue; |
|
1912 |
||
1913 |
if (dirtyClipBoundingRect) { |
|
1914 |
clipBoundingRect = sourceRegion.boundingRect(); |
|
1915 |
dirtyClipBoundingRect = false; |
|
1916 |
} |
|
1917 |
||
1918 |
if (!qRectIntersects(siblingGeometry, clipBoundingRect.translated(parentOffset))) |
|
1919 |
continue; |
|
1920 |
||
1921 |
if (dirtyParentClip) { |
|
1922 |
parentClip = sourceRegion.translated(parentOffset); |
|
1923 |
dirtyParentClip = false; |
|
1924 |
} |
|
1925 |
||
1926 |
const QPoint siblingPos(sibling->data->crect.topLeft()); |
|
1927 |
const QRect siblingClipRect(sibling->d_func()->clipRect()); |
|
1928 |
QRegion siblingDirty(parentClip); |
|
1929 |
siblingDirty &= (siblingClipRect.translated(siblingPos)); |
|
1930 |
const bool hasMask = sibling->d_func()->extra && sibling->d_func()->extra->hasMask |
|
1931 |
&& !sibling->d_func()->graphicsEffect; |
|
1932 |
if (hasMask) |
|
1933 |
siblingDirty &= sibling->d_func()->extra->mask.translated(siblingPos); |
|
1934 |
if (siblingDirty.isEmpty()) |
|
1935 |
continue; |
|
1936 |
||
1937 |
if (sibling->d_func()->isOpaque || alsoNonOpaque) { |
|
1938 |
if (hasMask) { |
|
1939 |
siblingDirty.translate(-parentOffset); |
|
1940 |
sourceRegion -= siblingDirty; |
|
1941 |
} else { |
|
1942 |
sourceRegion -= siblingGeometry.translated(-parentOffset); |
|
1943 |
} |
|
1944 |
} else { |
|
1945 |
if (hasDirtySiblingsAbove) |
|
1946 |
*hasDirtySiblingsAbove = true; |
|
1947 |
if (sibling->d_func()->children.isEmpty()) |
|
1948 |
continue; |
|
1949 |
QRegion opaqueSiblingChildren(sibling->d_func()->getOpaqueChildren()); |
|
1950 |
opaqueSiblingChildren.translate(-parentOffset + siblingPos); |
|
1951 |
sourceRegion -= opaqueSiblingChildren; |
|
1952 |
} |
|
1953 |
if (sourceRegion.isEmpty()) |
|
1954 |
return; |
|
1955 |
||
1956 |
dirtyClipBoundingRect = true; |
|
1957 |
dirtyParentClip = true; |
|
1958 |
} |
|
1959 |
||
1960 |
w = w->parentWidget(); |
|
1961 |
parentOffset += pd->data.crect.topLeft(); |
|
1962 |
dirtyParentClip = true; |
|
1963 |
} |
|
1964 |
} |
|
1965 |
||
1966 |
void QWidgetPrivate::clipToEffectiveMask(QRegion ®ion) const |
|
1967 |
{ |
|
1968 |
Q_Q(const QWidget); |
|
1969 |
||
1970 |
const QWidget *w = q; |
|
1971 |
QPoint offset; |
|
1972 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1973 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 1974 |
if (graphicsEffect) { |
1975 |
w = q->parentWidget(); |
|
1976 |
offset -= data.crect.topLeft(); |
|
1977 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1978 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 1979 |
|
1980 |
while (w) { |
|
1981 |
const QWidgetPrivate *wd = w->d_func(); |
|
1982 |
if (wd->extra && wd->extra->hasMask) |
|
1983 |
region &= (w != q) ? wd->extra->mask.translated(offset) : wd->extra->mask; |
|
1984 |
if (w->isWindow()) |
|
1985 |
return; |
|
1986 |
offset -= wd->data.crect.topLeft(); |
|
1987 |
w = w->parentWidget(); |
|
1988 |
} |
|
1989 |
} |
|
1990 |
||
1991 |
bool QWidgetPrivate::paintOnScreen() const |
|
1992 |
{ |
|
1993 |
#if defined(Q_WS_QWS) |
|
1994 |
return false; |
|
1995 |
#elif defined(QT_NO_BACKINGSTORE) |
|
1996 |
return true; |
|
1997 |
#else |
|
1998 |
Q_Q(const QWidget); |
|
1999 |
if (q->testAttribute(Qt::WA_PaintOnScreen) |
|
2000 |
|| (!q->isWindow() && q->window()->testAttribute(Qt::WA_PaintOnScreen))) { |
|
2001 |
return true; |
|
2002 |
} |
|
2003 |
||
2004 |
return !qt_enable_backingstore; |
|
2005 |
#endif |
|
2006 |
} |
|
2007 |
||
2008 |
void QWidgetPrivate::updateIsOpaque() |
|
2009 |
{ |
|
2010 |
// hw: todo: only needed if opacity actually changed |
|
2011 |
setDirtyOpaqueRegion(); |
|
2012 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2013 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 2014 |
if (graphicsEffect) { |
2015 |
// ### We should probably add QGraphicsEffect::isOpaque at some point. |
|
2016 |
setOpaque(false); |
|
2017 |
return; |
|
2018 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2019 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 2020 |
|
2021 |
Q_Q(QWidget); |
|
2022 |
#ifdef Q_WS_X11 |
|
2023 |
if (q->testAttribute(Qt::WA_X11OpenGLOverlay)) { |
|
2024 |
setOpaque(false); |
|
2025 |
return; |
|
2026 |
} |
|
2027 |
#endif |
|
2028 |
||
2029 |
if (q->testAttribute(Qt::WA_OpaquePaintEvent) || q->testAttribute(Qt::WA_PaintOnScreen)) { |
|
2030 |
setOpaque(true); |
|
2031 |
return; |
|
2032 |
} |
|
2033 |
||
2034 |
const QPalette &pal = q->palette(); |
|
2035 |
||
2036 |
if (q->autoFillBackground()) { |
|
2037 |
const QBrush &autoFillBrush = pal.brush(q->backgroundRole()); |
|
2038 |
if (autoFillBrush.style() != Qt::NoBrush && autoFillBrush.isOpaque()) { |
|
2039 |
setOpaque(true); |
|
2040 |
return; |
|
2041 |
} |
|
2042 |
} |
|
2043 |
||
2044 |
if (q->isWindow() && !q->testAttribute(Qt::WA_NoSystemBackground)) { |
|
2045 |
const QBrush &windowBrush = q->palette().brush(QPalette::Window); |
|
2046 |
if (windowBrush.style() != Qt::NoBrush && windowBrush.isOpaque()) { |
|
2047 |
setOpaque(true); |
|
2048 |
return; |
|
2049 |
} |
|
2050 |
} |
|
2051 |
setOpaque(false); |
|
2052 |
} |
|
2053 |
||
2054 |
void QWidgetPrivate::setOpaque(bool opaque) |
|
2055 |
{ |
|
2056 |
if (isOpaque == opaque) |
|
2057 |
return; |
|
2058 |
isOpaque = opaque; |
|
2059 |
#ifdef Q_WS_MAC |
|
2060 |
macUpdateIsOpaque(); |
|
2061 |
#endif |
|
2062 |
#ifdef Q_WS_X11 |
|
2063 |
x11UpdateIsOpaque(); |
|
2064 |
#endif |
|
2065 |
#ifdef Q_WS_WIN |
|
2066 |
winUpdateIsOpaque(); |
|
2067 |
#endif |
|
2068 |
#ifdef Q_OS_SYMBIAN |
|
2069 |
s60UpdateIsOpaque(); |
|
2070 |
#endif |
|
2071 |
} |
|
2072 |
||
2073 |
void QWidgetPrivate::updateIsTranslucent() |
|
2074 |
{ |
|
2075 |
#ifdef Q_WS_MAC |
|
2076 |
macUpdateIsOpaque(); |
|
2077 |
#endif |
|
2078 |
#ifdef Q_WS_X11 |
|
2079 |
x11UpdateIsOpaque(); |
|
2080 |
#endif |
|
2081 |
#ifdef Q_WS_WIN |
|
2082 |
winUpdateIsOpaque(); |
|
2083 |
#endif |
|
2084 |
#ifdef Q_OS_SYMBIAN |
|
2085 |
s60UpdateIsOpaque(); |
|
2086 |
#endif |
|
2087 |
} |
|
2088 |
||
2089 |
/*! |
|
2090 |
\fn void QPixmap::fill(const QWidget *widget, const QPoint &offset) |
|
2091 |
||
2092 |
Fills the pixmap with the \a widget's background color or pixmap |
|
2093 |
according to the given offset. |
|
2094 |
||
2095 |
The QPoint \a offset defines a point in widget coordinates to |
|
2096 |
which the pixmap's top-left pixel will be mapped to. This is only |
|
2097 |
significant if the widget has a background pixmap; otherwise the |
|
2098 |
pixmap will simply be filled with the background color of the |
|
2099 |
widget. |
|
2100 |
*/ |
|
2101 |
||
2102 |
void QPixmap::fill( const QWidget *widget, const QPoint &off ) |
|
2103 |
{ |
|
2104 |
QPainter p(this); |
|
2105 |
p.translate(-off); |
|
2106 |
widget->d_func()->paintBackground(&p, QRect(off, size())); |
|
2107 |
} |
|
2108 |
||
2109 |
static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush) |
|
2110 |
{ |
|
2111 |
Q_ASSERT(painter); |
|
2112 |
||
2113 |
if (brush.style() == Qt::TexturePattern) { |
|
2114 |
#ifdef Q_WS_MAC |
|
2115 |
// Optimize pattern filling on mac by using HITheme directly |
|
2116 |
// when filling with the standard widget background. |
|
2117 |
// Defined in qmacstyle_mac.cpp |
|
2118 |
extern void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush); |
|
2119 |
qt_mac_fill_background(painter, rgn, brush); |
|
2120 |
#else |
|
2121 |
#if !defined(QT_NO_STYLE_S60) |
|
2122 |
// Defined in qs60style.cpp |
|
2123 |
extern bool qt_s60_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush); |
|
2124 |
if (!qt_s60_fill_background(painter, rgn, brush)) |
|
2125 |
#endif // !defined(QT_NO_STYLE_S60) |
|
2126 |
{ |
|
2127 |
const QRect rect(rgn.boundingRect()); |
|
2128 |
painter->setClipRegion(rgn); |
|
2129 |
painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); |
|
2130 |
} |
|
2131 |
#endif // Q_WS_MAC |
|
2132 |
||
2133 |
} else if (brush.gradient() |
|
2134 |
&& brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode) { |
|
2135 |
painter->save(); |
|
2136 |
painter->setClipRegion(rgn); |
|
2137 |
painter->fillRect(0, 0, painter->device()->width(), painter->device()->height(), brush); |
|
2138 |
painter->restore(); |
|
2139 |
} else { |
|
2140 |
const QVector<QRect> &rects = rgn.rects(); |
|
2141 |
for (int i = 0; i < rects.size(); ++i) |
|
2142 |
painter->fillRect(rects.at(i), brush); |
|
2143 |
} |
|
2144 |
} |
|
2145 |
||
2146 |
void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int flags) const |
|
2147 |
{ |
|
2148 |
Q_Q(const QWidget); |
|
2149 |
||
2150 |
#ifndef QT_NO_SCROLLAREA |
|
2151 |
bool resetBrushOrigin = false; |
|
2152 |
QPointF oldBrushOrigin; |
|
2153 |
//If we are painting the viewport of a scrollarea, we must apply an offset to the brush in case we are drawing a texture |
|
2154 |
QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(parent); |
|
2155 |
if (scrollArea && scrollArea->viewport() == q) { |
|
2156 |
QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr.data(); |
|
2157 |
QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate); |
|
2158 |
oldBrushOrigin = painter->brushOrigin(); |
|
2159 |
resetBrushOrigin = true; |
|
2160 |
painter->setBrushOrigin(-priv->contentsOffset()); |
|
2161 |
||
2162 |
} |
|
2163 |
#endif // QT_NO_SCROLLAREA |
|
2164 |
||
2165 |
const QBrush autoFillBrush = q->palette().brush(q->backgroundRole()); |
|
2166 |
||
2167 |
if ((flags & DrawAsRoot) && !(q->autoFillBackground() && autoFillBrush.isOpaque())) { |
|
2168 |
const QBrush bg = q->palette().brush(QPalette::Window); |
|
2169 |
#ifdef Q_WS_QWS |
|
2170 |
if (!(flags & DontSetCompositionMode) && painter->paintEngine()->hasFeature(QPaintEngine::PorterDuff)) |
|
2171 |
painter->setCompositionMode(QPainter::CompositionMode_Source); //copy alpha straight in |
|
2172 |
#endif |
|
2173 |
fillRegion(painter, rgn, bg); |
|
2174 |
} |
|
2175 |
||
2176 |
if (q->autoFillBackground()) |
|
2177 |
fillRegion(painter, rgn, autoFillBrush); |
|
2178 |
||
2179 |
if (q->testAttribute(Qt::WA_StyledBackground)) { |
|
2180 |
painter->setClipRegion(rgn); |
|
2181 |
QStyleOption opt; |
|
2182 |
opt.initFrom(q); |
|
2183 |
q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q); |
|
2184 |
} |
|
2185 |
||
2186 |
#ifndef QT_NO_SCROLLAREA |
|
2187 |
if (resetBrushOrigin) |
|
2188 |
painter->setBrushOrigin(oldBrushOrigin); |
|
2189 |
#endif // QT_NO_SCROLLAREA |
|
2190 |
} |
|
2191 |
||
2192 |
/* |
|
2193 |
\internal |
|
2194 |
This function is called when a widget is hidden or destroyed. |
|
2195 |
It resets some application global pointers that should only refer active, |
|
2196 |
visible widgets. |
|
2197 |
*/ |
|
2198 |
||
2199 |
#ifdef Q_WS_MAC |
|
2200 |
extern QPointer<QWidget> qt_button_down; |
|
2201 |
#else |
|
2202 |
extern QWidget *qt_button_down; |
|
2203 |
#endif |
|
2204 |
||
2205 |
void QWidgetPrivate::deactivateWidgetCleanup() |
|
2206 |
{ |
|
2207 |
Q_Q(QWidget); |
|
2208 |
// If this was the active application window, reset it |
|
2209 |
if (QApplication::activeWindow() == q) |
|
2210 |
QApplication::setActiveWindow(0); |
|
2211 |
// If the is the active mouse press widget, reset it |
|
2212 |
if (q == qt_button_down) |
|
2213 |
qt_button_down = 0; |
|
2214 |
} |
|
2215 |
||
2216 |
||
2217 |
/*! |
|
2218 |
Returns a pointer to the widget with window identifer/handle \a |
|
2219 |
id. |
|
2220 |
||
2221 |
The window identifier type depends on the underlying window |
|
2222 |
system, see \c qwindowdefs.h for the actual definition. If there |
|
2223 |
is no widget with this identifier, 0 is returned. |
|
2224 |
*/ |
|
2225 |
||
2226 |
QWidget *QWidget::find(WId id) |
|
2227 |
{ |
|
2228 |
return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : 0; |
|
2229 |
} |
|
2230 |
||
2231 |
||
2232 |
||
2233 |
/*! |
|
2234 |
\fn WId QWidget::internalWinId() const |
|
2235 |
\internal |
|
2236 |
Returns the window system identifier of the widget, or 0 if the widget is not created yet. |
|
2237 |
||
2238 |
*/ |
|
2239 |
||
2240 |
/*! |
|
2241 |
\fn WId QWidget::winId() const |
|
2242 |
||
2243 |
Returns the window system identifier of the widget. |
|
2244 |
||
2245 |
Portable in principle, but if you use it you are probably about to |
|
2246 |
do something non-portable. Be careful. |
|
2247 |
||
2248 |
If a widget is non-native (alien) and winId() is invoked on it, that widget |
|
2249 |
will be provided a native handle. |
|
2250 |
||
2251 |
On Mac OS X, the type returned depends on which framework Qt was linked |
|
2252 |
against. If Qt is using Carbon, the {WId} is actually an HIViewRef. If Qt |
|
2253 |
is using Cocoa, {WId} is a pointer to an NSView. |
|
2254 |
||
2255 |
This value may change at run-time. An event with type QEvent::WinIdChange |
|
2256 |
will be sent to the widget following a change in window system identifier. |
|
2257 |
||
2258 |
\sa find() |
|
2259 |
*/ |
|
2260 |
WId QWidget::winId() const |
|
2261 |
{ |
|
2262 |
if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) { |
|
2263 |
QWidget *that = const_cast<QWidget*>(this); |
|
2264 |
that->setAttribute(Qt::WA_NativeWindow); |
|
2265 |
that->d_func()->createWinId(); |
|
2266 |
return that->data->winid; |
|
2267 |
} |
|
2268 |
return data->winid; |
|
2269 |
} |
|
2270 |
||
2271 |
||
2272 |
void QWidgetPrivate::createWinId(WId winid) |
|
2273 |
{ |
|
2274 |
Q_Q(QWidget); |
|
2275 |
const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow); |
|
2276 |
if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) { |
|
2277 |
if (!q->isWindow()) { |
|
2278 |
QWidget *parent = q->parentWidget(); |
|
2279 |
QWidgetPrivate *pd = parent->d_func(); |
|
2280 |
if (forceNativeWindow && !q->testAttribute(Qt::WA_DontCreateNativeAncestors)) |
|
2281 |
parent->setAttribute(Qt::WA_NativeWindow); |
|
2282 |
if (!parent->internalWinId()) { |
|
2283 |
pd->createWinId(); |
|
2284 |
} |
|
2285 |
||
2286 |
for (int i = 0; i < pd->children.size(); ++i) { |
|
2287 |
QWidget *w = qobject_cast<QWidget *>(pd->children.at(i)); |
|
2288 |
if (w && !w->isWindow() && (!w->testAttribute(Qt::WA_WState_Created) |
|
2289 |
|| (!w->internalWinId() && w->testAttribute(Qt::WA_NativeWindow)))) { |
|
2290 |
if (w!=q) { |
|
2291 |
w->create(); |
|
2292 |
} else { |
|
2293 |
w->create(winid); |
|
2294 |
// if the window has already been created, we |
|
2295 |
// need to raise it to its proper stacking position |
|
2296 |
if (winid) |
|
2297 |
w->raise(); |
|
2298 |
} |
|
2299 |
} |
|
2300 |
} |
|
2301 |
} else { |
|
2302 |
q->create(); |
|
2303 |
} |
|
2304 |
} |
|
2305 |
} |
|
2306 |
||
2307 |
||
2308 |
/*! |
|
2309 |
\internal |
|
2310 |
Ensures that the widget has a window system identifier, i.e. that it is known to the windowing system. |
|
2311 |
||
2312 |
*/ |
|
2313 |
||
2314 |
void QWidget::createWinId() |
|
2315 |
{ |
|
2316 |
Q_D(QWidget); |
|
2317 |
// qWarning("QWidget::createWinId is obsolete, please fix your code."); |
|
2318 |
d->createWinId(); |
|
2319 |
} |
|
2320 |
||
2321 |
/*! |
|
2322 |
\since 4.4 |
|
2323 |
||
2324 |
Returns the effective window system identifier of the widget, i.e. the |
|
2325 |
native parent's window system identifier. |
|
2326 |
||
2327 |
If the widget is native, this function returns the native widget ID. |
|
2328 |
Otherwise, the window ID of the first native parent widget, i.e., the |
|
2329 |
top-level widget that contains this widget, is returned. |
|
2330 |
||
2331 |
\note We recommend that you do not store this value as it is likely to |
|
2332 |
change at run-time. |
|
2333 |
||
2334 |
\sa nativeParentWidget() |
|
2335 |
*/ |
|
2336 |
WId QWidget::effectiveWinId() const |
|
2337 |
{ |
|
2338 |
WId id = internalWinId(); |
|
2339 |
if (id || !testAttribute(Qt::WA_WState_Created)) |
|
2340 |
return id; |
|
2341 |
QWidget *realParent = nativeParentWidget(); |
|
2342 |
Q_ASSERT(realParent); |
|
2343 |
Q_ASSERT(realParent->internalWinId()); |
|
2344 |
return realParent->internalWinId(); |
|
2345 |
} |
|
2346 |
||
2347 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
2348 |
||
2349 |
/*! |
|
2350 |
\property QWidget::styleSheet |
|
2351 |
\brief the widget's style sheet |
|
2352 |
\since 4.2 |
|
2353 |
||
2354 |
The style sheet contains a textual description of customizations to the |
|
2355 |
widget's style, as described in the \l{Qt Style Sheets} document. |
|
2356 |
||
2357 |
Since Qt 4.5, Qt style sheets fully supports Mac OS X. |
|
2358 |
||
2359 |
\warning Qt style sheets are currently not supported for custom QStyle |
|
2360 |
subclasses. We plan to address this in some future release. |
|
2361 |
||
2362 |
\sa setStyle(), QApplication::styleSheet, {Qt Style Sheets} |
|
2363 |
*/ |
|
2364 |
QString QWidget::styleSheet() const |
|
2365 |
{ |
|
2366 |
Q_D(const QWidget); |
|
2367 |
if (!d->extra) |
|
2368 |
return QString(); |
|
2369 |
return d->extra->styleSheet; |
|
2370 |
} |
|
2371 |
||
2372 |
void QWidget::setStyleSheet(const QString& styleSheet) |
|
2373 |
{ |
|
2374 |
Q_D(QWidget); |
|
2375 |
d->createExtra(); |
|
2376 |
||
2377 |
QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(d->extra->style); |
|
2378 |
d->extra->styleSheet = styleSheet; |
|
2379 |
if (styleSheet.isEmpty()) { // stylesheet removed |
|
2380 |
if (!proxy) |
|
2381 |
return; |
|
2382 |
||
2383 |
d->inheritStyle(); |
|
2384 |
return; |
|
2385 |
} |
|
2386 |
||
2387 |
if (proxy) { // style sheet update |
|
2388 |
proxy->repolish(this); |
|
2389 |
return; |
|
2390 |
} |
|
2391 |
||
2392 |
if (testAttribute(Qt::WA_SetStyle)) { |
|
2393 |
d->setStyle_helper(new QStyleSheetStyle(d->extra->style), true); |
|
2394 |
} else { |
|
2395 |
d->setStyle_helper(new QStyleSheetStyle(0), true); |
|
2396 |
} |
|
2397 |
} |
|
2398 |
||
2399 |
#endif // QT_NO_STYLE_STYLESHEET |
|
2400 |
||
2401 |
/*! |
|
2402 |
\sa QWidget::setStyle(), QApplication::setStyle(), QApplication::style() |
|
2403 |
*/ |
|
2404 |
||
2405 |
QStyle *QWidget::style() const |
|
2406 |
{ |
|
2407 |
Q_D(const QWidget); |
|
2408 |
||
2409 |
if (d->extra && d->extra->style) |
|
2410 |
return d->extra->style; |
|
2411 |
return QApplication::style(); |
|
2412 |
} |
|
2413 |
||
2414 |
/*! |
|
2415 |
Sets the widget's GUI style to \a style. The ownership of the style |
|
2416 |
object is not transferred. |
|
2417 |
||
2418 |
If no style is set, the widget uses the application's style, |
|
2419 |
QApplication::style() instead. |
|
2420 |
||
2421 |
Setting a widget's style has no effect on existing or future child |
|
2422 |
widgets. |
|
2423 |
||
2424 |
\warning This function is particularly useful for demonstration |
|
2425 |
purposes, where you want to show Qt's styling capabilities. Real |
|
2426 |
applications should avoid it and use one consistent GUI style |
|
2427 |
instead. |
|
2428 |
||
2429 |
\warning Qt style sheets are currently not supported for custom QStyle |
|
2430 |
subclasses. We plan to address this in some future release. |
|
2431 |
||
2432 |
\sa style(), QStyle, QApplication::style(), QApplication::setStyle() |
|
2433 |
*/ |
|
2434 |
||
2435 |
void QWidget::setStyle(QStyle *style) |
|
2436 |
{ |
|
2437 |
Q_D(QWidget); |
|
2438 |
setAttribute(Qt::WA_SetStyle, style != 0); |
|
2439 |
d->createExtra(); |
|
2440 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
2441 |
if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(style)) { |
|
2442 |
//if for some reason someone try to set a QStyleSheetStyle, ref it |
|
2443 |
//(this may happen for exemple in QButtonDialogBox which propagates its style) |
|
2444 |
proxy->ref(); |
|
2445 |
d->setStyle_helper(style, false); |
|
2446 |
} else if (qobject_cast<QStyleSheetStyle *>(d->extra->style) || !qApp->styleSheet().isEmpty()) { |
|
2447 |
// if we have an application stylesheet or have a proxy already, propagate |
|
2448 |
d->setStyle_helper(new QStyleSheetStyle(style), true); |
|
2449 |
} else |
|
2450 |
#endif |
|
2451 |
d->setStyle_helper(style, false); |
|
2452 |
} |
|
2453 |
||
2454 |
void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate, bool |
|
2455 |
#ifdef Q_WS_MAC |
|
2456 |
metalHack |
|
2457 |
#endif |
|
2458 |
) |
|
2459 |
{ |
|
2460 |
Q_Q(QWidget); |
|
2461 |
QStyle *oldStyle = q->style(); |
|
2462 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
2463 |
QStyle *origStyle = 0; |
|
2464 |
#endif |
|
2465 |
||
2466 |
#ifdef Q_WS_MAC |
|
2467 |
// the metalhack boolean allows Qt/Mac to do a proper re-polish depending |
|
2468 |
// on how the Qt::WA_MacBrushedMetal attribute is set. It is only ever |
|
2469 |
// set when changing that attribute and passes the widget's CURRENT style. |
|
2470 |
// therefore no need to do a reassignment. |
|
2471 |
if (!metalHack) |
|
2472 |
#endif |
|
2473 |
{ |
|
2474 |
createExtra(); |
|
2475 |
||
2476 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
2477 |
origStyle = extra->style; |
|
2478 |
#endif |
|
2479 |
extra->style = newStyle; |
|
2480 |
} |
|
2481 |
||
2482 |
// repolish |
|
2483 |
if (q->windowType() != Qt::Desktop) { |
|
2484 |
if (polished) { |
|
2485 |
oldStyle->unpolish(q); |
|
2486 |
#ifdef Q_WS_MAC |
|
2487 |
if (metalHack) |
|
2488 |
macUpdateMetalAttribute(); |
|
2489 |
#endif |
|
2490 |
q->style()->polish(q); |
|
2491 |
#ifdef Q_WS_MAC |
|
2492 |
} else if (metalHack) { |
|
2493 |
macUpdateMetalAttribute(); |
|
2494 |
#endif |
|
2495 |
} |
|
2496 |
} |
|
2497 |
||
2498 |
if (propagate) { |
|
2499 |
for (int i = 0; i < children.size(); ++i) { |
|
2500 |
QWidget *c = qobject_cast<QWidget*>(children.at(i)); |
|
2501 |
if (c) |
|
2502 |
c->d_func()->inheritStyle(); |
|
2503 |
} |
|
2504 |
} |
|
2505 |
||
2506 |
QEvent e(QEvent::StyleChange); |
|
2507 |
QApplication::sendEvent(q, &e); |
|
2508 |
#ifdef QT3_SUPPORT |
|
2509 |
q->styleChange(*oldStyle); |
|
2510 |
#endif |
|
2511 |
||
2512 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
2513 |
if (!qobject_cast<QStyleSheetStyle*>(newStyle)) { |
|
2514 |
if (const QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(origStyle)) { |
|
2515 |
cssStyle->clearWidgetFont(q); |
|
2516 |
} |
|
2517 |
} |
|
2518 |
#endif |
|
2519 |
||
2520 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
2521 |
// dereference the old stylesheet style |
|
2522 |
if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(origStyle)) |
|
2523 |
proxy->deref(); |
|
2524 |
#endif |
|
2525 |
} |
|
2526 |
||
2527 |
// Inherits style from the current parent and propagates it as necessary |
|
2528 |
void QWidgetPrivate::inheritStyle() |
|
2529 |
{ |
|
2530 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
2531 |
Q_Q(QWidget); |
|
2532 |
||
2533 |
QStyleSheetStyle *proxy = extra ? qobject_cast<QStyleSheetStyle *>(extra->style) : 0; |
|
2534 |
||
2535 |
if (!q->styleSheet().isEmpty()) { |
|
2536 |
Q_ASSERT(proxy); |
|
2537 |
proxy->repolish(q); |
|
2538 |
return; |
|
2539 |
} |
|
2540 |
||
2541 |
QStyle *origStyle = proxy ? proxy->base : (extra ? (QStyle*)extra->style : 0); |
|
2542 |
QWidget *parent = q->parentWidget(); |
|
2543 |
QStyle *parentStyle = (parent && parent->d_func()->extra) ? (QStyle*)parent->d_func()->extra->style : 0; |
|
2544 |
// If we have stylesheet on app or parent has stylesheet style, we need |
|
2545 |
// to be running a proxy |
|
2546 |
if (!qApp->styleSheet().isEmpty() || qobject_cast<QStyleSheetStyle *>(parentStyle)) { |
|
2547 |
QStyle *newStyle = parentStyle; |
|
2548 |
if (q->testAttribute(Qt::WA_SetStyle)) |
|
2549 |
newStyle = new QStyleSheetStyle(origStyle); |
|
2550 |
else if (QStyleSheetStyle *newProxy = qobject_cast<QStyleSheetStyle *>(parentStyle)) |
|
2551 |
newProxy->ref(); |
|
2552 |
||
2553 |
setStyle_helper(newStyle, true); |
|
2554 |
return; |
|
2555 |
} |
|
2556 |
||
2557 |
// So, we have no stylesheet on parent/app and we have an empty stylesheet |
|
2558 |
// we just need our original style back |
|
2559 |
if (origStyle == (extra ? (QStyle*)extra->style : 0)) // is it any different? |
|
2560 |
return; |
|
2561 |
||
2562 |
// We could have inherited the proxy from our parent (which has a custom style) |
|
2563 |
// In such a case we need to start following the application style (i.e revert |
|
2564 |
// the propagation behavior of QStyleSheetStyle) |
|
2565 |
if (!q->testAttribute(Qt::WA_SetStyle)) |
|
2566 |
origStyle = 0; |
|
2567 |
||
2568 |
setStyle_helper(origStyle, true); |
|
2569 |
#endif // QT_NO_STYLE_STYLESHEET |
|
2570 |
} |
|
2571 |
||
2572 |
#ifdef QT3_SUPPORT |
|
2573 |
/*! |
|
2574 |
\overload |
|
2575 |
||
2576 |
Sets the widget's GUI style to \a style using the QStyleFactory. |
|
2577 |
*/ |
|
2578 |
QStyle* QWidget::setStyle(const QString &style) |
|
2579 |
{ |
|
2580 |
QStyle *s = QStyleFactory::create(style); |
|
2581 |
setStyle(s); |
|
2582 |
return s; |
|
2583 |
} |
|
2584 |
#endif |
|
2585 |
||
2586 |
/*! |
|
2587 |
\fn bool QWidget::isWindow() const |
|
2588 |
||
2589 |
Returns true if the widget is an independent window, otherwise |
|
2590 |
returns false. |
|
2591 |
||
2592 |
A window is a widget that isn't visually the child of any other |
|
2593 |
widget and that usually has a frame and a |
|
2594 |
\l{QWidget::setWindowTitle()}{window title}. |
|
2595 |
||
2596 |
A window can have a \l{QWidget::parentWidget()}{parent widget}. |
|
2597 |
It will then be grouped with its parent and deleted when the |
|
2598 |
parent is deleted, minimized when the parent is minimized etc. If |
|
2599 |
supported by the window manager, it will also have a common |
|
2600 |
taskbar entry with its parent. |
|
2601 |
||
2602 |
QDialog and QMainWindow widgets are by default windows, even if a |
|
2603 |
parent widget is specified in the constructor. This behavior is |
|
2604 |
specified by the Qt::Window flag. |
|
2605 |
||
2606 |
\sa window(), isModal(), parentWidget() |
|
2607 |
*/ |
|
2608 |
||
2609 |
/*! |
|
2610 |
\property QWidget::modal |
|
2611 |
\brief whether the widget is a modal widget |
|
2612 |
||
2613 |
This property only makes sense for windows. A modal widget |
|
2614 |
prevents widgets in all other windows from getting any input. |
|
2615 |
||
2616 |
By default, this property is false. |
|
2617 |
||
2618 |
\sa isWindow(), windowModality, QDialog |
|
2619 |
*/ |
|
2620 |
||
2621 |
/*! |
|
2622 |
\property QWidget::windowModality |
|
2623 |
\brief which windows are blocked by the modal widget |
|
2624 |
\since 4.1 |
|
2625 |
||
2626 |
This property only makes sense for windows. A modal widget |
|
2627 |
prevents widgets in other windows from getting input. The value of |
|
2628 |
this property controls which windows are blocked when the widget |
|
2629 |
is visible. Changing this property while the window is visible has |
|
2630 |
no effect; you must hide() the widget first, then show() it again. |
|
2631 |
||
2632 |
By default, this property is Qt::NonModal. |
|
2633 |
||
2634 |
\sa isWindow(), QWidget::modal, QDialog |
|
2635 |
*/ |
|
2636 |
||
2637 |
Qt::WindowModality QWidget::windowModality() const |
|
2638 |
{ |
|
2639 |
return static_cast<Qt::WindowModality>(data->window_modality); |
|
2640 |
} |
|
2641 |
||
2642 |
void QWidget::setWindowModality(Qt::WindowModality windowModality) |
|
2643 |
{ |
|
2644 |
data->window_modality = windowModality; |
|
2645 |
// setModal_sys() will be called by setAttribute() |
|
2646 |
setAttribute(Qt::WA_ShowModal, (data->window_modality != Qt::NonModal)); |
|
2647 |
setAttribute(Qt::WA_SetWindowModality, true); |
|
2648 |
} |
|
2649 |
||
2650 |
/*! |
|
2651 |
\fn bool QWidget::underMouse() const |
|
2652 |
||
2653 |
Returns true if the widget is under the mouse cursor; otherwise |
|
2654 |
returns false. |
|
2655 |
||
2656 |
This value is not updated properly during drag and drop |
|
2657 |
operations. |
|
2658 |
||
2659 |
\sa enterEvent(), leaveEvent() |
|
2660 |
*/ |
|
2661 |
||
2662 |
/*! |
|
2663 |
\property QWidget::minimized |
|
2664 |
\brief whether this widget is minimized (iconified) |
|
2665 |
||
2666 |
This property is only relevant for windows. |
|
2667 |
||
2668 |
By default, this property is false. |
|
2669 |
||
2670 |
\sa showMinimized(), visible, show(), hide(), showNormal(), maximized |
|
2671 |
*/ |
|
2672 |
bool QWidget::isMinimized() const |
|
2673 |
{ return data->window_state & Qt::WindowMinimized; } |
|
2674 |
||
2675 |
/*! |
|
2676 |
Shows the widget minimized, as an icon. |
|
2677 |
||
2678 |
Calling this function only affects \l{isWindow()}{windows}. |
|
2679 |
||
2680 |
\sa showNormal(), showMaximized(), show(), hide(), isVisible(), |
|
2681 |
isMinimized() |
|
2682 |
*/ |
|
2683 |
void QWidget::showMinimized() |
|
2684 |
{ |
|
2685 |
bool isMin = isMinimized(); |
|
2686 |
if (isMin && isVisible()) |
|
2687 |
return; |
|
2688 |
||
2689 |
ensurePolished(); |
|
2690 |
#ifdef QT3_SUPPORT |
|
2691 |
if (parent()) |
|
2692 |
QApplication::sendPostedEvents(parent(), QEvent::ChildInserted); |
|
2693 |
#endif |
|
2694 |
||
2695 |
if (!isMin) |
|
2696 |
setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized); |
|
2697 |
show(); |
|
2698 |
} |
|
2699 |
||
2700 |
/*! |
|
2701 |
\property QWidget::maximized |
|
2702 |
\brief whether this widget is maximized |
|
2703 |
||
2704 |
This property is only relevant for windows. |
|
2705 |
||
2706 |
\note Due to limitations on some window systems, this does not always |
|
2707 |
report the expected results (e.g., if the user on X11 maximizes the |
|
2708 |
window via the window manager, Qt has no way of distinguishing this |
|
2709 |
from any other resize). This is expected to improve as window manager |
|
2710 |
protocols evolve. |
|
2711 |
||
2712 |
By default, this property is false. |
|
2713 |
||
2714 |
\sa windowState(), showMaximized(), visible, show(), hide(), showNormal(), minimized |
|
2715 |
*/ |
|
2716 |
bool QWidget::isMaximized() const |
|
2717 |
{ return data->window_state & Qt::WindowMaximized; } |
|
2718 |
||
2719 |
||
2720 |
||
2721 |
/*! |
|
2722 |
Returns the current window state. The window state is a OR'ed |
|
2723 |
combination of Qt::WindowState: Qt::WindowMinimized, |
|
2724 |
Qt::WindowMaximized, Qt::WindowFullScreen, and Qt::WindowActive. |
|
2725 |
||
2726 |
\sa Qt::WindowState setWindowState() |
|
2727 |
*/ |
|
2728 |
Qt::WindowStates QWidget::windowState() const |
|
2729 |
{ |
|
2730 |
return Qt::WindowStates(data->window_state); |
|
2731 |
} |
|
2732 |
||
2733 |
/*!\internal |
|
2734 |
||
2735 |
The function sets the window state on child widgets similar to |
|
2736 |
setWindowState(). The difference is that the window state changed |
|
2737 |
event has the isOverride() flag set. It exists mainly to keep |
|
2738 |
Q3Workspace working. |
|
2739 |
*/ |
|
2740 |
void QWidget::overrideWindowState(Qt::WindowStates newstate) |
|
2741 |
{ |
|
2742 |
QWindowStateChangeEvent e(Qt::WindowStates(data->window_state), true); |
|
2743 |
data->window_state = newstate; |
|
2744 |
QApplication::sendEvent(this, &e); |
|
2745 |
} |
|
2746 |
||
2747 |
/*! |
|
2748 |
\fn void QWidget::setWindowState(Qt::WindowStates windowState) |
|
2749 |
||
2750 |
Sets the window state to \a windowState. The window state is a OR'ed |
|
2751 |
combination of Qt::WindowState: Qt::WindowMinimized, |
|
2752 |
Qt::WindowMaximized, Qt::WindowFullScreen, and Qt::WindowActive. |
|
2753 |
||
2754 |
If the window is not visible (i.e. isVisible() returns false), the |
|
2755 |
window state will take effect when show() is called. For visible |
|
2756 |
windows, the change is immediate. For example, to toggle between |
|
2757 |
full-screen and normal mode, use the following code: |
|
2758 |
||
2759 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 0 |
|
2760 |
||
2761 |
In order to restore and activate a minimized window (while |
|
2762 |
preserving its maximized and/or full-screen state), use the following: |
|
2763 |
||
2764 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 1 |
|
2765 |
||
2766 |
Calling this function will hide the widget. You must call show() to make |
|
2767 |
the widget visible again. |
|
2768 |
||
2769 |
\note On some window systems Qt::WindowActive is not immediate, and may be |
|
2770 |
ignored in certain cases. |
|
2771 |
||
2772 |
When the window state changes, the widget receives a changeEvent() |
|
2773 |
of type QEvent::WindowStateChange. |
|
2774 |
||
2775 |
\sa Qt::WindowState windowState() |
|
2776 |
*/ |
|
2777 |
||
2778 |
/*! |
|
2779 |
\property QWidget::fullScreen |
|
2780 |
\brief whether the widget is shown in full screen mode |
|
2781 |
||
2782 |
A widget in full screen mode occupies the whole screen area and does not |
|
2783 |
display window decorations, such as a title bar. |
|
2784 |
||
2785 |
By default, this property is false. |
|
2786 |
||
2787 |
\sa windowState(), minimized, maximized |
|
2788 |
*/ |
|
2789 |
bool QWidget::isFullScreen() const |
|
2790 |
{ return data->window_state & Qt::WindowFullScreen; } |
|
2791 |
||
2792 |
/*! |
|
2793 |
Shows the widget in full-screen mode. |
|
2794 |
||
2795 |
Calling this function only affects \l{isWindow()}{windows}. |
|
2796 |
||
2797 |
To return from full-screen mode, call showNormal(). |
|
2798 |
||
2799 |
Full-screen mode works fine under Windows, but has certain |
|
2800 |
problems under X. These problems are due to limitations of the |
|
2801 |
ICCCM protocol that specifies the communication between X11 |
|
2802 |
clients and the window manager. ICCCM simply does not understand |
|
2803 |
the concept of non-decorated full-screen windows. Therefore, the |
|
2804 |
best we can do is to request a borderless window and place and |
|
2805 |
resize it to fill the entire screen. Depending on the window |
|
2806 |
manager, this may or may not work. The borderless window is |
|
2807 |
requested using MOTIF hints, which are at least partially |
|
2808 |
supported by virtually all modern window managers. |
|
2809 |
||
2810 |
An alternative would be to bypass the window manager entirely and |
|
2811 |
create a window with the Qt::X11BypassWindowManagerHint flag. This |
|
2812 |
has other severe problems though, like totally broken keyboard focus |
|
2813 |
and very strange effects on desktop changes or when the user raises |
|
2814 |
other windows. |
|
2815 |
||
2816 |
X11 window managers that follow modern post-ICCCM specifications |
|
2817 |
support full-screen mode properly. |
|
2818 |
||
2819 |
\sa showNormal(), showMaximized(), show(), hide(), isVisible() |
|
2820 |
*/ |
|
2821 |
void QWidget::showFullScreen() |
|
2822 |
{ |
|
2823 |
ensurePolished(); |
|
2824 |
#ifdef QT3_SUPPORT |
|
2825 |
if (parent()) |
|
2826 |
QApplication::sendPostedEvents(parent(), QEvent::ChildInserted); |
|
2827 |
#endif |
|
2828 |
||
2829 |
setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowMaximized)) |
|
2830 |
| Qt::WindowFullScreen); |
|
2831 |
show(); |
|
2832 |
activateWindow(); |
|
2833 |
} |
|
2834 |
||
2835 |
/*! |
|
2836 |
Shows the widget maximized. |
|
2837 |
||
2838 |
Calling this function only affects \l{isWindow()}{windows}. |
|
2839 |
||
2840 |
On X11, this function may not work properly with certain window |
|
2841 |
managers. See the \l{Window Geometry} documentation for an explanation. |
|
2842 |
||
2843 |
\sa setWindowState(), showNormal(), showMinimized(), show(), hide(), isVisible() |
|
2844 |
*/ |
|
2845 |
void QWidget::showMaximized() |
|
2846 |
{ |
|
2847 |
ensurePolished(); |
|
2848 |
#ifdef QT3_SUPPORT |
|
2849 |
if (parent()) |
|
2850 |
QApplication::sendPostedEvents(parent(), QEvent::ChildInserted); |
|
2851 |
#endif |
|
2852 |
||
2853 |
setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowFullScreen)) |
|
2854 |
| Qt::WindowMaximized); |
|
2855 |
show(); |
|
2856 |
} |
|
2857 |
||
2858 |
/*! |
|
2859 |
Restores the widget after it has been maximized or minimized. |
|
2860 |
||
2861 |
Calling this function only affects \l{isWindow()}{windows}. |
|
2862 |
||
2863 |
\sa setWindowState(), showMinimized(), showMaximized(), show(), hide(), isVisible() |
|
2864 |
*/ |
|
2865 |
void QWidget::showNormal() |
|
2866 |
{ |
|
2867 |
ensurePolished(); |
|
2868 |
#ifdef QT3_SUPPORT |
|
2869 |
if (parent()) |
|
2870 |
QApplication::sendPostedEvents(parent(), QEvent::ChildInserted); |
|
2871 |
#endif |
|
2872 |
||
2873 |
setWindowState(windowState() & ~(Qt::WindowMinimized |
|
2874 |
| Qt::WindowMaximized |
|
2875 |
| Qt::WindowFullScreen)); |
|
2876 |
show(); |
|
2877 |
} |
|
2878 |
||
2879 |
/*! |
|
2880 |
Returns true if this widget would become enabled if \a ancestor is |
|
2881 |
enabled; otherwise returns false. |
|
2882 |
||
2883 |
||
2884 |
||
2885 |
This is the case if neither the widget itself nor every parent up |
|
2886 |
to but excluding \a ancestor has been explicitly disabled. |
|
2887 |
||
2888 |
isEnabledTo(0) is equivalent to isEnabled(). |
|
2889 |
||
2890 |
\sa setEnabled() enabled |
|
2891 |
*/ |
|
2892 |
||
2893 |
bool QWidget::isEnabledTo(QWidget* ancestor) const |
|
2894 |
{ |
|
2895 |
const QWidget * w = this; |
|
2896 |
while (!w->testAttribute(Qt::WA_ForceDisabled) |
|
2897 |
&& !w->isWindow() |
|
2898 |
&& w->parentWidget() |
|
2899 |
&& w->parentWidget() != ancestor) |
|
2900 |
w = w->parentWidget(); |
|
2901 |
return !w->testAttribute(Qt::WA_ForceDisabled); |
|
2902 |
} |
|
2903 |
||
2904 |
#ifndef QT_NO_ACTION |
|
2905 |
/*! |
|
2906 |
Appends the action \a action to this widget's list of actions. |
|
2907 |
||
2908 |
All QWidgets have a list of \l{QAction}s, however they can be |
|
2909 |
represented graphically in many different ways. The default use of |
|
2910 |
the QAction list (as returned by actions()) is to create a context |
|
2911 |
QMenu. |
|
2912 |
||
2913 |
A QWidget should only have one of each action and adding an action |
|
2914 |
it already has will not cause the same action to be in the widget twice. |
|
2915 |
||
2916 |
The ownership of \a action is not transferred to this QWidget. |
|
2917 |
||
2918 |
\sa removeAction(), insertAction(), actions(), QMenu |
|
2919 |
*/ |
|
2920 |
void QWidget::addAction(QAction *action) |
|
2921 |
{ |
|
2922 |
insertAction(0, action); |
|
2923 |
} |
|
2924 |
||
2925 |
/*! |
|
2926 |
Appends the actions \a actions to this widget's list of actions. |
|
2927 |
||
2928 |
\sa removeAction(), QMenu, addAction() |
|
2929 |
*/ |
|
2930 |
void QWidget::addActions(QList<QAction*> actions) |
|
2931 |
{ |
|
2932 |
for(int i = 0; i < actions.count(); i++) |
|
2933 |
insertAction(0, actions.at(i)); |
|
2934 |
} |
|
2935 |
||
2936 |
/*! |
|
2937 |
Inserts the action \a action to this widget's list of actions, |
|
2938 |
before the action \a before. It appends the action if \a before is 0 or |
|
2939 |
\a before is not a valid action for this widget. |
|
2940 |
||
2941 |
A QWidget should only have one of each action. |
|
2942 |
||
2943 |
\sa removeAction(), addAction(), QMenu, contextMenuPolicy, actions() |
|
2944 |
*/ |
|
2945 |
void QWidget::insertAction(QAction *before, QAction *action) |
|
2946 |
{ |
|
2947 |
if(!action) { |
|
2948 |
qWarning("QWidget::insertAction: Attempt to insert null action"); |
|
2949 |
return; |
|
2950 |
} |
|
2951 |
||
2952 |
Q_D(QWidget); |
|
2953 |
if(d->actions.contains(action)) |
|
2954 |
removeAction(action); |
|
2955 |
||
2956 |
int pos = d->actions.indexOf(before); |
|
2957 |
if (pos < 0) { |
|
2958 |
before = 0; |
|
2959 |
pos = d->actions.size(); |
|
2960 |
} |
|
2961 |
d->actions.insert(pos, action); |
|
2962 |
||
2963 |
QActionPrivate *apriv = action->d_func(); |
|
2964 |
apriv->widgets.append(this); |
|
2965 |
||
2966 |
QActionEvent e(QEvent::ActionAdded, action, before); |
|
2967 |
QApplication::sendEvent(this, &e); |
|
2968 |
} |
|
2969 |
||
2970 |
/*! |
|
2971 |
Inserts the actions \a actions to this widget's list of actions, |
|
2972 |
before the action \a before. It appends the action if \a before is 0 or |
|
2973 |
\a before is not a valid action for this widget. |
|
2974 |
||
2975 |
A QWidget can have at most one of each action. |
|
2976 |
||
2977 |
\sa removeAction(), QMenu, insertAction(), contextMenuPolicy |
|
2978 |
*/ |
|
2979 |
void QWidget::insertActions(QAction *before, QList<QAction*> actions) |
|
2980 |
{ |
|
2981 |
for(int i = 0; i < actions.count(); ++i) |
|
2982 |
insertAction(before, actions.at(i)); |
|
2983 |
} |
|
2984 |
||
2985 |
/*! |
|
2986 |
Removes the action \a action from this widget's list of actions. |
|
2987 |
\sa insertAction(), actions(), insertAction() |
|
2988 |
*/ |
|
2989 |
void QWidget::removeAction(QAction *action) |
|
2990 |
{ |
|
2991 |
if (!action) |
|
2992 |
return; |
|
2993 |
||
2994 |
Q_D(QWidget); |
|
2995 |
||
2996 |
QActionPrivate *apriv = action->d_func(); |
|
2997 |
apriv->widgets.removeAll(this); |
|
2998 |
||
2999 |
if (d->actions.removeAll(action)) { |
|
3000 |
QActionEvent e(QEvent::ActionRemoved, action); |
|
3001 |
QApplication::sendEvent(this, &e); |
|
3002 |
} |
|
3003 |
} |
|
3004 |
||
3005 |
/*! |
|
3006 |
Returns the (possibly empty) list of this widget's actions. |
|
3007 |
||
3008 |
\sa contextMenuPolicy, insertAction(), removeAction() |
|
3009 |
*/ |
|
3010 |
QList<QAction*> QWidget::actions() const |
|
3011 |
{ |
|
3012 |
Q_D(const QWidget); |
|
3013 |
return d->actions; |
|
3014 |
} |
|
3015 |
#endif // QT_NO_ACTION |
|
3016 |
||
3017 |
/*! |
|
3018 |
\fn bool QWidget::isEnabledToTLW() const |
|
3019 |
\obsolete |
|
3020 |
||
3021 |
This function is deprecated. It is equivalent to isEnabled() |
|
3022 |
*/ |
|
3023 |
||
3024 |
/*! |
|
3025 |
\property QWidget::enabled |
|
3026 |
\brief whether the widget is enabled |
|
3027 |
||
3028 |
An enabled widget handles keyboard and mouse events; a disabled |
|
3029 |
widget does not. |
|
3030 |
||
3031 |
Some widgets display themselves differently when they are |
|
3032 |
disabled. For example a button might draw its label grayed out. If |
|
3033 |
your widget needs to know when it becomes enabled or disabled, you |
|
3034 |
can use the changeEvent() with type QEvent::EnabledChange. |
|
3035 |
||
3036 |
Disabling a widget implicitly disables all its children. Enabling |
|
3037 |
respectively enables all child widgets unless they have been |
|
3038 |
explicitly disabled. |
|
3039 |
||
3040 |
By default, this property is true. |
|
3041 |
||
3042 |
\sa isEnabledTo(), QKeyEvent, QMouseEvent, changeEvent() |
|
3043 |
*/ |
|
3044 |
void QWidget::setEnabled(bool enable) |
|
3045 |
{ |
|
3046 |
Q_D(QWidget); |
|
3047 |
setAttribute(Qt::WA_ForceDisabled, !enable); |
|
3048 |
d->setEnabled_helper(enable); |
|
3049 |
} |
|
3050 |
||
3051 |
void QWidgetPrivate::setEnabled_helper(bool enable) |
|
3052 |
{ |
|
3053 |
Q_Q(QWidget); |
|
3054 |
||
3055 |
if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->isEnabled()) |
|
3056 |
return; // nothing we can do |
|
3057 |
||
3058 |
if (enable != q->testAttribute(Qt::WA_Disabled)) |
|
3059 |
return; // nothing to do |
|
3060 |
||
3061 |
q->setAttribute(Qt::WA_Disabled, !enable); |
|
3062 |
updateSystemBackground(); |
|
3063 |
||
3064 |
if (!enable && q->window()->focusWidget() == q) { |
|
3065 |
bool parentIsEnabled = (!q->parentWidget() || q->parentWidget()->isEnabled()); |
|
3066 |
if (!parentIsEnabled || !q->focusNextChild()) |
|
3067 |
q->clearFocus(); |
|
3068 |
} |
|
3069 |
||
3070 |
Qt::WidgetAttribute attribute = enable ? Qt::WA_ForceDisabled : Qt::WA_Disabled; |
|
3071 |
for (int i = 0; i < children.size(); ++i) { |
|
3072 |
QWidget *w = qobject_cast<QWidget *>(children.at(i)); |
|
3073 |
if (w && !w->testAttribute(attribute)) |
|
3074 |
w->d_func()->setEnabled_helper(enable); |
|
3075 |
} |
|
3076 |
#if defined(Q_WS_X11) |
|
3077 |
if (q->testAttribute(Qt::WA_SetCursor) || q->isWindow()) { |
|
3078 |
// enforce the windows behavior of clearing the cursor on |
|
3079 |
// disabled widgets |
|
3080 |
qt_x11_enforce_cursor(q); |
|
3081 |
} |
|
3082 |
#endif |
|
3083 |
#if defined(Q_WS_MAC) |
|
3084 |
setEnabled_helper_sys(enable); |
|
3085 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3086 |
#ifndef QT_NO_IM |
0 | 3087 |
if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3088 |
QWidget *focusWidget = effectiveFocusWidget(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3089 |
QInputContext *qic = focusWidget->d_func()->inputContext(); |
0 | 3090 |
if (enable) { |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3091 |
if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3092 |
qic->setFocusWidget(focusWidget); |
0 | 3093 |
} else { |
3094 |
qic->reset(); |
|
3095 |
qic->setFocusWidget(0); |
|
3096 |
} |
|
3097 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3098 |
#endif //QT_NO_IM |
0 | 3099 |
QEvent e(QEvent::EnabledChange); |
3100 |
QApplication::sendEvent(q, &e); |
|
3101 |
#ifdef QT3_SUPPORT |
|
3102 |
q->enabledChange(!enable); // compatibility |
|
3103 |
#endif |
|
3104 |
} |
|
3105 |
||
3106 |
/*! |
|
3107 |
\property QWidget::acceptDrops |
|
3108 |
\brief whether drop events are enabled for this widget |
|
3109 |
||
3110 |
Setting this property to true announces to the system that this |
|
3111 |
widget \e may be able to accept drop events. |
|
3112 |
||
3113 |
If the widget is the desktop (windowType() == Qt::Desktop), this may |
|
3114 |
fail if another application is using the desktop; you can call |
|
3115 |
acceptDrops() to test if this occurs. |
|
3116 |
||
3117 |
\warning Do not modify this property in a drag and drop event handler. |
|
3118 |
||
3119 |
By default, this property is false. |
|
3120 |
||
3121 |
\sa {Drag and Drop} |
|
3122 |
*/ |
|
3123 |
bool QWidget::acceptDrops() const |
|
3124 |
{ |
|
3125 |
return testAttribute(Qt::WA_AcceptDrops); |
|
3126 |
} |
|
3127 |
||
3128 |
void QWidget::setAcceptDrops(bool on) |
|
3129 |
{ |
|
3130 |
setAttribute(Qt::WA_AcceptDrops, on); |
|
3131 |
||
3132 |
} |
|
3133 |
||
3134 |
/*! |
|
3135 |
\fn void QWidget::enabledChange(bool) |
|
3136 |
||
3137 |
\internal |
|
3138 |
\obsolete |
|
3139 |
*/ |
|
3140 |
||
3141 |
/*! |
|
3142 |
\fn void QWidget::paletteChange(const QPalette &) |
|
3143 |
||
3144 |
\internal |
|
3145 |
\obsolete |
|
3146 |
*/ |
|
3147 |
||
3148 |
/*! |
|
3149 |
\fn void QWidget::fontChange(const QFont &) |
|
3150 |
||
3151 |
\internal |
|
3152 |
\obsolete |
|
3153 |
*/ |
|
3154 |
||
3155 |
/*! |
|
3156 |
\fn void QWidget::windowActivationChange(bool) |
|
3157 |
||
3158 |
\internal |
|
3159 |
\obsolete |
|
3160 |
*/ |
|
3161 |
||
3162 |
/*! |
|
3163 |
\fn void QWidget::languageChange() |
|
3164 |
||
3165 |
\obsolete |
|
3166 |
*/ |
|
3167 |
||
3168 |
/*! |
|
3169 |
\fn void QWidget::styleChange(QStyle& style) |
|
3170 |
||
3171 |
\internal |
|
3172 |
\obsolete |
|
3173 |
*/ |
|
3174 |
||
3175 |
/*! |
|
3176 |
Disables widget input events if \a disable is true; otherwise |
|
3177 |
enables input events. |
|
3178 |
||
3179 |
See the \l enabled documentation for more information. |
|
3180 |
||
3181 |
\sa isEnabledTo(), QKeyEvent, QMouseEvent, changeEvent() |
|
3182 |
*/ |
|
3183 |
void QWidget::setDisabled(bool disable) |
|
3184 |
{ |
|
3185 |
setEnabled(!disable); |
|
3186 |
} |
|
3187 |
||
3188 |
/*! |
|
3189 |
\property QWidget::frameGeometry |
|
3190 |
\brief geometry of the widget relative to its parent including any |
|
3191 |
window frame |
|
3192 |
||
3193 |
See the \l{Window Geometry} documentation for an overview of geometry |
|
3194 |
issues with windows. |
|
3195 |
||
3196 |
By default, this property contains a value that depends on the user's |
|
3197 |
platform and screen geometry. |
|
3198 |
||
3199 |
\sa geometry() x() y() pos() |
|
3200 |
*/ |
|
3201 |
QRect QWidget::frameGeometry() const |
|
3202 |
{ |
|
3203 |
Q_D(const QWidget); |
|
3204 |
if (isWindow() && ! (windowType() == Qt::Popup)) { |
|
3205 |
QRect fs = d->frameStrut(); |
|
3206 |
return QRect(data->crect.x() - fs.left(), |
|
3207 |
data->crect.y() - fs.top(), |
|
3208 |
data->crect.width() + fs.left() + fs.right(), |
|
3209 |
data->crect.height() + fs.top() + fs.bottom()); |
|
3210 |
} |
|
3211 |
return data->crect; |
|
3212 |
} |
|
3213 |
||
3214 |
/*! |
|
3215 |
\property QWidget::x |
|
3216 |
||
3217 |
\brief the x coordinate of the widget relative to its parent including |
|
3218 |
any window frame |
|
3219 |
||
3220 |
See the \l{Window Geometry} documentation for an overview of geometry |
|
3221 |
issues with windows. |
|
3222 |
||
3223 |
By default, this property has a value of 0. |
|
3224 |
||
3225 |
\sa frameGeometry, y, pos |
|
3226 |
*/ |
|
3227 |
int QWidget::x() const |
|
3228 |
{ |
|
3229 |
Q_D(const QWidget); |
|
3230 |
if (isWindow() && ! (windowType() == Qt::Popup)) |
|
3231 |
return data->crect.x() - d->frameStrut().left(); |
|
3232 |
return data->crect.x(); |
|
3233 |
} |
|
3234 |
||
3235 |
/*! |
|
3236 |
\property QWidget::y |
|
3237 |
\brief the y coordinate of the widget relative to its parent and |
|
3238 |
including any window frame |
|
3239 |
||
3240 |
See the \l{Window Geometry} documentation for an overview of geometry |
|
3241 |
issues with windows. |
|
3242 |
||
3243 |
By default, this property has a value of 0. |
|
3244 |
||
3245 |
\sa frameGeometry, x, pos |
|
3246 |
*/ |
|
3247 |
int QWidget::y() const |
|
3248 |
{ |
|
3249 |
Q_D(const QWidget); |
|
3250 |
if (isWindow() && ! (windowType() == Qt::Popup)) |
|
3251 |
return data->crect.y() - d->frameStrut().top(); |
|
3252 |
return data->crect.y(); |
|
3253 |
} |
|
3254 |
||
3255 |
/*! |
|
3256 |
\property QWidget::pos |
|
3257 |
\brief the position of the widget within its parent widget |
|
3258 |
||
3259 |
If the widget is a window, the position is that of the widget on |
|
3260 |
the desktop, including its frame. |
|
3261 |
||
3262 |
When changing the position, the widget, if visible, receives a |
|
3263 |
move event (moveEvent()) immediately. If the widget is not |
|
3264 |
currently visible, it is guaranteed to receive an event before it |
|
3265 |
is shown. |
|
3266 |
||
3267 |
By default, this property contains a position that refers to the |
|
3268 |
origin. |
|
3269 |
||
3270 |
\warning Calling move() or setGeometry() inside moveEvent() can |
|
3271 |
lead to infinite recursion. |
|
3272 |
||
3273 |
See the \l{Window Geometry} documentation for an overview of geometry |
|
3274 |
issues with windows. |
|
3275 |
||
3276 |
\sa frameGeometry, size x(), y() |
|
3277 |
*/ |
|
3278 |
QPoint QWidget::pos() const |
|
3279 |
{ |
|
3280 |
Q_D(const QWidget); |
|
3281 |
if (isWindow() && ! (windowType() == Qt::Popup)) { |
|
3282 |
QRect fs = d->frameStrut(); |
|
3283 |
return QPoint(data->crect.x() - fs.left(), data->crect.y() - fs.top()); |
|
3284 |
} |
|
3285 |
return data->crect.topLeft(); |
|
3286 |
} |
|
3287 |
||
3288 |
/*! |
|
3289 |
\property QWidget::geometry |
|
3290 |
\brief the geometry of the widget relative to its parent and |
|
3291 |
excluding the window frame |
|
3292 |
||
3293 |
When changing the geometry, the widget, if visible, receives a |
|
3294 |
move event (moveEvent()) and/or a resize event (resizeEvent()) |
|
3295 |
immediately. If the widget is not currently visible, it is |
|
3296 |
guaranteed to receive appropriate events before it is shown. |
|
3297 |
||
3298 |
The size component is adjusted if it lies outside the range |
|
3299 |
defined by minimumSize() and maximumSize(). |
|
3300 |
||
3301 |
\warning Calling setGeometry() inside resizeEvent() or moveEvent() |
|
3302 |
can lead to infinite recursion. |
|
3303 |
||
3304 |
See the \l{Window Geometry} documentation for an overview of geometry |
|
3305 |
issues with windows. |
|
3306 |
||
3307 |
By default, this property contains a value that depends on the user's |
|
3308 |
platform and screen geometry. |
|
3309 |
||
3310 |
\sa frameGeometry(), rect(), move(), resize(), moveEvent(), |
|
3311 |
resizeEvent(), minimumSize(), maximumSize() |
|
3312 |
*/ |
|
3313 |
||
3314 |
/*! |
|
3315 |
\property QWidget::normalGeometry |
|
3316 |
||
3317 |
\brief the geometry of the widget as it will appear when shown as |
|
3318 |
a normal (not maximized or full screen) top-level widget |
|
3319 |
||
3320 |
For child widgets this property always holds an empty rectangle. |
|
3321 |
||
3322 |
By default, this property contains an empty rectangle. |
|
3323 |
||
3324 |
\sa QWidget::windowState(), QWidget::geometry |
|
3325 |
*/ |
|
3326 |
||
3327 |
/*! |
|
3328 |
\property QWidget::size |
|
3329 |
\brief the size of the widget excluding any window frame |
|
3330 |
||
3331 |
If the widget is visible when it is being resized, it receives a resize event |
|
3332 |
(resizeEvent()) immediately. If the widget is not currently |
|
3333 |
visible, it is guaranteed to receive an event before it is shown. |
|
3334 |
||
3335 |
The size is adjusted if it lies outside the range defined by |
|
3336 |
minimumSize() and maximumSize(). |
|
3337 |
||
3338 |
By default, this property contains a value that depends on the user's |
|
3339 |
platform and screen geometry. |
|
3340 |
||
3341 |
\warning Calling resize() or setGeometry() inside resizeEvent() can |
|
3342 |
lead to infinite recursion. |
|
3343 |
||
3344 |
\note Setting the size to \c{QSize(0, 0)} will cause the widget to not |
|
3345 |
appear on screen. This also applies to windows. |
|
3346 |
||
3347 |
\sa pos, geometry, minimumSize, maximumSize, resizeEvent() |
|
3348 |
*/ |
|
3349 |
||
3350 |
/*! |
|
3351 |
\property QWidget::width |
|
3352 |
\brief the width of the widget excluding any window frame |
|
3353 |
||
3354 |
See the \l{Window Geometry} documentation for an overview of geometry |
|
3355 |
issues with windows. |
|
3356 |
||
3357 |
\note Do not use this function to find the width of a screen on |
|
3358 |
a \l{QDesktopWidget}{multiple screen desktop}. Read |
|
3359 |
\l{QDesktopWidget#Screen Geometry}{this note} for details. |
|
3360 |
||
3361 |
By default, this property contains a value that depends on the user's |
|
3362 |
platform and screen geometry. |
|
3363 |
||
3364 |
\sa geometry, height, size |
|
3365 |
*/ |
|
3366 |
||
3367 |
/*! |
|
3368 |
\property QWidget::height |
|
3369 |
\brief the height of the widget excluding any window frame |
|
3370 |
||
3371 |
See the \l{Window Geometry} documentation for an overview of geometry |
|
3372 |
issues with windows. |
|
3373 |
||
3374 |
\note Do not use this function to find the height of a screen |
|
3375 |
on a \l{QDesktopWidget}{multiple screen desktop}. Read |
|
3376 |
\l{QDesktopWidget#Screen Geometry}{this note} for details. |
|
3377 |
||
3378 |
By default, this property contains a value that depends on the user's |
|
3379 |
platform and screen geometry. |
|
3380 |
||
3381 |
\sa geometry, width, size |
|
3382 |
*/ |
|
3383 |
||
3384 |
/*! |
|
3385 |
\property QWidget::rect |
|
3386 |
\brief the internal geometry of the widget excluding any window |
|
3387 |
frame |
|
3388 |
||
3389 |
The rect property equals QRect(0, 0, width(), height()). |
|
3390 |
||
3391 |
See the \l{Window Geometry} documentation for an overview of geometry |
|
3392 |
issues with windows. |
|
3393 |
||
3394 |
By default, this property contains a value that depends on the user's |
|
3395 |
platform and screen geometry. |
|
3396 |
||
3397 |
\sa size |
|
3398 |
*/ |
|
3399 |
||
3400 |
||
3401 |
QRect QWidget::normalGeometry() const |
|
3402 |
{ |
|
3403 |
Q_D(const QWidget); |
|
3404 |
if (!d->extra || !d->extra->topextra) |
|
3405 |
return QRect(); |
|
3406 |
||
3407 |
if (!isMaximized() && !isFullScreen()) |
|
3408 |
return geometry(); |
|
3409 |
||
3410 |
return d->topData()->normalGeometry; |
|
3411 |
} |
|
3412 |
||
3413 |
||
3414 |
/*! |
|
3415 |
\property QWidget::childrenRect |
|
3416 |
\brief the bounding rectangle of the widget's children |
|
3417 |
||
3418 |
Hidden children are excluded. |
|
3419 |
||
3420 |
By default, for a widget with no children, this property contains a |
|
3421 |
rectangle with zero width and height located at the origin. |
|
3422 |
||
3423 |
\sa childrenRegion() geometry() |
|
3424 |
*/ |
|
3425 |
||
3426 |
QRect QWidget::childrenRect() const |
|
3427 |
{ |
|
3428 |
Q_D(const QWidget); |
|
3429 |
QRect r(0, 0, 0, 0); |
|
3430 |
for (int i = 0; i < d->children.size(); ++i) { |
|
3431 |
QWidget *w = qobject_cast<QWidget *>(d->children.at(i)); |
|
3432 |
if (w && !w->isWindow() && !w->isHidden()) |
|
3433 |
r |= w->geometry(); |
|
3434 |
} |
|
3435 |
return r; |
|
3436 |
} |
|
3437 |
||
3438 |
/*! |
|
3439 |
\property QWidget::childrenRegion |
|
3440 |
\brief the combined region occupied by the widget's children |
|
3441 |
||
3442 |
Hidden children are excluded. |
|
3443 |
||
3444 |
By default, for a widget with no children, this property contains an |
|
3445 |
empty region. |
|
3446 |
||
3447 |
\sa childrenRect() geometry() mask() |
|
3448 |
*/ |
|
3449 |
||
3450 |
QRegion QWidget::childrenRegion() const |
|
3451 |
{ |
|
3452 |
Q_D(const QWidget); |
|
3453 |
QRegion r; |
|
3454 |
for (int i = 0; i < d->children.size(); ++i) { |
|
3455 |
QWidget *w = qobject_cast<QWidget *>(d->children.at(i)); |
|
3456 |
if (w && !w->isWindow() && !w->isHidden()) { |
|
3457 |
QRegion mask = w->mask(); |
|
3458 |
if (mask.isEmpty()) |
|
3459 |
r |= w->geometry(); |
|
3460 |
else |
|
3461 |
r |= mask.translated(w->pos()); |
|
3462 |
} |
|
3463 |
} |
|
3464 |
return r; |
|
3465 |
} |
|
3466 |
||
3467 |
||
3468 |
/*! |
|
3469 |
\property QWidget::minimumSize |
|
3470 |
\brief the widget's minimum size |
|
3471 |
||
3472 |
The widget cannot be resized to a smaller size than the minimum |
|
3473 |
widget size. The widget's size is forced to the minimum size if |
|
3474 |
the current size is smaller. |
|
3475 |
||
3476 |
The minimum size set by this function will override the minimum size |
|
3477 |
defined by QLayout. In order to unset the minimum size, use a |
|
3478 |
value of \c{QSize(0, 0)}. |
|
3479 |
||
3480 |
By default, this property contains a size with zero width and height. |
|
3481 |
||
3482 |
\sa minimumWidth, minimumHeight, maximumSize, sizeIncrement |
|
3483 |
*/ |
|
3484 |
||
3485 |
QSize QWidget::minimumSize() const |
|
3486 |
{ |
|
3487 |
Q_D(const QWidget); |
|
3488 |
return d->extra ? QSize(d->extra->minw, d->extra->minh) : QSize(0, 0); |
|
3489 |
} |
|
3490 |
||
3491 |
/*! |
|
3492 |
\property QWidget::maximumSize |
|
3493 |
\brief the widget's maximum size in pixels |
|
3494 |
||
3495 |
The widget cannot be resized to a larger size than the maximum |
|
3496 |
widget size. |
|
3497 |
||
3498 |
By default, this property contains a size in which both width and height |
|
3499 |
have values of 16777215. |
|
3500 |
||
3501 |
\note The definition of the \c QWIDGETSIZE_MAX macro limits the maximum size |
|
3502 |
of widgets. |
|
3503 |
||
3504 |
\sa maximumWidth, maximumHeight, minimumSize, sizeIncrement |
|
3505 |
*/ |
|
3506 |
||
3507 |
QSize QWidget::maximumSize() const |
|
3508 |
{ |
|
3509 |
Q_D(const QWidget); |
|
3510 |
return d->extra ? QSize(d->extra->maxw, d->extra->maxh) |
|
3511 |
: QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); |
|
3512 |
} |
|
3513 |
||
3514 |
||
3515 |
/*! |
|
3516 |
\property QWidget::minimumWidth |
|
3517 |
\brief the widget's minimum width in pixels |
|
3518 |
||
3519 |
This property corresponds to the width held by the \l minimumSize property. |
|
3520 |
||
3521 |
By default, this property has a value of 0. |
|
3522 |
||
3523 |
\sa minimumSize, minimumHeight |
|
3524 |
*/ |
|
3525 |
||
3526 |
/*! |
|
3527 |
\property QWidget::minimumHeight |
|
3528 |
\brief the widget's minimum height in pixels |
|
3529 |
||
3530 |
This property corresponds to the height held by the \l minimumSize property. |
|
3531 |
||
3532 |
By default, this property has a value of 0. |
|
3533 |
||
3534 |
\sa minimumSize, minimumWidth |
|
3535 |
*/ |
|
3536 |
||
3537 |
/*! |
|
3538 |
\property QWidget::maximumWidth |
|
3539 |
\brief the widget's maximum width in pixels |
|
3540 |
||
3541 |
This property corresponds to the width held by the \l maximumSize property. |
|
3542 |
||
3543 |
By default, this property contains a value of 16777215. |
|
3544 |
||
3545 |
\note The definition of the \c QWIDGETSIZE_MAX macro limits the maximum size |
|
3546 |
of widgets. |
|
3547 |
||
3548 |
\sa maximumSize, maximumHeight |
|
3549 |
*/ |
|
3550 |
||
3551 |
/*! |
|
3552 |
\property QWidget::maximumHeight |
|
3553 |
\brief the widget's maximum height in pixels |
|
3554 |
||
3555 |
This property corresponds to the height held by the \l maximumSize property. |
|
3556 |
||
3557 |
By default, this property contains a value of 16777215. |
|
3558 |
||
3559 |
\note The definition of the \c QWIDGETSIZE_MAX macro limits the maximum size |
|
3560 |
of widgets. |
|
3561 |
||
3562 |
\sa maximumSize, maximumWidth |
|
3563 |
*/ |
|
3564 |
||
3565 |
/*! |
|
3566 |
\property QWidget::sizeIncrement |
|
3567 |
\brief the size increment of the widget |
|
3568 |
||
3569 |
When the user resizes the window, the size will move in steps of |
|
3570 |
sizeIncrement().width() pixels horizontally and |
|
3571 |
sizeIncrement.height() pixels vertically, with baseSize() as the |
|
3572 |
basis. Preferred widget sizes are for non-negative integers \e i |
|
3573 |
and \e j: |
|
3574 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 2 |
|
3575 |
||
3576 |
Note that while you can set the size increment for all widgets, it |
|
3577 |
only affects windows. |
|
3578 |
||
3579 |
By default, this property contains a size with zero width and height. |
|
3580 |
||
3581 |
\warning The size increment has no effect under Windows, and may |
|
3582 |
be disregarded by the window manager on X11. |
|
3583 |
||
3584 |
\sa size, minimumSize, maximumSize |
|
3585 |
*/ |
|
3586 |
QSize QWidget::sizeIncrement() const |
|
3587 |
{ |
|
3588 |
Q_D(const QWidget); |
|
3589 |
return (d->extra && d->extra->topextra) |
|
3590 |
? QSize(d->extra->topextra->incw, d->extra->topextra->inch) |
|
3591 |
: QSize(0, 0); |
|
3592 |
} |
|
3593 |
||
3594 |
/*! |
|
3595 |
\property QWidget::baseSize |
|
3596 |
\brief the base size of the widget |
|
3597 |
||
3598 |
The base size is used to calculate a proper widget size if the |
|
3599 |
widget defines sizeIncrement(). |
|
3600 |
||
3601 |
By default, for a newly-created widget, this property contains a size with |
|
3602 |
zero width and height. |
|
3603 |
||
3604 |
\sa setSizeIncrement() |
|
3605 |
*/ |
|
3606 |
||
3607 |
QSize QWidget::baseSize() const |
|
3608 |
{ |
|
3609 |
Q_D(const QWidget); |
|
3610 |
return (d->extra != 0 && d->extra->topextra != 0) |
|
3611 |
? QSize(d->extra->topextra->basew, d->extra->topextra->baseh) |
|
3612 |
: QSize(0, 0); |
|
3613 |
} |
|
3614 |
||
3615 |
bool QWidgetPrivate::setMinimumSize_helper(int &minw, int &minh) |
|
3616 |
{ |
|
3617 |
Q_Q(QWidget); |
|
3618 |
||
3619 |
#ifdef Q_WS_QWS |
|
3620 |
if (q->isWindow()) { |
|
3621 |
const QRect maxWindowRect = QApplication::desktop()->availableGeometry(QApplication::desktop()->screenNumber(q)); |
|
3622 |
if (!maxWindowRect.isEmpty()) { |
|
3623 |
// ### This is really just a work-around. Layout shouldn't be |
|
3624 |
// asking for minimum sizes bigger than the screen. |
|
3625 |
if (minw > maxWindowRect.width()) |
|
3626 |
minw = maxWindowRect.width(); |
|
3627 |
if (minh > maxWindowRect.height()) |
|
3628 |
minh = maxWindowRect.height(); |
|
3629 |
} |
|
3630 |
} |
|
3631 |
#endif |
|
3632 |
int mw = minw, mh = minh; |
|
3633 |
if (mw == QWIDGETSIZE_MAX) |
|
3634 |
mw = 0; |
|
3635 |
if (mh == QWIDGETSIZE_MAX) |
|
3636 |
mh = 0; |
|
3637 |
if (minw > QWIDGETSIZE_MAX || minh > QWIDGETSIZE_MAX) { |
|
3638 |
qWarning("QWidget::setMinimumSize: (%s/%s) " |
|
3639 |
"The largest allowed size is (%d,%d)", |
|
3640 |
q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX, |
|
3641 |
QWIDGETSIZE_MAX); |
|
3642 |
minw = mw = qMin<int>(minw, QWIDGETSIZE_MAX); |
|
3643 |
minh = mh = qMin<int>(minh, QWIDGETSIZE_MAX); |
|
3644 |
} |
|
3645 |
if (minw < 0 || minh < 0) { |
|
3646 |
qWarning("QWidget::setMinimumSize: (%s/%s) Negative sizes (%d,%d) " |
|
3647 |
"are not possible", |
|
3648 |
q->objectName().toLocal8Bit().data(), q->metaObject()->className(), minw, minh); |
|
3649 |
minw = mw = qMax(minw, 0); |
|
3650 |
minh = mh = qMax(minh, 0); |
|
3651 |
} |
|
3652 |
createExtra(); |
|
3653 |
if (extra->minw == mw && extra->minh == mh) |
|
3654 |
return false; |
|
3655 |
extra->minw = mw; |
|
3656 |
extra->minh = mh; |
|
3657 |
extra->explicitMinSize = (mw ? Qt::Horizontal : 0) | (mh ? Qt::Vertical : 0); |
|
3658 |
return true; |
|
3659 |
} |
|
3660 |
||
3661 |
/*! |
|
3662 |
\overload |
|
3663 |
||
3664 |
This function corresponds to setMinimumSize(QSize(minw, minh)). |
|
3665 |
Sets the minimum width to \a minw and the minimum height to \a |
|
3666 |
minh. |
|
3667 |
*/ |
|
3668 |
||
3669 |
void QWidget::setMinimumSize(int minw, int minh) |
|
3670 |
{ |
|
3671 |
Q_D(QWidget); |
|
3672 |
if (!d->setMinimumSize_helper(minw, minh)) |
|
3673 |
return; |
|
3674 |
||
3675 |
if (isWindow()) |
|
3676 |
d->setConstraints_sys(); |
|
3677 |
if (minw > width() || minh > height()) { |
|
3678 |
bool resized = testAttribute(Qt::WA_Resized); |
|
3679 |
bool maximized = isMaximized(); |
|
3680 |
resize(qMax(minw,width()), qMax(minh,height())); |
|
3681 |
setAttribute(Qt::WA_Resized, resized); //not a user resize |
|
3682 |
if (maximized) |
|
3683 |
data->window_state = data->window_state | Qt::WindowMaximized; |
|
3684 |
} |
|
3685 |
#ifndef QT_NO_GRAPHICSVIEW |
|
3686 |
if (d->extra) { |
|
3687 |
if (d->extra->proxyWidget) |
|
3688 |
d->extra->proxyWidget->setMinimumSize(minw, minh); |
|
3689 |
} |
|
3690 |
#endif |
|
3691 |
d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh); |
|
3692 |
} |
|
3693 |
||
3694 |
bool QWidgetPrivate::setMaximumSize_helper(int &maxw, int &maxh) |
|
3695 |
{ |
|
3696 |
Q_Q(QWidget); |
|
3697 |
if (maxw > QWIDGETSIZE_MAX || maxh > QWIDGETSIZE_MAX) { |
|
3698 |
qWarning("QWidget::setMaximumSize: (%s/%s) " |
|
3699 |
"The largest allowed size is (%d,%d)", |
|
3700 |
q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX, |
|
3701 |
QWIDGETSIZE_MAX); |
|
3702 |
maxw = qMin<int>(maxw, QWIDGETSIZE_MAX); |
|
3703 |
maxh = qMin<int>(maxh, QWIDGETSIZE_MAX); |
|
3704 |
} |
|
3705 |
if (maxw < 0 || maxh < 0) { |
|
3706 |
qWarning("QWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) " |
|
3707 |
"are not possible", |
|
3708 |
q->objectName().toLocal8Bit().data(), q->metaObject()->className(), maxw, maxh); |
|
3709 |
maxw = qMax(maxw, 0); |
|
3710 |
maxh = qMax(maxh, 0); |
|
3711 |
} |
|
3712 |
createExtra(); |
|
3713 |
if (extra->maxw == maxw && extra->maxh == maxh) |
|
3714 |
return false; |
|
3715 |
extra->maxw = maxw; |
|
3716 |
extra->maxh = maxh; |
|
3717 |
extra->explicitMaxSize = (maxw != QWIDGETSIZE_MAX ? Qt::Horizontal : 0) | |
|
3718 |
(maxh != QWIDGETSIZE_MAX ? Qt::Vertical : 0); |
|
3719 |
return true; |
|
3720 |
} |
|
3721 |
||
3722 |
/*! |
|
3723 |
\overload |
|
3724 |
||
3725 |
This function corresponds to setMaximumSize(QSize(\a maxw, \a |
|
3726 |
maxh)). Sets the maximum width to \a maxw and the maximum height |
|
3727 |
to \a maxh. |
|
3728 |
*/ |
|
3729 |
void QWidget::setMaximumSize(int maxw, int maxh) |
|
3730 |
{ |
|
3731 |
Q_D(QWidget); |
|
3732 |
if (!d->setMaximumSize_helper(maxw, maxh)) |
|
3733 |
return; |
|
3734 |
||
3735 |
if (isWindow()) |
|
3736 |
d->setConstraints_sys(); |
|
3737 |
if (maxw < width() || maxh < height()) { |
|
3738 |
bool resized = testAttribute(Qt::WA_Resized); |
|
3739 |
resize(qMin(maxw,width()), qMin(maxh,height())); |
|
3740 |
setAttribute(Qt::WA_Resized, resized); //not a user resize |
|
3741 |
} |
|
3742 |
||
3743 |
#ifndef QT_NO_GRAPHICSVIEW |
|
3744 |
if (d->extra) { |
|
3745 |
if (d->extra->proxyWidget) |
|
3746 |
d->extra->proxyWidget->setMaximumSize(maxw, maxh); |
|
3747 |
} |
|
3748 |
#endif |
|
3749 |
||
3750 |
d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh); |
|
3751 |
} |
|
3752 |
||
3753 |
/*! |
|
3754 |
\overload |
|
3755 |
||
3756 |
Sets the x (width) size increment to \a w and the y (height) size |
|
3757 |
increment to \a h. |
|
3758 |
*/ |
|
3759 |
void QWidget::setSizeIncrement(int w, int h) |
|
3760 |
{ |
|
3761 |
Q_D(QWidget); |
|
3762 |
d->createTLExtra(); |
|
3763 |
QTLWExtra* x = d->topData(); |
|
3764 |
if (x->incw == w && x->inch == h) |
|
3765 |
return; |
|
3766 |
x->incw = w; |
|
3767 |
x->inch = h; |
|
3768 |
if (isWindow()) |
|
3769 |
d->setConstraints_sys(); |
|
3770 |
} |
|
3771 |
||
3772 |
/*! |
|
3773 |
\overload |
|
3774 |
||
3775 |
This corresponds to setBaseSize(QSize(\a basew, \a baseh)). Sets |
|
3776 |
the widgets base size to width \a basew and height \a baseh. |
|
3777 |
*/ |
|
3778 |
void QWidget::setBaseSize(int basew, int baseh) |
|
3779 |
{ |
|
3780 |
Q_D(QWidget); |
|
3781 |
d->createTLExtra(); |
|
3782 |
QTLWExtra* x = d->topData(); |
|
3783 |
if (x->basew == basew && x->baseh == baseh) |
|
3784 |
return; |
|
3785 |
x->basew = basew; |
|
3786 |
x->baseh = baseh; |
|
3787 |
if (isWindow()) |
|
3788 |
d->setConstraints_sys(); |
|
3789 |
} |
|
3790 |
||
3791 |
/*! |
|
3792 |
Sets both the minimum and maximum sizes of the widget to \a s, |
|
3793 |
thereby preventing it from ever growing or shrinking. |
|
3794 |
||
3795 |
This will override the default size constraints set by QLayout. |
|
3796 |
||
3797 |
To remove constraints, set the size to QWIDGETSIZE_MAX. |
|
3798 |
||
3799 |
Alternatively, if you want the widget to have a |
|
3800 |
fixed size based on its contents, you can call |
|
3801 |
QLayout::setSizeConstraint(QLayout::SetFixedSize); |
|
3802 |
||
3803 |
\sa maximumSize, minimumSize |
|
3804 |
*/ |
|
3805 |
||
3806 |
void QWidget::setFixedSize(const QSize & s) |
|
3807 |
{ |
|
3808 |
setFixedSize(s.width(), s.height()); |
|
3809 |
} |
|
3810 |
||
3811 |
||
3812 |
/*! |
|
3813 |
\fn void QWidget::setFixedSize(int w, int h) |
|
3814 |
\overload |
|
3815 |
||
3816 |
Sets the width of the widget to \a w and the height to \a h. |
|
3817 |
*/ |
|
3818 |
||
3819 |
void QWidget::setFixedSize(int w, int h) |
|
3820 |
{ |
|
3821 |
Q_D(QWidget); |
|
3822 |
#ifdef Q_WS_QWS |
|
3823 |
// temporary fix for 4.3.x. |
|
3824 |
// Should move the embedded spesific contraints in setMinimumSize_helper into QLayout |
|
3825 |
int tmpW = w; |
|
3826 |
int tmpH = h; |
|
3827 |
bool minSizeSet = d->setMinimumSize_helper(tmpW, tmpH); |
|
3828 |
#else |
|
3829 |
bool minSizeSet = d->setMinimumSize_helper(w, h); |
|
3830 |
#endif |
|
3831 |
bool maxSizeSet = d->setMaximumSize_helper(w, h); |
|
3832 |
if (!minSizeSet && !maxSizeSet) |
|
3833 |
return; |
|
3834 |
||
3835 |
if (isWindow()) |
|
3836 |
d->setConstraints_sys(); |
|
3837 |
else |
|
3838 |
d->updateGeometry_helper(true); |
|
3839 |
||
3840 |
if (w != QWIDGETSIZE_MAX || h != QWIDGETSIZE_MAX) |
|
3841 |
resize(w, h); |
|
3842 |
} |
|
3843 |
||
3844 |
void QWidget::setMinimumWidth(int w) |
|
3845 |
{ |
|
3846 |
Q_D(QWidget); |
|
3847 |
d->createExtra(); |
|
3848 |
uint expl = d->extra->explicitMinSize | (w ? Qt::Horizontal : 0); |
|
3849 |
setMinimumSize(w, minimumSize().height()); |
|
3850 |
d->extra->explicitMinSize = expl; |
|
3851 |
} |
|
3852 |
||
3853 |
void QWidget::setMinimumHeight(int h) |
|
3854 |
{ |
|
3855 |
Q_D(QWidget); |
|
3856 |
d->createExtra(); |
|
3857 |
uint expl = d->extra->explicitMinSize | (h ? Qt::Vertical : 0); |
|
3858 |
setMinimumSize(minimumSize().width(), h); |
|
3859 |
d->extra->explicitMinSize = expl; |
|
3860 |
} |
|
3861 |
||
3862 |
void QWidget::setMaximumWidth(int w) |
|
3863 |
{ |
|
3864 |
Q_D(QWidget); |
|
3865 |
d->createExtra(); |
|
3866 |
uint expl = d->extra->explicitMaxSize | (w == QWIDGETSIZE_MAX ? 0 : Qt::Horizontal); |
|
3867 |
setMaximumSize(w, maximumSize().height()); |
|
3868 |
d->extra->explicitMaxSize = expl; |
|
3869 |
} |
|
3870 |
||
3871 |
void QWidget::setMaximumHeight(int h) |
|
3872 |
{ |
|
3873 |
Q_D(QWidget); |
|
3874 |
d->createExtra(); |
|
3875 |
uint expl = d->extra->explicitMaxSize | (h == QWIDGETSIZE_MAX ? 0 : Qt::Vertical); |
|
3876 |
setMaximumSize(maximumSize().width(), h); |
|
3877 |
d->extra->explicitMaxSize = expl; |
|
3878 |
} |
|
3879 |
||
3880 |
/*! |
|
3881 |
Sets both the minimum and maximum width of the widget to \a w |
|
3882 |
without changing the heights. Provided for convenience. |
|
3883 |
||
3884 |
\sa sizeHint() minimumSize() maximumSize() setFixedSize() |
|
3885 |
*/ |
|
3886 |
||
3887 |
void QWidget::setFixedWidth(int w) |
|
3888 |
{ |
|
3889 |
Q_D(QWidget); |
|
3890 |
d->createExtra(); |
|
3891 |
uint explMin = d->extra->explicitMinSize | Qt::Horizontal; |
|
3892 |
uint explMax = d->extra->explicitMaxSize | Qt::Horizontal; |
|
3893 |
setMinimumSize(w, minimumSize().height()); |
|
3894 |
setMaximumSize(w, maximumSize().height()); |
|
3895 |
d->extra->explicitMinSize = explMin; |
|
3896 |
d->extra->explicitMaxSize = explMax; |
|
3897 |
} |
|
3898 |
||
3899 |
||
3900 |
/*! |
|
3901 |
Sets both the minimum and maximum heights of the widget to \a h |
|
3902 |
without changing the widths. Provided for convenience. |
|
3903 |
||
3904 |
\sa sizeHint() minimumSize() maximumSize() setFixedSize() |
|
3905 |
*/ |
|
3906 |
||
3907 |
void QWidget::setFixedHeight(int h) |
|
3908 |
{ |
|
3909 |
Q_D(QWidget); |
|
3910 |
d->createExtra(); |
|
3911 |
uint explMin = d->extra->explicitMinSize | Qt::Vertical; |
|
3912 |
uint explMax = d->extra->explicitMaxSize | Qt::Vertical; |
|
3913 |
setMinimumSize(minimumSize().width(), h); |
|
3914 |
setMaximumSize(maximumSize().width(), h); |
|
3915 |
d->extra->explicitMinSize = explMin; |
|
3916 |
d->extra->explicitMaxSize = explMax; |
|
3917 |
} |
|
3918 |
||
3919 |
||
3920 |
/*! |
|
3921 |
Translates the widget coordinate \a pos to the coordinate system |
|
3922 |
of \a parent. The \a parent must not be 0 and must be a parent |
|
3923 |
of the calling widget. |
|
3924 |
||
3925 |
\sa mapFrom() mapToParent() mapToGlobal() underMouse() |
|
3926 |
*/ |
|
3927 |
||
3928 |
QPoint QWidget::mapTo(QWidget * parent, const QPoint & pos) const |
|
3929 |
{ |
|
3930 |
QPoint p = pos; |
|
3931 |
if (parent) { |
|
3932 |
const QWidget * w = this; |
|
3933 |
while (w != parent) { |
|
3934 |
Q_ASSERT_X(w, "QWidget::mapTo(QWidget *parent, const QPoint &pos)", |
|
3935 |
"parent must be in parent hierarchy"); |
|
3936 |
p = w->mapToParent(p); |
|
3937 |
w = w->parentWidget(); |
|
3938 |
} |
|
3939 |
} |
|
3940 |
return p; |
|
3941 |
} |
|
3942 |
||
3943 |
||
3944 |
/*! |
|
3945 |
Translates the widget coordinate \a pos from the coordinate system |
|
3946 |
of \a parent to this widget's coordinate system. The \a parent |
|
3947 |
must not be 0 and must be a parent of the calling widget. |
|
3948 |
||
3949 |
\sa mapTo() mapFromParent() mapFromGlobal() underMouse() |
|
3950 |
*/ |
|
3951 |
||
3952 |
QPoint QWidget::mapFrom(QWidget * parent, const QPoint & pos) const |
|
3953 |
{ |
|
3954 |
QPoint p(pos); |
|
3955 |
if (parent) { |
|
3956 |
const QWidget * w = this; |
|
3957 |
while (w != parent) { |
|
3958 |
Q_ASSERT_X(w, "QWidget::mapFrom(QWidget *parent, const QPoint &pos)", |
|
3959 |
"parent must be in parent hierarchy"); |
|
3960 |
||
3961 |
p = w->mapFromParent(p); |
|
3962 |
w = w->parentWidget(); |
|
3963 |
} |
|
3964 |
} |
|
3965 |
return p; |
|
3966 |
} |
|
3967 |
||
3968 |
||
3969 |
/*! |
|
3970 |
Translates the widget coordinate \a pos to a coordinate in the |
|
3971 |
parent widget. |
|
3972 |
||
3973 |
Same as mapToGlobal() if the widget has no parent. |
|
3974 |
||
3975 |
\sa mapFromParent() mapTo() mapToGlobal() underMouse() |
|
3976 |
*/ |
|
3977 |
||
3978 |
QPoint QWidget::mapToParent(const QPoint &pos) const |
|
3979 |
{ |
|
3980 |
return pos + data->crect.topLeft(); |
|
3981 |
} |
|
3982 |
||
3983 |
/*! |
|
3984 |
Translates the parent widget coordinate \a pos to widget |
|
3985 |
coordinates. |
|
3986 |
||
3987 |
Same as mapFromGlobal() if the widget has no parent. |
|
3988 |
||
3989 |
\sa mapToParent() mapFrom() mapFromGlobal() underMouse() |
|
3990 |
*/ |
|
3991 |
||
3992 |
QPoint QWidget::mapFromParent(const QPoint &pos) const |
|
3993 |
{ |
|
3994 |
return pos - data->crect.topLeft(); |
|
3995 |
} |
|
3996 |
||
3997 |
||
3998 |
/*! |
|
3999 |
Returns the window for this widget, i.e. the next ancestor widget |
|
4000 |
that has (or could have) a window-system frame. |
|
4001 |
||
4002 |
If the widget is a window, the widget itself is returned. |
|
4003 |
||
4004 |
Typical usage is changing the window title: |
|
4005 |
||
4006 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 3 |
|
4007 |
||
4008 |
\sa isWindow() |
|
4009 |
*/ |
|
4010 |
||
4011 |
QWidget *QWidget::window() const |
|
4012 |
{ |
|
4013 |
QWidget *w = (QWidget *)this; |
|
4014 |
QWidget *p = w->parentWidget(); |
|
4015 |
while (!w->isWindow() && p) { |
|
4016 |
w = p; |
|
4017 |
p = p->parentWidget(); |
|
4018 |
} |
|
4019 |
return w; |
|
4020 |
} |
|
4021 |
||
4022 |
/*! |
|
4023 |
\since 4.4 |
|
4024 |
||
4025 |
Returns the native parent for this widget, i.e. the next ancestor widget |
|
4026 |
that has a system identifier, or 0 if it does not have any native parent. |
|
4027 |
||
4028 |
\sa effectiveWinId() |
|
4029 |
*/ |
|
4030 |
QWidget *QWidget::nativeParentWidget() const |
|
4031 |
{ |
|
4032 |
QWidget *parent = parentWidget(); |
|
4033 |
while (parent && !parent->internalWinId()) |
|
4034 |
parent = parent->parentWidget(); |
|
4035 |
return parent; |
|
4036 |
} |
|
4037 |
||
4038 |
/*! \fn QWidget *QWidget::topLevelWidget() const |
|
4039 |
\obsolete |
|
4040 |
||
4041 |
Use window() instead. |
|
4042 |
*/ |
|
4043 |
||
4044 |
#ifdef QT3_SUPPORT |
|
4045 |
/*! |
|
4046 |
Returns the color role used for painting the widget's background. |
|
4047 |
||
4048 |
Use QPalette(backgroundRole(()) instead. |
|
4049 |
*/ |
|
4050 |
Qt::BackgroundMode QWidget::backgroundMode() const |
|
4051 |
{ |
|
4052 |
if (testAttribute(Qt::WA_NoSystemBackground)) |
|
4053 |
return Qt::NoBackground; |
|
4054 |
switch(backgroundRole()) { |
|
4055 |
case QPalette::WindowText: |
|
4056 |
return Qt::PaletteForeground; |
|
4057 |
case QPalette::Button: |
|
4058 |
return Qt::PaletteButton; |
|
4059 |
case QPalette::Light: |
|
4060 |
return Qt::PaletteLight; |
|
4061 |
case QPalette::Midlight: |
|
4062 |
return Qt::PaletteMidlight; |
|
4063 |
case QPalette::Dark: |
|
4064 |
return Qt::PaletteDark; |
|
4065 |
case QPalette::Mid: |
|
4066 |
return Qt::PaletteMid; |
|
4067 |
case QPalette::Text: |
|
4068 |
return Qt::PaletteText; |
|
4069 |
case QPalette::BrightText: |
|
4070 |
return Qt::PaletteBrightText; |
|
4071 |
case QPalette::Base: |
|
4072 |
return Qt::PaletteBase; |
|
4073 |
case QPalette::Window: |
|
4074 |
return Qt::PaletteBackground; |
|
4075 |
case QPalette::Shadow: |
|
4076 |
return Qt::PaletteShadow; |
|
4077 |
case QPalette::Highlight: |
|
4078 |
return Qt::PaletteHighlight; |
|
4079 |
case QPalette::HighlightedText: |
|
4080 |
return Qt::PaletteHighlightedText; |
|
4081 |
case QPalette::ButtonText: |
|
4082 |
return Qt::PaletteButtonText; |
|
4083 |
case QPalette::Link: |
|
4084 |
return Qt::PaletteLink; |
|
4085 |
case QPalette::LinkVisited: |
|
4086 |
return Qt::PaletteLinkVisited; |
|
4087 |
default: |
|
4088 |
break; |
|
4089 |
} |
|
4090 |
return Qt::NoBackground; |
|
4091 |
} |
|
4092 |
||
4093 |
/*! |
|
4094 |
\fn void QWidget::setBackgroundMode(Qt::BackgroundMode |
|
4095 |
widgetBackground, Qt::BackgroundMode paletteBackground) |
|
4096 |
||
4097 |
Sets the color role used for painting the widget's background to |
|
4098 |
background mode \a widgetBackground. The \a paletteBackground mode |
|
4099 |
parameter is ignored. |
|
4100 |
*/ |
|
4101 |
void QWidget::setBackgroundMode(Qt::BackgroundMode m, Qt::BackgroundMode) |
|
4102 |
{ |
|
4103 |
Q_D(QWidget); |
|
4104 |
if(m == Qt::NoBackground) { |
|
4105 |
setAttribute(Qt::WA_NoSystemBackground, true); |
|
4106 |
return; |
|
4107 |
} |
|
4108 |
setAttribute(Qt::WA_NoSystemBackground, false); |
|
4109 |
d->fg_role = QPalette::NoRole; |
|
4110 |
QPalette::ColorRole role = d->bg_role; |
|
4111 |
switch(m) { |
|
4112 |
case Qt::FixedColor: |
|
4113 |
case Qt::FixedPixmap: |
|
4114 |
break; |
|
4115 |
case Qt::PaletteForeground: |
|
4116 |
role = QPalette::WindowText; |
|
4117 |
break; |
|
4118 |
case Qt::PaletteButton: |
|
4119 |
role = QPalette::Button; |
|
4120 |
break; |
|
4121 |
case Qt::PaletteLight: |
|
4122 |
role = QPalette::Light; |
|
4123 |
break; |
|
4124 |
case Qt::PaletteMidlight: |
|
4125 |
role = QPalette::Midlight; |
|
4126 |
break; |
|
4127 |
case Qt::PaletteDark: |
|
4128 |
role = QPalette::Dark; |
|
4129 |
break; |
|
4130 |
case Qt::PaletteMid: |
|
4131 |
role = QPalette::Mid; |
|
4132 |
break; |
|
4133 |
case Qt::PaletteText: |
|
4134 |
role = QPalette::Text; |
|
4135 |
break; |
|
4136 |
case Qt::PaletteBrightText: |
|
4137 |
role = QPalette::BrightText; |
|
4138 |
break; |
|
4139 |
case Qt::PaletteBase: |
|
4140 |
role = QPalette::Base; |
|
4141 |
break; |
|
4142 |
case Qt::PaletteBackground: |
|
4143 |
role = QPalette::Window; |
|
4144 |
break; |
|
4145 |
case Qt::PaletteShadow: |
|
4146 |
role = QPalette::Shadow; |
|
4147 |
break; |
|
4148 |
case Qt::PaletteHighlight: |
|
4149 |
role = QPalette::Highlight; |
|
4150 |
break; |
|
4151 |
case Qt::PaletteHighlightedText: |
|
4152 |
role = QPalette::HighlightedText; |
|
4153 |
break; |
|
4154 |
case Qt::PaletteButtonText: |
|
4155 |
role = QPalette::ButtonText; |
|
4156 |
break; |
|
4157 |
case Qt::PaletteLink: |
|
4158 |
role = QPalette::Link; |
|
4159 |
break; |
|
4160 |
case Qt::PaletteLinkVisited: |
|
4161 |
role = QPalette::LinkVisited; |
|
4162 |
break; |
|
4163 |
case Qt::X11ParentRelative: |
|
4164 |
d->fg_role = role = QPalette::NoRole; |
|
4165 |
default: |
|
4166 |
break; |
|
4167 |
} |
|
4168 |
setBackgroundRole(role); |
|
4169 |
} |
|
4170 |
||
4171 |
/*! |
|
4172 |
The widget mapper is no longer part of the public API. |
|
4173 |
*/ |
|
4174 |
QT3_SUPPORT QWidgetMapper *QWidget::wmapper() { return QWidgetPrivate::mapper; } |
|
4175 |
||
4176 |
#endif |
|
4177 |
||
4178 |
||
4179 |
/*! |
|
4180 |
Returns the background role of the widget. |
|
4181 |
||
4182 |
The background role defines the brush from the widget's \l palette that |
|
4183 |
is used to render the background. |
|
4184 |
||
4185 |
If no explicit background role is set, the widget inherts its parent |
|
4186 |
widget's background role. |
|
4187 |
||
4188 |
\sa setBackgroundRole(), foregroundRole() |
|
4189 |
*/ |
|
4190 |
QPalette::ColorRole QWidget::backgroundRole() const |
|
4191 |
{ |
|
4192 |
||
4193 |
const QWidget *w = this; |
|
4194 |
do { |
|
4195 |
QPalette::ColorRole role = w->d_func()->bg_role; |
|
4196 |
if (role != QPalette::NoRole) |
|
4197 |
return role; |
|
4198 |
if (w->isWindow() || w->windowType() == Qt::SubWindow) |
|
4199 |
break; |
|
4200 |
w = w->parentWidget(); |
|
4201 |
} while (w); |
|
4202 |
return QPalette::Window; |
|
4203 |
} |
|
4204 |
||
4205 |
/*! |
|
4206 |
Sets the background role of the widget to \a role. |
|
4207 |
||
4208 |
The background role defines the brush from the widget's \l palette that |
|
4209 |
is used to render the background. |
|
4210 |
||
4211 |
If \a role is QPalette::NoRole, then the widget inherits its |
|
4212 |
parent's background role. |
|
4213 |
||
4214 |
Note that styles are free to choose any color from the palette. |
|
4215 |
You can modify the palette or set a style sheet if you don't |
|
4216 |
achieve the result you want with setBackgroundRole(). |
|
4217 |
||
4218 |
\sa backgroundRole(), foregroundRole() |
|
4219 |
*/ |
|
4220 |
||
4221 |
void QWidget::setBackgroundRole(QPalette::ColorRole role) |
|
4222 |
{ |
|
4223 |
Q_D(QWidget); |
|
4224 |
d->bg_role = role; |
|
4225 |
d->updateSystemBackground(); |
|
4226 |
d->propagatePaletteChange(); |
|
4227 |
d->updateIsOpaque(); |
|
4228 |
} |
|
4229 |
||
4230 |
/*! |
|
4231 |
Returns the foreground role. |
|
4232 |
||
4233 |
The foreground role defines the color from the widget's \l palette that |
|
4234 |
is used to draw the foreground. |
|
4235 |
||
4236 |
If no explicit foreground role is set, the function returns a role |
|
4237 |
that contrasts with the background role. |
|
4238 |
||
4239 |
\sa setForegroundRole(), backgroundRole() |
|
4240 |
*/ |
|
4241 |
QPalette::ColorRole QWidget::foregroundRole() const |
|
4242 |
{ |
|
4243 |
Q_D(const QWidget); |
|
4244 |
QPalette::ColorRole rl = QPalette::ColorRole(d->fg_role); |
|
4245 |
if (rl != QPalette::NoRole) |
|
4246 |
return rl; |
|
4247 |
QPalette::ColorRole role = QPalette::WindowText; |
|
4248 |
switch (backgroundRole()) { |
|
4249 |
case QPalette::Button: |
|
4250 |
role = QPalette::ButtonText; |
|
4251 |
break; |
|
4252 |
case QPalette::Base: |
|
4253 |
role = QPalette::Text; |
|
4254 |
break; |
|
4255 |
case QPalette::Dark: |
|
4256 |
case QPalette::Shadow: |
|
4257 |
role = QPalette::Light; |
|
4258 |
break; |
|
4259 |
case QPalette::Highlight: |
|
4260 |
role = QPalette::HighlightedText; |
|
4261 |
break; |
|
4262 |
case QPalette::ToolTipBase: |
|
4263 |
role = QPalette::ToolTipText; |
|
4264 |
break; |
|
4265 |
default: |
|
4266 |
; |
|
4267 |
} |
|
4268 |
return role; |
|
4269 |
} |
|
4270 |
||
4271 |
/*! |
|
4272 |
Sets the foreground role of the widget to \a role. |
|
4273 |
||
4274 |
The foreground role defines the color from the widget's \l palette that |
|
4275 |
is used to draw the foreground. |
|
4276 |
||
4277 |
If \a role is QPalette::NoRole, the widget uses a foreground role |
|
4278 |
that contrasts with the background role. |
|
4279 |
||
4280 |
Note that styles are free to choose any color from the palette. |
|
4281 |
You can modify the palette or set a style sheet if you don't |
|
4282 |
achieve the result you want with setForegroundRole(). |
|
4283 |
||
4284 |
\sa foregroundRole(), backgroundRole() |
|
4285 |
*/ |
|
4286 |
void QWidget::setForegroundRole(QPalette::ColorRole role) |
|
4287 |
{ |
|
4288 |
Q_D(QWidget); |
|
4289 |
d->fg_role = role; |
|
4290 |
d->updateSystemBackground(); |
|
4291 |
d->propagatePaletteChange(); |
|
4292 |
} |
|
4293 |
||
4294 |
/*! |
|
4295 |
\property QWidget::palette |
|
4296 |
\brief the widget's palette |
|
4297 |
||
4298 |
This property describes the widget's palette. The palette is used by the |
|
4299 |
widget's style when rendering standard components, and is available as a |
|
4300 |
means to ensure that custom widgets can maintain consistency with the |
|
4301 |
native platform's look and feel. It's common that different platforms, or |
|
4302 |
different styles, have different palettes. |
|
4303 |
||
4304 |
When you assign a new palette to a widget, the color roles from this |
|
4305 |
palette are combined with the widget's default palette to form the |
|
4306 |
widget's final palette. The palette entry for the widget's background role |
|
4307 |
is used to fill the widget's background (see QWidget::autoFillBackground), |
|
4308 |
and the foreground role initializes QPainter's pen. |
|
4309 |
||
4310 |
The default depends on the system environment. QApplication maintains a |
|
4311 |
system/theme palette which serves as a default for all widgets. There may |
|
4312 |
also be special palette defaults for certain types of widgets (e.g., on |
|
4313 |
Windows XP and Vista, all classes that derive from QMenuBar have a special |
|
4314 |
default palette). You can also define default palettes for widgets |
|
4315 |
yourself by passing a custom palette and the name of a widget to |
|
4316 |
QApplication::setPalette(). Finally, the style always has the option of |
|
4317 |
polishing the palette as it's assigned (see QStyle::polish()). |
|
4318 |
||
4319 |
QWidget propagates explicit palette roles from parent to child. If you |
|
4320 |
assign a brush or color to a specific role on a palette and assign that |
|
4321 |
palette to a widget, that role will propagate to all the widget's |
|
4322 |
children, overriding any system defaults for that role. Note that palettes |
|
4323 |
by default don't propagate to windows (see isWindow()) unless the |
|
4324 |
Qt::WA_WindowPropagation attribute is enabled. |
|
4325 |
||
4326 |
QWidget's palette propagation is similar to its font propagation. |
|
4327 |
||
4328 |
The current style, which is used to render the content of all standard Qt |
|
4329 |
widgets, is free to choose colors and brushes from the widget palette, or |
|
4330 |
in some cases, to ignore the palette (partially, or completely). In |
|
4331 |
particular, certain styles like GTK style, Mac style, Windows XP, and |
|
4332 |
Vista style, depend on third party APIs to render the content of widgets, |
|
4333 |
and these styles typically do not follow the palette. Because of this, |
|
4334 |
assigning roles to a widget's palette is not guaranteed to change the |
|
4335 |
appearance of the widget. Instead, you may choose to apply a \l |
|
4336 |
styleSheet. You can refer to our Knowledge Base article |
|
4337 |
\l{http://qt.nokia.com/developer/knowledgebase/22}{here} for more |
|
4338 |
information. |
|
4339 |
||
4340 |
\warning Do not use this function in conjunction with \l{Qt Style Sheets}. |
|
4341 |
When using style sheets, the palette of a widget can be customized using |
|
4342 |
the "color", "background-color", "selection-color", |
|
4343 |
"selection-background-color" and "alternate-background-color". |
|
4344 |
||
4345 |
\sa QApplication::palette(), QWidget::font() |
|
4346 |
*/ |
|
4347 |
const QPalette &QWidget::palette() const |
|
4348 |
{ |
|
4349 |
if (!isEnabled()) { |
|
4350 |
data->pal.setCurrentColorGroup(QPalette::Disabled); |
|
4351 |
} else if ((!isVisible() || isActiveWindow()) |
|
4352 |
#if defined(Q_OS_WIN) && !defined(Q_WS_WINCE) |
|
4353 |
&& !QApplicationPrivate::isBlockedByModal(const_cast<QWidget *>(this)) |
|
4354 |
#endif |
|
4355 |
) { |
|
4356 |
data->pal.setCurrentColorGroup(QPalette::Active); |
|
4357 |
} else { |
|
4358 |
#ifdef Q_WS_MAC |
|
4359 |
extern bool qt_mac_can_clickThrough(const QWidget *); //qwidget_mac.cpp |
|
4360 |
if (qt_mac_can_clickThrough(this)) |
|
4361 |
data->pal.setCurrentColorGroup(QPalette::Active); |
|
4362 |
else |
|
4363 |
#endif |
|
4364 |
data->pal.setCurrentColorGroup(QPalette::Inactive); |
|
4365 |
} |
|
4366 |
return data->pal; |
|
4367 |
} |
|
4368 |
||
4369 |
void QWidget::setPalette(const QPalette &palette) |
|
4370 |
{ |
|
4371 |
Q_D(QWidget); |
|
4372 |
setAttribute(Qt::WA_SetPalette, palette.resolve() != 0); |
|
4373 |
||
4374 |
// Determine which palette is inherited from this widget's ancestors and |
|
4375 |
// QApplication::palette, resolve this against \a palette (attributes from |
|
4376 |
// the inherited palette are copied over this widget's palette). Then |
|
4377 |
// propagate this palette to this widget's children. |
|
4378 |
QPalette naturalPalette = d->naturalWidgetPalette(d->inheritedPaletteResolveMask); |
|
4379 |
QPalette resolvedPalette = palette.resolve(naturalPalette); |
|
4380 |
d->setPalette_helper(resolvedPalette); |
|
4381 |
} |
|
4382 |
||
4383 |
/*! |
|
4384 |
\internal |
|
4385 |
||
4386 |
Returns the palette that the widget \a w inherits from its ancestors and |
|
4387 |
QApplication::palette. \a inheritedMask is the combination of the widget's |
|
4388 |
ancestors palette request masks (i.e., which attributes from the parent |
|
4389 |
widget's palette are implicitly imposed on this widget by the user). Note |
|
4390 |
that this font does not take into account the palette set on \a w itself. |
|
4391 |
*/ |
|
4392 |
QPalette QWidgetPrivate::naturalWidgetPalette(uint inheritedMask) const |
|
4393 |
{ |
|
4394 |
Q_Q(const QWidget); |
|
4395 |
QPalette naturalPalette = QApplication::palette(q); |
|
4396 |
if (!q->testAttribute(Qt::WA_StyleSheet) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4397 |
&& (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4398 |
#ifndef QT_NO_GRAPHICSVIEW |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4399 |
|| (extra && extra->proxyWidget) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4400 |
#endif //QT_NO_GRAPHICSVIEW |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4401 |
)) { |
0 | 4402 |
if (QWidget *p = q->parentWidget()) { |
4403 |
if (!p->testAttribute(Qt::WA_StyleSheet)) { |
|
4404 |
if (!naturalPalette.isCopyOf(QApplication::palette())) { |
|
4405 |
QPalette inheritedPalette = p->palette(); |
|
4406 |
inheritedPalette.resolve(inheritedMask); |
|
4407 |
naturalPalette = inheritedPalette.resolve(naturalPalette); |
|
4408 |
} else { |
|
4409 |
naturalPalette = p->palette(); |
|
4410 |
} |
|
4411 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4412 |
} |
0 | 4413 |
#ifndef QT_NO_GRAPHICSVIEW |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4414 |
else if (extra && extra->proxyWidget) { |
0 | 4415 |
QPalette inheritedPalette = extra->proxyWidget->palette(); |
4416 |
inheritedPalette.resolve(inheritedMask); |
|
4417 |
naturalPalette = inheritedPalette.resolve(naturalPalette); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4418 |
} |
0 | 4419 |
#endif //QT_NO_GRAPHICSVIEW |
4420 |
} |
|
4421 |
naturalPalette.resolve(0); |
|
4422 |
return naturalPalette; |
|
4423 |
} |
|
4424 |
/*! |
|
4425 |
\internal |
|
4426 |
||
4427 |
Determine which palette is inherited from this widget's ancestors and |
|
4428 |
QApplication::palette, resolve this against this widget's palette |
|
4429 |
(attributes from the inherited palette are copied over this widget's |
|
4430 |
palette). Then propagate this palette to this widget's children. |
|
4431 |
*/ |
|
4432 |
void QWidgetPrivate::resolvePalette() |
|
4433 |
{ |
|
4434 |
QPalette naturalPalette = naturalWidgetPalette(inheritedPaletteResolveMask); |
|
4435 |
QPalette resolvedPalette = data.pal.resolve(naturalPalette); |
|
4436 |
setPalette_helper(resolvedPalette); |
|
4437 |
} |
|
4438 |
||
4439 |
void QWidgetPrivate::setPalette_helper(const QPalette &palette) |
|
4440 |
{ |
|
4441 |
Q_Q(QWidget); |
|
4442 |
if (data.pal == palette && data.pal.resolve() == palette.resolve()) |
|
4443 |
return; |
|
4444 |
data.pal = palette; |
|
4445 |
updateSystemBackground(); |
|
4446 |
propagatePaletteChange(); |
|
4447 |
updateIsOpaque(); |
|
4448 |
q->update(); |
|
4449 |
updateIsOpaque(); |
|
4450 |
} |
|
4451 |
||
4452 |
/*! |
|
4453 |
\property QWidget::font |
|
4454 |
\brief the font currently set for the widget |
|
4455 |
||
4456 |
This property describes the widget's requested font. The font is used by |
|
4457 |
the widget's style when rendering standard components, and is available as |
|
4458 |
a means to ensure that custom widgets can maintain consistency with the |
|
4459 |
native platform's look and feel. It's common that different platforms, or |
|
4460 |
different styles, define different fonts for an application. |
|
4461 |
||
4462 |
When you assign a new font to a widget, the properties from this font are |
|
4463 |
combined with the widget's default font to form the widget's final |
|
4464 |
font. You can call fontInfo() to get a copy of the widget's final |
|
4465 |
font. The final font is also used to initialize QPainter's font. |
|
4466 |
||
4467 |
The default depends on the system environment. QApplication maintains a |
|
4468 |
system/theme font which serves as a default for all widgets. There may |
|
4469 |
also be special font defaults for certain types of widgets. You can also |
|
4470 |
define default fonts for widgets yourself by passing a custom font and the |
|
4471 |
name of a widget to QApplication::setFont(). Finally, the font is matched |
|
4472 |
against Qt's font database to find the best match. |
|
4473 |
||
4474 |
QWidget propagates explicit font properties from parent to child. If you |
|
4475 |
change a specific property on a font and assign that font to a widget, |
|
4476 |
that property will propagate to all the widget's children, overriding any |
|
4477 |
system defaults for that property. Note that fonts by default don't |
|
4478 |
propagate to windows (see isWindow()) unless the Qt::WA_WindowPropagation |
|
4479 |
attribute is enabled. |
|
4480 |
||
4481 |
QWidget's font propagation is similar to its palette propagation. |
|
4482 |
||
4483 |
The current style, which is used to render the content of all standard Qt |
|
4484 |
widgets, is free to choose to use the widget font, or in some cases, to |
|
4485 |
ignore it (partially, or completely). In particular, certain styles like |
|
4486 |
GTK style, Mac style, Windows XP, and Vista style, apply special |
|
4487 |
modifications to the widget font to match the platform's native look and |
|
4488 |
feel. Because of this, assigning properties to a widget's font is not |
|
4489 |
guaranteed to change the appearance of the widget. Instead, you may choose |
|
4490 |
to apply a \l styleSheet. |
|
4491 |
||
4492 |
\note If \l{Qt Style Sheets} are used on the same widget as setFont(), |
|
4493 |
style sheets will take precedence if the settings conflict. |
|
4494 |
||
4495 |
\sa fontInfo(), fontMetrics() |
|
4496 |
*/ |
|
4497 |
||
4498 |
void QWidget::setFont(const QFont &font) |
|
4499 |
{ |
|
4500 |
Q_D(QWidget); |
|
4501 |
||
4502 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
4503 |
const QStyleSheetStyle* style; |
|
4504 |
if (d->extra && (style = qobject_cast<const QStyleSheetStyle*>(d->extra->style))) { |
|
4505 |
style->saveWidgetFont(this, font); |
|
4506 |
} |
|
4507 |
#endif |
|
4508 |
||
4509 |
setAttribute(Qt::WA_SetFont, font.resolve() != 0); |
|
4510 |
||
4511 |
// Determine which font is inherited from this widget's ancestors and |
|
4512 |
// QApplication::font, resolve this against \a font (attributes from the |
|
4513 |
// inherited font are copied over). Then propagate this font to this |
|
4514 |
// widget's children. |
|
4515 |
QFont naturalFont = d->naturalWidgetFont(d->inheritedFontResolveMask); |
|
4516 |
QFont resolvedFont = font.resolve(naturalFont); |
|
4517 |
d->setFont_helper(resolvedFont); |
|
4518 |
} |
|
4519 |
||
4520 |
/* |
|
4521 |
\internal |
|
4522 |
||
4523 |
Returns the font that the widget \a w inherits from its ancestors and |
|
4524 |
QApplication::font. \a inheritedMask is the combination of the widget's |
|
4525 |
ancestors font request masks (i.e., which attributes from the parent |
|
4526 |
widget's font are implicitly imposed on this widget by the user). Note |
|
4527 |
that this font does not take into account the font set on \a w itself. |
|
4528 |
||
4529 |
### Stylesheet has a different font propagation mechanism. When a stylesheet |
|
4530 |
is applied, fonts are not propagated anymore |
|
4531 |
*/ |
|
4532 |
QFont QWidgetPrivate::naturalWidgetFont(uint inheritedMask) const |
|
4533 |
{ |
|
4534 |
Q_Q(const QWidget); |
|
4535 |
QFont naturalFont = QApplication::font(q); |
|
4536 |
if (!q->testAttribute(Qt::WA_StyleSheet) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4537 |
&& (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4538 |
#ifndef QT_NO_GRAPHICSVIEW |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4539 |
|| (extra && extra->proxyWidget) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4540 |
#endif //QT_NO_GRAPHICSVIEW |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4541 |
)) { |
0 | 4542 |
if (QWidget *p = q->parentWidget()) { |
4543 |
if (!p->testAttribute(Qt::WA_StyleSheet)) { |
|
4544 |
if (!naturalFont.isCopyOf(QApplication::font())) { |
|
4545 |
QFont inheritedFont = p->font(); |
|
4546 |
inheritedFont.resolve(inheritedMask); |
|
4547 |
naturalFont = inheritedFont.resolve(naturalFont); |
|
4548 |
} else { |
|
4549 |
naturalFont = p->font(); |
|
4550 |
} |
|
4551 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4552 |
} |
0 | 4553 |
#ifndef QT_NO_GRAPHICSVIEW |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4554 |
else if (extra && extra->proxyWidget) { |
0 | 4555 |
QFont inheritedFont = extra->proxyWidget->font(); |
4556 |
inheritedFont.resolve(inheritedMask); |
|
4557 |
naturalFont = inheritedFont.resolve(naturalFont); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4558 |
} |
0 | 4559 |
#endif //QT_NO_GRAPHICSVIEW |
4560 |
} |
|
4561 |
naturalFont.resolve(0); |
|
4562 |
return naturalFont; |
|
4563 |
} |
|
4564 |
||
4565 |
/*! |
|
4566 |
\internal |
|
4567 |
||
4568 |
Determine which font is implicitly imposed on this widget by its ancestors |
|
4569 |
and QApplication::font, resolve this against its own font (attributes from |
|
4570 |
the implicit font are copied over). Then propagate this font to this |
|
4571 |
widget's children. |
|
4572 |
*/ |
|
4573 |
void QWidgetPrivate::resolveFont() |
|
4574 |
{ |
|
4575 |
QFont naturalFont = naturalWidgetFont(inheritedFontResolveMask); |
|
4576 |
QFont resolvedFont = data.fnt.resolve(naturalFont); |
|
4577 |
setFont_helper(resolvedFont); |
|
4578 |
} |
|
4579 |
||
4580 |
/*! |
|
4581 |
\internal |
|
4582 |
||
4583 |
Assign \a font to this widget, and propagate it to all children, except |
|
4584 |
style sheet widgets (handled differently) and windows that don't enable |
|
4585 |
window propagation. \a implicitMask is the union of all ancestor widgets' |
|
4586 |
font request masks, and determines which attributes from this widget's |
|
4587 |
font should propagate. |
|
4588 |
*/ |
|
4589 |
void QWidgetPrivate::updateFont(const QFont &font) |
|
4590 |
{ |
|
4591 |
Q_Q(QWidget); |
|
4592 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
4593 |
const QStyleSheetStyle* cssStyle; |
|
4594 |
cssStyle = extra ? qobject_cast<const QStyleSheetStyle*>(extra->style) : 0; |
|
4595 |
#endif |
|
4596 |
||
4597 |
#ifdef QT3_SUPPORT |
|
4598 |
QFont old = data.fnt; |
|
4599 |
#endif |
|
4600 |
data.fnt = QFont(font, q); |
|
4601 |
#if defined(Q_WS_X11) |
|
4602 |
// make sure the font set on this widget is associated with the correct screen |
|
4603 |
data.fnt.x11SetScreen(xinfo.screen()); |
|
4604 |
#endif |
|
4605 |
// Combine new mask with natural mask and propagate to children. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4606 |
#ifndef QT_NO_GRAPHICSVIEW |
0 | 4607 |
if (!q->parentWidget() && extra && extra->proxyWidget) { |
4608 |
QGraphicsProxyWidget *p = extra->proxyWidget; |
|
4609 |
inheritedFontResolveMask = p->d_func()->inheritedFontResolveMask | p->font().resolve(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4610 |
} else |
0 | 4611 |
#endif //QT_NO_GRAPHICSVIEW |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4612 |
if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) { |
0 | 4613 |
inheritedFontResolveMask = 0; |
4614 |
} |
|
4615 |
uint newMask = data.fnt.resolve() | inheritedFontResolveMask; |
|
4616 |
||
4617 |
for (int i = 0; i < children.size(); ++i) { |
|
4618 |
QWidget *w = qobject_cast<QWidget*>(children.at(i)); |
|
4619 |
if (w) { |
|
4620 |
if (0) { |
|
4621 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
4622 |
} else if (w->testAttribute(Qt::WA_StyleSheet)) { |
|
4623 |
// Style sheets follow a different font propagation scheme. |
|
4624 |
if (cssStyle) |
|
4625 |
cssStyle->updateStyleSheetFont(w); |
|
4626 |
#endif |
|
4627 |
} else if ((!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) { |
|
4628 |
// Propagate font changes. |
|
4629 |
QWidgetPrivate *wd = w->d_func(); |
|
4630 |
wd->inheritedFontResolveMask = newMask; |
|
4631 |
wd->resolveFont(); |
|
4632 |
} |
|
4633 |
} |
|
4634 |
} |
|
4635 |
||
4636 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
4637 |
if (cssStyle) { |
|
4638 |
cssStyle->updateStyleSheetFont(q); |
|
4639 |
} |
|
4640 |
#endif |
|
4641 |
||
4642 |
QEvent e(QEvent::FontChange); |
|
4643 |
QApplication::sendEvent(q, &e); |
|
4644 |
#ifdef QT3_SUPPORT |
|
4645 |
q->fontChange(old); |
|
4646 |
#endif |
|
4647 |
} |
|
4648 |
||
4649 |
void QWidgetPrivate::setLayoutDirection_helper(Qt::LayoutDirection direction) |
|
4650 |
{ |
|
4651 |
Q_Q(QWidget); |
|
4652 |
||
4653 |
if ( (direction == Qt::RightToLeft) == q->testAttribute(Qt::WA_RightToLeft)) |
|
4654 |
return; |
|
4655 |
q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft)); |
|
4656 |
if (!children.isEmpty()) { |
|
4657 |
for (int i = 0; i < children.size(); ++i) { |
|
4658 |
QWidget *w = qobject_cast<QWidget*>(children.at(i)); |
|
4659 |
if (w && !w->isWindow() && !w->testAttribute(Qt::WA_SetLayoutDirection)) |
|
4660 |
w->d_func()->setLayoutDirection_helper(direction); |
|
4661 |
} |
|
4662 |
} |
|
4663 |
QEvent e(QEvent::LayoutDirectionChange); |
|
4664 |
QApplication::sendEvent(q, &e); |
|
4665 |
} |
|
4666 |
||
4667 |
void QWidgetPrivate::resolveLayoutDirection() |
|
4668 |
{ |
|
4669 |
Q_Q(const QWidget); |
|
4670 |
if (!q->testAttribute(Qt::WA_SetLayoutDirection)) |
|
4671 |
setLayoutDirection_helper(q->isWindow() ? QApplication::layoutDirection() : q->parentWidget()->layoutDirection()); |
|
4672 |
} |
|
4673 |
||
4674 |
/*! |
|
4675 |
\property QWidget::layoutDirection |
|
4676 |
||
4677 |
\brief the layout direction for this widget |
|
4678 |
||
4679 |
By default, this property is set to Qt::LeftToRight. |
|
4680 |
||
4681 |
When the layout direction is set on a widget, it will propagate to |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4682 |
the widget's children, but not to a child that is a window and not |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4683 |
to a child for which setLayoutDirection() has been explicitly |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4684 |
called. Also, child widgets added \e after setLayoutDirection() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4685 |
has been called for the parent do not inherit the parent's layout |
0 | 4686 |
direction. |
4687 |
||
4688 |
\sa QApplication::layoutDirection |
|
4689 |
*/ |
|
4690 |
void QWidget::setLayoutDirection(Qt::LayoutDirection direction) |
|
4691 |
{ |
|
4692 |
Q_D(QWidget); |
|
4693 |
||
4694 |
setAttribute(Qt::WA_SetLayoutDirection); |
|
4695 |
d->setLayoutDirection_helper(direction); |
|
4696 |
} |
|
4697 |
||
4698 |
Qt::LayoutDirection QWidget::layoutDirection() const |
|
4699 |
{ |
|
4700 |
return testAttribute(Qt::WA_RightToLeft) ? Qt::RightToLeft : Qt::LeftToRight; |
|
4701 |
} |
|
4702 |
||
4703 |
void QWidget::unsetLayoutDirection() |
|
4704 |
{ |
|
4705 |
Q_D(QWidget); |
|
4706 |
setAttribute(Qt::WA_SetLayoutDirection, false); |
|
4707 |
d->resolveLayoutDirection(); |
|
4708 |
} |
|
4709 |
||
4710 |
/*! |
|
4711 |
\fn QFontMetrics QWidget::fontMetrics() const |
|
4712 |
||
4713 |
Returns the font metrics for the widget's current font. |
|
4714 |
Equivalent to QFontMetrics(widget->font()). |
|
4715 |
||
4716 |
\sa font(), fontInfo(), setFont() |
|
4717 |
*/ |
|
4718 |
||
4719 |
/*! |
|
4720 |
\fn QFontInfo QWidget::fontInfo() const |
|
4721 |
||
4722 |
Returns the font info for the widget's current font. |
|
4723 |
Equivalent to QFontInto(widget->font()). |
|
4724 |
||
4725 |
\sa font(), fontMetrics(), setFont() |
|
4726 |
*/ |
|
4727 |
||
4728 |
||
4729 |
/*! |
|
4730 |
\property QWidget::cursor |
|
4731 |
\brief the cursor shape for this widget |
|
4732 |
||
4733 |
The mouse cursor will assume this shape when it's over this |
|
4734 |
widget. See the \link Qt::CursorShape list of predefined cursor |
|
4735 |
objects\endlink for a range of useful shapes. |
|
4736 |
||
4737 |
An editor widget might use an I-beam cursor: |
|
4738 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 6 |
|
4739 |
||
4740 |
If no cursor has been set, or after a call to unsetCursor(), the |
|
4741 |
parent's cursor is used. |
|
4742 |
||
4743 |
By default, this property contains a cursor with the Qt::ArrowCursor |
|
4744 |
shape. |
|
4745 |
||
4746 |
Some underlying window implementations will reset the cursor if it |
|
4747 |
leaves a widget even if the mouse is grabbed. If you want to have |
|
4748 |
a cursor set for all widgets, even when outside the window, consider |
|
4749 |
QApplication::setOverrideCursor(). |
|
4750 |
||
4751 |
\sa QApplication::setOverrideCursor() |
|
4752 |
*/ |
|
4753 |
||
4754 |
#ifndef QT_NO_CURSOR |
|
4755 |
QCursor QWidget::cursor() const |
|
4756 |
{ |
|
4757 |
Q_D(const QWidget); |
|
4758 |
if (testAttribute(Qt::WA_SetCursor)) |
|
4759 |
return (d->extra && d->extra->curs) |
|
4760 |
? *d->extra->curs |
|
4761 |
: QCursor(Qt::ArrowCursor); |
|
4762 |
if (isWindow() || !parentWidget()) |
|
4763 |
return QCursor(Qt::ArrowCursor); |
|
4764 |
return parentWidget()->cursor(); |
|
4765 |
} |
|
4766 |
||
4767 |
void QWidget::setCursor(const QCursor &cursor) |
|
4768 |
{ |
|
4769 |
Q_D(QWidget); |
|
4770 |
// On Mac we must set the cursor even if it is the ArrowCursor. |
|
4771 |
#if !defined(Q_WS_MAC) && !defined(Q_WS_QWS) |
|
4772 |
if (cursor.shape() != Qt::ArrowCursor |
|
4773 |
|| (d->extra && d->extra->curs)) |
|
4774 |
#endif |
|
4775 |
{ |
|
4776 |
d->createExtra(); |
|
4777 |
QCursor *newCursor = new QCursor(cursor); |
|
4778 |
delete d->extra->curs; |
|
4779 |
d->extra->curs = newCursor; |
|
4780 |
} |
|
4781 |
setAttribute(Qt::WA_SetCursor); |
|
4782 |
d->setCursor_sys(cursor); |
|
4783 |
||
4784 |
QEvent event(QEvent::CursorChange); |
|
4785 |
QApplication::sendEvent(this, &event); |
|
4786 |
} |
|
4787 |
||
4788 |
void QWidget::unsetCursor() |
|
4789 |
{ |
|
4790 |
Q_D(QWidget); |
|
4791 |
if (d->extra) { |
|
4792 |
delete d->extra->curs; |
|
4793 |
d->extra->curs = 0; |
|
4794 |
} |
|
4795 |
if (!isWindow()) |
|
4796 |
setAttribute(Qt::WA_SetCursor, false); |
|
4797 |
d->unsetCursor_sys(); |
|
4798 |
||
4799 |
QEvent event(QEvent::CursorChange); |
|
4800 |
QApplication::sendEvent(this, &event); |
|
4801 |
} |
|
4802 |
||
4803 |
#endif |
|
4804 |
||
4805 |
/*! |
|
4806 |
\enum QWidget::RenderFlag |
|
4807 |
||
4808 |
This enum describes how to render the widget when calling QWidget::render(). |
|
4809 |
||
4810 |
\value DrawWindowBackground If you enable this option, the widget's background |
|
4811 |
is rendered into the target even if autoFillBackground is not set. By default, |
|
4812 |
this option is enabled. |
|
4813 |
||
4814 |
\value DrawChildren If you enable this option, the widget's children |
|
4815 |
are rendered recursively into the target. By default, this option is enabled. |
|
4816 |
||
4817 |
\value IgnoreMask If you enable this option, the widget's QWidget::mask() |
|
4818 |
is ignored when rendering into the target. By default, this option is disabled. |
|
4819 |
||
4820 |
\since 4.3 |
|
4821 |
*/ |
|
4822 |
||
4823 |
/*! |
|
4824 |
\since 4.3 |
|
4825 |
||
4826 |
Renders the \a sourceRegion of this widget into the \a target |
|
4827 |
using \a renderFlags to determine how to render. Rendering |
|
4828 |
starts at \a targetOffset in the \a target. For example: |
|
4829 |
||
4830 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 7 |
|
4831 |
||
4832 |
If \a sourceRegion is a null region, this function will use QWidget::rect() as |
|
4833 |
the region, i.e. the entire widget. |
|
4834 |
||
4835 |
Ensure that you call QPainter::end() for the \a target device's |
|
4836 |
active painter (if any) before rendering. For example: |
|
4837 |
||
4838 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 8 |
|
4839 |
||
4840 |
\note To obtain the contents of an OpenGL widget, use QGLWidget::grabFrameBuffer() |
|
4841 |
or QGLWidget::renderPixmap() instead. |
|
4842 |
*/ |
|
4843 |
void QWidget::render(QPaintDevice *target, const QPoint &targetOffset, |
|
4844 |
const QRegion &sourceRegion, RenderFlags renderFlags) |
|
4845 |
{ |
|
4846 |
Q_D(QWidget); |
|
4847 |
if (!target) { |
|
4848 |
qWarning("QWidget::render: null pointer to paint device"); |
|
4849 |
return; |
|
4850 |
} |
|
4851 |
||
4852 |
const bool inRenderWithPainter = d->extra && d->extra->inRenderWithPainter; |
|
4853 |
QRegion paintRegion = !inRenderWithPainter ? d->prepareToRender(sourceRegion, renderFlags) |
|
4854 |
: sourceRegion; |
|
4855 |
if (paintRegion.isEmpty()) |
|
4856 |
return; |
|
4857 |
||
4858 |
#ifndef Q_WS_MAC |
|
4859 |
QPainter *oldSharedPainter = inRenderWithPainter ? d->sharedPainter() : 0; |
|
4860 |
||
4861 |
// Use the target's shared painter if set (typically set when doing |
|
4862 |
// "other->render(widget);" in the widget's paintEvent. |
|
4863 |
if (target->devType() == QInternal::Widget) { |
|
4864 |
QWidgetPrivate *targetPrivate = static_cast<QWidget *>(target)->d_func(); |
|
4865 |
if (targetPrivate->extra && targetPrivate->extra->inRenderWithPainter) { |
|
4866 |
QPainter *targetPainter = targetPrivate->sharedPainter(); |
|
4867 |
if (targetPainter && targetPainter->isActive()) |
|
4868 |
d->setSharedPainter(targetPainter); |
|
4869 |
} |
|
4870 |
} |
|
4871 |
#endif |
|
4872 |
||
4873 |
// Use the target's redirected device if set and adjust offset and paint |
|
4874 |
// region accordingly. This is typically the case when people call render |
|
4875 |
// from the paintEvent. |
|
4876 |
QPoint offset = targetOffset; |
|
4877 |
offset -= paintRegion.boundingRect().topLeft(); |
|
4878 |
QPoint redirectionOffset; |
|
4879 |
QPaintDevice *redirected = 0; |
|
4880 |
||
4881 |
if (target->devType() == QInternal::Widget) |
|
4882 |
redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset); |
|
4883 |
if (!redirected) |
|
4884 |
redirected = QPainter::redirected(target, &redirectionOffset); |
|
4885 |
||
4886 |
if (redirected) { |
|
4887 |
target = redirected; |
|
4888 |
offset -= redirectionOffset; |
|
4889 |
} |
|
4890 |
||
4891 |
if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp). |
|
4892 |
if (QPaintEngine *targetEngine = target->paintEngine()) { |
|
4893 |
const QRegion targetSystemClip = targetEngine->systemClip(); |
|
4894 |
if (!targetSystemClip.isEmpty()) |
|
4895 |
paintRegion &= targetSystemClip.translated(-offset); |
|
4896 |
} |
|
4897 |
} |
|
4898 |
||
4899 |
// Set backingstore flags. |
|
4900 |
int flags = QWidgetPrivate::DrawPaintOnScreen | QWidgetPrivate::DrawInvisible; |
|
4901 |
if (renderFlags & DrawWindowBackground) |
|
4902 |
flags |= QWidgetPrivate::DrawAsRoot; |
|
4903 |
||
4904 |
if (renderFlags & DrawChildren) |
|
4905 |
flags |= QWidgetPrivate::DrawRecursive; |
|
4906 |
else |
|
4907 |
flags |= QWidgetPrivate::DontSubtractOpaqueChildren; |
|
4908 |
||
4909 |
#ifdef Q_WS_QWS |
|
4910 |
flags |= QWidgetPrivate::DontSetCompositionMode; |
|
4911 |
#endif |
|
4912 |
||
4913 |
if (target->devType() == QInternal::Printer) { |
|
4914 |
QPainter p(target); |
|
4915 |
d->render_helper(&p, targetOffset, paintRegion, renderFlags); |
|
4916 |
return; |
|
4917 |
} |
|
4918 |
||
4919 |
#ifndef Q_WS_MAC |
|
4920 |
// Render via backingstore. |
|
4921 |
d->drawWidget(target, paintRegion, offset, flags, d->sharedPainter()); |
|
4922 |
||
4923 |
// Restore shared painter. |
|
4924 |
if (oldSharedPainter) |
|
4925 |
d->setSharedPainter(oldSharedPainter); |
|
4926 |
#else |
|
4927 |
// Render via backingstore (no shared painter). |
|
4928 |
d->drawWidget(target, paintRegion, offset, flags, 0); |
|
4929 |
#endif |
|
4930 |
} |
|
4931 |
||
4932 |
/*! |
|
4933 |
\overload |
|
4934 |
||
4935 |
Renders the widget into the \a painter's QPainter::device(). |
|
4936 |
||
4937 |
Transformations and settings applied to the \a painter will be used |
|
4938 |
when rendering. |
|
4939 |
||
4940 |
\note The \a painter must be active. On Mac OS X the widget will be |
|
4941 |
rendered into a QPixmap and then drawn by the \a painter. |
|
4942 |
||
4943 |
\sa QPainter::device() |
|
4944 |
*/ |
|
4945 |
void QWidget::render(QPainter *painter, const QPoint &targetOffset, |
|
4946 |
const QRegion &sourceRegion, RenderFlags renderFlags) |
|
4947 |
{ |
|
4948 |
if (!painter) { |
|
4949 |
qWarning("QWidget::render: Null pointer to painter"); |
|
4950 |
return; |
|
4951 |
} |
|
4952 |
||
4953 |
if (!painter->isActive()) { |
|
4954 |
qWarning("QWidget::render: Cannot render with an inactive painter"); |
|
4955 |
return; |
|
4956 |
} |
|
4957 |
||
4958 |
const qreal opacity = painter->opacity(); |
|
4959 |
if (qFuzzyIsNull(opacity)) |
|
4960 |
return; // Fully transparent. |
|
4961 |
||
4962 |
Q_D(QWidget); |
|
4963 |
const bool inRenderWithPainter = d->extra && d->extra->inRenderWithPainter; |
|
4964 |
const QRegion toBePainted = !inRenderWithPainter ? d->prepareToRender(sourceRegion, renderFlags) |
|
4965 |
: sourceRegion; |
|
4966 |
if (toBePainted.isEmpty()) |
|
4967 |
return; |
|
4968 |
||
4969 |
if (!d->extra) |
|
4970 |
d->createExtra(); |
|
4971 |
d->extra->inRenderWithPainter = true; |
|
4972 |
||
4973 |
#ifdef Q_WS_MAC |
|
4974 |
d->render_helper(painter, targetOffset, toBePainted, renderFlags); |
|
4975 |
#else |
|
4976 |
QPaintEngine *engine = painter->paintEngine(); |
|
4977 |
Q_ASSERT(engine); |
|
4978 |
QPaintEnginePrivate *enginePriv = engine->d_func(); |
|
4979 |
Q_ASSERT(enginePriv); |
|
4980 |
QPaintDevice *target = engine->paintDevice(); |
|
4981 |
Q_ASSERT(target); |
|
4982 |
||
4983 |
// Render via a pixmap when dealing with non-opaque painters or printers. |
|
4984 |
if (!inRenderWithPainter && (opacity < 1.0 || (target->devType() == QInternal::Printer))) { |
|
4985 |
d->render_helper(painter, targetOffset, toBePainted, renderFlags); |
|
4986 |
d->extra->inRenderWithPainter = false; |
|
4987 |
return; |
|
4988 |
} |
|
4989 |
||
4990 |
// Set new shared painter. |
|
4991 |
QPainter *oldPainter = d->sharedPainter(); |
|
4992 |
d->setSharedPainter(painter); |
|
4993 |
||
4994 |
// Save current system clip, viewport and transform, |
|
4995 |
const QTransform oldTransform = enginePriv->systemTransform; |
|
4996 |
const QRegion oldSystemClip = enginePriv->systemClip; |
|
4997 |
const QRegion oldSystemViewport = enginePriv->systemViewport; |
|
4998 |
||
4999 |
// This ensures that all painting triggered by render() is clipped to the current engine clip. |
|
5000 |
if (painter->hasClipping()) { |
|
5001 |
const QRegion painterClip = painter->deviceTransform().map(painter->clipRegion()); |
|
5002 |
enginePriv->setSystemViewport(oldSystemClip.isEmpty() ? painterClip : oldSystemClip & painterClip); |
|
5003 |
} else { |
|
5004 |
enginePriv->setSystemViewport(oldSystemClip); |
|
5005 |
} |
|
5006 |
||
5007 |
render(target, targetOffset, toBePainted, renderFlags); |
|
5008 |
||
5009 |
// Restore system clip, viewport and transform. |
|
5010 |
enginePriv->systemClip = oldSystemClip; |
|
5011 |
enginePriv->setSystemViewport(oldSystemViewport); |
|
5012 |
enginePriv->setSystemTransform(oldTransform); |
|
5013 |
||
5014 |
// Restore shared painter. |
|
5015 |
d->setSharedPainter(oldPainter); |
|
5016 |
#endif |
|
5017 |
||
5018 |
d->extra->inRenderWithPainter = false; |
|
5019 |
} |
|
5020 |
||
5021 |
/*! |
|
5022 |
\brief The graphicsEffect function returns a pointer to the |
|
5023 |
widget's graphics effect. |
|
5024 |
||
5025 |
If the widget has no graphics effect, 0 is returned. |
|
5026 |
||
5027 |
\since 4.6 |
|
5028 |
||
5029 |
\sa setGraphicsEffect() |
|
5030 |
*/ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5031 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 5032 |
QGraphicsEffect *QWidget::graphicsEffect() const |
5033 |
{ |
|
5034 |
Q_D(const QWidget); |
|
5035 |
return d->graphicsEffect; |
|
5036 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5037 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 5038 |
|
5039 |
/*! |
|
5040 |
||
5041 |
\brief The setGraphicsEffect function is for setting the widget's graphics effect. |
|
5042 |
||
5043 |
Sets \a effect as the widget's effect. If there already is an effect installed |
|
5044 |
on this widget, QWidget will delete the existing effect before installing |
|
5045 |
the new \a effect. |
|
5046 |
||
5047 |
If \a effect is the installed on a different widget, setGraphicsEffect() will remove |
|
5048 |
the effect from the widget and install it on this widget. |
|
5049 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5050 |
QWidget takes ownership of \a effect. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5051 |
|
0 | 5052 |
\note This function will apply the effect on itself and all its children. |
5053 |
||
5054 |
\since 4.6 |
|
5055 |
||
5056 |
\sa graphicsEffect() |
|
5057 |
*/ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5058 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 5059 |
void QWidget::setGraphicsEffect(QGraphicsEffect *effect) |
5060 |
{ |
|
5061 |
Q_D(QWidget); |
|
5062 |
if (d->graphicsEffect == effect) |
|
5063 |
return; |
|
5064 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5065 |
if (d->graphicsEffect) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5066 |
d->invalidateBuffer(rect()); |
0 | 5067 |
delete d->graphicsEffect; |
5068 |
d->graphicsEffect = 0; |
|
5069 |
} |
|
5070 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5071 |
if (effect) { |
0 | 5072 |
// Set new effect. |
5073 |
QGraphicsEffectSourcePrivate *sourced = new QWidgetEffectSourcePrivate(this); |
|
5074 |
QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced); |
|
5075 |
d->graphicsEffect = effect; |
|
5076 |
effect->d_func()->setGraphicsEffectSource(source); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5077 |
update(); |
0 | 5078 |
} |
5079 |
||
5080 |
d->updateIsOpaque(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5081 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5082 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 5083 |
|
5084 |
bool QWidgetPrivate::isAboutToShow() const |
|
5085 |
{ |
|
5086 |
if (data.in_show) |
|
5087 |
return true; |
|
5088 |
||
5089 |
Q_Q(const QWidget); |
|
5090 |
if (q->isHidden()) |
|
5091 |
return false; |
|
5092 |
||
5093 |
// The widget will be shown if any of its ancestors are about to show. |
|
5094 |
QWidget *parent = q->parentWidget(); |
|
5095 |
return parent ? parent->d_func()->isAboutToShow() : false; |
|
5096 |
} |
|
5097 |
||
5098 |
QRegion QWidgetPrivate::prepareToRender(const QRegion ®ion, QWidget::RenderFlags renderFlags) |
|
5099 |
{ |
|
5100 |
Q_Q(QWidget); |
|
5101 |
const bool isVisible = q->isVisible(); |
|
5102 |
||
5103 |
// Make sure the widget is laid out correctly. |
|
5104 |
if (!isVisible && !isAboutToShow()) { |
|
5105 |
QWidget *topLevel = q->window(); |
|
5106 |
(void)topLevel->d_func()->topData(); // Make sure we at least have top-data. |
|
5107 |
topLevel->ensurePolished(); |
|
5108 |
||
5109 |
// Invalidate the layout of hidden ancestors (incl. myself) and pretend |
|
5110 |
// they're not explicitly hidden. |
|
5111 |
QWidget *widget = q; |
|
5112 |
QWidgetList hiddenWidgets; |
|
5113 |
while (widget) { |
|
5114 |
if (widget->isHidden()) { |
|
5115 |
widget->setAttribute(Qt::WA_WState_Hidden, false); |
|
5116 |
hiddenWidgets.append(widget); |
|
5117 |
if (!widget->isWindow() && widget->parentWidget()->d_func()->layout) |
|
5118 |
widget->d_func()->updateGeometry_helper(true); |
|
5119 |
} |
|
5120 |
widget = widget->parentWidget(); |
|
5121 |
} |
|
5122 |
||
5123 |
// Activate top-level layout. |
|
5124 |
if (topLevel->d_func()->layout) |
|
5125 |
topLevel->d_func()->layout->activate(); |
|
5126 |
||
5127 |
// Adjust size if necessary. |
|
5128 |
QTLWExtra *topLevelExtra = topLevel->d_func()->maybeTopData(); |
|
5129 |
if (topLevelExtra && !topLevelExtra->sizeAdjusted |
|
5130 |
&& !topLevel->testAttribute(Qt::WA_Resized)) { |
|
5131 |
topLevel->adjustSize(); |
|
5132 |
topLevel->setAttribute(Qt::WA_Resized, false); |
|
5133 |
} |
|
5134 |
||
5135 |
// Activate child layouts. |
|
5136 |
topLevel->d_func()->activateChildLayoutsRecursively(); |
|
5137 |
||
5138 |
// We're not cheating with WA_WState_Hidden anymore. |
|
5139 |
for (int i = 0; i < hiddenWidgets.size(); ++i) { |
|
5140 |
QWidget *widget = hiddenWidgets.at(i); |
|
5141 |
widget->setAttribute(Qt::WA_WState_Hidden); |
|
5142 |
if (!widget->isWindow() && widget->parentWidget()->d_func()->layout) |
|
5143 |
widget->parentWidget()->d_func()->layout->invalidate(); |
|
5144 |
} |
|
5145 |
} else if (isVisible) { |
|
5146 |
q->window()->d_func()->sendPendingMoveAndResizeEvents(true, true); |
|
5147 |
} |
|
5148 |
||
5149 |
// Calculate the region to be painted. |
|
5150 |
QRegion toBePainted = !region.isEmpty() ? region : QRegion(q->rect()); |
|
5151 |
if (!(renderFlags & QWidget::IgnoreMask) && extra && extra->hasMask) |
|
5152 |
toBePainted &= extra->mask; |
|
5153 |
return toBePainted; |
|
5154 |
} |
|
5155 |
||
5156 |
void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &toBePainted, |
|
5157 |
QWidget::RenderFlags renderFlags) |
|
5158 |
{ |
|
5159 |
Q_ASSERT(painter); |
|
5160 |
Q_ASSERT(!toBePainted.isEmpty()); |
|
5161 |
||
5162 |
Q_Q(QWidget); |
|
5163 |
#ifndef Q_WS_MAC |
|
5164 |
const QTransform originalTransform = painter->worldTransform(); |
|
5165 |
const bool useDeviceCoordinates = originalTransform.isScaling(); |
|
5166 |
if (!useDeviceCoordinates) { |
|
5167 |
#endif |
|
5168 |
// Render via a pixmap. |
|
5169 |
const QRect rect = toBePainted.boundingRect(); |
|
5170 |
const QSize size = rect.size(); |
|
5171 |
if (size.isNull()) |
|
5172 |
return; |
|
5173 |
||
5174 |
QPixmap pixmap(size); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5175 |
if (!(renderFlags & QWidget::DrawWindowBackground) || !isOpaque) |
0 | 5176 |
pixmap.fill(Qt::transparent); |
5177 |
q->render(&pixmap, QPoint(), toBePainted, renderFlags); |
|
5178 |
||
5179 |
const bool restore = !(painter->renderHints() & QPainter::SmoothPixmapTransform); |
|
5180 |
painter->setRenderHints(QPainter::SmoothPixmapTransform, true); |
|
5181 |
||
5182 |
painter->drawPixmap(targetOffset, pixmap); |
|
5183 |
||
5184 |
if (restore) |
|
5185 |
painter->setRenderHints(QPainter::SmoothPixmapTransform, false); |
|
5186 |
||
5187 |
#ifndef Q_WS_MAC |
|
5188 |
} else { |
|
5189 |
// Render via a pixmap in device coordinates (to avoid pixmap scaling). |
|
5190 |
QTransform transform = originalTransform; |
|
5191 |
transform.translate(targetOffset.x(), targetOffset.y()); |
|
5192 |
||
5193 |
QPaintDevice *device = painter->device(); |
|
5194 |
Q_ASSERT(device); |
|
5195 |
||
5196 |
// Calculate device rect. |
|
5197 |
const QRectF rect(toBePainted.boundingRect()); |
|
5198 |
QRect deviceRect = transform.mapRect(QRectF(0, 0, rect.width(), rect.height())).toAlignedRect(); |
|
5199 |
deviceRect &= QRect(0, 0, device->width(), device->height()); |
|
5200 |
||
5201 |
QPixmap pixmap(deviceRect.size()); |
|
5202 |
pixmap.fill(Qt::transparent); |
|
5203 |
||
5204 |
// Create a pixmap device coordinate painter. |
|
5205 |
QPainter pixmapPainter(&pixmap); |
|
5206 |
pixmapPainter.setRenderHints(painter->renderHints()); |
|
5207 |
transform *= QTransform::fromTranslate(-deviceRect.x(), -deviceRect.y()); |
|
5208 |
pixmapPainter.setTransform(transform); |
|
5209 |
||
5210 |
q->render(&pixmapPainter, QPoint(), toBePainted, renderFlags); |
|
5211 |
pixmapPainter.end(); |
|
5212 |
||
5213 |
// And then draw the pixmap. |
|
5214 |
painter->setTransform(QTransform()); |
|
5215 |
painter->drawPixmap(deviceRect.topLeft(), pixmap); |
|
5216 |
painter->setTransform(originalTransform); |
|
5217 |
} |
|
5218 |
#endif |
|
5219 |
} |
|
5220 |
||
5221 |
void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, |
|
5222 |
QPainter *sharedPainter, QWidgetBackingStore *backingStore) |
|
5223 |
{ |
|
5224 |
if (rgn.isEmpty()) |
|
5225 |
return; |
|
5226 |
||
5227 |
Q_Q(QWidget); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5228 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 5229 |
if (graphicsEffect && graphicsEffect->isEnabled()) { |
5230 |
QGraphicsEffectSource *source = graphicsEffect->d_func()->source; |
|
5231 |
QWidgetEffectSourcePrivate *sourced = static_cast<QWidgetEffectSourcePrivate *> |
|
5232 |
(source->d_func()); |
|
5233 |
if (!sourced->context) { |
|
5234 |
QWidgetPaintContext context(pdev, rgn, offset, flags, sharedPainter, backingStore); |
|
5235 |
sourced->context = &context; |
|
5236 |
if (!sharedPainter) { |
|
5237 |
QPaintEngine *paintEngine = pdev->paintEngine(); |
|
5238 |
paintEngine->d_func()->systemClip = rgn.translated(offset); |
|
5239 |
QPainter p(pdev); |
|
5240 |
p.translate(offset); |
|
5241 |
context.painter = &p; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5242 |
graphicsEffect->draw(&p); |
0 | 5243 |
paintEngine->d_func()->systemClip = QRegion(); |
5244 |
} else { |
|
5245 |
context.painter = sharedPainter; |
|
5246 |
if (sharedPainter->worldTransform() != sourced->lastEffectTransform) { |
|
5247 |
sourced->invalidateCache(); |
|
5248 |
sourced->lastEffectTransform = sharedPainter->worldTransform(); |
|
5249 |
} |
|
5250 |
sharedPainter->save(); |
|
5251 |
sharedPainter->translate(offset); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5252 |
graphicsEffect->draw(sharedPainter); |
0 | 5253 |
sharedPainter->restore(); |
5254 |
} |
|
5255 |
sourced->context = 0; |
|
5256 |
return; |
|
5257 |
} |
|
5258 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5259 |
#endif //QT_NO_GRAFFICSEFFECT |
0 | 5260 |
|
5261 |
const bool asRoot = flags & DrawAsRoot; |
|
5262 |
const bool alsoOnScreen = flags & DrawPaintOnScreen; |
|
5263 |
const bool recursive = flags & DrawRecursive; |
|
5264 |
const bool alsoInvisible = flags & DrawInvisible; |
|
5265 |
||
5266 |
Q_ASSERT(sharedPainter ? sharedPainter->isActive() : true); |
|
5267 |
||
5268 |
QRegion toBePainted(rgn); |
|
5269 |
if (asRoot && !alsoInvisible) |
|
5270 |
toBePainted &= clipRect(); //(rgn & visibleRegion()); |
|
5271 |
if (!(flags & DontSubtractOpaqueChildren)) |
|
5272 |
subtractOpaqueChildren(toBePainted, q->rect()); |
|
5273 |
||
5274 |
if (!toBePainted.isEmpty()) { |
|
5275 |
bool onScreen = paintOnScreen(); |
|
5276 |
if (!onScreen || alsoOnScreen) { |
|
5277 |
//update the "in paint event" flag |
|
5278 |
if (q->testAttribute(Qt::WA_WState_InPaintEvent)) |
|
5279 |
qWarning("QWidget::repaint: Recursive repaint detected"); |
|
5280 |
q->setAttribute(Qt::WA_WState_InPaintEvent); |
|
5281 |
||
5282 |
//clip away the new area |
|
5283 |
#ifndef QT_NO_PAINT_DEBUG |
|
5284 |
bool flushed = QWidgetBackingStore::flushPaint(q, toBePainted); |
|
5285 |
#endif |
|
5286 |
QPaintEngine *paintEngine = pdev->paintEngine(); |
|
5287 |
if (paintEngine) { |
|
5288 |
setRedirected(pdev, -offset); |
|
5289 |
||
5290 |
if (sharedPainter) |
|
5291 |
paintEngine->d_func()->systemClip = toBePainted; |
|
5292 |
else |
|
5293 |
paintEngine->d_func()->systemRect = q->data->crect; |
|
5294 |
||
5295 |
//paint the background |
|
5296 |
if ((asRoot || q->autoFillBackground() || onScreen || q->testAttribute(Qt::WA_StyledBackground)) |
|
5297 |
&& !q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) { |
|
5298 |
||
5299 |
QPainter p(q); |
|
5300 |
paintBackground(&p, toBePainted, (asRoot || onScreen) ? flags | DrawAsRoot : 0); |
|
5301 |
} |
|
5302 |
||
5303 |
if (!sharedPainter) |
|
5304 |
paintEngine->d_func()->systemClip = toBePainted.translated(offset); |
|
5305 |
||
5306 |
if (!onScreen && !asRoot && !isOpaque && q->testAttribute(Qt::WA_TintedBackground)) { |
|
5307 |
QPainter p(q); |
|
5308 |
QColor tint = q->palette().window().color(); |
|
5309 |
tint.setAlphaF(qreal(.6)); |
|
5310 |
p.fillRect(toBePainted.boundingRect(), tint); |
|
5311 |
} |
|
5312 |
} |
|
5313 |
||
5314 |
#if 0 |
|
5315 |
qDebug() << "painting" << q << "opaque ==" << isOpaque(); |
|
5316 |
qDebug() << "clipping to" << toBePainted << "location == " << offset |
|
5317 |
<< "geometry ==" << QRect(q->mapTo(q->window(), QPoint(0, 0)), q->size()); |
|
5318 |
#endif |
|
5319 |
||
5320 |
//actually send the paint event |
|
5321 |
QPaintEvent e(toBePainted); |
|
5322 |
QCoreApplication::sendSpontaneousEvent(q, &e); |
|
5323 |
#if !defined(Q_WS_MAC) && !defined(Q_WS_QWS) |
|
5324 |
if (backingStore && !onScreen && !asRoot && (q->internalWinId() || !q->nativeParentWidget()->isWindow())) |
|
5325 |
backingStore->markDirtyOnScreen(toBePainted, q, offset); |
|
5326 |
#endif |
|
5327 |
||
5328 |
//restore |
|
5329 |
if (paintEngine) { |
|
5330 |
restoreRedirected(); |
|
5331 |
if (!sharedPainter) |
|
5332 |
paintEngine->d_func()->systemRect = QRect(); |
|
5333 |
else |
|
5334 |
paintEngine->d_func()->currentClipWidget = 0; |
|
5335 |
paintEngine->d_func()->systemClip = QRegion(); |
|
5336 |
} |
|
5337 |
q->setAttribute(Qt::WA_WState_InPaintEvent, false); |
|
5338 |
if (q->paintingActive() && !q->testAttribute(Qt::WA_PaintOutsidePaintEvent)) |
|
5339 |
qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent"); |
|
5340 |
||
5341 |
if (paintEngine && paintEngine->autoDestruct()) { |
|
5342 |
delete paintEngine; |
|
5343 |
} |
|
5344 |
||
5345 |
#ifndef QT_NO_PAINT_DEBUG |
|
5346 |
if (flushed) |
|
5347 |
QWidgetBackingStore::unflushPaint(q, toBePainted); |
|
5348 |
#endif |
|
5349 |
} else if (q->isWindow()) { |
|
5350 |
QPaintEngine *engine = pdev->paintEngine(); |
|
5351 |
if (engine) { |
|
5352 |
QPainter p(pdev); |
|
5353 |
p.setClipRegion(toBePainted); |
|
5354 |
const QBrush bg = q->palette().brush(QPalette::Window); |
|
5355 |
if (bg.style() == Qt::TexturePattern) |
|
5356 |
p.drawTiledPixmap(q->rect(), bg.texture()); |
|
5357 |
else |
|
5358 |
p.fillRect(q->rect(), bg); |
|
5359 |
||
5360 |
if (engine->autoDestruct()) |
|
5361 |
delete engine; |
|
5362 |
} |
|
5363 |
} |
|
5364 |
} |
|
5365 |
||
5366 |
if (recursive && !children.isEmpty()) { |
|
5367 |
paintSiblingsRecursive(pdev, children, children.size() - 1, rgn, offset, flags & ~DrawAsRoot |
|
5368 |
#ifdef Q_BACKINGSTORE_SUBSURFACES |
|
5369 |
, q->windowSurface() |
|
5370 |
#endif |
|
5371 |
, sharedPainter, backingStore); |
|
5372 |
} |
|
5373 |
} |
|
5374 |
||
5375 |
void QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& siblings, int index, const QRegion &rgn, |
|
5376 |
const QPoint &offset, int flags |
|
5377 |
#ifdef Q_BACKINGSTORE_SUBSURFACES |
|
5378 |
, const QWindowSurface *currentSurface |
|
5379 |
#endif |
|
5380 |
, QPainter *sharedPainter, QWidgetBackingStore *backingStore) |
|
5381 |
{ |
|
5382 |
QWidget *w = 0; |
|
5383 |
QRect boundingRect; |
|
5384 |
bool dirtyBoundingRect = true; |
|
5385 |
const bool exludeOpaqueChildren = (flags & DontDrawOpaqueChildren); |
|
5386 |
||
5387 |
do { |
|
5388 |
QWidget *x = qobject_cast<QWidget*>(siblings.at(index)); |
|
5389 |
if (x && !(exludeOpaqueChildren && x->d_func()->isOpaque) && !x->isHidden() && !x->isWindow()) { |
|
5390 |
if (dirtyBoundingRect) { |
|
5391 |
boundingRect = rgn.boundingRect(); |
|
5392 |
dirtyBoundingRect = false; |
|
5393 |
} |
|
5394 |
||
5395 |
if (qRectIntersects(boundingRect, x->d_func()->effectiveRectFor(x->data->crect))) { |
|
5396 |
#ifdef Q_BACKINGSTORE_SUBSURFACES |
|
5397 |
if (x->windowSurface() == currentSurface) |
|
5398 |
#endif |
|
5399 |
{ |
|
5400 |
w = x; |
|
5401 |
break; |
|
5402 |
} |
|
5403 |
} |
|
5404 |
} |
|
5405 |
--index; |
|
5406 |
} while (index >= 0); |
|
5407 |
||
5408 |
if (!w) |
|
5409 |
return; |
|
5410 |
||
5411 |
QWidgetPrivate *wd = w->d_func(); |
|
5412 |
const QPoint widgetPos(w->data->crect.topLeft()); |
|
5413 |
const bool hasMask = wd->extra && wd->extra->hasMask && !wd->graphicsEffect; |
|
5414 |
if (index > 0) { |
|
5415 |
QRegion wr(rgn); |
|
5416 |
if (wd->isOpaque) |
|
5417 |
wr -= hasMask ? wd->extra->mask.translated(widgetPos) : w->data->crect; |
|
5418 |
paintSiblingsRecursive(pdev, siblings, --index, wr, offset, flags |
|
5419 |
#ifdef Q_BACKINGSTORE_SUBSURFACES |
|
5420 |
, currentSurface |
|
5421 |
#endif |
|
5422 |
, sharedPainter, backingStore); |
|
5423 |
} |
|
5424 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5425 |
if (w->updatesEnabled() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5426 |
#ifndef QT_NO_GRAPHICSVIEW |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5427 |
&& (!w->d_func()->extra || !w->d_func()->extra->proxyWidget) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5428 |
#endif //QT_NO_GRAPHICSVIEW |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5429 |
) { |
0 | 5430 |
QRegion wRegion(rgn); |
5431 |
wRegion &= wd->effectiveRectFor(w->data->crect); |
|
5432 |
wRegion.translate(-widgetPos); |
|
5433 |
if (hasMask) |
|
5434 |
wRegion &= wd->extra->mask; |
|
5435 |
wd->drawWidget(pdev, wRegion, offset + widgetPos, flags, sharedPainter, backingStore); |
|
5436 |
} |
|
5437 |
} |
|
5438 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5439 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 5440 |
QRectF QWidgetEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) const |
5441 |
{ |
|
5442 |
if (system != Qt::DeviceCoordinates) |
|
5443 |
return m_widget->rect(); |
|
5444 |
||
5445 |
if (!context) { |
|
5446 |
// Device coordinates without context not yet supported. |
|
5447 |
qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context"); |
|
5448 |
return QRectF(); |
|
5449 |
} |
|
5450 |
||
5451 |
return context->painter->worldTransform().mapRect(m_widget->rect()); |
|
5452 |
} |
|
5453 |
||
5454 |
void QWidgetEffectSourcePrivate::draw(QPainter *painter) |
|
5455 |
{ |
|
5456 |
if (!context || context->painter != painter) { |
|
5457 |
m_widget->render(painter); |
|
5458 |
return; |
|
5459 |
} |
|
5460 |
||
5461 |
// The region saved in the context is neither clipped to the rect |
|
5462 |
// nor the mask, so we have to clip it here before calling drawWidget. |
|
5463 |
QRegion toBePainted = context->rgn; |
|
5464 |
toBePainted &= m_widget->rect(); |
|
5465 |
QWidgetPrivate *wd = qt_widget_private(m_widget); |
|
5466 |
if (wd->extra && wd->extra->hasMask) |
|
5467 |
toBePainted &= wd->extra->mask; |
|
5468 |
||
5469 |
wd->drawWidget(context->pdev, toBePainted, context->offset, context->flags, |
|
5470 |
context->sharedPainter, context->backingStore); |
|
5471 |
} |
|
5472 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5473 |
QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5474 |
QGraphicsEffect::PixmapPadMode mode) const |
0 | 5475 |
{ |
5476 |
const bool deviceCoordinates = (system == Qt::DeviceCoordinates); |
|
5477 |
if (!context && deviceCoordinates) { |
|
5478 |
// Device coordinates without context not yet supported. |
|
5479 |
qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context"); |
|
5480 |
return QPixmap(); |
|
5481 |
} |
|
5482 |
||
5483 |
QPoint pixmapOffset; |
|
5484 |
QRectF sourceRect = m_widget->rect(); |
|
5485 |
||
5486 |
if (deviceCoordinates) { |
|
5487 |
const QTransform &painterTransform = context->painter->worldTransform(); |
|
5488 |
sourceRect = painterTransform.mapRect(sourceRect); |
|
5489 |
pixmapOffset = painterTransform.map(pixmapOffset); |
|
5490 |
} |
|
5491 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5492 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5493 |
QRect effectRect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5494 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5495 |
if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5496 |
effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5497 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5498 |
} else if (mode == QGraphicsEffect::PadToTransparentBorder) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5499 |
effectRect = sourceRect.adjusted(-1, -1, 1, 1).toAlignedRect(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5500 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5501 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5502 |
effectRect = sourceRect.toAlignedRect(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5503 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5504 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5505 |
|
0 | 5506 |
if (offset) |
5507 |
*offset = effectRect.topLeft(); |
|
5508 |
||
5509 |
if (deviceCoordinates) { |
|
5510 |
// Clip to device rect. |
|
5511 |
int left, top, right, bottom; |
|
5512 |
effectRect.getCoords(&left, &top, &right, &bottom); |
|
5513 |
if (left < 0) { |
|
5514 |
if (offset) |
|
5515 |
offset->rx() += -left; |
|
5516 |
effectRect.setX(0); |
|
5517 |
} |
|
5518 |
if (top < 0) { |
|
5519 |
if (offset) |
|
5520 |
offset->ry() += -top; |
|
5521 |
effectRect.setY(0); |
|
5522 |
} |
|
5523 |
// NB! We use +-1 for historical reasons (see QRect documentation). |
|
5524 |
QPaintDevice *device = context->painter->device(); |
|
5525 |
const int deviceWidth = device->width(); |
|
5526 |
const int deviceHeight = device->height(); |
|
5527 |
if (right + 1 > deviceWidth) |
|
5528 |
effectRect.setRight(deviceWidth - 1); |
|
5529 |
if (bottom + 1 > deviceHeight) |
|
5530 |
effectRect.setBottom(deviceHeight -1); |
|
5531 |
} |
|
5532 |
||
5533 |
pixmapOffset -= effectRect.topLeft(); |
|
5534 |
||
5535 |
QPixmap pixmap(effectRect.size()); |
|
5536 |
pixmap.fill(Qt::transparent); |
|
5537 |
m_widget->render(&pixmap, pixmapOffset); |
|
5538 |
return pixmap; |
|
5539 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5540 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 5541 |
|
5542 |
#ifndef QT_NO_GRAPHICSVIEW |
|
5543 |
/*! |
|
5544 |
\internal |
|
5545 |
||
5546 |
Finds the nearest widget embedded in a graphics proxy widget along the chain formed by this |
|
5547 |
widget and its ancestors. The search starts at \a origin (inclusive). |
|
5548 |
If successful, the function returns the proxy that embeds the widget, or 0 if no embedded |
|
5549 |
widget was found. |
|
5550 |
*/ |
|
5551 |
QGraphicsProxyWidget * QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin) |
|
5552 |
{ |
|
5553 |
if (origin) { |
|
5554 |
QWExtra *extra = origin->d_func()->extra; |
|
5555 |
if (extra && extra->proxyWidget) |
|
5556 |
return extra->proxyWidget; |
|
5557 |
return nearestGraphicsProxyWidget(origin->parentWidget()); |
|
5558 |
} |
|
5559 |
return 0; |
|
5560 |
} |
|
5561 |
#endif |
|
5562 |
||
5563 |
/*! |
|
5564 |
\property QWidget::locale |
|
5565 |
\brief the widget's locale |
|
5566 |
\since 4.3 |
|
5567 |
||
5568 |
As long as no special locale has been set, this is either |
|
5569 |
the parent's locale or (if this widget is a top level widget), |
|
5570 |
the default locale. |
|
5571 |
||
5572 |
If the widget displays dates or numbers, these should be formatted |
|
5573 |
using the widget's locale. |
|
5574 |
||
5575 |
\sa QLocale QLocale::setDefault() |
|
5576 |
*/ |
|
5577 |
||
5578 |
void QWidgetPrivate::setLocale_helper(const QLocale &loc, bool forceUpdate) |
|
5579 |
{ |
|
5580 |
Q_Q(QWidget); |
|
5581 |
if (locale == loc && !forceUpdate) |
|
5582 |
return; |
|
5583 |
||
5584 |
locale = loc; |
|
5585 |
||
5586 |
if (!children.isEmpty()) { |
|
5587 |
for (int i = 0; i < children.size(); ++i) { |
|
5588 |
QWidget *w = qobject_cast<QWidget*>(children.at(i)); |
|
5589 |
if (!w) |
|
5590 |
continue; |
|
5591 |
if (w->testAttribute(Qt::WA_SetLocale)) |
|
5592 |
continue; |
|
5593 |
if (w->isWindow() && !w->testAttribute(Qt::WA_WindowPropagation)) |
|
5594 |
continue; |
|
5595 |
w->d_func()->setLocale_helper(loc, forceUpdate); |
|
5596 |
} |
|
5597 |
} |
|
5598 |
QEvent e(QEvent::LocaleChange); |
|
5599 |
QApplication::sendEvent(q, &e); |
|
5600 |
} |
|
5601 |
||
5602 |
void QWidget::setLocale(const QLocale &locale) |
|
5603 |
{ |
|
5604 |
Q_D(QWidget); |
|
5605 |
||
5606 |
setAttribute(Qt::WA_SetLocale); |
|
5607 |
d->setLocale_helper(locale); |
|
5608 |
} |
|
5609 |
||
5610 |
QLocale QWidget::locale() const |
|
5611 |
{ |
|
5612 |
Q_D(const QWidget); |
|
5613 |
||
5614 |
return d->locale; |
|
5615 |
} |
|
5616 |
||
5617 |
void QWidgetPrivate::resolveLocale() |
|
5618 |
{ |
|
5619 |
Q_Q(const QWidget); |
|
5620 |
||
5621 |
if (!q->testAttribute(Qt::WA_SetLocale)) { |
|
5622 |
setLocale_helper(q->isWindow() |
|
5623 |
? QLocale() |
|
5624 |
: q->parentWidget()->locale()); |
|
5625 |
} |
|
5626 |
} |
|
5627 |
||
5628 |
void QWidget::unsetLocale() |
|
5629 |
{ |
|
5630 |
Q_D(QWidget); |
|
5631 |
setAttribute(Qt::WA_SetLocale, false); |
|
5632 |
d->resolveLocale(); |
|
5633 |
} |
|
5634 |
||
5635 |
static QString constructWindowTitleFromFilePath(const QString &filePath) |
|
5636 |
{ |
|
5637 |
QFileInfo fi(filePath); |
|
5638 |
QString windowTitle = fi.fileName() + QLatin1String("[*]"); |
|
5639 |
#ifndef Q_WS_MAC |
|
5640 |
QString appName = QApplication::applicationName(); |
|
5641 |
if (!appName.isEmpty()) |
|
5642 |
windowTitle += QLatin1Char(' ') + QChar(0x2014) + QLatin1Char(' ') + appName; |
|
5643 |
#endif |
|
5644 |
return windowTitle; |
|
5645 |
} |
|
5646 |
||
5647 |
/*! |
|
5648 |
\property QWidget::windowTitle |
|
5649 |
\brief the window title (caption) |
|
5650 |
||
5651 |
This property only makes sense for top-level widgets, such as |
|
5652 |
windows and dialogs. If no caption has been set, the title is based of the |
|
5653 |
\l windowFilePath. If neither of these is set, then the title is |
|
5654 |
an empty string. |
|
5655 |
||
5656 |
If you use the \l windowModified mechanism, the window title must |
|
5657 |
contain a "[*]" placeholder, which indicates where the '*' should |
|
5658 |
appear. Normally, it should appear right after the file name |
|
5659 |
(e.g., "document1.txt[*] - Text Editor"). If the \l |
|
5660 |
windowModified property is false (the default), the placeholder |
|
5661 |
is simply removed. |
|
5662 |
||
5663 |
\sa windowIcon, windowIconText, windowModified, windowFilePath |
|
5664 |
*/ |
|
5665 |
QString QWidget::windowTitle() const |
|
5666 |
{ |
|
5667 |
Q_D(const QWidget); |
|
5668 |
if (d->extra && d->extra->topextra) { |
|
5669 |
if (!d->extra->topextra->caption.isEmpty()) |
|
5670 |
return d->extra->topextra->caption; |
|
5671 |
if (!d->extra->topextra->filePath.isEmpty()) |
|
5672 |
return constructWindowTitleFromFilePath(d->extra->topextra->filePath); |
|
5673 |
} |
|
5674 |
return QString(); |
|
5675 |
} |
|
5676 |
||
5677 |
/*! |
|
5678 |
Returns a modified window title with the [*] place holder |
|
5679 |
replaced according to the rules described in QWidget::setWindowTitle |
|
5680 |
||
5681 |
This function assumes that "[*]" can be quoted by another |
|
5682 |
"[*]", so it will replace two place holders by one and |
|
5683 |
a single last one by either "*" or nothing depending on |
|
5684 |
the modified flag. |
|
5685 |
||
5686 |
\internal |
|
5687 |
*/ |
|
5688 |
QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widget) |
|
5689 |
{ |
|
5690 |
Q_ASSERT(widget); |
|
5691 |
||
5692 |
#ifdef QT_EVAL |
|
5693 |
extern QString qt_eval_adapt_window_title(const QString &title); |
|
5694 |
QString cap = qt_eval_adapt_window_title(title); |
|
5695 |
#else |
|
5696 |
QString cap = title; |
|
5697 |
#endif |
|
5698 |
||
5699 |
if (cap.isEmpty()) |
|
5700 |
return cap; |
|
5701 |
||
5702 |
QLatin1String placeHolder("[*]"); |
|
5703 |
int placeHolderLength = 3; // QLatin1String doesn't have length() |
|
5704 |
||
5705 |
int index = cap.indexOf(placeHolder); |
|
5706 |
||
5707 |
// here the magic begins |
|
5708 |
while (index != -1) { |
|
5709 |
index += placeHolderLength; |
|
5710 |
int count = 1; |
|
5711 |
while (cap.indexOf(placeHolder, index) == index) { |
|
5712 |
++count; |
|
5713 |
index += placeHolderLength; |
|
5714 |
} |
|
5715 |
||
5716 |
if (count%2) { // odd number of [*] -> replace last one |
|
5717 |
int lastIndex = cap.lastIndexOf(placeHolder, index - 1); |
|
5718 |
if (widget->isWindowModified() |
|
5719 |
&& widget->style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, widget)) |
|
5720 |
cap.replace(lastIndex, 3, QWidget::tr("*")); |
|
5721 |
else |
|
5722 |
cap.remove(lastIndex, 3); |
|
5723 |
} |
|
5724 |
||
5725 |
index = cap.indexOf(placeHolder, index); |
|
5726 |
} |
|
5727 |
||
5728 |
cap.replace(QLatin1String("[*][*]"), placeHolder); |
|
5729 |
||
5730 |
return cap; |
|
5731 |
} |
|
5732 |
||
5733 |
void QWidgetPrivate::setWindowTitle_helper(const QString &title) |
|
5734 |
{ |
|
5735 |
Q_Q(QWidget); |
|
5736 |
if (q->testAttribute(Qt::WA_WState_Created)) |
|
5737 |
setWindowTitle_sys(qt_setWindowTitle_helperHelper(title, q)); |
|
5738 |
} |
|
5739 |
||
5740 |
void QWidgetPrivate::setWindowIconText_helper(const QString &title) |
|
5741 |
{ |
|
5742 |
Q_Q(QWidget); |
|
5743 |
if (q->testAttribute(Qt::WA_WState_Created)) |
|
5744 |
setWindowIconText_sys(qt_setWindowTitle_helperHelper(title, q)); |
|
5745 |
} |
|
5746 |
||
5747 |
void QWidget::setWindowIconText(const QString &iconText) |
|
5748 |
{ |
|
5749 |
if (QWidget::windowIconText() == iconText) |
|
5750 |
return; |
|
5751 |
||
5752 |
Q_D(QWidget); |
|
5753 |
d->topData()->iconText = iconText; |
|
5754 |
d->setWindowIconText_helper(iconText); |
|
5755 |
||
5756 |
QEvent e(QEvent::IconTextChange); |
|
5757 |
QApplication::sendEvent(this, &e); |
|
5758 |
} |
|
5759 |
||
5760 |
void QWidget::setWindowTitle(const QString &title) |
|
5761 |
{ |
|
5762 |
if (QWidget::windowTitle() == title && !title.isEmpty() && !title.isNull()) |
|
5763 |
return; |
|
5764 |
||
5765 |
Q_D(QWidget); |
|
5766 |
d->topData()->caption = title; |
|
5767 |
d->setWindowTitle_helper(title); |
|
5768 |
||
5769 |
QEvent e(QEvent::WindowTitleChange); |
|
5770 |
QApplication::sendEvent(this, &e); |
|
5771 |
} |
|
5772 |
||
5773 |
||
5774 |
/*! |
|
5775 |
\property QWidget::windowIcon |
|
5776 |
\brief the widget's icon |
|
5777 |
||
5778 |
This property only makes sense for windows. If no icon |
|
5779 |
has been set, windowIcon() returns the application icon |
|
5780 |
(QApplication::windowIcon()). |
|
5781 |
||
5782 |
\sa windowIconText, windowTitle |
|
5783 |
*/ |
|
5784 |
QIcon QWidget::windowIcon() const |
|
5785 |
{ |
|
5786 |
const QWidget *w = this; |
|
5787 |
while (w) { |
|
5788 |
const QWidgetPrivate *d = w->d_func(); |
|
5789 |
if (d->extra && d->extra->topextra && d->extra->topextra->icon) |
|
5790 |
return *d->extra->topextra->icon; |
|
5791 |
w = w->parentWidget(); |
|
5792 |
} |
|
5793 |
return QApplication::windowIcon(); |
|
5794 |
} |
|
5795 |
||
5796 |
void QWidgetPrivate::setWindowIcon_helper() |
|
5797 |
{ |
|
5798 |
QEvent e(QEvent::WindowIconChange); |
|
5799 |
QApplication::sendEvent(q_func(), &e); |
|
5800 |
for (int i = 0; i < children.size(); ++i) { |
|
5801 |
QWidget *w = qobject_cast<QWidget *>(children.at(i)); |
|
5802 |
if (w && !w->isWindow()) |
|
5803 |
QApplication::sendEvent(w, &e); |
|
5804 |
} |
|
5805 |
} |
|
5806 |
||
5807 |
void QWidget::setWindowIcon(const QIcon &icon) |
|
5808 |
{ |
|
5809 |
Q_D(QWidget); |
|
5810 |
||
5811 |
setAttribute(Qt::WA_SetWindowIcon, !icon.isNull()); |
|
5812 |
d->createTLExtra(); |
|
5813 |
||
5814 |
if (!d->extra->topextra->icon) |
|
5815 |
d->extra->topextra->icon = new QIcon(); |
|
5816 |
*d->extra->topextra->icon = icon; |
|
5817 |
||
5818 |
delete d->extra->topextra->iconPixmap; |
|
5819 |
d->extra->topextra->iconPixmap = 0; |
|
5820 |
||
5821 |
d->setWindowIcon_sys(); |
|
5822 |
d->setWindowIcon_helper(); |
|
5823 |
} |
|
5824 |
||
5825 |
||
5826 |
/*! |
|
5827 |
\property QWidget::windowIconText |
|
5828 |
\brief the widget's icon text |
|
5829 |
||
5830 |
This property only makes sense for windows. If no icon |
|
5831 |
text has been set, this functions returns an empty string. |
|
5832 |
||
5833 |
\sa windowIcon, windowTitle |
|
5834 |
*/ |
|
5835 |
||
5836 |
QString QWidget::windowIconText() const |
|
5837 |
{ |
|
5838 |
Q_D(const QWidget); |
|
5839 |
return (d->extra && d->extra->topextra) ? d->extra->topextra->iconText : QString(); |
|
5840 |
} |
|
5841 |
||
5842 |
/*! |
|
5843 |
\property QWidget::windowFilePath |
|
5844 |
\since 4.4 |
|
5845 |
\brief the file path associated with a widget |
|
5846 |
||
5847 |
This property only makes sense for windows. It associates a file path with |
|
5848 |
a window. If you set the file path, but have not set the window title, Qt |
|
5849 |
sets the window title to contain a string created using the following |
|
5850 |
components. |
|
5851 |
||
5852 |
On Mac OS X: |
|
5853 |
||
5854 |
\list |
|
5855 |
\o The file name of the specified path, obtained using QFileInfo::fileName(). |
|
5856 |
\endlist |
|
5857 |
||
5858 |
On Windows and X11: |
|
5859 |
||
5860 |
\list |
|
5861 |
\o The file name of the specified path, obtained using QFileInfo::fileName(). |
|
5862 |
\o An optional \c{*} character, if the \l windowModified property is set. |
|
5863 |
\o The \c{0x2014} unicode character, padded either side by spaces. |
|
5864 |
\o The application name, obtained from the application's |
|
5865 |
\l{QCoreApplication::}{applicationName} property. |
|
5866 |
\endlist |
|
5867 |
||
5868 |
If the window title is set at any point, then the window title takes precedence and |
|
5869 |
will be shown instead of the file path string. |
|
5870 |
||
5871 |
Additionally, on Mac OS X, this has an added benefit that it sets the |
|
5872 |
\l{http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/XHIGWindows/chapter_17_section_3.html}{proxy icon} |
|
5873 |
for the window, assuming that the file path exists. |
|
5874 |
||
5875 |
If no file path is set, this property contains an empty string. |
|
5876 |
||
5877 |
By default, this property contains an empty string. |
|
5878 |
||
5879 |
\sa windowTitle, windowIcon |
|
5880 |
*/ |
|
5881 |
||
5882 |
QString QWidget::windowFilePath() const |
|
5883 |
{ |
|
5884 |
Q_D(const QWidget); |
|
5885 |
return (d->extra && d->extra->topextra) ? d->extra->topextra->filePath : QString(); |
|
5886 |
} |
|
5887 |
||
5888 |
void QWidget::setWindowFilePath(const QString &filePath) |
|
5889 |
{ |
|
5890 |
if (filePath == windowFilePath()) |
|
5891 |
return; |
|
5892 |
||
5893 |
Q_D(QWidget); |
|
5894 |
||
5895 |
d->createTLExtra(); |
|
5896 |
d->extra->topextra->filePath = filePath; |
|
5897 |
d->setWindowFilePath_helper(filePath); |
|
5898 |
} |
|
5899 |
||
5900 |
void QWidgetPrivate::setWindowFilePath_helper(const QString &filePath) |
|
5901 |
{ |
|
5902 |
if (extra->topextra && extra->topextra->caption.isEmpty()) { |
|
5903 |
#ifdef Q_WS_MAC |
|
5904 |
setWindowTitle_helper(QFileInfo(filePath).fileName()); |
|
5905 |
#else |
|
5906 |
Q_Q(QWidget); |
|
5907 |
Q_UNUSED(filePath); |
|
5908 |
setWindowTitle_helper(q->windowTitle()); |
|
5909 |
#endif |
|
5910 |
} |
|
5911 |
#ifdef Q_WS_MAC |
|
5912 |
setWindowFilePath_sys(filePath); |
|
5913 |
#endif |
|
5914 |
} |
|
5915 |
||
5916 |
/*! |
|
5917 |
Returns the window's role, or an empty string. |
|
5918 |
||
5919 |
\sa windowIcon, windowTitle |
|
5920 |
*/ |
|
5921 |
||
5922 |
QString QWidget::windowRole() const |
|
5923 |
{ |
|
5924 |
Q_D(const QWidget); |
|
5925 |
return (d->extra && d->extra->topextra) ? d->extra->topextra->role : QString(); |
|
5926 |
} |
|
5927 |
||
5928 |
/*! |
|
5929 |
Sets the window's role to \a role. This only makes sense for |
|
5930 |
windows on X11. |
|
5931 |
*/ |
|
5932 |
void QWidget::setWindowRole(const QString &role) |
|
5933 |
{ |
|
5934 |
#if defined(Q_WS_X11) |
|
5935 |
Q_D(QWidget); |
|
5936 |
d->topData()->role = role; |
|
5937 |
d->setWindowRole(); |
|
5938 |
#else |
|
5939 |
Q_UNUSED(role) |
|
5940 |
#endif |
|
5941 |
} |
|
5942 |
||
5943 |
/*! |
|
5944 |
\property QWidget::mouseTracking |
|
5945 |
\brief whether mouse tracking is enabled for the widget |
|
5946 |
||
5947 |
If mouse tracking is disabled (the default), the widget only |
|
5948 |
receives mouse move events when at least one mouse button is |
|
5949 |
pressed while the mouse is being moved. |
|
5950 |
||
5951 |
If mouse tracking is enabled, the widget receives mouse move |
|
5952 |
events even if no buttons are pressed. |
|
5953 |
||
5954 |
\sa mouseMoveEvent() |
|
5955 |
*/ |
|
5956 |
||
5957 |
||
5958 |
/*! |
|
5959 |
Sets the widget's focus proxy to widget \a w. If \a w is 0, the |
|
5960 |
function resets this widget to have no focus proxy. |
|
5961 |
||
5962 |
Some widgets can "have focus", but create a child widget, such as |
|
5963 |
QLineEdit, to actually handle the focus. In this case, the widget |
|
5964 |
can set the line edit to be its focus proxy. |
|
5965 |
||
5966 |
setFocusProxy() sets the widget which will actually get focus when |
|
5967 |
"this widget" gets it. If there is a focus proxy, setFocus() and |
|
5968 |
hasFocus() operate on the focus proxy. |
|
5969 |
||
5970 |
\sa focusProxy() |
|
5971 |
*/ |
|
5972 |
||
5973 |
void QWidget::setFocusProxy(QWidget * w) |
|
5974 |
{ |
|
5975 |
Q_D(QWidget); |
|
5976 |
if (!w && !d->extra) |
|
5977 |
return; |
|
5978 |
||
5979 |
for (QWidget* fp = w; fp; fp = fp->focusProxy()) { |
|
5980 |
if (fp == this) { |
|
5981 |
qWarning("QWidget: %s (%s) already in focus proxy chain", metaObject()->className(), objectName().toLocal8Bit().constData()); |
|
5982 |
return; |
|
5983 |
} |
|
5984 |
} |
|
5985 |
||
5986 |
d->createExtra(); |
|
5987 |
d->extra->focus_proxy = w; |
|
5988 |
} |
|
5989 |
||
5990 |
||
5991 |
/*! |
|
5992 |
Returns the focus proxy, or 0 if there is no focus proxy. |
|
5993 |
||
5994 |
\sa setFocusProxy() |
|
5995 |
*/ |
|
5996 |
||
5997 |
QWidget * QWidget::focusProxy() const |
|
5998 |
{ |
|
5999 |
Q_D(const QWidget); |
|
6000 |
return d->extra ? (QWidget *)d->extra->focus_proxy : 0; |
|
6001 |
} |
|
6002 |
||
6003 |
||
6004 |
/*! |
|
6005 |
\property QWidget::focus |
|
6006 |
\brief whether this widget (or its focus proxy) has the keyboard |
|
6007 |
input focus |
|
6008 |
||
6009 |
By default, this property is false. |
|
6010 |
||
6011 |
\note Obtaining the value of this property for a widget is effectively equivalent |
|
6012 |
to checking whether QApplication::focusWidget() refers to the widget. |
|
6013 |
||
6014 |
\sa setFocus(), clearFocus(), setFocusPolicy(), QApplication::focusWidget() |
|
6015 |
*/ |
|
6016 |
bool QWidget::hasFocus() const |
|
6017 |
{ |
|
6018 |
const QWidget* w = this; |
|
6019 |
while (w->d_func()->extra && w->d_func()->extra->focus_proxy) |
|
6020 |
w = w->d_func()->extra->focus_proxy; |
|
6021 |
if (QWidget *window = w->window()) { |
|
6022 |
#ifndef QT_NO_GRAPHICSVIEW |
|
6023 |
QWExtra *e = window->d_func()->extra; |
|
6024 |
if (e && e->proxyWidget && e->proxyWidget->hasFocus() && window->focusWidget() == w) |
|
6025 |
return true; |
|
6026 |
#endif |
|
6027 |
} |
|
6028 |
return (QApplication::focusWidget() == w); |
|
6029 |
} |
|
6030 |
||
6031 |
/*! |
|
6032 |
Gives the keyboard input focus to this widget (or its focus |
|
6033 |
proxy) if this widget or one of its parents is the \link |
|
6034 |
isActiveWindow() active window\endlink. The \a reason argument will |
|
6035 |
be passed into any focus event sent from this function, it is used |
|
6036 |
to give an explanation of what caused the widget to get focus. |
|
6037 |
If the window is not active, the widget will be given the focus when |
|
6038 |
the window becomes active. |
|
6039 |
||
6040 |
First, a focus out event is sent to the focus widget (if any) to |
|
6041 |
tell it that it is about to lose the focus. Then a focus in event |
|
6042 |
is sent to this widget to tell it that it just received the focus. |
|
6043 |
(Nothing happens if the focus in and focus out widgets are the |
|
6044 |
same.) |
|
6045 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6046 |
\note On embedded platforms, setFocus() will not cause an input panel |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6047 |
to be opened by the input method. If you want this to happen, you |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6048 |
have to send a QEvent::RequestSoftwareInputPanel event to the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6049 |
widget yourself. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6050 |
|
0 | 6051 |
setFocus() gives focus to a widget regardless of its focus policy, |
6052 |
but does not clear any keyboard grab (see grabKeyboard()). |
|
6053 |
||
6054 |
Be aware that if the widget is hidden, it will not accept focus |
|
6055 |
until it is shown. |
|
6056 |
||
6057 |
\warning If you call setFocus() in a function which may itself be |
|
6058 |
called from focusOutEvent() or focusInEvent(), you may get an |
|
6059 |
infinite recursion. |
|
6060 |
||
6061 |
\sa hasFocus(), clearFocus(), focusInEvent(), focusOutEvent(), |
|
6062 |
setFocusPolicy(), focusWidget(), QApplication::focusWidget(), grabKeyboard(), |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6063 |
grabMouse(), {Keyboard Focus}, QEvent::RequestSoftwareInputPanel |
0 | 6064 |
*/ |
6065 |
||
6066 |
void QWidget::setFocus(Qt::FocusReason reason) |
|
6067 |
{ |
|
6068 |
if (!isEnabled()) |
|
6069 |
return; |
|
6070 |
||
6071 |
QWidget *f = this; |
|
6072 |
while (f->d_func()->extra && f->d_func()->extra->focus_proxy) |
|
6073 |
f = f->d_func()->extra->focus_proxy; |
|
6074 |
||
6075 |
if (QApplication::focusWidget() == f |
|
6076 |
#if defined(Q_WS_WIN) |
|
6077 |
&& GetFocus() == f->internalWinId() |
|
6078 |
#endif |
|
6079 |
) |
|
6080 |
return; |
|
6081 |
||
6082 |
#ifndef QT_NO_GRAPHICSVIEW |
|
6083 |
QWidget *previousProxyFocus = 0; |
|
6084 |
if (QWExtra *topData = window()->d_func()->extra) { |
|
6085 |
if (topData->proxyWidget && topData->proxyWidget->hasFocus()) { |
|
6086 |
previousProxyFocus = topData->proxyWidget->widget()->focusWidget(); |
|
6087 |
if (previousProxyFocus && previousProxyFocus->focusProxy()) |
|
6088 |
previousProxyFocus = previousProxyFocus->focusProxy(); |
|
6089 |
} |
|
6090 |
} |
|
6091 |
#endif |
|
6092 |
||
6093 |
QWidget *w = f; |
|
6094 |
if (isHidden()) { |
|
6095 |
while (w && w->isHidden()) { |
|
6096 |
w->d_func()->focus_child = f; |
|
6097 |
w = w->isWindow() ? 0 : w->parentWidget(); |
|
6098 |
} |
|
6099 |
} else { |
|
6100 |
while (w) { |
|
6101 |
w->d_func()->focus_child = f; |
|
6102 |
w = w->isWindow() ? 0 : w->parentWidget(); |
|
6103 |
} |
|
6104 |
} |
|
6105 |
||
6106 |
#ifndef QT_NO_GRAPHICSVIEW |
|
6107 |
// Update proxy state |
|
6108 |
if (QWExtra *topData = window()->d_func()->extra) { |
|
6109 |
if (topData->proxyWidget && !topData->proxyWidget->hasFocus()) { |
|
6110 |
topData->proxyWidget->d_func()->focusFromWidgetToProxy = 1; |
|
6111 |
topData->proxyWidget->setFocus(reason); |
|
6112 |
topData->proxyWidget->d_func()->focusFromWidgetToProxy = 0; |
|
6113 |
} |
|
6114 |
} |
|
6115 |
#endif |
|
6116 |
||
6117 |
if (f->isActiveWindow()) { |
|
6118 |
QApplicationPrivate::setFocusWidget(f, reason); |
|
6119 |
#ifndef QT_NO_ACCESSIBILITY |
|
6120 |
# ifdef Q_OS_WIN |
|
6121 |
// The negation of the condition in setFocus_sys |
|
6122 |
if (!(testAttribute(Qt::WA_WState_Created) && window()->windowType() != Qt::Popup && internalWinId())) |
|
6123 |
//setFocusWidget will already post a focus event for us (that the AT client receives) on Windows |
|
6124 |
# endif |
|
6125 |
QAccessible::updateAccessibility(f, 0, QAccessible::Focus); |
|
6126 |
#endif |
|
6127 |
#ifndef QT_NO_GRAPHICSVIEW |
|
6128 |
if (QWExtra *topData = window()->d_func()->extra) { |
|
6129 |
if (topData->proxyWidget) { |
|
6130 |
if (previousProxyFocus && previousProxyFocus != f) { |
|
6131 |
// Send event to self |
|
6132 |
QFocusEvent event(QEvent::FocusOut, reason); |
|
6133 |
QPointer<QWidget> that = previousProxyFocus; |
|
6134 |
QApplication::sendEvent(previousProxyFocus, &event); |
|
6135 |
if (that) |
|
6136 |
QApplication::sendEvent(that->style(), &event); |
|
6137 |
} |
|
6138 |
if (!isHidden()) { |
|
6139 |
// Send event to self |
|
6140 |
QFocusEvent event(QEvent::FocusIn, reason); |
|
6141 |
QPointer<QWidget> that = f; |
|
6142 |
QApplication::sendEvent(f, &event); |
|
6143 |
if (that) |
|
6144 |
QApplication::sendEvent(that->style(), &event); |
|
6145 |
} |
|
6146 |
} |
|
6147 |
} |
|
6148 |
#endif |
|
6149 |
} |
|
6150 |
} |
|
6151 |
||
6152 |
/*! |
|
6153 |
\fn void QWidget::setFocus() |
|
6154 |
\overload |
|
6155 |
||
6156 |
Gives the keyboard input focus to this widget (or its focus |
|
6157 |
proxy) if this widget or one of its parents is the |
|
6158 |
\l{isActiveWindow()}{active window}. |
|
6159 |
*/ |
|
6160 |
||
6161 |
/*! |
|
6162 |
Takes keyboard input focus from the widget. |
|
6163 |
||
6164 |
If the widget has active focus, a \link focusOutEvent() focus out |
|
6165 |
event\endlink is sent to this widget to tell it that it is about |
|
6166 |
to lose the focus. |
|
6167 |
||
6168 |
This widget must enable focus setting in order to get the keyboard |
|
6169 |
input focus, i.e. it must call setFocusPolicy(). |
|
6170 |
||
6171 |
\sa hasFocus(), setFocus(), focusInEvent(), focusOutEvent(), |
|
6172 |
setFocusPolicy(), QApplication::focusWidget() |
|
6173 |
*/ |
|
6174 |
||
6175 |
void QWidget::clearFocus() |
|
6176 |
{ |
|
6177 |
QWidget *w = this; |
|
6178 |
while (w) { |
|
6179 |
if (w->d_func()->focus_child == this) |
|
6180 |
w->d_func()->focus_child = 0; |
|
6181 |
w = w->parentWidget(); |
|
6182 |
} |
|
6183 |
#ifndef QT_NO_GRAPHICSVIEW |
|
6184 |
QWExtra *topData = d_func()->extra; |
|
6185 |
if (topData && topData->proxyWidget) |
|
6186 |
topData->proxyWidget->clearFocus(); |
|
6187 |
#endif |
|
6188 |
||
6189 |
if (hasFocus()) { |
|
6190 |
// Update proxy state |
|
6191 |
QApplicationPrivate::setFocusWidget(0, Qt::OtherFocusReason); |
|
6192 |
#if defined(Q_WS_WIN) |
|
6193 |
if (!(windowType() == Qt::Popup) && GetFocus() == internalWinId()) |
|
6194 |
SetFocus(0); |
|
6195 |
else |
|
6196 |
#endif |
|
6197 |
{ |
|
6198 |
#ifndef QT_NO_ACCESSIBILITY |
|
6199 |
QAccessible::updateAccessibility(this, 0, QAccessible::Focus); |
|
6200 |
#endif |
|
6201 |
} |
|
6202 |
} |
|
6203 |
} |
|
6204 |
||
6205 |
||
6206 |
/*! |
|
6207 |
\fn bool QWidget::focusNextChild() |
|
6208 |
||
6209 |
Finds a new widget to give the keyboard focus to, as appropriate |
|
6210 |
for \key Tab, and returns true if it can find a new widget, or |
|
6211 |
false if it can't. |
|
6212 |
||
6213 |
\sa focusPreviousChild() |
|
6214 |
*/ |
|
6215 |
||
6216 |
/*! |
|
6217 |
\fn bool QWidget::focusPreviousChild() |
|
6218 |
||
6219 |
Finds a new widget to give the keyboard focus to, as appropriate |
|
6220 |
for \key Shift+Tab, and returns true if it can find a new widget, |
|
6221 |
or false if it can't. |
|
6222 |
||
6223 |
\sa focusNextChild() |
|
6224 |
*/ |
|
6225 |
||
6226 |
/*! |
|
6227 |
Finds a new widget to give the keyboard focus to, as appropriate |
|
6228 |
for Tab and Shift+Tab, and returns true if it can find a new |
|
6229 |
widget, or false if it can't. |
|
6230 |
||
6231 |
If \a next is true, this function searches forward, if \a next |
|
6232 |
is false, it searches backward. |
|
6233 |
||
6234 |
Sometimes, you will want to reimplement this function. For |
|
6235 |
example, a web browser might reimplement it to move its "current |
|
6236 |
active link" forward or backward, and call |
|
6237 |
focusNextPrevChild() only when it reaches the last or |
|
6238 |
first link on the "page". |
|
6239 |
||
6240 |
Child widgets call focusNextPrevChild() on their parent widgets, |
|
6241 |
but only the window that contains the child widgets decides where |
|
6242 |
to redirect focus. By reimplementing this function for an object, |
|
6243 |
you thus gain control of focus traversal for all child widgets. |
|
6244 |
||
6245 |
\sa focusNextChild(), focusPreviousChild() |
|
6246 |
*/ |
|
6247 |
||
6248 |
bool QWidget::focusNextPrevChild(bool next) |
|
6249 |
{ |
|
6250 |
Q_D(QWidget); |
|
6251 |
QWidget* p = parentWidget(); |
|
6252 |
bool isSubWindow = (windowType() == Qt::SubWindow); |
|
6253 |
if (!isWindow() && !isSubWindow && p) |
|
6254 |
return p->focusNextPrevChild(next); |
|
6255 |
#ifndef QT_NO_GRAPHICSVIEW |
|
6256 |
if (d->extra && d->extra->proxyWidget) |
|
6257 |
return d->extra->proxyWidget->focusNextPrevChild(next); |
|
6258 |
#endif |
|
6259 |
QWidget *w = QApplicationPrivate::focusNextPrevChild_helper(this, next); |
|
6260 |
if (!w) return false; |
|
6261 |
||
6262 |
w->setFocus(next ? Qt::TabFocusReason : Qt::BacktabFocusReason); |
|
6263 |
return true; |
|
6264 |
} |
|
6265 |
||
6266 |
/*! |
|
6267 |
Returns the last child of this widget that setFocus had been |
|
6268 |
called on. For top level widgets this is the widget that will get |
|
6269 |
focus in case this window gets activated |
|
6270 |
||
6271 |
This is not the same as QApplication::focusWidget(), which returns |
|
6272 |
the focus widget in the currently active window. |
|
6273 |
*/ |
|
6274 |
||
6275 |
QWidget *QWidget::focusWidget() const |
|
6276 |
{ |
|
6277 |
return const_cast<QWidget *>(d_func()->focus_child); |
|
6278 |
} |
|
6279 |
||
6280 |
/*! |
|
6281 |
Returns the next widget in this widget's focus chain. |
|
6282 |
||
6283 |
\sa previousInFocusChain() |
|
6284 |
*/ |
|
6285 |
QWidget *QWidget::nextInFocusChain() const |
|
6286 |
{ |
|
6287 |
return const_cast<QWidget *>(d_func()->focus_next); |
|
6288 |
} |
|
6289 |
||
6290 |
/*! |
|
6291 |
\brief The previousInFocusChain function returns the previous |
|
6292 |
widget in this widget's focus chain. |
|
6293 |
||
6294 |
\sa nextInFocusChain() |
|
6295 |
||
6296 |
\since 4.6 |
|
6297 |
*/ |
|
6298 |
QWidget *QWidget::previousInFocusChain() const |
|
6299 |
{ |
|
6300 |
return const_cast<QWidget *>(d_func()->focus_prev); |
|
6301 |
} |
|
6302 |
||
6303 |
/*! |
|
6304 |
\property QWidget::isActiveWindow |
|
6305 |
\brief whether this widget's window is the active window |
|
6306 |
||
6307 |
The active window is the window that contains the widget that has |
|
6308 |
keyboard focus (The window may still have focus if it has no |
|
6309 |
widgets or none of its widgets accepts keyboard focus). |
|
6310 |
||
6311 |
When popup windows are visible, this property is true for both the |
|
6312 |
active window \e and for the popup. |
|
6313 |
||
6314 |
By default, this property is false. |
|
6315 |
||
6316 |
\sa activateWindow(), QApplication::activeWindow() |
|
6317 |
*/ |
|
6318 |
bool QWidget::isActiveWindow() const |
|
6319 |
{ |
|
6320 |
QWidget *tlw = window(); |
|
6321 |
if(tlw == QApplication::activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup))) |
|
6322 |
return true; |
|
6323 |
||
6324 |
#ifndef QT_NO_GRAPHICSVIEW |
|
6325 |
if (QWExtra *tlwExtra = tlw->d_func()->extra) { |
|
6326 |
if (isVisible() && tlwExtra->proxyWidget) |
|
6327 |
return tlwExtra->proxyWidget->isActiveWindow(); |
|
6328 |
} |
|
6329 |
#endif |
|
6330 |
||
6331 |
#ifdef Q_WS_MAC |
|
6332 |
extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp |
|
6333 |
if(qt_mac_is_macdrawer(tlw) && |
|
6334 |
tlw->parentWidget() && tlw->parentWidget()->isActiveWindow()) |
|
6335 |
return true; |
|
6336 |
||
6337 |
extern bool qt_mac_insideKeyWindow(const QWidget *); //qwidget_mac.cpp |
|
6338 |
if (QApplication::testAttribute(Qt::AA_MacPluginApplication) && qt_mac_insideKeyWindow(tlw)) |
|
6339 |
return true; |
|
6340 |
#endif |
|
6341 |
if(style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, this)) { |
|
6342 |
if(tlw->windowType() == Qt::Tool && |
|
6343 |
!tlw->isModal() && |
|
6344 |
(!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow())) |
|
6345 |
return true; |
|
6346 |
QWidget *w = QApplication::activeWindow(); |
|
6347 |
while(w && tlw->windowType() == Qt::Tool && |
|
6348 |
!w->isModal() && w->parentWidget()) { |
|
6349 |
w = w->parentWidget()->window(); |
|
6350 |
if(w == tlw) |
|
6351 |
return true; |
|
6352 |
} |
|
6353 |
} |
|
6354 |
#if defined(Q_WS_WIN32) |
|
6355 |
HWND active = GetActiveWindow(); |
|
6356 |
if (!tlw->testAttribute(Qt::WA_WState_Created)) |
|
6357 |
return false; |
|
6358 |
return active == tlw->internalWinId() || ::IsChild(active, tlw->internalWinId()); |
|
6359 |
#else |
|
6360 |
return false; |
|
6361 |
#endif |
|
6362 |
} |
|
6363 |
||
6364 |
/*! |
|
6365 |
Puts the \a second widget after the \a first widget in the focus order. |
|
6366 |
||
6367 |
Note that since the tab order of the \a second widget is changed, you |
|
6368 |
should order a chain like this: |
|
6369 |
||
6370 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 9 |
|
6371 |
||
6372 |
\e not like this: |
|
6373 |
||
6374 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 10 |
|
6375 |
||
6376 |
If \a first or \a second has a focus proxy, setTabOrder() |
|
6377 |
correctly substitutes the proxy. |
|
6378 |
||
6379 |
\sa setFocusPolicy(), setFocusProxy(), {Keyboard Focus} |
|
6380 |
*/ |
|
6381 |
void QWidget::setTabOrder(QWidget* first, QWidget *second) |
|
6382 |
{ |
|
6383 |
if (!first || !second || first->focusPolicy() == Qt::NoFocus || second->focusPolicy() == Qt::NoFocus) |
|
6384 |
return; |
|
6385 |
||
6386 |
if (first->window() != second->window()) { |
|
6387 |
qWarning("QWidget::setTabOrder: 'first' and 'second' must be in the same window"); |
|
6388 |
return; |
|
6389 |
} |
|
6390 |
||
6391 |
QWidget *fp = first->focusProxy(); |
|
6392 |
if (fp) { |
|
6393 |
// If first is redirected, set first to the last child of first |
|
6394 |
// that can take keyboard focus so that second is inserted after |
|
6395 |
// that last child, and the focus order within first is (more |
|
6396 |
// likely to be) preserved. |
|
6397 |
QList<QWidget *> l = qFindChildren<QWidget *>(first); |
|
6398 |
for (int i = l.size()-1; i >= 0; --i) { |
|
6399 |
QWidget * next = l.at(i); |
|
6400 |
if (next->window() == fp->window()) { |
|
6401 |
fp = next; |
|
6402 |
if (fp->focusPolicy() != Qt::NoFocus) |
|
6403 |
break; |
|
6404 |
} |
|
6405 |
} |
|
6406 |
first = fp; |
|
6407 |
} |
|
6408 |
||
6409 |
||
6410 |
if (QWidget *sp = second->focusProxy()) |
|
6411 |
second = sp; |
|
6412 |
||
6413 |
// QWidget *fp = first->d_func()->focus_prev; |
|
6414 |
QWidget *fn = first->d_func()->focus_next; |
|
6415 |
||
6416 |
if (fn == second) |
|
6417 |
return; |
|
6418 |
||
6419 |
QWidget *sp = second->d_func()->focus_prev; |
|
6420 |
QWidget *sn = second->d_func()->focus_next; |
|
6421 |
||
6422 |
fn->d_func()->focus_prev = second; |
|
6423 |
first->d_func()->focus_next = second; |
|
6424 |
||
6425 |
second->d_func()->focus_next = fn; |
|
6426 |
second->d_func()->focus_prev = first; |
|
6427 |
||
6428 |
sp->d_func()->focus_next = sn; |
|
6429 |
sn->d_func()->focus_prev = sp; |
|
6430 |
||
6431 |
||
6432 |
Q_ASSERT(first->d_func()->focus_next->d_func()->focus_prev == first); |
|
6433 |
Q_ASSERT(first->d_func()->focus_prev->d_func()->focus_next == first); |
|
6434 |
||
6435 |
Q_ASSERT(second->d_func()->focus_next->d_func()->focus_prev == second); |
|
6436 |
Q_ASSERT(second->d_func()->focus_prev->d_func()->focus_next == second); |
|
6437 |
} |
|
6438 |
||
6439 |
/*!\internal |
|
6440 |
||
6441 |
Moves the relevant subwidgets of this widget from the \a oldtlw's |
|
6442 |
tab chain to that of the new parent, if there's anything to move and |
|
6443 |
we're really moving |
|
6444 |
||
6445 |
This function is called from QWidget::reparent() *after* the widget |
|
6446 |
has been reparented. |
|
6447 |
||
6448 |
\sa reparent() |
|
6449 |
*/ |
|
6450 |
||
6451 |
void QWidgetPrivate::reparentFocusWidgets(QWidget * oldtlw) |
|
6452 |
{ |
|
6453 |
Q_Q(QWidget); |
|
6454 |
if (oldtlw == q->window()) |
|
6455 |
return; // nothing to do |
|
6456 |
||
6457 |
if(focus_child) |
|
6458 |
focus_child->clearFocus(); |
|
6459 |
||
6460 |
// separate the focus chain into new (children of myself) and old (the rest) |
|
6461 |
QWidget *firstOld = 0; |
|
6462 |
//QWidget *firstNew = q; //invariant |
|
6463 |
QWidget *o = 0; // last in the old list |
|
6464 |
QWidget *n = q; // last in the new list |
|
6465 |
||
6466 |
bool prevWasNew = true; |
|
6467 |
QWidget *w = focus_next; |
|
6468 |
||
6469 |
//Note: for efficiency, we do not maintain the list invariant inside the loop |
|
6470 |
//we append items to the relevant list, and we optimize by not changing pointers |
|
6471 |
//when subsequent items are going into the same list. |
|
6472 |
while (w != q) { |
|
6473 |
bool currentIsNew = q->isAncestorOf(w); |
|
6474 |
if (currentIsNew) { |
|
6475 |
if (!prevWasNew) { |
|
6476 |
//prev was old -- append to new list |
|
6477 |
n->d_func()->focus_next = w; |
|
6478 |
w->d_func()->focus_prev = n; |
|
6479 |
} |
|
6480 |
n = w; |
|
6481 |
} else { |
|
6482 |
if (prevWasNew) { |
|
6483 |
//prev was new -- append to old list, if there is one |
|
6484 |
if (o) { |
|
6485 |
o->d_func()->focus_next = w; |
|
6486 |
w->d_func()->focus_prev = o; |
|
6487 |
} else { |
|
6488 |
// "create" the old list |
|
6489 |
firstOld = w; |
|
6490 |
} |
|
6491 |
} |
|
6492 |
o = w; |
|
6493 |
} |
|
6494 |
w = w->d_func()->focus_next; |
|
6495 |
prevWasNew = currentIsNew; |
|
6496 |
} |
|
6497 |
||
6498 |
//repair the old list: |
|
6499 |
if (firstOld) { |
|
6500 |
o->d_func()->focus_next = firstOld; |
|
6501 |
firstOld->d_func()->focus_prev = o; |
|
6502 |
} |
|
6503 |
||
6504 |
if (!q->isWindow()) { |
|
6505 |
QWidget *topLevel = q->window(); |
|
6506 |
//insert new chain into toplevel's chain |
|
6507 |
||
6508 |
QWidget *prev = topLevel->d_func()->focus_prev; |
|
6509 |
||
6510 |
topLevel->d_func()->focus_prev = n; |
|
6511 |
prev->d_func()->focus_next = q; |
|
6512 |
||
6513 |
focus_prev = prev; |
|
6514 |
n->d_func()->focus_next = topLevel; |
|
6515 |
} else { |
|
6516 |
//repair the new list |
|
6517 |
n->d_func()->focus_next = q; |
|
6518 |
focus_prev = n; |
|
6519 |
} |
|
6520 |
||
6521 |
} |
|
6522 |
||
6523 |
/*!\internal |
|
6524 |
||
6525 |
Measures the shortest distance from a point to a rect. |
|
6526 |
||
6527 |
This function is called from QDesktopwidget::screen(QPoint) to find the |
|
6528 |
closest screen for a point. |
|
6529 |
In directional KeypadNavigation, it is called to find the closest |
|
6530 |
widget to the current focus widget center. |
|
6531 |
*/ |
|
6532 |
int QWidgetPrivate::pointToRect(const QPoint &p, const QRect &r) |
|
6533 |
{ |
|
6534 |
int dx = 0; |
|
6535 |
int dy = 0; |
|
6536 |
if (p.x() < r.left()) |
|
6537 |
dx = r.left() - p.x(); |
|
6538 |
else if (p.x() > r.right()) |
|
6539 |
dx = p.x() - r.right(); |
|
6540 |
if (p.y() < r.top()) |
|
6541 |
dy = r.top() - p.y(); |
|
6542 |
else if (p.y() > r.bottom()) |
|
6543 |
dy = p.y() - r.bottom(); |
|
6544 |
return dx + dy; |
|
6545 |
} |
|
6546 |
||
6547 |
/*! |
|
6548 |
\property QWidget::frameSize |
|
6549 |
\brief the size of the widget including any window frame |
|
6550 |
||
6551 |
By default, this property contains a value that depends on the user's |
|
6552 |
platform and screen geometry. |
|
6553 |
*/ |
|
6554 |
QSize QWidget::frameSize() const |
|
6555 |
{ |
|
6556 |
Q_D(const QWidget); |
|
6557 |
if (isWindow() && !(windowType() == Qt::Popup)) { |
|
6558 |
QRect fs = d->frameStrut(); |
|
6559 |
return QSize(data->crect.width() + fs.left() + fs.right(), |
|
6560 |
data->crect.height() + fs.top() + fs.bottom()); |
|
6561 |
} |
|
6562 |
return data->crect.size(); |
|
6563 |
} |
|
6564 |
||
6565 |
/*! \fn void QWidget::move(int x, int y) |
|
6566 |
||
6567 |
\overload |
|
6568 |
||
6569 |
This corresponds to move(QPoint(\a x, \a y)). |
|
6570 |
*/ |
|
6571 |
||
6572 |
void QWidget::move(const QPoint &p) |
|
6573 |
{ |
|
6574 |
Q_D(QWidget); |
|
6575 |
setAttribute(Qt::WA_Moved); |
|
6576 |
if (isWindow()) |
|
6577 |
d->topData()->posFromMove = true; |
|
6578 |
if (testAttribute(Qt::WA_WState_Created)) { |
|
6579 |
d->setGeometry_sys(p.x() + geometry().x() - QWidget::x(), |
|
6580 |
p.y() + geometry().y() - QWidget::y(), |
|
6581 |
width(), height(), true); |
|
6582 |
d->setDirtyOpaqueRegion(); |
|
6583 |
} else { |
|
6584 |
data->crect.moveTopLeft(p); // no frame yet |
|
6585 |
setAttribute(Qt::WA_PendingMoveEvent); |
|
6586 |
} |
|
6587 |
} |
|
6588 |
||
6589 |
/*! \fn void QWidget::resize(int w, int h) |
|
6590 |
\overload |
|
6591 |
||
6592 |
This corresponds to resize(QSize(\a w, \a h)). |
|
6593 |
*/ |
|
6594 |
||
6595 |
void QWidget::resize(const QSize &s) |
|
6596 |
{ |
|
6597 |
Q_D(QWidget); |
|
6598 |
setAttribute(Qt::WA_Resized); |
|
6599 |
if (testAttribute(Qt::WA_WState_Created)) { |
|
6600 |
d->setGeometry_sys(geometry().x(), geometry().y(), s.width(), s.height(), false); |
|
6601 |
d->setDirtyOpaqueRegion(); |
|
6602 |
} else { |
|
6603 |
data->crect.setSize(s.boundedTo(maximumSize()).expandedTo(minimumSize())); |
|
6604 |
setAttribute(Qt::WA_PendingResizeEvent); |
|
6605 |
} |
|
6606 |
} |
|
6607 |
||
6608 |
void QWidget::setGeometry(const QRect &r) |
|
6609 |
{ |
|
6610 |
Q_D(QWidget); |
|
6611 |
setAttribute(Qt::WA_Resized); |
|
6612 |
setAttribute(Qt::WA_Moved); |
|
6613 |
if (isWindow()) |
|
6614 |
d->topData()->posFromMove = false; |
|
6615 |
if (testAttribute(Qt::WA_WState_Created)) { |
|
6616 |
d->setGeometry_sys(r.x(), r.y(), r.width(), r.height(), true); |
|
6617 |
d->setDirtyOpaqueRegion(); |
|
6618 |
} else { |
|
6619 |
data->crect.setTopLeft(r.topLeft()); |
|
6620 |
data->crect.setSize(r.size().boundedTo(maximumSize()).expandedTo(minimumSize())); |
|
6621 |
setAttribute(Qt::WA_PendingMoveEvent); |
|
6622 |
setAttribute(Qt::WA_PendingResizeEvent); |
|
6623 |
} |
|
6624 |
} |
|
6625 |
||
6626 |
/*! |
|
6627 |
\since 4.2 |
|
6628 |
Saves the current geometry and state for top-level widgets. |
|
6629 |
||
6630 |
To save the geometry when the window closes, you can |
|
6631 |
implement a close event like this: |
|
6632 |
||
6633 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 11 |
|
6634 |
||
6635 |
See the \l{Window Geometry} documentation for an overview of geometry |
|
6636 |
issues with windows. |
|
6637 |
||
6638 |
Use QMainWindow::saveState() to save the geometry and the state of |
|
6639 |
toolbars and dock widgets. |
|
6640 |
||
6641 |
\sa restoreGeometry(), QMainWindow::saveState(), QMainWindow::restoreState() |
|
6642 |
*/ |
|
6643 |
QByteArray QWidget::saveGeometry() const |
|
6644 |
{ |
|
6645 |
QByteArray array; |
|
6646 |
QDataStream stream(&array, QIODevice::WriteOnly); |
|
6647 |
stream.setVersion(QDataStream::Qt_4_0); |
|
6648 |
const quint32 magicNumber = 0x1D9D0CB; |
|
6649 |
quint16 majorVersion = 1; |
|
6650 |
quint16 minorVersion = 0; |
|
6651 |
stream << magicNumber |
|
6652 |
<< majorVersion |
|
6653 |
<< minorVersion |
|
6654 |
<< frameGeometry() |
|
6655 |
<< normalGeometry() |
|
6656 |
<< qint32(QApplication::desktop()->screenNumber(this)) |
|
6657 |
<< quint8(windowState() & Qt::WindowMaximized) |
|
6658 |
<< quint8(windowState() & Qt::WindowFullScreen); |
|
6659 |
return array; |
|
6660 |
} |
|
6661 |
||
6662 |
/*! |
|
6663 |
\since 4.2 |
|
6664 |
||
6665 |
Restores the geometry and state top-level widgets stored in the |
|
6666 |
byte array \a geometry. Returns true on success; otherwise |
|
6667 |
returns false. |
|
6668 |
||
6669 |
If the restored geometry is off-screen, it will be modified to be |
|
6670 |
inside the available screen geometry. |
|
6671 |
||
6672 |
To restore geometry saved using QSettings, you can use code like |
|
6673 |
this: |
|
6674 |
||
6675 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 12 |
|
6676 |
||
6677 |
See the \l{Window Geometry} documentation for an overview of geometry |
|
6678 |
issues with windows. |
|
6679 |
||
6680 |
Use QMainWindow::restoreState() to restore the geometry and the |
|
6681 |
state of toolbars and dock widgets. |
|
6682 |
||
6683 |
\sa saveGeometry(), QSettings, QMainWindow::saveState(), QMainWindow::restoreState() |
|
6684 |
*/ |
|
6685 |
bool QWidget::restoreGeometry(const QByteArray &geometry) |
|
6686 |
{ |
|
6687 |
if (geometry.size() < 4) |
|
6688 |
return false; |
|
6689 |
QDataStream stream(geometry); |
|
6690 |
stream.setVersion(QDataStream::Qt_4_0); |
|
6691 |
||
6692 |
const quint32 magicNumber = 0x1D9D0CB; |
|
6693 |
quint32 storedMagicNumber; |
|
6694 |
stream >> storedMagicNumber; |
|
6695 |
if (storedMagicNumber != magicNumber) |
|
6696 |
return false; |
|
6697 |
||
6698 |
const quint16 currentMajorVersion = 1; |
|
6699 |
quint16 majorVersion = 0; |
|
6700 |
quint16 minorVersion = 0; |
|
6701 |
||
6702 |
stream >> majorVersion >> minorVersion; |
|
6703 |
||
6704 |
if (majorVersion != currentMajorVersion) |
|
6705 |
return false; |
|
6706 |
// (Allow all minor versions.) |
|
6707 |
||
6708 |
QRect restoredFrameGeometry; |
|
6709 |
QRect restoredNormalGeometry; |
|
6710 |
qint32 restoredScreenNumber; |
|
6711 |
quint8 maximized; |
|
6712 |
quint8 fullScreen; |
|
6713 |
||
6714 |
stream >> restoredFrameGeometry |
|
6715 |
>> restoredNormalGeometry |
|
6716 |
>> restoredScreenNumber |
|
6717 |
>> maximized |
|
6718 |
>> fullScreen; |
|
6719 |
||
6720 |
const int frameHeight = 20; |
|
6721 |
if (!restoredFrameGeometry.isValid()) |
|
6722 |
restoredFrameGeometry = QRect(QPoint(0,0), sizeHint()); |
|
6723 |
||
6724 |
if (!restoredNormalGeometry.isValid()) |
|
6725 |
restoredNormalGeometry = QRect(QPoint(0, frameHeight), sizeHint()); |
|
6726 |
if (!restoredNormalGeometry.isValid()) { |
|
6727 |
// use the widget's adjustedSize if the sizeHint() doesn't help |
|
6728 |
restoredNormalGeometry.setSize(restoredNormalGeometry |
|
6729 |
.size() |
|
6730 |
.expandedTo(d_func()->adjustedSize())); |
|
6731 |
} |
|
6732 |
||
6733 |
const QDesktopWidget * const desktop = QApplication::desktop(); |
|
6734 |
if (restoredScreenNumber >= desktop->numScreens()) |
|
6735 |
restoredScreenNumber = desktop->primaryScreen(); |
|
6736 |
||
6737 |
const QRect availableGeometry = desktop->availableGeometry(restoredScreenNumber); |
|
6738 |
||
6739 |
// Modify the restored geometry if we are about to restore to coordinates |
|
6740 |
// that would make the window "lost". This happens if: |
|
6741 |
// - The restored geometry is completely oustside the available geometry |
|
6742 |
// - The title bar is outside the available geometry. |
|
6743 |
// - (Mac only) The window is higher than the available geometry. It must |
|
6744 |
// be possible to bring the size grip on screen by moving the window. |
|
6745 |
#ifdef Q_WS_MAC |
|
6746 |
restoredFrameGeometry.setHeight(qMin(restoredFrameGeometry.height(), availableGeometry.height())); |
|
6747 |
restoredNormalGeometry.setHeight(qMin(restoredNormalGeometry.height(), availableGeometry.height() - frameHeight)); |
|
6748 |
#endif |
|
6749 |
||
6750 |
if (!restoredFrameGeometry.intersects(availableGeometry)) { |
|
6751 |
restoredFrameGeometry.moveBottom(qMin(restoredFrameGeometry.bottom(), availableGeometry.bottom())); |
|
6752 |
restoredFrameGeometry.moveLeft(qMax(restoredFrameGeometry.left(), availableGeometry.left())); |
|
6753 |
restoredFrameGeometry.moveRight(qMin(restoredFrameGeometry.right(), availableGeometry.right())); |
|
6754 |
} |
|
6755 |
restoredFrameGeometry.moveTop(qMax(restoredFrameGeometry.top(), availableGeometry.top())); |
|
6756 |
||
6757 |
if (!restoredNormalGeometry.intersects(availableGeometry)) { |
|
6758 |
restoredNormalGeometry.moveBottom(qMin(restoredNormalGeometry.bottom(), availableGeometry.bottom())); |
|
6759 |
restoredNormalGeometry.moveLeft(qMax(restoredNormalGeometry.left(), availableGeometry.left())); |
|
6760 |
restoredNormalGeometry.moveRight(qMin(restoredNormalGeometry.right(), availableGeometry.right())); |
|
6761 |
} |
|
6762 |
restoredNormalGeometry.moveTop(qMax(restoredNormalGeometry.top(), availableGeometry.top() + frameHeight)); |
|
6763 |
||
6764 |
if (maximized || fullScreen) { |
|
6765 |
// set geomerty before setting the window state to make |
|
6766 |
// sure the window is maximized to the right screen. |
|
6767 |
setGeometry(restoredNormalGeometry); |
|
6768 |
Qt::WindowStates ws = windowState(); |
|
6769 |
if (maximized) |
|
6770 |
ws |= Qt::WindowMaximized; |
|
6771 |
if (fullScreen) |
|
6772 |
ws |= Qt::WindowFullScreen; |
|
6773 |
setWindowState(ws); |
|
6774 |
d_func()->topData()->normalGeometry = restoredNormalGeometry; |
|
6775 |
} else { |
|
6776 |
QPoint offset; |
|
6777 |
#ifdef Q_WS_X11 |
|
6778 |
if (isFullScreen()) |
|
6779 |
offset = d_func()->topData()->fullScreenOffset; |
|
6780 |
#endif |
|
6781 |
setWindowState(windowState() & ~(Qt::WindowMaximized | Qt::WindowFullScreen)); |
|
6782 |
move(restoredFrameGeometry.topLeft() + offset); |
|
6783 |
resize(restoredNormalGeometry.size()); |
|
6784 |
} |
|
6785 |
return true; |
|
6786 |
} |
|
6787 |
||
6788 |
/*!\fn void QWidget::setGeometry(int x, int y, int w, int h) |
|
6789 |
\overload |
|
6790 |
||
6791 |
This corresponds to setGeometry(QRect(\a x, \a y, \a w, \a h)). |
|
6792 |
*/ |
|
6793 |
||
6794 |
/*! |
|
6795 |
Sets the margins around the contents of the widget to have the sizes |
|
6796 |
\a left, \a top, \a right, and \a bottom. The margins are used by |
|
6797 |
the layout system, and may be used by subclasses to specify the area |
|
6798 |
to draw in (e.g. excluding the frame). |
|
6799 |
||
6800 |
Changing the margins will trigger a resizeEvent(). |
|
6801 |
||
6802 |
\sa contentsRect(), getContentsMargins() |
|
6803 |
*/ |
|
6804 |
void QWidget::setContentsMargins(int left, int top, int right, int bottom) |
|
6805 |
{ |
|
6806 |
Q_D(QWidget); |
|
6807 |
if (left == d->leftmargin && top == d->topmargin |
|
6808 |
&& right == d->rightmargin && bottom == d->bottommargin) |
|
6809 |
return; |
|
6810 |
d->leftmargin = left; |
|
6811 |
d->topmargin = top; |
|
6812 |
d->rightmargin = right; |
|
6813 |
d->bottommargin = bottom; |
|
6814 |
||
6815 |
if (QLayout *l=d->layout) |
|
6816 |
l->update(); //force activate; will do updateGeometry |
|
6817 |
else |
|
6818 |
updateGeometry(); |
|
6819 |
||
6820 |
// ### Qt 5: compat, remove |
|
6821 |
if (isVisible()) { |
|
6822 |
update(); |
|
6823 |
QResizeEvent e(data->crect.size(), data->crect.size()); |
|
6824 |
QApplication::sendEvent(this, &e); |
|
6825 |
} else { |
|
6826 |
setAttribute(Qt::WA_PendingResizeEvent, true); |
|
6827 |
} |
|
6828 |
||
6829 |
QEvent e(QEvent::ContentsRectChange); |
|
6830 |
QApplication::sendEvent(this, &e); |
|
6831 |
} |
|
6832 |
||
6833 |
/*! |
|
6834 |
\overload |
|
6835 |
\since 4.6 |
|
6836 |
||
6837 |
\brief The setContentsMargins function sets the margins around the |
|
6838 |
widget's contents. |
|
6839 |
||
6840 |
Sets the margins around the contents of the widget to have the |
|
6841 |
sizes determined by \a margins. The margins are |
|
6842 |
used by the layout system, and may be used by subclasses to |
|
6843 |
specify the area to draw in (e.g. excluding the frame). |
|
6844 |
||
6845 |
Changing the margins will trigger a resizeEvent(). |
|
6846 |
||
6847 |
\sa contentsRect(), getContentsMargins() |
|
6848 |
*/ |
|
6849 |
void QWidget::setContentsMargins(const QMargins &margins) |
|
6850 |
{ |
|
6851 |
setContentsMargins(margins.left(), margins.top(), |
|
6852 |
margins.right(), margins.bottom()); |
|
6853 |
} |
|
6854 |
||
6855 |
/*! |
|
6856 |
Returns the widget's contents margins for \a left, \a top, \a |
|
6857 |
right, and \a bottom. |
|
6858 |
||
6859 |
\sa setContentsMargins(), contentsRect() |
|
6860 |
*/ |
|
6861 |
void QWidget::getContentsMargins(int *left, int *top, int *right, int *bottom) const |
|
6862 |
{ |
|
6863 |
Q_D(const QWidget); |
|
6864 |
if (left) |
|
6865 |
*left = d->leftmargin; |
|
6866 |
if (top) |
|
6867 |
*top = d->topmargin; |
|
6868 |
if (right) |
|
6869 |
*right = d->rightmargin; |
|
6870 |
if (bottom) |
|
6871 |
*bottom = d->bottommargin; |
|
6872 |
} |
|
6873 |
||
6874 |
/*! |
|
6875 |
\since 4.6 |
|
6876 |
||
6877 |
\brief The contentsMargins function returns the widget's contents margins. |
|
6878 |
||
6879 |
\sa getContentsMargins(), setContentsMargins(), contentsRect() |
|
6880 |
*/ |
|
6881 |
QMargins QWidget::contentsMargins() const |
|
6882 |
{ |
|
6883 |
Q_D(const QWidget); |
|
6884 |
return QMargins(d->leftmargin, d->topmargin, d->rightmargin, d->bottommargin); |
|
6885 |
} |
|
6886 |
||
6887 |
||
6888 |
/*! |
|
6889 |
Returns the area inside the widget's margins. |
|
6890 |
||
6891 |
\sa setContentsMargins(), getContentsMargins() |
|
6892 |
*/ |
|
6893 |
QRect QWidget::contentsRect() const |
|
6894 |
{ |
|
6895 |
Q_D(const QWidget); |
|
6896 |
return QRect(QPoint(d->leftmargin, d->topmargin), |
|
6897 |
QPoint(data->crect.width() - 1 - d->rightmargin, |
|
6898 |
data->crect.height() - 1 - d->bottommargin)); |
|
6899 |
||
6900 |
} |
|
6901 |
||
6902 |
||
6903 |
||
6904 |
/*! |
|
6905 |
\fn void QWidget::customContextMenuRequested(const QPoint &pos) |
|
6906 |
||
6907 |
This signal is emitted when the widget's \l contextMenuPolicy is |
|
6908 |
Qt::CustomContextMenu, and the user has requested a context menu on |
|
6909 |
the widget. The position \a pos is the position of the context menu |
|
6910 |
event that the widget receives. Normally this is in widget |
|
6911 |
coordinates. The exception to this rule is QAbstractScrollArea and |
|
6912 |
its subclasses that map the context menu event to coordinates of the |
|
6913 |
\link QAbstractScrollArea::viewport() viewport() \endlink . |
|
6914 |
||
6915 |
||
6916 |
\sa mapToGlobal() QMenu contextMenuPolicy |
|
6917 |
*/ |
|
6918 |
||
6919 |
||
6920 |
/*! |
|
6921 |
\property QWidget::contextMenuPolicy |
|
6922 |
\brief how the widget shows a context menu |
|
6923 |
||
6924 |
The default value of this property is Qt::DefaultContextMenu, |
|
6925 |
which means the contextMenuEvent() handler is called. Other values |
|
6926 |
are Qt::NoContextMenu, Qt::PreventContextMenu, |
|
6927 |
Qt::ActionsContextMenu, and Qt::CustomContextMenu. With |
|
6928 |
Qt::CustomContextMenu, the signal customContextMenuRequested() is |
|
6929 |
emitted. |
|
6930 |
||
6931 |
\sa contextMenuEvent(), customContextMenuRequested(), actions() |
|
6932 |
*/ |
|
6933 |
||
6934 |
Qt::ContextMenuPolicy QWidget::contextMenuPolicy() const |
|
6935 |
{ |
|
6936 |
return (Qt::ContextMenuPolicy)data->context_menu_policy; |
|
6937 |
} |
|
6938 |
||
6939 |
void QWidget::setContextMenuPolicy(Qt::ContextMenuPolicy policy) |
|
6940 |
{ |
|
6941 |
data->context_menu_policy = (uint) policy; |
|
6942 |
} |
|
6943 |
||
6944 |
/*! |
|
6945 |
\property QWidget::focusPolicy |
|
6946 |
\brief the way the widget accepts keyboard focus |
|
6947 |
||
6948 |
The policy is Qt::TabFocus if the widget accepts keyboard |
|
6949 |
focus by tabbing, Qt::ClickFocus if the widget accepts |
|
6950 |
focus by clicking, Qt::StrongFocus if it accepts both, and |
|
6951 |
Qt::NoFocus (the default) if it does not accept focus at |
|
6952 |
all. |
|
6953 |
||
6954 |
You must enable keyboard focus for a widget if it processes |
|
6955 |
keyboard events. This is normally done from the widget's |
|
6956 |
constructor. For instance, the QLineEdit constructor calls |
|
6957 |
setFocusPolicy(Qt::StrongFocus). |
|
6958 |
||
6959 |
If the widget has a focus proxy, then the focus policy will |
|
6960 |
be propagated to it. |
|
6961 |
||
6962 |
\sa focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent(), enabled |
|
6963 |
*/ |
|
6964 |
||
6965 |
||
6966 |
Qt::FocusPolicy QWidget::focusPolicy() const |
|
6967 |
{ |
|
6968 |
return (Qt::FocusPolicy)data->focus_policy; |
|
6969 |
} |
|
6970 |
||
6971 |
void QWidget::setFocusPolicy(Qt::FocusPolicy policy) |
|
6972 |
{ |
|
6973 |
data->focus_policy = (uint) policy; |
|
6974 |
Q_D(QWidget); |
|
6975 |
if (d->extra && d->extra->focus_proxy) |
|
6976 |
d->extra->focus_proxy->setFocusPolicy(policy); |
|
6977 |
} |
|
6978 |
||
6979 |
/*! |
|
6980 |
\property QWidget::updatesEnabled |
|
6981 |
\brief whether updates are enabled |
|
6982 |
||
6983 |
An updates enabled widget receives paint events and has a system |
|
6984 |
background; a disabled widget does not. This also implies that |
|
6985 |
calling update() and repaint() has no effect if updates are |
|
6986 |
disabled. |
|
6987 |
||
6988 |
By default, this property is true. |
|
6989 |
||
6990 |
setUpdatesEnabled() is normally used to disable updates for a |
|
6991 |
short period of time, for instance to avoid screen flicker during |
|
6992 |
large changes. In Qt, widgets normally do not generate screen |
|
6993 |
flicker, but on X11 the server might erase regions on the screen |
|
6994 |
when widgets get hidden before they can be replaced by other |
|
6995 |
widgets. Disabling updates solves this. |
|
6996 |
||
6997 |
Example: |
|
6998 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 13 |
|
6999 |
||
7000 |
Disabling a widget implicitly disables all its children. Enabling a widget |
|
7001 |
enables all child widgets \e except top-level widgets or those that |
|
7002 |
have been explicitly disabled. Re-enabling updates implicitly calls |
|
7003 |
update() on the widget. |
|
7004 |
||
7005 |
\sa paintEvent() |
|
7006 |
*/ |
|
7007 |
void QWidget::setUpdatesEnabled(bool enable) |
|
7008 |
{ |
|
7009 |
Q_D(QWidget); |
|
7010 |
setAttribute(Qt::WA_ForceUpdatesDisabled, !enable); |
|
7011 |
d->setUpdatesEnabled_helper(enable); |
|
7012 |
} |
|
7013 |
||
7014 |
/*! \fn void QWidget::show() |
|
7015 |
||
7016 |
Shows the widget and its child widgets. This function is |
|
7017 |
equivalent to setVisible(true). |
|
7018 |
||
7019 |
\sa raise(), showEvent(), hide(), setVisible(), showMinimized(), showMaximized(), |
|
7020 |
showNormal(), isVisible() |
|
7021 |
*/ |
|
7022 |
||
7023 |
||
7024 |
/*! \internal |
|
7025 |
||
7026 |
Makes the widget visible in the isVisible() meaning of the word. |
|
7027 |
It is only called for toplevels or widgets with visible parents. |
|
7028 |
*/ |
|
7029 |
void QWidgetPrivate::show_recursive() |
|
7030 |
{ |
|
7031 |
Q_Q(QWidget); |
|
7032 |
// polish if necessary |
|
7033 |
||
7034 |
if (!q->testAttribute(Qt::WA_WState_Created)) |
|
7035 |
createRecursively(); |
|
7036 |
q->ensurePolished(); |
|
7037 |
||
7038 |
#ifdef QT3_SUPPORT |
|
7039 |
if(sendChildEvents) |
|
7040 |
QApplication::sendPostedEvents(q, QEvent::ChildInserted); |
|
7041 |
#endif |
|
7042 |
if (!q->isWindow() && q->parentWidget()->d_func()->layout && !q->parentWidget()->data->in_show) |
|
7043 |
q->parentWidget()->d_func()->layout->activate(); |
|
7044 |
// activate our layout before we and our children become visible |
|
7045 |
if (layout) |
|
7046 |
layout->activate(); |
|
7047 |
||
7048 |
show_helper(); |
|
7049 |
} |
|
7050 |
||
7051 |
void QWidgetPrivate::sendPendingMoveAndResizeEvents(bool recursive, bool disableUpdates) |
|
7052 |
{ |
|
7053 |
Q_Q(QWidget); |
|
7054 |
||
7055 |
disableUpdates = disableUpdates && q->updatesEnabled(); |
|
7056 |
if (disableUpdates) |
|
7057 |
q->setAttribute(Qt::WA_UpdatesDisabled); |
|
7058 |
||
7059 |
if (q->testAttribute(Qt::WA_PendingMoveEvent)) { |
|
7060 |
QMoveEvent e(data.crect.topLeft(), data.crect.topLeft()); |
|
7061 |
QApplication::sendEvent(q, &e); |
|
7062 |
q->setAttribute(Qt::WA_PendingMoveEvent, false); |
|
7063 |
} |
|
7064 |
||
7065 |
if (q->testAttribute(Qt::WA_PendingResizeEvent)) { |
|
7066 |
QResizeEvent e(data.crect.size(), QSize()); |
|
7067 |
QApplication::sendEvent(q, &e); |
|
7068 |
q->setAttribute(Qt::WA_PendingResizeEvent, false); |
|
7069 |
} |
|
7070 |
||
7071 |
if (disableUpdates) |
|
7072 |
q->setAttribute(Qt::WA_UpdatesDisabled, false); |
|
7073 |
||
7074 |
if (!recursive) |
|
7075 |
return; |
|
7076 |
||
7077 |
for (int i = 0; i < children.size(); ++i) { |
|
7078 |
if (QWidget *child = qobject_cast<QWidget *>(children.at(i))) |
|
7079 |
child->d_func()->sendPendingMoveAndResizeEvents(recursive, disableUpdates); |
|
7080 |
} |
|
7081 |
} |
|
7082 |
||
7083 |
void QWidgetPrivate::activateChildLayoutsRecursively() |
|
7084 |
{ |
|
7085 |
sendPendingMoveAndResizeEvents(false, true); |
|
7086 |
||
7087 |
for (int i = 0; i < children.size(); ++i) { |
|
7088 |
QWidget *child = qobject_cast<QWidget *>(children.at(i)); |
|
7089 |
if (!child || child->isHidden() || child->isWindow()) |
|
7090 |
continue; |
|
7091 |
||
7092 |
child->ensurePolished(); |
|
7093 |
||
7094 |
// Activate child's layout |
|
7095 |
QWidgetPrivate *childPrivate = child->d_func(); |
|
7096 |
if (childPrivate->layout) |
|
7097 |
childPrivate->layout->activate(); |
|
7098 |
||
7099 |
// Pretend we're visible. |
|
7100 |
const bool wasVisible = child->isVisible(); |
|
7101 |
if (!wasVisible) |
|
7102 |
child->setAttribute(Qt::WA_WState_Visible); |
|
7103 |
||
7104 |
// Do the same for all my children. |
|
7105 |
childPrivate->activateChildLayoutsRecursively(); |
|
7106 |
||
7107 |
// We're not cheating anymore. |
|
7108 |
if (!wasVisible) |
|
7109 |
child->setAttribute(Qt::WA_WState_Visible, false); |
|
7110 |
} |
|
7111 |
} |
|
7112 |
||
7113 |
void QWidgetPrivate::show_helper() |
|
7114 |
{ |
|
7115 |
Q_Q(QWidget); |
|
7116 |
data.in_show = true; // qws optimization |
|
7117 |
// make sure we receive pending move and resize events |
|
7118 |
sendPendingMoveAndResizeEvents(); |
|
7119 |
||
7120 |
// become visible before showing all children |
|
7121 |
q->setAttribute(Qt::WA_WState_Visible); |
|
7122 |
||
7123 |
// finally show all children recursively |
|
7124 |
showChildren(false); |
|
7125 |
||
7126 |
#ifdef QT3_SUPPORT |
|
7127 |
if (q->parentWidget() && sendChildEvents) |
|
7128 |
QApplication::sendPostedEvents(q->parentWidget(), |
|
7129 |
QEvent::ChildInserted); |
|
7130 |
#endif |
|
7131 |
||
7132 |
||
7133 |
// popup handling: new popups and tools need to be raised, and |
|
7134 |
// existing popups must be closed. Also propagate the current |
|
7135 |
// windows's KeyboardFocusChange status. |
|
7136 |
if (q->isWindow()) { |
|
7137 |
if ((q->windowType() == Qt::Tool) || (q->windowType() == Qt::Popup) || q->windowType() == Qt::ToolTip) { |
|
7138 |
q->raise(); |
|
7139 |
if (q->parentWidget() && q->parentWidget()->window()->testAttribute(Qt::WA_KeyboardFocusChange)) |
|
7140 |
q->setAttribute(Qt::WA_KeyboardFocusChange); |
|
7141 |
} else { |
|
7142 |
while (QApplication::activePopupWidget()) { |
|
7143 |
if (!QApplication::activePopupWidget()->close()) |
|
7144 |
break; |
|
7145 |
} |
|
7146 |
} |
|
7147 |
} |
|
7148 |
||
7149 |
// Automatic embedding of child windows of widgets already embedded into |
|
7150 |
// QGraphicsProxyWidget when they are shown the first time. |
|
7151 |
bool isEmbedded = false; |
|
7152 |
#ifndef QT_NO_GRAPHICSVIEW |
|
7153 |
if (q->isWindow()) { |
|
7154 |
isEmbedded = q->graphicsProxyWidget() ? true : false; |
|
7155 |
if (!isEmbedded && !bypassGraphicsProxyWidget(q)) { |
|
7156 |
QGraphicsProxyWidget *ancestorProxy = nearestGraphicsProxyWidget(q->parentWidget()); |
|
7157 |
if (ancestorProxy) { |
|
7158 |
isEmbedded = true; |
|
7159 |
ancestorProxy->d_func()->embedSubWindow(q); |
|
7160 |
} |
|
7161 |
} |
|
7162 |
} |
|
7163 |
#else |
|
7164 |
Q_UNUSED(isEmbedded); |
|
7165 |
#endif |
|
7166 |
||
7167 |
// On Windows, show the popup now so that our own focus handling |
|
7168 |
// stores the correct old focus widget even if it's stolen in the |
|
7169 |
// showevent |
|
7170 |
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_OS_SYMBIAN) |
|
7171 |
if (!isEmbedded && q->windowType() == Qt::Popup) |
|
7172 |
qApp->d_func()->openPopup(q); |
|
7173 |
#endif |
|
7174 |
||
7175 |
// send the show event before showing the window |
|
7176 |
QShowEvent showEvent; |
|
7177 |
QApplication::sendEvent(q, &showEvent); |
|
7178 |
||
7179 |
if (!isEmbedded && q->isModal() && q->isWindow()) |
|
7180 |
// QApplicationPrivate::enterModal *before* show, otherwise the initial |
|
7181 |
// stacking might be wrong |
|
7182 |
QApplicationPrivate::enterModal(q); |
|
7183 |
||
7184 |
||
7185 |
show_sys(); |
|
7186 |
||
7187 |
#if !defined(Q_WS_WIN) && !defined(Q_WS_MAC) && !defined(Q_OS_SYMBIAN) |
|
7188 |
if (!isEmbedded && q->windowType() == Qt::Popup) |
|
7189 |
qApp->d_func()->openPopup(q); |
|
7190 |
#endif |
|
7191 |
||
7192 |
#ifndef QT_NO_ACCESSIBILITY |
|
7193 |
if (q->windowType() != Qt::ToolTip) // Tooltips are read aloud twice in MS narrator. |
|
7194 |
QAccessible::updateAccessibility(q, 0, QAccessible::ObjectShow); |
|
7195 |
#endif |
|
7196 |
||
7197 |
if (QApplicationPrivate::hidden_focus_widget == q) { |
|
7198 |
QApplicationPrivate::hidden_focus_widget = 0; |
|
7199 |
q->setFocus(Qt::OtherFocusReason); |
|
7200 |
} |
|
7201 |
||
7202 |
// Process events when showing a Qt::SplashScreen widget before the event loop |
|
7203 |
// is spinnning; otherwise it might not show up on particular platforms. |
|
7204 |
// This makes QSplashScreen behave the same on all platforms. |
|
7205 |
if (!qApp->d_func()->in_exec && q->windowType() == Qt::SplashScreen) |
|
7206 |
QApplication::processEvents(); |
|
7207 |
||
7208 |
data.in_show = false; // reset qws optimization |
|
7209 |
} |
|
7210 |
||
7211 |
/*! \fn void QWidget::hide() |
|
7212 |
||
7213 |
Hides the widget. This function is equivalent to |
|
7214 |
setVisible(false). |
|
7215 |
||
7216 |
||
7217 |
\note If you are working with QDialog or its subclasses and you invoke |
|
7218 |
the show() function after this function, the dialog will be displayed in |
|
7219 |
its original position. |
|
7220 |
||
7221 |
\sa hideEvent(), isHidden(), show(), setVisible(), isVisible(), close() |
|
7222 |
*/ |
|
7223 |
||
7224 |
/*!\internal |
|
7225 |
*/ |
|
7226 |
void QWidgetPrivate::hide_helper() |
|
7227 |
{ |
|
7228 |
Q_Q(QWidget); |
|
7229 |
||
7230 |
bool isEmbedded = false; |
|
7231 |
#if !defined QT_NO_GRAPHICSVIEW |
|
7232 |
isEmbedded = q->isWindow() && nearestGraphicsProxyWidget(q->parentWidget()) != 0; |
|
7233 |
#else |
|
7234 |
Q_UNUSED(isEmbedded); |
|
7235 |
#endif |
|
7236 |
||
7237 |
if (!isEmbedded && (q->windowType() == Qt::Popup)) |
|
7238 |
qApp->d_func()->closePopup(q); |
|
7239 |
||
7240 |
// Move test modal here. Otherwise, a modal dialog could get |
|
7241 |
// destroyed and we lose all access to its parent because we haven't |
|
7242 |
// left modality. (Eg. modal Progress Dialog) |
|
7243 |
if (!isEmbedded && q->isModal() && q->isWindow()) |
|
7244 |
QApplicationPrivate::leaveModal(q); |
|
7245 |
||
7246 |
#if defined(Q_WS_WIN) |
|
7247 |
if (q->isWindow() && !(q->windowType() == Qt::Popup) && q->parentWidget() |
|
7248 |
&& !q->parentWidget()->isHidden() && q->isActiveWindow()) |
|
7249 |
q->parentWidget()->activateWindow(); // Activate parent |
|
7250 |
#endif |
|
7251 |
||
7252 |
q->setAttribute(Qt::WA_Mapped, false); |
|
7253 |
hide_sys(); |
|
7254 |
||
7255 |
bool wasVisible = q->testAttribute(Qt::WA_WState_Visible); |
|
7256 |
||
7257 |
if (wasVisible) { |
|
7258 |
q->setAttribute(Qt::WA_WState_Visible, false); |
|
7259 |
||
7260 |
} |
|
7261 |
||
7262 |
QHideEvent hideEvent; |
|
7263 |
QApplication::sendEvent(q, &hideEvent); |
|
7264 |
hideChildren(false); |
|
7265 |
||
7266 |
// next bit tries to move the focus if the focus widget is now |
|
7267 |
// hidden. |
|
7268 |
if (wasVisible) { |
|
7269 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) |
|
7270 |
qApp->d_func()->sendSyntheticEnterLeave(q); |
|
7271 |
#endif |
|
7272 |
||
7273 |
QWidget *fw = QApplication::focusWidget(); |
|
7274 |
while (fw && !fw->isWindow()) { |
|
7275 |
if (fw == q) { |
|
7276 |
q->focusNextPrevChild(true); |
|
7277 |
break; |
|
7278 |
} |
|
7279 |
fw = fw->parentWidget(); |
|
7280 |
} |
|
7281 |
} |
|
7282 |
||
7283 |
if (QWidgetBackingStore *bs = maybeBackingStore()) |
|
7284 |
bs->removeDirtyWidget(q); |
|
7285 |
||
7286 |
#ifndef QT_NO_ACCESSIBILITY |
|
7287 |
if (wasVisible) |
|
7288 |
QAccessible::updateAccessibility(q, 0, QAccessible::ObjectHide); |
|
7289 |
#endif |
|
7290 |
} |
|
7291 |
||
7292 |
/*! |
|
7293 |
\fn bool QWidget::isHidden() const |
|
7294 |
||
7295 |
Returns true if the widget is hidden, otherwise returns false. |
|
7296 |
||
7297 |
A hidden widget will only become visible when show() is called on |
|
7298 |
it. It will not be automatically shown when the parent is shown. |
|
7299 |
||
7300 |
To check visiblity, use !isVisible() instead (notice the exclamation mark). |
|
7301 |
||
7302 |
isHidden() implies !isVisible(), but a widget can be not visible |
|
7303 |
and not hidden at the same time. This is the case for widgets that are children of |
|
7304 |
widgets that are not visible. |
|
7305 |
||
7306 |
||
7307 |
Widgets are hidden if: |
|
7308 |
\list |
|
7309 |
\o they were created as independent windows, |
|
7310 |
\o they were created as children of visible widgets, |
|
7311 |
\o hide() or setVisible(false) was called. |
|
7312 |
\endlist |
|
7313 |
*/ |
|
7314 |
||
7315 |
||
7316 |
void QWidget::setVisible(bool visible) |
|
7317 |
{ |
|
7318 |
if (visible) { // show |
|
7319 |
if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) |
|
7320 |
return; |
|
7321 |
||
7322 |
Q_D(QWidget); |
|
7323 |
||
7324 |
// Designer uses a trick to make grabWidget work without showing |
|
7325 |
if (!isWindow() && parentWidget() && parentWidget()->isVisible() |
|
7326 |
&& !parentWidget()->testAttribute(Qt::WA_WState_Created)) |
|
7327 |
parentWidget()->window()->d_func()->createRecursively(); |
|
7328 |
||
7329 |
//we have to at least create toplevels before applyX11SpecificCommandLineArguments |
|
7330 |
//but not children of non-visible parents |
|
7331 |
QWidget *pw = parentWidget(); |
|
7332 |
if (!testAttribute(Qt::WA_WState_Created) |
|
7333 |
&& (isWindow() || pw->testAttribute(Qt::WA_WState_Created))) { |
|
7334 |
create(); |
|
7335 |
} |
|
7336 |
||
7337 |
#if defined(Q_WS_X11) |
|
7338 |
if (windowType() == Qt::Window) |
|
7339 |
QApplicationPrivate::applyX11SpecificCommandLineArguments(this); |
|
7340 |
#elif defined(Q_WS_QWS) |
|
7341 |
if (windowType() == Qt::Window) |
|
7342 |
QApplicationPrivate::applyQWSSpecificCommandLineArguments(this); |
|
7343 |
#endif |
|
7344 |
||
7345 |
bool wasResized = testAttribute(Qt::WA_Resized); |
|
7346 |
Qt::WindowStates initialWindowState = windowState(); |
|
7347 |
||
7348 |
// polish if necessary |
|
7349 |
ensurePolished(); |
|
7350 |
||
7351 |
// remember that show was called explicitly |
|
7352 |
setAttribute(Qt::WA_WState_ExplicitShowHide); |
|
7353 |
// whether we need to inform the parent widget immediately |
|
7354 |
bool needUpdateGeometry = !isWindow() && testAttribute(Qt::WA_WState_Hidden); |
|
7355 |
// we are no longer hidden |
|
7356 |
setAttribute(Qt::WA_WState_Hidden, false); |
|
7357 |
||
7358 |
if (needUpdateGeometry) |
|
7359 |
d->updateGeometry_helper(true); |
|
7360 |
||
7361 |
#ifdef QT3_SUPPORT |
|
7362 |
QApplication::sendPostedEvents(this, QEvent::ChildInserted); |
|
7363 |
#endif |
|
7364 |
// activate our layout before we and our children become visible |
|
7365 |
if (d->layout) |
|
7366 |
d->layout->activate(); |
|
7367 |
||
7368 |
if (!isWindow()) { |
|
7369 |
QWidget *parent = parentWidget(); |
|
7370 |
while (parent && parent->isVisible() && parent->d_func()->layout && !parent->data->in_show) { |
|
7371 |
parent->d_func()->layout->activate(); |
|
7372 |
if (parent->isWindow()) |
|
7373 |
break; |
|
7374 |
parent = parent->parentWidget(); |
|
7375 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7376 |
if (parent) |
0 | 7377 |
parent->d_func()->setDirtyOpaqueRegion(); |
7378 |
} |
|
7379 |
||
7380 |
// adjust size if necessary |
|
7381 |
if (!wasResized |
|
7382 |
&& (isWindow() || !parentWidget()->d_func()->layout)) { |
|
7383 |
if (isWindow()) { |
|
7384 |
adjustSize(); |
|
7385 |
if (windowState() != initialWindowState) |
|
7386 |
setWindowState(initialWindowState); |
|
7387 |
} else { |
|
7388 |
adjustSize(); |
|
7389 |
} |
|
7390 |
setAttribute(Qt::WA_Resized, false); |
|
7391 |
} |
|
7392 |
||
7393 |
setAttribute(Qt::WA_KeyboardFocusChange, false); |
|
7394 |
||
7395 |
if (isWindow() || parentWidget()->isVisible()) { |
|
7396 |
// remove posted quit events when showing a new window |
|
7397 |
QCoreApplication::removePostedEvents(qApp, QEvent::Quit); |
|
7398 |
||
7399 |
d->show_helper(); |
|
7400 |
||
7401 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) |
|
7402 |
qApp->d_func()->sendSyntheticEnterLeave(this); |
|
7403 |
#endif |
|
7404 |
} |
|
7405 |
||
7406 |
QEvent showToParentEvent(QEvent::ShowToParent); |
|
7407 |
QApplication::sendEvent(this, &showToParentEvent); |
|
7408 |
} else { // hide |
|
7409 |
if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) |
|
7410 |
return; |
|
7411 |
#if defined(Q_WS_WIN) |
|
7412 |
// reset WS_DISABLED style in a Blocked window |
|
7413 |
if(isWindow() && testAttribute(Qt::WA_WState_Created) |
|
7414 |
&& QApplicationPrivate::isBlockedByModal(this)) |
|
7415 |
{ |
|
7416 |
LONG dwStyle = GetWindowLong(winId(), GWL_STYLE); |
|
7417 |
dwStyle &= ~WS_DISABLED; |
|
7418 |
SetWindowLong(winId(), GWL_STYLE, dwStyle); |
|
7419 |
} |
|
7420 |
#endif |
|
7421 |
if (QApplicationPrivate::hidden_focus_widget == this) |
|
7422 |
QApplicationPrivate::hidden_focus_widget = 0; |
|
7423 |
||
7424 |
Q_D(QWidget); |
|
7425 |
||
7426 |
// hw: The test on getOpaqueRegion() needs to be more intelligent |
|
7427 |
// currently it doesn't work if the widget is hidden (the region will |
|
7428 |
// be clipped). The real check should be testing the cached region |
|
7429 |
// (and dirty flag) directly. |
|
7430 |
if (!isWindow() && parentWidget()) // && !d->getOpaqueRegion().isEmpty()) |
|
7431 |
parentWidget()->d_func()->setDirtyOpaqueRegion(); |
|
7432 |
||
7433 |
setAttribute(Qt::WA_WState_Hidden); |
|
7434 |
setAttribute(Qt::WA_WState_ExplicitShowHide); |
|
7435 |
if (testAttribute(Qt::WA_WState_Created)) |
|
7436 |
d->hide_helper(); |
|
7437 |
||
7438 |
// invalidate layout similar to updateGeometry() |
|
7439 |
if (!isWindow() && parentWidget()) { |
|
7440 |
if (parentWidget()->d_func()->layout) |
|
7441 |
parentWidget()->d_func()->layout->invalidate(); |
|
7442 |
else if (parentWidget()->isVisible()) |
|
7443 |
QApplication::postEvent(parentWidget(), new QEvent(QEvent::LayoutRequest)); |
|
7444 |
} |
|
7445 |
||
7446 |
QEvent hideToParentEvent(QEvent::HideToParent); |
|
7447 |
QApplication::sendEvent(this, &hideToParentEvent); |
|
7448 |
} |
|
7449 |
} |
|
7450 |
||
7451 |
/*!\fn void QWidget::setHidden(bool hidden) |
|
7452 |
||
7453 |
Convenience function, equivalent to setVisible(!\a hidden). |
|
7454 |
*/ |
|
7455 |
||
7456 |
/*!\fn void QWidget::setShown(bool shown) |
|
7457 |
||
7458 |
Use setVisible(\a shown) instead. |
|
7459 |
*/ |
|
7460 |
||
7461 |
||
7462 |
void QWidgetPrivate::_q_showIfNotHidden() |
|
7463 |
{ |
|
7464 |
Q_Q(QWidget); |
|
7465 |
if ( !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide)) ) |
|
7466 |
q->setVisible(true); |
|
7467 |
} |
|
7468 |
||
7469 |
void QWidgetPrivate::showChildren(bool spontaneous) |
|
7470 |
{ |
|
7471 |
QList<QObject*> childList = children; |
|
7472 |
for (int i = 0; i < childList.size(); ++i) { |
|
7473 |
QWidget *widget = qobject_cast<QWidget*>(childList.at(i)); |
|
7474 |
if (!widget |
|
7475 |
|| widget->isWindow() |
|
7476 |
|| widget->testAttribute(Qt::WA_WState_Hidden)) |
|
7477 |
continue; |
|
7478 |
if (spontaneous) { |
|
7479 |
widget->setAttribute(Qt::WA_Mapped); |
|
7480 |
widget->d_func()->showChildren(true); |
|
7481 |
QShowEvent e; |
|
7482 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
7483 |
} else { |
|
7484 |
if (widget->testAttribute(Qt::WA_WState_ExplicitShowHide)) |
|
7485 |
widget->d_func()->show_recursive(); |
|
7486 |
else |
|
7487 |
widget->show(); |
|
7488 |
} |
|
7489 |
} |
|
7490 |
} |
|
7491 |
||
7492 |
void QWidgetPrivate::hideChildren(bool spontaneous) |
|
7493 |
{ |
|
7494 |
QList<QObject*> childList = children; |
|
7495 |
for (int i = 0; i < childList.size(); ++i) { |
|
7496 |
QWidget *widget = qobject_cast<QWidget*>(childList.at(i)); |
|
7497 |
if (!widget || widget->isWindow() || widget->testAttribute(Qt::WA_WState_Hidden)) |
|
7498 |
continue; |
|
7499 |
if (spontaneous) |
|
7500 |
widget->setAttribute(Qt::WA_Mapped, false); |
|
7501 |
else |
|
7502 |
widget->setAttribute(Qt::WA_WState_Visible, false); |
|
7503 |
widget->d_func()->hideChildren(spontaneous); |
|
7504 |
QHideEvent e; |
|
7505 |
if (spontaneous) { |
|
7506 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
7507 |
} else { |
|
7508 |
QApplication::sendEvent(widget, &e); |
|
7509 |
if (widget->internalWinId() |
|
7510 |
&& widget->testAttribute(Qt::WA_DontCreateNativeAncestors)) { |
|
7511 |
// hide_sys() on an ancestor won't have any affect on this |
|
7512 |
// widget, so it needs an explicit hide_sys() of its own |
|
7513 |
widget->d_func()->hide_sys(); |
|
7514 |
} |
|
7515 |
} |
|
7516 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) |
|
7517 |
qApp->d_func()->sendSyntheticEnterLeave(widget); |
|
7518 |
#endif |
|
7519 |
#ifndef QT_NO_ACCESSIBILITY |
|
7520 |
if (!spontaneous) |
|
7521 |
QAccessible::updateAccessibility(widget, 0, QAccessible::ObjectHide); |
|
7522 |
#endif |
|
7523 |
} |
|
7524 |
} |
|
7525 |
||
7526 |
bool QWidgetPrivate::close_helper(CloseMode mode) |
|
7527 |
{ |
|
7528 |
if (data.is_closing) |
|
7529 |
return true; |
|
7530 |
||
7531 |
Q_Q(QWidget); |
|
7532 |
data.is_closing = 1; |
|
7533 |
||
7534 |
QPointer<QWidget> that = q; |
|
7535 |
QPointer<QWidget> parentWidget = q->parentWidget(); |
|
7536 |
||
7537 |
#ifdef QT3_SUPPORT |
|
7538 |
bool isMain = (QApplicationPrivate::main_widget == q); |
|
7539 |
#endif |
|
7540 |
bool quitOnClose = q->testAttribute(Qt::WA_QuitOnClose); |
|
7541 |
if (mode != CloseNoEvent) { |
|
7542 |
QCloseEvent e; |
|
7543 |
if (mode == CloseWithSpontaneousEvent) |
|
7544 |
QApplication::sendSpontaneousEvent(q, &e); |
|
7545 |
else |
|
7546 |
QApplication::sendEvent(q, &e); |
|
7547 |
if (!that.isNull() && !e.isAccepted()) { |
|
7548 |
data.is_closing = 0; |
|
7549 |
return false; |
|
7550 |
} |
|
7551 |
} |
|
7552 |
||
7553 |
if (!that.isNull() && !q->isHidden()) |
|
7554 |
q->hide(); |
|
7555 |
||
7556 |
#ifdef QT3_SUPPORT |
|
7557 |
if (isMain) |
|
7558 |
QApplication::quit(); |
|
7559 |
#endif |
|
7560 |
// Attempt to close the application only if this widget has the |
|
7561 |
// WA_QuitOnClose flag set set and has a non-visible parent |
|
7562 |
quitOnClose = quitOnClose && (parentWidget.isNull() || !parentWidget->isVisible() || parentWidget->testAttribute(Qt::WA_DontShowOnScreen)); |
|
7563 |
||
7564 |
if (quitOnClose) { |
|
7565 |
// If there is no non-withdrawn primary window left (except |
|
7566 |
// the ones without QuitOnClose or with WA_DontShowOnScreen), |
|
7567 |
// we emit the lastWindowClosed signal |
|
7568 |
QWidgetList list = QApplication::topLevelWidgets(); |
|
7569 |
bool lastWindowClosed = true; |
|
7570 |
for (int i = 0; i < list.size(); ++i) { |
|
7571 |
QWidget *w = list.at(i); |
|
7572 |
if ((w->isVisible() && !w->testAttribute(Qt::WA_DontShowOnScreen)) |
|
7573 |
&& !w->parentWidget() && w->testAttribute(Qt::WA_QuitOnClose)) { |
|
7574 |
lastWindowClosed = false; |
|
7575 |
break; |
|
7576 |
} |
|
7577 |
} |
|
7578 |
if (lastWindowClosed) |
|
7579 |
QApplicationPrivate::emitLastWindowClosed(); |
|
7580 |
} |
|
7581 |
||
7582 |
if (!that.isNull()) { |
|
7583 |
data.is_closing = 0; |
|
7584 |
if (q->testAttribute(Qt::WA_DeleteOnClose)) { |
|
7585 |
q->setAttribute(Qt::WA_DeleteOnClose, false); |
|
7586 |
q->deleteLater(); |
|
7587 |
} |
|
7588 |
} |
|
7589 |
return true; |
|
7590 |
} |
|
7591 |
||
7592 |
||
7593 |
/*! |
|
7594 |
Closes this widget. Returns true if the widget was closed; |
|
7595 |
otherwise returns false. |
|
7596 |
||
7597 |
First it sends the widget a QCloseEvent. The widget is \link |
|
7598 |
hide() hidden\endlink if it \link QCloseEvent::accept() |
|
7599 |
accepts\endlink the close event. If it \link QCloseEvent::ignore() |
|
7600 |
ignores\endlink the event, nothing happens. The default |
|
7601 |
implementation of QWidget::closeEvent() accepts the close event. |
|
7602 |
||
7603 |
If the widget has the Qt::WA_DeleteOnClose flag, the widget |
|
7604 |
is also deleted. A close events is delivered to the widget no |
|
7605 |
matter if the widget is visible or not. |
|
7606 |
||
7607 |
The \l QApplication::lastWindowClosed() signal is emitted when the |
|
7608 |
last visible primary window (i.e. window with no parent) with the |
|
7609 |
Qt::WA_QuitOnClose attribute set is closed. By default this |
|
7610 |
attribute is set for all widgets except transient windows such as |
|
7611 |
splash screens, tool windows, and popup menus. |
|
7612 |
||
7613 |
*/ |
|
7614 |
||
7615 |
bool QWidget::close() |
|
7616 |
{ |
|
7617 |
return d_func()->close_helper(QWidgetPrivate::CloseWithEvent); |
|
7618 |
} |
|
7619 |
||
7620 |
/*! |
|
7621 |
\property QWidget::visible |
|
7622 |
\brief whether the widget is visible |
|
7623 |
||
7624 |
Calling setVisible(true) or show() sets the widget to visible |
|
7625 |
status if all its parent widgets up to the window are visible. If |
|
7626 |
an ancestor is not visible, the widget won't become visible until |
|
7627 |
all its ancestors are shown. If its size or position has changed, |
|
7628 |
Qt guarantees that a widget gets move and resize events just |
|
7629 |
before it is shown. If the widget has not been resized yet, Qt |
|
7630 |
will adjust the widget's size to a useful default using |
|
7631 |
adjustSize(). |
|
7632 |
||
7633 |
Calling setVisible(false) or hide() hides a widget explicitly. An |
|
7634 |
explicitly hidden widget will never become visible, even if all |
|
7635 |
its ancestors become visible, unless you show it. |
|
7636 |
||
7637 |
A widget receives show and hide events when its visibility status |
|
7638 |
changes. Between a hide and a show event, there is no need to |
|
7639 |
waste CPU cycles preparing or displaying information to the user. |
|
7640 |
A video application, for example, might simply stop generating new |
|
7641 |
frames. |
|
7642 |
||
7643 |
A widget that happens to be obscured by other windows on the |
|
7644 |
screen is considered to be visible. The same applies to iconified |
|
7645 |
windows and windows that exist on another virtual |
|
7646 |
desktop (on platforms that support this concept). A widget |
|
7647 |
receives spontaneous show and hide events when its mapping status |
|
7648 |
is changed by the window system, e.g. a spontaneous hide event |
|
7649 |
when the user minimizes the window, and a spontaneous show event |
|
7650 |
when the window is restored again. |
|
7651 |
||
7652 |
You almost never have to reimplement the setVisible() function. If |
|
7653 |
you need to change some settings before a widget is shown, use |
|
7654 |
showEvent() instead. If you need to do some delayed initialization |
|
7655 |
use the Polish event delivered to the event() function. |
|
7656 |
||
7657 |
\sa show(), hide(), isHidden(), isVisibleTo(), isMinimized(), |
|
7658 |
showEvent(), hideEvent() |
|
7659 |
*/ |
|
7660 |
||
7661 |
||
7662 |
/*! |
|
7663 |
Returns true if this widget would become visible if \a ancestor is |
|
7664 |
shown; otherwise returns false. |
|
7665 |
||
7666 |
The true case occurs if neither the widget itself nor any parent |
|
7667 |
up to but excluding \a ancestor has been explicitly hidden. |
|
7668 |
||
7669 |
This function will still return true if the widget is obscured by |
|
7670 |
other windows on the screen, but could be physically visible if it |
|
7671 |
or they were to be moved. |
|
7672 |
||
7673 |
isVisibleTo(0) is identical to isVisible(). |
|
7674 |
||
7675 |
\sa show() hide() isVisible() |
|
7676 |
*/ |
|
7677 |
||
7678 |
bool QWidget::isVisibleTo(QWidget* ancestor) const |
|
7679 |
{ |
|
7680 |
if (!ancestor) |
|
7681 |
return isVisible(); |
|
7682 |
const QWidget * w = this; |
|
7683 |
while (!w->isHidden() |
|
7684 |
&& !w->isWindow() |
|
7685 |
&& w->parentWidget() |
|
7686 |
&& w->parentWidget() != ancestor) |
|
7687 |
w = w->parentWidget(); |
|
7688 |
return !w->isHidden(); |
|
7689 |
} |
|
7690 |
||
7691 |
#ifdef QT3_SUPPORT |
|
7692 |
/*! |
|
7693 |
Use visibleRegion() instead. |
|
7694 |
*/ |
|
7695 |
QRect QWidget::visibleRect() const |
|
7696 |
{ |
|
7697 |
return d_func()->clipRect(); |
|
7698 |
} |
|
7699 |
#endif |
|
7700 |
||
7701 |
/*! |
|
7702 |
Returns the unobscured region where paint events can occur. |
|
7703 |
||
7704 |
For visible widgets, this is an approximation of the area not |
|
7705 |
covered by other widgets; otherwise, this is an empty region. |
|
7706 |
||
7707 |
The repaint() function calls this function if necessary, so in |
|
7708 |
general you do not need to call it. |
|
7709 |
||
7710 |
*/ |
|
7711 |
QRegion QWidget::visibleRegion() const |
|
7712 |
{ |
|
7713 |
Q_D(const QWidget); |
|
7714 |
||
7715 |
QRect clipRect = d->clipRect(); |
|
7716 |
if (clipRect.isEmpty()) |
|
7717 |
return QRegion(); |
|
7718 |
QRegion r(clipRect); |
|
7719 |
d->subtractOpaqueChildren(r, clipRect); |
|
7720 |
d->subtractOpaqueSiblings(r); |
|
7721 |
#ifdef Q_WS_QWS |
|
7722 |
const QWSWindowSurface *surface = static_cast<const QWSWindowSurface*>(windowSurface()); |
|
7723 |
if (surface) { |
|
7724 |
const QPoint offset = mapTo(surface->window(), QPoint()); |
|
7725 |
r &= surface->clipRegion().translated(-offset); |
|
7726 |
} |
|
7727 |
#endif |
|
7728 |
return r; |
|
7729 |
} |
|
7730 |
||
7731 |
||
7732 |
QSize QWidgetPrivate::adjustedSize() const |
|
7733 |
{ |
|
7734 |
Q_Q(const QWidget); |
|
7735 |
||
7736 |
QSize s = q->sizeHint(); |
|
7737 |
||
7738 |
if (q->isWindow()) { |
|
7739 |
Qt::Orientations exp; |
|
7740 |
if (layout) { |
|
7741 |
if (layout->hasHeightForWidth()) |
|
7742 |
s.setHeight(layout->totalHeightForWidth(s.width())); |
|
7743 |
exp = layout->expandingDirections(); |
|
7744 |
} else |
|
7745 |
{ |
|
7746 |
if (q->sizePolicy().hasHeightForWidth()) |
|
7747 |
s.setHeight(q->heightForWidth(s.width())); |
|
7748 |
exp = q->sizePolicy().expandingDirections(); |
|
7749 |
} |
|
7750 |
if (exp & Qt::Horizontal) |
|
7751 |
s.setWidth(qMax(s.width(), 200)); |
|
7752 |
if (exp & Qt::Vertical) |
|
7753 |
s.setHeight(qMax(s.height(), 100)); |
|
7754 |
#if defined(Q_WS_X11) |
|
7755 |
QRect screen = QApplication::desktop()->screenGeometry(q->x11Info().screen()); |
|
7756 |
#else // all others |
|
7757 |
QRect screen = QApplication::desktop()->screenGeometry(q->pos()); |
|
7758 |
#endif |
|
7759 |
#if defined (Q_WS_WINCE) || defined (Q_OS_SYMBIAN) |
|
7760 |
s.setWidth(qMin(s.width(), screen.width())); |
|
7761 |
s.setHeight(qMin(s.height(), screen.height())); |
|
7762 |
#else |
|
7763 |
s.setWidth(qMin(s.width(), screen.width()*2/3)); |
|
7764 |
s.setHeight(qMin(s.height(), screen.height()*2/3)); |
|
7765 |
#endif |
|
7766 |
if (QTLWExtra *extra = maybeTopData()) |
|
7767 |
extra->sizeAdjusted = true; |
|
7768 |
} |
|
7769 |
||
7770 |
if (!s.isValid()) { |
|
7771 |
QRect r = q->childrenRect(); // get children rectangle |
|
7772 |
if (r.isNull()) |
|
7773 |
return s; |
|
7774 |
s = r.size() + QSize(2 * r.x(), 2 * r.y()); |
|
7775 |
} |
|
7776 |
||
7777 |
return s; |
|
7778 |
} |
|
7779 |
||
7780 |
/*! |
|
7781 |
Adjusts the size of the widget to fit its contents. |
|
7782 |
||
7783 |
This function uses sizeHint() if it is valid, i.e., the size hint's width |
|
7784 |
and height are \>= 0. Otherwise, it sets the size to the children |
|
7785 |
rectangle that covers all child widgets (the union of all child widget |
|
7786 |
rectangles). |
|
7787 |
||
7788 |
For windows, the screen size is also taken into account. If the sizeHint() |
|
7789 |
is less than (200, 100) and the size policy is \l{QSizePolicy::Expanding} |
|
7790 |
{expanding}, the window will be at least (200, 100). The maximum size of |
|
7791 |
a window is 2/3 of the screen's width and height. |
|
7792 |
||
7793 |
\sa sizeHint(), childrenRect() |
|
7794 |
*/ |
|
7795 |
||
7796 |
void QWidget::adjustSize() |
|
7797 |
{ |
|
7798 |
Q_D(QWidget); |
|
7799 |
ensurePolished(); |
|
7800 |
QSize s = d->adjustedSize(); |
|
7801 |
||
7802 |
if (d->layout) |
|
7803 |
d->layout->activate(); |
|
7804 |
||
7805 |
if (s.isValid()) |
|
7806 |
resize(s); |
|
7807 |
} |
|
7808 |
||
7809 |
||
7810 |
/*! |
|
7811 |
\property QWidget::sizeHint |
|
7812 |
\brief the recommended size for the widget |
|
7813 |
||
7814 |
If the value of this property is an invalid size, no size is |
|
7815 |
recommended. |
|
7816 |
||
7817 |
The default implementation of sizeHint() returns an invalid size |
|
7818 |
if there is no layout for this widget, and returns the layout's |
|
7819 |
preferred size otherwise. |
|
7820 |
||
7821 |
\sa QSize::isValid(), minimumSizeHint(), sizePolicy(), |
|
7822 |
setMinimumSize(), updateGeometry() |
|
7823 |
*/ |
|
7824 |
||
7825 |
QSize QWidget::sizeHint() const |
|
7826 |
{ |
|
7827 |
Q_D(const QWidget); |
|
7828 |
if (d->layout) |
|
7829 |
return d->layout->totalSizeHint(); |
|
7830 |
return QSize(-1, -1); |
|
7831 |
} |
|
7832 |
||
7833 |
/*! |
|
7834 |
\property QWidget::minimumSizeHint |
|
7835 |
\brief the recommended minimum size for the widget |
|
7836 |
||
7837 |
If the value of this property is an invalid size, no minimum size |
|
7838 |
is recommended. |
|
7839 |
||
7840 |
The default implementation of minimumSizeHint() returns an invalid |
|
7841 |
size if there is no layout for this widget, and returns the |
|
7842 |
layout's minimum size otherwise. Most built-in widgets reimplement |
|
7843 |
minimumSizeHint(). |
|
7844 |
||
7845 |
\l QLayout will never resize a widget to a size smaller than the |
|
7846 |
minimum size hint unless minimumSize() is set or the size policy is |
|
7847 |
set to QSizePolicy::Ignore. If minimumSize() is set, the minimum |
|
7848 |
size hint will be ignored. |
|
7849 |
||
7850 |
\sa QSize::isValid(), resize(), setMinimumSize(), sizePolicy() |
|
7851 |
*/ |
|
7852 |
QSize QWidget::minimumSizeHint() const |
|
7853 |
{ |
|
7854 |
Q_D(const QWidget); |
|
7855 |
if (d->layout) |
|
7856 |
return d->layout->totalMinimumSize(); |
|
7857 |
return QSize(-1, -1); |
|
7858 |
} |
|
7859 |
||
7860 |
||
7861 |
/*! |
|
7862 |
\fn QWidget *QWidget::parentWidget() const |
|
7863 |
||
7864 |
Returns the parent of this widget, or 0 if it does not have any |
|
7865 |
parent widget. |
|
7866 |
*/ |
|
7867 |
||
7868 |
||
7869 |
/*! |
|
7870 |
Returns true if this widget is a parent, (or grandparent and so on |
|
7871 |
to any level), of the given \a child, and both widgets are within |
|
7872 |
the same window; otherwise returns false. |
|
7873 |
*/ |
|
7874 |
||
7875 |
bool QWidget::isAncestorOf(const QWidget *child) const |
|
7876 |
{ |
|
7877 |
while (child) { |
|
7878 |
if (child == this) |
|
7879 |
return true; |
|
7880 |
if (child->isWindow()) |
|
7881 |
return false; |
|
7882 |
child = child->parentWidget(); |
|
7883 |
} |
|
7884 |
return false; |
|
7885 |
} |
|
7886 |
||
7887 |
#if defined(Q_WS_WIN) |
|
7888 |
inline void setDisabledStyle(QWidget *w, bool setStyle) |
|
7889 |
{ |
|
7890 |
// set/reset WS_DISABLED style. |
|
7891 |
if(w && w->isWindow() && w->isVisible() && w->isEnabled()) { |
|
7892 |
LONG dwStyle = GetWindowLong(w->winId(), GWL_STYLE); |
|
7893 |
if (setStyle) |
|
7894 |
dwStyle |= WS_DISABLED; |
|
7895 |
else |
|
7896 |
dwStyle &= ~WS_DISABLED; |
|
7897 |
SetWindowLong(w->winId(), GWL_STYLE, dwStyle); |
|
7898 |
// we might need to repaint in some situations (eg. menu) |
|
7899 |
w->repaint(); |
|
7900 |
} |
|
7901 |
} |
|
7902 |
#endif |
|
7903 |
||
7904 |
/***************************************************************************** |
|
7905 |
QWidget event handling |
|
7906 |
*****************************************************************************/ |
|
7907 |
||
7908 |
/*! |
|
7909 |
This is the main event handler; it handles event \a event. You can |
|
7910 |
reimplement this function in a subclass, but we recommend using |
|
7911 |
one of the specialized event handlers instead. |
|
7912 |
||
7913 |
Key press and release events are treated differently from other |
|
7914 |
events. event() checks for Tab and Shift+Tab and tries to move the |
|
7915 |
focus appropriately. If there is no widget to move the focus to |
|
7916 |
(or the key press is not Tab or Shift+Tab), event() calls |
|
7917 |
keyPressEvent(). |
|
7918 |
||
7919 |
Mouse and tablet event handling is also slightly special: only |
|
7920 |
when the widget is \l enabled, event() will call the specialized |
|
7921 |
handlers such as mousePressEvent(); otherwise it will discard the |
|
7922 |
event. |
|
7923 |
||
7924 |
This function returns true if the event was recognized, otherwise |
|
7925 |
it returns false. If the recognized event was accepted (see \l |
|
7926 |
QEvent::accepted), any further processing such as event |
|
7927 |
propagation to the parent widget stops. |
|
7928 |
||
7929 |
\sa closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(), |
|
7930 |
keyPressEvent(), keyReleaseEvent(), leaveEvent(), |
|
7931 |
mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), |
|
7932 |
mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(), |
|
7933 |
QObject::event(), QObject::timerEvent() |
|
7934 |
*/ |
|
7935 |
||
7936 |
bool QWidget::event(QEvent *event) |
|
7937 |
{ |
|
7938 |
Q_D(QWidget); |
|
7939 |
||
7940 |
// ignore mouse events when disabled |
|
7941 |
if (!isEnabled()) { |
|
7942 |
switch(event->type()) { |
|
7943 |
case QEvent::TabletPress: |
|
7944 |
case QEvent::TabletRelease: |
|
7945 |
case QEvent::TabletMove: |
|
7946 |
case QEvent::MouseButtonPress: |
|
7947 |
case QEvent::MouseButtonRelease: |
|
7948 |
case QEvent::MouseButtonDblClick: |
|
7949 |
case QEvent::MouseMove: |
|
7950 |
case QEvent::TouchBegin: |
|
7951 |
case QEvent::TouchUpdate: |
|
7952 |
case QEvent::TouchEnd: |
|
7953 |
case QEvent::ContextMenu: |
|
7954 |
#ifndef QT_NO_WHEELEVENT |
|
7955 |
case QEvent::Wheel: |
|
7956 |
#endif |
|
7957 |
return false; |
|
7958 |
default: |
|
7959 |
break; |
|
7960 |
} |
|
7961 |
} |
|
7962 |
switch (event->type()) { |
|
7963 |
case QEvent::MouseMove: |
|
7964 |
mouseMoveEvent((QMouseEvent*)event); |
|
7965 |
break; |
|
7966 |
||
7967 |
case QEvent::MouseButtonPress: |
|
7968 |
// Don't reset input context here. Whether reset or not is |
|
7969 |
// a responsibility of input method. reset() will be |
|
7970 |
// called by mouseHandler() of input method if necessary |
|
7971 |
// via mousePressEvent() of text widgets. |
|
7972 |
#if 0 |
|
7973 |
resetInputContext(); |
|
7974 |
#endif |
|
7975 |
mousePressEvent((QMouseEvent*)event); |
|
7976 |
break; |
|
7977 |
||
7978 |
case QEvent::MouseButtonRelease: |
|
7979 |
mouseReleaseEvent((QMouseEvent*)event); |
|
7980 |
break; |
|
7981 |
||
7982 |
case QEvent::MouseButtonDblClick: |
|
7983 |
mouseDoubleClickEvent((QMouseEvent*)event); |
|
7984 |
break; |
|
7985 |
#ifndef QT_NO_WHEELEVENT |
|
7986 |
case QEvent::Wheel: |
|
7987 |
wheelEvent((QWheelEvent*)event); |
|
7988 |
break; |
|
7989 |
#endif |
|
7990 |
#ifndef QT_NO_TABLETEVENT |
|
7991 |
case QEvent::TabletMove: |
|
7992 |
case QEvent::TabletPress: |
|
7993 |
case QEvent::TabletRelease: |
|
7994 |
tabletEvent((QTabletEvent*)event); |
|
7995 |
break; |
|
7996 |
#endif |
|
7997 |
#ifdef QT3_SUPPORT |
|
7998 |
case QEvent::Accel: |
|
7999 |
event->ignore(); |
|
8000 |
return false; |
|
8001 |
#endif |
|
8002 |
case QEvent::KeyPress: { |
|
8003 |
QKeyEvent *k = (QKeyEvent *)event; |
|
8004 |
bool res = false; |
|
8005 |
if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? |
|
8006 |
if (k->key() == Qt::Key_Backtab |
|
8007 |
|| (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) |
|
8008 |
res = focusNextPrevChild(false); |
|
8009 |
else if (k->key() == Qt::Key_Tab) |
|
8010 |
res = focusNextPrevChild(true); |
|
8011 |
if (res) |
|
8012 |
break; |
|
8013 |
} |
|
8014 |
keyPressEvent(k); |
|
8015 |
#ifdef QT_KEYPAD_NAVIGATION |
|
8016 |
if (!k->isAccepted() && QApplication::keypadNavigationEnabled() |
|
8017 |
&& !(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::ShiftModifier))) { |
|
8018 |
if (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder) { |
|
8019 |
if (k->key() == Qt::Key_Up) |
|
8020 |
res = focusNextPrevChild(false); |
|
8021 |
else if (k->key() == Qt::Key_Down) |
|
8022 |
res = focusNextPrevChild(true); |
|
8023 |
} else if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { |
|
8024 |
if (k->key() == Qt::Key_Up) |
|
8025 |
res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionNorth); |
|
8026 |
else if (k->key() == Qt::Key_Right) |
|
8027 |
res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionEast); |
|
8028 |
else if (k->key() == Qt::Key_Down) |
|
8029 |
res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionSouth); |
|
8030 |
else if (k->key() == Qt::Key_Left) |
|
8031 |
res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionWest); |
|
8032 |
} |
|
8033 |
if (res) { |
|
8034 |
k->accept(); |
|
8035 |
break; |
|
8036 |
} |
|
8037 |
} |
|
8038 |
#endif |
|
8039 |
#ifndef QT_NO_WHATSTHIS |
|
8040 |
if (!k->isAccepted() |
|
8041 |
&& k->modifiers() & Qt::ShiftModifier && k->key() == Qt::Key_F1 |
|
8042 |
&& d->whatsThis.size()) { |
|
8043 |
QWhatsThis::showText(mapToGlobal(inputMethodQuery(Qt::ImMicroFocus).toRect().center()), d->whatsThis, this); |
|
8044 |
k->accept(); |
|
8045 |
} |
|
8046 |
#endif |
|
8047 |
} |
|
8048 |
break; |
|
8049 |
||
8050 |
case QEvent::KeyRelease: |
|
8051 |
keyReleaseEvent((QKeyEvent*)event); |
|
8052 |
// fall through |
|
8053 |
case QEvent::ShortcutOverride: |
|
8054 |
break; |
|
8055 |
||
8056 |
case QEvent::InputMethod: |
|
8057 |
inputMethodEvent((QInputMethodEvent *) event); |
|
8058 |
break; |
|
8059 |
||
8060 |
case QEvent::PolishRequest: |
|
8061 |
ensurePolished(); |
|
8062 |
break; |
|
8063 |
||
8064 |
case QEvent::Polish: { |
|
8065 |
style()->polish(this); |
|
8066 |
setAttribute(Qt::WA_WState_Polished); |
|
8067 |
if (!QApplication::font(this).isCopyOf(QApplication::font())) |
|
8068 |
d->resolveFont(); |
|
8069 |
if (!QApplication::palette(this).isCopyOf(QApplication::palette())) |
|
8070 |
d->resolvePalette(); |
|
8071 |
#ifdef QT3_SUPPORT |
|
8072 |
if(d->sendChildEvents) |
|
8073 |
QApplication::sendPostedEvents(this, QEvent::ChildInserted); |
|
8074 |
#endif |
|
8075 |
} |
|
8076 |
break; |
|
8077 |
||
8078 |
case QEvent::ApplicationWindowIconChange: |
|
8079 |
if (isWindow() && !testAttribute(Qt::WA_SetWindowIcon)) { |
|
8080 |
d->setWindowIcon_sys(); |
|
8081 |
d->setWindowIcon_helper(); |
|
8082 |
} |
|
8083 |
break; |
|
8084 |
case QEvent::FocusIn: |
|
8085 |
#ifdef QT_SOFTKEYS_ENABLED |
|
8086 |
QSoftKeyManager::updateSoftKeys(); |
|
8087 |
#endif |
|
8088 |
focusInEvent((QFocusEvent*)event); |
|
8089 |
break; |
|
8090 |
||
8091 |
case QEvent::FocusOut: |
|
8092 |
focusOutEvent((QFocusEvent*)event); |
|
8093 |
break; |
|
8094 |
||
8095 |
case QEvent::Enter: |
|
8096 |
#ifndef QT_NO_STATUSTIP |
|
8097 |
if (d->statusTip.size()) { |
|
8098 |
QStatusTipEvent tip(d->statusTip); |
|
8099 |
QApplication::sendEvent(const_cast<QWidget *>(this), &tip); |
|
8100 |
} |
|
8101 |
#endif |
|
8102 |
enterEvent(event); |
|
8103 |
break; |
|
8104 |
||
8105 |
case QEvent::Leave: |
|
8106 |
#ifndef QT_NO_STATUSTIP |
|
8107 |
if (d->statusTip.size()) { |
|
8108 |
QString empty; |
|
8109 |
QStatusTipEvent tip(empty); |
|
8110 |
QApplication::sendEvent(const_cast<QWidget *>(this), &tip); |
|
8111 |
} |
|
8112 |
#endif |
|
8113 |
leaveEvent(event); |
|
8114 |
break; |
|
8115 |
||
8116 |
case QEvent::HoverEnter: |
|
8117 |
case QEvent::HoverLeave: |
|
8118 |
update(); |
|
8119 |
break; |
|
8120 |
||
8121 |
case QEvent::Paint: |
|
8122 |
// At this point the event has to be delivered, regardless |
|
8123 |
// whether the widget isVisible() or not because it |
|
8124 |
// already went through the filters |
|
8125 |
paintEvent((QPaintEvent*)event); |
|
8126 |
break; |
|
8127 |
||
8128 |
case QEvent::Move: |
|
8129 |
moveEvent((QMoveEvent*)event); |
|
8130 |
break; |
|
8131 |
||
8132 |
case QEvent::Resize: |
|
8133 |
resizeEvent((QResizeEvent*)event); |
|
8134 |
break; |
|
8135 |
||
8136 |
case QEvent::Close: |
|
8137 |
closeEvent((QCloseEvent *)event); |
|
8138 |
break; |
|
8139 |
||
8140 |
#ifndef QT_NO_CONTEXTMENU |
|
8141 |
case QEvent::ContextMenu: |
|
8142 |
switch (data->context_menu_policy) { |
|
8143 |
case Qt::PreventContextMenu: |
|
8144 |
break; |
|
8145 |
case Qt::DefaultContextMenu: |
|
8146 |
contextMenuEvent(static_cast<QContextMenuEvent *>(event)); |
|
8147 |
break; |
|
8148 |
case Qt::CustomContextMenu: |
|
8149 |
emit customContextMenuRequested(static_cast<QContextMenuEvent *>(event)->pos()); |
|
8150 |
break; |
|
8151 |
#ifndef QT_NO_MENU |
|
8152 |
case Qt::ActionsContextMenu: |
|
8153 |
if (d->actions.count()) { |
|
8154 |
QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(event)->globalPos(), |
|
8155 |
0, this); |
|
8156 |
break; |
|
8157 |
} |
|
8158 |
// fall through |
|
8159 |
#endif |
|
8160 |
default: |
|
8161 |
event->ignore(); |
|
8162 |
break; |
|
8163 |
} |
|
8164 |
break; |
|
8165 |
#endif // QT_NO_CONTEXTMENU |
|
8166 |
||
8167 |
#ifndef QT_NO_DRAGANDDROP |
|
8168 |
case QEvent::Drop: |
|
8169 |
dropEvent((QDropEvent*) event); |
|
8170 |
break; |
|
8171 |
||
8172 |
case QEvent::DragEnter: |
|
8173 |
dragEnterEvent((QDragEnterEvent*) event); |
|
8174 |
break; |
|
8175 |
||
8176 |
case QEvent::DragMove: |
|
8177 |
dragMoveEvent((QDragMoveEvent*) event); |
|
8178 |
break; |
|
8179 |
||
8180 |
case QEvent::DragLeave: |
|
8181 |
dragLeaveEvent((QDragLeaveEvent*) event); |
|
8182 |
break; |
|
8183 |
#endif |
|
8184 |
||
8185 |
case QEvent::Show: |
|
8186 |
showEvent((QShowEvent*) event); |
|
8187 |
break; |
|
8188 |
||
8189 |
case QEvent::Hide: |
|
8190 |
hideEvent((QHideEvent*) event); |
|
8191 |
break; |
|
8192 |
||
8193 |
case QEvent::ShowWindowRequest: |
|
8194 |
if (!isHidden()) |
|
8195 |
d->show_sys(); |
|
8196 |
break; |
|
8197 |
||
8198 |
case QEvent::ApplicationFontChange: |
|
8199 |
d->resolveFont(); |
|
8200 |
break; |
|
8201 |
case QEvent::ApplicationPaletteChange: |
|
8202 |
if (!(windowType() == Qt::Desktop)) |
|
8203 |
d->resolvePalette(); |
|
8204 |
break; |
|
8205 |
||
8206 |
case QEvent::ToolBarChange: |
|
8207 |
case QEvent::ActivationChange: |
|
8208 |
case QEvent::EnabledChange: |
|
8209 |
case QEvent::FontChange: |
|
8210 |
case QEvent::StyleChange: |
|
8211 |
case QEvent::PaletteChange: |
|
8212 |
case QEvent::WindowTitleChange: |
|
8213 |
case QEvent::IconTextChange: |
|
8214 |
case QEvent::ModifiedChange: |
|
8215 |
case QEvent::MouseTrackingChange: |
|
8216 |
case QEvent::ParentChange: |
|
8217 |
case QEvent::WindowStateChange: |
|
8218 |
case QEvent::LocaleChange: |
|
8219 |
case QEvent::MacSizeChange: |
|
8220 |
case QEvent::ContentsRectChange: |
|
8221 |
changeEvent(event); |
|
8222 |
break; |
|
8223 |
||
8224 |
case QEvent::WindowActivate: |
|
8225 |
case QEvent::WindowDeactivate: { |
|
8226 |
#ifdef QT3_SUPPORT |
|
8227 |
windowActivationChange(event->type() != QEvent::WindowActivate); |
|
8228 |
#endif |
|
8229 |
if (isVisible() && !palette().isEqual(QPalette::Active, QPalette::Inactive)) |
|
8230 |
update(); |
|
8231 |
QList<QObject*> childList = d->children; |
|
8232 |
for (int i = 0; i < childList.size(); ++i) { |
|
8233 |
QWidget *w = qobject_cast<QWidget *>(childList.at(i)); |
|
8234 |
if (w && w->isVisible() && !w->isWindow()) |
|
8235 |
QApplication::sendEvent(w, event); |
|
8236 |
} |
|
8237 |
||
8238 |
#ifdef QT_SOFTKEYS_ENABLED |
|
8239 |
if (isWindow() && isActiveWindow()) |
|
8240 |
QSoftKeyManager::updateSoftKeys(); |
|
8241 |
#endif |
|
8242 |
||
8243 |
break; } |
|
8244 |
||
8245 |
case QEvent::LanguageChange: |
|
8246 |
#ifdef QT3_SUPPORT |
|
8247 |
languageChange(); |
|
8248 |
#endif |
|
8249 |
changeEvent(event); |
|
8250 |
{ |
|
8251 |
QList<QObject*> childList = d->children; |
|
8252 |
for (int i = 0; i < childList.size(); ++i) { |
|
8253 |
QObject *o = childList.at(i); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8254 |
if (o) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8255 |
QApplication::sendEvent(o, event); |
0 | 8256 |
} |
8257 |
} |
|
8258 |
update(); |
|
8259 |
break; |
|
8260 |
||
8261 |
case QEvent::ApplicationLayoutDirectionChange: |
|
8262 |
d->resolveLayoutDirection(); |
|
8263 |
break; |
|
8264 |
||
8265 |
case QEvent::LayoutDirectionChange: |
|
8266 |
if (d->layout) |
|
8267 |
d->layout->invalidate(); |
|
8268 |
update(); |
|
8269 |
changeEvent(event); |
|
8270 |
break; |
|
8271 |
case QEvent::UpdateRequest: |
|
8272 |
d->syncBackingStore(); |
|
8273 |
break; |
|
8274 |
case QEvent::UpdateLater: |
|
8275 |
update(static_cast<QUpdateLaterEvent*>(event)->region()); |
|
8276 |
break; |
|
8277 |
||
8278 |
case QEvent::WindowBlocked: |
|
8279 |
case QEvent::WindowUnblocked: |
|
8280 |
{ |
|
8281 |
QList<QObject*> childList = d->children; |
|
8282 |
for (int i = 0; i < childList.size(); ++i) { |
|
8283 |
QObject *o = childList.at(i); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8284 |
if (o && o != QApplication::activeModalWidget()) { |
0 | 8285 |
if (qobject_cast<QWidget *>(o) && static_cast<QWidget *>(o)->isWindow()) { |
8286 |
// do not forward the event to child windows, |
|
8287 |
// QApplication does this for us |
|
8288 |
continue; |
|
8289 |
} |
|
8290 |
QApplication::sendEvent(o, event); |
|
8291 |
} |
|
8292 |
} |
|
8293 |
#if defined(Q_WS_WIN) |
|
8294 |
setDisabledStyle(this, (event->type() == QEvent::WindowBlocked)); |
|
8295 |
#endif |
|
8296 |
} |
|
8297 |
break; |
|
8298 |
#ifndef QT_NO_TOOLTIP |
|
8299 |
case QEvent::ToolTip: |
|
8300 |
if (!d->toolTip.isEmpty()) |
|
8301 |
QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), d->toolTip, this); |
|
8302 |
else |
|
8303 |
event->ignore(); |
|
8304 |
break; |
|
8305 |
#endif |
|
8306 |
#ifndef QT_NO_WHATSTHIS |
|
8307 |
case QEvent::WhatsThis: |
|
8308 |
if (d->whatsThis.size()) |
|
8309 |
QWhatsThis::showText(static_cast<QHelpEvent *>(event)->globalPos(), d->whatsThis, this); |
|
8310 |
else |
|
8311 |
event->ignore(); |
|
8312 |
break; |
|
8313 |
case QEvent::QueryWhatsThis: |
|
8314 |
if (d->whatsThis.isEmpty()) |
|
8315 |
event->ignore(); |
|
8316 |
break; |
|
8317 |
#endif |
|
8318 |
#ifndef QT_NO_ACCESSIBILITY |
|
8319 |
case QEvent::AccessibilityDescription: |
|
8320 |
case QEvent::AccessibilityHelp: { |
|
8321 |
QAccessibleEvent *ev = static_cast<QAccessibleEvent *>(event); |
|
8322 |
if (ev->child()) |
|
8323 |
return false; |
|
8324 |
switch (ev->type()) { |
|
8325 |
#ifndef QT_NO_TOOLTIP |
|
8326 |
case QEvent::AccessibilityDescription: |
|
8327 |
ev->setValue(d->toolTip); |
|
8328 |
break; |
|
8329 |
#endif |
|
8330 |
#ifndef QT_NO_WHATSTHIS |
|
8331 |
case QEvent::AccessibilityHelp: |
|
8332 |
ev->setValue(d->whatsThis); |
|
8333 |
break; |
|
8334 |
#endif |
|
8335 |
default: |
|
8336 |
return false; |
|
8337 |
} |
|
8338 |
break; } |
|
8339 |
#endif |
|
8340 |
case QEvent::EmbeddingControl: |
|
8341 |
d->topData()->frameStrut.setCoords(0 ,0, 0, 0); |
|
8342 |
data->fstrut_dirty = false; |
|
8343 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
8344 |
d->topData()->embedded = 1; |
|
8345 |
#endif |
|
8346 |
break; |
|
8347 |
#ifndef QT_NO_ACTION |
|
8348 |
case QEvent::ActionAdded: |
|
8349 |
case QEvent::ActionRemoved: |
|
8350 |
case QEvent::ActionChanged: |
|
8351 |
#ifdef QT_SOFTKEYS_ENABLED |
|
8352 |
QSoftKeyManager::updateSoftKeys(); |
|
8353 |
#endif |
|
8354 |
actionEvent((QActionEvent*)event); |
|
8355 |
break; |
|
8356 |
#endif |
|
8357 |
||
8358 |
case QEvent::KeyboardLayoutChange: |
|
8359 |
{ |
|
8360 |
changeEvent(event); |
|
8361 |
||
8362 |
// inform children of the change |
|
8363 |
QList<QObject*> childList = d->children; |
|
8364 |
for (int i = 0; i < childList.size(); ++i) { |
|
8365 |
QWidget *w = qobject_cast<QWidget *>(childList.at(i)); |
|
8366 |
if (w && w->isVisible() && !w->isWindow()) |
|
8367 |
QApplication::sendEvent(w, event); |
|
8368 |
} |
|
8369 |
break; |
|
8370 |
} |
|
8371 |
#ifdef Q_WS_MAC |
|
8372 |
case QEvent::MacGLWindowChange: |
|
8373 |
d->needWindowChange = false; |
|
8374 |
break; |
|
8375 |
#endif |
|
8376 |
case QEvent::TouchBegin: |
|
8377 |
case QEvent::TouchUpdate: |
|
8378 |
case QEvent::TouchEnd: |
|
8379 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8380 |
#ifndef Q_WS_MAC |
0 | 8381 |
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); |
8382 |
const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8383 |
if (touchPoint.isPrimary() || touchEvent->deviceType() == QTouchEvent::TouchPad) |
0 | 8384 |
break; |
8385 |
||
8386 |
// fake a mouse event! |
|
8387 |
QEvent::Type eventType = QEvent::None; |
|
8388 |
switch (touchEvent->type()) { |
|
8389 |
case QEvent::TouchBegin: |
|
8390 |
eventType = QEvent::MouseButtonPress; |
|
8391 |
break; |
|
8392 |
case QEvent::TouchUpdate: |
|
8393 |
eventType = QEvent::MouseMove; |
|
8394 |
break; |
|
8395 |
case QEvent::TouchEnd: |
|
8396 |
eventType = QEvent::MouseButtonRelease; |
|
8397 |
break; |
|
8398 |
default: |
|
8399 |
Q_ASSERT(!true); |
|
8400 |
break; |
|
8401 |
} |
|
8402 |
if (eventType == QEvent::None) |
|
8403 |
break; |
|
8404 |
||
8405 |
QMouseEvent mouseEvent(eventType, |
|
8406 |
touchPoint.pos().toPoint(), |
|
8407 |
touchPoint.screenPos().toPoint(), |
|
8408 |
Qt::LeftButton, |
|
8409 |
Qt::LeftButton, |
|
8410 |
touchEvent->modifiers()); |
|
8411 |
(void) QApplication::sendEvent(this, &mouseEvent); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8412 |
#endif // Q_WS_MAC |
0 | 8413 |
break; |
8414 |
} |
|
8415 |
case QEvent::Gesture: |
|
8416 |
event->ignore(); |
|
8417 |
break; |
|
8418 |
#ifndef QT_NO_PROPERTIES |
|
8419 |
case QEvent::DynamicPropertyChange: { |
|
8420 |
const QByteArray &propName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName(); |
|
8421 |
if (!qstrncmp(propName, "_q_customDpi", 12) && propName.length() == 13) { |
|
8422 |
uint value = property(propName.constData()).toUInt(); |
|
8423 |
if (!d->extra) |
|
8424 |
d->createExtra(); |
|
8425 |
const char axis = propName.at(12); |
|
8426 |
if (axis == 'X') |
|
8427 |
d->extra->customDpiX = value; |
|
8428 |
else if (axis == 'Y') |
|
8429 |
d->extra->customDpiY = value; |
|
8430 |
d->updateFont(d->data.fnt); |
|
8431 |
} |
|
8432 |
// fall through |
|
8433 |
} |
|
8434 |
#endif |
|
8435 |
default: |
|
8436 |
return QObject::event(event); |
|
8437 |
} |
|
8438 |
return true; |
|
8439 |
} |
|
8440 |
||
8441 |
/*! |
|
8442 |
This event handler can be reimplemented to handle state changes. |
|
8443 |
||
8444 |
The state being changed in this event can be retrieved through event \a |
|
8445 |
event. |
|
8446 |
||
8447 |
Change events include: QEvent::ToolBarChange, |
|
8448 |
QEvent::ActivationChange, QEvent::EnabledChange, QEvent::FontChange, |
|
8449 |
QEvent::StyleChange, QEvent::PaletteChange, |
|
8450 |
QEvent::WindowTitleChange, QEvent::IconTextChange, |
|
8451 |
QEvent::ModifiedChange, QEvent::MouseTrackingChange, |
|
8452 |
QEvent::ParentChange, QEvent::WindowStateChange, |
|
8453 |
QEvent::LanguageChange, QEvent::LocaleChange, |
|
8454 |
QEvent::LayoutDirectionChange. |
|
8455 |
||
8456 |
*/ |
|
8457 |
void QWidget::changeEvent(QEvent * event) |
|
8458 |
{ |
|
8459 |
switch(event->type()) { |
|
8460 |
case QEvent::EnabledChange: |
|
8461 |
update(); |
|
8462 |
#ifndef QT_NO_ACCESSIBILITY |
|
8463 |
QAccessible::updateAccessibility(this, 0, QAccessible::StateChanged); |
|
8464 |
#endif |
|
8465 |
break; |
|
8466 |
||
8467 |
case QEvent::FontChange: |
|
8468 |
case QEvent::StyleChange: { |
|
8469 |
Q_D(QWidget); |
|
8470 |
update(); |
|
8471 |
updateGeometry(); |
|
8472 |
if (d->layout) |
|
8473 |
d->layout->invalidate(); |
|
8474 |
#ifdef Q_WS_QWS |
|
8475 |
if (isWindow()) |
|
8476 |
d->data.fstrut_dirty = true; |
|
8477 |
#endif |
|
8478 |
break; |
|
8479 |
} |
|
8480 |
||
8481 |
case QEvent::PaletteChange: |
|
8482 |
update(); |
|
8483 |
break; |
|
8484 |
||
8485 |
#ifdef Q_WS_MAC |
|
8486 |
case QEvent::MacSizeChange: |
|
8487 |
updateGeometry(); |
|
8488 |
break; |
|
8489 |
case QEvent::ToolTipChange: |
|
8490 |
case QEvent::MouseTrackingChange: |
|
8491 |
qt_mac_update_mouseTracking(this); |
|
8492 |
break; |
|
8493 |
#endif |
|
8494 |
||
8495 |
default: |
|
8496 |
break; |
|
8497 |
} |
|
8498 |
} |
|
8499 |
||
8500 |
/*! |
|
8501 |
This event handler, for event \a event, can be reimplemented in a |
|
8502 |
subclass to receive mouse move events for the widget. |
|
8503 |
||
8504 |
If mouse tracking is switched off, mouse move events only occur if |
|
8505 |
a mouse button is pressed while the mouse is being moved. If mouse |
|
8506 |
tracking is switched on, mouse move events occur even if no mouse |
|
8507 |
button is pressed. |
|
8508 |
||
8509 |
QMouseEvent::pos() reports the position of the mouse cursor, |
|
8510 |
relative to this widget. For press and release events, the |
|
8511 |
position is usually the same as the position of the last mouse |
|
8512 |
move event, but it might be different if the user's hand shakes. |
|
8513 |
This is a feature of the underlying window system, not Qt. |
|
8514 |
||
8515 |
If you want to show a tooltip immediately, while the mouse is |
|
8516 |
moving (e.g., to get the mouse coordinates with QMouseEvent::pos() |
|
8517 |
and show them as a tooltip), you must first enable mouse tracking |
|
8518 |
as described above. Then, to ensure that the tooltip is updated |
|
8519 |
immediately, you must call QToolTip::showText() instead of |
|
8520 |
setToolTip() in your implementation of mouseMoveEvent(). |
|
8521 |
||
8522 |
\sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(), |
|
8523 |
mouseDoubleClickEvent(), event(), QMouseEvent, {Scribble Example} |
|
8524 |
*/ |
|
8525 |
||
8526 |
void QWidget::mouseMoveEvent(QMouseEvent *event) |
|
8527 |
{ |
|
8528 |
event->ignore(); |
|
8529 |
} |
|
8530 |
||
8531 |
/*! |
|
8532 |
This event handler, for event \a event, can be reimplemented in a |
|
8533 |
subclass to receive mouse press events for the widget. |
|
8534 |
||
8535 |
If you create new widgets in the mousePressEvent() the |
|
8536 |
mouseReleaseEvent() may not end up where you expect, depending on |
|
8537 |
the underlying window system (or X11 window manager), the widgets' |
|
8538 |
location and maybe more. |
|
8539 |
||
8540 |
The default implementation implements the closing of popup widgets |
|
8541 |
when you click outside the window. For other widget types it does |
|
8542 |
nothing. |
|
8543 |
||
8544 |
\sa mouseReleaseEvent(), mouseDoubleClickEvent(), |
|
8545 |
mouseMoveEvent(), event(), QMouseEvent, {Scribble Example} |
|
8546 |
*/ |
|
8547 |
||
8548 |
void QWidget::mousePressEvent(QMouseEvent *event) |
|
8549 |
{ |
|
8550 |
event->ignore(); |
|
8551 |
if ((windowType() == Qt::Popup)) { |
|
8552 |
event->accept(); |
|
8553 |
QWidget* w; |
|
8554 |
while ((w = QApplication::activePopupWidget()) && w != this){ |
|
8555 |
w->close(); |
|
8556 |
if (QApplication::activePopupWidget() == w) // widget does not want to dissappear |
|
8557 |
w->hide(); // hide at least |
|
8558 |
} |
|
8559 |
if (!rect().contains(event->pos())){ |
|
8560 |
close(); |
|
8561 |
} |
|
8562 |
} |
|
8563 |
} |
|
8564 |
||
8565 |
/*! |
|
8566 |
This event handler, for event \a event, can be reimplemented in a |
|
8567 |
subclass to receive mouse release events for the widget. |
|
8568 |
||
8569 |
\sa mousePressEvent(), mouseDoubleClickEvent(), |
|
8570 |
mouseMoveEvent(), event(), QMouseEvent, {Scribble Example} |
|
8571 |
*/ |
|
8572 |
||
8573 |
void QWidget::mouseReleaseEvent(QMouseEvent *event) |
|
8574 |
{ |
|
8575 |
event->ignore(); |
|
8576 |
} |
|
8577 |
||
8578 |
/*! |
|
8579 |
This event handler, for event \a event, can be reimplemented in a |
|
8580 |
subclass to receive mouse double click events for the widget. |
|
8581 |
||
8582 |
The default implementation generates a normal mouse press event. |
|
8583 |
||
8584 |
\note The widget will also receive mouse press and mouse release |
|
8585 |
events in addition to the double click event. It is up to the |
|
8586 |
developer to ensure that the application interprets these events |
|
8587 |
correctly. |
|
8588 |
||
8589 |
\sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(), |
|
8590 |
event(), QMouseEvent |
|
8591 |
*/ |
|
8592 |
||
8593 |
void QWidget::mouseDoubleClickEvent(QMouseEvent *event) |
|
8594 |
{ |
|
8595 |
mousePressEvent(event); // try mouse press event |
|
8596 |
} |
|
8597 |
||
8598 |
#ifndef QT_NO_WHEELEVENT |
|
8599 |
/*! |
|
8600 |
This event handler, for event \a event, can be reimplemented in a |
|
8601 |
subclass to receive wheel events for the widget. |
|
8602 |
||
8603 |
If you reimplement this handler, it is very important that you |
|
8604 |
\link QWheelEvent ignore()\endlink the event if you do not handle |
|
8605 |
it, so that the widget's parent can interpret it. |
|
8606 |
||
8607 |
The default implementation ignores the event. |
|
8608 |
||
8609 |
\sa QWheelEvent::ignore(), QWheelEvent::accept(), event(), |
|
8610 |
QWheelEvent |
|
8611 |
*/ |
|
8612 |
||
8613 |
void QWidget::wheelEvent(QWheelEvent *event) |
|
8614 |
{ |
|
8615 |
event->ignore(); |
|
8616 |
} |
|
8617 |
#endif // QT_NO_WHEELEVENT |
|
8618 |
||
8619 |
#ifndef QT_NO_TABLETEVENT |
|
8620 |
/*! |
|
8621 |
This event handler, for event \a event, can be reimplemented in a |
|
8622 |
subclass to receive tablet events for the widget. |
|
8623 |
||
8624 |
If you reimplement this handler, it is very important that you |
|
8625 |
\link QTabletEvent ignore()\endlink the event if you do not handle |
|
8626 |
it, so that the widget's parent can interpret it. |
|
8627 |
||
8628 |
The default implementation ignores the event. |
|
8629 |
||
8630 |
\sa QTabletEvent::ignore(), QTabletEvent::accept(), event(), |
|
8631 |
QTabletEvent |
|
8632 |
*/ |
|
8633 |
||
8634 |
void QWidget::tabletEvent(QTabletEvent *event) |
|
8635 |
{ |
|
8636 |
event->ignore(); |
|
8637 |
} |
|
8638 |
#endif // QT_NO_TABLETEVENT |
|
8639 |
||
8640 |
/*! |
|
8641 |
This event handler, for event \a event, can be reimplemented in a |
|
8642 |
subclass to receive key press events for the widget. |
|
8643 |
||
8644 |
A widget must call setFocusPolicy() to accept focus initially and |
|
8645 |
have focus in order to receive a key press event. |
|
8646 |
||
8647 |
If you reimplement this handler, it is very important that you |
|
8648 |
call the base class implementation if you do not act upon the key. |
|
8649 |
||
8650 |
The default implementation closes popup widgets if the user |
|
8651 |
presses Esc. Otherwise the event is ignored, so that the widget's |
|
8652 |
parent can interpret it. |
|
8653 |
||
8654 |
Note that QKeyEvent starts with isAccepted() == true, so you do not |
|
8655 |
need to call QKeyEvent::accept() - just do not call the base class |
|
8656 |
implementation if you act upon the key. |
|
8657 |
||
8658 |
\sa keyReleaseEvent(), setFocusPolicy(), |
|
8659 |
focusInEvent(), focusOutEvent(), event(), QKeyEvent, {Tetrix Example} |
|
8660 |
*/ |
|
8661 |
||
8662 |
void QWidget::keyPressEvent(QKeyEvent *event) |
|
8663 |
{ |
|
8664 |
if ((windowType() == Qt::Popup) && event->key() == Qt::Key_Escape) { |
|
8665 |
event->accept(); |
|
8666 |
close(); |
|
8667 |
} else { |
|
8668 |
event->ignore(); |
|
8669 |
} |
|
8670 |
} |
|
8671 |
||
8672 |
/*! |
|
8673 |
This event handler, for event \a event, can be reimplemented in a |
|
8674 |
subclass to receive key release events for the widget. |
|
8675 |
||
8676 |
A widget must \link setFocusPolicy() accept focus\endlink |
|
8677 |
initially and \link hasFocus() have focus\endlink in order to |
|
8678 |
receive a key release event. |
|
8679 |
||
8680 |
If you reimplement this handler, it is very important that you |
|
8681 |
call the base class implementation if you do not act upon the key. |
|
8682 |
||
8683 |
The default implementation ignores the event, so that the widget's |
|
8684 |
parent can interpret it. |
|
8685 |
||
8686 |
Note that QKeyEvent starts with isAccepted() == true, so you do not |
|
8687 |
need to call QKeyEvent::accept() - just do not call the base class |
|
8688 |
implementation if you act upon the key. |
|
8689 |
||
8690 |
\sa keyPressEvent(), QKeyEvent::ignore(), setFocusPolicy(), |
|
8691 |
focusInEvent(), focusOutEvent(), event(), QKeyEvent |
|
8692 |
*/ |
|
8693 |
||
8694 |
void QWidget::keyReleaseEvent(QKeyEvent *event) |
|
8695 |
{ |
|
8696 |
event->ignore(); |
|
8697 |
} |
|
8698 |
||
8699 |
/*! |
|
8700 |
\fn void QWidget::focusInEvent(QFocusEvent *event) |
|
8701 |
||
8702 |
This event handler can be reimplemented in a subclass to receive |
|
8703 |
keyboard focus events (focus received) for the widget. The event |
|
8704 |
is passed in the \a event parameter |
|
8705 |
||
8706 |
A widget normally must setFocusPolicy() to something other than |
|
8707 |
Qt::NoFocus in order to receive focus events. (Note that the |
|
8708 |
application programmer can call setFocus() on any widget, even |
|
8709 |
those that do not normally accept focus.) |
|
8710 |
||
8711 |
The default implementation updates the widget (except for windows |
|
8712 |
that do not specify a focusPolicy()). |
|
8713 |
||
8714 |
\sa focusOutEvent(), setFocusPolicy(), keyPressEvent(), |
|
8715 |
keyReleaseEvent(), event(), QFocusEvent |
|
8716 |
*/ |
|
8717 |
||
8718 |
void QWidget::focusInEvent(QFocusEvent *) |
|
8719 |
{ |
|
8720 |
if (focusPolicy() != Qt::NoFocus || !isWindow()) { |
|
8721 |
update(); |
|
8722 |
} |
|
8723 |
} |
|
8724 |
||
8725 |
/*! |
|
8726 |
\fn void QWidget::focusOutEvent(QFocusEvent *event) |
|
8727 |
||
8728 |
This event handler can be reimplemented in a subclass to receive |
|
8729 |
keyboard focus events (focus lost) for the widget. The events is |
|
8730 |
passed in the \a event parameter. |
|
8731 |
||
8732 |
A widget normally must setFocusPolicy() to something other than |
|
8733 |
Qt::NoFocus in order to receive focus events. (Note that the |
|
8734 |
application programmer can call setFocus() on any widget, even |
|
8735 |
those that do not normally accept focus.) |
|
8736 |
||
8737 |
The default implementation updates the widget (except for windows |
|
8738 |
that do not specify a focusPolicy()). |
|
8739 |
||
8740 |
\sa focusInEvent(), setFocusPolicy(), keyPressEvent(), |
|
8741 |
keyReleaseEvent(), event(), QFocusEvent |
|
8742 |
*/ |
|
8743 |
||
8744 |
void QWidget::focusOutEvent(QFocusEvent *) |
|
8745 |
{ |
|
8746 |
if (focusPolicy() != Qt::NoFocus || !isWindow()) |
|
8747 |
update(); |
|
8748 |
} |
|
8749 |
||
8750 |
/*! |
|
8751 |
\fn void QWidget::enterEvent(QEvent *event) |
|
8752 |
||
8753 |
This event handler can be reimplemented in a subclass to receive |
|
8754 |
widget enter events which are passed in the \a event parameter. |
|
8755 |
||
8756 |
An event is sent to the widget when the mouse cursor enters the |
|
8757 |
widget. |
|
8758 |
||
8759 |
\sa leaveEvent(), mouseMoveEvent(), event() |
|
8760 |
*/ |
|
8761 |
||
8762 |
void QWidget::enterEvent(QEvent *) |
|
8763 |
{ |
|
8764 |
} |
|
8765 |
||
8766 |
/*! |
|
8767 |
\fn void QWidget::leaveEvent(QEvent *event) |
|
8768 |
||
8769 |
This event handler can be reimplemented in a subclass to receive |
|
8770 |
widget leave events which are passed in the \a event parameter. |
|
8771 |
||
8772 |
A leave event is sent to the widget when the mouse cursor leaves |
|
8773 |
the widget. |
|
8774 |
||
8775 |
\sa enterEvent(), mouseMoveEvent(), event() |
|
8776 |
*/ |
|
8777 |
||
8778 |
void QWidget::leaveEvent(QEvent *) |
|
8779 |
{ |
|
8780 |
} |
|
8781 |
||
8782 |
/*! |
|
8783 |
\fn void QWidget::paintEvent(QPaintEvent *event) |
|
8784 |
||
8785 |
This event handler can be reimplemented in a subclass to receive paint |
|
8786 |
events passed in \a event. |
|
8787 |
||
8788 |
A paint event is a request to repaint all or part of a widget. It can |
|
8789 |
happen for one of the following reasons: |
|
8790 |
||
8791 |
\list |
|
8792 |
\o repaint() or update() was invoked, |
|
8793 |
\o the widget was obscured and has now been uncovered, or |
|
8794 |
\o many other reasons. |
|
8795 |
\endlist |
|
8796 |
||
8797 |
Many widgets can simply repaint their entire surface when asked to, but |
|
8798 |
some slow widgets need to optimize by painting only the requested region: |
|
8799 |
QPaintEvent::region(). This speed optimization does not change the result, |
|
8800 |
as painting is clipped to that region during event processing. QListView |
|
8801 |
and QTableView do this, for example. |
|
8802 |
||
8803 |
Qt also tries to speed up painting by merging multiple paint events into |
|
8804 |
one. When update() is called several times or the window system sends |
|
8805 |
several paint events, Qt merges these events into one event with a larger |
|
8806 |
region (see QRegion::united()). The repaint() function does not permit this |
|
8807 |
optimization, so we suggest using update() whenever possible. |
|
8808 |
||
8809 |
When the paint event occurs, the update region has normally been erased, so |
|
8810 |
you are painting on the widget's background. |
|
8811 |
||
8812 |
The background can be set using setBackgroundRole() and setPalette(). |
|
8813 |
||
8814 |
Since Qt 4.0, QWidget automatically double-buffers its painting, so there |
|
8815 |
is no need to write double-buffering code in paintEvent() to avoid flicker. |
|
8816 |
||
8817 |
\bold{Note for the X11 platform}: It is possible to toggle global double |
|
8818 |
buffering by calling \c qt_x11_set_global_double_buffer(). For example, |
|
8819 |
||
8820 |
\snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 14 |
|
8821 |
||
8822 |
\note Generally, you should refrain from calling update() or repaint() |
|
8823 |
\bold{inside} a paintEvent(). For example, calling update() or repaint() on |
|
8824 |
children inside a paintevent() results in undefined behavior; the child may |
|
8825 |
or may not get a paint event. |
|
8826 |
||
8827 |
\warning If you are using a custom paint engine without Qt's backingstore, |
|
8828 |
Qt::WA_PaintOnScreen must be set. Otherwise, QWidget::paintEngine() will |
|
8829 |
never be called; the backingstore will be used instead. |
|
8830 |
||
8831 |
\sa event(), repaint(), update(), QPainter, QPixmap, QPaintEvent, |
|
8832 |
{Analog Clock Example} |
|
8833 |
*/ |
|
8834 |
||
8835 |
void QWidget::paintEvent(QPaintEvent *) |
|
8836 |
{ |
|
8837 |
} |
|
8838 |
||
8839 |
||
8840 |
/*! |
|
8841 |
\fn void QWidget::moveEvent(QMoveEvent *event) |
|
8842 |
||
8843 |
This event handler can be reimplemented in a subclass to receive |
|
8844 |
widget move events which are passed in the \a event parameter. |
|
8845 |
When the widget receives this event, it is already at the new |
|
8846 |
position. |
|
8847 |
||
8848 |
The old position is accessible through QMoveEvent::oldPos(). |
|
8849 |
||
8850 |
\sa resizeEvent(), event(), move(), QMoveEvent |
|
8851 |
*/ |
|
8852 |
||
8853 |
void QWidget::moveEvent(QMoveEvent *) |
|
8854 |
{ |
|
8855 |
} |
|
8856 |
||
8857 |
||
8858 |
/*! |
|
8859 |
This event handler can be reimplemented in a subclass to receive |
|
8860 |
widget resize events which are passed in the \a event parameter. |
|
8861 |
When resizeEvent() is called, the widget already has its new |
|
8862 |
geometry. The old size is accessible through |
|
8863 |
QResizeEvent::oldSize(). |
|
8864 |
||
8865 |
The widget will be erased and receive a paint event immediately |
|
8866 |
after processing the resize event. No drawing need be (or should |
|
8867 |
be) done inside this handler. |
|
8868 |
||
8869 |
||
8870 |
\sa moveEvent(), event(), resize(), QResizeEvent, paintEvent(), |
|
8871 |
{Scribble Example} |
|
8872 |
*/ |
|
8873 |
||
8874 |
void QWidget::resizeEvent(QResizeEvent * /* event */) |
|
8875 |
{ |
|
8876 |
} |
|
8877 |
||
8878 |
#ifndef QT_NO_ACTION |
|
8879 |
/*! |
|
8880 |
\fn void QWidget::actionEvent(QActionEvent *event) |
|
8881 |
||
8882 |
This event handler is called with the given \a event whenever the |
|
8883 |
widget's actions are changed. |
|
8884 |
||
8885 |
\sa addAction(), insertAction(), removeAction(), actions(), QActionEvent |
|
8886 |
*/ |
|
8887 |
void QWidget::actionEvent(QActionEvent *) |
|
8888 |
{ |
|
8889 |
||
8890 |
} |
|
8891 |
#endif |
|
8892 |
||
8893 |
/*! |
|
8894 |
This event handler is called with the given \a event when Qt receives a window |
|
8895 |
close request for a top-level widget from the window system. |
|
8896 |
||
8897 |
By default, the event is accepted and the widget is closed. You can reimplement |
|
8898 |
this function to change the way the widget responds to window close requests. |
|
8899 |
For example, you can prevent the window from closing by calling \l{QEvent::}{ignore()} |
|
8900 |
on all events. |
|
8901 |
||
8902 |
Main window applications typically use reimplementations of this function to check |
|
8903 |
whether the user's work has been saved and ask for permission before closing. |
|
8904 |
For example, the \l{Application Example} uses a helper function to determine whether |
|
8905 |
or not to close the window: |
|
8906 |
||
8907 |
\snippet mainwindows/application/mainwindow.cpp 3 |
|
8908 |
\snippet mainwindows/application/mainwindow.cpp 4 |
|
8909 |
||
8910 |
\sa event(), hide(), close(), QCloseEvent, {Application Example} |
|
8911 |
*/ |
|
8912 |
||
8913 |
void QWidget::closeEvent(QCloseEvent *event) |
|
8914 |
{ |
|
8915 |
event->accept(); |
|
8916 |
} |
|
8917 |
||
8918 |
#ifndef QT_NO_CONTEXTMENU |
|
8919 |
/*! |
|
8920 |
This event handler, for event \a event, can be reimplemented in a |
|
8921 |
subclass to receive widget context menu events. |
|
8922 |
||
8923 |
The handler is called when the widget's \l contextMenuPolicy is |
|
8924 |
Qt::DefaultContextMenu. |
|
8925 |
||
8926 |
The default implementation ignores the context event. |
|
8927 |
See the \l QContextMenuEvent documentation for more details. |
|
8928 |
||
8929 |
\sa event(), QContextMenuEvent customContextMenuRequested() |
|
8930 |
*/ |
|
8931 |
||
8932 |
void QWidget::contextMenuEvent(QContextMenuEvent *event) |
|
8933 |
{ |
|
8934 |
event->ignore(); |
|
8935 |
} |
|
8936 |
#endif // QT_NO_CONTEXTMENU |
|
8937 |
||
8938 |
||
8939 |
/*! |
|
8940 |
This event handler, for event \a event, can be reimplemented in a |
|
8941 |
subclass to receive Input Method composition events. This handler |
|
8942 |
is called when the state of the input method changes. |
|
8943 |
||
8944 |
Note that when creating custom text editing widgets, the |
|
8945 |
Qt::WA_InputMethodEnabled window attribute must be set explicitly |
|
8946 |
(using the setAttribute() function) in order to receive input |
|
8947 |
method events. |
|
8948 |
||
8949 |
The default implementation calls event->ignore(), which rejects the |
|
8950 |
Input Method event. See the \l QInputMethodEvent documentation for more |
|
8951 |
details. |
|
8952 |
||
8953 |
\sa event(), QInputMethodEvent |
|
8954 |
*/ |
|
8955 |
void QWidget::inputMethodEvent(QInputMethodEvent *event) |
|
8956 |
{ |
|
8957 |
event->ignore(); |
|
8958 |
} |
|
8959 |
||
8960 |
/*! |
|
8961 |
This method is only relevant for input widgets. It is used by the |
|
8962 |
input method to query a set of properties of the widget to be |
|
8963 |
able to support complex input method operations as support for |
|
8964 |
surrounding text and reconversions. |
|
8965 |
||
8966 |
\a query specifies which property is queried. |
|
8967 |
||
8968 |
\sa inputMethodEvent(), QInputMethodEvent, QInputContext, inputMethodHints |
|
8969 |
*/ |
|
8970 |
QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const |
|
8971 |
{ |
|
8972 |
switch(query) { |
|
8973 |
case Qt::ImMicroFocus: |
|
8974 |
return QRect(width()/2, 0, 1, height()); |
|
8975 |
case Qt::ImFont: |
|
8976 |
return font(); |
|
8977 |
case Qt::ImAnchorPosition: |
|
8978 |
// Fallback. |
|
8979 |
return inputMethodQuery(Qt::ImCursorPosition); |
|
8980 |
default: |
|
8981 |
return QVariant(); |
|
8982 |
} |
|
8983 |
} |
|
8984 |
||
8985 |
/*! |
|
8986 |
\property QWidget::inputMethodHints |
|
8987 |
\brief What input method specific hints the widget has. |
|
8988 |
||
8989 |
This is only relevant for input widgets. It is used by |
|
8990 |
the input method to retrieve hints as to how the input method |
|
8991 |
should operate. For example, if the Qt::ImhFormattedNumbersOnly flag |
|
8992 |
is set, the input method may change its visual components to reflect |
|
8993 |
that only numbers can be entered. |
|
8994 |
||
8995 |
\note The flags are only hints, so the particular input method |
|
8996 |
implementation is free to ignore them. If you want to be |
|
8997 |
sure that a certain type of characters are entered, |
|
8998 |
you should also set a QValidator on the widget. |
|
8999 |
||
9000 |
The default value is Qt::ImhNone. |
|
9001 |
||
9002 |
\since 4.6 |
|
9003 |
||
9004 |
\sa inputMethodQuery(), QInputContext |
|
9005 |
*/ |
|
9006 |
Qt::InputMethodHints QWidget::inputMethodHints() const |
|
9007 |
{ |
|
9008 |
Q_D(const QWidget); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9009 |
#ifndef QT_NO_IM |
0 | 9010 |
return d->imHints; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9011 |
#else //QT_NO_IM |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9012 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9013 |
#endif //QT_NO_IM |
0 | 9014 |
} |
9015 |
||
9016 |
void QWidget::setInputMethodHints(Qt::InputMethodHints hints) |
|
9017 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9018 |
#ifndef QT_NO_IM |
0 | 9019 |
Q_D(QWidget); |
9020 |
d->imHints = hints; |
|
9021 |
// Optimisation to update input context only it has already been created. |
|
9022 |
if (d->ic || qApp->d_func()->inputContext) { |
|
9023 |
QInputContext *ic = inputContext(); |
|
9024 |
if (ic) |
|
9025 |
ic->update(); |
|
9026 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9027 |
#endif //QT_NO_IM |
0 | 9028 |
} |
9029 |
||
9030 |
||
9031 |
#ifndef QT_NO_DRAGANDDROP |
|
9032 |
||
9033 |
/*! |
|
9034 |
\fn void QWidget::dragEnterEvent(QDragEnterEvent *event) |
|
9035 |
||
9036 |
This event handler is called when a drag is in progress and the |
|
9037 |
mouse enters this widget. The event is passed in the \a event parameter. |
|
9038 |
||
9039 |
If the event is ignored, the widget won't receive any \l{dragMoveEvent()}{drag |
|
9040 |
move events}. |
|
9041 |
||
9042 |
See the \link dnd.html Drag-and-drop documentation\endlink for an |
|
9043 |
overview of how to provide drag-and-drop in your application. |
|
9044 |
||
9045 |
\sa QDrag, QDragEnterEvent |
|
9046 |
*/ |
|
9047 |
void QWidget::dragEnterEvent(QDragEnterEvent *) |
|
9048 |
{ |
|
9049 |
} |
|
9050 |
||
9051 |
/*! |
|
9052 |
\fn void QWidget::dragMoveEvent(QDragMoveEvent *event) |
|
9053 |
||
9054 |
This event handler is called if a drag is in progress, and when |
|
9055 |
any of the following conditions occur: the cursor enters this widget, |
|
9056 |
the cursor moves within this widget, or a modifier key is pressed on |
|
9057 |
the keyboard while this widget has the focus. The event is passed |
|
9058 |
in the \a event parameter. |
|
9059 |
||
9060 |
See the \link dnd.html Drag-and-drop documentation\endlink for an |
|
9061 |
overview of how to provide drag-and-drop in your application. |
|
9062 |
||
9063 |
\sa QDrag, QDragMoveEvent |
|
9064 |
*/ |
|
9065 |
void QWidget::dragMoveEvent(QDragMoveEvent *) |
|
9066 |
{ |
|
9067 |
} |
|
9068 |
||
9069 |
/*! |
|
9070 |
\fn void QWidget::dragLeaveEvent(QDragLeaveEvent *event) |
|
9071 |
||
9072 |
This event handler is called when a drag is in progress and the |
|
9073 |
mouse leaves this widget. The event is passed in the \a event |
|
9074 |
parameter. |
|
9075 |
||
9076 |
See the \link dnd.html Drag-and-drop documentation\endlink for an |
|
9077 |
overview of how to provide drag-and-drop in your application. |
|
9078 |
||
9079 |
\sa QDrag, QDragLeaveEvent |
|
9080 |
*/ |
|
9081 |
void QWidget::dragLeaveEvent(QDragLeaveEvent *) |
|
9082 |
{ |
|
9083 |
} |
|
9084 |
||
9085 |
/*! |
|
9086 |
\fn void QWidget::dropEvent(QDropEvent *event) |
|
9087 |
||
9088 |
This event handler is called when the drag is dropped on this |
|
9089 |
widget. The event is passed in the \a event parameter. |
|
9090 |
||
9091 |
See the \link dnd.html Drag-and-drop documentation\endlink for an |
|
9092 |
overview of how to provide drag-and-drop in your application. |
|
9093 |
||
9094 |
\sa QDrag, QDropEvent |
|
9095 |
*/ |
|
9096 |
void QWidget::dropEvent(QDropEvent *) |
|
9097 |
{ |
|
9098 |
} |
|
9099 |
||
9100 |
#endif // QT_NO_DRAGANDDROP |
|
9101 |
||
9102 |
/*! |
|
9103 |
\fn void QWidget::showEvent(QShowEvent *event) |
|
9104 |
||
9105 |
This event handler can be reimplemented in a subclass to receive |
|
9106 |
widget show events which are passed in the \a event parameter. |
|
9107 |
||
9108 |
Non-spontaneous show events are sent to widgets immediately |
|
9109 |
before they are shown. The spontaneous show events of windows are |
|
9110 |
delivered afterwards. |
|
9111 |
||
9112 |
Note: A widget receives spontaneous show and hide events when its |
|
9113 |
mapping status is changed by the window system, e.g. a spontaneous |
|
9114 |
hide event when the user minimizes the window, and a spontaneous |
|
9115 |
show event when the window is restored again. After receiving a |
|
9116 |
spontaneous hide event, a widget is still considered visible in |
|
9117 |
the sense of isVisible(). |
|
9118 |
||
9119 |
\sa visible, event(), QShowEvent |
|
9120 |
*/ |
|
9121 |
void QWidget::showEvent(QShowEvent *) |
|
9122 |
{ |
|
9123 |
} |
|
9124 |
||
9125 |
/*! |
|
9126 |
\fn void QWidget::hideEvent(QHideEvent *event) |
|
9127 |
||
9128 |
This event handler can be reimplemented in a subclass to receive |
|
9129 |
widget hide events. The event is passed in the \a event parameter. |
|
9130 |
||
9131 |
Hide events are sent to widgets immediately after they have been |
|
9132 |
hidden. |
|
9133 |
||
9134 |
Note: A widget receives spontaneous show and hide events when its |
|
9135 |
mapping status is changed by the window system, e.g. a spontaneous |
|
9136 |
hide event when the user minimizes the window, and a spontaneous |
|
9137 |
show event when the window is restored again. After receiving a |
|
9138 |
spontaneous hide event, a widget is still considered visible in |
|
9139 |
the sense of isVisible(). |
|
9140 |
||
9141 |
\sa visible, event(), QHideEvent |
|
9142 |
*/ |
|
9143 |
void QWidget::hideEvent(QHideEvent *) |
|
9144 |
{ |
|
9145 |
} |
|
9146 |
||
9147 |
/* |
|
9148 |
\fn QWidget::x11Event(MSG *) |
|
9149 |
||
9150 |
This special event handler can be reimplemented in a subclass to receive |
|
9151 |
native X11 events. |
|
9152 |
||
9153 |
In your reimplementation of this function, if you want to stop Qt from |
|
9154 |
handling the event, return true. If you return false, this native event |
|
9155 |
is passed back to Qt, which translates it into a Qt event and sends it to |
|
9156 |
the widget. |
|
9157 |
||
9158 |
\note Events are only delivered to this event handler if the widget is |
|
9159 |
native. |
|
9160 |
||
9161 |
\warning This function is not portable. |
|
9162 |
||
9163 |
\sa QApplication::x11EventFilter(), QWidget::winId() |
|
9164 |
*/ |
|
9165 |
||
9166 |
||
9167 |
#if defined(Q_WS_MAC) |
|
9168 |
||
9169 |
/*! |
|
9170 |
\fn bool QWidget::macEvent(EventHandlerCallRef caller, EventRef event) |
|
9171 |
||
9172 |
This special event handler can be reimplemented in a subclass to |
|
9173 |
receive native Macintosh events. |
|
9174 |
||
9175 |
The parameters are a bit different depending if Qt is build against Carbon |
|
9176 |
or Cocoa. In Carbon, \a caller and \a event are the corresponding |
|
9177 |
EventHandlerCallRef and EventRef that correspond to the Carbon event |
|
9178 |
handlers that are installed. In Cocoa, \a caller is always 0 and the |
|
9179 |
EventRef is the EventRef generated from the NSEvent. |
|
9180 |
||
9181 |
In your reimplementation of this function, if you want to stop the |
|
9182 |
event being handled by Qt, return true. If you return false, this |
|
9183 |
native event is passed back to Qt, which translates the event into |
|
9184 |
a Qt event and sends it to the widget. |
|
9185 |
||
9186 |
\warning This function is not portable. |
|
9187 |
||
9188 |
\warning This function was not called inside of Qt until Qt 4.4. |
|
9189 |
If you need compatibility with earlier versions of Qt, consider QApplication::macEventFilter() instead. |
|
9190 |
||
9191 |
\sa QApplication::macEventFilter() |
|
9192 |
*/ |
|
9193 |
||
9194 |
bool QWidget::macEvent(EventHandlerCallRef, EventRef) |
|
9195 |
{ |
|
9196 |
return false; |
|
9197 |
} |
|
9198 |
||
9199 |
#endif |
|
9200 |
#if defined(Q_WS_WIN) |
|
9201 |
||
9202 |
/*! |
|
9203 |
This special event handler can be reimplemented in a subclass to |
|
9204 |
receive native Windows events which are passed in the \a message |
|
9205 |
parameter. |
|
9206 |
||
9207 |
In your reimplementation of this function, if you want to stop the |
|
9208 |
event being handled by Qt, return true and set \a result to the value |
|
9209 |
that the window procedure should return. If you return false, this |
|
9210 |
native event is passed back to Qt, which translates the event into |
|
9211 |
a Qt event and sends it to the widget. |
|
9212 |
||
9213 |
\warning This function is not portable. |
|
9214 |
||
9215 |
\sa QApplication::winEventFilter() |
|
9216 |
*/ |
|
9217 |
bool QWidget::winEvent(MSG *message, long *result) |
|
9218 |
{ |
|
9219 |
Q_UNUSED(message); |
|
9220 |
Q_UNUSED(result); |
|
9221 |
return false; |
|
9222 |
} |
|
9223 |
||
9224 |
#endif |
|
9225 |
#if defined(Q_WS_X11) |
|
9226 |
||
9227 |
/*! |
|
9228 |
\fn bool QWidget::x11Event(XEvent *event) |
|
9229 |
||
9230 |
This special event handler can be reimplemented in a subclass to receive |
|
9231 |
native X11 events passed in the \a event parameter. |
|
9232 |
||
9233 |
In your reimplementation of this function, if you want to stop Qt from |
|
9234 |
handling the event, return true. If you return false, this native event |
|
9235 |
is passed back to Qt, which translates it into a Qt event and sends it to |
|
9236 |
the widget. |
|
9237 |
||
9238 |
\note Events are only delivered to this event handler if the widget is |
|
9239 |
native. |
|
9240 |
||
9241 |
\warning This function is not portable. |
|
9242 |
||
9243 |
\sa QApplication::x11EventFilter(), QWidget::winId() |
|
9244 |
*/ |
|
9245 |
bool QWidget::x11Event(XEvent *) |
|
9246 |
{ |
|
9247 |
return false; |
|
9248 |
} |
|
9249 |
||
9250 |
#endif |
|
9251 |
#if defined(Q_WS_QWS) |
|
9252 |
||
9253 |
/*! |
|
9254 |
\fn bool QWidget::qwsEvent(QWSEvent *event) |
|
9255 |
||
9256 |
This special event handler can be reimplemented in a subclass to |
|
9257 |
receive native Qt for Embedded Linux events which are passed in the |
|
9258 |
\a event parameter. |
|
9259 |
||
9260 |
In your reimplementation of this function, if you want to stop the |
|
9261 |
event being handled by Qt, return true. If you return false, this |
|
9262 |
native event is passed back to Qt, which translates the event into |
|
9263 |
a Qt event and sends it to the widget. |
|
9264 |
||
9265 |
\warning This function is not portable. |
|
9266 |
||
9267 |
\sa QApplication::qwsEventFilter() |
|
9268 |
*/ |
|
9269 |
bool QWidget::qwsEvent(QWSEvent *) |
|
9270 |
{ |
|
9271 |
return false; |
|
9272 |
} |
|
9273 |
||
9274 |
#endif |
|
9275 |
||
9276 |
||
9277 |
/*! |
|
9278 |
Ensures that the widget has been polished by QStyle (i.e., has a |
|
9279 |
proper font and palette). |
|
9280 |
||
9281 |
QWidget calls this function after it has been fully constructed |
|
9282 |
but before it is shown the very first time. You can call this |
|
9283 |
function if you want to ensure that the widget is polished before |
|
9284 |
doing an operation, e.g., the correct font size might be needed in |
|
9285 |
the widget's sizeHint() reimplementation. Note that this function |
|
9286 |
\e is called from the default implementation of sizeHint(). |
|
9287 |
||
9288 |
Polishing is useful for final initialization that must happen after |
|
9289 |
all constructors (from base classes as well as from subclasses) |
|
9290 |
have been called. |
|
9291 |
||
9292 |
If you need to change some settings when a widget is polished, |
|
9293 |
reimplement event() and handle the QEvent::Polish event type. |
|
9294 |
||
9295 |
\bold{Note:} The function is declared const so that it can be called from |
|
9296 |
other const functions (e.g., sizeHint()). |
|
9297 |
||
9298 |
\sa event() |
|
9299 |
*/ |
|
9300 |
void QWidget::ensurePolished() const |
|
9301 |
{ |
|
9302 |
Q_D(const QWidget); |
|
9303 |
||
9304 |
const QMetaObject *m = metaObject(); |
|
9305 |
if (m == d->polished) |
|
9306 |
return; |
|
9307 |
d->polished = m; |
|
9308 |
||
9309 |
QEvent e(QEvent::Polish); |
|
9310 |
QCoreApplication::sendEvent(const_cast<QWidget *>(this), &e); |
|
9311 |
||
9312 |
// polish children after 'this' |
|
9313 |
QList<QObject*> children = d->children; |
|
9314 |
for (int i = 0; i < children.size(); ++i) { |
|
9315 |
QObject *o = children.at(i); |
|
9316 |
if(!o->isWidgetType()) |
|
9317 |
continue; |
|
9318 |
if (QWidget *w = qobject_cast<QWidget *>(o)) |
|
9319 |
w->ensurePolished(); |
|
9320 |
} |
|
9321 |
||
9322 |
if (d->parent && d->sendChildEvents) { |
|
9323 |
QChildEvent e(QEvent::ChildPolished, const_cast<QWidget *>(this)); |
|
9324 |
QCoreApplication::sendEvent(d->parent, &e); |
|
9325 |
} |
|
9326 |
} |
|
9327 |
||
9328 |
/*! |
|
9329 |
Returns the mask currently set on a widget. If no mask is set the |
|
9330 |
return value will be an empty region. |
|
9331 |
||
9332 |
\sa setMask(), clearMask(), QRegion::isEmpty(), {Shaped Clock Example} |
|
9333 |
*/ |
|
9334 |
QRegion QWidget::mask() const |
|
9335 |
{ |
|
9336 |
Q_D(const QWidget); |
|
9337 |
return d->extra ? d->extra->mask : QRegion(); |
|
9338 |
} |
|
9339 |
||
9340 |
/*! |
|
9341 |
Returns the layout manager that is installed on this widget, or 0 |
|
9342 |
if no layout manager is installed. |
|
9343 |
||
9344 |
The layout manager sets the geometry of the widget's children |
|
9345 |
that have been added to the layout. |
|
9346 |
||
9347 |
\sa setLayout(), sizePolicy(), {Layout Management} |
|
9348 |
*/ |
|
9349 |
QLayout *QWidget::layout() const |
|
9350 |
{ |
|
9351 |
return d_func()->layout; |
|
9352 |
} |
|
9353 |
||
9354 |
||
9355 |
/*! |
|
9356 |
\fn void QWidget::setLayout(QLayout *layout) |
|
9357 |
||
9358 |
Sets the layout manager for this widget to \a layout. |
|
9359 |
||
9360 |
If there already is a layout manager installed on this widget, |
|
9361 |
QWidget won't let you install another. You must first delete the |
|
9362 |
existing layout manager (returned by layout()) before you can |
|
9363 |
call setLayout() with the new layout. |
|
9364 |
||
9365 |
If \a layout is the layout manger on a different widget, setLayout() |
|
9366 |
will reparent the layout and make it the layout manager for this widget. |
|
9367 |
||
9368 |
Example: |
|
9369 |
||
9370 |
\snippet examples/uitools/textfinder/textfinder.cpp 3b |
|
9371 |
||
9372 |
An alternative to calling this function is to pass this widget to |
|
9373 |
the layout's constructor. |
|
9374 |
||
9375 |
The QWidget will take ownership of \a layout. |
|
9376 |
||
9377 |
\sa layout(), {Layout Management} |
|
9378 |
*/ |
|
9379 |
||
9380 |
void QWidget::setLayout(QLayout *l) |
|
9381 |
{ |
|
9382 |
if (!l) { |
|
9383 |
qWarning("QWidget::setLayout: Cannot set layout to 0"); |
|
9384 |
return; |
|
9385 |
} |
|
9386 |
if (layout()) { |
|
9387 |
if (layout() != l) |
|
9388 |
qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", which already has a" |
|
9389 |
" layout", l->objectName().toLocal8Bit().data(), metaObject()->className(), |
|
9390 |
objectName().toLocal8Bit().data()); |
|
9391 |
return; |
|
9392 |
} |
|
9393 |
||
9394 |
QObject *oldParent = l->parent(); |
|
9395 |
if (oldParent && oldParent != this) { |
|
9396 |
if (oldParent->isWidgetType()) { |
|
9397 |
// Steal the layout off a widget parent. Takes effect when |
|
9398 |
// morphing laid-out container widgets in Designer. |
|
9399 |
QWidget *oldParentWidget = static_cast<QWidget *>(oldParent); |
|
9400 |
oldParentWidget->takeLayout(); |
|
9401 |
} else { |
|
9402 |
qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent", |
|
9403 |
l->objectName().toLocal8Bit().data(), metaObject()->className(), |
|
9404 |
objectName().toLocal8Bit().data()); |
|
9405 |
return; |
|
9406 |
} |
|
9407 |
} |
|
9408 |
||
9409 |
Q_D(QWidget); |
|
9410 |
l->d_func()->topLevel = true; |
|
9411 |
d->layout = l; |
|
9412 |
if (oldParent != this) { |
|
9413 |
l->setParent(this); |
|
9414 |
l->d_func()->reparentChildWidgets(this); |
|
9415 |
l->invalidate(); |
|
9416 |
} |
|
9417 |
||
9418 |
if (isWindow() && d->maybeTopData()) |
|
9419 |
d->topData()->sizeAdjusted = false; |
|
9420 |
} |
|
9421 |
||
9422 |
/*! |
|
9423 |
\fn QLayout *QWidget::takeLayout() |
|
9424 |
||
9425 |
Remove the layout from the widget. |
|
9426 |
\since 4.5 |
|
9427 |
*/ |
|
9428 |
||
9429 |
QLayout *QWidget::takeLayout() |
|
9430 |
{ |
|
9431 |
Q_D(QWidget); |
|
9432 |
QLayout *l = layout(); |
|
9433 |
if (!l) |
|
9434 |
return 0; |
|
9435 |
d->layout = 0; |
|
9436 |
l->setParent(0); |
|
9437 |
return l; |
|
9438 |
} |
|
9439 |
||
9440 |
/*! |
|
9441 |
\property QWidget::sizePolicy |
|
9442 |
\brief the default layout behavior of the widget |
|
9443 |
||
9444 |
If there is a QLayout that manages this widget's children, the |
|
9445 |
size policy specified by that layout is used. If there is no such |
|
9446 |
QLayout, the result of this function is used. |
|
9447 |
||
9448 |
The default policy is Preferred/Preferred, which means that the |
|
9449 |
widget can be freely resized, but prefers to be the size |
|
9450 |
sizeHint() returns. Button-like widgets set the size policy to |
|
9451 |
specify that they may stretch horizontally, but are fixed |
|
9452 |
vertically. The same applies to lineedit controls (such as |
|
9453 |
QLineEdit, QSpinBox or an editable QComboBox) and other |
|
9454 |
horizontally orientated widgets (such as QProgressBar). |
|
9455 |
QToolButton's are normally square, so they allow growth in both |
|
9456 |
directions. Widgets that support different directions (such as |
|
9457 |
QSlider, QScrollBar or QHeader) specify stretching in the |
|
9458 |
respective direction only. Widgets that can provide scroll bars |
|
9459 |
(usually subclasses of QScrollArea) tend to specify that they can |
|
9460 |
use additional space, and that they can make do with less than |
|
9461 |
sizeHint(). |
|
9462 |
||
9463 |
\sa sizeHint() QLayout QSizePolicy updateGeometry() |
|
9464 |
*/ |
|
9465 |
QSizePolicy QWidget::sizePolicy() const |
|
9466 |
{ |
|
9467 |
Q_D(const QWidget); |
|
9468 |
return d->size_policy; |
|
9469 |
} |
|
9470 |
||
9471 |
void QWidget::setSizePolicy(QSizePolicy policy) |
|
9472 |
{ |
|
9473 |
Q_D(QWidget); |
|
9474 |
setAttribute(Qt::WA_WState_OwnSizePolicy); |
|
9475 |
if (policy == d->size_policy) |
|
9476 |
return; |
|
9477 |
d->size_policy = policy; |
|
9478 |
||
9479 |
#ifndef QT_NO_GRAPHICSVIEW |
|
9480 |
if (QWExtra *extra = d->extra) { |
|
9481 |
if (extra->proxyWidget) |
|
9482 |
extra->proxyWidget->setSizePolicy(policy); |
|
9483 |
} |
|
9484 |
#endif |
|
9485 |
||
9486 |
updateGeometry(); |
|
9487 |
||
9488 |
if (isWindow() && d->maybeTopData()) |
|
9489 |
d->topData()->sizeAdjusted = false; |
|
9490 |
} |
|
9491 |
||
9492 |
/*! |
|
9493 |
\fn void QWidget::setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical) |
|
9494 |
\overload |
|
9495 |
||
9496 |
Sets the size policy of the widget to \a horizontal and \a |
|
9497 |
vertical, with standard stretch and no height-for-width. |
|
9498 |
||
9499 |
\sa QSizePolicy::QSizePolicy() |
|
9500 |
*/ |
|
9501 |
||
9502 |
/*! |
|
9503 |
Returns the preferred height for this widget, given the width \a w. |
|
9504 |
||
9505 |
If this widget has a layout, the default implementation returns |
|
9506 |
the layout's preferred height. if there is no layout, the default |
|
9507 |
implementation returns -1 indicating that the preferred height |
|
9508 |
does not depend on the width. |
|
9509 |
*/ |
|
9510 |
||
9511 |
int QWidget::heightForWidth(int w) const |
|
9512 |
{ |
|
9513 |
if (layout() && layout()->hasHeightForWidth()) |
|
9514 |
return layout()->totalHeightForWidth(w); |
|
9515 |
return -1; |
|
9516 |
} |
|
9517 |
||
9518 |
/*! |
|
9519 |
\fn QWidget *QWidget::childAt(int x, int y) const |
|
9520 |
||
9521 |
Returns the visible child widget at the position (\a{x}, \a{y}) |
|
9522 |
in the widget's coordinate system. If there is no visible child |
|
9523 |
widget at the specified position, the function returns 0. |
|
9524 |
*/ |
|
9525 |
||
9526 |
/*! |
|
9527 |
\overload |
|
9528 |
||
9529 |
Returns the visible child widget at point \a p in the widget's own |
|
9530 |
coordinate system. |
|
9531 |
*/ |
|
9532 |
||
9533 |
QWidget *QWidget::childAt(const QPoint &p) const |
|
9534 |
{ |
|
9535 |
return d_func()->childAt_helper(p, false); |
|
9536 |
} |
|
9537 |
||
9538 |
QWidget *QWidgetPrivate::childAt_helper(const QPoint &p, bool ignoreChildrenInDestructor) const |
|
9539 |
{ |
|
9540 |
Q_Q(const QWidget); |
|
9541 |
#ifdef Q_WS_MAC |
|
9542 |
bool includeFrame = q->isWindow() && qobject_cast<const QMainWindow *>(q) |
|
9543 |
&& static_cast<const QMainWindow *>(q)->unifiedTitleAndToolBarOnMac(); |
|
9544 |
#endif |
|
9545 |
||
9546 |
if ( |
|
9547 |
#ifdef Q_WS_MAC |
|
9548 |
!includeFrame && |
|
9549 |
#endif |
|
9550 |
!q->rect().contains(p)) |
|
9551 |
return 0; |
|
9552 |
||
9553 |
for (int i = children.size(); i > 0 ;) { |
|
9554 |
--i; |
|
9555 |
QWidget *w = qobject_cast<QWidget *>(children.at(i)); |
|
9556 |
if (w && !w->isWindow() && !w->isHidden() |
|
9557 |
&& (w->geometry().contains(p) |
|
9558 |
#ifdef Q_WS_MAC |
|
9559 |
|| (includeFrame && w->geometry().contains(qt_mac_nativeMapFromParent(w, p))) |
|
9560 |
#endif |
|
9561 |
)) { |
|
9562 |
if (ignoreChildrenInDestructor && w->data->in_destructor) |
|
9563 |
continue; |
|
9564 |
if (w->testAttribute(Qt::WA_TransparentForMouseEvents)) |
|
9565 |
continue; |
|
9566 |
QPoint childPoint = w->mapFromParent(p); |
|
9567 |
#ifdef Q_WS_MAC |
|
9568 |
if (includeFrame && !w->geometry().contains(p)) |
|
9569 |
childPoint = qt_mac_nativeMapFromParent(w, p); |
|
9570 |
#endif |
|
9571 |
if (QWidget *t = w->d_func()->childAt_helper(childPoint, ignoreChildrenInDestructor)) |
|
9572 |
return t; |
|
9573 |
// if WMouseNoMask is set the widget mask is ignored, if |
|
9574 |
// the widget has no mask then the WMouseNoMask flag has no |
|
9575 |
// effect |
|
9576 |
if (w->testAttribute(Qt::WA_MouseNoMask) || w->mask().contains(childPoint) |
|
9577 |
|| w->mask().isEmpty()) |
|
9578 |
return w; |
|
9579 |
} |
|
9580 |
} |
|
9581 |
return 0; |
|
9582 |
} |
|
9583 |
||
9584 |
void QWidgetPrivate::updateGeometry_helper(bool forceUpdate) |
|
9585 |
{ |
|
9586 |
Q_Q(QWidget); |
|
9587 |
if (widgetItem) |
|
9588 |
widgetItem->invalidateSizeCache(); |
|
9589 |
QWidget *parent; |
|
9590 |
if (forceUpdate || !extra || extra->minw != extra->maxw || extra->minh != extra->maxh) { |
|
9591 |
if (!q->isWindow() && !q->isHidden() && (parent = q->parentWidget())) { |
|
9592 |
if (parent->d_func()->layout) |
|
9593 |
parent->d_func()->layout->invalidate(); |
|
9594 |
else if (parent->isVisible()) |
|
9595 |
QApplication::postEvent(parent, new QEvent(QEvent::LayoutRequest)); |
|
9596 |
} |
|
9597 |
} |
|
9598 |
} |
|
9599 |
||
9600 |
/*! |
|
9601 |
Notifies the layout system that this widget has changed and may |
|
9602 |
need to change geometry. |
|
9603 |
||
9604 |
Call this function if the sizeHint() or sizePolicy() have changed. |
|
9605 |
||
9606 |
For explicitly hidden widgets, updateGeometry() is a no-op. The |
|
9607 |
layout system will be notified as soon as the widget is shown. |
|
9608 |
*/ |
|
9609 |
||
9610 |
void QWidget::updateGeometry() |
|
9611 |
{ |
|
9612 |
Q_D(QWidget); |
|
9613 |
d->updateGeometry_helper(false); |
|
9614 |
} |
|
9615 |
||
9616 |
/*! \property QWidget::windowFlags |
|
9617 |
||
9618 |
Window flags are a combination of a type (e.g. Qt::Dialog) and |
|
9619 |
zero or more hints to the window system (e.g. |
|
9620 |
Qt::FramelessWindowHint). |
|
9621 |
||
9622 |
If the widget had type Qt::Widget or Qt::SubWindow and becomes a |
|
9623 |
window (Qt::Window, Qt::Dialog, etc.), it is put at position (0, |
|
9624 |
0) on the desktop. If the widget is a window and becomes a |
|
9625 |
Qt::Widget or Qt::SubWindow, it is put at position (0, 0) |
|
9626 |
relative to its parent widget. |
|
9627 |
||
9628 |
\note This function calls setParent() when changing the flags for |
|
9629 |
a window, causing the widget to be hidden. You must call show() to make |
|
9630 |
the widget visible again.. |
|
9631 |
||
9632 |
\sa windowType(), {Window Flags Example} |
|
9633 |
*/ |
|
9634 |
void QWidget::setWindowFlags(Qt::WindowFlags flags) |
|
9635 |
{ |
|
9636 |
if (data->window_flags == flags) |
|
9637 |
return; |
|
9638 |
||
9639 |
Q_D(QWidget); |
|
9640 |
||
9641 |
if ((data->window_flags | flags) & Qt::Window) { |
|
9642 |
// the old type was a window and/or the new type is a window |
|
9643 |
QPoint oldPos = pos(); |
|
9644 |
bool visible = isVisible(); |
|
9645 |
setParent(parentWidget(), flags); |
|
9646 |
||
9647 |
// if both types are windows or neither of them are, we restore |
|
9648 |
// the old position |
|
9649 |
if (!((data->window_flags ^ flags) & Qt::Window) |
|
9650 |
&& (visible || testAttribute(Qt::WA_Moved))) { |
|
9651 |
move(oldPos); |
|
9652 |
} |
|
9653 |
// for backward-compatibility we change Qt::WA_QuitOnClose attribute value only when the window was recreated. |
|
9654 |
d->adjustQuitOnCloseAttribute(); |
|
9655 |
} else { |
|
9656 |
data->window_flags = flags; |
|
9657 |
} |
|
9658 |
} |
|
9659 |
||
9660 |
/*! |
|
9661 |
Sets the window flags for the widget to \a flags, |
|
9662 |
\e without telling the window system. |
|
9663 |
||
9664 |
\warning Do not call this function unless you really know what |
|
9665 |
you're doing. |
|
9666 |
||
9667 |
\sa setWindowFlags() |
|
9668 |
*/ |
|
9669 |
void QWidget::overrideWindowFlags(Qt::WindowFlags flags) |
|
9670 |
{ |
|
9671 |
data->window_flags = flags; |
|
9672 |
} |
|
9673 |
||
9674 |
/*! |
|
9675 |
\fn Qt::WindowType QWidget::windowType() const |
|
9676 |
||
9677 |
Returns the window type of this widget. This is identical to |
|
9678 |
windowFlags() & Qt::WindowType_Mask. |
|
9679 |
||
9680 |
\sa windowFlags |
|
9681 |
*/ |
|
9682 |
||
9683 |
/*! |
|
9684 |
Sets the parent of the widget to \a parent, and resets the window |
|
9685 |
flags. The widget is moved to position (0, 0) in its new parent. |
|
9686 |
||
9687 |
If the new parent widget is in a different window, the |
|
9688 |
reparented widget and its children are appended to the end of the |
|
9689 |
\l{setFocusPolicy()}{tab chain} of the new parent |
|
9690 |
widget, in the same internal order as before. If one of the moved |
|
9691 |
widgets had keyboard focus, setParent() calls clearFocus() for that |
|
9692 |
widget. |
|
9693 |
||
9694 |
If the new parent widget is in the same window as the |
|
9695 |
old parent, setting the parent doesn't change the tab order or |
|
9696 |
keyboard focus. |
|
9697 |
||
9698 |
If the "new" parent widget is the old parent widget, this function |
|
9699 |
does nothing. |
|
9700 |
||
9701 |
\note The widget becomes invisible as part of changing its parent, |
|
9702 |
even if it was previously visible. You must call show() to make the |
|
9703 |
widget visible again. |
|
9704 |
||
9705 |
\warning It is very unlikely that you will ever need this |
|
9706 |
function. If you have a widget that changes its content |
|
9707 |
dynamically, it is far easier to use \l QStackedWidget. |
|
9708 |
||
9709 |
\sa setWindowFlags() |
|
9710 |
*/ |
|
9711 |
void QWidget::setParent(QWidget *parent) |
|
9712 |
{ |
|
9713 |
if (parent == parentWidget()) |
|
9714 |
return; |
|
9715 |
setParent((QWidget*)parent, windowFlags() & ~Qt::WindowType_Mask); |
|
9716 |
} |
|
9717 |
||
9718 |
/*! |
|
9719 |
\overload |
|
9720 |
||
9721 |
This function also takes widget flags, \a f as an argument. |
|
9722 |
*/ |
|
9723 |
||
9724 |
void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) |
|
9725 |
{ |
|
9726 |
Q_D(QWidget); |
|
9727 |
bool resized = testAttribute(Qt::WA_Resized); |
|
9728 |
bool wasCreated = testAttribute(Qt::WA_WState_Created); |
|
9729 |
QWidget *oldtlw = window(); |
|
9730 |
||
9731 |
QWidget *desktopWidget = 0; |
|
9732 |
if (parent && parent->windowType() == Qt::Desktop) |
|
9733 |
desktopWidget = parent; |
|
9734 |
bool newParent = (parent != parentWidget()) || !wasCreated || desktopWidget; |
|
9735 |
||
9736 |
#if defined(Q_WS_X11) || defined(Q_WS_WIN) |
|
9737 |
if (newParent && parent && !desktopWidget) { |
|
9738 |
if (testAttribute(Qt::WA_NativeWindow) && !qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings)) |
|
9739 |
parent->d_func()->enforceNativeChildren(); |
|
9740 |
else if (parent->d_func()->nativeChildrenForced() || parent->testAttribute(Qt::WA_PaintOnScreen)) |
|
9741 |
setAttribute(Qt::WA_NativeWindow); |
|
9742 |
} |
|
9743 |
#endif |
|
9744 |
||
9745 |
if (wasCreated) { |
|
9746 |
if (!testAttribute(Qt::WA_WState_Hidden)) { |
|
9747 |
hide(); |
|
9748 |
setAttribute(Qt::WA_WState_ExplicitShowHide, false); |
|
9749 |
} |
|
9750 |
if (newParent) { |
|
9751 |
QEvent e(QEvent::ParentAboutToChange); |
|
9752 |
QApplication::sendEvent(this, &e); |
|
9753 |
} |
|
9754 |
} |
|
9755 |
if (newParent && isAncestorOf(focusWidget())) |
|
9756 |
focusWidget()->clearFocus(); |
|
9757 |
||
9758 |
d->setParent_sys(parent, f); |
|
9759 |
if (desktopWidget) |
|
9760 |
parent = 0; |
|
9761 |
||
9762 |
#ifdef Q_BACKINGSTORE_SUBSURFACES |
|
9763 |
QTLWExtra *extra = d->maybeTopData(); |
|
9764 |
QWindowSurface *windowSurface = (extra ? extra->windowSurface : 0); |
|
9765 |
if (newParent && windowSurface) { |
|
9766 |
QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore(); |
|
9767 |
if (oldBs) |
|
9768 |
oldBs->subSurfaces.removeAll(windowSurface); |
|
9769 |
||
9770 |
if (parent) { |
|
9771 |
QWidgetBackingStore *newBs = parent->d_func()->maybeBackingStore(); |
|
9772 |
if (newBs) |
|
9773 |
newBs->subSurfaces.append(windowSurface); |
|
9774 |
} |
|
9775 |
} |
|
9776 |
#endif |
|
9777 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
9778 |
if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
9779 |
if (newParent) |
0 | 9780 |
oldBs->removeDirtyWidget(this); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
9781 |
// Move the widget and all its static children from |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
9782 |
// the old backing store to the new one. |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
9783 |
oldBs->moveStaticWidgets(this); |
0 | 9784 |
} |
9785 |
||
9786 |
if ((QApplicationPrivate::app_compile_version < 0x040200 |
|
9787 |
|| QApplicationPrivate::testAttribute(Qt::AA_ImmediateWidgetCreation)) |
|
9788 |
&& !testAttribute(Qt::WA_WState_Created)) |
|
9789 |
create(); |
|
9790 |
||
9791 |
d->reparentFocusWidgets(oldtlw); |
|
9792 |
setAttribute(Qt::WA_Resized, resized); |
|
9793 |
if (!testAttribute(Qt::WA_StyleSheet) |
|
9794 |
&& (!parent || !parent->testAttribute(Qt::WA_StyleSheet))) { |
|
9795 |
d->resolveFont(); |
|
9796 |
d->resolvePalette(); |
|
9797 |
} |
|
9798 |
d->resolveLayoutDirection(); |
|
9799 |
d->resolveLocale(); |
|
9800 |
||
9801 |
// Note: GL widgets under WGL or EGL will always need a ParentChange |
|
9802 |
// event to handle recreation/rebinding of the GL context, hence the |
|
9803 |
// (f & Qt::MSWindowsOwnDC) clause (which is set on QGLWidgets on all |
|
9804 |
// platforms). |
|
9805 |
if (newParent |
|
9806 |
#if defined(Q_WS_WIN) || defined(QT_OPENGL_ES) |
|
9807 |
|| (f & Qt::MSWindowsOwnDC) |
|
9808 |
#endif |
|
9809 |
) { |
|
9810 |
// propagate enabled updates enabled state to non-windows |
|
9811 |
if (!isWindow()) { |
|
9812 |
if (!testAttribute(Qt::WA_ForceDisabled)) |
|
9813 |
d->setEnabled_helper(parent ? parent->isEnabled() : true); |
|
9814 |
if (!testAttribute(Qt::WA_ForceUpdatesDisabled)) |
|
9815 |
d->setUpdatesEnabled_helper(parent ? parent->updatesEnabled() : true); |
|
9816 |
} |
|
9817 |
d->inheritStyle(); |
|
9818 |
||
9819 |
// send and post remaining QObject events |
|
9820 |
if (parent && d->sendChildEvents) { |
|
9821 |
QChildEvent e(QEvent::ChildAdded, this); |
|
9822 |
QApplication::sendEvent(parent, &e); |
|
9823 |
#ifdef QT3_SUPPORT |
|
9824 |
if (parent->d_func()->pendingChildInsertedEvents.isEmpty()) { |
|
9825 |
QApplication::postEvent(parent, |
|
9826 |
new QEvent(QEvent::ChildInsertedRequest), |
|
9827 |
Qt::HighEventPriority); |
|
9828 |
} |
|
9829 |
parent->d_func()->pendingChildInsertedEvents.append(this); |
|
9830 |
#endif |
|
9831 |
} |
|
9832 |
||
9833 |
//### already hidden above ---> must probably do something smart on the mac |
|
9834 |
// #ifdef Q_WS_MAC |
|
9835 |
// extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp |
|
9836 |
// if(!qt_mac_is_macdrawer(q)) //special case |
|
9837 |
// q->setAttribute(Qt::WA_WState_Hidden); |
|
9838 |
// #else |
|
9839 |
// q->setAttribute(Qt::WA_WState_Hidden); |
|
9840 |
//#endif |
|
9841 |
||
9842 |
if (parent && d->sendChildEvents && d->polished) { |
|
9843 |
QChildEvent e(QEvent::ChildPolished, this); |
|
9844 |
QCoreApplication::sendEvent(parent, &e); |
|
9845 |
} |
|
9846 |
||
9847 |
QEvent e(QEvent::ParentChange); |
|
9848 |
QApplication::sendEvent(this, &e); |
|
9849 |
} |
|
9850 |
||
9851 |
if (!wasCreated) { |
|
9852 |
if (isWindow() || parentWidget()->isVisible()) |
|
9853 |
setAttribute(Qt::WA_WState_Hidden, true); |
|
9854 |
else if (!testAttribute(Qt::WA_WState_ExplicitShowHide)) |
|
9855 |
setAttribute(Qt::WA_WState_Hidden, false); |
|
9856 |
} |
|
9857 |
||
9858 |
d->updateIsOpaque(); |
|
9859 |
||
9860 |
#ifndef QT_NO_GRAPHICSVIEW |
|
9861 |
// Embed the widget into a proxy if the parent is embedded. |
|
9862 |
// ### Doesn't handle reparenting out of an embedded widget. |
|
9863 |
if (oldtlw->graphicsProxyWidget()) { |
|
9864 |
if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(oldtlw)) |
|
9865 |
ancestorProxy->d_func()->unembedSubWindow(this); |
|
9866 |
} |
|
9867 |
if (isWindow() && parent && !graphicsProxyWidget() && !bypassGraphicsProxyWidget(this)) { |
|
9868 |
if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(parent)) |
|
9869 |
ancestorProxy->d_func()->embedSubWindow(this); |
|
9870 |
} |
|
9871 |
#endif |
|
9872 |
} |
|
9873 |
||
9874 |
/*! |
|
9875 |
Scrolls the widget including its children \a dx pixels to the |
|
9876 |
right and \a dy downward. Both \a dx and \a dy may be negative. |
|
9877 |
||
9878 |
After scrolling, the widgets will receive paint events for |
|
9879 |
the areas that need to be repainted. For widgets that Qt knows to |
|
9880 |
be opaque, this is only the newly exposed parts. |
|
9881 |
For example, if an opaque widget is scrolled 8 pixels to the left, |
|
9882 |
only an 8-pixel wide stripe at the right edge needs updating. |
|
9883 |
||
9884 |
Since widgets propagate the contents of their parents by default, |
|
9885 |
you need to set the \l autoFillBackground property, or use |
|
9886 |
setAttribute() to set the Qt::WA_OpaquePaintEvent attribute, to make |
|
9887 |
a widget opaque. |
|
9888 |
||
9889 |
For widgets that use contents propagation, a scroll will cause an |
|
9890 |
update of the entire scroll area. |
|
9891 |
||
9892 |
\sa {Transparency and Double Buffering} |
|
9893 |
*/ |
|
9894 |
||
9895 |
void QWidget::scroll(int dx, int dy) |
|
9896 |
{ |
|
9897 |
if ((!updatesEnabled() && children().size() == 0) || !isVisible()) |
|
9898 |
return; |
|
9899 |
if (dx == 0 && dy == 0) |
|
9900 |
return; |
|
9901 |
Q_D(QWidget); |
|
9902 |
#ifndef QT_NO_GRAPHICSVIEW |
|
9903 |
if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9904 |
// Graphics View maintains its own dirty region as a list of rects; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9905 |
// until we can connect item updates directly to the view, we must |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9906 |
// separately add a translated dirty region. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9907 |
if (!d->dirty.isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9908 |
foreach (const QRect &rect, (d->dirty.translated(dx, dy)).rects()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9909 |
proxy->update(rect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9910 |
} |
0 | 9911 |
proxy->scroll(dx, dy, proxy->subWidgetRect(this)); |
9912 |
return; |
|
9913 |
} |
|
9914 |
#endif |
|
9915 |
d->setDirtyOpaqueRegion(); |
|
9916 |
d->scroll_sys(dx, dy); |
|
9917 |
} |
|
9918 |
||
9919 |
/*! |
|
9920 |
\overload |
|
9921 |
||
9922 |
This version only scrolls \a r and does not move the children of |
|
9923 |
the widget. |
|
9924 |
||
9925 |
If \a r is empty or invalid, the result is undefined. |
|
9926 |
||
9927 |
\sa QScrollArea |
|
9928 |
*/ |
|
9929 |
void QWidget::scroll(int dx, int dy, const QRect &r) |
|
9930 |
{ |
|
9931 |
||
9932 |
if ((!updatesEnabled() && children().size() == 0) || !isVisible()) |
|
9933 |
return; |
|
9934 |
if (dx == 0 && dy == 0) |
|
9935 |
return; |
|
9936 |
Q_D(QWidget); |
|
9937 |
#ifndef QT_NO_GRAPHICSVIEW |
|
9938 |
if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9939 |
// Graphics View maintains its own dirty region as a list of rects; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9940 |
// until we can connect item updates directly to the view, we must |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9941 |
// separately add a translated dirty region. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9942 |
if (!d->dirty.isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9943 |
foreach (const QRect &rect, (d->dirty.translated(dx, dy) & r).rects()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9944 |
proxy->update(rect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9945 |
} |
0 | 9946 |
proxy->scroll(dx, dy, r.translated(proxy->subWidgetRect(this).topLeft().toPoint())); |
9947 |
return; |
|
9948 |
} |
|
9949 |
#endif |
|
9950 |
d->scroll_sys(dx, dy, r); |
|
9951 |
} |
|
9952 |
||
9953 |
/*! |
|
9954 |
Repaints the widget directly by calling paintEvent() immediately, |
|
9955 |
unless updates are disabled or the widget is hidden. |
|
9956 |
||
9957 |
We suggest only using repaint() if you need an immediate repaint, |
|
9958 |
for example during animation. In almost all circumstances update() |
|
9959 |
is better, as it permits Qt to optimize for speed and minimize |
|
9960 |
flicker. |
|
9961 |
||
9962 |
\warning If you call repaint() in a function which may itself be |
|
9963 |
called from paintEvent(), you may get infinite recursion. The |
|
9964 |
update() function never causes recursion. |
|
9965 |
||
9966 |
\sa update(), paintEvent(), setUpdatesEnabled() |
|
9967 |
*/ |
|
9968 |
||
9969 |
void QWidget::repaint() |
|
9970 |
{ |
|
9971 |
repaint(rect()); |
|
9972 |
} |
|
9973 |
||
9974 |
/*! \overload |
|
9975 |
||
9976 |
This version repaints a rectangle (\a x, \a y, \a w, \a h) inside |
|
9977 |
the widget. |
|
9978 |
||
9979 |
If \a w is negative, it is replaced with \c{width() - x}, and if |
|
9980 |
\a h is negative, it is replaced width \c{height() - y}. |
|
9981 |
*/ |
|
9982 |
void QWidget::repaint(int x, int y, int w, int h) |
|
9983 |
{ |
|
9984 |
if (x > data->crect.width() || y > data->crect.height()) |
|
9985 |
return; |
|
9986 |
||
9987 |
if (w < 0) |
|
9988 |
w = data->crect.width() - x; |
|
9989 |
if (h < 0) |
|
9990 |
h = data->crect.height() - y; |
|
9991 |
||
9992 |
repaint(QRect(x, y, w, h)); |
|
9993 |
} |
|
9994 |
||
9995 |
/*! \overload |
|
9996 |
||
9997 |
This version repaints a rectangle \a rect inside the widget. |
|
9998 |
*/ |
|
9999 |
void QWidget::repaint(const QRect &rect) |
|
10000 |
{ |
|
10001 |
Q_D(QWidget); |
|
10002 |
||
10003 |
if (testAttribute(Qt::WA_WState_ConfigPending)) { |
|
10004 |
update(rect); |
|
10005 |
return; |
|
10006 |
} |
|
10007 |
||
10008 |
if (!isVisible() || !updatesEnabled() || rect.isEmpty()) |
|
10009 |
return; |
|
10010 |
||
10011 |
if (hasBackingStoreSupport()) { |
|
10012 |
QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); |
|
10013 |
if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) { |
|
10014 |
tlwExtra->inRepaint = true; |
|
10015 |
tlwExtra->backingStore->markDirty(rect, this, true); |
|
10016 |
tlwExtra->inRepaint = false; |
|
10017 |
} |
|
10018 |
} else { |
|
10019 |
d->repaint_sys(rect); |
|
10020 |
} |
|
10021 |
} |
|
10022 |
||
10023 |
/*! |
|
10024 |
\overload |
|
10025 |
||
10026 |
This version repaints a region \a rgn inside the widget. |
|
10027 |
*/ |
|
10028 |
void QWidget::repaint(const QRegion &rgn) |
|
10029 |
{ |
|
10030 |
Q_D(QWidget); |
|
10031 |
||
10032 |
if (testAttribute(Qt::WA_WState_ConfigPending)) { |
|
10033 |
update(rgn); |
|
10034 |
return; |
|
10035 |
} |
|
10036 |
||
10037 |
if (!isVisible() || !updatesEnabled() || rgn.isEmpty()) |
|
10038 |
return; |
|
10039 |
||
10040 |
if (hasBackingStoreSupport()) { |
|
10041 |
QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); |
|
10042 |
if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) { |
|
10043 |
tlwExtra->inRepaint = true; |
|
10044 |
tlwExtra->backingStore->markDirty(rgn, this, true); |
|
10045 |
tlwExtra->inRepaint = false; |
|
10046 |
} |
|
10047 |
} else { |
|
10048 |
d->repaint_sys(rgn); |
|
10049 |
} |
|
10050 |
} |
|
10051 |
||
10052 |
/*! |
|
10053 |
Updates the widget unless updates are disabled or the widget is |
|
10054 |
hidden. |
|
10055 |
||
10056 |
This function does not cause an immediate repaint; instead it |
|
10057 |
schedules a paint event for processing when Qt returns to the main |
|
10058 |
event loop. This permits Qt to optimize for more speed and less |
|
10059 |
flicker than a call to repaint() does. |
|
10060 |
||
10061 |
Calling update() several times normally results in just one |
|
10062 |
paintEvent() call. |
|
10063 |
||
10064 |
Qt normally erases the widget's area before the paintEvent() call. |
|
10065 |
If the Qt::WA_OpaquePaintEvent widget attribute is set, the widget is |
|
10066 |
responsible for painting all its pixels with an opaque color. |
|
10067 |
||
10068 |
\sa repaint() paintEvent(), setUpdatesEnabled(), {Analog Clock Example} |
|
10069 |
*/ |
|
10070 |
void QWidget::update() |
|
10071 |
{ |
|
10072 |
update(rect()); |
|
10073 |
} |
|
10074 |
||
10075 |
/*! \fn void QWidget::update(int x, int y, int w, int h) |
|
10076 |
\overload |
|
10077 |
||
10078 |
This version updates a rectangle (\a x, \a y, \a w, \a h) inside |
|
10079 |
the widget. |
|
10080 |
*/ |
|
10081 |
||
10082 |
/*! |
|
10083 |
\overload |
|
10084 |
||
10085 |
This version updates a rectangle \a rect inside the widget. |
|
10086 |
*/ |
|
10087 |
void QWidget::update(const QRect &rect) |
|
10088 |
{ |
|
10089 |
if (!isVisible() || !updatesEnabled() || rect.isEmpty()) |
|
10090 |
return; |
|
10091 |
||
10092 |
if (testAttribute(Qt::WA_WState_InPaintEvent)) { |
|
10093 |
QApplication::postEvent(this, new QUpdateLaterEvent(rect)); |
|
10094 |
return; |
|
10095 |
} |
|
10096 |
||
10097 |
if (hasBackingStoreSupport()) { |
|
10098 |
QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); |
|
10099 |
if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) |
|
10100 |
tlwExtra->backingStore->markDirty(rect, this); |
|
10101 |
} else { |
|
10102 |
d_func()->repaint_sys(rect); |
|
10103 |
} |
|
10104 |
} |
|
10105 |
||
10106 |
/*! |
|
10107 |
\overload |
|
10108 |
||
10109 |
This version repaints a region \a rgn inside the widget. |
|
10110 |
*/ |
|
10111 |
void QWidget::update(const QRegion &rgn) |
|
10112 |
{ |
|
10113 |
if (!isVisible() || !updatesEnabled() || rgn.isEmpty()) |
|
10114 |
return; |
|
10115 |
||
10116 |
if (testAttribute(Qt::WA_WState_InPaintEvent)) { |
|
10117 |
QApplication::postEvent(this, new QUpdateLaterEvent(rgn)); |
|
10118 |
return; |
|
10119 |
} |
|
10120 |
||
10121 |
if (hasBackingStoreSupport()) { |
|
10122 |
QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); |
|
10123 |
if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) |
|
10124 |
tlwExtra->backingStore->markDirty(rgn, this); |
|
10125 |
} else { |
|
10126 |
d_func()->repaint_sys(rgn); |
|
10127 |
} |
|
10128 |
} |
|
10129 |
||
10130 |
#ifdef QT3_SUPPORT |
|
10131 |
/*! |
|
10132 |
Clear the rectangle at point (\a x, \a y) of width \a w and height |
|
10133 |
\a h. |
|
10134 |
||
10135 |
\warning This is best done in a paintEvent(). |
|
10136 |
*/ |
|
10137 |
void QWidget::erase_helper(int x, int y, int w, int h) |
|
10138 |
{ |
|
10139 |
if (testAttribute(Qt::WA_NoSystemBackground) || testAttribute(Qt::WA_UpdatesDisabled) || !testAttribute(Qt::WA_WState_Visible)) |
|
10140 |
return; |
|
10141 |
if (w < 0) |
|
10142 |
w = data->crect.width() - x; |
|
10143 |
if (h < 0) |
|
10144 |
h = data->crect.height() - y; |
|
10145 |
if (w != 0 && h != 0) { |
|
10146 |
QPainter p(this); |
|
10147 |
p.eraseRect(QRect(x, y, w, h)); |
|
10148 |
} |
|
10149 |
} |
|
10150 |
||
10151 |
/*! |
|
10152 |
\overload |
|
10153 |
||
10154 |
Clear the given region, \a rgn. |
|
10155 |
||
10156 |
Drawing may only take place in a QPaintEvent. Overload |
|
10157 |
paintEvent() to do your erasing and call update() to schedule a |
|
10158 |
replaint whenever necessary. See also QPainter. |
|
10159 |
*/ |
|
10160 |
void QWidget::erase(const QRegion& rgn) |
|
10161 |
{ |
|
10162 |
if (testAttribute(Qt::WA_NoSystemBackground) || testAttribute(Qt::WA_UpdatesDisabled) || !testAttribute(Qt::WA_WState_Visible)) |
|
10163 |
return; |
|
10164 |
||
10165 |
QPainter p(this); |
|
10166 |
p.setClipRegion(rgn); |
|
10167 |
p.eraseRect(rgn.boundingRect()); |
|
10168 |
} |
|
10169 |
||
10170 |
void QWidget::drawText_helper(int x, int y, const QString &str) |
|
10171 |
{ |
|
10172 |
if(!testAttribute(Qt::WA_WState_Visible)) |
|
10173 |
return; |
|
10174 |
QPainter paint(this); |
|
10175 |
paint.drawText(x, y, str); |
|
10176 |
} |
|
10177 |
||
10178 |
||
10179 |
/*! |
|
10180 |
Closes the widget. |
|
10181 |
||
10182 |
Use the no-argument overload instead. |
|
10183 |
*/ |
|
10184 |
bool QWidget::close(bool alsoDelete) |
|
10185 |
{ |
|
10186 |
QPointer<QWidget> that = this; |
|
10187 |
bool accepted = close(); |
|
10188 |
if (alsoDelete && accepted && that) |
|
10189 |
deleteLater(); |
|
10190 |
return accepted; |
|
10191 |
} |
|
10192 |
||
10193 |
void QWidget::setIcon(const QPixmap &i) |
|
10194 |
{ |
|
10195 |
setWindowIcon(i); |
|
10196 |
} |
|
10197 |
||
10198 |
/*! |
|
10199 |
Return's the widget's icon. |
|
10200 |
||
10201 |
Use windowIcon() instead. |
|
10202 |
*/ |
|
10203 |
const QPixmap *QWidget::icon() const |
|
10204 |
{ |
|
10205 |
Q_D(const QWidget); |
|
10206 |
return (d->extra && d->extra->topextra) ? d->extra->topextra->iconPixmap : 0; |
|
10207 |
} |
|
10208 |
||
10209 |
#endif // QT3_SUPPORT |
|
10210 |
||
10211 |
/*! |
|
10212 |
Sets the attribute \a attribute on this widget if \a on is true; |
|
10213 |
otherwise clears the attribute. |
|
10214 |
||
10215 |
\sa testAttribute() |
|
10216 |
*/ |
|
10217 |
void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) |
|
10218 |
{ |
|
10219 |
if (testAttribute(attribute) == on) |
|
10220 |
return; |
|
10221 |
||
10222 |
Q_D(QWidget); |
|
10223 |
Q_ASSERT_X(sizeof(d->high_attributes)*8 >= (Qt::WA_AttributeCount - sizeof(uint)*8), |
|
10224 |
"QWidget::setAttribute(WidgetAttribute, bool)", |
|
10225 |
"QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute"); |
|
10226 |
||
10227 |
#ifdef Q_WS_WIN |
|
10228 |
// ### Don't use PaintOnScreen+paintEngine() to do native painting in 5.0 |
|
10229 |
if (attribute == Qt::WA_PaintOnScreen && on && !inherits("QGLWidget")) { |
|
10230 |
// see qwidget_win.cpp, ::paintEngine for details |
|
10231 |
paintEngine(); |
|
10232 |
if (d->noPaintOnScreen) |
|
10233 |
return; |
|
10234 |
} |
|
10235 |
#endif |
|
10236 |
||
10237 |
if (attribute < int(8*sizeof(uint))) { |
|
10238 |
if (on) |
|
10239 |
data->widget_attributes |= (1<<attribute); |
|
10240 |
else |
|
10241 |
data->widget_attributes &= ~(1<<attribute); |
|
10242 |
} else { |
|
10243 |
const int x = attribute - 8*sizeof(uint); |
|
10244 |
const int int_off = x / (8*sizeof(uint)); |
|
10245 |
if (on) |
|
10246 |
d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint)))); |
|
10247 |
else |
|
10248 |
d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint)))); |
|
10249 |
} |
|
10250 |
||
10251 |
switch (attribute) { |
|
10252 |
||
10253 |
#ifndef QT_NO_DRAGANDDROP |
|
10254 |
case Qt::WA_AcceptDrops: { |
|
10255 |
if (on && !testAttribute(Qt::WA_DropSiteRegistered)) |
|
10256 |
setAttribute(Qt::WA_DropSiteRegistered, true); |
|
10257 |
else if (!on && (isWindow() || !parentWidget() || !parentWidget()->testAttribute(Qt::WA_DropSiteRegistered))) |
|
10258 |
setAttribute(Qt::WA_DropSiteRegistered, false); |
|
10259 |
QEvent e(QEvent::AcceptDropsChange); |
|
10260 |
QApplication::sendEvent(this, &e); |
|
10261 |
break; |
|
10262 |
} |
|
10263 |
case Qt::WA_DropSiteRegistered: { |
|
10264 |
d->registerDropSite(on); |
|
10265 |
for (int i = 0; i < d->children.size(); ++i) { |
|
10266 |
QWidget *w = qobject_cast<QWidget *>(d->children.at(i)); |
|
10267 |
if (w && !w->isWindow() && !w->testAttribute(Qt::WA_AcceptDrops) && w->testAttribute(Qt::WA_DropSiteRegistered) != on) |
|
10268 |
w->setAttribute(Qt::WA_DropSiteRegistered, on); |
|
10269 |
} |
|
10270 |
break; |
|
10271 |
} |
|
10272 |
#endif |
|
10273 |
||
10274 |
case Qt::WA_NoChildEventsForParent: |
|
10275 |
d->sendChildEvents = !on; |
|
10276 |
break; |
|
10277 |
case Qt::WA_NoChildEventsFromChildren: |
|
10278 |
d->receiveChildEvents = !on; |
|
10279 |
break; |
|
10280 |
case Qt::WA_MacBrushedMetal: |
|
10281 |
#ifdef Q_WS_MAC |
|
10282 |
d->setStyle_helper(style(), false, true); // Make sure things get unpolished/polished correctly. |
|
10283 |
// fall through since changing the metal attribute affects the opaque size grip. |
|
10284 |
case Qt::WA_MacOpaqueSizeGrip: |
|
10285 |
d->macUpdateOpaqueSizeGrip(); |
|
10286 |
break; |
|
10287 |
case Qt::WA_MacShowFocusRect: |
|
10288 |
if (hasFocus()) { |
|
10289 |
clearFocus(); |
|
10290 |
setFocus(); |
|
10291 |
} |
|
10292 |
break; |
|
10293 |
case Qt::WA_Hover: |
|
10294 |
qt_mac_update_mouseTracking(this); |
|
10295 |
break; |
|
10296 |
#endif |
|
10297 |
case Qt::WA_MacAlwaysShowToolWindow: |
|
10298 |
#ifdef Q_WS_MAC |
|
10299 |
d->macUpdateHideOnSuspend(); |
|
10300 |
#endif |
|
10301 |
break; |
|
10302 |
case Qt::WA_MacNormalSize: |
|
10303 |
case Qt::WA_MacSmallSize: |
|
10304 |
case Qt::WA_MacMiniSize: |
|
10305 |
#ifdef Q_WS_MAC |
|
10306 |
{ |
|
10307 |
// We can only have one of these set at a time |
|
10308 |
static const int MacSizes[] = { Qt::WA_MacNormalSize, Qt::WA_MacSmallSize, |
|
10309 |
Qt::WA_MacMiniSize, 0 }; |
|
10310 |
for (int i = 0; MacSizes[i] != 0; ++i) { |
|
10311 |
if (MacSizes[i] == attribute) |
|
10312 |
continue; |
|
10313 |
int macsize_x = MacSizes[i] - 8*sizeof(uint); |
|
10314 |
int macsize_int_off = macsize_x / (8*sizeof(uint)); |
|
10315 |
d->high_attributes[macsize_int_off] &= ~(1<<(macsize_x-(macsize_int_off*8*sizeof(uint)))); |
|
10316 |
} |
|
10317 |
d->macUpdateSizeAttribute(); |
|
10318 |
} |
|
10319 |
#endif |
|
10320 |
break; |
|
10321 |
case Qt::WA_ShowModal: |
|
10322 |
if (!on) { |
|
10323 |
if (isVisible()) |
|
10324 |
QApplicationPrivate::leaveModal(this); |
|
10325 |
// reset modality type to Modeless when clearing WA_ShowModal |
|
10326 |
data->window_modality = Qt::NonModal; |
|
10327 |
} else if (data->window_modality == Qt::NonModal) { |
|
10328 |
// determine the modality type if it hasn't been set prior |
|
10329 |
// to setting WA_ShowModal. set the default to WindowModal |
|
10330 |
// if we are the child of a group leader; otherwise use |
|
10331 |
// ApplicationModal. |
|
10332 |
QWidget *w = parentWidget(); |
|
10333 |
if (w) |
|
10334 |
w = w->window(); |
|
10335 |
while (w && !w->testAttribute(Qt::WA_GroupLeader)) { |
|
10336 |
w = w->parentWidget(); |
|
10337 |
if (w) |
|
10338 |
w = w->window(); |
|
10339 |
} |
|
10340 |
data->window_modality = (w && w->testAttribute(Qt::WA_GroupLeader)) |
|
10341 |
? Qt::WindowModal |
|
10342 |
: Qt::ApplicationModal; |
|
10343 |
// Some window managers does not allow us to enter modal after the |
|
10344 |
// window is showing. Therefore, to be consistent, we cannot call |
|
10345 |
// QApplicationPrivate::enterModal(this) here. The window must be |
|
10346 |
// hidden before changing modality. |
|
10347 |
} |
|
10348 |
if (testAttribute(Qt::WA_WState_Created)) { |
|
10349 |
// don't call setModal_sys() before create_sys() |
|
10350 |
d->setModal_sys(); |
|
10351 |
} |
|
10352 |
break; |
|
10353 |
case Qt::WA_MouseTracking: { |
|
10354 |
QEvent e(QEvent::MouseTrackingChange); |
|
10355 |
QApplication::sendEvent(this, &e); |
|
10356 |
break; } |
|
10357 |
case Qt::WA_NativeWindow: { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10358 |
#ifndef QT_NO_IM |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10359 |
QWidget *focusWidget = d->effectiveFocusWidget(); |
0 | 10360 |
QInputContext *ic = 0; |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10361 |
if (on && !internalWinId() && hasFocus() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10362 |
&& focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10363 |
ic = focusWidget->d_func()->inputContext(); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10364 |
if (ic) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10365 |
ic->reset(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10366 |
ic->setFocusWidget(0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10367 |
} |
0 | 10368 |
} |
10369 |
if (!qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings) && parentWidget()) |
|
10370 |
parentWidget()->d_func()->enforceNativeChildren(); |
|
10371 |
if (on && !internalWinId() && testAttribute(Qt::WA_WState_Created)) |
|
10372 |
d->createWinId(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10373 |
if (ic && isEnabled() && focusWidget->isEnabled() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10374 |
&& focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10375 |
ic->setFocusWidget(focusWidget); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10376 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10377 |
#endif //QT_NO_IM |
0 | 10378 |
break; |
10379 |
} |
|
10380 |
case Qt::WA_PaintOnScreen: |
|
10381 |
d->updateIsOpaque(); |
|
10382 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
10383 |
// Recreate the widget if it's already created as an alien widget and |
|
10384 |
// WA_PaintOnScreen is enabled. Paint on screen widgets must have win id. |
|
10385 |
// So must their children. |
|
10386 |
if (on) { |
|
10387 |
setAttribute(Qt::WA_NativeWindow); |
|
10388 |
d->enforceNativeChildren(); |
|
10389 |
} |
|
10390 |
#endif |
|
10391 |
// fall through |
|
10392 |
case Qt::WA_OpaquePaintEvent: |
|
10393 |
d->updateIsOpaque(); |
|
10394 |
break; |
|
10395 |
case Qt::WA_NoSystemBackground: |
|
10396 |
d->updateIsOpaque(); |
|
10397 |
// fall through... |
|
10398 |
case Qt::WA_UpdatesDisabled: |
|
10399 |
d->updateSystemBackground(); |
|
10400 |
break; |
|
10401 |
case Qt::WA_TransparentForMouseEvents: |
|
10402 |
#ifdef Q_WS_MAC |
|
10403 |
d->macUpdateIgnoreMouseEvents(); |
|
10404 |
#endif |
|
10405 |
break; |
|
10406 |
case Qt::WA_InputMethodEnabled: { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10407 |
#ifndef QT_NO_IM |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10408 |
QWidget *focusWidget = d->effectiveFocusWidget(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10409 |
QInputContext *ic = focusWidget->d_func()->ic; |
0 | 10410 |
if (!ic && (!on || hasFocus())) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10411 |
ic = focusWidget->d_func()->inputContext(); |
0 | 10412 |
if (ic) { |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10413 |
if (on && hasFocus() && ic->focusWidget() != focusWidget && isEnabled() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10414 |
&& focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10415 |
ic->setFocusWidget(focusWidget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10416 |
} else if (!on && ic->focusWidget() == focusWidget) { |
0 | 10417 |
ic->reset(); |
10418 |
ic->setFocusWidget(0); |
|
10419 |
} |
|
10420 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10421 |
#endif //QT_NO_IM |
0 | 10422 |
break; |
10423 |
} |
|
10424 |
case Qt::WA_WindowPropagation: |
|
10425 |
d->resolvePalette(); |
|
10426 |
d->resolveFont(); |
|
10427 |
d->resolveLocale(); |
|
10428 |
break; |
|
10429 |
#ifdef Q_WS_X11 |
|
10430 |
case Qt::WA_NoX11EventCompression: |
|
10431 |
if (!d->extra) |
|
10432 |
d->createExtra(); |
|
10433 |
d->extra->compress_events = on; |
|
10434 |
break; |
|
10435 |
case Qt::WA_X11OpenGLOverlay: |
|
10436 |
d->updateIsOpaque(); |
|
10437 |
break; |
|
10438 |
#endif |
|
10439 |
case Qt::WA_DontShowOnScreen: { |
|
10440 |
if (on && isVisible()) { |
|
10441 |
// Make sure we keep the current state and only hide the widget |
|
10442 |
// from the desktop. show_sys will only update platform specific |
|
10443 |
// attributes at this point. |
|
10444 |
d->hide_sys(); |
|
10445 |
#ifdef Q_WS_QWS |
|
10446 |
// Release the region for this window from qws if the widget has |
|
10447 |
// been shown before the attribute was set. |
|
10448 |
if (QWSWindowSurface *surface = static_cast<QWSWindowSurface *>(windowSurface())) { |
|
10449 |
QWidget::qwsDisplay()->requestRegion(surface->winId(), surface->key(), |
|
10450 |
surface->permanentState(), QRegion()); |
|
10451 |
} |
|
10452 |
#endif |
|
10453 |
d->show_sys(); |
|
10454 |
} |
|
10455 |
break; |
|
10456 |
} |
|
10457 |
||
10458 |
#ifdef Q_WS_X11 |
|
10459 |
case Qt::WA_X11NetWmWindowTypeDesktop: |
|
10460 |
case Qt::WA_X11NetWmWindowTypeDock: |
|
10461 |
case Qt::WA_X11NetWmWindowTypeToolBar: |
|
10462 |
case Qt::WA_X11NetWmWindowTypeMenu: |
|
10463 |
case Qt::WA_X11NetWmWindowTypeUtility: |
|
10464 |
case Qt::WA_X11NetWmWindowTypeSplash: |
|
10465 |
case Qt::WA_X11NetWmWindowTypeDialog: |
|
10466 |
case Qt::WA_X11NetWmWindowTypeDropDownMenu: |
|
10467 |
case Qt::WA_X11NetWmWindowTypePopupMenu: |
|
10468 |
case Qt::WA_X11NetWmWindowTypeToolTip: |
|
10469 |
case Qt::WA_X11NetWmWindowTypeNotification: |
|
10470 |
case Qt::WA_X11NetWmWindowTypeCombo: |
|
10471 |
case Qt::WA_X11NetWmWindowTypeDND: |
|
10472 |
if (testAttribute(Qt::WA_WState_Created)) |
|
10473 |
d->setNetWmWindowTypes(); |
|
10474 |
break; |
|
10475 |
#endif |
|
10476 |
||
10477 |
case Qt::WA_StaticContents: |
|
10478 |
if (QWidgetBackingStore *bs = d->maybeBackingStore()) { |
|
10479 |
if (on) |
|
10480 |
bs->addStaticWidget(this); |
|
10481 |
else |
|
10482 |
bs->removeStaticWidget(this); |
|
10483 |
} |
|
10484 |
break; |
|
10485 |
case Qt::WA_TranslucentBackground: |
|
10486 |
if (on) { |
|
10487 |
setAttribute(Qt::WA_NoSystemBackground); |
|
10488 |
d->updateIsTranslucent(); |
|
10489 |
} |
|
10490 |
||
10491 |
break; |
|
10492 |
case Qt::WA_AcceptTouchEvents: |
|
10493 |
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_WS_S60) |
|
10494 |
if (on) |
|
10495 |
d->registerTouchWindow(); |
|
10496 |
#endif |
|
10497 |
break; |
|
10498 |
default: |
|
10499 |
break; |
|
10500 |
} |
|
10501 |
} |
|
10502 |
||
10503 |
/*! \fn bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const |
|
10504 |
||
10505 |
Returns true if attribute \a attribute is set on this widget; |
|
10506 |
otherwise returns false. |
|
10507 |
||
10508 |
\sa setAttribute() |
|
10509 |
*/ |
|
10510 |
bool QWidget::testAttribute_helper(Qt::WidgetAttribute attribute) const |
|
10511 |
{ |
|
10512 |
Q_D(const QWidget); |
|
10513 |
const int x = attribute - 8*sizeof(uint); |
|
10514 |
const int int_off = x / (8*sizeof(uint)); |
|
10515 |
return (d->high_attributes[int_off] & (1<<(x-(int_off*8*sizeof(uint))))); |
|
10516 |
} |
|
10517 |
||
10518 |
/*! |
|
10519 |
\property QWidget::windowOpacity |
|
10520 |
||
10521 |
\brief The level of opacity for the window. |
|
10522 |
||
10523 |
The valid range of opacity is from 1.0 (completely opaque) to |
|
10524 |
0.0 (completely transparent). |
|
10525 |
||
10526 |
By default the value of this property is 1.0. |
|
10527 |
||
10528 |
This feature is available on Embedded Linux, Mac OS X, Windows, |
|
10529 |
and X11 platforms that support the Composite extension. |
|
10530 |
||
10531 |
This feature is not available on Windows CE. |
|
10532 |
||
10533 |
Note that under X11 you need to have a composite manager running, |
|
10534 |
and the X11 specific _NET_WM_WINDOW_OPACITY atom needs to be |
|
10535 |
supported by the window manager you are using. |
|
10536 |
||
10537 |
\warning Changing this property from opaque to transparent might issue a |
|
10538 |
paint event that needs to be processed before the window is displayed |
|
10539 |
correctly. This affects mainly the use of QPixmap::grabWindow(). Also note |
|
10540 |
that semi-transparent windows update and resize significantly slower than |
|
10541 |
opaque windows. |
|
10542 |
||
10543 |
\sa setMask() |
|
10544 |
*/ |
|
10545 |
qreal QWidget::windowOpacity() const |
|
10546 |
{ |
|
10547 |
Q_D(const QWidget); |
|
10548 |
return (isWindow() && d->maybeTopData()) ? d->maybeTopData()->opacity / 255. : 1.0; |
|
10549 |
} |
|
10550 |
||
10551 |
void QWidget::setWindowOpacity(qreal opacity) |
|
10552 |
{ |
|
10553 |
Q_D(QWidget); |
|
10554 |
if (!isWindow()) |
|
10555 |
return; |
|
10556 |
||
10557 |
opacity = qBound(qreal(0.0), opacity, qreal(1.0)); |
|
10558 |
QTLWExtra *extra = d->topData(); |
|
10559 |
extra->opacity = uint(opacity * 255); |
|
10560 |
setAttribute(Qt::WA_WState_WindowOpacitySet); |
|
10561 |
||
10562 |
#ifndef Q_WS_QWS |
|
10563 |
if (!testAttribute(Qt::WA_WState_Created)) |
|
10564 |
return; |
|
10565 |
#endif |
|
10566 |
||
10567 |
#ifndef QT_NO_GRAPHICSVIEW |
|
10568 |
if (QGraphicsProxyWidget *proxy = graphicsProxyWidget()) { |
|
10569 |
// Avoid invalidating the cache if set. |
|
10570 |
if (proxy->cacheMode() == QGraphicsItem::NoCache) |
|
10571 |
proxy->update(); |
|
10572 |
else if (QGraphicsScene *scene = proxy->scene()) |
|
10573 |
scene->update(proxy->sceneBoundingRect()); |
|
10574 |
return; |
|
10575 |
} |
|
10576 |
#endif |
|
10577 |
||
10578 |
d->setWindowOpacity_sys(opacity); |
|
10579 |
} |
|
10580 |
||
10581 |
/*! |
|
10582 |
\property QWidget::windowModified |
|
10583 |
\brief whether the document shown in the window has unsaved changes |
|
10584 |
||
10585 |
A modified window is a window whose content has changed but has |
|
10586 |
not been saved to disk. This flag will have different effects |
|
10587 |
varied by the platform. On Mac OS X the close button will have a |
|
10588 |
modified look; on other platforms, the window title will have an |
|
10589 |
'*' (asterisk). |
|
10590 |
||
10591 |
The window title must contain a "[*]" placeholder, which |
|
10592 |
indicates where the '*' should appear. Normally, it should appear |
|
10593 |
right after the file name (e.g., "document1.txt[*] - Text |
|
10594 |
Editor"). If the window isn't modified, the placeholder is simply |
|
10595 |
removed. |
|
10596 |
||
10597 |
Note that if a widget is set as modified, all its ancestors will |
|
10598 |
also be set as modified. However, if you call \c |
|
10599 |
{setWindowModified(false)} on a widget, this will not propagate to |
|
10600 |
its parent because other children of the parent might have been |
|
10601 |
modified. |
|
10602 |
||
10603 |
\sa windowTitle, {Application Example}, {SDI Example}, {MDI Example} |
|
10604 |
*/ |
|
10605 |
bool QWidget::isWindowModified() const |
|
10606 |
{ |
|
10607 |
return testAttribute(Qt::WA_WindowModified); |
|
10608 |
} |
|
10609 |
||
10610 |
void QWidget::setWindowModified(bool mod) |
|
10611 |
{ |
|
10612 |
Q_D(QWidget); |
|
10613 |
setAttribute(Qt::WA_WindowModified, mod); |
|
10614 |
||
10615 |
#ifndef Q_WS_MAC |
|
10616 |
if (!windowTitle().contains(QLatin1String("[*]")) && mod) |
|
10617 |
qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder"); |
|
10618 |
#endif |
|
10619 |
d->setWindowTitle_helper(windowTitle()); |
|
10620 |
d->setWindowIconText_helper(windowIconText()); |
|
10621 |
#ifdef Q_WS_MAC |
|
10622 |
d->setWindowModified_sys(mod); |
|
10623 |
#endif |
|
10624 |
||
10625 |
QEvent e(QEvent::ModifiedChange); |
|
10626 |
QApplication::sendEvent(this, &e); |
|
10627 |
} |
|
10628 |
||
10629 |
#ifndef QT_NO_TOOLTIP |
|
10630 |
/*! |
|
10631 |
\property QWidget::toolTip |
|
10632 |
||
10633 |
\brief the widget's tooltip |
|
10634 |
||
10635 |
Note that by default tooltips are only shown for widgets that are |
|
10636 |
children of the active window. You can change this behavior by |
|
10637 |
setting the attribute Qt::WA_AlwaysShowToolTips on the \e window, |
|
10638 |
not on the widget with the tooltip. |
|
10639 |
||
10640 |
If you want to control a tooltip's behavior, you can intercept the |
|
10641 |
event() function and catch the QEvent::ToolTip event (e.g., if you |
|
10642 |
want to customize the area for which the tooltip should be shown). |
|
10643 |
||
10644 |
By default, this property contains an empty string. |
|
10645 |
||
10646 |
\sa QToolTip statusTip whatsThis |
|
10647 |
*/ |
|
10648 |
void QWidget::setToolTip(const QString &s) |
|
10649 |
{ |
|
10650 |
Q_D(QWidget); |
|
10651 |
d->toolTip = s; |
|
10652 |
||
10653 |
QEvent event(QEvent::ToolTipChange); |
|
10654 |
QApplication::sendEvent(this, &event); |
|
10655 |
} |
|
10656 |
||
10657 |
QString QWidget::toolTip() const |
|
10658 |
{ |
|
10659 |
Q_D(const QWidget); |
|
10660 |
return d->toolTip; |
|
10661 |
} |
|
10662 |
#endif // QT_NO_TOOLTIP |
|
10663 |
||
10664 |
||
10665 |
#ifndef QT_NO_STATUSTIP |
|
10666 |
/*! |
|
10667 |
\property QWidget::statusTip |
|
10668 |
\brief the widget's status tip |
|
10669 |
||
10670 |
By default, this property contains an empty string. |
|
10671 |
||
10672 |
\sa toolTip whatsThis |
|
10673 |
*/ |
|
10674 |
void QWidget::setStatusTip(const QString &s) |
|
10675 |
{ |
|
10676 |
Q_D(QWidget); |
|
10677 |
d->statusTip = s; |
|
10678 |
} |
|
10679 |
||
10680 |
QString QWidget::statusTip() const |
|
10681 |
{ |
|
10682 |
Q_D(const QWidget); |
|
10683 |
return d->statusTip; |
|
10684 |
} |
|
10685 |
#endif // QT_NO_STATUSTIP |
|
10686 |
||
10687 |
#ifndef QT_NO_WHATSTHIS |
|
10688 |
/*! |
|
10689 |
\property QWidget::whatsThis |
|
10690 |
||
10691 |
\brief the widget's What's This help text. |
|
10692 |
||
10693 |
By default, this property contains an empty string. |
|
10694 |
||
10695 |
\sa QWhatsThis QWidget::toolTip QWidget::statusTip |
|
10696 |
*/ |
|
10697 |
void QWidget::setWhatsThis(const QString &s) |
|
10698 |
{ |
|
10699 |
Q_D(QWidget); |
|
10700 |
d->whatsThis = s; |
|
10701 |
} |
|
10702 |
||
10703 |
QString QWidget::whatsThis() const |
|
10704 |
{ |
|
10705 |
Q_D(const QWidget); |
|
10706 |
return d->whatsThis; |
|
10707 |
} |
|
10708 |
#endif // QT_NO_WHATSTHIS |
|
10709 |
||
10710 |
#ifndef QT_NO_ACCESSIBILITY |
|
10711 |
/*! |
|
10712 |
\property QWidget::accessibleName |
|
10713 |
||
10714 |
\brief the widget's name as seen by assistive technologies |
|
10715 |
||
10716 |
This property is used by accessible clients to identify, find, or announce |
|
10717 |
the widget for accessible clients. |
|
10718 |
||
10719 |
By default, this property contains an empty string. |
|
10720 |
||
10721 |
\sa QAccessibleInterface::text() |
|
10722 |
*/ |
|
10723 |
void QWidget::setAccessibleName(const QString &name) |
|
10724 |
{ |
|
10725 |
Q_D(QWidget); |
|
10726 |
d->accessibleName = name; |
|
10727 |
} |
|
10728 |
||
10729 |
QString QWidget::accessibleName() const |
|
10730 |
{ |
|
10731 |
Q_D(const QWidget); |
|
10732 |
return d->accessibleName; |
|
10733 |
} |
|
10734 |
||
10735 |
/*! |
|
10736 |
\property QWidget::accessibleDescription |
|
10737 |
||
10738 |
\brief the widget's description as seen by assistive technologies |
|
10739 |
||
10740 |
By default, this property contains an empty string. |
|
10741 |
||
10742 |
\sa QAccessibleInterface::text() |
|
10743 |
*/ |
|
10744 |
void QWidget::setAccessibleDescription(const QString &description) |
|
10745 |
{ |
|
10746 |
Q_D(QWidget); |
|
10747 |
d->accessibleDescription = description; |
|
10748 |
} |
|
10749 |
||
10750 |
QString QWidget::accessibleDescription() const |
|
10751 |
{ |
|
10752 |
Q_D(const QWidget); |
|
10753 |
return d->accessibleDescription; |
|
10754 |
} |
|
10755 |
#endif // QT_NO_ACCESSIBILITY |
|
10756 |
||
10757 |
#ifndef QT_NO_SHORTCUT |
|
10758 |
/*! |
|
10759 |
Adds a shortcut to Qt's shortcut system that watches for the given |
|
10760 |
\a key sequence in the given \a context. If the \a context is |
|
10761 |
Qt::ApplicationShortcut, the shortcut applies to the application as a |
|
10762 |
whole. Otherwise, it is either local to this widget, Qt::WidgetShortcut, |
|
10763 |
or to the window itself, Qt::WindowShortcut. |
|
10764 |
||
10765 |
If the same \a key sequence has been grabbed by several widgets, |
|
10766 |
when the \a key sequence occurs a QEvent::Shortcut event is sent |
|
10767 |
to all the widgets to which it applies in a non-deterministic |
|
10768 |
order, but with the ``ambiguous'' flag set to true. |
|
10769 |
||
10770 |
\warning You should not normally need to use this function; |
|
10771 |
instead create \l{QAction}s with the shortcut key sequences you |
|
10772 |
require (if you also want equivalent menu options and toolbar |
|
10773 |
buttons), or create \l{QShortcut}s if you just need key sequences. |
|
10774 |
Both QAction and QShortcut handle all the event filtering for you, |
|
10775 |
and provide signals which are triggered when the user triggers the |
|
10776 |
key sequence, so are much easier to use than this low-level |
|
10777 |
function. |
|
10778 |
||
10779 |
\sa releaseShortcut() setShortcutEnabled() |
|
10780 |
*/ |
|
10781 |
int QWidget::grabShortcut(const QKeySequence &key, Qt::ShortcutContext context) |
|
10782 |
{ |
|
10783 |
Q_ASSERT(qApp); |
|
10784 |
if (key.isEmpty()) |
|
10785 |
return 0; |
|
10786 |
setAttribute(Qt::WA_GrabbedShortcut); |
|
10787 |
return qApp->d_func()->shortcutMap.addShortcut(this, key, context); |
|
10788 |
} |
|
10789 |
||
10790 |
/*! |
|
10791 |
Removes the shortcut with the given \a id from Qt's shortcut |
|
10792 |
system. The widget will no longer receive QEvent::Shortcut events |
|
10793 |
for the shortcut's key sequence (unless it has other shortcuts |
|
10794 |
with the same key sequence). |
|
10795 |
||
10796 |
\warning You should not normally need to use this function since |
|
10797 |
Qt's shortcut system removes shortcuts automatically when their |
|
10798 |
parent widget is destroyed. It is best to use QAction or |
|
10799 |
QShortcut to handle shortcuts, since they are easier to use than |
|
10800 |
this low-level function. Note also that this is an expensive |
|
10801 |
operation. |
|
10802 |
||
10803 |
\sa grabShortcut() setShortcutEnabled() |
|
10804 |
*/ |
|
10805 |
void QWidget::releaseShortcut(int id) |
|
10806 |
{ |
|
10807 |
Q_ASSERT(qApp); |
|
10808 |
if (id) |
|
10809 |
qApp->d_func()->shortcutMap.removeShortcut(id, this, 0); |
|
10810 |
} |
|
10811 |
||
10812 |
/*! |
|
10813 |
If \a enable is true, the shortcut with the given \a id is |
|
10814 |
enabled; otherwise the shortcut is disabled. |
|
10815 |
||
10816 |
\warning You should not normally need to use this function since |
|
10817 |
Qt's shortcut system enables/disables shortcuts automatically as |
|
10818 |
widgets become hidden/visible and gain or lose focus. It is best |
|
10819 |
to use QAction or QShortcut to handle shortcuts, since they are |
|
10820 |
easier to use than this low-level function. |
|
10821 |
||
10822 |
\sa grabShortcut() releaseShortcut() |
|
10823 |
*/ |
|
10824 |
void QWidget::setShortcutEnabled(int id, bool enable) |
|
10825 |
{ |
|
10826 |
Q_ASSERT(qApp); |
|
10827 |
if (id) |
|
10828 |
qApp->d_func()->shortcutMap.setShortcutEnabled(enable, id, this, 0); |
|
10829 |
} |
|
10830 |
||
10831 |
/*! |
|
10832 |
\since 4.2 |
|
10833 |
||
10834 |
If \a enable is true, auto repeat of the shortcut with the |
|
10835 |
given \a id is enabled; otherwise it is disabled. |
|
10836 |
||
10837 |
\sa grabShortcut() releaseShortcut() |
|
10838 |
*/ |
|
10839 |
void QWidget::setShortcutAutoRepeat(int id, bool enable) |
|
10840 |
{ |
|
10841 |
Q_ASSERT(qApp); |
|
10842 |
if (id) |
|
10843 |
qApp->d_func()->shortcutMap.setShortcutAutoRepeat(enable, id, this, 0); |
|
10844 |
} |
|
10845 |
#endif // QT_NO_SHORTCUT |
|
10846 |
/*! |
|
10847 |
Updates the widget's micro focus. |
|
10848 |
||
10849 |
\sa QInputContext |
|
10850 |
*/ |
|
10851 |
void QWidget::updateMicroFocus() |
|
10852 |
{ |
|
10853 |
#if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)) |
|
10854 |
Q_D(QWidget); |
|
10855 |
// and optimisation to update input context only it has already been created. |
|
10856 |
if (d->ic || qApp->d_func()->inputContext) { |
|
10857 |
QInputContext *ic = inputContext(); |
|
10858 |
if (ic) |
|
10859 |
ic->update(); |
|
10860 |
} |
|
10861 |
#endif |
|
10862 |
#ifndef QT_NO_ACCESSIBILITY |
|
10863 |
// ##### is this correct |
|
10864 |
QAccessible::updateAccessibility(this, 0, QAccessible::StateChanged); |
|
10865 |
#endif |
|
10866 |
} |
|
10867 |
||
10868 |
||
10869 |
#if defined (Q_WS_WIN) |
|
10870 |
/*! |
|
10871 |
Returns the window system handle of the widget, for low-level |
|
10872 |
access. Using this function is not portable. |
|
10873 |
||
10874 |
An HDC acquired with getDC() has to be released with releaseDC(). |
|
10875 |
||
10876 |
\warning Using this function is not portable. |
|
10877 |
*/ |
|
10878 |
HDC QWidget::getDC() const |
|
10879 |
{ |
|
10880 |
Q_D(const QWidget); |
|
10881 |
if (d->hd) |
|
10882 |
return (HDC) d->hd; |
|
10883 |
return GetDC(winId()); |
|
10884 |
} |
|
10885 |
||
10886 |
/*! |
|
10887 |
Releases the HDC \a hdc acquired by a previous call to getDC(). |
|
10888 |
||
10889 |
\warning Using this function is not portable. |
|
10890 |
*/ |
|
10891 |
void QWidget::releaseDC(HDC hdc) const |
|
10892 |
{ |
|
10893 |
Q_D(const QWidget); |
|
10894 |
// If its the widgets own dc, it will be released elsewhere. If |
|
10895 |
// its a different HDC we release it and issue a warning if it |
|
10896 |
// fails. |
|
10897 |
if (hdc != d->hd && !ReleaseDC(winId(), hdc)) |
|
10898 |
qErrnoWarning("QWidget::releaseDC(): failed to release HDC"); |
|
10899 |
} |
|
10900 |
#else |
|
10901 |
/*! |
|
10902 |
Returns the window system handle of the widget, for low-level |
|
10903 |
access. Using this function is not portable. |
|
10904 |
||
10905 |
The HANDLE type varies with platform; see \c qwindowdefs.h for |
|
10906 |
details. |
|
10907 |
*/ |
|
10908 |
Qt::HANDLE QWidget::handle() const |
|
10909 |
{ |
|
10910 |
Q_D(const QWidget); |
|
10911 |
if (!internalWinId() && testAttribute(Qt::WA_WState_Created)) |
|
10912 |
(void)winId(); // enforce native window |
|
10913 |
return d->hd; |
|
10914 |
} |
|
10915 |
#endif |
|
10916 |
||
10917 |
||
10918 |
/*! |
|
10919 |
Raises this widget to the top of the parent widget's stack. |
|
10920 |
||
10921 |
After this call the widget will be visually in front of any |
|
10922 |
overlapping sibling widgets. |
|
10923 |
||
10924 |
\note When using activateWindow(), you can call this function to |
|
10925 |
ensure that the window is stacked on top. |
|
10926 |
||
10927 |
\sa lower(), stackUnder() |
|
10928 |
*/ |
|
10929 |
||
10930 |
void QWidget::raise() |
|
10931 |
{ |
|
10932 |
Q_D(QWidget); |
|
10933 |
if (!isWindow()) { |
|
10934 |
QWidget *p = parentWidget(); |
|
10935 |
const int parentChildCount = p->d_func()->children.size(); |
|
10936 |
if (parentChildCount < 2) |
|
10937 |
return; |
|
10938 |
const int from = p->d_func()->children.indexOf(this); |
|
10939 |
Q_ASSERT(from >= 0); |
|
10940 |
// Do nothing if the widget is already in correct stacking order _and_ created. |
|
10941 |
if (from != parentChildCount -1) |
|
10942 |
p->d_func()->children.move(from, parentChildCount - 1); |
|
10943 |
if (!testAttribute(Qt::WA_WState_Created) && p->testAttribute(Qt::WA_WState_Created)) |
|
10944 |
create(); |
|
10945 |
else if (from == parentChildCount - 1) |
|
10946 |
return; |
|
10947 |
||
10948 |
QRegion region(rect()); |
|
10949 |
d->subtractOpaqueSiblings(region); |
|
10950 |
d->invalidateBuffer(region); |
|
10951 |
} |
|
10952 |
if (testAttribute(Qt::WA_WState_Created)) |
|
10953 |
d->raise_sys(); |
|
10954 |
||
10955 |
QEvent e(QEvent::ZOrderChange); |
|
10956 |
QApplication::sendEvent(this, &e); |
|
10957 |
} |
|
10958 |
||
10959 |
/*! |
|
10960 |
Lowers the widget to the bottom of the parent widget's stack. |
|
10961 |
||
10962 |
After this call the widget will be visually behind (and therefore |
|
10963 |
obscured by) any overlapping sibling widgets. |
|
10964 |
||
10965 |
\sa raise(), stackUnder() |
|
10966 |
*/ |
|
10967 |
||
10968 |
void QWidget::lower() |
|
10969 |
{ |
|
10970 |
Q_D(QWidget); |
|
10971 |
if (!isWindow()) { |
|
10972 |
QWidget *p = parentWidget(); |
|
10973 |
const int parentChildCount = p->d_func()->children.size(); |
|
10974 |
if (parentChildCount < 2) |
|
10975 |
return; |
|
10976 |
const int from = p->d_func()->children.indexOf(this); |
|
10977 |
Q_ASSERT(from >= 0); |
|
10978 |
// Do nothing if the widget is already in correct stacking order _and_ created. |
|
10979 |
if (from != 0) |
|
10980 |
p->d_func()->children.move(from, 0); |
|
10981 |
if (!testAttribute(Qt::WA_WState_Created) && p->testAttribute(Qt::WA_WState_Created)) |
|
10982 |
create(); |
|
10983 |
else if (from == 0) |
|
10984 |
return; |
|
10985 |
} |
|
10986 |
if (testAttribute(Qt::WA_WState_Created)) |
|
10987 |
d->lower_sys(); |
|
10988 |
||
10989 |
QEvent e(QEvent::ZOrderChange); |
|
10990 |
QApplication::sendEvent(this, &e); |
|
10991 |
} |
|
10992 |
||
10993 |
||
10994 |
/*! |
|
10995 |
Places the widget under \a w in the parent widget's stack. |
|
10996 |
||
10997 |
To make this work, the widget itself and \a w must be siblings. |
|
10998 |
||
10999 |
\sa raise(), lower() |
|
11000 |
*/ |
|
11001 |
void QWidget::stackUnder(QWidget* w) |
|
11002 |
{ |
|
11003 |
Q_D(QWidget); |
|
11004 |
QWidget *p = parentWidget(); |
|
11005 |
if (!w || isWindow() || p != w->parentWidget() || this == w) |
|
11006 |
return; |
|
11007 |
if (p) { |
|
11008 |
int from = p->d_func()->children.indexOf(this); |
|
11009 |
int to = p->d_func()->children.indexOf(w); |
|
11010 |
Q_ASSERT(from >= 0); |
|
11011 |
Q_ASSERT(to >= 0); |
|
11012 |
if (from < to) |
|
11013 |
--to; |
|
11014 |
// Do nothing if the widget is already in correct stacking order _and_ created. |
|
11015 |
if (from != to) |
|
11016 |
p->d_func()->children.move(from, to); |
|
11017 |
if (!testAttribute(Qt::WA_WState_Created) && p->testAttribute(Qt::WA_WState_Created)) |
|
11018 |
create(); |
|
11019 |
else if (from == to) |
|
11020 |
return; |
|
11021 |
} |
|
11022 |
if (testAttribute(Qt::WA_WState_Created)) |
|
11023 |
d->stackUnder_sys(w); |
|
11024 |
||
11025 |
QEvent e(QEvent::ZOrderChange); |
|
11026 |
QApplication::sendEvent(this, &e); |
|
11027 |
} |
|
11028 |
||
11029 |
void QWidget::styleChange(QStyle&) { } |
|
11030 |
void QWidget::enabledChange(bool) { } // compat |
|
11031 |
void QWidget::paletteChange(const QPalette &) { } // compat |
|
11032 |
void QWidget::fontChange(const QFont &) { } // compat |
|
11033 |
void QWidget::windowActivationChange(bool) { } // compat |
|
11034 |
void QWidget::languageChange() { } // compat |
|
11035 |
||
11036 |
||
11037 |
/*! |
|
11038 |
\enum QWidget::BackgroundOrigin |
|
11039 |
||
11040 |
\compat |
|
11041 |
||
11042 |
\value WidgetOrigin |
|
11043 |
\value ParentOrigin |
|
11044 |
\value WindowOrigin |
|
11045 |
\value AncestorOrigin |
|
11046 |
||
11047 |
*/ |
|
11048 |
||
11049 |
/*! |
|
11050 |
\fn bool QWidget::isVisibleToTLW() const |
|
11051 |
||
11052 |
Use isVisible() instead. |
|
11053 |
*/ |
|
11054 |
||
11055 |
/*! |
|
11056 |
\fn void QWidget::iconify() |
|
11057 |
||
11058 |
Use showMinimized() instead. |
|
11059 |
*/ |
|
11060 |
||
11061 |
/*! |
|
11062 |
\fn void QWidget::constPolish() const |
|
11063 |
||
11064 |
Use ensurePolished() instead. |
|
11065 |
*/ |
|
11066 |
||
11067 |
/*! |
|
11068 |
\fn void QWidget::reparent(QWidget *parent, Qt::WindowFlags f, const QPoint &p, bool showIt) |
|
11069 |
||
11070 |
Use setParent() to change the parent or the widget's widget flags; |
|
11071 |
use move() to move the widget, and use show() to show the widget. |
|
11072 |
*/ |
|
11073 |
||
11074 |
/*! |
|
11075 |
\fn void QWidget::reparent(QWidget *parent, const QPoint &p, bool showIt) |
|
11076 |
||
11077 |
Use setParent() to change the parent; use move() to move the |
|
11078 |
widget, and use show() to show the widget. |
|
11079 |
*/ |
|
11080 |
||
11081 |
/*! |
|
11082 |
\fn void QWidget::recreate(QWidget *parent, Qt::WindowFlags f, const QPoint & p, bool showIt) |
|
11083 |
||
11084 |
Use setParent() to change the parent or the widget's widget flags; |
|
11085 |
use move() to move the widget, and use show() to show the widget. |
|
11086 |
*/ |
|
11087 |
||
11088 |
/*! |
|
11089 |
\fn bool QWidget::hasMouse() const |
|
11090 |
||
11091 |
Use testAttribute(Qt::WA_UnderMouse) instead. |
|
11092 |
*/ |
|
11093 |
||
11094 |
/*! |
|
11095 |
\fn bool QWidget::ownCursor() const |
|
11096 |
||
11097 |
Use testAttribute(Qt::WA_SetCursor) instead. |
|
11098 |
*/ |
|
11099 |
||
11100 |
/*! |
|
11101 |
\fn bool QWidget::ownFont() const |
|
11102 |
||
11103 |
Use testAttribute(Qt::WA_SetFont) instead. |
|
11104 |
*/ |
|
11105 |
||
11106 |
/*! |
|
11107 |
\fn void QWidget::unsetFont() |
|
11108 |
||
11109 |
Use setFont(QFont()) instead. |
|
11110 |
*/ |
|
11111 |
||
11112 |
/*! |
|
11113 |
\fn bool QWidget::ownPalette() const |
|
11114 |
||
11115 |
Use testAttribute(Qt::WA_SetPalette) instead. |
|
11116 |
*/ |
|
11117 |
||
11118 |
/*! |
|
11119 |
\fn void QWidget::unsetPalette() |
|
11120 |
||
11121 |
Use setPalette(QPalette()) instead. |
|
11122 |
*/ |
|
11123 |
||
11124 |
/*! |
|
11125 |
\fn void QWidget::setEraseColor(const QColor &color) |
|
11126 |
||
11127 |
Use the palette instead. |
|
11128 |
||
11129 |
\oldcode |
|
11130 |
widget->setEraseColor(color); |
|
11131 |
\newcode |
|
11132 |
QPalette palette; |
|
11133 |
palette.setColor(widget->backgroundRole(), color); |
|
11134 |
widget->setPalette(palette); |
|
11135 |
\endcode |
|
11136 |
*/ |
|
11137 |
||
11138 |
/*! |
|
11139 |
\fn void QWidget::setErasePixmap(const QPixmap &pixmap) |
|
11140 |
||
11141 |
Use the palette instead. |
|
11142 |
||
11143 |
\oldcode |
|
11144 |
widget->setErasePixmap(pixmap); |
|
11145 |
\newcode |
|
11146 |
QPalette palette; |
|
11147 |
palette.setBrush(widget->backgroundRole(), QBrush(pixmap)); |
|
11148 |
widget->setPalette(palette); |
|
11149 |
\endcode |
|
11150 |
*/ |
|
11151 |
||
11152 |
/*! |
|
11153 |
\fn void QWidget::setPaletteForegroundColor(const QColor &color) |
|
11154 |
||
11155 |
Use the palette directly. |
|
11156 |
||
11157 |
\oldcode |
|
11158 |
widget->setPaletteForegroundColor(color); |
|
11159 |
\newcode |
|
11160 |
QPalette palette; |
|
11161 |
palette.setColor(widget->foregroundRole(), color); |
|
11162 |
widget->setPalette(palette); |
|
11163 |
\endcode |
|
11164 |
*/ |
|
11165 |
||
11166 |
/*! |
|
11167 |
\fn void QWidget::setPaletteBackgroundColor(const QColor &color) |
|
11168 |
||
11169 |
Use the palette directly. |
|
11170 |
||
11171 |
\oldcode |
|
11172 |
widget->setPaletteBackgroundColor(color); |
|
11173 |
\newcode |
|
11174 |
QPalette palette; |
|
11175 |
palette.setColor(widget->backgroundRole(), color); |
|
11176 |
widget->setPalette(palette); |
|
11177 |
\endcode |
|
11178 |
*/ |
|
11179 |
||
11180 |
/*! |
|
11181 |
\fn void QWidget::setPaletteBackgroundPixmap(const QPixmap &pixmap) |
|
11182 |
||
11183 |
Use the palette directly. |
|
11184 |
||
11185 |
\oldcode |
|
11186 |
widget->setPaletteBackgroundPixmap(pixmap); |
|
11187 |
\newcode |
|
11188 |
QPalette palette; |
|
11189 |
palette.setBrush(widget->backgroundRole(), QBrush(pixmap)); |
|
11190 |
widget->setPalette(palette); |
|
11191 |
\endcode |
|
11192 |
*/ |
|
11193 |
||
11194 |
/*! |
|
11195 |
\fn void QWidget::setBackgroundPixmap(const QPixmap &pixmap) |
|
11196 |
||
11197 |
Use the palette instead. |
|
11198 |
||
11199 |
\oldcode |
|
11200 |
widget->setBackgroundPixmap(pixmap); |
|
11201 |
\newcode |
|
11202 |
QPalette palette; |
|
11203 |
palette.setBrush(widget->backgroundRole(), QBrush(pixmap)); |
|
11204 |
widget->setPalette(palette); |
|
11205 |
\endcode |
|
11206 |
*/ |
|
11207 |
||
11208 |
/*! |
|
11209 |
\fn void QWidget::setBackgroundColor(const QColor &color) |
|
11210 |
||
11211 |
Use the palette instead. |
|
11212 |
||
11213 |
\oldcode |
|
11214 |
widget->setBackgroundColor(color); |
|
11215 |
\newcode |
|
11216 |
QPalette palette; |
|
11217 |
palette.setColor(widget->backgroundRole(), color); |
|
11218 |
widget->setPalette(palette); |
|
11219 |
\endcode |
|
11220 |
*/ |
|
11221 |
||
11222 |
/*! |
|
11223 |
\fn QColorGroup QWidget::colorGroup() const |
|
11224 |
||
11225 |
Use QColorGroup(palette()) instead. |
|
11226 |
*/ |
|
11227 |
||
11228 |
/*! |
|
11229 |
\fn QWidget *QWidget::parentWidget(bool sameWindow) const |
|
11230 |
||
11231 |
Use the no-argument overload instead. |
|
11232 |
*/ |
|
11233 |
||
11234 |
/*! |
|
11235 |
\fn void QWidget::setKeyCompression(bool b) |
|
11236 |
||
11237 |
Use setAttribute(Qt::WA_KeyCompression, b) instead. |
|
11238 |
*/ |
|
11239 |
||
11240 |
/*! |
|
11241 |
\fn void QWidget::setFont(const QFont &f, bool b) |
|
11242 |
||
11243 |
Use the single-argument overload instead. |
|
11244 |
*/ |
|
11245 |
||
11246 |
/*! |
|
11247 |
\fn void QWidget::setPalette(const QPalette &p, bool b) |
|
11248 |
||
11249 |
Use the single-argument overload instead. |
|
11250 |
*/ |
|
11251 |
||
11252 |
/*! |
|
11253 |
\fn void QWidget::setBackgroundOrigin(BackgroundOrigin background) |
|
11254 |
||
11255 |
\obsolete |
|
11256 |
*/ |
|
11257 |
||
11258 |
/*! |
|
11259 |
\fn BackgroundOrigin QWidget::backgroundOrigin() const |
|
11260 |
||
11261 |
\obsolete |
|
11262 |
||
11263 |
Always returns \c WindowOrigin. |
|
11264 |
*/ |
|
11265 |
||
11266 |
/*! |
|
11267 |
\fn QPoint QWidget::backgroundOffset() const |
|
11268 |
||
11269 |
\obsolete |
|
11270 |
||
11271 |
Always returns QPoint(). |
|
11272 |
*/ |
|
11273 |
||
11274 |
/*! |
|
11275 |
\fn void QWidget::repaint(bool b) |
|
11276 |
||
11277 |
The boolean parameter \a b is ignored. Use the no-argument overload instead. |
|
11278 |
*/ |
|
11279 |
||
11280 |
/*! |
|
11281 |
\fn void QWidget::repaint(int x, int y, int w, int h, bool b) |
|
11282 |
||
11283 |
The boolean parameter \a b is ignored. Use the four-argument overload instead. |
|
11284 |
*/ |
|
11285 |
||
11286 |
/*! |
|
11287 |
\fn void QWidget::repaint(const QRect &r, bool b) |
|
11288 |
||
11289 |
The boolean parameter \a b is ignored. Use the single rect-argument overload instead. |
|
11290 |
*/ |
|
11291 |
||
11292 |
/*! |
|
11293 |
\fn void QWidget::repaint(const QRegion &rgn, bool b) |
|
11294 |
||
11295 |
The boolean parameter \a b is ignored. Use the single region-argument overload instead. |
|
11296 |
*/ |
|
11297 |
||
11298 |
/*! |
|
11299 |
\fn void QWidget::erase() |
|
11300 |
||
11301 |
Drawing may only take place in a QPaintEvent. Overload |
|
11302 |
paintEvent() to do your erasing and call update() to schedule a |
|
11303 |
replaint whenever necessary. See also QPainter. |
|
11304 |
*/ |
|
11305 |
||
11306 |
/*! |
|
11307 |
\fn void QWidget::erase(int x, int y, int w, int h) |
|
11308 |
||
11309 |
Drawing may only take place in a QPaintEvent. Overload |
|
11310 |
paintEvent() to do your erasing and call update() to schedule a |
|
11311 |
replaint whenever necessary. See also QPainter. |
|
11312 |
*/ |
|
11313 |
||
11314 |
/*! |
|
11315 |
\fn void QWidget::erase(const QRect &rect) |
|
11316 |
||
11317 |
Drawing may only take place in a QPaintEvent. Overload |
|
11318 |
paintEvent() to do your erasing and call update() to schedule a |
|
11319 |
replaint whenever necessary. See also QPainter. |
|
11320 |
*/ |
|
11321 |
||
11322 |
/*! |
|
11323 |
\fn void QWidget::drawText(const QPoint &p, const QString &s) |
|
11324 |
||
11325 |
Drawing may only take place in a QPaintEvent. Overload |
|
11326 |
paintEvent() to do your drawing and call update() to schedule a |
|
11327 |
replaint whenever necessary. See also QPainter. |
|
11328 |
*/ |
|
11329 |
||
11330 |
/*! |
|
11331 |
\fn void QWidget::drawText(int x, int y, const QString &s) |
|
11332 |
||
11333 |
Drawing may only take place in a QPaintEvent. Overload |
|
11334 |
paintEvent() to do your drawing and call update() to schedule a |
|
11335 |
replaint whenever necessary. See also QPainter. |
|
11336 |
*/ |
|
11337 |
||
11338 |
/*! |
|
11339 |
\fn QWidget *QWidget::childAt(const QPoint &p, bool includeThis) const |
|
11340 |
||
11341 |
Use the single point argument overload instead. |
|
11342 |
*/ |
|
11343 |
||
11344 |
/*! |
|
11345 |
\fn void QWidget::setCaption(const QString &c) |
|
11346 |
||
11347 |
Use setWindowTitle() instead. |
|
11348 |
*/ |
|
11349 |
||
11350 |
/*! |
|
11351 |
\fn void QWidget::setIcon(const QPixmap &i) |
|
11352 |
||
11353 |
Use setWindowIcon() instead. |
|
11354 |
*/ |
|
11355 |
||
11356 |
/*! |
|
11357 |
\fn void QWidget::setIconText(const QString &it) |
|
11358 |
||
11359 |
Use setWindowIconText() instead. |
|
11360 |
*/ |
|
11361 |
||
11362 |
/*! |
|
11363 |
\fn QString QWidget::caption() const |
|
11364 |
||
11365 |
Use windowTitle() instead. |
|
11366 |
*/ |
|
11367 |
||
11368 |
/*! |
|
11369 |
\fn QString QWidget::iconText() const |
|
11370 |
||
11371 |
Use windowIconText() instead. |
|
11372 |
*/ |
|
11373 |
||
11374 |
/*! |
|
11375 |
\fn bool QWidget::isTopLevel() const |
|
11376 |
\obsolete |
|
11377 |
||
11378 |
Use isWindow() instead. |
|
11379 |
*/ |
|
11380 |
||
11381 |
/*! |
|
11382 |
\fn bool QWidget::isRightToLeft() const |
|
11383 |
\internal |
|
11384 |
*/ |
|
11385 |
||
11386 |
/*! |
|
11387 |
\fn bool QWidget::isLeftToRight() const |
|
11388 |
\internal |
|
11389 |
*/ |
|
11390 |
||
11391 |
/*! |
|
11392 |
\fn void QWidget::setInputMethodEnabled(bool enabled) |
|
11393 |
||
11394 |
Use setAttribute(Qt::WA_InputMethodEnabled, \a enabled) instead. |
|
11395 |
*/ |
|
11396 |
||
11397 |
/*! |
|
11398 |
\fn bool QWidget::isInputMethodEnabled() const |
|
11399 |
||
11400 |
Use testAttribute(Qt::WA_InputMethodEnabled) instead. |
|
11401 |
*/ |
|
11402 |
||
11403 |
/*! |
|
11404 |
\fn void QWidget::setActiveWindow() |
|
11405 |
||
11406 |
Use activateWindow() instead. |
|
11407 |
*/ |
|
11408 |
||
11409 |
/*! |
|
11410 |
\fn bool QWidget::isShown() const |
|
11411 |
||
11412 |
Use !isHidden() instead (notice the exclamation mark), or use isVisible() to check whether the widget is visible. |
|
11413 |
*/ |
|
11414 |
||
11415 |
/*! |
|
11416 |
\fn bool QWidget::isDialog() const |
|
11417 |
||
11418 |
Use windowType() == Qt::Dialog instead. |
|
11419 |
*/ |
|
11420 |
||
11421 |
/*! |
|
11422 |
\fn bool QWidget::isPopup() const |
|
11423 |
||
11424 |
Use windowType() == Qt::Popup instead. |
|
11425 |
*/ |
|
11426 |
||
11427 |
/*! |
|
11428 |
\fn bool QWidget::isDesktop() const |
|
11429 |
||
11430 |
Use windowType() == Qt::Desktop instead. |
|
11431 |
*/ |
|
11432 |
||
11433 |
/*! |
|
11434 |
\fn void QWidget::polish() |
|
11435 |
||
11436 |
Use ensurePolished() instead. |
|
11437 |
*/ |
|
11438 |
||
11439 |
/*! |
|
11440 |
\fn QWidget *QWidget::childAt(int x, int y, bool includeThis) const |
|
11441 |
||
11442 |
Use the childAt() overload that doesn't have an \a includeThis parameter. |
|
11443 |
||
11444 |
\oldcode |
|
11445 |
return widget->childAt(x, y, true); |
|
11446 |
\newcode |
|
11447 |
QWidget *child = widget->childAt(x, y, true); |
|
11448 |
if (child) |
|
11449 |
return child; |
|
11450 |
if (widget->rect().contains(x, y)) |
|
11451 |
return widget; |
|
11452 |
\endcode |
|
11453 |
*/ |
|
11454 |
||
11455 |
/*! |
|
11456 |
\fn void QWidget::setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver, bool hfw) |
|
11457 |
\compat |
|
11458 |
||
11459 |
Use the \l sizePolicy property and heightForWidth() function instead. |
|
11460 |
*/ |
|
11461 |
||
11462 |
/*! |
|
11463 |
\fn bool QWidget::isUpdatesEnabled() const |
|
11464 |
\compat |
|
11465 |
||
11466 |
Use the \l updatesEnabled property instead. |
|
11467 |
*/ |
|
11468 |
||
11469 |
/*! |
|
11470 |
\macro QWIDGETSIZE_MAX |
|
11471 |
\relates QWidget |
|
11472 |
||
11473 |
Defines the maximum size for a QWidget object. |
|
11474 |
||
11475 |
The largest allowed size for a widget is QSize(QWIDGETSIZE_MAX, |
|
11476 |
QWIDGETSIZE_MAX), i.e. QSize (16777215,16777215). |
|
11477 |
||
11478 |
\sa QWidget::setMaximumSize() |
|
11479 |
*/ |
|
11480 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11481 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11482 |
\fn QWidget::setupUi(QWidget *widget) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11483 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11484 |
Sets up the user interface for the specified \a widget. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11485 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11486 |
\note This function is available with widgets that derive from user |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11487 |
interface descriptions created using \l{uic}. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11488 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11489 |
\sa {Using a Designer UI File in Your Application} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11490 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11491 |
|
0 | 11492 |
QRect QWidgetPrivate::frameStrut() const |
11493 |
{ |
|
11494 |
Q_Q(const QWidget); |
|
11495 |
if (!q->isWindow() || (q->windowType() == Qt::Desktop) || q->testAttribute(Qt::WA_DontShowOnScreen)) { |
|
11496 |
// x2 = x1 + w - 1, so w/h = 1 |
|
11497 |
return QRect(0, 0, 1, 1); |
|
11498 |
} |
|
11499 |
||
11500 |
if (data.fstrut_dirty |
|
11501 |
#ifndef Q_WS_WIN |
|
11502 |
// ### Fix properly for 4.3 |
|
11503 |
&& q->isVisible() |
|
11504 |
#endif |
|
11505 |
&& q->testAttribute(Qt::WA_WState_Created)) |
|
11506 |
const_cast<QWidgetPrivate *>(this)->updateFrameStrut(); |
|
11507 |
||
11508 |
return maybeTopData() ? maybeTopData()->frameStrut : QRect(); |
|
11509 |
} |
|
11510 |
||
11511 |
#ifdef QT_KEYPAD_NAVIGATION |
|
11512 |
/*! |
|
11513 |
\internal |
|
11514 |
||
11515 |
Changes the focus from the current focusWidget to a widget in |
|
11516 |
the \a direction. |
|
11517 |
||
11518 |
Returns true, if there was a widget in that direction |
|
11519 |
*/ |
|
11520 |
bool QWidgetPrivate::navigateToDirection(Direction direction) |
|
11521 |
{ |
|
11522 |
QWidget *targetWidget = widgetInNavigationDirection(direction); |
|
11523 |
if (targetWidget) |
|
11524 |
targetWidget->setFocus(); |
|
11525 |
return (targetWidget != 0); |
|
11526 |
} |
|
11527 |
||
11528 |
/*! |
|
11529 |
\internal |
|
11530 |
||
11531 |
Searches for a widget that is positioned in the \a direction, starting |
|
11532 |
from the current focusWidget. |
|
11533 |
||
11534 |
Returns the pointer to a found widget or 0, if there was no widget in |
|
11535 |
that direction. |
|
11536 |
*/ |
|
11537 |
QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction) |
|
11538 |
{ |
|
11539 |
const QWidget *sourceWidget = QApplication::focusWidget(); |
|
11540 |
if (!sourceWidget) |
|
11541 |
return 0; |
|
11542 |
const QRect sourceRect = sourceWidget->rect().translated(sourceWidget->mapToGlobal(QPoint())); |
|
11543 |
const int sourceX = |
|
11544 |
(direction == DirectionNorth || direction == DirectionSouth) ? |
|
11545 |
(sourceRect.left() + (sourceRect.right() - sourceRect.left()) / 2) |
|
11546 |
:(direction == DirectionEast ? sourceRect.right() : sourceRect.left()); |
|
11547 |
const int sourceY = |
|
11548 |
(direction == DirectionEast || direction == DirectionWest) ? |
|
11549 |
(sourceRect.top() + (sourceRect.bottom() - sourceRect.top()) / 2) |
|
11550 |
:(direction == DirectionSouth ? sourceRect.bottom() : sourceRect.top()); |
|
11551 |
const QPoint sourcePoint(sourceX, sourceY); |
|
11552 |
const QPoint sourceCenter = sourceRect.center(); |
|
11553 |
const QWidget *sourceWindow = sourceWidget->window(); |
|
11554 |
||
11555 |
QWidget *targetWidget = 0; |
|
11556 |
int shortestDistance = INT_MAX; |
|
11557 |
foreach(QWidget *targetCandidate, QApplication::allWidgets()) { |
|
11558 |
||
11559 |
const QRect targetCandidateRect = targetCandidate->rect().translated(targetCandidate->mapToGlobal(QPoint())); |
|
11560 |
||
11561 |
// For focus proxies, the child widget handling the focus can have keypad navigation focus, |
|
11562 |
// but the owner of the proxy cannot. |
|
11563 |
// Additionally, empty widgets should be ignored. |
|
11564 |
if (targetCandidate->focusProxy() || targetCandidateRect.isEmpty()) |
|
11565 |
continue; |
|
11566 |
||
11567 |
// Only navigate to a target widget that... |
|
11568 |
if ( targetCandidate != sourceWidget |
|
11569 |
// ...takes the focus, |
|
11570 |
&& targetCandidate->focusPolicy() & Qt::TabFocus |
|
11571 |
// ...is above if DirectionNorth, |
|
11572 |
&& !(direction == DirectionNorth && targetCandidateRect.bottom() > sourceRect.top()) |
|
11573 |
// ...is on the right if DirectionEast, |
|
11574 |
&& !(direction == DirectionEast && targetCandidateRect.left() < sourceRect.right()) |
|
11575 |
// ...is below if DirectionSouth, |
|
11576 |
&& !(direction == DirectionSouth && targetCandidateRect.top() < sourceRect.bottom()) |
|
11577 |
// ...is on the left if DirectionWest, |
|
11578 |
&& !(direction == DirectionWest && targetCandidateRect.right() > sourceRect.left()) |
|
11579 |
// ...is enabled, |
|
11580 |
&& targetCandidate->isEnabled() |
|
11581 |
// ...is visible, |
|
11582 |
&& targetCandidate->isVisible() |
|
11583 |
// ...is in the same window, |
|
11584 |
&& targetCandidate->window() == sourceWindow) { |
|
11585 |
const int targetCandidateDistance = pointToRect(sourcePoint, targetCandidateRect); |
|
11586 |
if (targetCandidateDistance < shortestDistance) { |
|
11587 |
shortestDistance = targetCandidateDistance; |
|
11588 |
targetWidget = targetCandidate; |
|
11589 |
} |
|
11590 |
} |
|
11591 |
} |
|
11592 |
return targetWidget; |
|
11593 |
} |
|
11594 |
#endif |
|
11595 |
||
11596 |
/*! |
|
11597 |
\preliminary |
|
11598 |
\since 4.2 |
|
11599 |
\obsolete |
|
11600 |
||
11601 |
Sets the window surface to be the \a surface specified. |
|
11602 |
The QWidget takes will ownership of the \a surface. |
|
11603 |
widget itself is deleted. |
|
11604 |
*/ |
|
11605 |
void QWidget::setWindowSurface(QWindowSurface *surface) |
|
11606 |
{ |
|
11607 |
// ### createWinId() ?? |
|
11608 |
||
11609 |
#ifndef Q_BACKINGSTORE_SUBSURFACES |
|
11610 |
if (!isTopLevel()) |
|
11611 |
return; |
|
11612 |
#endif |
|
11613 |
||
11614 |
Q_D(QWidget); |
|
11615 |
||
11616 |
QTLWExtra *topData = d->topData(); |
|
11617 |
if (topData->windowSurface == surface) |
|
11618 |
return; |
|
11619 |
||
11620 |
QWindowSurface *oldSurface = topData->windowSurface; |
|
11621 |
delete topData->windowSurface; |
|
11622 |
topData->windowSurface = surface; |
|
11623 |
||
11624 |
QWidgetBackingStore *bs = d->maybeBackingStore(); |
|
11625 |
if (!bs) |
|
11626 |
return; |
|
11627 |
||
11628 |
if (isTopLevel()) { |
|
11629 |
if (bs->windowSurface != oldSurface && bs->windowSurface != surface) |
|
11630 |
delete bs->windowSurface; |
|
11631 |
bs->windowSurface = surface; |
|
11632 |
} |
|
11633 |
#ifdef Q_BACKINGSTORE_SUBSURFACES |
|
11634 |
else { |
|
11635 |
bs->subSurfaces.append(surface); |
|
11636 |
} |
|
11637 |
bs->subSurfaces.removeOne(oldSurface); |
|
11638 |
#endif |
|
11639 |
} |
|
11640 |
||
11641 |
/*! |
|
11642 |
\preliminary |
|
11643 |
\since 4.2 |
|
11644 |
||
11645 |
Returns the QWindowSurface this widget will be drawn into. |
|
11646 |
*/ |
|
11647 |
QWindowSurface *QWidget::windowSurface() const |
|
11648 |
{ |
|
11649 |
Q_D(const QWidget); |
|
11650 |
QTLWExtra *extra = d->maybeTopData(); |
|
11651 |
if (extra && extra->windowSurface) |
|
11652 |
return extra->windowSurface; |
|
11653 |
||
11654 |
QWidgetBackingStore *bs = d->maybeBackingStore(); |
|
11655 |
||
11656 |
#ifdef Q_BACKINGSTORE_SUBSURFACES |
|
11657 |
if (bs && bs->subSurfaces.isEmpty()) |
|
11658 |
return bs->windowSurface; |
|
11659 |
||
11660 |
if (!isTopLevel()) { |
|
11661 |
const QWidget *w = parentWidget(); |
|
11662 |
while (w) { |
|
11663 |
QTLWExtra *extra = w->d_func()->maybeTopData(); |
|
11664 |
if (extra && extra->windowSurface) |
|
11665 |
return extra->windowSurface; |
|
11666 |
if (w->isTopLevel()) |
|
11667 |
break; |
|
11668 |
w = w->parentWidget(); |
|
11669 |
} |
|
11670 |
} |
|
11671 |
#endif // Q_BACKINGSTORE_SUBSURFACES |
|
11672 |
||
11673 |
return bs ? bs->windowSurface : 0; |
|
11674 |
} |
|
11675 |
||
11676 |
void QWidgetPrivate::getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const |
|
11677 |
{ |
|
11678 |
if (left) |
|
11679 |
*left = (int)leftLayoutItemMargin; |
|
11680 |
if (top) |
|
11681 |
*top = (int)topLayoutItemMargin; |
|
11682 |
if (right) |
|
11683 |
*right = (int)rightLayoutItemMargin; |
|
11684 |
if (bottom) |
|
11685 |
*bottom = (int)bottomLayoutItemMargin; |
|
11686 |
} |
|
11687 |
||
11688 |
void QWidgetPrivate::setLayoutItemMargins(int left, int top, int right, int bottom) |
|
11689 |
{ |
|
11690 |
if (leftLayoutItemMargin == left |
|
11691 |
&& topLayoutItemMargin == top |
|
11692 |
&& rightLayoutItemMargin == right |
|
11693 |
&& bottomLayoutItemMargin == bottom) |
|
11694 |
return; |
|
11695 |
||
11696 |
Q_Q(QWidget); |
|
11697 |
leftLayoutItemMargin = (signed char)left; |
|
11698 |
topLayoutItemMargin = (signed char)top; |
|
11699 |
rightLayoutItemMargin = (signed char)right; |
|
11700 |
bottomLayoutItemMargin = (signed char)bottom; |
|
11701 |
q->updateGeometry(); |
|
11702 |
} |
|
11703 |
||
11704 |
void QWidgetPrivate::setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt) |
|
11705 |
{ |
|
11706 |
Q_Q(QWidget); |
|
11707 |
QStyleOption myOpt; |
|
11708 |
if (!opt) { |
|
11709 |
myOpt.initFrom(q); |
|
11710 |
myOpt.rect.setRect(0, 0, 32768, 32768); // arbitrary |
|
11711 |
opt = &myOpt; |
|
11712 |
} |
|
11713 |
||
11714 |
QRect liRect = q->style()->subElementRect(element, opt, q); |
|
11715 |
if (liRect.isValid()) { |
|
11716 |
leftLayoutItemMargin = (signed char)(opt->rect.left() - liRect.left()); |
|
11717 |
topLayoutItemMargin = (signed char)(opt->rect.top() - liRect.top()); |
|
11718 |
rightLayoutItemMargin = (signed char)(liRect.right() - opt->rect.right()); |
|
11719 |
bottomLayoutItemMargin = (signed char)(liRect.bottom() - opt->rect.bottom()); |
|
11720 |
} else { |
|
11721 |
leftLayoutItemMargin = 0; |
|
11722 |
topLayoutItemMargin = 0; |
|
11723 |
rightLayoutItemMargin = 0; |
|
11724 |
bottomLayoutItemMargin = 0; |
|
11725 |
} |
|
11726 |
} |
|
11727 |
// resets the Qt::WA_QuitOnClose attribute to the default value for transient widgets. |
|
11728 |
void QWidgetPrivate::adjustQuitOnCloseAttribute() |
|
11729 |
{ |
|
11730 |
Q_Q(QWidget); |
|
11731 |
||
11732 |
if (!q->parentWidget()) { |
|
11733 |
Qt::WindowType type = q->windowType(); |
|
11734 |
if (type == Qt::Widget || type == Qt::SubWindow) |
|
11735 |
type = Qt::Window; |
|
11736 |
if (type != Qt::Widget && type != Qt::Window && type != Qt::Dialog) |
|
11737 |
q->setAttribute(Qt::WA_QuitOnClose, false); |
|
11738 |
} |
|
11739 |
} |
|
11740 |
||
11741 |
||
11742 |
||
11743 |
Q_GUI_EXPORT QWidgetData *qt_qwidget_data(QWidget *widget) |
|
11744 |
{ |
|
11745 |
return widget->data; |
|
11746 |
} |
|
11747 |
||
11748 |
Q_GUI_EXPORT QWidgetPrivate *qt_widget_private(QWidget *widget) |
|
11749 |
{ |
|
11750 |
return widget->d_func(); |
|
11751 |
} |
|
11752 |
||
11753 |
||
11754 |
#ifndef QT_NO_GRAPHICSVIEW |
|
11755 |
/*! |
|
11756 |
\since 4.5 |
|
11757 |
||
11758 |
Returns the proxy widget for the corresponding embedded widget in a graphics |
|
11759 |
view; otherwise returns 0. |
|
11760 |
||
11761 |
\sa QGraphicsProxyWidget::createProxyForChildWidget(), |
|
11762 |
QGraphicsScene::addWidget() |
|
11763 |
*/ |
|
11764 |
QGraphicsProxyWidget *QWidget::graphicsProxyWidget() const |
|
11765 |
{ |
|
11766 |
Q_D(const QWidget); |
|
11767 |
if (d->extra) { |
|
11768 |
return d->extra->proxyWidget; |
|
11769 |
} |
|
11770 |
return 0; |
|
11771 |
} |
|
11772 |
#endif |
|
11773 |
||
11774 |
||
11775 |
/*! |
|
11776 |
\typedef QWidgetList |
|
11777 |
\relates QWidget |
|
11778 |
||
11779 |
Synonym for QList<QWidget *>. |
|
11780 |
*/ |
|
11781 |
||
11782 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11783 |
Subscribes the widget to a given \a gesture with specific \a flags. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11784 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11785 |
\sa ungrabGesture(), QGestureEvent |
0 | 11786 |
\since 4.6 |
11787 |
*/ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11788 |
void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags) |
0 | 11789 |
{ |
11790 |
Q_D(QWidget); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11791 |
d->gestureContext.insert(gesture, flags); |
0 | 11792 |
(void)QGestureManager::instance(); // create a gesture manager |
11793 |
} |
|
11794 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11795 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11796 |
Unsubscribes the widget from a given \a gesture type |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11797 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11798 |
\sa grabGesture(), QGestureEvent |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11799 |
\since 4.6 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11800 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11801 |
void QWidget::ungrabGesture(Qt::GestureType gesture) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11802 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11803 |
Q_D(QWidget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11804 |
if (d->gestureContext.remove(gesture)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11805 |
QGestureManager *manager = QGestureManager::instance(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11806 |
manager->cleanupCachedGestures(this, gesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11807 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11808 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11809 |
|
0 | 11810 |
|
11811 |
/*! |
|
11812 |
\typedef WId |
|
11813 |
\relates QWidget |
|
11814 |
||
11815 |
Platform dependent window identifier. |
|
11816 |
*/ |
|
11817 |
||
11818 |
/*! |
|
11819 |
\fn void QWidget::destroy(bool destroyWindow, bool destroySubWindows) |
|
11820 |
||
11821 |
Frees up window system resources. Destroys the widget window if \a |
|
11822 |
destroyWindow is true. |
|
11823 |
||
11824 |
destroy() calls itself recursively for all the child widgets, |
|
11825 |
passing \a destroySubWindows for the \a destroyWindow parameter. |
|
11826 |
To have more control over destruction of subwidgets, destroy |
|
11827 |
subwidgets selectively first. |
|
11828 |
||
11829 |
This function is usually called from the QWidget destructor. |
|
11830 |
*/ |
|
11831 |
||
11832 |
/*! |
|
11833 |
\fn QPaintEngine *QWidget::paintEngine() const |
|
11834 |
||
11835 |
Returns the widget's paint engine. |
|
11836 |
||
11837 |
Note that this function should not be called explicitly by the |
|
11838 |
user, since it's meant for reimplementation purposes only. The |
|
11839 |
function is called by Qt internally, and the default |
|
11840 |
implementation may not always return a valid pointer. |
|
11841 |
*/ |
|
11842 |
||
11843 |
/*! |
|
11844 |
\fn QPoint QWidget::mapToGlobal(const QPoint &pos) const |
|
11845 |
||
11846 |
Translates the widget coordinate \a pos to global screen |
|
11847 |
coordinates. For example, \c{mapToGlobal(QPoint(0,0))} would give |
|
11848 |
the global coordinates of the top-left pixel of the widget. |
|
11849 |
||
11850 |
\sa mapFromGlobal() mapTo() mapToParent() |
|
11851 |
*/ |
|
11852 |
||
11853 |
/*! |
|
11854 |
\fn QPoint QWidget::mapFromGlobal(const QPoint &pos) const |
|
11855 |
||
11856 |
Translates the global screen coordinate \a pos to widget |
|
11857 |
coordinates. |
|
11858 |
||
11859 |
\sa mapToGlobal() mapFrom() mapFromParent() |
|
11860 |
*/ |
|
11861 |
||
11862 |
/*! |
|
11863 |
\fn void QWidget::grabMouse() |
|
11864 |
||
11865 |
Grabs the mouse input. |
|
11866 |
||
11867 |
This widget receives all mouse events until releaseMouse() is |
|
11868 |
called; other widgets get no mouse events at all. Keyboard |
|
11869 |
events are not affected. Use grabKeyboard() if you want to grab |
|
11870 |
that. |
|
11871 |
||
11872 |
\warning Bugs in mouse-grabbing applications very often lock the |
|
11873 |
terminal. Use this function with extreme caution, and consider |
|
11874 |
using the \c -nograb command line option while debugging. |
|
11875 |
||
11876 |
It is almost never necessary to grab the mouse when using Qt, as |
|
11877 |
Qt grabs and releases it sensibly. In particular, Qt grabs the |
|
11878 |
mouse when a mouse button is pressed and keeps it until the last |
|
11879 |
button is released. |
|
11880 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
11881 |
\note Only visible widgets can grab mouse input. If isVisible() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
11882 |
returns false for a widget, that widget cannot call grabMouse(). |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
11883 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
11884 |
\note \bold{(Mac OS X developers)} For \e Cocoa, calling |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
11885 |
grabMouse() on a widget only works when the mouse is inside the |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
11886 |
frame of that widget. For \e Carbon, it works outside the widget's |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
11887 |
frame as well, like for Windows and X11. |
0 | 11888 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11889 |
\sa releaseMouse() grabKeyboard() releaseKeyboard() |
0 | 11890 |
*/ |
11891 |
||
11892 |
/*! |
|
11893 |
\fn void QWidget::grabMouse(const QCursor &cursor) |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
11894 |
\overload grabMouse() |
0 | 11895 |
|
11896 |
Grabs the mouse input and changes the cursor shape. |
|
11897 |
||
11898 |
The cursor will assume shape \a cursor (for as long as the mouse |
|
11899 |
focus is grabbed) and this widget will be the only one to receive |
|
11900 |
mouse events until releaseMouse() is called(). |
|
11901 |
||
11902 |
\warning Grabbing the mouse might lock the terminal. |
|
11903 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
11904 |
\note \bold{(Mac OS X developers)} See the note in QWidget::grabMouse(). |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
11905 |
|
0 | 11906 |
\sa releaseMouse(), grabKeyboard(), releaseKeyboard(), setCursor() |
11907 |
*/ |
|
11908 |
||
11909 |
/*! |
|
11910 |
\fn void QWidget::releaseMouse() |
|
11911 |
||
11912 |
Releases the mouse grab. |
|
11913 |
||
11914 |
\sa grabMouse(), grabKeyboard(), releaseKeyboard() |
|
11915 |
*/ |
|
11916 |
||
11917 |
/*! |
|
11918 |
\fn void QWidget::grabKeyboard() |
|
11919 |
||
11920 |
Grabs the keyboard input. |
|
11921 |
||
11922 |
This widget receives all keyboard events until releaseKeyboard() |
|
11923 |
is called; other widgets get no keyboard events at all. Mouse |
|
11924 |
events are not affected. Use grabMouse() if you want to grab that. |
|
11925 |
||
11926 |
The focus widget is not affected, except that it doesn't receive |
|
11927 |
any keyboard events. setFocus() moves the focus as usual, but the |
|
11928 |
new focus widget receives keyboard events only after |
|
11929 |
releaseKeyboard() is called. |
|
11930 |
||
11931 |
If a different widget is currently grabbing keyboard input, that |
|
11932 |
widget's grab is released first. |
|
11933 |
||
11934 |
\sa releaseKeyboard() grabMouse() releaseMouse() focusWidget() |
|
11935 |
*/ |
|
11936 |
||
11937 |
/*! |
|
11938 |
\fn void QWidget::releaseKeyboard() |
|
11939 |
||
11940 |
Releases the keyboard grab. |
|
11941 |
||
11942 |
\sa grabKeyboard(), grabMouse(), releaseMouse() |
|
11943 |
*/ |
|
11944 |
||
11945 |
/*! |
|
11946 |
\fn QWidget *QWidget::mouseGrabber() |
|
11947 |
||
11948 |
Returns the widget that is currently grabbing the mouse input. |
|
11949 |
||
11950 |
If no widget in this application is currently grabbing the mouse, |
|
11951 |
0 is returned. |
|
11952 |
||
11953 |
\sa grabMouse(), keyboardGrabber() |
|
11954 |
*/ |
|
11955 |
||
11956 |
/*! |
|
11957 |
\fn QWidget *QWidget::keyboardGrabber() |
|
11958 |
||
11959 |
Returns the widget that is currently grabbing the keyboard input. |
|
11960 |
||
11961 |
If no widget in this application is currently grabbing the |
|
11962 |
keyboard, 0 is returned. |
|
11963 |
||
11964 |
\sa grabMouse(), mouseGrabber() |
|
11965 |
*/ |
|
11966 |
||
11967 |
/*! |
|
11968 |
\fn void QWidget::activateWindow() |
|
11969 |
||
11970 |
Sets the top-level widget containing this widget to be the active |
|
11971 |
window. |
|
11972 |
||
11973 |
An active window is a visible top-level window that has the |
|
11974 |
keyboard input focus. |
|
11975 |
||
11976 |
This function performs the same operation as clicking the mouse on |
|
11977 |
the title bar of a top-level window. On X11, the result depends on |
|
11978 |
the Window Manager. If you want to ensure that the window is |
|
11979 |
stacked on top as well you should also call raise(). Note that the |
|
11980 |
window must be visible, otherwise activateWindow() has no effect. |
|
11981 |
||
11982 |
On Windows, if you are calling this when the application is not |
|
11983 |
currently the active one then it will not make it the active |
|
11984 |
window. It will change the color of the taskbar entry to indicate |
|
11985 |
that the window has changed in some way. This is because Microsoft |
|
11986 |
does not allow an application to interrupt what the user is currently |
|
11987 |
doing in another application. |
|
11988 |
||
11989 |
\sa isActiveWindow(), window(), show() |
|
11990 |
*/ |
|
11991 |
||
11992 |
/*! |
|
11993 |
\fn int QWidget::metric(PaintDeviceMetric m) const |
|
11994 |
||
11995 |
Internal implementation of the virtual QPaintDevice::metric() |
|
11996 |
function. |
|
11997 |
||
11998 |
\a m is the metric to get. |
|
11999 |
*/ |
|
12000 |
||
12001 |
/*! |
|
12002 |
\fn void QWidget::setMask(const QRegion ®ion) |
|
12003 |
\overload |
|
12004 |
||
12005 |
Causes only the parts of the widget which overlap \a region to be |
|
12006 |
visible. If the region includes pixels outside the rect() of the |
|
12007 |
widget, window system controls in that area may or may not be |
|
12008 |
visible, depending on the platform. |
|
12009 |
||
12010 |
Note that this effect can be slow if the region is particularly |
|
12011 |
complex. |
|
12012 |
||
12013 |
\sa windowOpacity |
|
12014 |
*/ |
|
12015 |
void QWidget::setMask(const QRegion &newMask) |
|
12016 |
{ |
|
12017 |
Q_D(QWidget); |
|
12018 |
||
12019 |
d->createExtra(); |
|
12020 |
if (newMask == d->extra->mask) |
|
12021 |
return; |
|
12022 |
||
12023 |
#ifndef QT_NO_BACKINGSTORE |
|
12024 |
const QRegion oldMask(d->extra->mask); |
|
12025 |
#endif |
|
12026 |
||
12027 |
d->extra->mask = newMask; |
|
12028 |
d->extra->hasMask = !newMask.isEmpty(); |
|
12029 |
||
12030 |
#ifndef QT_MAC_USE_COCOA |
|
12031 |
if (!testAttribute(Qt::WA_WState_Created)) |
|
12032 |
return; |
|
12033 |
#endif |
|
12034 |
||
12035 |
d->setMask_sys(newMask); |
|
12036 |
||
12037 |
#ifndef QT_NO_BACKINGSTORE |
|
12038 |
if (!isVisible()) |
|
12039 |
return; |
|
12040 |
||
12041 |
if (!d->extra->hasMask) { |
|
12042 |
// Mask was cleared; update newly exposed area. |
|
12043 |
QRegion expose(rect()); |
|
12044 |
expose -= oldMask; |
|
12045 |
if (!expose.isEmpty()) { |
|
12046 |
d->setDirtyOpaqueRegion(); |
|
12047 |
update(expose); |
|
12048 |
} |
|
12049 |
return; |
|
12050 |
} |
|
12051 |
||
12052 |
if (!isWindow()) { |
|
12053 |
// Update newly exposed area on the parent widget. |
|
12054 |
QRegion parentExpose(rect()); |
|
12055 |
parentExpose -= newMask; |
|
12056 |
if (!parentExpose.isEmpty()) { |
|
12057 |
d->setDirtyOpaqueRegion(); |
|
12058 |
parentExpose.translate(data->crect.topLeft()); |
|
12059 |
parentWidget()->update(parentExpose); |
|
12060 |
} |
|
12061 |
||
12062 |
// Update newly exposed area on this widget |
|
12063 |
if (!oldMask.isEmpty()) |
|
12064 |
update(newMask - oldMask); |
|
12065 |
} |
|
12066 |
#endif |
|
12067 |
} |
|
12068 |
||
12069 |
/*! |
|
12070 |
\fn void QWidget::setMask(const QBitmap &bitmap) |
|
12071 |
||
12072 |
Causes only the pixels of the widget for which \a bitmap has a |
|
12073 |
corresponding 1 bit to be visible. If the region includes pixels |
|
12074 |
outside the rect() of the widget, window system controls in that |
|
12075 |
area may or may not be visible, depending on the platform. |
|
12076 |
||
12077 |
Note that this effect can be slow if the region is particularly |
|
12078 |
complex. |
|
12079 |
||
12080 |
The following code shows how an image with an alpha channel can be |
|
12081 |
used to generate a mask for a widget: |
|
12082 |
||
12083 |
\snippet doc/src/snippets/widget-mask/main.cpp 0 |
|
12084 |
||
12085 |
The label shown by this code is masked using the image it contains, |
|
12086 |
giving the appearance that an irregularly-shaped image is being drawn |
|
12087 |
directly onto the screen. |
|
12088 |
||
12089 |
Masked widgets receive mouse events only on their visible |
|
12090 |
portions. |
|
12091 |
||
12092 |
\sa clearMask(), windowOpacity(), {Shaped Clock Example} |
|
12093 |
*/ |
|
12094 |
void QWidget::setMask(const QBitmap &bitmap) |
|
12095 |
{ |
|
12096 |
setMask(QRegion(bitmap)); |
|
12097 |
} |
|
12098 |
||
12099 |
/*! |
|
12100 |
\fn void QWidget::clearMask() |
|
12101 |
||
12102 |
Removes any mask set by setMask(). |
|
12103 |
||
12104 |
\sa setMask() |
|
12105 |
*/ |
|
12106 |
void QWidget::clearMask() |
|
12107 |
{ |
|
12108 |
setMask(QRegion()); |
|
12109 |
} |
|
12110 |
||
12111 |
/*! \fn const QX11Info &QWidget::x11Info() const |
|
12112 |
Returns information about the configuration of the X display used to display |
|
12113 |
the widget. |
|
12114 |
||
12115 |
\warning This function is only available on X11. |
|
12116 |
*/ |
|
12117 |
||
12118 |
/*! \fn Qt::HANDLE QWidget::x11PictureHandle() const |
|
12119 |
Returns the X11 Picture handle of the widget for XRender |
|
12120 |
support. Use of this function is not portable. This function will |
|
12121 |
return 0 if XRender support is not compiled into Qt, if the |
|
12122 |
XRender extension is not supported on the X11 display, or if the |
|
12123 |
handle could not be created. |
|
12124 |
*/ |
|
12125 |
||
12126 |
#ifdef Q_OS_SYMBIAN |
|
12127 |
void QWidgetPrivate::_q_delayedDestroy(WId winId) |
|
12128 |
{ |
|
12129 |
delete winId; |
|
12130 |
} |
|
12131 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
12132 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
12133 |
QT_END_NAMESPACE |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
12134 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
12135 |
#include "moc_qwidget.cpp" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
12136 |