KDDockWidgets API Documentation 1.7
Loading...
Searching...
No Matches
Widget_quick.cpp
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
12#include "Widget_quick.h"
13#include "Item_p.h"
14
15#include <QDebug>
16#include <QQmlEngine>
17
18using namespace Layouting;
19
23
25{
26 const QSize minSize = m_thisWidget->property("kddockwidgets_min_size").toSize();
27 return minSize.expandedTo(Item::hardcodedMinimumSize);
28}
29
31{
32 return QRectF(m_thisWidget->x(), m_thisWidget->y(),
33 m_thisWidget->width(), m_thisWidget->height())
34 .toRect();
35}
36
38{
39 m_thisWidget->setPosition(rect.topLeft());
40 m_thisWidget->setSize(rect.size());
41}
42
44{
45 if (!parent) {
46 m_thisWidget->setParent(nullptr);
47 return;
48 }
49
50 if (auto qquickitem = qobject_cast<QQuickItem *>(parent->asQObject())) {
51 m_thisWidget->setParent(qquickitem);
52 m_thisWidget->setParentItem(qquickitem);
53 } else {
54 qWarning() << Q_FUNC_INFO << "parent is not a widget, you have a bug" << parent->asQObject();
55 Q_ASSERT(false);
56 }
57}
58
60{
61 d << " Dump Start: Host=" << m_thisWidget << rect();
62 return d;
63}
64
66{
67 return m_thisWidget->isVisible();
68}
69
70void Widget_quick::setVisible(bool is) const
71{
72 m_thisWidget->setVisible(is);
73}
74
75std::unique_ptr<Widget> Widget_quick::parentWidget() const
76{
77 if (auto pw = m_thisWidget->parentItem()) {
78 return std::unique_ptr<Widget>(new Widget_quick(pw));
79 }
80
81 return {};
82}
83
85{
86 const QSize maxSize = m_thisWidget->property("kddockwidgets_max_size").toSize();
87 return maxSize.isEmpty() ? QSize(30000, 30000) // Some arbitrary big value
88 : maxSize;
89}
90
92{
93 m_thisWidget->setVisible(true);
94}
95
97{
98 m_thisWidget->setVisible(false);
99}
100
101void Widget_quick::move(int x, int y)
102{
103 QRect geo = geometry();
104 geo.setTopLeft(QPoint(x, y));
105 setGeometry(geo);
106}
107
108void Widget_quick::setSize(int width, int height)
109{
110 m_thisWidget->setSize(QSize(width, height));
111}
112
114{
115 m_thisWidget->setWidth(width);
116}
117
119{
120 m_thisWidget->setHeight(height);
121}
122
124{
125 m_thisWidget->update();
126}
127
128QQuickItem *Widget_quick::createQQuickItem(const QString &filename, QQuickItem *parent) const
129{
130 auto p = parent;
131 QQmlEngine *engine = nullptr;
132 while (p && !engine) {
133 engine = qmlEngine(p);
134 p = p->parentItem();
135 }
136
137 if (!engine) {
138 qWarning() << Q_FUNC_INFO << "No engine found";
139 return nullptr;
140 }
141
142 QQmlComponent component(engine, filename);
143 auto qquickitem = qobject_cast<QQuickItem *>(component.create());
144 if (!qquickitem) {
145 qWarning() << Q_FUNC_INFO << component.errorString();
146 return nullptr;
147 }
148
149 qquickitem->setParentItem(parent);
150 qquickitem->QObject::setParent(parent);
151
152 return qquickitem;
153}
A Layouting::Widget that's deals in QQuickItem.
A Layouting::Widget that's deals in QQuickItem Allows to host a QQuickItem in the layout.
void setVisible(bool) const override
void setSize(int width, int height) override
void move(int x, int y) override
QSize minSize() const override
void setParent(Widget *) override
void setWidth(int width) override
QSize maxSizeHint() const override
QQuickItem * createQQuickItem(const QString &filename, QQuickItem *parent) const
bool isVisible() const override
QRect geometry() const override
QDebug & dumpDebug(QDebug &) const override
std::unique_ptr< Widget > parentWidget() const override
void setHeight(int height) override
void setGeometry(QRect) override
An abstraction/wrapper around QWidget, QtQuickItem or anything else.
Definition Widget.h:77
QRect rect() const
Definition Widget.h:117
QObject * parent() const
Definition Widget.h:126
int y() const
Definition Widget.h:136
int x() const
Definition Widget.h:131
void setTopLeft(const QPoint &position)
QSize size() const const
QPoint topLeft() const const
QRect toRect() const const
QSize expandedTo(const QSize &otherSize) const const
bool isEmpty() 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