some configuration interface changes

This commit is contained in:
arcan1s 2014-12-29 23:37:21 +03:00
parent afed94745a
commit 7972f2d6d3
6 changed files with 134 additions and 38 deletions

View File

@ -58,8 +58,8 @@ IPv6: $intip6</default>
<entry name="fontColor" type="string"> <entry name="fontColor" type="string">
<default>#000000</default> <default>#000000</default>
</entry> </entry>
<entry name="fontWeight" type="int"> <entry name="fontWeight" type="string">
<default>400</default> <default>normal</default>
</entry> </entry>
<entry name="fontStyle" type="string"> <entry name="fontStyle" type="string">
<default>normal</default> <default>normal</default>

View File

@ -17,6 +17,7 @@
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Controls 1.0 as QtControls import QtQuick.Controls 1.0 as QtControls
import QtQuick.Controls.Styles 1.3 as QtStyles
import QtQuick.Dialogs 1.1 as QtDialogs import QtQuick.Dialogs 1.1 as QtDialogs
import QtQuick.Layouts 1.0 as QtLayouts import QtQuick.Layouts 1.0 as QtLayouts
@ -26,10 +27,18 @@ Item {
width: childrenRect.width width: childrenRect.width
height: childrenRect.height height: childrenRect.height
property variant weight: {
25: 0,
50: 1,
63: 3,
75: 4,
87: 5
}
property string cfg_textAlign: textAlign.currentText property string cfg_textAlign: textAlign.currentText
property alias cfg_fontFamily: selectFont.text property alias cfg_fontFamily: selectFont.text
property alias cfg_fontSize: fontSize.value property alias cfg_fontSize: fontSize.value
property alias cfg_fontWeight: fontWeight.value property string cfg_fontWeight: fontWeight.currentText
property string cfg_fontStyle: fontStyle.currentText property string cfg_fontStyle: fontStyle.currentText
property alias cfg_fontColor: selectColor.text property alias cfg_fontColor: selectColor.text
property alias cfg_activeIconPath: activeIcon.text property alias cfg_activeIconPath: activeIcon.text
@ -101,12 +110,39 @@ Item {
QtControls.Label { QtControls.Label {
text: i18n("Font weight") text: i18n("Font weight")
} }
QtControls.SpinBox { QtControls.ComboBox {
id: fontWeight id: fontWeight
minimumValue: 100 textRole: "label"
maximumValue: 900 model: [
stepSize: 100 {
value: plasmoid.configuration.fontWeight '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;
}
}
}
} }
} }
@ -144,6 +180,11 @@ Item {
} }
QtControls.Button { QtControls.Button {
id: selectColor id: selectColor
style: QtStyles.ButtonStyle {
background: Rectangle {
color: plasmoid.configuration.fontColor
}
}
text: plasmoid.configuration.fontColor text: plasmoid.configuration.fontColor
onClicked: colorDialog.visible = true onClicked: colorDialog.visible = true
} }
@ -224,6 +265,8 @@ Item {
onAccepted: { onAccepted: {
selectFont.text = fontDialog.font.family selectFont.text = fontDialog.font.family
fontSize.value = fontDialog.font.pointSize fontSize.value = fontDialog.font.pointSize
fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0
fontWeight.currentIndex = weight[fontDialog.font.weight]
} }
} }
} }

View File

