From b0d17803c8cc8b5148edaee254f0e7127bbb8ae3 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 7 Oct 2018 01:40:04 +0200 Subject: [PATCH] Qt interface: implemented details --- src/interface_qt.cpp | 51 +++++++++++++++++++++++++++++++++++-------- src/interface_qt.hpp | 5 +++++ src/whyblocked.ui | 16 ++++++++++++-- src/whyblocked_add.ui | 2 +- 4 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/interface_qt.cpp b/src/interface_qt.cpp index 257e975..16646e7 100644 --- a/src/interface_qt.cpp +++ b/src/interface_qt.cpp @@ -14,8 +14,10 @@ * along with this program. If not, see . */ +#include #include #include +#include "version.hpp" #include "whyblocked.hpp" #include "interface_qt.hpp" @@ -33,10 +35,12 @@ MainWindow::MainWindow(QMainWindow *parent) : QMainWindow(parent) tableview->horizontalHeader()->resizeSection(0, 300); tableview->setSelectionBehavior(QAbstractItemView::SelectRows); - connect(action_add, &QAction::triggered, this, &MainWindow::add); connect(action_remove, &QAction::triggered, this, &MainWindow::remove); connect(action_about, &QAction::triggered, this, &MainWindow::about); + + connect(tableview, &QTableView::clicked, this, &MainWindow::show_details); + connect(tableview, &QTableView::activated, this, &MainWindow::show_details); } void MainWindow::populate_tableview(QStandardItemModel &model) @@ -83,14 +87,43 @@ void MainWindow::remove() void MainWindow::about() { QMessageBox::about(this, tr("About whyblocked"), - tr("whyblocked reminds you why you blocked someone.

" - "Copyright © 2018 tastytea.
" - "Licence GPLv3: " - "GNU GPL version 3.
" - "This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n" - "and you are welcome to redistribute it under certain conditions.

" - "Sourcecode: " - "https://schlomp.space/tastytea/whyblocked")); + tr("

whyblocked %1

" + "

Reminds you why you blocked someone.

" + "

Sourcecode: " + "https://schlomp.space/tastytea/whyblocked

" + "

Copyright © 2018 tastytea.
" + "Licence GPLv3: " + "GNU GPL version 3.
" + "This program comes with ABSOLUTELY NO WARRANTY. This is free software," + "and you are welcome to redistribute it under certain conditions.

") + .arg(global::version)); +} + +void MainWindow::show_details(QModelIndex index) +{ + const string user = index.sibling(index.row(), 0).data().toString().toStdString(); + result_details result; + string text = ""; + + if (details(user, result)) + { + if (!std::get<2>(result).empty()) + { + text += "Receipts:"; + for (const string &url : std::get<2>(result)) + { + text += "
" + url; + } + text = urls_to_hyperlinks(text); + } + label_receipts->setText(QString::fromStdString((text))); + } +} + +const string MainWindow::urls_to_hyperlinks(const string &text) +{ + std::regex re_url("((https?|gopher|ftps?)\\://[^ <]*)"); + return std::regex_replace(text, re_url, "$1"); } int main(int argc, char *argv[]) diff --git a/src/interface_qt.hpp b/src/interface_qt.hpp index b29849a..d85c5aa 100644 --- a/src/interface_qt.hpp +++ b/src/interface_qt.hpp @@ -17,11 +17,14 @@ #ifndef INTERFACE_QT_HPP #define INTERFACE_QT_HPP +#include #include #include #include "ui_whyblocked.h" #include "ui_whyblocked_add.h" +using std::string; + class MainWindow : public QMainWindow, private Ui::MainWindow { Q_OBJECT @@ -33,9 +36,11 @@ private slots: void add(); void remove(); void about(); + void show_details(QModelIndex index); private: void populate_tableview(QStandardItemModel &model); + const string urls_to_hyperlinks(const string &text); }; #endif // INTERFACE_QT_HPP diff --git a/src/whyblocked.ui b/src/whyblocked.ui index 0fccb9f..81c6061 100644 --- a/src/whyblocked.ui +++ b/src/whyblocked.ui @@ -11,7 +11,7 @@ - MainWindow + whyblocked @@ -20,6 +20,9 @@ + + Click or press enter to view receipts + QAbstractItemView::NoEditTriggers @@ -36,11 +39,20 @@ + + Memory aids, proof + + + Qt::AutoText + + + true + - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse diff --git a/src/whyblocked_add.ui b/src/whyblocked_add.ui index 192b521..d3c514e 100644 --- a/src/whyblocked_add.ui +++ b/src/whyblocked_add.ui @@ -15,7 +15,7 @@ - +