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

ajout setGLWidgetMouseTracking(bool)

parent 5bb529c8
......@@ -55,10 +55,13 @@ class SimpleQT : public QMainWindow
public:
SimpleQT();
SimpleQT(const SimpleQT&) ;
virtual ~SimpleQT();
void operator=(const SimpleQT& v) ;
/**
* set the main widget of the dock
*/
......@@ -137,6 +140,13 @@ public:
// 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:
GLWidget *m_glWidget;
......@@ -173,8 +183,6 @@ protected:
void keyReleaseEvent(QKeyEvent *e);
public:
void operator=(const SimpleQT& v) ;
/**
* set width and pos center of object to draw
*/
......@@ -317,7 +325,7 @@ public:
/**
* end of program, some things to clean ?
*/
virtual void cb_exit() { }
virtual void cb_exit() {}
/**
* Ask to Qt to update the GL widget.
......@@ -330,7 +338,6 @@ public:
*/
void updateGLMatrices();
/**
* apply rotation to transformation matrix
*/
......@@ -351,7 +358,6 @@ public:
*/
void pushTransfoMatrix();
/**
* pop the transfo matrix from stack
*/
......
......@@ -40,8 +40,7 @@ namespace Utils
namespace QT
{
SimpleQT::SimpleQT():
m_dock(NULL)
SimpleQT::SimpleQT() : m_dock(NULL)
{
m_glWidget = new GLWidget(this);
setCentralWidget(m_glWidget);
......@@ -131,7 +130,8 @@ SimpleQT::~SimpleQT()
delete m_glWidget; // ??
}
void SimpleQT::operator=(const SimpleQT& sqt) {
void SimpleQT::operator=(const SimpleQT& sqt)
{
m_glWidget = new GLWidget(this);
setCentralWidget(m_glWidget) ;
......@@ -152,42 +152,48 @@ void SimpleQT::operator=(const SimpleQT& sqt) {
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);
return fileName.toStdString();
m_dock = dock;
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 fileName.toStdString();
return m_dock;
}
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"
"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);
connect(sender, signal, this, method);
}
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());
x = xy.x();
y = m_glWidget->getHeight() - xy.y();
if (msg)
{
QString message = tr(msg);
statusBar()->showMessage(message,timeoutms);
}
else
{
if (statusBar()->isHidden())
statusBar()->show();
else
statusBar()->hide();
}
}
QDockWidget* SimpleQT::addEmptyDock()
......@@ -233,39 +239,30 @@ void SimpleQT::toggleVisibilityConsole()
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_dock->setWindowTitle(tr(dockTitle));
m_appMenu->clear();
}
void SimpleQT::statusMsg(const char* msg, int timeoutms)
void SimpleQT::setHelpMsg(const std::string& msg)
{
if (msg)
{
QString message = tr(msg);
statusBar()->showMessage(message,timeoutms);
}
else
{
if (statusBar()->isHidden())
statusBar()->show();
else
statusBar()->hide();
}
m_helpString = msg;
}
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) ;
QWidget::closeEvent(event) ;
}
......@@ -283,7 +280,6 @@ void SimpleQT::keyPressEvent(QKeyEvent *e)
toggleVisibilityDock();
}
if (e->key() == Qt::Key_Escape)
close();
else
......@@ -297,51 +293,53 @@ void SimpleQT::keyReleaseEvent(QKeyEvent *e)
m_glWidget->keyReleaseEvent(e);
}
void SimpleQT::setDock(QDockWidget *dock)
void SimpleQT::glMousePosition(int& x, int& y)
{
m_dock = dock;
addDockWidget(Qt::RightDockWidgetArea, m_dock);
m_dock->show();
QPoint xy = m_glWidget->mapFromGlobal(QCursor::pos());
x = xy.x();
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()
{
m_glWidget->updateGL();
}
glm::i32vec4 viewport;
glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
void SimpleQT::updateGLMatrices()
{
m_glWidget->modelModified();
m_glWidget->updateGL();
}
glm::vec3 win(x, yy, 0.0f);
void SimpleQT::cb_updateMatrix()
{
if (GLSLShader::CURRENT_OGL_VERSION == 1)
{
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(glm::value_ptr(m_projection_matrix));
glm::vec3 P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(glm::value_ptr(m_modelView_matrix));
}
else
{
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);
}
}
}
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);
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)
......@@ -365,21 +363,6 @@ void SimpleQT::synchronize(SimpleQT* sqt)
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)
{
GLSLShader::registerShader(this, ptr) ;
......@@ -390,48 +373,40 @@ void SimpleQT::unregisterShader(GLSLShader* 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
// int yy = m_glWidget->getHeight() - y;
int yy = y;
GLfloat depth;
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;
if (GLSLShader::CURRENT_OGL_VERSION == 1)
{
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(glm::value_ptr(m_projection_matrix));
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];
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(glm::value_ptr(m_modelView_matrix));
}
else
{
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
Q -= rayB;
return float(Q.norm());
void SimpleQT::updateGL()
{
m_glWidget->updateGL();
}
void SimpleQT::updateGLMatrices()
{
m_glWidget->modelModified();
m_glWidget->updateGL();
}
void SimpleQT::transfoRotate(float angle, float x, float y, float z)
{
......@@ -462,6 +437,31 @@ bool SimpleQT::popTransfoMatrix()
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
......
......@@ -294,15 +294,18 @@ void GLWidget::mouseMoveEvent(QMouseEvent* event)
void GLWidget::wheelEvent(QWheelEvent* event)
{
float wl = -0.05f * FAR_PLANE / foc;
if (!(m_state_modifier & ( Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)))
{
float wl = -0.05f * FAR_PLANE / foc;
if (event->delta() > 0)
m_cbs->trans_z() += wl;
else
m_cbs->trans_z() -= wl;
if (event->delta() > 0)
m_cbs->trans_z() += wl;
else
m_cbs->trans_z() -= wl;
newModel = 1;
updateGL();
newModel = 1;
updateGL();
}
if (m_cbs)
m_cbs->cb_wheelEvent(event->delta(), event->x(), getHeight() - event->y());
......@@ -339,27 +342,27 @@ void GLWidget::keyReleaseEvent(QKeyEvent *event)
int k = event->key();
// 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};
axis_to_quat(Z,0.0f,m_cbs->curquat());
newModel=1;
float Z[3] = { 0.0f, 0.0f, 1.0f };
axis_to_quat(Z, 0.0f, m_cbs->curquat());
newModel = 1;
updateGL();
}
if ((k=='Y') && (event->modifiers() & Qt::ShiftModifier))
if ((k == 'Y') && (event->modifiers() & Qt::ShiftModifier))
{
float X[3]={1.0f,0.0f,0.0f};
axis_to_quat(X,M_PI/2.0f,m_cbs->curquat());
newModel=1;
float X[3] = { 1.0f, 0.0f, 0.0f };
axis_to_quat(X, M_PI / 2.0f, m_cbs->curquat());
newModel = 1;
updateGL();
}
if ((k=='X') && (event->modifiers() & Qt::ShiftModifier))
if ((k == 'X') && (event->modifiers() & Qt::ShiftModifier))
{
float Y[3]={0.0f,1.0f,0.0f};
axis_to_quat(Y,-M_PI/2.0f,m_cbs->curquat());
newModel=1;
float Y[3] = { 0.0f, 1.0f, 0.0f };
axis_to_quat(Y, -M_PI / 2.0f, m_cbs->curquat());
newModel = 1;
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