Clean and comment code
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
################################################################################
|
||||
## Author: Shaun Reed | Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
|
||||
## ##
|
||||
## Project for working with OpenGL and Qt6 widgets ##
|
||||
## ##
|
||||
## Author: Shaun Reed | Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
|
||||
## All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
################################################################################
|
||||
|
||||
################################################################################
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: MainWindow for creating an example Qt application ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Debug console for qtk views ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################*/
|
||||
@@ -29,16 +29,5 @@ DebugConsole::DebugConsole(
|
||||
auto qtkWidget = dynamic_cast<QtkWidget *>(owner);
|
||||
if(qtkWidget) {
|
||||
connect(qtkWidget, &QtkWidget::sendLog, this, &DebugConsole::sendLog);
|
||||
sendLog(
|
||||
"Debug console (" + name + ") attached to QtkWidget: '"
|
||||
+ qtkWidget->objectName() + "'");
|
||||
sendLog("Test\nLogging\t\n\tStuff", Status);
|
||||
sendLog("Test\nLogging\t\n\tStuff", Debug);
|
||||
sendLog("Test\nLogging\t\n\tStuff", Warn);
|
||||
sendLog("Test\nLogging\t\n\tStuff", Error);
|
||||
sendLog(
|
||||
"Test\nLogging\t\n\tStuff that is really long and will wrap around but "
|
||||
"it might not you don't know until you try",
|
||||
Fatal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Debug console for qtk views ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
@@ -73,10 +73,14 @@ namespace Qtk {
|
||||
* @param name Base name for the DebugConsole window.
|
||||
*/
|
||||
inline void setTitle(QString name) {
|
||||
setWindowTitle(name + "Debug Console");
|
||||
setWindowTitle(name + " Debug Console");
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* @param context Log context severity level.
|
||||
* @return QColor corresponding with the message context.
|
||||
*/
|
||||
[[nodiscard]] QColor logColor(const DebugContext & context) const {
|
||||
switch(context) {
|
||||
case Status:
|
||||
@@ -94,6 +98,13 @@ namespace Qtk {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefixes a log message to add context level.
|
||||
*
|
||||
* @param message The message to prefix.
|
||||
* @param context The log context severity level.
|
||||
* @return The log message prefixed with the DebugContext level.
|
||||
*/
|
||||
[[nodiscard]] QString logPrefix(
|
||||
QString & message, const DebugContext & context) {
|
||||
QString prefix;
|
||||
@@ -121,8 +132,8 @@ namespace Qtk {
|
||||
return message;
|
||||
}
|
||||
|
||||
QTextEdit * mConsole;
|
||||
Ui::DebugConsole * ui_;
|
||||
QTextEdit * mConsole;
|
||||
};
|
||||
} // namespace Qtk
|
||||
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Classes for managing objects and data within a scene ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Example Qtk scene ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################*/
|
||||
|
||||
#include <qtk/meshrenderer.h>
|
||||
#include <qtk/model.h>
|
||||
#include <qtk/texture.h>
|
||||
|
||||
#include "examplescene.h"
|
||||
#include "resources.h"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Classes for managing objects and data within a scene ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Example Qtk scene ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################*/
|
||||
@@ -9,11 +9,7 @@
|
||||
#ifndef QTK_EXAMPLE_SCENE_H
|
||||
#define QTK_EXAMPLE_SCENE_H
|
||||
|
||||
#include <QMatrix4x4>
|
||||
|
||||
#include <qtk/camera3d.h>
|
||||
#include <qtk/scene.h>
|
||||
#include <qtk/skybox.h>
|
||||
|
||||
/**
|
||||
* Example scene using QtkWidget to render 3D models and simple geometry within
|
||||
@@ -40,6 +36,7 @@ class ExampleScene : public Qtk::Scene {
|
||||
**************************************************************************/
|
||||
|
||||
ExampleScene();
|
||||
|
||||
~ExampleScene();
|
||||
|
||||
/***************************************************************************
|
||||
@@ -50,6 +47,7 @@ class ExampleScene : public Qtk::Scene {
|
||||
* Initialize objects within the scene
|
||||
*/
|
||||
void init() override;
|
||||
|
||||
/**
|
||||
* Called when OpenGL repaints the widget.
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Main program for practice using Qt6 widgets and OpenGL ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: MainWindow for Qtk application ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################*/
|
||||
|
||||
#include <qtk/qtkapi.h>
|
||||
|
||||
#include "examplescene.h"
|
||||
#include "qtkmainwindow.h"
|
||||
#include "ui_qtkmainwindow.h"
|
||||
|
||||
MainWindow * MainWindow::mainWindow_ = Q_NULLPTR;
|
||||
|
||||
/*******************************************************************************
|
||||
* Constructors / Destructors
|
||||
******************************************************************************/
|
||||
|
||||
MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) {
|
||||
ui_ = new Ui::MainWindow;
|
||||
setObjectName("MainWindow");
|
||||
@@ -47,6 +49,25 @@ MainWindow::~MainWindow() {
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Public Methods
|
||||
******************************************************************************/
|
||||
|
||||
MainWindow * MainWindow::getMainWindow() {
|
||||
if(mainWindow_ == Q_NULLPTR) {
|
||||
mainWindow_ = new MainWindow;
|
||||
}
|
||||
return mainWindow_;
|
||||
}
|
||||
|
||||
Qtk::QtkWidget * MainWindow::getQtkWidget(const QString & name) {
|
||||
if(!views_.count(name)) {
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
return views_[name];
|
||||
}
|
||||
|
||||
void MainWindow::refreshScene(QString sceneName) {
|
||||
// TODO: Select TreeView using sceneName>
|
||||
ui_->qtk__TreeView->updateView(getQtkWidget(sceneName)->getScene());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: MainWindow for Qtk application ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
@@ -40,22 +40,18 @@ class MainWindow : public QMainWindow {
|
||||
* @param parent The parent for this QMainWindow
|
||||
*/
|
||||
explicit MainWindow(QWidget * parent = nullptr);
|
||||
|
||||
~MainWindow() override;
|
||||
|
||||
/***************************************************************************
|
||||
* Public Static Methods
|
||||
* Public Methods
|
||||
**************************************************************************/
|
||||
|
||||
/**
|
||||
* Allows widgets to retrieve an instance of this root QMainWindow.
|
||||
* @return this
|
||||
*/
|
||||
inline static MainWindow * getMainWindow() {
|
||||
if(mainWindow_ == Q_NULLPTR) {
|
||||
mainWindow_ = new MainWindow;
|
||||
}
|
||||
return mainWindow_;
|
||||
}
|
||||
static MainWindow * getMainWindow();
|
||||
|
||||
/**
|
||||
* Accessor for retrieving a QtkWidget by it's objectName.
|
||||
@@ -64,22 +60,23 @@ class MainWindow : public QMainWindow {
|
||||
* @param name The objectName associated with the QtkWidget.
|
||||
* @return Pointer to an active QtkWidget or Q_NULLPTR is not found.
|
||||
*/
|
||||
inline Qtk::QtkWidget * getQtkWidget(const QString & name) {
|
||||
if(!views_.count(name)) {
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
return views_[name];
|
||||
}
|
||||
Qtk::QtkWidget * getQtkWidget(const QString & name);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* Trigger a refresh for widgets related to a scene that has been updated.
|
||||
* @param sceneName The name of the scene that has been modified.
|
||||
*/
|
||||
void refreshScene(QString sceneName);
|
||||
|
||||
private:
|
||||
MainWindow(const MainWindow &) {};
|
||||
/***************************************************************************
|
||||
* Private Members
|
||||
**************************************************************************/
|
||||
|
||||
/** Do not allow copying */
|
||||
MainWindow(const MainWindow &) {};
|
||||
|
||||
Ui::MainWindow * ui_ {};
|
||||
static MainWindow * mainWindow_;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Main window for Qt6 OpenGL widget application ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: QtkWidget for Qt desktop application ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################*/
|
||||
@@ -9,9 +9,9 @@
|
||||
#include <QKeyEvent>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "qtk/input.h"
|
||||
#include "qtk/mesh.h"
|
||||
#include "qtk/scene.h"
|
||||
#include <qtk/input.h>
|
||||
#include <qtk/scene.h>
|
||||
#include <qtk/shape.h>
|
||||
|
||||
#include "debugconsole.h"
|
||||
#include "qtkmainwindow.h"
|
||||
@@ -23,12 +23,15 @@ using namespace Qtk;
|
||||
* Constructors, Destructors
|
||||
******************************************************************************/
|
||||
|
||||
QtkWidget::QtkWidget(QWidget * parent) :
|
||||
QtkWidget(parent, "QtkWidget") {}
|
||||
|
||||
QtkWidget::QtkWidget(QWidget * parent, const QString & name) :
|
||||
QtkWidget(parent, name, Q_NULLPTR) {}
|
||||
|
||||
QtkWidget::QtkWidget(QWidget * parent, const QString & name, Scene * scene) :
|
||||
QOpenGLWidget(parent), mDebugLogger(Q_NULLPTR),
|
||||
mConsole(new DebugConsole(this, name)) {
|
||||
mConsole(new DebugConsole(this, name)), mScene(Q_NULLPTR) {
|
||||
setScene(scene);
|
||||
setObjectName(name);
|
||||
QSurfaceFormat format;
|
||||
@@ -65,10 +68,6 @@ QAction * QtkWidget::getActionToggleConsole() {
|
||||
return action;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Public Inherited Virtual Methods
|
||||
******************************************************************************/
|
||||
|
||||
void QtkWidget::initializeGL() {
|
||||
initializeOpenGLFunctions();
|
||||
// Connect the frameSwapped signal to call the update() function
|
||||
@@ -113,10 +112,58 @@ void QtkWidget::paintGL() {
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::setScene(Qtk::Scene * scene) {
|
||||
delete mScene;
|
||||
mScene = scene;
|
||||
if(mScene != Q_NULLPTR) {
|
||||
mConsole->setTitle(mScene->getSceneName());
|
||||
} else {
|
||||
mConsole->setTitle("Null Scene");
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::toggleConsole() {
|
||||
if(mConsoleActive) {
|
||||
mConsole->setHidden(true);
|
||||
mConsoleActive = false;
|
||||
} else {
|
||||
MainWindow::getMainWindow()->addDockWidget(
|
||||
Qt::DockWidgetArea::BottomDockWidgetArea,
|
||||
dynamic_cast<QDockWidget *>(mConsole));
|
||||
mConsole->setHidden(false);
|
||||
mConsoleActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Protected Slots
|
||||
* Protected Methods
|
||||
******************************************************************************/
|
||||
|
||||
void QtkWidget::keyPressEvent(QKeyEvent * event) {
|
||||
if(event->isAutoRepeat()) {
|
||||
// Do not repeat input while a key is held down
|
||||
event->ignore();
|
||||
} else {
|
||||
Input::registerKeyPress(event->key());
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::keyReleaseEvent(QKeyEvent * event) {
|
||||
if(event->isAutoRepeat()) {
|
||||
event->ignore();
|
||||
} else {
|
||||
Input::registerKeyRelease(event->key());
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::mousePressEvent(QMouseEvent * event) {
|
||||
Input::registerMousePress(event->button());
|
||||
}
|
||||
|
||||
void QtkWidget::mouseReleaseEvent(QMouseEvent * event) {
|
||||
Input::registerMouseRelease(event->button());
|
||||
}
|
||||
|
||||
void QtkWidget::update() {
|
||||
updateCameraInput();
|
||||
|
||||
@@ -195,39 +242,49 @@ void QtkWidget::messageLogged(const QOpenGLDebugMessage & msg) {
|
||||
sendLog("(OpenGL) " + error.replace("\n", "\n(OpenGL) "), context);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Protected Methods
|
||||
******************************************************************************/
|
||||
|
||||
void QtkWidget::keyPressEvent(QKeyEvent * event) {
|
||||
if(event->isAutoRepeat()) {
|
||||
// Do not repeat input while a key is held down
|
||||
event->ignore();
|
||||
} else {
|
||||
Input::registerKeyPress(event->key());
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::keyReleaseEvent(QKeyEvent * event) {
|
||||
if(event->isAutoRepeat()) {
|
||||
event->ignore();
|
||||
} else {
|
||||
Input::registerKeyRelease(event->key());
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::mousePressEvent(QMouseEvent * event) {
|
||||
Input::registerMousePress(event->button());
|
||||
}
|
||||
|
||||
void QtkWidget::mouseReleaseEvent(QMouseEvent * event) {
|
||||
Input::registerMouseRelease(event->button());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Private Methods
|
||||
******************************************************************************/
|
||||
|
||||
void QtkWidget::teardownGL() { /* Nothing to teardown yet... */ }
|
||||
|
||||
void QtkWidget::updateCameraInput() {
|
||||
Input::update();
|
||||
// Camera Transformation
|
||||
if(Input::buttonPressed(Qt::RightButton)) {
|
||||
static const float transSpeed = 0.1f;
|
||||
static const float rotSpeed = 0.5f;
|
||||
|
||||
// Handle rotations
|
||||
Scene::getCamera().getTransform().rotate(
|
||||
-rotSpeed * Input::mouseDelta().x(), Camera3D::LocalUp);
|
||||
Scene::getCamera().getTransform().rotate(
|
||||
-rotSpeed * Input::mouseDelta().y(), Scene::getCamera().getRight());
|
||||
|
||||
// Handle translations
|
||||
QVector3D translation;
|
||||
if(Input::keyPressed(Qt::Key_W)) {
|
||||
translation += Scene::getCamera().getForward();
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_S)) {
|
||||
translation -= Scene::getCamera().getForward();
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_A)) {
|
||||
translation -= Scene::getCamera().getRight();
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_D)) {
|
||||
translation += Scene::getCamera().getRight();
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_Q)) {
|
||||
translation -= Scene::getCamera().getUp() / 2.0f;
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_E)) {
|
||||
translation += Scene::getCamera().getUp() / 2.0f;
|
||||
}
|
||||
Scene::getCamera().getTransform().translate(transSpeed * translation);
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::printContextInformation() {
|
||||
QString glType;
|
||||
QString glVersion;
|
||||
@@ -260,63 +317,3 @@ void QtkWidget::printContextInformation() {
|
||||
qDebug() << qPrintable(message);
|
||||
sendLog("(OpenGL) " + message.replace("\n", "\n(OpenGL) "), Status);
|
||||
}
|
||||
|
||||
void QtkWidget::updateCameraInput() {
|
||||
Input::update();
|
||||
// Camera Transformation
|
||||
if(Input::buttonPressed(Qt::RightButton)) {
|
||||
static const float transSpeed = 0.1f;
|
||||
static const float rotSpeed = 0.5f;
|
||||
|
||||
// Handle rotations
|
||||
Scene::getCamera().getTransform().rotate(
|
||||
-rotSpeed * Input::mouseDelta().x(), Camera3D::LocalUp);
|
||||
Scene::getCamera().getTransform().rotate(
|
||||
-rotSpeed * Input::mouseDelta().y(), Scene::getCamera().right());
|
||||
|
||||
// Handle translations
|
||||
QVector3D translation;
|
||||
if(Input::keyPressed(Qt::Key_W)) {
|
||||
translation += Scene::getCamera().forward();
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_S)) {
|
||||
translation -= Scene::getCamera().forward();
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_A)) {
|
||||
translation -= Scene::getCamera().right();
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_D)) {
|
||||
translation += Scene::getCamera().right();
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_Q)) {
|
||||
translation -= Scene::getCamera().up() / 2.0f;
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_E)) {
|
||||
translation += Scene::getCamera().up() / 2.0f;
|
||||
}
|
||||
Scene::getCamera().getTransform().translate(transSpeed * translation);
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::toggleConsole() {
|
||||
if(mConsoleActive) {
|
||||
mConsole->setHidden(true);
|
||||
mConsoleActive = false;
|
||||
} else {
|
||||
MainWindow::getMainWindow()->addDockWidget(
|
||||
Qt::DockWidgetArea::BottomDockWidgetArea,
|
||||
dynamic_cast<QDockWidget *>(mConsole));
|
||||
mConsole->setHidden(false);
|
||||
mConsoleActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::setScene(Qtk::Scene * scene) {
|
||||
delete mScene;
|
||||
mScene = scene;
|
||||
if(mScene != Q_NULLPTR) {
|
||||
mConsole->setTitle(mScene->getSceneName());
|
||||
} else {
|
||||
mConsole->setTitle("Null Scene");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Main window for Qt6 OpenGL widget application ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: QtkWidget for Qt desktop application ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################*/
|
||||
@@ -17,8 +17,8 @@
|
||||
#include <QOpenGLWidget>
|
||||
#include <QPlainTextEdit>
|
||||
|
||||
#include "qtk/qtkapi.h"
|
||||
#include "qtk/scene.h"
|
||||
#include <qtk/qtkapi.h>
|
||||
#include <qtk/scene.h>
|
||||
|
||||
namespace Qtk {
|
||||
class DebugConsole;
|
||||
@@ -42,8 +42,7 @@ namespace Qtk {
|
||||
*
|
||||
* @param parent Pointer to a parent widget for this QtkWidget or nullptr.
|
||||
*/
|
||||
explicit QtkWidget(QWidget * parent = nullptr) :
|
||||
QtkWidget(parent, "QtkWidget") {}
|
||||
explicit QtkWidget(QWidget * parent = nullptr);
|
||||
|
||||
/**
|
||||
* Default construct a QtkWidget.
|
||||
@@ -62,26 +61,18 @@ namespace Qtk {
|
||||
*/
|
||||
QtkWidget(QWidget * parent, const QString & name, Qtk::Scene * scene);
|
||||
|
||||
~QtkWidget() override;
|
||||
~QtkWidget();
|
||||
|
||||
/*************************************************************************
|
||||
* Public Methods
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* Constructs a QAction to hide / show this DebugConsole.
|
||||
* @return QAction to toggle visibility of this DebugConsole.
|
||||
*/
|
||||
QAction * getActionToggleConsole();
|
||||
|
||||
private:
|
||||
/*************************************************************************
|
||||
* Private Methods
|
||||
************************************************************************/
|
||||
|
||||
// clang-format off
|
||||
void teardownGL() { /* Nothing to teardown yet... */ }
|
||||
// clang-format on
|
||||
|
||||
public:
|
||||
/*************************************************************************
|
||||
* Public Inherited Virtual Methods
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* Called when the widget is first constructed.
|
||||
*/
|
||||
@@ -104,24 +95,61 @@ namespace Qtk {
|
||||
* Accessors
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* @return The active scene being viewed in this widget.
|
||||
*/
|
||||
inline Qtk::Scene * getScene() { return mScene; }
|
||||
|
||||
/*************************************************************************
|
||||
* Setters
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* @param scene The new scene to view.
|
||||
*/
|
||||
void setScene(Qtk::Scene * scene);
|
||||
|
||||
public slots:
|
||||
|
||||
/**
|
||||
* Toggle visibility of the DebugConsole associated with this QtkWidget.
|
||||
*/
|
||||
void toggleConsole();
|
||||
|
||||
protected slots:
|
||||
signals:
|
||||
/**
|
||||
* Log a message to the DebugConsole associated with this widget.
|
||||
* @param message The message to log.
|
||||
* @param context The context of the log message.
|
||||
*/
|
||||
void sendLog(const QString & message, DebugContext context = Status);
|
||||
|
||||
protected:
|
||||
/*************************************************************************
|
||||
* Qt Slots
|
||||
* Protected Methods
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* @param event Key press event to update camera input manager.
|
||||
*/
|
||||
void keyPressEvent(QKeyEvent * event) override;
|
||||
|
||||
/**
|
||||
* @param event Key release event to update camera input manager.
|
||||
*/
|
||||
void keyReleaseEvent(QKeyEvent * event) override;
|
||||
|
||||
/**
|
||||
* @param event Mouse button press event to update camera input manager.
|
||||
*/
|
||||
void mousePressEvent(QMouseEvent * event) override;
|
||||
|
||||
/**
|
||||
* @param event Mouse button release event to update camera input manager.
|
||||
*/
|
||||
void mouseReleaseEvent(QMouseEvent * event) override;
|
||||
|
||||
protected slots:
|
||||
/**
|
||||
* Called when the `frameSwapped` signal is caught.
|
||||
* See definition of initializeGL()
|
||||
@@ -137,39 +165,39 @@ namespace Qtk {
|
||||
*/
|
||||
void messageLogged(const QOpenGLDebugMessage & msg);
|
||||
#endif
|
||||
public:
|
||||
signals:
|
||||
void sendLog(
|
||||
const QString & message, Qtk::DebugContext context = Qtk::Status);
|
||||
|
||||
protected:
|
||||
/*************************************************************************
|
||||
* Protected Methods
|
||||
************************************************************************/
|
||||
|
||||
void keyPressEvent(QKeyEvent * event) override;
|
||||
void keyReleaseEvent(QKeyEvent * event) override;
|
||||
void mousePressEvent(QMouseEvent * event) override;
|
||||
void mouseReleaseEvent(QMouseEvent * event) override;
|
||||
|
||||
private:
|
||||
/*************************************************************************
|
||||
* Private Methods
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* Deconstruct any resources we have allocated for this widget.
|
||||
*/
|
||||
void teardownGL();
|
||||
|
||||
/**
|
||||
* Callback function to update input for camera controls
|
||||
*/
|
||||
static void updateCameraInput();
|
||||
|
||||
#ifdef QTK_DEBUG
|
||||
/**
|
||||
* Prints OpenGL context information at start of debug session.
|
||||
*/
|
||||
void printContextInformation();
|
||||
QOpenGLDebugLogger * mDebugLogger;
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
* Private Members
|
||||
************************************************************************/
|
||||
|
||||
bool mConsoleActive = false;
|
||||
#ifdef QTK_DEBUG
|
||||
QOpenGLDebugLogger * mDebugLogger;
|
||||
#endif
|
||||
Qtk::Scene * mScene;
|
||||
Qtk::DebugConsole * mConsole;
|
||||
bool mConsoleActive = false;
|
||||
};
|
||||
} // namespace Qtk
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Toolbox plugin for object details and options ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Toolbox plugin for object details and options ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
@@ -22,10 +22,20 @@ namespace Qtk {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/*************************************************************************
|
||||
* Contructors / Destructors
|
||||
*************************************************************************/
|
||||
|
||||
explicit ToolBox(QWidget * parent = nullptr);
|
||||
|
||||
~ToolBox();
|
||||
|
||||
private:
|
||||
|
||||
/*************************************************************************
|
||||
* Private Members
|
||||
************************************************************************/
|
||||
|
||||
Ui::ToolBox * ui;
|
||||
};
|
||||
} // namespace Qtk
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: TreeView plugin for scene hierarchy ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
@@ -28,8 +28,9 @@ Qtk::TreeView::~TreeView() {
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Public Members
|
||||
* Public Methods
|
||||
******************************************************************************/
|
||||
|
||||
void Qtk::TreeView::updateView(const Qtk::Scene * scene) {
|
||||
ui->treeWidget->clear();
|
||||
ui->treeWidget->setColumnCount(1);
|
||||
@@ -48,9 +49,9 @@ void Qtk::TreeView::itemFocus(QTreeWidgetItem * item, int column) {
|
||||
auto & transform = scene->getCamera().getTransform();
|
||||
auto object = scene->getObject(name);
|
||||
Transform3D * objectTransform;
|
||||
if(object->getType() == Object::MESH) {
|
||||
if(object->getType() == Object::QTK_MESH) {
|
||||
objectTransform = &dynamic_cast<MeshRenderer *>(object)->getTransform();
|
||||
} else if(object->getType() == Object::MODEL) {
|
||||
} else if(object->getType() == Object::QTK_MODEL) {
|
||||
objectTransform = &dynamic_cast<Model *>(object)->getTransform();
|
||||
}
|
||||
transform.setTranslation(objectTransform->getTranslation());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: TreeView plugin for scene hierarchy ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
@@ -26,10 +26,18 @@ namespace Qtk {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/*************************************************************************
|
||||
* Constructors / Destructors
|
||||
************************************************************************/
|
||||
|
||||
explicit TreeView(QWidget * parent = nullptr);
|
||||
|
||||
~TreeView();
|
||||
|
||||
/*************************************************************************
|
||||
* Public Methods
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* Updates the QTreeWidget with all objects within the scene.
|
||||
* @param scene The scene to load objects from.
|
||||
@@ -48,6 +56,10 @@ namespace Qtk {
|
||||
void itemFocus(QTreeWidgetItem * item, int column);
|
||||
|
||||
private:
|
||||
/*************************************************************************
|
||||
* Private Members
|
||||
************************************************************************/
|
||||
|
||||
Ui::TreeView * ui;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Generic Qt Designer widget plugin ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
@@ -11,10 +11,14 @@
|
||||
#include <QtPlugin>
|
||||
#include <utility>
|
||||
|
||||
#include "qtk/qtkapi.h"
|
||||
#include <qtk/qtkapi.h>
|
||||
|
||||
#include "widgetplugin.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Constructors, Destructors
|
||||
******************************************************************************/
|
||||
|
||||
WidgetPlugin::WidgetPlugin(
|
||||
QString group, QString class_name, QString include,
|
||||
WidgetPlugin::Factory factory) :
|
||||
@@ -22,21 +26,11 @@ WidgetPlugin::WidgetPlugin(
|
||||
m_className(std::move(class_name)), m_includeFile(std::move(include)),
|
||||
m_factory(std::move(factory)), m_objectName(class_name) {}
|
||||
|
||||
QString WidgetPlugin::toolTip() const {
|
||||
return QStringLiteral("A custom widget tool tip.");
|
||||
}
|
||||
WidgetPlugin::WidgetPlugin(QObject * parent) : QObject(parent) {}
|
||||
|
||||
QString WidgetPlugin::whatsThis() const {
|
||||
return QStringLiteral("Custom widget what's this?");
|
||||
}
|
||||
|
||||
QIcon WidgetPlugin::icon() const {
|
||||
return Qtk::getIcon();
|
||||
}
|
||||
|
||||
bool WidgetPlugin::isContainer() const {
|
||||
return true;
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Public Methods
|
||||
******************************************************************************/
|
||||
|
||||
QString WidgetPlugin::group() const {
|
||||
return m_group;
|
||||
@@ -54,6 +48,22 @@ QWidget * WidgetPlugin::createWidget(QWidget * parent) {
|
||||
return m_factory(parent);
|
||||
}
|
||||
|
||||
QString WidgetPlugin::toolTip() const {
|
||||
return QStringLiteral("A custom widget tool tip.");
|
||||
}
|
||||
|
||||
QString WidgetPlugin::whatsThis() const {
|
||||
return QStringLiteral("Custom widget what's this?");
|
||||
}
|
||||
|
||||
QIcon WidgetPlugin::icon() const {
|
||||
return Qtk::getIcon();
|
||||
}
|
||||
|
||||
bool WidgetPlugin::isContainer() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WidgetPlugin::isInitialized() const {
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Generic Qt Designer widget plugin ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
@@ -22,14 +22,21 @@ class QDESIGNER_WIDGET_EXPORT WidgetPlugin :
|
||||
using Factory = std::function<QWidget *(QWidget *)>;
|
||||
|
||||
public:
|
||||
/***************************************************************************
|
||||
* Contructors / Destructors
|
||||
**************************************************************************/
|
||||
|
||||
WidgetPlugin(
|
||||
QString group, QString class_name, QString include, Factory factory);
|
||||
|
||||
explicit WidgetPlugin(QObject * parent = nullptr) : QObject(parent) {}
|
||||
explicit WidgetPlugin(QObject * parent = nullptr);
|
||||
|
||||
~WidgetPlugin() = default;
|
||||
|
||||
public:
|
||||
/***************************************************************************
|
||||
* Public Methods
|
||||
**************************************************************************/
|
||||
|
||||
/**
|
||||
* @return The name of the group to which this widget belongs.
|
||||
*/
|
||||
@@ -56,7 +63,7 @@ class QDESIGNER_WIDGET_EXPORT WidgetPlugin :
|
||||
* @param parent Parent widget to the new instance of this widget.
|
||||
* @return A new instance of this custom widget.
|
||||
*/
|
||||
QWidget * createWidget(QWidget * parent) override;
|
||||
[[nodiscard]] QWidget * createWidget(QWidget * parent) override;
|
||||
|
||||
/**
|
||||
* @return Short description used in Qt Designer tool tips.
|
||||
@@ -102,8 +109,11 @@ class QDESIGNER_WIDGET_EXPORT WidgetPlugin :
|
||||
[[nodiscard]] QString domXml() const override;
|
||||
|
||||
private:
|
||||
bool m_initialized = false;
|
||||
/***************************************************************************
|
||||
* Private Members
|
||||
**************************************************************************/
|
||||
|
||||
bool m_initialized = false;
|
||||
QString m_group;
|
||||
QString m_className;
|
||||
QString m_objectName;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Collection of widget plugins for Qt Designer ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
@@ -14,6 +14,10 @@
|
||||
#include "treeview.h"
|
||||
#include "widgetplugin.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Constructors, Destructors
|
||||
******************************************************************************/
|
||||
|
||||
WidgetPluginCollection::WidgetPluginCollection(QObject * parent) :
|
||||
QObject(parent), m_collectionName("Qtk Widget Collection") {
|
||||
m_collection = {
|
||||
@@ -28,6 +32,11 @@ WidgetPluginCollection::WidgetPluginCollection(QObject * parent) :
|
||||
[](QWidget * parent) { return new Qtk::ToolBox(parent); }),
|
||||
};
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Public Methods
|
||||
******************************************************************************/
|
||||
|
||||
QList<QDesignerCustomWidgetInterface *> WidgetPluginCollection::customWidgets()
|
||||
const {
|
||||
return m_collection;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Collection of widget plugins for Qt Designer ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
@@ -17,16 +17,32 @@ class WidgetPluginCollection :
|
||||
public QDesignerCustomWidgetCollectionInterface {
|
||||
Q_OBJECT
|
||||
// Since we're exporting a collection, this is the only plugin metadata
|
||||
// needed.
|
||||
// needed. We don't need this for-each widget in the collection.
|
||||
Q_PLUGIN_METADATA(IID "com.Klips.WidgetPluginCollection")
|
||||
// Tell Qt Object system that we're implementing an interface.
|
||||
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
|
||||
|
||||
public:
|
||||
/***************************************************************************
|
||||
* Contructors / Destructors
|
||||
**************************************************************************/
|
||||
|
||||
explicit WidgetPluginCollection(QObject * parent = nullptr);
|
||||
|
||||
/***************************************************************************
|
||||
* Public Methods
|
||||
**************************************************************************/
|
||||
|
||||
/**
|
||||
* @return QList of all custom widgets pointers.
|
||||
*/
|
||||
[[nodiscard]] QList<QDesignerCustomWidgetInterface *> customWidgets() const;
|
||||
|
||||
private:
|
||||
/***************************************************************************
|
||||
* Private Members
|
||||
**************************************************************************/
|
||||
|
||||
QList<QDesignerCustomWidgetInterface *> m_collection;
|
||||
QString m_collectionName;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user