Commit 04d09a3b authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

ajout setGLWidgetMouseTracking(bool)

parent 5bb529c8
...@@ -55,10 +55,13 @@ class SimpleQT : public QMainWindow ...@@ -55,10 +55,13 @@ class SimpleQT : public QMainWindow
public: public:
SimpleQT(); SimpleQT();
SimpleQT(const SimpleQT&) ; SimpleQT(const SimpleQT&) ;
virtual ~SimpleQT(); virtual ~SimpleQT();
void operator=(const SimpleQT& v) ;
/** /**
* set the main widget of the dock * set the main widget of the dock
*/ */
...@@ -137,6 +140,13 @@ public: ...@@ -137,6 +140,13 @@ public:
// void contextMenuEvent(QContextMenuEvent *event); // void contextMenuEvent(QContextMenuEvent *event);
/**
* set mouse tracking on the GLWidget
* if true : mouseMove events are generated for each mouse move
* if false : mouseMove events are only generated when a button is pressed
*/
void setGLWidgetMouseTracking(bool b);
protected: protected:
GLWidget *m_glWidget; GLWidget *m_glWidget;
...@@ -173,8 +183,6 @@ protected: ...@@ -173,8 +183,6 @@ protected:
void keyReleaseEvent(QKeyEvent *e); void keyReleaseEvent(QKeyEvent *e);
public: public:
void operator=(const SimpleQT& v) ;
/** /**
* set width and pos center of object to draw * set width and pos center of object to draw
*/ */
...@@ -317,7 +325,7 @@ public: ...@@ -317,7 +325,7 @@ public:
/** /**
* end of program, some things to clean ? * end of program, some things to clean ?
*/ */
virtual void cb_exit() { } virtual void cb_exit() {}
/** /**
* Ask to Qt to update the GL widget. * Ask to Qt to update the GL widget.
...@@ -330,7 +338,6 @@ public: ...@@ -330,7 +338,6 @@ public:
*/ */
void updateGLMatrices(); void updateGLMatrices();
/** /**
* apply rotation to transformation matrix * apply rotation to transformation matrix
*/ */
...@@ -351,7 +358,6 @@ public: ...@@ -351,7 +358,6 @@ public:
*/ */
void pushTransfoMatrix(); void pushTransfoMatrix();
/** /**
* pop the transfo matrix from stack * pop the transfo matrix from stack
*/ */
......
...@@ -40,8 +40,7 @@ namespace Utils ...@@ -40,8 +40,7 @@ namespace Utils
namespace QT namespace QT
{ {
SimpleQT::SimpleQT(): SimpleQT::SimpleQT() : m_dock(NULL)
m_dock(NULL)
{ {
m_glWidget = new GLWidget(this); m_glWidget = new GLWidget(this);
setCentralWidget(m_glWidget); setCentralWidget(m_glWidget);
...@@ -131,7 +130,8 @@ SimpleQT::~SimpleQT() ...@@ -131,7 +130,8 @@ SimpleQT::~SimpleQT()
delete m_glWidget; // ?? delete m_glWidget; // ??
} }
void SimpleQT::operator=(const SimpleQT& sqt) { void SimpleQT::operator=(const SimpleQT& sqt)
{
m_glWidget = new GLWidget(this); m_glWidget = new GLWidget(this);
setCentralWidget(m_glWidget) ; setCentralWidget(m_glWidget) ;
...@@ -152,42 +152,48 @@ void SimpleQT::operator=(const SimpleQT& sqt) { ...@@ -152,42 +152,48 @@ void SimpleQT::operator=(const SimpleQT& sqt) {
m_trans_z = sqt.m_trans_z ; m_trans_z = sqt.m_trans_z ;
} }
std::string SimpleQT::selectFile(const std::string& title, const std::string& dir, const std::string& filters) void SimpleQT::setDock(QDockWidget *dock)
{ {
QString fileName = QFileDialog::getOpenFileName(this, tr(title.c_str()), tr(dir.c_str()), tr(filters.c_str()), 0, 0); m_dock = dock;
return fileName.toStdString(); addDockWidget(Qt::RightDockWidgetArea, m_dock);
m_dock->show();
} }
std::string SimpleQT::selectFileSave(const std::string& title, const std::string& dir, const std::string& filters) QDockWidget* SimpleQT::dockWidget()
{ {
QString fileName = QFileDialog::getSaveFileName(this, tr(title.c_str()), tr(dir.c_str()), tr(filters.c_str()), 0, 0); return m_dock;
return fileName.toStdString();
} }
void SimpleQT::cb_about_cgogn() void SimpleQT::setCallBack( const QObject* sender, const char* signal, const char* method)
{ {
QString str("CGoGN:\nCombinatorial and Geometric modeling\n" connect(sender, signal, this, method);
"with Generic N-dimensional Maps\n"
"Web site: https://cgogn.u-strasbg.fr \n"
"Contact information: cgogn@unistra.fr");
QMessageBox::about(this, tr("About CGoGN"), str);
} }
void SimpleQT::cb_about() void SimpleQT::windowTitle(const char* windowTitle)
{ {
QMessageBox::about(this, tr("About App"), m_helpString.c_str()); setWindowTitle(tr(windowTitle));
} }
void SimpleQT::setHelpMsg(const std::string& msg) void SimpleQT::dockTitle(const char* dockTitle)
{ {
m_helpString = msg; if (m_dock)
m_dock->setWindowTitle(tr(dockTitle));
} }
void SimpleQT::glMousePosition(int& x, int& y) void SimpleQT::statusMsg(const char* msg, int timeoutms)
{ {
QPoint xy = m_glWidget->mapFromGlobal(QCursor::pos()); if (msg)
x = xy.x(); {
y = m_glWidget->getHeight() - xy.y(); QString message = tr(msg);
statusBar()->showMessage(message,timeoutms);
}
else
{
if (statusBar()->isHidden())
statusBar()->show();
else
statusBar()->hide();
}
} }
QDockWidget* SimpleQT::addEmptyDock() QDockWidget* SimpleQT::addEmptyDock()
...@@ -233,39 +239,30 @@ void SimpleQT::toggleVisibilityConsole() ...@@ -233,39 +239,30 @@ void SimpleQT::toggleVisibilityConsole()
m_dockConsole->hide(); m_dockConsole->hide();
} }
void SimpleQT::windowTitle(const char* windowTitle) void SimpleQT::add_menu_entry(const std::string label, const char* method)
{ {
setWindowTitle(tr(windowTitle)); QAction * action = new QAction(tr(label.c_str()), this);
connect(action, SIGNAL(triggered()), this, method);
m_appMenu->addAction(action);
} }
void SimpleQT::dockTitle(const char* dockTitle) void SimpleQT::init_app_menu()
{ {
if (m_dock) m_appMenu->clear();
m_dock->setWindowTitle(tr(dockTitle));
} }
void SimpleQT::statusMsg(const char* msg, int timeoutms) void SimpleQT::setHelpMsg(const std::string& msg)
{ {
if (msg) m_helpString = msg;
{
QString message = tr(msg);
statusBar()->showMessage(message,timeoutms);
}
else
{
if (statusBar()->isHidden())
statusBar()->show();
else
statusBar()->hide();
}
} }
void SimpleQT::setCallBack( const QObject* sender, const char* signal, const char* method) void SimpleQT::setGLWidgetMouseTracking(bool b)
{ {
connect(sender, signal, this, method); m_glWidget->setMouseTracking(b);
} }
void SimpleQT::closeEvent(QCloseEvent *event) { void SimpleQT::closeEvent(QCloseEvent *event)
{
m_glWidget->closeEvent(event) ; m_glWidget->closeEvent(event) ;
QWidget::closeEvent(event) ; QWidget::closeEvent(event) ;
} }
...@@ -283,7 +280,6 @@ void SimpleQT::keyPressEvent(QKeyEvent *e) ...@@ -283,7 +280,6 @@ void SimpleQT::keyPressEvent(QKeyEvent *e)
toggleVisibilityDock(); toggleVisibilityDock();
} }
if (e->key() == Qt::Key_Escape) if (e->key() == Qt::Key_Escape)
close(); close();
else else
...@@ -297,51 +293,53 @@ void SimpleQT::keyReleaseEvent(QKeyEvent *e) ...@@ -297,51 +293,53 @@ void SimpleQT::keyReleaseEvent(QKeyEvent *e)
m_glWidget->keyReleaseEvent(e); m_glWidget->keyReleaseEvent(e);
} }
void SimpleQT::setDock(QDockWidget *dock) void SimpleQT::glMousePosition(int& x, int& y)
{ {
m_dock = dock; QPoint xy = m_glWidget->mapFromGlobal(QCursor::pos());
addDockWidget(Qt::RightDockWidgetArea, m_dock); x = xy.x();
m_dock->show(); y = m_glWidget->getHeight() - xy.y();
} }
QDockWidget* SimpleQT::dockWidget() GLfloat SimpleQT::getOrthoScreenRay(int x, int y, Geom::Vec3f& rayA, Geom::Vec3f& rayB, int radius)
{ {
return m_dock; // get Z from depth buffer
} // int yy = m_glWidget->getHeight() - y;
int yy = y;
GLfloat depth;
glReadPixels(x, yy, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
void SimpleQT::updateGL() glm::i32vec4 viewport;
{ glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
m_glWidget->updateGL();
}
void SimpleQT::updateGLMatrices() glm::vec3 win(x, yy, 0.0f);
{
m_glWidget->modelModified();
m_glWidget->updateGL();
}
void SimpleQT::cb_updateMatrix() glm::vec3 P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport);
{
if (GLSLShader::CURRENT_OGL_VERSION == 1)
{
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(glm::value_ptr(m_projection_matrix));
glMatrixMode(GL_MODELVIEW); rayA[0] = P[0];
glLoadMatrixf(glm::value_ptr(m_modelView_matrix)); rayA[1] = P[1];
} rayA[2] = P[2];
else
{ win[2] = depth;
for(std::set< std::pair<void*, GLSLShader*> >::iterator it = GLSLShader::m_registeredShaders.begin();
it != GLSLShader::m_registeredShaders.end(); P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport);
++it) rayB[0] = P[0];
{ rayB[1] = P[1];
if ((it->first == NULL) || (it->first == this)) rayB[2] = P[2];
{
it->second->updateMatrices(m_projection_matrix, m_modelView_matrix); if (depth == 1.0f) // depth vary in [0-1]
} depth = 0.5f;
}
} win[0] += radius;
P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport);
Geom::Vec3f Q;
Q[0] = P[0];
Q[1] = P[1];
Q[2] = P[2];
// compute & return distance
Q -= rayB;
return float(Q.norm());
} }
void SimpleQT::synchronize(SimpleQT* sqt) void SimpleQT::synchronize(SimpleQT* sqt)
...@@ -365,21 +363,6 @@ void SimpleQT::synchronize(SimpleQT* sqt) ...@@ -365,21 +363,6 @@ void SimpleQT::synchronize(SimpleQT* sqt)
m_glWidget->updateGL(); m_glWidget->updateGL();
} }
void SimpleQT::add_menu_entry(const std::string label, const char* method)
{
QAction * action = new QAction(tr(label.c_str()), this);
connect(action, SIGNAL(triggered()), this, method);
m_appMenu->addAction(action);
}
/**
* initialize app menu
*/
void SimpleQT::init_app_menu()
{
m_appMenu->clear();
}
void SimpleQT::registerShader(GLSLShader* ptr) void SimpleQT::registerShader(GLSLShader* ptr)
{ {
GLSLShader::registerShader(this, ptr) ; GLSLShader::registerShader(this, ptr) ;
...@@ -390,48 +373,40 @@ void SimpleQT::unregisterShader(GLSLShader* ptr) ...@@ -390,48 +373,40 @@ void SimpleQT::unregisterShader(GLSLShader* ptr)
GLSLShader::unregisterShader(this, ptr) ; GLSLShader::unregisterShader(this, ptr) ;
} }
GLfloat SimpleQT::getOrthoScreenRay(int x, int y, Geom::Vec3f& rayA, Geom::Vec3f& rayB, int radius) void SimpleQT::cb_updateMatrix()
{ {
// get Z from depth buffer if (GLSLShader::CURRENT_OGL_VERSION == 1)
// int yy = m_glWidget->getHeight() - y; {
int yy = y; glMatrixMode(GL_PROJECTION);
GLfloat depth; glLoadMatrixf(glm::value_ptr(m_projection_matrix));
glReadPixels(x, yy, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
glm::i32vec4 viewport;
glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
glm::vec3 win(x, yy, 0.0f);
glm::vec3 P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport);
rayA[0] = P[0];
rayA[1] = P[1];
rayA[2] = P[2];
win[2] = depth;
P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport);
rayB[0] = P[0];
rayB[1] = P[1];
rayB[2] = P[2];
if (depth == 1.0f) // depth vary in [0-1]
depth = 0.5f;
win[0] += radius;
P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport); glMatrixMode(GL_MODELVIEW);
Geom::Vec3f Q; glLoadMatrixf(glm::value_ptr(m_modelView_matrix));
Q[0] = P[0]; }
Q[1] = P[1]; else
Q[2] = P[2]; {
for(std::set< std::pair<void*, GLSLShader*> >::iterator it = GLSLShader::m_registeredShaders.begin();
it != GLSLShader::m_registeredShaders.end();
++it)
{
if ((it->first == NULL) || (it->first == this))
{
it->second->updateMatrices(m_projection_matrix, m_modelView_matrix);
}
}
}
}
// compute & return distance void SimpleQT::updateGL()
Q -= rayB; {
return float(Q.norm()); m_glWidget->updateGL();
} }
void SimpleQT::updateGLMatrices()
{
m_glWidget->modelModified();
m_glWidget->updateGL();
}
void SimpleQT::transfoRotate(float angle, float x, float y, float z) void SimpleQT::transfoRotate(float angle, float x, float y, float z)
{ {
...@@ -462,6 +437,31 @@ bool SimpleQT::popTransfoMatrix() ...@@ -462,6 +437,31 @@ bool SimpleQT::popTransfoMatrix()
return true; return true;
} }
std::string SimpleQT::selectFile(const std::string& title, const std::string& dir, const std::string& filters)
{
QString fileName = QFileDialog::getOpenFileName(this, tr(title.c_str()), tr(dir.c_str()), tr(filters.c_str()), 0, 0);
return fileName.toStdString();
}
std::string SimpleQT::selectFileSave(const std::string& title, const std::string& dir, const std::string& filters)
{
QString fileName = QFileDialog::getSaveFileName(this, tr(title.c_str()), tr(dir.c_str()), tr(filters.c_str()), 0, 0);
return fileName.toStdString();
}
void SimpleQT::cb_about_cgogn()
{
QString str("CGoGN:\nCombinatorial and Geometric modeling\n"
"with Generic N-dimensional Maps\n"
"Web site: https://cgogn.u-strasbg.fr \n"
"Contact information: cgogn@unistra.fr");
QMessageBox::about(this, tr("About CGoGN"), str);
}
void SimpleQT::cb_about()
{
QMessageBox::about(this, tr("About App"), m_helpString.c_str());
}
} // namespace QT } // namespace QT
......
...@@ -294,6 +294,8 @@ void GLWidget::mouseMoveEvent(QMouseEvent* event) ...@@ -294,6 +294,8 @@ void GLWidget::mouseMoveEvent(QMouseEvent* event)
void GLWidget::wheelEvent(QWheelEvent* event) void GLWidget::wheelEvent(QWheelEvent* event)
{ {
if (!(m_state_modifier & ( Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)))
{
float wl = -0.05f * FAR_PLANE / foc; float wl = -0.05f * FAR_PLANE / foc;
if (event->delta() > 0) if (event->delta() > 0)
...@@ -303,6 +305,7 @@ void GLWidget::wheelEvent(QWheelEvent* event) ...@@ -303,6 +305,7 @@ void GLWidget::wheelEvent(QWheelEvent* event)
newModel = 1; newModel = 1;
updateGL(); updateGL();
}
if (m_cbs) if (m_cbs)
m_cbs->cb_wheelEvent(event->delta(), event->x(), getHeight() - event->y()); m_cbs->cb_wheelEvent(event->delta(), event->x(), getHeight() - event->y());
...@@ -339,27 +342,27 @@ void GLWidget::keyReleaseEvent(QKeyEvent *event) ...@@ -339,27 +342,27 @@ void GLWidget::keyReleaseEvent(QKeyEvent *event)
int k = event->key(); int k = event->key();
// align on axis // align on axis
if ((k=='Z') && (event->modifiers() & Qt::ShiftModifier)) if ((k == 'Z') && (event->modifiers() & Qt::ShiftModifier))
{ {
float Z[3]={0.0f,0.0f,1.0f}; float Z[3] = { 0.0f, 0.0f, 1.0f };
axis_to_quat(Z,0.0f,m_cbs->curquat()); axis_to_quat(Z, 0.0f, m_cbs->curquat());
newModel=1; newModel = 1;
updateGL(); updateGL();
} }
if ((k=='Y') && (event->modifiers() & Qt::ShiftModifier)) if ((k == 'Y') && (event->modifiers() & Qt::ShiftModifier))
{ {
float X[3]={1.0f,0.0f,0.0f}; float X[3] = { 1.0f, 0.0f, 0.0f };
axis_to_quat(X,M_PI/2.0f,m_cbs->curquat()); axis_to_quat(X, M_PI / 2.0f, m_cbs->curquat());
newModel=1; newModel = 1;
updateGL(); updateGL();
} }
if ((k=='X') && (event->modifiers() & Qt::ShiftModifier)) if ((k == 'X') && (event->modifiers() & Qt::ShiftModifier))
{ {
float Y[3]={0.0f,1.0f,0.0f}; float Y[3] = { 0.0f, 1.0f, 0.0f };
axis_to_quat(Y,-M_PI/2.0f,m_cbs->curquat()); axis_to_quat(Y, -M_PI / 2.0f, m_cbs->curquat());
newModel=1; newModel = 1;
updateGL(); updateGL();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment