forked from dashpay/dash
/
dashboardwidget.cpp
347 lines (274 loc) · 11.1 KB
/
dashboardwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#include "qt/pivx/dashboardwidget.h"
#include "qt/pivx/forms/ui_dashboardwidget.h"
#include "qt/pivx/sendconfirmdialog.h"
#include "qt/pivx/txrow.h"
#include "qt/pivx/qtutils.h"
#include "walletmodel.h"
#include "optionsmodel.h"
#include "qt/pivx/settings/settingsfaqwidget.h"
#include <QFile>
#include <QAbstractItemDelegate>
#include <QPainter>
#include <QSettings>
#include <QModelIndex>
#include <QObject>
#include <QPaintEngine>
#include <QGraphicsDropShadowEffect>
#include <iostream>
/*
// Chart
#include <QtCharts/QChartView>
#include <QtCharts/QBarSeries>
#include <QtCharts/QBarSet>
#include <QtCharts/QLegend>
#include <QtCharts/QBarCategoryAxis>
#include <QtCharts/QValueAxis>
*/
#include <QGraphicsLayout>
#define DECORATION_SIZE 60
#define NUM_ITEMS 3
#include "moc_dashboardwidget.cpp"
DashboardWidget::DashboardWidget(PIVXGUI* _window, QWidget *parent) :
QWidget(parent),
ui(new Ui::DashboardWidget),
window(_window)
{
ui->setupUi(this);
txHolder = new TxViewHolder(isLightTheme());
txViewDelegate = new FurAbstractListItemDelegate(
DECORATION_SIZE,
txHolder,
this
);
// Load css.
this->setStyleSheet(parent->styleSheet());
this->setContentsMargins(0,0,0,0);
setProperty("cssClass", "container");
// Containers
ui->left->setProperty("cssClass", "container");
ui->left->setContentsMargins(0,0,0,0);
ui->right->setProperty("cssClass", "container-right");
ui->right->setContentsMargins(20,20,20,20);
// Title
ui->labelTitle->setProperty("cssClass", "text-title-screen");
ui->labelTitle2->setText(tr("Staking Rewards"));
ui->labelTitle2->setProperty("cssClass", "text-title-screen");
/* Subtitle */
ui->labelSubtitle->setText(tr("You can view your account's history"));
ui->labelSubtitle->setProperty("cssClass", "text-subtitle");
// Staking Information
ui->labelMessage->setText("Amount of PIV and zPIV staked.");
ui->labelMessage->setProperty("cssClass", "text-subtitle");
ui->labelSquarePiv->setProperty("cssClass", "square-chart-piv");
ui->labelSquarezPiv->setProperty("cssClass", "square-chart-zpiv");
ui->labelPiv->setProperty("cssClass", "text-chart-piv");
ui->labelZpiv->setProperty("cssClass", "text-chart-zpiv");
// Staking Amount
QFont fontBold;
fontBold.setWeight(QFont::Bold);
ui->labelChart->setProperty("cssClass", "legend-chart");
ui->labelAmountPiv->setProperty("cssClass", "text-stake-piv");
ui->labelAmountPiv->setText("9 PIV");
ui->labelAmountZpiv->setProperty("cssClass", "text-stake-zpiv");
ui->labelAmountZpiv->setText("9 zPIV");
ui->labelAmountPiv->setProperty("cssClass", "text-stake-piv-disable");
ui->labelAmountZpiv->setProperty("cssClass", "text-stake-zpiv-disable");
// Chart
//ui->verticalWidgetChart->setProperty("cssClass", "container-chart");
ui->pushButtonHour->setProperty("cssClass", "btn-check-time");
ui->pushButtonDay->setProperty("cssClass", "btn-check-time");
ui->pushButtonWeek->setProperty("cssClass", "btn-check-time");
ui->pushButtonMonth->setProperty("cssClass", "btn-check-time");
ui->pushButtonYear->setProperty("cssClass", "btn-check-time");
// Sort Transactions
ui->comboBoxSort->setProperty("cssClass", "btn-combo");
ui->comboBoxSort->setEditable(true);
SortEdit* lineEdit = new SortEdit(ui->comboBoxSort);
lineEdit->setReadOnly(true);
lineEdit->setAlignment(Qt::AlignRight);
ui->comboBoxSort->setLineEdit(lineEdit);
ui->comboBoxSort->setStyleSheet("selection-background-color:transparent; selection-color:transparent;");
connect(lineEdit, SIGNAL(Mouse_Pressed()), this, SLOT(onSortTxPressed()));
ui->comboBoxSort->setView(new QListView());
ui->comboBoxSort->addItem("Date");
ui->comboBoxSort->addItem("Amount");
//ui->comboBoxSort->addItem("Sent");
//ui->comboBoxSort->addItem("Received");
connect(ui->comboBoxSort, SIGNAL(currentIndexChanged(const QString&)), this,SLOT(onSortChanged(const QString&)));
// transactions
ui->listTransactions->setProperty("cssClass", "container");
ui->listTransactions->setItemDelegate(txViewDelegate);
ui->listTransactions->setIconSize(QSize(DECORATION_SIZE, DECORATION_SIZE));
ui->listTransactions->setMinimumHeight(NUM_ITEMS * (DECORATION_SIZE + 2));
ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false);
ui->listTransactions->setSelectionBehavior(QAbstractItemView::SelectRows);
//ui->listTransactions->setVisible(false);
//Empty List
ui->emptyContainer->setVisible(false);
ui->pushImgEmpty->setProperty("cssClass", "img-empty-transactions");
ui->labelEmpty->setText("No transactions yet");
ui->labelEmpty->setProperty("cssClass", "text-empty");
ui->chartContainer->setProperty("cssClass", "container-chart");
ui->pushImgEmptyChart->setProperty("cssClass", "img-empty-staking-on");
ui->labelEmptyChart->setText("Staking off");
ui->btnHowTo->setText("How to get PIV or zPIV");
ui->btnHowTo->setProperty("cssClass", "btn-secundary");
// Staking off
//ui->pushImgEmptyChart->setProperty("cssClass", "img-empty-staking-off");
//ui->labelEmptyChart->setText("Staking off");
ui->labelEmptyChart->setText("Staking on");
ui->labelEmptyChart->setProperty("cssClass", "text-empty");
ui->labelMessageEmpty->setText("You can activate and deactivate the Staking mode in the status bar at the top right of the wallet");
ui->labelMessageEmpty->setProperty("cssClass", "text-subtitle");
// load chart
loadChart();
// Chart State
ui->layoutChart->setVisible(false);
ui->emptyContainerChart->setVisible(true);
connect(ui->listTransactions, SIGNAL(clicked(QModelIndex)), this, SLOT(handleTransactionClicked(QModelIndex)));
// Style
connect(window, SIGNAL(themeChanged(bool, QString&)), this, SLOT(changeTheme(bool, QString&)));
}
void DashboardWidget::handleTransactionClicked(const QModelIndex &index){
ui->listTransactions->setCurrentIndex(index);
QModelIndex rIndex = (filter) ? filter->mapToSource(index) : index;
window->showHide(true);
TxDetailDialog *dialog = new TxDetailDialog(window, false);
dialog->setData(walletModel, rIndex);
openDialogWithOpaqueBackgroundY(dialog, window, 3, 6);
// Back to regular status
ui->listTransactions->scrollTo(index);
ui->listTransactions->clearSelection();
ui->listTransactions->setFocus();
}
void DashboardWidget::loadChart(){
/*
set0 = new QBarSet("PIV");
set0->setColor(QColor(176,136,255));
set1 = new QBarSet("zPIV");
set1->setColor(QColor(92,75,125));
*set0 << 4 << 2 << 4 << 6;
*set1 << 6 << 9 << 3 << 6;
QBarSeries *series = new QBarSeries();
series->append(set0);
series->append(set1);
// bar width
series->setBarWidth(0.8);
chart = new QChart();
chart->addSeries(series);
// title
//chart->setTitle("Simple barchart example");
chart->setAnimationOptions(QChart::SeriesAnimations);
QStringList categories;
categories << "Jan" << "Feb" << "Mar" << "Apr";
axisX = new QBarCategoryAxis();
axisX->append(categories);
chart->addAxis(axisX, Qt::AlignBottom);
series->attachAxis(axisX);
axisY = new QValueAxis();
axisY->setRange(0,12);
chart->addAxis(axisY, Qt::AlignRight);
series->attachAxis(axisY);
// Legend
chart->legend()->setVisible(false);
chart->legend()->setAlignment(Qt::AlignTop);
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
QVBoxLayout *baseScreensContainer = new QVBoxLayout(this);
baseScreensContainer->setMargin(0);
ui->chartContainer->setLayout(baseScreensContainer);
ui->chartContainer->layout()->addWidget(chartView);
ui->chartContainer->setProperty("cssClass", "container-chart");
// Set colors
changeChartColors();
// Chart margin removed.
chart->layout()->setContentsMargins(0, 0, 0, 0);
chart->setBackgroundRoundness(0);
*/
}
void DashboardWidget::changeChartColors(){
/*
// Colors
QColor gridLineColorX;
QColor linePenColorY;
QColor backgroundColor;
QColor gridY;
if(isLightTheme()){
gridLineColorX = QColor(255,255,255);
linePenColorY = gridLineColorX;
backgroundColor = linePenColorY;
}else{
gridY = QColor("#40ffffff");
axisY->setGridLineColor(gridY);
gridLineColorX = QColor(15,11,22);
linePenColorY = gridLineColorX;
backgroundColor = linePenColorY;
}
axisX->setGridLineColor(gridLineColorX);
axisY->setLinePenColor(linePenColorY);
chart->setBackgroundBrush(QBrush(backgroundColor));
set0->setBorderColor(gridLineColorX);
set1->setBorderColor(gridLineColorX);
*/
}
void DashboardWidget::setWalletModel(WalletModel* model){
walletModel = model;
if (model && model->getOptionsModel()) {
txModel = model->getTransactionTableModel();
// Set up transaction list
filter = new TransactionFilterProxy();
filter->setSourceModel(txModel);
filter->sort(TransactionTableModel::Date, Qt::DescendingOrder);
txHolder->setFilter(filter);
ui->listTransactions->setModel(filter);
ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress);
if(txModel->size() == 0){
ui->emptyContainer->setVisible(true);
ui->listTransactions->setVisible(false);
connect(txModel, SIGNAL(firstTxArrived()), this, SLOT(showList()));
connect(ui->pushImgEmpty, SIGNAL(clicked()), this, SLOT(openFAQ()));
connect(ui->btnHowTo, SIGNAL(clicked()), this, SLOT(openFAQ()));
}
}
// update the display unit, to not use the default ("PIV")
updateDisplayUnit();
}
void DashboardWidget::openFAQ(){
window->showHide(true);
SettingsFaqWidget* dialog = new SettingsFaqWidget(window);
openDialogWithOpaqueBackgroundFullScreen(dialog, window);
}
void DashboardWidget::showList(){
ui->emptyContainer->setVisible(false);
ui->listTransactions->setVisible(true);
}
void DashboardWidget::updateDisplayUnit() {
if (walletModel && walletModel->getOptionsModel()) {
nDisplayUnit = walletModel->getOptionsModel()->getDisplayUnit();
txHolder->setDisplayUnit(nDisplayUnit);
ui->listTransactions->update();
}
}
void DashboardWidget::onSortTxPressed(){
ui->comboBoxSort->showPopup();
}
void DashboardWidget::onSortChanged(const QString& value){
if(!value.isNull()) {
if (value == "Amount")
filter->sort(TransactionTableModel::Amount, Qt::DescendingOrder);
else if (value == "Date")
filter->sort(TransactionTableModel::Date, Qt::DescendingOrder);
ui->listTransactions->update();
}
}
void DashboardWidget::changeTheme(bool isLightTheme, QString& theme){
// Change theme in all of the childs here..
this->setStyleSheet(theme);
static_cast<TxViewHolder*>(this->txViewDelegate->getRowFactory())->isLightTheme = isLightTheme;
this->changeChartColors();
updateStyle(this);
}
DashboardWidget::~DashboardWidget()
{
delete ui;
}