QuakeGod
2023-05-30 acd576fbf6ca6086455d7f82140dd495237c6803
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#include "myHMIDisplay.h"
#include <QPen>
#include <QBrush>
#include <QPainter>
#include <QTimer>
 
myHMIDisplay::myHMIDisplay(QWidget *parent) : QFrame(parent)
{
    QTimer* timer = new QTimer(this);
        timer->start(50);
        connect(timer,&QTimer::timeout,this,&myHMIDisplay::OnTimerd);
//        stEquipment equipment1 ={ "ABC",50,50,10,10,10,{3} };
//        m_equipments.append(equipment1);
        m_equipments.append({1,u8"熔制区",8,20,20,5,5,{0}});
 
        m_equipments.append({3,u8"龙门",40,15,40,3,5,{3}});
        m_equipments.append({3,u8"车",25,25,6,4,2,{3}});
        m_equipments.append({3,u8"车",35,25,6,4,2,{3}});
        m_equipments.append({3,u8"车",45,25,6,4,2,{3}});
        m_equipments.append({3,u8"车",55,25,6,4,2,{3}});
        m_equipments.append({5,u8"龙门1",70,20,10,5,1,{3}});
        m_equipments.append({5,u8"龙门2",80,20,10,5,1,{3}});
        m_equipments.append({5,u8"车1",70,30,5,5,1,{3}});
        m_equipments.append({5,u8"车2",75,30,5,5,1,{3}});
        m_equipments.append({5,u8"车3",80,30,5,5,1,{3}});
        m_equipments.append({5,u8"车4",85,30,5,5,1,{3}});
 
        m_equipments.append({1,u8"冷车间",8,50,10,5,5,{3}});
        m_equipments.append({7,u8"刷锅",20,50,10,5,5,{255}});
        m_equipments.append({7,u8"磨锅",35,50,10,5,5,{3}});
        m_equipments.append({7,u8"切割1",50,45,10,3,5,{3}});
        m_equipments.append({7,u8"切割2",50,55,10,3,5,{3}});
        m_equipments.append({7,u8"测量",65,50,10,5,5,{3}});
        m_equipments.append({7,u8"酸洗",80,50,10,5,5,{3}});
 
        m_equipments.append({1,u8"净化车间",8,80,20,5,5,{3}});
        m_equipments.append({7,u8"烘烤",20,80,10,5,5,{3}});
        m_equipments.append({7,u8"人工目检",40,80,10,5,5,{3}});
        m_equipments.append({7,u8"8条直传",60,80,10,5,5,{3}});
        m_equipments.append({7,u8"拆包",80,80,10,5,5,{3}});
}
 
 
void myHMIDisplay::OnTimerd()
{
    nCount++;
    update();
}
 
 
void myHMIDisplay::paintEvent(QPaintEvent *event)
{
    //控件的绘制工具,通过该工具我们可以进行常用的绘制了
    QPainter painter(this);
     painter.setRenderHint(QPainter::Antialiasing);
 
        //取得画布大小和中心方形。
     int w = this->rect().width();
     int h = this->rect().height();
     int s;
     int wmargin=0;
     int hmargin=0;
     if (w>h) {
         s= h;
         wmargin=(w-s)/2;
 
     }else{
         s= w;
         hmargin=(h-s)/2;
     }
     //画边框
     QPen pen0(QColor(0x4D9CF8));
     painter.setPen(pen0);
     painter.drawRoundRect(this->rect(),5,5);
 
      int thick =  s/20;        //线宽
 
 
 
     QPen pen1(QColor(80,80,80));
 
     //绘制弧线的背景
      pen1.setWidth(thick);
      pen1.setCapStyle(Qt::RoundCap);
      //      pen.setColor(QColor("#4D9CF8"));
      painter.setPen(pen1);
 
     QRectF in_rectangle(wmargin+10, hmargin+s/4, s-20, s-20);
     int in_startAngle = (0) * 16;
     int in_spanAngle = (180)*16;
     painter.drawArc(in_rectangle,in_startAngle,in_spanAngle);
 
 
 
     QPen pen2(lineColor);
     QBrush brush1(QColor(0xbb,0xbb,0x66,0xff));
     QBrush brush2(QColor(0x88,0x88,0x66,0xff));
     QBrush brush3(QColor(0x88,0x88,0x66,0xff));
 
     QBrush RunningBrush(RunningColor);
     QBrush StopedBrush(StopedColor);
     QBrush WarningBrush(WarningColor);
 
     QPen pen3(nameColor);
     //绘制弧线的背景
 //    pen2.setWidth(thick);
 //    pen1.setCapStyle(Qt::RoundCap);
     //      pen.setColor(QColor("#4D9CF8"));
     painter.setPen(pen2);
//     painter.setBrush(brush1);
     int n=m_equipments.count();
     for (int i=0;i<n;i++){
         stEquipment theequipment = m_equipments.at(i);
         theequipment.stat=0xff;
         theequipment.bRunning=1;
         theequipment.bStoped=1;
         theequipment.bWarning=1;
         int thetype = theequipment.nType;
         int ex = theequipment.x * w /100 ;
         int ey = theequipment.y * h /100 ;
         int el = theequipment.l * w /100 ;
         int ew = theequipment.w * w /100;
         int eh = theequipment.h/2 * h /100;
         QRect rect2(ex-el/2, ey-ew/2, el,ew);
         if (thetype & eqTypeSimple) {
            //draw Top
             painter.setPen(pen2);
            painter.setBrush(brush1);
             //painter.fillRect(rect2,brush1);
             painter.drawRect(rect2);
             //draw side;
             QPolygon polygon1;
             QPoint points[10];
             points[0]=QPoint(ex-el/2,ey-ew/2);
             points[1]=QPoint(ex-el/2-eh,ey-ew/2+eh);
             points[2]=QPoint(ex-el/2-eh,ey+ew/2+eh);
             points[3]=QPoint(ex-el/2,ey+ew/2);
 
             painter.setBrush(brush2);
             painter.drawPolygon(points,4);
             painter.drawPolyline(points,4);
 
             points[0]=QPoint(ex-el/2,ey+ew/2);
             points[1]=QPoint(ex-el/2-eh,ey+ew/2+eh);
             points[2]=QPoint(ex+el/2-eh,ey+ew/2+eh);
             points[3]=QPoint(ex+el/2,ey+ew/2);
                painter.setBrush(brush3);
             painter.drawPolygon(points,4);
             painter.drawPolyline(points,4);
         }
         if (thetype & eqTypeText){
             //draw Name
             QString sName = theequipment.sName;
             painter.setPen(pen3);
 
             painter.setFont(QFont("Microsoft YaHei",s/32));
             //painter.drawText(this->rect(),s1);
             painter.drawText(rect2,Qt::AlignCenter,sName);
         }
         if (thetype & eqTypeIndicator ){
             //draw indicator 指示器
             painter.setBrush(brush3);
             QRect rect3(ex-el/4,ey-ew*7/8,el/2,ew/4);
             painter.fillRect(rect3,brush1);
             painter.drawRect(rect3);
 
             QRect rect31(ex-el/4,ey-ew*7/8,el/8,ew/4);
             if (theequipment.bRunning){
                 painter.fillRect(rect31,RunningBrush);
             }
            // painter.drawRect(rect31);
 
             QRect rect32(ex-el/16,ey-ew*7/8,el/8,ew/4);
             if (theequipment.bStoped){
                //painter.fillRect(rect32,StopedBrush);
                 painter.setBrush(StopedBrush);
             }
 
             painter.drawRect(rect32);
 
             QRect rect33(ex+2*el/16,ey-ew*7/8,el/8,ew/4);
             if (theequipment.bWarning){
                painter.setBrush(WarningBrush);
                painter.fillRect(rect33,WarningBrush);
             }
             painter.drawRect(rect33);
 
 
         }
     }
 
//     in_startAngle = (nOffset + 90+270) * 16;
//     in_spanAngle = (45)*16;
//     painter.drawArc(in_rectangle,in_startAngle,in_spanAngle);
 
 
 
    return;
    //   QRect rect2(wmargin + 20, hmargin +20, s-40,s-40);
    QString s1;
/*
     //添加绘制的字体和字号
     s1=QString::number(int(position));
     int l = s1.length();
     double fr = sqrt(l*l + 4);
     painter.setFont(QFont("Microsoft YaHei",(s-20)/fr));
  //   painter.drawText(this->rect(),s1);
    painter.drawText(rect2,Qt::AlignCenter,s1);
*/
}
 
