update DP

update aw-kde4
This commit is contained in:
arcan1s 2015-02-08 12:57:25 +03:00
parent 6e27717dc8
commit 16d7d2bc20
15 changed files with 797 additions and 689 deletions

View File

@ -53,7 +53,6 @@ public:
// de configuration // de configuration
QMap<QString, QString> readDataEngineConfiguration(); QMap<QString, QString> readDataEngineConfiguration();
void writeDataEngineConfiguration(const QMap<QString, QString> settings); void writeDataEngineConfiguration(const QMap<QString, QString> settings);
QMap<QString, QString> updateDataEngineConfiguration(const QMap<QString, QString> rawConfig);
public slots: public slots:
// contextual actions // contextual actions

View File

@ -47,15 +47,13 @@ QMap<QString, QString> AwesomeWidget::readDataEngineConfiguration()
rawConfig[QString("MPDADDRESS")] = QString("localhost"); rawConfig[QString("MPDADDRESS")] = QString("localhost");
rawConfig[QString("MPDPORT")] = QString("6600"); rawConfig[QString("MPDPORT")] = QString("6600");
rawConfig[QString("MPRIS")] = QString("auto"); rawConfig[QString("MPRIS")] = QString("auto");
rawConfig[QString("PKGCMD")] = QString("pacman -Qu");
rawConfig[QString("PKGNULL")] = QString("0");
rawConfig[QString("PLAYER")] = QString("mpris"); rawConfig[QString("PLAYER")] = QString("mpris");
QString fileName = KGlobal::dirs()->findResource("config", "plasma-dataengine-extsysmon.conf"); QString fileName = KGlobal::dirs()->findResource("config", "plasma-dataengine-extsysmon.conf");
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName; if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName;
QFile configFile(fileName); QFile configFile(fileName);
if (!configFile.open(QIODevice::ReadOnly)) if (!configFile.open(QIODevice::ReadOnly))
return updateDataEngineConfiguration(rawConfig); return rawConfig;
QString fileStr; QString fileStr;
QStringList value; QStringList value;
while (true) { while (true) {
@ -73,7 +71,7 @@ QMap<QString, QString> AwesomeWidget::readDataEngineConfiguration()
} }
configFile.close(); configFile.close();
return updateDataEngineConfiguration(rawConfig); return rawConfig;
} }
@ -81,7 +79,7 @@ void AwesomeWidget::writeDataEngineConfiguration(const QMap<QString, QString> se
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QMap<QString, QString> config = updateDataEngineConfiguration(settings); QMap<QString, QString> config = settings;
QString fileName = KGlobal::dirs()->locateLocal("config", "plasma-dataengine-extsysmon.conf"); QString fileName = KGlobal::dirs()->locateLocal("config", "plasma-dataengine-extsysmon.conf");
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName; if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName;
QFile configFile(fileName); QFile configFile(fileName);
@ -94,35 +92,6 @@ void AwesomeWidget::writeDataEngineConfiguration(const QMap<QString, QString> se
} }
QMap<QString, QString> AwesomeWidget::updateDataEngineConfiguration(const QMap<QString, QString> rawConfig)
{
if (debug) qDebug() << PDEBUG;
QMap<QString, QString> config;
QString key, value;
// remove spaces and copy source map
for (int i=0; i<rawConfig.keys().count(); i++) {
key = rawConfig.keys()[i];
value = rawConfig[key];
key.remove(QChar(' '));
if ((key != QString("HDDTEMPCMD")) &&
(key != QString("PKGCMD")))
value.remove(QChar(' '));
config[key] = value;
}
// pkgcmd
for (int i=config[QString("PKGNULL")].split(QString(","), QString::SkipEmptyParts).count();
i<config[QString("PKGCMD")].split(QString(","), QString::SkipEmptyParts).count()+1;
i++)
config[QString("PKGNULL")] += QString(",0");
for (int i=0; i<config.keys().count(); i++)
if (debug) qDebug() << PDEBUG << ":" << config.keys()[i] + QString("=") + config[config.keys()[i]];
return config;
}
void AwesomeWidget::createConfigurationInterface(KConfigDialog *parent) void AwesomeWidget::createConfigurationInterface(KConfigDialog *parent)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;

View File

@ -282,7 +282,7 @@ void AwesomeWidget::dataUpdated(const QString &sourceName, const Plasma::DataEng
break; break;
} }
} else if (sourceName == QString("gpu")) { } else if (sourceName == QString("gpu")) {
values[QString("gpu")] = QString("%1").arg(data[QString("GPU")].toFloat(), 5, 'f', 1); values[QString("gpu")] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 1);
if (foundBars.indexOf(QRegExp(QString("bar[0-9].*gpu"))) > -1) { if (foundBars.indexOf(QRegExp(QString("bar[0-9].*gpu"))) > -1) {
for (int j=0; j<foundBars.count(); j++) { for (int j=0; j<foundBars.count(); j++) {
if (getItemByTag(foundBars[j])->bar() != QString("gpu")) continue; if (getItemByTag(foundBars[j])->bar() != QString("gpu")) continue;
@ -290,7 +290,7 @@ void AwesomeWidget::dataUpdated(const QString &sourceName, const Plasma::DataEng
} }
} }
} else if (sourceName == QString("gputemp")) { } else if (sourceName == QString("gputemp")) {
values[QString("gputemp")] = QString("%1").arg(getTemp(data[QString("GPUTemp")].toFloat()), 4, 'f', 1); values[QString("gputemp")] = QString("%1").arg(getTemp(data[QString("value")].toFloat()), 4, 'f', 1);
} else if (sourceName.contains(mountFillRegExp)) { } else if (sourceName.contains(mountFillRegExp)) {
QString mount = sourceName; QString mount = sourceName;
mount.remove(QString("partitions")); mount.remove(QString("partitions"));

View File

@ -146,8 +146,8 @@ Item {
PlasmaCore.ToolTipArea { PlasmaCore.ToolTipArea {
id: rootTooltip id: rootTooltip
mainItem: Text { mainItem: Text {
id: tooltip id: tooltip
textFormat: Text.RichText textFormat: Text.RichText
} }
} }
} }
@ -180,6 +180,8 @@ Item {
} }
Plasmoid.onUserConfiguringChanged: { Plasmoid.onUserConfiguringChanged: {
if (debug) console.log("[main::onUserConfiguringChanged]")
// init submodule // init submodule
AWKeys.initKeys(plasmoid.configuration.text, tooltipSettings) AWKeys.initKeys(plasmoid.configuration.text, tooltipSettings)
} }

