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

@ -9,7 +9,7 @@ ModelMeshBinder::ModelMeshBinder() :
m_renderEdgeVertexCount(0),
m_mesh(NULL),
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) {
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoEdge);
glDrawArrays(GL_LINES, 0, m_renderEdgeVertexCount);
@ -124,12 +124,12 @@ void ModelMeshBinder::cleanup()
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 paint();
void cleanup();
void showFrames();
void hideFrames();
void showWireframes();
void hideWireframes();
private:
QOpenGLVertexArrayObject m_vaoTriangle;
QOpenGLBuffer m_vboTriangle;
@ -28,7 +28,7 @@ private:
int m_renderTriangleVertexCount;
int m_renderEdgeVertexCount;
bool m_meshUpdated;
bool m_showFrames;
bool m_showWireframes;
};
#endif

View File

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

View File

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

View File

@ -385,6 +385,10 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
connect(m_document, &SkeletonDocument::skeletonChanged, 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);
}

View File

@ -320,14 +320,6 @@ void SkeletonGraphicsWidget::mousePressEvent(QMouseEvent *event)
return;
}
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)
@ -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;
}