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();
InitLayoutUnits();
InitTemplates();
MinimumPaperSize();
MinimumLayoutSize();
connect(ui->comboBoxTemplates, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogLayoutSettings::TemplateSelected);
@ -58,8 +60,6 @@ DialogLayoutSettings::DialogLayoutSettings(QWidget *parent)
connect(ui->toolButtonLandscape, &QToolButton::toggled, this, &DialogLayoutSettings::Swap);
connect(ui->comboBoxLayoutUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
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->doubleSpinBoxPaperHeight->setValue(size.height());
oldPaperUnit = PaperUnit();
CorrectDecimals();
CorrectPaperDecimals();
PaperSizeChanged();
}
@ -173,7 +173,8 @@ void DialogLayoutSettings::ConvertPaperSize()
ui->doubleSpinBoxPaperWidth->setValue(VAbstractMeasurements::UnitConvertor(width, oldPaperUnit, paperUnit));
ui->doubleSpinBoxPaperHeight->setValue(VAbstractMeasurements::UnitConvertor(height, oldPaperUnit, paperUnit));
oldPaperUnit = paperUnit;
CorrectDecimals();
CorrectPaperDecimals();
MinimumPaperSize();
}
//---------------------------------------------------------------------------------------------------------------------
@ -185,22 +186,13 @@ void DialogLayoutSettings::ConvertLayoutSize()
ui->doubleSpinBoxLayoutWidth->setValue(VAbstractMeasurements::UnitConvertor(layoutWidth, oldLayoutUnit, unit));
ui->doubleSpinBoxShift->setValue(VAbstractMeasurements::UnitConvertor(shift, oldLayoutUnit, unit));
oldLayoutUnit = unit;
CorrectLayoutDecimals();
MinimumLayoutSize();
}
//---------------------------------------------------------------------------------------------------------------------
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())
{
ui->toolButtonPortrate->blockSignals(true);
@ -217,21 +209,6 @@ void DialogLayoutSettings::PaperSizeChanged()
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)
{
@ -283,6 +260,9 @@ void DialogLayoutSettings::InitLayoutUnits()
{
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);
ui->doubleSpinBoxPaperHeight->setDecimals(0);
case Unit::Cm:
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);
ui->doubleSpinBoxPaperHeight->setDecimals(2);
case Unit::Cm:
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);
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);
public slots:
void TemplateSelected();
void ConvertPaperSize();
void ConvertLayoutSize();
void TemplateSelected();
void PaperSizeChanged();
void LayoutWidthChanged();
void Swap(bool checked);
private:
@ -83,8 +83,12 @@ private:
Unit PaperUnit() const;
Unit LayoutUnit() const;
void CorrectDecimals();
void CorrectPaperDecimals();
void CorrectLayoutDecimals();
void Label();
void MinimumPaperSize();
void MinimumLayoutSize();
};
#endif // DIALOGLAYOUTSETTINGS_H

View File

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