mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Merged latest changes from develop
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
#include <QVariant>
|
||||
#include <QMetaObject>
|
||||
#include <QHash>
|
||||
#include <QPair>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "MainWindow.h"
|
||||
|
||||
/**
|
||||
* Facade to control the application.
|
||||
*
|
||||
* TODO: implement it.
|
||||
* TODO: include it in the project
|
||||
* TODO: add signals
|
||||
* TODO: the whole app should use actual QObject for properties of everything
|
||||
*/
|
||||
class Controller
|
||||
{
|
||||
public:
|
||||
Controller(MainWindow *owner);
|
||||
// CRUD
|
||||
template<class T> void registerObjType(const char* objType);
|
||||
bool createObject(const char *objType, const char *objName);
|
||||
bool listObjects(const char *objType, QList<QString> &objNames);
|
||||
bool destroyObject(const char *objName);
|
||||
//FIXME: The original prototype functions for these had QVariantList
|
||||
// arguments. FOr now these 2 functions set/get a single QVariant for a
|
||||
// single property, but we can change this easily.
|
||||
bool setObjectProperty(const char* objName, const char* propName,
|
||||
const QVariant &value);
|
||||
bool getObjectProperty(const char *objName, const char *propName,
|
||||
QVariant &value);
|
||||
bool listObjectProperties(const char *objName, QList<QString> &names,
|
||||
QVariantList &values);
|
||||
bool saveProject(const char *fileName);
|
||||
bool loadProject(const char *fileName);
|
||||
bool quit();
|
||||
struct strCmp {
|
||||
bool operator()( const char* s1, const char* s2 ) const {
|
||||
return strcmp( s1, s2 ) < 0;
|
||||
}
|
||||
};
|
||||
private:
|
||||
MainWindow *_owner;
|
||||
std::map<const char*, const QMetaObject *, strCmp> _mControllerTypes;
|
||||
std::map<const char*, QObject *, strCmp> _mControllerObjects;
|
||||
};
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Facade.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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Facade.h"
|
||||
#include <iostream>
|
||||
|
||||
Facade::Facade(MappingManager *manager, MainWindow *window) :
|
||||
_manager(manager),
|
||||
_window(window)
|
||||
{
|
||||
}
|
||||
|
||||
bool Facade::clearProject()
|
||||
{
|
||||
std::cout << "TODO: Facade::clearProject" << std::endl;
|
||||
}
|
||||
|
||||
bool Facade::createImagePaint(const char *paint_id, const char *uri)
|
||||
{
|
||||
std::cout << "TODO: Facade::createImagePaint" << std::endl;
|
||||
}
|
||||
|
||||
bool Facade::updateImagePaintUri(const char *paint_id, const char *uri)
|
||||
{
|
||||
std::cout << "TODO: Facade::updateImagePaintUri" << std::endl;
|
||||
}
|
||||
|
||||
bool Facade::createMeshTextureMapping(const char *mapping_id, const char *paint_id,
|
||||
int n_rows, int n_cols,
|
||||
const QList<QPointF> &src, const QList<QPointF> &dst)
|
||||
{
|
||||
std::cout << "TODO: Facade::createMeshTextureMapping" << std::endl;
|
||||
}
|
||||
|
||||
bool Facade::createTriangleTextureMapping(const char *mapping_id, const char *paint_id,
|
||||
const QList<QPointF> &src, const QList<QPointF> &dst)
|
||||
{
|
||||
std::cout << "TODO: Facade::createTriangleTextureMapping" << std::endl;
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Facade.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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "MappingManager.h"
|
||||
#include "MainWindow.h"
|
||||
|
||||
/**
|
||||
* Facade to control the application.
|
||||
*/
|
||||
class Facade
|
||||
{
|
||||
public:
|
||||
Facade(MappingManager *manager, MainWindow *window);
|
||||
/**
|
||||
* Clears all mappings and paints.
|
||||
*/
|
||||
bool clearProject();
|
||||
/**
|
||||
* Create an image paint.
|
||||
*/
|
||||
bool createImagePaint(const char *paint_id, const char *uri);
|
||||
/**
|
||||
* Sets the image file to use in an image paint.
|
||||
*/
|
||||
bool updateImagePaintUri(const char *paint_id, const char *uri);
|
||||
/**
|
||||
* Creates a textured mesh.
|
||||
*/
|
||||
bool createMeshTextureMapping(const char *mapping_id, const char *paint_id,
|
||||
int n_rows, int n_cols,
|
||||
const QList<QPointF> &src, const QList<QPointF> &dst);
|
||||
/**
|
||||
* Creates a textured triangle.
|
||||
*/
|
||||
bool createTriangleTextureMapping(const char *mapping_id, const char *paint_id,
|
||||
const QList<QPointF> &src, const QList<QPointF> &dst);
|
||||
/**
|
||||
* Quits the application.
|
||||
*/
|
||||
// bool quit();
|
||||
|
||||
// TODO:
|
||||
// bool loadProject(const char *project_file);
|
||||
// bool saveProject(const char *project_file);
|
||||
// bool deleteMapping(const char *mapping_id);
|
||||
// bool deletePaint(const char *paint_id);
|
||||
// bool listMappings(QList<QString> &result) const;
|
||||
// bool listPaints(QList<QString> &result) const;
|
||||
// bool setMappingPoints(const char *mapping_id,
|
||||
// const QList<QPointF> &src, const QList<QPointF> &dst);
|
||||
// bool getMapping(const char *mapping_id, Mapping &mapping);
|
||||
// bool getPaint(const char *paint_id, Paint &paint);
|
||||
private:
|
||||
MappingManager *_manager;
|
||||
MainWindow *_window;
|
||||
};
|
||||
|
||||
+21
-7
@@ -21,7 +21,6 @@
|
||||
#include "MainWindow.h"
|
||||
#include "ProjectWriter.h"
|
||||
#include "ProjectReader.h"
|
||||
#include "Facade.h"
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
@@ -212,6 +211,7 @@ void MainWindow::handlePaintChanged(Paint::ptr paint) {
|
||||
// Change currently selected item.
|
||||
uid curMappingId = getCurrentMappingId();
|
||||
removeCurrentMapping();
|
||||
removeCurrentPaint();
|
||||
|
||||
uid paintId = mappingManager->getPaintId(paint);
|
||||
|
||||
@@ -240,7 +240,6 @@ void MainWindow::handlePaintChanged(Paint::ptr paint) {
|
||||
setCurrentMapping(curMappingId);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
// Stop video playback to avoid lags. XXX Hack
|
||||
@@ -670,7 +669,6 @@ uid MainWindow::createColorPaint(uid paintId, QColor color, Paint::ptr oldPaint)
|
||||
// Add paint to model and return its uid.
|
||||
uid id = mappingManager->addPaint(paint);
|
||||
|
||||
// Create a small icon with the color.
|
||||
// Add paint widget item.
|
||||
addPaintItem(id, createColorIcon(color), strippedName(color.name()));
|
||||
|
||||
@@ -1186,6 +1184,19 @@ void MainWindow::createActions()
|
||||
connect(displayCanvasControls, SIGNAL(toggled(bool)), sourceCanvas, SLOT(enableDisplayControls(bool)));
|
||||
connect(displayCanvasControls, SIGNAL(toggled(bool)), destinationCanvas, SLOT(enableDisplayControls(bool)));
|
||||
connect(displayCanvasControls, SIGNAL(toggled(bool)), outputWindow->getCanvas(), SLOT(enableDisplayControls(bool)));
|
||||
|
||||
// Toggle sticky vertices
|
||||
stickyVertices = new QAction(tr("&Sticky vertices"), this);
|
||||
// stickyVertices->setShortcut(tr("Ctrl+E"));
|
||||
stickyVertices->setIcon(QIcon(":/control-points"));
|
||||
stickyVertices->setStatusTip(tr("Enable sticky vertices"));
|
||||
stickyVertices->setIconVisibleInMenu(false);
|
||||
stickyVertices->setCheckable(true);
|
||||
stickyVertices->setChecked(true);
|
||||
// Manage sticky vertices
|
||||
connect(stickyVertices, SIGNAL(toggled(bool)), sourceCanvas, SLOT(enableStickyVertices(bool)));
|
||||
connect(stickyVertices, SIGNAL(toggled(bool)), destinationCanvas, SLOT(enableStickyVertices(bool)));
|
||||
connect(stickyVertices, SIGNAL(toggled(bool)), outputWindow->getCanvas(), SLOT(enableStickyVertices(bool)));
|
||||
}
|
||||
|
||||
void MainWindow::createMenus()
|
||||
@@ -1224,6 +1235,7 @@ void MainWindow::createMenus()
|
||||
viewMenu->addAction(displayOutputWindow);
|
||||
viewMenu->addAction(outputWindowFullScreen);
|
||||
viewMenu->addAction(displayCanvasControls);
|
||||
viewMenu->addAction(stickyVertices);
|
||||
|
||||
// Run.
|
||||
runMenu = menuBar->addMenu(tr("&Run"));
|
||||
@@ -1285,6 +1297,7 @@ void MainWindow::createToolBars()
|
||||
mainToolBar->addAction(displayOutputWindow);
|
||||
mainToolBar->addAction(outputWindowFullScreen);
|
||||
mainToolBar->addAction(displayCanvasControls);
|
||||
mainToolBar->addAction(stickyVertices);
|
||||
|
||||
runToolBar = addToolBar(tr("&Run"));
|
||||
runToolBar->setIconSize(QSize(MM::TOP_TOOLBAR_ICON_SIZE, MM::TOP_TOOLBAR_ICON_SIZE));
|
||||
@@ -1341,6 +1354,7 @@ void MainWindow::readSettings()
|
||||
canvasSplitter->restoreState(settings.value("canvasSplitter").toByteArray());
|
||||
outputWindow->restoreGeometry(settings.value("outputWindow").toByteArray());
|
||||
displayOutputWindow->setChecked(settings.value("displayOutputWindow").toBool());
|
||||
outputWindowFullScreen->setChecked(settings.value("outputWindowFullScreen").toBool());
|
||||
config_osc_receive_port = settings.value("osc_receive_port", 12345).toInt();
|
||||
}
|
||||
|
||||
@@ -1352,10 +1366,10 @@ void MainWindow::writeSettings()
|
||||
settings.setValue("mainSplitter", mainSplitter->saveState());
|
||||
settings.setValue("paintSplitter", paintSplitter->saveState());
|
||||
settings.setValue("mappingSplitter", mappingSplitter->saveState());
|
||||
// settings.setValue("resourceSplitter", resourceSplitter->saveState());
|
||||
settings.setValue("canvasSplitter", canvasSplitter->saveState());
|
||||
settings.setValue("outputWindow", outputWindow->saveGeometry());
|
||||
settings.setValue("displayOutputWindow", displayOutputWindow->isChecked());
|
||||
settings.setValue("outputWindowFullScreen", outputWindowFullScreen->isChecked());
|
||||
settings.setValue("osc_receive_port", config_osc_receive_port);
|
||||
}
|
||||
|
||||
@@ -1548,13 +1562,13 @@ void MainWindow::addPaintItem(uid paintId, const QIcon& icon, const QString& nam
|
||||
// Set size.
|
||||
item->setSizeHint(QSize(item->sizeHint().width(), MainWindow::PAINT_LIST_ITEM_HEIGHT));
|
||||
|
||||
// Switch to paint tab.
|
||||
contentTab->setCurrentWidget(paintSplitter);
|
||||
|
||||
// Add item to paint list.
|
||||
paintList->addItem(item);
|
||||
paintList->setCurrentItem(item);
|
||||
|
||||
// Switch to paint tab.
|
||||
contentTab->setCurrentWidget(paintSplitter);
|
||||
|
||||
// Window was modified.
|
||||
windowModified();
|
||||
}
|
||||
|
||||
@@ -256,6 +256,7 @@ private:
|
||||
QAction *displayOutputWindow;
|
||||
QAction *outputWindowFullScreen;
|
||||
QAction *displayCanvasControls;
|
||||
QAction *stickyVertices;
|
||||
|
||||
// Widgets and layout.
|
||||
QTabWidget* contentTab;
|
||||
|
||||
+52
-15
@@ -25,11 +25,12 @@
|
||||
MapperGLCanvas::MapperGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget)
|
||||
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent, shareWidget),
|
||||
_mainWindow(mainWindow),
|
||||
_mousepressed(false),
|
||||
_mousePressedToDragVertex(false),
|
||||
_activeVertex(NO_VERTEX),
|
||||
_shapeGrabbed(false), // comment out?
|
||||
_shapeFirstGrab(false), // comment out?
|
||||
_displayControls(true)
|
||||
_displayControls(true),
|
||||
_stickyVertices(true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -99,30 +100,62 @@ Shape* MapperGLCanvas::getCurrentShape()
|
||||
|
||||
void MapperGLCanvas::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
int i, dist, maxdist, mindist;
|
||||
int i;
|
||||
int dist;
|
||||
int max_distance_to_consider;
|
||||
int distance_of_the_closest;
|
||||
int xmouse = event->x();
|
||||
int ymouse = event->y();
|
||||
const QPointF& mousePos = event->posF();
|
||||
// Note: we compare with the square value for fastest computation of the distance
|
||||
maxdist = mindist = MM::VERTEX_SELECT_RADIUS * MM::VERTEX_SELECT_RADIUS;
|
||||
max_distance_to_consider = MM::VERTEX_SELECT_RADIUS * MM::VERTEX_SELECT_RADIUS;
|
||||
distance_of_the_closest = max_distance_to_consider;
|
||||
|
||||
// Drag the closest vertex
|
||||
if (event->buttons() & Qt::LeftButton)
|
||||
{
|
||||
Shape* shape = getCurrentShape();
|
||||
if (shape)
|
||||
{
|
||||
// find the ID of the nearest vertex: (from the selected shape)
|
||||
for (i = 0; i < shape->nVertices(); i++)
|
||||
{
|
||||
dist = distSq(mousePos, shape->getVertex(i)); // squared distance
|
||||
if (dist < maxdist && dist < mindist)
|
||||
if (dist < distance_of_the_closest)
|
||||
{
|
||||
_activeVertex = i;
|
||||
mindist = dist;
|
||||
distance_of_the_closest = dist;
|
||||
_mousePressedToDragVertex = true;
|
||||
}
|
||||
}
|
||||
_mousepressed = true;
|
||||
if (_mousePressedToDragVertex) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event->buttons() & Qt::RightButton)
|
||||
|
||||
if (event->buttons() & Qt::LeftButton)
|
||||
{
|
||||
// Select a shape with a click
|
||||
Shape* orig = getCurrentShape();
|
||||
MappingManager manager = getMainWindow()->getMappingManager();
|
||||
QVector<Mapping::ptr> mappings = manager.getVisibleMappings();
|
||||
for (QVector<Mapping::ptr>::const_iterator it = mappings.end() - 1; it >= mappings.begin(); --it)
|
||||
{
|
||||
Shape *shape = getShapeFromMappingId((*it)->getId());
|
||||
if (shape && shape->includesPoint(xmouse, ymouse))
|
||||
{
|
||||
if (shape != orig)
|
||||
{
|
||||
getMainWindow()->setCurrentMapping((*it)->getId());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Drag the currently selected shape
|
||||
if (event->buttons() & Qt::LeftButton)
|
||||
{
|
||||
Shape* shape = getCurrentShape();
|
||||
if (shape && shape->includesPoint(xmouse, ymouse))
|
||||
@@ -137,14 +170,13 @@ void MapperGLCanvas::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
// std::cout << "Mouse Release event " << std::endl;
|
||||
_mousepressed = false;
|
||||
_mousePressedToDragVertex = false;
|
||||
_shapeGrabbed = false;
|
||||
}
|
||||
|
||||
void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
|
||||
if (_mousepressed)
|
||||
if (_mousePressedToDragVertex)
|
||||
{
|
||||
// std::cout << "Move event " << std::endl;
|
||||
Shape* shape = getCurrentShape();
|
||||
@@ -156,7 +188,8 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event)
|
||||
p.setY(event->y());
|
||||
|
||||
// Stick to vertices.
|
||||
glueVertex(shape, &p);
|
||||
if (stickyVertices())
|
||||
glueVertex(shape, &p);
|
||||
shape->setVertex(_activeVertex, p);
|
||||
|
||||
update();
|
||||
@@ -182,7 +215,6 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event)
|
||||
// Update previous mouse position.
|
||||
prevMousePosition.setX( event->x() );
|
||||
prevMousePosition.setY( event->y() );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,6 +286,11 @@ void MapperGLCanvas::enableDisplayControls(bool display)
|
||||
updateCanvas();
|
||||
}
|
||||
|
||||
void MapperGLCanvas::enableStickyVertices(bool value)
|
||||
{
|
||||
_stickyVertices = value;
|
||||
}
|
||||
|
||||
/* Stick vertex p of Shape orig to another Shape's vertex, if the 2 vertices are
|
||||
* close enough. The distance per coordinate is currently set in dist_stick
|
||||
* variable. Perhaps the sticky-sensitivity should be configurable through GUI */
|
||||
@@ -275,7 +312,7 @@ void MapperGLCanvas::glueVertex(Shape *orig, QPointF *p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapperGLCanvas::deselectAll()
|
||||
@@ -283,5 +320,5 @@ void MapperGLCanvas::deselectAll()
|
||||
_activeVertex = NO_VERTEX;
|
||||
_shapeGrabbed = false;
|
||||
_shapeFirstGrab = false;
|
||||
_mousepressed = false;
|
||||
_mousePressedToDragVertex = false;
|
||||
}
|
||||
|
||||
+4
-1
@@ -52,6 +52,7 @@ public:
|
||||
|
||||
MainWindow* getMainWindow() const { return _mainWindow; }
|
||||
bool displayControls() const { return _displayControls; }
|
||||
bool stickyVertices() const { return _stickyVertices; }
|
||||
|
||||
protected:
|
||||
void initializeGL();
|
||||
@@ -71,11 +72,12 @@ private:
|
||||
void exitDraw(QPainter* painter);
|
||||
|
||||
MainWindow* _mainWindow;
|
||||
bool _mousepressed;
|
||||
bool _mousePressedToDragVertex;
|
||||
int _activeVertex;
|
||||
bool _shapeGrabbed;
|
||||
bool _shapeFirstGrab;
|
||||
bool _displayControls;
|
||||
bool _stickyVertices;
|
||||
|
||||
signals:
|
||||
void shapeChanged(Shape*);
|
||||
@@ -84,6 +86,7 @@ signals:
|
||||
public slots:
|
||||
void updateCanvas();
|
||||
void enableDisplayControls(bool display);
|
||||
void enableStickyVertices(bool display);
|
||||
void deselectAll();
|
||||
|
||||
public:
|
||||
|
||||
+8
-2
@@ -52,8 +52,14 @@ void OutputGLWindow::keyPressEvent(QKeyEvent *event)
|
||||
setFullScreen(false);
|
||||
emit fullScreenToggled(false);
|
||||
}
|
||||
else if (event->key() == Qt::Key_Escape)
|
||||
{
|
||||
// pass
|
||||
}
|
||||
else
|
||||
{
|
||||
QDialog::keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +84,7 @@ void OutputGLWindow::setFullScreen(bool fullscreen)
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
// Special case for Unity.
|
||||
if (session == "ubuntu") {
|
||||
if (session == "ubuntu" || session == "gnome") {
|
||||
setWindowState( windowState() | Qt::WindowFullScreen | Qt::WindowMaximized);
|
||||
setWindowFlags(Qt::Dialog);
|
||||
show();
|
||||
@@ -96,7 +102,7 @@ void OutputGLWindow::setFullScreen(bool fullscreen)
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
// Special case for Unity.
|
||||
if (session == "ubuntu") {
|
||||
if (session == "ubuntu" || session == "gnome") {
|
||||
setWindowState( windowState() & ~Qt::WindowFullScreen);
|
||||
} else {
|
||||
showNormal();
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ DEFINES += UNICODE QT_THREAD_SUPPORT QT_CORE_LIB QT_GUI_LIB
|
||||
|
||||
HEADERS = \
|
||||
DestinationGLCanvas.h \
|
||||
MM.h \
|
||||
MainApplication.h \
|
||||
MainWindow.h \
|
||||
Mapper.h \
|
||||
@@ -29,6 +30,7 @@ HEADERS = \
|
||||
|
||||
SOURCES = \
|
||||
DestinationGLCanvas.cpp \
|
||||
MM.cpp \
|
||||
MainApplication.cpp \
|
||||
MainWindow.cpp \
|
||||
Mapper.cpp \
|
||||
@@ -39,7 +41,6 @@ SOURCES = \
|
||||
OscInterface.cpp \
|
||||
OscReceiver.cpp \
|
||||
OutputGLWindow.cpp \
|
||||
MM.cpp \
|
||||
Paint.cpp \
|
||||
PaintGui.cpp \
|
||||
ProjectReader.cpp \
|
||||
|
||||
Reference in New Issue
Block a user