Seperate model render view control and edit view control

master
Jeremy Hu 2018-04-11 23:06:30 +08:00
parent f0e68d9f7a
commit e1e4953dec
7 changed files with 39 additions and 27 deletions

View File

@ -399,4 +399,4 @@
<h1>CatmullClark subdivision surface/C</h1> <h1>CatmullClark subdivision surface/C</h1>
<pre> <pre>
https://rosettacode.org/wiki/Catmull%E2%80%93Clark_subdivision_surface/C https://rosettacode.org/wiki/Catmull%E2%80%93Clark_subdivision_surface/C
</pre> </pre>

View File

@ -9,7 +9,7 @@ ModelMeshBinder::ModelMeshBinder() :
m_renderEdgeVertexCount(0), m_renderEdgeVertexCount(0),
m_mesh(NULL), m_mesh(NULL),
m_meshUpdated(false), m_meshUpdated(false),
m_showFrames(true) m_showWireframes(true)
{ {
} }
@ -104,7 +104,7 @@ void ModelMeshBinder::paint()
} }
} }
if (m_showFrames) { if (m_showWireframes) {
if (m_renderEdgeVertexCount > 0) { if (m_renderEdgeVertexCount > 0) {
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoEdge); QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoEdge);
glDrawArrays(GL_LINES, 0, m_renderEdgeVertexCount); glDrawArrays(GL_LINES, 0, m_renderEdgeVertexCount);
@ -124,12 +124,12 @@ void ModelMeshBinder::cleanup()
m_vboEdge.destroy(); m_vboEdge.destroy();
} }
void ModelMeshBinder::showFrames() void ModelMeshBinder::showWireframes()
{ {
m_showFrames = true; m_showWireframes = true;
} }
void ModelMeshBinder::hideFrames() void ModelMeshBinder::hideWireframes()
{ {
m_showFrames = false; m_showWireframes = false;
} }

View File

@ -16,8 +16,8 @@ public:
void initialize(); void initialize();
void paint(); void paint();
void cleanup(); void cleanup();
void showFrames(); void showWireframes();
void hideFrames(); void hideWireframes();
private: private:
QOpenGLVertexArrayObject m_vaoTriangle; QOpenGLVertexArrayObject m_vaoTriangle;
QOpenGLBuffer m_vboTriangle; QOpenGLBuffer m_vboTriangle;
@ -28,7 +28,7 @@ private:
int m_renderTriangleVertexCount; int m_renderTriangleVertexCount;
int m_renderEdgeVertexCount; int m_renderEdgeVertexCount;
bool m_meshUpdated; bool m_meshUpdated;
bool m_showFrames; bool m_showWireframes;
}; };
#endif #endif

View File

@ -64,7 +64,7 @@ QImage ModelOfflineRender::toImage(const QSize &size)
ModelShaderProgram *program = new ModelShaderProgram; ModelShaderProgram *program = new ModelShaderProgram;
ModelMeshBinder meshBinder; ModelMeshBinder meshBinder;
meshBinder.initialize(); meshBinder.initialize();
meshBinder.hideFrames(); meshBinder.hideWireframes();
program->setUniformValue(program->lightPosLoc(), QVector3D(0, 0, 70)); program->setUniformValue(program->lightPosLoc(), QVector3D(0, 0, 70));

View File

