5b7ee217213cf92f412bd1541c1ed43ed118594f
[novacoin.git] / src / qt / guiutil.h
1 #ifndef GUIUTIL_H
2 #define GUIUTIL_H
3
4 #include <QString>
5 #include <QObject>
6 #include <QMessageBox>
7
8 QT_BEGIN_NAMESPACE
9 class QFont;
10 class QLineEdit;
11 class QWidget;
12 class QDateTime;
13 class QUrl;
14 class QAbstractItemView;
15 QT_END_NAMESPACE
16 class SendCoinsRecipient;
17
18 /** Utility functions used by the Bitcoin Qt UI.
19  */
20 namespace GUIUtil
21 {
22     // Create human-readable string from date
23     QString dateTimeStr(const QDateTime &datetime);
24     QString dateTimeStr(qint64 nTime);
25
26     // Render Bitcoin addresses in monospace font
27     QFont bitcoinAddressFont();
28
29     // Set up widgets for address and amounts
30     void setupAddressWidget(QLineEdit *widget, QWidget *parent);
31     void setupAmountWidget(QLineEdit *widget, QWidget *parent);
32
33     // Parse "novacoin:" URI into recipient object, return true on successful parsing
34     // See Bitcoin URI definition discussion here: https://bitcointalk.org/index.php?topic=33490.0
35     bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out);
36     bool parseBitcoinURI(QString uri, SendCoinsRecipient *out);
37
38     // HTML escaping for rich text controls
39     QString HtmlEscape(const QString& str, bool fMultiLine=false);
40     QString HtmlEscape(const std::string& str, bool fMultiLine=false);
41
42     /** Copy a field of the currently selected entry of a view to the clipboard. Does nothing if nothing
43         is selected.
44        @param[in] column  Data column to extract from the model
45        @param[in] role    Data role to extract from the model
46        @see  TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress
47      */
48     void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole);
49
50     /** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix
51         when no suffix is provided by the user.
52
53       @param[in] parent  Parent window (or 0)
54       @param[in] caption Window caption (or empty, for default)
55       @param[in] dir     Starting directory (or empty, to default to documents directory)
56       @param[in] filter  Filter specification such as "Comma Separated Files (*.csv)"
57       @param[out] selectedSuffixOut  Pointer to return the suffix (file type) that was selected (or 0).
58                   Can be useful when choosing the save file format based on suffix.
59      */
60     QString getSaveFileName(QWidget *parent=0, const QString &caption=QString(),
61                                    const QString &dir=QString(), const QString &filter=QString(),
62                                    QString *selectedSuffixOut=0);
63
64     /** Get connection type to call object slot in GUI thread with invokeMethod. The call will be blocking.
65
66        @returns If called from the GUI thread, return a Qt::DirectConnection.
67                 If called from another thread, return a Qt::BlockingQueuedConnection.
68     */
69     Qt::ConnectionType blockingGUIThreadConnection();
70
71     // Determine whether a widget is hidden behind other windows
72     bool isObscured(QWidget *w);
73
74     // Open debug.log
75     void openDebugLogfile();
76
77     /** Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text
78       representation if needed. This assures that Qt can word-wrap long tooltip messages.
79       Tooltips longer than the provided size threshold (in characters) are wrapped.
80      */
81     class ToolTipToRichTextFilter : public QObject
82     {
83         Q_OBJECT
84
85     public:
86         explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = 0);
87
88     protected:
89         bool eventFilter(QObject *obj, QEvent *evt);
90
91     private:
92         int size_threshold;
93     };
94
95     bool GetStartOnSystemStartup();
96     bool SetStartOnSystemStartup(bool fAutoStart);
97
98     /** Help message for Bitcoin-Qt, shown with --help. */
99     class HelpMessageBox : public QMessageBox
100     {
101         Q_OBJECT
102
103     public:
104         HelpMessageBox(QWidget *parent = 0);
105
106         /** Show message box or print help message to standard output, based on operating system. */
107         void showOrPrint();
108
109         /** Print help message to console */
110         void printToConsole();
111
112     private:
113         QString header;
114         QString coreOptions;
115         QString uiOptions;
116     };
117
118 } // namespace GUIUtil
119
120 #endif // GUIUTIL_H