Progress with the QtQuick port

This commit is contained in:
Sergio Martins
2019-09-04 18:43:54 +01:00
parent 3b041c3145
commit abbc79f0e0
38 changed files with 480 additions and 77 deletions

1
.gitignore vendored
View File

@@ -36,3 +36,4 @@ fuzzer
custom_titlebar
libkddockwidgets.so
*.depends
kddockwidgets_basic_quick

View File

@@ -42,7 +42,10 @@ endif()
add_subdirectory(src)
if (OPTION_DEVELOPER_MODE AND NOT OPTION_QTQUICK)
add_subdirectory(tests)
if (OPTION_DEVELOPER_MODE)
if (NOT OPTION_QTQUICK)
add_subdirectory(tests)
endif()
add_subdirectory(examples)
endif()

View File

@@ -1,2 +1,6 @@
add_subdirectory(basic)
add_subdirectory(custom_titlebar)
if (OPTION_QTQUICK)
add_subdirectory(basic_quick)
else()
add_subdirectory(basic)
add_subdirectory(custom_titlebar)
endif()

View File

@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.12)
project(kddockwidgets_basic_quick)
find_package(Qt5Quick)
set(EXAMPLE_SRCS
main.cpp
)
qt5_add_resources(RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/resources.qrc)
include_directories(${CMAKE_SOURCE_DIR}/src/)
add_executable(kddockwidgets_basic_quick ${EXAMPLE_SRCS} ${RESOURCES})
target_link_libraries(kddockwidgets_basic_quick kddockwidgets Qt5::Quick)
install(TARGETS kddockwidgets_basic_quick DESTINATION bin)

View File

