From 692fe58427ded3fd7d0b4d0a211be91b5ece50da Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Tue, 10 Oct 2023 09:17:04 +0200 Subject: [PATCH] Terminal: Add debug button to easily copy theme Adds a button to copy the current theme to the clipboard in a format suitable for the Qt Creator Theme files. Change-Id: Ib302d0544507b3111675a99f0915323d61d684c5 Reviewed-by: Cristian Adam Reviewed-by: --- src/plugins/terminal/terminalsettings.cpp | 43 ++++++++++++++++------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/plugins/terminal/terminalsettings.cpp b/src/plugins/terminal/terminalsettings.cpp index c098ff0ed81..0493237f0c5 100644 --- a/src/plugins/terminal/terminalsettings.cpp +++ b/src/plugins/terminal/terminalsettings.cpp @@ -15,17 +15,21 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include #include #include +Q_LOGGING_CATEGORY(schemeLog, "qtc.terminal.scheme", QtWarningMsg) + using namespace Utils; namespace Terminal { @@ -553,6 +557,8 @@ TerminalSettings::TerminalSettings() auto loadThemeButton = new QPushButton(Tr::tr("Load Theme...")); auto resetTheme = new QPushButton(Tr::tr("Reset Theme")); + auto copyTheme = schemeLog().isDebugEnabled() ? new QPushButton(Tr::tr("Copy Theme")) + : nullptr; connect(loadThemeButton, &QPushButton::clicked, this, [] { const FilePath path = FileUtils::getOpenFilePath( @@ -589,20 +595,31 @@ TerminalSettings::TerminalSettings() color.setVolatileValue(color.defaultValue()); }); -// FIXME: Implement and use a Layouting::DropArea item + if (schemeLog().isDebugEnabled()) { + connect(copyTheme, &QPushButton::clicked, this, [this] { + auto toThemeColor = [](const ColorAspect &color) -> QString { + QColor c = color.value(); + QString a = c.alpha() != 255 ? QString("%1").arg(c.alpha(), 2, 16, QChar('0')) + : QString(); + return QString("%1%2%3%4") + .arg(a) + .arg(c.red(), 2, 16, QChar('0')) + .arg(c.green(), 2, 16, QChar('0')) + .arg(c.blue(), 2, 16, QChar('0')); + }; -// DropSupport *dropSupport = new DropSupport; -// connect(dropSupport, -// &DropSupport::filesDropped, -// this, -// [this](const QList &files) { -// if (files.size() != 1) -// return; + QString theme; + QTextStream stream(&theme); + stream << "TerminalForeground=" << toThemeColor(foregroundColor) << '\n'; + stream << "TerminalBackground=" << toThemeColor(backgroundColor) << '\n'; + stream << "TerminalSelection=" << toThemeColor(selectionColor) << '\n'; + stream << "TerminalFindMatch=" << toThemeColor(findMatchColor) << '\n'; + for (int i = 0; i < 16; ++i) + stream << "TerminalAnsi" << i << '=' << toThemeColor(colors[i]) << '\n'; -// const expected_str result = loadColorScheme(files.at(0).filePath); -// if (!result) -// QMessageBox::warning(Core::ICore::dialogParent(), Tr::tr("Error"), result.error()); -// }); + setClipboardAndSelection(theme); + }); + } // clang-format off return Column { @@ -646,7 +663,7 @@ TerminalSettings::TerminalSettings() colors[14], colors[15] }, Row { - loadThemeButton, resetTheme, st, + loadThemeButton, resetTheme, copyTheme, st, } }, },