Warning, /frameworks/kirigami/src/controls/ApplicationItem.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 0008 import org.kde.kirigami as Kirigami 0009 0010 /** 0011 * @brief An item that provides the features of ApplicationWindow without the window itself. 0012 * 0013 * This allows embedding into a larger application. 0014 * It's based around the PageRow component that allows adding/removing of pages. 0015 * 0016 * Example usage: 0017 * @code 0018 * import org.kde.kirigami 2.4 as Kirigami 0019 * 0020 * Kirigami.ApplicationItem { 0021 * globalDrawer: Kirigami.GlobalDrawer { 0022 * actions: [ 0023 * Kirigami.Action { 0024 * text: "View" 0025 * icon.name: "view-list-icons" 0026 * Kirigami.Action { 0027 * text: "action 1" 0028 * } 0029 * Kirigami.Action { 0030 * text: "action 2" 0031 * } 0032 * Kirigami.Action { 0033 * text: "action 3" 0034 * } 0035 * }, 0036 * Kirigami.Action { 0037 * text: "Sync" 0038 * icon.name: "folder-sync" 0039 * } 0040 * ] 0041 * } 0042 * 0043 * contextDrawer: Kirigami.ContextDrawer { 0044 * id: contextDrawer 0045 * } 0046 * 0047 * pageStack.initialPage: Kirigami.Page { 0048 * mainAction: Kirigami.Action { 0049 * icon.name: "edit" 0050 * onTriggered: { 0051 * // do stuff 0052 * } 0053 * } 0054 * contextualActions: [ 0055 * Kirigami.Action { 0056 * icon.name: "edit" 0057 * text: "Action text" 0058 * onTriggered: { 0059 * // do stuff 0060 * } 0061 * }, 0062 * Kirigami.Action { 0063 * icon.name: "edit" 0064 * text: "Action text" 0065 * onTriggered: { 0066 * // do stuff 0067 * } 0068 * } 0069 * ] 0070 * // ... 0071 * } 0072 * } 0073 * @endcode 0074 */ 0075 Kirigami.AbstractApplicationItem { 0076 id: root 0077 0078 /** 0079 * @brief This property holds the PageRow used to allocate the pages and 0080 * manage the transitions between them. 0081 * 0082 * It's using a PageRow, while having the same API as PageStack, 0083 * it positions the pages as adjacent columns, with as many columns 0084 * as can fit in the screen. An handheld device would usually have a single 0085 * fullscreen column, a tablet device would have many tiled columns. 0086 * 0087 * @property org::kde::kirigami::PageRow pageStack 0088 */ 0089 readonly property alias pageStack: __pageStack 0090 0091 // Redefines here as here we can know a pointer to PageRow 0092 wideScreen: width >= applicationWindow().pageStack.defaultColumnWidth * 2 0093 0094 Component.onCompleted: { 0095 pageStack.currentItem?.forceActiveFocus(); 0096 } 0097 0098 Kirigami.PageRow { 0099 id: __pageStack 0100 anchors { 0101 fill: parent 0102 // HACK: workaround a bug in android iOS keyboard management 0103 bottomMargin: ((Qt.platform.os === "android" || Qt.platform.os === "ios") || !Qt.inputMethod.visible) ? 0 : Qt.inputMethod.keyboardRectangle.height 0104 } 0105 0106 function goBack() { 0107 // NOTE: drawers are handling the back button by themselves 0108 const backEvent = {accepted: false} 0109 if (root.pageStack.currentIndex >= 1) { 0110 root.pageStack.currentItem.backRequested(backEvent); 0111 if (!backEvent.accepted) { 0112 root.pageStack.flickBack(); 0113 backEvent.accepted = true; 0114 } 0115 } 0116 0117 if (Kirigami.Settings.isMobile && !backEvent.accepted && Qt.platform.os !== "ios") { 0118 Qt.quit(); 0119 } 0120 } 0121 function goForward() { 0122 root.pageStack.currentIndex = Math.min(root.pageStack.depth - 1, root.pageStack.currentIndex + 1); 0123 } 0124 Keys.onBackPressed: event => { 0125 goBack(); 0126 event.accepted = true; 0127 } 0128 Shortcut { 0129 sequences: [StandardKey.Forward] 0130 onActivated: __pageStack.goForward(); 0131 } 0132 Shortcut { 0133 sequences: [StandardKey.Back] 0134 onActivated: __pageStack.goBack(); 0135 } 0136 0137 background: Rectangle { 0138 color: root.color 0139 } 0140 0141 focus: true 0142 } 0143 }