Blame view

app/gui/oven_control/circulargauge.cpp 1.91 KB
99b8066f4   김태훈   V0.1.1
1
2
3
4
5
6
7
8
  #include "circulargauge.h"
  
  #include <QPainter>
  #include <QtDebug>
  
  CircularGauge::CircularGauge(QWidget *parent) : QWidget(parent),
      value(30), maximum(40), minimum(0)
  {
05f2a7552   김태훈   image 관리 구조 변경
9
      background.load(":/images/gauge/circle_background.png");
99b8066f4   김태훈   V0.1.1
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
  }
  
  void CircularGauge::setValue(int value)
  {
      value = qBound(minimum, value, maximum);
      if (this->value != value)
      {
          this->value = value;
          update();
      }
  }
  
  void CircularGauge::setMaximum(int maximum)
  {
      maximum = qMax(minimum, maximum);
      if (this->maximum != maximum)
      {
          this->maximum = maximum;
          update();
      }
  }
  
  void CircularGauge::setMinimum(int minimum)
  {
      minimum = qMin(minimum, maximum);
      if (this->minimum != minimum)
      {
          this->minimum = minimum;
          update();
      }
  }
  
  void CircularGauge::paintEvent(QPaintEvent */*event*/)
  {
      QPainter painter(this);
      painter.setRenderHint(QPainter::Antialiasing);
      painter.drawImage(0, 0, background);
  
      painter.save();
  
      QRect rect((291-283)/2, (290-282)/2, 283, 282);
  
      qreal degree = (qreal) qMax(value - minimum, 0) / qMax(maximum - minimum, 1) * 345;
  
      QBrush barBrush(bar);
      barBrush.setTransform(QTransform().translate(4, 3));
  
      painter.setPen(Qt::NoPen);
      painter.setBrush(barBrush);
      painter.drawPie(rect, 5760 / 4 - 10 * 16, (int) (degree * 16) + 10 * 16 );
  
      painter.restore();
      painter.save();
  
      rect = QRect((291-25)/2 + 2, 2, indicator.size().width() - 2, indicator.size().height() - 2);
      rect.translate(-size().width() / 2, -size().height() / 2);
  
      painter.translate(size().width() / 2, size().height() / 2);
      painter.rotate(-degree);
  
      painter.drawImage(rect, indicator);
  
      painter.restore();
  
      QPen white(Qt::white);
      white.setWidth(3);
  
      painter.setPen(white);
      painter.drawLine(54, 167, 238, 167);
  
      rect.setSize(icon.size());
      rect.moveCenter(QPoint(291/2, 290/3 + 15));
  
      painter.drawImage(rect, icon);
  }