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 <qsoundeffect.h>
|
||||
#include <string>
|
||||
#include "./ui_mainwindow.h"
|
||||
#include "mainglwidget.h"
|
||||
#include "datatypes/vector.h"
|
||||
#include "handles.h"
|
||||
|
@ -19,10 +20,11 @@
|
|||
#include "datatypes/meta.h"
|
||||
|
||||
#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));
|
||||
|
||||
MainGLWidget::MainGLWidget(QWidget* parent): QOpenGLWidget(parent) {
|
||||
MainGLWidget::MainGLWidget(QWidget* parent): QOpenGLWidget(parent), contextMenu(this) {
|
||||
setFocusPolicy(Qt::FocusPolicy::ClickFocus);
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
@ -115,6 +117,7 @@ CFrame snapCFrame(CFrame frame) {
|
|||
return CFrame(frame.Position(), frame.Position() + closestVec1, closestVec2);
|
||||
}
|
||||
|
||||
bool tryMouseContextMenu = false;
|
||||
bool isMouseDragging = false;
|
||||
std::weak_ptr<Part> draggingObject;
|
||||
std::optional<HandleFace> draggingHandle;
|
||||
|
@ -339,6 +342,7 @@ void MainGLWidget::wheelEvent(QWheelEvent* evt) {
|
|||
}
|
||||
|
||||
void MainGLWidget::mouseMoveEvent(QMouseEvent* evt) {
|
||||
tryMouseContextMenu = false;
|
||||
handleCameraRotate(evt);
|
||||
handleObjectDrag(evt);
|
||||
handleCursorChange(evt);
|
||||
|
@ -357,6 +361,7 @@ void MainGLWidget::mouseMoveEvent(QMouseEvent* evt) {
|
|||
}
|
||||
|
||||
void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
|
||||
tryMouseContextMenu = evt->button() == Qt::RightButton;
|
||||
switch(evt->button()) {
|
||||
// Camera drag
|
||||
case Qt::RightButton: {
|
||||
|
@ -443,6 +448,23 @@ void MainGLWidget::mouseReleaseEvent(QMouseEvent* evt) {
|
|||
isMouseDragging = false;
|
||||
draggingObject = {};
|
||||
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;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QOpenGLWidget>
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
#include <qmenu.h>
|
||||
|
||||
class HandleFace;
|
||||
class MainWindow;
|
||||
|
@ -16,6 +17,7 @@ public:
|
|||
void updateCycle();
|
||||
std::shared_ptr<Part> lastPart;
|
||||
|
||||
void buildContextMenu();
|
||||
protected:
|
||||
void initializeGL() override;
|
||||
void resizeGL(int w, int h) override;
|
||||
|
@ -36,6 +38,8 @@ protected:
|
|||
void keyPressEvent(QKeyEvent* evt) override;
|
||||
void keyReleaseEvent(QKeyEvent* evt) override;
|
||||
|
||||
QMenu contextMenu;
|
||||
|
||||
MainWindow* mainWindow();
|
||||
float snappingFactor();
|
||||
};
|
||||
|
|
|
@ -85,6 +85,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
this->close();
|
||||
});
|
||||
|
||||
ui->explorerView->buildContextMenu();
|
||||
|
||||
connectActionHandlers();
|
||||
|
||||
// Update properties
|
||||
|
@ -143,10 +145,6 @@ void MainWindow::closeEvent(QCloseEvent* evt) {
|
|||
}
|
||||
|
||||
void MainWindow::connectActionHandlers() {
|
||||
// Explorer View
|
||||
|
||||
ui->explorerView->buildContextMenu();
|
||||
|
||||
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->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() {
|
||||
timer.start(33, this);
|
||||
placeWidget->buildContextMenu();
|
||||
|
||||
std::shared_ptr<Part> lastPart;
|
||||
// Baseplate
|
||||
|
|
Loading…
Add table
Reference in a new issue