View File

@ -122,10 +122,10 @@ QString AWKeys::parsePattern(const QString pattern)
if (!ready) return pattern; if (!ready) return pattern;
QString parsed = pattern; QString parsed = pattern;
parsed.replace(QString(" "), QString("&nbsp;"));
parsed.replace(QString("$$"), QString("$\\$\\")); parsed.replace(QString("$$"), QString("$\\$\\"));
for (int i=0; i<foundKeys.count(); i++) for (int i=0; i<foundKeys.count(); i++)
parsed.replace(QString("$") + foundKeys[i], valueByKey(foundKeys[i])); parsed.replace(QString("$") + foundKeys[i], valueByKey(foundKeys[i]));
parsed.replace(QString(" "), QString("&nbsp;"));
for (int i=0; i<foundBars.count(); i++) for (int i=0; i<foundBars.count(); i++)
parsed.replace(QString("$") + foundBars[i], getItemByTag(foundBars[i])->image(valueByKey(foundBars[i]).toFloat())); parsed.replace(QString("$") + foundBars[i], getItemByTag(foundBars[i])->image(valueByKey(foundBars[i]).toFloat()));
parsed.replace(QString("$\\$\\"), QString("$$")); parsed.replace(QString("$\\$\\"), QString("$$"));

View File

@ -34,9 +34,15 @@ ConfigModel {
} }
ConfigCategory { ConfigCategory {
name: i18n("Appearance") name: i18n("Active desktop")
icon: "preferences-desktop-theme" icon: "preferences-desktop-theme"
source: "appearance.qml" source: "activeapp.qml"
}
ConfigCategory {
name: i18n("Inactive desktop")
icon: "preferences-desktop-theme"
source: "inactiveapp.qml"
} }
ConfigCategory { ConfigCategory {

View File

@ -8,7 +8,7 @@
<group name="Widget"> <group name="Widget">
<!-- widget --> <!-- widget -->
<entry name="text" type="string"> <entry name="text" type="string">
<default>[$fullmark$number/$total: $name]</default> <default>[$mark$number/$total: $name]</default>
</entry> </entry>
</group> </group>

View File

@ -0,0 +1,219 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets 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 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls
import QtQuick.Controls.Styles 1.3 as QtStyles
import QtQuick.Dialogs 1.1 as QtDialogs
import org.kde.plasma.private.desktoppanel 1.0
Item {
id: activeAppearancePage
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: DPAdds.isDebugEnabled()
property variant weight: {
25: 0,
50: 1,
63: 3,
75: 4,
87: 5
}
property alias cfg_currentFontFamily: selectFont.text
property alias cfg_currentFontSize: fontSize.value
property string cfg_currentFontWeight: fontWeight.currentText
property string cfg_currentFontStyle: fontStyle.currentText
property alias cfg_currentFontColor: selectColor.text
Column {
id: pageColumn
width: units.gridUnit * 25
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font")
}
QtControls.Button {
id: selectFont
width: parent.width * 2 / 3
text: plasmoid.configuration.currentFontFamily
onClicked: fontDialog.visible = true
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font size")
}
QtControls.SpinBox {
id: fontSize
width: parent.width * 2 / 3
minimumValue: 8
maximumValue: 32
stepSize: 1
value: plasmoid.configuration.currentFontSize
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font weight")
}
QtControls.ComboBox {
id: fontWeight
width: parent.width * 2 / 3
textRole: "label"
model: [
{
'label': i18n("light"),
'name': "light"
},
{
'label': i18n("normal"),
'name': "normal"
},
{
'label': i18n("demi bold"),
'name': "demibold"
},
{
'label': i18n("bold"),
'name': "bold"
},
{
'label': i18n("black"),
'name': "black"
}
]
onCurrentIndexChanged: cfg_currentFontWeight = model[currentIndex]["name"]
Component.onCompleted: {
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.currentFontWeight) {
currentFontWeight.currentIndex = i;
}
}
}
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font style")
}
QtControls.ComboBox {
id: fontStyle
width: parent.width * 2 / 3
textRole: "label"
model: [
{
'label': i18n("normal"),
'name': "normal"
},
{
'label': i18n("italic"),
'name': "italic"
}
]
onCurrentIndexChanged: cfg_currentFontStyle = model[currentIndex]["name"]
Component.onCompleted: {
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.currentFontStyle) {
currentFontStyle.currentIndex = i;
}
}
}
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font color")
}
QtControls.Button {
id: selectColor
width: parent.width * 2 / 3
style: QtStyles.ButtonStyle {
background: Rectangle {
color: plasmoid.configuration.currentFontColor
}
}
text: plasmoid.configuration.currentFontColor
onClicked: colorDialog.visible = true
}
}
}
QtDialogs.ColorDialog {
id: colorDialog
title: i18n("Select a color")
color: selectColor.text
onAccepted: selectColor.text = colorDialog.color
}
QtDialogs.FontDialog {
id: fontDialog
title: i18n("Select a font")
font: Qt.font({ family: selectFont.text, pointSize: fontSize.value, weight: Font.Normal })
onAccepted: {
selectFont.text = fontDialog.font.family
fontSize.value = fontDialog.font.pointSize
fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0
fontWeight.currentIndex = weight[fontDialog.font.weight]
}
}
Component.onCompleted: {
if (debug) console.log("[activeapp::onCompleted]")
}
}

View File

