diff --git a/examples/basic_external/CMakeLists.txt b/examples/basic_external/CMakeLists.txt new file mode 100644 index 00000000..b0911b1c --- /dev/null +++ b/examples/basic_external/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.0) + +project(docks_example) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIRS ON) + +# This will look for Qt, do find_package yourself manually before +# if you want to look for a specific version for instance. +find_package(KDDockWidgets REQUIRED) + +add_executable(docks_example + main.cpp + ExampleDockableWidget.cpp +) + +target_link_libraries(docks_example + PRIVATE + KDAB::kddockwidgets +) + diff --git a/examples/basic_external/ExampleDockableWidget.cpp b/examples/basic_external/ExampleDockableWidget.cpp new file mode 100644 index 00000000..3e75769d --- /dev/null +++ b/examples/basic_external/ExampleDockableWidget.cpp @@ -0,0 +1,58 @@ +/* + 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 + + 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 . +*/ + +#include "ExampleDockableWidget.h" + +#include +#include +#include +#include + +MyWidget::MyWidget(QWidget *parent) + : QWidget(parent) +{ + auto l = new QVBoxLayout(this); + + auto box = new QGroupBox(); + auto l2 = new QVBoxLayout(box); + auto radio1 = new QRadioButton(QStringLiteral("foo"), box); + auto radio2 = new QRadioButton(QStringLiteral("bar"), box); + auto radio3 = new QRadioButton(QStringLiteral("baz"), box); + l2->addWidget(radio1); + l2->addWidget(radio2); + l2->addWidget(radio3); + + l->addWidget(box); + auto button = new QPushButton(QStringLiteral("Test")); + l->addWidget(button); + l->addWidget(new QPushButton(QStringLiteral("Test"))); + l->addStretch(); + + connect(button, &QPushButton::clicked, button, [this] { + // To test if moving windows work on Wayland + QPoint pos = window()->pos(); + window()->move(pos + QPoint(30, 30)); + }); + +} + +MyWidget::~MyWidget() +{ +} diff --git a/examples/basic_external/ExampleDockableWidget.h b/examples/basic_external/ExampleDockableWidget.h new file mode 100644 index 00000000..896c50f1 --- /dev/null +++ b/examples/basic_external/ExampleDockableWidget.h @@ -0,0 +1,34 @@ +/* + 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 + + 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 . +*/ + +#ifndef EXAMPLEDOCKABLEWIDGET_H +#define EXAMPLEDOCKABLEWIDGET_H + +#include + +class MyWidget : public QWidget +{ + Q_OBJECT +public: + explicit MyWidget(QWidget *parent = nullptr); + ~MyWidget(); +}; + +#endif diff --git a/examples/basic_external/README.md b/examples/basic_external/README.md new file mode 100644 index 00000000..1841acdb --- /dev/null +++ b/examples/basic_external/README.md @@ -0,0 +1,6 @@ +# External usage example + +This example is the same than `basic`, except that it shows +how the library is meant to be used from an externally-provided KDDockWidgets, +found with CMake find_package. + diff --git a/examples/basic_external/main.cpp b/examples/basic_external/main.cpp new file mode 100644 index 00000000..50974d71 --- /dev/null +++ b/examples/basic_external/main.cpp @@ -0,0 +1,168 @@ +/* + 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 + + 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 . +*/ + +#include "ExampleDockableWidget.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace KDDockWidgets; + +DockWidgetBase::Options s_dockWidgetOptions = DockWidgetBase::Option_None; // DockWidget::Option_NotClosable; + +static MyWidget *newMyWidget() +{ + static int count = 0; + count++; + return new MyWidget(); +} + + +class MyMainWindow : public MainWindow +{ + Q_OBJECT +public: + MyMainWindow(MainWindowOptions options, QWidget *parent = nullptr) + : MainWindow(QStringLiteral("MyMainWindow"), options, parent) + { + // qApp->installEventFilter(this); + + auto menubar = menuBar(); + auto fileMenu = new QMenu(QStringLiteral("File")); + toggleMenu = new QMenu(QStringLiteral("Toggle")); + menubar->addMenu(fileMenu); + menubar->addMenu(toggleMenu); + + QAction *newAction = fileMenu->addAction(QStringLiteral("New DockWidget")); + static int count = 0; + count++; + connect(newAction, &QAction::triggered, this, [] { + auto w = newMyWidget(); + w->setGeometry(100, 100, 400, 400); + auto dock = new DockWidget(QStringLiteral("dock %1").arg(count)); + dock->setWidget(w); + dock->resize(400, 400); + dock->show(); + }); + + // newAction = fileMenu->addAction("Change MainWindow indicator style"); + + auto saveLayoutAction = fileMenu->addAction(QStringLiteral("Save Layout")); + connect(saveLayoutAction, &QAction::triggered, this, [] { + LayoutSaver saver; + const bool result = saver.saveToDisk(); + qDebug() << "Saving layout to disk. Result=" << result; + }); + + auto restoreLayoutAction = fileMenu->addAction(QStringLiteral("Restore Layout")); + connect(restoreLayoutAction, &QAction::triggered, this, [] { + LayoutSaver saver; + saver.restoreFromDisk(); + }); + } + + bool eventFilter(QObject *o, QEvent *ev) override + { + if (ev->type() == QEvent::MouseButtonPress || + ev->type() == QEvent::MouseButtonRelease || + //ev->type() == QEvent::MouseMove || + ev->type() == QEvent::NonClientAreaMouseButtonPress || + ev->type() == QEvent::NonClientAreaMouseButtonRelease || + ev->type() == QEvent::NonClientAreaMouseMove) + qDebug() << "Mouse event: " << ev->type(); + + if (ev->type() == QEvent::Move) + qDebug() << "Move event " << window()->pos(); + + return KDDockWidgets::MainWindow::eventFilter(o, ev); + } + + QMenu *toggleMenu; +}; + +int main(int argc, char **argv) +{ + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + QApplication app(argc, argv); + //KDDockWidgets::Config::self().setFlags( KDDockWidgets::Config::Flags() | KDDockWidgets::Config::Flag_HideTitleBarWhenTabsVisible | KDDockWidgets::Config::Flag_AlwaysShowTabs); + //KDDockWidgets::Config::self().setFlags( KDDockWidgets::Config::Flags() | KDDockWidgets::Config::Flag_AlwaysShowTabs); + app.setOrganizationName(QStringLiteral("KDAB")); + app.setApplicationName(QStringLiteral("Test app")); + qApp->setStyle(QStyleFactory::create(QStringLiteral("Fusion"))); + + const bool embedded = app.arguments().contains(QStringLiteral("--embedded")); + const bool noCentralFrame = app.arguments().contains(QStringLiteral("--no-central")); + MainWindowOptions options = noCentralFrame ? MainWindowOption_None + : MainWindowOption_HasCentralFrame; + + MyMainWindow mainWindow(options); + QWidget *window; + if (embedded) { + window = new QWidget(); + auto lay = new QVBoxLayout(window); + lay->addWidget(&mainWindow); + } else { + window = &mainWindow; + } + + window->resize(1000, 800); + window->show(); + + auto example = newMyWidget(); + auto dock = new DockWidget(QStringLiteral("foo"), s_dockWidgetOptions); + dock->setIcon(QIcon::fromTheme(QStringLiteral("mail-message"))); + dock->setWidget(example); + dock->setTitle(QStringLiteral("foo")); + example->winId(); // for testing native widgets too + dock->resize(400, 400); + dock->show(); + mainWindow.toggleMenu->addAction(dock->toggleAction()); + + example = newMyWidget(); + example->setGeometry(100, 100, 400, 400); + dock = new DockWidget(QStringLiteral("bar"), s_dockWidgetOptions); + dock->setWidget(example); + dock->resize(400, 400); + dock->show(); + mainWindow.toggleMenu->addAction(dock->toggleAction()); + + auto textEdit = new QTextEdit(); + textEdit->setText(QStringLiteral("Hello, this is the central document.")); + dock = new DockWidget(QStringLiteral("doc 0"), s_dockWidgetOptions); + dock->setWidget(textEdit); + mainWindow.toggleMenu->addAction(dock->toggleAction()); + if (!noCentralFrame) + mainWindow.addDockWidgetAsTab(dock); + + return app.exec(); +} + +#include "main.moc" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 500458c3..2ae9dcdb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -112,6 +112,7 @@ else() set(DOCKS_INSTALLABLE_INCLUDES ${DOCKS_INSTALLABLE_INCLUDES} MainWindow.h + MainWindowBase.h widgets/DockWidget.h) endif() @@ -127,7 +128,7 @@ add_library(kddockwidgets SHARED ${DOCKSLIBS_SRCS} ${DOCKS_INSTALLABLE_INCLUDES} target_include_directories(kddockwidgets PUBLIC - $ + $ $ $ $ @@ -159,8 +160,27 @@ if (NOT WIN32 AND NOT APPLE) endif() install (TARGETS kddockwidgets + EXPORT kddockwidgetsTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install (FILES ${DOCKS_INSTALLABLE_INCLUDES} DESTINATION include/kddockwidgets) install (FILES ${DOCKS_INSTALLABLE_PRIVATE_WIDGET_INCLUDES} DESTINATION include/kddockwidgets/widgets) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + KDDockWidgetsConfigVersion.cmake + VERSION ${PACKAGE_VERSION} + COMPATIBILITY AnyNewerVersion + ) + +install(EXPORT kddockwidgetsTargets + FILE KDDockWidgetsTargets.cmake + NAMESPACE KDAB:: + DESTINATION lib/cmake/KDDockWidgets +) +configure_file(KDDockWidgetsConfig.cmake.in KDDockWidgetsConfig.cmake @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgetsConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgetsConfigVersion.cmake" + DESTINATION lib/cmake/KDDockWidgets +) diff --git a/src/KDDockWidgetsConfig.cmake.in b/src/KDDockWidgetsConfig.cmake.in new file mode 100644 index 00000000..1a3534a2 --- /dev/null +++ b/src/KDDockWidgetsConfig.cmake.in @@ -0,0 +1,13 @@ +include(CMakeFindDependencyMacro) + +find_dependency(Qt5Widgets REQUIRED) +if (@OPTION_QTQUICK@) + find_dependency(Qt5Quick REQUIRED) +endif() + +if (NOT WIN32 AND NOT APPLE) + find_dependency(Qt5X11Extras REQUIRED) +endif() + +# Add the targets file +include("${CMAKE_CURRENT_LIST_DIR}/KDDockWidgetsTargets.cmake")