mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-15 06:45:48 +00:00
wayland support
This commit is contained in:
@ -21,17 +21,11 @@ import QtQuick.Layouts 1.1
|
||||
import org.kde.plasma.plasmoid 2.0
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||
|
||||
import org.kde.plasma.private.desktoppanel 1.0
|
||||
import "."
|
||||
|
||||
|
||||
Item {
|
||||
id: main
|
||||
// backend
|
||||
DPAdds {
|
||||
id: dpAdds
|
||||
}
|
||||
|
||||
property bool debug: dpAdds.isDebugEnabled()
|
||||
property variant tooltipSettings: {
|
||||
@ -40,20 +34,113 @@ Item {
|
||||
"tooltipWidth": plasmoid.configuration.tooltipWidth
|
||||
}
|
||||
|
||||
signal needUpdate
|
||||
signal needTooltipUpdate
|
||||
signal sizeUpdate
|
||||
|
||||
signal needUpdate()
|
||||
signal needTooltipUpdate()
|
||||
signal sizeUpdate()
|
||||
|
||||
// init
|
||||
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
|
||||
Plasmoid.compactRepresentation: Plasmoid.fullRepresentation
|
||||
|
||||
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
|
||||
|
||||
Plasmoid.icon: "utilities-system-monitor"
|
||||
Plasmoid.backgroundHints: plasmoid.configuration.background ? "DefaultBackground" : "NoBackground"
|
||||
onNeedUpdate: {
|
||||
if (debug)
|
||||
console.debug();
|
||||
|
||||
for (var i = 0; i < repeater.count; i++) {
|
||||
if (!repeater.itemAt(i)) {
|
||||
if (debug)
|
||||
console.info("Nothing to do here yet", i);
|
||||
|
||||
timer.start();
|
||||
return ;
|
||||
}
|
||||
repeater.itemAt(i).text = dpAdds.parsePattern(plasmoid.configuration.text, i);
|
||||
if (dpAdds.currentDesktop() === i) {
|
||||
repeater.itemAt(i).color = plasmoid.configuration.currentFontColor;
|
||||
repeater.itemAt(i).font.family = plasmoid.configuration.currentFontFamily;
|
||||
repeater.itemAt(i).font.italic = plasmoid.configuration.currentFontStyle === "italic";
|
||||
repeater.itemAt(i).font.pointSize = plasmoid.configuration.currentFontSize;
|
||||
repeater.itemAt(i).font.weight = General.fontWeight[plasmoid.configuration.currentFontWeight];
|
||||
repeater.itemAt(i).style = General.textStyle[plasmoid.configuration.currentTextStyle];
|
||||
repeater.itemAt(i).styleColor = plasmoid.configuration.currentTextStyleColor;
|
||||
} else {
|
||||
repeater.itemAt(i).color = plasmoid.configuration.fontColor;
|
||||
repeater.itemAt(i).font.family = plasmoid.configuration.fontFamily;
|
||||
repeater.itemAt(i).font.italic = plasmoid.configuration.fontStyle === "italic";
|
||||
repeater.itemAt(i).font.pointSize = plasmoid.configuration.fontSize;
|
||||
repeater.itemAt(i).font.weight = General.fontWeight[plasmoid.configuration.fontWeight];
|
||||
repeater.itemAt(i).style = General.textStyle[plasmoid.configuration.textStyle];
|
||||
repeater.itemAt(i).styleColor = plasmoid.configuration.textStyleColor;
|
||||
}
|
||||
repeater.itemAt(i).update();
|
||||
}
|
||||
sizeUpdate();
|
||||
needTooltipUpdate();
|
||||
}
|
||||
onNeedTooltipUpdate: {
|
||||
if (debug)
|
||||
console.debug();
|
||||
|
||||
for (var i = 0; i < repeater.count; i++) {
|
||||
repeater.itemAt(i).tooltip.text = dpAdds.toolTipImage(i);
|
||||
// resize text tooltip to content size
|
||||
// this hack does not work for images-based tooltips
|
||||
if (tooltipSettings.tooltipType === "names") {
|
||||
repeater.itemAt(i).tooltip.height = repeater.itemAt(i).tooltip.implicitHeight;
|
||||
repeater.itemAt(i).tooltip.width = repeater.itemAt(i).tooltip.implicitWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
onSizeUpdate: {
|
||||
if (debug)
|
||||
console.debug();
|
||||
|
||||
if (plasmoid.configuration.height === 0) {
|
||||
var newHeight = 0;
|
||||
for (var i = 0; i < repeater.count; i++) newHeight += repeater.itemAt(i).contentHeight
|
||||
Layout.minimumHeight = newHeight;
|
||||
Layout.maximumHeight = -1;
|
||||
} else {
|
||||
Layout.minimumHeight = plasmoid.configuration.height;
|
||||
Layout.maximumHeight = plasmoid.configuration.height;
|
||||
}
|
||||
if (plasmoid.configuration.width === 0) {
|
||||
var newWidth = 0;
|
||||
for (var i = 0; i < repeater.count; i++) newWidth += repeater.itemAt(i).contentWidth
|
||||
Layout.minimumWidth = newWidth;
|
||||
Layout.maximumWidth = -1;
|
||||
} else {
|
||||
Layout.minimumWidth = plasmoid.configuration.width;
|
||||
Layout.maximumWidth = plasmoid.configuration.width;
|
||||
}
|
||||
}
|
||||
Plasmoid.onUserConfiguringChanged: {
|
||||
if (plasmoid.userConfiguring)
|
||||
return ;
|
||||
|
||||
if (debug)
|
||||
console.debug();
|
||||
|
||||
dpAdds.setMark(plasmoid.configuration.mark);
|
||||
dpAdds.setToolTipData(tooltipSettings);
|
||||
needUpdate();
|
||||
}
|
||||
Component.onCompleted: {
|
||||
if (debug)
|
||||
console.debug();
|
||||
|
||||
// init submodule
|
||||
Plasmoid.userConfiguringChanged(false);
|
||||
dpAdds.desktopChanged.connect(needUpdate);
|
||||
dpAdds.windowListChanged.connect(needTooltipUpdate);
|
||||
}
|
||||
|
||||
// backend
|
||||
DPAdds {
|
||||
id: dpAdds
|
||||
}
|
||||
|
||||
// ui
|
||||
GridLayout {
|
||||
@ -63,140 +150,56 @@ Item {
|
||||
|
||||
Repeater {
|
||||
id: repeater
|
||||
|
||||
Layout.columnSpan: 0
|
||||
Layout.rowSpan: 0
|
||||
model: dpAdds.numberOfDesktops()
|
||||
|
||||
Text {
|
||||
id: text
|
||||
|
||||
property alias tooltip: tooltip
|
||||
|
||||
height: contentHeight
|
||||
width: contentWidth
|
||||
renderType: Text.NativeRendering
|
||||
textFormat: Text.RichText
|
||||
wrapMode: Text.NoWrap
|
||||
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
|
||||
text: dpAdds.parsePattern(plasmoid.configuration.text, index + 1)
|
||||
property alias tooltip: tooltip
|
||||
text: dpAdds.parsePattern(plasmoid.configuration.text, index)
|
||||
|
||||
MouseArea {
|
||||
hoverEnabled: true
|
||||
anchors.fill: parent
|
||||
onClicked: dpAdds.setCurrentDesktop(index + 1)
|
||||
onClicked: dpAdds.setCurrentDesktop(index)
|
||||
onEntered: needTooltipUpdate()
|
||||
}
|
||||
|
||||
PlasmaCore.ToolTipArea {
|
||||
height: tooltip.height
|
||||
width: tooltip.width
|
||||
|
||||
mainItem: Text {
|
||||
id: tooltip
|
||||
|
||||
height: contentHeight
|
||||
width: contentWidth
|
||||
textFormat: Text.RichText
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: timer
|
||||
|
||||
interval: 1000
|
||||
onTriggered: needUpdate()
|
||||
}
|
||||
|
||||
onNeedUpdate: {
|
||||
if (debug) console.debug()
|
||||
|
||||
for (var i=0; i<repeater.count; i++) {
|
||||
if (!repeater.itemAt(i)) {
|
||||
if (debug) console.info("Nothing to do here yet", i)
|
||||
timer.start()
|
||||
return
|
||||
}
|
||||
repeater.itemAt(i).text = dpAdds.parsePattern(plasmoid.configuration.text, i + 1)
|
||||
if (dpAdds.currentDesktop() == i + 1) {
|
||||
repeater.itemAt(i).color = plasmoid.configuration.currentFontColor
|
||||
repeater.itemAt(i).font.family = plasmoid.configuration.currentFontFamily
|
||||
repeater.itemAt(i).font.italic = plasmoid.configuration.currentFontStyle == "italic" ? true : false
|
||||
repeater.itemAt(i).font.pointSize = plasmoid.configuration.currentFontSize
|
||||
repeater.itemAt(i).font.weight = General.fontWeight[plasmoid.configuration.currentFontWeight]
|
||||
repeater.itemAt(i).style = General.textStyle[plasmoid.configuration.currentTextStyle]
|
||||
repeater.itemAt(i).styleColor = plasmoid.configuration.currentTextStyleColor
|
||||
} else {
|
||||
repeater.itemAt(i).color = plasmoid.configuration.fontColor
|
||||
repeater.itemAt(i).font.family = plasmoid.configuration.fontFamily
|
||||
repeater.itemAt(i).font.italic = plasmoid.configuration.fontStyle == "italic" ? true : false
|
||||
repeater.itemAt(i).font.pointSize = plasmoid.configuration.fontSize
|
||||
repeater.itemAt(i).font.weight = General.fontWeight[plasmoid.configuration.fontWeight]
|
||||
repeater.itemAt(i).style = General.textStyle[plasmoid.configuration.textStyle]
|
||||
repeater.itemAt(i).styleColor = plasmoid.configuration.textStyleColor
|
||||
}
|
||||
repeater.itemAt(i).update()
|
||||
}
|
||||
|
||||
sizeUpdate()
|
||||
needTooltipUpdate()
|
||||
}
|
||||
|
||||
onNeedTooltipUpdate: {
|
||||
if (debug) console.debug()
|
||||
|
||||
for (var i=0; i<repeater.count; i++) {
|
||||
repeater.itemAt(i).tooltip.text = dpAdds.toolTipImage(i + 1)
|
||||
// resize text tooltip to content size
|
||||
// this hack does not work for images-based tooltips
|
||||
if (tooltipSettings.tooltipType == "names") {
|
||||
repeater.itemAt(i).tooltip.height = repeater.itemAt(i).tooltip.implicitHeight
|
||||
repeater.itemAt(i).tooltip.width = repeater.itemAt(i).tooltip.implicitWidth
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onSizeUpdate: {
|
||||
if (debug) console.debug()
|
||||
|
||||
if (plasmoid.configuration.height == 0) {
|
||||
var newHeight = 0
|
||||
for (var i=0; i<repeater.count; i++)
|
||||
newHeight += repeater.itemAt(i).contentHeight
|
||||
Layout.minimumHeight = newHeight
|
||||
Layout.maximumHeight = -1
|
||||
} else {
|
||||
Layout.minimumHeight = plasmoid.configuration.height
|
||||
Layout.maximumHeight = plasmoid.configuration.height
|
||||
}
|
||||
if (plasmoid.configuration.width == 0) {
|
||||
var newWidth = 0
|
||||
for (var i=0; i<repeater.count; i++)
|
||||
newWidth += repeater.itemAt(i).contentWidth
|
||||
Layout.minimumWidth = newWidth
|
||||
Layout.maximumWidth = -1
|
||||
} else {
|
||||
Layout.minimumWidth = plasmoid.configuration.width
|
||||
Layout.maximumWidth = plasmoid.configuration.width
|
||||
}
|
||||
}
|
||||
|
||||
Plasmoid.onUserConfiguringChanged: {
|
||||
if (plasmoid.userConfiguring) return
|
||||
if (debug) console.debug()
|
||||
|
||||
dpAdds.setMark(plasmoid.configuration.mark)
|
||||
dpAdds.setToolTipData(tooltipSettings)
|
||||
|
||||
needUpdate()
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
if (debug) console.debug()
|
||||
|
||||
// init submodule
|
||||
Plasmoid.userConfiguringChanged(false)
|
||||
dpAdds.desktopChanged.connect(needUpdate)
|
||||
dpAdds.windowListChanged.connect(needTooltipUpdate)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user