@@ -0,0 +1,48 @@
/*
This file is part of KDDockWidgets.
Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
Author: Sérgio Martins <sergio.martins@kdab.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "DockRegistry_p.h"
#include "Config.h"
#include <QQuickView>
#include <QGuiApplication>
int main(int argc, char **argv)
{
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QGuiApplication app(argc, argv);
app.setOrganizationName(QStringLiteral("KDAB"));
app.setApplicationName(QStringLiteral("Test app"));
KDDockWidgets::DockRegistry::self(); // TODO: Remove. Right now registers qml types.
QQuickView view;
KDDockWidgets::Config::self().setQmlEngine(view.engine());
view.setSource(QUrl("qrc:/main.qml"));
view.resize(500, 500);
view.show();
return app.exec();
}

View File

@@ -0,0 +1,9 @@
import QtQuick 2.9
import "qrc:/kddockwidgets/quick/qml" // TODO
MainWindow {
id: root
uniqueName: "MainWindow1"
}

View File

@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>

View File

@@ -67,6 +67,7 @@ set(DOCKS_INSTALLABLE_PRIVATE_WIDGET_INCLUDES
if (OPTION_QTQUICK)
set(DOCKSLIBS_SRCS ${DOCKSLIBS_SRCS}
quick/QmlTypes.cpp
quick/QWidgetAdapter_quick.cpp
quick/QWidgetAdapter_quick_p.h
quick/FrameQuick.cpp
@@ -76,6 +77,7 @@ if (OPTION_QTQUICK)
quick/FloatingWindowQuick.cpp
quick/FloatingWindowQuick_p.h
quick/LayoutSaverQuick.cpp
quick/MainWindowQuick.cpp
quick/SeparatorQuick.cpp
quick/SeparatorQuick_p.h
quick/TabBarQuick.cpp
@@ -83,8 +85,10 @@ if (OPTION_QTQUICK)
quick/TabWidgetQuick.cpp
quick/TabWidgetQuick_p.h
quick/TitleBarQuick.cpp
quick/TitleBarQuick_p.h
)
quick/TitleBarQuick_p.h)
qt5_add_resources(RESOURCES_QUICK ${CMAKE_CURRENT_SOURCE_DIR}/qtquick.qrc)
else()
set(DOCKSLIBS_SRCS ${DOCKSLIBS_SRCS}
DebugWindow.cpp
@@ -119,7 +123,7 @@ endif()
qt5_add_resources(RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/resources.qrc)
add_library(kddockwidgets SHARED ${DOCKSLIBS_SRCS} ${DOCKS_INSTALLABLE_INCLUDES} ${RESOURCES})
add_library(kddockwidgets SHARED ${DOCKSLIBS_SRCS} ${DOCKS_INSTALLABLE_INCLUDES} ${RESOURCES} ${RESOURCES_QUICK})
target_include_directories(kddockwidgets
PUBLIC

View File

@@ -50,6 +50,7 @@ public:
void fixFlags();
QQmlEngine *m_qmlEngine = nullptr;
DockWidgetFactoryFunc m_dockWidgetFactoryFunc = nullptr;
FrameworkWidgetFactory *m_frameworkWidgetFactory;
Flags m_flags = Flag_Default;
@@ -137,6 +138,21 @@ void Config::setSeparatorThickness(int value, bool staticSeparator)
d->m_separatorThickness = value;
}
void Config::setQmlEngine(QQmlEngine *qmlEngine)
{
if (d->m_qmlEngine) {
qWarning() << Q_FUNC_INFO << "Already has QML engine";
return;
}
d->m_qmlEngine = qmlEngine;
}
QQmlEngine *Config::qmlEngine() const
{
return d->m_qmlEngine;
}
void Config::Private::fixFlags()
{
#if defined(Q_OS_WIN)

View File

@@ -30,10 +30,14 @@
#include "docks_export.h"
class QQmlEngine;
namespace KDDockWidgets
{
class DockWidgetBase;
class FrameworkWidgetFactory;
typedef KDDockWidgets::DockWidgetBase* (*DockWidgetFactoryFunc)(const QString &name);
/**
@@ -108,6 +112,11 @@ public:
///Note: Only use this function at startup before creating any DockWidget or MainWindow.
void setSeparatorThickness(int value, bool staticSeparator);
///@brief Sets the QQmlEngine to use. Applicable only when using QtQuick.
void setQmlEngine(QQmlEngine *);
QQmlEngine* qmlEngine() const;
private:
Q_DISABLE_COPY(Config)
Config();

View File

@@ -24,6 +24,7 @@
#include "DebugWindow_p.h"
#include "LastPosition_p.h"
#include "multisplitter/MultiSplitterLayout_p.h"
#include "quick/QmlTypes.h"
#include <QPointer>
#include <QDebug>
@@ -33,13 +34,17 @@ using namespace KDDockWidgets;
DockRegistry::DockRegistry(QObject *parent)
: QObject(parent)
{
#ifdef DOCKS_DEVELOPER_MODE
# ifdef KDDOCKWIDGETS_QTWIDGETS
#ifdef KDDOCKWIDGETS_QTWIDGETS
# ifdef DOCKS_DEVELOPER_MODE
if (qEnvironmentVariableIntValue("KDDOCKWIDGETS_SHOW_DEBUG_WINDOW") == 1) {
auto dv = new Debug::DebugWindow();
dv->show();
}
# endif
#else
KDDockWidgets::registerQmlTypes();
#endif
}

View File

@@ -30,7 +30,7 @@ class DOCKS_EXPORT DropAreaWithCentralFrame : public DropArea
{
Q_OBJECT
public:
explicit DropAreaWithCentralFrame(QWidgetOrQuick *parent = {}, MainWindowOptions options = {});
explicit DropAreaWithCentralFrame(QWidgetOrQuick *parent = {}, MainWindowOptions options = MainWindowOption_HasCentralFrame);
~DropAreaWithCentralFrame();
static Frame* createCentralFrame(MainWindowOptions options);

View File

@@ -39,6 +39,18 @@
using namespace KDDockWidgets;
class MainWindow::Private
{
public:
explicit Private(MainWindowOptions options, MainWindowBase *mainWindow)
: m_dropArea(new DropAreaWithCentralFrame(mainWindow, options))
{
}
DropAreaWithCentralFrame *const m_dropArea;
};
namespace KDDockWidgets {
class MyCentralWidget : public QWidget
{
@@ -66,6 +78,7 @@ MyCentralWidget::~MyCentralWidget() {}
MainWindow::MainWindow(const QString &name, MainWindowOptions options,
QWidget *parent, Qt::WindowFlags flags)
: MainWindowBase(name, options, parent, flags)
, d(new Private(options, this))
{
auto centralWidget = new MyCentralWidget(this);
auto layout = new QVBoxLayout(centralWidget);
@@ -78,4 +91,10 @@ MainWindow::MainWindow(const QString &name, MainWindowOptions options,
MainWindow::~MainWindow()
{
delete d;
}
DropAreaWithCentralFrame *MainWindow::dropArea() const
{
return d->m_dropArea;
}

View File

@@ -41,6 +41,11 @@ public:
QWidget *parent = nullptr, Qt::WindowFlags flags = {});
~MainWindow() override;
DropAreaWithCentralFrame *dropArea() const override;
private:
class Private;
Private *const d;
};
}

View File

@@ -42,10 +42,8 @@ using namespace KDDockWidgets;
class MainWindowBase::Private
{
public:
explicit Private(const QString &mainWindowName, MainWindowOptions options, MainWindowBase *mainWindow)
: m_dropArea(new DropAreaWithCentralFrame(mainWindow, options))
, name(mainWindowName)
, m_options(options)
explicit Private(MainWindowOptions options)
: m_options(options)
{
}
@@ -54,17 +52,16 @@ public:
return m_options & MainWindowOption_HasCentralFrame;
}
DropAreaWithCentralFrame *const m_dropArea;
const QString name;
QString name;
const MainWindowOptions m_options;
};
MainWindowBase::MainWindowBase(const QString &uniqueName, KDDockWidgets::MainWindowOptions options,
QWidget *parent, Qt::WindowFlags flags)
QWidgetOrQuick *parent, Qt::WindowFlags flags)
: QMainWindowOrQuick(parent, flags)
, d(new Private(uniqueName, options, this))
, d(new Private(options))
{
DockRegistry::self()->registerMainWindow(this);
setUniqueName(uniqueName);
}
MainWindowBase::~MainWindowBase()
@@ -79,7 +76,7 @@ void MainWindowBase::addDockWidgetAsTab(DockWidgetBase *widget)
qCDebug(addwidget) << Q_FUNC_INFO << widget;
if (d->supportsCentralFrame()) {
d->m_dropArea->m_centralFrame->addWidget(widget);
dropArea()->m_centralFrame->addWidget(widget);
} else {
qWarning() << Q_FUNC_INFO << "Not supported without MainWindowOption_HasCentralFrame";
}
@@ -87,7 +84,7 @@ void MainWindowBase::addDockWidgetAsTab(DockWidgetBase *widget)
void MainWindowBase::addDockWidget(DockWidgetBase *dw, Location location, DockWidgetBase *relativeTo, AddingOption option)
{
d->m_dropArea->addDockWidget(dw, location, relativeTo, option);
dropArea()->addDockWidget(dw, location, relativeTo, option);
}
QString MainWindowBase::uniqueName() const
@@ -100,16 +97,24 @@ MainWindowOptions MainWindowBase::options() const
return d->m_options;
}
DropArea *MainWindowBase::dropArea() const
{
return d->m_dropArea;
}
MultiSplitterLayout *MainWindowBase::multiSplitterLayout() const
{
return d->m_dropArea->multiSplitterLayout();
return dropArea()->multiSplitterLayout();
}
void MainWindowBase::setUniqueName(const QString &uniqueName)
{
if (uniqueName.isEmpty())
return;
if (d->name.isEmpty()) {
d->name = uniqueName;
Q_EMIT uniqueNameChanged();
DockRegistry::self()->registerMainWindow(this);
} else {
qWarning() << Q_FUNC_INFO << "Already has a name." << this->uniqueName() << uniqueName;
}
}
bool MainWindowBase::fillFromDataStream(QDataStream &ds)
{

View File

@@ -43,6 +43,7 @@ class DockWidgetBase;
class Frame;
class DropArea;
class MultiSplitterLayout;
class DropAreaWithCentralFrame;
class DOCKS_EXPORT MainWindowBase : public QMainWindowOrQuick
{
@@ -50,7 +51,7 @@ class DOCKS_EXPORT MainWindowBase : public QMainWindowOrQuick
public:
typedef QVector<MainWindowBase*> List;
explicit MainWindowBase(const QString &uniqueName, MainWindowOptions options = MainWindowOption_HasCentralFrame,
QWidget *parent = nullptr, Qt::WindowFlags flags = {});
QWidgetOrQuick *parent = nullptr, Qt::WindowFlags flags = {});
~MainWindowBase() override;
void addDockWidgetAsTab(DockWidgetBase *);
@@ -61,12 +62,18 @@ public:
///@internal
///@brief returns the drop area.
DropArea *dropArea() const;
virtual DropAreaWithCentralFrame *dropArea() const = 0;
///@internal
///@brief returns the MultiSplitterLayout.
MultiSplitterLayout* multiSplitterLayout() const;
protected:
void setUniqueName(const QString &uniqueName);
Q_SIGNALS:
void uniqueNameChanged();
private:
class Private;
Private *const d;

View File

@@ -31,6 +31,12 @@ Separator::Separator(KDDockWidgets::Anchor *anchor, QWidgetAdapter *parent)
{
Q_ASSERT(anchor);
setVisible(true);
const int thickness = Anchor::thickness(isStatic());
if (isVertical())
setFixedWidth(thickness);
else
setFixedHeight(thickness);
}
bool Separator::isVertical() const
@@ -65,3 +71,12 @@ void Separator::onMouseRelease()
Q_ASSERT(!m_anchor->isFollowing());
m_anchor->onMouseReleased();
}
void Separator::move(int p)
{
if (isVertical()) {
QWidgetAdapter::move(p, y());
} else {
QWidgetAdapter::move(x(), p);
}
}

View File

@@ -32,14 +32,16 @@ class Anchor;
class DOCKS_EXPORT Separator : public QWidgetAdapter
{
Q_OBJECT
Q_PROPERTY(bool isVertical READ isVertical CONSTANT)
Q_PROPERTY(bool isStatic READ isStatic CONSTANT)
//Q_PROPERTY(int position READ position NOTIFY positionChanged)
public:
explicit Separator(Anchor *anchor, QWidgetAdapter *parent = nullptr);
bool isVertical() const;
bool isStatic() const;
int position() const;
void move(int p);
const QPointer<Anchor> anchor() const { return m_anchor; }
virtual void move(int p) = 0;
protected:
void onMousePress() override;

7
src/qtquick.qrc Normal file
View File

@@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/kddockwidgets/">
<file>quick/qml/Frame.qml</file>
<file>quick/qml/MainWindow.qml</file>
<file>quick/qml/Separator.qml</file>
</qresource>
</RCC>

View File

@@ -26,11 +26,21 @@
*/
#include "FrameQuick_p.h"
#include "Config.h"
#include <QDebug>
using namespace KDDockWidgets;
FrameQuick::FrameQuick(QWidgetAdapter *parent, Options options)
: Frame(parent, options)
{
qDebug() << Q_FUNC_INFO << "Created frame";
auto component = new QQmlComponent(Config::self().qmlEngine(),
QUrl(QStringLiteral("qrc:/kddockwidgets/quick/qml/Frame.qml")));
auto separatorItem = static_cast<QQuickItem*>(component->create());
separatorItem->setParentItem(this);
separatorItem->setParent(this);
}

