2018-08-27 08:50:40 +00:00
|
|
|
#include <QMenu>
|
|
|
|
#include <vector>
|
2018-09-06 15:04:59 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QWidgetAction>
|
2018-09-07 10:13:55 +00:00
|
|
|
#include <QRadialGradient>
|
|
|
|
#include <QBrush>
|
|
|
|
#include <QGuiApplication>
|
2018-10-25 00:19:38 +00:00
|
|
|
#include "parttreewidget.h"
|
|
|
|
#include "partwidget.h"
|
2018-09-01 00:47:10 +00:00
|
|
|
#include "skeletongraphicswidget.h"
|
2018-09-06 15:04:59 +00:00
|
|
|
#include "floatnumberwidget.h"
|
2018-08-27 08:50:40 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
PartTreeWidget::PartTreeWidget(const Document *document, QWidget *parent) :
|
2018-08-27 08:50:40 +00:00
|
|
|
QTreeWidget(parent),
|
|
|
|
m_document(document)
|
|
|
|
{
|
|
|
|
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
|
|
|
setFocusPolicy(Qt::NoFocus);
|
|
|
|
|
|
|
|
QPalette palette = this->palette();
|
|
|
|
palette.setColor(QPalette::Window, Qt::transparent);
|
|
|
|
palette.setColor(QPalette::Base, Qt::transparent);
|
|
|
|
setPalette(palette);
|
|
|
|
|
|
|
|
setColumnCount(1);
|
|
|
|
setHeaderHidden(true);
|
|
|
|
|
|
|
|
m_componentItemMap[QUuid()] = invisibleRootItem();
|
|
|
|
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
2018-09-06 15:04:59 +00:00
|
|
|
//setIconSize(QSize(Theme::miniIconFontSize, Theme::miniIconFontSize));
|
2018-08-27 08:50:40 +00:00
|
|
|
|
|
|
|
setStyleSheet("QTreeView {qproperty-indentation: 10; margin-left: 5px; margin-top: 5px;}"
|
|
|
|
"QTreeView::branch:has-siblings:!adjoins-item {border-image: url(:/resources/tree-vline.png);}"
|
|
|
|
"QTreeView::branch:has-siblings:adjoins-item {border-image: url(:/resources/tree-branch-more.png);}"
|
|
|
|
"QTreeView::branch:!has-children:!has-siblings:adjoins-item {border-image: url(:/resources/tree-branch-end.png);}"
|
|
|
|
"QTreeView::branch:has-children:!has-siblings:closed, QTreeView::branch:closed:has-children:has-siblings {border-image: none; image: url(:/resources/tree-branch-closed.png);}"
|
|
|
|
"QTreeView::branch:open:has-children:!has-siblings, QTreeView::branch:open:has-children:has-siblings {border-image: none; image: url(:/resources/tree-branch-open.png);}");
|
|
|
|
|
2018-09-06 15:04:59 +00:00
|
|
|
m_normalFont.setWeight(QFont::Light);
|
|
|
|
m_normalFont.setPixelSize(9);
|
|
|
|
m_normalFont.setBold(false);
|
|
|
|
|
|
|
|
m_selectedFont.setWeight(QFont::Light);
|
|
|
|
m_selectedFont.setPixelSize(9);
|
|
|
|
m_selectedFont.setBold(true);
|
|
|
|
|
|
|
|
setFont(m_normalFont);
|
2018-08-27 08:50:40 +00:00
|
|
|
|
2018-10-24 14:08:42 +00:00
|
|
|
QRadialGradient gradient(QPointF(0.2, 0.3), 0.3);
|
2018-09-07 10:13:55 +00:00
|
|
|
QColor fillColor = QColor(0xfb, 0xf9, 0x87);
|
|
|
|
fillColor.setAlphaF(0.85);
|
|
|
|
gradient.setCoordinateMode(QGradient::StretchToDeviceMode);
|
|
|
|
gradient.setColorAt(0, fillColor);
|
|
|
|
gradient.setColorAt(1, Qt::transparent);
|
|
|
|
m_hightlightedPartBackground = QBrush(gradient);
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
connect(this, &QTreeWidget::customContextMenuRequested, this, &PartTreeWidget::showContextMenu);
|
|
|
|
connect(this, &QTreeWidget::itemChanged, this, &PartTreeWidget::groupChanged);
|
|
|
|
connect(this, &QTreeWidget::itemExpanded, this, &PartTreeWidget::groupExpanded);
|
|
|
|
connect(this, &QTreeWidget::itemCollapsed, this, &PartTreeWidget::groupCollapsed);
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::selectComponent(QUuid componentId, bool multiple)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-09-07 10:13:55 +00:00
|
|
|
if (multiple) {
|
|
|
|
if (!m_currentSelectedComponentId.isNull()) {
|
|
|
|
m_selectedComponentIds.insert(m_currentSelectedComponentId);
|
|
|
|
m_currentSelectedComponentId = QUuid();
|
|
|
|
emit currentComponentChanged(m_currentSelectedComponentId);
|
2018-09-06 15:04:59 +00:00
|
|
|
}
|
2018-09-07 10:13:55 +00:00
|
|
|
if (m_selectedComponentIds.find(componentId) != m_selectedComponentIds.end()) {
|
|
|
|
updateComponentSelectState(componentId, false);
|
|
|
|
m_selectedComponentIds.erase(componentId);
|
|
|
|
} else {
|
|
|
|
updateComponentSelectState(componentId, true);
|
|
|
|
m_selectedComponentIds.insert(componentId);
|
|
|
|
}
|
|
|
|
if (m_selectedComponentIds.size() > 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_selectedComponentIds.size() == 1)
|
|
|
|
componentId = *m_selectedComponentIds.begin();
|
|
|
|
else
|
|
|
|
componentId = QUuid();
|
|
|
|
}
|
|
|
|
if (!m_selectedComponentIds.empty()) {
|
|
|
|
for (const auto &id: m_selectedComponentIds) {
|
|
|
|
updateComponentSelectState(id, false);
|
|
|
|
}
|
|
|
|
m_selectedComponentIds.clear();
|
|
|
|
}
|
|
|
|
if (m_currentSelectedComponentId != componentId) {
|
|
|
|
if (!m_currentSelectedComponentId.isNull()) {
|
|
|
|
updateComponentSelectState(m_currentSelectedComponentId, false);
|
|
|
|
}
|
|
|
|
m_currentSelectedComponentId = componentId;
|
|
|
|
if (!m_currentSelectedComponentId.isNull()) {
|
|
|
|
updateComponentSelectState(m_currentSelectedComponentId, true);
|
|
|
|
}
|
|
|
|
emit currentComponentChanged(m_currentSelectedComponentId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::updateComponentSelectState(QUuid componentId, bool selected)
|
2018-09-07 10:13:55 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *component = m_document->findComponent(componentId);
|
2018-09-07 10:13:55 +00:00
|
|
|
if (nullptr == component) {
|
|
|
|
qDebug() << "Component not found:" << componentId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!component->linkToPartId.isNull()) {
|
|
|
|
auto item = m_partItemMap.find(component->linkToPartId);
|
|
|
|
if (item != m_componentItemMap.end()) {
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
2018-09-07 10:13:55 +00:00
|
|
|
widget->updateCheckedState(selected);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto item = m_componentItemMap.find(componentId);
|
|
|
|
if (item != m_componentItemMap.end()) {
|
|
|
|
if (selected) {
|
|
|
|
item->second->setFont(0, m_selectedFont);
|
|
|
|
item->second->setForeground(0, QBrush(Theme::red));
|
|
|
|
} else {
|
|
|
|
item->second->setFont(0, m_normalFont);
|
|
|
|
item->second->setForeground(0, QBrush(Theme::white));
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::mousePressEvent(QMouseEvent *event)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-09-06 15:04:59 +00:00
|
|
|
QModelIndex itemIndex = indexAt(event->pos());
|
|
|
|
QTreeView::mousePressEvent(event);
|
2018-09-07 10:13:55 +00:00
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
bool multiple = QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ControlModifier);
|
|
|
|
if (itemIndex.isValid()) {
|
|
|
|
QTreeWidgetItem *item = itemFromIndex(itemIndex);
|
|
|
|
auto componentId = QUuid(item->data(0, Qt::UserRole).toString());
|
|
|
|
if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
|
|
|
|
if (!m_shiftStartComponentId.isNull()) {
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *parent = m_document->findComponentParent(m_shiftStartComponentId);
|
2018-09-07 10:13:55 +00:00
|
|
|
if (parent) {
|
|
|
|
if (!parent->childrenIds.empty()) {
|
|
|
|
bool startAdd = false;
|
|
|
|
bool stopAdd = false;
|
|
|
|
std::vector<QUuid> waitQueue;
|
|
|
|
for (const auto &childId: parent->childrenIds) {
|
|
|
|
if (m_shiftStartComponentId == childId || componentId == childId) {
|
|
|
|
if (startAdd) {
|
|
|
|
stopAdd = true;
|
|
|
|
} else {
|
|
|
|
startAdd = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (startAdd)
|
|
|
|
waitQueue.push_back(childId);
|
|
|
|
if (stopAdd)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (stopAdd && !waitQueue.empty()) {
|
|
|
|
if (!m_selectedComponentIds.empty()) {
|
|
|
|
for (const auto &id: m_selectedComponentIds) {
|
|
|
|
updateComponentSelectState(id, false);
|
|
|
|
}
|
|
|
|
m_selectedComponentIds.clear();
|
|
|
|
}
|
|
|
|
if (!m_currentSelectedComponentId.isNull()) {
|
|
|
|
m_currentSelectedComponentId = QUuid();
|
|
|
|
emit currentComponentChanged(m_currentSelectedComponentId);
|
|
|
|
}
|
|
|
|
for (const auto &waitId: waitQueue) {
|
|
|
|
selectComponent(waitId, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 15:04:59 +00:00
|
|
|
return;
|
2018-09-07 10:13:55 +00:00
|
|
|
} else {
|
|
|
|
m_shiftStartComponentId = componentId;
|
2018-09-06 15:04:59 +00:00
|
|
|
}
|
2018-09-07 10:13:55 +00:00
|
|
|
selectComponent(componentId, multiple);
|
|
|
|
return;
|
2018-09-06 15:04:59 +00:00
|
|
|
}
|
2018-09-07 10:13:55 +00:00
|
|
|
if (!multiple)
|
|
|
|
selectComponent(QUuid());
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::showContextMenu(const QPoint &pos)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *component = nullptr;
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonPart *part = nullptr;
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *partWidget = nullptr;
|
2018-08-27 08:50:40 +00:00
|
|
|
|
2018-09-07 10:13:55 +00:00
|
|
|
std::set<QUuid> unorderedComponentIds = m_selectedComponentIds;
|
|
|
|
if (!m_currentSelectedComponentId.isNull())
|
|
|
|
unorderedComponentIds.insert(m_currentSelectedComponentId);
|
|
|
|
|
|
|
|
if (unorderedComponentIds.empty()) {
|
|
|
|
QTreeWidgetItem *item = itemAt(pos);
|
|
|
|
if (nullptr != item) {
|
|
|
|
QUuid componentId = QUuid(item->data(0, Qt::UserRole).toString());
|
|
|
|
unorderedComponentIds.insert(componentId);
|
|
|
|
}
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
|
|
|
|
2018-09-07 10:13:55 +00:00
|
|
|
std::vector<QUuid> componentIds;
|
|
|
|
std::vector<QUuid> candidates;
|
|
|
|
m_document->collectComponentDescendantComponents(QUuid(), candidates);
|
|
|
|
for (const auto &cand: candidates) {
|
|
|
|
if (unorderedComponentIds.find(cand) != unorderedComponentIds.end())
|
|
|
|
componentIds.push_back(cand);
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QMenu contextMenu(this);
|
|
|
|
|
2018-09-07 10:13:55 +00:00
|
|
|
if (componentIds.size() == 1) {
|
|
|
|
QUuid componentId = *componentIds.begin();
|
|
|
|
component = m_document->findComponent(componentId);
|
|
|
|
if (nullptr == component) {
|
|
|
|
qDebug() << "Component not found:" << componentId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (component && !component->linkToPartId.isNull()) {
|
|
|
|
part = m_document->findPart(component->linkToPartId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout;
|
2018-09-18 06:22:29 +00:00
|
|
|
QWidgetAction forDisplayPartImage(this);
|
2018-09-07 10:13:55 +00:00
|
|
|
layout->setAlignment(Qt::AlignCenter);
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
layout->setSpacing(0);
|
2018-09-18 06:22:29 +00:00
|
|
|
if (nullptr != part) {
|
|
|
|
auto findItem = m_partItemMap.find(part->id);
|
|
|
|
if (findItem != m_partItemMap.end()) {
|
2018-10-25 00:19:38 +00:00
|
|
|
partWidget = (PartWidget *)itemWidget(findItem->second, 0);
|
2018-09-18 06:22:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nullptr != part && nullptr != partWidget) {
|
|
|
|
ModelWidget *previewWidget = new ModelWidget;
|
|
|
|
previewWidget->enableMove(false);
|
|
|
|
previewWidget->enableZoom(false);
|
2018-09-21 07:10:18 +00:00
|
|
|
previewWidget->setFixedSize(Theme::partPreviewImageSize, Theme::partPreviewImageSize);
|
2018-09-18 06:22:29 +00:00
|
|
|
previewWidget->setXRotation(partWidget->previewWidget()->xRot());
|
|
|
|
previewWidget->setYRotation(partWidget->previewWidget()->yRot());
|
|
|
|
previewWidget->setZRotation(partWidget->previewWidget()->zRot());
|
|
|
|
previewWidget->updateMesh(part->takePreviewMesh());
|
|
|
|
layout->addWidget(previewWidget);
|
|
|
|
} else {
|
|
|
|
QLabel *previewLabel = new QLabel;
|
2018-09-21 07:10:18 +00:00
|
|
|
previewLabel->setFixedHeight(Theme::partPreviewImageSize);
|
2018-09-18 06:22:29 +00:00
|
|
|
previewLabel->setStyleSheet("QLabel {color: " + Theme::red.name() + "}");
|
|
|
|
if (nullptr != component) {
|
|
|
|
previewLabel->setText(component->name);
|
|
|
|
} else if (!componentIds.empty()) {
|
|
|
|
previewLabel->setText(tr("(%1 items)").arg(QString::number(componentIds.size())));
|
|
|
|
}
|
|
|
|
layout->addWidget(previewLabel);
|
|
|
|
}
|
2018-09-07 10:13:55 +00:00
|
|
|
QWidget *widget = new QWidget;
|
|
|
|
widget->setLayout(layout);
|
|
|
|
forDisplayPartImage.setDefaultWidget(widget);
|
|
|
|
if (!componentIds.empty()) {
|
|
|
|
contextMenu.addAction(&forDisplayPartImage);
|
|
|
|
contextMenu.addSeparator();
|
|
|
|
}
|
2018-08-27 08:50:40 +00:00
|
|
|
|
|
|
|
QAction showAction(tr("Show"), this);
|
2018-09-06 15:04:59 +00:00
|
|
|
showAction.setIcon(Theme::awesome()->icon(fa::eye));
|
2018-08-27 08:50:40 +00:00
|
|
|
QAction hideAction(tr("Hide"), this);
|
2018-09-06 15:04:59 +00:00
|
|
|
hideAction.setIcon(Theme::awesome()->icon(fa::eyeslash));
|
2018-08-27 08:50:40 +00:00
|
|
|
QAction lockAction(tr("Lock"), this);
|
2018-09-06 15:04:59 +00:00
|
|
|
lockAction.setIcon(Theme::awesome()->icon(fa::lock));
|
2018-08-27 08:50:40 +00:00
|
|
|
QAction unlockAction(tr("Unlock"), this);
|
2018-09-06 15:04:59 +00:00
|
|
|
unlockAction.setIcon(Theme::awesome()->icon(fa::unlock));
|
2018-08-27 08:50:40 +00:00
|
|
|
QAction invertAction(tr("Invert"), this);
|
|
|
|
QAction cancelInverseAction(tr("Cancel Inverse"), this);
|
2018-09-01 02:17:26 +00:00
|
|
|
QAction selectAction(tr("Select"), this);
|
2018-08-27 08:50:40 +00:00
|
|
|
|
2018-09-07 10:13:55 +00:00
|
|
|
if (nullptr != component && nullptr != part) {
|
|
|
|
connect(&selectAction, &QAction::triggered, [=]() {
|
|
|
|
emit addPartToSelection(component->linkToPartId);
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&selectAction);
|
2018-08-27 08:50:40 +00:00
|
|
|
|
2018-09-07 10:13:55 +00:00
|
|
|
if (part->visible) {
|
|
|
|
connect(&hideAction, &QAction::triggered, [=]() {
|
|
|
|
emit setPartVisibleState(component->linkToPartId, false);
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&hideAction);
|
|
|
|
} else {
|
|
|
|
connect(&showAction, &QAction::triggered, [=]() {
|
|
|
|
emit setPartVisibleState(component->linkToPartId, true);
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&showAction);
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
2018-09-07 10:13:55 +00:00
|
|
|
|
|
|
|
if (part->locked) {
|
|
|
|
connect(&unlockAction, &QAction::triggered, [=]() {
|
|
|
|
emit setPartLockState(component->linkToPartId, false);
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&unlockAction);
|
|
|
|
} else {
|
|
|
|
connect(&lockAction, &QAction::triggered, [=]() {
|
|
|
|
emit setPartLockState(component->linkToPartId, true);
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&lockAction);
|
|
|
|
}
|
|
|
|
} else if (!componentIds.empty()) {
|
|
|
|
connect(&selectAction, &QAction::triggered, [=]() {
|
|
|
|
for (const auto &componentId: componentIds) {
|
2018-09-01 02:17:26 +00:00
|
|
|
std::vector<QUuid> partIds;
|
|
|
|
m_document->collectComponentDescendantParts(componentId, partIds);
|
|
|
|
for (const auto &partId: partIds) {
|
|
|
|
emit addPartToSelection(partId);
|
|
|
|
}
|
2018-09-07 10:13:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&selectAction);
|
|
|
|
|
|
|
|
connect(&showAction, &QAction::triggered, [=]() {
|
|
|
|
for (const auto &componentId: componentIds)
|
2018-08-27 08:50:40 +00:00
|
|
|
emit showDescendantComponents(componentId);
|
2018-09-07 10:13:55 +00:00
|
|
|
});
|
|
|
|
contextMenu.addAction(&showAction);
|
|
|
|
|
|
|
|
connect(&hideAction, &QAction::triggered, [=]() {
|
|
|
|
for (const auto &componentId: componentIds)
|
2018-08-27 08:50:40 +00:00
|
|
|
emit hideDescendantComponents(componentId);
|
2018-09-07 10:13:55 +00:00
|
|
|
});
|
|
|
|
contextMenu.addAction(&hideAction);
|
|
|
|
|
|
|
|
connect(&lockAction, &QAction::triggered, [=]() {
|
|
|
|
for (const auto &componentId: componentIds)
|
2018-08-27 08:50:40 +00:00
|
|
|
emit lockDescendantComponents(componentId);
|
2018-09-07 10:13:55 +00:00
|
|
|
});
|
|
|
|
contextMenu.addAction(&lockAction);
|
|
|
|
|
|
|
|
connect(&unlockAction, &QAction::triggered, [=]() {
|
|
|
|
for (const auto &componentId: componentIds)
|
2018-08-27 08:50:40 +00:00
|
|
|
emit unlockDescendantComponents(componentId);
|
2018-09-07 10:13:55 +00:00
|
|
|
});
|
|
|
|
contextMenu.addAction(&unlockAction);
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
|
|
|
|
2018-09-07 10:13:55 +00:00
|
|
|
if (component && !component->inverse) {
|
2018-08-27 08:50:40 +00:00
|
|
|
connect(&invertAction, &QAction::triggered, [=]() {
|
2018-09-07 10:13:55 +00:00
|
|
|
emit setComponentInverseState(component->id, true);
|
2018-08-27 08:50:40 +00:00
|
|
|
});
|
|
|
|
contextMenu.addAction(&invertAction);
|
|
|
|
}
|
|
|
|
|
2018-09-07 10:13:55 +00:00
|
|
|
if (component && component->inverse) {
|
2018-08-27 08:50:40 +00:00
|
|
|
connect(&cancelInverseAction, &QAction::triggered, [=]() {
|
2018-09-07 10:13:55 +00:00
|
|
|
emit setComponentInverseState(component->id, false);
|
2018-08-27 08:50:40 +00:00
|
|
|
});
|
|
|
|
contextMenu.addAction(&cancelInverseAction);
|
|
|
|
}
|
|
|
|
|
|
|
|
contextMenu.addSeparator();
|
|
|
|
|
2018-09-06 15:04:59 +00:00
|
|
|
QWidgetAction smoothAction(this);
|
2018-08-27 08:50:40 +00:00
|
|
|
QAction hideOthersAction(tr("Hide Others"), this);
|
|
|
|
QAction lockOthersAction(tr("Lock Others"), this);
|
2018-09-07 10:13:55 +00:00
|
|
|
if (nullptr != component) {
|
|
|
|
QMenu *smoothMenu = contextMenu.addMenu(tr("Smooth"));
|
|
|
|
|
|
|
|
smoothAction.setDefaultWidget(createSmoothMenuWidget(component->id));
|
|
|
|
smoothMenu->addAction(&smoothAction);
|
|
|
|
|
|
|
|
contextMenu.addSeparator();
|
2018-08-27 08:50:40 +00:00
|
|
|
|
2018-09-07 10:13:55 +00:00
|
|
|
hideOthersAction.setIcon(Theme::awesome()->icon(fa::eyeslash));
|
|
|
|
connect(&hideOthersAction, &QAction::triggered, [=]() {
|
|
|
|
emit hideOtherComponents(component->id);
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&hideOthersAction);
|
|
|
|
|
|
|
|
lockOthersAction.setIcon(Theme::awesome()->icon(fa::lock));
|
|
|
|
connect(&lockOthersAction, &QAction::triggered, [=]() {
|
|
|
|
emit lockOtherComponents(component->id);
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&lockOthersAction);
|
|
|
|
|
|
|
|
contextMenu.addSeparator();
|
|
|
|
}
|
2018-08-27 08:50:40 +00:00
|
|
|
|
|
|
|
QAction collapseAllAction(tr("Collapse All"), this);
|
|
|
|
connect(&collapseAllAction, &QAction::triggered, [=]() {
|
|
|
|
emit collapseAllComponents();
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&collapseAllAction);
|
|
|
|
|
|
|
|
QAction expandAllAction(tr("Expand All"), this);
|
|
|
|
connect(&expandAllAction, &QAction::triggered, [=]() {
|
|
|
|
emit expandAllComponents();
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&expandAllAction);
|
|
|
|
|
|
|
|
contextMenu.addSeparator();
|
|
|
|
|
|
|
|
QAction hideAllAction(tr("Hide All"), this);
|
2018-09-06 15:04:59 +00:00
|
|
|
hideAllAction.setIcon(Theme::awesome()->icon(fa::eyeslash));
|
2018-08-27 08:50:40 +00:00
|
|
|
connect(&hideAllAction, &QAction::triggered, [=]() {
|
|
|
|
emit hideAllComponents();
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&hideAllAction);
|
|
|
|
|
|
|
|
QAction showAllAction(tr("Show All"), this);
|
2018-09-06 15:04:59 +00:00
|
|
|
showAllAction.setIcon(Theme::awesome()->icon(fa::eye));
|
2018-08-27 08:50:40 +00:00
|
|
|
connect(&showAllAction, &QAction::triggered, [=]() {
|
|
|
|
emit showAllComponents();
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&showAllAction);
|
|
|
|
|
|
|
|
contextMenu.addSeparator();
|
|
|
|
|
|
|
|
QAction lockAllAction(tr("Lock All"), this);
|
2018-09-06 15:04:59 +00:00
|
|
|
lockAllAction.setIcon(Theme::awesome()->icon(fa::lock));
|
2018-08-27 08:50:40 +00:00
|
|
|
connect(&lockAllAction, &QAction::triggered, [=]() {
|
|
|
|
emit lockAllComponents();
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&lockAllAction);
|
|
|
|
|
|
|
|
QAction unlockAllAction(tr("Unlock All"), this);
|
2018-09-06 15:04:59 +00:00
|
|
|
unlockAllAction.setIcon(Theme::awesome()->icon(fa::unlock));
|
2018-08-27 08:50:40 +00:00
|
|
|
connect(&unlockAllAction, &QAction::triggered, [=]() {
|
|
|
|
emit unlockAllComponents();
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&unlockAllAction);
|
|
|
|
|
|
|
|
contextMenu.addSeparator();
|
|
|
|
|
2018-09-07 10:13:55 +00:00
|
|
|
QAction newGroupAction(tr("New Group"), this);
|
|
|
|
newGroupAction.setIcon(Theme::awesome()->icon(fa::file));
|
|
|
|
connect(&newGroupAction, &QAction::triggered, [=]() {
|
|
|
|
emit createNewChildComponent(nullptr == component ? QUuid() : component->id);
|
2018-09-06 15:04:59 +00:00
|
|
|
});
|
2018-09-07 10:13:55 +00:00
|
|
|
contextMenu.addAction(&newGroupAction);
|
2018-09-06 15:04:59 +00:00
|
|
|
|
2018-09-07 10:13:55 +00:00
|
|
|
contextMenu.addSeparator();
|
2018-08-27 08:50:40 +00:00
|
|
|
|
2018-09-07 10:13:55 +00:00
|
|
|
std::vector<QAction *> groupsActions;
|
|
|
|
QAction deleteAction(tr("Delete"), this);
|
|
|
|
QAction moveToTopAction(tr("Top"), this);
|
|
|
|
QAction moveUpAction(tr("Up"), this);
|
2018-08-27 08:50:40 +00:00
|
|
|
QAction moveDownAction(tr("Down"), this);
|
|
|
|
QAction moveToBottomAction(tr("Bottom"), this);
|
|
|
|
QAction moveToNewGroupAction(tr("New Group"), this);
|
|
|
|
QAction moveToRootGroupAction(tr("Root"), this);
|
|
|
|
std::function<void(QUuid, int)> addChildGroupsFunc;
|
2018-09-07 10:13:55 +00:00
|
|
|
if (!componentIds.empty()) {
|
|
|
|
QMenu *moveToMenu = contextMenu.addMenu(tr("Move To"));
|
|
|
|
|
|
|
|
if (nullptr != component) {
|
|
|
|
moveToTopAction.setIcon(Theme::awesome()->icon(fa::angledoubleup));
|
|
|
|
connect(&moveToTopAction, &QAction::triggered, [=]() {
|
|
|
|
emit moveComponentToTop(component->id);
|
2018-08-27 08:50:40 +00:00
|
|
|
});
|
2018-09-07 10:13:55 +00:00
|
|
|
moveToMenu->addAction(&moveToTopAction);
|
|
|
|
|
|
|
|
moveUpAction.setIcon(Theme::awesome()->icon(fa::angleup));
|
|
|
|
connect(&moveUpAction, &QAction::triggered, [=]() {
|
|
|
|
emit moveComponentUp(component->id);
|
|
|
|
});
|
|
|
|
moveToMenu->addAction(&moveUpAction);
|
|
|
|
|
|
|
|
moveDownAction.setIcon(Theme::awesome()->icon(fa::angledown));
|
|
|
|
connect(&moveDownAction, &QAction::triggered, [=]() {
|
|
|
|
emit moveComponentDown(component->id);
|
|
|
|
});
|
|
|
|
moveToMenu->addAction(&moveDownAction);
|
|
|
|
|
|
|
|
moveToBottomAction.setIcon(Theme::awesome()->icon(fa::angledoubledown));
|
|
|
|
connect(&moveToBottomAction, &QAction::triggered, [=]() {
|
|
|
|
emit moveComponentToBottom(component->id);
|
|
|
|
});
|
|
|
|
moveToMenu->addAction(&moveToBottomAction);
|
|
|
|
|
|
|
|
moveToMenu->addSeparator();
|
|
|
|
|
|
|
|
moveToNewGroupAction.setIcon(Theme::awesome()->icon(fa::file));
|
|
|
|
moveToMenu->addAction(&moveToNewGroupAction);
|
|
|
|
connect(&moveToNewGroupAction, &QAction::triggered, [=]() {
|
|
|
|
emit createNewComponentAndMoveThisIn(component->id);
|
|
|
|
});
|
|
|
|
|
|
|
|
moveToMenu->addSeparator();
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
2018-09-07 10:13:55 +00:00
|
|
|
|
|
|
|
moveToMenu->addAction(&moveToRootGroupAction);
|
|
|
|
connect(&moveToRootGroupAction, &QAction::triggered, [=]() {
|
|
|
|
for (const auto &componentId: componentIds)
|
|
|
|
emit moveComponent(componentId, QUuid());
|
|
|
|
});
|
|
|
|
|
|
|
|
addChildGroupsFunc = [this, &groupsActions, &addChildGroupsFunc, &moveToMenu, &componentIds](QUuid currentId, int tabs) -> void {
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *current = m_document->findComponent(currentId);
|
2018-09-07 10:13:55 +00:00
|
|
|
if (nullptr == current)
|
|
|
|
return;
|
|
|
|
if (!current->id.isNull() && current->linkDataType().isEmpty()) {
|
|
|
|
QAction *action = new QAction(QString(" ").repeated(tabs * 4) + current->name, this);
|
|
|
|
connect(action, &QAction::triggered, [=]() {
|
|
|
|
for (const auto &componentId: componentIds)
|
|
|
|
emit moveComponent(componentId, current->id);
|
|
|
|
});
|
|
|
|
groupsActions.push_back(action);
|
|
|
|
moveToMenu->addAction(action);
|
|
|
|
}
|
|
|
|
for (const auto &childId: current->childrenIds) {
|
|
|
|
addChildGroupsFunc(childId, tabs + 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
addChildGroupsFunc(QUuid(), 0);
|
|
|
|
|
|
|
|
contextMenu.addSeparator();
|
|
|
|
|
|
|
|
deleteAction.setIcon(Theme::awesome()->icon(fa::trash));
|
|
|
|
connect(&deleteAction, &QAction::triggered, [=]() {
|
|
|
|
for (const auto &componentId: componentIds)
|
|
|
|
emit removeComponent(componentId);
|
|
|
|
});
|
|
|
|
contextMenu.addAction(&deleteAction);
|
|
|
|
}
|
2018-08-27 08:50:40 +00:00
|
|
|
|
|
|
|
contextMenu.exec(mapToGlobal(pos));
|
|
|
|
|
|
|
|
for (const auto &action: groupsActions) {
|
|
|
|
delete action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
QWidget *PartTreeWidget::createSmoothMenuWidget(QUuid componentId)
|
2018-09-06 15:04:59 +00:00
|
|
|
{
|
|
|
|
QWidget *popup = new QWidget;
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *component = m_document->findComponent(componentId);
|
2018-09-06 15:04:59 +00:00
|
|
|
if (!component) {
|
|
|
|
qDebug() << "Find component failed:" << componentId;
|
|
|
|
return popup;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool showSeamControl = component->linkToPartId.isNull();
|
|
|
|
|
|
|
|
FloatNumberWidget *smoothAllWidget = new FloatNumberWidget;
|
|
|
|
smoothAllWidget->setItemName(tr("All"));
|
|
|
|
smoothAllWidget->setRange(0, 1);
|
|
|
|
smoothAllWidget->setValue(component->smoothAll);
|
|
|
|
|
|
|
|
connect(smoothAllWidget, &FloatNumberWidget::valueChanged, [=](float value) {
|
|
|
|
emit setComponentSmoothAll(componentId, value);
|
|
|
|
emit groupOperationAdded();
|
|
|
|
});
|
|
|
|
|
|
|
|
QPushButton *smoothAllEraser = new QPushButton(QChar(fa::eraser));
|
|
|
|
Theme::initAwesomeToolButton(smoothAllEraser);
|
|
|
|
|
|
|
|
connect(smoothAllEraser, &QPushButton::clicked, [=]() {
|
|
|
|
smoothAllWidget->setValue(0.0);
|
|
|
|
});
|
|
|
|
|
|
|
|
FloatNumberWidget *smoothSeamWidget = nullptr;
|
|
|
|
QPushButton *smoothSeamEraser = nullptr;
|
|
|
|
|
|
|
|
if (showSeamControl) {
|
|
|
|
smoothSeamWidget = new FloatNumberWidget;
|
|
|
|
smoothSeamWidget->setItemName(tr("Seam"));
|
|
|
|
smoothSeamWidget->setRange(0, 1);
|
|
|
|
smoothSeamWidget->setValue(component->smoothSeam);
|
|
|
|
|
|
|
|
connect(smoothSeamWidget, &FloatNumberWidget::valueChanged, [=](float value) {
|
|
|
|
emit setComponentSmoothSeam(componentId, value);
|
|
|
|
emit groupOperationAdded();
|
|
|
|
});
|
|
|
|
|
|
|
|
smoothSeamEraser = new QPushButton(QChar(fa::eraser));
|
|
|
|
Theme::initAwesomeToolButton(smoothSeamEraser);
|
|
|
|
|
|
|
|
connect(smoothSeamEraser, &QPushButton::clicked, [=]() {
|
|
|
|
smoothSeamWidget->setValue(0.0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
QHBoxLayout *smoothSeamLayout = nullptr;
|
|
|
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
|
|
|
QHBoxLayout *smoothAllLayout = new QHBoxLayout;
|
|
|
|
if (showSeamControl)
|
|
|
|
smoothSeamLayout = new QHBoxLayout;
|
|
|
|
smoothAllLayout->addWidget(smoothAllEraser);
|
|
|
|
smoothAllLayout->addWidget(smoothAllWidget);
|
|
|
|
if (showSeamControl) {
|
|
|
|
smoothSeamLayout->addWidget(smoothSeamEraser);
|
|
|
|
smoothSeamLayout->addWidget(smoothSeamWidget);
|
|
|
|
}
|
|
|
|
layout->addLayout(smoothAllLayout);
|
|
|
|
if (showSeamControl)
|
|
|
|
layout->addLayout(smoothSeamLayout);
|
|
|
|
|
|
|
|
popup->setLayout(layout);
|
|
|
|
|
|
|
|
return popup;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
QTreeWidgetItem *PartTreeWidget::findComponentItem(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto findResult = m_componentItemMap.find(componentId);
|
|
|
|
if (findResult == m_componentItemMap.end())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return findResult->second;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::componentNameChanged(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto componentItem = m_componentItemMap.find(componentId);
|
|
|
|
if (componentItem == m_componentItemMap.end()) {
|
|
|
|
qDebug() << "Find component item failed:" << componentId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *component = m_document->findComponent(componentId);
|
2018-08-27 08:50:40 +00:00
|
|
|
if (nullptr == component) {
|
|
|
|
qDebug() << "Find component failed:" << componentId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentItem->second->setText(0, component->name);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::componentExpandStateChanged(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto componentItem = m_componentItemMap.find(componentId);
|
|
|
|
if (componentItem == m_componentItemMap.end()) {
|
|
|
|
qDebug() << "Find component item failed:" << componentId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *component = m_document->findComponent(componentId);
|
2018-08-27 08:50:40 +00:00
|
|
|
if (nullptr == component) {
|
|
|
|
qDebug() << "Find component failed:" << componentId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentItem->second->setExpanded(component->expanded);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::addComponentChildrenToItem(QUuid componentId, QTreeWidgetItem *parentItem)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *parentComponent = m_document->findComponent(componentId);
|
2018-08-27 08:50:40 +00:00
|
|
|
if (nullptr == parentComponent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (const auto &childId: parentComponent->childrenIds) {
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *component = m_document->findComponent(childId);
|
2018-08-27 08:50:40 +00:00
|
|
|
if (nullptr == component)
|
|
|
|
continue;
|
|
|
|
if (!component->linkToPartId.isNull()) {
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem();
|
|
|
|
parentItem->addChild(item);
|
|
|
|
item->setData(0, Qt::UserRole, QVariant(component->id.toString()));
|
|
|
|
item->setFlags(item->flags() & ~(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable));
|
|
|
|
QUuid partId = component->linkToPartId;
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = new PartWidget(m_document, partId);
|
|
|
|
item->setSizeHint(0, PartWidget::preferredSize());
|
2018-08-27 08:50:40 +00:00
|
|
|
setItemWidget(item, 0, widget);
|
|
|
|
widget->reload();
|
|
|
|
m_partItemMap[partId] = item;
|
|
|
|
} else {
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(component->name));
|
|
|
|
parentItem->addChild(item);
|
|
|
|
item->setData(0, Qt::UserRole, QVariant(component->id.toString()));
|
|
|
|
item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
|
|
|
|
item->setExpanded(component->expanded);
|
2018-09-06 15:04:59 +00:00
|
|
|
item->setFlags((item->flags() | Qt::ItemIsEditable | Qt::ItemIsEnabled) & ~(Qt::ItemIsSelectable));
|
2018-08-27 08:50:40 +00:00
|
|
|
m_componentItemMap[childId] = item;
|
|
|
|
addComponentChildrenToItem(childId, item);
|
|
|
|
}
|
2018-09-07 10:13:55 +00:00
|
|
|
updateComponentSelectState(childId, isComponentSelected(childId));
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::deleteItemChildren(QTreeWidgetItem *item)
|
2018-08-31 01:40:53 +00:00
|
|
|
{
|
|
|
|
auto children = item->takeChildren();
|
|
|
|
while (!children.isEmpty()) {
|
|
|
|
auto first = children.takeFirst();
|
|
|
|
auto componentId = QUuid(first->data(0, Qt::UserRole).toString());
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *component = m_document->findComponent(componentId);
|
2018-08-31 01:40:53 +00:00
|
|
|
if (nullptr != component) {
|
|
|
|
m_componentItemMap.erase(componentId);
|
|
|
|
if (!component->linkToPartId.isNull()) {
|
|
|
|
m_partItemMap.erase(component->linkToPartId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deleteItemChildren(first);
|
|
|
|
delete first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::componentChildrenChanged(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
QTreeWidgetItem *parentItem = findComponentItem(componentId);
|
|
|
|
if (nullptr == parentItem) {
|
|
|
|
qDebug() << "Find component item failed:" << componentId;
|
|
|
|
return;
|
|
|
|
}
|
2018-08-31 01:40:53 +00:00
|
|
|
deleteItemChildren(parentItem);
|
2018-08-27 08:50:40 +00:00
|
|
|
addComponentChildrenToItem(componentId, parentItem);
|
|
|
|
|
|
|
|
// Fix the last item show in the wrong place sometimes
|
|
|
|
int childCount = invisibleRootItem()->childCount();
|
|
|
|
if (childCount > 0) {
|
|
|
|
QTreeWidgetItem *lastItem = invisibleRootItem()->child(childCount - 1);
|
|
|
|
bool isExpanded = lastItem->isExpanded();
|
|
|
|
lastItem->setExpanded(!isExpanded);
|
|
|
|
lastItem->setExpanded(isExpanded);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::removeAllContent()
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
qDeleteAll(invisibleRootItem()->takeChildren());
|
|
|
|
m_partItemMap.clear();
|
|
|
|
m_componentItemMap.clear();
|
|
|
|
m_componentItemMap[QUuid()] = invisibleRootItem();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::componentRemoved(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto componentItem = m_componentItemMap.find(componentId);
|
|
|
|
if (componentItem == m_componentItemMap.end())
|
|
|
|
return;
|
2018-09-07 10:13:55 +00:00
|
|
|
m_selectedComponentIds.erase(componentId);
|
|
|
|
if (m_currentSelectedComponentId == componentId)
|
|
|
|
m_currentSelectedComponentId = QUuid();
|
2018-08-27 08:50:40 +00:00
|
|
|
m_componentItemMap.erase(componentId);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::componentAdded(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partRemoved(QUuid partId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto partItem = m_partItemMap.find(partId);
|
|
|
|
if (partItem == m_partItemMap.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_partItemMap.erase(partItem);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::groupChanged(QTreeWidgetItem *item, int column)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
if (0 != column)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto componentId = QUuid(item->data(0, Qt::UserRole).toString());
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *component = m_document->findComponent(componentId);
|
2018-08-27 08:50:40 +00:00
|
|
|
if (nullptr == component) {
|
|
|
|
qDebug() << "Find component failed:" << componentId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->text(0) != component->name)
|
|
|
|
emit renameComponent(componentId, item->text(0));
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::groupExpanded(QTreeWidgetItem *item)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
QUuid componentId = QUuid(item->data(0, Qt::UserRole).toString());
|
|
|
|
emit setComponentExpandState(componentId, true);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::groupCollapsed(QTreeWidgetItem *item)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
QUuid componentId = QUuid(item->data(0, Qt::UserRole).toString());
|
|
|
|
emit setComponentExpandState(componentId, false);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partPreviewChanged(QUuid partId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
2018-08-27 08:50:40 +00:00
|
|
|
widget->updatePreview();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partLockStateChanged(QUuid partId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
2018-08-27 08:50:40 +00:00
|
|
|
widget->updateLockButton();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partVisibleStateChanged(QUuid partId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
2018-08-27 08:50:40 +00:00
|
|
|
widget->updateVisibleButton();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partSubdivStateChanged(QUuid partId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
2018-08-27 08:50:40 +00:00
|
|
|
widget->updateSubdivButton();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partDisableStateChanged(QUuid partId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
2018-08-27 08:50:40 +00:00
|
|
|
widget->updateDisableButton();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partXmirrorStateChanged(QUuid partId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
2018-08-27 08:50:40 +00:00
|
|
|
widget->updateXmirrorButton();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partDeformChanged(QUuid partId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
2018-08-27 08:50:40 +00:00
|
|
|
widget->updateDeformButton();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partRoundStateChanged(QUuid partId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
2018-08-27 08:50:40 +00:00
|
|
|
widget->updateRoundButton();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partWrapStateChanged(QUuid partId)
|
2018-08-31 04:54:32 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
2018-08-31 04:54:32 +00:00
|
|
|
widget->updateWrapButton();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partColorStateChanged(QUuid partId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
2018-08-27 08:50:40 +00:00
|
|
|
widget->updateColorButton();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partMaterialIdChanged(QUuid partId)
|
2018-10-04 12:51:01 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
2018-10-04 12:51:01 +00:00
|
|
|
widget->updateColorButton();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partChecked(QUuid partId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-09-07 10:13:55 +00:00
|
|
|
item->second->setBackground(0, m_hightlightedPartBackground);
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void PartTreeWidget::partUnchecked(QUuid partId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto item = m_partItemMap.find(partId);
|
|
|
|
if (item == m_partItemMap.end()) {
|
|
|
|
//qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-09-07 10:13:55 +00:00
|
|
|
item->second->setBackground(0, QBrush(Qt::transparent));
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
QSize PartTreeWidget::sizeHint() const
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
QSize size = PartWidget::preferredSize();
|
2018-08-27 08:50:40 +00:00
|
|
|
return QSize(size.width() * 1.35, size.height() * 5.5);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool PartTreeWidget::isComponentSelected(QUuid componentId)
|
2018-09-07 10:13:55 +00:00
|
|
|
{
|
|
|
|
return (m_currentSelectedComponentId == componentId ||
|
|
|
|
m_selectedComponentIds.find(componentId) != m_selectedComponentIds.end());
|
|
|
|
}
|