on xenial help sign in
try adding some SpreadFlickable
commit3c241c3a6a36c85b4929c4bc0d701587cc201bd0 authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 13 Apr 2015, 15:40 (12 years ago) parent6f759cf
4 files changed+151−6
plugins/Utils/spreadflickable.cpp+66 plugins/Utils/spreadflickable.h+37 qml/Stages/DecoratedWindow.qml+47−6 qml/Stages/DesktopStage.qml+1
plugins/Utils/spreadflickable.cppnew file+66
@@ -0,0 +1,66 @@
1+#include "spreadflickable.h"
2+
3+SpreadFlickable::SpreadFlickable(QQuickItem *parent):
4+ QQuickItem(parent),
5+ m_mousePressed(false),
6+ m_touchPressed(false)
7+{
8+ m_flickable = new QQuickFlickable(this);
9+ m_flickable->installEventFilter(this);
10+ connect(m_flickable, &QQuickFlickable::contentWidthChanged, this, &SpreadFlickable::contentWidthChanged);
11+ connect(m_flickable, &QQuickFlickable::contentXChanged, this, &SpreadFlickable::contentXChanged);
12+
13+ connect(this, &QQuickItem::heightChanged, this, &SpreadFlickable::slotHeightChanged);
14+ connect(this, &QQuickItem::widthChanged, this, &SpreadFlickable::slotWidthChanged);
15+}
16+
17+qreal SpreadFlickable::contentWidth() const
18+{
19+ return m_flickable->contentWidth();
20+}
21+
22+void SpreadFlickable::setContentWidth(qreal contentWidth)
23+{
24+ m_flickable->setContentWidth(contentWidth);
25+}
26+
27+qreal SpreadFlickable::contentX() const
28+{
29+ return m_flickable->contentX();
30+}
31+
32+void SpreadFlickable::setContentX(qreal contentX)
33+{
34+ m_flickable->setContentX(contentX);
35+}
36+
37+void SpreadFlickable::slotHeightChanged()
38+{
39+ m_flickable->setHeight(height());
40+}
41+
42+void SpreadFlickable::slotWidthChanged()
43+{
44+ m_flickable->setWidth(width());
45+}
46+
47+bool SpreadFlickable::eventFilter(QObject* /*watched*/, QEvent *event)
48+{
49+ //m_flickable->eventFilter(watched, event);
50+ switch (event->type()) {
51+ case QEvent::TouchBegin:
52+ break;
53+ case QEvent::TouchEnd:
54+ break;
55+ case QEvent::MouseButtonPress:
56+ break;
57+ case QEvent::MouseButtonRelease:
58+ break;
59+ default:
60+ // Not interested
61+ break;
62+ }
63+
64+ // We never filter them out. We are just watching.
65+ return false;
66+}
plugins/Utils/spreadflickable.hnew file+37
@@ -0,0 +1,37 @@
1+#include <QQuickItem>
2+#include <private/qquickflickable_p.h>
3+
4+class SpreadFlickable: public QQuickItem
5+{
6+ Q_OBJECT
7+ Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged)
8+ Q_PROPERTY(qreal contentX READ contentX WRITE setContentX NOTIFY contentXChanged)
9+
10+public:
11+ SpreadFlickable(QQuickItem *parent = nullptr);
12+
13+ qreal contentWidth() const;
14+ void setContentWidth(qreal contentWidth);
15+
16+ qreal contentX() const;
17+ void setContentX(qreal contentX);
18+
19+ bool eventFilter(QObject* /*watched*/, QEvent *event) override;
20+
21+Q_SIGNALS:
22+ void contentWidthChanged();
23+ void contentXChanged();
24+
25+private Q_SLOTS:
26+ void slotHeightChanged();
27+ void slotWidthChanged();
28+
29+private:
30+ void setMousePressed(bool value);
31+ void setTouchPressed(bool value);
32+
33+ bool m_mousePressed;
34+ bool m_touchPressed;
35+
36+ QQuickFlickable *m_flickable;
37+};
qml/Stages/DecoratedWindow.qml+47−6
@@ -31,10 +31,34 @@ FocusScope {
3131 property bool highlightShown: false
3232 property real highlightScale: 1
3333
34+ property int transformedWidth: width
35+ property int transformedHeight: height
36+
3437 signal close();
3538 signal maximize();
3639 signal minimize();
3740
41+ state: "normal"
42+ states: [
43+ State {
44+ name: "normal"
45+ PropertyChanges {
46+ target: applicationWindow
47+ }
48+ },
49+ State {
50+ name: "transformed"
51+ PropertyChanges {
52+ target: applicationWindow
53+ itemScale: root.transformedWidth / root.width / root.highlightScale
54+ }
55+ PropertyChanges {
56+ target: clipper
57+ clip: true
58+ }
59+ }
60+ ]
61+
3862 BorderImage {
3963 anchors {
4064 fill: root
@@ -72,12 +96,29 @@ FocusScope {
7296 visible: decorationShown
7397 }
7498
75− ApplicationWindow {
76− id: applicationWindow
77− objectName: application ? "appWindow_" + application.appId : "appWindow_null"
99+ Item {
100+ id: clipper
78101 anchors.fill: parent
79− anchors.topMargin: root.decorationShown ? decoration.height : 0
80− interactive: true
81− focus: true
102+
103+ ApplicationWindow {
104+ id: applicationWindow
105+ objectName: application ? "appWindow_" + application.appId : "appWindow_null"
106+ anchors.top: parent.top
107+ anchors.topMargin: root.decorationShown ? decoration.height : 0
108+ anchors.left: parent.left
109+ width: parent.width
110+ height: parent.height - (root.decorationShown ? decoration.height : 0)
111+ interactive: true
112+ focus: true
113+
114+ property real itemsScale: 1
115+ transform: [
116+ Scale {
117+ origin.x: 0; origin.y: 0
118+ xScale: applicationWindow.itemScale
119+ yScale: applicationWindow.itemScale
120+ }
121+ ]
122+ }
82123 }
83124}
qml/Stages/DesktopStage.qml+1
@@ -168,6 +168,7 @@ FocusScope {
168168 target: decoratedWindow
169169 decorationShown: false
170170 highlightShown: index == appRepeater.highlightedIndex
171+ state: "transformed"
171172 }
172173 PropertyChanges {
173174 target: tileInfo