valentina/src/libs/vmisc/vcommonsettings.h

376 lines
13 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 "../vmisc/def.h"
#include "../vlayout/vlayoutdef.h"
class QMarginsF;
class VCommonSettings : public QSettings
{
2022-08-12 17:50:13 +02:00
Q_OBJECT // NOLINT
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);
2022-08-12 17:50:13 +02:00
~VCommonSettings() override =default;
2022-08-12 17:50:13 +02:00
static auto SharePath(const QString &shareItem) -> QString;
static auto MultisizeTablesPath() -> QString;
static auto StandardTemplatesPath() -> QString;
static auto LabelTemplatesPath() -> QString;
2022-08-12 17:50:13 +02:00
static auto PrepareStandardTemplates(const QString &currentPath) -> QString;
static auto PrepareMultisizeTables(const QString &currentPath) -> QString;
static auto PrepareLabelTemplates(const QString &currentPath) -> QString;
2022-08-12 17:50:13 +02:00
static auto GetDefPathIndividualMeasurements() -> QString;
auto GetPathIndividualMeasurements() const -> QString;
void SetPathIndividualMeasurements(const QString &value);
2022-08-12 17:50:13 +02:00
static auto GetDefPathMultisizeMeasurements() -> QString;
auto GetPathMultisizeMeasurements() const -> QString;
void SetPathMultisizeMeasurements(const QString &value);
2022-08-12 17:50:13 +02:00
static auto GetDefPathPattern() -> QString;
auto GetPathPattern() const -> QString;
void SetPathPattern(const QString &value);
2022-08-12 17:50:13 +02:00
static auto GetDefPathTemplate() -> QString;
auto GetPathTemplate() const -> QString;
void SetPathTemplate(const QString &value);
2022-08-12 17:50:13 +02:00
static auto GetDefPathLabelTemplate() -> QString;
auto GetPathLabelTemplate() const -> QString;
void SetPathLabelTemplate(const QString &value);
2022-08-12 17:50:13 +02:00
static auto GetDefPathManualLayouts() -> QString;
auto GetPathManualLayouts() const -> QString;
2020-04-21 17:57:11 +02:00
void SetPathManualLayouts(const QString &value);
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);
2022-08-12 17:50:13 +02:00
auto GetPMSystemCode() const -> QString;
void SetPMSystemCode(const QString &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);
2022-08-12 17:50:13 +02:00
auto GetDarkMode() const -> bool;
void SetDarkMode(const bool &value);
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 GetWindowState() const -> QByteArray;
void SetWindowState(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;
void SetPreferenceDialogSize(const QSize& sz);
2022-08-12 17:50:13 +02:00
auto GetToolSeamAllowanceDialogSize() const -> QSize;
void SetToolSeamAllowanceDialogSize(const QSize& sz);
2022-08-12 17:50:13 +02:00
auto GetFormulaWizardDialogSize() const -> QSize;
void SetFormulaWizardDialogSize(const QSize& sz);
2022-08-12 17:50:13 +02:00
auto GetIncrementsDialogSize() const -> QSize;
void SetIncrementsDialogSize(const QSize& sz);
2022-08-12 17:50:13 +02:00
auto GetFinalMeasurementsDialogSize() const -> QSize;
void SetFinalMeasurementsDialogSize(const QSize& sz);
2022-08-12 17:50:13 +02:00
auto GetLayoutSettingsDialogSize() const -> QSize;
void SetLayoutSettingsDialogSize(const QSize& sz);
2022-09-05 13:38:26 +02:00
auto GetDialogSplinePathSize() const -> QSize;
void SetDialogSplinePathSize(const QSize& sz);
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);
2022-08-12 17:50:13 +02:00
auto GetLabelFontSize() const -> int;
void SetLabelFontSize(int size);
2022-08-12 17:50:13 +02:00
static auto GetDefLabelFontSize() -> 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;
void SetWatermarkEditorSize(const QSize& sz);
auto GetWatermarkCustomColors() const -> QVector<QColor>;
void SetWatermarkCustomColors(QVector<QColor> colors);
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
}
//---------------------------------------------------------------------------------------------------------------------
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 <>
2022-08-12 17:50:13 +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