Skip to content

Commit

Permalink
feat(tabbar): support background gradient.
Browse files Browse the repository at this point in the history
Change-Id: I717976ae43046976bf60e438215eaf31f21de049
  • Loading branch information
rekols committed Sep 12, 2018
1 parent 226e139 commit 279dffa
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 16 deletions.
10 changes: 6 additions & 4 deletions editor/src/tabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ bool TabWidget::eventFilter(QObject *, QEvent *event)
static_cast<Window*>(this->window())->changeTitlebarBackground(m_dndStartColor, m_dndEndColor);
}
} else if (event->type() == QEvent::DragLeave) {
static_cast<Window*>(this->window())->changeTitlebarBackground(m_backgroundColor);
static_cast<Window*>(this->window())->changeTitlebarBackground(m_backgroundStartColor, m_backgroundEndColor);
} else if (event->type() == QEvent::Drop) {
static_cast<Window*>(this->window())->changeTitlebarBackground(m_backgroundColor);
static_cast<Window*>(this->window())->changeTitlebarBackground(m_backgroundStartColor, m_backgroundEndColor);
} else if (event->type() == QEvent::DragMove) {
event->accept();
}
Expand Down Expand Up @@ -274,9 +274,11 @@ void TabWidget::handleDragActionChanged(Qt::DropAction action)
}
}

void TabWidget::setBackground(QString color)

void TabWidget::setBackground(const QString &startColor, const QString &endColor)
{
m_backgroundColor = color;
m_backgroundStartColor = startColor;
m_backgroundEndColor = endColor;
}

void TabWidget::setDNDColor(QString startColor, QString endColor)
Expand Down
6 changes: 4 additions & 2 deletions editor/src/tabwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TabWidget : public DTabBar
void insertFromMimeData(int index, const QMimeData *source);
void insertFromMimeDataOnDragEnter(int index, const QMimeData *source);

void setBackground(QString color);
void setBackground(const QString &startColor, const QString &endColor);
void setDNDColor(QString startColor, QString endColor);

signals:
Expand All @@ -65,7 +65,9 @@ public slots:
QAction *m_closeTabAction;
QMenu *m_menu;
int m_rightClickTab;
QString m_backgroundColor;

QString m_backgroundStartColor;
QString m_backgroundEndColor;
QString m_dndStartColor;
QString m_dndEndColor;
};
Expand Down
10 changes: 6 additions & 4 deletions editor/src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,16 +1246,18 @@ void Window::loadTheme(const QString &path)

QVariantMap jsonMap = Utils::getThemeMapFromPath(path);
const QString &backgroundColor = jsonMap["editor-colors"].toMap()["background-color"].toString();
m_tabbarBackgroundColor = jsonMap["app-colors"].toMap()["tab-background-color"].toString();
m_tabbarActiveColor = jsonMap["app-colors"].toMap()["tab-active"].toString();

if (QColor(m_tabbarBackgroundColor).lightness() < 128) {
const QString &tabbarStartColor = jsonMap["app-colors"].toMap()["tab-background-start-color"].toString();
const QString &tabbarEndColor = jsonMap["app-colors"].toMap()["tab-background-end-color"].toString();

if (QColor(backgroundColor).lightness() < 128) {
DThemeManager::instance()->setTheme("dark");
} else {
DThemeManager::instance()->setTheme("light");
}

changeTitlebarBackground(m_tabbarBackgroundColor);
changeTitlebarBackground(tabbarStartColor, tabbarEndColor);

for (Editor *editor : m_editorMap.values()) {
editor->textEditor->setThemeWithPath(path);
Expand All @@ -1266,7 +1268,7 @@ void Window::loadTheme(const QString &path)
m_replaceBar->setBackground(backgroundColor);
m_findBar->setBackground(backgroundColor);
m_tabbar->tabbar->setDNDColor(jsonMap["app-colors"].toMap()["tab-dnd-start"].toString(), jsonMap["app-colors"].toMap()["tab-dnd-end"].toString());
m_tabbar->tabbar->setBackground(m_tabbarBackgroundColor);
m_tabbar->tabbar->setBackground(tabbarStartColor, tabbarEndColor);

const QString &frameSelectedColor = jsonMap["app-colors"].toMap()["themebar-frame-selected"].toString();
const QString &frameNormalColor = jsonMap["app-colors"].toMap()["themebar-frame-normal"].toString();
Expand Down
1 change: 0 additions & 1 deletion editor/src/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ public slots:
QString m_readonlySeparator = " !_! ";

QString m_themePath;
QString m_tabbarBackgroundColor;
QString m_tabbarActiveColor;
};

Expand Down
3 changes: 2 additions & 1 deletion editor/themes/breeze_dark.theme
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@
},
"app-colors" : {
"tab-active" : "#00FFFF",
"tab-background-color": "#15171A",
"tab-background-start-color" : "(20, 21, 23, 90%)",
"tab-background-end-color" : "(20, 21, 23, 90%)",
"tab-dnd-start" : "(35, 38, 41, 90%)",
"tab-dnd-end" : "(35, 38, 41, 90%)",
"themebar-frame-selected" : "#00FFFF",
Expand Down
3 changes: 2 additions & 1 deletion editor/themes/deepin.theme
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@
},
"app-colors" : {
"tab-active" : "#2CA7F8",
"tab-background-color": "#FFFFFF",
"tab-background-start-color" : "(255, 255, 255, 90%)",
"tab-background-end-color" : "(245, 245, 245, 90%)",
"tab-dnd-start" : "(0, 0, 0, 10%)",
"tab-dnd-end" : "(0, 0, 0, 5%)",
"themebar-frame-selected" : "#2CA7F8",
Expand Down
3 changes: 2 additions & 1 deletion editor/themes/printing.theme
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@
},
"app-colors" : {
"tab-active" : "#FF0000",
"tab-background-color": "#FFFFFF",
"tab-background-start-color" : "(255, 255, 255, 90%)",
"tab-background-end-color" : "(245, 245, 245, 90%)",
"tab-dnd-start" : "(0, 0, 0, 10%)",
"tab-dnd-end" : "(0, 0, 0, 5%)",
"themebar-frame-selected" : "#00FFFF",
Expand Down
3 changes: 2 additions & 1 deletion editor/themes/solarized_dark.theme
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@
},
"app-colors" : {
"tab-active" : "#93A1A1",
"tab-background-color": "#00252E",
"tab-background-start-color" : "(0, 37, 46, 90%)",
"tab-background-end-color" : "(0, 37, 46, 90%)",
"tab-dnd-start" : "(7, 54, 66, 90%)",
"tab-dnd-end" : "(10, 77, 94, 90%)",
"themebar-frame-selected" : "#2CA7F8",
Expand Down
3 changes: 2 additions & 1 deletion editor/themes/solarized_light.theme
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@
},
"app-colors" : {
"tab-active" : "#403513",
"tab-background-color": "#FDF6E3",
"tab-background-start-color" : "(253, 246, 227, 90%)",
"tab-background-end-color" : "(245, 238, 220, 90%)",
"tab-dnd-start" : "(238, 232, 213, 90%)",
"tab-dnd-end" : "(238, 232, 213, 90%)",
"themebar-frame-selected" : "#2CA7F8",
Expand Down

0 comments on commit 279dffa

Please sign in to comment.