Lomiri
Loading...
Searching...
No Matches
MousePointer.h
1/*
2 * Copyright (C) 2015-2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef MOUSEPOINTER_H
18#define MOUSEPOINTER_H
19
20// Qt
21#include <QPointer>
22#include <QWindow>
23#include <QScreen>
24
25// Lomiri API
26#include <lomiri/shell/application/MirMousePointerInterface.h>
27
28class MousePointer : public MirMousePointerInterface {
29 Q_OBJECT
30 Q_PROPERTY(QQuickItem* confiningItem READ confiningItem WRITE setConfiningItem NOTIFY confiningItemChanged)
31 Q_PROPERTY(int topBoundaryOffset READ topBoundaryOffset WRITE setTopBoundaryOffset NOTIFY topBoundaryOffsetChanged)
32 Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
33
34public:
35 MousePointer(QQuickItem *parent = nullptr);
36 ~MousePointer();
37
38 void setCursorName(const QString &qtCursorName) override;
39 QString cursorName() const override { return m_cursorName; }
40
41 void setThemeName(const QString &themeName) override;
42 QString themeName() const override { return m_themeName; }
43
44 void moveTo(const QPoint& position) override;
45
46 void setCustomCursor(const QCursor &) override;
47
48 QQuickItem* confiningItem() const;
49 void setConfiningItem(QQuickItem*);
50
51 int topBoundaryOffset() const;
52 void setTopBoundaryOffset(int topBoundaryOffset);
53
54 QScreen* screen() const { return m_registeredScreen; }
55
56 bool isActive() { return m_active; }
57 void setActive(bool value);
58
59 bool centerAdjust() { return m_centerAdjust; }
60 void setCenterAdjust(bool value);
61
62Q_SIGNALS:
63 void pushedLeftBoundary(qreal amount, Qt::MouseButtons buttons);
64 void pushedRightBoundary(qreal amount, Qt::MouseButtons buttons);
65 void pushedTopBoundary(qreal amount, Qt::MouseButtons buttons);
66 void pushedTopLeftCorner(qreal amount, Qt::MouseButtons buttons);
67 void pushedTopRightCorner(qreal amount, Qt::MouseButtons buttons);
68 void pushedBottomLeftCorner(qreal amount, Qt::MouseButtons buttons);
69 void pushedBottomRightCorner(qreal amount, Qt::MouseButtons buttons);
70 void pushStopped();
71 void mouseMoved();
72 void confiningItemChanged();
73
74 void topBoundaryOffsetChanged(int topBoundaryOffset);
75
76 void activeChanged();
77
78protected:
79 void itemChange(ItemChange change, const ItemChangeData &value) override;
80
81private Q_SLOTS:
82 void registerScreen(QScreen *screen);
83
84private:
85 void registerWindow(QWindow *window);
86 void applyItemConfinement(qreal &newX, qreal &newY);
87
88 QPointer<QWindow> m_registeredWindow;
89 QPointer<QScreen> m_registeredScreen;
90 QString m_cursorName;
91 QString m_themeName;
92 bool m_active;
93 bool m_centerAdjust;
94
95 // Accumulated, unapplied, mouse movement.
96 QPointF m_accumulatedMovement;
97
98 QPointer<QQuickItem> m_confiningItem;
99
100 int m_topBoundaryOffset{0};
101 bool m_pushing{false};
102};
103
104#endif // MOUSEPOINTER_H