Commit fcec3833 authored by Mathieu Faverge's avatar Mathieu Faverge

Avoid to refresh all the time, but do it only when necessary

parent 3a19369a
......@@ -40,25 +40,18 @@ static void drawTemporarySelection(int x, int y, int dx, int dy)
}
MatrixGLWidget::MatrixGLWidget(QWidget* parent, symbol_matrix_t* matrix, QLabel* label)
:
#ifdef USE_QT5
: QOpenGLWidget(parent)
QOpenGLWidget(parent)
#else
: QGLWidget(parent)
QGLWidget(parent)
#endif
, m_label(label)
, m_frameCount(0)
{
this->setFixedSize(MATRIX_WINDOW_LENGTH, MATRIX_WINDOW_HEIGHT);
m_zooming = new Zooming(matrix);
#ifdef USE_QT5
connect(&m_updateTimer, &QTimer::timeout, this, &MatrixGLWidget::updateTimer);
#else
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTimer()));
#endif
m_updateTimer.start(1000 / 60);
m_zooming = new Zooming( matrix );
m_qtToGLWidthCoeff = 1.f;
m_qtToGLHeightCoeff = 1.f;
......@@ -157,13 +150,6 @@ void MatrixGLWidget::paintGL()
m_frameCount++;
}
void MatrixGLWidget::updateTimer()
{
// Need to do this because the connect function cannot
// differenciate overloaded cases of update
update();
}
void MatrixGLWidget::keyPressEvent(QKeyEvent *keyEvent)
{
switch (keyEvent->key())
......@@ -208,12 +194,15 @@ void MatrixGLWidget::mouseMoveEvent(QMouseEvent* mouseEvent)
m_tempSelectionY = m_mouseYClicked;
m_tempSelectionDx = glPosX - m_mouseXClicked;
m_tempSelectionDy = glPosY - m_mouseYClicked;
update();
}
}
void MatrixGLWidget::mouseReleaseEvent(QMouseEvent* mouseEvent)
{
if (m_mouseXClicked != -1 && m_mouseYClicked != -1)
if ( (m_mouseXClicked != -1) &&
(m_mouseYClicked != -1) )
{
int xmin, xmax, ymin, ymax;
int glPosX = mouseEvent->x() * m_qtToGLWidthCoeff;
......@@ -259,15 +248,17 @@ void MatrixGLWidget::mouseReleaseEvent(QMouseEvent* mouseEvent)
dX = dX * m_camera.m_cameraDx;
dY = dY * m_camera.m_cameraDy;
m_drawTempSelection = 0;
// Return if in the upper triangular part
if ( (Y + dY) < X )
{
update();
return;
}
// Position is valid, we save it
m_savedPositions.push(m_camera);
m_drawTempSelection = 0;
m_camera.m_cameraX = X;
m_camera.m_cameraY = Y;
......@@ -283,6 +274,7 @@ void MatrixGLWidget::mouseReleaseEvent(QMouseEvent* mouseEvent)
void MatrixGLWidget::refreshCamera()
{
m_zooming->move(m_camera.m_cameraX, m_camera.m_cameraX + m_camera.m_cameraDx,
m_camera.m_cameraY, m_camera.m_cameraY + m_camera.m_cameraDy);
m_zooming->move( m_camera.m_cameraX, m_camera.m_cameraX + m_camera.m_cameraDx,
m_camera.m_cameraY, m_camera.m_cameraY + m_camera.m_cameraDy );
update();
}
......@@ -52,14 +52,9 @@ private:
private:
void refreshCamera();
private slots:
/* Helpers */
void updateTimer();
private:
uint32_t m_frameCount;
QTime m_time;
QTimer m_updateTimer;
QLabel* m_label;
char m_fpsString[256];
......
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