@ -27,6 +27,25 @@ Item {
id: main id: main
// variables // variables
// internal
property variant weight: {
"light": Font.Light,
"normal": Font.Normal,
"demibold": Font.DemiBold,
"bold": Font.Bold,
"black": Font.Black
}
property variant align: {
"left": Text.AlignLeft,
"center": Text.AlignHCenter,
"right": Text.AlignRight,
"justify": Text.AlignJustify
}
// external
property variant iconPath: {
"true": plasmoid.configuration.activeIconPath,
"false": plasmoid.configuration.inactiveIconPath
}
property variant info: { property variant info: {
"current": "N\\A", "current": "N\\A",
"extip4": "127.0.0.1", "extip4": "127.0.0.1",
@ -37,12 +56,8 @@ Item {
"profiles": "", "profiles": "",
"status": "N\\A" "status": "N\\A"
} }
Text {
id: iconPath
property string active: plasmoid.configuration.activeIconPath
property string inactive: plasmoid.configuration.inactiveIconPath
}
property int interval: plasmoid.configuration.autoUpdateInterval property int interval: plasmoid.configuration.autoUpdateInterval
property string pattern: plasmoid.configuration.textPattern
property bool status: false property bool status: false
// init // init
@ -57,19 +72,13 @@ Item {
onNewData: { onNewData: {
if (data.isEmpty) return if (data.isEmpty) return
if (sourceName == "active") { if (sourceName == "active") {
if (data.value == "true") { main.status = data.value == "true" ? true : false
main.status = true icon.source = iconPath[data.value]
icon.source = iconPath.active
} else {
main.status = false
icon.source = iconPath.inactive
}
} else if (sourceName == "current") { } else if (sourceName == "current") {
info["current"] = data.value info["current"] = data.value
// text update // text update
for (var prop in info) { info["info"] = NetctlAdds.getInfo(info["current"], info["status"])
console.log(prop + " = " + info[prop]) text.text = NetctlAdds.parsePattern(pattern, info)
}
} else if (sourceName == "extip4") { } else if (sourceName == "extip4") {
info["extip4"] = data.value info["extip4"] = data.value
} else if (sourceName == "extip6") { } else if (sourceName == "extip6") {
@ -94,10 +103,17 @@ Item {
Image { Image {
id: icon id: icon
source: iconPath.inactive source: iconPath["inactive"]
} }
Text { Text {
id: text id: text
color: plasmoid.configuration.fontColor
font.family: plasmoid.configuration.fontFamily
font.italic: plasmoid.configuration.fontStyle == "italic" ? true : false
font.pointSize: plasmoid.configuration.fontSize
font.weight: weight[plasmoid.configuration.fontWeight]
horizontalAlignment: align[plasmoid.configuration.textAlign]
textFormat: Text.RichText
text: "N\\A" text: "N\\A"
} }
} }

View File

@ -17,18 +17,22 @@
#include <QtQml> #include <QtQml>
#include <pdebug/pdebug.h>
#include "netctl.h" #include "netctl.h"
#include "netctladds.h" #include "netctladds.h"
#include "version.h"
static QObject *netctl_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new NetctlAdds();
}
void NetctlPlugin::registerTypes(const char *uri) void NetctlPlugin::registerTypes(const char *uri)
{ {
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.netctl")); Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.netctl"));
qmlRegisterType<NetctlAdds>(uri, 1, 0, "NetctlAdds"); qmlRegisterSingletonType<NetctlAdds>(uri, 1, 0, "NetctlAdds", netctl_singletontype_provider);
// qmlRegisterType<TimeZoneModel>(uri, 1, 0, "TimeZoneModel");
// qmlRegisterSingletonType<TimezonesI18n>(uri, 1, 0, "TimezonesI18n", timezonesi18n_singletontype_provider);
} }

View File

@ -15,7 +15,10 @@
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ * * along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/ ***************************************************************************/
//#include <pdebug/pdebug.h> #include <QDebug>
#include <QProcessEnvironment>
#include <pdebug/pdebug.h>
#include "netctladds.h" #include "netctladds.h"
#include "version.h" #include "version.h"
@ -24,19 +27,45 @@
NetctlAdds::NetctlAdds(QObject *parent) NetctlAdds::NetctlAdds(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
// debug
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
QString debugEnv = environment.value(QString("NETCTLGUI_DEBUG"), QString("no"));
debug = (debugEnv == QString("yes"));
} }
NetctlAdds::~NetctlAdds() NetctlAdds::~NetctlAdds()
{ {
// if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
} }
QString NetctlAdds::parsePattern(QString pattern, const QString key, const QString value) QString NetctlAdds::getInfo(const QString current, const QString status)
{ {
// if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Current profiles" << current;
if (debug) qDebug() << PDEBUG << ":" << "Statuses" << status;
return pattern.replace(QString("$") + key, value); QStringList profiles;
for (int i=0; i<current.split(QChar('|')).count(); i++)
profiles.append(current.split(QChar('|'))[i] +
QString(" (") + status.split(QChar('|'))[i] + QString(")"));
return profiles.join(QString(" | "));
}
QString NetctlAdds::parsePattern(const QString pattern, const QMap<QString, QVariant> dict)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Dictionary" << dict;
QString parsed = pattern;
for (int i=0; i<dict.keys().count(); i++)
parsed.replace(QString("$") + dict.keys()[i], dict[dict.keys()[i]].toString());
// fix newline
parsed.replace(QString("\n"), QString("<br>"));
return parsed;
} }

View File

@ -19,11 +19,11 @@
#ifndef NETCTLADDS_H #ifndef NETCTLADDS_H
#define NETCTLADDS_H #define NETCTLADDS_H
#include <QMap>
#include <QObject> #include <QObject>
#include <QVariant>
class QQmlEngine;
class NetctlAdds : public QObject class NetctlAdds : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -32,7 +32,11 @@ public:
NetctlAdds(QObject *parent = 0); NetctlAdds(QObject *parent = 0);
~NetctlAdds(); ~NetctlAdds();
Q_INVOKABLE QString parsePattern(QString pattern, const QString key, const QString value); Q_INVOKABLE QString getInfo(const QString current, const QString status);
Q_INVOKABLE QString parsePattern(const QString pattern, const QMap<QString, QVariant> dict);
private:
bool debug = false;
}; };