summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwhatsthis.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel/qwhatsthis.cpp')
-rw-r--r--src/widgets/kernel/qwhatsthis.cpp180
1 files changed, 59 insertions, 121 deletions
diff --git a/src/widgets/kernel/qwhatsthis.cpp b/src/widgets/kernel/qwhatsthis.cpp
index 1fa83d3238..c80f37267f 100644
--- a/src/widgets/kernel/qwhatsthis.cpp
+++ b/src/widgets/kernel/qwhatsthis.cpp
@@ -1,48 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwhatsthis.h"
#include "qpointer.h"
#include "qapplication.h"
#include <private/qguiapplication_p.h>
-#include "qdesktopwidget.h"
-#include <private/qdesktopwidget_p.h>
+#include "qwidget.h"
#include "qevent.h"
#include "qpixmap.h"
#include "qscreen.h"
@@ -57,7 +20,7 @@
#include <qpa/qplatformtheme.h>
#include "private/qtextdocumentlayout_p.h"
#include "qdebug.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
@@ -134,8 +97,6 @@ QT_BEGIN_NAMESPACE
\sa QToolTip
*/
-Q_CORE_EXPORT void qDeleteInEventHandler(QObject *o);
-
class QWhatsThat : public QWidget
{
Q_OBJECT
@@ -147,7 +108,6 @@ public:
static QWhatsThat *instance;
protected:
- void showEvent(QShowEvent *e) override;
void mousePressEvent(QMouseEvent*) override;
void mouseReleaseEvent(QMouseEvent*) override;
void mouseMoveEvent(QMouseEvent*) override;
@@ -160,10 +120,9 @@ private:
QString text;
QTextDocument* doc;
QString anchor;
- QPixmap background;
};
-QWhatsThat *QWhatsThat::instance = 0;
+QWhatsThat *QWhatsThat::instance = nullptr;
// shadowWidth not const, for XP drop-shadow-fu turns it to 0
static int shadowWidth = 6; // also used as '5' and '6' and even '8' below
@@ -193,7 +152,7 @@ QWhatsThat::QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor
setCursor(Qt::ArrowCursor);
#endif
QRect r;
- doc = 0;
+ doc = nullptr;
ensurePolished(); // Ensures style sheet font before size calc
if (Qt::mightBeRichText(text)) {
doc = new QTextDocument();
@@ -212,15 +171,15 @@ QWhatsThat::QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor
}
else
{
- int sw = QDesktopWidgetPrivate::width() / 3;
+ int sw = QGuiApplication::primaryScreen()->virtualGeometry().width() / 3;
if (sw < 200)
sw = 200;
else if (sw > 300)
sw = 300;
r = fontMetrics().boundingRect(0, 0, sw, 1000,
- Qt::AlignLeft + Qt::AlignTop
- + Qt::TextWordWrap + Qt::TextExpandTabs,
+ Qt::AlignLeft | Qt::AlignTop
+ | Qt::TextWordWrap | Qt::TextExpandTabs,
text);
}
shadowWidth = dropShadow() ? 0 : 6;
@@ -229,23 +188,17 @@ QWhatsThat::QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor
QWhatsThat::~QWhatsThat()
{
- instance = 0;
+ instance = nullptr;
if (doc)
delete doc;
}
-void QWhatsThat::showEvent(QShowEvent *)
-{
- background = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->internalWinId(),
- x(), y(), width(), height());
-}
-
void QWhatsThat::mousePressEvent(QMouseEvent* e)
{
pressed = true;
- if (e->button() == Qt::LeftButton && rect().contains(e->pos())) {
+ if (e->button() == Qt::LeftButton && rect().contains(e->position().toPoint())) {
if (doc)
- anchor = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin));
+ anchor = doc->documentLayout()->anchorAt(e->position().toPoint() - QPoint(hMargin, vMargin));
return;
}
close();
@@ -255,15 +208,15 @@ void QWhatsThat::mouseReleaseEvent(QMouseEvent* e)
{
if (!pressed)
return;
- if (widget && e->button() == Qt::LeftButton && doc && rect().contains(e->pos())) {
- QString a = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin));
+ if (widget && e->button() == Qt::LeftButton && doc && rect().contains(e->position().toPoint())) {
+ QString a = doc->documentLayout()->anchorAt(e->position().toPoint() - QPoint(hMargin, vMargin));
QString href;
if (anchor == a)
href = a;
anchor.clear();
if (!href.isEmpty()) {
QWhatsThisClickedEvent e(href);
- if (QApplication::sendEvent(widget, &e))
+ if (QCoreApplication::sendEvent(widget, &e))
return;
}
}
@@ -277,7 +230,7 @@ void QWhatsThat::mouseMoveEvent(QMouseEvent* e)
#else
if (!doc)
return;
- QString a = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin));
+ QString a = doc->documentLayout()->anchorAt(e->position().toPoint() - QPoint(hMargin, vMargin));
if (!a.isEmpty())
setCursor(Qt::PointingHandCursor);
else
@@ -299,7 +252,6 @@ void QWhatsThat::paintEvent(QPaintEvent*)
if (drawShadow)
r.adjust(0, 0, -shadowWidth, -shadowWidth);
QPainter p(this);
- p.drawPixmap(0, 0, background);
p.setPen(QPen(palette().toolTipText(), 0));
p.setBrush(palette().toolTipBase());
p.drawRect(r);
@@ -335,7 +287,7 @@ void QWhatsThat::paintEvent(QPaintEvent*)
}
else
{
- p.drawText(r, Qt::AlignLeft + Qt::AlignTop + Qt::TextWordWrap + Qt::TextExpandTabs, text);
+ p.drawText(r, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap | Qt::TextExpandTabs, text);
}
}
@@ -380,10 +332,10 @@ void QWhatsThisPrivate::notifyToplevels(QEvent *e)
{
const QWidgetList toplevels = QApplication::topLevelWidgets();
for (auto *w : toplevels)
- QApplication::sendEvent(w, e);
+ QCoreApplication::sendEvent(w, e);
}
-QWhatsThisPrivate *QWhatsThisPrivate::instance = 0;
+QWhatsThisPrivate *QWhatsThisPrivate::instance = nullptr;
QWhatsThisPrivate::QWhatsThisPrivate()
: leaveOnMouseRelease(false)
@@ -394,17 +346,17 @@ QWhatsThisPrivate::QWhatsThisPrivate()
QPoint pos = QCursor::pos();
if (QWidget *w = QApplication::widgetAt(pos)) {
QHelpEvent e(QEvent::QueryWhatsThis, w->mapFromGlobal(pos), pos);
- bool sentEvent = QApplication::sendEvent(w, &e);
+ const bool sentEvent = QCoreApplication::sendEvent(w, &e);
#ifdef QT_NO_CURSOR
Q_UNUSED(sentEvent);
#else
- QApplication::setOverrideCursor((!sentEvent || !e.isAccepted())?
+ QGuiApplication::setOverrideCursor((!sentEvent || !e.isAccepted())?
Qt::ForbiddenCursor:Qt::WhatsThisCursor);
} else {
- QApplication::setOverrideCursor(Qt::WhatsThisCursor);
+ QGuiApplication::setOverrideCursor(Qt::WhatsThisCursor);
#endif
}
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleEvent event(this, QAccessible::ContextHelpStart);
QAccessible::updateAccessibility(&event);
#endif
@@ -417,13 +369,13 @@ QWhatsThisPrivate::~QWhatsThisPrivate()
action->setChecked(false);
#endif // QT_CONFIG(action)
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleEvent event(this, QAccessible::ContextHelpEnd);
QAccessible::updateAccessibility(&event);
#endif
- instance = 0;
+ instance = nullptr;
}
bool QWhatsThisPrivate::eventFilter(QObject *o, QEvent *e)
@@ -438,8 +390,8 @@ bool QWhatsThisPrivate::eventFilter(QObject *o, QEvent *e)
QMouseEvent *me = static_cast<QMouseEvent*>(e);
if (me->button() == Qt::RightButton || customWhatsThis)
return false;
- QHelpEvent e(QEvent::WhatsThis, me->pos(), me->globalPos());
- if (!QApplication::sendEvent(w, &e) || !e.isAccepted())
+ QHelpEvent e(QEvent::WhatsThis, me->position().toPoint(), me->globalPosition().toPoint());
+ if (!QCoreApplication::sendEvent(w, &e) || !e.isAccepted())
leaveOnMouseRelease = true;
} break;
@@ -447,13 +399,13 @@ bool QWhatsThisPrivate::eventFilter(QObject *o, QEvent *e)
case QEvent::MouseMove:
{
QMouseEvent *me = static_cast<QMouseEvent*>(e);
- QHelpEvent e(QEvent::QueryWhatsThis, me->pos(), me->globalPos());
- bool sentEvent = QApplication::sendEvent(w, &e);
+ QHelpEvent e(QEvent::QueryWhatsThis, me->position().toPoint(), me->globalPosition().toPoint());
+ const bool sentEvent = QCoreApplication::sendEvent(w, &e);
#ifdef QT_NO_CURSOR
Q_UNUSED(sentEvent);
#else
- QApplication::changeOverrideCursor((!sentEvent || !e.isAccepted())?
- Qt::ForbiddenCursor:Qt::WhatsThisCursor);
+ QGuiApplication::changeOverrideCursor((!sentEvent || !e.isAccepted())?
+ Qt::ForbiddenCursor:Qt::WhatsThisCursor);
#endif
Q_FALLTHROUGH();
}
@@ -466,7 +418,7 @@ bool QWhatsThisPrivate::eventFilter(QObject *o, QEvent *e)
break;
case QEvent::KeyPress:
{
- QKeyEvent* kev = (QKeyEvent*)e;
+ QKeyEvent *kev = static_cast<QKeyEvent *>(e);
#if QT_CONFIG(shortcut)
if (kev->matches(QKeySequence::Cancel)) {
QWhatsThis::leaveWhatsThisMode();
@@ -497,7 +449,7 @@ class QWhatsThisAction: public QAction
Q_OBJECT
public:
- explicit QWhatsThisAction(QObject* parent = 0);
+ explicit QWhatsThisAction(QObject* parent = nullptr);
private slots:
void actionTriggered();
@@ -510,9 +462,9 @@ QWhatsThisAction::QWhatsThisAction(QObject *parent) : QAction(tr("What's This?")
setIcon(p);
#endif
setCheckable(true);
- connect(this, SIGNAL(triggered()), this, SLOT(actionTriggered()));
+ connect(this, &QWhatsThisAction::triggered, this, &QWhatsThisAction::actionTriggered);
#ifndef QT_NO_SHORTCUT
- setShortcut(Qt::ShiftModifier + Qt::Key_F1);
+ setShortcut(Qt::ShiftModifier | Qt::Key_F1);
#endif
}
@@ -553,7 +505,7 @@ void QWhatsThis::enterWhatsThisMode()
*/
bool QWhatsThis::inWhatsThisMode()
{
- return (QWhatsThisPrivate::instance != 0);
+ return (QWhatsThisPrivate::instance != nullptr);
}
/*!
@@ -577,33 +529,19 @@ void QWhatsThisPrivate::say(QWidget * widget, const QString &text, int x, int y)
if (text.size() == 0)
return;
// make a fresh widget, and set it up
- QWhatsThat *whatsThat = new QWhatsThat(
- text,
-#if 0 /* Used to be included in Qt4 for Q_WS_X11 */ && !defined(QT_NO_CURSOR)
- QApplication::desktop()->screen(widget ? widget->x11Info().screen() : QCursor::x11Screen()),
-#else
- 0,
-#endif
- widget
- );
-
+ QWhatsThat *whatsThat = new QWhatsThat(text, nullptr, widget);
// okay, now to find a suitable location
-
- int scr = (widget ?
- QDesktopWidgetPrivate::screenNumber(widget) :
-#if 0 /* Used to be included in Qt4 for Q_WS_X11 */ && !defined(QT_NO_CURSOR)
- QCursor::x11Screen()
-#else
- QDesktopWidgetPrivate::screenNumber(QPoint(x,y))
-#endif
- );
- QRect screen = QDesktopWidgetPrivate::screenGeometry(scr);
+ QScreen *screen = widget ? widget->screen()
+ : QGuiApplication::screenAt(QPoint(x, y));
+ if (!screen)
+ screen = QGuiApplication::primaryScreen();
+ QRect screenRect = screen->geometry();
int w = whatsThat->width();
int h = whatsThat->height();
- int sx = screen.x();
- int sy = screen.y();
+ int sx = screenRect.x();
+ int sy = screenRect.y();
// first try locating the widget immediately above/below,
// with nice alignment if possible.
@@ -616,13 +554,13 @@ void QWhatsThisPrivate::say(QWidget * widget, const QString &text, int x, int y)
else
x = x - w/2;
- // squeeze it in if that would result in part of what's this
- // being only partially visible
- if (x + w + shadowWidth > sx+screen.width())
- x = (widget? (qMin(screen.width(),
- pos.x() + widget->width())
- ) : screen.width())
+ // squeeze it in if that would result in part of what's this
+ // being only partially visible
+ if (x + w + shadowWidth > sx+screenRect.width()) {
+ x = (widget ? qMin(screenRect.width(), pos.x() + widget->width())
+ : screenRect.width())
- w;
+ }
if (x < sx)
x = sx;
@@ -630,18 +568,18 @@ void QWhatsThisPrivate::say(QWidget * widget, const QString &text, int x, int y)
if (widget && h > widget->height() + 16) {
y = pos.y() + widget->height() + 2; // below, two pixels spacing
// what's this is above or below, wherever there's most space
- if (y + h + 10 > sy+screen.height())
+ if (y + h + 10 > sy + screenRect.height())
y = pos.y() + 2 - shadowWidth - h; // above, overlap
}
y = y + 2;
- // squeeze it in if that would result in part of what's this
- // being only partially visible
- if (y + h + shadowWidth > sy+screen.height())
- y = (widget ? (qMin(screen.height(),
- pos.y() + widget->height())
- ) : screen.height())
+ // squeeze it in if that would result in part of what's this
+ // being only partially visible
+ if (y + h + shadowWidth > sy + screenRect.height()) {
+ y = (widget ? qMin(screenRect.height(), pos.y() + widget->height())
+ : screenRect.height())
- h;
+ }
if (y < sy)
y = sy;
@@ -670,7 +608,7 @@ void QWhatsThis::showText(const QPoint &pos, const QString &text, QWidget *w)
*/
void QWhatsThis::hideText()
{
- qDeleteInEventHandler(QWhatsThat::instance);
+ delete QWhatsThat::instance;
}
/*!