KDDockWidgets API Documentation 2.1
Loading...
Searching...
No Matches
qtwidgets/views/View.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 "View.h"
13#include "../Window_p.h"
14#include "core/View_p.h"
15#include "core/layouting/Item_p.h"
16#include "ViewWrapper_p.h"
17
18#include <QTabBar>
19#include <QTabWidget>
20#include <QMainWindow>
21#include <QRubberBand>
22#include <QLineEdit>
23
24using namespace KDDockWidgets;
25using namespace KDDockWidgets::QtWidgets;
26
27// clazy:excludeall=missing-qobject-macro
28
29template<>
31 QWidget *parent, Qt::WindowFlags windowFlags)
32 : QWidget(parent, windowFlags)
33 , View_qt(controller, type, this)
34{
35}
36
37template<>
39 QWidget *parent, Qt::WindowFlags)
40 : QTabBar(parent)
41 , View_qt(controller, type, this)
42{
43}
44
45template<>
47 QWidget *parent, Qt::WindowFlags)
48 : QTabWidget(parent)
49 , View_qt(controller, type, this)
50{
51}
52
53template<>
55 QWidget *parent, Qt::WindowFlags)
56 : QMainWindow(parent)
57 , View_qt(controller, type, this)
58{
59}
60
61template<>
63 QWidget *parent, Qt::WindowFlags)
64 : QRubberBand(QRubberBand::Rectangle, parent)
65 , View_qt(controller, type, this)
66{
67}
68
69template<>
71 QWidget *parent, Qt::WindowFlags)
72 : QLineEdit(parent)
73 , View_qt(controller, type, this)
74{
75}
76
77template<class T>
78std::shared_ptr<Core::Window> View<T>::window() const
79{
80 if (QWidget *root = QWidget::window()) {
81 if (root->window()) {
82 return std::shared_ptr<Core::Window>(new Window(root));
83 }
84 }
85
86 return {};
87}
88
89template<class T>
91{
92 if (sz != QWidget::maximumSize()) {
93 T::setMaximumSize(sz);
94 d->layoutInvalidated.emit();
95 }
96}
97
98template<class T>
100{
101 if (e->type() == QEvent::LayoutRequest)
102 d->layoutInvalidated.emit();
103
104 return T::event(e);
105}
106
107template<class T>
109{
110 d->requestClose(ev);
111}
113template<class T>
115{
116 if (sz != QWidget::minimumSize()) {
118 d->layoutInvalidated.emit();
119 }
120}
121
122
123template<class T>
124std::shared_ptr<Core::View> View<T>::childViewAt(QPoint localPos) const
125{
126 if (QWidget *child = QWidget::childAt(localPos))
127 return ViewWrapper::create(child);
128
129 return {};
130}
131
132template<class T>
133std::shared_ptr<Core::View> View<T>::rootView() const
134{
135 if (auto w = QWidget::window()) {
136 return ViewWrapper::create(w);
137 }
138
139 return {};
140}
141
142template<class T>
143std::shared_ptr<Core::View> View<T>::parentView() const
144{
145 if (QWidget *p = QWidget::parentWidget()) {
146 return ViewWrapper::create(p);
147 }
148
149 return {};
150}
151
152template<class T>
153std::shared_ptr<Core::View> View<T>::asWrapper()
154{
155 return ViewWrapper::create(this);
156}
157
158/* static */
159template<class T>
161{
163 const QObjectList &children = parent->children();
164 result.reserve(children.size());
165 for (QObject *child : children) {
166 if (auto widget = qobject_cast<QWidget *>(child)) {
167 result.push_back(ViewWrapper::create(widget));
168 }
169 }
170
171 return result;
172}
173
174namespace KDDockWidgets::QtWidgets {
175
176template class View<QWidget>;
177template class View<QMainWindow>;
178template class View<QLineEdit>;
179template class View<QRubberBand>;
180template class View<QTabWidget>;
181template class View<QTabBar>;
182
184{
185 // Max should be bigger than min, but not bigger than the hardcoded max
186 max = max.boundedTo(Core::Item::hardcodedMaximumSize);
187
188 // 0 interpreted as not having max
189 if (max.width() <= 0)
190 max.setWidth(Core::Item::hardcodedMaximumSize.width());
191 if (max.height() <= 0)
192 max.setHeight(Core::Item::hardcodedMaximumSize.height());
193
194 max = max.expandedTo(min);
195
196 return max;
197}
198
199}
std::shared_ptr< Core::View > rootView() const override
Returns the top-level gui element which this view is inside It's the root view of the window.
void closeEvent(QCloseEvent *ev) override
void setMaximumSize(QSize sz) override
View(Core::Controller *controller, Core::ViewType type, QWidget *parent=nullptr, Qt::WindowFlags windowFlags={})
static QVector< std::shared_ptr< Core::View > > childViewsFor(const QWidget *parent)
std::shared_ptr< Core::View > childViewAt(QPoint localPos) const override
std::shared_ptr< Core::View > parentView() const override
Returns the gui element's parent. Like QWidget::parentWidget()
std::shared_ptr< Core::Window > window() const override
Returns the window this view is inside For the Qt frontend, this wraps a QWindow. Like QWidget::windo...
std::shared_ptr< Core::View > asWrapper() override
Returns this view, but as a wrapper.
ViewType
Each View type also has a specific Controller associated with, except for ViewType::None.
Definition Controller.h:26
QSize boundedMaxSize(QSize min, QSize max)
Class to abstract QAction, so code still works with QtQuick and Flutter.
QEvent::Type type() const const
const QObjectList & children() const const
QSize boundedTo(const QSize &otherSize) const const
QSize expandedTo(const QSize &otherSize) const const
int height() const const
void setHeight(int height)
void setWidth(int width)
int width() const const
typedef WindowFlags
void push_back(const T &value)
void reserve(int size)
QWidget * childAt(int x, int y) const const
QWidget * parentWidget() const const
QWidget * window() 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