aboutsummaryrefslogtreecommitdiff
path: root/src/browsertab.cpp
diff options
context:
space:
mode:
authorFelix (xq) Queißner <git@mq32.de>2020-08-17 12:05:40 +0200
committerFelix (xq) Queißner <git@mq32.de>2020-08-17 12:05:40 +0200
commit3d1f480798f8708a85785d16f10ae10ed997bfeb (patch)
tree5d0a944ed5f3e83241de7b2ef0913b9270af48a6 /src/browsertab.cpp
parent68e1e48c63be4889d3c6c00c382c65e8d15596d8 (diff)
downloadkristall-3d1f480798f8708a85785d16f10ae10ed997bfeb.tar.gz
Adds 'show document source' menu item. Closes #11.
Diffstat (limited to 'src/browsertab.cpp')
-rw-r--r--src/browsertab.cpp37
1 files changed, 37 insertions, 0 deletions
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() };