Bitcoin ABC  0.24.7
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 <amount.h>
9 #include <fs.h>
10 
11 #include <QEvent>
12 #include <QHeaderView>
13 #include <QItemDelegate>
14 #include <QLabel>
15 #include <QMessageBox>
16 #include <QObject>
17 #include <QProgressBar>
18 #include <QString>
19 #include <QTableView>
20 
21 class QValidatedLineEdit;
22 class SendCoinsRecipient;
23 class CChainParams;
24 class Config;
25 
26 namespace interfaces {
27 class Node;
28 }
29 
30 QT_BEGIN_NAMESPACE
31 class QAbstractItemView;
32 class QAction;
33 class QDateTime;
34 class QFont;
35 class QLineEdit;
36 class QMenu;
37 class QPoint;
38 class QProgressDialog;
39 class QUrl;
40 class QWidget;
41 QT_END_NAMESPACE
42 
46 namespace GUIUtil {
47 
48 // Create human-readable string from date
49 QString dateTimeStr(const QDateTime &datetime);
50 QString dateTimeStr(qint64 nTime);
51 
52 // Return a monospace font
53 QFont fixedPitchFont();
54 
55 // Generate an invalid, but convincing address.
56 std::string DummyAddress(const CChainParams &params);
57 
58 // Convert any address into cashaddr
59 QString convertToCashAddr(const CChainParams &params, const QString &addr);
60 
61 // Set up widget for address
62 void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);
63 
64 // Parse "bitcoincash:" URI into recipient object, return true on successful
65 // parsing
66 bool parseBitcoinURI(const QString &scheme, const QUrl &uri,
67  SendCoinsRecipient *out);
68 bool parseBitcoinURI(const QString &scheme, QString uri,
69  SendCoinsRecipient *out);
70 QString formatBitcoinURI(const SendCoinsRecipient &info);
71 QString formatBitcoinURI(const CChainParams &params,
72  const SendCoinsRecipient &info);
73 
74 // Returns true if given address+amount meets "dust" definition
75 bool isDust(interfaces::Node &node, const QString &address, const Amount amount,
76  const CChainParams &chainParams);
77 
78 // HTML escaping for rich text controls
79 QString HtmlEscape(const QString &str, bool fMultiLine = false);
80 QString HtmlEscape(const std::string &str, bool fMultiLine = false);
81 
90 void copyEntryData(const QAbstractItemView *view, int column,
91  int role = Qt::EditRole);
92 
100 QList<QModelIndex> getEntryData(const QAbstractItemView *view, int column);
101 
109 bool hasEntryData(const QAbstractItemView *view, int column, int role);
110 
111 void setClipboard(const QString &str);
112 
116 QString getDefaultDataDirectory();
117 
132 QString getSaveFileName(QWidget *parent, const QString &caption,
133  const QString &dir, const QString &filter,
134  QString *selectedSuffixOut);
135 
148 QString getOpenFileName(QWidget *parent, const QString &caption,
149  const QString &dir, const QString &filter,
150  QString *selectedSuffixOut);
151 
160 
161 // Determine whether a widget is hidden behind other windows
162 bool isObscured(QWidget *w);
163 
164 // Activate, show and raise the widget
165 void bringToFront(QWidget *w);
166 
167 // Set shortcut to close window
168 void handleCloseWindowShortcut(QWidget *w);
169 
170 // Open debug.log
171 void openDebugLogfile();
172 
173 // Open the config file
174 bool openBitcoinConf();
175 
176 // Split a QString using given separator, skipping the empty parts
177 QStringList splitSkipEmptyParts(const QString &s, const QString &separator);
178 
184 class ToolTipToRichTextFilter : public QObject {
185  Q_OBJECT
186 
187 public:
188  explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = 0);
189 
190 protected:
191  bool eventFilter(QObject *obj, QEvent *evt) override;
192 
193 private:
195 };
196 
204 class LabelOutOfFocusEventFilter : public QObject {
205  Q_OBJECT
206 
207 public:
208  explicit LabelOutOfFocusEventFilter(QObject *parent);
209  bool eventFilter(QObject *watched, QEvent *event) override;
210 };
211 
224 class TableViewLastColumnResizingFixer : public QObject {
225  Q_OBJECT
226 
227 public:
228  TableViewLastColumnResizingFixer(QTableView *table, int lastColMinimumWidth,
229  int allColsMinimumWidth, QObject *parent);
230  void stretchColumnWidth(int column);
231 
232 private:
233  QTableView *tableView;
239 
241  int getAvailableWidthForColumn(int column);
242  int getColumnsWidth();
245  void setViewHeaderResizeMode(int logicalIndex,
246  QHeaderView::ResizeMode resizeMode);
247  void resizeColumn(int nColumnIndex, int width);
248 
249 private Q_SLOTS:
250  void on_sectionResized(int logicalIndex, int oldSize, int newSize);
251  void on_geometriesChanged();
252 };
253 
255 bool SetStartOnSystemStartup(bool fAutoStart);
256 
257 /* Convert QString to OS specific boost path through UTF-8 */
258 fs::path qstringToBoostPath(const QString &path);
259 
260 /* Convert OS specific boost path to QString through UTF-8 */
261 QString boostPathToQString(const fs::path &path);
262 
263 /* Convert seconds into a QString with days, hours, mins, secs */
264 QString formatDurationStr(int secs);
265 
266 /* Format CNodeStats.nServices bitmask into a user-readable string */
267 QString formatServicesStr(quint64 mask);
268 
269 /*
270  * Format a CNodeStats.m_ping_usec into a user-readable string or display N/A,
271  * if 0.
272  */
273 QString formatPingTime(int64_t ping_usec);
274 
275 /* Format a CNodeCombinedStats.nTimeOffset into a user-readable string. */
276 QString formatTimeOffset(int64_t nTimeOffset);
277 
278 QString formatNiceTimeOffset(qint64 secs);
279 
280 QString formatBytes(uint64_t bytes);
281 
282 qreal calculateIdealFontSize(int width, const QString &text, QFont font,
283  qreal minPointSize = 4, qreal startPointSize = 14);
284 
285 class ClickableLabel : public QLabel {
286  Q_OBJECT
287 
288 public:
289  bool hasPixmap() const;
290 
291 Q_SIGNALS:
295  void clicked(const QPoint &point);
296 
297 protected:
298  void mouseReleaseEvent(QMouseEvent *event) override;
299 };
300 
301 class ClickableProgressBar : public QProgressBar {
302  Q_OBJECT
303 
304 Q_SIGNALS:
308  void clicked(const QPoint &point);
309 
310 protected:
311  void mouseReleaseEvent(QMouseEvent *event) override;
312 };
313 
315 
316 class ItemDelegate : public QItemDelegate {
317  Q_OBJECT
318 public:
319  ItemDelegate(QObject *parent) : QItemDelegate(parent) {}
320 
321 Q_SIGNALS:
322  void keyEscapePressed();
323 
324 private:
325  bool eventFilter(QObject *object, QEvent *event) override;
326 };
327 
336 int TextWidth(const QFontMetrics &fm, const QString &text);
337 
341 void LogQtInfo();
342 
346 void PopupMenu(QMenu *menu, const QPoint &point, QAction *at_action = nullptr);
347 
348 // Fix known bugs in QProgressDialog class.
349 void PolishProgressDialog(QProgressDialog *dialog);
350 } // namespace GUIUtil
351 
352 #endif // BITCOIN_QT_GUIUTIL_H
GUIUtil::TableViewLastColumnResizingFixer::on_geometriesChanged
void on_geometriesChanged()
Definition: guiutil.cpp:575
interfaces
Definition: dummywallet.cpp:12
GUIUtil::ToolTipToRichTextFilter
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
Definition: guiutil.h:184
GUIUtil::TableViewLastColumnResizingFixer::connectViewHeadersSignals
void connectViewHeadersSignals()
Definition: guiutil.cpp:487
GUIUtil::boostPathToQString
QString boostPathToQString(const fs::path &path)
Definition: guiutil.cpp:775
GUIUtil::openBitcoinConf
bool openBitcoinConf()
Definition: guiutil.cpp:411
GUIUtil::PopupMenu
void PopupMenu(QMenu *menu, const QPoint &point, QAction *at_action)
Call QMenu::popup() only on supported QT_QPA_PLATFORM.
Definition: guiutil.cpp:952
GUIUtil::TableViewLastColumnResizingFixer::columnCount
int columnCount
Definition: guiutil.h:237
GUIUtil::ClickableLabel
Definition: guiutil.h:285
fs.h
GUIUtil::SetStartOnSystemStartup
bool SetStartOnSystemStartup(bool fAutoStart)
Definition: guiutil.cpp:760
GUIUtil::TableViewLastColumnResizingFixer::TableViewLastColumnResizingFixer
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:589
GUIUtil::TableViewLastColumnResizingFixer::resizeColumn
void resizeColumn(int nColumnIndex, int width)
Definition: guiutil.cpp:512
GUIUtil::DummyAddress
std::string DummyAddress(const CChainParams &params)
Definition: guiutil.cpp:95
GUIUtil::ItemDelegate::ItemDelegate
ItemDelegate(QObject *parent)
Definition: guiutil.h:319
GUIUtil::ItemDelegate::eventFilter
bool eventFilter(QObject *object, QEvent *event) override
Definition: guiutil.cpp:902
GUIUtil::ClickableProgressBar::clicked
void clicked(const QPoint &point)
Emitted when the progressbar is clicked.
GUIUtil::TableViewLastColumnResizingFixer
Makes a QTableView last column feel as if it was being resized from its left border.
Definition: guiutil.h:224
GUIUtil::ClickableProgressBar
Definition: guiutil.h:301
GUIUtil
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:58
CChainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:47
GUIUtil::openDebugLogfile
void openDebugLogfile()
Definition: guiutil.cpp:401
GUIUtil::hasEntryData
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:271
GUIUtil::TableViewLastColumnResizingFixer::stretchColumnWidth
void stretchColumnWidth(int column)
Definition: guiutil.cpp:555
GUIUtil::splitSkipEmptyParts
QStringList splitSkipEmptyParts(const QString &s, const QString &separator)
Definition: guiutil.cpp:438
GUIUtil::formatBitcoinURI
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:199
GUIUtil::ItemDelegate
Definition: guiutil.h:316
GUIUtil::bringToFront
void bringToFront(QWidget *w)
Definition: guiutil.cpp:379
GUIUtil::qstringToBoostPath
fs::path qstringToBoostPath(const QString &path)
Definition: guiutil.cpp:771
GUIUtil::ItemDelegate::keyEscapePressed
void keyEscapePressed()
GUIUtil::TableViewLastColumnResizingFixer::tableView
QTableView * tableView
Definition: guiutil.h:233
GUIUtil::convertToCashAddr
QString convertToCashAddr(const CChainParams &params, const QString &addr)
Definition: guiutil.cpp:110
GUIUtil::formatPingTime
QString formatPingTime(int64_t ping_usec)
Definition: guiutil.cpp:818
GUIUtil::isObscured
bool isObscured(QWidget *w)
Definition: guiutil.cpp:371
GUIUtil::setClipboard
void setClipboard(const QString &str)
Definition: guiutil.cpp:766
GUIUtil::fixedPitchFont
QFont fixedPitchFont()
Definition: guiutil.cpp:76
GUIUtil::LabelOutOfFocusEventFilter
Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and resets their ‘textInt...
Definition: guiutil.h:204
SendCoinsRecipient
Definition: sendcoinsrecipient.h:23
Config
Definition: config.h:17
GUIUtil::formatTimeOffset
QString formatTimeOffset(int64_t nTimeOffset)
Definition: guiutil.cpp:825
GUIUtil::getOpenFileName
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:326
GUIUtil::formatNiceTimeOffset
QString formatNiceTimeOffset(qint64 secs)
Definition: guiutil.cpp:830
GUIUtil::TableViewLastColumnResizingFixer::secondToLastColumnIndex
int secondToLastColumnIndex
Definition: guiutil.h:238
GUIUtil::TableViewLastColumnResizingFixer::getAvailableWidthForColumn
int getAvailableWidthForColumn(int column)
Definition: guiutil.cpp:526
GUIUtil::ClickableLabel::clicked
void clicked(const QPoint &point)
Emitted when the label is clicked.
GUIUtil::ClickableLabel::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *event) override
Definition: guiutil.cpp:894
GUIUtil::LabelOutOfFocusEventFilter::eventFilter
bool eventFilter(QObject *watched, QEvent *event) override
Definition: guiutil.cpp:471
GUIUtil::isDust
bool isDust(interfaces::Node &node, const QString &address, const Amount amount, const CChainParams &chainParams)
Definition: guiutil.cpp:232
GUIUtil::PolishProgressDialog
void PolishProgressDialog(QProgressDialog *dialog)
Definition: guiutil.cpp:919
QValidatedLineEdit
Line edit that can be marked as "invalid" to show input validation feedback.
Definition: qvalidatedlineedit.h:14
GUIUtil::TableViewLastColumnResizingFixer::adjustTableColumnsWidth
void adjustTableColumnsWidth()
Definition: guiutil.cpp:541
GUIUtil::TableViewLastColumnResizingFixer::getColumnsWidth
int getColumnsWidth()
Definition: guiutil.cpp:518
GUIUtil::TableViewLastColumnResizingFixer::disconnectViewHeadersSignals
void disconnectViewHeadersSignals()
Definition: guiutil.cpp:496
GUIUtil::formatBytes
QString formatBytes(uint64_t bytes)
Definition: guiutil.cpp:859
Amount
Definition: amount.h:19
GUIUtil::formatServicesStr
QString formatServicesStr(quint64 mask)
Definition: guiutil.cpp:802
GUIUtil::getDefaultDataDirectory
QString getDefaultDataDirectory()
Determine default data directory for operating system.
Definition: guiutil.cpp:279
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:55
GUIUtil::ToolTipToRichTextFilter::eventFilter
bool eventFilter(QObject *obj, QEvent *evt) override
Definition: guiutil.cpp:452
GUIUtil::getSaveFileName
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:283
GUIUtil::LabelOutOfFocusEventFilter::LabelOutOfFocusEventFilter
LabelOutOfFocusEventFilter(QObject *parent)
Definition: guiutil.cpp:468
GUIUtil::GetStartOnSystemStartup
bool GetStartOnSystemStartup()
Definition: guiutil.cpp:757
GUIUtil::HtmlEscape
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:240
GUIUtil::copyEntryData
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:252
GUIUtil::ToolTipToRichTextFilter::size_threshold
int size_threshold
Definition: guiutil.h:194
GUIUtil::TableViewLastColumnResizingFixer::lastColumnMinimumWidth
int lastColumnMinimumWidth
Definition: guiutil.h:234
GUIUtil::ClickableLabel::hasPixmap
bool hasPixmap() const
Definition: guiutil.cpp:873
GUIUtil::TableViewLastColumnResizingFixer::on_sectionResized
void on_sectionResized(int logicalIndex, int oldSize, int newSize)
Definition: guiutil.cpp:562
GUIUtil::blockingGUIThreadConnection
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
Definition: guiutil.cpp:355
GUIUtil::LogQtInfo
void LogQtInfo()
Writes to debug.log short info about the used Qt and the host system.
Definition: guiutil.cpp:930
GUIUtil::ClickableProgressBar::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *event) override
Definition: guiutil.cpp:898
GUIUtil::ToolTipToRichTextFilter::ToolTipToRichTextFilter
ToolTipToRichTextFilter(int size_threshold, QObject *parent=0)
Definition: guiutil.cpp:448
GUIUtil::calculateIdealFontSize
qreal calculateIdealFontSize(int width, const QString &text, QFont font, qreal minPointSize, qreal font_size)
Definition: guiutil.cpp:881
GUIUtil::formatDurationStr
QString formatDurationStr(int secs)
Definition: guiutil.cpp:779
GUIUtil::TextWidth
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text.
Definition: guiutil.cpp:911
GUIUtil::dateTimeStr
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:67
GUIUtil::handleCloseWindowShortcut
void handleCloseWindowShortcut(QWidget *w)
Definition: guiutil.cpp:396
GUIUtil::getEntryData
QList< QModelIndex > getEntryData(const QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
Definition: guiutil.cpp:264
GUIUtil::setupAddressWidget
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:119
amount.h
GUIUtil::parseBitcoinURI
bool parseBitcoinURI(const QString &scheme, const QUrl &uri, SendCoinsRecipient *out)
Definition: guiutil.cpp:133
ConnectionType
ConnectionType
Different types of connections to a peer.
Definition: net.h:154
GUIUtil::TableViewLastColumnResizingFixer::lastColumnIndex
int lastColumnIndex
Definition: guiutil.h:236
GUIUtil::TableViewLastColumnResizingFixer::setViewHeaderResizeMode
void setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode)
Definition: guiutil.cpp:506
GUIUtil::ProgressBar
ClickableProgressBar ProgressBar
Definition: guiutil.h:314
GUIUtil::TableViewLastColumnResizingFixer::allColumnsMinimumWidth
int allColumnsMinimumWidth
Definition: guiutil.h:235