Skip to content

Commit

Permalink
Images can be saved, undo & redo is working (#1160)
Browse files Browse the repository at this point in the history
* feat: DraftImage struct updated

* feat: xml attributes updated for the image feature

* feat: images can be parsed from the sm2d file

* fix: lib include order fixed

* fix: loop between image and handles removed

* feat: images can now be saved, undo & redo are also working

* feat: info popup removed when image is imported

* refactor: code simplification in image_tool

* fix: image z order works again

* fix: ts files updated

* refactor: m_coloredHandles is now m_handleIsHighlighted

* refactor: schema 0.8.0 is now 0.7.1

* feat: handling of broken image paths

---------

Signed-off-by: DSCaskey <[email protected]>
Co-authored-by: DSCaskey <[email protected]>
  • Loading branch information
Onetchou and DSCaskey authored Aug 19, 2024
1 parent a60c8a4 commit 79ef650
Show file tree
Hide file tree
Showing 42 changed files with 5,355 additions and 3,388 deletions.
379 changes: 205 additions & 174 deletions share/translations/seamly2d_cs_CZ.ts

Large diffs are not rendered by default.

469 changes: 244 additions & 225 deletions share/translations/seamly2d_de_DE.ts

Large diffs are not rendered by default.

379 changes: 205 additions & 174 deletions share/translations/seamly2d_el_GR.ts

Large diffs are not rendered by default.

379 changes: 205 additions & 174 deletions share/translations/seamly2d_en_CA.ts

Large diffs are not rendered by default.

311 changes: 171 additions & 140 deletions share/translations/seamly2d_en_GB.ts

Large diffs are not rendered by default.

379 changes: 205 additions & 174 deletions share/translations/seamly2d_en_IN.ts

Large diffs are not rendered by default.

379 changes: 205 additions & 174 deletions share/translations/seamly2d_en_US.ts

Large diffs are not rendered by default.

493 changes: 239 additions & 254 deletions share/translations/seamly2d_es_ES.ts

Large diffs are not rendered by default.

379 changes: 205 additions & 174 deletions share/translations/seamly2d_fi_FI.ts

Large diffs are not rendered by default.

379 changes: 205 additions & 174 deletions share/translations/seamly2d_fr_FR.ts

Large diffs are not rendered by default.

311 changes: 171 additions & 140 deletions share/translations/seamly2d_he_IL.ts

Large diffs are not rendered by default.

311 changes: 171 additions & 140 deletions share/translations/seamly2d_id_ID.ts

Large diffs are not rendered by default.

379 changes: 205 additions & 174 deletions share/translations/seamly2d_it_IT.ts

Large diffs are not rendered by default.

379 changes: 205 additions & 174 deletions share/translations/seamly2d_nl_NL.ts

Large diffs are not rendered by default.

379 changes: 205 additions & 174 deletions share/translations/seamly2d_pt_BR.ts

Large diffs are not rendered by default.

311 changes: 171 additions & 140 deletions share/translations/seamly2d_ro_RO.ts

Large diffs are not rendered by default.

379 changes: 205 additions & 174 deletions share/translations/seamly2d_ru_RU.ts

Large diffs are not rendered by default.

315 changes: 173 additions & 142 deletions share/translations/seamly2d_uk_UA.ts

Large diffs are not rendered by default.

311 changes: 171 additions & 140 deletions share/translations/seamly2d_zh_CN.ts

Large diffs are not rendered by default.

32 changes: 3 additions & 29 deletions src/app/seamly2d/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(doc, &VPattern::patternChanged, this, &MainWindow::patternChangesWereSaved);
connect(doc, &VPattern::UndoCommand, this, &MainWindow::fullParseFile);
connect(doc, &VPattern::setGuiEnabled, this, &MainWindow::setGuiEnabled);
connect(doc, &VPattern::setStatusMessage, this, &MainWindow::setStatusMessage);

// After a pattern is parsed show draft block scene if any draft blocks exist
// AND the View->Draft menu item is checked.
Expand Down Expand Up @@ -1738,7 +1739,7 @@ void MainWindow::handleImageTool()
ui->draft_ToolBox->setCurrentWidget(ui->backgroundImage_Page);
ui->importImage_ToolButton->setChecked(true);

QString filename = getImageFilename();
QString filename = getImageFilename(this);

if(!filename.isEmpty())
{
Expand All @@ -1750,6 +1751,7 @@ void MainWindow::handleImageTool()
if(image_tool->creationWasSuccessful)
{
connect(image_tool, &ImageTool::setStatusMessage, this, &MainWindow::setStatusMessage);
image_tool->addToFile();
}
else
{
Expand All @@ -1766,34 +1768,6 @@ void MainWindow::handleImageTool()
ui->importImage_ToolButton->setChecked(false);
}


//---------------------------------------------------------------------------------------------------------------------
QString MainWindow::getImageFilename()
{
const QString filter = tr("Images") + QLatin1String(" (*.bmp *.jpg *.jpeg *.png *.svg *.tf);;") +
"BMP" + QLatin1String(" (*.bmp);;") +
"JPG" + QLatin1String(" (*.jpg);;") +
"JPEG" + QLatin1String(" (*.jpeg);;") +
"PNG" + QLatin1String(" (*.png);;") +
"SVG" + QLatin1String(" (*.svg);;") +
"TIF" + QLatin1String(" (*.tf)");

const QString path = qApp->Seamly2DSettings()->getImageFilePath();

bool usedNotExistedDir = false;
QDir directory(path);
if (!directory.exists())
{
usedNotExistedDir = directory.mkpath(".");
}

const QString filename = QFileDialog::getOpenFileName(this, tr("Open Image File"), path, filter, nullptr,
QFileDialog::DontUseNativeDialog);

return filename;
}


//Pieces
//---------------------------------------------------------------------------------------------------------------------
/**
Expand Down
1 change: 0 additions & 1 deletion src/app/seamly2d/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ private slots:
void handlePieceMenu();
void handleLayoutMenu();
void handleImagesMenu();
QString getImageFilename();


void CancelTool();
Expand Down
20 changes: 10 additions & 10 deletions src/app/seamly2d/seamly2d.pro
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,6 @@ win32 {
# When the GNU linker sees a library, it discards all symbols that it doesn't need.
# Dependent library go first.

#VTools static library (depend on VWidgets, VMisc, VPatternDB)
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vtools/$${DESTDIR}/ -lvtools

INCLUDEPATH += $$PWD/../../libs/vtools
INCLUDEPATH += $$OUT_PWD/../../libs/vtools/$${UI_DIR} # For UI files
DEPENDPATH += $$PWD/../../libs/vtools

win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/vtools.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/libvtools.a

#Tools static library (depend on VWidgets, VMisc, VPatternDB)
unix|win32: LIBS += -L$$OUT_PWD/../../libs/tools/$${DESTDIR}/ -ltools

Expand All @@ -231,6 +221,16 @@ DEPENDPATH += $$PWD/../../libs/tools
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/tools/$${DESTDIR}/tools.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/tools/$${DESTDIR}/libtools.a

#VTools static library (depend on VWidgets, VMisc, VPatternDB)
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vtools/$${DESTDIR}/ -lvtools

INCLUDEPATH += $$PWD/../../libs/vtools
INCLUDEPATH += $$OUT_PWD/../../libs/vtools/$${UI_DIR} # For UI files
DEPENDPATH += $$PWD/../../libs/vtools

win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/vtools.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/libvtools.a

#VWidgets static library
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/ -lvwidgets

Expand Down
91 changes: 88 additions & 3 deletions src/app/seamly2d/xml/vpattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "../vtools/tools/union_tool.h"
#include "../vtools/tools/drawTools/drawtools.h"
#include "../vtools/tools/nodeDetails/nodedetails.h"
#include "../tools/images/image_tool.h"
#include "../ifc/exception/vexceptionobjecterror.h"
#include "../ifc/exception/vexceptionwrongid.h"
#include "../ifc/exception/vexceptionconversionerror.h"
Expand Down Expand Up @@ -683,7 +684,7 @@ VNodeDetail VPattern::parsePieceNode(const QDomElement &domElement) const
*/
void VPattern::parseDraftBlockElement(const QDomNode &node, const Document &parse)
{
QStringList tags = QStringList() << TagCalculation << TagModeling << TagPieces << TagGroups;
QStringList tags = QStringList() << TagCalculation << TagModeling << TagPieces << TagGroups << TagDraftImages;
QDomNode domNode = node.firstChild();
while (domNode.isNull() == false)
{
Expand Down Expand Up @@ -711,6 +712,10 @@ void VPattern::parseDraftBlockElement(const QDomNode &node, const Document &pars
qCDebug(vXML, "Tag groups.");
parseGroups(domElement);
break;
case 4: // TagDraftImages
qCDebug(vXML, "Tag draft images.");
parseDraftImages(domElement, parse);
break;
default:
VException e(tr("Wrong tag name '%1'.").arg(domElement.tagName()));
throw e;
Expand Down Expand Up @@ -798,6 +803,37 @@ void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const
}
}


//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ParseDraftImages parses draft images.
* @param node node.
*/
void VPattern::parseDraftImages(const QDomNode &node, const Document &parse)
{
SCASSERT(draftScene != nullptr)
SCASSERT(pieceScene != nullptr)

const QDomNodeList nodeList = node.childNodes();
const qint32 num = nodeList.size();
for (qint32 i = 0; i < num; ++i)
{
QDomElement domElement = nodeList.at(i).toElement();
if (domElement.isNull() == false)
{
if (domElement.tagName()==TagDraftImage)
{
qCDebug(vXML, "Tag image.");
parseImageElement(domElement, parse);
}else{
VException e(tr("Wrong tag name '%1'.").arg(domElement.tagName()));
throw e;
}
}
}
}


//---------------------------------------------------------------------------------------------------------------------
/**
* @brief parsePieceElement parse piece tag.
Expand Down Expand Up @@ -903,6 +939,56 @@ void VPattern::parsePieceElement(QDomElement &domElement, const Document &parse)
}
}


//---------------------------------------------------------------------------------------------------------------------
/**
* @brief parseImageElement parse image tag.
* @param domElement tag in xml tree.
*/
void VPattern::parseImageElement(QDomElement &domElement, const Document &parse)
{
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");

DraftImage image;

image.id = getParameterId(domElement);
image.name = GetParametrString(domElement, AttrName, tr("Image_name"));
image.filename = GetParametrString(domElement, AttrSource);
image.width = GetParametrDouble(domElement, AttrWidth, "0.0");
image.height = GetParametrDouble(domElement, AttrHeight, "0.0");
image.xPos = GetParametrDouble(domElement, AttrXPos, "0.0");
image.yPos = GetParametrDouble(domElement, AttrYPos, "0.0");
image.rotation = GetParametrDouble(domElement, AttrRotation, "0.0");
image.aspectLocked = getParameterBool(domElement, AttrAspectRatio, falseStr);
image.locked = getParameterBool(domElement, AttrLocked, falseStr);
image.units = StrToUnits(GetParametrString(domElement, AttrUnits, "px"));
image.opacity = GetParametrDouble(domElement, AttrOpacity, "1.0");
image.order = qint32(GetParametrDouble(domElement, AttrOrder, "0"));
image.xOrigin = GetParametrDouble(domElement, AttrXOffset, "0.0");
image.yOrigin = GetParametrDouble(domElement, AttrYOffset, "0.0");
image.basepoint = GetParametrUInt(domElement, AttrBasepoint, 0);
image.visible = getParameterBool(domElement, AttrVisible, trueStr);

if(parse == Document::FullParse)
{
ImageTool *image_tool = new ImageTool(this, this, draftScene, image);
if(image_tool->creationWasSuccessful)
{
connect(image_tool, &ImageTool::setStatusMessage, this, [this](QString message) {emit setStatusMessage(message);});
}
else
{
image_tool->deleteLater();
ParentNodeById(image.id).removeChild(domElement); //this way the broken image is not light-parsed in the future
}
}
else
{
getBackgroundImage(image.id)->updateImageAndHandles(image);
}
}


//---------------------------------------------------------------------------------------------------------------------
void VPattern::parsePieceNodes(const QDomElement &domElement, VPiece &piece, qreal width, bool closed) const
{
Expand Down Expand Up @@ -3937,15 +4023,14 @@ void VPattern::PrepareForParse(const Document &parse)
if (parse == Document::FullParse)
{
TestUniqueId();
foreach (ImageItem *item, getBackgroundImageMap().values()) {draftScene->removeItem(item);}
draftScene->clear();
foreach (ImageItem *item, getBackgroundImageMap().values()) {draftScene->addItem(item);}
draftScene->initializeOrigins();
pieceScene->clear();
pieceScene->initializeOrigins();
data->ClearForFullParse();
activeDraftBlock.clear();
patternPieces.clear();
clearBackgroundImageMap();

qDeleteAll(toolsOnRemove);//Remove all invisible on a scene objects.
toolsOnRemove.clear();
Expand Down
5 changes: 5 additions & 0 deletions src/app/seamly2d/xml/vpattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ class VPattern : public VAbstractPattern

static const QString AttrReadOnly;

signals:
void setStatusMessage(QString message);

public slots:
virtual void LiteParseTree(const Document &parse) Q_DECL_OVERRIDE;

Expand All @@ -141,6 +144,8 @@ public slots:

void parseDraftBlockElement(const QDomNode &node, const Document &parse);
void ParseDrawMode(const QDomNode &node, const Document &parse, const Draw &mode);
void parseDraftImages(const QDomNode &node, const Document &parse);
void parseImageElement(QDomElement &domElement, const Document &parse);
void parsePieceElement(QDomElement &domElement, const Document &parse);
void parsePieceNodes(const QDomElement &domElement, VPiece &piece, qreal width, bool closed) const;
void ParsePieceDataTag(const QDomElement &domElement, VPiece &piece) const;
Expand Down
1 change: 1 addition & 0 deletions src/libs/ifc/schema.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@
<file>schema/multi_size_measurements/v0.4.5.xsd</file>
<file>schema/pattern/v0.6.9.xsd</file>
<file>schema/pattern/v0.7.0.xsd</file>
<file>schema/pattern/v0.7.1.xsd</file>
</qresource>
</RCC>
Loading

0 comments on commit 79ef650

Please sign in to comment.