blob: b4fcddf249e7289e5a0365e676e6ee6f86efe8fc (
plain) (
blame)
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
|
/*
* console.cpp
*
* Created on: Jan 31, 2012
* Author: joe
*/
#include "console.h"
Console::Console(QMainWindow* parent) :
QTextEdit(parent) {
setWindowFlags(Qt::FramelessWindowHint);
// fanciness
QPalette pal;
pal.setColor(QPalette::Base, Qt::black);
setPalette(pal);
setTextColor(Qt::white);
// CTRL + D toggles debug window
QAction* _toggle = new QAction(tr("&toggleDebug"), parentWidget());
_toggle->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
parentWidget()->addAction(_toggle);
connect(_toggle, SIGNAL(triggered()), this, SLOT(toggle()));
// watcher to detect file change
QFileSystemWatcher* _watcher = new QFileSystemWatcher(this);
// read from log file
_logFile = new QFile(logFilePath);
_logFileIn = new QTextStream(_logFile);
if (!_logFile->open(QFile::ReadOnly | QFile::Text)) {
} else {
// watch log file
_watcher->addPath(logFilePath);
connect(_watcher, SIGNAL(fileChanged(const QString&)), this,
SLOT(refresh(const QString&)));
}
}
Console::~Console() {
delete _logFile;
delete _logFileIn;
}
void Console::refresh(const QString& fileName) {
if (fileName == logFilePath) {
while (!_logFileIn->atEnd()) {
QString line = _logFileIn->readLine();
if (!line.isEmpty())
this->append(line);
}
this->moveCursor(QTextCursor::End);
}
}
void Console::toggle() {
(this->isVisible()) ? this->hide() : this->show();
}
|