1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
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 "qapplication_p.h"
|
---|
44 | #include "qwidget_p.h"
|
---|
45 | #include "qt_s60_p.h"
|
---|
46 | #include <w32std.h>
|
---|
47 |
|
---|
48 | #include "hal.h"
|
---|
49 | #include "hal_data.h"
|
---|
50 |
|
---|
51 | QT_BEGIN_NAMESPACE
|
---|
52 |
|
---|
53 | class QDesktopWidgetPrivate : public QWidgetPrivate
|
---|
54 | {
|
---|
55 |
|
---|
56 | public:
|
---|
57 | QDesktopWidgetPrivate();
|
---|
58 | ~QDesktopWidgetPrivate();
|
---|
59 |
|
---|
60 | static void init(QDesktopWidget *that);
|
---|
61 | static void cleanup();
|
---|
62 |
|
---|
63 | static int screenCount;
|
---|
64 | static int primaryScreen;
|
---|
65 |
|
---|
66 | static QVector<QRect> *rects;
|
---|
67 | static QVector<QRect> *workrects;
|
---|
68 |
|
---|
69 | static int refcount;
|
---|
70 | };
|
---|
71 |
|
---|
72 | int QDesktopWidgetPrivate::screenCount = 1;
|
---|
73 | int QDesktopWidgetPrivate::primaryScreen = 0;
|
---|
74 | QVector<QRect> *QDesktopWidgetPrivate::rects = 0;
|
---|
75 | QVector<QRect> *QDesktopWidgetPrivate::workrects = 0;
|
---|
76 | int QDesktopWidgetPrivate::refcount = 0;
|
---|
77 |
|
---|
78 | QDesktopWidgetPrivate::QDesktopWidgetPrivate()
|
---|
79 | {
|
---|
80 | ++refcount;
|
---|
81 | }
|
---|
82 |
|
---|
83 | QDesktopWidgetPrivate::~QDesktopWidgetPrivate()
|
---|
84 | {
|
---|
85 | if (!--refcount)
|
---|
86 | cleanup();
|
---|
87 | }
|
---|
88 |
|
---|
89 | void QDesktopWidgetPrivate::init(QDesktopWidget *that)
|
---|
90 | {
|
---|
91 | int screenCount=0;
|
---|
92 |
|
---|
93 | if (HAL::Get(0, HALData::EDisplayNumberOfScreens, screenCount) == KErrNone)
|
---|
94 | QDesktopWidgetPrivate::screenCount = screenCount;
|
---|
95 | else
|
---|
96 | QDesktopWidgetPrivate::screenCount = 0;
|
---|
97 |
|
---|
98 | rects = new QVector<QRect>();
|
---|
99 | workrects = new QVector<QRect>();
|
---|
100 |
|
---|
101 | rects->resize(QDesktopWidgetPrivate::screenCount);
|
---|
102 | workrects->resize(QDesktopWidgetPrivate::screenCount);
|
---|
103 |
|
---|
104 | // ### TODO: Implement proper multi-display support
|
---|
105 | rects->resize(1);
|
---|
106 | rects->replace(0, that->rect());
|
---|
107 | workrects->resize(1);
|
---|
108 | workrects->replace(0, that->rect());
|
---|
109 | }
|
---|
110 |
|
---|
111 | void QDesktopWidgetPrivate::cleanup()
|
---|
112 | {
|
---|
113 | delete rects;
|
---|
114 | rects = 0;
|
---|
115 | delete workrects;
|
---|
116 | workrects = 0;
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | QDesktopWidget::QDesktopWidget()
|
---|
121 | : QWidget(*new QDesktopWidgetPrivate, 0, Qt::Desktop)
|
---|
122 | {
|
---|
123 | setObjectName(QLatin1String("desktop"));
|
---|
124 | QDesktopWidgetPrivate::init(this);
|
---|
125 | }
|
---|
126 |
|
---|
127 | QDesktopWidget::~QDesktopWidget()
|
---|
128 | {
|
---|
129 | }
|
---|
130 |
|
---|
131 | bool QDesktopWidget::isVirtualDesktop() const
|
---|
132 | {
|
---|
133 | return true;
|
---|
134 | }
|
---|
135 |
|
---|
136 | int QDesktopWidget::primaryScreen() const
|
---|
137 | {
|
---|
138 | return QDesktopWidgetPrivate::primaryScreen;
|
---|
139 | }
|
---|
140 |
|
---|
141 | int QDesktopWidget::numScreens() const
|
---|
142 | {
|
---|
143 | Q_D(const QDesktopWidget);
|
---|
144 | return QDesktopWidgetPrivate::screenCount;
|
---|
145 | }
|
---|
146 |
|
---|
147 | QWidget *QDesktopWidget::screen(int /* screen */)
|
---|
148 | {
|
---|
149 | return this;
|
---|
150 | }
|
---|
151 |
|
---|
152 | const QRect QDesktopWidget::availableGeometry(int /* screen */) const
|
---|
153 | {
|
---|
154 | TRect clientRect = static_cast<CEikAppUi*>(S60->appUi())->ClientRect();
|
---|
155 | return qt_TRect2QRect(clientRect);
|
---|
156 | }
|
---|
157 |
|
---|
158 | const QRect QDesktopWidget::screenGeometry(int /* screen */) const
|
---|
159 | {
|
---|
160 | Q_D(const QDesktopWidget);
|
---|
161 | return QRect(0, 0, S60->screenWidthInPixels, S60->screenHeightInPixels);
|
---|
162 | }
|
---|
163 |
|
---|
164 | int QDesktopWidget::screenNumber(const QWidget * /* widget */) const
|
---|
165 | {
|
---|
166 | return QDesktopWidgetPrivate::primaryScreen;
|
---|
167 | }
|
---|
168 |
|
---|
169 | int QDesktopWidget::screenNumber(const QPoint & /* point */) const
|
---|
170 | {
|
---|
171 | return QDesktopWidgetPrivate::primaryScreen;
|
---|
172 | }
|
---|
173 |
|
---|
174 | void QDesktopWidget::resizeEvent(QResizeEvent *)
|
---|
175 | {
|
---|
176 | Q_D(QDesktopWidget);
|
---|
177 | QVector<QRect> oldrects;
|
---|
178 | oldrects = *d->rects;
|
---|
179 | QVector<QRect> oldworkrects;
|
---|
180 | oldworkrects = *d->workrects;
|
---|
181 | int oldscreencount = d->screenCount;
|
---|
182 |
|
---|
183 | QDesktopWidgetPrivate::cleanup();
|
---|
184 | QDesktopWidgetPrivate::init(this);
|
---|
185 |
|
---|
186 | for (int i = 0; i < qMin(oldscreencount, d->screenCount); ++i) {
|
---|
187 | QRect oldrect = oldrects[i];
|
---|
188 | QRect newrect = d->rects->at(i);
|
---|
189 | if (oldrect != newrect)
|
---|
190 | emit resized(i);
|
---|
191 | }
|
---|
192 |
|
---|
193 | for (int j = 0; j < qMin(oldscreencount, d->screenCount); ++j) {
|
---|
194 | QRect oldrect = oldworkrects[j];
|
---|
195 | QRect newrect = d->workrects->at(j);
|
---|
196 | if (oldrect != newrect)
|
---|
197 | emit workAreaResized(j);
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 | QT_END_NAMESPACE
|
---|