qtquick: Add example of custom tabBar
Will do some styling in a follow up
This commit is contained in:
@@ -23,3 +23,9 @@ set_compiler_flags(qtquick_customtitlebar)
|
||||
set_target_properties(
|
||||
qtquick_customtitlebar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples/"
|
||||
)
|
||||
|
||||
add_subdirectory(customtabbar)
|
||||
set_compiler_flags(qtquick_customtabbar)
|
||||
set_target_properties(
|
||||
qtquick_customtabbar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples/"
|
||||
)
|
||||
|
||||
31
examples/qtquick/customtabbar/CMakeLists.txt
Normal file
31
examples/qtquick/customtabbar/CMakeLists.txt
Normal file
@@ -0,0 +1,31 @@
|
||||
#
|
||||
# This file is part of KDDockWidgets.
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2019-2022 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.
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
project(qtquick_customtabbar)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIRS ON)
|
||||
|
||||
if(NOT TARGET kddockwidgets)
|
||||
# This will look for Qt, do find_package yourself manually before if you want
|
||||
# to look for a specific Qt version for instance.
|
||||
find_package(KDDockWidgets REQUIRED)
|
||||
endif()
|
||||
|
||||
set(RESOURCES_EXAMPLE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/resources_qtquick_example.qrc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../dockwidgets/resources_example.qrc
|
||||
)
|
||||
|
||||
add_executable(qtquick_customtabbar main.cpp ${RESOURCES_EXAMPLE_SRC})
|
||||
|
||||
target_link_libraries(qtquick_customtabbar PRIVATE KDAB::kddockwidgets)
|
||||
36
examples/qtquick/customtabbar/Guest.qml
Normal file
36
examples/qtquick/customtabbar/Guest.qml
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2020-2022 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.
|
||||
*/
|
||||
|
||||
import QtQuick 2.9
|
||||
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
|
||||
property alias background: background.source
|
||||
property alias logo: logo.source
|
||||
|
||||
|
||||
Image {
|
||||
id: background
|
||||
anchors.fill: parent
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
|
||||
Image {
|
||||
id: logo
|
||||
|
||||
fillMode: Image.PreserveAspectFit
|
||||
anchors {
|
||||
fill: parent
|
||||
margins: 50
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
examples/qtquick/customtabbar/Guest1.qml
Normal file
18
examples/qtquick/customtabbar/Guest1.qml
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2020-2022 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.
|
||||
*/
|
||||
|
||||
import QtQuick 2.9
|
||||
|
||||
Guest {
|
||||
anchors.fill: parent
|
||||
background: "qrc:/assets/triangles.png"
|
||||
logo: "qrc:/assets/KDAB_bubble_white.png"
|
||||
}
|
||||
17
examples/qtquick/customtabbar/Guest2.qml
Normal file
17
examples/qtquick/customtabbar/Guest2.qml
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2020-2022 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.
|
||||
*/
|
||||
|
||||
import QtQuick 2.9
|
||||
|
||||
Guest {
|
||||
anchors.fill: parent
|
||||
logo: "qrc:/assets/KDAB_bubble_blue.png"
|
||||
}
|
||||
18
examples/qtquick/customtabbar/Guest3.qml
Normal file
18
examples/qtquick/customtabbar/Guest3.qml
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2020-2022 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.
|
||||
*/
|
||||
|
||||
import QtQuick 2.9
|
||||
|
||||
Guest {
|
||||
anchors.fill: parent
|
||||
background: "qrc:/assets/base.png"
|
||||
logo: "qrc:/assets/KDAB_bubble_fulcolor.png"
|
||||
}
|
||||
25
examples/qtquick/customtabbar/MyTabBar.qml
Normal file
25
examples/qtquick/customtabbar/MyTabBar.qml
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2020-2022 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.
|
||||
*/
|
||||
|
||||
import QtQuick 2.6
|
||||
|
||||
// Will be moved to a plugin in the future, if there's enough demand
|
||||
import "qrc:/kddockwidgets/qtquick/views/qml/" as KDDW
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
color: "black"
|
||||
border.color: "orange"
|
||||
border.width: 2
|
||||
|
||||
implicitHeight: 50
|
||||
|
||||
}
|
||||
77
examples/qtquick/customtabbar/main.cpp
Normal file
77
examples/qtquick/customtabbar/main.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2020-2022 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/views/DockWidget_qtquick.h>
|
||||
#include <kddockwidgets/Platform_qtquick.h>
|
||||
#include <kddockwidgets/ViewFactory_qtquick.h>
|
||||
#include <kddockwidgets/private/DockRegistry.h>
|
||||
#include <kddockwidgets/views/MainWindow_qtquick.h>
|
||||
|
||||
|
||||
#include <QQuickView>
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
class CustomViewFactory : public KDDockWidgets::ViewFactory_qtquick
|
||||
{
|
||||
public:
|
||||
~CustomViewFactory() override;
|
||||
|
||||
QUrl tabbarFilename() const override
|
||||
{
|
||||
return QUrl("qrc:/MyTabBar.qml");
|
||||
}
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
config.setFlags(flags);
|
||||
config.setViewFactory(new CustomViewFactory());
|
||||
|
||||
QQmlApplicationEngine appEngine;
|
||||
KDDockWidgets::Platform_qtquick::instance()->setQmlEngine(&appEngine);
|
||||
appEngine.load((QUrl("qrc:/main.qml")));
|
||||
|
||||
auto dw1 = new KDDockWidgets::Views::DockWidget_qtquick("Dock #1");
|
||||
|
||||
dw1->setGuestItem(QStringLiteral("qrc:/Guest1.qml"));
|
||||
dw1->resize(QSize(800, 800));
|
||||
dw1->show();
|
||||
|
||||
auto dw2 = new KDDockWidgets::Views::DockWidget_qtquick("Dock #2");
|
||||
dw2->setGuestItem(QStringLiteral("qrc:/Guest2.qml"));
|
||||
dw2->resize(QSize(800, 800));
|
||||
dw2->show();
|
||||
|
||||
auto dw3 = new KDDockWidgets::Views::DockWidget_qtquick("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();
|
||||
}
|
||||
27
examples/qtquick/customtabbar/main.qml
Normal file
27
examples/qtquick/customtabbar/main.qml
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2020-2022 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.
|
||||
*/
|
||||
|
||||
import QtQuick 2.6
|
||||
import QtQuick.Controls 2.12
|
||||
import com.kdab.dockwidgets 2.0 as KDDW
|
||||
|
||||
ApplicationWindow {
|
||||
visible: true
|
||||
width: 1000
|
||||
height: 800
|
||||
|
||||
KDDW.DockingArea {
|
||||
id: dockWidgetArea
|
||||
anchors.fill: parent
|
||||
|
||||
uniqueName: "MyMainLayout"
|
||||
}
|
||||
}
|
||||
10
examples/qtquick/customtabbar/resources_qtquick_example.qrc
Normal file
10
examples/qtquick/customtabbar/resources_qtquick_example.qrc
Normal file
@@ -0,0 +1,10 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>main.qml</file>
|
||||
<file>Guest1.qml</file>
|
||||
<file>Guest2.qml</file>
|
||||
<file>Guest3.qml</file>
|
||||
<file>Guest.qml</file>
|
||||
<file>MyTabBar.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
Reference in New Issue
Block a user