forked from xibeilang524/Graphics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.cpp
264 lines (236 loc) · 7.58 KB
/
util.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
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
#include "util.h"
#include <QWidget>
#include <QHeaderView>
#include <QTableWidget>
#include <QUuid>
#include <QFile>
#include "qmath.h"
#include "global.h"
#include "mainwindow.h"
#define TABLE_ROW_HEIGHT 30 //表格高度
void Util::setWidgetColor(QWidget *widget, QColor &color)
{
widget->setStyleSheet("background-color:rgba("+QString::number(color.red())\
+","+QString::number(color.green())\
+","+QString::number(color.blue())\
+","+QString::number(color.alpha())+")");
}
//获取字体的信息
QString Util::getFontInfo(QFont font)
{
return QString("%1px,%2").arg(font.pointSize()).arg(font.family());
}
//决定每个控件的纵向深度,在添加或复制时候自动调用
qreal Util::getGlobalZValue()
{
GlobalItemZValue += 0.1;
return GlobalItemZValue;
}
//在清空控件时自动清0
void Util::resetGlobalZValue()
{
GlobalItemZValue = 0;
}
//获取唯一标识符
QString Util::getUUID()
{
return QUuid::createUuid().toString();
}
qreal Util::getMaxNum(qreal &a, qreal &b)
{
if(a >= b)
{
return a;
}
else
{
return b;
}
return 0;
}
//设置表头的样式
void Util::setTableStylesheet(QTableWidget *table)
{
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setSelectionMode(QAbstractItemView::SingleSelection);
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->setFocusPolicy(Qt::NoFocus);
table->setStyleSheet("selection-color:white;selection-background-color:#567dbc");//
// table->horizontalHeader()->setStyleSheet("QHeaderView::section{color:white;border:none;border-radius:5px;height:23px;margin-left:1px; \
// background-color:#567dbc;}");
table->horizontalHeader()->setVisible(true);
}
//创建表格单元格,并且设置各行变色
void Util::createTableItem(const int rowCount, QTableWidget *table)
{
for(int i=0 ; i<rowCount ; i++)
{
int row = table->rowCount();
table->setRowCount(row+1);
table->setRowHeight(row,TABLE_ROW_HEIGHT);
for(int j = 0 ; j < table->columnCount(); j++)
{
QTableWidgetItem * item = new QTableWidgetItem();
item->setTextColor(Qt::black);
item->setTextAlignment(Qt::AlignCenter);
if(row%2==0)
{
item->setBackgroundColor(QColor(100,100,100,15));
}
table->setItem(i,j,item);
}
}
}
//删除表格中所有的单元格(除表头)
void Util::removeTableItem(QTableWidget *table)
{
int rowCount = table->rowCount();
for(int i = rowCount-1; i >= 0; i--)
{
table->removeRow(i);
}
}
//清除表格的内容(除表头)
void Util::clearTableData(QTableWidget *table)
{
int rowCount = table->rowCount();
int columnCount = table->columnCount();
for(int i = 0 ; i <rowCount ; i++ )
{
for(int j = 0 ; j < columnCount; j++)
{
table->item(i,j)->setText("");
}
}
}
//将弧度转换为角度
qreal Util::radinToAngle(const qreal &radin)
{
return 180/M_PI*radin;
}
//根据不同类型加载对应的图片
void Util::loadPixmapByGType(GraphicsType type, QPixmap &pixmap)
{
switch(type)
{
case GRA_SQUARE:
pixmap.load(":/images/square.png");
break;
case GRA_RECT:
pixmap.load(":/images/rectange.png");
break;
case GRA_ROUND_RECT:
pixmap.load(":/images/roundedrect.png");
break;
case GRA_CIRCLE:
pixmap.load(":/images/circle.png");
break;
case GRA_ELLIPSE:
pixmap.load(":/images/ellipse.png");
break;
case GRA_POLYGON:
pixmap.load(":/images/diamonds.png");
break;
case GRA_TEXT:
pixmap.load(":/images/text.png");
break;
case GRA_NODE_PORT:
pixmap.load(":/images/nodePort.png");
break;
case GRA_NODE_TRIANGLE_OUT:
pixmap.load(":/images/nodeTriangle.png");
break;
case GRA_NODE_TRIANGLE_IN:
pixmap.load(":/images/nodeTriangle.png");
break;
case GRA_NODE_HALF_CIRCLE_IN:
pixmap.load(":/images/nodeHalfCircleIn.png");
break;
case GRA_NODE_HALF_CIRCLE_OUT:
pixmap.load(":/images/nodeHalfCircleOut.png");
break;
case GRA_NODE_CIRCLE:
pixmap.load(":/images/circle.png");
break;
case GRA_PARALLELOGRAM:
pixmap.load(":/images/parallelogram.png");
break;
case GRA_LOOP_UP:
pixmap.load(":/images/loop_up.png");
break;
case GRA_LOOP_DOWN:
pixmap.load(":/images/loop_down.png");
break;
case GRA_ANNOTATION:
pixmap.load(":/images/annotation.png");
break;
case GAR_PARALLE:
pixmap.load(":/images/parallel.png");
break;
#ifdef ADD_STATE_MODEL
//状态机
case GRA_STATE_START:
pixmap.load(":/images/State_Start.png");
break;
case GRA_STATE_END:
pixmap.load(":/images/State_End.png");
break;
case GRA_STATE_PROCESS:
pixmap.load(":/images/roundedrect.png");
break;
//遮罩
case GRA_MASK_RECT:
pixmap.load(":/images/rectange.png");
break;
case GRA_MASK_BOUND_RECT:
pixmap.load(":/images/roundedrect.png");
break;
case GRA_MASK_CIRCLE:
pixmap.load(":/images/circle.png");
break;
case GRA_NODE_PROCESS:
pixmap.load(":/images/rectange.png");
break;
#endif
default:
break;
}
}
//只显示提示信息,无需获取返回值
void Util::showWarn(QString tipText)
{
QMessageBox::warning(GlobalMainWindow,"警告",tipText,QMessageBox::Yes,QMessageBox::Yes);
}
//全局显示警告信息
int Util::getWarnChoice(QString tipText,QMessageBox::StandardButton butt)
{
int result = QMessageBox::warning(GlobalMainWindow,"警告",tipText,QMessageBox::Yes|butt,butt);
return result;
}
//只显示提示信息,无需获取返回值
void Util::showInfo(QString tipText)
{
QMessageBox::information(GlobalMainWindow,"提示",tipText,QMessageBox::Yes,QMessageBox::Yes);
}
//全局显示信息提示信息
QMessageBox::StandardButton Util::getInfoChoice(QString tipText,QMessageBox::StandardButton butt)
{
return QMessageBox::information(GlobalMainWindow,"提示",tipText,QMessageBox::Yes|butt,butt);
}
//是否是合法的文件,在本地打开和拖入时使用
ReturnType Util::isIllegalFile(QDataStream & stream)
{
int softVersion;
stream >>softVersion;
if(softVersion != M_VERTION)
{
return FILE_VERSION;
}
QString fileFlag;
stream>>fileFlag;
if(fileFlag != SaveFileHeadFlag)
{
return FILE_ILLEGAL;
}
return RETURN_SUCCESS;
}