Skip to content

Commit

Permalink
Add check part and show part check status.
Browse files Browse the repository at this point in the history
Now can check part from part list widget, double click it will check the whole part to graphics view, and also, if the part's node or edge been hovered or checked, the first one's part will be highlighted in the part list.
  • Loading branch information
huxingyi committed Apr 18, 2018
1 parent f1b2193 commit fe11e09
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/skeletondocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ class SkeletonDocument : public QObject
void xlockStateChanged();
void ylockStateChanged();
void zlockStateChanged();
void checkPart(QUuid partId);
void partChecked(QUuid partId);
void partUnchecked(QUuid partId);
public: // need initialize
float originX;
float originY;
Expand Down
5 changes: 5 additions & 0 deletions src/skeletondocumentwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
connect(graphicsWidget, &SkeletonGraphicsWidget::batchChangeEnd, m_document, &SkeletonDocument::batchChangeEnd);
connect(graphicsWidget, &SkeletonGraphicsWidget::breakEdge, m_document, &SkeletonDocument::breakEdge);
connect(graphicsWidget, &SkeletonGraphicsWidget::moveOriginBy, m_document, &SkeletonDocument::moveOriginBy);
connect(graphicsWidget, &SkeletonGraphicsWidget::partChecked, m_document, &SkeletonDocument::partChecked);
connect(graphicsWidget, &SkeletonGraphicsWidget::partUnchecked, m_document, &SkeletonDocument::partUnchecked);

connect(graphicsWidget, &SkeletonGraphicsWidget::changeTurnaround, this, &SkeletonDocumentWindow::changeTurnaround);
connect(graphicsWidget, &SkeletonGraphicsWidget::save, this, &SkeletonDocumentWindow::save);
Expand All @@ -414,6 +416,7 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
connect(m_document, &SkeletonDocument::partDisableStateChanged, graphicsWidget, &SkeletonGraphicsWidget::partVisibleStateChanged);
connect(m_document, &SkeletonDocument::cleanup, graphicsWidget, &SkeletonGraphicsWidget::removeAllContent);
connect(m_document, &SkeletonDocument::originChanged, graphicsWidget, &SkeletonGraphicsWidget::originChanged);
connect(m_document, &SkeletonDocument::checkPart, graphicsWidget, &SkeletonGraphicsWidget::selectPartAllById);

connect(m_document, &SkeletonDocument::partListChanged, partListWidget, &SkeletonPartListWidget::partListChanged);
connect(m_document, &SkeletonDocument::partPreviewChanged, partListWidget, &SkeletonPartListWidget::partPreviewChanged);
Expand All @@ -425,6 +428,8 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
connect(m_document, &SkeletonDocument::partDeformThicknessChanged, partListWidget, &SkeletonPartListWidget::partDeformChanged);
connect(m_document, &SkeletonDocument::partDeformWidthChanged, partListWidget, &SkeletonPartListWidget::partDeformChanged);
connect(m_document, &SkeletonDocument::cleanup, partListWidget, &SkeletonPartListWidget::partListChanged);
connect(m_document, &SkeletonDocument::partChecked, partListWidget, &SkeletonPartListWidget::partChecked);
connect(m_document, &SkeletonDocument::partUnchecked, partListWidget, &SkeletonPartListWidget::partUnchecked);

connect(m_document, &SkeletonDocument::skeletonChanged, m_document, &SkeletonDocument::generateMesh);

