Bitcoin ABC  0.22.12
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 QDateTime;
33 class QFont;
34 class QLineEdit;
35 class QProgressDialog;
36 class QUrl;
37 class QWidget;
38 QT_END_NAMESPACE
39 
43 namespace GUIUtil {
44 
45 // Create human-readable string from date
46 QString dateTimeStr(const QDateTime &datetime);
47 QString dateTimeStr(qint64 nTime);
48 
49 // Return a monospace font
50 QFont fixedPitchFont();
51 
52 // Generate an invalid, but convincing address.
53 std::string DummyAddress(const CChainParams &params);
54 
55 // Convert any address into cashaddr
56 QString convertToCashAddr(const CChainParams &params, const QString &addr);
57 
58 // Set up widget for address
59 void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);
60 
61 // Parse "bitcoincash:" URI into recipient object, return true on successful
62 // parsing
63 bool parseBitcoinURI(const QString &scheme, const QUrl &uri,
64  SendCoinsRecipient *out);
65 bool parseBitcoinURI(const QString &scheme, QString uri,
66  SendCoinsRecipient *out);
67 QString formatBitcoinURI(const SendCoinsRecipient &info);
68 QString formatBitcoinURI(const CChainParams &params,
69  const SendCoinsRecipient &info);
70 
71 // Returns true if given address+amount meets "dust" definition
72 bool isDust(interfaces::Node &node, const QString &address, const Amount amount,
73  const CChainParams &chainParams);
74 
75 // HTML escaping for rich text controls
76 QString HtmlEscape(const QString &str, bool fMultiLine = false);
77 QString HtmlEscape(const std::string &str, bool fMultiLine = false);
78 
87 void copyEntryData(QAbstractItemView *view, int column,
88  int role = Qt::EditRole);
89 
97 QList<QModelIndex> getEntryData(QAbstractItemView *view, int column);
98 
99 void setClipboard(const QString &str);
100 
104 QString getDefaultDataDirectory();
105 
120 QString getSaveFileName(QWidget *parent, const QString &caption,
121  const QString &dir, const QString &filter,
122  QString *selectedSuffixOut);
123 
136 QString getOpenFileName(QWidget *parent, const QString &caption,
137  const QString &dir, const QString &filter,
138  QString *selectedSuffixOut);
139 
148 
149 // Determine whether a widget is hidden behind other windows
150 bool isObscured(QWidget *w);
151 
152 // Activate, show and raise the widget
153 void bringToFront(QWidget *w);
154 
155 // Open debug.log
156 void openDebugLogfile();
157 
158 // Open the config file
159 bool openBitcoinConf();
160 
161 // Split a QString using given separator, skipping the empty parts
162 QStringList splitSkipEmptyParts(const QString &s, const QString &separator);
163 
169 class ToolTipToRichTextFilter : public QObject {
170  Q_OBJECT
171 
172 public:
173  explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = 0);
174 
175 protected:
176  bool eventFilter(QObject *obj, QEvent *evt) override;
177 
178 private:
180 };
181 
194 class TableViewLastColumnResizingFixer : public QObject {
195  Q_OBJECT
196 
197 public:
198  TableViewLastColumnResizingFixer(QTableView *table, int lastColMinimumWidth,
199  int allColsMinimumWidth, QObject *parent);
200  void stretchColumnWidth(int column);
201 
202 private:
203  QTableView *tableView;
209 
210  void adjustTableColumnsWidth();
211  int getAvailableWidthForColumn(int column);
212  int getColumnsWidth();
213  void connectViewHeadersSignals();
214  void disconnectViewHeadersSignals();
215  void setViewHeaderResizeMode(int logicalIndex,
216  QHeaderView::ResizeMode resizeMode);
217  void resizeColumn(int nColumnIndex, int width);
218 
219 private Q_SLOTS:
220  void on_sectionResized(int logicalIndex, int oldSize, int newSize);
221  void on_geometriesChanged();
222 };
223 
225 bool SetStartOnSystemStartup(bool fAutoStart);
226 
227 /* Convert QString to OS specific boost path through UTF-8 */
228 fs::path qstringToBoostPath(const QString &path);
229 
230 /* Convert OS specific boost path to QString through UTF-8 */
231 QString boostPathToQString(const fs::path &path);
232 
233 /* Convert seconds into a QString with days, hours, mins, secs */
234 QString formatDurationStr(int secs);
235 
236 /* Format CNodeStats.nServices bitmask into a user-readable string */
237 QString formatServicesStr(quint64 mask);
238 
239 /*
240  * Format a CNodeStats.m_ping_usec into a user-readable string or display N/A,
241  * if 0.
242  */
243 QString formatPingTime(int64_t ping_usec);
244 
245 /* Format a CNodeCombinedStats.nTimeOffset into a user-readable string. */
246 QString formatTimeOffset(int64_t nTimeOffset);
247 
248 QString formatNiceTimeOffset(qint64 secs);
249 
250 QString formatBytes(uint64_t bytes);
251 
252 qreal calculateIdealFontSize(int width, const QString &text, QFont font,
253  qreal minPointSize = 4, qreal startPointSize = 14);
254 
255 class ClickableLabel : public QLabel {
256  Q_OBJECT
257 
258 public:
259  bool hasPixmap() const;
260 
261 Q_SIGNALS:
265  void clicked(const QPoint &point);
266 
267 protected:
268  void mouseReleaseEvent(QMouseEvent *event) override;
269 };
270 
271 class ClickableProgressBar : public QProgressBar {
272  Q_OBJECT
273 
274 Q_SIGNALS:
278  void clicked(const QPoint &point);
279 
280 protected:
281  void mouseReleaseEvent(QMouseEvent *event) override;
282 };
283 
285 
286 class ItemDelegate : public QItemDelegate {
287  Q_OBJECT
288 public:
289  ItemDelegate(QObject *parent) : QItemDelegate(parent) {}
290 
291 Q_SIGNALS:
292  void keyEscapePressed();
293 
294 private:
295  bool eventFilter(QObject *object, QEvent *event);
296 };
297 
306 int TextWidth(const QFontMetrics &fm, const QString &text);
307 
311 void LogQtInfo();
312 
313 // Fix known bugs in QProgressDialog class.
314 void PolishProgressDialog(QProgressDialog *dialog);
315 } // namespace GUIUtil
316 
317 #endif // BITCOIN_QT_GUIUTIL_H
void openDebugLogfile()
Definition: guiutil.cpp:386
QFont fixedPitchFont()
Definition: guiutil.cpp:74
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:57
void LogQtInfo()
Writes to debug.log short info about the used Qt and the host system.
Definition: guiutil.cpp:896
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:316
QList< QModelIndex > getEntryData(QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
Definition: guiutil.cpp:262
QStringList splitSkipEmptyParts(const QString &s, const QString &separator)
Definition: guiutil.cpp:423
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text...
Definition: guiutil.cpp:877
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:65
Definition: amount.h:17
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
Definition: guiutil.cpp:345
QString formatBytes(uint64_t bytes)
Definition: guiutil.cpp:825
QString formatTimeOffset(int64_t nTimeOffset)
Definition: guiutil.cpp:791
bool GetStartOnSystemStartup()
Definition: guiutil.cpp:723
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
Definition: chainparams.h:47
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:238
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
Definition: guiutil.h:169
Line edit that can be marked as "invalid" to show input validation feedback.
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:197
void bringToFront(QWidget *w)
Definition: guiutil.cpp:369
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:117
Definition: config.h:19
bool isObscured(QWidget *w)
Definition: guiutil.cpp:361
QString formatPingTime(int64_t ping_usec)
Definition: guiutil.cpp:784
qreal calculateIdealFontSize(int width, const QString &text, QFont font, qreal minPointSize, qreal font_size)
Definition: guiutil.cpp:847
QString formatDurationStr(int secs)
Definition: guiutil.cpp:745
QString convertToCashAddr(const CChainParams &params, const QString &addr)
Definition: guiutil.cpp:108
void setClipboard(const QString &str)
Definition: guiutil.cpp:732
Makes a QTableView last column feel as if it was being resized from its left border.
Definition: guiutil.h:194
bool parseBitcoinURI(const QString &scheme, const QUrl &uri, SendCoinsRecipient *out)
Definition: guiutil.cpp:131
void PolishProgressDialog(QProgressDialog *dialog)
Definition: guiutil.cpp:885
ClickableProgressBar ProgressBar
Definition: guiutil.h:284
bool isDust(interfaces::Node &node, const QString &address, const Amount amount, const CChainParams &chainParams)
Definition: guiutil.cpp:230
bool openBitcoinConf()
Definition: guiutil.cpp:396
fs::path qstringToBoostPath(const QString &path)
Definition: guiutil.cpp:737
ConnectionType
Different types of connections to a peer.
Definition: net.h:133
QString formatServicesStr(quint64 mask)
Definition: guiutil.cpp:768
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:273
std::string DummyAddress(const CChainParams &params)
Definition: guiutil.cpp:93
bool SetStartOnSystemStartup(bool fAutoStart)
Definition: guiutil.cpp:726
QString formatNiceTimeOffset(qint64 secs)
Definition: guiutil.cpp:796
void copyEntryData(QAbstractItemView *view, int column, int role)
Copy a field of the currently selected entry of a view to the clipboard.
Definition: guiutil.cpp:250
QString getDefaultDataDirectory()
Determine default data directory for operating system.
Definition: guiutil.cpp:269
QString boostPathToQString(const fs::path &path)
Definition: guiutil.cpp:741
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:45
ItemDelegate(QObject *parent)
Definition: guiutil.h:289