Move skeleton graphics items to separate source file
parent
da277c7f80
commit
427a692558
|
@ -180,6 +180,14 @@ HEADERS += sources/preferences.h
|
|||
SOURCES += sources/preferences.cc
|
||||
HEADERS += sources/preview_grid_view.h
|
||||
SOURCES += sources/preview_grid_view.cc
|
||||
HEADERS += sources/skeleton_graphics_edge_item.h
|
||||
SOURCES += sources/skeleton_graphics_edge_item.cc
|
||||
HEADERS += sources/skeleton_graphics_node_item.h
|
||||
SOURCES += sources/skeleton_graphics_node_item.cc
|
||||
HEADERS += sources/skeleton_graphics_origin_item.h
|
||||
SOURCES += sources/skeleton_graphics_origin_item.cc
|
||||
HEADERS += sources/skeleton_graphics_selection_item.h
|
||||
SOURCES += sources/skeleton_graphics_selection_item.cc
|
||||
HEADERS += sources/skeleton_graphics_widget.h
|
||||
SOURCES += sources/skeleton_graphics_widget.cc
|
||||
HEADERS += sources/skeleton_ik_mover.h
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
#include "skeleton_graphics_edge_item.h"
|
||||
#include "skeleton_graphics_node_item.h"
|
||||
#include "theme.h"
|
||||
|
||||
SkeletonGraphicsEdgeItem::SkeletonGraphicsEdgeItem()
|
||||
: m_firstItem(nullptr)
|
||||
, m_secondItem(nullptr)
|
||||
, m_hovered(false)
|
||||
, m_checked(false)
|
||||
, m_profile(Document::Profile::Unknown)
|
||||
, m_deactivated(false)
|
||||
, m_rotated(false)
|
||||
{
|
||||
setData(0, "edge");
|
||||
}
|
||||
|
||||
void SkeletonGraphicsEdgeItem::setRotated(bool rotated)
|
||||
{
|
||||
m_rotated = rotated;
|
||||
}
|
||||
|
||||
void SkeletonGraphicsEdgeItem::setEndpoints(SkeletonGraphicsNodeItem* first, SkeletonGraphicsNodeItem* second)
|
||||
{
|
||||
m_firstItem = first;
|
||||
m_secondItem = second;
|
||||
updateAppearance();
|
||||
}
|
||||
|
||||
SkeletonGraphicsNodeItem* SkeletonGraphicsEdgeItem::firstItem()
|
||||
{
|
||||
return m_firstItem;
|
||||
}
|
||||
|
||||
SkeletonGraphicsNodeItem* SkeletonGraphicsEdgeItem::secondItem()
|
||||
{
|
||||
return m_secondItem;
|
||||
}
|
||||
|
||||
void SkeletonGraphicsEdgeItem::updateAppearance()
|
||||
{
|
||||
if (nullptr == m_firstItem || nullptr == m_secondItem)
|
||||
return;
|
||||
|
||||
m_profile = m_firstItem->profile();
|
||||
|
||||
QLineF line(m_firstItem->origin(), m_secondItem->origin());
|
||||
|
||||
QPolygonF polygon;
|
||||
float radAngle = line.angle() * M_PI / 180;
|
||||
float dx = 2 * sin(radAngle);
|
||||
float dy = 2 * cos(radAngle);
|
||||
QPointF offset1 = QPointF(dx, dy);
|
||||
QPointF offset2 = QPointF(-dx, -dy);
|
||||
//polygon << line.p1() + offset1 << line.p1() + offset2 << line.p2() + offset2 << line.p2() + offset1;
|
||||
polygon << line.p1() + offset1 << line.p1() + offset2 << line.p2();
|
||||
setPolygon(polygon);
|
||||
|
||||
QColor color = Qt::gray;
|
||||
|
||||
if (!m_deactivated) {
|
||||
switch (m_firstItem->profile()) {
|
||||
case Document::Profile::Unknown:
|
||||
break;
|
||||
case Document::Profile::Main:
|
||||
color = m_rotated ? Theme::blue : Theme::red;
|
||||
break;
|
||||
case Document::Profile::Side:
|
||||
color = Theme::green;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QColor penColor = color;
|
||||
penColor.setAlphaF((m_checked || m_hovered) ? Theme::checkedAlpha : Theme::normalAlpha);
|
||||
QPen pen(penColor);
|
||||
pen.setWidth(0);
|
||||
setPen(pen);
|
||||
}
|
||||
|
||||
dust3d::Uuid SkeletonGraphicsEdgeItem::id()
|
||||
{
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
void SkeletonGraphicsEdgeItem::setId(dust3d::Uuid id)
|
||||
{
|
||||
m_uuid = id;
|
||||
}
|
||||
|
||||
Document::Profile SkeletonGraphicsEdgeItem::profile()
|
||||
{
|
||||
return m_profile;
|
||||
}
|
||||
|
||||
void SkeletonGraphicsEdgeItem::setHovered(bool hovered)
|
||||
{
|
||||
m_hovered = hovered;
|
||||
updateAppearance();
|
||||
}
|
||||
|
||||
void SkeletonGraphicsEdgeItem::setChecked(bool checked)
|
||||
{
|
||||
m_checked = checked;
|
||||
updateAppearance();
|
||||
}
|
||||
|
||||
void SkeletonGraphicsEdgeItem::setDeactivated(bool deactivated)
|
||||
{
|
||||
m_deactivated = deactivated;
|
||||
updateAppearance();
|
||||
}
|
||||
|
||||
void SkeletonGraphicsEdgeItem::reverse()
|
||||
{
|
||||
std::swap(m_firstItem, m_secondItem);
|
||||
updateAppearance();
|
||||
}
|
||||
|
||||
bool SkeletonGraphicsEdgeItem::deactivated()
|
||||
{
|
||||
return m_deactivated;
|
||||
}
|
||||
|
||||
bool SkeletonGraphicsEdgeItem::checked()
|
||||
{
|
||||
return m_checked;
|
||||
}
|
||||
|
||||
bool SkeletonGraphicsEdgeItem::hovered()
|
||||
{
|
||||
return m_hovered;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef DUST3D_APPLICATION_SKELETON_GRAPHICS_EDGE_ITEM_H_
|
||||
#define DUST3D_APPLICATION_SKELETON_GRAPHICS_EDGE_ITEM_H_
|
||||
|
||||
#include "document.h"
|
||||
#include <QGraphicsPolygonItem>
|
||||
|
||||
class SkeletonGraphicsNodeItem;
|
||||
|
||||
class SkeletonGraphicsEdgeItem : public QGraphicsPolygonItem {
|
||||
public:
|
||||
SkeletonGraphicsEdgeItem();
|
||||
void setRotated(bool rotated);
|
||||
void setEndpoints(SkeletonGraphicsNodeItem* first, SkeletonGraphicsNodeItem* second);
|
||||
SkeletonGraphicsNodeItem* firstItem();
|
||||
SkeletonGraphicsNodeItem* secondItem();
|
||||
void updateAppearance();
|
||||
dust3d::Uuid id();
|
||||
void setId(dust3d::Uuid id);
|
||||
Document::Profile profile();
|
||||
void setHovered(bool hovered);
|
||||
void setChecked(bool checked);
|
||||
void setDeactivated(bool deactivated);
|
||||
void reverse();
|
||||
bool deactivated();
|
||||
bool checked();
|
||||
bool hovered();
|
||||
|
||||
private:
|
||||
dust3d::Uuid m_uuid;
|
||||
SkeletonGraphicsNodeItem* m_firstItem;
|
||||
SkeletonGraphicsNodeItem* m_secondItem;
|
||||
QPolygonF m_selectionPolygon;
|
||||
bool m_hovered = false;
|
||||
bool m_checked = false;
|
||||
Document::Profile m_profile = Document::Profile::Unknown;
|
||||
bool m_deactivated = false;
|
||||
bool m_rotated = false;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,144 @@
|
|||
#include "skeleton_graphics_node_item.h"
|
||||
#include "theme.h"
|
||||
|
||||
SkeletonGraphicsNodeItem::SkeletonGraphicsNodeItem(Document::Profile profile)
|
||||
: m_profile(profile)
|
||||
, m_hovered(false)
|
||||
, m_checked(false)
|
||||
, m_markColor(Qt::transparent)
|
||||
, m_deactivated(false)
|
||||
, m_rotated(false)
|
||||
{
|
||||
setData(0, "node");
|
||||
setRadius(32);
|
||||
}
|
||||
|
||||
void SkeletonGraphicsNodeItem::setRotated(bool rotated)
|
||||
{
|
||||
m_rotated = rotated;
|
||||
}
|
||||
|
||||
void SkeletonGraphicsNodeItem::updateAppearance()
|
||||
{
|
||||
QColor color = Qt::gray;
|
||||
|
||||
if (!m_deactivated) {
|
||||
switch (m_profile) {
|
||||
case Document::Profile::Unknown:
|
||||
break;
|
||||
case Document::Profile::Main:
|
||||
color = m_rotated ? Theme::blue : Theme::red;
|
||||
break;
|
||||
case Document::Profile::Side:
|
||||
color = Theme::green;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QColor penColor = color;
|
||||
penColor.setAlphaF((m_checked || m_hovered) ? Theme::checkedAlpha : Theme::normalAlpha);
|
||||
QPen pen(penColor);
|
||||
pen.setWidth(0);
|
||||
setPen(pen);
|
||||
|
||||
QColor brushColor;
|
||||
Qt::BrushStyle style;
|
||||
if (m_markColor == Qt::transparent) {
|
||||
brushColor = color;
|
||||
brushColor.setAlphaF((m_checked || m_hovered) ? Theme::fillAlpha : 0);
|
||||
style = Qt::SolidPattern;
|
||||
} else {
|
||||
brushColor = m_markColor;
|
||||
brushColor.setAlphaF((m_checked || m_hovered) ? Theme::fillAlpha * 4 : Theme::fillAlpha * 1.5);
|
||||
style = Qt::Dense4Pattern;
|
||||
}
|
||||
if (m_checked)
|
||||
brushColor.setAlphaF(brushColor.alphaF() * 1.2);
|
||||
QBrush brush(brushColor);
|
||||
brush.setStyle(style);
|
||||
setBrush(brush);
|
||||
}
|
||||
|
||||
void SkeletonGraphicsNodeItem::setOrigin(QPointF point)
|
||||
{
|
||||
QPointF moveBy = point - origin();
|
||||
QRectF newRect = rect();
|
||||
newRect.adjust(moveBy.x(), moveBy.y(), moveBy.x(), moveBy.y());
|
||||
setRect(newRect);
|
||||
updateAppearance();
|
||||
}
|
||||
|
||||
QPointF SkeletonGraphicsNodeItem::origin()
|
||||
{
|
||||
return QPointF(rect().x() + rect().width() / 2,
|
||||
rect().y() + rect().height() / 2);
|
||||
}
|
||||
|
||||
float SkeletonGraphicsNodeItem::radius()
|
||||
{
|
||||
return rect().width() / 2;
|
||||
}
|
||||
|
||||
void SkeletonGraphicsNodeItem::setRadius(float radius)
|
||||
{
|
||||
if (radius < 1)
|
||||
radius = 1;
|
||||
QPointF oldOrigin = origin();
|
||||
setRect(oldOrigin.x() - radius, oldOrigin.y() - radius,
|
||||
radius * 2, radius * 2);
|
||||
updateAppearance();
|
||||
}
|
||||
|
||||
void SkeletonGraphicsNodeItem::setMarkColor(QColor color)
|
||||
{
|
||||
m_markColor = color;
|
||||
updateAppearance();
|
||||
}
|
||||
|
||||
Document::Profile SkeletonGraphicsNodeItem::profile()
|
||||
{
|
||||
return m_profile;
|
||||
}
|
||||
|
||||
dust3d::Uuid SkeletonGraphicsNodeItem::id()
|
||||
{
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
void SkeletonGraphicsNodeItem::setId(dust3d::Uuid id)
|
||||
{
|
||||
m_uuid = id;
|
||||
}
|
||||
|
||||
void SkeletonGraphicsNodeItem::setHovered(bool hovered)
|
||||
{
|
||||
m_hovered = hovered;
|
||||
updateAppearance();
|
||||
}
|
||||
|
||||
void SkeletonGraphicsNodeItem::setChecked(bool checked)
|
||||
{
|
||||
m_checked = checked;
|
||||
updateAppearance();
|
||||
}
|
||||
|
||||
void SkeletonGraphicsNodeItem::setDeactivated(bool deactivated)
|
||||
{
|
||||
m_deactivated = deactivated;
|
||||
updateAppearance();
|
||||
}
|
||||
|
||||
bool SkeletonGraphicsNodeItem::deactivated()
|
||||
{
|
||||
return m_deactivated;
|
||||
}
|
||||
|
||||
bool SkeletonGraphicsNodeItem::checked()
|
||||
{
|
||||
return m_checked;
|
||||
}
|
||||
|
||||
bool SkeletonGraphicsNodeItem::hovered()
|
||||
{
|
||||
return m_hovered;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef DUST3D_APPLICATION_SKELETON_NODE_ITEM_H_
|
||||
#define DUST3D_APPLICATION_SKELETON_NODE_ITEM_H_
|
||||
|
||||
#include "document.h"
|
||||
#include <QGraphicsEllipseItem>
|
||||
|
||||
class SkeletonGraphicsNodeItem : public QGraphicsEllipseItem {
|
||||
public:
|
||||
SkeletonGraphicsNodeItem(Document::Profile profile = Document::Profile::Unknown);
|
||||
void setRotated(bool rotated);
|
||||
void updateAppearance();
|
||||
void setOrigin(QPointF point);
|
||||
QPointF origin();
|
||||
float radius();
|
||||
void setRadius(float radius);
|
||||
void setMarkColor(QColor color);
|
||||
Document::Profile profile();
|
||||
dust3d::Uuid id();
|
||||
void setId(dust3d::Uuid id);
|
||||
void setHovered(bool hovered);
|
||||
void setChecked(bool checked);
|
||||
void setDeactivated(bool deactivated);
|
||||
bool deactivated();
|
||||
bool checked();
|
||||
bool hovered();
|
||||
|
||||
private:
|
||||
dust3d::Uuid m_uuid;
|
||||
Document::Profile m_profile = Document::Profile::Unknown;
|
||||
bool m_hovered = false;
|
||||
bool m_checked = false;
|
||||
QColor m_markColor;
|
||||
bool m_deactivated = false;
|
||||
bool m_rotated = false;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,79 @@
|
|||
#include "skeleton_graphics_origin_item.h"
|
||||
#include "theme.h"
|
||||
|
||||
SkeletonGraphicsOriginItem::SkeletonGraphicsOriginItem(Document::Profile profile)
|
||||
: m_profile(profile)
|
||||
, m_hovered(false)
|
||||
, m_checked(false)
|
||||
, m_rotated(false)
|
||||
{
|
||||
setData(0, "origin");
|
||||
}
|
||||
void SkeletonGraphicsOriginItem::setRotated(bool rotated)
|
||||
{
|
||||
m_rotated = rotated;
|
||||
}
|
||||
void SkeletonGraphicsOriginItem::updateAppearance()
|
||||
{
|
||||
QColor color = Theme::white;
|
||||
|
||||
switch (m_profile) {
|
||||
case Document::Profile::Unknown:
|
||||
break;
|
||||
case Document::Profile::Main:
|
||||
color = m_rotated ? Theme::blue : Theme::red;
|
||||
break;
|
||||
case Document::Profile::Side:
|
||||
color = Theme::green;
|
||||
break;
|
||||
}
|
||||
|
||||
QColor penColor = color;
|
||||
penColor.setAlphaF(m_checked ? Theme::checkedAlpha : Theme::normalAlpha);
|
||||
QPen pen(penColor);
|
||||
pen.setWidth(0);
|
||||
setPen(pen);
|
||||
|
||||
QColor brushColor = color;
|
||||
brushColor.setAlphaF((m_checked || m_hovered) ? Theme::checkedAlpha : Theme::normalAlpha);
|
||||
QBrush brush(brushColor);
|
||||
setBrush(brush);
|
||||
}
|
||||
void SkeletonGraphicsOriginItem::setOrigin(QPointF point)
|
||||
{
|
||||
m_origin = point;
|
||||
QPolygonF triangle;
|
||||
const int triangleRadius = 10;
|
||||
triangle.append(QPointF(point.x() - triangleRadius, point.y()));
|
||||
triangle.append(QPointF(point.x() + triangleRadius, point.y()));
|
||||
triangle.append(QPointF(point.x(), point.y() - triangleRadius));
|
||||
triangle.append(QPointF(point.x() - triangleRadius, point.y()));
|
||||
setPolygon(triangle);
|
||||
updateAppearance();
|
||||
}
|
||||
QPointF SkeletonGraphicsOriginItem::origin()
|
||||
{
|
||||
return m_origin;
|
||||
}
|
||||
Document::Profile SkeletonGraphicsOriginItem::profile()
|
||||
{
|
||||
return m_profile;
|
||||
}
|
||||
void SkeletonGraphicsOriginItem::setHovered(bool hovered)
|
||||
{
|
||||
m_hovered = hovered;
|
||||
updateAppearance();
|
||||
}
|
||||
void SkeletonGraphicsOriginItem::setChecked(bool checked)
|
||||
{
|
||||
m_checked = checked;
|
||||
updateAppearance();
|
||||
}
|
||||
bool SkeletonGraphicsOriginItem::checked()
|
||||
{
|
||||
return m_checked;
|
||||
}
|
||||
bool SkeletonGraphicsOriginItem::hovered()
|
||||
{
|
||||
return m_hovered;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef DUST3D_APPLICATION_SKELETON_ORIGIN_ITEM_H_
|
||||
#define DUST3D_APPLICATION_SKELETON_ORIGIN_ITEM_H_
|
||||
|
||||
#include "document.h"
|
||||
#include <QGraphicsPolygonItem>
|
||||
|
||||
class SkeletonGraphicsOriginItem : public QGraphicsPolygonItem {
|
||||
public:
|
||||
SkeletonGraphicsOriginItem(Document::Profile profile = Document::Profile::Unknown);
|
||||
void setRotated(bool rotated);
|
||||
void updateAppearance();
|
||||
void setOrigin(QPointF point);
|
||||
QPointF origin();
|
||||
Document::Profile profile();
|
||||
void setHovered(bool hovered);
|
||||
void setChecked(bool checked);
|
||||
bool checked();
|
||||
bool hovered();
|
||||
|
||||
private:
|
||||
Document::Profile m_profile = Document::Profile::Unknown;
|
||||
bool m_hovered = false;
|
||||
bool m_checked = false;
|
||||
QPointF m_origin;
|
||||
bool m_rotated = false;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,16 @@
|
|||
#include "skeleton_graphics_selection_item.h"
|
||||
#include "theme.h"
|
||||
|
||||
SkeletonGraphicsSelectionItem::SkeletonGraphicsSelectionItem()
|
||||
{
|
||||
QColor penColor = Theme::white;
|
||||
QPen pen(penColor);
|
||||
pen.setWidth(0);
|
||||
pen.setStyle(Qt::DashLine);
|
||||
setPen(pen);
|
||||
}
|
||||
|
||||
void SkeletonGraphicsSelectionItem::updateRange(QPointF beginPos, QPointF endPos)
|
||||
{
|
||||
setRect(QRectF(beginPos, endPos).normalized());
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef DUST3D_APPLICATION_SKELETON_SELECTION_ITEM_H_
|
||||
#define DUST3D_APPLICATION_SKELETON_SELECTION_ITEM_H_
|
||||
|
||||
#include "document.h"
|
||||
#include <QGraphicsRectItem>
|
||||
|
||||
class SkeletonGraphicsSelectionItem : public QGraphicsRectItem {
|
||||
public:
|
||||
SkeletonGraphicsSelectionItem();
|
||||
void updateRange(QPointF beginPos, QPointF endPos);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,4 +1,8 @@
|
|||
#include "skeleton_graphics_widget.h"
|
||||
#include "skeleton_graphics_edge_item.h"
|
||||
#include "skeleton_graphics_node_item.h"
|
||||
#include "skeleton_graphics_origin_item.h"
|
||||
#include "skeleton_graphics_selection_item.h"
|
||||
#include "theme.h"
|
||||
#include <QApplication>
|
||||
#include <QBitmap>
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
#ifndef DUST3D_APPLICATION_SKELETON_GRAPHICS_VIEW_H_
|
||||
#define DUST3D_APPLICATION_SKELETON_GRAPHICS_VIEW_H_
|
||||
#ifndef DUST3D_APPLICATION_SKELETON_GRAPHICS_WIDGET_H_
|
||||
#define DUST3D_APPLICATION_SKELETON_GRAPHICS_WIDGET_H_
|
||||
|
||||
#include "document.h"
|
||||
#include "model_widget.h"
|
||||
#include "skeleton_ik_mover.h"
|
||||
#include "theme.h"
|
||||
#include "turnaround_loader.h"
|
||||
#include <QGraphicsEllipseItem>
|
||||
#include <QGraphicsLineItem>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsPolygonItem>
|
||||
#include <QGraphicsView>
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
|
@ -19,374 +16,10 @@
|
|||
#include <map>
|
||||
#include <set>
|
||||
|
||||
class SkeletonGraphicsOriginItem : public QGraphicsPolygonItem {
|
||||
public:
|
||||
SkeletonGraphicsOriginItem(Document::Profile profile = Document::Profile::Unknown)
|
||||
: m_profile(profile)
|
||||
, m_hovered(false)
|
||||
, m_checked(false)
|
||||
, m_rotated(false)
|
||||
{
|
||||
setData(0, "origin");
|
||||
}
|
||||
void setRotated(bool rotated)
|
||||
{
|
||||
m_rotated = rotated;
|
||||
}
|
||||
void updateAppearance()
|
||||
{
|
||||
QColor color = Theme::white;
|
||||
|
||||
switch (m_profile) {
|
||||
case Document::Profile::Unknown:
|
||||
break;
|
||||
case Document::Profile::Main:
|
||||
color = m_rotated ? Theme::blue : Theme::red;
|
||||
break;
|
||||
case Document::Profile::Side:
|
||||
color = Theme::green;
|
||||
break;
|
||||
}
|
||||
|
||||
QColor penColor = color;
|
||||
penColor.setAlphaF(m_checked ? Theme::checkedAlpha : Theme::normalAlpha);
|
||||
QPen pen(penColor);
|
||||
pen.setWidth(0);
|
||||
setPen(pen);
|
||||
|
||||
QColor brushColor = color;
|
||||
brushColor.setAlphaF((m_checked || m_hovered) ? Theme::checkedAlpha : Theme::normalAlpha);
|
||||
QBrush brush(brushColor);
|
||||
setBrush(brush);
|
||||
}
|
||||
void setOrigin(QPointF point)
|
||||
{
|
||||
m_origin = point;
|
||||
QPolygonF triangle;
|
||||
const int triangleRadius = 10;
|
||||
triangle.append(QPointF(point.x() - triangleRadius, point.y()));
|
||||
triangle.append(QPointF(point.x() + triangleRadius, point.y()));
|
||||
triangle.append(QPointF(point.x(), point.y() - triangleRadius));
|
||||
triangle.append(QPointF(point.x() - triangleRadius, point.y()));
|
||||
setPolygon(triangle);
|
||||
updateAppearance();
|
||||
}
|
||||
QPointF origin()
|
||||
{
|
||||
return m_origin;
|
||||
}
|
||||
Document::Profile profile()
|
||||
{
|
||||
return m_profile;
|
||||
}
|
||||
void setHovered(bool hovered)
|
||||
{
|
||||
m_hovered = hovered;
|
||||
updateAppearance();
|
||||
}
|
||||
void setChecked(bool checked)
|
||||
{
|
||||
m_checked = checked;
|
||||
updateAppearance();
|
||||
}
|
||||
bool checked()
|
||||
{
|
||||
return m_checked;
|
||||
}
|
||||
bool hovered()
|
||||
{
|
||||
return m_hovered;
|
||||
}
|
||||
|
||||
private:
|
||||
Document::Profile m_profile;
|
||||
bool m_hovered;
|
||||
bool m_checked;
|
||||
QPointF m_origin;
|
||||
bool m_rotated;
|
||||
};
|
||||
|
||||
class SkeletonGraphicsSelectionItem : public QGraphicsRectItem {
|
||||
public:
|
||||
SkeletonGraphicsSelectionItem()
|
||||
{
|
||||
QColor penColor = Theme::white;
|
||||
QPen pen(penColor);
|
||||
pen.setWidth(0);
|
||||
pen.setStyle(Qt::DashLine);
|
||||
setPen(pen);
|
||||
}
|
||||
void updateRange(QPointF beginPos, QPointF endPos)
|
||||
{
|
||||
setRect(QRectF(beginPos, endPos).normalized());
|
||||
}
|
||||
};
|
||||
|
||||
class SkeletonGraphicsNodeItem : public QGraphicsEllipseItem {
|
||||
public:
|
||||
SkeletonGraphicsNodeItem(Document::Profile profile = Document::Profile::Unknown)
|
||||
: m_profile(profile)
|
||||
, m_hovered(false)
|
||||
, m_checked(false)
|
||||
, m_markColor(Qt::transparent)
|
||||
, m_deactivated(false)
|
||||
, m_rotated(false)
|
||||
{
|
||||
setData(0, "node");
|
||||
setRadius(32);
|
||||
}
|
||||
void setRotated(bool rotated)
|
||||
{
|
||||
m_rotated = rotated;
|
||||
}
|
||||
void updateAppearance()
|
||||
{
|
||||
QColor color = Qt::gray;
|
||||
|
||||
if (!m_deactivated) {
|
||||
switch (m_profile) {
|
||||
case Document::Profile::Unknown:
|
||||
break;
|
||||
case Document::Profile::Main:
|
||||
color = m_rotated ? Theme::blue : Theme::red;
|
||||
break;
|
||||
case Document::Profile::Side:
|
||||
color = Theme::green;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QColor penColor = color;
|
||||
penColor.setAlphaF((m_checked || m_hovered) ? Theme::checkedAlpha : Theme::normalAlpha);
|
||||
QPen pen(penColor);
|
||||
pen.setWidth(0);
|
||||
setPen(pen);
|
||||
|
||||
QColor brushColor;
|
||||
Qt::BrushStyle style;
|
||||
if (m_markColor == Qt::transparent) {
|
||||
brushColor = color;
|
||||
brushColor.setAlphaF((m_checked || m_hovered) ? Theme::fillAlpha : 0);
|
||||
style = Qt::SolidPattern;
|
||||
} else {
|
||||
brushColor = m_markColor;
|
||||
brushColor.setAlphaF((m_checked || m_hovered) ? Theme::fillAlpha * 4 : Theme::fillAlpha * 1.5);
|
||||
style = Qt::Dense4Pattern;
|
||||
}
|
||||
if (m_checked)
|
||||
brushColor.setAlphaF(brushColor.alphaF() * 1.2);
|
||||
QBrush brush(brushColor);
|
||||
brush.setStyle(style);
|
||||
setBrush(brush);
|
||||
}
|
||||
void setOrigin(QPointF point)
|
||||
{
|
||||
QPointF moveBy = point - origin();
|
||||
QRectF newRect = rect();
|
||||
newRect.adjust(moveBy.x(), moveBy.y(), moveBy.x(), moveBy.y());
|
||||
setRect(newRect);
|
||||
updateAppearance();
|
||||
}
|
||||
QPointF origin()
|
||||
{
|
||||
return QPointF(rect().x() + rect().width() / 2,
|
||||
rect().y() + rect().height() / 2);
|
||||
}
|
||||
float radius()
|
||||
{
|
||||
return rect().width() / 2;
|
||||
}
|
||||
void setRadius(float radius)
|
||||
{
|
||||
if (radius < 1)
|
||||
radius = 1;
|
||||
QPointF oldOrigin = origin();
|
||||
setRect(oldOrigin.x() - radius, oldOrigin.y() - radius,
|
||||
radius * 2, radius * 2);
|
||||
updateAppearance();
|
||||
}
|
||||
void setMarkColor(QColor color)
|
||||
{
|
||||
m_markColor = color;
|
||||
updateAppearance();
|
||||
}
|
||||
Document::Profile profile()
|
||||
{
|
||||
return m_profile;
|
||||
}
|
||||
dust3d::Uuid id()
|
||||
{
|
||||
return m_uuid;
|
||||
}
|
||||
void setId(dust3d::Uuid id)
|
||||
{
|
||||
m_uuid = id;
|
||||
}
|
||||
void setHovered(bool hovered)
|
||||
{
|
||||
m_hovered = hovered;
|
||||
updateAppearance();
|
||||
}
|
||||
void setChecked(bool checked)
|
||||
{
|
||||
m_checked = checked;
|
||||
updateAppearance();
|
||||
}
|
||||
void setDeactivated(bool deactivated)
|
||||
{
|
||||
m_deactivated = deactivated;
|
||||
updateAppearance();
|
||||
}
|
||||
bool deactivated()
|
||||
{
|
||||
return m_deactivated;
|
||||
}
|
||||
bool checked()
|
||||
{
|
||||
return m_checked;
|
||||
}
|
||||
bool hovered()
|
||||
{
|
||||
return m_hovered;
|
||||
}
|
||||
|
||||
private:
|
||||
dust3d::Uuid m_uuid;
|
||||
Document::Profile m_profile;
|
||||
bool m_hovered;
|
||||
bool m_checked;
|
||||
QColor m_markColor;
|
||||
bool m_deactivated;
|
||||
bool m_rotated;
|
||||
};
|
||||
|
||||
class SkeletonGraphicsEdgeItem : public QGraphicsPolygonItem {
|
||||
public:
|
||||
SkeletonGraphicsEdgeItem()
|
||||
: m_firstItem(nullptr)
|
||||
, m_secondItem(nullptr)
|
||||
, m_hovered(false)
|
||||
, m_checked(false)
|
||||
, m_profile(Document::Profile::Unknown)
|
||||
, m_deactivated(false)
|
||||
, m_rotated(false)
|
||||
{
|
||||
setData(0, "edge");
|
||||
}
|
||||
void setRotated(bool rotated)
|
||||
{
|
||||
m_rotated = rotated;
|
||||
}
|
||||
void setEndpoints(SkeletonGraphicsNodeItem* first, SkeletonGraphicsNodeItem* second)
|
||||
{
|
||||
m_firstItem = first;
|
||||
m_secondItem = second;
|
||||
updateAppearance();
|
||||
}
|
||||
SkeletonGraphicsNodeItem* firstItem()
|
||||
{
|
||||
return m_firstItem;
|
||||
}
|
||||
SkeletonGraphicsNodeItem* secondItem()
|
||||
{
|
||||
return m_secondItem;
|
||||
}
|
||||
void updateAppearance()
|
||||
{
|
||||
if (nullptr == m_firstItem || nullptr == m_secondItem)
|
||||
return;
|
||||
|
||||
m_profile = m_firstItem->profile();
|
||||
|
||||
QLineF line(m_firstItem->origin(), m_secondItem->origin());
|
||||
|
||||
QPolygonF polygon;
|
||||
float radAngle = line.angle() * M_PI / 180;
|
||||
float dx = 2 * sin(radAngle);
|
||||
float dy = 2 * cos(radAngle);
|
||||
QPointF offset1 = QPointF(dx, dy);
|
||||
QPointF offset2 = QPointF(-dx, -dy);
|
||||
//polygon << line.p1() + offset1 << line.p1() + offset2 << line.p2() + offset2 << line.p2() + offset1;
|
||||
polygon << line.p1() + offset1 << line.p1() + offset2 << line.p2();
|
||||
setPolygon(polygon);
|
||||
|
||||
QColor color = Qt::gray;
|
||||
|
||||
if (!m_deactivated) {
|
||||
switch (m_firstItem->profile()) {
|
||||
case Document::Profile::Unknown:
|
||||
break;
|
||||
case Document::Profile::Main:
|
||||
color = m_rotated ? Theme::blue : Theme::red;
|
||||
break;
|
||||
case Document::Profile::Side:
|
||||
color = Theme::green;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QColor penColor = color;
|
||||
penColor.setAlphaF((m_checked || m_hovered) ? Theme::checkedAlpha : Theme::normalAlpha);
|
||||
QPen pen(penColor);
|
||||
pen.setWidth(0);
|
||||
setPen(pen);
|
||||
}
|
||||
dust3d::Uuid id()
|
||||
{
|
||||
return m_uuid;
|
||||
}
|
||||
void setId(dust3d::Uuid id)
|
||||
{
|
||||
m_uuid = id;
|
||||
}
|
||||
Document::Profile profile()
|
||||
{
|
||||
return m_profile;
|
||||
}
|
||||
void setHovered(bool hovered)
|
||||
{
|
||||
m_hovered = hovered;
|
||||
updateAppearance();
|
||||
}
|
||||
void setChecked(bool checked)
|
||||
{
|
||||
m_checked = checked;
|
||||
updateAppearance();
|
||||
}
|
||||
void setDeactivated(bool deactivated)
|
||||
{
|
||||
m_deactivated = deactivated;
|
||||
updateAppearance();
|
||||
}
|
||||
void reverse()
|
||||
{
|
||||
std::swap(m_firstItem, m_secondItem);
|
||||
updateAppearance();
|
||||
}
|
||||
bool deactivated()
|
||||
{
|
||||
return m_deactivated;
|
||||
}
|
||||
bool checked()
|
||||
{
|
||||
return m_checked;
|
||||
}
|
||||
bool hovered()
|
||||
{
|
||||
return m_hovered;
|
||||
}
|
||||
|
||||
private:
|
||||
dust3d::Uuid m_uuid;
|
||||
SkeletonGraphicsNodeItem* m_firstItem;
|
||||
SkeletonGraphicsNodeItem* m_secondItem;
|
||||
QPolygonF m_selectionPolygon;
|
||||
bool m_hovered;
|
||||
bool m_checked;
|
||||
Document::Profile m_profile;
|
||||
bool m_deactivated;
|
||||
bool m_rotated;
|
||||
};
|
||||
class SkeletonGraphicsEdgeItem;
|
||||
class SkeletonGraphicsNodeItem;
|
||||
class SkeletonGraphicsOriginItem;
|
||||
class SkeletonGraphicsSelectionItem;
|
||||
|
||||
class SkeletonGraphicsWidget : public QGraphicsView {
|
||||
Q_OBJECT
|
||||
|
|
Loading…
Reference in New Issue