This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
85 lines (78 loc) · 2.72 KB
/
mainwindow.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
#include "mainwindow.h"
#include "daemon.h"
#include <DApplication>
#include <DThemeManager>
#include <DVerticalLine>
#include <QDebug>
DTK_USE_NAMESPACE
MainWindow::MainWindow(QWidget* parent)
: DMainWindow(parent)
, modified(false)
{
setMinimumSize(800, 800);
mainLayout = new QHBoxLayout(this);
notesList = new ZList(this);
notesList->setObjectName("List");
notesList->setFixedWidth(300);
noteEditor = new Editor(this);
noteEditor->setObjectName("Editor");
auto spliter = new DVerticalLine(this);
spliter->setLineWidth(2);
spliter->setFixedWidth(6);
mainLayout->addWidget(notesList);
mainLayout->addWidget(spliter);
mainLayout->addWidget(noteEditor);
mainLayout->addSpacing(5);
titlebar()->setTitle(tr("便笺"));
titlebar()->setIcon(QIcon(":/images/logo256"));
titlebar()->setFixedHeight(40);
for (auto i : titlebar()->children()) { // adjust titlebar buttons so that they're vertical-centered
if (qobject_cast<QWidget*>(i))
qobject_cast<QWidget*>(i)->setFixedHeight(40);
}
auto globalSearchBox = new SearchWidget(this);
globalSearchBox->setObjectName("searchBox");
titlebar()->setCustomWidget(globalSearchBox, true);
globalSearchBox->setMaximumWidth(800);
globalSearchBox->setModel(Daemon::instance()->sourceModel());
// connect(globalSearchBox, &SearchWidget::selectItem, notesList, &ZList::setCurrentIndex);
QWidget* hiddenLayer = new QWidget(this);
hiddenLayer->setLayout(mainLayout);
mainLayout->setContentsMargins(0, 5, 0, 0);
this->setCentralWidget(hiddenLayer);
QStatusBar* stat = statusBar();
stat->setObjectName("statusBar");
stat->setFixedHeight(15);
auto saveAction = new QAction(tr("保存"));
saveAction->setShortcut(QKeySequence::Save);
connect(saveAction, &QAction::triggered, this, &MainWindow::save);
addAction(saveAction);
connect(notesList, &ZList::currentChanged, [this](const QModelIndex& item) {
noteEditor->setNote(item.data(Qt::UserRole).value<ZNote>());
});
connect(notesList, &ZList::listEmptied, [this]() { noteEditor->reset(); });
connect(noteEditor, &Editor::indexUpdated, notesList, &ZList::setCurrentIndex);
connect(Daemon::instance(), &Daemon::activateMainwindow, notesList, &ZList::setCurrentIndex);
}
MainWindow::~MainWindow()
{
qDebug() << "delete Mainwindow";
emit sigDestruct();
}
void MainWindow::initNotesList()
{
//如果没有创建过的note,自动新建
}
void MainWindow::save()
{
if (!modified)
return;
// notesList->commitChange();
Daemon::instance()->save();
modified = false;
}
void MainWindow::closeEvent(QCloseEvent* e)
{
DMainWindow::closeEvent(e);
deleteLater();
}