From 496ea48de41e6c637c9fb3582216dbd9d8ee55c7 Mon Sep 17 00:00:00 2001 From: Mike Skec Date: Sat, 13 Feb 2021 12:48:06 +1100 Subject: 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). --- src/browsertab.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/browsertab.cpp') 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); +} -- cgit v1.2.3