summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-28 20:07:57 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-28 20:16:52 (GMT)
commit5c2567847c73f6095206dfbd451fe2f26f4056aa (patch)
tree06a9ed263bec86531bd08b89242c78b3aeb0d8a0 /Swift/QtUI
parent85dcc894ccf417ec8b057d868afb1d8006634ac4 (diff)
downloadswift-5c2567847c73f6095206dfbd451fe2f26f4056aa.zip
swift-5c2567847c73f6095206dfbd451fe2f26f4056aa.tar.bz2
Implemented XML console.
Resolves: #135
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtXMLConsoleWidget.cpp46
-rw-r--r--Swift/QtUI/QtXMLConsoleWidget.h22
2 files changed, 63 insertions, 5 deletions
diff --git a/Swift/QtUI/QtXMLConsoleWidget.cpp b/Swift/QtUI/QtXMLConsoleWidget.cpp
index 7553d06..662f070 100644
--- a/Swift/QtUI/QtXMLConsoleWidget.cpp
+++ b/Swift/QtUI/QtXMLConsoleWidget.cpp
@@ -1,10 +1,37 @@
#include "QtXMLConsoleWidget.h"
#include <QCloseEvent>
+#include <QTextEdit>
+#include <QVBoxLayout>
+#include <QPushButton>
+#include <QScrollBar>
+
+#include "QtSwiftUtil.h"
+#include "Swiften/Base/String.h"
namespace Swift {
+
QtXMLConsoleWidget::QtXMLConsoleWidget() {
+ setWindowTitle("Console");
+
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ layout->setSpacing(0);
+ layout->setContentsMargins(0,0,0,0);
+ textEdit = new QTextEdit(this);
+ textEdit->setReadOnly(true);
+ layout->addWidget(textEdit);
+
+ QWidget* bottom = new QWidget(this);
+ layout->addWidget(bottom);
+
+ QHBoxLayout* buttonLayout = new QHBoxLayout(bottom);
+ buttonLayout->setContentsMargins(0,0,20,0);
+ buttonLayout->setSpacing(0);
+ buttonLayout->addStretch();
+ QPushButton* clearButton = new QPushButton("Clear", bottom);
+ connect(clearButton, SIGNAL(clicked()), textEdit, SLOT(clear()));
+ buttonLayout->addWidget(clearButton);
}
void QtXMLConsoleWidget::showEvent(QShowEvent* event) {
@@ -26,4 +53,23 @@ void QtXMLConsoleWidget::closeEvent(QCloseEvent* event) {
event->accept();
}
+void QtXMLConsoleWidget::handleDataRead(const String& data) {
+ textEdit->setTextColor(QColor(33,98,33));
+ appendText(data);
+}
+
+void QtXMLConsoleWidget::handleDataWritten(const String& data) {
+ textEdit->setTextColor(QColor(155,1,0));
+ appendText(data);
+}
+
+void QtXMLConsoleWidget::appendText(const String& data) {
+ QScrollBar* scrollBar = textEdit->verticalScrollBar();
+ bool scrollToBottom = (!scrollBar || scrollBar->value() == scrollBar->maximum());
+ textEdit->append(P2QSTRING(data));
+ if (scrollToBottom) {
+ textEdit->ensureCursorVisible();
+ }
+}
+
}
diff --git a/Swift/QtUI/QtXMLConsoleWidget.h b/Swift/QtUI/QtXMLConsoleWidget.h
index 50b53f2..0d5a10d 100644
--- a/Swift/QtUI/QtXMLConsoleWidget.h
+++ b/Swift/QtUI/QtXMLConsoleWidget.h
@@ -3,16 +3,28 @@
#include "Swift/Controllers/UIInterfaces/XMLConsoleWidget.h"
#include "QtTabbable.h"
+class QTextEdit;
+
namespace Swift {
class QtXMLConsoleWidget : public QtTabbable, public XMLConsoleWidget {
- Q_OBJECT
+ Q_OBJECT
+
public:
QtXMLConsoleWidget();
+
void show();
void activate();
- protected slots:
- void closeEvent(QCloseEvent* event);
- protected:
- void showEvent(QShowEvent* event);
+
+ virtual void handleDataRead(const String& data);
+ virtual void handleDataWritten(const String& data);
+
+ private:
+ virtual void closeEvent(QCloseEvent* event);
+ virtual void showEvent(QShowEvent* event);
+
+ void appendText(const String& data);
+
+ private:
+ QTextEdit* textEdit;
};
}