2015-06-12 10:55:44 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file def.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 11 6, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-06-12 10:55:44 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2015-06-12 10:55:44 +02: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 "def.h"
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QChar>
|
|
|
|
#include <QColor>
|
2015-10-16 19:26:05 +02:00
|
|
|
#include <QComboBox>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QCursor>
|
2015-10-31 13:41:52 +01:00
|
|
|
#include <QDir>
|
2017-04-12 14:50:48 +02:00
|
|
|
#include <QDirIterator>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QLatin1Char>
|
|
|
|
#include <QList>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QPixmap>
|
2015-11-09 12:33:36 +01:00
|
|
|
#include <QPrinterInfo>
|
2016-06-18 15:57:07 +02:00
|
|
|
#include <QProcess>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QRgb>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <QtDebug>
|
2017-08-01 13:35:48 +02:00
|
|
|
#include <QPixmapCache>
|
|
|
|
#include <QGraphicsItem>
|
2018-03-14 14:39:15 +01:00
|
|
|
#include <QGlobalStatic>
|
2020-07-07 16:48:26 +02:00
|
|
|
#include <QDesktopServices>
|
2020-07-07 17:55:31 +02:00
|
|
|
#include <QUrl>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include "vabstractapplication.h"
|
2020-01-07 13:21:47 +01:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
2020-01-07 08:45:26 +01:00
|
|
|
# include "vdatastreamenum.h"
|
|
|
|
#endif
|
2019-07-01 12:25:03 +02:00
|
|
|
#include "../ifc/exception/vexception.h"
|
2022-02-18 09:36:38 +01:00
|
|
|
#include "literals.h"
|
2015-06-15 15:47:44 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-01-12 13:31:45 +01:00
|
|
|
QPixmap QPixmapFromCache(const QString &pixmapPath)
|
2015-06-15 15:47:44 +02:00
|
|
|
{
|
2017-08-01 13:35:48 +02:00
|
|
|
QPixmap pixmap;
|
2015-06-15 15:47:44 +02:00
|
|
|
|
2019-07-24 14:10:13 +02:00
|
|
|
if (not QPixmapCache::find(pixmapPath, &pixmap))
|
2015-06-15 15:47:44 +02:00
|
|
|
{
|
2017-08-01 13:35:48 +02:00
|
|
|
pixmap = QPixmap(pixmapPath);
|
|
|
|
QPixmapCache::insert(pixmapPath, pixmap);
|
2015-06-15 15:47:44 +02:00
|
|
|
}
|
2018-01-12 13:31:45 +01:00
|
|
|
return pixmap;
|
|
|
|
}
|
2017-08-01 13:35:48 +02:00
|
|
|
|
2018-01-12 13:31:45 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
|
|
|
|
{
|
|
|
|
#ifndef QT_NO_CURSOR
|
|
|
|
SCASSERT(item != nullptr)
|
|
|
|
item->setCursor(QCursor(QPixmapFromCache(pixmapPath), hotX, hotY));
|
2015-10-01 16:59:01 +02:00
|
|
|
#else
|
2017-08-01 13:35:48 +02:00
|
|
|
Q_UNUSED(item)
|
2016-12-20 20:19:21 +01:00
|
|
|
Q_UNUSED(pixmapPath)
|
|
|
|
Q_UNUSED(hotX)
|
|
|
|
Q_UNUSED(hotY)
|
2015-06-15 15:47:44 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-09-19 21:58:32 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList SupportedLocales()
|
|
|
|
{
|
2020-01-16 13:10:49 +01:00
|
|
|
return QStringList
|
|
|
|
{
|
|
|
|
"uk_UA",
|
|
|
|
"de_DE",
|
|
|
|
"cs_CZ",
|
|
|
|
"he_IL",
|
|
|
|
"fr_FR",
|
|
|
|
"it_IT",
|
|
|
|
"nl_NL",
|
|
|
|
"id_ID",
|
|
|
|
"es_ES",
|
|
|
|
"fi_FI",
|
|
|
|
"en_US",
|
|
|
|
"en_CA",
|
|
|
|
"en_IN",
|
|
|
|
"ro_RO",
|
|
|
|
"zh_CN",
|
|
|
|
"pt_BR",
|
|
|
|
"el_GR",
|
|
|
|
"pl_PL"
|
|
|
|
};
|
2015-09-19 21:58:32 +02:00
|
|
|
}
|
2015-09-22 16:41:05 +02:00
|
|
|
|
2015-10-31 09:46:45 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief strippedName the function call around curFile to exclude the path to the file.
|
|
|
|
* @param fullFileName full path to the file.
|
|
|
|
* @return file name.
|
|
|
|
*/
|
|
|
|
QString StrippedName(const QString &fullFileName)
|
|
|
|
{
|
|
|
|
return QFileInfo(fullFileName).fileName();
|
|
|
|
}
|
2015-10-31 13:41:52 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString RelativeMPath(const QString &patternPath, const QString &absoluteMPath)
|
|
|
|
{
|
2016-02-09 16:19:19 +01:00
|
|
|
if (patternPath.isEmpty() || absoluteMPath.isEmpty())
|
2015-10-31 13:41:52 +01:00
|
|
|
{
|
|
|
|
return absoluteMPath;
|
|
|
|
}
|
|
|
|
|
2016-02-09 16:19:19 +01:00
|
|
|
if (QFileInfo(absoluteMPath).isRelative())
|
2015-10-31 13:41:52 +01:00
|
|
|
{
|
|
|
|
return absoluteMPath;
|
|
|
|
}
|
|
|
|
|
2016-02-09 16:19:19 +01:00
|
|
|
return QFileInfo(patternPath).absoluteDir().relativeFilePath(absoluteMPath);
|
2015-10-31 13:41:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath)
|
|
|
|
{
|
2016-02-09 16:19:19 +01:00
|
|
|
if (patternPath.isEmpty() || relativeMPath.isEmpty())
|
2015-10-31 13:41:52 +01:00
|
|
|
{
|
|
|
|
return relativeMPath;
|
|
|
|
}
|
|
|
|
|
2016-02-09 16:19:19 +01:00
|
|
|
if (QFileInfo(relativeMPath).isAbsolute())
|
|
|
|
{
|
|
|
|
return relativeMPath;
|
2015-10-31 13:41:52 +01:00
|
|
|
}
|
|
|
|
|
2016-02-09 16:19:19 +01:00
|
|
|
return QFileInfo(QFileInfo(patternPath).absoluteDir(), relativeMPath).absoluteFilePath();
|
2015-10-31 13:41:52 +01:00
|
|
|
}
|
2015-11-09 12:33:36 +01:00
|
|
|
|
2016-10-06 18:13:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QMarginsF GetMinPrinterFields(const QSharedPointer<QPrinter> &printer)
|
|
|
|
{
|
|
|
|
QPageLayout layout = printer->pageLayout();
|
|
|
|
layout.setUnits(QPageLayout::Millimeter);
|
|
|
|
const QMarginsF minMargins = layout.minimumMargins();
|
|
|
|
|
|
|
|
QMarginsF min;
|
|
|
|
min.setLeft(UnitConvertor(minMargins.left(), Unit::Mm, Unit::Px));
|
|
|
|
min.setRight(UnitConvertor(minMargins.right(), Unit::Mm, Unit::Px));
|
|
|
|
min.setTop(UnitConvertor(minMargins.top(), Unit::Mm, Unit::Px));
|
|
|
|
min.setBottom(UnitConvertor(minMargins.bottom(), Unit::Mm, Unit::Px));
|
|
|
|
return min;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-12-19 12:13:03 +01:00
|
|
|
auto GetPrinterFields(const QSharedPointer<QPrinter> &printer) -> QMarginsF
|
2016-10-06 18:13:06 +02:00
|
|
|
{
|
|
|
|
if (printer.isNull())
|
|
|
|
{
|
2020-12-19 12:13:03 +01:00
|
|
|
return {};
|
2016-10-06 18:13:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// We can't use Unit::Px because our dpi in most cases is different
|
2020-12-19 12:13:03 +01:00
|
|
|
const QMarginsF m = printer->pageLayout().margins(QPageLayout::Millimeter);
|
|
|
|
|
2016-10-06 18:13:06 +02:00
|
|
|
QMarginsF def;
|
2020-12-19 12:13:03 +01:00
|
|
|
def.setLeft(UnitConvertor(m.left(), Unit::Mm, Unit::Px));
|
|
|
|
def.setRight(UnitConvertor(m.right(), Unit::Mm, Unit::Px));
|
|
|
|
def.setTop(UnitConvertor(m.top(), Unit::Mm, Unit::Px));
|
|
|
|
def.setBottom(UnitConvertor(m.bottom(), Unit::Mm, Unit::Px));
|
2016-10-06 18:13:06 +02:00
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2015-12-03 13:07:51 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPixmap darkenPixmap(const QPixmap &pixmap)
|
|
|
|
{
|
|
|
|
QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
|
|
|
|
const int imgh = img.height();
|
|
|
|
const int imgw = img.width();
|
|
|
|
for (int y = 0; y < imgh; ++y)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < imgw; ++x)
|
|
|
|
{
|
|
|
|
int h, s, v;
|
|
|
|
QRgb pixel = img.pixel(x, y);
|
|
|
|
const int a = qAlpha(pixel);
|
|
|
|
QColor hsvColor(pixel);
|
|
|
|
hsvColor.getHsv(&h, &s, &v);
|
|
|
|
s = qMin(100, s * 2);
|
|
|
|
v = v / 2;
|
|
|
|
hsvColor.setHsv(h, s, v);
|
|
|
|
pixel = hsvColor.rgb();
|
|
|
|
img.setPixel(x, y, qRgba(qRed(pixel), qGreen(pixel), qBlue(pixel), a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QPixmap::fromImage(img);
|
|
|
|
}
|
2016-06-18 15:57:07 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void ShowInGraphicalShell(const QString &filePath)
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_MAC
|
2020-07-07 16:48:26 +02:00
|
|
|
QStringList args{
|
|
|
|
"-e", "tell application \"Finder\"",
|
|
|
|
"-e", "activate",
|
|
|
|
"-e", "select POSIX file \""+filePath+"\"",
|
|
|
|
"-e", "end tell"
|
|
|
|
};
|
|
|
|
QProcess::startDetached(QStringLiteral("osascript"), args);
|
2016-06-18 15:57:07 +02:00
|
|
|
#elif defined(Q_OS_WIN)
|
2020-07-07 16:48:26 +02:00
|
|
|
QProcess::startDetached(QStringLiteral("explorer"), QStringList{"/select", QDir::toNativeSeparators(filePath)});
|
2016-06-18 15:57:07 +02:00
|
|
|
#else
|
2020-07-07 16:48:26 +02:00
|
|
|
// we cannot select a file here, because no file browser really supports it...
|
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(filePath).path()));
|
2016-06-18 15:57:07 +02:00
|
|
|
#endif
|
|
|
|
}
|
2017-02-09 14:43:17 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool IsOptionSet(int argc, char *argv[], const char *option)
|
|
|
|
{
|
|
|
|
for (int i = 1; i < argc; ++i)
|
|
|
|
{
|
|
|
|
if (!qstrcmp(argv[i], option))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
// See issue #624. https://bitbucket.org/dismine/valentina/issues/624
|
|
|
|
void InitHighDpiScaling(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
/* For more info see: http://doc.qt.io/qt-5/highdpi.html */
|
|
|
|
if (IsOptionSet(argc, argv, qPrintable(QLatin1String("--") + LONG_OPTION_NO_HDPI_SCALING)))
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
|
|
|
|
#else
|
|
|
|
qputenv("QT_DEVICE_PIXEL_RATIO", QByteArray("1"));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // DPI support
|
|
|
|
#else
|
|
|
|
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", QByteArray("1"));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2017-03-24 13:48:07 +01:00
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strTMark, (QLatin1String("tMark"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strVMark, (QLatin1String("vMark"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strVMark2, (QLatin1String("vMark2"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strUMark, (QLatin1String("uMark"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strBoxMark, (QLatin1String("boxMark"))) // NOLINT
|
2017-03-24 13:48:07 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString PassmarkLineTypeToString(PassmarkLineType type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case PassmarkLineType::OneLine:
|
|
|
|
return strOne;
|
|
|
|
case PassmarkLineType::TwoLines:
|
|
|
|
return strTwo;
|
|
|
|
case PassmarkLineType::ThreeLines:
|
|
|
|
return strThree;
|
2017-04-05 12:22:33 +02:00
|
|
|
case PassmarkLineType::TMark:
|
2018-03-14 14:39:15 +01:00
|
|
|
return *strTMark;
|
2017-04-05 12:22:33 +02:00
|
|
|
case PassmarkLineType::VMark:
|
2018-03-14 14:39:15 +01:00
|
|
|
return *strVMark;
|
2019-01-24 08:26:57 +01:00
|
|
|
case PassmarkLineType::VMark2:
|
|
|
|
return *strVMark2;
|
2019-04-23 19:56:11 +02:00
|
|
|
case PassmarkLineType::UMark:
|
|
|
|
return *strUMark;
|
|
|
|
case PassmarkLineType::BoxMark:
|
|
|
|
return *strBoxMark;
|
2017-03-24 13:48:07 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return strOne;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
PassmarkLineType StringToPassmarkLineType(const QString &value)
|
|
|
|
{
|
2019-04-23 19:56:11 +02:00
|
|
|
const QStringList values{strOne, strTwo, strThree, *strTMark, *strVMark, *strVMark2, *strUMark, *strBoxMark};
|
2017-03-24 13:48:07 +01:00
|
|
|
|
|
|
|
switch(values.indexOf(value))
|
|
|
|
{
|
2017-04-05 12:22:33 +02:00
|
|
|
case 0: // strOne
|
2017-03-24 13:48:07 +01:00
|
|
|
return PassmarkLineType::OneLine;
|
2017-04-05 12:22:33 +02:00
|
|
|
case 1: // strTwo
|
2017-03-24 13:48:07 +01:00
|
|
|
return PassmarkLineType::TwoLines;
|
2017-04-05 12:22:33 +02:00
|
|
|
case 2: // strThree
|
2017-03-24 13:48:07 +01:00
|
|
|
return PassmarkLineType::ThreeLines;
|
2017-04-05 12:22:33 +02:00
|
|
|
case 3: // strTMark
|
|
|
|
return PassmarkLineType::TMark;
|
|
|
|
case 4: // strVMark
|
|
|
|
return PassmarkLineType::VMark;
|
2019-01-24 08:26:57 +01:00
|
|
|
case 5: // strVMark2
|
|
|
|
return PassmarkLineType::VMark2;
|
2019-04-23 19:56:11 +02:00
|
|
|
case 6: // strUMark
|
|
|
|
return PassmarkLineType::UMark;
|
|
|
|
case 7: // strBoxMark
|
|
|
|
return PassmarkLineType::BoxMark;
|
2017-03-24 13:48:07 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return PassmarkLineType::OneLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString PassmarkAngleTypeToString(PassmarkAngleType type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case PassmarkAngleType::Straightforward:
|
|
|
|
return strStraightforward;
|
|
|
|
case PassmarkAngleType::Bisector:
|
|
|
|
return strBisector;
|
2017-04-25 10:42:08 +02:00
|
|
|
case PassmarkAngleType::Intersection:
|
|
|
|
return strIntersection;
|
2017-09-28 20:18:13 +02:00
|
|
|
case PassmarkAngleType::IntersectionOnlyLeft:
|
|
|
|
return strIntersectionOnlyLeft;
|
|
|
|
case PassmarkAngleType::IntersectionOnlyRight:
|
|
|
|
return strIntersectionOnlyRight;
|
2018-02-04 11:35:27 +01:00
|
|
|
case PassmarkAngleType::Intersection2:
|
|
|
|
return strIntersection2;
|
|
|
|
case PassmarkAngleType::Intersection2OnlyLeft:
|
|
|
|
return strIntersection2OnlyLeft;
|
|
|
|
case PassmarkAngleType::Intersection2OnlyRight:
|
|
|
|
return strIntersection2OnlyRight;
|
2017-03-24 13:48:07 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return strStraightforward;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
PassmarkAngleType StringToPassmarkAngleType(const QString &value)
|
|
|
|
{
|
2017-09-28 20:18:13 +02:00
|
|
|
const QStringList values = QStringList() << strStraightforward
|
|
|
|
<< strBisector
|
|
|
|
<< strIntersection
|
|
|
|
<< strIntersectionOnlyLeft
|
2018-02-04 11:35:27 +01:00
|
|
|
<< strIntersectionOnlyRight
|
|
|
|
<< strIntersection2
|
|
|
|
<< strIntersection2OnlyLeft
|
|
|
|
<< strIntersection2OnlyRight;
|
2017-03-24 13:48:07 +01:00
|
|
|
|
|
|
|
switch(values.indexOf(value))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return PassmarkAngleType::Straightforward;
|
|
|
|
case 1:
|
|
|
|
return PassmarkAngleType::Bisector;
|
2017-04-25 10:42:08 +02:00
|
|
|
case 2:
|
|
|
|
return PassmarkAngleType::Intersection;
|
2017-09-28 20:18:13 +02:00
|
|
|
case 3:
|
|
|
|
return PassmarkAngleType::IntersectionOnlyLeft;
|
|
|
|
case 4:
|
|
|
|
return PassmarkAngleType::IntersectionOnlyRight;
|
2018-02-04 11:35:27 +01:00
|
|
|
case 5:
|
|
|
|
return PassmarkAngleType::Intersection2;
|
|
|
|
case 6:
|
|
|
|
return PassmarkAngleType::Intersection2OnlyLeft;
|
|
|
|
case 7:
|
|
|
|
return PassmarkAngleType::Intersection2OnlyRight;
|
2017-03-24 13:48:07 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return PassmarkAngleType::Straightforward;
|
|
|
|
}
|
2017-04-12 14:50:48 +02:00
|
|
|
|
2017-07-02 13:34:36 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Unit StrToUnits(const QString &unit)
|
|
|
|
{
|
|
|
|
const QStringList units = QStringList() << unitMM << unitCM << unitINCH << unitPX;
|
|
|
|
Unit result = Unit::Cm;
|
|
|
|
switch (units.indexOf(unit))
|
|
|
|
{
|
|
|
|
case 0:// mm
|
|
|
|
result = Unit::Mm;
|
|
|
|
break;
|
|
|
|
case 2:// inch
|
|
|
|
result = Unit::Inch;
|
|
|
|
break;
|
|
|
|
case 3:// px
|
|
|
|
result = Unit::Px;
|
|
|
|
break;
|
|
|
|
case 1:// cm
|
|
|
|
default:
|
|
|
|
result = Unit::Cm;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief UnitsToStr translate unit to string.
|
|
|
|
*
|
|
|
|
* This method used when need write unit in xml file and for showing unit in dialogs.
|
|
|
|
* @param unit curent unit
|
|
|
|
* @param translate true if need show translated name. Default value false.
|
|
|
|
* @return string reprezantation for unit.
|
|
|
|
*/
|
|
|
|
QString UnitsToStr(const Unit &unit, const bool translate)
|
|
|
|
{
|
|
|
|
QString result;
|
|
|
|
switch (unit)
|
|
|
|
{
|
|
|
|
case Unit::Mm:
|
|
|
|
translate ? result = QObject::tr("mm") : result = unitMM;
|
|
|
|
break;
|
|
|
|
case Unit::Inch:
|
|
|
|
translate ? result = QObject::tr("inch") : result = unitINCH;
|
|
|
|
break;
|
|
|
|
case Unit::Px:
|
|
|
|
translate ? result = QObject::tr("px") : result = unitPX;
|
|
|
|
break;
|
2020-10-16 10:37:49 +02:00
|
|
|
case Unit::LAST_UNIT_DO_NOT_USE:
|
|
|
|
break;
|
2017-07-02 13:34:36 +02:00
|
|
|
case Unit::Cm:
|
|
|
|
default:
|
|
|
|
translate ? result = QObject::tr("cm") : result = unitCM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-04-12 14:50:48 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void InitLanguages(QComboBox *combobox)
|
|
|
|
{
|
|
|
|
SCASSERT(combobox != nullptr)
|
|
|
|
combobox->clear();
|
|
|
|
|
|
|
|
QStringList fileNames;
|
2022-04-22 11:42:46 +02:00
|
|
|
QDirIterator it(VAbstractApplication::translationsPath(), QStringList("valentina_*.qm"), QDir::Files,
|
2021-02-06 14:52:21 +01:00
|
|
|
QDirIterator::Subdirectories);
|
2017-04-12 14:50:48 +02:00
|
|
|
while (it.hasNext())
|
|
|
|
{
|
|
|
|
it.next();
|
|
|
|
fileNames.append(it.fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool englishUS = false;
|
|
|
|
const QString en_US = QStringLiteral("en_US");
|
|
|
|
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto locale : fileNames)
|
2017-04-12 14:50:48 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
// get locale extracted by filename "valentina_de_De.qm"
|
2017-04-12 14:50:48 +02:00
|
|
|
locale.truncate(locale.lastIndexOf('.')); // "valentina_de_De"
|
|
|
|
locale.remove(0, locale.indexOf('_') + 1); // "de_De"
|
|
|
|
|
2022-03-18 11:28:47 +01:00
|
|
|
if (locale.startsWith(QLatin1String("ru")))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-04-12 14:50:48 +02:00
|
|
|
if (not englishUS)
|
|
|
|
{
|
|
|
|
englishUS = (en_US == locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
QLocale loc = QLocale(locale);
|
|
|
|
QString lang = loc.nativeLanguageName();
|
2021-02-21 18:39:06 +01:00
|
|
|
// Since Qt 5.12 country names have spaces
|
|
|
|
QIcon ico(QString("://flags/%1.png").arg(QLocale::countryToString(loc.country()).remove(' ')));
|
2017-04-12 14:50:48 +02:00
|
|
|
|
|
|
|
combobox->addItem(ico, lang, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (combobox->count() == 0 || not englishUS)
|
|
|
|
{
|
|
|
|
// English language is internal and doens't have own *.qm file.
|
2021-02-21 18:39:06 +01:00
|
|
|
// Since Qt 5.12 country names have spaces
|
|
|
|
QIcon ico(QString("://flags/%1.png").arg(QLocale::countryToString(QLocale::UnitedStates).remove(' ')));
|
2017-04-12 14:50:48 +02:00
|
|
|
QString lang = QLocale(en_US).nativeLanguageName();
|
|
|
|
combobox->addItem(ico, lang, en_US);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set default translators and language checked
|
2021-02-06 14:52:21 +01:00
|
|
|
qint32 index = combobox->findData(VAbstractApplication::VApp()->Settings()->GetLocale());
|
2017-04-12 14:50:48 +02:00
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
combobox->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
}
|
2018-12-21 12:01:32 +01:00
|
|
|
|
2019-07-01 12:25:03 +02:00
|
|
|
const quint32 CustomSARecord::streamHeader = 0xEBFF7586; // CRC-32Q string "CustomSARecord"
|
|
|
|
const quint16 CustomSARecord::classVersion = 1;
|
|
|
|
|
2018-12-21 12:01:32 +01:00
|
|
|
// Friend functions
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDataStream &operator<<(QDataStream &out, const CustomSARecord &record)
|
|
|
|
{
|
2019-07-01 12:25:03 +02:00
|
|
|
out << CustomSARecord::streamHeader << CustomSARecord::classVersion;
|
|
|
|
|
|
|
|
// Added in classVersion = 1
|
2018-12-21 12:01:32 +01:00
|
|
|
out << record.startPoint;
|
|
|
|
out << record.path;
|
|
|
|
out << record.endPoint;
|
|
|
|
out << record.reverse;
|
|
|
|
out << record.includeType;
|
2019-07-01 12:25:03 +02:00
|
|
|
|
|
|
|
// Added in classVersion = 2
|
|
|
|
|
2018-12-21 12:01:32 +01:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDataStream &operator>>(QDataStream &in, CustomSARecord &record)
|
|
|
|
{
|
2019-07-01 12:25:03 +02:00
|
|
|
quint32 actualStreamHeader = 0;
|
|
|
|
in >> actualStreamHeader;
|
|
|
|
|
|
|
|
if (actualStreamHeader != CustomSARecord::streamHeader)
|
|
|
|
{
|
|
|
|
QString message = QCoreApplication::tr("CustomSARecord prefix mismatch error: actualStreamHeader = 0x%1 "
|
|
|
|
"and streamHeader = 0x%2")
|
|
|
|
.arg(actualStreamHeader, 8, 0x10, QChar('0'))
|
|
|
|
.arg(CustomSARecord::streamHeader, 8, 0x10, QChar('0'));
|
|
|
|
throw VException(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
quint16 actualClassVersion = 0;
|
|
|
|
in >> actualClassVersion;
|
|
|
|
|
|
|
|
if (actualClassVersion > CustomSARecord::classVersion)
|
|
|
|
{
|
|
|
|
QString message = QCoreApplication::tr("CustomSARecord compatibility error: actualClassVersion = %1 and "
|
|
|
|
"classVersion = %2")
|
|
|
|
.arg(actualClassVersion).arg(CustomSARecord::classVersion);
|
|
|
|
throw VException(message);
|
|
|
|
}
|
|
|
|
|
2018-12-21 12:01:32 +01:00
|
|
|
in >> record.startPoint;
|
|
|
|
in >> record.path;
|
|
|
|
in >> record.endPoint;
|
|
|
|
in >> record.reverse;
|
|
|
|
in >> record.includeType;
|
2019-07-01 12:25:03 +02:00
|
|
|
|
|
|
|
// if (actualClassVersion >= 2)
|
|
|
|
// {
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
2018-12-21 12:01:32 +01:00
|
|
|
return in;
|
|
|
|
}
|
2019-01-16 15:24:41 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString IncrementTypeToString(IncrementType type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case IncrementType::Increment:
|
|
|
|
return strTypeIncrement;
|
|
|
|
case IncrementType::Separator:
|
|
|
|
return strTypeSeparator;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return strTypeIncrement;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
IncrementType StringToIncrementType(const QString &value)
|
|
|
|
{
|
|
|
|
const QStringList values { strTypeIncrement, strTypeSeparator };
|
|
|
|
|
|
|
|
switch(values.indexOf(value))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return IncrementType::Increment;
|
|
|
|
case 1:
|
|
|
|
return IncrementType::Separator;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return IncrementType::Increment;
|
|
|
|
}
|
2020-07-13 15:11:57 +02:00
|
|
|
|
2022-02-05 14:00:22 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString MeasurementTypeToString(MeasurementType type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case MeasurementType::Measurement:
|
|
|
|
return strTypeMeasurement;
|
|
|
|
case MeasurementType::Separator:
|
|
|
|
return strTypeSeparator;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return strTypeIncrement;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MeasurementType StringToMeasurementType(const QString &value)
|
|
|
|
{
|
|
|
|
const QStringList values { strTypeMeasurement, strTypeSeparator };
|
|
|
|
|
|
|
|
switch(values.indexOf(value))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return MeasurementType::Measurement;
|
|
|
|
case 1:
|
|
|
|
return MeasurementType::Separator;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return MeasurementType::Measurement;
|
|
|
|
}
|
|
|
|
|
2020-07-13 15:11:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList SplitFilePaths(const QString &path)
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
QString subPath = QDir::cleanPath(path);
|
|
|
|
QString lastFileName;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
QFileInfo fileInfo(subPath);
|
|
|
|
lastFileName = fileInfo.fileName();
|
|
|
|
if (not lastFileName.isEmpty())
|
|
|
|
{
|
|
|
|
result.prepend(lastFileName);
|
|
|
|
subPath = fileInfo.path();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(not lastFileName.isEmpty());
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|