Expand Down
73 changes: 73 additions & 0 deletions src/skeletongraphicswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,14 @@ bool SkeletonGraphicsWidget::mouseMove(QMouseEvent *event)
m_hoveredOriginItem->setHovered(true);
}
}
QUuid hoveredPartId;
if (newHoverNodeItem != m_hoveredNodeItem) {
if (nullptr != m_hoveredNodeItem) {
m_hoveredNodeItem->setHovered(false);
}
m_hoveredNodeItem = newHoverNodeItem;
if (nullptr != m_hoveredNodeItem) {
hoveredPartId = querySkeletonItemPartId(m_hoveredNodeItem);
m_hoveredNodeItem->setHovered(true);
}
}
Expand All @@ -519,9 +521,16 @@ bool SkeletonGraphicsWidget::mouseMove(QMouseEvent *event)
}
m_hoveredEdgeItem = newHoverEdgeItem;
if (nullptr != m_hoveredEdgeItem) {
hoveredPartId = querySkeletonItemPartId(m_hoveredEdgeItem);
m_hoveredEdgeItem->setHovered(true);
}
}
if (m_hoveredNodeItem) {
hoveredPartId = querySkeletonItemPartId(m_hoveredNodeItem);
} else if (m_hoveredEdgeItem) {
hoveredPartId = querySkeletonItemPartId(m_hoveredEdgeItem);
}
hoverPart(hoveredPartId);
}

