forked from qtexe/qt_2019_ncov
-
Notifications
You must be signed in to change notification settings - Fork 15
/
slots.cpp
154 lines (142 loc) · 5.31 KB
/
slots.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
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
#include "dialog.h"
#include "ui_dialog.h"
void Dialog::anchorClickedSlot(const QUrl& url)
{
//更多报道:840*520
QString moreUrl = "https://new.qq.com/ch/antip/";
//视频直播:1230*520
QString cctvUrl = "http://tv.cctv.com/live/cctv13/";
QString urlStr = url.toString();
QNetworkConfigurationManager mgr;
if(mgr.isOnline() == true)
{
if(urlStr != moreUrl && urlStr != cctvUrl)
{
qDebug() << urlStr;
// this->setWindowModality(Qt::WindowModal); //不阻塞当前窗口的进程
newsInfo_win.openURL(url);
newsInfo_win.exec();
}
else
QDesktopServices::openUrl(url);
}
else
QMessageBox::warning(NULL, "错误", "无网络连接,请检查网络", QMessageBox::Yes);
}
void Dialog::closeEvent(QCloseEvent *win)
{
int ret = QMessageBox::information(this, "提示", "是否关闭?", "是/Yes", "否/No");
if(ret == 0)
{
win->accept();//不会将事件传递给组件的父组件
qDebug()<<"已关闭";
}
else
win->ignore();
}
//鼠标悬停,显示曲线值
void Dialog::disTip(QMouseEvent *event, QCustomPlot *widget, QVector<QString> date)
{
//获取鼠标坐标,相对父窗体坐标
float x_pos = event->pos().x();
// int y_pos = event->pos().y();
//鼠标坐标转化为CustomPlot内部坐标
uint16_t x_val = widget->xAxis->pixelToCoord(x_pos) + 0.5;
// int y_val = ui->widget_1->yAxis->pixelToCoord(y_pos);
QString str, strToolTip;
// int a = x_val + 0.5;
// qDebug() << x_val << a;
if(x_val < date.size())
{
// qDebug() << x_val;
str = date[x_val];
// str = QString::number(x_val, 10, 3);
strToolTip += "日期: ";
strToolTip += str;
strToolTip += "\n";
uint8_t lineNum = widget->xAxis->graphs().count(); //当前窗口的曲线个数
for (int i = 0; i < lineNum; i++)
{
QString lineName = widget->graph(i)->name();
//获得x轴坐标位置对应的曲线上y的值
if(clickId < 3)
{
int y = widget->graph(i)->data()->at(x_val)->value;
str = QString::number(y);
}
else
{
double y= widget->graph(i)->data()->at(x_val)->value;
str = QString::number(y, 10, 1);
}
strToolTip += lineName + ":";
strToolTip += str;
if(clickId == 3)
strToolTip += "%";
if(i != lineNum - 1)
strToolTip += "\n";
}
QToolTip::showText(cursor().pos(), strToolTip, widget);
}
}
void Dialog::widget_chart_event(QMouseEvent *event)
{
if(clickId == 1 | clickId == 2)
{
disTip(event, ui->widget_chart, TotalDate);
}
else if(clickId == 0)
disTip(event, ui->widget_chart, AddDate);
// else if(ui->rb3_rate->isChecked())
else
disTip(event, ui->widget_chart, RateDate);
}
//点击不同的按钮绘制不同的曲线
void Dialog::drawCharts(int id)
{
// qDebug() << id;
setSelectStyle(id);
clickId = id;
switch(id)
{
case 0:
widgetDrawLine(ui->widget_chart, "新增疑似/确诊趋势", "新增确诊", "新增疑似",
clr1_1, clr1_2, AddDate, AddConfirmDub, AddSuspectDub);
break;
case 1:
widgetDrawLine(ui->widget_chart, "累计疑似/确诊趋势", "累计确诊", "累计疑似",
clr2_1, clr2_2, TotalDate, TotalConfirmDub, TotalSuspectDub);
break;
case 2:
widgetDrawLine(ui->widget_chart, "累计治愈/死亡趋势", "累计治愈", "累计死亡",
clr3_1, clr3_2, TotalDate, TotalHealDub, TotalDeadDub);
break;
case 3:
widgetDrawLine(ui->widget_chart, "治愈率/病死率", "治愈率", "病死率",
clr4_1, clr4_2, RateDate, chinaDayListHealRate, chinaDayListDeadRate);
break;
default:break;
}
}
void Dialog::setSelectStyle(int id)
{
QString style1 =
"border:3px groove rgb(126, 126, 126);" //边框线条粗线,线型,颜色
"border-radius:8px;" //圆角弧度
"padding:2px 4px;" //文字离边框的距离,H/L
"background-color: rgb(243, 246, 248);" //背景颜色
"color: rgb(0, 0, 0);"; //字体黑色; //未选中
QString style2 =
"border:3px groove rgb(126, 126, 226);" //边框线条粗线,线型,颜色
"border-radius:8px;" //圆角弧度
"padding:2px 4px;" //文字离边框的距离,H/L
"background-color: rgb(238,244,255);" //背景颜色
"color: rgb(22,107,241);" ; //字体蓝色;
ui->btn_group->button(id)->setStyleSheet(style2);
QList<QAbstractButton*> btnList = ui->btn_group->buttons();
btnList.removeAt(id); //移除当前,其余设置未选中状态
for(int i = 0; i < btnList.size(); i++)
{
btnList.at(i)->setStyleSheet(style1);
}
}