-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtab.cpp
More file actions
78 lines (65 loc) · 1.94 KB
/
Copy pathtab.cpp
File metadata and controls
78 lines (65 loc) · 1.94 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
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
#include "tab.h"
Tab::Tab(QWidget *parent) :
QMainWindow(parent),
code(new CodeEditor()),
currentFilePath(""),
settings("IDE65xx Project", "IDE65xx")
{
code->setWordWrapMode(QTextOption::NoWrap);
connect(code->document(), SIGNAL(blockCountChanged(int)), this, SLOT(blockCountChanged(int)));
setCentralWidget(code);
setFonts();
restoreGeometry(settings.value("tabgeometry").toByteArray());
restoreState(settings.value("tabwindowstate").toByteArray());
}
void Tab::setFonts()
{
QFont codeFont;
codeFont.setPointSize(settings.value("fontsize", 12).toInt());
codeFont.setFamily(settings.value("fontfamily", QString("Ubuntu Mono")).value<QString>());
codeFont.setStyleHint(QFont::Monospace);
code->setFont(codeFont);
}
void Tab::blockCountChanged(int newBlockCount)
{
emit code->updateLineNumber(code->textCursor().blockNumber()+1, newBlockCount - oldBlockCount);
oldBlockCount = newBlockCount;
}
QTextDocument * Tab::getCodeDocument()
{
return code->document();
}
QString Tab::getCurrentFilePath()
{
return currentFilePath;
}
void Tab::saveCodeToFile(const QString &filePath, bool changeCodeModifiedFlag)
{
QFile outfile;
outfile.setFileName(filePath);
outfile.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&outfile);
out << code->toPlainText();
if (changeCodeModifiedFlag) {
currentFilePath = filePath;
getCodeDocument()->setModified(false);
}
outfile.close();
}
bool Tab::loadCodeFromFile(const QString &filePath)
{
QFile file;
file.setFileName(filePath);
if(!file.open(QIODevice::ReadOnly)) return false;
QTextStream text(&file);
QString source = text.readAll();
code->setPlainText(source);
currentFilePath = filePath;
code->document()->setModified(false);
file.close();
return true;
}
Tab::~Tab()
{
delete code;
}