KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
qtwidgets/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#include "Action_p.h"
15
16#include "core/Utils_p.h"
17
18#include "kddockwidgets/core/TabBar.h"
19#include "kddockwidgets/core/Stack.h"
20#include "kddockwidgets/core/FloatingWindow.h"
21#include "kddockwidgets/core/indicators/ClassicDropIndicatorOverlay.h"
22#include "kddockwidgets/core/indicators/NullDropIndicatorOverlay.h"
23#include "kddockwidgets/core/indicators/SegmentedDropIndicatorOverlay.h"
24#include "kddockwidgets/core/MainWindow.h"
25#include "kddockwidgets/core/views/ClassicIndicatorWindowViewInterface.h"
26
42
43#include <QToolButton>
44
45
46// clazy:excludeall=ctor-missing-parent-argument
47
48using namespace KDDockWidgets;
49using namespace KDDockWidgets::QtWidgets;
50
51
55
56Core::View *ViewFactory::createDockWidget(const QString &uniqueName, DockWidgetOptions options,
57 LayoutSaverOptions layoutSaverOptions,
58 Qt::WindowFlags windowFlags) const
59{
60 return new QtWidgets::DockWidget(uniqueName, options, layoutSaverOptions, windowFlags);
61}
62
63
65 Core::View *parent = nullptr) const
66{
67 return new QtWidgets::Group(controller, QtCommon::View_qt::asQWidget(parent));
68}
69
71{
72 return new QtWidgets::TitleBar(titleBar, parent);
73}
74
76{
77 return new QtWidgets::TabBar(tabBar, QtCommon::View_qt::asQWidget(parent));
78}
79
81{
82 return new QtWidgets::Stack(controller, QtCommon::View_qt::asQWidget(parent));
83}
84
86{
87 return new QtWidgets::Separator(controller, parent);
88}
89
91 Core::MainWindow *parent,
92 Qt::WindowFlags windowFlags) const
93{
94 auto mainwindow =
95 qobject_cast<QMainWindow *>(QtCommon::View_qt::asQWidget(parent ? parent->view() : nullptr));
96 return new QtWidgets::FloatingWindow(controller, mainwindow, windowFlags);
97}
98
100{
101 return new QtWidgets::RubberBand(QtCommon::View_qt::asQWidget(parent));
102}
103
105{
106 return new QtWidgets::SideBar(controller, QtCommon::View_qt::asQWidget(parent));
107}
108
110 TitleBarButtonType type) const
111{
112 if (!parent) {
113 qWarning() << Q_FUNC_INFO << "Parent not provided";
114 return nullptr;
115 }
116
117 auto button = new QtWidgets::Button(parent);
118 button->setIcon(iconForButtonType(type, parent->devicePixelRatioF()));
119
120 return button;
121}
122
123// iconForButtonType impl is the same for QtQuick and QtWidgets
125{
126 auto key = std::make_pair(type, dpr);
127 auto it = m_cachedIcons.constFind(key);
128 if (it != m_cachedIcons.cend())
129 return *it;
130
132 switch (type) {
134 iconName = QStringLiteral("auto-hide");
135 break;
137 iconName = QStringLiteral("unauto-hide");
138 break;
140 iconName = QStringLiteral("close");
141 break;
143 iconName = QStringLiteral("min");
144 break;
146 iconName = QStringLiteral("max");
147 break;
149 // We're using the same icon as dock/float
150 iconName = QStringLiteral("dock-float");
151 break;
153 iconName = QStringLiteral("dock-float");
154 break;
156 break;
157 }
158
159 if (iconName.isEmpty())
160 return {};
161
162 QIcon icon(QStringLiteral(":/img/%1.png").arg(iconName));
163 if (!scalingFactorIsSupported(dpr)) {
164 m_cachedIcons.insert(key, icon);
165 return icon;
166 }
167
168 // Not using Qt's sugar syntax, which doesn't support 1.5x anyway when we need it.
169 // Simply add the high-res files and Qt will pick them when needed
170
171 if (scalingFactorIsSupported(1.5))
172 icon.addFile(QStringLiteral(":/img/%1-1.5x.png").arg(iconName));
173
174 icon.addFile(QStringLiteral(":/img/%1-2x.png").arg(iconName));
175 m_cachedIcons.insert(key, icon);
176
177 return icon;
178}
179
181{
182 return new QtWidgets::DropArea(controller, parent);
183}
184
186{
187 return new QtWidgets::MDILayout(controller, parent);
188}
189
191 Core::SegmentedDropIndicatorOverlay *controller, Core::View *parent) const
192{
193 return new QtWidgets::SegmentedDropIndicatorOverlay(controller,
194 QtCommon::View_qt::asQWidget(parent));
195}
196
198 Core::ClassicDropIndicatorOverlay *classicIndicators, Core::View *parent) const
199{
200 Q_UNUSED(parent);
201 return new QtWidgets::IndicatorWindow(classicIndicators);
202}
203
205{
206 m_cachedIcons.clear();
207}
208
210{
211 return new QtWidgets::Action(dw, debugName);
212}
Application-wide config to tune certain behaviours of the framework.
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...
Button widget to be used in the TitleBar. These are the KDDockWidget default buttons....
Core::ClassicIndicatorWindowViewInterface * createClassicIndicatorWindow(Core::ClassicDropIndicatorOverlay *, Core::View *parent) const override
Creates the window that will show the actual drop indicators. They need a higher z-order,...
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.
QAbstractButton * createTitleBarButton(QWidget *parent, TitleBarButtonType) const
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::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...
Core::View * createMDILayout(Core::MDILayout *, Core::View *parent) const override
Called by the framework to create a MDI Layout view.
Core::View * createDockWidget(const QString &uniqueName, DockWidgetOptions={}, LayoutSaverOptions={}, Qt::WindowFlags={}) const override
Creates a dock widget. This is only used by MainWindow's persistent widget feature....
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)
QMap::const_iterator cend() const const
void clear()
QMap::const_iterator constFind(const Key &key) const const
QMap::iterator insert(const Key &key, const T &value)
qreal devicePixelRatioF() const const
bool isEmpty() const const
typedef WindowFlags
A factory class for allowing the user to customize some internal widgets.
Represents a dock widget.
A MultiSplitter with support for drop indicators when hovering over.
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