puzzle main graphics and pieces

This commit is contained in:
Ronan Le Tiec 2020-05-05 07:44:20 +02:00
parent 497cb65cb2
commit c4dbea1d56
19 changed files with 972 additions and 25 deletions

View file

@ -6,11 +6,17 @@ SOURCES += \
$$PWD/puzzlecommands.cpp \
$$PWD/puzzlemainwindow.cpp \
$$PWD/puzzleapplication.cpp \
$$PWD/vpiececarrouselpiecepreview.cpp \
$$PWD/vpuzzlecommandline.cpp \
$$PWD/dialogs/dialogaboutpuzzle.cpp \
$$PWD/vpiececarrousel.cpp \
$$PWD/vpuzzlegraphicslayout.cpp \
$$PWD/vpuzzlegraphicspiece.cpp \
$$PWD/vpuzzlelayout.cpp \
$$PWD/vpuzzlelayer.cpp \
$$PWD/vpuzzlemaingraphicsscene.cpp \
$$PWD/vpuzzlemaingraphicsview.cpp \
$$PWD/vpuzzlemimedatapiece.cpp \
$$PWD/vpuzzlepiece.cpp \
$$PWD/xml/layoutliterals.cpp \
$$PWD/xml/vpuzzlelayoutfilewriter.cpp \
@ -25,11 +31,17 @@ HEADERS += \
$$PWD/puzzlemainwindow.h \
$$PWD/stable.h \
$$PWD/puzzleapplication.h \
$$PWD/vpiececarrouselpiecepreview.h \
$$PWD/vpuzzlecommandline.h \
$$PWD/dialogs/dialogaboutpuzzle.h \
$$PWD/vpiececarrousel.h \
$$PWD/vpuzzlegraphicslayout.h \
$$PWD/vpuzzlegraphicspiece.h \
$$PWD/vpuzzlelayout.h \
$$PWD/vpuzzlelayer.h \
$$PWD/vpuzzlemaingraphicsscene.h \
$$PWD/vpuzzlemaingraphicsview.h \
$$PWD/vpuzzlemimedatapiece.h \
$$PWD/vpuzzlepiece.h \
$$PWD/xml/layoutliterals.h \
$$PWD/xml/vpuzzlelayoutfilewriter.h \

View file