@ -17,9 +17,10 @@
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls import QtQuick.Controls 1.3 as QtControls
import org.kde.plasma.core 2.0 as PlasmaCore import QtQuick.Controls.Styles 1.3 as QtStyles
import QtQuick.Dialogs 1.1 as QtDialogs
import org.kde.plasma.private.awesomewidget 1.0 import org.kde.plasma.private.desktoppanel 1.0
Item { Item {
@ -29,46 +30,109 @@ Item {
implicitWidth: pageColumn.implicitWidth implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight implicitHeight: pageColumn.implicitHeight
property bool debug: AWKeys.isDebugEnabled() property bool debug: DPAdds.isDebugEnabled()
property variant settings: {
"customTime": plasmoid.configuration.customTime,
"customUptime": plasmoid.configuration.customUptime,
"tempUnits": plasmoid.configuration.tempUnits,
"acOnline": plasmoid.configuration.acOnline,
"acOffline": plasmoid.configuration.acOffline
}
property variant tooltipSettings: {
"tooltipNumber": plasmoid.configuration.tooltipNumber,
"useTooltipBackground": plasmoid.configuration.useTooltipBackground,
"tooltipBackgroung": plasmoid.configuration.tooltipBackgroung,
"cpuTooltip": plasmoid.configuration.cpuTooltip,
"cpuclTooltip": plasmoid.configuration.cpuclTooltip,
"memTooltip": plasmoid.configuration.memTooltip,
"swapTooltip": plasmoid.configuration.swapTooltip,
"downTooltip": plasmoid.configuration.downTooltip,
"upTooltip": plasmoid.configuration.downTooltip,
"batTooltip": plasmoid.configuration.batTooltip,
"cpuTooltipColor": plasmoid.configuration.cpuTooltipColor,
"cpuclTooltipColor": plasmoid.configuration.cpuclTooltipColor,
"memTooltipColor": plasmoid.configuration.memTooltipColor,
"swapTooltipColor": plasmoid.configuration.swapTooltipColor,
"downTooltipColor": plasmoid.configuration.downTooltipColor,
"upTooltipColor": plasmoid.configuration.upTooltipColor,
"batTooltipColor": plasmoid.configuration.batTooltipColor,
"batInTooltipColor": plasmoid.configuration.batInTooltipColor
}
property string cfg_tooltipType: tooltipType.currentText
property alias cfg_tooltipWidth: tooltipWidth.value
property alias cfg_tooltipColor: tooltipColor.text
property alias cfg_background: background.checked property alias cfg_background: background.checked
property alias cfg_customTime: customTime.text property alias cfg_verticalLayout: verticalLayout.checked
property alias cfg_customUptime: customUptime.text property string cfg_mark: mark.currentText
property string cfg_tempUnits: tempUnits.currentText
property alias cfg_acOnline: acOnline.text
property alias cfg_acOffline: acOffline.text
Column { Column {
id: pageColumn id: pageColumn
width: units.gridUnit * 25 width: units.gridUnit * 25
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Tooltip type")
}
QtControls.ComboBox {
id: tooltipType
width: parent.width * 3 / 5
textRole: "label"
model: [
{
'label': i18n("contours"),
'name': "contours"
},
{
'label': i18n("windows"),
'name': "windows"
},
{
'label': i18n("clean desktop"),
'name': "clean"
},
{
'label': i18n("names"),
'name': "names"
},
{
'label': i18n("none"),
'name': "none"
}
]
onCurrentIndexChanged: cfg_tooltipType = model[currentIndex]["name"]
Component.onCompleted: {
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.tooltipType) {
tooltipType.currentIndex = i;
}
}
}
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Tooltip width")
}
QtControls.SpinBox {
id: tooltipWidth
width: parent.width * 3 / 5
minimumValue: 100
maximumValue: 1000
stepSize: 50
value: plasmoid.configuration.tooltipWidth
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font color")
}
QtControls.Button {
id: tooltipColor
width: parent.width * 3 / 5
style: QtStyles.ButtonStyle {
background: Rectangle {
color: plasmoid.configuration.tooltipColor
}
}
text: plasmoid.configuration.tooltipColor
onClicked: colorDialog.visible = true
}
}
Row { Row {
height: implicitHeight height: implicitHeight
width: parent.width width: parent.width
@ -87,16 +151,13 @@ Item {
height: implicitHeight height: implicitHeight
width: parent.width width: parent.width
QtControls.Label { QtControls.Label {
height: parent.height height: parent.heigth
width: parent.width * 2 / 5 width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Custom time format")
} }
QtControls.TextField { QtControls.CheckBox {
id: customTime id: verticalLayout
width: parent.width * 3 / 5 width: parent.width * 3 / 5
text: plasmoid.configuration.customTime text: i18n("Vertical layout")
} }
} }
@ -108,67 +169,16 @@ Item {
width: parent.width * 2 / 5 width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
text: i18n("Custom uptime format") text: i18n("Mark")
}
QtControls.TextField {
id: customUptime
width: parent.width * 3 / 5
text: plasmoid.configuration.customUptime
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Temperature units")
} }
QtControls.ComboBox { QtControls.ComboBox {
id: tempUnits id: mark
width: parent.width * 3 / 5 width: parent.width * 3 / 5
textRole: "label" editable: true
model: [ model: ["#", "$", "%", "&", "*", "@", "¤", "¶", "·", "º",
{ plasmoid.configuration.mark]
'label': i18n("Celsius"), currentIndex: model.length - 1
'name': "Celsius" onCurrentIndexChanged: cfg_mark = currentText
},
{
'label': i18n("Fahrenheit"),
'name': "Fahrenheit"
},
{
'label': i18n("Kelvin"),
'name': "Kelvin"
},
{
'label': i18n("Reaumur"),
'name': "Reaumur"
},
{
'label': i18n("cm^-1"),
'name': "cm^-1"
},
{
'label': i18n("kJ/mol"),
'name': "kJ/mol"
},
{
'label': i18n("kcal/mol"),
'name': "kcal/mol"
}
]
onCurrentIndexChanged: cfg_tempUnits = model[currentIndex]["name"]
Component.onCompleted: {
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.tempUnits) {
tempUnits.currentIndex = i;
}
}
}
} }
} }
@ -180,96 +190,24 @@ Item {
width: parent.width * 2 / 5 width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
text: i18n("AC online tag") text: i18n("Panels to be hidden")
}
QtControls.TextField {
id: acOnline
width: parent.width * 3 / 5
text: plasmoid.configuration.acOnline
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("AC offline tag")
}
QtControls.TextField {
id: acOffline
width: parent.width * 3 / 5
text: plasmoid.configuration.acOffline
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Bars")
} }
QtControls.Button { QtControls.Button {
width: parent.width * 3 / 5 width: parent.width * 3 / 5
text: i18n("Edit bars") text: i18n("Edit panels")
onClicked: AWKeys.editItem("graphicalitem") onClicked: cfg_panels = DPAdds.editPanelsToContol(plasmoid.configuration.panels)
} }
} }
} }
// we need to initializate DataEngines here too QtDialogs.ColorDialog {
// because we need to get keys and values id: colorDialog
PlasmaCore.DataSource { title: i18n("Select a color")
id: systemmonitorDE color: tooltipColor.text
engine: "systemmonitor" onAccepted: tooltipColor.text = colorDialog.color
connectedSources: systemmonitorDE.sources
interval: 5000
onNewData: {
if (debug) console.log("[advanced::onNewData] : Update source " + sourceName)
AWKeys.setDataBySource(sourceName, data, settings)
}
}
PlasmaCore.DataSource {
id: extsysmonDE
engine: "extsysmon"
connectedSources: ["battery", "custom", "desktop", "netdev", "gpu",
"gputemp", "hddtemp", "pkg", "player", "ps", "update"]
interval: 5000
onNewData: {
if (debug) console.log("[advanced::onNewData] : Update source " + sourceName)
AWKeys.setDataBySource(sourceName, data, settings)
}
}
PlasmaCore.DataSource {
id: timeDE
engine: "time"
connectedSources: ["Local"]
interval: 5000
onNewData: {
if (debug) console.log("[advanced::onNewData] : Update source " + sourceName)
AWKeys.setDataBySource(sourceName, data, settings)
}
} }
Component.onCompleted: { Component.onCompleted: {
if (debug) console.log("[advanced::onCompleted]") if (debug) console.log("[advanced::onCompleted]")
// init submodule
AWKeys.initKeys(plasmoid.configuration.text, tooltipSettings)
} }
} }

