From eef76173b6eed76584f01bcd1fa0fe7e9845f676 Mon Sep 17 00:00:00 2001 From: Tats Date: Thu, 16 Oct 2014 17:52:32 +0000 Subject: [PATCH] Integrated paint guis while removing remains of oldPaint/double-click system. --- MainWindow.cpp | 31 +++++++++++++++---------------- MainWindow.h | 8 ++++---- ProjectReader.cpp | 5 ++--- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/MainWindow.cpp b/MainWindow.cpp index 16c565a..4f4f28e 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -216,6 +216,9 @@ void MainWindow::handlePaintChanged(Paint::ptr paint) { uid paintId = mappingManager->getPaintId(paint); if (paint->getType() == "media") { + std::tr1::shared_ptr media = std::tr1::static_pointer_cast(paint); + Q_CHECK_PTR(media); + updatePaintItem(paintId, QIcon(), strippedName(media->getUri())); // QString fileName = QFileDialog::getOpenFileName(this, // tr("Import media source file"), "."); // // Restart video playback. XXX Hack @@ -223,6 +226,9 @@ void MainWindow::handlePaintChanged(Paint::ptr paint) { // importMediaFile(fileName, paint, false); } if (paint->getType() == "image") { + std::tr1::shared_ptr image = std::tr1::static_pointer_cast(paint); + Q_CHECK_PTR(image); + updatePaintItem(paintId, QIcon(), strippedName(image->getUri())); // QString fileName = QFileDialog::getOpenFileName(this, // tr("Import media source file"), "."); // // Restart video playback. XXX Hack @@ -351,7 +357,7 @@ void MainWindow::importVideo() videoTimer->start(); if (!fileName.isEmpty()) - importMediaFile(fileName, std::tr1::shared_ptr(static_cast(0)), false); + importMediaFile(fileName, false); } void MainWindow::importImage() @@ -368,7 +374,7 @@ void MainWindow::importImage() videoTimer->start(); if (!fileName.isEmpty()) - importMediaFile(fileName, std::tr1::shared_ptr(static_cast(0)), true); + importMediaFile(fileName, true); } void MainWindow::addColor() @@ -380,7 +386,7 @@ void MainWindow::addColor() QColor initialColor; QColor color = QColorDialog::getColor(initialColor, this); if (color.isValid()) - addColorPaint(color, std::tr1::shared_ptr(static_cast(0))); + addColorPaint(color); // Restart video playback. XXX Hack videoTimer->start(); @@ -617,7 +623,7 @@ bool MainWindow::clearProject() return true; } -uid MainWindow::createMediaPaint(uid paintId, QString uri, float x, float y, Paint::ptr oldPaint, bool isImage) +uid MainWindow::createMediaPaint(uid paintId, QString uri, float x, float y, bool isImage) { // Cannot create image with already existing id. if (Paint::getUidAllocator().exists(paintId)) @@ -640,20 +646,13 @@ uid MainWindow::createMediaPaint(uid paintId, QString uri, float x, float y, Pai // Add paint to model and return its uid. uid id = mappingManager->addPaint(paint); - // If replacing existing paint, extra work needs to be done - if (oldPaint.get()) { - mappingManager->replacePaintMappings(oldPaint, paint); - deletePaint(oldPaint->getId(), true); - emit paintChanged(); - } - // Add paint widget item. addPaintItem(id, QIcon(uri), strippedName(uri)); return id; } } -uid MainWindow::createColorPaint(uid paintId, QColor color, Paint::ptr oldPaint) +uid MainWindow::createColorPaint(uid paintId, QColor color) { // Cannot create image with already existing id. if (Paint::getUidAllocator().exists(paintId)) @@ -1465,7 +1464,7 @@ void MainWindow::setCurrentFile(const QString &fileName) // { // } -bool MainWindow::importMediaFile(const QString &fileName, Paint::ptr oldPaint, bool isImage) +bool MainWindow::importMediaFile(const QString &fileName, bool isImage) { QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { @@ -1479,7 +1478,7 @@ bool MainWindow::importMediaFile(const QString &fileName, Paint::ptr oldPaint, b QApplication::setOverrideCursor(Qt::WaitCursor); // Add media file to model. - uint mediaId = createMediaPaint(NULL_UID, fileName, 0, 0, oldPaint, isImage); + uint mediaId = createMediaPaint(NULL_UID, fileName, 0, 0, isImage); // Initialize position (center). std::tr1::shared_ptr media = std::tr1::static_pointer_cast(mappingManager->getPaintById(mediaId)); @@ -1500,12 +1499,12 @@ bool MainWindow::importMediaFile(const QString &fileName, Paint::ptr oldPaint, b return true; } -bool MainWindow::addColorPaint(const QColor& color, Paint::ptr oldPaint) +bool MainWindow::addColorPaint(const QColor& color) { QApplication::setOverrideCursor(Qt::WaitCursor); // Add color to model. - uint colorId = createColorPaint(NULL_UID, color, oldPaint); + uint colorId = createColorPaint(NULL_UID, color); // Initialize position (center). std::tr1::shared_ptr colorPaint = std::tr1::static_pointer_cast(mappingManager->getPaintById(colorId)); diff --git a/MainWindow.h b/MainWindow.h index 17ed798..5664293 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -115,10 +115,10 @@ public slots: bool clearProject(); /// Create or replace a media paint (or image). - uid createMediaPaint(uid paintId, QString uri, float x, float y, Paint::ptr oldPaint, bool isImage); + uid createMediaPaint(uid paintId, QString uri, float x, float y, bool isImage); /// Create or replace a color paint. - uid createColorPaint(uid paintId, QColor color, Paint::ptr oldPaint); + uid createColorPaint(uid paintId, QColor color); /// Creates a textured mesh. uid createMeshTextureMapping(uid mappingId, @@ -188,8 +188,8 @@ public: bool loadFile(const QString &fileName); bool saveFile(const QString &fileName); void setCurrentFile(const QString &fileName); - bool importMediaFile(const QString &fileName, Paint::ptr oldPaint, bool isImage); - bool addColorPaint(const QColor& color, Paint::ptr oldPaint); + bool importMediaFile(const QString &fileName, bool isImage); + bool addColorPaint(const QColor& color); void addMappingItem(uid mappingId); void removeMappingItem(uid mappingId); void addPaintItem(uid paintId, const QIcon& icon, const QString& name); diff --git a/ProjectReader.cpp b/ProjectReader.cpp index 7448d4e..e646da8 100644 --- a/ProjectReader.cpp +++ b/ProjectReader.cpp @@ -96,8 +96,7 @@ void ProjectReader::parsePaint(const QDomElement& paint) QString x = paint.firstChildElement("x").text(); QString y = paint.firstChildElement("y").text(); - uid id = _window->createMediaPaint(paintAttrId.toInt(), uri, x.toFloat(), y.toFloat(), - std::tr1::shared_ptr(static_cast(0)), paintAttrType == "image"); + uid id = _window->createMediaPaint(paintAttrId.toInt(), uri, x.toFloat(), y.toFloat(), paintAttrType == "image"); if (id == NULL_UID) _xml.raiseError(QObject::tr("Cannot create media with uri %1.").arg(uri)); } @@ -106,7 +105,7 @@ void ProjectReader::parsePaint(const QDomElement& paint) QString rgb = paint.firstChildElement("rgb").text(); QColor color(rgb); - uid id = _window->createColorPaint(paintAttrId.toInt(), color, std::tr1::shared_ptr(static_cast(0))); + uid id = _window->createColorPaint(paintAttrId.toInt(), color); if (id == NULL_UID) _xml.raiseError(QObject::tr("Cannot create color with RGB hex code %1.").arg(rgb));