1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 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 The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 37 ** 38 ** $QT_END_LICENSE$ 39 ** 40 ****************************************************************************/ 41 42 #include "qdesktopwidget.h" 43 #include "qscreen_qws.h" 44 #include "private/qapplication_p.h" 45 46 QT_BEGIN_NAMESPACE 47 48 QT_USE_NAMESPACE 49 QDesktopWidget()50QDesktopWidget::QDesktopWidget() 51 : QWidget(0, Qt::Desktop) 52 { 53 setObjectName(QLatin1String("desktop")); 54 } 55 ~QDesktopWidget()56QDesktopWidget::~QDesktopWidget() 57 { 58 } 59 isVirtualDesktop() const60bool QDesktopWidget::isVirtualDesktop() const 61 { 62 return true; 63 } 64 primaryScreen() const65int QDesktopWidget::primaryScreen() const 66 { 67 return 0; 68 } 69 numScreens() const70int QDesktopWidget::numScreens() const 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 screen(int)80QWidget *QDesktopWidget::screen(int) 81 { 82 return this; 83 } 84 availableGeometry(int screenNo) const85const 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 100 QApplicationPrivate *ap = QApplicationPrivate::instance(); 101 const QRect r = ap->maxWindowRect(screen); 102 if (!r.isEmpty()) 103 return r; 104 105 return screen->region().boundingRect(); 106 } 107 screenGeometry(int screenNo) const108const 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 screenNumber(const QWidget * w) const126int 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 screenNumber(const QPoint & p) const138int 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 resizeEvent(QResizeEvent *)155void QDesktopWidget::resizeEvent(QResizeEvent *) 156 { 157 } 158 159 QT_END_NAMESPACE 160