valentina/src/libs/vmisc/vcommonsettings.h

416 lines
14 KiB
C
Raw Normal View History

2021-05-21 16:17:22 +02:00
/************************************************************************
**
** @file vcommonsettings.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 15 7, 2015
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2015 Valentina project
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
**
** 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/>.
**
*************************************************************************/
#ifndef VCOMMONSETTINGS_H
#define VCOMMONSETTINGS_H
#include <QByteArray>
#include <QMetaObject>
#include <QObject>
#include <QSettings>
#include <QSize>
#include <QString>
#include <QStringList>
#include <QtGlobal>
#include "../vlayout/vlayoutdef.h"
2023-05-16 18:20:49 +02:00
#include "../vmisc/def.h"
2023-10-31 08:42:09 +01:00
#include "quuid.h"
class QMarginsF;
enum class VThemeMode
{
System = 0,
Dark = 1,
Light = 2
};
class VCommonSettings : public QSettings
{
2022-08-12 17:50:13 +02:00
Q_OBJECT // NOLINT
2023-05-22 16:27:15 +02:00
public:
VCommonSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(),
QObject *parent = nullptr);
VCommonSettings(const QString &fileName, Format format, QObject *parent = nullptr);
2023-05-16 18:20:49 +02:00
~VCommonSettings() override = default;
static auto CastToLayoutExportFormat(qint8 f) -> qint8;
2022-08-12 17:50:13 +02:00
auto GetPathIndividualMeasurements() const -> QString;
void SetPathIndividualMeasurements(const QString &value);
2022-08-12 17:50:13 +02:00
auto GetPathMultisizeMeasurements() const -> QString;
void SetPathMultisizeMeasurements(const QString &value);
2022-08-12 17:50:13 +02:00
auto GetPathPattern() const -> QString;
void SetPathPattern(const QString &value);
2022-08-12 17:50:13 +02:00
auto GetPathManualLayouts() const -> QString;
2020-04-21 17:57:11 +02:00
void SetPathManualLayouts(const QString &value);
2023-10-19 16:35:29 +02:00
auto GetPathCustomImage() const -> QString;
void SetPathCustomImage(const QString &value);
2023-06-22 17:30:43 +02:00
static auto GetDefPathSVGFonts() -> QString;
auto GetPathSVGFonts() const -> QString;
void SetPathSVGFonts(const QString &value);
static auto GetDefPathFontCorrections() -> QString;
auto GetPathFontCorrections() const -> QString;
void SetPathFontCorrections(const QString &value);
2023-10-26 11:05:45 +02:00
static auto GetDefPathKnownMeasurements() -> QString;
auto GetPathKnownMeasurements() const -> QString;
void SetPathKnownMeasurements(const QString &value);
2023-06-22 17:30:43 +02:00
2022-08-12 17:50:13 +02:00
auto GetOsSeparator() const -> bool;
void SetOsSeparator(const bool &value);
2022-08-12 17:50:13 +02:00
auto GetAutosaveState() const -> bool;
void SetAutosaveState(const bool &value);
2022-08-12 17:50:13 +02:00
auto GetAutosaveTime() const -> int;
void SetAutosaveTime(const int &value);
2022-08-12 17:50:13 +02:00
auto IsLocaleSelected() const -> bool;
auto GetLocale() const -> QString;
void SetLocale(const QString &value);
static const QString defaultPieceLabelLocale;
auto GetPieceLabelLocale() const -> QString;
void SetPieceLabelLocale(const QString &value);
2023-10-31 08:42:09 +01:00
auto GetKnownMeasurementsId() const -> QUuid;
void SetKnownMeasurementsId(const QUuid &value);
2022-08-12 17:50:13 +02:00
auto GetUnit() const -> QString;
void SetUnit(const QString &value);
2022-08-12 17:50:13 +02:00
auto GetConfirmItemDelete() const -> bool;
void SetConfirmItemDelete(const bool &value);
2022-08-12 17:50:13 +02:00
auto GetConfirmFormatRewriting() const -> bool;
void SetConfirmFormatRewriting(const bool &value);
2022-08-12 17:50:13 +02:00
auto GetAskContinueIfLayoutStale() const -> bool;
void SetAskContinueIfLayoutStale(const bool &value);
2022-08-12 17:50:13 +02:00
auto GetToolBarStyle() const -> bool;
void SetToolBarStyle(const bool &value);
2023-08-21 14:51:49 +02:00
auto GetToolboxIconSizeSmall() const -> bool;
void SetToolboxIconSizeSmall(bool value);
auto GetThemeMode() const -> VThemeMode;
void SetThemeMode(VThemeMode mode);
2022-08-12 17:50:13 +02:00
auto IsFreeCurveMode() const -> bool;
void SetFreeCurveMode(bool value);
2022-08-12 17:50:13 +02:00
auto IsDoubleClickZoomFitBestCurrentPP() const -> bool;
void SetDoubleClickZoomFitBestCurrentPP(bool value);
2022-11-17 15:42:03 +01:00
auto IsInteractiveTools() const -> bool;
void SetInteractiveTools(bool value);
2022-08-12 17:50:13 +02:00
auto GetUndoCount() const -> int;
void SetUndoCount(const int &value);
2022-08-12 17:50:13 +02:00
auto GetRecentFileList() const -> QStringList;
void SetRecentFileList(const QStringList &value);
2022-08-12 17:50:13 +02:00
auto GetRestoreFileList() const -> QStringList;
void SetRestoreFileList(const QStringList &value);
2022-08-12 17:50:13 +02:00
auto GetGeometry() const -> QByteArray;
void SetGeometry(const QByteArray &value);
2022-08-12 17:50:13 +02:00
auto GetToolbarsState() const -> QByteArray;
void SetToolbarsState(const QByteArray &value);
2022-08-12 17:50:13 +02:00
auto GetPreferenceDialogSize() const -> QSize;
2023-05-16 18:20:49 +02:00
void SetPreferenceDialogSize(const QSize &sz);
2022-08-12 17:50:13 +02:00
auto GetToolSeamAllowanceDialogSize() const -> QSize;
2023-05-16 18:20:49 +02:00
void SetToolSeamAllowanceDialogSize(const QSize &sz);
2022-08-12 17:50:13 +02:00
auto GetFormulaWizardDialogSize() const -> QSize;
2023-05-16 18:20:49 +02:00
void SetFormulaWizardDialogSize(const QSize &sz);
2022-08-12 17:50:13 +02:00
auto GetIncrementsDialogSize() const -> QSize;
2023-05-16 18:20:49 +02:00
void SetIncrementsDialogSize(const QSize &sz);
2022-08-12 17:50:13 +02:00
auto GetFinalMeasurementsDialogSize() const -> QSize;
2023-05-16 18:20:49 +02:00
void SetFinalMeasurementsDialogSize(const QSize &sz);
2022-08-12 17:50:13 +02:00
auto GetLayoutSettingsDialogSize() const -> QSize;
2023-05-16 18:20:49 +02:00
void SetLayoutSettingsDialogSize(const QSize &sz);
2022-09-05 13:38:26 +02:00
auto GetDialogSplinePathSize() const -> QSize;
2023-05-16 18:20:49 +02:00
void SetDialogSplinePathSize(const QSize &sz);
2022-09-05 13:38:26 +02:00
2022-08-12 17:50:13 +02:00
auto IsAutomaticallyCheckUpdates() const -> bool;
void SetAutomaticallyCheckUpdates(bool value);
2022-08-12 17:50:13 +02:00
auto GetLatestSkippedVersion() const -> unsigned;
2021-09-24 13:57:30 +02:00
void SetLatestSkippedVersion(unsigned value);
2022-08-12 17:50:13 +02:00
auto GetDateOfLastRemind() const -> QDate;
void SetDateOfLastRemind(const QDate &date);
2022-08-12 17:50:13 +02:00
auto GetForbidWorkpieceFlipping() const -> bool;
void SetForbidWorkpieceFlipping(bool value);
2022-08-12 17:50:13 +02:00
auto GetForceWorkpieceFlipping() const -> bool;
void SetForceWorkpieceFlipping(bool value);
auto GetSewLineOnDrawing() const -> bool;
void SetSewLineOnDrawing(bool value);
2022-08-12 17:50:13 +02:00
auto IsHideMainPath() const -> bool;
void SetHideMainPath(bool value);
2022-08-12 17:50:13 +02:00
auto IsDoublePassmark() const -> bool;
void SetDoublePassmark(bool value);
void SetCSVWithHeader(bool withHeader);
2022-08-12 17:50:13 +02:00
auto GetCSVWithHeader() const -> bool;
static auto GetDefCSVWithHeader() -> bool;
void SetCSVCodec(int mib);
2022-08-12 17:50:13 +02:00
auto GetCSVCodec() const -> int;
static auto GetDefCSVCodec() -> int;
2022-08-12 17:50:13 +02:00
void SetCSVSeparator(const QChar &separator);
auto GetCSVSeparator() const -> QChar;
static auto GetDefCSVSeparator() -> QChar;
void SetDefaultSeamAllowance(double value);
2022-08-12 17:50:13 +02:00
auto GetDefaultSeamAllowance() -> double;
2022-08-12 17:50:13 +02:00
auto GetLabelFont() const -> QFont;
void SetLabelFont(const QFont &f);
2023-06-22 17:30:43 +02:00
auto GetLabelSVGFont() const -> QString;
void SetLabelSVGFont(const QString &family);
auto GetSingleStrokeOutlineFont() const -> bool;
void SetSingleStrokeOutlineFont(bool value);
auto GetSingleLineFonts() const -> bool;
void SetSingleLineFonts(bool value);
2023-05-22 16:30:18 +02:00
auto GetPieceLabelFontPointSize() const -> int;
void SetPieceLabelFontPointSize(int size);
static auto MinPieceLabelFontPointSize() -> int;
auto GetPatternLabelFontSize() const -> int;
void SetPatternLabelFontSize(int size);
static auto GetDefPatternLabelFontSize() -> int;
2022-08-12 17:50:13 +02:00
auto GetHideLabels() const -> bool;
void SetHideLabels(bool value);
2022-11-14 16:28:51 +01:00
auto GetShowAccuracyRadius() const -> bool;
void SetShowAccuracyRadius(bool value);
#if !defined(Q_OS_WIN)
static const QString unixStandardSharePath;
#endif
2022-08-12 17:50:13 +02:00
auto GetLabelDateFormat() const -> QString;
void SetLabelDateFormat(const QString &format);
2022-08-12 17:50:13 +02:00
static auto PredefinedDateFormats() -> QStringList;
auto GetUserDefinedDateFormats() const -> QStringList;
void SetUserDefinedDateFormats(const QStringList &formats);
2022-08-12 17:50:13 +02:00
auto GetLabelTimeFormat() const -> QString;
void SetLabelTimeFormat(const QString &format);
2022-08-12 17:50:13 +02:00
static auto PredefinedTimeFormats() -> QStringList;
auto GetUserDefinedTimeFormats() const -> QStringList;
void SetUserDefinedTimeFormats(const QStringList &formats);
2022-08-12 17:50:13 +02:00
auto GetCurveApproximationScale() const -> qreal;
void SetCurveApproximationScale(qreal value);
2022-08-12 17:50:13 +02:00
auto IsShowCurveDetails() const -> bool;
void SetShowCurveDetails(bool value);
2022-08-12 17:50:13 +02:00
auto IsPieceShowMainPath() const -> bool;
void SetPieceShowMainPath(bool value);
2022-08-12 17:50:13 +02:00
auto IsDontUseNativeDialog() const -> bool;
void SetDontUseNativeDialog(bool value);
2022-08-12 17:50:13 +02:00
static auto DefaultLineWidth() -> qreal;
static auto MinimalLineWidth() -> qreal;
static auto MaximalLineWidth() -> qreal;
auto GetLineWidth() const -> qreal;
void SetLineWidth(qreal width);
auto WidthMainLine() const -> qreal;
auto WidthHairLine() const -> qreal;
// settings for the tiled PDFs
auto GetTiledPDFMargins(const Unit &unit) const -> QMarginsF;
void SetTiledPDFMargins(const QMarginsF &value, const Unit &unit);
auto GetTiledPDFOrientation() const -> PageOrientation;
void SetTiledPDFOrientation(PageOrientation value);
static const int defaultScrollingDuration;
static const int scrollingDurationMin;
static const int scrollingDurationMax;
2022-08-12 17:50:13 +02:00
auto GetScrollingDuration() const -> int;
void SetScrollingDuration(int duration);
static const int defaultScrollingUpdateInterval;
static const int scrollingUpdateIntervalMin;
static const int scrollingUpdateIntervalMax;
2022-08-12 17:50:13 +02:00
auto GetScrollingUpdateInterval() const -> int;
void SetScrollingUpdateInterval(int updateInterval);
static const qreal defaultSensorMouseScale;
static const qreal sensorMouseScaleMin;
static const qreal sensorMouseScaleMax;
2022-08-12 17:50:13 +02:00
auto GetSensorMouseScale() const -> qreal;
void SetSensorMouseScale(qreal scale);
static const qreal defaultWheelMouseScale;
static const qreal wheelMouseScaleMin;
static const qreal wheelMouseScaleMax;
2022-08-12 17:50:13 +02:00
auto GetWheelMouseScale() const -> qreal;
void SetWheelMouseScale(qreal scale);
static const qreal defaultScrollingAcceleration;
static const qreal scrollingAccelerationMin;
static const qreal scrollingAccelerationMax;
2022-08-12 17:50:13 +02:00
auto GetScrollingAcceleration() const -> qreal;
void SetScrollingAcceleration(qreal acceleration);
2022-08-12 17:50:13 +02:00
auto IsOpenGLRender() const -> bool;
void SetOpenGLRender(bool value);
2022-08-12 17:50:13 +02:00
auto GetGraphicalOutput() const -> bool;
void SetGraphicalOutput(const bool &value);
2021-09-11 18:39:38 +02:00
auto GetWatermarkEditorSize() const -> QSize;
2023-05-16 18:20:49 +02:00
void SetWatermarkEditorSize(const QSize &sz);
2021-09-11 18:39:38 +02:00
auto GetWatermarkCustomColors() const -> QVector<QColor>;
void SetWatermarkCustomColors(QVector<QColor> colors);
2023-06-27 13:15:21 +02:00
auto IsAskCollectStatistic() const -> bool;
void SetAskCollectStatistic(bool value);
auto IsCollectStatistic() const -> bool;
void SetCollectStatistic(bool value);
auto GetClientID() const -> QString;
void SetClientID(const QString &clientID);
2023-10-06 09:57:46 +02:00
auto IsTranslateFormula() const -> bool;
void SetTranslateFormula(bool value);
2023-10-23 15:57:22 +02:00
auto GetActionShortcuts(const QString &name, const QStringList &defaultShortcuts) -> QStringList;
void SetActionShortcuts(const QString &name, const QStringList &shortcuts);
2023-06-22 17:30:43 +02:00
signals:
void SVGFontsPathChanged(const QString &oldPath, const QString &newPath);
2023-10-28 08:55:21 +02:00
void KnownMeasurementsPathChanged(const QString &oldPath, const QString &newPath);
2023-06-22 17:30:43 +02:00
protected:
template <typename T>
2022-08-12 17:50:13 +02:00
static auto GetCachedValue(const QSettings &settings, T &cache, const QString &setting, T defValue, T valueMin,
T valueMax) -> T;
template <class T>
2022-08-12 17:50:13 +02:00
static auto ValueOrDef(const QSettings &settings, const QString &setting, const T &defValue) -> T;
private:
2022-08-12 17:50:13 +02:00
Q_DISABLE_COPY_MOVE(VCommonSettings) // NOLINT
};
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
inline auto VCommonSettings::DefaultLineWidth() -> qreal
{
return 1.2; // mm
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
inline auto VCommonSettings::MinimalLineWidth() -> qreal
{
return 0.5; // mm
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
inline auto VCommonSettings::MaximalLineWidth() -> qreal
{
return 5.0; // mm
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-16 18:20:49 +02:00
template <typename T>
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetCachedValue(const QSettings &settings, T &cache, const QString &setting, T defValue,
T valueMin, T valueMax) -> T
{
if (cache < 0)
{
cache = qBound(valueMin, ValueOrDef(settings, setting, defValue), valueMax);
}
return cache;
}
//---------------------------------------------------------------------------------------------------------------------
template <class T>
2022-08-12 17:50:13 +02:00
inline auto VCommonSettings::ValueOrDef(const QSettings &settings, const QString &setting, const T &defValue) -> T
{
const QVariant val = settings.value(setting, QVariant::fromValue(defValue));
return val.canConvert<T>() ? val.value<T>() : defValue;
}
//---------------------------------------------------------------------------------------------------------------------
template <>
2023-05-16 18:20:49 +02:00
inline auto VCommonSettings::ValueOrDef<Cases>(const QSettings &settings, const QString &setting, const Cases &defValue)
-> Cases
{
const QVariant val = settings.value(setting, QVariant::fromValue(static_cast<int>(defValue)));
2022-08-12 17:50:13 +02:00
const int g = val.canConvert<int>() ? val.toInt() : static_cast<int>(defValue);
if (g < static_cast<int>(Cases::CaseThreeGroup) || g >= static_cast<int>(Cases::UnknownCase))
{
return defValue;
}
2022-08-12 17:50:13 +02:00
return static_cast<Cases>(g);
}
#endif // VCOMMONSETTINGS_H