From 8f13597451bf47f539358b6ff94e335df58eefda Mon Sep 17 00:00:00 2001 From: Tats Date: Mon, 13 Jul 2015 16:44:41 -0600 Subject: [PATCH] Created a special class for output gl canvas to prevent some events (like zooming) to happen. --- DestinationGLCanvas.cpp | 90 +----------------------------- DestinationGLCanvas.h | 21 ------- MapperGLCanvas.cpp | 16 ++++++ MapperGLCanvas.h | 5 +- OutputGLCanvas.cpp | 118 ++++++++++++++++++++++++++++++++++++++++ OutputGLCanvas.h | 56 +++++++++++++++++++ OutputGLWindow.cpp | 2 +- OutputGLWindow.h | 4 +- mapmap.pro | 2 + 9 files changed, 200 insertions(+), 114 deletions(-) create mode 100644 OutputGLCanvas.cpp create mode 100644 OutputGLCanvas.h diff --git a/DestinationGLCanvas.cpp b/DestinationGLCanvas.cpp index d8aba97..9009640 100644 --- a/DestinationGLCanvas.cpp +++ b/DestinationGLCanvas.cpp @@ -22,10 +22,7 @@ #include "MainWindow.h" DestinationGLCanvas::DestinationGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget* shareWidget, QGraphicsScene* scene) -: MapperGLCanvas(mainWindow, parent, shareWidget, scene), - _displayCrosshair(false), - _svg_test_signal(":/test-signal"), - _brush_test_signal(_svg_test_signal) +: MapperGLCanvas(mainWindow, parent, shareWidget, scene) { } @@ -37,88 +34,3 @@ MShape* DestinationGLCanvas::getShapeFromMappingId(uid mappingId) return getMainWindow()->getMappingManager().getMappingById(mappingId)->getShape().get(); } -void DestinationGLCanvas::drawForeground(QPainter *painter , const QRectF &rect) -{ - if (getMainWindow()->displayTestSignal()) - { - glPushMatrix(); - painter->save(); - _drawTestSignal(painter); - painter->restore(); - glPopMatrix(); - return; - } - - // Display crosshair cursor. - if (_displayCrosshair) - { - QPointF cursorPosition = mapToScene(cursor().pos());// - rect.topLeft();//(QCursor::pos());///*this->mapFromGlobal(*/QCursor::pos()/*)*/; - if (rect.contains(cursorPosition)) - { - painter->setPen(MM::CONTROL_COLOR); - painter->drawLine(cursorPosition.x(), rect.y(), cursorPosition.x(), rect.height()); - painter->drawLine(rect.x(), cursorPosition.y(), rect.width(), cursorPosition.y()); - } - } -} - -void DestinationGLCanvas::_drawTestSignal(QPainter* painter) -{ - const QRect& geo = geometry(); - painter->setPen(MM::CONTROL_COLOR); - int height = geo.height(); - int width = geo.width(); - int rect_size = 10; - QColor color_0(191, 191, 191); - QColor color_1(128, 128, 128); - QBrush brush_0(color_0); - QBrush brush_1(color_1); - - painter->setPen(Qt::NoPen); - - for (int x = 0; x < width; x += rect_size) - { - for (int y = 0; y < height; y += rect_size) - { - if (((x + y) % 20) == 0) - { - painter->setBrush(brush_0); - } else { - painter->setBrush(brush_1); - } - painter->drawRect(x, y, rect_size, rect_size); - } - } - - painter->fillRect(geo, this->_brush_test_signal); -} - -void DestinationGLCanvas::resizeGL(int width, int height) -{ - int side_length = width; - if (height < width) - { - side_length = height; - } - - (void) side_length; // to get rid of warnings - // TODO: reload SVG with the new size - // TODO: _svg_test_signal.load(":/test-signal"); - // TODO: _brush_test_signal(_svg_test_signal) -} - -bool DestinationGLCanvas::eventFilter(QObject *target, QEvent *event) -{ - if (event->type() == QEvent::KeyPress) - { - QKeyEvent *keyEvent = static_cast(event); - setActiveVertexIndex(getMainWindow()->getOutputWindow()->getCanvas()->getActiveVertexIndex()); - MapperGLCanvas::keyPressEvent(keyEvent); - return true; - } - else - { - return QObject::eventFilter(target, event); - } -} - diff --git a/DestinationGLCanvas.h b/DestinationGLCanvas.h index 8477fff..1cf0007 100644 --- a/DestinationGLCanvas.h +++ b/DestinationGLCanvas.h @@ -35,27 +35,6 @@ public: virtual ~DestinationGLCanvas() {} virtual MShape* getShapeFromMappingId(uid mappingId); - - void setDisplayCrosshair(bool displayCrosshair) { - _displayCrosshair = displayCrosshair; - } - - // Draws foreground (displays crosshair if needed). - void drawForeground(QPainter *painter , const QRectF &rect); - -private: - void _drawTestSignal(QPainter* painter); - - bool _displayCrosshair; - QImage _svg_test_signal; - QBrush _brush_test_signal; - -protected: - // overriden from QGlWidget: - virtual void resizeGL(int width, int height); - - // Event Filter - bool eventFilter(QObject *target, QEvent *event); }; #endif /* DESTINATIONGLCANVAS_H_ */ diff --git a/MapperGLCanvas.cpp b/MapperGLCanvas.cpp index 5c4ff58..c198e11 100644 --- a/MapperGLCanvas.cpp +++ b/MapperGLCanvas.cpp @@ -390,3 +390,19 @@ void MapperGLCanvas::wheelEvent(QWheelEvent *event) // Accept wheel scrolling event. event->accept(); } + +bool MapperGLCanvas::eventFilter(QObject *target, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) + { + QKeyEvent *keyEvent = static_cast(event); + setActiveVertexIndex(getMainWindow()->getOutputWindow()->getCanvas()->getActiveVertexIndex()); + MapperGLCanvas::keyPressEvent(keyEvent); + return true; + } + else + { + return QObject::eventFilter(target, event); + } +} + diff --git a/MapperGLCanvas.h b/MapperGLCanvas.h index d1571ee..7b537eb 100644 --- a/MapperGLCanvas.h +++ b/MapperGLCanvas.h @@ -141,7 +141,10 @@ public slots: void deselectVertices(); void deselectAll(); - void wheelEvent(QWheelEvent * event); + void wheelEvent(QWheelEvent *event); + + // Event Filter + bool eventFilter(QObject *target, QEvent *event); public: static const int NO_VERTEX = -1; diff --git a/OutputGLCanvas.cpp b/OutputGLCanvas.cpp new file mode 100644 index 0000000..5a0b6bc --- /dev/null +++ b/OutputGLCanvas.cpp @@ -0,0 +1,118 @@ +/* + * OutputGLCanvas.cpp + * + * (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com + * (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "OutputGLCanvas.h" +#include "MainWindow.h" + +OutputGLCanvas::OutputGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget* shareWidget, QGraphicsScene* scene) +: DestinationGLCanvas(mainWindow, parent, shareWidget, scene), + _displayCrosshair(false), + _svg_test_signal(":/test-signal"), + _brush_test_signal(_svg_test_signal) +{ +} + +void OutputGLCanvas::drawForeground(QPainter *painter , const QRectF &rect) +{ + if (getMainWindow()->displayTestSignal()) + { + glPushMatrix(); + painter->save(); + _drawTestSignal(painter); + painter->restore(); + glPopMatrix(); + return; + } + + // Display crosshair cursor. + if (_displayCrosshair) + { + QPointF cursorPosition = mapToScene(cursor().pos());// - rect.topLeft();//(QCursor::pos());///*this->mapFromGlobal(*/QCursor::pos()/*)*/; + if (rect.contains(cursorPosition)) + { + painter->setPen(MM::CONTROL_COLOR); + painter->drawLine(cursorPosition.x(), rect.y(), cursorPosition.x(), rect.height()); + painter->drawLine(rect.x(), cursorPosition.y(), rect.width(), cursorPosition.y()); + } + } +} + +void OutputGLCanvas::_drawTestSignal(QPainter* painter) +{ + const QRect& geo = geometry(); + painter->setPen(MM::CONTROL_COLOR); + int height = geo.height(); + int width = geo.width(); + int rect_size = 10; + QColor color_0(191, 191, 191); + QColor color_1(128, 128, 128); + QBrush brush_0(color_0); + QBrush brush_1(color_1); + + painter->setPen(Qt::NoPen); + + for (int x = 0; x < width; x += rect_size) + { + for (int y = 0; y < height; y += rect_size) + { + if (((x + y) % 20) == 0) + { + painter->setBrush(brush_0); + } else { + painter->setBrush(brush_1); + } + painter->drawRect(x, y, rect_size, rect_size); + } + } + + painter->fillRect(geo, this->_brush_test_signal); +} + +void OutputGLCanvas::resizeGL(int width, int height) +{ + int side_length = width; + if (height < width) + { + side_length = height; + } + + (void) side_length; // to get rid of warnings + // TODO: reload SVG with the new size + // TODO: _svg_test_signal.load(":/test-signal"); + // TODO: _brush_test_signal(_svg_test_signal) +} + +void OutputGLCanvas::wheelEvent(QWheelEvent *event) +{ + event->ignore(); +} + +void OutputGLCanvas::mouseMoveEvent(QMouseEvent *event) +{ + // Click-and-drag translate view. + if (event->buttons() & Qt::MiddleButton) + { + event->ignore(); + } + else + { + DestinationGLCanvas::mouseMoveEvent(event); + } +} diff --git a/OutputGLCanvas.h b/OutputGLCanvas.h new file mode 100644 index 0000000..85d5e6e --- /dev/null +++ b/OutputGLCanvas.h @@ -0,0 +1,56 @@ +/* + * OutputGLCanvas.h + * + * (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com + * (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef OUTPUTGLCANVAS_H_ +#define OUTPUTGLCANVAS_H_ + +#include "DestinationGLCanvas.h" + +class OutputGLCanvas: public DestinationGLCanvas +{ + Q_OBJECT + +public: + OutputGLCanvas(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget* shareWidget = 0, QGraphicsScene* scene = 0); + virtual ~OutputGLCanvas() {} + + void setDisplayCrosshair(bool displayCrosshair) { + _displayCrosshair = displayCrosshair; + } + + // Draws foreground (displays crosshair if needed). + void drawForeground(QPainter *painter , const QRectF &rect); + +private: + void _drawTestSignal(QPainter* painter); + + bool _displayCrosshair; + QImage _svg_test_signal; + QBrush _brush_test_signal; + +protected: + // overriden from QGlWidget: + virtual void resizeGL(int width, int height); + + void wheelEvent(QWheelEvent *event); + void mouseMoveEvent(QMouseEvent *event); +}; + +#endif /* OutputGLCanvas_H_ */ diff --git a/OutputGLWindow.cpp b/OutputGLWindow.cpp index d58108c..630789d 100644 --- a/OutputGLWindow.cpp +++ b/OutputGLWindow.cpp @@ -27,7 +27,7 @@ OutputGLWindow:: OutputGLWindow(const DestinationGLCanvas* canvas_) { resize(MainWindow::OUTPUT_WINDOW_MINIMUM_WIDTH, MainWindow::OUTPUT_WINDOW_MINIMUM_HEIGHT); - canvas = new DestinationGLCanvas(canvas_->getMainWindow(), this, (const QGLWidget*)canvas_->viewport(), canvas_->scene()); + canvas = new OutputGLCanvas(canvas_->getMainWindow(), this, (const QGLWidget*)canvas_->viewport(), canvas_->scene()); canvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); canvas->setMinimumSize(MainWindow::OUTPUT_WINDOW_MINIMUM_WIDTH, MainWindow::OUTPUT_WINDOW_MINIMUM_HEIGHT); diff --git a/OutputGLWindow.h b/OutputGLWindow.h index 678dd69..c646d9f 100644 --- a/OutputGLWindow.h +++ b/OutputGLWindow.h @@ -24,7 +24,7 @@ #include #include #include -#include "DestinationGLCanvas.h" +#include "OutputGLCanvas.h" // TODO: add SLOT for mySetVisible // TODO: Maybe improve support for Ubuntu: http://stackoverflow.com/questions/12645880/fullscreen-for-qdialog-from-within-mainwindow-only-working-sometimes @@ -53,7 +53,7 @@ public: void setCursorVisible(bool visible); private: - DestinationGLCanvas* canvas; + OutputGLCanvas* canvas; QByteArray _geometry; bool _pointerIsVisible; diff --git a/mapmap.pro b/mapmap.pro index b5a323c..9bef7bb 100644 --- a/mapmap.pro +++ b/mapmap.pro @@ -20,6 +20,7 @@ HEADERS = \ MediaImpl.h \ OscInterface.h \ OscReceiver.h \ + OutputGLCanvas.h \ OutputGLWindow.h \ Paint.h \ PaintGui.h \ @@ -44,6 +45,7 @@ SOURCES = \ MediaImpl.cpp \ OscInterface.cpp \ OscReceiver.cpp \ + OutputGLCanvas.cpp \ OutputGLWindow.cpp \ Paint.cpp \ PaintGui.cpp \