KDDockWidgets API Documentation  1.5
SideBar.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 "SideBar_p.h"
13 #include "DockWidgetBase.h"
14 #include "MainWindowBase.h"
15 
16 #include <QDebug>
17 
18 using namespace KDDockWidgets;
19 
20 SideBar::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 
30 void 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 
47 void 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 
61 bool SideBar::containsDockWidget(DockWidgetBase *dw) const
62 {
63  return m_dockWidgets.contains(dw);
64 }
65 
66 void SideBar::onButtonClicked(DockWidgetBase *dw)
67 {
68  toggleOverlay(dw);
69 }
70 
71 void SideBar::onDockWidgetDestroyed(QObject *dw)
72 {
73  removeDockWidget(static_cast<DockWidgetBase *>(dw));
74 }
75 
76 void SideBar::updateSize()
77 {
78  const int thickness = isEmpty() ? 0 : 30;
79  if (isVertical()) {
80  setFixedWidth(thickness);
81  } else {
82  setFixedHeight(thickness);
83  }
84 }
85 
86 Qt::Orientation SideBar::orientation() const
87 {
88  return m_orientation;
89 }
90 
91 bool SideBar::isEmpty() const
92 {
93  return m_dockWidgets.isEmpty();
94 }
95 
96 SideBarLocation SideBar::location() const
97 {
98  return m_location;
99 }
100 
101 MainWindowBase *SideBar::mainWindow() const
102 {
103  return m_mainWindow;
104 }
105 
106 void SideBar::toggleOverlay(DockWidgetBase *dw)
107 {
108  m_mainWindow->toggleOverlayOnSideBar(dw);
109 }
110 
111 QStringList SideBar::serialize() const
112 {
113  QStringList ids;
114  ids.reserve(m_dockWidgets.size());
115  for (DockWidgetBase *dw : m_dockWidgets)
116  ids << dw->uniqueName();
117 
118  return ids;
119 }
120 
121 void SideBar::clear()
122 {
123  for (DockWidgetBase *dw : qAsConst(m_dockWidgets))
124  removeDockWidget(dw);
125 }
DockWidgetBase.h
The DockWidget base-class that's shared between QtWidgets and QtQuick stack.
KDDockWidgets::DockWidgetBase::uniqueName
QString uniqueName
Definition: DockWidgetBase.h:65
KDDockWidgets::DockWidgetBase::title
QString title
Definition: DockWidgetBase.h:66
MainWindowBase.h
The MainWindow base-class that's shared between QtWidgets and QtQuick stack.
QList::reserve
void reserve(int alloc)
QObject::destroyed
void destroyed(QObject *obj)
QObject
KDDockWidgets::SideBarLocation::None
@ None
Qt
Qt::Horizontal
Horizontal
KDDockWidgets::MainWindowBase::toggleOverlayOnSideBar
Q_INVOKABLE void toggleOverlayOnSideBar(KDDockWidgets::DockWidgetBase *)
Shows or hides an overlay. It's assumed the dock widget is already in a side-bar.
Definition: MainWindowBase.cpp:558
KDDockWidgets::SideBarLocation
SideBarLocation
Each main window supports 4 sidebars.
Definition: KDDockWidgets.h:211
KDDockWidgets::DockWidgetBase::removedFromSideBar
void removedFromSideBar()
emitted when this dock widget is removed from a side-bar. Only relevant for the auto-hide/sidebar fea...
KDDockWidgets::DockWidgetBase
The DockWidget base-class. DockWidget and DockWidgetBase are only split in two so we can share some c...
Definition: DockWidgetBase.h:61
KDDockWidgets
Definition: Config.cpp:36
KDDockWidgets::MainWindowBase
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
Definition: MainWindowBase.h:56
QStringList

© 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:21 for KDDockWidgets API Documentation by doxygen 1.8.20