Merge with feature.
--HG-- branch : develop
|
@ -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");
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#define OPTIONS_H
|
#define OPTIONS_H
|
||||||
|
|
||||||
#include "../libs/ifc/ifcdef.h"
|
#include "../libs/ifc/ifcdef.h"
|
||||||
|
#include "../../utils/def.h"
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
# if defined( Q_CC_MSVC ) // MSVC USED
|
# if defined( Q_CC_MSVC ) // MSVC USED
|
||||||
|
|
|
@ -55,5 +55,6 @@
|
||||||
<file>icon/16x16/landscape.png</file>
|
<file>icon/16x16/landscape.png</file>
|
||||||
<file>icon/16x16/portrait.png</file>
|
<file>icon/16x16/portrait.png</file>
|
||||||
<file>icon/16x16/template.png</file>
|
<file>icon/16x16/template.png</file>
|
||||||
|
<file>icon/32x32/pdf.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
BIN
src/app/share/resources/icon/32x32/pdf.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 544 B |
After Width: | Height: | Size: 478 B |
After Width: | Height: | Size: 1.6 KiB |
BIN
src/app/share/resources/icons/win.icon.theme/24x24/actions/document-print.png
Executable file
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 1.9 KiB |
|
@ -61,5 +61,11 @@
|
||||||
<file alias="16x16/actions/help-contents.png">icons/win.icon.theme/16x16/actions/help-contents.png</file>
|
<file alias="16x16/actions/help-contents.png">icons/win.icon.theme/16x16/actions/help-contents.png</file>
|
||||||
<file alias="24x24/actions/help-contents.png">icons/win.icon.theme/24x24/actions/help-contents.png</file>
|
<file alias="24x24/actions/help-contents.png">icons/win.icon.theme/24x24/actions/help-contents.png</file>
|
||||||
<file alias="32x32/actions/help-contents.png">icons/win.icon.theme/32x32/actions/help-contents.png</file>
|
<file alias="32x32/actions/help-contents.png">icons/win.icon.theme/32x32/actions/help-contents.png</file>
|
||||||
|
<file alias="16x16/actions/document-print.png">icons/win.icon.theme/16x16/actions/document-print.png</file>
|
||||||
|
<file alias="24x24/actions/document-print.png">icons/win.icon.theme/24x24/actions/document-print.png</file>
|
||||||
|
<file alias="32x32/actions/document-print.png">icons/win.icon.theme/32x32/actions/document-print.png</file>
|
||||||
|
<file alias="16x16/actions/document-print-preview.png">icons/win.icon.theme/16x16/actions/document-print-preview.png</file>
|
||||||
|
<file alias="24x24/actions/document-print-preview.png">icons/win.icon.theme/24x24/actions/document-print-preview.png</file>
|
||||||
|
<file alias="32x32/actions/document-print-preview.png">icons/win.icon.theme/32x32/actions/document-print-preview.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -36,10 +36,13 @@
|
||||||
#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 <QPrintDialog>
|
||||||
#include <QtCore/qmath.h>
|
#include <QtCore/qmath.h>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
@ -78,6 +81,9 @@ 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);
|
||||||
|
connect(ui->action_Print, &QAction::triggered, this, &TableWindow::LayoutPrint);
|
||||||
|
connect(ui->actionSave_to_p_df, &QAction::triggered, this, &TableWindow::PrintToPdf);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -238,7 +244,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 +254,114 @@ 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));
|
||||||
|
printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
|
||||||
|
printer.setDocName(fileName);
|
||||||
|
|
||||||
|
// display print preview dialog
|
||||||
|
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::LayoutPrint()
|
||||||
|
{
|
||||||
|
// display print dialog and if accepted print
|
||||||
|
QPrinter printer;
|
||||||
|
printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
|
||||||
|
printer.setDocName(fileName);
|
||||||
|
QPrintDialog dialog( &printer, this );
|
||||||
|
if ( dialog.exec() == QDialog::Accepted )
|
||||||
|
{
|
||||||
|
printer.setResolution(static_cast<int>(VApplication::PrintDPI));
|
||||||
|
Print( &printer );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TableWindow::PrintToPdf()
|
||||||
|
{
|
||||||
|
// display print dialog and if accepted print
|
||||||
|
QPrinter printer;
|
||||||
|
printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
|
||||||
|
printer.setDocName(fileName);
|
||||||
|
printer.setOutputFormat(QPrinter::PdfFormat);
|
||||||
|
|
||||||
|
const QString fileName = QFileDialog::getSaveFileName(this, tr("Print to pdf"),
|
||||||
|
QDir::homePath()+"/"+this->fileName+".pdf",
|
||||||
|
tr("PDF file (*.pdf)"));
|
||||||
|
if (fileName.isEmpty())
|
||||||
|
{
|
||||||
|
printer.setOutputFileName(fileName);
|
||||||
|
printer.setResolution(static_cast<int>(VApplication::PrintDPI));
|
||||||
|
Print( &printer );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TableWindow::Layout()
|
void TableWindow::Layout()
|
||||||
{
|
{
|
||||||
|
@ -281,8 +395,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 +576,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 +627,7 @@ void TableWindow::ClearLayout()
|
||||||
shadows.clear();
|
shadows.clear();
|
||||||
papers.clear();
|
papers.clear();
|
||||||
ui->listWidget->clear();
|
ui->listWidget->clear();
|
||||||
|
EnableActions(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -529,7 +687,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 +745,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);
|
||||||
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ namespace Ui
|
||||||
|
|
||||||
class QGraphicsScene;
|
class QGraphicsScene;
|
||||||
class QGraphicsRectItem;
|
class QGraphicsRectItem;
|
||||||
|
class QPrinter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TableWindow class layout window.
|
* @brief TableWindow class layout window.
|
||||||
|
@ -54,12 +55,15 @@ 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);
|
||||||
|
void LayoutPrint();
|
||||||
|
void PrintToPdf();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/** @brief closed emit if window is closing. */
|
/** @brief closed emit if window is closing. */
|
||||||
|
@ -99,12 +103,16 @@ private:
|
||||||
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();
|
||||||
void CreateScenes();
|
void CreateScenes();
|
||||||
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>
|
||||||
|
@ -133,6 +133,56 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menuBar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>1000</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuFile">
|
||||||
|
<property name="title">
|
||||||
|
<string>File</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionSave"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionPrint_pre_view"/>
|
||||||
|
<addaction name="action_Print"/>
|
||||||
|
<addaction name="actionSave_to_p_df"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuEdit">
|
||||||
|
<property name="title">
|
||||||
|
<string>Edit</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionZoomIn"/>
|
||||||
|
<addaction name="actionZoomOut"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuLayout">
|
||||||
|
<property name="title">
|
||||||
|
<string>Layout</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionLayout"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuFile"/>
|
||||||
|
<addaction name="menuEdit"/>
|
||||||
|
<addaction name="menuLayout"/>
|
||||||
|
</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>
|
||||||
|
@ -143,11 +193,14 @@
|
||||||
</iconset>
|
</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save</string>
|
<string>&Save As...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Save layout</string>
|
<string>Save layout</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+S</string>
|
||||||
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionStop">
|
<action name="actionStop">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
|
@ -197,6 +250,43 @@
|
||||||
<string>Layout</string>
|
<string>Layout</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionPrint_pre_view">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="document-print-preview"/>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Print pre&view...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="action_Print">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="document-print"/>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>&Print...</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+P</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionSave_to_p_df">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="share/resources/icon.qrc">
|
||||||
|
<normaloff>:/icon/32x32/pdf.png</normaloff>:/icon/32x32/pdf.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Print to p&df</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include "vexception.h"
|
#include "vexception.h"
|
||||||
#include "../../../utils/logging.h"
|
#include "../../../utils/logging.h"
|
||||||
|
#include "../../../utils/def.h"
|
||||||
|
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#ifndef IFCDEF_H
|
#ifndef IFCDEF_H
|
||||||
#define IFCDEF_H
|
#define IFCDEF_H
|
||||||
|
|
||||||
#include <csignal>
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
|
@ -45,63 +44,6 @@ static const quint32 null_id = 0;
|
||||||
#define NULL_ID null_id//use this value for initialization variables that keeps id values. 0 mean uknown id value.
|
#define NULL_ID null_id//use this value for initialization variables that keeps id values. 0 mean uknown id value.
|
||||||
#define NULL_ID_STR "0"
|
#define NULL_ID_STR "0"
|
||||||
|
|
||||||
/*
|
|
||||||
* This macros SCASSERT (for Stop and Continue Assert) will break into the debugger on the line of the assert and allow
|
|
||||||
* you to continue afterwards should you choose to.
|
|
||||||
* idea: Q_ASSERT no longer pauses debugger - http://qt-project.org/forums/viewthread/13148
|
|
||||||
* Usefull links:
|
|
||||||
* 1. What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__? -
|
|
||||||
* https://stackoverflow.com/questions/4384765/whats-the-difference-between-pretty-function-function-func
|
|
||||||
*
|
|
||||||
* 2. Windows Predefined Macros - http://msdn.microsoft.com/library/b0084kay.aspx
|
|
||||||
*
|
|
||||||
* 3. Windows DebugBreak function - http://msdn.microsoft.com/en-us/library/ms679297%28VS.85%29.aspx
|
|
||||||
*
|
|
||||||
* 4. Continue to debug after failed assertion on Linux? [C/C++] -
|
|
||||||
* https://stackoverflow.com/questions/1721543/continue-to-debug-after-failed-assertion-on-linux-c-c
|
|
||||||
*/
|
|
||||||
#ifndef V_NO_ASSERT
|
|
||||||
#ifdef Q_OS_WIN32
|
|
||||||
#ifdef Q_CC_MSVC
|
|
||||||
#define SCASSERT(cond) \
|
|
||||||
{ \
|
|
||||||
if (!(cond)) \
|
|
||||||
{ \
|
|
||||||
qDebug("ASSERT: %s in %s (%s:%u)", \
|
|
||||||
#cond, __FUNCSIG__, __FILE__, __LINE__); \
|
|
||||||
DebugBreak(); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
|
|
||||||
#else // GCC (Windows)
|
|
||||||
|
|
||||||
#define SCASSERT(cond) \
|
|
||||||
{ \
|
|
||||||
if (!(cond)) \
|
|
||||||
{ \
|
|
||||||
qDebug("ASSERT: %s in %s (%s:%u)", \
|
|
||||||
#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\
|
|
||||||
DebugBreak(); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
|
|
||||||
#endif /*Q_CC_MSVC*/
|
|
||||||
#else // UNIX
|
|
||||||
#define SCASSERT(cond) \
|
|
||||||
{ \
|
|
||||||
if (!(cond)) \
|
|
||||||
{ \
|
|
||||||
qDebug("ASSERT: %s in %s (%s:%u)", \
|
|
||||||
#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\
|
|
||||||
std::raise(SIGTRAP); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
|
|
||||||
#endif /* Q_OS_WIN32 */
|
|
||||||
#else // define but disable this function if debugging is not set
|
|
||||||
#define SCASSERT(cond) qt_noop();
|
|
||||||
#endif /* V_NO_ASSERT */
|
|
||||||
|
|
||||||
// Detect whether the compiler supports C++11 noexcept exception specifications.
|
// Detect whether the compiler supports C++11 noexcept exception specifications.
|
||||||
# if defined(__clang__)
|
# if defined(__clang__)
|
||||||
# if __has_feature(cxx_noexcept)
|
# if __has_feature(cxx_noexcept)
|
||||||
|
|
6
src/libs/vlayout/share/icons.qrc
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>scissors_horizontal.png</file>
|
||||||
|
<file>scissors_vertical.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
BIN
src/libs/vlayout/share/scissors_horizontal.png
Normal file
After Width: | Height: | Size: 696 B |
BIN
src/libs/vlayout/share/scissors_vertical.png
Normal file
After Width: | Height: | Size: 726 B |
|
@ -15,7 +15,8 @@ HEADERS += \
|
||||||
$$PWD/vcontour.h \
|
$$PWD/vcontour.h \
|
||||||
$$PWD/vcontour_p.h \
|
$$PWD/vcontour_p.h \
|
||||||
$$PWD/vbestsquare.h \
|
$$PWD/vbestsquare.h \
|
||||||
$$PWD/vposition.h
|
$$PWD/vposition.h \
|
||||||
|
vposter.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/stable.cpp \
|
$$PWD/stable.cpp \
|
||||||
|
@ -26,4 +27,5 @@ SOURCES += \
|
||||||
$$PWD/vbank.cpp \
|
$$PWD/vbank.cpp \
|
||||||
$$PWD/vcontour.cpp \
|
$$PWD/vcontour.cpp \
|
||||||
$$PWD/vbestsquare.cpp \
|
$$PWD/vbestsquare.cpp \
|
||||||
$$PWD/vposition.cpp
|
$$PWD/vposition.cpp \
|
||||||
|
vposter.cpp
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
# File with common stuff for whole project
|
# File with common stuff for whole project
|
||||||
include(../../../Valentina.pri)
|
include(../../../Valentina.pri)
|
||||||
|
|
||||||
QT += core gui widgets
|
QT += core gui widgets printsupport
|
||||||
|
|
||||||
# Name of library
|
# Name of library
|
||||||
TARGET = vlayout
|
TARGET = vlayout
|
||||||
|
@ -93,3 +93,6 @@ CONFIG(debug, debug|release){
|
||||||
QMAKE_LFLAGS_RELEASE =
|
QMAKE_LFLAGS_RELEASE =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RESOURCES += \
|
||||||
|
share/icons.qrc
|
||||||
|
|
239
src/libs/vlayout/vposter.cpp
Normal file
|
@ -0,0 +1,239 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vposter.cpp
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 11 4, 2015
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentine project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2015 Valentina project
|
||||||
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#include "vposter.h"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPrinter>
|
||||||
|
#include <QtMath>
|
||||||
|
|
||||||
|
#include "../../utils/def.h"
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VPoster::VPoster(const QPrinter *printer)
|
||||||
|
:printer(printer), allowence(38)//1 cm
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QVector<QImage> VPoster::Generate(const QImage &image, int page, int pages) const
|
||||||
|
{
|
||||||
|
QVector<QImage> poster;
|
||||||
|
|
||||||
|
if (printer == nullptr)
|
||||||
|
{
|
||||||
|
return poster;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int rows = CountRows(image.rect().height());
|
||||||
|
const int colomns = CountColomns(image.rect().width());
|
||||||
|
|
||||||
|
for (int i=0; i < rows; i++)
|
||||||
|
{
|
||||||
|
for (int j=0; j< colomns; j++)
|
||||||
|
{
|
||||||
|
QImage img = Cut(i, j, image);
|
||||||
|
img = Borders(rows, colomns, i, j, img, page, pages);
|
||||||
|
poster.append(img);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return poster;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
int VPoster::CountRows(int height) const
|
||||||
|
{
|
||||||
|
const qreal imgLength = height;
|
||||||
|
const qreal pageLength = PageRect().height();
|
||||||
|
|
||||||
|
// Example
|
||||||
|
// ― ―
|
||||||
|
// * *
|
||||||
|
// * *
|
||||||
|
// * *
|
||||||
|
// * * ―
|
||||||
|
// ― ― *
|
||||||
|
// * *
|
||||||
|
// * *
|
||||||
|
// * * ―
|
||||||
|
// * ― *
|
||||||
|
// — *
|
||||||
|
// * *
|
||||||
|
// * * ―
|
||||||
|
// * ― *
|
||||||
|
// * *
|
||||||
|
// — *
|
||||||
|
// * * ―
|
||||||
|
// * ― * <-(2)
|
||||||
|
// * + *
|
||||||
|
// * + *
|
||||||
|
// — + * ― <-(4)
|
||||||
|
// ^ ^ ― *
|
||||||
|
//(3) (1) *
|
||||||
|
// *
|
||||||
|
// *
|
||||||
|
// ―
|
||||||
|
|
||||||
|
const int pCount = qCeil(imgLength/pageLength);// Pages count without allowence (or allowence = 0) (3)
|
||||||
|
|
||||||
|
// Calculate how many pages will be after using allowence.
|
||||||
|
// We know start pages count. This number not enought because
|
||||||
|
// each n-1 pages add (n-1)*allowence length to page (1).
|
||||||
|
const qreal addionalLength = (pCount-1)*allowence;
|
||||||
|
|
||||||
|
// Calculate additional length form pages that will cover this length (2).
|
||||||
|
// In the end add page length (3).
|
||||||
|
// Bottom page have mandatory border (4)
|
||||||
|
return qCeil((addionalLength +
|
||||||
|
qCeil(addionalLength/pageLength)*allowence + allowence + imgLength)/pageLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
int VPoster::CountColomns(int width) const
|
||||||
|
{
|
||||||
|
const qreal imgLength = width;
|
||||||
|
const qreal pageLength = PageRect().width();
|
||||||
|
|
||||||
|
// Example
|
||||||
|
// |----|----|----|----| <- (3)
|
||||||
|
// |----|+++++++++++++++
|
||||||
|
// |----|+++++++++++
|
||||||
|
// |----|+++++++
|
||||||
|
// |----|+++ <- (1)
|
||||||
|
// |----|
|
||||||
|
// ^
|
||||||
|
// (2)
|
||||||
|
const int pCount = qCeil(imgLength/pageLength);// Pages count without allowence (or allowence = 0) (3)
|
||||||
|
|
||||||
|
// Calculate how many pages will be after using allowence.
|
||||||
|
// We know start pages count. This number not enought because
|
||||||
|
// each n-1 pages add (n-1)*allowence length to page (1).
|
||||||
|
const qreal addionalLength = (pCount-1)*allowence;
|
||||||
|
|
||||||
|
// Calculate additional length form pages that will cover this length (2).
|
||||||
|
// In the end add page length (3).
|
||||||
|
return qCeil((addionalLength + qCeil(addionalLength/pageLength)*allowence + imgLength)/pageLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QImage VPoster::Cut(int i, int j, const QImage &image) const
|
||||||
|
{
|
||||||
|
const int x = j*PageRect().width() - j*allowence;
|
||||||
|
const int y = i*PageRect().height() - i*allowence;
|
||||||
|
|
||||||
|
SCASSERT(x <= image.rect().width());
|
||||||
|
SCASSERT(y <= image.rect().height());
|
||||||
|
|
||||||
|
QRect copyRect(x, y, PageRect().width(), PageRect().height());
|
||||||
|
|
||||||
|
if (not image.rect().contains(copyRect))
|
||||||
|
{
|
||||||
|
QImage fullPage(copyRect.size(), image.format());
|
||||||
|
fullPage.fill(Qt::white);
|
||||||
|
|
||||||
|
copyRect = image.rect().intersected(copyRect);
|
||||||
|
|
||||||
|
QPainter painter(&fullPage);
|
||||||
|
painter.drawImage(QPointF(), image.copy( copyRect));
|
||||||
|
painter.end();
|
||||||
|
|
||||||
|
return fullPage;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return image.copy(copyRect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QImage VPoster::Borders(int rows, int colomns, int i, int j, QImage &image, int page, int pages) const
|
||||||
|
{
|
||||||
|
QPainter painter(&image);
|
||||||
|
|
||||||
|
QPen pen = QPen(Qt::NoBrush, 1, Qt::DashLine);
|
||||||
|
pen.setColor(Qt::black);
|
||||||
|
painter.setPen(pen);
|
||||||
|
|
||||||
|
if (j != 0)
|
||||||
|
{// Left border
|
||||||
|
painter.drawLine(QLine(0, 0, 0, image.rect().height()));
|
||||||
|
painter.drawImage(QPoint(0, image.rect().height()-allowence), QImage("://scissors_vertical.png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j != colomns-1)
|
||||||
|
{// Right border
|
||||||
|
painter.drawLine(QLine(image.rect().width()-allowence, 0,
|
||||||
|
image.rect().width()-allowence, image.rect().height()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i != 0)
|
||||||
|
{// Top border
|
||||||
|
painter.drawLine(QLine(0, 0, image.rect().width(), 0));
|
||||||
|
painter.drawImage(QPoint(image.rect().width()-allowence, 0), QImage("://scissors_horizontal.png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bottom border (mandatory)
|
||||||
|
painter.drawLine(QLine(0, image.rect().height()-allowence,
|
||||||
|
image.rect().width(), image.rect().height()-allowence));
|
||||||
|
if (i == rows-1)
|
||||||
|
{
|
||||||
|
painter.drawImage(QPoint(image.rect().width()-allowence, image.rect().height()-allowence),
|
||||||
|
QImage("://scissors_horizontal.png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Labels
|
||||||
|
const int layoutX = 15;
|
||||||
|
const int layoutY = 5;
|
||||||
|
QRect labels(layoutX, image.rect().height()-allowence+layoutY,
|
||||||
|
image.rect().width()-(allowence+layoutX), allowence-layoutY);
|
||||||
|
painter.drawText(labels, Qt::AlignLeft, tr("Grid ( %1 , %2 )").arg(i).arg(j));
|
||||||
|
painter.drawText(labels, Qt::AlignHCenter, tr("Page %1 of %2").arg(i*(colomns)+j+1).arg(rows*colomns));
|
||||||
|
if (pages > 1)
|
||||||
|
{
|
||||||
|
painter.drawText(labels, Qt::AlignRight, tr("Sheet %1 of %2").arg(page).arg(pages));
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.end();
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QRect VPoster::PageRect() const
|
||||||
|
{
|
||||||
|
|
||||||
|
const QRectF rect = printer->pageRect(QPrinter::Millimeter);
|
||||||
|
QRect pageRect(qFloor(ToPixel(rect.x())), qFloor(ToPixel(rect.y())), qFloor(ToPixel(rect.width())),
|
||||||
|
qFloor(ToPixel(rect.height())));
|
||||||
|
return pageRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qreal VPoster::ToPixel(qreal val) const
|
||||||
|
{
|
||||||
|
return val / 25.4 * printer->resolution(); // Mm to pixels with current dpi.
|
||||||
|
}
|
60
src/libs/vlayout/vposter.h
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vposter.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 11 4, 2015
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentine project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2015 Valentina project
|
||||||
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#ifndef VPOSTER_H
|
||||||
|
#define VPOSTER_H
|
||||||
|
|
||||||
|
#include <QImage>
|
||||||
|
#include <QRect>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
class QPrinter;
|
||||||
|
|
||||||
|
class VPoster
|
||||||
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(VPoster)
|
||||||
|
public:
|
||||||
|
VPoster(const QPrinter *printer);
|
||||||
|
|
||||||
|
QVector<QImage> Generate(const QImage &image, int page, int pages = 1) const;
|
||||||
|
private:
|
||||||
|
const QPrinter *printer;
|
||||||
|
unsigned int allowence;
|
||||||
|
|
||||||
|
int CountRows(int height) const;
|
||||||
|
int CountColomns(int width) const;
|
||||||
|
|
||||||
|
QImage Cut(int i, int j, const QImage &image) const;
|
||||||
|
QImage Borders(int rows, int colomns, int i, int j, QImage &image, int page, int pages) const;
|
||||||
|
|
||||||
|
QRect PageRect() const;
|
||||||
|
|
||||||
|
qreal ToPixel(qreal val) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VPOSTER_H
|
92
src/utils/def.h
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file def.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 11 4, 2015
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentine project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2015 Valentina project
|
||||||
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#ifndef DEF_H
|
||||||
|
#define DEF_H
|
||||||
|
|
||||||
|
#include <csignal>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This macros SCASSERT (for Stop and Continue Assert) will break into the debugger on the line of the assert and allow
|
||||||
|
* you to continue afterwards should you choose to.
|
||||||
|
* idea: Q_ASSERT no longer pauses debugger - http://qt-project.org/forums/viewthread/13148
|
||||||
|
* Usefull links:
|
||||||
|
* 1. What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__? -
|
||||||
|
* https://stackoverflow.com/questions/4384765/whats-the-difference-between-pretty-function-function-func
|
||||||
|
*
|
||||||
|
* 2. Windows Predefined Macros - http://msdn.microsoft.com/library/b0084kay.aspx
|
||||||
|
*
|
||||||
|
* 3. Windows DebugBreak function - http://msdn.microsoft.com/en-us/library/ms679297%28VS.85%29.aspx
|
||||||
|
*
|
||||||
|
* 4. Continue to debug after failed assertion on Linux? [C/C++] -
|
||||||
|
* https://stackoverflow.com/questions/1721543/continue-to-debug-after-failed-assertion-on-linux-c-c
|
||||||
|
*/
|
||||||
|
#ifndef V_NO_ASSERT
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
#ifdef Q_CC_MSVC
|
||||||
|
#define SCASSERT(cond) \
|
||||||
|
{ \
|
||||||
|
if (!(cond)) \
|
||||||
|
{ \
|
||||||
|
qDebug("ASSERT: %s in %s (%s:%u)", \
|
||||||
|
#cond, __FUNCSIG__, __FILE__, __LINE__); \
|
||||||
|
DebugBreak(); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
|
||||||
|
#else // GCC (Windows)
|
||||||
|
|
||||||
|
#define SCASSERT(cond) \
|
||||||
|
{ \
|
||||||
|
if (!(cond)) \
|
||||||
|
{ \
|
||||||
|
qDebug("ASSERT: %s in %s (%s:%u)", \
|
||||||
|
#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\
|
||||||
|
DebugBreak(); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
|
||||||
|
#endif /*Q_CC_MSVC*/
|
||||||
|
#else // UNIX
|
||||||
|
#define SCASSERT(cond) \
|
||||||
|
{ \
|
||||||
|
if (!(cond)) \
|
||||||
|
{ \
|
||||||
|
qDebug("ASSERT: %s in %s (%s:%u)", \
|
||||||
|
#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\
|
||||||
|
std::raise(SIGTRAP); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
|
||||||
|
#endif /* Q_OS_WIN32 */
|
||||||
|
#else // define but disable this function if debugging is not set
|
||||||
|
#define SCASSERT(cond) qt_noop();
|
||||||
|
#endif /* V_NO_ASSERT */
|
||||||
|
|
||||||
|
#endif // DEF_H
|
|
@ -1,3 +1,4 @@
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/logging.h \
|
$$PWD/logging.h \
|
||||||
$$PWD/vmath.h
|
$$PWD/vmath.h \
|
||||||
|
$$PWD/def.h
|
||||||
|
|