mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
Start work on adding ability to use custom image for bars instead of
color
This commit is contained in:
parent
3a6033e676
commit
fe7f82373b
@ -23,6 +23,7 @@
|
||||
#include <QBuffer>
|
||||
#include <QColorDialog>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QSettings>
|
||||
@ -47,12 +48,20 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
|
||||
|
||||
connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this,
|
||||
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,
|
||||
SLOT(changeCountState(int)));
|
||||
connect(ui->pushButton_activeColor, SIGNAL(clicked()), this,
|
||||
SLOT(changeColor()));
|
||||
connect(ui->pushButton_inactiveColor, SIGNAL(clicked()), this,
|
||||
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()),
|
||||
_fileName, directories());
|
||||
copyDefaults(item);
|
||||
item->setActiveColor(activeColor());
|
||||
item->setActiveColor(m_activeColor);
|
||||
item->setBar(m_bar);
|
||||
item->setCount(m_count);
|
||||
item->setCustom(m_custom);
|
||||
item->setDirection(m_direction);
|
||||
item->setHeight(m_height);
|
||||
item->setInactiveColor(inactiveColor());
|
||||
item->setInactiveColor(m_inactiveColor);
|
||||
item->setMaxValue(m_maxValue);
|
||||
item->setMinValue(m_minValue);
|
||||
item->setNumber(_number);
|
||||
@ -144,13 +153,13 @@ QString GraphicalItem::bar() const
|
||||
|
||||
QString GraphicalItem::activeColor() const
|
||||
{
|
||||
return m_helper->colorToString(m_activeColor);
|
||||
return m_activeColor;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
m_activeColor = m_helper->stringToColor(_color);
|
||||
m_activeColor = _color;
|
||||
}
|
||||
|
||||
|
||||
@ -292,7 +301,7 @@ void GraphicalItem::setInactiveColor(const QString _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());
|
||||
setMinValue(settings.value(QString("X-AW-Min"), m_minValue).toFloat());
|
||||
setActiveColor(
|
||||
settings.value(QString("X-AW-ActiveColor"), activeColor())
|
||||
settings.value(QString("X-AW-ActiveColor"), m_activeColor)
|
||||
.toString());
|
||||
setInactiveColor(
|
||||
settings.value(QString("X-AW-InactiveColor"), inactiveColor())
|
||||
settings.value(QString("X-AW-InactiveColor"), m_inactiveColor)
|
||||
.toString());
|
||||
setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
|
||||
setStrDirection(
|
||||
@ -430,13 +439,6 @@ void GraphicalItem::readConfiguration()
|
||||
}
|
||||
|
||||
|
||||
QVariantHash GraphicalItem::run()
|
||||
{
|
||||
// required by abstract class
|
||||
return QVariantHash();
|
||||
}
|
||||
|
||||
|
||||
int GraphicalItem::showConfiguration(const QVariant 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_min->setValue(m_minValue);
|
||||
ui->spinBox_count->setValue(m_count);
|
||||
ui->pushButton_activeColor->setText(activeColor());
|
||||
ui->pushButton_inactiveColor->setText(inactiveColor());
|
||||
ui->pushButton_activeColor->setText(m_activeColor);
|
||||
ui->pushButton_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);
|
||||
@ -505,8 +507,8 @@ void GraphicalItem::writeConfiguration() const
|
||||
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"), activeColor());
|
||||
settings.setValue(QString("X-AW-InactiveColor"), inactiveColor());
|
||||
settings.setValue(QString("X-AW-ActiveColor"), m_activeColor);
|
||||
settings.setValue(QString("X-AW-InactiveColor"), m_inactiveColor);
|
||||
settings.setValue(QString("X-AW-Type"), strType());
|
||||
settings.setValue(QString("X-AW-Direction"), strDirection());
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Current state is" << state;
|
||||
@ -560,10 +592,7 @@ void GraphicalItem::initScene()
|
||||
{
|
||||
// init scene
|
||||
m_scene = new QGraphicsScene();
|
||||
if (m_type == Graph)
|
||||
m_scene->setBackgroundBrush(m_inactiveColor);
|
||||
else
|
||||
m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||
m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||
// init view
|
||||
m_view = new QGraphicsView(m_scene);
|
||||
m_view->setStyleSheet(QString("background: transparent"));
|
||||
@ -590,8 +619,12 @@ 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->label_activeImage->setText(i18n("Active image"));
|
||||
ui->checkBox_inactiveCheck->setText(i18n("Use image for inactive"));
|
||||
ui->label_inactiveColor->setText(i18n("Inactive color"));
|
||||
ui->label_inactiveImage->setText(i18n("Inactive image"));
|
||||
ui->label_type->setText(i18n("Type"));
|
||||
ui->label_direction->setText(i18n("Direction"));
|
||||
ui->label_height->setText(i18n("Height"));
|
||||
|
@ -92,13 +92,15 @@ public:
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
QVariantHash run();
|
||||
QVariantHash run() { return QVariantHash(); };
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
void writeConfiguration() const;
|
||||
|
||||
private slots:
|
||||
void changeColor();
|
||||
void changeColorState(const int state);
|
||||
void changeCountState(const int state);
|
||||
void changeImage();
|
||||
void changeValue(const int state);
|
||||
|
||||
private:
|
||||
@ -112,8 +114,8 @@ private:
|
||||
QString m_bar = QString("cpu");
|
||||
int m_count = 100;
|
||||
bool m_custom = false;
|
||||
QColor m_activeColor = QColor(0, 0, 0, 130);
|
||||
QColor m_inactiveColor = QColor(255, 255, 255, 130);
|
||||
QString m_activeColor;
|
||||
QString m_inactiveColor;
|
||||
float m_minValue = 0.0f;
|
||||
float m_maxValue = 100.0f;
|
||||
Type m_type = Horizontal;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>416</width>
|
||||
<height>481</height>
|
||||
<height>606</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -25,7 +25,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
<string>&Name</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@ -48,7 +48,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Comment</string>
|
||||
<string>&Comment</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@ -100,10 +100,22 @@
|
||||
<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">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_value">
|
||||
<property name="text">
|
||||
<string>Value</string>
|
||||
<string>&Value</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@ -123,6 +135,18 @@
|
||||
<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">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_customValue">
|
||||
<property name="sizePolicy">
|
||||
@ -132,7 +156,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Value</string>
|
||||
<string>Va&lue</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@ -150,7 +174,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_max">
|
||||
<property name="text">
|
||||
<string>Max value</string>
|
||||
<string>&Max value</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@ -171,7 +195,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_min">
|
||||
<property name="text">
|
||||
<string>Min value</string>
|
||||
<string>Min val&ue</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@ -190,10 +214,22 @@
|
||||
<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">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_count">
|
||||
<property name="text">
|
||||
<string>Points count</string>
|
||||
<string>&Points count</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@ -221,53 +257,211 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_activeColor">
|
||||
<layout class="QHBoxLayout" name="layout_activeCheck">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_activeColor">
|
||||
<property name="text">
|
||||
<string>Active color</string>
|
||||
<spacer name="spacer_activeCheck">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</spacer>
|
||||
</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">
|
||||
<string notr="true"/>
|
||||
<string>Use image for active</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</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&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>&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>
|
||||
<widget class="QLabel" name="label_inactiveColor">
|
||||
<property name="text">
|
||||
<string>Inactive color</string>
|
||||
<spacer name="spacer_inactiveCheck">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</spacer>
|
||||
</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">
|
||||
<string notr="true"/>
|
||||
<string>Use image for inactive</string>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</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>
|
||||
<layout class="QHBoxLayout" name="layout_type">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_type">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
<string>&Type</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@ -305,7 +499,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_direction">
|
||||
<property name="text">
|
||||
<string>Direction</string>
|
||||
<string>&Direction</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@ -333,7 +527,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_height">
|
||||
<property name="text">
|
||||
<string>Height</string>
|
||||
<string>&Height</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@ -357,7 +551,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_width">
|
||||
<property name="text">
|
||||
<string>Width</string>
|
||||
<string>&Width</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
|
@ -40,16 +40,30 @@ GraphicalItemHelper::~GraphicalItemHelper()
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItemHelper::setParameters(const QColor active,
|
||||
const QColor inactive, const int width,
|
||||
void GraphicalItemHelper::setParameters(const QString active,
|
||||
const QString inactive, const int width,
|
||||
const int height, const int count)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Use active color" << active << ", inactive" << inactive
|
||||
<< ", width" << width << ", height" << height << ", count"
|
||||
<< count;
|
||||
|
||||
m_activeColor = active;
|
||||
m_inactiveColor = inactive;
|
||||
if (active.startsWith(QString("/"))) {
|
||||
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_height = height;
|
||||
m_count = count;
|
||||
@ -63,6 +77,8 @@ void GraphicalItemHelper::paintCircle(const float &percent)
|
||||
QPen pen;
|
||||
pen.setWidth(1);
|
||||
QGraphicsEllipseItem *circle;
|
||||
// 16 is because of qt. From Qt documentation:
|
||||
// Returns the start angle for an ellipse segment in 16ths of a degree
|
||||
|
||||
// inactive
|
||||
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,
|
||||
QBrush(m_activeColor, Qt::SolidPattern));
|
||||
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;
|
||||
|
||||
// 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);
|
||||
QPen pen;
|
||||
pen.setColor(m_activeColor);
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define GRAPHICALITEMHELPER_H
|
||||
|
||||
#include <QColor>
|
||||
#include <QPixmap>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
@ -31,7 +32,7 @@ public:
|
||||
QGraphicsScene *scene = nullptr);
|
||||
virtual ~GraphicalItemHelper();
|
||||
// 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);
|
||||
// paint methods
|
||||
void paintCircle(const float &percent);
|
||||
@ -47,8 +48,10 @@ private:
|
||||
void storeValue(const float &value);
|
||||
QGraphicsScene *m_scene = nullptr;
|
||||
int m_count = 100;
|
||||
QColor m_activeColor;
|
||||
QColor m_inactiveColor;
|
||||
QColor m_activeColor = QColor(0, 0, 0, 130);
|
||||
QColor m_inactiveColor = QColor(255, 255, 255, 130);
|
||||
QPixmap m_activeImage;
|
||||
QPixmap m_inactiveImage;
|
||||
int m_width = 100;
|
||||
int m_height = 100;
|
||||
// list of values which will be used to store data for graph type only
|
||||
|
Loading…
Reference in New Issue
Block a user