-
Notifications
You must be signed in to change notification settings - Fork 2
/
widget.cpp
285 lines (232 loc) · 6.64 KB
/
widget.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#include "widget.h"
#include "ui_widget.h"
// #include "QGraphicsSegment.h"
// #include "QGraphicsCircleItem.h"
// #include "QGraphicsPartitionItem.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
myscene = new QGraphicsScene(0,0,255,255);
ui->graphicsView->setScene(myscene);
ui->graphicsView->setSceneRect(0,0,255,255);
//创建一个640x480的图像用于测试
//CurrentFrame cf;
curFrame = myscene->addPixmap(*cf.mImage);
int VideoWidth = cf.width;
int VideoHeight = cf.height;
//根据视频大小,设置场景区域
myscene->setSceneRect(0,0,VideoWidth,VideoHeight);
//根据视频显示区域的大小,缩放视口的大小和位置
//设置到视频显示区域
ui->graphicsView->setParent(ui->label_3);
//获取视频显示区域的大小
int height = ui->label_3->height();
int width = ui->label_3->width();
qDebug("%d %d",height,width);
//调整为合适的大小,放置到正中央
int vHeight = height-4;//边框设置了1个像素,为了显示区别,还空了1个像素,因此-4
int vWidth = vHeight*4/3;
int vTop = 2;
int vLeft = (width-vWidth)/2;
ui->graphicsView->setGeometry(vLeft,vTop,vWidth,vHeight);
ui->graphicsView->setSceneRect(0,0,640,480);
//根据视频大小,进行缩放映射
ui->graphicsView->resetTransform();
float s = (float)(vWidth-2)/(float)VideoWidth; //默认具有1个像素边框,因此-2
ui->graphicsView->scale(s,s);
ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->label_5->setText(QString("100"));
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_Marker_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_MARKER);
}
void Widget::on_SelectItem_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_NONE);
}
void Widget::on_DrawLine_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_DRAWLINE);
}
void Widget::on_Pencil_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_PENCIL);
}
void Widget::on_Text_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_TEXT);
}
void Widget::on_Image_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_IMAGE);
}
void Widget::on_Curve_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_CURVE);
}
void Widget::on_DrawRect_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_DRAWRECT);
}
void Widget::on_Ellipse_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_CIRCLE);
}
void Widget::on_Time_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_TIME);
}
void Widget::on_Distance_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_SCALE);
}
void Widget::on_InnerDegree_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_INNERDEGREE);
}
void Widget::on_OutterDegree_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_OUTTERDEGREE);
}
void Widget::on_CloneRect_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_CLONERECT);
}
/*
void Widget::on_Horizontal_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_HORIZONTAL);
}
void Widget::on_Vertical_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_VERTICAL);
}
*/
void Widget::on_MakerPen_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::ITEM_MARKERPEN);
}
void Widget::on_Color_clicked()//color
{
const QColor color = QColorDialog::getColor(Qt::green, this, "Select Color");
if (color.isValid()) {
ui->graphicsView->setSelectedItemPenColor(color);
}
}
void Widget::on_font_clicked()
{
bool ok;
QFont font = QFontDialog::getFont(&ok, this);
if (ok) {
qDebug()<<"font:"<<font;
ui->graphicsView->setSelectedItemFont(font);
}
}
void Widget::on_opacity_valueChanged(int value)
{
ui->graphicsView->setSelectedItemOpacity(value);
ui->label_5->setText(QString::number(value));
}
void Widget::on_lineStyle_currentIndexChanged(const QString &arg)
{
if (arg == QString("直线"))
{
ui->graphicsView->setSelectedItemLineStyle(ToolAtrribute::LINE);
}
else if (arg == QString("左箭头"))
{
ui->graphicsView->setSelectedItemLineStyle(ToolAtrribute::LEFT_ARROW);
}else if (arg == QString("右箭头"))
{
ui->graphicsView->setSelectedItemLineStyle(ToolAtrribute::RIGHT_ARROW);
}else if (arg == QString("双向箭头"))
{
ui->graphicsView->setSelectedItemLineStyle(ToolAtrribute::BOTH_ARROW);
}
}
void Widget::on_LineWidth_currentIndexChanged(int index)
{
ui->graphicsView->setSelectedItemWidth(index);
}
void Widget::on_brushColor_clicked()
{
const QColor color = QColorDialog::getColor(Qt::green, this, "Select Color");
if (color.isValid()) {
qDebug()<<"color:"<<color;
ui->graphicsView->setSelectedItemBrushColor(color);
}
}
void Widget::on_copy_clicked()
{
ui->graphicsView->Copy();
}
void Widget::on_setOrder_clicked()
{
ui->graphicsView->setSelectedItemZOrder();
}
void Widget::on_SetAsScale_clicked()
{
try{
ui->graphicsView->setScale();
}
catch(...)
{
qDebug()<<"set scale failed.";
}
}
void Widget::on_delete_2_clicked()
{
ui->graphicsView->deleteAllSelected();
}
void Widget::on_paste_clicked()
{
ui->graphicsView->Paste();
}
//json输入
void Widget::on_save_clicked()
{
ui->graphicsView->saveItems();
}
//json解析
void Widget::on_load_clicked()
{
ui->graphicsView->loadItems();
}
void Widget::on_cut_clicked()
{
ui->graphicsView->Cut();
}
void Widget::flipImage()
{
bool vflip = ui->VFlip->isChecked();
bool hflip = ui->HFlip->isChecked();
QPixmap temp = cf.mImage->copy();
QPixmap img = QPixmap::fromImage(temp.toImage().mirrored(hflip,vflip));
curFrame->setPixmap(img);
}
void Widget::on_Zoom_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::GLOBAL_ZOOM);
}
void Widget::on_Move_clicked()
{
ui->graphicsView->setCurrentMode(GraphicsView::GLOBAL_MOVE);
}
void Widget::on_HFlip_stateChanged(int )
{
flipImage();
ui->graphicsView->FlipAllItems(true,false);
}
void Widget::on_VFlip_stateChanged(int )
{
flipImage();
ui->graphicsView->FlipAllItems(false,true);
}