Qt interface: implemented details

develop
tastytea 2018-10-07 01:40:04 +02:00
parent ad308f3dd5
commit b0d17803c8
No known key found for this signature in database
GPG Key ID: CFC39497F1B26E07
4 changed files with 62 additions and 12 deletions

View File

@ -14,8 +14,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <regex>
#include <QMessageBox> #include <QMessageBox>
#include <QDebug> #include <QDebug>
#include "version.hpp"
#include "whyblocked.hpp" #include "whyblocked.hpp"
#include "interface_qt.hpp" #include "interface_qt.hpp"
@ -33,10 +35,12 @@ MainWindow::MainWindow(QMainWindow *parent) : QMainWindow(parent)
tableview->horizontalHeader()->resizeSection(0, 300); tableview->horizontalHeader()->resizeSection(0, 300);
tableview->setSelectionBehavior(QAbstractItemView::SelectRows); tableview->setSelectionBehavior(QAbstractItemView::SelectRows);
connect(action_add, &QAction::triggered, this, &MainWindow::add); connect(action_add, &QAction::triggered, this, &MainWindow::add);
connect(action_remove, &QAction::triggered, this, &MainWindow::remove); connect(action_remove, &QAction::triggered, this, &MainWindow::remove);
connect(action_about, &QAction::triggered, this, &MainWindow::about); 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) void MainWindow::populate_tableview(QStandardItemModel &model)
@ -83,14 +87,43 @@ void MainWindow::remove()
void MainWindow::about() void MainWindow::about()
{ {
QMessageBox::about(this, tr("About whyblocked"), QMessageBox::about(this, tr("About whyblocked"),
tr("<b>whyblocked</b> reminds you why you blocked someone.<br><br>" tr("<p><b>whyblocked</b> %1</p>"
"Copyright © 2018 <a href=\"mailto:tastytea@tastytea.de\">tastytea</a>.<br>" "<p>Reminds you why you blocked someone.</p>"
"Licence GPLv3: <a href=\"https://www.gnu.org/licenses/gpl-3.0.html\">" "<p>Sourcecode: <a href=\"https://schlomp.space/tastytea/whyblocked\">"
"GNU GPL version 3</a>.<br>" "https://schlomp.space/tastytea/whyblocked</a></p>"
"This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n" "<p><small>Copyright © 2018 <a href=\"mailto:tastytea@tastytea.de\">tastytea</a>.<br>"
"and you are welcome to redistribute it under certain conditions.<br><br>" "Licence GPLv3: <a href=\"https://www.gnu.org/licenses/gpl-3.0.html\">"
"Sourcecode: <a href=\"https://schlomp.space/tastytea/whyblocked\">" "GNU GPL version 3</a>.<br>"
"https://schlomp.space/tastytea/whyblocked</a>")); "This program comes with ABSOLUTELY NO WARRANTY. This is free software,"
"and you are welcome to redistribute it under certain conditions.</small></p>")
.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 += "<b>Receipts:</b>";
for (const string &url : std::get<2>(result))
{
text += "<br>" + 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, "<a href=\"$1\">$1</a>");
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])

View File

@ -17,11 +17,14 @@
#ifndef INTERFACE_QT_HPP #ifndef INTERFACE_QT_HPP
#define INTERFACE_QT_HPP #define INTERFACE_QT_HPP
#include <string>
#include <QMainWindow> #include <QMainWindow>
#include <QStandardItemModel> #include <QStandardItemModel>
#include "ui_whyblocked.h" #include "ui_whyblocked.h"
#include "ui_whyblocked_add.h" #include "ui_whyblocked_add.h"
using std::string;
class MainWindow : public QMainWindow, private Ui::MainWindow class MainWindow : public QMainWindow, private Ui::MainWindow
{ {
Q_OBJECT Q_OBJECT
@ -33,9 +36,11 @@ private slots:
void add(); void add();
void remove(); void remove();
void about(); void about();
void show_details(QModelIndex index);
private: private:
void populate_tableview(QStandardItemModel &model); void populate_tableview(QStandardItemModel &model);
const string urls_to_hyperlinks(const string &text);
}; };
#endif // INTERFACE_QT_HPP #endif // INTERFACE_QT_HPP

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>MainWindow</string> <string>whyblocked</string>
</property> </property>
<property name="locale"> <property name="locale">
<locale language="English" country="UnitedKingdom"/> <locale language="English" country="UnitedKingdom"/>
@ -20,6 +20,9 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QTableView" name="tableview"> <widget class="QTableView" name="tableview">
<property name="toolTip">
<string>Click or press enter to view receipts</string>
</property>
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set> <set>QAbstractItemView::NoEditTriggers</set>
</property> </property>
@ -36,11 +39,20 @@
</item> </item>
<item> <item>
<widget class="QLabel" name="label_receipts"> <widget class="QLabel" name="label_receipts">
<property name="toolTip">
<string>Memory aids, proof</string>
</property>
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags"> <property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse</set> <set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -15,7 +15,7 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="layout_grid">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_user"> <widget class="QLabel" name="label_user">
<property name="text"> <property name="text">