diff options
author | Miodrag Milanovic <mmicko@gmail.com> | 2018-06-12 21:29:37 +0200 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2018-06-12 21:29:37 +0200 |
commit | 65bc2d3f3906791e6fc94e8548a556b0c9f03141 (patch) | |
tree | bda63a3359be658cd184ecf95e954961f329b2e8 | |
parent | 7b1c599947f18267dd50ad62812e9a932403fd4d (diff) | |
download | nextpnr-65bc2d3f3906791e6fc94e8548a556b0c9f03141.tar.gz nextpnr-65bc2d3f3906791e6fc94e8548a556b0c9f03141.tar.bz2 nextpnr-65bc2d3f3906791e6fc94e8548a556b0c9f03141.zip |
context menu and cleanup
-rw-r--r-- | gui/mainwindow.cc | 45 | ||||
-rw-r--r-- | gui/mainwindow.h | 8 |
2 files changed, 43 insertions, 10 deletions
diff --git a/gui/mainwindow.cc b/gui/mainwindow.cc index 3c5b74de..5f62ecec 100644 --- a/gui/mainwindow.cc +++ b/gui/mainwindow.cc @@ -4,9 +4,6 @@ #include <string> #include "emb.h" #include "pybindings.h" -#include "qtpropertymanager.h" -#include "qttreepropertybrowser.h" -#include "qtvariantproperty.h" #include "ui_mainwindow.h" #include <QDate> @@ -18,6 +15,9 @@ MainWindow::MainWindow(Design *_design, QWidget *parent) ui->setupUi(this); ui->treeWidget->setColumnCount(1); ui->treeWidget->setHeaderLabel(QString("Items")); + ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this, + &MainWindow::prepareMenu); QTreeWidgetItem *bel_root = new QTreeWidgetItem(ui->treeWidget); bel_root->setText(0, QString("Bels")); @@ -62,7 +62,8 @@ MainWindow::MainWindow(Design *_design, QWidget *parent) emb::set_stdout(write); std::string title = "nextpnr-ice40 - " + design->chip.getChipName(); setWindowTitle(title.c_str()); - QtVariantPropertyManager *variantManager = new QtVariantPropertyManager(); + + variantManager = new QtVariantPropertyManager(); int i = 0; QtProperty *topItem = variantManager->addProperty( @@ -221,9 +222,9 @@ MainWindow::MainWindow(Design *_design, QWidget *parent) QString::number(i++) + QLatin1String(" Color Property")); topItem->addSubProperty(item); - QtVariantEditorFactory *variantFactory = new QtVariantEditorFactory(); + variantFactory = new QtVariantEditorFactory(); - QtTreePropertyBrowser *variantEditor = new QtTreePropertyBrowser(); + variantEditor = new QtTreePropertyBrowser(); variantEditor->setFactoryForManager(variantManager, variantFactory); variantEditor->addProperty(topItem); variantEditor->setPropertiesWithoutValueMarked(true); @@ -234,13 +235,37 @@ MainWindow::MainWindow(Design *_design, QWidget *parent) MainWindow::~MainWindow() { - - // delete variantManager; - // delete variantFactory; - // delete variantEditor; + delete variantManager; + delete variantFactory; + delete variantEditor; delete ui; } +void MainWindow::prepareMenu(const QPoint &pos) +{ + QTreeWidget *tree = ui->treeWidget; + + QTreeWidgetItem *item = tree->itemAt(pos); + + QAction *selectAction = new QAction("&Select", this); + selectAction->setStatusTip("Select item on view"); + connect(selectAction, SIGNAL(triggered()), this, SLOT(selectObject(item))); + + QMenu menu(this); + menu.addAction(selectAction); + + QPoint pt(pos); + menu.exec(tree->mapToGlobal(pos)); +} + +void MainWindow::selectObject(QTreeWidgetItem *item) +{ + ui->plainTextEdit->moveCursor(QTextCursor::End); + ui->plainTextEdit->insertPlainText( + std::string("selected " + item->text(0).toStdString() + "\n").c_str()); + ui->plainTextEdit->moveCursor(QTextCursor::End); +} + void handle_system_exit() { exit(-1); } int MainWindow::executePython(std::string command) diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 6f3e515f..27918486 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -3,6 +3,9 @@ #include "emb.h" #include "nextpnr.h" +#include "qtpropertymanager.h" +#include "qttreepropertybrowser.h" +#include "qtvariantproperty.h" #include <QMainWindow> @@ -27,11 +30,16 @@ class MainWindow : public QMainWindow private Q_SLOTS: void on_lineEdit_returnPressed(); + void prepareMenu(const QPoint &pos); + void selectObject(QTreeWidgetItem *item); private: Ui::MainWindow *ui; emb::stdout_write_type write; Design *design; + QtVariantPropertyManager *variantManager; + QtVariantEditorFactory *variantFactory; + QtTreePropertyBrowser *variantEditor; }; #endif // MAINWINDOW_H |