KDDockWidgets API Documentation  1.5
Widget.h
Go to the documentation of this file.
1 /*
2  This file is part of KDDockWidgets.
3 
4  SPDX-FileCopyrightText: 2020-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 
14 
15 #pragma once
16 
17 #include "kddockwidgets/docks_export.h"
18 #include "Item_p.h"
19 
20 #include <QRect>
21 #include <QSize>
22 #include <QDebug>
23 #include <QObject>
24 #include <qglobal.h>
25 
26 #include <memory>
27 
28 QT_BEGIN_NAMESPACE
29 class QWidget;
30 QT_END_NAMESPACE
31 
32 #ifdef QT_WIDGETS_LIB
33 #include <QSizePolicy>
34 #else
35 class QSizePolicy
36 {
37 public:
38  enum Policy
39  {
40  Fixed,
41  Preferred,
42  Maximum
43  };
44 
45  explicit QSizePolicy(Policy h, Policy v)
46  : horizontal(h)
47  , vertical(v)
48  {
49  }
50 
51  Policy verticalPolicy() const
52  {
53  return vertical;
54  }
55 
56  Policy horizontalPolicy() const
57  {
58  return horizontal;
59  }
60 
61  Policy horizontal = Fixed;
62  Policy vertical = Fixed;
63 };
64 #endif
65 
66 namespace Layouting {
67 
68 class Item;
69 
78 class DOCKS_EXPORT Widget
79 {
80 public:
81  explicit Widget(QObject *thisObj);
82  virtual ~Widget();
83 
84  virtual void setLayoutItem(Item *) = 0;
85 
86  // Not strickly necessary, but it's nice convenience for kddw which is widget based.
87  virtual QWidget *asQWidget() const
88  {
89  Q_ASSERT(false); // Only wanted for QtWidgets. All other should not call this.
90  return nullptr;
91  }
92 
93  virtual QSize sizeHint() const
94  {
95  return {};
96  }
97  virtual QSize minSize() const = 0;
98  virtual QSize maxSizeHint() const = 0;
99  virtual QRect geometry() const = 0;
100  virtual void setGeometry(QRect) = 0;
101  virtual void setParent(Widget *) = 0;
102  virtual QDebug &dumpDebug(QDebug &) const = 0;
103  virtual bool isVisible() const = 0;
104  virtual void setVisible(bool) const = 0;
105  virtual void move(int x, int y) = 0;
106  virtual void setSize(int width, int height) = 0;
107  virtual void setWidth(int width) = 0;
108  virtual void setHeight(int height) = 0;
109  virtual std::unique_ptr<Widget> parentWidget() const = 0;
110  virtual void show() = 0;
111  virtual void hide() = 0;
112  virtual void update() = 0;
113 
114  QSize size() const
115  {
116  return geometry().size();
117  }
118 
119  QRect rect() const
120  {
121  return QRect(QPoint(0, 0), size());
122  }
123 
125  {
126  return m_thisObj;
127  }
128  QObject *parent() const
129  {
130  return m_thisObj->parent();
131  }
132 
133  int x() const
134  {
135  return geometry().x();
136  }
137 
138  int y() const
139  {
140  return geometry().y();
141  }
142 
143  bool operator==(const QObject *obj) const
144  {
145  return obj == m_thisObj;
146  }
147 
149  QString id() const;
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(Item::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 
184 protected:
185  static QSize boundedMaxSize(QSize min, QSize max);
186 
187 private:
188  const QString m_id;
189  QObject *const m_thisObj;
190  Q_DISABLE_COPY(Widget)
191 };
192 
193 inline 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 }
Layouting::Widget::widgetMaxSize
static QSize widgetMaxSize(const T *w)
Definition: Widget.h:164
Layouting::Widget::update
virtual void update()=0
Layouting::Widget::widgetMinSize
static QSize widgetMinSize(const T *w)
Definition: Widget.h:152
Layouting::Widget::isVisible
virtual bool isVisible() const =0
QRect
Layouting::Widget::setWidth
virtual void setWidth(int width)=0
Layouting::Widget::show
virtual void show()=0
QSizePolicy::horizontalPolicy
QSizePolicy::Policy horizontalPolicy() const const
QWidget
Layouting::operator==
bool operator==(const Widget *w, const QObject &obj)
Definition: Widget.h:193
Layouting::Widget::geometry
virtual QRect geometry() const =0
Layouting::Widget::y
int y() const
Definition: Widget.h:138
Layouting::Widget::move
virtual void move(int x, int y)=0
QSize
Layouting::Widget::setVisible
virtual void setVisible(bool) const =0
QDebug
QSize::width
int width() const const
Layouting::Widget::size
QSize size() const
Definition: Widget.h:114
QSize::setWidth
void setWidth(int width)
Layouting::Widget::setLayoutItem
virtual void setLayoutItem(Item *)=0
QSizePolicy
QSizePolicy::verticalPolicy
QSizePolicy::Policy verticalPolicy() const const
QObject
QSize::height
int height() const const
QString
Layouting::Widget::x
int x() const
Definition: Widget.h:133
Layouting::Widget::hide
virtual void hide()=0
Layouting::Widget
An abstraction/wrapper around QWidget, QtQuickItem or anything else.
Definition: Widget.h:79
Layouting::Widget::setHeight
virtual void setHeight(int height)=0
Layouting::Widget::maxSizeHint
virtual QSize maxSizeHint() const =0
Layouting::Widget::setSize
virtual void setSize(int width, int height)=0
Layouting::Widget::asQObject
QObject * asQObject() const
Definition: Widget.h:124
Layouting::Widget::minSize
virtual QSize minSize() const =0
Layouting::Widget::rect
QRect rect() const
Definition: Widget.h:119
QSize::expandedTo
QSize expandedTo(const QSize &otherSize) const const
Layouting::Widget::setParent
virtual void setParent(Widget *)=0
QSizePolicy::QSizePolicy
QSizePolicy()
QSizePolicy::Policy
Policy
Layouting
Definition: FrameworkWidgetFactory.h:32
Layouting::Widget::setGeometry
virtual void setGeometry(QRect)=0
Layouting::Widget::parentWidget
virtual std::unique_ptr< Widget > parentWidget() const =0
Layouting::Widget::asQWidget
virtual QWidget * asQWidget() const
Definition: Widget.h:87
QObject::parent
QObject * parent() const const
QSize::setHeight
void setHeight(int height)
QPoint
Layouting::Widget::dumpDebug
virtual QDebug & dumpDebug(QDebug &) const =0
Layouting::Widget::sizeHint
virtual QSize sizeHint() const
Definition: Widget.h:93
Layouting::Widget::parent
QObject * parent() const
Definition: Widget.h:128
Layouting::Widget::operator==
bool operator==(const QObject *obj) const
Definition: Widget.h:143

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