summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/consolewindow.cpp73
-rw-r--r--gui/consolewindow.h69
-rw-r--r--gui/consolewindow.ui66
3 files changed, 208 insertions, 0 deletions
diff --git a/gui/consolewindow.cpp b/gui/consolewindow.cpp
new file mode 100644
index 00000000..1d84fe04
--- /dev/null
+++ b/gui/consolewindow.cpp
@@ -0,0 +1,73 @@
+#include "consolewindow.h"
+#include "ui_consolewindow.h"
+
+#include <QScrollBar>
+
+ConsoleWindow::ConsoleWindow(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::ConsoleWindow),
+ m_mayclose(true)
+{
+ ui->setupUi(this);
+}
+
+ConsoleWindow::~ConsoleWindow()
+{
+ delete ui;
+}
+
+void ConsoleWindow::writeColor(QString text, const char *color)
+{
+ // append a paragraph
+ if (color != nullptr)
+ ui->text->appendHtml(QString("<font color=%1>%2</font>").arg(color).arg(text));
+ else
+ ui->text->appendPlainText(text);
+ // scroll down
+ QScrollBar *bar = ui->text->verticalScrollBar();
+ bar->setValue(bar->maximum());
+}
+
+void ConsoleWindow::write(QString data, WriteMode mode)
+{
+ if (data.endsWith('\n'))
+ data = data.left(data.length()-1);
+ QStringList paragraphs = data.split('\n');
+ QListIterator<QString> iter(paragraphs);
+ if (mode == MULTIMC)
+ while(iter.hasNext())
+ writeColor(iter.next(), "blue");
+ else if (mode == ERROR)
+ while(iter.hasNext())
+ writeColor(iter.next(), "red");
+ else
+ while(iter.hasNext())
+ writeColor(iter.next());
+}
+
+void ConsoleWindow::clear()
+{
+ ui->text->clear();
+}
+
+void ConsoleWindow::on_closeButton_clicked()
+{
+ close();
+}
+
+void ConsoleWindow::setMayClose(bool mayclose)
+{
+ m_mayclose = mayclose;
+ if (mayclose)
+ ui->closeButton->setEnabled(true);
+ else
+ ui->closeButton->setEnabled(false);
+}
+
+void ConsoleWindow::closeEvent(QCloseEvent * event)
+{
+ if(!m_mayclose)
+ event->ignore();
+ else
+ QDialog::closeEvent(event);
+}
diff --git a/gui/consolewindow.h b/gui/consolewindow.h
new file mode 100644
index 00000000..1d322afb
--- /dev/null
+++ b/gui/consolewindow.h
@@ -0,0 +1,69 @@
+#ifndef CONSOLEWINDOW_H
+#define CONSOLEWINDOW_H
+
+#include <QDialog>
+
+namespace Ui {
+class ConsoleWindow;
+}
+
+class ConsoleWindow : public QDialog
+{
+ Q_OBJECT
+
+public:
+ /**
+ * @brief The WriteMode enum
+ * defines how stuff is displayed
+ */
+ enum WriteMode {
+ DEFAULT,
+ ERROR,
+ MULTIMC
+ };
+
+ explicit ConsoleWindow(QWidget *parent = 0);
+ ~ConsoleWindow();
+
+ /**
+ * @brief specify if the window is allowed to close
+ * @param mayclose
+ * used to keep it alive while MC runs
+ */
+ void setMayClose(bool mayclose);
+
+public slots:
+ /**
+ * @brief write a string
+ * @param data the string
+ * @param mode the WriteMode
+ * lines have to be put through this as a whole!
+ */
+ void write(QString data, WriteMode mode=MULTIMC);
+
+ /**
+ * @brief write a colored paragraph
+ * @param data the string
+ * @param color the css color name
+ * this will only insert a single paragraph.
+ * \n are ignored. a real \n is always appended.
+ */
+ void writeColor(QString data, const char *color=nullptr);
+
+ /**
+ * @brief clear the text widget
+ */
+ void clear();
+
+private slots:
+ void on_closeButton_clicked();
+
+protected:
+ void closeEvent(QCloseEvent *);
+
+private:
+ Ui::ConsoleWindow *ui;
+ bool m_mayclose;
+};
+
+#endif // CONSOLEWINDOW_H
diff --git a/gui/consolewindow.ui b/gui/consolewindow.ui
new file mode 100644
index 00000000..f8c87aa0
--- /dev/null
+++ b/gui/consolewindow.ui
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ConsoleWindow</class>
+ <widget class="QDialog" name="ConsoleWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>400</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MultiMC Console</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QPlainTextEdit" name="text">
+ <property name="font">
+ <font>
+ <pointsize>10</pointsize>
+ </font>
+ </property>
+ <property name="undoRedoEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="plainText">
+ <string notr="true"/>
+ </property>
+ <property name="centerOnScroll">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="closeButton">
+ <property name="text">
+ <string>Close</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>