KDDockWidgets API Documentation 1.7
Loading...
Searching...
No Matches
SideBar.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
12#include "SideBar_p.h"
13#include "DockWidgetBase.h"
14#include "MainWindowBase.h"
15
16#include <QDebug>
17
18using namespace KDDockWidgets;
19
20SideBar::SideBar(SideBarLocation location, MainWindowBase *parent)
21 : QWidgetAdapter(parent)
22 , m_mainWindow(parent)
23 , m_location(location)
24 , m_orientation((location == SideBarLocation::North || location == SideBarLocation::South) ? Qt::Horizontal
25 : Qt::Vertical)
26{
27 updateSize();
28}
29
30void SideBar::addDockWidget(DockWidgetBase *dw)
31{
32 if (!dw)
33 return;
34
35 if (m_dockWidgets.contains(dw)) {
36 qWarning() << Q_FUNC_INFO << "Already contains dock widget" << dw->title();
37 return;
38 }
39
40 connect(dw, &QObject::destroyed, this, &SideBar::onDockWidgetDestroyed);
41
42 m_dockWidgets << dw;
43 addDockWidget_Impl(dw);
44 updateSize();
45}
46
47void SideBar::removeDockWidget(DockWidgetBase *dw)
48{
49 if (!m_dockWidgets.contains(dw)) {
50 qWarning() << Q_FUNC_INFO << "Doesn't contain dock widget" << dw->title();
51 return;
52 }
53
54 disconnect(dw, &QObject::destroyed, this, &SideBar::onDockWidgetDestroyed);
55 m_dockWidgets.removeOne(dw);
56 removeDockWidget_Impl(dw);
57 Q_EMIT dw->removedFromSideBar();
58 updateSize();
59}
60
61bool SideBar::containsDockWidget(DockWidgetBase *dw) const
62{
63 return m_dockWidgets.contains(dw);
64}
65
66void SideBar::onButtonClicked(DockWidgetBase *dw)
67{
68 toggleOverlay(dw);
69}
70
71QVector<DockWidgetBase *> SideBar::dockWidgets() const
72{
73 return m_dockWidgets;
74}
75
76void SideBar::onDockWidgetDestroyed(QObject *dw)
77{
78 removeDockWidget(static_cast<DockWidgetBase *>(dw));
79}
80
81void SideBar::updateSize()
82{
83 const int thickness = isEmpty() ? 0 : 30;
84 if (isVertical()) {
85 setFixedWidth(thickness);
86 } else {
87 setFixedHeight(thickness);
88 }
89}
90
91Qt::Orientation SideBar::orientation() const
92{
93 return m_orientation;
94}
95
96bool SideBar::isEmpty() const
97{
98 return m_dockWidgets.isEmpty();
99}
100
101SideBarLocation SideBar::location() const
102{
103 return m_location;
104}
105
106MainWindowBase *SideBar::mainWindow() const
107{
108 return m_mainWindow;
109}
110
111void SideBar::toggleOverlay(DockWidgetBase *dw)
112{
113 m_mainWindow->toggleOverlayOnSideBar(dw);
114}
115
116QStringList SideBar::serialize() const
117{
118 QStringList ids;
119 ids.reserve(m_dockWidgets.size());
120 for (DockWidgetBase *dw : m_dockWidgets)
121 ids << dw->uniqueName();
122
123 return ids;
124}
125
126void SideBar::clear()
127{
128 for (DockWidgetBase *dw : qAsConst(m_dockWidgets))
129 removeDockWidget(dw);
130}
The DockWidget base-class that's shared between QtWidgets and QtQuick stack.
The MainWindow base-class that's shared between QtWidgets and QtQuick stack.
The DockWidget base-class. DockWidget and DockWidgetBase are only split in two so we can share some c...
void removedFromSideBar()
emitted when this dock widget is removed from a side-bar. Only relevant for the auto-hide/sidebar fea...
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
Q_INVOKABLE void toggleOverlayOnSideBar(KDDockWidgets::DockWidgetBase *)
Shows or hides an overlay. It's assumed the dock widget is already in a side-bar.
SideBarLocation
Each main window supports 4 sidebars.
void reserve(int alloc)
void destroyed(QObject *obj)
Horizontal

© 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