1 /************************************************************************
2  **
3  **  @file   vcommonsettings.h
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   15 7, 2015
6  **
7  **  @brief
8  **  @copyright
9  **  This source code is part of the Valentina project, a pattern making
10  **  program, whose allow create and modeling patterns of clothing.
11  **  Copyright (C) 2015 Valentina project
12  **  <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13  **
14  **  Valentina is free software: you can redistribute it and/or modify
15  **  it under the terms of the GNU General Public License as published by
16  **  the Free Software Foundation, either version 3 of the License, or
17  **  (at your option) any later version.
18  **
19  **  Valentina is distributed in the hope that it will be useful,
20  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  **  GNU General Public License for more details.
23  **
24  **  You should have received a copy of the GNU General Public License
25  **  along with Valentina.  If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #ifndef VCOMMONSETTINGS_H
30 #define VCOMMONSETTINGS_H
31 
32 #include <QByteArray>
33 #include <QMetaObject>
34 #include <QObject>
35 #include <QSettings>
36 #include <QSize>
37 #include <QString>
38 #include <QStringList>
39 #include <QtGlobal>
40 
41 #include "../vmisc/def.h"
42 #include "../vlayout/vlayoutdef.h"
43 
44 class QMarginsF;
45 
46 class VCommonSettings : public QSettings
47 {
48     Q_OBJECT
49 public:
50     VCommonSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(),
51               QObject *parent = nullptr);
52     VCommonSettings(const QString &fileName, Format format, QObject *parent = nullptr);
53 
54     static QString SharePath(const QString &shareItem);
55     static QString MultisizeTablesPath();
56     static QString StandardTemplatesPath();
57     static QString LabelTemplatesPath();
58 
59     static QString PrepareStandardTemplates(const QString &currentPath);
60     static QString PrepareMultisizeTables(const QString &currentPath);
61     static QString PrepareLabelTemplates(const QString &currentPath);
62 
63     static QString GetDefPathIndividualMeasurements();
64     QString GetPathIndividualMeasurements() const;
65     void SetPathIndividualMeasurements(const QString &value);
66 
67     static QString GetDefPathMultisizeMeasurements();
68     QString GetPathMultisizeMeasurements() const;
69     void SetPathMultisizeMeasurements(const QString &value);
70 
71     static QString GetDefPathPattern();
72     QString GetPathPattern() const;
73     void SetPathPattern(const QString &value);
74 
75     static QString GetDefPathTemplate();
76     QString GetPathTemplate() const;
77     void SetPathTemplate(const QString &value);
78 
79     static QString GetDefPathLabelTemplate();
80     QString GetPathLabelTemplate() const;
81     void SetPathLabelTemplate(const QString &value);
82 
83     bool GetOsSeparator() const;
84     void SetOsSeparator(const bool &value);
85 
86     bool GetAutosaveState() const;
87     void SetAutosaveState(const bool &value);
88 
89     int  GetAutosaveTime() const;
90     void SetAutosaveTime(const int &value);
91 
92     QString GetLocale() const;
93     void SetLocale(const QString &value);
94 
95     QString GetPMSystemCode() const;
96     void SetPMSystemCode(const QString &value);
97 
98     QString GetUnit() const;
99     void SetUnit(const QString &value);
100 
101     bool GetConfirmItemDelete() const;
102     void SetConfirmItemDelete(const bool &value);
103 
104     bool GetConfirmFormatRewriting() const;
105     void SetConfirmFormatRewriting(const bool &value);
106 
107     bool GetToolBarStyle() const;
108     void SetToolBarStyle(const bool &value);
109 
110     bool GetDarkMode() const;
111     void SetDarkMode(const bool &value);
112 
113     bool IsFreeCurveMode() const;
114     void SetFreeCurveMode(bool value);
115 
116     bool IsDoubleClickZoomFitBestCurrentPP() const;
117     void SetDoubleClickZoomFitBestCurrentPP(bool value);
118 
119     int  GetUndoCount() const;
120     void SetUndoCount(const int &value);
121 
122     QStringList GetRecentFileList() const;
123     void SetRecentFileList(const QStringList &value);
124 
125     QStringList GetRestoreFileList() const;
126     void SetRestoreFileList(const QStringList &value);
127 
128     QByteArray GetGeometry() const;
129     void SetGeometry(const QByteArray &value);
130 
131     QByteArray GetWindowState() const;
132     void SetWindowState(const QByteArray &value);
133 
134     QByteArray GetToolbarsState() const;
135     void SetToolbarsState(const QByteArray &value);
136 
137     QSize GetPreferenceDialogSize() const;
138     void SetPreferenceDialogSize(const QSize& sz);
139 
140     QSize GetToolSeamAllowanceDialogSize() const;
141     void  SetToolSeamAllowanceDialogSize(const QSize& sz);
142 
143     QSize GetFormulaWizardDialogSize() const;
144     void  SetFormulaWizardDialogSize(const QSize& sz);
145 
146     QSize GetIncrementsDialogSize() const;
147     void  SetIncrementsDialogSize(const QSize& sz);
148 
149     QSize GetFinalMeasurementsDialogSize() const;
150     void  SetFinalMeasurementsDialogSize(const QSize& sz);
151 
152     int  GetLatestSkippedVersion() const;
153     void SetLatestSkippedVersion(int value);
154 
155     QDate GetDateOfLastRemind() const;
156     void  SetDateOfLastRemind(const QDate &date);
157 
158     bool GetForbidWorkpieceFlipping() const;
159     void SetForbidWorkpieceFlipping(bool value);
160 
161     bool GetForceWorkpieceFlipping() const;
162     void SetForceWorkpieceFlipping(bool value);
163 
164     bool IsHideMainPath() const;
165     void SetHideMainPath(bool value);
166 
167     bool IsDoublePassmark() const;
168     void SetDoublePassmark(bool value);
169 
170     void SetCSVWithHeader(bool withHeader);
171     bool GetCSVWithHeader() const;
172     static bool GetDefCSVWithHeader();
173 
174     void SetCSVCodec(int mib);
175     int  GetCSVCodec() const;
176     static int GetDefCSVCodec();
177 
178     void  SetCSVSeparator(const QChar &separator);
179     QChar GetCSVSeparator() const;
180     static QChar GetDefCSVSeparator();
181 
182     void SetDefaultSeamAllowance(double value);
183     double GetDefaultSeamAllowance();
184 
185     QFont GetLabelFont() const;
186     void  SetLabelFont(const QFont &f);
187 
188     int  GetLabelFontSize() const;
189     void SetLabelFontSize(int size);
190     static int GetDefLabelFontSize();
191 
192     bool GetHideLabels() const;
193     void SetHideLabels(bool value);
194 
195 #if !defined(Q_OS_WIN)
196     static const QString unixStandardSharePath;
197 #endif
198 
199     QString GetLabelDateFormat() const;
200     void    SetLabelDateFormat(const QString &format);
201 
202     static QStringList PredefinedDateFormats();
203     QStringList GetUserDefinedDateFormats() const;
204     void        SetUserDefinedDateFormats(const QStringList &formats);
205 
206     QString GetLabelTimeFormat() const;
207     void    SetLabelTimeFormat(const QString &format);
208 
209     static QStringList PredefinedTimeFormats();
210     QStringList GetUserDefinedTimeFormats() const;
211     void        SetUserDefinedTimeFormats(const QStringList &formats);
212 
213     qreal GetCurveApproximationScale() const;
214     void  SetCurveApproximationScale(qreal value);
215 
216     bool IsShowCurveDetails() const;
217     void SetShowCurveDetails(bool value);
218 
219     bool IsPieceShowMainPath() const;
220     void SetPieceShowMainPath(bool value);
221 
222     bool IsDontUseNativeDialog() const;
223     void SetDontUseNativeDialog(bool value);
224 
225     static qreal DefaultLineWidth();
226     static qreal MinimalLineWidth();
227     static qreal MaximalLineWidth();
228     qreal GetLineWidth() const;
229     void  SetLineWidth(qreal width);
230     qreal WidthMainLine() const;
231     qreal WidthHairLine() const;
232 
233     // settings for the tiled PDFs
234    auto GetTiledPDFMargins(const Unit &unit) const -> QMarginsF;
235    void SetTiledPDFMargins(const QMarginsF &value, const Unit &unit);
236 
237    auto GetTiledPDFOrientation() const -> PageOrientation;
238    void SetTiledPDFOrientation(PageOrientation value);
239 
240 protected:
241    template <class T>
242    T ValueOrDef(const QString &setting, const T &defValue) const;
243 
244 private:
245     Q_DISABLE_COPY(VCommonSettings)
246 };
247 
248 //---------------------------------------------------------------------------------------------------------------------
DefaultLineWidth()249 inline qreal VCommonSettings::DefaultLineWidth()
250 {
251     return 1.2; // mm
252 }
253 
254 //---------------------------------------------------------------------------------------------------------------------
MinimalLineWidth()255 inline qreal VCommonSettings::MinimalLineWidth()
256 {
257     return 0.5; // mm
258 }
259 
260 //---------------------------------------------------------------------------------------------------------------------
MaximalLineWidth()261 inline qreal VCommonSettings::MaximalLineWidth()
262 {
263     return 5.0; // mm
264 }
265 
266 //---------------------------------------------------------------------------------------------------------------------
267 template <class T>
ValueOrDef(const QString & setting,const T & defValue)268 inline T VCommonSettings::ValueOrDef(const QString &setting, const T &defValue) const
269 {
270     const QVariant val = value(setting, QVariant::fromValue(defValue));
271     return val.canConvert<T>() ? val.value<T>() : defValue;
272 }
273 
274 //---------------------------------------------------------------------------------------------------------------------
275 template <>
276 inline Cases VCommonSettings::ValueOrDef<Cases>(const QString &setting, const Cases &defValue) const
277 {
278     const QVariant val = value(setting, QVariant::fromValue(static_cast<int>(defValue)));
279     const int g = val.canConvert<int>() ? val.value<int>() : static_cast<int>(defValue);
280     if (g < static_cast<int>(Cases::CaseThreeGroup) || g >= static_cast<int>(Cases::UnknownCase))
281     {
282         return defValue;
283     }
284     else
285     {
286         return static_cast<Cases>(g);
287     }
288 }
289 
290 #endif // VCOMMONSETTINGS_H
291