[556] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[651] | 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[556] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
| 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 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
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
| 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
| 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 |
|
---|
| 50 | QDesktopWidget::QDesktopWidget()
|
---|
| 51 | : QWidget(0, Qt::Desktop)
|
---|
| 52 | {
|
---|
| 53 | setObjectName(QLatin1String("desktop"));
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | QDesktopWidget::~QDesktopWidget()
|
---|
| 57 | {
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | bool QDesktopWidget::isVirtualDesktop() const
|
---|
| 61 | {
|
---|
| 62 | return true;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | int QDesktopWidget::primaryScreen() const
|
---|
| 66 | {
|
---|
| 67 | return 0;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | int 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 |
|
---|
| 80 | QWidget *QDesktopWidget::screen(int)
|
---|
| 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 |
|
---|
| 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 |
|
---|
| 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 |
|
---|
| 155 | void QDesktopWidget::resizeEvent(QResizeEvent *)
|
---|
| 156 | {
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | QT_END_NAMESPACE
|
---|