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);