summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/CMakeLists.txt7
-rw-r--r--application/Colors.cpp26
-rw-r--r--application/Colors.h15
-rw-r--r--application/pages/LogPage.cpp20
4 files changed, 59 insertions, 9 deletions
diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt
index ae4c0a88..a1a91969 100644
--- a/application/CMakeLists.txt
+++ b/application/CMakeLists.txt
@@ -129,6 +129,8 @@ SET(MULTIMC_SOURCES
InstanceProxyModel.cpp
VersionProxyModel.h
VersionProxyModel.cpp
+ Colors.h
+ Colors.cpp
# GUI - windows
MainWindow.h
@@ -325,7 +327,6 @@ else()
list(APPEND MULTIMC_SOURCES Platform_Other.cpp)
endif()
-
# Link additional libraries
if(WIN32)
set(MultiMC_LINK_ADDITIONAL_LIBS ${MultiMC_LINK_ADDITIONAL_LIBS} Qt5::WinMain)
@@ -341,8 +342,8 @@ qt5_add_resources(MULTIMC_RESOURCES ${MULTIMC_QRCS})
add_executable(MultiMC MACOSX_BUNDLE WIN32 ${MULTIMC_SOURCES} ${MULTIMC_UI} ${MULTIMC_RESOURCES} ${MULTIMC_RCS})
target_link_libraries(MultiMC MultiMC_logic xz-embedded unpack200 iconfix libUtil LogicalGui
${QUAZIP_LIBRARIES} Qt5::Core Qt5::Xml Qt5::Widgets Qt5::Network Qt5::Concurrent
- hoedown
- ${MultiMC_LINK_ADDITIONAL_LIBS})
+ hoedown rainbow
+ ${MultiMC_LINK_ADDITIONAL_LIBS})
################################ INSTALLATION AND PACKAGING ################################
diff --git a/application/Colors.cpp b/application/Colors.cpp
new file mode 100644
index 00000000..8812c93d
--- /dev/null
+++ b/application/Colors.cpp
@@ -0,0 +1,26 @@
+#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
new file mode 100644
index 00000000..8825f39f
--- /dev/null
+++ b/application/Colors.h
@@ -0,0 +1,15 @@
+#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 77d5d6b8..280f64d0 100644
--- a/application/pages/LogPage.cpp
+++ b/application/pages/LogPage.cpp
@@ -10,6 +10,7 @@
#include "launch/LaunchTask.h"
#include <settings/Setting.h>
#include "GuiUtil.h"
+#include <Colors.h>
LogPage::LogPage(std::shared_ptr<LaunchTask> proc, QWidget *parent)
: QWidget(parent), ui(new Ui::LogPage), m_process(proc)
@@ -203,31 +204,38 @@ 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:
{
- format.setForeground(QColor("blue"));
+ foreground(QColor("purple"));
break;
}
case MessageLevel::Debug:
{
- format.setForeground(QColor("green"));
+ foreground(QColor("green"));
break;
}
case MessageLevel::Warning:
{
- format.setForeground(QColor("orange"));
+ foreground(QColor("orange"));
break;
}
case MessageLevel::Error:
{
- format.setForeground(QColor("red"));
+ foreground(QColor("red"));
break;
}
case MessageLevel::Fatal:
{
- format.setForeground(QColor("red"));
+ origBackground = QColor("black");
+ foreground(QColor("red"));
format.setBackground(QColor("black"));
break;
}
@@ -235,7 +243,7 @@ void LogPage::write(QString data, MessageLevel::Enum mode)
case MessageLevel::Message:
default:
{
- // do nothing, keep original
+ foreground(QColor("black"));
}
}