xwhatsit util gui: added context menu to main window too
authorPurdea Andrei <andrei@purdea.ro>
Sun, 31 May 2020 21:03:15 +0000 (00:03 +0300)
committerPurdea Andrei <andrei@purdea.ro>
Sun, 31 May 2020 21:03:15 +0000 (00:03 +0300)
keyboards/xwhatsit/util/util/mainwindow.cpp
keyboards/xwhatsit/util/util/mainwindow.h

index 55e86bd..356dd73 100644 (file)
@@ -5,6 +5,8 @@
 #include <string>
 #include <QMessageBox>
 #include <QMetaType>
+#include <QMenu>
+#include <QAction>
 
 Q_DECLARE_METATYPE(std::vector<std::string>)
 Q_DECLARE_METATYPE(std::string)
@@ -27,10 +29,22 @@ MainWindow::MainWindow(Communication &comm, QWidget *parent) :
     connect(&thread, &HidThread::scannedDevices, this, &MainWindow::on_updateScannedDevices);
     connect(&thread, &HidThread::reportError, this, &MainWindow::on_reportError);
     connect(&thread, &HidThread::reportInfo, this, &MainWindow::on_reportInfo);
+    this->setContextMenuPolicy(Qt::CustomContextMenu);
+    connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
+            this, SLOT(ShowContextMenu(const QPoint &)));
     thread.start();
     thread.setScanning(true);
 }
 
+void MainWindow::ShowContextMenu(const QPoint &pos)
+{
+    QMenu contextMenu(tr("Context menu"), this);
+    QAction action1("Close", this);
+    connect(&action1, SIGNAL(triggered()), this, SLOT(close()));
+    contextMenu.addAction(&action1);
+    contextMenu.exec(mapToGlobal(pos));
+}
+
 void MainWindow::on_updateScannedDevices(std::vector<std::string> devices)
 {
     int i;
index 4f877d1..e2a318c 100644 (file)
@@ -33,6 +33,7 @@ private slots:
     void on_eraseEepromPushButton_clicked();
 
     void on_signalLevelPushButton_clicked();
+    void ShowContextMenu(const QPoint &pos);
 
 private:
     Ui::MainWindow *ui;