| 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) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the plugins of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 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 https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at https://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 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include "qfbcursor_p.h" | - | ||||||||||||
| 41 | #include "qfbscreen_p.h" | - | ||||||||||||
| 42 | #include <QtGui/QPainter> | - | ||||||||||||
| 43 | #include <QtGui/private/qguiapplication_p.h> | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | bool QFbCursorDeviceListener::hasMouse() const | - | ||||||||||||
| 48 | { | - | ||||||||||||
| 49 | return QGuiApplicationPrivate::inputDeviceManager()->deviceCount(QInputDeviceManager::DeviceTypePointer) > 0; never executed: return QGuiApplicationPrivate::inputDeviceManager()->deviceCount(QInputDeviceManager::DeviceTypePointer) > 0; | 0 | ||||||||||||
| 50 | } | - | ||||||||||||
| 51 | - | |||||||||||||
| 52 | void QFbCursorDeviceListener::onDeviceListChanged(QInputDeviceManager::DeviceType type) | - | ||||||||||||
| 53 | { | - | ||||||||||||
| 54 | if (type == QInputDeviceManager::DeviceTypePointer)
| 0 | ||||||||||||
| 55 | m_cursor->updateMouseStatus(); never executed: m_cursor->updateMouseStatus(); | 0 | ||||||||||||
| 56 | } never executed: end of block | 0 | ||||||||||||
| 57 | - | |||||||||||||
| 58 | QFbCursor::QFbCursor(QFbScreen *screen) | - | ||||||||||||
| 59 | : mVisible(true), | - | ||||||||||||
| 60 | mScreen(screen), | - | ||||||||||||
| 61 | mDirty(false), | - | ||||||||||||
| 62 | mOnScreen(false), | - | ||||||||||||
| 63 | mGraphic(0), | - | ||||||||||||
| 64 | mDeviceListener(0) | - | ||||||||||||
| 65 | { | - | ||||||||||||
| 66 | QByteArray hideCursorVal = qgetenv("QT_QPA_FB_HIDECURSOR"); | - | ||||||||||||
| 67 | if (!hideCursorVal.isEmpty())
| 0 | ||||||||||||
| 68 | mVisible = hideCursorVal.toInt() == 0; never executed: mVisible = hideCursorVal.toInt() == 0; | 0 | ||||||||||||
| 69 | if (!mVisible)
| 0 | ||||||||||||
| 70 | return; never executed: return; | 0 | ||||||||||||
| 71 | - | |||||||||||||
| 72 | mGraphic = new QPlatformCursorImage(0, 0, 0, 0, 0, 0); | - | ||||||||||||
| 73 | setCursor(Qt::ArrowCursor); | - | ||||||||||||
| 74 | - | |||||||||||||
| 75 | mDeviceListener = new QFbCursorDeviceListener(this); | - | ||||||||||||
| 76 | connect(QGuiApplicationPrivate::inputDeviceManager(), &QInputDeviceManager::deviceListChanged, | - | ||||||||||||
| 77 | mDeviceListener, &QFbCursorDeviceListener::onDeviceListChanged); | - | ||||||||||||
| 78 | updateMouseStatus(); | - | ||||||||||||
| 79 | } never executed: end of block | 0 | ||||||||||||
| 80 | - | |||||||||||||
| 81 | QFbCursor::~QFbCursor() | - | ||||||||||||
| 82 | { | - | ||||||||||||
| 83 | delete mDeviceListener; | - | ||||||||||||
| 84 | } never executed: end of block | 0 | ||||||||||||
| 85 | - | |||||||||||||
| 86 | QRect QFbCursor::getCurrentRect() | - | ||||||||||||
| 87 | { | - | ||||||||||||
| 88 | QRect rect = mGraphic->image()->rect().translated(-mGraphic->hotspot().x(), | - | ||||||||||||
| 89 | -mGraphic->hotspot().y()); | - | ||||||||||||
| 90 | rect.translate(m_pos); | - | ||||||||||||
| 91 | QPoint mScreenOffset = mScreen->geometry().topLeft(); | - | ||||||||||||
| 92 | rect.translate(-mScreenOffset); // global to local translation | - | ||||||||||||
| 93 | return rect; never executed: return rect; | 0 | ||||||||||||
| 94 | } | - | ||||||||||||
| 95 | - | |||||||||||||
| 96 | QPoint QFbCursor::pos() const | - | ||||||||||||
| 97 | { | - | ||||||||||||
| 98 | return m_pos; never executed: return m_pos; | 0 | ||||||||||||
| 99 | } | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | void QFbCursor::setPos(const QPoint &pos) | - | ||||||||||||
| 102 | { | - | ||||||||||||
| 103 | QGuiApplicationPrivate::inputDeviceManager()->setCursorPos(pos); | - | ||||||||||||
| 104 | m_pos = pos; | - | ||||||||||||
| 105 | mCurrentRect = getCurrentRect(); | - | ||||||||||||
| 106 | if (mOnScreen || mScreen->geometry().intersects(mCurrentRect.translated(mScreen->geometry().topLeft())))
| 0 | ||||||||||||
| 107 | setDirty(); never executed: setDirty(); | 0 | ||||||||||||
| 108 | } never executed: end of block | 0 | ||||||||||||
| 109 | - | |||||||||||||
| 110 | void QFbCursor::pointerEvent(const QMouseEvent &e) | - | ||||||||||||
| 111 | { | - | ||||||||||||
| 112 | if (e.type() != QEvent::MouseMove)
| 0 | ||||||||||||
| 113 | return; never executed: return; | 0 | ||||||||||||
| 114 | m_pos = e.screenPos().toPoint(); | - | ||||||||||||
| 115 | mCurrentRect = getCurrentRect(); | - | ||||||||||||
| 116 | if (mOnScreen || mScreen->geometry().intersects(mCurrentRect.translated(mScreen->geometry().topLeft())))
| 0 | ||||||||||||
| 117 | setDirty(); never executed: setDirty(); | 0 | ||||||||||||
| 118 | } never executed: end of block | 0 | ||||||||||||
| 119 | - | |||||||||||||
| 120 | QRect QFbCursor::drawCursor(QPainter & painter) | - | ||||||||||||
| 121 | { | - | ||||||||||||
| 122 | if (!mVisible)
| 0 | ||||||||||||
| 123 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||
| 124 | - | |||||||||||||
| 125 | mDirty = false; | - | ||||||||||||
| 126 | if (mCurrentRect.isNull())
| 0 | ||||||||||||
| 127 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||
| 128 | - | |||||||||||||
| 129 | // We need this because the cursor might be mDirty due to moving off mScreen | - | ||||||||||||
| 130 | QPoint mScreenOffset = mScreen->geometry().topLeft(); | - | ||||||||||||
| 131 | // global to local translation | - | ||||||||||||
| 132 | if (!mCurrentRect.translated(mScreenOffset).intersects(mScreen->geometry()))
| 0 | ||||||||||||
| 133 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||
| 134 | - | |||||||||||||
| 135 | mPrevRect = mCurrentRect; | - | ||||||||||||
| 136 | painter.drawImage(mPrevRect, *mGraphic->image()); | - | ||||||||||||
| 137 | mOnScreen = true; | - | ||||||||||||
| 138 | return mPrevRect; never executed: return mPrevRect; | 0 | ||||||||||||
| 139 | } | - | ||||||||||||
| 140 | - | |||||||||||||
| 141 | QRect QFbCursor::dirtyRect() | - | ||||||||||||
| 142 | { | - | ||||||||||||
| 143 | if (mOnScreen) {
| 0 | ||||||||||||
| 144 | mOnScreen = false; | - | ||||||||||||
| 145 | return mPrevRect; never executed: return mPrevRect; | 0 | ||||||||||||
| 146 | } | - | ||||||||||||
| 147 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||
| 148 | } | - | ||||||||||||
| 149 | - | |||||||||||||
| 150 | void QFbCursor::setCursor(Qt::CursorShape shape) | - | ||||||||||||
| 151 | { | - | ||||||||||||
| 152 | mGraphic->set(shape); | - | ||||||||||||
| 153 | } never executed: end of block | 0 | ||||||||||||
| 154 | - | |||||||||||||
| 155 | void QFbCursor::setCursor(const QImage &image, int hotx, int hoty) | - | ||||||||||||
| 156 | { | - | ||||||||||||
| 157 | mGraphic->set(image, hotx, hoty); | - | ||||||||||||
| 158 | } never executed: end of block | 0 | ||||||||||||
| 159 | - | |||||||||||||
| 160 | void QFbCursor::setCursor(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY) | - | ||||||||||||
| 161 | { | - | ||||||||||||
| 162 | mGraphic->set(data, mask, width, height, hotX, hotY); | - | ||||||||||||
| 163 | } never executed: end of block | 0 | ||||||||||||
| 164 | - | |||||||||||||
| 165 | #ifndef QT_NO_CURSOR | - | ||||||||||||
| 166 | void QFbCursor::changeCursor(QCursor * widgetCursor, QWindow *window) | - | ||||||||||||
| 167 | { | - | ||||||||||||
| 168 | Q_UNUSED(window); | - | ||||||||||||
| 169 | const Qt::CursorShape shape = widgetCursor ? widgetCursor->shape() : Qt::ArrowCursor;
| 0 | ||||||||||||
| 170 | - | |||||||||||||
| 171 | if (shape == Qt::BitmapCursor) {
| 0 | ||||||||||||
| 172 | // application supplied cursor | - | ||||||||||||
| 173 | QPoint spot = widgetCursor->hotSpot(); | - | ||||||||||||
| 174 | setCursor(widgetCursor->pixmap().toImage(), spot.x(), spot.y()); | - | ||||||||||||
| 175 | } else { never executed: end of block | 0 | ||||||||||||
| 176 | // system cursor | - | ||||||||||||
| 177 | setCursor(shape); | - | ||||||||||||
| 178 | } never executed: end of block | 0 | ||||||||||||
| 179 | mCurrentRect = getCurrentRect(); | - | ||||||||||||
| 180 | QPoint mScreenOffset = mScreen->geometry().topLeft(); // global to local translation | - | ||||||||||||
| 181 | if (mOnScreen || mScreen->geometry().intersects(mCurrentRect.translated(mScreenOffset)))
| 0 | ||||||||||||
| 182 | setDirty(); never executed: setDirty(); | 0 | ||||||||||||
| 183 | } never executed: end of block | 0 | ||||||||||||
| 184 | #endif | - | ||||||||||||
| 185 | - | |||||||||||||
| 186 | void QFbCursor::setDirty() | - | ||||||||||||
| 187 | { | - | ||||||||||||
| 188 | if (!mVisible)
| 0 | ||||||||||||
| 189 | return; never executed: return; | 0 | ||||||||||||
| 190 | - | |||||||||||||
| 191 | if (!mDirty) {
| 0 | ||||||||||||
| 192 | mDirty = true; | - | ||||||||||||
| 193 | mScreen->scheduleUpdate(); | - | ||||||||||||
| 194 | } never executed: end of block | 0 | ||||||||||||
| 195 | } never executed: end of block | 0 | ||||||||||||
| 196 | - | |||||||||||||
| 197 | void QFbCursor::updateMouseStatus() | - | ||||||||||||
| 198 | { | - | ||||||||||||
| 199 | mVisible = mDeviceListener->hasMouse(); | - | ||||||||||||
| 200 | mScreen->setDirty(mVisible ? getCurrentRect() : lastPainted()); | - | ||||||||||||
| 201 | } never executed: end of block | 0 | ||||||||||||
| 202 | - | |||||||||||||
| 203 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |