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

tdeprint

  • tdeprint
marginvaluewidget.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 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 "marginvaluewidget.h"
21 
22 #include <math.h>
23 
24 MarginValueWidget::MarginValueWidget(KNumInput *below, double value, TQWidget *parent, const char *name)
25 : KDoubleNumInput(below, value, parent, name)
26 {
27  m_mode = Pixels;
28  m_block = false;
29  setPrecision(0);
30  m_dpi = 72.0;
31  m_margin = ( float )value;
32  setMode(m_mode);
33  setRange(0, 999, 1, false);
34  connect(this, TQT_SIGNAL(valueChanged(double)), TQT_SLOT(slotValueChanged(double)));
35 }
36 
37 float MarginValueWidget::margin()
38 {
39  // Force synchronization
40  m_margin = toPixel(value(), m_mode);
41  return m_margin;
42 }
43 
44 void MarginValueWidget::setMargin(float m)
45 {
46  m_margin = m;
47  double v = toValue(m, m_mode);
48  m_block = true;
49  setValue(v);
50  m_block = false;
51  emit marginChanged( m_margin );
52 }
53 
54 float MarginValueWidget::toPixel(double value, int mode)
55 {
56  switch (mode)
57  {
58  default:
59  case Pixels: return (float)value;
60  case IN: return (float)(value * m_dpi);
61  case CM: return (float)(value * m_dpi / 2.54);
62  case MM: return (float)(value * m_dpi / 25.4);
63  }
64 }
65 
66 double MarginValueWidget::toValue(float pix, int mode)
67 {
68  switch (mode)
69  {
70  default:
71  case Pixels:
72  return (double)pix;
73  case IN:
74  return (double(pix) / m_dpi);
75  case CM:
76  return (double(pix) * 2.54 / m_dpi);
77  case MM:
78  return ( double( pix ) * 25.4 / m_dpi );
79  }
80 }
81 
82 void MarginValueWidget::slotValueChanged(double v)
83 {
84  if (!m_block)
85  {
86  m_margin = toPixel( v, m_mode );
87  emit marginChanged(margin());
88  }
89 }
90 
91 void MarginValueWidget::setMode(int m)
92 {
93  if (m != m_mode)
94  {
95  m_block = true;
96  m_mode = m;
97  double v = toValue(m_margin, m);
98  if (m == Pixels)
99  {
100  setPrecision(0);
101  setRange(0.0, 999.0, 1.0, false);
102  }
103  else
104  {
105  setPrecision(3);
106  setRange(0.0, 999.0, 0.01, false);
107  }
108  setValue(v);
109  m_block = false;
110  }
111 }
112 
113 void MarginValueWidget::setResolution(int dpi)
114 {
115  m_dpi = dpi;
116  m_block = true;
117  setMargin(m_margin);
118  m_block = false;
119 }
120 
121 int MarginValueWidget::resolution() const
122 {
123  return (int)(m_dpi+0.5);
124 }
125 
126 #include "marginvaluewidget.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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.8.8
This website is maintained by Timothy Pearson.