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.cpp147
1 files changed, 49 insertions, 98 deletions
diff --git a/src/widgets/kernel/qwhatsthis.cpp b/src/widgets/kernel/qwhatsthis.cpp
index 228ca4d38a..4c988e4af3 100644
--- a/src/widgets/kernel/qwhatsthis.cpp
+++ b/src/widgets/kernel/qwhatsthis.cpp
@@ -1,53 +1,15 @@
-/****************************************************************************
-**
-** 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"
#include "qpainter.h"
-#include "qtimer.h"
#if QT_CONFIG(action)
#include "qaction.h"
#endif // QT_CONFIG(action)
@@ -57,7 +19,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 +96,6 @@ QT_BEGIN_NAMESPACE
\sa QToolTip
*/
-Q_CORE_EXPORT void qDeleteInEventHandler(QObject *o);
-
class QWhatsThat : public QWidget
{
Q_OBJECT
@@ -147,7 +107,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 +119,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 +151,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 +170,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 +187,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,8 +207,8 @@ 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;
@@ -277,7 +229,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 +251,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 +286,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);
}
}
@@ -383,7 +334,7 @@ void QWhatsThisPrivate::notifyToplevels(QEvent *e)
QCoreApplication::sendEvent(w, e);
}
-QWhatsThisPrivate *QWhatsThisPrivate::instance = 0;
+QWhatsThisPrivate *QWhatsThisPrivate::instance = nullptr;
QWhatsThisPrivate::QWhatsThisPrivate()
: leaveOnMouseRelease(false)
@@ -404,7 +355,7 @@ QWhatsThisPrivate::QWhatsThisPrivate()
QGuiApplication::setOverrideCursor(Qt::WhatsThisCursor);
#endif
}
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleEvent event(this, QAccessible::ContextHelpStart);
QAccessible::updateAccessibility(&event);
#endif
@@ -419,11 +370,11 @@ QWhatsThisPrivate::~QWhatsThisPrivate()
#ifndef QT_NO_CURSOR
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,7 +389,7 @@ 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());
+ QHelpEvent e(QEvent::WhatsThis, me->position().toPoint(), me->globalPosition().toPoint());
if (!QCoreApplication::sendEvent(w, &e) || !e.isAccepted())
leaveOnMouseRelease = true;
@@ -447,7 +398,7 @@ bool QWhatsThisPrivate::eventFilter(QObject *o, QEvent *e)
case QEvent::MouseMove:
{
QMouseEvent *me = static_cast<QMouseEvent*>(e);
- QHelpEvent e(QEvent::QueryWhatsThis, me->pos(), me->globalPos());
+ QHelpEvent e(QEvent::QueryWhatsThis, me->position().toPoint(), me->globalPosition().toPoint());
const bool sentEvent = QCoreApplication::sendEvent(w, &e);
#ifdef QT_NO_CURSOR
Q_UNUSED(sentEvent);
@@ -466,7 +417,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 +448,7 @@ class QWhatsThisAction: public QAction
Q_OBJECT
public:
- explicit QWhatsThisAction(QObject* parent = 0);
+ explicit QWhatsThisAction(QObject* parent = nullptr);
private slots:
void actionTriggered();
@@ -510,9 +461,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 +504,7 @@ void QWhatsThis::enterWhatsThisMode()
*/
bool QWhatsThis::inWhatsThisMode()
{
- return (QWhatsThisPrivate::instance != 0);
+ return (QWhatsThisPrivate::instance != nullptr);
}
/*!
@@ -577,19 +528,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, 0, widget);
+ QWhatsThat *whatsThat = new QWhatsThat(text, nullptr, widget);
// okay, now to find a suitable location
- int scr = (widget ?
- QDesktopWidgetPrivate::screenNumber(widget) :
- QDesktopWidgetPrivate::screenNumber(QPoint(x,y))
- );
- 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.
@@ -602,13 +553,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;
@@ -616,18 +567,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;
@@ -656,7 +607,7 @@ void QWhatsThis::showText(const QPoint &pos, const QString &text, QWidget *w)
*/
void QWhatsThis::hideText()
{
- qDeleteInEventHandler(QWhatsThat::instance);
+ delete QWhatsThat::instance;
}
/*!