From 701d6bd0425a5fca73feaeba7e0dbb136743b9cf Mon Sep 17 00:00:00 2001 From: baydam Date: Mon, 14 Oct 2019 19:59:18 +0000 Subject: [PATCH 01/11] Cosmetic changes on console window + Add message log context --- mapmap.pro | 2 +- src/gui/ConsoleWindow.cpp | 4 ++-- src/gui/ConsoleWindow.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mapmap.pro b/mapmap.pro index e59a9f1..001f9e7 100644 --- a/mapmap.pro +++ b/mapmap.pro @@ -6,7 +6,7 @@ TEMPLATE = app VERSION = 0.6.3 TARGET = mapmap -DEFINES += UNICODE QT_THREAD_SUPPORT QT_CORE_LIB QT_GUI_LIB +DEFINES += UNICODE QT_THREAD_SUPPORT QT_CORE_LIB QT_GUI_LIB QT_MESSAGELOGCONTEXT include(src/core/core.pri) include(src/shape/shape.pri) diff --git a/src/gui/ConsoleWindow.cpp b/src/gui/ConsoleWindow.cpp index 9d94f20..5b73116 100644 --- a/src/gui/ConsoleWindow.cpp +++ b/src/gui/ConsoleWindow.cpp @@ -41,7 +41,7 @@ ConsoleWindow::ConsoleWindow(QWidget *parent) : QMainWindow(parent) // Set color scheme QPalette scheme = palette(); - scheme.setColor(QPalette::Base, Qt::black); + scheme.setColor(QPalette::Base, QColor("#00020E")); scheme.setColor(QPalette::Text, Qt::white); _console->setPalette(scheme); @@ -102,7 +102,7 @@ void ConsoleWindow::printMessage(QtMsgType type, const QMessageLogContext &conte debug = "Debug:", info = "Info:", warning = "Warning:", - critical = "Critical:", + critical = "Critical:", fatal = "Fatal!"; // Output QString output; diff --git a/src/gui/ConsoleWindow.h b/src/gui/ConsoleWindow.h index 81be7ca..e9864a9 100644 --- a/src/gui/ConsoleWindow.h +++ b/src/gui/ConsoleWindow.h @@ -72,8 +72,8 @@ private: QMenu *fileMenu; // Constants - static const int CONSOLE_WINDOW_DEFAULT_WIDTH = 640; - static const int CONSOLE_WINDOW_DEFAULT_HEIGHT = 480; + static const int CONSOLE_WINDOW_DEFAULT_WIDTH = 1024; + static const int CONSOLE_WINDOW_DEFAULT_HEIGHT = 768; }; } From 915033df07b1c566e3129a449ab25c618fa39d43 Mon Sep 17 00:00:00 2001 From: baydam Date: Thu, 17 Oct 2019 15:49:09 +0000 Subject: [PATCH 02/11] Extend camera support for Windows and OSX (base on Sofian's work) --- src/core/CameraImpl.cpp | 71 ++++++++++++++++++++++++ src/core/CameraImpl.h | 57 +++++++++++++++++++ src/core/CameraSurface.cpp | 111 +++++++++++++++++++++++++++++++++++++ src/core/CameraSurface.h | 70 +++++++++++++++++++++++ src/core/Paint.cpp | 9 +-- src/core/Paint.h | 8 +++ src/core/VideoImpl.h | 16 +++--- src/core/core.pri | 4 ++ src/gui/MainWindow.cpp | 45 ++++++++------- src/gui/MainWindow.h | 4 +- 10 files changed, 356 insertions(+), 39 deletions(-) create mode 100644 src/core/CameraImpl.cpp create mode 100644 src/core/CameraImpl.h create mode 100644 src/core/CameraSurface.cpp create mode 100644 src/core/CameraSurface.h diff --git a/src/core/CameraImpl.cpp b/src/core/CameraImpl.cpp new file mode 100644 index 0000000..b82d786 --- /dev/null +++ b/src/core/CameraImpl.cpp @@ -0,0 +1,71 @@ +/* + * CameraImpl.cpp + * + * (c) 2019 Dame Diongue -- baydamd(@)gmail(.)com + * + * 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 "CameraImpl.h" + +namespace mmp { + +CameraImpl::CameraImpl() : + _camera(nullptr), + _cameraSurface(nullptr) +{ + +} + +CameraImpl::~CameraImpl() +{ + delete _camera; + delete _cameraSurface; +} + +bool CameraImpl::loadMovie(const QString &path) +{ + VideoImpl::loadMovie(path); + + _camera = new QCamera(path.toLocal8Bit()); + + _cameraSurface = new CameraSurface(); + + _camera->setViewfinder(_cameraSurface); + + if (_camera->isAvailable()) + _camera->start(); + + if (_camera->state() == QCamera::ActiveState) + return true; + + return false; +} + +int CameraImpl::getWidth() const +{ + return _cameraSurface->surfaceFormat().frameWidth(); +} + +int CameraImpl::getHeight() const +{ + return _cameraSurface->surfaceFormat().frameHeight(); +} + +const uchar *CameraImpl::getBits() +{ + return _cameraSurface->bits(); +} + +} diff --git a/src/core/CameraImpl.h b/src/core/CameraImpl.h new file mode 100644 index 0000000..5740a6f --- /dev/null +++ b/src/core/CameraImpl.h @@ -0,0 +1,57 @@ +/* + * CameraImpl.h + * + * (c) 2019 Dame Diongue -- baydamd(@)gmail(.)com + * + * 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 . + */ + +#ifndef CAMERAIMPL_H_ +#define CAMERAIMPL_H_ + +#include "CameraSurface.h" +#include "VideoImpl.h" + +#include +#include + +namespace mmp { + +class CameraImpl : public VideoImpl +{ +public: + CameraImpl(); + ~CameraImpl(); + + bool loadMovie(const QString& path); + bool isLive() { return true; } + + int getWidth() const; + int getHeight() const; + + const uchar* getBits(); + + bool hasBits() const { return _cameraSurface->isActive(); } + + bool bitsHaveChanged() const { return true; } + +private: + QCamera *_camera; + CameraSurface *_cameraSurface; + +}; + +} + +#endif // CAMERAIMPL_H_ diff --git a/src/core/CameraSurface.cpp b/src/core/CameraSurface.cpp new file mode 100644 index 0000000..3ff03e6 --- /dev/null +++ b/src/core/CameraSurface.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "CameraSurface.h" + +#include +#include +#include + +namespace mmp { + +CameraSurface::CameraSurface(QObject *parent) + : QAbstractVideoSurface(parent) +{ +} + +CameraSurface::~CameraSurface() +{ +} + +QList CameraSurface::supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const +{ + + if (handleType == QAbstractVideoBuffer::NoHandle) { + return QList() + << QVideoFrame::Format_ARGB32 + << QVideoFrame::Format_ARGB32_Premultiplied + << QVideoFrame::Format_RGB32 + << QVideoFrame::Format_RGB24 + ; + } else { + return QList(); + } +} + +bool CameraSurface::present(const QVideoFrame &frame) +{ + if (frame.isValid()) { + // Copy current frame. + QVideoFrame currentFrame(frame); + + if (currentFrame.map(QAbstractVideoBuffer::ReadOnly)) + { + QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(currentFrame.pixelFormat()); + if (imageFormat != QImage::Format_Invalid) { + _temporaryImage = QImage(currentFrame.bits(), + currentFrame.width(), + currentFrame.height(), + imageFormat); + } else { + int nbytes = currentFrame.mappedBytes(); + _temporaryImage = QImage::fromData(currentFrame.bits(), nbytes); + } + currentFrame.unmap(); + } + + // Convert to OpenGLformat and apply transforms to straighten. + _temporaryImage = QGLWidget::convertToGLFormat(_temporaryImage) + .mirrored(true, false) + .transformed(QTransform().rotate(180)); + + return true; + } + + return false; +} + +const uchar* CameraSurface::bits() +{ + return _temporaryImage.bits(); +} + +} diff --git a/src/core/CameraSurface.h b/src/core/CameraSurface.h new file mode 100644 index 0000000..f890723 --- /dev/null +++ b/src/core/CameraSurface.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CAMERA_SURFACE_H_ +#define CAMERA_SURFACE_H_ + +#include +#include +#include +#include + +namespace mmp { + +class CameraSurface : public QAbstractVideoSurface +{ + Q_OBJECT +public: + CameraSurface(QObject *parent = nullptr); + ~CameraSurface() override; + + QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const override; + bool present(const QVideoFrame &frame) override; + + const uchar* bits(); + +private: + QImage _temporaryImage; +}; + +} + +#endif // CAMERA_SURFACE_H_ diff --git a/src/core/Paint.cpp b/src/core/Paint.cpp index 98bc5e6..16d35bc 100644 --- a/src/core/Paint.cpp +++ b/src/core/Paint.cpp @@ -21,7 +21,7 @@ #include "Paint.h" #include "VideoImpl.h" #include "VideoUriDecodeBinImpl.h" -#include "VideoV4l2SrcImpl.h" +#include "CameraImpl.h" #include "VideoShmSrcImpl.h" #include @@ -205,19 +205,16 @@ Video::Video(const QString uri_, VideoType type, double rate, uid id): _impl = new VideoUriDecodeBinImpl(); break; case VIDEO_WEBCAM: - _impl = new VideoV4l2SrcImpl(); + _impl = new CameraImpl(); break; case VIDEO_SHMSRC: _impl = new VideoShmSrcImpl(); break; - default: - fprintf (stderr, "Could not determine type for video source\n "); - break; } - //_impl = new VideoShmSrcImpl();//V4l2SrcImpl();//UriDecodeBinImpl(); setRate(rate); setVolume(1); setUri(uri_); + _videoType = type; } // vertigo diff --git a/src/core/Paint.h b/src/core/Paint.h index 217850b..82caa16 100644 --- a/src/core/Paint.h +++ b/src/core/Paint.h @@ -38,6 +38,8 @@ #include "Element.h" #include "Maths.h" +#include + namespace mmp { typedef enum { @@ -202,6 +204,11 @@ public: virtual void read(const QDomElement& obj); virtual void write(QDomElement& obj); + // Get Camera human-readable name from url + QString getCameraNameFromUri(const QString &uri) { + return QCameraInfo(uri.toLocal8Bit()).description(); + } + protected: // Lists QProperties that should NOT be parsed automatically. virtual QList _propertiesSpecial() const { return Paint::_propertiesSpecial() << "x" << "y"; } @@ -353,6 +360,7 @@ protected: QString _uri; QIcon _icon; + VideoType _videoType; /** * Private implementation, so that GStreamer headers don't need diff --git a/src/core/VideoImpl.h b/src/core/VideoImpl.h index de660ca..65e1ba0 100644 --- a/src/core/VideoImpl.h +++ b/src/core/VideoImpl.h @@ -78,12 +78,12 @@ public: /** * Returns the width of the video image. */ - int getWidth() const; + virtual int getWidth() const; /** * Returns the height of the video image. */ - int getHeight() const; + virtual int getHeight() const; /** * Returns the path to the media file being played. @@ -94,13 +94,13 @@ public: * Returns the raw image of the last video frame. * It is currently unused! */ - const uchar* getBits(); + virtual const uchar* getBits(); /// Returns true iff bits have started flowing (ie. if there is at least a first sample available). - bool hasBits() const { return (_currentFrameSample != NULL); } + virtual bool hasBits() const { return (_currentFrameSample != nullptr); } /// Returns true iff bits have changed since last call to getBits(). - bool bitsHaveChanged() const { return _bitsChanged; } + virtual bool bitsHaveChanged() const { return _bitsChanged; } /** * Checks if the pipeline is ready. @@ -112,11 +112,11 @@ public: bool videoIsConnected() const { return _videoIsConnected; } void videoConnect() { _videoIsConnected = true; } - bool videoIsSupported() const { return _queue0 != NULL; } + bool videoIsSupported() const { return _queue0 != nullptr; } bool audioIsConnected() const { return _audioIsConnected; } void audioConnect() { _audioIsConnected = true; } - bool audioIsSupported() const { return _audioqueue0 != NULL; } + bool audioIsSupported() const { return _audioqueue0 != nullptr; } /** * Performs regular updates (checks if movie is ready and checks messages). @@ -195,7 +195,7 @@ public: void unlockMutex(); /// Wait until first data samples are available (blocking). - bool waitForNextBits(int timeout, const uchar** bits=0); + bool waitForNextBits(int timeout, const uchar** bits=nullptr); protected: int _width; diff --git a/src/core/core.pri b/src/core/core.pri index a8df44f..2a1a24f 100644 --- a/src/core/core.pri +++ b/src/core/core.pri @@ -2,6 +2,8 @@ include(../src.pri) HEADERS += $$PWD/Commands.h \ + $$PWD/CameraImpl.h \ + $$PWD/CameraSurface.h \ $$PWD/Element.h \ $$PWD/Mapping.h \ $$PWD/MappingManager.h \ @@ -21,6 +23,8 @@ HEADERS += $$PWD/Commands.h \ $$PWD/Util.h SOURCES += $$PWD/Commands.cpp \ + $$PWD/CameraImpl.cpp \ + $$PWD/CameraSurface.cpp \ $$PWD/Element.cpp \ $$PWD/Mapping.cpp \ $$PWD/MappingManager.cpp \ diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 893803f..566c154 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -628,7 +628,7 @@ void MainWindow::importMedia() void MainWindow::openCameraDevice() { -#if QT_VERSION >= 0x050500 +#if QT_VERSION >= 0x050300 QString device; QList cameras = QCameraInfo::availableCameras(); @@ -665,7 +665,7 @@ void MainWindow::openCameraDevice() } if (!device.isEmpty()) - importMediaFile(device, false); + importMediaFile(device, false, true); #else QMessageBox::warning(this, tr("No camera available"), tr("You can not use this feature!\nNo camera available in your system")); #endif @@ -1060,7 +1060,7 @@ void MainWindow::openRecentVideo() { QAction *action = qobject_cast(sender()); if (action) - importMediaFile(action->data().toString(),false); + importMediaFile(action->data().toString(), false); } bool MainWindow::clearProject() @@ -1126,7 +1126,12 @@ uid MainWindow::createMediaPaint(uid paintId, QString uri, float x, float y, // Add it to the manager. Paint::ptr paint(tex); - paint->setName(strippedName(uri)); + + if (type == VIDEO_WEBCAM) { + paint->setName(tex->getCameraNameFromUri(uri)); + } else { + paint->setName(strippedName(uri)); + } // Add paint to model and return its uid. uid id = mappingManager->addPaint(paint); @@ -1694,16 +1699,14 @@ void MainWindow::createActions() connect(importMediaAction, SIGNAL(triggered()), this, SLOT(importMedia())); // Open camera. -#ifdef Q_OS_LINUX - openCameraAction = new QAction(tr("Open &Camera Device..."), this); - openCameraAction->setShortcut(Qt::CTRL + Qt::Key_C); - openCameraAction->setIcon(QIcon(":/add-camera")); - openCameraAction->setIconVisibleInMenu(false); - openCameraAction->setToolTip(tr("Choose your camera device...")); - openCameraAction->setShortcutContext(Qt::ApplicationShortcut); - addAction(openCameraAction); - connect(openCameraAction, SIGNAL(triggered()), this, SLOT(openCameraDevice())); -#endif + AddCameraAction = new QAction(tr("Open &Camera Device..."), this); + AddCameraAction->setShortcut(Qt::CTRL + Qt::Key_C); + AddCameraAction->setIcon(QIcon(":/add-image")); + AddCameraAction->setIconVisibleInMenu(false); + AddCameraAction->setToolTip(tr("Choose your camera device...")); + AddCameraAction->setShortcutContext(Qt::ApplicationShortcut); + addAction(AddCameraAction); + connect(AddCameraAction, SIGNAL(triggered()), this, SLOT(openCameraDevice())); // Add color. addColorAction = new QAction(tr("Add &Color Source..."), this); @@ -2145,9 +2148,7 @@ void MainWindow::createMenus() fileMenu->addAction(saveAsAction); fileMenu->addSeparator(); fileMenu->addAction(importMediaAction); -#ifdef Q_OS_LINUX - fileMenu->addAction(openCameraAction); -#endif + fileMenu->addAction(AddCameraAction); fileMenu->addAction(addColorAction); // Recent file separator @@ -2309,9 +2310,7 @@ void MainWindow::createToolBars() mainToolBar = addToolBar(tr("&Toolbar")); mainToolBar->setMovable(false); mainToolBar->addAction(importMediaAction); -#ifdef Q_OS_LINUX - mainToolBar->addAction(openCameraAction); -#endif + mainToolBar->addAction(AddCameraAction); mainToolBar->addAction(addColorAction); mainToolBar->addSeparator(); @@ -2319,7 +2318,6 @@ void MainWindow::createToolBars() mainToolBar->addAction(addMeshAction); mainToolBar->addAction(addTriangleAction); mainToolBar->addAction(addEllipseAction); - mainToolBar->addSeparator(); mainToolBar->addAction(outputFullScreenAction); @@ -2706,7 +2704,7 @@ void MainWindow::clearRecentFileList() // { // } -bool MainWindow::importMediaFile(const QString &fileName, bool isImage) +bool MainWindow::importMediaFile(const QString &fileName, bool isImage, bool isCamera) { QFile file(fileName); QDir currentDir; @@ -2715,7 +2713,8 @@ bool MainWindow::importMediaFile(const QString &fileName, bool isImage) if (!fileSupported(fileName, isImage)) return false; - if (fileName.startsWith(QString("/dev/video"))) { +// if (fileName.contains(QString("/dev/video"))) { + if (isCamera) { type = VIDEO_WEBCAM; } diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 305c8a3..765cb85 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -304,7 +304,7 @@ public: bool saveFile(const QString &fileName); void setCurrentFile(const QString &fileName); void setCurrentVideo(const QString &filename); - bool importMediaFile(const QString &fileName, bool isImage); + bool importMediaFile(const QString &fileName, bool isImage = false, bool isCamera = false); bool addColorPaint(const QColor& color); void addMappingItem(uid mappingId); void removeMappingItem(uid mappingId); @@ -378,7 +378,7 @@ private: QAction *newAction; QAction *openAction; QAction *importMediaAction; - QAction *openCameraAction; + QAction *AddCameraAction; QAction *addColorAction; QAction *saveAction; QAction *saveAsAction; From e594581f00132cedd63341d8545ee56f3bb839e7 Mon Sep 17 00:00:00 2001 From: baydam Date: Fri, 18 Oct 2019 13:09:01 +0000 Subject: [PATCH 03/11] Use enumeration instead of string to define constant source type --- src/core/Paint.h | 13 +++++++++---- src/core/ProjectReader.cpp | 4 ++-- src/gui/MainWindow.cpp | 34 ++++++++++++++++++---------------- src/gui/MainWindow.h | 2 ++ 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/core/Paint.h b/src/core/Paint.h index 82caa16..a106640 100644 --- a/src/core/Paint.h +++ b/src/core/Paint.h @@ -68,6 +68,11 @@ protected: Paint(uid id=NULL_UID); public: + + enum SourceType { + Video, Image, Color + }; + typedef QSharedPointer ptr; virtual ~Paint(); @@ -101,7 +106,7 @@ public: /// Unlocks mutex (default = no effect). virtual void unlockMutex() {} - virtual QString getType() const = 0; + virtual SourceType getSourceType() const = 0; protected: virtual void _doPlay() {} @@ -127,7 +132,7 @@ public: QColor getColor() const { return color; } void setColor(const QColor& color_) { color = color_; } - virtual QString getType() const { return "color"; } + virtual SourceType getSourceType() const { return SourceType::Color; } virtual QIcon getIcon() const { QPixmap pixmap(MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE); @@ -253,7 +258,7 @@ public: const QString getUri() const { return _uri; } bool setUri(const QString &uri); - virtual QString getType() const { return "image"; } + virtual SourceType getSourceType() const { return SourceType::Image; } bool isAnimation() const { return (_images.size() > 1); } @@ -319,7 +324,7 @@ public: /// Unlocks mutex (default = no effect). virtual void unlockMutex(); - virtual QString getType() const { return "media"; } + virtual SourceType getSourceType() const { return SourceType::Video; } virtual int getWidth() const; virtual int getHeight() const; diff --git a/src/core/ProjectReader.cpp b/src/core/ProjectReader.cpp index bffa2b7..96d3fd3 100644 --- a/src/core/ProjectReader.cpp +++ b/src/core/ProjectReader.cpp @@ -101,14 +101,14 @@ void ProjectReader::parseProject(const QDomElement& project) _window->addPaintItem(paint->getId(), paint->getIcon(), paint->getName()); // Locate media file if not found - if (paint->getType() == "media") + if (paint->getSourceType() == Paint::SourceType::Video) { QSharedPointer