diff --git a/README.md b/README.md index c47468f..b198392 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,7 @@ [![All Builds](https://github.com/shaunrd0/qtk/actions/workflows/all-builds.yml/badge.svg)](https://github.com/shaunrd0/qtk/actions/workflows/all-builds.yml) [![Linting](https://github.com/shaunrd0/qtk/actions/workflows/linting.yml/badge.svg)](https://github.com/shaunrd0/qtk/actions/workflows/linting.yml) -Qtk is a Qt OpenGL graphics library created primarily for my own learning -purposes. The library wraps some QOpenGL functionality in convenience classes +Qtk is a Qt OpenGL graphics library that wraps some QOpenGL functionality in convenience classes that allow rendering geometry in 2D and 3D using custom GLSL shader programs. The Qtk desktop application provides a model loader using [Assimp](https://assimp.org/) within a Qt widget application. diff --git a/src/app/qtkmainwindow.cpp b/src/app/qtkmainwindow.cpp index 0365d51..9d7d547 100644 --- a/src/app/qtkmainwindow.cpp +++ b/src/app/qtkmainwindow.cpp @@ -9,8 +9,6 @@ #include "qtkmainwindow.h" #include "ui_qtkmainwindow.h" -MainWindow * MainWindow::mainWindow_ = Q_NULLPTR; - /******************************************************************************* * Constructors / Destructors ******************************************************************************/ @@ -27,6 +25,10 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) // Initialize static container for all active QtkWidgets auto qtkWidgets = findChildren(); for (auto & qtkWidget : qtkWidgets) { + // NOTE: Set a temporary scene for the widget to use for initialization. + // This should be replaced by loading a scene, or creating a new (unsaved) + // scene when Qtk is opened. + qtkWidget->setScene(new EmptyScene); views_.emplace(qtkWidget->getScene()->getSceneName(), qtkWidget); // Add GUI 'view' toolbar option to show debug console. @@ -36,8 +38,7 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) &Qtk::Scene::sceneUpdated, this, &MainWindow::refreshScene); - connect(qtkWidget, - &Qtk::QtkWidget::objectFocusChanged, + connect(qtkWidget, &Qtk::QtkWidget::objectFocusChanged, ui_->qtk__ToolBox, &Qtk::ToolBox::updateFocus); } @@ -70,10 +71,8 @@ MainWindow::~MainWindow() MainWindow * MainWindow::getMainWindow() { - if (mainWindow_ == Q_NULLPTR) { - mainWindow_ = new MainWindow; - } - return mainWindow_; + static MainWindow window; + return &window; } Qtk::QtkWidget * MainWindow::getQtkWidget(int64_t index) diff --git a/src/app/qtkmainwindow.h b/src/app/qtkmainwindow.h index 23628e8..4bd2fe9 100644 --- a/src/app/qtkmainwindow.h +++ b/src/app/qtkmainwindow.h @@ -22,6 +22,38 @@ namespace Ui class MainWindow; } +/** + * An empty scene used for initializing all QtkWidgets within the MainWindow. + * This serves as a temporary placeholder for QtkScene (for example), which is + * defined in the separate qtk_gui target. The reason for this separation is to + * support the use of QtkWidgets (the qtk_plugins target) within the Qt Designer + * application without implementations provided in the Qtk Desktop Application. + * + * For the Qtk application, this should be replaced by loading the previous + * scene or creating a new _unsaved_ scene when the application is opened. + * Currently we have essentially hard-coded QtkScene to use as examples for + * testing the application. This means that the only way to create or modify a + * scene is to write code. Any modifications made in the application, such as + * moving or resizing objects, will not persist and cannot be saved. + * + * For users of Qtk Designer Plugins, this means that installing + * the `qtk_plugins` target to Qt Designer allows use all of the designer's + * features to build an interface and position or resize a QtkWidget as needed. + * The QtkWidget also appears as widget in the IDE's toolbars and can be added + * to any new application easily, once the plugins are installed. + * + * Once the application is designed, you can define a custom scene and use the + * Qtk API or Qt OpenGL funtions directly to render to it. + * + * Any application using a QtkWidget can set a custom scene in their main + * function. See the MainWindow::MainWindow constructor as an example. + */ +class EmptyScene : public Qtk::Scene { + void init() override { + setSceneName("Empty Scene"); + } +}; + /** * MainWindow class to provide an example of using a QtkWidget within a Qt * window application. @@ -82,7 +114,6 @@ class MainWindow : public QMainWindow MainWindow(const MainWindow &) {}; Ui::MainWindow * ui_ {}; - static MainWindow * mainWindow_; /** * Maps a scene name to the QtkWidget viewing it.