GH-1197 add console log color adaptation

rainbow library was part of KDE - KGuiAddons
This commit is contained in:
Petr Mrázek
2015-08-19 02:06:32 +02:00
parent 9681f724e5
commit 6858f1dd62
10 changed files with 630 additions and 9 deletions

View File

@ -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 ################################

26
application/Colors.cpp Normal file
View File

@ -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));
}

15
application/Colors.h Normal file
View File

@ -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);
}

View File

@ -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"));
}
}