mirror of
https://github.com/ONLYOFFICE/desktop-apps.git
synced 2026-04-07 14:09:22 +08:00
[win-linux] apply portal tab theme according to theme id
This commit is contained in:
@ -34,6 +34,7 @@ namespace NSTheme {
|
||||
static const QString theme_type_light = "light";
|
||||
|
||||
enum class ThemeType {
|
||||
ttUndef,
|
||||
ttDark,
|
||||
ttLight
|
||||
};
|
||||
@ -183,6 +184,16 @@ auto getUserThemesPath() -> QString
|
||||
class CTheme::CThemePrivate {
|
||||
public:
|
||||
CThemePrivate() {}
|
||||
CThemePrivate(const CThemePrivate &other) :
|
||||
id(other.id),
|
||||
wstype(other.wstype),
|
||||
type(other.type),
|
||||
is_system(other.is_system),
|
||||
jsonValues(other.jsonValues),
|
||||
defdark(other.defdark),
|
||||
deflight(other.deflight),
|
||||
source_file(other.source_file)
|
||||
{}
|
||||
|
||||
auto fromJsonObject(const QJsonObject& obj) -> void {
|
||||
id = obj.value("id").toString().toStdWString();
|
||||
@ -221,7 +232,7 @@ public:
|
||||
|
||||
std::wstring id;
|
||||
std::wstring wstype;
|
||||
NSTheme::ThemeType type;
|
||||
NSTheme::ThemeType type = NSTheme::ThemeType::ttUndef;
|
||||
bool is_system{false};
|
||||
|
||||
QJsonObject jsonValues;
|
||||
@ -467,6 +478,16 @@ CTheme::CTheme(const QString& path)
|
||||
fromFile(path);
|
||||
}
|
||||
|
||||
CTheme::CTheme(const CTheme &other)
|
||||
: m_priv(new CThemePrivate(*other.m_priv))
|
||||
{}
|
||||
|
||||
CTheme::CTheme(CTheme &&other) noexcept
|
||||
: m_priv(other.m_priv)
|
||||
{
|
||||
other.m_priv = nullptr;
|
||||
}
|
||||
|
||||
CTheme::~CTheme()
|
||||
{
|
||||
if ( m_priv ) {
|
||||
@ -475,6 +496,27 @@ CTheme::~CTheme()
|
||||
}
|
||||
}
|
||||
|
||||
CTheme& CTheme::operator=(const CTheme &other)
|
||||
{
|
||||
if (this != &other) {
|
||||
if (m_priv)
|
||||
delete m_priv;
|
||||
m_priv = new CThemePrivate(*other.m_priv);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
CTheme& CTheme::operator=(CTheme &&other) noexcept
|
||||
{
|
||||
if (this != &other) {
|
||||
if (m_priv)
|
||||
delete m_priv;
|
||||
m_priv = other.m_priv;
|
||||
other.m_priv = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto CTheme::fromFile(const QString& path) -> bool
|
||||
{
|
||||
QFile _file(path);
|
||||
@ -578,6 +620,11 @@ auto CTheme::isSystem() const -> bool
|
||||
return m_priv->is_system;
|
||||
}
|
||||
|
||||
auto CTheme::isValid() const -> bool
|
||||
{
|
||||
return !m_priv->id.empty() && m_priv->type != NSTheme::ThemeType::ttUndef && !m_priv->jsonValues.isEmpty();
|
||||
}
|
||||
|
||||
/**/
|
||||
|
||||
CThemes::CThemes()
|
||||
@ -609,6 +656,16 @@ auto CThemes::defaultLight() -> const CTheme&
|
||||
return *m_priv->getDefault(NSTheme::ThemeType::ttLight);
|
||||
}
|
||||
|
||||
auto CThemes::localFromId(const QString &id) const -> CTheme
|
||||
{
|
||||
CTheme theme;
|
||||
auto it = m_priv->rc_themes.find(id);
|
||||
if (it != m_priv->rc_themes.end()) {
|
||||
theme.fromFile(it->second);
|
||||
}
|
||||
return theme;
|
||||
}
|
||||
|
||||
auto CThemes::setCurrentTheme(const std::wstring& name) -> void
|
||||
{
|
||||
if ( !isThemeCurrent(name) && m_priv->setCurrent(QString::fromStdWString(name), true) ) {
|
||||
|
||||
@ -71,6 +71,13 @@ public:
|
||||
, ecrTabThemeType
|
||||
};
|
||||
|
||||
CTheme(const CTheme &other);
|
||||
CTheme(CTheme &&other) noexcept;
|
||||
~CTheme();
|
||||
|
||||
CTheme& operator=(const CTheme&);
|
||||
CTheme& operator=(CTheme&&) noexcept;
|
||||
|
||||
auto fromFile(const QString&) -> bool;
|
||||
auto fromJson(const QString&) -> bool;
|
||||
|
||||
@ -84,10 +91,10 @@ public:
|
||||
auto value(ColorRole, const std::wstring& def = L"") const -> std::wstring;
|
||||
auto isDark() const -> bool;
|
||||
auto isSystem() const -> bool;
|
||||
auto isValid() const -> bool;
|
||||
|
||||
private:
|
||||
CTheme(const QString& path = QString());
|
||||
~CTheme();
|
||||
|
||||
class CThemePrivate;
|
||||
CThemePrivate * m_priv = nullptr;
|
||||
@ -104,6 +111,7 @@ public:
|
||||
auto current() -> const CTheme&;
|
||||
auto defaultDark() -> const CTheme&;
|
||||
auto defaultLight() -> const CTheme&;
|
||||
auto localFromId(const QString &id) const -> CTheme;
|
||||
|
||||
// auto addLocalTheme(const std::wstring&) -> bool;
|
||||
auto addLocalTheme(QJsonObject&, const QString& filepath) -> bool;
|
||||
|
||||
@ -916,6 +916,12 @@ void CMainWindow::onPortalUITheme(int viewid, const std::wstring& json)
|
||||
if (index < 0 || m_pTabs->panel(index)->data()->isViewType(cvwtEditor))
|
||||
return;
|
||||
|
||||
const QString id = QString::fromStdWString(json);
|
||||
CTheme tm = AscAppManager::themes().localFromId(id);
|
||||
if (tm.isValid()) {
|
||||
const QString color = QString::fromStdWString(tm.value(CTheme::ColorRole::ecrTabSimpleActiveBackground));
|
||||
m_pTabs->setTabTheme(index, tm.isDark() ? "dark" : "light", color);
|
||||
} else
|
||||
if ( json.rfind(L"default-", 0) == 0 ) {
|
||||
if ( json.compare(L"default-dark") == 0 )
|
||||
m_pTabs->setTabTheme(index, "dark", "#333");
|
||||
|
||||
Reference in New Issue
Block a user