1 #include "mainwindow.h"
3 MainWindow::MainWindow(QWidget
*parent
) : QMainWindow(parent
) {
4 /* Main window properties */
5 setWindowTitle("Skavegra");
6 setWindowIcon(QPixmap(":/gfx/Skavegra.svg"));
10 programMenu
= new QMenu("&Program", this);
11 actionQuit
= programMenu
->addAction("&Quit");
12 actionQuit
->setIcon(QIcon::fromTheme("application-exit"));
13 actionQuit
->setShortcut(Qt::Key_Q
);
14 actionQuit
->setStatusTip("Close this program");
15 menuBar()->addMenu(programMenu
);
17 fileMenu
= new QMenu("&File", this);
18 actionOpen
= fileMenu
->addAction("&Open");
19 actionOpen
->setIcon(QIcon::fromTheme("document-open"));
20 actionOpen
->setStatusTip("Open and display an existing SVG document");
21 actionOpen
->setShortcut(Qt::Key_O
);
22 actionReOpen
= fileMenu
->addAction("&Reload");
23 actionReOpen
->setIcon(QIcon::fromTheme("view-refresh"));
24 actionReOpen
->setEnabled(false);
25 actionReOpen
->setShortcut(Qt::Key_R
);
26 actionReOpen
->setStatusTip("Open the currently opened SVG document again to make changes visible");
27 actionClose
= fileMenu
->addAction("&Close");
28 actionClose
->setEnabled(false);
29 actionClose
->setShortcut(Qt::Key_C
);
30 actionClose
->setStatusTip("Close the currently opened SVG document");
31 menuBar()->addMenu(fileMenu
);
33 viewMenu
= new QMenu("&View", this);
34 actionZoomIn
= viewMenu
->addAction("Zoom &in");
35 actionZoomIn
->setIcon(QIcon::fromTheme("zoom-in"));
36 actionZoomIn
->setEnabled(false);
37 actionZoomIn
->setShortcut(Qt::Key_Plus
);
38 actionZoomIn
->setStatusTip("Increase the displaying size of the shown image");
39 actionZoomOut
= viewMenu
->addAction("Zoom &out");
40 actionZoomOut
->setIcon(QIcon::fromTheme("zoom-out"));
41 actionZoomOut
->setEnabled(false);
42 actionZoomOut
->setShortcut(Qt::Key_Minus
);
43 actionZoomOut
->setStatusTip("Decrease the displaying size of the shown image");
44 actionZoomReset
= viewMenu
->addAction("&Reset zoom");
45 actionZoomReset
->setIcon(QIcon::fromTheme("zoom-original"));
46 actionZoomReset
->setEnabled(false);
47 actionZoomReset
->setShortcut(Qt::Key_0
);
48 actionZoomReset
->setStatusTip("Set the displaying size of the shown image to its default size");
49 actionZoomBestFit
= viewMenu
->addAction("&Best fit");
50 actionZoomBestFit
->setIcon(QIcon::fromTheme("zoom-fit-best"));
51 actionZoomBestFit
->setEnabled(false);
52 actionZoomBestFit
->setShortcut(Qt::Key_F
);
53 actionZoomBestFit
->setStatusTip("Automatically adjust the displaying size of the shown image to \
54 fill the window, with respect to its aspect ratio");
55 menuBar()->addMenu(viewMenu
);
57 aboutMenu
= new QMenu("&About", this);
58 actionAbout
= aboutMenu
->addAction("&About");
59 actionAbout
->setIcon(QIcon::fromTheme("help-about"));
60 actionAbout
->setStatusTip("Show information about this program");
61 menuBar()->addMenu(aboutMenu
);
66 /* Central widget: The SVG viewer */
67 svgViewer
= new SVGViewer();
68 setCentralWidget(svgViewer
);
70 /* Signals and slots */
71 connect(actionQuit
, SIGNAL(triggered()), this, SLOT(close()));
72 connect(actionOpen
, SIGNAL(triggered()), this, SLOT(openFileDialog()));
73 connect(actionReOpen
, SIGNAL(triggered()), this, SLOT(reOpen()));
74 connect(actionClose
, SIGNAL(triggered()), this, SLOT(closeFile()));
75 connect(actionZoomIn
, SIGNAL(triggered()), svgViewer
, SLOT(zoomIn()));
76 connect(actionZoomOut
, SIGNAL(triggered()), svgViewer
, SLOT(zoomOut()));
77 connect(actionZoomReset
, SIGNAL(triggered()), svgViewer
, SLOT(zoomReset()));
78 connect(actionAbout
, SIGNAL(triggered()), this, SLOT(aboutDialog()));
80 statusBar()->showMessage("Skavegra 0.1.0 started.", 5000);
83 void MainWindow::reOpen() {
84 /* Reset the currently opened document and load and render it again */
85 if(lastFileName
!= NULL
) {
86 if(svgViewer
->openFile(lastFileName
)) {
87 actionClose
->setEnabled(true);
88 statusBar()->showMessage(QString("File successfully reopened: %1").arg(lastFileName
), 5000);
90 statusBar()->showMessage(QString("File could not be reopened: %1").arg(lastFileName
), 5000);
95 void MainWindow::openFileDialog() {
96 /* Open the “Open file …” dialog */
98 fileName
= QFileDialog::getOpenFileName(this, "Open SVG file …", ".",
99 "Scalable Vector Graphics (*.svg *.svgz *.svg.gz)");
100 if (fileName
== NULL
) {
101 /* No file selected */
105 /* Delegate file opening to svgViewer */
106 if(svgViewer
->openFile(fileName
)) {
107 lastFileName
= fileName
;
108 statusBar()->showMessage(QString("File successfully opened: %1").arg(fileName
), 5000);
109 actionReOpen
->setEnabled(true);
110 actionClose
->setEnabled(true);
111 actionZoomIn
->setEnabled(true);
112 actionZoomOut
->setEnabled(true);
113 actionZoomReset
->setEnabled(true);
115 statusBar()->showMessage(QString("File could not be opened: %1").arg(fileName
), 5000);
119 void MainWindow::aboutDialog() {
120 QMessageBox::about(this, "About Skavegra",
121 "<h1>Skavegra 0.1.0</h1><p>Skavegra is a simple non-conforming \
122 viewer for SVG (Scalable Vector Graphics) images as specified in the SVG Tiny 1.2 specification.</p>\
123 <p>This software is not finished yet and is unable to display some SVG images correctly.");
126 void MainWindow::closeFile() {
127 /* Close the current file and reset the view */
128 svgViewer
->closeFile();
129 actionReOpen
->setEnabled(false);
130 actionClose
->setEnabled(false);
131 actionZoomIn
->setEnabled(false);
132 actionZoomOut
->setEnabled(false);
133 actionZoomReset
->setEnabled(false);
134 actionZoomBestFit
->setEnabled(false);
135 statusBar()->showMessage(QString("File has been closed."), 5000);