Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Multimedia
Kdenlive
Commits
9a94ca4e
Commit
9a94ca4e
authored
Oct 02, 2020
by
Jean-Baptiste Mardelle
Browse files
Store color theme in a localized neutral way.
Should fix
#732
parent
0df40f21
Pipeline
#36216
passed with stage
in 13 minutes and 44 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main.cpp
View file @
9a94ca4e
...
...
@@ -146,9 +146,6 @@ int main(int argc, char *argv[])
qCDebug
(
KDENLIVE_LOG
)
<<
"Non KDE Desktop detected, forcing Breeze icon theme"
;
}
}
// Set breeze dark as default on first opening
KConfigGroup
cg
(
config
,
"UiSettings"
);
cg
.
writeEntry
(
"ColorScheme"
,
"Breeze Dark"
);
}
#if KICONTHEMES_VERSION < QT_VERSION_CHECK(5,60,0)
// work around bug in Kirigami2 resetting icon theme path
...
...
src/utils/thememanager.cpp
View file @
9a94ca4e
...
...
@@ -28,8 +28,8 @@
#include <QAction>
#include <QMenu>
#include <QModelIndex>
#include <QStandardPaths>
#include <QStringList>
#include <QFileInfo>
#include <KColorSchemeManager>
#include <KConfigGroup>
...
...
@@ -42,10 +42,10 @@ ThemeManager::ThemeManager(QObject *parent)
{
auto
manager
=
new
KColorSchemeManager
(
parent
);
const
auto
scheme
(
currentSchemeName
());
auto
selectionMenu
=
manager
->
createSchemeSelectionMenu
(
scheme
,
this
);
Q
Menu
*
themesMenu
=
selectionMenu
->
menu
()
;
const
auto
scheme
Path
(
loadCurrentPath
());
auto
selectionMenu
=
manager
->
createSchemeSelectionMenu
(
QString
(),
this
);
auto
themesMenu
=
selectionMenu
->
menu
(
);
Q
String
scheme
;
// Check for duplicates
QList
<
QAction
*>
actions
=
themesMenu
->
actions
();
QStringList
existing
;
...
...
@@ -55,17 +55,37 @@ ThemeManager::ThemeManager(QObject *parent)
duplicates
<<
ac
;
}
else
{
existing
<<
ac
->
text
();
if
(
schemePath
.
isEmpty
())
{
if
(
ac
->
data
().
toString
().
endsWith
(
QLatin1String
(
"BreezeDark.colors"
)))
{
themesMenu
->
setActiveAction
(
ac
);
scheme
=
ac
->
text
();
}
}
else
if
(
ac
->
data
().
toString
().
endsWith
(
schemePath
))
{
themesMenu
->
setActiveAction
(
ac
);
scheme
=
ac
->
text
();
}
}
}
for
(
QAction
*
ac
:
qAsConst
(
duplicates
))
{
themesMenu
->
removeAction
(
ac
);
}
qDeleteAll
(
duplicates
);
// Since 5.67 KColorSchemeManager includes a system color scheme option that reacts to system
// scheme changes. This scheme will be activated if we pass an empty string to KColorSchemeManager
// So no need anymore to read the current global scheme ourselves if no custom one is configured.
#if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 67, 0)
if
(
scheme
.
isEmpty
())
{
scheme
=
currentDesktopDefaultScheme
();
}
#endif
connect
(
themesMenu
,
&
QMenu
::
triggered
,
this
,
[
this
,
manager
](
QAction
*
action
)
{
QModelIndex
schemeIndex
=
manager
->
indexForScheme
(
KLocalizedString
::
removeAcceleratorMarker
(
action
->
text
()));
const
QString
path
=
manager
->
model
()
->
data
(
schemeIndex
,
Qt
::
UserRole
).
toString
();
slotSchemeChanged
(
action
,
path
);
slotSchemeChanged
(
path
);
});
manager
->
activateScheme
(
manager
->
indexForScheme
(
scheme
));
...
...
@@ -75,25 +95,18 @@ ThemeManager::ThemeManager(QObject *parent)
menu
()
->
setTitle
(
i18n
(
"&Color Theme"
));
}
QString
ThemeManager
::
loadCurrent
Scheme
()
const
QString
ThemeManager
::
loadCurrent
Path
()
const
{
KSharedConfigPtr
config
=
KSharedConfig
::
openConfig
();
KConfigGroup
cg
(
config
,
"UiSettings"
);
#if KCONFIGWIDGETS_VERSION >= QT_VERSION_CHECK(5, 67, 0)
// Since 5.67 KColorSchemeManager includes a system color scheme option that reacts to system
// scheme changes. This scheme will be activated if we pass an empty string to KColorSchemeManager
// So no need anymore to read the current global scheme ourselves if no custom one is configured.
return
cg
.
readEntry
(
"ColorScheme"
);
#else
return
cg
.
readEntry
(
"ColorScheme"
,
currentDesktopDefaultScheme
());
#endif
return
cg
.
readEntry
(
"ColorSchemePath"
);
}
void
ThemeManager
::
saveCurrentScheme
(
const
QString
&
name
)
void
ThemeManager
::
saveCurrentScheme
(
const
QString
&
path
)
{
KSharedConfigPtr
config
=
KSharedConfig
::
openConfig
();
KConfigGroup
cg
(
config
,
"UiSettings"
);
cg
.
writeEntry
(
"ColorScheme
"
,
name
);
cg
.
writeEntry
(
"ColorScheme
Path"
,
path
);
cg
.
sync
();
}
...
...
@@ -106,23 +119,8 @@ QString ThemeManager::currentDesktopDefaultScheme() const
}
#endif
QString
ThemeManager
::
currentSchemeName
()
const
{
if
(
!
menu
())
return
loadCurrentScheme
();
QAction
*
const
action
=
menu
()
->
activeAction
();
if
(
action
)
return
KLocalizedString
::
removeAcceleratorMarker
(
action
->
text
());
#if KCONFIGWIDGETS_VERSION >= QT_VERSION_CHECK(5, 67, 0)
// See above
return
QString
();
#else
return
currentDesktopDefaultScheme
();
#endif
}
void
ThemeManager
::
slotSchemeChanged
(
QAction
*
triggeredAction
,
const
QString
&
path
)
void
ThemeManager
::
slotSchemeChanged
(
const
QString
&
path
)
{
saveCurrentScheme
(
KLocalizedString
::
removeAcceleratorMarker
(
triggeredAction
->
text
()
));
saveCurrentScheme
(
QFileInfo
(
path
).
fileName
(
));
emit
themeChanged
(
path
);
}
src/utils/thememanager.h
View file @
9a94ca4e
...
...
@@ -41,11 +41,12 @@ public:
QString
currentSchemeName
()
const
;
private
Q_SLOTS
:
void
slotSchemeChanged
(
QAction
*
triggeredAction
,
const
QString
&
path
);
void
slotSchemeChanged
(
const
QString
&
path
);
private:
QString
loadCurrentScheme
()
const
;
void
saveCurrentScheme
(
const
QString
&
name
);
QString
loadCurrentPath
()
const
;
void
saveCurrentScheme
(
const
QString
&
path
);
#if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 67, 0)
QString
currentDesktopDefaultScheme
()
const
;
#endif
...
...
Write
Preview
Supports
Markdown
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