1 | /****************************************************************************
|
---|
2 | ** $Id: qwidget.cpp 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Implementation of QWidget class
|
---|
5 | **
|
---|
6 | ** Created : 931031
|
---|
7 | **
|
---|
8 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
|
---|
9 | **
|
---|
10 | ** This file is part of the kernel module of the Qt GUI Toolkit.
|
---|
11 | **
|
---|
12 | ** This file may be distributed under the terms of the Q Public License
|
---|
13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
---|
14 | ** LICENSE.QPL included in the packaging of this file.
|
---|
15 | **
|
---|
16 | ** This file may be distributed and/or modified under the terms of the
|
---|
17 | ** GNU General Public License version 2 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
19 | ** packaging of this file.
|
---|
20 | **
|
---|
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
22 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
23 | ** Agreement provided with the Software.
|
---|
24 | **
|
---|
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
27 | **
|
---|
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
29 | ** information about Qt Commercial License Agreements.
|
---|
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
32 | **
|
---|
33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
34 | ** not clear to you.
|
---|
35 | **
|
---|
36 | **********************************************************************/
|
---|
37 |
|
---|
38 |
|
---|
39 | #include "qobjectlist.h"
|
---|
40 | #include "qwidget.h"
|
---|
41 | #include "qwidgetlist.h"
|
---|
42 | #include "qwidgetintdict.h"
|
---|
43 | #include "qptrdict.h"
|
---|
44 | #include "qfocusdata.h"
|
---|
45 | #include "qcursor.h"
|
---|
46 | #include "qpixmap.h"
|
---|
47 | #include "qapplication.h"
|
---|
48 | #include "qapplication_p.h"
|
---|
49 | #include "qbrush.h"
|
---|
50 | #include "qlayout.h"
|
---|
51 | #include "qstylefactory.h"
|
---|
52 | #include "qcleanuphandler.h"
|
---|
53 | #include "qstyle.h"
|
---|
54 | #include "qmetaobject.h"
|
---|
55 | #include "qguardedptr.h"
|
---|
56 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
---|
57 | #include "qaccessible.h"
|
---|
58 | #endif
|
---|
59 | #if defined(Q_WS_WIN)
|
---|
60 | #include "qt_windows.h"
|
---|
61 | #include "qinputcontext_p.h"
|
---|
62 | #endif
|
---|
63 | #if defined(Q_WS_QWS)
|
---|
64 | #include "qwsmanager_qws.h"
|
---|
65 | #endif
|
---|
66 | #include "qfontdata_p.h"
|
---|
67 |
|
---|
68 |
|
---|
69 | /*!
|
---|
70 | \class QWidget qwidget.h
|
---|
71 | \brief The QWidget class is the base class of all user interface objects.
|
---|
72 |
|
---|
73 | \ingroup abstractwidgets
|
---|
74 | \mainclass
|
---|
75 |
|
---|
76 | The widget is the atom of the user interface: it receives mouse,
|
---|
77 | keyboard and other events from the window system, and paints a
|
---|
78 | representation of itself on the screen. Every widget is
|
---|
79 | rectangular, and they are sorted in a Z-order. A widget is
|
---|
80 | clipped by its parent and by the widgets in front of it.
|
---|
81 |
|
---|
82 | A widget that isn't embedded in a parent widget is called a
|
---|
83 | top-level widget. Usually, top-level widgets are windows with a
|
---|
84 | frame and a title bar (although it is also possible to create
|
---|
85 | top-level widgets without such decoration if suitable widget flags
|
---|
86 | are used). In Qt, QMainWindow and the various subclasses of
|
---|
87 | QDialog are the most common top-level windows.
|
---|
88 |
|
---|
89 | A widget without a parent widget is always a top-level widget.
|
---|
90 |
|
---|
91 | Non-top-level widgets are child widgets. These are child windows
|
---|
92 | in their parent widgets. You cannot usually distinguish a child
|
---|
93 | widget from its parent visually. Most other widgets in Qt are
|
---|
94 | useful only as child widgets. (It is possible to make, say, a
|
---|
95 | button into a top-level widget, but most people prefer to put
|
---|
96 | their buttons inside other widgets, e.g. QDialog.)
|
---|
97 |
|
---|
98 | If you want to use a QWidget to hold child widgets you will
|
---|
99 | probably want to add a layout to the parent QWidget. (See \link
|
---|
100 | layout.html Layouts\endlink.)
|
---|
101 |
|
---|
102 | QWidget has many member functions, but some of them have little
|
---|
103 | direct functionality: for example, QWidget has a font property,
|
---|
104 | but never uses this itself. There are many subclasses which
|
---|
105 | provide real functionality, such as QPushButton, QListBox and
|
---|
106 | QTabDialog, etc.
|
---|
107 |
|
---|
108 | \section1 Groups of functions:
|
---|
109 |
|
---|
110 | \table
|
---|
111 | \header \i Context \i Functions
|
---|
112 |
|
---|
113 | \row \i Window functions \i
|
---|
114 | show(),
|
---|
115 | hide(),
|
---|
116 | raise(),
|
---|
117 | lower(),
|
---|
118 | close().
|
---|
119 |
|
---|
120 | \row \i Top level windows \i
|
---|
121 | caption(),
|
---|
122 | setCaption(),
|
---|
123 | icon(),
|
---|
124 | setIcon(),
|
---|
125 | iconText(),
|
---|
126 | setIconText(),
|
---|
127 | isActiveWindow(),
|
---|
128 | setActiveWindow(),
|
---|
129 | showMinimized().
|
---|
130 | showMaximized(),
|
---|
131 | showFullScreen(),
|
---|
132 | showNormal().
|
---|
133 |
|
---|
134 | \row \i Window contents \i
|
---|
135 | update(),
|
---|
136 | repaint(),
|
---|
137 | erase(),
|
---|
138 | scroll(),
|
---|
139 | updateMask().
|
---|
140 |
|
---|
141 | \row \i Geometry \i
|
---|
142 | pos(),
|
---|
143 | size(),
|
---|
144 | rect(),
|
---|
145 | x(),
|
---|
146 | y(),
|
---|
147 | width(),
|
---|
148 | height(),
|
---|
149 | sizePolicy(),
|
---|
150 | setSizePolicy(),
|
---|
151 | sizeHint(),
|
---|
152 | updateGeometry(),
|
---|
153 | layout(),
|
---|
154 | move(),
|
---|
155 | resize(),
|
---|
156 | setGeometry(),
|
---|
157 | frameGeometry(),
|
---|
158 | geometry(),
|
---|
159 | childrenRect(),
|
---|
160 | adjustSize(),
|
---|
161 | mapFromGlobal(),
|
---|
162 | mapFromParent()
|
---|
163 | mapToGlobal(),
|
---|
164 | mapToParent(),
|
---|
165 | maximumSize(),
|
---|
166 | minimumSize(),
|
---|
167 | sizeIncrement(),
|
---|
168 | setMaximumSize(),
|
---|
169 | setMinimumSize(),
|
---|
170 | setSizeIncrement(),
|
---|
171 | setBaseSize(),
|
---|
172 | setFixedSize()
|
---|
173 |
|
---|
174 | \row \i Mode \i
|
---|
175 | isVisible(),
|
---|
176 | isVisibleTo(),
|
---|
177 | isMinimized(),
|
---|
178 | isDesktop(),
|
---|
179 | isEnabled(),
|
---|
180 | isEnabledTo(),
|
---|
181 | isModal(),
|
---|
182 | isPopup(),
|
---|
183 | isTopLevel(),
|
---|
184 | setEnabled(),
|
---|
185 | hasMouseTracking(),
|
---|
186 | setMouseTracking(),
|
---|
187 | isUpdatesEnabled(),
|
---|
188 | setUpdatesEnabled(),
|
---|
189 | clipRegion().
|
---|
190 |
|
---|
191 | \row \i Look and feel \i
|
---|
192 | style(),
|
---|
193 | setStyle(),
|
---|
194 | cursor(),
|
---|
195 | setCursor()
|
---|
196 | font(),
|
---|
197 | setFont(),
|
---|
198 | palette(),
|
---|
199 | setPalette(),
|
---|
200 | backgroundMode(),
|
---|
201 | setBackgroundMode(),
|
---|
202 | colorGroup(),
|
---|
203 | fontMetrics(),
|
---|
204 | fontInfo().
|
---|
205 |
|
---|
206 | \row \i Keyboard focus<br>functions \i
|
---|
207 | isFocusEnabled(),
|
---|
208 | setFocusPolicy(),
|
---|
209 | focusPolicy(),
|
---|
210 | hasFocus(),
|
---|
211 | setFocus(),
|
---|
212 | clearFocus(),
|
---|
213 | setTabOrder(),
|
---|
214 | setFocusProxy().
|
---|
215 |
|
---|
216 | \row \i Mouse and<br>keyboard grabbing \i
|
---|
217 | grabMouse(),
|
---|
218 | releaseMouse(),
|
---|
219 | grabKeyboard(),
|
---|
220 | releaseKeyboard(),
|
---|
221 | mouseGrabber(),
|
---|
222 | keyboardGrabber().
|
---|
223 |
|
---|
224 | \row \i Event handlers \i
|
---|
225 | event(),
|
---|
226 | mousePressEvent(),
|
---|
227 | mouseReleaseEvent(),
|
---|
228 | mouseDoubleClickEvent(),
|
---|
229 | mouseMoveEvent(),
|
---|
230 | keyPressEvent(),
|
---|
231 | keyReleaseEvent(),
|
---|
232 | focusInEvent(),
|
---|
233 | focusOutEvent(),
|
---|
234 | wheelEvent(),
|
---|
235 | enterEvent(),
|
---|
236 | leaveEvent(),
|
---|
237 | paintEvent(),
|
---|
238 | moveEvent(),
|
---|
239 | resizeEvent(),
|
---|
240 | closeEvent(),
|
---|
241 | dragEnterEvent(),
|
---|
242 | dragMoveEvent(),
|
---|
243 | dragLeaveEvent(),
|
---|
244 | dropEvent(),
|
---|
245 | childEvent(),
|
---|
246 | showEvent(),
|
---|
247 | hideEvent(),
|
---|
248 | customEvent().
|
---|
249 |
|
---|
250 | \row \i Change handlers \i
|
---|
251 | enabledChange(),
|
---|
252 | fontChange(),
|
---|
253 | paletteChange(),
|
---|
254 | styleChange(),
|
---|
255 | windowActivationChange().
|
---|
256 |
|
---|
257 | \row \i System functions \i
|
---|
258 | parentWidget(),
|
---|
259 | topLevelWidget(),
|
---|
260 | reparent(),
|
---|
261 | polish(),
|
---|
262 | winId(),
|
---|
263 | find(),
|
---|
264 | metric().
|
---|
265 |
|
---|
266 | \row \i What's this help \i
|
---|
267 | customWhatsThis()
|
---|
268 |
|
---|
269 | \row \i Internal kernel<br>functions \i
|
---|
270 | focusNextPrevChild(),
|
---|
271 | wmapper(),
|
---|
272 | clearWFlags(),
|
---|
273 | getWFlags(),
|
---|
274 | setWFlags(),
|
---|
275 | testWFlags().
|
---|
276 |
|
---|
277 | \endtable
|
---|
278 |
|
---|
279 | Every widget's constructor accepts two or three standard arguments:
|
---|
280 | \list 1
|
---|
281 | \i \c{QWidget *parent = 0} is the parent of the new widget.
|
---|
282 | If it is 0 (the default), the new widget will be a top-level window.
|
---|
283 | If not, it will be a child of \e parent, and be constrained by \e
|
---|
284 | parent's geometry (unless you specify \c WType_TopLevel as
|
---|
285 | widget flag).
|
---|
286 | \i \c{const char *name = 0} is the widget name of the new
|
---|
287 | widget. You can access it using name(). The widget name is little
|
---|
288 | used by programmers but is quite useful with GUI builders such as
|
---|
289 | \e{Qt Designer} (you can name a widget in \e{Qt Designer}, and
|
---|
290 | connect() to it using the name in your code). The dumpObjectTree()
|
---|
291 | debugging function also uses it.
|
---|
292 | \i \c{WFlags f = 0} (where available) sets the widget flags; the
|
---|
293 | default is suitable for almost all widgets, but to get, for
|
---|
294 | example, a top-level widget without a window system frame, you
|
---|
295 | must use special flags.
|
---|
296 | \endlist
|
---|
297 |
|
---|
298 | The tictac/tictac.cpp example program is good example of a simple
|
---|
299 | widget. It contains a few event handlers (as all widgets must), a
|
---|
300 | few custom routines that are specific to it (as all useful widgets
|
---|
301 | do), and has a few children and connections. Everything it does
|
---|
302 | is done in response to an event: this is by far the most common way
|
---|
303 | to design GUI applications.
|
---|
304 |
|
---|
305 | You will need to supply the content for your widgets yourself, but
|
---|
306 | here is a brief run-down of the events, starting with the most common
|
---|
307 | ones:
|
---|
308 |
|
---|
309 | \list
|
---|
310 |
|
---|
311 | \i paintEvent() - called whenever the widget needs to be
|
---|
312 | repainted. Every widget which displays output must implement it,
|
---|
313 | and it is wise \e not to paint on the screen outside
|
---|
314 | paintEvent().
|
---|
315 |
|
---|
316 | \i resizeEvent() - called when the widget has been resized.
|
---|
317 |
|
---|
318 | \i mousePressEvent() - called when a mouse button is pressed.
|
---|
319 | There are six mouse-related events, but the mouse press and mouse
|
---|
320 | release events are by far the most important. A widget receives
|
---|
321 | mouse press events when the mouse is inside it, or when it has
|
---|
322 | grabbed the mouse using grabMouse().
|
---|
323 |
|
---|
324 | \i mouseReleaseEvent() - called when a mouse button is released.
|
---|
325 | A widget receives mouse release events when it has received the
|
---|
326 | corresponding mouse press event. This means that if the user
|
---|
327 | presses the mouse inside \e your widget, then drags the mouse to
|
---|
328 | somewhere else, then releases, \e your widget receives the release
|
---|
329 | event. There is one exception: if a popup menu appears while the
|
---|
330 | mouse button is held down, this popup immediately steals the mouse
|
---|
331 | events.
|
---|
332 |
|
---|
333 | \i mouseDoubleClickEvent() - not quite as obvious as it might seem.
|
---|
334 | If the user double-clicks, the widget receives a mouse press event
|
---|
335 | (perhaps a mouse move event or two if they don't hold the mouse
|
---|
336 | quite steady), a mouse release event and finally this event. It is
|
---|
337 | \e{not possible} to distinguish a click from a double click until you've
|
---|
338 | seen whether the second click arrives. (This is one reason why most GUI
|
---|
339 | books recommend that double clicks be an extension of single clicks,
|
---|
340 | rather than trigger a different action.)
|
---|
341 |
|
---|
342 | \endlist
|
---|
343 |
|
---|
344 | If your widget only contains child widgets, you probably do not need to
|
---|
345 | implement any event handlers. If you want to detect a mouse click in
|
---|
346 | a child widget call the child's hasMouse() function inside the
|
---|
347 | parent widget's mousePressEvent().
|
---|
348 |
|
---|
349 | Widgets that accept keyboard input need to reimplement a few more
|
---|
350 | event handlers:
|
---|
351 |
|
---|
352 | \list
|
---|
353 |
|
---|
354 | \i keyPressEvent() - called whenever a key is pressed, and again
|
---|
355 | when a key has been held down long enough for it to auto-repeat.
|
---|
356 | Note that the Tab and Shift+Tab keys are only passed to the widget
|
---|
357 | if they are not used by the focus-change mechanisms. To force those
|
---|
358 | keys to be processed by your widget, you must reimplement
|
---|
359 | QWidget::event().
|
---|
360 |
|
---|
361 | \i focusInEvent() - called when the widget gains keyboard focus
|
---|
362 | (assuming you have called setFocusPolicy()). Well written widgets
|
---|
363 | indicate that they own the keyboard focus in a clear but discreet
|
---|
364 | way.
|
---|
365 |
|
---|
366 | \i focusOutEvent() - called when the widget loses keyboard focus.
|
---|
367 |
|
---|
368 | \endlist
|
---|
369 |
|
---|
370 | Some widgets will also need to reimplement some of the less common
|
---|
371 | event handlers:
|
---|
372 |
|
---|
373 | \list
|
---|
374 |
|
---|
375 | \i mouseMoveEvent() - called whenever the mouse moves while a
|
---|
376 | button is held down. This is useful for, for example, dragging. If
|
---|
377 | you call setMouseTracking(TRUE), you get mouse move events even
|
---|
378 | when no buttons are held down. (Note that applications which make
|
---|
379 | use of mouse tracking are often not very useful on low-bandwidth X
|
---|
380 | connections.) (See also the \link dnd.html drag and drop\endlink
|
---|
381 | information.)
|
---|
382 |
|
---|
383 | \i keyReleaseEvent() - called whenever a key is released, and also
|
---|
384 | while it is held down if the key is auto-repeating. In that case
|
---|
385 | the widget receives a key release event and immediately a key press
|
---|
386 | event for every repeat. Note that the Tab and Shift+Tab keys are
|
---|
387 | only passed to the widget if they are not used by the focus-change
|
---|
388 | mechanisms. To force those keys to be processed by your widget, you
|
---|
389 | must reimplement QWidget::event().
|
---|
390 |
|
---|
391 | \i wheelEvent() -- called whenever the user turns the mouse wheel
|
---|
392 | while the widget has the focus.
|
---|
393 |
|
---|
394 | \i enterEvent() - called when the mouse enters the widget's screen
|
---|
395 | space. (This excludes screen space owned by any children of the
|
---|
396 | widget.)
|
---|
397 |
|
---|
398 | \i leaveEvent() - called when the mouse leaves the widget's screen
|
---|
399 | space.
|
---|
400 |
|
---|
401 | \i moveEvent() - called when the widget has been moved relative to its
|
---|
402 | parent.
|
---|
403 |
|
---|
404 | \i closeEvent() - called when the user closes the widget (or when
|
---|
405 | close() is called).
|
---|
406 |
|
---|
407 | \endlist
|
---|
408 |
|
---|
409 | There are also some rather obscure events. They are listed in
|
---|
410 | \c qevent.h and you need to reimplement event() to handle them.
|
---|
411 | The default implementation of event() handles Tab and Shift+Tab
|
---|
412 | (to move the keyboard focus), and passes on most other events to
|
---|
413 | one of the more specialized handlers above.
|
---|
414 |
|
---|
415 | When implementing a widget, there are a few more things to
|
---|
416 | consider.
|
---|
417 |
|
---|
418 | \list
|
---|
419 |
|
---|
420 | \i In the constructor, be sure to set up your member variables
|
---|
421 | early on, before there's any chance that you might receive an event.
|
---|
422 |
|
---|
423 | \i It is almost always useful to reimplement sizeHint() and to set
|
---|
424 | the correct size policy with setSizePolicy(), so users of your class
|
---|
425 | can set up layout management more easily. A size policy lets you
|
---|
426 | supply good defaults for the layout management handling, so that
|
---|
427 | other widgets can contain and manage yours easily. sizeHint()
|
---|
428 | indicates a "good" size for the widget.
|
---|
429 |
|
---|
430 | \i If your widget is a top-level window, setCaption() and setIcon() set
|
---|
431 | the title bar and icon respectively.
|
---|
432 |
|
---|
433 | \endlist
|
---|
434 |
|
---|
435 | \sa QEvent, QPainter, QGridLayout, QBoxLayout
|
---|
436 | */
|
---|
437 |
|
---|
438 |
|
---|
439 | /*****************************************************************************
|
---|
440 | Internal QWidgetMapper class
|
---|
441 |
|
---|
442 | The purpose of this class is to map widget identifiers to QWidget objects.
|
---|
443 | All QWidget objects register themselves in the QWidgetMapper when they
|
---|
444 | get an identifier. Widgets unregister themselves when they change ident-
|
---|
445 | ifier or when they are destroyed. A widget identifier is really a window
|
---|
446 | handle.
|
---|
447 |
|
---|
448 | The widget mapper is created and destroyed by the main application routines
|
---|
449 | in the file qapp_xxx.cpp.
|
---|
450 | *****************************************************************************/
|
---|
451 |
|
---|
452 | #if defined(Q_WS_QWS) || defined(Q_OS_TEMP)
|
---|
453 | static const int WDictSize = 163; // plenty for small devices
|
---|
454 | #else
|
---|
455 | static const int WDictSize = 1123; // plenty for 5 big complex windows
|
---|
456 | #endif
|
---|
457 |
|
---|
458 | class QWidgetMapper : public QWidgetIntDict
|
---|
459 | { // maps ids -> widgets
|
---|
460 | public:
|
---|
461 | QWidgetMapper();
|
---|
462 | ~QWidgetMapper();
|
---|
463 | QWidget *find( WId id ); // find widget
|
---|
464 | void insert( const QWidget * ); // insert widget
|
---|
465 | bool remove( WId id ); // remove widget
|
---|
466 | private:
|
---|
467 | WId cur_id;
|
---|
468 | QWidget *cur_widget;
|
---|
469 | };
|
---|
470 |
|
---|
471 | QWidgetMapper *QWidget::mapper = 0; // app global widget mapper
|
---|
472 |
|
---|
473 |
|
---|
474 | QWidgetMapper::QWidgetMapper() : QWidgetIntDict(WDictSize)
|
---|
475 | {
|
---|
476 | cur_id = 0;
|
---|
477 | cur_widget = 0;
|
---|
478 | }
|
---|
479 |
|
---|
480 | QWidgetMapper::~QWidgetMapper()
|
---|
481 | {
|
---|
482 | clear();
|
---|
483 | }
|
---|
484 |
|
---|
485 | inline QWidget *QWidgetMapper::find( WId id )
|
---|
486 | {
|
---|
487 | if ( id != cur_id ) { // need to lookup
|
---|
488 | cur_widget = QWidgetIntDict::find((long)id);
|
---|
489 | if ( cur_widget )
|
---|
490 | cur_id = id;
|
---|
491 | else
|
---|
492 | cur_id = 0;
|
---|
493 | }
|
---|
494 | return cur_widget;
|
---|
495 | }
|
---|
496 |
|
---|
497 | inline void QWidgetMapper::insert( const QWidget *widget )
|
---|
498 | {
|
---|
499 | QWidgetIntDict::insert((long)widget->winId(),widget);
|
---|
500 | }
|
---|
501 |
|
---|
502 | inline bool QWidgetMapper::remove( WId id )
|
---|
503 | {
|
---|
504 | if ( cur_id == id ) { // reset current widget
|
---|
505 | cur_id = 0;
|
---|
506 | cur_widget = 0;
|
---|
507 | }
|
---|
508 | return QWidgetIntDict::remove((long)id);
|
---|
509 | }
|
---|
510 |
|
---|
511 |
|
---|
512 | /*****************************************************************************
|
---|
513 | QWidget utility functions
|
---|
514 | *****************************************************************************/
|
---|
515 |
|
---|
516 | static QFont qt_naturalWidgetFont( QWidget* w ) {
|
---|
517 | QFont naturalfont = QApplication::font( w );
|
---|
518 | if ( ! w->isTopLevel() ) {
|
---|
519 | if ( ! naturalfont.isCopyOf( QApplication::font() ) )
|
---|
520 | naturalfont = naturalfont.resolve( w->parentWidget()->font() );
|
---|
521 | else
|
---|
522 | naturalfont = w->parentWidget()->font();
|
---|
523 | }
|
---|
524 | return naturalfont;
|
---|
525 | }
|
---|
526 |
|
---|
527 | #ifndef QT_NO_PALETTE
|
---|
528 | static QPalette qt_naturalWidgetPalette( QWidget* w ) {
|
---|
529 | QPalette naturalpalette = QApplication::palette( w );
|
---|
530 | if ( !w->isTopLevel() && naturalpalette.isCopyOf( QApplication::palette() ) )
|
---|
531 | naturalpalette = w->parentWidget()->palette();
|
---|
532 | return naturalpalette;
|
---|
533 | }
|
---|
534 | #endif
|
---|
535 |
|
---|
536 | QSize qt_naturalWidgetSize( QWidget *w ) {
|
---|
537 | #ifndef Q_OS_TEMP
|
---|
538 | QSize s = w->sizeHint();
|
---|
539 | QSizePolicy::ExpandData exp;
|
---|
540 | #ifndef QT_NO_LAYOUT
|
---|
541 | if ( w->layout() ) {
|
---|
542 | if ( w->layout()->hasHeightForWidth() )
|
---|
543 | s.setHeight( w->layout()->totalHeightForWidth( s.width() ) );
|
---|
544 | exp = w->layout()->expanding();
|
---|
545 | } else
|
---|
546 | #endif
|
---|
547 | {
|
---|
548 | if ( w->sizePolicy().hasHeightForWidth() )
|
---|
549 | s.setHeight( w->heightForWidth( s.width() ) );
|
---|
550 | exp = w->sizePolicy().expanding();
|
---|
551 | }
|
---|
552 | if ( exp & QSizePolicy::Horizontally )
|
---|
553 | s.setWidth( QMAX( s.width(), 200 ) );
|
---|
554 | if ( exp & QSizePolicy::Vertically )
|
---|
555 | s.setHeight( QMAX( s.height(), 150 ) );
|
---|
556 | #if defined(Q_WS_X11)
|
---|
557 | QRect screen = QApplication::desktop()->screenGeometry( w->x11Screen() );
|
---|
558 | #else // all others
|
---|
559 | QRect screen = QApplication::desktop()->screenGeometry( w->pos() );
|
---|
560 | #endif
|
---|
561 | s.setWidth( QMIN( s.width(), screen.width()*2/3 ) );
|
---|
562 | s.setHeight( QMIN( s.height(), screen.height()*2/3 ) );
|
---|
563 | return s;
|
---|
564 | }
|
---|
565 |
|
---|
566 | /*****************************************************************************
|
---|
567 | QWidget member functions
|
---|
568 | *****************************************************************************/
|
---|
569 |
|
---|
570 | /*
|
---|
571 | Widget state flags:
|
---|
572 | \list
|
---|
573 | \i WState_Created The widget has a valid winId().
|
---|
574 | \i WState_Disabled The widget does not receive any mouse or keyboard
|
---|
575 | events.
|
---|
576 | \i WState_ForceDisabled The widget is explicitly disabled, i.e. it
|
---|
577 | will remain disabled even when all its ancestors are set to the enabled
|
---|
578 | state. This implies WState_Disabled.
|
---|
579 | \i WState_Visible The widget is currently visible.
|
---|
580 | \i WState_ForceHide The widget is explicitly hidden, i.e. it won't
|
---|
581 | become visible unless you call show() on it. WState_ForceHide
|
---|
582 | implies !WState_Visible.
|
---|
583 | \i WState_OwnCursor A cursor has been set for this widget.
|
---|
584 | \i WState_MouseTracking Mouse tracking is enabled.
|
---|
585 | \i WState_CompressKeys Compress keyboard events.
|
---|
586 | \i WState_BlockUpdates Repaints and updates are disabled.
|
---|
587 | \i WState_InPaintEvent Currently processing a paint event.
|
---|
588 | \i WState_Reparented The widget has been reparented.
|
---|
589 | \i WState_ConfigPending A configuration (resize/move) event is pending.
|
---|
590 | \i WState_Resized The widget has been resized.
|
---|
591 | \i WState_AutoMask The widget has an automatic mask, see setAutoMask().
|
---|
592 | \i WState_Polished The widget has been "polished" (i.e. late
|
---|
593 | initialization) by a QStyle.
|
---|
594 | \i WState_DND The widget supports drag and drop, see setAcceptDrops().
|
---|
595 | \i WState_Exposed the widget was finally exposed (X11 only,
|
---|
596 | helps avoid paint event doubling).
|
---|
597 | \i WState_HasMouse The widget is under the mouse cursor.
|
---|
598 | \endlist
|
---|
599 | */
|
---|
600 |
|
---|
601 | /*! \enum Qt::WFlags
|
---|
602 | \internal */
|
---|
603 | /*! \enum Qt::WState
|
---|
604 | \internal */
|
---|
605 |
|
---|
606 | /*!
|
---|
607 | \enum Qt::WidgetFlags
|
---|
608 |
|
---|
609 | \keyword widget flag
|
---|
610 |
|
---|
611 | This enum type is used to specify various window-system properties
|
---|
612 | for the widget. They are fairly unusual but necessary in a few
|
---|
613 | cases. Some of these flags depend on whether the underlying window
|
---|
614 | manager supports them. (See the \link toplevel-example.html
|
---|
615 | toplevel example\endlink for an explanation and example of their
|
---|
616 | use.)
|
---|
617 |
|
---|
618 | The main types are
|
---|
619 |
|
---|
620 | \value WType_TopLevel indicates that this widget is a top-level
|
---|
621 | widget, usually with a window-system frame and so on.
|
---|
622 |
|
---|
623 | \value WType_Dialog indicates that this widget is a top-level
|
---|
624 | window that should be decorated as a dialog (i.e. typically no
|
---|
625 | maximize or minimize buttons in the title bar). If you want to use
|
---|
626 | it as a modal dialog it should be launched from another window, or
|
---|
627 | have a parent and this flag should be combined with \c WShowModal.
|
---|
628 | If you make it modal, the dialog will prevent other top-level
|
---|
629 | windows in the application from getting any input. \c WType_Dialog
|
---|
630 | implies \c WType_TopLevel. We refer to a top-level window that has
|
---|
631 | a parent as a \e secondary window. (See also \c WGroupLeader.)
|
---|
632 |
|
---|
633 | \value WType_Popup indicates that this widget is a popup
|
---|
634 | top-level window, i.e. that it is modal, but has a window system
|
---|
635 | frame appropriate for popup menus. \c WType_Popup implies
|
---|
636 | WType_TopLevel.
|
---|
637 |
|
---|
638 | \value WType_Desktop indicates that this widget is the desktop.
|
---|
639 | See also \c WPaintDesktop below. \c WType_Desktop implies \c
|
---|
640 | WType_TopLevel.
|
---|
641 |
|
---|
642 | There are also a number of flags which you can use to customize
|
---|
643 | the appearance of top-level windows. These have no effect on other
|
---|
644 | windows:
|
---|
645 |
|
---|
646 | \value WStyle_Customize indicates that the \c WStyle_* flags
|
---|
647 | should be used to build the window instead of the default flags.
|
---|
648 |
|
---|
649 | \value WStyle_NormalBorder gives the window a normal border.
|
---|
650 | This cannot be combined with \c WStyle_DialogBorder or \c
|
---|
651 | WStyle_NoBorder.
|
---|
652 |
|
---|
653 | \value WStyle_DialogBorder gives the window a thin dialog border.
|
---|
654 | This cannot be combined with \c WStyle_NormalBorder or \c
|
---|
655 | WStyle_NoBorder.
|
---|
656 |
|
---|
657 | \value WStyle_NoBorder produces a borderless window. Note that
|
---|
658 | the user cannot move or resize a borderless window via the window
|
---|
659 | system. This cannot be combined with \c WStyle_NormalBorder or \c
|
---|
660 | WStyle_DialogBorder. On Windows, the flag works fine. On X11, the
|
---|
661 | result of the flag is dependent on the window manager and its
|
---|
662 | ability to understand MOTIF and/or NETWM hints: most existing
|
---|
663 | modern window managers can handle this. With \c WX11BypassWM, you
|
---|
664 | can bypass the window manager completely. This results in a
|
---|
665 | borderless window that is not managed at all (i.e. no keyboard
|
---|
666 | input unless you call setActiveWindow() manually).
|
---|
667 |
|
---|
668 | \value WStyle_NoBorderEx this value is obsolete. It has the same
|
---|
669 | effect as using \c WStyle_NoBorder.
|
---|
670 |
|
---|
671 | \value WStyle_Title gives the window a title bar.
|
---|
672 |
|
---|
673 | \value WStyle_SysMenu adds a window system menu.
|
---|
674 |
|
---|
675 | \value WStyle_Minimize adds a minimize button. Note that on
|
---|
676 | Windows this has to be combined with \c WStyle_SysMenu for it to
|
---|
677 | work.
|
---|
678 |
|
---|
679 | \value WStyle_Maximize adds a maximize button. Note that on
|
---|
680 | Windows this has to be combined with \c WStyle_SysMenu for it to work.
|
---|
681 |
|
---|
682 | \value WStyle_MinMax is equal to \c
|
---|
683 | WStyle_Minimize|WStyle_Maximize. Note that on Windows this has to
|
---|
684 | be combined with \c WStyle_SysMenu to work.
|
---|
685 |
|
---|
686 | \value WStyle_ContextHelp adds a context help button to dialogs.
|
---|
687 |
|
---|
688 | \value WStyle_Tool makes the window a tool window. A tool window
|
---|
689 | is often a small window with a smaller than usual title bar and
|
---|
690 | decoration, typically used for collections of tool buttons. It
|
---|
691 | there is a parent, the tool window will always be kept on top of
|
---|
692 | it. If there isn't a parent, you may consider passing \c
|
---|
693 | WStyle_StaysOnTop as well. If the window system supports it, a
|
---|
694 | tool window can be decorated with a somewhat lighter frame. It can
|
---|
695 | also be combined with \c WStyle_NoBorder.
|
---|
696 |
|
---|
697 | \value WStyle_StaysOnTop informs the window system that the
|
---|
698 | window should stay on top of all other windows. Note that on some
|
---|
699 | window managers on X11 you also have to pass \c WX11BypassWM for
|
---|
700 | this flag to work correctly.
|
---|
701 |
|
---|
702 | \value WStyle_Dialog indicates that the window is a logical
|
---|
703 | subwindow of its parent (i.e. a dialog). The window will not get
|
---|
704 | its own taskbar entry and will be kept on top of its parent by the
|
---|
705 | window system. Usually it will also be minimized when the parent
|
---|
706 | is minimized. If not customized, the window is decorated with a
|
---|
707 | slightly simpler title bar. This is the flag QDialog uses.
|
---|
708 |
|
---|
709 | \value WStyle_Splash indicates that the window is a splash screen.
|
---|
710 | On X11, we try to follow NETWM standard for a splash screen window if the
|
---|
711 | window manager supports is otherwise it is equivalent to \c WX11BypassWM. On
|
---|
712 | other platforms, it is equivalent to \c WStyle_NoBorder \c | \c WMacNoSheet \c |
|
---|
713 | \c WStyle_Tool \c | \c WWinOwnDC
|
---|
714 |
|
---|
715 | Modifier flags:
|
---|
716 |
|
---|
717 | \value WDestructiveClose makes Qt delete this widget when the
|
---|
718 | widget has accepted closeEvent(), or when the widget tried to
|
---|
719 | ignore closeEvent() but could not.
|
---|
720 |
|
---|
721 | \value WPaintDesktop gives this widget paint events for the
|
---|
722 | desktop.
|
---|
723 |
|
---|
724 | \value WPaintUnclipped makes all painters operating on this
|
---|
725 | widget unclipped. Children of this widget or other widgets in
|
---|
726 | front of it do not clip the area the painter can paint on.
|
---|
727 |
|
---|
728 | \value WPaintClever indicates that Qt should \e not try to
|
---|
729 | optimize repainting for the widget, but instead pass on window
|
---|
730 | system repaint events directly. (This tends to produce more events
|
---|
731 | and smaller repaint regions.)
|
---|
732 |
|
---|
733 | \value WMouseNoMask indicates that even if the widget has a mask,
|
---|
734 | it wants mouse events for its entire rectangle.
|
---|
735 |
|
---|
736 | \value WStaticContents indicates that the widget contents are
|
---|
737 | north-west aligned and static. On resize, such a widget will
|
---|
738 | receive paint events only for the newly visible part of itself.
|
---|
739 |
|
---|
740 | \value WNoAutoErase indicates that the widget paints all its
|
---|
741 | pixels. Updating, resizing, scrolling and focus changes should
|
---|
742 | therefore not erase the widget. This allows smart-repainting to
|
---|
743 | avoid flicker.
|
---|
744 |
|
---|
745 | \value WResizeNoErase \obsolete Use WNoAutoErase instead.
|
---|
746 | \value WRepaintNoErase \obsolete Use WNoAutoErase instead.
|
---|
747 | \value WGroupLeader makes this window a group leader. A group
|
---|
748 | leader should \e not have a parent (i.e. it should be a top-level
|
---|
749 | window). Any decendant windows (direct or indirect) of a group
|
---|
750 | leader are in its group; other windows are not. If you show a
|
---|
751 | secondary window from the group (i.e. show a window whose top-most
|
---|
752 | parent is a group leader), that window will be modal with respect
|
---|
753 | to the other windows in the group, but modeless with respect to
|
---|
754 | windows in other groups.
|
---|
755 |
|
---|
756 | Miscellaneous flags
|
---|
757 |
|
---|
758 | \value WShowModal see WType_Dialog
|
---|
759 |
|
---|
760 | Internal flags.
|
---|
761 |
|
---|
762 | \value WNoMousePropagation
|
---|
763 | \value WStaticContents
|
---|
764 | \value WStyle_Reserved
|
---|
765 | \value WSubWindow
|
---|
766 | \value WType_Modal
|
---|
767 | \value WWinOwnDC
|
---|
768 | \value WX11BypassWM
|
---|
769 | \value WMacNoSheet
|
---|
770 | \value WMacDrawer
|
---|
771 | \value WStyle_Mask
|
---|
772 | \value WType_Mask
|
---|
773 |
|
---|
774 | */
|
---|
775 |
|
---|
776 | /*!
|
---|
777 | \enum Qt::WidgetState
|
---|
778 |
|
---|
779 | Internal flags.
|
---|
780 |
|
---|
781 | \value WState_Created
|
---|
782 | \value WState_Disabled
|
---|
783 | \value WState_Visible
|
---|
784 | \value WState_ForceHide
|
---|
785 | \value WState_OwnCursor
|
---|
786 | \value WState_MouseTracking
|
---|
787 | \value WState_CompressKeys
|
---|
788 | \value WState_BlockUpdates
|
---|
789 | \value WState_InPaintEvent
|
---|
790 | \value WState_Reparented
|
---|
791 | \value WState_ConfigPending
|
---|
792 | \value WState_Resized
|
---|
793 | \value WState_AutoMask
|
---|
794 | \value WState_Polished
|
---|
795 | \value WState_DND
|
---|
796 | \value WState_Reserved0 \e internal
|
---|
797 | \value WState_CreatedHidden
|
---|
798 | \value WState_Maximized
|
---|
799 | \value WState_Minimized
|
---|
800 | \value WState_ForceDisabled
|
---|
801 | \value WState_Exposed
|
---|
802 | \value WState_HasMouse
|
---|
803 | \value WState_CreatedHidden
|
---|
804 | \value WState_OwnSizePolicy
|
---|
805 | \value WState_FullScreen
|
---|
806 | */
|
---|
807 |
|
---|
808 |
|
---|
809 | /*!
|
---|
810 | \enum Qt::WindowState
|
---|
811 |
|
---|
812 | \keyword window state
|
---|
813 |
|
---|
814 | This enum type is used to specify the current state of a top-level
|
---|
815 | window.
|
---|
816 |
|
---|
817 | The states are
|
---|
818 |
|
---|
819 | \value WindowNoState The window has no state set (in normal state).
|
---|
820 | \value WindowMinimized The window is minimized (i.e. iconified).
|
---|
821 | \value WindowMaximized The window is maximized with a frame around it.
|
---|
822 | \value WindowFullScreen The window fills the entire screen without any frame around it.
|
---|
823 | \value WindowActive The window is the active window, i.e. it has keyboard focus.
|
---|
824 |
|
---|
825 | */
|
---|
826 |
|
---|
827 | /*!
|
---|
828 | Constructs a widget which is a child of \a parent, with the name
|
---|
829 | \a name and widget flags set to \a f.
|
---|
830 |
|
---|
831 | If \a parent is 0, the new widget becomes a top-level window. If
|
---|
832 | \a parent is another widget, this widget becomes a child window
|
---|
833 | inside \a parent. The new widget is deleted when its \a parent is
|
---|
834 | deleted.
|
---|
835 |
|
---|
836 | The \a name is sent to the QObject constructor.
|
---|
837 |
|
---|
838 | The widget flags argument, \a f, is normally 0, but it can be set
|
---|
839 | to customize the window frame of a top-level widget (i.e. \a
|
---|
840 | parent must be 0). To customize the frame, set the \c
|
---|
841 | WStyle_Customize flag OR'ed with any of the \l Qt::WidgetFlags.
|
---|
842 |
|
---|
843 | If you add a child widget to an already visible widget you must
|
---|
844 | explicitly show the child to make it visible.
|
---|
845 |
|
---|
846 | Note that the X11 version of Qt may not be able to deliver all
|
---|
847 | combinations of style flags on all systems. This is because on
|
---|
848 | X11, Qt can only ask the window manager, and the window manager
|
---|
849 | can override the application's settings. On Windows, Qt can set
|
---|
850 | whatever flags you want.
|
---|
851 |
|
---|
852 | Example:
|
---|
853 | \code
|
---|
854 | QLabel *splashScreen = new QLabel( 0, "mySplashScreen",
|
---|
855 | WStyle_Customize | WStyle_Splash );
|
---|
856 | \endcode
|
---|
857 | */
|
---|
858 |
|
---|
859 | QWidget::QWidget( QWidget *parent, const char *name, WFlags f )
|
---|
860 | : QObject( parent, name ), QPaintDevice( QInternal::Widget )
|
---|
861 | {
|
---|
862 | #if defined(QT_CHECK_STATE) && !defined(Q_WS_WIN)
|
---|
863 | if ( qApp->type() == QApplication::Tty ) {
|
---|
864 | qWarning( "QWidget: Cannot create a QWidget when no GUI "
|
---|
865 | "is being used" );
|
---|
866 | }
|
---|
867 | #endif
|
---|
868 |
|
---|
869 | fstrut_dirty = 1;
|
---|
870 |
|
---|
871 | isWidget = TRUE; // is a widget
|
---|
872 | winid = 0; // default attributes
|
---|
873 | widget_state = 0;
|
---|
874 | widget_flags = f;
|
---|
875 | focus_policy = 0;
|
---|
876 | own_font = 0;
|
---|
877 | own_palette = 0;
|
---|
878 | sizehint_forced = 0;
|
---|
879 | is_closing = 0;
|
---|
880 | in_show = 0;
|
---|
881 | in_show_maximized = 0;
|
---|
882 | im_enabled = FALSE;
|
---|
883 | #ifndef QT_NO_LAYOUT
|
---|
884 | lay_out = 0;
|
---|
885 | #endif
|
---|
886 | extra = 0; // no extra widget info
|
---|
887 | #ifndef QT_NO_PALETTE
|
---|
888 | bg_col = pal.active().background(); // default background color
|
---|
889 | #endif
|
---|
890 | create(); // platform-dependent init
|
---|
891 | #ifndef QT_NO_PALETTE
|
---|
892 | pal = isTopLevel() ? QApplication::palette() : parentWidget()->palette();
|
---|
893 | #endif
|
---|
894 | if ( ! isTopLevel() )
|
---|
895 | fnt = parentWidget()->font();
|
---|
896 | #if defined(Q_WS_X11)
|
---|
897 | fnt.x11SetScreen( x11Screen() );
|
---|
898 | #endif // Q_WS_X11
|
---|
899 |
|
---|
900 | if ( !isDesktop() )
|
---|
901 | setBackgroundFromMode(); //### parts of this are done in create but not all (see reparent(...) )
|
---|
902 | // make sure move/resize events are sent to all widgets
|
---|
903 | QApplication::postEvent( this, new QMoveEvent( crect.topLeft(),
|
---|
904 | crect.topLeft() ) );
|
---|
905 | QApplication::postEvent( this, new QResizeEvent(crect.size(),
|
---|
906 | crect.size()) );
|
---|
907 | if ( isTopLevel() ) {
|
---|
908 | setWState( WState_ForceHide | WState_CreatedHidden );
|
---|
909 | QFocusData *fd = focusData( TRUE );
|
---|
910 | if ( fd->focusWidgets.findRef(this) < 0 )
|
---|
911 | fd->focusWidgets.append( this );
|
---|
912 | } else {
|
---|
913 | // propagate enabled state
|
---|
914 | if ( !parentWidget()->isEnabled() )
|
---|
915 | setWState( WState_Disabled );
|
---|
916 | // new widgets do not show up in already visible parents
|
---|
917 | if ( parentWidget()->isVisible() )
|
---|
918 | setWState( WState_ForceHide | WState_CreatedHidden );
|
---|
919 | }
|
---|
920 | if ( ++instanceCounter > maxInstances )
|
---|
921 | maxInstances = instanceCounter;
|
---|
922 | }
|
---|
923 |
|
---|
924 | /*!
|
---|
925 | Destroys the widget.
|
---|
926 |
|
---|
927 | All this widget's children are deleted first. The application
|
---|
928 | exits if this widget is the main widget.
|
---|
929 | */
|
---|
930 |
|
---|
931 | QWidget::~QWidget()
|
---|
932 | {
|
---|
933 | #if defined (QT_CHECK_STATE)
|
---|
934 | if ( paintingActive() )
|
---|
935 | qWarning( "%s (%s): deleted while being painted", className(), name() );
|
---|
936 | #endif
|
---|
937 |
|
---|
938 | // Remove myself and all children from the can-take-focus list
|
---|
939 | QFocusData *f = focusData( FALSE );
|
---|
940 | if ( f ) {
|
---|
941 | QPtrListIterator<QWidget> it(f->focusWidgets);
|
---|
942 | QWidget *w;
|
---|
943 | while ( (w = it.current()) ) {
|
---|
944 | ++it;
|
---|
945 | QWidget * p = w;
|
---|
946 | while( p && p != this )
|
---|
947 | p = p->parentWidget();
|
---|
948 | if ( p ) // my descendant
|
---|
949 | f->focusWidgets.removeRef( w );
|
---|
950 | }
|
---|
951 | }
|
---|
952 | --instanceCounter;
|
---|
953 |
|
---|
954 | if ( QApplication::main_widget == this ) { // reset main widget
|
---|
955 | QApplication::main_widget = 0;
|
---|
956 | if (qApp)
|
---|
957 | qApp->quit();
|
---|
958 | }
|
---|
959 |
|
---|
960 | if ( hasFocus() )
|
---|
961 | clearFocus();
|
---|
962 |
|
---|
963 | if ( isTopLevel() && isShown() && winId() )
|
---|
964 | hide();
|
---|
965 |
|
---|
966 | // A parent widget must destroy all its children before destroying itself
|
---|
967 | if ( childObjects ) { // delete children objects
|
---|
968 | QObjectListIt it(*childObjects);
|
---|
969 | QObject *obj;
|
---|
970 | while ( (obj=it.current()) ) {
|
---|
971 | ++it;
|
---|
972 | obj->parentObj = 0;
|
---|
973 | childObjects->removeRef( obj );
|
---|
974 | delete obj;
|
---|
975 | }
|
---|
976 | delete childObjects;
|
---|
977 | childObjects = 0;
|
---|
978 | }
|
---|
979 |
|
---|
980 | QApplication::removePostedEvents( this );
|
---|
981 | if ( extra )
|
---|
982 | deleteExtra();
|
---|
983 |
|
---|
984 | destroy(); // platform-dependent cleanup
|
---|
985 | }
|
---|
986 |
|
---|
987 | int QWidget::instanceCounter = 0; // Current number of widget instances
|
---|
988 | int QWidget::maxInstances = 0; // Maximum number of widget instances
|
---|
989 |
|
---|
990 | /*!
|
---|
991 | \internal
|
---|
992 | Creates the global widget mapper.
|
---|
993 | The widget mapper converts window handles to widget pointers.
|
---|
994 | \sa destroyMapper()
|
---|
995 | */
|
---|
996 |
|
---|
997 | void QWidget::createMapper()
|
---|
998 | {
|
---|
999 | mapper = new QWidgetMapper;
|
---|
1000 | Q_CHECK_PTR( mapper );
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | /*!
|
---|
1004 | \internal
|
---|
1005 | Destroys the global widget mapper.
|
---|
1006 | \sa createMapper()
|
---|
1007 | */
|
---|
1008 |
|
---|
1009 | void QWidget::destroyMapper()
|
---|
1010 | {
|
---|
1011 | if ( !mapper ) // already gone
|
---|
1012 | return;
|
---|
1013 | QWidgetIntDictIt it( *((QWidgetIntDict*)mapper) );
|
---|
1014 | QWidgetMapper * myMapper = mapper;
|
---|
1015 | mapper = 0;
|
---|
1016 | register QWidget *w;
|
---|
1017 | while ( (w=it.current()) ) { // remove parents widgets
|
---|
1018 | ++it;
|
---|
1019 | if ( !w->parentObj ) // widget is a parent
|
---|
1020 | w->destroy( TRUE, TRUE );
|
---|
1021 | }
|
---|
1022 | delete myMapper;
|
---|
1023 | }
|
---|
1024 |
|
---|
1025 |
|
---|
1026 | static QWidgetList *wListInternal( QWidgetMapper *mapper, bool onlyTopLevel )
|
---|
1027 | {
|
---|
1028 | QWidgetList *list = new QWidgetList;
|
---|
1029 | Q_CHECK_PTR( list );
|
---|
1030 | if ( mapper ) {
|
---|
1031 | QWidget *w;
|
---|
1032 | QWidgetIntDictIt it( *((QWidgetIntDict*)mapper) );
|
---|
1033 | while ( (w=it.current()) ) {
|
---|
1034 | ++it;
|
---|
1035 | if ( !onlyTopLevel || w->isTopLevel() )
|
---|
1036 | list->append( w );
|
---|
1037 | }
|
---|
1038 | }
|
---|
1039 | return list;
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | /*!
|
---|
1043 | \internal
|
---|
1044 | Returns a list of all widgets.
|
---|
1045 | \sa tlwList(), QApplication::allWidgets()
|
---|
1046 | */
|
---|
1047 |
|
---|
1048 | QWidgetList *QWidget::wList()
|
---|
1049 | {
|
---|
1050 | return wListInternal( mapper, FALSE );
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | /*!
|
---|
1054 | \internal
|
---|
1055 | Returns a list of all top level widgets.
|
---|
1056 | \sa wList(), QApplication::topLevelWidgets()
|
---|
1057 | */
|
---|
1058 |
|
---|
1059 | QWidgetList *QWidget::tlwList()
|
---|
1060 | {
|
---|
1061 | return wListInternal( mapper, TRUE );
|
---|
1062 | }
|
---|
1063 |
|
---|
1064 |
|
---|
1065 | void QWidget::setWinId( WId id ) // set widget identifier
|
---|
1066 | {
|
---|
1067 | if ( !mapper ) // mapper destroyed
|
---|
1068 | return;
|
---|
1069 | if ( winid )
|
---|
1070 | mapper->remove( winid );
|
---|
1071 | winid = id;
|
---|
1072 | #if defined(Q_WS_X11)
|
---|
1073 | hd = id; // X11: hd == ident
|
---|
1074 | #endif
|
---|
1075 | if ( id )
|
---|
1076 | mapper->insert( this );
|
---|
1077 | }
|
---|
1078 |
|
---|
1079 |
|
---|
1080 | /*!
|
---|
1081 | \internal
|
---|
1082 | Returns a pointer to the block of extra widget data.
|
---|
1083 | */
|
---|
1084 |
|
---|
1085 | QWExtra *QWidget::extraData()
|
---|
1086 | {
|
---|
1087 | return extra;
|
---|
1088 | }
|
---|
1089 |
|
---|
1090 |
|
---|
1091 | /*!
|
---|
1092 | \internal
|
---|
1093 | Returns a pointer to the block of extra top level widget data.
|
---|
1094 |
|
---|
1095 | This data is guaranteed to exist for top level widgets.
|
---|
1096 | */
|
---|
1097 |
|
---|
1098 | QTLWExtra *QWidget::topData()
|
---|
1099 | {
|
---|
1100 | createTLExtra();
|
---|
1101 | return extra->topextra;
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 |
|
---|
1105 | void QWidget::createTLExtra()
|
---|
1106 | {
|
---|
1107 | if ( !extra )
|
---|
1108 | createExtra();
|
---|
1109 | if ( !extra->topextra ) {
|
---|
1110 | QTLWExtra* x = extra->topextra = new QTLWExtra;
|
---|
1111 | #if defined( Q_WS_WIN ) || defined( Q_WS_MAC )
|
---|
1112 | x->opacity = 255;
|
---|
1113 | #endif
|
---|
1114 | #ifndef QT_NO_WIDGET_TOPEXTRA
|
---|
1115 | x->icon = 0;
|
---|
1116 | #endif
|
---|
1117 | x->focusData = 0;
|
---|
1118 | x->fleft = x->fright = x->ftop = x->fbottom = 0;
|
---|
1119 | x->incw = x->inch = 0;
|
---|
1120 | x->basew = x->baseh = 0;
|
---|
1121 | x->normalGeometry = QRect(0,0,-1,-1);
|
---|
1122 | #if defined(Q_WS_X11)
|
---|
1123 | x->embedded = 0;
|
---|
1124 | x->parentWinId = 0;
|
---|
1125 | x->spont_unmapped = 0;
|
---|
1126 | x->dnd = 0;
|
---|
1127 | x->uspos = 0;
|
---|
1128 | x->ussize = 0;
|
---|
1129 | #endif
|
---|
1130 | x->savedFlags = 0;
|
---|
1131 | #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
|
---|
1132 | x->decor_allocated_region = QRegion();
|
---|
1133 | x->qwsManager = 0;
|
---|
1134 | #endif
|
---|
1135 | createTLSysExtra();
|
---|
1136 | }
|
---|
1137 | }
|
---|
1138 |
|
---|
1139 | /*!
|
---|
1140 | \internal
|
---|
1141 | Creates the widget extra data.
|
---|
1142 | */
|
---|
1143 |
|
---|
1144 | void QWidget::createExtra()
|
---|
1145 | {
|
---|
1146 | if ( !extra ) { // if not exists
|
---|
1147 | extra = new QWExtra;
|
---|
1148 | Q_CHECK_PTR( extra );
|
---|
1149 | extra->minw = extra->minh = 0;
|
---|
1150 | extra->maxw = extra->maxh = QWIDGETSIZE_MAX;
|
---|
1151 | extra->bg_pix = 0;
|
---|
1152 | extra->focus_proxy = 0;
|
---|
1153 | #ifndef QT_NO_CURSOR
|
---|
1154 | extra->curs = 0;
|
---|
1155 | #endif
|
---|
1156 | extra->topextra = 0;
|
---|
1157 | extra->bg_mode = PaletteBackground;
|
---|
1158 | extra->bg_mode_visual = PaletteBackground;
|
---|
1159 | extra->bg_origin = WidgetOrigin;
|
---|
1160 | #ifndef QT_NO_STYLE
|
---|
1161 | extra->style = 0;
|
---|
1162 | #endif
|
---|
1163 | extra->size_policy = QSizePolicy( QSizePolicy::Preferred,
|
---|
1164 | QSizePolicy::Preferred );
|
---|
1165 | createSysExtra();
|
---|
1166 | }
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 |
|
---|
1170 | /*!
|
---|
1171 | \internal
|
---|
1172 | Deletes the widget extra data.
|
---|
1173 | */
|
---|
1174 |
|
---|
1175 | void QWidget::deleteExtra()
|
---|
1176 | {
|
---|
1177 | if ( extra ) { // if exists
|
---|
1178 | delete extra->bg_pix;
|
---|
1179 | #ifndef QT_NO_CURSOR
|
---|
1180 | delete extra->curs;
|
---|
1181 | #endif
|
---|
1182 | deleteSysExtra();
|
---|
1183 | if ( extra->topextra ) {
|
---|
1184 | deleteTLSysExtra();
|
---|
1185 | #ifndef QT_NO_WIDGET_TOPEXTRA
|
---|
1186 | delete extra->topextra->icon;
|
---|
1187 | #endif
|
---|
1188 | delete extra->topextra->focusData;
|
---|
1189 | #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
|
---|
1190 | delete extra->topextra->qwsManager;
|
---|
1191 | #endif
|
---|
1192 | delete extra->topextra;
|
---|
1193 | }
|
---|
1194 | delete extra;
|
---|
1195 | // extra->xic destroyed in QWidget::destroy()
|
---|
1196 | extra = 0;
|
---|
1197 | }
|
---|
1198 | }
|
---|
1199 |
|
---|
1200 |
|
---|
1201 | /*!
|
---|
1202 | \internal
|
---|
1203 | This function is called when a widget is hidden or destroyed.
|
---|
1204 | It resets some application global pointers that should only refer active,
|
---|
1205 | visible widgets.
|
---|
1206 | */
|
---|
1207 |
|
---|
1208 | void QWidget::deactivateWidgetCleanup()
|
---|
1209 | {
|
---|
1210 | // If this was the active application window, reset it
|
---|
1211 | if ( this == QApplication::active_window )
|
---|
1212 | qApp->setActiveWindow( 0 );
|
---|
1213 | // If the is the active mouse press widget, reset it
|
---|
1214 | #ifdef Q_WS_MAC
|
---|
1215 | extern QGuardedPtr<QWidget> qt_button_down;
|
---|
1216 | #else
|
---|
1217 | extern QWidget *qt_button_down;
|
---|
1218 | #endif
|
---|
1219 | if ( this == qt_button_down )
|
---|
1220 | qt_button_down = 0;
|
---|
1221 | }
|
---|
1222 |
|
---|
1223 |
|
---|
1224 | /*!
|
---|
1225 | Returns a pointer to the widget with window identifer/handle \a
|
---|
1226 | id.
|
---|
1227 |
|
---|
1228 | The window identifier type depends on the underlying window
|
---|
1229 | system, see \c qwindowdefs.h for the actual definition. If there
|
---|
1230 | is no widget with this identifier, 0 is returned.
|
---|
1231 | */
|
---|
1232 |
|
---|
1233 | QWidget *QWidget::find( WId id )
|
---|
1234 | {
|
---|
1235 | return mapper ? mapper->find( id ) : 0;
|
---|
1236 | }
|
---|
1237 |
|
---|
1238 | /*!
|
---|
1239 | \fn QWidgetMapper *QWidget::wmapper()
|
---|
1240 | \internal
|
---|
1241 | Returns a pointer to the widget mapper.
|
---|
1242 |
|
---|
1243 | The widget mapper is an internal dictionary that is used to map from
|
---|
1244 | window identifiers/handles to widget pointers.
|
---|
1245 | \sa find(), id()
|
---|
1246 | */
|
---|
1247 |
|
---|
1248 | /*!
|
---|
1249 | \fn WFlags QWidget::getWFlags() const
|
---|
1250 |
|
---|
1251 | Returns the widget flags for this this widget.
|
---|
1252 |
|
---|
1253 | Widget flags are a combination of \l{Qt::WidgetFlags}.
|
---|
1254 |
|
---|
1255 | \sa testWFlags(), setWFlags(), clearWFlags()
|
---|
1256 | */
|
---|
1257 |
|
---|
1258 | /*!
|
---|
1259 | \fn void QWidget::setWFlags( WFlags f )
|
---|
1260 |
|
---|
1261 | Sets the widget flags \a f.
|
---|
1262 |
|
---|
1263 | Widget flags are a combination of \l{Qt::WidgetFlags}.
|
---|
1264 |
|
---|
1265 | \sa testWFlags(), getWFlags(), clearWFlags()
|
---|
1266 | */
|
---|
1267 |
|
---|
1268 | /*!
|
---|
1269 | \fn void QWidget::clearWFlags( WFlags f )
|
---|
1270 |
|
---|
1271 | Clears the widget flags \a f.
|
---|
1272 |
|
---|
1273 | Widget flags are a combination of \l{Qt::WidgetFlags}.
|
---|
1274 |
|
---|
1275 | \sa testWFlags(), getWFlags(), setWFlags()
|
---|
1276 | */
|
---|
1277 |
|
---|
1278 |
|
---|
1279 |
|
---|
1280 | /*!
|
---|
1281 | \fn WId QWidget::winId() const
|
---|
1282 |
|
---|
1283 | Returns the window system identifier of the widget.
|
---|
1284 |
|
---|
1285 | Portable in principle, but if you use it you are probably about to
|
---|
1286 | do something non-portable. Be careful.
|
---|
1287 |
|
---|
1288 | \sa find()
|
---|
1289 | */
|
---|
1290 |
|
---|
1291 | #ifndef QT_NO_STYLE
|
---|
1292 | /*!
|
---|
1293 | Returns the GUI style for this widget
|
---|
1294 |
|
---|
1295 | \sa QWidget::setStyle(), QApplication::setStyle(), QApplication::style()
|
---|
1296 | */
|
---|
1297 |
|
---|
1298 | QStyle& QWidget::style() const
|
---|
1299 | {
|
---|
1300 | if ( extra && extra->style )
|
---|
1301 | return *extra->style;
|
---|
1302 | QStyle &ret = qApp->style();
|
---|
1303 | return ret;
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | /*!
|
---|
1307 | Sets the widget's GUI style to \a style. Ownership of the style
|
---|
1308 | object is not transferred.
|
---|
1309 |
|
---|
1310 | If no style is set, the widget uses the application's style,
|
---|
1311 | QApplication::style() instead.
|
---|
1312 |
|
---|
1313 | Setting a widget's style has no effect on existing or future child
|
---|
1314 | widgets.
|
---|
1315 |
|
---|
1316 | \warning This function is particularly useful for demonstration
|
---|
1317 | purposes, where you want to show Qt's styling capabilities. Real
|
---|
1318 | applications should avoid it and use one consistent GUI style
|
---|
1319 | instead.
|
---|
1320 |
|
---|
1321 | \sa style(), QStyle, QApplication::style(), QApplication::setStyle()
|
---|
1322 | */
|
---|
1323 |
|
---|
1324 | void QWidget::setStyle( QStyle *style )
|
---|
1325 | {
|
---|
1326 | QStyle& old = QWidget::style();
|
---|
1327 | createExtra();
|
---|
1328 | extra->style = style;
|
---|
1329 | if ( !testWFlags(WType_Desktop) // (except desktop)
|
---|
1330 | && testWState(WState_Polished)) { // (and have been polished)
|
---|
1331 | old.unPolish( this );
|
---|
1332 | QWidget::style().polish( this );
|
---|
1333 | }
|
---|
1334 | styleChange( old );
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 | /*!
|
---|
1338 | \overload
|
---|
1339 |
|
---|
1340 | Sets the widget's GUI style to \a style using the QStyleFactory.
|
---|
1341 | */
|
---|
1342 | QStyle* QWidget::setStyle( const QString &style )
|
---|
1343 | {
|
---|
1344 | QStyle *s = QStyleFactory::create( style );
|
---|
1345 | setStyle( s );
|
---|
1346 | return s;
|
---|
1347 | }
|
---|
1348 |
|
---|
1349 | /*!
|
---|
1350 | This virtual function is called when the style of the widgets
|
---|
1351 | changes. \a oldStyle is the previous GUI style; you can get the
|
---|
1352 | new style from style().
|
---|
1353 |
|
---|
1354 | Reimplement this function if your widget needs to know when its
|
---|
1355 | GUI style changes. You will almost certainly need to update the
|
---|
1356 | widget using update().
|
---|
1357 |
|
---|
1358 | The default implementation updates the widget including its
|
---|
1359 | geometry.
|
---|
1360 |
|
---|
1361 | \sa QApplication::setStyle(), style(), update(), updateGeometry()
|
---|
1362 | */
|
---|
1363 |
|
---|
1364 | void QWidget::styleChange( QStyle& /* oldStyle */ )
|
---|
1365 | {
|
---|
1366 | update();
|
---|
1367 | updateGeometry();
|
---|
1368 | }
|
---|
1369 |
|
---|
1370 | #endif
|
---|
1371 |
|
---|
1372 | /*!
|
---|
1373 | \property QWidget::isTopLevel
|
---|
1374 | \brief whether the widget is a top-level widget
|
---|
1375 |
|
---|
1376 | A top-level widget is a widget which usually has a frame and a
|
---|
1377 | \link QWidget::caption caption (title)\endlink. \link
|
---|
1378 | QWidget::isPopup() Popup\endlink and \link QWidget::isDesktop()
|
---|
1379 | desktop\endlink widgets are also top-level widgets.
|
---|
1380 |
|
---|
1381 | A top-level widget can have a \link QWidget::parentWidget() parent
|
---|
1382 | widget\endlink. It will then be grouped with its parent and deleted
|
---|
1383 | when the parent is deleted, minimized when the parent is minimized
|
---|
1384 | etc. If supported by the window manager, it will also have a
|
---|
1385 | common taskbar entry with its parent.
|
---|
1386 |
|
---|
1387 | QDialog and QMainWindow widgets are by default top-level, even if
|
---|
1388 | a parent widget is specified in the constructor. This behavior is
|
---|
1389 | specified by the \c WType_TopLevel widget flag.
|
---|
1390 |
|
---|
1391 | \sa topLevelWidget(), isDialog(), isModal(), isPopup(), isDesktop(), parentWidget()
|
---|
1392 | */
|
---|
1393 |
|
---|
1394 | /*!
|
---|
1395 | \property QWidget::isDialog
|
---|
1396 | \brief whether the widget is a dialog widget
|
---|
1397 |
|
---|
1398 | A dialog widget is a secondary top-level widget, i.e. a top-level
|
---|
1399 | widget with a parent.
|
---|
1400 |
|
---|
1401 | \sa isTopLevel(), QDialog
|
---|
1402 | */
|
---|
1403 |
|
---|
1404 | /*!
|
---|
1405 | \property QWidget::isPopup
|
---|
1406 | \brief whether the widget is a popup widget
|
---|
1407 |
|
---|
1408 | A popup widget is created by specifying the widget flag \c
|
---|
1409 | WType_Popup to the widget constructor. A popup widget is also a
|
---|
1410 | top-level widget.
|
---|
1411 |
|
---|
1412 | \sa isTopLevel()
|
---|
1413 | */
|
---|
1414 |
|
---|
1415 | /*!
|
---|
1416 | \property QWidget::isDesktop
|
---|
1417 | \brief whether the widget is a desktop widget, i.e. represents the desktop
|
---|
1418 |
|
---|
1419 | A desktop widget is also a top-level widget.
|
---|
1420 |
|
---|
1421 | \sa isTopLevel(), QApplication::desktop()
|
---|
1422 | */
|
---|
1423 |
|
---|
1424 | /*!
|
---|
1425 | \property QWidget::isModal
|
---|
1426 | \brief whether the widget is a modal widget
|
---|
1427 |
|
---|
1428 | This property only makes sense for top-level widgets. A modal
|
---|
1429 | widget prevents widgets in all other top-level widgets from
|
---|
1430 | getting any input.
|
---|
1431 |
|
---|
1432 | \sa isTopLevel(), isDialog(), QDialog
|
---|
1433 | */
|
---|
1434 |
|
---|
1435 | /*!
|
---|
1436 | \property QWidget::underMouse
|
---|
1437 | \brief whether the widget is under the mouse cursor
|
---|
1438 |
|
---|
1439 | This value is not updated properly during drag and drop
|
---|
1440 | operations.
|
---|
1441 |
|
---|
1442 | \sa QEvent::Enter, QEvent::Leave
|
---|
1443 | */
|
---|
1444 |
|
---|
1445 | /*!
|
---|
1446 | \property QWidget::minimized
|
---|
1447 | \brief whether this widget is minimized (iconified)
|
---|
1448 |
|
---|
1449 | This property is only relevant for top-level widgets.
|
---|
1450 |
|
---|
1451 | \sa showMinimized(), visible, show(), hide(), showNormal(), maximized
|
---|
1452 | */
|
---|
1453 | bool QWidget::isMinimized() const
|
---|
1454 | { return testWState(WState_Minimized); }
|
---|
1455 |
|
---|
1456 | /*!
|
---|
1457 | Shows the widget minimized, as an icon.
|
---|
1458 |
|
---|
1459 | Calling this function only affects \link isTopLevel() top-level
|
---|
1460 | widgets\endlink.
|
---|
1461 |
|
---|
1462 | \sa showNormal(), showMaximized(), show(), hide(), isVisible(),
|
---|
1463 | isMinimized()
|
---|
1464 | */
|
---|
1465 | void QWidget::showMinimized()
|
---|
1466 | {
|
---|
1467 | if (isMinimized()) return;
|
---|
1468 |
|
---|
1469 | setWindowState((windowState() & ~WindowActive) | WindowMinimized);
|
---|
1470 | show();
|
---|
1471 | if (!isTopLevel())
|
---|
1472 | QApplication::sendPostedEvents(this, QEvent::ShowMinimized);
|
---|
1473 | }
|
---|
1474 |
|
---|
1475 | /*!
|
---|
1476 | \property QWidget::maximized
|
---|
1477 | \brief whether this widget is maximized
|
---|
1478 |
|
---|
1479 | This property is only relevant for top-level widgets.
|
---|
1480 |
|
---|
1481 | Note that due to limitations in some window-systems, this does not
|
---|
1482 | always report the expected results (e.g. if the user on X11
|
---|
1483 | maximizes the window via the window manager, Qt has no way of
|
---|
1484 | distinguishing this from any other resize). This is expected to
|
---|
1485 | improve as window manager protocols evolve.
|
---|
1486 |
|
---|
1487 | \sa windowState(), showMaximized(), visible, show(), hide(), showNormal(), minimized
|
---|
1488 | */
|
---|
1489 | bool QWidget::isMaximized() const
|
---|
1490 | { return testWState(WState_Maximized); }
|
---|
1491 |
|
---|
1492 |
|
---|
1493 |
|
---|
1494 | /*! Returns the current window state. The window state is a OR'ed
|
---|
1495 | combination of Qt::WindowState: \c WindowMinimized, \c
|
---|
1496 | WindowMaximized, \c WindowFullScreen and \c WindowActive.
|
---|
1497 |
|
---|
1498 | \sa Qt::WindowState setWindowState()
|
---|
1499 | */
|
---|
1500 | uint QWidget::windowState() const
|
---|
1501 | {
|
---|
1502 | uint state = 0;
|
---|
1503 | if (testWState(WState_Minimized))
|
---|
1504 | state |= WindowMinimized;
|
---|
1505 | if (testWState(WState_Maximized))
|
---|
1506 | state |= WindowMaximized;
|
---|
1507 | if (testWState(WState_FullScreen))
|
---|
1508 | state |= WindowFullScreen;
|
---|
1509 | if (isActiveWindow())
|
---|
1510 | state |= WindowActive;
|
---|
1511 | return state;
|
---|
1512 | }
|
---|
1513 |
|
---|
1514 | /*!
|
---|
1515 | \fn void QWidget::setWindowState(uint windowState)
|
---|
1516 |
|
---|
1517 | Sets the window state to \a windowState. The window state is a OR'ed
|
---|
1518 | combination of Qt::WindowState: \c WindowMinimized, \c
|
---|
1519 | WindowMaximized, \c WindowFullScreen and \c WindowActive.
|
---|
1520 |
|
---|
1521 | If the window is not visible (i.e. isVisible() returns FALSE), the
|
---|
1522 | window state will take effect when show() is called. For visible
|
---|
1523 | windows, the change is immediate. For example, to toggle between
|
---|
1524 | full-screen and mormal mode, use the following code:
|
---|
1525 |
|
---|
1526 | \code
|
---|
1527 | w->setWindowState(w->windowState() ^ WindowFullScreen);
|
---|
1528 | \endcode
|
---|
1529 |
|
---|
1530 | In order to restore and activate a minimized window (while
|
---|
1531 | preserving its maximized and/or full-screen state), use the following:
|
---|
1532 |
|
---|
1533 | \code
|
---|
1534 | w->setWindowState(w->windowState() & ~WindowMinimized | WindowActive);
|
---|
1535 | \endcode
|
---|
1536 |
|
---|
1537 | Note: On some window systems \c WindowActive is not immediate, and may be
|
---|
1538 | ignored in certain cases.
|
---|
1539 |
|
---|
1540 | \sa Qt::WindowState windowState()
|
---|
1541 | */
|
---|
1542 |
|
---|
1543 | /*!
|
---|
1544 | \property QWidget::fullScreen
|
---|
1545 | \brief whether the widget is full screen
|
---|
1546 |
|
---|
1547 | \sa windowState(), minimized, maximized
|
---|
1548 | */
|
---|
1549 | bool QWidget::isFullScreen() const
|
---|
1550 | { return testWState(WState_FullScreen); }
|
---|
1551 |
|
---|
1552 | /*!
|
---|
1553 | Shows the widget in full-screen mode.
|
---|
1554 |
|
---|
1555 | Calling this function only affects top-level widgets.
|
---|
1556 |
|
---|
1557 | To return from full-screen mode, call showNormal().
|
---|
1558 |
|
---|
1559 | Full-screen mode works fine under Windows, but has certain
|
---|
1560 | problems under X. These problems are due to limitations of the
|
---|
1561 | ICCCM protocol that specifies the communication between X11
|
---|
1562 | clients and the window manager. ICCCM simply does not understand
|
---|
1563 | the concept of non-decorated full-screen windows. Therefore, the
|
---|
1564 | best we can do is to request a borderless window and place and
|
---|
1565 | resize it to fill the entire screen. Depending on the window
|
---|
1566 | manager, this may or may not work. The borderless window is
|
---|
1567 | requested using MOTIF hints, which are at least partially
|
---|
1568 | supported by virtually all modern window managers.
|
---|
1569 |
|
---|
1570 | An alternative would be to bypass the window manager entirely and
|
---|
1571 | create a window with the WX11BypassWM flag. This has other severe
|
---|
1572 | problems though, like totally broken keyboard focus and very
|
---|
1573 | strange effects on desktop changes or when the user raises other
|
---|
1574 | windows.
|
---|
1575 |
|
---|
1576 | X11 window managers that follow modern post-ICCCM specifications
|
---|
1577 | support full-screen mode properly.
|
---|
1578 |
|
---|
1579 | \sa showNormal(), showMaximized(), show(), hide(), isVisible()
|
---|
1580 | */
|
---|
1581 | void QWidget::showFullScreen()
|
---|
1582 | {
|
---|
1583 | if (isFullScreen()) return;
|
---|
1584 |
|
---|
1585 | setWindowState(windowState() | WindowFullScreen);
|
---|
1586 | show();
|
---|
1587 | if (!isTopLevel())
|
---|
1588 | QApplication::sendPostedEvents(this, QEvent::ShowFullScreen);
|
---|
1589 | setActiveWindow();
|
---|
1590 | }
|
---|
1591 |
|
---|
1592 | /*!
|
---|
1593 | Shows the widget maximized.
|
---|
1594 |
|
---|
1595 | Calling this function only affects \link isTopLevel() top-level
|
---|
1596 | widgets\endlink.
|
---|
1597 |
|
---|
1598 | On X11, this function may not work properly with certain window
|
---|
1599 | managers. See the \link geometry.html Window Geometry
|
---|
1600 | documentation\endlink for an explanation.
|
---|
1601 |
|
---|
1602 | \sa setWindowState(), showNormal(), showMinimized(), show(), hide(), isVisible()
|
---|
1603 | */
|
---|
1604 | void QWidget::showMaximized()
|
---|
1605 | {
|
---|
1606 | if (isMaximized()) return;
|
---|
1607 |
|
---|
1608 | setWindowState((windowState() & ~WindowMinimized) | WindowMaximized);
|
---|
1609 | show();
|
---|
1610 | if (!isTopLevel())
|
---|
1611 | QApplication::sendPostedEvents(this, QEvent::ShowMaximized);
|
---|
1612 | }
|
---|
1613 |
|
---|
1614 | /*!
|
---|
1615 | Restores the widget after it has been maximized or minimized.
|
---|
1616 |
|
---|
1617 | Calling this function only affects \link isTopLevel() top-level
|
---|
1618 | widgets\endlink.
|
---|
1619 |
|
---|
1620 | \sa setWindowState(), showMinimized(), showMaximized(), show(), hide(), isVisible()
|
---|
1621 | */
|
---|
1622 | void QWidget::showNormal()
|
---|
1623 | {
|
---|
1624 | setWindowState(WindowNoState);
|
---|
1625 | show();
|
---|
1626 | if (!isTopLevel())
|
---|
1627 | QApplication::sendPostedEvents(this, QEvent::ShowNormal);
|
---|
1628 | }
|
---|
1629 |
|
---|
1630 | /*!
|
---|
1631 | Returns TRUE if this widget would become enabled if \a ancestor is
|
---|
1632 | enabled; otherwise returns FALSE.
|
---|
1633 |
|
---|
1634 | This is the case if neither the widget itself nor every parent up
|
---|
1635 | to but excluding \a ancestor has been explicitly disabled.
|
---|
1636 |
|
---|
1637 | isEnabledTo(0) is equivalent to isEnabled().
|
---|
1638 |
|
---|
1639 | \sa setEnabled() enabled
|
---|
1640 | */
|
---|
1641 |
|
---|
1642 | bool QWidget::isEnabledTo( QWidget* ancestor ) const
|
---|
1643 | {
|
---|
1644 | const QWidget * w = this;
|
---|
1645 | while ( w && !w->testWState(WState_ForceDisabled)
|
---|
1646 | && !w->isTopLevel()
|
---|
1647 | && w->parentWidget()
|
---|
1648 | && w->parentWidget() != ancestor )
|
---|
1649 | w = w->parentWidget();
|
---|
1650 | return !w->testWState( WState_ForceDisabled );
|
---|
1651 | }
|
---|
1652 |
|
---|
1653 |
|
---|
1654 | /*!
|
---|
1655 | \fn bool QWidget::isEnabledToTLW() const
|
---|
1656 | \obsolete
|
---|
1657 |
|
---|
1658 | This function is deprecated. It is equivalent to isEnabled()
|
---|
1659 | */
|
---|
1660 |
|
---|
1661 | /*!
|
---|
1662 | \property QWidget::enabled
|
---|
1663 | \brief whether the widget is enabled
|
---|
1664 |
|
---|
1665 | An enabled widget receives keyboard and mouse events; a disabled
|
---|
1666 | widget does not. In fact, an enabled widget only receives keyboard
|
---|
1667 | events when it is in focus.
|
---|
1668 |
|
---|
1669 | Some widgets display themselves differently when they are
|
---|
1670 | disabled. For example a button might draw its label grayed out. If
|
---|
1671 | your widget needs to know when it becomes enabled or disabled, you
|
---|
1672 | can reimplement the enabledChange() function.
|
---|
1673 |
|
---|
1674 | Disabling a widget implicitly disables all its children. Enabling
|
---|
1675 | respectively enables all child widgets unless they have been
|
---|
1676 | explicitly disabled.
|
---|
1677 |
|
---|
1678 | \sa isEnabled(), isEnabledTo(), QKeyEvent, QMouseEvent, enabledChange()
|
---|
1679 | */
|
---|
1680 | void QWidget::setEnabled( bool enable )
|
---|
1681 | {
|
---|
1682 | if ( enable )
|
---|
1683 | clearWState( WState_ForceDisabled );
|
---|
1684 | else
|
---|
1685 | setWState( WState_ForceDisabled );
|
---|
1686 |
|
---|
1687 | if ( !isTopLevel() && parentWidget() &&
|
---|
1688 | !parentWidget()->isEnabled() && enable )
|
---|
1689 | return; // nothing we can do
|
---|
1690 |
|
---|
1691 | if ( enable ) {
|
---|
1692 | if ( testWState(WState_Disabled) ) {
|
---|
1693 | clearWState( WState_Disabled );
|
---|
1694 | setBackgroundFromMode();
|
---|
1695 | enabledChange( !enable );
|
---|
1696 | if ( children() ) {
|
---|
1697 | QObjectListIt it( *children() );
|
---|
1698 | QWidget *w;
|
---|
1699 | while( (w = (QWidget *)it.current()) != 0 ) {
|
---|
1700 | ++it;
|
---|
1701 | if ( w->isWidgetType() &&
|
---|
1702 | !w->testWState( WState_ForceDisabled ) )
|
---|
1703 | w->setEnabled( TRUE );
|
---|
1704 | }
|
---|
1705 | }
|
---|
1706 | }
|
---|
1707 | } else {
|
---|
1708 | if ( !testWState(WState_Disabled) ) {
|
---|
1709 | if ( focusWidget() == this && ( !parentWidget() || parentWidget()->isEnabled() ) ) {
|
---|
1710 | if ( !focusNextPrevChild( TRUE ) )
|
---|
1711 | clearFocus();
|
---|
1712 | }
|
---|
1713 | setWState( WState_Disabled );
|
---|
1714 | setBackgroundFromMode();
|
---|
1715 | enabledChange( !enable );
|
---|
1716 | if ( children() ) {
|
---|
1717 | QObjectListIt it( *children() );
|
---|
1718 | QWidget *w;
|
---|
1719 | while( (w = (QWidget *)it.current()) != 0 ) {
|
---|
1720 | ++it;
|
---|
1721 | if ( w->isWidgetType() && w->isEnabled() ) {
|
---|
1722 | w->setEnabled( FALSE );
|
---|
1723 | w->clearWState( WState_ForceDisabled );
|
---|
1724 | }
|
---|
1725 | }
|
---|
1726 | }
|
---|
1727 | }
|
---|
1728 | }
|
---|
1729 | #if defined(Q_WS_X11)
|
---|
1730 | if ( testWState( WState_OwnCursor ) ) {
|
---|
1731 | // enforce the windows behavior of clearing the cursor on
|
---|
1732 | // disabled widgets
|
---|
1733 |
|
---|
1734 | extern void qt_x11_enforce_cursor( QWidget * w ); // defined in qwidget_x11.cpp
|
---|
1735 | qt_x11_enforce_cursor( this );
|
---|
1736 | }
|
---|
1737 | #endif
|
---|
1738 | #ifdef Q_WS_WIN
|
---|
1739 | QInputContext::enable( this, im_enabled & !((bool)testWState(WState_Disabled)) );
|
---|
1740 | #endif
|
---|
1741 | }
|
---|
1742 |
|
---|
1743 | /*!
|
---|
1744 | Disables widget input events if \a disable is TRUE; otherwise
|
---|
1745 | enables input events.
|
---|
1746 |
|
---|
1747 | See the \l enabled documentation for more information.
|
---|
1748 |
|
---|
1749 | \sa isEnabledTo(), QKeyEvent, QMouseEvent, enabledChange()
|
---|
1750 | */
|
---|
1751 | void QWidget::setDisabled( bool disable )
|
---|
1752 | {
|
---|
1753 | setEnabled( !disable );
|
---|
1754 | }
|
---|
1755 |
|
---|
1756 | /*!
|
---|
1757 | \fn void QWidget::enabledChange( bool oldEnabled )
|
---|
1758 |
|
---|
1759 | This virtual function is called from setEnabled(). \a oldEnabled
|
---|
1760 | is the previous setting; you can get the new setting from
|
---|
1761 | isEnabled().
|
---|
1762 |
|
---|
1763 | Reimplement this function if your widget needs to know when it
|
---|
1764 | becomes enabled or disabled. You will almost certainly need to
|
---|
1765 | update the widget using update().
|
---|
1766 |
|
---|
1767 | The default implementation repaints the visible part of the
|
---|
1768 | widget.
|
---|
1769 |
|
---|
1770 | \sa setEnabled(), isEnabled(), repaint(), update(), clipRegion()
|
---|
1771 | */
|
---|
1772 |
|
---|
1773 | void QWidget::enabledChange( bool )
|
---|
1774 | {
|
---|
1775 | update();
|
---|
1776 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
---|
1777 | QAccessible::updateAccessibility( this, 0, QAccessible::StateChanged );
|
---|
1778 | #endif
|
---|
1779 | }
|
---|
1780 |
|
---|
1781 | /*!
|
---|
1782 | \fn void QWidget::windowActivationChange( bool oldActive )
|
---|
1783 |
|
---|
1784 | This virtual function is called for a widget when its window is
|
---|
1785 | activated or deactivated by the window system. \a oldActive is the
|
---|
1786 | previous state; you can get the new setting from isActiveWindow().
|
---|
1787 |
|
---|
1788 | Reimplement this function if your widget needs to know when its
|
---|
1789 | window becomes activated or deactivated.
|
---|
1790 |
|
---|
1791 | The default implementation updates the visible part of the widget
|
---|
1792 | if the inactive and the active colorgroup are different for colors
|
---|
1793 | other than the highlight and link colors.
|
---|
1794 |
|
---|
1795 | \sa setActiveWindow(), isActiveWindow(), update(), palette()
|
---|
1796 | */
|
---|
1797 |
|
---|
1798 | void QWidget::windowActivationChange( bool )
|
---|
1799 | {
|
---|
1800 | #ifndef QT_NO_PALETTE
|
---|
1801 | if ( !isVisible() )
|
---|
1802 | return;
|
---|
1803 |
|
---|
1804 | const QColorGroup &acg = palette().active();
|
---|
1805 | const QColorGroup &icg = palette().inactive();
|
---|
1806 |
|
---|
1807 | if ( acg != icg ) {
|
---|
1808 | BackgroundMode bm = backgroundMode();
|
---|
1809 | QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode(bm);
|
---|
1810 | if ( bm > NoBackground && acg.brush(role) != icg.brush(role) )
|
---|
1811 | setBackgroundFromMode();
|
---|
1812 | else if ( acg.background() == icg.background() &&
|
---|
1813 | acg.base() == icg.base() &&
|
---|
1814 | acg.text() == icg.text() &&
|
---|
1815 | acg.foreground() == icg.foreground() &&
|
---|
1816 | acg.button() == icg.button() &&
|
---|
1817 | acg.buttonText() == icg.buttonText() &&
|
---|
1818 | acg.brightText() == icg.brightText() &&
|
---|
1819 | acg.dark() == icg.dark() &&
|
---|
1820 | acg.light() == icg.light() &&
|
---|
1821 | acg.mid() == icg.mid() &&
|
---|
1822 | acg.midlight() == icg.midlight() &&
|
---|
1823 | acg.shadow() == icg.shadow() )
|
---|
1824 | return;
|
---|
1825 | update();
|
---|
1826 | }
|
---|
1827 | #endif
|
---|
1828 | }
|
---|
1829 |
|
---|
1830 | /*!
|
---|
1831 | \property QWidget::frameGeometry
|
---|
1832 | \brief geometry of the widget relative to its parent including any
|
---|
1833 | window frame
|
---|
1834 |
|
---|
1835 | See the \link geometry.html Window Geometry documentation\endlink
|
---|
1836 | for an overview of geometry issues with top-level widgets.
|
---|
1837 |
|
---|
1838 | \sa geometry() x() y() pos()
|
---|
1839 | */
|
---|
1840 | QRect QWidget::frameGeometry() const
|
---|
1841 | {
|
---|
1842 | if (isTopLevel() && ! isPopup()) {
|
---|
1843 | if (fstrut_dirty)
|
---|
1844 | updateFrameStrut();
|
---|
1845 | QWidget *that = (QWidget *) this;
|
---|
1846 | QTLWExtra *top = that->topData();
|
---|
1847 | return QRect(crect.x() - top->fleft,
|
---|
1848 | crect.y() - top->ftop,
|
---|
1849 | crect.width() + top->fleft + top->fright,
|
---|
1850 | crect.height() + top->ftop + top->fbottom);
|
---|
1851 | }
|
---|
1852 | return crect;
|
---|
1853 | }
|
---|
1854 |
|
---|
1855 | /*! \property QWidget::x
|
---|
1856 | \brief the x coordinate of the widget relative to its parent including
|
---|
1857 | any window frame
|
---|
1858 |
|
---|
1859 | See the \link geometry.html Window Geometry documentation\endlink
|
---|
1860 | for an overview of top-level widget geometry.
|
---|
1861 |
|
---|
1862 | \sa frameGeometry, y, pos
|
---|
1863 | */
|
---|
1864 | int QWidget::x() const
|
---|
1865 | {
|
---|
1866 | if (isTopLevel() && ! isPopup()) {
|
---|
1867 | if (fstrut_dirty)
|
---|
1868 | updateFrameStrut();
|
---|
1869 | QWidget *that = (QWidget *) this;
|
---|
1870 | return crect.x() - that->topData()->fleft;
|
---|
1871 | }
|
---|
1872 | return crect.x();
|
---|
1873 | }
|
---|
1874 |
|
---|
1875 | /*!
|
---|
1876 | \property QWidget::y
|
---|
1877 | \brief the y coordinate of the widget relative to its parent and
|
---|
1878 | including any window frame
|
---|
1879 |
|
---|
1880 | See the \link geometry.html Window Geometry documentation\endlink
|
---|
1881 | for an overview of top-level widget geometry.
|
---|
1882 |
|
---|
1883 | \sa frameGeometry, x, pos
|
---|
1884 | */
|
---|
1885 | int QWidget::y() const
|
---|
1886 | {
|
---|
1887 | if (isTopLevel() && ! isPopup()) {
|
---|
1888 | if (fstrut_dirty)
|
---|
1889 | updateFrameStrut();
|
---|
1890 | QWidget *that = (QWidget *) this;
|
---|
1891 | return crect.y() - that->topData()->ftop;
|
---|
1892 | }
|
---|
1893 | return crect.y();
|
---|
1894 | }
|
---|
1895 |
|
---|
1896 | /*!
|
---|
1897 | \property QWidget::pos
|
---|
1898 | \brief the position of the widget within its parent widget
|
---|
1899 |
|
---|
1900 | If the widget is a top-level widget, the position is that of the
|
---|
1901 | widget on the desktop, including its frame.
|
---|
1902 |
|
---|
1903 | When changing the position, the widget, if visible, receives a
|
---|
1904 | move event (moveEvent()) immediately. If the widget is not
|
---|
1905 | currently visible, it is guaranteed to receive an event before it
|
---|
1906 | is shown.
|
---|
1907 |
|
---|
1908 | move() is virtual, and all other overloaded move() implementations
|
---|
1909 | in Qt call it.
|
---|
1910 |
|
---|
1911 | \warning Calling move() or setGeometry() inside moveEvent() can
|
---|
1912 | lead to infinite recursion.
|
---|
1913 |
|
---|
1914 | See the \link geometry.html Window Geometry documentation\endlink
|
---|
1915 | for an overview of top-level widget geometry.
|
---|
1916 |
|
---|
1917 | \sa frameGeometry, size x(), y()
|
---|
1918 | */
|
---|
1919 | QPoint QWidget::pos() const
|
---|
1920 | {
|
---|
1921 | if (isTopLevel() && ! isPopup()) {
|
---|
1922 | if (fstrut_dirty)
|
---|
1923 | updateFrameStrut();
|
---|
1924 | QWidget *that = (QWidget *) this;
|
---|
1925 | QTLWExtra *top = that->topData();
|
---|
1926 | return QPoint(crect.x() - top->fleft, crect.y() - top->ftop);
|
---|
1927 | }
|
---|
1928 | return crect.topLeft();
|
---|
1929 | }
|
---|
1930 |
|
---|
1931 | /*!
|
---|
1932 | \property QWidget::geometry
|
---|
1933 | \brief the geometry of the widget relative to its parent and
|
---|
1934 | excluding the window frame
|
---|
1935 |
|
---|
1936 | When changing the geometry, the widget, if visible, receives a
|
---|
1937 | move event (moveEvent()) and/or a resize event (resizeEvent())
|
---|
1938 | immediately. If the widget is not currently visible, it is
|
---|
1939 | guaranteed to receive appropriate events before it is shown.
|
---|
1940 |
|
---|
1941 | The size component is adjusted if it lies outside the range
|
---|
1942 | defined by minimumSize() and maximumSize().
|
---|
1943 |
|
---|
1944 | setGeometry() is virtual, and all other overloaded setGeometry()
|
---|
1945 | implementations in Qt call it.
|
---|
1946 |
|
---|
1947 | \warning Calling setGeometry() inside resizeEvent() or moveEvent()
|
---|
1948 | can lead to infinite recursion.
|
---|
1949 |
|
---|
1950 | See the \link geometry.html Window Geometry documentation\endlink
|
---|
1951 | for an overview of top-level widget geometry.
|
---|
1952 |
|
---|
1953 | \sa frameGeometry(), rect(), move(), resize(), moveEvent(),
|
---|
1954 | resizeEvent(), minimumSize(), maximumSize()
|
---|
1955 | */
|
---|
1956 |
|
---|
1957 | /*!
|
---|
1958 | \property QWidget::size
|
---|
1959 | \brief the size of the widget excluding any window frame
|
---|
1960 |
|
---|
1961 | When resizing, the widget, if visible, receives a resize event
|
---|
1962 | (resizeEvent()) immediately. If the widget is not currently
|
---|
1963 | visible, it is guaranteed to receive an event before it is shown.
|
---|
1964 |
|
---|
1965 | The size is adjusted if it lies outside the range defined by
|
---|
1966 | minimumSize() and maximumSize(). Furthermore, the size is always
|
---|
1967 | at least QSize(1, 1). For toplevel widgets, the minimum size
|
---|
1968 | might be larger, depending on the window manager.
|
---|
1969 |
|
---|
1970 | If you want a top-level window to have a fixed size, call
|
---|
1971 | setResizeMode( QLayout::FreeResize ) on its layout.
|
---|
1972 |
|
---|
1973 | resize() is virtual, and all other overloaded resize()
|
---|
1974 | implementations in Qt call it.
|
---|
1975 |
|
---|
1976 | \warning Calling resize() or setGeometry() inside resizeEvent() can
|
---|
1977 | lead to infinite recursion.
|
---|
1978 |
|
---|
1979 | \sa pos, geometry, minimumSize, maximumSize, resizeEvent()
|
---|
1980 | */
|
---|
1981 |
|
---|
1982 | /*!
|
---|
1983 | \property QWidget::width
|
---|
1984 | \brief the width of the widget excluding any window frame
|
---|
1985 |
|
---|
1986 | See the \link geometry.html Window Geometry documentation\endlink
|
---|
1987 | for an overview of top-level widget geometry.
|
---|
1988 |
|
---|
1989 | \sa geometry, height, size
|
---|
1990 | */
|
---|
1991 |
|
---|
1992 | /*!
|
---|
1993 | \property QWidget::height
|
---|
1994 | \brief the height of the widget excluding any window frame
|
---|
1995 |
|
---|
1996 | See the \link geometry.html Window Geometry documentation\endlink
|
---|
1997 | for an overview of top-level widget geometry.
|
---|
1998 |
|
---|
1999 | \sa geometry, width, size
|
---|
2000 | */
|
---|
2001 |
|
---|
2002 | /*!
|
---|
2003 | \property QWidget::rect
|
---|
2004 | \brief the internal geometry of the widget excluding any window
|
---|
2005 | frame
|
---|
2006 |
|
---|
2007 | The rect property equals QRect(0, 0, width(), height()).
|
---|
2008 |
|
---|
2009 | See the \link geometry.html Window Geometry documentation\endlink
|
---|
2010 | for an overview of top-level widget geometry.
|
---|
2011 |
|
---|
2012 | \sa size
|
---|
2013 | */
|
---|
2014 |
|
---|
2015 | /*!
|
---|
2016 | \property QWidget::childrenRect
|
---|
2017 | \brief the bounding rectangle of the widget's children
|
---|
2018 |
|
---|
2019 | Hidden children are excluded.
|
---|
2020 |
|
---|
2021 | \sa childrenRegion() geometry()
|
---|
2022 | */
|
---|
2023 |
|
---|
2024 | QRect QWidget::childrenRect() const
|
---|
2025 | {
|
---|
2026 | QRect r( 0, 0, 0, 0 );
|
---|
2027 | if ( !children() )
|
---|
2028 | return r;
|
---|
2029 | QObjectListIt it( *children() );
|
---|
2030 | QObject *obj;
|
---|
2031 | while ( (obj = it.current()) ) {
|
---|
2032 | ++it;
|
---|
2033 | if ( obj->isWidgetType() && !((QWidget*)obj)->isHidden() )
|
---|
2034 | r = r.unite( ((QWidget*)obj)->geometry() );
|
---|
2035 | }
|
---|
2036 | return r;
|
---|
2037 | }
|
---|
2038 |
|
---|
2039 | /*!
|
---|
2040 | \property QWidget::childrenRegion
|
---|
2041 | \brief the combined region occupied by the widget's children
|
---|
2042 |
|
---|
2043 | Hidden children are excluded.
|
---|
2044 |
|
---|
2045 | \sa childrenRect() geometry()
|
---|
2046 | */
|
---|
2047 |
|
---|
2048 | QRegion QWidget::childrenRegion() const
|
---|
2049 | {
|
---|
2050 | QRegion r;
|
---|
2051 | if ( !children() )
|
---|
2052 | return r;
|
---|
2053 | QObjectListIt it( *children() ); // iterate over all children
|
---|
2054 | QObject *obj;
|
---|
2055 | while ( (obj=it.current()) ) {
|
---|
2056 | ++it;
|
---|
2057 | if ( obj->isWidgetType() && !((QWidget*)obj)->isHidden() )
|
---|
2058 | r = r.unite( ((QWidget*)obj)->geometry() );
|
---|
2059 | }
|
---|
2060 | return r;
|
---|
2061 | }
|
---|
2062 |
|
---|
2063 |
|
---|
2064 | /*!
|
---|
2065 | \property QWidget::minimumSize
|
---|
2066 | \brief the widget's minimum size
|
---|
2067 |
|
---|
2068 | The widget cannot be resized to a smaller size than the minimum
|
---|
2069 | widget size. The widget's size is forced to the minimum size if
|
---|
2070 | the current size is smaller.
|
---|
2071 |
|
---|
2072 | If you use a layout inside the widget, the minimum size will be
|
---|
2073 | set by the layout and not by setMinimumSize(), unless you set the
|
---|
2074 | layout's resize mode to QLayout::FreeResize.
|
---|
2075 |
|
---|
2076 | \sa minimumWidth, minimumHeight, maximumSize, sizeIncrement
|
---|
2077 | QLayout::setResizeMode()
|
---|
2078 | */
|
---|
2079 |
|
---|
2080 | QSize QWidget::minimumSize() const
|
---|
2081 | {
|
---|
2082 | return extra ? QSize( extra->minw, extra->minh ) : QSize( 0, 0 );
|
---|
2083 | }
|
---|
2084 |
|
---|
2085 | /*!
|
---|
2086 | \property QWidget::maximumSize
|
---|
2087 | \brief the widget's maximum size
|
---|
2088 |
|
---|
2089 | The widget cannot be resized to a larger size than the maximum
|
---|
2090 | widget size.
|
---|
2091 |
|
---|
2092 | \sa maximumWidth(), maximumHeight(), setMaximumSize(),
|
---|
2093 | minimumSize(), sizeIncrement()
|
---|
2094 | */
|
---|
2095 |
|
---|
2096 | QSize QWidget::maximumSize() const
|
---|
2097 | {
|
---|
2098 | return extra ? QSize( extra->maxw, extra->maxh )
|
---|
2099 | : QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX );
|
---|
2100 | }
|
---|
2101 |
|
---|
2102 |
|
---|
2103 | /*!
|
---|
2104 | \property QWidget::minimumWidth
|
---|
2105 | \brief the widget's minimum width
|
---|
2106 |
|
---|
2107 | This property corresponds to minimumSize().width().
|
---|
2108 |
|
---|
2109 | \sa minimumSize, minimumHeight
|
---|
2110 | */
|
---|
2111 |
|
---|
2112 | /*!
|
---|
2113 | \property QWidget::minimumHeight
|
---|
2114 | \brief the widget's minimum height
|
---|
2115 |
|
---|
2116 | This property corresponds to minimumSize().height().
|
---|
2117 |
|
---|
2118 | \sa minimumSize, minimumWidth
|
---|
2119 | */
|
---|
2120 |
|
---|
2121 | /*!
|
---|
2122 | \property QWidget::maximumWidth
|
---|
2123 | \brief the widget's maximum width
|
---|
2124 |
|
---|
2125 | This property corresponds to maximumSize().width().
|
---|
2126 |
|
---|
2127 | \sa maximumSize, maximumHeight
|
---|
2128 | */
|
---|
2129 |
|
---|
2130 | /*!
|
---|
2131 | \property QWidget::maximumHeight
|
---|
2132 | \brief the widget's maximum height
|
---|
2133 |
|
---|
2134 | This property corresponds to maximumSize().height().
|
---|
2135 |
|
---|
2136 | \sa maximumSize, maximumWidth
|
---|
2137 | */
|
---|
2138 |
|
---|
2139 | /*!
|
---|
2140 | \property QWidget::sizeIncrement
|
---|
2141 | \brief the size increment of the widget
|
---|
2142 |
|
---|
2143 | When the user resizes the window, the size will move in steps of
|
---|
2144 | sizeIncrement().width() pixels horizontally and
|
---|
2145 | sizeIncrement.height() pixels vertically, with baseSize() as the
|
---|
2146 | basis. Preferred widget sizes are for non-negative integers \e i
|
---|
2147 | and \e j:
|
---|
2148 | \code
|
---|
2149 | width = baseSize().width() + i * sizeIncrement().width();
|
---|
2150 | height = baseSize().height() + j * sizeIncrement().height();
|
---|
2151 | \endcode
|
---|
2152 |
|
---|
2153 | Note that while you can set the size increment for all widgets, it
|
---|
2154 | only affects top-level widgets.
|
---|
2155 |
|
---|
2156 | \warning The size increment has no effect under Windows, and may
|
---|
2157 | be disregarded by the window manager on X.
|
---|
2158 |
|
---|
2159 | \sa size, minimumSize, maximumSize
|
---|
2160 | */
|
---|
2161 | QSize QWidget::sizeIncrement() const
|
---|
2162 | {
|
---|
2163 | return ( extra && extra->topextra )
|
---|
2164 | ? QSize( extra->topextra->incw, extra->topextra->inch )
|
---|
2165 | : QSize( 0, 0 );
|
---|
2166 | }
|
---|
2167 |
|
---|
2168 | /*!
|
---|
2169 | \property QWidget::baseSize
|
---|
2170 | \brief the base size of the widget
|
---|
2171 |
|
---|
2172 | The base size is used to calculate a proper widget size if the
|
---|
2173 | widget defines sizeIncrement().
|
---|
2174 |
|
---|
2175 | \sa setSizeIncrement()
|
---|
2176 | */
|
---|
2177 |
|
---|
2178 | QSize QWidget::baseSize() const
|
---|
2179 | {
|
---|
2180 | return ( extra != 0 && extra->topextra != 0 )
|
---|
2181 | ? QSize( extra->topextra->basew, extra->topextra->baseh )
|
---|
2182 | : QSize( 0, 0 );
|
---|
2183 | }
|
---|
2184 |
|
---|
2185 | /*!
|
---|
2186 | Sets both the minimum and maximum sizes of the widget to \a s,
|
---|
2187 | thereby preventing it from ever growing or shrinking.
|
---|
2188 |
|
---|
2189 | \sa setMaximumSize() setMinimumSize()
|
---|
2190 | */
|
---|
2191 |
|
---|
2192 | void QWidget::setFixedSize( const QSize & s)
|
---|
2193 | {
|
---|
2194 | setMinimumSize( s );
|
---|
2195 | setMaximumSize( s );
|
---|
2196 | resize( s );
|
---|
2197 | }
|
---|
2198 |
|
---|
2199 |
|
---|
2200 | /*!
|
---|
2201 | \overload void QWidget::setFixedSize( int w, int h )
|
---|
2202 |
|
---|
2203 | Sets the width of the widget to \a w and the height to \a h.
|
---|
2204 | */
|
---|
2205 |
|
---|
2206 | void QWidget::setFixedSize( int w, int h )
|
---|
2207 | {
|
---|
2208 | setMinimumSize( w, h );
|
---|
2209 | setMaximumSize( w, h );
|
---|
2210 | resize( w, h );
|
---|
2211 | }
|
---|
2212 |
|
---|
2213 | void QWidget::setMinimumWidth( int w )
|
---|
2214 | {
|
---|
2215 | setMinimumSize( w, minimumSize().height() );
|
---|
2216 | }
|
---|
2217 |
|
---|
2218 | void QWidget::setMinimumHeight( int h )
|
---|
2219 | {
|
---|
2220 | setMinimumSize( minimumSize().width(), h );
|
---|
2221 | }
|
---|
2222 |
|
---|
2223 | void QWidget::setMaximumWidth( int w )
|
---|
2224 | {
|
---|
2225 | setMaximumSize( w, maximumSize().height() );
|
---|
2226 | }
|
---|
2227 |
|
---|
2228 | void QWidget::setMaximumHeight( int h )
|
---|
2229 | {
|
---|
2230 | setMaximumSize( maximumSize().width(), h );
|
---|
2231 | }
|
---|
2232 |
|
---|
2233 | /*!
|
---|
2234 | Sets both the minimum and maximum width of the widget to \a w
|
---|
2235 | without changing the heights. Provided for convenience.
|
---|
2236 |
|
---|
2237 | \sa sizeHint() minimumSize() maximumSize() setFixedSize()
|
---|
2238 | */
|
---|
2239 |
|
---|
2240 | void QWidget::setFixedWidth( int w )
|
---|
2241 | {
|
---|
2242 | setMinimumSize( w, minimumSize().height() );
|
---|
2243 | setMaximumSize( w, maximumSize().height() );
|
---|
2244 | }
|
---|
2245 |
|
---|
2246 |
|
---|
2247 | /*!
|
---|
2248 | Sets both the minimum and maximum heights of the widget to \a h
|
---|
2249 | without changing the widths. Provided for convenience.
|
---|
2250 |
|
---|
2251 | \sa sizeHint() minimumSize() maximumSize() setFixedSize()
|
---|
2252 | */
|
---|
2253 |
|
---|
2254 | void QWidget::setFixedHeight( int h )
|
---|
2255 | {
|
---|
2256 | setMinimumSize( minimumSize().width(), h );
|
---|
2257 | setMaximumSize( maximumSize().width(), h );
|
---|
2258 | }
|
---|
2259 |
|
---|
2260 |
|
---|
2261 | /*!
|
---|
2262 | Translates the widget coordinate \a pos to the coordinate system
|
---|
2263 | of \a parent. The \a parent must not be 0 and must be a parent
|
---|
2264 | of the calling widget.
|
---|
2265 |
|
---|
2266 | \sa mapFrom() mapToParent() mapToGlobal() hasMouse()
|
---|
2267 | */
|
---|
2268 |
|
---|
2269 | QPoint QWidget::mapTo( QWidget * parent, const QPoint & pos ) const
|
---|
2270 | {
|
---|
2271 | QPoint p = pos;
|
---|
2272 | if ( parent ) {
|
---|
2273 | const QWidget * w = this;
|
---|
2274 | while ( w != parent ) {
|
---|
2275 | p = w->mapToParent( p );
|
---|
2276 | w = w->parentWidget();
|
---|
2277 | }
|
---|
2278 | }
|
---|
2279 | return p;
|
---|
2280 | }
|
---|
2281 |
|
---|
2282 |
|
---|
2283 | /*!
|
---|
2284 | Translates the widget coordinate \a pos from the coordinate system
|
---|
2285 | of \a parent to this widget's coordinate system. The \a parent
|
---|
2286 | must not be 0 and must be a parent of the calling widget.
|
---|
2287 |
|
---|
2288 | \sa mapTo() mapFromParent() mapFromGlobal() hasMouse()
|
---|
2289 | */
|
---|
2290 |
|
---|
2291 | QPoint QWidget::mapFrom( QWidget * parent, const QPoint & pos ) const
|
---|
2292 | {
|
---|
2293 | QPoint p( pos );
|
---|
2294 | if ( parent ) {
|
---|
2295 | const QWidget * w = this;
|
---|
2296 | while ( w != parent ) {
|
---|
2297 | p = w->mapFromParent( p );
|
---|
2298 | w = w->parentWidget();
|
---|
2299 | }
|
---|
2300 | }
|
---|
2301 | return p;
|
---|
2302 | }
|
---|
2303 |
|
---|
2304 |
|
---|
2305 | /*!
|
---|
2306 | Translates the widget coordinate \a pos to a coordinate in the
|
---|
2307 | parent widget.
|
---|
2308 |
|
---|
2309 | Same as mapToGlobal() if the widget has no parent.
|
---|
2310 |
|
---|
2311 | \sa mapFromParent() mapTo() mapToGlobal() hasMouse()
|
---|
2312 | */
|
---|
2313 |
|
---|
2314 | QPoint QWidget::mapToParent( const QPoint &pos ) const
|
---|
2315 | {
|
---|
2316 | return pos + crect.topLeft();
|
---|
2317 | }
|
---|
2318 |
|
---|
2319 | /*!
|
---|
2320 | Translates the parent widget coordinate \a pos to widget
|
---|
2321 | coordinates.
|
---|
2322 |
|
---|
2323 | Same as mapFromGlobal() if the widget has no parent.
|
---|
2324 |
|
---|
2325 | \sa mapToParent() mapFrom() mapFromGlobal() hasMouse()
|
---|
2326 | */
|
---|
2327 |
|
---|
2328 | QPoint QWidget::mapFromParent( const QPoint &pos ) const
|
---|
2329 | {
|
---|
2330 | return pos - crect.topLeft();
|
---|
2331 | }
|
---|
2332 |
|
---|
2333 |
|
---|
2334 | /*!
|
---|
2335 | Returns the top-level widget for this widget, i.e. the next
|
---|
2336 | ancestor widget that has (or could have) a window-system frame.
|
---|
2337 |
|
---|
2338 | If the widget is a top-level, the widget itself is returned.
|
---|
2339 |
|
---|
2340 | Typical usage is changing the window caption:
|
---|
2341 |
|
---|
2342 | \code
|
---|
2343 | aWidget->topLevelWidget()->setCaption( "New Caption" );
|
---|
2344 | \endcode
|
---|
2345 |
|
---|
2346 | \sa isTopLevel()
|
---|
2347 | */
|
---|
2348 |
|
---|
2349 | QWidget *QWidget::topLevelWidget() const
|
---|
2350 | {
|
---|
2351 | QWidget *w = (QWidget *)this;
|
---|
2352 | QWidget *p = w->parentWidget();
|
---|
2353 | while ( !w->testWFlags(WType_TopLevel) && p ) {
|
---|
2354 | w = p;
|
---|
2355 | p = p->parentWidget();
|
---|
2356 | }
|
---|
2357 | return w;
|
---|
2358 | }
|
---|
2359 |
|
---|
2360 |
|
---|
2361 | /*!
|
---|
2362 | \property QWidget::paletteForegroundColor
|
---|
2363 | \brief the foreground color of the widget
|
---|
2364 |
|
---|
2365 | setPaletteForegroundColor() is a convenience function that creates
|
---|
2366 | and sets a modified QPalette with setPalette(). The palette is
|
---|
2367 | modified according to the widget's \e {background mode}. For
|
---|
2368 | example, if the background mode is \c PaletteButton the palette entry
|
---|
2369 | \c QColorGroup::ButtonText is set to color.
|
---|
2370 |
|
---|
2371 | \sa setPalette() QApplication::setPalette() backgroundMode()
|
---|
2372 | foregroundColor() setBackgroundMode() setEraseColor()
|
---|
2373 | */
|
---|
2374 | const QColor &QWidget::paletteForegroundColor() const
|
---|
2375 | {
|
---|
2376 | #ifndef QT_NO_PALETTE
|
---|
2377 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
---|
2378 | return colorGroup().color( QPalette::foregroundRoleFromMode(mode) );
|
---|
2379 | #else
|
---|
2380 | return Qt::black;
|
---|
2381 | #endif
|
---|
2382 | }
|
---|
2383 |
|
---|
2384 | void QWidget::setPaletteForegroundColor( const QColor & color )
|
---|
2385 | {
|
---|
2386 | #ifndef QT_NO_PALETTE
|
---|
2387 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
---|
2388 | QPalette pal = palette();
|
---|
2389 | QColorGroup::ColorRole role = QPalette::foregroundRoleFromMode( mode );
|
---|
2390 | pal.setColor( QPalette::Active, role, color );
|
---|
2391 | pal.setColor( QPalette::Inactive, role, color );
|
---|
2392 | pal.setColor( QPalette::Disabled, role, color );
|
---|
2393 | setPalette( pal );
|
---|
2394 | #endif
|
---|
2395 | }
|
---|
2396 |
|
---|
2397 |
|
---|
2398 | /*!
|
---|
2399 | Same as paletteForegroundColor()
|
---|
2400 | */
|
---|
2401 | const QColor &QWidget::foregroundColor() const
|
---|
2402 | {
|
---|
2403 | return paletteForegroundColor();
|
---|
2404 | }
|
---|
2405 |
|
---|
2406 |
|
---|
2407 | /*!
|
---|
2408 | \fn const QColor& QWidget::eraseColor() const
|
---|
2409 |
|
---|
2410 | Returns the erase color of the widget.
|
---|
2411 |
|
---|
2412 | \sa setEraseColor() setErasePixmap() backgroundColor()
|
---|
2413 | */
|
---|
2414 |
|
---|
2415 | /*!
|
---|
2416 | Sets the erase color of the widget to \a color.
|
---|
2417 |
|
---|
2418 | The erase color is the color the widget is to be cleared to before
|
---|
2419 | paintEvent() is called. If there is an erase pixmap (set using
|
---|
2420 | setErasePixmap()), then this property has an indeterminate value.
|
---|
2421 |
|
---|
2422 | \sa erasePixmap(), backgroundColor(), backgroundMode(), palette()
|
---|
2423 | */
|
---|
2424 | void QWidget::setEraseColor( const QColor & color )
|
---|
2425 | {
|
---|
2426 | setBackgroundModeDirect( FixedColor );
|
---|
2427 | setBackgroundColorDirect( color );
|
---|
2428 | update();
|
---|
2429 | }
|
---|
2430 |
|
---|
2431 | /*!
|
---|
2432 | Returns the widget's erase pixmap.
|
---|
2433 |
|
---|
2434 | \sa setErasePixmap() eraseColor()
|
---|
2435 | */
|
---|
2436 | const QPixmap *QWidget::erasePixmap() const
|
---|
2437 | {
|
---|
2438 | return ( extra && extra->bg_pix ) ? extra->bg_pix : 0;
|
---|
2439 | }
|
---|
2440 |
|
---|
2441 | /*!
|
---|
2442 | Sets the widget's erase pixmap to \a pixmap.
|
---|
2443 |
|
---|
2444 | This pixmap is used to clear the widget before paintEvent() is
|
---|
2445 | called.
|
---|
2446 | */
|
---|
2447 | void QWidget::setErasePixmap( const QPixmap &pixmap )
|
---|
2448 | {
|
---|
2449 | // This function is called with a null pixmap by setBackgroundEmpty().
|
---|
2450 | setBackgroundPixmapDirect( pixmap );
|
---|
2451 | setBackgroundModeDirect( FixedPixmap );
|
---|
2452 | update();
|
---|
2453 | }
|
---|
2454 |
|
---|
2455 | void QWidget::setBackgroundFromMode()
|
---|
2456 | {
|
---|
2457 | #ifndef QT_NO_PALETTE
|
---|
2458 | QColorGroup::ColorRole r = QColorGroup::Background;
|
---|
2459 | if ( extra ) {
|
---|
2460 | int i = (BackgroundMode)extra->bg_mode;
|
---|
2461 | if ( i == FixedColor || i == FixedPixmap || i == NoBackground ) {
|
---|
2462 | // Mode is for fixed color, not one based on palette,
|
---|
2463 | // so nothing to do.
|
---|
2464 | return;
|
---|
2465 | }
|
---|
2466 | switch( i ) {
|
---|
2467 | case PaletteForeground:
|
---|
2468 | r = QColorGroup::Foreground;
|
---|
2469 | break;
|
---|
2470 | case PaletteButton:
|
---|
2471 | r = QColorGroup::Button;
|
---|
2472 | break;
|
---|
2473 | case PaletteLight:
|
---|
2474 | r = QColorGroup::Light;
|
---|
2475 | break;
|
---|
2476 | case PaletteMidlight:
|
---|
2477 | r = QColorGroup::Midlight;
|
---|
2478 | break;
|
---|
2479 | case PaletteDark:
|
---|
2480 | r = QColorGroup::Dark;
|
---|
2481 | break;
|
---|
2482 | case PaletteMid:
|
---|
2483 | r = QColorGroup::Mid;
|
---|
2484 | break;
|
---|
2485 | case PaletteText:
|
---|
2486 | r = QColorGroup::Text;
|
---|
2487 | break;
|
---|
2488 | case PaletteBrightText:
|
---|
2489 | r = QColorGroup::BrightText;
|
---|
2490 | break;
|
---|
2491 | case PaletteBase:
|
---|
2492 | r = QColorGroup::Base;
|
---|
2493 | break;
|
---|
2494 | case PaletteBackground:
|
---|
2495 | r = QColorGroup::Background;
|
---|
2496 | break;
|
---|
2497 | case PaletteShadow:
|
---|
2498 | r = QColorGroup::Shadow;
|
---|
2499 | break;
|
---|
2500 | case PaletteHighlight:
|
---|
2501 | r = QColorGroup::Highlight;
|
---|
2502 | break;
|
---|
2503 | case PaletteHighlightedText:
|
---|
2504 | r = QColorGroup::HighlightedText;
|
---|
2505 | break;
|
---|
2506 | case PaletteButtonText:
|
---|
2507 | r = QColorGroup::ButtonText;
|
---|
2508 | break;
|
---|
2509 | case X11ParentRelative:
|
---|
2510 | #if defined(Q_WS_X11)
|
---|
2511 | setBackgroundX11Relative();
|
---|
2512 | #endif
|
---|
2513 | return;
|
---|
2514 | }
|
---|
2515 | }
|
---|
2516 | const QColorGroup &cg = colorGroup();
|
---|
2517 | QPixmap * p = cg.brush( r ).pixmap();
|
---|
2518 | if ( p )
|
---|
2519 | setBackgroundPixmapDirect( *p );
|
---|
2520 | else
|
---|
2521 | setBackgroundColorDirect( cg.color( r ) );
|
---|
2522 | #endif
|
---|
2523 | }
|
---|
2524 |
|
---|
2525 | /*!
|
---|
2526 | \enum Qt::BackgroundMode
|
---|
2527 |
|
---|
2528 | This enum describes how the background of a widget changes, as the
|
---|
2529 | widget's palette changes.
|
---|
2530 |
|
---|
2531 | The background is what the widget contains when \link
|
---|
2532 | QWidget::paintEvent() paintEvent()\endlink is called. To minimize
|
---|
2533 | flicker, this should be the most common color or pixmap in the
|
---|
2534 | widget. For \c PaletteBackground, use colorGroup().brush( \c
|
---|
2535 | QColorGroup::Background ), and so on.
|
---|
2536 |
|
---|
2537 | \value PaletteForeground
|
---|
2538 | \value PaletteBackground
|
---|
2539 | \value PaletteButton
|
---|
2540 | \value PaletteLight
|
---|
2541 | \value PaletteMidlight
|
---|
2542 | \value PaletteDark
|
---|
2543 | \value PaletteMid
|
---|
2544 | \value PaletteText
|
---|
2545 | \value PaletteBrightText
|
---|
2546 | \value PaletteButtonText
|
---|
2547 | \value PaletteBase
|
---|
2548 | \value PaletteShadow
|
---|
2549 | \value PaletteHighlight
|
---|
2550 | \value PaletteHighlightedText
|
---|
2551 | \value PaletteLink
|
---|
2552 | \value PaletteLinkVisited
|
---|
2553 | \value X11ParentRelative (internal use only)
|
---|
2554 |
|
---|
2555 | The final three values have special meaning:
|
---|
2556 |
|
---|
2557 | \value NoBackground the widget is not cleared before paintEvent().
|
---|
2558 | If the widget's paint event always draws on all the pixels, using
|
---|
2559 | this mode can be both fast and flicker-free.
|
---|
2560 | \value FixedColor the widget is cleared to a fixed color, normally
|
---|
2561 | different from all the ones in the palette(). Set using \link
|
---|
2562 | QWidget::setPaletteBackgroundColor()
|
---|
2563 | setPaletteBackgroundColor()\endlink.
|
---|
2564 | \value FixedPixmap the widget is cleared to a fixed pixmap,
|
---|
2565 | normally different from all the ones in the palette(). Set using
|
---|
2566 | \link QWidget::setPaletteBackgroundPixmap()
|
---|
2567 | setPaletteBackgroundPixmap()\endlink.
|
---|
2568 |
|
---|
2569 | Although \c FixedColor and \c FixedPixmap are sometimes just
|
---|
2570 | right, if you use them, make sure that you test your application
|
---|
2571 | when the desktop color scheme has been changed. (On X11, a quick
|
---|
2572 | way to test this is e.g. "./myapp -bg paleblue". On Windows, you
|
---|
2573 | must use the control panel.)
|
---|
2574 |
|
---|
2575 | \sa QWidget::setBackgroundMode() QWidget::backgroundMode()
|
---|
2576 | QWidget::setBackgroundPixmap() QWidget::setPaletteBackgroundColor()
|
---|
2577 | */
|
---|
2578 |
|
---|
2579 | /*!
|
---|
2580 | \property QWidget::backgroundMode
|
---|
2581 | \brief the color role used for painting the background of the widget
|
---|
2582 |
|
---|
2583 | setPaletteBackgroundColor() reads this property to determine which
|
---|
2584 | entry of the \link QWidget::palette palette\endlink to set.
|
---|
2585 |
|
---|
2586 | For most widgets the default suffices (\c PaletteBackground,
|
---|
2587 | typically gray), but some need to use \c PaletteBase (the
|
---|
2588 | background color for text output, typically white) or another
|
---|
2589 | role.
|
---|
2590 |
|
---|
2591 | QListBox, which is "sunken" and uses the base color to contrast
|
---|
2592 | with its environment, does this in its constructor:
|
---|
2593 |
|
---|
2594 | \code
|
---|
2595 | setBackgroundMode( PaletteBase );
|
---|
2596 | \endcode
|
---|
2597 |
|
---|
2598 | You will never need to set the background mode of a built-in
|
---|
2599 | widget in Qt, but you might consider setting it in your custom
|
---|
2600 | widgets, so that setPaletteBackgroundColor() works as expected.
|
---|
2601 |
|
---|
2602 | Note that two of the BackgroundMode values make no sense for
|
---|
2603 | setBackgroundMode(), namely \c FixedPixmap and \c FixedColor. You
|
---|
2604 | must call setBackgroundPixmap() and setPaletteBackgroundColor()
|
---|
2605 | instead.
|
---|
2606 | */
|
---|
2607 | Qt::BackgroundMode QWidget::backgroundMode() const
|
---|
2608 | {
|
---|
2609 | return extra ? (BackgroundMode) extra->bg_mode : PaletteBackground;
|
---|
2610 | }
|
---|
2611 |
|
---|
2612 | void QWidget::setBackgroundMode( BackgroundMode m )
|
---|
2613 | {
|
---|
2614 | setBackgroundMode( m, m );
|
---|
2615 | if ( (widget_state & (WState_Visible|WState_BlockUpdates)) ==
|
---|
2616 | WState_Visible )
|
---|
2617 | update();
|
---|
2618 | }
|
---|
2619 |
|
---|
2620 |
|
---|
2621 | /*!
|
---|
2622 | \overload
|
---|
2623 |
|
---|
2624 | Sets the widget's own background mode to \a m and the visual
|
---|
2625 | background mode to \a visual. The visual background mode is used
|
---|
2626 | with the designable properties \c backgroundColor, \c
|
---|
2627 | foregroundColor and \c backgroundPixmap.
|
---|
2628 |
|
---|
2629 | For complex controls, the logical background mode sometimes
|
---|
2630 | differs from a widget's own background mode. A spinbox for example
|
---|
2631 | has \c PaletteBackground as background mode (typically dark gray),
|
---|
2632 | while it's embedded lineedit control uses \c PaletteBase
|
---|
2633 | (typically white). Since the lineedit covers most of the visual
|
---|
2634 | area of a spinbox, it defines \c PaletteBase to be its \a visual
|
---|
2635 | background mode. Changing the \c backgroundColor property thus
|
---|
2636 | changes the lineedit control's background, which is exactly what
|
---|
2637 | the user expects in \e{Qt Designer}.
|
---|
2638 | */
|
---|
2639 | void QWidget::setBackgroundMode( BackgroundMode m, BackgroundMode visual )
|
---|
2640 | {
|
---|
2641 | if ( m == NoBackground ) {
|
---|
2642 | setBackgroundEmpty();
|
---|
2643 | } else if ( m == FixedColor || m == FixedPixmap ) {
|
---|
2644 | #if defined(QT_DEBUG)
|
---|
2645 | qWarning( "QWidget::setBackgroundMode: FixedColor or FixedPixmap makes"
|
---|
2646 | " no sense" );
|
---|
2647 | #endif
|
---|
2648 | return;
|
---|
2649 | }
|
---|
2650 | setBackgroundModeDirect(m);
|
---|
2651 | if ( m != visual && !extra )
|
---|
2652 | createExtra();
|
---|
2653 | if ( extra )
|
---|
2654 | extra->bg_mode_visual = visual;
|
---|
2655 | }
|
---|
2656 |
|
---|
2657 |
|
---|
2658 | /*!
|
---|
2659 | \internal
|
---|
2660 | */
|
---|
2661 | void QWidget::setBackgroundModeDirect( BackgroundMode m )
|
---|
2662 | {
|
---|
2663 | if ( m == PaletteBackground && !extra )
|
---|
2664 | return;
|
---|
2665 |
|
---|
2666 | createExtra();
|
---|
2667 | if ( (BackgroundMode)extra->bg_mode != m ) {
|
---|
2668 | extra->bg_mode = m;
|
---|
2669 | extra->bg_mode_visual = m;
|
---|
2670 | setBackgroundFromMode();
|
---|
2671 | }
|
---|
2672 | }
|
---|
2673 |
|
---|
2674 | /*!
|
---|
2675 | \property QWidget::paletteBackgroundColor
|
---|
2676 | \brief the background color of the widget
|
---|
2677 |
|
---|
2678 | The palette background color is usually set implicitly by
|
---|
2679 | setBackgroundMode(), although it can also be set explicitly by
|
---|
2680 | setPaletteBackgroundColor(). setPaletteBackgroundColor() is a
|
---|
2681 | convenience function that creates and sets a modified QPalette
|
---|
2682 | with setPalette(). The palette is modified according to the
|
---|
2683 | widget's background mode. For example, if the background mode is
|
---|
2684 | \c PaletteButton the color used for the palette's \c
|
---|
2685 | QColorGroup::Button color entry is set.
|
---|
2686 |
|
---|
2687 | If there is a background pixmap (set using
|
---|
2688 | setPaletteBackgroundPixmap()), then the return value of this
|
---|
2689 | function is indeterminate.
|
---|
2690 |
|
---|
2691 | \sa paletteBackgroundPixmap, paletteForegroundColor, palette, colorGroup()
|
---|
2692 | */
|
---|
2693 | const QColor & QWidget::paletteBackgroundColor() const
|
---|
2694 | {
|
---|
2695 | #ifndef QT_NO_PALETTE
|
---|
2696 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
---|
2697 | switch( mode ) {
|
---|
2698 | case FixedColor:
|
---|
2699 | case FixedPixmap :
|
---|
2700 | case NoBackground:
|
---|
2701 | case X11ParentRelative:
|
---|
2702 | return eraseColor();
|
---|
2703 | default:
|
---|
2704 | QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
|
---|
2705 | return colorGroup().color( role );
|
---|
2706 | }
|
---|
2707 | #else
|
---|
2708 | return eraseColor();
|
---|
2709 | #endif
|
---|
2710 | }
|
---|
2711 |
|
---|
2712 | void QWidget::setPaletteBackgroundColor( const QColor &color )
|
---|
2713 | {
|
---|
2714 | #ifndef QT_NO_PALETTE
|
---|
2715 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
---|
2716 | switch( mode ) {
|
---|
2717 | case FixedColor:
|
---|
2718 | case FixedPixmap :
|
---|
2719 | case NoBackground:
|
---|
2720 | case X11ParentRelative:
|
---|
2721 | setEraseColor( color );
|
---|
2722 | break;
|
---|
2723 | default:
|
---|
2724 | QPalette pal = palette();
|
---|
2725 | QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
|
---|
2726 | pal.setColor( QPalette::Active, role, color );
|
---|
2727 | pal.setColor( QPalette::Inactive, role, color );
|
---|
2728 | pal.setColor( QPalette::Disabled, role, color );
|
---|
2729 | setPalette( pal );
|
---|
2730 | break;
|
---|
2731 | }
|
---|
2732 | #else
|
---|
2733 | setEraseColor( color );
|
---|
2734 | #endif
|
---|
2735 | }
|
---|
2736 |
|
---|
2737 |
|
---|
2738 | /*!
|
---|
2739 | \property QWidget::paletteBackgroundPixmap
|
---|
2740 | \brief the background pixmap of the widget
|
---|
2741 |
|
---|
2742 | The palette background pixmap is usually set implicitly by
|
---|
2743 | setBackgroundMode(), although it can also be set explicitly by
|
---|
2744 | setPaletteBackgroundPixmap(). setPaletteBackgroundPixmap() is a
|
---|
2745 | convenience function that creates and sets a modified QPalette
|
---|
2746 | with setPalette(). The palette is modified according to the
|
---|
2747 | widget's background mode. For example, if the background mode is
|
---|
2748 | \c PaletteButton the pixmap used for the palette's
|
---|
2749 | \c QColorGroup::Button color entry is set.
|
---|
2750 |
|
---|
2751 | If there is a plain background color (set using
|
---|
2752 | setPaletteBackgroundColor()), then this function returns 0.
|
---|
2753 |
|
---|
2754 | \sa paletteBackgroundColor, paletteForegroundColor, palette, colorGroup()
|
---|
2755 | */
|
---|
2756 | const QPixmap *QWidget::paletteBackgroundPixmap() const
|
---|
2757 | {
|
---|
2758 | #ifndef QT_NO_PALETTE
|
---|
2759 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
---|
2760 | switch( mode ) {
|
---|
2761 | case FixedColor:
|
---|
2762 | case FixedPixmap :
|
---|
2763 | case NoBackground:
|
---|
2764 | case X11ParentRelative:
|
---|
2765 | return erasePixmap();
|
---|
2766 | default:
|
---|
2767 | QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
|
---|
2768 | return palette().brush( QPalette::Active, role ).pixmap();
|
---|
2769 | }
|
---|
2770 | #else
|
---|
2771 | return erasePixmap();
|
---|
2772 | #endif
|
---|
2773 | }
|
---|
2774 |
|
---|
2775 | void QWidget::setPaletteBackgroundPixmap( const QPixmap &pixmap )
|
---|
2776 | {
|
---|
2777 | #ifndef QT_NO_PALETTE
|
---|
2778 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
---|
2779 | switch( mode ) {
|
---|
2780 | case FixedColor:
|
---|
2781 | case FixedPixmap :
|
---|
2782 | case NoBackground:
|
---|
2783 | case X11ParentRelative:
|
---|
2784 | setErasePixmap( pixmap );
|
---|
2785 | break;
|
---|
2786 | default:
|
---|
2787 | QPalette pal = palette();
|
---|
2788 | QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
|
---|
2789 | pal.setBrush( QPalette::Active, role, QBrush( pal.color( QPalette::Active, role ), pixmap ) );
|
---|
2790 | pal.setBrush( QPalette::Inactive, role, QBrush( pal.color( QPalette::Inactive, role ), pixmap ) );
|
---|
2791 | pal.setBrush( QPalette::Disabled, role, QBrush( pal.color( QPalette::Disabled, role ), pixmap ) );
|
---|
2792 | setPalette( pal );
|
---|
2793 | break;
|
---|
2794 | }
|
---|
2795 | #else
|
---|
2796 | setErasePixmap( pixmap );
|
---|
2797 | #endif
|
---|
2798 | }
|
---|
2799 |
|
---|
2800 |
|
---|
2801 | /*!
|
---|
2802 | \property QWidget::backgroundBrush
|
---|
2803 | \brief the widget's background brush
|
---|
2804 |
|
---|
2805 | The background brush depends on a widget's palette and its
|
---|
2806 | background mode.
|
---|
2807 |
|
---|
2808 | \sa backgroundColor(), backgroundPixmap(), eraseColor(), palette,
|
---|
2809 | QApplication::setPalette()
|
---|
2810 | */
|
---|
2811 | const QBrush& QWidget::backgroundBrush() const
|
---|
2812 | {
|
---|
2813 | static QBrush noBrush;
|
---|
2814 | #ifndef QT_NO_PALETTE
|
---|
2815 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
---|
2816 | switch( mode ) {
|
---|
2817 | case FixedColor:
|
---|
2818 | case FixedPixmap :
|
---|
2819 | case NoBackground:
|
---|
2820 | case X11ParentRelative:
|
---|
2821 | return noBrush;
|
---|
2822 | default:
|
---|
2823 | QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
|
---|
2824 | return colorGroup().brush( role );
|
---|
2825 | }
|
---|
2826 | #else
|
---|
2827 | return noBrush;
|
---|
2828 | #endif
|
---|
2829 | }
|
---|
2830 |
|
---|
2831 |
|
---|
2832 | /*!
|
---|
2833 | \property QWidget::colorGroup
|
---|
2834 | \brief the current color group of the widget palette
|
---|
2835 |
|
---|
2836 | The color group is determined by the state of the widget. A
|
---|
2837 | disabled widget has the QPalette::disabled() color group, a widget
|
---|
2838 | with keyboard focus has the QPalette::active() color group, and an
|
---|
2839 | inactive widget has the QPalette::inactive() color group.
|
---|
2840 |
|
---|
2841 | \sa palette
|
---|
2842 | */
|
---|
2843 | #ifndef QT_NO_PALETTE
|
---|
2844 | const QColorGroup &QWidget::colorGroup() const
|
---|
2845 | {
|
---|
2846 | if ( !isEnabled() )
|
---|
2847 | return palette().disabled();
|
---|
2848 | else if ( !isVisible() || isActiveWindow() )
|
---|
2849 | return palette().active();
|
---|
2850 | else
|
---|
2851 | return palette().inactive();
|
---|
2852 | }
|
---|
2853 | #endif
|
---|
2854 |
|
---|
2855 | /*!
|
---|
2856 | \property QWidget::palette
|
---|
2857 | \brief the widget's palette
|
---|
2858 |
|
---|
2859 | As long as no special palette has been set, or after unsetPalette()
|
---|
2860 | has been called, this is either a special palette for the widget
|
---|
2861 | class, the parent's palette or (if this widget is a top level
|
---|
2862 | widget), the default application palette.
|
---|
2863 |
|
---|
2864 | Instead of defining an entirely new palette, you can also use the
|
---|
2865 | \link QWidget::paletteBackgroundColor paletteBackgroundColor\endlink,
|
---|
2866 | \link QWidget::paletteBackgroundPixmap paletteBackgroundPixmap\endlink and
|
---|
2867 | \link QWidget::paletteForegroundColor paletteForegroundColor\endlink
|
---|
2868 | convenience properties to change a widget's
|
---|
2869 | background and foreground appearance only.
|
---|
2870 |
|
---|
2871 | \sa ownPalette, colorGroup(), QApplication::palette()
|
---|
2872 | */
|
---|
2873 |
|
---|
2874 | #ifndef QT_NO_PALETTE
|
---|
2875 | void QWidget::setPalette( const QPalette &palette )
|
---|
2876 | {
|
---|
2877 | own_palette = TRUE;
|
---|
2878 | if ( pal == palette )
|
---|
2879 | return;
|
---|
2880 | QPalette old = pal;
|
---|
2881 | pal = palette;
|
---|
2882 | setBackgroundFromMode();
|
---|
2883 | QEvent ev( QEvent::PaletteChange );
|
---|
2884 | QApplication::sendEvent( this, &ev );
|
---|
2885 | if ( children() ) {
|
---|
2886 | QEvent e( QEvent::ParentPaletteChange );
|
---|
2887 | QObjectListIt it( *children() );
|
---|
2888 | QWidget *w;
|
---|
2889 | while( (w=(QWidget *)it.current()) != 0 ) {
|
---|
2890 | ++it;
|
---|
2891 | if ( w->isWidgetType() )
|
---|
2892 | QApplication::sendEvent( w, &e );
|
---|
2893 | }
|
---|
2894 | }
|
---|
2895 | paletteChange( old );
|
---|
2896 | update();
|
---|
2897 | }
|
---|
2898 |
|
---|
2899 | void QWidget::unsetPalette()
|
---|
2900 | {
|
---|
2901 | // reset the palette
|
---|
2902 | setPalette( qt_naturalWidgetPalette( this ) );
|
---|
2903 | own_palette = FALSE;
|
---|
2904 | }
|
---|
2905 |
|
---|
2906 | /*!
|
---|
2907 | \fn void QWidget::setPalette( const QPalette&, bool )
|
---|
2908 | \obsolete
|
---|
2909 |
|
---|
2910 | Use setPalette( const QPalette& p ) instead.
|
---|
2911 | */
|
---|
2912 |
|
---|
2913 | /*!
|
---|
2914 | \fn void QWidget::paletteChange( const QPalette &oldPalette )
|
---|
2915 |
|
---|
2916 | This virtual function is called from setPalette(). \a oldPalette
|
---|
2917 | is the previous palette; you can get the new palette from
|
---|
2918 | palette().
|
---|
2919 |
|
---|
2920 | Reimplement this function if your widget needs to know when its
|
---|
2921 | palette changes.
|
---|
2922 |
|
---|
2923 | \sa setPalette(), palette()
|
---|
2924 | */
|
---|
2925 |
|
---|
2926 | void QWidget::paletteChange( const QPalette & )
|
---|
2927 | {
|
---|
2928 | }
|
---|
2929 | #endif // QT_NO_PALETTE
|
---|
2930 |
|
---|
2931 | /*!
|
---|
2932 | \property QWidget::font
|
---|
2933 | \brief the font currently set for the widget
|
---|
2934 |
|
---|
2935 | The fontInfo() function reports the actual font that is being used
|
---|
2936 | by the widget.
|
---|
2937 |
|
---|
2938 | As long as no special font has been set, or after unsetFont() is
|
---|
2939 | called, this is either a special font for the widget class, the
|
---|
2940 | parent's font or (if this widget is a top level widget), the
|
---|
2941 | default application font.
|
---|
2942 |
|
---|
2943 | This code fragment sets a 12 point helvetica bold font:
|
---|
2944 | \code
|
---|
2945 | QFont f( "Helvetica", 12, QFont::Bold );
|
---|
2946 | setFont( f );
|
---|
2947 | \endcode
|
---|
2948 |
|
---|
2949 | In addition to setting the font, setFont() informs all children
|
---|
2950 | about the change.
|
---|
2951 |
|
---|
2952 | \sa fontChange() fontInfo() fontMetrics() ownFont()
|
---|
2953 | */
|
---|
2954 | void QWidget::setFont( const QFont &font )
|
---|
2955 | {
|
---|
2956 | own_font = TRUE;
|
---|
2957 | if ( fnt == font && fnt.d->mask == font.d->mask )
|
---|
2958 | return;
|
---|
2959 | QFont old = fnt;
|
---|
2960 | fnt = font.resolve( qt_naturalWidgetFont( this ) );
|
---|
2961 | #if defined(Q_WS_X11)
|
---|
2962 | // make sure the font set on this widget is associated with the correct screen
|
---|
2963 | fnt.x11SetScreen( x11Screen() );
|
---|
2964 | #endif
|
---|
2965 | if ( children() ) {
|
---|
2966 | QEvent e( QEvent::ParentFontChange );
|
---|
2967 | QObjectListIt it( *children() );
|
---|
2968 | QWidget *w;
|
---|
2969 | while( (w=(QWidget *)it.current()) != 0 ) {
|
---|
2970 | ++it;
|
---|
2971 | if ( w->isWidgetType() )
|
---|
2972 | QApplication::sendEvent( w, &e );
|
---|
2973 | }
|
---|
2974 | }
|
---|
2975 | if ( hasFocus() )
|
---|
2976 | setFontSys();
|
---|
2977 | fontChange( old );
|
---|
2978 | }
|
---|
2979 |
|
---|
2980 | void QWidget::unsetFont()
|
---|
2981 | {
|
---|
2982 | // reset the font
|
---|
2983 | setFont( qt_naturalWidgetFont( this ) );
|
---|
2984 | own_font = FALSE;
|
---|
2985 | }
|
---|
2986 |
|
---|
2987 | /*!
|
---|
2988 | \fn void QWidget::setFont( const QFont&, bool )
|
---|
2989 | \obsolete
|
---|
2990 |
|
---|
2991 | Use setFont(const QFont& font) instead.
|
---|
2992 | */
|
---|
2993 |
|
---|
2994 | /*!
|
---|
2995 | \fn void QWidget::fontChange( const QFont &oldFont )
|
---|
2996 |
|
---|
2997 | This virtual function is called from setFont(). \a oldFont is the
|
---|
2998 | previous font; you can get the new font from font().
|
---|
2999 |
|
---|
3000 | Reimplement this function if your widget needs to know when its
|
---|
3001 | font changes. You will almost certainly need to update the widget
|
---|
3002 | using update().
|
---|
3003 |
|
---|
3004 | The default implementation updates the widget including its
|
---|
3005 | geometry.
|
---|
3006 |
|
---|
3007 | \sa setFont(), font(), update(), updateGeometry()
|
---|
3008 | */
|
---|
3009 |
|
---|
3010 | void QWidget::fontChange( const QFont & )
|
---|
3011 | {
|
---|
3012 | update();
|
---|
3013 | updateGeometry();
|
---|
3014 | }
|
---|
3015 |
|
---|
3016 |
|
---|
3017 | /*!
|
---|
3018 | \fn QFontMetrics QWidget::fontMetrics() const
|
---|
3019 |
|
---|
3020 | Returns the font metrics for the widget's current font.
|
---|
3021 | Equivalent to QFontMetrics(widget->font()).
|
---|
3022 |
|
---|
3023 | \sa font(), fontInfo(), setFont()
|
---|
3024 | */
|
---|
3025 |
|
---|
3026 | /*!
|
---|
3027 | \fn QFontInfo QWidget::fontInfo() const
|
---|
3028 |
|
---|
3029 | Returns the font info for the widget's current font.
|
---|
3030 | Equivalent to QFontInto(widget->font()).
|
---|
3031 |
|
---|
3032 | \sa font(), fontMetrics(), setFont()
|
---|
3033 | */
|
---|
3034 |
|
---|
3035 |
|
---|
3036 | /*!
|
---|
3037 | \property QWidget::cursor
|
---|
3038 | \brief the cursor shape for this widget
|
---|
3039 |
|
---|
3040 | The mouse cursor will assume this shape when it's over this
|
---|
3041 | widget. See the \link Qt::CursorShape list of predefined cursor
|
---|
3042 | objects\endlink for a range of useful shapes.
|
---|
3043 |
|
---|
3044 | An editor widget might use an I-beam cursor:
|
---|
3045 | \code
|
---|
3046 | setCursor( IbeamCursor );
|
---|
3047 | \endcode
|
---|
3048 |
|
---|
3049 | If no cursor has been set, or after a call to unsetCursor(), the
|
---|
3050 | parent's cursor is used. The function unsetCursor() has no effect
|
---|
3051 | on top-level widgets.
|
---|
3052 |
|
---|
3053 | \sa QApplication::setOverrideCursor()
|
---|
3054 | */
|
---|
3055 |
|
---|
3056 | #ifndef QT_NO_CURSOR
|
---|
3057 | const QCursor &QWidget::cursor() const
|
---|
3058 | {
|
---|
3059 | if ( testWState(WState_OwnCursor) )
|
---|
3060 | return (extra && extra->curs)
|
---|
3061 | ? *extra->curs
|
---|
3062 | : arrowCursor;
|
---|
3063 | else
|
---|
3064 | return (isTopLevel() || !parentWidget()) ? arrowCursor : parentWidget()->cursor();
|
---|
3065 | }
|
---|
3066 | #endif
|
---|
3067 | #ifndef QT_NO_WIDGET_TOPEXTRA
|
---|
3068 | /*!
|
---|
3069 | \property QWidget::caption
|
---|
3070 | \brief the window caption (title)
|
---|
3071 |
|
---|
3072 | This property only makes sense for top-level widgets. If no
|
---|
3073 | caption has been set, the caption is QString::null.
|
---|
3074 |
|
---|
3075 | \sa icon() iconText()
|
---|
3076 | */
|
---|
3077 | QString QWidget::caption() const
|
---|
3078 | {
|
---|
3079 | return extra && extra->topextra
|
---|
3080 | ? extra->topextra->caption
|
---|
3081 | : QString::null;
|
---|
3082 | }
|
---|
3083 |
|
---|
3084 | /*!
|
---|
3085 | \property QWidget::icon
|
---|
3086 | \brief the widget's icon
|
---|
3087 |
|
---|
3088 | This property only makes sense for top-level widgets. If no icon
|
---|
3089 | has been set, icon() returns 0.
|
---|
3090 |
|
---|
3091 | \sa iconText, caption,
|
---|
3092 | \link appicon.html Setting the Application Icon\endlink
|
---|
3093 | */
|
---|
3094 | const QPixmap *QWidget::icon() const
|
---|
3095 | {
|
---|
3096 | return ( extra && extra->topextra ) ? extra->topextra->icon : 0;
|
---|
3097 | }
|
---|
3098 |
|
---|
3099 | /*!
|
---|
3100 | \property QWidget::iconText
|
---|
3101 | \brief the widget's icon text
|
---|
3102 |
|
---|
3103 | This property only makes sense for top-level widgets. If no icon
|
---|
3104 | text has been set, this functions returns QString::null.
|
---|
3105 |
|
---|
3106 | \sa icon, caption
|
---|
3107 | */
|
---|
3108 |
|
---|
3109 | QString QWidget::iconText() const
|
---|
3110 | {
|
---|
3111 | return ( extra && extra->topextra ) ? extra->topextra->iconText
|
---|
3112 | : QString::null;
|
---|
3113 | }
|
---|
3114 | #endif //QT_NO_WIDGET_TOPEXTRA
|
---|
3115 |
|
---|
3116 | /*!
|
---|
3117 | \property QWidget::mouseTracking
|
---|
3118 | \brief whether mouse tracking is enabled for the widget
|
---|
3119 |
|
---|
3120 | If mouse tracking is disabled (the default), the widget only
|
---|
3121 | receives mouse move events when at least one mouse button is
|
---|
3122 | pressed while the mouse is being moved.
|
---|
3123 |
|
---|
3124 | If mouse tracking is enabled, the widget receives mouse move
|
---|
3125 | events even if no buttons are pressed.
|
---|
3126 |
|
---|
3127 | \sa mouseMoveEvent(), QApplication::setGlobalMouseTracking()
|
---|
3128 | */
|
---|
3129 |
|
---|
3130 |
|
---|
3131 | /*!
|
---|
3132 | Sets the widget's focus proxy to widget \a w. If \a w is 0, the
|
---|
3133 | function resets this widget to have no focus proxy.
|
---|
3134 |
|
---|
3135 | Some widgets, such as QComboBox, can "have focus", but create a
|
---|
3136 | child widget to actually handle the focus. QComboBox, for example,
|
---|
3137 | creates a QLineEdit which handles the focus.
|
---|
3138 |
|
---|
3139 | setFocusProxy() sets the widget which will actually get focus when
|
---|
3140 | "this widget" gets it. If there is a focus proxy, focusPolicy(),
|
---|
3141 | setFocusPolicy(), setFocus() and hasFocus() all operate on the
|
---|
3142 | focus proxy.
|
---|
3143 |
|
---|
3144 | \sa focusProxy()
|
---|
3145 | */
|
---|
3146 |
|
---|
3147 | void QWidget::setFocusProxy( QWidget * w )
|
---|
3148 | {
|
---|
3149 | if ( !w && !extra )
|
---|
3150 | return;
|
---|
3151 |
|
---|
3152 | for ( QWidget* fp = w; fp; fp = fp->focusProxy() ) {
|
---|
3153 | if ( fp == this ) {
|
---|
3154 | #if defined (QT_CHECK_STATE)
|
---|
3155 | qWarning( "%s (%s): already in focus proxy chain", className(), name() );
|
---|
3156 | #endif
|
---|
3157 | return;
|
---|
3158 | }
|
---|
3159 | }
|
---|
3160 |
|
---|
3161 | createExtra();
|
---|
3162 |
|
---|
3163 | if ( extra->focus_proxy ) {
|
---|
3164 | disconnect( extra->focus_proxy, SIGNAL(destroyed()),
|
---|
3165 | this, SLOT(focusProxyDestroyed()) );
|
---|
3166 | extra->focus_proxy = 0;
|
---|
3167 | }
|
---|
3168 |
|
---|
3169 | if ( w ) {
|
---|
3170 | setFocusPolicy( w->focusPolicy() );
|
---|
3171 | connect( w, SIGNAL(destroyed()),
|
---|
3172 | this, SLOT(focusProxyDestroyed()) );
|
---|
3173 | }
|
---|
3174 | extra->focus_proxy = w;
|
---|
3175 | }
|
---|
3176 |
|
---|
3177 |
|
---|
3178 | /*!
|
---|
3179 | Returns the focus proxy, or 0 if there is no focus proxy.
|
---|
3180 |
|
---|
3181 | \sa setFocusProxy()
|
---|
3182 | */
|
---|
3183 |
|
---|
3184 | QWidget * QWidget::focusProxy() const
|
---|
3185 | {
|
---|
3186 | return extra ? extra->focus_proxy : 0;
|
---|
3187 | }
|
---|
3188 |
|
---|
3189 |
|
---|
3190 | /*!
|
---|
3191 | \internal
|
---|
3192 |
|
---|
3193 | Internal slot used to clean up if the focus proxy is destroyed.
|
---|
3194 |
|
---|
3195 | \sa setFocusProxy()
|
---|
3196 | */
|
---|
3197 |
|
---|
3198 | void QWidget::focusProxyDestroyed()
|
---|
3199 | {
|
---|
3200 | if ( extra )
|
---|
3201 | extra->focus_proxy = 0;
|
---|
3202 | setFocusPolicy( NoFocus );
|
---|
3203 | }
|
---|
3204 |
|
---|
3205 | /*!
|
---|
3206 | \property QWidget::focus
|
---|
3207 | \brief whether this widget (or its focus proxy) has the keyboard
|
---|
3208 | input focus
|
---|
3209 |
|
---|
3210 | Effectively equivalent to \c {qApp->focusWidget() == this}.
|
---|
3211 |
|
---|
3212 | \sa setFocus(), clearFocus(), setFocusPolicy(), QApplication::focusWidget()
|
---|
3213 | */
|
---|
3214 | bool QWidget::hasFocus() const
|
---|
3215 | {
|
---|
3216 | const QWidget* w = this;
|
---|
3217 | while ( w->focusProxy() )
|
---|
3218 | w = w->focusProxy();
|
---|
3219 | return qApp->focusWidget() == w;
|
---|
3220 | }
|
---|
3221 |
|
---|
3222 | /*!
|
---|
3223 | Gives the keyboard input focus to this widget (or its focus
|
---|
3224 | proxy) if this widget or one of its parents is the \link
|
---|
3225 | isActiveWindow() active window\endlink.
|
---|
3226 |
|
---|
3227 | First, a focus out event is sent to the focus widget (if any) to
|
---|
3228 | tell it that it is about to lose the focus. Then a focus in event
|
---|
3229 | is sent to this widget to tell it that it just received the focus.
|
---|
3230 | (Nothing happens if the focus in and focus out widgets are the
|
---|
3231 | same.)
|
---|
3232 |
|
---|
3233 | setFocus() gives focus to a widget regardless of its focus policy,
|
---|
3234 | but does not clear any keyboard grab (see grabKeyboard()).
|
---|
3235 |
|
---|
3236 | Be aware that if the widget is hidden, it will not accept focus.
|
---|
3237 |
|
---|
3238 | \warning If you call setFocus() in a function which may itself be
|
---|
3239 | called from focusOutEvent() or focusInEvent(), you may get an
|
---|
3240 | infinite recursion.
|
---|
3241 |
|
---|
3242 | \sa hasFocus() clearFocus() focusInEvent() focusOutEvent()
|
---|
3243 | setFocusPolicy() QApplication::focusWidget() grabKeyboard()
|
---|
3244 | grabMouse()
|
---|
3245 | */
|
---|
3246 |
|
---|
3247 | void QWidget::setFocus()
|
---|
3248 | {
|
---|
3249 | if ( !isEnabled() )
|
---|
3250 | return;
|
---|
3251 |
|
---|
3252 | if ( focusProxy() ) {
|
---|
3253 | focusProxy()->setFocus();
|
---|
3254 | return;
|
---|
3255 | }
|
---|
3256 |
|
---|
3257 | QFocusData * f = focusData( TRUE );
|
---|
3258 | if ( f->it.current() == this && qApp->focusWidget() == this
|
---|
3259 | #if defined(Q_WS_WIN)
|
---|
3260 | && GetFocus() == winId()
|
---|
3261 | #endif
|
---|
3262 | )
|
---|
3263 | return;
|
---|
3264 |
|
---|
3265 | f->it.toFirst();
|
---|
3266 | while ( f->it.current() != this && !f->it.atLast() )
|
---|
3267 | ++f->it;
|
---|
3268 | // at this point, the iterator should point to 'this'. if it
|
---|
3269 | // does not, 'this' must not be in the list - an error, but
|
---|
3270 | // perhaps possible. fix it.
|
---|
3271 | if ( f->it.current() != this ) {
|
---|
3272 | f->focusWidgets.append( this );
|
---|
3273 | f->it.toLast();
|
---|
3274 | }
|
---|
3275 |
|
---|
3276 | if ( isActiveWindow() ) {
|
---|
3277 | QWidget * prev = qApp->focus_widget;
|
---|
3278 | if ( prev ) {
|
---|
3279 | if ( prev != this )
|
---|
3280 | prev->resetInputContext();
|
---|
3281 | }
|
---|
3282 | #if defined(Q_WS_WIN)
|
---|
3283 | else {
|
---|
3284 | QInputContext::endComposition();
|
---|
3285 | }
|
---|
3286 | #endif
|
---|
3287 | qApp->focus_widget = this;
|
---|
3288 | #if defined(Q_WS_X11)
|
---|
3289 | focusInputContext();
|
---|
3290 | #endif
|
---|
3291 |
|
---|
3292 | #if defined(Q_WS_WIN)
|
---|
3293 | if ( !topLevelWidget()->isPopup() )
|
---|
3294 | SetFocus( winId() );
|
---|
3295 | else {
|
---|
3296 | #endif
|
---|
3297 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
---|
3298 | QAccessible::updateAccessibility( this, 0, QAccessible::Focus );
|
---|
3299 | #endif
|
---|
3300 | #if defined(Q_WS_WIN)
|
---|
3301 | }
|
---|
3302 | #endif
|
---|
3303 |
|
---|
3304 | if ( prev != this ) {
|
---|
3305 | if ( prev ) {
|
---|
3306 | QFocusEvent out( QEvent::FocusOut );
|
---|
3307 | QApplication::sendEvent( prev, &out );
|
---|
3308 | }
|
---|
3309 |
|
---|
3310 | if ( qApp->focus_widget == this ) {
|
---|
3311 | QFocusEvent in( QEvent::FocusIn );
|
---|
3312 | QApplication::sendEvent( this, &in );
|
---|
3313 | }
|
---|
3314 | }
|
---|
3315 | }
|
---|
3316 | }
|
---|
3317 |
|
---|
3318 | /*!
|
---|
3319 | Takes keyboard input focus from the widget.
|
---|
3320 |
|
---|
3321 | If the widget has active focus, a \link focusOutEvent() focus out
|
---|
3322 | event\endlink is sent to this widget to tell it that it is about
|
---|
3323 | to lose the focus.
|
---|
3324 |
|
---|
3325 | This widget must enable focus setting in order to get the keyboard
|
---|
3326 | input focus, i.e. it must call setFocusPolicy().
|
---|
3327 |
|
---|
3328 | \sa hasFocus(), setFocus(), focusInEvent(), focusOutEvent(),
|
---|
3329 | setFocusPolicy(), QApplication::focusWidget()
|
---|
3330 | */
|
---|
3331 |
|
---|
3332 | void QWidget::clearFocus()
|
---|
3333 | {
|
---|
3334 | if ( focusProxy() ) {
|
---|
3335 | focusProxy()->clearFocus();
|
---|
3336 | return;
|
---|
3337 | } else if ( hasFocus() ) {
|
---|
3338 | QWidget* w = qApp->focusWidget();
|
---|
3339 | // clear active focus
|
---|
3340 | qApp->focus_widget = 0;
|
---|
3341 | QFocusEvent out( QEvent::FocusOut );
|
---|
3342 | QApplication::sendEvent( w, &out );
|
---|
3343 | #if defined(Q_WS_WIN)
|
---|
3344 | if ( !isPopup() && GetFocus() == winId() )
|
---|
3345 | SetFocus( 0 );
|
---|
3346 | else {
|
---|
3347 | #endif
|
---|
3348 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
---|
3349 | QAccessible::updateAccessibility( this, 0, QAccessible::Focus );
|
---|
3350 | #endif
|
---|
3351 | #if defined(Q_WS_WIN)
|
---|
3352 | }
|
---|
3353 | #endif
|
---|
3354 | }
|
---|
3355 | }
|
---|
3356 |
|
---|
3357 |
|
---|
3358 | /*!
|
---|
3359 | Finds a new widget to give the keyboard focus to, as appropriate
|
---|
3360 | for Tab and Shift+Tab, and returns TRUE if is can find a new
|
---|
3361 | widget and FALSE if it can't,
|
---|
3362 |
|
---|
3363 | If \a next is TRUE, this function searches "forwards", if \a next
|
---|
3364 | is FALSE, it searches "backwards".
|
---|
3365 |
|
---|
3366 | Sometimes, you will want to reimplement this function. For
|
---|
3367 | example, a web browser might reimplement it to move its "current
|
---|
3368 | active link" forwards or backwards, and call
|
---|
3369 | QWidget::focusNextPrevChild() only when it reaches the last or
|
---|
3370 | first link on the "page".
|
---|
3371 |
|
---|
3372 | Child widgets call focusNextPrevChild() on their parent widgets,
|
---|
3373 | but only the top-level widget decides where to redirect focus. By
|
---|
3374 | overriding this method for an object, you thus gain control of
|
---|
3375 | focus traversal for all child widgets.
|
---|
3376 |
|
---|
3377 | \warning QScrollView uses it own logic for this function, which
|
---|
3378 | does the right thing in most cases. But if you are using a
|
---|
3379 | QScrollView and want complete control of the focus chain you'll
|
---|
3380 | need to override QScrollView::focusNextPrevChild() and your
|
---|
3381 | top-level widgets' focusNextPrevChild() functions.
|
---|
3382 |
|
---|
3383 | \sa focusData()
|
---|
3384 | */
|
---|
3385 |
|
---|
3386 | bool QWidget::focusNextPrevChild( bool next )
|
---|
3387 | {
|
---|
3388 | QWidget* p = parentWidget();
|
---|
3389 | if ( !isTopLevel() && p )
|
---|
3390 | return p->focusNextPrevChild(next);
|
---|
3391 |
|
---|
3392 | QFocusData *f = focusData( TRUE );
|
---|
3393 |
|
---|
3394 | QWidget *startingPoint = f->it.current();
|
---|
3395 | QWidget *candidate = 0;
|
---|
3396 | QWidget *w = next ? f->focusWidgets.last() : f->focusWidgets.first();
|
---|
3397 | extern bool qt_tab_all_widgets;
|
---|
3398 | uint focus_flag = qt_tab_all_widgets ? TabFocus : StrongFocus;
|
---|
3399 | do {
|
---|
3400 | if ( w && w != startingPoint &&
|
---|
3401 | ( ( w->focusPolicy() & focus_flag ) == focus_flag )
|
---|
3402 | && !w->focusProxy() && w->isVisibleTo(this) && w->isEnabled())
|
---|
3403 | candidate = w;
|
---|
3404 | w = next ? f->focusWidgets.prev() : f->focusWidgets.next();
|
---|
3405 | } while( w && !(candidate && w==startingPoint) );
|
---|
3406 |
|
---|
3407 | if ( !candidate )
|
---|
3408 | return FALSE;
|
---|
3409 |
|
---|
3410 | candidate->setFocus();
|
---|
3411 | return TRUE;
|
---|
3412 | }
|
---|
3413 |
|
---|
3414 | /*!
|
---|
3415 | Returns the focus widget in this widget's window. This is not the
|
---|
3416 | same as QApplication::focusWidget(), which returns the focus
|
---|
3417 | widget in the currently active window.
|
---|
3418 | */
|
---|
3419 |
|
---|
3420 | QWidget *QWidget::focusWidget() const
|
---|
3421 | {
|
---|
3422 | QWidget *that = (QWidget *)this; // mutable
|
---|
3423 | QFocusData *f = that->focusData( FALSE );
|
---|
3424 | if ( f && f->focusWidgets.count() && f->it.current() == 0 )
|
---|
3425 | f->it.toFirst();
|
---|
3426 | return ( f && f->it.current() ) ? f->it.current() : 0;
|
---|
3427 | }
|
---|
3428 |
|
---|
3429 |
|
---|
3430 | /*!
|
---|
3431 | Returns the focus data for this widget's top-level widget.
|
---|
3432 |
|
---|
3433 | Focus data always belongs to the top-level widget. The focus data
|
---|
3434 | list contains all the widgets in this top-level widget that can
|
---|
3435 | accept focus, in tab order. An iterator points to the current
|
---|
3436 | focus widget (focusWidget() returns a pointer to this widget).
|
---|
3437 |
|
---|
3438 | This information is useful for implementing advanced versions of
|
---|
3439 | focusNextPrevChild().
|
---|
3440 | */
|
---|
3441 | QFocusData * QWidget::focusData()
|
---|
3442 | {
|
---|
3443 | return focusData( TRUE );
|
---|
3444 | }
|
---|
3445 |
|
---|
3446 | /*!
|
---|
3447 | \internal
|
---|
3448 |
|
---|
3449 | Internal function which lets us ask for the focus data, creating
|
---|
3450 | it if it doesn't exist and \a create is TRUE.
|
---|
3451 | */
|
---|
3452 | QFocusData * QWidget::focusData( bool create )
|
---|
3453 | {
|
---|
3454 | QWidget * tlw = topLevelWidget();
|
---|
3455 | QWExtra * ed = tlw->extraData();
|
---|
3456 | if ( !ed || !ed->topextra ) {
|
---|
3457 | if ( !create )
|
---|
3458 | return 0;
|
---|
3459 | tlw->createTLExtra();
|
---|
3460 | ed = tlw->extraData();
|
---|
3461 | }
|
---|
3462 | if ( create && !ed->topextra->focusData )
|
---|
3463 | ed->topextra->focusData = new QFocusData;
|
---|
3464 |
|
---|
3465 | return ed->topextra->focusData;
|
---|
3466 | }
|
---|
3467 |
|
---|
3468 | /*!
|
---|
3469 | \property QWidget::inputMethodEnabled
|
---|
3470 | \brief enables or disables the use of input methods for this widget.
|
---|
3471 |
|
---|
3472 | Most Widgets (as eg. buttons) that do not handle text input should have
|
---|
3473 | the input method disabled if they have focus. This is the default.
|
---|
3474 |
|
---|
3475 | If a widget handles text input it should set this property to TRUE.
|
---|
3476 | */
|
---|
3477 |
|
---|
3478 | void QWidget::setInputMethodEnabled( bool b )
|
---|
3479 | {
|
---|
3480 | im_enabled = b;
|
---|
3481 | #ifdef Q_WS_WIN
|
---|
3482 | QInputContext::enable( this, im_enabled & !((bool)testWState(WState_Disabled)) );
|
---|
3483 | #endif
|
---|
3484 | }
|
---|
3485 |
|
---|
3486 |
|
---|
3487 | /*!
|
---|
3488 | Enables key event compression, if \a compress is TRUE, and
|
---|
3489 | disables it if \a compress is FALSE.
|
---|
3490 |
|
---|
3491 | Key compression is off by default (except for QLineEdit), so
|
---|
3492 | widgets receive one key press event for each key press (or more,
|
---|
3493 | since autorepeat is usually on). If you turn it on and your
|
---|
3494 | program doesn't keep up with key input, Qt may try to compress key
|
---|
3495 | events so that more than one character can be processed in each
|
---|
3496 | event.
|
---|
3497 |
|
---|
3498 | For example, a word processor widget might receive 2, 3 or more
|
---|
3499 | characters in each QKeyEvent::text(), if the layout recalculation
|
---|
3500 | takes too long for the CPU.
|
---|
3501 |
|
---|
3502 | If a widget supports multiple character unicode input, it is
|
---|
3503 | always safe to turn the compression on.
|
---|
3504 |
|
---|
3505 | Qt performs key event compression only for printable characters.
|
---|
3506 | Modifier keys, cursor movement keys, function keys and
|
---|
3507 | miscellaneous action keys (e.g. Escape, Enter, Backspace,
|
---|
3508 | PrintScreen) will stop key event compression, even if there are
|
---|
3509 | more compressible key events available.
|
---|
3510 |
|
---|
3511 | Not all platforms support this compression, in which case turning
|
---|
3512 | it on will have no effect.
|
---|
3513 |
|
---|
3514 | \sa QKeyEvent::text();
|
---|
3515 | */
|
---|
3516 |
|
---|
3517 | void QWidget::setKeyCompression(bool compress)
|
---|
3518 | {
|
---|
3519 | if ( compress )
|
---|
3520 | setWState( WState_CompressKeys );
|
---|
3521 | else
|
---|
3522 | clearWState( WState_CompressKeys );
|
---|
3523 | }
|
---|
3524 |
|
---|
3525 | /*!
|
---|
3526 | \property QWidget::isActiveWindow
|
---|
3527 | \brief whether this widget is the active window
|
---|
3528 |
|
---|
3529 | The active window is the window (or child of the window) that has
|
---|
3530 | keyboard focus.
|
---|
3531 |
|
---|
3532 | When popup windows are visible, this property is TRUE for both the
|
---|
3533 | active window \e and for the popup.
|
---|
3534 |
|
---|
3535 | \sa setActiveWindow(), QApplication::activeWindow()
|
---|
3536 | */
|
---|
3537 | bool QWidget::isActiveWindow() const
|
---|
3538 | {
|
---|
3539 | QWidget *tlw = topLevelWidget();
|
---|
3540 | if(testWFlags(WSubWindow) && parentWidget())
|
---|
3541 | tlw = parentWidget()->topLevelWidget();
|
---|
3542 | if(tlw == qApp->activeWindow() || ( isVisible() && tlw->isPopup() ))
|
---|
3543 | return TRUE;
|
---|
3544 | #ifndef QT_NO_STYLE
|
---|
3545 | if(style().styleHint(QStyle::SH_Widget_ShareActivation, this )) {
|
---|
3546 | if(tlw->isDialog() && !tlw->testWFlags(WShowModal) &&
|
---|
3547 | tlw->parentWidget() && tlw->parentWidget()->isActiveWindow())
|
---|
3548 | return TRUE;
|
---|
3549 | QWidget *w = qApp->activeWindow();
|
---|
3550 | if( !testWFlags(WSubWindow) && w && w->testWFlags(WSubWindow) &&
|
---|
3551 | w->parentWidget()->topLevelWidget() == tlw)
|
---|
3552 | return TRUE;
|
---|
3553 | while( w && w->isDialog() && !w->testWFlags(WShowModal) && w->parentWidget() ) {
|
---|
3554 | w = w->parentWidget()->topLevelWidget();
|
---|
3555 | if( w == tlw )
|
---|
3556 | return TRUE;
|
---|
3557 | }
|
---|
3558 | }
|
---|
3559 | #endif
|
---|
3560 | #if defined(Q_WS_WIN32)
|
---|
3561 | HWND parent = tlw->winId();
|
---|
3562 | HWND topparent = GetActiveWindow();
|
---|
3563 | while ( parent ) {
|
---|
3564 | parent = ::GetParent( parent );
|
---|
3565 | if ( parent && parent == topparent )
|
---|
3566 | return TRUE;
|
---|
3567 | }
|
---|
3568 | #endif
|
---|
3569 |
|
---|
3570 | return FALSE;
|
---|
3571 | }
|
---|
3572 |
|
---|
3573 | /*!
|
---|
3574 | Moves the \a second widget around the ring of focus widgets so
|
---|
3575 | that keyboard focus moves from the \a first widget to the \a
|
---|
3576 | second widget when the Tab key is pressed.
|
---|
3577 |
|
---|
3578 | Note that since the tab order of the \a second widget is changed,
|
---|
3579 | you should order a chain like this:
|
---|
3580 |
|
---|
3581 | \code
|
---|
3582 | setTabOrder( a, b ); // a to b
|
---|
3583 | setTabOrder( b, c ); // a to b to c
|
---|
3584 | setTabOrder( c, d ); // a to b to c to d
|
---|
3585 | \endcode
|
---|
3586 |
|
---|
3587 | \e not like this:
|
---|
3588 |
|
---|
3589 | \code
|
---|
3590 | setTabOrder( c, d ); // c to d WRONG
|
---|
3591 | setTabOrder( a, b ); // a to b AND c to d
|
---|
3592 | setTabOrder( b, c ); // a to b to c, but not c to d
|
---|
3593 | \endcode
|
---|
3594 |
|
---|
3595 | If \a first or \a second has a focus proxy, setTabOrder()
|
---|
3596 | correctly substitutes the proxy.
|
---|
3597 |
|
---|
3598 | \sa setFocusPolicy(), setFocusProxy()
|
---|
3599 | */
|
---|
3600 | void QWidget::setTabOrder( QWidget* first, QWidget *second )
|
---|
3601 | {
|
---|
3602 | if ( !first || !second ||
|
---|
3603 | first->focusPolicy() == NoFocus || second->focusPolicy() == NoFocus )
|
---|
3604 | return;
|
---|
3605 |
|
---|
3606 | // If first is redirected, set first to the last child of first
|
---|
3607 | // that can take keyboard focus so that second is inserted after
|
---|
3608 | // that last child, and the focus order within first is (more
|
---|
3609 | // likely to be) preserved.
|
---|
3610 | if ( first->focusProxy() ) {
|
---|
3611 | QObjectList *l = first->queryList( "QWidget" );
|
---|
3612 | if ( l && l->count() ) {
|
---|
3613 | QObjectListIt it(*l);
|
---|
3614 | it.toLast();
|
---|
3615 | while (it.current()) {
|
---|
3616 | if (((QWidget*)it.current())->topLevelWidget() == first->topLevelWidget()) {
|
---|
3617 | first = (QWidget*)it.current();
|
---|
3618 | if (first->focusPolicy() != NoFocus)
|
---|
3619 | break;
|
---|
3620 | }
|
---|
3621 | --it;
|
---|
3622 | }
|
---|
3623 | }
|
---|
3624 | delete l;
|
---|
3625 | }
|
---|
3626 | while ( first->focusProxy() )
|
---|
3627 | first = first->focusProxy();
|
---|
3628 | while ( second->focusProxy() )
|
---|
3629 | second = second->focusProxy();
|
---|
3630 |
|
---|
3631 | QFocusData *f = first->focusData( TRUE );
|
---|
3632 | bool focusThere = (f->it.current() == second );
|
---|
3633 | f->focusWidgets.removeRef( second );
|
---|
3634 | if ( f->focusWidgets.findRef( first ) >= 0 )
|
---|
3635 | f->focusWidgets.insert( f->focusWidgets.at() + 1, second );
|
---|
3636 | else
|
---|
3637 | f->focusWidgets.append( second );
|
---|
3638 | if ( focusThere ) { // reset iterator so tab will work appropriately
|
---|
3639 | f->it.toFirst();
|
---|
3640 | while( f->it.current() && f->it.current() != second )
|
---|
3641 | ++f->it;
|
---|
3642 | }
|
---|
3643 | }
|
---|
3644 |
|
---|
3645 | /*!\internal
|
---|
3646 |
|
---|
3647 | Moves the relevant subwidgets of this widget from the \a oldtlw's
|
---|
3648 | tab chain to that of the new parent, if there's anything to move and
|
---|
3649 | we're really moving
|
---|
3650 |
|
---|
3651 | This function is called from QWidget::reparent() *after* the widget
|
---|
3652 | has been reparented.
|
---|
3653 |
|
---|
3654 | \sa reparent()
|
---|
3655 | */
|
---|
3656 |
|
---|
3657 | void QWidget::reparentFocusWidgets( QWidget * oldtlw )
|
---|
3658 | {
|
---|
3659 | if ( oldtlw == topLevelWidget() )
|
---|
3660 | return; // nothing to do
|
---|
3661 |
|
---|
3662 | QFocusData * from = oldtlw ? oldtlw->topData()->focusData : 0;
|
---|
3663 | QFocusData * to;
|
---|
3664 | to = focusData();
|
---|
3665 |
|
---|
3666 | if ( from ) {
|
---|
3667 | from->focusWidgets.first();
|
---|
3668 | do {
|
---|
3669 | QWidget * pw = from->focusWidgets.current();
|
---|
3670 | while( pw && pw != this )
|
---|
3671 | pw = pw->parentWidget();
|
---|
3672 | if ( pw == this ) {
|
---|
3673 | QWidget * w = from->focusWidgets.take();
|
---|
3674 | if ( w == from->it.current() )
|
---|
3675 | // probably best to clear keyboard focus, or
|
---|
3676 | // the user might become rather confused
|
---|
3677 | w->clearFocus();
|
---|
3678 | if ( !isTopLevel() )
|
---|
3679 | to->focusWidgets.append( w );
|
---|
3680 | } else {
|
---|
3681 | from->focusWidgets.next();
|
---|
3682 | }
|
---|
3683 | } while( from->focusWidgets.current() );
|
---|
3684 | }
|
---|
3685 |
|
---|
3686 | if ( to->focusWidgets.findRef(this) < 0 )
|
---|
3687 | to->focusWidgets.append( this );
|
---|
3688 |
|
---|
3689 | if ( !isTopLevel() && extra && extra->topextra && extra->topextra->focusData ) {
|
---|
3690 | // this widget is no longer a top-level widget, so get rid
|
---|
3691 | // of old focus data
|
---|
3692 | delete extra->topextra->focusData;
|
---|
3693 | extra->topextra->focusData = 0;
|
---|
3694 | }
|
---|
3695 | }
|
---|
3696 |
|
---|
3697 | /*!
|
---|
3698 | \fn void QWidget::recreate( QWidget *parent, WFlags f, const QPoint & p, bool showIt )
|
---|
3699 |
|
---|
3700 | \obsolete
|
---|
3701 |
|
---|
3702 | This method is provided to aid porting from Qt 1.0 to 2.0. It has
|
---|
3703 | been renamed reparent() in Qt 2.0.
|
---|
3704 | */
|
---|
3705 |
|
---|
3706 | /*!
|
---|
3707 | \property QWidget::frameSize
|
---|
3708 | \brief the size of the widget including any window frame
|
---|
3709 | */
|
---|
3710 | QSize QWidget::frameSize() const
|
---|
3711 | {
|
---|
3712 | if ( isTopLevel() && !isPopup() ) {
|
---|
3713 | if ( fstrut_dirty )
|
---|
3714 | updateFrameStrut();
|
---|
3715 | QWidget *that = (QWidget *) this;
|
---|
3716 | QTLWExtra *top = that->topData();
|
---|
3717 | return QSize( crect.width() + top->fleft + top->fright,
|
---|
3718 | crect.height() + top->ftop + top->fbottom );
|
---|
3719 | }
|
---|
3720 | return crect.size();
|
---|
3721 | }
|
---|
3722 |
|
---|
3723 | /*!
|
---|
3724 | \internal
|
---|
3725 |
|
---|
3726 | Recursive function that updates \a widget and all its children,
|
---|
3727 | if they have some parent background origin.
|
---|
3728 | */
|
---|
3729 | static void qt_update_bg_recursive( QWidget *widget )
|
---|
3730 | {
|
---|
3731 | if ( !widget || widget->isHidden() || widget->backgroundOrigin() == QWidget::WidgetOrigin || !widget->backgroundPixmap() )
|
---|
3732 | return;
|
---|
3733 |
|
---|
3734 | const QObjectList *lst = widget->children();
|
---|
3735 |
|
---|
3736 | if ( lst ) {
|
---|
3737 | QObjectListIterator it( *lst );
|
---|
3738 | QWidget *widget;
|
---|
3739 | while ( (widget = (QWidget*)it.current()) ) {
|
---|
3740 | ++it;
|
---|
3741 | if ( widget->isWidgetType() && !widget->isHidden() && !widget->isTopLevel() && !widget->testWFlags(Qt::WSubWindow) )
|
---|
3742 | qt_update_bg_recursive( widget );
|
---|
3743 | }
|
---|
3744 | }
|
---|
3745 | QApplication::postEvent( widget, new QPaintEvent( widget->clipRegion(), !widget->testWFlags(Qt::WRepaintNoErase) ) );
|
---|
3746 | }
|
---|
3747 |
|
---|
3748 | /*!
|
---|
3749 | \overload
|
---|
3750 |
|
---|
3751 | This corresponds to move( QSize(\a x, \a y) ).
|
---|
3752 | */
|
---|
3753 |
|
---|
3754 | void QWidget::move( int x, int y )
|
---|
3755 | {
|
---|
3756 | QPoint oldp(pos());
|
---|
3757 | internalSetGeometry( x + geometry().x() - QWidget::x(),
|
---|
3758 | y + geometry().y() - QWidget::y(),
|
---|
3759 | width(), height(), TRUE );
|
---|
3760 | if ( isVisible() && oldp != pos() )
|
---|
3761 | qt_update_bg_recursive( this );
|
---|
3762 | }
|
---|
3763 |
|
---|
3764 | /*!
|
---|
3765 | \overload
|
---|
3766 |
|
---|
3767 | This corresponds to resize( QSize(\a w, \a h) ).
|
---|
3768 | */
|
---|
3769 | void QWidget::resize( int w, int h )
|
---|
3770 | {
|
---|
3771 | internalSetGeometry( geometry().x(), geometry().y(), w, h, FALSE );
|
---|
3772 | setWState( WState_Resized );
|
---|
3773 | }
|
---|
3774 |
|
---|
3775 | /*!
|
---|
3776 | \overload
|
---|
3777 |
|
---|
3778 | This corresponds to setGeometry( QRect(\a x, \a y, \a w, \a h) ).
|
---|
3779 | */
|
---|
3780 | void QWidget::setGeometry( int x, int y, int w, int h )
|
---|
3781 | {
|
---|
3782 | QPoint oldp( pos( ));
|
---|
3783 | internalSetGeometry( x, y, w, h, TRUE );
|
---|
3784 | setWState( WState_Resized );
|
---|
3785 | if ( isVisible() && oldp != pos() )
|
---|
3786 | qt_update_bg_recursive( this );
|
---|
3787 | }
|
---|
3788 |
|
---|
3789 | /*!
|
---|
3790 | \property QWidget::focusEnabled
|
---|
3791 | \brief whether the widget accepts keyboard focus
|
---|
3792 |
|
---|
3793 | Keyboard focus is initially disabled (i.e. focusPolicy() ==
|
---|
3794 | \c QWidget::NoFocus).
|
---|
3795 |
|
---|
3796 | You must enable keyboard focus for a widget if it processes
|
---|
3797 | keyboard events. This is normally done from the widget's
|
---|
3798 | constructor. For instance, the QLineEdit constructor calls
|
---|
3799 | setFocusPolicy(QWidget::StrongFocus).
|
---|
3800 |
|
---|
3801 | \sa setFocusPolicy(), focusInEvent(), focusOutEvent(), keyPressEvent(),
|
---|
3802 | keyReleaseEvent(), isEnabled()
|
---|
3803 | */
|
---|
3804 |
|
---|
3805 | /*!
|
---|
3806 | \enum QWidget::FocusPolicy
|
---|
3807 |
|
---|
3808 | This enum type defines the various policies a widget can have with
|
---|
3809 | respect to acquiring keyboard focus.
|
---|
3810 |
|
---|
3811 | \value TabFocus the widget accepts focus by tabbing.
|
---|
3812 | \value ClickFocus the widget accepts focus by clicking.
|
---|
3813 | \value StrongFocus the widget accepts focus by both tabbing
|
---|
3814 | and clicking. On Mac OS X this will also
|
---|
3815 | be indicate that the widget accepts tab focus
|
---|
3816 | when in 'Text/List focus mode'.
|
---|
3817 | \value WheelFocus like StrongFocus plus the widget accepts
|
---|
3818 | focus by using the mouse wheel.
|
---|
3819 | \value NoFocus the widget does not accept focus.
|
---|
3820 |
|
---|
3821 | */
|
---|
3822 |
|
---|
3823 | /*!
|
---|
3824 | \property QWidget::focusPolicy
|
---|
3825 | \brief the way the widget accepts keyboard focus
|
---|
3826 |
|
---|
3827 | The policy is \c QWidget::TabFocus if the widget accepts keyboard
|
---|
3828 | focus by tabbing, \c QWidget::ClickFocus if the widget accepts
|
---|
3829 | focus by clicking, \c QWidget::StrongFocus if it accepts both, and
|
---|
3830 | \c QWidget::NoFocus (the default) if it does not accept focus at
|
---|
3831 | all.
|
---|
3832 |
|
---|
3833 | You must enable keyboard focus for a widget if it processes
|
---|
3834 | keyboard events. This is normally done from the widget's
|
---|
3835 | constructor. For instance, the QLineEdit constructor calls
|
---|
3836 | setFocusPolicy(QWidget::StrongFocus).
|
---|
3837 |
|
---|
3838 | \sa focusEnabled, focusInEvent(), focusOutEvent(), keyPressEvent(),
|
---|
3839 | keyReleaseEvent(), enabled
|
---|
3840 | */
|
---|
3841 |
|
---|
3842 | void QWidget::setFocusPolicy( FocusPolicy policy )
|
---|
3843 | {
|
---|
3844 | if ( focusProxy() )
|
---|
3845 | focusProxy()->setFocusPolicy( policy );
|
---|
3846 | if ( policy != NoFocus ) {
|
---|
3847 | QFocusData * f = focusData( TRUE );
|
---|
3848 | if ( f->focusWidgets.findRef( this ) < 0 )
|
---|
3849 | f->focusWidgets.append( this );
|
---|
3850 | }
|
---|
3851 | focus_policy = (uint) policy;
|
---|
3852 | }
|
---|
3853 |
|
---|
3854 | /*!
|
---|
3855 | \property QWidget::updatesEnabled
|
---|
3856 | \brief whether updates are enabled
|
---|
3857 |
|
---|
3858 | Calling update() and repaint() has no effect if updates are
|
---|
3859 | disabled. Paint events from the window system are processed
|
---|
3860 | normally even if updates are disabled.
|
---|
3861 |
|
---|
3862 | setUpdatesEnabled() is normally used to disable updates for a
|
---|
3863 | short period of time, for instance to avoid screen flicker during
|
---|
3864 | large changes.
|
---|
3865 |
|
---|
3866 | Example:
|
---|
3867 | \code
|
---|
3868 | setUpdatesEnabled( FALSE );
|
---|
3869 | bigVisualChanges();
|
---|
3870 | setUpdatesEnabled( TRUE );
|
---|
3871 | repaint();
|
---|
3872 | \endcode
|
---|
3873 |
|
---|
3874 | \sa update(), repaint(), paintEvent()
|
---|
3875 | */
|
---|
3876 | void QWidget::setUpdatesEnabled( bool enable )
|
---|
3877 | {
|
---|
3878 | if ( enable )
|
---|
3879 | clearWState( WState_BlockUpdates );
|
---|
3880 | else
|
---|
3881 | setWState( WState_BlockUpdates );
|
---|
3882 | }
|
---|
3883 |
|
---|
3884 | /*!
|
---|
3885 | Shows the widget and its child widgets.
|
---|
3886 |
|
---|
3887 | If its size or position has changed, Qt guarantees that a widget
|
---|
3888 | gets move and resize events just before it is shown.
|
---|
3889 |
|
---|
3890 | You almost never have to reimplement this function. If you need to
|
---|
3891 | change some settings before a widget is shown, use showEvent()
|
---|
3892 | instead. If you need to do some delayed initialization use
|
---|
3893 | polish().
|
---|
3894 |
|
---|
3895 | \sa showEvent(), hide(), showMinimized(), showMaximized(),
|
---|
3896 | showNormal(), isVisible(), polish()
|
---|
3897 | */
|
---|
3898 |
|
---|
3899 | void QWidget::show()
|
---|
3900 | {
|
---|
3901 | if ( testWState(WState_Visible) )
|
---|
3902 | return;
|
---|
3903 |
|
---|
3904 | bool wasHidden = isHidden();
|
---|
3905 | bool postLayoutHint = !isTopLevel() && wasHidden;
|
---|
3906 | clearWState( WState_ForceHide | WState_CreatedHidden );
|
---|
3907 |
|
---|
3908 | if ( !isTopLevel() && !parentWidget()->isVisible() ) {
|
---|
3909 | // we should become visible, but one of our ancestors is
|
---|
3910 | // explicitly hidden. Since we cleared the ForceHide flag, our
|
---|
3911 | // immediate parent will call show() on us again during its
|
---|
3912 | // own processing of show().
|
---|
3913 | if ( wasHidden ) {
|
---|
3914 | QEvent showToParentEvent( QEvent::ShowToParent );
|
---|
3915 | QApplication::sendEvent( this, &showToParentEvent );
|
---|
3916 | }
|
---|
3917 | if ( postLayoutHint )
|
---|
3918 | QApplication::postEvent( parentWidget(),
|
---|
3919 | new QEvent(QEvent::LayoutHint) );
|
---|
3920 | return;
|
---|
3921 | }
|
---|
3922 |
|
---|
3923 | in_show = TRUE; // set qws recursion watch
|
---|
3924 |
|
---|
3925 | QApplication::sendPostedEvents( this, QEvent::ChildInserted );
|
---|
3926 |
|
---|
3927 | if ( isTopLevel() && !testWState( WState_Resized ) ) {
|
---|
3928 | // do this before sending the posted resize events. Otherwise
|
---|
3929 | // the layout would catch the resize event and may expand the
|
---|
3930 | // minimum size.
|
---|
3931 | QSize s = qt_naturalWidgetSize( this );
|
---|
3932 | bool wasMax = windowState() & WindowMaximized;
|
---|
3933 | bool wasFullScreen = windowState() & WindowFullScreen;
|
---|
3934 | if ( !s.isEmpty() )
|
---|
3935 | resize( s );
|
---|
3936 | if (wasMax)
|
---|
3937 | setWindowState(windowState() | WindowMaximized);
|
---|
3938 | if (wasFullScreen)
|
---|
3939 | setWindowState(windowState() | WindowFullScreen);
|
---|
3940 | #endif // Q_OS_TEMP
|
---|
3941 | }
|
---|
3942 |
|
---|
3943 | QApplication::sendPostedEvents( this, QEvent::Move );
|
---|
3944 | QApplication::sendPostedEvents( this, QEvent::Resize );
|
---|
3945 |
|
---|
3946 | setWState( WState_Visible );
|
---|
3947 |
|
---|
3948 | if ( parentWidget() )
|
---|
3949 | QApplication::sendPostedEvents( parentWidget(),
|
---|
3950 | QEvent::ChildInserted );
|
---|
3951 |
|
---|
3952 | if ( extra ) {
|
---|
3953 | int w = crect.width();
|
---|
3954 | int h = crect.height();
|
---|
3955 | if ( w < extra->minw || h < extra->minh ||
|
---|
3956 | w > extra->maxw || h > extra->maxh ) {
|
---|
3957 | w = QMAX( extra->minw, QMIN( w, extra->maxw ));
|
---|
3958 | h = QMAX( extra->minh, QMIN( h, extra->maxh ));
|
---|
3959 | resize( w, h ); // deferred resize
|
---|
3960 | }
|
---|
3961 | }
|
---|
3962 |
|
---|
3963 | if ( testWFlags(WStyle_Tool) || isPopup() ) {
|
---|
3964 | raise();
|
---|
3965 | } else if ( testWFlags(WType_TopLevel) ) {
|
---|
3966 | while ( QApplication::activePopupWidget() ) {
|
---|
3967 | if ( !QApplication::activePopupWidget()->close() )
|
---|
3968 | break;
|
---|
3969 | }
|
---|
3970 | }
|
---|
3971 |
|
---|
3972 | if ( !testWState(WState_Polished) )
|
---|
3973 | polish();
|
---|
3974 |
|
---|
3975 | showChildren( FALSE );
|
---|
3976 |
|
---|
3977 | if ( postLayoutHint )
|
---|
3978 | QApplication::postEvent( parentWidget(),
|
---|
3979 | new QEvent(QEvent::LayoutHint) );
|
---|
3980 |
|
---|
3981 | // Required for Mac, not sure whether we should always do that
|
---|
3982 | if( isTopLevel() )
|
---|
3983 | QApplication::sendPostedEvents(0, QEvent::LayoutHint);
|
---|
3984 |
|
---|
3985 | // On Windows, show the popup now so that our own focus handling
|
---|
3986 | // stores the correct old focus widget even if it's stolen in the showevent
|
---|
3987 | #if defined(Q_WS_WIN)
|
---|
3988 | if ( testWFlags(WType_Popup) )
|
---|
3989 | qApp->openPopup( this );
|
---|
3990 | #endif
|
---|
3991 |
|
---|
3992 | QShowEvent showEvent;
|
---|
3993 | QApplication::sendEvent( this, &showEvent );
|
---|
3994 |
|
---|
3995 | if ( testWFlags(WShowModal) ) {
|
---|
3996 | // qt_enter_modal *before* show, otherwise the initial
|
---|
3997 | // stacking might be wrong
|
---|
3998 | qt_enter_modal( this );
|
---|
3999 | }
|
---|
4000 |
|
---|
4001 | // do not show the window directly, but post a show-window request
|
---|
4002 | // to reduce flicker with widgets in layouts
|
---|
4003 | if ( postLayoutHint )
|
---|
4004 | QApplication::postEvent( this, new QEvent( QEvent::ShowWindowRequest ) );
|
---|
4005 | else
|
---|
4006 | showWindow();
|
---|
4007 |
|
---|
4008 | #if !defined(Q_WS_WIN)
|
---|
4009 | if ( testWFlags(WType_Popup) )
|
---|
4010 | qApp->openPopup( this );
|
---|
4011 | #endif
|
---|
4012 |
|
---|
4013 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
---|
4014 | QAccessible::updateAccessibility( this, 0, QAccessible::ObjectShow );
|
---|
4015 | #endif
|
---|
4016 |
|
---|
4017 | in_show = FALSE; // reset qws recursion watch
|
---|
4018 | }
|
---|
4019 |
|
---|
4020 | /*! \fn void QWidget::iconify()
|
---|
4021 | \obsolete
|
---|
4022 | */
|
---|
4023 |
|
---|
4024 | /*!
|
---|
4025 | Hides the widget.
|
---|
4026 |
|
---|
4027 | You almost never have to reimplement this function. If you need to
|
---|
4028 | do something after a widget is hidden, use hideEvent() instead.
|
---|
4029 |
|
---|
4030 | \sa hideEvent(), isHidden(), show(), showMinimized(), isVisible(), close()
|
---|
4031 | */
|
---|
4032 |
|
---|
4033 | void QWidget::hide()
|
---|
4034 | {
|
---|
4035 | clearWState( WState_CreatedHidden );
|
---|
4036 | if ( testWState(WState_ForceHide) )
|
---|
4037 | return;
|
---|
4038 |
|
---|
4039 | setWState( WState_ForceHide );
|
---|
4040 |
|
---|
4041 | if ( testWFlags(WType_Popup) )
|
---|
4042 | qApp->closePopup( this );
|
---|
4043 |
|
---|
4044 | // Move test modal here. Otherwise, a modal dialog could get
|
---|
4045 | // destroyed and we lose all access to its parent because we haven't
|
---|
4046 | // left modality. (Eg. modal Progress Dialog)
|
---|
4047 | if ( testWFlags(WShowModal) )
|
---|
4048 | qt_leave_modal( this );
|
---|
4049 |
|
---|
4050 | #if defined(Q_WS_WIN)
|
---|
4051 | if ( isTopLevel() && !isPopup() && parentWidget() && isActiveWindow() )
|
---|
4052 | parentWidget()->setActiveWindow(); // Activate parent
|
---|
4053 | #endif
|
---|
4054 |
|
---|
4055 | hideWindow();
|
---|
4056 |
|
---|
4057 | if ( testWState(WState_Visible) ) {
|
---|
4058 | clearWState( WState_Visible );
|
---|
4059 |
|
---|
4060 | // next bit tries to move the focus if the focus widget is now
|
---|
4061 | // hidden.
|
---|
4062 | if ( qApp && qApp->focusWidget() == this )
|
---|
4063 | focusNextPrevChild( TRUE );
|
---|
4064 | QHideEvent hideEvent;
|
---|
4065 | QApplication::sendEvent( this, &hideEvent );
|
---|
4066 | hideChildren( FALSE );
|
---|
4067 |
|
---|
4068 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
---|
4069 | QAccessible::updateAccessibility( this, 0, QAccessible::ObjectHide );
|
---|
4070 | #endif
|
---|
4071 | } else {
|
---|
4072 | QEvent hideToParentEvent( QEvent::HideToParent );
|
---|
4073 | QApplication::sendEvent( this, &hideToParentEvent );
|
---|
4074 | }
|
---|
4075 |
|
---|
4076 | // post layout hint for non toplevels. The parent widget check is
|
---|
4077 | // necessary since the function is called in the destructor
|
---|
4078 | if ( !isTopLevel() && parentWidget() )
|
---|
4079 | QApplication::postEvent( parentWidget(),
|
---|
4080 | new QEvent( QEvent::LayoutHint) );
|
---|
4081 | }
|
---|
4082 |
|
---|
4083 | void QWidget::setShown( bool show )
|
---|
4084 | {
|
---|
4085 | if ( show )
|
---|
4086 | this->show();
|
---|
4087 | else
|
---|
4088 | hide();
|
---|
4089 | }
|
---|
4090 |
|
---|
4091 | void QWidget::setHidden( bool hide )
|
---|
4092 | {
|
---|
4093 | if ( hide )
|
---|
4094 | this->hide();
|
---|
4095 | else
|
---|
4096 | show();
|
---|
4097 | }
|
---|
4098 |
|
---|
4099 | void QWidget::showChildren( bool spontaneous )
|
---|
4100 | {
|
---|
4101 | if ( children() ) {
|
---|
4102 | QObjectListIt it(*children());
|
---|
4103 | register QObject *object;
|
---|
4104 | QWidget *widget;
|
---|
4105 | while ( it ) {
|
---|
4106 | object = it.current();
|
---|
4107 | ++it;
|
---|
4108 | if ( object->isWidgetType() ) {
|
---|
4109 | widget = (QWidget*)object;
|
---|
4110 | if ( !widget->isTopLevel() && widget->isShown() ) {
|
---|
4111 | if ( spontaneous ) {
|
---|
4112 | widget->showChildren( spontaneous );
|
---|
4113 | QShowEvent e;
|
---|
4114 | QApplication::sendSpontaneousEvent( widget, &e );
|
---|
4115 | } else {
|
---|
4116 | widget->show();
|
---|
4117 | }
|
---|
4118 | }
|
---|
4119 | }
|
---|
4120 | }
|
---|
4121 | }
|
---|
4122 | }
|
---|
4123 |
|
---|
4124 | void QWidget::hideChildren( bool spontaneous )
|
---|
4125 | {
|
---|
4126 | if ( children() ) {
|
---|
4127 | QObjectListIt it(*children());
|
---|
4128 | register QObject *object;
|
---|
4129 | QWidget *widget;
|
---|
4130 | while ( it ) {
|
---|
4131 | object = it.current();
|
---|
4132 | ++it;
|
---|
4133 | if ( object->isWidgetType() ) {
|
---|
4134 | widget = (QWidget*)object;
|
---|
4135 | if ( !widget->isTopLevel() && widget->isShown() ) {
|
---|
4136 | if ( !spontaneous )
|
---|
4137 | widget->clearWState( WState_Visible );
|
---|
4138 | widget->hideChildren( spontaneous );
|
---|
4139 | QHideEvent e;
|
---|
4140 | if ( spontaneous )
|
---|
4141 | QApplication::sendSpontaneousEvent( widget, &e );
|
---|
4142 | else
|
---|
4143 | QApplication::sendEvent( widget, &e );
|
---|
4144 | }
|
---|
4145 | }
|
---|
4146 | }
|
---|
4147 | }
|
---|
4148 | }
|
---|
4149 |
|
---|
4150 |
|
---|
4151 | /*!
|
---|
4152 | Delayed initialization of a widget.
|
---|
4153 |
|
---|
4154 | This function will be called \e after a widget has been fully
|
---|
4155 | created and \e before it is shown the very first time.
|
---|
4156 |
|
---|
4157 | Polishing is useful for final initialization which depends on
|
---|
4158 | having an instantiated widget. This is something a constructor
|
---|
4159 | cannot guarantee since the initialization of the subclasses might
|
---|
4160 | not be finished.
|
---|
4161 |
|
---|
4162 | After this function, the widget has a proper font and palette and
|
---|
4163 | QApplication::polish() has been called.
|
---|
4164 |
|
---|
4165 | Remember to call QWidget's implementation first when reimplementing this
|
---|
4166 | function to ensure that your program does not end up in infinite recursion.
|
---|
4167 |
|
---|
4168 | \sa constPolish(), QApplication::polish()
|
---|
4169 | */
|
---|
4170 |
|
---|
4171 | void QWidget::polish()
|
---|
4172 | {
|
---|
4173 | #ifndef QT_NO_WIDGET_TOPEXTRA
|
---|
4174 | if ( isTopLevel() ) {
|
---|
4175 | const QPixmap *pm = icon();
|
---|
4176 | if ( !pm || pm->isNull() ) {
|
---|
4177 | QWidget *mw = (QWidget *)parent();
|
---|
4178 | pm = mw ? mw->icon() : 0;
|
---|
4179 | if ( pm && !pm->isNull() )
|
---|
4180 | setIcon( *pm );
|
---|
4181 | else {
|
---|
4182 | mw = mw ? mw->topLevelWidget() : 0;
|
---|
4183 | pm = mw ? mw->icon() : 0;
|
---|
4184 | if ( pm && !pm->isNull() )
|
---|
4185 | setIcon( *pm );
|
---|
4186 | else {
|
---|
4187 | mw = qApp ? qApp->mainWidget() : 0;
|
---|
4188 | pm = mw ? mw->icon() : 0;
|
---|
4189 | if ( pm && !pm->isNull() )
|
---|
4190 | setIcon( *pm );
|
---|
4191 | }
|
---|
4192 | }
|
---|
4193 | }
|
---|
4194 | }
|
---|
4195 | #endif
|
---|
4196 | if ( !testWState(WState_Polished) ) {
|
---|
4197 | if ( ! own_font &&
|
---|
4198 | ! QApplication::font( this ).isCopyOf( QApplication::font() ) )
|
---|
4199 | unsetFont();
|
---|
4200 | #ifndef QT_NO_PALETTE
|
---|
4201 | if ( ! own_palette &&
|
---|
4202 | ! QApplication::palette( this ).isCopyOf( QApplication::palette() ) )
|
---|
4203 | unsetPalette();
|
---|
4204 | #endif
|
---|
4205 | setWState(WState_Polished);
|
---|
4206 | qApp->polish( this );
|
---|
4207 | QApplication::sendPostedEvents( this, QEvent::ChildInserted );
|
---|
4208 | }
|
---|
4209 | }
|
---|
4210 |
|
---|
4211 |
|
---|
4212 | /*!
|
---|
4213 | \fn void QWidget::constPolish() const
|
---|
4214 |
|
---|
4215 | Ensures that the widget is properly initialized by calling
|
---|
4216 | polish().
|
---|
4217 |
|
---|
4218 | Call constPolish() from functions like sizeHint() that depends on
|
---|
4219 | the widget being initialized, and that may be called before
|
---|
4220 | show().
|
---|
4221 |
|
---|
4222 | \warning Do not call constPolish() on a widget from inside that
|
---|
4223 | widget's constructor.
|
---|
4224 |
|
---|
4225 | \sa polish()
|
---|
4226 | */
|
---|
4227 |
|
---|
4228 | /*!
|
---|
4229 | \overload
|
---|
4230 |
|
---|
4231 | Closes this widget. Returns TRUE if the widget was closed;
|
---|
4232 | otherwise returns FALSE.
|
---|
4233 |
|
---|
4234 | If \a alsoDelete is TRUE or the widget has the \c
|
---|
4235 | WDestructiveClose widget flag, the widget is also deleted. The
|
---|
4236 | widget can prevent itself from being closed by rejecting the
|
---|
4237 | \l QCloseEvent it gets. A close events is delivered to the widget
|
---|
4238 | no matter if the widget is visible or not.
|
---|
4239 |
|
---|
4240 | The QApplication::lastWindowClosed() signal is emitted when the
|
---|
4241 | last visible top level widget is closed.
|
---|
4242 |
|
---|
4243 | Note that closing the \l QApplication::mainWidget() terminates the
|
---|
4244 | application.
|
---|
4245 |
|
---|
4246 | \sa closeEvent(), QCloseEvent, hide(), QApplication::quit(),
|
---|
4247 | QApplication::setMainWidget(), QApplication::lastWindowClosed()
|
---|
4248 | */
|
---|
4249 |
|
---|
4250 | bool QWidget::close( bool alsoDelete )
|
---|
4251 | {
|
---|
4252 | if ( is_closing )
|
---|
4253 | return TRUE;
|
---|
4254 | is_closing = 1;
|
---|
4255 | WId id = winId();
|
---|
4256 | bool isMain = qApp->mainWidget() == this;
|
---|
4257 | bool checkLastWindowClosed = isTopLevel() && !isPopup();
|
---|
4258 | bool deleted = FALSE;
|
---|
4259 | QCloseEvent e;
|
---|
4260 | QApplication::sendEvent( this, &e );
|
---|
4261 | deleted = !QWidget::find(id);
|
---|
4262 | if ( !deleted && !e.isAccepted() ) {
|
---|
4263 | is_closing = 0;
|
---|
4264 | return FALSE;
|
---|
4265 | }
|
---|
4266 | if ( !deleted && !isHidden() )
|
---|
4267 | hide();
|
---|
4268 | if ( checkLastWindowClosed
|
---|
4269 | && qApp->receivers(SIGNAL(lastWindowClosed())) ) {
|
---|
4270 | /* if there is no non-withdrawn top level window left (except
|
---|
4271 | the desktop, popups, or dialogs with parents), we emit the
|
---|
4272 | lastWindowClosed signal */
|
---|
4273 | QWidgetList *list = qApp->topLevelWidgets();
|
---|
4274 | QWidget *widget = list->first();
|
---|
4275 | while ( widget ) {
|
---|
4276 | if ( !widget->isHidden()
|
---|
4277 | && !widget->isDesktop()
|
---|
4278 | && !widget->isPopup()
|
---|
4279 | && (!widget->isDialog() || !widget->parentWidget()))
|
---|
4280 | break;
|
---|
4281 | widget = list->next();
|
---|
4282 | }
|
---|
4283 | delete list;
|
---|
4284 | if ( widget == 0 )
|
---|
4285 | emit qApp->lastWindowClosed();
|
---|
4286 | }
|
---|
4287 | if ( isMain )
|
---|
4288 | qApp->quit();
|
---|
4289 | if ( deleted )
|
---|
4290 | return TRUE;
|
---|
4291 | is_closing = 0;
|
---|
4292 | if ( alsoDelete )
|
---|
4293 | delete this;
|
---|
4294 | else if ( testWFlags(WDestructiveClose) ) {
|
---|
4295 | clearWFlags(WDestructiveClose);
|
---|
4296 | deleteLater();
|
---|
4297 | }
|
---|
4298 | return TRUE;
|
---|
4299 | }
|
---|
4300 |
|
---|
4301 |
|
---|
4302 | /*!
|
---|
4303 | \fn bool QWidget::close()
|
---|
4304 |
|
---|
4305 | Closes this widget. Returns TRUE if the widget was closed;
|
---|
4306 | otherwise returns FALSE.
|
---|
4307 |
|
---|
4308 | First it sends the widget a QCloseEvent. The widget is \link
|
---|
4309 | hide() hidden\endlink if it \link QCloseEvent::accept()
|
---|
4310 | accepts\endlink the close event. The default implementation of
|
---|
4311 | QWidget::closeEvent() accepts the close event.
|
---|
4312 |
|
---|
4313 | The \l QApplication::lastWindowClosed() signal is emitted when the
|
---|
4314 | last visible top level widget is closed.
|
---|
4315 |
|
---|
4316 | */
|
---|
4317 |
|
---|
4318 | /*!
|
---|
4319 | \property QWidget::visible
|
---|
4320 | \brief whether the widget is visible
|
---|
4321 |
|
---|
4322 | Calling show() sets the widget to visible status if all its parent
|
---|
4323 | widgets up to the top-level widget are visible. If an ancestor is
|
---|
4324 | not visible, the widget won't become visible until all its
|
---|
4325 | ancestors are shown.
|
---|
4326 |
|
---|
4327 | Calling hide() hides a widget explicitly. An explicitly hidden
|
---|
4328 | widget will never become visible, even if all its ancestors become
|
---|
4329 | visible, unless you show it.
|
---|
4330 |
|
---|
4331 | A widget receives show and hide events when its visibility status
|
---|
4332 | changes. Between a hide and a show event, there is no need to
|
---|
4333 | waste CPU cycles preparing or displaying information to the user.
|
---|
4334 | A video application, for example, might simply stop generating new
|
---|
4335 | frames.
|
---|
4336 |
|
---|
4337 | A widget that happens to be obscured by other windows on the
|
---|
4338 | screen is considered to be visible. The same applies to iconified
|
---|
4339 | top-level widgets and windows that exist on another virtual
|
---|
4340 | desktop (on platforms that support this concept). A widget
|
---|
4341 | receives spontaneous show and hide events when its mapping status
|
---|
4342 | is changed by the window system, e.g. a spontaneous hide event
|
---|
4343 | when the user minimizes the window, and a spontaneous show event
|
---|
4344 | when the window is restored again.
|
---|
4345 |
|
---|
4346 | \sa show(), hide(), isHidden(), isVisibleTo(), isMinimized(),
|
---|
4347 | showEvent(), hideEvent()
|
---|
4348 | */
|
---|
4349 |
|
---|
4350 |
|
---|
4351 | /*!
|
---|
4352 | Returns TRUE if this widget would become visible if \a ancestor is
|
---|
4353 | shown; otherwise returns FALSE.
|
---|
4354 |
|
---|
4355 | The TRUE case occurs if neither the widget itself nor any parent
|
---|
4356 | up to but excluding \a ancestor has been explicitly hidden.
|
---|
4357 |
|
---|
4358 | This function will still return TRUE if the widget is obscured by
|
---|
4359 | other windows on the screen, but could be physically visible if it
|
---|
4360 | or they were to be moved.
|
---|
4361 |
|
---|
4362 | isVisibleTo(0) is identical to isVisible().
|
---|
4363 |
|
---|
4364 | \sa show() hide() isVisible()
|
---|
4365 | */
|
---|
4366 |
|
---|
4367 | bool QWidget::isVisibleTo(QWidget* ancestor) const
|
---|
4368 | {
|
---|
4369 | if ( !ancestor )
|
---|
4370 | return isVisible();
|
---|
4371 | const QWidget * w = this;
|
---|
4372 | while ( w
|
---|
4373 | && w->isShown()
|
---|
4374 | && !w->isTopLevel()
|
---|
4375 | && w->parentWidget()
|
---|
4376 | && w->parentWidget() != ancestor )
|
---|
4377 | w = w->parentWidget();
|
---|
4378 | return w->isShown();
|
---|
4379 | }
|
---|
4380 |
|
---|
4381 |
|
---|
4382 | /*!
|
---|
4383 | \fn bool QWidget::isVisibleToTLW() const
|
---|
4384 | \obsolete
|
---|
4385 |
|
---|
4386 | This function is deprecated. It is equivalent to isVisible()
|
---|
4387 | */
|
---|
4388 |
|
---|
4389 | /*!
|
---|
4390 | \property QWidget::hidden
|
---|
4391 | \brief whether the widget is explicitly hidden
|
---|
4392 |
|
---|
4393 | If FALSE, the widget is visible or would become visible if all its
|
---|
4394 | ancestors became visible.
|
---|
4395 |
|
---|
4396 | \sa hide(), show(), isVisible(), isVisibleTo(), shown
|
---|
4397 | */
|
---|
4398 |
|
---|
4399 | /*!
|
---|
4400 | \property QWidget::shown
|
---|
4401 | \brief whether the widget is shown
|
---|
4402 |
|
---|
4403 | If TRUE, the widget is visible or would become visible if all its
|
---|
4404 | ancestors became visible.
|
---|
4405 |
|
---|
4406 | \sa hide(), show(), isVisible(), isVisibleTo(), hidden
|
---|
4407 | */
|
---|
4408 |
|
---|
4409 | /*!
|
---|
4410 | \property QWidget::visibleRect
|
---|
4411 | \brief the visible rectangle
|
---|
4412 |
|
---|
4413 | \obsolete
|
---|
4414 |
|
---|
4415 | No longer necessary, you can simply call repaint(). If you do not
|
---|
4416 | need the rectangle for repaint(), use clipRegion() instead.
|
---|
4417 | */
|
---|
4418 | QRect QWidget::visibleRect() const
|
---|
4419 | {
|
---|
4420 | QRect r = rect();
|
---|
4421 | const QWidget * w = this;
|
---|
4422 | int ox = 0;
|
---|
4423 | int oy = 0;
|
---|
4424 | while ( w
|
---|
4425 | && w->isVisible()
|
---|
4426 | && !w->isTopLevel()
|
---|
4427 | && w->parentWidget() ) {
|
---|
4428 | ox -= w->x();
|
---|
4429 | oy -= w->y();
|
---|
4430 | w = w->parentWidget();
|
---|
4431 | r = r.intersect( QRect( ox, oy, w->width(), w->height() ) );
|
---|
4432 | }
|
---|
4433 | if ( !w->isVisible() )
|
---|
4434 | return QRect();
|
---|
4435 | return r;
|
---|
4436 | }
|
---|
4437 |
|
---|
4438 | /*!
|
---|
4439 | Returns the unobscured region where paint events can occur.
|
---|
4440 |
|
---|
4441 | For visible widgets, this is an approximation of the area not
|
---|
4442 | covered by other widgets; otherwise, this is an empty region.
|
---|
4443 |
|
---|
4444 | The repaint() function calls this function if necessary, so in
|
---|
4445 | general you do not need to call it.
|
---|
4446 |
|
---|
4447 | */
|
---|
4448 | QRegion QWidget::clipRegion() const
|
---|
4449 | {
|
---|
4450 | return visibleRect();
|
---|
4451 | }
|
---|
4452 |
|
---|
4453 |
|
---|
4454 | /*!
|
---|
4455 | Adjusts the size of the widget to fit the contents.
|
---|
4456 |
|
---|
4457 | Uses sizeHint() if valid (i.e if the size hint's width and height
|
---|
4458 | are \>= 0), otherwise sets the size to the children rectangle (the
|
---|
4459 | union of all child widget geometries).
|
---|
4460 |
|
---|
4461 | \sa sizeHint(), childrenRect()
|
---|
4462 | */
|
---|
4463 |
|
---|
4464 | void QWidget::adjustSize()
|
---|
4465 | {
|
---|
4466 | QApplication::sendPostedEvents( 0, QEvent::ChildInserted );
|
---|
4467 | QApplication::sendPostedEvents( 0, QEvent::LayoutHint );
|
---|
4468 | if ( !testWState(WState_Polished) )
|
---|
4469 | polish();
|
---|
4470 | QSize s = sizeHint();
|
---|
4471 |
|
---|
4472 | if ( isTopLevel() ) {
|
---|
4473 |
|
---|
4474 | #if defined(Q_WS_X11)
|
---|
4475 | QRect screen = QApplication::desktop()->screenGeometry( x11Screen() );
|
---|
4476 | #else // all others
|
---|
4477 | QRect screen = QApplication::desktop()->screenGeometry( pos() );
|
---|
4478 | #endif
|
---|
4479 |
|
---|
4480 | #ifndef QT_NO_LAYOUT
|
---|
4481 | if ( layout() ) {
|
---|
4482 | if ( layout()->hasHeightForWidth() ) {
|
---|
4483 | s = s.boundedTo( screen.size() );
|
---|
4484 | s.setHeight( layout()->totalHeightForWidth( s.width() ) );
|
---|
4485 | }
|
---|
4486 | } else
|
---|
4487 | #endif
|
---|
4488 | {
|
---|
4489 | if ( sizePolicy().hasHeightForWidth() ) {
|
---|
4490 | s = s.boundedTo( screen.size() );
|
---|
4491 | s.setHeight( heightForWidth( s.width() ) );
|
---|
4492 | }
|
---|
4493 | }
|
---|
4494 | }
|
---|
4495 | if ( s.isValid() ) {
|
---|
4496 | resize( s );
|
---|
4497 | return;
|
---|
4498 | }
|
---|
4499 | QRect r = childrenRect(); // get children rectangle
|
---|
4500 | if ( r.isNull() ) // probably no widgets
|
---|
4501 | return;
|
---|
4502 | resize( r.width() + 2 * r.x(), r.height() + 2 * r.y() );
|
---|
4503 | }
|
---|
4504 |
|
---|
4505 |
|
---|
4506 | /*!
|
---|
4507 | \property QWidget::sizeHint
|
---|
4508 | \brief the recommended size for the widget
|
---|
4509 |
|
---|
4510 | If the value of this property is an invalid size, no size is
|
---|
4511 | recommended.
|
---|
4512 |
|
---|
4513 | The default implementation of sizeHint() returns an invalid size
|
---|
4514 | if there is no layout for this widget, and returns the layout's
|
---|
4515 | preferred size otherwise.
|
---|
4516 |
|
---|
4517 | \sa QSize::isValid(), minimumSizeHint(), sizePolicy(),
|
---|
4518 | setMinimumSize(), updateGeometry()
|
---|
4519 | */
|
---|
4520 |
|
---|
4521 | QSize QWidget::sizeHint() const
|
---|
4522 | {
|
---|
4523 | #ifndef QT_NO_LAYOUT
|
---|
4524 | if ( layout() )
|
---|
4525 | return layout()->totalSizeHint();
|
---|
4526 | #endif
|
---|
4527 | return QSize( -1, -1 );
|
---|
4528 | }
|
---|
4529 |
|
---|
4530 | /*!
|
---|
4531 | \property QWidget::minimumSizeHint
|
---|
4532 | \brief the recommended minimum size for the widget
|
---|
4533 |
|
---|
4534 | If the value of this property is an invalid size, no minimum size
|
---|
4535 | is recommended.
|
---|
4536 |
|
---|
4537 | The default implementation of minimumSizeHint() returns an invalid
|
---|
4538 | size if there is no layout for this widget, and returns the
|
---|
4539 | layout's minimum size otherwise. Most built-in widgets reimplement
|
---|
4540 | minimumSizeHint().
|
---|
4541 |
|
---|
4542 | \l QLayout will never resize a widget to a size smaller than
|
---|
4543 | minimumSizeHint.
|
---|
4544 |
|
---|
4545 | \sa QSize::isValid(), resize(), setMinimumSize(), sizePolicy()
|
---|
4546 | */
|
---|
4547 | QSize QWidget::minimumSizeHint() const
|
---|
4548 | {
|
---|
4549 | #ifndef QT_NO_LAYOUT
|
---|
4550 | if ( layout() )
|
---|
4551 | return layout()->totalMinimumSize();
|
---|
4552 | #endif
|
---|
4553 | return QSize( -1, -1 );
|
---|
4554 | }
|
---|
4555 |
|
---|
4556 |
|
---|
4557 | /*!
|
---|
4558 | \fn QWidget *QWidget::parentWidget( bool sameWindow ) const
|
---|
4559 |
|
---|
4560 | Returns the parent of this widget, or 0 if it does not have any
|
---|
4561 | parent widget. If \a sameWindow is TRUE and the widget is top
|
---|
4562 | level returns 0; otherwise returns the widget's parent.
|
---|
4563 | */
|
---|
4564 |
|
---|
4565 | /*!
|
---|
4566 | \fn WFlags QWidget::testWFlags( WFlags f ) const
|
---|
4567 |
|
---|
4568 | Returns the bitwise AND of the widget flags and \a f.
|
---|
4569 |
|
---|
4570 | Widget flags are a combination of \l{Qt::WidgetFlags}.
|
---|
4571 |
|
---|
4572 | If you want to test for the presence of multiple flags (or
|
---|
4573 | composite flags such as \c WStyle_Splash), test the
|
---|
4574 | return value for equality against the argument. For example:
|
---|
4575 |
|
---|
4576 | \code
|
---|
4577 | int flags = WStyle_Tool | WStyle_NoBorder;
|
---|
4578 | if ( testWFlags(flags) )
|
---|
4579 | ... // WStyle_Tool or WStyle_NoBorder or both are set
|
---|
4580 | if ( testWFlags(flags) == flags )
|
---|
4581 | ... // both WStyle_Tool and WStyle_NoBorder are set
|
---|
4582 | \endcode
|
---|
4583 |
|
---|
4584 | \sa getWFlags(), setWFlags(), clearWFlags()
|
---|
4585 | */
|
---|
4586 |
|
---|
4587 | /*!
|
---|
4588 | \fn WState QWidget::testWState( WState s ) const
|
---|
4589 | \internal
|
---|
4590 |
|
---|
4591 | Returns the bitwise AND of the widget states and \a s.
|
---|
4592 | */
|
---|
4593 |
|
---|
4594 | /*!
|
---|
4595 | \fn uint QWidget::getWState() const
|
---|
4596 |
|
---|
4597 | \internal
|
---|
4598 |
|
---|
4599 | Returns the current widget state.
|
---|
4600 | */
|
---|
4601 | /*!
|
---|
4602 | \fn void QWidget::clearWState( uint n )
|
---|
4603 |
|
---|
4604 | \internal
|
---|
4605 |
|
---|
4606 | Clears the widgets states \a n.
|
---|
4607 | */
|
---|
4608 | /*!
|
---|
4609 | \fn void QWidget::setWState( uint n )
|
---|
4610 |
|
---|
4611 | \internal
|
---|
4612 |
|
---|
4613 | Sets the widgets states \a n.
|
---|
4614 | */
|
---|
4615 |
|
---|
4616 |
|
---|
4617 |
|
---|
4618 | /*****************************************************************************
|
---|
4619 | QWidget event handling
|
---|
4620 | *****************************************************************************/
|
---|
4621 |
|
---|
4622 | /*!
|
---|
4623 | This is the main event handler; it handles event \a e. You can
|
---|
4624 | reimplement this function in a subclass, but we recommend using
|
---|
4625 | one of the specialized event handlers instead.
|
---|
4626 |
|
---|
4627 | The main event handler first passes an event through all \link
|
---|
4628 | QObject::installEventFilter() event filters\endlink that have been
|
---|
4629 | installed. If none of the filters intercept the event, it calls
|
---|
4630 | one of the specialized event handlers.
|
---|
4631 |
|
---|
4632 | Key press and release events are treated differently from other
|
---|
4633 | events. event() checks for Tab and Shift+Tab and tries to move the
|
---|
4634 | focus appropriately. If there is no widget to move the focus to
|
---|
4635 | (or the key press is not Tab or Shift+Tab), event() calls
|
---|
4636 | keyPressEvent().
|
---|
4637 |
|
---|
4638 | This function returns TRUE if it is able to pass the event over to
|
---|
4639 | someone (i.e. someone wanted the event); otherwise returns FALSE.
|
---|
4640 |
|
---|
4641 | \sa closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(),
|
---|
4642 | keyPressEvent(), keyReleaseEvent(), leaveEvent(),
|
---|
4643 | mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(),
|
---|
4644 | mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(),
|
---|
4645 | QObject::event(), QObject::timerEvent()
|
---|
4646 | */
|
---|
4647 |
|
---|
4648 | bool QWidget::event( QEvent *e )
|
---|
4649 | {
|
---|
4650 | if ( QObject::event( e ) )
|
---|
4651 | return TRUE;
|
---|
4652 |
|
---|
4653 | switch ( e->type() ) {
|
---|
4654 | case QEvent::MouseMove:
|
---|
4655 | mouseMoveEvent( (QMouseEvent*)e );
|
---|
4656 | if ( ! ((QMouseEvent*)e)->isAccepted() )
|
---|
4657 | return FALSE;
|
---|
4658 | break;
|
---|
4659 |
|
---|
4660 | case QEvent::MouseButtonPress:
|
---|
4661 | resetInputContext();
|
---|
4662 | mousePressEvent( (QMouseEvent*)e );
|
---|
4663 | if ( ! ((QMouseEvent*)e)->isAccepted() )
|
---|
4664 | return FALSE;
|
---|
4665 | break;
|
---|
4666 |
|
---|
4667 | case QEvent::MouseButtonRelease:
|
---|
4668 | mouseReleaseEvent( (QMouseEvent*)e );
|
---|
4669 | if ( ! ((QMouseEvent*)e)->isAccepted() )
|
---|
4670 | return FALSE;
|
---|
4671 | break;
|
---|
4672 |
|
---|
4673 | case QEvent::MouseButtonDblClick:
|
---|
4674 | mouseDoubleClickEvent( (QMouseEvent*)e );
|
---|
4675 | if ( ! ((QMouseEvent*)e)->isAccepted() )
|
---|
4676 | return FALSE;
|
---|
4677 | break;
|
---|
4678 | #ifndef QT_NO_WHEELEVENT
|
---|
4679 | case QEvent::Wheel:
|
---|
4680 | wheelEvent( (QWheelEvent*)e );
|
---|
4681 | if ( ! ((QWheelEvent*)e)->isAccepted() )
|
---|
4682 | return FALSE;
|
---|
4683 | break;
|
---|
4684 | #endif
|
---|
4685 | case QEvent::TabletMove:
|
---|
4686 | case QEvent::TabletPress:
|
---|
4687 | case QEvent::TabletRelease:
|
---|
4688 | tabletEvent( (QTabletEvent*)e );
|
---|
4689 | if ( ! ((QTabletEvent*)e)->isAccepted() )
|
---|
4690 | return FALSE;
|
---|
4691 | break;
|
---|
4692 | case QEvent::Accel:
|
---|
4693 | ((QKeyEvent*)e)->ignore();
|
---|
4694 | return FALSE;
|
---|
4695 | case QEvent::KeyPress: {
|
---|
4696 | QKeyEvent *k = (QKeyEvent *)e;
|
---|
4697 | bool res = FALSE;
|
---|
4698 | if ( !(k->state() & ControlButton || k->state() & AltButton) ) {
|
---|
4699 | if ( k->key() == Key_Backtab ||
|
---|
4700 | (k->key() == Key_Tab &&
|
---|
4701 | (k->state() & ShiftButton)) ) {
|
---|
4702 | QFocusEvent::setReason( QFocusEvent::Backtab );
|
---|
4703 | res = focusNextPrevChild( FALSE );
|
---|
4704 | QFocusEvent::resetReason();
|
---|
4705 |
|
---|
4706 | } else if ( k->key() == Key_Tab ) {
|
---|
4707 | QFocusEvent::setReason( QFocusEvent::Tab );
|
---|
4708 | res = focusNextPrevChild( TRUE );
|
---|
4709 | QFocusEvent::resetReason();
|
---|
4710 | }
|
---|
4711 | if ( res )
|
---|
4712 | break;
|
---|
4713 | }
|
---|
4714 | keyPressEvent( k );
|
---|
4715 | if ( !k->isAccepted() )
|
---|
4716 | return FALSE;
|
---|
4717 | }
|
---|
4718 | break;
|
---|
4719 |
|
---|
4720 | case QEvent::KeyRelease:
|
---|
4721 | keyReleaseEvent( (QKeyEvent*)e );
|
---|
4722 | if ( ! ((QKeyEvent*)e)->isAccepted() )
|
---|
4723 | return FALSE;
|
---|
4724 | break;
|
---|
4725 |
|
---|
4726 | case QEvent::IMStart: {
|
---|
4727 | QIMEvent *i = (QIMEvent *) e;
|
---|
4728 | imStartEvent(i);
|
---|
4729 | if (! i->isAccepted())
|
---|
4730 | return FALSE;
|
---|
4731 | }
|
---|
4732 | break;
|
---|
4733 |
|
---|
4734 | case QEvent::IMCompose: {
|
---|
4735 | QIMEvent *i = (QIMEvent *) e;
|
---|
4736 | imComposeEvent(i);
|
---|
4737 | if (! i->isAccepted())
|
---|
4738 | return FALSE;
|
---|
4739 | }
|
---|
4740 | break;
|
---|
4741 |
|
---|
4742 | case QEvent::IMEnd: {
|
---|
4743 | QIMEvent *i = (QIMEvent *) e;
|
---|
4744 | imEndEvent(i);
|
---|
4745 | if (! i->isAccepted())
|
---|
4746 | return FALSE;
|
---|
4747 | }
|
---|
4748 | break;
|
---|
4749 |
|
---|
4750 | case QEvent::FocusIn:
|
---|
4751 | focusInEvent( (QFocusEvent*)e );
|
---|
4752 | setFontSys();
|
---|
4753 | break;
|
---|
4754 |
|
---|
4755 | case QEvent::FocusOut:
|
---|
4756 | focusOutEvent( (QFocusEvent*)e );
|
---|
4757 | break;
|
---|
4758 |
|
---|
4759 | case QEvent::Enter:
|
---|
4760 | enterEvent( e );
|
---|
4761 | break;
|
---|
4762 |
|
---|
4763 | case QEvent::Leave:
|
---|
4764 | leaveEvent( e );
|
---|
4765 | break;
|
---|
4766 |
|
---|
4767 | case QEvent::Paint:
|
---|
4768 | // At this point the event has to be delivered, regardless
|
---|
4769 | // whether the widget isVisible() or not because it
|
---|
4770 | // already went through the filters
|
---|
4771 | paintEvent( (QPaintEvent*)e );
|
---|
4772 | break;
|
---|
4773 |
|
---|
4774 | case QEvent::Move:
|
---|
4775 | moveEvent( (QMoveEvent*)e );
|
---|
4776 | break;
|
---|
4777 |
|
---|
4778 | case QEvent::Resize:
|
---|
4779 | resizeEvent( (QResizeEvent*)e );
|
---|
4780 | break;
|
---|
4781 |
|
---|
4782 | case QEvent::Close: {
|
---|
4783 | QCloseEvent *c = (QCloseEvent *)e;
|
---|
4784 | closeEvent( c );
|
---|
4785 | if ( !c->isAccepted() )
|
---|
4786 | return FALSE;
|
---|
4787 | }
|
---|
4788 | break;
|
---|
4789 |
|
---|
4790 | case QEvent::ContextMenu: {
|
---|
4791 | QContextMenuEvent *c = (QContextMenuEvent *)e;
|
---|
4792 | contextMenuEvent( c );
|
---|
4793 | if ( !c->isAccepted() )
|
---|
4794 | return FALSE;
|
---|
4795 | }
|
---|
4796 | break;
|
---|
4797 |
|
---|
4798 | #ifndef QT_NO_DRAGANDDROP
|
---|
4799 | case QEvent::Drop:
|
---|
4800 | dropEvent( (QDropEvent*) e);
|
---|
4801 | break;
|
---|
4802 |
|
---|
4803 | case QEvent::DragEnter:
|
---|
4804 | dragEnterEvent( (QDragEnterEvent*) e);
|
---|
4805 | break;
|
---|
4806 |
|
---|
4807 | case QEvent::DragMove:
|
---|
4808 | dragMoveEvent( (QDragMoveEvent*) e);
|
---|
4809 | break;
|
---|
4810 |
|
---|
4811 | case QEvent::DragLeave:
|
---|
4812 | dragLeaveEvent( (QDragLeaveEvent*) e);
|
---|
4813 | break;
|
---|
4814 | #endif
|
---|
4815 |
|
---|
4816 | case QEvent::Show:
|
---|
4817 | showEvent( (QShowEvent*) e);
|
---|
4818 | break;
|
---|
4819 |
|
---|
4820 | case QEvent::Hide:
|
---|
4821 | hideEvent( (QHideEvent*) e);
|
---|
4822 | break;
|
---|
4823 |
|
---|
4824 | case QEvent::ShowWindowRequest:
|
---|
4825 | if ( isShown() )
|
---|
4826 | showWindow();
|
---|
4827 | break;
|
---|
4828 |
|
---|
4829 | case QEvent::ParentFontChange:
|
---|
4830 | if ( isTopLevel() )
|
---|
4831 | break;
|
---|
4832 | // fall through
|
---|
4833 | case QEvent::ApplicationFontChange:
|
---|
4834 | if ( own_font )
|
---|
4835 | setFont( fnt.resolve( qt_naturalWidgetFont( this ) ) );
|
---|
4836 | else
|
---|
4837 | unsetFont();
|
---|
4838 | break;
|
---|
4839 |
|
---|
4840 | #ifndef QT_NO_PALETTE
|
---|
4841 | case QEvent::ParentPaletteChange:
|
---|
4842 | if ( isTopLevel() )
|
---|
4843 | break;
|
---|
4844 | // fall through
|
---|
4845 | case QEvent::ApplicationPaletteChange:
|
---|
4846 | if ( !own_palette && !isDesktop() )
|
---|
4847 | unsetPalette();
|
---|
4848 | # if defined(Q_WS_QWS) && !defined (QT_NO_QWS_MANAGER)
|
---|
4849 | if ( isTopLevel() && topData()->qwsManager ) {
|
---|
4850 | QRegion r( topData()->qwsManager->region() );
|
---|
4851 | QApplication::postEvent(topData()->qwsManager, new QPaintEvent(r, FALSE) );
|
---|
4852 | }
|
---|
4853 | # endif
|
---|
4854 | break;
|
---|
4855 | #endif
|
---|
4856 |
|
---|
4857 | case QEvent::WindowActivate:
|
---|
4858 | case QEvent::WindowDeactivate:
|
---|
4859 | windowActivationChange( e->type() != QEvent::WindowActivate );
|
---|
4860 | if ( children() ) {
|
---|
4861 | QObjectListIt it( *children() );
|
---|
4862 | QObject *o;
|
---|
4863 | while( ( o = it.current() ) != 0 ) {
|
---|
4864 | ++it;
|
---|
4865 | if ( o->isWidgetType() &&
|
---|
4866 | ((QWidget*)o)->isVisible() &&
|
---|
4867 | !((QWidget*)o)->isTopLevel() )
|
---|
4868 | QApplication::sendEvent( o, e );
|
---|
4869 | }
|
---|
4870 | }
|
---|
4871 | break;
|
---|
4872 |
|
---|
4873 | case QEvent::LanguageChange:
|
---|
4874 | case QEvent::LocaleChange:
|
---|
4875 | if ( children() ) {
|
---|
4876 | QObjectListIt it( *children() );
|
---|
4877 | QObject *o;
|
---|
4878 | while( ( o = it.current() ) != 0 ) {
|
---|
4879 | ++it;
|
---|
4880 | QApplication::sendEvent( o, e );
|
---|
4881 | }
|
---|
4882 | }
|
---|
4883 | if ( e->type() == QEvent::LanguageChange ) {
|
---|
4884 | int index = metaObject()->findSlot( "languageChange()", TRUE );
|
---|
4885 | if ( index >= 0 )
|
---|
4886 | qt_invoke( index, 0 );
|
---|
4887 | }
|
---|
4888 | update();
|
---|
4889 | break;
|
---|
4890 | #ifndef QT_NO_LAYOUT
|
---|
4891 | case QEvent::LayoutDirectionChange:
|
---|
4892 | if ( layout() ) {
|
---|
4893 | layout()->activate();
|
---|
4894 | } else {
|
---|
4895 | QObjectList* llist = queryList( "QLayout", 0, TRUE, TRUE );
|
---|
4896 | QObjectListIt lit( *llist );
|
---|
4897 | QLayout *lay;
|
---|
4898 | while ( ( lay = (QLayout*)lit.current() ) != 0 ) {
|
---|
4899 | ++lit;
|
---|
4900 | lay->activate();
|
---|
4901 | }
|
---|
4902 | delete llist;
|
---|
4903 | }
|
---|
4904 | update();
|
---|
4905 | break;
|
---|
4906 | #endif
|
---|
4907 |
|
---|
4908 | case QEvent::WindowStateChange:
|
---|
4909 | {
|
---|
4910 | QEvent::Type type;
|
---|
4911 | if (isMinimized())
|
---|
4912 | type = QEvent::ShowMinimized;
|
---|
4913 | else if (isFullScreen())
|
---|
4914 | type = QEvent::ShowFullScreen;
|
---|
4915 | else if (isMaximized())
|
---|
4916 | type = QEvent::ShowMaximized;
|
---|
4917 | else
|
---|
4918 | type = QEvent::ShowNormal;
|
---|
4919 |
|
---|
4920 | if (e->spontaneous()) {
|
---|
4921 | QEvent e2(type);
|
---|
4922 | QApplication::sendEvent(this, &e2);
|
---|
4923 | } else {
|
---|
4924 | QApplication::postEvent(this, new QEvent(type));
|
---|
4925 | }
|
---|
4926 | break;
|
---|
4927 | }
|
---|
4928 |
|
---|
4929 | case QEvent::WindowBlocked:
|
---|
4930 | case QEvent::WindowUnblocked:
|
---|
4931 | if ( children() ) {
|
---|
4932 | QObjectListIt it( *children() );
|
---|
4933 | QObject *o;
|
---|
4934 | while( ( o = it.current() ) != 0 ) {
|
---|
4935 | ++it;
|
---|
4936 | QApplication::sendEvent( o, e );
|
---|
4937 | }
|
---|
4938 | }
|
---|
4939 | break;
|
---|
4940 |
|
---|
4941 | default:
|
---|
4942 | return FALSE;
|
---|
4943 | }
|
---|
4944 | return TRUE;
|
---|
4945 | }
|
---|
4946 |
|
---|
4947 | /*!
|
---|
4948 | This event handler, for event \a e, can be reimplemented in a
|
---|
4949 | subclass to receive mouse move events for the widget.
|
---|
4950 |
|
---|
4951 | If mouse tracking is switched off, mouse move events only occur if
|
---|
4952 | a mouse button is pressed while the mouse is being moved. If mouse
|
---|
4953 | tracking is switched on, mouse move events occur even if no mouse
|
---|
4954 | button is pressed.
|
---|
4955 |
|
---|
4956 | QMouseEvent::pos() reports the position of the mouse cursor,
|
---|
4957 | relative to this widget. For press and release events, the
|
---|
4958 | position is usually the same as the position of the last mouse
|
---|
4959 | move event, but it might be different if the user's hand shakes.
|
---|
4960 | This is a feature of the underlying window system, not Qt.
|
---|
4961 |
|
---|
4962 | \sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(),
|
---|
4963 | mouseDoubleClickEvent(), event(), QMouseEvent
|
---|
4964 | */
|
---|
4965 |
|
---|
4966 | void QWidget::mouseMoveEvent( QMouseEvent * e)
|
---|
4967 | {
|
---|
4968 | e->ignore();
|
---|
4969 | }
|
---|
4970 |
|
---|
4971 | /*!
|
---|
4972 | This event handler, for event \a e, can be reimplemented in a
|
---|
4973 | subclass to receive mouse press events for the widget.
|
---|
4974 |
|
---|
4975 | If you create new widgets in the mousePressEvent() the
|
---|
4976 | mouseReleaseEvent() may not end up where you expect, depending on
|
---|
4977 | the underlying window system (or X11 window manager), the widgets'
|
---|
4978 | location and maybe more.
|
---|
4979 |
|
---|
4980 | The default implementation implements the closing of popup widgets
|
---|
4981 | when you click outside the window. For other widget types it does
|
---|
4982 | nothing.
|
---|
4983 |
|
---|
4984 | \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
|
---|
4985 | mouseMoveEvent(), event(), QMouseEvent
|
---|
4986 | */
|
---|
4987 |
|
---|
4988 | void QWidget::mousePressEvent( QMouseEvent *e )
|
---|
4989 | {
|
---|
4990 | e->ignore();
|
---|
4991 | if ( isPopup() ) {
|
---|
4992 | e->accept();
|
---|
4993 | QWidget* w;
|
---|
4994 | while ( (w = qApp->activePopupWidget() ) && w != this ){
|
---|
4995 | w->close();
|
---|
4996 | if (qApp->activePopupWidget() == w) // widget does not want to dissappear
|
---|
4997 | w->hide(); // hide at least
|
---|
4998 | }
|
---|
4999 | if (!rect().contains(e->pos()) ){
|
---|
5000 | close();
|
---|
5001 | }
|
---|
5002 | }
|
---|
5003 | }
|
---|
5004 |
|
---|
5005 | /*!
|
---|
5006 | This event handler, for event \a e, can be reimplemented in a
|
---|
5007 | subclass to receive mouse release events for the widget.
|
---|
5008 |
|
---|
5009 | \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
|
---|
5010 | mouseMoveEvent(), event(), QMouseEvent
|
---|
5011 | */
|
---|
5012 |
|
---|
5013 | void QWidget::mouseReleaseEvent( QMouseEvent * e )
|
---|
5014 | {
|
---|
5015 | e->ignore();
|
---|
5016 | }
|
---|
5017 |
|
---|
5018 | /*!
|
---|
5019 | This event handler, for event \a e, can be reimplemented in a
|
---|
5020 | subclass to receive mouse double click events for the widget.
|
---|
5021 |
|
---|
5022 | The default implementation generates a normal mouse press event.
|
---|
5023 |
|
---|
5024 | Note that the widgets gets a mousePressEvent() and a
|
---|
5025 | mouseReleaseEvent() before the mouseDoubleClickEvent().
|
---|
5026 |
|
---|
5027 | \sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
|
---|
5028 | event(), QMouseEvent
|
---|
5029 | */
|
---|
5030 |
|
---|
5031 | void QWidget::mouseDoubleClickEvent( QMouseEvent *e )
|
---|
5032 | {
|
---|
5033 | mousePressEvent( e ); // try mouse press event
|
---|
5034 | }
|
---|
5035 |
|
---|
5036 | #ifndef QT_NO_WHEELEVENT
|
---|
5037 | /*!
|
---|
5038 | This event handler, for event \a e, can be reimplemented in a
|
---|
5039 | subclass to receive wheel events for the widget.
|
---|
5040 |
|
---|
5041 | If you reimplement this handler, it is very important that you
|
---|
5042 | \link QWheelEvent ignore()\endlink the event if you do not handle
|
---|
5043 | it, so that the widget's parent can interpret it.
|
---|
5044 |
|
---|
5045 | The default implementation ignores the event.
|
---|
5046 |
|
---|
5047 | \sa QWheelEvent::ignore(), QWheelEvent::accept(), event(),
|
---|
5048 | QWheelEvent
|
---|
5049 | */
|
---|
5050 |
|
---|
5051 | void QWidget::wheelEvent( QWheelEvent *e )
|
---|
5052 | {
|
---|
5053 | e->ignore();
|
---|
5054 | }
|
---|
5055 | #endif
|
---|
5056 |
|
---|
5057 | /*!
|
---|
5058 | This event handler, for event \a e, can be reimplemented in a
|
---|
5059 | subclass to receive tablet events for the widget.
|
---|
5060 |
|
---|
5061 | If you reimplement this handler, it is very important that you
|
---|
5062 | \link QTabletEvent ignore()\endlink the event if you do not handle
|
---|
5063 | it, so that the widget's parent can interpret it.
|
---|
5064 |
|
---|
5065 | The default implementation ignores the event.
|
---|
5066 |
|
---|
5067 | \sa QTabletEvent::ignore(), QTabletEvent::accept(), event(),
|
---|
5068 | QTabletEvent
|
---|
5069 | */
|
---|
5070 |
|
---|
5071 | void QWidget::tabletEvent( QTabletEvent *e )
|
---|
5072 | {
|
---|
5073 | e->ignore();
|
---|
5074 | }
|
---|
5075 |
|
---|
5076 | /*!
|
---|
5077 | This event handler, for event \a e, can be reimplemented in a
|
---|
5078 | subclass to receive key press events for the widget.
|
---|
5079 |
|
---|
5080 | A widget must call setFocusPolicy() to accept focus initially and
|
---|
5081 | have focus in order to receive a key press event.
|
---|
5082 |
|
---|
5083 | If you reimplement this handler, it is very important that you
|
---|
5084 | \link QKeyEvent ignore()\endlink the event if you do not
|
---|
5085 | understand it, so that the widget's parent can interpret it.
|
---|
5086 |
|
---|
5087 | The default implementation closes popup widgets if the user
|
---|
5088 | presses Esc. Otherwise the event is ignored.
|
---|
5089 |
|
---|
5090 | \sa keyReleaseEvent(), QKeyEvent::ignore(), setFocusPolicy(),
|
---|
5091 | focusInEvent(), focusOutEvent(), event(), QKeyEvent
|
---|
5092 | */
|
---|
5093 |
|
---|
5094 | void QWidget::keyPressEvent( QKeyEvent *e )
|
---|
5095 | {
|
---|
5096 | if ( isPopup() && e->key() == Key_Escape ) {
|
---|
5097 | e->accept();
|
---|
5098 | close();
|
---|
5099 | } else {
|
---|
5100 | e->ignore();
|
---|
5101 | }
|
---|
5102 | }
|
---|
5103 |
|
---|
5104 | /*!
|
---|
5105 | This event handler, for event \a e, can be reimplemented in a
|
---|
5106 | subclass to receive key release events for the widget.
|
---|
5107 |
|
---|
5108 | A widget must \link setFocusPolicy() accept focus\endlink
|
---|
5109 | initially and \link hasFocus() have focus\endlink in order to
|
---|
5110 | receive a key release event.
|
---|
5111 |
|
---|
5112 | If you reimplement this handler, it is very important that you
|
---|
5113 | \link QKeyEvent ignore()\endlink the release if you do not
|
---|
5114 | understand it, so that the widget's parent can interpret it.
|
---|
5115 |
|
---|
5116 | The default implementation ignores the event.
|
---|
5117 |
|
---|
5118 | \sa keyPressEvent(), QKeyEvent::ignore(), setFocusPolicy(),
|
---|
5119 | focusInEvent(), focusOutEvent(), event(), QKeyEvent
|
---|
5120 | */
|
---|
5121 |
|
---|
5122 | void QWidget::keyReleaseEvent( QKeyEvent *e )
|
---|
5123 | {
|
---|
5124 | e->ignore();
|
---|
5125 | }
|
---|
5126 |
|
---|
5127 | /*!
|
---|
5128 | This event handler can be reimplemented in a subclass to receive
|
---|
5129 | keyboard focus events (focus received) for the widget.
|
---|
5130 |
|
---|
5131 | A widget normally must setFocusPolicy() to something other than
|
---|
5132 | \c NoFocus in order to receive focus events. (Note that the
|
---|
5133 | application programmer can call setFocus() on any widget, even
|
---|
5134 | those that do not normally accept focus.)
|
---|
5135 |
|
---|
5136 | The default implementation updates the widget (except for toplevel
|
---|
5137 | widgets that do not specify a focusPolicy() ). It also calls
|
---|
5138 | setMicroFocusHint(), hinting any system-specific input tools about
|
---|
5139 | the focus of the user's attention.
|
---|
5140 |
|
---|
5141 | \sa focusOutEvent(), setFocusPolicy(), keyPressEvent(),
|
---|
5142 | keyReleaseEvent(), event(), QFocusEvent
|
---|
5143 | */
|
---|
5144 |
|
---|
5145 | void QWidget::focusInEvent( QFocusEvent * )
|
---|
5146 | {
|
---|
5147 | if ( focusPolicy() != NoFocus || !isTopLevel() ) {
|
---|
5148 | update();
|
---|
5149 | if ( testWState(WState_AutoMask) )
|
---|
5150 | updateMask();
|
---|
5151 | setMicroFocusHint(width()/2, 0, 1, height(), FALSE);
|
---|
5152 | }
|
---|
5153 | }
|
---|
5154 |
|
---|
5155 | /*!
|
---|
5156 | This event handler can be reimplemented in a subclass to receive
|
---|
5157 | keyboard focus events (focus lost) for the widget.
|
---|
5158 |
|
---|
5159 | A widget normally must setFocusPolicy() to something other than
|
---|
5160 | \c NoFocus in order to receive focus events. (Note that the
|
---|
5161 | application programmer can call setFocus() on any widget, even
|
---|
5162 | those that do not normally accept focus.)
|
---|
5163 |
|
---|
5164 | The default implementation updates the widget (except for toplevel
|
---|
5165 | widgets that do not specify a focusPolicy() ). It also calls
|
---|
5166 | setMicroFocusHint(), hinting any system-specific input tools about
|
---|
5167 | the focus of the user's attention.
|
---|
5168 |
|
---|
5169 | \sa focusInEvent(), setFocusPolicy(), keyPressEvent(),
|
---|
5170 | keyReleaseEvent(), event(), QFocusEvent
|
---|
5171 | */
|
---|
5172 |
|
---|
5173 | void QWidget::focusOutEvent( QFocusEvent * )
|
---|
5174 | {
|
---|
5175 | if ( focusPolicy() != NoFocus || !isTopLevel() ){
|
---|
5176 | update();
|
---|
5177 | if ( testWState(WState_AutoMask) )
|
---|
5178 | updateMask();
|
---|
5179 | }
|
---|
5180 | }
|
---|
5181 |
|
---|
5182 | /*!
|
---|
5183 | \property QWidget::microFocusHint
|
---|
5184 | \brief the currently set micro focus hint for this widget.
|
---|
5185 |
|
---|
5186 | See the documentation of setMicroFocusHint() for more information.
|
---|
5187 | */
|
---|
5188 | QRect QWidget::microFocusHint() const
|
---|
5189 | {
|
---|
5190 | if ( !extra || extra->micro_focus_hint.isEmpty() )
|
---|
5191 | return QRect(width()/2, 0, 1, height() );
|
---|
5192 | else
|
---|
5193 | return extra->micro_focus_hint;
|
---|
5194 | }
|
---|
5195 |
|
---|
5196 | /*!
|
---|
5197 | This event handler can be reimplemented in a subclass to receive
|
---|
5198 | widget enter events.
|
---|
5199 |
|
---|
5200 | An event is sent to the widget when the mouse cursor enters the
|
---|
5201 | widget.
|
---|
5202 |
|
---|
5203 | \sa leaveEvent(), mouseMoveEvent(), event()
|
---|
5204 | */
|
---|
5205 |
|
---|
5206 | void QWidget::enterEvent( QEvent * )
|
---|
5207 | {
|
---|
5208 | }
|
---|
5209 |
|
---|
5210 | /*!
|
---|
5211 | This event handler can be reimplemented in a subclass to receive
|
---|
5212 | widget leave events.
|
---|
5213 |
|
---|
5214 | A leave event is sent to the widget when the mouse cursor leaves
|
---|
5215 | the widget.
|
---|
5216 |
|
---|
5217 | \sa enterEvent(), mouseMoveEvent(), event()
|
---|
5218 | */
|
---|
5219 |
|
---|
5220 | void QWidget::leaveEvent( QEvent * )
|
---|
5221 | {
|
---|
5222 | }
|
---|
5223 |
|
---|
5224 | /*!
|
---|
5225 | This event handler can be reimplemented in a subclass to receive
|
---|
5226 | paint events.
|
---|
5227 |
|
---|
5228 | A paint event is a request to repaint all or part of the widget.
|
---|
5229 | It can happen as a result of repaint() or update(), or because the
|
---|
5230 | widget was obscured and has now been uncovered, or for many other
|
---|
5231 | reasons.
|
---|
5232 |
|
---|
5233 | Many widgets can simply repaint their entire surface when asked
|
---|
5234 | to, but some slow widgets need to optimize by painting only the
|
---|
5235 | requested region: QPaintEvent::region(). This speed optimization
|
---|
5236 | does not change the result, as painting is clipped to that region
|
---|
5237 | during event processing. QListView and QCanvas do this, for
|
---|
5238 | example.
|
---|
5239 |
|
---|
5240 | Qt also tries to speed up painting by merging multiple paint
|
---|
5241 | events into one. When update() is called several times or the
|
---|
5242 | window system sends several paint events, Qt merges these events
|
---|
5243 | into one event with a larger region (see QRegion::unite()).
|
---|
5244 | repaint() does not permit this optimization, so we suggest using
|
---|
5245 | update() when possible.
|
---|
5246 |
|
---|
5247 | When the paint event occurs, the update region has normally been
|
---|
5248 | erased, so that you're painting on the widget's background. There
|
---|
5249 | are a couple of exceptions and QPaintEvent::erased() tells you
|
---|
5250 | whether the widget has been erased or not.
|
---|
5251 |
|
---|
5252 | The background can be set using setBackgroundMode(),
|
---|
5253 | setPaletteBackgroundColor() or setBackgroundPixmap(). The
|
---|
5254 | documentation for setBackgroundMode() elaborates on the
|
---|
5255 | background; we recommend reading it.
|
---|
5256 |
|
---|
5257 | \sa event(), repaint(), update(), QPainter, QPixmap, QPaintEvent
|
---|
5258 | */
|
---|
5259 |
|
---|
5260 | void QWidget::paintEvent( QPaintEvent * )
|
---|
5261 | {
|
---|
5262 | }
|
---|
5263 |
|
---|
5264 |
|
---|
5265 | /*!
|
---|
5266 | This event handler can be reimplemented in a subclass to receive
|
---|
5267 | widget move events. When the widget receives this event, it is
|
---|
5268 | already at the new position.
|
---|
5269 |
|
---|
5270 | The old position is accessible through QMoveEvent::oldPos().
|
---|
5271 |
|
---|
5272 | \sa resizeEvent(), event(), move(), QMoveEvent
|
---|
5273 | */
|
---|
5274 |
|
---|
5275 | void QWidget::moveEvent( QMoveEvent * )
|
---|
5276 | {
|
---|
5277 | }
|
---|
5278 |
|
---|
5279 |
|
---|
5280 | /*!
|
---|
5281 | This event handler can be reimplemented in a subclass to receive
|
---|
5282 | widget resize events. When resizeEvent() is called, the widget
|
---|
5283 | already has its new geometry. The old size is accessible through
|
---|
5284 | QResizeEvent::oldSize().
|
---|
5285 |
|
---|
5286 | The widget will be erased and receive a paint event immediately
|
---|
5287 | after processing the resize event. No drawing need be (or should
|
---|
5288 | be) done inside this handler.
|
---|
5289 |
|
---|
5290 | Widgets that have been created with the \c WNoAutoErase flag
|
---|
5291 | will not be erased. Nevertheless, they will receive a paint event
|
---|
5292 | for their entire area afterwards. Again, no drawing needs to be
|
---|
5293 | done inside this handler.
|
---|
5294 |
|
---|
5295 | The default implementation calls updateMask() if the widget has
|
---|
5296 | \link QWidget::setAutoMask() automatic masking\endlink enabled.
|
---|
5297 |
|
---|
5298 | \sa moveEvent(), event(), resize(), QResizeEvent, paintEvent()
|
---|
5299 | */
|
---|
5300 |
|
---|
5301 | void QWidget::resizeEvent( QResizeEvent * )
|
---|
5302 | {
|
---|
5303 | if ( testWState(WState_AutoMask) )
|
---|
5304 | updateMask();
|
---|
5305 | }
|
---|
5306 |
|
---|
5307 | /*!
|
---|
5308 | This event handler, for event \a e, can be reimplemented in a
|
---|
5309 | subclass to receive widget close events.
|
---|
5310 |
|
---|
5311 | The default implementation calls e->accept(), which hides this
|
---|
5312 | widget. See the \l QCloseEvent documentation for more details.
|
---|
5313 |
|
---|
5314 | \sa event(), hide(), close(), QCloseEvent
|
---|
5315 | */
|
---|
5316 |
|
---|
5317 | void QWidget::closeEvent( QCloseEvent *e )
|
---|
5318 | {
|
---|
5319 | e->accept();
|
---|
5320 | }
|
---|
5321 |
|
---|
5322 |
|
---|
5323 | /*!
|
---|
5324 | This event handler, for event \a e, can be reimplemented in a
|
---|
5325 | subclass to receive widget context menu events.
|
---|
5326 |
|
---|
5327 | The default implementation calls e->ignore(), which rejects the
|
---|
5328 | context event. See the \l QContextMenuEvent documentation for
|
---|
5329 | more details.
|
---|
5330 |
|
---|
5331 | \sa event(), QContextMenuEvent
|
---|
5332 | */
|
---|
5333 |
|
---|
5334 | void QWidget::contextMenuEvent( QContextMenuEvent *e )
|
---|
5335 | {
|
---|
5336 | e->ignore();
|
---|
5337 | }
|
---|
5338 |
|
---|
5339 |
|
---|
5340 | /*!
|
---|
5341 | This event handler, for event \a e, can be reimplemented in a
|
---|
5342 | subclass to receive Input Method composition events. This handler
|
---|
5343 | is called when the user begins entering text using an Input Method.
|
---|
5344 |
|
---|
5345 | The default implementation calls e->ignore(), which rejects the
|
---|
5346 | Input Method event. See the \l QIMEvent documentation for more
|
---|
5347 | details.
|
---|
5348 |
|
---|
5349 | \sa event(), QIMEvent
|
---|
5350 | */
|
---|
5351 | void QWidget::imStartEvent( QIMEvent *e )
|
---|
5352 | {
|
---|
5353 | e->ignore();
|
---|
5354 | }
|
---|
5355 |
|
---|
5356 | /*!
|
---|
5357 | This event handler, for event \a e, can be reimplemented in a
|
---|
5358 | subclass to receive Input Method composition events. This handler
|
---|
5359 | is called when the user has entered some text using an Input Method.
|
---|
5360 |
|
---|
5361 | The default implementation calls e->ignore(), which rejects the
|
---|
5362 | Input Method event. See the \l QIMEvent documentation for more
|
---|
5363 | details.
|
---|
5364 |
|
---|
5365 | \sa event(), QIMEvent
|
---|
5366 | */
|
---|
5367 | void QWidget::imComposeEvent( QIMEvent *e )
|
---|
5368 | {
|
---|
5369 | e->ignore();
|
---|
5370 | }
|
---|
5371 |
|
---|
5372 |
|
---|
5373 | /*!
|
---|
5374 | This event handler, for event \a e, can be reimplemented in a
|
---|
5375 | subclass to receive Input Method composition events. This handler
|
---|
5376 | is called when the user has finished inputting text via an Input
|
---|
5377 | Method.
|
---|
5378 |
|
---|
5379 | The default implementation calls e->ignore(), which rejects the
|
---|
5380 | Input Method event. See the \l QIMEvent documentation for more
|
---|
5381 | details.
|
---|
5382 |
|
---|
5383 | \sa event(), QIMEvent
|
---|
5384 | */
|
---|
5385 | void QWidget::imEndEvent( QIMEvent *e )
|
---|
5386 | {
|
---|
5387 | e->ignore();
|
---|
5388 | }
|
---|
5389 |
|
---|
5390 |
|
---|
5391 | #ifndef QT_NO_DRAGANDDROP
|
---|
5392 |
|
---|
5393 | /*!
|
---|
5394 | This event handler is called when a drag is in progress and the
|
---|
5395 | mouse enters this widget.
|
---|
5396 |
|
---|
5397 | See the \link dnd.html Drag-and-drop documentation\endlink for an
|
---|
5398 | overview of how to provide drag-and-drop in your application.
|
---|
5399 |
|
---|
5400 | \sa QTextDrag, QImageDrag, QDragEnterEvent
|
---|
5401 | */
|
---|
5402 | void QWidget::dragEnterEvent( QDragEnterEvent * )
|
---|
5403 | {
|
---|
5404 | }
|
---|
5405 |
|
---|
5406 | /*!
|
---|
5407 | This event handler is called when a drag is in progress and the
|
---|
5408 | mouse enters this widget, and whenever it moves within the widget.
|
---|
5409 |
|
---|
5410 | See the \link dnd.html Drag-and-drop documentation\endlink for an
|
---|
5411 | overview of how to provide drag-and-drop in your application.
|
---|
5412 |
|
---|
5413 | \sa QTextDrag, QImageDrag, QDragMoveEvent
|
---|
5414 | */
|
---|
5415 | void QWidget::dragMoveEvent( QDragMoveEvent * )
|
---|
5416 | {
|
---|
5417 | }
|
---|
5418 |
|
---|
5419 | /*!
|
---|
5420 | This event handler is called when a drag is in progress and the
|
---|
5421 | mouse leaves this widget.
|
---|
5422 |
|
---|
5423 | See the \link dnd.html Drag-and-drop documentation\endlink for an
|
---|
5424 | overview of how to provide drag-and-drop in your application.
|
---|
5425 |
|
---|
5426 | \sa QTextDrag, QImageDrag, QDragLeaveEvent
|
---|
5427 | */
|
---|
5428 | void QWidget::dragLeaveEvent( QDragLeaveEvent * )
|
---|
5429 | {
|
---|
5430 | }
|
---|
5431 |
|
---|
5432 | /*!
|
---|
5433 | This event handler is called when the drag is dropped on this
|
---|
5434 | widget.
|
---|
5435 |
|
---|
5436 | See the \link dnd.html Drag-and-drop documentation\endlink for an
|
---|
5437 | overview of how to provide drag-and-drop in your application.
|
---|
5438 |
|
---|
5439 | \sa QTextDrag, QImageDrag, QDropEvent
|
---|
5440 | */
|
---|
5441 | void QWidget::dropEvent( QDropEvent * )
|
---|
5442 | {
|
---|
5443 | }
|
---|
5444 |
|
---|
5445 | #endif // QT_NO_DRAGANDDROP
|
---|
5446 |
|
---|
5447 | /*!
|
---|
5448 | This event handler can be reimplemented in a subclass to receive
|
---|
5449 | widget show events.
|
---|
5450 |
|
---|
5451 | Non-spontaneous show events are sent to widgets immediately before
|
---|
5452 | they are shown. The spontaneous show events of top-level widgets
|
---|
5453 | are delivered afterwards.
|
---|
5454 |
|
---|
5455 | \sa event(), QShowEvent
|
---|
5456 | */
|
---|
5457 | void QWidget::showEvent( QShowEvent * )
|
---|
5458 | {
|
---|
5459 | }
|
---|
5460 |
|
---|
5461 | /*!
|
---|
5462 | This event handler can be reimplemented in a subclass to receive
|
---|
5463 | widget hide events.
|
---|
5464 |
|
---|
5465 | Hide events are sent to widgets immediately after they have been
|
---|
5466 | hidden.
|
---|
5467 |
|
---|
5468 | \sa event(), QHideEvent
|
---|
5469 | */
|
---|
5470 | void QWidget::hideEvent( QHideEvent * )
|
---|
5471 | {
|
---|
5472 | }
|
---|
5473 |
|
---|
5474 | /*
|
---|
5475 | \fn QWidget::x11Event( MSG * )
|
---|
5476 |
|
---|
5477 | This special event handler can be reimplemented in a subclass to
|
---|
5478 | receive native X11 events.
|
---|
5479 |
|
---|
5480 | In your reimplementation of this function, if you want to stop the
|
---|
5481 | event being handled by Qt, return TRUE. If you return FALSE, this
|
---|
5482 | native event is passed back to Qt, which translates the event into
|
---|
5483 | a Qt event and sends it to the widget.
|
---|
5484 |
|
---|
5485 | \warning This function is not portable.
|
---|
5486 |
|
---|
5487 | \sa QApplication::x11EventFilter()
|
---|
5488 | */
|
---|
5489 |
|
---|
5490 |
|
---|
5491 | #if defined(Q_WS_MAC)
|
---|
5492 |
|
---|
5493 | /*!
|
---|
5494 | This special event handler can be reimplemented in a subclass to
|
---|
5495 | receive native Macintosh events.
|
---|
5496 |
|
---|
5497 | In your reimplementation of this function, if you want to stop the
|
---|
5498 | event being handled by Qt, return TRUE. If you return FALSE, this
|
---|
5499 | native event is passed back to Qt, which translates the event into
|
---|
5500 | a Qt event and sends it to the widget.
|
---|
5501 |
|
---|
5502 | \warning This function is not portable.
|
---|
5503 |
|
---|
5504 | \sa QApplication::macEventFilter()
|
---|
5505 | */
|
---|
5506 |
|
---|
5507 | bool QWidget::macEvent( MSG * )
|
---|
5508 | {
|
---|
5509 | return FALSE;
|
---|
5510 | }
|
---|
5511 |
|
---|
5512 | #endif
|
---|
5513 | #if defined(Q_WS_WIN)
|
---|
5514 |
|
---|
5515 | /*!
|
---|
5516 | This special event handler can be reimplemented in a subclass to
|
---|
5517 | receive native Windows events.
|
---|
5518 |
|
---|
5519 | In your reimplementation of this function, if you want to stop the
|
---|
5520 | event being handled by Qt, return TRUE. If you return FALSE, this
|
---|
5521 | native event is passed back to Qt, which translates the event into
|
---|
5522 | a Qt event and sends it to the widget.
|
---|
5523 |
|
---|
5524 | \warning This function is not portable.
|
---|
5525 |
|
---|
5526 | \sa QApplication::winEventFilter()
|
---|
5527 | */
|
---|
5528 | bool QWidget::winEvent( MSG * )
|
---|
5529 | {
|
---|
5530 | return FALSE;
|
---|
5531 | }
|
---|
5532 |
|
---|
5533 | #endif
|
---|
5534 | #if defined(Q_WS_X11)
|
---|
5535 |
|
---|
5536 | /*!
|
---|
5537 | This special event handler can be reimplemented in a subclass to
|
---|
5538 | receive native X11 events.
|
---|
5539 |
|
---|
5540 | In your reimplementation of this function, if you want to stop the
|
---|
5541 | event being handled by Qt, return TRUE. If you return FALSE, this
|
---|
5542 | native event is passed back to Qt, which translates the event into
|
---|
5543 | a Qt event and sends it to the widget.
|
---|
5544 |
|
---|
5545 | \warning This function is not portable.
|
---|
5546 |
|
---|
5547 | \sa QApplication::x11EventFilter()
|
---|
5548 | */
|
---|
5549 | bool QWidget::x11Event( XEvent * )
|
---|
5550 | {
|
---|
5551 | return FALSE;
|
---|
5552 | }
|
---|
5553 |
|
---|
5554 | #endif
|
---|
5555 | #if defined(Q_WS_QWS)
|
---|
5556 |
|
---|
5557 | /*!
|
---|
5558 | This special event handler can be reimplemented in a subclass to
|
---|
5559 | receive native Qt/Embedded events.
|
---|
5560 |
|
---|
5561 | In your reimplementation of this function, if you want to stop the
|
---|
5562 | event being handled by Qt, return TRUE. If you return FALSE, this
|
---|
5563 | native event is passed back to Qt, which translates the event into
|
---|
5564 | a Qt event and sends it to the widget.
|
---|
5565 |
|
---|
5566 | \warning This function is not portable.
|
---|
5567 |
|
---|
5568 | \sa QApplication::qwsEventFilter()
|
---|
5569 | */
|
---|
5570 | bool QWidget::qwsEvent( QWSEvent * )
|
---|
5571 | {
|
---|
5572 | return FALSE;
|
---|
5573 | }
|
---|
5574 |
|
---|
5575 | #endif
|
---|
5576 |
|
---|
5577 | /*!
|
---|
5578 | \property QWidget::autoMask
|
---|
5579 | \brief whether the auto mask feature is enabled for the widget
|
---|
5580 |
|
---|
5581 | Transparent widgets use a mask to define their visible region.
|
---|
5582 | QWidget has some built-in support to make the task of
|
---|
5583 | recalculating the mask easier. When setting auto mask to TRUE,
|
---|
5584 | updateMask() will be called whenever the widget is resized or
|
---|
5585 | changes its focus state. Note that you must reimplement
|
---|
5586 | updateMask() (which should include a call to setMask()) or nothing
|
---|
5587 | will happen.
|
---|
5588 |
|
---|
5589 | Note: when you re-implement resizeEvent(), focusInEvent() or
|
---|
5590 | focusOutEvent() in your custom widgets and still want to ensure
|
---|
5591 | that the auto mask calculation works, you should add:
|
---|
5592 |
|
---|
5593 | \code
|
---|
5594 | if ( autoMask() )
|
---|
5595 | updateMask();
|
---|
5596 | \endcode
|
---|
5597 |
|
---|
5598 | at the end of your event handlers. This is true for all member
|
---|
5599 | functions that change the appearance of the widget in a way that
|
---|
5600 | requires a recalculation of the mask.
|
---|
5601 |
|
---|
5602 | While being a technically appealing concept, masks have a big
|
---|
5603 | drawback: when using complex masks that cannot be expressed easily
|
---|
5604 | with relatively simple regions, they can be very slow on some
|
---|
5605 | window systems. The classic example is a transparent label. The
|
---|
5606 | complex shape of its contents makes it necessary to represent its
|
---|
5607 | mask by a bitmap, which consumes both memory and time. If all you
|
---|
5608 | want is to blend the background of several neighboring widgets
|
---|
5609 | together seamlessly, you will probably want to use
|
---|
5610 | setBackgroundOrigin() rather than a mask.
|
---|
5611 |
|
---|
5612 | \sa autoMask() updateMask() setMask() clearMask() setBackgroundOrigin()
|
---|
5613 | */
|
---|
5614 |
|
---|
5615 | bool QWidget::autoMask() const
|
---|
5616 | {
|
---|
5617 | return testWState(WState_AutoMask);
|
---|
5618 | }
|
---|
5619 |
|
---|
5620 | void QWidget::setAutoMask( bool enable )
|
---|
5621 | {
|
---|
5622 | if ( enable == autoMask() )
|
---|
5623 | return;
|
---|
5624 |
|
---|
5625 | if ( enable ) {
|
---|
5626 | setWState(WState_AutoMask);
|
---|
5627 | updateMask();
|
---|
5628 | } else {
|
---|
5629 | clearWState(WState_AutoMask);
|
---|
5630 | clearMask();
|
---|
5631 | }
|
---|
5632 | }
|
---|
5633 |
|
---|
5634 | /*!
|
---|
5635 | \enum QWidget::BackgroundOrigin
|
---|
5636 |
|
---|
5637 | This enum defines the origin used to draw a widget's background
|
---|
5638 | pixmap.
|
---|
5639 |
|
---|
5640 | The pixmap is drawn using the:
|
---|
5641 | \value WidgetOrigin widget's coordinate system.
|
---|
5642 | \value ParentOrigin parent's coordinate system.
|
---|
5643 | \value WindowOrigin top-level window's coordinate system.
|
---|
5644 | \value AncestorOrigin same origin as the parent uses.
|
---|
5645 | */
|
---|
5646 |
|
---|
5647 | /*!
|
---|
5648 | \property QWidget::backgroundOrigin
|
---|
5649 | \brief the origin of the widget's background
|
---|
5650 |
|
---|
5651 | The origin is either WidgetOrigin (the default), ParentOrigin,
|
---|
5652 | WindowOrigin or AncestorOrigin.
|
---|
5653 |
|
---|
5654 | This only makes a difference if the widget has a background
|
---|
5655 | pixmap, in which case positioning matters. Using \c WindowOrigin
|
---|
5656 | for several neighboring widgets makes the background blend
|
---|
5657 | together seamlessly. \c AncestorOrigin allows blending backgrounds
|
---|
5658 | seamlessly when an ancestor of the widget has an origin other than
|
---|
5659 | \c QWindowOrigin.
|
---|
5660 |
|
---|
5661 | \sa backgroundPixmap(), setBackgroundMode()
|
---|
5662 | */
|
---|
5663 | QWidget::BackgroundOrigin QWidget::backgroundOrigin() const
|
---|
5664 | {
|
---|
5665 | return extra ? (BackgroundOrigin)extra->bg_origin : WidgetOrigin;
|
---|
5666 | }
|
---|
5667 |
|
---|
5668 | void QWidget::setBackgroundOrigin( BackgroundOrigin origin )
|
---|
5669 | {
|
---|
5670 | if ( origin == backgroundOrigin() )
|
---|
5671 | return;
|
---|
5672 | createExtra();
|
---|
5673 | extra->bg_origin = origin;
|
---|
5674 | update();
|
---|
5675 | }
|
---|
5676 |
|
---|
5677 | /*!
|
---|
5678 | This function can be reimplemented in a subclass to support
|
---|
5679 | transparent widgets. It should be called whenever a widget changes
|
---|
5680 | state in a way that means that the shape mask must be recalculated.
|
---|
5681 |
|
---|
5682 | \sa setAutoMask(), updateMask(), setMask(), clearMask()
|
---|
5683 | */
|
---|
5684 | void QWidget::updateMask()
|
---|
5685 | {
|
---|
5686 | }
|
---|
5687 |
|
---|
5688 | /*!
|
---|
5689 | \internal
|
---|
5690 | Returns the offset of the widget from the backgroundOrigin.
|
---|
5691 |
|
---|
5692 | \sa setBackgroundMode(), backgroundMode(),
|
---|
5693 | */
|
---|
5694 | QPoint QWidget::backgroundOffset() const
|
---|
5695 | {
|
---|
5696 | if (!isTopLevel()) {
|
---|
5697 | switch(backgroundOrigin()) {
|
---|
5698 | case WidgetOrigin:
|
---|
5699 | break;
|
---|
5700 | case ParentOrigin:
|
---|
5701 | return pos();
|
---|
5702 | case WindowOrigin:
|
---|
5703 | {
|
---|
5704 | const QWidget *topl = this;
|
---|
5705 | while(topl && !topl->isTopLevel() && !topl->testWFlags(Qt::WSubWindow))
|
---|
5706 | topl = topl->parentWidget(TRUE);
|
---|
5707 | return mapTo((QWidget *)topl, QPoint(0, 0) );
|
---|
5708 | }
|
---|
5709 | case AncestorOrigin:
|
---|
5710 | {
|
---|
5711 | const QWidget *topl = this;
|
---|
5712 | bool ancestorIsWindowOrigin = FALSE;
|
---|
5713 | while(topl && !topl->isTopLevel() && !topl->testWFlags(Qt::WSubWindow))
|
---|
5714 | {
|
---|
5715 | if (!ancestorIsWindowOrigin) {
|
---|
5716 | if (topl->backgroundOrigin() == QWidget::WidgetOrigin)
|
---|
5717 | break;
|
---|
5718 | if (topl->backgroundOrigin() == QWidget::ParentOrigin)
|
---|
5719 | {
|
---|
5720 | topl = topl->parentWidget(TRUE);
|
---|
5721 | break;
|
---|
5722 | }
|
---|
5723 | if (topl->backgroundOrigin() == QWidget::WindowOrigin)
|
---|
5724 | ancestorIsWindowOrigin = TRUE;
|
---|
5725 | }
|
---|
5726 | topl = topl->parentWidget(TRUE);
|
---|
5727 | }
|
---|
5728 |
|
---|
5729 | return mapTo((QWidget *) topl, QPoint(0,0) );
|
---|
5730 | }
|
---|
5731 | }
|
---|
5732 | }
|
---|
5733 | // fall back
|
---|
5734 | return QPoint(0,0);
|
---|
5735 | }
|
---|
5736 |
|
---|
5737 | /*!
|
---|
5738 | \fn QLayout* QWidget::layout () const
|
---|
5739 |
|
---|
5740 | Returns the layout engine that manages the geometry of this
|
---|
5741 | widget's children.
|
---|
5742 |
|
---|
5743 | If the widget does not have a layout, layout() returns 0.
|
---|
5744 |
|
---|
5745 | \sa sizePolicy()
|
---|
5746 | */
|
---|
5747 |
|
---|
5748 |
|
---|
5749 | /* Sets this widget to use layout \a l to manage the geometry of its
|
---|
5750 | children.
|
---|
5751 |
|
---|
5752 | If the widget already had a layout, the old layout is
|
---|
5753 | forgotten. (Note that it is not deleted.)
|
---|
5754 |
|
---|
5755 | \sa layout() QLayout sizePolicy()
|
---|
5756 | */
|
---|
5757 | #ifndef QT_NO_LAYOUT
|
---|
5758 | void QWidget::setLayout( QLayout *l )
|
---|
5759 | {
|
---|
5760 | lay_out = l;
|
---|
5761 | }
|
---|
5762 | #endif
|
---|
5763 |
|
---|
5764 | /*!
|
---|
5765 | \property QWidget::sizePolicy
|
---|
5766 | \brief the default layout behavior of the widget
|
---|
5767 |
|
---|
5768 | If there is a QLayout that manages this widget's children, the
|
---|
5769 | size policy specified by that layout is used. If there is no such
|
---|
5770 | QLayout, the result of this function is used.
|
---|
5771 |
|
---|
5772 | The default policy is Preferred/Preferred, which means that the
|
---|
5773 | widget can be freely resized, but prefers to be the size
|
---|
5774 | sizeHint() returns. Button-like widgets set the size policy to
|
---|
5775 | specify that they may stretch horizontally, but are fixed
|
---|
5776 | vertically. The same applies to lineedit controls (such as
|
---|
5777 | QLineEdit, QSpinBox or an editable QComboBox) and other
|
---|
5778 | horizontally orientated widgets (such as QProgressBar).
|
---|
5779 | QToolButton's are normally square, so they allow growth in both
|
---|
5780 | directions. Widgets that support different directions (such as
|
---|
5781 | QSlider, QScrollBar or QHeader) specify stretching in the
|
---|
5782 | respective direction only. Widgets that can provide scrollbars
|
---|
5783 | (usually subclasses of QScrollView) tend to specify that they can
|
---|
5784 | use additional space, and that they can make do with less than
|
---|
5785 | sizeHint().
|
---|
5786 |
|
---|
5787 | \sa sizeHint() QLayout QSizePolicy updateGeometry()
|
---|
5788 | */
|
---|
5789 | QSizePolicy QWidget::sizePolicy() const
|
---|
5790 | {
|
---|
5791 | return extra ? extra->size_policy
|
---|
5792 | : QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
|
---|
5793 | }
|
---|
5794 |
|
---|
5795 | void QWidget::setSizePolicy( QSizePolicy policy )
|
---|
5796 | {
|
---|
5797 | setWState( WState_OwnSizePolicy );
|
---|
5798 | if ( policy == sizePolicy() )
|
---|
5799 | return;
|
---|
5800 | createExtra();
|
---|
5801 | extra->size_policy = policy;
|
---|
5802 | updateGeometry();
|
---|
5803 | }
|
---|
5804 |
|
---|
5805 | /*!
|
---|
5806 | \overload void QWidget::setSizePolicy( QSizePolicy::SizeType hor, QSizePolicy::SizeType ver, bool hfw )
|
---|
5807 |
|
---|
5808 | Sets the size policy of the widget to \a hor, \a ver and \a hfw
|
---|
5809 | (height for width).
|
---|
5810 |
|
---|
5811 | \sa QSizePolicy::QSizePolicy()
|
---|
5812 | */
|
---|
5813 |
|
---|
5814 | /*!
|
---|
5815 | Returns the preferred height for this widget, given the width \a
|
---|
5816 | w. The default implementation returns 0, indicating that the
|
---|
5817 | preferred height does not depend on the width.
|
---|
5818 |
|
---|
5819 | \warning Does not look at the widget's layout.
|
---|
5820 | */
|
---|
5821 |
|
---|
5822 | int QWidget::heightForWidth( int w ) const
|
---|
5823 | {
|
---|
5824 | (void)w;
|
---|
5825 | return 0;
|
---|
5826 | }
|
---|
5827 |
|
---|
5828 | /*!
|
---|
5829 | \property QWidget::customWhatsThis
|
---|
5830 | \brief whether the widget wants to handle What's This help manually
|
---|
5831 |
|
---|
5832 | The default implementation of customWhatsThis() returns FALSE,
|
---|
5833 | which means the widget will not receive any events in Whats This
|
---|
5834 | mode.
|
---|
5835 |
|
---|
5836 | The widget may leave What's This mode by calling
|
---|
5837 | QWhatsThis::leaveWhatsThisMode(), with or without actually
|
---|
5838 | displaying any help text.
|
---|
5839 |
|
---|
5840 | You can also reimplement customWhatsThis() if your widget is a
|
---|
5841 | "passive interactor" supposed to work under all circumstances.
|
---|
5842 | Simply don't call QWhatsThis::leaveWhatsThisMode() in that case.
|
---|
5843 |
|
---|
5844 | \sa QWhatsThis::inWhatsThisMode() QWhatsThis::leaveWhatsThisMode()
|
---|
5845 | */
|
---|
5846 | bool QWidget::customWhatsThis() const
|
---|
5847 | {
|
---|
5848 | return FALSE;
|
---|
5849 | }
|
---|
5850 |
|
---|
5851 | /*!
|
---|
5852 | Returns the visible child widget at pixel position \a (x, y) in
|
---|
5853 | the widget's own coordinate system.
|
---|
5854 |
|
---|
5855 | If \a includeThis is TRUE, and there is no child visible at \a (x,
|
---|
5856 | y), the widget itself is returned.
|
---|
5857 | */
|
---|
5858 | QWidget *QWidget::childAt( int x, int y, bool includeThis ) const
|
---|
5859 | {
|
---|
5860 | if ( !rect().contains( x, y ) )
|
---|
5861 | return 0;
|
---|
5862 | if ( children() ) {
|
---|
5863 | QObjectListIt it( *children() );
|
---|
5864 | it.toLast();
|
---|
5865 | QWidget *w, *t;
|
---|
5866 | while( (w=(QWidget *)it.current()) != 0 ) {
|
---|
5867 | --it;
|
---|
5868 | if ( w->isWidgetType() && !w->isTopLevel() && !w->isHidden() ) {
|
---|
5869 | if ( ( t = w->childAt( x - w->x(), y - w->y(), TRUE ) ) )
|
---|
5870 | return t;
|
---|
5871 | }
|
---|
5872 | }
|
---|
5873 | }
|
---|
5874 | if ( includeThis )
|
---|
5875 | return (QWidget*)this;
|
---|
5876 | return 0;
|
---|
5877 | }
|
---|
5878 |
|
---|
5879 | /*!
|
---|
5880 | \overload
|
---|
5881 |
|
---|
5882 | Returns the visible child widget at point \a p in the widget's own
|
---|
5883 | coordinate system.
|
---|
5884 |
|
---|
5885 | If \a includeThis is TRUE, and there is no child visible at \a p,
|
---|
5886 | the widget itself is returned.
|
---|
5887 |
|
---|
5888 | */
|
---|
5889 | QWidget *QWidget::childAt( const QPoint & p, bool includeThis ) const
|
---|
5890 | {
|
---|
5891 | return childAt( p.x(), p.y(), includeThis );
|
---|
5892 | }
|
---|
5893 |
|
---|
5894 |
|
---|
5895 | /*!
|
---|
5896 | Notifies the layout system that this widget has changed and may
|
---|
5897 | need to change geometry.
|
---|
5898 |
|
---|
5899 | Call this function if the sizeHint() or sizePolicy() have changed.
|
---|
5900 |
|
---|
5901 | For explicitly hidden widgets, updateGeometry() is a no-op. The
|
---|
5902 | layout system will be notified as soon as the widget is shown.
|
---|
5903 | */
|
---|
5904 |
|
---|
5905 | void QWidget::updateGeometry()
|
---|
5906 | {
|
---|
5907 | if ( !isTopLevel() && isShown() )
|
---|
5908 | QApplication::postEvent( parentWidget(),
|
---|
5909 | new QEvent( QEvent::LayoutHint ) );
|
---|
5910 | }
|
---|
5911 |
|
---|
5912 |
|
---|
5913 | /*!
|
---|
5914 | Reparents the widget. The widget gets a new \a parent, new widget
|
---|
5915 | flags (\a f, but as usual, use 0) at a new position in its new
|
---|
5916 | parent (\a p).
|
---|
5917 |
|
---|
5918 | If \a showIt is TRUE, show() is called once the widget has been
|
---|
5919 | reparented.
|
---|
5920 |
|
---|
5921 | If the new parent widget is in a different top-level widget, the
|
---|
5922 | reparented widget and its children are appended to the end of the
|
---|
5923 | \link setFocusPolicy() tab chain \endlink of the new parent
|
---|
5924 | widget, in the same internal order as before. If one of the moved
|
---|
5925 | widgets had keyboard focus, reparent() calls clearFocus() for that
|
---|
5926 | widget.
|
---|
5927 |
|
---|
5928 | If the new parent widget is in the same top-level widget as the
|
---|
5929 | old parent, reparent doesn't change the tab order or keyboard
|
---|
5930 | focus.
|
---|
5931 |
|
---|
5932 | \warning It is extremely unlikely that you will ever need this
|
---|
5933 | function. If you have a widget that changes its content
|
---|
5934 | dynamically, it is far easier to use \l QWidgetStack or \l
|
---|
5935 | QWizard.
|
---|
5936 |
|
---|
5937 | \sa getWFlags()
|
---|
5938 | */
|
---|
5939 |
|
---|
5940 | void QWidget::reparent( QWidget *parent, WFlags f, const QPoint &p,
|
---|
5941 | bool showIt )
|
---|
5942 | {
|
---|
5943 | reparentSys( parent, f, p, showIt );
|
---|
5944 | QEvent e( QEvent::Reparent );
|
---|
5945 | QApplication::sendEvent( this, &e );
|
---|
5946 | if (!own_font)
|
---|
5947 | unsetFont();
|
---|
5948 | else
|
---|
5949 | setFont( fnt.resolve( qt_naturalWidgetFont( this ) ) );
|
---|
5950 | #ifndef QT_NO_PALETTE
|
---|
5951 | if (!own_palette)
|
---|
5952 | unsetPalette();
|
---|
5953 | #endif
|
---|
5954 | }
|
---|
5955 |
|
---|
5956 | /*!
|
---|
5957 | \overload
|
---|
5958 |
|
---|
5959 | A convenience version of reparent that does not take widget flags
|
---|
5960 | as argument.
|
---|
5961 |
|
---|
5962 | Calls reparent(\a parent, getWFlags() \& ~\l WType_Mask, \a p, \a
|
---|
5963 | showIt).
|
---|
5964 | */
|
---|
5965 | void QWidget::reparent( QWidget *parent, const QPoint & p,
|
---|
5966 | bool showIt )
|
---|
5967 | {
|
---|
5968 | reparent( parent, getWFlags() & ~WType_Mask, p, showIt );
|
---|
5969 | }
|
---|
5970 |
|
---|
5971 | /*!
|
---|
5972 | \property QWidget::ownCursor
|
---|
5973 | \brief whether the widget uses its own cursor
|
---|
5974 |
|
---|
5975 | If FALSE, the widget uses its parent widget's cursor.
|
---|
5976 |
|
---|
5977 | \sa cursor
|
---|
5978 | */
|
---|
5979 |
|
---|
5980 | /*!
|
---|
5981 | \property QWidget::ownFont
|
---|
5982 | \brief whether the widget uses its own font
|
---|
5983 |
|
---|
5984 | If FALSE, the widget uses its parent widget's font.
|
---|
5985 |
|
---|
5986 | \sa font
|
---|
5987 | */
|
---|
5988 |
|
---|
5989 | /*!
|
---|
5990 | \property QWidget::ownPalette
|
---|
5991 | \brief whether the widget uses its own palette
|
---|
5992 |
|
---|
5993 | If FALSE, the widget uses its parent widget's palette.
|
---|
5994 |
|
---|
5995 | \sa palette
|
---|
5996 | */
|
---|
5997 |
|
---|
5998 |
|
---|
5999 | void QWidget::repaint( bool erase )
|
---|
6000 | {
|
---|
6001 | repaint( visibleRect(), erase );
|
---|
6002 | }
|
---|
6003 |
|
---|
6004 |
|
---|
6005 |
|
---|
6006 |
|
---|
6007 | /*!\obsolete Use paletteBackgroundColor() or eraseColor() instead. */
|
---|
6008 | const QColor & QWidget::backgroundColor() const { return eraseColor(); }
|
---|
6009 | /*!\obsolete Use setPaletteBackgroundColor() or setEraseColor() instead. */
|
---|
6010 | void QWidget::setBackgroundColor( const QColor &c ) { setEraseColor( c ); }
|
---|
6011 | /*!\obsolete Use paletteBackgroundPixmap() or erasePixmap() instead. */
|
---|
6012 | const QPixmap *QWidget::backgroundPixmap() const { return erasePixmap(); }
|
---|
6013 | /*!\obsolete Use setPaletteBackgroundPixmap() or setErasePixmap() instead. */
|
---|
6014 | void QWidget::setBackgroundPixmap( const QPixmap &pm ) { setErasePixmap( pm ); }
|
---|
6015 |
|
---|
6016 |
|
---|
6017 | // documentation in qdesktopwidget_win.cpp
|
---|
6018 | void QDesktopWidget::insertChild( QObject *obj )
|
---|
6019 | {
|
---|
6020 | if ( obj->isWidgetType() )
|
---|
6021 | return;
|
---|
6022 | QWidget::insertChild( obj );
|
---|
6023 | }
|
---|
6024 |
|
---|
6025 | /*!
|
---|
6026 | \property QWidget::windowOpacity
|
---|
6027 |
|
---|
6028 | \brief The level of opacity for the window.
|
---|
6029 |
|
---|
6030 | The valid range of opacity is from 1.0 (completely opaque) to
|
---|
6031 | 0.0 (completely transparent).
|
---|
6032 |
|
---|
6033 | By default the value of this property is 1.0.
|
---|
6034 |
|
---|
6035 | This feature is only present on Mac OS X and Windows 2000 and up.
|
---|
6036 |
|
---|
6037 | \warning Changing this property from opaque to transparent might issue a
|
---|
6038 | paint event that needs to be processed before the window is displayed
|
---|
6039 | correctly. This affects mainly the use of QPixmap::grabWindow(). Also note
|
---|
6040 | that semi-transparent windows update and resize significantely slower than
|
---|
6041 | opaque windows.
|
---|
6042 | */
|
---|