diff options
-rw-r--r-- | 3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp | 11 | ||||
-rw-r--r-- | 3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.h | 4 | ||||
-rw-r--r-- | gui/basewindow.cc | 11 | ||||
-rw-r--r-- | gui/designwidget.cc | 58 | ||||
-rw-r--r-- | gui/designwidget.h | 6 | ||||
-rw-r--r-- | gui/fpgaviewwidget.cc | 6 | ||||
-rw-r--r-- | gui/fpgaviewwidget.h | 1 |
7 files changed, 69 insertions, 28 deletions
diff --git a/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp b/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp index a92ab537..673252d2 100644 --- a/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp +++ b/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp @@ -74,6 +74,7 @@ public: QtProperty *indexToProperty(const QModelIndex &index) const; QTreeWidgetItem *indexToItem(const QModelIndex &index) const; QtBrowserItem *indexToBrowserItem(const QModelIndex &index) const; + QtBrowserItem *itemToBrowserItem(QTreeWidgetItem *item) const { return m_itemToIndex.value(item); }; bool lastColumn(int column) const; void disableItem(QTreeWidgetItem *item) const; void enableItem(QTreeWidgetItem *item) const; @@ -1068,6 +1069,16 @@ void QtTreePropertyBrowser::editItem(QtBrowserItem *item) d_ptr->editItem(item); } +QTreeWidget *QtTreePropertyBrowser::treeWidget() const +{ + return d_ptr->treeWidget(); +} + +QtBrowserItem *QtTreePropertyBrowser::itemToBrowserItem(QTreeWidgetItem *item) +{ + return d_ptr->itemToBrowserItem(item); +} + #if QT_VERSION >= 0x040400 QT_END_NAMESPACE #endif diff --git a/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.h b/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.h index c5f7fa88..7bc96b69 100644 --- a/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.h +++ b/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.h @@ -47,6 +47,7 @@ QT_BEGIN_NAMESPACE #endif +class QTreeWidget; class QTreeWidgetItem; class QtTreePropertyBrowserPrivate; @@ -107,6 +108,9 @@ public: void editItem(QtBrowserItem *item); + //ADDED:miodrag + QTreeWidget *treeWidget() const; + QtBrowserItem *itemToBrowserItem(QTreeWidgetItem *item); Q_SIGNALS: void collapsed(QtBrowserItem *item); diff --git a/gui/basewindow.cc b/gui/basewindow.cc index 0c7632ee..a57d3ef1 100644 --- a/gui/basewindow.cc +++ b/gui/basewindow.cc @@ -81,7 +81,8 @@ BaseMainWindow::BaseMainWindow(std::unique_ptr<Context> context, QWidget *parent centralTabWidget->addTab(fpgaView, "Graphics");
connect(this, SIGNAL(contextChanged(Context *)), fpgaView, SLOT(newContext(Context *)));
- connect(designview, SIGNAL(selected(std::vector<DecalXY>)), fpgaView, SLOT(onSelectedArchItem(std::vector<DecalXY>)));
+ connect(designview, SIGNAL(selected(std::vector<DecalXY>)), fpgaView,
+ SLOT(onSelectedArchItem(std::vector<DecalXY>)));
splitter_v->addWidget(centralTabWidget);
splitter_v->addWidget(tabWidget);
@@ -93,26 +94,26 @@ void BaseMainWindow::writeInfo(std::string text) { console->info(text); } void BaseMainWindow::createMenusAndBars()
{
- actionNew = new QAction("New", this);
+ actionNew = new QAction("New", this);
actionNew->setIcon(QIcon(":/icons/resources/new.png"));
actionNew->setShortcuts(QKeySequence::New);
actionNew->setStatusTip("New project file");
connect(actionNew, SIGNAL(triggered()), this, SLOT(new_proj()));
- actionOpen = new QAction("Open", this);
+ actionOpen = new QAction("Open", this);
actionOpen->setIcon(QIcon(":/icons/resources/open.png"));
actionOpen->setShortcuts(QKeySequence::Open);
actionOpen->setStatusTip("Open an existing project file");
connect(actionOpen, SIGNAL(triggered()), this, SLOT(open_proj()));
- QAction *actionSave = new QAction("Save", this);
+ QAction *actionSave = new QAction("Save", this);
actionSave->setIcon(QIcon(":/icons/resources/save.png"));
actionSave->setShortcuts(QKeySequence::Save);
actionSave->setStatusTip("Save existing project to disk");
actionSave->setEnabled(false);
connect(actionSave, SIGNAL(triggered()), this, SLOT(save_proj()));
- QAction *actionExit = new QAction("Exit", this);
+ QAction *actionExit = new QAction("Exit", this);
actionExit->setIcon(QIcon(":/icons/resources/exit.png"));
actionExit->setShortcuts(QKeySequence::Quit);
actionExit->setStatusTip("Exit the application");
diff --git a/gui/designwidget.cc b/gui/designwidget.cc index 553171ab..cfcdc9fc 100644 --- a/gui/designwidget.cc +++ b/gui/designwidget.cc @@ -77,9 +77,8 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net propertyEditor = new QtTreePropertyBrowser(this);
propertyEditor->setFactoryForManager(variantManager, variantFactory);
propertyEditor->setPropertiesWithoutValueMarked(true);
- connect(propertyEditor, SIGNAL(currentItemChanged(QtBrowserItem *)), this,
- SLOT(onCurrentPropertyChanged(QtBrowserItem *)));
propertyEditor->show();
+ propertyEditor->treeWidget()->setContextMenuPolicy(Qt::CustomContextMenu);
QLineEdit *lineEdit = new QLineEdit();
lineEdit->setClearButtonEnabled(true);
@@ -144,7 +143,9 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net setLayout(mainLayout);
// Connection
- connect(treeWidget, &QTreeWidget::customContextMenuRequested, this, &DesignWidget::prepareMenu);
+ connect(propertyEditor->treeWidget(), &QTreeWidget::customContextMenuRequested, this,
+ &DesignWidget::prepareMenuProperty);
+ connect(propertyEditor->treeWidget(), &QTreeWidget::itemDoubleClicked, this, &DesignWidget::onItemDoubleClicked);
connect(treeWidget, SIGNAL(itemSelectionChanged()), SLOT(onItemSelectionChanged()));
}
@@ -312,33 +313,41 @@ void DesignWidget::clearProperties() idToProperty.clear();
}
-void DesignWidget::onCurrentPropertyChanged(QtBrowserItem *_item)
+void DesignWidget::onCurrentPropertySelected(QtBrowserItem *_item)
{
if (_item) {
QtProperty *selectedProperty = _item->property();
- QString type = selectedProperty->propertyId();
+ ElementType type = getElementTypeByName(selectedProperty->propertyId());
IdString value = ctx->id(selectedProperty->valueText().toStdString());
std::vector<DecalXY> decals;
- if (type == "BEL") {
+ switch (type) {
+ case ElementType::BEL: {
BelId bel = ctx->getBelByName(value);
if (bel != BelId()) {
decals.push_back(ctx->getBelDecal(bel));
Q_EMIT selected(decals);
}
- } else if (type == "WIRE") {
+ } break;
+ case ElementType::WIRE: {
WireId wire = ctx->getWireByName(value);
if (wire != WireId()) {
decals.push_back(ctx->getWireDecal(wire));
Q_EMIT selected(decals);
}
- } else if (type == "PIP") {
+ } break;
+ case ElementType::PIP: {
PipId pip = ctx->getPipByName(value);
if (pip != PipId()) {
decals.push_back(ctx->getPipDecal(pip));
Q_EMIT selected(decals);
}
- } else if (type == "NET") {
- } else if (type == "CELL") {
+ } break;
+ case ElementType::NET: {
+ } break;
+ case ElementType::CELL: {
+ } break;
+ default:
+ break;
}
}
}
@@ -596,23 +605,38 @@ void DesignWidget::onItemSelectionChanged() }
}
-void DesignWidget::prepareMenu(const QPoint &pos)
+void DesignWidget::prepareMenuProperty(const QPoint &pos)
{
- QTreeWidget *tree = treeWidget;
+ QTreeWidget *tree = propertyEditor->treeWidget();
itemContextMenu = tree->itemAt(pos);
+ if (itemContextMenu->parent() == nullptr)
+ return;
- QAction *selectAction = new QAction("&Select", this);
- selectAction->setStatusTip("Select item on view");
-
- connect(selectAction, SIGNAL(triggered()), this, SLOT(selectObject()));
+ QtBrowserItem *browserItem = propertyEditor->itemToBrowserItem(itemContextMenu);
+ // if (((ElementTreeItem*)itemContextMenu)->getType() == ElementType::NONE) return;
QMenu menu(this);
+ QAction *selectAction = new QAction("&Select", this);
+ connect(selectAction, &QAction::triggered, this, [this, browserItem] { onCurrentPropertySelected(browserItem); });
+
menu.addAction(selectAction);
menu.exec(tree->mapToGlobal(pos));
}
-void DesignWidget::selectObject() { Q_EMIT info("selected " + itemContextMenu->text(0).toStdString() + "\n"); }
+void DesignWidget::onItemDoubleClicked(QTreeWidgetItem *item, int column)
+{
+ QtProperty *selectedProperty = propertyEditor->itemToBrowserItem(item)->property();
+ ElementType type = getElementTypeByName(selectedProperty->propertyId());
+ IdString value = ctx->id(selectedProperty->valueText().toStdString());
+ switch (type) {
+ case ElementType::NONE:
+ return;
+ default:
+ Q_EMIT info("double clicked " + std::string(value.c_str(ctx)) + "\n");
+ break;
+ }
+}
NEXTPNR_NAMESPACE_END
diff --git a/gui/designwidget.h b/gui/designwidget.h index a4940213..50f00bbe 100644 --- a/gui/designwidget.h +++ b/gui/designwidget.h @@ -61,10 +61,10 @@ class DesignWidget : public QWidget void selected(std::vector<DecalXY> decal);
private Q_SLOTS:
- void prepareMenu(const QPoint &pos);
+ void prepareMenuProperty(const QPoint &pos);
void onItemSelectionChanged();
- void selectObject();
- void onCurrentPropertyChanged(QtBrowserItem *_item);
+ void onItemDoubleClicked(QTreeWidgetItem *item, int column);
+ void onCurrentPropertySelected(QtBrowserItem *_item);
public Q_SLOTS:
void newContext(Context *ctx);
void updateTree();
diff --git a/gui/fpgaviewwidget.cc b/gui/fpgaviewwidget.cc index ad62d38f..cb60bc76 100644 --- a/gui/fpgaviewwidget.cc +++ b/gui/fpgaviewwidget.cc @@ -240,7 +240,8 @@ void LineShader::draw(const LineShaderData &line, const QColor &color, float thi vao_.release(); } -FPGAViewWidget::FPGAViewWidget(QWidget *parent) : QOpenGLWidget(parent), lineShader_(this), zoom_(500.f), ctx_(nullptr), selectedItemsChanged(false) +FPGAViewWidget::FPGAViewWidget(QWidget *parent) + : QOpenGLWidget(parent), lineShader_(this), zoom_(500.f), ctx_(nullptr), selectedItemsChanged(false) { backgroundColor_ = QColor("#000000"); gridColor_ = QColor("#333"); @@ -412,8 +413,7 @@ void FPGAViewWidget::paintGL() drawDecal(shaders, ctx_->getGroupDecal(group)); } - if (selectedItemsChanged) - { + if (selectedItemsChanged) { selectedItemsChanged = false; selectedShader_.clear(); for (auto decal : selectedItems_) { diff --git a/gui/fpgaviewwidget.h b/gui/fpgaviewwidget.h index dd86277e..ea4a17cf 100644 --- a/gui/fpgaviewwidget.h +++ b/gui/fpgaviewwidget.h @@ -245,6 +245,7 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions public Q_SLOTS: void newContext(Context *ctx); void onSelectedArchItem(std::vector<DecalXY> decals); + private: QPoint lastPos_; LineShader lineShader_; |