Qt 4.8
qdesktopwidget_qws.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qdesktopwidget.h"
43 #include "qscreen_qws.h"
44 #include "private/qapplication_p.h"
45 
47 
49 
51  : QWidget(0, Qt::Desktop)
52 {
53  setObjectName(QLatin1String("desktop"));
54 }
55 
57 {
58 }
59 
61 {
62  return true;
63 }
64 
66 {
67  return 0;
68 }
69 
71 {
72  QScreen *screen = QScreen::instance();
73  if (!screen)
74  return 0;
75 
76  const QList<QScreen*> subScreens = screen->subScreens();
77  return qMax(subScreens.size(), 1);
78 }
79 
81 {
82  return this;
83 }
84 
85 const QRect QDesktopWidget::availableGeometry(int screenNo) const
86 {
87  const QScreen *screen = QScreen::instance();
88  if (screenNo == -1)
89  screenNo = 0;
90  if (!screen || screenNo < 0)
91  return QRect();
92 
93  const QList<QScreen*> subScreens = screen->subScreens();
94  if (!subScreens.isEmpty()) {
95  if (screenNo >= subScreens.size())
96  return QRect();
97  screen = subScreens.at(screenNo);
98  }
99 
101  const QRect r = ap->maxWindowRect(screen);
102  if (!r.isEmpty())
103  return r;
104 
105  return screen->region().boundingRect();
106 }
107 
108 const QRect QDesktopWidget::screenGeometry(int screenNo) const
109 {
110  const QScreen *screen = QScreen::instance();
111  if (screenNo == -1)
112  screenNo = 0;
113  if (!screen || screenNo < 0)
114  return QRect();
115 
116  const QList<QScreen*> subScreens = screen->subScreens();
117  if (subScreens.size() == 0 && screenNo == 0)
118  return screen->region().boundingRect();
119 
120  if (screenNo >= subScreens.size())
121  return QRect();
122 
123  return subScreens.at(screenNo)->region().boundingRect();
124 }
125 
126 int QDesktopWidget::screenNumber(const QWidget *w) const
127 {
128  if (!w)
129  return 0;
130 
131  QRect frame = w->frameGeometry();
132  if (!w->isWindow())
133  frame.moveTopLeft(w->mapToGlobal(QPoint(0, 0)));
134  const QPoint midpoint = (frame.topLeft() + frame.bottomRight()) / 2;
135  return screenNumber(midpoint);
136 }
137 
138 int QDesktopWidget::screenNumber(const QPoint &p) const
139 {
140  const QScreen *screen = QScreen::instance();
141  if (!screen || !screen->region().contains(p))
142  return -1;
143 
144  const QList<QScreen*> subScreens = screen->subScreens();
145  if (subScreens.size() == 0)
146  return 0;
147 
148  for (int i = 0; i < subScreens.size(); ++i)
149  if (subScreens.at(i)->region().contains(p))
150  return i;
151 
152  return -1;
153 }
154 
156 {
157 }
158 
void resizeEvent(QResizeEvent *e)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
QRect maxWindowRect(const QScreen *screen) const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QRect frameGeometry
geometry of the widget relative to its parent including any window frame
Definition: qwidget.h:159
int primaryScreen() const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QApplicationPrivate * instance()
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
virtual QRegion region() const
Returns the region covered by this screen driver.
Definition: qscreen_qws.h:284
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isVirtualDesktop() const
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
bool contains(const QPoint &p) const
Returns true if the region contains the point p; otherwise returns false.
Definition: qregion.cpp:4104
static QScreen * instance()
Returns a pointer to the application&#39;s QScreen instance.
Definition: qscreen_qws.h:201
int numScreens() const
void moveTopLeft(const QPoint &p)
Moves the rectangle, leaving the top-left corner at the given position.
Definition: qrect.h:368
QWidget * screen(int screen=-1)
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
const QRect screenGeometry(int screen=-1) const
virtual QList< QScreen * > subScreens() const
Definition: qscreen_qws.h:283
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
The QScreen class is a base class for screen drivers in Qt for Embedded Linux.
Definition: qscreen_qws.h:191
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88
int screenNumber(const QWidget *widget=0) const
const QRect availableGeometry(int screen=-1) const
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288