KDDockWidgets API Documentation 2.1
Loading...
Searching...
No Matches
qtwidgets/views/Group.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2020 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 "Group.h"
13
15
16#include "kddockwidgets/core/Layout.h"
17#include "kddockwidgets/core/Group.h"
18#include "kddockwidgets/core/Stack.h"
19#include "kddockwidgets/core/TabBar.h"
20#include "kddockwidgets/core/TitleBar.h"
21#include "Config.h"
22#include "core/layouting/Item_p.h"
23#include "core/View_p.h"
24#include "core/Group_p.h"
25
26#include <QPainter>
27#include <QTabBar>
28#include <QVBoxLayout>
29#include <QTimer>
30
31using namespace KDDockWidgets;
32using namespace KDDockWidgets::QtWidgets;
33
35class VBoxLayout : public QVBoxLayout // clazy:exclude=missing-qobject-macro
36{
37public:
38 explicit VBoxLayout(Group *parent)
40 , m_groupWidget(parent)
41 {
42 }
43 ~VBoxLayout() override;
44
45 void invalidate() override
46 {
47 if (m_groupWidget->inDtor())
48 return;
50
51 if (auto item = m_groupWidget->group()->layoutItem()) {
52 if (auto root = item->root()) {
53 if (root->inSetSize() || root->isDeserializing()) {
54 // There's at least one item currently in the middle of a resize
55 // schedule relayout, do not interrupt.
56 QTimer::singleShot(0, m_groupWidget, [this] {
57 if (!m_groupWidget->inDtor())
58 m_groupWidget->d->layoutInvalidated.emit();
59 });
60 } else {
61 // normal case
62 m_groupWidget->d->layoutInvalidated.emit();
63 }
64 }
65 }
66 }
67
68 Group *const m_groupWidget;
69};
70
71VBoxLayout::~VBoxLayout() = default;
72
73Group::Group(Core::Group *controller, QWidget *parent)
74 : View<QWidget>(controller, Core::ViewType::Group, parent)
75 , GroupViewInterface(controller)
76{
77}
78
80{
81 m_group->dptr()->numDockWidgetsChanged.connect([this] {
83 });
84
85 m_group->dptr()->isInMainWindowChanged.connect([this] {
87 });
88
89 m_group->dptr()->isFocusedChanged.connect([this] {
91 });
92
93 auto vlayout = new VBoxLayout(this);
94 vlayout->setContentsMargins(0, 0, 0, 0);
95 vlayout->setSpacing(0);
96 vlayout->addWidget(asQWidget(m_group->titleBar()));
97
98 vlayout->addWidget(asQWidget(m_group->stack()));
99
100 if (m_group->isOverlayed())
102}
103
105{
107 QWidget *tabBar = asQWidget(m_group->tabBar());
108
109 return (tb->isVisible() ? tb->height() : 0) + (tabBar->isVisible() ? tabBar->height() : 0);
110}
111
113{
114 if (d->freed())
115 return;
116
117 if (!m_group->isFloating()) {
118 QPainter p(this);
120
121 const qreal penWidth = 1;
122 const qreal halfPenWidth = penWidth / 2;
123 const QRectF rectf = QWidget::rect();
124
125 const bool isOverlayed = m_group->isOverlayed();
126 const QColor penColor = isOverlayed ? QColor(0x666666) : QColor(184, 184, 184, 184);
127 QPen pen(penColor);
128 pen.setWidthF(penWidth);
129 p.setPen(pen);
130
131 if (isOverlayed) {
133 p.drawRect(rectf.adjusted(halfPenWidth, penWidth, -halfPenWidth, -halfPenWidth));
134 } else {
136 rectf.adjusted(halfPenWidth, halfPenWidth, -halfPenWidth, -halfPenWidth), 2, 2);
137 }
138 }
139}
140
142{
143 if (d->freed())
144 return {};
145
146 // waste due to QTabWidget margins, tabbar etc.
147 const QSize waste = minSize() - m_group->dockWidgetsMinSize();
148 return waste + m_group->biggestDockWidgetMaxSize();
149}
150
152{
153 QRect rect;
154
156 auto tabBar = qobject_cast<QTabBar *>(asQWidget(m_group->tabBar()));
157 rect.setHeight(tabBar->height());
158 rect.setWidth(QWidget::width() - tabBar->width());
159 rect.moveTopLeft(QPoint(tabBar->width(), tabBar->y()));
160 rect.moveTopLeft(QWidget::mapToGlobal(rect.topLeft()));
161 }
162
163 return rect;
164}
Application-wide config to tune certain behaviours of the framework.
static Config & self()
returns the singleton Config instance
Definition Config.cpp:88
@ Flag_HideTitleBarWhenTabsVisible
Definition Config.h:89
Core::TitleBar * titleBar() const
bool isFloating() const
Returns whether this group is floating. A floating group isn't attached to any other MainWindow,...
Size dockWidgetsMinSize() const
Returns the minimum size of the dock widgets. This might be slightly smaller than Frame::minSize() du...
Core::Stack * stack() const
returns the tab widget
bool isOverlayed() const
Returns whether this group is overlayed on top of the MainWindow (auto-hide feature);.
Size biggestDockWidgetMaxSize() const
Returns the biggest combined maxSize of all dock widgets.
Core::TabBar * tabBar() const
QRect dragRect() const override
the rect that should start a drag. Only relevant if the title bar isn't visible. For normal KDDW usag...
int nonContentsHeight() const override
Returns the height of the "non-dockwidget" part. i.e.: the height of the titlebar (if any),...
Group(Core::Group *controller, QWidget *parent=nullptr)
void paintEvent(QPaintEvent *) override
Class to abstract QAction, so code still works with QtQuick and Flutter.
virtual void invalidate() override
Q_EMITQ_EMIT
QObject * parent() const const
void drawRect(const QRectF &rectangle)
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
void setPen(const QColor &color)
void setRenderHint(QPainter::RenderHint hint, bool on)
void setJoinStyle(Qt::PenJoinStyle style)
void setWidthF(qreal width)
QRectF adjusted(qreal dx1, qreal dy1, qreal dx2, qreal dy2) const const
MiterJoin
void setAutoFillBackground(bool enabled)
QPoint mapToGlobal(const QPoint &pos) const const
bool isVisible() const const

© 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