Start work on adding ability to use custom image for bars instead of

color
This commit is contained in:
Evgenii Alekseev 2016-03-19 17:50:51 +03:00
parent 3a6033e676
commit fe7f82373b
5 changed files with 319 additions and 64 deletions

View File

@ -23,6 +23,7 @@
#include <QBuffer> #include <QBuffer>
#include <QColorDialog> #include <QColorDialog>
#include <QDir> #include <QDir>
#include <QFileDialog>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGraphicsView> #include <QGraphicsView>
#include <QSettings> #include <QSettings>
@ -47,12 +48,20 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this, connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this,
SLOT(changeValue(int))); SLOT(changeValue(int)));
connect(ui->checkBox_activeCheck, SIGNAL(stateChanged(int)), this,
SLOT(changeColorState(int)));
connect(ui->checkBox_inactiveCheck, SIGNAL(stateChanged(int)), this,
SLOT(changeColorState(int)));
connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this, connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this,
SLOT(changeCountState(int))); SLOT(changeCountState(int)));
connect(ui->pushButton_activeColor, SIGNAL(clicked()), this, connect(ui->pushButton_activeColor, SIGNAL(clicked()), this,
SLOT(changeColor())); SLOT(changeColor()));
connect(ui->pushButton_inactiveColor, SIGNAL(clicked()), this, connect(ui->pushButton_inactiveColor, SIGNAL(clicked()), this,
SLOT(changeColor())); SLOT(changeColor()));
connect(ui->pushButton_activeImage, SIGNAL(clicked()), this,
SLOT(changeImage()));
connect(ui->pushButton_inactiveImage, SIGNAL(clicked()), this,
SLOT(changeImage()));
} }
@ -73,13 +82,13 @@ GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()), GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()),
_fileName, directories()); _fileName, directories());
copyDefaults(item); copyDefaults(item);
item->setActiveColor(activeColor()); item->setActiveColor(m_activeColor);
item->setBar(m_bar); item->setBar(m_bar);
item->setCount(m_count); item->setCount(m_count);
item->setCustom(m_custom); item->setCustom(m_custom);
item->setDirection(m_direction); item->setDirection(m_direction);
item->setHeight(m_height); item->setHeight(m_height);
item->setInactiveColor(inactiveColor()); item->setInactiveColor(m_inactiveColor);
item->setMaxValue(m_maxValue); item->setMaxValue(m_maxValue);
item->setMinValue(m_minValue); item->setMinValue(m_minValue);
item->setNumber(_number); item->setNumber(_number);
@ -144,13 +153,13 @@ QString GraphicalItem::bar() const
QString GraphicalItem::activeColor() const QString GraphicalItem::activeColor() const
{ {
return m_helper->colorToString(m_activeColor); return m_activeColor;
} }
QString GraphicalItem::inactiveColor() const QString GraphicalItem::inactiveColor() const
{ {
return m_helper->colorToString(m_inactiveColor); return m_inactiveColor;
} }
@ -266,7 +275,7 @@ void GraphicalItem::setActiveColor(const QString _color)
{ {
qCDebug(LOG_LIB) << "Color" << _color; qCDebug(LOG_LIB) << "Color" << _color;
m_activeColor = m_helper->stringToColor(_color); m_activeColor = _color;
} }
@ -292,7 +301,7 @@ void GraphicalItem::setInactiveColor(const QString _color)
{ {
qCDebug(LOG_LIB) << "Color" << _color; qCDebug(LOG_LIB) << "Color" << _color;
m_inactiveColor = m_helper->stringToColor(_color); m_inactiveColor = _color;
} }
@ -403,10 +412,10 @@ void GraphicalItem::readConfiguration()
setMaxValue(settings.value(QString("X-AW-Max"), m_maxValue).toFloat()); setMaxValue(settings.value(QString("X-AW-Max"), m_maxValue).toFloat());
setMinValue(settings.value(QString("X-AW-Min"), m_minValue).toFloat()); setMinValue(settings.value(QString("X-AW-Min"), m_minValue).toFloat());
setActiveColor( setActiveColor(
settings.value(QString("X-AW-ActiveColor"), activeColor()) settings.value(QString("X-AW-ActiveColor"), m_activeColor)
.toString()); .toString());
setInactiveColor( setInactiveColor(
settings.value(QString("X-AW-InactiveColor"), inactiveColor()) settings.value(QString("X-AW-InactiveColor"), m_inactiveColor)
.toString()); .toString());
setStrType(settings.value(QString("X-AW-Type"), strType()).toString()); setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
setStrDirection( setStrDirection(
@ -430,13 +439,6 @@ void GraphicalItem::readConfiguration()
} }
QVariantHash GraphicalItem::run()
{
// required by abstract class
return QVariantHash();
}
int GraphicalItem::showConfiguration(const QVariant args) int GraphicalItem::showConfiguration(const QVariant args)
{ {
qCDebug(LOG_LIB) << "Combobox arguments" << args; qCDebug(LOG_LIB) << "Combobox arguments" << args;
@ -455,8 +457,8 @@ int GraphicalItem::showConfiguration(const QVariant args)
ui->doubleSpinBox_max->setValue(m_maxValue); ui->doubleSpinBox_max->setValue(m_maxValue);
ui->doubleSpinBox_min->setValue(m_minValue); ui->doubleSpinBox_min->setValue(m_minValue);
ui->spinBox_count->setValue(m_count); ui->spinBox_count->setValue(m_count);
ui->pushButton_activeColor->setText(activeColor()); ui->pushButton_activeColor->setText(m_activeColor);
ui->pushButton_inactiveColor->setText(inactiveColor()); ui->pushButton_inactiveColor->setText(m_inactiveColor);
ui->comboBox_type->setCurrentIndex(static_cast<int>(m_type)); ui->comboBox_type->setCurrentIndex(static_cast<int>(m_type));
ui->comboBox_direction->setCurrentIndex(static_cast<int>(m_direction)); ui->comboBox_direction->setCurrentIndex(static_cast<int>(m_direction));
ui->spinBox_height->setValue(m_height); ui->spinBox_height->setValue(m_height);
@ -505,8 +507,8 @@ void GraphicalItem::writeConfiguration() const
settings.setValue(QString("X-AW-Custom"), m_custom); settings.setValue(QString("X-AW-Custom"), m_custom);
settings.setValue(QString("X-AW-Max"), m_maxValue); settings.setValue(QString("X-AW-Max"), m_maxValue);
settings.setValue(QString("X-AW-Min"), m_minValue); settings.setValue(QString("X-AW-Min"), m_minValue);
settings.setValue(QString("X-AW-ActiveColor"), activeColor()); settings.setValue(QString("X-AW-ActiveColor"), m_activeColor);
settings.setValue(QString("X-AW-InactiveColor"), inactiveColor()); settings.setValue(QString("X-AW-InactiveColor"), m_inactiveColor);
settings.setValue(QString("X-AW-Type"), strType()); settings.setValue(QString("X-AW-Type"), strType());
settings.setValue(QString("X-AW-Direction"), strDirection()); settings.setValue(QString("X-AW-Direction"), strDirection());
settings.setValue(QString("X-AW-Height"), m_height); settings.setValue(QString("X-AW-Height"), m_height);
@ -538,6 +540,22 @@ void GraphicalItem::changeColor()
} }
void GraphicalItem::changeColorState(const int state)
{
qCDebug(LOG_LIB) << "Current color state is" << state;
if (sender() == ui->checkBox_activeCheck) {
qCInfo(LOG_LIB) << "Change active color state";
ui->widget_activeColor->setHidden(state == Qt::Unchecked);
ui->widget_activeImage->setHidden(state != Qt::Unchecked);
} else if (sender() == ui->checkBox_inactiveCheck) {
qCInfo(LOG_LIB) << "Change inactive color state";
ui->widget_inactiveColor->setHidden(state == Qt::Unchecked);
ui->widget_inactiveImage->setHidden(state != Qt::Unchecked);
}
}
void GraphicalItem::changeCountState(const int state) void GraphicalItem::changeCountState(const int state)
{ {
qCDebug(LOG_LIB) << "Current state is" << state; qCDebug(LOG_LIB) << "Current state is" << state;
@ -547,6 +565,20 @@ void GraphicalItem::changeCountState(const int state)
} }
void GraphicalItem::changeImage()
{
QString path = static_cast<QPushButton *>(sender())->text();
QString directory = QFileInfo(path).absolutePath();
QString newPath = QFileDialog::getOpenFileName(
this, tr("Select path"), directory,
tr("Images (*.png *.bpm *.jpg);;All files (*.*)"));
qCInfo(LOG_LIB) << "Selected path" << newPath;
return static_cast<QPushButton *>(sender())->setText(newPath);
}
void GraphicalItem::changeValue(const int state) void GraphicalItem::changeValue(const int state)
{ {
qCDebug(LOG_LIB) << "Current state is" << state; qCDebug(LOG_LIB) << "Current state is" << state;
@ -560,10 +592,7 @@ void GraphicalItem::initScene()
{ {
// init scene // init scene
m_scene = new QGraphicsScene(); m_scene = new QGraphicsScene();
if (m_type == Graph) m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
m_scene->setBackgroundBrush(m_inactiveColor);
else
m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
// init view // init view
m_view = new QGraphicsView(m_scene); m_view = new QGraphicsView(m_scene);
m_view->setStyleSheet(QString("background: transparent")); m_view->setStyleSheet(QString("background: transparent"));
@ -590,8 +619,12 @@ void GraphicalItem::translate()
ui->label_customValue->setText(i18n("Value")); ui->label_customValue->setText(i18n("Value"));
ui->label_max->setText(i18n("Max value")); ui->label_max->setText(i18n("Max value"));
ui->label_min->setText(i18n("Min 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->label_activeColor->setText(i18n("Active color"));
ui->label_activeImage->setText(i18n("Active image"));
ui->checkBox_inactiveCheck->setText(i18n("Use image for inactive"));
ui->label_inactiveColor->setText(i18n("Inactive color")); ui->label_inactiveColor->setText(i18n("Inactive color"));
ui->label_inactiveImage->setText(i18n("Inactive image"));
ui->label_type->setText(i18n("Type")); ui->label_type->setText(i18n("Type"));
ui->label_direction->setText(i18n("Direction")); ui->label_direction->setText(i18n("Direction"));
ui->label_height->setText(i18n("Height")); ui->label_height->setText(i18n("Height"));

View File

@ -92,13 +92,15 @@ public:
public slots: public slots:
void readConfiguration(); void readConfiguration();
QVariantHash run(); QVariantHash run() { return QVariantHash(); };
int showConfiguration(const QVariant args = QVariant()); int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const; void writeConfiguration() const;
private slots: private slots:
void changeColor(); void changeColor();
void changeColorState(const int state);
void changeCountState(const int state); void changeCountState(const int state);
void changeImage();
void changeValue(const int state); void changeValue(const int state);
private: private:
@ -112,8 +114,8 @@ private:
QString m_bar = QString("cpu"); QString m_bar = QString("cpu");
int m_count = 100; int m_count = 100;
bool m_custom = false; bool m_custom = false;
QColor m_activeColor = QColor(0, 0, 0, 130); QString m_activeColor;
QColor m_inactiveColor = QColor(255, 255, 255, 130); QString m_inactiveColor;
float m_minValue = 0.0f; float m_minValue = 0.0f;
float m_maxValue = 100.0f; float m_maxValue = 100.0f;
Type m_type = Horizontal; Type m_type = Horizontal;

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>416</width> <width>416</width>
<height>481</height> <height>606</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -25,7 +25,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Name</string> <string>&amp;Name</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -48,7 +48,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Comment</string> <string>&amp;Comment</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -100,10 +100,22 @@
<item> <item>
<widget class="QWidget" name="widget_value" native="true"> <widget class="QWidget" name="widget_value" native="true">
<layout class="QHBoxLayout" name="layout_value"> <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">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="label_value"> <widget class="QLabel" name="label_value">
<property name="text"> <property name="text">
<string>Value</string> <string>&amp;Value</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -123,6 +135,18 @@
<item> <item>
<widget class="QWidget" name="widget_customValue" native="true"> <widget class="QWidget" name="widget_customValue" native="true">
<layout class="QHBoxLayout" name="layout_customValue"> <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">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="label_customValue"> <widget class="QLabel" name="label_customValue">
<property name="sizePolicy"> <property name="sizePolicy">
@ -132,7 +156,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Value</string> <string>Va&amp;lue</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -150,7 +174,7 @@
<item> <item>
<widget class="QLabel" name="label_max"> <widget class="QLabel" name="label_max">
<property name="text"> <property name="text">
<string>Max value</string> <string>&amp;Max value</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -171,7 +195,7 @@
<item> <item>
<widget class="QLabel" name="label_min"> <widget class="QLabel" name="label_min">
<property name="text"> <property name="text">
<string>Min value</string> <string>Min val&amp;ue</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -190,10 +214,22 @@
<item> <item>
<widget class="QWidget" name="widget_count" native="true"> <widget class="QWidget" name="widget_count" native="true">
<layout class="QHBoxLayout" name="layout_count"> <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">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="label_count"> <widget class="QLabel" name="label_count">
<property name="text"> <property name="text">
<string>Points count</string> <string>&amp;Points count</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -221,53 +257,211 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="layout_activeColor"> <layout class="QHBoxLayout" name="layout_activeCheck">
<item> <item>
<widget class="QLabel" name="label_activeColor"> <spacer name="spacer_activeCheck">
<property name="text"> <property name="orientation">
<string>Active color</string> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="alignment"> <property name="sizeHint" stdset="0">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <size>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</widget> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_activeColor"> <widget class="QCheckBox" name="checkBox_activeCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string notr="true"/> <string>Use image for active</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="layout_inactiveColor"> <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>Activ&amp;e 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>
<widget class="QWidget" name="widget_activeImage" native="true">
<layout class="QHBoxLayout" name="layout_activeImage">
<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_activeImage">
<property name="text">
<string>&amp;Active image</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_activeImage">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_inactiveCheck">
<item> <item>
<widget class="QLabel" name="label_inactiveColor"> <spacer name="spacer_inactiveCheck">
<property name="text"> <property name="orientation">
<string>Inactive color</string> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="alignment"> <property name="sizeHint" stdset="0">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <size>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</widget> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_inactiveColor"> <widget class="QCheckBox" name="checkBox_inactiveCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string notr="true"/> <string>Use image for inactive</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </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>&amp;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>
</item>
<item>
<widget class="QWidget" name="widget_inactiveImage" native="true">
<layout class="QHBoxLayout" name="layout_inactiveImage">
<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_inactiveImage">
<property name="text">
<string>Inactive image</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_inactiveImage">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="layout_type"> <layout class="QHBoxLayout" name="layout_type">
<item> <item>
<widget class="QLabel" name="label_type"> <widget class="QLabel" name="label_type">
<property name="text"> <property name="text">
<string>Type</string> <string>&amp;Type</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -305,7 +499,7 @@
<item> <item>
<widget class="QLabel" name="label_direction"> <widget class="QLabel" name="label_direction">
<property name="text"> <property name="text">
<string>Direction</string> <string>&amp;Direction</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -333,7 +527,7 @@
<item> <item>
<widget class="QLabel" name="label_height"> <widget class="QLabel" name="label_height">
<property name="text"> <property name="text">
<string>Height</string> <string>&amp;Height</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -357,7 +551,7 @@
<item> <item>
<widget class="QLabel" name="label_width"> <widget class="QLabel" name="label_width">
<property name="text"> <property name="text">
<string>Width</string> <string>&amp;Width</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>

View File

@ -40,16 +40,30 @@ GraphicalItemHelper::~GraphicalItemHelper()
} }
void GraphicalItemHelper::setParameters(const QColor active, void GraphicalItemHelper::setParameters(const QString active,
const QColor inactive, const int width, const QString inactive, const int width,
const int height, const int count) const int height, const int count)
{ {
qCDebug(LOG_LIB) << "Use active color" << active << ", inactive" << inactive qCDebug(LOG_LIB) << "Use active color" << active << ", inactive" << inactive
<< ", width" << width << ", height" << height << ", count" << ", width" << width << ", height" << height << ", count"
<< count; << count;
m_activeColor = active; if (active.startsWith(QString("/"))) {
m_inactiveColor = inactive; qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << active;
m_activeImage = QPixmap(active);
if (m_activeImage.isNull())
qCInfo(LOG_LIB) << "Invalid pixmap found" << active;
} else {
m_activeColor = stringToColor(active);
}
if (inactive.startsWith(QString("/"))) {
qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << inactive;
m_inactiveImage = QPixmap(inactive);
if (m_inactiveImage.isNull())
qCInfo(LOG_LIB) << "Invalid pixmap found" << inactive;
} else {
m_inactiveColor = stringToColor(inactive);
}
m_width = width; m_width = width;
m_height = height; m_height = height;
m_count = count; m_count = count;
@ -63,6 +77,8 @@ void GraphicalItemHelper::paintCircle(const float &percent)
QPen pen; QPen pen;
pen.setWidth(1); pen.setWidth(1);
QGraphicsEllipseItem *circle; QGraphicsEllipseItem *circle;
// 16 is because of qt. From Qt documentation:
// Returns the start angle for an ellipse segment in 16ths of a degree
// inactive // inactive
pen.setColor(m_inactiveColor); pen.setColor(m_inactiveColor);
@ -75,7 +91,7 @@ void GraphicalItemHelper::paintCircle(const float &percent)
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen, circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen,
QBrush(m_activeColor, Qt::SolidPattern)); QBrush(m_activeColor, Qt::SolidPattern));
circle->setSpanAngle(-percent * 360.0f * 16.0f); circle->setSpanAngle(-percent * 360.0f * 16.0f);
circle->setStartAngle(90.0f * 16.0f); circle->setStartAngle(90 * 16);
} }
@ -83,6 +99,13 @@ void GraphicalItemHelper::paintGraph(const float &value)
{ {
qCDebug(LOG_LIB) << "Paint with value" << value; qCDebug(LOG_LIB) << "Paint with value" << value;
// refresh background image
if (m_inactiveImage.isNull())
m_scene->setBackgroundBrush(QBrush(m_inactiveColor));
else
m_scene->setBackgroundBrush(
QBrush(m_inactiveImage.scaled(m_width, m_height)));
storeValue(value); storeValue(value);
QPen pen; QPen pen;
pen.setColor(m_activeColor); pen.setColor(m_activeColor);

View File

@ -19,6 +19,7 @@
#define GRAPHICALITEMHELPER_H #define GRAPHICALITEMHELPER_H
#include <QColor> #include <QColor>
#include <QPixmap>
#include <QObject> #include <QObject>
@ -31,7 +32,7 @@ public:
QGraphicsScene *scene = nullptr); QGraphicsScene *scene = nullptr);
virtual ~GraphicalItemHelper(); virtual ~GraphicalItemHelper();
// parameters // parameters
void setParameters(const QColor active, const QColor inactive, void setParameters(const QString active, const QString inactive,
const int width, const int height, const int count); const int width, const int height, const int count);
// paint methods // paint methods
void paintCircle(const float &percent); void paintCircle(const float &percent);
@ -47,8 +48,10 @@ private:
void storeValue(const float &value); void storeValue(const float &value);
QGraphicsScene *m_scene = nullptr; QGraphicsScene *m_scene = nullptr;
int m_count = 100; int m_count = 100;
QColor m_activeColor; QColor m_activeColor = QColor(0, 0, 0, 130);
QColor m_inactiveColor; QColor m_inactiveColor = QColor(255, 255, 255, 130);
QPixmap m_activeImage;
QPixmap m_inactiveImage;
int m_width = 100; int m_width = 100;
int m_height = 100; int m_height = 100;
// list of values which will be used to store data for graph type only // list of values which will be used to store data for graph type only