First Commit

This commit is contained in:
2025-11-18 14:18:26 -07:00
parent 33eb6e3707
commit 27277ec342
6106 changed files with 3571167 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2019 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.15)
project(qtquick_customtabbar)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIRS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT TARGET kddockwidgets)
# For the purpose of our example, we're looking for Qt5 or Qt6 KDDW.
# For your own purposes, just chose the one you need.
find_package(KDDockWidgets QUIET)
if(NOT KDDockWidgets_FOUND)
find_package(KDDockWidgets-qt6 REQUIRED)
endif()
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)

View File

@@ -0,0 +1,36 @@
/*
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.
*/
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
}
}
}
}

View File

@@ -0,0 +1,18 @@
/*
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.
*/
import QtQuick 2.9
Guest {
anchors.fill: parent
background: "qrc:/assets/triangles.png"
logo: "qrc:/assets/KDAB_bubble_white.png"
}

View File

@@ -0,0 +1,17 @@
/*
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.
*/
import QtQuick 2.9
Guest {
anchors.fill: parent
logo: "qrc:/assets/KDAB_bubble_blue.png"
}

View File

@@ -0,0 +1,18 @@
/*
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.
*/
import QtQuick 2.9
Guest {
anchors.fill: parent
background: "qrc:/assets/base.png"
logo: "qrc:/assets/KDAB_bubble_fulcolor.png"
}

View File

@@ -0,0 +1,172 @@
/*
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.
*/
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
/// Example of a QML Tab Bar that doesn't use QtQuick.Controls, just for demo purposes.
/// Se the comments named "#HERE#" for important things you shouldn't forget.
KDDW.TabBarBase {
id: root
implicitHeight: 30
currentTabIndex: 0
/// Optionally, we add a background.
Rectangle {
id: tabBarBackground
color: "#85baa1"
anchors.fill: parent
z: tabBarRow.z + 100
Rectangle {
id: addButton
width: 50
color: addButtonMouseArea.containsMouse ? (addButtonMouseArea.pressed ? "#d6ce93" : "#ffecd1" ) : "#ffecd1"
anchors {
right: parent.right
top: parent.top
bottom: parent.bottom
topMargin: 5
rightMargin: 5
}
Text {
text: "+"
font.pixelSize: 24
anchors.centerIn: parent
}
MouseArea {
id: addButtonMouseArea
anchors.fill: parent
hoverEnabled: true
onPressed: {
/// Do not use random uuids if you're planing to use layout save/restore!
/// Using them here for convenience of the exercise
var uniqueName = _kddwHelpers.generateUuid();
var code = `import com.kdab.dockwidgets 2.0 as KDDW;
import QtQuick 2.6;
KDDW.DockWidget {
uniqueName: "${uniqueName}";
title: "dynamic";
Rectangle {
color: "#85baa1";
anchors.fill: parent;
}
}`;
var newDW = Qt.createQmlObject(code, root);
tabBarCpp.addDockWidgetAsTab(newDW);
}
}
}
}
/// #HERE#. This function required in all derived tab bars. It's called by C++;
/// Returns the tab bar (QQuickItem*) at the specified index.
function getTabAtIndex(index) {
return tabBarRow.children[index];
}
/// #HERE#. This function required in all derived tab bars. It's called by C++;
/// Returns an int, with the index of the tab that's at the specified position.
function getTabIndexAtPosition(globalPoint) {
for (var i = 0; i < tabBarRow.children.length; ++i) {
var tab = tabBarRow.children[i];
var localPt = tab.mapFromGlobal(globalPoint.x, globalPoint.y);
if (tab.contains(localPt)) {
return i;
}
}
return -1;
}
Row {
id: tabBarRow
/// #HERE#: If you're going to add any custom MouseAreas please use set a higher Z than the builtin one
z: root.mouseAreaZ.z + 1
anchors.fill: parent
spacing: 2
/// Needed only if you want to style hovered tabs differently
property int hoveredIndex: -1;
/// ##HERE## The list of tabs is stored in a C++ model. This repeater populates our tab bar
Repeater {
model: root.groupCpp ? root.groupCpp.tabBar.dockWidgetModel : 0
Rectangle {
id: tab
height: parent.height
width: 150
readonly property bool isCurrent: index == root.groupCpp.currentIndex;
color: (tabBarRow.hoveredIndex == index) ? "#d6ce93" : (isCurrent ? "#d6ce93" : "#ffecd1")
border.color: "black"
// ##HERE## Illustrating how to have a different style in case the tab is current
border.width: isCurrent ? 2 : 1
radius: 2
// ##HERE## The index of the tab. This is required in all custom tab bar implementations
// It is be used by "getTabAtIndex()" and "getTabIndexAtPosition()" functions
readonly property int tabIndex: index
Text {
anchors.centerIn: parent
text: title
}
// Optionally, and for illustration purposes, we add a close button
Rectangle {
id: closeButton
color: "transparent"
radius: 3
border.width: closeButtonMouseArea.containsMouse ? 1 : 0
border.color: "black"
height: 17
width: height
anchors {
right: parent.right
rightMargin: 4
verticalCenter: parent.verticalCenter
}
Image {
source: "qrc:/img/close.png"
anchors.centerIn: parent
MouseArea {
id: closeButtonMouseArea
anchors.fill: parent
hoverEnabled: true
onClicked: {
tabBarCpp.closeAtIndex(index);
}
}
}
}
}
}
Connections {
target: tabBarCpp
function onHoveredTabIndexChanged(index) {
tabBarRow.hoveredIndex = index;
}
}
}
}

