FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bitcoin/src/qt/overviewpage.cpp at master · blaklite/bitcoin · GitHub
blaklite
/
bitcoin
Public
forked from
bitcoin/bitcoin
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
bitcoin
/
src
/
qt
/
overviewpage.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
214 lines (179 loc) · 7.12 KB
Breadcrumbs
bitcoin
/
src
/
qt
/
overviewpage.cpp
Copy path
File metadata and controls
214 lines (179 loc) · 7.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
overviewpage.h
"
#
include
"
ui_overviewpage.h
"
#
include
"
clientmodel.h
"
#
include
"
walletmodel.h
"
#
include
"
bitcoinunits.h
"
#
include
"
optionsmodel.h
"
#
include
"
transactiontablemodel.h
"
#
include
"
transactionfilterproxy.h
"
#
include
"
guiutil.h
"
#
include
"
guiconstants.h
"
#
include
<
QAbstractItemDelegate
>
#
include
<
QPainter
>
#
define
DECORATION_SIZE
64
#
define
NUM_ITEMS
3
class
TxViewDelegate
:
public
QAbstractItemDelegate
{
Q_OBJECT
public:
TxViewDelegate
(): QAbstractItemDelegate(), unit(BitcoinUnits::
BTC
)
{
}
inline
void
paint
(QPainter *painter,
const
QStyleOptionViewItem &option,
const
QModelIndex &index )
const
{
painter->
save
();
QIcon icon = qvariant_cast<QIcon>(index.
data
(Qt::DecorationRole));
QRect mainRect = option.
rect
;
QRect
decorationRect
(mainRect.
topLeft
(),
QSize
(
DECORATION_SIZE
,
DECORATION_SIZE
));
int
xspace =
DECORATION_SIZE
+
8
;
int
ypad =
6
;
int
halfheight = (mainRect.
height
() -
2
*ypad)/
2
;
QRect
amountRect
(mainRect.
left
() + xspace, mainRect.
top
()+ypad, mainRect.
width
() - xspace, halfheight);
QRect
addressRect
(mainRect.
left
() + xspace, mainRect.
top
()+ypad+halfheight, mainRect.
width
() - xspace, halfheight);
icon.
paint
(painter, decorationRect);
QDateTime date = index.
data
(TransactionTableModel::DateRole).
toDateTime
();
QString address = index.
data
(Qt::DisplayRole).
toString
();
qint64 amount = index.
data
(TransactionTableModel::AmountRole).
toLongLong
();
bool
confirmed = index.
data
(TransactionTableModel::ConfirmedRole).
toBool
();
QVariant value = index.
data
(Qt::ForegroundRole);
QColor foreground = option.
palette
.
color
(QPalette::Text);
if
(value.
canConvert
<QBrush>())
{
QBrush brush = qvariant_cast<QBrush>(value);
foreground = brush.
color
();
}
painter->
setPen
(foreground);
painter->
drawText
(addressRect, Qt::AlignLeft|Qt::AlignVCenter, address);
if
(amount <
0
)
{
foreground =
COLOR_NEGATIVE
;
}
else
if
(!confirmed)
{
foreground =
COLOR_UNCONFIRMED
;
}
else
{
foreground = option.
palette
.
color
(QPalette::Text);
}
painter->
setPen
(foreground);
QString amountText =
BitcoinUnits::formatWithUnit
(unit, amount,
true
);
if
(!confirmed)
{
amountText =
QString
(
"
[
"
) + amountText +
QString
(
"
]
"
);
}
painter->
drawText
(amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText);
painter->
setPen
(option.
palette
.
color
(QPalette::Text));
painter->
drawText
(amountRect, Qt::AlignLeft|Qt::AlignVCenter,
GUIUtil::dateTimeStr
(date));
painter->
restore
();
}
inline
QSize
sizeHint
(
const
QStyleOptionViewItem &option,
const
QModelIndex &index)
const
{
return
QSize
(
DECORATION_SIZE
,
DECORATION_SIZE
);
}
int
unit;
};
#
include
"
overviewpage.moc
"
OverviewPage::OverviewPage
(QWidget *parent) :
QWidget(parent),
ui(
new
Ui::OverviewPage),
clientModel(
0
),
walletModel(
0
),
currentBalance(-
1
),
currentUnconfirmedBalance(-
1
),
currentImmatureBalance(-
1
),
txdelegate(
new
TxViewDelegate()),
filter(
0
)
{
ui->
setupUi
(
this
);
//
Recent transactions
ui->
listTransactions
->
setItemDelegate
(txdelegate);
ui->
listTransactions
->
setIconSize
(
QSize
(
DECORATION_SIZE
,
DECORATION_SIZE
));
ui->
listTransactions
->
setMinimumHeight
(
NUM_ITEMS
* (
DECORATION_SIZE
+
2
));
ui->
listTransactions
->
setAttribute
(Qt::WA_MacShowFocusRect,
false
);
connect
(ui->
listTransactions
,
SIGNAL
(
clicked
(QModelIndex)),
this
,
SLOT
(
handleTransactionClicked
(QModelIndex)));
//
init "out of sync" warning labels
ui->
labelWalletStatus
->
setText
(
"
(
"
+
tr
(
"
out of sync
"
) +
"
)
"
);
ui->
labelTransactionsStatus
->
setText
(
"
(
"
+
tr
(
"
out of sync
"
) +
"
)
"
);
//
start with displaying the "out of sync" warnings
showOutOfSyncWarning
(
true
);
}
void
OverviewPage::handleTransactionClicked
(
const
QModelIndex &index)
{
if
(filter)
emit
transactionClicked
(filter->
mapToSource
(index));
}
OverviewPage::~OverviewPage
()
{
delete
ui;
}
void
OverviewPage::setBalance
(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance)
{
int
unit = walletModel->
getOptionsModel
()->
getDisplayUnit
();
currentBalance = balance;
currentUnconfirmedBalance = unconfirmedBalance;
currentImmatureBalance = immatureBalance;
ui->
labelBalance
->
setText
(
BitcoinUnits::formatWithUnit
(unit, balance));
ui->
labelUnconfirmed
->
setText
(
BitcoinUnits::formatWithUnit
(unit, unconfirmedBalance));
ui->
labelImmature
->
setText
(
BitcoinUnits::formatWithUnit
(unit, immatureBalance));
ui->
labelTotal
->
setText
(
BitcoinUnits::formatWithUnit
(unit, balance + unconfirmedBalance + immatureBalance));
//
only show immature (newly mined) balance if it's non-zero, so as not to complicate things
//
for the non-mining users
bool
showImmature = immatureBalance !=
0
;
ui->
labelImmature
->
setVisible
(showImmature);
ui->
labelImmatureText
->
setVisible
(showImmature);
}
void
OverviewPage::setClientModel
(ClientModel *model)
{
this
->
clientModel
= model;
if
(model)
{
//
Show warning if this is a prerelease version
connect
(model,
SIGNAL
(
alertsChanged
(QString)),
this
,
SLOT
(
updateAlerts
(QString)));
updateAlerts
(model->
getStatusBarWarnings
());
}
}
void
OverviewPage::setWalletModel
(WalletModel *model)
{
this
->
walletModel
= model;
if
(model && model->
getOptionsModel
())
{
//
Set up transaction list
filter =
new
TransactionFilterProxy
();
filter->
setSourceModel
(model->
getTransactionTableModel
());
filter->
setLimit
(
NUM_ITEMS
);
filter->
setDynamicSortFilter
(
true
);
filter->
setSortRole
(Qt::EditRole);
filter->
sort
(TransactionTableModel::Status, Qt::DescendingOrder);
ui->
listTransactions
->
setModel
(filter);
ui->
listTransactions
->
setModelColumn
(TransactionTableModel::ToAddress);
//
Keep up to date with wallet
setBalance
(model->
getBalance
(), model->
getUnconfirmedBalance
(), model->
getImmatureBalance
());
connect
(model,
SIGNAL
(
balanceChanged
(qint64, qint64, qint64)),
this
,
SLOT
(
setBalance
(qint64, qint64, qint64)));
connect
(model->
getOptionsModel
(),
SIGNAL
(
displayUnitChanged
(
int
)),
this
,
SLOT
(
updateDisplayUnit
()));
}
//
update the display unit, to not use the default ("BTC")
updateDisplayUnit
();
}
void
OverviewPage::updateDisplayUnit
()
{
if
(walletModel && walletModel->
getOptionsModel
())
{
if
(currentBalance != -
1
)
setBalance
(currentBalance, currentUnconfirmedBalance, currentImmatureBalance);
//
Update txdelegate->unit with the current unit
txdelegate->
unit
= walletModel->
getOptionsModel
()->
getDisplayUnit
();
ui->
listTransactions
->
update
();
}
}
void
OverviewPage::updateAlerts
(
const
QString &warnings)
{
this
->
ui
->
labelAlerts
->
setVisible
(!warnings.
isEmpty
());
this
->
ui
->
labelAlerts
->
setText
(warnings);
}
void
OverviewPage::showOutOfSyncWarning
(
bool
fShow
)
{
ui->
labelWalletStatus
->
setVisible
(
fShow
);
ui->
labelTransactionsStatus
->
setVisible
(
fShow
);
}
Back
|
FazBrowse Home
|
New Git URL