2021-07-16 19:33:52 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2015 by Eike Hein <hein@kde.org> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
import QtQuick 2.0
|
|
|
|
|
|
|
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
|
|
|
import org.kde.plasma.components 2.0 as PlasmaComponents
|
|
|
|
|
2022-08-28 21:48:51 +00:00
|
|
|
import "code/tools.js" as Tools
|
2021-07-16 19:33:52 +00:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: item
|
|
|
|
|
|
|
|
height: GridView.view.cellHeight
|
2022-08-28 21:48:51 +00:00
|
|
|
width: GridView.view.cellWidth // height
|
|
|
|
|
|
|
|
property int iconSize: 22
|
|
|
|
|
2021-07-16 19:33:52 +00:00
|
|
|
property bool showLabel: true
|
2022-08-28 21:48:51 +00:00
|
|
|
property int itemIndex: model.index
|
|
|
|
property string favoriteId: model.favoriteId !== undefined ? model.favoriteId : ""
|
|
|
|
property url url: model.url !== undefined ? model.url : ""
|
|
|
|
property variant icon: model.decoration !== undefined ? model.decoration : ""
|
|
|
|
property var m: model
|
|
|
|
property bool hasActionList: ((model.favoriteId !== null)
|
|
|
|
|| (("hasActionList" in model) && (model.hasActionList === true)))
|
2021-07-16 19:33:52 +00:00
|
|
|
|
|
|
|
Accessible.role: Accessible.MenuItem
|
|
|
|
Accessible.name: model.display
|
|
|
|
|
|
|
|
function openActionMenu(x, y) {
|
|
|
|
var actionList = hasActionList ? model.actionList : [];
|
|
|
|
Tools.fillActionMenu(i18n, actionMenu, actionList, GridView.view.model.favoritesModel, model.favoriteId);
|
|
|
|
actionMenu.visualParent = item;
|
|
|
|
actionMenu.open(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
function actionTriggered(actionId, actionArgument) {
|
2022-08-28 21:48:51 +00:00
|
|
|
var close = (Tools.triggerAction(GridView.view.model, model.index, actionId, actionArgument) === true);
|
|
|
|
if (close) {
|
|
|
|
root.toggle();
|
|
|
|
}
|
2021-07-16 19:33:52 +00:00
|
|
|
}
|
|
|
|
|
2022-08-28 21:48:51 +00:00
|
|
|
|
2021-07-16 19:33:52 +00:00
|
|
|
PlasmaCore.IconItem {
|
|
|
|
id: icon
|
2022-08-28 21:48:51 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2021-07-16 19:33:52 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2022-08-28 21:48:51 +00:00
|
|
|
anchors.verticalCenterOffset: -units.gridUnit
|
|
|
|
width: iconSize
|
2021-07-16 19:33:52 +00:00
|
|
|
height: width
|
2022-08-28 21:48:51 +00:00
|
|
|
colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
|
2021-07-16 19:33:52 +00:00
|
|
|
animated: false
|
|
|
|
usesPlasmaTheme: item.GridView.view.usesPlasmaTheme
|
|
|
|
source: model.decoration
|
2022-08-28 21:48:51 +00:00
|
|
|
smooth: plasmoid.configuration.iconSmooth
|
2021-07-16 19:33:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PlasmaComponents.Label {
|
|
|
|
id: label
|
|
|
|
visible: showLabel
|
|
|
|
anchors {
|
2022-08-28 21:48:51 +00:00
|
|
|
horizontalCenter: icon.horizontalCenter
|
|
|
|
top: icon.bottom
|
|
|
|
topMargin: units.smallSpacing
|
2021-07-16 19:33:52 +00:00
|
|
|
}
|
2022-08-28 21:48:51 +00:00
|
|
|
width: parent.width - units.largeSpacing
|
|
|
|
maximumLineCount: 2
|
|
|
|
height: units.gridUnit * 2
|
2021-07-16 19:33:52 +00:00
|
|
|
elide: Text.ElideRight
|
2022-08-28 21:48:51 +00:00
|
|
|
horizontalAlignment: Qt.AlignHCenter
|
|
|
|
verticalAlignment: Qt.AlignTop
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
color: theme.textColor
|
|
|
|
text: ("name" in model ? model.name : model.display)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PlasmaCore.ToolTipArea {
|
|
|
|
id: toolTip
|
|
|
|
|
|
|
|
property string text: model.display
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
active: root.visible && label.truncated
|
|
|
|
mainItem: toolTipDelegate
|
|
|
|
|
|
|
|
onContainsMouseChanged: item.GridView.view.itemContainsMouseChanged(containsMouse)
|
2021-07-16 19:33:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Keys.onPressed: {
|
2022-08-28 21:48:51 +00:00
|
|
|
if (event.key === Qt.Key_Menu && hasActionList) {
|
2021-07-16 19:33:52 +00:00
|
|
|
event.accepted = true;
|
|
|
|
openActionMenu(item);
|
2022-08-28 21:48:51 +00:00
|
|
|
} else if ((event.key === Qt.Key_Enter || event.key === Qt.Key_Return)) {
|
2021-07-16 19:33:52 +00:00
|
|
|
event.accepted = true;
|
|
|
|
|
2022-08-28 21:48:51 +00:00
|
|
|
if ("trigger" in GridView.view.model) {
|
|
|
|
GridView.view.model.trigger(index, "", null);
|
2021-07-16 19:33:52 +00:00
|
|
|
root.toggle();
|
|
|
|
}
|
2022-08-28 21:48:51 +00:00
|
|
|
|
|
|
|
itemGrid.itemActivated(index, "", null);
|
2021-07-16 19:33:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|