View File

@ -1,402 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets 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 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls
import QtQuick.Layouts 1.0 as QtLayouts
import QtQuick.Controls.Styles 1.3 as QtStyles
import QtQuick.Dialogs 1.1 as QtDialogs
import org.kde.plasma.private.desktoppanel 1.0
Item {
id: appearancePage
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: DPAdds.isDebugEnabled()
property variant weight: {
25: 0,
50: 1,
63: 3,
75: 4,
87: 5
}
property alias cfg_fontFamily: selectFont.text
property alias cfg_fontSize: fontSize.value
property string cfg_fontWeight: fontWeight.currentText
property string cfg_fontStyle: fontStyle.currentText
property alias cfg_fontColor: selectColor.text
property alias cfg_currentFontFamily: currentSelectFont.text
property alias cfg_currentFontSize: currentFontSize.value
property string cfg_currentFontWeight: currentFontWeight.currentText
property string cfg_currentFontStyle: currentFontStyle.currentText
property alias cfg_currentFontColor: currentSelectColor.text
Column {
id: pageColumn
width: units.gridUnit * 25
QtControls.TabView {
height: parent.height
width: parent.width
QtControls.Tab {
title: i18n("Active desktop")
QtLayouts.ColumnLayout {
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font")
}
QtControls.Button {
id: currentSelectFont
width: parent.width * 2 / 3
text: plasmoid.configuration.currentFontFamily
onClicked: currentFontDialog.visible = true
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font size")
}
QtControls.SpinBox {
id: currentFontSize
width: parent.width * 2 / 3
minimumValue: 8
maximumValue: 32
stepSize: 1
value: plasmoid.configuration.currentFontSize
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font weight")
}
QtControls.ComboBox {
id: currentFontWeight
width: parent.width * 2 / 3
textRole: "label"
model: [
{
'label': i18n("light"),
'name': "light"
},
{
'label': i18n("normal"),
'name': "normal"
},
{
'label': i18n("demi bold"),
'name': "demibold"
},
{
'label': i18n("bold"),
'name': "bold"
},
{
'label': i18n("black"),
'name': "black"
}
]
onCurrentIndexChanged: cfg_currentFontWeight = model[currentIndex]["name"]
Component.onCompleted: {
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.currentFontWeight) {
currentFontWeight.currentIndex = i;
}
}
}
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font style")
}
QtControls.ComboBox {
id: currentFontStyle
width: parent.width * 2 / 3
textRole: "label"
model: [
{
'label': i18n("normal"),
'name': "normal"
},
{
'label': i18n("italic"),
'name': "italic"
}
]
onCurrentIndexChanged: cfg_currentFontStyle = model[currentIndex]["name"]
Component.onCompleted: {
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.currentFontStyle) {
currentFontStyle.currentIndex = i;
}
}
}
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font color")
}
QtControls.Button {
id: currentSelectColor
width: parent.width * 2 / 3
style: QtStyles.ButtonStyle {
background: Rectangle {
color: plasmoid.configuration.currentFontColor
}
}
text: plasmoid.configuration.currentFontColor
onClicked: currentColorDialog.visible = true
}
}
}
QtDialogs.ColorDialog {
id: currentColorDialog
title: i18n("Select a color")
color: currentSelectColor.text
onAccepted: currentSelectColor.text = currentColorDialog.color
}
QtDialogs.FontDialog {
id: currentFontDialog
title: i18n("Select a font")
font: Qt.font({ family: currentSelectFont.text, pointSize: currentFontSize.value, weight: Font.Normal })
onAccepted: {
currentSelectFont.text = currentFontDialog.font.family
currentFontSize.value = currentFontDialog.font.pointSize
currentFontStyle.currentIndex = currentFontDialog.font.italic ? 1 : 0
currentFontWeight.currentIndex = weight[currentFontDialog.font.weight]
}
}
}
QtControls.Tab {
title: i18n("Inactive desktop")
QtLayouts.ColumnLayout {
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font")
}
QtControls.Button {
id: selectFont
width: parent.width * 2 / 3
text: plasmoid.configuration.fontFamily
onClicked: fontDialog.visible = true
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font size")
}
QtControls.SpinBox {
id: fontSize
width: parent.width * 2 / 3
minimumValue: 8
maximumValue: 32
stepSize: 1
value: plasmoid.configuration.fontSize
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font weight")
}
QtControls.ComboBox {
id: fontWeight
width: parent.width * 2 / 3
textRole: "label"
model: [
{
'label': i18n("light"),
'name': "light"
},
{
'label': i18n("normal"),
'name': "normal"
},
{
'label': i18n("demi bold"),
'name': "demibold"
},
{
'label': i18n("bold"),
'name': "bold"
},
{
'label': i18n("black"),
'name': "black"
}
]
onCurrentIndexChanged: cfg_fontWeight = model[currentIndex]["name"]
Component.onCompleted: {
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.fontWeight) {
fontWeight.currentIndex = i;
}
}
}
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font style")
}
QtControls.ComboBox {
id: fontStyle
width: parent.width * 2 / 3
textRole: "label"
model: [
{
'label': i18n("normal"),
'name': "normal"
},
{
'label': i18n("italic"),
'name': "italic"
}
]
onCurrentIndexChanged: cfg_fontStyle = model[currentIndex]["name"]
Component.onCompleted: {
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.fontStyle) {
fontStyle.currentIndex = i;
}
}
}
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font color")
}
QtControls.Button {
id: selectColor
width: parent.width * 2 / 3
style: QtStyles.ButtonStyle {
background: Rectangle {
color: plasmoid.configuration.fontColor
}
}
text: plasmoid.configuration.fontColor
onClicked: colorDialog.visible = true
}
}
}
QtDialogs.ColorDialog {
id: colorDialog
title: i18n("Select a color")
color: selectColor.text
onAccepted: selectColor.text = colorDialog.color
}
QtDialogs.FontDialog {
id: fontDialog
title: i18n("Select a font")
font: Qt.font({ family: selectFont.text, pointSize: fontSize.value, weight: Font.Normal })
onAccepted: {
selectFont.text = fontDialog.font.family
fontSize.value = fontDialog.font.pointSize
fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0
fontWeight.currentIndex = weight[fontDialog.font.weight]
}
}
}
}
}
Component.onCompleted: {
if (debug) console.log("[appearance::onCompleted]")
}
}

