| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | #include "qwhatsthis.h" | - |
| 41 | #ifndef QT_NO_WHATSTHIS | - |
| 42 | #include "qpointer.h" | - |
| 43 | #include "qapplication.h" | - |
| 44 | #include <private/qguiapplication_p.h> | - |
| 45 | #include "qdesktopwidget.h" | - |
| 46 | #include "qevent.h" | - |
| 47 | #include "qpixmap.h" | - |
| 48 | #include "qscreen.h" | - |
| 49 | #include "qpainter.h" | - |
| 50 | #include "qtimer.h" | - |
| 51 | #include "qaction.h" | - |
| 52 | #include "qcursor.h" | - |
| 53 | #include "qbitmap.h" | - |
| 54 | #include "qtextdocument.h" | - |
| 55 | #include <qpa/qplatformtheme.h> | - |
| 56 | #include "private/qtextdocumentlayout_p.h" | - |
| 57 | #include "qtoolbutton.h" | - |
| 58 | #include "qdebug.h" | - |
| 59 | #ifndef QT_NO_ACCESSIBILITY | - |
| 60 | #include "qaccessible.h" | - |
| 61 | #endif | - |
| 62 | | - |
| 63 | QT_BEGIN_NAMESPACE | - |
| 64 | | - |
| 65 | | - |
| 66 | | - |
| 67 | | - |
| 68 | | - |
| 69 | | - |
| 70 | | - |
| 71 | | - |
| 72 | | - |
| 73 | | - |
| 74 | | - |
| 75 | | - |
| 76 | | - |
| 77 | | - |
| 78 | | - |
| 79 | | - |
| 80 | | - |
| 81 | | - |
| 82 | | - |
| 83 | | - |
| 84 | | - |
| 85 | | - |
| 86 | | - |
| 87 | | - |
| 88 | | - |
| 89 | | - |
| 90 | | - |
| 91 | | - |
| 92 | | - |
| 93 | | - |
| 94 | | - |
| 95 | | - |
| 96 | | - |
| 97 | | - |
| 98 | | - |
| 99 | | - |
| 100 | | - |
| 101 | | - |
| 102 | | - |
| 103 | | - |
| 104 | | - |
| 105 | | - |
| 106 | | - |
| 107 | | - |
| 108 | | - |
| 109 | | - |
| 110 | | - |
| 111 | | - |
| 112 | | - |
| 113 | | - |
| 114 | | - |
| 115 | | - |
| 116 | | - |
| 117 | | - |
| 118 | | - |
| 119 | | - |
| 120 | | - |
| 121 | | - |
| 122 | | - |
| 123 | | - |
| 124 | | - |
| 125 | | - |
| 126 | | - |
| 127 | | - |
| 128 | | - |
| 129 | | - |
| 130 | | - |
| 131 | | - |
| 132 | | - |
| 133 | | - |
| 134 | | - |
| 135 | | - |
| 136 | Q_CORE_EXPORT void qDeleteInEventHandler(QObject *o); | - |
| 137 | | - |
| 138 | class QWhatsThat : public QWidget | - |
| 139 | { | - |
| 140 | Q_OBJECT | - |
| 141 | | - |
| 142 | public: | - |
| 143 | QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor); | - |
| 144 | ~QWhatsThat() ; | - |
| 145 | | - |
| 146 | static QWhatsThat *instance; | - |
| 147 | | - |
| 148 | protected: | - |
| 149 | void showEvent(QShowEvent *e) Q_DECL_OVERRIDE; | - |
| 150 | void mousePressEvent(QMouseEvent*) Q_DECL_OVERRIDE; | - |
| 151 | void mouseReleaseEvent(QMouseEvent*) Q_DECL_OVERRIDE; | - |
| 152 | void mouseMoveEvent(QMouseEvent*) Q_DECL_OVERRIDE; | - |
| 153 | void keyPressEvent(QKeyEvent*) Q_DECL_OVERRIDE; | - |
| 154 | void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE; | - |
| 155 | | - |
| 156 | private: | - |
| 157 | QPointer<QWidget>widget; | - |
| 158 | bool pressed; | - |
| 159 | QString text; | - |
| 160 | QTextDocument* doc; | - |
| 161 | QString anchor; | - |
| 162 | QPixmap background; | - |
| 163 | }; | - |
| 164 | | - |
| 165 | QWhatsThat *QWhatsThat::instance = 0; | - |
| 166 | | - |
| 167 | | - |
| 168 | static int shadowWidth = 6; | - |
| 169 | static const int vMargin = 8; | - |
| 170 | static const int hMargin = 12; | - |
| 171 | | - |
| 172 | static inline bool dropShadow() | - |
| 173 | { | - |
| 174 | if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) | - |
| 175 | return theme->themeHint(QPlatformTheme::DropShadow).toBool(); | - |
| 176 | return false; | - |
| 177 | } | - |
| 178 | | - |
| 179 | QWhatsThat::QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor) | - |
| 180 | : QWidget(parent, Qt::Popup), | - |
| 181 | widget(showTextFor), pressed(false), text(txt) | - |
| 182 | { | - |
| 183 | delete instance; | - |
| 184 | instance = this; | - |
| 185 | setAttribute(Qt::WA_DeleteOnClose, true); | - |
| 186 | setAttribute(Qt::WA_NoSystemBackground, true); | - |
| 187 | if (parent) | - |
| 188 | setPalette(parent->palette()); | - |
| 189 | setMouseTracking(true); | - |
| 190 | setFocusPolicy(Qt::StrongFocus); | - |
| 191 | #ifndef QT_NO_CURSOR | - |
| 192 | setCursor(Qt::ArrowCursor); | - |
| 193 | #endif | - |
| 194 | QRect r; | - |
| 195 | doc = 0; | - |
| 196 | ensurePolished(); | - |
| 197 | if (Qt::mightBeRichText(text)) { | - |
| 198 | doc = new QTextDocument(); | - |
| 199 | doc->setUndoRedoEnabled(false); | - |
| 200 | doc->setDefaultFont(QApplication::font(this)); | - |
| 201 | #ifdef QT_NO_TEXTHTMLPARSER | - |
| 202 | doc->setPlainText(text); | - |
| 203 | #else | - |
| 204 | doc->setHtml(text); | - |
| 205 | #endif | - |
| 206 | doc->setUndoRedoEnabled(false); | - |
| 207 | doc->adjustSize(); | - |
| 208 | r.setTop(0); | - |
| 209 | r.setLeft(0); | - |
| 210 | r.setSize(doc->size().toSize()); | - |
| 211 | } | - |
| 212 | else | - |
| 213 | { | - |
| 214 | int sw = QApplication::desktop()->width() / 3; | - |
| 215 | if (sw < 200) | - |
| 216 | sw = 200; | - |
| 217 | else if (sw > 300) | - |
| 218 | sw = 300; | - |
| 219 | | - |
| 220 | r = fontMetrics().boundingRect(0, 0, sw, 1000, | - |
| 221 | Qt::AlignLeft + Qt::AlignTop | - |
| 222 | + Qt::TextWordWrap + Qt::TextExpandTabs, | - |
| 223 | text); | - |
| 224 | } | - |
| 225 | shadowWidth = dropShadow() ? 0 : 6; | - |
| 226 | resize(r.width() + 2*hMargin + shadowWidth, r.height() + 2*vMargin + shadowWidth); | - |
| 227 | } | - |
| 228 | | - |
| 229 | QWhatsThat::~QWhatsThat() | - |
| 230 | { | - |
| 231 | instance = 0; | - |
| 232 | if (doc) | - |
| 233 | delete doc; | - |
| 234 | } | - |
| 235 | | - |
| 236 | void QWhatsThat::showEvent(QShowEvent *) | - |
| 237 | { | - |
| 238 | background = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->internalWinId(), | - |
| 239 | x(), y(), width(), height()); | - |
| 240 | } | - |
| 241 | | - |
| 242 | void QWhatsThat::mousePressEvent(QMouseEvent* e) | - |
| 243 | { | - |
| 244 | pressed = true; | - |
| 245 | if (e->button() == Qt::LeftButton && rect().contains(e->pos())) { | - |
| 246 | if (doc) | - |
| 247 | anchor = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); | - |
| 248 | return; | - |
| 249 | } | - |
| 250 | close(); | - |
| 251 | } | - |
| 252 | | - |
| 253 | void QWhatsThat::mouseReleaseEvent(QMouseEvent* e) | - |
| 254 | { | - |
| 255 | if (!pressed) | - |
| 256 | return; | - |
| 257 | if (widget && e->button() == Qt::LeftButton && doc && rect().contains(e->pos())) { | - |
| 258 | QString a = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); | - |
| 259 | QString href; | - |
| 260 | if (anchor == a) | - |
| 261 | href = a; | - |
| 262 | anchor.clear(); | - |
| 263 | if (!href.isEmpty()) { | - |
| 264 | QWhatsThisClickedEvent e(href); | - |
| 265 | if (QApplication::sendEvent(widget, &e)) | - |
| 266 | return; | - |
| 267 | } | - |
| 268 | } | - |
| 269 | close(); | - |
| 270 | } | - |
| 271 | | - |
| 272 | void QWhatsThat::mouseMoveEvent(QMouseEvent* e) | - |
| 273 | { | - |
| 274 | #ifdef QT_NO_CURSOR | - |
| 275 | Q_UNUSED(e); | - |
| 276 | #else | - |
| 277 | if (!doc) | - |
| 278 | return; | - |
| 279 | QString a = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); | - |
| 280 | if (!a.isEmpty()) | - |
| 281 | setCursor(Qt::PointingHandCursor); | - |
| 282 | else | - |
| 283 | setCursor(Qt::ArrowCursor); | - |
| 284 | #endif | - |
| 285 | } | - |
| 286 | | - |
| 287 | void QWhatsThat::keyPressEvent(QKeyEvent*) | - |
| 288 | { | - |
| 289 | close(); | - |
| 290 | } | - |
| 291 | | - |
| 292 | void QWhatsThat::paintEvent(QPaintEvent*) | - |
| 293 | { | - |
| 294 | const bool drawShadow = dropShadow(); | - |
| 295 | | - |
| 296 | QRect r = rect(); | - |
| 297 | r.adjust(0, 0, -1, -1); | - |
| 298 | if (drawShadow) | - |
| 299 | r.adjust(0, 0, -shadowWidth, -shadowWidth); | - |
| 300 | QPainter p(this); | - |
| 301 | p.drawPixmap(0, 0, background); | - |
| 302 | p.setPen(QPen(palette().toolTipText(), 0)); | - |
| 303 | p.setBrush(palette().toolTipBase()); | - |
| 304 | p.drawRect(r); | - |
| 305 | int w = r.width(); | - |
| 306 | int h = r.height(); | - |
| 307 | p.setPen(palette().brush(QPalette::Dark).color()); | - |
| 308 | p.drawRect(1, 1, w-2, h-2); | - |
| 309 | if (drawShadow) { | - |
| 310 | p.setPen(palette().shadow().color()); | - |
| 311 | p.drawPoint(w + 5, 6); | - |
| 312 | p.drawLine(w + 3, 6, w + 5, 8); | - |
| 313 | p.drawLine(w + 1, 6, w + 5, 10); | - |
| 314 | int i; | - |
| 315 | for(i=7; i < h; i += 2) | - |
| 316 | p.drawLine(w, i, w + 5, i + 5); | - |
| 317 | for(i = w - i + h; i > 6; i -= 2) | - |
| 318 | p.drawLine(i, h, i + 5, h + 5); | - |
| 319 | for(; i > 0 ; i -= 2) | - |
| 320 | p.drawLine(6, h + 6 - i, i + 5, h + 5); | - |
| 321 | } | - |
| 322 | r.adjust(0, 0, 1, 1); | - |
| 323 | p.setPen(palette().toolTipText().color()); | - |
| 324 | r.adjust(hMargin, vMargin, -hMargin, -vMargin); | - |
| 325 | | - |
| 326 | if (doc) { | - |
| 327 | p.translate(r.x(), r.y()); | - |
| 328 | QRect rect = r; | - |
| 329 | rect.translate(-r.x(), -r.y()); | - |
| 330 | p.setClipRect(rect); | - |
| 331 | QAbstractTextDocumentLayout::PaintContext context; | - |
| 332 | context.palette.setBrush(QPalette::Text, context.palette.toolTipText()); | - |
| 333 | doc->documentLayout()->draw(&p, context); | - |
| 334 | } | - |
| 335 | else | - |
| 336 | { | - |
| 337 | p.drawText(r, Qt::AlignLeft + Qt::AlignTop + Qt::TextWordWrap + Qt::TextExpandTabs, text); | - |
| 338 | } | - |
| 339 | } | - |
| 340 | | - |
| 341 | static const char * const button_image[] = { | - |
| 342 | "16 16 3 1", | - |
| 343 | " c None", | - |
| 344 | "o c #000000", | - |
| 345 | "a c #000080", | - |
| 346 | "o aaaaa ", | - |
| 347 | "oo aaa aaa ", | - |
| 348 | "ooo aaa aaa", | - |
| 349 | "oooo aa aa", | - |
| 350 | "ooooo aa aa", | - |
| 351 | "oooooo a aaa", | - |
| 352 | "ooooooo aaa ", | - |
| 353 | "oooooooo aaa ", | - |
| 354 | "ooooooooo aaa ", | - |
| 355 | "ooooo aaa ", | - |
| 356 | "oo ooo ", | - |
| 357 | "o ooo aaa ", | - |
| 358 | " ooo aaa ", | - |
| 359 | " ooo ", | - |
| 360 | " ooo ", | - |
| 361 | " ooo "}; | - |
| 362 | | - |
| 363 | class QWhatsThisPrivate : public QObject | - |
| 364 | { | - |
| 365 | public: | - |
| 366 | QWhatsThisPrivate(); | - |
| 367 | ~QWhatsThisPrivate(); | - |
| 368 | static QWhatsThisPrivate *instance; | - |
| 369 | bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE; | - |
| 370 | QPointer<QAction> action; | - |
| 371 | static void say(QWidget *, const QString &, int x = 0, int y = 0); | - |
| 372 | static void notifyToplevels(QEvent *e); | - |
| 373 | bool leaveOnMouseRelease; | - |
| 374 | }; | - |
| 375 | | - |
| 376 | void QWhatsThisPrivate::notifyToplevels(QEvent *e) | - |
| 377 | { | - |
| 378 | const QWidgetList toplevels = QApplication::topLevelWidgets(); | - |
| 379 | for (int i = 0; i < toplevels.count(); ++i) { | - |
| QWidgetauto *w =: toplevels.at(i);) | |
| 380 | QApplication::sendEvent(w, e);} never executed: QApplication::sendEvent(w, e); | 0 |
| 381 | } never executed: end of block | 0 |
| 382 | | - |
| 383 | QWhatsThisPrivate *QWhatsThisPrivate::instance = 0; | - |
| 384 | | - |
| 385 | QWhatsThisPrivate::QWhatsThisPrivate() | - |
| 386 | : leaveOnMouseRelease(false) | - |
| 387 | { | - |
| 388 | instance = this; | - |
| 389 | qApp->installEventFilter(this); | - |
| 390 | | - |
| 391 | QPoint pos = QCursor::pos(); | - |
| 392 | if (QWidget *w = QApplication::widgetAt(pos)) { | - |
| 393 | QHelpEvent e(QEvent::QueryWhatsThis, w->mapFromGlobal(pos), pos); | - |
| 394 | bool sentEvent = QApplication::sendEvent(w, &e); | - |
| 395 | #ifdef QT_NO_CURSOR | - |
| 396 | Q_UNUSED(sentEvent); | - |
| 397 | #else | - |
| 398 | QApplication::setOverrideCursor((!sentEvent || !e.isAccepted())? | - |
| 399 | Qt::ForbiddenCursor:Qt::WhatsThisCursor); | - |
| 400 | } else { | - |
| 401 | QApplication::setOverrideCursor(Qt::WhatsThisCursor); | - |
| 402 | #endif | - |
| 403 | } | - |
| 404 | #ifndef QT_NO_ACCESSIBILITY | - |
| 405 | QAccessibleEvent event(this, QAccessible::ContextHelpStart); | - |
| 406 | QAccessible::updateAccessibility(&event); | - |
| 407 | #endif | - |
| 408 | } | - |
| 409 | | - |
| 410 | QWhatsThisPrivate::~QWhatsThisPrivate() | - |
| 411 | { | - |
| 412 | if (action) | - |
| 413 | action->setChecked(false); | - |
| 414 | #ifndef QT_NO_CURSOR | - |
| 415 | QApplication::restoreOverrideCursor(); | - |
| 416 | #endif | - |
| 417 | #ifndef QT_NO_ACCESSIBILITY | - |
| 418 | QAccessibleEvent event(this, QAccessible::ContextHelpEnd); | - |
| 419 | QAccessible::updateAccessibility(&event); | - |
| 420 | #endif | - |
| 421 | instance = 0; | - |
| 422 | } | - |
| 423 | | - |
| 424 | bool QWhatsThisPrivate::eventFilter(QObject *o, QEvent *e) | - |
| 425 | { | - |
| 426 | if (!o->isWidgetType()) | - |
| 427 | return false; | - |
| 428 | QWidget * w = static_cast<QWidget *>(o); | - |
| 429 | bool customWhatsThis = w->testAttribute(Qt::WA_CustomWhatsThis); | - |
| 430 | switch (e->type()) { | - |
| 431 | case QEvent::MouseButtonPress: | - |
| 432 | { | - |
| 433 | QMouseEvent *me = static_cast<QMouseEvent*>(e); | - |
| 434 | if (me->button() == Qt::RightButton || customWhatsThis) | - |
| 435 | return false; | - |
| 436 | QHelpEvent e(QEvent::WhatsThis, me->pos(), me->globalPos()); | - |
| 437 | if (!QApplication::sendEvent(w, &e) || !e.isAccepted()) | - |
| 438 | leaveOnMouseRelease = true; | - |
| 439 | | - |
| 440 | } break; | - |
| 441 | | - |
| 442 | case QEvent::MouseMove: | - |
| 443 | { | - |
| 444 | QMouseEvent *me = static_cast<QMouseEvent*>(e); | - |
| 445 | QHelpEvent e(QEvent::QueryWhatsThis, me->pos(), me->globalPos()); | - |
| 446 | bool sentEvent = QApplication::sendEvent(w, &e); | - |
| 447 | #ifdef QT_NO_CURSOR | - |
| 448 | Q_UNUSED(sentEvent); | - |
| 449 | #else | - |
| 450 | QApplication::changeOverrideCursor((!sentEvent || !e.isAccepted())? | - |
| 451 | Qt::ForbiddenCursor:Qt::WhatsThisCursor); | - |
| 452 | #endif | - |
| 453 | } | - |
| 454 | | - |
| 455 | case QEvent::MouseButtonRelease: | - |
| 456 | case QEvent::MouseButtonDblClick: | - |
| 457 | if (leaveOnMouseRelease && e->type() == QEvent::MouseButtonRelease) | - |
| 458 | QWhatsThis::leaveWhatsThisMode(); | - |
| 459 | if (static_cast<QMouseEvent*>(e)->button() == Qt::RightButton || customWhatsThis) | - |
| 460 | return false; | - |
| 461 | break; | - |
| 462 | case QEvent::KeyPress: | - |
| 463 | { | - |
| 464 | QKeyEvent* kev = (QKeyEvent*)e; | - |
| 465 | | - |
| 466 | if (kev->matches(QKeySequence::Cancel)) { | - |
| 467 | QWhatsThis::leaveWhatsThisMode(); | - |
| 468 | return true; | - |
| 469 | } else if (customWhatsThis) { | - |
| 470 | return false; | - |
| 471 | } else if (kev->key() == Qt::Key_Menu || | - |
| 472 | (kev->key() == Qt::Key_F10 && | - |
| 473 | kev->modifiers() == Qt::ShiftModifier)) { | - |
| 474 | | - |
| 475 | return false; | - |
| 476 | } else if (kev->key() != Qt::Key_Shift && kev->key() != Qt::Key_Alt | - |
| 477 | && kev->key() != Qt::Key_Control && kev->key() != Qt::Key_Meta) { | - |
| 478 | QWhatsThis::leaveWhatsThisMode(); | - |
| 479 | } | - |
| 480 | } break; | - |
| 481 | default: | - |
| 482 | return false; | - |
| 483 | } | - |
| 484 | return true; | - |
| 485 | } | - |
| 486 | | - |
| 487 | class QWhatsThisAction: public QAction | - |
| 488 | { | - |
| 489 | Q_OBJECT | - |
| 490 | | - |
| 491 | public: | - |
| 492 | explicit QWhatsThisAction(QObject* parent = 0); | - |
| 493 | | - |
| 494 | private slots: | - |
| 495 | void actionTriggered(); | - |
| 496 | }; | - |
| 497 | | - |
| 498 | QWhatsThisAction::QWhatsThisAction(QObject *parent) : QAction(tr("What's This?"), parent) | - |
| 499 | { | - |
| 500 | #ifndef QT_NO_IMAGEFORMAT_XPM | - |
| 501 | QPixmap p(button_image); | - |
| 502 | setIcon(p); | - |
| 503 | #endif | - |
| 504 | setCheckable(true); | - |
| 505 | connect(this, SIGNAL(triggered()), this, SLOT(actionTriggered())); | - |
| 506 | #ifndef QT_NO_SHORTCUT | - |
| 507 | setShortcut(Qt::ShiftModifier + Qt::Key_F1); | - |
| 508 | #endif | - |
| 509 | } | - |
| 510 | | - |
| 511 | void QWhatsThisAction::actionTriggered() | - |
| 512 | { | - |
| 513 | if (isChecked()) { | - |
| 514 | QWhatsThis::enterWhatsThisMode(); | - |
| 515 | QWhatsThisPrivate::instance->action = this; | - |
| 516 | } | - |
| 517 | } | - |
| 518 | | - |
| 519 | | - |
| 520 | | - |
| 521 | | - |
| 522 | | - |
| 523 | | - |
| 524 | | - |
| 525 | | - |
| 526 | | - |
| 527 | | - |
| 528 | | - |
| 529 | | - |
| 530 | void QWhatsThis::enterWhatsThisMode() | - |
| 531 | { | - |
| 532 | if (QWhatsThisPrivate::instance) | - |
| 533 | return; | - |
| 534 | (void) new QWhatsThisPrivate; | - |
| 535 | QEvent e(QEvent::EnterWhatsThisMode); | - |
| 536 | QWhatsThisPrivate::notifyToplevels(&e); | - |
| 537 | } | - |
| 538 | | - |
| 539 | | - |
| 540 | | - |
| 541 | | - |
| 542 | | - |
| 543 | | - |
| 544 | | - |
| 545 | bool QWhatsThis::inWhatsThisMode() | - |
| 546 | { | - |
| 547 | return (QWhatsThisPrivate::instance != 0); | - |
| 548 | } | - |
| 549 | | - |
| 550 | | - |
| 551 | | - |
| 552 | | - |
| 553 | | - |
| 554 | | - |
| 555 | | - |
| 556 | | - |
| 557 | | - |
| 558 | | - |
| 559 | void QWhatsThis::leaveWhatsThisMode() | - |
| 560 | { | - |
| 561 | delete QWhatsThisPrivate::instance; | - |
| 562 | QEvent e(QEvent::LeaveWhatsThisMode); | - |
| 563 | QWhatsThisPrivate::notifyToplevels(&e); | - |
| 564 | } | - |
| 565 | | - |
| 566 | void QWhatsThisPrivate::say(QWidget * widget, const QString &text, int x, int y) | - |
| 567 | { | - |
| 568 | if (text.size() == 0) | - |
| 569 | return; | - |
| 570 | | - |
| 571 | QWhatsThat *whatsThat = new QWhatsThat( | - |
| 572 | text, | - |
| 573 | #if defined(Q_DEAD_CODE_FROM_QT4_X11) && !defined(QT_NO_CURSOR) | - |
| 574 | QApplication::desktop()->screen(widget ? widget->x11Info().screen() : QCursor::x11Screen()), | - |
| 575 | #else | - |
| 576 | 0, | - |
| 577 | #endif | - |
| 578 | widget | - |
| 579 | ); | - |
| 580 | | - |
| 581 | | - |
| 582 | | - |
| 583 | | - |
| 584 | int scr = (widget ? | - |
| 585 | QApplication::desktop()->screenNumber(widget) : | - |
| 586 | #if defined(Q_DEAD_CODE_FROM_QT4_X11) && !defined(QT_NO_CURSOR) | - |
| 587 | QCursor::x11Screen() | - |
| 588 | #else | - |
| 589 | QApplication::desktop()->screenNumber(QPoint(x,y)) | - |
| 590 | #endif // Q_DEAD_CODE_FROM_QT4_X11 | - |
| 591 | ); | - |
| 592 | QRect screen = QApplication::desktop()->screenGeometry(scr); | - |
| 593 | | - |
| 594 | int w = whatsThat->width(); | - |
| 595 | int h = whatsThat->height(); | - |
| 596 | int sx = screen.x(); | - |
| 597 | int sy = screen.y(); | - |
| 598 | | - |
| 599 | | - |
| 600 | | - |
| 601 | QPoint pos; | - |
| 602 | if (widget) | - |
| 603 | pos = widget->mapToGlobal(QPoint(0,0)); | - |
| 604 | | - |
| 605 | if (widget && w > widget->width() + 16) | - |
| 606 | x = pos.x() + widget->width()/2 - w/2; | - |
| 607 | else | - |
| 608 | x = x - w/2; | - |
| 609 | | - |
| 610 | | - |
| 611 | | - |
| 612 | if (x + w + shadowWidth > sx+screen.width()) | - |
| 613 | x = (widget? (qMin(screen.width(), | - |
| 614 | pos.x() + widget->width()) | - |
| 615 | ) : screen.width()) | - |
| 616 | - w; | - |
| 617 | | - |
| 618 | if (x < sx) | - |
| 619 | x = sx; | - |
| 620 | | - |
| 621 | if (widget && h > widget->height() + 16) { | - |
| 622 | y = pos.y() + widget->height() + 2; | - |
| 623 | | - |
| 624 | if (y + h + 10 > sy+screen.height()) | - |
| 625 | y = pos.y() + 2 - shadowWidth - h; | - |
| 626 | } | - |
| 627 | y = y + 2; | - |
| 628 | | - |
| 629 | | - |
| 630 | | - |
| 631 | if (y + h + shadowWidth > sy+screen.height()) | - |
| 632 | y = (widget ? (qMin(screen.height(), | - |
| 633 | pos.y() + widget->height()) | - |
| 634 | ) : screen.height()) | - |
| 635 | - h; | - |
| 636 | if (y < sy) | - |
| 637 | y = sy; | - |
| 638 | | - |
| 639 | whatsThat->move(x, y); | - |
| 640 | whatsThat->show(); | - |
| 641 | whatsThat->grabKeyboard(); | - |
| 642 | } | - |
| 643 | | - |
| 644 | | - |
| 645 | | - |
| 646 | | - |
| 647 | | - |
| 648 | | - |
| 649 | | - |
| 650 | | - |
| 651 | void QWhatsThis::showText(const QPoint &pos, const QString &text, QWidget *w) | - |
| 652 | { | - |
| 653 | leaveWhatsThisMode(); | - |
| 654 | QWhatsThisPrivate::say(w, text, pos.x(), pos.y()); | - |
| 655 | } | - |
| 656 | | - |
| 657 | | - |
| 658 | | - |
| 659 | | - |
| 660 | | - |
| 661 | | - |
| 662 | void QWhatsThis::hideText() | - |
| 663 | { | - |
| 664 | qDeleteInEventHandler(QWhatsThat::instance); | - |
| 665 | } | - |
| 666 | | - |
| 667 | | - |
| 668 | | - |
| 669 | | - |
| 670 | | - |
| 671 | | - |
| 672 | | - |
| 673 | | - |
| 674 | QAction *QWhatsThis::createAction(QObject *parent) | - |
| 675 | { | - |
| 676 | return new QWhatsThisAction(parent); | - |
| 677 | } | - |
| 678 | | - |
| 679 | QT_END_NAMESPACE | - |
| 680 | | - |
| 681 | #include "qwhatsthis.moc" | - |
| 682 | | - |
| 683 | #endif // QT_NO_WHATSTHIS | - |
| | |