View File

@@ -0,0 +1,74 @@
/*
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/core/MainWindow.h>
#include <kddockwidgets/core/views/MainWindowViewInterface.h>
#include <QQuickView>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
class CustomViewFactory : public KDDockWidgets::QtQuick::ViewFactory
{
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::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"));
auto dw2 = new KDDockWidgets::QtQuick::DockWidget("Dock #2");
dw2->setGuestItem(QStringLiteral("qrc:/Guest2.qml"));
auto dw3 = new KDDockWidgets::QtQuick::DockWidget("Dock #3");
dw3->setGuestItem(QStringLiteral("qrc:/Guest3.qml"));
// Access the main area we created in QML with DockingArea {}
auto mainArea = KDDockWidgets::DockRegistry::self()->mainDockingAreas().constFirst();
mainArea->addDockWidget(dw1, KDDockWidgets::Location_OnTop);
dw1->addDockWidgetAsTab(dw2);
dw1->addDockWidgetAsTab(dw3);
return app.exec();
}

View File

@@ -0,0 +1,75 @@
/*
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.
*/
import QtQuick 2.6
import QtQuick.Controls 2.12
import com.kdab.dockwidgets 2.0 as KDDW
/// The top 3 tabbed dock widgets were created in C++, while the bottom 2 (dock4 and dock5) were created in QML
ApplicationWindow {
visible: true
width: 1000
height: 800
menuBar: MenuBar {
Menu {
title: qsTr("&Misc")
Action {
// For demonstration purposes, show how to change title:
text: qsTr("Change title of #4")
onTriggered: {
dock4.title = "new title";
}
}
}
}
KDDW.DockWidget {
id: dock4
uniqueName: "dock4"
Rectangle {
color: "#85baa1"
anchors.fill: parent
Text {
font.pixelSize: 25
text: "Four"
anchors.centerIn: parent
}
}
}
KDDW.DockWidget {
id: dock5
uniqueName: "dock5"
Rectangle {
color: "#85baa1"
anchors.fill: parent
Text {
font.pixelSize: 25
text: "Five"
anchors.centerIn: parent
}
}
}
KDDW.DockingArea {
id: dockWidgetArea
anchors.fill: parent
uniqueName: "MyMainLayout"
Component.onCompleted: {
addDockWidget(dock4, KDDW.KDDockWidgets.Location_OnBottom);
dock4.addDockWidgetAsTab(dock5);
}
}
}

View 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>