View File

@@ -0,0 +1,47 @@
/*
This file is part of KDDockWidgets.
Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
Author: Sérgio Martins <sergio.martins@kdab.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MainWindowQuick_p.h"
#include <QDebug>
using namespace KDDockWidgets;
MainWindowQuick::MainWindowQuick()
: MainWindowBase(QString(), MainWindowOption_HasCentralFrame)
{
qDebug() << "Created";
}
DropAreaWithCentralFrame *MainWindowQuick::dropArea() const
{
return m_dropArea;
}
void MainWindowQuick::setDropArea(DropAreaWithCentralFrame *dropArea)
{
if (m_dropArea) {
qWarning() << Q_FUNC_INFO << "Already contains a drop area!";
return;
}
qDebug() << "Got drop area";
m_dropArea = dropArea;
Q_EMIT dropAreaChanged();
}

View File

@@ -0,0 +1,46 @@
/*
This file is part of KDDockWidgets.
Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
Author: Sérgio Martins <sergio.martins@kdab.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KD_MAIN_WINDOW_QUICK_P_H
#define KD_MAIN_WINDOW_QUICK_P_H
#include "MainWindowBase.h"
namespace KDDockWidgets {
class MainWindowQuick : public MainWindowBase
{
Q_OBJECT
Q_PROPERTY(QString uniqueName READ uniqueName WRITE setUniqueName NOTIFY uniqueNameChanged)
Q_PROPERTY(KDDockWidgets::DropAreaWithCentralFrame* dropArea READ dropArea WRITE setDropArea NOTIFY dropAreaChanged)
public:
MainWindowQuick();
protected:
DropAreaWithCentralFrame *dropArea() const override;
void setDropArea(DropAreaWithCentralFrame*);
Q_SIGNALS:
void dropAreaChanged();
private:
DropAreaWithCentralFrame *m_dropArea = nullptr;
};
}
#endif

View File

@@ -39,9 +39,10 @@
using namespace KDDockWidgets;
QWidgetAdapter::QWidgetAdapter(QObject *parent, Qt::WindowFlags)
: QObject (parent)
QWidgetAdapter::QWidgetAdapter(QQuickItem *parent, Qt::WindowFlags)
: QQuickItem(parent)
{
this->setParent(parent); // also set parentItem
}
QWidgetAdapter::~QWidgetAdapter()
@@ -69,27 +70,68 @@ FloatingWindow * QWidgetAdapter::floatingWindow() const
QRect QWidgetAdapter::geometry() const
{
return {};
QRect r = rect();
r.moveTopLeft(QPointF(x(), y()).toPoint());
return r;
}
QRect QWidgetAdapter::rect() const
{
return {};
return QRectF(0, 0, width(), height()).toRect();
}
void QWidgetAdapter::show()
{
setVisible(true);
}
void QWidgetAdapter::setGeometry(QRect) {}
void QWidgetAdapter::setVisible(bool) {}
void QWidgetAdapter::setFixedHeight(int height)
{
qDebug() << Q_FUNC_INFO << height << this;
setHeight(height);
}
void QWidgetAdapter::setFixedWidth(int width)
{
qDebug() << Q_FUNC_INFO << width << this;
setWidth(width);
}
void QWidgetAdapter::setGeometry(QRect rect)
{
qDebug() << Q_FUNC_INFO << rect << this;
setWidth(rect.width());
setHeight(rect.height());
setX(rect.x());
setY(rect.y());
}
void QWidgetAdapter::grabMouse() {}
void QWidgetAdapter::releaseMouse() {}
void QWidgetAdapter::setMinimumSize(QSize) {}
void QWidgetAdapter::resize(QSize) {}
void QWidgetAdapter::resize(QSize sz)
{
qDebug() << Q_FUNC_INFO << sz << this;
setWidth(sz.width());
setHeight(sz.height());
}
QWindow *QWidgetAdapter::windowHandle() const { return nullptr; }
void QWidgetAdapter::move(int x, int y)
{
qDebug() << Q_FUNC_INFO << x << y << this;
setX(x);
setY(y);
}
void QWidgetAdapter::setParent(QQuickItem *p)
{
QQuickItem::setParent(p);
QQuickItem::setParentItem(p);
}
void QWidgetAdapter::setFlag(Qt::WindowType f, bool on)
{
if (auto w = windowHandle()) {

View File

@@ -62,11 +62,11 @@ public:
QuickItem::~QuickItem() {}
*/
class DOCKS_EXPORT QWidgetAdapter : public QObject
class DOCKS_EXPORT QWidgetAdapter : public QQuickItem
{
Q_OBJECT
public:
explicit QWidgetAdapter(QObject *parent = nullptr, Qt::WindowFlags f = {});
explicit QWidgetAdapter(QQuickItem *parent = nullptr, Qt::WindowFlags f = {});
~QWidgetAdapter() override;
///@brief returns the FloatingWindow this widget is in, otherwise nullptr
@@ -74,17 +74,18 @@ public:
void setFlag(Qt::WindowType, bool on = true);
int x() const { return int(QQuickItem::x()); }
int y() const { return int(QQuickItem::y()); }
int width() const { return int(QQuickItem::width()); }
int height() const { return int(QQuickItem::height()); }
void setGeometry(QRect);
QRect geometry() const;
QRect rect() const;
void show();
bool isVisible() const { return true; }
void setVisible(bool);
void setEnabled(bool) {}
int width() const { return 0; }
int height() const { return 0; }
void setFixedHeight(int) {}
void setFixedWidth(int) {}
void setFixedHeight(int);
void setFixedWidth(int);
void raise();
void update() {}
QSize size() const {return {}; }
@@ -92,8 +93,6 @@ public:
QSize minimumSize() const {return {}; }
int minimumHeight() const {return {};}
int minimumWidth() const {return {};}
int x() const { return 0; }
int y() const { return 0; }
void grabMouse();
void releaseMouse();
@@ -112,6 +111,9 @@ public:
void setWindowIcon(const QIcon &) {}
void close() {}
QWidgetAdapter* childAt(QPoint) { return nullptr; }
void move(int x, int y);
void setParent(QQuickItem*);
protected:
void raiseAndActivate();

33
src/quick/QmlTypes.cpp Normal file
View File

@@ -0,0 +1,33 @@
/*
This file is part of KDDockWidgets.
Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
Author: Sérgio Martins <sergio.martins@kdab.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "QmlTypes.h"
#include "DropAreaWithCentralFrame_p.h"
#include "quick/MainWindowQuick_p.h"
#include <QQmlEngine>
#include <QDebug>
void KDDockWidgets::registerQmlTypes()
{
qDebug() << "Registering types";
qmlRegisterType<DropAreaWithCentralFrame>("com.kdab.dockwidgets", 1, 0, "DropAreaWithCentralFrame");
qmlRegisterType<MainWindowQuick>("com.kdab.dockwidgets", 1, 0, "MainWindowQuick");
}

23
src/quick/QmlTypes.h Normal file
View File

@@ -0,0 +1,23 @@
/*
This file is part of KDDockWidgets.
Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
Author: Sérgio Martins <sergio.martins@kdab.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace KDDockWidgets {
void registerQmlTypes();
}

View File

@@ -22,18 +22,20 @@
#include "multisplitter/MultiSplitterLayout_p.h"
#include "multisplitter/Anchor_p.h"
#include "Logging_p.h"
#include "Config.h"
#include <QQmlComponent>
using namespace KDDockWidgets;
SeparatorQuick::SeparatorQuick(KDDockWidgets::Anchor *anchor, QWidgetAdapter *parent)
: Separator(anchor, parent)
{
auto component = new QQmlComponent(Config::self().qmlEngine(),
QUrl(QStringLiteral("qrc:/kddockwidgets/quick/qml/Separator.qml")));
auto separatorItem = static_cast<QQuickItem*>(component->create());
separatorItem->setParentItem(this);
separatorItem->setParent(this);
}
void SeparatorQuick::move(int )
{
}

View File

@@ -33,8 +33,6 @@ public:
explicit SeparatorQuick(Anchor *anchor, QWidgetAdapter *parent = nullptr);
protected:
virtual void move(int p) override;
/* void paintEvent(QPaintEvent *) override;
void enterEvent(QEvent *) override;
void leaveEvent(QEvent *) override;*/

View File

@@ -32,7 +32,8 @@
using namespace KDDockWidgets;
TabBarQuick::TabBarQuick(TabWidget *parent)
: TabBar(nullptr, parent) // TODO replace nullptr
: QWidgetAdapter(parent->asWidget())
, TabBar(this, parent)
{
}

View File

@@ -37,7 +37,7 @@ namespace KDDockWidgets {
class DockWidget;
class TabWidget;
class DOCKS_EXPORT TabBarQuick : public TabBar
class DOCKS_EXPORT TabBarQuick : public QWidgetAdapter, public TabBar
{
public:

View File

@@ -33,7 +33,7 @@
using namespace KDDockWidgets;
TabWidgetQuick::TabWidgetQuick(Frame *parent)
: TabWidget(nullptr, parent) // TODO replace nullptr
: TabWidget(this, parent)
, m_tabBar(Config::self().frameWorkWidgetFactory()->createTabBar(this))
{
}

View File

@@ -35,7 +35,7 @@ namespace KDDockWidgets {
class Frame;
class TabBar;
class DOCKS_EXPORT TabWidgetQuick : public TabWidget
class DOCKS_EXPORT TabWidgetQuick : public TabWidget, public QWidgetAdapter
{
public:
explicit TabWidgetQuick(Frame *parent);

7
src/quick/qml/Frame.qml Normal file
View File

@@ -0,0 +1,7 @@
import QtQuick 2.9
Rectangle {
id: root
color: "cyan"
anchors.fill: parent
}

View File

@@ -0,0 +1,18 @@
import QtQuick 2.9
import com.kdab.dockwidgets 1.0
MainWindowQuick {
id: root
dropArea: dropArea
anchors.fill: parent
Item {
id: centralItem // mimic the hierarchy of QtWidgets
anchors.fill: parent
DropAreaWithCentralFrame {
id: dropArea
anchors.fill: parent
}
}
}

View File

@@ -0,0 +1,8 @@
import QtQuick 2.9
Rectangle {
id: root
anchors.fill: parent
color: "red"
}

View File

@@ -31,24 +31,9 @@ using namespace KDDockWidgets;
SeparatorWidget::SeparatorWidget(KDDockWidgets::Anchor *anchor, QWidgetAdapter *parent)
: Separator(anchor, parent)
{
const int thickness = Anchor::thickness(isStatic());
if (isVertical())
setFixedWidth(thickness);
else
setFixedHeight(thickness);
setMouseTracking(true);
}
void SeparatorWidget::move(int p)
{
if (isVertical()) {
QWidget::move(p, y());
} else {
QWidget::move(x(), p);
}
}
void SeparatorWidget::paintEvent(QPaintEvent *)
{
if (!anchor())

View File

@@ -34,8 +34,6 @@ public:
explicit SeparatorWidget(Anchor *anchor, QWidgetAdapter *parent = nullptr);
protected:
virtual void move(int p) override;
void paintEvent(QPaintEvent *) override;
void enterEvent(QEvent *) override;
void leaveEvent(QEvent *) override;

View File

@@ -37,6 +37,7 @@
#include "LastPosition_p.h"
#include "utils.h"
#include "FrameworkWidgetFactory.h"
#include "DropAreaWithCentralFrame_p.h"
#include <QtTest/QtTest>
#include <QPainter>