-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathltview.cpp
More file actions
101 lines (80 loc) · 2.76 KB
/
ltview.cpp
File metadata and controls
101 lines (80 loc) · 2.76 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "ltview.h"
LTView::LTView(QWidget *parent) : QGraphicsView(parent),
group1(new QGraphicsItemGroup),
group2(new QGraphicsItemGroup),
scene(new QGraphicsScene),
penBlack(Qt::black),
penRed(Qt::red),
brushRed(Qt::red, Qt::SolidPattern)
{
this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setAlignment(Qt::AlignCenter);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->setMinimumHeight(100);
this->setMinimumWidth(100);
this->setScene(scene);
penRed.setWidth(1);
scene->addItem(group1);
scene->addItem(group2);
}
LTView::~LTView(){
}
void LTView::updateView(){
int width = this->width();
int height = this->height();
scene->setSceneRect(0, 0, width, height);
double maxH = mLH + 1;
double maxW = mTH + 10;
double ratioL = ((double)(height)) / maxH;
double ratioT = ((double)(width)) / maxW;
int topL = ratioL * (maxH - mLH);
int botL = ratioL * (maxH - mLL);
int topT = ratioT * (mTH);
int botT = ratioT * (mTL);
scene->addLine(0, botL, width, botL, penBlack);
scene->addLine(0, topL, width, topL, penBlack);
scene->addLine(botT, 0, botT, height, penBlack);
scene->addLine(topT, 0, topT, height, penBlack);
int pointS = 8;
int pointX = ratioT * mTemp;
int pointY = ratioL * (maxH - mLevel);
int pointXold = ratioT * mTempOld;
int pointYold = ratioL * (maxH - mLevelOld);
QGraphicsEllipseItem* ellipse = scene->addEllipse(0, 0, pointS, pointS, penBlack, brushRed);
ellipse->setPos(pointX-pointS/2, pointY-pointS/2);
deleteItemsFromGroup(group1);
group1->addToGroup(ellipse);
if (pointX != pointXold || pointY != pointYold){
QGraphicsLineItem *line = scene->addLine(pointXold, pointYold, pointX, pointY, penRed);
group2->addToGroup(line);
mTempOld = mTemp;
mLevelOld = mLevel;
}
}
void LTView::deleteItemsFromGroup(QGraphicsItemGroup *group){
foreach (QGraphicsItem *item, scene->items(group->boundingRect())) {
if (item->group() == group){
delete item;
}
}
}
void LTView::applySettings(QMap<QString, double> ¶ms){
if (params.isEmpty()) return;
mLH = params.value("LH");
mLL = params.value("LL");
mLevel = params.value("Level");
mLevelOld = mLevel;
mTH = params.value("TH");
mTL = params.value("TL");
mTemp = params.value("Temp");
mTempOld = mTemp;
}
void LTView::setLH(double level){ mLH = level; }
void LTView::setLL(double level){ mLL = level; }
void LTView::setTH(double level){ mTH = level; }
void LTView::setTL(double level){ mTL = level; }
void LTView::setCursor(double t, double l){
mTemp = t;
mLevel = l;
}