12#include "ViewWrapper_p.h"
15#include "core/View_p.h"
22#include "core/layouting/Item_p.h"
30#include "../Window_p.h"
32#include "kddockwidgets/core/DropArea.h"
33#include "kddockwidgets/core/MDILayout.h"
36#include <QtQuick/private/qquickitem_p.h>
54 if (
auto view = qobject_cast<Group *>(item))
55 return view->controller();
58 if (
auto view = qobject_cast<TitleBar *>(item))
59 return view->controller();
62 if (
auto view = qobject_cast<TabBar *>(item))
63 return view->controller();
66 if (
auto view = qobject_cast<Stack *>(item))
67 return view->controller();
70 if (
auto view = qobject_cast<FloatingWindow *>(item))
71 return view->controller();
74 if (
auto view = qobject_cast<Separator *>(item))
75 return view->controller();
78 if (
auto view = qobject_cast<QtQuick::DockWidget *>(item))
79 return view->controller();
82 if (
auto view = qobject_cast<DropArea *>(item))
83 return view->controller();
86 if (
auto view = qobject_cast<MDILayout *>(item))
87 return view->controller();
93 if (
auto view = qobject_cast<MainWindow *>(item))
94 return view->controller();
110ViewWrapper::ViewWrapper(
QObject *item)
115ViewWrapper::ViewWrapper(QQuickItem *item)
121QRect ViewWrapper::geometry()
const
124 if (
QWindow *w = m_item->window()) {
125 return w->geometry();
134 return m_item->mapToGlobal(localPt).toPoint();
139 return m_item->mapFromGlobal(globalPt).toPoint();
142void ViewWrapper::setGeometry(
QRect rect)
148std::shared_ptr<Core::View> ViewWrapper::childViewAt(
QPoint p)
const
150 auto child = m_item->childAt(p.
x(), p.
y());
154std::shared_ptr<Core::Window> ViewWrapper::window()
const
156 if (
QWindow *w = m_item->window()) {
157 auto windowqtquick =
new Window(w);
158 return std::shared_ptr<Core::Window>(windowqtquick);
164bool ViewWrapper::isRootView()
const
169void ViewWrapper::setVisible(
bool is)
172 if (
QWindow *w = m_item->window()) {
173 if (is && !w->isVisible()) {
175 }
else if (!is && w->isVisible()) {
181 m_item->setVisible(is);
184bool ViewWrapper::isVisible()
const
186 if (
QWindow *w = m_item->window()) {
191 return m_item->isVisible();
194bool ViewWrapper::isExplicitlyHidden()
const
196 auto priv = QQuickItemPrivate::get(m_item);
197 return !priv->explicitVisible;
200void ViewWrapper::move(
int x,
int y)
203 if (
QWindow *w = m_item->window()) {
204 w->setPosition(x, y);
214void ViewWrapper::activateWindow()
216 if (
QWindow *w = m_item->window())
217 w->requestActivate();
220bool ViewWrapper::isMaximized()
const
222 if (
QWindow *w = m_item->window())
228bool ViewWrapper::isMinimized()
const
230 if (
QWindow *w = m_item->window())
236QSize ViewWrapper::maxSizeHint()
const
238 if (
auto view = unwrap()) {
239 return view->maxSizeHint();
241 const QSize max = m_item->property(
"kddockwidgets_max_size").toSize();
242 return max.
isEmpty() ? Core::Item::hardcodedMaximumSize
243 : max.
boundedTo(Core::Item::hardcodedMaximumSize);
247void ViewWrapper::setSize(
int w,
int h)
250 if (
QWindow *window = m_item->window()) {
251 QRect windowGeo = window->geometry();
253 window->setGeometry(windowGeo);
257 m_item->setSize(
QSizeF(w, h));
262 if (t == Core::ViewType::ViewWrapper)
267 case Core::ViewType::Frame:
268 return qobject_cast<Group *>(m_item);
269 case Core::ViewType::TitleBar:
270 return qobject_cast<TitleBar *>(m_item);
271 case Core::ViewType::TabBar:
272 return qobject_cast<TabBar *>(m_item);
273 case Core::ViewType::Stack:
274 return qobject_cast<Stack *>(m_item);
275 case Core::ViewType::FloatingWindow:
276 return qobject_cast<FloatingWindow *>(m_item);
277 case Core::ViewType::Separator:
278 return qobject_cast<Separator *>(m_item);
279 case Core::ViewType::DockWidget:
280 return qobject_cast<QtQuick::DockWidget *>(m_item);
281 case Core::ViewType::SideBar:
284 case Core::ViewType::MainWindow:
285 return qobject_cast<QtQuick::MainWindow *>(m_item);
286 case Core::ViewType::DropArea:
287 return qobject_cast<DropArea *>(m_item);
288 case Core::ViewType::MDILayout:
289 return qobject_cast<MDILayout *>(m_item);
290 case Core::ViewType::RubberBand:
291 return qobject_cast<RubberBand *>(m_item);
292 case Core::ViewType::LayoutItem:
293 case Core::ViewType::None:
294 case Core::ViewType::DropAreaIndicatorOverlay:
295 qWarning() << Q_FUNC_INFO <<
"These are framework internals that are not wrapped";
297 case Core::ViewType::ViewWrapper:
301 qWarning() << Q_FUNC_INFO <<
"Unknown type" <<
static_cast<int>(t);
305std::shared_ptr<Core::View> ViewWrapper::rootView()
const
307 if (Core::Window::Ptr window = this->window())
308 return window->rootView();
310 qWarning() << Q_FUNC_INFO <<
"No window present";
314std::shared_ptr<Core::View> ViewWrapper::parentView()
const
319void ViewWrapper::grabMouse()
324void ViewWrapper::releaseMouse()
326 m_item->ungrabMouse();
331 if (
auto view = unwrap()) {
332 return view->focusPolicy();
342 m_item->QQuickItem::setFocus(
true, reason);
343 m_item->forceActiveFocus(reason);
348 if (
auto view = unwrap()) {
349 view->setFocusPolicy(policy);
351 qWarning() << Q_FUNC_INFO <<
"Not implemented for QtQuick";
355bool ViewWrapper::hasFocus()
const
357 return m_item->hasActiveFocus();
360QString ViewWrapper::viewName()
const
362 return m_item->objectName();
365bool ViewWrapper::isNull()
const
367 return m_item.
data() ==
nullptr;
370void ViewWrapper::setWindowTitle(
const QString &title)
372 if (
QWindow *w = m_item->window())
382 return parentItem->mapFromGlobal(m_item->mapToGlobal(pos)).toPoint();
387 if (
auto view = unwrap()) {
389 return view->hasAttribute(attr);
391 qFatal(
"not implemented");
398 m_item->QQuickItem::setCursor(shape);
401QSize ViewWrapper::minSize()
const
403 if (
auto view = unwrap()) {
405 return view->minSize();
407 const QSize min = m_item->property(
"kddockwidgets_min_size").toSize();
408 return min.
expandedTo(Core::Item::hardcodedMinimumSize);
415 const auto childItems = m_item->childItems();
416 result.
reserve(childItems.size());
417 for (QQuickItem *child : childItems) {
424void ViewWrapper::setParent(
View *parent)
426 if (
auto view = unwrap()) {
427 view->setParent(parent);
430 m_item->QQuickItem::setParent(parentItem);
431 m_item->QQuickItem::setParentItem(parentItem);
434 m_item->setVisible(
false);
437bool ViewWrapper::close()
444 return qobject_cast<QtQuick::View *>(m_item);
449 return qobject_cast<const QtQuick::View *>(m_item);
452void ViewWrapper::raiseAndActivate()
458std::shared_ptr<Core::View> ViewWrapper::create(
QObject *item)
460 return create(qobject_cast<QQuickItem *>(item));
464std::shared_ptr<Core::View> ViewWrapper::create(QQuickItem *item)
470 auto sharedptr = std::shared_ptr<View>(wrapper);
471 wrapper->d->m_thisWeakPtr = sharedptr;
QPoint toPoint() const const
void setSize(const QSize &size)
QPoint topLeft() const const
QSize boundedTo(const QSize &otherSize) const const
QSize expandedTo(const QSize &otherSize) const const
bool isEmpty() const const
The QQuickItem counter part of TabWidgetQuick. Handles GUI while TabWidget handles state.
Implements a QTabWidget derived class with support for docking and undocking KDockWidget::DockWidget ...