Changeset View
Changeset View
Standalone View
Standalone View
src/controls/ContextDrawer.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 QtQuick.Controls 1.0 as QtControls | 22 | import org.kde.kirigami 2.0 | ||
23 | import org.kde.kirigami 1.0 | 23 | | ||
24 | import "templates/private" | ||||
24 | 25 | | |||
25 | /** | 26 | /** | ||
26 | * A drawer specialization that will show a list of actions that are | 27 | * A drawer specialization that will show a list of actions that are | ||
27 | * specific of the current page shown by the application | 28 | * specific of the current page shown by the application | ||
28 | * | 29 | * | ||
29 | * Example usage: | 30 | * Example usage: | ||
30 | * @code | 31 | * @code | ||
31 | * import org.kde.kirigami 1.0 as Kirigami | 32 | * import org.kde.kirigami 2.0 as Kirigami | ||
32 | * | 33 | * | ||
33 | * Kirigami.ApplicationWindow { | 34 | * Kirigami.ApplicationWindow { | ||
34 | * [...] | 35 | * [...] | ||
35 | * contextDrawer: Kirigami.ContextDrawer { | 36 | * contextDrawer: Kirigami.ContextDrawer { | ||
36 | * id: contextDrawer | 37 | * id: contextDrawer | ||
37 | * } | 38 | * } | ||
38 | * [...] | 39 | * [...] | ||
39 | * } | 40 | * } | ||
40 | * @endcode | 41 | * @endcode | ||
41 | * | 42 | * | ||
42 | * @code | 43 | * @code | ||
43 | * import org.kde.kirigami 1.0 as Kirigami | 44 | * import org.kde.kirigami 2.0 as Kirigami | ||
44 | * | 45 | * | ||
45 | * Kirigami.Page { | 46 | * Kirigami.Page { | ||
46 | * [...] | 47 | * [...] | ||
47 | * contextualActions: [ | 48 | * contextualActions: [ | ||
48 | * Kirigami.Action { | 49 | * Kirigami.Action { | ||
49 | * iconName: "edit" | 50 | * iconName: "edit" | ||
50 | * text: "Action text" | 51 | * text: "Action text" | ||
51 | * onTriggered: { | 52 | * onTriggered: { | ||
Show All 26 Lines | 70 | OverlayDrawer { | |||
78 | /** | 79 | /** | ||
79 | * actions: list<Action> | 80 | * actions: list<Action> | ||
80 | * This can be any type of object that a ListView can accept as model. | 81 | * This can be any type of object that a ListView can accept as model. | ||
81 | * It expects items compatible with either QAction or Kirigami Action | 82 | * It expects items compatible with either QAction or Kirigami Action | ||
82 | */ | 83 | */ | ||
83 | property var actions: pageStack.currentItem ? pageStack.currentItem.contextualActions : null | 84 | property var actions: pageStack.currentItem ? pageStack.currentItem.contextualActions : null | ||
84 | enabled: menu.count > 0 | 85 | enabled: menu.count > 0 | ||
85 | edge: Qt.RightEdge | 86 | edge: Qt.RightEdge | ||
86 | opened: false | 87 | drawerOpen: false | ||
88 | | ||||
89 | //list items go to edges, have their own padding | ||||
90 | leftPadding: 0 | ||||
91 | rightPadding: 0 | ||||
92 | bottomPadding: 0 | ||||
87 | 93 | | |||
88 | handleVisible: applicationWindow == undefined || applicationWindow().wideScreen == true ? false : applicationWindow().controlsVisible | 94 | handleVisible: applicationWindow == undefined || applicationWindow().wideScreen == true ? false : applicationWindow().controlsVisible | ||
89 | 95 | | |||
90 | Connections { | 96 | Connections { | ||
91 | target: pageStack | 97 | target: pageStack | ||
92 | onCurrentItemChanged: { | 98 | onCurrentItemChanged: { | ||
93 | if (pageStack.currentItem) | 99 | if (pageStack.currentItem) | ||
94 | actions = pageStack.currentItem.contextualActions | 100 | actions = pageStack.currentItem.contextualActions | ||
95 | } | 101 | } | ||
96 | } | 102 | } | ||
97 | 103 | | |||
98 | contentItem: QtControls.ScrollView { | 104 | contentItem: ScrollView { | ||
99 | implicitWidth: Units.gridUnit * 20 | 105 | implicitWidth: Units.gridUnit * 20 | ||
100 | ListView { | 106 | ListView { | ||
101 | id: menu | 107 | id: menu | ||
102 | interactive: contentHeight > height | 108 | interactive: contentHeight > height | ||
103 | model: { | 109 | model: { | ||
104 | if (typeof root.actions == "undefined") { | 110 | if (typeof root.actions == "undefined") { | ||
105 | return null; | 111 | return null; | ||
106 | } | 112 | } | ||
Show All 35 Lines | 147 | onClicked: { | |||
142 | if (modelData && modelData.trigger !== undefined) { | 148 | if (modelData && modelData.trigger !== undefined) { | ||
143 | modelData.trigger(); | 149 | modelData.trigger(); | ||
144 | // assume the model is a list of QAction or Action | 150 | // assume the model is a list of QAction or Action | ||
145 | } else if (menu.model.length > index) { | 151 | } else if (menu.model.length > index) { | ||
146 | menu.model[index].trigger(); | 152 | menu.model[index].trigger(); | ||
147 | } else { | 153 | } else { | ||
148 | console.warning("Don't know how to trigger the action") | 154 | console.warning("Don't know how to trigger the action") | ||
149 | } | 155 | } | ||
150 | root.opened = false; | 156 | root.drawerOpen = false; | ||
151 | } | 157 | } | ||
152 | } | 158 | } | ||
153 | } | 159 | } | ||
154 | } | 160 | } | ||
155 | } | 161 | } |