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