Implemented print dialog, no printing yet

pull/12/head
mandlm 2018-10-29 21:53:52 +01:00
parent 4524cfa76d
commit 3626f72fbd
6 changed files with 47 additions and 16 deletions

View File

@ -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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 818 B

View File

@ -10,20 +10,21 @@
#include <QDataWidgetMapper>
#include <QCloseEvent>
#include <QMessageBox>
#include <QtPrintSupport/QPrinter>
#include <QtPrintSupport/QPrintDialog>
#include <QDebug>
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;

View File

@ -18,7 +18,7 @@ class MainWindow : public QMainWindow
private:
Ui::MainWindow *ui;
std::unique_ptr<DataModel> 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);
};

View File

@ -1,5 +1,6 @@
<RCC>
<qresource>
<file>images/document-print.png</file>
<file>images/document-new.png</file>
<file>images/document-open.png</file>
<file>images/document-save-as.png</file>

View File

@ -132,6 +132,8 @@
<addaction name="actionSave"/>
<addaction name="actionSave_as"/>
<addaction name="separator"/>
<addaction name="actionPrint"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<addaction name="menuFile"/>
@ -149,6 +151,8 @@
<addaction name="actionNew"/>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="separator"/>
<addaction name="actionPrint"/>
</widget>
<action name="actionSave_as">
<property name="icon">
@ -209,6 +213,21 @@
<string>Ctrl+S</string>
</property>
</action>
<action name="actionPrint">
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/images/document-print.png</normaloff>:/images/document-print.png</iconset>
</property>
<property name="text">
<string>Print</string>
</property>
<property name="toolTip">
<string>Print</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>