aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Skec <skec@protonmail.ch>2021-02-13 13:57:35 +1100
committerFelix Queißner <felix@ib-queissner.de>2021-02-13 12:32:26 +0100
commit19ac43503568ebc7fe4721f84292a11bbf7c2c2c (patch)
tree4feaa078c614476ed0a4165da6eab5a1a1ca39bb /src
parent496ea48de41e6c637c9fb3582216dbd9d8ee55c7 (diff)
downloadkristall-19ac43503568ebc7fe4721f84292a11bbf7c2c2c.tar.gz
Adds per-style pref for text width
Diffstat (limited to 'src')
-rw-r--r--src/browsertab.cpp7
-rw-r--r--src/browsertab.hpp2
-rw-r--r--src/dialogs/settingsdialog.cpp15
-rw-r--r--src/dialogs/settingsdialog.hpp4
-rw-r--r--src/dialogs/settingsdialog.ui67
-rw-r--r--src/documentstyle.cpp6
-rw-r--r--src/documentstyle.hpp4
7 files changed, 89 insertions, 16 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp
index 1455ea8..dfcf517 100644
--- a/src/browsertab.cpp
+++ b/src/browsertab.cpp
@@ -730,6 +730,7 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime)
this->ui->text_browser->setDocument(document.get());
this->current_document = std::move(document);
+ this->current_style = std::move(doc_style);
this->updatePageMargins();
this->needs_rerender = false;
@@ -1315,11 +1316,13 @@ void BrowserTab::setUiDensity(UIDensity density)
void BrowserTab::updatePageMargins()
{
- if (!this->current_document) return;
+ if (!this->current_document || !this->current_style.text_width_enabled)
+ return;
QTextFrame *root = this->current_document->rootFrame();
QTextFrameFormat fmt = root->frameFormat();
- int margin = std::max((this->width() - 900) / 2, 30);
+ int margin = std::max((this->width() - this->current_style.text_width) / 2,
+ this->current_style.margin);
fmt.setLeftMargin(margin);
fmt.setRightMargin(margin);
root->setFrameFormat(fmt);
diff --git a/src/browsertab.hpp b/src/browsertab.hpp
index 8172122..4b5958a 100644
--- a/src/browsertab.hpp
+++ b/src/browsertab.hpp
@@ -237,6 +237,8 @@ public:
bool was_read_from_cache = false;
RequestState request_state;
+
+ DocumentStyle current_style;
};
#endif // BROWSERTAB_HPP
diff --git a/src/dialogs/settingsdialog.cpp b/src/dialogs/settingsdialog.cpp
index 16c74aa..1bbdcf3 100644
--- a/src/dialogs/settingsdialog.cpp
+++ b/src/dialogs/settingsdialog.cpp
@@ -114,6 +114,10 @@ void SettingsDialog::setGeminiStyle(DocumentStyle const &style)
this->ui->enable_justify_text->setChecked(this->current_style.justify_text);
+ this->ui->enable_text_width->setChecked(this->current_style.text_width_enabled);
+
+ this->ui->text_width->setValue(this->current_style.text_width);
+
this->ui->line_height_p->setValue(this->current_style.line_height_p);
this->ui->line_height_h->setValue(this->current_style.line_height_h);
@@ -445,6 +449,17 @@ void SettingsDialog::on_enable_justify_text_clicked(bool checked)
this->reloadStylePreview();
}
+void SettingsDialog::on_enable_text_width_clicked(bool checked)
+{
+ this->current_style.text_width_enabled = checked;
+ this->ui->text_width->setEnabled(checked);
+}
+
+void SettingsDialog::on_text_width_valueChanged(int value)
+{
+ this->current_style.text_width = value;
+}
+
void SettingsDialog::on_line_height_p_valueChanged(double value)
{
this->current_style.line_height_p = value;
diff --git a/src/dialogs/settingsdialog.hpp b/src/dialogs/settingsdialog.hpp
index ff558f6..4032129 100644
--- a/src/dialogs/settingsdialog.hpp
+++ b/src/dialogs/settingsdialog.hpp
@@ -80,6 +80,10 @@ private slots:
void on_enable_justify_text_clicked(bool arg1);
+ void on_enable_text_width_clicked(bool arg1);
+
+ void on_text_width_valueChanged(int value);
+
void on_line_height_p_valueChanged(double arg1);
void on_line_height_h_valueChanged(double arg1);
diff --git a/src/dialogs/settingsdialog.ui b/src/dialogs/settingsdialog.ui
index 2193656..b1c0684 100644
--- a/src/dialogs/settingsdialog.ui
+++ b/src/dialogs/settingsdialog.ui
@@ -930,16 +930,54 @@
</property>
</widget>
</item>
+ <item>
+ <widget class="QCheckBox" name="enable_text_width">
+ <property name="text">
+ <string>Enable text width limit</string>
+ </property>
+ <property name="toolTip">
+ <string>Whether to limit the width of formatted text on the page or not.</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
+
<item row="15" column="0">
+ <widget class="QLabel" name="label_38">
+ <property name="text">
+ <string>Text width limit</string>
+ </property>
+ <property name="toolTip">
+ <string>Preferred width of formatted text on the page.</string>
+ </property>
+ </widget>
+ </item>
+ <item row="15" column="1">
+ <widget class="QSpinBox" name="text_width">
+ <property name="minimum">
+ <number>300</number>
+ </property>
+ <property name="value">
+ <number>900</number>
+ </property>
+ <property name="maximum">
+ <number>2000</number>
+ </property>
+ <property name="suffix">
+ <string> px</string>
+ </property>
+ </widget>
+ </item>
+
+ <item row="16" column="0">
<widget class="QLabel" name="label_35">
<property name="text">
<string>Line height (paragraph)</string>
</property>
</widget>
</item>
- <item row="15" column="1">
+ <item row="16" column="1">
<widget class="QDoubleSpinBox" name="line_height_p">
<property name="suffix">
<string> px</string>
@@ -952,14 +990,15 @@
</property>
</widget>
</item>
- <item row="16" column="0">
+
+ <item row="17" column="0">
<widget class="QLabel" name="label_36">
<property name="text">
<string>Line height (header)</string>
</property>
</widget>
</item>
- <item row="16" column="1">
+ <item row="17" column="1">
<widget class="QDoubleSpinBox" name="line_height_h">
<property name="suffix">
<string> px</string>
@@ -973,14 +1012,14 @@
</widget>
</item>
- <item row="17" column="0">
+ <item row="18" column="0">
<widget class="QLabel" name="label_37">
<property name="text">
<string>Indentation</string>
</property>
</widget>
</item>
- <item row="17" column="1">
+ <item row="18" column="1">
<layout class="QHBoxLayout" name="indent_container">
<item>
@@ -1070,7 +1109,14 @@
</layout>
</item>
- <item row="18" column="1">
+ <item row="19" column="0">
+ <widget class="QLabel" name="label_17">
+ <property name="text">
+ <string>Presets</string>
+ </property>
+ </widget>
+ </item>
+ <item row="19" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QComboBox" name="presets"/>
@@ -1146,13 +1192,6 @@
</item>
</layout>
</item>
- <item row="18" column="0">
- <widget class="QLabel" name="label_17">
- <property name="text">
- <string>Presets</string>
- </property>
- </widget>
- </item>
<item row="11" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
@@ -1305,6 +1344,8 @@
<tabstop>auto_theme</tabstop>
<tabstop>page_margin</tabstop>
<tabstop>enable_justify_text</tabstop>
+ <tabstop>enable_text_width</tabstop>
+ <tabstop>text_width</tabstop>
<tabstop>line_height_p</tabstop>
<tabstop>line_height_h</tabstop>
<tabstop>indent_p</tabstop>
diff --git a/src/documentstyle.cpp b/src/documentstyle.cpp
index e6642a2..3bfd857 100644
--- a/src/documentstyle.cpp
+++ b/src/documentstyle.cpp
@@ -135,11 +135,13 @@ DocumentStyle::DocumentStyle(bool do_init) : theme(Fixed),
internal_link_prefix("→ "),
external_link_prefix("⇒ "),
margin(55.0),
+ text_width(900),
ansi_colors({"black", "darkred", "darkgreen", "darkgoldenrod",
"darkblue", "darkmagenta", "darkcyan", "lightgray",
"gray", "red", "green", "goldenrod",
"lightblue", "magenta", "cyan", "white"}),
justify_text(true),
+ text_width_enabled(true),
line_height_p(5.0),
line_height_h(0.0),
indent_bq(2), indent_p(1), indent_h(0), indent_l(2)
@@ -273,6 +275,8 @@ bool DocumentStyle::save(QSettings &settings) const
settings.beginGroup("Formatting");
settings.setValue("justify_text", justify_text);
+ settings.setValue("text_width_enabled", text_width_enabled);
+ settings.setValue("text_width", text_width);
settings.setValue("line_height_p", line_height_p);
settings.setValue("line_height_h", line_height_h);
settings.setValue("indent_bq", indent_bq);
@@ -378,6 +382,8 @@ bool DocumentStyle::load(QSettings &settings)
settings.beginGroup("Formatting");
justify_text = settings.value("justify_text", justify_text).toBool();
+ text_width_enabled = settings.value("text_width_enabled", text_width_enabled).toBool();
+ text_width = settings.value("text_width", text_width).toInt();
line_height_p = settings.value("line_height_p", line_height_p).toDouble();
line_height_h = settings.value("line_height_h", line_height_h).toDouble();
indent_bq = settings.value("indent_bq", indent_bq).toInt();
diff --git a/src/documentstyle.hpp b/src/documentstyle.hpp
index c300a95..a8d12fe 100644
--- a/src/documentstyle.hpp
+++ b/src/documentstyle.hpp
@@ -51,9 +51,11 @@ struct DocumentStyle
double margin;
+ double text_width;
+
QStringList ansi_colors;
- bool justify_text;
+ bool justify_text, text_width_enabled;
double line_height_p;
double line_height_h;
int indent_bq, indent_p, indent_h, indent_l;