From 092553a30b3ccdacda787760ac8774dbf6fa0a72 Mon Sep 17 00:00:00 2001 From: baydam Date: Tue, 1 Sep 2015 12:27:41 +0000 Subject: [PATCH] Add paint context menu --- MainWindow.cpp | 105 +++++++++++++++++++++++++++++++++++++++---------- MainWindow.h | 21 +++++++--- 2 files changed, 99 insertions(+), 27 deletions(-) diff --git a/MainWindow.cpp b/MainWindow.cpp index 7fd6b7e..86f6fc4 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -58,7 +58,8 @@ MainWindow::MainWindow() createLayout(); createActions(); createMenus(); - createContextMenu(); + createMappingContextMenu(); + createPaintContextMenu(); createToolBars(); createStatusBar(); updateRecentFileActions(); @@ -736,12 +737,34 @@ void MainWindow::cloneItem() } } -void MainWindow::renameItem() +void MainWindow::renameMappingItem() { // Set current item editable and rename it QListWidgetItem* item = mappingList->currentItem(); item->setFlags(item->flags() | Qt::ItemIsEditable); mappingList->editItem(item); + contentTab->setCurrentWidget(mappingSplitter); +} + +void MainWindow::deletePaintItem() +{ + if(currentSelectedItem) + { + deletePaint(getItemId(*paintList->currentItem()), false); + } + else + { + qCritical() << "No selected paint" << endl; + } +} + +void MainWindow::renamePaintItem() +{ + // Set current item editable and rename it + QListWidgetItem* item = paintList->currentItem(); + item->setFlags(item->flags() | Qt::ItemIsEditable); + paintList->editItem(item); + contentTab->setCurrentWidget(paintSplitter); } void MainWindow::openRecentFile() @@ -1375,19 +1398,33 @@ void MainWindow::createActions() cloneAction->setIconVisibleInMenu(false); connect(cloneAction, SIGNAL(triggered()), this, SLOT(cloneItem())); - // Delete. - deleteAction = new QAction(tr("Delete"), this); - deleteAction->setShortcut(tr("CTRL+DEL")); - deleteAction->setStatusTip(tr("Delete item")); - deleteAction->setIconVisibleInMenu(false); - connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem())); + // Delete mapping. + deleteMappingAction = new QAction(tr("Delete"), this); + deleteMappingAction->setShortcut(tr("CTRL+DEL")); + deleteMappingAction->setStatusTip(tr("Delete item")); + deleteMappingAction->setIconVisibleInMenu(false); + connect(deleteMappingAction, SIGNAL(triggered()), this, SLOT(deleteItem())); - // Rename. - renameAction = new QAction(tr("Rename"), this); - renameAction->setShortcut(Qt::Key_F2); - renameAction->setStatusTip(tr("Rename item")); - renameAction->setIconVisibleInMenu(false); - connect(renameAction, SIGNAL(triggered()), this, SLOT(renameItem())); + // Rename mapping. + renameMappingAction = new QAction(tr("Rename"), this); + renameMappingAction->setShortcut(Qt::Key_F2); + renameMappingAction->setStatusTip(tr("Rename item")); + renameMappingAction->setIconVisibleInMenu(false); + connect(renameMappingAction, SIGNAL(triggered()), this, SLOT(renameMappingItem())); + + // Delete paint. + deletePaintAction = new QAction(tr("Delete"), this); + //deletePaintAction->setShortcut(tr("CTRL+DEL")); + deletePaintAction->setStatusTip(tr("Delete item")); + deletePaintAction->setIconVisibleInMenu(false); + connect(deletePaintAction, SIGNAL(triggered()), this, SLOT(deletePaintItem())); + + // Rename paint. + renamePaintAction = new QAction(tr("Rename"), this); + //renamePaintAction->setShortcut(Qt::Key_F2); + renamePaintAction->setStatusTip(tr("Rename item")); + renamePaintAction->setIconVisibleInMenu(false); + connect(renamePaintAction, SIGNAL(triggered()), this, SLOT(renamePaintItem())); // Preferences... preferencesAction = new QAction(tr("&Preferences..."), this); @@ -1565,7 +1602,7 @@ void MainWindow::createMenus() editMenu = menuBar->addMenu(tr("&Edit")); editMenu->addAction(undoAction); editMenu->addAction(redoAction); - editMenu->addAction(deleteAction); + editMenu->addAction(deleteMappingAction); editMenu->addAction(preferencesAction); // View. @@ -1589,15 +1626,15 @@ void MainWindow::createMenus() } -void MainWindow::createContextMenu() +void MainWindow::createMappingContextMenu() { // Context menu. - contextMenu = new QMenu(); + mappingContextMenu = new QMenu(); // Add different Action - contextMenu->addAction(cloneAction); - contextMenu->addAction(deleteAction); - contextMenu->addAction(renameAction); + mappingContextMenu->addAction(cloneAction); + mappingContextMenu->addAction(deleteMappingAction); + mappingContextMenu->addAction(renameMappingAction); // Set context menu policy mappingList->setContextMenuPolicy(Qt::CustomContextMenu); @@ -1610,6 +1647,24 @@ void MainWindow::createContextMenu() connect(outputWindow, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMappingContextMenu(const QPoint&))); } +void MainWindow::createPaintContextMenu() +{ + // Paint Context Menu + paintContextMenu = new QMenu(); + + // Add Actions + paintContextMenu->addAction(deletePaintAction); + paintContextMenu->addAction(renamePaintAction); + + // Define Context policy + paintList->setContextMenuPolicy(Qt::CustomContextMenu); + sourceCanvas->setContextMenuPolicy(Qt::CustomContextMenu); + + // Connexions + connect(paintList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showPaintContextMenu(const QPoint&))); + connect(sourceCanvas, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showPaintContextMenu(const QPoint&))); +} + void MainWindow::createToolBars() { mainToolBar = addToolBar(tr("&File")); @@ -2276,7 +2331,15 @@ void MainWindow::showMappingContextMenu(const QPoint &point) QWidget *objectSender = dynamic_cast(sender()); if (objectSender != NULL && mappingList->count() > 0) - contextMenu->exec(objectSender->mapToGlobal(point)); + mappingContextMenu->exec(objectSender->mapToGlobal(point)); +} + +void MainWindow::showPaintContextMenu(const QPoint &point) +{ + QWidget *objectSender = dynamic_cast(sender()); + + if (objectSender != NULL && paintList->count() > 0) + paintContextMenu->exec(objectSender->mapToGlobal(point)); } QString MainWindow::strippedName(const QString &fullFileName) diff --git a/MainWindow.h b/MainWindow.h index ae4dda6..171f612 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -91,8 +91,11 @@ private slots: void openRecentVideo(); // Edit menu. void deleteItem(); + // Context menu. void cloneItem(); - void renameItem(); + void renameMappingItem(); + void deletePaintItem(); + void renamePaintItem(); // Widget callbacks. void handlePaintItemSelectionChanged(); @@ -185,8 +188,10 @@ public slots: void enableStickyVertices(bool display); void enableTestSignal(bool enable); - // Show Context Menu + // Show Mapping Context Menu void showMappingContextMenu(const QPoint &point); + // Show Paint Context Menu + void showPaintContextMenu(const QPoint &point); public: bool setTextureUri(int texture_id, const std::string &uri); @@ -199,7 +204,8 @@ private: void createLayout(); void createActions(); void createMenus(); - void createContextMenu(); + void createMappingContextMenu(); + void createPaintContextMenu(); void createToolBars(); void createStatusBar(); void updateRecentFileActions(); @@ -259,7 +265,8 @@ private: QMenu *helpMenu; QMenu *recentFileMenu; QMenu *recentVideoMenu; - QMenu *contextMenu; + QMenu *mappingContextMenu; + QMenu *paintContextMenu; // Toolbar. QToolBar *mainToolBar; @@ -278,8 +285,10 @@ private: QAction *undoAction; QAction *redoAction; QAction *cloneAction; - QAction *deleteAction; - QAction *renameAction; + QAction *deleteMappingAction; + QAction *renameMappingAction; + QAction *deletePaintAction; + QAction *renamePaintAction; QAction *preferencesAction; QAction *aboutAction; QAction *clearRecentFileActions;