diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index da393d2..73c771b 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -116,6 +116,11 @@ QString GraphicalItem::image(const QVariant &value) m_helper->paintGraph(converted); // direction option is not recognized by this GI type break; + case Bars: + m_helper->paintBars(converted); + // direction option is not recognized by this GI type + scale[1] = -1; + break; case Horizontal: default: m_helper->paintHorizontal(converted); @@ -198,6 +203,9 @@ QString GraphicalItem::strType() const case Graph: value = QString("Graph"); break; + case Bars: + value = QString("Bars"); + break; case Horizontal: default: value = QString("Horizontal"); @@ -331,6 +339,8 @@ void GraphicalItem::setStrType(const QString _type) setType(Circle); else if (_type == QString("Graph")) setType(Graph); + else if (_type == QString("Bars")) + setType(Bars); else setType(Horizontal); } diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index 9ccd67f..50f4ed5 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -50,7 +50,7 @@ class GraphicalItem : public AbstractExtItem public: enum Direction { LeftToRight = 0, RightToLeft }; - enum Type { Horizontal = 0, Vertical, Circle, Graph }; + enum Type { Horizontal = 0, Vertical, Circle, Graph, Bars }; explicit GraphicalItem(QWidget *parent = nullptr, const QString desktopName = QString(), diff --git a/sources/awesomewidgets/graphicalitem.ui b/sources/awesomewidgets/graphicalitem.ui index a97f8d3..3d80311 100644 --- a/sources/awesomewidgets/graphicalitem.ui +++ b/sources/awesomewidgets/graphicalitem.ui @@ -325,6 +325,11 @@ Graph + + + Bars + + diff --git a/sources/awesomewidgets/graphicalitemhelper.cpp b/sources/awesomewidgets/graphicalitemhelper.cpp index c781ba4..bf274bd 100644 --- a/sources/awesomewidgets/graphicalitemhelper.cpp +++ b/sources/awesomewidgets/graphicalitemhelper.cpp @@ -51,25 +51,25 @@ void GraphicalItemHelper::setParameters(const QString active, // put images to pens if any otherwise set pen colors // Images resize to content here as well if (isColor(active)) { - m_activePen.setColor(stringToColor(active)); + m_activePen.setBrush(QBrush(stringToColor(active))); } else { qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << active; QPixmap pixmap = QPixmap(active); if (pixmap.isNull()) { qCInfo(LOG_LIB) << "Invalid pixmap found" << active; - m_activePen.setColor(QColor(0, 0, 0, 130)); + m_activePen.setBrush(QBrush(QColor(0, 0, 0, 130))); } else { m_activePen.setBrush(QBrush(pixmap.scaled(width, height))); } } if (isColor(inactive)) { - m_inactivePen.setColor(stringToColor(inactive)); + m_inactivePen.setBrush(QBrush(stringToColor(inactive))); } else { qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << inactive; QPixmap pixmap = QPixmap(inactive); if (pixmap.isNull()) { qCInfo(LOG_LIB) << "Invalid pixmap found" << inactive; - m_inactivePen.setColor(QColor(255, 255, 255, 130)); + m_inactivePen.setBrush(QBrush(QColor(255, 255, 255, 130))); } else { m_inactivePen.setBrush(QBrush(pixmap.scaled(width, height))); } @@ -80,6 +80,30 @@ void GraphicalItemHelper::setParameters(const QString active, } +void GraphicalItemHelper::paintBars(const float &value) +{ + qCDebug(LOG_LIB) << "Paint with value" << value; + + // refresh background image + m_scene->setBackgroundBrush(m_inactivePen.brush()); + + storeValue(value); + + // default norms + float normX + = static_cast(m_width) / static_cast(m_values.count()); + float normY = static_cast(m_height - 1); + // paint graph + for (int i = 0; i < m_values.count(); i++) { + float x = i * normX; + float y = 0.5f; + float width = normX; + float height = m_values.at(i) * normY + 0.5f; + m_scene->addRect(x, y, width, height, m_activePen, m_activePen.brush()); + } +} + + void GraphicalItemHelper::paintCircle(const float &percent) { qCDebug(LOG_LIB) << "Paint with percent" << percent; @@ -120,9 +144,9 @@ void GraphicalItemHelper::paintGraph(const float &value) for (int i = 0; i < m_values.count() - 1; i++) { // some magic here float x1 = i * normX; - float y1 = -fabs(m_values.at(i)) * normY + 0.5f; + float y1 = -m_values.at(i) * normY + 0.5f; float x2 = (i + 1) * normX; - float y2 = -fabs(m_values.at(i + 1)) * normY + 0.5f; + float y2 = -m_values.at(i + 1) * normY + 0.5f; m_scene->addLine(x1, y1, x2, y2, m_activePen); } } diff --git a/sources/awesomewidgets/graphicalitemhelper.h b/sources/awesomewidgets/graphicalitemhelper.h index f4cd6e1..ee83e7e 100644 --- a/sources/awesomewidgets/graphicalitemhelper.h +++ b/sources/awesomewidgets/graphicalitemhelper.h @@ -35,6 +35,7 @@ public: void setParameters(const QString active, const QString inactive, const int width, const int height, const int count); // paint methods + void paintBars(const float &value); void paintCircle(const float &percent); void paintGraph(const float &value); void paintHorizontal(const float &percent);