Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qwhatsthis.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||
5 | - | |||||||||||||||||||||||||
6 | __attribute__((visibility("default"))) void qDeleteInEventHandler(QObject *o); | - | ||||||||||||||||||||||||
7 | - | |||||||||||||||||||||||||
8 | class QWhatsThat : public QWidget | - | ||||||||||||||||||||||||
9 | { | - | ||||||||||||||||||||||||
10 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||||||||||||||||||||
11 | #pragma GCC diagnostic push | - | ||||||||||||||||||||||||
12 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||||||||||||||
13 | #pragma GCC diagnostic pop | - | ||||||||||||||||||||||||
14 | struct QPrivateSignal {}; | - | ||||||||||||||||||||||||
15 | - | |||||||||||||||||||||||||
16 | public: | - | ||||||||||||||||||||||||
17 | QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor); | - | ||||||||||||||||||||||||
18 | ~QWhatsThat() ; | - | ||||||||||||||||||||||||
19 | - | |||||||||||||||||||||||||
20 | static QWhatsThat *instance; | - | ||||||||||||||||||||||||
21 | - | |||||||||||||||||||||||||
22 | protected: | - | ||||||||||||||||||||||||
23 | void showEvent(QShowEvent *e) override; | - | ||||||||||||||||||||||||
24 | void mousePressEvent(QMouseEvent*) override; | - | ||||||||||||||||||||||||
25 | void mouseReleaseEvent(QMouseEvent*) override; | - | ||||||||||||||||||||||||
26 | void mouseMoveEvent(QMouseEvent*) override; | - | ||||||||||||||||||||||||
27 | void keyPressEvent(QKeyEvent*) override; | - | ||||||||||||||||||||||||
28 | void paintEvent(QPaintEvent*) override; | - | ||||||||||||||||||||||||
29 | - | |||||||||||||||||||||||||
30 | private: | - | ||||||||||||||||||||||||
31 | QPointer<QWidget>widget; | - | ||||||||||||||||||||||||
32 | bool pressed; | - | ||||||||||||||||||||||||
33 | QString text; | - | ||||||||||||||||||||||||
34 | QTextDocument* doc; | - | ||||||||||||||||||||||||
35 | QString anchor; | - | ||||||||||||||||||||||||
36 | QPixmap background; | - | ||||||||||||||||||||||||
37 | }; | - | ||||||||||||||||||||||||
38 | - | |||||||||||||||||||||||||
39 | QWhatsThat *QWhatsThat::instance = 0; | - | ||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||
42 | static int shadowWidth = 6; | - | ||||||||||||||||||||||||
43 | static const int vMargin = 8; | - | ||||||||||||||||||||||||
44 | static const int hMargin = 12; | - | ||||||||||||||||||||||||
45 | - | |||||||||||||||||||||||||
46 | static inline bool dropShadow() | - | ||||||||||||||||||||||||
47 | { | - | ||||||||||||||||||||||||
48 | if (const
| 0 | ||||||||||||||||||||||||
49 | return never executed: theme->themeHint(QPlatformTheme::DropShadow).toBool();return theme->themeHint(QPlatformTheme::DropShadow).toBool(); never executed: return theme->themeHint(QPlatformTheme::DropShadow).toBool(); | 0 | ||||||||||||||||||||||||
50 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||
51 | } | - | ||||||||||||||||||||||||
52 | - | |||||||||||||||||||||||||
53 | QWhatsThat::QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor) | - | ||||||||||||||||||||||||
54 | : QWidget(parent, Qt::Popup), | - | ||||||||||||||||||||||||
55 | widget(showTextFor), pressed(false), text(txt) | - | ||||||||||||||||||||||||
56 | { | - | ||||||||||||||||||||||||
57 | delete instance; | - | ||||||||||||||||||||||||
58 | instance = this; | - | ||||||||||||||||||||||||
59 | setAttribute(Qt::WA_DeleteOnClose, true); | - | ||||||||||||||||||||||||
60 | setAttribute(Qt::WA_NoSystemBackground, true); | - | ||||||||||||||||||||||||
61 | if (parent
| 0 | ||||||||||||||||||||||||
62 | setPalette(parent->palette()); never executed: setPalette(parent->palette()); | 0 | ||||||||||||||||||||||||
63 | setMouseTracking(true); | - | ||||||||||||||||||||||||
64 | setFocusPolicy(Qt::StrongFocus); | - | ||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||
66 | setCursor(Qt::ArrowCursor); | - | ||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||
68 | QRect r; | - | ||||||||||||||||||||||||
69 | doc = 0; | - | ||||||||||||||||||||||||
70 | ensurePolished(); | - | ||||||||||||||||||||||||
71 | if (Qt::mightBeRichText(text)
| 0 | ||||||||||||||||||||||||
72 | doc = new QTextDocument(); | - | ||||||||||||||||||||||||
73 | doc->setUndoRedoEnabled(false); | - | ||||||||||||||||||||||||
74 | doc->setDefaultFont(QApplication::font(this)); | - | ||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||
76 | - | |||||||||||||||||||||||||
77 | - | |||||||||||||||||||||||||
78 | doc->setHtml(text); | - | ||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||
80 | doc->setUndoRedoEnabled(false); | - | ||||||||||||||||||||||||
81 | doc->adjustSize(); | - | ||||||||||||||||||||||||
82 | r.setTop(0); | - | ||||||||||||||||||||||||
83 | r.setLeft(0); | - | ||||||||||||||||||||||||
84 | r.setSize(doc->size().toSize()); | - | ||||||||||||||||||||||||
85 | } never executed: end of block | 0 | ||||||||||||||||||||||||
86 | else | - | ||||||||||||||||||||||||
87 | { | - | ||||||||||||||||||||||||
88 | int sw = QApplication::desktop()->width() / 3; | - | ||||||||||||||||||||||||
89 | if (sw < 200
| 0 | ||||||||||||||||||||||||
90 | sw = 200; never executed: sw = 200; | 0 | ||||||||||||||||||||||||
91 | else if (sw > 300
| 0 | ||||||||||||||||||||||||
92 | sw = 300; never executed: sw = 300; | 0 | ||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||
94 | r = fontMetrics().boundingRect(0, 0, sw, 1000, | - | ||||||||||||||||||||||||
95 | Qt::AlignLeft + Qt::AlignTop | - | ||||||||||||||||||||||||
96 | + Qt::TextWordWrap + Qt::TextExpandTabs, | - | ||||||||||||||||||||||||
97 | text); | - | ||||||||||||||||||||||||
98 | } never executed: end of block | 0 | ||||||||||||||||||||||||
99 | shadowWidth = dropShadow()
| 0 | ||||||||||||||||||||||||
100 | resize(r.width() + 2*hMargin + shadowWidth, r.height() + 2*vMargin + shadowWidth); | - | ||||||||||||||||||||||||
101 | } never executed: end of block | 0 | ||||||||||||||||||||||||
102 | - | |||||||||||||||||||||||||
103 | QWhatsThat::~QWhatsThat() | - | ||||||||||||||||||||||||
104 | { | - | ||||||||||||||||||||||||
105 | instance = 0; | - | ||||||||||||||||||||||||
106 | if (doc
| 0 | ||||||||||||||||||||||||
107 | delete doc; never executed: delete doc; | 0 | ||||||||||||||||||||||||
108 | } never executed: end of block | 0 | ||||||||||||||||||||||||
109 | - | |||||||||||||||||||||||||
110 | void QWhatsThat::showEvent(QShowEvent *) | - | ||||||||||||||||||||||||
111 | { | - | ||||||||||||||||||||||||
112 | background = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->internalWinId(), | - | ||||||||||||||||||||||||
113 | x(), y(), width(), height()); | - | ||||||||||||||||||||||||
114 | } never executed: end of block | 0 | ||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||
116 | void QWhatsThat::mousePressEvent(QMouseEvent* e) | - | ||||||||||||||||||||||||
117 | { | - | ||||||||||||||||||||||||
118 | pressed = true; | - | ||||||||||||||||||||||||
119 | if (e->button() == Qt::LeftButton
| 0 | ||||||||||||||||||||||||
120 | if (doc
| 0 | ||||||||||||||||||||||||
121 | anchor = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); never executed: anchor = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); | 0 | ||||||||||||||||||||||||
122 | return; never executed: return; | 0 | ||||||||||||||||||||||||
123 | } | - | ||||||||||||||||||||||||
124 | close(); | - | ||||||||||||||||||||||||
125 | } never executed: end of block | 0 | ||||||||||||||||||||||||
126 | - | |||||||||||||||||||||||||
127 | void QWhatsThat::mouseReleaseEvent(QMouseEvent* e) | - | ||||||||||||||||||||||||
128 | { | - | ||||||||||||||||||||||||
129 | if (!pressed
| 0 | ||||||||||||||||||||||||
130 | return; never executed: return; | 0 | ||||||||||||||||||||||||
131 | if (widget
| 0 | ||||||||||||||||||||||||
132 | QString a = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); | - | ||||||||||||||||||||||||
133 | QString href; | - | ||||||||||||||||||||||||
134 | if (anchor == a
| 0 | ||||||||||||||||||||||||
135 | href = a; never executed: href = a; | 0 | ||||||||||||||||||||||||
136 | anchor.clear(); | - | ||||||||||||||||||||||||
137 | if (!href.isEmpty()
| 0 | ||||||||||||||||||||||||
138 | QWhatsThisClickedEvent e(href); | - | ||||||||||||||||||||||||
139 | if (QApplication::sendEvent(widget, &e)
| 0 | ||||||||||||||||||||||||
140 | return; never executed: return; | 0 | ||||||||||||||||||||||||
141 | } never executed: end of block | 0 | ||||||||||||||||||||||||
142 | } never executed: end of block | 0 | ||||||||||||||||||||||||
143 | close(); | - | ||||||||||||||||||||||||
144 | } never executed: end of block | 0 | ||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||
146 | void QWhatsThat::mouseMoveEvent(QMouseEvent* e) | - | ||||||||||||||||||||||||
147 | { | - | ||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||
150 | - | |||||||||||||||||||||||||
151 | if (!doc
| 0 | ||||||||||||||||||||||||
152 | return; never executed: return; | 0 | ||||||||||||||||||||||||
153 | QString a = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); | - | ||||||||||||||||||||||||
154 | if (!a.isEmpty()
| 0 | ||||||||||||||||||||||||
155 | setCursor(Qt::PointingHandCursor); never executed: setCursor(Qt::PointingHandCursor); | 0 | ||||||||||||||||||||||||
156 | else | - | ||||||||||||||||||||||||
157 | setCursor(Qt::ArrowCursor); never executed: setCursor(Qt::ArrowCursor); | 0 | ||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||
159 | } | - | ||||||||||||||||||||||||
160 | - | |||||||||||||||||||||||||
161 | void QWhatsThat::keyPressEvent(QKeyEvent*) | - | ||||||||||||||||||||||||
162 | { | - | ||||||||||||||||||||||||
163 | close(); | - | ||||||||||||||||||||||||
164 | } never executed: end of block | 0 | ||||||||||||||||||||||||
165 | - | |||||||||||||||||||||||||
166 | void QWhatsThat::paintEvent(QPaintEvent*) | - | ||||||||||||||||||||||||
167 | { | - | ||||||||||||||||||||||||
168 | const bool drawShadow = dropShadow(); | - | ||||||||||||||||||||||||
169 | - | |||||||||||||||||||||||||
170 | QRect r = rect(); | - | ||||||||||||||||||||||||
171 | r.adjust(0, 0, -1, -1); | - | ||||||||||||||||||||||||
172 | if (drawShadow
| 0 | ||||||||||||||||||||||||
173 | r.adjust(0, 0, -shadowWidth, -shadowWidth); never executed: r.adjust(0, 0, -shadowWidth, -shadowWidth); | 0 | ||||||||||||||||||||||||
174 | QPainter p(this); | - | ||||||||||||||||||||||||
175 | p.drawPixmap(0, 0, background); | - | ||||||||||||||||||||||||
176 | p.setPen(QPen(palette().toolTipText(), 0)); | - | ||||||||||||||||||||||||
177 | p.setBrush(palette().toolTipBase()); | - | ||||||||||||||||||||||||
178 | p.drawRect(r); | - | ||||||||||||||||||||||||
179 | int w = r.width(); | - | ||||||||||||||||||||||||
180 | int h = r.height(); | - | ||||||||||||||||||||||||
181 | p.setPen(palette().brush(QPalette::Dark).color()); | - | ||||||||||||||||||||||||
182 | p.drawRect(1, 1, w-2, h-2); | - | ||||||||||||||||||||||||
183 | if (drawShadow
| 0 | ||||||||||||||||||||||||
184 | p.setPen(palette().shadow().color()); | - | ||||||||||||||||||||||||
185 | p.drawPoint(w + 5, 6); | - | ||||||||||||||||||||||||
186 | p.drawLine(w + 3, 6, w + 5, 8); | - | ||||||||||||||||||||||||
187 | p.drawLine(w + 1, 6, w + 5, 10); | - | ||||||||||||||||||||||||
188 | int i; | - | ||||||||||||||||||||||||
189 | for(i=7; i < h
| 0 | ||||||||||||||||||||||||
190 | p.drawLine(w, i, w + 5, i + 5); never executed: p.drawLine(w, i, w + 5, i + 5); | 0 | ||||||||||||||||||||||||
191 | for(i = w - i + h; i > 6
| 0 | ||||||||||||||||||||||||
192 | p.drawLine(i, h, i + 5, h + 5); never executed: p.drawLine(i, h, i + 5, h + 5); | 0 | ||||||||||||||||||||||||
193 | for(; i > 0
| 0 | ||||||||||||||||||||||||
194 | p.drawLine(6, h + 6 - i, i + 5, h + 5); never executed: p.drawLine(6, h + 6 - i, i + 5, h + 5); | 0 | ||||||||||||||||||||||||
195 | } never executed: end of block | 0 | ||||||||||||||||||||||||
196 | r.adjust(0, 0, 1, 1); | - | ||||||||||||||||||||||||
197 | p.setPen(palette().toolTipText().color()); | - | ||||||||||||||||||||||||
198 | r.adjust(hMargin, vMargin, -hMargin, -vMargin); | - | ||||||||||||||||||||||||
199 | - | |||||||||||||||||||||||||
200 | if (doc
| 0 | ||||||||||||||||||||||||
201 | p.translate(r.x(), r.y()); | - | ||||||||||||||||||||||||
202 | QRect rect = r; | - | ||||||||||||||||||||||||
203 | rect.translate(-r.x(), -r.y()); | - | ||||||||||||||||||||||||
204 | p.setClipRect(rect); | - | ||||||||||||||||||||||||
205 | QAbstractTextDocumentLayout::PaintContext context; | - | ||||||||||||||||||||||||
206 | context.palette.setBrush(QPalette::Text, context.palette.toolTipText()); | - | ||||||||||||||||||||||||
207 | doc->documentLayout()->draw(&p, context); | - | ||||||||||||||||||||||||
208 | } never executed: end of block | 0 | ||||||||||||||||||||||||
209 | else | - | ||||||||||||||||||||||||
210 | { | - | ||||||||||||||||||||||||
211 | p.drawText(r, Qt::AlignLeft + Qt::AlignTop + Qt::TextWordWrap + Qt::TextExpandTabs, text); | - | ||||||||||||||||||||||||
212 | } never executed: end of block | 0 | ||||||||||||||||||||||||
213 | } | - | ||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||
215 | static const char * const button_image[] = { | - | ||||||||||||||||||||||||
216 | "16 16 3 1", | - | ||||||||||||||||||||||||
217 | " c None", | - | ||||||||||||||||||||||||
218 | "o c #000000", | - | ||||||||||||||||||||||||
219 | "a c #000080", | - | ||||||||||||||||||||||||
220 | "o aaaaa ", | - | ||||||||||||||||||||||||
221 | "oo aaa aaa ", | - | ||||||||||||||||||||||||
222 | "ooo aaa aaa", | - | ||||||||||||||||||||||||
223 | "oooo aa aa", | - | ||||||||||||||||||||||||
224 | "ooooo aa aa", | - | ||||||||||||||||||||||||
225 | "oooooo a aaa", | - | ||||||||||||||||||||||||
226 | "ooooooo aaa ", | - | ||||||||||||||||||||||||
227 | "oooooooo aaa ", | - | ||||||||||||||||||||||||
228 | "ooooooooo aaa ", | - | ||||||||||||||||||||||||
229 | "ooooo aaa ", | - | ||||||||||||||||||||||||
230 | "oo ooo ", | - | ||||||||||||||||||||||||
231 | "o ooo aaa ", | - | ||||||||||||||||||||||||
232 | " ooo aaa ", | - | ||||||||||||||||||||||||
233 | " ooo ", | - | ||||||||||||||||||||||||
234 | " ooo ", | - | ||||||||||||||||||||||||
235 | " ooo "}; | - | ||||||||||||||||||||||||
236 | - | |||||||||||||||||||||||||
237 | class QWhatsThisPrivate : public QObject | - | ||||||||||||||||||||||||
238 | { | - | ||||||||||||||||||||||||
239 | public: | - | ||||||||||||||||||||||||
240 | QWhatsThisPrivate(); | - | ||||||||||||||||||||||||
241 | ~QWhatsThisPrivate(); | - | ||||||||||||||||||||||||
242 | static QWhatsThisPrivate *instance; | - | ||||||||||||||||||||||||
243 | bool eventFilter(QObject *, QEvent *) override; | - | ||||||||||||||||||||||||
244 | QPointer<QAction> action; | - | ||||||||||||||||||||||||
245 | static void say(QWidget *, const QString &, int x = 0, int y = 0); | - | ||||||||||||||||||||||||
246 | static void notifyToplevels(QEvent *e); | - | ||||||||||||||||||||||||
247 | bool leaveOnMouseRelease; | - | ||||||||||||||||||||||||
248 | }; | - | ||||||||||||||||||||||||
249 | - | |||||||||||||||||||||||||
250 | void QWhatsThisPrivate::notifyToplevels(QEvent *e) | - | ||||||||||||||||||||||||
251 | { | - | ||||||||||||||||||||||||
252 | QWidgetList toplevels = QApplication::topLevelWidgets(); | - | ||||||||||||||||||||||||
253 | for (int i = 0; i < toplevels.count()
| 0 | ||||||||||||||||||||||||
254 | QWidget *w = toplevels.at(i); | - | ||||||||||||||||||||||||
255 | QApplication::sendEvent(w, e); | - | ||||||||||||||||||||||||
256 | } never executed: end of block | 0 | ||||||||||||||||||||||||
257 | } never executed: end of block | 0 | ||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||
259 | QWhatsThisPrivate *QWhatsThisPrivate::instance = 0; | - | ||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||
261 | QWhatsThisPrivate::QWhatsThisPrivate() | - | ||||||||||||||||||||||||
262 | : leaveOnMouseRelease(false) | - | ||||||||||||||||||||||||
263 | { | - | ||||||||||||||||||||||||
264 | instance = this; | - | ||||||||||||||||||||||||
265 | (static_cast<QApplication *>(QCoreApplication::instance()))->installEventFilter(this); | - | ||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||
267 | QPoint pos = QCursor::pos(); | - | ||||||||||||||||||||||||
268 | if (QWidget *w = QApplication::widgetAt(pos)
| 0 | ||||||||||||||||||||||||
269 | QHelpEvent e(QEvent::QueryWhatsThis, w->mapFromGlobal(pos), pos); | - | ||||||||||||||||||||||||
270 | bool sentEvent = QApplication::sendEvent(w, &e); | - | ||||||||||||||||||||||||
271 | - | |||||||||||||||||||||||||
272 | - | |||||||||||||||||||||||||
273 | - | |||||||||||||||||||||||||
274 | QApplication::setOverrideCursor((!sentEvent || !e.isAccepted())? | - | ||||||||||||||||||||||||
275 | Qt::ForbiddenCursor:Qt::WhatsThisCursor); | - | ||||||||||||||||||||||||
276 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
277 | QApplication::setOverrideCursor(Qt::WhatsThisCursor); | - | ||||||||||||||||||||||||
278 | - | |||||||||||||||||||||||||
279 | } never executed: end of block | 0 | ||||||||||||||||||||||||
280 | - | |||||||||||||||||||||||||
281 | QAccessibleEvent event(this, QAccessible::ContextHelpStart); | - | ||||||||||||||||||||||||
282 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||
284 | } never executed: end of block | 0 | ||||||||||||||||||||||||
285 | - | |||||||||||||||||||||||||
286 | QWhatsThisPrivate::~QWhatsThisPrivate() | - | ||||||||||||||||||||||||
287 | { | - | ||||||||||||||||||||||||
288 | if (action
| 0 | ||||||||||||||||||||||||
289 | action->setChecked(false); never executed: action->setChecked(false); | 0 | ||||||||||||||||||||||||
290 | - | |||||||||||||||||||||||||
291 | QApplication::restoreOverrideCursor(); | - | ||||||||||||||||||||||||
292 | - | |||||||||||||||||||||||||
293 | - | |||||||||||||||||||||||||
294 | QAccessibleEvent event(this, QAccessible::ContextHelpEnd); | - | ||||||||||||||||||||||||
295 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||||||||
296 | - | |||||||||||||||||||||||||
297 | instance = 0; | - | ||||||||||||||||||||||||
298 | } never executed: end of block | 0 | ||||||||||||||||||||||||
299 | - | |||||||||||||||||||||||||
300 | bool QWhatsThisPrivate::eventFilter(QObject *o, QEvent *e) | - | ||||||||||||||||||||||||
301 | { | - | ||||||||||||||||||||||||
302 | if (!o->isWidgetType()
| 0 | ||||||||||||||||||||||||
303 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||
304 | QWidget * w = static_cast<QWidget *>(o); | - | ||||||||||||||||||||||||
305 | bool customWhatsThis = w->testAttribute(Qt::WA_CustomWhatsThis); | - | ||||||||||||||||||||||||
306 | switch (e->type()) { | - | ||||||||||||||||||||||||
307 | case never executed: QEvent::MouseButtonPress:case QEvent::MouseButtonPress: never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||||||||
308 | { | - | ||||||||||||||||||||||||
309 | QMouseEvent *me = static_cast<QMouseEvent*>(e); | - | ||||||||||||||||||||||||
310 | if (me->button() == Qt::RightButton
| 0 | ||||||||||||||||||||||||
311 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||
312 | QHelpEvent e(QEvent::WhatsThis, me->pos(), me->globalPos()); | - | ||||||||||||||||||||||||
313 | if (!QApplication::sendEvent(w, &e)
| 0 | ||||||||||||||||||||||||
314 | leaveOnMouseRelease = true; never executed: leaveOnMouseRelease = true; | 0 | ||||||||||||||||||||||||
315 | - | |||||||||||||||||||||||||
316 | } break; never executed: break; | 0 | ||||||||||||||||||||||||
317 | - | |||||||||||||||||||||||||
318 | case never executed: QEvent::MouseMove:case QEvent::MouseMove: never executed: case QEvent::MouseMove: | 0 | ||||||||||||||||||||||||
319 | { | - | ||||||||||||||||||||||||
320 | QMouseEvent *me = static_cast<QMouseEvent*>(e); | - | ||||||||||||||||||||||||
321 | QHelpEvent e(QEvent::QueryWhatsThis, me->pos(), me->globalPos()); | - | ||||||||||||||||||||||||
322 | bool sentEvent = QApplication::sendEvent(w, &e); | - | ||||||||||||||||||||||||
323 | - | |||||||||||||||||||||||||
324 | - | |||||||||||||||||||||||||
325 | - | |||||||||||||||||||||||||
326 | QApplication::changeOverrideCursor((!sentEvent || !e.isAccepted())? | - | ||||||||||||||||||||||||
327 | Qt::ForbiddenCursor:Qt::WhatsThisCursor); | - | ||||||||||||||||||||||||
328 | - | |||||||||||||||||||||||||
329 | } | - | ||||||||||||||||||||||||
330 | - | |||||||||||||||||||||||||
331 | case never executed: QEvent::MouseButtonRelease:case QEvent::MouseButtonRelease: never executed: case QEvent::MouseButtonRelease: code before this statement never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||||||||
332 | case never executed: QEvent::MouseButtonDblClick:case QEvent::MouseButtonDblClick: never executed: case QEvent::MouseButtonDblClick: | 0 | ||||||||||||||||||||||||
333 | if (leaveOnMouseRelease
| 0 | ||||||||||||||||||||||||
334 | QWhatsThis::leaveWhatsThisMode(); never executed: QWhatsThis::leaveWhatsThisMode(); | 0 | ||||||||||||||||||||||||
335 | if (static_cast<
| 0 | ||||||||||||||||||||||||
336 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||
337 | break; never executed: break; | 0 | ||||||||||||||||||||||||
338 | case never executed: QEvent::KeyPress:case QEvent::KeyPress: never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||||||||
339 | { | - | ||||||||||||||||||||||||
340 | QKeyEvent* kev = (QKeyEvent*)e; | - | ||||||||||||||||||||||||
341 | - | |||||||||||||||||||||||||
342 | if (kev->matches(QKeySequence::Cancel)
| 0 | ||||||||||||||||||||||||
343 | QWhatsThis::leaveWhatsThisMode(); | - | ||||||||||||||||||||||||
344 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||||||||
345 | } else if (customWhatsThis
| 0 | ||||||||||||||||||||||||
346 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||
347 | } else if (kev->key() == Qt::Key_Menu
| 0 | ||||||||||||||||||||||||
348 | (kev->key() == Qt::Key_F10
| 0 | ||||||||||||||||||||||||
349 | kev->modifiers() == Qt::ShiftModifier
| 0 | ||||||||||||||||||||||||
350 | - | |||||||||||||||||||||||||
351 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||
352 | } else if (kev->key() != Qt::Key_Shift
| 0 | ||||||||||||||||||||||||
353 | && kev->key() != Qt::Key_Control
| 0 | ||||||||||||||||||||||||
354 | QWhatsThis::leaveWhatsThisMode(); | - | ||||||||||||||||||||||||
355 | } never executed: end of block | 0 | ||||||||||||||||||||||||
356 | } break; never executed: break; | 0 | ||||||||||||||||||||||||
357 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||||||||
358 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||
359 | } | - | ||||||||||||||||||||||||
360 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||||||||
361 | } | - | ||||||||||||||||||||||||
362 | - | |||||||||||||||||||||||||
363 | class QWhatsThisAction: public QAction | - | ||||||||||||||||||||||||
364 | { | - | ||||||||||||||||||||||||
365 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||||||||||||||||||||
366 | #pragma GCC diagnostic push | - | ||||||||||||||||||||||||
367 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||||||||||||||
368 | #pragma GCC diagnostic pop | - | ||||||||||||||||||||||||
369 | struct QPrivateSignal {}; | - | ||||||||||||||||||||||||
370 | - | |||||||||||||||||||||||||
371 | public: | - | ||||||||||||||||||||||||
372 | explicit QWhatsThisAction(QObject* parent = 0); | - | ||||||||||||||||||||||||
373 | - | |||||||||||||||||||||||||
374 | private : | - | ||||||||||||||||||||||||
375 | void actionTriggered(); | - | ||||||||||||||||||||||||
376 | }; | - | ||||||||||||||||||||||||
377 | - | |||||||||||||||||||||||||
378 | QWhatsThisAction::QWhatsThisAction(QObject *parent) : QAction(tr("What's This?"), parent) | - | ||||||||||||||||||||||||
379 | { | - | ||||||||||||||||||||||||
380 | - | |||||||||||||||||||||||||
381 | QPixmap p(button_image); | - | ||||||||||||||||||||||||
382 | setIcon(p); | - | ||||||||||||||||||||||||
383 | - | |||||||||||||||||||||||||
384 | setCheckable(true); | - | ||||||||||||||||||||||||
385 | connect(this, qFlagLocation("2""triggered()" "\0" __FILE__ ":" "501"), this, qFlagLocation("1""actionTriggered()" "\0" __FILE__ ":" "501")); | - | ||||||||||||||||||||||||
386 | - | |||||||||||||||||||||||||
387 | setShortcut(Qt::ShiftModifier + Qt::Key_F1); | - | ||||||||||||||||||||||||
388 | - | |||||||||||||||||||||||||
389 | } never executed: end of block | 0 | ||||||||||||||||||||||||
390 | - | |||||||||||||||||||||||||
391 | void QWhatsThisAction::actionTriggered() | - | ||||||||||||||||||||||||
392 | { | - | ||||||||||||||||||||||||
393 | if (isChecked()
| 0 | ||||||||||||||||||||||||
394 | QWhatsThis::enterWhatsThisMode(); | - | ||||||||||||||||||||||||
395 | QWhatsThisPrivate::instance->action = this; | - | ||||||||||||||||||||||||
396 | } never executed: end of block | 0 | ||||||||||||||||||||||||
397 | } never executed: end of block | 0 | ||||||||||||||||||||||||
398 | void QWhatsThis::enterWhatsThisMode() | - | ||||||||||||||||||||||||
399 | { | - | ||||||||||||||||||||||||
400 | if (QWhatsThisPrivate::instance
| 0 | ||||||||||||||||||||||||
401 | return; never executed: return; | 0 | ||||||||||||||||||||||||
402 | (void) new QWhatsThisPrivate; | - | ||||||||||||||||||||||||
403 | QEvent e(QEvent::EnterWhatsThisMode); | - | ||||||||||||||||||||||||
404 | QWhatsThisPrivate::notifyToplevels(&e); | - | ||||||||||||||||||||||||
405 | } never executed: end of block | 0 | ||||||||||||||||||||||||
406 | - | |||||||||||||||||||||||||
407 | - | |||||||||||||||||||||||||
408 | - | |||||||||||||||||||||||||
409 | - | |||||||||||||||||||||||||
410 | - | |||||||||||||||||||||||||
411 | - | |||||||||||||||||||||||||
412 | - | |||||||||||||||||||||||||
413 | bool QWhatsThis::inWhatsThisMode() | - | ||||||||||||||||||||||||
414 | { | - | ||||||||||||||||||||||||
415 | return never executed: (QWhatsThisPrivate::instance != 0);return (QWhatsThisPrivate::instance != 0); never executed: return (QWhatsThisPrivate::instance != 0); | 0 | ||||||||||||||||||||||||
416 | } | - | ||||||||||||||||||||||||
417 | void QWhatsThis::leaveWhatsThisMode() | - | ||||||||||||||||||||||||
418 | { | - | ||||||||||||||||||||||||
419 | delete QWhatsThisPrivate::instance; | - | ||||||||||||||||||||||||
420 | QEvent e(QEvent::LeaveWhatsThisMode); | - | ||||||||||||||||||||||||
421 | QWhatsThisPrivate::notifyToplevels(&e); | - | ||||||||||||||||||||||||
422 | } never executed: end of block | 0 | ||||||||||||||||||||||||
423 | - | |||||||||||||||||||||||||
424 | void QWhatsThisPrivate::say(QWidget * widget, const QString &text, int x, int y) | - | ||||||||||||||||||||||||
425 | { | - | ||||||||||||||||||||||||
426 | if (text.size() == 0
| 0 | ||||||||||||||||||||||||
427 | return; never executed: return; | 0 | ||||||||||||||||||||||||
428 | - | |||||||||||||||||||||||||
429 | QWhatsThat *whatsThat = new QWhatsThat( | - | ||||||||||||||||||||||||
430 | text, | - | ||||||||||||||||||||||||
431 | - | |||||||||||||||||||||||||
432 | - | |||||||||||||||||||||||||
433 | - | |||||||||||||||||||||||||
434 | 0, | - | ||||||||||||||||||||||||
435 | - | |||||||||||||||||||||||||
436 | widget | - | ||||||||||||||||||||||||
437 | ); | - | ||||||||||||||||||||||||
438 | - | |||||||||||||||||||||||||
439 | - | |||||||||||||||||||||||||
440 | - | |||||||||||||||||||||||||
441 | - | |||||||||||||||||||||||||
442 | int scr = (widget
| 0 | ||||||||||||||||||||||||
443 | QApplication::desktop()->screenNumber(widget) : | - | ||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||
445 | - | |||||||||||||||||||||||||
446 | - | |||||||||||||||||||||||||
447 | QApplication::desktop()->screenNumber(QPoint(x,y)) | - | ||||||||||||||||||||||||
448 | - | |||||||||||||||||||||||||
449 | ); | - | ||||||||||||||||||||||||
450 | QRect screen = QApplication::desktop()->screenGeometry(scr); | - | ||||||||||||||||||||||||
451 | - | |||||||||||||||||||||||||
452 | int w = whatsThat->width(); | - | ||||||||||||||||||||||||
453 | int h = whatsThat->height(); | - | ||||||||||||||||||||||||
454 | int sx = screen.x(); | - | ||||||||||||||||||||||||
455 | int sy = screen.y(); | - | ||||||||||||||||||||||||
456 | - | |||||||||||||||||||||||||
457 | - | |||||||||||||||||||||||||
458 | - | |||||||||||||||||||||||||
459 | QPoint pos; | - | ||||||||||||||||||||||||
460 | if (widget
| 0 | ||||||||||||||||||||||||
461 | pos = widget->mapToGlobal(QPoint(0,0)); never executed: pos = widget->mapToGlobal(QPoint(0,0)); | 0 | ||||||||||||||||||||||||
462 | - | |||||||||||||||||||||||||
463 | if (widget
| 0 | ||||||||||||||||||||||||
464 | x = pos.x() + widget->width()/2 - w/2; never executed: x = pos.x() + widget->width()/2 - w/2; | 0 | ||||||||||||||||||||||||
465 | else | - | ||||||||||||||||||||||||
466 | x = x - w/2; never executed: x = x - w/2; | 0 | ||||||||||||||||||||||||
467 | - | |||||||||||||||||||||||||
468 | - | |||||||||||||||||||||||||
469 | - | |||||||||||||||||||||||||
470 | if (x + w + shadowWidth > sx+screen.width()
| 0 | ||||||||||||||||||||||||
471 | x = (widget
never executed: x = (widget? (qMin(screen.width(), pos.x() + widget->width()) ) : screen.width()) - w; | 0 | ||||||||||||||||||||||||
472 | pos.x() + widget->width()) never executed: x = (widget? (qMin(screen.width(), pos.x() + widget->width()) ) : screen.width()) - w; | 0 | ||||||||||||||||||||||||
473 | ) : screen.width()) never executed: x = (widget? (qMin(screen.width(), pos.x() + widget->width()) ) : screen.width()) - w; | 0 | ||||||||||||||||||||||||
474 | - w; never executed: x = (widget? (qMin(screen.width(), pos.x() + widget->width()) ) : screen.width()) - w; | 0 | ||||||||||||||||||||||||
475 | - | |||||||||||||||||||||||||
476 | if (x < sx
| 0 | ||||||||||||||||||||||||
477 | x = sx; never executed: x = sx; | 0 | ||||||||||||||||||||||||
478 | - | |||||||||||||||||||||||||
479 | if (widget
| 0 | ||||||||||||||||||||||||
480 | y = pos.y() + widget->height() + 2; | - | ||||||||||||||||||||||||
481 | - | |||||||||||||||||||||||||
482 | if (y + h + 10 > sy+screen.height()
| 0 | ||||||||||||||||||||||||
483 | y = pos.y() + 2 - shadowWidth - h; never executed: y = pos.y() + 2 - shadowWidth - h; | 0 | ||||||||||||||||||||||||
484 | } never executed: end of block | 0 | ||||||||||||||||||||||||
485 | y = y + 2; | - | ||||||||||||||||||||||||
486 | - | |||||||||||||||||||||||||
487 | - | |||||||||||||||||||||||||
488 | - | |||||||||||||||||||||||||
489 | if (y + h + shadowWidth > sy+screen.height()
| 0 | ||||||||||||||||||||||||
490 | y = (widget
never executed: y = (widget ? (qMin(screen.height(), pos.y() + widget->height()) ) : screen.height()) - h; | 0 | ||||||||||||||||||||||||
491 | pos.y() + widget->height()) never executed: y = (widget ? (qMin(screen.height(), pos.y() + widget->height()) ) : screen.height()) - h; | 0 | ||||||||||||||||||||||||
492 | ) : screen.height()) never executed: y = (widget ? (qMin(screen.height(), pos.y() + widget->height()) ) : screen.height()) - h; | 0 | ||||||||||||||||||||||||
493 | - h; never executed: y = (widget ? (qMin(screen.height(), pos.y() + widget->height()) ) : screen.height()) - h; | 0 | ||||||||||||||||||||||||
494 | if (y < sy
| 0 | ||||||||||||||||||||||||
495 | y = sy; never executed: y = sy; | 0 | ||||||||||||||||||||||||
496 | - | |||||||||||||||||||||||||
497 | whatsThat->move(x, y); | - | ||||||||||||||||||||||||
498 | whatsThat->show(); | - | ||||||||||||||||||||||||
499 | whatsThat->grabKeyboard(); | - | ||||||||||||||||||||||||
500 | } never executed: end of block | 0 | ||||||||||||||||||||||||
501 | void QWhatsThis::showText(const QPoint &pos, const QString &text, QWidget *w) | - | ||||||||||||||||||||||||
502 | { | - | ||||||||||||||||||||||||
503 | leaveWhatsThisMode(); | - | ||||||||||||||||||||||||
504 | QWhatsThisPrivate::say(w, text, pos.x(), pos.y()); | - | ||||||||||||||||||||||||
505 | } never executed: end of block | 0 | ||||||||||||||||||||||||
506 | - | |||||||||||||||||||||||||
507 | - | |||||||||||||||||||||||||
508 | - | |||||||||||||||||||||||||
509 | - | |||||||||||||||||||||||||
510 | - | |||||||||||||||||||||||||
511 | - | |||||||||||||||||||||||||
512 | void QWhatsThis::hideText() | - | ||||||||||||||||||||||||
513 | { | - | ||||||||||||||||||||||||
514 | qDeleteInEventHandler(QWhatsThat::instance); | - | ||||||||||||||||||||||||
515 | } never executed: end of block | 0 | ||||||||||||||||||||||||
516 | QAction *QWhatsThis::createAction(QObject *parent) | - | ||||||||||||||||||||||||
517 | { | - | ||||||||||||||||||||||||
518 | return never executed: new QWhatsThisAction(parent);return new QWhatsThisAction(parent); never executed: return new QWhatsThisAction(parent); | 0 | ||||||||||||||||||||||||
519 | } | - | ||||||||||||||||||||||||
520 | - | |||||||||||||||||||||||||
521 | - | |||||||||||||||||||||||||
522 | - | |||||||||||||||||||||||||
Switch to Source code | Preprocessed file |