You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

119 lines
3.9 KiB

/*
* Copyright 2015 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, 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 Library General Public License for more details
*
* You should have received a copy of the GNU Library 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.1
import org.kde.plasma.core 2.0 as PlasmaCore
AbstractItem {
id: plasmoidContainer
property Item applet
iconItem: applet
text: applet ? applet.title : ""
itemId: applet ? applet.pluginName : ""
category: applet ? plasmoid.nativeInterface.plasmoidCategory(applet) : "UnknownCategory"
mainText: applet ? applet.toolTipMainText : ""
subText: applet ? applet.toolTipSubText : ""
icon: applet ? applet.icon : ""
mainItem: applet && applet.toolTipItem ? applet.toolTipItem : null
textFormat: applet ? applet.toolTipTextFormat : ""
status: applet ? applet.status : PlasmaCore.Types.UnknownStatus
active: root.activeApplet !== applet
Component.onDestruction: {
applet = null
}
onClicked: {
if (applet && mouse.button === Qt.LeftButton) {
applet.expanded = true;
}
}
onPressed: {
if (mouse.button === Qt.RightButton) {
plasmoidContainer.contextMenu(mouse);
}
}
onContextMenu: {
if (applet) {
plasmoid.nativeInterface.showPlasmoidMenu(applet, 0, plasmoidContainer.inHiddenLayout ? applet.height : 0);
}
}
onHeightChanged: {
if (applet) {
applet.width = height
}
}
//This is to make preloading effective, minimizes the scene changes
function preloadFullRepresentationItem(fullRepresentationItem) {
if (fullRepresentationItem && applet.fullRepresentationItem.parent === null) {
fullRepresentationItem.width = expandedRepresentation.width
fullRepresentationItem.width = expandedRepresentation.height
fullRepresentationItem.parent = preloadedStorage;
}
}
onAppletChanged: {
if (applet) {
applet.parent = plasmoidContainer
applet.anchors.left = plasmoidContainer.left
applet.anchors.top = plasmoidContainer.top
applet.anchors.bottom = plasmoidContainer.bottom
applet.width = plasmoidContainer.height
applet.visible = true
plasmoidContainer.visible = true
preloadFullRepresentationItem(applet.fullRepresentationItem)
}
if (!applet) {
plasmoidContainer.destroy();
}
}
Connections {
target: applet
onActivated: plasmoidContainer.activated()
onExpandedChanged: {
if (expanded) {
var oldApplet = root.activeApplet;
root.activeApplet = applet;
if (oldApplet && oldApplet !== applet) {
oldApplet.expanded = false;
}
dialog.visible = true;
plasmoidContainer.activated()
} else if (root.activeApplet === applet) {
if (!inHiddenLayout) {
dialog.visible = false;
}
//if not expanded we don't have an active applet anymore
root.activeApplet = null;
}
}
onFullRepresentationItemChanged: {
preloadFullRepresentationItem(fullRepresentationItem)
}
}
}