Raven Core  3.0.0
P2P Digital Currency
guiutil.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef RAVEN_QT_GUIUTIL_H
7 #define RAVEN_QT_GUIUTIL_H
8 
9 #include "amount.h"
10 #include "fs.h"
11 
12 #include <QEvent>
13 #include <QHeaderView>
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 QT_BEGIN_NAMESPACE
25 class QAbstractItemView;
26 class QDateTime;
27 class QFont;
28 class QLineEdit;
29 class QUrl;
30 class QWidget;
31 class QGraphicsDropShadowEffect;
32 QT_END_NAMESPACE
33 
36 namespace GUIUtil
37 {
38  // Get the font for the sub labels
39  QFont getSubLabelFont();
40  QFont getSubLabelFontBolded();
41 
42  // Get the font for the main labels
43  QFont getTopLabelFont();
44  QFont getTopLabelFontBolded();
45  QFont getTopLabelFont(int weight, int pxsize);
46 
47  QGraphicsDropShadowEffect* getShadowEffect();
48 
49  // Create human-readable string from date
50  QString dateTimeStr(const QDateTime &datetime);
51  QString dateTimeStr(qint64 nTime);
52 
53  // Return a monospace font
54  QFont fixedPitchFont();
55 
56  // Set up widgets for address and amounts
57  void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);
58  void setupAmountWidget(QLineEdit *widget, QWidget *parent);
59 
60  // Parse "raven:" URI into recipient object, return true on successful parsing
61  bool parseRavenURI(const QUrl &uri, SendCoinsRecipient *out);
62  bool parseRavenURI(QString uri, SendCoinsRecipient *out);
63  QString formatRavenURI(const SendCoinsRecipient &info);
64 
65  // Returns true if given address+amount meets "dust" definition
66  bool isDust(const QString& address, const CAmount& amount);
67 
68  // HTML escaping for rich text controls
69  QString HtmlEscape(const QString& str, bool fMultiLine=false);
70  QString HtmlEscape(const std::string& str, bool fMultiLine=false);
71 
78  void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole);
79 
85  QList<QModelIndex> getEntryData(QAbstractItemView *view, int column);
86 
87  void setClipboard(const QString& str);
88 
99  QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,
100  const QString &filter,
101  QString *selectedSuffixOut);
102 
112  QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir,
113  const QString &filter,
114  QString *selectedSuffixOut);
115 
121  Qt::ConnectionType blockingGUIThreadConnection();
122 
123  // Determine whether a widget is hidden behind other windows
124  bool isObscured(QWidget *w);
125 
126  // Open debug.log
127  void openDebugLogfile();
128 
129  // Open the config file
130  bool openRavenConf();
131 
132  // Replace invalid default fonts with known good ones
133  void SubstituteFonts(const QString& language);
134 
135  // Concatenate a string given the painter, static text width, left side of rect, and right side of rect
136  // and which side the concatenated string is on (default left)
137  void concatenate(QPainter* painter, QString& strToCon, int static_width, int left_side, int right_size);
138 
143  class ToolTipToRichTextFilter : public QObject
144  {
145  Q_OBJECT
146 
147  public:
148  explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = 0);
149 
150  protected:
151  bool eventFilter(QObject *obj, QEvent *evt);
152 
153  private:
155  };
156 
167  class TableViewLastColumnResizingFixer: public QObject
168  {
169  Q_OBJECT
170 
171  public:
172  TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth, QObject *parent);
173  void stretchColumnWidth(int column);
174 
175  private:
176  QTableView* tableView;
182 
183  void adjustTableColumnsWidth();
184  int getAvailableWidthForColumn(int column);
185  int getColumnsWidth();
186  void connectViewHeadersSignals();
187  void disconnectViewHeadersSignals();
188  void setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode);
189  void resizeColumn(int nColumnIndex, int width);
190 
191  private Q_SLOTS:
192  void on_sectionResized(int logicalIndex, int oldSize, int newSize);
193  void on_geometriesChanged();
194  };
195 
197  bool SetStartOnSystemStartup(bool fAutoStart);
198 
199  /* Convert QString to OS specific boost path through UTF-8 */
200  fs::path qstringToBoostPath(const QString &path);
201 
202  /* Convert OS specific boost path to QString through UTF-8 */
203  QString boostPathToQString(const fs::path &path);
204 
205  /* Convert seconds into a QString with days, hours, mins, secs */
206  QString formatDurationStr(int secs);
207 
208  /* Format CNodeStats.nServices bitmask into a user-readable string */
209  QString formatServicesStr(quint64 mask);
210 
211  /* Format a CNodeCombinedStats.dPingTime into a user-readable string or display N/A, if 0*/
212  QString formatPingTime(double dPingTime);
213 
214  /* Format a CNodeCombinedStats.nTimeOffset into a user-readable string. */
215  QString formatTimeOffset(int64_t nTimeOffset);
216 
217  QString formatNiceTimeOffset(qint64 secs);
218 
219  QString formatBytes(uint64_t bytes);
220 
221  class ClickableLabel : public QLabel
222  {
223  Q_OBJECT
224 
225  Q_SIGNALS:
229  void clicked(const QPoint& point);
230  protected:
231  void mouseReleaseEvent(QMouseEvent *event);
232  };
233 
234  class ClickableProgressBar : public QProgressBar
235  {
236  Q_OBJECT
237 
238  Q_SIGNALS:
242  void clicked(const QPoint& point);
243  protected:
244  void mouseReleaseEvent(QMouseEvent *event);
245  };
246 
247 #if defined(Q_OS_MAC) && QT_VERSION >= 0x050000
248  // workaround for Qt OSX Bug:
249  // https://bugreports.qt-project.org/browse/QTBUG-15631
250  // QProgressBar uses around 10% CPU even when app is in background
251  class ProgressBar : public ClickableProgressBar
252  {
253  bool event(QEvent *e) {
254  return (e->type() != QEvent::StyleAnimationUpdate) ? QProgressBar::event(e) : false;
255  }
256  };
257 #else
259 #endif
260 
261 } // namespace GUIUtil
262 
263 #endif // RAVEN_QT_GUIUTIL_H
void SubstituteFonts(const QString &language)
Definition: guiutil.cpp:513
void openDebugLogfile()
Definition: guiutil.cpp:488
bool isDust(const QString &address, const CAmount &amount)
Definition: guiutil.cpp:328
QFont fixedPitchFont()
Definition: guiutil.cpp:168
Utility functions used by the Raven Qt UI.
Definition: guiutil.cpp:84
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:425
QList< QModelIndex > getEntryData(QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
Definition: guiutil.cpp:368
void setupAmountWidget(QLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:216
QGraphicsDropShadowEffect * getShadowEffect()
Definition: guiutil.cpp:146
void concatenate(QPainter *painter, QString &catString, int static_width, int left_side, int right_size)
Definition: guiutil.cpp:1088
bool parseRavenURI(const QUrl &uri, SendCoinsRecipient *out)
Definition: guiutil.cpp:225
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:158
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
Definition: guiutil.cpp:460
QString formatBytes(uint64_t bytes)
Definition: guiutil.cpp:1066
QString formatTimeOffset(int64_t nTimeOffset)
Definition: guiutil.cpp:1024
bool GetStartOnSystemStartup()
Definition: guiutil.cpp:940
ToolTipToRichTextFilter(int size_threshold, QObject *parent=0)
Definition: guiutil.cpp:549
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:336
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
Definition: guiutil.h:143
Line edit that can be marked as "invalid" to show input validation feedback.
bool openRavenConf()
Definition: guiutil.cpp:497
QFont getTopLabelFontBolded()
Definition: guiutil.cpp:110
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
QFont getSubLabelFont()
Definition: guiutil.cpp:86
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:201
bool isObscured(QWidget *w)
Definition: guiutil.cpp:479
bool eventFilter(QObject *obj, QEvent *evt)
Definition: guiutil.cpp:556
QString formatDurationStr(int secs)
Definition: guiutil.cpp:961
void setClipboard(const QString &str)
Definition: guiutil.cpp:945
Makes a QTableView last column feel as if it was being resized from its left border.
Definition: guiutil.h:167
ClickableProgressBar ProgressBar
Definition: guiutil.h:258
QString formatPingTime(double dPingTime)
Definition: guiutil.cpp:1019
QString formatRavenURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:300
fs::path qstringToBoostPath(const QString &path)
Definition: guiutil.cpp:951
QString formatServicesStr(quint64 mask)
Definition: guiutil.cpp:981
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:375
QFont getTopLabelFont(int weight, int pxsize)
Definition: guiutil.cpp:122
bool SetStartOnSystemStartup(bool fAutoStart)
Definition: guiutil.cpp:941
QString formatNiceTimeOffset(qint64 secs)
Definition: guiutil.cpp:1029
QFont getSubLabelFontBolded()
Definition: guiutil.cpp:98
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:355
QString boostPathToQString(const fs::path &path)
Definition: guiutil.cpp:956