Implemented print dialog, no printing yet

This commit is contained in:
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) project(ESGRAF48 LANGUAGES CXX)
find_package(Qt5Widgets REQUIRED) find_package(Qt5Widgets REQUIRED)
find_package(Qt5PrintSupport REQUIRED)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
@ -48,6 +49,7 @@ target_link_libraries(${PROJECT_NAME}
LateSkills LateSkills
ResultWidget ResultWidget
Qt5::Widgets Qt5::Widgets
Qt5::PrintSupport
) )
add_subdirectory(CheckableItem) add_subdirectory(CheckableItem)

Binary file not shown.

After

Width:  |  Height:  |  Size: 818 B

View File

@ -10,6 +10,8 @@
#include <QDataWidgetMapper> #include <QDataWidgetMapper>
#include <QCloseEvent> #include <QCloseEvent>
#include <QMessageBox> #include <QMessageBox>
#include <QtPrintSupport/QPrinter>
#include <QtPrintSupport/QPrintDialog>
#include <QDebug> #include <QDebug>
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
@ -20,10 +22,9 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newFile); connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newFile);
connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::openFile); connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::openFile);
connect(ui->actionSave, &QAction::triggered, this, connect(ui->actionSave, &QAction::triggered, this, qOverload<>(&MainWindow::saveFile));
qOverload<>(&MainWindow::saveFile)); connect(ui->actionSave_as, &QAction::triggered, this, &MainWindow::saveFileAs);
connect( connect(ui->actionPrint, &QAction::triggered, this, &MainWindow::print);
ui->actionSave_as, &QAction::triggered, this, &MainWindow::saveFileAs);
newFile(); newFile();
} }
@ -50,8 +51,7 @@ void MainWindow::newFile()
ui->resultWidget->setModel(&m_dataModel->m_results); ui->resultWidget->setModel(&m_dataModel->m_results);
connect(&*m_dataModel, &DataModel::modelChanged, this, connect(&*m_dataModel, &DataModel::modelChanged, this, &MainWindow::dataModelChanged);
&MainWindow::dataModelChanged);
setWindowModified(false); setWindowModified(false);
setWindowTitle("untitled[*]"); setWindowTitle("untitled[*]");
@ -61,8 +61,8 @@ void MainWindow::newFile()
void MainWindow::openFile() void MainWindow::openFile()
{ {
QString filename = QFileDialog::getOpenFileName( QString filename =
this, "Open file", "", "ESGRAF 4-8 (*.esgraf48)"); QFileDialog::getOpenFileName(this, "Open file", "", "ESGRAF 4-8 (*.esgraf48)");
if (filename.isEmpty()) if (filename.isEmpty())
{ {
return; return;
@ -104,8 +104,8 @@ void MainWindow::saveFile()
void MainWindow::saveFileAs() void MainWindow::saveFileAs()
{ {
QString filename = QFileDialog::getSaveFileName( QString filename =
this, "Save file", "", "ESGRAF 4-8 (*.esgraf48)"); QFileDialog::getSaveFileName(this, "Save file", "", "ESGRAF 4-8 (*.esgraf48)");
if (filename.isEmpty()) if (filename.isEmpty())
{ {
return; return;
@ -131,6 +131,14 @@ void MainWindow::closeFile()
} }
} }
void MainWindow::print() const
{
QPrinter printer;
QPrintDialog dialog(&printer);
dialog.exec();
}
void MainWindow::dataModelChanged() void MainWindow::dataModelChanged()
{ {
m_saveOnClose = true; m_saveOnClose = true;

View File

@ -31,6 +31,7 @@ public slots:
void saveFile(); void saveFile();
void saveFileAs(); void saveFileAs();
void closeFile(); void closeFile();
void print() const;
void dataModelChanged(); void dataModelChanged();
protected: protected:

View File

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

View File

@ -132,6 +132,8 @@
<addaction name="actionSave"/> <addaction name="actionSave"/>
<addaction name="actionSave_as"/> <addaction name="actionSave_as"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionPrint"/>
<addaction name="separator"/>
<addaction name="actionQuit"/> <addaction name="actionQuit"/>
</widget> </widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
@ -149,6 +151,8 @@
<addaction name="actionNew"/> <addaction name="actionNew"/>
<addaction name="actionOpen"/> <addaction name="actionOpen"/>
<addaction name="actionSave"/> <addaction name="actionSave"/>
<addaction name="separator"/>
<addaction name="actionPrint"/>
</widget> </widget>
<action name="actionSave_as"> <action name="actionSave_as">
<property name="icon"> <property name="icon">
@ -209,6 +213,21 @@
<string>Ctrl+S</string> <string>Ctrl+S</string>
</property> </property>
</action> </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> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>