Hooked up print button and associated cleanup.
This commit is contained in:
@@ -134,13 +134,25 @@ namespace glabels
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Print page using persistent page number
|
||||||
|
///
|
||||||
void PageRenderer::printPage( QPainter* painter ) const
|
void PageRenderer::printPage( QPainter* painter ) const
|
||||||
|
{
|
||||||
|
printPage( painter, mIPage );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Print page
|
||||||
|
///
|
||||||
|
void PageRenderer::printPage( QPainter* painter, int iPage ) const
|
||||||
{
|
{
|
||||||
if ( mModel )
|
if ( mModel )
|
||||||
{
|
{
|
||||||
/// @TODO merge case
|
/// @TODO merge case
|
||||||
|
|
||||||
printSimplePage( painter, mIPage );
|
printSimplePage( painter, iPage );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ namespace glabels
|
|||||||
int nPages() const;
|
int nPages() const;
|
||||||
QRectF pageRect() const;
|
QRectF pageRect() const;
|
||||||
void printPage( QPainter* painter ) const;
|
void printPage( QPainter* painter ) const;
|
||||||
|
void printPage( QPainter* painter, int iPage ) const;
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
|||||||
+44
-4
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "LabelModel.h"
|
#include "LabelModel.h"
|
||||||
|
|
||||||
|
#include <QPrintDialog>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
|
|
||||||
@@ -35,8 +36,18 @@ namespace glabels
|
|||||||
: QWidget(parent), mModel(0), mBlocked(false)
|
: QWidget(parent), mModel(0), mBlocked(false)
|
||||||
{
|
{
|
||||||
setupUi( this );
|
setupUi( this );
|
||||||
|
|
||||||
preview->setRenderer( &mRenderer );
|
preview->setRenderer( &mRenderer );
|
||||||
|
|
||||||
|
mPrinter = new QPrinter( QPrinter::HighResolution );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Destructor
|
||||||
|
///
|
||||||
|
PrintView::~PrintView()
|
||||||
|
{
|
||||||
|
delete mPrinter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -45,8 +56,6 @@ namespace glabels
|
|||||||
///
|
///
|
||||||
void PrintView::setModel( LabelModel* model )
|
void PrintView::setModel( LabelModel* model )
|
||||||
{
|
{
|
||||||
int nLabelsPerPage = model->frame()->nLabels();
|
|
||||||
|
|
||||||
mModel = model;
|
mModel = model;
|
||||||
|
|
||||||
// TODO set visibility based on merge selection
|
// TODO set visibility based on merge selection
|
||||||
@@ -129,7 +138,38 @@ namespace glabels
|
|||||||
///
|
///
|
||||||
void PrintView::onPrintButtonClicked()
|
void PrintView::onPrintButtonClicked()
|
||||||
{
|
{
|
||||||
qDebug() << "Print!";
|
QSizeF pageSize( mModel->tmplate()->pageWidth(), mModel->tmplate()->pageHeight() );
|
||||||
|
mPrinter->setPaperSize( pageSize, QPrinter::Point );
|
||||||
|
mPrinter->setFullPage( true );
|
||||||
|
mPrinter->setPageMargins( 0, 0, 0, 0, QPrinter::Point );
|
||||||
|
|
||||||
|
QPrintDialog printDialog( mPrinter, this );
|
||||||
|
|
||||||
|
printDialog.setOption( QAbstractPrintDialog::PrintToFile, true );
|
||||||
|
printDialog.setOption( QAbstractPrintDialog::PrintSelection, false );
|
||||||
|
printDialog.setOption( QAbstractPrintDialog::PrintPageRange, false );
|
||||||
|
printDialog.setOption( QAbstractPrintDialog::PrintShowPageSize, true );
|
||||||
|
printDialog.setOption( QAbstractPrintDialog::PrintCollateCopies, false );
|
||||||
|
printDialog.setOption( QAbstractPrintDialog::PrintCurrentPage, false );
|
||||||
|
|
||||||
|
if ( printDialog.exec() == QDialog::Accepted )
|
||||||
|
{
|
||||||
|
QPainter painter( mPrinter );
|
||||||
|
|
||||||
|
QSizeF sizePx = mPrinter->paperSize( QPrinter::DevicePixel );
|
||||||
|
QSizeF sizePts = mPrinter->paperSize( QPrinter::Point );
|
||||||
|
painter.scale( sizePx.width()/sizePts.width(), sizePx.height()/sizePts.height() );
|
||||||
|
|
||||||
|
for ( int iPage = 0; iPage < mRenderer.nPages(); iPage++ )
|
||||||
|
{
|
||||||
|
if ( iPage )
|
||||||
|
{
|
||||||
|
mPrinter->newPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
mRenderer.printPage( &painter, iPage );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
#include "ui_PrintView.h"
|
#include "ui_PrintView.h"
|
||||||
#include "PageRenderer.h"
|
#include "PageRenderer.h"
|
||||||
|
|
||||||
|
#include <QPrinter>
|
||||||
|
|
||||||
|
|
||||||
namespace glabels
|
namespace glabels
|
||||||
{
|
{
|
||||||
@@ -43,6 +45,7 @@ namespace glabels
|
|||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
public:
|
public:
|
||||||
PrintView( QWidget *parent = 0 );
|
PrintView( QWidget *parent = 0 );
|
||||||
|
~PrintView();
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
@@ -66,6 +69,7 @@ namespace glabels
|
|||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
private:
|
private:
|
||||||
LabelModel* mModel;
|
LabelModel* mModel;
|
||||||
|
QPrinter* mPrinter;
|
||||||
PageRenderer mRenderer;
|
PageRenderer mRenderer;
|
||||||
|
|
||||||
bool mBlocked;
|
bool mBlocked;
|
||||||
|
|||||||
+62
-75
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>778</width>
|
<width>833</width>
|
||||||
<height>574</height>
|
<height>633</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="4">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<property name="sizeConstraint">
|
<property name="sizeConstraint">
|
||||||
<enum>QLayout::SetFixedSize</enum>
|
<enum>QLayout::SetFixedSize</enum>
|
||||||
@@ -108,78 +108,10 @@
|
|||||||
<property name="margin">
|
<property name="margin">
|
||||||
<number>24</number>
|
<number>24</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
|
||||||
<widget class="QToolButton" name="printButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Print</string>
|
|
||||||
</property>
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../icons.qrc">
|
|
||||||
<normaloff>:/icons/24x24/actions/fallback-file-print.png</normaloff>:/icons/24x24/actions/fallback-file-print.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="toolButtonStyle">
|
|
||||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="groupBox">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>350</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>350</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="title">
|
|
||||||
<string>Printer</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QComboBox" name="printerCombo"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="printerPropertiesButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Properties</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<spacer name="horizontalSpacer_3">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="copiesBox">
|
<widget class="QGroupBox" name="copiesBox">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@@ -291,7 +223,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="mergeBox">
|
<widget class="QGroupBox" name="mergeBox">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@@ -403,7 +335,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox_4">
|
<widget class="QGroupBox" name="groupBox_4">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@@ -465,6 +397,60 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget" native="true">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>350</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>350</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="printButton">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="layoutDirection">
|
||||||
|
<enum>Qt::LeftToRight</enum>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Print</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../icons.qrc">
|
||||||
|
<normaloff>:/icons/24x24/actions/fallback-file-print.png</normaloff>:/icons/24x24/actions/fallback-file-print.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="toolButtonStyle">
|
||||||
|
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
@@ -480,7 +466,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="3">
|
||||||
<widget class="Line" name="line">
|
<widget class="Line" name="line">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@@ -729,5 +715,6 @@
|
|||||||
<slots>
|
<slots>
|
||||||
<slot>onPrintButtonClicked()</slot>
|
<slot>onPrintButtonClicked()</slot>
|
||||||
<slot>onFormChanged()</slot>
|
<slot>onFormChanged()</slot>
|
||||||
|
<slot>onPrinterPropertiesButtonClicked()</slot>
|
||||||
</slots>
|
</slots>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
Reference in New Issue
Block a user