Fix mouse handling for render model

Before we use a tricky way to share mouse event between model render widget and model edit widget, which forward the event from render widget to edit widget. This will cause some problem, such as the scroll bar of edit widget would not work when it covered by the render model.
Now the mouse event is totally disabled in the render widget, and when there is a need we forward it from edit widget.
master
Jeremy Hu 2018-10-24 16:54:18 +08:00
parent f2849a020f
commit 71ccb2b71f
13 changed files with 91 additions and 272 deletions

View File

@ -261,7 +261,6 @@ void MaterialListWidget::reload()
MaterialWidget *widget = new MaterialWidget(m_document, materialId); MaterialWidget *widget = new MaterialWidget(m_document, materialId);
connect(widget, &MaterialWidget::modifyMaterial, this, &MaterialListWidget::modifyMaterial); connect(widget, &MaterialWidget::modifyMaterial, this, &MaterialListWidget::modifyMaterial);
connect(widget, &MaterialWidget::cornerButtonClicked, this, &MaterialListWidget::cornerButtonClicked); connect(widget, &MaterialWidget::cornerButtonClicked, this, &MaterialListWidget::cornerButtonClicked);
widget->previewWidget()->setGraphicsFunctions(this);
setItemWidget(item, col, widget); setItemWidget(item, col, widget);
widget->reload(); widget->reload();
widget->updateCheckedState(isMaterialSelected(materialId)); widget->updateCheckedState(isMaterialSelected(materialId));
@ -287,40 +286,6 @@ void MaterialListWidget::removeAllContent()
clear(); clear();
} }
bool MaterialListWidget::mouseMove(QMouseEvent *event)
{
return false;
}
bool MaterialListWidget::wheel(QWheelEvent *event)
{
return false;
}
bool MaterialListWidget::mouseRelease(QMouseEvent *event)
{
return false;
}
bool MaterialListWidget::mousePress(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
showContextMenu(mapFromGlobal(event->globalPos()));
return false;
}
return false;
}
bool MaterialListWidget::mouseDoubleClick(QMouseEvent *event)
{
return false;
}
bool MaterialListWidget::keyPress(QKeyEvent *event)
{
return false;
}
void MaterialListWidget::copy() void MaterialListWidget::copy()
{ {
if (m_selectedMaterialIds.empty() && m_currentSelectedMaterialId.isNull()) if (m_selectedMaterialIds.empty() && m_currentSelectedMaterialId.isNull())

View File

@ -2,11 +2,11 @@
#define MATERIAL_LIST_WIDGET_H #define MATERIAL_LIST_WIDGET_H
#include <QTreeWidget> #include <QTreeWidget>
#include <map> #include <map>
#include <QMouseEvent>
#include "skeletondocument.h" #include "skeletondocument.h"
#include "materialwidget.h" #include "materialwidget.h"
#include "skeletongraphicswidget.h"
class MaterialListWidget : public QTreeWidget, public SkeletonGraphicsFunctions class MaterialListWidget : public QTreeWidget
{ {
Q_OBJECT Q_OBJECT
signals: signals:
@ -30,12 +30,6 @@ public slots:
protected: protected:
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
void mousePressEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override;
bool mouseMove(QMouseEvent *event) override;
bool wheel(QWheelEvent *event) override;
bool mouseRelease(QMouseEvent *event) override;
bool mousePress(QMouseEvent *event) override;
bool mouseDoubleClick(QMouseEvent *event) override;
bool keyPress(QKeyEvent *event) override;
private: private:
int calculateColumnCount(); int calculateColumnCount();
void updateMaterialSelectState(QUuid materialId, bool selected); void updateMaterialSelectState(QUuid materialId, bool selected);

View File

@ -4,9 +4,7 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <math.h> #include <math.h>
#include "modelwidget.h" #include "modelwidget.h"
#include "ds3file.h" #include "dust3dutil.h"
#include "skeletongraphicswidget.h"
#include "modelwidget.h"
// Modifed from http://doc.qt.io/qt-5/qtopengl-hellogl2-glwidget-cpp.html // Modifed from http://doc.qt.io/qt-5/qtopengl-hellogl2-glwidget-cpp.html
@ -19,10 +17,11 @@ ModelWidget::ModelWidget(QWidget *parent) :
m_zRot(0), m_zRot(0),
m_program(nullptr), m_program(nullptr),
m_moveStarted(false), m_moveStarted(false),
m_graphicsFunctions(NULL),
m_moveEnabled(true), m_moveEnabled(true),
m_zoomEnabled(true) m_zoomEnabled(true)
{ {
setAttribute(Qt::WA_TransparentForMouseEvents);
// --transparent causes the clear color to be transparent. Therefore, on systems that // --transparent causes the clear color to be transparent. Therefore, on systems that
// support it, the widget will become transparent apart from the logo. // support it, the widget will become transparent apart from the logo.
if (m_transparent) { if (m_transparent) {
@ -37,7 +36,6 @@ ModelWidget::ModelWidget(QWidget *parent) :
fmt.setSamples(4); fmt.setSamples(4);
setFormat(fmt); setFormat(fmt);
} }
setMouseTracking(true);
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
} }
@ -56,11 +54,6 @@ int ModelWidget::zRot()
return m_zRot; return m_zRot;
} }
void ModelWidget::setGraphicsFunctions(SkeletonGraphicsFunctions *graphicsFunctions)
{
m_graphicsFunctions = graphicsFunctions;
}
ModelWidget::~ModelWidget() ModelWidget::~ModelWidget()
{ {
cleanup(); cleanup();
@ -187,71 +180,56 @@ void ModelWidget::toggleWireframe()
update(); update();
} }
void ModelWidget::mousePressEvent(QMouseEvent *event) bool ModelWidget::inputMousePressEventFromOtherWidget(QMouseEvent *event)
{ {
bool shouldStartMove = false; bool shouldStartMove = false;
QOpenGLWidget::mousePressEvent(event);
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::AltModifier) && if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::AltModifier) &&
!QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ControlModifier)) { !QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ControlModifier)) {
shouldStartMove = true; shouldStartMove = m_moveEnabled;
} }
} else if (event->button() == Qt::MidButton) { } else if (event->button() == Qt::MidButton) {
shouldStartMove = m_moveEnabled; shouldStartMove = m_moveEnabled;
} }
if (shouldStartMove) { if (shouldStartMove) {
m_lastPos = event->pos(); m_lastPos = convertInputPosFromOtherWidget(event);
if (!m_moveStarted) { if (!m_moveStarted) {
m_moveStartPos = mapToParent(event->pos()); m_moveStartPos = mapToParent(convertInputPosFromOtherWidget(event));
m_moveStartGeometry = geometry(); m_moveStartGeometry = geometry();
m_moveStarted = true; m_moveStarted = true;
} }
return; return true;
} }
if (!m_moveStarted && m_graphicsFunctions && m_graphicsFunctions->mousePress(event)) return false;
return;
} }
void ModelWidget::mouseReleaseEvent(QMouseEvent *event) bool ModelWidget::inputMouseReleaseEventFromOtherWidget(QMouseEvent *event)
{ {
QOpenGLWidget::mouseReleaseEvent(event); Q_UNUSED(event);
if (m_graphicsFunctions)
m_graphicsFunctions->mouseRelease(event);
if (m_moveStarted) { if (m_moveStarted) {
m_moveStarted = false; m_moveStarted = false;
return true;
} }
return false;
} }
void ModelWidget::mouseDoubleClickEvent(QMouseEvent *event) bool ModelWidget::inputMouseMoveEventFromOtherWidget(QMouseEvent *event)
{ {
QOpenGLWidget::mouseDoubleClickEvent(event); if (!m_moveStarted) {
if (m_graphicsFunctions) return false;
m_graphicsFunctions->mouseDoubleClick(event); }
}
void ModelWidget::keyPressEvent(QKeyEvent *event) QPoint pos = convertInputPosFromOtherWidget(event);
{ int dx = pos.x() - m_lastPos.x();
QOpenGLWidget::keyPressEvent(event); int dy = pos.y() - m_lastPos.y();
if (m_graphicsFunctions)
m_graphicsFunctions->keyPress(event);
}
void ModelWidget::mouseMoveEvent(QMouseEvent *event)
{
QOpenGLWidget::mouseMoveEvent(event);
if (!m_moveStarted && m_graphicsFunctions && m_graphicsFunctions->mouseMove(event))
return;
int dx = event->x() - m_lastPos.x();
int dy = event->y() - m_lastPos.y();
if ((event->buttons() & Qt::MidButton) || if ((event->buttons() & Qt::MidButton) ||
(m_moveStarted && (event->buttons() & Qt::LeftButton))) { (m_moveStarted && (event->buttons() & Qt::LeftButton))) {
if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) { if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
if (m_moveStarted) { if (m_moveStarted) {
QRect rect = m_moveStartGeometry; QRect rect = m_moveStartGeometry;
QPoint pos = mapToParent(event->pos()); QPoint posInParent = mapToParent(pos);
rect.translate(pos.x() - m_moveStartPos.x(), pos.y() - m_moveStartPos.y()); rect.translate(posInParent.x() - m_moveStartPos.x(), posInParent.y() - m_moveStartPos.y());
setGeometry(rect); setGeometry(rect);
} }
} else { } else {
@ -259,24 +237,29 @@ void ModelWidget::mouseMoveEvent(QMouseEvent *event)
setYRotation(m_yRot + 8 * dx); setYRotation(m_yRot + 8 * dx);
} }
} }
m_lastPos = event->pos(); m_lastPos = pos;
return true;
} }
void ModelWidget::zoom(float delta) QPoint ModelWidget::convertInputPosFromOtherWidget(QMouseEvent *event)
{ {
QMargins margins(delta, delta, delta, delta); return mapFromGlobal(event->globalPos());
setGeometry(geometry().marginsAdded(margins));
} }
void ModelWidget::wheelEvent(QWheelEvent *event) bool ModelWidget::inputWheelEventFromOtherWidget(QWheelEvent *event)
{ {
QOpenGLWidget::wheelEvent(event); //QPoint globalPos = event->globalPos();
if (!m_moveStarted && m_graphicsFunctions && m_graphicsFunctions->wheel(event)) //QPoint zero;
return; //QPoint leftTop = mapToGlobal(zero);
//QRect globalRect(leftTop.x(), leftTop.y(), width(), height());
//if (!globalRect.contains(globalPos))
// return false;
if (m_moveStarted) if (m_moveStarted)
return; return true;
if (!m_zoomEnabled) if (!m_zoomEnabled)
return; return false;
qreal delta = event->delta() / 10; qreal delta = event->delta() / 10;
if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) { if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
if (delta > 0) if (delta > 0)
@ -288,6 +271,13 @@ void ModelWidget::wheelEvent(QWheelEvent *event)
delta = delta < 0 ? -1.0 : 1.0; delta = delta < 0 ? -1.0 : 1.0;
} }
zoom(delta); zoom(delta);
return true;
}
void ModelWidget::zoom(float delta)
{
QMargins margins(delta, delta, delta, delta);
setGeometry(geometry().marginsAdded(margins));
} }
void ModelWidget::updateMesh(MeshLoader *mesh) void ModelWidget::updateMesh(MeshLoader *mesh)

