forked from qt-creator/qt-creator
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 <cristian.adam@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -15,17 +15,21 @@
|
|||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
#include <utils/pathchooser.h>
|
#include <utils/pathchooser.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
|
||||||
#include <QFontComboBox>
|
#include <QFontComboBox>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QLoggingCategory>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
|
|
||||||
|
Q_LOGGING_CATEGORY(schemeLog, "qtc.terminal.scheme", QtWarningMsg)
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Terminal {
|
namespace Terminal {
|
||||||
@@ -553,6 +557,8 @@ TerminalSettings::TerminalSettings()
|
|||||||
|
|
||||||
auto loadThemeButton = new QPushButton(Tr::tr("Load Theme..."));
|
auto loadThemeButton = new QPushButton(Tr::tr("Load Theme..."));
|
||||||
auto resetTheme = new QPushButton(Tr::tr("Reset 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, [] {
|
connect(loadThemeButton, &QPushButton::clicked, this, [] {
|
||||||
const FilePath path = FileUtils::getOpenFilePath(
|
const FilePath path = FileUtils::getOpenFilePath(
|
||||||
@@ -589,20 +595,31 @@ TerminalSettings::TerminalSettings()
|
|||||||
color.setVolatileValue(color.defaultValue());
|
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;
|
QString theme;
|
||||||
// connect(dropSupport,
|
QTextStream stream(&theme);
|
||||||
// &DropSupport::filesDropped,
|
stream << "TerminalForeground=" << toThemeColor(foregroundColor) << '\n';
|
||||||
// this,
|
stream << "TerminalBackground=" << toThemeColor(backgroundColor) << '\n';
|
||||||
// [this](const QList<DropSupport::FileSpec> &files) {
|
stream << "TerminalSelection=" << toThemeColor(selectionColor) << '\n';
|
||||||
// if (files.size() != 1)
|
stream << "TerminalFindMatch=" << toThemeColor(findMatchColor) << '\n';
|
||||||
// return;
|
for (int i = 0; i < 16; ++i)
|
||||||
|
stream << "TerminalAnsi" << i << '=' << toThemeColor(colors[i]) << '\n';
|
||||||
|
|
||||||
// const expected_str<void> result = loadColorScheme(files.at(0).filePath);
|
setClipboardAndSelection(theme);
|
||||||
// if (!result)
|
});
|
||||||
// QMessageBox::warning(Core::ICore::dialogParent(), Tr::tr("Error"), result.error());
|
}
|
||||||
// });
|
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
return Column {
|
return Column {
|
||||||
@@ -646,7 +663,7 @@ TerminalSettings::TerminalSettings()
|
|||||||
colors[14], colors[15]
|
colors[14], colors[15]
|
||||||
},
|
},
|
||||||
Row {
|
Row {
|
||||||
loadThemeButton, resetTheme, st,
|
loadThemeButton, resetTheme, copyTheme, st,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user