-
Notifications
You must be signed in to change notification settings - Fork 1
/
tabbededitorplugin.cpp
159 lines (124 loc) · 5.5 KB
/
tabbededitorplugin.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "tabbededitorplugin.h"
#include "tabbededitorconstants.h"
#include "tabsforeditorswidget.h"
#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/coreconstants.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/stylehelper.h>
#include <coreplugin/editormanager/editormanager.h>
#include <QAction>
#include <QMainWindow>
#include <QMenu>
#include <QtPlugin>
#include <QByteArray>
#include <QBoxLayout>
#include <QFrame>
#include <QMainWindow>
using namespace TabbedEditor::Internal;
TabbedEditorPlugin::TabbedEditorPlugin()
{
styleUpdatedToBaseColor = false;
}
TabbedEditorPlugin::~TabbedEditorPlugin()
{
tabbedWidget->deleteLater();
}
bool TabbedEditorPlugin::initialize(const QStringList &arguments, QString *errorString)
{
Q_UNUSED(arguments)
Q_UNUSED(errorString)
em = Core::EditorManager::instance();
connect(em, SIGNAL(editorOpened(Core::IEditor*)), this, SLOT(updateStyleToBaseColor()));
backgroundFrame = new QFrame();
QHBoxLayout *layout = new QHBoxLayout();
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
tabbedWidget = new TabsForEditorsWidget(backgroundFrame);
layout->addWidget(tabbedWidget->getTabWidget());
backgroundFrame->setLayout(layout);
QWidget *coreWidget = Core::ICore::mainWindow();
QMainWindow *mainWindow = qobject_cast<QMainWindow *>(coreWidget);
mainWindow->layout()->setSpacing(0);
QWidget* oldCentralWidget = mainWindow->centralWidget();
QWidget* newCentralWidget = new QWidget(mainWindow);
newCentralWidget->setMinimumHeight(0);
QVBoxLayout *newCentralWidgetLayout = new QVBoxLayout();
newCentralWidgetLayout->setSpacing(0);
newCentralWidgetLayout->setContentsMargins(0, 0, 0, 0);
newCentralWidgetLayout->addWidget(backgroundFrame);
newCentralWidgetLayout->addWidget(oldCentralWidget);
newCentralWidget->setLayout(newCentralWidgetLayout);
mainWindow->setCentralWidget(newCentralWidget);
backgroundFrame->setHidden(true);
ExtensionSystem::PluginManager::instance()->addObject(tabbedWidget);
return true;
}
void TabbedEditorPlugin::updateStyleToBaseColor()
{
QColor baseColor = Utils::StyleHelper::baseColor();
baseColor = baseColor.lighter(130);
QString baseColorQSS = getQssStringFromColor(baseColor);
QColor borderColor = Utils::StyleHelper::borderColor();
QString borderColorQSS = getQssStringFromColor(borderColor);
QColor highlightColor = Utils::StyleHelper::highlightColor();
QString highlightColorQSS = getQssStringFromColor(highlightColor);
QColor selectedTabBorderColor = highlightColor.lighter();
QString selectedTabBorderColorQSS = getQssStringFromColor(selectedTabBorderColor);
QColor shadowColor = Utils::StyleHelper::shadowColor();
QString shadowColorQSS = getQssStringFromColor(shadowColor);
if (styleUpdatedToBaseColor)
{
disconnect(em, SIGNAL(editorOpened(Core::IEditor*)), this, SLOT(updateStyleToBaseColor()));
return;
}
QString stylesheetPattern = getStylesheetPatternFromFile(QString::fromUtf8(":/styles/styles/default.qss"));
stylesheetPattern = stylesheetPattern.replace(QString::fromUtf8("%FRAME_BACKGROUND_COLOR%"), highlightColorQSS);
stylesheetPattern = stylesheetPattern.replace(QString::fromUtf8("%TAB_SELECTED_BORDER_COLOR%"), selectedTabBorderColorQSS);
stylesheetPattern = stylesheetPattern.replace(QString::fromUtf8("%TAB_SELECTED_BACKGROUND_COLOR%"), baseColorQSS);
stylesheetPattern = stylesheetPattern.replace(QString::fromUtf8("%TAB_SELECTED_BOTTOM_BORDER_COLOR%"), baseColorQSS);
stylesheetPattern = stylesheetPattern.replace(QString::fromUtf8("%TAB_BACKGROUND_COLOR_FROM%"), shadowColorQSS);
stylesheetPattern = stylesheetPattern.replace(QString::fromUtf8("%TAB_BACKGROUND_COLOR_TO%"), shadowColorQSS);
stylesheetPattern = stylesheetPattern.replace(QString::fromUtf8("%TAB_BORDER_COLOR%"), borderColorQSS);
stylesheetPattern = stylesheetPattern.replace(QString::fromUtf8("%TAB_BOTTOM_BORDER_COLOR%"), borderColorQSS);
backgroundFrame->setStyleSheet(stylesheetPattern);
backgroundFrame->setHidden(false);
styleUpdatedToBaseColor = true;
}
QString TabbedEditorPlugin::getQssStringFromColor(const QColor &color)
{
QString QssString = QString::fromUtf8("rgba( " ) +
QString::number(color.red()) +
QString::fromUtf8(", ") +
QString::number(color.green()) +
QString::fromUtf8(", ") +
QString::number(color.blue()) +
QString::fromUtf8(", ") +
QString::number(color.alpha()) +
QString::fromUtf8(" )");
return QssString;
}
void TabbedEditorPlugin::extensionsInitialized()
{
}
ExtensionSystem::IPlugin::ShutdownFlag TabbedEditorPlugin::aboutToShutdown()
{
return SynchronousShutdown;
}
QString TabbedEditorPlugin::getStylesheetPatternFromFile(const QString &filepath)
{
QFile stylesheetFile(filepath);
QString stylesheetContent;
if (stylesheetFile.exists())
{
if (stylesheetFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
stylesheetContent = QString::fromUtf8(stylesheetFile.readAll());
stylesheetFile.close();
}
}
return stylesheetContent;
}