View File

@ -0,0 +1,218 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets 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 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls
import QtQuick.Controls.Styles 1.3 as QtStyles
import QtQuick.Dialogs 1.1 as QtDialogs
import org.kde.plasma.private.desktoppanel 1.0
Item {
id: inactiveAppearancePage
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: AWKeys.isDebugEnabled()
property variant weight: {
25: 0,
50: 1,
63: 3,
75: 4,
87: 5
}
property alias cfg_fontFamily: selectFont.text
property alias cfg_fontSize: fontSize.value
property string cfg_fontWeight: fontWeight.currentText
property string cfg_fontStyle: fontStyle.currentText
property alias cfg_fontColor: selectColor.text
Column {
id: pageColumn
width: units.gridUnit * 25
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font")
}
QtControls.Button {
id: selectFont
width: parent.width * 2 / 3
text: plasmoid.configuration.fontFamily
onClicked: fontDialog.visible = true
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font size")
}
QtControls.SpinBox {
id: fontSize
width: parent.width * 2 / 3
minimumValue: 8
maximumValue: 32
stepSize: 1
value: plasmoid.configuration.fontSize
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font weight")
}
QtControls.ComboBox {
id: fontWeight
width: parent.width * 2 / 3
textRole: "label"
model: [
{
'label': i18n("light"),
'name': "light"
},
{
'label': i18n("normal"),
'name': "normal"
},
{
'label': i18n("demi bold"),
'name': "demibold"
},
{
'label': i18n("bold"),
'name': "bold"
},
{
'label': i18n("black"),
'name': "black"
}
]
onCurrentIndexChanged: cfg_fontWeight = model[currentIndex]["name"]
Component.onCompleted: {
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.fontWeight) {
fontWeight.currentIndex = i;
}
}
}
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font style")
}
QtControls.ComboBox {
id: fontStyle
width: parent.width * 2 / 3
textRole: "label"
model: [
{
'label': i18n("normal"),
'name': "normal"
},
{
'label': i18n("italic"),
'name': "italic"
}
]
onCurrentIndexChanged: cfg_fontStyle = model[currentIndex]["name"]
Component.onCompleted: {
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.fontStyle) {
fontStyle.currentIndex = i;
}
}
}
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width / 3
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Font color")
}
QtControls.Button {
id: selectColor
width: parent.width * 2 / 3
style: QtStyles.ButtonStyle {
background: Rectangle {
color: plasmoid.configuration.fontColor
}
}
text: plasmoid.configuration.fontColor
onClicked: colorDialog.visible = true
}
}
}
QtDialogs.ColorDialog {
id: colorDialog
title: i18n("Select a color")
color: selectColor.text
onAccepted: selectColor.text = colorDialog.color
}
QtDialogs.FontDialog {
id: fontDialog
title: i18n("Select a font")
font: Qt.font({ family: selectFont.text, pointSize: fontSize.value, weight: Font.Normal })
onAccepted: {
selectFont.text = fontDialog.font.family
fontSize.value = fontDialog.font.pointSize
fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0
fontWeight.currentIndex = weight[fontDialog.font.weight]
}
}
Component.onCompleted: {
if (debug) console.log("[inactiveapp::onCompleted]")
}
}

View File

