-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmetrics_view.cpp
More file actions
46 lines (39 loc) · 1.27 KB
/
Copy pathmetrics_view.cpp
File metadata and controls
46 lines (39 loc) · 1.27 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
#include "metrics_view.h"
MetricsView::MetricsView()
{
auto palette = this->palette();
QColor bgColor = Qt::black;
bgColor.setAlphaF(0.5);
palette.setColor(QPalette::Window, bgColor);
this->setPalette(palette);
setAutoFillBackground(true);
m_avgTimePerFrame = new QLabel(this);
QFont font = m_avgTimePerFrame->font();
font.setPointSizeF(14);
m_avgTimePerFrame->setFont(font);
palette = m_avgTimePerFrame->palette();
palette.setColor(QPalette::WindowText, Qt::white);
m_avgTimePerFrame->setPalette(palette);
auto layout = new QVBoxLayout(this);
layout->setContentsMargins(5, 3, 5, 3);
layout->addWidget(m_avgTimePerFrame);
}
void MetricsView::update(const MetricsClock::duration& avgDuration, const QSize& size)
{
auto microsecondsPerFrame =
std::chrono::duration_cast<std::chrono::microseconds>(avgDuration);
auto milisecondsPerFrame = double(microsecondsPerFrame.count()) / 1000;
auto text = QString("%1 ms per frame").arg(milisecondsPerFrame, 0, 'g', 3);
if (size.isValid()) {
text += QString(", last frame size: %1x%2").arg(size.width()).arg(size.height());
}
m_avgTimePerFrame->setText(text);
}
void MetricsView::setCameraSwitch()
{
m_avgTimePerFrame->setText("Switch camera");
}
void MetricsView::setCameraError()
{
m_avgTimePerFrame->setText("Camera error");
}