| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: qwidget.cpp 57 2006-01-19 21:22:10Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Implementation of QWidget class
|
|---|
| 5 | **
|
|---|
| 6 | ** Created : 931031
|
|---|
| 7 | **
|
|---|
| 8 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
|
|---|
| 9 | **
|
|---|
| 10 | ** This file is part of the kernel module of the Qt GUI Toolkit.
|
|---|
| 11 | **
|
|---|
| 12 | ** This file may be distributed under the terms of the Q Public License
|
|---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
|---|
| 14 | ** LICENSE.QPL included in the packaging of this file.
|
|---|
| 15 | **
|
|---|
| 16 | ** This file may be distributed and/or modified under the terms of the
|
|---|
| 17 | ** GNU General Public License version 2 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 19 | ** packaging of this file.
|
|---|
| 20 | **
|
|---|
| 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
|---|
| 22 | ** licenses may use this file in accordance with the Qt Commercial License
|
|---|
| 23 | ** Agreement provided with the Software.
|
|---|
| 24 | **
|
|---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 27 | **
|
|---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|---|
| 29 | ** information about Qt Commercial License Agreements.
|
|---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|---|
| 32 | **
|
|---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
|---|
| 34 | ** not clear to you.
|
|---|
| 35 | **
|
|---|
| 36 | **********************************************************************/
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | #include "qobjectlist.h"
|
|---|
| 40 | #include "qwidget.h"
|
|---|
| 41 | #include "qwidgetlist.h"
|
|---|
| 42 | #include "qwidgetintdict.h"
|
|---|
| 43 | #include "qptrdict.h"
|
|---|
| 44 | #include "qfocusdata.h"
|
|---|
| 45 | #include "qcursor.h"
|
|---|
| 46 | #include "qpixmap.h"
|
|---|
| 47 | #include "qapplication.h"
|
|---|
| 48 | #include "qapplication_p.h"
|
|---|
| 49 | #include "qbrush.h"
|
|---|
| 50 | #include "qlayout.h"
|
|---|
| 51 | #include "qstylefactory.h"
|
|---|
| 52 | #include "qcleanuphandler.h"
|
|---|
| 53 | #include "qstyle.h"
|
|---|
| 54 | #include "qmetaobject.h"
|
|---|
| 55 | #include "qguardedptr.h"
|
|---|
| 56 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
|---|
| 57 | #include "qaccessible.h"
|
|---|
| 58 | #endif
|
|---|
| 59 | #if defined(Q_WS_WIN)
|
|---|
| 60 | #include "qt_windows.h"
|
|---|
| 61 | #include "qinputcontext_p.h"
|
|---|
| 62 | #endif
|
|---|
| 63 | #if defined(Q_WS_PM)
|
|---|
| 64 | #include "qt_os2.h"
|
|---|
| 65 | #endif
|
|---|
| 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
|
|---|
| 1132 | #if !defined(Q_WS_PM)
|
|---|
| 1133 | x->savedFlags = 0;
|
|---|
| 1134 | #endif
|
|---|
| 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 |
|
|---|
| 1473 | setWindowState((windowState() & ~WindowActive) | WindowMinimized);
|
|---|
| 1474 | show();
|
|---|
| 1475 | if (!isTopLevel())
|
|---|
| 1476 | QApplication::sendPostedEvents(this, QEvent::ShowMinimized);
|
|---|
| 1477 | }
|
|---|
| 1478 |
|
|---|
| 1479 | /*!
|
|---|
| 1480 | \property QWidget::maximized
|
|---|
| 1481 | \brief whether this widget is maximized
|
|---|
| 1482 |
|
|---|
| 1483 | This property is only relevant for top-level widgets.
|
|---|
| 1484 |
|
|---|
| 1485 | Note that due to limitations in some window-systems, this does not
|
|---|
| 1486 | always report the expected results (e.g. if the user on X11
|
|---|
| 1487 | maximizes the window via the window manager, Qt has no way of
|
|---|
| 1488 | distinguishing this from any other resize). This is expected to
|
|---|
| 1489 | improve as window manager protocols evolve.
|
|---|
| 1490 |
|
|---|
| 1491 | \sa windowState(), showMaximized(), visible, show(), hide(), showNormal(), minimized
|
|---|
| 1492 | */
|
|---|
| 1493 | bool QWidget::isMaximized() const
|
|---|
| 1494 | { return testWState(WState_Maximized); }
|
|---|
| 1495 |
|
|---|
| 1496 |
|
|---|
| 1497 |
|
|---|
| 1498 | /*! Returns the current window state. The window state is a OR'ed
|
|---|
| 1499 | combination of Qt::WindowState: \c WindowMinimized, \c
|
|---|
| 1500 | WindowMaximized, \c WindowFullScreen and \c WindowActive.
|
|---|
| 1501 |
|
|---|
| 1502 | \sa Qt::WindowState setWindowState()
|
|---|
| 1503 | */
|
|---|
| 1504 | uint QWidget::windowState() const
|
|---|
| 1505 | {
|
|---|
| 1506 | uint state = 0;
|
|---|
| 1507 | if (testWState(WState_Minimized))
|
|---|
| 1508 | state |= WindowMinimized;
|
|---|
| 1509 | if (testWState(WState_Maximized))
|
|---|
| 1510 | state |= WindowMaximized;
|
|---|
| 1511 | if (testWState(WState_FullScreen))
|
|---|
| 1512 | state |= WindowFullScreen;
|
|---|
| 1513 | if (isActiveWindow())
|
|---|
| 1514 | state |= WindowActive;
|
|---|
| 1515 | return state;
|
|---|
| 1516 | }
|
|---|
| 1517 |
|
|---|
| 1518 | /*!
|
|---|
| 1519 | \fn void QWidget::setWindowState(uint windowState)
|
|---|
| 1520 |
|
|---|
| 1521 | Sets the window state to \a windowState. The window state is a OR'ed
|
|---|
| 1522 | combination of Qt::WindowState: \c WindowMinimized, \c
|
|---|
| 1523 | WindowMaximized, \c WindowFullScreen and \c WindowActive.
|
|---|
| 1524 |
|
|---|
| 1525 | If the window is not visible (i.e. isVisible() returns FALSE), the
|
|---|
| 1526 | window state will take effect when show() is called. For visible
|
|---|
| 1527 | windows, the change is immediate. For example, to toggle between
|
|---|
| 1528 | full-screen and mormal mode, use the following code:
|
|---|
| 1529 |
|
|---|
| 1530 | \code
|
|---|
| 1531 | w->setWindowState(w->windowState() ^ WindowFullScreen);
|
|---|
| 1532 | \endcode
|
|---|
| 1533 |
|
|---|
| 1534 | In order to restore and activate a minimized window (while
|
|---|
| 1535 | preserving its maximized and/or full-screen state), use the following:
|
|---|
| 1536 |
|
|---|
| 1537 | \code
|
|---|
| 1538 | w->setWindowState(w->windowState() & ~WindowMinimized | WindowActive);
|
|---|
| 1539 | \endcode
|
|---|
| 1540 |
|
|---|
| 1541 | Note: On some window systems \c WindowActive is not immediate, and may be
|
|---|
| 1542 | ignored in certain cases.
|
|---|
| 1543 |
|
|---|
| 1544 | \sa Qt::WindowState windowState()
|
|---|
| 1545 | */
|
|---|
| 1546 |
|
|---|
| 1547 | /*!
|
|---|
| 1548 | \property QWidget::fullScreen
|
|---|
| 1549 | \brief whether the widget is full screen
|
|---|
| 1550 |
|
|---|
| 1551 | \sa windowState(), minimized, maximized
|
|---|
| 1552 | */
|
|---|
| 1553 | bool QWidget::isFullScreen() const
|
|---|
| 1554 | { return testWState(WState_FullScreen); }
|
|---|
| 1555 |
|
|---|
| 1556 | /*!
|
|---|
| 1557 | Shows the widget in full-screen mode.
|
|---|
| 1558 |
|
|---|
| 1559 | Calling this function only affects top-level widgets.
|
|---|
| 1560 |
|
|---|
| 1561 | To return from full-screen mode, call showNormal().
|
|---|
| 1562 |
|
|---|
| 1563 | Full-screen mode works fine under Windows, but has certain
|
|---|
| 1564 | problems under X. These problems are due to limitations of the
|
|---|
| 1565 | ICCCM protocol that specifies the communication between X11
|
|---|
| 1566 | clients and the window manager. ICCCM simply does not understand
|
|---|
| 1567 | the concept of non-decorated full-screen windows. Therefore, the
|
|---|
| 1568 | best we can do is to request a borderless window and place and
|
|---|
| 1569 | resize it to fill the entire screen. Depending on the window
|
|---|
| 1570 | manager, this may or may not work. The borderless window is
|
|---|
| 1571 | requested using MOTIF hints, which are at least partially
|
|---|
| 1572 | supported by virtually all modern window managers.
|
|---|
| 1573 |
|
|---|
| 1574 | An alternative would be to bypass the window manager entirely and
|
|---|
| 1575 | create a window with the WX11BypassWM flag. This has other severe
|
|---|
| 1576 | problems though, like totally broken keyboard focus and very
|
|---|
| 1577 | strange effects on desktop changes or when the user raises other
|
|---|
| 1578 | windows.
|
|---|
| 1579 |
|
|---|
| 1580 | X11 window managers that follow modern post-ICCCM specifications
|
|---|
| 1581 | support full-screen mode properly.
|
|---|
| 1582 |
|
|---|
| 1583 | \sa showNormal(), showMaximized(), show(), hide(), isVisible()
|
|---|
| 1584 | */
|
|---|
| 1585 | void QWidget::showFullScreen()
|
|---|
| 1586 | {
|
|---|
| 1587 | if (isFullScreen()) return;
|
|---|
| 1588 |
|
|---|
| 1589 | setWindowState(windowState() | WindowFullScreen);
|
|---|
| 1590 | show();
|
|---|
| 1591 | if (!isTopLevel())
|
|---|
| 1592 | QApplication::sendPostedEvents(this, QEvent::ShowFullScreen);
|
|---|
| 1593 | setActiveWindow();
|
|---|
| 1594 | }
|
|---|
| 1595 |
|
|---|
| 1596 | /*!
|
|---|
| 1597 | Shows the widget maximized.
|
|---|
| 1598 |
|
|---|
| 1599 | Calling this function only affects \link isTopLevel() top-level
|
|---|
| 1600 | widgets\endlink.
|
|---|
| 1601 |
|
|---|
| 1602 | On X11, this function may not work properly with certain window
|
|---|
| 1603 | managers. See the \link geometry.html Window Geometry
|
|---|
| 1604 | documentation\endlink for an explanation.
|
|---|
| 1605 |
|
|---|
| 1606 | \sa setWindowState(), showNormal(), showMinimized(), show(), hide(), isVisible()
|
|---|
| 1607 | */
|
|---|
| 1608 | void QWidget::showMaximized()
|
|---|
| 1609 | {
|
|---|
| 1610 | if (isMaximized()) return;
|
|---|
| 1611 |
|
|---|
| 1612 | setWindowState((windowState() & ~WindowMinimized) | WindowMaximized);
|
|---|
| 1613 | show();
|
|---|
| 1614 | if (!isTopLevel())
|
|---|
| 1615 | QApplication::sendPostedEvents(this, QEvent::ShowMaximized);
|
|---|
| 1616 | }
|
|---|
| 1617 |
|
|---|
| 1618 | /*!
|
|---|
| 1619 | Restores the widget after it has been maximized or minimized.
|
|---|
| 1620 |
|
|---|
| 1621 | Calling this function only affects \link isTopLevel() top-level
|
|---|
| 1622 | widgets\endlink.
|
|---|
| 1623 |
|
|---|
| 1624 | \sa setWindowState(), showMinimized(), showMaximized(), show(), hide(), isVisible()
|
|---|
| 1625 | */
|
|---|
| 1626 | void QWidget::showNormal()
|
|---|
| 1627 | {
|
|---|
| 1628 | setWindowState(WindowNoState);
|
|---|
| 1629 | show();
|
|---|
| 1630 | if (!isTopLevel())
|
|---|
| 1631 | QApplication::sendPostedEvents(this, QEvent::ShowNormal);
|
|---|
| 1632 | }
|
|---|
| 1633 |
|
|---|
| 1634 | /*!
|
|---|
| 1635 | Returns TRUE if this widget would become enabled if \a ancestor is
|
|---|
| 1636 | enabled; otherwise returns FALSE.
|
|---|
| 1637 |
|
|---|
| 1638 | This is the case if neither the widget itself nor every parent up
|
|---|
| 1639 | to but excluding \a ancestor has been explicitly disabled.
|
|---|
| 1640 |
|
|---|
| 1641 | isEnabledTo(0) is equivalent to isEnabled().
|
|---|
| 1642 |
|
|---|
| 1643 | \sa setEnabled() enabled
|
|---|
| 1644 | */
|
|---|
| 1645 |
|
|---|
| 1646 | bool QWidget::isEnabledTo( QWidget* ancestor ) const
|
|---|
| 1647 | {
|
|---|
| 1648 | const QWidget * w = this;
|
|---|
| 1649 | while ( w && !w->testWState(WState_ForceDisabled)
|
|---|
| 1650 | && !w->isTopLevel()
|
|---|
| 1651 | && w->parentWidget()
|
|---|
| 1652 | && w->parentWidget() != ancestor )
|
|---|
| 1653 | w = w->parentWidget();
|
|---|
| 1654 | return !w->testWState( WState_ForceDisabled );
|
|---|
| 1655 | }
|
|---|
| 1656 |
|
|---|
| 1657 |
|
|---|
| 1658 | /*!
|
|---|
| 1659 | \fn bool QWidget::isEnabledToTLW() const
|
|---|
| 1660 | \obsolete
|
|---|
| 1661 |
|
|---|
| 1662 | This function is deprecated. It is equivalent to isEnabled()
|
|---|
| 1663 | */
|
|---|
| 1664 |
|
|---|
| 1665 | /*!
|
|---|
| 1666 | \property QWidget::enabled
|
|---|
| 1667 | \brief whether the widget is enabled
|
|---|
| 1668 |
|
|---|
| 1669 | An enabled widget receives keyboard and mouse events; a disabled
|
|---|
| 1670 | widget does not. In fact, an enabled widget only receives keyboard
|
|---|
| 1671 | events when it is in focus.
|
|---|
| 1672 |
|
|---|
| 1673 | Some widgets display themselves differently when they are
|
|---|
| 1674 | disabled. For example a button might draw its label grayed out. If
|
|---|
| 1675 | your widget needs to know when it becomes enabled or disabled, you
|
|---|
| 1676 | can reimplement the enabledChange() function.
|
|---|
| 1677 |
|
|---|
| 1678 | Disabling a widget implicitly disables all its children. Enabling
|
|---|
| 1679 | respectively enables all child widgets unless they have been
|
|---|
| 1680 | explicitly disabled.
|
|---|
| 1681 |
|
|---|
| 1682 | \sa isEnabled(), isEnabledTo(), QKeyEvent, QMouseEvent, enabledChange()
|
|---|
| 1683 | */
|
|---|
| 1684 | void QWidget::setEnabled( bool enable )
|
|---|
| 1685 | {
|
|---|
| 1686 | if ( enable )
|
|---|
| 1687 | clearWState( WState_ForceDisabled );
|
|---|
| 1688 | else
|
|---|
| 1689 | setWState( WState_ForceDisabled );
|
|---|
| 1690 |
|
|---|
| 1691 | if ( !isTopLevel() && parentWidget() &&
|
|---|
| 1692 | !parentWidget()->isEnabled() && enable )
|
|---|
| 1693 | return; // nothing we can do
|
|---|
| 1694 |
|
|---|
| 1695 | if ( enable ) {
|
|---|
| 1696 | if ( testWState(WState_Disabled) ) {
|
|---|
| 1697 | clearWState( WState_Disabled );
|
|---|
| 1698 | setBackgroundFromMode();
|
|---|
| 1699 | enabledChange( !enable );
|
|---|
| 1700 | if ( children() ) {
|
|---|
| 1701 | QObjectListIt it( *children() );
|
|---|
| 1702 | QWidget *w;
|
|---|
| 1703 | while( (w = (QWidget *)it.current()) != 0 ) {
|
|---|
| 1704 | ++it;
|
|---|
| 1705 | if ( w->isWidgetType() &&
|
|---|
| 1706 | !w->testWState( WState_ForceDisabled ) )
|
|---|
| 1707 | w->setEnabled( TRUE );
|
|---|
| 1708 | }
|
|---|
| 1709 | }
|
|---|
| 1710 | }
|
|---|
| 1711 | } else {
|
|---|
| 1712 | if ( !testWState(WState_Disabled) ) {
|
|---|
| 1713 | if ( focusWidget() == this && ( !parentWidget() || parentWidget()->isEnabled() ) ) {
|
|---|
| 1714 | if ( !focusNextPrevChild( TRUE ) )
|
|---|
| 1715 | clearFocus();
|
|---|
| 1716 | }
|
|---|
| 1717 | setWState( WState_Disabled );
|
|---|
| 1718 | setBackgroundFromMode();
|
|---|
| 1719 | enabledChange( !enable );
|
|---|
| 1720 | if ( children() ) {
|
|---|
| 1721 | QObjectListIt it( *children() );
|
|---|
| 1722 | QWidget *w;
|
|---|
| 1723 | while( (w = (QWidget *)it.current()) != 0 ) {
|
|---|
| 1724 | ++it;
|
|---|
| 1725 | if ( w->isWidgetType() && w->isEnabled() ) {
|
|---|
| 1726 | w->setEnabled( FALSE );
|
|---|
| 1727 | w->clearWState( WState_ForceDisabled );
|
|---|
| 1728 | }
|
|---|
| 1729 | }
|
|---|
| 1730 | }
|
|---|
| 1731 | }
|
|---|
| 1732 | }
|
|---|
| 1733 | #if defined(Q_WS_X11)
|
|---|
| 1734 | if ( testWState( WState_OwnCursor ) ) {
|
|---|
| 1735 | // enforce the windows behavior of clearing the cursor on
|
|---|
| 1736 | // disabled widgets
|
|---|
| 1737 |
|
|---|
| 1738 | extern void qt_x11_enforce_cursor( QWidget * w ); // defined in qwidget_x11.cpp
|
|---|
| 1739 | qt_x11_enforce_cursor( this );
|
|---|
| 1740 | }
|
|---|
| 1741 | #endif
|
|---|
| 1742 | #ifdef Q_WS_WIN
|
|---|
| 1743 | QInputContext::enable( this, im_enabled & !((bool)testWState(WState_Disabled)) );
|
|---|
| 1744 | #endif
|
|---|
| 1745 | }
|
|---|
| 1746 |
|
|---|
| 1747 | /*!
|
|---|
| 1748 | Disables widget input events if \a disable is TRUE; otherwise
|
|---|
| 1749 | enables input events.
|
|---|
| 1750 |
|
|---|
| 1751 | See the \l enabled documentation for more information.
|
|---|
| 1752 |
|
|---|
| 1753 | \sa isEnabledTo(), QKeyEvent, QMouseEvent, enabledChange()
|
|---|
| 1754 | */
|
|---|
| 1755 | void QWidget::setDisabled( bool disable )
|
|---|
| 1756 | {
|
|---|
| 1757 | setEnabled( !disable );
|
|---|
| 1758 | }
|
|---|
| 1759 |
|
|---|
| 1760 | /*!
|
|---|
| 1761 | \fn void QWidget::enabledChange( bool oldEnabled )
|
|---|
| 1762 |
|
|---|
| 1763 | This virtual function is called from setEnabled(). \a oldEnabled
|
|---|
| 1764 | is the previous setting; you can get the new setting from
|
|---|
| 1765 | isEnabled().
|
|---|
| 1766 |
|
|---|
| 1767 | Reimplement this function if your widget needs to know when it
|
|---|
| 1768 | becomes enabled or disabled. You will almost certainly need to
|
|---|
| 1769 | update the widget using update().
|
|---|
| 1770 |
|
|---|
| 1771 | The default implementation repaints the visible part of the
|
|---|
| 1772 | widget.
|
|---|
| 1773 |
|
|---|
| 1774 | \sa setEnabled(), isEnabled(), repaint(), update(), clipRegion()
|
|---|
| 1775 | */
|
|---|
| 1776 |
|
|---|
| 1777 | void QWidget::enabledChange( bool )
|
|---|
| 1778 | {
|
|---|
| 1779 | update();
|
|---|
| 1780 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
|---|
| 1781 | QAccessible::updateAccessibility( this, 0, QAccessible::StateChanged );
|
|---|
| 1782 | #endif
|
|---|
| 1783 | }
|
|---|
| 1784 |
|
|---|
| 1785 | /*!
|
|---|
| 1786 | \fn void QWidget::windowActivationChange( bool oldActive )
|
|---|
| 1787 |
|
|---|
| 1788 | This virtual function is called for a widget when its window is
|
|---|
| 1789 | activated or deactivated by the window system. \a oldActive is the
|
|---|
| 1790 | previous state; you can get the new setting from isActiveWindow().
|
|---|
| 1791 |
|
|---|
| 1792 | Reimplement this function if your widget needs to know when its
|
|---|
| 1793 | window becomes activated or deactivated.
|
|---|
| 1794 |
|
|---|
| 1795 | The default implementation updates the visible part of the widget
|
|---|
| 1796 | if the inactive and the active colorgroup are different for colors
|
|---|
| 1797 | other than the highlight and link colors.
|
|---|
| 1798 |
|
|---|
| 1799 | \sa setActiveWindow(), isActiveWindow(), update(), palette()
|
|---|
| 1800 | */
|
|---|
| 1801 |
|
|---|
| 1802 | void QWidget::windowActivationChange( bool )
|
|---|
| 1803 | {
|
|---|
| 1804 | #ifndef QT_NO_PALETTE
|
|---|
| 1805 | if ( !isVisible() )
|
|---|
| 1806 | return;
|
|---|
| 1807 |
|
|---|
| 1808 | const QColorGroup &acg = palette().active();
|
|---|
| 1809 | const QColorGroup &icg = palette().inactive();
|
|---|
| 1810 |
|
|---|
| 1811 | if ( acg != icg ) {
|
|---|
| 1812 | BackgroundMode bm = backgroundMode();
|
|---|
| 1813 | QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode(bm);
|
|---|
| 1814 | if ( bm > NoBackground && acg.brush(role) != icg.brush(role) )
|
|---|
| 1815 | setBackgroundFromMode();
|
|---|
| 1816 | else if ( acg.background() == icg.background() &&
|
|---|
| 1817 | acg.base() == icg.base() &&
|
|---|
| 1818 | acg.text() == icg.text() &&
|
|---|
| 1819 | acg.foreground() == icg.foreground() &&
|
|---|
| 1820 | acg.button() == icg.button() &&
|
|---|
| 1821 | acg.buttonText() == icg.buttonText() &&
|
|---|
| 1822 | acg.brightText() == icg.brightText() &&
|
|---|
| 1823 | acg.dark() == icg.dark() &&
|
|---|
| 1824 | acg.light() == icg.light() &&
|
|---|
| 1825 | acg.mid() == icg.mid() &&
|
|---|
| 1826 | acg.midlight() == icg.midlight() &&
|
|---|
| 1827 | acg.shadow() == icg.shadow() )
|
|---|
| 1828 | return;
|
|---|
| 1829 | update();
|
|---|
| 1830 | }
|
|---|
| 1831 | #endif
|
|---|
| 1832 | }
|
|---|
| 1833 |
|
|---|
| 1834 | /*!
|
|---|
| 1835 | \property QWidget::frameGeometry
|
|---|
| 1836 | \brief geometry of the widget relative to its parent including any
|
|---|
| 1837 | window frame
|
|---|
| 1838 |
|
|---|
| 1839 | See the \link geometry.html Window Geometry documentation\endlink
|
|---|
| 1840 | for an overview of geometry issues with top-level widgets.
|
|---|
| 1841 |
|
|---|
| 1842 | \sa geometry() x() y() pos()
|
|---|
| 1843 | */
|
|---|
| 1844 | QRect QWidget::frameGeometry() const
|
|---|
| 1845 | {
|
|---|
| 1846 | if (isTopLevel() && ! isPopup()) {
|
|---|
| 1847 | if (fstrut_dirty)
|
|---|
| 1848 | updateFrameStrut();
|
|---|
| 1849 | QWidget *that = (QWidget *) this;
|
|---|
| 1850 | QTLWExtra *top = that->topData();
|
|---|
| 1851 | return QRect(crect.x() - top->fleft,
|
|---|
| 1852 | crect.y() - top->ftop,
|
|---|
| 1853 | crect.width() + top->fleft + top->fright,
|
|---|
| 1854 | crect.height() + top->ftop + top->fbottom);
|
|---|
| 1855 | }
|
|---|
| 1856 | return crect;
|
|---|
| 1857 | }
|
|---|
| 1858 |
|
|---|
| 1859 | /*! \property QWidget::x
|
|---|
| 1860 | \brief the x coordinate of the widget relative to its parent including
|
|---|
| 1861 | any window frame
|
|---|
| 1862 |
|
|---|
| 1863 | See the \link geometry.html Window Geometry documentation\endlink
|
|---|
| 1864 | for an overview of top-level widget geometry.
|
|---|
| 1865 |
|
|---|
| 1866 | \sa frameGeometry, y, pos
|
|---|
| 1867 | */
|
|---|
| 1868 | int QWidget::x() const
|
|---|
| 1869 | {
|
|---|
| 1870 | if (isTopLevel() && ! isPopup()) {
|
|---|
| 1871 | if (fstrut_dirty)
|
|---|
| 1872 | updateFrameStrut();
|
|---|
| 1873 | QWidget *that = (QWidget *) this;
|
|---|
| 1874 | return crect.x() - that->topData()->fleft;
|
|---|
| 1875 | }
|
|---|
| 1876 | return crect.x();
|
|---|
| 1877 | }
|
|---|
| 1878 |
|
|---|
| 1879 | /*!
|
|---|
| 1880 | \property QWidget::y
|
|---|
| 1881 | \brief the y coordinate of the widget relative to its parent and
|
|---|
| 1882 | including any window frame
|
|---|
| 1883 |
|
|---|
| 1884 | See the \link geometry.html Window Geometry documentation\endlink
|
|---|
| 1885 | for an overview of top-level widget geometry.
|
|---|
| 1886 |
|
|---|
| 1887 | \sa frameGeometry, x, pos
|
|---|
| 1888 | */
|
|---|
| 1889 | int QWidget::y() const
|
|---|
| 1890 | {
|
|---|
| 1891 | if (isTopLevel() && ! isPopup()) {
|
|---|
| 1892 | if (fstrut_dirty)
|
|---|
| 1893 | updateFrameStrut();
|
|---|
| 1894 | QWidget *that = (QWidget *) this;
|
|---|
| 1895 | return crect.y() - that->topData()->ftop;
|
|---|
| 1896 | }
|
|---|
| 1897 | return crect.y();
|
|---|
| 1898 | }
|
|---|
| 1899 |
|
|---|
| 1900 | /*!
|
|---|
| 1901 | \property QWidget::pos
|
|---|
| 1902 | \brief the position of the widget within its parent widget
|
|---|
| 1903 |
|
|---|
| 1904 | If the widget is a top-level widget, the position is that of the
|
|---|
| 1905 | widget on the desktop, including its frame.
|
|---|
| 1906 |
|
|---|
| 1907 | When changing the position, the widget, if visible, receives a
|
|---|
| 1908 | move event (moveEvent()) immediately. If the widget is not
|
|---|
| 1909 | currently visible, it is guaranteed to receive an event before it
|
|---|
| 1910 | is shown.
|
|---|
| 1911 |
|
|---|
| 1912 | move() is virtual, and all other overloaded move() implementations
|
|---|
| 1913 | in Qt call it.
|
|---|
| 1914 |
|
|---|
| 1915 | \warning Calling move() or setGeometry() inside moveEvent() can
|
|---|
| 1916 | lead to infinite recursion.
|
|---|
| 1917 |
|
|---|
| 1918 | See the \link geometry.html Window Geometry documentation\endlink
|
|---|
| 1919 | for an overview of top-level widget geometry.
|
|---|
| 1920 |
|
|---|
| 1921 | \sa frameGeometry, size x(), y()
|
|---|
| 1922 | */
|
|---|
| 1923 | QPoint QWidget::pos() const
|
|---|
| 1924 | {
|
|---|
| 1925 | if (isTopLevel() && ! isPopup()) {
|
|---|
| 1926 | if (fstrut_dirty)
|
|---|
| 1927 | updateFrameStrut();
|
|---|
| 1928 | QWidget *that = (QWidget *) this;
|
|---|
| 1929 | QTLWExtra *top = that->topData();
|
|---|
| 1930 | return QPoint(crect.x() - top->fleft, crect.y() - top->ftop);
|
|---|
| 1931 | }
|
|---|
| 1932 | return crect.topLeft();
|
|---|
| 1933 | }
|
|---|
| 1934 |
|
|---|
| 1935 | /*!
|
|---|
| 1936 | \property QWidget::geometry
|
|---|
| 1937 | \brief the geometry of the widget relative to its parent and
|
|---|
| 1938 | excluding the window frame
|
|---|
| 1939 |
|
|---|
| 1940 | When changing the geometry, the widget, if visible, receives a
|
|---|
| 1941 | move event (moveEvent()) and/or a resize event (resizeEvent())
|
|---|
| 1942 | immediately. If the widget is not currently visible, it is
|
|---|
| 1943 | guaranteed to receive appropriate events before it is shown.
|
|---|
| 1944 |
|
|---|
| 1945 | The size component is adjusted if it lies outside the range
|
|---|
| 1946 | defined by minimumSize() and maximumSize().
|
|---|
| 1947 |
|
|---|
| 1948 | setGeometry() is virtual, and all other overloaded setGeometry()
|
|---|
| 1949 | implementations in Qt call it.
|
|---|
| 1950 |
|
|---|
| 1951 | \warning Calling setGeometry() inside resizeEvent() or moveEvent()
|
|---|
| 1952 | can lead to infinite recursion.
|
|---|
| 1953 |
|
|---|
| 1954 | See the \link geometry.html Window Geometry documentation\endlink
|
|---|
| 1955 | for an overview of top-level widget geometry.
|
|---|
| 1956 |
|
|---|
| 1957 | \sa frameGeometry(), rect(), move(), resize(), moveEvent(),
|
|---|
| 1958 | resizeEvent(), minimumSize(), maximumSize()
|
|---|
| 1959 | */
|
|---|
| 1960 |
|
|---|
| 1961 | /*!
|
|---|
| 1962 | \property QWidget::size
|
|---|
| 1963 | \brief the size of the widget excluding any window frame
|
|---|
| 1964 |
|
|---|
| 1965 | When resizing, the widget, if visible, receives a resize event
|
|---|
| 1966 | (resizeEvent()) immediately. If the widget is not currently
|
|---|
| 1967 | visible, it is guaranteed to receive an event before it is shown.
|
|---|
| 1968 |
|
|---|
| 1969 | The size is adjusted if it lies outside the range defined by
|
|---|
| 1970 | minimumSize() and maximumSize(). Furthermore, the size is always
|
|---|
| 1971 | at least QSize(1, 1). For toplevel widgets, the minimum size
|
|---|
| 1972 | might be larger, depending on the window manager.
|
|---|
| 1973 |
|
|---|
| 1974 | If you want a top-level window to have a fixed size, call
|
|---|
| 1975 | setResizeMode( QLayout::FreeResize ) on its layout.
|
|---|
| 1976 |
|
|---|
| 1977 | resize() is virtual, and all other overloaded resize()
|
|---|
| 1978 | implementations in Qt call it.
|
|---|
| 1979 |
|
|---|
| 1980 | \warning Calling resize() or setGeometry() inside resizeEvent() can
|
|---|
| 1981 | lead to infinite recursion.
|
|---|
| 1982 |
|
|---|
| 1983 | \sa pos, geometry, minimumSize, maximumSize, resizeEvent()
|
|---|
| 1984 | */
|
|---|
| 1985 |
|
|---|
| 1986 | /*!
|
|---|
| 1987 | \property QWidget::width
|
|---|
| 1988 | \brief the width of the widget excluding any window frame
|
|---|
| 1989 |
|
|---|
| 1990 | See the \link geometry.html Window Geometry documentation\endlink
|
|---|
| 1991 | for an overview of top-level widget geometry.
|
|---|
| 1992 |
|
|---|
| 1993 | \sa geometry, height, size
|
|---|
| 1994 | */
|
|---|
| 1995 |
|
|---|
| 1996 | /*!
|
|---|
| 1997 | \property QWidget::height
|
|---|
| 1998 | \brief the height of the widget excluding any window frame
|
|---|
| 1999 |
|
|---|
| 2000 | See the \link geometry.html Window Geometry documentation\endlink
|
|---|
| 2001 | for an overview of top-level widget geometry.
|
|---|
| 2002 |
|
|---|
| 2003 | \sa geometry, width, size
|
|---|
| 2004 | */
|
|---|
| 2005 |
|
|---|
| 2006 | /*!
|
|---|
| 2007 | \property QWidget::rect
|
|---|
| 2008 | \brief the internal geometry of the widget excluding any window
|
|---|
| 2009 | frame
|
|---|
| 2010 |
|
|---|
| 2011 | The rect property equals QRect(0, 0, width(), height()).
|
|---|
| 2012 |
|
|---|
| 2013 | See the \link geometry.html Window Geometry documentation\endlink
|
|---|
| 2014 | for an overview of top-level widget geometry.
|
|---|
| 2015 |
|
|---|
| 2016 | \sa size
|
|---|
| 2017 | */
|
|---|
| 2018 |
|
|---|
| 2019 | /*!
|
|---|
| 2020 | \property QWidget::childrenRect
|
|---|
| 2021 | \brief the bounding rectangle of the widget's children
|
|---|
| 2022 |
|
|---|
| 2023 | Hidden children are excluded.
|
|---|
| 2024 |
|
|---|
| 2025 | \sa childrenRegion() geometry()
|
|---|
| 2026 | */
|
|---|
| 2027 |
|
|---|
| 2028 | QRect QWidget::childrenRect() const
|
|---|
| 2029 | {
|
|---|
| 2030 | QRect r( 0, 0, 0, 0 );
|
|---|
| 2031 | if ( !children() )
|
|---|
| 2032 | return r;
|
|---|
| 2033 | QObjectListIt it( *children() );
|
|---|
| 2034 | QObject *obj;
|
|---|
| 2035 | while ( (obj = it.current()) ) {
|
|---|
| 2036 | ++it;
|
|---|
| 2037 | if ( obj->isWidgetType() && !((QWidget*)obj)->isHidden() )
|
|---|
| 2038 | r = r.unite( ((QWidget*)obj)->geometry() );
|
|---|
| 2039 | }
|
|---|
| 2040 | return r;
|
|---|
| 2041 | }
|
|---|
| 2042 |
|
|---|
| 2043 | /*!
|
|---|
| 2044 | \property QWidget::childrenRegion
|
|---|
| 2045 | \brief the combined region occupied by the widget's children
|
|---|
| 2046 |
|
|---|
| 2047 | Hidden children are excluded.
|
|---|
| 2048 |
|
|---|
| 2049 | \sa childrenRect() geometry()
|
|---|
| 2050 | */
|
|---|
| 2051 |
|
|---|
| 2052 | QRegion QWidget::childrenRegion() const
|
|---|
| 2053 | {
|
|---|
| 2054 | QRegion r;
|
|---|
| 2055 | if ( !children() )
|
|---|
| 2056 | return r;
|
|---|
| 2057 | QObjectListIt it( *children() ); // iterate over all children
|
|---|
| 2058 | QObject *obj;
|
|---|
| 2059 | while ( (obj=it.current()) ) {
|
|---|
| 2060 | ++it;
|
|---|
| 2061 | if ( obj->isWidgetType() && !((QWidget*)obj)->isHidden() )
|
|---|
| 2062 | r = r.unite( ((QWidget*)obj)->geometry() );
|
|---|
| 2063 | }
|
|---|
| 2064 | return r;
|
|---|
| 2065 | }
|
|---|
| 2066 |
|
|---|
| 2067 |
|
|---|
| 2068 | /*!
|
|---|
| 2069 | \property QWidget::minimumSize
|
|---|
| 2070 | \brief the widget's minimum size
|
|---|
| 2071 |
|
|---|
| 2072 | The widget cannot be resized to a smaller size than the minimum
|
|---|
| 2073 | widget size. The widget's size is forced to the minimum size if
|
|---|
| 2074 | the current size is smaller.
|
|---|
| 2075 |
|
|---|
| 2076 | If you use a layout inside the widget, the minimum size will be
|
|---|
| 2077 | set by the layout and not by setMinimumSize(), unless you set the
|
|---|
| 2078 | layout's resize mode to QLayout::FreeResize.
|
|---|
| 2079 |
|
|---|
| 2080 | \sa minimumWidth, minimumHeight, maximumSize, sizeIncrement
|
|---|
| 2081 | QLayout::setResizeMode()
|
|---|
| 2082 | */
|
|---|
| 2083 |
|
|---|
| 2084 | QSize QWidget::minimumSize() const
|
|---|
| 2085 | {
|
|---|
| 2086 | return extra ? QSize( extra->minw, extra->minh ) : QSize( 0, 0 );
|
|---|
| 2087 | }
|
|---|
| 2088 |
|
|---|
| 2089 | /*!
|
|---|
| 2090 | \property QWidget::maximumSize
|
|---|
| 2091 | \brief the widget's maximum size
|
|---|
| 2092 |
|
|---|
| 2093 | The widget cannot be resized to a larger size than the maximum
|
|---|
| 2094 | widget size.
|
|---|
| 2095 |
|
|---|
| 2096 | \sa maximumWidth(), maximumHeight(), setMaximumSize(),
|
|---|
| 2097 | minimumSize(), sizeIncrement()
|
|---|
| 2098 | */
|
|---|
| 2099 |
|
|---|
| 2100 | QSize QWidget::maximumSize() const
|
|---|
| 2101 | {
|
|---|
| 2102 | return extra ? QSize( extra->maxw, extra->maxh )
|
|---|
| 2103 | : QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX );
|
|---|
| 2104 | }
|
|---|
| 2105 |
|
|---|
| 2106 |
|
|---|
| 2107 | /*!
|
|---|
| 2108 | \property QWidget::minimumWidth
|
|---|
| 2109 | \brief the widget's minimum width
|
|---|
| 2110 |
|
|---|
| 2111 | This property corresponds to minimumSize().width().
|
|---|
| 2112 |
|
|---|
| 2113 | \sa minimumSize, minimumHeight
|
|---|
| 2114 | */
|
|---|
| 2115 |
|
|---|
| 2116 | /*!
|
|---|
| 2117 | \property QWidget::minimumHeight
|
|---|
| 2118 | \brief the widget's minimum height
|
|---|
| 2119 |
|
|---|
| 2120 | This property corresponds to minimumSize().height().
|
|---|
| 2121 |
|
|---|
| 2122 | \sa minimumSize, minimumWidth
|
|---|
| 2123 | */
|
|---|
| 2124 |
|
|---|
| 2125 | /*!
|
|---|
| 2126 | \property QWidget::maximumWidth
|
|---|
| 2127 | \brief the widget's maximum width
|
|---|
| 2128 |
|
|---|
| 2129 | This property corresponds to maximumSize().width().
|
|---|
| 2130 |
|
|---|
| 2131 | \sa maximumSize, maximumHeight
|
|---|
| 2132 | */
|
|---|
| 2133 |
|
|---|
| 2134 | /*!
|
|---|
| 2135 | \property QWidget::maximumHeight
|
|---|
| 2136 | \brief the widget's maximum height
|
|---|
| 2137 |
|
|---|
| 2138 | This property corresponds to maximumSize().height().
|
|---|
| 2139 |
|
|---|
| 2140 | \sa maximumSize, maximumWidth
|
|---|
| 2141 | */
|
|---|
| 2142 |
|
|---|
| 2143 | /*!
|
|---|
| 2144 | \property QWidget::sizeIncrement
|
|---|
| 2145 | \brief the size increment of the widget
|
|---|
| 2146 |
|
|---|
| 2147 | When the user resizes the window, the size will move in steps of
|
|---|
| 2148 | sizeIncrement().width() pixels horizontally and
|
|---|
| 2149 | sizeIncrement.height() pixels vertically, with baseSize() as the
|
|---|
| 2150 | basis. Preferred widget sizes are for non-negative integers \e i
|
|---|
| 2151 | and \e j:
|
|---|
| 2152 | \code
|
|---|
| 2153 | width = baseSize().width() + i * sizeIncrement().width();
|
|---|
| 2154 | height = baseSize().height() + j * sizeIncrement().height();
|
|---|
| 2155 | \endcode
|
|---|
| 2156 |
|
|---|
| 2157 | Note that while you can set the size increment for all widgets, it
|
|---|
| 2158 | only affects top-level widgets.
|
|---|
| 2159 |
|
|---|
| 2160 | \warning The size increment has no effect under Windows, and may
|
|---|
| 2161 | be disregarded by the window manager on X.
|
|---|
| 2162 |
|
|---|
| 2163 | \sa size, minimumSize, maximumSize
|
|---|
| 2164 | */
|
|---|
| 2165 | QSize QWidget::sizeIncrement() const
|
|---|
| 2166 | {
|
|---|
| 2167 | return ( extra && extra->topextra )
|
|---|
| 2168 | ? QSize( extra->topextra->incw, extra->topextra->inch )
|
|---|
| 2169 | : QSize( 0, 0 );
|
|---|
| 2170 | }
|
|---|
| 2171 |
|
|---|
| 2172 | /*!
|
|---|
| 2173 | \property QWidget::baseSize
|
|---|
| 2174 | \brief the base size of the widget
|
|---|
| 2175 |
|
|---|
| 2176 | The base size is used to calculate a proper widget size if the
|
|---|
| 2177 | widget defines sizeIncrement().
|
|---|
| 2178 |
|
|---|
| 2179 | \sa setSizeIncrement()
|
|---|
| 2180 | */
|
|---|
| 2181 |
|
|---|
| 2182 | QSize QWidget::baseSize() const
|
|---|
| 2183 | {
|
|---|
| 2184 | return ( extra != 0 && extra->topextra != 0 )
|
|---|
| 2185 | ? QSize( extra->topextra->basew, extra->topextra->baseh )
|
|---|
| 2186 | : QSize( 0, 0 );
|
|---|
| 2187 | }
|
|---|
| 2188 |
|
|---|
| 2189 | /*!
|
|---|
| 2190 | Sets both the minimum and maximum sizes of the widget to \a s,
|
|---|
| 2191 | thereby preventing it from ever growing or shrinking.
|
|---|
| 2192 |
|
|---|
| 2193 | \sa setMaximumSize() setMinimumSize()
|
|---|
| 2194 | */
|
|---|
| 2195 |
|
|---|
| 2196 | void QWidget::setFixedSize( const QSize & s)
|
|---|
| 2197 | {
|
|---|
| 2198 | setMinimumSize( s );
|
|---|
| 2199 | setMaximumSize( s );
|
|---|
| 2200 | resize( s );
|
|---|
| 2201 | }
|
|---|
| 2202 |
|
|---|
| 2203 |
|
|---|
| 2204 | /*!
|
|---|
| 2205 | \overload void QWidget::setFixedSize( int w, int h )
|
|---|
| 2206 |
|
|---|
| 2207 | Sets the width of the widget to \a w and the height to \a h.
|
|---|
| 2208 | */
|
|---|
| 2209 |
|
|---|
| 2210 | void QWidget::setFixedSize( int w, int h )
|
|---|
| 2211 | {
|
|---|
| 2212 | setMinimumSize( w, h );
|
|---|
| 2213 | setMaximumSize( w, h );
|
|---|
| 2214 | resize( w, h );
|
|---|
| 2215 | }
|
|---|
| 2216 |
|
|---|
| 2217 | void QWidget::setMinimumWidth( int w )
|
|---|
| 2218 | {
|
|---|
| 2219 | setMinimumSize( w, minimumSize().height() );
|
|---|
| 2220 | }
|
|---|
| 2221 |
|
|---|
| 2222 | void QWidget::setMinimumHeight( int h )
|
|---|
| 2223 | {
|
|---|
| 2224 | setMinimumSize( minimumSize().width(), h );
|
|---|
| 2225 | }
|
|---|
| 2226 |
|
|---|
| 2227 | void QWidget::setMaximumWidth( int w )
|
|---|
| 2228 | {
|
|---|
| 2229 | setMaximumSize( w, maximumSize().height() );
|
|---|
| 2230 | }
|
|---|
| 2231 |
|
|---|
| 2232 | void QWidget::setMaximumHeight( int h )
|
|---|
| 2233 | {
|
|---|
| 2234 | setMaximumSize( maximumSize().width(), h );
|
|---|
| 2235 | }
|
|---|
| 2236 |
|
|---|
| 2237 | /*!
|
|---|
| 2238 | Sets both the minimum and maximum width of the widget to \a w
|
|---|
| 2239 | without changing the heights. Provided for convenience.
|
|---|
| 2240 |
|
|---|
| 2241 | \sa sizeHint() minimumSize() maximumSize() setFixedSize()
|
|---|
| 2242 | */
|
|---|
| 2243 |
|
|---|
| 2244 | void QWidget::setFixedWidth( int w )
|
|---|
| 2245 | {
|
|---|
| 2246 | setMinimumSize( w, minimumSize().height() );
|
|---|
| 2247 | setMaximumSize( w, maximumSize().height() );
|
|---|
| 2248 | }
|
|---|
| 2249 |
|
|---|
| 2250 |
|
|---|
| 2251 | /*!
|
|---|
| 2252 | Sets both the minimum and maximum heights of the widget to \a h
|
|---|
| 2253 | without changing the widths. Provided for convenience.
|
|---|
| 2254 |
|
|---|
| 2255 | \sa sizeHint() minimumSize() maximumSize() setFixedSize()
|
|---|
| 2256 | */
|
|---|
| 2257 |
|
|---|
| 2258 | void QWidget::setFixedHeight( int h )
|
|---|
| 2259 | {
|
|---|
| 2260 | setMinimumSize( minimumSize().width(), h );
|
|---|
| 2261 | setMaximumSize( maximumSize().width(), h );
|
|---|
| 2262 | }
|
|---|
| 2263 |
|
|---|
| 2264 |
|
|---|
| 2265 | /*!
|
|---|
| 2266 | Translates the widget coordinate \a pos to the coordinate system
|
|---|
| 2267 | of \a parent. The \a parent must not be 0 and must be a parent
|
|---|
| 2268 | of the calling widget.
|
|---|
| 2269 |
|
|---|
| 2270 | \sa mapFrom() mapToParent() mapToGlobal() hasMouse()
|
|---|
| 2271 | */
|
|---|
| 2272 |
|
|---|
| 2273 | QPoint QWidget::mapTo( QWidget * parent, const QPoint & pos ) const
|
|---|
| 2274 | {
|
|---|
| 2275 | QPoint p = pos;
|
|---|
| 2276 | if ( parent ) {
|
|---|
| 2277 | const QWidget * w = this;
|
|---|
| 2278 | while ( w != parent ) {
|
|---|
| 2279 | p = w->mapToParent( p );
|
|---|
| 2280 | w = w->parentWidget();
|
|---|
| 2281 | }
|
|---|
| 2282 | }
|
|---|
| 2283 | return p;
|
|---|
| 2284 | }
|
|---|
| 2285 |
|
|---|
| 2286 |
|
|---|
| 2287 | /*!
|
|---|
| 2288 | Translates the widget coordinate \a pos from the coordinate system
|
|---|
| 2289 | of \a parent to this widget's coordinate system. The \a parent
|
|---|
| 2290 | must not be 0 and must be a parent of the calling widget.
|
|---|
| 2291 |
|
|---|
| 2292 | \sa mapTo() mapFromParent() mapFromGlobal() hasMouse()
|
|---|
| 2293 | */
|
|---|
| 2294 |
|
|---|
| 2295 | QPoint QWidget::mapFrom( QWidget * parent, const QPoint & pos ) const
|
|---|
| 2296 | {
|
|---|
| 2297 | QPoint p( pos );
|
|---|
| 2298 | if ( parent ) {
|
|---|
| 2299 | const QWidget * w = this;
|
|---|
| 2300 | while ( w != parent ) {
|
|---|
| 2301 | p = w->mapFromParent( p );
|
|---|
| 2302 | w = w->parentWidget();
|
|---|
| 2303 | }
|
|---|
| 2304 | }
|
|---|
| 2305 | return p;
|
|---|
| 2306 | }
|
|---|
| 2307 |
|
|---|
| 2308 |
|
|---|
| 2309 | /*!
|
|---|
| 2310 | Translates the widget coordinate \a pos to a coordinate in the
|
|---|
| 2311 | parent widget.
|
|---|
| 2312 |
|
|---|
| 2313 | Same as mapToGlobal() if the widget has no parent.
|
|---|
| 2314 |
|
|---|
| 2315 | \sa mapFromParent() mapTo() mapToGlobal() hasMouse()
|
|---|
| 2316 | */
|
|---|
| 2317 |
|
|---|
| 2318 | QPoint QWidget::mapToParent( const QPoint &pos ) const
|
|---|
| 2319 | {
|
|---|
| 2320 | return pos + crect.topLeft();
|
|---|
| 2321 | }
|
|---|
| 2322 |
|
|---|
| 2323 | /*!
|
|---|
| 2324 | Translates the parent widget coordinate \a pos to widget
|
|---|
| 2325 | coordinates.
|
|---|
| 2326 |
|
|---|
| 2327 | Same as mapFromGlobal() if the widget has no parent.
|
|---|
| 2328 |
|
|---|
| 2329 | \sa mapToParent() mapFrom() mapFromGlobal() hasMouse()
|
|---|
| 2330 | */
|
|---|
| 2331 |
|
|---|
| 2332 | QPoint QWidget::mapFromParent( const QPoint &pos ) const
|
|---|
| 2333 | {
|
|---|
| 2334 | return pos - crect.topLeft();
|
|---|
| 2335 | }
|
|---|
| 2336 |
|
|---|
| 2337 |
|
|---|
| 2338 | /*!
|
|---|
| 2339 | Returns the top-level widget for this widget, i.e. the next
|
|---|
| 2340 | ancestor widget that has (or could have) a window-system frame.
|
|---|
| 2341 |
|
|---|
| 2342 | If the widget is a top-level, the widget itself is returned.
|
|---|
| 2343 |
|
|---|
| 2344 | Typical usage is changing the window caption:
|
|---|
| 2345 |
|
|---|
| 2346 | \code
|
|---|
| 2347 | aWidget->topLevelWidget()->setCaption( "New Caption" );
|
|---|
| 2348 | \endcode
|
|---|
| 2349 |
|
|---|
| 2350 | \sa isTopLevel()
|
|---|
| 2351 | */
|
|---|
| 2352 |
|
|---|
| 2353 | QWidget *QWidget::topLevelWidget() const
|
|---|
| 2354 | {
|
|---|
| 2355 | QWidget *w = (QWidget *)this;
|
|---|
| 2356 | QWidget *p = w->parentWidget();
|
|---|
| 2357 | while ( !w->testWFlags(WType_TopLevel) && p ) {
|
|---|
| 2358 | w = p;
|
|---|
| 2359 | p = p->parentWidget();
|
|---|
| 2360 | }
|
|---|
| 2361 | return w;
|
|---|
| 2362 | }
|
|---|
| 2363 |
|
|---|
| 2364 |
|
|---|
| 2365 | /*!
|
|---|
| 2366 | \property QWidget::paletteForegroundColor
|
|---|
| 2367 | \brief the foreground color of the widget
|
|---|
| 2368 |
|
|---|
| 2369 | setPaletteForegroundColor() is a convenience function that creates
|
|---|
| 2370 | and sets a modified QPalette with setPalette(). The palette is
|
|---|
| 2371 | modified according to the widget's \e {background mode}. For
|
|---|
| 2372 | example, if the background mode is \c PaletteButton the palette entry
|
|---|
| 2373 | \c QColorGroup::ButtonText is set to color.
|
|---|
| 2374 |
|
|---|
| 2375 | \sa setPalette() QApplication::setPalette() backgroundMode()
|
|---|
| 2376 | foregroundColor() setBackgroundMode() setEraseColor()
|
|---|
| 2377 | */
|
|---|
| 2378 | const QColor &QWidget::paletteForegroundColor() const
|
|---|
| 2379 | {
|
|---|
| 2380 | #ifndef QT_NO_PALETTE
|
|---|
| 2381 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
|---|
| 2382 | return colorGroup().color( QPalette::foregroundRoleFromMode(mode) );
|
|---|
| 2383 | #else
|
|---|
| 2384 | return Qt::black;
|
|---|
| 2385 | #endif
|
|---|
| 2386 | }
|
|---|
| 2387 |
|
|---|
| 2388 | void QWidget::setPaletteForegroundColor( const QColor & color )
|
|---|
| 2389 | {
|
|---|
| 2390 | #ifndef QT_NO_PALETTE
|
|---|
| 2391 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
|---|
| 2392 | QPalette pal = palette();
|
|---|
| 2393 | QColorGroup::ColorRole role = QPalette::foregroundRoleFromMode( mode );
|
|---|
| 2394 | pal.setColor( QPalette::Active, role, color );
|
|---|
| 2395 | pal.setColor( QPalette::Inactive, role, color );
|
|---|
| 2396 | pal.setColor( QPalette::Disabled, role, color );
|
|---|
| 2397 | setPalette( pal );
|
|---|
| 2398 | #endif
|
|---|
| 2399 | }
|
|---|
| 2400 |
|
|---|
| 2401 |
|
|---|
| 2402 | /*!
|
|---|
| 2403 | Same as paletteForegroundColor()
|
|---|
| 2404 | */
|
|---|
| 2405 | const QColor &QWidget::foregroundColor() const
|
|---|
| 2406 | {
|
|---|
| 2407 | return paletteForegroundColor();
|
|---|
| 2408 | }
|
|---|
| 2409 |
|
|---|
| 2410 |
|
|---|
| 2411 | /*!
|
|---|
| 2412 | \fn const QColor& QWidget::eraseColor() const
|
|---|
| 2413 |
|
|---|
| 2414 | Returns the erase color of the widget.
|
|---|
| 2415 |
|
|---|
| 2416 | \sa setEraseColor() setErasePixmap() backgroundColor()
|
|---|
| 2417 | */
|
|---|
| 2418 |
|
|---|
| 2419 | /*!
|
|---|
| 2420 | Sets the erase color of the widget to \a color.
|
|---|
| 2421 |
|
|---|
| 2422 | The erase color is the color the widget is to be cleared to before
|
|---|
| 2423 | paintEvent() is called. If there is an erase pixmap (set using
|
|---|
| 2424 | setErasePixmap()), then this property has an indeterminate value.
|
|---|
| 2425 |
|
|---|
| 2426 | \sa erasePixmap(), backgroundColor(), backgroundMode(), palette()
|
|---|
| 2427 | */
|
|---|
| 2428 | void QWidget::setEraseColor( const QColor & color )
|
|---|
| 2429 | {
|
|---|
| 2430 | setBackgroundModeDirect( FixedColor );
|
|---|
| 2431 | setBackgroundColorDirect( color );
|
|---|
| 2432 | update();
|
|---|
| 2433 | }
|
|---|
| 2434 |
|
|---|
| 2435 | /*!
|
|---|
| 2436 | Returns the widget's erase pixmap.
|
|---|
| 2437 |
|
|---|
| 2438 | \sa setErasePixmap() eraseColor()
|
|---|
| 2439 | */
|
|---|
| 2440 | const QPixmap *QWidget::erasePixmap() const
|
|---|
| 2441 | {
|
|---|
| 2442 | return ( extra && extra->bg_pix ) ? extra->bg_pix : 0;
|
|---|
| 2443 | }
|
|---|
| 2444 |
|
|---|
| 2445 | /*!
|
|---|
| 2446 | Sets the widget's erase pixmap to \a pixmap.
|
|---|
| 2447 |
|
|---|
| 2448 | This pixmap is used to clear the widget before paintEvent() is
|
|---|
| 2449 | called.
|
|---|
| 2450 | */
|
|---|
| 2451 | void QWidget::setErasePixmap( const QPixmap &pixmap )
|
|---|
| 2452 | {
|
|---|
| 2453 | // This function is called with a null pixmap by setBackgroundEmpty().
|
|---|
| 2454 | setBackgroundPixmapDirect( pixmap );
|
|---|
| 2455 | setBackgroundModeDirect( FixedPixmap );
|
|---|
| 2456 | update();
|
|---|
| 2457 | }
|
|---|
| 2458 |
|
|---|
| 2459 | void QWidget::setBackgroundFromMode()
|
|---|
| 2460 | {
|
|---|
| 2461 | #ifndef QT_NO_PALETTE
|
|---|
| 2462 | QColorGroup::ColorRole r = QColorGroup::Background;
|
|---|
| 2463 | if ( extra ) {
|
|---|
| 2464 | int i = (BackgroundMode)extra->bg_mode;
|
|---|
| 2465 | if ( i == FixedColor || i == FixedPixmap || i == NoBackground ) {
|
|---|
| 2466 | // Mode is for fixed color, not one based on palette,
|
|---|
| 2467 | // so nothing to do.
|
|---|
| 2468 | return;
|
|---|
| 2469 | }
|
|---|
| 2470 | switch( i ) {
|
|---|
| 2471 | case PaletteForeground:
|
|---|
| 2472 | r = QColorGroup::Foreground;
|
|---|
| 2473 | break;
|
|---|
| 2474 | case PaletteButton:
|
|---|
| 2475 | r = QColorGroup::Button;
|
|---|
| 2476 | break;
|
|---|
| 2477 | case PaletteLight:
|
|---|
| 2478 | r = QColorGroup::Light;
|
|---|
| 2479 | break;
|
|---|
| 2480 | case PaletteMidlight:
|
|---|
| 2481 | r = QColorGroup::Midlight;
|
|---|
| 2482 | break;
|
|---|
| 2483 | case PaletteDark:
|
|---|
| 2484 | r = QColorGroup::Dark;
|
|---|
| 2485 | break;
|
|---|
| 2486 | case PaletteMid:
|
|---|
| 2487 | r = QColorGroup::Mid;
|
|---|
| 2488 | break;
|
|---|
| 2489 | case PaletteText:
|
|---|
| 2490 | r = QColorGroup::Text;
|
|---|
| 2491 | break;
|
|---|
| 2492 | case PaletteBrightText:
|
|---|
| 2493 | r = QColorGroup::BrightText;
|
|---|
| 2494 | break;
|
|---|
| 2495 | case PaletteBase:
|
|---|
| 2496 | r = QColorGroup::Base;
|
|---|
| 2497 | break;
|
|---|
| 2498 | case PaletteBackground:
|
|---|
| 2499 | r = QColorGroup::Background;
|
|---|
| 2500 | break;
|
|---|
| 2501 | case PaletteShadow:
|
|---|
| 2502 | r = QColorGroup::Shadow;
|
|---|
| 2503 | break;
|
|---|
| 2504 | case PaletteHighlight:
|
|---|
| 2505 | r = QColorGroup::Highlight;
|
|---|
| 2506 | break;
|
|---|
| 2507 | case PaletteHighlightedText:
|
|---|
| 2508 | r = QColorGroup::HighlightedText;
|
|---|
| 2509 | break;
|
|---|
| 2510 | case PaletteButtonText:
|
|---|
| 2511 | r = QColorGroup::ButtonText;
|
|---|
| 2512 | break;
|
|---|
| 2513 | case X11ParentRelative:
|
|---|
| 2514 | #if defined(Q_WS_X11)
|
|---|
| 2515 | setBackgroundX11Relative();
|
|---|
| 2516 | #endif
|
|---|
| 2517 | return;
|
|---|
| 2518 | }
|
|---|
| 2519 | }
|
|---|
| 2520 | const QColorGroup &cg = colorGroup();
|
|---|
| 2521 | QPixmap * p = cg.brush( r ).pixmap();
|
|---|
| 2522 | if ( p )
|
|---|
| 2523 | setBackgroundPixmapDirect( *p );
|
|---|
| 2524 | else
|
|---|
| 2525 | setBackgroundColorDirect( cg.color( r ) );
|
|---|
| 2526 | #endif
|
|---|
| 2527 | }
|
|---|
| 2528 |
|
|---|
| 2529 | /*!
|
|---|
| 2530 | \enum Qt::BackgroundMode
|
|---|
| 2531 |
|
|---|
| 2532 | This enum describes how the background of a widget changes, as the
|
|---|
| 2533 | widget's palette changes.
|
|---|
| 2534 |
|
|---|
| 2535 | The background is what the widget contains when \link
|
|---|
| 2536 | QWidget::paintEvent() paintEvent()\endlink is called. To minimize
|
|---|
| 2537 | flicker, this should be the most common color or pixmap in the
|
|---|
| 2538 | widget. For \c PaletteBackground, use colorGroup().brush( \c
|
|---|
| 2539 | QColorGroup::Background ), and so on.
|
|---|
| 2540 |
|
|---|
| 2541 | \value PaletteForeground
|
|---|
| 2542 | \value PaletteBackground
|
|---|
| 2543 | \value PaletteButton
|
|---|
| 2544 | \value PaletteLight
|
|---|
| 2545 | \value PaletteMidlight
|
|---|
| 2546 | \value PaletteDark
|
|---|
| 2547 | \value PaletteMid
|
|---|
| 2548 | \value PaletteText
|
|---|
| 2549 | \value PaletteBrightText
|
|---|
| 2550 | \value PaletteButtonText
|
|---|
| 2551 | \value PaletteBase
|
|---|
| 2552 | \value PaletteShadow
|
|---|
| 2553 | \value PaletteHighlight
|
|---|
| 2554 | \value PaletteHighlightedText
|
|---|
| 2555 | \value PaletteLink
|
|---|
| 2556 | \value PaletteLinkVisited
|
|---|
| 2557 | \value X11ParentRelative (internal use only)
|
|---|
| 2558 |
|
|---|
| 2559 | The final three values have special meaning:
|
|---|
| 2560 |
|
|---|
| 2561 | \value NoBackground the widget is not cleared before paintEvent().
|
|---|
| 2562 | If the widget's paint event always draws on all the pixels, using
|
|---|
| 2563 | this mode can be both fast and flicker-free.
|
|---|
| 2564 | \value FixedColor the widget is cleared to a fixed color, normally
|
|---|
| 2565 | different from all the ones in the palette(). Set using \link
|
|---|
| 2566 | QWidget::setPaletteBackgroundColor()
|
|---|
| 2567 | setPaletteBackgroundColor()\endlink.
|
|---|
| 2568 | \value FixedPixmap the widget is cleared to a fixed pixmap,
|
|---|
| 2569 | normally different from all the ones in the palette(). Set using
|
|---|
| 2570 | \link QWidget::setPaletteBackgroundPixmap()
|
|---|
| 2571 | setPaletteBackgroundPixmap()\endlink.
|
|---|
| 2572 |
|
|---|
| 2573 | Although \c FixedColor and \c FixedPixmap are sometimes just
|
|---|
| 2574 | right, if you use them, make sure that you test your application
|
|---|
| 2575 | when the desktop color scheme has been changed. (On X11, a quick
|
|---|
| 2576 | way to test this is e.g. "./myapp -bg paleblue". On Windows, you
|
|---|
| 2577 | must use the control panel.)
|
|---|
| 2578 |
|
|---|
| 2579 | \sa QWidget::setBackgroundMode() QWidget::backgroundMode()
|
|---|
| 2580 | QWidget::setBackgroundPixmap() QWidget::setPaletteBackgroundColor()
|
|---|
| 2581 | */
|
|---|
| 2582 |
|
|---|
| 2583 | /*!
|
|---|
| 2584 | \property QWidget::backgroundMode
|
|---|
| 2585 | \brief the color role used for painting the background of the widget
|
|---|
| 2586 |
|
|---|
| 2587 | setPaletteBackgroundColor() reads this property to determine which
|
|---|
| 2588 | entry of the \link QWidget::palette palette\endlink to set.
|
|---|
| 2589 |
|
|---|
| 2590 | For most widgets the default suffices (\c PaletteBackground,
|
|---|
| 2591 | typically gray), but some need to use \c PaletteBase (the
|
|---|
| 2592 | background color for text output, typically white) or another
|
|---|
| 2593 | role.
|
|---|
| 2594 |
|
|---|
| 2595 | QListBox, which is "sunken" and uses the base color to contrast
|
|---|
| 2596 | with its environment, does this in its constructor:
|
|---|
| 2597 |
|
|---|
| 2598 | \code
|
|---|
| 2599 | setBackgroundMode( PaletteBase );
|
|---|
| 2600 | \endcode
|
|---|
| 2601 |
|
|---|
| 2602 | You will never need to set the background mode of a built-in
|
|---|
| 2603 | widget in Qt, but you might consider setting it in your custom
|
|---|
| 2604 | widgets, so that setPaletteBackgroundColor() works as expected.
|
|---|
| 2605 |
|
|---|
| 2606 | Note that two of the BackgroundMode values make no sense for
|
|---|
| 2607 | setBackgroundMode(), namely \c FixedPixmap and \c FixedColor. You
|
|---|
| 2608 | must call setBackgroundPixmap() and setPaletteBackgroundColor()
|
|---|
| 2609 | instead.
|
|---|
| 2610 | */
|
|---|
| 2611 | Qt::BackgroundMode QWidget::backgroundMode() const
|
|---|
| 2612 | {
|
|---|
| 2613 | return extra ? (BackgroundMode) extra->bg_mode : PaletteBackground;
|
|---|
| 2614 | }
|
|---|
| 2615 |
|
|---|
| 2616 | void QWidget::setBackgroundMode( BackgroundMode m )
|
|---|
| 2617 | {
|
|---|
| 2618 | setBackgroundMode( m, m );
|
|---|
| 2619 | if ( (widget_state & (WState_Visible|WState_BlockUpdates)) ==
|
|---|
| 2620 | WState_Visible )
|
|---|
| 2621 | update();
|
|---|
| 2622 | }
|
|---|
| 2623 |
|
|---|
| 2624 |
|
|---|
| 2625 | /*!
|
|---|
| 2626 | \overload
|
|---|
| 2627 |
|
|---|
| 2628 | Sets the widget's own background mode to \a m and the visual
|
|---|
| 2629 | background mode to \a visual. The visual background mode is used
|
|---|
| 2630 | with the designable properties \c backgroundColor, \c
|
|---|
| 2631 | foregroundColor and \c backgroundPixmap.
|
|---|
| 2632 |
|
|---|
| 2633 | For complex controls, the logical background mode sometimes
|
|---|
| 2634 | differs from a widget's own background mode. A spinbox for example
|
|---|
| 2635 | has \c PaletteBackground as background mode (typically dark gray),
|
|---|
| 2636 | while it's embedded lineedit control uses \c PaletteBase
|
|---|
| 2637 | (typically white). Since the lineedit covers most of the visual
|
|---|
| 2638 | area of a spinbox, it defines \c PaletteBase to be its \a visual
|
|---|
| 2639 | background mode. Changing the \c backgroundColor property thus
|
|---|
| 2640 | changes the lineedit control's background, which is exactly what
|
|---|
| 2641 | the user expects in \e{Qt Designer}.
|
|---|
| 2642 | */
|
|---|
| 2643 | void QWidget::setBackgroundMode( BackgroundMode m, BackgroundMode visual )
|
|---|
| 2644 | {
|
|---|
| 2645 | if ( m == NoBackground ) {
|
|---|
| 2646 | setBackgroundEmpty();
|
|---|
| 2647 | } else if ( m == FixedColor || m == FixedPixmap ) {
|
|---|
| 2648 | #if defined(QT_DEBUG)
|
|---|
| 2649 | qWarning( "QWidget::setBackgroundMode: FixedColor or FixedPixmap makes"
|
|---|
| 2650 | " no sense" );
|
|---|
| 2651 | #endif
|
|---|
| 2652 | return;
|
|---|
| 2653 | }
|
|---|
| 2654 | setBackgroundModeDirect(m);
|
|---|
| 2655 | if ( m != visual && !extra )
|
|---|
| 2656 | createExtra();
|
|---|
| 2657 | if ( extra )
|
|---|
| 2658 | extra->bg_mode_visual = visual;
|
|---|
| 2659 | }
|
|---|
| 2660 |
|
|---|
| 2661 |
|
|---|
| 2662 | /*!
|
|---|
| 2663 | \internal
|
|---|
| 2664 | */
|
|---|
| 2665 | void QWidget::setBackgroundModeDirect( BackgroundMode m )
|
|---|
| 2666 | {
|
|---|
| 2667 | if ( m == PaletteBackground && !extra )
|
|---|
| 2668 | return;
|
|---|
| 2669 |
|
|---|
| 2670 | createExtra();
|
|---|
| 2671 | if ( (BackgroundMode)extra->bg_mode != m ) {
|
|---|
| 2672 | extra->bg_mode = m;
|
|---|
| 2673 | extra->bg_mode_visual = m;
|
|---|
| 2674 | setBackgroundFromMode();
|
|---|
| 2675 | }
|
|---|
| 2676 | }
|
|---|
| 2677 |
|
|---|
| 2678 | /*!
|
|---|
| 2679 | \property QWidget::paletteBackgroundColor
|
|---|
| 2680 | \brief the background color of the widget
|
|---|
| 2681 |
|
|---|
| 2682 | The palette background color is usually set implicitly by
|
|---|
| 2683 | setBackgroundMode(), although it can also be set explicitly by
|
|---|
| 2684 | setPaletteBackgroundColor(). setPaletteBackgroundColor() is a
|
|---|
| 2685 | convenience function that creates and sets a modified QPalette
|
|---|
| 2686 | with setPalette(). The palette is modified according to the
|
|---|
| 2687 | widget's background mode. For example, if the background mode is
|
|---|
| 2688 | \c PaletteButton the color used for the palette's \c
|
|---|
| 2689 | QColorGroup::Button color entry is set.
|
|---|
| 2690 |
|
|---|
| 2691 | If there is a background pixmap (set using
|
|---|
| 2692 | setPaletteBackgroundPixmap()), then the return value of this
|
|---|
| 2693 | function is indeterminate.
|
|---|
| 2694 |
|
|---|
| 2695 | \sa paletteBackgroundPixmap, paletteForegroundColor, palette, colorGroup()
|
|---|
| 2696 | */
|
|---|
| 2697 | const QColor & QWidget::paletteBackgroundColor() const
|
|---|
| 2698 | {
|
|---|
| 2699 | #ifndef QT_NO_PALETTE
|
|---|
| 2700 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
|---|
| 2701 | switch( mode ) {
|
|---|
| 2702 | case FixedColor:
|
|---|
| 2703 | case FixedPixmap :
|
|---|
| 2704 | case NoBackground:
|
|---|
| 2705 | case X11ParentRelative:
|
|---|
| 2706 | return eraseColor();
|
|---|
| 2707 | default:
|
|---|
| 2708 | QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
|
|---|
| 2709 | return colorGroup().color( role );
|
|---|
| 2710 | }
|
|---|
| 2711 | #else
|
|---|
| 2712 | return eraseColor();
|
|---|
| 2713 | #endif
|
|---|
| 2714 | }
|
|---|
| 2715 |
|
|---|
| 2716 | void QWidget::setPaletteBackgroundColor( const QColor &color )
|
|---|
| 2717 | {
|
|---|
| 2718 | #ifndef QT_NO_PALETTE
|
|---|
| 2719 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
|---|
| 2720 | switch( mode ) {
|
|---|
| 2721 | case FixedColor:
|
|---|
| 2722 | case FixedPixmap :
|
|---|
| 2723 | case NoBackground:
|
|---|
| 2724 | case X11ParentRelative:
|
|---|
| 2725 | setEraseColor( color );
|
|---|
| 2726 | break;
|
|---|
| 2727 | default:
|
|---|
| 2728 | QPalette pal = palette();
|
|---|
| 2729 | QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
|
|---|
| 2730 | pal.setColor( QPalette::Active, role, color );
|
|---|
| 2731 | pal.setColor( QPalette::Inactive, role, color );
|
|---|
| 2732 | pal.setColor( QPalette::Disabled, role, color );
|
|---|
| 2733 | setPalette( pal );
|
|---|
| 2734 | break;
|
|---|
| 2735 | }
|
|---|
| 2736 | #else
|
|---|
| 2737 | setEraseColor( color );
|
|---|
| 2738 | #endif
|
|---|
| 2739 | }
|
|---|
| 2740 |
|
|---|
| 2741 |
|
|---|
| 2742 | /*!
|
|---|
| 2743 | \property QWidget::paletteBackgroundPixmap
|
|---|
| 2744 | \brief the background pixmap of the widget
|
|---|
| 2745 |
|
|---|
| 2746 | The palette background pixmap is usually set implicitly by
|
|---|
| 2747 | setBackgroundMode(), although it can also be set explicitly by
|
|---|
| 2748 | setPaletteBackgroundPixmap(). setPaletteBackgroundPixmap() is a
|
|---|
| 2749 | convenience function that creates and sets a modified QPalette
|
|---|
| 2750 | with setPalette(). The palette is modified according to the
|
|---|
| 2751 | widget's background mode. For example, if the background mode is
|
|---|
| 2752 | \c PaletteButton the pixmap used for the palette's
|
|---|
| 2753 | \c QColorGroup::Button color entry is set.
|
|---|
| 2754 |
|
|---|
| 2755 | If there is a plain background color (set using
|
|---|
| 2756 | setPaletteBackgroundColor()), then this function returns 0.
|
|---|
| 2757 |
|
|---|
| 2758 | \sa paletteBackgroundColor, paletteForegroundColor, palette, colorGroup()
|
|---|
| 2759 | */
|
|---|
| 2760 | const QPixmap *QWidget::paletteBackgroundPixmap() const
|
|---|
| 2761 | {
|
|---|
| 2762 | #ifndef QT_NO_PALETTE
|
|---|
| 2763 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
|---|
| 2764 | switch( mode ) {
|
|---|
| 2765 | case FixedColor:
|
|---|
| 2766 | case FixedPixmap :
|
|---|
| 2767 | case NoBackground:
|
|---|
| 2768 | case X11ParentRelative:
|
|---|
| 2769 | return erasePixmap();
|
|---|
| 2770 | default:
|
|---|
| 2771 | QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
|
|---|
| 2772 | return palette().brush( QPalette::Active, role ).pixmap();
|
|---|
| 2773 | }
|
|---|
| 2774 | #else
|
|---|
| 2775 | return erasePixmap();
|
|---|
| 2776 | #endif
|
|---|
| 2777 | }
|
|---|
| 2778 |
|
|---|
| 2779 | void QWidget::setPaletteBackgroundPixmap( const QPixmap &pixmap )
|
|---|
| 2780 | {
|
|---|
| 2781 | #ifndef QT_NO_PALETTE
|
|---|
| 2782 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
|---|
| 2783 | switch( mode ) {
|
|---|
| 2784 | case FixedColor:
|
|---|
| 2785 | case FixedPixmap :
|
|---|
| 2786 | case NoBackground:
|
|---|
| 2787 | case X11ParentRelative:
|
|---|
| 2788 | setErasePixmap( pixmap );
|
|---|
| 2789 | break;
|
|---|
| 2790 | default:
|
|---|
| 2791 | QPalette pal = palette();
|
|---|
| 2792 | QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
|
|---|
| 2793 | pal.setBrush( QPalette::Active, role, QBrush( pal.color( QPalette::Active, role ), pixmap ) );
|
|---|
| 2794 | pal.setBrush( QPalette::Inactive, role, QBrush( pal.color( QPalette::Inactive, role ), pixmap ) );
|
|---|
| 2795 | pal.setBrush( QPalette::Disabled, role, QBrush( pal.color( QPalette::Disabled, role ), pixmap ) );
|
|---|
| 2796 | setPalette( pal );
|
|---|
| 2797 | break;
|
|---|
| 2798 | }
|
|---|
| 2799 | #else
|
|---|
| 2800 | setErasePixmap( pixmap );
|
|---|
| 2801 | #endif
|
|---|
| 2802 | }
|
|---|
| 2803 |
|
|---|
| 2804 |
|
|---|
| 2805 | /*!
|
|---|
| 2806 | \property QWidget::backgroundBrush
|
|---|
| 2807 | \brief the widget's background brush
|
|---|
| 2808 |
|
|---|
| 2809 | The background brush depends on a widget's palette and its
|
|---|
| 2810 | background mode.
|
|---|
| 2811 |
|
|---|
| 2812 | \sa backgroundColor(), backgroundPixmap(), eraseColor(), palette,
|
|---|
| 2813 | QApplication::setPalette()
|
|---|
| 2814 | */
|
|---|
| 2815 | const QBrush& QWidget::backgroundBrush() const
|
|---|
| 2816 | {
|
|---|
| 2817 | static QBrush noBrush;
|
|---|
| 2818 | #ifndef QT_NO_PALETTE
|
|---|
| 2819 | BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
|
|---|
| 2820 | switch( mode ) {
|
|---|
| 2821 | case FixedColor:
|
|---|
| 2822 | case FixedPixmap :
|
|---|
| 2823 | case NoBackground:
|
|---|
| 2824 | case X11ParentRelative:
|
|---|
| 2825 | return noBrush;
|
|---|
| 2826 | default:
|
|---|
| 2827 | QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
|
|---|
| 2828 | return colorGroup().brush( role );
|
|---|
| 2829 | }
|
|---|
| 2830 | #else
|
|---|
| 2831 | return noBrush;
|
|---|
| 2832 | #endif
|
|---|
| 2833 | }
|
|---|
| 2834 |
|
|---|
| 2835 |
|
|---|
| 2836 | /*!
|
|---|
| 2837 | \property QWidget::colorGroup
|
|---|
| 2838 | \brief the current color group of the widget palette
|
|---|
| 2839 |
|
|---|
| 2840 | The color group is determined by the state of the widget. A
|
|---|
| 2841 | disabled widget has the QPalette::disabled() color group, a widget
|
|---|
| 2842 | with keyboard focus has the QPalette::active() color group, and an
|
|---|
| 2843 | inactive widget has the QPalette::inactive() color group.
|
|---|
| 2844 |
|
|---|
| 2845 | \sa palette
|
|---|
| 2846 | */
|
|---|
| 2847 | #ifndef QT_NO_PALETTE
|
|---|
| 2848 | const QColorGroup &QWidget::colorGroup() const
|
|---|
| 2849 | {
|
|---|
| 2850 | if ( !isEnabled() )
|
|---|
| 2851 | return palette().disabled();
|
|---|
| 2852 | else if ( !isVisible() || isActiveWindow() )
|
|---|
| 2853 | return palette().active();
|
|---|
| 2854 | else
|
|---|
| 2855 | return palette().inactive();
|
|---|
| 2856 | }
|
|---|
| 2857 | #endif
|
|---|
| 2858 |
|
|---|
| 2859 | /*!
|
|---|
| 2860 | \property QWidget::palette
|
|---|
| 2861 | \brief the widget's palette
|
|---|
| 2862 |
|
|---|
| 2863 | As long as no special palette has been set, or after unsetPalette()
|
|---|
| 2864 | has been called, this is either a special palette for the widget
|
|---|
| 2865 | class, the parent's palette or (if this widget is a top level
|
|---|
| 2866 | widget), the default application palette.
|
|---|
| 2867 |
|
|---|
| 2868 | Instead of defining an entirely new palette, you can also use the
|
|---|
| 2869 | \link QWidget::paletteBackgroundColor paletteBackgroundColor\endlink,
|
|---|
| 2870 | \link QWidget::paletteBackgroundPixmap paletteBackgroundPixmap\endlink and
|
|---|
| 2871 | \link QWidget::paletteForegroundColor paletteForegroundColor\endlink
|
|---|
| 2872 | convenience properties to change a widget's
|
|---|
| 2873 | background and foreground appearance only.
|
|---|
| 2874 |
|
|---|
| 2875 | \sa ownPalette, colorGroup(), QApplication::palette()
|
|---|
| 2876 | */
|
|---|
| 2877 |
|
|---|
| 2878 | #ifndef QT_NO_PALETTE
|
|---|
| 2879 | void QWidget::setPalette( const QPalette &palette )
|
|---|
| 2880 | {
|
|---|
| 2881 | own_palette = TRUE;
|
|---|
| 2882 | if ( pal == palette )
|
|---|
| 2883 | return;
|
|---|
| 2884 | QPalette old = pal;
|
|---|
| 2885 | pal = palette;
|
|---|
| 2886 | setBackgroundFromMode();
|
|---|
| 2887 | QEvent ev( QEvent::PaletteChange );
|
|---|
| 2888 | QApplication::sendEvent( this, &ev );
|
|---|
| 2889 | if ( children() ) {
|
|---|
| 2890 | QEvent e( QEvent::ParentPaletteChange );
|
|---|
| 2891 | QObjectListIt it( *children() );
|
|---|
| 2892 | QWidget *w;
|
|---|
| 2893 | while( (w=(QWidget *)it.current()) != 0 ) {
|
|---|
| 2894 | ++it;
|
|---|
| 2895 | if ( w->isWidgetType() )
|
|---|
| 2896 | QApplication::sendEvent( w, &e );
|
|---|
| 2897 | }
|
|---|
| 2898 | }
|
|---|
| 2899 | paletteChange( old );
|
|---|
| 2900 | update();
|
|---|
| 2901 | }
|
|---|
| 2902 |
|
|---|
| 2903 | void QWidget::unsetPalette()
|
|---|
| 2904 | {
|
|---|
| 2905 | // reset the palette
|
|---|
| 2906 | setPalette( qt_naturalWidgetPalette( this ) );
|
|---|
| 2907 | own_palette = FALSE;
|
|---|
| 2908 | }
|
|---|
| 2909 |
|
|---|
| 2910 | /*!
|
|---|
| 2911 | \fn void QWidget::setPalette( const QPalette&, bool )
|
|---|
| 2912 | \obsolete
|
|---|
| 2913 |
|
|---|
| 2914 | Use setPalette( const QPalette& p ) instead.
|
|---|
| 2915 | */
|
|---|
| 2916 |
|
|---|
| 2917 | /*!
|
|---|
| 2918 | \fn void QWidget::paletteChange( const QPalette &oldPalette )
|
|---|
| 2919 |
|
|---|
| 2920 | This virtual function is called from setPalette(). \a oldPalette
|
|---|
| 2921 | is the previous palette; you can get the new palette from
|
|---|
| 2922 | palette().
|
|---|
| 2923 |
|
|---|
| 2924 | Reimplement this function if your widget needs to know when its
|
|---|
| 2925 | palette changes.
|
|---|
| 2926 |
|
|---|
| 2927 | \sa setPalette(), palette()
|
|---|
| 2928 | */
|
|---|
| 2929 |
|
|---|
| 2930 | void QWidget::paletteChange( const QPalette & )
|
|---|
| 2931 | {
|
|---|
| 2932 | }
|
|---|
| 2933 | #endif // QT_NO_PALETTE
|
|---|
| 2934 |
|
|---|
| 2935 | /*!
|
|---|
| 2936 | \property QWidget::font
|
|---|
| 2937 | \brief the font currently set for the widget
|
|---|
| 2938 |
|
|---|
| 2939 | The fontInfo() function reports the actual font that is being used
|
|---|
| 2940 | by the widget.
|
|---|
| 2941 |
|
|---|
| 2942 | As long as no special font has been set, or after unsetFont() is
|
|---|
| 2943 | called, this is either a special font for the widget class, the
|
|---|
| 2944 | parent's font or (if this widget is a top level widget), the
|
|---|
| 2945 | default application font.
|
|---|
| 2946 |
|
|---|
| 2947 | This code fragment sets a 12 point helvetica bold font:
|
|---|
| 2948 | \code
|
|---|
| 2949 | QFont f( "Helvetica", 12, QFont::Bold );
|
|---|
| 2950 | setFont( f );
|
|---|
| 2951 | \endcode
|
|---|
| 2952 |
|
|---|
| 2953 | In addition to setting the font, setFont() informs all children
|
|---|
| 2954 | about the change.
|
|---|
| 2955 |
|
|---|
| 2956 | \sa fontChange() fontInfo() fontMetrics() ownFont()
|
|---|
| 2957 | */
|
|---|
| 2958 | void QWidget::setFont( const QFont &font )
|
|---|
| 2959 | {
|
|---|
| 2960 | own_font = TRUE;
|
|---|
| 2961 | if ( fnt == font && fnt.d->mask == font.d->mask )
|
|---|
| 2962 | return;
|
|---|
| 2963 | QFont old = fnt;
|
|---|
| 2964 | fnt = font.resolve( qt_naturalWidgetFont( this ) );
|
|---|
| 2965 | #if defined(Q_WS_X11)
|
|---|
| 2966 | // make sure the font set on this widget is associated with the correct screen
|
|---|
| 2967 | fnt.x11SetScreen( x11Screen() );
|
|---|
| 2968 | #endif
|
|---|
| 2969 | if ( children() ) {
|
|---|
| 2970 | QEvent e( QEvent::ParentFontChange );
|
|---|
| 2971 | QObjectListIt it( *children() );
|
|---|
| 2972 | QWidget *w;
|
|---|
| 2973 | while( (w=(QWidget *)it.current()) != 0 ) {
|
|---|
| 2974 | ++it;
|
|---|
| 2975 | if ( w->isWidgetType() )
|
|---|
| 2976 | QApplication::sendEvent( w, &e );
|
|---|
| 2977 | }
|
|---|
| 2978 | }
|
|---|
| 2979 | if ( hasFocus() )
|
|---|
| 2980 | setFontSys();
|
|---|
| 2981 | fontChange( old );
|
|---|
| 2982 | }
|
|---|
| 2983 |
|
|---|
| 2984 | void QWidget::unsetFont()
|
|---|
| 2985 | {
|
|---|
| 2986 | // reset the font
|
|---|
| 2987 | setFont( qt_naturalWidgetFont( this ) );
|
|---|
| 2988 | own_font = FALSE;
|
|---|
| 2989 | }
|
|---|
| 2990 |
|
|---|
| 2991 | /*!
|
|---|
| 2992 | \fn void QWidget::setFont( const QFont&, bool )
|
|---|
| 2993 | \obsolete
|
|---|
| 2994 |
|
|---|
| 2995 | Use setFont(const QFont& font) instead.
|
|---|
| 2996 | */
|
|---|
| 2997 |
|
|---|
| 2998 | /*!
|
|---|
| 2999 | \fn void QWidget::fontChange( const QFont &oldFont )
|
|---|
| 3000 |
|
|---|
| 3001 | This virtual function is called from setFont(). \a oldFont is the
|
|---|
| 3002 | previous font; you can get the new font from font().
|
|---|
| 3003 |
|
|---|
| 3004 | Reimplement this function if your widget needs to know when its
|
|---|
| 3005 | font changes. You will almost certainly need to update the widget
|
|---|
| 3006 | using update().
|
|---|
| 3007 |
|
|---|
| 3008 | The default implementation updates the widget including its
|
|---|
| 3009 | geometry.
|
|---|
| 3010 |
|
|---|
| 3011 | \sa setFont(), font(), update(), updateGeometry()
|
|---|
| 3012 | */
|
|---|
| 3013 |
|
|---|
| 3014 | void QWidget::fontChange( const QFont & )
|
|---|
| 3015 | {
|
|---|
| 3016 | update();
|
|---|
| 3017 | updateGeometry();
|
|---|
| 3018 | }
|
|---|
| 3019 |
|
|---|
| 3020 |
|
|---|
| 3021 | /*!
|
|---|
| 3022 | \fn QFontMetrics QWidget::fontMetrics() const
|
|---|
| 3023 |
|
|---|
| 3024 | Returns the font metrics for the widget's current font.
|
|---|
| 3025 | Equivalent to QFontMetrics(widget->font()).
|
|---|
| 3026 |
|
|---|
| 3027 | \sa font(), fontInfo(), setFont()
|
|---|
| 3028 | */
|
|---|
| 3029 |
|
|---|
| 3030 | /*!
|
|---|
| 3031 | \fn QFontInfo QWidget::fontInfo() const
|
|---|
| 3032 |
|
|---|
| 3033 | Returns the font info for the widget's current font.
|
|---|
| 3034 | Equivalent to QFontInto(widget->font()).
|
|---|
| 3035 |
|
|---|
| 3036 | \sa font(), fontMetrics(), setFont()
|
|---|
| 3037 | */
|
|---|
| 3038 |
|
|---|
| 3039 |
|
|---|
| 3040 | /*!
|
|---|
| 3041 | \property QWidget::cursor
|
|---|
| 3042 | \brief the cursor shape for this widget
|
|---|
| 3043 |
|
|---|
| 3044 | The mouse cursor will assume this shape when it's over this
|
|---|
| 3045 | widget. See the \link Qt::CursorShape list of predefined cursor
|
|---|
| 3046 | objects\endlink for a range of useful shapes.
|
|---|
| 3047 |
|
|---|
| 3048 | An editor widget might use an I-beam cursor:
|
|---|
| 3049 | \code
|
|---|
| 3050 | setCursor( IbeamCursor );
|
|---|
| 3051 | \endcode
|
|---|
| 3052 |
|
|---|
| 3053 | If no cursor has been set, or after a call to unsetCursor(), the
|
|---|
| 3054 | parent's cursor is used. The function unsetCursor() has no effect
|
|---|
| 3055 | on top-level widgets.
|
|---|
| 3056 |
|
|---|
| 3057 | \sa QApplication::setOverrideCursor()
|
|---|
| 3058 | */
|
|---|
| 3059 |
|
|---|
| 3060 | #ifndef QT_NO_CURSOR
|
|---|
| 3061 | const QCursor &QWidget::cursor() const
|
|---|
| 3062 | {
|
|---|
| 3063 | if ( testWState(WState_OwnCursor) )
|
|---|
| 3064 | return (extra && extra->curs)
|
|---|
| 3065 | ? *extra->curs
|
|---|
| 3066 | : arrowCursor;
|
|---|
| 3067 | else
|
|---|
| 3068 | return (isTopLevel() || !parentWidget()) ? arrowCursor : parentWidget()->cursor();
|
|---|
| 3069 | }
|
|---|
| 3070 | #endif
|
|---|
| 3071 | #ifndef QT_NO_WIDGET_TOPEXTRA
|
|---|
| 3072 | /*!
|
|---|
| 3073 | \property QWidget::caption
|
|---|
| 3074 | \brief the window caption (title)
|
|---|
| 3075 |
|
|---|
| 3076 | This property only makes sense for top-level widgets. If no
|
|---|
| 3077 | caption has been set, the caption is QString::null.
|
|---|
| 3078 |
|
|---|
| 3079 | \sa icon() iconText()
|
|---|
| 3080 | */
|
|---|
| 3081 | QString QWidget::caption() const
|
|---|
| 3082 | {
|
|---|
| 3083 | return extra && extra->topextra
|
|---|
| 3084 | ? extra->topextra->caption
|
|---|
| 3085 | : QString::null;
|
|---|
| 3086 | }
|
|---|
| 3087 |
|
|---|
| 3088 | /*!
|
|---|
| 3089 | \property QWidget::icon
|
|---|
| 3090 | \brief the widget's icon
|
|---|
| 3091 |
|
|---|
| 3092 | This property only makes sense for top-level widgets. If no icon
|
|---|
| 3093 | has been set, icon() returns 0.
|
|---|
| 3094 |
|
|---|
| 3095 | \sa iconText, caption,
|
|---|
| 3096 | \link appicon.html Setting the Application Icon\endlink
|
|---|
| 3097 | */
|
|---|
| 3098 | const QPixmap *QWidget::icon() const
|
|---|
| 3099 | {
|
|---|
| 3100 | return ( extra && extra->topextra ) ? extra->topextra->icon : 0;
|
|---|
| 3101 | }
|
|---|
| 3102 |
|
|---|
| 3103 | /*!
|
|---|
| 3104 | \property QWidget::iconText
|
|---|
| 3105 | \brief the widget's icon text
|
|---|
| 3106 |
|
|---|
| 3107 | This property only makes sense for top-level widgets. If no icon
|
|---|
| 3108 | text has been set, this functions returns QString::null.
|
|---|
| 3109 |
|
|---|
| 3110 | \sa icon, caption
|
|---|
| 3111 | */
|
|---|
| 3112 |
|
|---|
| 3113 | QString QWidget::iconText() const
|
|---|
| 3114 | {
|
|---|
| 3115 | return ( extra && extra->topextra ) ? extra->topextra->iconText
|
|---|
| 3116 | : QString::null;
|
|---|
| 3117 | }
|
|---|
| 3118 | #endif //QT_NO_WIDGET_TOPEXTRA
|
|---|
| 3119 |
|
|---|
| 3120 | /*!
|
|---|
| 3121 | \property QWidget::mouseTracking
|
|---|
| 3122 | \brief whether mouse tracking is enabled for the widget
|
|---|
| 3123 |
|
|---|
| 3124 | If mouse tracking is disabled (the default), the widget only
|
|---|
| 3125 | receives mouse move events when at least one mouse button is
|
|---|
| 3126 | pressed while the mouse is being moved.
|
|---|
| 3127 |
|
|---|
| 3128 | If mouse tracking is enabled, the widget receives mouse move
|
|---|
| 3129 | events even if no buttons are pressed.
|
|---|
| 3130 |
|
|---|
| 3131 | \sa mouseMoveEvent(), QApplication::setGlobalMouseTracking()
|
|---|
| 3132 | */
|
|---|
| 3133 |
|
|---|
| 3134 |
|
|---|
| 3135 | /*!
|
|---|
| 3136 | Sets the widget's focus proxy to widget \a w. If \a w is 0, the
|
|---|
| 3137 | function resets this widget to have no focus proxy.
|
|---|
| 3138 |
|
|---|
| 3139 | Some widgets, such as QComboBox, can "have focus", but create a
|
|---|
| 3140 | child widget to actually handle the focus. QComboBox, for example,
|
|---|
| 3141 | creates a QLineEdit which handles the focus.
|
|---|
| 3142 |
|
|---|
| 3143 | setFocusProxy() sets the widget which will actually get focus when
|
|---|
| 3144 | "this widget" gets it. If there is a focus proxy, focusPolicy(),
|
|---|
| 3145 | setFocusPolicy(), setFocus() and hasFocus() all operate on the
|
|---|
| 3146 | focus proxy.
|
|---|
| 3147 |
|
|---|
| 3148 | \sa focusProxy()
|
|---|
| 3149 | */
|
|---|
| 3150 |
|
|---|
| 3151 | void QWidget::setFocusProxy( QWidget * w )
|
|---|
| 3152 | {
|
|---|
| 3153 | if ( !w && !extra )
|
|---|
| 3154 | return;
|
|---|
| 3155 |
|
|---|
| 3156 | for ( QWidget* fp = w; fp; fp = fp->focusProxy() ) {
|
|---|
| 3157 | if ( fp == this ) {
|
|---|
| 3158 | #if defined (QT_CHECK_STATE)
|
|---|
| 3159 | qWarning( "%s (%s): already in focus proxy chain", className(), name() );
|
|---|
| 3160 | #endif
|
|---|
| 3161 | return;
|
|---|
| 3162 | }
|
|---|
| 3163 | }
|
|---|
| 3164 |
|
|---|
| 3165 | createExtra();
|
|---|
| 3166 |
|
|---|
| 3167 | if ( extra->focus_proxy ) {
|
|---|
| 3168 | disconnect( extra->focus_proxy, SIGNAL(destroyed()),
|
|---|
| 3169 | this, SLOT(focusProxyDestroyed()) );
|
|---|
| 3170 | extra->focus_proxy = 0;
|
|---|
| 3171 | }
|
|---|
| 3172 |
|
|---|
| 3173 | if ( w ) {
|
|---|
| 3174 | setFocusPolicy( w->focusPolicy() );
|
|---|
| 3175 | connect( w, SIGNAL(destroyed()),
|
|---|
| 3176 | this, SLOT(focusProxyDestroyed()) );
|
|---|
| 3177 | }
|
|---|
| 3178 | extra->focus_proxy = w;
|
|---|
| 3179 | }
|
|---|
| 3180 |
|
|---|
| 3181 |
|
|---|
| 3182 | /*!
|
|---|
| 3183 | Returns the focus proxy, or 0 if there is no focus proxy.
|
|---|
| 3184 |
|
|---|
| 3185 | \sa setFocusProxy()
|
|---|
| 3186 | */
|
|---|
| 3187 |
|
|---|
| 3188 | QWidget * QWidget::focusProxy() const
|
|---|
| 3189 | {
|
|---|
| 3190 | return extra ? extra->focus_proxy : 0;
|
|---|
| 3191 | }
|
|---|
| 3192 |
|
|---|
| 3193 |
|
|---|
| 3194 | /*!
|
|---|
| 3195 | \internal
|
|---|
| 3196 |
|
|---|
| 3197 | Internal slot used to clean up if the focus proxy is destroyed.
|
|---|
| 3198 |
|
|---|
| 3199 | \sa setFocusProxy()
|
|---|
| 3200 | */
|
|---|
| 3201 |
|
|---|
| 3202 | void QWidget::focusProxyDestroyed()
|
|---|
| 3203 | {
|
|---|
| 3204 | if ( extra )
|
|---|
| 3205 | extra->focus_proxy = 0;
|
|---|
| 3206 | setFocusPolicy( NoFocus );
|
|---|
| 3207 | }
|
|---|
| 3208 |
|
|---|
| 3209 | /*!
|
|---|
| 3210 | \property QWidget::focus
|
|---|
| 3211 | \brief whether this widget (or its focus proxy) has the keyboard
|
|---|
| 3212 | input focus
|
|---|
| 3213 |
|
|---|
| 3214 | Effectively equivalent to \c {qApp->focusWidget() == this}.
|
|---|
| 3215 |
|
|---|
| 3216 | \sa setFocus(), clearFocus(), setFocusPolicy(), QApplication::focusWidget()
|
|---|
| 3217 | */
|
|---|
| 3218 | bool QWidget::hasFocus() const
|
|---|
| 3219 | {
|
|---|
| 3220 | const QWidget* w = this;
|
|---|
| 3221 | while ( w->focusProxy() )
|
|---|
| 3222 | w = w->focusProxy();
|
|---|
| 3223 | return qApp->focusWidget() == w;
|
|---|
| 3224 | }
|
|---|
| 3225 |
|
|---|
| 3226 | /*!
|
|---|
| 3227 | Gives the keyboard input focus to this widget (or its focus
|
|---|
| 3228 | proxy) if this widget or one of its parents is the \link
|
|---|
| 3229 | isActiveWindow() active window\endlink.
|
|---|
| 3230 |
|
|---|
| 3231 | First, a focus out event is sent to the focus widget (if any) to
|
|---|
| 3232 | tell it that it is about to lose the focus. Then a focus in event
|
|---|
| 3233 | is sent to this widget to tell it that it just received the focus.
|
|---|
| 3234 | (Nothing happens if the focus in and focus out widgets are the
|
|---|
| 3235 | same.)
|
|---|
| 3236 |
|
|---|
| 3237 | setFocus() gives focus to a widget regardless of its focus policy,
|
|---|
| 3238 | but does not clear any keyboard grab (see grabKeyboard()).
|
|---|
| 3239 |
|
|---|
| 3240 | Be aware that if the widget is hidden, it will not accept focus.
|
|---|
| 3241 |
|
|---|
| 3242 | \warning If you call setFocus() in a function which may itself be
|
|---|
| 3243 | called from focusOutEvent() or focusInEvent(), you may get an
|
|---|
| 3244 | infinite recursion.
|
|---|
| 3245 |
|
|---|
| 3246 | \sa hasFocus() clearFocus() focusInEvent() focusOutEvent()
|
|---|
| 3247 | setFocusPolicy() QApplication::focusWidget() grabKeyboard()
|
|---|
| 3248 | grabMouse()
|
|---|
| 3249 | */
|
|---|
| 3250 |
|
|---|
| 3251 | void QWidget::setFocus()
|
|---|
| 3252 | {
|
|---|
| 3253 | if ( !isEnabled() )
|
|---|
| 3254 | return;
|
|---|
| 3255 |
|
|---|
| 3256 | if ( focusProxy() ) {
|
|---|
| 3257 | focusProxy()->setFocus();
|
|---|
| 3258 | return;
|
|---|
| 3259 | }
|
|---|
| 3260 |
|
|---|
| 3261 | QFocusData * f = focusData( TRUE );
|
|---|
| 3262 | if ( f->it.current() == this && qApp->focusWidget() == this
|
|---|
| 3263 | #if defined(Q_WS_WIN)
|
|---|
| 3264 | && GetFocus() == winId()
|
|---|
| 3265 | #elif defined(Q_WS_PM)
|
|---|
| 3266 | //@@TODO (dmik): currently we don't use WinSetFocus(). what for? Qt seems
|
|---|
| 3267 | // to completely handle focus traversal itself.
|
|---|
| 3268 | // && WinQueryFocus( HWND_DESKTOP ) == winId()
|
|---|
| 3269 | #endif
|
|---|
| 3270 | )
|
|---|
| 3271 | return;
|
|---|
| 3272 |
|
|---|
| 3273 | f->it.toFirst();
|
|---|
| 3274 | while ( f->it.current() != this && !f->it.atLast() )
|
|---|
| 3275 | ++f->it;
|
|---|
| 3276 | // at this point, the iterator should point to 'this'. if it
|
|---|
| 3277 | // does not, 'this' must not be in the list - an error, but
|
|---|
| 3278 | // perhaps possible. fix it.
|
|---|
| 3279 | if ( f->it.current() != this ) {
|
|---|
| 3280 | f->focusWidgets.append( this );
|
|---|
| 3281 | f->it.toLast();
|
|---|
| 3282 | }
|
|---|
| 3283 |
|
|---|
| 3284 | if ( isActiveWindow() ) {
|
|---|
| 3285 | QWidget * prev = qApp->focus_widget;
|
|---|
| 3286 | if ( prev ) {
|
|---|
| 3287 | if ( prev != this )
|
|---|
| 3288 | prev->resetInputContext();
|
|---|
| 3289 | }
|
|---|
| 3290 | #if defined(Q_WS_WIN)
|
|---|
| 3291 | else {
|
|---|
| 3292 | QInputContext::endComposition();
|
|---|
| 3293 | }
|
|---|
| 3294 | #endif
|
|---|
| 3295 | qApp->focus_widget = this;
|
|---|
| 3296 | #if defined(Q_WS_X11)
|
|---|
| 3297 | focusInputContext();
|
|---|
| 3298 | #endif
|
|---|
| 3299 |
|
|---|
| 3300 | #if defined(Q_WS_WIN)
|
|---|
| 3301 | if ( !topLevelWidget()->isPopup() )
|
|---|
| 3302 | SetFocus( winId() );
|
|---|
| 3303 | else {
|
|---|
| 3304 | #elif defined(Q_WS_PM)
|
|---|
| 3305 | //@@TODO (dmik): currently we don't use WinSetFocus(). what for? Qt seems
|
|---|
| 3306 | // to completely handle focus traversal itself.
|
|---|
| 3307 | // if ( !topLevelWidget()->isPopup() )
|
|---|
| 3308 | // WinSetFocus( HWND_DESKTOP, winId() );
|
|---|
| 3309 | // else {
|
|---|
| 3310 | #endif
|
|---|
| 3311 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
|---|
| 3312 | QAccessible::updateAccessibility( this, 0, QAccessible::Focus );
|
|---|
| 3313 | #endif
|
|---|
| 3314 | #if defined(Q_WS_WIN) // || defined(Q_WS_PM)
|
|---|
| 3315 | }
|
|---|
| 3316 | #endif
|
|---|
| 3317 |
|
|---|
| 3318 | if ( prev != this ) {
|
|---|
| 3319 | if ( prev ) {
|
|---|
| 3320 | QFocusEvent out( QEvent::FocusOut );
|
|---|
| 3321 | QApplication::sendEvent( prev, &out );
|
|---|
| 3322 | }
|
|---|
| 3323 |
|
|---|
| 3324 | if ( qApp->focus_widget == this ) {
|
|---|
| 3325 | QFocusEvent in( QEvent::FocusIn );
|
|---|
| 3326 | QApplication::sendEvent( this, &in );
|
|---|
| 3327 | }
|
|---|
| 3328 | }
|
|---|
| 3329 | }
|
|---|
| 3330 | }
|
|---|
| 3331 |
|
|---|
| 3332 | /*!
|
|---|
| 3333 | Takes keyboard input focus from the widget.
|
|---|
| 3334 |
|
|---|
| 3335 | If the widget has active focus, a \link focusOutEvent() focus out
|
|---|
| 3336 | event\endlink is sent to this widget to tell it that it is about
|
|---|
| 3337 | to lose the focus.
|
|---|
| 3338 |
|
|---|
| 3339 | This widget must enable focus setting in order to get the keyboard
|
|---|
| 3340 | input focus, i.e. it must call setFocusPolicy().
|
|---|
| 3341 |
|
|---|
| 3342 | \sa hasFocus(), setFocus(), focusInEvent(), focusOutEvent(),
|
|---|
| 3343 | setFocusPolicy(), QApplication::focusWidget()
|
|---|
| 3344 | */
|
|---|
| 3345 |
|
|---|
| 3346 | void QWidget::clearFocus()
|
|---|
| 3347 | {
|
|---|
| 3348 | if ( focusProxy() ) {
|
|---|
| 3349 | focusProxy()->clearFocus();
|
|---|
| 3350 | return;
|
|---|
| 3351 | } else if ( hasFocus() ) {
|
|---|
| 3352 | QWidget* w = qApp->focusWidget();
|
|---|
| 3353 | // clear active focus
|
|---|
| 3354 | qApp->focus_widget = 0;
|
|---|
| 3355 | QFocusEvent out( QEvent::FocusOut );
|
|---|
| 3356 | QApplication::sendEvent( w, &out );
|
|---|
| 3357 | #if defined(Q_WS_WIN)
|
|---|
| 3358 | if ( !isPopup() && GetFocus() == winId() )
|
|---|
| 3359 | SetFocus( 0 );
|
|---|
| 3360 | else {
|
|---|
| 3361 | #elif defined(Q_WS_PM)
|
|---|
| 3362 | //@@TODO (dmik): currently we don't use WinSetFocus(). what for? Qt seems
|
|---|
| 3363 | // to completely handle focus traversal itself.
|
|---|
| 3364 | // if ( !isPopup() && WinQueryFocus( HWND_DESKTOP ) == winId() )
|
|---|
| 3365 | // WinSetFocus( HWND_DESKTOP, topLevelWidget()->winId() );
|
|---|
| 3366 | // else {
|
|---|
| 3367 | #endif
|
|---|
| 3368 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
|---|
| 3369 | QAccessible::updateAccessibility( this, 0, QAccessible::Focus );
|
|---|
| 3370 | #endif
|
|---|
| 3371 | #if defined(Q_WS_WIN) // || defined(Q_WS_PM)
|
|---|
| 3372 | }
|
|---|
| 3373 | #endif
|
|---|
| 3374 | }
|
|---|
| 3375 | }
|
|---|
| 3376 |
|
|---|
| 3377 |
|
|---|
| 3378 | /*!
|
|---|
| 3379 | Finds a new widget to give the keyboard focus to, as appropriate
|
|---|
| 3380 | for Tab and Shift+Tab, and returns TRUE if is can find a new
|
|---|
| 3381 | widget and FALSE if it can't,
|
|---|
| 3382 |
|
|---|
| 3383 | If \a next is TRUE, this function searches "forwards", if \a next
|
|---|
| 3384 | is FALSE, it searches "backwards".
|
|---|
| 3385 |
|
|---|
| 3386 | Sometimes, you will want to reimplement this function. For
|
|---|
| 3387 | example, a web browser might reimplement it to move its "current
|
|---|
| 3388 | active link" forwards or backwards, and call
|
|---|
| 3389 | QWidget::focusNextPrevChild() only when it reaches the last or
|
|---|
| 3390 | first link on the "page".
|
|---|
| 3391 |
|
|---|
| 3392 | Child widgets call focusNextPrevChild() on their parent widgets,
|
|---|
| 3393 | but only the top-level widget decides where to redirect focus. By
|
|---|
| 3394 | overriding this method for an object, you thus gain control of
|
|---|
| 3395 | focus traversal for all child widgets.
|
|---|
| 3396 |
|
|---|
| 3397 | \warning QScrollView uses it own logic for this function, which
|
|---|
| 3398 | does the right thing in most cases. But if you are using a
|
|---|
| 3399 | QScrollView and want complete control of the focus chain you'll
|
|---|
| 3400 | need to override QScrollView::focusNextPrevChild() and your
|
|---|
| 3401 | top-level widgets' focusNextPrevChild() functions.
|
|---|
| 3402 |
|
|---|
| 3403 | \sa focusData()
|
|---|
| 3404 | */
|
|---|
| 3405 |
|
|---|
| 3406 | bool QWidget::focusNextPrevChild( bool next )
|
|---|
| 3407 | {
|
|---|
| 3408 | QWidget* p = parentWidget();
|
|---|
| 3409 | if ( !isTopLevel() && p )
|
|---|
| 3410 | return p->focusNextPrevChild(next);
|
|---|
| 3411 |
|
|---|
| 3412 | QFocusData *f = focusData( TRUE );
|
|---|
| 3413 |
|
|---|
| 3414 | QWidget *startingPoint = f->it.current();
|
|---|
| 3415 | QWidget *candidate = 0;
|
|---|
| 3416 | QWidget *w = next ? f->focusWidgets.last() : f->focusWidgets.first();
|
|---|
| 3417 | extern bool qt_tab_all_widgets;
|
|---|
| 3418 | uint focus_flag = qt_tab_all_widgets ? TabFocus : StrongFocus;
|
|---|
| 3419 | do {
|
|---|
| 3420 | if ( w && w != startingPoint &&
|
|---|
| 3421 | ( ( w->focusPolicy() & focus_flag ) == focus_flag )
|
|---|
| 3422 | && !w->focusProxy() && w->isVisibleTo(this) && w->isEnabled())
|
|---|
| 3423 | candidate = w;
|
|---|
| 3424 | w = next ? f->focusWidgets.prev() : f->focusWidgets.next();
|
|---|
| 3425 | } while( w && !(candidate && w==startingPoint) );
|
|---|
| 3426 |
|
|---|
| 3427 | if ( !candidate )
|
|---|
| 3428 | return FALSE;
|
|---|
| 3429 |
|
|---|
| 3430 | candidate->setFocus();
|
|---|
| 3431 | return TRUE;
|
|---|
| 3432 | }
|
|---|
| 3433 |
|
|---|
| 3434 | /*!
|
|---|
| 3435 | Returns the focus widget in this widget's window. This is not the
|
|---|
| 3436 | same as QApplication::focusWidget(), which returns the focus
|
|---|
| 3437 | widget in the currently active window.
|
|---|
| 3438 | */
|
|---|
| 3439 |
|
|---|
| 3440 | QWidget *QWidget::focusWidget() const
|
|---|
| 3441 | {
|
|---|
| 3442 | QWidget *that = (QWidget *)this; // mutable
|
|---|
| 3443 | QFocusData *f = that->focusData( FALSE );
|
|---|
| 3444 | if ( f && f->focusWidgets.count() && f->it.current() == 0 )
|
|---|
| 3445 | f->it.toFirst();
|
|---|
| 3446 | return ( f && f->it.current() ) ? f->it.current() : 0;
|
|---|
| 3447 | }
|
|---|
| 3448 |
|
|---|
| 3449 |
|
|---|
| 3450 | /*!
|
|---|
| 3451 | Returns the focus data for this widget's top-level widget.
|
|---|
| 3452 |
|
|---|
| 3453 | Focus data always belongs to the top-level widget. The focus data
|
|---|
| 3454 | list contains all the widgets in this top-level widget that can
|
|---|
| 3455 | accept focus, in tab order. An iterator points to the current
|
|---|
| 3456 | focus widget (focusWidget() returns a pointer to this widget).
|
|---|
| 3457 |
|
|---|
| 3458 | This information is useful for implementing advanced versions of
|
|---|
| 3459 | focusNextPrevChild().
|
|---|
| 3460 | */
|
|---|
| 3461 | QFocusData * QWidget::focusData()
|
|---|
| 3462 | {
|
|---|
| 3463 | return focusData( TRUE );
|
|---|
| 3464 | }
|
|---|
| 3465 |
|
|---|
| 3466 | /*!
|
|---|
| 3467 | \internal
|
|---|
| 3468 |
|
|---|
| 3469 | Internal function which lets us ask for the focus data, creating
|
|---|
| 3470 | it if it doesn't exist and \a create is TRUE.
|
|---|
| 3471 | */
|
|---|
| 3472 | QFocusData * QWidget::focusData( bool create )
|
|---|
| 3473 | {
|
|---|
| 3474 | QWidget * tlw = topLevelWidget();
|
|---|
| 3475 | QWExtra * ed = tlw->extraData();
|
|---|
| 3476 | if ( !ed || !ed->topextra ) {
|
|---|
| 3477 | if ( !create )
|
|---|
| 3478 | return 0;
|
|---|
| 3479 | tlw->createTLExtra();
|
|---|
| 3480 | ed = tlw->extraData();
|
|---|
| 3481 | }
|
|---|
| 3482 | if ( create && !ed->topextra->focusData )
|
|---|
| 3483 | ed->topextra->focusData = new QFocusData;
|
|---|
| 3484 |
|
|---|
| 3485 | return ed->topextra->focusData;
|
|---|
| 3486 | }
|
|---|
| 3487 |
|
|---|
| 3488 | /*!
|
|---|
| 3489 | \property QWidget::inputMethodEnabled
|
|---|
| 3490 | \brief enables or disables the use of input methods for this widget.
|
|---|
| 3491 |
|
|---|
| 3492 | Most Widgets (as eg. buttons) that do not handle text input should have
|
|---|
| 3493 | the input method disabled if they have focus. This is the default.
|
|---|
| 3494 |
|
|---|
| 3495 | If a widget handles text input it should set this property to TRUE.
|
|---|
| 3496 | */
|
|---|
| 3497 |
|
|---|
| 3498 | void QWidget::setInputMethodEnabled( bool b )
|
|---|
| 3499 | {
|
|---|
| 3500 | im_enabled = b;
|
|---|
| 3501 | #ifdef Q_WS_WIN
|
|---|
| 3502 | QInputContext::enable( this, im_enabled & !((bool)testWState(WState_Disabled)) );
|
|---|
| 3503 | #endif
|
|---|
| 3504 | }
|
|---|
| 3505 |
|
|---|
| 3506 |
|
|---|
| 3507 | /*!
|
|---|
| 3508 | Enables key event compression, if \a compress is TRUE, and
|
|---|
| 3509 | disables it if \a compress is FALSE.
|
|---|
| 3510 |
|
|---|
| 3511 | Key compression is off by default (except for QLineEdit), so
|
|---|
| 3512 | widgets receive one key press event for each key press (or more,
|
|---|
| 3513 | since autorepeat is usually on). If you turn it on and your
|
|---|
| 3514 | program doesn't keep up with key input, Qt may try to compress key
|
|---|
| 3515 | events so that more than one character can be processed in each
|
|---|
| 3516 | event.
|
|---|
| 3517 |
|
|---|
| 3518 | For example, a word processor widget might receive 2, 3 or more
|
|---|
| 3519 | characters in each QKeyEvent::text(), if the layout recalculation
|
|---|
| 3520 | takes too long for the CPU.
|
|---|
| 3521 |
|
|---|
| 3522 | If a widget supports multiple character unicode input, it is
|
|---|
| 3523 | always safe to turn the compression on.
|
|---|
| 3524 |
|
|---|
| 3525 | Qt performs key event compression only for printable characters.
|
|---|
| 3526 | Modifier keys, cursor movement keys, function keys and
|
|---|
| 3527 | miscellaneous action keys (e.g. Escape, Enter, Backspace,
|
|---|
| 3528 | PrintScreen) will stop key event compression, even if there are
|
|---|
| 3529 | more compressible key events available.
|
|---|
| 3530 |
|
|---|
| 3531 | Not all platforms support this compression, in which case turning
|
|---|
| 3532 | it on will have no effect.
|
|---|
| 3533 |
|
|---|
| 3534 | \sa QKeyEvent::text();
|
|---|
| 3535 | */
|
|---|
| 3536 |
|
|---|
| 3537 | void QWidget::setKeyCompression(bool compress)
|
|---|
| 3538 | {
|
|---|
| 3539 | if ( compress )
|
|---|
| 3540 | setWState( WState_CompressKeys );
|
|---|
| 3541 | else
|
|---|
| 3542 | clearWState( WState_CompressKeys );
|
|---|
| 3543 | }
|
|---|
| 3544 |
|
|---|
| 3545 | /*!
|
|---|
| 3546 | \property QWidget::isActiveWindow
|
|---|
| 3547 | \brief whether this widget is the active window
|
|---|
| 3548 |
|
|---|
| 3549 | The active window is the window (or child of the window) that has
|
|---|
| 3550 | keyboard focus.
|
|---|
| 3551 |
|
|---|
| 3552 | When popup windows are visible, this property is TRUE for both the
|
|---|
| 3553 | active window \e and for the popup.
|
|---|
| 3554 |
|
|---|
| 3555 | \sa setActiveWindow(), QApplication::activeWindow()
|
|---|
| 3556 | */
|
|---|
| 3557 | bool QWidget::isActiveWindow() const
|
|---|
| 3558 | {
|
|---|
| 3559 | QWidget *tlw = topLevelWidget();
|
|---|
| 3560 | if(testWFlags(WSubWindow) && parentWidget())
|
|---|
| 3561 | tlw = parentWidget()->topLevelWidget();
|
|---|
| 3562 | if(tlw == qApp->activeWindow() || ( isVisible() && tlw->isPopup() ))
|
|---|
| 3563 | return TRUE;
|
|---|
| 3564 | #ifndef QT_NO_STYLE
|
|---|
| 3565 | if(style().styleHint(QStyle::SH_Widget_ShareActivation, this )) {
|
|---|
| 3566 | if(tlw->isDialog() && !tlw->testWFlags(WShowModal) &&
|
|---|
| 3567 | tlw->parentWidget() && tlw->parentWidget()->isActiveWindow())
|
|---|
| 3568 | return TRUE;
|
|---|
| 3569 | QWidget *w = qApp->activeWindow();
|
|---|
| 3570 | if( !testWFlags(WSubWindow) && w && w->testWFlags(WSubWindow) &&
|
|---|
| 3571 | w->parentWidget()->topLevelWidget() == tlw)
|
|---|
| 3572 | return TRUE;
|
|---|
| 3573 | while( w && w->isDialog() && !w->testWFlags(WShowModal) && w->parentWidget() ) {
|
|---|
| 3574 | w = w->parentWidget()->topLevelWidget();
|
|---|
| 3575 | if( w == tlw )
|
|---|
| 3576 | return TRUE;
|
|---|
| 3577 | }
|
|---|
| 3578 | }
|
|---|
| 3579 | #endif
|
|---|
| 3580 | #if defined(Q_WS_WIN32)
|
|---|
| 3581 | HWND parent = tlw->winId();
|
|---|
| 3582 | HWND topparent = GetActiveWindow();
|
|---|
| 3583 | while ( parent ) {
|
|---|
| 3584 | parent = ::GetParent( parent );
|
|---|
| 3585 | if ( parent && parent == topparent )
|
|---|
| 3586 | return TRUE;
|
|---|
| 3587 | }
|
|---|
| 3588 | #endif
|
|---|
| 3589 | //@@TODO (dmik): I think we don't need the same as above in OS/2,
|
|---|
| 3590 | // because if the window is active (in Qt terminology)
|
|---|
| 3591 | // qApp->activeWindow() will be equal to toplevelWidget() which is
|
|---|
| 3592 | // checked at the beginnig.
|
|---|
| 3593 |
|
|---|
| 3594 | return FALSE;
|
|---|
| 3595 | }
|
|---|
| 3596 |
|
|---|
| 3597 | /*!
|
|---|
| 3598 | Moves the \a second widget around the ring of focus widgets so
|
|---|
| 3599 | that keyboard focus moves from the \a first widget to the \a
|
|---|
| 3600 | second widget when the Tab key is pressed.
|
|---|
| 3601 |
|
|---|
| 3602 | Note that since the tab order of the \a second widget is changed,
|
|---|
| 3603 | you should order a chain like this:
|
|---|
| 3604 |
|
|---|
| 3605 | \code
|
|---|
| 3606 | setTabOrder( a, b ); // a to b
|
|---|
| 3607 | setTabOrder( b, c ); // a to b to c
|
|---|
| 3608 | setTabOrder( c, d ); // a to b to c to d
|
|---|
| 3609 | \endcode
|
|---|
| 3610 |
|
|---|
| 3611 | \e not like this:
|
|---|
| 3612 |
|
|---|
| 3613 | \code
|
|---|
| 3614 | setTabOrder( c, d ); // c to d WRONG
|
|---|
| 3615 | setTabOrder( a, b ); // a to b AND c to d
|
|---|
| 3616 | setTabOrder( b, c ); // a to b to c, but not c to d
|
|---|
| 3617 | \endcode
|
|---|
| 3618 |
|
|---|
| 3619 | If \a first or \a second has a focus proxy, setTabOrder()
|
|---|
| 3620 | correctly substitutes the proxy.
|
|---|
| 3621 |
|
|---|
| 3622 | \sa setFocusPolicy(), setFocusProxy()
|
|---|
| 3623 | */
|
|---|
| 3624 | void QWidget::setTabOrder( QWidget* first, QWidget *second )
|
|---|
| 3625 | {
|
|---|
| 3626 | if ( !first || !second ||
|
|---|
| 3627 | first->focusPolicy() == NoFocus || second->focusPolicy() == NoFocus )
|
|---|
| 3628 | return;
|
|---|
| 3629 |
|
|---|
| 3630 | // If first is redirected, set first to the last child of first
|
|---|
| 3631 | // that can take keyboard focus so that second is inserted after
|
|---|
| 3632 | // that last child, and the focus order within first is (more
|
|---|
| 3633 | // likely to be) preserved.
|
|---|
| 3634 | if ( first->focusProxy() ) {
|
|---|
| 3635 | QObjectList *l = first->queryList( "QWidget" );
|
|---|
| 3636 | if ( l && l->count() ) {
|
|---|
| 3637 | QObjectListIt it(*l);
|
|---|
| 3638 | it.toLast();
|
|---|
| 3639 | while (it.current()) {
|
|---|
| 3640 | if (((QWidget*)it.current())->topLevelWidget() == first->topLevelWidget()) {
|
|---|
| 3641 | first = (QWidget*)it.current();
|
|---|
| 3642 | if (first->focusPolicy() != NoFocus)
|
|---|
| 3643 | break;
|
|---|
| 3644 | }
|
|---|
| 3645 | --it;
|
|---|
| 3646 | }
|
|---|
| 3647 | }
|
|---|
| 3648 | delete l;
|
|---|
| 3649 | }
|
|---|
| 3650 | while ( first->focusProxy() )
|
|---|
| 3651 | first = first->focusProxy();
|
|---|
| 3652 | while ( second->focusProxy() )
|
|---|
| 3653 | second = second->focusProxy();
|
|---|
| 3654 |
|
|---|
| 3655 | QFocusData *f = first->focusData( TRUE );
|
|---|
| 3656 | bool focusThere = (f->it.current() == second );
|
|---|
| 3657 | f->focusWidgets.removeRef( second );
|
|---|
| 3658 | if ( f->focusWidgets.findRef( first ) >= 0 )
|
|---|
| 3659 | f->focusWidgets.insert( f->focusWidgets.at() + 1, second );
|
|---|
| 3660 | else
|
|---|
| 3661 | f->focusWidgets.append( second );
|
|---|
| 3662 | if ( focusThere ) { // reset iterator so tab will work appropriately
|
|---|
| 3663 | f->it.toFirst();
|
|---|
| 3664 | while( f->it.current() && f->it.current() != second )
|
|---|
| 3665 | ++f->it;
|
|---|
| 3666 | }
|
|---|
| 3667 | }
|
|---|
| 3668 |
|
|---|
| 3669 | /*!\internal
|
|---|
| 3670 |
|
|---|
| 3671 | Moves the relevant subwidgets of this widget from the \a oldtlw's
|
|---|
| 3672 | tab chain to that of the new parent, if there's anything to move and
|
|---|
| 3673 | we're really moving
|
|---|
| 3674 |
|
|---|
| 3675 | This function is called from QWidget::reparent() *after* the widget
|
|---|
| 3676 | has been reparented.
|
|---|
| 3677 |
|
|---|
| 3678 | \sa reparent()
|
|---|
| 3679 | */
|
|---|
| 3680 |
|
|---|
| 3681 | void QWidget::reparentFocusWidgets( QWidget * oldtlw )
|
|---|
| 3682 | {
|
|---|
| 3683 | if ( oldtlw == topLevelWidget() )
|
|---|
| 3684 | return; // nothing to do
|
|---|
| 3685 |
|
|---|
| 3686 | QFocusData * from = oldtlw ? oldtlw->topData()->focusData : 0;
|
|---|
| 3687 | QFocusData * to;
|
|---|
| 3688 | to = focusData();
|
|---|
| 3689 |
|
|---|
| 3690 | if ( from ) {
|
|---|
| 3691 | from->focusWidgets.first();
|
|---|
| 3692 | do {
|
|---|
| 3693 | QWidget * pw = from->focusWidgets.current();
|
|---|
| 3694 | while( pw && pw != this )
|
|---|
| 3695 | pw = pw->parentWidget();
|
|---|
| 3696 | if ( pw == this ) {
|
|---|
| 3697 | QWidget * w = from->focusWidgets.take();
|
|---|
| 3698 | if ( w == from->it.current() )
|
|---|
| 3699 | // probably best to clear keyboard focus, or
|
|---|
| 3700 | // the user might become rather confused
|
|---|
| 3701 | w->clearFocus();
|
|---|
| 3702 | if ( !isTopLevel() )
|
|---|
| 3703 | to->focusWidgets.append( w );
|
|---|
| 3704 | } else {
|
|---|
| 3705 | from->focusWidgets.next();
|
|---|
| 3706 | }
|
|---|
| 3707 | } while( from->focusWidgets.current() );
|
|---|
| 3708 | }
|
|---|
| 3709 |
|
|---|
| 3710 | if ( to->focusWidgets.findRef(this) < 0 )
|
|---|
| 3711 | to->focusWidgets.append( this );
|
|---|
| 3712 |
|
|---|
| 3713 | if ( !isTopLevel() && extra && extra->topextra && extra->topextra->focusData ) {
|
|---|
| 3714 | // this widget is no longer a top-level widget, so get rid
|
|---|
| 3715 | // of old focus data
|
|---|
| 3716 | delete extra->topextra->focusData;
|
|---|
| 3717 | extra->topextra->focusData = 0;
|
|---|
| 3718 | }
|
|---|
| 3719 | }
|
|---|
| 3720 |
|
|---|
| 3721 | /*!
|
|---|
| 3722 | \fn void QWidget::recreate( QWidget *parent, WFlags f, const QPoint & p, bool showIt )
|
|---|
| 3723 |
|
|---|
| 3724 | \obsolete
|
|---|
| 3725 |
|
|---|
| 3726 | This method is provided to aid porting from Qt 1.0 to 2.0. It has
|
|---|
| 3727 | been renamed reparent() in Qt 2.0.
|
|---|
| 3728 | */
|
|---|
| 3729 |
|
|---|
| 3730 | /*!
|
|---|
| 3731 | \property QWidget::frameSize
|
|---|
| 3732 | \brief the size of the widget including any window frame
|
|---|
| 3733 | */
|
|---|
| 3734 | QSize QWidget::frameSize() const
|
|---|
| 3735 | {
|
|---|
| 3736 | if ( isTopLevel() && !isPopup() ) {
|
|---|
| 3737 | if ( fstrut_dirty )
|
|---|
| 3738 | updateFrameStrut();
|
|---|
| 3739 | QWidget *that = (QWidget *) this;
|
|---|
| 3740 | QTLWExtra *top = that->topData();
|
|---|
| 3741 | return QSize( crect.width() + top->fleft + top->fright,
|
|---|
| 3742 | crect.height() + top->ftop + top->fbottom );
|
|---|
| 3743 | }
|
|---|
| 3744 | return crect.size();
|
|---|
| 3745 | }
|
|---|
| 3746 |
|
|---|
| 3747 | /*!
|
|---|
| 3748 | \internal
|
|---|
| 3749 |
|
|---|
| 3750 | Recursive function that updates \a widget and all its children,
|
|---|
| 3751 | if they have some parent background origin.
|
|---|
| 3752 | */
|
|---|
| 3753 | static void qt_update_bg_recursive( QWidget *widget )
|
|---|
| 3754 | {
|
|---|
| 3755 | if ( !widget || widget->isHidden() || widget->backgroundOrigin() == QWidget::WidgetOrigin || !widget->backgroundPixmap() )
|
|---|
| 3756 | return;
|
|---|
| 3757 |
|
|---|
| 3758 | const QObjectList *lst = widget->children();
|
|---|
| 3759 |
|
|---|
| 3760 | if ( lst ) {
|
|---|
| 3761 | QObjectListIterator it( *lst );
|
|---|
| 3762 | QWidget *widget;
|
|---|
| 3763 | while ( (widget = (QWidget*)it.current()) ) {
|
|---|
| 3764 | ++it;
|
|---|
| 3765 | if ( widget->isWidgetType() && !widget->isHidden() && !widget->isTopLevel() && !widget->testWFlags(Qt::WSubWindow) )
|
|---|
| 3766 | qt_update_bg_recursive( widget );
|
|---|
| 3767 | }
|
|---|
| 3768 | }
|
|---|
| 3769 | QApplication::postEvent( widget, new QPaintEvent( widget->clipRegion(), !widget->testWFlags(Qt::WRepaintNoErase) ) );
|
|---|
| 3770 | }
|
|---|
| 3771 |
|
|---|
| 3772 | /*!
|
|---|
| 3773 | \overload
|
|---|
| 3774 |
|
|---|
| 3775 | This corresponds to move( QSize(\a x, \a y) ).
|
|---|
| 3776 | */
|
|---|
| 3777 |
|
|---|
| 3778 | void QWidget::move( int x, int y )
|
|---|
| 3779 | {
|
|---|
| 3780 | QPoint oldp(pos());
|
|---|
| 3781 | internalSetGeometry( x + geometry().x() - QWidget::x(),
|
|---|
| 3782 | y + geometry().y() - QWidget::y(),
|
|---|
| 3783 | width(), height(), TRUE );
|
|---|
| 3784 | if ( isVisible() && oldp != pos() )
|
|---|
| 3785 | qt_update_bg_recursive( this );
|
|---|
| 3786 | }
|
|---|
| 3787 |
|
|---|
| 3788 | /*!
|
|---|
| 3789 | \overload
|
|---|
| 3790 |
|
|---|
| 3791 | This corresponds to resize( QSize(\a w, \a h) ).
|
|---|
| 3792 | */
|
|---|
| 3793 | void QWidget::resize( int w, int h )
|
|---|
| 3794 | {
|
|---|
| 3795 | internalSetGeometry( geometry().x(), geometry().y(), w, h, FALSE );
|
|---|
| 3796 | setWState( WState_Resized );
|
|---|
| 3797 | }
|
|---|
| 3798 |
|
|---|
| 3799 | /*!
|
|---|
| 3800 | \overload
|
|---|
| 3801 |
|
|---|
| 3802 | This corresponds to setGeometry( QRect(\a x, \a y, \a w, \a h) ).
|
|---|
| 3803 | */
|
|---|
| 3804 | void QWidget::setGeometry( int x, int y, int w, int h )
|
|---|
| 3805 | {
|
|---|
| 3806 | QPoint oldp( pos( ));
|
|---|
| 3807 | internalSetGeometry( x, y, w, h, TRUE );
|
|---|
| 3808 | setWState( WState_Resized );
|
|---|
| 3809 | if ( isVisible() && oldp != pos() )
|
|---|
| 3810 | qt_update_bg_recursive( this );
|
|---|
| 3811 | }
|
|---|
| 3812 |
|
|---|
| 3813 | /*!
|
|---|
| 3814 | \property QWidget::focusEnabled
|
|---|
| 3815 | \brief whether the widget accepts keyboard focus
|
|---|
| 3816 |
|
|---|
| 3817 | Keyboard focus is initially disabled (i.e. focusPolicy() ==
|
|---|
| 3818 | \c QWidget::NoFocus).
|
|---|
| 3819 |
|
|---|
| 3820 | You must enable keyboard focus for a widget if it processes
|
|---|
| 3821 | keyboard events. This is normally done from the widget's
|
|---|
| 3822 | constructor. For instance, the QLineEdit constructor calls
|
|---|
| 3823 | setFocusPolicy(QWidget::StrongFocus).
|
|---|
| 3824 |
|
|---|
| 3825 | \sa setFocusPolicy(), focusInEvent(), focusOutEvent(), keyPressEvent(),
|
|---|
| 3826 | keyReleaseEvent(), isEnabled()
|
|---|
| 3827 | */
|
|---|
| 3828 |
|
|---|
| 3829 | /*!
|
|---|
| 3830 | \enum QWidget::FocusPolicy
|
|---|
| 3831 |
|
|---|
| 3832 | This enum type defines the various policies a widget can have with
|
|---|
| 3833 | respect to acquiring keyboard focus.
|
|---|
| 3834 |
|
|---|
| 3835 | \value TabFocus the widget accepts focus by tabbing.
|
|---|
| 3836 | \value ClickFocus the widget accepts focus by clicking.
|
|---|
| 3837 | \value StrongFocus the widget accepts focus by both tabbing
|
|---|
| 3838 | and clicking. On Mac OS X this will also
|
|---|
| 3839 | be indicate that the widget accepts tab focus
|
|---|
| 3840 | when in 'Text/List focus mode'.
|
|---|
| 3841 | \value WheelFocus like StrongFocus plus the widget accepts
|
|---|
| 3842 | focus by using the mouse wheel.
|
|---|
| 3843 | \value NoFocus the widget does not accept focus.
|
|---|
| 3844 |
|
|---|
| 3845 | */
|
|---|
| 3846 |
|
|---|
| 3847 | /*!
|
|---|
| 3848 | \property QWidget::focusPolicy
|
|---|
| 3849 | \brief the way the widget accepts keyboard focus
|
|---|
| 3850 |
|
|---|
| 3851 | The policy is \c QWidget::TabFocus if the widget accepts keyboard
|
|---|
| 3852 | focus by tabbing, \c QWidget::ClickFocus if the widget accepts
|
|---|
| 3853 | focus by clicking, \c QWidget::StrongFocus if it accepts both, and
|
|---|
| 3854 | \c QWidget::NoFocus (the default) if it does not accept focus at
|
|---|
| 3855 | all.
|
|---|
| 3856 |
|
|---|
| 3857 | You must enable keyboard focus for a widget if it processes
|
|---|
| 3858 | keyboard events. This is normally done from the widget's
|
|---|
| 3859 | constructor. For instance, the QLineEdit constructor calls
|
|---|
| 3860 | setFocusPolicy(QWidget::StrongFocus).
|
|---|
| 3861 |
|
|---|
| 3862 | \sa focusEnabled, focusInEvent(), focusOutEvent(), keyPressEvent(),
|
|---|
| 3863 | keyReleaseEvent(), enabled
|
|---|
| 3864 | */
|
|---|
| 3865 |
|
|---|
| 3866 | void QWidget::setFocusPolicy( FocusPolicy policy )
|
|---|
| 3867 | {
|
|---|
| 3868 | if ( focusProxy() )
|
|---|
| 3869 | focusProxy()->setFocusPolicy( policy );
|
|---|
| 3870 | if ( policy != NoFocus ) {
|
|---|
| 3871 | QFocusData * f = focusData( TRUE );
|
|---|
| 3872 | if ( f->focusWidgets.findRef( this ) < 0 )
|
|---|
| 3873 | f->focusWidgets.append( this );
|
|---|
| 3874 | }
|
|---|
| 3875 | focus_policy = (uint) policy;
|
|---|
| 3876 | }
|
|---|
| 3877 |
|
|---|
| 3878 | /*!
|
|---|
| 3879 | \property QWidget::updatesEnabled
|
|---|
| 3880 | \brief whether updates are enabled
|
|---|
| 3881 |
|
|---|
| 3882 | Calling update() and repaint() has no effect if updates are
|
|---|
| 3883 | disabled. Paint events from the window system are processed
|
|---|
| 3884 | normally even if updates are disabled.
|
|---|
| 3885 |
|
|---|
| 3886 | setUpdatesEnabled() is normally used to disable updates for a
|
|---|
| 3887 | short period of time, for instance to avoid screen flicker during
|
|---|
| 3888 | large changes.
|
|---|
| 3889 |
|
|---|
| 3890 | Example:
|
|---|
| 3891 | \code
|
|---|
| 3892 | setUpdatesEnabled( FALSE );
|
|---|
| 3893 | bigVisualChanges();
|
|---|
| 3894 | setUpdatesEnabled( TRUE );
|
|---|
| 3895 | repaint();
|
|---|
| 3896 | \endcode
|
|---|
| 3897 |
|
|---|
| 3898 | \sa update(), repaint(), paintEvent()
|
|---|
| 3899 | */
|
|---|
| 3900 | void QWidget::setUpdatesEnabled( bool enable )
|
|---|
| 3901 | {
|
|---|
| 3902 | if ( enable )
|
|---|
| 3903 | clearWState( WState_BlockUpdates );
|
|---|
| 3904 | else
|
|---|
| 3905 | setWState( WState_BlockUpdates );
|
|---|
| 3906 | }
|
|---|
| 3907 |
|
|---|
| 3908 | /*!
|
|---|
| 3909 | Shows the widget and its child widgets.
|
|---|
| 3910 |
|
|---|
| 3911 | If its size or position has changed, Qt guarantees that a widget
|
|---|
| 3912 | gets move and resize events just before it is shown.
|
|---|
| 3913 |
|
|---|
| 3914 | You almost never have to reimplement this function. If you need to
|
|---|
| 3915 | change some settings before a widget is shown, use showEvent()
|
|---|
| 3916 | instead. If you need to do some delayed initialization use
|
|---|
| 3917 | polish().
|
|---|
| 3918 |
|
|---|
| 3919 | \sa showEvent(), hide(), showMinimized(), showMaximized(),
|
|---|
| 3920 | showNormal(), isVisible(), polish()
|
|---|
| 3921 | */
|
|---|
| 3922 |
|
|---|
| 3923 | void QWidget::show()
|
|---|
| 3924 | {
|
|---|
| 3925 | if ( testWState(WState_Visible) )
|
|---|
| 3926 | return;
|
|---|
| 3927 |
|
|---|
| 3928 | bool wasHidden = isHidden();
|
|---|
| 3929 | bool postLayoutHint = !isTopLevel() && wasHidden;
|
|---|
| 3930 | clearWState( WState_ForceHide | WState_CreatedHidden );
|
|---|
| 3931 |
|
|---|
| 3932 | if ( !isTopLevel() && !parentWidget()->isVisible() ) {
|
|---|
| 3933 | // we should become visible, but one of our ancestors is
|
|---|
| 3934 | // explicitly hidden. Since we cleared the ForceHide flag, our
|
|---|
| 3935 | // immediate parent will call show() on us again during its
|
|---|
| 3936 | // own processing of show().
|
|---|
| 3937 | if ( wasHidden ) {
|
|---|
| 3938 | QEvent showToParentEvent( QEvent::ShowToParent );
|
|---|
| 3939 | QApplication::sendEvent( this, &showToParentEvent );
|
|---|
| 3940 | }
|
|---|
| 3941 | if ( postLayoutHint )
|
|---|
| 3942 | QApplication::postEvent( parentWidget(),
|
|---|
| 3943 | new QEvent(QEvent::LayoutHint) );
|
|---|
| 3944 | return;
|
|---|
| 3945 | }
|
|---|
| 3946 |
|
|---|
| 3947 | in_show = TRUE; // set qws recursion watch
|
|---|
| 3948 |
|
|---|
| 3949 | QApplication::sendPostedEvents( this, QEvent::ChildInserted );
|
|---|
| 3950 |
|
|---|
| 3951 | if ( isTopLevel() && !testWState( WState_Resized ) ) {
|
|---|
| 3952 | // do this before sending the posted resize events. Otherwise
|
|---|
| 3953 | // the layout would catch the resize event and may expand the
|
|---|
| 3954 | // minimum size.
|
|---|
| 3955 | QSize s = qt_naturalWidgetSize( this );
|
|---|
| 3956 | bool wasMax = windowState() & WindowMaximized;
|
|---|
| 3957 | bool wasFullScreen = windowState() & WindowFullScreen;
|
|---|
| 3958 | if ( !s.isEmpty() )
|
|---|
| 3959 | resize( s );
|
|---|
| 3960 | if (wasMax)
|
|---|
| 3961 | setWindowState(windowState() | WindowMaximized);
|
|---|
| 3962 | if (wasFullScreen)
|
|---|
| 3963 | setWindowState(windowState() | WindowFullScreen);
|
|---|
| 3964 | #endif // Q_OS_TEMP
|
|---|
| 3965 | }
|
|---|
| 3966 |
|
|---|
| 3967 | QApplication::sendPostedEvents( this, QEvent::Move );
|
|---|
| 3968 | QApplication::sendPostedEvents( this, QEvent::Resize );
|
|---|
| 3969 |
|
|---|
| 3970 | setWState( WState_Visible );
|
|---|
| 3971 |
|
|---|
| 3972 | if ( parentWidget() )
|
|---|
| 3973 | QApplication::sendPostedEvents( parentWidget(),
|
|---|
| 3974 | QEvent::ChildInserted );
|
|---|
| 3975 |
|
|---|
| 3976 | if ( extra ) {
|
|---|
| 3977 | int w = crect.width();
|
|---|
| 3978 | int h = crect.height();
|
|---|
| 3979 | if ( w < extra->minw || h < extra->minh ||
|
|---|
| 3980 | w > extra->maxw || h > extra->maxh ) {
|
|---|
| 3981 | w = QMAX( extra->minw, QMIN( w, extra->maxw ));
|
|---|
| 3982 | h = QMAX( extra->minh, QMIN( h, extra->maxh ));
|
|---|
| 3983 | resize( w, h ); // deferred resize
|
|---|
| 3984 | }
|
|---|
| 3985 | }
|
|---|
| 3986 |
|
|---|
| 3987 | if ( testWFlags(WStyle_Tool) || isPopup() ) {
|
|---|
| 3988 | raise();
|
|---|
| 3989 | } else if ( testWFlags(WType_TopLevel) ) {
|
|---|
| 3990 | while ( QApplication::activePopupWidget() ) {
|
|---|
| 3991 | if ( !QApplication::activePopupWidget()->close() )
|
|---|
| 3992 | break;
|
|---|
| 3993 | }
|
|---|
| 3994 | }
|
|---|
| 3995 |
|
|---|
| 3996 | if ( !testWState(WState_Polished) )
|
|---|
| 3997 | polish();
|
|---|
| 3998 |
|
|---|
| 3999 | showChildren( FALSE );
|
|---|
| 4000 |
|
|---|
| 4001 | if ( postLayoutHint )
|
|---|
| 4002 | QApplication::postEvent( parentWidget(),
|
|---|
| 4003 | new QEvent(QEvent::LayoutHint) );
|
|---|
| 4004 |
|
|---|
| 4005 | // Required for Mac, not sure whether we should always do that
|
|---|
| 4006 | if( isTopLevel() )
|
|---|
| 4007 | QApplication::sendPostedEvents(0, QEvent::LayoutHint);
|
|---|
| 4008 |
|
|---|
| 4009 | // On Windows, show the popup now so that our own focus handling
|
|---|
| 4010 | // stores the correct old focus widget even if it's stolen in the showevent
|
|---|
| 4011 | //@@TODO (dmik): need the same in OS/2? guess not.
|
|---|
| 4012 | #if defined(Q_WS_WIN)
|
|---|
| 4013 | if ( testWFlags(WType_Popup) )
|
|---|
| 4014 | qApp->openPopup( this );
|
|---|
| 4015 | #endif
|
|---|
| 4016 |
|
|---|
| 4017 | QShowEvent showEvent;
|
|---|
| 4018 | QApplication::sendEvent( this, &showEvent );
|
|---|
| 4019 |
|
|---|
| 4020 | if ( testWFlags(WShowModal) ) {
|
|---|
| 4021 | // qt_enter_modal *before* show, otherwise the initial
|
|---|
| 4022 | // stacking might be wrong
|
|---|
| 4023 | qt_enter_modal( this );
|
|---|
| 4024 | }
|
|---|
| 4025 |
|
|---|
| 4026 | // do not show the window directly, but post a show-window request
|
|---|
| 4027 | // to reduce flicker with widgets in layouts
|
|---|
| 4028 | if ( postLayoutHint )
|
|---|
| 4029 | QApplication::postEvent( this, new QEvent( QEvent::ShowWindowRequest ) );
|
|---|
| 4030 | else
|
|---|
| 4031 | showWindow();
|
|---|
| 4032 |
|
|---|
| 4033 | //@@TODO (dmik): need the same in OS/2? guess not.
|
|---|
| 4034 | #if !defined(Q_WS_WIN)
|
|---|
| 4035 | if ( testWFlags(WType_Popup) )
|
|---|
| 4036 | qApp->openPopup( this );
|
|---|
| 4037 | #endif
|
|---|
| 4038 |
|
|---|
| 4039 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
|---|
| 4040 | QAccessible::updateAccessibility( this, 0, QAccessible::ObjectShow );
|
|---|
| 4041 | #endif
|
|---|
| 4042 |
|
|---|
| 4043 | in_show = FALSE; // reset qws recursion watch
|
|---|
| 4044 | }
|
|---|
| 4045 |
|
|---|
| 4046 | /*! \fn void QWidget::iconify()
|
|---|
| 4047 | \obsolete
|
|---|
| 4048 | */
|
|---|
| 4049 |
|
|---|
| 4050 | /*!
|
|---|
| 4051 | Hides the widget.
|
|---|
| 4052 |
|
|---|
| 4053 | You almost never have to reimplement this function. If you need to
|
|---|
| 4054 | do something after a widget is hidden, use hideEvent() instead.
|
|---|
| 4055 |
|
|---|
| 4056 | \sa hideEvent(), isHidden(), show(), showMinimized(), isVisible(), close()
|
|---|
| 4057 | */
|
|---|
| 4058 |
|
|---|
| 4059 | void QWidget::hide()
|
|---|
| 4060 | {
|
|---|
| 4061 | clearWState( WState_CreatedHidden );
|
|---|
| 4062 | if ( testWState(WState_ForceHide) )
|
|---|
| 4063 | return;
|
|---|
| 4064 |
|
|---|
| 4065 | setWState( WState_ForceHide );
|
|---|
| 4066 |
|
|---|
| 4067 | if ( testWFlags(WType_Popup) )
|
|---|
| 4068 | qApp->closePopup( this );
|
|---|
| 4069 |
|
|---|
| 4070 | // Move test modal here. Otherwise, a modal dialog could get
|
|---|
| 4071 | // destroyed and we lose all access to its parent because we haven't
|
|---|
| 4072 | // left modality. (Eg. modal Progress Dialog)
|
|---|
| 4073 | if ( testWFlags(WShowModal) )
|
|---|
| 4074 | qt_leave_modal( this );
|
|---|
| 4075 |
|
|---|
| 4076 | //@@TODO (dmik): is it correct for OS/2?
|
|---|
| 4077 | #if defined(Q_WS_WIN) || defined(Q_WS_PM)
|
|---|
| 4078 | if ( isTopLevel() && !isPopup() && parentWidget() && isActiveWindow() )
|
|---|
| 4079 | parentWidget()->setActiveWindow(); // Activate parent
|
|---|
| 4080 | #endif
|
|---|
| 4081 |
|
|---|
| 4082 | hideWindow();
|
|---|
| 4083 |
|
|---|
| 4084 | if ( testWState(WState_Visible) ) {
|
|---|
| 4085 | clearWState( WState_Visible );
|
|---|
| 4086 |
|
|---|
| 4087 | // next bit tries to move the focus if the focus widget is now
|
|---|
| 4088 | // hidden.
|
|---|
| 4089 | if ( qApp && qApp->focusWidget() == this )
|
|---|
| 4090 | focusNextPrevChild( TRUE );
|
|---|
| 4091 | QHideEvent hideEvent;
|
|---|
| 4092 | QApplication::sendEvent( this, &hideEvent );
|
|---|
| 4093 | hideChildren( FALSE );
|
|---|
| 4094 |
|
|---|
| 4095 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
|---|
| 4096 | QAccessible::updateAccessibility( this, 0, QAccessible::ObjectHide );
|
|---|
| 4097 | #endif
|
|---|
| 4098 | } else {
|
|---|
| 4099 | QEvent hideToParentEvent( QEvent::HideToParent );
|
|---|
| 4100 | QApplication::sendEvent( this, &hideToParentEvent );
|
|---|
| 4101 | }
|
|---|
| 4102 |
|
|---|
| 4103 | // post layout hint for non toplevels. The parent widget check is
|
|---|
| 4104 | // necessary since the function is called in the destructor
|
|---|
| 4105 | if ( !isTopLevel() && parentWidget() )
|
|---|
| 4106 | QApplication::postEvent( parentWidget(),
|
|---|
| 4107 | new QEvent( QEvent::LayoutHint) );
|
|---|
| 4108 | }
|
|---|
| 4109 |
|
|---|
| 4110 | void QWidget::setShown( bool show )
|
|---|
| 4111 | {
|
|---|
| 4112 | if ( show )
|
|---|
| 4113 | this->show();
|
|---|
| 4114 | else
|
|---|
| 4115 | hide();
|
|---|
| 4116 | }
|
|---|
| 4117 |
|
|---|
| 4118 | void QWidget::setHidden( bool hide )
|
|---|
| 4119 | {
|
|---|
| 4120 | if ( hide )
|
|---|
| 4121 | this->hide();
|
|---|
| 4122 | else
|
|---|
| 4123 | show();
|
|---|
| 4124 | }
|
|---|
| 4125 |
|
|---|
| 4126 | void QWidget::showChildren( bool spontaneous )
|
|---|
| 4127 | {
|
|---|
| 4128 | if ( children() ) {
|
|---|
| 4129 | QObjectListIt it(*children());
|
|---|
| 4130 | register QObject *object;
|
|---|
| 4131 | QWidget *widget;
|
|---|
| 4132 | while ( it ) {
|
|---|
| 4133 | object = it.current();
|
|---|
| 4134 | ++it;
|
|---|
| 4135 | if ( object->isWidgetType() ) {
|
|---|
| 4136 | widget = (QWidget*)object;
|
|---|
| 4137 | if ( !widget->isTopLevel() && widget->isShown() ) {
|
|---|
| 4138 | if ( spontaneous ) {
|
|---|
| 4139 | widget->showChildren( spontaneous );
|
|---|
| 4140 | QShowEvent e;
|
|---|
| 4141 | QApplication::sendSpontaneousEvent( widget, &e );
|
|---|
| 4142 | } else {
|
|---|
| 4143 | widget->show();
|
|---|
| 4144 | }
|
|---|
| 4145 | }
|
|---|
| 4146 | }
|
|---|
| 4147 | }
|
|---|
| 4148 | }
|
|---|
| 4149 | }
|
|---|
| 4150 |
|
|---|
| 4151 | void QWidget::hideChildren( bool spontaneous )
|
|---|
| 4152 | {
|
|---|
| 4153 | if ( children() ) {
|
|---|
| 4154 | QObjectListIt it(*children());
|
|---|
| 4155 | register QObject *object;
|
|---|
| 4156 | QWidget *widget;
|
|---|
| 4157 | while ( it ) {
|
|---|
| 4158 | object = it.current();
|
|---|
| 4159 | ++it;
|
|---|
| 4160 | if ( object->isWidgetType() ) {
|
|---|
| 4161 | widget = (QWidget*)object;
|
|---|
| 4162 | if ( !widget->isTopLevel() && widget->isShown() ) {
|
|---|
| 4163 | if ( !spontaneous )
|
|---|
| 4164 | widget->clearWState( WState_Visible );
|
|---|
| 4165 | widget->hideChildren( spontaneous );
|
|---|
| 4166 | QHideEvent e;
|
|---|
| 4167 | if ( spontaneous )
|
|---|
| 4168 | QApplication::sendSpontaneousEvent( widget, &e );
|
|---|
| 4169 | else
|
|---|
| 4170 | QApplication::sendEvent( widget, &e );
|
|---|
| 4171 | }
|
|---|
| 4172 | }
|
|---|
| 4173 | }
|
|---|
| 4174 | }
|
|---|
| 4175 | }
|
|---|
| 4176 |
|
|---|
| 4177 |
|
|---|
| 4178 | /*!
|
|---|
| 4179 | Delayed initialization of a widget.
|
|---|
| 4180 |
|
|---|
| 4181 | This function will be called \e after a widget has been fully
|
|---|
| 4182 | created and \e before it is shown the very first time.
|
|---|
| 4183 |
|
|---|
| 4184 | Polishing is useful for final initialization which depends on
|
|---|
| 4185 | having an instantiated widget. This is something a constructor
|
|---|
| 4186 | cannot guarantee since the initialization of the subclasses might
|
|---|
| 4187 | not be finished.
|
|---|
| 4188 |
|
|---|
| 4189 | After this function, the widget has a proper font and palette and
|
|---|
| 4190 | QApplication::polish() has been called.
|
|---|
| 4191 |
|
|---|
| 4192 | Remember to call QWidget's implementation first when reimplementing this
|
|---|
| 4193 | function to ensure that your program does not end up in infinite recursion.
|
|---|
| 4194 |
|
|---|
| 4195 | \sa constPolish(), QApplication::polish()
|
|---|
| 4196 | */
|
|---|
| 4197 |
|
|---|
| 4198 | void QWidget::polish()
|
|---|
| 4199 | {
|
|---|
| 4200 | #ifndef QT_NO_WIDGET_TOPEXTRA
|
|---|
| 4201 | if ( isTopLevel() ) {
|
|---|
| 4202 | const QPixmap *pm = icon();
|
|---|
| 4203 | if ( !pm || pm->isNull() ) {
|
|---|
| 4204 | QWidget *mw = (QWidget *)parent();
|
|---|
| 4205 | pm = mw ? mw->icon() : 0;
|
|---|
| 4206 | if ( pm && !pm->isNull() )
|
|---|
| 4207 | setIcon( *pm );
|
|---|
| 4208 | else {
|
|---|
| 4209 | mw = mw ? mw->topLevelWidget() : 0;
|
|---|
| 4210 | pm = mw ? mw->icon() : 0;
|
|---|
| 4211 | if ( pm && !pm->isNull() )
|
|---|
| 4212 | setIcon( *pm );
|
|---|
| 4213 | else {
|
|---|
| 4214 | mw = qApp ? qApp->mainWidget() : 0;
|
|---|
| 4215 | pm = mw ? mw->icon() : 0;
|
|---|
| 4216 | if ( pm && !pm->isNull() )
|
|---|
| 4217 | setIcon( *pm );
|
|---|
| 4218 | }
|
|---|
| 4219 | }
|
|---|
| 4220 | }
|
|---|
| 4221 | }
|
|---|
| 4222 | #endif
|
|---|
| 4223 | if ( !testWState(WState_Polished) ) {
|
|---|
| 4224 | if ( ! own_font &&
|
|---|
| 4225 | ! QApplication::font( this ).isCopyOf( QApplication::font() ) )
|
|---|
| 4226 | unsetFont();
|
|---|
| 4227 | #ifndef QT_NO_PALETTE
|
|---|
| 4228 | if ( ! own_palette &&
|
|---|
| 4229 | ! QApplication::palette( this ).isCopyOf( QApplication::palette() ) )
|
|---|
| 4230 | unsetPalette();
|
|---|
| 4231 | #endif
|
|---|
| 4232 | setWState(WState_Polished);
|
|---|
| 4233 | qApp->polish( this );
|
|---|
| 4234 | QApplication::sendPostedEvents( this, QEvent::ChildInserted );
|
|---|
| 4235 | }
|
|---|
| 4236 | }
|
|---|
| 4237 |
|
|---|
| 4238 |
|
|---|
| 4239 | /*!
|
|---|
| 4240 | \fn void QWidget::constPolish() const
|
|---|
| 4241 |
|
|---|
| 4242 | Ensures that the widget is properly initialized by calling
|
|---|
| 4243 | polish().
|
|---|
| 4244 |
|
|---|
| 4245 | Call constPolish() from functions like sizeHint() that depends on
|
|---|
| 4246 | the widget being initialized, and that may be called before
|
|---|
| 4247 | show().
|
|---|
| 4248 |
|
|---|
| 4249 | \warning Do not call constPolish() on a widget from inside that
|
|---|
| 4250 | widget's constructor.
|
|---|
| 4251 |
|
|---|
| 4252 | \sa polish()
|
|---|
| 4253 | */
|
|---|
| 4254 |
|
|---|
| 4255 | /*!
|
|---|
| 4256 | \overload
|
|---|
| 4257 |
|
|---|
| 4258 | Closes this widget. Returns TRUE if the widget was closed;
|
|---|
| 4259 | otherwise returns FALSE.
|
|---|
| 4260 |
|
|---|
| 4261 | If \a alsoDelete is TRUE or the widget has the \c
|
|---|
| 4262 | WDestructiveClose widget flag, the widget is also deleted. The
|
|---|
| 4263 | widget can prevent itself from being closed by rejecting the
|
|---|
| 4264 | \l QCloseEvent it gets. A close events is delivered to the widget
|
|---|
| 4265 | no matter if the widget is visible or not.
|
|---|
| 4266 |
|
|---|
| 4267 | The QApplication::lastWindowClosed() signal is emitted when the
|
|---|
| 4268 | last visible top level widget is closed.
|
|---|
| 4269 |
|
|---|
| 4270 | Note that closing the \l QApplication::mainWidget() terminates the
|
|---|
| 4271 | application.
|
|---|
| 4272 |
|
|---|
| 4273 | \sa closeEvent(), QCloseEvent, hide(), QApplication::quit(),
|
|---|
| 4274 | QApplication::setMainWidget(), QApplication::lastWindowClosed()
|
|---|
| 4275 | */
|
|---|
| 4276 |
|
|---|
| 4277 | bool QWidget::close( bool alsoDelete )
|
|---|
| 4278 | {
|
|---|
| 4279 | if ( is_closing )
|
|---|
| 4280 | return TRUE;
|
|---|
| 4281 | is_closing = 1;
|
|---|
| 4282 | WId id = winId();
|
|---|
| 4283 | bool isMain = qApp->mainWidget() == this;
|
|---|
| 4284 | bool checkLastWindowClosed = isTopLevel() && !isPopup();
|
|---|
| 4285 | bool deleted = FALSE;
|
|---|
| 4286 | QCloseEvent e;
|
|---|
| 4287 | QApplication::sendEvent( this, &e );
|
|---|
| 4288 | deleted = !QWidget::find(id);
|
|---|
| 4289 | if ( !deleted && !e.isAccepted() ) {
|
|---|
| 4290 | is_closing = 0;
|
|---|
| 4291 | return FALSE;
|
|---|
| 4292 | }
|
|---|
| 4293 | if ( !deleted && !isHidden() )
|
|---|
| 4294 | hide();
|
|---|
| 4295 | if ( checkLastWindowClosed
|
|---|
| 4296 | && qApp->receivers(SIGNAL(lastWindowClosed())) ) {
|
|---|
| 4297 | /* if there is no non-withdrawn top level window left (except
|
|---|
| 4298 | the desktop, popups, or dialogs with parents), we emit the
|
|---|
| 4299 | lastWindowClosed signal */
|
|---|
| 4300 | QWidgetList *list = qApp->topLevelWidgets();
|
|---|
| 4301 | QWidget *widget = list->first();
|
|---|
| 4302 | while ( widget ) {
|
|---|
| 4303 | if ( !widget->isHidden()
|
|---|
| 4304 | && !widget->isDesktop()
|
|---|
| 4305 | && !widget->isPopup()
|
|---|
| 4306 | && (!widget->isDialog() || !widget->parentWidget()))
|
|---|
| 4307 | break;
|
|---|
| 4308 | widget = list->next();
|
|---|
| 4309 | }
|
|---|
| 4310 | delete list;
|
|---|
| 4311 | if ( widget == 0 )
|
|---|
| 4312 | emit qApp->lastWindowClosed();
|
|---|
| 4313 | }
|
|---|
| 4314 | if ( isMain )
|
|---|
| 4315 | qApp->quit();
|
|---|
| 4316 | if ( deleted )
|
|---|
| 4317 | return TRUE;
|
|---|
| 4318 | is_closing = 0;
|
|---|
| 4319 | if ( alsoDelete )
|
|---|
| 4320 | delete this;
|
|---|
| 4321 | else if ( testWFlags(WDestructiveClose) ) {
|
|---|
| 4322 | clearWFlags(WDestructiveClose);
|
|---|
| 4323 | deleteLater();
|
|---|
| 4324 | }
|
|---|
| 4325 | return TRUE;
|
|---|
| 4326 | }
|
|---|
| 4327 |
|
|---|
| 4328 |
|
|---|
| 4329 | /*!
|
|---|
| 4330 | \fn bool QWidget::close()
|
|---|
| 4331 |
|
|---|
| 4332 | Closes this widget. Returns TRUE if the widget was closed;
|
|---|
| 4333 | otherwise returns FALSE.
|
|---|
| 4334 |
|
|---|
| 4335 | First it sends the widget a QCloseEvent. The widget is \link
|
|---|
| 4336 | hide() hidden\endlink if it \link QCloseEvent::accept()
|
|---|
| 4337 | accepts\endlink the close event. The default implementation of
|
|---|
| 4338 | QWidget::closeEvent() accepts the close event.
|
|---|
| 4339 |
|
|---|
| 4340 | The \l QApplication::lastWindowClosed() signal is emitted when the
|
|---|
| 4341 | last visible top level widget is closed.
|
|---|
| 4342 |
|
|---|
| 4343 | */
|
|---|
| 4344 |
|
|---|
| 4345 | /*!
|
|---|
| 4346 | \property QWidget::visible
|
|---|
| 4347 | \brief whether the widget is visible
|
|---|
| 4348 |
|
|---|
| 4349 | Calling show() sets the widget to visible status if all its parent
|
|---|
| 4350 | widgets up to the top-level widget are visible. If an ancestor is
|
|---|
| 4351 | not visible, the widget won't become visible until all its
|
|---|
| 4352 | ancestors are shown.
|
|---|
| 4353 |
|
|---|
| 4354 | Calling hide() hides a widget explicitly. An explicitly hidden
|
|---|
| 4355 | widget will never become visible, even if all its ancestors become
|
|---|
| 4356 | visible, unless you show it.
|
|---|
| 4357 |
|
|---|
| 4358 | A widget receives show and hide events when its visibility status
|
|---|
| 4359 | changes. Between a hide and a show event, there is no need to
|
|---|
| 4360 | waste CPU cycles preparing or displaying information to the user.
|
|---|
| 4361 | A video application, for example, might simply stop generating new
|
|---|
| 4362 | frames.
|
|---|
| 4363 |
|
|---|
| 4364 | A widget that happens to be obscured by other windows on the
|
|---|
| 4365 | screen is considered to be visible. The same applies to iconified
|
|---|
| 4366 | top-level widgets and windows that exist on another virtual
|
|---|
| 4367 | desktop (on platforms that support this concept). A widget
|
|---|
| 4368 | receives spontaneous show and hide events when its mapping status
|
|---|
| 4369 | is changed by the window system, e.g. a spontaneous hide event
|
|---|
| 4370 | when the user minimizes the window, and a spontaneous show event
|
|---|
| 4371 | when the window is restored again.
|
|---|
| 4372 |
|
|---|
| 4373 | \sa show(), hide(), isHidden(), isVisibleTo(), isMinimized(),
|
|---|
| 4374 | showEvent(), hideEvent()
|
|---|
| 4375 | */
|
|---|
| 4376 |
|
|---|
| 4377 |
|
|---|
| 4378 | /*!
|
|---|
| 4379 | Returns TRUE if this widget would become visible if \a ancestor is
|
|---|
| 4380 | shown; otherwise returns FALSE.
|
|---|
| 4381 |
|
|---|
| 4382 | The TRUE case occurs if neither the widget itself nor any parent
|
|---|
| 4383 | up to but excluding \a ancestor has been explicitly hidden.
|
|---|
| 4384 |
|
|---|
| 4385 | This function will still return TRUE if the widget is obscured by
|
|---|
| 4386 | other windows on the screen, but could be physically visible if it
|
|---|
| 4387 | or they were to be moved.
|
|---|
| 4388 |
|
|---|
| 4389 | isVisibleTo(0) is identical to isVisible().
|
|---|
| 4390 |
|
|---|
| 4391 | \sa show() hide() isVisible()
|
|---|
| 4392 | */
|
|---|
| 4393 |
|
|---|
| 4394 | bool QWidget::isVisibleTo(QWidget* ancestor) const
|
|---|
| 4395 | {
|
|---|
| 4396 | if ( !ancestor )
|
|---|
| 4397 | return isVisible();
|
|---|
| 4398 | const QWidget * w = this;
|
|---|
| 4399 | while ( w
|
|---|
| 4400 | && w->isShown()
|
|---|
| 4401 | && !w->isTopLevel()
|
|---|
| 4402 | && w->parentWidget()
|
|---|
| 4403 | && w->parentWidget() != ancestor )
|
|---|
| 4404 | w = w->parentWidget();
|
|---|
| 4405 | return w->isShown();
|
|---|
| 4406 | }
|
|---|
| 4407 |
|
|---|
| 4408 |
|
|---|
| 4409 | /*!
|
|---|
| 4410 | \fn bool QWidget::isVisibleToTLW() const
|
|---|
| 4411 | \obsolete
|
|---|
| 4412 |
|
|---|
| 4413 | This function is deprecated. It is equivalent to isVisible()
|
|---|
| 4414 | */
|
|---|
| 4415 |
|
|---|
| 4416 | /*!
|
|---|
| 4417 | \property QWidget::hidden
|
|---|
| 4418 | \brief whether the widget is explicitly hidden
|
|---|
| 4419 |
|
|---|
| 4420 | If FALSE, the widget is visible or would become visible if all its
|
|---|
| 4421 | ancestors became visible.
|
|---|
| 4422 |
|
|---|
| 4423 | \sa hide(), show(), isVisible(), isVisibleTo(), shown
|
|---|
| 4424 | */
|
|---|
| 4425 |
|
|---|
| 4426 | /*!
|
|---|
| 4427 | \property QWidget::shown
|
|---|
| 4428 | \brief whether the widget is shown
|
|---|
| 4429 |
|
|---|
| 4430 | If TRUE, the widget is visible or would become visible if all its
|
|---|
| 4431 | ancestors became visible.
|
|---|
| 4432 |
|
|---|
| 4433 | \sa hide(), show(), isVisible(), isVisibleTo(), hidden
|
|---|
| 4434 | */
|
|---|
| 4435 |
|
|---|
| 4436 | /*!
|
|---|
| 4437 | \property QWidget::visibleRect
|
|---|
| 4438 | \brief the visible rectangle
|
|---|
| 4439 |
|
|---|
| 4440 | \obsolete
|
|---|
| 4441 |
|
|---|
| 4442 | No longer necessary, you can simply call repaint(). If you do not
|
|---|
| 4443 | need the rectangle for repaint(), use clipRegion() instead.
|
|---|
| 4444 | */
|
|---|
| 4445 | QRect QWidget::visibleRect() const
|
|---|
| 4446 | {
|
|---|
| 4447 | QRect r = rect();
|
|---|
| 4448 | const QWidget * w = this;
|
|---|
| 4449 | int ox = 0;
|
|---|
| 4450 | int oy = 0;
|
|---|
| 4451 | while ( w
|
|---|
| 4452 | && w->isVisible()
|
|---|
| 4453 | && !w->isTopLevel()
|
|---|
| 4454 | && w->parentWidget() ) {
|
|---|
| 4455 | ox -= w->x();
|
|---|
| 4456 | oy -= w->y();
|
|---|
| 4457 | w = w->parentWidget();
|
|---|
| 4458 | r = r.intersect( QRect( ox, oy, w->width(), w->height() ) );
|
|---|
| 4459 | }
|
|---|
| 4460 | if ( !w->isVisible() )
|
|---|
| 4461 | return QRect();
|
|---|
| 4462 | return r;
|
|---|
| 4463 | }
|
|---|
| 4464 |
|
|---|
| 4465 | /*!
|
|---|
| 4466 | Returns the unobscured region where paint events can occur.
|
|---|
| 4467 |
|
|---|
| 4468 | For visible widgets, this is an approximation of the area not
|
|---|
| 4469 | covered by other widgets; otherwise, this is an empty region.
|
|---|
| 4470 |
|
|---|
| 4471 | The repaint() function calls this function if necessary, so in
|
|---|
| 4472 | general you do not need to call it.
|
|---|
| 4473 |
|
|---|
| 4474 | */
|
|---|
| 4475 | QRegion QWidget::clipRegion() const
|
|---|
| 4476 | {
|
|---|
| 4477 | return visibleRect();
|
|---|
| 4478 | }
|
|---|
| 4479 |
|
|---|
| 4480 |
|
|---|
| 4481 | /*!
|
|---|
| 4482 | Adjusts the size of the widget to fit the contents.
|
|---|
| 4483 |
|
|---|
| 4484 | Uses sizeHint() if valid (i.e if the size hint's width and height
|
|---|
| 4485 | are \>= 0), otherwise sets the size to the children rectangle (the
|
|---|
| 4486 | union of all child widget geometries).
|
|---|
| 4487 |
|
|---|
| 4488 | \sa sizeHint(), childrenRect()
|
|---|
| 4489 | */
|
|---|
| 4490 |
|
|---|
| 4491 | void QWidget::adjustSize()
|
|---|
| 4492 | {
|
|---|
| 4493 | QApplication::sendPostedEvents( 0, QEvent::ChildInserted );
|
|---|
| 4494 | QApplication::sendPostedEvents( 0, QEvent::LayoutHint );
|
|---|
| 4495 | if ( !testWState(WState_Polished) )
|
|---|
| 4496 | polish();
|
|---|
| 4497 | QSize s = sizeHint();
|
|---|
| 4498 |
|
|---|
| 4499 | if ( isTopLevel() ) {
|
|---|
| 4500 |
|
|---|
| 4501 | #if defined(Q_WS_X11)
|
|---|
| 4502 | QRect screen = QApplication::desktop()->screenGeometry( x11Screen() );
|
|---|
| 4503 | #else // all others
|
|---|
| 4504 | QRect screen = QApplication::desktop()->screenGeometry( pos() );
|
|---|
| 4505 | #endif
|
|---|
| 4506 |
|
|---|
| 4507 | #ifndef QT_NO_LAYOUT
|
|---|
| 4508 | if ( layout() ) {
|
|---|
| 4509 | if ( layout()->hasHeightForWidth() ) {
|
|---|
| 4510 | s = s.boundedTo( screen.size() );
|
|---|
| 4511 | s.setHeight( layout()->totalHeightForWidth( s.width() ) );
|
|---|
| 4512 | }
|
|---|
| 4513 | } else
|
|---|
| 4514 | #endif
|
|---|
| 4515 | {
|
|---|
| 4516 | if ( sizePolicy().hasHeightForWidth() ) {
|
|---|
| 4517 | s = s.boundedTo( screen.size() );
|
|---|
| 4518 | s.setHeight( heightForWidth( s.width() ) );
|
|---|
| 4519 | }
|
|---|
| 4520 | }
|
|---|
| 4521 | }
|
|---|
| 4522 | if ( s.isValid() ) {
|
|---|
| 4523 | resize( s );
|
|---|
| 4524 | return;
|
|---|
| 4525 | }
|
|---|
| 4526 | QRect r = childrenRect(); // get children rectangle
|
|---|
| 4527 | if ( r.isNull() ) // probably no widgets
|
|---|
| 4528 | return;
|
|---|
| 4529 | resize( r.width() + 2 * r.x(), r.height() + 2 * r.y() );
|
|---|
| 4530 | }
|
|---|
| 4531 |
|
|---|
| 4532 |
|
|---|
| 4533 | /*!
|
|---|
| 4534 | \property QWidget::sizeHint
|
|---|
| 4535 | \brief the recommended size for the widget
|
|---|
| 4536 |
|
|---|
| 4537 | If the value of this property is an invalid size, no size is
|
|---|
| 4538 | recommended.
|
|---|
| 4539 |
|
|---|
| 4540 | The default implementation of sizeHint() returns an invalid size
|
|---|
| 4541 | if there is no layout for this widget, and returns the layout's
|
|---|
| 4542 | preferred size otherwise.
|
|---|
| 4543 |
|
|---|
| 4544 | \sa QSize::isValid(), minimumSizeHint(), sizePolicy(),
|
|---|
| 4545 | setMinimumSize(), updateGeometry()
|
|---|
| 4546 | */
|
|---|
| 4547 |
|
|---|
| 4548 | QSize QWidget::sizeHint() const
|
|---|
| 4549 | {
|
|---|
| 4550 | #ifndef QT_NO_LAYOUT
|
|---|
| 4551 | if ( layout() )
|
|---|
| 4552 | return layout()->totalSizeHint();
|
|---|
| 4553 | #endif
|
|---|
| 4554 | return QSize( -1, -1 );
|
|---|
| 4555 | }
|
|---|
| 4556 |
|
|---|
| 4557 | /*!
|
|---|
| 4558 | \property QWidget::minimumSizeHint
|
|---|
| 4559 | \brief the recommended minimum size for the widget
|
|---|
| 4560 |
|
|---|
| 4561 | If the value of this property is an invalid size, no minimum size
|
|---|
| 4562 | is recommended.
|
|---|
| 4563 |
|
|---|
| 4564 | The default implementation of minimumSizeHint() returns an invalid
|
|---|
| 4565 | size if there is no layout for this widget, and returns the
|
|---|
| 4566 | layout's minimum size otherwise. Most built-in widgets reimplement
|
|---|
| 4567 | minimumSizeHint().
|
|---|
| 4568 |
|
|---|
| 4569 | \l QLayout will never resize a widget to a size smaller than
|
|---|
| 4570 | minimumSizeHint.
|
|---|
| 4571 |
|
|---|
| 4572 | \sa QSize::isValid(), resize(), setMinimumSize(), sizePolicy()
|
|---|
| 4573 | */
|
|---|
| 4574 | QSize QWidget::minimumSizeHint() const
|
|---|
| 4575 | {
|
|---|
| 4576 | #ifndef QT_NO_LAYOUT
|
|---|
| 4577 | if ( layout() )
|
|---|
| 4578 | return layout()->totalMinimumSize();
|
|---|
| 4579 | #endif
|
|---|
| 4580 | return QSize( -1, -1 );
|
|---|
| 4581 | }
|
|---|
| 4582 |
|
|---|
| 4583 |
|
|---|
| 4584 | /*!
|
|---|
| 4585 | \fn QWidget *QWidget::parentWidget( bool sameWindow ) const
|
|---|
| 4586 |
|
|---|
| 4587 | Returns the parent of this widget, or 0 if it does not have any
|
|---|
| 4588 | parent widget. If \a sameWindow is TRUE and the widget is top
|
|---|
| 4589 | level returns 0; otherwise returns the widget's parent.
|
|---|
| 4590 | */
|
|---|
| 4591 |
|
|---|
| 4592 | /*!
|
|---|
| 4593 | \fn WFlags QWidget::testWFlags( WFlags f ) const
|
|---|
| 4594 |
|
|---|
| 4595 | Returns the bitwise AND of the widget flags and \a f.
|
|---|
| 4596 |
|
|---|
| 4597 | Widget flags are a combination of \l{Qt::WidgetFlags}.
|
|---|
| 4598 |
|
|---|
| 4599 | If you want to test for the presence of multiple flags (or
|
|---|
| 4600 | composite flags such as \c WStyle_Splash), test the
|
|---|
| 4601 | return value for equality against the argument. For example:
|
|---|
| 4602 |
|
|---|
| 4603 | \code
|
|---|
| 4604 | int flags = WStyle_Tool | WStyle_NoBorder;
|
|---|
| 4605 | if ( testWFlags(flags) )
|
|---|
| 4606 | ... // WStyle_Tool or WStyle_NoBorder or both are set
|
|---|
| 4607 | if ( testWFlags(flags) == flags )
|
|---|
| 4608 | ... // both WStyle_Tool and WStyle_NoBorder are set
|
|---|
| 4609 | \endcode
|
|---|
| 4610 |
|
|---|
| 4611 | \sa getWFlags(), setWFlags(), clearWFlags()
|
|---|
| 4612 | */
|
|---|
| 4613 |
|
|---|
| 4614 | /*!
|
|---|
| 4615 | \fn WState QWidget::testWState( WState s ) const
|
|---|
| 4616 | \internal
|
|---|
| 4617 |
|
|---|
| 4618 | Returns the bitwise AND of the widget states and \a s.
|
|---|
| 4619 | */
|
|---|
| 4620 |
|
|---|
| 4621 | /*!
|
|---|
| 4622 | \fn uint QWidget::getWState() const
|
|---|
| 4623 |
|
|---|
| 4624 | \internal
|
|---|
| 4625 |
|
|---|
| 4626 | Returns the current widget state.
|
|---|
| 4627 | */
|
|---|
| 4628 | /*!
|
|---|
| 4629 | \fn void QWidget::clearWState( uint n )
|
|---|
| 4630 |
|
|---|
| 4631 | \internal
|
|---|
| 4632 |
|
|---|
| 4633 | Clears the widgets states \a n.
|
|---|
| 4634 | */
|
|---|
| 4635 | /*!
|
|---|
| 4636 | \fn void QWidget::setWState( uint n )
|
|---|
| 4637 |
|
|---|
| 4638 | \internal
|
|---|
| 4639 |
|
|---|
| 4640 | Sets the widgets states \a n.
|
|---|
| 4641 | */
|
|---|
| 4642 |
|
|---|
| 4643 |
|
|---|
| 4644 |
|
|---|
| 4645 | /*****************************************************************************
|
|---|
| 4646 | QWidget event handling
|
|---|
| 4647 | *****************************************************************************/
|
|---|
| 4648 |
|
|---|
| 4649 | /*!
|
|---|
| 4650 | This is the main event handler; it handles event \a e. You can
|
|---|
| 4651 | reimplement this function in a subclass, but we recommend using
|
|---|
| 4652 | one of the specialized event handlers instead.
|
|---|
| 4653 |
|
|---|
| 4654 | The main event handler first passes an event through all \link
|
|---|
| 4655 | QObject::installEventFilter() event filters\endlink that have been
|
|---|
| 4656 | installed. If none of the filters intercept the event, it calls
|
|---|
| 4657 | one of the specialized event handlers.
|
|---|
| 4658 |
|
|---|
| 4659 | Key press and release events are treated differently from other
|
|---|
| 4660 | events. event() checks for Tab and Shift+Tab and tries to move the
|
|---|
| 4661 | focus appropriately. If there is no widget to move the focus to
|
|---|
| 4662 | (or the key press is not Tab or Shift+Tab), event() calls
|
|---|
| 4663 | keyPressEvent().
|
|---|
| 4664 |
|
|---|
| 4665 | This function returns TRUE if it is able to pass the event over to
|
|---|
| 4666 | someone (i.e. someone wanted the event); otherwise returns FALSE.
|
|---|
| 4667 |
|
|---|
| 4668 | \sa closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(),
|
|---|
| 4669 | keyPressEvent(), keyReleaseEvent(), leaveEvent(),
|
|---|
| 4670 | mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(),
|
|---|
| 4671 | mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(),
|
|---|
| 4672 | QObject::event(), QObject::timerEvent()
|
|---|
| 4673 | */
|
|---|
| 4674 |
|
|---|
| 4675 | bool QWidget::event( QEvent *e )
|
|---|
| 4676 | {
|
|---|
| 4677 | if ( QObject::event( e ) )
|
|---|
| 4678 | return TRUE;
|
|---|
| 4679 |
|
|---|
| 4680 | switch ( e->type() ) {
|
|---|
| 4681 | case QEvent::MouseMove:
|
|---|
| 4682 | mouseMoveEvent( (QMouseEvent*)e );
|
|---|
| 4683 | if ( ! ((QMouseEvent*)e)->isAccepted() )
|
|---|
| 4684 | return FALSE;
|
|---|
| 4685 | break;
|
|---|
| 4686 |
|
|---|
| 4687 | case QEvent::MouseButtonPress:
|
|---|
| 4688 | resetInputContext();
|
|---|
| 4689 | mousePressEvent( (QMouseEvent*)e );
|
|---|
| 4690 | if ( ! ((QMouseEvent*)e)->isAccepted() )
|
|---|
| 4691 | return FALSE;
|
|---|
| 4692 | break;
|
|---|
| 4693 |
|
|---|
| 4694 | case QEvent::MouseButtonRelease:
|
|---|
| 4695 | mouseReleaseEvent( (QMouseEvent*)e );
|
|---|
| 4696 | if ( ! ((QMouseEvent*)e)->isAccepted() )
|
|---|
| 4697 | return FALSE;
|
|---|
| 4698 | break;
|
|---|
| 4699 |
|
|---|
| 4700 | case QEvent::MouseButtonDblClick:
|
|---|
| 4701 | mouseDoubleClickEvent( (QMouseEvent*)e );
|
|---|
| 4702 | if ( ! ((QMouseEvent*)e)->isAccepted() )
|
|---|
| 4703 | return FALSE;
|
|---|
| 4704 | break;
|
|---|
| 4705 | #ifndef QT_NO_WHEELEVENT
|
|---|
| 4706 | case QEvent::Wheel:
|
|---|
| 4707 | wheelEvent( (QWheelEvent*)e );
|
|---|
| 4708 | if ( ! ((QWheelEvent*)e)->isAccepted() )
|
|---|
| 4709 | return FALSE;
|
|---|
| 4710 | break;
|
|---|
| 4711 | #endif
|
|---|
| 4712 | case QEvent::TabletMove:
|
|---|
| 4713 | case QEvent::TabletPress:
|
|---|
| 4714 | case QEvent::TabletRelease:
|
|---|
| 4715 | tabletEvent( (QTabletEvent*)e );
|
|---|
| 4716 | if ( ! ((QTabletEvent*)e)->isAccepted() )
|
|---|
| 4717 | return FALSE;
|
|---|
| 4718 | break;
|
|---|
| 4719 | case QEvent::Accel:
|
|---|
| 4720 | ((QKeyEvent*)e)->ignore();
|
|---|
| 4721 | return FALSE;
|
|---|
| 4722 | case QEvent::KeyPress: {
|
|---|
| 4723 | QKeyEvent *k = (QKeyEvent *)e;
|
|---|
| 4724 | bool res = FALSE;
|
|---|
| 4725 | if ( !(k->state() & ControlButton || k->state() & AltButton) ) {
|
|---|
| 4726 | if ( k->key() == Key_Backtab ||
|
|---|
| 4727 | (k->key() == Key_Tab &&
|
|---|
| 4728 | (k->state() & ShiftButton)) ) {
|
|---|
| 4729 | QFocusEvent::setReason( QFocusEvent::Backtab );
|
|---|
| 4730 | res = focusNextPrevChild( FALSE );
|
|---|
| 4731 | QFocusEvent::resetReason();
|
|---|
| 4732 |
|
|---|
| 4733 | } else if ( k->key() == Key_Tab ) {
|
|---|
| 4734 | QFocusEvent::setReason( QFocusEvent::Tab );
|
|---|
| 4735 | res = focusNextPrevChild( TRUE );
|
|---|
| 4736 | QFocusEvent::resetReason();
|
|---|
| 4737 | }
|
|---|
| 4738 | if ( res )
|
|---|
| 4739 | break;
|
|---|
| 4740 | }
|
|---|
| 4741 | keyPressEvent( k );
|
|---|
| 4742 | if ( !k->isAccepted() )
|
|---|
| 4743 | return FALSE;
|
|---|
| 4744 | }
|
|---|
| 4745 | break;
|
|---|
| 4746 |
|
|---|
| 4747 | case QEvent::KeyRelease:
|
|---|
| 4748 | keyReleaseEvent( (QKeyEvent*)e );
|
|---|
| 4749 | if ( ! ((QKeyEvent*)e)->isAccepted() )
|
|---|
| 4750 | return FALSE;
|
|---|
| 4751 | break;
|
|---|
| 4752 |
|
|---|
| 4753 | case QEvent::IMStart: {
|
|---|
| 4754 | QIMEvent *i = (QIMEvent *) e;
|
|---|
| 4755 | imStartEvent(i);
|
|---|
| 4756 | if (! i->isAccepted())
|
|---|
| 4757 | return FALSE;
|
|---|
| 4758 | }
|
|---|
| 4759 | break;
|
|---|
| 4760 |
|
|---|
| 4761 | case QEvent::IMCompose: {
|
|---|
| 4762 | QIMEvent *i = (QIMEvent *) e;
|
|---|
| 4763 | imComposeEvent(i);
|
|---|
| 4764 | if (! i->isAccepted())
|
|---|
| 4765 | return FALSE;
|
|---|
| 4766 | }
|
|---|
| 4767 | break;
|
|---|
| 4768 |
|
|---|
| 4769 | case QEvent::IMEnd: {
|
|---|
| 4770 | QIMEvent *i = (QIMEvent *) e;
|
|---|
| 4771 | imEndEvent(i);
|
|---|
| 4772 | if (! i->isAccepted())
|
|---|
| 4773 | return FALSE;
|
|---|
| 4774 | }
|
|---|
| 4775 | break;
|
|---|
| 4776 |
|
|---|
| 4777 | case QEvent::FocusIn:
|
|---|
| 4778 | focusInEvent( (QFocusEvent*)e );
|
|---|
| 4779 | setFontSys();
|
|---|
| 4780 | break;
|
|---|
| 4781 |
|
|---|
| 4782 | case QEvent::FocusOut:
|
|---|
| 4783 | focusOutEvent( (QFocusEvent*)e );
|
|---|
| 4784 | break;
|
|---|
| 4785 |
|
|---|
| 4786 | case QEvent::Enter:
|
|---|
| 4787 | enterEvent( e );
|
|---|
| 4788 | break;
|
|---|
| 4789 |
|
|---|
| 4790 | case QEvent::Leave:
|
|---|
| 4791 | leaveEvent( e );
|
|---|
| 4792 | break;
|
|---|
| 4793 |
|
|---|
| 4794 | case QEvent::Paint:
|
|---|
| 4795 | // At this point the event has to be delivered, regardless
|
|---|
| 4796 | // whether the widget isVisible() or not because it
|
|---|
| 4797 | // already went through the filters
|
|---|
| 4798 | paintEvent( (QPaintEvent*)e );
|
|---|
| 4799 | break;
|
|---|
| 4800 |
|
|---|
| 4801 | case QEvent::Move:
|
|---|
| 4802 | moveEvent( (QMoveEvent*)e );
|
|---|
| 4803 | break;
|
|---|
| 4804 |
|
|---|
| 4805 | case QEvent::Resize:
|
|---|
| 4806 | resizeEvent( (QResizeEvent*)e );
|
|---|
| 4807 | break;
|
|---|
| 4808 |
|
|---|
| 4809 | case QEvent::Close: {
|
|---|
| 4810 | QCloseEvent *c = (QCloseEvent *)e;
|
|---|
| 4811 | closeEvent( c );
|
|---|
| 4812 | if ( !c->isAccepted() )
|
|---|
| 4813 | return FALSE;
|
|---|
| 4814 | }
|
|---|
| 4815 | break;
|
|---|
| 4816 |
|
|---|
| 4817 | case QEvent::ContextMenu: {
|
|---|
| 4818 | QContextMenuEvent *c = (QContextMenuEvent *)e;
|
|---|
| 4819 | contextMenuEvent( c );
|
|---|
| 4820 | if ( !c->isAccepted() )
|
|---|
| 4821 | return FALSE;
|
|---|
| 4822 | }
|
|---|
| 4823 | break;
|
|---|
| 4824 |
|
|---|
| 4825 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 4826 | case QEvent::Drop:
|
|---|
| 4827 | dropEvent( (QDropEvent*) e);
|
|---|
| 4828 | break;
|
|---|
| 4829 |
|
|---|
| 4830 | case QEvent::DragEnter:
|
|---|
| 4831 | dragEnterEvent( (QDragEnterEvent*) e);
|
|---|
| 4832 | break;
|
|---|
| 4833 |
|
|---|
| 4834 | case QEvent::DragMove:
|
|---|
| 4835 | dragMoveEvent( (QDragMoveEvent*) e);
|
|---|
| 4836 | break;
|
|---|
| 4837 |
|
|---|
| 4838 | case QEvent::DragLeave:
|
|---|
| 4839 | dragLeaveEvent( (QDragLeaveEvent*) e);
|
|---|
| 4840 | break;
|
|---|
| 4841 | #endif
|
|---|
| 4842 |
|
|---|
| 4843 | case QEvent::Show:
|
|---|
| 4844 | showEvent( (QShowEvent*) e);
|
|---|
| 4845 | break;
|
|---|
| 4846 |
|
|---|
| 4847 | case QEvent::Hide:
|
|---|
| 4848 | hideEvent( (QHideEvent*) e);
|
|---|
| 4849 | break;
|
|---|
| 4850 |
|
|---|
| 4851 | case QEvent::ShowWindowRequest:
|
|---|
| 4852 | if ( isShown() )
|
|---|
| 4853 | showWindow();
|
|---|
| 4854 | break;
|
|---|
| 4855 |
|
|---|
| 4856 | case QEvent::ParentFontChange:
|
|---|
| 4857 | if ( isTopLevel() )
|
|---|
| 4858 | break;
|
|---|
| 4859 | // fall through
|
|---|
| 4860 | case QEvent::ApplicationFontChange:
|
|---|
| 4861 | if ( own_font )
|
|---|
| 4862 | setFont( fnt.resolve( qt_naturalWidgetFont( this ) ) );
|
|---|
| 4863 | else
|
|---|
| 4864 | unsetFont();
|
|---|
| 4865 | break;
|
|---|
| 4866 |
|
|---|
| 4867 | #ifndef QT_NO_PALETTE
|
|---|
| 4868 | case QEvent::ParentPaletteChange:
|
|---|
| 4869 | if ( isTopLevel() )
|
|---|
| 4870 | break;
|
|---|
| 4871 | // fall through
|
|---|
| 4872 | case QEvent::ApplicationPaletteChange:
|
|---|
| 4873 | if ( !own_palette && !isDesktop() )
|
|---|
| 4874 | unsetPalette();
|
|---|
| 4875 | # if defined(Q_WS_QWS) && !defined (QT_NO_QWS_MANAGER)
|
|---|
| 4876 | if ( isTopLevel() && topData()->qwsManager ) {
|
|---|
| 4877 | QRegion r( topData()->qwsManager->region() );
|
|---|
| 4878 | QApplication::postEvent(topData()->qwsManager, new QPaintEvent(r, FALSE) );
|
|---|
| 4879 | }
|
|---|
| 4880 | # endif
|
|---|
| 4881 | break;
|
|---|
| 4882 | #endif
|
|---|
| 4883 |
|
|---|
| 4884 | case QEvent::WindowActivate:
|
|---|
| 4885 | case QEvent::WindowDeactivate:
|
|---|
| 4886 | windowActivationChange( e->type() != QEvent::WindowActivate );
|
|---|
| 4887 | if ( children() ) {
|
|---|
| 4888 | QObjectListIt it( *children() );
|
|---|
| 4889 | QObject *o;
|
|---|
| 4890 | while( ( o = it.current() ) != 0 ) {
|
|---|
| 4891 | ++it;
|
|---|
| 4892 | if ( o->isWidgetType() &&
|
|---|
| 4893 | ((QWidget*)o)->isVisible() &&
|
|---|
| 4894 | !((QWidget*)o)->isTopLevel() )
|
|---|
| 4895 | QApplication::sendEvent( o, e );
|
|---|
| 4896 | }
|
|---|
| 4897 | }
|
|---|
| 4898 | break;
|
|---|
| 4899 |
|
|---|
| 4900 | case QEvent::LanguageChange:
|
|---|
| 4901 | case QEvent::LocaleChange:
|
|---|
| 4902 | if ( children() ) {
|
|---|
| 4903 | QObjectListIt it( *children() );
|
|---|
| 4904 | QObject *o;
|
|---|
| 4905 | while( ( o = it.current() ) != 0 ) {
|
|---|
| 4906 | ++it;
|
|---|
| 4907 | QApplication::sendEvent( o, e );
|
|---|
| 4908 | }
|
|---|
| 4909 | }
|
|---|
| 4910 | if ( e->type() == QEvent::LanguageChange ) {
|
|---|
| 4911 | int index = metaObject()->findSlot( "languageChange()", TRUE );
|
|---|
| 4912 | if ( index >= 0 )
|
|---|
| 4913 | qt_invoke( index, 0 );
|
|---|
| 4914 | }
|
|---|
| 4915 | update();
|
|---|
| 4916 | break;
|
|---|
| 4917 | #ifndef QT_NO_LAYOUT
|
|---|
| 4918 | case QEvent::LayoutDirectionChange:
|
|---|
| 4919 | if ( layout() ) {
|
|---|
| 4920 | layout()->activate();
|
|---|
| 4921 | } else {
|
|---|
| 4922 | QObjectList* llist = queryList( "QLayout", 0, TRUE, TRUE );
|
|---|
| 4923 | QObjectListIt lit( *llist );
|
|---|
| 4924 | QLayout *lay;
|
|---|
| 4925 | while ( ( lay = (QLayout*)lit.current() ) != 0 ) {
|
|---|
| 4926 | ++lit;
|
|---|
| 4927 | lay->activate();
|
|---|
| 4928 | }
|
|---|
| 4929 | delete llist;
|
|---|
| 4930 | }
|
|---|
| 4931 | update();
|
|---|
| 4932 | break;
|
|---|
| 4933 | #endif
|
|---|
| 4934 |
|
|---|
| 4935 | case QEvent::WindowStateChange:
|
|---|
| 4936 | {
|
|---|
| 4937 | QEvent::Type type;
|
|---|
| 4938 | if (isMinimized())
|
|---|
| 4939 | type = QEvent::ShowMinimized;
|
|---|
| 4940 | else if (isFullScreen())
|
|---|
| 4941 | type = QEvent::ShowFullScreen;
|
|---|
| 4942 | else if (isMaximized())
|
|---|
| 4943 | type = QEvent::ShowMaximized;
|
|---|
| 4944 | else
|
|---|
| 4945 | type = QEvent::ShowNormal;
|
|---|
| 4946 |
|
|---|
| 4947 | if (e->spontaneous()) {
|
|---|
| 4948 | QEvent e2(type);
|
|---|
| 4949 | QApplication::sendEvent(this, &e2);
|
|---|
| 4950 | } else {
|
|---|
| 4951 | QApplication::postEvent(this, new QEvent(type));
|
|---|
| 4952 | }
|
|---|
| 4953 | break;
|
|---|
| 4954 | }
|
|---|
| 4955 |
|
|---|
| 4956 | #ifndef Q_WS_PM
|
|---|
| 4957 | // We disable this on OS/2 since we send these events from qt_sendBlocked()
|
|---|
| 4958 | // which does it more accurately compared to the code below -- only those
|
|---|
| 4959 | // widgets that have actually been blocked/unblocked (not less and not
|
|---|
| 4960 | // more) will receive these events.
|
|---|
| 4961 | case QEvent::WindowBlocked:
|
|---|
| 4962 | case QEvent::WindowUnblocked:
|
|---|
| 4963 | if ( children() ) {
|
|---|
| 4964 | QObjectListIt it( *children() );
|
|---|
| 4965 | QObject *o;
|
|---|
| 4966 | while( ( o = it.current() ) != 0 ) {
|
|---|
| 4967 | ++it;
|
|---|
| 4968 | QApplication::sendEvent( o, e );
|
|---|
| 4969 | }
|
|---|
| 4970 | }
|
|---|
| 4971 | break;
|
|---|
| 4972 | #endif
|
|---|
| 4973 |
|
|---|
| 4974 | default:
|
|---|
| 4975 | return FALSE;
|
|---|
| 4976 | }
|
|---|
| 4977 | return TRUE;
|
|---|
| 4978 | }
|
|---|
| 4979 |
|
|---|
| 4980 | /*!
|
|---|
| 4981 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 4982 | subclass to receive mouse move events for the widget.
|
|---|
| 4983 |
|
|---|
| 4984 | If mouse tracking is switched off, mouse move events only occur if
|
|---|
| 4985 | a mouse button is pressed while the mouse is being moved. If mouse
|
|---|
| 4986 | tracking is switched on, mouse move events occur even if no mouse
|
|---|
| 4987 | button is pressed.
|
|---|
| 4988 |
|
|---|
| 4989 | QMouseEvent::pos() reports the position of the mouse cursor,
|
|---|
| 4990 | relative to this widget. For press and release events, the
|
|---|
| 4991 | position is usually the same as the position of the last mouse
|
|---|
| 4992 | move event, but it might be different if the user's hand shakes.
|
|---|
| 4993 | This is a feature of the underlying window system, not Qt.
|
|---|
| 4994 |
|
|---|
| 4995 | \sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(),
|
|---|
| 4996 | mouseDoubleClickEvent(), event(), QMouseEvent
|
|---|
| 4997 | */
|
|---|
| 4998 |
|
|---|
| 4999 | void QWidget::mouseMoveEvent( QMouseEvent * e)
|
|---|
| 5000 | {
|
|---|
| 5001 | e->ignore();
|
|---|
| 5002 | }
|
|---|
| 5003 |
|
|---|
| 5004 | /*!
|
|---|
| 5005 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 5006 | subclass to receive mouse press events for the widget.
|
|---|
| 5007 |
|
|---|
| 5008 | If you create new widgets in the mousePressEvent() the
|
|---|
| 5009 | mouseReleaseEvent() may not end up where you expect, depending on
|
|---|
| 5010 | the underlying window system (or X11 window manager), the widgets'
|
|---|
| 5011 | location and maybe more.
|
|---|
| 5012 |
|
|---|
| 5013 | The default implementation implements the closing of popup widgets
|
|---|
| 5014 | when you click outside the window. For other widget types it does
|
|---|
| 5015 | nothing.
|
|---|
| 5016 |
|
|---|
| 5017 | \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
|
|---|
| 5018 | mouseMoveEvent(), event(), QMouseEvent
|
|---|
| 5019 | */
|
|---|
| 5020 |
|
|---|
| 5021 | void QWidget::mousePressEvent( QMouseEvent *e )
|
|---|
| 5022 | {
|
|---|
| 5023 | e->ignore();
|
|---|
| 5024 | if ( isPopup() ) {
|
|---|
| 5025 | e->accept();
|
|---|
| 5026 | QWidget* w;
|
|---|
| 5027 | while ( (w = qApp->activePopupWidget() ) && w != this ){
|
|---|
| 5028 | w->close();
|
|---|
| 5029 | if (qApp->activePopupWidget() == w) // widget does not want to dissappear
|
|---|
| 5030 | w->hide(); // hide at least
|
|---|
| 5031 | }
|
|---|
| 5032 | if (!rect().contains(e->pos()) ){
|
|---|
| 5033 | close();
|
|---|
| 5034 | }
|
|---|
| 5035 | }
|
|---|
| 5036 | }
|
|---|
| 5037 |
|
|---|
| 5038 | /*!
|
|---|
| 5039 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 5040 | subclass to receive mouse release events for the widget.
|
|---|
| 5041 |
|
|---|
| 5042 | \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
|
|---|
| 5043 | mouseMoveEvent(), event(), QMouseEvent
|
|---|
| 5044 | */
|
|---|
| 5045 |
|
|---|
| 5046 | void QWidget::mouseReleaseEvent( QMouseEvent * e )
|
|---|
| 5047 | {
|
|---|
| 5048 | e->ignore();
|
|---|
| 5049 | }
|
|---|
| 5050 |
|
|---|
| 5051 | /*!
|
|---|
| 5052 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 5053 | subclass to receive mouse double click events for the widget.
|
|---|
| 5054 |
|
|---|
| 5055 | The default implementation generates a normal mouse press event.
|
|---|
| 5056 |
|
|---|
| 5057 | Note that the widgets gets a mousePressEvent() and a
|
|---|
| 5058 | mouseReleaseEvent() before the mouseDoubleClickEvent().
|
|---|
| 5059 |
|
|---|
| 5060 | \sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
|
|---|
| 5061 | event(), QMouseEvent
|
|---|
| 5062 | */
|
|---|
| 5063 |
|
|---|
| 5064 | void QWidget::mouseDoubleClickEvent( QMouseEvent *e )
|
|---|
| 5065 | {
|
|---|
| 5066 | mousePressEvent( e ); // try mouse press event
|
|---|
| 5067 | }
|
|---|
| 5068 |
|
|---|
| 5069 | #ifndef QT_NO_WHEELEVENT
|
|---|
| 5070 | /*!
|
|---|
| 5071 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 5072 | subclass to receive wheel events for the widget.
|
|---|
| 5073 |
|
|---|
| 5074 | If you reimplement this handler, it is very important that you
|
|---|
| 5075 | \link QWheelEvent ignore()\endlink the event if you do not handle
|
|---|
| 5076 | it, so that the widget's parent can interpret it.
|
|---|
| 5077 |
|
|---|
| 5078 | The default implementation ignores the event.
|
|---|
| 5079 |
|
|---|
| 5080 | \sa QWheelEvent::ignore(), QWheelEvent::accept(), event(),
|
|---|
| 5081 | QWheelEvent
|
|---|
| 5082 | */
|
|---|
| 5083 |
|
|---|
| 5084 | void QWidget::wheelEvent( QWheelEvent *e )
|
|---|
| 5085 | {
|
|---|
| 5086 | e->ignore();
|
|---|
| 5087 | }
|
|---|
| 5088 | #endif
|
|---|
| 5089 |
|
|---|
| 5090 | /*!
|
|---|
| 5091 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 5092 | subclass to receive tablet events for the widget.
|
|---|
| 5093 |
|
|---|
| 5094 | If you reimplement this handler, it is very important that you
|
|---|
| 5095 | \link QTabletEvent ignore()\endlink the event if you do not handle
|
|---|
| 5096 | it, so that the widget's parent can interpret it.
|
|---|
| 5097 |
|
|---|
| 5098 | The default implementation ignores the event.
|
|---|
| 5099 |
|
|---|
| 5100 | \sa QTabletEvent::ignore(), QTabletEvent::accept(), event(),
|
|---|
| 5101 | QTabletEvent
|
|---|
| 5102 | */
|
|---|
| 5103 |
|
|---|
| 5104 | void QWidget::tabletEvent( QTabletEvent *e )
|
|---|
| 5105 | {
|
|---|
| 5106 | e->ignore();
|
|---|
| 5107 | }
|
|---|
| 5108 |
|
|---|
| 5109 | /*!
|
|---|
| 5110 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 5111 | subclass to receive key press events for the widget.
|
|---|
| 5112 |
|
|---|
| 5113 | A widget must call setFocusPolicy() to accept focus initially and
|
|---|
| 5114 | have focus in order to receive a key press event.
|
|---|
| 5115 |
|
|---|
| 5116 | If you reimplement this handler, it is very important that you
|
|---|
| 5117 | \link QKeyEvent ignore()\endlink the event if you do not
|
|---|
| 5118 | understand it, so that the widget's parent can interpret it.
|
|---|
| 5119 |
|
|---|
| 5120 | The default implementation closes popup widgets if the user
|
|---|
| 5121 | presses Esc. Otherwise the event is ignored.
|
|---|
| 5122 |
|
|---|
| 5123 | \sa keyReleaseEvent(), QKeyEvent::ignore(), setFocusPolicy(),
|
|---|
| 5124 | focusInEvent(), focusOutEvent(), event(), QKeyEvent
|
|---|
| 5125 | */
|
|---|
| 5126 |
|
|---|
| 5127 | void QWidget::keyPressEvent( QKeyEvent *e )
|
|---|
| 5128 | {
|
|---|
| 5129 | if ( isPopup() && e->key() == Key_Escape ) {
|
|---|
| 5130 | e->accept();
|
|---|
| 5131 | close();
|
|---|
| 5132 | } else {
|
|---|
| 5133 | e->ignore();
|
|---|
| 5134 | }
|
|---|
| 5135 | }
|
|---|
| 5136 |
|
|---|
| 5137 | /*!
|
|---|
| 5138 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 5139 | subclass to receive key release events for the widget.
|
|---|
| 5140 |
|
|---|
| 5141 | A widget must \link setFocusPolicy() accept focus\endlink
|
|---|
| 5142 | initially and \link hasFocus() have focus\endlink in order to
|
|---|
| 5143 | receive a key release event.
|
|---|
| 5144 |
|
|---|
| 5145 | If you reimplement this handler, it is very important that you
|
|---|
| 5146 | \link QKeyEvent ignore()\endlink the release if you do not
|
|---|
| 5147 | understand it, so that the widget's parent can interpret it.
|
|---|
| 5148 |
|
|---|
| 5149 | The default implementation ignores the event.
|
|---|
| 5150 |
|
|---|
| 5151 | \sa keyPressEvent(), QKeyEvent::ignore(), setFocusPolicy(),
|
|---|
| 5152 | focusInEvent(), focusOutEvent(), event(), QKeyEvent
|
|---|
| 5153 | */
|
|---|
| 5154 |
|
|---|
| 5155 | void QWidget::keyReleaseEvent( QKeyEvent *e )
|
|---|
| 5156 | {
|
|---|
| 5157 | e->ignore();
|
|---|
| 5158 | }
|
|---|
| 5159 |
|
|---|
| 5160 | /*!
|
|---|
| 5161 | This event handler can be reimplemented in a subclass to receive
|
|---|
| 5162 | keyboard focus events (focus received) for the widget.
|
|---|
| 5163 |
|
|---|
| 5164 | A widget normally must setFocusPolicy() to something other than
|
|---|
| 5165 | \c NoFocus in order to receive focus events. (Note that the
|
|---|
| 5166 | application programmer can call setFocus() on any widget, even
|
|---|
| 5167 | those that do not normally accept focus.)
|
|---|
| 5168 |
|
|---|
| 5169 | The default implementation updates the widget (except for toplevel
|
|---|
| 5170 | widgets that do not specify a focusPolicy() ). It also calls
|
|---|
| 5171 | setMicroFocusHint(), hinting any system-specific input tools about
|
|---|
| 5172 | the focus of the user's attention.
|
|---|
| 5173 |
|
|---|
| 5174 | \sa focusOutEvent(), setFocusPolicy(), keyPressEvent(),
|
|---|
| 5175 | keyReleaseEvent(), event(), QFocusEvent
|
|---|
| 5176 | */
|
|---|
| 5177 |
|
|---|
| 5178 | void QWidget::focusInEvent( QFocusEvent * )
|
|---|
| 5179 | {
|
|---|
| 5180 | if ( focusPolicy() != NoFocus || !isTopLevel() ) {
|
|---|
| 5181 | update();
|
|---|
| 5182 | if ( testWState(WState_AutoMask) )
|
|---|
| 5183 | updateMask();
|
|---|
| 5184 | setMicroFocusHint(width()/2, 0, 1, height(), FALSE);
|
|---|
| 5185 | }
|
|---|
| 5186 | }
|
|---|
| 5187 |
|
|---|
| 5188 | /*!
|
|---|
| 5189 | This event handler can be reimplemented in a subclass to receive
|
|---|
| 5190 | keyboard focus events (focus lost) for the widget.
|
|---|
| 5191 |
|
|---|
| 5192 | A widget normally must setFocusPolicy() to something other than
|
|---|
| 5193 | \c NoFocus in order to receive focus events. (Note that the
|
|---|
| 5194 | application programmer can call setFocus() on any widget, even
|
|---|
| 5195 | those that do not normally accept focus.)
|
|---|
| 5196 |
|
|---|
| 5197 | The default implementation updates the widget (except for toplevel
|
|---|
| 5198 | widgets that do not specify a focusPolicy() ). It also calls
|
|---|
| 5199 | setMicroFocusHint(), hinting any system-specific input tools about
|
|---|
| 5200 | the focus of the user's attention.
|
|---|
| 5201 |
|
|---|
| 5202 | \sa focusInEvent(), setFocusPolicy(), keyPressEvent(),
|
|---|
| 5203 | keyReleaseEvent(), event(), QFocusEvent
|
|---|
| 5204 | */
|
|---|
| 5205 |
|
|---|
| 5206 | void QWidget::focusOutEvent( QFocusEvent * )
|
|---|
| 5207 | {
|
|---|
| 5208 | if ( focusPolicy() != NoFocus || !isTopLevel() ){
|
|---|
| 5209 | update();
|
|---|
| 5210 | if ( testWState(WState_AutoMask) )
|
|---|
| 5211 | updateMask();
|
|---|
| 5212 | }
|
|---|
| 5213 | }
|
|---|
| 5214 |
|
|---|
| 5215 | /*!
|
|---|
| 5216 | \property QWidget::microFocusHint
|
|---|
| 5217 | \brief the currently set micro focus hint for this widget.
|
|---|
| 5218 |
|
|---|
| 5219 | See the documentation of setMicroFocusHint() for more information.
|
|---|
| 5220 | */
|
|---|
| 5221 | QRect QWidget::microFocusHint() const
|
|---|
| 5222 | {
|
|---|
| 5223 | if ( !extra || extra->micro_focus_hint.isEmpty() )
|
|---|
| 5224 | return QRect(width()/2, 0, 1, height() );
|
|---|
| 5225 | else
|
|---|
| 5226 | return extra->micro_focus_hint;
|
|---|
| 5227 | }
|
|---|
| 5228 |
|
|---|
| 5229 | /*!
|
|---|
| 5230 | This event handler can be reimplemented in a subclass to receive
|
|---|
| 5231 | widget enter events.
|
|---|
| 5232 |
|
|---|
| 5233 | An event is sent to the widget when the mouse cursor enters the
|
|---|
| 5234 | widget.
|
|---|
| 5235 |
|
|---|
| 5236 | \sa leaveEvent(), mouseMoveEvent(), event()
|
|---|
| 5237 | */
|
|---|
| 5238 |
|
|---|
| 5239 | void QWidget::enterEvent( QEvent * )
|
|---|
| 5240 | {
|
|---|
| 5241 | }
|
|---|
| 5242 |
|
|---|
| 5243 | /*!
|
|---|
| 5244 | This event handler can be reimplemented in a subclass to receive
|
|---|
| 5245 | widget leave events.
|
|---|
| 5246 |
|
|---|
| 5247 | A leave event is sent to the widget when the mouse cursor leaves
|
|---|
| 5248 | the widget.
|
|---|
| 5249 |
|
|---|
| 5250 | \sa enterEvent(), mouseMoveEvent(), event()
|
|---|
| 5251 | */
|
|---|
| 5252 |
|
|---|
| 5253 | void QWidget::leaveEvent( QEvent * )
|
|---|
| 5254 | {
|
|---|
| 5255 | }
|
|---|
| 5256 |
|
|---|
| 5257 | /*!
|
|---|
| 5258 | This event handler can be reimplemented in a subclass to receive
|
|---|
| 5259 | paint events.
|
|---|
| 5260 |
|
|---|
| 5261 | A paint event is a request to repaint all or part of the widget.
|
|---|
| 5262 | It can happen as a result of repaint() or update(), or because the
|
|---|
| 5263 | widget was obscured and has now been uncovered, or for many other
|
|---|
| 5264 | reasons.
|
|---|
| 5265 |
|
|---|
| 5266 | Many widgets can simply repaint their entire surface when asked
|
|---|
| 5267 | to, but some slow widgets need to optimize by painting only the
|
|---|
| 5268 | requested region: QPaintEvent::region(). This speed optimization
|
|---|
| 5269 | does not change the result, as painting is clipped to that region
|
|---|
| 5270 | during event processing. QListView and QCanvas do this, for
|
|---|
| 5271 | example.
|
|---|
| 5272 |
|
|---|
| 5273 | Qt also tries to speed up painting by merging multiple paint
|
|---|
| 5274 | events into one. When update() is called several times or the
|
|---|
| 5275 | window system sends several paint events, Qt merges these events
|
|---|
| 5276 | into one event with a larger region (see QRegion::unite()).
|
|---|
| 5277 | repaint() does not permit this optimization, so we suggest using
|
|---|
| 5278 | update() when possible.
|
|---|
| 5279 |
|
|---|
| 5280 | When the paint event occurs, the update region has normally been
|
|---|
| 5281 | erased, so that you're painting on the widget's background. There
|
|---|
| 5282 | are a couple of exceptions and QPaintEvent::erased() tells you
|
|---|
| 5283 | whether the widget has been erased or not.
|
|---|
| 5284 |
|
|---|
| 5285 | The background can be set using setBackgroundMode(),
|
|---|
| 5286 | setPaletteBackgroundColor() or setBackgroundPixmap(). The
|
|---|
| 5287 | documentation for setBackgroundMode() elaborates on the
|
|---|
| 5288 | background; we recommend reading it.
|
|---|
| 5289 |
|
|---|
| 5290 | \sa event(), repaint(), update(), QPainter, QPixmap, QPaintEvent
|
|---|
| 5291 | */
|
|---|
| 5292 |
|
|---|
| 5293 | void QWidget::paintEvent( QPaintEvent * )
|
|---|
| 5294 | {
|
|---|
| 5295 | }
|
|---|
| 5296 |
|
|---|
| 5297 |
|
|---|
| 5298 | /*!
|
|---|
| 5299 | This event handler can be reimplemented in a subclass to receive
|
|---|
| 5300 | widget move events. When the widget receives this event, it is
|
|---|
| 5301 | already at the new position.
|
|---|
| 5302 |
|
|---|
| 5303 | The old position is accessible through QMoveEvent::oldPos().
|
|---|
| 5304 |
|
|---|
| 5305 | \sa resizeEvent(), event(), move(), QMoveEvent
|
|---|
| 5306 | */
|
|---|
| 5307 |
|
|---|
| 5308 | void QWidget::moveEvent( QMoveEvent * )
|
|---|
| 5309 | {
|
|---|
| 5310 | }
|
|---|
| 5311 |
|
|---|
| 5312 |
|
|---|
| 5313 | /*!
|
|---|
| 5314 | This event handler can be reimplemented in a subclass to receive
|
|---|
| 5315 | widget resize events. When resizeEvent() is called, the widget
|
|---|
| 5316 | already has its new geometry. The old size is accessible through
|
|---|
| 5317 | QResizeEvent::oldSize().
|
|---|
| 5318 |
|
|---|
| 5319 | The widget will be erased and receive a paint event immediately
|
|---|
| 5320 | after processing the resize event. No drawing need be (or should
|
|---|
| 5321 | be) done inside this handler.
|
|---|
| 5322 |
|
|---|
| 5323 | Widgets that have been created with the \c WNoAutoErase flag
|
|---|
| 5324 | will not be erased. Nevertheless, they will receive a paint event
|
|---|
| 5325 | for their entire area afterwards. Again, no drawing needs to be
|
|---|
| 5326 | done inside this handler.
|
|---|
| 5327 |
|
|---|
| 5328 | The default implementation calls updateMask() if the widget has
|
|---|
| 5329 | \link QWidget::setAutoMask() automatic masking\endlink enabled.
|
|---|
| 5330 |
|
|---|
| 5331 | \sa moveEvent(), event(), resize(), QResizeEvent, paintEvent()
|
|---|
| 5332 | */
|
|---|
| 5333 |
|
|---|
| 5334 | void QWidget::resizeEvent( QResizeEvent * )
|
|---|
| 5335 | {
|
|---|
| 5336 | if ( testWState(WState_AutoMask) )
|
|---|
| 5337 | updateMask();
|
|---|
| 5338 | }
|
|---|
| 5339 |
|
|---|
| 5340 | /*!
|
|---|
| 5341 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 5342 | subclass to receive widget close events.
|
|---|
| 5343 |
|
|---|
| 5344 | The default implementation calls e->accept(), which hides this
|
|---|
| 5345 | widget. See the \l QCloseEvent documentation for more details.
|
|---|
| 5346 |
|
|---|
| 5347 | \sa event(), hide(), close(), QCloseEvent
|
|---|
| 5348 | */
|
|---|
| 5349 |
|
|---|
| 5350 | void QWidget::closeEvent( QCloseEvent *e )
|
|---|
| 5351 | {
|
|---|
| 5352 | e->accept();
|
|---|
| 5353 | }
|
|---|
| 5354 |
|
|---|
| 5355 |
|
|---|
| 5356 | /*!
|
|---|
| 5357 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 5358 | subclass to receive widget context menu events.
|
|---|
| 5359 |
|
|---|
| 5360 | The default implementation calls e->ignore(), which rejects the
|
|---|
| 5361 | context event. See the \l QContextMenuEvent documentation for
|
|---|
| 5362 | more details.
|
|---|
| 5363 |
|
|---|
| 5364 | \sa event(), QContextMenuEvent
|
|---|
| 5365 | */
|
|---|
| 5366 |
|
|---|
| 5367 | void QWidget::contextMenuEvent( QContextMenuEvent *e )
|
|---|
| 5368 | {
|
|---|
| 5369 | e->ignore();
|
|---|
| 5370 | }
|
|---|
| 5371 |
|
|---|
| 5372 |
|
|---|
| 5373 | /*!
|
|---|
| 5374 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 5375 | subclass to receive Input Method composition events. This handler
|
|---|
| 5376 | is called when the user begins entering text using an Input Method.
|
|---|
| 5377 |
|
|---|
| 5378 | The default implementation calls e->ignore(), which rejects the
|
|---|
| 5379 | Input Method event. See the \l QIMEvent documentation for more
|
|---|
| 5380 | details.
|
|---|
| 5381 |
|
|---|
| 5382 | \sa event(), QIMEvent
|
|---|
| 5383 | */
|
|---|
| 5384 | void QWidget::imStartEvent( QIMEvent *e )
|
|---|
| 5385 | {
|
|---|
| 5386 | e->ignore();
|
|---|
| 5387 | }
|
|---|
| 5388 |
|
|---|
| 5389 | /*!
|
|---|
| 5390 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 5391 | subclass to receive Input Method composition events. This handler
|
|---|
| 5392 | is called when the user has entered some text using an Input Method.
|
|---|
| 5393 |
|
|---|
| 5394 | The default implementation calls e->ignore(), which rejects the
|
|---|
| 5395 | Input Method event. See the \l QIMEvent documentation for more
|
|---|
| 5396 | details.
|
|---|
| 5397 |
|
|---|
| 5398 | \sa event(), QIMEvent
|
|---|
| 5399 | */
|
|---|
| 5400 | void QWidget::imComposeEvent( QIMEvent *e )
|
|---|
| 5401 | {
|
|---|
| 5402 | e->ignore();
|
|---|
| 5403 | }
|
|---|
| 5404 |
|
|---|
| 5405 |
|
|---|
| 5406 | /*!
|
|---|
| 5407 | This event handler, for event \a e, can be reimplemented in a
|
|---|
| 5408 | subclass to receive Input Method composition events. This handler
|
|---|
| 5409 | is called when the user has finished inputting text via an Input
|
|---|
| 5410 | Method.
|
|---|
| 5411 |
|
|---|
| 5412 | The default implementation calls e->ignore(), which rejects the
|
|---|
| 5413 | Input Method event. See the \l QIMEvent documentation for more
|
|---|
| 5414 | details.
|
|---|
| 5415 |
|
|---|
| 5416 | \sa event(), QIMEvent
|
|---|
| 5417 | */
|
|---|
| 5418 | void QWidget::imEndEvent( QIMEvent *e )
|
|---|
| 5419 | {
|
|---|
| 5420 | e->ignore();
|
|---|
| 5421 | }
|
|---|
| 5422 |
|
|---|
| 5423 |
|
|---|
| 5424 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 5425 |
|
|---|
| 5426 | /*!
|
|---|
| 5427 | This event handler is called when a drag is in progress and the
|
|---|
| 5428 | mouse enters this widget.
|
|---|
| 5429 |
|
|---|
| 5430 | See the \link dnd.html Drag-and-drop documentation\endlink for an
|
|---|
| 5431 | overview of how to provide drag-and-drop in your application.
|
|---|
| 5432 |
|
|---|
| 5433 | \sa QTextDrag, QImageDrag, QDragEnterEvent
|
|---|
| 5434 | */
|
|---|
| 5435 | void QWidget::dragEnterEvent( QDragEnterEvent * )
|
|---|
| 5436 | {
|
|---|
| 5437 | }
|
|---|
| 5438 |
|
|---|
| 5439 | /*!
|
|---|
| 5440 | This event handler is called when a drag is in progress and the
|
|---|
| 5441 | mouse enters this widget, and whenever it moves within the widget.
|
|---|
| 5442 |
|
|---|
| 5443 | See the \link dnd.html Drag-and-drop documentation\endlink for an
|
|---|
| 5444 | overview of how to provide drag-and-drop in your application.
|
|---|
| 5445 |
|
|---|
| 5446 | \sa QTextDrag, QImageDrag, QDragMoveEvent
|
|---|
| 5447 | */
|
|---|
| 5448 | void QWidget::dragMoveEvent( QDragMoveEvent * )
|
|---|
| 5449 | {
|
|---|
| 5450 | }
|
|---|
| 5451 |
|
|---|
| 5452 | /*!
|
|---|
| 5453 | This event handler is called when a drag is in progress and the
|
|---|
| 5454 | mouse leaves this widget.
|
|---|
| 5455 |
|
|---|
| 5456 | See the \link dnd.html Drag-and-drop documentation\endlink for an
|
|---|
| 5457 | overview of how to provide drag-and-drop in your application.
|
|---|
| 5458 |
|
|---|
| 5459 | \sa QTextDrag, QImageDrag, QDragLeaveEvent
|
|---|
| 5460 | */
|
|---|
| 5461 | void QWidget::dragLeaveEvent( QDragLeaveEvent * )
|
|---|
| 5462 | {
|
|---|
| 5463 | }
|
|---|
| 5464 |
|
|---|
| 5465 | /*!
|
|---|
| 5466 | This event handler is called when the drag is dropped on this
|
|---|
| 5467 | widget.
|
|---|
| 5468 |
|
|---|
| 5469 | See the \link dnd.html Drag-and-drop documentation\endlink for an
|
|---|
| 5470 | overview of how to provide drag-and-drop in your application.
|
|---|
| 5471 |
|
|---|
| 5472 | \sa QTextDrag, QImageDrag, QDropEvent
|
|---|
| 5473 | */
|
|---|
| 5474 | void QWidget::dropEvent( QDropEvent * )
|
|---|
| 5475 | {
|
|---|
| 5476 | }
|
|---|
| 5477 |
|
|---|
| 5478 | #endif // QT_NO_DRAGANDDROP
|
|---|
| 5479 |
|
|---|
| 5480 | /*!
|
|---|
| 5481 | This event handler can be reimplemented in a subclass to receive
|
|---|
| 5482 | widget show events.
|
|---|
| 5483 |
|
|---|
| 5484 | Non-spontaneous show events are sent to widgets immediately before
|
|---|
| 5485 | they are shown. The spontaneous show events of top-level widgets
|
|---|
| 5486 | are delivered afterwards.
|
|---|
| 5487 |
|
|---|
| 5488 | \sa event(), QShowEvent
|
|---|
| 5489 | */
|
|---|
| 5490 | void QWidget::showEvent( QShowEvent * )
|
|---|
| 5491 | {
|
|---|
| 5492 | }
|
|---|
| 5493 |
|
|---|
| 5494 | /*!
|
|---|
| 5495 | This event handler can be reimplemented in a subclass to receive
|
|---|
| 5496 | widget hide events.
|
|---|
| 5497 |
|
|---|
| 5498 | Hide events are sent to widgets immediately after they have been
|
|---|
| 5499 | hidden.
|
|---|
| 5500 |
|
|---|
| 5501 | \sa event(), QHideEvent
|
|---|
| 5502 | */
|
|---|
| 5503 | void QWidget::hideEvent( QHideEvent * )
|
|---|
| 5504 | {
|
|---|
| 5505 | }
|
|---|
| 5506 |
|
|---|
| 5507 | /*
|
|---|
| 5508 | \fn QWidget::x11Event( MSG * )
|
|---|
| 5509 |
|
|---|
| 5510 | This special event handler can be reimplemented in a subclass to
|
|---|
| 5511 | receive native X11 events.
|
|---|
| 5512 |
|
|---|
| 5513 | In your reimplementation of this function, if you want to stop the
|
|---|
| 5514 | event being handled by Qt, return TRUE. If you return FALSE, this
|
|---|
| 5515 | native event is passed back to Qt, which translates the event into
|
|---|
| 5516 | a Qt event and sends it to the widget.
|
|---|
| 5517 |
|
|---|
| 5518 | \warning This function is not portable.
|
|---|
| 5519 |
|
|---|
| 5520 | \sa QApplication::x11EventFilter()
|
|---|
| 5521 | */
|
|---|
| 5522 |
|
|---|
| 5523 |
|
|---|
| 5524 | #if defined(Q_WS_MAC)
|
|---|
| 5525 |
|
|---|
| 5526 | /*!
|
|---|
| 5527 | This special event handler can be reimplemented in a subclass to
|
|---|
| 5528 | receive native Macintosh events.
|
|---|
| 5529 |
|
|---|
| 5530 | In your reimplementation of this function, if you want to stop the
|
|---|
| 5531 | event being handled by Qt, return TRUE. If you return FALSE, this
|
|---|
| 5532 | native event is passed back to Qt, which translates the event into
|
|---|
| 5533 | a Qt event and sends it to the widget.
|
|---|
| 5534 |
|
|---|
| 5535 | \warning This function is not portable.
|
|---|
| 5536 |
|
|---|
| 5537 | \sa QApplication::macEventFilter()
|
|---|
| 5538 | */
|
|---|
| 5539 |
|
|---|
| 5540 | bool QWidget::macEvent( MSG * )
|
|---|
| 5541 | {
|
|---|
| 5542 | return FALSE;
|
|---|
| 5543 | }
|
|---|
| 5544 |
|
|---|
| 5545 | #endif
|
|---|
| 5546 | #if defined(Q_WS_WIN)
|
|---|
| 5547 |
|
|---|
| 5548 | /*!
|
|---|
| 5549 | This special event handler can be reimplemented in a subclass to
|
|---|
| 5550 | receive native Windows events.
|
|---|
| 5551 |
|
|---|
| 5552 | In your reimplementation of this function, if you want to stop the
|
|---|
| 5553 | event being handled by Qt, return TRUE. If you return FALSE, this
|
|---|
| 5554 | native event is passed back to Qt, which translates the event into
|
|---|
| 5555 | a Qt event and sends it to the widget.
|
|---|
| 5556 |
|
|---|
| 5557 | \warning This function is not portable.
|
|---|
| 5558 |
|
|---|
| 5559 | \sa QApplication::winEventFilter()
|
|---|
| 5560 | */
|
|---|
| 5561 | bool QWidget::winEvent( MSG * )
|
|---|
| 5562 | {
|
|---|
| 5563 | return FALSE;
|
|---|
| 5564 | }
|
|---|
| 5565 |
|
|---|
| 5566 | #endif
|
|---|
| 5567 | #if defined(Q_WS_PM)
|
|---|
| 5568 |
|
|---|
| 5569 | /*!
|
|---|
| 5570 | This special event handler can be reimplemented in a subclass to
|
|---|
| 5571 | receive native OS/2 PM events.
|
|---|
| 5572 |
|
|---|
| 5573 | In your reimplementation of this function, if you want to stop the
|
|---|
| 5574 | event being handled by Qt, return TRUE. If you return FALSE, this
|
|---|
| 5575 | native event is passed back to Qt, which translates the event into
|
|---|
| 5576 | a Qt event and sends it to the widget.
|
|---|
| 5577 |
|
|---|
| 5578 | \warning This function is not portable.
|
|---|
| 5579 |
|
|---|
| 5580 | \sa QApplication::pmEventFilter()
|
|---|
| 5581 | */
|
|---|
| 5582 | bool QWidget::pmEvent( QMSG * )
|
|---|
| 5583 | {
|
|---|
| 5584 | return FALSE;
|
|---|
| 5585 | }
|
|---|
| 5586 |
|
|---|
| 5587 | #endif
|
|---|
| 5588 | #if defined(Q_WS_X11)
|
|---|
| 5589 |
|
|---|
| 5590 | /*!
|
|---|
| 5591 | This special event handler can be reimplemented in a subclass to
|
|---|
| 5592 | receive native X11 events.
|
|---|
| 5593 |
|
|---|
| 5594 | In your reimplementation of this function, if you want to stop the
|
|---|
| 5595 | event being handled by Qt, return TRUE. If you return FALSE, this
|
|---|
| 5596 | native event is passed back to Qt, which translates the event into
|
|---|
| 5597 | a Qt event and sends it to the widget.
|
|---|
| 5598 |
|
|---|
| 5599 | \warning This function is not portable.
|
|---|
| 5600 |
|
|---|
| 5601 | \sa QApplication::x11EventFilter()
|
|---|
| 5602 | */
|
|---|
| 5603 | bool QWidget::x11Event( XEvent * )
|
|---|
| 5604 | {
|
|---|
| 5605 | return FALSE;
|
|---|
| 5606 | }
|
|---|
| 5607 |
|
|---|
| 5608 | #endif
|
|---|
| 5609 | #if defined(Q_WS_QWS)
|
|---|
| 5610 |
|
|---|
| 5611 | /*!
|
|---|
| 5612 | This special event handler can be reimplemented in a subclass to
|
|---|
| 5613 | receive native Qt/Embedded events.
|
|---|
| 5614 |
|
|---|
| 5615 | In your reimplementation of this function, if you want to stop the
|
|---|
| 5616 | event being handled by Qt, return TRUE. If you return FALSE, this
|
|---|
| 5617 | native event is passed back to Qt, which translates the event into
|
|---|
| 5618 | a Qt event and sends it to the widget.
|
|---|
| 5619 |
|
|---|
| 5620 | \warning This function is not portable.
|
|---|
| 5621 |
|
|---|
| 5622 | \sa QApplication::qwsEventFilter()
|
|---|
| 5623 | */
|
|---|
| 5624 | bool QWidget::qwsEvent( QWSEvent * )
|
|---|
| 5625 | {
|
|---|
| 5626 | return FALSE;
|
|---|
| 5627 | }
|
|---|
| 5628 |
|
|---|
| 5629 | #endif
|
|---|
| 5630 |
|
|---|
| 5631 | /*!
|
|---|
| 5632 | \property QWidget::autoMask
|
|---|
| 5633 | \brief whether the auto mask feature is enabled for the widget
|
|---|
| 5634 |
|
|---|
| 5635 | Transparent widgets use a mask to define their visible region.
|
|---|
| 5636 | QWidget has some built-in support to make the task of
|
|---|
| 5637 | recalculating the mask easier. When setting auto mask to TRUE,
|
|---|
| 5638 | updateMask() will be called whenever the widget is resized or
|
|---|
| 5639 | changes its focus state. Note that you must reimplement
|
|---|
| 5640 | updateMask() (which should include a call to setMask()) or nothing
|
|---|
| 5641 | will happen.
|
|---|
| 5642 |
|
|---|
| 5643 | Note: when you re-implement resizeEvent(), focusInEvent() or
|
|---|
| 5644 | focusOutEvent() in your custom widgets and still want to ensure
|
|---|
| 5645 | that the auto mask calculation works, you should add:
|
|---|
| 5646 |
|
|---|
| 5647 | \code
|
|---|
| 5648 | if ( autoMask() )
|
|---|
| 5649 | updateMask();
|
|---|
| 5650 | \endcode
|
|---|
| 5651 |
|
|---|
| 5652 | at the end of your event handlers. This is true for all member
|
|---|
| 5653 | functions that change the appearance of the widget in a way that
|
|---|
| 5654 | requires a recalculation of the mask.
|
|---|
| 5655 |
|
|---|
| 5656 | While being a technically appealing concept, masks have a big
|
|---|
| 5657 | drawback: when using complex masks that cannot be expressed easily
|
|---|
| 5658 | with relatively simple regions, they can be very slow on some
|
|---|
| 5659 | window systems. The classic example is a transparent label. The
|
|---|
| 5660 | complex shape of its contents makes it necessary to represent its
|
|---|
| 5661 | mask by a bitmap, which consumes both memory and time. If all you
|
|---|
| 5662 | want is to blend the background of several neighboring widgets
|
|---|
| 5663 | together seamlessly, you will probably want to use
|
|---|
| 5664 | setBackgroundOrigin() rather than a mask.
|
|---|
| 5665 |
|
|---|
| 5666 | \sa autoMask() updateMask() setMask() clearMask() setBackgroundOrigin()
|
|---|
| 5667 | */
|
|---|
| 5668 |
|
|---|
| 5669 | bool QWidget::autoMask() const
|
|---|
| 5670 | {
|
|---|
| 5671 | return testWState(WState_AutoMask);
|
|---|
| 5672 | }
|
|---|
| 5673 |
|
|---|
| 5674 | void QWidget::setAutoMask( bool enable )
|
|---|
| 5675 | {
|
|---|
| 5676 | if ( enable == autoMask() )
|
|---|
| 5677 | return;
|
|---|
| 5678 |
|
|---|
| 5679 | if ( enable ) {
|
|---|
| 5680 | setWState(WState_AutoMask);
|
|---|
| 5681 | updateMask();
|
|---|
| 5682 | } else {
|
|---|
| 5683 | clearWState(WState_AutoMask);
|
|---|
| 5684 | clearMask();
|
|---|
| 5685 | }
|
|---|
| 5686 | }
|
|---|
| 5687 |
|
|---|
| 5688 | /*!
|
|---|
| 5689 | \enum QWidget::BackgroundOrigin
|
|---|
| 5690 |
|
|---|
| 5691 | This enum defines the origin used to draw a widget's background
|
|---|
| 5692 | pixmap.
|
|---|
| 5693 |
|
|---|
| 5694 | The pixmap is drawn using the:
|
|---|
| 5695 | \value WidgetOrigin widget's coordinate system.
|
|---|
| 5696 | \value ParentOrigin parent's coordinate system.
|
|---|
| 5697 | \value WindowOrigin top-level window's coordinate system.
|
|---|
| 5698 | \value AncestorOrigin same origin as the parent uses.
|
|---|
| 5699 | */
|
|---|
| 5700 |
|
|---|
| 5701 | /*!
|
|---|
| 5702 | \property QWidget::backgroundOrigin
|
|---|
| 5703 | \brief the origin of the widget's background
|
|---|
| 5704 |
|
|---|
| 5705 | The origin is either WidgetOrigin (the default), ParentOrigin,
|
|---|
| 5706 | WindowOrigin or AncestorOrigin.
|
|---|
| 5707 |
|
|---|
| 5708 | This only makes a difference if the widget has a background
|
|---|
| 5709 | pixmap, in which case positioning matters. Using \c WindowOrigin
|
|---|
| 5710 | for several neighboring widgets makes the background blend
|
|---|
| 5711 | together seamlessly. \c AncestorOrigin allows blending backgrounds
|
|---|
| 5712 | seamlessly when an ancestor of the widget has an origin other than
|
|---|
| 5713 | \c QWindowOrigin.
|
|---|
| 5714 |
|
|---|
| 5715 | \sa backgroundPixmap(), setBackgroundMode()
|
|---|
| 5716 | */
|
|---|
| 5717 | QWidget::BackgroundOrigin QWidget::backgroundOrigin() const
|
|---|
| 5718 | {
|
|---|
| 5719 | return extra ? (BackgroundOrigin)extra->bg_origin : WidgetOrigin;
|
|---|
| 5720 | }
|
|---|
| 5721 |
|
|---|
| 5722 | void QWidget::setBackgroundOrigin( BackgroundOrigin origin )
|
|---|
| 5723 | {
|
|---|
| 5724 | if ( origin == backgroundOrigin() )
|
|---|
| 5725 | return;
|
|---|
| 5726 | createExtra();
|
|---|
| 5727 | extra->bg_origin = origin;
|
|---|
| 5728 | update();
|
|---|
| 5729 | }
|
|---|
| 5730 |
|
|---|
| 5731 | /*!
|
|---|
| 5732 | This function can be reimplemented in a subclass to support
|
|---|
| 5733 | transparent widgets. It should be called whenever a widget changes
|
|---|
| 5734 | state in a way that means that the shape mask must be recalculated.
|
|---|
| 5735 |
|
|---|
| 5736 | \sa setAutoMask(), updateMask(), setMask(), clearMask()
|
|---|
| 5737 | */
|
|---|
| 5738 | void QWidget::updateMask()
|
|---|
| 5739 | {
|
|---|
| 5740 | }
|
|---|
| 5741 |
|
|---|
| 5742 | /*!
|
|---|
| 5743 | \internal
|
|---|
| 5744 | Returns the offset of the widget from the backgroundOrigin.
|
|---|
| 5745 |
|
|---|
| 5746 | \sa setBackgroundMode(), backgroundMode(),
|
|---|
| 5747 | */
|
|---|
| 5748 | QPoint QWidget::backgroundOffset() const
|
|---|
| 5749 | {
|
|---|
| 5750 | if (!isTopLevel()) {
|
|---|
| 5751 | switch(backgroundOrigin()) {
|
|---|
| 5752 | case WidgetOrigin:
|
|---|
| 5753 | break;
|
|---|
| 5754 | case ParentOrigin:
|
|---|
| 5755 | return pos();
|
|---|
| 5756 | case WindowOrigin:
|
|---|
| 5757 | {
|
|---|
| 5758 | const QWidget *topl = this;
|
|---|
| 5759 | while(topl && !topl->isTopLevel() && !topl->testWFlags(Qt::WSubWindow))
|
|---|
| 5760 | topl = topl->parentWidget(TRUE);
|
|---|
| 5761 | return mapTo((QWidget *)topl, QPoint(0, 0) );
|
|---|
| 5762 | }
|
|---|
| 5763 | case AncestorOrigin:
|
|---|
| 5764 | {
|
|---|
| 5765 | const QWidget *topl = this;
|
|---|
| 5766 | bool ancestorIsWindowOrigin = FALSE;
|
|---|
| 5767 | while(topl && !topl->isTopLevel() && !topl->testWFlags(Qt::WSubWindow))
|
|---|
| 5768 | {
|
|---|
| 5769 | if (!ancestorIsWindowOrigin) {
|
|---|
| 5770 | if (topl->backgroundOrigin() == QWidget::WidgetOrigin)
|
|---|
| 5771 | break;
|
|---|
| 5772 | if (topl->backgroundOrigin() == QWidget::ParentOrigin)
|
|---|
| 5773 | {
|
|---|
| 5774 | topl = topl->parentWidget(TRUE);
|
|---|
| 5775 | break;
|
|---|
| 5776 | }
|
|---|
| 5777 | if (topl->backgroundOrigin() == QWidget::WindowOrigin)
|
|---|
| 5778 | ancestorIsWindowOrigin = TRUE;
|
|---|
| 5779 | }
|
|---|
| 5780 | topl = topl->parentWidget(TRUE);
|
|---|
| 5781 | }
|
|---|
| 5782 |
|
|---|
| 5783 | return mapTo((QWidget *) topl, QPoint(0,0) );
|
|---|
| 5784 | }
|
|---|
| 5785 | }
|
|---|
| 5786 | }
|
|---|
| 5787 | // fall back
|
|---|
| 5788 | return QPoint(0,0);
|
|---|
| 5789 | }
|
|---|
| 5790 |
|
|---|
| 5791 | /*!
|
|---|
| 5792 | \fn QLayout* QWidget::layout () const
|
|---|
| 5793 |
|
|---|
| 5794 | Returns the layout engine that manages the geometry of this
|
|---|
| 5795 | widget's children.
|
|---|
| 5796 |
|
|---|
| 5797 | If the widget does not have a layout, layout() returns 0.
|
|---|
| 5798 |
|
|---|
| 5799 | \sa sizePolicy()
|
|---|
| 5800 | */
|
|---|
| 5801 |
|
|---|
| 5802 |
|
|---|
| 5803 | /* Sets this widget to use layout \a l to manage the geometry of its
|
|---|
| 5804 | children.
|
|---|
| 5805 |
|
|---|
| 5806 | If the widget already had a layout, the old layout is
|
|---|
| 5807 | forgotten. (Note that it is not deleted.)
|
|---|
| 5808 |
|
|---|
| 5809 | \sa layout() QLayout sizePolicy()
|
|---|
| 5810 | */
|
|---|
| 5811 | #ifndef QT_NO_LAYOUT
|
|---|
| 5812 | void QWidget::setLayout( QLayout *l )
|
|---|
| 5813 | {
|
|---|
| 5814 | lay_out = l;
|
|---|
| 5815 | }
|
|---|
| 5816 | #endif
|
|---|
| 5817 |
|
|---|
| 5818 | /*!
|
|---|
| 5819 | \property QWidget::sizePolicy
|
|---|
| 5820 | \brief the default layout behavior of the widget
|
|---|
| 5821 |
|
|---|
| 5822 | If there is a QLayout that manages this widget's children, the
|
|---|
| 5823 | size policy specified by that layout is used. If there is no such
|
|---|
| 5824 | QLayout, the result of this function is used.
|
|---|
| 5825 |
|
|---|
| 5826 | The default policy is Preferred/Preferred, which means that the
|
|---|
| 5827 | widget can be freely resized, but prefers to be the size
|
|---|
| 5828 | sizeHint() returns. Button-like widgets set the size policy to
|
|---|
| 5829 | specify that they may stretch horizontally, but are fixed
|
|---|
| 5830 | vertically. The same applies to lineedit controls (such as
|
|---|
| 5831 | QLineEdit, QSpinBox or an editable QComboBox) and other
|
|---|
| 5832 | horizontally orientated widgets (such as QProgressBar).
|
|---|
| 5833 | QToolButton's are normally square, so they allow growth in both
|
|---|
| 5834 | directions. Widgets that support different directions (such as
|
|---|
| 5835 | QSlider, QScrollBar or QHeader) specify stretching in the
|
|---|
| 5836 | respective direction only. Widgets that can provide scrollbars
|
|---|
| 5837 | (usually subclasses of QScrollView) tend to specify that they can
|
|---|
| 5838 | use additional space, and that they can make do with less than
|
|---|
| 5839 | sizeHint().
|
|---|
| 5840 |
|
|---|
| 5841 | \sa sizeHint() QLayout QSizePolicy updateGeometry()
|
|---|
| 5842 | */
|
|---|
| 5843 | QSizePolicy QWidget::sizePolicy() const
|
|---|
| 5844 | {
|
|---|
| 5845 | return extra ? extra->size_policy
|
|---|
| 5846 | : QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
|
|---|
| 5847 | }
|
|---|
| 5848 |
|
|---|
| 5849 | void QWidget::setSizePolicy( QSizePolicy policy )
|
|---|
| 5850 | {
|
|---|
| 5851 | setWState( WState_OwnSizePolicy );
|
|---|
| 5852 | if ( policy == sizePolicy() )
|
|---|
| 5853 | return;
|
|---|
| 5854 | createExtra();
|
|---|
| 5855 | extra->size_policy = policy;
|
|---|
| 5856 | updateGeometry();
|
|---|
| 5857 | }
|
|---|
| 5858 |
|
|---|
| 5859 | /*!
|
|---|
| 5860 | \overload void QWidget::setSizePolicy( QSizePolicy::SizeType hor, QSizePolicy::SizeType ver, bool hfw )
|
|---|
| 5861 |
|
|---|
| 5862 | Sets the size policy of the widget to \a hor, \a ver and \a hfw
|
|---|
| 5863 | (height for width).
|
|---|
| 5864 |
|
|---|
| 5865 | \sa QSizePolicy::QSizePolicy()
|
|---|
| 5866 | */
|
|---|
| 5867 |
|
|---|
| 5868 | /*!
|
|---|
| 5869 | Returns the preferred height for this widget, given the width \a
|
|---|
| 5870 | w. The default implementation returns 0, indicating that the
|
|---|
| 5871 | preferred height does not depend on the width.
|
|---|
| 5872 |
|
|---|
| 5873 | \warning Does not look at the widget's layout.
|
|---|
| 5874 | */
|
|---|
| 5875 |
|
|---|
| 5876 | int QWidget::heightForWidth( int w ) const
|
|---|
| 5877 | {
|
|---|
| 5878 | (void)w;
|
|---|
| 5879 | return 0;
|
|---|
| 5880 | }
|
|---|
| 5881 |
|
|---|
| 5882 | /*!
|
|---|
| 5883 | \property QWidget::customWhatsThis
|
|---|
| 5884 | \brief whether the widget wants to handle What's This help manually
|
|---|
| 5885 |
|
|---|
| 5886 | The default implementation of customWhatsThis() returns FALSE,
|
|---|
| 5887 | which means the widget will not receive any events in Whats This
|
|---|
| 5888 | mode.
|
|---|
| 5889 |
|
|---|
| 5890 | The widget may leave What's This mode by calling
|
|---|
| 5891 | QWhatsThis::leaveWhatsThisMode(), with or without actually
|
|---|
| 5892 | displaying any help text.
|
|---|
| 5893 |
|
|---|
| 5894 | You can also reimplement customWhatsThis() if your widget is a
|
|---|
| 5895 | "passive interactor" supposed to work under all circumstances.
|
|---|
| 5896 | Simply don't call QWhatsThis::leaveWhatsThisMode() in that case.
|
|---|
| 5897 |
|
|---|
| 5898 | \sa QWhatsThis::inWhatsThisMode() QWhatsThis::leaveWhatsThisMode()
|
|---|
| 5899 | */
|
|---|
| 5900 | bool QWidget::customWhatsThis() const
|
|---|
| 5901 | {
|
|---|
| 5902 | return FALSE;
|
|---|
| 5903 | }
|
|---|
| 5904 |
|
|---|
| 5905 | /*!
|
|---|
| 5906 | Returns the visible child widget at pixel position \a (x, y) in
|
|---|
| 5907 | the widget's own coordinate system.
|
|---|
| 5908 |
|
|---|
| 5909 | If \a includeThis is TRUE, and there is no child visible at \a (x,
|
|---|
| 5910 | y), the widget itself is returned.
|
|---|
| 5911 | */
|
|---|
| 5912 | QWidget *QWidget::childAt( int x, int y, bool includeThis ) const
|
|---|
| 5913 | {
|
|---|
| 5914 | if ( !rect().contains( x, y ) )
|
|---|
| 5915 | return 0;
|
|---|
| 5916 | if ( children() ) {
|
|---|
| 5917 | QObjectListIt it( *children() );
|
|---|
| 5918 | it.toLast();
|
|---|
| 5919 | QWidget *w, *t;
|
|---|
| 5920 | while( (w=(QWidget *)it.current()) != 0 ) {
|
|---|
| 5921 | --it;
|
|---|
| 5922 | if ( w->isWidgetType() && !w->isTopLevel() && !w->isHidden() ) {
|
|---|
| 5923 | if ( ( t = w->childAt( x - w->x(), y - w->y(), TRUE ) ) )
|
|---|
| 5924 | return t;
|
|---|
| 5925 | }
|
|---|
| 5926 | }
|
|---|
| 5927 | }
|
|---|
| 5928 | if ( includeThis )
|
|---|
| 5929 | return (QWidget*)this;
|
|---|
| 5930 | return 0;
|
|---|
| 5931 | }
|
|---|
| 5932 |
|
|---|
| 5933 | /*!
|
|---|
| 5934 | \overload
|
|---|
| 5935 |
|
|---|
| 5936 | Returns the visible child widget at point \a p in the widget's own
|
|---|
| 5937 | coordinate system.
|
|---|
| 5938 |
|
|---|
| 5939 | If \a includeThis is TRUE, and there is no child visible at \a p,
|
|---|
| 5940 | the widget itself is returned.
|
|---|
| 5941 |
|
|---|
| 5942 | */
|
|---|
| 5943 | QWidget *QWidget::childAt( const QPoint & p, bool includeThis ) const
|
|---|
| 5944 | {
|
|---|
| 5945 | return childAt( p.x(), p.y(), includeThis );
|
|---|
| 5946 | }
|
|---|
| 5947 |
|
|---|
| 5948 |
|
|---|
| 5949 | /*!
|
|---|
| 5950 | Notifies the layout system that this widget has changed and may
|
|---|
| 5951 | need to change geometry.
|
|---|
| 5952 |
|
|---|
| 5953 | Call this function if the sizeHint() or sizePolicy() have changed.
|
|---|
| 5954 |
|
|---|
| 5955 | For explicitly hidden widgets, updateGeometry() is a no-op. The
|
|---|
| 5956 | layout system will be notified as soon as the widget is shown.
|
|---|
| 5957 | */
|
|---|
| 5958 |
|
|---|
| 5959 | void QWidget::updateGeometry()
|
|---|
| 5960 | {
|
|---|
| 5961 | if ( !isTopLevel() && isShown() )
|
|---|
| 5962 | QApplication::postEvent( parentWidget(),
|
|---|
| 5963 | new QEvent( QEvent::LayoutHint ) );
|
|---|
| 5964 | }
|
|---|
| 5965 |
|
|---|
| 5966 |
|
|---|
| 5967 | /*!
|
|---|
| 5968 | Reparents the widget. The widget gets a new \a parent, new widget
|
|---|
| 5969 | flags (\a f, but as usual, use 0) at a new position in its new
|
|---|
| 5970 | parent (\a p).
|
|---|
| 5971 |
|
|---|
| 5972 | If \a showIt is TRUE, show() is called once the widget has been
|
|---|
| 5973 | reparented.
|
|---|
| 5974 |
|
|---|
| 5975 | If the new parent widget is in a different top-level widget, the
|
|---|
| 5976 | reparented widget and its children are appended to the end of the
|
|---|
| 5977 | \link setFocusPolicy() tab chain \endlink of the new parent
|
|---|
| 5978 | widget, in the same internal order as before. If one of the moved
|
|---|
| 5979 | widgets had keyboard focus, reparent() calls clearFocus() for that
|
|---|
| 5980 | widget.
|
|---|
| 5981 |
|
|---|
| 5982 | If the new parent widget is in the same top-level widget as the
|
|---|
| 5983 | old parent, reparent doesn't change the tab order or keyboard
|
|---|
| 5984 | focus.
|
|---|
| 5985 |
|
|---|
| 5986 | \warning It is extremely unlikely that you will ever need this
|
|---|
| 5987 | function. If you have a widget that changes its content
|
|---|
| 5988 | dynamically, it is far easier to use \l QWidgetStack or \l
|
|---|
| 5989 | QWizard.
|
|---|
| 5990 |
|
|---|
| 5991 | \sa getWFlags()
|
|---|
| 5992 | */
|
|---|
| 5993 |
|
|---|
| 5994 | void QWidget::reparent( QWidget *parent, WFlags f, const QPoint &p,
|
|---|
| 5995 | bool showIt )
|
|---|
| 5996 | {
|
|---|
| 5997 | reparentSys( parent, f, p, showIt );
|
|---|
| 5998 | QEvent e( QEvent::Reparent );
|
|---|
| 5999 | QApplication::sendEvent( this, &e );
|
|---|
| 6000 | if (!own_font)
|
|---|
| 6001 | unsetFont();
|
|---|
| 6002 | else
|
|---|
| 6003 | setFont( fnt.resolve( qt_naturalWidgetFont( this ) ) );
|
|---|
| 6004 | #ifndef QT_NO_PALETTE
|
|---|
| 6005 | if (!own_palette)
|
|---|
| 6006 | unsetPalette();
|
|---|
| 6007 | #endif
|
|---|
| 6008 | }
|
|---|
| 6009 |
|
|---|
| 6010 | /*!
|
|---|
| 6011 | \overload
|
|---|
| 6012 |
|
|---|
| 6013 | A convenience version of reparent that does not take widget flags
|
|---|
| 6014 | as argument.
|
|---|
| 6015 |
|
|---|
| 6016 | Calls reparent(\a parent, getWFlags() \& ~\l WType_Mask, \a p, \a
|
|---|
| 6017 | showIt).
|
|---|
| 6018 | */
|
|---|
| 6019 | void QWidget::reparent( QWidget *parent, const QPoint & p,
|
|---|
| 6020 | bool showIt )
|
|---|
| 6021 | {
|
|---|
| 6022 | reparent( parent, getWFlags() & ~WType_Mask, p, showIt );
|
|---|
| 6023 | }
|
|---|
| 6024 |
|
|---|
| 6025 | /*!
|
|---|
| 6026 | \property QWidget::ownCursor
|
|---|
| 6027 | \brief whether the widget uses its own cursor
|
|---|
| 6028 |
|
|---|
| 6029 | If FALSE, the widget uses its parent widget's cursor.
|
|---|
| 6030 |
|
|---|
| 6031 | \sa cursor
|
|---|
| 6032 | */
|
|---|
| 6033 |
|
|---|
| 6034 | /*!
|
|---|
| 6035 | \property QWidget::ownFont
|
|---|
| 6036 | \brief whether the widget uses its own font
|
|---|
| 6037 |
|
|---|
| 6038 | If FALSE, the widget uses its parent widget's font.
|
|---|
| 6039 |
|
|---|
| 6040 | \sa font
|
|---|
| 6041 | */
|
|---|
| 6042 |
|
|---|
| 6043 | /*!
|
|---|
| 6044 | \property QWidget::ownPalette
|
|---|
| 6045 | \brief whether the widget uses its own palette
|
|---|
| 6046 |
|
|---|
| 6047 | If FALSE, the widget uses its parent widget's palette.
|
|---|
| 6048 |
|
|---|
| 6049 | \sa palette
|
|---|
| 6050 | */
|
|---|
| 6051 |
|
|---|
| 6052 |
|
|---|
| 6053 | void QWidget::repaint( bool erase )
|
|---|
| 6054 | {
|
|---|
| 6055 | repaint( visibleRect(), erase );
|
|---|
| 6056 | }
|
|---|
| 6057 |
|
|---|
| 6058 |
|
|---|
| 6059 |
|
|---|
| 6060 |
|
|---|
| 6061 | /*!\obsolete Use paletteBackgroundColor() or eraseColor() instead. */
|
|---|
| 6062 | const QColor & QWidget::backgroundColor() const { return eraseColor(); }
|
|---|
| 6063 | /*!\obsolete Use setPaletteBackgroundColor() or setEraseColor() instead. */
|
|---|
| 6064 | void QWidget::setBackgroundColor( const QColor &c ) { setEraseColor( c ); }
|
|---|
| 6065 | /*!\obsolete Use paletteBackgroundPixmap() or erasePixmap() instead. */
|
|---|
| 6066 | const QPixmap *QWidget::backgroundPixmap() const { return erasePixmap(); }
|
|---|
| 6067 | /*!\obsolete Use setPaletteBackgroundPixmap() or setErasePixmap() instead. */
|
|---|
| 6068 | void QWidget::setBackgroundPixmap( const QPixmap &pm ) { setErasePixmap( pm ); }
|
|---|
| 6069 |
|
|---|
| 6070 |
|
|---|
| 6071 | // documentation in qdesktopwidget_win.cpp
|
|---|
| 6072 | void QDesktopWidget::insertChild( QObject *obj )
|
|---|
| 6073 | {
|
|---|
| 6074 | if ( obj->isWidgetType() )
|
|---|
| 6075 | return;
|
|---|
| 6076 | QWidget::insertChild( obj );
|
|---|
| 6077 | }
|
|---|
| 6078 |
|
|---|
| 6079 | /*!
|
|---|
| 6080 | \property QWidget::windowOpacity
|
|---|
| 6081 |
|
|---|
| 6082 | \brief The level of opacity for the window.
|
|---|
| 6083 |
|
|---|
| 6084 | The valid range of opacity is from 1.0 (completely opaque) to
|
|---|
| 6085 | 0.0 (completely transparent).
|
|---|
| 6086 |
|
|---|
| 6087 | By default the value of this property is 1.0.
|
|---|
| 6088 |
|
|---|
| 6089 | This feature is only present on Mac OS X and Windows 2000 and up.
|
|---|
| 6090 |
|
|---|
| 6091 | \warning Changing this property from opaque to transparent might issue a
|
|---|
| 6092 | paint event that needs to be processed before the window is displayed
|
|---|
| 6093 | correctly. This affects mainly the use of QPixmap::grabWindow(). Also note
|
|---|
| 6094 | that semi-transparent windows update and resize significantely slower than
|
|---|
| 6095 | opaque windows.
|
|---|
| 6096 | */
|
|---|