Qt: add log colors to stylesheet

and silence some compiler warnings
This commit is contained in:
Megamouse 2017-09-20 22:25:10 +02:00 committed by Ivan
parent ca36d08893
commit 0b51102167
5 changed files with 64 additions and 27 deletions

View File

@ -315,6 +315,22 @@ void rpcs3_app::OnChangeStyleSheetRequest(const QString& sheetFilePath)
"QLabel#gamelist_icon_background_color { color: " + rgba(GUI::gl_icon_color) + " }"
);
// log stylesheet
QString style_log = QString
(
"QTextEdit#tty_frame { background-color: #ffffff; }"
"QTextEdit#log_frame { background-color: #ffffff; }"
"QLabel#log_level_always { color: #107896; }"
"QLabel#log_level_fatal { color: #ff00ff; }"
"QLabel#log_level_error { color: #C02F1D; }"
"QLabel#log_level_todo { color: #ff6000; }"
"QLabel#log_level_success { color: #008000; }"
"QLabel#log_level_warning { color: #BA8745; }"
"QLabel#log_level_notice { color: #000000; }"
"QLabel#log_level_trace { color: #808080; }"
"QLabel#log_stack { color: #000000; }"
);
// other objects' stylesheet
QString style_rest = QString
(
@ -323,7 +339,7 @@ void rpcs3_app::OnChangeStyleSheetRequest(const QString& sheetFilePath)
"QLabel#gamegrid_font { font-weight: 600; font-size: 8pt; font-family: Lucida Grande; color: rgba(51, 51, 51, 255); }"
);
setStyleSheet(style_toolbar + style_toolbar_icons + style_thumbnail_icons + style_gamelist_toolbar + style_gamelist_icons + style_rest);
setStyleSheet(style_toolbar + style_toolbar_icons + style_thumbnail_icons + style_gamelist_toolbar + style_gamelist_icons + style_log + style_rest);
}
else if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{

View File

@ -105,17 +105,12 @@ log_frame::log_frame(std::shared_ptr<gui_settings> guiSettings, QWidget *parent)
QTabWidget* tabWidget = new QTabWidget;
m_log = new QTextEdit(tabWidget);
QPalette logPalette = m_log->palette();
logPalette.setColor(QPalette::Base, Qt::black);
m_log->setPalette(logPalette);
m_log->setObjectName("log_frame");
m_log->setReadOnly(true);
m_log->setContextMenuPolicy(Qt::CustomContextMenu);
m_tty = new QTextEdit(tabWidget);
QPalette ttyPalette = m_log->palette();
ttyPalette.setColor(QPalette::Base, Qt::black);
ttyPalette.setColor(QPalette::Text, Qt::white);
m_tty->setPalette(ttyPalette);
m_log->setObjectName("tty_frame");
m_tty->setReadOnly(true);
tabWidget->addTab(m_log, tr("Log"));
@ -264,6 +259,21 @@ void log_frame::LoadSettings()
m_stackAct->setChecked(m_stack_log);
}
void log_frame::RepaintTextColors()
{
// Get text color. Do this once to prevent possible slowdown
m_color.clear();
m_color.append(GUI::get_Label_Color("log_level_always"));
m_color.append(GUI::get_Label_Color("log_level_fatal"));
m_color.append(GUI::get_Label_Color("log_level_error"));
m_color.append(GUI::get_Label_Color("log_level_todo"));
m_color.append(GUI::get_Label_Color("log_level_success"));
m_color.append(GUI::get_Label_Color("log_level_warning"));
m_color.append(GUI::get_Label_Color("log_level_notice"));
m_color.append(GUI::get_Label_Color("log_level_trace"));
m_color_stack = GUI::get_Label_Color("log_stack");
}
void log_frame::UpdateUI()
{
std::vector<char> buf(4096);
@ -320,14 +330,14 @@ void log_frame::UpdateUI()
QString text;
switch (packet->sev)
{
case logs::level::always: color = QColor(0x00, 0xFF, 0xFF); break; // Cyan
case logs::level::fatal: text = "F "; color = QColor(0xFF, 0x00, 0xFF); break; // Fuchsia
case logs::level::error: text = "E "; color = QColor(0xFF, 0x00, 0x00); break; // Red
case logs::level::todo: text = "U "; color = QColor(0xFF, 0x60, 0x00); break; // Orange
case logs::level::success: text = "S "; color = QColor(0x00, 0xFF, 0x00); break; // Green
case logs::level::warning: text = "W "; color = QColor(0xFF, 0xFF, 0x00); break; // Yellow
case logs::level::notice: text = "! "; color = QColor(0xFF, 0xFF, 0xFF); break; // White
case logs::level::trace: text = "T "; color = QColor(0x80, 0x80, 0x80); break; // Gray
case logs::level::always: break;
case logs::level::fatal: text = "F "; break;
case logs::level::error: text = "E "; break;
case logs::level::todo: text = "U "; break;
case logs::level::success: text = "S "; break;
case logs::level::warning: text = "W "; break;
case logs::level::notice: text = "! "; break;
case logs::level::trace: text = "T "; break;
default: continue;
}
@ -374,13 +384,13 @@ void log_frame::UpdateUI()
}
// add actual log message
m_log->setTextColor(color);
m_log->setTextColor(m_color[static_cast<int>(packet->sev)]);
m_log->append(text);
// add counter suffix if needed
if (m_stack_log && isSame)
{
m_log->setTextColor(Qt::white);
m_log->setTextColor(m_color_stack);
m_log->insertPlainText(suffix);
}

