-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.cpp
203 lines (178 loc) · 6.16 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
removeToolBar(ui->mainToolBar);
m_FileWindow = new FileWindow(this);
// this->setCentralWidget(m_FileWindow);
this->setWindowTitle(tr("Bamboo多功能PDF阅读器"));
toolbar = new AnnoToolbar;
addToolBar(toolbar);
toolbar->initialStatus();
connect(this->m_FileWindow->m_file_list, &FileList::sendFileName, this, &MainWindow::loadPageView);
connect(toolbar->open_action, &QAction::triggered, this, &MainWindow::openNewPDF);
connect(toolbar->files_action, &QAction::triggered, this, &MainWindow::return_to_front);
this->showMaximized();
// loadPageView("/home/pysong/下载/test.pdf");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::loadPageView(QString filename)
{
m_FileWindow->hide();
if(pageviewwidget!=nullptr)
{
if(pageviewwidget->modified_status)
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("提示"), tr("您的文档尚未保存,是否保存?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Cancel);
if(reply==QMessageBox::Yes) // 文件保存,继续打开
{
pageviewwidget->mainscene->savePDF();
this->centralWidget()->close();
}
else if(reply==QMessageBox::No) // 文件未保存,继续打开
{
this->centralWidget()->close();
}
else // 操作取消
{
return;
}
}
else
{
this->centralWidget()->close();
}
delete pageviewwidget;
}
else
{
}
pageviewwidget = new PageViewWidget(filename);
this->setCentralWidget(pageviewwidget);
connect(pageviewwidget->mainscene, &MainScene::draw_completed, this->toolbar, &AnnoToolbar::resetStatus);
connect(toolbar, &AnnoToolbar::isDrawing, pageviewwidget->mainscene, &MainScene::changeIsDrawing);
connect(toolbar->saving_action, &QAction::triggered, pageviewwidget->mainscene, &MainScene::savePDF);
connect(toolbar->saving_as_action, &QAction::triggered, pageviewwidget->mainscene, &MainScene::savePDFas);
connect(toolbar->print_action, &QAction::triggered, pageviewwidget->mainscene, &MainScene::printPDF);
connect(pageviewwidget, &PageViewWidget::file_loaded, this, &MainWindow::setWindowTitle);
connect(pageviewwidget->mainscene, &MainScene::status_changed, this, &MainWindow::setModiefiedTitle);
connect(toolbar->preview_action, &QAction::triggered, pageviewwidget->mainscene, &MainScene::changePreview);
if(!(pageviewwidget->loadNewPDF()))
{
QMessageBox::about(this, tr("提示"), tr("打开PDF时出现错误,可能PDF文件已加密或超出大小!"));
return_to_front();
return;
}
toolbar->pdfStatus();
}
void MainWindow::setModiefiedTitle(bool status)
{
pageviewwidget->modified_status = status;
pageviewwidget->mainscene->modified_status = status;
if(status)
{
this->toolbar->saving_action->setEnabled(true);
this->setWindowTitle(this->pageviewwidget->filename + QString("*"));
}
else
{
this->toolbar->saving_action->setEnabled(false);
this->pageviewwidget->filename = this->pageviewwidget->mainscene->filename;
this->setWindowTitle(this->pageviewwidget->filename);
}
}
void MainWindow::openNewPDF()
{
QString open_filename = QFileDialog::getOpenFileName(this, tr("打开文件"), "", "PDF Files(*.pdf)", nullptr);
if(open_filename!="")
{
loadPageView(open_filename);
}
}
void MainWindow::return_to_front()
{
if(pageviewwidget!=nullptr)
{
if(pageviewwidget->modified_status)
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("提示"), tr("您的文档尚未保存,是否保存?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Cancel);
if(reply==QMessageBox::Yes) // 文件保存,继续打开
{
pageviewwidget->mainscene->savePDF();
}
else if(reply==QMessageBox::No) // 文件未保存,继续打开
{
}
else // 操作取消
{
return;
}
}
//removeToolBar(toolbar);
pageviewwidget->close();
delete pageviewwidget;
pageviewwidget = nullptr;
}
m_FileWindow->show();
this->setWindowTitle(tr("Bamboo多功能PDF阅读器"));
toolbar->initialStatus();
//this->setCentralWidget(m_FileWindow);
}
void MainWindow::keyPressEvent(QKeyEvent *event)
{
if(Qt::ControlModifier && event->key()==Qt::Key_S)
{
if(pageviewwidget!=nullptr)
{
if(pageviewwidget->modified_status)
{
pageviewwidget->mainscene->savePDF();
}
}
}
else if(Qt::ControlModifier && event->key()==Qt::Key_P)
{
if(pageviewwidget!=nullptr)
{
pageviewwidget->mainscene->printPDF();
}
}
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if(pageviewwidget!=nullptr)
{
if(pageviewwidget->modified_status)
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("提示"), tr("您的文档尚未保存,是否保存?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Cancel);
if(reply==QMessageBox::Yes) // 文件保存,继续打开
{
pageviewwidget->mainscene->savePDF();
}
else if(reply==QMessageBox::No) // 文件未保存,继续打开
{
}
else // 操作取消
{
event->ignore();
}
}
else
{
MainWindow::closeEvent(event);
}
}
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
if(this->m_FileWindow != nullptr) this->m_FileWindow->mresize(this->size());
}