20 #include "marginwidget.h"
21 #include "marginpreview.h"
22 #include "marginvaluewidget.h"
25 #include <tqcombobox.h>
26 #include <tqcheckbox.h>
29 #include <tqwhatsthis.h>
30 #include <tdelocale.h>
31 #include <tdeglobal.h>
33 MarginWidget::MarginWidget(TQWidget *parent,
const char* name,
bool allowMetricUnit)
34 : TQWidget(parent, name), m_default(4, 0), m_pagesize( 2 )
37 TQString whatsThisTopMarginWidget = i18n(
" <qt> "
38 " <p><b>Top Margin</b></p>. "
39 " <p>This spinbox/text edit field lets you control the top margin of your printout if the printing "
40 " application does not define its margins internally. </p> "
41 " <p>The setting works for instance for ASCII text file printing, or for printing from KMail and "
42 " and Konqueror.. </p>"
43 " <p><b>Note:</b></p>This margin setting is not intended for KOffice or OpenOffice.org printing, "
44 " because these applications (or rather their users) are expected to do it by themselves. "
45 " It also does not work for PostScript or PDF file, which in most cases have their margins hardcoded "
49 " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
50 " with the CUPS commandline job option parameter:</em> "
52 " -o page-top=... # use values from \"0\" or higher. \"72\" is equal to 1 inch. "
57 TQString whatsThisBottomMarginWidget = i18n(
" <qt> "
58 " <p><b>Bottom Margin</b></p>. "
59 " <p>This spinbox/text edit field lets you control the bottom margin of your printout if the printing "
60 " application does not define its margins internally. </p> "
61 " <p>The setting works for instance for ASCII text file printing, or for printing from KMail and "
62 " and Konqueror. </p>"
63 " <p><b>Note:</b></p>This margin setting is not intended for KOffice or OpenOffice.org printing, "
64 " because these applications (or rather their users) are expected to do it by themselves. "
65 " It also does not work for PostScript or PDF file, which in most cases have their margins hardcoded "
69 " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
70 " with the CUPS commandline job option parameter:</em> "
72 " -o page-bottom=... # use values from \"0\" or higher. \"72\" is equal to 1 inch. "
76 TQString whatsThisLeftMarginWidget = i18n(
" <qt> "
77 " <p><b>Left Margin</b></p>. "
78 " <p>This spinbox/text edit field lets you control the left margin of your printout if the printing "
79 " application does not define its margins internally. </p> "
80 " <p>The setting works for instance for ASCII text file printing, or for printing from KMail and "
81 " and Konqueror. </p>"
82 " <p><b>Note:</b></p>This margin setting is not intended for KOffice or OpenOffice.org printing, "
83 " because these applications (or rather their users) are expected to do it by themselves. "
84 " It also does not work for PostScript or PDF file, which in most cases have their margins hardcoded "
88 " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
89 " with the CUPS commandline job option parameter:</em> "
91 " -o page-left=... # use values from \"0\" or higher. \"72\" is equal to 1 inch. "
95 TQString whatsThisRightMarginWidget = i18n(
" <qt> "
96 " <p><b>Right Margin</b></p>. "
97 " <p>This spinbox/text edit field lets you control the right margin of your printout if the printing "
98 " application does not define its margins internally. </p> "
99 " <p>The setting works for instance for ASCII text file printing, or for printing from KMail and "
100 " and Konqueror. </p>"
101 " <p><b>Note:</b></p>This margin setting is not intended for KOffice or OpenOffice.org printing, "
102 " because these applications (or rather their users) are expected to do it by themselves. "
103 " It also does not work for PostScript or PDF file, which in most cases have their margins hardcoded "
107 " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
108 " with the CUPS commandline job option parameter:</em> "
110 " -o page-right=... # use values from \"0\" or higher. \"72\" is equal to 1 inch. "
114 TQString whatsThisMeasurementUnitMarginWidget = i18n(
" <qt> "
115 " <p><b>Change Measurement Unit<b></p>. "
116 " <p>You can change the units of measurement for the page"
117 " margins here. Select from Millimeter, Centimeter, Inch or Pixels (1 pixel == 1/72 inch). "
121 TQString whatsThisCheckboxMarginWidget = i18n(
" <qt> "
122 " <p><b>Custom Margins Checkbox</b></p>. "
123 " <p>Enable this checkbox if you want to modify the margins of your printouts "
124 " <p>You can change margin settings in 4 ways: "
126 " <li>Edit the text fields. </li> "
127 " <li>Click spinbox arrows. </li> "
128 " <li>Scroll wheel of wheelmouses. </li> "
129 " <li>Drag margins in preview frame with mouse. </li> "
131 " <b>Note:</b> The margin setting does not work if you load such files directly into "
132 " kprinter, which have their print margins hardcoded internally, like as most "
133 " PDF or PostScript files. It works for all ASCII text files however. It also may not "
134 " work with non-TDE applications which fail to "
135 " fully utilize the TDEPrint framework, such as OpenOffice.org. </p> "
138 TQString whatsThisDragAndPreviewMarginWidget = i18n(
" <qt> "
139 " <p><b>\"Drag-your-Margins\" </p>. "
140 " <p>Use your mouse to drag and set each margin on this little preview window. </p> "
143 m_symetric = m_block =
false;
144 m_pagesize[ 0 ] = 595;
145 m_pagesize[ 1 ] = 842;
148 m_custom =
new TQCheckBox(i18n(
"&Use custom margins"),
this);
149 TQWhatsThis::add(m_custom, whatsThisCheckboxMarginWidget);
150 m_top =
new MarginValueWidget(0, 0.0,
this);
151 TQWhatsThis::add(m_top, whatsThisTopMarginWidget);
152 m_bottom =
new MarginValueWidget(m_top, 0.0,
this);
153 TQWhatsThis::add(m_bottom, whatsThisBottomMarginWidget);
154 m_left =
new MarginValueWidget(m_bottom, 0.0,
this);
155 TQWhatsThis::add(m_left, whatsThisLeftMarginWidget);
156 m_right =
new MarginValueWidget(m_left, 0.0,
this);
157 TQWhatsThis::add(m_right, whatsThisRightMarginWidget);
158 m_top->setLabel(i18n(
"&Top:"), TQt::AlignLeft|TQt::AlignVCenter);
159 m_bottom->setLabel(i18n(
"&Bottom:"), TQt::AlignLeft|TQt::AlignVCenter);
160 m_left->setLabel(i18n(
"Le&ft:"), TQt::AlignLeft|TQt::AlignVCenter);
161 m_right->setLabel(i18n(
"&Right:"), TQt::AlignLeft|TQt::AlignVCenter);
162 m_units =
new TQComboBox(
this);
163 TQWhatsThis::add(m_units, whatsThisMeasurementUnitMarginWidget);
164 m_units->insertItem(i18n(
"Pixels (1/72nd in)"));
165 if ( allowMetricUnit )
167 m_units->insertItem(i18n(
"Inches (in)"));
168 m_units->insertItem(i18n(
"Centimeters (cm)"));
169 m_units->insertItem( i18n(
"Millimeters (mm)" ) );
171 m_units->setCurrentItem(0);
172 connect(m_units, TQ_SIGNAL(activated(
int)), m_top, TQ_SLOT(setMode(
int)));
173 connect(m_units, TQ_SIGNAL(activated(
int)), m_bottom, TQ_SLOT(setMode(
int)));
174 connect(m_units, TQ_SIGNAL(activated(
int)), m_left, TQ_SLOT(setMode(
int)));
175 connect(m_units, TQ_SIGNAL(activated(
int)), m_right, TQ_SLOT(setMode(
int)));
176 m_preview =
new MarginPreview(
this);
177 TQWhatsThis::add(m_preview, whatsThisDragAndPreviewMarginWidget);
178 m_preview->setMinimumSize(60, 80);
179 m_preview->setPageSize(m_pagesize[ 0 ], m_pagesize[ 1 ]);
180 connect(m_preview, TQ_SIGNAL(marginChanged(
int,
float)), TQ_SLOT(slotMarginPreviewChanged(
int,
float)));
181 connect(m_top, TQ_SIGNAL(marginChanged(
float)), TQ_SLOT(slotMarginValueChanged()));
182 connect(m_bottom, TQ_SIGNAL(marginChanged(
float)), TQ_SLOT(slotMarginValueChanged()));
183 connect(m_left, TQ_SIGNAL(marginChanged(
float)), TQ_SLOT(slotMarginValueChanged()));
184 connect(m_right, TQ_SIGNAL(marginChanged(
float)), TQ_SLOT(slotMarginValueChanged()));
185 slotMarginValueChanged();
186 connect(m_custom, TQ_SIGNAL(toggled(
bool)), m_top, TQ_SLOT(setEnabled(
bool)));
187 connect(m_custom, TQ_SIGNAL(toggled(
bool)), m_left, TQ_SLOT(setEnabled(
bool)));
189 connect(m_custom, TQ_SIGNAL(toggled(
bool)), TQ_SLOT(slotCustomMarginsToggled(
bool)));
190 connect(m_custom, TQ_SIGNAL(toggled(
bool)), m_preview, TQ_SLOT(enableRubberBand(
bool)));
191 m_top->setEnabled(
false);
192 m_bottom->setEnabled(
false);
193 m_left->setEnabled(
false);
194 m_right->setEnabled(
false);
197 TQGridLayout *l3 =
new TQGridLayout(
this, 7, 2, 0, 10);
198 l3->addWidget(m_custom, 0, 0);
199 l3->addWidget(m_top, 1, 0);
200 l3->addWidget(m_bottom, 2, 0);
201 l3->addWidget(m_left, 3, 0);
202 l3->addWidget(m_right, 4, 0);
203 l3->addRowSpacing(5, 10);
204 l3->addWidget(m_units, 6, 0);
205 l3->addMultiCellWidget(m_preview, 0, 6, 1, 1);
207 if ( allowMetricUnit )
209 int mode = (TDEGlobal::locale()->measureSystem() == TDELocale::Metric ? 2 : 1);
210 m_top->setMode(mode);
211 m_bottom->setMode(mode);
212 m_left->setMode(mode);
213 m_right->setMode(mode);
214 m_units->setCurrentItem(mode);
218 MarginWidget::~MarginWidget()
222 void MarginWidget::slotCustomMarginsToggled(
bool b)
224 m_bottom->setEnabled(b && !m_symetric);
225 m_right->setEnabled(b && !m_symetric);
230 void MarginWidget::setSymetricMargins(
bool on)
232 if (on == m_symetric)
236 m_bottom->setEnabled(on && m_custom->isChecked());
237 m_right->setEnabled(on && m_custom->isChecked());
240 connect(m_top, TQ_SIGNAL(marginChanged(
float)), m_bottom, TQ_SLOT(setMargin(
float)));
241 connect(m_left, TQ_SIGNAL(marginChanged(
float)), m_right, TQ_SLOT(setMargin(
float)));
242 m_bottom->setMargin(m_top->margin());
243 m_right->setMargin(m_left->margin());
247 disconnect(m_top, 0, m_bottom, 0);
248 disconnect(m_left, 0, m_right, 0);
250 m_preview->setSymetric(on);
253 void MarginWidget::slotMarginValueChanged()
257 m_preview->setMargins(m_top->margin(), m_bottom->margin(), m_left->margin(), m_right->margin());
260 void MarginWidget::slotMarginPreviewChanged(
int type,
float value)
265 case MarginPreview::TMoving:
266 m_top->setMargin(value);
268 case MarginPreview::BMoving:
269 m_bottom->setMargin(value);
271 case MarginPreview::LMoving:
272 m_left->setMargin(value);
274 case MarginPreview::RMoving:
275 m_right->setMargin(value);
281 void MarginWidget::setPageSize(
float w,
float h)
284 int dpi = m_top->resolution();
288 m_preview->setPageSize((m_pagesize[ 1 ]*dpi)/72, (m_pagesize[ 0 ]*dpi)/72);
290 m_preview->setPageSize((m_pagesize[ 0 ]*dpi)/72, (m_pagesize[ 1 ]*dpi)/72);
293 float MarginWidget::top()
const
295 return m_top->margin();
298 float MarginWidget::bottom()
const
300 return m_bottom->margin();
303 float MarginWidget::left()
const
305 return m_left->margin();
308 float MarginWidget::right()
const
310 return m_right->margin();
313 void MarginWidget::setTop(
float value)
315 m_top->setMargin(value);
318 void MarginWidget::setBottom(
float value)
320 m_bottom->setMargin(value);
323 void MarginWidget::setLeft(
float value)
325 m_left->setMargin(value);
328 void MarginWidget::setRight(
float value)
330 m_right->setMargin(value);
333 void MarginWidget::setResolution(
int dpi)
335 m_top->setResolution(dpi);
336 m_bottom->setResolution(dpi);
337 m_left->setResolution(dpi);
338 m_right->setResolution(dpi);
341 void MarginWidget::setDefaultMargins(
float t,
float b,
float l,
float r)
343 int dpi = m_top->resolution();
344 m_default[0] = (t*dpi)/72;
345 m_default[1] = (b*dpi)/72;
346 m_default[2] = (l*dpi)/72;
347 m_default[3] = (r*dpi)/72;
348 if (!m_custom->isChecked())
352 void MarginWidget::resetDefault()
354 m_top->setMargin(m_landscape ? m_default[2] : m_default[0]);
355 m_bottom->setMargin(m_landscape ? m_default[3] : m_default[1]);
356 m_left->setMargin(m_landscape ? m_default[1] : m_default[2]);
357 m_right->setMargin(m_landscape ? m_default[0] : m_default[3]);
360 void MarginWidget::setCustomEnabled(
bool on)
362 m_custom->setChecked(on);
365 bool MarginWidget::isCustomEnabled()
const
367 return m_custom->isChecked();
370 void MarginWidget::setOrientation(
int orient)
372 m_landscape = (orient == KPrinter::Landscape);
373 setPageSize(m_pagesize[ 0 ], m_pagesize[ 1 ]);
376 #include "marginwidget.moc"