Unity 8
WindowMargins.cpp
1 /*
2  * Copyright (C) 2017 Canonical, Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 3, as published by
6  * the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10  * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #include "WindowMargins.h"
18 
19 #include <QGuiApplication>
20 #include <QQuickWindow>
21 #include <qpa/qplatformnativeinterface.h>
22 
23 void WindowMargins::setNormal(QRectF value)
24 {
25  if (m_normal == value) {
26  return;
27  }
28 
29  m_normal = value;
30 
31  if (window()) {
32  QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
33  nativeInterface->setWindowProperty(window()->handle(), "normalWindowMargins", QVariant(m_normal.toRect()));
34  }
35 
36  Q_EMIT normalChanged();
37 }
38 
39 QRectF WindowMargins::normal() const
40 {
41  return m_normal;
42 }
43 
44 void WindowMargins::setDialog(QRectF value)
45 {
46  if (m_dialog == value) {
47  return;
48  }
49 
50  m_dialog = value;
51 
52  if (window()) {
53  QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
54  nativeInterface->setWindowProperty(window()->handle(), "dialogWindowMargins", QVariant(m_dialog.toRect()));
55  }
56 
57  Q_EMIT dialogChanged();
58 }
59 
60 QRectF WindowMargins::dialog() const
61 {
62  return m_dialog;
63 }
64 
65 void WindowMargins::itemChange(ItemChange change, const ItemChangeData &data)
66 {
67  if (change == ItemSceneChange && data.window != nullptr) {
68  QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
69  if (!m_normal.isNull()) {
70  nativeInterface->setWindowProperty(data.window->handle(), "normalWindowMargins", QVariant(m_normal.toRect()));
71  nativeInterface->setWindowProperty(data.window->handle(), "dialogWindowMargins", QVariant(m_dialog.toRect()));
72  }
73  }
74 }