Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/platformsupport/fbconvenience/qfbcursor.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 plugins of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
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 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include "qfbcursor_p.h" | - | ||||||||||||
35 | #include "qfbscreen_p.h" | - | ||||||||||||
36 | #include <QtGui/QPainter> | - | ||||||||||||
37 | #include <QtGui/private/qguiapplication_p.h> | - | ||||||||||||
38 | - | |||||||||||||
39 | QT_BEGIN_NAMESPACE | - | ||||||||||||
40 | - | |||||||||||||
41 | bool QFbCursorDeviceListener::hasMouse() const | - | ||||||||||||
42 | { | - | ||||||||||||
43 | return QGuiApplicationPrivate::inputDeviceManager()->deviceCount(QInputDeviceManager::DeviceTypePointer) > 0; never executed: return QGuiApplicationPrivate::inputDeviceManager()->deviceCount(QInputDeviceManager::DeviceTypePointer) > 0; | 0 | ||||||||||||
44 | } | - | ||||||||||||
45 | - | |||||||||||||
46 | void QFbCursorDeviceListener::onDeviceListChanged(QInputDeviceManager::DeviceType type) | - | ||||||||||||
47 | { | - | ||||||||||||
48 | if (type == QInputDeviceManager::DeviceTypePointer)
| 0 | ||||||||||||
49 | m_cursor->updateMouseStatus(); never executed: m_cursor->updateMouseStatus(); | 0 | ||||||||||||
50 | } never executed: end of block | 0 | ||||||||||||
51 | - | |||||||||||||
52 | QFbCursor::QFbCursor(QFbScreen *screen) | - | ||||||||||||
53 | : mVisible(true), | - | ||||||||||||
54 | mScreen(screen), | - | ||||||||||||
55 | mDirty(false), | - | ||||||||||||
56 | mOnScreen(false), | - | ||||||||||||
57 | mGraphic(0), | - | ||||||||||||
58 | mDeviceListener(0) | - | ||||||||||||
59 | { | - | ||||||||||||
60 | QByteArray hideCursorVal = qgetenv("QT_QPA_FB_HIDECURSOR"); | - | ||||||||||||
61 | if (!hideCursorVal.isEmpty())
| 0 | ||||||||||||
62 | mVisible = hideCursorVal.toInt() == 0; never executed: mVisible = hideCursorVal.toInt() == 0; | 0 | ||||||||||||
63 | if (!mVisible)
| 0 | ||||||||||||
64 | return; never executed: return; | 0 | ||||||||||||
65 | - | |||||||||||||
66 | mGraphic = new QPlatformCursorImage(0, 0, 0, 0, 0, 0); | - | ||||||||||||
67 | setCursor(Qt::ArrowCursor); | - | ||||||||||||
68 | - | |||||||||||||
69 | mDeviceListener = new QFbCursorDeviceListener(this); | - | ||||||||||||
70 | connect(QGuiApplicationPrivate::inputDeviceManager(), &QInputDeviceManager::deviceListChanged, | - | ||||||||||||
71 | mDeviceListener, &QFbCursorDeviceListener::onDeviceListChanged); | - | ||||||||||||
72 | updateMouseStatus(); | - | ||||||||||||
73 | } never executed: end of block | 0 | ||||||||||||
74 | - | |||||||||||||
75 | QFbCursor::~QFbCursor() | - | ||||||||||||
76 | { | - | ||||||||||||
77 | delete mDeviceListener; | - | ||||||||||||
78 | } never executed: end of block | 0 | ||||||||||||
79 | - | |||||||||||||
80 | QRect QFbCursor::getCurrentRect() | - | ||||||||||||
81 | { | - | ||||||||||||
82 | QRect rect = mGraphic->image()->rect().translated(-mGraphic->hotspot().x(), | - | ||||||||||||
83 | -mGraphic->hotspot().y()); | - | ||||||||||||
84 | rect.translate(m_pos); | - | ||||||||||||
85 | QPoint mScreenOffset = mScreen->geometry().topLeft(); | - | ||||||||||||
86 | rect.translate(-mScreenOffset); // global to local translation | - | ||||||||||||
87 | return rect; never executed: return rect; | 0 | ||||||||||||
88 | } | - | ||||||||||||
89 | - | |||||||||||||
90 | QPoint QFbCursor::pos() const | - | ||||||||||||
91 | { | - | ||||||||||||
92 | return m_pos; never executed: return m_pos; | 0 | ||||||||||||
93 | } | - | ||||||||||||
94 | - | |||||||||||||
95 | void QFbCursor::setPos(const QPoint &pos) | - | ||||||||||||
96 | { | - | ||||||||||||
97 | QGuiApplicationPrivate::inputDeviceManager()->setCursorPos(pos); | - | ||||||||||||
98 | m_pos = pos; | - | ||||||||||||
99 | mCurrentRect = getCurrentRect(); | - | ||||||||||||
100 | if (mOnScreen || mScreen->geometry().intersects(mCurrentRect.translated(mScreen->geometry().topLeft())))
| 0 | ||||||||||||
101 | setDirty(); never executed: setDirty(); | 0 | ||||||||||||
102 | } never executed: end of block | 0 | ||||||||||||
103 | - | |||||||||||||
104 | void QFbCursor::pointerEvent(const QMouseEvent &e) | - | ||||||||||||
105 | { | - | ||||||||||||
106 | if (e.type() != QEvent::MouseMove)
| 0 | ||||||||||||
107 | return; never executed: return; | 0 | ||||||||||||
108 | m_pos = e.screenPos().toPoint(); | - | ||||||||||||
109 | mCurrentRect = getCurrentRect(); | - | ||||||||||||
110 | if (mOnScreen || mScreen->geometry().intersects(mCurrentRect.translated(mScreen->geometry().topLeft())))
| 0 | ||||||||||||
111 | setDirty(); never executed: setDirty(); | 0 | ||||||||||||
112 | } never executed: end of block | 0 | ||||||||||||
113 | - | |||||||||||||
114 | QRect QFbCursor::drawCursor(QPainter & painter) | - | ||||||||||||
115 | { | - | ||||||||||||
116 | if (!mVisible)
| 0 | ||||||||||||
117 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||
118 | - | |||||||||||||
119 | mDirty = false; | - | ||||||||||||
120 | if (mCurrentRect.isNull())
| 0 | ||||||||||||
121 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||
122 | - | |||||||||||||
123 | // We need this because the cursor might be mDirty due to moving off mScreen | - | ||||||||||||
124 | QPoint mScreenOffset = mScreen->geometry().topLeft(); | - | ||||||||||||
125 | // global to local translation | - | ||||||||||||
126 | if (!mCurrentRect.translated(mScreenOffset).intersects(mScreen->geometry()))
| 0 | ||||||||||||
127 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||
128 | - | |||||||||||||
129 | mPrevRect = mCurrentRect; | - | ||||||||||||
130 | painter.drawImage(mPrevRect, *mGraphic->image()); | - | ||||||||||||
131 | mOnScreen = true; | - | ||||||||||||
132 | return mPrevRect; never executed: return mPrevRect; | 0 | ||||||||||||
133 | } | - | ||||||||||||
134 | - | |||||||||||||
135 | QRect QFbCursor::dirtyRect() | - | ||||||||||||
136 | { | - | ||||||||||||
137 | if (mOnScreen) {
| 0 | ||||||||||||
138 | mOnScreen = false; | - | ||||||||||||
139 | return mPrevRect; never executed: return mPrevRect; | 0 | ||||||||||||
140 | } | - | ||||||||||||
141 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||
142 | } | - | ||||||||||||
143 | - | |||||||||||||
144 | void QFbCursor::setCursor(Qt::CursorShape shape) | - | ||||||||||||
145 | { | - | ||||||||||||
146 | mGraphic->set(shape); | - | ||||||||||||
147 | } never executed: end of block | 0 | ||||||||||||
148 | - | |||||||||||||
149 | void QFbCursor::setCursor(const QImage &image, int hotx, int hoty) | - | ||||||||||||
150 | { | - | ||||||||||||
151 | mGraphic->set(image, hotx, hoty); | - | ||||||||||||
152 | } never executed: end of block | 0 | ||||||||||||
153 | - | |||||||||||||
154 | void QFbCursor::setCursor(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY) | - | ||||||||||||
155 | { | - | ||||||||||||
156 | mGraphic->set(data, mask, width, height, hotX, hotY); | - | ||||||||||||
157 | } never executed: end of block | 0 | ||||||||||||
158 | - | |||||||||||||
159 | #ifndef QT_NO_CURSOR | - | ||||||||||||
160 | void QFbCursor::changeCursor(QCursor * widgetCursor, QWindow *window) | - | ||||||||||||
161 | { | - | ||||||||||||
162 | Q_UNUSED(window); | - | ||||||||||||
163 | const Qt::CursorShape shape = widgetCursor ? widgetCursor->shape() : Qt::ArrowCursor;
| 0 | ||||||||||||
164 | - | |||||||||||||
165 | if (shape == Qt::BitmapCursor) {
| 0 | ||||||||||||
166 | // application supplied cursor | - | ||||||||||||
167 | QPoint spot = widgetCursor->hotSpot(); | - | ||||||||||||
168 | setCursor(widgetCursor->pixmap().toImage(), spot.x(), spot.y()); | - | ||||||||||||
169 | } else { never executed: end of block | 0 | ||||||||||||
170 | // system cursor | - | ||||||||||||
171 | setCursor(shape); | - | ||||||||||||
172 | } never executed: end of block | 0 | ||||||||||||
173 | mCurrentRect = getCurrentRect(); | - | ||||||||||||
174 | QPoint mScreenOffset = mScreen->geometry().topLeft(); // global to local translation | - | ||||||||||||
175 | if (mOnScreen || mScreen->geometry().intersects(mCurrentRect.translated(mScreenOffset)))
| 0 | ||||||||||||
176 | setDirty(); never executed: setDirty(); | 0 | ||||||||||||
177 | } never executed: end of block | 0 | ||||||||||||
178 | #endif | - | ||||||||||||
179 | - | |||||||||||||
180 | void QFbCursor::setDirty() | - | ||||||||||||
181 | { | - | ||||||||||||
182 | if (!mVisible)
| 0 | ||||||||||||
183 | return; never executed: return; | 0 | ||||||||||||
184 | - | |||||||||||||
185 | if (!mDirty) {
| 0 | ||||||||||||
186 | mDirty = true; | - | ||||||||||||
187 | mScreen->scheduleUpdate(); | - | ||||||||||||
188 | } never executed: end of block | 0 | ||||||||||||
189 | } never executed: end of block | 0 | ||||||||||||
190 | - | |||||||||||||
191 | void QFbCursor::updateMouseStatus() | - | ||||||||||||
192 | { | - | ||||||||||||
193 | mVisible = mDeviceListener->hasMouse(); | - | ||||||||||||
194 | mScreen->setDirty(mVisible ? getCurrentRect() : lastPainted()); | - | ||||||||||||
195 | } never executed: end of block | 0 | ||||||||||||
196 | - | |||||||||||||
197 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |