-
Notifications
You must be signed in to change notification settings - Fork 1
/
teleprompter_window.cpp
120 lines (108 loc) · 2.51 KB
/
teleprompter_window.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
#include <sstream>
#include <QCursor>
#include <QScrollBar>
#include <QString>
#include "teleprompter_window.h"
#include "application_window.h"
#define STYLE "text-align:center;color:white;background-color:black;selection-color:white;selection-background-color:black;"
inline std::string toString (int i)
{
std::stringstream ss;
ss << i;
return ss.str();
}
TeleprompterWindow::TeleprompterWindow(QWidget *parent,QWidget *setupHandler)
: QTextEdit(parent)
{
this->setAlignment(Qt::AlignCenter);
this->viewport()->setCursor(QCursor(Qt::BlankCursor));
this->verticalScrollBar()->hide();
this->horizontalScrollBar()->hide();
setupWindow = setupHandler;
speed = 1;
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(scrollText()));
timerStarted=false;
}
void TeleprompterWindow::setPadding(int padding)
{
std::stringstream out;
out << padding;
QString paddingString = STYLE;
paddingString.append("padding-left:");
paddingString.append(out.str().c_str());
paddingString.append("px;padding-right:");
paddingString.append(out.str().c_str());
paddingString.append("px;");
this->setStyleSheet(paddingString);
}
void TeleprompterWindow::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Escape:
killTimer(this->timer->timerId());
this->timerStarted = false;
this->setReadOnly(false);
this->hide();
static_cast<ApplicationWindow *>(this->setupWindow)->show();
break;
case Qt::Key_Space:
if (this->timerStarted) {
killTimer(this->timer->timerId());
this->timerStarted=false;
} else {
this->timer->start(0);
this->timerStarted=true;
}
break;
case Qt::Key_Down:
if (this->speed<10)
this->speed += 1;
break;
case Qt::Key_Up:
if (this->speed > 1)
this->speed -= 1;
break;
case Qt::Key_1:
this->speed = 1;
break;
case Qt::Key_2:
this->speed = 2;
break;
case Qt::Key_3:
this->speed = 3;
break;
case Qt::Key_4:
this->speed = 4;
break;
case Qt::Key_5:
this->speed = 5;
break;
case Qt::Key_6:
this->speed = 6;
break;
case Qt::Key_7:
this->speed = 7;
break;
case Qt::Key_8:
this->speed = 8;
break;
case Qt::Key_9:
this->speed = 9;
break;
case Qt::Key_0:
this->speed = 10;
break;
default:
event->ignore();
}
}
void TeleprompterWindow::wheelEvent(QWheelEvent *event){
if (!this->timerStarted) {
QTextEdit::wheelEvent(event);
}
}
void TeleprompterWindow::scrollText()
{
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value()+this->speed);
}