Seamly2D
Code documentation
vabstractlayoutdialog.cpp
Go to the documentation of this file.
2 
3 #include "../core/vapplication.h"
4 
5 
6 //must be the same order as PaperSizeTemplate constants
8  VAbstractLayoutDialog::FormatsVector () << QLatin1String("A0")
9  << QLatin1String("A1")
10  << QLatin1String("A2")
11  << QLatin1String("A3")
12  << QLatin1String("A4")
13  << QApplication::translate("DialogLayoutSettings", "Letter")
14  << QApplication::translate("DialogLayoutSettings", "Legal")
15  << QApplication::translate("DialogLayoutSettings", "Roll 24in")
16  << QApplication::translate("DialogLayoutSettings", "Roll 30in")
17  << QApplication::translate("DialogLayoutSettings", "Roll 36in")
18  << QApplication::translate("DialogLayoutSettings", "Roll 42in")
19  << QApplication::translate("DialogLayoutSettings", "Roll 44in")
20  << QApplication::translate("DialogLayoutSettings", "Custom");
21 
22 //---------------------------------------------------------------------------------------------------------------------
23 
24 VAbstractLayoutDialog::VAbstractLayoutDialog(QWidget *parent) : QDialog(parent)
25 {
26 }
27 
28 //---------------------------------------------------------------------------------------------------------------------
29 
30 void VAbstractLayoutDialog::initTemplates(QComboBox *comboBoxTemplates)
31 {
32  SCASSERT(comboBoxTemplates != nullptr)
33  const QIcon icoPaper("://icon/16x16/template.png");
34  const QIcon icoRoll("://icon/16x16/roll.png");
35  const QString pdi = QString("(%1ppi)").arg(PrintDPI);
36 
37  auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
38  foreach(const auto& v, VAbstractLayoutDialog::pageFormatNames)
39  {
40  if (cntr <= static_cast<int>(PaperSizeTemplate::Legal))
41  {
42  comboBoxTemplates->addItem(icoPaper, v+" "+pdi, QVariant(cntr++));
43  }
44  else if (cntr <= static_cast<int>(PaperSizeTemplate::Roll44in))
45  {
46  comboBoxTemplates->addItem(icoRoll, v+" "+pdi, QVariant(cntr++));
47  }
48  else
49  {
50  comboBoxTemplates->addItem(v+" "+pdi, QVariant(cntr++));
51  }
52  }
53  comboBoxTemplates->setCurrentIndex(-1);
54 }
55 
56 
57 //---------------------------------------------------------------------------------------------------------------------
58 /**
59  * @brief DialogLayoutSettings::TemplateSize
60  * @param tmpl
61  * @param unit
62  * @return
63  */
64 QSizeF VAbstractLayoutDialog::getTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const
65 {
66  qreal width = 0;
67  qreal height = 0;
68 
69  switch (tmpl)
70  {
72  width = UnitConvertor(841, Unit::Mm, unit);
73  height = UnitConvertor(1189, Unit::Mm, unit);
74  return RoundTemplateSize(width, height, unit);
76  width = UnitConvertor(594, Unit::Mm, unit);
77  height = UnitConvertor(841, Unit::Mm, unit);
78  return RoundTemplateSize(width, height, unit);
80  width = UnitConvertor(420, Unit::Mm, unit);
81  height = UnitConvertor(594, Unit::Mm, unit);
82  return RoundTemplateSize(width, height, unit);
84  width = UnitConvertor(297, Unit::Mm, unit);
85  height = UnitConvertor(420, Unit::Mm, unit);
86  return RoundTemplateSize(width, height, unit);
88  width = UnitConvertor(210, Unit::Mm, unit);
89  height = UnitConvertor(297, Unit::Mm, unit);
90  return RoundTemplateSize(width, height, unit);
92  width = UnitConvertor(8.5, Unit::Inch, unit);
93  height = UnitConvertor(11, Unit::Inch, unit);
94  return RoundTemplateSize(width, height, unit);
96  width = UnitConvertor(8.5, Unit::Inch, unit);
97  height = UnitConvertor(14, Unit::Inch, unit);
98  return RoundTemplateSize(width, height, unit);
100  width = UnitConvertor(24, Unit::Inch, unit);
101  height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit);
102  return RoundTemplateSize(width, height, unit);
104  width = UnitConvertor(30, Unit::Inch, unit);
105  height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit);
106  return RoundTemplateSize(width, height, unit);
108  width = UnitConvertor(36, Unit::Inch, unit);
109  height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit);
110  return RoundTemplateSize(width, height, unit);
112  width = UnitConvertor(42, Unit::Inch, unit);
113  height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit);
114  return RoundTemplateSize(width, height, unit);
116  width = UnitConvertor(44, Unit::Inch, unit);
117  height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit);
118  return RoundTemplateSize(width, height, unit);
119  default:
120  break;
121  }
122  return QSizeF();
123 }
124 
125 //---------------------------------------------------------------------------------------------------------------------
126 QSizeF VAbstractLayoutDialog::RoundTemplateSize(qreal width, qreal height, Unit unit) const
127 {
128  qreal w = 0;
129  qreal h = 0;
130 
131  switch (unit)
132  {
133  case Unit::Cm:
134  case Unit::Mm:
135  case Unit::Px:
136  w = qRound(width * 100.0) / 100.0;
137  h = qRound(height * 100.0) / 100.0;
138  return QSizeF(w, h);
139  case Unit::Inch:
140  w = qRound(width * 100000.0) / 100000.0;
141  h = qRound(height * 100000.0) / 100000.0;
142  return QSizeF(w, h);
143  default:
144  break;
145  }
146 
147  return QSizeF(width, height);
148 }
149 
150 
void initTemplates(QComboBox *comboBoxTemplates)
QSizeF RoundTemplateSize(qreal width, qreal height, Unit unit) const
QSizeF getTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const
DialogLayoutSettings::TemplateSize.
static const FormatsVector pageFormatNames
VAbstractLayoutDialog(QWidget *parent=nullptr)
const qreal PrintDPI
Definition: def.cpp:228
qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
Definition: def.cpp:269
#define SCASSERT(cond)
Definition: def.h:317
Unit
Definition: def.h:105
#define QIMAGE_MAX
Definition: def.h:298
#define translate(context, source)
Definition: vcmdexport.cpp:41