diff --git a/DestinationGLCanvas.cpp b/DestinationGLCanvas.cpp
index 263f282..e92b1ee 100644
--- a/DestinationGLCanvas.cpp
+++ b/DestinationGLCanvas.cpp
@@ -41,6 +41,6 @@ ShapeGraphicsItem* DestinationGLCanvas::getShapeGraphicsItemFromMappingId(uid ma
else
{
- return MainWindow::instance()->getMapperByMappingId(mappingId)->getGraphicsItem();
+ return MainWindow::instance()->getMapperByMappingId(mappingId)->getGraphicsItem().data();
}
}
diff --git a/DestinationGLCanvas.cpp.orig b/DestinationGLCanvas.cpp.orig
new file mode 100644
index 0000000..f1963d2
--- /dev/null
+++ b/DestinationGLCanvas.cpp.orig
@@ -0,0 +1,215 @@
+/*
+ * DestinationGLCanvas.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 "DestinationGLCanvas.h"
+#include "MainWindow.h"
+
+<<<<<<< HEAD
+DestinationGLCanvas::DestinationGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget)
+: MapperGLCanvas(mainWindow, parent, shareWidget),
+ _displayCrosshair(false),
+ _svg_test_signal(":/test-signal"),
+ _brush_test_signal(_svg_test_signal)
+=======
+DestinationGLCanvas::DestinationGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget* shareWidget, QGraphicsScene* scene)
+: MapperGLCanvas(mainWindow, parent, shareWidget, scene),
+ _displayCrosshair(false)
+>>>>>>> spike-qgraphicsview-zoom-and-scroll
+{
+}
+
+MShape* DestinationGLCanvas::getShapeFromMappingId(uid mappingId)
+{
+ if (mappingId == NULL_UID)
+ return NULL;
+ else
+ return getMainWindow()->getMappingManager().getMappingById(mappingId)->getShape().get();
+}
+
+<<<<<<< HEAD
+void DestinationGLCanvas::doDraw(QPainter* painter)
+{
+ if (this->displayTestSignal())
+ {
+ glPushMatrix();
+ painter->save();
+ this->_drawTestSignal(painter);
+ painter->restore();
+ glPopMatrix();
+ return;
+ }
+
+ glPushMatrix();
+
+ // Draw the mappings.
+ QVector mappings = getMainWindow()->getMappingManager().getVisibleMappings();
+ for (QVector::const_iterator it = mappings.begin(); it != mappings.end(); ++it)
+ {
+ painter->save();
+ getMainWindow()->getMapperByMappingId((*it)->getId())->draw(painter);
+ painter->restore();
+ }
+
+ // Draw the controls of current mapping.
+ if (displayControls() &&
+ getMainWindow()->hasCurrentMapping() &&
+ getCurrentShape() != NULL)
+ {
+ painter->save();
+ const Mapper::ptr& mapper = getMainWindow()->getMapperByMappingId(getMainWindow()->getCurrentMappingId());
+ if (hasActiveVertex()) {
+ QList selectedVertices;
+ selectedVertices.append(getActiveVertexIndex());
+ mapper->drawControls(painter, &selectedVertices);
+ }
+ else
+ {
+ mapper->drawControls(painter);
+ }
+ painter->restore();
+ }
+
+ glPopMatrix();
+
+ // Display crosshair cursor.
+=======
+void DestinationGLCanvas::drawForeground(QPainter *painter , const QRectF &rect) {
+>>>>>>> spike-qgraphicsview-zoom-and-scroll
+ 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());
+ }
+ }
+}
+
+<<<<<<< HEAD
+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);
+ }
+}
+=======
+//void DestinationGLCanvas::doDraw(QPainter* painter)
+//{
+// glPushMatrix();
+//
+// // Draw the mappings.
+// QVector mappings = getMainWindow()->getMappingManager().getVisibleMappings();
+// for (QVector::const_iterator it = mappings.begin(); it != mappings.end(); ++it)
+// {
+// painter->save();
+// getMainWindow()->getMapperByMappingId((*it)->getId())->draw(painter);
+// painter->restore();
+// }
+//
+// // Draw the controls of current mapping.
+// if (displayControls() &&
+// getMainWindow()->hasCurrentMapping() &&
+// getCurrentShape() != NULL)
+// {
+// painter->save();
+// const Mapper::ptr& mapper = getMainWindow()->getMapperByMappingId(getMainWindow()->getCurrentMappingId());
+// if (hasActiveVertex()) {
+// QList selectedVertices;
+// selectedVertices.append(getActiveVertexIndex());
+// mapper->drawControls(painter, &selectedVertices);
+// }
+// else
+// mapper->drawControls(painter);
+// painter->restore();
+// }
+//
+// glPopMatrix();
+//
+// // Display crosshair cursor.
+// if (_displayCrosshair)
+// {
+// const QPoint& cursorPosition = this->mapFromGlobal(QCursor::pos());
+// const QRect& geo = geometry();
+// if (geo.contains(cursorPosition))
+// {
+// painter->setPen(MM::CONTROL_COLOR);
+// painter->drawLine(cursorPosition.x(), 0, cursorPosition.x(), geo.height());
+// painter->drawLine(0, cursorPosition.y(), geo.width(), cursorPosition.y());
+// }
+// }
+//
+//}
+>>>>>>> spike-qgraphicsview-zoom-and-scroll
+
diff --git a/MainWindow.cpp b/MainWindow.cpp
index b3ec72f..b232aed 100644
--- a/MainWindow.cpp
+++ b/MainWindow.cpp
@@ -2137,9 +2137,9 @@ void MainWindow::addMappingItem(uid mappingId)
// Add items to scenes.
if (mapper->getInputGraphicsItem())
- sourceCanvas->scene()->addItem(mapper->getInputGraphicsItem());
+ sourceCanvas->scene()->addItem(mapper->getInputGraphicsItem().data());
if (mapper->getGraphicsItem())
- destinationCanvas->scene()->addItem(mapper->getGraphicsItem());
+ destinationCanvas->scene()->addItem(mapper->getGraphicsItem().data());
// Window was modified.
windowModified();
diff --git a/Mapper.cpp b/Mapper.cpp
index 615409f..81e366d 100644
--- a/Mapper.cpp
+++ b/Mapper.cpp
@@ -629,7 +629,7 @@ Mapper::Mapper(Mapping::ptr mapping)
Q_CHECK_PTR(outputShape);
// Create editor.
- _propertyBrowser = new QtTreePropertyBrowser;
+ _propertyBrowser.reset(new QtTreePropertyBrowser);
_variantManager = new VariantManager;
_variantFactory = new VariantFactory;
@@ -663,18 +663,6 @@ Mapper::Mapper(Mapping::ptr mapping)
//qDebug() << "Creating mapper" << endl;
}
-Mapper::~Mapper()
-{
- if (_propertyBrowser)
- delete _propertyBrowser;
- if (_graphicsItem)
- delete _graphicsItem;
-}
-
-QWidget* Mapper::getPropertiesEditor()
-{
- return _propertyBrowser;
-}
void Mapper::setValue(QtProperty* property, const QVariant& value)
{
@@ -922,8 +910,8 @@ void TextureMapper::updateShape(MShape* shape)
TriangleTextureMapper::TriangleTextureMapper(QSharedPointer mapping)
: PolygonTextureMapper(mapping)
{
- _graphicsItem = new TriangleTextureGraphicsItem(_mapping, true);
- _inputGraphicsItem = new TriangleTextureGraphicsItem(_mapping, false);
+ _graphicsItem.reset(new TriangleTextureGraphicsItem(_mapping, true));
+ _inputGraphicsItem.reset(new TriangleTextureGraphicsItem(_mapping, false));
}
//
//void TriangleTextureMapper::_doDraw(QPainter* painter)
@@ -943,8 +931,8 @@ TriangleTextureMapper::TriangleTextureMapper(QSharedPointer mapp
MeshTextureMapper::MeshTextureMapper(QSharedPointer mapping)
: PolygonTextureMapper(mapping)
{
- _graphicsItem = new MeshTextureGraphicsItem(_mapping, true);
- _inputGraphicsItem = new MeshTextureGraphicsItem(_mapping, false);
+ _graphicsItem.reset(new MeshTextureGraphicsItem(_mapping, true));
+ _inputGraphicsItem.reset(new MeshTextureGraphicsItem(_mapping, false));
// Add mesh sub property.
QSharedPointer mesh = qSharedPointerCast(_mapping->getShape());
@@ -982,7 +970,7 @@ void MeshTextureMapper::setValue(QtProperty* property, const QVariant& value)
EllipseTextureMapper::EllipseTextureMapper(QSharedPointer mapping)
: PolygonTextureMapper(mapping)
{
- _graphicsItem = new EllipseTextureGraphicsItem(_mapping, true);
- _inputGraphicsItem = new EllipseTextureGraphicsItem(_mapping, false);
+ _graphicsItem.reset(new EllipseTextureGraphicsItem(_mapping, true));
+ _inputGraphicsItem.reset(new EllipseTextureGraphicsItem(_mapping, false));
}
diff --git a/Mapper.h b/Mapper.h
index fbfae03..df568e1 100644
--- a/Mapper.h
+++ b/Mapper.h
@@ -105,6 +105,8 @@ protected:
class ShapeGraphicsItem : public QGraphicsItem
{
Q_DECLARE_TR_FUNCTIONS(ShapeGraphicsItem)
+public:
+ typedef QSharedPointer ptr;
protected:
ShapeGraphicsItem(Mapping::ptr mapping, bool output=true);
@@ -311,18 +313,14 @@ protected:
Mapper(Mapping::ptr mapping);
public:
- virtual ~Mapper();
+ virtual ~Mapper() {}
public:
/// Returns a pointer to the properties editor for that mapper.
- virtual QWidget* getPropertiesEditor();
+ virtual QWidget* getPropertiesEditor() { return _propertyBrowser.data(); }
- virtual ShapeGraphicsItem* getGraphicsItem() {
- return _graphicsItem;
- }
- virtual ShapeGraphicsItem* getInputGraphicsItem() {
- return _inputGraphicsItem;
- }
+ virtual ShapeGraphicsItem::ptr getGraphicsItem() const { return _graphicsItem; }
+ virtual ShapeGraphicsItem::ptr getInputGraphicsItem() { return _inputGraphicsItem; }
public slots:
virtual void setValue(QtProperty* property, const QVariant& value);
@@ -335,7 +333,7 @@ signals:
protected:
Mapping::ptr _mapping;
- QtTreePropertyBrowser* _propertyBrowser;
+ QSharedPointer _propertyBrowser;
QtVariantEditorFactory* _variantFactory;
QtVariantPropertyManager* _variantManager;
@@ -345,8 +343,8 @@ protected:
std::map > _propertyToVertex;
- ShapeGraphicsItem* _graphicsItem;
- ShapeGraphicsItem* _inputGraphicsItem;
+ ShapeGraphicsItem::ptr _graphicsItem;
+ ShapeGraphicsItem::ptr _inputGraphicsItem;
// FIXME: use typedefs, member of the class for type names that are too long to type:
MShape::ptr outputShape;
@@ -376,7 +374,7 @@ class PolygonColorMapper : public ColorMapper
public:
PolygonColorMapper(Mapping::ptr mapping) : ColorMapper(mapping) {
- _graphicsItem = new PolygonColorGraphicsItem(mapping, true);
+ _graphicsItem.reset(new PolygonColorGraphicsItem(mapping, true));
}
virtual ~PolygonColorMapper() {}
};
@@ -405,7 +403,7 @@ class EllipseColorMapper : public ColorMapper
public:
EllipseColorMapper(Mapping::ptr mapping) : ColorMapper(mapping) {
- _graphicsItem = new EllipseColorGraphicsItem(mapping, true);
+ _graphicsItem.reset(new EllipseColorGraphicsItem(mapping, true));
}
virtual ~EllipseColorMapper() {}
diff --git a/SourceGLCanvas.cpp b/SourceGLCanvas.cpp
index 01239f5..9a57277 100644
--- a/SourceGLCanvas.cpp
+++ b/SourceGLCanvas.cpp
@@ -48,7 +48,7 @@ ShapeGraphicsItem* SourceGLCanvas::getShapeGraphicsItemFromMappingId(uid mapping
else
{
- return MainWindow::instance()->getMapperByMappingId(mappingId)->getInputGraphicsItem();
+ return MainWindow::instance()->getMapperByMappingId(mappingId)->getInputGraphicsItem().data();
}
}