@ -30,9 +30,15 @@ Item {
id: main id: main
property bool debug: DPAdds.isDebugEnabled() property bool debug: DPAdds.isDebugEnabled()
property variant settings: { property variant tooltipSettings: {
"tooltipColor": plasmoid.configuration.tooltipColor,
"tooltipType": plasmoid.configuration.tooltipType,
"tooltipWidth": plasmoid.configuration.tooltipWidth
} }
signal needUpdate
signal needTooltipUpdate
// init // init
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
@ -40,8 +46,8 @@ Item {
Layout.fillWidth: plasmoid.formFactor != PlasmaCore.Planar Layout.fillWidth: plasmoid.formFactor != PlasmaCore.Planar
Layout.fillHeight: plasmoid.formFactor != PlasmaCore.Planar Layout.fillHeight: plasmoid.formFactor != PlasmaCore.Planar
Layout.minimumHeight: text.height Layout.minimumWidth: width
Layout.minimumWidth: text.width Layout. minimumHeight: height
Plasmoid.icon: "utilities-system-monitor" Plasmoid.icon: "utilities-system-monitor"
Plasmoid.backgroundHints: plasmoid.configuration.background ? "DefaultBackground" : "NoBackground" Plasmoid.backgroundHints: plasmoid.configuration.background ? "DefaultBackground" : "NoBackground"
@ -49,37 +55,116 @@ Item {
// ui // ui
Grid { Grid {
columns: 1 columns: plasmoid.configuration.verticalLayout ? 1 : DPAdds.numberOfDesktops()
rows: plasmoid.configuration.verticalLayout ? DPAdds.numberOfDesktops() : 1
Text { Repeater {
id: text id: repeater
height: contentHeight model: DPAdds.numberOfDesktops()
width: contentWidth Text {
textFormat: Text.RichText id: text
wrapMode: Text.NoWrap height: contentHeight
width: contentWidth
horizontalAlignment: general.align[plasmoid.configuration.textAlign]
verticalAlignment: Text.AlignVCenter
color: plasmoid.configuration.fontColor
font.family: plasmoid.configuration.fontFamily
font.italic: plasmoid.configuration.fontStyle == "italic" ? true : false
font.pointSize: plasmoid.configuration.fontSize
font.weight: general.fontWeight[plasmoid.configuration.fontWeight]
text: plasmoid.configuration.text
PlasmaCore.ToolTipArea {
id: rootTooltip
mainItem: Text {
id: tooltip
textFormat: Text.RichText textFormat: Text.RichText
wrapMode: Text.NoWrap
verticalAlignment: Text.AlignVCenter
text: DPAdds.parsePattern(plasmoid.configuration.text, index + 1)
property alias tooltip: tooltip
MouseArea {
hoverEnabled: true
anchors.fill: parent
onClicked: DPAdds.setCurrentDesktop(index + 1);
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.log("[main::onNeedUpdate]")
var newHeight = 0
var newWidth = 0
for (var i=0; i<repeater.count; i++) {
if (!repeater.itemAt(i)) {
if (debug) console.log("[main::onNeedUpdate] : Nothing to do here " + 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]
} 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).update()
newHeight += repeater.itemAt(i).height
newWidth += repeater.itemAt(i).width
}
height = newHeight
width = newHeight
update()
needTooltipUpdate()
}
onNeedTooltipUpdate: {
if (debug) console.log("[main::onNeedTooltipUpdate]")
for (var i=0; i<repeater.count; i++) {
repeater.itemAt(i).tooltip.text = DPAdds.toolTipImage(i + 1)
}
}
Plasmoid.onActivated: {
if (debug) console.log("[main::onActivated]")
DPAdds.changePanelsState()
}
Plasmoid.onUserConfiguringChanged: {
if (debug) console.log("[main::onUserConfiguringChanged]")
DPAdds.setMark(plasmoid.configuration.mark)
DPAdds.setPanelsToControl(plasmoid.configuration.panels)
DPAdds.setToolTipData(tooltipSettings)
needUpdate()
}
Component.onCompleted: { Component.onCompleted: {
if (debug) console.log("[main::onCompleted]") if (debug) console.log("[main::onCompleted]")
// init submodule
Plasmoid.userConfiguringChanged(true)
DPAdds.desktopChanged.connect(needUpdate)
DPAdds.windowListChanged.connect(needTooltipUpdate)
} }
} }

View File

@ -187,7 +187,7 @@ Item {
QtControls.ComboBox { QtControls.ComboBox {
id: tags id: tags
width: parent.width - addTagButton.width - showValueButton.width width: parent.width - addTagButton.width - showValueButton.width
model: ADAdds.dictKeys() model: DPAdds.dictKeys()
} }
QtControls.Button { QtControls.Button {
id: addTagButton id: addTagButton
@ -212,8 +212,6 @@ Item {
var message = i18n("Tag: %1", tags.currentText) var message = i18n("Tag: %1", tags.currentText)
message += "<br>" message += "<br>"
message += i18n("Value: %1", DPAdds.valueByKey(tags.currentText)) message += i18n("Value: %1", DPAdds.valueByKey(tags.currentText))
message += "<br>"
message += i18n("Info: %1", DPAdds.infoByKey(tags.currentText))
DPAdds.sendNotification("tag", message) DPAdds.sendNotification("tag", message)
} }
} }

View File

@ -24,6 +24,7 @@
#include <QBuffer> #include <QBuffer>
#include <QDebug> #include <QDebug>
#include <QGraphicsPixmapItem>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGraphicsView> #include <QGraphicsView>
#include <QHBoxLayout> #include <QHBoxLayout>
@ -31,6 +32,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QPixmap> #include <QPixmap>
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include <QScreen>
#include <fontdialog/fontdialog.h> #include <fontdialog/fontdialog.h>
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
@ -47,6 +49,8 @@ DPAdds::DPAdds(QObject *parent)
debug = (debugEnv == QString("yes")); debug = (debugEnv == QString("yes"));
connect(KWindowSystem::self(), SIGNAL(currentDesktopChanged(int)), this, SLOT(changeDesktop(int))); connect(KWindowSystem::self(), SIGNAL(currentDesktopChanged(int)), this, SLOT(changeDesktop(int)));
connect(KWindowSystem::self(), SIGNAL(windowAdded(WId)), this, SLOT(changeWindowList(WId)));
connect(KWindowSystem::self(), SIGNAL(windowRemoved(WId)), this, SLOT(changeWindowList(WId)));
} }
@ -64,6 +68,14 @@ bool DPAdds::isDebugEnabled()
} }
int DPAdds::currentDesktop()
{
if (debug) qDebug() << PDEBUG;
return KWindowSystem::currentDesktop();
}
QStringList DPAdds::dictKeys() QStringList DPAdds::dictKeys()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -78,16 +90,37 @@ QStringList DPAdds::dictKeys()
} }
int DPAdds::numberOfDesktops()
{
if (debug) qDebug() << PDEBUG;
return KWindowSystem::numberOfDesktops();
}
QString DPAdds::toolTipImage(const int desktop) QString DPAdds::toolTipImage(const int desktop)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Desktop" << desktop; if (debug) qDebug() << PDEBUG << ":" << "Desktop" << desktop;
if (tooltipType == QString("none")) return QString();
// prepare // prepare
// clear DesktopWindowsInfo info = getInfoByDesktop(desktop);
if (tooltipType == QString("names")) {
QStringList windowList;
for (int i=0; i<info.windowsData.count(); i++)
windowList.append(info.windowsData[i].name);
return QString("<ul><li>") + windowList.join(QString("</li><li>")) + QString("</li></ul>");
}
// init
QGraphicsScene *toolTipScene = new QGraphicsScene(); QGraphicsScene *toolTipScene = new QGraphicsScene();
QGraphicsView *toolTipView = new QGraphicsView(toolTipScene); QGraphicsView *toolTipView = new QGraphicsView(toolTipScene);
DesktopWindowsInfo info = getInfoByDesktop(desktop); toolTipView->setStyleSheet(QString("background: transparent"));
toolTipView->setContentsMargins(0, 0, 0, 0);
toolTipView->setFrameShape(QFrame::NoFrame);
toolTipView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
toolTipView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// update
float margin = 5.0 * info.desktop.width() / 400.0; float margin = 5.0 * info.desktop.width() / 400.0;
toolTipView->resize(info.desktop.width() + 2.0 * margin, info.desktop.height() + 2.0 * margin); toolTipView->resize(info.desktop.width() + 2.0 * margin, info.desktop.height() + 2.0 * margin);
toolTipScene->clear(); toolTipScene->clear();
@ -104,20 +137,36 @@ QString DPAdds::toolTipImage(const int desktop)
QPen pen = QPen(); QPen pen = QPen();
pen.setWidthF(2.0 * info.desktop.width() / 400.0); pen.setWidthF(2.0 * info.desktop.width() / 400.0);
pen.setColor(QColor(tooltipColor)); pen.setColor(QColor(tooltipColor));
for (int i=0; i<info.windows.count(); i++) { for (int i=0; i<info.windowsData.count(); i++) {
toolTipScene->addLine(info.windows[i].left() + margin, info.windows[i].bottom() + margin, QRect rect = info.windowsData[i].rect;
info.windows[i].left() + margin, info.windows[i].top() + margin, pen); toolTipScene->addLine(rect.left() + margin, rect.bottom() + margin,
toolTipScene->addLine(info.windows[i].left() + margin, info.windows[i].top() + margin, rect.left() + margin, rect.top() + margin, pen);
info.windows[i].right() + margin, info.windows[i].top() + margin, pen); toolTipScene->addLine(rect.left() + margin, rect.top() + margin,
toolTipScene->addLine(info.windows[i].right() + margin, info.windows[i].top() + margin, rect.right() + margin, rect.top() + margin, pen);
info.windows[i].right() + margin, info.windows[i].bottom() + margin, pen); toolTipScene->addLine(rect.right() + margin, rect.top() + margin,
toolTipScene->addLine(info.windows[i].right() + margin, info.windows[i].bottom() + margin, rect.right() + margin, rect.bottom() + margin, pen);
info.windows[i].left() + margin, info.windows[i].bottom() + margin, pen); toolTipScene->addLine(rect.right() + margin, rect.bottom() + margin,
rect.left() + margin, rect.bottom() + margin, pen);
} }
} else if (tooltipType == QString("clean")) { } else if (tooltipType == QString("clean")) {
// toolTip.setWindowsToPreview(info.desktopId); QScreen *screen = QGuiApplication::primaryScreen();
for (int i=0; i<info.desktopsData.count(); i++) {
QPixmap desktop = screen->grabWindow(info.desktopsData[i].id);
toolTipScene->addPixmap(desktop)
->setOffset(info.desktopsData[i].rect.left(), info.desktopsData[i].rect.top());
}
} else if (tooltipType == QString("windows")) { } else if (tooltipType == QString("windows")) {
// toolTip.setWindowsToPreview(info.winId); QScreen *screen = QGuiApplication::primaryScreen();
for (int i=0; i<info.desktopsData.count(); i++) {
QPixmap desktop = screen->grabWindow(info.desktopsData[i].id);
toolTipScene->addPixmap(desktop)
->setOffset(info.desktopsData[i].rect.left(), info.desktopsData[i].rect.top());
}
for (int i=0; i<info.windowsData.count(); i++) {
QPixmap window = screen->grabWindow(info.windowsData[i].id);
toolTipScene->addPixmap(window)
->setOffset(info.windowsData[i].rect.left(), info.windowsData[i].rect.top());
}
} }
QPixmap image = toolTipView->grab().scaledToWidth(tooltipWidth); QPixmap image = toolTipView->grab().scaledToWidth(tooltipWidth);
@ -125,6 +174,9 @@ QString DPAdds::toolTipImage(const int desktop)
QBuffer buffer(&byteArray); QBuffer buffer(&byteArray);
image.save(&buffer, "PNG"); image.save(&buffer, "PNG");
delete toolTipView;
delete toolTipScene;
return QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64())); return QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
} }
@ -135,10 +187,10 @@ QString DPAdds::parsePattern(const QString pattern, const int desktop)
QString parsed = pattern; QString parsed = pattern;
QStringList keys = dictKeys(); QStringList keys = dictKeys();
parsed.replace(QString(" "), QString("&nbsp;"));
parsed.replace(QString("$$"), QString("$\\$\\")); parsed.replace(QString("$$"), QString("$\\$\\"));
for (int i=0; i<keys.count(); i++) for (int i=0; i<keys.count(); i++)
parsed.replace(QString("$") + keys[i], valueByKey(keys[i], desktop)); parsed.replace(QString("$") + keys[i], valueByKey(keys[i], desktop));
parsed.replace(QString(" "), QString("&nbsp;"));
parsed.replace(QString("$\\$\\"), QString("$$")); parsed.replace(QString("$\\$\\"), QString("$$"));
return parsed; return parsed;
@ -170,7 +222,7 @@ void DPAdds::setPanelsToControl(const QString newPanels)
} }
void DPAdds::setToolTipData(const QMap< QString, QVariant > tooltipData) void DPAdds::setToolTipData(const QMap<QString, QVariant> tooltipData)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Data" << tooltipData; if (debug) qDebug() << PDEBUG << ":" << "Data" << tooltipData;
@ -181,24 +233,25 @@ void DPAdds::setToolTipData(const QMap< QString, QVariant > tooltipData)
} }
QString DPAdds::valueByKey(const QString key, const int desktop) QString DPAdds::valueByKey(const QString key, int desktop)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Requested key" << key; if (debug) qDebug() << PDEBUG << ":" << "Requested key" << key;
if (desktop == -1) desktop = currentDesktop();
QString currentMark; QString currentMark;
if (KWindowSystem::currentDesktop() == desktop) if (currentDesktop() == desktop)
currentMark = mark; currentMark = mark;
else else
currentMark = QString(""); currentMark = QString("");
if (key == QString("mark")) if (key == QString("mark"))
return QString("%1").arg(currentMark, currentMark.count(), QLatin1Char(' ')); return QString("%1").arg(currentMark, mark.count(), QLatin1Char(' '));
else if (key == QString("name")) else if (key == QString("name"))
return KWindowSystem::desktopName(desktop); return KWindowSystem::desktopName(desktop);
else if (key == QString("number")) else if (key == QString("number"))
return QString::number(desktop); return QString::number(desktop);
else if (key == QString("total")) else if (key == QString("total"))
return QString::number(KWindowSystem::numberOfDesktops()); return QString::number(numberOfDesktops());
else else
return QString(); return QString();
} }
@ -361,6 +414,15 @@ void DPAdds::changeDesktop(const int desktop)
} }
void DPAdds::changeWindowList(const WId window)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Window" << window;
emit(windowListChanged());
}
DPAdds::DesktopWindowsInfo DPAdds::getInfoByDesktop(const int desktop) DPAdds::DesktopWindowsInfo DPAdds::getInfoByDesktop(const int desktop)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -374,14 +436,18 @@ DPAdds::DesktopWindowsInfo DPAdds::getInfoByDesktop(const int desktop)
for (int i=0; i<windows.count(); i++) { for (int i=0; i<windows.count(); i++) {
KWindowInfo winInfo = KWindowInfo(windows[i], KWindowInfo winInfo = KWindowInfo(windows[i],
NET::Property::WMDesktop | NET::Property::WMGeometry | NET::Property::WMDesktop | NET::Property::WMGeometry |
NET::Property::WMState | NET::Property::WMWindowType); NET::Property::WMState | NET::Property::WMWindowType |
NET::Property::WMVisibleName);
if (!winInfo.isOnDesktop(desktop)) continue; if (!winInfo.isOnDesktop(desktop)) continue;
WindowData data;
data.id = windows[i];
data.name = winInfo.visibleName();
data.rect = winInfo.geometry();
if (winInfo.windowType(NET::WindowTypeMask::NormalMask) == NET::WindowType::Normal) { if (winInfo.windowType(NET::WindowTypeMask::NormalMask) == NET::WindowType::Normal) {
if (winInfo.isMinimized()) continue; if (winInfo.isMinimized()) continue;
info.windows.append(winInfo.geometry()); info.windowsData.append(data);
info.winId.append(windows[i]);
} else if (winInfo.windowType(NET::WindowTypeMask::DesktopMask) == NET::WindowType::Desktop) { } else if (winInfo.windowType(NET::WindowTypeMask::DesktopMask) == NET::WindowType::Desktop) {
info.desktopId.append(windows[i]); info.desktopsData.append(data);
} }
} }
@ -393,13 +459,12 @@ QList<Plasma::Containment *> DPAdds::getPanels()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
Plasma::Containment *containment = new Plasma::Containment(this, QVariantList()); // Plasma::Corona *corona = new Plasma::Corona(this);
QList<Plasma::Containment *> panels; QList<Plasma::Containment *> panels;
for (int i=0; i<containment->corona()->containments().count(); i++) // for (int i=0; i<corona->containments().count(); i++)
if (containment->corona()->containments()[i]->containmentType() == // if (corona->containments()[i]->containmentType() == Plasma::Types::ContainmentType::PanelContainment)
Plasma::Types::ContainmentType::PanelContainment) // panels.append(corona->containments()[i]);
panels.append(containment->corona()->containments()[i]); // delete corona;
delete containment;
return panels; return panels;
} }

