Persistence of Layout in UI

This commit is contained in:
Ronan Le Tiec 2020-04-19 12:47:38 +02:00
parent 8be95376f1
commit 83f5d70f98
3 changed files with 136 additions and 75 deletions

View file

@ -38,7 +38,8 @@ PuzzleMainWindow::PuzzleMainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::PuzzleMainWindow),
pieceCarrousel(new VPieceCarrousel),
m_layout (nullptr)
m_layout (nullptr),
m_selectedPiece (nullptr)
{
ui->setupUi(this);
@ -46,13 +47,14 @@ PuzzleMainWindow::PuzzleMainWindow(QWidget *parent) :
InitProperties();
InitPieceCarrousel();
// ----- for test purposes, to be removed------------------
m_layout = new VPuzzleLayout();
m_layout->SetLayoutMarginsConverted(1.5, 2.00, 4.21, 0.25);
m_layout->SetLayoutSizeConverted(21.0, 29.7);
m_layout->SetPiecesGapConverted(1);
m_layout->SetLayoutSizeConverted(30.0, 29.7);
m_layout->SetPiecesGapConverted(1.27);
m_layout->SetUnit(Unit::Cm);
m_layout->SetWarningSuperpositionOfPieces(true);
SetPropertiesData();
}
@ -290,6 +292,16 @@ void PuzzleMainWindow::SetPropertyTabLayoutData()
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutWidth, size.width());
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutLength, size.height());
// Set Orientation
if(size.width() <= size.height())
{
ui->radioButtonLayoutPortrait->setChecked(true);
}
else
{
ui->radioButtonLayoutLandscape->setChecked(true);
}
// set margins
QMarginsF margins = m_layout->GetLayoutMarginsConverted();
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginLeft, margins.left());
@ -299,6 +311,11 @@ void PuzzleMainWindow::SetPropertyTabLayoutData()
// set pieces gap
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutPiecesGap, m_layout->GetPiecesGapConverted());
// set the checkboxes
SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesOutOfBound, m_layout->GetWarningPiecesOutOfBound());
SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesSuperposition, m_layout->GetWarningSuperpositionOfPieces());
SetCheckBoxValue(ui->checkBoxLayoutStickyEdges, m_layout->GetStickyEdges());
}
//---------------------------------------------------------------------------------------------------------------------
@ -322,6 +339,15 @@ void PuzzleMainWindow::SetDoubleSpinBoxValue(QDoubleSpinBox *spinBox, qreal valu
spinBox->blockSignals(false);
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::SetCheckBoxValue(QCheckBox *checkbox, bool value)
{
checkbox->blockSignals(true);
checkbox->setChecked(value);
checkbox->blockSignals(false);
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::New()
@ -430,17 +456,24 @@ void PuzzleMainWindow::AboutPuzzle()
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutUnitChanged(int index)
{
// just for test purpuses, to be removed:
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutUnitChanged");
int ret = msgBox.exec();
Q_UNUSED(index);
Q_UNUSED(ret);
QVariant comboBoxValue = ui->comboBoxLayoutUnit->currentData();
if(comboBoxValue == QVariant(UnitsToStr(Unit::Cm)))
{
m_layout->SetUnit(Unit::Cm);
}
else if(comboBoxValue == QVariant(UnitsToStr(Unit::Mm)))
{
m_layout->SetUnit(Unit::Mm);
}
else if(comboBoxValue == QVariant(UnitsToStr(Unit::Inch)))
{
m_layout->SetUnit(Unit::Inch);
}
// TODO
SetPropertyTabLayoutData();
SetPropertyTabCurrentPieceData();
}
//---------------------------------------------------------------------------------------------------------------------
@ -461,27 +494,36 @@ void PuzzleMainWindow::LayoutTemplateChanged(int index)
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutSizeChanged()
{
// just for test purpuses, to be removed:
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutSizeChanged");
int ret = msgBox.exec();
m_layout->SetLayoutSizeConverted(ui->doubleSpinBoxLayoutWidth->value(), ui->doubleSpinBoxLayoutLength->value());
Q_UNUSED(ret);
// updates orientation - no need to block signals because the signal reacts on "clicked"
if(ui->doubleSpinBoxLayoutWidth->value() <= ui->doubleSpinBoxLayoutLength->value())
{
//portrait
ui->radioButtonLayoutPortrait->setChecked(true);
}
else
{
//landscape
ui->radioButtonLayoutLandscape->setChecked(true);
}
// TODO
// TODO Undo / Redo
// TODO update the QGraphicView
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutOrientationChanged()
{
// just for test purpuses, to be removed:
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutOrientationChanged");
int ret = msgBox.exec();
// swap the width and length
qreal width_before = ui->doubleSpinBoxLayoutWidth->value();
qreal length_before = ui->doubleSpinBoxLayoutLength->value();
Q_UNUSED(ret);
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutWidth, length_before);
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutLength, width_before);
// TODO
// TODO Undo / Redo
// TODO update the QGraphicView
}
//---------------------------------------------------------------------------------------------------------------------
@ -501,14 +543,15 @@ void PuzzleMainWindow::LayoutRemoveUnusedLength()
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutMarginChanged()
{
// just for test purpuses, to be removed:
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutMarginChanged");
int ret = msgBox.exec();
m_layout->SetLayoutMarginsConverted(
ui->doubleSpinBoxLayoutMarginLeft->value(),
ui->doubleSpinBoxLayoutMarginTop->value(),
ui->doubleSpinBoxLayoutMarginRight->value(),
ui->doubleSpinBoxLayoutMarginBottom->value()
);
Q_UNUSED(ret);
// TODO
// TODO Undo / Redo
// TODO update the QGraphicView
}
@ -529,60 +572,37 @@ void PuzzleMainWindow::LayoutFollowGrainlineChanged()
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutPiecesGapChanged(double value)
{
// just for test purpuses, to be removed:
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutPieceGapChanged");
int ret = msgBox.exec();
m_layout->SetPiecesGapConverted(value);
Q_UNUSED(value);
Q_UNUSED(ret);
// TODO
// TODO Undo / Redo
// TODO update the QGraphicView
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutWarningPiecesSuperpositionChanged(bool checked)
{
// just for test purpuses, to be removed:
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutWarningPiecesSuperpositionChanged");
int ret = msgBox.exec();
m_layout->SetWarningSuperpositionOfPieces(checked);
Q_UNUSED(checked);
Q_UNUSED(ret);
// TODO
// TODO Undo / Redo
// TODO update the QGraphicView
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutWarningPiecesOutOfBoundChanged(bool checked)
{
// just for test purpuses, to be removed:
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutWarningPiecesOutOfBoundChanged");
int ret = msgBox.exec();
Q_UNUSED(checked);
Q_UNUSED(ret);
// TODO
m_layout->SetWarningPiecesOutOfBound(checked);
// TODO Undo / Redo
// TODO update the QGraphicView
}
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutStickyEdgesChanged(bool checked)
{
// just for test purpuses, to be removed:
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutStickyEdgesChanged");
int ret = msgBox.exec();
Q_UNUSED(checked);
Q_UNUSED(ret);
// TODO
m_layout->SetStickyEdges(checked);
// TODO Undo / Redo
// TODO update the QGraphicView
}

View file

@ -76,20 +76,52 @@ private:
void InitPieceCarrousel();
/**
* @brief SetPropertiesData Sets the values of UI elements
* in all the property tabs to the values saved in m_layout
*/
void SetPropertiesData();
/**
* @brief SetPropertyTabCurrentPieceData Sets the values of UI elements
* in the Current Piece Tab to the values saved in m_layout
*/
void SetPropertyTabCurrentPieceData();
/**
* @brief SetPropertyTabLayoutData Sets the values of UI elements
* in the Layout Tab to the values saved in m_layout
*/
void SetPropertyTabLayoutData();
/**
* @brief SetPropertyTabTilesData Sets the values of UI elements
* in the Tiles Tab to the values saved in m_layout
*/
void SetPropertyTabTilesData();
/**
* @brief SetPropertyTabLayersData Sets the values of UI elements
* in the Layers Tab to the values saved in m_layout
*/
void SetPropertyTabLayersData();
/**
* @brief SetDoubleSpinBoxValue sets the given spinbox to the given value
* @brief SetDoubleSpinBoxValue sets the given spinbox to the given value.
* the signals are blocked before changing the value and unblocked after
* @param spinbox
* @param value
*/
void SetDoubleSpinBoxValue(QDoubleSpinBox *spinBox, qreal value);
/**
* @brief SetCheckBoxValue sets the given checkbox to the given value.
* the signals are blocked before changing the value and unblocked after
* @param checkbox
* @param value
*/
void SetCheckBoxValue(QCheckBox *checkbox, bool value);
private slots:
void Open();
void Save();

View file

@ -228,8 +228,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>356</width>
<height>760</height>
<width>170</width>
<height>452</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -495,10 +495,18 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxLayoutWidth"/>
<widget class="QDoubleSpinBox" name="doubleSpinBoxLayoutWidth">
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxLayoutLength"/>
<widget class="QDoubleSpinBox" name="doubleSpinBoxLayoutLength">
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelLayoutLength">
@ -850,8 +858,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>356</width>
<height>760</height>
<width>98</width>
<height>41</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
@ -930,8 +938,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>356</width>
<height>760</height>
<width>98</width>
<height>41</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
@ -1064,6 +1072,7 @@
</tabstops>
<resources>
<include location="share/resources/puzzleicon.qrc"/>
<include location="share/resources/puzzleicon.qrc"/>
</resources>
<connections/>
</ui>