diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-04 23:15:27 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-04 23:15:27 +0200 |
| commit | 55e4bf4197d5992d05296bff3bb339da17ed0a39 (patch) | |
| tree | 8673beae4f8fadaa4e3bfcaa2211036fdc2b4d16 | |
| parent | 850cd41dd8c9ec7645b2c5c4441d48473aed9375 (diff) | |
| download | kristall-55e4bf4197d5992d05296bff3bb339da17ed0a39.tar.gz | |
Removes the need for qt web engine, replaces the web renderer with the waaaay faster rich text rendering engine.
| -rw-r--r-- | browsertab.cpp | 67 | ||||
| -rw-r--r-- | browsertab.hpp | 11 | ||||
| -rw-r--r-- | browsertab.ui | 26 | ||||
| -rw-r--r-- | geminiwebpage.cpp | 44 | ||||
| -rw-r--r-- | geminiwebpage.hpp | 27 | ||||
| -rw-r--r-- | kristall.pro | 4 |
6 files changed, 77 insertions, 102 deletions
diff --git a/browsertab.cpp b/browsertab.cpp index 46603b6..ebeb0a3 100644 --- a/browsertab.cpp +++ b/browsertab.cpp @@ -11,7 +11,6 @@ BrowserTab::BrowserTab(MainWindow * mainWindow) : QWidget(nullptr), ui(new Ui::BrowserTab), mainWindow(mainWindow), - page(mainWindow), outline() { ui->setupUi(this); @@ -26,11 +25,6 @@ BrowserTab::BrowserTab(MainWindow * mainWindow) : connect(&gemini_client, &GeminiClient::authorisedCertificateRequested, this, &BrowserTab::on_authorisedCertificateRequested); connect(&gemini_client, &GeminiClient::certificateRejected, this, &BrowserTab::on_certificateRejected); - connect(&page, &QWebEnginePage::linkHovered, this, &BrowserTab::on_linkHovered); - connect(&page, &GeminiWebPage::navigationRequest, this, &BrowserTab::on_navigationRequest); - - ui->content->setPage(&page); - this->updateUI(); } @@ -103,10 +97,26 @@ void BrowserTab::on_refresh_button_clicked() void BrowserTab::on_gemini_complete(const QByteArray &data, const QString &mime) { + qDebug() << "Loaded" << data.length() << "bytes of type" << mime; + if(mime.startsWith("text/gemini")) { - this->page.setHtml(translateGeminiToHtml(data, this->outline), this->current_location); - } else { - this->page.setContent(data, mime); + auto html = translateGeminiToHtml(data, this->outline); + + this->ui->textBrowser->setHtml(html); + } + else if(mime.startsWith("text/html")) { + this->ui->textBrowser->setHtml(QString::fromUtf8(data)); + } +#if QT_CONFIG(textmarkdownreader) + else if(mime.startsWith("text/markdown")) { + this->ui->textBrowser->setMarkdown(QString::fromUtf8(data)); + } +#endif + else if(mime.startsWith("text/")) { + this->ui->textBrowser->setText(QString::fromUtf8(data)); + } + else { + this->ui->textBrowser->setText(QString("Unsupported Mime: %1").arg(mime)); } this->successfully_loaded = true; this->updateUI(); @@ -265,10 +275,44 @@ void BrowserTab::on_fav_button_clicked() } +void BrowserTab::on_textBrowser_anchorClicked(const QUrl &url) +{ + qDebug() << url; + + QUrl real_url = url; + if(real_url.isRelative()) + real_url = this->current_location.resolved(url); + + if(real_url.scheme() != "gemini") { + QMessageBox::warning(this, "Kristall", QString("Unsupported url: %1").arg(real_url.toString())); + } + else { + this->navigateTo(real_url); + } +} + +void BrowserTab::on_textBrowser_backwardAvailable(bool arg1) +{ + this->ui->back_button->setEnabled(arg1); +} + +void BrowserTab::on_textBrowser_forwardAvailable(bool arg1) +{ + this->ui->forward_button->setEnabled(arg1); +} + +void BrowserTab::on_textBrowser_highlighted(const QUrl &url) +{ + QUrl real_url = url; + if(real_url.isRelative()) + real_url = this->current_location.resolved(url); + this->mainWindow->setUrlPreview(real_url); +} + void BrowserTab::updateUI() { - this->ui->back_button->setEnabled(this->navigation_history.size() > 0); - this->ui->forward_button->setEnabled(false); + // this->ui->back_button->setEnabled(this->navigation_history.size() > 0); + // this->ui->forward_button->setEnabled(false); this->ui->refresh_button->setEnabled(this->successfully_loaded); @@ -393,3 +437,4 @@ QByteArray BrowserTab::translateGeminiToHtml(const QByteArray &input, DocumentOu )html").toUtf8()); return result; } + diff --git a/browsertab.hpp b/browsertab.hpp index ddaf1b4..79bf9c8 100644 --- a/browsertab.hpp +++ b/browsertab.hpp @@ -5,7 +5,6 @@ #include <QUrl> #include "geminiclient.hpp" -#include "geminiwebpage.hpp" #include "documentoutlinemodel.hpp" namespace Ui { @@ -64,6 +63,14 @@ private slots: void on_fav_button_clicked(); + void on_textBrowser_anchorClicked(const QUrl &arg1); + + void on_textBrowser_backwardAvailable(bool arg1); + + void on_textBrowser_forwardAvailable(bool arg1); + + void on_textBrowser_highlighted(const QUrl &arg1); + private: void setErrorMessage(QString const & msg); @@ -83,8 +90,6 @@ public: QVector<QUrl> navigation_history; - GeminiWebPage page; - bool successfully_loaded = false; DocumentOutlineModel outline; diff --git a/browsertab.ui b/browsertab.ui index 5979733..cbd79fe 100644 --- a/browsertab.ui +++ b/browsertab.ui @@ -127,23 +127,21 @@ </layout> </item> <item> - <widget class="QWebEngineView" name="content"> - <property name="url"> - <url> - <string>about:blank</string> - </url> - </property> - </widget> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QTextBrowser" name="textBrowser"> + <property name="readOnly"> + <bool>true</bool> + </property> + <property name="openLinks"> + <bool>false</bool> + </property> + </widget> + </item> + </layout> </item> </layout> </widget> - <customwidgets> - <customwidget> - <class>QWebEngineView</class> - <extends>QWidget</extends> - <header location="global">QtWebEngineWidgets/QWebEngineView</header> - </customwidget> - </customwidgets> <resources> <include location="icons.qrc"/> </resources> diff --git a/geminiwebpage.cpp b/geminiwebpage.cpp deleted file mode 100644 index 1cbd130..0000000 --- a/geminiwebpage.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "geminiwebpage.hpp" -#include "browsertab.hpp" - -GeminiWebPage::GeminiWebPage(MainWindow * container) : - QWebEnginePage(), - main_window(container) -{ - -} - -bool GeminiWebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) -{ - switch(type) - { - // link navigation - case QWebEnginePage::NavigationTypeLinkClicked: { - bool result = false; - emit this->navigationRequest(url, result); - return result; - } - - // manual navigation - case QWebEnginePage::NavigationTypeTyped: - return true; - - // we do this by hand! - case QWebEnginePage::NavigationTypeFormSubmitted: - case QWebEnginePage::NavigationTypeBackForward: - case QWebEnginePage::NavigationTypeReload: - return false; - - // forbidden by default - case QWebEnginePage::NavigationTypeOther: - case QWebEnginePage::NavigationTypeRedirect: - return false; - } -} - -QWebEnginePage *GeminiWebPage::createWindow(QWebEnginePage::WebWindowType type) -{ - auto tab = main_window->addEmptyTab(true); - - return &tab->page; -} diff --git a/geminiwebpage.hpp b/geminiwebpage.hpp deleted file mode 100644 index a5de627..0000000 --- a/geminiwebpage.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef GEMINIWEBPAGE_HPP -#define GEMINIWEBPAGE_HPP - -#include <QObject> -#include <QWebEnginePage> -#include "mainwindow.hpp" - -class GeminiWebPage : public QWebEnginePage -{ - Q_OBJECT -public: - explicit GeminiWebPage(MainWindow * container); - - -signals: - void navigationRequest(QUrl const & url, bool & allow); - -protected: - bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) override; - - QWebEnginePage *createWindow(QWebEnginePage::WebWindowType type) override; - -private: - MainWindow * main_window; -}; - -#endif // GEMINIWEBPAGE_HPP diff --git a/kristall.pro b/kristall.pro index 20a3219..bd03af0 100644 --- a/kristall.pro +++ b/kristall.pro @@ -1,6 +1,6 @@ QT += core gui -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets webenginewidgets +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets network CONFIG += c++17 @@ -20,7 +20,6 @@ SOURCES += \ documentoutlinemodel.cpp \ favouritecollection.cpp \ geminiclient.cpp \ - geminiwebpage.cpp \ main.cpp \ mainwindow.cpp @@ -29,7 +28,6 @@ HEADERS += \ documentoutlinemodel.hpp \ favouritecollection.hpp \ geminiclient.hpp \ - geminiwebpage.hpp \ mainwindow.hpp FORMS += \ |
