summaryrefslogtreecommitdiffstats
path: root/src/fbgui/console.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fbgui/console.cpp')
-rw-r--r--src/fbgui/console.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/fbgui/console.cpp b/src/fbgui/console.cpp
new file mode 100644
index 0000000..b4fcddf
--- /dev/null
+++ b/src/fbgui/console.cpp
@@ -0,0 +1,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();
+}