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