Changeset View
Changeset View
Standalone View
Standalone View
applets/systemtray/package/contents/ui/items/PlasmoidItem.qml
Show All 22 Lines | |||||
23 | AbstractItem { | 23 | AbstractItem { | ||
24 | id: plasmoidContainer | 24 | id: plasmoidContainer | ||
25 | 25 | | |||
26 | property Item applet | 26 | property Item applet | ||
27 | iconItem: applet | 27 | iconItem: applet | ||
28 | text: applet ? applet.title : "" | 28 | text: applet ? applet.title : "" | ||
29 | 29 | | |||
30 | itemId: applet ? applet.pluginName : "" | 30 | itemId: applet ? applet.pluginName : "" | ||
31 | category: applet ? plasmoid.nativeInterface.plasmoidCategory(applet) : "UnknownCategory" | | |||
32 | mainText: applet ? applet.toolTipMainText : "" | 31 | mainText: applet ? applet.toolTipMainText : "" | ||
33 | subText: applet ? applet.toolTipSubText : "" | 32 | subText: applet ? applet.toolTipSubText : "" | ||
34 | icon: applet ? applet.icon : "" | 33 | icon: applet ? applet.icon : "" | ||
35 | mainItem: applet && applet.toolTipItem ? applet.toolTipItem : null | 34 | mainItem: applet && applet.toolTipItem ? applet.toolTipItem : null | ||
36 | textFormat: applet ? applet.toolTipTextFormat : "" | 35 | textFormat: applet ? applet.toolTipTextFormat : "" | ||
37 | status: applet ? applet.status : PlasmaCore.Types.UnknownStatus | 36 | status: applet ? applet.status : PlasmaCore.Types.UnknownStatus | ||
38 | active: root.activeApplet !== applet | 37 | active: root.activeApplet !== applet | ||
39 | 38 | | |||
39 | Component.onDestruction: { | ||||
40 | applet = null | ||||
41 | } | ||||
42 | | ||||
40 | onClicked: { | 43 | onClicked: { | ||
41 | if (applet && mouse.button === Qt.LeftButton) { | 44 | if (applet && mouse.button === Qt.LeftButton) { | ||
42 | applet.expanded = true; | 45 | applet.expanded = true; | ||
43 | } | 46 | } | ||
44 | } | 47 | } | ||
45 | onPressed: { | 48 | onPressed: { | ||
46 | if (mouse.button === Qt.RightButton) { | 49 | if (mouse.button === Qt.RightButton) { | ||
47 | plasmoidContainer.contextMenu(mouse); | 50 | plasmoidContainer.contextMenu(mouse); | ||
48 | } | 51 | } | ||
49 | } | 52 | } | ||
50 | onContextMenu: { | 53 | onContextMenu: { | ||
51 | if (applet) { | 54 | if (applet) { | ||
52 | plasmoid.nativeInterface.showPlasmoidMenu(applet, 0, plasmoidContainer.hidden ? applet.height : 0); | 55 | plasmoid.nativeInterface.showPlasmoidMenu(applet, 0, plasmoidContainer.inHiddenLayout ? applet.height : 0); | ||
53 | } | 56 | } | ||
54 | } | 57 | } | ||
55 | 58 | | |||
56 | onHeightChanged: { | 59 | onHeightChanged: { | ||
57 | if (applet) { | 60 | if (applet) { | ||
58 | applet.width = height | 61 | applet.width = height | ||
59 | } | 62 | } | ||
60 | } | 63 | } | ||
64 | | ||||
65 | //This is to make preloading effective, minimizes the scene changes | ||||
66 | function preloadFullRepresentationItem(fullRepresentationItem) { | ||||
67 | if (fullRepresentationItem && applet.fullRepresentationItem.parent === null) { | ||||
68 | fullRepresentationItem.width = expandedRepresentation.width | ||||
69 | fullRepresentationItem.width = expandedRepresentation.height | ||||
70 | fullRepresentationItem.parent = preloadedStorage; | ||||
71 | } | ||||
72 | } | ||||
73 | | ||||
61 | onAppletChanged: { | 74 | onAppletChanged: { | ||
62 | if (!applet) { | 75 | if (applet) { | ||
63 | plasmoidContainer.destroy(); | 76 | applet.parent = plasmoidContainer | ||
64 | print("applet destroyed") | 77 | applet.anchors.left = plasmoidContainer.left | ||
78 | applet.anchors.top = plasmoidContainer.top | ||||
79 | applet.anchors.bottom = plasmoidContainer.bottom | ||||
80 | applet.width = plasmoidContainer.height | ||||
81 | applet.visible = true | ||||
82 | plasmoidContainer.visible = true | ||||
83 | | ||||
84 | preloadFullRepresentationItem(applet.fullRepresentationItem) | ||||
65 | } | 85 | } | ||
66 | } | 86 | } | ||
87 | | ||||
67 | Connections { | 88 | Connections { | ||
68 | target: applet | 89 | target: applet | ||
69 | onActivated: plasmoidContainer.activated() | 90 | onActivated: plasmoidContainer.activated() | ||
70 | 91 | | |||
71 | onExpandedChanged: { | 92 | onExpandedChanged: { | ||
72 | if (expanded) { | 93 | if (expanded) { | ||
73 | var oldApplet = root.activeApplet; | 94 | var oldApplet = root.activeApplet; | ||
74 | root.activeApplet = applet; | 95 | root.activeApplet = applet; | ||
75 | if (oldApplet) { | 96 | if (oldApplet && oldApplet !== applet) { | ||
76 | oldApplet.expanded = false; | 97 | oldApplet.expanded = false; | ||
77 | } | 98 | } | ||
78 | dialog.visible = true; | 99 | dialog.visible = true; | ||
79 | plasmoidContainer.activated() | 100 | plasmoidContainer.activated() | ||
80 | 101 | | |||
81 | } else if (root.activeApplet === applet) { | 102 | } else if (root.activeApplet === applet) { | ||
82 | if (!applet.parent.hidden) { | 103 | if (!inHiddenLayout) { | ||
83 | dialog.visible = false; | 104 | dialog.visible = false; | ||
84 | } | 105 | } | ||
85 | //if not expanded we don't have an active applet anymore | 106 | //if not expanded we don't have an active applet anymore | ||
86 | root.activeApplet = null; | 107 | root.activeApplet = null; | ||
87 | } | 108 | } | ||
88 | } | 109 | } | ||
110 | | ||||
111 | onFullRepresentationItemChanged: { | ||||
112 | preloadFullRepresentationItem(fullRepresentationItem) | ||||
113 | } | ||||
89 | } | 114 | } | ||
90 | } | 115 | } |