From 10de5a19d0db5521f6f306cb2c0ecff24fb85dbb Mon Sep 17 00:00:00 2001 From: Paddle Date: Wed, 17 Jan 2024 17:00:55 +0100 Subject: [PATCH] Core : Tree: Add 'Properties' action in contextual menu. Opens a property dialog. --- src/Gui/PropertyView.cpp | 6 ++--- src/Gui/PropertyView.h | 2 +- src/Gui/Tree.cpp | 27 +++++++++++++++++++++++ src/Gui/Tree.h | 2 ++ src/Gui/propertyeditor/PropertyEditor.cpp | 6 ++++- src/Gui/propertyeditor/PropertyEditor.h | 2 +- 6 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/Gui/PropertyView.cpp b/src/Gui/PropertyView.cpp index 535f54fa2c..fb0dda47d1 100644 --- a/src/Gui/PropertyView.cpp +++ b/src/Gui/PropertyView.cpp @@ -67,7 +67,7 @@ static ParameterGrp::handle _GetParam() { * Provides two Gui::PropertyEditor::PropertyEditor widgets, for "View" and "Data", * in two tabs. */ -PropertyView::PropertyView(QWidget *parent) +PropertyView::PropertyView(QWidget *parent, int sizeOfFirstColumn) : QWidget(parent), SelectionObserver(false, ResolveMode::NoResolve) { auto pLayout = new QGridLayout( this ); @@ -83,12 +83,12 @@ PropertyView::PropertyView(QWidget *parent) tabs->setTabPosition(QTabWidget::South); pLayout->addWidget(tabs, 0, 0); - propertyEditorView = new Gui::PropertyEditor::PropertyEditor(); + propertyEditorView = new Gui::PropertyEditor::PropertyEditor(parent, sizeOfFirstColumn); propertyEditorView->setAutomaticDocumentUpdate(_GetParam()->GetBool("AutoTransactionView", false)); propertyEditorView->setAutomaticExpand(_GetParam()->GetBool("AutoExpandView", false)); tabs->addTab(propertyEditorView, tr("View")); - propertyEditorData = new Gui::PropertyEditor::PropertyEditor(); + propertyEditorData = new Gui::PropertyEditor::PropertyEditor(parent, sizeOfFirstColumn); propertyEditorData->setAutomaticDocumentUpdate(_GetParam()->GetBool("AutoTransactionData", true)); propertyEditorData->setAutomaticExpand(_GetParam()->GetBool("AutoExpandData", false)); tabs->addTab(propertyEditorData, tr("Data")); diff --git a/src/Gui/PropertyView.h b/src/Gui/PropertyView.h index a058fcd04e..cf539df318 100644 --- a/src/Gui/PropertyView.h +++ b/src/Gui/PropertyView.h @@ -56,7 +56,7 @@ class PropertyView : public QWidget, public Gui::SelectionObserver Q_OBJECT public: - explicit PropertyView(QWidget *parent=nullptr); + explicit PropertyView(QWidget *parent=nullptr, int sizeOfFirstColumn = 0); ~PropertyView() override; Gui::PropertyEditor::PropertyEditor* propertyEditorView; diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 4a657680d4..3b2cc0717c 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -61,6 +61,7 @@ #include "Macro.h" #include "MainWindow.h" #include "MenuManager.h" +#include "PropertyView.h" #include "TreeParams.h" #include "View3DInventor.h" #include "ViewProviderDocumentObject.h" @@ -523,6 +524,13 @@ TreeWidget::TreeWidget(const char* name, QWidget* parent) connect(this->relabelObjectAction, &QAction::triggered, this, &TreeWidget::onRelabelObject); + this->objectPropertyAction = new QAction(this); +#ifndef Q_OS_MAC + this->objectPropertyAction->setShortcut(Qt::Key_F6); +#endif + connect(this->objectPropertyAction, &QAction::triggered, + this, &TreeWidget::onObjectProperty); + this->finishEditingAction = new QAction(this); connect(this->finishEditingAction, &QAction::triggered, this, &TreeWidget::onFinishEditing); @@ -961,6 +969,7 @@ void TreeWidget::contextMenuEvent(QContextMenuEvent* e) // relabeling is only possible for a single selected document if (SelectedObjectsList.size() == 1) contextMenu.addAction(this->relabelObjectAction); + contextMenu.addAction(this->objectPropertyAction); auto selItems = this->selectedItems(); // if only one item is selected, setup the edit menu @@ -1082,6 +1091,21 @@ void TreeWidget::onRelabelObject() editItem(item); } +void TreeWidget::onObjectProperty() +{ + int sizeOfFirstColumn = 200; + auto prop = new PropertyView(this, sizeOfFirstColumn); + QDialog* propertyDialog = new QDialog(this); + propertyDialog->setWindowTitle(QString::fromLatin1("Properties")); + propertyDialog->resize(700, 500); + QVBoxLayout* layout = new QVBoxLayout(propertyDialog); + layout->addWidget(prop); + propertyDialog->setLayout(layout); + QPoint cursorPos = QCursor::pos() - QPoint(0, 300); + propertyDialog->move(cursorPos); + propertyDialog->show(); +} + void TreeWidget::onStartEditing() { auto action = qobject_cast(sender()); @@ -2965,6 +2989,9 @@ void TreeWidget::setupText() this->relabelObjectAction->setText(tr("Rename")); this->relabelObjectAction->setStatusTip(tr("Rename object")); + this->objectPropertyAction->setText(tr("Properties")); + this->objectPropertyAction->setStatusTip(tr("Properties of the selected object")); + this->finishEditingAction->setText(tr("Finish editing")); this->finishEditingAction->setStatusTip(tr("Finish editing object")); diff --git a/src/Gui/Tree.h b/src/Gui/Tree.h index 6d35edfec2..877cddf664 100644 --- a/src/Gui/Tree.h +++ b/src/Gui/Tree.h @@ -154,6 +154,7 @@ protected: protected Q_SLOTS: void onCreateGroup(); void onRelabelObject(); + void onObjectProperty(); void onActivateDocument(QAction*); void onStartEditing(); void onFinishEditing(); @@ -208,6 +209,7 @@ private: private: QAction* createGroupAction; QAction* relabelObjectAction; + QAction* objectPropertyAction; QAction* finishEditingAction; QAction* selectDependentsAction; QAction* skipRecomputeAction; diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index b0b0e3489b..184d0420dd 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -51,7 +51,7 @@ FC_LOG_LEVEL_INIT("PropertyView", true, true) using namespace Gui::PropertyEditor; -PropertyEditor::PropertyEditor(QWidget *parent) +PropertyEditor::PropertyEditor(QWidget *parent, int sizeOfFirstColumn) : QTreeView(parent) , autoexpand(false) , autoupdate(false) @@ -99,6 +99,10 @@ PropertyEditor::PropertyEditor(QWidget *parent) setHeaderHidden(true); viewport()->installEventFilter(this); viewport()->setMouseTracking(true); + + if (sizeOfFirstColumn != 0) { + header()->resizeSection(0, sizeOfFirstColumn); + } } PropertyEditor::~PropertyEditor() diff --git a/src/Gui/propertyeditor/PropertyEditor.h b/src/Gui/propertyeditor/PropertyEditor.h index bd01c2f99e..5c5342d129 100644 --- a/src/Gui/propertyeditor/PropertyEditor.h +++ b/src/Gui/propertyeditor/PropertyEditor.h @@ -67,7 +67,7 @@ class PropertyEditor : public QTreeView Q_PROPERTY(QBrush itemBackground READ itemBackground WRITE setItemBackground DESIGNABLE true SCRIPTABLE true) // clazy:exclude=qproperty-without-notify public: - PropertyEditor(QWidget *parent = nullptr); + PropertyEditor(QWidget *parent = nullptr, int sizeOfFirstColumn = 0); ~PropertyEditor() override; /** Builds up the list view with the properties. */