mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Correct management of source<->destionation interaction using signals/slots
This commit is contained in:
@@ -24,6 +24,16 @@ DestinationGLCanvas::DestinationGLCanvas(QWidget* parent, const QGLWidget * shar
|
||||
{
|
||||
}
|
||||
|
||||
Quad& DestinationGLCanvas::getQuad() {
|
||||
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
|
||||
Q_CHECK_PTR(textureMapping);
|
||||
|
||||
std::tr1::shared_ptr<Quad> quad = std::tr1::static_pointer_cast<Quad>(Common::currentMapping->getShape());
|
||||
Q_CHECK_PTR(quad);
|
||||
|
||||
return (*quad);
|
||||
}
|
||||
|
||||
void DestinationGLCanvas::doDraw() {
|
||||
// TODO: Ceci est un hack necessaire car tout est en fonction de la width/height de la texture.
|
||||
// Il faut changer ca.
|
||||
|
||||
+3
-10
@@ -26,20 +26,13 @@
|
||||
|
||||
class DestinationGLCanvas: public MapperGLCanvas
|
||||
{
|
||||
// Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DestinationGLCanvas(QWidget* parent = 0, const QGLWidget * shareWidget = 0);
|
||||
// virtual ~DestinationGLCanvas();
|
||||
|
||||
virtual Quad& getQuad() {
|
||||
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
|
||||
Q_CHECK_PTR(textureMapping);
|
||||
|
||||
std::tr1::shared_ptr<Quad> quad = std::tr1::static_pointer_cast<Quad>(Common::currentMapping->getShape());
|
||||
Q_CHECK_PTR(quad);
|
||||
|
||||
return (*quad);
|
||||
}
|
||||
virtual Quad& getQuad();
|
||||
|
||||
private:
|
||||
virtual void doDraw();
|
||||
|
||||
+10
-3
@@ -108,7 +108,10 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event)
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Tab:
|
||||
if (event->modifiers() & Qt::ControlModifier)
|
||||
{
|
||||
Common::nextImage();
|
||||
emit quadSwitched();
|
||||
}
|
||||
else
|
||||
current = (current + 1) % 4;
|
||||
break;
|
||||
@@ -136,15 +139,15 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event)
|
||||
p.y += yMove;
|
||||
quad.setVertex(current, p);
|
||||
|
||||
updateGL();
|
||||
update();
|
||||
|
||||
emit quadChanged();
|
||||
}
|
||||
|
||||
void MapperGLCanvas::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
std::cout << "Paint event" << std::endl;
|
||||
updateGL();
|
||||
update();
|
||||
}
|
||||
|
||||
void MapperGLCanvas::exitDraw()
|
||||
@@ -153,4 +156,8 @@ void MapperGLCanvas::exitDraw()
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
||||
void MapperGLCanvas::updateCanvas()
|
||||
{
|
||||
std::cout << "Update me!" << std::endl;
|
||||
update();
|
||||
}
|
||||
|
||||
+17
-8
@@ -31,6 +31,8 @@
|
||||
|
||||
class MapperGLCanvas: public QGLWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MapperGLCanvas(QWidget* parent = 0, const QGLWidget * shareWidget = 0);
|
||||
virtual ~MapperGLCanvas() {}
|
||||
@@ -38,18 +40,25 @@ public:
|
||||
virtual Quad& getQuad() = 0;
|
||||
|
||||
protected:
|
||||
virtual void initializeGL();
|
||||
virtual void resizeGL(int width, int height);
|
||||
virtual void paintGL();
|
||||
void initializeGL();
|
||||
void resizeGL(int width, int height);
|
||||
void paintGL();
|
||||
|
||||
virtual void keyPressEvent(QKeyEvent* event);
|
||||
virtual void paintEvent(QPaintEvent* event);
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
void paintEvent(QPaintEvent* event);
|
||||
|
||||
private:
|
||||
virtual void draw();
|
||||
virtual void enterDraw();
|
||||
void draw();
|
||||
void enterDraw();
|
||||
virtual void doDraw() = 0;
|
||||
virtual void exitDraw();
|
||||
void exitDraw();
|
||||
|
||||
signals:
|
||||
void quadChanged();
|
||||
void quadSwitched();
|
||||
|
||||
public slots:
|
||||
void updateCanvas();
|
||||
};
|
||||
|
||||
#endif /* MAPPERGLCANVAS_H_ */
|
||||
|
||||
@@ -24,6 +24,16 @@ SourceGLCanvas::SourceGLCanvas(QWidget* parent)
|
||||
{
|
||||
}
|
||||
|
||||
Quad& SourceGLCanvas::getQuad() {
|
||||
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
|
||||
Q_CHECK_PTR(textureMapping);
|
||||
|
||||
std::tr1::shared_ptr<Quad> inputQuad = std::tr1::static_pointer_cast<Quad>(textureMapping->getInputShape());
|
||||
Q_CHECK_PTR(inputQuad);
|
||||
|
||||
return (*inputQuad);
|
||||
}
|
||||
|
||||
void SourceGLCanvas::doDraw() {
|
||||
// TODO: Ceci est un hack necessaire car tout est en fonction de la width/height de la texture.
|
||||
// Il faut changer ca.
|
||||
|
||||
+4
-9
@@ -27,18 +27,13 @@
|
||||
|
||||
class SourceGLCanvas: public MapperGLCanvas
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SourceGLCanvas(QWidget* parent = 0);
|
||||
// virtual ~SourceGLCanvas() {}
|
||||
|
||||
virtual Quad& getQuad() {
|
||||
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
|
||||
Q_CHECK_PTR(textureMapping);
|
||||
|
||||
std::tr1::shared_ptr<Quad> inputQuad = std::tr1::static_pointer_cast<Quad>(textureMapping->getInputShape());
|
||||
Q_CHECK_PTR(inputQuad);
|
||||
|
||||
return (*inputQuad);
|
||||
}
|
||||
virtual Quad& getQuad();
|
||||
|
||||
private:
|
||||
virtual void doDraw();
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
CONFIG += qt debug
|
||||
TEMPLATE = app
|
||||
SOURCES = main.cpp Common.cpp MapperGLCanvas.cpp SourceGLCanvas.cpp DestinationGLCanvas.cpp
|
||||
HEADERS = Common.h SourceGLCanvas.h DestinationGLCanvas.h MapperGLCanvas.h
|
||||
SOURCES = main.cpp Common.cpp SourceGLCanvas.cpp DestinationGLCanvas.cpp MapperGLCanvas.cpp
|
||||
QT += gui opengl
|
||||
LIBS += -lSOIL -lglut
|
||||
|
||||
|
||||
@@ -24,6 +24,12 @@ int main(int argc, char *argv[])
|
||||
SourceGLCanvas sourceCanvas;
|
||||
DestinationGLCanvas destinationCanvas(0, &sourceCanvas);
|
||||
|
||||
QObject::connect(&sourceCanvas, SIGNAL(quadChanged()),
|
||||
&destinationCanvas, SLOT(updateCanvas()));
|
||||
|
||||
QObject::connect(&destinationCanvas, SIGNAL(quadSwitched()),
|
||||
&sourceCanvas, SLOT(updateCanvas()));
|
||||
|
||||
Common::initializeLibremapper(320, 480);
|
||||
|
||||
QSplitter splitter(Qt::Horizontal);
|
||||
|
||||
Reference in New Issue
Block a user