@ -59,9 +59,9 @@ PuzzleMainWindow::PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *pa
m_layout = new VPuzzleLayout();
// ----- for test purposes, to be removed------------------
m_layout->SetLayoutMarginsConverted(1.5, 2.00, 4.21, 0.25);
m_layout->SetLayoutSizeConverted(30.0, 29.7);
m_layout->SetPiecesGapConverted(1.27);
m_layout->SetLayoutMarginsConverted(2, 2, 2, 2);
m_layout->SetLayoutSizeConverted(30.0, 45);
m_layout->SetPiecesGapConverted(1);
m_layout->SetUnit(Unit::Cm);
m_layout->SetWarningSuperpositionOfPieces(true);
// --------------------------------------------------------
@ -71,6 +71,8 @@ PuzzleMainWindow::PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *pa
InitMenuBar();
InitProperties();
InitPieceCarrousel();
InitMainGraphics();
SetPropertiesData();
}
@ -142,7 +144,12 @@ void PuzzleMainWindow::ImportRawLayouts(const QStringList &rawLayouts)
{
VLayoutPiece rawPiece = data.pieces.at(i);
// TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece()
// We translate the piece, so that the origin of the bounding rect of the piece is at (0,0)
// It makes positioning later on easier.
QRectF boundingRect = rawPiece.DetailBoundingRect();
QPointF topLeft = boundingRect.topLeft();
rawPiece.Translate(-topLeft.x(), -topLeft.y());
// TODO / FIXME: make a few tests, on the data to check for validity. If not
@ -152,6 +159,7 @@ void PuzzleMainWindow::ImportRawLayouts(const QStringList &rawLayouts)
// If seam allowance is built-in, but the seam line path is empty — invalid.
// TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece()
VPuzzlePiece *piece = CreatePiece(rawPiece);
m_layout->GetUnplacedPiecesLayer()->AddPiece(piece);
}
@ -173,7 +181,6 @@ void PuzzleMainWindow::ImportRawLayouts(const QStringList &rawLayouts)
//---------------------------------------------------------------------------------------------------------------------
VPuzzlePiece* PuzzleMainWindow::CreatePiece(const VLayoutPiece &rawPiece)
{
VPuzzlePiece *piece = new VPuzzlePiece();
piece->SetName(rawPiece.GetName());
piece->SetUuid(rawPiece.GetUUID());
@ -411,6 +418,15 @@ void PuzzleMainWindow::SetPropertyTabLayersData()
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::InitMainGraphics()
{
m_graphicsView = new VPuzzleMainGraphicsView(m_layout, this);
ui->centralWidget->layout()->addWidget(m_graphicsView);
m_graphicsView->RefreshLayout();
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::SetDoubleSpinBoxValue(QDoubleSpinBox *spinBox, qreal value)
@ -654,7 +670,8 @@ void PuzzleMainWindow::on_LayoutSizeChanged()
}
// TODO Undo / Redo
// TODO update the QGraphicView
m_graphicsView->RefreshLayout();
}
//---------------------------------------------------------------------------------------------------------------------
@ -667,8 +684,11 @@ void PuzzleMainWindow::on_LayoutOrientationChanged()
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutWidth, length_before);
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutLength, width_before);
m_layout->SetLayoutSizeConverted(ui->doubleSpinBoxLayoutWidth->value(), ui->doubleSpinBoxLayoutLength->value());
// TODO Undo / Redo
// TODO update the QGraphicView
m_graphicsView->RefreshLayout();
}
//---------------------------------------------------------------------------------------------------------------------
@ -696,7 +716,8 @@ void PuzzleMainWindow::on_LayoutMarginChanged()
);
// TODO Undo / Redo
// TODO update the QGraphicView
m_graphicsView->RefreshLayout();
}

View file

