diff --git a/sources/awesome-widget/plugin/awdataaggregator.cpp b/sources/awesome-widget/plugin/awdataaggregator.cpp index ed565b5..7c890f7 100644 --- a/sources/awesome-widget/plugin/awdataaggregator.cpp +++ b/sources/awesome-widget/plugin/awdataaggregator.cpp @@ -264,7 +264,7 @@ void AWDataAggregator::setData(const QVariantHash &values) // usual case setData(QString("cpuTooltip"), values[QString("cpu")].toFloat(), 90.0); setData(QString("cpuclTooltip"), values[QString("cpucl")].toFloat()); - setData(QString("memTooltip"), values[QString("mem")].toFloat(), 90.0); + setData(QString("memTooltip"), values[QString("mem")].toFloat(), 80.0); setData(QString("swapTooltip"), values[QString("swap")].toFloat(), 0.0); setData(QString("downkbTooltip"), values[QString("downkb")].toFloat()); setData(QString("upkbTooltip"), values[QString("upkb")].toFloat()); diff --git a/sources/awesome-widget/plugin/awdataaggregator.h b/sources/awesome-widget/plugin/awdataaggregator.h index ef70d01..a5da613 100644 --- a/sources/awesome-widget/plugin/awdataaggregator.h +++ b/sources/awesome-widget/plugin/awdataaggregator.h @@ -44,7 +44,7 @@ signals: void updateData(const QVariantHash &values); void toolTipPainted(const QString image) const; -public slots: +private slots: void dataUpdate(const QVariantHash &values); private: diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index 1d2d5b4..b4908f4 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -60,6 +60,7 @@ GraphicalItem::~GraphicalItem() delete m_scene; delete ui; + delete m_helper; } @@ -89,6 +90,7 @@ GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number) QString GraphicalItem::image(const QVariant &value) { qCDebug(LOG_LIB) << "Value" << value; + qDebug() << "Value" << value; m_scene->clear(); int scale[2] = {1, 1}; @@ -96,33 +98,25 @@ QString GraphicalItem::image(const QVariant &value) // paint switch (m_type) { case Vertical: - GraphicalItemHelper::paintVertical( - GraphicalItemHelper::getPercents(value.toFloat(), m_minValue, - m_maxValue), - m_inactiveColor, m_activeColor, m_width, m_height, m_scene); + m_helper->paintVertical( + m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue)); // scale scale[1] = -2 * static_cast(m_direction) + 1; break; case Circle: - GraphicalItemHelper::paintCircle( - GraphicalItemHelper::getPercents(value.toFloat(), m_minValue, - m_maxValue), - m_inactiveColor, m_activeColor, m_width, m_height, m_scene); + m_helper->paintCircle( + m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue)); // scale scale[0] = -2 * static_cast(m_direction) + 1; break; case Graph: - GraphicalItemHelper::paintGraph(value.value>(), - m_activeColor, m_width, m_height, - m_scene); + m_helper->paintGraph(value.value>()); // direction option is not recognized by this GI type break; case Horizontal: default: - GraphicalItemHelper::paintHorizontal( - GraphicalItemHelper::getPercents(value.toFloat(), m_minValue, - m_maxValue), - m_inactiveColor, m_activeColor, m_width, m_height, m_scene); + m_helper->paintHorizontal( + m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue)); // scale scale[0] = -2 * static_cast(m_direction) + 1; break; @@ -137,6 +131,7 @@ QString GraphicalItem::image(const QVariant &value) QString url = QString("") .arg(QString(byteArray.toBase64())); + qDebug() << url; return url; } @@ -149,13 +144,13 @@ QString GraphicalItem::bar() const QString GraphicalItem::activeColor() const { - return GraphicalItemHelper::colorToString(m_activeColor); + return m_helper->colorToString(m_activeColor); } QString GraphicalItem::inactiveColor() const { - return GraphicalItemHelper::colorToString(m_inactiveColor); + return m_helper->colorToString(m_inactiveColor); } @@ -265,7 +260,7 @@ void GraphicalItem::setActiveColor(const QString _color) { qCDebug(LOG_LIB) << "Color" << _color; - m_activeColor = GraphicalItemHelper::stringToColor(_color); + m_activeColor = m_helper->stringToColor(_color); } @@ -281,7 +276,7 @@ void GraphicalItem::setInactiveColor(const QString _color) { qCDebug(LOG_LIB) << "Color" << _color; - m_inactiveColor = GraphicalItemHelper::stringToColor(_color); + m_inactiveColor = m_helper->stringToColor(_color); } @@ -500,7 +495,7 @@ void GraphicalItem::writeConfiguration() const void GraphicalItem::changeColor() { - QColor color = GraphicalItemHelper::stringToColor( + QColor color = m_helper->stringToColor( (static_cast(sender()))->text()); QColor newColor = QColorDialog::getColor(color, this, tr("Select color"), QColorDialog::ShowAlphaChannel); @@ -544,6 +539,10 @@ void GraphicalItem::initScene() m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_view->resize(m_width + 5, m_height + 5); + + // init helper + m_helper = new GraphicalItemHelper(this, m_scene); + m_helper->setParameters(m_activeColor, m_inactiveColor, m_width, m_height); } diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index 91cb71b..c051279 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -23,6 +23,7 @@ #include "abstractextitem.h" +class GraphicalItemHelper; class QGraphicsScene; class QGraphicsView; @@ -97,6 +98,7 @@ private slots: void changeValue(const int state); private: + GraphicalItemHelper *m_helper = nullptr; QGraphicsScene *m_scene = nullptr; QGraphicsView *m_view = nullptr; Ui::GraphicalItem *ui; diff --git a/sources/awesomewidgets/graphicalitemhelper.cpp b/sources/awesomewidgets/graphicalitemhelper.cpp index 9fcd788..06069c5 100644 --- a/sources/awesomewidgets/graphicalitemhelper.cpp +++ b/sources/awesomewidgets/graphicalitemhelper.cpp @@ -17,6 +17,7 @@ #include "graphicalitemhelper.h" +#include #include #include @@ -25,40 +26,68 @@ #include "awdebug.h" -void GraphicalItemHelper::paintCircle(const float &percent, - const QColor &inactive, - const QColor &active, const int &width, - const int &height, QGraphicsScene *scene) +GraphicalItemHelper::GraphicalItemHelper(QObject *parent, QGraphicsScene *scene) + : QObject(parent) + , m_scene(scene) { + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; +} + + +GraphicalItemHelper::~GraphicalItemHelper() +{ + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; +} + + +void GraphicalItemHelper::setParameters(const QColor active, + const QColor inactive, const int width, + const int height) +{ + qCDebug(LOG_LIB) << "Use active color" << active << ", inactive" << inactive + << ", width" << width << ", height" << height; + + m_activeColor = active; + m_inactiveColor = inactive; + m_width = width; + m_height = height; +} + + +void GraphicalItemHelper::paintCircle(const float &percent) +{ + qCDebug(LOG_LIB) << "Paint with percent" << percent; + QPen pen; pen.setWidth(1); QGraphicsEllipseItem *circle; // inactive - pen.setColor(inactive); - circle = scene->addEllipse(0.0, 0.0, width, height, pen, - QBrush(inactive, Qt::SolidPattern)); + pen.setColor(m_inactiveColor); + circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen, + QBrush(m_inactiveColor, Qt::SolidPattern)); 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 = scene->addEllipse(0.0, 0.0, width, height, pen, - QBrush(active, Qt::SolidPattern)); + pen.setColor(m_activeColor); + 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); } -void GraphicalItemHelper::paintGraph(const QList &value, - const QColor &active, const int &width, - const int &height, QGraphicsScene *scene) +void GraphicalItemHelper::paintGraph(const QList &value) { + qCDebug(LOG_LIB) << "Paint with value" << value; + QPen pen; - pen.setColor(active); + pen.setColor(m_activeColor); // default norms - float normX = static_cast(width) / static_cast(value.count()); - float normY = static_cast(height) / (1.5f * 100.0f); + float normX + = static_cast(m_width) / static_cast(value.count()); + float normY = static_cast(m_height) / (1.5f * 100.0f); // paint graph for (int i = 0; i < value.count() - 1; i++) { // some magic here @@ -66,46 +95,42 @@ void GraphicalItemHelper::paintGraph(const QList &value, float y1 = -fabs(value.at(i)) * normY + 5.0f; float x2 = (i + 1) * normX; float y2 = -fabs(value.at(i + 1)) * normY + 5.0f; - scene->addLine(x1, y1, x2, y2, pen); + m_scene->addLine(x1, y1, x2, y2, pen); } } -void GraphicalItemHelper::paintHorizontal(const float &percent, - const QColor &inactive, - const QColor &active, - const int &width, const int &height, - QGraphicsScene *scene) +void GraphicalItemHelper::paintHorizontal(const float &percent) { + qCDebug(LOG_LIB) << "Paint with percent" << percent; + QPen pen; - pen.setWidth(height); + pen.setWidth(m_height); // inactive - pen.setColor(inactive); - scene->addLine(percent * width + 0.5 * height, 0.5 * height, - width + 0.5 * height, 0.5 * height, pen); + pen.setColor(m_inactiveColor); + m_scene->addLine(percent * m_width + 0.5 * m_height, 0.5 * m_height, + m_width + 0.5 * m_height, 0.5 * m_height, pen); // active - pen.setColor(active); - scene->addLine(-0.5 * height, 0.5 * height, percent * width - 0.5 * height, - 0.5 * height, pen); + pen.setColor(m_activeColor); + m_scene->addLine(-0.5 * m_height, 0.5 * m_height, + percent * m_width - 0.5 * m_height, 0.5 * m_height, pen); } -void GraphicalItemHelper::paintVertical(const float &percent, - const QColor &inactive, - const QColor &active, const int &width, - const int &height, - QGraphicsScene *scene) +void GraphicalItemHelper::paintVertical(const float &percent) { + qCDebug(LOG_LIB) << "Paint with percent" << percent; + QPen pen; - pen.setWidth(width); + pen.setWidth(m_width); // inactive - pen.setColor(inactive); - scene->addLine(0.5 * width, -0.5 * width, 0.5 * width, - (1.0 - percent) * height - 0.5 * width, pen); + pen.setColor(m_inactiveColor); + m_scene->addLine(0.5 * m_width, -0.5 * m_width, 0.5 * m_width, + (1.0 - percent) * m_height - 0.5 * m_width, pen); // active - pen.setColor(active); - scene->addLine(0.5 * width, (1.0 - percent) * height + 0.5 * width, - 0.5 * width, height + 0.5 * width, pen); + pen.setColor(m_activeColor); + m_scene->addLine(0.5 * m_width, (1.0 - percent) * m_height + 0.5 * m_width, + 0.5 * m_width, m_height + 0.5 * m_width, pen); } diff --git a/sources/awesomewidgets/graphicalitemhelper.h b/sources/awesomewidgets/graphicalitemhelper.h index f76c41f..5b326fd 100644 --- a/sources/awesomewidgets/graphicalitemhelper.h +++ b/sources/awesomewidgets/graphicalitemhelper.h @@ -19,28 +19,36 @@ #define GRAPHICALITEMHELPER_H #include +#include class QGraphicsScene; -namespace GraphicalItemHelper +class GraphicalItemHelper : public QObject { -// paint methods -void paintCircle(const float &percent, const QColor &inactive, - const QColor &active, const int &width, const int &height, - QGraphicsScene *scene); -void paintGraph(const QList &value, const QColor &active, - const int &width, const int &height, QGraphicsScene *scene); -void paintHorizontal(const float &percent, const QColor &inactive, - const QColor &active, const int &width, const int &height, - QGraphicsScene *scene); -void paintVertical(const float &percent, const QColor &inactive, - const QColor &active, const int &width, const int &height, - QGraphicsScene *scene); -// additional conversion methods -QString colorToString(const QColor &color); -float getPercents(const float &value, const float &min, const float &max); -QColor stringToColor(const QString &color); +public: + explicit GraphicalItemHelper(QObject *parent = nullptr, + QGraphicsScene *scene = nullptr); + virtual ~GraphicalItemHelper(); + // parameters + void setParameters(const QColor active, const QColor inactive, + const int width, const int height); + // paint methods + void paintCircle(const float &percent); + void paintGraph(const QList &value); + void paintHorizontal(const float &percent); + void paintVertical(const float &percent); + // additional conversion methods + QString colorToString(const QColor &color); + float getPercents(const float &value, const float &min, const float &max); + QColor stringToColor(const QString &color); + +private: + QGraphicsScene *m_scene = nullptr; + QColor m_activeColor; + QColor m_inactiveColor; + int m_width; + int m_height; };