2020-05-05 07:44:20 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
2020-05-23 15:36:46 +02:00
|
|
|
** @file vpmaingraphicsview.cpp
|
2020-05-05 07:44:20 +02:00
|
|
|
** @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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
2020-05-23 15:36:46 +02:00
|
|
|
#include "vpmaingraphicsview.h"
|
2020-05-05 07:44:20 +02:00
|
|
|
|
|
|
|
#include <QDragEnterEvent>
|
|
|
|
#include <QMimeData>
|
2020-05-08 23:49:41 +02:00
|
|
|
#include <QKeyEvent>
|
2021-07-31 11:21:07 +02:00
|
|
|
#include <QMenu>
|
2021-08-17 17:49:28 +02:00
|
|
|
#include <QUndoStack>
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
#include "../carousel/vpmimedatapiece.h"
|
|
|
|
#include "../layout/vplayout.h"
|
|
|
|
#include "../layout/vpsheet.h"
|
|
|
|
#include "../layout/vppiece.h"
|
2020-05-11 16:39:54 +02:00
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
2022-02-18 16:57:41 +01:00
|
|
|
#include "undocommands/vpundopiecezvaluemove.h"
|
2021-09-06 14:31:19 +02:00
|
|
|
#include "vpgraphicspiece.h"
|
2021-08-09 14:09:10 +02:00
|
|
|
#include "vpgraphicspiececontrols.h"
|
2021-09-06 14:31:19 +02:00
|
|
|
|
2021-08-17 17:49:28 +02:00
|
|
|
#include "../undocommands/vpundopiecemove.h"
|
2021-08-18 19:33:47 +02:00
|
|
|
#include "../undocommands/vpundopiecerotate.h"
|
2021-08-19 11:36:39 +02:00
|
|
|
#include "../undocommands/vpundooriginmove.h"
|
2021-08-19 14:13:54 +02:00
|
|
|
#include "../undocommands/vpundomovepieceonsheet.h"
|
2021-08-19 15:24:43 +02:00
|
|
|
#include "../undocommands/vpundoremovesheet.h"
|
2020-05-05 07:44:20 +02:00
|
|
|
|
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
|
|
|
QT_WARNING_DISABLE_INTEL(1418)
|
|
|
|
|
|
|
|
Q_LOGGING_CATEGORY(pMainGraphicsView, "p.mainGraphicsView") // NOLINT
|
|
|
|
|
|
|
|
QT_WARNING_POP
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
namespace
|
|
|
|
{
|
2021-09-24 15:53:47 +02:00
|
|
|
QT_WARNING_PUSH
|
2023-01-21 14:01:21 +01:00
|
|
|
#if !defined(Q_OS_MACOS) && defined(Q_CC_CLANG)
|
2021-09-24 15:53:47 +02:00
|
|
|
QT_WARNING_DISABLE_CLANG("-Wenum-enum-conversion")
|
2023-01-21 14:01:21 +01:00
|
|
|
#endif
|
2021-09-24 15:53:47 +02:00
|
|
|
|
2023-02-09 15:02:25 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QKeySequence, restoreOriginShortcut, // NOLINT
|
|
|
|
(QKeySequence(Qt::ControlModifier | Qt::Key_Asterisk)))
|
|
|
|
#else
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QKeySequence, restoreOriginShortcut, // NOLINT
|
|
|
|
(QKeySequence(Qt::ControlModifier + Qt::Key_Asterisk)))
|
2023-02-09 15:02:25 +01:00
|
|
|
#endif
|
2021-09-24 15:53:47 +02:00
|
|
|
|
|
|
|
QT_WARNING_POP
|
2023-05-03 13:07:02 +02:00
|
|
|
} // namespace
|
2020-05-05 07:44:20 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 14:31:19 +02:00
|
|
|
VPMainGraphicsView::VPMainGraphicsView(const VPLayoutPtr &layout, QWidget *parent) :
|
2020-05-11 16:39:54 +02:00
|
|
|
VMainGraphicsView(parent),
|
|
|
|
m_layout(layout)
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
SCASSERT(not layout.isNull())
|
2021-08-25 15:58:50 +02:00
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
SwitchScene(layout->GetFocusedSheet());
|
2020-05-05 07:44:20 +02:00
|
|
|
|
|
|
|
setAcceptDrops(true);
|
2020-05-08 23:49:41 +02:00
|
|
|
|
2021-07-30 13:49:38 +02:00
|
|
|
// add the connections
|
2021-09-13 17:19:39 +02:00
|
|
|
connect(layout.data(), &VPLayout::PieceSheetChanged, this, &VPMainGraphicsView::on_PieceSheetChanged);
|
|
|
|
connect(layout.data(), &VPLayout::ActiveSheetChanged, this, &VPMainGraphicsView::on_ActiveSheetChanged);
|
2021-08-09 14:09:10 +02:00
|
|
|
|
|
|
|
auto *restoreOrigin = new QAction(this);
|
2022-08-12 17:50:13 +02:00
|
|
|
restoreOrigin->setShortcut(*restoreOriginShortcut);
|
2021-08-09 14:09:10 +02:00
|
|
|
connect(restoreOrigin, &QAction::triggered, this, &VPMainGraphicsView::RestoreOrigin);
|
|
|
|
this->addAction(restoreOrigin);
|
2020-05-05 07:44:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:36:46 +02:00
|
|
|
void VPMainGraphicsView::RefreshLayout()
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
2021-08-17 17:49:28 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (not layout.isNull())
|
2021-07-31 11:21:07 +02:00
|
|
|
{
|
2021-08-17 17:49:28 +02:00
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (not sheet.isNull())
|
2021-07-31 11:21:07 +02:00
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
sheet->SceneData()->RefreshLayout();
|
2021-07-31 11:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 10:55:57 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 14:31:19 +02:00
|
|
|
void VPMainGraphicsView::RefreshPieces()
|
2020-11-14 12:37:43 +01:00
|
|
|
{
|
2021-08-17 17:49:28 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (not layout.isNull())
|
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (not sheet.isNull())
|
|
|
|
{
|
2021-09-06 17:06:06 +02:00
|
|
|
sheet->SceneData()->RefreshPieces();
|
2021-09-06 14:31:19 +02:00
|
|
|
}
|
2021-08-17 17:49:28 +02:00
|
|
|
}
|
2020-11-14 12:37:43 +01:00
|
|
|
}
|
|
|
|
|
2020-05-05 07:44:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:36:46 +02:00
|
|
|
void VPMainGraphicsView::dragEnterEvent(QDragEnterEvent *event)
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
|
|
|
const QMimeData *mime = event->mimeData();
|
|
|
|
|
2021-07-30 13:49:38 +02:00
|
|
|
if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr))
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
2021-09-28 16:12:55 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto *mimePiece = qobject_cast<const VPMimeDataPiece *> (mime);
|
|
|
|
if (mimePiece != nullptr && mimePiece->LayoutUuid() == layout->Uuid())
|
|
|
|
{
|
|
|
|
qCDebug(pMainGraphicsView(), "drag enter");
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
2020-05-05 07:44:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:36:46 +02:00
|
|
|
void VPMainGraphicsView::dragMoveEvent(QDragMoveEvent *event)
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
|
|
|
const QMimeData *mime = event->mimeData();
|
|
|
|
|
2021-07-30 13:49:38 +02:00
|
|
|
if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr))
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
2021-09-28 16:12:55 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto *mimePiece = qobject_cast<const VPMimeDataPiece *> (mime);
|
|
|
|
if (mimePiece != nullptr && mimePiece->LayoutUuid() == layout->Uuid())
|
|
|
|
{
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
2020-05-05 07:44:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:36:46 +02:00
|
|
|
void VPMainGraphicsView::dragLeaveEvent(QDragLeaveEvent *event)
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:36:46 +02:00
|
|
|
void VPMainGraphicsView::dropEvent(QDropEvent *event)
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
|
|
|
const QMimeData *mime = event->mimeData();
|
|
|
|
|
|
|
|
qCDebug(pMainGraphicsView(), "drop enter , %s", qUtf8Printable(mime->objectName()));
|
|
|
|
|
2021-07-30 13:49:38 +02:00
|
|
|
if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr))
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
2021-09-28 16:12:55 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-30 13:49:38 +02:00
|
|
|
const auto *mimePiece = qobject_cast<const VPMimeDataPiece *> (mime);
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2021-09-28 16:12:55 +02:00
|
|
|
if (mimePiece == nullptr || mimePiece->LayoutUuid() != layout->Uuid())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-17 17:49:28 +02:00
|
|
|
VPPiecePtr piece = mimePiece->GetPiecePtr();
|
|
|
|
if(not piece.isNull())
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
|
|
|
qCDebug(pMainGraphicsView(), "element dropped, %s", qUtf8Printable(piece->GetName()));
|
|
|
|
event->acceptProposedAction();
|
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
piece->ClearTransformations();
|
2023-02-09 15:13:18 +01:00
|
|
|
piece->SetPosition(mapToScene(DropEventPos(event)));
|
2022-02-18 16:57:41 +01:00
|
|
|
piece->SetZValue(1.0);
|
2020-05-08 23:49:41 +02:00
|
|
|
|
2021-08-19 14:13:54 +02:00
|
|
|
auto *command = new VPUndoMovePieceOnSheet(layout->GetFocusedSheet(), piece);
|
|
|
|
layout->UndoStack()->push(command);
|
2020-05-08 23:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2020-05-08 23:49:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:36:46 +02:00
|
|
|
void VPMainGraphicsView::keyPressEvent(QKeyEvent *event)
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
const bool shiftModifier = (event->modifiers() & Qt::ShiftModifier) != 0U;
|
|
|
|
const bool controlModifier = (event->modifiers() & Qt::ControlModifier) != 0U;
|
|
|
|
const bool altModifier = (event->modifiers() & Qt::AltModifier) != 0U;
|
|
|
|
|
|
|
|
switch(event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Backspace:
|
|
|
|
case Qt::Key_Delete:
|
|
|
|
RemovePiece();
|
|
|
|
break;
|
|
|
|
case Qt::Key_Left:
|
|
|
|
shiftModifier ? TranslatePiecesOn(-10, 0) : TranslatePiecesOn(-1, 0);
|
|
|
|
break;
|
|
|
|
case Qt::Key_Right:
|
|
|
|
shiftModifier ? TranslatePiecesOn(10, 0) : TranslatePiecesOn(1, 0);
|
|
|
|
break;
|
|
|
|
case Qt::Key_Up:
|
|
|
|
shiftModifier ? TranslatePiecesOn(0, -10) : TranslatePiecesOn(0, -1);
|
|
|
|
break;
|
|
|
|
case Qt::Key_Down:
|
|
|
|
shiftModifier ? TranslatePiecesOn(0, 10) : TranslatePiecesOn(0, 1);
|
|
|
|
break;
|
|
|
|
case Qt::Key_BracketLeft:
|
|
|
|
if(controlModifier)
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
RotatePiecesByAngle(90);
|
2020-11-19 15:08:45 +01:00
|
|
|
}
|
2022-08-12 17:50:13 +02:00
|
|
|
else if(altModifier)
|
2021-08-30 17:45:27 +02:00
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
RotatePiecesByAngle(1);
|
2021-09-06 14:31:19 +02:00
|
|
|
}
|
2022-08-12 17:50:13 +02:00
|
|
|
else
|
2021-09-06 14:31:19 +02:00
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
RotatePiecesByAngle(15);
|
2021-09-06 14:31:19 +02:00
|
|
|
}
|
2022-08-12 17:50:13 +02:00
|
|
|
break;
|
|
|
|
case Qt::Key_BracketRight:
|
|
|
|
if(controlModifier)
|
2021-09-06 14:31:19 +02:00
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
RotatePiecesByAngle(-90);
|
2021-08-30 17:45:27 +02:00
|
|
|
}
|
2022-08-12 17:50:13 +02:00
|
|
|
else if(altModifier)
|
|
|
|
{
|
|
|
|
RotatePiecesByAngle(-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RotatePiecesByAngle(-15);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Qt::Key_Home:
|
|
|
|
ZValueMove(static_cast<int>(ML::ZValueMove::Top));
|
|
|
|
break;
|
|
|
|
case Qt::Key_PageUp:
|
|
|
|
ZValueMove(static_cast<int>(ML::ZValueMove::Up));
|
|
|
|
break;
|
|
|
|
case Qt::Key_PageDown:
|
|
|
|
ZValueMove(static_cast<int>(ML::ZValueMove::Down));
|
|
|
|
break;
|
|
|
|
case Qt::Key_End:
|
|
|
|
ZValueMove(static_cast<int>(ML::ZValueMove::Bottom));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-08-30 17:45:27 +02:00
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPMainGraphicsView::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
switch(event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Left:
|
|
|
|
case Qt::Key_Right:
|
|
|
|
case Qt::Key_Up:
|
|
|
|
case Qt::Key_Down:
|
|
|
|
case Qt::Key_BracketLeft:
|
|
|
|
case Qt::Key_BracketRight:
|
|
|
|
MovePiece(event);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2021-08-17 17:49:28 +02:00
|
|
|
}
|
2021-08-18 19:33:47 +02:00
|
|
|
|
|
|
|
if (event->key() == Qt::Key_BracketLeft || event->key() == Qt::Key_BracketRight)
|
|
|
|
{
|
|
|
|
if (not event->isAutoRepeat())
|
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
2021-09-25 19:57:05 +02:00
|
|
|
if (not sheet.isNull())
|
2021-09-06 14:31:19 +02:00
|
|
|
{
|
|
|
|
sheet->SceneData()->RotationControls()->SetIgnorePieceTransformation(false);
|
|
|
|
sheet->SceneData()->RotationControls()->on_UpdateControls();
|
|
|
|
sheet->SceneData()->RotationControls()->on_HideHandles(false);
|
|
|
|
}
|
|
|
|
|
2021-08-26 18:04:24 +02:00
|
|
|
m_rotationSum = 0;
|
2021-08-18 19:33:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
VMainGraphicsView::keyReleaseEvent(event);
|
2021-08-17 17:49:28 +02:00
|
|
|
}
|
|
|
|
|
2021-07-31 11:21:07 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPMainGraphicsView::contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
{
|
2021-07-31 15:00:32 +02:00
|
|
|
QGraphicsItem *item = itemAt(event->pos());
|
|
|
|
if (item != nullptr && item->type() == VPGraphicsPiece::Type)
|
|
|
|
{
|
|
|
|
VMainGraphicsView::contextMenuEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-17 17:49:28 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
|
2021-07-31 11:21:07 +02:00
|
|
|
QMenu menu;
|
2021-08-09 14:09:10 +02:00
|
|
|
|
|
|
|
QAction *restoreOriginAction = menu.addAction(tr("Restore transformation origin"));
|
2022-08-12 17:50:13 +02:00
|
|
|
restoreOriginAction->setShortcut(*restoreOriginShortcut);
|
2021-08-17 17:49:28 +02:00
|
|
|
restoreOriginAction->setEnabled(not sheet.isNull() && sheet->TransformationOrigin().custom);
|
2021-08-09 14:09:10 +02:00
|
|
|
|
2021-07-31 11:21:07 +02:00
|
|
|
QAction *removeSheetAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), tr("Remove sheet"));
|
2021-08-17 17:49:28 +02:00
|
|
|
removeSheetAction->setEnabled(not sheet.isNull() && layout->GetSheets().size() > 1);
|
2021-07-31 11:21:07 +02:00
|
|
|
|
|
|
|
QAction *selectedAction = menu.exec(event->globalPos());
|
|
|
|
if (selectedAction == removeSheetAction)
|
|
|
|
{
|
2021-08-19 15:24:43 +02:00
|
|
|
layout->UndoStack()->push(new VPUndoRemoveSheet(sheet));
|
2021-07-31 11:21:07 +02:00
|
|
|
}
|
2021-08-09 14:09:10 +02:00
|
|
|
else if (selectedAction == restoreOriginAction)
|
|
|
|
{
|
|
|
|
RestoreOrigin();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPMainGraphicsView::RestoreOrigin() const
|
|
|
|
{
|
2021-08-17 17:49:28 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (not sheet.isNull())
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
|
|
|
VPTransformationOrigon origin = sheet->TransformationOrigin();
|
2021-08-19 11:36:39 +02:00
|
|
|
if (origin.custom)
|
|
|
|
{ // ignore if not custom. Prevent double call
|
|
|
|
origin.custom = false;
|
|
|
|
|
|
|
|
QRectF boundingRect;
|
2021-08-25 15:58:50 +02:00
|
|
|
QList<VPPiecePtr> selectedPieces = sheet->GetSelectedPieces();
|
|
|
|
for (const auto& piece : selectedPieces)
|
2021-08-19 11:36:39 +02:00
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
if (piece->IsSelected())
|
2021-08-19 11:36:39 +02:00
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
boundingRect = boundingRect.united(piece->MappedDetailBoundingRect());
|
2021-08-19 11:36:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
origin.origin = boundingRect.center();
|
|
|
|
|
|
|
|
auto *command = new VPUndoOriginMove(sheet, origin);
|
|
|
|
layout->UndoStack()->push(command);
|
|
|
|
}
|
2021-08-09 14:09:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 14:31:19 +02:00
|
|
|
void VPMainGraphicsView::on_SceneMouseMove(const QPointF &scenePos)
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
emit mouseMove(scenePos);
|
2021-08-09 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-18 19:33:47 +02:00
|
|
|
void VPMainGraphicsView::RotatePiecesByAngle(qreal angle)
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
2021-08-17 17:49:28 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (sheet.isNull())
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
sheet->SceneData()->RotationControls()->on_HideHandles(true);
|
|
|
|
sheet->SceneData()->RotationControls()->SetIgnorePieceTransformation(true);
|
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
VPTransformationOrigon origin = sheet->TransformationOrigin();
|
|
|
|
|
2021-08-18 19:33:47 +02:00
|
|
|
auto PreparePieces = [this]()
|
2021-08-09 14:24:36 +02:00
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
QList<VPPiecePtr> pieces;
|
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (not layout.isNull())
|
2021-08-09 14:24:36 +02:00
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (not sheet.isNull())
|
2021-08-18 19:33:47 +02:00
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
pieces = sheet->GetSelectedPieces();
|
2021-08-18 19:33:47 +02:00
|
|
|
}
|
2021-08-09 14:24:36 +02:00
|
|
|
}
|
2021-08-18 19:33:47 +02:00
|
|
|
|
|
|
|
return pieces;
|
|
|
|
};
|
|
|
|
|
2021-08-26 18:04:24 +02:00
|
|
|
if (layout->LayoutSettings().GetFollowGrainline() && not origin.custom)
|
|
|
|
{
|
|
|
|
if (m_rotationSum > 90 || m_rotationSum < -90)
|
|
|
|
{
|
|
|
|
m_rotationSum = angle;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_rotationSum += angle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_rotationSum = angle;
|
|
|
|
}
|
|
|
|
|
2021-08-25 15:58:50 +02:00
|
|
|
QList<VPPiecePtr> pieces = PreparePieces();
|
2021-08-18 19:33:47 +02:00
|
|
|
|
|
|
|
if (pieces.size() == 1)
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
auto *command = new VPUndoPieceRotate(ConstFirst(pieces), origin, angle, m_rotationSum, m_allowChangeMerge);
|
2021-08-18 19:33:47 +02:00
|
|
|
layout->UndoStack()->push(command);
|
2021-08-09 14:24:36 +02:00
|
|
|
}
|
2021-08-18 19:33:47 +02:00
|
|
|
else if (pieces.size() > 1)
|
|
|
|
{
|
2021-08-26 18:04:24 +02:00
|
|
|
auto *command = new VPUndoPiecesRotate(pieces, origin, angle, m_rotationSum, m_allowChangeMerge);
|
2021-08-18 19:33:47 +02:00
|
|
|
layout->UndoStack()->push(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_allowChangeMerge = true;
|
2021-08-09 14:24:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-17 17:49:28 +02:00
|
|
|
void VPMainGraphicsView::TranslatePiecesOn(qreal dx, qreal dy)
|
2021-08-09 14:24:36 +02:00
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
2021-08-17 17:49:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (sheet.isNull())
|
2021-08-17 17:49:28 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
const QList<VPGraphicsPiece *> &graphicsPieces = sheet->SceneData()->GraphicsPieces();
|
|
|
|
|
|
|
|
if (graphicsPieces.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-29 09:59:02 +01:00
|
|
|
VPPiecePtr piece = ConstFirst(graphicsPieces)->GetPiece();
|
2021-09-06 14:31:19 +02:00
|
|
|
if (piece.isNull())
|
2021-08-17 17:49:28 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto PreparePieces = [this]()
|
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
QList<VPPiecePtr> pieces;
|
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (not layout.isNull())
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (not sheet.isNull())
|
2021-08-17 17:49:28 +02:00
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
pieces = sheet->GetSelectedPieces();
|
2021-08-17 17:49:28 +02:00
|
|
|
}
|
2021-08-09 14:09:10 +02:00
|
|
|
}
|
2021-08-17 17:49:28 +02:00
|
|
|
|
|
|
|
return pieces;
|
|
|
|
};
|
|
|
|
|
2021-08-25 15:58:50 +02:00
|
|
|
QList<VPPiecePtr> pieces = PreparePieces();
|
2021-08-17 17:49:28 +02:00
|
|
|
if (pieces.size() == 1)
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
const VPPiecePtr &p = ConstFirst(pieces);
|
2021-08-30 17:45:27 +02:00
|
|
|
auto *command = new VPUndoPieceMove(p, dx, dy, m_allowChangeMerge);
|
2021-08-17 17:49:28 +02:00
|
|
|
layout->UndoStack()->push(command);
|
2021-08-30 17:45:27 +02:00
|
|
|
|
|
|
|
if (layout->LayoutSettings().GetStickyEdges())
|
|
|
|
{
|
|
|
|
QVector<QPointF> path;
|
|
|
|
if (not p.isNull() && p->StickyPosition(m_stickyTranslateX, m_stickyTranslateY))
|
|
|
|
{
|
2022-10-28 12:55:24 +02:00
|
|
|
CastTo(p->GetMappedExternalContourPoints(), path);
|
2021-08-30 17:45:27 +02:00
|
|
|
QTransform m;
|
|
|
|
m.translate(m_stickyTranslateX, m_stickyTranslateY);
|
|
|
|
path = m.map(path);
|
|
|
|
m_hasStickyPosition = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_hasStickyPosition = false;
|
|
|
|
}
|
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
VPGraphicsPiece *gPiece = sheet->SceneData()->ScenePiece(p);
|
2021-08-30 17:45:27 +02:00
|
|
|
if (gPiece != nullptr)
|
|
|
|
{
|
|
|
|
gPiece->SetStickyPoints(path);
|
|
|
|
}
|
|
|
|
}
|
2021-08-09 14:09:10 +02:00
|
|
|
}
|
2021-08-17 17:49:28 +02:00
|
|
|
else if (pieces.size() > 1)
|
|
|
|
{
|
|
|
|
auto *command = new VPUndoPiecesMove(pieces, dx, dy, m_allowChangeMerge);
|
|
|
|
layout->UndoStack()->push(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_allowChangeMerge = true;
|
2021-07-31 11:21:07 +02:00
|
|
|
}
|
|
|
|
|
2021-07-30 13:49:38 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 14:31:19 +02:00
|
|
|
void VPMainGraphicsView::SwitchScene(const VPSheetPtr &sheet)
|
2021-07-30 13:49:38 +02:00
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
if (not sheet.isNull())
|
2021-07-30 13:49:38 +02:00
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
VMainGraphicsScene *scene = sheet->SceneData()->Scene();
|
|
|
|
setScene(scene);
|
|
|
|
connect(scene, &VMainGraphicsScene::mouseMove, this, &VPMainGraphicsView::on_SceneMouseMove,
|
|
|
|
Qt::UniqueConnection);
|
2021-07-30 13:49:38 +02:00
|
|
|
}
|
2021-09-06 14:31:19 +02:00
|
|
|
}
|
2021-07-30 13:49:38 +02:00
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPMainGraphicsView::ClearSelection()
|
|
|
|
{
|
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (sheet.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<VPPiecePtr> pieces = sheet->GetSelectedPieces();
|
|
|
|
for (const auto& piece : pieces)
|
|
|
|
{
|
|
|
|
piece->SetSelected(false);
|
|
|
|
emit layout->PieceSelectionChanged(piece);
|
|
|
|
}
|
2021-08-30 17:45:27 +02:00
|
|
|
}
|
|
|
|
|
2022-02-18 16:57:41 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPMainGraphicsView::ZValueMove(int move)
|
|
|
|
{
|
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (sheet.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<VPPiecePtr> selectedPieces = sheet->GetSelectedPieces();
|
|
|
|
if (selectedPieces.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<VPPiecePtr> allPieces = sheet->GetPieces();
|
|
|
|
if (allPieces.isEmpty() || (allPieces.size() == selectedPieces.size()))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto zMove = static_cast<ML::ZValueMove>(move);
|
|
|
|
|
|
|
|
if (selectedPieces.size() == 1)
|
|
|
|
{
|
|
|
|
layout->UndoStack()->push(new VPUndoPieceZValueMove(ConstFirst(selectedPieces), zMove));
|
|
|
|
}
|
|
|
|
else if (selectedPieces.size() > 1)
|
|
|
|
{
|
|
|
|
layout->UndoStack()->push(new VPUndoPiecesZValueMove(allPieces, zMove));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPMainGraphicsView::RemovePiece() const
|
|
|
|
{
|
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (sheet.isNull())
|
|
|
|
{
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QList<VPGraphicsPiece *> &graphicsPieces = sheet->SceneData()->GraphicsPieces();
|
|
|
|
for(auto *graphicsPiece : graphicsPieces)
|
|
|
|
{
|
|
|
|
VPPiecePtr piece = graphicsPiece->GetPiece();
|
|
|
|
|
|
|
|
if(not piece.isNull() && piece->IsSelected())
|
|
|
|
{
|
|
|
|
piece->SetSelected(false);
|
|
|
|
|
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (not layout.isNull())
|
|
|
|
{
|
|
|
|
emit layout->PieceSelectionChanged(piece);
|
|
|
|
|
|
|
|
auto *command = new VPUndoMovePieceOnSheet(VPSheetPtr(), piece);
|
|
|
|
layout->UndoStack()->push(command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPMainGraphicsView::MovePiece(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
if (not event->isAutoRepeat())
|
|
|
|
{
|
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (sheet.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QList<VPGraphicsPiece *> &graphicsPieces = sheet->SceneData()->GraphicsPieces();
|
|
|
|
if (m_hasStickyPosition && not graphicsPieces.isEmpty())
|
|
|
|
{
|
|
|
|
if (layout->LayoutSettings().GetStickyEdges())
|
|
|
|
{
|
|
|
|
auto PreparePieces = [layout]()
|
|
|
|
{
|
|
|
|
QList<VPPiecePtr> pieces;
|
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (not sheet.isNull())
|
|
|
|
{
|
|
|
|
pieces = sheet->GetSelectedPieces();
|
|
|
|
}
|
|
|
|
|
|
|
|
return pieces;
|
|
|
|
};
|
|
|
|
|
|
|
|
QList<VPPiecePtr> pieces = PreparePieces();
|
|
|
|
if (pieces.size() == 1)
|
|
|
|
{
|
|
|
|
const VPPiecePtr &p = ConstFirst(pieces);
|
|
|
|
|
|
|
|
auto *command = new VPUndoPieceMove(p, m_stickyTranslateX, m_stickyTranslateY,
|
|
|
|
m_allowChangeMerge);
|
|
|
|
layout->UndoStack()->push(command);
|
|
|
|
|
|
|
|
VPGraphicsPiece * gPiece = sheet->SceneData()->ScenePiece(p);
|
|
|
|
if (gPiece != nullptr)
|
|
|
|
{
|
|
|
|
gPiece->SetStickyPoints(QVector<QPointF>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_allowChangeMerge = false;
|
|
|
|
m_hasStickyPosition = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-30 17:45:27 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPMainGraphicsView::on_PieceSheetChanged(const VPPiecePtr &piece)
|
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
2021-08-17 17:49:28 +02:00
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (sheet.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VPGraphicsPiece *graphicsPiece = sheet->SceneData()->ScenePiece(piece);
|
|
|
|
|
|
|
|
if (piece != nullptr && (piece->Sheet().isNull() || piece->Sheet() == layout->GetTrashSheet() ||
|
|
|
|
piece->Sheet() != layout->GetFocusedSheet())) // remove
|
2021-07-30 13:49:38 +02:00
|
|
|
{
|
2021-08-30 17:45:27 +02:00
|
|
|
if (graphicsPiece != nullptr)
|
2021-07-30 13:49:38 +02:00
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
sheet->SceneData()->Scene()->removeItem(graphicsPiece);
|
|
|
|
sheet->SceneData()->RemovePiece(graphicsPiece);
|
2021-08-30 17:45:27 +02:00
|
|
|
delete graphicsPiece;
|
2021-07-30 13:49:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else // add
|
|
|
|
{
|
2021-08-30 17:45:27 +02:00
|
|
|
if(graphicsPiece == nullptr)
|
2021-07-30 13:49:38 +02:00
|
|
|
{
|
2021-08-30 17:45:27 +02:00
|
|
|
graphicsPiece = new VPGraphicsPiece(piece);
|
2021-09-06 14:31:19 +02:00
|
|
|
sheet->SceneData()->AddPiece(graphicsPiece);
|
2021-07-30 13:49:38 +02:00
|
|
|
}
|
2021-09-06 14:31:19 +02:00
|
|
|
sheet->SceneData()->Scene()->addItem(graphicsPiece);
|
2021-07-30 13:49:38 +02:00
|
|
|
}
|
2021-08-27 17:34:37 +02:00
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
sheet->SceneData()->RotationControls()->on_UpdateControls();
|
2021-08-31 13:12:46 +02:00
|
|
|
|
2021-08-27 17:34:37 +02:00
|
|
|
VMainGraphicsView::NewSceneRect(scene(), this);
|
2021-07-30 13:49:38 +02:00
|
|
|
}
|
2021-09-06 14:31:19 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPMainGraphicsView::on_ActiveSheetChanged(const VPSheetPtr &focusedSheet)
|
|
|
|
{
|
|
|
|
if (not focusedSheet.isNull())
|
|
|
|
{
|
|
|
|
ClearSelection();
|
|
|
|
SwitchScene(focusedSheet);
|
|
|
|
RefreshLayout();
|
|
|
|
RefreshPieces();
|
|
|
|
}
|
|
|
|
}
|