Dialog must do not allow values smaller than 1 pixel.

--HG--
branch : feature
This commit is contained in:
dismine 2015-01-15 19:31:42 +02:00
parent 00e42b4368
commit ce67acc6ff
3 changed files with 83 additions and 41 deletions

View File

@ -45,6 +45,8 @@ DialogLayoutSettings::DialogLayoutSettings(QWidget *parent)
InitPaperUnits(); InitPaperUnits();
InitLayoutUnits(); InitLayoutUnits();
InitTemplates(); InitTemplates();
MinimumPaperSize();
MinimumLayoutSize();
connect(ui->comboBoxTemplates, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(ui->comboBoxTemplates, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogLayoutSettings::TemplateSelected); this, &DialogLayoutSettings::TemplateSelected);
@ -58,8 +60,6 @@ DialogLayoutSettings::DialogLayoutSettings(QWidget *parent)
connect(ui->toolButtonLandscape, &QToolButton::toggled, this, &DialogLayoutSettings::Swap); connect(ui->toolButtonLandscape, &QToolButton::toggled, this, &DialogLayoutSettings::Swap);
connect(ui->comboBoxLayoutUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(ui->comboBoxLayoutUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogLayoutSettings::ConvertLayoutSize); this, &DialogLayoutSettings::ConvertLayoutSize);
connect(ui->doubleSpinBoxLayoutWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogLayoutSettings::LayoutWidthChanged);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -160,7 +160,7 @@ void DialogLayoutSettings::TemplateSelected()
ui->doubleSpinBoxPaperWidth->setValue(size.width()); ui->doubleSpinBoxPaperWidth->setValue(size.width());
ui->doubleSpinBoxPaperHeight->setValue(size.height()); ui->doubleSpinBoxPaperHeight->setValue(size.height());
oldPaperUnit = PaperUnit(); oldPaperUnit = PaperUnit();
CorrectDecimals(); CorrectPaperDecimals();
PaperSizeChanged(); PaperSizeChanged();
} }
@ -173,7 +173,8 @@ void DialogLayoutSettings::ConvertPaperSize()
ui->doubleSpinBoxPaperWidth->setValue(VAbstractMeasurements::UnitConvertor(width, oldPaperUnit, paperUnit)); ui->doubleSpinBoxPaperWidth->setValue(VAbstractMeasurements::UnitConvertor(width, oldPaperUnit, paperUnit));
ui->doubleSpinBoxPaperHeight->setValue(VAbstractMeasurements::UnitConvertor(height, oldPaperUnit, paperUnit)); ui->doubleSpinBoxPaperHeight->setValue(VAbstractMeasurements::UnitConvertor(height, oldPaperUnit, paperUnit));
oldPaperUnit = paperUnit; oldPaperUnit = paperUnit;
CorrectDecimals(); CorrectPaperDecimals();
MinimumPaperSize();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -185,22 +186,13 @@ void DialogLayoutSettings::ConvertLayoutSize()
ui->doubleSpinBoxLayoutWidth->setValue(VAbstractMeasurements::UnitConvertor(layoutWidth, oldLayoutUnit, unit)); ui->doubleSpinBoxLayoutWidth->setValue(VAbstractMeasurements::UnitConvertor(layoutWidth, oldLayoutUnit, unit));
ui->doubleSpinBoxShift->setValue(VAbstractMeasurements::UnitConvertor(shift, oldLayoutUnit, unit)); ui->doubleSpinBoxShift->setValue(VAbstractMeasurements::UnitConvertor(shift, oldLayoutUnit, unit));
oldLayoutUnit = unit; oldLayoutUnit = unit;
CorrectLayoutDecimals();
MinimumLayoutSize();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::PaperSizeChanged() void DialogLayoutSettings::PaperSizeChanged()
{ {
QDoubleSpinBox *box = qobject_cast<QDoubleSpinBox*>(sender());
if (box != nullptr)
{
if (box->value() <= 0)
{
box->blockSignals(true);
box->setValue(1);
box->blockSignals(false);
}
}
if (ui->doubleSpinBoxPaperHeight->value() > ui->doubleSpinBoxPaperWidth->value()) if (ui->doubleSpinBoxPaperHeight->value() > ui->doubleSpinBoxPaperWidth->value())
{ {
ui->toolButtonPortrate->blockSignals(true); ui->toolButtonPortrate->blockSignals(true);
@ -217,21 +209,6 @@ void DialogLayoutSettings::PaperSizeChanged()
Label(); Label();
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::LayoutWidthChanged()
{
QDoubleSpinBox *box = qobject_cast<QDoubleSpinBox*>(sender());
if (box != nullptr)
{
if (box->value() <= 0)
{
box->blockSignals(true);
box->setValue(1);
box->blockSignals(false);
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::Swap(bool checked) void DialogLayoutSettings::Swap(bool checked)
{ {
@ -283,6 +260,9 @@ void DialogLayoutSettings::InitLayoutUnits()
{ {
ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit);
} }
ui->doubleSpinBoxLayoutWidth->setValue(VAbstractMeasurements::UnitConvertor(1, Unit::Mm, oldLayoutUnit));
ui->doubleSpinBoxShift->setValue(VAbstractMeasurements::UnitConvertor(10, Unit::Mm, oldLayoutUnit));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -350,17 +330,48 @@ Unit DialogLayoutSettings::LayoutUnit() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::CorrectDecimals() void DialogLayoutSettings::CorrectPaperDecimals()
{ {
if (oldPaperUnit == Unit::Px) switch(oldPaperUnit)
{ {
ui->doubleSpinBoxPaperWidth->setDecimals(0); case Unit::Cm:
ui->doubleSpinBoxPaperHeight->setDecimals(0); case Unit::Mm:
ui->doubleSpinBoxPaperWidth->setDecimals(2);
ui->doubleSpinBoxPaperHeight->setDecimals(2);
break;
case Unit::Inch:
ui->doubleSpinBoxPaperWidth->setDecimals(5);
ui->doubleSpinBoxPaperHeight->setDecimals(5);
break;
case Unit::Px:
ui->doubleSpinBoxPaperWidth->setDecimals(0);
ui->doubleSpinBoxPaperHeight->setDecimals(0);
break;
default:
break;
} }
else }
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::CorrectLayoutDecimals()
{
switch(oldLayoutUnit)
{ {
ui->doubleSpinBoxPaperWidth->setDecimals(2); case Unit::Cm:
ui->doubleSpinBoxPaperHeight->setDecimals(2); case Unit::Mm:
ui->doubleSpinBoxLayoutWidth->setDecimals(2);
ui->doubleSpinBoxShift->setDecimals(2);
break;
case Unit::Inch:
ui->doubleSpinBoxLayoutWidth->setDecimals(5);
ui->doubleSpinBoxShift->setDecimals(5);
break;
case Unit::Px:
ui->doubleSpinBoxLayoutWidth->setDecimals(0);
ui->doubleSpinBoxShift->setDecimals(0);
break;
default:
break;
} }
} }
@ -374,3 +385,18 @@ void DialogLayoutSettings::Label()
QString text = QString("%1 x %2 px, \n%3 ppi").arg(width).arg(height).arg(VApplication::PrintDPI); QString text = QString("%1 x %2 px, \n%3 ppi").arg(width).arg(height).arg(VApplication::PrintDPI);
ui->labelSizeDescription->setText(text); ui->labelSizeDescription->setText(text);
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::MinimumPaperSize()
{
const qreal value = VAbstractMeasurements::UnitConvertor(1, Unit::Px, oldPaperUnit);
ui->doubleSpinBoxPaperWidth->setMinimum(value);
ui->doubleSpinBoxPaperHeight->setMinimum(value);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::MinimumLayoutSize()
{
const qreal value = VAbstractMeasurements::UnitConvertor(1, Unit::Px, oldLayoutUnit);
ui->doubleSpinBoxLayoutWidth->setMinimum(value);
}

View File

@ -62,11 +62,11 @@ public:
void SetGroup(const Cases &value); void SetGroup(const Cases &value);
public slots: public slots:
void TemplateSelected();
void ConvertPaperSize(); void ConvertPaperSize();
void ConvertLayoutSize(); void ConvertLayoutSize();
void TemplateSelected();
void PaperSizeChanged(); void PaperSizeChanged();
void LayoutWidthChanged();
void Swap(bool checked); void Swap(bool checked);
private: private:
@ -83,8 +83,12 @@ private:
Unit PaperUnit() const; Unit PaperUnit() const;
Unit LayoutUnit() const; Unit LayoutUnit() const;
void CorrectDecimals(); void CorrectPaperDecimals();
void CorrectLayoutDecimals();
void Label(); void Label();
void MinimumPaperSize();
void MinimumLayoutSize();
}; };
#endif // DIALOGLAYOUTSETTINGS_H #endif // DIALOGLAYOUTSETTINGS_H

View File

@ -193,6 +193,12 @@
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1"> <item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxLayoutWidth"> <widget class="QDoubleSpinBox" name="doubleSpinBoxLayoutWidth">
<property name="minimumSize">
<size>
<width>94</width>
<height>0</height>
</size>
</property>
<property name="minimum"> <property name="minimum">
<double>0.000000000000000</double> <double>0.000000000000000</double>
</property> </property>
@ -220,6 +226,12 @@
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxShift"> <widget class="QDoubleSpinBox" name="doubleSpinBoxShift">
<property name="minimumSize">
<size>
<width>94</width>
<height>0</height>
</size>
</property>
<property name="maximum"> <property name="maximum">
<double>99999.990000000005239</double> <double>99999.990000000005239</double>
</property> </property>
@ -337,7 +349,7 @@
</connection> </connection>
</connections> </connections>
<buttongroups> <buttongroups>
<buttongroup name="buttonGroupPrinciple"/>
<buttongroup name="buttonGroup"/> <buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroupPrinciple"/>
</buttongroups> </buttongroups>
</ui> </ui>