PIVX Core  5.6.99
P2P Digital Currency
governancewidget.h
Go to the documentation of this file.
1 // Copyright (c) 2021 The PIVX Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef PIVX_QT_GOVERNANCEWIDGET_H
6 #define PIVX_QT_GOVERNANCEWIDGET_H
7 
8 #include "proposalcard.h"
9 #include "pwidget.h"
10 
11 #include <QGridLayout>
12 #include <QStandardItemModel>
13 #include <QStandardItem>
14 #include <QStyledItemDelegate>
15 #include <QApplication>
16 
17 namespace Ui {
18 class governancewidget;
19 }
20 
21 QT_BEGIN_NAMESPACE
22 class QTimer;
23 QT_END_NAMESPACE
24 
25 class MNModel;
26 class PIVXGUI;
27 class GovernanceModel;
28 class TooltipMenu;
29 
30 class Delegate : public QStyledItemDelegate
31 {
32  Q_OBJECT
33 public:
34  explicit Delegate(QObject *parent = nullptr) :
35  QStyledItemDelegate(parent) {}
36 
37  void setValues(QList<QString> _values) {
38  values = std::move(_values);
39  }
40 
41  void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override {
42  if (!index.isValid())
43  return;
44 
45  QStyleOptionViewItem opt = option;
46  QStyle *style = option.widget ? option.widget->style() : QApplication::style();
47  opt.text = values.value(index.row());
48  style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, option.widget);
49  }
50 
51 private:
52  QList<QString> values;
53 };
54 
55 class GovernanceWidget : public PWidget
56 {
57  Q_OBJECT
58 
59 public:
60  explicit GovernanceWidget(PIVXGUI* parent);
61  ~GovernanceWidget() override;
62 
63  void showEvent(QShowEvent *event) override;
64  void hideEvent(QHideEvent *event) override;
65  void wheelEvent(QWheelEvent* event) override;
66  void resizeEvent(QResizeEvent *event) override;
67  void loadClientModel() override;
68  void loadWalletModel() override;
69  void setGovModel(GovernanceModel* _model);
70  void setMNModel(MNModel* _mnModel);
71 
72 public Q_SLOTS:
73  void tierTwoSynced(bool IsSync);
74  void onFilterChanged(const QString& value);
75  void chainHeightChanged(int height);
76  void onVoteForPropClicked(const ProposalInfo& proposalInfo);
77  void onCreatePropClicked();
78  void onMenuClicked(ProposalCard* card);
79  //
80  void onCopyUrl();
81  void onOpenClicked();
82  void onMoreInfoClicked();
83 
84 private:
85  Ui::governancewidget *ui;
87  MNModel* mnModel{nullptr};
88  bool isSync{false};
89  QGridLayout* gridLayout{nullptr}; // cards
90  std::vector<ProposalCard*> cards;
91  int propsPerRow = 0;
92  QTimer* refreshTimer{nullptr};
93 
94  TooltipMenu* propMenu{nullptr};
96 
97  // Proposals filter
99 
100  void showEmptyScreen(bool show);
101  void tryGridRefresh(bool force=false);
103  void refreshCardsGrid(bool forceRefresh);
105 };
106 
107 #endif // PIVX_QT_GOVERNANCEWIDGET_H
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
void setValues(QList< QString > _values)
QList< QString > values
Delegate(QObject *parent=nullptr)
GovernanceWidget(PIVXGUI *parent)
void refreshCardsGrid(bool forceRefresh)
void showEvent(QShowEvent *event) override
void tryGridRefresh(bool force=false)
void onMenuClicked(ProposalCard *card)
std::vector< ProposalCard * > cards
void resizeEvent(QResizeEvent *event) override
void showEmptyScreen(bool show)
GovernanceModel * governanceModel
void setGovModel(GovernanceModel *_model)
void onVoteForPropClicked(const ProposalInfo &proposalInfo)
void loadWalletModel() override
void chainHeightChanged(int height)
ProposalCard * menuCard
ProposalCard * newCard()
Optional< ProposalInfo::Status > statusFilter
Ui::governancewidget * ui
TooltipMenu * propMenu
void hideEvent(QHideEvent *event) override
void wheelEvent(QWheelEvent *event) override
void setMNModel(MNModel *_mnModel)
~GovernanceWidget() override
void tierTwoSynced(bool IsSync)
void onFilterChanged(const QString &value)
void loadClientModel() override
QGridLayout * gridLayout
PIVX GUI main class.
Definition: pivxgui.h:46
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12