From d5b5512a7b7fbb21659d0975dcfb26fa09cbbaf5 Mon Sep 17 00:00:00 2001 From: maxkadushkin Date: Sun, 3 Sep 2023 01:01:21 +0300 Subject: [PATCH] [win-nix] change tab colors according to tab's theme --- win-linux/res/styles/tabbar.qss | 50 +----- win-linux/res/styles/theme-contrast-dark.json | 4 +- win-linux/res/styles/theme-dark.json | 4 +- win-linux/src/components/asctabwidget.cpp | 152 ++++++++++++++--- win-linux/src/components/asctabwidget.h | 3 + win-linux/src/components/ctabbar.cpp | 160 ++++++++++++++++-- win-linux/src/components/ctabbar.h | 6 +- win-linux/src/windows/cmainwindow.cpp | 5 +- 8 files changed, 292 insertions(+), 92 deletions(-) diff --git a/win-linux/res/styles/tabbar.qss b/win-linux/res/styles/tabbar.qss index 5f126b67b..663e6fcf7 100644 --- a/win-linux/res/styles/tabbar.qss +++ b/win-linux/res/styles/tabbar.qss @@ -17,28 +17,17 @@ CTabBar #tabScroll>#rightButton:hover {image: url(:/tabbar/icons/scrolltab_rh.sv CTabBar #tabScroll>#rightButton:pressed {image: url(:/tabbar/icons/scrolltab_rp.svg);} Tab {background: #f1f1f1; border: none; border-right: 1px solid #dfdfdf; margin: 0px; padding: 0px;} -Tab #tabIcon {background: transparent; /*image: url(:/tabbar/icons/res/icons/tabicon_oform_normal.svg);*/} -Tab #tabText {color: #444; background: transparent; font-family: "Arial", "Helvetica", "Helvetica Neue", sans-serif;} +Tab #tabIcon {background: transparent;} +Tab #tabText {background: transparent; font-family: "Arial", "Helvetica", "Helvetica Neue", sans-serif;} Tab #tabButton {border: none; margin-top: 0px; image: none; background: transparent;} Tab[selected=true] {background: #446995; border-color: #446995;} -Tab[selected=true] #tabText {color: #fff;} -Tab[selected=true] #tabButton {image:url(:/tabbar/icons/close_active_normal.svg); /*background: #446995;*/} -Tab[selected=true] #tabButton:hover {image: url(:/tabbar/icons/close_active_hover.svg);} -Tab[selected=true] #tabButton:pressed {image: url(:/tabbar/icons/close_active_pressed.svg);} -CTabBar[active=false] Tab[selected=true] {background: #f1f1f1; border-color: #dfdfdf;} -CTabBar[active=false] Tab[selected=true] #tabText {color: #444;} -CTabBar[active=false] Tab[selected=true] #tabButton {image: none; /*background: #f1f1f1;*/} +CTabBar[active=false] Tab[selected=true] {border-color: #dfdfdf;} +CTabBar[active=false] Tab[selected=true] #tabButton {image: none;} Tab[selected=false][hovered=true], CTabBar[active=false] Tab[selected=true][hovered=true] {background: #cecece;} -Tab[selected=false][hovered=true] #tabButton, -CTabBar[active=false] Tab[selected=true][hovered=true] #tabButton {image: url(:/tabbar/icons/close_normal.svg); /*background: #cecece;*/} -Tab[selected=false][hovered=true] #tabButton:hover, -CTabBar[active=false] Tab[selected=true][hovered=true] #tabButton:hover {image: url(:/tabbar/icons/close_hover.svg);} -Tab[selected=false][hovered=true] #tabButton:pressed, -CTabBar[active=false] Tab[selected=true][hovered=true] #tabButton:pressed {image: url(:/tabbar/icons/close_pressed.svg);} /* light */ #mainPanel[uitheme=theme-light] Tab {border-right-color: #dfdfdf;} @@ -52,21 +41,10 @@ CTabBar[active=false] Tab[selected=true][hovered=true] #tabButton:pressed {image #mainPanel[uitheme=theme-dark] CTabBar #tabScroll>QToolButton:hover {background: #555;} #mainPanel[uitheme=theme-dark] CTabBar #tabScroll>QToolButton:pressed {background: #606060;} #mainPanel[uitheme=theme-dark] Tab {background: #404040; border-right-color: #505050;} -#mainPanel[uitheme=theme-dark] Tab #tabText {color: #dfdfdf;} #mainPanel[uitheme=theme-dark] Tab[selected=true] {background: #2a2a2a; border-color: #2a2a2a;} #mainPanel[uitheme=theme-dark] CTabBar[active=false] Tab[selected=true] {background: #404040; border-color: #505050;} -#mainPanel[uitheme=theme-dark] CTabBar[active=false] Tab[selected=true][custom=true] #tabText {color: #dfdfdf;} -#mainPanel[uitheme=theme-dark] CTabBar[active=false] Tab[selected=true][custom=true] #tabButton {image: none;} #mainPanel[uitheme=theme-dark] Tab[selected=false][hovered=true], #mainPanel[uitheme=theme-dark] CTabBar[active=false] Tab[selected=true][hovered=true] {background: #555;} -#mainPanel[uitheme=theme-dark] Tab[selected=false][hovered=true] #tabButton, -#mainPanel[uitheme=theme-dark] CTabBar[active=false] Tab[selected=true][hovered=true] #tabButton {image: url(:/tabbar/icons/close_active_normal.svg);} -#mainPanel[uitheme=theme-dark] Tab[selected=false][hovered=true] #tabButton:hover, -#mainPanel[uitheme=theme-dark] CTabBar[active=false] Tab[selected=true][hovered=true] #tabButton:hover {image: url(:/tabbar/icons/close_active_hover.svg);} -#mainPanel[uitheme=theme-dark] Tab[selected=false][hovered=true] #tabButton:pressed, -#mainPanel[uitheme=theme-dark] CTabBar[active=false] Tab[selected=true][hovered=true] #tabButton:pressed {image: url(:/tabbar/icons/close_active_pressed.svg);} -#mainPanel[uitheme=theme-dark] Tab[selected=true] #tabButton:pressed {background: #555;} -#mainPanel[uitheme=theme-dark] Tab[selected=true][custom=true] #tabButton:pressed {background: transparent;} /* contrast-dark */ #mainPanel[uitheme=theme-contrast-dark] CTabBar {background: #2a2a2a;} @@ -74,32 +52,12 @@ CTabBar[active=false] Tab[selected=true][hovered=true] #tabButton:pressed {image #mainPanel[uitheme=theme-contrast-dark] CTabBar #tabScroll>QToolButton:hover {background: #525252;} #mainPanel[uitheme=theme-contrast-dark] CTabBar #tabScroll>QToolButton:pressed {background: #424242;} #mainPanel[uitheme=theme-contrast-dark] Tab {background: #2a2a2a; border-right-color: #414141;} -#mainPanel[uitheme=theme-contrast-dark] Tab #tabText {color: #fff;} #mainPanel[uitheme=theme-contrast-dark] Tab[selected=true] {background: #1e1e1e; border-color: #1e1e1e;} #mainPanel[uitheme=theme-contrast-dark] CTabBar[active=false] Tab[selected=true] {background: #2a2a2a; border-color: #414141;} -#mainPanel[uitheme=theme-contrast-dark] CTabBar[active=false] Tab[selected=true][custom=true] #tabText {color: #fff;} -#mainPanel[uitheme=theme-contrast-dark] CTabBar[active=false] Tab[selected=true][custom=true] #tabButton {image: none;} #mainPanel[uitheme=theme-contrast-dark] Tab[selected=false][hovered=true], #mainPanel[uitheme=theme-contrast-dark] CTabBar[active=false] Tab[selected=true][hovered=true] {background: #424242;} -#mainPanel[uitheme=theme-contrast-dark] Tab[selected=false][hovered=true] #tabButton, -#mainPanel[uitheme=theme-contrast-dark] CTabBar[active=false] Tab[selected=true][hovered=true] #tabButton {image: url(:/tabbar/icons/close_active_normal.svg);} -#mainPanel[uitheme=theme-contrast-dark] Tab[selected=false][hovered=true] #tabButton:hover, -#mainPanel[uitheme=theme-contrast-dark] CTabBar[active=false] Tab[selected=true][hovered=true] #tabButton:hover {image: url(:/tabbar/icons/close_active_hover.svg);} -#mainPanel[uitheme=theme-contrast-dark] Tab[selected=false][hovered=true] #tabButton:pressed, -#mainPanel[uitheme=theme-contrast-dark] CTabBar[active=false] Tab[selected=true][hovered=true] #tabButton:pressed {image: url(:/tabbar/icons/close_active_pressed.svg);} -#mainPanel[uitheme=theme-contrast-dark] Tab[selected=true] #tabButton:pressed {background: #424242;} -#mainPanel[uitheme=theme-contrast-dark] Tab[selected=true][custom=true] #tabButton:pressed {background: transparent;} /* portal */ -Tab[selected=true][custom=true], -#mainPanel[uitheme=theme-dark] Tab[selected=true][custom=true], -#mainPanel[uitheme=theme-contrast-dark] Tab[selected=true][custom=true] {background: #fff;} -Tab[selected=true][custom=true] #tabText, -#mainPanel[uitheme=theme-dark] Tab[selected=true][custom=true] #tabText, -#mainPanel[uitheme=theme-contrast-dark] Tab[selected=true][custom=true] #tabText {color: #444;} -Tab[selected=true][custom=true] #tabButton {image:url(:/tabbar/icons/close_normal.svg);} -Tab[selected=true][custom=true] #tabButton:hover {image: url(:/tabbar/icons/close_hover.svg);} -Tab[selected=true][custom=true] #tabButton:pressed {image: url(:/tabbar/icons/close_pressed.svg);} /* dark, contrast-dark */ #mainPanel[uitheme=theme-dark] CTabBar #tabScroll>#leftButton, diff --git a/win-linux/res/styles/theme-contrast-dark.json b/win-linux/res/styles/theme-contrast-dark.json index d92b454c0..eb961ed85 100644 --- a/win-linux/res/styles/theme-contrast-dark.json +++ b/win-linux/res/styles/theme-contrast-dark.json @@ -17,8 +17,8 @@ "tab-active-background": "#121212", "tab-simple-active-background": "#fff", - "tab-simple-active-text": "#444", - "tab-default-active-background": "#121212", + "tab-simple-active-text": "#fff", + "tab-default-active-background": "#fff", "tab-default-active-text": "#fff", "tab-divider": "#414141", diff --git a/win-linux/res/styles/theme-dark.json b/win-linux/res/styles/theme-dark.json index 02ef9aa98..c54f1f4da 100644 --- a/win-linux/res/styles/theme-dark.json +++ b/win-linux/res/styles/theme-dark.json @@ -17,8 +17,8 @@ "tab-active-background": "#333", "tab-simple-active-background": "#fff", - "tab-simple-active-text": "#444", - "tab-default-active-background": "#333", + "tab-simple-active-text": "#fff", + "tab-default-active-background": "#fff", "tab-default-active-text": "#fff", "tab-divider": "#505050", diff --git a/win-linux/src/components/asctabwidget.cpp b/win-linux/src/components/asctabwidget.cpp index 1f813aded..10a95c339 100644 --- a/win-linux/src/components/asctabwidget.cpp +++ b/win-linux/src/components/asctabwidget.cpp @@ -374,7 +374,9 @@ int CAscTabWidget::addPortal(const QString& url, const QString& name, const QStr tab_index = insertWidget(tab_index, panelwidget); m_pBar->insertTab(tab_index, portal); m_pBar->setTabToolTip(tab_index, _url); - m_pBar->setTabIconTheme(tab_index, CTabBar::LightTab); + m_pBar->setTabThemeType(tab_index, CTabBar::LightTab); + m_pBar->setTabThemeIcons(tab_index, std::make_pair(":/tabbar/icons/portal.svg", ":/tabbar/icons/portal_light.svg")); + m_pBar->setActiveTabColor(tab_index, "#fff"); m_pBar->tabStartLoading(tab_index); // updateTabIcon(tabIndexByView(id)); @@ -413,8 +415,10 @@ int CAscTabWidget::addOAuthPortal(const QString& portal, const QString& type, co tab_index = insertWidget(tab_index, panelwidget); m_pBar->insertTab(tab_index, _portal); m_pBar->setTabToolTip(tab_index, portal); - m_pBar->setTabIconTheme(tab_index, CTabBar::LightTab); - m_pBar->tabStartLoading(tab_index); + m_pBar->setTabThemeType(tab_index, CTabBar::LightTab); + m_pBar->setTabThemeIcons(tab_index, std::make_pair(":/tabbar/icons/portal_light.svg", ":/tabbar/icons/portal.svg")); + m_pBar->setActiveTabColor(tab_index, "#fff"); +// m_pBar->tabStartLoading(tab_index); return tab_index; } @@ -433,6 +437,33 @@ int CAscTabWidget::insertPanel(QWidget * panel, int index) tabindex = insertWidget(index, panelwidget); m_pBar->insertTab(tabindex, tabdata->title()); m_pBar->setTabToolTip(tabindex, tabdata->title()); + + QString tabcolor = "none"; + const CTheme & ui_theme = AscAppManager::themes().current(); + const AscEditorType tab_type = tabdata->contentType(); + switch ( tab_type ) { + case etPresentation: + tabcolor = QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabSlideActive)); + m_pBar->setTabThemeType(tabindex, CTabBar::DarkTab); + break; + case etSpreadsheet: + tabcolor = QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabCellActive)); + m_pBar->setTabThemeType(tabindex, CTabBar::DarkTab); + break; + case etDocumentMasterForm: + case etDocument: + tabcolor = QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabWordActive)); + m_pBar->setTabThemeType(tabindex, CTabBar::DarkTab); + break; + default: + tabcolor = QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabDefaultActiveBackground)); + m_pBar->setTabThemeType(tabindex, /*ui_theme.isDark() ? CTabBar::DarkTab :*/ CTabBar::LightTab); + } + + m_pBar->setActiveTabColor(tabindex, tabcolor); + + const char *icon_name = tabindex == m_pBar->currentIndex() ? m_mapTabIcons.at(tab_type).second : m_mapTabIcons.at(tab_type).first; + m_pBar->setTabIcon(tabindex, QIcon(icon_name)); } return tabindex; @@ -493,7 +524,9 @@ void CAscTabWidget::updateTabIcon(int index) case etDocument: active_tab_color = QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabWordActive)); break; case etNewPortal: case etPortal: - active_tab_color = QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabSimpleActiveBackground)); +// if ( panel(index)->data()->colorTabActive().isEmpty() ) +// active_tab_color = QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabSimpleActiveBackground)); +// else active_tab_color = panel(index)->data()->colorTabActive(); // tab_theme = CTabBar::LightTab; break; default: @@ -503,15 +536,27 @@ void CAscTabWidget::updateTabIcon(int index) break; } } - const char *icon_name = is_active ? m_mapTabIcons.at(tab_type).second : m_mapTabIcons.at(tab_type).first; - m_pBar->setTabIcon(index, QIcon(icon_name)); -// m_pBar->setTabIconTheme(index, tab_theme); + +// const char *icon_name = is_active ? m_mapTabIcons.at(tab_type).second : m_mapTabIcons.at(tab_type).first; +// m_pBar->setTabIcon(index, QIcon(icon_name)); if ( index == currentIndex() ) { - if (tab_type == etPortal || tab_type == etNewPortal || tab_type == etUndefined) - m_pBar->setUseTabCustomPalette(index, true); + if (tab_type == etPortal || tab_type == etNewPortal || tab_type == etUndefined) { + if ( 0 /* panel(index)->data()->colorTabActive().isEmpty()*/ ) + m_pBar->setUseTabCustomPalette(index, true); + else { +// active_tab_color = panel(index)->data()->colorTabActive(); +// m_pBar->setUseTabCustomPalette(index, false); +// m_pBar->setActiveTabColor(index, active_tab_color); + } + +// m_pBar->setUseTabCustomPalette(index, true); + } else { - m_pBar->setUseTabCustomPalette(index, false); - m_pBar->setActiveTabColor(index, active_tab_color); +// const char *icon_name = is_active ? m_mapTabIcons.at(tab_type).second : m_mapTabIcons.at(tab_type).first; +// m_pBar->setTabIcon(index, QIcon(icon_name)); + +// m_pBar->setUseTabCustomPalette(index, false); +// m_pBar->setActiveTabColor(index, active_tab_color); } } } @@ -541,6 +586,23 @@ void CAscTabWidget::reloadTabIcons() }); } +void CAscTabWidget::setTabActiveColor(int index, const std::wstring& color) +{ +} + +void CAscTabWidget::setTabThemeType(int index, const QString& type) +{ + if ( !(index < 0) && index < count() ) { + if ( type == "dark" ) { + m_pBar->setActiveTabColor(index, "#333"); + m_pBar->setTabThemeType(index, CTabBar::DarkTab); + } else { + m_pBar->setActiveTabColor(index, "#fff"); + m_pBar->setTabThemeType(index, CTabBar::LightTab); + } + } +} + /* * Slots */ @@ -809,12 +871,31 @@ void CAscTabWidget::applyDocumentChanging(int id, int type) if ( !(tabIndex < 0) ) { panel(tabIndex)->data()->setContentType(AscEditorType(type)); + const CTheme & ui_theme = AscAppManager::themes().current(); switch (type) { - case etDocument: panel(tabIndex)->applyLoader("loader:style", "word"); break; - case etSpreadsheet: panel(tabIndex)->applyLoader("loader:style", "cell"); break; - case etPresentation: panel(tabIndex)->applyLoader("loader:style", "slide"); break; + case etDocument: + panel(tabIndex)->applyLoader("loader:style", "word"); + m_pBar->setTabThemeType(tabIndex, CTabBar::DarkTab); + m_pBar->setActiveTabColor(tabIndex, + QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabWordActive))); + break; + case etSpreadsheet: + panel(tabIndex)->applyLoader("loader:style", "cell"); + m_pBar->setTabThemeType(tabIndex, CTabBar::DarkTab); + m_pBar->setActiveTabColor(tabIndex, + QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabCellActive))); + break; + case etPresentation: + panel(tabIndex)->applyLoader("loader:style", "slide"); + m_pBar->setTabThemeType(tabIndex, CTabBar::DarkTab); + m_pBar->setActiveTabColor(tabIndex, + QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabSlideActive))); + break; default: break; } + + const char *icon_name = tabIndex == m_pBar->currentIndex() ? m_mapTabIcons.at(type).second : m_mapTabIcons.at(type).first; + m_pBar->setTabIcon(tabIndex, QIcon(icon_name)); } updateTabIcon(tabIndexByView(id)); @@ -883,7 +964,14 @@ void CAscTabWidget::activate(bool a) m_pBar->setProperty("active", a); } updateIcons(); - m_pBar->polish(); + + if ( a ) { + if ( m_pBar->currentIndex() < 0 ) + m_pBar->setCurrentIndex(currentIndex()); + } else { + m_pBar->setCurrentIndex(-1); + } +// m_pBar->polish(); } bool CAscTabWidget::isActiveWidget() @@ -1157,16 +1245,42 @@ void CAscTabWidget::setStyleSheet(const QString& stylesheet) // } } +void CAscTabWidget::setCurrentIndex(int index) +{ + QStackedWidget::setCurrentIndex(index); + m_pBar->setCurrentIndex(index); +} + void CAscTabWidget::applyUITheme(const std::wstring& theme) { reloadTabIcons(); updateIcons(); - m_pBar->setIgnoreActiveTabColor(GetCurrentTheme().isDark()); - m_pBar->polish(); - style()->polish(this); +// m_pBar->setIgnoreActiveTabColor(GetCurrentTheme().isDark()); +// m_pBar->polish(); - QColor back_color = GetColorByRole(ecrWindowBackground); + const CTheme & ui_theme = AscAppManager::themes().current(); + std::vector tab_color{QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabWordActive)), + QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabCellActive)), + QString::fromStdWString(ui_theme.value(CTheme::ColorRole::ecrTabSlideActive))}; + QColor back_color = ui_theme.color(CTheme::ColorRole::ecrWindowBackground); for (int i(count()); i-- > 0; ) { panel(i)->setBackground(back_color); + + switch ( panel(i)->data()->contentType() ) { + case etPresentation: + m_pBar->setActiveTabColor(i, tab_color.at(2)); + break; + case etSpreadsheet: + m_pBar->setActiveTabColor(i, tab_color.at(1)); + break; + case etDocumentMasterForm: + case etDocument: + m_pBar->setActiveTabColor(i, tab_color.at(0)); + break; + default: break; + } } + + m_pBar->refreshTheme(); + style()->polish(this); } diff --git a/win-linux/src/components/asctabwidget.h b/win-linux/src/components/asctabwidget.h index e65e00327..e84016e22 100644 --- a/win-linux/src/components/asctabwidget.h +++ b/win-linux/src/components/asctabwidget.h @@ -141,6 +141,7 @@ public: void closeEditorByIndex(int index, bool checkmodified = false); void closePortal(const std::wstring&, bool editors = false); void setStyleSheet(const QString&); + void setCurrentIndex(int); void applyUITheme(const std::wstring&); using QStackedWidget::count; @@ -183,6 +184,8 @@ public: void reloadTabIcons(); void updateIcons(); void updateTabIcon(int); + void setTabActiveColor(int index, const std::wstring& color); + void setTabThemeType(int index, const QString& type); void setFocusedView(int index = -1); void setFullScreen(bool, int id = -1); QWidget * fullScreenWidget(); diff --git a/win-linux/src/components/ctabbar.cpp b/win-linux/src/components/ctabbar.cpp index da3a0edff..51991d845 100644 --- a/win-linux/src/components/ctabbar.cpp +++ b/win-linux/src/components/ctabbar.cpp @@ -32,6 +32,7 @@ #include "components/ctabbar.h" #include "components/canimatedicon.h" +#include "cascapplicationmanagerwrapper.h" #include #include #include @@ -43,6 +44,7 @@ #include #include + #define ANIMATION_DEFAULT_MS 0 #define ANIMATION_SCROLL_MS 60 #define ANIMATION_MOVE_TAB_MS 350 @@ -63,7 +65,14 @@ public: void setText(const QString &text, Qt::TextElideMode mode = Qt::ElideRight); void elideText(Qt::TextElideMode mode = Qt::ElideRight); void setIcon(const QIcon &icon); + void setIcon(const QString &path); + void setThemeIcons(const std::pair &); + void setColorThemeType(const QString&); + void setActive(bool state); void polish(); + void refreshIcon(const QString& themetype); + void refreshTextColor(); + void refreshCloseButton(); QIcon *tab_icon = nullptr; CAnimatedIcon *icon_label = nullptr; @@ -74,6 +83,9 @@ public: int tab_width = -1; int index = -1; + std::pair theme_icons; + QString tab_theme_type; + bool is_active = false; signals: void onTabWidthChanged(int width); @@ -148,6 +160,97 @@ void Tab::setIcon(const QIcon &icon) icon_label->setPixmap(tab_icon->pixmap(icon_label->size())); } +void Tab::setIcon(const QString &path) +{ + if ( !path.isEmpty() ) { + if ( tab_icon ) + delete tab_icon, tab_icon = nullptr; + + tab_icon = new QIcon(path); + icon_label->setPixmap(tab_icon->pixmap(icon_label->size())); + } +} + +void Tab::setThemeIcons(const std::pair & icons) +{ + theme_icons = icons; + + if ( is_active ) + setIcon(tab_theme_type == "dark" ? theme_icons.second : theme_icons.first); +} + +void Tab::setColorThemeType(const QString& type) +{ + if ( tab_theme_type != type ) { + tab_theme_type = type; + setProperty("uithemetype", tab_theme_type); + + if ( is_active ) { + refreshIcon(tab_theme_type); + refreshTextColor(); + } + + refreshCloseButton(); + } +} + +void Tab::setActive(bool state) +{ + if ( state != is_active ) { + is_active = state; + + if ( is_active ) { + refreshIcon(tab_theme_type); + } else { + refreshIcon(AscAppManager::themes().current().isDark() ? "dark" : "light"); + } + + refreshTextColor(); + } +} + +void Tab::refreshIcon(const QString& themetype) +{ + setIcon(themetype == "dark" ? theme_icons.second : theme_icons.first); + icon_label->setSvgElement(themetype == "dark" ? "light" : "dark"); +} + +void Tab::refreshTextColor() +{ + const CTheme & _app_theme = AscAppManager::themes().current(); + const CTheme & _tab_theme = tab_theme_type == "dark" ? AscAppManager::themes().defaultDark() : + AscAppManager::themes().defaultLight(); + + QString _styles = "#tabText{color:" + QString::fromStdWString(_app_theme.value(CTheme::ColorRole::ecrTabSimpleActiveText)) + ";}" + "[selected=true] #tabText{color:" + QString::fromStdWString(_tab_theme.value(CTheme::ColorRole::ecrTabSimpleActiveText)) + ";}"; + text_label->setStyleSheet(_styles); +} + +void Tab::refreshCloseButton() +{ + bool _is_app_theme_dark = AscAppManager::themes().current().isDark(), + _is_tab_theme_dark = tab_theme_type == "dark"; + + QString _image_normal = _is_app_theme_dark ? ":/tabbar/icons/close_active_normal.svg" : ":/tabbar/icons/close_normal.svg"; + QString _image_hover = _is_app_theme_dark ? ":/tabbar/icons/close_active_hover.svg" : ":/tabbar/icons/close_hover.svg"; + QString _image_pressed = _is_app_theme_dark ? ":/tabbar/icons/close_active_pressed.svg" : ":/tabbar/icons/close_pressed.svg"; + QString _image_active_normal = _is_tab_theme_dark ? ":/tabbar/icons/close_active_normal.svg" : ":/tabbar/icons/close_normal.svg"; + QString _image_active_hover = _is_tab_theme_dark ? ":/tabbar/icons/close_active_hover.svg" : ":/tabbar/icons/close_hover.svg"; + QString _image_active_pressed = _is_tab_theme_dark ? ":/tabbar/icons/close_active_pressed.svg" : ":/tabbar/icons/close_pressed.svg"; + + QString _styles = "[hovered=true] #tabButton{image:url(" + _image_normal + ");}" + "[hovered=true] #tabButton:hover{image:url(" + _image_hover + ");}" + "[hovered=true] #tabButton:pressed{image:url(" + _image_pressed + ");}" + "[selected=true] #tabButton{image:url(" + _image_active_normal + ");}" + "[selected=true] #tabButton:hover{image:url(" + _image_active_hover + ");}" + "[selected=true] #tabButton:pressed{image:url(" + _image_active_pressed + ");}"; +// "CTabBar[active=false] Tab[selected=true] #tabButton{image:url(" + _image_normal + ");}" +// "CTabBar[active=false] Tab[selected=true] #tabButton:hover{image:url(" + _image_hover + ");}" +// "CTabBar[active=false] Tab[selected=true] #tabButton:pressed{image:url(" + _image_pressed + ");}" + ; + close_btn->setStyleSheet(_styles); +} + void Tab::polish() { style()->polish(this); @@ -176,7 +279,8 @@ void Tab::paintEvent(QPaintEvent *ev) { QFrame::paintEvent(ev); if (!tabcolor.isEmpty() && tabcolor != "none" && property("selected").toBool()) { - if (tabBar && tabBar->property("active").toBool() && !tabBar->ignoreActiveTabColor()) { +// if (tabBar && tabBar->property("active").toBool()) + { QStylePainter p(this); p.fillRect(rect(), QBrush(QColor(tabcolor))); } @@ -237,8 +341,6 @@ public: Qt::TextElideMode elideMode; Tab* movedTab = nullptr; bool lock = false; - bool isUIThemeDark = false; - bool ignore_tabcolor = false; int animationInProgress = 0; int movedTabPosX = 0; int movedTabPressPosX = 0; @@ -383,13 +485,21 @@ void CTabBar::CTabBarPrivate::onCurrentChanged(int index) { while (animationInProgress) qApp->processEvents(); + recalcWidth(); - scrollTo(index); + + if ( !(index < 0) ) + scrollTo(index); + currentIndex = index; + for (int i = 0; i < tabList.size(); i++) { tabList[i]->setProperty("selected", i == index); + + tabList[i]->setActive(i == index); tabList[i]->polish(); } + emit owner->currentChanged(index); } @@ -788,8 +898,10 @@ void CTabBar::setCurrentIndex(int index) { while (d->animationInProgress) qApp->processEvents(); - if (!d->indexIsValid(index) || index == d->currentIndex) + + if (/*!d->indexIsValid(index) ||*/ index == d->currentIndex) return; + d->onCurrentChanged(index); } @@ -821,10 +933,18 @@ void CTabBar::setTabLoading(int index, bool start) } } -void CTabBar::setTabIconTheme(int index, TabTheme theme) +void CTabBar::setTabThemeType(int index, TabTheme theme) { - if (CAnimatedIcon * icon = (CAnimatedIcon*)tabIconLabel(index)) - icon->setSvgElement(theme == TabTheme::LightTab ? "dark" : "light"); + if ( d->indexIsValid(index) ) { + d->tabList[index]->setColorThemeType(TabTheme::LightTab == theme ? "light" : "dark"); + } +} + +void CTabBar::setTabThemeIcons(int index, const std::pair & icons) +{ + if ( d->indexIsValid(index) ) { + d->tabList[index]->setThemeIcons(icons); + } } void CTabBar::tabStartLoading(int index, const QString& theme) @@ -834,16 +954,6 @@ void CTabBar::tabStartLoading(int index, const QString& theme) icon->startSvg(":/tabbar/icons/loader.svg", theme); } -void CTabBar::setIgnoreActiveTabColor(bool ignore) -{ - d->ignore_tabcolor = ignore; -} - -bool CTabBar::ignoreActiveTabColor() -{ - return d->ignore_tabcolor; -} - void CTabBar::polish() { for (int i = 0; i < d->tabList.size(); i++) @@ -854,6 +964,20 @@ void CTabBar::polish() d->rightButton->style()->polish(d->rightButton); } +void CTabBar::refreshTheme() +{ + for (int i = 0; i < d->tabList.size(); i++) { + d->tabList[i]->refreshCloseButton(); + d->tabList[i]->refreshTextColor(); + + if ( i != currentIndex() ) + d->tabList[i]->refreshIcon(AscAppManager::themes().current().isDark() ? "dark" : "light"); + else d->tabList[i]->refreshIcon(d->tabList[i]->tab_theme_type); + + d->tabList[i]->polish(); + } +} + int CTabBar::tabIndexAt(const QPoint &pos) const { QPoint rel_pos = d->tabArea->mapFromParent(pos); diff --git a/win-linux/src/components/ctabbar.h b/win-linux/src/components/ctabbar.h index 7075fa4aa..d2960feae 100644 --- a/win-linux/src/components/ctabbar.h +++ b/win-linux/src/components/ctabbar.h @@ -70,11 +70,11 @@ public: void setActiveTabColor(int index, const QString&); void setUseTabCustomPalette(int, bool); void setTabLoading(int, bool); - void setTabIconTheme(int, TabTheme); + void setTabThemeType(int, TabTheme); + void setTabThemeIcons(int, const std::pair &); void tabStartLoading(int, const QString& theme = QString()); - void setIgnoreActiveTabColor(bool ignore); - bool ignoreActiveTabColor(); void polish(); + void refreshTheme(); int tabIndexAt(const QPoint &pos) const; QWidget* tabIconLabel(int index) const; QWidget* tabButton(int index) const; diff --git a/win-linux/src/windows/cmainwindow.cpp b/win-linux/src/windows/cmainwindow.cpp index 6e159479b..6bf6df012 100644 --- a/win-linux/src/windows/cmainwindow.cpp +++ b/win-linux/src/windows/cmainwindow.cpp @@ -702,10 +702,11 @@ void CMainWindow::onPortalLogin(int viewid, const std::wstring &json) QString _ui_theme = objRoot["uiTheme"].toString(); if ( !_ui_theme.isEmpty() ) { // onFileLocation(vid, _url); + + if ( _ui_theme == "default-dark" ) + m_pTabs->setTabThemeType(m_pTabs->tabIndexByView(viewid), "dark"); } } - - m_pTabs->tabIndexByView(viewid); } }