-
Notifications
You must be signed in to change notification settings - Fork 37
/
plugin.cpp
122 lines (96 loc) · 4.63 KB
/
plugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "plugin.h"
#include "constants.h"
#include "tabbar.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <utils/stylehelper.h>
#include <utils/theme/theme.h>
#include <QBoxLayout>
#include <QFile>
#include <QMainWindow>
using namespace TabbedEditor::Internal;
TabbedEditorPlugin::TabbedEditorPlugin() :
m_tabBar(nullptr),
m_styleUpdatedToBaseColor(false)
{
}
bool TabbedEditorPlugin::initialize(const QStringList &arguments, QString *errorString)
{
Q_UNUSED(arguments)
Q_UNUSED(errorString)
connect(Core::ICore::instance(), SIGNAL(themeChanged()), this, SLOT(updateStyleToBaseColor()));
connect(Core::EditorManager::instance(), SIGNAL(editorOpened(Core::IEditor*)), SLOT(showTabBar()));
QMainWindow *mainWindow = qobject_cast<QMainWindow *>(Core::ICore::mainWindow());
mainWindow->layout()->setSpacing(0);
QWidget *wrapper = new QWidget(mainWindow);
wrapper->setMinimumHeight(0);
QVBoxLayout *layout = new QVBoxLayout();
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
m_tabBar = new TabBar();
layout->addWidget(m_tabBar);
layout->addWidget(mainWindow->centralWidget());
wrapper->setLayout(layout);
mainWindow->setCentralWidget(wrapper);
return true;
}
QString TabbedEditorPlugin::getStylesheetPatternFromFile(const QString &filepath)
{
QFile stylesheetFile(filepath);
if (!stylesheetFile.open(QIODevice::ReadOnly | QIODevice::Text))
return QString();
return QString::fromUtf8(stylesheetFile.readAll());
}
void TabbedEditorPlugin::updateStyleToBaseColor()
{
Utils::Theme *theme = Utils::creatorTheme();
QString baseColorQss;
QString borderColorQss;
QString highlightColorQss;
QString selectedTabBorderColorQss;
QString shadowColorQss;
if(theme->preferredStyles().isEmpty()) {
baseColorQss = getQssStringFromColor(Utils::StyleHelper::baseColor().lighter(130));
borderColorQss = getQssStringFromColor(Utils::StyleHelper::borderColor());
highlightColorQss = getQssStringFromColor(Utils::StyleHelper::baseColor());
selectedTabBorderColorQss
= getQssStringFromColor(Utils::StyleHelper::highlightColor().lighter());
shadowColorQss = getQssStringFromColor(Utils::StyleHelper::shadowColor());
} else { // Flat widget style
baseColorQss
= getQssStringFromColor(theme->color(Utils::Theme::BackgroundColorHover));
borderColorQss = getQssStringFromColor(theme->color(Utils::Theme::BackgroundColorHover));
highlightColorQss = getQssStringFromColor(theme->color(Utils::Theme::BackgroundColorDark));
selectedTabBorderColorQss
= getQssStringFromColor(theme->color(Utils::Theme::BackgroundColorDark));
shadowColorQss = getQssStringFromColor(theme->color(Utils::Theme::BackgroundColorNormal));
}
QString stylesheetPattern = getStylesheetPatternFromFile(QStringLiteral(":/styles/default.qss"));
stylesheetPattern = stylesheetPattern.replace(QLatin1String("%FRAME_BACKGROUND_COLOR%"), highlightColorQss);
stylesheetPattern = stylesheetPattern.replace(QLatin1String("%TAB_SELECTED_BORDER_COLOR%"), selectedTabBorderColorQss);
stylesheetPattern = stylesheetPattern.replace(QLatin1String("%TAB_SELECTED_BACKGROUND_COLOR%"), baseColorQss);
stylesheetPattern = stylesheetPattern.replace(QLatin1String("%TAB_SELECTED_BOTTOM_BORDER_COLOR%"), baseColorQss);
stylesheetPattern = stylesheetPattern.replace(QLatin1String("%TAB_BACKGROUND_COLOR_FROM%"), shadowColorQss);
stylesheetPattern = stylesheetPattern.replace(QLatin1String("%TAB_BACKGROUND_COLOR_TO%"), shadowColorQss);
stylesheetPattern = stylesheetPattern.replace(QLatin1String("%TAB_BORDER_COLOR%"), borderColorQss);
stylesheetPattern = stylesheetPattern.replace(QLatin1String("%TAB_BOTTOM_BORDER_COLOR%"), borderColorQss);
m_tabBar->setStyleSheet(stylesheetPattern);
}
void TabbedEditorPlugin::showTabBar()
{
updateStyleToBaseColor();
if (m_styleUpdatedToBaseColor) {
disconnect(Core::EditorManager::instance(), SIGNAL(editorOpened(Core::IEditor*)),
this, SLOT(showTabBar()));
return;
}
m_styleUpdatedToBaseColor = true;
}
QString TabbedEditorPlugin::getQssStringFromColor(const QColor &color)
{
return QString::fromLatin1("rgba(%1, %2, %3, %4)").arg(
QString::number(color.red()),
QString::number(color.green()),
QString::number(color.blue()),
QString::number(color.alpha()));
}