Export the Draw mode. Closes #83

This commit is contained in:
Roman Telezhynskyi 2021-06-28 20:05:19 +03:00
parent b2b7dff106
commit c867a9a56e
8 changed files with 130 additions and 5 deletions

View File

@ -3,6 +3,7 @@
- Parsing formulas with not canonical math symbols.
- [smart-pattern/valentina#133] Incorrect seam allowance.
- Fix regression. Fix correct handle export format for exporting details in the Detail mode.
- [smart-pattern/valentina#83] Export the Draw mode.
# Version 0.7.47 May 13, 2021
- [smart-pattern/valentina#118] Incorrect seam allowance.

View File

@ -67,6 +67,8 @@
#include "../vformat/vpatternrecipe.h"
#include "watermarkwindow.h"
#include "../vmisc/backport/qoverload.h"
#include "../vlayout/vlayoutexporter.h"
#include "../vwidgets/vgraphicssimpletextitem.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
#include "../vmisc/backport/qscopeguard.h"
@ -2244,6 +2246,62 @@ void MainWindow::StoreDimensions()
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ExportDraw(const QString &fileName)
{
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wnoexcept")
VLayoutExporter exporter;
QT_WARNING_POP
exporter.SetFileName(fileName);
int verticalScrollBarValue = ui->view->verticalScrollBar()->value();
int horizontalScrollBarValue = ui->view->horizontalScrollBar()->value();
QTransform viewTransform = ui->view->transform();
ui->view->ZoomFitBest(); // Resize all labels
ui->view->repaint();
ui->view->ZoomOriginal(); // Set to original scale
// Enable all items on scene
const QList<QGraphicsItem *> qItems = sceneDraw->items();
for (auto *item : qItems)
{
item->setEnabled(true);
if (item->type() == VGraphicsSimpleTextItem::Type)
{
auto *text = dynamic_cast<VGraphicsSimpleTextItem*>(item);
text->setBrush(text->BaseColor()); // Regular update doesn't work on labels
}
}
ui->view->repaint();
sceneDraw->SetOriginsVisible(false);
const QRectF rect = sceneDraw->VisibleItemsBoundingRect();
sceneDraw->update(rect);
exporter.SetImageRect(rect);
exporter.SetOffset(rect.topLeft()); // Correct positions to fit SVG view rect
exporter.ExportToSVG(sceneDraw);
sceneDraw->SetOriginsVisible(true);
// Restore scale, scrollbars and current active pattern piece
ui->view->setTransform(viewTransform);
VMainGraphicsView::NewSceneRect(ui->view->scene(), ui->view);
emit ScaleChanged(ui->view->transform().m11());
ui->view->verticalScrollBar()->setValue(verticalScrollBarValue);
ui->view->horizontalScrollBar()->setValue(horizontalScrollBarValue);
doc->ChangeActivPP(doc->GetNameActivPP(), Document::FullParse);
}
//---------------------------------------------------------------------------------------------------------------------
#if defined(Q_OS_MAC)
void MainWindow::OpenAt(QAction *where)
@ -2517,6 +2575,7 @@ void MainWindow::InitToolButtons()
connect(ui->toolButtonFlippingByAxis, &QToolButton::clicked, this, &MainWindow::ToolFlippingByAxis);
connect(ui->toolButtonMove, &QToolButton::clicked, this, &MainWindow::ToolMove);
connect(ui->toolButtonMidpoint, &QToolButton::clicked, this, &MainWindow::ToolMidpoint);
connect(ui->toolButtonExportDraw, &QToolButton::clicked, this, &MainWindow::ExportDrawAs);
connect(ui->toolButtonLayoutExportAs, &QToolButton::clicked, this, &MainWindow::ExportLayoutAs);
connect(ui->toolButtonDetailExportAs, &QToolButton::clicked, this, &MainWindow::ExportDetailsAs);
connect(ui->toolButtonEllipticalArc, &QToolButton::clicked, this, &MainWindow::ToolEllipticalArc);
@ -4226,6 +4285,7 @@ QT_WARNING_POP
ui->toolButtonPin->setEnabled(drawTools);
ui->toolButtonInsertNode->setEnabled(drawTools);
ui->toolButtonPlaceLabel->setEnabled(drawTools);
ui->toolButtonExportDraw->setEnabled(drawTools);
ui->actionLast_tool->setEnabled(drawTools);
@ -5480,6 +5540,30 @@ void MainWindow::CreateMeasurements()
}
#endif
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ExportDrawAs()
{
auto Uncheck = qScopeGuard([this] {ui->toolButtonExportDraw->setChecked(false);});
QString filters(tr("Scalable Vector Graphics files") + QLatin1String("(*.svg)"));
QString dir = QDir::homePath() + QLatin1String("/") + FileName() + QLatin1String(".svg");
QString fileName = QFileDialog::getSaveFileName(this, tr("Save draw"), dir, filters, nullptr,
VAbstractApplication::VApp()->NativeFileDialog());
if (fileName.isEmpty())
{
return;
}
QFileInfo f( fileName );
if (f.suffix().isEmpty() || f.suffix() != QLatin1String("svg"))
{
fileName += QLatin1String(".svg");
}
ExportDraw(fileName);
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ExportLayoutAs()
{

View File

@ -130,6 +130,7 @@ private slots:
#if defined(Q_OS_MAC)
void CreateMeasurements();
#endif
void ExportDrawAs();
void ExportLayoutAs();
void ExportDetailsAs();
@ -415,6 +416,8 @@ private:
void SetDimensionBases();
void StoreDimensions();
void ExportDraw(const QString &fileName);
};
#endif // MAINWINDOW_H

View File

@ -1119,9 +1119,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-53</y>
<width>126</width>
<height>192</height>
<height>237</height>
</rect>
</property>
<attribute name="icon">
@ -1317,6 +1317,26 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QToolButton" name="toolButtonExportDraw">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../libs/vmisc/share/resources/icon.qrc">
<normaloff>:/icon/32x32/export_to_picture_document.png</normaloff>:/icon/32x32/export_to_picture_document.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="detailPage">

View File

@ -291,7 +291,7 @@ QStringList VAbstractPattern::ListMeasurements() const
void VAbstractPattern::ChangeActivPP(const QString &name, const Document &parse)
{
Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name pattern piece is empty");
if (CheckExistNamePP(name) && this->nameActivPP != name)
if (CheckExistNamePP(name))
{
this->nameActivPP = name;
if (parse == Document::FullParse)

View File

@ -139,6 +139,7 @@ void VLayoutExporter::ExportToSVG(QGraphicsScene *scene) const
QPainter painter;
painter.begin(&generator);
painter.translate(-m_offset.x(), -m_offset.y());
painter.translate(m_margins.left(), m_margins.top());
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(m_pen);
@ -374,6 +375,18 @@ auto VLayoutExporter::SupportPDFConversion() -> bool
return res;
}
//---------------------------------------------------------------------------------------------------------------------
QPointF VLayoutExporter::offset() const
{
return m_offset;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::SetOffset(QPointF newOffset)
{
m_offset = newOffset;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief PdfToPs use external tool "pdftops" for converting pdf too eps or ps format.

View File

@ -90,6 +90,9 @@ public:
static auto SupportPDFConversion() -> bool;
auto offset() const -> QPointF;
void SetOffset(QPointF newOffset);
private:
QString m_fileName{};
QMarginsF m_margins{};
@ -102,6 +105,7 @@ private:
bool m_ignorePrinterMargins{false};
bool m_binaryDxfFormat{false};
int m_dxfVersion{0};
QPointF m_offset{};
static void PdfToPs(const QStringList &params);
};

View File

@ -221,9 +221,9 @@ void VMainGraphicsScene::InitOrigins()
//---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsScene::SetOriginsVisible(bool visible)
{
for (auto item : qAsConst(origins))
for (auto *item : qAsConst(origins))
{
if (item)
if (item != nullptr)
{
item->setVisible(visible);
}