Action print preview.
--HG-- branch : feature
This commit is contained in:
parent
130063d690
commit
fc54866019
|
@ -51,6 +51,7 @@ int main(int argc, char *argv[])
|
||||||
Q_INIT_RESOURCE(schema);
|
Q_INIT_RESOURCE(schema);
|
||||||
Q_INIT_RESOURCE(theme);
|
Q_INIT_RESOURCE(theme);
|
||||||
Q_INIT_RESOURCE(flags);
|
Q_INIT_RESOURCE(flags);
|
||||||
|
Q_INIT_RESOURCE(icons);
|
||||||
|
|
||||||
QT_REQUIRE_VERSION(argc, argv, "5.0.0");
|
QT_REQUIRE_VERSION(argc, argv, "5.0.0");
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,12 @@
|
||||||
#include "../../libs/vlayout/vlayoutgenerator.h"
|
#include "../../libs/vlayout/vlayoutgenerator.h"
|
||||||
#include "../dialogs/app/dialoglayoutprogress.h"
|
#include "../dialogs/app/dialoglayoutprogress.h"
|
||||||
#include "../dialogs/app/dialogsavelayout.h"
|
#include "../dialogs/app/dialogsavelayout.h"
|
||||||
|
#include "../../libs/vlayout/vposter.h"
|
||||||
|
|
||||||
#include <QtSvg>
|
#include <QtSvg>
|
||||||
#include <QPrinter>
|
#include <QPrinter>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
#include <QPrintPreviewDialog>
|
||||||
#include <QtCore/qmath.h>
|
#include <QtCore/qmath.h>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
@ -78,6 +80,7 @@ TableWindow::TableWindow(QWidget *parent)
|
||||||
connect(ui->actionSave, &QAction::triggered, this, &TableWindow::SaveLayout);
|
connect(ui->actionSave, &QAction::triggered, this, &TableWindow::SaveLayout);
|
||||||
connect(ui->actionLayout, &QAction::triggered, this, &TableWindow::Layout);
|
connect(ui->actionLayout, &QAction::triggered, this, &TableWindow::Layout);
|
||||||
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &TableWindow::ShowPaper);
|
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &TableWindow::ShowPaper);
|
||||||
|
connect(ui->actionPrint_pre_view, &QAction::triggered, this, &TableWindow::PrintPreview);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -238,7 +241,7 @@ void TableWindow::ShowPaper(int index)
|
||||||
if (index < 0 || index > scenes.size())
|
if (index < 0 || index > scenes.size())
|
||||||
{
|
{
|
||||||
ui->view->setScene(tempScene);
|
ui->view->setScene(tempScene);
|
||||||
ui->actionSave->setEnabled(false);
|
EnableActions(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -248,6 +251,76 @@ void TableWindow::ShowPaper(int index)
|
||||||
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
|
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TableWindow::PrintPreview()
|
||||||
|
{
|
||||||
|
QPrinterInfo def = QPrinterInfo::defaultPrinter();
|
||||||
|
|
||||||
|
//if there is no default printer set the print preview won't show
|
||||||
|
if(def.isNull() || def.printerName().isEmpty())
|
||||||
|
{
|
||||||
|
if(QPrinterInfo::availablePrinters().isEmpty())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("Print error"),
|
||||||
|
tr("Cannot proceed because there are no available printers in your system."),
|
||||||
|
QMessageBox::Ok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
def = QPrinterInfo::availablePrinters().first();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QPrinter printer(def, QPrinter::ScreenResolution);
|
||||||
|
printer.setResolution(static_cast<int>(VApplication::PrintDPI));
|
||||||
|
|
||||||
|
QPrintPreviewDialog preview(&printer);
|
||||||
|
connect(&preview, &QPrintPreviewDialog::paintRequested, this, &TableWindow::Print);
|
||||||
|
preview.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TableWindow::Print(QPrinter *printer)
|
||||||
|
{
|
||||||
|
if (printer == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QVector<QImage> images = AllSheets();
|
||||||
|
|
||||||
|
VPoster posterazor(printer);
|
||||||
|
QVector<QImage> poster;
|
||||||
|
for (int i=0; i < images.size(); i++)
|
||||||
|
{
|
||||||
|
poster += posterazor.Generate(images.at(i), i+1, images.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
QPainter painter;
|
||||||
|
if (not painter.begin(printer))
|
||||||
|
{ // failed to open file
|
||||||
|
qWarning("failed to open file, is it writable?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i < poster.size(); i++)
|
||||||
|
{
|
||||||
|
painter.drawImage(QPointF(), poster.at(i));
|
||||||
|
|
||||||
|
if (i+1 < poster.size())
|
||||||
|
{
|
||||||
|
if (not printer->newPage())
|
||||||
|
{
|
||||||
|
qWarning("failed in flushing page to disk, disk full?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.end();
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TableWindow::Layout()
|
void TableWindow::Layout()
|
||||||
{
|
{
|
||||||
|
@ -281,8 +354,8 @@ void TableWindow::Layout()
|
||||||
{
|
{
|
||||||
case LayoutErrors::NoError:
|
case LayoutErrors::NoError:
|
||||||
ClearLayout();
|
ClearLayout();
|
||||||
papers = lGenerator.GetPapersItems();
|
papers = lGenerator.GetPapersItems();// Blank sheets
|
||||||
details = lGenerator.GetAllDetails();
|
details = lGenerator.GetAllDetails();// All details
|
||||||
CreateShadows();
|
CreateShadows();
|
||||||
CreateScenes();
|
CreateScenes();
|
||||||
PrepareSceneList();
|
PrepareSceneList();
|
||||||
|
@ -462,6 +535,49 @@ void TableWindow::ObjFile(const QString &name, int i) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QVector<QImage> TableWindow::AllSheets()
|
||||||
|
{
|
||||||
|
QVector<QImage> images;
|
||||||
|
for (int i=0; i < scenes.size(); ++i)
|
||||||
|
{
|
||||||
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
||||||
|
if (paper)
|
||||||
|
{
|
||||||
|
// Hide shadow and paper border
|
||||||
|
QBrush *brush = new QBrush();
|
||||||
|
brush->setColor( QColor( Qt::white ) );
|
||||||
|
scenes[i]->setBackgroundBrush( *brush );
|
||||||
|
shadows[i]->setVisible(false);
|
||||||
|
paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));// border
|
||||||
|
|
||||||
|
// Render png
|
||||||
|
const QRectF r = paper->rect();
|
||||||
|
// Create the image with the exact size of the shrunk scene
|
||||||
|
QImage image(QSize(static_cast<qint32>(r.width()), static_cast<qint32>(r.height())), QImage::Format_RGB32);
|
||||||
|
image.fill(Qt::white);
|
||||||
|
QPainter painter(&image);
|
||||||
|
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap,
|
||||||
|
Qt::RoundJoin));
|
||||||
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
||||||
|
scenes.at(i)->render(&painter);
|
||||||
|
painter.end();
|
||||||
|
images.append(image);
|
||||||
|
|
||||||
|
// Resore
|
||||||
|
paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
||||||
|
brush->setColor( QColor( Qt::gray ) );
|
||||||
|
brush->setStyle( Qt::SolidPattern );
|
||||||
|
scenes[i]->setBackgroundBrush( *brush );
|
||||||
|
shadows[i]->setVisible(true);
|
||||||
|
delete brush;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TableWindow::ClearLayout()
|
void TableWindow::ClearLayout()
|
||||||
{
|
{
|
||||||
|
@ -470,6 +586,7 @@ void TableWindow::ClearLayout()
|
||||||
shadows.clear();
|
shadows.clear();
|
||||||
papers.clear();
|
papers.clear();
|
||||||
ui->listWidget->clear();
|
ui->listWidget->clear();
|
||||||
|
EnableActions(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -529,7 +646,7 @@ void TableWindow::PrepareSceneList()
|
||||||
if (scenes.isEmpty() == false)
|
if (scenes.isEmpty() == false)
|
||||||
{
|
{
|
||||||
ui->listWidget->setCurrentRow(0);
|
ui->listWidget->setCurrentRow(0);
|
||||||
ui->actionSave->setEnabled(true);
|
EnableActions(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,3 +704,12 @@ QMap<QString, QString> TableWindow::InitFormates() const
|
||||||
}
|
}
|
||||||
return extByMessage;
|
return extByMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TableWindow::EnableActions(bool enable)
|
||||||
|
{
|
||||||
|
ui->actionSave->setEnabled(enable);
|
||||||
|
ui->actionSave_to_p_df->setEnabled(enable);
|
||||||
|
ui->actionPrint_pre_view->setEnabled(enable);
|
||||||
|
ui->action_Print->setEnabled(enable);
|
||||||
|
}
|
||||||
|
|
|
@ -54,12 +54,13 @@ public:
|
||||||
~TableWindow();
|
~TableWindow();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void ModelChosen(QVector<VLayoutDetail> listDetails, const QString &fileName,
|
void ModelChosen(QVector<VLayoutDetail> listDetails, const QString &fileName, const QString &description);
|
||||||
const QString &description);
|
void Layout();
|
||||||
void Layout();
|
void StopTable();
|
||||||
void StopTable();
|
void SaveLayout();
|
||||||
void SaveLayout();
|
void ShowPaper(int index);
|
||||||
void ShowPaper(int index);
|
void PrintPreview();
|
||||||
|
void Print (QPrinter *printer);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/** @brief closed emit if window is closing. */
|
/** @brief closed emit if window is closing. */
|
||||||
|
@ -91,13 +92,15 @@ private:
|
||||||
|
|
||||||
QGraphicsScene* tempScene;
|
QGraphicsScene* tempScene;
|
||||||
|
|
||||||
void SvgFile(const QString &name, int i)const;
|
void SvgFile(const QString &name, int i)const;
|
||||||
void PngFile(const QString &name, int i)const;
|
void PngFile(const QString &name, int i)const;
|
||||||
void PdfFile(const QString &name, int i)const;
|
void PdfFile(const QString &name, int i)const;
|
||||||
void EpsFile(const QString &name, int i)const;
|
void EpsFile(const QString &name, int i)const;
|
||||||
void PsFile(const QString &name, int i)const;
|
void PsFile(const QString &name, int i)const;
|
||||||
void PdfToPs(const QStringList ¶ms)const;
|
void PdfToPs(const QStringList ¶ms)const;
|
||||||
void ObjFile(const QString &name, int i)const;
|
void ObjFile(const QString &name, int i)const;
|
||||||
|
|
||||||
|
QVector<QImage> AllSheets();
|
||||||
|
|
||||||
void ClearLayout();
|
void ClearLayout();
|
||||||
void CreateShadows();
|
void CreateShadows();
|
||||||
|
@ -105,6 +108,8 @@ private:
|
||||||
void PrepareSceneList();
|
void PrepareSceneList();
|
||||||
QIcon ScenePreview(int i) const;
|
QIcon ScenePreview(int i) const;
|
||||||
QMap<QString, QString> InitFormates() const;
|
QMap<QString, QString> InitFormates() const;
|
||||||
|
|
||||||
|
void EnableActions(bool enable);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TABLEWINDOW_H
|
#endif // TABLEWINDOW_H
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QToolBar" name="toolBar">
|
<widget class="QToolBar" name="toolBar">
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>toolBar</string>
|
<string>Main toolbar</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
<size>
|
<size>
|
||||||
|
@ -169,6 +169,20 @@
|
||||||
<addaction name="menuEdit"/>
|
<addaction name="menuEdit"/>
|
||||||
<addaction name="menuLayout"/>
|
<addaction name="menuLayout"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QToolBar" name="toolBar_2">
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Toolbar print</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="toolBarArea">
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<addaction name="actionSave_to_p_df"/>
|
||||||
|
<addaction name="actionPrint_pre_view"/>
|
||||||
|
<addaction name="action_Print"/>
|
||||||
|
</widget>
|
||||||
<action name="actionSave">
|
<action name="actionSave">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
@ -234,6 +248,9 @@
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionPrint_pre_view">
|
<action name="actionPrint_pre_view">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="document-print-preview"/>
|
<iconset theme="document-print-preview"/>
|
||||||
</property>
|
</property>
|
||||||
|
@ -242,6 +259,9 @@
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="action_Print">
|
<action name="action_Print">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="document-print"/>
|
<iconset theme="document-print"/>
|
||||||
</property>
|
</property>
|
||||||
|
@ -250,6 +270,9 @@
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionSave_to_p_df">
|
<action name="actionSave_to_p_df">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Print to p&df</string>
|
<string>Print to p&df</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user