View File

@ -32,6 +32,11 @@ public:
void toggleWireframe(); void toggleWireframe();
void enableMove(bool enabled); void enableMove(bool enabled);
void enableZoom(bool enabled); void enableZoom(bool enabled);
bool inputMousePressEventFromOtherWidget(QMouseEvent *event);
bool inputMouseMoveEventFromOtherWidget(QMouseEvent *event);
bool inputWheelEventFromOtherWidget(QWheelEvent *event);
bool inputMouseReleaseEventFromOtherWidget(QMouseEvent *event);
QPoint convertInputPosFromOtherWidget(QMouseEvent *event);
public slots: public slots:
void setXRotation(int angle); void setXRotation(int angle);
void setYRotation(int angle); void setYRotation(int angle);
@ -46,12 +51,6 @@ protected:
void initializeGL() override; void initializeGL() override;
void paintGL() override; void paintGL() override;
void resizeGL(int width, int height) override; void resizeGL(int width, int height) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
public: public:
int xRot(); int xRot();
int yRot(); int yRot();
@ -62,7 +61,6 @@ private:
int m_zRot; int m_zRot;
ModelShaderProgram *m_program; ModelShaderProgram *m_program;
bool m_moveStarted; bool m_moveStarted;
SkeletonGraphicsFunctions *m_graphicsFunctions;
bool m_moveEnabled; bool m_moveEnabled;
bool m_zoomEnabled; bool m_zoomEnabled;
private: private:

