From 79158144df1b606982bfa722447416c9549de860 Mon Sep 17 00:00:00 2001 From: Sky Date: Sun, 5 Jan 2014 00:06:59 +0000 Subject: [PATCH] Implement the beloved right click context menu. Just a copy of the instance toolbar --- gui/MainWindow.cpp | 27 +++++++++++++++++++++++++++ gui/MainWindow.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 2b911b2c..75ebefe4 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -165,6 +165,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi view->setFrameShape(QFrame::NoFrame); view->setModel(proxymodel); + view->setContextMenuPolicy(Qt::CustomContextMenu); + connect(view, SIGNAL(customContextMenuRequested(const QPoint&)), + this, SLOT(showInstanceContextMenu(const QPoint&))); + ui->horizontalLayout->addWidget(view); } // The cat background @@ -311,6 +315,29 @@ MainWindow::~MainWindow() delete drawer; } +void MainWindow::showInstanceContextMenu(const QPoint& pos) +{ + if(!view->indexAt(pos).isValid()) + { + return; + } + + QList actions = ui->instanceToolBar->actions(); + + // HACK: Filthy rename button hack because the instance view is getting rewritten anyway + QAction *actionRename; + actionRename = new QAction(tr("Rename"), this); + actionRename->setToolTip(ui->actionRenameInstance->toolTip()); + + connect(actionRename, SIGNAL(triggered(bool)), SLOT(on_actionRenameInstance_triggered())); + + actions.replace(1, actionRename); + + QMenu myMenu; + myMenu.addActions(actions); + myMenu.exec(view->mapToGlobal(pos)); +} + void MainWindow::repopulateAccountsMenu() { accountMenu->clear(); diff --git a/gui/MainWindow.h b/gui/MainWindow.h index f2315ee6..ca11b380 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -145,6 +145,8 @@ slots: // called when an icon is changed in the icon model. void iconUpdated(QString); + void showInstanceContextMenu(const QPoint&); + public slots: void instanceActivated(QModelIndex);