From a3e7a84b92598ff3e2824b175db652b249015de6 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Tue, 12 Apr 2016 14:22:19 +0300 Subject: [PATCH] drop another part of pornography in gi more intuinitve configuration interface in graphicalitem. Improve code for the future references (in case if new color type will be added). Change X-AW-*Color values to ones with prefixes (added autoconversion from old-version api) --- .../awesome-widget/plugin/awupdatehelper.cpp | 8 +- .../desktops/aw-bat-bar.desktop | 6 +- .../desktops/aw-cpu-bar.desktop | 6 +- .../desktops/aw-mem-bar.desktop | 6 +- .../desktops/aw-swap-bar.desktop | 6 +- sources/awesomewidgets/graphicalitem.cpp | 97 +++++---- sources/awesomewidgets/graphicalitem.h | 9 +- sources/awesomewidgets/graphicalitem.ui | 189 +++++------------- .../awesomewidgets/graphicalitemhelper.cpp | 25 ++- sources/awesomewidgets/graphicalitemhelper.h | 1 + sources/version.h.in | 2 +- 11 files changed, 157 insertions(+), 198 deletions(-) diff --git a/sources/awesome-widget/plugin/awupdatehelper.cpp b/sources/awesome-widget/plugin/awupdatehelper.cpp index eecb557..b43001b 100644 --- a/sources/awesome-widget/plugin/awupdatehelper.cpp +++ b/sources/awesome-widget/plugin/awupdatehelper.cpp @@ -74,14 +74,18 @@ bool AWUpdateHelper::checkVersion() // update version settings.setValue(QString("Version"), QString(VERSION)); settings.sync(); + qCInfo(LOG_AW) << "Found version" << version << "actual one is" + << m_foundVersion; - qCInfo(LOG_AW) << "Found version" << version << "actual one is" << VERSION; - if (version != QVersionNumber::fromString(VERSION)) { + if ((version != m_foundVersion) && (!QString(CHANGELOG).isEmpty())) { genMessageBox(i18n("Changelog of %1", QString(VERSION)), QString(CHANGELOG).replace(QChar('@'), QChar('\n')), QMessageBox::Ok) ->open(); return true; + } else if (version != m_foundVersion) { + qCWarning(LOG_AW) << "No changelog information provided"; + return true; } else { qCInfo(LOG_AW) << "No need to update version"; } diff --git a/sources/awesomewidgets/desktops/aw-bat-bar.desktop b/sources/awesomewidgets/desktops/aw-bat-bar.desktop index 5dac5d4..cb0d109 100644 --- a/sources/awesomewidgets/desktops/aw-bat-bar.desktop +++ b/sources/awesomewidgets/desktops/aw-bat-bar.desktop @@ -6,11 +6,11 @@ X-AW-Value=bat X-AW-Custom=false X-AW-Max=100.0 X-AW-Min=0.0 -X-AW-ActiveColor="0,0,0,255" -X-AW-InactiveColor="255,255,255,255" +X-AW-ActiveColor="color://0,0,0,255" +X-AW-InactiveColor="color://255,255,255,255" X-AW-Type=Horizontal X-AW-Direction=LeftToRight X-AW-Height=25 X-AW-Width=100 -X-AW-ApiVersion=4 +X-AW-ApiVersion=5 X-AW-Number=3 diff --git a/sources/awesomewidgets/desktops/aw-cpu-bar.desktop b/sources/awesomewidgets/desktops/aw-cpu-bar.desktop index 224f58b..df164f4 100644 --- a/sources/awesomewidgets/desktops/aw-cpu-bar.desktop +++ b/sources/awesomewidgets/desktops/aw-cpu-bar.desktop @@ -6,11 +6,11 @@ X-AW-Value=cpu X-AW-Custom=false X-AW-Max=100.0 X-AW-Min=0.0 -X-AW-ActiveColor="0,0,0,255" -X-AW-InactiveColor="255,255,255,255" +X-AW-ActiveColor="color://0,0,0,255" +X-AW-InactiveColor="color://255,255,255,255" X-AW-Type=Horizontal X-AW-Direction=LeftToRight X-AW-Height=25 X-AW-Width=100 -X-AW-ApiVersion=4 +X-AW-ApiVersion=5 X-AW-Number=0 diff --git a/sources/awesomewidgets/desktops/aw-mem-bar.desktop b/sources/awesomewidgets/desktops/aw-mem-bar.desktop index d76fa22..4749a0c 100644 --- a/sources/awesomewidgets/desktops/aw-mem-bar.desktop +++ b/sources/awesomewidgets/desktops/aw-mem-bar.desktop @@ -6,11 +6,11 @@ X-AW-Value=mem X-AW-Custom=false X-AW-Max=100.0 X-AW-Min=0.0 -X-AW-ActiveColor="0,0,0,255" -X-AW-InactiveColor="255,255,255,255" +X-AW-ActiveColor="color://0,0,0,255" +X-AW-InactiveColor="color://255,255,255,255" X-AW-Type=Horizontal X-AW-Direction=LeftToRight X-AW-Height=25 X-AW-Width=100 -X-AW-ApiVersion=4 +X-AW-ApiVersion=5 X-AW-Number=1 diff --git a/sources/awesomewidgets/desktops/aw-swap-bar.desktop b/sources/awesomewidgets/desktops/aw-swap-bar.desktop index ee957ee..ba90548 100644 --- a/sources/awesomewidgets/desktops/aw-swap-bar.desktop +++ b/sources/awesomewidgets/desktops/aw-swap-bar.desktop @@ -6,11 +6,11 @@ X-AW-Value=swap X-AW-Custom=false X-AW-Max=100.0 X-AW-Min=0.0 -X-AW-ActiveColor="0,0,0,255" -X-AW-InactiveColor="255,255,255,255" +X-AW-ActiveColor="color://0,0,0,255" +X-AW-InactiveColor="color://255,255,255,255" X-AW-Type=Horizontal X-AW-Direction=LeftToRight X-AW-Height=25 X-AW-Width=100 -X-AW-ApiVersion=4 +X-AW-ApiVersion=5 X-AW-Number=2 diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index 9c523be..57c228c 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -50,9 +50,9 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName, SLOT(changeValue(int))); connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this, SLOT(changeCountState(int))); - connect(ui->pushButton_activeColor, SIGNAL(clicked()), this, + connect(ui->toolButton_activeColor, SIGNAL(clicked()), this, SLOT(changeColor())); - connect(ui->pushButton_inactiveColor, SIGNAL(clicked()), this, + connect(ui->toolButton_inactiveColor, SIGNAL(clicked()), this, SLOT(changeColor())); } @@ -415,9 +415,18 @@ void GraphicalItem::readConfiguration() .toString()); setHeight(settings.value(QString("X-AW-Height"), m_height).toInt()); setWidth(settings.value(QString("X-AW-Width"), m_width).toInt()); - // api == 2 - if (apiVersion() < 2) - setNumber(bar().remove(QString("bar")).toInt()); + // api == 5 + if (apiVersion() < 5) { + QString prefix; + prefix = m_activeColor.startsWith(QString("/")) + ? QString("file://%1") + : QString("color://%1"); + m_activeColor = prefix.arg(m_activeColor); + prefix = m_inactiveColor.startsWith(QString("/")) + ? QString("file://%1") + : QString("color://%1"); + m_inactiveColor = prefix.arg(m_inactiveColor); + } settings.endGroup(); } @@ -449,12 +458,16 @@ int GraphicalItem::showConfiguration(const QVariant args) ui->doubleSpinBox_max->setValue(m_maxValue); ui->doubleSpinBox_min->setValue(m_minValue); ui->spinBox_count->setValue(m_count); - ui->checkBox_activeCheck->setChecked( - m_activeColor.startsWith(QString("/"))); - ui->pushButton_activeColor->setText(m_activeColor); - ui->checkBox_inactiveCheck->setChecked( - m_inactiveColor.startsWith(QString("/"))); - ui->pushButton_inactiveColor->setText(m_inactiveColor); + if (m_helper->isColor(m_activeColor)) + ui->comboBox_activeImageType->setCurrentIndex(0); + else + ui->comboBox_activeImageType->setCurrentIndex(1); + ui->lineEdit_activeColor->setText(m_activeColor); + if (m_helper->isColor(m_inactiveColor)) + ui->comboBox_inactiveImageType->setCurrentIndex(0); + else + ui->comboBox_inactiveImageType->setCurrentIndex(1); + ui->lineEdit_inactiveColor->setText(m_inactiveColor); ui->comboBox_type->setCurrentIndex(static_cast(m_type)); ui->comboBox_direction->setCurrentIndex(static_cast(m_direction)); ui->spinBox_height->setValue(m_height); @@ -477,8 +490,8 @@ int GraphicalItem::showConfiguration(const QVariant args) : 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('&'))); + setActiveColor(ui->lineEdit_activeColor->text()); + setInactiveColor(ui->lineEdit_inactiveColor->text()); setStrType(ui->comboBox_type->currentText()); setStrDirection(ui->comboBox_direction->currentText()); setHeight(ui->spinBox_height->value()); @@ -518,22 +531,20 @@ void GraphicalItem::writeConfiguration() const void GraphicalItem::changeColor() { - QString outputColor; - bool imageRequired = sender() == ui->pushButton_activeColor - ? ui->checkBox_activeCheck->isChecked() - : ui->checkBox_inactiveCheck->isChecked(); - - if (imageRequired) { - QString path = static_cast(sender())->text(); - QString directory = QFileInfo(path).absolutePath(); - outputColor = QFileDialog::getOpenFileName( - this, tr("Select path"), directory, - tr("Images (*.png *.bpm *.jpg);;All files (*.*)")); - - qCInfo(LOG_LIB) << "Selected path" << outputColor; + QLineEdit *lineEdit; + int state; + if (sender() == ui->toolButton_activeColor) { + lineEdit = ui->lineEdit_activeColor; + state = ui->comboBox_activeImageType->currentIndex(); } else { - QColor color = m_helper->stringToColor( - (static_cast(sender()))->text()); + lineEdit = ui->lineEdit_inactiveColor; + state = ui->comboBox_inactiveImageType->currentIndex(); + } + qCInfo(LOG_LIB) << "Using state" << state << "and lineEdit" << lineEdit; + + QString outputColor; + if (state == 0) { + QColor color = m_helper->stringToColor(lineEdit->text()); QColor newColor = QColorDialog::getColor( color, this, tr("Select color"), QColorDialog::ShowAlphaChannel); if (!newColor.isValid()) @@ -546,10 +557,23 @@ void GraphicalItem::changeColor() colorText.append(QString("%1").arg(newColor.blue())); colorText.append(QString("%1").arg(newColor.alpha())); - outputColor = colorText.join(QChar(',')); + outputColor = QString("color://%1").arg(colorText.join(QChar(','))); + } else if (state == 1) { + QString path = lineEdit->text(); + QString directory = QFileInfo(path).absolutePath(); + outputColor = QFileDialog::getOpenFileUrl( + this, tr("Select path"), directory, + tr("Images (*.png *.bpm *.jpg);;All files (*.*)")) + .toString(); + + qCInfo(LOG_LIB) << "Selected path" << outputColor; } - return static_cast(sender())->setText(outputColor); + if (outputColor.isEmpty()) { + qCWarning(LOG_LIB) << "Empty color selected, skipping"; + return; + } + return lineEdit->setText(outputColor); } @@ -602,12 +626,17 @@ void GraphicalItem::translate() ui->label_customValue->setText(i18n("Value")); ui->label_max->setText(i18n("Max value")); ui->label_min->setText(i18n("Min value")); - ui->checkBox_activeCheck->setText(i18n("Use image for active")); - ui->label_activeColor->setText(i18n("Active color")); - ui->checkBox_inactiveCheck->setText(i18n("Use image for inactive")); - ui->label_inactiveColor->setText(i18n("Inactive color")); + ui->label_activeImageType->setText(i18n("Active image type")); + ui->label_inactiveImageType->setText(i18n("Inctive image type")); ui->label_type->setText(i18n("Type")); ui->label_direction->setText(i18n("Direction")); ui->label_height->setText(i18n("Height")); ui->label_width->setText(i18n("Width")); + + ui->comboBox_activeImageType->clear(); + ui->comboBox_activeImageType->addItem(i18n("color")); + ui->comboBox_activeImageType->addItem(i18n("image")); + ui->comboBox_inactiveImageType->clear(); + ui->comboBox_inactiveImageType->addItem(i18n("color")); + ui->comboBox_inactiveImageType->addItem(i18n("image")); } diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index 5555847..9ccd67f 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -76,10 +76,11 @@ public: QString uniq() const; // set methods void setBar(const QString _bar = QString("cpu")); - void setActiveColor(const QString _color = QString("0,0,0,130")); + void setActiveColor(const QString _color = QString("color://0,0,0,130")); void setCount(const int _count = 100); void setCustom(const bool _custom = false); - void setInactiveColor(const QString _color = QString("255,255,255,130")); + void setInactiveColor(const QString _color + = QString("color://255,255,255,130")); void setMinValue(const float _value = 0.0); void setMaxValue(const float _value = 100.0); void setType(const Type _type = Horizontal); @@ -112,8 +113,8 @@ private: QString m_bar = QString("cpu"); int m_count = 100; bool m_custom = false; - QString m_activeColor; - QString m_inactiveColor; + QString m_activeColor = QString("color://0,0,0,130"); + QString m_inactiveColor = QString("color://255,255,255,130"); float m_minValue = 0.0f; float m_maxValue = 100.0f; Type m_type = Horizontal; diff --git a/sources/awesomewidgets/graphicalitem.ui b/sources/awesomewidgets/graphicalitem.ui index 212c0a4..45ad29d 100644 --- a/sources/awesomewidgets/graphicalitem.ui +++ b/sources/awesomewidgets/graphicalitem.ui @@ -7,7 +7,7 @@ 0 0 416 - 537 + 540 @@ -100,16 +100,7 @@ - - 0 - - - 0 - - - 0 - - + 0 @@ -135,16 +126,7 @@ - - 0 - - - 0 - - - 0 - - + 0 @@ -219,134 +201,74 @@ - + - - - Qt::Horizontal + + + Active image type - - - 40 - 20 - + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + - - - - 0 - 0 - + + + + + + + + + + true + + + + - Use image for active + ... - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Active color - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - - - - + - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - + - Use image for inactive + Inactive image type + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Inactive color - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - + + + + + true + + + + + + + ... + + + + @@ -417,16 +339,7 @@ - - 0 - - - 0 - - - 0 - - + 0 diff --git a/sources/awesomewidgets/graphicalitemhelper.cpp b/sources/awesomewidgets/graphicalitemhelper.cpp index 6442f23..c781ba4 100644 --- a/sources/awesomewidgets/graphicalitemhelper.cpp +++ b/sources/awesomewidgets/graphicalitemhelper.cpp @@ -50,7 +50,9 @@ void GraphicalItemHelper::setParameters(const QString active, // put images to pens if any otherwise set pen colors // Images resize to content here as well - if (active.startsWith(QString("/"))) { + if (isColor(active)) { + m_activePen.setColor(stringToColor(active)); + } else { qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << active; QPixmap pixmap = QPixmap(active); if (pixmap.isNull()) { @@ -59,10 +61,10 @@ void GraphicalItemHelper::setParameters(const QString active, } else { m_activePen.setBrush(QBrush(pixmap.scaled(width, height))); } - } else { - m_activePen.setColor(stringToColor(active)); } - if (inactive.startsWith(QString("/"))) { + if (isColor(inactive)) { + m_inactivePen.setColor(stringToColor(inactive)); + } else { qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << inactive; QPixmap pixmap = QPixmap(inactive); if (pixmap.isNull()) { @@ -71,8 +73,6 @@ void GraphicalItemHelper::setParameters(const QString active, } else { m_inactivePen.setBrush(QBrush(pixmap.scaled(width, height))); } - } else { - m_inactivePen.setColor(stringToColor(inactive)); } m_width = width; m_height = height; @@ -171,14 +171,25 @@ float GraphicalItemHelper::getPercents(const float &value, const float &min, } +bool GraphicalItemHelper::isColor(const QString &input) +{ + qCDebug(LOG_LIB) << "Define input type in" << input; + + return input.startsWith(QString("color://")); +} + + QColor GraphicalItemHelper::stringToColor(const QString &color) { qCDebug(LOG_LIB) << "Color" << color; - QColor qColor; QStringList listColor = color.split(QChar(',')); while (listColor.count() < 4) listColor.append(QString("0")); + // remove prefix + listColor[0].remove(QString("color://")); + // init color + QColor qColor; qColor.setRed(listColor.at(0).toInt()); qColor.setGreen(listColor.at(1).toInt()); qColor.setBlue(listColor.at(2).toInt()); diff --git a/sources/awesomewidgets/graphicalitemhelper.h b/sources/awesomewidgets/graphicalitemhelper.h index 96ac999..f4cd6e1 100644 --- a/sources/awesomewidgets/graphicalitemhelper.h +++ b/sources/awesomewidgets/graphicalitemhelper.h @@ -41,6 +41,7 @@ public: void paintVertical(const float &percent); // additional conversion methods float getPercents(const float &value, const float &min, const float &max); + bool isColor(const QString &input); QColor stringToColor(const QString &color); private: diff --git a/sources/version.h.in b/sources/version.h.in index aa4f886..b3f6ab9 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -24,7 +24,7 @@ // configuraion // graphical items api version -#define AWGIAPI 4 +#define AWGIAPI 5 // extquotes api version #define AWEQAPI 3 // extscript api version