-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSnippetView.cpp
More file actions
54 lines (42 loc) · 1.53 KB
/
SnippetView.cpp
File metadata and controls
54 lines (42 loc) · 1.53 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
#include "SnippetView.h"
#include <QVBoxLayout>
#include <QLabel>
#include <QApplication>
SnippetView::SnippetView(SnippetController& controller) : controller(controller) {
QVBoxLayout* layout = new QVBoxLayout(this);
QLabel* titleLabel = new QLabel("Title:", this);
titleInput = new QLineEdit(this);
QLabel* languageLabel = new QLabel("Language:", this);
languageInput = new QLineEdit(this);
QLabel* tagsLabel = new QLabel("Tags (comma-separated):", this);
tagsInput = new QLineEdit(this);
QLabel* codeLabel = new QLabel("Code:", this);
codeInput = new QTextEdit(this);
addButton = new QPushButton("Add Snippet", this);
snippetList = new QListWidget(this);
layout->addWidget(titleLabel);
layout->addWidget(titleInput);
layout->addWidget(languageLabel);
layout->addWidget(languageInput);
layout->addWidget(tagsLabel);
layout->addWidget(tagsInput);
layout->addWidget(codeLabel);
layout->addWidget(codeInput);
layout->addWidget(addButton);
layout->addWidget(snippetList);
connect(addButton, &QPushButton::clicked, this, &SnippetView::addSnippet);
refreshSnippetList();
}
void SnippetView::refreshSnippetList() {
snippetList->clear();
for (const CodeSnippet& snippet : controller.getAllSnippets()) {
snippetList->addItem(QString::fromStdString(snippet.getTitle()));
}
}
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
SnippetController controller;
SnippetView view(controller);
view.show();
return app.exec();
}