diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 431d48a..a43579c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -9,3 +9,4 @@ add_subdirectory(autohide) add_subdirectory(autohidedragndrop) add_subdirectory(emptydockarea) add_subdirectory(dockindock) +add_subdirectory(openGL) diff --git a/examples/openGL/CMakeLists.txt b/examples/openGL/CMakeLists.txt new file mode 100644 index 0000000..d9948f8 --- /dev/null +++ b/examples/openGL/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.5) + +project(OpenGLExample VERSION ${VERSION_SHORT}) + +find_package( + QT NAMES Qt6 + COMPONENTS Core Gui Widgets Charts OpenGLWidgets + REQUIRED) +find_package( + Qt${QT_VERSION_MAJOR} + COMPONENTS Core Gui Widgets Charts OpenGLWidgets + REQUIRED) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +add_executable(${PROJECT_NAME} WIN32 main.cpp MainWindow.cpp) + +target_include_directories(${PROJECT_NAME} + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../src") +target_link_libraries(${PROJECT_NAME} + PRIVATE qtadvanceddocking-qt${QT_VERSION_MAJOR}) + +target_link_libraries( + ${PROJECT_NAME} + PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Charts + Qt${QT_VERSION_MAJOR}::OpenGLWidgets) + +set_target_properties( + ${PROJECT_NAME} + PROPERTIES AUTOMOC ON + AUTORCC ON + AUTOUIC ON + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + VERSION ${VERSION_SHORT} + EXPORT_NAME "Qt Advanced Docking System OpenGL Example" + ARCHIVE_OUTPUT_DIRECTORY + "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib" + LIBRARY_OUTPUT_DIRECTORY + "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib" + RUNTIME_OUTPUT_DIRECTORY + "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/bin") + +# Define include directories +target_include_directories( + ${PROJECT_NAME} + PRIVATE $ + $ + $) diff --git a/examples/openGL/MainWindow.cpp b/examples/openGL/MainWindow.cpp new file mode 100644 index 0000000..f7c1b68 --- /dev/null +++ b/examples/openGL/MainWindow.cpp @@ -0,0 +1,34 @@ +#include "MainWindow.h" + +#include +#include +#include +#include +#include + +MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) +{ + setFixedSize(900, 600); + // Create the dock manager. Because the parent parameter is a QMainWindow + // the dock manager registers itself as the central widget. + m_DockManager = new ads::CDockManager(this); + + // Create example chart using OpenGL + QChartView* chart_view = new QChartView(this); + QList points = {{0, 0}, {2, 0}, {2, 5}, {4, 5}, {4, -2}, {6, -2}}; + QLineSeries* series = new QLineSeries(this); + series->setUseOpenGL(true); + series->replace(points); + chart_view->chart()->addSeries(series); + chart_view->chart()->createDefaultAxes(); + chart_view->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + + // Create a dock widget with the title "Chart with OpenGL" and set the created + // chart as the dock widget content + ads::CDockWidget* DockWidget = new ads::CDockWidget("Chart with OpenGL"); + DockWidget->setWidget(chart_view); + DockWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + + // Add the dock widget to the top dock widget area + m_DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget); +} diff --git a/examples/openGL/MainWindow.h b/examples/openGL/MainWindow.h new file mode 100644 index 0000000..4aba067 --- /dev/null +++ b/examples/openGL/MainWindow.h @@ -0,0 +1,20 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +#include "DockManager.h" + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget* parent = 0); + ~MainWindow() = default; + +private: + ads::CDockManager* m_DockManager; +}; + +#endif // MAINWINDOW_H diff --git a/examples/openGL/main.cpp b/examples/openGL/main.cpp new file mode 100644 index 0000000..b4d3f48 --- /dev/null +++ b/examples/openGL/main.cpp @@ -0,0 +1,17 @@ +#include + +#include + +int main(int argc, char* argv[]) +{ + QApplication::setAttribute(Qt::AA_ShareOpenGLContexts); // required for + // dockings system + // when using OpenGL + // widgets like + // Coin3D viewer + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +}