Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5
6#include "qplatformwindow.h"
7
8#include <QtGui/QPainter>
9#include <QtGui/QCursor>
10#include <QtGui/QGuiApplication>
11#include <QtGui/QPalette>
12#include <QtGui/QBitmap>
13
15
26
30
32{
33 m_pixmap = pixmap;
34 if (!m_useCompositing) {
35 const QBitmap mask = m_pixmap.mask();
36 if (!mask.isNull()) {
37 if (!handle())
38 create();
39 if (auto platformWindow = handle()) {
40 const auto pixmapDpr = m_pixmap.devicePixelRatio();
41 const auto winDpr = devicePixelRatio();
42 const auto maskSize = (QSizeF(m_pixmap.size()) * winDpr / pixmapDpr).toSize();
43 platformWindow->setMask(QBitmap::fromPixmap(mask.scaled(maskSize)));
44 }
45 }
46 }
47}
48
50{
51 m_hotSpot = hotspot;
52}
53
55{
56 if (!m_pixmap.isNull()) {
57 const QRect rect(QPoint(0, 0), size());
58 QPainter painter(this);
59 if (m_useCompositing)
61 else
63 painter.drawPixmap(rect, m_pixmap);
64 }
65}
66
68{
69 QSize size(1, 1);
70 if (!m_pixmap.isNull()) {
71 size = m_pixmap.deviceIndependentSize().toSize();
72 }
73 setGeometry(QRect(pos - m_hotSpot, size));
74}
75
77
78#include "moc_qshapedpixmapdndwindow_p.cpp"
\inmodule QtGui
Definition qbitmap.h:16
static QBitmap fromPixmap(const QPixmap &pixmap)
Returns a copy of the given pixmap converted to a bitmap.
Definition qbitmap.cpp:234
static QPalette palette()
Returns the current application palette.
qreal devicePixelRatio() const
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
@ CompositionMode_Source
Definition qpainter.h:101
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
QSizeF deviceIndependentSize() const
Returns the size of the pixmap in device independent pixels.
Definition qpixmap.cpp:626
QSize size() const
Returns the size of the pixmap.
Definition qpixmap.cpp:493
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition qpixmap.cpp:456
QBitmap mask() const
Returns true if this pixmap has an alpha channel, or has a mask, otherwise returns false.
qreal devicePixelRatio() const
Returns the device pixel ratio for the pixmap.
Definition qpixmap.cpp:576
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QShapedPixmapWindow(QScreen *screen=nullptr)
void setHotspot(const QPoint &hotspot)
void updateGeometry(const QPoint &pos)
void paintEvent(QPaintEvent *) override
Handles paint events passed in the event parameter.
void setPixmap(const QPixmap &pixmap)
\inmodule QtCore
Definition qsize.h:208
constexpr QSize toSize() const noexcept
Returns an integer based copy of this size.
Definition qsize.h:401
\inmodule QtCore
Definition qsize.h:25
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
void setAlphaBufferSize(int size)
Set the desired size in bits of the alpha channel of the color buffer.
QSurfaceFormat format() const override
Returns the actual format of this window.
Definition qwindow.cpp:946
QSize size() const override
Returns the size of the window excluding any window frame.
Definition qwindow.h:210
void setGeometry(int posx, int posy, int w, int h)
Sets the geometry of the window, excluding its window frame, to a rectangle constructed from posx,...
Definition qwindow.cpp:1802
widget setFormat(format)
rect
[4]
Combined button and popup list for selecting options.
@ BypassWindowManagerHint
Definition qnamespace.h:223
@ FramelessWindowHint
Definition qnamespace.h:225
@ WindowDoesNotAcceptFocus
Definition qnamespace.h:236
@ WindowTransparentForInput
Definition qnamespace.h:234
GLuint64 GLenum void * handle
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLsizei GLsizei GLenum format
QScreen * screen
[1]
Definition main.cpp:29
static const uint base
Definition qurlidna.cpp:20
widget render & pixmap
QPainter painter(this)
[7]
view create()