KDDockWidgets API Documentation 2.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages Concepts
qtquick/views/MainWindow.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#include "MainWindow.h"
13#include "core/Layout.h"
14#include "core/MainWindow.h"
15#include "core/Window_p.h"
16#include "core/Logging_p.h"
17#include "core/DockRegistry.h"
18#include "core/layouting/Item_p.h"
19
20#include "kddockwidgets/qtquick/Platform.h"
21#include "kddockwidgets/qtquick/views/View.h"
22
23#include <QQuickItem>
24#include <QDebug>
25#include <QTimer>
26
27using namespace KDDockWidgets;
28using namespace KDDockWidgets::QtQuick;
29
30namespace KDDockWidgets {
31class MainWindow::Private
32{
33public:
34 explicit Private(MainWindow *qq)
35 : q(qq)
36 {
37 }
38
39 void onLayoutGeometryUpdated()
40 {
41 const QSize minSz = q->minSize();
42 const bool mainWindowIsTooSmall = minSz.expandedTo(q->Core::View::size()) != q->Core::View::size();
43 if (mainWindowIsTooSmall) {
44 if (q->isRootView()) {
45 // If we're a top-level, let's go ahead and resize the QWindow
46 // any other case is too complex for QtQuick as there's no layout propagation.
47 q->window()->resize(minSz.width(), minSz.height());
48 }
49 }
50 }
51
52 MainWindow *const q;
53 QMetaObject::Connection layoutGeometryChangedConnection;
54};
55}
56
57
58MainWindow::MainWindow(const QString &uniqueName, MainWindowOptions options,
59 QQuickItem *parent, Qt::WindowFlags flags)
60 : View(new Core::MainWindow(this, uniqueName, options), Core::ViewType::MainWindow, parent,
61 flags)
62 , MainWindowViewInterface(static_cast<Core::MainWindow *>(View::controller()))
63 , d(new Private(this))
64{
65 m_mainWindow->init(uniqueName);
66 makeItemFillParent(this);
67
68 Core::Layout *lw = m_mainWindow->layout();
69 auto layoutView = asView_qtquick(lw->view());
70 makeItemFillParent(layoutView);
71
72 // MainWindowQuick has the same constraints as Layout, so just forward the signal
73 d->layoutGeometryChangedConnection = connect(layoutView, &View::geometryUpdated, this,
74 [this] {
75 Q_EMIT geometryUpdated();
76 d->onLayoutGeometryUpdated(); });
77
78 {
79 // This block silences a benign layouting constraints warning.
80 // During initialization, QtQuick will evaluate the width and height bindings separately,
81 // meaning our first Layout::setSize() might have height=0 still, as we're processing the
82 // width binding.
83
84 auto timer = new QTimer(this);
85 timer->setSingleShot(true);
86 timer->start();
87 Core::Item::s_silenceSanityChecks = true;
88 timer->callOnTimeout([] { Core::Item::s_silenceSanityChecks = false; });
89 }
90}
91
93{
94 // early disconnect to avoid rentrancy
95 disconnect(d->layoutGeometryChangedConnection);
96
97 if (isRootView()) {
98 if (auto window = this->window()) {
99 QObject::setParent(nullptr);
100 window->destroy();
101 }
102 }
103
104 delete d;
105}
106
108{
110}
111
113{
115}
116
118{
119 qDebug() << Q_FUNC_INFO << "SideBar hasn't been implemented yet";
120 return {};
121}
122
124{
125 qFatal("Not implemented");
126 return {};
127}
128
129// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
130void MainWindow::setContentsMargins(int left, int top, int right, int bottom)
131{
132 Q_UNUSED(left);
133 Q_UNUSED(right);
134 Q_UNUSED(top);
135 Q_UNUSED(bottom);
136 qDebug() << Q_FUNC_INFO << "not implemented";
137}
138
139void MainWindow::setPersistentCentralView(const QString &qmlFilename)
140{
141 QQuickItem *guest = QtQuick::View::createItem(plat()->qmlEngine(), qmlFilename);
142 if (guest) {
143 // kddw deals in Core::View, so put it inside one
144 auto wrapper = QtQuick::View::asQQuickWrapper(guest);
146 } else {
147 KDDW_ERROR("setPersistentCentralView: Failed to create item for {}", qmlFilename);
148 }
149}
A widget that supports an arbitrary number of splitters (called Separators) in any combination of ver...
View * view() const
Returns the view associated with this controller, if any.
The widget (QWidget or QQuickItem) which holds a layout of dock widgets.
Definition Layout.h:57
Size layoutMaximumSizeHint() const
returns the layout's maximum size hint
Definition Layout.cpp:117
Size layoutMinimumSize() const
returns the layout's minimum size setLayoutMinimumSize
Definition Layout.cpp:112
void setPersistentCentralView(std::shared_ptr< View > widget)
Sets a persistent central widget. It can't be detached.
A docking area for dock widgets Named MainWindow as it's the QtWidgets/QMainWindow counterpart....
QSize maxSizeHint() const override
Reimplemented for internal purposes. .
MainWindow(const QString &uniqueName, MainWindowOptions options={}, QQuickItem *parent=nullptr, Qt::WindowFlags flags={})
Constructor. Use it as you would use QMainWindow.
QRect centralAreaGeometry() const override
QMargins centerWidgetMargins() const override
void setContentsMargins(int left, int top, int right, int bottom) override
QSize minSize() const override
Reimplemented for internal purposes. .
void setPersistentCentralView(const QString &qmlFilename)
static QQuickItem * createItem(QQmlEngine *engine, const QString &filename, QQmlContext *context=nullptr)
Convenience to create a QQuickItem.
bool isRootView() const override final
static std::shared_ptr< Core::View > asQQuickWrapper(QQuickItem *item)
std::shared_ptr< Core::Window > window() const override
Returns the window this view is inside For the Qt frontend, this wraps a QWindow. Like QWidget::windo...
The MainWindow base-class that's shared between QtWidgets and QtQuick stack.
ViewType
Each View type also has a specific Controller associated with, except for ViewType::None.
Definition Controller.h:26
View * asView_qtquick(Core::View *view)
Class to abstract QAction, so code still works with QtQuick and Flutter.
QtQuick::Platform * plat()
void connect(T &&future, QObjectSubclass *context, Callback func)
Definition qcorotask.h:721
void setParent(QObject *parent)
QSize expandedTo(const QSize &otherSize) const const
int height() const const
int width() const const
typedef WindowFlags
QMainWindow sub-class to enable KDDockWidgets support.

© 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