2014-12-12 15:08:31 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vobjpaintdevice.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 6 12, 2014
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2014-12-12 15:08:31 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2014-12-12 15:08:31 +01:00
|
|
|
**
|
|
|
|
** Valentina 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.
|
|
|
|
**
|
|
|
|
** Valentina 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 Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vobjpaintdevice.h"
|
|
|
|
|
|
|
|
#include <QFile>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QIODevice>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
|
|
|
#include "vobjengine.h"
|
|
|
|
|
2014-12-12 15:08:31 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VObjPaintDevice::VObjPaintDevice()
|
2023-08-12 09:31:10 +02:00
|
|
|
: QPaintDevice(),
|
|
|
|
engine(new VObjEngine()),
|
|
|
|
fileName(),
|
|
|
|
owns_iodevice(1)
|
2014-12-12 15:08:31 +01:00
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
owns_iodevice = static_cast<int>(false);
|
2014-12-12 15:08:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VObjPaintDevice::~VObjPaintDevice()
|
|
|
|
{
|
|
|
|
if (owns_iodevice)
|
|
|
|
{
|
|
|
|
delete engine->getOutputDevice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VObjPaintDevice::paintEngine() const -> QPaintEngine *
|
2014-12-12 15:08:31 +01:00
|
|
|
{
|
2015-10-20 16:32:01 +02:00
|
|
|
return engine.data();
|
2014-12-12 15:08:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VObjPaintDevice::getFileName() const -> QString
|
2014-12-12 15:08:31 +01:00
|
|
|
{
|
|
|
|
return fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VObjPaintDevice::setFileName(const QString &value)
|
|
|
|
{
|
|
|
|
if (engine->isActive())
|
|
|
|
{
|
|
|
|
qWarning("VObjPaintDevice::setFileName(), cannot set file name while OBJ is being generated");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (owns_iodevice)
|
|
|
|
{
|
|
|
|
delete engine->getOutputDevice();
|
|
|
|
}
|
|
|
|
|
2015-10-28 15:22:36 +01:00
|
|
|
owns_iodevice = static_cast<int>(true);
|
2014-12-12 15:08:31 +01:00
|
|
|
|
|
|
|
fileName = value;
|
2024-02-19 17:15:42 +01:00
|
|
|
auto *file = new QFile(fileName);
|
2014-12-12 15:08:31 +01:00
|
|
|
engine->setOutputDevice(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VObjPaintDevice::getSize() -> QSize
|
2014-12-12 15:08:31 +01:00
|
|
|
{
|
|
|
|
return engine->getSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VObjPaintDevice::setSize(const QSize &size)
|
|
|
|
{
|
|
|
|
if (engine->isActive())
|
|
|
|
{
|
|
|
|
qWarning("VObjPaintDevice::setSize(), cannot set size while OBJ is being generated");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
engine->setSize(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VObjPaintDevice::getOutputDevice() -> QIODevice *
|
2014-12-12 15:08:31 +01:00
|
|
|
{
|
|
|
|
return engine->getOutputDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VObjPaintDevice::setOutputDevice(QIODevice *outputDevice)
|
|
|
|
{
|
|
|
|
if (engine->isActive())
|
|
|
|
{
|
|
|
|
qWarning("VObjPaintDevice::setOutputDevice(), cannot set output device while OBJ is being generated");
|
|
|
|
return;
|
|
|
|
}
|
2015-10-28 15:22:36 +01:00
|
|
|
owns_iodevice = static_cast<int>(false);
|
2014-12-12 15:08:31 +01:00
|
|
|
engine->setOutputDevice(outputDevice);
|
|
|
|
fileName = QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VObjPaintDevice::getResolution() const -> int
|
2014-12-12 15:08:31 +01:00
|
|
|
{
|
|
|
|
return engine->getResolution();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VObjPaintDevice::setResolution(int dpi)
|
|
|
|
{
|
|
|
|
engine->setResolution(dpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VObjPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const -> int
|
2014-12-12 15:08:31 +01:00
|
|
|
{
|
|
|
|
switch (metric)
|
|
|
|
{
|
|
|
|
case QPaintDevice::PdmDepth:
|
|
|
|
return 32;
|
|
|
|
case QPaintDevice::PdmWidth:
|
|
|
|
return engine->getSize().width();
|
|
|
|
case QPaintDevice::PdmHeight:
|
|
|
|
return engine->getSize().height();
|
|
|
|
case QPaintDevice::PdmHeightMM:
|
|
|
|
return qRound(engine->getSize().height() * 25.4 / engine->getResolution());
|
|
|
|
case QPaintDevice::PdmWidthMM:
|
|
|
|
return qRound(engine->getSize().width() * 25.4 / engine->getResolution());
|
|
|
|
case QPaintDevice::PdmNumColors:
|
2015-03-16 13:23:02 +01:00
|
|
|
return static_cast<int>(0xffffffff);
|
2016-12-21 20:35:07 +01:00
|
|
|
case QPaintDevice::PdmDpiX:
|
|
|
|
case QPaintDevice::PdmDpiY:
|
2014-12-12 15:08:31 +01:00
|
|
|
case QPaintDevice::PdmPhysicalDpiX:
|
|
|
|
case QPaintDevice::PdmPhysicalDpiY:
|
|
|
|
return engine->getResolution();
|
2015-09-12 00:24:39 +02:00
|
|
|
case QPaintDevice::PdmDevicePixelRatio:
|
2016-11-19 09:13:51 +01:00
|
|
|
case QPaintDevice::PdmDevicePixelRatioScaled:
|
2015-09-12 00:24:39 +02:00
|
|
|
return 1;
|
2014-12-12 15:08:31 +01:00
|
|
|
default:
|
|
|
|
qWarning("VObjPaintDevice::metric(), unhandled metric %d\n", metric);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|