summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/CMakeLists.txt4
-rw-r--r--application/ColorCache.cpp35
-rw-r--r--application/ColorCache.h119
-rw-r--r--application/Colors.cpp26
-rw-r--r--application/Colors.h15
-rw-r--r--application/pages/LogPage.cpp50
-rw-r--r--application/pages/LogPage.h2
-rw-r--r--application/pages/global/MultiMCPage.cpp9
-rw-r--r--application/pages/global/MultiMCPage.h3
9 files changed, 175 insertions, 88 deletions
diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt
index a1a91969..90bb0c04 100644
--- a/application/CMakeLists.txt
+++ b/application/CMakeLists.txt
@@ -129,8 +129,8 @@ SET(MULTIMC_SOURCES
InstanceProxyModel.cpp
VersionProxyModel.h
VersionProxyModel.cpp
- Colors.h
- Colors.cpp
+ ColorCache.h
+ ColorCache.cpp
# GUI - windows
MainWindow.h
diff --git a/application/ColorCache.cpp b/application/ColorCache.cpp
new file mode 100644
index 00000000..e216b597
--- /dev/null
+++ b/application/ColorCache.cpp
@@ -0,0 +1,35 @@
+#include "ColorCache.h"
+
+
+/**
+ * Blend the color with the front color, adapting to the back color
+ */
+QColor ColorCache::blend(QColor color)
+{
+ if (Rainbow::luma(m_front) > Rainbow::luma(m_back))
+ {
+ // for dark color schemes, produce a fitting color first
+ color = Rainbow::tint(m_front, color, 0.5);
+ }
+ // adapt contrast
+ return Rainbow::mix(m_front, color, m_bias);
+}
+
+/**
+ * Blend the color with the back color
+ */
+QColor ColorCache::blendBackground(QColor color)
+{
+ // adapt contrast
+ return Rainbow::mix(m_back, color, m_bias);
+}
+
+void ColorCache::recolorAll()
+{
+ auto iter = m_colors.begin();
+ while(iter != m_colors.end())
+ {
+ iter->front = blend(iter->original);
+ iter->back = blendBackground(iter->original);
+ }
+}
diff --git a/application/ColorCache.h b/application/ColorCache.h
new file mode 100644
index 00000000..9d5ad02b
--- /dev/null
+++ b/application/ColorCache.h
@@ -0,0 +1,119 @@
+#pragma once
+#include <QtGui/QColor>
+#include <rainbow.h>
+#include <launch/MessageLevel.h>
+#include <QMap>
+
+class ColorCache
+{
+public:
+ ColorCache(QColor front, QColor back, qreal bias)
+ {
+ m_front = front;
+ m_back = back;
+ m_bias = bias;
+ };
+
+ void addColor(int key, QColor color)
+ {
+ m_colors[key] = {color, blend(color), blendBackground(color)};
+ }
+
+ void setForeground(QColor front)
+ {
+ if(m_front != front)
+ {
+ m_front = front;
+ recolorAll();
+ }
+ }
+
+ void setBackground(QColor back)
+ {
+ if(m_back != back)
+ {
+ m_back = back;
+ recolorAll();
+ }
+ }
+
+ QColor getFront(int key)
+ {
+ auto iter = m_colors.find(key);
+ if(iter == m_colors.end())
+ {
+ return QColor();
+ }
+ return (*iter).front;
+ }
+
+ QColor getBack(int key)
+ {
+ auto iter = m_colors.find(key);
+ if(iter == m_colors.end())
+ {
+ return QColor();
+ }
+ return (*iter).back;
+ }
+
+ /**
+ * Blend the color with the front color, adapting to the back color
+ */
+ QColor blend(QColor color);
+
+ /**
+ * Blend the color with the back color
+ */
+ QColor blendBackground(QColor color);
+
+protected:
+ void recolorAll();
+
+protected:
+ struct ColorEntry
+ {
+ QColor original;
+ QColor front;
+ QColor back;
+ };
+
+protected:
+ qreal m_bias;
+ QColor m_front;
+ QColor m_back;
+ QMap<int, ColorEntry> m_colors;
+};
+
+class LogColorCache : public ColorCache
+{
+public:
+ LogColorCache(QColor front, QColor back)
+ : ColorCache(front, back, 1.0)
+ {
+ addColor((int)MessageLevel::MultiMC, QColor("purple"));
+ addColor((int)MessageLevel::Debug, QColor("green"));
+ addColor((int)MessageLevel::Warning, QColor("orange"));
+ addColor((int)MessageLevel::Error, QColor("red"));
+ addColor((int)MessageLevel::Fatal, QColor("red"));
+ addColor((int)MessageLevel::Message, front);
+ }
+
+ QColor getFront(MessageLevel::Enum level)
+ {
+ if(!m_colors.contains((int) level))
+ {
+ return ColorCache::getFront((int)MessageLevel::Message);
+ }
+ return ColorCache::getFront((int)level);
+ }
+
+ QColor getBack(MessageLevel::Enum level)
+ {
+ if(level == MessageLevel::Fatal)
+ {
+ return QColor(Qt::black);
+ }
+ return QColor(Qt::transparent);
+ }
+};
diff --git a/application/Colors.cpp b/application/Colors.cpp
deleted file mode 100644
index 8812c93d..00000000
--- a/application/Colors.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "Colors.h"
-
-/**
- * Blend the color with the front color, adapting to the back color
- */
-QColor Color::blend(QColor front, QColor back, QColor color, uchar ratio)
-{
- Q_ASSERT(front.isValid());
- Q_ASSERT(back.isValid());
- if (Rainbow::luma(front) > Rainbow::luma(back))
- {
- // for dark color schemes, produce a fitting color first
- color = Rainbow::tint(front, color, 0.5);
- }
- // adapt contrast
- return Rainbow::mix(front, color, float(ratio) / float(0xff));
-}
-
-/**
- * Blend the color with the back color
- */
-QColor Color::blendBackground(QColor back, QColor color, uchar ratio)
-{
- // adapt contrast
- return Rainbow::mix(back, color, float(ratio) / float(0xff));
-}
diff --git a/application/Colors.h b/application/Colors.h
deleted file mode 100644
index 8825f39f..00000000
--- a/application/Colors.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-#include <QtGui/QColor>
-#include <rainbow.h>
-namespace Color
-{
-/**
- * Blend the color with the front color, adapting to the back color
- */
-QColor blend(QColor front, QColor back, QColor color, uchar ratio);
-
-/**
- * Blend the color with the back color
- */
-QColor blendBackground(QColor back, QColor color, uchar ratio);
-}
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 <settings/Setting.h>
#include "GuiUtil.h"
-#include <Colors.h>
+#include <ColorCache.h>
LogPage::LogPage(std::shared_ptr<LaunchTask> proc, QWidget *parent)
: QWidget(parent), ui(new Ui::LogPage), m_process(proc)
@@ -41,6 +41,10 @@ LogPage::LogPage(std::shared_ptr<LaunchTask> 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<QString> 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 <MultiMC.h>
+#include <ColorCache.h>
namespace Ui
{
@@ -86,4 +87,5 @@ private:
QTextCharFormat * defaultFormat;
BasePageContainer * m_parentContainer;
+ std::unique_ptr<LogColorCache> 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 <MultiMC.h>
+#include "ColorCache.h"
class QTextCharFormat;
class SettingsObject;
@@ -97,4 +98,6 @@ private:
// default format for the font preview...
QTextCharFormat *defaultFormat;
+
+ std::unique_ptr<LogColorCache> m_colors;
};