Bitcoin ABC  0.26.3
P2P Digital Currency
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 <fs.h>
10 #include <netaddress.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 
24 class QValidatedLineEdit;
25 class SendCoinsRecipient;
26 class CChainParams;
27 class Config;
28 
29 namespace interfaces {
30 class Node;
31 }
32 
33 QT_BEGIN_NAMESPACE
34 class QAbstractItemView;
35 class QAction;
36 class QDateTime;
37 class QFont;
38 class QLineEdit;
39 class QMenu;
40 class QPoint;
41 class QProgressDialog;
42 class QUrl;
43 class QWidget;
44 QT_END_NAMESPACE
45 
49 namespace GUIUtil {
50 
51 // Create human-readable string from date
52 QString dateTimeStr(const QDateTime &datetime);
53 QString dateTimeStr(qint64 nTime);
54 
55 // Return a monospace font
56 QFont fixedPitchFont();
57 
58 // Generate an invalid, but convincing address.
59 std::string DummyAddress(const CChainParams &params);
60 
61 // Convert any address into cashaddr
62 QString convertToCashAddr(const CChainParams &params, const QString &addr);
63 
64 // Set up widget for address
65 void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);
66 
67 // Parse "bitcoincash:" URI into recipient object, return true on successful
68 // parsing
69 bool parseBitcoinURI(const QString &scheme, const QUrl &uri,
70  SendCoinsRecipient *out);
71 bool parseBitcoinURI(const QString &scheme, QString uri,
72  SendCoinsRecipient *out);
73 QString formatBitcoinURI(const SendCoinsRecipient &info);
74 QString formatBitcoinURI(const CChainParams &params,
75  const SendCoinsRecipient &info);
76 
77 // Returns true if given address+amount meets "dust" definition
78 bool isDust(interfaces::Node &node, const QString &address, const Amount amount,
79  const CChainParams &chainParams);
80 
81 // HTML escaping for rich text controls
82 QString HtmlEscape(const QString &str, bool fMultiLine = false);
83 QString HtmlEscape(const std::string &str, bool fMultiLine = false);
84 
93 void copyEntryData(const QAbstractItemView *view, int column,
94  int role = Qt::EditRole);
95 
103 QList<QModelIndex> getEntryData(const QAbstractItemView *view, int column);
104 
112 bool hasEntryData(const QAbstractItemView *view, int column, int role);
113 
114 void setClipboard(const QString &str);
115 
119 QString getDefaultDataDirectory();
120 
135 QString getSaveFileName(QWidget *parent, const QString &caption,
136  const QString &dir, const QString &filter,
137  QString *selectedSuffixOut);
138 
151 QString getOpenFileName(QWidget *parent, const QString &caption,
152  const QString &dir, const QString &filter,
153  QString *selectedSuffixOut);
154 
163 
164 // Determine whether a widget is hidden behind other windows
165 bool isObscured(QWidget *w);
166 
167 // Activate, show and raise the widget
168 void bringToFront(QWidget *w);
169 
170 // Set shortcut to close window
171 void handleCloseWindowShortcut(QWidget *w);
172 
173 // Open debug.log
174 void openDebugLogfile();
175 
176 // Open the config file
177 bool openBitcoinConf();
178 
179 // Split a QString using given separator, skipping the empty parts
180 QStringList splitSkipEmptyParts(const QString &s, const QString &separator);
181 
187 class ToolTipToRichTextFilter : public QObject {
188  Q_OBJECT
189 
190 public:
191  explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = 0);
192 
193 protected:
194  bool eventFilter(QObject *obj, QEvent *evt) override;
195 
196 private:
198 };
199 
207 class LabelOutOfFocusEventFilter : public QObject {
208  Q_OBJECT
209 
210 public:
211  explicit LabelOutOfFocusEventFilter(QObject *parent);
212  bool eventFilter(QObject *watched, QEvent *event) override;
213 };
214 
227 class TableViewLastColumnResizingFixer : public QObject {
228  Q_OBJECT
229 
230 public:
231  TableViewLastColumnResizingFixer(QTableView *table, int lastColMinimumWidth,
232  int allColsMinimumWidth, QObject *parent);
233  void stretchColumnWidth(int column);
234 
235 private:
236  QTableView *tableView;
242 
244  int getAvailableWidthForColumn(int column);
245  int getColumnsWidth();
248  void setViewHeaderResizeMode(int logicalIndex,
249  QHeaderView::ResizeMode resizeMode);
250  void resizeColumn(int nColumnIndex, int width);
251 
252 private Q_SLOTS:
253  void on_sectionResized(int logicalIndex, int oldSize, int newSize);
254  void on_geometriesChanged();
255 };
256 
258 bool SetStartOnSystemStartup(bool fAutoStart);
259 
261 fs::path qstringToBoostPath(const QString &path);
262 
264 QString boostPathToQString(const fs::path &path);
265 
267 QString NetworkToQString(Network net);
268 
270 QString formatDurationStr(std::chrono::seconds dur);
271 
273 QString formatServicesStr(quint64 mask);
274 
279 QString formatPingTime(std::chrono::microseconds ping_time);
280 
282 QString formatTimeOffset(int64_t nTimeOffset);
283 
284 QString formatNiceTimeOffset(qint64 secs);
285 
286 QString formatBytes(uint64_t bytes);
287 
288 qreal calculateIdealFontSize(int width, const QString &text, QFont font,
289  qreal minPointSize = 4, qreal startPointSize = 14);
290 
291 class ClickableLabel : public QLabel {
292  Q_OBJECT
293 
294 public:
295  bool hasPixmap() const;
296 
297 Q_SIGNALS:
301  void clicked(const QPoint &point);
302 
303 protected:
304  void mouseReleaseEvent(QMouseEvent *event) override;
305 };
306 
307 class ClickableProgressBar : public QProgressBar {
308  Q_OBJECT
309 
310 Q_SIGNALS:
314  void clicked(const QPoint &point);
315 
316 protected:
317  void mouseReleaseEvent(QMouseEvent *event) override;
318 };
319 
321 
322 class ItemDelegate : public QItemDelegate {
323  Q_OBJECT
324 public:
325  ItemDelegate(QObject *parent) : QItemDelegate(parent) {}
326 
327 Q_SIGNALS:
329 
330 private:
331  bool eventFilter(QObject *object, QEvent *event) override;
332 };
333 
342 int TextWidth(const QFontMetrics &fm, const QString &text);
343 
347 void LogQtInfo();
348 
352 void PopupMenu(QMenu *menu, const QPoint &point, QAction *at_action = nullptr);
353 
354 // Fix known bugs in QProgressDialog class.
355 void PolishProgressDialog(QProgressDialog *dialog);
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:74
Definition: config.h:17
void mouseReleaseEvent(QMouseEvent *event) override
Definition: guiutil.cpp:921
bool hasPixmap() const
Definition: guiutil.cpp:900
void clicked(const QPoint &point)
Emitted when the label is clicked.
void mouseReleaseEvent(QMouseEvent *event) override
Definition: guiutil.cpp:925
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:929
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:474
LabelOutOfFocusEventFilter(QObject *parent)
Definition: guiutil.cpp:471
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:509
void resizeColumn(int nColumnIndex, int width)
Definition: guiutil.cpp:515
void on_sectionResized(int logicalIndex, int oldSize, int newSize)
Definition: guiutil.cpp:565
TableViewLastColumnResizingFixer(QTableView *table, int lastColMinimumWidth, int allColsMinimumWidth, QObject *parent)
Initializes all internal variables and prepares the the resize modes of the last 2 columns of the tab...
Definition: guiutil.cpp:592
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:455
ToolTipToRichTextFilter(int size_threshold, QObject *parent=0)
Definition: guiutil.cpp:451
Line edit that can be marked as "invalid" to show input validation feedback.
Path class wrapper to prepare application code for transition from boost::filesystem library to std::...
Definition: fs.h:33
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:57
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:58
QString NetworkToQString(Network net)
Convert enum Network to QString.
Definition: guiutil.cpp:782
fs::path qstringToBoostPath(const QString &path)
Convert QString to OS specific boost path through UTF-8.
Definition: guiutil.cpp:774
bool isObscured(QWidget *w)
Definition: guiutil.cpp:374
bool parseBitcoinURI(const QString &scheme, const QUrl &uri, SendCoinsRecipient *out)
Definition: guiutil.cpp:136
bool openBitcoinConf()
Definition: guiutil.cpp:414
bool isDust(interfaces::Node &node, const QString &address, const Amount amount, const CChainParams &chainParams)
Definition: guiutil.cpp:235
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
Definition: guiutil.cpp:358
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:243
void PopupMenu(QMenu *menu, const QPoint &point, QAction *at_action)
Call QMenu::popup() only on supported QT_QPA_PLATFORM.
Definition: guiutil.cpp:979
QList< QModelIndex > getEntryData(const QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
Definition: guiutil.cpp:267
QString formatBytes(uint64_t bytes)
Definition: guiutil.cpp:886
QString formatDurationStr(std::chrono::seconds dur)
Convert seconds into a QString with days, hours, mins, secs.
Definition: guiutil.cpp:804
void handleCloseWindowShortcut(QWidget *w)
Definition: guiutil.cpp:399
void PolishProgressDialog(QProgressDialog *dialog)
Definition: guiutil.cpp:946
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:329
std::string DummyAddress(const CChainParams &params)
Definition: guiutil.cpp:98
QString getDefaultDataDirectory()
Determine default data directory for operating system.
Definition: guiutil.cpp:282
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:255
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:286
QString boostPathToQString(const fs::path &path)
Convert OS specific boost path to QString through UTF-8.
Definition: guiutil.cpp:778
bool SetStartOnSystemStartup(bool fAutoStart)
Definition: guiutil.cpp:763
ClickableProgressBar ProgressBar
Definition: guiutil.h:320
void bringToFront(QWidget *w)
Definition: guiutil.cpp:382
void LogQtInfo()
Writes to debug.log short info about the used Qt and the host system.
Definition: guiutil.cpp:957
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:844
void openDebugLogfile()
Definition: guiutil.cpp:404
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:70
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:202
QString formatTimeOffset(int64_t nTimeOffset)
Format a CNodeCombinedStats.nTimeOffset into a user-readable string.
Definition: guiutil.cpp:852
QString convertToCashAddr(const CChainParams &params, const QString &addr)
Definition: guiutil.cpp:113
QString formatServicesStr(quint64 mask)
Format CNodeStats.nServices bitmask into a user-readable string.
Definition: guiutil.cpp:828
QString formatNiceTimeOffset(qint64 secs)
Definition: guiutil.cpp:857
bool GetStartOnSystemStartup()
Definition: guiutil.cpp:760
QStringList splitSkipEmptyParts(const QString &s, const QString &separator)
Definition: guiutil.cpp:441
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text.
Definition: guiutil.cpp:938
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:122
void setClipboard(const QString &str)
Definition: guiutil.cpp:769
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:274
QFont fixedPitchFont()
Definition: guiutil.cpp:79
qreal calculateIdealFontSize(int width, const QString &text, QFont font, qreal minPointSize, qreal font_size)
Definition: guiutil.cpp:908
Definition: init.h:28
ConnectionType
Different types of connections to a peer.
Definition: net.h:142
Network
A network type.
Definition: netaddress.h:45
Definition: amount.h:19