summaryrefslogtreecommitdiffstats
path: root/gui/pages
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-11-09 14:53:08 +0100
committerPetr Mrázek <peterix@gmail.com>2014-11-09 14:53:08 +0100
commit2e9284951c7364dc766a406099ce3a779773abb1 (patch)
tree67c5ac688edc42027e7815bd1d5614c3d1458a9f /gui/pages
parentf9a7c1cf216a464c922ca47a60a6f44ebd7decc9 (diff)
downloadMultiMC-2e9284951c7364dc766a406099ce3a779773abb1.tar
MultiMC-2e9284951c7364dc766a406099ce3a779773abb1.tar.gz
MultiMC-2e9284951c7364dc766a406099ce3a779773abb1.tar.lz
MultiMC-2e9284951c7364dc766a406099ce3a779773abb1.tar.xz
MultiMC-2e9284951c7364dc766a406099ce3a779773abb1.zip
Improve log formatting
* Updated log level detection for current Minecraft versions * Better formatting: using a monospaced font and raw text instead of HTML (fixes #111)
Diffstat (limited to 'gui/pages')
-rw-r--r--gui/pages/LogPage.cpp101
-rw-r--r--gui/pages/LogPage.h12
2 files changed, 63 insertions, 50 deletions
diff --git a/gui/pages/LogPage.cpp b/gui/pages/LogPage.cpp
index 636d2695..f16e3477 100644
--- a/gui/pages/LogPage.cpp
+++ b/gui/pages/LogPage.cpp
@@ -16,6 +16,14 @@ LogPage::LogPage(MinecraftProcess *proc, QWidget *parent)
connect(m_process, SIGNAL(log(QString, MessageLevel::Enum)), this,
SLOT(write(QString, MessageLevel::Enum)));
+ // create the format and set its font
+ defaultFormat = new QTextCharFormat(ui->text->currentCharFormat());
+ QFont font;
+ font.setFamily("Courier");
+ font.setStyleHint(QFont::Monospace);
+ font.setFixedPitch(true);
+ defaultFormat->setFont(font);
+
auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this);
connect(findShortcut, SIGNAL(activated()), SLOT(findActivated()));
auto findNextShortcut = new QShortcut(QKeySequence(QKeySequence::FindNext), this);
@@ -28,6 +36,7 @@ LogPage::LogPage(MinecraftProcess *proc, QWidget *parent)
LogPage::~LogPage()
{
delete ui;
+ delete defaultFormat;
}
bool LogPage::apply()
@@ -107,24 +116,6 @@ void LogPage::findPreviousActivated()
}
}
-void LogPage::writeColor(QString text, const char *color, const char *background)
-{
- // append a paragraph
- QString newtext;
- newtext += "<span style=\"";
- {
- if (color)
- newtext += QString("color:") + color + ";";
- if (background)
- newtext += QString("background-color:") + background + ";";
- newtext += "font-family: monospace;";
- }
- newtext += "\">";
- newtext += text.toHtmlEscaped();
- newtext += "</span>";
- ui->text->appendHtml(newtext);
-}
-
void LogPage::write(QString data, MessageLevel::Enum mode)
{
if (!m_write_active)
@@ -159,31 +150,59 @@ void LogPage::write(QString data, MessageLevel::Enum mode)
for (QString &paragraph : paragraphs)
{
//TODO: implement filtering here.
- filtered.append(paragraph.trimmed());
+ filtered.append(paragraph);
}
QListIterator<QString> iter(filtered);
- if (mode == MessageLevel::MultiMC)
- while (iter.hasNext())
- writeColor(iter.next(), "blue", 0);
- else if (mode == MessageLevel::Error)
- while (iter.hasNext())
- writeColor(iter.next(), "red", 0);
- else if (mode == MessageLevel::Warning)
- while (iter.hasNext())
- writeColor(iter.next(), "orange", 0);
- else if (mode == MessageLevel::Fatal)
- while (iter.hasNext())
- writeColor(iter.next(), "red", "black");
- else if (mode == MessageLevel::Debug)
- while (iter.hasNext())
- writeColor(iter.next(), "green", 0);
- else if (mode == MessageLevel::PrePost)
- while (iter.hasNext())
- writeColor(iter.next(), "grey", 0);
- // TODO: implement other MessageLevels
- else
- while (iter.hasNext())
- writeColor(iter.next(), 0, 0);
+ QTextCharFormat format(*defaultFormat);
+
+ switch(mode)
+ {
+ case MessageLevel::MultiMC:
+ {
+ format.setForeground(QColor("blue"));
+ break;
+ }
+ case MessageLevel::Debug:
+ {
+ format.setForeground(QColor("green"));
+ break;
+ }
+ case MessageLevel::Warning:
+ {
+ format.setForeground(QColor("orange"));
+ break;
+ }
+ case MessageLevel::Error:
+ {
+ format.setForeground(QColor("red"));
+ break;
+ }
+ case MessageLevel::Fatal:
+ {
+ format.setForeground(QColor("red"));
+ format.setBackground(QColor("black"));
+ }
+ case MessageLevel::PrePost:
+ {
+ format.setForeground(QColor("grey"));
+ }
+ case MessageLevel::Info:
+ case MessageLevel::Message:
+ default:
+ {
+ // do nothing, keep original
+ }
+ }
+
+ while (iter.hasNext())
+ {
+ // append a paragraph/line
+ auto workCursor = ui->text->textCursor();
+ workCursor.movePosition(QTextCursor::End);
+ workCursor.insertText(iter.next(), format);
+ workCursor.insertBlock();
+ }
+
if (isVisible())
{
if (m_scroll_active)
diff --git a/gui/pages/LogPage.h b/gui/pages/LogPage.h
index 3c86724e..468dcf79 100644
--- a/gui/pages/LogPage.h
+++ b/gui/pages/LogPage.h
@@ -28,6 +28,7 @@ namespace Ui
{
class LogPage;
}
+class QTextCharFormat;
class LogPage : public QWidget, public BasePage
{
@@ -55,15 +56,6 @@ public:
}
virtual bool shouldDisplay() const;
-private:
- /**
- * @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 text, const char *color, const char *background);
private slots:
/**
* @brief write a string
@@ -90,4 +82,6 @@ private:
bool m_scroll_active = true;
int m_saved_offset = 0;
bool m_write_active = true;
+
+ QTextCharFormat * defaultFormat;
};