KDDockWidgets API Documentation 1.7
Loading...
Searching...
No Matches
FrameworkWidgetFactory.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019-2023 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
13#include "Config.h"
14
15#include "private/Frame_p.h"
16#include "private/TitleBar_p.h"
17#include "private/multisplitter/Separator_p.h"
18#include "private/FloatingWindow_p.h"
19#include "private/indicators/ClassicIndicators_p.h"
20#include "private/indicators/NullIndicators_p.h"
21#include "private/Utils_p.h"
22#include "private/TabWidget_p.h"
23
24#ifdef KDDOCKWIDGETS_QTWIDGETS
25#include "private/widgets/FrameWidget_p.h"
26#include "private/widgets/TitleBarWidget_p.h"
27#include "private/widgets/TabBarWidget_p.h"
28#include "private/widgets/SideBarWidget_p.h"
29#include "private/widgets/TabWidgetWidget_p.h"
31#include "private/widgets/FloatingWindowWidget_p.h"
32#include "private/indicators/SegmentedIndicators_p.h"
33
34#include <QRubberBand>
35#include <QToolButton>
36#else
37#include "DockWidgetQuick.h"
38#include "private/quick/FrameQuick_p.h"
39#include "private/quick/TitleBarQuick_p.h"
40#include "private/quick/TabWidgetQuick_p.h"
41#include "private/quick/TabBarQuick_p.h"
42#include "private/quick/FloatingWindowQuick_p.h"
45#endif
46
47// clazy:excludeall=ctor-missing-parent-argument
48
49using namespace KDDockWidgets;
50
52
56
57#ifdef KDDOCKWIDGETS_QTWIDGETS
58Frame *DefaultWidgetFactory::createFrame(QWidgetOrQuick *parent, FrameOptions options) const
59{
60 return new FrameWidget(parent, options);
61}
62
63TitleBar *DefaultWidgetFactory::createTitleBar(Frame *frame) const
64{
65 return new TitleBarWidget(frame);
66}
67
68TitleBar *DefaultWidgetFactory::createTitleBar(FloatingWindow *fw) const
69{
70 return new TitleBarWidget(fw);
71}
72
73TabBar *DefaultWidgetFactory::createTabBar(TabWidget *parent) const
74{
75 return new TabBarWidget(parent);
76}
77
78TabWidget *DefaultWidgetFactory::createTabWidget(Frame *parent, TabWidgetOptions options) const
79{
80 return new TabWidgetWidget(parent, options);
81}
82
83Layouting::Separator *DefaultWidgetFactory::createSeparator(Layouting::Widget *parent) const
84{
86}
87
89 FloatingWindowFlags flags) const
90{
91 return new FloatingWindowWidget(QRect(), parent, flags);
92}
93
94FloatingWindow *DefaultWidgetFactory::createFloatingWindow(Frame *frame, MainWindowBase *parent, QRect suggestedGeometry) const
95{
97}
98
99DropIndicatorOverlayInterface *DefaultWidgetFactory::createDropIndicatorOverlay(DropArea *dropArea) const
100{
101#ifdef Q_OS_WASM
102 // On WASM windows don't support translucency, which is required for the classic indicators.
103 return new SegmentedIndicators(dropArea);
104#endif
105
106 switch (s_dropIndicatorType) {
108 return new ClassicIndicators(dropArea);
110 return new SegmentedIndicators(dropArea);
112 return new NullIndicators(dropArea);
113 }
114
115 return new ClassicIndicators(dropArea);
116}
117
122
124{
125 return new SideBarWidget(loc, parent);
126}
127
129{
130 if (!parent) {
131 qWarning() << Q_FUNC_INFO << "Parent not provided";
132 return nullptr;
133 }
134
135 auto button = new Button(parent);
136 button->setIcon(iconForButtonType(type, parent->devicePixelRatioF()));
137
138 return button;
139}
140
141#else
142
143Frame *DefaultWidgetFactory::createFrame(QWidgetOrQuick *parent, FrameOptions options) const
144{
145 return new FrameQuick(parent, options);
146}
147
148TitleBar *DefaultWidgetFactory::createTitleBar(Frame *frame) const
149{
150 return new TitleBarQuick(frame);
151}
152
153TitleBar *DefaultWidgetFactory::createTitleBar(FloatingWindow *fw) const
154{
155 return new TitleBarQuick(fw);
156}
157
158/*Separator *DefaultWidgetFactory::createSeparator(QWidgetAdapter *parent) const
159{
160 return new SeparatorQuick(parent);
161}*/
162
163FloatingWindow *DefaultWidgetFactory::createFloatingWindow(MainWindowBase *parent, FloatingWindowFlags flags) const
164{
165 return new FloatingWindowQuick(parent, flags);
166}
167
168FloatingWindow *DefaultWidgetFactory::createFloatingWindow(Frame *frame, MainWindowBase *parent, QRect suggestedGeometry) const
169{
170 return new FloatingWindowQuick(frame, suggestedGeometry, parent);
171}
172
173DropIndicatorOverlayInterface *DefaultWidgetFactory::createDropIndicatorOverlay(DropArea *dropArea) const
174{
175 switch (s_dropIndicatorType) {
177 return new ClassicIndicators(dropArea);
179 qWarning() << "Segmented indicators not supported for QtQuick yet";
180 return new NullIndicators(dropArea);
182 return new NullIndicators(dropArea);
183 }
184
185 return new ClassicIndicators(dropArea);
186}
187
188TabBar *DefaultWidgetFactory::createTabBar(TabWidget *parent) const
189{
190 return new TabBarQuick(parent);
191}
192
193TabWidget *DefaultWidgetFactory::createTabWidget(Frame *parent, TabWidgetOptions) const
194{
195 return new TabWidgetQuick(parent);
196}
197
198Layouting::Separator *DefaultWidgetFactory::createSeparator(Layouting::Widget *parent) const
199{
201}
202
204{
205 return new RubberBandQuick(parent);
206}
207
209{
210 Q_UNUSED(loc);
212
213 qWarning() << Q_FUNC_INFO << "Not implemented yet";
214 return nullptr;
215}
216
218{
219 return QUrl(QStringLiteral("qrc:/kddockwidgets/private/quick/qml/TitleBar.qml"));
220}
221
223{
224 return QUrl(QStringLiteral("qrc:/kddockwidgets/private/quick/qml/DockWidget.qml"));
225}
226
228{
229 return QUrl(QStringLiteral("qrc:/kddockwidgets/private/quick/qml/Frame.qml"));
230}
231
233{
234 return QUrl(QStringLiteral("qrc:/kddockwidgets/private/quick/qml/FloatingWindow.qml"));
235}
236
237#endif // QtQuick
238
239// iconForButtonType impl is the same for QtQuick and QtWidgets
241{
242 auto key = std::make_pair(type, dpr);
243 auto it = m_cachedIcons.constFind(key);
244 if (it != m_cachedIcons.cend())
245 return *it;
246
248 switch (type) {
250 iconName = QStringLiteral("auto-hide");
251 break;
253 iconName = QStringLiteral("unauto-hide");
254 break;
256 iconName = QStringLiteral("close");
257 break;
259 iconName = QStringLiteral("min");
260 break;
262 iconName = QStringLiteral("max");
263 break;
265 // We're using the same icon as dock/float
266 iconName = QStringLiteral("dock-float");
267 break;
269 iconName = QStringLiteral("dock-float");
270 break;
271 }
272
273 if (iconName.isEmpty())
274 return {};
275
276 QIcon icon(QStringLiteral(":/img/%1.png").arg(iconName));
277
278
280 m_cachedIcons.insert(key, icon);
281 return icon;
282 }
283
284 // Not using Qt's sugar syntax, which doesn't support 1.5x anyway when we need it.
285 // Simply add the high-res files and Qt will pick them when needed
286
288 icon.addFile(QStringLiteral(":/img/%1-1.5x.png").arg(iconName));
289
290 icon.addFile(QStringLiteral(":/img/%1-2x.png").arg(iconName));
291 m_cachedIcons.insert(key, icon);
292
293 return icon;
294}
295
297{
298 m_cachedIcons.clear();
299}
Application-wide config to tune certain behaviours of the framework.
Represents a dock widget.
A factory class for allowing the user to customize some internal widgets.
DropIndicatorOverlayInterface * createDropIndicatorOverlay(DropArea *) const override
Called internally by the framework to create a DropIndicatorOverlayInterface Override to provide your...
QIcon iconForButtonType(TitleBarButtonType type, qreal dpr) const override
Returns the icon to be used with the specified type.
Layouting::Separator * createSeparator(Layouting::Widget *parent=nullptr) const override
Called internally by the framework to create a Separator Override to provide your own Separator sub-c...
FloatingWindow * createFloatingWindow(MainWindowBase *parent=nullptr, FloatingWindowFlags=FloatingWindowFlag::FromGlobalConfig) const override
Called internally by the framework to create a FloatingWindow Override to provide your own FloatingWi...
SideBar * createSideBar(SideBarLocation loc, MainWindowBase *parent) const override
Called internally by the framework to create a SideBar.
TabBar * createTabBar(TabWidget *parent) const override
Called internally by the framework to create a TabBar Override to provide your own TabBar sub-class.
TabWidget * createTabWidget(Frame *parent, TabWidgetOptions=TabWidgetOption_None) const override
Called internally by the framework to create a TabWidget Override to provide your own TabWidget sub-c...
Frame * createFrame(QWidgetOrQuick *parent, FrameOptions) const override
Called internally by the framework to create a Frame class Override to provide your own Frame sub-cla...
TitleBar * createTitleBar(Frame *) const override
Called internally by the framework to create a TitleBar Override to provide your own TitleBar sub-cla...
QWidgetOrQuick * createRubberBand(QWidgetOrQuick *parent) const override
Called internally by the framework to create a RubberBand to show as drop zone Returns a rubber band.
QAbstractButton * createTitleBarButton(QWidget *parent, TitleBarButtonType) const override
Called internally by the framework to create a title bar button parent the button's parent.
virtual ~FrameworkWidgetFactory()
Destructor.Don't delete FrameworkWidgetFactory directly, it's owned by the framework.
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
An abstraction/wrapper around QWidget, QtQuickItem or anything else.
Definition Widget.h:77
SideBarLocation
Each main window supports 4 sidebars.
TitleBarButtonType
describes a type of button you can have in the title bar
@ None
Don't show any drop indicators while dragging.
@ Segmented
Segmented indicators.
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)
QObject * parent() const const
T qobject_cast(QObject *object)
bool isEmpty() const const

© 2019-2023 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 on Wed Nov 1 2023 00:02:31 for KDDockWidgets API Documentation by doxygen 1.9.8