diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-06 16:46:36 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-06 16:46:36 +0200 |
| commit | 7772993ed5d65f10588f3d70961c429991fd7849 (patch) | |
| tree | eb90d892fc11731cfa1ca322f783204a727e23f2 /settingsdialog.cpp | |
| parent | bcda97a2e17f6e1366cfe5b03bd0b407d4484255 (diff) | |
| download | kristall-7772993ed5d65f10588f3d70961c429991fd7849.tar.gz | |
Starts to implement settings dialog, allows styling the fonts, fixes stop/reload button, refactors text document rendering into own file, fixes stuff in README
Diffstat (limited to 'settingsdialog.cpp')
| -rw-r--r-- | settingsdialog.cpp | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/settingsdialog.cpp b/settingsdialog.cpp new file mode 100644 index 0000000..32c37eb --- /dev/null +++ b/settingsdialog.cpp @@ -0,0 +1,123 @@ +#include "settingsdialog.hpp" +#include "ui_settingsdialog.h" +#include <QFontDialog> +#include <QColorDialog> + +SettingsDialog::SettingsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SettingsDialog), + current_style() +{ + ui->setupUi(this); + + setStyle(GeminiStyle { }); +} + +SettingsDialog::~SettingsDialog() +{ + delete ui; +} + +static QString formatFont(QFont const & font) +{ + QString style; + if(font.italic() and font.bold()) + style = "bold, italic"; + else if(font.italic()) + style = "italic"; + else if(font.bold()) + style = "bold"; + else + style = "regular"; + + return QString("%1 (%2pt, %3)") + .arg(font.family()) + .arg(font.pointSizeF()) + .arg(style); +} + +void SettingsDialog::setStyle(const GeminiStyle &style) +{ + 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->reloadStylePreview(); +} + +void SettingsDialog::reloadStylePreview() +{ + auto const document = R"gemini(# H1 Header +## H2 Header +### H3 Header +Plain text document here. +* List A +* List B +=> rela-link Same-Site Link +=> //foreign.host/ Foreign Site Link +=> https://foreign.host/ Cross-Protocol Link +``` + ▄▄▄ ██▀███ ▄▄▄█████▓ + ▒████▄ ▓██ ▒ ██▒▓ ██▒ ▓▒ + ▒██ ▀█▄ ▓██ ░▄█ ▒▒ ▓██░ ▒░ + ░██▄▄▄▄██ ▒██▀▀█▄ ░ ▓██▓ ░ + ▓█ ▓██▒░██▓ ▒██▒ ▒██▒ ░ + ▒▒ ▓▒█░░ ▒▓ ░▒▓░ ▒ ░░ + ▒ ▒▒ ░ ░▒ ░ ▒░ ░ + ░ ▒ ░░ ░ ░ + ░ ░ ░ +)gemini"; + + + DocumentOutlineModel outline; + auto doc = GeminiRenderer { current_style }.render( + document, + QUrl("about://preview"), + outline + ); + + ui->style_preview->setDocument(doc.get()); + preview_document = std::move(doc); +} + +void SettingsDialog::updateFont(QFont & input) +{ + QFontDialog dialog { this }; + + dialog.setCurrentFont(input); + + if(dialog.exec() == QDialog::Accepted) { + input = dialog.currentFont(); + setStyle(current_style); + } +} + + +void SettingsDialog::on_std_change_font_clicked() +{ + updateFont(current_style.standard_font); +} + +void SettingsDialog::on_pre_change_font_clicked() +{ + updateFont(current_style.preformatted_font); +} + +void SettingsDialog::on_h1_change_font_clicked() +{ + updateFont(current_style.h1_font); +} + +void SettingsDialog::on_h2_change_font_clicked() +{ + updateFont(current_style.h2_font); +} + +void SettingsDialog::on_h3_change_font_clicked() +{ + updateFont(current_style.h3_font); +} |
