• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
marginwidget.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001-2002 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include "marginwidget.h"
21 #include "marginpreview.h"
22 #include "marginvaluewidget.h"
23 #include "kprinter.h"
24 
25 #include <tqcombobox.h>
26 #include <tqcheckbox.h>
27 #include <tqlayout.h>
28 #include <tqlabel.h>
29 #include <tqwhatsthis.h>
30 #include <tdelocale.h>
31 #include <tdeglobal.h>
32 
33 MarginWidget::MarginWidget(TQWidget *parent, const char* name, bool allowMetricUnit)
34 : TQWidget(parent, name), m_default(4, 0), m_pagesize( 2 )
35 {
36  //WhatsThis strings.... (added by pfeifle@kde.org)
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 "
46  " internally.</p> "
47  " <br> "
48  " <hr> "
49  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
50  " with the CUPS commandline job option parameter:</em> "
51  " <pre>"
52  " -o page-top=... # use values from \"0\" or higher. \"72\" is equal to 1 inch. "
53  " </pre>"
54  " </p> "
55  " </qt>" );
56 
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 "
66  " internally.</p> "
67  " <br> "
68  " <hr> "
69  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
70  " with the CUPS commandline job option parameter:</em> "
71  " <pre>"
72  " -o page-bottom=... # use values from \"0\" or higher. \"72\" is equal to 1 inch. "
73  " </pre>"
74  " </qt>" );
75 
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 "
85  " internally.</p> "
86  " <br> "
87  " <hr> "
88  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
89  " with the CUPS commandline job option parameter:</em> "
90  " <pre>"
91  " -o page-left=... # use values from \"0\" or higher. \"72\" is equal to 1 inch. "
92  " </pre>"
93  " </qt>" );
94 
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 "
104  " internally.</p> "
105  " <br> "
106  " <hr> "
107  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
108  " with the CUPS commandline job option parameter:</em> "
109  " <pre>"
110  " -o page-right=... # use values from \"0\" or higher. \"72\" is equal to 1 inch. "
111  " </pre>"
112  " </qt>" );
113 
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). "
118  " </p> "
119  " </qt>" );
120 
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: "
125  " <ul> "
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> "
130  " </ul> "
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> "
136  " </qt>" );
137 
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> "
141  " </qt>" );
142 
143  m_symetric = m_block = false;
144  m_pagesize[ 0 ] = 595;
145  m_pagesize[ 1 ] = 842;
146  m_landscape = false;
147 
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 )
166  {
167  m_units->insertItem(i18n("Inches (in)"));
168  m_units->insertItem(i18n("Centimeters (cm)"));
169  m_units->insertItem( i18n( "Millimeters (mm)" ) );
170  }
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)));
188  //connect(m_custom, TQ_SIGNAL(toggled(bool)), m_units, 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);
195  //m_units->setEnabled(false);
196 
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);
206 
207  if ( allowMetricUnit )
208  {
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);
215  }
216 }
217 
218 MarginWidget::~MarginWidget()
219 {
220 }
221 
222 void MarginWidget::slotCustomMarginsToggled(bool b)
223 {
224  m_bottom->setEnabled(b && !m_symetric);
225  m_right->setEnabled(b && !m_symetric);
226  if (!b)
227  resetDefault();
228 }
229 
230 void MarginWidget::setSymetricMargins(bool on)
231 {
232  if (on == m_symetric)
233  return;
234 
235  m_symetric = on;
236  m_bottom->setEnabled(on && m_custom->isChecked());
237  m_right->setEnabled(on && m_custom->isChecked());
238  if (on)
239  {
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());
244  }
245  else
246  {
247  disconnect(m_top, 0, m_bottom, 0);
248  disconnect(m_left, 0, m_right, 0);
249  }
250  m_preview->setSymetric(on);
251 }
252 
253 void MarginWidget::slotMarginValueChanged()
254 {
255  if (m_block)
256  return;
257  m_preview->setMargins(m_top->margin(), m_bottom->margin(), m_left->margin(), m_right->margin());
258 }
259 
260 void MarginWidget::slotMarginPreviewChanged(int type, float value)
261 {
262  m_block = true;
263  switch (type)
264  {
265  case MarginPreview::TMoving:
266  m_top->setMargin(value);
267  break;
268  case MarginPreview::BMoving:
269  m_bottom->setMargin(value);
270  break;
271  case MarginPreview::LMoving:
272  m_left->setMargin(value);
273  break;
274  case MarginPreview::RMoving:
275  m_right->setMargin(value);
276  break;
277  }
278  m_block = false;
279 }
280 
281 void MarginWidget::setPageSize(float w, float h)
282 {
283  // takes care of the orientation and the resolution
284  int dpi = m_top->resolution();
285  m_pagesize[ 0 ] = w;
286  m_pagesize[ 1 ] = h;
287  if (m_landscape)
288  m_preview->setPageSize((m_pagesize[ 1 ]*dpi)/72, (m_pagesize[ 0 ]*dpi)/72);
289  else
290  m_preview->setPageSize((m_pagesize[ 0 ]*dpi)/72, (m_pagesize[ 1 ]*dpi)/72);
291 }
292 
293 float MarginWidget::top() const
294 {
295  return m_top->margin();
296 }
297 
298 float MarginWidget::bottom() const
299 {
300  return m_bottom->margin();
301 }
302 
303 float MarginWidget::left() const
304 {
305  return m_left->margin();
306 }
307 
308 float MarginWidget::right() const
309 {
310  return m_right->margin();
311 }
312 
313 void MarginWidget::setTop(float value)
314 {
315  m_top->setMargin(value);
316 }
317 
318 void MarginWidget::setBottom(float value)
319 {
320  m_bottom->setMargin(value);
321 }
322 
323 void MarginWidget::setLeft(float value)
324 {
325  m_left->setMargin(value);
326 }
327 
328 void MarginWidget::setRight(float value)
329 {
330  m_right->setMargin(value);
331 }
332 
333 void MarginWidget::setResolution(int dpi)
334 {
335  m_top->setResolution(dpi);
336  m_bottom->setResolution(dpi);
337  m_left->setResolution(dpi);
338  m_right->setResolution(dpi);
339 }
340 
341 void MarginWidget::setDefaultMargins(float t, float b, float l, float r)
342 {
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())
349  resetDefault();
350 }
351 
352 void MarginWidget::resetDefault()
353 {
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]);
358 }
359 
360 void MarginWidget::setCustomEnabled(bool on)
361 {
362  m_custom->setChecked(on);
363 }
364 
365 bool MarginWidget::isCustomEnabled() const
366 {
367  return m_custom->isChecked();
368 }
369 
370 void MarginWidget::setOrientation(int orient)
371 {
372  m_landscape = (orient == KPrinter::Landscape);
373  setPageSize(m_pagesize[ 0 ], m_pagesize[ 1 ]);
374 }
375 
376 #include "marginwidget.moc"

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.1
This website is maintained by Timothy Pearson.