| 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 | const QWidgetList toplevels = QApplication::topLevelWidgets(); | - | ||||||||||||||||||||||||
| 253 | for (auto *w : toplevels) | - | ||||||||||||||||||||||||
| 254 | QApplication::sendEvent(w, e); never executed: QApplication::sendEvent(w, e); | 0 | ||||||||||||||||||||||||
| 255 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 256 | - | |||||||||||||||||||||||||
| 257 | QWhatsThisPrivate *QWhatsThisPrivate::instance = 0; | - | ||||||||||||||||||||||||
| 258 | - | |||||||||||||||||||||||||
| 259 | QWhatsThisPrivate::QWhatsThisPrivate() | - | ||||||||||||||||||||||||
| 260 | : leaveOnMouseRelease(false) | - | ||||||||||||||||||||||||
| 261 | { | - | ||||||||||||||||||||||||
| 262 | instance = this; | - | ||||||||||||||||||||||||
| 263 | (static_cast<QApplication *>(QCoreApplication::instance()))->installEventFilter(this); | - | ||||||||||||||||||||||||
| 264 | - | |||||||||||||||||||||||||
| 265 | QPoint pos = QCursor::pos(); | - | ||||||||||||||||||||||||
| 266 | if (QWidget *w = QApplication::widgetAt(pos)
| 0 | ||||||||||||||||||||||||
| 267 | QHelpEvent e(QEvent::QueryWhatsThis, w->mapFromGlobal(pos), pos); | - | ||||||||||||||||||||||||
| 268 | bool sentEvent = QApplication::sendEvent(w, &e); | - | ||||||||||||||||||||||||
| 269 | - | |||||||||||||||||||||||||
| 270 | - | |||||||||||||||||||||||||
| 271 | - | |||||||||||||||||||||||||
| 272 | QApplication::setOverrideCursor((!sentEvent || !e.isAccepted())? | - | ||||||||||||||||||||||||
| 273 | Qt::ForbiddenCursor:Qt::WhatsThisCursor); | - | ||||||||||||||||||||||||
| 274 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 275 | QApplication::setOverrideCursor(Qt::WhatsThisCursor); | - | ||||||||||||||||||||||||
| 276 | - | |||||||||||||||||||||||||
| 277 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 278 | - | |||||||||||||||||||||||||
| 279 | QAccessibleEvent event(this, QAccessible::ContextHelpStart); | - | ||||||||||||||||||||||||
| 280 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||||||||
| 281 | - | |||||||||||||||||||||||||
| 282 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 283 | - | |||||||||||||||||||||||||
| 284 | QWhatsThisPrivate::~QWhatsThisPrivate() | - | ||||||||||||||||||||||||
| 285 | { | - | ||||||||||||||||||||||||
| 286 | if (action
| 0 | ||||||||||||||||||||||||
| 287 | action->setChecked(false); never executed: action->setChecked(false); | 0 | ||||||||||||||||||||||||
| 288 | - | |||||||||||||||||||||||||
| 289 | QApplication::restoreOverrideCursor(); | - | ||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||
| 291 | - | |||||||||||||||||||||||||
| 292 | QAccessibleEvent event(this, QAccessible::ContextHelpEnd); | - | ||||||||||||||||||||||||
| 293 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||||||||
| 294 | - | |||||||||||||||||||||||||
| 295 | instance = 0; | - | ||||||||||||||||||||||||
| 296 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 297 | - | |||||||||||||||||||||||||
| 298 | bool QWhatsThisPrivate::eventFilter(QObject *o, QEvent *e) | - | ||||||||||||||||||||||||
| 299 | { | - | ||||||||||||||||||||||||
| 300 | if (!o->isWidgetType()
| 0 | ||||||||||||||||||||||||
| 301 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 302 | QWidget * w = static_cast<QWidget *>(o); | - | ||||||||||||||||||||||||
| 303 | bool customWhatsThis = w->testAttribute(Qt::WA_CustomWhatsThis); | - | ||||||||||||||||||||||||
| 304 | switch (e->type()) { | - | ||||||||||||||||||||||||
| 305 | case never executed: QEvent::MouseButtonPress:case QEvent::MouseButtonPress:never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||||||||
| 306 | { | - | ||||||||||||||||||||||||
| 307 | QMouseEvent *me = static_cast<QMouseEvent*>(e); | - | ||||||||||||||||||||||||
| 308 | if (me->button() == Qt::RightButton
| 0 | ||||||||||||||||||||||||
| 309 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 310 | QHelpEvent e(QEvent::WhatsThis, me->pos(), me->globalPos()); | - | ||||||||||||||||||||||||
| 311 | if (!QApplication::sendEvent(w, &e)
| 0 | ||||||||||||||||||||||||
| 312 | leaveOnMouseRelease = true; never executed: leaveOnMouseRelease = true; | 0 | ||||||||||||||||||||||||
| 313 | - | |||||||||||||||||||||||||
| 314 | } break; never executed: break; | 0 | ||||||||||||||||||||||||
| 315 | - | |||||||||||||||||||||||||
| 316 | case never executed: QEvent::MouseMove:case QEvent::MouseMove:never executed: case QEvent::MouseMove: | 0 | ||||||||||||||||||||||||
| 317 | { | - | ||||||||||||||||||||||||
| 318 | QMouseEvent *me = static_cast<QMouseEvent*>(e); | - | ||||||||||||||||||||||||
| 319 | QHelpEvent e(QEvent::QueryWhatsThis, me->pos(), me->globalPos()); | - | ||||||||||||||||||||||||
| 320 | bool sentEvent = QApplication::sendEvent(w, &e); | - | ||||||||||||||||||||||||
| 321 | - | |||||||||||||||||||||||||
| 322 | - | |||||||||||||||||||||||||
| 323 | - | |||||||||||||||||||||||||
| 324 | QApplication::changeOverrideCursor((!sentEvent || !e.isAccepted())? | - | ||||||||||||||||||||||||
| 325 | Qt::ForbiddenCursor:Qt::WhatsThisCursor); | - | ||||||||||||||||||||||||
| 326 | - | |||||||||||||||||||||||||
| 327 | } | - | ||||||||||||||||||||||||
| 328 | - | |||||||||||||||||||||||||
| 329 | case never executed: QEvent::MouseButtonRelease:case QEvent::MouseButtonRelease:never executed: case QEvent::MouseButtonRelease:code before this statement never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||||||||
| 330 | case never executed: QEvent::MouseButtonDblClick:case QEvent::MouseButtonDblClick:never executed: case QEvent::MouseButtonDblClick: | 0 | ||||||||||||||||||||||||
| 331 | if (leaveOnMouseRelease
| 0 | ||||||||||||||||||||||||
| 332 | QWhatsThis::leaveWhatsThisMode(); never executed: QWhatsThis::leaveWhatsThisMode(); | 0 | ||||||||||||||||||||||||
| 333 | if (static_cast<
| 0 | ||||||||||||||||||||||||
| 334 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 335 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 336 | case never executed: QEvent::KeyPress:case QEvent::KeyPress:never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||||||||
| 337 | { | - | ||||||||||||||||||||||||
| 338 | QKeyEvent* kev = (QKeyEvent*)e; | - | ||||||||||||||||||||||||
| 339 | - | |||||||||||||||||||||||||
| 340 | if (kev->matches(QKeySequence::Cancel)
| 0 | ||||||||||||||||||||||||
| 341 | QWhatsThis::leaveWhatsThisMode(); | - | ||||||||||||||||||||||||
| 342 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||
| 343 | } else if (customWhatsThis
| 0 | ||||||||||||||||||||||||
| 344 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 345 | } else if (kev->key() == Qt::Key_Menu
| 0 | ||||||||||||||||||||||||
| 346 | (kev->key() == Qt::Key_F10
| 0 | ||||||||||||||||||||||||
| 347 | kev->modifiers() == Qt::ShiftModifier
| 0 | ||||||||||||||||||||||||
| 348 | - | |||||||||||||||||||||||||
| 349 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 350 | } else if (kev->key() != Qt::Key_Shift
| 0 | ||||||||||||||||||||||||
| 351 | && kev->key() != Qt::Key_Control
| 0 | ||||||||||||||||||||||||
| 352 | QWhatsThis::leaveWhatsThisMode(); | - | ||||||||||||||||||||||||
| 353 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 354 | } break; never executed: break; | 0 | ||||||||||||||||||||||||
| 355 | default never executed: :default:never executed: default: | 0 | ||||||||||||||||||||||||
| 356 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 357 | } | - | ||||||||||||||||||||||||
| 358 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||
| 359 | } | - | ||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||
| 361 | class QWhatsThisAction: public QAction | - | ||||||||||||||||||||||||
| 362 | { | - | ||||||||||||||||||||||||
| 363 | 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; } | - | ||||||||||||||||||||||||
| 364 | #pragma GCC diagnostic push | - | ||||||||||||||||||||||||
| 365 | 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 **); | - | ||||||||||||||||||||||||
| 366 | #pragma GCC diagnostic pop | - | ||||||||||||||||||||||||
| 367 | struct QPrivateSignal {}; | - | ||||||||||||||||||||||||
| 368 | - | |||||||||||||||||||||||||
| 369 | public: | - | ||||||||||||||||||||||||
| 370 | explicit QWhatsThisAction(QObject* parent = 0); | - | ||||||||||||||||||||||||
| 371 | - | |||||||||||||||||||||||||
| 372 | private : | - | ||||||||||||||||||||||||
| 373 | void actionTriggered(); | - | ||||||||||||||||||||||||
| 374 | }; | - | ||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||
| 376 | QWhatsThisAction::QWhatsThisAction(QObject *parent) : QAction(tr("What's This?"), parent) | - | ||||||||||||||||||||||||
| 377 | { | - | ||||||||||||||||||||||||
| 378 | - | |||||||||||||||||||||||||
| 379 | QPixmap p(button_image); | - | ||||||||||||||||||||||||
| 380 | setIcon(p); | - | ||||||||||||||||||||||||
| 381 | - | |||||||||||||||||||||||||
| 382 | setCheckable(true); | - | ||||||||||||||||||||||||
| 383 | connect(this, qFlagLocation("2""triggered()" "\0" __FILE__ ":" "505"), this, qFlagLocation("1""actionTriggered()" "\0" __FILE__ ":" "505")); | - | ||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||
| 385 | setShortcut(Qt::ShiftModifier + Qt::Key_F1); | - | ||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 388 | - | |||||||||||||||||||||||||
| 389 | void QWhatsThisAction::actionTriggered() | - | ||||||||||||||||||||||||
| 390 | { | - | ||||||||||||||||||||||||
| 391 | if (isChecked()
| 0 | ||||||||||||||||||||||||
| 392 | QWhatsThis::enterWhatsThisMode(); | - | ||||||||||||||||||||||||
| 393 | QWhatsThisPrivate::instance->action = this; | - | ||||||||||||||||||||||||
| 394 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 395 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 396 | void QWhatsThis::enterWhatsThisMode() | - | ||||||||||||||||||||||||
| 397 | { | - | ||||||||||||||||||||||||
| 398 | if (QWhatsThisPrivate::instance
| 0 | ||||||||||||||||||||||||
| 399 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 400 | (void) new QWhatsThisPrivate; | - | ||||||||||||||||||||||||
| 401 | QEvent e(QEvent::EnterWhatsThisMode); | - | ||||||||||||||||||||||||
| 402 | QWhatsThisPrivate::notifyToplevels(&e); | - | ||||||||||||||||||||||||
| 403 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 404 | - | |||||||||||||||||||||||||
| 405 | - | |||||||||||||||||||||||||
| 406 | - | |||||||||||||||||||||||||
| 407 | - | |||||||||||||||||||||||||
| 408 | - | |||||||||||||||||||||||||
| 409 | - | |||||||||||||||||||||||||
| 410 | - | |||||||||||||||||||||||||
| 411 | bool QWhatsThis::inWhatsThisMode() | - | ||||||||||||||||||||||||
| 412 | { | - | ||||||||||||||||||||||||
| 413 | return never executed: (QWhatsThisPrivate::instance != 0);return (QWhatsThisPrivate::instance != 0);never executed: return (QWhatsThisPrivate::instance != 0); | 0 | ||||||||||||||||||||||||
| 414 | } | - | ||||||||||||||||||||||||
| 415 | void QWhatsThis::leaveWhatsThisMode() | - | ||||||||||||||||||||||||
| 416 | { | - | ||||||||||||||||||||||||
| 417 | delete QWhatsThisPrivate::instance; | - | ||||||||||||||||||||||||
| 418 | QEvent e(QEvent::LeaveWhatsThisMode); | - | ||||||||||||||||||||||||
| 419 | QWhatsThisPrivate::notifyToplevels(&e); | - | ||||||||||||||||||||||||
| 420 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 421 | - | |||||||||||||||||||||||||
| 422 | void QWhatsThisPrivate::say(QWidget * widget, const QString &text, int x, int y) | - | ||||||||||||||||||||||||
| 423 | { | - | ||||||||||||||||||||||||
| 424 | if (text.size() == 0
| 0 | ||||||||||||||||||||||||
| 425 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 426 | - | |||||||||||||||||||||||||
| 427 | QWhatsThat *whatsThat = new QWhatsThat( | - | ||||||||||||||||||||||||
| 428 | text, | - | ||||||||||||||||||||||||
| 429 | - | |||||||||||||||||||||||||
| 430 | - | |||||||||||||||||||||||||
| 431 | - | |||||||||||||||||||||||||
| 432 | 0, | - | ||||||||||||||||||||||||
| 433 | - | |||||||||||||||||||||||||
| 434 | widget | - | ||||||||||||||||||||||||
| 435 | ); | - | ||||||||||||||||||||||||
| 436 | - | |||||||||||||||||||||||||
| 437 | - | |||||||||||||||||||||||||
| 438 | - | |||||||||||||||||||||||||
| 439 | - | |||||||||||||||||||||||||
| 440 | int scr = (widget
| 0 | ||||||||||||||||||||||||
| 441 | QApplication::desktop()->screenNumber(widget) : | - | ||||||||||||||||||||||||
| 442 | - | |||||||||||||||||||||||||
| 443 | - | |||||||||||||||||||||||||
| 444 | - | |||||||||||||||||||||||||
| 445 | QApplication::desktop()->screenNumber(QPoint(x,y)) | - | ||||||||||||||||||||||||
| 446 | - | |||||||||||||||||||||||||
| 447 | ); | - | ||||||||||||||||||||||||
| 448 | QRect screen = QApplication::desktop()->screenGeometry(scr); | - | ||||||||||||||||||||||||
| 449 | - | |||||||||||||||||||||||||
| 450 | int w = whatsThat->width(); | - | ||||||||||||||||||||||||
| 451 | int h = whatsThat->height(); | - | ||||||||||||||||||||||||
| 452 | int sx = screen.x(); | - | ||||||||||||||||||||||||
| 453 | int sy = screen.y(); | - | ||||||||||||||||||||||||
| 454 | - | |||||||||||||||||||||||||
| 455 | - | |||||||||||||||||||||||||
| 456 | - | |||||||||||||||||||||||||
| 457 | QPoint pos; | - | ||||||||||||||||||||||||
| 458 | if (widget
| 0 | ||||||||||||||||||||||||
| 459 | pos = widget->mapToGlobal(QPoint(0,0)); never executed: pos = widget->mapToGlobal(QPoint(0,0)); | 0 | ||||||||||||||||||||||||
| 460 | - | |||||||||||||||||||||||||
| 461 | if (widget
| 0 | ||||||||||||||||||||||||
| 462 | x = pos.x() + widget->width()/2 - w/2; never executed: x = pos.x() + widget->width()/2 - w/2; | 0 | ||||||||||||||||||||||||
| 463 | else | - | ||||||||||||||||||||||||
| 464 | x = x - w/2; never executed: x = x - w/2; | 0 | ||||||||||||||||||||||||
| 465 | - | |||||||||||||||||||||||||
| 466 | - | |||||||||||||||||||||||||
| 467 | - | |||||||||||||||||||||||||
| 468 | if (x + w + shadowWidth > sx+screen.width()
| 0 | ||||||||||||||||||||||||
| 469 | x = (widget
never executed: x = (widget? (qMin(screen.width(), pos.x() + widget->width()) ) : screen.width()) - w; | 0 | ||||||||||||||||||||||||
| 470 | pos.x() + widget->width()) never executed: x = (widget? (qMin(screen.width(), pos.x() + widget->width()) ) : screen.width()) - w; | 0 | ||||||||||||||||||||||||
| 471 | ) : screen.width()) never executed: x = (widget? (qMin(screen.width(), pos.x() + widget->width()) ) : screen.width()) - w; | 0 | ||||||||||||||||||||||||
| 472 | - w; never executed: x = (widget? (qMin(screen.width(), pos.x() + widget->width()) ) : screen.width()) - w; | 0 | ||||||||||||||||||||||||
| 473 | - | |||||||||||||||||||||||||
| 474 | if (x < sx
| 0 | ||||||||||||||||||||||||
| 475 | x = sx; never executed: x = sx; | 0 | ||||||||||||||||||||||||
| 476 | - | |||||||||||||||||||||||||
| 477 | if (widget
| 0 | ||||||||||||||||||||||||
| 478 | y = pos.y() + widget->height() + 2; | - | ||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||
| 480 | if (y + h + 10 > sy+screen.height()
| 0 | ||||||||||||||||||||||||
| 481 | y = pos.y() + 2 - shadowWidth - h; never executed: y = pos.y() + 2 - shadowWidth - h; | 0 | ||||||||||||||||||||||||
| 482 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 483 | y = y + 2; | - | ||||||||||||||||||||||||
| 484 | - | |||||||||||||||||||||||||
| 485 | - | |||||||||||||||||||||||||
| 486 | - | |||||||||||||||||||||||||
| 487 | if (y + h + shadowWidth > sy+screen.height()
| 0 | ||||||||||||||||||||||||
| 488 | y = (widget
never executed: y = (widget ? (qMin(screen.height(), pos.y() + widget->height()) ) : screen.height()) - h; | 0 | ||||||||||||||||||||||||
| 489 | pos.y() + widget->height()) never executed: y = (widget ? (qMin(screen.height(), pos.y() + widget->height()) ) : screen.height()) - h; | 0 | ||||||||||||||||||||||||
| 490 | ) : screen.height()) never executed: y = (widget ? (qMin(screen.height(), pos.y() + widget->height()) ) : screen.height()) - h; | 0 | ||||||||||||||||||||||||
| 491 | - h; never executed: y = (widget ? (qMin(screen.height(), pos.y() + widget->height()) ) : screen.height()) - h; | 0 | ||||||||||||||||||||||||
| 492 | if (y < sy
| 0 | ||||||||||||||||||||||||
| 493 | y = sy; never executed: y = sy; | 0 | ||||||||||||||||||||||||
| 494 | - | |||||||||||||||||||||||||
| 495 | whatsThat->move(x, y); | - | ||||||||||||||||||||||||
| 496 | whatsThat->show(); | - | ||||||||||||||||||||||||
| 497 | whatsThat->grabKeyboard(); | - | ||||||||||||||||||||||||
| 498 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 499 | void QWhatsThis::showText(const QPoint &pos, const QString &text, QWidget *w) | - | ||||||||||||||||||||||||
| 500 | { | - | ||||||||||||||||||||||||
| 501 | leaveWhatsThisMode(); | - | ||||||||||||||||||||||||
| 502 | QWhatsThisPrivate::say(w, text, pos.x(), pos.y()); | - | ||||||||||||||||||||||||
| 503 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 504 | - | |||||||||||||||||||||||||
| 505 | - | |||||||||||||||||||||||||
| 506 | - | |||||||||||||||||||||||||
| 507 | - | |||||||||||||||||||||||||
| 508 | - | |||||||||||||||||||||||||
| 509 | - | |||||||||||||||||||||||||
| 510 | void QWhatsThis::hideText() | - | ||||||||||||||||||||||||
| 511 | { | - | ||||||||||||||||||||||||
| 512 | qDeleteInEventHandler(QWhatsThat::instance); | - | ||||||||||||||||||||||||
| 513 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 514 | QAction *QWhatsThis::createAction(QObject *parent) | - | ||||||||||||||||||||||||
| 515 | { | - | ||||||||||||||||||||||||
| 516 | return never executed: new QWhatsThisAction(parent);return new QWhatsThisAction(parent);never executed: return new QWhatsThisAction(parent); | 0 | ||||||||||||||||||||||||
| 517 | } | - | ||||||||||||||||||||||||
| 518 | - | |||||||||||||||||||||||||
| 519 | - | |||||||||||||||||||||||||
| 520 | - | |||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |