diff options
Diffstat (limited to 'src/webenginewidgets/ui')
-rw-r--r-- | src/webenginewidgets/ui/autofillpopupwidget.cpp | 40 | ||||
-rw-r--r-- | src/webenginewidgets/ui/autofillpopupwidget_p.h | 40 | ||||
-rw-r--r-- | src/webenginewidgets/ui/touchhandlewidget.cpp | 59 | ||||
-rw-r--r-- | src/webenginewidgets/ui/touchhandlewidget_p.h | 50 | ||||
-rw-r--r-- | src/webenginewidgets/ui/touchselectionmenuwidget.cpp | 117 | ||||
-rw-r--r-- | src/webenginewidgets/ui/touchselectionmenuwidget_p.h | 52 |
6 files changed, 282 insertions, 76 deletions
diff --git a/src/webenginewidgets/ui/autofillpopupwidget.cpp b/src/webenginewidgets/ui/autofillpopupwidget.cpp index 579869d9e..a4dc31beb 100644 --- a/src/webenginewidgets/ui/autofillpopupwidget.cpp +++ b/src/webenginewidgets/ui/autofillpopupwidget.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2022 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine 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) 2022 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 "autofillpopupwidget_p.h" #include "qwebengineview.h" diff --git a/src/webenginewidgets/ui/autofillpopupwidget_p.h b/src/webenginewidgets/ui/autofillpopupwidget_p.h index 064c4f824..79decc6ab 100644 --- a/src/webenginewidgets/ui/autofillpopupwidget_p.h +++ b/src/webenginewidgets/ui/autofillpopupwidget_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2022 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine 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) 2022 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 #ifndef AUTOFILLPOPUPWIDGET_P_H #define AUTOFILLPOPUPWIDGET_P_H diff --git a/src/webenginewidgets/ui/touchhandlewidget.cpp b/src/webenginewidgets/ui/touchhandlewidget.cpp new file mode 100644 index 000000000..88af0ff36 --- /dev/null +++ b/src/webenginewidgets/ui/touchhandlewidget.cpp @@ -0,0 +1,59 @@ +// Copyright (C) 2022 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 "touchhandlewidget_p.h" +#include "qwebengineview.h" + +#include <QBoxLayout> +#include <QGraphicsOpacityEffect> +#include <QLabel> +#include <QWidget> + +namespace QtWebEngineWidgetUI { +TouchHandleWidget::TouchHandleWidget(QWebEngineView *view, const QMap<int, QImage> &images) + : m_widget(new QWidget(view)) + , m_label(new QLabel(m_widget)) + , m_opacityEffect(new QGraphicsOpacityEffect(m_widget)) + , m_images(images) +{ + m_widget->setAttribute(Qt::WA_AcceptTouchEvents, true); + m_widget->setAttribute(Qt::WA_TransparentForMouseEvents, true); +} + +TouchHandleWidget::~TouchHandleWidget() +{ +} + +void TouchHandleWidget::setImage(int orientation) +{ + const QImage &img = m_images[orientation]; + m_label->setPixmap(QPixmap::fromImage(img)); + m_label->setFrameStyle(QFrame::NoFrame); + m_label->resize(img.size()); + m_label->setVisible(true); + + QVBoxLayout layout; + layout.setSpacing(0); + layout.setContentsMargins(QMargins()); + layout.addWidget(m_label); + layout.setParent(m_widget); + m_widget->setLayout(&layout); + m_widget->resize(img.size()); +} + +void TouchHandleWidget::setBounds(const QRect &bounds) +{ + m_widget->setGeometry(bounds); +} + +void TouchHandleWidget::setVisible(bool visible) +{ + m_widget->setVisible(visible); +} + +void TouchHandleWidget::setOpacity(float opacity) +{ + m_opacityEffect->setOpacity(opacity); + m_widget->setGraphicsEffect(m_opacityEffect); +} +} // namespace QtWebEngineWidgetUI diff --git a/src/webenginewidgets/ui/touchhandlewidget_p.h b/src/webenginewidgets/ui/touchhandlewidget_p.h new file mode 100644 index 000000000..9f181c935 --- /dev/null +++ b/src/webenginewidgets/ui/touchhandlewidget_p.h @@ -0,0 +1,50 @@ +// Copyright (C) 2022 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 + +#ifndef TOUCHHANDLEWIDGET_P_H +#define TOUCHHANDLEWIDGET_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "touch_handle_drawable_client.h" + +#include <QImage> +#include <QMap> + +QT_BEGIN_NAMESPACE +class QGraphicsOpacityEffect; +class QLabel; +class QWebEngineView; +class QWidget; +QT_END_NAMESPACE + +namespace QtWebEngineWidgetUI { +class TouchHandleWidget : public QtWebEngineCore::TouchHandleDrawableDelegate +{ +public: + TouchHandleWidget(QWebEngineView *view, const QMap<int, QImage> &images); + ~TouchHandleWidget(); + + void setImage(int orientation) override; + void setBounds(const QRect &bounds) override; + void setVisible(bool visible) override; + void setOpacity(float opacity) override; + +private: + QWidget *m_widget; + QLabel *m_label; + QGraphicsOpacityEffect *m_opacityEffect; + QMap<int, QImage> m_images; +}; +} // namespace QtWebEngineWidgetUI + +#endif // TOUCHHANDLEWIDGET_P_H diff --git a/src/webenginewidgets/ui/touchselectionmenuwidget.cpp b/src/webenginewidgets/ui/touchselectionmenuwidget.cpp new file mode 100644 index 000000000..ff69fe84b --- /dev/null +++ b/src/webenginewidgets/ui/touchselectionmenuwidget.cpp @@ -0,0 +1,117 @@ +// Copyright (C) 2022 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 "touchselectionmenuwidget_p.h" +#include "qwebengineview.h" + +#include "touch_selection_menu_controller.h" + +#include <QBoxLayout> +#include <QEvent> + +namespace QtWebEngineWidgetUI { +namespace { +// The Widgets module is built with rtti in developer-build while Core is not. +// The MOC will throw "undefined reference to typeinfo..." errors if we connect slots +// from QtWebEngineCore via function pointers, because it expects rtti on them. +// To workaround this we use lambdas. +void connectButton(TouchSelectionMenuWidget::TouchButton *button, std::function<void()> callback) +{ + QObject::connect(button, &QPushButton::clicked, std::move(callback)); +} +} // namespace + +TouchSelectionMenuWidget::TouchButton::TouchButton(QString name, QWidget *parent) + : QPushButton(name, parent) +{ + setAttribute(Qt::WA_AcceptTouchEvents, true); +} + +TouchSelectionMenuWidget::TouchButton::~TouchButton() +{ +} + +bool TouchSelectionMenuWidget::TouchButton::event(QEvent *ev) +{ + switch (ev->type()) { + case QEvent::TouchBegin: + ev->accept(); + return true; + case QEvent::TouchEnd: + Q_EMIT clicked(); + ev->accept(); + return true; + default: + break; + } + + return QPushButton::event(ev); +} + +TouchSelectionMenuWidget::TouchSelectionMenuWidget( + QWebEngineView *view, QtWebEngineCore::TouchSelectionMenuController *controller) + : QWidget(view, + Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint + | Qt::WindowDoesNotAcceptFocus) +{ + setAttribute(Qt::WA_AcceptTouchEvents, true); + setAttribute(Qt::WA_TransparentForMouseEvents, true); + setAttribute(Qt::WA_DeleteOnClose, true); + + bool cutEnabled = + controller->isCommandEnabled(QtWebEngineCore::TouchSelectionMenuController::Cut); + bool copyEnabled = + controller->isCommandEnabled(QtWebEngineCore::TouchSelectionMenuController::Copy); + bool pasteEnabled = + controller->isCommandEnabled(QtWebEngineCore::TouchSelectionMenuController::Paste); + + QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding); + QHBoxLayout *layout = new QHBoxLayout(); + + if (cutEnabled) { + TouchButton *button = new TouchButton(tr("Cut"), this); + button->setSizePolicy(policy); + layout->addWidget(button); + connectButton(button, [controller]() { controller->cut(); }); + } + + if (copyEnabled) { + TouchButton *button = new TouchButton(tr("Copy"), this); + button->setSizePolicy(policy); + layout->addWidget(button); + connectButton(button, [controller]() { controller->copy(); }); + } + + if (pasteEnabled) { + TouchButton *button = new TouchButton(tr("Paste"), this); + button->setSizePolicy(policy); + layout->addWidget(button); + connectButton(button, [controller]() { controller->paste(); }); + } + + TouchButton *button = new TouchButton(tr("..."), this); + button->setSizePolicy(policy); + layout->addWidget(button); + connectButton(button, [controller]() { controller->runContextMenu(); }); + + layout->setSpacing(2); + layout->setSizeConstraint(QLayout::SetMinimumSize); + layout->setContentsMargins(0, 0, 0, 0); + setLayout(layout); + + nativeParentWidget()->installEventFilter(this); +} + +TouchSelectionMenuWidget::~TouchSelectionMenuWidget() +{ +} + +bool TouchSelectionMenuWidget::eventFilter(QObject *obj, QEvent *ev) +{ + // Close the menu if the window is moved + if (ev->type() == QEvent::Move) + close(); + + return QWidget::eventFilter(obj, ev); +} +} // QtWebEngineWidgetUI diff --git a/src/webenginewidgets/ui/touchselectionmenuwidget_p.h b/src/webenginewidgets/ui/touchselectionmenuwidget_p.h new file mode 100644 index 000000000..1f822023b --- /dev/null +++ b/src/webenginewidgets/ui/touchselectionmenuwidget_p.h @@ -0,0 +1,52 @@ +// Copyright (C) 2022 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 + +#ifndef TOUCHSELECTIONMENUWIDGET_P_H +#define TOUCHSELECTIONMENUWIDGET_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QPushButton> +#include <QWidget> + +namespace QtWebEngineCore { +class TouchSelectionMenuController; +} + +QT_BEGIN_NAMESPACE +class QWebEngineView; +QT_END_NAMESPACE + +namespace QtWebEngineWidgetUI { +class TouchSelectionMenuWidget : public QWidget +{ +public: + class TouchButton : public QPushButton + { + public: + TouchButton(QString name, QWidget *parent); + ~TouchButton(); + + protected: + bool event(QEvent *ev) override; + }; + + TouchSelectionMenuWidget(QWebEngineView *view, + QtWebEngineCore::TouchSelectionMenuController *controller); + ~TouchSelectionMenuWidget(); + +protected: + bool eventFilter(QObject *obj, QEvent *ev) override; +}; +} // namespace QtWebEngineWidgetUI + +#endif // TOUCHSELECTIONMENUWIDGET_P_H |