Unity 8
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 // Unity API
26 #include <unity/shell/application/MirMousePointerInterface.h>
27 
28 class 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 public:
33  MousePointer(QQuickItem *parent = nullptr);
34 
35  void setCursorName(const QString &qtCursorName) override;
36  QString cursorName() const override { return m_cursorName; }
37 
38  void setThemeName(const QString &themeName) override;
39  QString themeName() const override { return m_themeName; }
40 
41  void setCustomCursor(const QCursor &) override;
42 
43  QQuickItem* confiningItem() const;
44  void setConfiningItem(QQuickItem*);
45 
46  int topBoundaryOffset() const;
47  void setTopBoundaryOffset(int topBoundaryOffset);
48 
49 public Q_SLOTS:
50  void handleMouseEvent(ulong timestamp, QPointF movement, Qt::MouseButtons buttons,
51  Qt::KeyboardModifiers modifiers) override;
52  void handleWheelEvent(ulong timestamp, QPoint angleDelta, Qt::KeyboardModifiers modifiers) override;
53 
54 Q_SIGNALS:
55  void pushedLeftBoundary(qreal amount, Qt::MouseButtons buttons);
56  void pushedRightBoundary(qreal amount, Qt::MouseButtons buttons);
57  void pushedTopBoundary(qreal amount, Qt::MouseButtons buttons);
58  void pushedTopLeftCorner(qreal amount, Qt::MouseButtons buttons);
59  void pushedTopRightCorner(qreal amount, Qt::MouseButtons buttons);
60  void pushedBottomLeftCorner(qreal amount, Qt::MouseButtons buttons);
61  void pushedBottomRightCorner(qreal amount, Qt::MouseButtons buttons);
62  void pushStopped();
63  void mouseMoved();
64  void confiningItemChanged();
65 
66  void topBoundaryOffsetChanged(int topBoundaryOffset);
67 
68 protected:
69  void itemChange(ItemChange change, const ItemChangeData &value) override;
70 
71 private Q_SLOTS:
72  void registerScreen(QScreen *screen);
73 
74 private:
75  void registerWindow(QWindow *window);
76  void applyItemConfinement(qreal &newX, qreal &newY);
77 
78  QPointer<QWindow> m_registeredWindow;
79  QPointer<QScreen> m_registeredScreen;
80  QString m_cursorName;
81  QString m_themeName;
82 
83  // Accumulated, unapplied, mouse movement.
84  QPointF m_accumulatedMovement;
85 
86  QPointer<QQuickItem> m_confiningItem;
87 
88  int m_topBoundaryOffset{0};
89  bool m_pushing{false};
90 };
91 
92 #endif // MOUSEPOINTER_H