KDDockWidgets API Documentation 2.1
Loading...
Searching...
No Matches
qtquick/Window.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2020 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#include "Window_p.h"
13#include "views/View.h"
14
15#include <QWindow>
16#include <QQuickWindow>
17#include <QDebug>
18
19using namespace KDDockWidgets;
20using namespace KDDockWidgets::QtQuick;
21
22Window::~Window()
23{
24}
25
26inline Core::View *topMostKDDWView(QQuickItem *parent)
27{
28 if (!parent)
29 return {};
30
31 if (auto v = qobject_cast<QtQuick::View *>(parent))
32 return v;
33
34 const auto children = parent->childItems();
35 for (QQuickItem *item : children) {
36 if (auto v = topMostKDDWView(item))
37 return v;
38 }
39
40 return nullptr;
41}
42
43std::shared_ptr<Core::View> Window::rootView() const
44{
45 if (auto quickwindow = qobject_cast<QQuickWindow *>(m_window)) {
46 auto contentItem = quickwindow->contentItem();
47 if (Core::View *view = topMostKDDWView(contentItem)) {
48 // This block is for retrocompatibility with 1.x. For QtQuick the topmost "widget" is a
49 // KDDW known widget and not any arbitrary user QtQuickItem.
50 return view->asWrapper();
51 } else {
52 const auto children = contentItem->childItems();
53 Q_ASSERT(!children.isEmpty());
54 return QtQuick::View::asQQuickWrapper(children.first());
55 }
56 } else {
57 qWarning() << Q_FUNC_INFO << "Expected QQuickView";
58 }
59
60 qWarning() << Q_FUNC_INFO << "Window does not have a root";
61 return {};
62}
63
64Core::Window::Ptr Window::transientParent() const
65{
66 if (QWindow *w = m_window->transientParent())
67 return Core::Window::Ptr(new Window(w));
68
69 return nullptr;
70}
71
72void Window::setVisible(bool is)
73{
74 QtCommon::Window::setVisible(is);
75 if (auto root = rootView())
76 root->setVisible(is);
77}
78
79bool Window::supportsHonouringLayoutMinSize() const
80{
81 // If this method returns true, then Item.cpp will be strict and issue qWarnings
82 // whenever the window is resized lower than the layout's min-size.
83
84 if (auto view = rootView()) {
85 // For floating window we have full control. While for anything else we don't know the
86 // disposition of the users main.qml
87 return view->is(Core::ViewType::FloatingWindow);
88 }
89
90 return false;
91}
virtual std::shared_ptr< View > asWrapper()=0
Returns this view, but as a wrapper.
static std::shared_ptr< Core::View > asQQuickWrapper(QQuickItem *item)
Class to abstract QAction, so code still works with QtQuick and Flutter.
Core::View * topMostKDDWView(QQuickItem *parent)

© 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