@ -34,6 +34,7 @@
#include "../vmisc/def.h"
#include "vpiececarrousel.h"
#include "vpuzzlemaingraphicsview.h"
#include "vpuzzlelayout.h"
#include "vpuzzlepiece.h"
#include "../vlayout/vlayoutpiece.h"
@ -86,11 +87,13 @@ protected:
private:
Q_DISABLE_COPY(PuzzleMainWindow)
Ui::PuzzleMainWindow *ui;
VPieceCarrousel *m_pieceCarrousel{nullptr};
VPuzzleMainGraphicsView *m_graphicsView{nullptr};
VPuzzleCommandLinePtr m_cmd;
VPuzzleLayout *m_layout{nullptr};
VPuzzlePiece *m_selectedPiece{nullptr};
/**
@ -134,6 +137,10 @@ private:
*/
void InitPieceCarrousel();
/**
* @brief InitMainGraphics Initialises the puzzle main graphics
*/
void InitMainGraphics();
/**
* @brief SetPropertiesData Sets the values of UI elements

View file

@ -24,9 +24,6 @@
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QGraphicsView" name="graphicsView"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
@ -1096,7 +1093,6 @@
</widget>
<layoutdefault spacing="6" margin="11"/>
<tabstops>
<tabstop>graphicsView</tabstop>
<tabstop>scrollAreaLayout</tabstop>
<tabstop>doubleSpinBoxLayoutMarginTop</tabstop>
<tabstop>doubleSpinBoxLayoutMarginLeft</tabstop>

View file

@ -230,7 +230,6 @@ void VPieceCarrousel::RefreshOrientation()
{
m_comboBoxLayer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
// scroll bar policy of scroll area
m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);

View file

@ -27,15 +27,22 @@
*************************************************************************/
#include "vpiececarrouselpiece.h"
#include <QLabel>
#include <QVBoxLayout>
#include <QGraphicsScene>
#include <QPainter>
#include <QDrag>
#include <QPainter>
#include <QApplication>
#include "vpuzzlemimedatapiece.h"
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece")
//---------------------------------------------------------------------------------------------------------------------
VPieceCarrouselPiece::VPieceCarrouselPiece(VPuzzlePiece *piece, QWidget *parent) :
QFrame(parent),
@ -48,7 +55,7 @@ VPieceCarrouselPiece::VPieceCarrouselPiece(VPuzzlePiece *piece, QWidget *parent)
//---------------------------------------------------------------------------------------------------------------------
VPieceCarrouselPiece::~VPieceCarrouselPiece()
{
delete m_graphicsView;
delete m_piecePreview;
}
//---------------------------------------------------------------------------------------------------------------------
@ -64,15 +71,15 @@ void VPieceCarrouselPiece::Init()
setStyleSheet("background-color:white; border: 2px solid transparent;");
// define the preview of the piece
m_graphicsView = new QGraphicsView(this);
m_piecePreview = new VPieceCarrouselPiecePreview(this);
// m_graphicsView = new VMainGraphicsView(this);
// --> undefined reference to 'VMainGraphicsView::VMainGraphicView(QWidget*)'
QGraphicsScene *graphicsScene = new QGraphicsScene(this);
m_graphicsView->setScene(graphicsScene);
m_graphicsView->setFixedSize(120,100);
m_graphicsView->setStyleSheet("border: 4px solid transparent;");
m_graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
m_piecePreview->setScene(graphicsScene);
m_piecePreview->setFixedSize(120,100);
m_piecePreview->setStyleSheet("border: 4px solid transparent;");
m_piecePreview->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
// define the label
m_label = new QLabel();
@ -80,8 +87,9 @@ void VPieceCarrouselPiece::Init()
m_label->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
m_label->setFixedSize(120,24);
m_label->setStyleSheet("border: 0px;");
m_label->setMouseTracking(false);
pieceLayout->addWidget(m_graphicsView);
pieceLayout->addWidget(m_piecePreview);
pieceLayout->addWidget(m_label);
// then refresh the data
@ -91,7 +99,7 @@ void VPieceCarrouselPiece::Init()
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::CleanPreview()
{
m_graphicsView->fitInView(m_graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio);
m_piecePreview->fitInView(m_piecePreview->scene()->sceneRect(), Qt::KeepAspectRatio);
}
//---------------------------------------------------------------------------------------------------------------------
@ -113,9 +121,9 @@ void VPieceCarrouselPiece::Refresh()
path.moveTo(points.first());
for (int i = 1; i < points.size(); ++i)
path.lineTo(points.at(i));
m_graphicsView->scene()->addPath(path, pen, noBrush);
m_piecePreview->scene()->addPath(path, pen, noBrush);
m_graphicsView->fitInView(m_graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio);
m_piecePreview->fitInView(m_piecePreview->scene()->sceneRect(), Qt::KeepAspectRatio);
// update the label of the piece
QFontMetrics metrix(m_label->font());
@ -157,12 +165,48 @@ bool VPieceCarrouselPiece::GetIsSelected()
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::mousePressEvent(QMouseEvent *event)
{
qCDebug(pCarrouselPiece, "mouse pressed");
if (event->button() == Qt::LeftButton)
{
if(!m_isSelected)
{
emit clicked(this);
}
m_dragStart = event->pos();
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::mouseMoveEvent(QMouseEvent *event)
{
if (!(event->buttons() & Qt::LeftButton))
{
return;
}
if((event->pos() - m_dragStart).manhattanLength() < QApplication::startDragDistance())
{
return;
}
QDrag *drag = new QDrag(this);
VPuzzleMimeDataPiece *mimeData = new VPuzzleMimeDataPiece();
mimeData->SetPiecePtr(m_piece);
mimeData->setObjectName("piecePointer");
// in case we would want to have the pieces original size:
//drag->setHotSpot(QPoint(0,0));
//QPixmap pixmap(m_piecePreview->sceneRect().size().toSize());
QPixmap pixmap(112,92);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
painter.setRenderHint(QPainter::Antialiasing);
m_piecePreview->scene()->render(&painter);
drag->setPixmap(pixmap);
drag->setMimeData(mimeData);
drag->exec();
}

View file

@ -34,6 +34,7 @@
#include <QMouseEvent>
#include "vpuzzlepiece.h"
#include "vpiececarrouselpiecepreview.h"
class VPieceCarrouselPiece : public QFrame
@ -77,15 +78,19 @@ public slots:
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
private:
Q_DISABLE_COPY(VPieceCarrouselPiece)
VPuzzlePiece *m_piece;
QLabel *m_label{nullptr};
QGraphicsView *m_graphicsView{nullptr};
VPieceCarrouselPiecePreview *m_piecePreview{nullptr};
bool m_isSelected = false;
QPoint m_dragStart;
private slots:
};

View file

@ -0,0 +1,55 @@
/************************************************************************
**
** @file vpiececarrouselpiecepreview.cpp
** @author Ronan Le Tiec
** @date 3 5, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 "vpiececarrouselpiecepreview.h"
#include <QMouseEvent>
//---------------------------------------------------------------------------------------------------------------------
VPieceCarrouselPiecePreview::VPieceCarrouselPiecePreview(QWidget *parent):
QGraphicsView(parent)
{
}
//---------------------------------------------------------------------------------------------------------------------
VPieceCarrouselPiecePreview::~VPieceCarrouselPiecePreview()
{
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiecePreview::mousePressEvent(QMouseEvent *event)
{
event->ignore();
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiecePreview::mouseMoveEvent(QMouseEvent *event)
{
event->ignore();
}

View file

@ -0,0 +1,45 @@
/************************************************************************
**
** @file vpiececarrouselpiecepreview.h
** @author Ronan Le Tiec
** @date 3 5, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 VPUZZLEPIECECARROUSELPIECEPREVIEW_H
#define VPUZZLEPIECECARROUSELPIECEPREVIEW_H
#include <QGraphicsView>
class VPieceCarrouselPiecePreview: public QGraphicsView
{
public:
VPieceCarrouselPiecePreview(QWidget *parent = nullptr);
~VPieceCarrouselPiecePreview();
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
};
#endif // VPUZZLEPIECECARROUSELPIECEPREVIEW_H

View file

@ -0,0 +1,91 @@
/************************************************************************
**
** @file vpuzzlegraphicslayout.cpp
** @author Ronan Le Tiec
** @date 3 5, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 "vpuzzlegraphicslayout.h"
//---------------------------------------------------------------------------------------------------------------------
VPuzzleGraphicsLayout::VPuzzleGraphicsLayout(VPuzzleLayout *layout, QGraphicsItem *parent):
QGraphicsItem(parent),
m_layout(layout)
{
m_boundingRect = GetLayoutRect();
}
//---------------------------------------------------------------------------------------------------------------------
VPuzzleGraphicsLayout::~VPuzzleGraphicsLayout()
{
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleGraphicsLayout::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
Q_UNUSED(option);
QPen pen(QColor(0,179,255), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
pen.setCosmetic(true);
QBrush noBrush(Qt::NoBrush);
painter->setPen(pen);
painter->setBrush(noBrush);
painter->drawRect(GetMarginsRect());
pen.setColor(Qt::black);
painter->setPen(pen);
painter->drawRect(GetLayoutRect());
m_boundingRect = GetLayoutRect();
}
//---------------------------------------------------------------------------------------------------------------------
QRectF VPuzzleGraphicsLayout::GetLayoutRect() const
{
QRectF rect = QRectF(QPointF(0,0), m_layout->GetLayoutSize());
return rect;
}
//---------------------------------------------------------------------------------------------------------------------
QRectF VPuzzleGraphicsLayout::GetMarginsRect() const
{
QMarginsF margins = m_layout->GetLayoutMargins();
QSizeF size = m_layout->GetLayoutSize();
QRectF rect = QRectF(
QPointF(margins.left(),margins.top()),
QPointF(size.width()-margins.right(), size.height()-margins.bottom())
);
return rect;
}
//---------------------------------------------------------------------------------------------------------------------
QRectF VPuzzleGraphicsLayout::boundingRect() const
{
return m_boundingRect;
}

View file

@ -0,0 +1,58 @@
/************************************************************************
**
** @file vpuzzlegraphicslayout.h
** @author Ronan Le Tiec
** @date 3 5, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 VPUZZLEGRAPHICSLAYOUT_H
#define VPUZZLEGRAPHICSLAYOUT_H
#include <QGraphicsItem>
#include <QPainter>
#include "vpuzzlelayout.h"
class VPuzzleGraphicsLayout : public QGraphicsItem
{
public:
VPuzzleGraphicsLayout(VPuzzleLayout *layout, QGraphicsItem *parent = nullptr);
~VPuzzleGraphicsLayout();
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget) override;
QRectF GetLayoutRect() const;
QRectF GetMarginsRect() const;
private:
Q_DISABLE_COPY(VPuzzleGraphicsLayout)
VPuzzleLayout *m_layout{nullptr};
QRectF m_boundingRect;
};
#endif // VPUZZLEGRAPHICSLAYOUT_H

View file

@ -0,0 +1,158 @@
/************************************************************************
**
** @file vpuzzlegraphicspiece.cpp
** @author Ronan Le Tiec
** @date 4 5, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 "vpuzzlegraphicspiece.h"
#include <QPen>
#include <QBrush>
#include <QPainter>
#include <QCursor>
#include <QGraphicsSceneMouseEvent>
//---------------------------------------------------------------------------------------------------------------------
VPuzzleGraphicsPiece::VPuzzleGraphicsPiece(VPuzzlePiece *piece, QGraphicsItem *parent) :
QGraphicsItem(parent),
m_piece(piece),
m_cuttingLine(QPainterPath()),
m_seamLine(QPainterPath())
{
Init();
}
//---------------------------------------------------------------------------------------------------------------------
VPuzzleGraphicsPiece::~VPuzzleGraphicsPiece()
{
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleGraphicsPiece::Init()
{
// set some infos
setFlags(ItemIsSelectable | ItemIsMovable);
setCursor(QCursor(Qt::OpenHandCursor));
//setAcceptHoverEvents(true); // maybe we can do some stuff with this
// initialises the seam line
QVector<QPointF> seamLinePoints = m_piece->GetSeamLine();
m_seamLine.moveTo(seamLinePoints.first());
for (int i = 1; i < seamLinePoints.size(); ++i)
m_seamLine.lineTo(seamLinePoints.at(i));
// initiliases the cutting line
QVector<QPointF> cuttingLinepoints = m_piece->GetCuttingLine();
m_cuttingLine.moveTo(cuttingLinepoints.first());
for (int i = 1; i < cuttingLinepoints.size(); ++i)
m_cuttingLine.lineTo(cuttingLinepoints.at(i));
// TODO : initialises the other elements like grain line, labels, passmarks etc.
}
//---------------------------------------------------------------------------------------------------------------------
QRectF VPuzzleGraphicsPiece::boundingRect() const
{
if(!m_cuttingLine.isEmpty())
{
return m_cuttingLine.boundingRect();
}
return m_seamLine.boundingRect();
}
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VPuzzleGraphicsPiece::shape() const
{
if(!m_cuttingLine.isEmpty())
{
return m_cuttingLine;
}
return m_seamLine;
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
QPen pen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
QBrush noBrush(Qt::NoBrush);
painter->setPen(pen);
painter->setBrush(noBrush);
if(!m_cuttingLine.isEmpty())
{
painter->drawPath(m_cuttingLine);
}
if(!m_seamLine.isEmpty())
{
painter->drawPath(m_seamLine);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
//perform the default behaviour
QGraphicsItem::mousePressEvent(event);
// change the cursor when clicking left button
if (!(event->buttons() & Qt::LeftButton))
{
return;
}
setCursor(Qt::ClosedHandCursor);
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
//perform the default behaviour
QGraphicsItem::mouseReleaseEvent(event);
// change the cursor when clicking left button
if (!(event->buttons() & Qt::LeftButton))
{
return;
}
setCursor(Qt::OpenHandCursor);
}

View file

@ -0,0 +1,61 @@
/************************************************************************
**
** @file vpuzzlegraphicspiece.h
** @author Ronan Le Tiec
** @date 4 5, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 VPUZZLEGRAPHICSPIECE_H
#define VPUZZLEGRAPHICSPIECE_H
#include <QGraphicsItem>
#include "vpuzzlepiece.h"
class VPuzzleGraphicsPiece : public QGraphicsItem
{
public:
VPuzzleGraphicsPiece(VPuzzlePiece *piece, QGraphicsItem *parent = nullptr);
~VPuzzleGraphicsPiece();
void Init();
protected:
QRectF boundingRect() const override;
QPainterPath shape() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget) override;
void mousePressEvent(QGraphicsSceneMouseEvent * event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
private:
Q_DISABLE_COPY(VPuzzleGraphicsPiece)
VPuzzlePiece *m_piece;
QPainterPath m_cuttingLine;
QPainterPath m_seamLine;
};
#endif // VPUZZLEGRAPHICSPIECE_H

View file

@ -0,0 +1,36 @@
/************************************************************************
**
** @file vpuzzlemaingraphicsscene.cpp
** @author Ronan Le Tiec
** @date 3 5, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 "vpuzzlemaingraphicsscene.h"
//---------------------------------------------------------------------------------------------------------------------
VPuzzleMainGraphicsScene::VPuzzleMainGraphicsScene(QObject *parent): QGraphicsScene(parent)
{
}

View file

@ -0,0 +1,43 @@
/************************************************************************
**
** @file vpuzzlemaingraphicsscene.cpp
** @author Ronan Le Tiec
** @date 3 5, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 VPUZZLEMAINGRAPHICSSCENE_H
#define VPUZZLEMAINGRAPHICSSCENE_H
#include <QGraphicsScene>
// TODO: When ready, extend from QGraphicsScene instead
class VPuzzleMainGraphicsScene : public QGraphicsScene
{
Q_OBJECT
public:
VPuzzleMainGraphicsScene(QObject *parent = nullptr);
};
#endif // VPUZZLEMAINGRAPHICSSCENE_H

View file

@ -0,0 +1,131 @@
/************************************************************************
**
** @file vpuzzlemaingraphicsview.cpp
** @author Ronan Le Tiec
** @date 3 5, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 "vpuzzlemaingraphicsview.h"
#include <QDragEnterEvent>
#include <QMimeData>
#include "vpuzzlemimedatapiece.h"
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(pMainGraphicsView, "p.mainGraphicsView")
//---------------------------------------------------------------------------------------------------------------------
VPuzzleMainGraphicsView::VPuzzleMainGraphicsView(VPuzzleLayout *layout, QWidget *parent) :
QGraphicsView(parent)
{
m_scene = new VPuzzleMainGraphicsScene(this);
setScene(m_scene);
m_graphicsLayout = new VPuzzleGraphicsLayout(layout);
m_graphicsLayout->setPos(0,0);
m_scene->addItem(m_graphicsLayout);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
setAcceptDrops(true);
}
//---------------------------------------------------------------------------------------------------------------------
VPuzzleMainGraphicsView::~VPuzzleMainGraphicsView()
{
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleMainGraphicsView::RefreshLayout()
{
// FIXME: Is that the way to go?
m_graphicsLayout->update();
m_scene->update();
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleMainGraphicsView::dragEnterEvent(QDragEnterEvent *event)
{
const QMimeData *mime = event->mimeData();
if(mime->objectName() == "piecePointer")
{
qCDebug(pMainGraphicsView(), "drag enter");
event->acceptProposedAction();
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleMainGraphicsView::dragMoveEvent(QDragMoveEvent *event)
{
const QMimeData *mime = event->mimeData();
if(mime->objectName() == "piecePointer")
{
event->acceptProposedAction();
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleMainGraphicsView::dragLeaveEvent(QDragLeaveEvent *event)
{
event->accept();
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleMainGraphicsView::dropEvent(QDropEvent *event)
{
const QMimeData *mime = event->mimeData();
qCDebug(pMainGraphicsView(), "drop enter , %s", qUtf8Printable(mime->objectName()));
if(mime->objectName() == "piecePointer")
{
const VPuzzleMimeDataPiece *mimePiece = qobject_cast<const VPuzzleMimeDataPiece *> (mime);
VPuzzlePiece *piece = mimePiece->GetPiecePtr();
if(piece != nullptr)
{
qCDebug(pMainGraphicsView(), "element dropped, %s", qUtf8Printable(piece->GetName()));
event->acceptProposedAction();
QPoint point = event->pos();
QPointF scenePos = mapToScene(point);
// todo take the position into account
VPuzzleGraphicsPiece *item = new VPuzzleGraphicsPiece(piece);
item->setPos(scenePos);
m_scene->addItem(item);
}
}
}

View file

@ -0,0 +1,67 @@
/************************************************************************
**
** @file vpuzzlemaingraphicsview.h
** @author Ronan Le Tiec
** @date 3 5, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 VPUZZLEMAINGRAPHICSVIEW_H
#define VPUZZLEMAINGRAPHICSVIEW_H
#include <QGraphicsView>
#include "vpuzzlegraphicslayout.h"
#include "vpuzzlemaingraphicsscene.h"
#include "vpuzzlegraphicspiece.h"
// TODO: when ready, extend the VMainGrapchisView instead
class VPuzzleMainGraphicsView : public QGraphicsView
{
Q_OBJECT
public:
VPuzzleMainGraphicsView(VPuzzleLayout *layout, QWidget *parent);
~VPuzzleMainGraphicsView();
/**
* @brief RefreshLayout Refreshes the rectangles for the layout border and the margin
*/
void RefreshLayout();
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
void dragMoveEvent(QDragMoveEvent *event) override;
void dragLeaveEvent(QDragLeaveEvent *event) override;
void dropEvent(QDropEvent *event) override;
private:
Q_DISABLE_COPY(VPuzzleMainGraphicsView)
VPuzzleGraphicsLayout *m_graphicsLayout{nullptr};
VPuzzleMainGraphicsScene *m_scene{nullptr};
};
#endif // VPUZZLEMAINGRAPHICVIEW_H

