forked from trollixx/qtcreator-tabbededitor-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabbededitorplugin.cpp
141 lines (106 loc) · 5.06 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
#include "tabbededitorplugin.h"
#include "tabbededitorconstants.h"
#include "tabsforeditorswidget.h"
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <utils/stylehelper.h>
#include <QBoxLayout>
#include <QFile>
#include <QFrame>
#include <QMainWindow>
using namespace TabbedEditor::Internal;
TabbedEditorPlugin::TabbedEditorPlugin() :
m_styleUpdatedToBaseColor(false)
{
}
bool TabbedEditorPlugin::initialize(const QStringList &arguments, QString *errorString)
{
Q_UNUSED(arguments)
Q_UNUSED(errorString)
m_editorManager = Core::EditorManager::instance();
connect(m_editorManager, SIGNAL(editorOpened(Core::IEditor*)), SLOT(updateStyleToBaseColor()));
m_backgroundFrame = new QFrame();
m_backgroundFrame->setMinimumHeight(25);
m_backgroundFrame->setMaximumHeight(25);
QHBoxLayout *layout = new QHBoxLayout();
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
m_tabbedWidget = new TabsForEditorsWidget(m_backgroundFrame);
layout->addWidget(m_tabbedWidget->tabWidget());
m_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(m_backgroundFrame);
newCentralWidgetLayout->addWidget(oldCentralWidget);
newCentralWidget->setLayout(newCentralWidgetLayout);
mainWindow->setCentralWidget(newCentralWidget);
m_backgroundFrame->setHidden(true);
addAutoReleasedObject(m_tabbedWidget);
return true;
}
void TabbedEditorPlugin::extensionsInitialized()
{
}
ExtensionSystem::IPlugin::ShutdownFlag TabbedEditorPlugin::aboutToShutdown()
{
return SynchronousShutdown;
}
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()
{
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 (m_styleUpdatedToBaseColor) {
disconnect(m_editorManager, SIGNAL(editorOpened(Core::IEditor*)),
this, SLOT(updateStyleToBaseColor()));
return;
}
QString stylesheetPattern = getStylesheetPatternFromFile(QString::fromUtf8(":/styles/styles/default.qss"));
stylesheetPattern = stylesheetPattern.replace(QStringLiteral("%FRAME_BACKGROUND_COLOR%"), highlightColorQSS);
stylesheetPattern = stylesheetPattern.replace(QStringLiteral("%TAB_SELECTED_BORDER_COLOR%"), selectedTabBorderColorQSS);
stylesheetPattern = stylesheetPattern.replace(QStringLiteral("%TAB_SELECTED_BACKGROUND_COLOR%"), baseColorQSS);
stylesheetPattern = stylesheetPattern.replace(QStringLiteral("%TAB_SELECTED_BOTTOM_BORDER_COLOR%"), baseColorQSS);
stylesheetPattern = stylesheetPattern.replace(QStringLiteral("%TAB_BACKGROUND_COLOR_FROM%"), shadowColorQSS);
stylesheetPattern = stylesheetPattern.replace(QStringLiteral("%TAB_BACKGROUND_COLOR_TO%"), shadowColorQSS);
stylesheetPattern = stylesheetPattern.replace(QStringLiteral("%TAB_BORDER_COLOR%"), borderColorQSS);
stylesheetPattern = stylesheetPattern.replace(QStringLiteral("%TAB_BOTTOM_BORDER_COLOR%"), borderColorQSS);
m_backgroundFrame->setStyleSheet(stylesheetPattern);
m_backgroundFrame->setHidden(false);
m_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;
}
Q_EXPORT_PLUGIN2(TabbedEditor, TabbedEditorPlugin)