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

© 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