New paper size template - "custom". Appers if change height or width. The

program also test each size and show appropriate template from the list.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-11-05 20:04:09 +02:00
parent 912d1f91f6
commit f632ef6480
3 changed files with 186 additions and 73 deletions

View File

@ -53,7 +53,8 @@ const DialogLayoutSettings::FormatsVector DialogLayoutSettings::pageFormatNames
<< QApplication::translate("DialogLayoutSettings", "Roll 30in") << QApplication::translate("DialogLayoutSettings", "Roll 30in")
<< QApplication::translate("DialogLayoutSettings", "Roll 36in") << QApplication::translate("DialogLayoutSettings", "Roll 36in")
<< QApplication::translate("DialogLayoutSettings", "Roll 42in") << QApplication::translate("DialogLayoutSettings", "Roll 42in")
<< QApplication::translate("DialogLayoutSettings", "Roll 44in"); << QApplication::translate("DialogLayoutSettings", "Roll 44in")
<< QApplication::translate("DialogLayoutSettings", "Custom");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent, bool disableSettings) DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent, bool disableSettings)
@ -86,10 +87,17 @@ DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget
this, &DialogLayoutSettings::TemplateSelected); this, &DialogLayoutSettings::TemplateSelected);
connect(ui->comboBoxPaperSizeUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(ui->comboBoxPaperSizeUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogLayoutSettings::ConvertPaperSize); this, &DialogLayoutSettings::ConvertPaperSize);
connect(ui->doubleSpinBoxPaperWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), connect(ui->doubleSpinBoxPaperWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogLayoutSettings::PaperSizeChanged); this, &DialogLayoutSettings::PaperSizeChanged);
connect(ui->doubleSpinBoxPaperHeight, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), connect(ui->doubleSpinBoxPaperHeight, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogLayoutSettings::PaperSizeChanged); this, &DialogLayoutSettings::PaperSizeChanged);
connect(ui->doubleSpinBoxPaperWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogLayoutSettings::FindTemplate);
connect(ui->doubleSpinBoxPaperHeight, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogLayoutSettings::FindTemplate);
connect(ui->toolButtonPortrate, &QToolButton::toggled, this, &DialogLayoutSettings::Swap); connect(ui->toolButtonPortrate, &QToolButton::toggled, this, &DialogLayoutSettings::Swap);
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),
@ -269,6 +277,39 @@ void DialogLayoutSettings::TemplateSelected()
SheetSize(Template()); SheetSize(Template());
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::FindTemplate()
{
const qreal width = ui->doubleSpinBoxPaperWidth->value();
const qreal height = ui->doubleSpinBoxPaperHeight->value();
QSizeF size(width, height);
const int max = static_cast<int>(PaperSizeTemplate::Custom);
for (int i=0; i < max; ++i)
{
const QSizeF tmplSize = TemplateSize(static_cast<PaperSizeTemplate>(i));
if (size == tmplSize)
{
ui->comboBoxTemplates->blockSignals(true);
const int index = ui->comboBoxTemplates->findData(i);
if (index != -1)
{
ui->comboBoxTemplates->setCurrentIndex(index);
}
ui->comboBoxTemplates->blockSignals(false);
return;
}
}
ui->comboBoxTemplates->blockSignals(true);
const int index = ui->comboBoxTemplates->findData(max);
if (index != -1)
{
ui->comboBoxTemplates->setCurrentIndex(index);
}
ui->comboBoxTemplates->blockSignals(false);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::ConvertPaperSize() void DialogLayoutSettings::ConvertPaperSize()
{ {
@ -276,8 +317,12 @@ void DialogLayoutSettings::ConvertPaperSize()
const qreal width = ui->doubleSpinBoxPaperWidth->value(); const qreal width = ui->doubleSpinBoxPaperWidth->value();
const qreal height = ui->doubleSpinBoxPaperHeight->value(); const qreal height = ui->doubleSpinBoxPaperHeight->value();
ui->doubleSpinBoxPaperWidth->blockSignals(true);
ui->doubleSpinBoxPaperHeight->blockSignals(true);
ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, paperUnit)); ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, paperUnit));
ui->doubleSpinBoxPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, paperUnit)); ui->doubleSpinBoxPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, paperUnit));
ui->doubleSpinBoxPaperWidth->blockSignals(false);
ui->doubleSpinBoxPaperHeight->blockSignals(false);
const qreal newWidth = UnitConvertor(width, oldPaperUnit, paperUnit); const qreal newWidth = UnitConvertor(width, oldPaperUnit, paperUnit);
const qreal newHeight = UnitConvertor(height, oldPaperUnit, paperUnit); const qreal newHeight = UnitConvertor(height, oldPaperUnit, paperUnit);
@ -505,14 +550,18 @@ void DialogLayoutSettings::InitTemplates()
auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0); auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
foreach(const auto& v, pageFormatNames) foreach(const auto& v, pageFormatNames)
{ {
if (cntr <= 6) if (cntr <= static_cast<int>(PaperSizeTemplate::Legal))
{ {
ui->comboBoxTemplates->addItem(icoPaper, v+" "+pdi, QVariant(cntr++)); ui->comboBoxTemplates->addItem(icoPaper, v+" "+pdi, QVariant(cntr++));
} }
else else if (cntr <= static_cast<int>(PaperSizeTemplate::Roll44in))
{ {
ui->comboBoxTemplates->addItem(icoRoll, v+" "+pdi, QVariant(cntr++)); ui->comboBoxTemplates->addItem(icoRoll, v+" "+pdi, QVariant(cntr++));
} }
else
{
ui->comboBoxTemplates->addItem(v+" "+pdi, QVariant(cntr++));
}
} }
ui->comboBoxTemplates->setCurrentIndex(-1); ui->comboBoxTemplates->setCurrentIndex(-1);
} }
@ -524,9 +573,12 @@ QString DialogLayoutSettings::MakeHelpTemplateList()
auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0); auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
foreach(const auto& v, pageFormatNames) foreach(const auto& v, pageFormatNames)
{
if (cntr <= static_cast<int>(PaperSizeTemplate::Roll44in))// Don't include custom template
{ {
out += "\t"+v+" = "+ QString::number(cntr++)+"\n"; out += "\t"+v+" = "+ QString::number(cntr++)+"\n";
} }
}
return out; return out;
} }
@ -540,91 +592,125 @@ QSizeF DialogLayoutSettings::Template()
#else #else
temp = static_cast<PaperSizeTemplate>(ui->comboBoxTemplates->currentData().toInt()); temp = static_cast<PaperSizeTemplate>(ui->comboBoxTemplates->currentData().toInt());
#endif #endif
const Unit paperUnit = PaperUnit();
qreal width = 0;
qreal height = 0;
switch (temp) switch (temp)
{ {
case PaperSizeTemplate::A0: case PaperSizeTemplate::A0:
SetAdditionalOptions(false);
width = UnitConvertor(841, Unit::Mm, paperUnit);
height = UnitConvertor(1189, Unit::Mm, paperUnit);
return QSizeF(width, height);
case PaperSizeTemplate::A1: case PaperSizeTemplate::A1:
SetAdditionalOptions(false);
width = UnitConvertor(594, Unit::Mm, paperUnit);
height = UnitConvertor(841, Unit::Mm, paperUnit);
return QSizeF(width, height);
case PaperSizeTemplate::A2: case PaperSizeTemplate::A2:
SetAdditionalOptions(false);
width = UnitConvertor(420, Unit::Mm, paperUnit);
height = UnitConvertor(594, Unit::Mm, paperUnit);
return QSizeF(width, height);
case PaperSizeTemplate::A3: case PaperSizeTemplate::A3:
SetAdditionalOptions(false);
width = UnitConvertor(297, Unit::Mm, paperUnit);
height = UnitConvertor(420, Unit::Mm, paperUnit);
return QSizeF(width, height);
case PaperSizeTemplate::A4: case PaperSizeTemplate::A4:
SetAdditionalOptions(false);
width = UnitConvertor(210, Unit::Mm, paperUnit);
height = UnitConvertor(297, Unit::Mm, paperUnit);
return QSizeF(width, height);
case PaperSizeTemplate::Letter: case PaperSizeTemplate::Letter:
SetAdditionalOptions(false); SetAdditionalOptions(false);
return TemplateSize(temp);
width = UnitConvertor(8.5, Unit::Inch, paperUnit);
height = UnitConvertor(11, Unit::Inch, paperUnit);
return QSizeF(width, height);
case PaperSizeTemplate::Legal: case PaperSizeTemplate::Legal:
SetAdditionalOptions(true);
width = UnitConvertor(11, Unit::Inch, paperUnit);
height = UnitConvertor(17, Unit::Inch, paperUnit);
return QSizeF(width, height);
case PaperSizeTemplate::Roll24in: case PaperSizeTemplate::Roll24in:
SetAdditionalOptions(true);
width = UnitConvertor(24, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return QSizeF(width, height);
case PaperSizeTemplate::Roll30in: case PaperSizeTemplate::Roll30in:
SetAdditionalOptions(true);
width = UnitConvertor(30, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return QSizeF(width, height);
case PaperSizeTemplate::Roll36in: case PaperSizeTemplate::Roll36in:
SetAdditionalOptions(true);
width = UnitConvertor(36, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return QSizeF(width, height);
case PaperSizeTemplate::Roll42in: case PaperSizeTemplate::Roll42in:
SetAdditionalOptions(true);
width = UnitConvertor(42, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return QSizeF(width, height);
case PaperSizeTemplate::Roll44in: case PaperSizeTemplate::Roll44in:
SetAdditionalOptions(true); SetAdditionalOptions(true);
return TemplateSize(temp);
width = UnitConvertor(44, Unit::Inch, paperUnit); case PaperSizeTemplate::Custom:
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); return TemplateSize(temp);
return QSizeF(width, height);
default: default:
break; break;
} }
return QSizeF(); return QSizeF();
} }
//---------------------------------------------------------------------------------------------------------------------
QSizeF DialogLayoutSettings::TemplateSize(const PaperSizeTemplate &tmpl) const
{
const Unit paperUnit = PaperUnit();
qreal width = 0;
qreal height = 0;
switch (tmpl)
{
case PaperSizeTemplate::A0:
width = UnitConvertor(841, Unit::Mm, paperUnit);
height = UnitConvertor(1189, Unit::Mm, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::A1:
width = UnitConvertor(594, Unit::Mm, paperUnit);
height = UnitConvertor(841, Unit::Mm, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::A2:
width = UnitConvertor(420, Unit::Mm, paperUnit);
height = UnitConvertor(594, Unit::Mm, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::A3:
width = UnitConvertor(297, Unit::Mm, paperUnit);
height = UnitConvertor(420, Unit::Mm, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::A4:
width = UnitConvertor(210, Unit::Mm, paperUnit);
height = UnitConvertor(297, Unit::Mm, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Letter:
width = UnitConvertor(8.5, Unit::Inch, paperUnit);
height = UnitConvertor(11, Unit::Inch, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Legal:
width = UnitConvertor(11, Unit::Inch, paperUnit);
height = UnitConvertor(17, Unit::Inch, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Roll24in:
width = UnitConvertor(24, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Roll30in:
width = UnitConvertor(30, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Roll36in:
width = UnitConvertor(36, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Roll42in:
width = UnitConvertor(42, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Roll44in:
width = UnitConvertor(44, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Custom:
width = ui->doubleSpinBoxPaperWidth->value();
height = ui->doubleSpinBoxPaperHeight->value();
return RoundTemplateSize(width, height);
default:
break;
}
return QSizeF();
}
//---------------------------------------------------------------------------------------------------------------------
QSizeF DialogLayoutSettings::RoundTemplateSize(qreal width, qreal height) const
{
qreal w = 0;
qreal h = 0;
switch (PaperUnit())
{
case Unit::Cm:
case Unit::Mm:
case Unit::Px:
w = qRound(width * 100.0) / 100.0;
h = qRound(height * 100.0) / 100.0;
return QSizeF(w, h);
case Unit::Inch:
w = qRound(width * 100000.0) / 100000.0;
h = qRound(height * 100000.0) / 100000.0;
return QSizeF(w, h);
default:
break;
}
return QSizeF(width, height);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
Unit DialogLayoutSettings::PaperUnit() const Unit DialogLayoutSettings::PaperUnit() const
{ {
@ -733,6 +819,8 @@ void DialogLayoutSettings::ReadSettings()
SetAutoCrop(settings->GetLayoutAutoCrop()); SetAutoCrop(settings->GetLayoutAutoCrop());
SetSaveLength(settings->GetLayoutSaveLength()); SetSaveLength(settings->GetLayoutSaveLength());
SetUnitePages(settings->GetLayoutUnitePages()); SetUnitePages(settings->GetLayoutUnitePages());
FindTemplate();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -58,7 +58,8 @@ public:
Roll30in, // Used also for showing icon Roll30in, // Used also for showing icon
Roll36in, Roll36in,
Roll42in, Roll42in,
Roll44in = 11}; Roll44in = 11,
Custom = 12};
explicit DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent = nullptr, bool disableSettings = false); explicit DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent = nullptr, bool disableSettings = false);
~DialogLayoutSettings(); ~DialogLayoutSettings();
@ -107,6 +108,7 @@ public slots:
void ConvertLayoutSize(); void ConvertLayoutSize();
void TemplateSelected(); void TemplateSelected();
void FindTemplate();
void PaperSizeChanged(); void PaperSizeChanged();
void Swap(bool checked); void Swap(bool checked);
@ -131,6 +133,8 @@ private:
void InitLayoutUnits(); void InitLayoutUnits();
void InitTemplates(); void InitTemplates();
QSizeF Template(); QSizeF Template();
QSizeF TemplateSize(const PaperSizeTemplate &tmpl) const;
QSizeF RoundTemplateSize(qreal width, qreal height) const;
Unit PaperUnit() const; Unit PaperUnit() const;
Unit LayoutUnit() const; Unit LayoutUnit() const;

View File

@ -63,6 +63,13 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="2"> <item row="1" column="2">
@ -215,6 +222,13 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBoxRotate"> <widget class="QGroupBox" name="groupBoxRotate">
<property name="title"> <property name="title">
@ -442,6 +456,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBoxCase"> <widget class="QGroupBox" name="groupBoxCase">
<property name="title"> <property name="title">