@@ -41,24 +41,34 @@ Theme::Theme(QObject* parent)
4141 physicalDotsPerInchConf->sync ();
4242 }
4343
44- MDConfItem* dpScaleFactorValue = new MDConfItem (QStringLiteral (" /nemo/apps/libglacier/dpScaleFactor" ));
45- m_dpScaleFactor = dpScaleFactorValue ->value (" 1" ).toFloat ();
44+ m_dpScaleFactorValue = new MDConfItem (QStringLiteral (" /nemo/apps/libglacier/dpScaleFactor" ));
45+ m_dpScaleFactor = m_dpScaleFactorValue ->value (" 1" ).toFloat ();
4646
4747 MDConfItem* dpi = new MDConfItem (" /lipstick/screen/primary/physicalDotsPerInch" );
4848 m_mmScaleFactor = dpi->value (" 1" ).toReal () / 2.45 / 10 ;
4949
5050 loadDefaultValue ();
5151
5252 m_themeValue = new MDConfItem (QStringLiteral (" /nemo/apps/libglacier/themePath" ));
53- m_theme = m_themeValue->value ().toString ();
53+ m_theme = m_themeValue->value (" /usr/share/themes/nemo.json " ).toString ();
5454
5555 connect (m_themeValue, &MDConfItem::valueChanged, this , &Theme::themeValueChanged);
56- connect (dpScaleFactorValue, &MDConfItem::valueChanged, this , &Theme::setThemeValues);
5756 connect (dpi, &MDConfItem::valueChanged, this , &Theme::setThemeValues);
5857 connect (physicalDotsPerInchConf, &MDConfItem::valueChanged, this , &Theme::setThemeValues);
5958
59+ connect (m_dpScaleFactorValue, &MDConfItem::valueChanged, [=](){
60+ float newDpScaleFactor = m_dpScaleFactorValue->value (" 0" ).toFloat ();
61+ if (newDpScaleFactor != m_dpScaleFactor) {
62+ m_dpScaleFactor = newDpScaleFactor;
63+ emit dpScaleFactorChanged ();
64+ emit themeUpdated ();
65+ }
66+ });
67+
6068 if (!m_theme.isEmpty ()) {
6169 loadTheme (m_theme);
70+ } else {
71+ loadDefaultValue ();
6272 }
6373}
6474
@@ -88,7 +98,6 @@ bool Theme::loadTheme(QString fileName)
8898
8999 if (fileName != m_theme) {
90100 m_themeValue->set (fileName);
91- } else {
92101 setThemeValues ();
93102 }
94103 return true ;
@@ -106,9 +115,6 @@ float Theme::mm(float value)
106115
107116void Theme::setThemeValues ()
108117{
109- MDConfItem* dpScaleFactorValue = new MDConfItem (QStringLiteral (" /nemo/apps/libglacier/dpScaleFactor" ));
110- m_dpScaleFactor = dpScaleFactorValue->value (" 0" ).toFloat ();
111-
112118 qreal dpi = MDConfItem (" /lipstick/screen/primary/physicalDotsPerInch" ).value ().toReal ();
113119 m_mmScaleFactor = dpi / 2.45 / 10 ;
114120
@@ -125,184 +131,87 @@ void Theme::setThemeValues()
125131 QJsonDocument t = QJsonDocument::fromJson (themeJsonString.toUtf8 ());
126132 QJsonObject theme = t.object ();
127133
128- if (theme.value (" iconSizeLauncher" ).toString ().toFloat () != 0 && theme.value (" iconSizeLauncher" ).toString ().toFloat () != m_iconSizeLauncher) {
129- m_iconSizeLauncher = theme.value (" iconSizeLauncher" ).toString ().toFloat ();
130- updated = true ;
131- }
132-
133- if (theme.value (" itemWidthExtraLarge" ).toString ().toFloat () != 0 && floor (theme.value (" itemWidthExtraLarge" ).toString ().toFloat ()) != m_itemWidthExtraLarge) {
134- m_itemWidthExtraLarge = floor (theme.value (" itemWidthExtraLarge" ).toString ().toFloat () * m_dpScaleFactor);
135- updated = true ;
136- }
137-
138- if (theme.value (" itemWidthLarge" ).toString ().toFloat () != 0 && floor (theme.value (" itemWidthLarge" ).toString ().toFloat ()) != m_itemWidthLarge) {
139- m_itemWidthLarge = floor (theme.value (" itemWidthLarge" ).toString ().toFloat () * m_dpScaleFactor);
140- updated = true ;
141- }
142- if (theme.value (" itemWidthMedium" ).toString ().toFloat () != 0 && floor (theme.value (" itemWidthMedium" ).toString ().toFloat ()) != m_itemWidthMedium) {
143- m_itemWidthMedium = floor (theme.value (" itemWidthMedium" ).toString ().toFloat () * m_dpScaleFactor);
144- updated = true ;
145- }
146- if (theme.value (" itemWidthSmall" ).toString ().toFloat () != 0 && floor (theme.value (" itemWidthSmall" ).toString ().toFloat ()) != m_itemWidthSmall) {
147- m_itemWidthSmall = floor (theme.value (" itemWidthSmall" ).toString ().toFloat () * m_dpScaleFactor);
148- updated = true ;
149- }
150- if (theme.value (" itemWidthExtraSmall" ).toString ().toFloat () != 0 && floor (theme.value (" itemWidthExtraSmall" ).toString ().toFloat ()) != m_itemWidthExtraSmall) {
151- m_itemWidthExtraSmall = floor (theme.value (" itemWidthExtraSmall" ).toString ().toFloat () * m_dpScaleFactor);
152- updated = true ;
153- }
154-
155- if (theme.value (" itemHeightHuge" ).toString ().toFloat () != 0 && floor (theme.value (" itemHeightHuge" ).toString ().toFloat ()) != m_itemHeightHuge) {
156- m_itemHeightHuge = floor (theme.value (" itemHeightHuge" ).toString ().toFloat () * m_dpScaleFactor);
157- updated = true ;
158- }
159- if (theme.value (" itemHeightExtraLarge" ).toString ().toFloat () != 0 && floor (theme.value (" itemHeightExtraLarge" ).toString ().toFloat ()) != m_itemHeightExtraLarge) {
160- m_itemHeightExtraLarge = floor (theme.value (" itemHeightExtraLarge" ).toString ().toFloat () * m_dpScaleFactor);
161- updated = true ;
162- }
163- if (theme.value (" itemHeightLarge" ).toString ().toFloat () != 0 && floor (theme.value (" itemHeightLarge" ).toString ().toFloat ()) != m_itemHeightLarge) {
164- m_itemHeightLarge = floor (theme.value (" itemHeightLarge" ).toString ().toFloat () * m_dpScaleFactor);
165- updated = true ;
166- }
167- if (theme.value (" itemHeightMedium" ).toString ().toFloat () != 0 && floor (theme.value (" itemHeightMedium" ).toString ().toFloat ()) != m_itemHeightMedium) {
168- m_itemHeightMedium = floor (theme.value (" itemHeightMedium" ).toString ().toFloat () * m_dpScaleFactor);
169- updated = true ;
170- }
171- if (theme.value (" itemHeightSmall" ).toString ().toFloat () != 0 && floor (theme.value (" itemHeightSmall" ).toString ().toFloat ()) != m_itemHeightSmall) {
172- m_itemHeightSmall = floor (theme.value (" itemHeightSmall" ).toString ().toFloat () * m_dpScaleFactor);
173- updated = true ;
174- }
175- if (theme.value (" itemHeightExtraSmall" ).toString ().toFloat () != 0 && floor (theme.value (" itemHeightExtraSmall" ).toString ().toFloat ()) != m_itemHeightExtraSmall) {
176- m_itemHeightExtraSmall = floor (theme.value (" itemHeightExtraSmall" ).toString ().toFloat () * m_dpScaleFactor);
177- updated = true ;
178- }
179-
180- if (theme.value (" itemSpacingHuge" ).toString ().toFloat () != 0 && floor (theme.value (" itemSpacingHuge" ).toString ().toFloat ()) != m_itemSpacingHuge) {
181- m_itemSpacingHuge = floor (theme.value (" itemSpacingHuge" ).toString ().toFloat () * m_dpScaleFactor);
182- updated = true ;
183- }
184- if (theme.value (" itemSpacingLarge" ).toString ().toFloat () != 0 && floor (theme.value (" itemSpacingLarge" ).toString ().toFloat ()) != m_itemSpacingLarge) {
185- m_itemSpacingLarge = floor (theme.value (" itemSpacingLarge" ).toString ().toFloat () * m_dpScaleFactor);
186- updated = true ;
187- }
188- if (theme.value (" itemSpacingMedium" ).toString ().toFloat () != 0 && floor (theme.value (" itemSpacingMedium" ).toString ().toFloat ()) != m_itemSpacingMedium) {
189- m_itemSpacingMedium = floor (theme.value (" itemSpacingMedium" ).toString ().toFloat () * m_dpScaleFactor);
190- updated = true ;
191- }
192- if (theme.value (" itemSpacingSmall" ).toString ().toFloat () != 0 && floor (theme.value (" itemSpacingSmall" ).toString ().toFloat ()) != m_itemSpacingSmall) {
193- m_itemSpacingSmall = floor (theme.value (" itemSpacingSmall" ).toString ().toFloat () * m_dpScaleFactor);
194- updated = true ;
195- }
196- if (theme.value (" itemSpacingExtraSmall" ).toString ().toFloat () != 0 && floor (theme.value (" itemSpacingExtraSmall" ).toString ().toFloat ()) != m_itemSpacingExtraSmall) {
197- m_itemSpacingExtraSmall = floor (theme.value (" itemSpacingExtraSmall" ).toString ().toFloat () * m_dpScaleFactor);
198- updated = true ;
199- }
200-
201- if (theme.value (" fontSizeExtraLarge" ).toInt () != 0 && floor (theme.value (" fontSizeExtraLarge" ).toInt ()) != m_fontSizeExtraLarge) {
202- m_fontSizeExtraLarge = floor (theme.value (" fontSizeExtraLarge" ).toInt () * m_dpScaleFactor);
203- updated = true ;
204- }
205- if (theme.value (" fontSizeLarge" ).toInt () != 0 && floor (theme.value (" fontSizeLarge" ).toInt ()) != m_fontSizeLarge) {
206- m_fontSizeLarge = floor (theme.value (" fontSizeLarge" ).toInt () * m_dpScaleFactor);
207- updated = true ;
208- }
209- if (theme.value (" fontSizeMedium" ).toInt () != 0 && floor (theme.value (" fontSizeMedium" ).toInt ()) != m_fontSizeMedium) {
210- m_fontSizeMedium = floor (theme.value (" fontSizeMedium" ).toInt () * m_dpScaleFactor);
211- updated = true ;
212- }
213- if (theme.value (" fontSizeSmall" ).toInt () != 0 && floor (theme.value (" fontSizeSmall" ).toInt ()) != m_fontSizeSmall) {
214- m_fontSizeSmall = floor (theme.value (" fontSizeSmall" ).toInt () * m_dpScaleFactor);
215- updated = true ;
216- }
217- if (theme.value (" fontSizeTiny" ).toInt () != 0 && floor (theme.value (" fontSizeTiny" ).toInt ()) != m_fontSizeTiny) {
218- m_fontSizeTiny = floor (theme.value (" fontSizeTiny" ).toInt () * m_dpScaleFactor);
219- updated = true ;
220- }
221- if (theme.value (" fontWeightLarge" ).toInt () != 0 && theme.value (" fontWeightLarge" ).toInt () != m_fontWeightLarge) {
222- m_fontWeightLarge = theme.value (" fontWeightLarge" ).toInt () * m_dpScaleFactor;
223- updated = true ;
224- }
225- if (theme.value (" fontWeightMedium" ).toInt () != 0 && theme.value (" fontWeightMedium" ).toInt () != m_fontWeightMedium) {
226- m_fontWeightMedium = theme.value (" fontWeightMedium" ).toInt () * m_dpScaleFactor;
227- updated = true ;
228- }
229-
230- if (theme.value (" fontPath" ).toString () != " " && theme.value (" fontPath" ).toString () != m_fontPath) {
231- QFile fontFile;
232- fontFile.setFileName (theme.value (" fontPath" ).toString ());
233- if (!themeFile.exists ()) {
234- qCWarning (lcNemoControlsCoreLog) << " Font file " << fontFile.fileName () << " not found" ;
235- } else {
236- m_fontPath = theme.value (" fontPath" ).toString ();
237- updated = true ;
238- }
239- }
240-
241- if (theme.value (" accentColor" ).toString () != " " && theme.value (" accentColor" ).toString () != m_accentColor) {
242- m_accentColor = theme.value (" accentColor" ).toString ();
243- updated = true ;
244- }
245- if (theme.value (" fillColor" ).toString () != " " && theme.value (" fillColor" ).toString () != m_fillColor) {
246- m_fillColor = theme.value (" fillColor" ).toString ();
247- updated = true ;
248- }
249- if (theme.value (" fillDarkColor" ).toString () != " " && theme.value (" fillDarkColor" ).toString () != m_fillDarkColor) {
250- m_fillDarkColor = theme.value (" fillDarkColor" ).toString ();
251- updated = true ;
252- }
253- if (theme.value (" textColor" ).toString () != " " && theme.value (" textColor" ).toString () != m_textColor) {
254- m_textColor = theme.value (" textColor" ).toString ();
255- updated = true ;
256- }
257- if (theme.value (" backgroundColor" ).toString () != " " && theme.value (" backgroundColor" ).toString () != m_backgroundColor) {
258- m_backgroundColor = theme.value (" backgroundColor" ).toString ();
259- updated = true ;
260- }
261- if (theme.value (" backgroundAccentColor" ).toString () != " " && theme.value (" backgroundAccentColor" ).toString () != m_backgroundAccentColor) {
262- m_backgroundAccentColor = theme.value (" backgroundAccentColor" ).toString ();
134+ m_iconSizeLauncher = theme.value (" iconSizeLauncher" ).toString ().toFloat ();
135+ m_itemWidthExtraLarge = floor (theme.value (" itemWidthExtraLarge" ).toString ().toFloat ());
136+ m_itemWidthLarge = floor (theme.value (" itemWidthLarge" ).toString ().toFloat ());
137+ m_itemWidthMedium = floor (theme.value (" itemWidthMedium" ).toString ().toFloat ());
138+ m_itemWidthSmall = floor (theme.value (" itemWidthSmall" ).toString ().toFloat ());
139+ m_itemWidthExtraSmall = floor (theme.value (" itemWidthExtraSmall" ).toString ().toFloat ());
140+ m_itemHeightHuge = floor (theme.value (" itemHeightHuge" ).toString ().toFloat ());
141+ m_itemHeightExtraLarge = floor (theme.value (" itemHeightExtraLarge" ).toString ().toFloat ());
142+ m_itemHeightLarge = floor (theme.value (" itemHeightLarge" ).toString ().toFloat ());
143+ m_itemHeightMedium = floor (theme.value (" itemHeightMedium" ).toString ().toFloat ());
144+ m_itemHeightSmall = floor (theme.value (" itemHeightSmall" ).toString ().toFloat ());
145+ m_itemHeightExtraSmall = floor (theme.value (" itemHeightExtraSmall" ).toString ().toFloat ());
146+ m_itemSpacingHuge = floor (theme.value (" itemSpacingHuge" ).toString ().toFloat ());
147+ m_itemSpacingLarge = floor (theme.value (" itemSpacingLarge" ).toString ().toFloat ());
148+ m_itemSpacingMedium = floor (theme.value (" itemSpacingMedium" ).toString ().toFloat ());
149+ m_itemSpacingSmall = floor (theme.value (" itemSpacingSmall" ).toString ().toFloat ());
150+ m_itemSpacingExtraSmall = floor (theme.value (" itemSpacingExtraSmall" ).toString ().toFloat ());
151+ m_fontSizeExtraLarge = floor (theme.value (" fontSizeExtraLarge" ).toInt ());
152+ m_fontSizeLarge = floor (theme.value (" fontSizeLarge" ).toInt ());
153+ m_fontSizeMedium = floor (theme.value (" fontSizeMedium" ).toInt ());
154+ m_fontSizeSmall = floor (theme.value (" fontSizeSmall" ).toInt ());
155+ m_fontSizeTiny = floor (theme.value (" fontSizeTiny" ).toInt ());
156+ m_fontWeightLarge = theme.value (" fontWeightLarge" ).toInt ();
157+ m_fontWeightMedium = theme.value (" fontWeightMedium" ).toInt ();
158+
159+ QFile fontFile;
160+ fontFile.setFileName (theme.value (" fontPath" ).toString ());
161+ if (!themeFile.exists ()) {
162+ qCWarning (lcNemoControlsCoreLog) << " Font file " << fontFile.fileName () << " not found" ;
163+ } else {
164+ m_fontPath = theme.value (" fontPath" ).toString ();
263165 updated = true ;
264166 }
167+ m_accentColor = theme.value (" accentColor" ).toString ();
168+ m_fillColor = theme.value (" fillColor" ).toString ();
169+ m_fillDarkColor = theme.value (" fillDarkColor" ).toString ();
170+ m_textColor = theme.value (" textColor" ).toString ();
171+ m_backgroundColor = theme.value (" backgroundColor" ).toString ();
172+ m_backgroundAccentColor = theme.value (" backgroundAccentColor" ).toString ();
265173
266- if (updated) {
267- emit themeUpdated ();
268- }
174+ emit themeUpdated ();
269175}
270176
271177void Theme::themeValueChanged ()
272178{
273- m_theme = m_themeValue->value ().toString ();
274- setThemeValues ();
179+ QString themePath = m_themeValue->value ().toString ();
180+ if (!themePath.isEmpty () && QFile::exists (themePath)) {
181+ m_theme = themePath;
182+ setThemeValues ();
183+ }
275184}
276185
277186void Theme::loadDefaultValue ()
278187{
279188 // Load defaults
280- m_itemWidthExtraLarge = floor ( 450 * m_dpScaleFactor) ;
281- m_itemWidthLarge = floor ( 320 * m_dpScaleFactor) ;
282- m_itemWidthMedium = floor ( 240 * m_dpScaleFactor) ;
283- m_itemWidthSmall = floor ( 120 * m_dpScaleFactor) ;
284- m_itemWidthExtraSmall = floor ( 72 * m_dpScaleFactor) ;
285-
286- m_itemHeightHuge = floor ( 80 * m_dpScaleFactor) ;
287- m_itemHeightExtraLarge = floor ( 75 * m_dpScaleFactor) ;
288- m_itemHeightLarge = floor ( 63 * m_dpScaleFactor) ;
289- m_itemHeightMedium = floor ( 50 * m_dpScaleFactor) ;
290- m_itemHeightSmall = floor ( 40 * m_dpScaleFactor) ;
291- m_itemHeightExtraSmall = floor ( 32 * m_dpScaleFactor) ;
292-
293- m_itemSpacingHuge = floor ( 48 * m_dpScaleFactor) ;
294- m_itemSpacingLarge = floor ( 24 * m_dpScaleFactor) ;
295- m_itemSpacingMedium = floor ( 18 * m_dpScaleFactor) ;
296- m_itemSpacingSmall = floor ( 14 * m_dpScaleFactor) ;
297- m_itemSpacingExtraSmall = floor ( 12 * m_dpScaleFactor) ;
298-
299- m_fontSizeExtraLarge = floor ( 44 * m_dpScaleFactor) ;
300- m_fontSizeLarge = floor ( 24 * m_dpScaleFactor) ;
301- m_fontSizeMedium = floor ( 20 * m_dpScaleFactor) ;
302- m_fontSizeSmall = floor ( 18 * m_dpScaleFactor) ;
303- m_fontSizeTiny = floor ( 14 * m_dpScaleFactor) ;
304- m_fontWeightLarge = 63 * m_dpScaleFactor ;
305- m_fontWeightMedium = 25 * m_dpScaleFactor ;
189+ m_itemWidthExtraLarge = 450 ;
190+ m_itemWidthLarge = 320 ;
191+ m_itemWidthMedium = 240 ;
192+ m_itemWidthSmall = 120 ;
193+ m_itemWidthExtraSmall = 72 ;
194+
195+ m_itemHeightHuge = 80 ;
196+ m_itemHeightExtraLarge = 75 ;
197+ m_itemHeightLarge = 63 ;
198+ m_itemHeightMedium = 50 ;
199+ m_itemHeightSmall = 40 ;
200+ m_itemHeightExtraSmall = 32 ;
201+
202+ m_itemSpacingHuge = 48 ;
203+ m_itemSpacingLarge = 24 ;
204+ m_itemSpacingMedium = 18 ;
205+ m_itemSpacingSmall = 14 ;
206+ m_itemSpacingExtraSmall = 12 ;
207+
208+ m_fontSizeExtraLarge = 44 ;
209+ m_fontSizeLarge = 24 ;
210+ m_fontSizeMedium = 20 ;
211+ m_fontSizeSmall = 18 ;
212+ m_fontSizeTiny = 14 ;
213+ m_fontWeightLarge = 63 ;
214+ m_fontWeightMedium = 25 ;
306215 m_fontPath = " /usr/share/fonts/google-opensans/OpenSans-Regular.ttf" ;
307216
308217 m_accentColor = " #0091e5" ;
0 commit comments