Fabcoin Core  0.16.2
P2P Digital Currency
guiutil.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2017 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 FABCOIN_QT_GUIUTIL_H
6 #define FABCOIN_QT_GUIUTIL_H
7 
8 #include <amount.h>
9 #include <fs.h>
10 
11 #include <QEvent>
12 #include <QHeaderView>
13 #include <QMessageBox>
14 #include <QObject>
15 #include <QProgressBar>
16 #include <QString>
17 #include <QTableView>
18 #include <QLabel>
19 #include <QToolButton>
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 "fabcoin:" URI into recipient object, return true on successful parsing
49  bool parseFabcoinURI(const QUrl &uri, SendCoinsRecipient *out);
50  bool parseFabcoinURI(QString uri, SendCoinsRecipient *out);
51  QString formatFabcoinURI(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  void copyEntryDataFromList(QAbstractItemView *view, int role=Qt::EditRole);
74 
80  QList<QModelIndex> getEntryData(QAbstractItemView *view, int column);
81 
82  void setClipboard(const QString& str);
83 
94  QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,
95  const QString &filter,
96  QString *selectedSuffixOut);
97 
107  QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir,
108  const QString &filter,
109  QString *selectedSuffixOut);
110 
116  Qt::ConnectionType blockingGUIThreadConnection();
117 
118  // Determine whether a widget is hidden behind other windows
119  bool isObscured(QWidget *w);
120 
121  // Open debug.log
122  void openDebugLogfile();
123 
124  // Open the config file
125  bool openFabcoinConf();
126 
127  // Replace invalid default fonts with known good ones
128  void SubstituteFonts(const QString& language);
129 
134  class ToolTipToRichTextFilter : public QObject
135  {
136  Q_OBJECT
137 
138  public:
139  explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = 0);
140 
141  protected:
142  bool eventFilter(QObject *obj, QEvent *evt);
143 
144  private:
146  };
147 
158  class TableViewLastColumnResizingFixer: public QObject
159  {
160  Q_OBJECT
161 
162  public:
163  TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth, QObject *parent, int columnStretch = 2);
164  void stretchColumnWidth(int column);
165 
166  private:
167  QTableView* tableView;
173 
174  void adjustTableColumnsWidth();
175  int getAvailableWidthForColumn(int column);
176  int getColumnsWidth();
177  void connectViewHeadersSignals();
178  void disconnectViewHeadersSignals();
179  void setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode);
180  void resizeColumn(int nColumnIndex, int width);
181 
182  private Q_SLOTS:
183  void on_sectionResized(int logicalIndex, int oldSize, int newSize);
184  void on_geometriesChanged();
185  };
186 
188  bool SetStartOnSystemStartup(bool fAutoStart);
189 
190  /* Convert QString to OS specific boost path through UTF-8 */
191  fs::path qstringToBoostPath(const QString &path);
192 
193  /* Convert OS specific boost path to QString through UTF-8 */
194  QString boostPathToQString(const fs::path &path);
195 
196  /* Convert seconds into a QString with days, hours, mins, secs */
197  QString formatDurationStr(int secs);
198 
199  /* Format CNodeStats.nServices bitmask into a user-readable string */
200  QString formatServicesStr(quint64 mask);
201 
202  /* Format a CNodeCombinedStats.dPingTime into a user-readable string or display N/A, if 0*/
203  QString formatPingTime(double dPingTime);
204 
205  /* Format a CNodeCombinedStats.nTimeOffset into a user-readable string. */
206  QString formatTimeOffset(int64_t nTimeOffset);
207 
208  QString formatNiceTimeOffset(qint64 secs);
209 
210  class ClickableLabel : public QLabel
211  {
212  Q_OBJECT
213 
214  Q_SIGNALS:
218  void clicked(const QPoint& point);
219  protected:
220  void mouseReleaseEvent(QMouseEvent *event);
221  };
222 
223  class ClickableProgressBar : public QProgressBar
224  {
225  Q_OBJECT
226 
227  Q_SIGNALS:
231  void clicked(const QPoint& point);
232  protected:
233  void mouseReleaseEvent(QMouseEvent *event);
234  };
235 
236 #if defined(Q_OS_MAC) && QT_VERSION >= 0x050000
237  // workaround for Qt OSX Bug:
238  // https://bugreports.qt-project.org/browse/QTBUG-15631
239  // QProgressBar uses around 10% CPU even when app is in background
240  class ProgressBar : public ClickableProgressBar
241  {
242  bool event(QEvent *e) {
243  return (e->type() != QEvent::StyleAnimationUpdate) ? QProgressBar::event(e) : false;
244  }
245  };
246 #else
248 #endif
249 
250  void formatToolButtons(QToolButton* btn1, QToolButton* btn2 = 0, QToolButton* btn3 = 0);
251 
252 } // namespace GUIUtil
253 
254 #endif // FABCOIN_QT_GUIUTIL_H
void SubstituteFonts(const QString &language)
Definition: guiutil.cpp:447
void openDebugLogfile()
Definition: guiutil.cpp:422
bool isDust(const QString &address, const CAmount &amount)
Definition: guiutil.cpp:250
QFont fixedPitchFont()
Definition: guiutil.cpp:90
Utility functions used by the Fabcoin Qt UI.
Definition: guiutil.cpp:78
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:359
QList< QModelIndex > getEntryData(QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
Definition: guiutil.cpp:302
void setupAmountWidget(QLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:137
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:80
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
Definition: guiutil.cpp:394
QString formatTimeOffset(int64_t nTimeOffset)
Definition: guiutil.cpp:937
bool GetStartOnSystemStartup()
Definition: guiutil.cpp:853
ToolTipToRichTextFilter(int size_threshold, QObject *parent=0)
Definition: guiutil.cpp:483
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:258
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
Definition: guiutil.h:134
void copyEntryDataFromList(QAbstractItemView *view, int role)
Copy a field of the currently selected entry of a view to the clipboard.
Definition: guiutil.cpp:290
Line edit that can be marked as "invalid" to show input validation feedback.
int64_t CAmount
Amount in lius (Can be negative)
Definition: amount.h:15
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:122
bool isObscured(QWidget *w)
Definition: guiutil.cpp:413
bool eventFilter(QObject *obj, QEvent *evt)
Definition: guiutil.cpp:490
bool parseFabcoinURI(const QUrl &uri, SendCoinsRecipient *out)
Definition: guiutil.cpp:146
QString formatDurationStr(int secs)
Definition: guiutil.cpp:874
void setClipboard(const QString &str)
Definition: guiutil.cpp:858
Makes a QTableView last column feel as if it was being resized from its left border.
Definition: guiutil.h:158
ClickableProgressBar ProgressBar
Definition: guiutil.h:247
QString formatPingTime(double dPingTime)
Definition: guiutil.cpp:932
QString formatFabcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:222
fs::path qstringToBoostPath(const QString &path)
Definition: guiutil.cpp:864
QString formatServicesStr(quint64 mask)
Definition: guiutil.cpp:894
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:309
#define e(i)
Definition: sha.cpp:733
bool SetStartOnSystemStartup(bool fAutoStart)
Definition: guiutil.cpp:854
QString formatNiceTimeOffset(qint64 secs)
Definition: guiutil.cpp:942
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
void formatToolButtons(QToolButton *btn1, QToolButton *btn2, QToolButton *btn3)
Definition: guiutil.cpp:989
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:277
QString boostPathToQString(const fs::path &path)
Definition: guiutil.cpp:869
bool openFabcoinConf()
Definition: guiutil.cpp:431