1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/*
This file is part of KDDockWidgets.
SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Sergio 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.
*/
#include <kddockwidgets/Config.h>
#include <kddockwidgets/core/DockRegistry.h>
#include <kddockwidgets/qtquick/views/DockWidget.h>
#include <kddockwidgets/qtquick/Platform.h>
#include <kddockwidgets/qtquick/ViewFactory.h>
#include <kddockwidgets/qtquick/views/MainWindow.h>
#include <QQuickView>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
/// A playground for playing with styling
class CustomViewFactory : public KDDockWidgets::QtQuick::ViewFactory
{
public:
~CustomViewFactory() override;
QUrl dockwidgetFilename() const override
{
return QUrl("qrc:/MyDockWidget.qml");
}
QUrl titleBarFilename() const override
{
return KDDockWidgets::QtQuick::ViewFactory::titleBarFilename();
}
QUrl separatorFilename() const override
{
return KDDockWidgets::QtQuick::ViewFactory::separatorFilename();
}
QUrl groupFilename() const override
{
return KDDockWidgets::QtQuick::ViewFactory::groupFilename();
}
QUrl floatingWindowFilename() const override
{
return KDDockWidgets::QtQuick::ViewFactory::floatingWindowFilename();
}
};
CustomViewFactory::~CustomViewFactory() = default;
int main(int argc, char *argv[])
{
#ifdef Q_OS_WIN
QGuiApplication::setAttribute(Qt::AA_UseOpenGLES);
#endif
QGuiApplication app(argc, argv);
KDDockWidgets::initFrontend(KDDockWidgets::FrontendType::QtQuick);
auto &config = KDDockWidgets::Config::self();
auto flags = config.flags() | KDDockWidgets::Config::Flag_TitleBarIsFocusable;
config.setFlags(flags);
config.setViewFactory(new CustomViewFactory());
QQmlApplicationEngine appEngine;
KDDockWidgets::QtQuick::Platform::instance()->setQmlEngine(&appEngine);
appEngine.load((QUrl("qrc:/main.qml")));
auto dw1 = new KDDockWidgets::QtQuick::DockWidget("Dock #1");
dw1->setGuestItem(QStringLiteral("qrc:/Guest1.qml"));
dw1->resize(QSize(800, 800));
dw1->open();
auto dw2 = new KDDockWidgets::QtQuick::DockWidget("Dock #2");
dw2->setGuestItem(QStringLiteral("qrc:/Guest2.qml"));
dw2->resize(QSize(800, 800));
dw2->open();
auto dw3 = new KDDockWidgets::QtQuick::DockWidget("Dock #3");
dw3->setGuestItem(QStringLiteral("qrc:/Guest3.qml"));
dw1->addDockWidgetToContainingWindow(dw3, KDDockWidgets::Location_OnRight);
// Access the main area we created in QML with DockingArea {}
auto mainArea = KDDockWidgets::DockRegistry::self()->mainDockingAreas().constFirst();
mainArea->addDockWidget(dw2, KDDockWidgets::Location_OnTop);
return app.exec();
}
|