-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsidebarview.cpp
More file actions
executable file
·121 lines (94 loc) · 3.55 KB
/
sidebarview.cpp
File metadata and controls
executable file
·121 lines (94 loc) · 3.55 KB
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
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QLabel>
#include <QStackedLayout>
#include <QGradient>
#include <QLineEdit>
#include <QPushButton>
#include <QStyle>
#include <QDebug>
#include "sidebarview.h"
#include "contentview.h"
#include "recentfilesview.h"
#include "themefile.h"
#include "inferredvariablesview.h"
#include "toggleviewhost.h"
SideBarView::SideBarView(ContentView *parent) :
QWidget(parent)
{
this->contentView = parent;
this->setContentsMargins(0, 0, 0, 0);
QStackedLayout* mainZStack = new QStackedLayout();
mainZStack->setStackingMode(QStackedLayout::StackAll);
// Creating the widget to host the background gradient
background = new QWidget(this);
// Creating the main VStack to host widgets in front of the background
QVBoxLayout* mainVStack = new QVBoxLayout();
// Creating the label to show the current file directory
QHBoxLayout* fileHStack = new QHBoxLayout();
fileDisplay = new QLineEdit("Please select a file", this);
fileDisplay->setDisabled(true);
fileHStack->addWidget(fileDisplay);
QPushButton* fileButton = new QPushButton(this->style()->standardIcon(QStyle::SP_DirOpenIcon), "", this);
fileButton->setToolTip("Open file");
fileHStack->addWidget(fileButton);
mainVStack->addLayout(fileHStack);
// Creating a recent files view
recentFilesView = new RecentFilesView(this->contentView);
mainVStack->addWidget(recentFilesView);
inferredVariablesView = new InferredVariablesView(this->contentView);
mainVStack->addWidget(inferredVariablesView);
QWidget* dummyZStackWidget = new QWidget();
dummyZStackWidget->setLayout(mainVStack);
mainZStack->addWidget(background);
mainZStack->addWidget(dummyZStackWidget);
this->setLayout(mainZStack);
connect(fileButton, SIGNAL(released()), this->contentView, SLOT(obtainScriptFile()));
QObject::connect(inferredVariablesView, &ToggleViewHost::shown, this, [=]() {
if (mainVStack->count()) {
QLayoutItem* stretch = mainVStack->takeAt(mainVStack->count()-1);
delete stretch;
}
});
QObject::connect(inferredVariablesView, &ToggleViewHost::hidden, this, [=]() {
mainVStack->addStretch();
});
}
void SideBarView::setDarkTheme()
{
background->setStyleSheet("background-color: qlineargradient( x1:0 y1:1, x2:0 y2:0, stop:0 #454545, stop:1 #808080);");
saveTheme("theme.cfg", DARK);
}
void SideBarView::setDefaultTheme()
{
background->setStyleSheet("background-color: qlineargradient( x1:0 y1:1, x2:0 y2:0, stop:0 #6375d7, stop:1 #7ba2e6);");
saveTheme("theme.cfg", DEFAULT);
}
void SideBarView::setClassicTheme()
{
background->setStyleSheet("background-color: palette(window);");
saveTheme("theme.cfg", CLASSIC);
}
void SideBarView::setTheme(Theme theme) {
switch (theme) {
case CLASSIC:
this->setClassicTheme();
this->recentFilesView->setClassicTheme();
this->inferredVariablesView->setClassicTheme();
break;
case DARK:
this->setDarkTheme();
this->recentFilesView->setDarkTheme();
this->inferredVariablesView->setDarkTheme();
break;
default:
this->setDefaultTheme();
this->recentFilesView->setDefaultTheme();
this->inferredVariablesView->setDefaultTheme();
}
}
void SideBarView::setFileLabel(QString text) {
this->fileDisplay->setText(text);
this->fileDisplay->setToolTip(text);
}