1 #include "mainwindow.h"
3 MainWindow::MainWindow(QWidget
*parent
)
6 /* Main window properties */
7 setWindowTitle("Skavegra");
10 programMenu
= new QMenu("&Program", this);
11 actionQuit
= programMenu
->addAction("&Quit");
12 actionQuit
->setIcon(QIcon::fromTheme("application-exit"));
13 menuBar()->addMenu(programMenu
);
15 fileMenu
= new QMenu("&File", this);
16 actionOpen
= fileMenu
->addAction("&Open");
17 actionOpen
->setIcon(QIcon::fromTheme("document-open"));
18 actionReOpen
= fileMenu
->addAction("&Reload");
19 actionReOpen
->setIcon(QIcon::fromTheme("document-revert"));
20 actionReOpen
->setEnabled(false);
21 actionClose
= fileMenu
->addAction("&Close");
22 actionClose
->setEnabled(false);
23 menuBar()->addMenu(fileMenu
);
25 viewMenu
= new QMenu("&View", this);
26 actionZoomIn
= viewMenu
->addAction("Zoom &in");
27 actionZoomIn
->setIcon(QIcon::fromTheme("zoom-in"));
28 actionZoomOut
= viewMenu
->addAction("Zoom &out");
29 actionZoomOut
->setIcon(QIcon::fromTheme("zoom-out"));
30 actionZoomReset
= viewMenu
->addAction("&Reset zoom");
31 actionZoomReset
->setIcon(QIcon::fromTheme("zoom-original"));
32 actionZoomBestFit
= viewMenu
->addAction("&Best fit");
33 actionZoomBestFit
->setIcon(QIcon::fromTheme("zoom-fit-best"));
34 menuBar()->addMenu(viewMenu
);
36 aboutMenu
= new QMenu("&About", this);
37 actionAbout
= aboutMenu
->addAction("A&bout");
38 actionAbout
->setIcon(QIcon::fromTheme("help-about"));
39 menuBar()->addMenu(aboutMenu
);
43 svgViewer
= new SVGViewer();
45 setCentralWidget(svgViewer
);
47 /* Error messages and other dialogs */
48 errorFileOpen
= new QErrorMessage(this);
50 /* Signals and slots */
51 connect(actionQuit
, SIGNAL(triggered()), this, SLOT(close()));
52 connect(actionOpen
, SIGNAL(triggered()), this, SLOT(openFileDialog()));
53 connect(actionReOpen
, SIGNAL(triggered()), this, SLOT(reOpen()));
54 connect(actionClose
, SIGNAL(triggered()), this, SLOT(closeFile()));
55 connect(actionZoomIn
, SIGNAL(triggered()), svgViewer
, SLOT(zoomIn()));
56 connect(actionZoomOut
, SIGNAL(triggered()), svgViewer
, SLOT(zoomOut()));
59 void MainWindow::reOpen() {
60 if(lastFileName
!= NULL
) {
61 if(svgViewer
->openFile(lastFileName
)) {
62 actionClose
->setEnabled(true);
68 void MainWindow::openFileDialog() {
70 fileName
= QFileDialog::getOpenFileName(this, "Load file …", ".", "Scalable Vector Graphics (*.svg *.svgz *.svg.gz)");
71 if (fileName
== NULL
) {
74 lastFileName
= fileName
;
76 if(svgViewer
->openFile(fileName
)) {
77 actionReOpen
->setEnabled(true);
78 actionClose
->setEnabled(true);
82 void MainWindow::closeFile() {
83 svgViewer
->closeFile();
84 actionReOpen
->setEnabled(false);
85 actionClose
->setEnabled(false);
88 MainWindow::~MainWindow()