KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
qtquick/ViewFactory.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 "ViewFactory.h"
13#include "Config.h"
14
15#include "kddockwidgets/core/indicators/ClassicDropIndicatorOverlay.h"
16#include "kddockwidgets/core/indicators/NullDropIndicatorOverlay.h"
17#include "kddockwidgets/core/indicators/SegmentedDropIndicatorOverlay.h"
18#include "core/Utils_p.h"
19
20#include "kddockwidgets/core/MainWindow.h"
21#include "kddockwidgets/core/TabBar.h"
22#include "kddockwidgets/core/Stack.h"
23#include "kddockwidgets/core/FloatingWindow.h"
24
25#include "qtquick/Action.h"
29#include "qtquick/views/Group.h"
30#include "qtquick/views/View.h"
35// #include "qtquick/views/SideBar.h"
36#include "qtquick/views/Stack.h"
40
41#include "views/ClassicIndicatorsWindow.h"
42
43// clazy:excludeall=ctor-missing-parent-argument
44
45using namespace KDDockWidgets;
46using namespace KDDockWidgets::QtQuick;
47
48
52
53Core::View *ViewFactory::createDockWidget(const QString &uniqueName, DockWidgetOptions options,
54 LayoutSaverOptions layoutSaverOptions,
55 Qt::WindowFlags windowFlags) const
56{
57 return createDockWidget(uniqueName, /*engine=*/nullptr, options, layoutSaverOptions,
58 windowFlags);
59}
60
61Core::View *ViewFactory::createDockWidget(const QString &uniqueName, QQmlEngine *qmlEngine,
62 DockWidgetOptions options,
63 LayoutSaverOptions layoutSaverOptions,
64 Qt::WindowFlags windowFlags) const
65{
66 return new QtQuick::DockWidget(uniqueName, options, layoutSaverOptions, windowFlags,
67 qmlEngine);
68}
69
71{
72 return new Group(controller, QtQuick::asQQuickItem(parent));
73}
74
76{
77 return new TitleBar(titleBar, QtQuick::asQQuickItem(parent));
78}
79
81{
82 return new TabBar(controller, QtQuick::asQQuickItem(parent));
83}
84
86{
87 return new Stack(controller, QtQuick::asQQuickItem(parent));
88}
89
91{
92 return new Separator(
93 controller, parent ? static_cast<QtQuick::View *>(parent) : nullptr);
94}
95
97 Core::MainWindow *parent,
98 Qt::WindowFlags flags) const
99{
100
101 auto mainwindow = parent
102 ? qobject_cast<QtQuick::MainWindow *>(QtQuick::asQQuickItem(parent->view()))
103 : nullptr;
104 return new FloatingWindow(controller, mainwindow, flags);
105}
106
108{
109 return new RubberBand(QtQuick::asQQuickItem(parent));
110}
111
113{
114 return {};
115}
116
117// iconForButtonType impl is the same for QtQuick and QtWidgets
119{
121 switch (type) {
123 iconName = QStringLiteral("auto-hide");
124 break;
126 iconName = QStringLiteral("unauto-hide");
127 break;
129 iconName = QStringLiteral("close");
130 break;
132 iconName = QStringLiteral("min");
133 break;
135 iconName = QStringLiteral("max");
136 break;
138 // We're using the same icon as dock/float
139 iconName = QStringLiteral("dock-float");
140 break;
142 iconName = QStringLiteral("dock-float");
143 break;
145 break;
146 }
147
148 if (iconName.isEmpty())
149 return {};
150
151 QIcon icon(QStringLiteral(":/img/%1.png").arg(iconName));
152 if (!scalingFactorIsSupported(dpr))
153 return icon;
154
155 // Not using Qt's sugar syntax, which doesn't support 1.5x anyway when we need it.
156 // Simply add the high-res files and Qt will pick them when needed
157
158 if (scalingFactorIsSupported(1.5))
159 icon.addFile(QStringLiteral(":/img/%1-1.5x.png").arg(iconName));
160
161 icon.addFile(QStringLiteral(":/img/%1-2x.png").arg(iconName));
162
163 return icon;
164}
165
167{
168 return new DropArea(controller, parent);
169}
170
172{
173 return new MDILayout(controller, parent);
174}
175
177{
178 return QUrl(QStringLiteral("qrc:/kddockwidgets/qtquick/views/qml/TitleBar.qml"));
179}
180
182{
183 return QUrl(QStringLiteral("qrc:/kddockwidgets/qtquick/views/qml/DockWidget.qml"));
184}
185
187{
188 return QUrl(QStringLiteral("qrc:/kddockwidgets/qtquick/views/qml/Group.qml"));
189}
190
192{
193 return QUrl(QStringLiteral("qrc:/kddockwidgets/qtquick/views/qml/FloatingWindow.qml"));
194}
195
197{
198 return QUrl(QStringLiteral("qrc:/kddockwidgets/qtquick/views/qml/TabBar.qml"));
199}
200
202{
203 return QUrl(QStringLiteral("qrc:/kddockwidgets/qtquick/views/qml/Separator.qml"));
204}
205
212
218
220{
221 auto factory = qobject_cast<ViewFactory *>(Config::self().viewFactory());
222
223 if (!factory)
224 qWarning() << Q_FUNC_INFO << "Expected a ViewFactory subclass, not"
226
227 return factory;
228}
229
231{
232 return new QtQuick::Action(dw, debugName);
233}
Application-wide config to tune certain behaviours of the framework.
Core::ViewFactory * viewFactory() const
getter for the framework view factory
Definition Config.cpp:182
static Config & self()
returns the singleton Config instance
Definition Config.cpp:88
The window that will hold the classic indicators This is a window so it can be over the window that i...
View * view() const
Returns the view associated with this controller, if any.
The DockWidget base-class. DockWidget and Core::DockWidget are only split in two so we can share some...
The MDILayout class implements a layout suitable for MDI style docking. Where dock widgets are free t...
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
The default ViewFactory for QtQuick frontend.
Core::View * createGroup(Core::Group *, Core::View *parent) const override
Called by the framework to create a Frame view Override to provide your own Frame sub-class....
Core::View * createTabBar(Core::TabBar *tabBar, Core::View *parent) const override
Called by the framework to create a TabBar view Override to provide your own TabBar sub-class.
virtual Q_INVOKABLE QUrl titleBarFilename() const
Called by QML.
virtual QUrl dockwidgetFilename() const
Called by C++.
Core::View * createDockWidget(const QString &uniqueName, DockWidgetOptions options={}, LayoutSaverOptions layoutSaverOptions={}, Qt::WindowFlags windowFlags={}) const override
Creates a dock widget. This is only used by MainWindow's persistent widget feature....
Core::View * createSeparator(Core::Separator *, Core::View *parent=nullptr) const override
Called by the framework to create a Separator view Override to provide your own Separator sub-class....
Core::View * createStack(Core::Stack *, Core::View *parent) const override
Called by the framework to create a Stack view Override to provide your own Stack sub-class.
~ViewFactory() override
Destructor. Don't delete ViewFactory directly, it's owned by the framework.
KDDockWidgets::Core::Action * createAction(Core::DockWidget *, const char *debugName) const override
Creates a QAction if QtWidgets, or an equivalent fallback if QtQuick/Flutter Not needed to be overrid...
Core::View * createDropArea(Core::DropArea *, Core::View *parent) const override
Called by the framework to create a DropArea view.
Core::View * createTitleBar(Core::TitleBar *, Core::View *parent) const override
Called by the framework to create a TitleBar view Override to provide your own TitleBar sub-class....
Core::View * createSideBar(Core::SideBar *, Core::View *parent) const override
Called by the framework to create a SideBar view.
QIcon iconForButtonType(TitleBarButtonType type, qreal dpr) const override
Core::View * createSegmentedDropIndicatorOverlayView(Core::SegmentedDropIndicatorOverlay *controller, Core::View *parent) const override
Creates the view that will parent the segmented drop indicators.
Core::View * createRubberBand(Core::View *parent) const override
Called by the framework to create a RubberBand view to show as drop zone.
Core::ClassicIndicatorWindowViewInterface * createClassicIndicatorWindow(Core::ClassicDropIndicatorOverlay *, Core::View *parent=nullptr) const override
Creates the window that will show the actual drop indicators. They need a higher z-order,...
Core::View * createFloatingWindow(Core::FloatingWindow *, Core::MainWindow *parent=nullptr, Qt::WindowFlags windowFlags={}) const override
Called by the framework to create a FloatingWindow view Override to provide your own FloatingWindow s...
virtual Q_INVOKABLE QUrl tabbarFilename() const
Core::View * createMDILayout(Core::MDILayout *, Core::View *parent) const override
Called by the framework to create a MDI Layout view.
QQuickItem * asQQuickItem(Core::View *view)
Class to abstract QAction, so code still works with QtQuick and Flutter.
TitleBarButtonType
describes a type of button you can have in the title bar
static QString iconName(DropLocation loc, bool active)
void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)
bool isEmpty() const const
typedef WindowFlags
Represents a dock widget.
The QQuickItem counter part of TabWidgetQuick. Handles GUI while TabWidget handles state.
Implements a QTabWidget derived class with support for docking and undocking KDockWidget::DockWidget ...
A factory class for allowing the user to customize some internal widgets.

© 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