diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-08-17 12:05:40 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-08-17 12:05:40 +0200 |
| commit | 3d1f480798f8708a85785d16f10ae10ed997bfeb (patch) | |
| tree | 5d0a944ed5f3e83241de7b2ef0913b9270af48a6 /src | |
| parent | 68e1e48c63be4889d3c6c00c382c65e8d15596d8 (diff) | |
| download | kristall-3d1f480798f8708a85785d16f10ae10ed997bfeb.tar.gz | |
Adds 'show document source' menu item. Closes #11.
Diffstat (limited to 'src')
| -rw-r--r-- | src/about/updates.gemini | 1 | ||||
| -rw-r--r-- | src/browsertab.cpp | 37 | ||||
| -rw-r--r-- | src/browsertab.hpp | 2 | ||||
| -rw-r--r-- | src/main.cpp | 2 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 12 | ||||
| -rw-r--r-- | src/mainwindow.hpp | 2 | ||||
| -rw-r--r-- | src/mainwindow.ui | 7 |
7 files changed, 61 insertions, 2 deletions
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 <QShortcut> #include <QKeySequence> +#include <QPlainTextEdit> +#include <QVBoxLayout> +#include <QDialogButtonBox> +#include <QPushButton> + #include <QGraphicsPixmapItem> #include <QGraphicsTextItem> @@ -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<QDialog>(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<QDockWidget*>(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<BrowserTab*>(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 @@ <property name="title"> <string>View</string> </property> + <addaction name="actionShow_document_source"/> + <addaction name="separator"/> </widget> <widget class="QMenu" name="menuNavigation"> <property name="title"> @@ -388,6 +390,11 @@ <string>Manage Certificates…</string> </property> </action> + <action name="actionShow_document_source"> + <property name="text"> + <string>Show document source</string> + </property> + </action> </widget> <customwidgets> <customwidget> |
