feat: Basic context menu for explorer

This commit is contained in:
maelstrom 2025-01-20 11:50:47 +01:00
parent 6931aa5b7e
commit 497b24c03f
4 changed files with 33 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

View file

@ -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();

View file

@ -4,6 +4,7 @@
#include "explorermodel.h"
#include "qbasictimer.h"
#include "qcoreevent.h"
#include "qmenu.h"
#include <QMainWindow>
#include <QLineEdit>
@ -23,6 +24,7 @@ public:
private:
ExplorerModel explorerModel;
QMenu explorerMenu;
Ui::MainWindow *ui;
QBasicTimer timer;

View file

@ -61,6 +61,21 @@
</layout>
</widget>
</widget>
<action name="actionDelete">
<property name="icon">
<iconset>
<normaloff>assets/icons/editor/delete.png</normaloff>assets/icons/editor/delete.png</iconset>
</property>
<property name="text">
<string>Delete</string>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Deletes a selected object&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="shortcut">
<string>Del</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>