Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Q
qtquickcontrols-nemo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
NemoMobile
qtquickcontrols-nemo
Commits
729fd844
Commit
729fd844
authored
May 10, 2017
by
Chupligin Sergey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Theme] Add update theme function
parent
b9eba256
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
252 additions
and
5 deletions
+252
-5
theme.cpp
src/controls/theme.cpp
+251
-4
theme.h
src/controls/theme.h
+1
-1
No files found.
src/controls/theme.cpp
View file @
729fd844
#include "theme.h"
#include "sizing.h"
#include <QFile>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
Theme
::
Theme
(
QObject
*
parent
)
:
QObject
(
parent
)
{
Sizing
*
size
=
new
Sizing
;
m_dp
=
size
->
getDpScaleFactor
();
//Load defaults
//Load defaults
m_itemWidthLarge
=
320
*
m_dp
;
m_itemWidthMedium
=
240
*
m_dp
;
m_itemWidthSmall
=
120
*
m_dp
;
...
...
@@ -41,8 +46,250 @@ Theme::Theme(QObject *parent) : QObject(parent)
m_backgroundAccentColor
=
"#ffffff"
;
}
bool
Theme
::
loadTheme
(
QString
n
ame
)
bool
Theme
::
loadTheme
(
QString
fileN
ame
)
{
QString
themeJsonString
;
bool
updated
=
false
;
QFile
themeFile
;
themeFile
.
setFileName
(
fileName
);
if
(
!
themeFile
.
exists
())
{
qDebug
()
<<
"Theme file "
<<
fileName
<<
" not found"
;
return
false
;
}
themeFile
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
);
themeJsonString
=
themeFile
.
readAll
();
themeFile
.
close
();
QJsonDocument
t
=
QJsonDocument
::
fromJson
(
themeJsonString
.
toUtf8
());
QJsonObject
theme
=
t
.
object
();
if
(
theme
.
value
(
"itemWidthLarge"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemWidthLarge"
).
toString
().
toFloat
()
!=
m_itemWidthLarge
)
{
m_itemWidthLarge
=
theme
.
value
(
"itemWidthLarge"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemWidthLargeChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemWidthMedium"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemWidthMedium"
).
toString
().
toFloat
()
!=
m_itemWidthMedium
)
{
m_itemWidthMedium
=
theme
.
value
(
"itemWidthMedium"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemWidthMediumChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemWidthSmall"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemWidthSmall"
).
toString
().
toFloat
()
!=
m_itemWidthSmall
)
{
m_itemWidthSmall
=
theme
.
value
(
"itemWidthSmall"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemWidthSmallChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemWidthExtraSmall"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemWidthExtraSmall"
).
toString
().
toFloat
()
!=
m_itemWidthExtraSmall
)
{
m_itemWidthExtraSmall
=
theme
.
value
(
"itemWidthExtraSmall"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemWidthExtraSmallChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemHeightHuge"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemHeightHuge"
).
toString
().
toFloat
()
!=
m_itemHeightHuge
)
{
m_itemHeightHuge
=
theme
.
value
(
"itemHeightHuge"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemHeightHugeChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemHeightExtraLarge"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemHeightExtraLarge"
).
toString
().
toFloat
()
!=
m_itemHeightExtraLarge
)
{
m_itemHeightExtraLarge
=
theme
.
value
(
"itemHeightExtraLarge"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemHeightExtraLargeChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemHeightLarge"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemHeightLarge"
).
toString
().
toFloat
()
!=
m_itemHeightLarge
)
{
m_itemHeightLarge
=
theme
.
value
(
"itemHeightLarge"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemHeightLargeChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemHeightMedium"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemHeightMedium"
).
toString
().
toFloat
()
!=
m_itemHeightMedium
)
{
m_itemHeightMedium
=
theme
.
value
(
"itemHeightMedium"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemHeightMediumChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemHeightSmall"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemHeightSmall"
).
toString
().
toFloat
()
!=
m_itemHeightSmall
)
{
m_itemHeightSmall
=
theme
.
value
(
"itemHeightSmall"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemHeightSmallChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemHeightExtraSmall"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemHeightExtraSmall"
).
toString
().
toFloat
()
!=
m_itemHeightExtraSmall
)
{
m_itemHeightExtraSmall
=
theme
.
value
(
"itemHeightExtraSmall"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemHeightExtraSmallChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemSpacingHuge"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemSpacingHuge"
).
toString
().
toFloat
()
!=
m_itemSpacingHuge
)
{
m_itemSpacingHuge
=
theme
.
value
(
"itemSpacingHuge"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemSpacingHugeChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemSpacingLarge"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemSpacingLarge"
).
toString
().
toFloat
()
!=
m_itemSpacingLarge
)
{
m_itemSpacingLarge
=
theme
.
value
(
"itemSpacingLarge"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemSpacingLargeChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemSpacingMedium"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemSpacingMedium"
).
toString
().
toFloat
()
!=
m_itemSpacingMedium
)
{
m_itemSpacingMedium
=
theme
.
value
(
"itemSpacingMedium"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemSpacingMediumChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemSpacingSmall"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemSpacingSmall"
).
toString
().
toFloat
()
!=
m_itemSpacingSmall
)
{
m_itemSpacingSmall
=
theme
.
value
(
"itemSpacingSmall"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemSpacingSmallChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"itemSpacingExtraSmall"
).
toString
().
toFloat
()
!=
0
&&
theme
.
value
(
"itemSpacingExtraSmall"
).
toString
().
toFloat
()
!=
m_itemSpacingExtraSmall
)
{
m_itemSpacingExtraSmall
=
theme
.
value
(
"itemSpacingExtraSmall"
).
toString
().
toFloat
()
*
m_dp
;
emit
itemSpacingExtraSmallChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"fontSizeExtraLarge"
).
toInt
()
!=
0
&&
theme
.
value
(
"fontSizeExtraLarge"
).
toInt
()
!=
m_fontSizeExtraLarge
)
{
m_fontSizeExtraLarge
=
theme
.
value
(
"itemSpacingExtraSmall"
).
toInt
()
*
m_dp
;
emit
fontSizeExtraLargeChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"fontSizeLarge"
).
toInt
()
!=
0
&&
theme
.
value
(
"fontSizeLarge"
).
toInt
()
!=
m_fontSizeLarge
)
{
m_fontSizeLarge
=
theme
.
value
(
"fontSizeLarge"
).
toInt
()
*
m_dp
;
emit
fontSizeLargeChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"fontSizeMedium"
).
toInt
()
!=
0
&&
theme
.
value
(
"fontSizeMedium"
).
toInt
()
!=
m_fontSizeMedium
)
{
m_fontSizeMedium
=
theme
.
value
(
"fontSizeMedium"
).
toInt
()
*
m_dp
;
emit
fontSizeMediumChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"fontSizeSmall"
).
toInt
()
!=
0
&&
theme
.
value
(
"fontSizeSmall"
).
toInt
()
!=
m_fontSizeSmall
)
{
m_fontSizeSmall
=
theme
.
value
(
"fontSizeSmall"
).
toInt
()
*
m_dp
;
emit
fontSizeSmallChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"fontSizeTiny"
).
toInt
()
!=
0
&&
theme
.
value
(
"fontSizeTiny"
).
toInt
()
!=
m_fontSizeTiny
)
{
m_fontSizeTiny
=
theme
.
value
(
"fontSizeTiny"
).
toInt
()
*
m_dp
;
emit
fontSizeTinyChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"fontWeightLarge"
).
toInt
()
!=
0
&&
theme
.
value
(
"fontWeightLarge"
).
toInt
()
!=
m_fontWeightLarge
)
{
m_fontWeightLarge
=
theme
.
value
(
"fontWeightLarge"
).
toInt
()
*
m_dp
;
emit
fontWeightLargeChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"fontWeightMedium"
).
toInt
()
!=
0
&&
theme
.
value
(
"fontWeightMedium"
).
toInt
()
!=
m_fontWeightMedium
)
{
m_fontWeightMedium
=
theme
.
value
(
"fontWeightMedium"
).
toInt
()
*
m_dp
;
emit
fontWeightMediumChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"fontFamily"
).
toString
()
!=
""
&&
theme
.
value
(
"fontFamily"
).
toString
()
!=
m_fontFamily
)
{
QFile
fontFile
;
fontFile
.
setFileName
(
theme
.
value
(
"fontFamily"
).
toString
());
if
(
!
themeFile
.
exists
())
{
qDebug
()
<<
"Font file "
<<
fileName
<<
" not found"
;
}
else
{
m_fontFamily
=
theme
.
value
(
"fontFamily"
).
toString
();
emit
fontFamilyChanged
();
updated
=
true
;
}
}
if
(
theme
.
value
(
"accentColor"
).
toString
()
!=
""
&&
theme
.
value
(
"accentColor"
).
toString
()
!=
m_accentColor
)
{
m_accentColor
=
theme
.
value
(
"accentColor"
).
toString
();
emit
accentColorChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"fillColor"
).
toString
()
!=
""
&&
theme
.
value
(
"fillColor"
).
toString
()
!=
m_fillColor
)
{
m_fillColor
=
theme
.
value
(
"fillColor"
).
toString
();
emit
fillColorChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"fillDarkColor"
).
toString
()
!=
""
&&
theme
.
value
(
"fillDarkColor"
).
toString
()
!=
m_fillDarkColor
)
{
m_fillDarkColor
=
theme
.
value
(
"fillDarkColor"
).
toString
();
emit
fillDarkColorChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"textColor"
).
toString
()
!=
""
&&
theme
.
value
(
"textColor"
).
toString
()
!=
m_textColor
)
{
m_textColor
=
theme
.
value
(
"textColor"
).
toString
();
emit
textColorChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"backgroundColor"
).
toString
()
!=
""
&&
theme
.
value
(
"backgroundColor"
).
toString
()
!=
m_backgroundColor
)
{
m_backgroundColor
=
theme
.
value
(
"backgroundColor"
).
toString
();
emit
backgroundColorChanged
();
updated
=
true
;
}
if
(
theme
.
value
(
"backgroundAccentColor"
).
toString
()
!=
""
&&
theme
.
value
(
"backgroundAccentColor"
).
toString
()
!=
m_backgroundAccentColor
)
{
m_backgroundAccentColor
=
theme
.
value
(
"backgroundAccentColor"
).
toString
();
emit
backgroundAccentColorChanged
();
updated
=
true
;
}
if
(
updated
)
{
emit
themeUpdate
();
return
true
;
}
return
false
;
}
src/controls/theme.h
View file @
729fd844
...
...
@@ -45,7 +45,7 @@ class Theme : public QObject
public:
explicit
Theme
(
QObject
*
parent
=
0
);
bool
loadTheme
(
QString
n
ame
);
bool
loadTheme
(
QString
fileN
ame
);
qreal
itemWidthLarge
(){
return
m_itemWidthLarge
;}
qreal
itemWidthMedium
(){
return
m_itemWidthMedium
;}
qreal
itemWidthSmall
(){
return
m_itemWidthSmall
;}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment