mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-04-01 02:42:39 +08:00
Add OpenGL example
This commit is contained in:
parent
483bb7354a
commit
a6be441848
@ -9,3 +9,4 @@ add_subdirectory(autohide)
|
|||||||
add_subdirectory(autohidedragndrop)
|
add_subdirectory(autohidedragndrop)
|
||||||
add_subdirectory(emptydockarea)
|
add_subdirectory(emptydockarea)
|
||||||
add_subdirectory(dockindock)
|
add_subdirectory(dockindock)
|
||||||
|
add_subdirectory(openGL)
|
||||||
|
51
examples/openGL/CMakeLists.txt
Normal file
51
examples/openGL/CMakeLists.txt
Normal file
@ -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 $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/examples/openGL>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${INSTALL_NAME}>)
|
34
examples/openGL/MainWindow.cpp
Normal file
34
examples/openGL/MainWindow.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include "MainWindow.h"
|
||||||
|
|
||||||
|
#include <QChart>
|
||||||
|
#include <QChartView>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineSeries>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
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<QPointF> 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);
|
||||||
|
}
|
20
examples/openGL/MainWindow.h
Normal file
20
examples/openGL/MainWindow.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef MAINWINDOW_H
|
||||||
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
#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
|
17
examples/openGL/main.cpp
Normal file
17
examples/openGL/main.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
#include <MainWindow.h>
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user