-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGoalBar.cpp
40 lines (30 loc) · 854 Bytes
/
GoalBar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "GoalBar.h"
#include <QPainter>
#include <qdebug.h>
GoalBar::GoalBar(QWidget *parent)
: QProgressBar(parent), m_goalBarLevel(-1)
{
}
GoalBar::GoalBar(QWidget *parent, int goalBarLevel)
: QProgressBar(parent), m_goalBarLevel(goalBarLevel)
{
}
void GoalBar::paintEvent(QPaintEvent *event)
{
QProgressBar::paintEvent(event);
if (m_goalBarLevel < 0)
return;
QPainter painter(this);
int barWidth = width();
int barHeight = height();
int drawAtHeight = barHeight - int(float(barHeight) * float(m_goalBarLevel - minimum())/float(maximum() - minimum()));
QColor markerColor(0,0,0);
painter.save();
painter.setPen(markerColor);
painter.drawLine(0,drawAtHeight,barWidth,drawAtHeight);
painter.restore();
}
void GoalBar::setGoalBarLevel(int newlevel)
{
m_goalBarLevel = newlevel;
}