1 /*
2  * Copyright (C) 2018 Damir Porobic <damir.porobic@gmx.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef KIMAGEANNOTATOR_CONFIG_H
21 #define KIMAGEANNOTATOR_CONFIG_H
22 
23 #include <QObject>
24 #include <QPointF>
25 #include <QColor>
26 #include <QHash>
27 #include <QFont>
28 #include <QSettings>
29 
30 #include "src/common/enum/Tools.h"
31 #include "src/common/enum/FillModes.h"
32 #include "src/common/enum/NumberUpdateMode.h"
33 #include "src/common/helper/ConfigNameHelper.h"
34 
35 namespace kImageAnnotator {
36 
37 class Config : public QObject
38 {
39 Q_OBJECT
40 public:
41 	explicit Config();
42 	~Config() override = default;
43 
44 public slots:
45 	Tools selectedTool() const;
46 	void setSelectedToolType(Tools tool);
47 
48 	QColor toolColor(Tools tool) const;
49 	void setToolColor(const QColor &color, Tools tool);
50 
51 	QColor toolTextColor(Tools tool) const;
52 	void setToolTextColor(const QColor &color, Tools tool);
53 
54 	int toolWidth(Tools tool) const;
55 	void setToolWidth(int width, Tools tool);
56 
57 	FillModes toolFillType(Tools tool) const;
58 	void setToolFillType(FillModes fillType, Tools tool);
59 
60 	QFont toolFont(Tools tool) const;
61 	void setToolFont(const QFont &font, Tools tool);
62 
63 	bool shadowEnabled(Tools tool) const;
64 	void setShadowEnabled(bool enabled, Tools tool);
65 
66 	bool smoothPathEnabled() const;
67 	void setSmoothPathEnabled(bool enabled);
68 
69 	void setSaveToolSelection(bool enabled);
70 
71 	int smoothFactor() const;
72 	void setSmoothFactor(int factor);
73 
74 	bool switchToSelectToolAfterDrawingItem() const;
75 	void setSwitchToSelectToolAfterDrawingItem(bool enabled);
76 
77 	NumberUpdateMode numberUpdateMode() const;
78 	void setNumberToolUpdateMode(enum NumberUpdateMode numberUpdateMode);
79 
80 	int obfuscationFactor(Tools toolType) const;
81 	void setObfuscationFactor(int factor, Tools toolType);
82 
83 	QColor canvasColor() const;
84 	void setCanvasColor(const QColor &color);
85 
86 	QByteArray annotatorDockWidgetsState() const;
87 	void setAnnotatorDockWidgetsState(const QByteArray &state);
88 
89 	bool selectItemAfterDrawing() const;
90 	void setSelectItemAfterDrawing(bool enabled);
91 
92 signals:
93 	void numberUpdateModeChanged(enum NumberUpdateMode numberUpdateMode) const;
94 
95 private:
96 	QSettings mConfig;
97 	QList<Tools> mAllTools;
98 	Tools mSelectTool;
99 	QHash<Tools, QColor> mToolToColor;
100 	QHash<Tools, QColor> mToolToTextColor;
101 	QHash<Tools, int> mToolToWidth;
102 	QHash<Tools, FillModes> mToolToFillType;
103 	QHash<Tools, QFont> mToolToFont;
104 	QHash<Tools, int> mToolToObfuscationFactor;
105 	QHash<Tools, bool> mToolToShadowEnabled;
106 	bool mSmoothPathEnabled;
107 	bool mSaveToolSelection;
108 	int mSmoothFactor;
109 	bool mSwitchToSelectToolAfterDrawingItem;
110 	bool mSelectItemAfterDrawing;
111 	NumberUpdateMode mNumberUpdateMode;
112 	QColor mCanvasColor;
113 
114 	void initToolSettings();
115 	void initSelectedTool();
116 	void initToolColors();
117 	void initToolTextColors();
118 	void initToolWidths();
119 	void initToolFillTypes();
120 	void initToolFonts();
121 	void initObfuscateFactor();
122 	void initShadowEnabled();
123 	void initGeneralSettings();
124 
125 	QColor loadToolColor(Tools toolType);
126 	void saveToolColor(Tools toolType, const QColor &color);
127 	QColor loadToolTextColor(Tools toolType);
128 	void saveToolTextColor(Tools toolType, const QColor &color);
129 	int loadToolWidth(Tools toolType);
130 	void saveToolWidth(Tools toolType, int size);
131 	FillModes loadToolFillType(Tools toolType);
132 	void saveToolFillType(Tools toolType, FillModes fillType);
133 	QFont loadToolFont(Tools tool) const;
134 	void saveToolFont(Tools tool, const QFont &font);
135 	Tools loadToolType();
136 	void saveToolType(Tools toolType);
137 	int loadToolObfuscateFactor(Tools toolType);
138 	void saveToolObfuscateFactor(Tools toolType, int radius);
139 	bool loadToolShadowEnabled(Tools tool);
140 	void saveToolShadowEnabled(Tools tool, bool enabled);
141 
142 	static QColor defaultToolColor(Tools toolType);
143 	static QColor defaultToolTextColor(Tools toolType);
144 	static int defaultToolWidth(Tools toolType);
145 	static FillModes defaultToolFillMode(Tools toolType);
146 	static QFont defaultToolFont(Tools tool);
147 	static Tools defaultToolType();
148 	static int defaultObfuscateFactor();
149 	static bool defaultShadowEnabled(Tools tool);
150 };
151 
152 } // namespace kImageAnnotator
153 
154 #endif // KIMAGEANNOTATOR_CONFIG_H
155