KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
qtwidgets/Window.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: SĂ©rgio Martins <sergio.martins@kdab.com>
6
7 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
8
9 Contact KDAB at <info@kdab.com> for commercial licensing options.
10*/
11
12
13#include "Window_p.h"
14#include "qtwidgets/views/ViewWrapper_p.h"
15
16#include <QWidget>
17#include <QVariant>
18#include <QWindow>
19#include <QDebug>
20
21using namespace KDDockWidgets;
22using namespace KDDockWidgets::QtWidgets;
23
24Window::~Window() = default;
25
27{
28 if (!topLevel->windowHandle())
29 topLevel->winId();
30
31 return topLevel->windowHandle();
32}
33
34Window::Window(QWidget *topLevel)
35 : QtCommon::Window(windowForWidget(topLevel))
36{
37 // QWidgetWindow is private API, we have no way for going from QWindow to the top-level QWidget
38 // So set it as a property
39 setProperty("kddockwidgets_qwidget", QVariant::fromValue<QWidget *>(topLevel));
40}
41
42std::shared_ptr<Core::View> Window::rootView() const
43{
44 if (!m_window)
45 return {};
46
47 if (auto widget = m_window->property("kddockwidgets_qwidget").value<QWidget *>())
48 return QtWidgets::ViewWrapper::create(widget);
49
50 qWarning() << Q_FUNC_INFO << "Window does not have a root";
51 return nullptr;
52}
53
54Core::Window::Ptr Window::transientParent() const
55{
56 if (QWindow *w = m_window->transientParent())
57 return Core::Window::Ptr(new QtWidgets::Window(w));
58
59 return nullptr;
60}
61
62void Window::setGeometry(QRect geo)
63{
64 if (auto v = rootView()) {
65 // In QWidget world QWidget interface is preferred over QWindow
66 v->setGeometry(geo);
67 } else {
68 // Go via QWindow instead
69 Window::setGeometry(geo);
70 }
71}
72
73void Window::setVisible(bool is)
74{
75 if (auto v = rootView()) {
76 // In QWidget world QWidget interface is preferred over QWindow
77 v->setVisible(is);
78 } else {
79 // Go via QWindow instead
80 Window::setVisible(is);
81 }
82}
83
84bool Window::supportsHonouringLayoutMinSize() const
85{
86 // QWidget's QLayout does this for us and propagates the min-size up to QWindow
87 return true;
88}
89
90void Window::destroy()
91{
92 if (auto v = rootView()) {
93 // deleting the QWidget deletes its QWindow
94 delete static_cast<QtWidgets::ViewWrapper *>(v.get())->widget();
95 } else {
96 Window::destroy();
97 }
98}
QWindow * windowForWidget(const QWidget *w)
Class to abstract QAction, so code still works with QtQuick and Flutter.
WId winId() const const
QWindow * windowHandle() const const

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDDockWidgets
Advanced Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets/
Generated by doxygen 1.9.8