View File

@ -251,7 +251,6 @@ void MotionListWidget::reload()
MotionWidget *widget = new MotionWidget(m_document, motionId); MotionWidget *widget = new MotionWidget(m_document, motionId);
connect(widget, &MotionWidget::modifyMotion, this, &MotionListWidget::modifyMotion); connect(widget, &MotionWidget::modifyMotion, this, &MotionListWidget::modifyMotion);
connect(widget, &MotionWidget::cornerButtonClicked, this, &MotionListWidget::cornerButtonClicked); connect(widget, &MotionWidget::cornerButtonClicked, this, &MotionListWidget::cornerButtonClicked);
widget->previewWidget()->setGraphicsFunctions(this);
setItemWidget(item, col, widget); setItemWidget(item, col, widget);
widget->reload(); widget->reload();
widget->updateCheckedState(isMotionSelected(motionId)); widget->updateCheckedState(isMotionSelected(motionId));
@ -277,40 +276,6 @@ void MotionListWidget::removeAllContent()
clear(); clear();
} }
bool MotionListWidget::mouseMove(QMouseEvent *event)
{
return false;
}
bool MotionListWidget::wheel(QWheelEvent *event)
{
return false;
}
bool MotionListWidget::mouseRelease(QMouseEvent *event)
{
return false;
}
bool MotionListWidget::mousePress(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
showContextMenu(mapFromGlobal(event->globalPos()));
return false;
}
return false;
}
bool MotionListWidget::mouseDoubleClick(QMouseEvent *event)
{
return false;
}
bool MotionListWidget::keyPress(QKeyEvent *event)
{
return false;
}
void MotionListWidget::copy() void MotionListWidget::copy()
{ {
if (m_selectedMotionIds.empty() && m_currentSelectedMotionId.isNull()) if (m_selectedMotionIds.empty() && m_currentSelectedMotionId.isNull())

View File

@ -2,11 +2,11 @@
#define MOTION_LIST_WIDGET_H #define MOTION_LIST_WIDGET_H
#include <QTreeWidget> #include <QTreeWidget>
#include <map> #include <map>
#include <QMouseEvent>
#include "skeletondocument.h" #include "skeletondocument.h"
#include "motionwidget.h" #include "motionwidget.h"
#include "skeletongraphicswidget.h"
class MotionListWidget : public QTreeWidget, public SkeletonGraphicsFunctions class MotionListWidget : public QTreeWidget
{ {
Q_OBJECT Q_OBJECT
signals: signals:
@ -28,12 +28,6 @@ public slots:
protected: protected:
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
void mousePressEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override;
bool mouseMove(QMouseEvent *event) override;
bool wheel(QWheelEvent *event) override;
bool mouseRelease(QMouseEvent *event) override;
bool mousePress(QMouseEvent *event) override;
bool mouseDoubleClick(QMouseEvent *event) override;
bool keyPress(QKeyEvent *event) override;
private: private:
int calculateColumnCount(); int calculateColumnCount();
void updateMotionSelectState(QUuid motionId, bool selected); void updateMotionSelectState(QUuid motionId, bool selected);

View File

@ -251,7 +251,6 @@ void PoseListWidget::reload()
PoseWidget *widget = new PoseWidget(m_document, poseId); PoseWidget *widget = new PoseWidget(m_document, poseId);
connect(widget, &PoseWidget::modifyPose, this, &PoseListWidget::modifyPose); connect(widget, &PoseWidget::modifyPose, this, &PoseListWidget::modifyPose);
connect(widget, &PoseWidget::cornerButtonClicked, this, &PoseListWidget::cornerButtonClicked); connect(widget, &PoseWidget::cornerButtonClicked, this, &PoseListWidget::cornerButtonClicked);
widget->previewWidget()->setGraphicsFunctions(this);
setItemWidget(item, col, widget); setItemWidget(item, col, widget);
widget->reload(); widget->reload();
widget->updateCheckedState(isPoseSelected(poseId)); widget->updateCheckedState(isPoseSelected(poseId));
@ -277,40 +276,6 @@ void PoseListWidget::removeAllContent()
clear(); clear();
} }
bool PoseListWidget::mouseMove(QMouseEvent *event)
{
return false;
}
bool PoseListWidget::wheel(QWheelEvent *event)
{
return false;
}
bool PoseListWidget::mouseRelease(QMouseEvent *event)
{
return false;
}
bool PoseListWidget::mousePress(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
showContextMenu(mapFromGlobal(event->globalPos()));
return false;
}
return false;
}
bool PoseListWidget::mouseDoubleClick(QMouseEvent *event)
{
return false;
}
bool PoseListWidget::keyPress(QKeyEvent *event)
{
return false;
}
void PoseListWidget::copy() void PoseListWidget::copy()
{ {
if (m_selectedPoseIds.empty() && m_currentSelectedPoseId.isNull()) if (m_selectedPoseIds.empty() && m_currentSelectedPoseId.isNull())

View File

@ -2,11 +2,11 @@
#define POSE_LIST_WIDGET_H #define POSE_LIST_WIDGET_H
#include <QTreeWidget> #include <QTreeWidget>
#include <map> #include <map>
#include <QMouseEvent>
#include "skeletondocument.h" #include "skeletondocument.h"
#include "posewidget.h" #include "posewidget.h"
#include "skeletongraphicswidget.h"
class PoseListWidget : public QTreeWidget, public SkeletonGraphicsFunctions class PoseListWidget : public QTreeWidget
{ {
Q_OBJECT Q_OBJECT
signals: signals:
@ -28,12 +28,6 @@ public slots:
protected: protected:
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
void mousePressEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override;
bool mouseMove(QMouseEvent *event) override;
bool wheel(QWheelEvent *event) override;
bool mouseRelease(QMouseEvent *event) override;
bool mousePress(QMouseEvent *event) override;
bool mouseDoubleClick(QMouseEvent *event) override;
bool keyPress(QKeyEvent *event) override;
private: private:
int calculateColumnCount(); int calculateColumnCount();
void updatePoseSelectState(QUuid poseId, bool selected); void updatePoseSelectState(QUuid poseId, bool selected);

View File

@ -221,7 +221,8 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
m_modelRenderWidget->setMinimumSize(SkeletonDocumentWindow::m_modelRenderWidgetInitialSize, SkeletonDocumentWindow::m_modelRenderWidgetInitialSize); m_modelRenderWidget->setMinimumSize(SkeletonDocumentWindow::m_modelRenderWidgetInitialSize, SkeletonDocumentWindow::m_modelRenderWidgetInitialSize);
m_modelRenderWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); m_modelRenderWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
m_modelRenderWidget->move(SkeletonDocumentWindow::m_modelRenderWidgetInitialX, SkeletonDocumentWindow::m_modelRenderWidgetInitialY); m_modelRenderWidget->move(SkeletonDocumentWindow::m_modelRenderWidgetInitialX, SkeletonDocumentWindow::m_modelRenderWidgetInitialY);
m_modelRenderWidget->setGraphicsFunctions(graphicsWidget);
m_graphicsWidget->setModelWidget(m_modelRenderWidget);
m_document->setSharedContextWidget(m_modelRenderWidget); m_document->setSharedContextWidget(m_modelRenderWidget);
@ -230,7 +231,6 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
QDockWidget *partTreeDocker = new QDockWidget(tr("Parts"), this); QDockWidget *partTreeDocker = new QDockWidget(tr("Parts"), this);
partTreeDocker->setAllowedAreas(Qt::RightDockWidgetArea); partTreeDocker->setAllowedAreas(Qt::RightDockWidgetArea);
SkeletonPartTreeWidget *partTreeWidget = new SkeletonPartTreeWidget(m_document, partTreeDocker); SkeletonPartTreeWidget *partTreeWidget = new SkeletonPartTreeWidget(m_document, partTreeDocker);
partTreeWidget->setGraphicsFunctions(graphicsWidget);
partTreeDocker->setWidget(partTreeWidget); partTreeDocker->setWidget(partTreeWidget);
addDockWidget(Qt::RightDockWidgetArea, partTreeDocker); addDockWidget(Qt::RightDockWidgetArea, partTreeDocker);
connect(partTreeDocker, &QDockWidget::topLevelChanged, [=](bool topLevel) { connect(partTreeDocker, &QDockWidget::topLevelChanged, [=](bool topLevel) {

View File

@ -41,7 +41,9 @@ SkeletonGraphicsWidget::SkeletonGraphicsWidget(const SkeletonDocument *document)
m_checkedOriginItem(nullptr), m_checkedOriginItem(nullptr),
m_ikMoveUpdateVersion(0), m_ikMoveUpdateVersion(0),
m_ikMover(nullptr), m_ikMover(nullptr),
m_deferredRemoveTimer(nullptr) m_deferredRemoveTimer(nullptr),
m_eventForwardingToModelWidget(false),
m_modelWidget(nullptr)
{ {
setRenderHint(QPainter::Antialiasing, false); setRenderHint(QPainter::Antialiasing, false);
setBackgroundBrush(QBrush(QWidget::palette().color(QWidget::backgroundRole()), Qt::SolidPattern)); setBackgroundBrush(QBrush(QWidget::palette().color(QWidget::backgroundRole()), Qt::SolidPattern));
@ -86,6 +88,11 @@ SkeletonGraphicsWidget::SkeletonGraphicsWidget(const SkeletonDocument *document)
connect(this, &SkeletonGraphicsWidget::customContextMenuRequested, this, &SkeletonGraphicsWidget::showContextMenu); connect(this, &SkeletonGraphicsWidget::customContextMenuRequested, this, &SkeletonGraphicsWidget::showContextMenu);
} }
void SkeletonGraphicsWidget::setModelWidget(ModelWidget *modelWidget)
{
m_modelWidget = modelWidget;
}
void SkeletonGraphicsWidget::enableBackgroundBlur() void SkeletonGraphicsWidget::enableBackgroundBlur()
{ {
m_backgroundItem->setOpacity(0.25); m_backgroundItem->setOpacity(0.25);
@ -564,27 +571,40 @@ void SkeletonGraphicsWidget::editModeChanged()
void SkeletonGraphicsWidget::mouseMoveEvent(QMouseEvent *event) void SkeletonGraphicsWidget::mouseMoveEvent(QMouseEvent *event)
{ {
if (m_modelWidget && m_modelWidget->inputMouseMoveEventFromOtherWidget(event))
return;
QGraphicsView::mouseMoveEvent(event); QGraphicsView::mouseMoveEvent(event);
mouseMove(event); mouseMove(event);
} }
void SkeletonGraphicsWidget::wheelEvent(QWheelEvent *event) void SkeletonGraphicsWidget::wheelEvent(QWheelEvent *event)
{ {
if (SkeletonDocumentEditMode::ZoomIn == m_document->editMode || if (!wheel(event)) {
SkeletonDocumentEditMode::ZoomOut == m_document->editMode || if (m_modelWidget && m_modelWidget->inputWheelEventFromOtherWidget(event))
SkeletonDocumentEditMode::Drag == m_document->editMode) return;
QGraphicsView::wheelEvent(event); }
wheel(event);
//if (SkeletonDocumentEditMode::ZoomIn == m_document->editMode ||
// SkeletonDocumentEditMode::ZoomOut == m_document->editMode ||
// SkeletonDocumentEditMode::Drag == m_document->editMode)
// QGraphicsView::wheelEvent(event);
} }
void SkeletonGraphicsWidget::mouseReleaseEvent(QMouseEvent *event) void SkeletonGraphicsWidget::mouseReleaseEvent(QMouseEvent *event)
{ {
if (m_modelWidget && m_modelWidget->inputMouseReleaseEventFromOtherWidget(event))
return;
QGraphicsView::mouseReleaseEvent(event); QGraphicsView::mouseReleaseEvent(event);
mouseRelease(event); mouseRelease(event);
} }
void SkeletonGraphicsWidget::mousePressEvent(QMouseEvent *event) void SkeletonGraphicsWidget::mousePressEvent(QMouseEvent *event)
{ {
if (m_modelWidget && m_modelWidget->inputMousePressEventFromOtherWidget(event))
return;
QGraphicsView::mousePressEvent(event); QGraphicsView::mousePressEvent(event);
m_mouseEventFromSelf = true; m_mouseEventFromSelf = true;
if (mousePress(event)) { if (mousePress(event)) {

View File

@ -17,6 +17,7 @@
#include "theme.h" #include "theme.h"
#include "dust3dutil.h" #include "dust3dutil.h"
#include "skeletonikmover.h" #include "skeletonikmover.h"
#include "modelwidget.h"
class SkeletonGraphicsOriginItem : public QGraphicsPolygonItem class SkeletonGraphicsOriginItem : public QGraphicsPolygonItem
{ {
@ -336,18 +337,7 @@ private:
SkeletonProfile m_profile; SkeletonProfile m_profile;
}; };
class SkeletonGraphicsFunctions class SkeletonGraphicsWidget : public QGraphicsView
{
public:
virtual bool mouseMove(QMouseEvent *event) = 0;
virtual bool wheel(QWheelEvent *event) = 0;
virtual bool mouseRelease(QMouseEvent *event) = 0;
virtual bool mousePress(QMouseEvent *event) = 0;
virtual bool mouseDoubleClick(QMouseEvent *event) = 0;
virtual bool keyPress(QKeyEvent *event) = 0;
};
class SkeletonGraphicsWidget : public QGraphicsView, public SkeletonGraphicsFunctions
{ {
Q_OBJECT Q_OBJECT
signals: signals:
@ -411,6 +401,7 @@ public:
bool hasEdgeSelection(); bool hasEdgeSelection();
bool hasNodeSelection(); bool hasNodeSelection();
bool hasTwoDisconnectedNodesSelection(); bool hasTwoDisconnectedNodesSelection();
void setModelWidget(ModelWidget *modelWidget);
protected: protected:
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);
@ -522,6 +513,8 @@ private: //need initalize
unsigned long long m_ikMoveUpdateVersion; unsigned long long m_ikMoveUpdateVersion;
SkeletonIkMover *m_ikMover; SkeletonIkMover *m_ikMover;
QTimer *m_deferredRemoveTimer; QTimer *m_deferredRemoveTimer;
bool m_eventForwardingToModelWidget;
ModelWidget *m_modelWidget;
private: private:
QVector3D m_ikMoveTarget; QVector3D m_ikMoveTarget;
QUuid m_ikMoveEndEffectorId; QUuid m_ikMoveEndEffectorId;

View File

@ -62,42 +62,6 @@ SkeletonPartTreeWidget::SkeletonPartTreeWidget(const SkeletonDocument *document,
connect(this, &QTreeWidget::itemCollapsed, this, &SkeletonPartTreeWidget::groupCollapsed); connect(this, &QTreeWidget::itemCollapsed, this, &SkeletonPartTreeWidget::groupCollapsed);
} }
bool SkeletonPartTreeWidget::mouseMove(QMouseEvent *event)
{
return false;
}
bool SkeletonPartTreeWidget::wheel(QWheelEvent *event)
{
return false;
}
bool SkeletonPartTreeWidget::mouseRelease(QMouseEvent *event)
{
return false;
}
bool SkeletonPartTreeWidget::mousePress(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
showContextMenu(mapFromGlobal(event->globalPos()));
return true;
}
return false;
}
bool SkeletonPartTreeWidget::mouseDoubleClick(QMouseEvent *event)
{
return false;
}
bool SkeletonPartTreeWidget::keyPress(QKeyEvent *event)
{
if (m_graphicsFunctions)
return m_graphicsFunctions->keyPress(event);
return false;
}
void SkeletonPartTreeWidget::selectComponent(QUuid componentId, bool multiple) void SkeletonPartTreeWidget::selectComponent(QUuid componentId, bool multiple)
{ {
if (multiple) { if (multiple) {
@ -703,7 +667,6 @@ void SkeletonPartTreeWidget::addComponentChildrenToItem(QUuid componentId, QTree
item->setFlags(item->flags() & ~(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable)); item->setFlags(item->flags() & ~(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable));
QUuid partId = component->linkToPartId; QUuid partId = component->linkToPartId;
SkeletonPartWidget *widget = new SkeletonPartWidget(m_document, partId); SkeletonPartWidget *widget = new SkeletonPartWidget(m_document, partId);
widget->previewWidget()->setGraphicsFunctions(this);
item->setSizeHint(0, SkeletonPartWidget::preferredSize()); item->setSizeHint(0, SkeletonPartWidget::preferredSize());
setItemWidget(item, 0, widget); setItemWidget(item, 0, widget);
widget->reload(); widget->reload();
@ -969,18 +932,6 @@ QSize SkeletonPartTreeWidget::sizeHint() const
return QSize(size.width() * 1.35, size.height() * 5.5); return QSize(size.width() * 1.35, size.height() * 5.5);
} }
void SkeletonPartTreeWidget::setGraphicsFunctions(SkeletonGraphicsFunctions *graphicsFunctions)
{
m_graphicsFunctions = graphicsFunctions;
}
void SkeletonPartTreeWidget::keyPressEvent(QKeyEvent *event)
{
QTreeWidget::keyPressEvent(event);
if (m_graphicsFunctions)
m_graphicsFunctions->keyPress(event);
}
bool SkeletonPartTreeWidget::isComponentSelected(QUuid componentId) bool SkeletonPartTreeWidget::isComponentSelected(QUuid componentId)
{ {
return (m_currentSelectedComponentId == componentId || return (m_currentSelectedComponentId == componentId ||

View File

@ -4,9 +4,8 @@
#include <QUuid> #include <QUuid>
#include <QMouseEvent> #include <QMouseEvent>
#include "skeletondocument.h" #include "skeletondocument.h"
#include "skeletongraphicswidget.h"
class SkeletonPartTreeWidget : public QTreeWidget, public SkeletonGraphicsFunctions class SkeletonPartTreeWidget : public QTreeWidget
{ {
Q_OBJECT Q_OBJECT
signals: signals:
@ -44,7 +43,6 @@ signals:
public: public:
SkeletonPartTreeWidget(const SkeletonDocument *document, QWidget *parent); SkeletonPartTreeWidget(const SkeletonDocument *document, QWidget *parent);
QTreeWidgetItem *findComponentItem(QUuid componentId); QTreeWidgetItem *findComponentItem(QUuid componentId);
void setGraphicsFunctions(SkeletonGraphicsFunctions *graphicsFunctions);
public slots: public slots:
void componentNameChanged(QUuid componentId); void componentNameChanged(QUuid componentId);
void componentChildrenChanged(QUuid componentId); void componentChildrenChanged(QUuid componentId);
@ -71,15 +69,8 @@ public slots:
void removeAllContent(); void removeAllContent();
void showContextMenu(const QPoint &pos); void showContextMenu(const QPoint &pos);
protected: protected:
virtual QSize sizeHint() const; QSize sizeHint() const override;
virtual void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event) override;
virtual void keyPressEvent(QKeyEvent *event);
bool mouseMove(QMouseEvent *event);
bool wheel(QWheelEvent *event);
bool mouseRelease(QMouseEvent *event);
bool mousePress(QMouseEvent *event);
bool mouseDoubleClick(QMouseEvent *event);
bool keyPress(QKeyEvent *event);
private: private:
void addComponentChildrenToItem(QUuid componentId, QTreeWidgetItem *parentItem); void addComponentChildrenToItem(QUuid componentId, QTreeWidgetItem *parentItem);
void deleteItemChildren(QTreeWidgetItem *item); void deleteItemChildren(QTreeWidgetItem *item);
@ -91,7 +82,6 @@ private:
const SkeletonDocument *m_document = nullptr; const SkeletonDocument *m_document = nullptr;
std::map<QUuid, QTreeWidgetItem *> m_partItemMap; std::map<QUuid, QTreeWidgetItem *> m_partItemMap;
std::map<QUuid, QTreeWidgetItem *> m_componentItemMap; std::map<QUuid, QTreeWidgetItem *> m_componentItemMap;
SkeletonGraphicsFunctions *m_graphicsFunctions = nullptr;
QFont m_normalFont; QFont m_normalFont;
QFont m_selectedFont; QFont m_selectedFont;
QUuid m_currentSelectedComponentId; QUuid m_currentSelectedComponentId;