Changeset View
Changeset View
Standalone View
Standalone View
src/controls/ScrollablePage.qml
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU Library General Public | 14 | * You should have received a copy of the GNU Library General Public | ||
15 | * License along with this program; if not, write to the | 15 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | 16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | import QtQuick 2.1 | 20 | import QtQuick 2.1 | ||
21 | import QtQuick.Layouts 1.2 | 21 | import QtQuick.Layouts 1.2 | ||
22 | import org.kde.kirigami 1.0 | 22 | import org.kde.kirigami 2.0 | ||
23 | import "private" | 23 | import "private" | ||
24 | 24 | | |||
25 | /** | 25 | /** | ||
26 | * ScrollablePage is a container for all the app pages: everything pushed to the | 26 | * ScrollablePage is a container for all the app pages: everything pushed to the | ||
27 | * ApplicationWindow stackView should be a Page or ScrollablePage instabnce. | 27 | * ApplicationWindow stackView should be a Page or ScrollablePage instabnce. | ||
28 | * This Page subclass is for content that has to be scrolled around, such as | 28 | * This Page subclass is for content that has to be scrolled around, such as | ||
29 | * bigger content than the screen that would normally go in a Flickable | 29 | * bigger content than the screen that would normally go in a Flickable | ||
30 | * or a ListView. | 30 | * or a ListView. | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 62 | Page { | |||
83 | * The main Flickable item of this page | 83 | * The main Flickable item of this page | ||
84 | */ | 84 | */ | ||
85 | property alias flickable: scrollView.flickableItem | 85 | property alias flickable: scrollView.flickableItem | ||
86 | 86 | | |||
87 | /** | 87 | /** | ||
88 | * The main content Item of this page. | 88 | * The main content Item of this page. | ||
89 | * In the case of a ListView or GridView, both contentItem and flickable | 89 | * In the case of a ListView or GridView, both contentItem and flickable | ||
90 | * will be a pointer to the ListView (or GridView) | 90 | * will be a pointer to the ListView (or GridView) | ||
91 | * NOTE: can't be contentItem as Page's contentItem is final | ||||
91 | */ | 92 | */ | ||
92 | default property alias contentItem: scrollView.contentItem | 93 | default property QtObject mainItem | ||
93 | 94 | | |||
94 | /** | | |||
95 | * leftPadding: int | | |||
96 | * default contents padding at left | | |||
97 | */ | | |||
98 | property alias leftPadding: scrollView.leftPadding | | |||
99 | | ||||
100 | /** | | |||
101 | * topPadding: int | | |||
102 | * default contents padding at top | | |||
103 | */ | | |||
104 | property alias topPadding: scrollView.topPadding | | |||
105 | | ||||
106 | /** | | |||
107 | * rightPadding: int | | |||
108 | * default contents padding at right | | |||
109 | */ | | |||
110 | property alias rightPadding: scrollView.rightPadding | | |||
111 | | ||||
112 | /** | | |||
113 | * bottomPadding: int | | |||
114 | * default contents padding at bottom | | |||
115 | */ | | |||
116 | property alias bottomPadding: scrollView.bottomPadding | | |||
117 | | ||||
118 | children: [ | | |||
119 | RefreshableScrollView { | 95 | RefreshableScrollView { | ||
120 | id: scrollView | 96 | id: scrollView | ||
121 | topPadding: (applicationWindow() && applicationWindow().header ? applicationWindow().header.preferredHeight : 0) + (contentItem == flickable ? 0 : Units.gridUnit) | 97 | z: 0 | ||
122 | leftPadding: contentItem == flickable ? 0 : Units.gridUnit | 98 | //child of root as it shouldn't have margins | ||
123 | rightPadding: contentItem == flickable ? 0 : Units.gridUnit | 99 | parent: root | ||
124 | bottomPadding: contentItem == flickable ? 0 : Units.gridUnit | 100 | topPadding: (applicationWindow() && applicationWindow().header ? applicationWindow().header.preferredHeight : 0) + (contentItem == flickable ? 0 : root.topPadding) | ||
101 | leftPadding: contentItem == flickable ? 0 : root.leftPadding | ||||
102 | rightPadding: contentItem == flickable ? 0 : root.rightPadding | ||||
103 | bottomPadding: contentItem == flickable ? 0 : root.bottomPadding | ||||
125 | anchors { | 104 | anchors { | ||
126 | fill: parent | 105 | fill: parent | ||
106 | topMargin: root.header ? root.header.height : 0 | ||||
127 | } | 107 | } | ||
128 | }, | 108 | } | ||
109 | | ||||
110 | anchors.topMargin: 0 | ||||
129 | 111 | | |||
130 | Item { | 112 | Item { | ||
131 | id: overlay | 113 | id: overlay | ||
114 | parent: root | ||||
115 | z: 9998 | ||||
132 | anchors.fill: parent | 116 | anchors.fill: parent | ||
133 | property Item oldContentItem | 117 | property QtObject oldMainItem | ||
134 | } | 118 | } | ||
135 | ] | | |||
136 | 119 | | |||
137 | //HACK to get the contentItem as the last one, all the other eventual items as an overlay | 120 | //HACK to get the mainItem as the last one, all the other eventual items as an overlay | ||
138 | //no idea if is the way the user expects | 121 | //no idea if is the way the user expects | ||
139 | onContentItemChanged: { | 122 | onMainItemChanged: { | ||
140 | if (overlay.oldContentItem) { | 123 | if (mainItem.hasOwnProperty("anchors")) { | ||
141 | overlay.oldContentItem.parent = overlay | 124 | scrollView.contentItem = mainItem | ||
125 | //don't try to reparent drawers | ||||
126 | } else if (mainItem.hasOwnProperty("dragMargin")) { | ||||
127 | return; | ||||
128 | } | ||||
129 | if (overlay.oldMainItem && overlay.oldMainItem.parent != applicationWindow().overlay) { | ||||
130 | overlay.oldMainItem.parent = overlay | ||||
142 | } | 131 | } | ||
143 | overlay.oldContentItem = root.contentItem | 132 | overlay.oldMainItem = mainItem | ||
144 | } | 133 | } | ||
145 | } | 134 | } |