diff --git a/DestinationGLCanvas.cpp b/DestinationGLCanvas.cpp index a9894e5..f22225a 100644 --- a/DestinationGLCanvas.cpp +++ b/DestinationGLCanvas.cpp @@ -21,8 +21,8 @@ #include "DestinationGLCanvas.h" #include "MainWindow.h" -DestinationGLCanvas::DestinationGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget) -: MapperGLCanvas(mainWindow, parent, shareWidget), +DestinationGLCanvas::DestinationGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget* shareWidget, QGraphicsScene* scene) +: MapperGLCanvas(mainWindow, parent, shareWidget, scene), _displayCrosshair(false) { } @@ -35,6 +35,19 @@ MShape* DestinationGLCanvas::getShapeFromMappingId(uid mappingId) return getMainWindow()->getMappingManager().getMappingById(mappingId)->getShape().get(); } +void DestinationGLCanvas::drawForeground(QPainter *painter , const QRectF &rect) { + 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::doDraw(QPainter* painter) //{ // glPushMatrix(); diff --git a/DestinationGLCanvas.h b/DestinationGLCanvas.h index 8057480..6074f4d 100644 --- a/DestinationGLCanvas.h +++ b/DestinationGLCanvas.h @@ -31,7 +31,7 @@ class DestinationGLCanvas: public MapperGLCanvas Q_OBJECT public: - DestinationGLCanvas(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget * shareWidget = 0); + DestinationGLCanvas(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget* shareWidget = 0, QGraphicsScene* scene = 0); virtual ~DestinationGLCanvas() {} virtual MShape* getShapeFromMappingId(uid mappingId); @@ -40,6 +40,9 @@ public: _displayCrosshair = displayCrosshair; } + // Draws foreground (displays crosshair if needed). + void drawForeground(QPainter *painter , const QRectF &rect); + private: // virtual void doDraw(QPainter* painter); diff --git a/MainWindow.cpp b/MainWindow.cpp index b0962a0..450d344 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -981,24 +981,34 @@ void MainWindow::createLayout() destinationCanvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); destinationCanvas->setMinimumSize(CANVAS_MINIMUM_WIDTH, CANVAS_MINIMUM_HEIGHT); - outputWindow = new OutputGLWindow(this, this, (QGLWidget*)sourceCanvas->viewport()); + outputWindow = new OutputGLWindow(destinationCanvas); outputWindow->setVisible(true); // Source changed -> change destination - connect(sourceCanvas, SIGNAL(shapeChanged(Shape*)), - destinationCanvas, SLOT(updateCanvas())); +// connect(sourceCanvas, SIGNAL(shapeChanged(MShape*)), +// destinationCanvas, SLOT(updateCanvas())); + + connect(sourceCanvas->scene(), SIGNAL(changed(const QList&)), + destinationCanvas, SLOT(updateCanvas())); // Source changed -> change output window - connect(sourceCanvas, SIGNAL(shapeChanged(Shape*)), +// connect(sourceCanvas, SIGNAL(shapeChanged(MShape*)), +// outputWindow->getCanvas(), SLOT(updateCanvas())); + + connect(sourceCanvas->scene(), SIGNAL(changed(const QList&)), outputWindow->getCanvas(), SLOT(updateCanvas())); // Destination changed -> change output window - connect(destinationCanvas, SIGNAL(shapeChanged(Shape*)), - outputWindow->getCanvas(), SLOT(updateCanvas())); +// connect(destinationCanvas, SIGNAL(shapeChanged(MShape*)), +// outputWindow->getCanvas(), SLOT(updateCanvas())); + + connect(destinationCanvas->scene(), SIGNAL(changed(const QList&)), + outputWindow->getCanvas(), SLOT(updateCanvas())); // Output changed -> change destinatioin - connect(outputWindow->getCanvas(), SIGNAL(shapeChanged(Shape*)), - destinationCanvas, SLOT(updateCanvas())); + // XXX si je decommente cette ligne alors quand je clique sur ajouter media ca gele... +// connect(outputWindow->getCanvas()->scene(), SIGNAL(changed(const QList&)), +// destinationCanvas, SLOT(updateCanvas())); // Create layout. paintSplitter = new QSplitter(Qt::Vertical); @@ -1868,11 +1878,11 @@ void MainWindow::addMappingItem(uid mappingId) connect(mapper.get(), SIGNAL(valueChanged()), this, SLOT(updateCanvases())); - connect(sourceCanvas, SIGNAL(shapeChanged(Shape*)), - mapper.get(), SLOT(updateShape(Shape*))); + connect(sourceCanvas, SIGNAL(shapeChanged(MShape*)), + mapper.get(), SLOT(updateShape(MShape*))); - connect(destinationCanvas, SIGNAL(shapeChanged(Shape*)), - mapper.get(), SLOT(updateShape(Shape*))); + connect(destinationCanvas, SIGNAL(shapeChanged(MShape*)), + mapper.get(), SLOT(updateShape(MShape*))); connect(this, SIGNAL(paintChanged()), mapper.get(), SLOT(updatePaint())); @@ -1895,6 +1905,8 @@ void MainWindow::addMappingItem(uid mappingId) sourceCanvas->scene()->addItem(mapper->getInputGraphicsItem()); if (mapper->getGraphicsItem()) destinationCanvas->scene()->addItem(mapper->getGraphicsItem()); + if (mapper->getGraphicsItem()) + outputWindow->getCanvas()->scene()->addItem(mapper->getGraphicsItem()); // Window was modified. windowModified(); diff --git a/MapperGLCanvas.cpp b/MapperGLCanvas.cpp index 1460a78..bcbd936 100644 --- a/MapperGLCanvas.cpp +++ b/MapperGLCanvas.cpp @@ -22,7 +22,7 @@ #include "MainWindow.h" -MapperGLCanvas::MapperGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget) +MapperGLCanvas::MapperGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget, QGraphicsScene* scene) : QGraphicsView(parent), _mainWindow(mainWindow), _mousePressedOnVertex(false), @@ -48,13 +48,13 @@ MapperGLCanvas::MapperGLCanvas(MainWindow* mainWindow, QWidget* parent, const QG // Render with OpenGL. setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers), this, shareWidget)); + setViewportUpdateMode(QGraphicsView::FullViewportUpdate); // TODO: do we need to delete scene (or call new QGraphicsScene(this)?) -// _scene = new QGraphicsScene; - setScene(new QGraphicsScene); + setScene(scene ? scene : new QGraphicsScene); // Black background. - scene()->setBackgroundBrush(Qt::black); + this->scene()->setBackgroundBrush(Qt::black); } //void MapperGLCanvas::initializeGL() @@ -396,7 +396,6 @@ void MapperGLCanvas::glueVertex(MShape *orig, QPointF *p) } } - void MapperGLCanvas::deselectVertices() { _activeVertex = NO_VERTEX; diff --git a/MapperGLCanvas.h b/MapperGLCanvas.h index f56ab6d..d326492 100644 --- a/MapperGLCanvas.h +++ b/MapperGLCanvas.h @@ -44,7 +44,7 @@ class MapperGLCanvas: public QGraphicsView public: /// Constructor. - MapperGLCanvas(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget* shareWidget = 0); + MapperGLCanvas(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget* shareWidget = 0, QGraphicsScene* scene = 0); virtual ~MapperGLCanvas() {} /// Returns shape associated with mapping id. @@ -67,8 +67,6 @@ public: /// Returns pointer to main window. MainWindow* getMainWindow() const { return _mainWindow; } -// QGLWidget* getViewport() const { return _viewport; } - /// Returns true iff we should display the controls. bool displayControls() const { return _displayControls; } @@ -117,7 +115,7 @@ private: MainWindow* _mainWindow; // QGraphicsScene* _scene; - +// // QGLWidget* _viewport; // Last point pressed. diff --git a/OutputGLWindow.cpp b/OutputGLWindow.cpp index 0e562df..1f16c89 100644 --- a/OutputGLWindow.cpp +++ b/OutputGLWindow.cpp @@ -21,11 +21,11 @@ #include "MainWindow.h" -OutputGLWindow::OutputGLWindow(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget) : QDialog(parent) +OutputGLWindow:: OutputGLWindow(const DestinationGLCanvas* canvas_) { resize(MainWindow::OUTPUT_WINDOW_MINIMUM_WIDTH, MainWindow::OUTPUT_WINDOW_MINIMUM_HEIGHT); - canvas = new DestinationGLCanvas(mainWindow, this, shareWidget); + canvas = new DestinationGLCanvas(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); @@ -38,9 +38,28 @@ OutputGLWindow::OutputGLWindow(MainWindow* mainWindow, QWidget* parent, const QG _geometry = saveGeometry(); _pointerIsVisible = true; - } +//OutputGLWindow::OutputGLWindow(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget) : QDialog(parent) +//{ +// resize(MainWindow::OUTPUT_WINDOW_MINIMUM_WIDTH, MainWindow::OUTPUT_WINDOW_MINIMUM_HEIGHT); +// +// canvas = new DestinationGLCanvas(mainWindow, this, shareWidget); +// canvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); +// canvas->setMinimumSize(MainWindow::OUTPUT_WINDOW_MINIMUM_WIDTH, MainWindow::OUTPUT_WINDOW_MINIMUM_HEIGHT); +// +// QLayout* layout = new QVBoxLayout; +// layout->setContentsMargins(0,0,0,0); // remove margin +// layout->addWidget(canvas); +// setLayout(layout); +// +// // Save window geometry. +// _geometry = saveGeometry(); +// +// _pointerIsVisible = true; +// +//} + void OutputGLWindow::setCursorVisible(bool visible) { _pointerIsVisible = visible; @@ -52,6 +71,7 @@ void OutputGLWindow::setCursorVisible(bool visible) } else { + this->setCursor(Qt::ArrowCursor); this->setCursor(Qt::BlankCursor); _pointerIsVisible = false; } diff --git a/OutputGLWindow.h b/OutputGLWindow.h index 768df62..642ef46 100644 --- a/OutputGLWindow.h +++ b/OutputGLWindow.h @@ -34,7 +34,8 @@ class OutputGLWindow : public QDialog Q_OBJECT public: - OutputGLWindow(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget * shareWidget = 0); + OutputGLWindow(const DestinationGLCanvas* canvas_); + //OutputGLWindow(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget * shareWidget = 0); public slots: void setFullScreen(bool fullScreen);