View File

@ -22,6 +22,10 @@ public:
/** Loads from settings. Public so that main_window can call this easily. */
void LoadSettings();
/** Repaint log colors after new stylesheet was applied */
void RepaintTextColors();
Q_SIGNALS:
void LogFrameClosed();
protected:
@ -35,6 +39,8 @@ private:
void CreateAndConnectActions();
QList<QColor> m_color;
QColor m_color_stack;
QTextEdit *m_log;
QTextEdit *m_tty;
QString m_old_text;

View File

@ -98,18 +98,14 @@ void main_window::Init()
CreateActions();
CreateDockWindows();
setMinimumSize(350, minimumSizeHint().height()); // seems fine on win 10
CreateConnects();
setMinimumSize(350, minimumSizeHint().height()); // seems fine on win 10
setWindowTitle(QString::fromStdString("RPCS3 v" + rpcs3::version.to_string()));
!m_appIcon.isNull() ? setWindowIcon(m_appIcon) : LOG_WARNING(GENERAL, "AppImage could not be loaded!");
Q_EMIT RequestGlobalStylesheetChange(guiSettings->GetCurrentStylesheetPath());
ConfigureGuiFromSettings(true);
RepaintToolBarIcons();
m_gameListFrame->RepaintToolBarIcons();
if (!utils::has_ssse3())
{
@ -1073,9 +1069,18 @@ void main_window::AddRecentAction(const q_string_pair& entry)
}
void main_window::RepaintGui()
{
if (m_gameListFrame)
{
m_gameListFrame->RepaintIcons(true);
m_gameListFrame->RepaintToolBarIcons();
}
if (m_logFrame)
{
m_logFrame->RepaintTextColors();
}
RepaintToolbar();
RepaintToolBarIcons();
RepaintThumbnailIcons();

View File

@ -17,7 +17,7 @@
namespace
{
// Helper converters
inline QString qstr(const std::string& _in) { return QString::fromUtf8(_in.data(), _in.size()); }
constexpr auto qstr = QString::fromStdString;
inline std::string sstr(const QString& _in) { return _in.toUtf8().toStdString(); }
/**
@ -147,7 +147,7 @@ void save_manager_dialog::UpdateList()
m_save_entries = GetSaveEntries(m_dir);
m_list->clearContents();
m_list->setRowCount(m_save_entries.size());
m_list->setRowCount(static_cast<int>(m_save_entries.size()));
gui_settings settings(this);
int row = 0;