Remove requirement to call QWindow::setMask after creating window

Like other QWindow properties we can just store it, and the platform
window should pick it up on creation like other properties.

[ChangeLog][QtGui][QWindow] setMask() no longer requires the window
to be created to have an effect; it can be set at any time.

Change-Id: I55b616363801b770bd61bda5325b443013b99866
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
This commit is contained in:
Tor Arne Vestbø 2017-06-14 11:52:09 +02:00
parent 84cc43413a
commit b0e4c8f427
5 changed files with 30 additions and 13 deletions

View File

@ -1062,15 +1062,12 @@ qreal QWindow::opacity() const
The window manager may or may not choose to display any areas of the window
not included in the mask, thus it is the application's responsibility to
clear to transparent the areas that are not part of the mask.
Setting the mask before the window has been created has no effect.
*/
void QWindow::setMask(const QRegion &region)
{
Q_D(QWindow);
if (!d->platformWindow)
return;
d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region, this));
if (d->platformWindow)
d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region, this));
d->mask = region;
}

View File

@ -54,6 +54,7 @@
#include <qpa/qwindowsysteminterface.h>
#include <qpa/qplatformscreen.h>
#include <QtGui/private/qcoregraphics_p.h>
#include <QtGui/private/qhighdpiscaling_p.h>
#include <AppKit/AppKit.h>
@ -764,7 +765,7 @@ void QCocoaWindow::setMask(const QRegion &region)
{
qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setMask" << window() << region;
if (isContentView())
m_view.window.backgroundColor = [NSColor clearColor];
m_view.window.backgroundColor = !region.isEmpty() ? [NSColor clearColor] : nil;
[qnsview_cast(m_view) setMaskRegion:&region];
m_view.window.opaque = isOpaque();
@ -1167,6 +1168,8 @@ void QCocoaWindow::recreateWindowIfNeeded()
if (!qFuzzyCompare(opacity, qreal(1.0)))
setOpacity(opacity);
setMask(QHighDpi::toNativeLocalRegion(window()->mask(), window()));
// top-level QWindows may have an attached NSToolBar, call
// update function which will attach to the NSWindow.
if (!parentWindow)

View File

@ -1093,6 +1093,9 @@ QWindowsWindow::QWindowsWindow(QWindow *aWindow, const QWindowsWindowData &data)
const qreal opacity = qt_window_private(aWindow)->opacity;
if (!qFuzzyCompare(opacity, qreal(1.0)))
setOpacity(opacity);
setMask(QHighDpi::toNativeLocalRegion(window()->mask(), window()));
if (aWindow->isTopLevel())
setWindowIcon(aWindow->icon());
clearFlag(WithinCreate);

View File

@ -600,6 +600,9 @@ void QXcbWindow::create()
const qreal opacity = qt_window_private(window())->opacity;
if (!qFuzzyCompare(opacity, qreal(1.0)))
setOpacity(opacity);
setMask(QHighDpi::toNativeLocalRegion(window()->mask(), window()));
if (window()->isTopLevel())
setWindowIcon(window()->icon());

View File

@ -1786,16 +1786,27 @@ void tst_QWindow::mask()
{
QRegion mask = QRect(10, 10, 800 - 20, 600 - 20);
QWindow window;
window.resize(800, 600);
window.setMask(mask);
{
QWindow window;
window.resize(800, 600);
QCOMPARE(window.mask(), QRegion());
QCOMPARE(window.mask(), QRegion());
window.create();
window.setMask(mask);
QCOMPARE(window.mask(), mask);
}
window.create();
window.setMask(mask);
{
QWindow window;
window.resize(800, 600);
QCOMPARE(window.mask(), QRegion());
window.setMask(mask);
QCOMPARE(window.mask(), mask);
window.create();
QCOMPARE(window.mask(), mask);
}
QCOMPARE(window.mask(), mask);
}
void tst_QWindow::initialSize()