diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-10 00:31:56 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-10 00:31:56 +0200 |
| commit | 656391ecc0555b3462266b886434ae0f120a401c (patch) | |
| tree | bb87b6889c2dae9a5c65c6b9bcb783139bebdf3c /src | |
| parent | 0739bce0be84e8ccebdc632726efd0fd6f612789 (diff) | |
| download | kristall-656391ecc0555b3462266b886434ae0f120a401c.tar.gz | |
Adds some right click menus, fixes bug in gopher.
Diffstat (limited to 'src')
| -rw-r--r-- | src/browsertab.cpp | 36 | ||||
| -rw-r--r-- | src/browsertab.hpp | 2 | ||||
| -rw-r--r-- | src/gophermaprenderer.cpp | 26 | ||||
| -rw-r--r-- | src/gophertypes.txt | 21 | ||||
| -rw-r--r-- | src/kristall.hpp | 2 | ||||
| -rw-r--r-- | src/kristall.pro | 3 | ||||
| -rw-r--r-- | src/main.cpp | 4 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 49 | ||||
| -rw-r--r-- | src/mainwindow.hpp | 4 |
9 files changed, 126 insertions, 21 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp index cde8fc7..2cd4fff 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -64,6 +64,8 @@ BrowserTab::BrowserTab(MainWindow * mainWindow) : this->ui->graphics_browser->setVisible(false); this->ui->text_browser->setVisible(true); + this->ui->text_browser->setContextMenuPolicy(Qt::CustomContextMenu); + this->ui->graphics_browser->setScene(&graphics_scene); } @@ -591,3 +593,37 @@ void BrowserTab::updateUI() this->ui->fav_button->setEnabled(this->successfully_loaded); this->ui->fav_button->setChecked(this->mainWindow->favourites.contains(this->current_location)); } + +#include <QClipboard> + +void BrowserTab::on_text_browser_customContextMenuRequested(const QPoint &pos) +{ + QMenu menu; + + QString anchor = ui->text_browser->anchorAt(pos); + if(not anchor.isEmpty()) { + QUrl real_url { anchor }; + if(real_url.isRelative()) + real_url = this->current_location.resolved(real_url); + + connect(menu.addAction("Follow link…"), &QAction::triggered, [this,real_url]() { + this->navigateTo(real_url, PushImmediate); + }); + + connect(menu.addAction("Open in new tab…"), &QAction::triggered, [this,real_url]() { + mainWindow->addNewTab(false, real_url); + }); + + connect(menu.addAction("Copy link"), &QAction::triggered, [this,real_url]() { + global_clipboard->setText(real_url.toString(QUrl::FullyEncoded)); + }); + + menu.addSeparator(); + } + + connect(menu.addAction("Select all"), &QAction::triggered, [this]() { + this->ui->text_browser->selectAll(); + }); + + menu.exec(ui->text_browser->mapToGlobal(pos)); +} diff --git a/src/browsertab.hpp b/src/browsertab.hpp index 68e10fb..644da70 100644 --- a/src/browsertab.hpp +++ b/src/browsertab.hpp @@ -102,6 +102,8 @@ private slots: void on_requestProgress(qint64 transferred); + void on_text_browser_customContextMenuRequested(const QPoint &pos); + private: void setErrorMessage(QString const & msg); diff --git a/src/gophermaprenderer.cpp b/src/gophermaprenderer.cpp index d1e3bf6..c705883 100644 --- a/src/gophermaprenderer.cpp +++ b/src/gophermaprenderer.cpp @@ -11,25 +11,6 @@ #include "kristall.hpp" -//Canonical Types -//0 Text File -//1 Gopher submenu or link to another gopher server -//2 CCSO Nameserver -//3 Error code returned by a Gopher server to indicate failure -//4 BinHex-encoded file (primarily for Macintosh computers) -//5 DOS file -//6 uuencoded file -//7 Gopher full-text search -//8 Telnet -//9 Binary file -//+ Mirror or alternate server (for load balancing or in case of primary server downtime) -//g GIF file -//I Image file -//T Telnet 3270 -//Non-Canonical Types -//h HTML file -//i Informational message -//s Sound file std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input, const QUrl &root_url, const DocumentStyle &themed_style) { @@ -84,6 +65,7 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input continue; QString icon; + QString scheme = "gopher"; switch (line.at(0)) { case '0': // Text File @@ -112,6 +94,7 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input break; case '8': // Telnet icon = "telnet"; + scheme = "telnet"; break; case '9': // Binary file icon = "binary"; @@ -127,6 +110,7 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input break; case 'T': // Telnet 3270 icon = "telnet"; + scheme = "telnet"; break; //Non-Canonical Types case 'h': // HTML file @@ -163,10 +147,10 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input dst_url = root_url.resolved(QUrl(items.at(1))).toString(); break; case 3: - dst_url = "gopher://" + items.at(2) + "/" + line.mid(0, 1) + items.at(1); + dst_url = scheme + "://" + items.at(2) + "/" + line.mid(0, 1) + items.at(1); break; default: - dst_url = "gopher://" + items.at(2) + ":" + items.at(3) + "/" + line.mid(0, 1) + items.at(1); + dst_url = scheme + "://" + items.at(2) + ":" + items.at(3) + "/" + line.mid(0, 1) + items.at(1); break; } diff --git a/src/gophertypes.txt b/src/gophertypes.txt new file mode 100644 index 0000000..3356dcd --- /dev/null +++ b/src/gophertypes.txt @@ -0,0 +1,21 @@ + +Canonical Types +0 Text File +1 Gopher submenu or link to another gopher server +2 CCSO Nameserver +3 Error code returned by a Gopher server to indicate failure +4 BinHex-encoded file (primarily for Macintosh computers) +5 DOS file +6 uuencoded file +7 Gopher full-text search +8 Telnet +9 Binary file ++ Mirror or alternate server (for load balancing or in case of primary server downtime) +g GIF file +I Image file +T Telnet 3270 +Non-Canonical Types +h HTML file +i Informational message +s Sound file +d Document file diff --git a/src/kristall.hpp b/src/kristall.hpp index 5fbca63..73c0bc5 100644 --- a/src/kristall.hpp +++ b/src/kristall.hpp @@ -2,7 +2,9 @@ #define KRISTALL_HPP #include <QSettings> +#include <QClipboard> extern QSettings global_settings; +extern QClipboard * global_clipboard; #endif // KRISTALL_HPP diff --git a/src/kristall.pro b/src/kristall.pro index 1ff82cf..dc69b8b 100644 --- a/src/kristall.pro +++ b/src/kristall.pro @@ -75,3 +75,6 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin RESOURCES += \ ../lib/BreezeStyleSheets/breeze.qrc \ icons.qrc + +DISTFILES += \ + gophertypes.txt diff --git a/src/main.cpp b/src/main.cpp index 180a49b..b7974de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include "mainwindow.hpp" +#include "kristall.hpp" #include <QApplication> #include <QUrl> @@ -7,11 +8,14 @@ #include <QDebug> QSettings global_settings { "xqTechnologies", "Kristall" }; +QClipboard * global_clipboard; int main(int argc, char *argv[]) { QApplication app(argc, argv); + global_clipboard = app.clipboard(); + QCommandLineParser cli_parser; cli_parser.parse(app.arguments()); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f735b2a..10302d2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -84,6 +84,9 @@ MainWindow::MainWindow(QApplication * app, QWidget *parent) : global_settings.endGroup(); } + this->ui->favourites_view->setContextMenuPolicy(Qt::CustomContextMenu); + this->ui->history_view->setContextMenuPolicy(Qt::CustomContextMenu); + reloadTheme(); } @@ -402,3 +405,49 @@ void MainWindow::on_actionHelp_triggered() { this->addNewTab(true, QUrl("about:help")); } + +void MainWindow::on_history_view_customContextMenuRequested(const QPoint &pos) +{ + if(auto idx = this->ui->history_view->indexAt(pos); idx.isValid()) { + BrowserTab * tab = qobject_cast<BrowserTab*>(this->ui->browser_tabs->currentWidget()); + if(tab != nullptr) { + if(QUrl url = tab->history.get(idx); url.isValid()) { + QMenu menu; + + connect(menu.addAction("Open here"), &QAction::triggered, [tab, idx]() { + // We do the same thing as a double click here + tab->navigateBack(idx); + }); + + connect(menu.addAction("Open in new tab"), &QAction::triggered, [this, url]() { + addNewTab(true, url); + }); + + menu.exec(this->ui->history_view->mapToGlobal(pos)); + } + } + } +} + +void MainWindow::on_favourites_view_customContextMenuRequested(const QPoint &pos) +{ + if(auto idx = this->ui->favourites_view->indexAt(pos); idx.isValid()) { + if(QUrl url = favourites.get(idx); url.isValid()) { + QMenu menu; + + BrowserTab * tab = qobject_cast<BrowserTab*>(this->ui->browser_tabs->currentWidget()); + if(tab != nullptr) { + connect(menu.addAction("Open here"), &QAction::triggered, [tab, url]() { + tab->navigateTo(url, BrowserTab::PushImmediate); + }); + } + + connect(menu.addAction("Open in new tab"), &QAction::triggered, [this, url]() { + addNewTab(true, url); + }); + + menu.exec(this->ui->favourites_view->mapToGlobal(pos)); + + } + } +} diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index 2b5e2ef..954ba5f 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -79,6 +79,10 @@ private slots: void on_actionHelp_triggered(); + void on_history_view_customContextMenuRequested(const QPoint &pos); + + void on_favourites_view_customContextMenuRequested(const QPoint &pos); + private: void reloadTheme(); |
