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)
This commit is contained in:
Evgenii Alekseev 2016-04-12 14:22:19 +03:00
parent 354fd3cd0c
commit a3e7a84b92
11 changed files with 157 additions and 198 deletions

View File

@ -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";
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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<int>(m_type));
ui->comboBox_direction->setCurrentIndex(static_cast<int>(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<QPushButton *>(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<QPushButton *>(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<QPushButton *>(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"));
}

View File

@ -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;

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>416</width>
<height>537</height>
<height>540</height>
</rect>
</property>
<property name="windowTitle">
@ -100,16 +100,7 @@
<item>
<widget class="QWidget" name="widget_value" native="true">
<layout class="QHBoxLayout" name="layout_value">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
@ -135,16 +126,7 @@
<item>
<widget class="QWidget" name="widget_customValue" native="true">
<layout class="QHBoxLayout" name="layout_customValue">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
@ -219,134 +201,74 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_activeCheck">
<layout class="QHBoxLayout" name="layout_activeImageType">
<item>
<spacer name="spacer_activeCheck">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QLabel" name="label_activeImageType">
<property name="text">
<string>Active image type</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</spacer>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_activeCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QComboBox" name="comboBox_activeImageType"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_activeColorButton">
<item>
<widget class="QLineEdit" name="lineEdit_activeColor">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_activeColor">
<property name="text">
<string>Use image for active</string>
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget_activeColor" native="true">
<layout class="QHBoxLayout" name="layout_activeColor">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_activeColor">
<property name="text">
<string>Active color</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_activeColor">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_inactiveCheck">
<layout class="QHBoxLayout" name="layout_inactiveImageType">
<item>
<spacer name="spacer_inactiveCheck">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_inactiveCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QLabel" name="label_inactiveImageType">
<property name="text">
<string>Use image for inactive</string>
<string>Inactive image type</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_inactiveImageType"/>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget_inactiveColor" native="true">
<layout class="QHBoxLayout" name="layout_inactiveColor">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_inactiveColor">
<property name="text">
<string>Inactive color</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_inactiveColor">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</widget>
<layout class="QHBoxLayout" name="layout_inactiveColorButton">
<item>
<widget class="QLineEdit" name="lineEdit_inactiveColor">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_inactiveColor">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_type">
@ -417,16 +339,7 @@
<item>
<widget class="QWidget" name="widget_count" native="true">
<layout class="QHBoxLayout" name="layout_count">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>

View File

@ -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());

View File

@ -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:

View File

@ -24,7 +24,7 @@
// configuraion
// graphical items api version
#define AWGIAPI 4
#define AWGIAPI 5
// extquotes api version
#define AWEQAPI 3
// extscript api version