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