enable rotation

This commit is contained in:
Ronan Le Tiec 2020-05-09 11:13:29 +02:00
parent e72a664c8a
commit dc44bef761
6 changed files with 63 additions and 27 deletions

View File

@ -372,7 +372,8 @@ void PuzzleMainWindow::SetPropertyTabCurrentPieceData()
SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionX, UnitConvertor(pos.x(), Unit::Px, m_layout->GetUnit())); SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionX, UnitConvertor(pos.x(), Unit::Px, m_layout->GetUnit()));
SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionY, UnitConvertor(pos.y(), Unit::Px, m_layout->GetUnit())); SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionY, UnitConvertor(pos.y(), Unit::Px, m_layout->GetUnit()));
// TODO: rotation qreal angle = selectedPiece->GetRotation();
SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceAngle, angle);
} }
else else
{ {
@ -831,24 +832,17 @@ void PuzzleMainWindow::on_checkBoxCurrentPieceMirrorPiece_toggled(bool checked)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::on_doubleSpinBoxCurrentPieceAngle_valueChanged(double value) void PuzzleMainWindow::on_doubleSpinBoxCurrentPieceAngle_valueChanged(double value)
{ {
// just for test purpuses, to be removed: if(m_selectedPieces.count() == 1)
QMessageBox msgBox; {
msgBox.setText("TODO PuzzleMainWindow::CurrentPieceAngleChanged"); VPuzzlePiece *piece = m_selectedPieces.first();
int ret = msgBox.exec(); piece->SetRotation(value);
}
Q_UNUSED(value);
Q_UNUSED(ret);
// TODO
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::on_CurrentPiecePositionEdited() void PuzzleMainWindow::on_CurrentPiecePositionEdited()
{ {
// ui->doubleSpinBoxCurrentPieceBoxPositionX->blockSignals(true);
// ui->doubleSpinBoxCurrentPieceBoxPositionY->blockSignals(true);
if(m_selectedPieces.count() == 1) if(m_selectedPieces.count() == 1)
{ {
VPuzzlePiece *piece = m_selectedPieces.first(); VPuzzlePiece *piece = m_selectedPieces.first();
@ -856,10 +850,6 @@ void PuzzleMainWindow::on_CurrentPiecePositionEdited()
UnitConvertor(ui->doubleSpinBoxCurrentPieceBoxPositionY->value(), m_layout->GetUnit(), Unit::Px)); UnitConvertor(ui->doubleSpinBoxCurrentPieceBoxPositionY->value(), m_layout->GetUnit(), Unit::Px));
piece->SetPosition(pos); piece->SetPosition(pos);
} }
// ui->doubleSpinBoxCurrentPieceBoxPositionX->blockSignals(false);
// ui->doubleSpinBoxCurrentPieceBoxPositionY->blockSignals(false);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -228,9 +228,9 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>-542</y> <y>0</y>
<width>342</width> <width>342</width>
<height>1302</height> <height>1318</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -333,7 +333,7 @@
<double>360.000000000000000</double> <double>360.000000000000000</double>
</property> </property>
<property name="singleStep"> <property name="singleStep">
<double>0.100000000000000</double> <double>1.000000000000000</double>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -92,6 +92,7 @@ void VPuzzleGraphicsPiece::Init()
// Initialises the connectors // Initialises the connectors
connect(m_piece, &VPuzzlePiece::SelectionChanged, this, &VPuzzleGraphicsPiece::on_PieceSelectionChanged); connect(m_piece, &VPuzzlePiece::SelectionChanged, this, &VPuzzleGraphicsPiece::on_PieceSelectionChanged);
connect(m_piece, &VPuzzlePiece::PositionChanged, this, &VPuzzleGraphicsPiece::on_PiecePositionChanged); connect(m_piece, &VPuzzlePiece::PositionChanged, this, &VPuzzleGraphicsPiece::on_PiecePositionChanged);
connect(m_piece, &VPuzzlePiece::RotationChanged, this, &VPuzzleGraphicsPiece::on_PieceRotationChanged);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -265,6 +266,13 @@ void VPuzzleGraphicsPiece::on_PiecePositionChanged()
setPos(m_piece->GetPosition()); setPos(m_piece->GetPosition());
} }
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleGraphicsPiece::on_PieceRotationChanged()
{
setTransformOriginPoint(boundingRect().center());
setRotation(-m_piece->GetRotation());
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVariant VPuzzleGraphicsPiece::itemChange(GraphicsItemChange change, const QVariant &value) QVariant VPuzzleGraphicsPiece::itemChange(GraphicsItemChange change, const QVariant &value)
{ {

View File

@ -49,15 +49,20 @@ public:
public slots: public slots:
/** /**
* @brief on_PieceSelectionChanged When the piece selection was changed * @brief on_PieceSelectionChanged Slot called when the piece selection was changed
*/ */
void on_PieceSelectionChanged(); void on_PieceSelectionChanged();
/** /**
* @brief on_PiecePositionChanged When the piece position was changed * @brief on_PiecePositionChanged Slot called when the piece position was changed
*/ */
void on_PiecePositionChanged(); void on_PiecePositionChanged();
/**
* @brief on_PieceRotationChanged Slot called when the piece rotation was changed
*/
void on_PieceRotationChanged();
protected: protected:
QRectF boundingRect() const override; QRectF boundingRect() const override;
QPainterPath shape() const override; QPainterPath shape() const override;

View File

@ -27,6 +27,8 @@
*************************************************************************/ *************************************************************************/
#include "vpuzzlepiece.h" #include "vpuzzlepiece.h"
#include <QtMath>
#include "vpuzzlelayer.h" #include "vpuzzlelayer.h"
#include <QLoggingCategory> #include <QLoggingCategory>
@ -142,8 +144,25 @@ QPointF VPuzzlePiece::GetPosition()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzlePiece::SetRotation(qreal angle) void VPuzzlePiece::SetRotation(qreal angle)
{ {
Q_UNUSED(angle); m_pieceAngle = angle;
//TODO
// make sure the angle is [0 <= angle < 360]
while(m_pieceAngle >= 360)
{
m_pieceAngle -= 360;
}
while(m_pieceAngle < 0)
{
m_pieceAngle += 360;
}
// qreal currentAngle = GetRotation();
// qreal newAngle = angle - currentAngle;
// m_transform.rotate(newAngle);
emit RotationChanged(); emit RotationChanged();
} }
@ -151,8 +170,20 @@ void VPuzzlePiece::SetRotation(qreal angle)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VPuzzlePiece::GetRotation() qreal VPuzzlePiece::GetRotation()
{ {
// TODO return m_pieceAngle;
return 0;
// We don't use the QTransform vor now because the math behind it to retrieve the angle is not trivial.
// TODO / FIXME: we can use QTransform later for optimization
// QTransform tmpTransform = m_transform;
// tmpTransform.translate(-tmpTransform.dx(), -tmpTransform.dy()); // make sure there is only the rotation in the matrix
// qreal angle = qRadiansToDegrees(qAcos(tmpTransform.m11()));
// qCDebug(pPiece, "new angle : %f", angle);
// return angle;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -127,7 +127,7 @@ public:
/** /**
* @brief SetRotation Sets the rotation of the piece to the given angle. * @brief SetRotation Sets the rotation of the piece to the given angle.
* @param angle the angle of the rotation * @param angle the angle of the rotation in degree
*/ */
void SetRotation(qreal angle); void SetRotation(qreal angle);
@ -235,6 +235,8 @@ private:
qreal m_grainlineAngle{0}; qreal m_grainlineAngle{0};
QTransform m_transform{QTransform()}; QTransform m_transform{QTransform()};
// use a separate value for now because it's not easy to get the angle from the transform matrix
qreal m_pieceAngle{0};
bool m_showSeamline{true}; bool m_showSeamline{true};
bool m_mirrorPiece{false}; bool m_mirrorPiece{false};