20 #include "marginvaluewidget.h"
24 MarginValueWidget::MarginValueWidget(KNumInput *below,
double value, TQWidget *parent,
const char *name)
25 : KDoubleNumInput(below, value, parent, name)
31 m_margin = ( float )value;
33 setRange(0, 999, 1,
false);
34 connect(
this, TQ_SIGNAL(valueChanged(
double)), TQ_SLOT(slotValueChanged(
double)));
37 float MarginValueWidget::margin()
40 m_margin = toPixel(value(), m_mode);
44 void MarginValueWidget::setMargin(
float m)
47 double v = toValue(m, m_mode);
51 emit marginChanged( m_margin );
54 float MarginValueWidget::toPixel(
double value,
int mode)
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);
66 double MarginValueWidget::toValue(
float pix,
int mode)
74 return (
double(pix) / m_dpi);
76 return (
double(pix) * 2.54 / m_dpi);
78 return (
double( pix ) * 25.4 / m_dpi );
82 void MarginValueWidget::slotValueChanged(
double v)
86 m_margin = toPixel( v, m_mode );
87 emit marginChanged(margin());
91 void MarginValueWidget::setMode(
int m)
97 double v = toValue(m_margin, m);
101 setRange(0.0, 999.0, 1.0,
false);
106 setRange(0.0, 999.0, 0.01,
false);
113 void MarginValueWidget::setResolution(
int dpi)
121 int MarginValueWidget::resolution()
const
123 return (
int)(m_dpi+0.5);
126 #include "marginvaluewidget.moc"