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/>.
*/
#include <regex>
#include <QMessageBox>
#include <QDebug>
#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("<b>whyblocked</b> reminds you why you blocked someone.<br><br>"
"Copyright © 2018 <a href=\"mailto:tastytea@tastytea.de\">tastytea</a>.<br>"
"Licence GPLv3: <a href=\"https://www.gnu.org/licenses/gpl-3.0.html\">"
"GNU GPL version 3</a>.<br>"
"This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
"and you are welcome to redistribute it under certain conditions.<br><br>"
"Sourcecode: <a href=\"https://schlomp.space/tastytea/whyblocked\">"
"https://schlomp.space/tastytea/whyblocked</a>"));
tr("<p><b>whyblocked</b> %1</p>"
"<p>Reminds you why you blocked someone.</p>"
"<p>Sourcecode: <a href=\"https://schlomp.space/tastytea/whyblocked\">"
"https://schlomp.space/tastytea/whyblocked</a></p>"
"<p><small>Copyright © 2018 <a href=\"mailto:tastytea@tastytea.de\">tastytea</a>.<br>"
"Licence GPLv3: <a href=\"https://www.gnu.org/licenses/gpl-3.0.html\">"
"GNU GPL version 3</a>.<br>"
"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[])

View File

@ -17,11 +17,14 @@
#ifndef INTERFACE_QT_HPP
#define INTERFACE_QT_HPP
#include <string>
#include <QMainWindow>
#include <QStandardItemModel>
#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

View File

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

View File

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