diff --git a/FinalProject/editorpage.cpp b/FinalProject/editorpage.cpp new file mode 100644 index 0000000..47abe62 --- /dev/null +++ b/FinalProject/editorpage.cpp @@ -0,0 +1,113 @@ +#pragma once + +#include + +#include "editorpage.h" + +EditorPage::EditorPage(QWidget* parent) : + PageWidget(parent) +{ + _contentWidget->setMouseTracking(true); + + // Construct title layout + _titleLayout = new QVBoxLayout(_contentWidget); + _titleLayout->setContentsMargins(28, 46, 28, 28); + _titleLayout->setSpacing(18); + _titleLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); + _contentWidget->setLayout(_titleLayout); + + // Construct title + _titleLabel = new QLabel("EDITOR", _contentWidget); + _titleLabel->setFont(_titleFont); + _titleLayout->addWidget(_titleLabel); + _titleLabel->show(); + + // Construct main layout + _mainWidget = new QWidget(_contentWidget); + _mainWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + _mainLayout = new QHBoxLayout(_mainWidget); + _mainLayout->setContentsMargins(0, 0, 0, 0); + _mainLayout->setSpacing(16); + _mainWidget->setLayout(_mainLayout); + _titleLayout->addWidget(_mainWidget); + _mainWidget->show(); + + // Generate scene viewer + _sceneViewerContainer = new RoundedCornerWidget(_mainWidget); + _sceneViewerContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + _sceneViewerContainerLayout = new QVBoxLayout(_sceneViewerContainer->mainWidget()); + _sceneViewerContainerLayout->setContentsMargins(0, 0, 0, 0); + _sceneViewerContainerLayout->setSpacing(0); + _sceneViewerContainer->mainWidget()->setLayout(_sceneViewerContainerLayout); + _sceneViewer = new SceneViewer(_sceneViewerContainer->mainWidget()); + _sceneViewerContainerLayout->addWidget(_sceneViewer); + _sceneViewer->show(); + _mainLayout->addWidget(_sceneViewerContainer); + _sceneViewerContainer->show(); +} + +EditorPage::~EditorPage() {} + +PushButton* EditorPage::getPageIconButton(QWidget* context) { + // Check for existed button + if (_iconButton != nullptr) { + return _iconButton; + } + + // Generate new icon button + _iconButton = new PushButton(nullptr, context); + _iconButton->setMargin(20, 18, 16, 18); + _iconButtonLabel = new QLabel(_iconButton); + _iconButtonLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); + QFont iconButtonFont("Font Awesome 6 Free Solid", 12); + iconButtonFont.setStyleStrategy(QFont::PreferAntialias); + _iconButtonLabel->setFont(iconButtonFont); + _iconButtonLabel->setText("\uf304"); // set icon to "pen" icon + _iconButtonLabel->setAlignment(Qt::AlignLeft); + _iconButton->setChildWidget(_iconButtonLabel); + + // Return newly generated icon + return _iconButton; +} + +PushButton* EditorPage::getPageTextButton(QWidget* context) { + // Check for existed button + if (_textButton != nullptr) { + return _textButton; + } + + // Generate new text button + _textButton = new PushButton(nullptr, context); + _textButton->setMargin(20, 18, 16, 18); + _textButtonWidget = new QWidget(_textButton); + _textButtonLayout = new QHBoxLayout(_textButtonWidget); + _textButtonLayout->setContentsMargins(0, 0, 0, 0); + _textButtonLayout->setSpacing(8); + _textButtonWidget->setLayout(_textButtonLayout); + + // Generate text button contents + _textButtonIcon = new QLabel(_textButtonWidget); + QFont textButtonFont("Font Awesome 6 Free Solid", 12); + textButtonFont.setStyleStrategy(QFont::PreferQuality); + _textButtonIcon->setFont(textButtonFont); + _textButtonIcon->setText("\uf304"); // set icon to "pen" icon + _textButtonIcon->setAlignment(Qt::AlignLeft); + + _textButtonLabel = new QLabel(_textButtonWidget); + _textButtonLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); + _textButtonLabel->setText("Editor"); + _textButtonLabel->setAlignment(Qt::AlignLeft); + + // Add text button contents to layout + _textButtonLayout->addWidget(_textButtonIcon); + _textButtonLayout->addWidget(_textButtonLabel); + _textButtonIcon->show(); + _textButtonLabel->show(); + + // Set text button child widget + _textButton->setChildWidget(_textButtonWidget); + _textButtonWidget->show(); + + // Return newly generated text button + return _textButton; +} diff --git a/FinalProject/editorpage.h b/FinalProject/editorpage.h new file mode 100644 index 0000000..ac2a645 --- /dev/null +++ b/FinalProject/editorpage.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include + +#include "pagewidget.h" +#include "sceneviewer.h" +#include "roundedcornerwidget.h" + +class EditorPage : public PageWidget { + + Q_OBJECT + +public: + EditorPage(QWidget* parent = 0); + ~EditorPage(); + +private: + // Push button icons + QLabel* _iconButtonLabel = nullptr; + QWidget* _textButtonWidget = nullptr; + QHBoxLayout* _textButtonLayout = nullptr; + QLabel* _textButtonIcon = nullptr; + QLabel* _textButtonLabel = nullptr; + + // UI elements + QVBoxLayout* _titleLayout = nullptr; + const QFont _titleFont = QFont("DengXian", 26, QFont::ExtraLight); + QLabel* _titleLabel = nullptr; + + QWidget* _mainWidget = nullptr; + QHBoxLayout* _mainLayout = nullptr; + + RoundedCornerWidget* _sceneViewerContainer = nullptr; + QVBoxLayout* _sceneViewerContainerLayout = nullptr; + SceneViewer* _sceneViewer = nullptr; + +public: + virtual PushButton* getPageIconButton(QWidget* context) override; + virtual PushButton* getPageTextButton(QWidget* context) override; +}; diff --git a/FinalProject/sceneviewer.cpp b/FinalProject/sceneviewer.cpp index 2ddb15f..98198f8 100644 --- a/FinalProject/sceneviewer.cpp +++ b/FinalProject/sceneviewer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "vbo.h" #include "vao.h" @@ -17,6 +18,7 @@ using std::vector; SceneViewer::SceneViewer(QWidget* parent) : QOpenGLWidget(parent) { + // OpenGL initialize QSurfaceFormat format; format.setProfile(QSurfaceFormat::CoreProfile); format.setVersion(4, 3); @@ -70,7 +72,7 @@ void SceneViewer::initializeGL() { Renderable backpack(backpackModel); _objects.push_back(backpack); - _camera.setPosition(glm::vec3(0.0f, 0.0f, 5.0f)); + _camera.setPosition(glm::vec3(0.0f, 0.0f, 10.0f)); } void SceneViewer::resizeGL(int w, int h) { @@ -78,6 +80,8 @@ void SceneViewer::resizeGL(int w, int h) { } void SceneViewer::paintGL() { + Logger::debug("Repainting"); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); _shaderProgram.bind(); @@ -106,7 +110,9 @@ void SceneViewer::mousePressEvent(QMouseEvent* event) { } void SceneViewer::mouseMoveEvent(QMouseEvent* event) { - Logger::debug("Mouse moved with offset: " + std::to_string(event->x() - _lastMousePosition.x()) + ", " + std::to_string(event->y() - _lastMousePosition.y())); + if (event->buttons() != Qt::NoButton) { + Logger::debug("Mouse moved with offset: " + std::to_string(event->x() - _lastMousePosition.x()) + ", " + std::to_string(event->y() - _lastMousePosition.y())); + } // Check the type of button pressed switch (event->buttons()) { case Qt::LeftButton: { @@ -152,7 +158,7 @@ void SceneViewer::mouseMoveEvent(QMouseEvent* event) { // Update the last mouse position _lastMousePosition = event->pos(); // Update the view - update(); + parentWidget()->update(); } void SceneViewer::wheelEvent(QWheelEvent* event) { @@ -165,5 +171,31 @@ void SceneViewer::wheelEvent(QWheelEvent* event) { Logger::debug("New camera position: " + std::to_string(_camera.position().x) + ", " + std::to_string(_camera.position().y) + ", " + std::to_string(_camera.position().z)); Logger::debug("New center position: " + std::to_string(_rotateCenter.x) + ", " + std::to_string(_rotateCenter.y) + ", " + std::to_string(_rotateCenter.z)); // Update the view - update(); + parentWidget()->update(); +} + +void SceneViewer::showEvent(QShowEvent* event) { + // Call show event of super class + QOpenGLWidget::showEvent(event); + + if (_initialized) { + return; + } + + //// Create mask for rounded corner + //QPainterPath mask; + //mask.addRoundedRect(rect(), _cornerRadius, _cornerRadius); + //setMask(mask.toFillPolygon().toPolygon()); + + _initialized = true; +} + +void SceneViewer::resizeEvent(QResizeEvent* event) { + // Call resize event of super class + QOpenGLWidget::resizeEvent(event); + + //// Create mask for rounded corner + //QPainterPath mask; + //mask.addRoundedRect(rect(), _cornerRadius, _cornerRadius); + //setMask(mask.toFillPolygon().toPolygon()); } diff --git a/FinalProject/sceneviewer.h b/FinalProject/sceneviewer.h index a854b32..5d2460e 100644 --- a/FinalProject/sceneviewer.h +++ b/FinalProject/sceneviewer.h @@ -34,6 +34,10 @@ private: // User Interaction flags section--------------------- QPoint _lastMousePosition; Renderable* _selectedObject = nullptr; + + // UI interface control + const int _cornerRadius = 10; + bool _initialized = false; public: SceneViewer(QWidget* parent = 0); @@ -50,4 +54,7 @@ protected: virtual void mouseMoveEvent(QMouseEvent* event) override; virtual void wheelEvent(QWheelEvent* event) override; + // UI update events + virtual void showEvent(QShowEvent* event) override; + virtual void resizeEvent(QResizeEvent* event) override; }; \ No newline at end of file