KDDockWidgets API Documentation 1.7
Loading...
Searching...
No Matches
Widget.h
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2020-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
14
15#pragma once
16
17#include "kddockwidgets/docks_export.h"
18
19#include <QRect>
20#include <QSize>
21#include <QDebug>
22#include <QObject>
23#include <qglobal.h>
24
25#include <memory>
26
27QT_BEGIN_NAMESPACE
28class QWidget;
30
31#ifdef QT_WIDGETS_LIB
32#include <QSizePolicy>
33#else
34class QSizePolicy
35{
36public:
37 enum Policy {
38 Fixed,
41 };
42
43 explicit QSizePolicy(Policy h, Policy v)
44 : horizontal(h)
45 , vertical(v)
46 {
47 }
48
50 {
51 return vertical;
52 }
53
55 {
56 return horizontal;
57 }
58
59 Policy horizontal = Fixed;
60 Policy vertical = Fixed;
61};
62#endif
63
64namespace Layouting {
65
66class Item;
67
76class DOCKS_EXPORT Widget
77{
78public:
79 explicit Widget(QObject *thisObj);
80 virtual ~Widget();
81
82 virtual void setLayoutItem(Item *) = 0;
83
84 // Not strickly necessary, but it's nice convenience for kddw which is widget based.
85 virtual QWidget *asQWidget() const
86 {
87 Q_ASSERT(false); // Only wanted for QtWidgets. All other should not call this.
88 return nullptr;
89 }
90
91 virtual QSize sizeHint() const
92 {
93 return {};
94 }
95 virtual QSize minSize() const = 0;
96 virtual QSize maxSizeHint() const = 0;
97 virtual QRect geometry() const = 0;
98 virtual void setGeometry(QRect) = 0;
99 virtual void setParent(Widget *) = 0;
100 virtual QDebug &dumpDebug(QDebug &) const = 0;
101 virtual bool isVisible() const = 0;
102 virtual void setVisible(bool) const = 0;
103 virtual void move(int x, int y) = 0;
104 virtual void setSize(int width, int height) = 0;
105 virtual void setWidth(int width) = 0;
106 virtual void setHeight(int height) = 0;
107 virtual std::unique_ptr<Widget> parentWidget() const = 0;
108 virtual void show() = 0;
109 virtual void hide() = 0;
110 virtual void update() = 0;
111
112 QSize size() const
113 {
114 return geometry().size();
115 }
116
117 QRect rect() const
118 {
119 return QRect(QPoint(0, 0), size());
120 }
121
123 {
124 return m_thisObj;
125 }
127 {
128 return m_thisObj->parent();
129 }
130
131 int x() const
132 {
133 return geometry().x();
134 }
135
136 int y() const
137 {
138 return geometry().y();
139 }
140
141 bool operator==(const QObject *obj) const
142 {
143 return obj == m_thisObj;
144 }
145
147 QString id() const;
148
149 static QSize hardcodedMinimumSize();
150
151 template<typename T>
152 static QSize widgetMinSize(const T *w)
153 {
154 const int minW = w->minimumWidth() > 0 ? w->minimumWidth()
155 : w->minimumSizeHint().width();
156
157 const int minH = w->minimumHeight() > 0 ? w->minimumHeight()
158 : w->minimumSizeHint().height();
159
160 return QSize(minW, minH).expandedTo(hardcodedMinimumSize());
161 }
162
163 template<typename T>
164 static QSize widgetMaxSize(const T *w)
165 {
166 // The max size is usually QWidget::maximumSize(), but we also honour the QSizePolicy::Fixed+sizeHint() case
167 // as widgets don't need to have QWidget::maximumSize() to have a max size honoured
168
169 const QSize min = widgetMinSize(w);
170 QSize max = w->maximumSize();
171 max = boundedMaxSize(min, max); // for safety against weird values
172
173 const QSizePolicy policy = w->sizePolicy();
174
176 max.setHeight(qMin(max.height(), w->sizeHint().height()));
178 max.setWidth(qMin(max.width(), w->sizeHint().width()));
179
180 max = boundedMaxSize(min, max); // for safety against weird values
181 return max;
182 }
183
184protected:
185 static QSize boundedMaxSize(QSize min, QSize max);
186
187private:
188 const QString m_id;
189 QObject *const m_thisObj;
190 Q_DISABLE_COPY(Widget)
191};
192
193inline bool operator==(const Widget *w, const QObject &obj)
194{
195 // if (!w && !obj)
196 // return true;
197
198 return w && w->operator==(&obj);
199}
200
201}
An abstraction/wrapper around QWidget, QtQuickItem or anything else.
Definition Widget.h:77
virtual void setGeometry(QRect)=0
virtual void setParent(Widget *)=0
virtual std::unique_ptr< Widget > parentWidget() const =0
virtual QDebug & dumpDebug(QDebug &) const =0
bool operator==(const QObject *obj) const
Definition Widget.h:141
virtual void hide()=0
virtual QRect geometry() const =0
virtual void setWidth(int width)=0
virtual QWidget * asQWidget() const
Definition Widget.h:85
static QSize widgetMaxSize(const T *w)
Definition Widget.h:164
virtual void show()=0
QObject * asQObject() const
Definition Widget.h:122
virtual bool isVisible() const =0
virtual QSize minSize() const =0
virtual void setVisible(bool) const =0
QSize size() const
Definition Widget.h:112
virtual QSize maxSizeHint() const =0
virtual void update()=0
virtual QSize sizeHint() const
Definition Widget.h:91
QRect rect() const
Definition Widget.h:117
static QSize widgetMinSize(const T *w)
Definition Widget.h:152
virtual void setHeight(int height)=0
QObject * parent() const
Definition Widget.h:126
virtual void move(int x, int y)=0
int y() const
Definition Widget.h:136
virtual void setLayoutItem(Item *)=0
virtual void setSize(int width, int height)=0
int x() const
Definition Widget.h:131
bool operator==(const Widget *w, const QObject &obj)
Definition Widget.h:193
QObject * parent() const const
T qobject_cast(QObject *object)
QSize expandedTo(const QSize &otherSize) const const
int height() const const
void setHeight(int height)
void setWidth(int width)
int width() const const
QSizePolicy::Policy horizontalPolicy() const const
QSizePolicy::Policy verticalPolicy() 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