23 #include "kpmarginpage.h"
26 #include "marginwidget.h"
28 #include <tqgroupbox.h>
30 #include <tqprinter.h>
31 #include <tqpaintdevicemetrics.h>
33 #include <kiconloader.h>
34 #include <tdelocale.h>
36 #include <tdeglobal.h>
38 KPMarginPage::KPMarginPage(
KPrinter *prt, DrMain *driver, TQWidget *parent,
const char *name)
42 setTitle(i18n(
"Margins"));
45 TQGroupBox *box =
new TQGroupBox(1, TQt::Vertical, i18n(
"Margins"),
this);
46 m_margin =
new MarginWidget(box,
"MarginWidget", (m_printer != 0));
51 TQVBoxLayout *l0 =
new TQVBoxLayout(
this, 0, 10);
56 KPMarginPage::~KPMarginPage()
60 void KPMarginPage::initPageSize(
const TQString& ps,
bool landscape)
63 TQPrinter prt(TQPrinter::PrinterResolution);
65 prt.
setPageSize((TQPrinter::PageSize)(ps.isEmpty() ? TDEGlobal::locale()->pageSize() : ps.toInt()));
66 TQPaintDeviceMetrics metrics(&prt);
67 float w = metrics.width();
68 float h = metrics.height();
69 unsigned int it, il, ib, ir;
70 prt.
margins( &it, &il, &ib, &ir );
76 if (driver() && m_usedriver )
78 TQString pageSize(ps);
80 if (pageSize.isEmpty())
82 DrListOption *o = (DrListOption*)driver()->findOption(
"PageSize");
84 pageSize = o->get(
"default");
86 if (!pageSize.isEmpty())
88 DrPageSize *dps = driver()->findPageSize(pageSize);
92 h = dps->pageHeight();
93 mt = TQMAX( mt, dps->topMargin() );
94 ml = TQMAX( ml, dps->leftMargin() );
95 mb = TQMAX( mb, dps->bottomMargin() );
96 mr = TQMAX( mr, dps->rightMargin() );
100 m_margin->setPageSize(w, h);
101 m_margin->setOrientation(landscape ? KPrinter::Landscape : KPrinter::Portrait);
102 m_margin->setDefaultMargins( mt, mb, ml, mr );
103 m_margin->setCustomEnabled(
false);
106 void KPMarginPage::setOptions(
const TQMap<TQString,TQString>& opts)
108 TQString orient = opts[
"orientation-requested"];
109 bool land = (orient.isEmpty()? opts[
"kde-orientation"] ==
"Landscape" : orient ==
"4" || orient ==
"5");
110 TQString ps = opts[
"kde-printsize" ];
114 ps = opts[
"PageSize" ];
116 ps = opts[
"kde-pagesize"];
120 initPageSize(ps, land);
122 bool marginset(
false);
124 if (!(value=opts[
"kde-margin-top"]).isEmpty() && value.toFloat() != m_margin->top())
127 m_margin->setTop(value.toFloat());
129 if (!(value=opts[
"kde-margin-left"]).isEmpty() && value.toFloat() != m_margin->left())
132 m_margin->setLeft(value.toFloat());
134 if (!(value=opts[
"kde-margin-bottom"]).isEmpty() && value.toFloat() != m_margin->bottom())
137 m_margin->setBottom(value.toFloat());
139 if (!(value=opts[
"kde-margin-right"]).isEmpty() && value.toFloat() != m_margin->right())
142 m_margin->setRight(value.toFloat());
144 m_margin->setCustomEnabled(marginset);
147 void KPMarginPage::getOptions(TQMap<TQString,TQString>& opts,
bool )
149 if (m_margin->isCustomEnabled() )
151 opts[
"kde-margin-top"] = TQString::number(m_margin->top());
152 opts[
"kde-margin-left"] = TQString::number(m_margin->left());
153 opts[
"kde-margin-bottom"] = TQString::number(m_margin->bottom());
154 opts[
"kde-margin-right"] = TQString::number(m_margin->right());
158 opts.remove(
"kde-margin-top");
159 opts.remove(
"kde-margin-left");
160 opts.remove(
"kde-margin-bottom");
161 opts.remove(
"kde-margin-right");
This class is intended to be used as base class for customized print dialog page.
This class is the main interface to access the TDE print framework.
void setFullPage(bool)
See TQPrinter::setFullPage().
void setPageSize(PageSize, bool locking=false)
See TQPrinter::setPageSize().
TQSize margins() const
See TQPrinter::margins().