-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_controller.cpp
87 lines (68 loc) · 1.59 KB
/
view_controller.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
// Controls the currently viewed slide
// Author: Max Schwarz <[email protected]>
#include "view_controller.h"
#include <QApplication>
#include <QTimer>
ViewController::ViewController(RenderingPool* renderingPool, QObject* parent)
: QObject(parent)
, m_renderingPool(renderingPool)
{
m_timer = new QTimer(this);
connect(m_timer, &QTimer::timeout, this, &ViewController::timerTick);
}
void ViewController::setCurrentSlideNumber(int number)
{
m_slideNumber = std::max(0, std::min(m_renderingPool->count()-1, number));
currentSlideNumberChanged(m_slideNumber);
}
void ViewController::nextSlide()
{
setCurrentSlideNumber(currentSlideNumber() + 1);
if(!m_timer->isActive())
m_timer->start(1000);
}
void ViewController::previousSlide()
{
setCurrentSlideNumber(currentSlideNumber() - 1);
}
void ViewController::quit()
{
QApplication::exit(0);
}
QObject* ViewController::nextPage() const
{
if(currentSlideNumber() >= m_renderingPool->count()-1)
return nullptr;
return (*m_renderingPool)[currentSlideNumber() + 1];
}
void ViewController::resetTime()
{
m_timer->stop();
m_elapsedHours = 0;
m_elapsedMinutes = 0;
m_elapsedSeconds = 0;
elapsedTimeChanged();
}
void ViewController::timerTick()
{
m_elapsedSeconds++;
if(m_elapsedSeconds == 60)
{
m_elapsedSeconds = 0;
m_elapsedMinutes++;
if(m_elapsedMinutes == 60)
{
m_elapsedMinutes = 0;
m_elapsedHours++;
}
}
elapsedTimeChanged();
}
QString ViewController::elapsedTimeString() const
{
return QString("%1:%2:%3")
.arg(m_elapsedHours)
.arg(m_elapsedMinutes, 2, 10, QChar('0'))
.arg(m_elapsedSeconds, 2, 10, QChar('0'))
;
}