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