KDDockWidgets API Documentation  1.5
FrameWidget.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 
19 #include "FrameWidget_p.h"
20 #include "../TitleBar_p.h"
21 #include "../TabWidget_p.h"
22 #include "Config.h"
23 #include "FrameworkWidgetFactory.h"
24 
25 #include <QVBoxLayout>
26 #include <QPainter>
27 #include <QTableWidget>
28 #include <QTabBar>
29 
30 using namespace KDDockWidgets;
31 
33 class VBoxLayout : public QVBoxLayout //clazy:exclude=missing-qobject-macro
34 {
35 public:
36  explicit VBoxLayout(FrameWidget *parent)
37  : QVBoxLayout(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 
52 VBoxLayout::~VBoxLayout() = default;
53 
54 FrameWidget::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 
69 FrameWidget::~FrameWidget()
70 {
71  m_inDtor = true;
72 }
73 
74 void 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 
99 QSize FrameWidget::maxSizeHint() const
100 {
101  // waste due to QTabWidget margins, tabbar etc.
102  const QSize waste = minSize() - dockWidgetsMinSize();
103  return waste + biggestDockWidgetMaxSize();
104 }
105 
106 int FrameWidget::indexOfDockWidget_impl(const DockWidgetBase *dw)
107 {
108  return m_tabWidget->indexOfDockWidget(dw);
109 }
110 
111 void FrameWidget::setCurrentDockWidget_impl(DockWidgetBase *dw)
112 {
113  m_tabWidget->setCurrentDockWidget(dw);
114 }
115 
116 int FrameWidget::currentIndex_impl() const
117 {
118  return m_tabWidget->currentIndex();
119 }
120 
121 void FrameWidget::insertDockWidget_impl(DockWidgetBase *dw, int index)
122 {
123  m_tabWidget->insertDockWidget(dw, index);
124 }
125 
126 void FrameWidget::removeWidget_impl(DockWidgetBase *dw)
127 {
128  m_tabWidget->removeDockWidget(dw);
129 }
130 
131 void FrameWidget::setCurrentTabIndex_impl(int index)
132 {
133  m_tabWidget->setCurrentDockWidget(index);
134 }
135 
136 DockWidgetBase *FrameWidget::currentDockWidget_impl() const
137 {
138  return m_tabWidget->dockwidgetAt(m_tabWidget->currentIndex());
139 }
140 
141 DockWidgetBase *FrameWidget::dockWidgetAt_impl(int index) const
142 {
143  return qobject_cast<DockWidgetBase *>(m_tabWidget->dockwidgetAt(index));
144 }
145 
146 QTabBar *FrameWidget::tabBar() const
147 {
148  auto tw = static_cast<QTabWidget *>(m_tabWidget->asWidget());
149  return tw->tabBar();
150 }
151 
152 QRect FrameWidget::dragRect() const
153 {
154  QRect rect = Frame::dragRect();
155  if (rect.isValid())
156  return rect;
157 
158  if (Config::self().flags() & Config::Flag_HideTitleBarWhenTabsVisible) {
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 
169 void FrameWidget::renameTab(int index, const QString &text)
170 {
171  m_tabWidget->renameTab(index, text);
172 }
173 
174 void FrameWidget::changeTabIcon(int index, const QIcon &icon)
175 {
176  m_tabWidget->changeTabIcon(index, icon);
177 }
178 
179 int 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 }
QPainter::Antialiasing
Antialiasing
QTabWidget
QColor
QWidget::y
y
QRect::moveTopLeft
void moveTopLeft(const QPoint &position)
QVBoxLayout
QRect::setWidth
void setWidth(int width)
QRect::topLeft
QPoint topLeft() const const
QRect
Qt::MiterJoin
MiterJoin
QWidget::rect
rect
QTabBar
QWidget
QSize
QRectF::adjusted
QRectF adjusted(qreal dx1, qreal dy1, qreal dx2, qreal dy2) const const
QBoxLayout::invalidate
virtual void invalidate() override
QPainter
QPen
QWidget::isVisible
bool isVisible() const const
QRect::setHeight
void setHeight(int height)
QString
QRect::isValid
bool isValid() const const
QWidget::mapToGlobal
QPoint mapToGlobal(const QPoint &pos) const const
QIcon
Config.h
Application-wide config to tune certain behaviours of the framework.
QTabWidget::tabBar
QTabBar * tabBar() const const
QWidget::height
height
QPaintEvent
KDDockWidgets::DockWidgetBase
The DockWidget base-class. DockWidget and DockWidgetBase are only split in two so we can share some c...
Definition: DockWidgetBase.h:61
QRectF
KDDockWidgets
Definition: Config.cpp:36
QWidget::width
width
QPoint
FrameworkWidgetFactory.h
A factory class for allowing the user to customize some internal widgets.

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