@ -35,6 +35,7 @@ ModelWidget::ModelWidget(QWidget *parent)
setFormat(fmt); setFormat(fmt);
} }
setMouseTracking(true); setMouseTracking(true);
setContextMenuPolicy(Qt::CustomContextMenu);
} }
int ModelWidget::xRot() int ModelWidget::xRot()
@ -188,6 +189,8 @@ void ModelWidget::mousePressEvent(QMouseEvent *event)
m_moveStartPos = mapToParent(event->pos()); m_moveStartPos = mapToParent(event->pos());
m_moveStartGeometry = geometry(); m_moveStartGeometry = geometry();
m_moveStarted = true; m_moveStarted = true;
m_meshBinder.hideWireframes();
update();
} }
} }
} }
@ -198,6 +201,8 @@ void ModelWidget::mouseReleaseEvent(QMouseEvent *event)
m_graphicsFunctions->mouseRelease(event); m_graphicsFunctions->mouseRelease(event);
if (m_moveStarted) { if (m_moveStarted) {
m_moveStarted = false; m_moveStarted = false;
m_meshBinder.showWireframes();
update();
} }
} }
@ -210,15 +215,17 @@ void ModelWidget::mouseMoveEvent(QMouseEvent *event)
int dy = event->y() - m_lastPos.y(); int dy = event->y() - m_lastPos.y();
if (event->buttons() & Qt::MidButton) { if (event->buttons() & Qt::MidButton) {
if (m_moveStarted) { if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
QRect rect = m_moveStartGeometry; if (m_moveStarted) {
QPoint pos = mapToParent(event->pos()); QRect rect = m_moveStartGeometry;
rect.translate(pos.x() - m_moveStartPos.x(), pos.y() - m_moveStartPos.y()); QPoint pos = mapToParent(event->pos());
setGeometry(rect); rect.translate(pos.x() - m_moveStartPos.x(), pos.y() - m_moveStartPos.y());
setGeometry(rect);
}
} else {
setXRotation(m_xRot - 8 * dy);
setYRotation(m_yRot - 8 * dx);
} }
} else if (event->buttons() & Qt::RightButton) {
setXRotation(m_xRot - 8 * dy);
setYRotation(m_yRot - 8 * dx);
} }
m_lastPos = event->pos(); m_lastPos = event->pos();
} }

View File

@ -385,6 +385,10 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
connect(m_document, &SkeletonDocument::skeletonChanged, this, &SkeletonDocumentWindow::documentChanged); connect(m_document, &SkeletonDocument::skeletonChanged, this, &SkeletonDocumentWindow::documentChanged);
connect(m_document, &SkeletonDocument::turnaroundChanged, this, &SkeletonDocumentWindow::documentChanged); connect(m_document, &SkeletonDocument::turnaroundChanged, this, &SkeletonDocumentWindow::documentChanged);
connect(m_modelWidget, &ModelWidget::customContextMenuRequested, [=](const QPoint &pos) {
graphicsWidget->showContextMenu(graphicsWidget->mapFromGlobal(m_modelWidget->mapToGlobal(pos)));
});
connect(this, &SkeletonDocumentWindow::initialized, m_document, &SkeletonDocument::uiReady); connect(this, &SkeletonDocumentWindow::initialized, m_document, &SkeletonDocument::uiReady);
} }

View File

@ -320,14 +320,6 @@ void SkeletonGraphicsWidget::mousePressEvent(QMouseEvent *event)
return; return;
} }
m_mouseEventFromSelf = false; m_mouseEventFromSelf = false;
if (event->button() == Qt::LeftButton) {
if (SkeletonDocumentEditMode::Select == m_document->editMode) {
if (!m_rangeSelectionStarted) {
m_rangeSelectionStartPos = mouseEventScenePos(event);
m_rangeSelectionStarted = true;
}
}
}
} }
void SkeletonGraphicsWidget::mouseDoubleClickEvent(QMouseEvent *event) void SkeletonGraphicsWidget::mouseDoubleClickEvent(QMouseEvent *event)
@ -660,6 +652,15 @@ bool SkeletonGraphicsWidget::mousePress(QMouseEvent *event)
//} //}
} }
} }
if (event->button() == Qt::LeftButton) {
if (SkeletonDocumentEditMode::Select == m_document->editMode) {
if (!m_rangeSelectionStarted) {
m_rangeSelectionStartPos = mouseEventScenePos(event);
m_rangeSelectionStarted = true;
}
}
}
return false; return false;
} }