diff --git a/application/application.pro b/application/application.pro index 6bbb99ea..d0071253 100644 --- a/application/application.pro +++ b/application/application.pro @@ -106,6 +106,8 @@ HEADERS += sources/component_preview_grid_widget.h SOURCES += sources/component_preview_grid_widget.cc HEADERS += sources/component_preview_images_decorator.h SOURCES += sources/component_preview_images_decorator.cc +HEADERS += sources/component_property_widget.h +SOURCES += sources/component_property_widget.cc HEADERS += sources/cut_face_preview.h SOURCES += sources/cut_face_preview.cc HEADERS += sources/dds_file.h diff --git a/application/sources/component_property_widget.cc b/application/sources/component_property_widget.cc new file mode 100644 index 00000000..41a28964 --- /dev/null +++ b/application/sources/component_property_widget.cc @@ -0,0 +1,20 @@ +#include "component_property_widget.h" + +ComponentPropertyWidget::ComponentPropertyWidget(Document *document, QWidget *parent): + QWidget(parent), + m_document(document) +{ + setFixedSize(300, 200); +} + +void ComponentPropertyWidget::setComponentIds(const std::vector &componentIds) +{ + if (m_componentIds == componentIds) + return; + m_componentIds = componentIds; + if (m_componentIds.empty()) { + //hide(); + return; + } + // TODO: +} diff --git a/application/sources/component_property_widget.h b/application/sources/component_property_widget.h new file mode 100644 index 00000000..520a75e9 --- /dev/null +++ b/application/sources/component_property_widget.h @@ -0,0 +1,21 @@ +#ifndef DUST3D_APPLICATION_COMPONENT_PROPERTY_WIDGET_H_ +#define DUST3D_APPLICATION_COMPONENT_PROPERTY_WIDGET_H_ + +#include +#include + +class Document; + +class ComponentPropertyWidget: public QWidget +{ + Q_OBJECT +public: + ComponentPropertyWidget(Document *document, QWidget *parent=nullptr); +public slots: + void setComponentIds(const std::vector &componentIds); +private: + Document *m_document = nullptr; + std::vector m_componentIds; +}; + +#endif diff --git a/application/sources/part_manage_widget.cc b/application/sources/part_manage_widget.cc index 6a189bfc..b17cfdcd 100644 --- a/application/sources/part_manage_widget.cc +++ b/application/sources/part_manage_widget.cc @@ -1,6 +1,9 @@ #include +#include +#include #include "part_manage_widget.h" #include "component_preview_grid_widget.h" +#include "component_property_widget.h" #include "component_list_model.h" #include "theme.h" #include "document.h" @@ -15,21 +18,22 @@ PartManageWidget::PartManageWidget(Document *document, QWidget *parent): setStyleSheet("QPushButton:disabled {border: 0; color: " + Theme::gray.name() + "}"); - auto createButton = [](QChar icon) { + auto createButton = [](QChar icon, const QString &title) { QPushButton *button = new QPushButton(icon); button->setFixedSize(Theme::toolIconSize, Theme::toolIconSize); + button->setToolTip(title); return button; }; - m_levelUpButton = createButton(QChar(fa::levelup)); - m_selectButton = createButton(QChar(fa::checksquareo)); - m_lockButton = createButton(QChar(fa::lock)); - m_unlockButton = createButton(QChar(fa::unlock)); - m_showButton = createButton(QChar(fa::eye)); - m_hideButton = createButton(QChar(fa::eyeslash)); - m_unlinkButton = createButton(QChar(fa::unlink)); - m_linkButton = createButton(QChar(fa::link)); - m_removeButton = createButton(QChar(fa::trash)); + m_levelUpButton = createButton(QChar(fa::levelup), tr("Go level up")); + m_selectButton = createButton(QChar(fa::objectgroup), tr("Select them on canvas")); + m_lockButton = createButton(QChar(fa::lock), tr("Lock them on canvas")); + m_unlockButton = createButton(QChar(fa::unlock), tr("Unlock them on canvas")); + m_showButton = createButton(QChar(fa::eye), tr("Show them on canvas")); + m_hideButton = createButton(QChar(fa::eyeslash), tr("Hide them on canvas")); + m_unlinkButton = createButton(QChar(fa::unlink), tr("Exclude them from result generation")); + m_linkButton = createButton(QChar(fa::link), tr("Include them in result generation")); + m_propertyButton = createButton(QChar(fa::sliders), tr("Configure properties")); toolsLayout->addWidget(m_levelUpButton); toolsLayout->addWidget(m_selectButton); @@ -39,7 +43,7 @@ PartManageWidget::PartManageWidget(Document *document, QWidget *parent): toolsLayout->addWidget(m_unlockButton); toolsLayout->addWidget(m_unlinkButton); toolsLayout->addWidget(m_linkButton); - toolsLayout->addWidget(m_removeButton); + toolsLayout->addWidget(m_propertyButton); toolsLayout->addStretch(); m_componentPreviewGridWidget = new ComponentPreviewGridWidget(document); @@ -49,6 +53,8 @@ PartManageWidget::PartManageWidget(Document *document, QWidget *parent): connect(m_componentPreviewGridWidget, &ComponentPreviewGridWidget::unselectAllOnCanvas, this, &PartManageWidget::unselectAllOnCanvas); connect(m_componentPreviewGridWidget, &ComponentPreviewGridWidget::selectPartOnCanvas, this, &PartManageWidget::selectPartOnCanvas); + //connect(m_componentPreviewGridWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &PartManageWidget::showSelectedComponentProperties); + connect(m_levelUpButton, &QPushButton::clicked, [this]() { const auto &parent = m_document->findComponentParent(this->m_componentPreviewGridWidget->componentListModel()->listingComponentId()); if (nullptr == parent) @@ -89,12 +95,6 @@ PartManageWidget::PartManageWidget(Document *document, QWidget *parent): this->m_document->saveSnapshot(); }); - connect(m_removeButton, &QPushButton::clicked, [this]() { - for (const auto &componentId: this->m_componentPreviewGridWidget->getSelectedComponentIds()) - this->m_document->removeComponent(componentId); - this->m_document->saveSnapshot(); - }); - connect(m_selectButton, &QPushButton::clicked, [this]() { for (const auto &componentId: this->m_componentPreviewGridWidget->getSelectedComponentIds()) { std::vector partIds; @@ -104,6 +104,8 @@ PartManageWidget::PartManageWidget(Document *document, QWidget *parent): } }); + connect(m_propertyButton, &QPushButton::clicked, this, &PartManageWidget::showSelectedComponentProperties); + connect(m_document, &Document::partLockStateChanged, this, &PartManageWidget::updateToolButtons); connect(m_document, &Document::partVisibleStateChanged, this, &PartManageWidget::updateToolButtons); connect(m_document, &Document::partDisableStateChanged, this, &PartManageWidget::updateToolButtons); @@ -119,6 +121,29 @@ PartManageWidget::PartManageWidget(Document *document, QWidget *parent): updateLevelUpButton(); } +void PartManageWidget::showSelectedComponentProperties() +{ + auto componentIds = m_componentPreviewGridWidget->getSelectedComponentIds(); + if (componentIds.empty()) + return; + + auto *propertyWidget = new ComponentPropertyWidget(m_document); + propertyWidget->setComponentIds(componentIds); + + auto menu = std::make_unique(this); + QWidgetAction *widgetAction = new QWidgetAction(menu.get()); + widgetAction->setDefaultWidget(propertyWidget); + menu->addAction(widgetAction); + + auto x = mapToGlobal(QPoint(0, 0)).x(); + if (x <= 0) + x = QCursor::pos().x(); + menu->exec(QPoint( + x - propertyWidget->width(), + QCursor::pos().y() + )); +} + void PartManageWidget::selectComponentByPartId(const dust3d::Uuid &partId) { const auto &part = m_document->findPart(partId); @@ -160,9 +185,9 @@ void PartManageWidget::updateToolButtons() bool enableUnlockButton = false; bool enableUnlinkButton = false; bool enableLinkButton = false; - bool enableRemoveButton = false; + bool enablePropertyButton = false; for (const auto &component: selectedComponents) { - enableRemoveButton = true; + enablePropertyButton = true; enableSelectButton = true; if (component->linkToPartId.isNull()) { continue; @@ -191,5 +216,5 @@ void PartManageWidget::updateToolButtons() m_unlockButton->setEnabled(enableUnlockButton); m_unlinkButton->setEnabled(enableUnlinkButton); m_linkButton->setEnabled(enableLinkButton); - m_removeButton->setEnabled(enableRemoveButton); + m_propertyButton->setEnabled(enablePropertyButton); } diff --git a/application/sources/part_manage_widget.h b/application/sources/part_manage_widget.h index d8e08d76..073f9d2a 100644 --- a/application/sources/part_manage_widget.h +++ b/application/sources/part_manage_widget.h @@ -6,9 +6,10 @@ class Document; class ComponentPreviewGridWidget; +class ComponentPropertyWidget; class QPushButton; -class PartManageWidget : public QWidget +class PartManageWidget: public QWidget { Q_OBJECT signals: @@ -16,6 +17,7 @@ signals: void selectPartOnCanvas(const dust3d::Uuid &partId); public slots: void selectComponentByPartId(const dust3d::Uuid &partId); + void showSelectedComponentProperties(); public: PartManageWidget(Document *document, QWidget *parent=nullptr); private: @@ -29,7 +31,7 @@ private: QPushButton *m_hideButton = nullptr; QPushButton *m_unlinkButton = nullptr; QPushButton *m_linkButton = nullptr; - QPushButton *m_removeButton = nullptr; + QPushButton *m_propertyButton = nullptr; void updateToolButtons(); void updateLevelUpButton(); };