blob: 88af0ff36ab3417b0b659403740d531b374ffde2 (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
|