mirror of
				https://github.com/arcan1s/awesome-widgets.git
				synced 2025-11-03 22:33:42 +00:00 
			
		
		
		
	add bars support to gi
same as graphs but also provides solid background under lines
This commit is contained in:
		@ -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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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(),
 | 
			
		||||
 | 
			
		||||
@ -325,6 +325,11 @@
 | 
			
		||||
         <string notr="true">Graph</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </item>
 | 
			
		||||
       <item>
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string notr="true">Bars</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </item>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
 | 
			
		||||
@ -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<float>(m_width) / static_cast<float>(m_values.count());
 | 
			
		||||
    float normY = static_cast<float>(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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user