diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-02-13 12:48:06 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-02-13 12:32:26 +0100 |
| commit | 496ea48de41e6c637c9fb3582216dbd9d8ee55c7 (patch) | |
| tree | a81964ac52d142e908ac608b6b0f0b4f6692f620 /src/browsertab.cpp | |
| parent | d5953785dfed6df96388aed876b5a0673158ae94 (diff) | |
| download | kristall-496ea48de41e6c637c9fb3582216dbd9d8ee55c7.tar.gz | |
Adds maximum line width functionality
Hard-coded values for now. This works by setting the left/right margins of the page dynamically (e.g on window resize). The margins are calculated to limit the text's width between a value. If the window width is less than this text width, the text fill width is the same width as the page, the margins in this case will be the user's configured margins (not yet implemented).
Diffstat (limited to 'src/browsertab.cpp')
| -rw-r--r-- | src/browsertab.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp index c86051d..1455ea8 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->updatePageMargins(); this->needs_rerender = false; @@ -1312,6 +1313,20 @@ void BrowserTab::setUiDensity(UIDensity density) } } +void BrowserTab::updatePageMargins() +{ + if (!this->current_document) return; + + QTextFrame *root = this->current_document->rootFrame(); + QTextFrameFormat fmt = root->frameFormat(); + int margin = std::max((this->width() - 900) / 2, 30); + fmt.setLeftMargin(margin); + fmt.setRightMargin(margin); + root->setFrameFormat(fmt); + + this->ui->text_browser->setDocument(this->current_document.get()); +} + bool BrowserTab::trySetClientCertificate(const QString &query) { CertificateSelectionDialog dialog{this}; @@ -1652,3 +1667,9 @@ void BrowserTab::on_close_search_clicked() { this->ui->search_bar->setVisible(false); } + +void BrowserTab::resizeEvent(QResizeEvent * event) +{ + this->updatePageMargins(); + QWidget::resizeEvent(event); +} |
