From 3d1f480798f8708a85785d16f10ae10ed997bfeb Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Mon, 17 Aug 2020 12:05:40 +0200 Subject: Adds 'show document source' menu item. Closes #11. --- src/about/updates.gemini | 1 + src/browsertab.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/browsertab.hpp | 2 ++ src/main.cpp | 2 +- src/mainwindow.cpp | 12 +++++++++++- src/mainwindow.hpp | 2 ++ src/mainwindow.ui | 7 +++++++ 7 files changed, 61 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/about/updates.gemini b/src/about/updates.gemini index 7c5730f..a6df987 100644 --- a/src/about/updates.gemini +++ b/src/about/updates.gemini @@ -11,6 +11,7 @@ * Improved settings system with folder-based approach * Document styles are now saved as files which are exchangeable * Adds colored icons to dark/light theme so it has improved contrast +* New action: "View/Show document source" will display the raw data of the document in a small separate window ## 0.3 - TLS and security * Adds support for transient client certificates diff --git a/src/browsertab.cpp b/src/browsertab.cpp index 87c1c7d..2c34314 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -39,6 +39,11 @@ #include #include +#include +#include +#include +#include + #include #include @@ -215,6 +220,38 @@ void BrowserTab::focusSearchBar() this->ui->search_box->selectAll(); } +void BrowserTab::openSourceView() +{ + QFont monospace_font("monospace"); + monospace_font.setStyleHint(QFont::Monospace); + + auto dialog = std::make_unique(this); + dialog->setWindowTitle(QString("Source of %0").arg(this->current_location.toString())); + + auto layout = new QVBoxLayout(dialog.get()); + dialog->setLayout(layout); + + auto hint = new QLabel(dialog.get()); + hint->setText(QString("Mime type: %0").arg(current_mime.toString())); + layout->addWidget(hint); + + auto text = new QPlainTextEdit(dialog.get()); + text->setPlainText(QString::fromUtf8(current_buffer)); + text->setReadOnly(true); + text->setFont(monospace_font); + text->setWordWrapMode(QTextOption::NoWrap); + layout->addWidget(text); + + auto buttons = new QDialogButtonBox(dialog.get()); + buttons->setStandardButtons(QDialogButtonBox::Ok); + layout->addWidget(buttons); + + connect(buttons->button(QDialogButtonBox::Ok), &QPushButton::pressed, dialog.get(), &QDialog::accept); + + dialog->resize(640, 480); + dialog->exec(); +} + void BrowserTab::on_url_bar_returnPressed() { QUrl url { this->ui->url_bar->text().trimmed() }; diff --git a/src/browsertab.hpp b/src/browsertab.hpp index 7e7f446..0a8f26e 100644 --- a/src/browsertab.hpp +++ b/src/browsertab.hpp @@ -71,6 +71,8 @@ public: void focusSearchBar(); + void openSourceView(); + signals: void titleChanged(QString const & title); void locationChanged(QUrl const & url); diff --git a/src/main.cpp b/src/main.cpp index 8de3530..46bc7e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -78,7 +78,7 @@ static void addEmojiSubstitutions() { auto current = QFont::substitutes(family); current << emojiFonts; - QFont::insertSubstitutions(family, current); + // TODO: QFont::insertSubstitutions(family, current); } } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ba80651..ee79efa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -62,7 +62,9 @@ MainWindow::MainWindow(QApplication * app, QWidget *parent) : for(QAction * act : this->ui->menuView->actions()) { auto * dock = qvariant_cast(act->data()); - act->setChecked(dock->isVisible()); + if(dock != nullptr) { + act->setChecked(dock->isVisible()); + } } }); @@ -456,3 +458,11 @@ void MainWindow::on_actionManage_Certificates_triggered() kristall::saveSettings(); } + +void MainWindow::on_actionShow_document_source_triggered() +{ + BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); + if(tab != nullptr) { + tab->openSourceView(); + } +} diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index 1966684..6cfee9f 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -75,6 +75,8 @@ private slots: void on_actionManage_Certificates_triggered(); + void on_actionShow_document_source_triggered(); + private: // slots void on_tab_fileLoaded(DocumentStats const & stats); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 7c792a5..ea7c7cd 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -203,6 +203,8 @@ View + + @@ -388,6 +390,11 @@ Manage Certificates… + + + Show document source + + -- cgit v1.2.3