Button export with test svg export
This commit is contained in:
parent
491d5848b4
commit
f6e5f67159
|
@ -7,7 +7,7 @@
|
|||
# File with common stuff for whole project
|
||||
include(../../../common.pri)
|
||||
|
||||
QT += core gui widgets network xml xmlpatterns printsupport concurrent
|
||||
QT += core gui widgets network xml svg xmlpatterns printsupport concurrent
|
||||
|
||||
# Name of binary file
|
||||
TARGET = puzzle
|
||||
|
|
|
@ -55,12 +55,18 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
|
|||
painter->setPen(pen);
|
||||
painter->setBrush(noBrush);
|
||||
|
||||
painter->drawRect(GetMarginsRect());
|
||||
if(m_showMargin)
|
||||
{
|
||||
painter->drawRect(GetMarginsRect());
|
||||
}
|
||||
|
||||
pen.setColor(Qt::black);
|
||||
if(m_showBorder)
|
||||
{
|
||||
pen.setColor(Qt::black);
|
||||
|
||||
painter->setPen(pen);
|
||||
painter->drawRect(GetSheetRect());
|
||||
painter->setPen(pen);
|
||||
painter->drawRect(GetSheetRect());
|
||||
}
|
||||
|
||||
m_boundingRect = GetSheetRect();
|
||||
}
|
||||
|
@ -96,6 +102,18 @@ QRectF VPGraphicsSheet::GetMarginsRect() const
|
|||
return rect;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPGraphicsSheet::SetShowMargin(bool value)
|
||||
{
|
||||
m_showMargin = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPGraphicsSheet::SetShowBorder(bool value)
|
||||
{
|
||||
m_showBorder = value;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QRectF VPGraphicsSheet::boundingRect() const
|
||||
|
|
|
@ -47,12 +47,28 @@ public:
|
|||
QRectF GetSheetRect() const;
|
||||
QRectF GetMarginsRect() const;
|
||||
|
||||
/**
|
||||
* @brief ShowMargin Sets Wether we see the margin
|
||||
* @param value true to show the margin
|
||||
*/
|
||||
void SetShowMargin(bool value);
|
||||
|
||||
/**
|
||||
* @brief ShowBorder Sets whether we see the border of the sheet
|
||||
* @param value true to show the border
|
||||
*/
|
||||
void SetShowBorder(bool value);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VPGraphicsSheet)
|
||||
|
||||
VPSheet *m_sheet{nullptr};
|
||||
QRectF m_boundingRect;
|
||||
|
||||
bool m_showMargin{true};
|
||||
bool m_showBorder{true};
|
||||
};
|
||||
|
||||
#endif // VPGRAPHICSSHEET_H
|
||||
|
|
|
@ -80,6 +80,24 @@ VMainGraphicsScene* VPMainGraphicsView::GetScene()
|
|||
return m_scene;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPMainGraphicsView::PrepareForExport()
|
||||
{
|
||||
m_graphicsSheet->SetShowBorder(false);
|
||||
m_graphicsSheet->SetShowMargin(false);
|
||||
RefreshLayout();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPMainGraphicsView::CleanAfterExport()
|
||||
{
|
||||
m_graphicsSheet->SetShowBorder(true);
|
||||
m_graphicsSheet->SetShowMargin(true);
|
||||
RefreshLayout();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPMainGraphicsView::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
|
|
|
@ -55,6 +55,16 @@ public:
|
|||
*/
|
||||
VMainGraphicsScene* GetScene();
|
||||
|
||||
/**
|
||||
* @brief PrepareForExport prepares the graphic for an export (i.e hide margin etc)
|
||||
*/
|
||||
void PrepareForExport();
|
||||
|
||||
/**
|
||||
* @brief CleanAfterExport cleans the graphic for an export (i.e show margin etc)
|
||||
*/
|
||||
void CleanAfterExport();
|
||||
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "vpsheet.h"
|
||||
|
||||
#include <QLoggingCategory>
|
||||
#include <QtSvg>
|
||||
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
||||
|
@ -993,14 +994,42 @@ void VPMainWindow::on_checkBoxSheetStickyEdges_toggled(bool checked)
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPMainWindow::on_pushButtonSheetExport_clicked()
|
||||
{
|
||||
// just for test purpuses, to be removed:
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("TODO VPMainWindow::on_pushButtonSheetExport_clicked");
|
||||
int ret = msgBox.exec();
|
||||
m_graphicsView->PrepareForExport();
|
||||
|
||||
Q_UNUSED(ret);
|
||||
// svg export to do some test for the first test
|
||||
|
||||
// TODO
|
||||
QString dir = QDir::homePath();
|
||||
QString filters(tr("SVG Files") + QLatin1String("(*.svg)"));
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"),
|
||||
dir + QLatin1String("/") + tr("Layout") + QLatin1String(".svg"),
|
||||
filters, nullptr
|
||||
#ifdef Q_OS_LINUX
|
||||
, QFileDialog::DontUseNativeDialog
|
||||
#endif
|
||||
);
|
||||
|
||||
|
||||
|
||||
const QSizeF s = m_layout->GetFocusedSheet()->GetSheetSize();
|
||||
const QRectF r = QRectF(0, 0, s.width(), s.height());
|
||||
|
||||
QSvgGenerator generator;
|
||||
generator.setFileName(fileName);
|
||||
generator.setSize(QSize(qFloor(s.width()),qFloor(s.height())));
|
||||
generator.setViewBox(r);
|
||||
generator.setTitle(tr("Pattern"));
|
||||
generator.setDescription(m_layout->GetDescription().toHtmlEscaped());
|
||||
generator.setResolution(static_cast<int>(PrintDPI));
|
||||
|
||||
QPainter painter;
|
||||
painter.begin(&generator);
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
painter.setPen(QPen(Qt::black, qApp->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
||||
m_graphicsView->GetScene()->render(&painter, r, r, Qt::IgnoreAspectRatio);
|
||||
painter.end();
|
||||
|
||||
m_graphicsView->CleanAfterExport();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "vppiece.h"
|
||||
#include "../vlayout/vlayoutpiece.h"
|
||||
#include "vpcommandline.h"
|
||||
#include "../vlayout/vlayoutdef.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
|
@ -216,6 +217,7 @@ private:
|
|||
|
||||
bool MaybeSave();
|
||||
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* @brief on_actionOpen_triggered When the menu action File > Open is
|
||||
|
|
Loading…
Reference in New Issue
Block a user