-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathframe_vis.cpp
More file actions
181 lines (159 loc) · 5.49 KB
/
frame_vis.cpp
File metadata and controls
181 lines (159 loc) · 5.49 KB
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
#include "frame_vis.h"
frame_vis::frame_vis(QWidget *parent) :
QDialog(parent),
ui(new Ui::frame_vis)
{
ui->setupUi(this);
scene = NULL;
pixels = NULL;
win_title = VIS_FRAME_TXT+" ";
set_label = "vis_window";
settings_hdl = NULL;
en_pos_save = false;
prev_width = 640;
prev_height = 480;
//update_time.start();
pos_timer.setSingleShot(true);
pos_timer.setInterval(500);
connect(&pos_timer, SIGNAL(timeout()), this, SLOT(updateWindowPosition()));
scene = new QGraphicsScene(this);
ui->viewport->setViewportUpdateMode(QGraphicsView::NoViewportUpdate);
//ui->viewport->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
ui->viewport->setOptimizationFlags(QGraphicsView::DontSavePainterState|QGraphicsView::DontAdjustForAntialiasing);
ui->viewport->setInteractive(false);
ui->viewport->setViewport(new QGLWidget(QGLFormat()));
ui->viewport->setScene(scene);
ui->viewport->setAlignment(Qt::AlignLeft|Qt::AlignTop);
//ui->viewport->setCacheMode(QGraphicsView::CacheBackground);
//ui->viewport->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//ui->viewport->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->viewport->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
ui->viewport->setMouseTracking(false);
pix_data = QPixmap(prev_width, prev_height);
pix_data.fill(Qt::black);
pixels = new QGraphicsPixmapItem(pix_data);
pixels->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
scene->addItem(pixels);
connect(scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(redrawDone()));
settings_hdl = new QSettings(QSettings::IniFormat, QSettings::UserScope, APP_ORG_NAME, APP_INI_NAME);
if(settings_hdl!=NULL)
{
//qInfo()<<"[VIS] Settings path:"<<settings_hdl->fileName();
settings_hdl->sync();
}
qInfo()<<"[VIS] Launched, thread:"<<this->thread()<<"ID"<<QString::number((uint)QThread::currentThreadId());
}
frame_vis::~frame_vis()
{
if(settings_hdl!=NULL)
{
settings_hdl->sync();
delete settings_hdl;
}
qInfo()<<"[VIS] Visualizer destroyed";
delete ui;
}
//------------------------ Set speciefic visualizator label to load proper settings.
void frame_vis::setSettingsLabel(QString in_label)
{
set_label = in_label;
}
//------------------------ Visualizator window was moved.
void frame_vis::moveEvent(QMoveEvent *event)
{
// (Re)start timer to update window position and size.
pos_timer.start();
event->accept();
}
//------------------------ Visualizator window was resized.
void frame_vis::resizeEvent(QResizeEvent *event)
{
// (Re)start timer to update window position and size.
pos_timer.start();
event->accept();
}
//------------------------ Visualizator window is about to be shown.
void frame_vis::showEvent(QShowEvent *event)
{
if(settings_hdl!=NULL)
{
settings_hdl->beginGroup(set_label);
if((settings_hdl->contains("size")!=false)&&(settings_hdl->contains("position")!=false))
{
qInfo()<<"[VIS] Loading window position"<<set_label;
this->setGeometry(settings_hdl->value("size").toRect());
this->move(settings_hdl->value("position").toPoint());
}
settings_hdl->endGroup();
en_pos_save = true;
}
event->accept();
}
//------------------------ Set speciefic visualizator window title.
void frame_vis::setTitle(QString in_str)
{
if(in_str.isEmpty()==false)
{
win_title = in_str+". "+VIS_FRAME_TXT+" ";
}
else
{
win_title = VIS_FRAME_TXT+" ";
}
this->setWindowTitle(win_title+QString::number(0));
}
//------------------------ Get new frame from renderer and display it.
void frame_vis::drawFrame(QImage in_img)
{
if(in_img.isNull()!=false)
{
return;
}
//qDebug()<<"Drawing"<<in_img.text("Frame")<<update_time.elapsed();
if((prev_width!=in_img.width())||(prev_height!=in_img.height()))
{
//qInfo()<<"[VIS] Resized to"<<in_img.width()<<"x"<<in_img.height();
// Save new dimensions.
prev_width = in_img.width();
prev_height = in_img.height();
// Update pixmap.
pixels->setPixmap(QPixmap::fromImage(in_img.copy()));
scene->setSceneRect(0, 0, prev_width, prev_height);
ui->viewport->setSceneRect(scene->sceneRect());
ui->viewport->adjustSize();
ui->viewport->viewport()->update();
this->setMinimumSize(ui->viewport->size());
this->setMaximumSize(ui->viewport->size());
this->resize(ui->viewport->size());
this->adjustSize();
}
else
{
pixels->setPixmap(QPixmap::fromImage(in_img));
ui->viewport->viewport()->update();
}
// Update frame number in the window title.
this->setWindowTitle(win_title+in_img.text("Frame"));
update_time.start();
}
//------------------------ Update window position and size in settings.
void frame_vis::updateWindowPosition()
{
if(en_pos_save!=false)
{
if(settings_hdl!=NULL)
{
qInfo()<<"[VIS] Updating window position"<<set_label;
settings_hdl->beginGroup(set_label);
settings_hdl->setValue("size", this->geometry());
settings_hdl->setValue("position", this->pos());
settings_hdl->endGroup();
}
}
}
//------------------------ Scene redraw is done after last frame update.
void frame_vis::redrawDone()
{
//qDebug()<<"[VIS] Preview updated"<<update_time.elapsed();
emit readyToDraw();
}