KDDockWidgets API Documentation 2.0
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/View_p.h"
23#include "core/Group_p.h"
24
25#include <QPainter>
26#include <QTabBar>
27#include <QVBoxLayout>
28
29using namespace KDDockWidgets;
30using namespace KDDockWidgets::QtWidgets;
31
33class VBoxLayout : public QVBoxLayout // clazy:exclude=missing-qobject-macro
34{
35public:
36 explicit VBoxLayout(Group *parent)
38 , m_groupWidget(parent)
39 {
40 }
41 ~VBoxLayout() override;
42
43 void invalidate() override
44 {
45 if (m_groupWidget->inDtor())
46 return;
48 m_groupWidget->d->layoutInvalidated.emit();
49 }
50
51 Group *const m_groupWidget;
52};
53
54VBoxLayout::~VBoxLayout() = default;
55
56Group::Group(Core::Group *controller, QWidget *parent)
57 : View<QWidget>(controller, Core::ViewType::Frame, parent)
58 , GroupViewInterface(controller)
59{
60}
61
63{
64 m_group->dptr()->numDockWidgetsChanged.connect([this] {
66 });
67
68 m_group->dptr()->isInMainWindowChanged.connect([this] {
70 });
71
72 m_group->dptr()->isFocusedChanged.connect([this] {
74 });
75
76 auto vlayout = new VBoxLayout(this);
77 vlayout->setContentsMargins(0, 0, 0, 0);
78 vlayout->setSpacing(0);
79 vlayout->addWidget(asQWidget(m_group->titleBar()));
80
81 vlayout->addWidget(asQWidget(m_group->stack()));
82
83 if (m_group->isOverlayed())
85}
86
88{
90 QWidget *tabBar = asQWidget(m_group->tabBar());
91
92 return (tb->isVisible() ? tb->height() : 0) + (tabBar->isVisible() ? tabBar->height() : 0);
93}
94
96{
97 if (d->freed())
98 return;
99
100 if (!m_group->isFloating()) {
101 QPainter p(this);
103
104 const qreal penWidth = 1;
105 const qreal halfPenWidth = penWidth / 2;
106 const QRectF rectf = QWidget::rect();
107
108 const bool isOverlayed = m_group->isOverlayed();
109 const QColor penColor = isOverlayed ? QColor(0x666666) : QColor(184, 184, 184, 184);
110 QPen pen(penColor);
111 pen.setWidthF(penWidth);
112 p.setPen(pen);
113
114 if (isOverlayed) {
116 p.drawRect(rectf.adjusted(halfPenWidth, penWidth, -halfPenWidth, -halfPenWidth));
117 } else {
119 rectf.adjusted(halfPenWidth, halfPenWidth, -halfPenWidth, -halfPenWidth), 2, 2);
120 }
121 }
122}
123
125{
126 if (d->freed())
127 return {};
128
129 // waste due to QTabWidget margins, tabbar etc.
130 const QSize waste = minSize() - m_group->dockWidgetsMinSize();
131 return waste + m_group->biggestDockWidgetMaxSize();
132}
133
135{
136 QRect rect;
137
139 auto tabBar = qobject_cast<QTabBar *>(asQWidget(m_group->tabBar()));
140 rect.setHeight(tabBar->height());
141 rect.setWidth(QWidget::width() - tabBar->width());
142 rect.moveTopLeft(QPoint(tabBar->width(), tabBar->y()));
143 rect.moveTopLeft(QWidget::mapToGlobal(rect.topLeft()));
144 }
145
146 return rect;
147}
Application-wide config to tune certain behaviours of the framework.
static Config & self()
returns the singleton Config instance
Definition Config.cpp:87
@ 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