Dogecoin Core  1.14.2
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 
10 #include <QEvent>
11 #include <QHeaderView>
12 #include <QMessageBox>
13 #include <QObject>
14 #include <QProgressBar>
15 #include <QString>
16 #include <QTableView>
17 #include <QLabel>
18 
19 #include <boost/filesystem.hpp>
20 
21 class QValidatedLineEdit;
22 class SendCoinsRecipient;
23 
24 QT_BEGIN_NAMESPACE
25 class QAbstractItemView;
26 class QDateTime;
27 class QFont;
28 class QLineEdit;
29 class QUrl;
30 class QWidget;
31 QT_END_NAMESPACE
32 
35 namespace GUIUtil
36 {
37  // Create human-readable string from date
38  QString dateTimeStr(const QDateTime &datetime);
39  QString dateTimeStr(qint64 nTime);
40 
41  // Return a monospace font
42  QFont fixedPitchFont();
43 
44  // Set up widgets for address and amounts
45  void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);
46  void setupAmountWidget(QLineEdit *widget, QWidget *parent);
47 
48  // Parse "bitcoin:" URI into recipient object, return true on successful parsing
49  bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out);
50  bool parseBitcoinURI(QString uri, SendCoinsRecipient *out);
51  QString formatBitcoinURI(const SendCoinsRecipient &info);
52 
53  // Returns true if given address+amount meets "dust" definition
54  bool isDust(const QString& address, const CAmount& amount);
55 
56  // HTML escaping for rich text controls
57  QString HtmlEscape(const QString& str, bool fMultiLine=false);
58  QString HtmlEscape(const std::string& str, bool fMultiLine=false);
59 
66  void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole);
67 
73  QList<QModelIndex> getEntryData(QAbstractItemView *view, int column);
74 
75  void setClipboard(const QString& str);
76 
87  QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,
88  const QString &filter,
89  QString *selectedSuffixOut);
90 
100  QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir,
101  const QString &filter,
102  QString *selectedSuffixOut);
103 
109  Qt::ConnectionType blockingGUIThreadConnection();
110 
111  // Determine whether a widget is hidden behind other windows
112  bool isObscured(QWidget *w);
113 
114  // Open debug.log
115  void openDebugLogfile();
116 
117  // Replace invalid default fonts with known good ones
118  void SubstituteFonts(const QString& language);
119 
124  class ToolTipToRichTextFilter : public QObject
125  {
126  Q_OBJECT
127 
128  public:
129  explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = 0);
130 
131  protected:
132  bool eventFilter(QObject *obj, QEvent *evt);
133 
134  private:
136  };
137 
148  class TableViewLastColumnResizingFixer: public QObject
149  {
150  Q_OBJECT
151 
152  public:
153  TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth, QObject *parent);
154  void stretchColumnWidth(int column);
155 
156  private:
157  QTableView* tableView;
163 
165  int getAvailableWidthForColumn(int column);
166  int getColumnsWidth();
169  void setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode);
170  void resizeColumn(int nColumnIndex, int width);
171 
172  private Q_SLOTS:
173  void on_sectionResized(int logicalIndex, int oldSize, int newSize);
174  void on_geometriesChanged();
175  };
176 
178  bool SetStartOnSystemStartup(bool fAutoStart);
179 
181  void saveWindowGeometry(const QString& strSetting, QWidget *parent);
183  void restoreWindowGeometry(const QString& strSetting, const QSize &defaultSizeIn, QWidget *parent);
184 
185  /* Convert QString to OS specific boost path through UTF-8 */
186  boost::filesystem::path qstringToBoostPath(const QString &path);
187 
188  /* Convert OS specific boost path to QString through UTF-8 */
189  QString boostPathToQString(const boost::filesystem::path &path);
190 
191  /* Convert seconds into a QString with days, hours, mins, secs */
192  QString formatDurationStr(int secs);
193 
194  /* Format CNodeStats.nServices bitmask into a user-readable string */
195  QString formatServicesStr(quint64 mask);
196 
197  /* Format a CNodeCombinedStats.dPingTime into a user-readable string or display N/A, if 0*/
198  QString formatPingTime(double dPingTime);
199 
200  /* Format a CNodeCombinedStats.nTimeOffset into a user-readable string. */
201  QString formatTimeOffset(int64_t nTimeOffset);
202 
203  QString formatNiceTimeOffset(qint64 secs);
204 
205  class ClickableLabel : public QLabel
206  {
207  Q_OBJECT
208 
209  Q_SIGNALS:
213  void clicked(const QPoint& point);
214  protected:
215  void mouseReleaseEvent(QMouseEvent *event);
216  };
217 
218  class ClickableProgressBar : public QProgressBar
219  {
220  Q_OBJECT
221 
222  Q_SIGNALS:
226  void clicked(const QPoint& point);
227  protected:
228  void mouseReleaseEvent(QMouseEvent *event);
229  };
230 
231 #if defined(Q_OS_MAC) && QT_VERSION >= 0x050000
232  // workaround for Qt OSX Bug:
233  // https://bugreports.qt-project.org/browse/QTBUG-15631
234  // QProgressBar uses around 10% CPU even when app is in background
235  class ProgressBar : public ClickableProgressBar
236  {
237  bool event(QEvent *e) {
238  return (e->type() != QEvent::StyleAnimationUpdate) ? QProgressBar::event(e) : false;
239  }
240  };
241 #else
243 #endif
244 
245 } // namespace GUIUtil
246 
247 #endif // BITCOIN_QT_GUIUTIL_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:15
void mouseReleaseEvent(QMouseEvent *event)
Definition: guiutil.cpp:986
void clicked(const QPoint &point)
Emitted when the label is clicked.
void mouseReleaseEvent(QMouseEvent *event)
Definition: guiutil.cpp:991
void clicked(const QPoint &point)
Emitted when the progressbar is clicked.
Makes a QTableView last column feel as if it was being resized from its left border.
Definition: guiutil.h:149
void setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode)
Definition: guiutil.cpp:492
void resizeColumn(int nColumnIndex, int width)
Definition: guiutil.cpp:501
void on_sectionResized(int logicalIndex, int oldSize, int newSize)
Definition: guiutil.cpp:555
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:581
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
Definition: guiutil.h:125
bool eventFilter(QObject *obj, QEvent *evt)
Definition: guiutil.cpp:459
ToolTipToRichTextFilter(int size_threshold, QObject *parent=0)
Definition: guiutil.cpp:452
Line edit that can be marked as "invalid" to show input validation feedback.
Utility functions used by the Bitcoin Qt UI.
Definition: guiutil.cpp:84
bool isObscured(QWidget *w)
Definition: guiutil.cpp:398
void setupAmountWidget(QLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:135
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
Definition: guiutil.cpp:379
boost::filesystem::path qstringToBoostPath(const QString &path)
Definition: guiutil.cpp:870
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:255
QString formatPingTime(double dPingTime)
Definition: guiutil.cpp:939
void saveWindowGeometry(const QString &strSetting, QWidget *parent)
Save window size and position.
Definition: guiutil.cpp:829
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:344
QList< QModelIndex > getEntryData(QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
Definition: guiutil.cpp:287
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
bool SetStartOnSystemStartup(bool fAutoStart)
Definition: guiutil.cpp:825
QString boostPathToQString(const boost::filesystem::path &path)
Definition: guiutil.cpp:875
ClickableProgressBar ProgressBar
Definition: guiutil.h:242
void restoreWindowGeometry(const QString &strSetting, const QSize &defaultSize, QWidget *parent)
Restore window size and position.
Definition: guiutil.cpp:836
void SubstituteFonts(const QString &language)
Definition: guiutil.cpp:416
void openDebugLogfile()
Definition: guiutil.cpp:407
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:86
QString formatDurationStr(int secs)
Definition: guiutil.cpp:881
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:219
QString formatTimeOffset(int64_t nTimeOffset)
Definition: guiutil.cpp:944
QString formatServicesStr(quint64 mask)
Definition: guiutil.cpp:901
QString formatNiceTimeOffset(qint64 secs)
Definition: guiutil.cpp:949
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
Definition: guiutil.cpp:144
bool GetStartOnSystemStartup()
Definition: guiutil.cpp:824
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:274
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:120
void setClipboard(const QString &str)
Definition: guiutil.cpp:852
QFont fixedPitchFont()
Definition: guiutil.cpp:96
bool isDust(const QString &address, const CAmount &amount)
Definition: guiutil.cpp:247