From 80c994bce020fe8530c5cdff503c834fef799db4 Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Wed, 28 Sep 2016 13:50:57 +0300 Subject: [PATCH] massive qml controls replacement (#114) --- .../package/contents/ui/ComboBoxSelector.qml | 55 ++++ .../package/contents/ui/IntegerSelector.qml | 47 +++ .../package/contents/ui/LineSelector.qml | 43 +++ .../package/contents/ui/advanced.qml | 274 +++++------------ .../package/contents/ui/appearance.qml | 215 +++++-------- .../package/contents/ui/dataengine.qml | 283 +++++++----------- .../awesome-widget/package/contents/ui/qmldir | 3 + .../package/contents/ui/tooltip.qml | 25 +- sources/awesome-widget/plugin/awkeys.cpp | 17 +- sources/awesome-widget/plugin/awkeys.h | 2 +- sources/test/testawkeys.cpp | 2 +- 11 files changed, 439 insertions(+), 527 deletions(-) create mode 100644 sources/awesome-widget/package/contents/ui/ComboBoxSelector.qml create mode 100644 sources/awesome-widget/package/contents/ui/IntegerSelector.qml create mode 100644 sources/awesome-widget/package/contents/ui/LineSelector.qml diff --git a/sources/awesome-widget/package/contents/ui/ComboBoxSelector.qml b/sources/awesome-widget/package/contents/ui/ComboBoxSelector.qml new file mode 100644 index 0000000..19929d4 --- /dev/null +++ b/sources/awesome-widget/package/contents/ui/ComboBoxSelector.qml @@ -0,0 +1,55 @@ +/*************************************************************************** + * 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 + + +Row { + height: implicitHeight + width: parent.width + + property alias currentIndex: comboBox.currentIndex + property alias editable: comboBox.editable + property alias editText: comboBox.editText + property alias model: comboBox.model + property alias text: label.text + property string value + + signal valueEdited(string newValue) + + QtControls.Label { + id: label + height: parent.height + width: parent.width * 2 / 5 + horizontalAlignment: Text.AlignRight + verticalAlignment: Text.AlignVCenter + } + QtControls.ComboBox { + id: comboBox + width: parent.width * 3 / 5 + textRole: 'label' + onCurrentIndexChanged: valueEdited(comboBox.model[comboBox.currentIndex]['name']) + Component.onCompleted: { + var total = comboBox.model.length + for (var i = 0; i < total; i++) { + if (comboBox.model[i]["name"] == value) + comboBox.currentIndex = i + } + } + } +} diff --git a/sources/awesome-widget/package/contents/ui/IntegerSelector.qml b/sources/awesome-widget/package/contents/ui/IntegerSelector.qml new file mode 100644 index 0000000..dea9443 --- /dev/null +++ b/sources/awesome-widget/package/contents/ui/IntegerSelector.qml @@ -0,0 +1,47 @@ +/*************************************************************************** + * 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 + + +Row { + height: implicitHeight + width: parent.width + + property alias text: label.text + property alias value: spinBox.value + + property alias maximumValue: spinBox.maximumValue + property alias minimumValue: spinBox.minimumValue + property alias stepSize: spinBox.stepSize + + signal valueEdited(int newValue) + + QtControls.Label { + id: label + height: parent.height + width: parent.width * 2 / 5 + horizontalAlignment: Text.AlignRight + verticalAlignment: Text.AlignVCenter + } + QtControls.SpinBox { + id: spinBox + width: parent.width * 3 / 5 + onEditingFinished: valueEdited(spinBox.value) + } +} diff --git a/sources/awesome-widget/package/contents/ui/LineSelector.qml b/sources/awesome-widget/package/contents/ui/LineSelector.qml new file mode 100644 index 0000000..ab21728 --- /dev/null +++ b/sources/awesome-widget/package/contents/ui/LineSelector.qml @@ -0,0 +1,43 @@ +/*************************************************************************** + * 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 + + +Row { + height: implicitHeight + width: parent.width + + property alias text: label.text + property alias value: textField.text + + signal valueEdited(string newValue) + + QtControls.Label { + id: label + height: parent.height + width: parent.width * 2 / 5 + horizontalAlignment: Text.AlignRight + verticalAlignment: Text.AlignVCenter + } + QtControls.TextField { + id: textField + width: parent.width * 3 / 5 + onEditingFinished: valueEdited(textField.text) + } +} diff --git a/sources/awesome-widget/package/contents/ui/advanced.qml b/sources/awesome-widget/package/contents/ui/advanced.qml index b9d6cc7..c231872 100644 --- a/sources/awesome-widget/package/contents/ui/advanced.qml +++ b/sources/awesome-widget/package/contents/ui/advanced.qml @@ -50,11 +50,11 @@ Item { property alias cfg_width: widgetWidth.value property alias cfg_interval: update.value property alias cfg_queueLimit: queueLimit.value - property string cfg_tempUnits: tempUnits.currentText - property alias cfg_customTime: customTime.text - property alias cfg_customUptime: customUptime.text - property alias cfg_acOnline: acOnline.text - property alias cfg_acOffline: acOffline.text + property string cfg_tempUnits: tempUnits.value + property alias cfg_customTime: customTime.value + property alias cfg_customUptime: customUptime.value + property alias cfg_acOnline: acOnline.value + property alias cfg_acOffline: acOffline.value Column { @@ -96,209 +96,101 @@ Item { text: i18n("Optimize subscription") } - Row { - height: implicitHeight - width: parent.width - QtControls.Label { - height: parent.height - width: parent.width * 2 / 5 - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - text: i18n("Widget height, px") - } - QtControls.SpinBox { - id: widgetHeight - width: parent.width * 3 / 5 - minimumValue: 0 - maximumValue: 4096 - stepSize: 50 - value: plasmoid.configuration.height - } + IntegerSelector { + id: widgetHeight + maximumValue: 4096 + minimumValue: 0 + stepSize: 50 + text: i18n("Widget height, px") + value: plasmoid.configuration.height } - Row { - height: implicitHeight - width: parent.width - QtControls.Label { - height: parent.height - width: parent.width * 2 / 5 - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - text: i18n("Widget width, px") - } - QtControls.SpinBox { - id: widgetWidth - width: parent.width * 3 / 5 - minimumValue: 0 - maximumValue: 4096 - stepSize: 50 - value: plasmoid.configuration.width - } + IntegerSelector { + id: widgetWidth + maximumValue: 4096 + minimumValue: 0 + stepSize: 50 + text: i18n("Widget width, px") + value: plasmoid.configuration.width } - Row { - height: implicitHeight - width: parent.width - QtControls.Label { - height: parent.height - width: parent.width * 2 / 5 - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - text: i18n("Time interval") - } - QtControls.SpinBox { - id: update - width: parent.width * 3 / 5 - minimumValue: 1000 - maximumValue: 10000 - stepSize: 500 - value: plasmoid.configuration.interval - } + IntegerSelector { + id: update + maximumValue: 10000 + minimumValue: 1000 + stepSize: 500 + text: i18n("Time interval") + value: plasmoid.configuration.interval } - Row { - height: implicitHeight - width: parent.width - QtControls.Label { - height: parent.height - width: parent.width * 2 / 5 - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - text: i18n("Messages queue limit") - } - QtControls.SpinBox { - id: queueLimit - width: parent.width * 3 / 5 - minimumValue: 0 - maximumValue: 99 - stepSize: 1 - value: plasmoid.configuration.queueLimit - } + IntegerSelector { + id: queueLimit + maximumValue: 99 + minimumValue: 0 + stepSize: 1 + text: i18n("Messages queue limit") + value: plasmoid.configuration.queueLimit } - 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 { - id: tempUnits - width: parent.width * 3 / 5 - textRole: "label" - model: [ - { - 'label': i18n("Celsius"), - 'name': "Celsius" - }, - { - '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: { - if (debug) console.debug() - for (var i = 0; i < model.length; i++) { - if (model[i]["name"] == plasmoid.configuration.tempUnits) { - if (debug) console.info("Found", model[i]["name"], "on", i) - tempUnits.currentIndex = i - } - } + ComboBoxSelector { + id: tempUnits + model: [ + { + 'label': i18n("Celsius"), + 'name': "Celsius" + }, + { + '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" } - } + ] + text: i18n("Temperature units") + value: plasmoid.configuration.tempUnits + onValueEdited: cfg_tempUnits = newValue } - Row { - height: implicitHeight - width: parent.width - QtControls.Label { - height: parent.height - width: parent.width * 2 / 5 - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - text: i18n("Custom time format") - } - QtControls.TextField { - id: customTime - width: parent.width * 3 / 5 - text: plasmoid.configuration.customTime - } + LineSelector { + id: customTime + text: i18n("Custom time format") + value: plasmoid.configuration.customTime } - Row { - height: implicitHeight - width: parent.width - QtControls.Label { - height: parent.height - width: parent.width * 2 / 5 - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - text: i18n("Custom uptime format") - } - QtControls.TextField { - id: customUptime - width: parent.width * 3 / 5 - text: plasmoid.configuration.customUptime - } + LineSelector { + id: customUptime + text: i18n("Custom uptime format") + value: 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("AC online tag") - } - QtControls.TextField { - id: acOnline - width: parent.width * 3 / 5 - text: plasmoid.configuration.acOnline - } + LineSelector { + id: acOnline + text: i18n("AC online tag") + value: 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 - } + LineSelector { + id: acOffline + text: i18n("AC offline tag") + value: plasmoid.configuration.acOffline } Row { diff --git a/sources/awesome-widget/package/contents/ui/appearance.qml b/sources/awesome-widget/package/contents/ui/appearance.qml index 20b88ab..66c552e 100644 --- a/sources/awesome-widget/package/contents/ui/appearance.qml +++ b/sources/awesome-widget/package/contents/ui/appearance.qml @@ -46,11 +46,11 @@ Item { 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 string cfg_fontWeight: fontWeight.value + property string cfg_fontStyle: fontStyle.value property alias cfg_fontColor: selectColor.text property alias cfg_textStyleColor: selectStyleColor.text - property string cfg_textStyle: textStyle.currentText + property string cfg_textStyle: textStyle.value Column { @@ -78,110 +78,59 @@ Item { } } - 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 - } + IntegerSelector { + id: fontSize + maximumValue: 32 + minimumValue: 8 + stepSize: 1 + text: i18n("Font size") + 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: { - if (debug) console.debug() - for (var i = 0; i < model.length; i++) { - if (model[i]["name"] == plasmoid.configuration.fontWeight) { - if (debug) console.info("Found", model[i]["name"], "on", i) - fontWeight.currentIndex = i - } - } + ComboBoxSelector { + id: fontWeight + 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" } - } + ] + text: i18n("Font weight") + value: plasmoid.configuration.fontWeight + onValueEdited: cfg_fontWeight = newValue } - 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: { - if (debug) console.debug() - for (var i = 0; i < model.length; i++) { - if (model[i]["name"] == plasmoid.configuration.fontStyle) { - if (debug) console.info("Found", model[i]["name"], "on", i) - fontStyle.currentIndex = i - } - } + ComboBoxSelector { + id: fontStyle + model: [ + { + 'label': i18n("normal"), + 'name': "normal" + }, + { + 'label': i18n("italic"), + 'name': "italic" } - } + ] + text: i18n("Font style") + value: plasmoid.configuration.fontStyle + onValueEdited: cfg_fontStyle = newValue } Row { @@ -207,49 +156,29 @@ Item { } } - Row { - height: implicitHeight - width: parent.width - QtControls.Label { - height: parent.height - width: parent.width / 3 - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - text: i18n("Style") - } - QtControls.ComboBox { - id: textStyle - width: parent.width * 2 / 3 - textRole: "label" - model: [ - { - 'label': i18n("normal"), - 'name': "normal" - }, - { - 'label': i18n("outline"), - 'name': "outline" - }, - { - 'label': i18n("raised"), - 'name': "raised" - }, - { - 'label': i18n("sunken"), - 'name': "sunken" - } - ] - onCurrentIndexChanged: cfg_textStyle = model[currentIndex]["name"] - Component.onCompleted: { - if (debug) console.debug() - for (var i = 0; i < model.length; i++) { - if (model[i]["name"] == plasmoid.configuration.textStyle) { - if (debug) console.info("Found", model[i]["name"], "on", i) - textStyle.currentIndex = i - } - } + ComboBoxSelector { + id: textStyle + model: [ + { + 'label': i18n("normal"), + 'name': "normal" + }, + { + 'label': i18n("outline"), + 'name': "outline" + }, + { + 'label': i18n("raised"), + 'name': "raised" + }, + { + 'label': i18n("sunken"), + 'name': "sunken" } - } + ] + text: i18n("Style") + value: plasmoid.configuration.textStyle + onValueEdited: cfg_textStyle = newValue } Row { diff --git a/sources/awesome-widget/package/contents/ui/dataengine.qml b/sources/awesome-widget/package/contents/ui/dataengine.qml index a536dee..b507ef4 100644 --- a/sources/awesome-widget/package/contents/ui/dataengine.qml +++ b/sources/awesome-widget/package/contents/ui/dataengine.qml @@ -52,21 +52,10 @@ Item { height: implicitHeight width: parent.width title: i18n("ACPI") - Row { - height: implicitHeight - width: parent.width - QtControls.Label { - height: parent.height - width: parent.width * 2 / 5 - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - text: i18n("ACPI path") - } - QtControls.TextField { - width: parent.width * 3 / 5 - text: cfg_dataengine["ACPIPATH"] - onEditingFinished: cfg_dataengine["ACPIPATH"] = text - } + LineSelector { + text: i18n("ACPI path") + value: cfg_dataengine["ACPIPATH"] + onValueEdited: cfg_dataengine["ACPIPATH"] = newValue } } @@ -74,30 +63,28 @@ Item { height: implicitHeight width: parent.width title: i18n("GPU") - Row { - height: implicitHeight - width: parent.width - QtControls.Label { - height: parent.height - width: parent.width * 2 / 5 - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - text: i18n("GPU device") - } - QtControls.ComboBox { - id: gpuDev - width: parent.width * 3 / 5 - model: ["auto", "disable", "ati", "nvidia"] - Component.onCompleted: { - if (debug) console.debug() - for (var i=0; idevices(QString("hdd")); + QStringList hddDevices = m_keyOperator->devices(QString("hdd")); // required by selector in the UI - devices.insert(0, QString("disable")); - devices.insert(0, QString("auto")); + hddDevices.insert(0, QString("disable")); + hddDevices.insert(0, QString("auto")); + + // build model + QVariantList devices; + for (auto device : hddDevices) { + QVariantMap model; + model[QString("label")] = device; + model[QString("name")] = device; + devices.append(model); + } return devices; } diff --git a/sources/awesome-widget/plugin/awkeys.h b/sources/awesome-widget/plugin/awkeys.h index 257fe00..0f70d36 100644 --- a/sources/awesome-widget/plugin/awkeys.h +++ b/sources/awesome-widget/plugin/awkeys.h @@ -51,7 +51,7 @@ public: // keys Q_INVOKABLE QStringList dictKeys(const bool sorted = false, const QString regexp = QString()) const; - Q_INVOKABLE QStringList getHddDevices() const; + Q_INVOKABLE QVariantList getHddDevices() const; // values Q_INVOKABLE QString infoByKey(QString key) const; Q_INVOKABLE QString valueByKey(QString key) const; diff --git a/sources/test/testawkeys.cpp b/sources/test/testawkeys.cpp index 84d7beb..cb819fa 100644 --- a/sources/test/testawkeys.cpp +++ b/sources/test/testawkeys.cpp @@ -72,7 +72,7 @@ void TestAWKeys::cleanupTestCase() void TestAWKeys::test_hddDevices() { - QVERIFY(!plugin->getHddDevices().isEmpty()); + QVERIFY(plugin->getHddDevices().count() > 2); }