KDDockWidgets API Documentation 1.7
Loading...
Searching...
No Matches
FrameWidget.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
19#include "FrameWidget_p.h"
20#include "../TitleBar_p.h"
21#include "../TabWidget_p.h"
22#include "Config.h"
24
25#include <QVBoxLayout>
26#include <QPainter>
27#include <QTableWidget>
28#include <QTabBar>
29
30using namespace KDDockWidgets;
31
33class VBoxLayout : public QVBoxLayout // clazy:exclude=missing-qobject-macro
34{
35public:
36 explicit VBoxLayout(FrameWidget *parent)
38 , m_frameWidget(parent)
39 {
40 }
41 ~VBoxLayout() override;
42
43 void invalidate() override
44 {
46 Q_EMIT m_frameWidget->layoutInvalidated();
47 }
48
49 FrameWidget *const m_frameWidget;
50};
51
52VBoxLayout::~VBoxLayout() = default;
53
54FrameWidget::FrameWidget(QWidget *parent, FrameOptions options, int userType)
55 : Frame(parent, options, userType)
56{
57 auto vlayout = new VBoxLayout(this);
58 vlayout->setContentsMargins(0, 0, 0, 0);
59 vlayout->setSpacing(0);
60 vlayout->addWidget(titleBar());
61 vlayout->addWidget(m_tabWidget->asWidget());
62
63 m_tabWidget->setTabBarAutoHide(!alwaysShowsTabs());
64
65 if (isOverlayed())
66 setAutoFillBackground(true);
67}
68
69FrameWidget::~FrameWidget()
70{
71 m_inDtor = true;
72}
73
74void FrameWidget::paintEvent(QPaintEvent *)
75{
76 if (!isFloating()) {
77 QPainter p(this);
78 p.setRenderHint(QPainter::Antialiasing);
79
80 const qreal penWidth = 1;
81 const qreal halfPenWidth = penWidth / 2;
82 const QRectF rectf = QWidget::rect();
83
84 const QColor penColor = isOverlayed() ? QColor(0x666666)
85 : QColor(184, 184, 184, 184);
86 QPen pen(penColor);
87 pen.setWidthF(penWidth);
88 p.setPen(pen);
89
90 if (isOverlayed()) {
91 pen.setJoinStyle(Qt::MiterJoin);
92 p.drawRect(rectf.adjusted(halfPenWidth, penWidth, -halfPenWidth, -halfPenWidth));
93 } else {
94 p.drawRoundedRect(rectf.adjusted(halfPenWidth, halfPenWidth, -halfPenWidth, -halfPenWidth), 2, 2);
95 }
96 }
97}
98
99QSize FrameWidget::maxSizeHint() const
100{
101 // waste due to QTabWidget margins, tabbar etc.
102 const QSize waste = minSize() - dockWidgetsMinSize();
103 return waste + biggestDockWidgetMaxSize();
104}
105
106int FrameWidget::indexOfDockWidget_impl(const DockWidgetBase *dw)
107{
108 return m_tabWidget->indexOfDockWidget(dw);
109}
110
111void FrameWidget::setCurrentDockWidget_impl(DockWidgetBase *dw)
112{
113 m_tabWidget->setCurrentDockWidget(dw);
114}
115
116int FrameWidget::currentIndex_impl() const
117{
118 return m_tabWidget->currentIndex();
119}
120
121void FrameWidget::insertDockWidget_impl(DockWidgetBase *dw, int index)
122{
123 m_tabWidget->insertDockWidget(dw, index);
124}
125
126void FrameWidget::removeWidget_impl(DockWidgetBase *dw)
127{
128 m_tabWidget->removeDockWidget(dw);
129}
130
131void FrameWidget::setCurrentTabIndex_impl(int index)
132{
133 m_tabWidget->setCurrentDockWidget(index);
134}
135
136DockWidgetBase *FrameWidget::currentDockWidget_impl() const
137{
138 return m_tabWidget->dockwidgetAt(m_tabWidget->currentIndex());
139}
140
141DockWidgetBase *FrameWidget::dockWidgetAt_impl(int index) const
142{
143 return qobject_cast<DockWidgetBase *>(m_tabWidget->dockwidgetAt(index));
144}
145
146QTabBar *FrameWidget::tabBar() const
147{
148 auto tw = static_cast<QTabWidget *>(m_tabWidget->asWidget());
149 return tw->tabBar();
150}
151
152QRect FrameWidget::dragRect() const
153{
154 QRect rect = Frame::dragRect();
155 if (rect.isValid())
156 return rect;
157
159 QTabBar *tabBar = this->tabBar();
160 rect.setHeight(tabBar->height());
161 rect.setWidth(width() - tabBar->width());
162 rect.moveTopLeft(QPoint(tabBar->width(), tabBar->y()));
164 }
165
166 return rect;
167}
168
169void FrameWidget::renameTab(int index, const QString &text)
170{
171 m_tabWidget->renameTab(index, text);
172}
173
174void FrameWidget::changeTabIcon(int index, const QIcon &icon)
175{
176 m_tabWidget->changeTabIcon(index, icon);
177}
178
179int FrameWidget::nonContentsHeight() const
180{
181 TitleBar *tb = titleBar();
182 QWidget *tabBar = this->tabBar();
183
184 return (tb->isVisible() ? tb->height() : 0) + (tabBar->isVisible() ? tabBar->height() : 0);
185}
Application-wide config to tune certain behaviours of the framework.
A factory class for allowing the user to customize some internal widgets.
static Config & self()
returns the singleton Config instance
Definition Config.cpp:84
@ Flag_HideTitleBarWhenTabsVisible
Hides the title bar if there's tabs visible. The empty space in the tab bar becomes draggable.
Definition Config.h:92
The DockWidget base-class. DockWidget and DockWidgetBase are only split in two so we can share some c...
virtual void invalidate() override
Q_EMITQ_EMIT
QObject * parent() const const
T qobject_cast(QObject *object)
bool isValid() const const
void moveTopLeft(const QPoint &position)
void setHeight(int height)
void setWidth(int width)
QPoint topLeft() const const
QRectF adjusted(qreal dx1, qreal dy1, qreal dx2, qreal dy2) const const
MiterJoin
QTabBar * tabBar() const const
QPoint mapToGlobal(const QPoint &pos) const const

© 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