-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsolutionbrowser.cpp
More file actions
94 lines (77 loc) · 3.18 KB
/
Copy pathtsolutionbrowser.cpp
File metadata and controls
94 lines (77 loc) · 3.18 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
#include "tsolutionbrowser.h"
#include <QAction>
#include <QFileDialog>
#include <QUrl>
#include <QVBoxLayout>
#include <QtPrintSupport/QPrintDialog>
#include <QtPrintSupport/QPrinter>
TSolutionBrowser::TSolutionBrowser(QWidget* parent) : QWidget(parent) {
setWindowFlags(Qt::Window);
QVBoxLayout* layout = new QVBoxLayout(this);
WebView = new QWebEngineView(this);
ToolBar = new QToolBar(this);
ToolBar->setIconSize(QSize(48, 48));
layout->addWidget(ToolBar);
layout->addWidget(WebView);
setLayout(layout);
// RegisterToolButton(":formulas/Pictures/Formulas/arrow_left_48.png", "Back", WebView, SLOT(back()));
// RegisterToolButton(":formulas/Pictures/Formulas/arrow_right_48.png", "Forward", WebView, SLOT(forward()));
RegisterToolButton(":Commands/Pictures/Commands/Zoom In_48x48.png", "ZoomIn", this, SLOT(ZoomIn()));
RegisterToolButton(":Commands/Pictures/Commands/Zoom Out_48x48.png", "ZoomOut", this, SLOT(ZoomOut()));
ToolBar->addSeparator();
// RegisterToolButton(":Commands/Pictures/Commands/floppy_disk_48.png", "Save", this, SLOT(Save()));
RegisterToolButton(":Commands/Pictures/Commands/file_pdf.png", "Export PDF", this, SLOT(ExportToPDF()));
RegisterToolButton(":Commands/Pictures/Commands/print.png", "Print", this, SLOT(Print()));
ToolBar->addSeparator();
QWidget* spacer = new QWidget();
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
ToolBar->addWidget(spacer);
ToolBar->addSeparator();
RegisterToolButton(":Commands/Pictures/Commands/cross_48.png", "Close", this, SLOT(Close()));
SetCaption("Mathstyle Pro Browser");
setMinimumSize(800, 600);
};
void TSolutionBrowser::RegisterToolButton(const char* Img, QString ToolTip, QWidget* Receiver, const char* Slot) {
QIcon* Icon = new QIcon(Img);
ToolBar->addAction(*Icon, ToolTip, Receiver, Slot);
delete Icon;
}
void TSolutionBrowser::Load(QString DocumentFolder, QString FileName) {
QUrl URL = QUrl::fromLocalFile(DocumentFolder + "/" + FileName);
// URL.setPath(DocumentFolder);
WebView->load(URL);
// WebView->load(QUrl("http://mail.ru"));
// WebView->setHtml(FileName, QUrl(URL));
}
void TSolutionBrowser::SetCaption(QString Caption) {
this->setWindowTitle(Caption);
}
void TSolutionBrowser::ZoomIn() {
WebView->setZoomFactor(2.0 * WebView->zoomFactor());
}
void TSolutionBrowser::ZoomOut() {
WebView->setZoomFactor(0.5 * WebView->zoomFactor());
}
void TSolutionBrowser::Save() {}
void TSolutionBrowser::Print() {
QPrinter printer;
QPrintDialog printDialog(&printer, this);
if (printDialog.exec() == QDialog::Accepted) {
WebView->print(&printer);
}
}
void TSolutionBrowser::ExportToPDF() {
QString fileName = QFileDialog::getSaveFileName(this, tr("Export as Pdf.."), "", tr("PDF files (*.pdf)"));
if (fileName.isEmpty())
return;
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
printer.setFullPage(false);
printer.setPageOrientation(QPageLayout::Orientation::Portrait);
printer.setPageSize(QPageSize::A4);
WebView->print(&printer);
}
void TSolutionBrowser::Close() {
this->close();
}