/src/qtbase/src/gui/kernel/qshapedpixmapdndwindow.cpp
Line | Count | Source |
1 | | // Copyright (C) 2016 The Qt Company Ltd. |
2 | | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | | // Qt-Security score:significant reason:default |
4 | | |
5 | | #include "qshapedpixmapdndwindow_p.h" |
6 | | |
7 | | #include "qplatformwindow.h" |
8 | | |
9 | | #include <QtGui/QPainter> |
10 | | #include <QtGui/QCursor> |
11 | | #include <QtGui/QGuiApplication> |
12 | | #include <QtGui/QPalette> |
13 | | #include <QtGui/QBitmap> |
14 | | |
15 | | QT_BEGIN_NAMESPACE |
16 | | |
17 | | QShapedPixmapWindow::QShapedPixmapWindow(QScreen *screen) |
18 | 0 | : m_useCompositing(true) |
19 | 0 | { |
20 | 0 | setScreen(screen); |
21 | 0 | QSurfaceFormat format; |
22 | 0 | format.setAlphaBufferSize(8); |
23 | 0 | setFormat(format); |
24 | 0 | setFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint |
25 | 0 | | Qt::WindowTransparentForInput | Qt::WindowDoesNotAcceptFocus); |
26 | 0 | } |
27 | | |
28 | | QShapedPixmapWindow::~QShapedPixmapWindow() |
29 | 0 | { |
30 | 0 | } |
31 | | |
32 | | void QShapedPixmapWindow::setPixmap(const QPixmap &pixmap) |
33 | 0 | { |
34 | 0 | m_pixmap = pixmap; |
35 | 0 | if (!m_useCompositing) { |
36 | 0 | const QBitmap mask = m_pixmap.mask(); |
37 | 0 | if (!mask.isNull()) { |
38 | 0 | if (!handle()) |
39 | 0 | create(); |
40 | 0 | if (auto platformWindow = handle()) { |
41 | 0 | const auto pixmapDpr = m_pixmap.devicePixelRatio(); |
42 | 0 | const auto winDpr = devicePixelRatio(); |
43 | 0 | const auto maskSize = (QSizeF(m_pixmap.size()) * winDpr / pixmapDpr).toSize(); |
44 | 0 | platformWindow->setMask(QBitmap::fromPixmap(mask.scaled(maskSize))); |
45 | 0 | } |
46 | 0 | } |
47 | 0 | } |
48 | 0 | } |
49 | | |
50 | | void QShapedPixmapWindow::setHotspot(const QPoint &hotspot) |
51 | 0 | { |
52 | 0 | m_hotSpot = hotspot; |
53 | 0 | } |
54 | | |
55 | | void QShapedPixmapWindow::paintEvent(QPaintEvent *) |
56 | 0 | { |
57 | 0 | if (!m_pixmap.isNull()) { |
58 | 0 | const QRect rect(QPoint(0, 0), size()); |
59 | 0 | QPainter painter(this); |
60 | 0 | if (m_useCompositing) |
61 | 0 | painter.setCompositionMode(QPainter::CompositionMode_Source); |
62 | 0 | else |
63 | 0 | painter.fillRect(rect, QGuiApplication::palette().base()); |
64 | 0 | painter.drawPixmap(rect, m_pixmap); |
65 | 0 | } |
66 | 0 | } |
67 | | |
68 | | void QShapedPixmapWindow::updateGeometry(const QPoint &pos) |
69 | 0 | { |
70 | 0 | QSize size(1, 1); |
71 | 0 | if (!m_pixmap.isNull()) { |
72 | 0 | size = m_pixmap.deviceIndependentSize().toSize(); |
73 | 0 | } |
74 | 0 | setGeometry(QRect(pos - m_hotSpot, size)); |
75 | 0 | } |
76 | | |
77 | | QT_END_NAMESPACE |
78 | | |
79 | | #include "moc_qshapedpixmapdndwindow_p.cpp" |