mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-18 16:08:11 +08:00
[UI] Update main appearance
- Rounded corner window - Side bar - Rounded corner view port
This commit is contained in:
parent
ea4c3dcc7e
commit
75f3eef152
@ -8,13 +8,12 @@
|
|||||||
|
|
||||||
#define MAX_MOUSE_MOVEMENT 300
|
#define MAX_MOUSE_MOVEMENT 300
|
||||||
|
|
||||||
FramelessWidget::FramelessWidget(int cornerRadius, unsigned int attributes, QWidget* parent)
|
FramelessWindow::FramelessWindow(int cornerRadius, unsigned int attributes, QWidget* parent)
|
||||||
: _cornerRadius(cornerRadius), _attributes((LUI_WINDOW_ATTRIBUTES)attributes), QWidget(parent)
|
: _cornerRadius(cornerRadius), _attributes((LUI_WINDOW_ATTRIBUTES)attributes), QWidget(parent)
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_TranslucentBackground);
|
setAttribute(Qt::WA_TranslucentBackground);
|
||||||
setWindowFlags(Qt::FramelessWindowHint);
|
setWindowFlags(Qt::FramelessWindowHint);
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
|
||||||
setFocus();
|
setFocus();
|
||||||
|
|
||||||
// Create and properly set real displayed window widget
|
// Create and properly set real displayed window widget
|
||||||
@ -79,33 +78,33 @@ FramelessWidget::FramelessWidget(int cornerRadius, unsigned int attributes, QWid
|
|||||||
|
|
||||||
// Connect window control buttons
|
// Connect window control buttons
|
||||||
connect(_minimizeBtn, &QPushButton::clicked, this, &QWidget::showMinimized);
|
connect(_minimizeBtn, &QPushButton::clicked, this, &QWidget::showMinimized);
|
||||||
connect(_maximizeBtn, &QPushButton::clicked, this, &FramelessWidget::controlWindowScale);
|
connect(_maximizeBtn, &QPushButton::clicked, this, &FramelessWindow::controlWindowScale);
|
||||||
connect(_closeBtn, &QPushButton::clicked, this, &QWidget::close);
|
connect(_closeBtn, &QPushButton::clicked, this, &QWidget::close);
|
||||||
}
|
}
|
||||||
|
|
||||||
FramelessWidget::FramelessWidget(QWidget* parent)
|
FramelessWindow::FramelessWindow(QWidget* parent)
|
||||||
: FramelessWidget(0, LUI_WINDOW_ATTRIBUTES::LUI_WINDOW_NO_ATTRIBUTES, parent)
|
: FramelessWindow(0, LUI_WINDOW_ATTRIBUTES::LUI_WINDOW_NO_ATTRIBUTES, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FramelessWidget::FramelessWidget(int cornerRadius, QWidget* parent)
|
FramelessWindow::FramelessWindow(int cornerRadius, QWidget* parent)
|
||||||
: FramelessWidget(cornerRadius, LUI_WINDOW_ATTRIBUTES::LUI_WINDOW_NO_ATTRIBUTES, parent)
|
: FramelessWindow(cornerRadius, LUI_WINDOW_ATTRIBUTES::LUI_WINDOW_NO_ATTRIBUTES, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FramelessWidget::FramelessWidget(unsigned int attributes, QWidget* parent)
|
FramelessWindow::FramelessWindow(unsigned int attributes, QWidget* parent)
|
||||||
: FramelessWidget(0, attributes, parent)
|
: FramelessWindow(0, attributes, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FramelessWidget::~FramelessWidget() {}
|
FramelessWindow::~FramelessWindow() {}
|
||||||
|
|
||||||
void FramelessWidget::showEvent(QShowEvent* event) {
|
void FramelessWindow::showEvent(QShowEvent* event) {
|
||||||
// Initialize window UI after window is shown
|
// Initialize window UI after window is shown
|
||||||
initializeWindowUI();
|
initializeWindowUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessWidget::initializeWindowUI() {
|
void FramelessWindow::initializeWindowUI() {
|
||||||
if (_initialized) {
|
if (_initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -130,12 +129,13 @@ void FramelessWidget::initializeWindowUI() {
|
|||||||
// Move button widget to the top right of the window widget
|
// Move button widget to the top right of the window widget
|
||||||
_windowBtnWidget->move(_windowWidget->width() - _windowBtnWidget->width() - 18, 18);
|
_windowBtnWidget->move(_windowWidget->width() - _windowBtnWidget->width() - 18, 18);
|
||||||
_windowBtnWidget->show();
|
_windowBtnWidget->show();
|
||||||
|
_windowBtnWidget->raise();
|
||||||
|
|
||||||
// Set initialized state
|
// Set initialized state
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessWidget::resizeEvent(QResizeEvent* event) {
|
void FramelessWindow::resizeEvent(QResizeEvent* event) {
|
||||||
// Resize window border
|
// Resize window border
|
||||||
if (_windowBorder != nullptr) {
|
if (_windowBorder != nullptr) {
|
||||||
_windowBorder->move(_windowWidget->pos() - QPoint(1, 1));
|
_windowBorder->move(_windowWidget->pos() - QPoint(1, 1));
|
||||||
@ -152,7 +152,7 @@ void FramelessWidget::resizeEvent(QResizeEvent* event) {
|
|||||||
_windowBtnWidget->move(_windowWidget->width() - _windowBtnWidget->width() - 18, 18);
|
_windowBtnWidget->move(_windowWidget->width() - _windowBtnWidget->width() - 18, 18);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessWidget::controlWindowScale() {
|
void FramelessWindow::controlWindowScale() {
|
||||||
if ((_attributes & LUI_WINDOW_ATTRIBUTES::LUI_WINDOW_DISABLE_MAXIMIZE) != 0) {
|
if ((_attributes & LUI_WINDOW_ATTRIBUTES::LUI_WINDOW_DISABLE_MAXIMIZE) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -213,7 +213,7 @@ void FramelessWidget::controlWindowScale() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessWidget::updateMouseState(QMouseEvent* event) {
|
void FramelessWindow::updateMouseState(QMouseEvent* event) {
|
||||||
_mouseState = MOUSE_STATE_NONE;
|
_mouseState = MOUSE_STATE_NONE;
|
||||||
if ((_attributes & LUI_WINDOW_ATTRIBUTES::LUI_WINDOW_DISABLE_RESIZE) != 0) {
|
if ((_attributes & LUI_WINDOW_ATTRIBUTES::LUI_WINDOW_DISABLE_RESIZE) != 0) {
|
||||||
return;
|
return;
|
||||||
@ -259,14 +259,14 @@ void FramelessWidget::updateMouseState(QMouseEvent* event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessWidget::mousePressEvent(QMouseEvent* event) {
|
void FramelessWindow::mousePressEvent(QMouseEvent* event) {
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
_mousePressed = true;
|
_mousePressed = true;
|
||||||
_lastMousePosition = event->globalPos().toPointF();
|
_lastMousePosition = event->globalPos().toPointF();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessWidget::mouseReleaseEvent(QMouseEvent* event) {
|
void FramelessWindow::mouseReleaseEvent(QMouseEvent* event) {
|
||||||
_mousePressed = false;
|
_mousePressed = false;
|
||||||
QScreen* screen = QGuiApplication::screenAt(event->globalPos());
|
QScreen* screen = QGuiApplication::screenAt(event->globalPos());
|
||||||
Logger::debug("Current screen geometry:");
|
Logger::debug("Current screen geometry:");
|
||||||
@ -278,7 +278,7 @@ void FramelessWidget::mouseReleaseEvent(QMouseEvent* event) {
|
|||||||
updateMouseState(event);
|
updateMouseState(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessWidget::mouseMoveEvent(QMouseEvent* event) {
|
void FramelessWindow::mouseMoveEvent(QMouseEvent* event) {
|
||||||
Logger::debug("Detected mouse move");
|
Logger::debug("Detected mouse move");
|
||||||
Logger::debug("[+] mouse global position : " + std::to_string(event->globalPos().x()) + ", " + std::to_string(event->globalPos().y()));
|
Logger::debug("[+] mouse global position : " + std::to_string(event->globalPos().x()) + ", " + std::to_string(event->globalPos().y()));
|
||||||
Logger::debug("[+] window geometry: " + std::to_string(frameGeometry().x()) + ", " + std::to_string(frameGeometry().y()) + ", " + std::to_string(frameGeometry().width()) + ", " + std::to_string(frameGeometry().height()));
|
Logger::debug("[+] window geometry: " + std::to_string(frameGeometry().x()) + ", " + std::to_string(frameGeometry().y()) + ", " + std::to_string(frameGeometry().width()) + ", " + std::to_string(frameGeometry().height()));
|
||||||
@ -345,11 +345,11 @@ void FramelessWidget::mouseMoveEvent(QMouseEvent* event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FramelessWidget::LUI_WINDOW_ATTRIBUTES FramelessWidget::getWindowAttributes() {
|
FramelessWindow::LUI_WINDOW_ATTRIBUTES FramelessWindow::getWindowAttributes() {
|
||||||
return _attributes;
|
return _attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessWidget::setWindowAttributes(unsigned int attributes) {
|
void FramelessWindow::setWindowAttributes(unsigned int attributes) {
|
||||||
_attributes = (LUI_WINDOW_ATTRIBUTES)attributes;
|
_attributes = (LUI_WINDOW_ATTRIBUTES)attributes;
|
||||||
if ((_attributes & LUI_WINDOW_ATTRIBUTES::LUI_WINDOW_DISABLE_MINIMIZE) == 0) {
|
if ((_attributes & LUI_WINDOW_ATTRIBUTES::LUI_WINDOW_DISABLE_MINIMIZE) == 0) {
|
||||||
_minimizeBtn->show();
|
_minimizeBtn->show();
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
#include <qgraphicseffect.h>
|
#include <qgraphicseffect.h>
|
||||||
#include <qpushbutton.h>
|
#include <qpushbutton.h>
|
||||||
|
|
||||||
class FramelessWidget : public QWidget {
|
class FramelessWindow : public QWidget {
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -21,13 +21,13 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FramelessWidget(QWidget* parent = 0);
|
FramelessWindow(QWidget* parent = 0);
|
||||||
FramelessWidget(int cornerRadius, QWidget* parent = 0);
|
FramelessWindow(int cornerRadius, QWidget* parent = 0);
|
||||||
FramelessWidget(unsigned int attributes, QWidget* parent = 0);
|
FramelessWindow(unsigned int attributes, QWidget* parent = 0);
|
||||||
FramelessWidget(int cornerRadius, unsigned int attributes, QWidget* parent = 0);
|
FramelessWindow(int cornerRadius, unsigned int attributes, QWidget* parent = 0);
|
||||||
~FramelessWidget();
|
~FramelessWindow();
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
// UI control variables
|
// UI control variables
|
||||||
const int _cornerRadius = 0;
|
const int _cornerRadius = 0;
|
||||||
const QColor _backgroundColor = QColor(251, 251, 251);
|
const QColor _backgroundColor = QColor(251, 251, 251);
|
||||||
|
|||||||
@ -1,13 +1,21 @@
|
|||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
|
#include <qfontdatabase.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv); // Create main application instance
|
||||||
|
|
||||||
|
QFontDatabase::addApplicationFont(":/fonts/font_awesome_6_regular_free.otf"); // Add font awesome font to application
|
||||||
|
QFontDatabase::addApplicationFont(":/fonts/font_awesome_6_solid_free.otf"); // Add font awesome font to application
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.setMouseTracking(true);
|
w.setMouseTracking(true);
|
||||||
w.resize(900, 600);
|
w.resize(900, 600);
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,29 +1,93 @@
|
|||||||
#include <qpainterpath.h>
|
|
||||||
#include <qscreen.h>
|
|
||||||
#include <qlabel.h>
|
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "pushbutton.h"
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
#define MAX_MOUSE_MOVEMENT 300
|
#define MAX_MOUSE_MOVEMENT 300
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: FramelessWidget(20, parent)
|
: FramelessWindow(20, parent)
|
||||||
{
|
{
|
||||||
PushButton* btn = new PushButton(new QLabel("Button"), this);
|
// Create main layout for page and sidebar
|
||||||
btn->setFixedSize(100, 100);
|
_mainLayout = new QHBoxLayout(_windowWidget);
|
||||||
btn->move(100, 100);
|
_mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
btn->show();
|
_mainLayout->setSpacing(0);
|
||||||
connect(btn, &PushButton::onClick, this, [=]() {
|
_windowWidget->setLayout(_mainLayout);
|
||||||
if (btn->isSelected()) {
|
|
||||||
btn->deselect();
|
// Create placeholder widget for pages
|
||||||
|
_placeHolderWidget = new QWidget(_windowWidget);
|
||||||
|
_placeHolderWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
_placeHolderWidget->setMouseTracking(true);
|
||||||
|
|
||||||
|
// Connect the resize event of the placeholder widget to the resizePages function using event filter
|
||||||
|
_placeHolderWidget->installEventFilter(this);
|
||||||
|
|
||||||
|
// Create sidebar
|
||||||
|
_sideBar = new SideBar(_windowWidget);
|
||||||
|
connect(_sideBar, &SideBar::onPageChanged, this, [=](PageWidget* previousPage, PageWidget* currentPage) {
|
||||||
|
// Check for input validity
|
||||||
|
if (previousPage == currentPage) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
if (previousPage != nullptr) {
|
||||||
btn->select();
|
previousPage->offStage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (currentPage != nullptr) {
|
||||||
|
currentPage->onStage();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
_sideBar->setMouseTracking(true);
|
||||||
|
|
||||||
|
// Add sidebar and placeholder widget to main layout
|
||||||
|
_mainLayout->addWidget(_sideBar);
|
||||||
|
_mainLayout->addWidget(_placeHolderWidget);
|
||||||
|
|
||||||
|
// Create editor page and connect to side bar
|
||||||
|
_editorPage = new EditorPage(_placeHolderWidget);
|
||||||
|
_editorPage->setMouseTracking(true);
|
||||||
|
_editorPage->show();
|
||||||
|
_sideBar->addPage(_editorPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::resizePages(QResizeEvent* event) {
|
||||||
|
// Check for input validity
|
||||||
|
if (event == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the size of the placeholder widget
|
||||||
|
QSize size = event->size();
|
||||||
|
|
||||||
|
// Resize the editor page
|
||||||
|
_editorPage->resize(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::showEvent(QShowEvent* event) {
|
||||||
|
// Call parent show event
|
||||||
|
FramelessWindow::showEvent(event);
|
||||||
|
|
||||||
|
// Resize all the pages based on the placeholder widget
|
||||||
|
_editorPage->resize(_placeHolderWidget->size());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::eventFilter(QObject* object, QEvent* event) {
|
||||||
|
// Check for input validity
|
||||||
|
if (object == nullptr || event == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the object is the placeholder widget
|
||||||
|
if (object == _placeHolderWidget) {
|
||||||
|
// Check if the event is a resize event
|
||||||
|
if (event->type() == QEvent::Resize) {
|
||||||
|
// Resize all the pages
|
||||||
|
resizePages(static_cast<QResizeEvent*>(event));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call parent event filter
|
||||||
|
return FramelessWindow::eventFilter(object, event);
|
||||||
|
}
|
||||||
@ -1,12 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "framelesswindow.h"
|
#include <qevent.h>
|
||||||
|
|
||||||
class MainWindow : public FramelessWidget
|
#include "framelesswindow.h"
|
||||||
|
#include "sidebar.h"
|
||||||
|
#include "editorpage.h"
|
||||||
|
|
||||||
|
class MainWindow : public FramelessWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget *parent = nullptr);
|
MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Main ui layout
|
||||||
|
QHBoxLayout* _mainLayout = nullptr;
|
||||||
|
|
||||||
|
// Side bar and corresponding pages
|
||||||
|
SideBar* _sideBar = nullptr;
|
||||||
|
EditorPage* _editorPage = nullptr;
|
||||||
|
|
||||||
|
// Place holder widget for resizing pages
|
||||||
|
QWidget* _placeHolderWidget = nullptr;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void resizePages(QResizeEvent* event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void showEvent(QShowEvent* event) override;
|
||||||
|
virtual bool eventFilter(QObject* object, QEvent* event) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <qwidget.h>
|
||||||
|
|
||||||
|
//class ModelSelector : public QWidget
|
||||||
|
//{
|
||||||
|
// Q_OBJECT
|
||||||
|
//
|
||||||
|
//public:
|
||||||
|
// ModelSelector(QWidget* parent = 0);
|
||||||
|
// ~ModelSelector();
|
||||||
|
//};
|
||||||
|
|||||||
@ -1 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <qwidget.h>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user