2018-04-07 11:51:33 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
2018-04-07 08:44:39 +00:00
|
|
|
#include <QDebug>
|
|
|
|
#include "skeletonpartlistwidget.h"
|
|
|
|
#include "theme.h"
|
|
|
|
|
|
|
|
SkeletonPartWidget::SkeletonPartWidget(const SkeletonDocument *document, QUuid partId) :
|
|
|
|
m_document(document),
|
|
|
|
m_partId(partId)
|
|
|
|
{
|
2018-04-08 01:30:55 +00:00
|
|
|
m_visibleButton = new QPushButton();
|
|
|
|
updateButton(m_visibleButton, QChar(fa::eye), false);
|
|
|
|
initButton(m_visibleButton);
|
2018-04-07 08:44:39 +00:00
|
|
|
|
2018-04-08 01:30:55 +00:00
|
|
|
m_lockButton = new QPushButton();
|
|
|
|
updateButton(m_lockButton, QChar(fa::unlock), false);
|
|
|
|
initButton(m_lockButton);
|
2018-04-07 12:30:26 +00:00
|
|
|
|
2018-04-08 01:30:55 +00:00
|
|
|
m_subdivButton = new QPushButton();
|
|
|
|
updateButton(m_subdivButton, QChar(fa::cube), false);
|
|
|
|
initButton(m_subdivButton);
|
2018-04-07 12:30:26 +00:00
|
|
|
|
2018-04-11 09:19:27 +00:00
|
|
|
m_disableButton = new QPushButton();
|
|
|
|
updateButton(m_disableButton, QChar(fa::toggleon), false);
|
|
|
|
initButton(m_disableButton);
|
|
|
|
|
2018-04-07 08:44:39 +00:00
|
|
|
m_previewLabel = new QLabel;
|
|
|
|
|
2018-04-11 09:19:27 +00:00
|
|
|
QHBoxLayout *miniTopToolLayout = new QHBoxLayout;
|
|
|
|
miniTopToolLayout->setSpacing(0);
|
|
|
|
miniTopToolLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
miniTopToolLayout->addWidget(m_visibleButton);
|
|
|
|
miniTopToolLayout->addWidget(m_lockButton);
|
|
|
|
miniTopToolLayout->addWidget(m_subdivButton);
|
|
|
|
miniTopToolLayout->addStretch();
|
|
|
|
|
|
|
|
QHBoxLayout *miniBottomToolLayout = new QHBoxLayout;
|
|
|
|
miniBottomToolLayout->setSpacing(0);
|
|
|
|
miniBottomToolLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
miniBottomToolLayout->addWidget(m_disableButton);
|
|
|
|
miniBottomToolLayout->addStretch();
|
2018-04-07 08:44:39 +00:00
|
|
|
|
2018-04-08 01:30:55 +00:00
|
|
|
QWidget *hrWidget = new QWidget;
|
|
|
|
hrWidget->setFixedHeight(1);
|
|
|
|
hrWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
hrWidget->setStyleSheet(QString("background-color: #252525;"));
|
|
|
|
hrWidget->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
2018-04-07 11:51:33 +00:00
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
|
|
mainLayout->setSpacing(0);
|
|
|
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
2018-04-11 09:19:27 +00:00
|
|
|
mainLayout->addLayout(miniTopToolLayout);
|
2018-04-07 11:51:33 +00:00
|
|
|
mainLayout->addWidget(m_previewLabel);
|
2018-04-11 09:19:27 +00:00
|
|
|
mainLayout->addLayout(miniBottomToolLayout);
|
2018-04-08 01:30:55 +00:00
|
|
|
mainLayout->addWidget(hrWidget);
|
2018-04-07 08:44:39 +00:00
|
|
|
|
|
|
|
setLayout(mainLayout);
|
2018-04-08 01:30:55 +00:00
|
|
|
|
|
|
|
connect(this, &SkeletonPartWidget::setPartLockState, m_document, &SkeletonDocument::setPartLockState);
|
|
|
|
connect(this, &SkeletonPartWidget::setPartVisibleState, m_document, &SkeletonDocument::setPartVisibleState);
|
|
|
|
connect(this, &SkeletonPartWidget::setPartSubdivState, m_document, &SkeletonDocument::setPartSubdivState);
|
2018-04-11 09:19:27 +00:00
|
|
|
connect(this, &SkeletonPartWidget::setPartDisableState, m_document, &SkeletonDocument::setPartDisableState);
|
2018-04-08 01:30:55 +00:00
|
|
|
|
|
|
|
connect(m_lockButton, &QPushButton::clicked, [=]() {
|
|
|
|
if (m_lockButton->text() == QChar(fa::lock)) {
|
|
|
|
emit setPartLockState(m_partId, false);
|
|
|
|
} else {
|
|
|
|
emit setPartLockState(m_partId, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(m_visibleButton, &QPushButton::clicked, [=]() {
|
|
|
|
if (m_visibleButton->text() == QChar(fa::eye)) {
|
|
|
|
emit setPartVisibleState(m_partId, false);
|
|
|
|
} else {
|
|
|
|
emit setPartVisibleState(m_partId, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(m_subdivButton, &QPushButton::clicked, [=]() {
|
|
|
|
if (m_subdivButton->text() == QChar(fa::cube)) {
|
|
|
|
emit setPartSubdivState(m_partId, true);
|
|
|
|
} else {
|
|
|
|
emit setPartSubdivState(m_partId, false);
|
|
|
|
}
|
|
|
|
});
|
2018-04-11 09:19:27 +00:00
|
|
|
|
|
|
|
connect(m_disableButton, &QPushButton::clicked, [=]() {
|
|
|
|
if (m_disableButton->text() == QChar(fa::link)) {
|
|
|
|
emit setPartDisableState(m_partId, true);
|
|
|
|
} else {
|
|
|
|
emit setPartDisableState(m_partId, false);
|
|
|
|
}
|
|
|
|
});
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-08 01:30:55 +00:00
|
|
|
void SkeletonPartWidget::initButton(QPushButton *button)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2018-04-08 01:30:55 +00:00
|
|
|
button->setFont(Theme::awesome()->font(Theme::miniIconFontSize));
|
|
|
|
button->setFixedSize(Theme::miniIconSize, Theme::miniIconSize);
|
2018-04-13 01:27:28 +00:00
|
|
|
button->setFocusPolicy(Qt::NoFocus);
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-08 01:30:55 +00:00
|
|
|
void SkeletonPartWidget::updateButton(QPushButton *button, QChar icon, bool highlighted)
|
|
|
|
{
|
|
|
|
button->setText(icon);
|
|
|
|
if (highlighted)
|
|
|
|
button->setStyleSheet("QPushButton {border: none; background: none; color: #f7d9c8;}");
|
|
|
|
else
|
|
|
|
button->setStyleSheet("QPushButton {border: none; background: none; color: #252525;}");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonPartWidget::updatePreview()
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
|
|
|
const SkeletonPart *part = m_document->findPart(m_partId);
|
|
|
|
if (!part) {
|
|
|
|
qDebug() << "Part not found:" << m_partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_previewLabel->setPixmap(QPixmap::fromImage(part->preview));
|
|
|
|
}
|
|
|
|
|
2018-04-08 01:30:55 +00:00
|
|
|
void SkeletonPartWidget::updateLockButton()
|
|
|
|
{
|
|
|
|
const SkeletonPart *part = m_document->findPart(m_partId);
|
|
|
|
if (!part) {
|
|
|
|
qDebug() << "Part not found:" << m_partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->locked)
|
|
|
|
updateButton(m_lockButton, QChar(fa::lock), true);
|
|
|
|
else
|
|
|
|
updateButton(m_lockButton, QChar(fa::unlock), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonPartWidget::updateVisibleButton()
|
|
|
|
{
|
|
|
|
const SkeletonPart *part = m_document->findPart(m_partId);
|
|
|
|
if (!part) {
|
|
|
|
qDebug() << "Part not found:" << m_partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->visible)
|
|
|
|
updateButton(m_visibleButton, QChar(fa::eye), false);
|
|
|
|
else
|
|
|
|
updateButton(m_visibleButton, QChar(fa::eyeslash), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonPartWidget::updateSubdivButton()
|
|
|
|
{
|
|
|
|
const SkeletonPart *part = m_document->findPart(m_partId);
|
|
|
|
if (!part) {
|
|
|
|
qDebug() << "Part not found:" << m_partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->subdived)
|
2018-04-08 08:05:12 +00:00
|
|
|
updateButton(m_subdivButton, QChar(fa::connectdevelop), true);
|
2018-04-08 01:30:55 +00:00
|
|
|
else
|
|
|
|
updateButton(m_subdivButton, QChar(fa::cube), false);
|
|
|
|
}
|
|
|
|
|
2018-04-11 09:19:27 +00:00
|
|
|
void SkeletonPartWidget::updateDisableButton()
|
|
|
|
{
|
|
|
|
const SkeletonPart *part = m_document->findPart(m_partId);
|
|
|
|
if (!part) {
|
|
|
|
qDebug() << "Part not found:" << m_partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->disabled)
|
|
|
|
updateButton(m_disableButton, QChar(fa::unlink), true);
|
|
|
|
else
|
|
|
|
updateButton(m_disableButton, QChar(fa::link), false);
|
|
|
|
}
|
|
|
|
|
2018-04-08 01:30:55 +00:00
|
|
|
void SkeletonPartWidget::reload()
|
|
|
|
{
|
|
|
|
updatePreview();
|
|
|
|
updateLockButton();
|
|
|
|
updateVisibleButton();
|
|
|
|
updateSubdivButton();
|
2018-04-11 09:19:27 +00:00
|
|
|
updateDisableButton();
|
2018-04-08 01:30:55 +00:00
|
|
|
}
|
|
|
|
|
2018-04-07 08:44:39 +00:00
|
|
|
SkeletonPartListWidget::SkeletonPartListWidget(const SkeletonDocument *document) :
|
|
|
|
m_document(document)
|
|
|
|
{
|
|
|
|
setSelectionMode(QAbstractItemView::NoSelection);
|
2018-04-08 01:30:55 +00:00
|
|
|
setFocusPolicy(Qt::NoFocus);
|
2018-04-07 08:44:39 +00:00
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2018-04-08 01:30:55 +00:00
|
|
|
setSpacing(0);
|
2018-04-07 11:51:33 +00:00
|
|
|
setContentsMargins(0, 0, 0, 0);
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonPartListWidget::partChanged(QUuid partId)
|
|
|
|
{
|
2018-04-08 01:30:55 +00:00
|
|
|
auto item = m_itemMap.find(partId);
|
|
|
|
if (item == m_itemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
2018-04-07 08:44:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-04-08 01:30:55 +00:00
|
|
|
SkeletonPartWidget *widget = (SkeletonPartWidget *)itemWidget(item->second);
|
|
|
|
widget->reload();
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonPartListWidget::partListChanged()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
m_itemMap.clear();
|
|
|
|
|
|
|
|
for (auto partIdIt = m_document->partIds.begin(); partIdIt != m_document->partIds.end(); partIdIt++) {
|
|
|
|
QUuid partId = *partIdIt;
|
|
|
|
QListWidgetItem *item = new QListWidgetItem(this);
|
|
|
|
item->setSizeHint(QSize(width(), Theme::previewImageSize));
|
|
|
|
addItem(item);
|
|
|
|
SkeletonPartWidget *widget = new SkeletonPartWidget(m_document, partId);
|
|
|
|
setItemWidget(item, widget);
|
|
|
|
widget->reload();
|
|
|
|
m_itemMap[partId] = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-08 01:30:55 +00:00
|
|
|
void SkeletonPartListWidget::partPreviewChanged(QUuid partId)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2018-04-08 01:30:55 +00:00
|
|
|
auto item = m_itemMap.find(partId);
|
|
|
|
if (item == m_itemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
2018-04-07 08:44:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-04-08 01:30:55 +00:00
|
|
|
SkeletonPartWidget *widget = (SkeletonPartWidget *)itemWidget(item->second);
|
|
|
|
widget->updatePreview();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonPartListWidget::partLockStateChanged(QUuid partId)
|
|
|
|
{
|
|
|
|
auto item = m_itemMap.find(partId);
|
|
|
|
if (item == m_itemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkeletonPartWidget *widget = (SkeletonPartWidget *)itemWidget(item->second);
|
|
|
|
widget->updateLockButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonPartListWidget::partVisibleStateChanged(QUuid partId)
|
|
|
|
{
|
|
|
|
auto item = m_itemMap.find(partId);
|
|
|
|
if (item == m_itemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkeletonPartWidget *widget = (SkeletonPartWidget *)itemWidget(item->second);
|
|
|
|
widget->updateVisibleButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonPartListWidget::partSubdivStateChanged(QUuid partId)
|
|
|
|
{
|
|
|
|
auto item = m_itemMap.find(partId);
|
2018-04-07 08:44:39 +00:00
|
|
|
if (item == m_itemMap.end()) {
|
2018-04-08 01:30:55 +00:00
|
|
|
qDebug() << "Part item not found:" << partId;
|
2018-04-07 08:44:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkeletonPartWidget *widget = (SkeletonPartWidget *)itemWidget(item->second);
|
2018-04-08 01:30:55 +00:00
|
|
|
widget->updateSubdivButton();
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
2018-04-11 09:19:27 +00:00
|
|
|
|
|
|
|
void SkeletonPartListWidget::partDisableStateChanged(QUuid partId)
|
|
|
|
{
|
|
|
|
auto item = m_itemMap.find(partId);
|
|
|
|
if (item == m_itemMap.end()) {
|
|
|
|
qDebug() << "Part item not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkeletonPartWidget *widget = (SkeletonPartWidget *)itemWidget(item->second);
|
|
|
|
widget->updateDisableButton();
|
|
|
|
}
|