1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/*
* Copyright 2013 Bhushan Shah <bhush94@gmail.com>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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, see <http://www.gnu.org/licenses/>
*/
import QtQuick 2.0
import QtQuick.Layouts 1.1
import QtGraphicalEffects 1.0
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as Components
import org.kde.kquickcontrolsaddons 2.0
import org.kde.draganddrop 2.0 as DragDrop
import org.kde.plasma.private.icon 1.0
MouseArea {
id: root
property bool containsAcceptableDrag: false
property int jumpListCount: 0
height: units.iconSizes.desktop + theme.mSize(theme.defaultFont).height
width: units.iconSizes.desktop
Layout.minimumWidth: formFactor === PlasmaCore.Types.Horizontal ? height : units.iconSizes.small
Layout.minimumHeight: formFactor === PlasmaCore.Types.Vertical ? width : units.iconSizes.small
property int formFactor: plasmoid.formFactor
property bool constrained: formFactor == PlasmaCore.Types.Vertical || formFactor == PlasmaCore.Types.Horizontal
hoverEnabled: true
onClicked: logic.open();
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
Plasmoid.icon: logic.icon
Plasmoid.title: logic.name
Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground
Component.onCompleted: {
plasmoid.activated.connect(logic.open);
updateActions()
}
function updateActions() {
plasmoid.removeAction("properties")
plasmoid.removeAction("separator0")
for (var i = 0, length = jumpListCount; i < length; ++i) {
plasmoid.removeAction("jumplist_" + i)
}
var actions = logic.jumpListActions
jumpListCount = actions.length
for (var i = 0; i < jumpListCount; ++i) {
var item = actions[i]
plasmoid.setAction("jumplist_" + i, item.name, item.icon)
}
if (jumpListCount) {
plasmoid.setActionSeparator("separator0")
}
}
function actionTriggered(name) {
if (name.indexOf("jumplist_") === 0) {
var actionIndex = parseInt(name.substr("jumplist_".length))
logic.execJumpList(actionIndex)
}
}
DragDrop.DropArea {
id: dropArea
anchors.fill: parent
preventStealing: true
onDragEnter: root.containsAcceptableDrag = event.mimeData.hasUrls
onDragLeave: root.containsAcceptableDrag = false
onDrop: {
logic.processDrop(event)
root.containsAcceptableDrag = false
}
}
PlasmaCore.IconItem {
id:icon
source: plasmoid.icon
anchors{
left : parent.left
right : parent.right
top : parent.top
bottom : constrained ? parent.bottom : text.top
}
active: root.containsMouse || root.containsAcceptableDrag
usesPlasmaTheme: false
}
DropShadow {
id: textShadow
anchors.fill: text
visible: !constrained
horizontalOffset: units.devicePixelRatio * 2
verticalOffset: horizontalOffset
radius: 9.0
samples: 18
spread: 0.15
color: "black"
source: constrained ? null : text
}
Components.Label {
id : text
text : plasmoid.title
anchors {
left : parent.left
bottom : parent.bottom
right : parent.right
}
height: undefined // unset Label defaults
horizontalAlignment : Text.AlignHCenter
visible: false // rendered by DropShadow
maximumLineCount: 2
color: "white"
elide: Text.ElideRight
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
PlasmaCore.ToolTipArea {
anchors.fill: parent
mainText: logic.name
subText: logic.genericName !== mainText ? logic.genericName :""
icon: logic.icon
}
Logic {
id: logic
url: plasmoid.configuration.url
onJumpListActionsChanged: updateActions()
}
Connections {
target: plasmoid
onExternalData: {
plasmoid.configuration.url = data
}
}
}
|