-
Notifications
You must be signed in to change notification settings - Fork 0
/
DisplayWidget.cpp
60 lines (42 loc) · 1.34 KB
/
DisplayWidget.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
//
/////////////////////////////////////////////////////////
#include <QtGui>
#include "DisplayWidget.h"
const QString DisplayWidget::Input = "in";
const QString DisplayWidget::Output = "out";
/////////////////////////////////////////////////////////
DisplayWidget::DisplayWidget(QWidget *parent) : QTextEdit(parent)
{
setReadOnly(true);
setTabChangesFocus(true);
setOverwriteMode(true);
setAlignment(Qt::AlignCenter);
resetLine();
append(tr("Welcome to the Free Group Calculator!\n"));
setAlignment(Qt::AlignLeft);
setFontFamily("Monaco");
setFontPointSize(12.0);
append(tr("[%1 %2]:>").arg(Input).arg(lineNumber));
moveCursor(QTextCursor::End);
}
/////////////////////////////////////////////////////////
//PUBLIC
void DisplayWidget::addLine(const QString &text, const QString &type)
{
QString arrow_text = text;
arrow_text.prepend(QString("[%1 %2]:> ").arg(type).arg(lineNumber));
if (type == Input) {
moveCursor(QTextCursor::End);
moveCursor(QTextCursor::StartOfLine,QTextCursor::KeepAnchor);
textCursor().removeSelectedText();
insertPlainText(arrow_text);
}
if (type == Output) {
append(arrow_text);
append("");
lineNumber++;
append(QString("[%1 %2]:> ").arg(Input).arg(lineNumber));
moveCursor(QTextCursor::End);
}
}
/////////////////////////////////////////////////////////