Qt 4.8
qdesktopwidget_qpa.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 "private/qapplication_p.h"
44 #include "private/qgraphicssystem_p.h"
45 #include <QWidget>
46 #include "private/qwidget_p.h"
47 #include "private/qdesktopwidget_qpa_p.h"
49 
51 
53 {
55 
56  QList<QPlatformScreen *> screenList = QApplicationPrivate::platformIntegration()->screens();
57  int targetLength = screenList.length();
58  int currentLength = screens.length();
59 
60  // Add or remove screen widgets as necessary
61  if(currentLength > targetLength) {
62  QDesktopScreenWidget *screen;
63  while (currentLength-- > targetLength) {
64  screen = screens.takeLast();
65  delete screen;
66  }
67  }
68  else if (currentLength < targetLength) {
69  QDesktopScreenWidget *screen;
70  while (currentLength < targetLength) {
71  screen = new QDesktopScreenWidget(currentLength++);
72  screens.append(screen);
73  }
74  }
75 
76  QRegion virtualGeometry;
77 
78  // update the geometry of each screen widget
79  for (int i = 0; i < screens.length(); i++) {
80  QRect screenGeometry = screenList.at(i)->geometry();
81  screens.at(i)->setGeometry(screenGeometry);
82  virtualGeometry += screenGeometry;
83  }
84 
85  q->setGeometry(virtualGeometry.boundingRect());
86 }
87 
90 {
92  setObjectName(QLatin1String("desktop"));
93  d->updateScreenList();
94 }
95 
97 {
98 }
99 
101 {
102  return QApplicationPrivate::platformIntegration()->isVirtualDesktop();
103 }
104 
106 {
107  return 0;
108 }
109 
110 int QDesktopWidget::numScreens() const
111 {
112  QPlatformIntegration *pi = QApplicationPrivate::platformIntegration();
113  return qMax(pi->screens().size(), 1);
114 }
115 
116 QWidget *QDesktopWidget::screen(int screen)
117 {
119  if (screen < 0 || screen >= d->screens.length())
120  return d->screens.at(0);
121  return d->screens.at(screen);
122 }
123 
124 const QRect QDesktopWidget::availableGeometry(int screenNo) const
125 {
126  QPlatformIntegration *pi = QApplicationPrivate::platformIntegration();
128  if (screenNo == -1)
129  screenNo = 0;
130  if (screenNo < 0 || screenNo >= screens.size())
131  return QRect();
132  else
133  return screens[screenNo]->availableGeometry();
134 }
135 
136 const QRect QDesktopWidget::screenGeometry(int screenNo) const
137 {
138  QPlatformIntegration *pi = QApplicationPrivate::platformIntegration();
140  if (screenNo == -1)
141  screenNo = 0;
142  if (screenNo < 0 || screenNo >= screens.size())
143  return QRect();
144  else
145  return screens[screenNo]->geometry();
146 }
147 
148 int QDesktopWidget::screenNumber(const QWidget *w) const
149 {
150  if (!w)
151  return 0;
152 
153  QRect frame = w->frameGeometry();
154  if (!w->isWindow())
155  frame.moveTopLeft(w->mapToGlobal(QPoint(0, 0)));
156  const QPoint midpoint = (frame.topLeft() + frame.bottomRight()) / 2;
157  return screenNumber(midpoint);
158 }
159 
160 int QDesktopWidget::screenNumber(const QPoint &p) const
161 {
162  QPlatformIntegration *pi = QApplicationPrivate::platformIntegration();
164 
165  for (int i = 0; i < screens.size(); ++i)
166  if (screens[i]->geometry().contains(p))
167  return i;
168 
169  return primaryScreen(); //even better would be closest screen
170 }
171 
173 {
174 }
175 
double d
Definition: qnumeric_p.h:62
void resizeEvent(QResizeEvent *e)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
#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
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
#define Q_Q(Class)
Definition: qglobal.h:2483
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
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
virtual QList< QPlatformScreen * > screens() const =0
Accessor function to a list of all the screens on the current system.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
int numScreens() const
virtual QRect geometry() const =0
Reimplement in subclass to return the pixel geometry of the screen.
void moveTopLeft(const QPoint &p)
Moves the rectangle, leaving the top-left corner at the given position.
Definition: qrect.h:368
QList< QDesktopScreenWidget * > screens
QWidget * screen(int screen=-1)
The QPlatformIntegration class is the entry for WindowSystem specific functionality.
const QRect screenGeometry(int screen=-1) const
int length() const
This function is identical to count().
Definition: qlist.h:281
static QRect screenGeometry(const QWidget *widget)
Definition: qwidget_p.h:600
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
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492
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