Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qshapedpixmapdndwindow.cpp
Go to the documentation of this file.
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
6
8
9#include <QtGui/QPainter>
10#include <QtGui/QCursor>
11#include <QtGui/QGuiApplication>
12#include <QtGui/QPalette>
13#include <QtGui/QBitmap>
14
16
17QShapedPixmapWindow::QShapedPixmapWindow(QScreen *screen)
18 : m_useCompositing(true)
19{
20 setScreen(screen);
21 QSurfaceFormat format;
22 format.setAlphaBufferSize(8);
23 setFormat(format);
24 setFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint
25 | Qt::WindowTransparentForInput | Qt::WindowDoesNotAcceptFocus);
26}
27
28QShapedPixmapWindow::~QShapedPixmapWindow()
29{
30}
31
32void QShapedPixmapWindow::setPixmap(const QPixmap &pixmap)
33{
34 m_pixmap = pixmap;
35 if (!m_useCompositing) {
36 const QBitmap mask = m_pixmap.mask();
37 if (!mask.isNull()) {
38 if (!handle())
39 create();
40 if (auto platformWindow = handle()) {
41 const auto pixmapDpr = m_pixmap.devicePixelRatio();
42 const auto winDpr = devicePixelRatio();
43 const auto maskSize = (QSizeF(m_pixmap.size()) * winDpr / pixmapDpr).toSize();
44 platformWindow->setMask(QBitmap::fromPixmap(mask.scaled(maskSize)));
45 }
46 }
47 }
48}
49
50void QShapedPixmapWindow::setHotspot(const QPoint &hotspot)
51{
52 m_hotSpot = hotspot;
53}
54
55void QShapedPixmapWindow::paintEvent(QPaintEvent *)
56{
57 if (!m_pixmap.isNull()) {
58 const QRect rect(QPoint(0, 0), size());
59 QPainter painter(this);
60 if (m_useCompositing)
61 painter.setCompositionMode(QPainter::CompositionMode_Source);
62 else
63 painter.fillRect(rect, QGuiApplication::palette().base());
64 painter.drawPixmap(rect, m_pixmap);
65 }
66}
67
68void QShapedPixmapWindow::updateGeometry(const QPoint &pos)
69{
70 QSize size(1, 1);
71 if (!m_pixmap.isNull()) {
72 size = m_pixmap.deviceIndependentSize().toSize();
73 }
74 setGeometry(QRect(pos - m_hotSpot, size));
75}
76
77QT_END_NAMESPACE
78
79#include "moc_qshapedpixmapdndwindow_p.cpp"
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:33
Combined button and popup list for selecting options.