source: trunk/src/gui/embedded/qscreenmulti_qws.cpp@ 855

Last change on this file since 855 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 12.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 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 "qscreenmulti_qws_p.h"
43
44#ifndef QT_NO_QWS_MULTISCREEN
45
46#include <qlist.h>
47#include <qstringlist.h>
48#include <qwidget.h>
49#include <qdebug.h>
50
51QT_BEGIN_NAMESPACE
52
53#ifndef QT_NO_QWS_CURSOR
54
55class QMultiScreenCursor : public QScreenCursor
56{
57public:
58 QMultiScreenCursor() : currentCursor(qt_screencursor) { enable = false; }
59 ~QMultiScreenCursor() { qt_screencursor = 0; }
60
61 void set(const QImage &image, int hotx, int hoty);
62 void move(int x, int y);
63 void show();
64 void hide();
65
66 void addCursor(QScreenCursor *cursor);
67
68private:
69 void setCurrentCursor(QScreenCursor *newCursor);
70
71 QScreenCursor *currentCursor;
72 QList<QScreenCursor*> cursors;
73};
74
75void QMultiScreenCursor::set(const QImage &image, int hotx, int hoty)
76{
77 QScreenCursor::set(image, hotx, hoty);
78 if (currentCursor)
79 currentCursor->set(image, hotx, hoty);
80}
81
82void QMultiScreenCursor::setCurrentCursor(QScreenCursor *newCursor)
83{
84 *((QScreenCursor*)this) = *newCursor;
85 currentCursor = newCursor;
86}
87
88// XXX: this is a mess!
89void QMultiScreenCursor::move(int x, int y)
90{
91 const int oldIndex = qt_screen->subScreenIndexAt(pos);
92 QScreenCursor::move(x, y); // updates pos
93 const int newIndex = qt_screen->subScreenIndexAt(pos);
94
95 if (!currentCursor && oldIndex != -1)
96 setCurrentCursor(cursors.at(oldIndex));
97 QScreenCursor *oldCursor = currentCursor;
98
99 if (oldIndex != -1) {
100 const QScreen *oldScreen = qt_screen->subScreens().at(oldIndex);
101 if (newIndex == -1 || oldScreen->region().contains(pos)) {
102 oldCursor->move(x, y);
103 return;
104 }
105 }
106
107 if (newIndex != -1) {
108 QScreenCursor *newCursor = cursors.at(newIndex);
109 newCursor->set(cursor, hotspot.x(), hotspot.y());
110
111 if (oldCursor) {
112 if (oldCursor->isVisible())
113 newCursor->show();
114 oldCursor->hide();
115 }
116
117 newCursor->move(x, y);
118
119 setCurrentCursor(newCursor);
120 }
121}
122
123void QMultiScreenCursor::show()
124{
125 if (currentCursor)
126 currentCursor->show();
127}
128
129void QMultiScreenCursor::hide()
130{
131 if (currentCursor)
132 currentCursor->hide();
133}
134
135void QMultiScreenCursor::addCursor(QScreenCursor *cursor)
136{
137 cursors.append(cursor);
138}
139
140#endif
141
142class QMultiScreenPrivate
143{
144public:
145 QMultiScreenPrivate()
146#ifndef QT_NO_QWS_CURSOR
147 : cursor(0)
148#endif
149 {}
150 ~QMultiScreenPrivate()
151 {
152#ifndef QT_NO_QWS_CURSOR
153 delete cursor;
154#endif
155 }
156
157 QList<QScreen*> screens;
158 QRegion region;
159#ifndef QT_NO_QWS_CURSOR
160 QMultiScreenCursor *cursor;
161#endif
162};
163
164QMultiScreen::QMultiScreen(int displayId)
165 : QScreen(displayId, MultiClass), d_ptr(new QMultiScreenPrivate)
166{
167}
168
169QMultiScreen::~QMultiScreen()
170{
171 delete d_ptr;
172}
173
174bool QMultiScreen::initDevice()
175{
176 bool ok = true;
177
178#ifndef QT_NO_QWS_CURSOR
179 d_ptr->cursor = new QMultiScreenCursor;
180#endif
181
182 const int n = d_ptr->screens.count();
183 for (int i = 0; i < n; ++i) {
184 QScreen *s = d_ptr->screens.at(i);
185 ok = s->initDevice() && ok;
186#ifndef QT_NO_QWS_CURSOR
187 d_ptr->cursor->addCursor(qt_screencursor); // XXX
188#endif
189 }
190
191#ifndef QT_NO_QWS_CURSOR
192 // XXX
193 qt_screencursor = d_ptr->cursor;
194#endif
195
196 return ok;
197}
198
199static int getDisplayId(const QString &spec)
200{
201 QRegExp regexp(QLatin1String(":(\\d+)\\b"));
202 if (regexp.lastIndexIn(spec) != -1) {
203 const QString capture = regexp.cap(1);
204 return capture.toInt();
205 }
206 return 0;
207}
208
209static QPoint filterDisplayOffset(QString &spec)
210{
211 QRegExp regexp(QLatin1String(":offset=(\\d+),(\\d+)\\b"));
212 if (regexp.indexIn(spec) == -1)
213 return QPoint();
214
215 const int x = regexp.cap(1).toInt();
216 const int y = regexp.cap(2).toInt();
217 spec.remove(regexp.pos(0), regexp.matchedLength());
218 return QPoint(x, y);
219}
220
221bool QMultiScreen::connect(const QString &displaySpec)
222{
223 QString dSpec = displaySpec;
224 if (dSpec.startsWith(QLatin1String("Multi:"), Qt::CaseInsensitive))
225 dSpec = dSpec.mid(QString::fromLatin1("Multi:").size());
226
227 const QString displayIdSpec = QString::fromLatin1(" :%1").arg(displayId);
228 if (dSpec.endsWith(displayIdSpec))
229 dSpec = dSpec.left(dSpec.size() - displayIdSpec.size());
230
231 QStringList specs = dSpec.split(QLatin1Char(' '), QString::SkipEmptyParts);
232 foreach (QString spec, specs) {
233 const int id = getDisplayId(spec);
234 if (spec.startsWith("vnc:", Qt::CaseInsensitive)) {
235 spec.append(":noDisablePainting");
236 }
237 const QPoint offset = filterDisplayOffset(spec);
238 QScreen *s = qt_get_screen(id, spec.toLatin1().constData());
239 s->setOffset(offset);
240 addSubScreen(s);
241 }
242
243 QScreen *firstScreen = d_ptr->screens.at(0);
244 Q_ASSERT(firstScreen);
245
246 // XXX
247 QScreen::d = firstScreen->depth();
248
249 QScreen::lstep = 0;
250 QScreen::data = 0;
251 QScreen::size = 0;
252
253 QScreen::w = d_ptr->region.boundingRect().width();
254 QScreen::h = d_ptr->region.boundingRect().height();
255
256 QScreen::dw = QScreen::w;
257 QScreen::dh = QScreen::h;
258
259 // XXX - Extend the physical size based on the first screen
260 // to encompass all screens, so that code that uses the multi
261 // screen to calculate dpi values will get the right numbers.
262 QScreen::physWidth = firstScreen->physicalWidth() * w / firstScreen->width();
263 QScreen::physHeight = firstScreen->physicalHeight() * h / firstScreen->height();
264
265 // XXXXX
266 qt_screen = this;
267
268 return true;
269}
270
271void QMultiScreen::disconnect()
272{
273 const int n = d_ptr->screens.size();
274 for (int i = 0; i < n; ++i)
275 d_ptr->screens.at(i)->disconnect();
276}
277
278void QMultiScreen::shutdownDevice()
279{
280 const int n = d_ptr->screens.size();
281 for (int i = 0; i < n; ++i)
282 d_ptr->screens.at(i)->shutdownDevice();
283}
284
285void QMultiScreen::setMode(int, int, int)
286{
287 return;
288}
289
290bool QMultiScreen::supportsDepth(int) const
291{
292 return false;
293}
294
295void QMultiScreen::save()
296{
297 const int n = d_ptr->screens.size();
298 for (int i = 0; i < n; ++i)
299 d_ptr->screens.at(i)->save();
300}
301
302void QMultiScreen::restore()
303{
304 const int n = d_ptr->screens.size();
305 for (int i = 0; i < n; ++i)
306 d_ptr->screens.at(i)->restore();
307}
308
309void QMultiScreen::blank(bool on)
310{
311 const int n = d_ptr->screens.size();
312 for (int i = 0; i < n; ++i)
313 d_ptr->screens.at(i)->blank(on);
314}
315
316bool QMultiScreen::onCard(const unsigned char *ptr) const
317{
318 const int n = d_ptr->screens.size();
319 for (int i = 0; i < n; ++i)
320 if (d_ptr->screens.at(i)->onCard(ptr))
321 return true;
322 return false;
323}
324
325bool QMultiScreen::onCard(const unsigned char *ptr, ulong &offset) const
326{
327 const int n = d_ptr->screens.size();
328 for (int i = 0; i < n; ++i)
329 if (d_ptr->screens.at(i)->onCard(ptr, offset))
330 return true;
331 return false;
332}
333
334bool QMultiScreen::isInterlaced() const
335{
336 const int n = d_ptr->screens.size();
337 for (int i = 0; i < n; ++i)
338 if (d_ptr->screens.at(i)->isInterlaced())
339 return true;
340
341 return false;
342}
343
344int QMultiScreen::memoryNeeded(const QString &string)
345{
346 int total = 0;
347 const int n = d_ptr->screens.size();
348 for (int i = 0; i < n; ++i)
349 total += d_ptr->screens.at(i)->memoryNeeded(string);
350 return total;
351}
352
353int QMultiScreen::sharedRamSize(void *arg)
354{
355 int total = 0;
356 const int n = d_ptr->screens.size();
357 for (int i = 0; i < n; ++i)
358 total += d_ptr->screens.at(i)->sharedRamSize(arg);
359 return total;
360}
361
362void QMultiScreen::haltUpdates()
363{
364 const int n = d_ptr->screens.size();
365 for (int i = 0; i < n; ++i)
366 d_ptr->screens.at(i)->haltUpdates();
367}
368
369void QMultiScreen::resumeUpdates()
370{
371 const int n = d_ptr->screens.size();
372 for (int i = 0; i < n; ++i)
373 d_ptr->screens.at(i)->resumeUpdates();
374}
375
376void QMultiScreen::exposeRegion(QRegion region, int changing)
377{
378 const int n = d_ptr->screens.size();
379 for (int i = 0; i < n; ++i) {
380 QScreen *screen = d_ptr->screens.at(i);
381 const QRegion r = region & screen->region();
382 if (r.isEmpty())
383 continue;
384 screen->exposeRegion(r, changing);
385 }
386}
387
388void QMultiScreen::solidFill(const QColor &color, const QRegion &region)
389{
390 const int n = d_ptr->screens.size();
391 for (int i = 0; i < n; ++i) {
392 QScreen *screen = d_ptr->screens.at(i);
393 const QRegion r = region & screen->region();
394 if (r.isEmpty())
395 continue;
396 screen->solidFill(color, r);
397 }
398}
399
400void QMultiScreen::blit(const QImage &img, const QPoint &topLeft,
401 const QRegion &region)
402{
403 const int n = d_ptr->screens.size();
404 for (int i = 0; i < n; ++i) {
405 QScreen *screen = d_ptr->screens.at(i);
406 const QRegion r = region & screen->region();
407 if (r.isEmpty())
408 continue;
409 screen->blit(img, topLeft, r);
410 }
411}
412
413void QMultiScreen::blit(QWSWindow *bs, const QRegion &clip)
414{
415 const int n = d_ptr->screens.size();
416 for (int i = 0; i < n; ++i) {
417 QScreen *screen = d_ptr->screens.at(i);
418 const QRegion r = clip & screen->region();
419 if (r.isEmpty())
420 continue;
421 screen->blit(bs, r);
422 }
423}
424
425void QMultiScreen::setDirty(const QRect &rect)
426{
427 const int n = d_ptr->screens.size();
428 for (int i = 0; i < n; ++i) {
429 QScreen *screen = d_ptr->screens.at(i);
430 const QRegion r = screen->region() & rect;
431 if (r.isEmpty())
432 continue;
433 screen->setDirty(r.boundingRect());
434 }
435}
436
437
438QWSWindowSurface* QMultiScreen::createSurface(const QString &key) const
439{
440 QWSWindowSurface* surf = 0;
441 const int n = d_ptr->screens.size();
442 for (int i = 0; i < n; ++i) {
443 QScreen *screen = d_ptr->screens.at(i);
444 surf = screen->createSurface(key);
445 if (surf)
446 break;
447 }
448 return surf;
449}
450
451
452QWSWindowSurface* QMultiScreen::createSurface(QWidget *widget) const
453{
454 const QPoint midpoint = (widget->frameGeometry().topLeft()
455 + widget->frameGeometry().bottomRight()) / 2;
456 int index = subScreenIndexAt(midpoint);
457 if (index == -1)
458 index = 0; // XXX
459 return d_ptr->screens.at(index)->createSurface(widget);
460}
461
462QList<QScreen*> QMultiScreen::subScreens() const
463{
464 return d_ptr->screens;
465}
466
467QRegion QMultiScreen::region() const
468{
469 return d_ptr->region;
470}
471
472void QMultiScreen::addSubScreen(QScreen *screen)
473{
474 d_ptr->screens.append(screen);
475 d_ptr->region += screen->region();
476}
477
478void QMultiScreen::removeSubScreen(QScreen *screen)
479{
480 d_ptr->screens.removeAll(screen);
481 d_ptr->region -= screen->region();
482}
483
484QT_END_NAMESPACE
485
486#endif // QT_NO_QWS_MULTISCREEN
Note: See TracBrowser for help on using the repository browser.