File tree Expand file tree Collapse file tree 5 files changed +57
-3
lines changed Expand file tree Collapse file tree 5 files changed +57
-3
lines changed Original file line number Diff line number Diff line change 6
6
#include " walletmodel.h"
7
7
#include " optionsmodel.h"
8
8
#include " guiutil.h"
9
+ #include " guiconstants.h"
9
10
10
11
#include " init.h"
11
12
#include " ui_interface.h"
@@ -164,6 +165,9 @@ int main(int argc, char *argv[])
164
165
Q_INIT_RESOURCE (bitcoin);
165
166
QApplication app (argc, argv);
166
167
168
+ // Install global event filter that makes sure that long tooltips can be word-wrapped
169
+ app.installEventFilter (new GUIUtil::ToolTipToRichTextFilter (TOOLTIP_WRAP_THRESHOLD, &app));
170
+
167
171
// Command-line options take precedence:
168
172
ParseParameters (argc, argv);
169
173
Original file line number Diff line number Diff line change @@ -563,22 +563,25 @@ void BitcoinGUI::setNumBlocks(int count)
563
563
// Set icon state: spinning if catching up, tick otherwise
564
564
if (secs < 90 *60 && count >= nTotalBlocks)
565
565
{
566
- tooltip = tr (" Up to date" ) + QString (" .\n " ) + tooltip;
566
+ tooltip = tr (" Up to date" ) + QString (" .<br> " ) + tooltip;
567
567
labelBlocksIcon->setPixmap (QIcon (" :/icons/synced" ).pixmap (STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
568
568
}
569
569
else
570
570
{
571
- tooltip = tr (" Catching up..." ) + QString (" \n " ) + tooltip;
571
+ tooltip = tr (" Catching up..." ) + QString (" <br> " ) + tooltip;
572
572
labelBlocksIcon->setMovie (syncIconMovie);
573
573
syncIconMovie->start ();
574
574
}
575
575
576
576
if (!text.isEmpty ())
577
577
{
578
- tooltip += QString (" \n " );
578
+ tooltip += QString (" <br> " );
579
579
tooltip += tr (" Last received block was generated %1." ).arg (text);
580
580
}
581
581
582
+ // Don't word-wrap this (fixed-width) tooltip
583
+ tooltip = QString (" <nobr>" ) + tooltip + QString (" </nobr>" );
584
+
582
585
labelBlocksIcon->setToolTip (tooltip);
583
586
progressBarLabel->setToolTip (tooltip);
584
587
progressBar->setToolTip (tooltip);
Original file line number Diff line number Diff line change @@ -20,4 +20,9 @@ static const int STATUSBAR_ICONSIZE = 16;
20
20
/* Transaction list -- bare address (without label) */
21
21
#define COLOR_BAREADDRESS QColor(140, 140, 140)
22
22
23
+ /* Tooltips longer than this (in characters) are converted into rich text,
24
+ so that they can be word-wrapped.
25
+ */
26
+ static const int TOOLTIP_WRAP_THRESHOLD = 80 ;
27
+
23
28
#endif // GUICONSTANTS_H
Original file line number Diff line number Diff line change @@ -214,5 +214,29 @@ bool isObscured(QWidget *w)
214
214
&& checkPoint (QPoint (w->width ()/2 , w->height ()/2 ), w));
215
215
}
216
216
217
+ ToolTipToRichTextFilter::ToolTipToRichTextFilter (int size_threshold, QObject *parent):
218
+ size_threshold (size_threshold), QObject(parent)
219
+ {
220
+
221
+ }
222
+
223
+ bool ToolTipToRichTextFilter::eventFilter (QObject *obj, QEvent *evt)
224
+ {
225
+ if (evt->type () == QEvent::ToolTipChange)
226
+ {
227
+ QWidget *widget = static_cast <QWidget*>(obj);
228
+ QString tooltip = widget->toolTip ();
229
+ if (!Qt::mightBeRichText (tooltip) && tooltip.size () > size_threshold)
230
+ {
231
+ // Prefix <qt/> to make sure Qt detects this as rich text
232
+ // Escape the current message as HTML and replace \n by <br>
233
+ tooltip = " <qt/>" + HtmlEscape (tooltip, true );
234
+ widget->setToolTip (tooltip);
235
+ return true ;
236
+ }
237
+ }
238
+ return QObject::eventFilter (obj, evt);
239
+ }
240
+
217
241
} // namespace GUIUtil
218
242
Original file line number Diff line number Diff line change 2
2
#define GUIUTIL_H
3
3
4
4
#include < QString>
5
+ #include < QObject>
5
6
6
7
QT_BEGIN_NAMESPACE
7
8
class QFont ;
@@ -69,6 +70,23 @@ namespace GUIUtil
69
70
// Determine whether a widget is hidden behind other windows
70
71
bool isObscured (QWidget *w);
71
72
73
+ /* * Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text
74
+ representation if needed. This assures that Qt can word-wrap long tooltip messages.
75
+ Tooltips longer than the provided size threshold (in characters) are wrapped.
76
+ */
77
+ class ToolTipToRichTextFilter : public QObject
78
+ {
79
+ Q_OBJECT
80
+ public:
81
+ ToolTipToRichTextFilter (int size_threshold, QObject *parent);
82
+
83
+ protected:
84
+ bool eventFilter (QObject *obj, QEvent *evt);
85
+
86
+ private:
87
+ int size_threshold;
88
+ };
89
+
72
90
} // namespace GUIUtil
73
91
74
92
#endif // GUIUTIL_H
You can’t perform that action at this time.
0 commit comments