summaryrefslogtreecommitdiff
path: root/src/study/CardsStatusBar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/study/CardsStatusBar.cpp')
-rw-r--r--src/study/CardsStatusBar.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/study/CardsStatusBar.cpp b/src/study/CardsStatusBar.cpp
new file mode 100644
index 0000000..e29f9f8
--- /dev/null
+++ b/src/study/CardsStatusBar.cpp
@@ -0,0 +1,82 @@
+#include "CardsStatusBar.h"
+
+const QStringList CardsStatusBar::Colors = {"green", "#fffd7c", "white", "#bd8d71"};
+
+CardsStatusBar::CardsStatusBar(QWidget* aParent) :
+ QWidget(aParent)
+{
+ setMinimumHeight(10);
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+}
+
+CardsStatusBar::~CardsStatusBar()
+{
+ delete painter;
+}
+
+void CardsStatusBar::paintEvent(QPaintEvent* aEvent)
+{
+ QWidget::paintEvent( aEvent );
+ if(values.isEmpty())
+ return;
+ max = getMax();
+
+ painter = new QPainter(this);
+ painter->setRenderHint(QPainter::Antialiasing);
+ painter->save();
+
+ QPainterPath path;
+ path.addRoundedRect( rect(), Radius, Radius);
+ painter->setClipPath( path );
+
+ barRect = rect().adjusted(0, 0, 1, 0);
+
+ sectionLeft = rect().left();
+ for(int i = 0; i < values.size(); i++)
+ drawSection(i);
+
+ painter->restore();
+
+ painter->setPen(QPen("#7c7c7c"));
+ painter->drawRoundedRect(rect(), Radius, Radius);
+}
+
+int CardsStatusBar::getMax() const
+{
+ int max = 0;
+ foreach(int v, values)
+ max += v;
+ if(max == 0)
+ max = 1;
+ return max;
+}
+
+void CardsStatusBar::drawSection(int index)
+{
+ QRectF sectionRect = getSectionRect(index);
+ painter->setPen( Qt::NoPen );
+ painter->setBrush(getSectionGradient(index));
+ painter->drawRect(sectionRect);
+
+ painter->setPen(QPen(QBrush("#a7a7a7"), 0.5));
+ painter->drawLine(sectionRect.topRight(), sectionRect.bottomRight());
+
+ sectionLeft += sectionRect.width();
+}
+
+QLinearGradient CardsStatusBar::getSectionGradient(int index)
+{
+ QLinearGradient grad(barRect.topLeft(), barRect.bottomLeft());
+ grad.setColorAt( 0, Qt::white);
+ grad.setColorAt( 0.9, QColor(Colors[index]) );
+ return grad;
+}
+
+QRectF CardsStatusBar::getSectionRect(int index)
+{
+ QRectF sectionRect = barRect;
+ sectionRect.moveLeft(sectionLeft);
+ qreal sectionWidth = barRect.width() * values[index] / max;
+ sectionRect.setWidth(sectionWidth);
+ return sectionRect;
+}