diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-05 10:13:45 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-05 10:13:45 +0200 |
| commit | 3508f8a2a0867a886ceca9139ce0dcae2405ff29 (patch) | |
| tree | d20449727b2bd7b99a3f76870349af5db96d5af0 | |
| parent | c0d62ee7beaa0a800e8fbc6edf2d0086ffd3e448 (diff) | |
| download | kristall-3508f8a2a0867a886ceca9139ce0dcae2405ff29.tar.gz | |
Adds support for images served via gemini.
| -rw-r--r-- | browsertab.cpp | 86 | ||||
| -rw-r--r-- | browsertab.hpp | 12 | ||||
| -rw-r--r-- | browsertab.ui | 36 |
3 files changed, 56 insertions, 78 deletions
diff --git a/browsertab.cpp b/browsertab.cpp index 48c2593..856b3f5 100644 --- a/browsertab.cpp +++ b/browsertab.cpp @@ -7,12 +7,15 @@ #include <QMessageBox> #include <QInputDialog> #include <QDockWidget> +#include <QImage> +#include <QPixmap> BrowserTab::BrowserTab(MainWindow * mainWindow) : QWidget(nullptr), ui(new Ui::BrowserTab), mainWindow(mainWindow), - outline() + outline(), + graphics_scene() { ui->setupUi(this); @@ -28,28 +31,27 @@ BrowserTab::BrowserTab(MainWindow * mainWindow) : this->updateUI(); - this->ui->textBrowser->document()->setDocumentMargin(55.0); - this->ui->textBrowser->document()->setDefaultStyleSheet( + this->ui->graphics_browser->setScene(&graphics_scene); + + this->ui->text_browser->document()->setDocumentMargin(55.0); + this->ui->text_browser->document()->setDefaultStyleSheet( R"css( -h1 { - color: red; -} -h2 { - color: green; -} -h3 { - color: blue; -} -span { - color: lime; -} -a { - color: magenta; -} -ul { - -qt-list-indent: 1; - type: square; -} + h1 { + color: red; + } + h2 { + color: green; + } + h3 { + color: gold; + } + a { + color: blue; + } + ul { + -qt-list-indent: 1; + type: square; + } )css"); } @@ -140,26 +142,40 @@ void BrowserTab::on_gemini_complete(const QByteArray &data, const QString &mime) { qDebug() << "Loaded" << data.length() << "bytes of type" << mime; - bool enable_styles = false; + + this->graphics_scene.clear(); + this->ui->text_browser->setText(""); + + this->ui->text_browser->setVisible(mime.startsWith("text/")); + this->ui->graphics_browser->setVisible(mime.startsWith("image/")); if(mime.startsWith("text/gemini")) { auto html = translateGeminiToHtml(data, this->outline); - this->ui->textBrowser->setHtml(html); + this->ui->text_browser->setHtml(html); } else if(mime.startsWith("text/html")) { - this->ui->textBrowser->setHtml(QString::fromUtf8(data)); + this->ui->text_browser->setHtml(QString::fromUtf8(data)); } #if QT_CONFIG(textmarkdownreader) else if(mime.startsWith("text/markdown")) { - this->ui->textBrowser->setMarkdown(QString::fromUtf8(data)); + this->ui->text_browser->setMarkdown(QString::fromUtf8(data)); } #endif else if(mime.startsWith("text/")) { - this->ui->textBrowser->setText(QString::fromUtf8(data)); + this->ui->text_browser->setText(QString::fromUtf8(data)); + } + else if(mime.startsWith("image/")) { + + QImage img; + if(img.loadFromData(data, nullptr)) + { + this->graphics_scene.addPixmap(QPixmap::fromImage(img)); + } } else { - this->ui->textBrowser->setText(QString("Unsupported Mime: %1").arg(mime)); + this->ui->text_browser->setVisible(true); + this->ui->text_browser->setText(QString("Unsupported Mime: %1").arg(mime)); } this->successfully_loaded = true; @@ -319,7 +335,7 @@ void BrowserTab::on_fav_button_clicked() } -void BrowserTab::on_textBrowser_anchorClicked(const QUrl &url) +void BrowserTab::on_text_browser_anchorClicked(const QUrl &url) { qDebug() << url; @@ -335,17 +351,17 @@ void BrowserTab::on_textBrowser_anchorClicked(const QUrl &url) } } -void BrowserTab::on_textBrowser_backwardAvailable(bool arg1) +void BrowserTab::on_text_browser_backwardAvailable(bool arg1) { this->ui->back_button->setEnabled(arg1); } -void BrowserTab::on_textBrowser_forwardAvailable(bool arg1) +void BrowserTab::on_text_browser_forwardAvailable(bool arg1) { this->ui->forward_button->setEnabled(arg1); } -void BrowserTab::on_textBrowser_highlighted(const QUrl &url) +void BrowserTab::on_text_browser_highlighted(const QUrl &url) { QUrl real_url = url; if(real_url.isRelative()) @@ -483,9 +499,3 @@ QByteArray BrowserTab::translateGeminiToHtml(const QByteArray &input, DocumentOu } -#include <QTextBlock> - -void BrowserTab::on_textEdit_textChanged() -{ - this->ui->textBrowser->document()->setDefaultStyleSheet(this->ui->textEdit->toPlainText()); -} diff --git a/browsertab.hpp b/browsertab.hpp index 7ac3a40..cb6c45a 100644 --- a/browsertab.hpp +++ b/browsertab.hpp @@ -3,6 +3,7 @@ #include <QWidget> #include <QUrl> +#include <QGraphicsScene> #include "geminiclient.hpp" #include "documentoutlinemodel.hpp" @@ -63,15 +64,13 @@ private slots: void on_fav_button_clicked(); - void on_textBrowser_anchorClicked(const QUrl &arg1); + void on_text_browser_anchorClicked(const QUrl &arg1); - void on_textBrowser_backwardAvailable(bool arg1); + void on_text_browser_backwardAvailable(bool arg1); - void on_textBrowser_forwardAvailable(bool arg1); + void on_text_browser_forwardAvailable(bool arg1); - void on_textBrowser_highlighted(const QUrl &arg1); - - void on_textEdit_textChanged(); + void on_text_browser_highlighted(const QUrl &arg1); private: void setErrorMessage(QString const & msg); @@ -95,6 +94,7 @@ public: bool successfully_loaded = false; DocumentOutlineModel outline; + QGraphicsScene graphics_scene; }; #endif // BROWSERTAB_HPP diff --git a/browsertab.ui b/browsertab.ui index 11a85d8..a080bbd 100644 --- a/browsertab.ui +++ b/browsertab.ui @@ -129,7 +129,7 @@ <item> <layout class="QHBoxLayout" name="horizontalLayout_2"> <item> - <widget class="QTextBrowser" name="textBrowser"> + <widget class="QTextBrowser" name="text_browser"> <property name="styleSheet"> <string notr="true"/> </property> @@ -155,39 +155,7 @@ p, li { white-space: pre-wrap; } </widget> </item> <item> - <widget class="QTextEdit" name="textEdit"> - <property name="html"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#d69545;">body</span><span style=" color:#bec0c2;"> </span><span style=" color:#d69545;">{</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">margin:</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">10px;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">-qt-block-indent:</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">0;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">/*</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">background-color:</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">black;</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">*/</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">/*</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">color:</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">white;</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">*/</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">}</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">h1</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">{</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">color:</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">red;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">}</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">h2</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">{</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">color:</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">green;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">}</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">h3</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">{</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">color:</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">blue;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">}</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">span</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">{</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">color:</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">lime;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">}</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">a</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">{</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">color:</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">magenta;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">}</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">ul</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">{</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">-qt-list-indent:</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">1;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">type:</span><span style=" font-family:'monospace'; color:#bec0c2;"> </span><span style=" font-family:'monospace'; color:#d69545;">square;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; color:#d69545;">}</span></p></body></html></string> - </property> - </widget> + <widget class="QGraphicsView" name="graphics_browser"/> </item> </layout> </item> |
