[F] React on mouse pressing ig view only.

pull/1981/head
smalcom 2018-05-24 13:05:50 +03:00
parent f56432f713
commit fd7f07068c
2 changed files with 40 additions and 25 deletions

View File

@ -128,40 +128,54 @@ void MainWindow::LogError(const QString& pMessage)
void MainWindow::mousePressEvent(QMouseEvent* pEvent) void MainWindow::mousePressEvent(QMouseEvent* pEvent)
{ {
if(pEvent->button() & Qt::LeftButton) const QPoint ms_pt = pEvent->pos();
mPosition_Pressed_LMB = pEvent->pos();
else if(pEvent->button() & Qt::RightButton) // Check if GLView is pointed.
mPosition_Pressed_RMB = pEvent->pos(); if(childAt(ms_pt) == mGLView)
{
mPosition_Pressed_Valid = true;
if(pEvent->button() & Qt::LeftButton)
mPosition_Pressed_LMB = ms_pt;
else if(pEvent->button() & Qt::RightButton)
mPosition_Pressed_RMB = ms_pt;
}
else
{
mPosition_Pressed_Valid = false;
}
} }
void MainWindow::mouseMoveEvent(QMouseEvent* pEvent) void MainWindow::mouseMoveEvent(QMouseEvent* pEvent)
{ {
if(pEvent->buttons() & Qt::LeftButton) if(mPosition_Pressed_Valid)
{ {
GLfloat dx = 180 * GLfloat(pEvent->x() - mPosition_Pressed_LMB.x()) / mGLView->width(); if(pEvent->buttons() & Qt::LeftButton)
GLfloat dy = 180 * GLfloat(pEvent->y() - mPosition_Pressed_LMB.y()) / mGLView->height(); {
GLfloat dx = 180 * GLfloat(pEvent->x() - mPosition_Pressed_LMB.x()) / mGLView->width();
GLfloat dy = 180 * GLfloat(pEvent->y() - mPosition_Pressed_LMB.y()) / mGLView->height();
if(pEvent->modifiers() & Qt::ShiftModifier) if(pEvent->modifiers() & Qt::ShiftModifier)
mGLView->Camera_RotateScene(dy, 0, dx);// Rotate around oX and oZ axises. mGLView->Camera_RotateScene(dy, 0, dx);// Rotate around oX and oZ axises.
else else
mGLView->Camera_RotateScene(dy, dx, 0);// Rotate around oX and oY axises. mGLView->Camera_RotateScene(dy, dx, 0);// Rotate around oX and oY axises.
mGLView->updateGL(); mGLView->updateGL();
mPosition_Pressed_LMB = pEvent->pos(); mPosition_Pressed_LMB = pEvent->pos();
} }
if(pEvent->buttons() & Qt::RightButton) if(pEvent->buttons() & Qt::RightButton)
{ {
GLfloat dx = 180 * GLfloat(pEvent->x() - mPosition_Pressed_RMB.x()) / mGLView->width(); GLfloat dx = 180 * GLfloat(pEvent->x() - mPosition_Pressed_RMB.x()) / mGLView->width();
GLfloat dy = 180 * GLfloat(pEvent->y() - mPosition_Pressed_RMB.y()) / mGLView->height(); GLfloat dy = 180 * GLfloat(pEvent->y() - mPosition_Pressed_RMB.y()) / mGLView->height();
if(pEvent->modifiers() & Qt::ShiftModifier) if(pEvent->modifiers() & Qt::ShiftModifier)
mGLView->Camera_Rotate(dy, 0, dx);// Rotate around oX and oZ axises. mGLView->Camera_Rotate(dy, 0, dx);// Rotate around oX and oZ axises.
else else
mGLView->Camera_Rotate(dy, dx, 0);// Rotate around oX and oY axises. mGLView->Camera_Rotate(dy, dx, 0);// Rotate around oX and oY axises.
mGLView->updateGL(); mGLView->updateGL();
mPosition_Pressed_RMB = pEvent->pos(); mPosition_Pressed_RMB = pEvent->pos();
}
} }
} }
@ -198,7 +212,7 @@ GLfloat step;
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow), : QMainWindow(parent), ui(new Ui::MainWindow),
mScene(nullptr) mScene(nullptr), mPosition_Pressed_Valid(false)
{ {
using namespace Assimp; using namespace Assimp;

View File

@ -36,6 +36,7 @@ private:
CLoggerView* mLoggerView;///< Pointer to logging object. CLoggerView* mLoggerView;///< Pointer to logging object.
Assimp::Importer mImporter;///< Assimp importer. Assimp::Importer mImporter;///< Assimp importer.
const aiScene* mScene;///< Pointer to loaded scene (\ref aiScene). const aiScene* mScene;///< Pointer to loaded scene (\ref aiScene).
bool mPosition_Pressed_Valid;///< Mouse button pressed on GLView.
QPoint mPosition_Pressed_LMB;///< Position where was pressed left mouse button. QPoint mPosition_Pressed_LMB;///< Position where was pressed left mouse button.
QPoint mPosition_Pressed_RMB;///< Position where was pressed right mouse button. QPoint mPosition_Pressed_RMB;///< Position where was pressed right mouse button.