feat(editor): right-click context menu in main gl widget
This commit is contained in:
parent
e5c8bdd2e2
commit
14b0667fc9
4 changed files with 30 additions and 5 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
#include <qsoundeffect.h>
|
#include <qsoundeffect.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "./ui_mainwindow.h"
|
||||||
#include "mainglwidget.h"
|
#include "mainglwidget.h"
|
||||||
#include "datatypes/vector.h"
|
#include "datatypes/vector.h"
|
||||||
#include "handles.h"
|
#include "handles.h"
|
||||||
|
@ -19,10 +20,11 @@
|
||||||
#include "datatypes/meta.h"
|
#include "datatypes/meta.h"
|
||||||
|
|
||||||
#define PI 3.14159
|
#define PI 3.14159
|
||||||
|
#define M_mainWindow dynamic_cast<MainWindow*>(window())
|
||||||
|
|
||||||
static CFrame XYZToZXY(glm::vec3(0, 0, 0), -glm::vec3(1, 0, 0), glm::vec3(0, 0, 1));
|
static CFrame XYZToZXY(glm::vec3(0, 0, 0), -glm::vec3(1, 0, 0), glm::vec3(0, 0, 1));
|
||||||
|
|
||||||
MainGLWidget::MainGLWidget(QWidget* parent): QOpenGLWidget(parent) {
|
MainGLWidget::MainGLWidget(QWidget* parent): QOpenGLWidget(parent), contextMenu(this) {
|
||||||
setFocusPolicy(Qt::FocusPolicy::ClickFocus);
|
setFocusPolicy(Qt::FocusPolicy::ClickFocus);
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
}
|
}
|
||||||
|
@ -115,6 +117,7 @@ CFrame snapCFrame(CFrame frame) {
|
||||||
return CFrame(frame.Position(), frame.Position() + closestVec1, closestVec2);
|
return CFrame(frame.Position(), frame.Position() + closestVec1, closestVec2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tryMouseContextMenu = false;
|
||||||
bool isMouseDragging = false;
|
bool isMouseDragging = false;
|
||||||
std::weak_ptr<Part> draggingObject;
|
std::weak_ptr<Part> draggingObject;
|
||||||
std::optional<HandleFace> draggingHandle;
|
std::optional<HandleFace> draggingHandle;
|
||||||
|
@ -339,6 +342,7 @@ void MainGLWidget::wheelEvent(QWheelEvent* evt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainGLWidget::mouseMoveEvent(QMouseEvent* evt) {
|
void MainGLWidget::mouseMoveEvent(QMouseEvent* evt) {
|
||||||
|
tryMouseContextMenu = false;
|
||||||
handleCameraRotate(evt);
|
handleCameraRotate(evt);
|
||||||
handleObjectDrag(evt);
|
handleObjectDrag(evt);
|
||||||
handleCursorChange(evt);
|
handleCursorChange(evt);
|
||||||
|
@ -357,6 +361,7 @@ void MainGLWidget::mouseMoveEvent(QMouseEvent* evt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
|
void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
|
||||||
|
tryMouseContextMenu = evt->button() == Qt::RightButton;
|
||||||
switch(evt->button()) {
|
switch(evt->button()) {
|
||||||
// Camera drag
|
// Camera drag
|
||||||
case Qt::RightButton: {
|
case Qt::RightButton: {
|
||||||
|
@ -443,6 +448,23 @@ void MainGLWidget::mouseReleaseEvent(QMouseEvent* evt) {
|
||||||
isMouseDragging = false;
|
isMouseDragging = false;
|
||||||
draggingObject = {};
|
draggingObject = {};
|
||||||
draggingHandle = std::nullopt;
|
draggingHandle = std::nullopt;
|
||||||
|
|
||||||
|
// Open context menu
|
||||||
|
if (tryMouseContextMenu)
|
||||||
|
contextMenu.exec(QCursor::pos());
|
||||||
|
tryMouseContextMenu = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainGLWidget::buildContextMenu() {
|
||||||
|
contextMenu.addAction(M_mainWindow->ui->actionDelete);
|
||||||
|
contextMenu.addSeparator();
|
||||||
|
contextMenu.addAction(M_mainWindow->ui->actionCopy);
|
||||||
|
contextMenu.addAction(M_mainWindow->ui->actionCut);
|
||||||
|
contextMenu.addAction(M_mainWindow->ui->actionPaste);
|
||||||
|
contextMenu.addAction(M_mainWindow->ui->actionPasteInto);
|
||||||
|
contextMenu.addSeparator();
|
||||||
|
contextMenu.addAction(M_mainWindow->ui->actionSaveModel);
|
||||||
|
contextMenu.addAction(M_mainWindow->ui->actionInsertModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int moveZ = 0;
|
static int moveZ = 0;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QOpenGLWidget>
|
#include <QOpenGLWidget>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <qmenu.h>
|
||||||
|
|
||||||
class HandleFace;
|
class HandleFace;
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
@ -16,6 +17,7 @@ public:
|
||||||
void updateCycle();
|
void updateCycle();
|
||||||
std::shared_ptr<Part> lastPart;
|
std::shared_ptr<Part> lastPart;
|
||||||
|
|
||||||
|
void buildContextMenu();
|
||||||
protected:
|
protected:
|
||||||
void initializeGL() override;
|
void initializeGL() override;
|
||||||
void resizeGL(int w, int h) override;
|
void resizeGL(int w, int h) override;
|
||||||
|
@ -36,6 +38,8 @@ protected:
|
||||||
void keyPressEvent(QKeyEvent* evt) override;
|
void keyPressEvent(QKeyEvent* evt) override;
|
||||||
void keyReleaseEvent(QKeyEvent* evt) override;
|
void keyReleaseEvent(QKeyEvent* evt) override;
|
||||||
|
|
||||||
|
QMenu contextMenu;
|
||||||
|
|
||||||
MainWindow* mainWindow();
|
MainWindow* mainWindow();
|
||||||
float snappingFactor();
|
float snappingFactor();
|
||||||
};
|
};
|
||||||
|
|
|
@ -85,6 +85,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
this->close();
|
this->close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ui->explorerView->buildContextMenu();
|
||||||
|
|
||||||
connectActionHandlers();
|
connectActionHandlers();
|
||||||
|
|
||||||
// Update properties
|
// Update properties
|
||||||
|
@ -143,10 +145,6 @@ void MainWindow::closeEvent(QCloseEvent* evt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::connectActionHandlers() {
|
void MainWindow::connectActionHandlers() {
|
||||||
// Explorer View
|
|
||||||
|
|
||||||
ui->explorerView->buildContextMenu();
|
|
||||||
|
|
||||||
connect(ui->actionToolSelect, &QAction::triggered, this, [&]() { selectedTool = TOOL_SELECT; updateToolbars(); });
|
connect(ui->actionToolSelect, &QAction::triggered, this, [&]() { selectedTool = TOOL_SELECT; updateToolbars(); });
|
||||||
connect(ui->actionToolMove, &QAction::triggered, this, [&](bool state) { selectedTool = state ? TOOL_MOVE : TOOL_SELECT; updateToolbars(); });
|
connect(ui->actionToolMove, &QAction::triggered, this, [&](bool state) { selectedTool = state ? TOOL_MOVE : TOOL_SELECT; updateToolbars(); });
|
||||||
connect(ui->actionToolScale, &QAction::triggered, this, [&](bool state) { selectedTool = state ? TOOL_SCALE : TOOL_SELECT; updateToolbars(); });
|
connect(ui->actionToolScale, &QAction::triggered, this, [&](bool state) { selectedTool = state ? TOOL_SCALE : TOOL_SELECT; updateToolbars(); });
|
||||||
|
|
|
@ -74,6 +74,7 @@ void PlaceDocument::timerEvent(QTimerEvent* evt) {
|
||||||
|
|
||||||
void PlaceDocument::init() {
|
void PlaceDocument::init() {
|
||||||
timer.start(33, this);
|
timer.start(33, this);
|
||||||
|
placeWidget->buildContextMenu();
|
||||||
|
|
||||||
std::shared_ptr<Part> lastPart;
|
std::shared_ptr<Part> lastPart;
|
||||||
// Baseplate
|
// Baseplate
|
||||||
|
|
Loading…
Add table
Reference in a new issue