Bitcoin Core  0.18.99
P2P Digital Currency
guiutil.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2018 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 <QMessageBox>
15 #include <QObject>
16 #include <QProgressBar>
17 #include <QString>
18 #include <QTableView>
19 #include <QLabel>
20 
21 class QValidatedLineEdit;
22 class SendCoinsRecipient;
23 
24 namespace interfaces
25 {
26  class Node;
27 }
28 
29 QT_BEGIN_NAMESPACE
30 class QAbstractItemView;
31 class QDateTime;
32 class QFont;
33 class QLineEdit;
34 class QProgressDialog;
35 class QUrl;
36 class QWidget;
37 QT_END_NAMESPACE
38 
41 namespace GUIUtil
42 {
43  // Create human-readable string from date
44  QString dateTimeStr(const QDateTime &datetime);
45  QString dateTimeStr(qint64 nTime);
46 
47  // Return a monospace font
48  QFont fixedPitchFont();
49 
50  // Set up widget for address
51  void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);
52 
53  // Parse "bitcoin:" URI into recipient object, return true on successful parsing
54  bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out);
55  bool parseBitcoinURI(QString uri, SendCoinsRecipient *out);
56  QString formatBitcoinURI(const SendCoinsRecipient &info);
57 
58  // Returns true if given address+amount meets "dust" definition
59  bool isDust(interfaces::Node& node, const QString& address, const CAmount& amount);
60 
61  // HTML escaping for rich text controls
62  QString HtmlEscape(const QString& str, bool fMultiLine=false);
63  QString HtmlEscape(const std::string& str, bool fMultiLine=false);
64 
71  void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole);
72 
78  QList<QModelIndex> getEntryData(QAbstractItemView *view, int column);
79 
80  void setClipboard(const QString& str);
81 
85  QString getDefaultDataDirectory();
86 
97  QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,
98  const QString &filter,
99  QString *selectedSuffixOut);
100 
110  QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir,
111  const QString &filter,
112  QString *selectedSuffixOut);
113 
119  Qt::ConnectionType blockingGUIThreadConnection();
120 
121  // Determine whether a widget is hidden behind other windows
122  bool isObscured(QWidget *w);
123 
124  // Activate, show and raise the widget
125  void bringToFront(QWidget* w);
126 
127  // Open debug.log
128  void openDebugLogfile();
129 
130  // Open the config file
131  bool openBitcoinConf();
132 
137  class ToolTipToRichTextFilter : public QObject
138  {
139  Q_OBJECT
140 
141  public:
142  explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = nullptr);
143 
144  protected:
145  bool eventFilter(QObject *obj, QEvent *evt);
146 
147  private:
149  };
150 
161  class TableViewLastColumnResizingFixer: public QObject
162  {
163  Q_OBJECT
164 
165  public:
166  TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth, QObject *parent);
167  void stretchColumnWidth(int column);
168 
169  private:
170  QTableView* tableView;
176 
177  void adjustTableColumnsWidth();
178  int getAvailableWidthForColumn(int column);
179  int getColumnsWidth();
180  void connectViewHeadersSignals();
181  void disconnectViewHeadersSignals();
182  void setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode);
183  void resizeColumn(int nColumnIndex, int width);
184 
185  private Q_SLOTS:
186  void on_sectionResized(int logicalIndex, int oldSize, int newSize);
187  void on_geometriesChanged();
188  };
189 
191  bool SetStartOnSystemStartup(bool fAutoStart);
192 
193  /* Convert QString to OS specific boost path through UTF-8 */
194  fs::path qstringToBoostPath(const QString &path);
195 
196  /* Convert OS specific boost path to QString through UTF-8 */
197  QString boostPathToQString(const fs::path &path);
198 
199  /* Convert seconds into a QString with days, hours, mins, secs */
200  QString formatDurationStr(int secs);
201 
202  /* Format CNodeStats.nServices bitmask into a user-readable string */
203  QString formatServicesStr(quint64 mask);
204 
205  /* Format a CNodeCombinedStats.dPingTime into a user-readable string or display N/A, if 0*/
206  QString formatPingTime(double dPingTime);
207 
208  /* Format a CNodeCombinedStats.nTimeOffset into a user-readable string. */
209  QString formatTimeOffset(int64_t nTimeOffset);
210 
211  QString formatNiceTimeOffset(qint64 secs);
212 
213  QString formatBytes(uint64_t bytes);
214 
215  qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize = 4, qreal startPointSize = 14);
216 
217  class ClickableLabel : public QLabel
218  {
219  Q_OBJECT
220 
221  Q_SIGNALS:
225  void clicked(const QPoint& point);
226  protected:
227  void mouseReleaseEvent(QMouseEvent *event);
228  };
229 
230  class ClickableProgressBar : public QProgressBar
231  {
232  Q_OBJECT
233 
234  Q_SIGNALS:
238  void clicked(const QPoint& point);
239  protected:
240  void mouseReleaseEvent(QMouseEvent *event);
241  };
242 
244 
245  class ItemDelegate : public QItemDelegate
246  {
247  Q_OBJECT
248  public:
249  ItemDelegate(QObject* parent) : QItemDelegate(parent) {}
250 
251  Q_SIGNALS:
252  void keyEscapePressed();
253 
254  private:
255  bool eventFilter(QObject *object, QEvent *event);
256  };
257 
258  // Fix known bugs in QProgressDialog class.
259  void PolishProgressDialog(QProgressDialog* dialog);
260 } // namespace GUIUtil
261 
262 #endif // BITCOIN_QT_GUIUTIL_H
void openDebugLogfile()
Definition: guiutil.cpp:381
QFont fixedPitchFont()
Definition: guiutil.cpp:78
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:55
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:301
QList< QModelIndex > getEntryData(QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
Definition: guiutil.cpp:243
bool isDust(interfaces::Node &node, const QString &address, const CAmount &amount)
Definition: guiutil.cpp:207
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:68
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
Definition: guiutil.cpp:332
QString formatBytes(uint64_t bytes)
Definition: guiutil.cpp:906
QString formatTimeOffset(int64_t nTimeOffset)
Definition: guiutil.cpp:864
bool GetStartOnSystemStartup()
Definition: guiutil.cpp:780
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:215
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
Definition: guiutil.h:137
Line edit that can be marked as "invalid" to show input validation feedback.
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
Definition: guiutil.cpp:114
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:177
void bringToFront(QWidget *w)
Definition: guiutil.cpp:360
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:101
bool isObscured(QWidget *w)
Definition: guiutil.cpp:351
qreal calculateIdealFontSize(int width, const QString &text, QFont font, qreal minPointSize, qreal font_size)
Definition: guiutil.cpp:918
QString formatDurationStr(int secs)
Definition: guiutil.cpp:801
void setClipboard(const QString &str)
Definition: guiutil.cpp:785
Makes a QTableView last column feel as if it was being resized from its left border.
Definition: guiutil.h:161
void PolishProgressDialog(QProgressDialog *dialog)
Definition: guiutil.cpp:950
ClickableProgressBar ProgressBar
Definition: guiutil.h:243
QString formatPingTime(double dPingTime)
Definition: guiutil.cpp:859
bool openBitcoinConf()
Definition: guiutil.cpp:390
fs::path qstringToBoostPath(const QString &path)
Definition: guiutil.cpp:791
QString formatServicesStr(quint64 mask)
Definition: guiutil.cpp:821
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:255
bool SetStartOnSystemStartup(bool fAutoStart)
Definition: guiutil.cpp:781
QString formatNiceTimeOffset(qint64 secs)
Definition: guiutil.cpp:869
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:230
QString getDefaultDataDirectory()
Determine default data directory for operating system.
Definition: guiutil.cpp:250
QString boostPathToQString(const fs::path &path)
Definition: guiutil.cpp:796
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:36
ItemDelegate(QObject *parent)
Definition: guiutil.h:249