-
Notifications
You must be signed in to change notification settings - Fork 1
/
nightchartswidget.cpp
44 lines (38 loc) · 1008 Bytes
/
nightchartswidget.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
40
41
42
43
44
#include "nightchartswidget.h"
#include "nightcharts.h"
NightchartsWidget::NightchartsWidget(QWidget *parent) :
QWidget(parent)
{
clear();
}
void NightchartsWidget::setType(Nightcharts::type t)
{
_chart.setType(t);
}
void NightchartsWidget::clear()
{
_chart = Nightcharts();
_chart.setType(Nightcharts::Histogramm);
_chart.setLegendType(Nightcharts::Vertical);
_margin_left = 40;
_margin_top = 40;
}
void NightchartsWidget::paintEvent(QPaintEvent * e)
{
QWidget::paintEvent(e);
if(!_chart.pieceCount()) return ;
QPainter painter;
QFont font;
painter.begin(this);
int w = (this->width() - _margin_left - 150);
int h = (this->height() - _margin_top - 100);
int size = (w<h)?w:h;
_chart.setCords(_margin_left, _margin_top,size, size);
_chart.draw(&painter);
_chart.drawLegend(&painter);
//painter.end();
}
void NightchartsWidget::addItem(QString name, QColor color, float value)
{
_chart.addPiece(name,color,value);
}