mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 03:29:16 +02:00
Added printing support
"Save" is now "Export"
This commit is contained in:
77
src/gui.cpp
77
src/gui.cpp
@ -4,6 +4,7 @@
|
||||
#include <QStatusBar>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <QPrintDialog>
|
||||
#include <QPrinter>
|
||||
#include <QPainter>
|
||||
#include <QKeyEvent>
|
||||
@ -202,18 +203,21 @@ void GUI::createActions()
|
||||
_openFileAction->setShortcut(OPEN_SHORTCUT);
|
||||
connect(_openFileAction, SIGNAL(triggered()), this, SLOT(openFile()));
|
||||
addAction(_openFileAction);
|
||||
_saveFileAction = new QAction(QIcon(QPixmap(SAVE_FILE_ICON)),
|
||||
tr("Save"), this);
|
||||
_saveFileAction->setShortcut(SAVE_SHORTCUT);
|
||||
_saveFileAction->setActionGroup(_fileActionGroup);
|
||||
connect(_saveFileAction, SIGNAL(triggered()), this, SLOT(saveFile()));
|
||||
addAction(_saveFileAction);
|
||||
_saveAsAction = new QAction(QIcon(QPixmap(SAVE_AS_ICON)),
|
||||
tr("Save as"), this);
|
||||
_saveAsAction->setShortcut(SAVE_AS_SHORTCUT);
|
||||
_saveAsAction->setActionGroup(_fileActionGroup);
|
||||
connect(_saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs()));
|
||||
addAction(_saveAsAction);
|
||||
_printFileAction = new QAction(QIcon(QPixmap(PRINT_FILE_ICON)),
|
||||
tr("Print"), this);
|
||||
_printFileAction->setActionGroup(_fileActionGroup);
|
||||
connect(_printFileAction, SIGNAL(triggered()), this, SLOT(printFile()));
|
||||
addAction(_printFileAction);
|
||||
_exportFileAction = new QAction(QIcon(QPixmap(EXPORT_FILE_ICON)),
|
||||
tr("Export"), this);
|
||||
_exportFileAction->setShortcut(EXPORT_SHORTCUT);
|
||||
_exportFileAction->setActionGroup(_fileActionGroup);
|
||||
connect(_exportFileAction, SIGNAL(triggered()), this, SLOT(exportFile()));
|
||||
addAction(_exportFileAction);
|
||||
_exportAsAction = new QAction(QIcon(QPixmap(EXPORT_FILE_ICON)),
|
||||
tr("Export as"), this);
|
||||
_exportAsAction->setActionGroup(_fileActionGroup);
|
||||
connect(_exportAsAction, SIGNAL(triggered()), this, SLOT(exportAs()));
|
||||
_closeFileAction = new QAction(QIcon(QPixmap(CLOSE_FILE_ICON)),
|
||||
tr("Close"), this);
|
||||
_closeFileAction->setShortcut(CLOSE_SHORTCUT);
|
||||
@ -321,8 +325,9 @@ void GUI::createMenus()
|
||||
_fileMenu = menuBar()->addMenu(tr("File"));
|
||||
_fileMenu->addAction(_openFileAction);
|
||||
_fileMenu->addSeparator();
|
||||
_fileMenu->addAction(_saveFileAction);
|
||||
_fileMenu->addAction(_saveAsAction);
|
||||
_fileMenu->addAction(_printFileAction);
|
||||
_fileMenu->addAction(_exportFileAction);
|
||||
_fileMenu->addAction(_exportAsAction);
|
||||
_fileMenu->addSeparator();
|
||||
_fileMenu->addAction(_reloadFileAction);
|
||||
_fileMenu->addSeparator();
|
||||
@ -375,9 +380,10 @@ void GUI::createToolBars()
|
||||
|
||||
_fileToolBar = addToolBar(tr("File"));
|
||||
_fileToolBar->addAction(_openFileAction);
|
||||
_fileToolBar->addAction(_saveFileAction);
|
||||
_fileToolBar->addAction(_reloadFileAction);
|
||||
_fileToolBar->addAction(_closeFileAction);
|
||||
_fileToolBar->addAction(_exportFileAction);
|
||||
_fileToolBar->addAction(_printFileAction);
|
||||
|
||||
_showToolBar = addToolBar(tr("Show"));
|
||||
_showToolBar->addAction(_showPOIAction);
|
||||
@ -629,26 +635,35 @@ void GUI::closePOIFiles()
|
||||
_poi.clear();
|
||||
}
|
||||
|
||||
void GUI::saveAs()
|
||||
void GUI::printFile()
|
||||
{
|
||||
QPrinter printer(QPrinter::HighResolution);
|
||||
QPrintDialog printDialog(&printer, this);
|
||||
|
||||
if (printDialog.exec() == QDialog::Accepted)
|
||||
plot(&printer);
|
||||
}
|
||||
|
||||
void GUI::exportAs()
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(this, "Export to PDF",
|
||||
QString(), "*.pdf");
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
saveFile(fileName);
|
||||
_saveFileName = fileName;
|
||||
exportFile(fileName);
|
||||
_exportFileName = fileName;
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::saveFile()
|
||||
void GUI::exportFile()
|
||||
{
|
||||
if (_saveFileName.isEmpty())
|
||||
emit saveAs();
|
||||
if (_exportFileName.isEmpty())
|
||||
emit exportAs();
|
||||
else
|
||||
saveFile(_saveFileName);
|
||||
exportFile(_exportFileName);
|
||||
}
|
||||
|
||||
void GUI::saveFile(const QString &fileName)
|
||||
void GUI::exportFile(const QString &fileName)
|
||||
{
|
||||
QPrinter printer(QPrinter::HighResolution);
|
||||
printer.setPageSize(QPrinter::A4);
|
||||
@ -656,9 +671,15 @@ void GUI::saveFile(const QString &fileName)
|
||||
printer.setOutputFormat(QPrinter::PdfFormat);
|
||||
printer.setOutputFileName(fileName);
|
||||
|
||||
QPainter p(&printer);
|
||||
plot(&printer);
|
||||
}
|
||||
|
||||
void GUI::plot(QPrinter *printer)
|
||||
{
|
||||
QPainter p(printer);
|
||||
|
||||
TrackInfo info;
|
||||
|
||||
if (_imperialUnitsAction->isChecked()) {
|
||||
info.insert(tr("Distance"), QString::number(_distance * M2MI, 'f', 1)
|
||||
+ UNIT_SPACE + tr("mi"));
|
||||
@ -685,11 +706,11 @@ void GUI::saveFile(const QString &fileName)
|
||||
0) + UNIT_SPACE + tr("m"));
|
||||
}
|
||||
|
||||
_track->plot(&p, QRectF(0, 300, printer.width(), (0.80 * printer.height())
|
||||
_track->plot(&p, QRectF(0, 300, printer->width(), (0.80 * printer->height())
|
||||
- 400));
|
||||
_elevationGraph->plot(&p, QRectF(0, 0.80 * printer.height(),
|
||||
printer.width(), printer.height() * 0.20));
|
||||
info.plot(&p, QRectF(0, 0, printer.width(), 200));
|
||||
_elevationGraph->plot(&p, QRectF(0, 0.80 * printer->height(),
|
||||
printer->width(), printer->height() * 0.20));
|
||||
info.plot(&p, QRectF(0, 0, printer->width(), 200));
|
||||
}
|
||||
|
||||
void GUI::reloadFile()
|
||||
|
16
src/gui.h
16
src/gui.h
@ -13,6 +13,7 @@ class QActionGroup;
|
||||
class QAction;
|
||||
class QLabel;
|
||||
class QSignalMapper;
|
||||
class QPrinter;
|
||||
class FileBrowser;
|
||||
class GraphView;
|
||||
class ElevationGraph;
|
||||
@ -35,8 +36,9 @@ private slots:
|
||||
void about();
|
||||
void keys();
|
||||
void dataSources();
|
||||
void saveFile();
|
||||
void saveAs();
|
||||
void printFile();
|
||||
void exportFile();
|
||||
void exportAs();
|
||||
void openFile();
|
||||
void closeAll();
|
||||
void reloadFile();
|
||||
@ -71,6 +73,7 @@ private:
|
||||
void loadMaps();
|
||||
void loadPOIs();
|
||||
void closeFiles();
|
||||
void plot(QPrinter *printer);
|
||||
|
||||
QAction *createPOIFileAction(int index);
|
||||
void createPOIFilesActions();
|
||||
@ -84,7 +87,7 @@ private:
|
||||
|
||||
bool openPOIFile(const QString &fileName);
|
||||
bool loadFile(const QString &fileName);
|
||||
void saveFile(const QString &fileName);
|
||||
void exportFile(const QString &fileName);
|
||||
void updateStatusBarInfo();
|
||||
void updateWindowTitle();
|
||||
void updateNavigationActions();
|
||||
@ -118,8 +121,9 @@ private:
|
||||
QAction *_dataSourcesAction;
|
||||
QAction *_aboutAction;
|
||||
QAction *_aboutQtAction;
|
||||
QAction *_saveFileAction;
|
||||
QAction *_saveAsAction;
|
||||
QAction *_printFileAction;
|
||||
QAction *_exportFileAction;
|
||||
QAction *_exportAsAction;
|
||||
QAction *_openFileAction;
|
||||
QAction *_closeFileAction;
|
||||
QAction *_reloadFileAction;
|
||||
@ -159,7 +163,7 @@ private:
|
||||
|
||||
FileBrowser *_browser;
|
||||
QList<QString> _files;
|
||||
QString _saveFileName;
|
||||
QString _exportFileName;
|
||||
Map *_currentMap;
|
||||
|
||||
qreal _distance;
|
||||
|
@ -3,8 +3,8 @@
|
||||
|
||||
#define APP_ICON ":/icons/gpxsee.png"
|
||||
#define OPEN_FILE_ICON ":/icons/document-open.png"
|
||||
#define SAVE_FILE_ICON ":/icons/document-save.png"
|
||||
#define SAVE_AS_ICON ":/icons/document-save-as.png"
|
||||
#define EXPORT_FILE_ICON ":/icons/document-export.png"
|
||||
#define PRINT_FILE_ICON ":/icons/document-print.png"
|
||||
#define CLOSE_FILE_ICON ":/icons/dialog-close.png"
|
||||
#define SHOW_POI_ICON ":/icons/flag.png"
|
||||
#define SHOW_MAP_ICON ":/icons/applications-internet.png"
|
||||
|
@ -12,10 +12,9 @@
|
||||
|
||||
#define QUIT_SHORTCUT QKeySequence::Quit
|
||||
#define OPEN_SHORTCUT QKeySequence::Open
|
||||
#define SAVE_SHORTCUT QKeySequence::Save
|
||||
#define SAVE_AS_SHORTCUT QKeySequence::SaveAs
|
||||
#define CLOSE_SHORTCUT QKeySequence::Close
|
||||
#define RELOAD_SHORTCUT QKeySequence::Refresh
|
||||
#define EXPORT_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_E)
|
||||
#define SHOW_POI_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_P)
|
||||
#define SHOW_MAP_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_M)
|
||||
#define NEXT_MAP_SHORTCUT QKeySequence::Forward
|
||||
|
Reference in New Issue
Block a user