diff --git a/DestinationGLCanvas.cpp b/DestinationGLCanvas.cpp index ee771a5..6b5117e 100644 --- a/DestinationGLCanvas.cpp +++ b/DestinationGLCanvas.cpp @@ -21,8 +21,8 @@ #include "DestinationGLCanvas.h" #include "MainWindow.h" -DestinationGLCanvas::DestinationGLCanvas(QWidget* parent, const QGLWidget * shareWidget) -: MapperGLCanvas(parent, shareWidget) +DestinationGLCanvas::DestinationGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget) +: MapperGLCanvas(mainWindow, parent, shareWidget) { } @@ -31,7 +31,7 @@ Shape* DestinationGLCanvas::getShapeFromMappingId(uid mappingId) if (mappingId == NULL_UID) return NULL; else - return MainWindow::getInstance().getMappingManager().getMappingById(mappingId)->getShape().get(); + return getMainWindow()->getMappingManager().getMappingById(mappingId)->getShape().get(); } void DestinationGLCanvas::doDraw(QPainter* painter) @@ -62,12 +62,11 @@ void DestinationGLCanvas::doDraw(QPainter* painter) // } - MainWindow &mainwindow = MainWindow::getInstance(); - if ((&mainwindow) == NULL) + if (getMainWindow() == NULL) return; glPushMatrix(); - MappingManager& mappingManager = MainWindow::getInstance().getMappingManager(); + MappingManager& mappingManager = getMainWindow()->getMappingManager(); QVector mappings = mappingManager.getVisibleMappings(); for (QVector::const_iterator it = mappings.begin(); it != mappings.end(); ++it) { @@ -87,14 +86,14 @@ void DestinationGLCanvas::doDraw(QPainter* painter) } // Draw the mappings. - MainWindow::getInstance().getMapperByMappingId(mapping->getId())->draw(painter); + getMainWindow()->getMapperByMappingId(mapping->getId())->draw(painter); } // Draw the controls of current mapping. - if (MainWindow::getInstance().hasCurrentMapping() && + if (getMainWindow()->hasCurrentMapping() && getCurrentShape() != NULL) { - MainWindow::getInstance().getMapperByMappingId(MainWindow::getInstance().getCurrentMappingId())->drawControls(painter); + getMainWindow()->getMapperByMappingId(getMainWindow()->getCurrentMappingId())->drawControls(painter); } glPopMatrix(); diff --git a/DestinationGLCanvas.h b/DestinationGLCanvas.h index 973d35a..46cbc8c 100644 --- a/DestinationGLCanvas.h +++ b/DestinationGLCanvas.h @@ -31,7 +31,7 @@ class DestinationGLCanvas: public MapperGLCanvas Q_OBJECT public: - DestinationGLCanvas(QWidget* parent = 0, const QGLWidget * shareWidget = 0); + DestinationGLCanvas(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget * shareWidget = 0); // virtual ~DestinationGLCanvas(); virtual Shape* getShapeFromMappingId(uid mappingId); diff --git a/MainWindow.cpp b/MainWindow.cpp index 76ac07c..f6533b9 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -24,11 +24,8 @@ #include "Facade.h" #include -MainWindow* MainWindow::instance = 0; - MainWindow::MainWindow() { - MainWindow::setInstance(this); // Create model. mappingManager = new MappingManager; @@ -59,18 +56,6 @@ MainWindow::MainWindow() setCurrentFile(""); } -MainWindow& MainWindow::getInstance() -{ - //Q_ASSERT(instance); - - return *instance; -} - -void MainWindow::setInstance(MainWindow* inst) -{ - instance = inst; -} - MainWindow::~MainWindow() { delete mappingManager; @@ -249,7 +234,7 @@ void MainWindow::addMesh() return; // Retrieve current paint (as texture). - Paint::ptr paint = MainWindow::getInstance().getMappingManager().getPaint(getCurrentPaintId()); + Paint::ptr paint = getMappingManager().getPaint(getCurrentPaintId()); Q_CHECK_PTR(paint); // Create input and output quads. @@ -282,7 +267,7 @@ void MainWindow::addTriangle() return; // Retrieve current paint (as texture). - Paint::ptr paint = MainWindow::getInstance().getMappingManager().getPaint(getCurrentPaintId()); + Paint::ptr paint = getMappingManager().getPaint(getCurrentPaintId()); Q_CHECK_PTR(paint); // Create input and output quads. @@ -315,7 +300,7 @@ void MainWindow::addEllipse() return; // Retrieve current paint (as texture). - Paint::ptr paint = MainWindow::getInstance().getMappingManager().getPaint(getCurrentPaintId()); + Paint::ptr paint = getMappingManager().getPaint(getCurrentPaintId()); Q_CHECK_PTR(paint); // Create input and output ellipses. @@ -725,17 +710,17 @@ void MainWindow::createLayout() // Create canvases. - sourceCanvas = new SourceGLCanvas; + sourceCanvas = new SourceGLCanvas(this); sourceCanvas->setFocusPolicy(Qt::ClickFocus); sourceCanvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); sourceCanvas->setMinimumSize(CANVAS_MINIMUM_WIDTH, CANVAS_MINIMUM_HEIGHT); - destinationCanvas = new DestinationGLCanvas(0, sourceCanvas); + destinationCanvas = new DestinationGLCanvas(this, 0, sourceCanvas); destinationCanvas->setFocusPolicy(Qt::ClickFocus); destinationCanvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); destinationCanvas->setMinimumSize(CANVAS_MINIMUM_WIDTH, CANVAS_MINIMUM_HEIGHT); - outputWindow = new OutputGLWindow(this, sourceCanvas); + outputWindow = new OutputGLWindow(this, this, sourceCanvas); outputWindow->setVisible(true); // Source changed -> change destination diff --git a/MainWindow.h b/MainWindow.h index a0370bc..56be2cf 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -56,10 +56,6 @@ public: // Destructor. ~MainWindow(); - // TODO: It is a bad shortcut to make MainWindow a singleton: it would be better to use signals/slots instead. - static MainWindow& getInstance(); - static void setInstance(MainWindow* inst); - // XXX Unused. void applyOscCommand(const QVariantList& command); @@ -272,9 +268,6 @@ private: // Keeps track of the current selected item, wether it's a paint or mapping. QListWidgetItem* currentSelectedItem; - // Singleton instance. - static MainWindow* instance; - public: // Accessor/mutators for the view. /////////////////////////////////////////////////////////////////// MappingManager& getMappingManager() { return *mappingManager; } diff --git a/MapperGLCanvas.cpp b/MapperGLCanvas.cpp index 097bbac..33f35ea 100644 --- a/MapperGLCanvas.cpp +++ b/MapperGLCanvas.cpp @@ -22,8 +22,8 @@ #include "MainWindow.h" -MapperGLCanvas::MapperGLCanvas(QWidget* parent, const QGLWidget * shareWidget) - : QGLWidget(parent, shareWidget), _mousepressed(false), _active_vertex(NO_VERTEX) +MapperGLCanvas::MapperGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget) + : QGLWidget(parent, shareWidget), _mainWindow(mainWindow), _mousepressed(false), _active_vertex(NO_VERTEX) { } @@ -98,7 +98,7 @@ void MapperGLCanvas::enterDraw(QPainter* painter) Shape* MapperGLCanvas::getCurrentShape() { - return getShapeFromMappingId(MainWindow::getInstance().getCurrentMappingId()); + return getShapeFromMappingId(getMainWindow()->getCurrentMappingId()); } void MapperGLCanvas::mousePressEvent(QMouseEvent* event) @@ -284,7 +284,7 @@ void MapperGLCanvas::updateCanvas() * variable. Perhaps the sticky-sensitivity should be configurable through GUI */ void MapperGLCanvas::glueVertex(Shape *orig, QPointF *p) { - MappingManager manager = MainWindow::getInstance().getMappingManager(); + MappingManager manager = getMainWindow()->getMappingManager(); int dist_stick = 10; /*this parameter may*/ for (int i = 0; i < manager.nMappings(); i++) { diff --git a/MapperGLCanvas.h b/MapperGLCanvas.h index f308015..3110ea6 100644 --- a/MapperGLCanvas.h +++ b/MapperGLCanvas.h @@ -26,11 +26,10 @@ #include -//#include "Common.h" #include "UidAllocator.h" #include "Shape.h" -//#include "MainWindow.h" +class MainWindow; /** * Qt GUI widget that draws a mapper, which is a shape with some paint. @@ -40,7 +39,7 @@ class MapperGLCanvas: public QGLWidget Q_OBJECT public: - MapperGLCanvas(QWidget* parent = 0, const QGLWidget* shareWidget = 0); + MapperGLCanvas(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget* shareWidget = 0); virtual ~MapperGLCanvas() {} virtual Shape* getShapeFromMappingId(uid mappingId) = 0; @@ -51,6 +50,8 @@ public: Shape* getCurrentShape(); void glueVertex(Shape *, QPointF *); + MainWindow* getMainWindow() const { return _mainWindow; } + protected: void initializeGL(); void resizeGL(int width, int height); @@ -67,6 +68,8 @@ private: void enterDraw(QPainter* painter); virtual void doDraw(QPainter* painter) = 0; void exitDraw(QPainter* painter); + + MainWindow* _mainWindow; bool _mousepressed; int _active_vertex; bool _shapegrabbed; diff --git a/OutputGLWindow.cpp b/OutputGLWindow.cpp index c3f97a7..da9d34b 100644 --- a/OutputGLWindow.cpp +++ b/OutputGLWindow.cpp @@ -21,11 +21,11 @@ #include "MainWindow.h" -OutputGLWindow::OutputGLWindow(QWidget* parent, const QGLWidget * shareWidget) : QDialog(parent) +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(this, shareWidget); + canvas = new DestinationGLCanvas(mainWindow, this, shareWidget); 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 3851861..b0c72c0 100644 --- a/OutputGLWindow.h +++ b/OutputGLWindow.h @@ -31,7 +31,7 @@ class OutputGLWindow : public QDialog Q_OBJECT public: - OutputGLWindow(QWidget* parent = 0, const QGLWidget * shareWidget = 0); + OutputGLWindow(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget * shareWidget = 0); protected: void closeEvent(QCloseEvent* event); diff --git a/SourceGLCanvas.cpp b/SourceGLCanvas.cpp index bc7938a..e4f49db 100644 --- a/SourceGLCanvas.cpp +++ b/SourceGLCanvas.cpp @@ -23,8 +23,8 @@ #include "MainWindow.h" -SourceGLCanvas::SourceGLCanvas(QWidget* parent) - : MapperGLCanvas(parent) +SourceGLCanvas::SourceGLCanvas(MainWindow* mainWindow, QWidget* parent) + : MapperGLCanvas(mainWindow, parent) { } @@ -35,7 +35,7 @@ Shape* SourceGLCanvas::getShapeFromMappingId(uid mappingId) else { - Mapping::ptr mapping = MainWindow::getInstance().getMappingManager().getMappingById(mappingId); + Mapping::ptr mapping = getMainWindow()->getMappingManager().getMappingById(mappingId); // TODO: this is real shit... : we should at the very least use some dynamic casting or (better) implement a correct // class architecture to suit our needs if (mapping->getType().endsWith("_texture")) @@ -63,17 +63,17 @@ Shape* SourceGLCanvas::getShapeFromMappingId(uid mappingId) void SourceGLCanvas::doDraw(QPainter* painter) { - if (!MainWindow::getInstance().hasCurrentPaint()) + if (!getMainWindow()->hasCurrentPaint()) return; - uint paintId = MainWindow::getInstance().getCurrentPaintId(); + uint paintId = getMainWindow()->getCurrentPaintId(); // Retrieve paint (as texture) and draw it. - Paint::ptr paint = MainWindow::getInstance().getMappingManager().getPaintById(paintId); + Paint::ptr paint = getMainWindow()->getMappingManager().getPaintById(paintId); Q_CHECK_PTR(paint); // Retrieve all mappings associated to paint. - QMap mappings = MainWindow::getInstance().getMappingManager().getPaintMappingsById(paintId); + QMap mappings = getMainWindow()->getMappingManager().getPaintMappingsById(paintId); if (paint->getType() == "color") _drawColor(painter, paint, mappings); @@ -163,9 +163,9 @@ void SourceGLCanvas::_drawTexture(QPainter* painter, Paint::ptr paint, QMap inputShape = std::tr1::static_pointer_cast(textureMapping->getInputShape()); Q_CHECK_PTR(inputShape); - if (it.key() == MainWindow::getInstance().getCurrentMappingId()) + if (it.key() == getMainWindow()->getCurrentMappingId()) { - Mapper::ptr mapper = MainWindow::getInstance().getMapperByMappingId(it.key()); + Mapper::ptr mapper = getMainWindow()->getMapperByMappingId(it.key()); Q_CHECK_PTR(mapper); std::tr1::shared_ptr textureMapper = std::tr1::static_pointer_cast(mapper); diff --git a/SourceGLCanvas.h b/SourceGLCanvas.h index 8330d88..f0ac43e 100644 --- a/SourceGLCanvas.h +++ b/SourceGLCanvas.h @@ -32,7 +32,7 @@ class SourceGLCanvas: public MapperGLCanvas Q_OBJECT public: - SourceGLCanvas(QWidget* parent = 0); + SourceGLCanvas(MainWindow* mainWindow, QWidget* parent = 0); // virtual ~SourceGLCanvas() {} virtual Shape* getShapeFromMappingId(uid mappingId);