]> Git Repo - VerusCoin.git/blame - src/qt/guiutil.h
Remove translation for -help-debug options
[VerusCoin.git] / src / qt / guiutil.h
CommitLineData
f914f1a7 1// Copyright (c) 2011-2013 The Bitcoin Core developers
78253fcb 2// Distributed under the MIT software license, see the accompanying
e592d43f
WL
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
84738627
PJ
5#ifndef BITCOIN_QT_GUIUTIL_H
6#define BITCOIN_QT_GUIUTIL_H
0856c1a0 7
a372168e
MF
8#include "amount.h"
9
0ceab00d 10#include <QEvent>
cfe4cad9 11#include <QHeaderView>
5d6b3027 12#include <QMessageBox>
51ed9ec9 13#include <QObject>
0ceab00d 14#include <QProgressBar>
51ed9ec9 15#include <QString>
8c29273f 16#include <QTableView>
0856c1a0 17
7e591c19
WL
18#include <boost/filesystem.hpp>
19
c78bd937 20class QValidatedLineEdit;
32af5266
PK
21class SendCoinsRecipient;
22
e457b021 23QT_BEGIN_NAMESPACE
51ed9ec9
BD
24class QAbstractItemView;
25class QDateTime;
e457b021
WL
26class QFont;
27class QLineEdit;
db7f0234 28class QUrl;
51ed9ec9 29class QWidget;
e457b021
WL
30QT_END_NAMESPACE
31
86d56349 32/** Utility functions used by the Bitcoin Qt UI.
af836ad5 33 */
86d56349 34namespace GUIUtil
e457b021 35{
db7f0234 36 // Create human-readable string from date
86d56349 37 QString dateTimeStr(const QDateTime &datetime);
38 QString dateTimeStr(qint64 nTime);
e457b021 39
ff0ee876 40 // Render Bitcoin addresses in monospace font
86d56349 41 QFont bitcoinAddressFont();
e457b021 42
db7f0234 43 // Set up widgets for address and amounts
c78bd937 44 void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);
86d56349 45 void setupAmountWidget(QLineEdit *widget, QWidget *parent);
db7f0234 46
26227db8 47 // Parse "bitcoin:" URI into recipient object, return true on successful parsing
86d56349 48 bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out);
49 bool parseBitcoinURI(QString uri, SendCoinsRecipient *out);
786b066f 50 QString formatBitcoinURI(const SendCoinsRecipient &info);
e0734571 51
57d80467 52 // Returns true if given address+amount meets "dust" definition
a372168e 53 bool isDust(const QString& address, const CAmount& amount);
57d80467 54
e0734571 55 // HTML escaping for rich text controls
86d56349 56 QString HtmlEscape(const QString& str, bool fMultiLine=false);
57 QString HtmlEscape(const std::string& str, bool fMultiLine=false);
c58e7d4e
WL
58
59 /** Copy a field of the currently selected entry of a view to the clipboard. Does nothing if nothing
60 is selected.
61 @param[in] column Data column to extract from the model
62 @param[in] role Data role to extract from the model
63 @see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress
64 */
86d56349 65 void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole);
c58e7d4e 66
6a86c24d
CL
67 void setClipboard(const QString& str);
68
814efd6f 69 /** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix
303a47c0
WL
70 when no suffix is provided by the user.
71
72 @param[in] parent Parent window (or 0)
73 @param[in] caption Window caption (or empty, for default)
74 @param[in] dir Starting directory (or empty, to default to documents directory)
75 @param[in] filter Filter specification such as "Comma Separated Files (*.csv)"
76 @param[out] selectedSuffixOut Pointer to return the suffix (file type) that was selected (or 0).
77 Can be useful when choosing the save file format based on suffix.
78 */
4f7d496b
PK
79 QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,
80 const QString &filter,
81 QString *selectedSuffixOut);
303a47c0 82
4c603586
WL
83 /** Get open filename, convenience wrapper for QFileDialog::getOpenFileName.
84
85 @param[in] parent Parent window (or 0)
86 @param[in] caption Window caption (or empty, for default)
87 @param[in] dir Starting directory (or empty, to default to documents directory)
88 @param[in] filter Filter specification such as "Comma Separated Files (*.csv)"
89 @param[out] selectedSuffixOut Pointer to return the suffix (file type) that was selected (or 0).
90 Can be useful when choosing the save file format based on suffix.
91 */
92 QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir,
93 const QString &filter,
94 QString *selectedSuffixOut);
95
7e7bcce2
WL
96 /** Get connection type to call object slot in GUI thread with invokeMethod. The call will be blocking.
97
98 @returns If called from the GUI thread, return a Qt::DirectConnection.
99 If called from another thread, return a Qt::BlockingQueuedConnection.
100 */
86d56349 101 Qt::ConnectionType blockingGUIThreadConnection();
102
103 // Determine whether a widget is hidden behind other windows
104 bool isObscured(QWidget *w);
7e7bcce2 105
4d3dda5d
PK
106 // Open debug.log
107 void openDebugLogfile();
108
c4bae530 109 // Replace invalid default fonts with known good ones
f5ad78b3 110 void SubstituteFonts(const QString& language);
c4bae530 111
3793fa09
WL
112 /** Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text
113 representation if needed. This assures that Qt can word-wrap long tooltip messages.
114 Tooltips longer than the provided size threshold (in characters) are wrapped.
115 */
58b01afc 116 class ToolTipToRichTextFilter : public QObject
3793fa09
WL
117 {
118 Q_OBJECT
5d6b3027 119
3793fa09 120 public:
58b01afc 121 explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = 0);
3793fa09
WL
122
123 protected:
124 bool eventFilter(QObject *obj, QEvent *evt);
125
126 private:
127 int size_threshold;
128 };
129
8c29273f 130 /**
131 * Makes a QTableView last column feel as if it was being resized from its left border.
132 * Also makes sure the column widths are never larger than the table's viewport.
133 * In Qt, all columns are resizable from the right, but it's not intuitive resizing the last column from the right.
134 * Usually our second to last columns behave as if stretched, and when on strech mode, columns aren't resizable
135 * interactively or programatically.
136 *
137 * This helper object takes care of this issue.
138 *
139 */
140 class TableViewLastColumnResizingFixer: public QObject
141 {
cfe4cad9 142 Q_OBJECT
8c29273f 143
cfe4cad9
PK
144 public:
145 TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth);
146 void stretchColumnWidth(int column);
147
148 private:
149 QTableView* tableView;
150 int lastColumnMinimumWidth;
151 int allColumnsMinimumWidth;
152 int lastColumnIndex;
153 int columnCount;
154 int secondToLastColumnIndex;
155
156 void adjustTableColumnsWidth();
157 int getAvailableWidthForColumn(int column);
158 int getColumnsWidth();
159 void connectViewHeadersSignals();
160 void disconnectViewHeadersSignals();
161 void setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode);
162 void resizeColumn(int nColumnIndex, int width);
163
164 private slots:
165 void on_sectionResized(int logicalIndex, int oldSize, int newSize);
166 void on_geometriesChanged();
8c29273f 167 };
168
67d4cbab
WL
169 bool GetStartOnSystemStartup();
170 bool SetStartOnSystemStartup(bool fAutoStart);
171
c431e9f1
PK
172 /** Save window size and position */
173 void saveWindowGeometry(const QString& strSetting, QWidget *parent);
174 /** Restore window size and position */
175 void restoreWindowGeometry(const QString& strSetting, const QSize &defaultSizeIn, QWidget *parent);
176
7e591c19
WL
177 /* Convert QString to OS specific boost path through UTF-8 */
178 boost::filesystem::path qstringToBoostPath(const QString &path);
179
180 /* Convert OS specific boost path to QString through UTF-8 */
181 QString boostPathToQString(const boost::filesystem::path &path);
182
65f78a11
AH
183 /* Convert seconds into a QString with days, hours, mins, secs */
184 QString formatDurationStr(int secs);
185
186 /* Format CNodeStats.nServices bitmask into a user-readable string */
e4731dd8 187 QString formatServicesStr(quint64 mask);
a5b2d9c8
PK
188
189 /* Format a CNodeCombinedStats.dPingTime into a user-readable string or display N/A, if 0*/
190 QString formatPingTime(double dPingTime);
73caf47d
PJ
191
192 /* Format a CNodeCombinedStats.nTimeOffset into a user-readable string. */
193 QString formatTimeOffset(int64_t nTimeOffset);
194
c5a22828 195#if defined(Q_OS_MAC) && QT_VERSION >= 0x050000
0ceab00d
JS
196 // workaround for Qt OSX Bug:
197 // https://bugreports.qt-project.org/browse/QTBUG-15631
198 // QProgressBar uses around 10% CPU even when app is in background
199 class ProgressBar : public QProgressBar
200 {
201 bool event(QEvent *e) {
202 return (e->type() != QEvent::StyleAnimationUpdate) ? QProgressBar::event(e) : false;
203 }
204 };
205#else
206 typedef QProgressBar ProgressBar;
207#endif
208
86d56349 209} // namespace GUIUtil
0856c1a0 210
84738627 211#endif // BITCOIN_QT_GUIUTIL_H
This page took 0.215237 seconds and 4 git commands to generate.