-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageWindow.cpp
232 lines (185 loc) · 4.86 KB
/
ImageWindow.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
//
// Copyright (c) 2012, 2013 Pansenti, LLC.
//
// This file is part of Syntro
//
// Syntro is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Syntro is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Syntro. If not, see <http://www.gnu.org/licenses/>.
//
#include <QtGui>
#include "ImageWindow.h"
#define SPACESVIEW_CAMERA_DEADTIME (10 * SYNTRO_CLOCKS_PER_SEC)
ImageWindow::ImageWindow(AVData *avData, bool filtered, bool showName, bool showDate,
bool showTime, QColor textColor, QWidget *parent)
: QLabel(parent)
{
m_avData = avData;
m_filtered = filtered;
m_showName = showName;
m_showDate = showDate;
m_showTime = showTime;
m_textColor = textColor;
m_selected = false;
m_idle = true;
m_lastFrame = SyntroClock();
m_displayDate = QDate::currentDate();
m_displayTime = QTime::currentTime();
setAlignment(Qt::AlignCenter);
setMinimumWidth(120);
setMinimumHeight(90);
setMaximumWidth(640);
setMaximumHeight(480);
if (m_avData) {
if (m_filtered)
m_name = m_avData->filteredName();
else
m_name = m_avData->name();
m_timer = startTimer(30);
}
}
ImageWindow::~ImageWindow()
{
killTimer(m_timer);
m_avData = NULL;
}
QString ImageWindow::name()
{
return m_name;
}
void ImageWindow::setShowName(bool enable)
{
m_showName = enable;
update();
}
void ImageWindow::setShowDate(bool enable)
{
m_showDate = enable;
update();
}
void ImageWindow::setShowTime(bool enable)
{
m_showTime = enable;
update();
}
void ImageWindow::setTextColor(QColor color)
{
m_textColor = color;
update();
}
void ImageWindow::mousePressEvent(QMouseEvent *)
{
if (m_avData)
emit imageMousePress(m_name);
}
void ImageWindow::mouseDoubleClickEvent(QMouseEvent *)
{
if (m_avData)
emit imageDoubleClick(m_name);
}
bool ImageWindow::selected()
{
return m_selected;
}
void ImageWindow::setSelected(bool select)
{
m_selected = select;
update();
}
void ImageWindow::newImage(QImage image, qint64 timestamp)
{
m_lastFrame = SyntroClock();
if (image.width() == 0)
return;
m_idle = false;
m_image = image;
QPixmap pixmap = QPixmap::fromImage(image.scaled(size(), Qt::KeepAspectRatio));
setPixmap(pixmap);
QDateTime dt = QDateTime::fromMSecsSinceEpoch(timestamp);
m_displayDate = dt.date();
m_displayTime = dt.time();
update();
}
void ImageWindow::timerEvent(QTimerEvent *)
{
if (m_avData && m_lastFrame < m_avData->lastUpdate()) {
if (m_filtered)
newImage(m_avData->filteredImage(), m_avData->imageTimestamp());
else
newImage(m_avData->image(), m_avData->imageTimestamp());
}
else if (SyntroUtils::syntroTimerExpired(SyntroClock(), m_lastFrame, SPACESVIEW_CAMERA_DEADTIME)) {
m_idle = true;
update();
}
}
void ImageWindow::paintEvent(QPaintEvent *event)
{
QString timestamp;
QLabel::paintEvent(event);
QString timeFormat("hh:mm:ss:zzz");
QString dateFormat("ddd MMMM d yyyy");
QPainter painter(this);
QRect dr = drawingRect();
if (m_idle)
painter.fillRect(dr, Qt::Dense2Pattern);
if (m_selected) {
QPen pen(Qt::green, 3);
painter.setPen(pen);
painter.drawRect(dr);
}
if (!m_showDate && !m_showTime && !m_showName)
return;
painter.setPen(m_textColor);
int fontHeight = dr.height() / 20;
if (fontHeight < 8)
fontHeight = 8;
else if (fontHeight > 12)
fontHeight = 12;
painter.setFont(QFont("Arial", fontHeight));
if (m_showName)
painter.drawText(dr.left() + 4, dr.top() + fontHeight + 2, m_name);
if (m_showTime || m_showDate) {
if (dr.width() < 160) {
// only room for one, choose time over date
if (m_showDate && m_showTime)
timestamp = m_displayTime.toString(timeFormat);
else if (m_showDate)
timestamp = m_displayDate.toString(dateFormat);
else
timestamp = m_displayTime.toString(timeFormat);
}
else if (!m_showDate) {
timestamp = m_displayTime.toString(timeFormat);
}
else if (!m_showTime) {
timestamp = m_displayDate.toString(dateFormat);
}
else {
timestamp = m_displayDate.toString(dateFormat) + " " + m_displayTime.toString(timeFormat);
}
painter.drawText(dr.left() + 4, dr.bottom() - 2, timestamp);
}
}
// Assumes horizontal and vertical center alignment
QRect ImageWindow::drawingRect()
{
QRect dr = rect();
const QPixmap *pm = pixmap();
if (pm) {
QRect pmRect = pm->rect();
int x = (dr.width() - pmRect.width()) / 2;
int y = (dr.height() - pmRect.height()) / 2;
dr.adjust(x, y, -x, -y);
}
return dr;
}