Changeset View
Changeset View
Standalone View
Standalone View
src/controls/Page.qml
Show All 11 Lines | |||||
12 | * GNU Library General Public License for more details | 12 | * GNU Library General Public License for more details | ||
13 | * | 13 | * | ||
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.5 | ||
21 | import QtQuick.Layouts 1.2 | 21 | import QtQuick.Layouts 1.2 | ||
22 | import org.kde.kirigami 2.4 as Kirigami | 22 | import org.kde.kirigami 2.4 as Kirigami | ||
23 | import "private" | 23 | import "private" | ||
24 | import QtQuick.Templates 2.0 as T2 | 24 | import QtQuick.Templates 2.0 as T2 | ||
25 | 25 | | |||
26 | /** | 26 | /** | ||
27 | * Page is a container for all the app pages: everything pushed to the | 27 | * Page is a container for all the app pages: everything pushed to the | ||
28 | * ApplicationWindow stackView should be a Page instabnce (or a subclass, | 28 | * ApplicationWindow stackView should be a Page instabnce (or a subclass, | ||
▲ Show 20 Lines • Show All 199 Lines • ▼ Show 20 Line(s) | 33 | T2.Page { | |||
228 | * For instance a global "back" shortcut or the Android | 228 | * For instance a global "back" shortcut or the Android | ||
229 | * Back button has been pressed. | 229 | * Back button has been pressed. | ||
230 | * The page can manage the back event by itself, | 230 | * The page can manage the back event by itself, | ||
231 | * and if it set event.accepted = true, it will stop the main | 231 | * and if it set event.accepted = true, it will stop the main | ||
232 | * application to manage the back event. | 232 | * application to manage the back event. | ||
233 | */ | 233 | */ | ||
234 | signal backRequested(var event); | 234 | signal backRequested(var event); | ||
235 | 235 | | |||
236 | property Component titleDelegate: Kirigami.Heading { | ||||
237 | id: title | ||||
238 | level: 1 | ||||
239 | Layout.fillWidth: true | ||||
240 | | ||||
241 | Layout.preferredWidth: titleTextMetrics.width | ||||
242 | Layout.minimumWidth: titleTextMetrics.width | ||||
243 | opacity: root.isCurrentPage ? 1 : 0.4 | ||||
244 | maximumLineCount: 1 | ||||
245 | elide: Text.ElideRight | ||||
246 | text: root.title | ||||
247 | TextMetrics { | ||||
248 | id: titleTextMetrics | ||||
249 | text: root.title | ||||
250 | font: title.font | ||||
251 | } | ||||
252 | } | ||||
253 | | ||||
236 | // Look for sheets and cose them | 254 | // Look for sheets and cose them | ||
237 | //FIXME: port Sheets to Popup? | 255 | //FIXME: port Sheets to Popup? | ||
238 | onBackRequested: { | 256 | onBackRequested: { | ||
239 | for(var i in root.resources) { | 257 | for(var i in root.resources) { | ||
240 | var item = root.resources[i]; | 258 | var item = root.resources[i]; | ||
241 | if (item.hasOwnProperty("close") && item.hasOwnProperty("sheetOpen") && item.sheetOpen) { | 259 | if (item.hasOwnProperty("close") && item.hasOwnProperty("sheetOpen") && item.sheetOpen) { | ||
242 | item.close() | 260 | item.close() | ||
243 | event.accepted = true; | 261 | event.accepted = true; | ||
244 | return; | 262 | return; | ||
245 | } | 263 | } | ||
246 | } | 264 | } | ||
247 | } | 265 | } | ||
248 | 266 | | |||
249 | /** | 267 | /** | ||
250 | * globalToolBarItem: Item | 268 | * globalToolBarItem: Item | ||
251 | * The item used as global toolbar for the page | 269 | * The item used as global toolbar for the page | ||
252 | * present only if we are in a PageRow as a page or as a layer, | 270 | * present only if we are in a PageRow as a page or as a layer, | ||
253 | * and the style is either Titles or ToolBar | 271 | * and the style is either Titles or ToolBar | ||
254 | * @since 2.5 | 272 | * @since 2.5 | ||
255 | */ | 273 | */ | ||
256 | readonly property Item globalToolBarItem: globalToolBar.item | 274 | readonly property Item globalToolBarItem: globalToolBar.item | ||
257 | 275 | | |||
276 | /** | ||||
277 | * The style for the automatically generated global toolbar: by default the Page toolbar is the one set globally in the PageRow in its globalToolBar.style property. | ||||
278 | * A single page can override the application toolbar style for itself. | ||||
279 | * It is discouraged to use this, except very specific exceptions, like a chat | ||||
280 | * application which can't have controls on the bottom except the text field. | ||||
281 | */ | ||||
282 | property int globalToolBarStyle: globalToolBar.row.globalToolBar.actualStyle | ||||
283 | | ||||
258 | //NOTE: contentItem will be created if not existing (and contentChildren of Page would become its children) This with anchors enforces the geometry we want, where globalToolBar is a super-header, on top of header | 284 | //NOTE: contentItem will be created if not existing (and contentChildren of Page would become its children) This with anchors enforces the geometry we want, where globalToolBar is a super-header, on top of header | ||
259 | contentItem: Item { | 285 | contentItem: Item { | ||
260 | anchors { | 286 | anchors { | ||
261 | top: root.header | 287 | top: root.header | ||
262 | ? root.header.bottom | 288 | ? root.header.bottom | ||
263 | : (globalToolBar.visible ? globalToolBar.bottom : parent.top) | 289 | : (globalToolBar.visible ? globalToolBar.bottom : parent.top) | ||
264 | topMargin: root.topPadding + root.spacing | 290 | topMargin: root.topPadding + root.spacing | ||
265 | bottom: root.footer ? root.footer.top : parent.bottom | 291 | bottom: root.footer ? root.footer.top : parent.bottom | ||
Show All 25 Lines | 310 | onParentChanged: { | |||
291 | if (root.parent.hasOwnProperty("__pageRow")) { | 317 | if (root.parent.hasOwnProperty("__pageRow")) { | ||
292 | globalToolBar.row = root.parent.__pageRow; | 318 | globalToolBar.row = root.parent.__pageRow; | ||
293 | } | 319 | } | ||
294 | if (root.T2.StackView.view) { | 320 | if (root.T2.StackView.view) { | ||
295 | globalToolBar.stack = root.T2.StackView.view; | 321 | globalToolBar.stack = root.T2.StackView.view; | ||
296 | globalToolBar.row = root.T2.StackView.view.parent; | 322 | globalToolBar.row = root.T2.StackView.view.parent; | ||
297 | } | 323 | } | ||
298 | if (globalToolBar.row) { | 324 | if (globalToolBar.row) { | ||
299 | globalToolBar.row.globalToolBar.actualStyleChanged.connect(globalToolBar.syncSource); | 325 | root.globalToolBarStyleChanged.connect(globalToolBar.syncSource); | ||
300 | globalToolBar.syncSource(); | 326 | globalToolBar.syncSource(); | ||
301 | } | 327 | } | ||
302 | } | 328 | } | ||
303 | 329 | | |||
304 | //in data in order for them to not be considered for contentItem, contentChildren, contentData | 330 | //in data in order for them to not be considered for contentItem, contentChildren, contentData | ||
305 | data: [ | 331 | data: [ | ||
306 | PageActionPropertyGroup { | 332 | PageActionPropertyGroup { | ||
307 | id: actionsGroup | 333 | id: actionsGroup | ||
Show All 13 Lines | 343 | Loader { | |||
321 | anchors { | 347 | anchors { | ||
322 | left: parent.left | 348 | left: parent.left | ||
323 | right: parent.right | 349 | right: parent.right | ||
324 | top: parent.top | 350 | top: parent.top | ||
325 | } | 351 | } | ||
326 | property Kirigami.PageRow row | 352 | property Kirigami.PageRow row | ||
327 | property T2.StackView stack | 353 | property T2.StackView stack | ||
328 | 354 | | |||
329 | // property Component toolbarComponent: Qt.createComponent(Qt.resolvedUrl(row.globalToolBar.actualStyle == Kirigami.ApplicationHeaderStyle.ToolBar ? "private/globaltoolbar/ToolBarPageHeader.qml" : "private/globaltoolbar/TitlesPageHeader.qml")) | | |||
330 | | ||||
331 | visible: active | 355 | visible: active | ||
332 | active: row && (stack != null || row.globalToolBar.actualStyle === Kirigami.ApplicationHeaderStyle.ToolBar || globalToolBar.row.globalToolBar.actualStyle == Kirigami.ApplicationHeaderStyle.Titles) | 356 | active: row && (stack != null || root.globalToolBarStyle === Kirigami.ApplicationHeaderStyle.ToolBar || root.globalToolBarStyle == Kirigami.ApplicationHeaderStyle.Titles) | ||
333 | 357 | | |||
334 | function syncSource() { | 358 | function syncSource() { | ||
335 | if (row && active) { | 359 | if (row && active) { | ||
336 | setSource(Qt.resolvedUrl(row.globalToolBar.actualStyle === Kirigami.ApplicationHeaderStyle.ToolBar ? "private/globaltoolbar/ToolBarPageHeader.qml" : "private/globaltoolbar/TitlesPageHeader.qml"), | 360 | setSource(Qt.resolvedUrl(root.globalToolBarStyle === Kirigami.ApplicationHeaderStyle.ToolBar ? "private/globaltoolbar/ToolBarPageHeader.qml" : "private/globaltoolbar/TitlesPageHeader.qml"), | ||
337 | //TODO: find container reliably, remove assumption | 361 | //TODO: find container reliably, remove assumption | ||
338 | {"pageRow": Qt.binding(function() {return row}), | 362 | {"pageRow": Qt.binding(function() {return row}), | ||
339 | "page": root, | 363 | "page": root, | ||
340 | "current": Qt.binding(function() {return stack || !root.parent ? true : row.currentIndex === root.parent.level})}); | 364 | "current": Qt.binding(function() {return stack || !root.parent ? true : row.currentIndex === root.parent.level})}); | ||
341 | } | 365 | } | ||
342 | } | 366 | } | ||
343 | 367 | | |||
344 | Separator { | 368 | Separator { | ||
Show All 13 Lines | 378 | Loader { | |||
358 | anchors { | 382 | anchors { | ||
359 | left: parent.left | 383 | left: parent.left | ||
360 | right: parent.right | 384 | right: parent.right | ||
361 | bottom: parent.bottom | 385 | bottom: parent.bottom | ||
362 | } | 386 | } | ||
363 | //It should be T2.Page, Qt 5.7 doesn't like it | 387 | //It should be T2.Page, Qt 5.7 doesn't like it | ||
364 | property Item page: root | 388 | property Item page: root | ||
365 | height: item ? item.height : 0 | 389 | height: item ? item.height : 0 | ||
366 | active: typeof applicationWindow !== "undefined" && (!globalToolBar.row || globalToolBar.row.globalToolBar.actualStyle !== Kirigami.ApplicationHeaderStyle.ToolBar) && | 390 | active: typeof applicationWindow !== "undefined" && (!globalToolBar.row || root.globalToolBarStyle !== Kirigami.ApplicationHeaderStyle.ToolBar) && | ||
367 | //Legacy | 391 | //Legacy | ||
368 | (typeof applicationWindow === "undefined" || | 392 | (typeof applicationWindow === "undefined" || | ||
369 | (!applicationWindow().header || applicationWindow().header.toString().indexOf("ToolBarApplicationHeader") === -1) && | 393 | (!applicationWindow().header || applicationWindow().header.toString().indexOf("ToolBarApplicationHeader") === -1) && | ||
370 | (!applicationWindow().footer || applicationWindow().footer.toString().indexOf("ToolBarApplicationHeader") === -1)) | 394 | (!applicationWindow().footer || applicationWindow().footer.toString().indexOf("ToolBarApplicationHeader") === -1)) | ||
371 | source: Qt.resolvedUrl("./private/ActionButton.qml") | 395 | source: Qt.resolvedUrl("./private/ActionButton.qml") | ||
372 | } | 396 | } | ||
373 | ] | 397 | ] | ||
374 | 398 | | |||
375 | Layout.fillWidth: true | 399 | Layout.fillWidth: true | ||
376 | } | 400 | } |