Add bone nodes picking interface

master
Jeremy HU 2022-11-16 21:58:13 +11:00
parent d736d86969
commit 12e7eacea2
6 changed files with 38 additions and 9 deletions

View File

@ -4,7 +4,6 @@
#include "bone_property_widget.h"
#include "document.h"
#include "theme.h"
#include <QMenu>
#include <QVBoxLayout>
#include <QWidgetAction>
@ -76,15 +75,23 @@ void BoneManageWidget::showSelectedBoneProperties()
auto* propertyWidget = new BonePropertyWidget(m_document, boneIds);
auto menu = std::make_unique<QMenu>(this->parentWidget());
QWidgetAction* widgetAction = new QWidgetAction(menu.get());
m_propertyMenu = std::make_unique<QMenu>(this->parentWidget());
connect(propertyWidget, &BonePropertyWidget::pickBoneJoints, this, [this]() {
if (nullptr == this->m_propertyMenu)
return;
this->m_document->setEditMode(Document::EditMode::Pick);
this->m_propertyMenu->close();
});
QWidgetAction* widgetAction = new QWidgetAction(m_propertyMenu.get());
widgetAction->setDefaultWidget(propertyWidget);
menu->addAction(widgetAction);
m_propertyMenu->addAction(widgetAction);
auto x = mapToGlobal(QPoint(0, 0)).x();
if (x <= 0)
x = QCursor::pos().x();
menu->exec(QPoint(
m_propertyMenu->exec(QPoint(
x - propertyWidget->width(),
QCursor::pos().y()));
}

View File

@ -1,8 +1,10 @@
#ifndef DUST3D_APPLICATION_BONE_MANAGE_WIDGET_H_
#define DUST3D_APPLICATION_BONE_MANAGE_WIDGET_H_
#include <QMenu>
#include <QWidget>
#include <dust3d/base/uuid.h>
#include <memory>
class Document;
class BonePreviewGridWidget;
@ -29,6 +31,7 @@ private:
QPushButton* m_addButton = nullptr;
QPushButton* m_selectButton = nullptr;
QPushButton* m_propertyButton = nullptr;
std::unique_ptr<QMenu> m_propertyMenu;
void updateToolButtons();
};

View File

@ -2,6 +2,7 @@
#include "float_number_widget.h"
#include "image_preview_widget.h"
#include "theme.h"
#include <QComboBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLineEdit>
@ -33,7 +34,23 @@ BonePropertyWidget::BonePropertyWidget(Document* document,
renameLayout->addWidget(m_nameEdit);
renameLayout->addStretch();
m_jointsWidget = new IntNumberWidget;
m_jointsWidget->setRange(2, 10);
QPushButton* nodePicker = new QPushButton(QChar(fa::eyedropper));
nodePicker->setToolTip(tr("Click node one by one on canvas as joints in order"));
Theme::initIconButton(nodePicker);
connect(nodePicker, &QPushButton::clicked, this, &BonePropertyWidget::pickBoneJoints);
QHBoxLayout* jointsLayout = new QHBoxLayout;
jointsLayout->addWidget(new QLabel(tr("Joints")));
jointsLayout->addWidget(m_jointsWidget);
jointsLayout->addStretch();
jointsLayout->addWidget(nodePicker);
mainLayout->addLayout(renameLayout);
mainLayout->addLayout(jointsLayout);
}
mainLayout->setSizeConstraint(QLayout::SetFixedSize);

View File

@ -2,6 +2,7 @@
#define DUST3D_APPLICATION_BONE_PROPERTY_WIDGET_H_
#include "document.h"
#include "int_number_widget.h"
#include <QWidget>
#include <dust3d/base/uuid.h>
@ -12,6 +13,7 @@ class BonePropertyWidget : public QWidget {
signals:
void renameBone(const dust3d::Uuid& boneId, const QString& name);
void groupOperationAdded();
void pickBoneJoints();
public:
BonePropertyWidget(Document* document,
@ -26,6 +28,7 @@ private:
dust3d::Uuid m_boneId;
const Document::Bone* m_bone = nullptr;
QLineEdit* m_nameEdit = nullptr;
IntNumberWidget* m_jointsWidget = nullptr;
void prepareBoneIds();
};

View File

@ -9,7 +9,7 @@ IntNumberWidget::IntNumberWidget(QWidget* parent, bool singleLine)
{
m_slider = new QSlider(Qt::Horizontal, this);
m_slider->setRange(0, 100);
m_slider->setFixedWidth(240);
m_slider->setFixedWidth(Theme::sidebarPreferredWidth * 0.6);
m_label = new QLabel(this);
m_label->setAlignment(Qt::AlignLeft);

View File

@ -705,8 +705,7 @@ void SkeletonGraphicsWidget::updateCursor()
setCursor(Qt::CrossCursor);
break;
default:
unsetCursor();
break;
setCursor(Qt::ArrowCursor);
}
emit cursorChanged();
@ -827,7 +826,7 @@ bool SkeletonGraphicsWidget::mouseMove(QMouseEvent* event)
}
}
if (Document::EditMode::Select == m_document->editMode || Document::EditMode::Add == m_document->editMode) {
if (Document::EditMode::Select == m_document->editMode || Document::EditMode::Add == m_document->editMode || Document::EditMode::Pick == m_document->editMode) {
//
// > For overlapping nodes, you can make it a bit better by selecting the node center nearest the mouse, rather than simply checking against the wider circle.