KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
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/DockRegistry.h"
17#include "core/layouting/Item_p.h"
18
19#include <QDebug>
20#include <QTimer>
21
22using namespace KDDockWidgets;
23using namespace KDDockWidgets::QtQuick;
24
25namespace KDDockWidgets {
26class MainWindow::Private
27{
28public:
29 explicit Private(MainWindow *qq)
30 : q(qq)
31 {
32 }
33
34 void onLayoutGeometryUpdated()
35 {
36 const QSize minSz = q->minSize();
37 const bool mainWindowIsTooSmall = minSz.expandedTo(q->Core::View::size()) != q->Core::View::size();
38 if (mainWindowIsTooSmall) {
39 if (q->isRootView()) {
40 // If we're a top-level, let's go ahead and resize the QWindow
41 // any other case is too complex for QtQuick as there's no layout propagation.
42 q->window()->resize(minSz.width(), minSz.height());
43 }
44 }
45 }
46
47 MainWindow *const q;
48 QMetaObject::Connection layoutGeometryChangedConnection;
49};
50}
51
52
53MainWindow::MainWindow(const QString &uniqueName, MainWindowOptions options,
54 QQuickItem *parent, Qt::WindowFlags flags)
55 : View(new Core::MainWindow(this, uniqueName, options), Core::ViewType::MainWindow, parent,
56 flags)
57 , MainWindowViewInterface(static_cast<Core::MainWindow *>(View::controller()))
58 , d(new Private(this))
59{
60 m_mainWindow->init(uniqueName);
61 makeItemFillParent(this);
62
63 Core::Layout *lw = m_mainWindow->layout();
64 auto layoutView = asView_qtquick(lw->view());
65 makeItemFillParent(layoutView);
66
67 // MainWindowQuick has the same constraints as Layout, so just forward the signal
68 d->layoutGeometryChangedConnection = connect(layoutView, &View::geometryUpdated, this,
69 [this] {
70 Q_EMIT geometryUpdated();
71 d->onLayoutGeometryUpdated(); });
72
73 {
74 // This block silences a benign layouting constraints warning.
75 // During initialization, QtQuick will evaluate the width and height bindings separately,
76 // meaning our first Layout::setSize() might have height=0 still, as we're processing the
77 // width binding.
78
79 auto timer = new QTimer(this);
80 timer->setSingleShot(true);
81 timer->start();
82 Core::Item::s_silenceSanityChecks = true;
83 timer->callOnTimeout([] { Core::Item::s_silenceSanityChecks = false; });
84 }
85}
86
88{
89 // early disconnect to avoid rentrancy
90 disconnect(d->layoutGeometryChangedConnection);
91
92 if (isRootView()) {
93 if (auto window = this->window()) {
94 QObject::setParent(nullptr);
95 window->destroy();
96 }
97 }
98
99 delete d;
100}
101
103{
105}
106
108{
110}
111
113{
114 qDebug() << Q_FUNC_INFO << "SideBar hasn't been implemented yet";
115 return {};
116}
117
119{
120 qFatal("Not implemented");
121 return {};
122}
123
124// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
125void MainWindow::setContentsMargins(int left, int top, int right, int bottom)
126{
127 Q_UNUSED(left);
128 Q_UNUSED(right);
129 Q_UNUSED(top);
130 Q_UNUSED(bottom);
131 qDebug() << Q_FUNC_INFO << "not implemented";
132}
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:120
Size layoutMinimumSize() const
returns the layout's minimum size setLayoutMinimumSize
Definition Layout.cpp:115
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. .
bool isRootView() const override final
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.
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