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), QMainWindow(parent),
ui(new Ui::PuzzleMainWindow), ui(new Ui::PuzzleMainWindow),
pieceCarrousel(new VPieceCarrousel), pieceCarrousel(new VPieceCarrousel),
m_layout (nullptr) m_layout (nullptr),
m_selectedPiece (nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -46,13 +47,14 @@ PuzzleMainWindow::PuzzleMainWindow(QWidget *parent) :
InitProperties(); InitProperties();
InitPieceCarrousel(); InitPieceCarrousel();
// ----- for test purposes, to be removed------------------ // ----- for test purposes, to be removed------------------
m_layout = new VPuzzleLayout(); m_layout = new VPuzzleLayout();
m_layout->SetLayoutMarginsConverted(1.5, 2.00, 4.21, 0.25); m_layout->SetLayoutMarginsConverted(1.5, 2.00, 4.21, 0.25);
m_layout->SetLayoutSizeConverted(21.0, 29.7); m_layout->SetLayoutSizeConverted(30.0, 29.7);
m_layout->SetPiecesGapConverted(1); m_layout->SetPiecesGapConverted(1.27);
m_layout->SetUnit(Unit::Cm); m_layout->SetUnit(Unit::Cm);
m_layout->SetWarningSuperpositionOfPieces(true);
SetPropertiesData(); SetPropertiesData();
} }
@ -290,6 +292,16 @@ void PuzzleMainWindow::SetPropertyTabLayoutData()
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutWidth, size.width()); SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutWidth, size.width());
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutLength, size.height()); SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutLength, size.height());
// Set Orientation
if(size.width() <= size.height())
{
ui->radioButtonLayoutPortrait->setChecked(true);
}
else
{
ui->radioButtonLayoutLandscape->setChecked(true);
}
// set margins // set margins
QMarginsF margins = m_layout->GetLayoutMarginsConverted(); QMarginsF margins = m_layout->GetLayoutMarginsConverted();
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginLeft, margins.left()); SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginLeft, margins.left());
@ -299,6 +311,11 @@ void PuzzleMainWindow::SetPropertyTabLayoutData()
// set pieces gap // set pieces gap
SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutPiecesGap, m_layout->GetPiecesGapConverted()); 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); spinBox->blockSignals(false);
} }
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::SetCheckBoxValue(QCheckBox *checkbox, bool value)
{
checkbox->blockSignals(true);
checkbox->setChecked(value);
checkbox->blockSignals(false);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::New() void PuzzleMainWindow::New()
@ -430,17 +456,24 @@ void PuzzleMainWindow::AboutPuzzle()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutUnitChanged(int index) 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(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() void PuzzleMainWindow::LayoutSizeChanged()
{ {
// just for test purpuses, to be removed: m_layout->SetLayoutSizeConverted(ui->doubleSpinBoxLayoutWidth->value(), ui->doubleSpinBoxLayoutLength->value());
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutSizeChanged");
int ret = msgBox.exec();
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() void PuzzleMainWindow::LayoutOrientationChanged()
{ {
// just for test purpuses, to be removed: // swap the width and length
QMessageBox msgBox; qreal width_before = ui->doubleSpinBoxLayoutWidth->value();
msgBox.setText("TODO PuzzleMainWindow::LayoutOrientationChanged"); qreal length_before = ui->doubleSpinBoxLayoutLength->value();
int ret = msgBox.exec();
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() void PuzzleMainWindow::LayoutMarginChanged()
{ {
// just for test purpuses, to be removed: m_layout->SetLayoutMarginsConverted(
QMessageBox msgBox; ui->doubleSpinBoxLayoutMarginLeft->value(),
msgBox.setText("TODO PuzzleMainWindow::LayoutMarginChanged"); ui->doubleSpinBoxLayoutMarginTop->value(),
int ret = msgBox.exec(); ui->doubleSpinBoxLayoutMarginRight->value(),
ui->doubleSpinBoxLayoutMarginBottom->value()
);
Q_UNUSED(ret); // TODO Undo / Redo
// TODO update the QGraphicView
// TODO
} }
@ -529,60 +572,37 @@ void PuzzleMainWindow::LayoutFollowGrainlineChanged()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutPiecesGapChanged(double value) void PuzzleMainWindow::LayoutPiecesGapChanged(double value)
{ {
// just for test purpuses, to be removed: m_layout->SetPiecesGapConverted(value);
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutPieceGapChanged");
int ret = msgBox.exec();
Q_UNUSED(value); // TODO Undo / Redo
Q_UNUSED(ret); // TODO update the QGraphicView
// TODO
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutWarningPiecesSuperpositionChanged(bool checked) void PuzzleMainWindow::LayoutWarningPiecesSuperpositionChanged(bool checked)
{ {
// just for test purpuses, to be removed: m_layout->SetWarningSuperpositionOfPieces(checked);
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutWarningPiecesSuperpositionChanged");
int ret = msgBox.exec();
Q_UNUSED(checked); // TODO Undo / Redo
Q_UNUSED(ret); // TODO update the QGraphicView
// TODO
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutWarningPiecesOutOfBoundChanged(bool checked) void PuzzleMainWindow::LayoutWarningPiecesOutOfBoundChanged(bool checked)
{ {
// just for test purpuses, to be removed: m_layout->SetWarningPiecesOutOfBound(checked);
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutWarningPiecesOutOfBoundChanged");
int ret = msgBox.exec();
Q_UNUSED(checked);
Q_UNUSED(ret);
// TODO
// TODO Undo / Redo
// TODO update the QGraphicView
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::LayoutStickyEdgesChanged(bool checked) void PuzzleMainWindow::LayoutStickyEdgesChanged(bool checked)
{ {
// just for test purpuses, to be removed: m_layout->SetStickyEdges(checked);
QMessageBox msgBox;
msgBox.setText("TODO PuzzleMainWindow::LayoutStickyEdgesChanged");
int ret = msgBox.exec();
Q_UNUSED(checked);
Q_UNUSED(ret);
// TODO
// TODO Undo / Redo
// TODO update the QGraphicView
} }

View file

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

View file

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