| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** All rights reserved. | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 6 | ** | 
|---|
| 7 | ** This file is part of the documentation of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:FDL$ | 
|---|
| 10 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in a | 
|---|
| 14 | ** written agreement between you and Nokia. | 
|---|
| 15 | ** | 
|---|
| 16 | ** GNU Free Documentation License | 
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Free | 
|---|
| 18 | ** Documentation License version 1.3 as published by the Free Software | 
|---|
| 19 | ** Foundation and appearing in the file included in the packaging of this | 
|---|
| 20 | ** file. | 
|---|
| 21 | ** | 
|---|
| 22 | ** If you have questions regarding the use of this file, please contact | 
|---|
| 23 | ** Nokia at qt-info@nokia.com. | 
|---|
| 24 | ** $QT_END_LICENSE$ | 
|---|
| 25 | ** | 
|---|
| 26 | ****************************************************************************/ | 
|---|
| 27 |  | 
|---|
| 28 | /*! | 
|---|
| 29 | \class QDesktopWidget | 
|---|
| 30 | \brief The QDesktopWidget class provides access to screen information on multi-head systems. | 
|---|
| 31 |  | 
|---|
| 32 | \ingroup advanced | 
|---|
| 33 | \ingroup desktop | 
|---|
| 34 |  | 
|---|
| 35 | Systems with more than one graphics card and monitor can manage the | 
|---|
| 36 | physical screen space available either as multiple desktops, or as a | 
|---|
| 37 | large virtual desktop. | 
|---|
| 38 |  | 
|---|
| 39 | This class provides information about the user's desktop, such as its | 
|---|
| 40 | total size, number of screens, the geometry of each screen, and whether | 
|---|
| 41 | they are configured as separate desktops or a single virtual desktop. | 
|---|
| 42 |  | 
|---|
| 43 | Widgets provided by Qt use this class to place tooltips, menus and | 
|---|
| 44 | dialog boxes on the correct screen for their parent or application | 
|---|
| 45 | widgets. Applications can use this class to obtain information that | 
|---|
| 46 | can be used to save window positions, or to place child widgets and | 
|---|
| 47 | dialogs on one particular screen. | 
|---|
| 48 |  | 
|---|
| 49 | \section1 Obtaining a Desktop Widget | 
|---|
| 50 |  | 
|---|
| 51 | The QApplication::desktop() function is used to get an instance of | 
|---|
| 52 | QDesktopWidget. | 
|---|
| 53 |  | 
|---|
| 54 | The widget's screenGeometry() function provides information about the | 
|---|
| 55 | geometry of the available screens with. The number of screens | 
|---|
| 56 | available is returned by screenCount, and the screenCountChanged() | 
|---|
| 57 | signal is emitted when screens are added or removed. | 
|---|
| 58 | The screen number that a particular point or widget is located in | 
|---|
| 59 | is returned by screenNumber(). | 
|---|
| 60 |  | 
|---|
| 61 | \section1 Screen Geometry | 
|---|
| 62 |  | 
|---|
| 63 | To obtain the dimensions of a particular screen, call the screenGeometry() | 
|---|
| 64 | function. On some desktop environments, not all of the screen is | 
|---|
| 65 | available for applications to use; for example, an application dock or | 
|---|
| 66 | menu bar may take up some space. Use the availableGeometry() function | 
|---|
| 67 | to obtain the available area for applications. | 
|---|
| 68 |  | 
|---|
| 69 | QDesktopWidget also inherits the QWidget properties, width() and | 
|---|
| 70 | height(), which specify the size of the desktop. However, for | 
|---|
| 71 | desktops with multiple screens, the size of the desktop is the union | 
|---|
| 72 | of all the screen sizes, so width() and height() should \e not be | 
|---|
| 73 | used for computing the size of a widget to be placed on one of the | 
|---|
| 74 | screens. | 
|---|
| 75 |  | 
|---|
| 76 | On systems that are configured to use the available screens as a | 
|---|
| 77 | single, large virtual desktop, the virtualDesktop property will be | 
|---|
| 78 | set to true. In this case, the widget's size is usually the size of | 
|---|
| 79 | the bounding rectangle of all the screens. | 
|---|
| 80 |  | 
|---|
| 81 | \section1 Use of the Primary Screen | 
|---|
| 82 |  | 
|---|
| 83 | For an application, the screen where the main widget resides is the | 
|---|
| 84 | primary screen. This is stored in the primaryScreen property. | 
|---|
| 85 | All windows opened in the context of the application should be | 
|---|
| 86 | constrained to the boundaries of the primary screen; for example, | 
|---|
| 87 | it would be inconvenient if a dialog box popped up on a different | 
|---|
| 88 | screen, or split over two screens. | 
|---|
| 89 |  | 
|---|
| 90 | \image qdesktopwidget.png Managing Multiple Screens | 
|---|
| 91 |  | 
|---|
| 92 | In the illustration above, Application One's primary screen is | 
|---|
| 93 | screen 0, and App Two's primary screen is screen 1. | 
|---|
| 94 |  | 
|---|
| 95 | \sa QApplication, QApplication::desktop(), QX11Info::appRootWindow() | 
|---|
| 96 | */ | 
|---|
| 97 |  | 
|---|
| 98 | /*! | 
|---|
| 99 | \fn QDesktopWidget::QDesktopWidget() | 
|---|
| 100 |  | 
|---|
| 101 | \internal | 
|---|
| 102 |  | 
|---|
| 103 | Creates the desktop widget. | 
|---|
| 104 |  | 
|---|
| 105 | If the system supports a virtual desktop, this widget will have | 
|---|
| 106 | the size of the virtual desktop; otherwise this widget will have | 
|---|
| 107 | the size of the primary screen. | 
|---|
| 108 |  | 
|---|
| 109 | Instead of using QDesktopWidget directly, use QApplication::desktop(). | 
|---|
| 110 | */ | 
|---|
| 111 |  | 
|---|
| 112 | /*! | 
|---|
| 113 | \fn QDesktopWidget::~QDesktopWidget() | 
|---|
| 114 |  | 
|---|
| 115 | \internal | 
|---|
| 116 |  | 
|---|
| 117 | Destroys the desktop widget and frees any allocated resources. | 
|---|
| 118 | */ | 
|---|
| 119 |  | 
|---|
| 120 | /*! | 
|---|
| 121 | \fn int QDesktopWidget::numScreens() const | 
|---|
| 122 |  | 
|---|
| 123 | Returns the number of available screens. | 
|---|
| 124 |  | 
|---|
| 125 | \obsolete | 
|---|
| 126 |  | 
|---|
| 127 | This function is deprecated. Use screenCount instead. | 
|---|
| 128 |  | 
|---|
| 129 | \sa primaryScreen | 
|---|
| 130 | */ | 
|---|
| 131 |  | 
|---|
| 132 | /*! | 
|---|
| 133 | \fn QWidget *QDesktopWidget::screen(int screen) | 
|---|
| 134 |  | 
|---|
| 135 | Returns a widget that represents the screen with index \a screen | 
|---|
| 136 | (a value of -1 means the default screen). | 
|---|
| 137 |  | 
|---|
| 138 | If the system uses a virtual desktop, the returned widget will | 
|---|
| 139 | have the geometry of the entire virtual desktop; i.e., bounding | 
|---|
| 140 | every \a screen. | 
|---|
| 141 |  | 
|---|
| 142 | \sa primaryScreen, screenCount, virtualDesktop | 
|---|
| 143 | */ | 
|---|
| 144 |  | 
|---|
| 145 | /*! | 
|---|
| 146 | \fn const QRect QDesktopWidget::availableGeometry(int screen) const | 
|---|
| 147 |  | 
|---|
| 148 | Returns the available geometry of the screen with index \a screen. What | 
|---|
| 149 | is available will be subrect of screenGeometry() based on what the | 
|---|
| 150 | platform decides is available (for example excludes the dock and menu bar | 
|---|
| 151 | on Mac OS X, or the task bar on Windows). The default screen is used if | 
|---|
| 152 | \a screen is -1. | 
|---|
| 153 |  | 
|---|
| 154 | \sa screenNumber(), screenGeometry() | 
|---|
| 155 | */ | 
|---|
| 156 |  | 
|---|
| 157 | /*! | 
|---|
| 158 | \fn const QRect QDesktopWidget::availableGeometry(const QWidget *widget) const | 
|---|
| 159 | \overload | 
|---|
| 160 |  | 
|---|
| 161 | Returns the available geometry of the screen which contains \a widget. | 
|---|
| 162 |  | 
|---|
| 163 | \sa screenGeometry() | 
|---|
| 164 | */ | 
|---|
| 165 |  | 
|---|
| 166 | /*! | 
|---|
| 167 | \fn const QRect QDesktopWidget::availableGeometry(const QPoint &p) const | 
|---|
| 168 | \overload | 
|---|
| 169 |  | 
|---|
| 170 | Returns the available geometry of the screen which contains \a p. | 
|---|
| 171 |  | 
|---|
| 172 | \sa screenGeometry() | 
|---|
| 173 | */ | 
|---|
| 174 |  | 
|---|
| 175 |  | 
|---|
| 176 | /*! | 
|---|
| 177 | \fn const QRect QDesktopWidget::screenGeometry(int screen) const | 
|---|
| 178 |  | 
|---|
| 179 | Returns the geometry of the screen with index \a screen. The default | 
|---|
| 180 | screen is used if \a screen is -1. | 
|---|
| 181 |  | 
|---|
| 182 | \sa screenNumber() | 
|---|
| 183 | */ | 
|---|
| 184 |  | 
|---|
| 185 | /*! | 
|---|
| 186 | \fn const QRect QDesktopWidget::screenGeometry(const QWidget *widget) const | 
|---|
| 187 | \overload | 
|---|
| 188 |  | 
|---|
| 189 | Returns the geometry of the screen which contains \a widget. | 
|---|
| 190 | */ | 
|---|
| 191 |  | 
|---|
| 192 | /*! | 
|---|
| 193 | \fn const QRect QDesktopWidget::screenGeometry(const QPoint &p) const | 
|---|
| 194 | \overload | 
|---|
| 195 |  | 
|---|
| 196 | Returns the geometry of the screen which contains \a p. | 
|---|
| 197 | */ | 
|---|
| 198 |  | 
|---|
| 199 |  | 
|---|
| 200 | /*! | 
|---|
| 201 | \fn int QDesktopWidget::screenNumber(const QWidget *widget) const | 
|---|
| 202 |  | 
|---|
| 203 | Returns the index of the screen that contains the largest | 
|---|
| 204 | part of \a widget, or -1 if the widget not on a screen. | 
|---|
| 205 |  | 
|---|
| 206 | \sa primaryScreen | 
|---|
| 207 | */ | 
|---|
| 208 |  | 
|---|
| 209 | /*! | 
|---|
| 210 | \fn int QDesktopWidget::screenNumber(const QPoint &point) const | 
|---|
| 211 |  | 
|---|
| 212 | \overload | 
|---|
| 213 | Returns the index of the screen that contains the \a point, or the | 
|---|
| 214 | screen which is the shortest distance from the \a point. | 
|---|
| 215 |  | 
|---|
| 216 | \sa primaryScreen | 
|---|
| 217 | */ | 
|---|
| 218 |  | 
|---|
| 219 | /*! | 
|---|
| 220 | \fn void QDesktopWidget::resizeEvent(QResizeEvent *event) | 
|---|
| 221 | \reimp | 
|---|
| 222 | */ | 
|---|
| 223 |  | 
|---|
| 224 | /*! | 
|---|
| 225 | \fn void QDesktopWidget::resized(int screen) | 
|---|
| 226 |  | 
|---|
| 227 | This signal is emitted when the size of \a screen changes. | 
|---|
| 228 | */ | 
|---|
| 229 |  | 
|---|
| 230 | /*! | 
|---|
| 231 | \fn void QDesktopWidget::workAreaResized(int screen) | 
|---|
| 232 |  | 
|---|
| 233 | This signal is emitted when the work area available on \a screen changes. | 
|---|
| 234 | */ | 
|---|
| 235 |  | 
|---|
| 236 | /*! | 
|---|
| 237 | \property QDesktopWidget::screenCount | 
|---|
| 238 | \brief the number of screens currently available on the system. | 
|---|
| 239 |  | 
|---|
| 240 | \since 4.6 | 
|---|
| 241 |  | 
|---|
| 242 | \sa screenCountChanged() | 
|---|
| 243 | */ | 
|---|
| 244 |  | 
|---|
| 245 | /*! | 
|---|
| 246 | \property QDesktopWidget::primaryScreen | 
|---|
| 247 | \brief the index of the screen that is configured to be the primary screen | 
|---|
| 248 | on the system. | 
|---|
| 249 | */ | 
|---|
| 250 |  | 
|---|
| 251 | /*! | 
|---|
| 252 | \property QDesktopWidget::virtualDesktop | 
|---|
| 253 |  | 
|---|
| 254 | \brief if the system manages the available screens in a virtual desktop. | 
|---|
| 255 |  | 
|---|
| 256 | For virtual desktops, screen() will always return the same widget. | 
|---|
| 257 | The size of the virtual desktop is the size of this desktop | 
|---|
| 258 | widget. | 
|---|
| 259 | */ | 
|---|
| 260 |  | 
|---|
| 261 | /*! | 
|---|
| 262 | \fn void QDesktopWidget::screenCountChanged(int newCount) | 
|---|
| 263 |  | 
|---|
| 264 | \since 4.6 | 
|---|
| 265 |  | 
|---|
| 266 | This signal is emitted when the number of screens changes to \a newCount. | 
|---|
| 267 |  | 
|---|
| 268 | \sa screenCount | 
|---|
| 269 | */ | 
|---|