diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 5f6b9d2..ee552ba 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -44,6 +44,7 @@ qt_add_qml_module(theterminal QML_FILES settings/RootProfileSettings.qml QML_FILES settings/SingleProfileSettings.qml SOURCES settings/fontmodel.h settings/fontmodel.cpp + SOURCES settings/colormodel.h settings/colormodel.cpp ) set_target_properties(theterminal PROPERTIES diff --git a/application/settings/SingleProfileSettings.qml b/application/settings/SingleProfileSettings.qml index 8d5e809..fe56648 100644 --- a/application/settings/SingleProfileSettings.qml +++ b/application/settings/SingleProfileSettings.qml @@ -22,6 +22,10 @@ Item { id: fontModel } + ColorModel { + id: colorModel + } + Grandstand { id: grandstand anchors.top: parent.top @@ -121,6 +125,38 @@ Item { } } + GroupBox { + Layout.alignment: Qt.AlignHCenter + implicitWidth: 600 + title: qsTr("Colours") + + GridLayout { + columns: 2 + + Label { + text: qsTr("Theme") + } + + ComboBox { + id: colorsBox + Layout.fillWidth: true + + model: colorModel + textRole: "description" + valueRole: "identifier" + + onActivated: () => { + profile.colorName = colorsBox.currentValue; + profile.saveProfile(); + } + + Component.onCompleted: () => { + colorsBox.currentIndex = colorsBox.indexOfValue(profile.colorName) + } + } + } + } + Item { Layout.fillHeight: true } diff --git a/application/settings/colormodel.cpp b/application/settings/colormodel.cpp new file mode 100644 index 0000000..ad62c41 --- /dev/null +++ b/application/settings/colormodel.cpp @@ -0,0 +1,46 @@ +#include "colormodel.h" + +#include + +struct ColorModelPrivate { +}; + +ColorModel::ColorModel(QObject* parent) : + QAbstractListModel(parent), d{new ColorModelPrivate()} { +} + +ColorModel::~ColorModel() { + delete d; +} + +int ColorModel::rowCount(const QModelIndex& parent) const { + // For list models only the root node (an invalid parent) should return the list's size. For all + // other (valid) parents, rowCount() should return 0 so that it does not become a tree model. + if (parent.isValid()) + return 0; + + // FIXME: Implement me! + return ScreenColorManager::definitions().length(); +} + +QVariant ColorModel::data(const QModelIndex& index, int role) const { + if (!index.isValid()) + return QVariant(); + + auto definition = ScreenColorManager::definitions().value(index.row()); + switch (role) { + case Description: + return ScreenColorManager::name(definition); + case Identifier: + return definition; + } + + return QVariant(); +} + +QHash ColorModel::roleNames() const { + return { + {Description, "description"}, + {Identifier, "identifier" } + }; +} diff --git a/application/settings/colormodel.h b/application/settings/colormodel.h new file mode 100644 index 0000000..5fadba4 --- /dev/null +++ b/application/settings/colormodel.h @@ -0,0 +1,30 @@ +#ifndef COLORMODEL_H +#define COLORMODEL_H + +#include +#include + +struct ColorModelPrivate; +class ColorModel : public QAbstractListModel { + Q_OBJECT + QML_ELEMENT + + public: + explicit ColorModel(QObject* parent = nullptr); + ~ColorModel(); + + enum ColorRoles { + Description = Qt::DisplayRole, + Identifier = Qt::UserRole + }; + + // Basic functionality: + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + QHash roleNames() const override; + + private: + ColorModelPrivate* d; +}; + +#endif // COLORMODEL_H diff --git a/application/translations/en_US.ts b/application/translations/en_US.ts index bfafb74..d79c662 100644 --- a/application/translations/en_US.ts +++ b/application/translations/en_US.ts @@ -176,29 +176,41 @@ SingleProfileSettings - - + + Shell - - + + Set the shell that is used when you start a terminal with this profile - - + + Text - - + + Font + + + + Colours + + + + + + Theme + + main diff --git a/libtheterminal/com/vicr123/theterminal/libtheterminal/impl/qmlterminalscreencontroller.cpp b/libtheterminal/com/vicr123/theterminal/libtheterminal/impl/qmlterminalscreencontroller.cpp index 415e93d..f8881df 100644 --- a/libtheterminal/com/vicr123/theterminal/libtheterminal/impl/qmlterminalscreencontroller.cpp +++ b/libtheterminal/com/vicr123/theterminal/libtheterminal/impl/qmlterminalscreencontroller.cpp @@ -46,12 +46,8 @@ QmlTerminalScreenController::QmlTerminalScreenController(QObject* parent) : }); connect(d->terminalScreen, &TerminalScreen::historyRolled, this, [this] { for (auto i = 0; i < d->terminalScreen->rows(); i++) { - // if (d->cachedRuns.contains(i + 1)) { - // d->cachedRuns.insert(i, d->cachedRuns.value(i + 1)); - // } queueRowUpdate(i); } - // d->cachedRuns.remove(d->terminalScreen->rows() - 1); queueRowUpdate(d->terminalScreen->rows() - 1); }); connect(d->terminalScreen, &TerminalScreen::invertScreenChanged, this, [this] { @@ -347,4 +343,10 @@ void QmlTerminalScreenController::setColorName(QString colorName) { d->colorName = colorName; d->screenColorManager.loadColorDefinition(colorName); emit colorNameChanged(); + + // Update all rows + for (auto i = 0; i < d->terminalScreen->rows(); i++) { + queueRowUpdate(i); + } + emit scrollbackLinesChanged(); } diff --git a/libtheterminal/common/colorschemes/PowerShell.colorscheme b/libtheterminal/common/colorschemes/PowerShell.colorscheme index b4f9c6d..e1a0540 100644 --- a/libtheterminal/common/colorschemes/PowerShell.colorscheme +++ b/libtheterminal/common/colorschemes/PowerShell.colorscheme @@ -94,6 +94,6 @@ Color=204,204,204 [General] Blur=false ColorRandomization=false -Description=Campbell +Description=Campbell (PowerShell) Opacity=1 Wallpaper= diff --git a/libtheterminal/common/screencolormanager.cpp b/libtheterminal/common/screencolormanager.cpp index bcd0f90..7fee7a5 100644 --- a/libtheterminal/common/screencolormanager.cpp +++ b/libtheterminal/common/screencolormanager.cpp @@ -29,6 +29,31 @@ ScreenColorManager::~ScreenColorManager() { delete d; } +QStringList ScreenColorManager::definitions() { + return { + "Campbell", + "GreenOnBlack", + "Linux", + "PowerShell", + "Solarized", + "SolarizedLight", + "Ubuntu"}; +} + +QString ScreenColorManager::name(QString definition) { + auto file = definition; + if (!definition.startsWith("/")) { + // Interpret as an internal resource + file = QStringLiteral(":/com/vicr123/theterminal/libtheterminal/colorschemes/%1.colorscheme").arg(definition); + } + + // Colors are packed into d->colors as 0xAABBGGRR + + QSettings settings(file, QSettings::IniFormat); + auto k = settings.allKeys(); + return settings.value("Description", definition).toString(); +} + QColor ScreenColorManager::decodeColor(quint32 color) { switch (decodeColorMode(color)) { case 0: // 24 bit color diff --git a/libtheterminal/common/screencolormanager.h b/libtheterminal/common/screencolormanager.h index 1ddd8be..44ba266 100644 --- a/libtheterminal/common/screencolormanager.h +++ b/libtheterminal/common/screencolormanager.h @@ -11,6 +11,9 @@ class LIBTHETERMINAL_COMMON_EXPORT ScreenColorManager : public QObject { explicit ScreenColorManager(QObject* parent = nullptr); ~ScreenColorManager(); + static QStringList definitions(); + static QString name(QString definition); + using Color = quint32; using ColorSection = quint8;