mirror of
https://github.com/wownero/wowlet.git
synced 2026-11-19 06:34:12 +01:00
Forum post widget showing latest from forum.wownero.com
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// Copyright (c) 2020-2021, The Monero Project.
|
||||
|
||||
#ifndef WOWLET_FORUMPOST_H
|
||||
#define WOWLET_FORUMPOST_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
struct ForumPost {
|
||||
ForumPost(const QString &title, const QString &author, const QString &permalink, int comments)
|
||||
: title(title), author(author), permalink(permalink), comments(comments){};
|
||||
|
||||
QString title;
|
||||
QString author;
|
||||
QString permalink;
|
||||
int comments;
|
||||
};
|
||||
|
||||
#endif //WOWLET_FORUMPOST_H
|
||||
@@ -0,0 +1,74 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// Copyright (c) 2020-2021, The Monero Project.
|
||||
|
||||
#include <QStandardItemModel>
|
||||
#include <QTableWidget>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include "model/ForumModel.h"
|
||||
#include "forumwidget.h"
|
||||
#include "ui_forumwidget.h"
|
||||
#include "utils/utils.h"
|
||||
#include "utils/config.h"
|
||||
|
||||
ForumWidget::ForumWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ForumWidget),
|
||||
m_model(new ForumModel(this)),
|
||||
m_contextMenu(new QMenu(this))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->tableView->setModel(m_model);
|
||||
this->setupTable();
|
||||
|
||||
m_contextMenu->addAction("View thread", this, &ForumWidget::linkClicked);
|
||||
m_contextMenu->addAction("Copy link", this, &ForumWidget::copyUrl);
|
||||
connect(ui->tableView, &QHeaderView::customContextMenuRequested, this, &ForumWidget::showContextMenu);
|
||||
|
||||
connect(ui->tableView, &QTableView::doubleClicked, this, &ForumWidget::linkClicked);
|
||||
|
||||
ui->tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
}
|
||||
|
||||
ForumModel* ForumWidget::model() {
|
||||
return m_model;
|
||||
}
|
||||
|
||||
void ForumWidget::linkClicked() {
|
||||
QModelIndex index = ui->tableView->currentIndex();
|
||||
auto post = m_model->post(index.row());
|
||||
|
||||
if (post)
|
||||
Utils::externalLinkWarning(this, post->permalink);
|
||||
}
|
||||
|
||||
void ForumWidget::copyUrl() {
|
||||
QModelIndex index = ui->tableView->currentIndex();
|
||||
auto post = m_model->post(index.row());
|
||||
|
||||
if (post) {
|
||||
Utils::copyToClipboard(post->permalink);
|
||||
emit setStatusText("Link copied to clipboard", true, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
void ForumWidget::setupTable() {
|
||||
ui->tableView->verticalHeader()->setVisible(false);
|
||||
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
|
||||
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
ui->tableView->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch);
|
||||
}
|
||||
|
||||
void ForumWidget::showContextMenu(const QPoint &pos) {
|
||||
QModelIndex index = ui->tableView->indexAt(pos);
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_contextMenu->exec(ui->tableView->viewport()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
ForumWidget::~ForumWidget() {
|
||||
delete ui;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// Copyright (c) 2020-2021, The Monero Project.
|
||||
|
||||
#ifndef FORUMWIDGET_H
|
||||
#define FORUMWIDGET_H
|
||||
|
||||
#include <QMenu>
|
||||
#include <QWidget>
|
||||
#include <QItemSelection>
|
||||
|
||||
#include "model/ForumModel.h"
|
||||
|
||||
namespace Ui {
|
||||
class ForumWidget;
|
||||
}
|
||||
|
||||
class ForumWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ForumWidget(QWidget *parent = nullptr);
|
||||
~ForumWidget();
|
||||
ForumModel* model();
|
||||
|
||||
public slots:
|
||||
void linkClicked();
|
||||
|
||||
signals:
|
||||
void setStatusText(const QString &msg, bool override, int timeout);
|
||||
|
||||
private:
|
||||
void setupTable();
|
||||
void showContextMenu(const QPoint &pos);
|
||||
void copyUrl();
|
||||
|
||||
Ui::ForumWidget *ui;
|
||||
ForumModel* const m_model;
|
||||
QMenu *m_contextMenu;
|
||||
};
|
||||
|
||||
#endif // FORUMWIDGET_H
|
||||
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ForumWidget</class>
|
||||
<widget class="QWidget" name="ForumWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>492</width>
|
||||
<height>409</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTableView" name="tableView">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<slots>
|
||||
<slot>linkClicked()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user