if (SkeletonDocumentEditMode::Add == m_document->editMode) {
Expand Down Expand Up @@ -1321,6 +1330,28 @@ bool SkeletonGraphicsWidget::checkSkeletonItem(QGraphicsItem *item, bool checked
return false;
}

QUuid SkeletonGraphicsWidget::querySkeletonItemPartId(QGraphicsItem *item)
{
if (item->data(0) == "node") {
SkeletonGraphicsNodeItem *nodeItem = (SkeletonGraphicsNodeItem *)item;
const SkeletonNode *node = m_document->findNode(nodeItem->id());
if (!node) {
qDebug() << "Find node id failed:" << nodeItem->id();
return QUuid();
}
return node->partId;
} else if (item->data(0) == "edge") {
SkeletonGraphicsEdgeItem *edgeItem = (SkeletonGraphicsEdgeItem *)item;
const SkeletonEdge *edge = m_document->findEdge(edgeItem->id());
if (!edge) {
qDebug() << "Find edge id failed:" << edgeItem->id();
return QUuid();
}
return edge->partId;
}
return QUuid();
}

SkeletonProfile SkeletonGraphicsWidget::readSkeletonItemProfile(QGraphicsItem *item)
{
if (item->data(0) == "node") {
Expand Down Expand Up @@ -1447,6 +1478,30 @@ bool SkeletonGraphicsWidget::readSkeletonNodeAndAnyEdgeOfNodeFromRangeSelection(
return true;
}

void SkeletonGraphicsWidget::selectPartAllById(QUuid partId)
{
unselectAll();
for (const auto &it: nodeItemMap) {
SkeletonGraphicsNodeItem *item = it.second.first;
const SkeletonNode *node = m_document->findNode(item->id());
if (!node)
continue;
if (node->partId != partId)
continue;
addItemToRangeSelection(item);
}
for (const auto &it: edgeItemMap) {
SkeletonGraphicsEdgeItem *item = it.second.first;
const SkeletonEdge *edge = m_document->findEdge(item->id());
if (!edge)
continue;
if (edge->partId != partId)
continue;
addItemToRangeSelection(item);
}
hoverPart(QUuid());
}

void SkeletonGraphicsWidget::selectPartAll()
{
unselectAll();
Expand Down Expand Up @@ -1588,3 +1643,21 @@ bool SkeletonGraphicsWidget::isSingleNodeSelected()
return item->data(0) == "node";
}

void SkeletonGraphicsWidget::hoverPart(QUuid partId)
{
if (partId.isNull()) {
if (!m_rangeSelectionSet.empty()) {
const auto &it = m_rangeSelectionSet.begin();
partId = querySkeletonItemPartId(*it);
}
}

if (m_lastCheckedPart == partId)
return;

if (!m_lastCheckedPart.isNull())
emit partUnchecked(m_lastCheckedPart);
m_lastCheckedPart = partId;
if (!m_lastCheckedPart.isNull())
emit partChecked(m_lastCheckedPart);
}
6 changes: 6 additions & 0 deletions src/skeletongraphicswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ class SkeletonGraphicsWidget : public QGraphicsView, public SkeletonGraphicsFunc
void exportResult();
void breakEdge(QUuid edgeId);
void moveOriginBy(float x, float y, float z);
void partChecked(QUuid partId);
void partUnchecked(QUuid partId);
public:
SkeletonGraphicsWidget(const SkeletonDocument *document);
std::map<QUuid, std::pair<SkeletonGraphicsNodeItem *, SkeletonGraphicsNodeItem *>> nodeItemMap;
Expand All @@ -366,6 +368,7 @@ class SkeletonGraphicsWidget : public QGraphicsView, public SkeletonGraphicsFunc
bool mouseDoubleClick(QMouseEvent *event);
bool keyPress(QKeyEvent *event);
bool checkSkeletonItem(QGraphicsItem *item, bool checked);
QUuid querySkeletonItemPartId(QGraphicsItem *item);
static SkeletonProfile readSkeletonItemProfile(QGraphicsItem *item);
void readMergedSkeletonNodeSetFromRangeSelection(std::set<SkeletonGraphicsNodeItem *> *nodeItemSet);
void readSkeletonNodeAndEdgeIdSetFromRangeSelection(std::set<QUuid> *nodeIdSet, std::set<QUuid> *edgeIdSet);
Expand Down Expand Up @@ -414,6 +417,7 @@ public slots:
void moveCheckedOrigin(float byX, float byY);
void originChanged();
void alignSelectedToCenter();
void selectPartAllById(QUuid partId);
private slots:
void turnaroundImageReady();
private:
Expand All @@ -431,6 +435,7 @@ private slots:
bool isSingleNodeSelected();
void addItemToRangeSelection(QGraphicsItem *item);
void removeItemFromRangeSelection(QGraphicsItem *item);
void hoverPart(QUuid partId);
private: //need initalize
const SkeletonDocument *m_document;
QGraphicsPixmapItem *m_backgroundItem;
Expand Down Expand Up @@ -460,6 +465,7 @@ private slots:
QPoint m_lastGlobalPos;
QPointF m_lastScenePos;
QPointF m_rangeSelectionStartPos;
QUuid m_lastCheckedPart;
};

class SkeletonGraphicsContainerWidget : public QWidget
Expand Down
46 changes: 45 additions & 1 deletion src/skeletonpartlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ SkeletonPartWidget::SkeletonPartWidget(const SkeletonDocument *document, QUuid p
connect(this, &SkeletonPartWidget::setPartXmirrorState, m_document, &SkeletonDocument::setPartXmirrorState);
connect(this, &SkeletonPartWidget::setPartDeformThickness, m_document, &SkeletonDocument::setPartDeformThickness);
connect(this, &SkeletonPartWidget::setPartDeformWidth, m_document, &SkeletonDocument::setPartDeformWidth);
connect(this, &SkeletonPartWidget::checkPart, m_document, &SkeletonDocument::checkPart);

connect(m_lockButton, &QPushButton::clicked, [=]() {
const SkeletonPart *part = m_document->findPart(m_partId);
Expand Down Expand Up @@ -132,6 +133,12 @@ SkeletonPartWidget::SkeletonPartWidget(const SkeletonDocument *document, QUuid p
});
}

void SkeletonPartWidget::mouseDoubleClickEvent(QMouseEvent *event)
{
QWidget::mouseDoubleClickEvent(event);
emit checkPart(m_partId);
}

void SkeletonPartWidget::initToolButton(QPushButton *button)
{
button->setFont(Theme::awesome()->font(Theme::toolIconFontSize / 2));
Expand Down Expand Up @@ -343,10 +350,14 @@ void SkeletonPartListWidget::partListChanged()
clear();
m_itemMap.clear();

for (auto partIdIt = m_document->partIds.begin(); partIdIt != m_document->partIds.end(); partIdIt++) {
int row = 0;

for (auto partIdIt = m_document->partIds.begin(); partIdIt != m_document->partIds.end(); partIdIt++, row++) {
QUuid partId = *partIdIt;
QListWidgetItem *item = new QListWidgetItem(this);
item->setSizeHint(QSize(width(), Theme::previewImageSize));
item->setData(Qt::UserRole, QVariant(row));
updateItemBackground(item, false);
addItem(item);
SkeletonPartWidget *widget = new SkeletonPartWidget(m_document, partId);
setItemWidget(item, widget);
Expand All @@ -355,6 +366,18 @@ void SkeletonPartListWidget::partListChanged()
}
}

void SkeletonPartListWidget::updateItemBackground(QListWidgetItem *item, bool checked)
{
if (checked) {
QColor color = Theme::green;
color.setAlphaF(Theme::fillAlpha);
item->setBackground(color);
} else {
int row = item->data(Qt::UserRole).toInt();
item->setBackground(0 == row % 2 ? Theme::dark : Theme::altDark);
}
}

void SkeletonPartListWidget::partPreviewChanged(QUuid partId)
{
auto item = m_itemMap.find(partId);
Expand Down Expand Up @@ -431,3 +454,24 @@ void SkeletonPartListWidget::partDeformChanged(QUuid partId)
SkeletonPartWidget *widget = (SkeletonPartWidget *)itemWidget(item->second);
widget->updateDeformButton();
}

void SkeletonPartListWidget::partChecked(QUuid partId)
{
auto item = m_itemMap.find(partId);
if (item == m_itemMap.end()) {
qDebug() << "Part item not found:" << partId;
return;
}
updateItemBackground(item->second, true);
}

void SkeletonPartListWidget::partUnchecked(QUuid partId)
{
auto item = m_itemMap.find(partId);
if (item == m_itemMap.end()) {
qDebug() << "Part item not found:" << partId;
return;
}
updateItemBackground(item->second, false);
}

8 changes: 8 additions & 0 deletions src/skeletonpartlistwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <map>
#include <QLabel>
#include <QPushButton>
#include <QMouseEvent>
#include "skeletondocument.h"

class SkeletonPartWidget : public QWidget
Expand All @@ -18,6 +19,7 @@ class SkeletonPartWidget : public QWidget
void setPartZmirrorState(QUuid partId, bool mirrored);
void setPartDeformThickness(QUuid partId, float thickness);
void setPartDeformWidth(QUuid partId, float width);
void checkPart(QUuid partId);
public:
SkeletonPartWidget(const SkeletonDocument *document, QUuid partId);
void reload();
Expand All @@ -29,6 +31,8 @@ class SkeletonPartWidget : public QWidget
void updateXmirrorButton();
void updateZmirrorButton();
void updateDeformButton();
protected:
void mouseDoubleClickEvent(QMouseEvent *event);
public slots:
void showDeformSettingPopup(const QPoint &pos);
private:
Expand Down Expand Up @@ -64,6 +68,10 @@ public slots:
void partDisableStateChanged(QUuid partId);
void partXmirrorStateChanged(QUuid partId);
void partDeformChanged(QUuid partId);
void partChecked(QUuid partId);
void partUnchecked(QUuid partId);
private:
void updateItemBackground(QListWidgetItem *item, bool checked);
private:
const SkeletonDocument *m_document;
std::map<QUuid, QListWidgetItem *> m_itemMap;
Expand Down
2 changes: 2 additions & 0 deletions src/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ QColor Theme::green = QColor(0xaa, 0xeb, 0xc4);
QColor Theme::blue = QColor(0x2a, 0x5a, 0xac);
QColor Theme::white = QColor(0xf7, 0xd9, 0xc8);
QColor Theme::black = QColor(0x25,0x25,0x25);
QColor Theme::dark = QColor(0x19,0x19,0x19);
QColor Theme::altDark = QColor(0x16,0x16,0x16);
float Theme::normalAlpha = 96.0 / 255;
float Theme::branchAlpha = 64.0 / 255;
float Theme::checkedAlpha = 1.0;
Expand Down
2 changes: 2 additions & 0 deletions src/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Theme
static QColor blue;
static QColor white;
static QColor black;
static QColor dark;
static QColor altDark;
static float normalAlpha;
static float checkedAlpha;
static float branchAlpha;
Expand Down

0 comments on commit fe11e09

Please sign in to comment.