qml: Layout the drop area and title bar inside the FloatingWindow
We could just control geometry of the c++ title bar and geometry,
but then the user wouldn't be able to style it, and users rather
style things in QML than subclassing FloatingWindow and writing C++.
So instance some .qml files to represent the drop area and floating
window, so user can muck with.
Hierarchy looks like this now:
-QQuickWindow
--FloatingWindowQuick (C++ QQuickItem)
---FloatingWindow.qml
----TitleBar.qml (reads state from TitleBar c++)
----DropArea.qml
-----DropArea (C++ QQuickItem)
------Frame
etc
This commit is contained in:
@@ -30,10 +30,13 @@ class DropArea;
|
||||
class Frame;
|
||||
class MultiSplitter;
|
||||
|
||||
class DOCKS_EXPORT FloatingWindow : public QWidgetAdapter
|
||||
, public Draggable
|
||||
class DOCKS_EXPORT FloatingWindow
|
||||
: public QWidgetAdapter
|
||||
, public Draggable
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(KDDockWidgets::TitleBar* titleBar READ titleBar CONSTANT)
|
||||
Q_PROPERTY(KDDockWidgets::DropArea* dropArea READ dropArea CONSTANT)
|
||||
public:
|
||||
explicit FloatingWindow(MainWindowBase *parent = nullptr);
|
||||
explicit FloatingWindow(Frame *frame, MainWindowBase *parent = nullptr);
|
||||
|
||||
@@ -40,6 +40,14 @@ void FloatingWindowQuick::init()
|
||||
{
|
||||
m_quickWindow->setResizeMode(QQuickView::SizeViewToRootObject);
|
||||
QWidgetAdapter::setParent(m_quickWindow->contentItem());
|
||||
|
||||
QQuickItem *visualItem = createItem(Config::self().qmlEngine(), QStringLiteral("qrc:/kddockwidgets/private/quick/qml/FloatingWindow.qml"));
|
||||
Q_ASSERT(visualItem);
|
||||
visualItem->setParent(this);
|
||||
visualItem->setParentItem(this);
|
||||
|
||||
//dropArea()->QWidgetAdapter::setParent(visualItem);
|
||||
|
||||
m_quickWindow->setFlags(windowFlags());
|
||||
m_quickWindow->show();
|
||||
m_quickWindow->setGeometry(200, 200, 800, 800); // TODO: remove
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <QResizeEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QWindow>
|
||||
#include <QQmlComponent>
|
||||
#include <QQuickItem>
|
||||
#include <QQmlEngine>
|
||||
|
||||
using namespace KDDockWidgets;
|
||||
|
||||
@@ -211,6 +214,18 @@ Qt::WindowFlags QWidgetAdapter::windowFlags() const
|
||||
return m_requestedWindowFlags;
|
||||
}
|
||||
|
||||
QQuickItem *QWidgetAdapter::createItem(QQmlEngine *engine, const QString &filename) const
|
||||
{
|
||||
QQmlComponent component(engine, filename);
|
||||
QObject *obj = component.create();
|
||||
if (!obj) {
|
||||
qWarning() << Q_FUNC_INFO << component.errorString();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return qobject_cast<QQuickItem*>(obj);
|
||||
}
|
||||
|
||||
void QWidgetAdapter::setFlag(Qt::WindowType f, bool on)
|
||||
{
|
||||
if (QWindow *w = windowHandle()) {
|
||||
|
||||
@@ -30,32 +30,12 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QWindow;
|
||||
class QQmlEngine;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace KDDockWidgets {
|
||||
|
||||
class FloatingWindow;
|
||||
/*
|
||||
class QuickItem : public QQuickItem
|
||||
{
|
||||
public:
|
||||
explicit QuickItem(QQuickItem *parent)
|
||||
: QQuickItem(parent)
|
||||
{
|
||||
}
|
||||
~QuickItem() override;
|
||||
|
||||
QRect geometry() const { return {}; }
|
||||
void setGeometry(QRect) {}
|
||||
|
||||
void releaseMouse()
|
||||
{
|
||||
ungrabMouse();
|
||||
}
|
||||
};
|
||||
QuickItem::~QuickItem() {}
|
||||
*/
|
||||
|
||||
class DOCKS_EXPORT QWidgetAdapter : public QQuickItem
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -125,9 +105,9 @@ public:
|
||||
|
||||
Qt::WindowFlags windowFlags() const;
|
||||
|
||||
QQuickItem *createItem(QQmlEngine *, const QString &filename) const;
|
||||
protected:
|
||||
void raiseAndActivate();
|
||||
|
||||
virtual bool onResize(QSize newSize);
|
||||
virtual void onLayoutRequest();
|
||||
virtual void onMousePress();
|
||||
|
||||
@@ -24,4 +24,5 @@ void KDDockWidgets::registerQmlTypes()
|
||||
qmlRegisterType<MainWindowQuick>("com.kdab.dockwidgets", 1, 0, "MainWindowQuick");
|
||||
|
||||
qmlRegisterUncreatableType<TitleBar>("com.kdab.dockwidgets", 1, 0, "TitleBar", QStringLiteral("Enum access only"));
|
||||
qRegisterMetaType<DropArea*>();
|
||||
}
|
||||
|
||||
18
src/private/quick/qml/DropArea.qml
Normal file
18
src/private/quick/qml/DropArea.qml
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2019-2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
|
||||
Author: Sérgio Martins <sergio.martins@kdab.com>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
*/
|
||||
|
||||
import QtQuick 2.9
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
property QtObject dropAreaCpp: null
|
||||
color: "orange"
|
||||
}
|
||||
52
src/private/quick/qml/FloatingWindow.qml
Normal file
52
src/private/quick/qml/FloatingWindow.qml
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2019-2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
|
||||
Author: Sérgio Martins <sergio.martins@kdab.com>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
*/
|
||||
|
||||
import QtQuick 2.9
|
||||
import "." as KDDW
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
readonly property QtObject floatingWindowCpp: parent
|
||||
readonly property QtObject titleBarCpp: floatingWindowCpp ? floatingWindowCpp.titleBar : null
|
||||
readonly property QtObject dropAreaCpp: floatingWindowCpp ? floatingWindowCpp.dropArea : null
|
||||
|
||||
color: "yellow"
|
||||
anchors.fill: parent
|
||||
|
||||
KDDW.TitleBar {
|
||||
id: titleBar
|
||||
height: 30
|
||||
titleBarCpp: root.titleBarCpp
|
||||
|
||||
anchors {
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
}
|
||||
|
||||
KDDW.DropArea {
|
||||
id: dropArea
|
||||
dropAreaCpp: root.dropAreaCpp
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
top: titleBar.bottom
|
||||
bottom: parent.bottom
|
||||
}
|
||||
}
|
||||
|
||||
onDropAreaCppChanged: {
|
||||
// Parent the cpp obj to the visual obj. So the user can style it
|
||||
dropAreaCpp.parent = dropArea;
|
||||
dropAreaCpp.anchors.fill = dropArea;
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,15 @@ import QtQuick 2.9
|
||||
Rectangle {
|
||||
id: root
|
||||
property QtObject frameCpp
|
||||
readonly property QtObject titleBarCpp: frameCpp ? frameCpp.titleBar : null
|
||||
|
||||
color: "cyan"
|
||||
anchors.fill: parent
|
||||
|
||||
TitleBar {
|
||||
height: 30
|
||||
titleBarCpp: frameCpp ? frameCpp.titleBar : null
|
||||
titleBarCpp: root.titleBarCpp
|
||||
visible: true
|
||||
anchors {
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/kddockwidgets/">
|
||||
<file>private/quick/qml/DropArea.qml</file>
|
||||
<file>private/quick/qml/FloatingWindow.qml</file>
|
||||
<file>private/quick/qml/Frame.qml</file>
|
||||
<file>private/quick/qml/MainWindow.qml</file>
|
||||
<file>private/quick/qml/Separator.qml</file>
|
||||
|
||||
Reference in New Issue
Block a user