KDDockWidgets API Documentation  1.5
FrameworkWidgetFactory.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KDDockWidgets.
3 
4  SPDX-FileCopyrightText: 2019-2022 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 "FrameworkWidgetFactory.h"
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 
49 using namespace KDDockWidgets;
50 
52 
54 {
55 }
56 
57 #ifdef KDDOCKWIDGETS_QTWIDGETS
58 Frame *DefaultWidgetFactory::createFrame(QWidgetOrQuick *parent, FrameOptions options) const
59 {
60  return new FrameWidget(parent, options);
61 }
62 
63 TitleBar *DefaultWidgetFactory::createTitleBar(Frame *frame) const
64 {
65  return new TitleBarWidget(frame);
66 }
67 
68 TitleBar *DefaultWidgetFactory::createTitleBar(FloatingWindow *fw) const
69 {
70  return new TitleBarWidget(fw);
71 }
72 
73 TabBar *DefaultWidgetFactory::createTabBar(TabWidget *parent) const
74 {
75  return new TabBarWidget(parent);
76 }
77 
78 TabWidget *DefaultWidgetFactory::createTabWidget(Frame *parent) const
79 {
80  return new TabWidgetWidget(parent);
81 }
82 
83 Layouting::Separator *DefaultWidgetFactory::createSeparator(Layouting::Widget *parent) const
84 {
86 }
87 
89 {
90  return new FloatingWindowWidget(QRect(), parent);
91 }
92 
93 FloatingWindow *DefaultWidgetFactory::createFloatingWindow(Frame *frame, MainWindowBase *parent, QRect suggestedGeometry) const
94 {
95  return new FloatingWindowWidget(frame, suggestedGeometry, parent);
96 }
97 
98 DropIndicatorOverlayInterface *DefaultWidgetFactory::createDropIndicatorOverlay(DropArea *dropArea) const
99 {
100 #ifdef Q_OS_WASM
101  // On WASM windows don't support translucency, which is required for the classic indicators.
102  return new SegmentedIndicators(dropArea);
103 #endif
104 
105  switch (s_dropIndicatorType) {
106  case DropIndicatorType::Classic:
107  return new ClassicIndicators(dropArea);
108  case DropIndicatorType::Segmented:
109  return new SegmentedIndicators(dropArea);
111  return new NullIndicators(dropArea);
112  }
113 
114  return new ClassicIndicators(dropArea);
115 }
116 
118 {
120 }
121 
123 {
124  return new SideBarWidget(loc, parent);
125 }
126 
128 {
129  if (!parent) {
130  qWarning() << Q_FUNC_INFO << "Parent not provided";
131  return nullptr;
132  }
133 
134  auto button = new Button(parent);
135  button->setIcon(iconForButtonType(type, parent->devicePixelRatioF()));
136 
137  return button;
138 }
139 
140 #else
141 
142 Frame *DefaultWidgetFactory::createFrame(QWidgetOrQuick *parent, FrameOptions options) const
143 {
144  return new FrameQuick(parent, options);
145 }
146 
147 TitleBar *DefaultWidgetFactory::createTitleBar(Frame *frame) const
148 {
149  return new TitleBarQuick(frame);
150 }
151 
152 TitleBar *DefaultWidgetFactory::createTitleBar(FloatingWindow *fw) const
153 {
154  return new TitleBarQuick(fw);
155 }
156 
157 /*Separator *DefaultWidgetFactory::createSeparator(QWidgetAdapter *parent) const
158 {
159  return new SeparatorQuick(parent);
160 }*/
161 
162 FloatingWindow *DefaultWidgetFactory::createFloatingWindow(MainWindowBase *parent) const
163 {
164  return new FloatingWindowQuick(parent);
165 }
166 
167 FloatingWindow *DefaultWidgetFactory::createFloatingWindow(Frame *frame, MainWindowBase *parent, QRect suggestedGeometry) const
168 {
169  return new FloatingWindowQuick(frame, suggestedGeometry, parent);
170 }
171 
172 DropIndicatorOverlayInterface *DefaultWidgetFactory::createDropIndicatorOverlay(DropArea *dropArea) const
173 {
174  switch (s_dropIndicatorType) {
175  case DropIndicatorType::Classic:
176  return new ClassicIndicators(dropArea);
177  case DropIndicatorType::Segmented:
178  qWarning() << "Segmented indicators not supported for QtQuick yet";
179  return new NullIndicators(dropArea);
181  return new NullIndicators(dropArea);
182  }
183 
184  return new ClassicIndicators(dropArea);
185 }
186 
187 TabBar *DefaultWidgetFactory::createTabBar(TabWidget *parent) const
188 {
189  return new TabBarQuick(parent);
190 }
191 
192 TabWidget *DefaultWidgetFactory::createTabWidget(Frame *parent) const
193 {
194  return new TabWidgetQuick(parent);
195 }
196 
197 Layouting::Separator *DefaultWidgetFactory::createSeparator(Layouting::Widget *parent) const
198 {
199  return new Layouting::SeparatorQuick(parent);
200 }
201 
203 {
204  return new RubberBandQuick(parent);
205 }
206 
208 {
209  Q_UNUSED(loc);
210  Q_UNUSED(parent);
211 
212  qWarning() << Q_FUNC_INFO << "Not implemented yet";
213  return nullptr;
214 }
215 
216 QUrl DefaultWidgetFactory::titleBarFilename() const
217 {
218  return QUrl(QStringLiteral("qrc:/kddockwidgets/private/quick/qml/TitleBar.qml"));
219 }
220 
221 QUrl DefaultWidgetFactory::dockwidgetFilename() const
222 {
223  return QUrl(QStringLiteral("qrc:/kddockwidgets/private/quick/qml/DockWidget.qml"));
224 }
225 
226 QUrl DefaultWidgetFactory::frameFilename() const
227 {
228  return QUrl(QStringLiteral("qrc:/kddockwidgets/private/quick/qml/Frame.qml"));
229 }
230 
231 QUrl DefaultWidgetFactory::floatingWindowFilename() const
232 {
233  return QUrl(QStringLiteral("qrc:/kddockwidgets/private/quick/qml/FloatingWindow.qml"));
234 }
235 
236 #endif // QtQuick
237 
238 // iconForButtonType impl is the same for QtQuick and QtWidgets
240 {
242  switch (type) {
243  case TitleBarButtonType::AutoHide:
244  iconName = QStringLiteral("auto-hide");
245  break;
247  iconName = QStringLiteral("unauto-hide");
248  break;
250  iconName = QStringLiteral("close");
251  break;
252  case TitleBarButtonType::Minimize:
253  iconName = QStringLiteral("min");
254  break;
255  case TitleBarButtonType::Maximize:
256  iconName = QStringLiteral("max");
257  break;
259  // We're using the same icon as dock/float
260  iconName = QStringLiteral("dock-float");
261  break;
263  iconName = QStringLiteral("dock-float");
264  break;
265  }
266 
267  if (iconName.isEmpty())
268  return {};
269 
270  QIcon icon(QStringLiteral(":/img/%1.png").arg(iconName));
271  if (!scalingFactorIsSupported(dpr))
272  return icon;
273 
274  // Not using Qt's sugar syntax, which doesn't support 1.5x anyway when we need it.
275  // Simply add the high-res files and Qt will pick them when needed
276 
277  if (scalingFactorIsSupported(1.5))
278  icon.addFile(QStringLiteral(":/img/%1-1.5x.png").arg(iconName));
279 
280  icon.addFile(QStringLiteral(":/img/%1-2x.png").arg(iconName));
281 
282  return icon;
283 }
DockWidgetQuick.h
Represents a dock widget.
Layouting::SeparatorQuick
Definition: Separator_quick.h:27
Separator_quick.h
QUrl
QRect
KDDockWidgets::TitleBarButtonType
TitleBarButtonType
describes a type of button you can have in the title bar
Definition: KDDockWidgets.h:221
QWidget
Layouting::SeparatorWidget
Definition: Separator_qwidget.h:30
KDDockWidgets::DropIndicatorType
DropIndicatorType
Definition: KDDockWidgets.h:192
KDDockWidgets::RubberBandQuick
Definition: RubberBandQuick.h:20
KDDockWidgets::DefaultWidgetFactory::createTabBar
TabBar * createTabBar(TabWidget *parent) const override
Called internally by the framework to create a TabBar Override to provide your own TabBar sub-class.
Definition: FrameworkWidgetFactory.cpp:73
KDDockWidgets::DefaultWidgetFactory::createTitleBar
TitleBar * createTitleBar(Frame *) const override
Called internally by the framework to create a TitleBar Override to provide your own TitleBar sub-cla...
Definition: FrameworkWidgetFactory.cpp:63
QIcon::addFile
void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)
RubberBandQuick.h
QString
Layouting::Widget
An abstraction/wrapper around QWidget, QtQuickItem or anything else.
Definition: Widget.h:79
KDDockWidgets::DefaultWidgetFactory::createFloatingWindow
FloatingWindow * createFloatingWindow(MainWindowBase *parent=nullptr) const override
Called internally by the framework to create a FloatingWindow Override to provide your own FloatingWi...
Definition: FrameworkWidgetFactory.cpp:88
QString::isEmpty
bool isEmpty() const const
KDDockWidgets::iconName
static QString iconName(DropIndicatorOverlayInterface::DropLocation loc, bool active)
Definition: ClassicIndicatorsWindow.cpp:20
QIcon
KDDockWidgets::SideBarLocation
SideBarLocation
Each main window supports 4 sidebars.
Definition: KDDockWidgets.h:211
KDDockWidgets::DefaultWidgetFactory::createFrame
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...
Definition: FrameworkWidgetFactory.cpp:58
Config.h
Application-wide config to tune certain behaviours of the framework.
KDDockWidgets::TitleBarButtonType::Close
@ Close
KDDockWidgets::DefaultWidgetFactory::createSeparator
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...
Definition: FrameworkWidgetFactory.cpp:83
KDDockWidgets::DefaultWidgetFactory::createSideBar
SideBar * createSideBar(SideBarLocation loc, MainWindowBase *parent) const override
Called internally by the framework to create a SideBar.
Definition: FrameworkWidgetFactory.cpp:122
KDDockWidgets::DefaultWidgetFactory::createRubberBand
QWidgetOrQuick * createRubberBand(QWidgetOrQuick *parent) const override
Called internally by the framework to create a RubberBand to show as drop zone Returns a rubber band.
Definition: FrameworkWidgetFactory.cpp:117
KDDockWidgets::DefaultWidgetFactory::createTabWidget
TabWidget * createTabWidget(Frame *parent) const override
Called internally by the framework to create a TabWidget Override to provide your own TabWidget sub-c...
Definition: FrameworkWidgetFactory.cpp:78
QRubberBand::Rectangle
Rectangle
KDDockWidgets
Definition: Config.cpp:36
QAbstractButton
KDDockWidgets::DefaultWidgetFactory::iconForButtonType
QIcon iconForButtonType(TitleBarButtonType type, qreal dpr) const override
Returns the icon to be used with the specified type.
Definition: FrameworkWidgetFactory.cpp:239
KDDockWidgets::DropIndicatorType::None
@ None
Don't show any drop indicators while dragging.
KDDockWidgets::MainWindowBase
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
Definition: MainWindowBase.h:56
Separator_qwidget.h
QRubberBand
KDDockWidgets::TitleBarButtonType::Normal
@ Normal
KDDockWidgets::FrameworkWidgetFactory::~FrameworkWidgetFactory
virtual ~FrameworkWidgetFactory()
Destructor.Don't delete FrameworkWidgetFactory directly, it's owned by the framework.
Definition: FrameworkWidgetFactory.cpp:53
KDDockWidgets::DefaultWidgetFactory::createTitleBarButton
QAbstractButton * createTitleBarButton(QWidget *parent, TitleBarButtonType) const override
Called internally by the framework to create a title bar button parent the button's parent.
Definition: FrameworkWidgetFactory.cpp:127
QObject::parent
QObject * parent() const const
FrameworkWidgetFactory.h
A factory class for allowing the user to customize some internal widgets.
KDDockWidgets::DefaultWidgetFactory::s_dropIndicatorType
static DropIndicatorType s_dropIndicatorType
Definition: FrameworkWidgetFactory.h:190
KDDockWidgets::DefaultWidgetFactory::createDropIndicatorOverlay
DropIndicatorOverlayInterface * createDropIndicatorOverlay(DropArea *) const override
Called internally by the framework to create a DropIndicatorOverlayInterface Override to provide your...
Definition: FrameworkWidgetFactory.cpp:98
KDDockWidgets::TitleBarButtonType::Float
@ Float

© 2019-2022 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 Mon Mar 7 2022 02:01:20 for KDDockWidgets API Documentation by doxygen 1.8.20