|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QWidgetAction>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#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<dust3d::Uuid> 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<QMenu>(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);
|
|
|
|
|
}
|
|
|
|
|