mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-17 15:38:11 +08:00
[UI] Create EditorPage
- Adjusted Sceneviewer for embedding
This commit is contained in:
parent
b198e4d7c5
commit
ea4c3dcc7e
113
FinalProject/editorpage.cpp
Normal file
113
FinalProject/editorpage.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
#pragma once
|
||||
|
||||
#include <qfontdatabase.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
42
FinalProject/editorpage.h
Normal file
42
FinalProject/editorpage.h
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <qwidget.h>
|
||||
#include <qboxlayout.h>
|
||||
#include <qlabel.h>
|
||||
|
||||
#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;
|
||||
};
|
||||
@ -5,6 +5,7 @@
|
||||
#include <qresource.h>
|
||||
#include <qurl.h>
|
||||
#include <qdir.h>
|
||||
#include <qpainterpath.h>
|
||||
|
||||
#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) {
|
||||
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());
|
||||
}
|
||||
|
||||
@ -35,6 +35,10 @@ private:
|
||||
QPoint _lastMousePosition;
|
||||
Renderable* _selectedObject = nullptr;
|
||||
|
||||
// UI interface control
|
||||
const int _cornerRadius = 10;
|
||||
bool _initialized = false;
|
||||
|
||||
public:
|
||||
SceneViewer(QWidget* parent = 0);
|
||||
~SceneViewer();
|
||||
@ -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;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user