From 362f1fd87e5cf6b4828b4bcf478526967ec6b689 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Fri, 12 Feb 2016 09:23:30 +0300 Subject: [PATCH] prepare to move to generic bars This commits series introduces bars which may be calculated from any custom formula. For a start I've renamed $bar*tag to $bar* and add new configuration parameters to graphical items. --- sources/awesome-widget/plugin/awkeycache.cpp | 6 +- .../awesome-widget/plugin/awkeyoperations.cpp | 37 ++--- sources/awesome-widget/plugin/awkeys.cpp | 41 ++++- .../plugin/awkeysaggregator.cpp | 3 +- sources/awesomewidgets/abstractextitem.cpp | 10 +- sources/awesomewidgets/abstractextitem.h | 3 +- sources/awesomewidgets/extitemaggregator.h | 8 +- sources/awesomewidgets/extquotes.cpp | 6 +- sources/awesomewidgets/extscript.cpp | 6 +- sources/awesomewidgets/extupgrade.cpp | 6 +- sources/awesomewidgets/extweather.cpp | 6 +- sources/awesomewidgets/graphicalitem.cpp | 155 +++++++++++++----- sources/awesomewidgets/graphicalitem.h | 22 ++- sources/awesomewidgets/graphicalitem.ui | 139 ++++++++++++++-- sources/version.h.in | 2 +- 15 files changed, 322 insertions(+), 128 deletions(-) diff --git a/sources/awesome-widget/plugin/awkeycache.cpp b/sources/awesome-widget/plugin/awkeycache.cpp index c1133ad..cf2347b 100644 --- a/sources/awesome-widget/plugin/awkeycache.cpp +++ b/sources/awesome-widget/plugin/awkeycache.cpp @@ -91,11 +91,7 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &keys, // initial copy QSet used = QSet::fromList(keys); - // insert bars - for (auto bar : bars) { - bar.remove(QRegExp(QString("^bar[0-9]{1,}"))); - used << bar; - } + used.unite(QSet::fromList(bars)); // insert keys from tooltip for (auto key : tooltip.keys()) { if ((key.endsWith(QString("Tooltip"))) && (tooltip[key].toBool())) { diff --git a/sources/awesome-widget/plugin/awkeyoperations.cpp b/sources/awesome-widget/plugin/awkeyoperations.cpp index 135d6f2..72d2c8b 100644 --- a/sources/awesome-widget/plugin/awkeyoperations.cpp +++ b/sources/awesome-widget/plugin/awkeyoperations.cpp @@ -226,12 +226,8 @@ QStringList AWKeyOperations::dictKeys() const allKeys.append(QString("la5")); allKeys.append(QString("la1")); // bars - QStringList graphicalItemsKeys; - for (auto item : graphicalItems->items()) - graphicalItemsKeys.append(item->tag()); - graphicalItemsKeys.sort(); - for (int i = graphicalItemsKeys.count() - 1; i >= 0; i--) - allKeys.append(graphicalItemsKeys.at(i)); + for (int i = graphicalItems->activeItems().count() -1; i >= 0; i--) + allKeys.append(graphicalItems->activeItems().at(i)->tag(QString("bar"))); return allKeys; } @@ -243,7 +239,7 @@ GraphicalItem *AWKeyOperations::giByKey(const QString key) const { qCDebug(LOG_AW) << "Looking for item" << key; - return graphicalItems->itemByTag(key); + return graphicalItems->itemByTag(key, QString("bar")); } @@ -251,11 +247,10 @@ QString AWKeyOperations::infoByKey(QString key) const { qCDebug(LOG_AW) << "Requested key" << key; - key.remove(QRegExp(QString("^bar[0-9]{1,}"))); - if (key.startsWith(QString("custom"))) - return extScripts->itemByTagNumber( - key.remove(QString("custom")).toInt()) - ->uniq(); + if (key.startsWith(QString("bar"))) + return graphicalItems->itemByTag(key, QString("bar"))->uniq(); + else if (key.startsWith(QString("custom"))) + return extScripts->itemByTag(key, QString("custom"))->uniq(); else if (key.contains(QRegExp(QString("^hdd[rw]")))) return QString("%1").arg(m_devices[QString( "disk")][key.remove(QRegExp(QString("hdd[rw]"))).toInt()]); @@ -273,24 +268,12 @@ QString AWKeyOperations::infoByKey(QString key) const return QString("%1").arg(m_devices[QString( "net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]); else if (key.startsWith(QString("pkgcount"))) - return extUpgrade->itemByTagNumber( - key.remove(QString("pkgcount")).toInt()) - ->uniq(); + return extUpgrade->itemByTag(key, QString("pkgcount"))->uniq(); else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)")))) - return extQuotes->itemByTagNumber( - key.remove(QRegExp(QString( - "(^|perc)(ask|bid|price)(chg|)"))) - .toInt()) - ->uniq(); + return extQuotes->itemByTag(key, QString("ask"))->uniq(); else if (key.contains(QRegExp( QString("(weather|weatherId|humidity|pressure|temperature)")))) - return extWeather - ->itemByTagNumber( - key - .remove(QRegExp(QString( - "(weather|weatherId|humidity|pressure|temperature)"))) - .toInt()) - ->uniq(); + return extWeather->itemByTag(key, QString("weather"))->uniq(); else if (key.startsWith(QString("temp"))) return QString("%1").arg( m_devices[QString("temp")][key.remove(QString("temp")).toInt()]); diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index 4526906..8251cfe 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -205,9 +205,19 @@ void AWKeys::reinitKeys(const QStringList currentKeys) m_foundKeys = AWPatternFunctions::findKeys(keyOperator->pattern(), currentKeys); m_foundLambdas = AWPatternFunctions::findLambdas(keyOperator->pattern()); + // generate list of required keys for bars + QStringList barKeys; + for (auto bar : m_foundBars) { + GraphicalItem *item = keyOperator->giByKey(bar); + if (item->isCustom()) + item->setUsedKeys(AWPatternFunctions::findKeys(item->bar(), currentKeys)); + else + item->setUsedKeys(QStringList() << item->bar()); + barKeys.append(item->usedKeys()); + } // get required keys m_requiredKeys - = m_optimize ? AWKeyCache::getRequiredKeys(m_foundKeys, m_foundBars, + = m_optimize ? AWKeyCache::getRequiredKeys(m_foundKeys, barKeys, m_tooltipParams, currentKeys) : QStringList(); @@ -318,16 +328,29 @@ QString AWKeys::parsePattern(QString pattern) const // bars for (auto bar : m_foundBars) { GraphicalItem *item = keyOperator->giByKey(bar); - QString key = bar; - key.remove(QRegExp(QString("^bar[0-9]{1,}"))); if (item->type() == GraphicalItem::Graph) pattern.replace(QString("$%1").arg(bar), - item->image([](const QList data) { - return QVariant::fromValue>(data); - }(dataAggregator->getData(key)))); - else - pattern.replace(QString("$%1").arg(bar), - item->image(values[key].toFloat())); + item->image(QVariant::fromValue>(dataAggregator->getData(item->bar())))); + else { + if (item->isCustom()) + pattern.replace(QString("$%1").arg(bar),item->image([this, item](QString bar ){ + QJSEngine engine; + for (auto key : item->usedKeys()) + bar.replace(QString("$%1").arg(key), aggregator->formater(values[key], key)); + qCInfo(LOG_AW) << "Expression" << bar; + QJSValue result = engine.evaluate(bar); + if (result.isError()) { + qCWarning(LOG_AW) << "Uncaught exception at line" + << result.property("lineNumber").toInt() + << ":" << result.toString(); + return QString(); + } else { + return result.toString(); + } + }(item->bar()))); + else + pattern.replace(QString("$%1").arg(bar),item->image(values[item->bar()])); + } } // prepare strings diff --git a/sources/awesome-widget/plugin/awkeysaggregator.cpp b/sources/awesome-widget/plugin/awkeysaggregator.cpp index ddc7c42..7a1887b 100644 --- a/sources/awesome-widget/plugin/awkeysaggregator.cpp +++ b/sources/awesome-widget/plugin/awkeysaggregator.cpp @@ -539,7 +539,8 @@ QStringList AWKeysAggregator::registerSource(const QString &source, // drop key from dictionary if no one user requested key required it QStringList foundKeys = keysFromSource(source); qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << keys; - // let required if key list is empty no one use it + // this source is required if list is empty (which means skip checking) + // or if key in required key list bool required = keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(), [&keys](const QString &key) { diff --git a/sources/awesomewidgets/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp index 6691f10..b66f7ca 100644 --- a/sources/awesomewidgets/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -24,6 +24,7 @@ #include "awdebug.h" #include "version.h" +#include "abstractextitemaggregator.h" AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName, @@ -47,10 +48,13 @@ AbstractExtItem::~AbstractExtItem() } -template T *AbstractExtItem::copy(const QString, const int) +void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const { - // an analog of pure virtual method - return new T(); + _other->setActive(m_active); + _other->setApiVersion(m_apiVersion); + _other->setComment(m_comment); + _other->setInterval(m_interval); + _other->setName(m_name); } diff --git a/sources/awesomewidgets/abstractextitem.h b/sources/awesomewidgets/abstractextitem.h index 60d0729..bc01a81 100644 --- a/sources/awesomewidgets/abstractextitem.h +++ b/sources/awesomewidgets/abstractextitem.h @@ -40,7 +40,8 @@ public: const QString desktopName = QString(), const QStringList directories = QStringList()); virtual ~AbstractExtItem(); - template T *copy(const QString, const int); + virtual AbstractExtItem *copy(const QString _fileName, const int _number) = 0; + void copyDefaults(AbstractExtItem *_other) const; // get methods int apiVersion() const; QString comment() const; diff --git a/sources/awesomewidgets/extitemaggregator.h b/sources/awesomewidgets/extitemaggregator.h index 5e0b9ea..df92a16 100644 --- a/sources/awesomewidgets/extitemaggregator.h +++ b/sources/awesomewidgets/extitemaggregator.h @@ -62,13 +62,13 @@ public: qCInfo(LOG_LIB) << "Dialog returns" << ret; }; - T *itemByTag(const QString _tag) const + T *itemByTag(const QString _tag, const QString _type) const { - qCDebug(LOG_LIB) << "Tag" << _tag; + qCDebug(LOG_LIB) << "Tag" << _tag << "with used type" << _type; T *found = nullptr; for (auto item : m_items) { - if (item->tag() != _tag) + if (item->tag(_type) != _tag) continue; found = item; break; @@ -211,7 +211,7 @@ private: return; } - T *newItem = source->copy(fileName, number); + T *newItem = static_cast(source->copy(fileName, number)); if (newItem->showConfiguration(configArgs()) == 1) { initItems(); repaint(); diff --git a/sources/awesomewidgets/extquotes.cpp b/sources/awesomewidgets/extquotes.cpp index 49e9725..cbb4ed5 100644 --- a/sources/awesomewidgets/extquotes.cpp +++ b/sources/awesomewidgets/extquotes.cpp @@ -81,11 +81,7 @@ ExtQuotes *ExtQuotes::copy(const QString _fileName, const int _number) ExtQuotes *item = new ExtQuotes(static_cast(parent()), _fileName, directories()); - item->setActive(isActive()); - item->setApiVersion(apiVersion()); - item->setComment(comment()); - item->setInterval(interval()); - item->setName(name()); + copyDefaults(item); item->setNumber(_number); item->setTicker(ticker()); diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index 6c114a0..90c61d1 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -68,12 +68,8 @@ ExtScript *ExtScript::copy(const QString _fileName, const int _number) ExtScript *item = new ExtScript(static_cast(parent()), _fileName, directories()); - item->setActive(isActive()); - item->setApiVersion(apiVersion()); - item->setComment(comment()); + copyDefaults(item); item->setExecutable(executable()); - item->setInterval(interval()); - item->setName(name()); item->setNumber(_number); item->setPrefix(prefix()); item->setRedirect(redirect()); diff --git a/sources/awesomewidgets/extupgrade.cpp b/sources/awesomewidgets/extupgrade.cpp index 2fe6a4f..33d79df 100644 --- a/sources/awesomewidgets/extupgrade.cpp +++ b/sources/awesomewidgets/extupgrade.cpp @@ -64,13 +64,9 @@ ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number) ExtUpgrade *item = new ExtUpgrade(static_cast(parent()), _fileName, directories()); - item->setActive(isActive()); - item->setApiVersion(apiVersion()); - item->setComment(comment()); + copyDefaults(item); item->setExecutable(executable()); item->setFilter(filter()); - item->setInterval(interval()); - item->setName(name()); item->setNumber(_number); item->setNull(null()); diff --git a/sources/awesomewidgets/extweather.cpp b/sources/awesomewidgets/extweather.cpp index 8e865d5..6a69254 100644 --- a/sources/awesomewidgets/extweather.cpp +++ b/sources/awesomewidgets/extweather.cpp @@ -78,14 +78,10 @@ ExtWeather *ExtWeather::copy(const QString _fileName, const int _number) ExtWeather *item = new ExtWeather(static_cast(parent()), _fileName, directories()); - item->setActive(isActive()); - item->setApiVersion(apiVersion()); + copyDefaults(item); item->setCity(city()); - item->setComment(comment()); item->setCountry(country()); - item->setInterval(interval()); item->setImage(image()); - item->setName(name()); item->setNumber(_number); item->setTs(ts()); diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index 843da2b..7b0a27d 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -47,6 +47,8 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName, initScene(); + connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this, + SLOT(changeValue(int))); connect(ui->pushButton_activeColor, SIGNAL(clicked()), this, SLOT(changeColor())); connect(ui->pushButton_inactiveColor, SIGNAL(clicked()), this, @@ -69,29 +71,26 @@ GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number) GraphicalItem *item = new GraphicalItem(static_cast(parent()), _fileName, directories()); - item->setActive(isActive()); - item->setActiveColor(activeColor()); - item->setApiVersion(apiVersion()); - item->setBar(bar()); - item->setComment(comment()); - item->setDirection(direction()); - item->setHeight(height()); - item->setInactiveColor(inactiveColor()); - item->setInterval(interval()); - item->setName(QString("bar%1").arg(_number)); + copyDefaults(item); + item->setActiveColor(m_activeColor); + item->setBar(m_bar); + item->setCustom(m_custom); + item->setDirection(m_direction); + item->setHeight(m_height); + item->setInactiveColor(m_inactiveColor); + item->setMaxValue(m_maxValue); + item->setMinValue(m_minValue); item->setNumber(_number); - item->setType(type()); - item->setWidth(width()); + item->setType(m_type); + item->setWidth(m_width); return item; } -QString GraphicalItem::image(const QVariant value) +QString GraphicalItem::image(const QVariant &value) { qCDebug(LOG_LIB) << "Value" << value; - if (m_bar == QString("none")) - return QString(""); m_scene->clear(); int scale[2] = {1, 1}; @@ -151,9 +150,21 @@ QString GraphicalItem::inactiveColor() const } -QString GraphicalItem::tag() const +bool GraphicalItem::isCustom() const { - return QString("bar%1%2").arg(number()).arg(m_bar); + return m_custom; +} + + +float GraphicalItem::maxValue() const +{ + return m_maxValue; +} + + +float GraphicalItem::minValue() const +{ + return m_minValue; } @@ -215,6 +226,12 @@ int GraphicalItem::height() const } +QStringList GraphicalItem::usedKeys() const +{ + return m_usedKeys; +} + + int GraphicalItem::width() const { return m_width; @@ -231,13 +248,7 @@ void GraphicalItem::setBar(const QString _bar) { qCDebug(LOG_LIB) << "Bar" << _bar; - if (!_bar.contains(QRegExp( - QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")))) { - qCWarning(LOG_LIB) << "Unsupported bar type" << _bar; - m_bar = QString("none"); - } else { - m_bar = _bar; - } + m_bar = _bar; } @@ -249,6 +260,14 @@ void GraphicalItem::setActiveColor(const QString _color) } +void GraphicalItem::setCustom(const bool _custom) +{ + qCDebug(LOG_LIB) << "Use custom tag" << _custom; + + m_custom = _custom; +} + + void GraphicalItem::setInactiveColor(const QString _color) { qCDebug(LOG_LIB) << "Color" << _color; @@ -257,6 +276,22 @@ void GraphicalItem::setInactiveColor(const QString _color) } +void GraphicalItem::setMaxValue(const float _value) +{ + qCDebug(LOG_LIB) << "Max value" << _value; + + m_maxValue = _value; +} + + +void GraphicalItem::setMinValue(const float _value) +{ + qCDebug(LOG_LIB) << "Min value" << _value; + + m_minValue = _value; +} + + void GraphicalItem::setType(const Type _type) { qCDebug(LOG_LIB) << "Type" << _type; @@ -309,6 +344,15 @@ void GraphicalItem::setHeight(const int _height) } +void GraphicalItem::setUsedKeys(const QStringList _usedKeys) +{ + qCDebug(LOG_LIB) << "Used keys" << _usedKeys; + + // remove dubs + m_usedKeys = QSet::fromList(_usedKeys).toList(); +} + + void GraphicalItem::setWidth(const int _width) { qCDebug(LOG_LIB) << "Width" << _width; @@ -333,7 +377,10 @@ void GraphicalItem::readConfiguration() QSettings::IniFormat); settings.beginGroup(QString("Desktop Entry")); + setCustom(settings.value(QString("X-AW-Custom"), m_custom).toBool()); setBar(settings.value(QString("X-AW-Value"), m_bar).toString()); + setMaxValue(settings.value(QString("X-AW-Max"), m_maxValue).toFloat()); + setMinValue(settings.value(QString("X-AW-Min"), m_minValue).toFloat()); setActiveColor( settings.value(QString("X-AW-ActiveColor"), m_activeColor) .toString()); @@ -374,11 +421,18 @@ int GraphicalItem::showConfiguration(const QVariant args) qCDebug(LOG_LIB) << "Combobox arguments" << args; QStringList tags = args.toStringList(); - ui->label_nameValue->setText(name()); + ui->lineEdit_name->setText(name()); ui->lineEdit_comment->setText(comment()); + ui->checkBox_custom->setChecked(m_custom); ui->comboBox_value->addItems(tags); - ui->comboBox_value->addItem(m_bar); - ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count() - 1); + if (m_custom) { + ui->lineEdit_customValue->setText(m_bar); + } else { + ui->comboBox_value->addItem(m_bar); + ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count() - 1); + } + ui->doubleSpinBox_max->setValue(m_maxValue); + ui->doubleSpinBox_min->setValue(m_minValue); ui->pushButton_activeColor->setText(m_activeColor); ui->pushButton_inactiveColor->setText(m_inactiveColor); ui->comboBox_type->setCurrentIndex(static_cast(m_type)); @@ -389,10 +443,13 @@ int GraphicalItem::showConfiguration(const QVariant args) int ret = exec(); if (ret != 1) return ret; - setName(ui->label_nameValue->text()); + setName(ui->lineEdit_name->text()); setComment(ui->lineEdit_comment->text()); setApiVersion(AWGIAPI); - setBar(ui->comboBox_value->currentText()); + setCustom(ui->checkBox_custom->isChecked()); + setBar(m_custom ? ui->lineEdit_customValue->text() : ui->comboBox_value->currentText()); + setMaxValue(ui->doubleSpinBox_max->value()); + setMinValue(ui->doubleSpinBox_min->value()); setActiveColor(ui->pushButton_activeColor->text().remove(QChar('&'))); setInactiveColor(ui->pushButton_inactiveColor->text().remove(QChar('&'))); setStrType(ui->comboBox_type->currentText()); @@ -416,6 +473,9 @@ void GraphicalItem::writeConfiguration() const settings.beginGroup(QString("Desktop Entry")); settings.setValue(QString("X-AW-Value"), m_bar); + settings.setValue(QString("X-AW-Custom"), m_custom); + settings.setValue(QString("X-AW-Max"), m_maxValue); + settings.setValue(QString("X-AW-Min"), m_minValue); settings.setValue(QString("X-AW-ActiveColor"), m_activeColor); settings.setValue(QString("X-AW-InactiveColor"), m_inactiveColor); settings.setValue(QString("X-AW-Type"), strType()); @@ -449,6 +509,15 @@ void GraphicalItem::changeColor() } +void GraphicalItem::changeValue(const int state) +{ + qCDebug(LOG_LIB) << "Current state is" << state; + + ui->widget_value->setHidden(state == Qt::Unchecked); + ui->widget_customValue->setHidden(state != Qt::Unchecked); +} + + void GraphicalItem::initScene() { // init scene @@ -464,15 +533,15 @@ void GraphicalItem::initScene() m_view->setFrameShape(QFrame::NoFrame); m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_view->resize(m_width + 5.0, m_height + 5.0); + m_view->resize(m_width + 5, m_height + 5); } void GraphicalItem::paintCircle(const float value) { QPen pen; - pen.setWidth(1.0); - float percent = value / 100.0; + pen.setWidth(1); + float percent = (value - m_minValue) / (m_maxValue - m_minValue); QGraphicsEllipseItem *circle; QColor inactive = stringToColor(m_inactiveColor); @@ -482,14 +551,14 @@ void GraphicalItem::paintCircle(const float value) pen.setColor(inactive); circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen, QBrush(inactive, Qt::SolidPattern)); - circle->setSpanAngle(-(1.0 - percent) * 360.0 * 16.0); - circle->setStartAngle(90.0 * 16.0 - percent * 360.0 * 16.0); + circle->setSpanAngle(-(1.0f - percent) * 360.0f * 16.0f); + circle->setStartAngle(90.0f * 16.0f - percent * 360.0f * 16.0f); // active pen.setColor(active); circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen, QBrush(active, Qt::SolidPattern)); - circle->setSpanAngle(-percent * 360.0 * 16.0); - circle->setStartAngle(90.0 * 16.0); + circle->setSpanAngle(-percent * 360.0f * 16.0f); + circle->setStartAngle(90.0f * 16.0f); } @@ -501,14 +570,14 @@ void GraphicalItem::paintGraph(const QList value) // default norms float normX = static_cast(m_width) / static_cast(value.count()); - float normY = static_cast(m_height) / (1.5 * 100.0); + float normY = static_cast(m_height) / (1.5f * 100.0f); // paint graph for (int i = 0; i < value.count() - 1; i++) { // some magic here float x1 = i * normX; - float y1 = -fabs(value.at(i)) * normY + 5.0; + float y1 = -fabs(value.at(i)) * normY + 5.0f; float x2 = (i + 1) * normX; - float y2 = -fabs(value.at(i + 1)) * normY + 5.0; + float y2 = -fabs(value.at(i + 1)) * normY + 5.0f; m_scene->addLine(x1, y1, x2, y2, pen); } } @@ -517,7 +586,7 @@ void GraphicalItem::paintGraph(const QList value) void GraphicalItem::paintHorizontal(const float value) { QPen pen; - float percent = value / 100.0; + float percent = (value - m_minValue) / (m_maxValue - m_minValue); pen.setWidth(m_height); // inactive @@ -534,7 +603,7 @@ void GraphicalItem::paintHorizontal(const float value) void GraphicalItem::paintVertical(const float value) { QPen pen; - float percent = value / 100.0; + float percent = (value - m_minValue) / (m_maxValue - m_minValue); pen.setWidth(m_width); // inactive @@ -569,7 +638,11 @@ void GraphicalItem::translate() { ui->label_name->setText(i18n("Name")); ui->label_comment->setText(i18n("Comment")); + ui->checkBox_custom->setText(i18n("Use custom formula")); ui->label_value->setText(i18n("Value")); + ui->label_customValue->setText(i18n("Value")); + ui->label_max->setText(i18n("Max value")); + ui->label_min->setText(i18n("Min value")); ui->label_activeColor->setText(i18n("Active color")); ui->label_inactiveColor->setText(i18n("Inactive color")); ui->label_type->setText(i18n("Type")); diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index eb0ef78..ee83c00 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -36,10 +36,14 @@ class GraphicalItem : public AbstractExtItem Q_OBJECT Q_PROPERTY(QString bar READ bar WRITE setBar) Q_PROPERTY(QString activeColor READ activeColor WRITE setActiveColor) + Q_PROPERTY(bool custom READ isCustom WRITE setCustom) Q_PROPERTY(QString inactiveColor READ inactiveColor WRITE setInactiveColor) Q_PROPERTY(Type type READ type WRITE setType) Q_PROPERTY(Direction direction READ direction WRITE setDirection) Q_PROPERTY(int height READ height WRITE setHeight) + Q_PROPERTY(float maxValue READ maxValue WRITE setMaxValue) + Q_PROPERTY(float minValue READ minValue WRITE setMinValue) + Q_PROPERTY(QStringList usedKeys READ usedKeys WRITE setUsedKeys) Q_PROPERTY(int width READ width WRITE setWidth) public: @@ -51,28 +55,35 @@ public: const QStringList directories = QStringList()); virtual ~GraphicalItem(); GraphicalItem *copy(const QString _fileName, const int _number); - QString image(const QVariant value); + QString image(const QVariant &value); // get methods QString bar() const; QString activeColor() const; QString inactiveColor() const; - QString tag() const; + bool isCustom() const; + float minValue() const; + float maxValue() const; Type type() const; QString strType() const; Direction direction() const; QString strDirection() const; int height() const; + QStringList usedKeys() const; int width() const; QString uniq() const; // set methods void setBar(const QString _bar = QString("cpu")); void setActiveColor(const QString _color = QString("0,0,0,130")); + void setCustom(const bool _custom); void setInactiveColor(const QString _color = QString("255,255,255,130")); + void setMinValue(const float _value); + void setMaxValue(const float _value); void setType(const Type _type = Horizontal); void setStrType(const QString _type = QString("Horizontal")); void setDirection(const Direction _direction = LeftToRight); void setStrDirection(const QString _direction = QString("LeftToRight")); void setHeight(const int _height = 100); + void setUsedKeys(const QStringList _usedKeys = QStringList()); void setWidth(const int _width = 100); public slots: @@ -83,10 +94,9 @@ public slots: private slots: void changeColor(); + void changeValue(const int state); private: - QString m_fileName; - QStringList m_dirs; QGraphicsScene *m_scene = nullptr; QGraphicsView *m_view = nullptr; Ui::GraphicalItem *ui; @@ -101,11 +111,15 @@ private: void translate(); // properties QString m_bar = QString("cpu"); + bool m_custom = false; QString m_activeColor = QString("0,0,0,130"); QString m_inactiveColor = QString("255,255,255,130"); + float m_minValue = 0.0f; + float m_maxValue = 100.0f; Type m_type = Horizontal; Direction m_direction = LeftToRight; int m_height = 100; + QStringList m_usedKeys; int m_width = 100; }; diff --git a/sources/awesomewidgets/graphicalitem.ui b/sources/awesomewidgets/graphicalitem.ui index a2fb703..a14676e 100644 --- a/sources/awesomewidgets/graphicalitem.ui +++ b/sources/awesomewidgets/graphicalitem.ui @@ -7,7 +7,7 @@ 0 0 416 - 325 + 461 @@ -18,6 +18,12 @@ + + + 0 + 0 + + Name @@ -27,11 +33,7 @@ - - - - - + @@ -59,11 +61,96 @@ - + + + Qt::Horizontal + + + + + - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + - Value + Use custom formula + + + + + + + + + + + + Value + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + false + + + + + + + + + + + + + + 0 + 0 + + + + Value + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + Max value Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -71,14 +158,42 @@ - - - false + + + 9999.989999999999782 + + + + + + Min value + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 9999.989999999999782 + + + + + + + + + Qt::Horizontal + + + diff --git a/sources/version.h.in b/sources/version.h.in index 31f8744..4867298 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -16,7 +16,7 @@ // configuraion // graphical items api version -#define AWGIAPI 3 +#define AWGIAPI 4 // extquotes api version #define AWEQAPI 3 // extscript api version