aboutsummaryrefslogtreecommitdiff
path: root/settingsdialog.cpp
diff options
context:
space:
mode:
authorFelix (xq) Queißner <git@mq32.de>2020-06-06 18:28:10 +0200
committerFelix (xq) Queißner <git@mq32.de>2020-06-06 18:28:10 +0200
commitcb69dca1dbf19ae854276803442e724045c4be81 (patch)
tree8c3dd168d5ab337161a44246133bef98fb5be31c /settingsdialog.cpp
parent7772993ed5d65f10588f3d70961c429991fd7849 (diff)
downloadkristall-cb69dca1dbf19ae854276803442e724045c4be81.tar.gz
Adds color theming, adds automatic color theming with dark/light themes
Diffstat (limited to 'settingsdialog.cpp')
-rw-r--r--settingsdialog.cpp144
1 files changed, 134 insertions, 10 deletions
diff --git a/settingsdialog.cpp b/settingsdialog.cpp
index 32c37eb..e100c91 100644
--- a/settingsdialog.cpp
+++ b/settingsdialog.cpp
@@ -2,6 +2,7 @@
#include "ui_settingsdialog.h"
#include <QFontDialog>
#include <QColorDialog>
+#include <QStyle>
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
@@ -10,7 +11,16 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
{
ui->setupUi(this);
- setStyle(GeminiStyle { });
+ static_assert(GeminiStyle::Fixed == 0);
+ static_assert(GeminiStyle::AutoDarkTheme == 1);
+ static_assert(GeminiStyle::AutoLightTheme == 2);
+
+ this->ui->auto_theme->clear();
+ this->ui->auto_theme->addItem("Disabled", QVariant::fromValue<int>(GeminiStyle::Fixed));
+ this->ui->auto_theme->addItem("Dark Theme", QVariant::fromValue<int>(GeminiStyle::AutoDarkTheme));
+ this->ui->auto_theme->addItem("Light Theme", QVariant::fromValue<int>(GeminiStyle::AutoLightTheme));
+
+ setGeminiStyle(GeminiStyle { });
}
SettingsDialog::~SettingsDialog()
@@ -36,15 +46,43 @@ static QString formatFont(QFont const & font)
.arg(style);
}
-void SettingsDialog::setStyle(const GeminiStyle &style)
+void SettingsDialog::setGeminiStyle(const GeminiStyle &style)
{
+ static const QString COLOR_STYLE("border: 1px solid black; padding: 4px; background-color : %1; color : %2;");
+
this->current_style = style;
- this->ui->std_preview->setText(formatFont(this->current_style.standard_font));
- this->ui->pre_preview->setText(formatFont(this->current_style.preformatted_font));
- this->ui->h1_preview->setText(formatFont(this->current_style.h1_font));
- this->ui->h2_preview->setText(formatFont(this->current_style.h2_font));
- this->ui->h3_preview->setText(formatFont(this->current_style.h3_font));
+ this->ui->auto_theme->setCurrentIndex(this->current_style.theme);
+
+ auto setFontAndColor = [this](QLabel * label, QFont font, QColor color)
+ {
+ label->setText(formatFont(font));
+ label->setStyleSheet(COLOR_STYLE
+ .arg(this->current_style.background_color.name())
+ .arg(color.name()));
+ };
+
+ ui->bg_preview->setStyleSheet(COLOR_STYLE
+ .arg(this->current_style.background_color.name())
+ .arg("#FF00FF"));
+
+ ui->link_local_preview->setStyleSheet(COLOR_STYLE
+ .arg(this->current_style.background_color.name())
+ .arg(this->current_style.internal_link_color.name()));
+
+ ui->link_foreign_preview->setStyleSheet(COLOR_STYLE
+ .arg(this->current_style.background_color.name())
+ .arg(this->current_style.external_link_color.name()));
+
+ ui->link_cross_preview->setStyleSheet(COLOR_STYLE
+ .arg(this->current_style.background_color.name())
+ .arg(this->current_style.cross_scheme_link_color.name()));
+
+ setFontAndColor(this->ui->std_preview, this->current_style.standard_font, this->current_style.standard_color);
+ setFontAndColor(this->ui->pre_preview, this->current_style.preformatted_font, this->current_style.preformatted_color);
+ setFontAndColor(this->ui->h1_preview, this->current_style.h1_font, this->current_style.h1_color);
+ setFontAndColor(this->ui->h2_preview, this->current_style.h2_font, this->current_style.h2_color);
+ setFontAndColor(this->ui->h3_preview, this->current_style.h3_font, this->current_style.h3_color);
this->reloadStylePreview();
}
@@ -72,14 +110,19 @@ Plain text document here.
░ ░ ░
)gemini";
+ QString host = this->ui->preview_url->text();
+ if(host.length() == 0)
+ host = "preview";
DocumentOutlineModel outline;
auto doc = GeminiRenderer { current_style }.render(
document,
- QUrl("about://preview"),
+ QUrl(QString("about://%1/foobar").arg(host)),
outline
);
+ ui->style_preview->setStyleSheet(QString("QTextBrowser { background-color: %1; }")
+ .arg(doc->background_color.name()));
ui->style_preview->setDocument(doc.get());
preview_document = std::move(doc);
}
@@ -92,11 +135,10 @@ void SettingsDialog::updateFont(QFont & input)
if(dialog.exec() == QDialog::Accepted) {
input = dialog.currentFont();
- setStyle(current_style);
+ setGeminiStyle(current_style);
}
}
-
void SettingsDialog::on_std_change_font_clicked()
{
updateFont(current_style.standard_font);
@@ -121,3 +163,85 @@ void SettingsDialog::on_h3_change_font_clicked()
{
updateFont(current_style.h3_font);
}
+
+void SettingsDialog::updateColor(QColor &input)
+{
+ QColorDialog dialog { this };
+
+ dialog.setCurrentColor(input);
+
+ if(dialog.exec() == QDialog::Accepted) {
+ input = dialog.currentColor();
+ setGeminiStyle(current_style);
+ }
+}
+
+void SettingsDialog::on_std_change_color_clicked()
+{
+ updateColor(current_style.standard_color);
+}
+
+void SettingsDialog::on_pre_change_color_clicked()
+{
+ updateColor(current_style.preformatted_color);
+}
+
+void SettingsDialog::on_h1_change_color_clicked()
+{
+ updateColor(current_style.h1_color);
+}
+
+void SettingsDialog::on_h2_change_color_clicked()
+{
+ updateColor(current_style.h2_color);
+}
+
+void SettingsDialog::on_h3_change_color_clicked()
+{
+ updateColor(current_style.h3_color);
+}
+
+void SettingsDialog::on_bg_change_color_clicked()
+{
+ updateColor(current_style.background_color);
+}
+
+void SettingsDialog::on_link_local_change_color_clicked()
+{
+ updateColor(current_style.internal_link_color);
+}
+
+void SettingsDialog::on_link_foreign_change_color_clicked()
+{
+ updateColor(current_style.external_link_color);
+}
+
+void SettingsDialog::on_link_cross_change_color_clicked()
+{
+ updateColor(current_style.cross_scheme_link_color);
+}
+
+void SettingsDialog::on_link_local_prefix_textChanged(const QString &text)
+{
+ current_style.internal_link_prefix = text;
+ reloadStylePreview();
+}
+
+void SettingsDialog::on_link_foreign_prefix_textChanged(const QString &text)
+{
+ current_style.external_link_prefix = text;
+ reloadStylePreview();
+}
+
+void SettingsDialog::on_auto_theme_currentIndexChanged(int index)
+{
+ if(index >= 0) {
+ current_style.theme = GeminiStyle::Theme(index);
+ reloadStylePreview();
+ }
+}
+
+void SettingsDialog::on_preview_url_textChanged(const QString &arg1)
+{
+ this->reloadStylePreview();
+}