Advertisement
Guest User

KickoffItem.qml

a guest
Jul 6th, 2017
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.60 KB | None | 0 0
  1. /*
  2. Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org>
  3. Copyright (C) 2012 Gregor Taetzner <gregor@freenet.de>
  4. Copyright 2014 Sebastian Kügler <sebas@kde.org>
  5. Copyright (C) 2015 Eike Hein <hein@kde.org>
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License along
  18. with this program; if not, write to the Free Software Foundation, Inc.,
  19. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. import QtQuick 2.0
  22. import org.kde.plasma.core 2.0 as PlasmaCore
  23. import org.kde.plasma.components 2.0 as PlasmaComponents
  24. import org.kde.draganddrop 2.0
  25.  
  26. import "../code/tools.js" as Tools
  27.  
  28. Item {
  29. id: listItem
  30.  
  31. width: ListView.view.width
  32. // height: listItemDelegate.height // + listItemDelegate.anchors.margins*2
  33. height: (units.smallSpacing * 2) + Math.max(elementIcon.height, titleElement.height + subTitleElement.height)
  34.  
  35. signal actionTriggered(string actionId, variant actionArgument)
  36. signal aboutToShowActionMenu(variant actionMenu)
  37.  
  38. readonly property int itemIndex: model.index
  39.  
  40. property bool dropEnabled: false
  41. property bool appView: false
  42. property bool modelChildren: model.hasChildren || false
  43. property bool isCurrent: listItem.ListView.view.currentIndex === index;
  44. property string url: model.url || ""
  45. property bool showAppsByName: plasmoid.configuration.showAppsByName
  46.  
  47. property bool hasActionList: ((model.favoriteId != null)
  48. || (("hasActionList" in model) && (model.hasActionList == true)))
  49. property Item menu: actionMenu
  50.  
  51. onAboutToShowActionMenu: {
  52. var actionList = hasActionList ? model.actionList : [];
  53. Tools.fillActionMenu(actionMenu, actionList, ListView.view.model.favoritesModel, model.favoriteId);
  54. }
  55.  
  56. onActionTriggered: {
  57. Tools.triggerAction(ListView.view.model, model.index, actionId, actionArgument);
  58.  
  59. if (actionId.indexOf("_kicker_favorite_") === 0) {
  60. switchToInitial();
  61. }
  62. }
  63.  
  64. function activate() {
  65. var view = listItem.ListView.view;
  66.  
  67. if (model.hasChildren) {
  68. var childModel = view.model.modelForRow(index);
  69.  
  70. view.addBreadcrumb(childModel, display);
  71. view.model = childModel;
  72. } else {
  73. view.model.trigger(index, "", null);
  74. plasmoid.expanded = false;
  75.  
  76. if (view.reset) {
  77. view.reset();
  78. }
  79. }
  80. }
  81.  
  82. function openActionMenu(visualParent, x, y) {
  83. aboutToShowActionMenu(actionMenu);
  84. actionMenu.visualParent = visualParent != undefined ? visualParent : mouseArea;
  85. actionMenu.open(x, y);
  86. }
  87.  
  88. ActionMenu {
  89. id: actionMenu
  90.  
  91. onActionClicked: {
  92. actionTriggered(actionId, actionArgument);
  93. }
  94. }
  95.  
  96. Item {
  97. id: listItemDelegate
  98.  
  99. anchors {
  100. left: parent.left
  101. right: parent.right
  102. top: parent.top
  103. bottom: parent.bottom
  104. //margins: units.smallSpacing
  105. }
  106.  
  107. MouseArea {
  108. id: mouseArea
  109.  
  110. anchors.fill: parent
  111. //anchors.margins: -8
  112.  
  113. property bool pressed: false
  114. property int pressX: -1
  115. property int pressY: -1
  116.  
  117. hoverEnabled: true
  118. acceptedButtons: Qt.LeftButton | Qt.RightButton
  119.  
  120. onEntered: {
  121. listItem.ListView.view.currentIndex = index;
  122. }
  123.  
  124. onExited: {
  125. listItem.ListView.view.currentIndex = -1;
  126. }
  127.  
  128. onPressed: {
  129. if (mouse.buttons & Qt.RightButton) {
  130. if (hasActionList) {
  131. openActionMenu(mouseArea, mouse.x, mouse.y);
  132. }
  133. } else {
  134. pressed = true;
  135. pressX = mouse.x;
  136. pressY = mouse.y;
  137. }
  138. }
  139.  
  140. onReleased: {
  141. if (pressed) {
  142. if (appView) {
  143. appViewScrollArea.state = "OutgoingLeft";
  144. } else {
  145. listItem.activate();
  146. }
  147.  
  148. listItem.ListView.view.currentIndex = -1;
  149. }
  150.  
  151. pressed = false;
  152. pressX = -1;
  153. pressY = -1;
  154. }
  155.  
  156. onPositionChanged: {
  157. if (pressX != -1 && model.url && dragHelper.isDrag(pressX, pressY, mouse.x, mouse.y)) {
  158. kickoff.dragSource = listItem;
  159. dragHelper.startDrag(root, model.url, model.decoration);
  160. pressed = false;
  161. pressX = -1;
  162. pressY = -1;
  163. }
  164. }
  165.  
  166. onContainsMouseChanged: {
  167. if (!containsMouse) {
  168. pressed = false;
  169. pressX = -1;
  170. pressY = -1;
  171. }
  172. }
  173. }
  174.  
  175. PlasmaCore.IconItem {
  176. id: elementIcon
  177.  
  178. anchors {
  179. left: parent.left
  180. leftMargin: (units.gridUnit * 4) - units.iconSizes.medium
  181. verticalCenter: parent.verticalCenter
  182. }
  183. width: units.iconSizes.medium
  184. height: width
  185.  
  186. animated: false
  187. usesPlasmaTheme: false
  188.  
  189. source: model.decoration
  190. }
  191. PlasmaComponents.Label {
  192. id: titleElement
  193.  
  194. y: Math.round((parent.height - titleElement.height - ( (subTitleElement.text != "") ? subTitleElement.paintedHeight : 0) ) / 2)
  195. anchors {
  196. //bottom: elementIcon.verticalCenter
  197. left: elementIcon.right
  198. right: arrow.left
  199. leftMargin: units.gridUnit
  200. rightMargin: units.gridUnit * 2
  201. }
  202. height: paintedHeight
  203. // TODO: games should always show the by name!
  204. Rectangle {
  205. color: "yellow"
  206. Text {
  207. text: model.display
  208. elide: Text.ElideRight
  209. }
  210. width: childrenRect.width
  211. height: childrenRect.height
  212. }
  213. }
  214. PlasmaComponents.Label {
  215. id: subTitleElement
  216.  
  217. anchors {
  218. left: titleElement.left
  219. right: arrow.left
  220. rightMargin: units.gridUnit * 2
  221. top: titleElement.bottom
  222. }
  223. height: paintedHeight
  224.  
  225. Rectangle {
  226. color: "#3DFF33"
  227. Text {
  228. text: model.description
  229. opacity: isCurrent ? 0.8 : 0.6
  230. font.pointSize: theme.smallestFont.pointSize
  231. elide: Text.ElideMiddle
  232. }
  233. width: childrenRect.width
  234. height: childrenRect.height
  235. radius: height
  236. }
  237. }
  238.  
  239. PlasmaCore.SvgItem {
  240. id: arrow
  241.  
  242. anchors {
  243. right: parent.right
  244. rightMargin: units.gridUnit * 2
  245. verticalCenter: parent.verticalCenter
  246. }
  247.  
  248. width: visible ? units.iconSizes.small : 0
  249. height: width
  250.  
  251. visible: (model.hasChildren == true)
  252. opacity: (listItem.ListView.view.currentIndex == index) ? 1.0 : 0.4
  253.  
  254. svg: arrowsSvg
  255. elementId: (Qt.application.layoutDirection == Qt.RightToLeft) ? "left-arrow" : "right-arrow"
  256. }
  257. } // listItemDelegate
  258.  
  259. Keys.onPressed: {
  260. if (event.key == Qt.Key_Menu && hasActionList) {
  261. event.accepted = true;
  262. openActionMenu(mouseArea);
  263. } else if ((event.key == Qt.Key_Enter || event.key == Qt.Key_Return) && !modelChildren) {
  264. if (!modelChildren) {
  265. event.accepted = true;
  266. listItem.activate();
  267. }
  268. }
  269. }
  270. } // listItem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement