on xenial help sign in
use a Qt C++ property for the panel height
commitcee9f51495f8550cb7a8ac2f8c7a940ac82caf64 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateWed 31 Aug 2016, 15:11 (10 years ago) parentf803c90
5 files changed+30−21
plugins/Cursor/Cursor.qml−2 plugins/Cursor/MousePointer.cpp+20−15 plugins/Cursor/MousePointer.h+8−2 qml/Shell.qml+1−1 tests/mocks/Cursor/Cursor.qml+1−1
plugins/Cursor/Cursor.qml−2
@@ -21,8 +21,6 @@ import Powerd 0.1
2121MousePointer {
2222 id: mousePointer
2323
24− property int panelHeight // to be read from MousePointer C++ class
25−
2624 CursorImageInfo {
2725 id: imageInfo
2826 themeName: mousePointer.themeName
plugins/Cursor/MousePointer.cpp+20−15
@@ -55,11 +55,11 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
5555 const qreal sceneWidth = parentItem()->width();
5656 const qreal sceneHeight = parentItem()->height();
5757
58− if (newX <= 0 && newY < m_panelHeight) { // top left corner
59− const auto distance = qSqrt(qPow(newX, 2) + qPow(newY-m_panelHeight, 2));
58+ if (newX <= 0 && newY < m_topBoundaryOffset) { // top left corner
59+ const auto distance = qSqrt(qPow(newX, 2) + qPow(newY-m_topBoundaryOffset, 2));
6060 Q_EMIT pushedTopLeftCorner(qAbs(distance), buttons);
61− } else if (newX >= sceneWidth-1 && newY < m_panelHeight) { // top right corner
62− const auto distance = qSqrt(qPow(newX-sceneWidth, 2) + qPow(newY-m_panelHeight, 2));
61+ } else if (newX >= sceneWidth-1 && newY < m_topBoundaryOffset) { // top right corner
62+ const auto distance = qSqrt(qPow(newX-sceneWidth, 2) + qPow(newY-m_topBoundaryOffset, 2));
6363 Q_EMIT pushedTopRightCorner(qAbs(distance), buttons);
6464 } else if (newX < 0 && newY >= sceneHeight-1) { // bottom left corner
6565 const auto distance = qSqrt(qPow(newX, 2) + qPow(newY-sceneHeight, 2));
@@ -71,8 +71,8 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
7171 Q_EMIT pushedLeftBoundary(qAbs(newX), buttons);
7272 } else if (newX >= sceneWidth) { // right edge
7373 Q_EMIT pushedRightBoundary(newX - (sceneWidth - 1), buttons);
74− } else if (newY < m_panelHeight) { // top edge
75− Q_EMIT pushedTopBoundary(qAbs(newY - m_panelHeight), buttons);
74+ } else if (newY < m_topBoundaryOffset) { // top edge
75+ Q_EMIT pushedTopBoundary(qAbs(newY - m_topBoundaryOffset), buttons);
7676 } else if (Q_LIKELY(newX > 0 && newX < sceneWidth-1 && newY > 0 && newY < sceneHeight-1)) { // normal pos, not pushing
7777 Q_EMIT pushStopped();
7878 }
@@ -96,22 +96,27 @@ void MousePointer::handleWheelEvent(ulong timestamp, QPoint angleDelta, Qt::Keyb
9696 QPoint() /* pixelDelta */, angleDelta, modifiers, Qt::ScrollUpdate);
9797}
9898
99+int MousePointer::topBoundaryOffset() const
100+{
101+ return m_topBoundaryOffset;
102+}
103+
104+void MousePointer::setTopBoundaryOffset(int topBoundaryOffset)
105+{
106+ if (m_topBoundaryOffset == topBoundaryOffset)
107+ return;
108+
109+ m_topBoundaryOffset = topBoundaryOffset;
110+ Q_EMIT topBoundaryOffsetChanged(topBoundaryOffset);
111+}
112+
99113void MousePointer::itemChange(ItemChange change, const ItemChangeData &value)
100114{
101115 if (change == ItemSceneChange) {
102116 registerWindow(value.window);
103− if (value.window) {
104− m_panelHeight = QQmlProperty::read(this, "panelHeight").toInt(); // when we move e.g. to a different screen (with possible different DGU)
105− }
106117 }
107118}
108119
109−void MousePointer::componentComplete()
110−{
111− MirMousePointerInterface::componentComplete();
112− m_panelHeight = QQmlProperty::read(this, "panelHeight").toInt();
113−}
114−
115120void MousePointer::registerWindow(QWindow *window)
116121{
117122 if (window == m_registeredWindow) {
plugins/Cursor/MousePointer.h+8−2
@@ -27,6 +27,8 @@
2727
2828class MousePointer : public MirMousePointerInterface {
2929 Q_OBJECT
30+ Q_PROPERTY(int topBoundaryOffset READ topBoundaryOffset WRITE setTopBoundaryOffset NOTIFY topBoundaryOffsetChanged)
31+
3032public:
3133 MousePointer(QQuickItem *parent = nullptr);
3234
@@ -38,6 +40,9 @@ public:
3840
3941 void setCustomCursor(const QCursor &) override;
4042
43+ int topBoundaryOffset() const;
44+ void setTopBoundaryOffset(int topBoundaryOffset);
45+
4146public Q_SLOTS:
4247 void handleMouseEvent(ulong timestamp, QPointF movement, Qt::MouseButtons buttons,
4348 Qt::KeyboardModifiers modifiers) override;
@@ -54,9 +59,10 @@ Q_SIGNALS:
5459 void pushStopped();
5560 void mouseMoved();
5661
62+ void topBoundaryOffsetChanged(int topBoundaryOffset);
63+
5764protected:
5865 void itemChange(ItemChange change, const ItemChangeData &value) override;
59− void componentComplete() override;
6066
6167private Q_SLOTS:
6268 void registerScreen(QScreen *screen);
@@ -72,7 +78,7 @@ private:
7278 // Accumulated, unapplied, mouse movement.
7379 QPointF m_accumulatedMovement;
7480
75− int m_panelHeight = 0;
81+ int m_topBoundaryOffset{0};
7682};
7783
7884#endif // MOUSEPOINTER_H
qml/Shell.qml+1−1
@@ -764,7 +764,7 @@ StyledItem {
764764 id: cursor
765765 visible: shell.hasMouse
766766 z: itemGrabber.z + 1
767− panelHeight: panel.panelHeight
767+ topBoundaryOffset: panel.panelHeight
768768
769769 property bool mouseNeverMoved: true
770770 Binding {
tests/mocks/Cursor/Cursor.qml+1−1
@@ -17,7 +17,7 @@
1717import QtQuick 2.4
1818
1919Item {
20− property int panelHeight // to be read from MousePointer C++ class
20+ property int topBoundaryOffset // effectively panel height
2121
2222 signal pushedLeftBoundary(real amount, int buttons)
2323 signal pushedRightBoundary(real amount, int buttons)