void myHMIDisplay::SetRange(int n)
{
    range=n;
}
void myHMIDisplay::SetPosition(float n)
{
    position=n;
    update();
}
void myHMIDisplay::SetTitle(QString title)
{
    sTitle = title;
}
void myHMIDisplay::SetUnit(QString unit)
{
    sUnit = unit;
}
void myHMIDisplay::SetColor(QColor Start,QColor End)
{
    color1 = Start;
    color2 = End;
}
 
 
void drawArc()
{
    int nCount=0;
    int position;
    int range=0;
    int thick=2;
    int wmargin=10;
    int hmargin=10;
    int s=2;
 
    QColor color1,color2;
 
    QPainter painter;
    QString sTitle="1122";
    QString sUnit;
 
    int nOffset = nCount*5 % 180;
 
    position = nOffset *range /180;
 
    QPen pen2(QColor(0x4D9CF8));
    pen2.setWidth(thick);
    pen2.setCapStyle(Qt::RoundCap);
 
    QRectF sec_rectangle(wmargin+10, hmargin+s/4, s-20, s-20);
    int sec_startAngle = 180 * 16;
    int sec_spanAngle = -1*((position / range)*180)*16;
 
    QConicalGradient gradient;
    gradient.setCenter(sec_rectangle.center());
    gradient.setAngle(190);
    gradient.setColorAt(0, color2);
    gradient.setColorAt(0.5, color2);
    gradient.setColorAt(1, color1);
 
 
    //    int arcLengthApproximation = m_width + m_width / 3;
    QPen pen3(QBrush(gradient), thick);
    pen3.setCapStyle(Qt::RoundCap);
    painter.setPen(pen3);
    painter.drawArc(sec_rectangle,sec_startAngle,sec_spanAngle);
 
 
 
    //绘制文本,绘制白色的文字
    painter.setPen(QPen(QColor(255,255,255)));
    QString s1;
    s1=sTitle;
    //显示标题
    QRect rect2(wmargin + 20, hmargin +10, s-40,s/8);
    painter.setFont(QFont("Microsoft YaHei",s/12));
    //   painter.drawText(this->rect(),s1);
    painter.drawText(rect2,Qt::AlignCenter,s1);
        //显示前后刻度
    painter.setFont(QFont("Microsoft YaHei",s/18));
    s1="0";
    //   painter.drawText(this->rect(),s1);
    rect2.setRect(wmargin,hmargin+s*3/4,20,s/16);
    painter.drawText(rect2,Qt::AlignCenter,s1);
 
    s1=QString::number(range);
    //   painter.drawText(this->rect(),s1);
    rect2.setRect(wmargin+s-30,hmargin+s*3/4,40,s/16);
    painter.drawText(rect2,Qt::AlignCenter,s1);
 
    //显示当前数量
    painter.setFont(QFont("Microsoft YaHei",s/8));
    s1=QString::number(position);
    //   painter.drawText(this->rect(),s1);
    rect2.setRect(wmargin+10,hmargin+10-s/20,s-20,s-20);
    painter.drawText(rect2,Qt::AlignCenter,s1);
        //显示单位
    painter.setFont(QFont("Microsoft YaHei",s/16));
    s1=sUnit;
    //   painter.drawText(this->rect(),s1);
    rect2.setRect(wmargin+10,hmargin+10+s/10,s-20,s-20);
    painter.drawText(rect2,Qt::AlignCenter,s1);
}