From 3626f72fbdd04667a10d728cc3d9c4fca17d7853 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 29 Oct 2018 21:53:52 +0100 Subject: [PATCH] Implemented print dialog, no printing yet --- source/CMakeLists.txt | 4 +++- source/images/document-print.png | Bin 0 -> 818 bytes source/mainwindow.cpp | 32 +++++++++++++++++++------------ source/mainwindow.h | 7 ++++--- source/mainwindow.qrc | 1 + source/mainwindow.ui | 19 ++++++++++++++++++ 6 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 source/images/document-print.png diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index bdc6f6f..2bb2e79 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6) project(ESGRAF48 LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) +find_package(Qt5PrintSupport REQUIRED) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) @@ -45,9 +46,10 @@ target_link_libraries(${PROJECT_NAME} Genus AkkusativDativ V2Svk - LateSkills + LateSkills ResultWidget Qt5::Widgets + Qt5::PrintSupport ) add_subdirectory(CheckableItem) diff --git a/source/images/document-print.png b/source/images/document-print.png new file mode 100644 index 0000000000000000000000000000000000000000..05d22d7a876e6b58ebae2eba22b7010b2d0c7a68 GIT binary patch literal 818 zcmV-21I_%2P)fLnND1e4wX{UGgaCKd&`$L)b_+m2jCOTf%{ms|uB zftbO>c`-2~*xp{Wd_@HW3$(S}I^{aI0%noT%NAf}BofJta|SV`V`fn19SjC55fBLY z{SK~kD7;Z%l>V&%*@QL76^nwp|hUqn)$waeYI25li1kUK+4c_ zC81ndoUpgQkN*DqwWDLB^Py1aT09=#2LMt^Argsbdg^Ggqoecs?%sE8cXzks5}Zce znL3>F)|; #include #include +#include +#include #include MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) - , ui(new Ui::MainWindow) + : QMainWindow(parent) + , ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newFile); connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::openFile); - connect(ui->actionSave, &QAction::triggered, this, - qOverload<>(&MainWindow::saveFile)); - connect( - ui->actionSave_as, &QAction::triggered, this, &MainWindow::saveFileAs); + connect(ui->actionSave, &QAction::triggered, this, qOverload<>(&MainWindow::saveFile)); + connect(ui->actionSave_as, &QAction::triggered, this, &MainWindow::saveFileAs); + connect(ui->actionPrint, &QAction::triggered, this, &MainWindow::print); newFile(); } @@ -50,8 +51,7 @@ void MainWindow::newFile() ui->resultWidget->setModel(&m_dataModel->m_results); - connect(&*m_dataModel, &DataModel::modelChanged, this, - &MainWindow::dataModelChanged); + connect(&*m_dataModel, &DataModel::modelChanged, this, &MainWindow::dataModelChanged); setWindowModified(false); setWindowTitle("untitled[*]"); @@ -61,8 +61,8 @@ void MainWindow::newFile() void MainWindow::openFile() { - QString filename = QFileDialog::getOpenFileName( - this, "Open file", "", "ESGRAF 4-8 (*.esgraf48)"); + QString filename = + QFileDialog::getOpenFileName(this, "Open file", "", "ESGRAF 4-8 (*.esgraf48)"); if (filename.isEmpty()) { return; @@ -104,8 +104,8 @@ void MainWindow::saveFile() void MainWindow::saveFileAs() { - QString filename = QFileDialog::getSaveFileName( - this, "Save file", "", "ESGRAF 4-8 (*.esgraf48)"); + QString filename = + QFileDialog::getSaveFileName(this, "Save file", "", "ESGRAF 4-8 (*.esgraf48)"); if (filename.isEmpty()) { return; @@ -131,6 +131,14 @@ void MainWindow::closeFile() } } +void MainWindow::print() const +{ + QPrinter printer; + + QPrintDialog dialog(&printer); + dialog.exec(); +} + void MainWindow::dataModelChanged() { m_saveOnClose = true; diff --git a/source/mainwindow.h b/source/mainwindow.h index ab9424f..78fa2bb 100644 --- a/source/mainwindow.h +++ b/source/mainwindow.h @@ -18,7 +18,7 @@ class MainWindow : public QMainWindow private: Ui::MainWindow *ui; std::unique_ptr m_dataModel; - QString m_filename; + QString m_filename; bool m_saveOnClose = false; public: @@ -28,14 +28,15 @@ public: public slots: void newFile(); void openFile(); - void saveFile(); + void saveFile(); void saveFileAs(); void closeFile(); + void print() const; void dataModelChanged(); protected: void closeEvent(QCloseEvent *event) override; private: - void saveFile(const QString &filename); + void saveFile(const QString &filename); }; diff --git a/source/mainwindow.qrc b/source/mainwindow.qrc index b8f23c7..795ca6d 100644 --- a/source/mainwindow.qrc +++ b/source/mainwindow.qrc @@ -1,5 +1,6 @@ + images/document-print.png images/document-new.png images/document-open.png images/document-save-as.png diff --git a/source/mainwindow.ui b/source/mainwindow.ui index e820298..86d0199 100644 --- a/source/mainwindow.ui +++ b/source/mainwindow.ui @@ -132,6 +132,8 @@ + + @@ -149,6 +151,8 @@ + + @@ -209,6 +213,21 @@ Ctrl+S + + + + :/images/document-print.png:/images/document-print.png + + + Print + + + Print + + + Ctrl+P + +