Added zoom changeable with key presses (just the option/event management, zoom not working yet).

This commit is contained in:
Tats
2014-10-18 10:04:14 +00:00
parent 40c7dc039b
commit b6b4173866
2 changed files with 26 additions and 5 deletions
+21 -5
View File
@@ -30,10 +30,23 @@ MapperGLCanvas::MapperGLCanvas(MainWindow* mainWindow, QWidget* parent, const QG
_shapeGrabbed(false), // comment out?
_shapeFirstGrab(false), // comment out?
_displayControls(true),
_stickyVertices(true)
_stickyVertices(true),
_zoomFactor(8)
{
}
void MapperGLCanvas::setZoomFactor(int zoom)
{
qDebug() << zoom << endl;
if (zoom < 1)
zoom = 1; // the closest we can get is 1:1
if (zoom != _zoomFactor) {
_zoomFactor = zoom;
update();
updateGeometry();
}
}
void MapperGLCanvas::initializeGL()
{
//qDebug() << "initializeGL" << endl;
@@ -45,10 +58,11 @@ void MapperGLCanvas::initializeGL()
void MapperGLCanvas::resizeGL(int width, int height)
{
qDebug() << "Resize: " << width << " " << height << " at zoom " << _zoomFactor << endl;
glViewport(0, 0, width, height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (
glOrtho(
0.0f, (GLfloat) width, // left, right
(GLfloat) height, 0.0f, // bottom, top
-1.0, 1.0f);
@@ -220,11 +234,13 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event)
void MapperGLCanvas::keyPressEvent(QKeyEvent* event)
{
Q_UNUSED(event);
// std::cout << "Key pressed" << std::endl;
qDebug() << "Key pressed" << endl;
// int xMove = 0;
// int yMove = 0;
// switch (event->key()) {
switch (event->key()) {
case Qt::Key_Equal: setZoomFactor(zoomFactor()+1); break;
case Qt::Key_Minus: setZoomFactor(zoomFactor()-1); break;
}
// case Qt::Key_Tab:
// if (event->modifiers() & Qt::ControlModifier)
// switchImage( (Common::getCurrentSourceId() + 1) % Common::nImages());
+5
View File
@@ -37,6 +37,7 @@ class MainWindow;
class MapperGLCanvas: public QGLWidget
{
Q_OBJECT
Q_PROPERTY(int zoomFactor READ zoomFactor WRITE setZoomFactor);
public:
MapperGLCanvas(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget* shareWidget = 0);
@@ -54,6 +55,9 @@ public:
bool displayControls() const { return _displayControls; }
bool stickyVertices() const { return _stickyVertices; }
void setZoomFactor(int zoom);
int zoomFactor() const { return _zoomFactor; }
protected:
void initializeGL();
void resizeGL(int width, int height);
@@ -78,6 +82,7 @@ private:
bool _shapeFirstGrab;
bool _displayControls;
bool _stickyVertices;
int _zoomFactor;
signals:
void shapeChanged(Shape*);