diff options
author | Miodrag Milanovic <mmicko@gmail.com> | 2018-08-22 18:37:24 +0200 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2018-08-22 18:37:24 +0200 |
commit | 28e30b2af09a16cc3d58ff8ecd0c742b9be8cf5f (patch) | |
tree | 0a23c90bfbe9ebd636163a4214256dc4cf305d2c | |
parent | ad84df7974a82d657938a226da2ceace150cc068 (diff) | |
download | nextpnr-28e30b2af09a16cc3d58ff8ecd0c742b9be8cf5f.tar.gz nextpnr-28e30b2af09a16cc3d58ff8ecd0c742b9be8cf5f.tar.bz2 nextpnr-28e30b2af09a16cc3d58ff8ecd0c742b9be8cf5f.zip |
Added hover on properties as well, fixes #64
-rw-r--r-- | 3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp | 28 | ||||
-rw-r--r-- | 3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.h | 5 | ||||
-rw-r--r-- | gui/designwidget.cc | 20 | ||||
-rw-r--r-- | gui/designwidget.h | 1 |
4 files changed, 52 insertions, 2 deletions
diff --git a/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp b/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp index 523856eb..bdca7dd5 100644 --- a/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp +++ b/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp @@ -82,6 +82,7 @@ public: void slotCollapsed(const QModelIndex &index); void slotExpanded(const QModelIndex &index); + void onHoverPropertyChanged(QtBrowserItem *item); QColor calculatedBackgroundColor(QtBrowserItem *item) const; @@ -129,12 +130,17 @@ public: { return itemFromIndex(index); } protected: + void mouseMoveEvent(QMouseEvent *event) override; + void leaveEvent(QEvent *event) override; void keyPressEvent(QKeyEvent *event); void mousePressEvent(QMouseEvent *event); void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; +Q_SIGNALS: + void hoverPropertyChanged(QtBrowserItem *item); private: QtTreePropertyBrowserPrivate *m_editorPrivate; + QModelIndex current; }; QtPropertyEditorView::QtPropertyEditorView(QWidget *parent) : @@ -172,6 +178,21 @@ void QtPropertyEditorView::drawRow(QPainter *painter, const QStyleOptionViewItem painter->restore(); } +void QtPropertyEditorView::mouseMoveEvent(QMouseEvent *event) +{ + QModelIndex index = indexAt(event->pos()); + if (index!=current) { + current = index; + Q_EMIT hoverPropertyChanged(m_editorPrivate->indexToBrowserItem(index)); + } + QTreeWidget::mouseMoveEvent(event); +} + +void QtPropertyEditorView::leaveEvent(QEvent *event) +{ + Q_EMIT hoverPropertyChanged(nullptr); +} + void QtPropertyEditorView::keyPressEvent(QKeyEvent *event) { switch (event->key()) { @@ -489,6 +510,7 @@ void QtTreePropertyBrowserPrivate::init(QWidget *parent) QObject::connect(m_treeWidget, SIGNAL(collapsed(const QModelIndex &)), q_ptr, SLOT(slotCollapsed(const QModelIndex &))); QObject::connect(m_treeWidget, SIGNAL(expanded(const QModelIndex &)), q_ptr, SLOT(slotExpanded(const QModelIndex &))); QObject::connect(m_treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), q_ptr, SLOT(slotCurrentTreeItemChanged(QTreeWidgetItem*,QTreeWidgetItem*))); + QObject::connect(m_treeWidget, SIGNAL(hoverPropertyChanged(QtBrowserItem *)), q_ptr, SLOT(onHoverPropertyChanged(QtBrowserItem *))); } QtBrowserItem *QtTreePropertyBrowserPrivate::currentItem() const @@ -688,6 +710,12 @@ void QtTreePropertyBrowserPrivate::slotExpanded(const QModelIndex &index) emit q_ptr->expanded(idx); } +void QtTreePropertyBrowserPrivate::onHoverPropertyChanged(QtBrowserItem *item) +{ + emit q_ptr->hoverPropertyChanged(item); +} + + void QtTreePropertyBrowserPrivate::slotCurrentBrowserItemChanged(QtBrowserItem *item) { if (!m_browserChangedBlocked && item != currentItem()) diff --git a/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.h b/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.h index 7bc96b69..194ce627 100644 --- a/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.h +++ b/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.h @@ -115,7 +115,7 @@ Q_SIGNALS: void collapsed(QtBrowserItem *item); void expanded(QtBrowserItem *item); - + void hoverPropertyChanged(QtBrowserItem *item); protected: virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem); virtual void itemRemoved(QtBrowserItem *item); @@ -130,7 +130,8 @@ private: Q_PRIVATE_SLOT(d_func(), void slotCollapsed(const QModelIndex &)) Q_PRIVATE_SLOT(d_func(), void slotExpanded(const QModelIndex &)) Q_PRIVATE_SLOT(d_func(), void slotCurrentBrowserItemChanged(QtBrowserItem *)) - Q_PRIVATE_SLOT(d_func(), void slotCurrentTreeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)) + Q_PRIVATE_SLOT(d_func(), void slotCurrentTreeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)) + Q_PRIVATE_SLOT(d_func(), void onHoverPropertyChanged(QtBrowserItem *)) }; diff --git a/gui/designwidget.cc b/gui/designwidget.cc index bd1c6c5a..c49df085 100644 --- a/gui/designwidget.cc +++ b/gui/designwidget.cc @@ -69,6 +69,7 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), sel propertyEditor->show();
propertyEditor->treeWidget()->setContextMenuPolicy(Qt::CustomContextMenu);
propertyEditor->treeWidget()->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ propertyEditor->treeWidget()->viewport()->setMouseTracking(true);
searchEdit = new QLineEdit();
searchEdit->setClearButtonEnabled(true);
@@ -177,6 +178,7 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), sel connect(propertyEditor->treeWidget(), &QTreeWidget::customContextMenuRequested, this,
&DesignWidget::prepareMenuProperty);
connect(propertyEditor->treeWidget(), &QTreeWidget::itemDoubleClicked, this, &DesignWidget::onItemDoubleClicked);
+ connect(propertyEditor, &QtTreePropertyBrowser::hoverPropertyChanged, this, &DesignWidget::onHoverPropertyChanged);
connect(treeView, &TreeView::customContextMenuRequested, this, &DesignWidget::prepareMenuTree);
connect(treeView, &TreeView::doubleClicked, this, &DesignWidget::onDoubleClicked);
@@ -832,4 +834,22 @@ void DesignWidget::onHoverIndexChanged(QModelIndex index) Q_EMIT hover(DecalXY());
}
+void DesignWidget::onHoverPropertyChanged(QtBrowserItem *item)
+{
+ if (item!=nullptr) {
+ QtProperty *selectedProperty = item->property();
+ ElementType type = getElementTypeByName(selectedProperty->propertyId());
+ if (type != ElementType::NONE) {
+ IdString value = ctx->id(selectedProperty->valueText().toStdString());
+ if (value!=IdString()) {
+ auto node = treeModel->nodeForIdType(type, value);
+ if (node) {
+ Q_EMIT hover(getDecals((*node)->type(), (*node)->id()).at(0));
+ return;
+ }
+ }
+ }
+ }
+ Q_EMIT hover(DecalXY());
+}
NEXTPNR_NAMESPACE_END
diff --git a/gui/designwidget.h b/gui/designwidget.h index 37791aa1..91da556a 100644 --- a/gui/designwidget.h +++ b/gui/designwidget.h @@ -83,6 +83,7 @@ class DesignWidget : public QWidget void onDoubleClicked(const QModelIndex &index);
void onSearchInserted();
void onHoverIndexChanged(QModelIndex index);
+ void onHoverPropertyChanged(QtBrowserItem *item);
public Q_SLOTS:
void newContext(Context *ctx);
void updateTree();
|