View File

@ -30,11 +30,16 @@ class DPAdds : public QObject
{ {
Q_OBJECT Q_OBJECT
typedef struct {
WId id;
QString name;
QRect rect;
} WindowData;
typedef struct { typedef struct {
QRect desktop; QRect desktop;
QList<WId> desktopId; QList<WindowData> desktopsData;
QList<QRect> windows; QList<WindowData> windowsData;
QList<WId> winId;
} DesktopWindowsInfo; } DesktopWindowsInfo;
public: public:
@ -42,14 +47,16 @@ public:
~DPAdds(); ~DPAdds();
Q_INVOKABLE bool isDebugEnabled(); Q_INVOKABLE bool isDebugEnabled();
Q_INVOKABLE int currentDesktop();
Q_INVOKABLE QStringList dictKeys(); Q_INVOKABLE QStringList dictKeys();
Q_INVOKABLE int numberOfDesktops();
Q_INVOKABLE QString toolTipImage(const int desktop); Q_INVOKABLE QString toolTipImage(const int desktop);
Q_INVOKABLE QString parsePattern(const QString pattern, const int desktop); Q_INVOKABLE QString parsePattern(const QString pattern, const int desktop);
// values // values
Q_INVOKABLE void setMark(const QString newMark); Q_INVOKABLE void setMark(const QString newMark);
Q_INVOKABLE void setPanelsToControl(const QString newPanels); Q_INVOKABLE void setPanelsToControl(const QString newPanels);
Q_INVOKABLE void setToolTipData(const QMap<QString, QVariant> tooltipData); Q_INVOKABLE void setToolTipData(const QMap<QString, QVariant> tooltipData);
Q_INVOKABLE QString valueByKey(const QString key, const int desktop); Q_INVOKABLE QString valueByKey(const QString key, int desktop = -1);
// configuration slots // configuration slots
Q_INVOKABLE QString editPanelsToContol(const QString current); Q_INVOKABLE QString editPanelsToContol(const QString current);
Q_INVOKABLE QString getAboutText(const QString type = "header"); Q_INVOKABLE QString getAboutText(const QString type = "header");
@ -57,6 +64,7 @@ public:
signals: signals:
void desktopChanged(); void desktopChanged();
void windowListChanged();
public slots: public slots:
Q_INVOKABLE void changePanelsState(); Q_INVOKABLE void changePanelsState();
@ -65,6 +73,7 @@ public slots:
private slots: private slots:
void changeDesktop(const int desktop); void changeDesktop(const int desktop);
void changeWindowList(const WId window);
private: private:
DesktopWindowsInfo getInfoByDesktop(const int desktop); DesktopWindowsInfo getInfoByDesktop(const int desktop);
@ -72,8 +81,10 @@ private:
QString panelLocationToStr(Plasma::Types::Location location); QString panelLocationToStr(Plasma::Types::Location location);
// variables // variables
bool debug = false; bool debug = false;
int oldState, tooltipWidth; int oldState, tooltipWidth = 200;
QString mark, tooltipColor, tooltipType; QString mark = QString("*");
QString tooltipColor = QString("#000000");
QString tooltipType = QString("none");
QList<int> panelsToControl; QList<int> panelsToControl;
}; };