From d0e88011dc025a1e68964a9363cece66c677969f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 20 Aug 2015 01:49:03 +0200 Subject: GH-1197 finish color stuff --- application/pages/LogPage.cpp | 50 +++++--------------------------- application/pages/LogPage.h | 2 ++ application/pages/global/MultiMCPage.cpp | 9 ++++-- application/pages/global/MultiMCPage.h | 3 ++ 4 files changed, 19 insertions(+), 45 deletions(-) (limited to 'application/pages') diff --git a/application/pages/LogPage.cpp b/application/pages/LogPage.cpp index 280f64d0..892ba324 100644 --- a/application/pages/LogPage.cpp +++ b/application/pages/LogPage.cpp @@ -10,7 +10,7 @@ #include "launch/LaunchTask.h" #include #include "GuiUtil.h" -#include +#include LogPage::LogPage(std::shared_ptr proc, QWidget *parent) : QWidget(parent), ui(new Ui::LogPage), m_process(proc) @@ -41,6 +41,10 @@ LogPage::LogPage(std::shared_ptr proc, QWidget *parent) } ui->text->setMaximumBlockCount(maxLines); + auto origForeground = ui->text->palette().color(ui->text->foregroundRole()); + auto origBackground = ui->text->palette().color(ui->text->backgroundRole()); + m_colors.reset(new LogColorCache(origForeground, origBackground)); + m_stopOnOverflow = MMC->settings()->get("ConsoleOverflowStop").toBool(); auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this); @@ -204,48 +208,8 @@ void LogPage::write(QString data, MessageLevel::Enum mode) QListIterator iter(filtered); QTextCharFormat format(*defaultFormat); - auto origForeground = ui->text->palette().color(ui->text->foregroundRole()); - auto origBackground = ui->text->palette().color(ui->text->backgroundRole()); - auto foreground = [&](QColor foreColor) - { - format.setForeground(Color::blend(origForeground, origBackground, foreColor, 255)); - }; - switch(mode) - { - case MessageLevel::MultiMC: - { - foreground(QColor("purple")); - break; - } - case MessageLevel::Debug: - { - foreground(QColor("green")); - break; - } - case MessageLevel::Warning: - { - foreground(QColor("orange")); - break; - } - case MessageLevel::Error: - { - foreground(QColor("red")); - break; - } - case MessageLevel::Fatal: - { - origBackground = QColor("black"); - foreground(QColor("red")); - format.setBackground(QColor("black")); - break; - } - case MessageLevel::Info: - case MessageLevel::Message: - default: - { - foreground(QColor("black")); - } - } + format.setForeground(m_colors->getFront(mode)); + format.setBackground(m_colors->getBack(mode)); while (iter.hasNext()) { diff --git a/application/pages/LogPage.h b/application/pages/LogPage.h index f2cd90c3..169319a3 100644 --- a/application/pages/LogPage.h +++ b/application/pages/LogPage.h @@ -21,6 +21,7 @@ #include "launch/LaunchTask.h" #include "BasePage.h" #include +#include namespace Ui { @@ -86,4 +87,5 @@ private: QTextCharFormat * defaultFormat; BasePageContainer * m_parentContainer; + std::unique_ptr m_colors; }; diff --git a/application/pages/global/MultiMCPage.cpp b/application/pages/global/MultiMCPage.cpp index b5389e25..6a8730c7 100644 --- a/application/pages/global/MultiMCPage.cpp +++ b/application/pages/global/MultiMCPage.cpp @@ -40,6 +40,10 @@ enum InstSortMode MultiMCPage::MultiMCPage(QWidget *parent) : QWidget(parent), ui(new Ui::MultiMCPage) { ui->setupUi(this); + auto origForeground = ui->fontPreview->palette().color(ui->fontPreview->foregroundRole()); + auto origBackground = ui->fontPreview->palette().color(ui->fontPreview->backgroundRole()); + m_colors.reset(new LogColorCache(origForeground, origBackground)); + ui->sortingModeGroup->setId(ui->sortByNameBtn, Sort_Name); ui->sortingModeGroup->setId(ui->sortLastLaunchedBtn, Sort_LastLaunch); @@ -424,7 +428,7 @@ void MultiMCPage::refreshFontPreview() defaultFormat->setFont(QFont(fontFamily, fontSize)); { QTextCharFormat format(*defaultFormat); - format.setForeground(QColor("red")); + format.setForeground(m_colors->getFront(MessageLevel::Error)); // append a paragraph/line auto workCursor = ui->fontPreview->textCursor(); workCursor.movePosition(QTextCursor::End); @@ -433,6 +437,7 @@ void MultiMCPage::refreshFontPreview() } { QTextCharFormat format(*defaultFormat); + format.setForeground(m_colors->getFront(MessageLevel::Message)); // append a paragraph/line auto workCursor = ui->fontPreview->textCursor(); workCursor.movePosition(QTextCursor::End); @@ -441,7 +446,7 @@ void MultiMCPage::refreshFontPreview() } { QTextCharFormat format(*defaultFormat); - format.setForeground(QColor("orange")); + format.setForeground(m_colors->getFront(MessageLevel::Warning)); // append a paragraph/line auto workCursor = ui->fontPreview->textCursor(); workCursor.movePosition(QTextCursor::End); diff --git a/application/pages/global/MultiMCPage.h b/application/pages/global/MultiMCPage.h index d90acc13..4ecc2d93 100644 --- a/application/pages/global/MultiMCPage.h +++ b/application/pages/global/MultiMCPage.h @@ -21,6 +21,7 @@ #include "java/JavaChecker.h" #include "pages/BasePage.h" #include +#include "ColorCache.h" class QTextCharFormat; class SettingsObject; @@ -97,4 +98,6 @@ private: // default format for the font preview... QTextCharFormat *defaultFormat; + + std::unique_ptr m_colors; }; -- cgit v1.2.3