KDDockWidgets API Documentation  1.6
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 #include "Item_p.h"
14 
15 #include <QDebug>
16 #include <QQmlEngine>
17 
18 using namespace Layouting;
19 
21 {
22 }
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 
70 void Widget_quick::setVisible(bool is) const
71 {
72  m_thisWidget->setVisible(is);
73 }
74 
75 std::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 
101 void Widget_quick::move(int x, int y)
102 {
103  QRect geo = geometry();
104  geo.setTopLeft(QPoint(x, y));
105  setGeometry(geo);
106 }
107 
108 void Widget_quick::setSize(int width, int height)
109 {
110  m_thisWidget->setSize(QSize(width, height));
111 }
112 
113 void Widget_quick::setWidth(int width)
114 {
115  m_thisWidget->setWidth(width);
116 }
117 
118 void Widget_quick::setHeight(int height)
119 {
120  m_thisWidget->setHeight(height);
121 }
122 
124 {
125  m_thisWidget->update();
126 }
127 
128 QQuickItem *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 }
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:43
QRectF::toRect
QRect toRect() const const
Layouting::Widget_quick::setWidth
void setWidth(int width) override
Definition: Widget_quick.cpp:113
QSize::isEmpty
bool isEmpty() const const
Layouting::Widget_quick::geometry
QRect geometry() const override
Definition: Widget_quick.cpp:30
Layouting::Widget_quick::setVisible
void setVisible(bool) const override
Definition: Widget_quick.cpp:70
Layouting::Widget_quick::parentWidget
std::unique_ptr< Widget > parentWidget() const override
Definition: Widget_quick.cpp:75
Layouting::Widget::y
int y() const
Definition: Widget.h:136
QSize
QDebug
Layouting::Widget_quick::hide
void hide() override
Definition: Widget_quick.cpp:96
Layouting::Widget_quick::setHeight
void setHeight(int height) override
Definition: Widget_quick.cpp:118
Layouting::Widget_quick::update
void update() override
Definition: Widget_quick.cpp:123
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:37
Layouting::Widget_quick::isVisible
bool isVisible() const override
Definition: Widget_quick.cpp:65
Layouting::Widget_quick::setSize
void setSize(int width, int height) override
Definition: Widget_quick.cpp:108
QString
Layouting::Widget::x
int x() const
Definition: Widget.h:131
Layouting::Widget_quick::createQQuickItem
QQuickItem * createQQuickItem(const QString &filename, QQuickItem *parent) const
Definition: Widget_quick.cpp:128
Layouting::Widget
An abstraction/wrapper around QWidget, QtQuickItem or anything else.
Definition: Widget.h:77
QRect::setTopLeft
void setTopLeft(const QPoint &position)
Layouting::Widget_quick::show
void show() override
Definition: Widget_quick.cpp:91
Widget_quick.h
A Layouting::Widget that's deals in QQuickItem.
Layouting::Widget::rect
QRect rect() const
Definition: Widget.h:117
QSize::expandedTo
QSize expandedTo(const QSize &otherSize) const const
Layouting::Widget_quick::minSize
QSize minSize() const override
Definition: Widget_quick.cpp:24
QRectF
Layouting::Widget_quick::dumpDebug
QDebug & dumpDebug(QDebug &) const override
Definition: Widget_quick.cpp:59
Layouting::Widget_quick::maxSizeHint
QSize maxSizeHint() const override
Definition: Widget_quick.cpp:84
Layouting::Widget_quick::~Widget_quick
~Widget_quick() override
Definition: Widget_quick.cpp:20
Layouting::Widget_quick::move
void move(int x, int y) override
Definition: Widget_quick.cpp:101
Layouting
Definition: FrameworkWidgetFactory.h:32
QPoint
Layouting::Widget::parent
QObject * parent() const
Definition: Widget.h:126

© 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 Thu Sep 15 2022 00:16:29 for KDDockWidgets API Documentation by doxygen 1.8.20