From 497b24c03ff7a6312aca0ec6880084a4064d5746 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Mon, 20 Jan 2025 11:50:47 +0100 Subject: [PATCH] feat: Basic context menu for explorer --- assets/icons/editor/delete.png | Bin 0 -> 715 bytes editor/mainwindow.cpp | 16 ++++++++++++++++ editor/mainwindow.h | 2 ++ editor/mainwindow.ui | 15 +++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 assets/icons/editor/delete.png diff --git a/assets/icons/editor/delete.png b/assets/icons/editor/delete.png new file mode 100644 index 0000000000000000000000000000000000000000..08f249365afd29594b51210c6e21ba253897505d GIT binary patch literal 715 zcmV;+0yO=JP)C4}Mrzlg<+1Y8PEBfUp0jJpx4B>@E+cy3`^(Gw`Mf+2&yxZm<$to~Vpgvg&QKNR z_f#1(r6svZt%iF?s+n<8X?B&!h3g9Dbb8_=MX}!;HiQSAh`bp^WMl~Z-44teO7W_Y zV4thSL{h;rJY7!l3%5J4H1!tIzB`Dv+YxO(haWeausGZYkI8^hWj6mzo=L0{%;yxzh{5!Htr?51 zvG|W62MzC8BZ76hRpCyO2zOn<%e)K>NHge!-~)Ap33OdWw6hsLYbCxGNt0%wk_2z7 zfyYvXheSG)5HRK1VB~%mq7Dmurw#bi@hEcOr3&G1ZiF*$M=&9nB#VNf&Q^r$4G5kp zTURh&s)E0%5&hyVD}sp<72~zmAY`Y(9aqO6CXF%=zFHGzO-A&I(pE}v70YQxCPJ{Y z4L+?5-crdLn3ZRPEs!A4ehEY3ZRpL~w9>@aMN+{F4dI@v&>(QDHQum!mG~E^$OS8l z!7?%Uwib*ROP67Hw`ika)gX-(8Ia`-u_IEhxG7U<13kSsMW+$lbb2dUMm5p6pa}cjgA+U$^mJ^AjD?&bdi)8~y+Q002ovPDHLkV1g8IMc@Dc literal 0 HcmV?d00001 diff --git a/editor/mainwindow.cpp b/editor/mainwindow.cpp index 37c7526..3f3af5f 100644 --- a/editor/mainwindow.cpp +++ b/editor/mainwindow.cpp @@ -22,6 +22,7 @@ #include "qevent.h" #include "qnamespace.h" #include "qobject.h" +#include "qtreeview.h" class ExplorerEventFilter : public QObject { @@ -68,6 +69,21 @@ MainWindow::MainWindow(QWidget *parent) ui->explorerView->setAcceptDrops(true); ui->explorerView->setDropIndicatorShown(true); ui->explorerView->installEventFilter(new ExplorerEventFilter(ui->explorerView, &explorerModel)); + ui->explorerView->setContextMenuPolicy(Qt::CustomContextMenu); + + explorerMenu.addAction(ui->actionDelete); + + connect(ui->explorerView, &QTreeView::customContextMenuRequested, this, [&](const QPoint& point) { + QModelIndex index = ui->explorerView->indexAt(point); + explorerMenu.exec(ui->explorerView->viewport()->mapToGlobal(point)); + }); + + connect(ui->actionDelete, &QAction::triggered, this, [&]() { + QModelIndexList selectedIndexes = ui->explorerView->selectionModel()->selectedIndexes(); + for (QModelIndex index : selectedIndexes) { + explorerModel.fromIndex(index)->SetParent(std::nullopt); + } + }); simulationInit(); diff --git a/editor/mainwindow.h b/editor/mainwindow.h index 79695b4..a41d01b 100644 --- a/editor/mainwindow.h +++ b/editor/mainwindow.h @@ -4,6 +4,7 @@ #include "explorermodel.h" #include "qbasictimer.h" #include "qcoreevent.h" +#include "qmenu.h" #include #include @@ -23,6 +24,7 @@ public: private: ExplorerModel explorerModel; + QMenu explorerMenu; Ui::MainWindow *ui; QBasicTimer timer; diff --git a/editor/mainwindow.ui b/editor/mainwindow.ui index 1ec3c87..74fc745 100644 --- a/editor/mainwindow.ui +++ b/editor/mainwindow.ui @@ -61,6 +61,21 @@ + + + + assets/icons/editor/delete.pngassets/icons/editor/delete.png + + + Delete + + + <html><head/><body><p>Deletes a selected object</p></body></html> + + + Del + +