Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
guiutil.h
Go to the documentation of this file.
1// Copyright (c) 2011-2016 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_QT_GUIUTIL_H
6#define BITCOIN_QT_GUIUTIL_H
7
8#include <consensus/amount.h>
9#include <netaddress.h>
10#include <util/fs.h>
11
12#include <QEvent>
13#include <QHeaderView>
14#include <QItemDelegate>
15#include <QLabel>
16#include <QMessageBox>
17#include <QObject>
18#include <QProgressBar>
19#include <QString>
20#include <QTableView>
21
22#include <chrono>
23
26class CChainParams;
27class Config;
28
29namespace interfaces {
30class Node;
31}
32
35class QAction;
36class QDateTime;
37class QFont;
38class QLineEdit;
39class QMenu;
40class QPoint;
41class QProgressDialog;
42class QUrl;
43class QWidget;
45
49namespace GUIUtil {
50
51// Create human-readable string from date
54
55// Return a monospace font
57
58// Generate an invalid, but convincing address.
59std::string DummyAddress(const CChainParams &params);
60
61// Convert any address into cashaddr
62QString convertToCashAddr(const CChainParams &params, const QString &addr);
63
64// Set up widget for address
65void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);
66
67// Parse "bitcoincash:" URI into recipient object, return true on successful
68// parsing
69bool parseBitcoinURI(const QString &scheme, const QUrl &uri,
75 const SendCoinsRecipient &info);
76
77// Returns true if given address+amount meets "dust" definition
78bool isDust(interfaces::Node &node, const QString &address, const Amount amount,
79 const CChainParams &chainParams);
80
81// HTML escaping for rich text controls
82QString HtmlEscape(const QString &str, bool fMultiLine = false);
83QString HtmlEscape(const std::string &str, bool fMultiLine = false);
84
93void copyEntryData(const QAbstractItemView *view, int column,
94 int role = Qt::EditRole);
95
104
112bool hasEntryData(const QAbstractItemView *view, int column, int role);
113
114void setClipboard(const QString &str);
115
120
135QString getSaveFileName(QWidget *parent, const QString &caption,
136 const QString &dir, const QString &filter,
138
151QString getOpenFileName(QWidget *parent, const QString &caption,
152 const QString &dir, const QString &filter,
154
162Qt::ConnectionType blockingGUIThreadConnection();
163
164// Determine whether a widget is hidden behind other windows
165bool isObscured(QWidget *w);
166
167// Activate, show and raise the widget
168void bringToFront(QWidget *w);
169
170// Set shortcut to close window
171void handleCloseWindowShortcut(QWidget *w);
172
173// Open debug.log
174void openDebugLogfile();
175
176// Open the config file
177bool openBitcoinConf();
178
179// Split a QString using given separator, skipping the empty parts
181
187class ToolTipToRichTextFilter : public QObject {
189
190public:
191 explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = 0);
192
193protected:
194 bool eventFilter(QObject *obj, QEvent *evt) override;
195
196private:
198};
199
207class LabelOutOfFocusEventFilter : public QObject {
209
210public:
211 explicit LabelOutOfFocusEventFilter(QObject *parent);
212 bool eventFilter(QObject *watched, QEvent *event) override;
213};
214
227class TableViewLastColumnResizingFixer : public QObject {
229
230public:
232 int allColsMinimumWidth, QObject *parent);
233 void stretchColumnWidth(int column);
234
235private:
242
244 int getAvailableWidthForColumn(int column);
245 int getColumnsWidth();
249 QHeaderView::ResizeMode resizeMode);
250 void resizeColumn(int nColumnIndex, int width);
251
252private Q_SLOTS:
253 void on_sectionResized(int logicalIndex, int oldSize, int newSize);
255};
256
259
262
265
268
270QString formatDurationStr(std::chrono::seconds dur);
271
274
279QString formatPingTime(std::chrono::microseconds ping_time);
280
282QString formatTimeOffset(int64_t nTimeOffset);
283
285
287
290
291class ClickableLabel : public QLabel {
293
294public:
295 bool hasPixmap() const;
296
301 void clicked(const QPoint &point);
302
303protected:
304 void mouseReleaseEvent(QMouseEvent *event) override;
305};
306
307class ClickableProgressBar : public QProgressBar {
309
314 void clicked(const QPoint &point);
315
316protected:
317 void mouseReleaseEvent(QMouseEvent *event) override;
318};
319
321
322class ItemDelegate : public QItemDelegate {
324public:
325 ItemDelegate(QObject *parent) : QItemDelegate(parent) {}
326
329
330private:
331 bool eventFilter(QObject *object, QEvent *event) override;
332};
333
342int TextWidth(const QFontMetrics &fm, const QString &text);
343
347void LogQtInfo();
348
352void PopupMenu(QMenu *menu, const QPoint &point, QAction *at_action = nullptr);
353
354// Fix known bugs in QProgressDialog class.
356} // namespace GUIUtil
357
358#endif // BITCOIN_QT_GUIUTIL_H
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition chainparams.h:80
void mouseReleaseEvent(QMouseEvent *event) override
Definition guiutil.cpp:928
bool hasPixmap() const
Definition guiutil.cpp:907
void clicked(const QPoint &point)
Emitted when the label is clicked.
void mouseReleaseEvent(QMouseEvent *event) override
Definition guiutil.cpp:932
void clicked(const QPoint &point)
Emitted when the progressbar is clicked.
ItemDelegate(QObject *parent)
Definition guiutil.h:325
bool eventFilter(QObject *object, QEvent *event) override
Definition guiutil.cpp:936
Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and resets their ‘textInt...
Definition guiutil.h:207
bool eventFilter(QObject *watched, QEvent *event) override
Definition guiutil.cpp:481
Makes a QTableView last column feel as if it was being resized from its left border.
Definition guiutil.h:227
void setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode)
Definition guiutil.cpp:516
void resizeColumn(int nColumnIndex, int width)
Definition guiutil.cpp:522
void on_sectionResized(int logicalIndex, int oldSize, int newSize)
Definition guiutil.cpp:572
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
Definition guiutil.h:187
bool eventFilter(QObject *obj, QEvent *evt) override
Definition guiutil.cpp:462
Line edit that can be marked as "invalid" to show input validation feedback.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition fs.h:30
Top-level interface for a bitcoin node (bitcoind process).
Definition node.h:59
Utility functions used by the Bitcoin Qt UI.
Definition bitcoingui.h:58
QString NetworkToQString(Network net)
Convert enum Network to QString.
Definition guiutil.cpp:789
fs::path qstringToBoostPath(const QString &path)
Convert QString to OS specific boost path through UTF-8.
Definition guiutil.cpp:781
bool isObscured(QWidget *w)
Definition guiutil.cpp:382
bool parseBitcoinURI(const QString &scheme, const QUrl &uri, SendCoinsRecipient *out)
Definition guiutil.cpp:144
bool openBitcoinConf()
Definition guiutil.cpp:422
bool isDust(interfaces::Node &node, const QString &address, const Amount amount, const CChainParams &chainParams)
Definition guiutil.cpp:243
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
Definition guiutil.cpp:366
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition guiutil.cpp:251
void PopupMenu(QMenu *menu, const QPoint &point, QAction *at_action)
Call QMenu::popup() only on supported QT_QPA_PLATFORM.
Definition guiutil.cpp:986
QList< QModelIndex > getEntryData(const QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
Definition guiutil.cpp:275
QString formatBytes(uint64_t bytes)
Definition guiutil.cpp:893
QString formatDurationStr(std::chrono::seconds dur)
Convert seconds into a QString with days, hours, mins, secs.
Definition guiutil.cpp:811
void handleCloseWindowShortcut(QWidget *w)
Definition guiutil.cpp:407
void PolishProgressDialog(QProgressDialog *dialog)
Definition guiutil.cpp:953
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get open filename, convenience wrapper for QFileDialog::getOpenFileName.
Definition guiutil.cpp:337
std::string DummyAddress(const CChainParams &params)
Definition guiutil.cpp:106
QString getDefaultDataDirectory()
Determine default data directory for operating system.
Definition guiutil.cpp:290
void copyEntryData(const QAbstractItemView *view, int column, int role)
Copy a field of the currently selected entry of a view to the clipboard.
Definition guiutil.cpp:263
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when ...
Definition guiutil.cpp:294
QString boostPathToQString(const fs::path &path)
Convert OS specific boost path to QString through UTF-8.
Definition guiutil.cpp:785
bool SetStartOnSystemStartup(bool fAutoStart)
Definition guiutil.cpp:770
ClickableProgressBar ProgressBar
Definition guiutil.h:320
void bringToFront(QWidget *w)
Definition guiutil.cpp:390
void LogQtInfo()
Writes to debug.log short info about the used Qt and the host system.
Definition guiutil.cpp:964
QString formatPingTime(std::chrono::microseconds ping_time)
Format a CNodeStats.m_last_ping_time into a user-readable string or display N/A, if 0.
Definition guiutil.cpp:851
void openDebugLogfile()
Definition guiutil.cpp:412
QString dateTimeStr(const QDateTime &date)
Definition guiutil.cpp:78
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition guiutil.cpp:210
QString formatTimeOffset(int64_t nTimeOffset)
Format a CNodeCombinedStats.nTimeOffset into a user-readable string.
Definition guiutil.cpp:859
QString convertToCashAddr(const CChainParams &params, const QString &addr)
Definition guiutil.cpp:121
QString formatServicesStr(quint64 mask)
Format CNodeStats.nServices bitmask into a user-readable string.
Definition guiutil.cpp:835
QString formatNiceTimeOffset(qint64 secs)
Definition guiutil.cpp:864
bool GetStartOnSystemStartup()
Definition guiutil.cpp:767
QStringList splitSkipEmptyParts(const QString &s, const QString &separator)
Definition guiutil.cpp:448
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text.
Definition guiutil.cpp:945
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition guiutil.cpp:130
void setClipboard(const QString &str)
Definition guiutil.cpp:776
bool hasEntryData(const QAbstractItemView *view, int column, int role)
Returns true if the specified field of the currently selected view entry is not empty.
Definition guiutil.cpp:282
QFont fixedPitchFont()
Definition guiutil.cpp:87
qreal calculateIdealFontSize(int width, const QString &text, QFont font, qreal minPointSize, qreal font_size)
Definition guiutil.cpp:915
Definition init.h:28
Network
A network type.
Definition netaddress.h:44
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85