View file

@ -0,0 +1,53 @@
/************************************************************************
**
** @file vpuzzlemimedatapiece.cpp
** @author Ronan Le Tiec
** @date 4 5, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 "vpuzzlemimedatapiece.h"
//---------------------------------------------------------------------------------------------------------------------
VPuzzleMimeDataPiece::VPuzzleMimeDataPiece()
{
}
//---------------------------------------------------------------------------------------------------------------------
VPuzzleMimeDataPiece::~VPuzzleMimeDataPiece()
{
}
//---------------------------------------------------------------------------------------------------------------------
VPuzzlePiece* VPuzzleMimeDataPiece::GetPiecePtr() const
{
return m_piece;
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleMimeDataPiece::SetPiecePtr(VPuzzlePiece* piece)
{
m_piece = piece;
}

View file

@ -0,0 +1,65 @@
/************************************************************************
**
** @file vpuzzlemimedatapiece.h
** @author Ronan Le Tiec
** @date 4 5, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 VPUZZLEMIMEDATAPIECE_H
#define VPUZZLEMIMEDATAPIECE_H
#include <QMimeData>
#include "vpuzzlepiece.h"
class VPuzzleMimeDataPiece : public QMimeData
{
Q_OBJECT
public:
VPuzzleMimeDataPiece();
~VPuzzleMimeDataPiece();
/**
* @brief GetPiecePtr Returns the piece pointer of the mime data
* @return piece pointer
*/
VPuzzlePiece* GetPiecePtr() const;
/**
* @brief SetPiecePtr sets the piece pointer to the given value
* @param piece the piece pointer
*/
void SetPiecePtr(VPuzzlePiece* piece);
private:
Q_DISABLE_COPY(VPuzzleMimeDataPiece)
VPuzzlePiece *m_piece{nullptr};
};
#endif // VPUZZLEMIMEDATAPIECE_H