kpmarginpage.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include "kpmarginpage.h"
00024 #include "kprinter.h"
00025 #include "driver.h"
00026 #include "marginwidget.h"
00027
00028 #include <qgroupbox.h>
00029 #include <qlayout.h>
00030 #include <qprinter.h>
00031 #include <qpaintdevicemetrics.h>
00032
00033 #include <kiconloader.h>
00034 #include <klocale.h>
00035 #include <kdebug.h>
00036 #include <kglobal.h>
00037
00038 KPMarginPage::KPMarginPage(KPrinter *prt, DrMain *driver, QWidget *parent, const char *name)
00039 : KPrintDialogPage(0, driver, parent, name)
00040 {
00041 m_printer = prt;
00042 setTitle(i18n("Margins"));
00043 m_usedriver = true;
00044
00045 QGroupBox *box = new QGroupBox(1, Qt::Vertical, i18n("Margins"), this);
00046 m_margin = new MarginWidget(box, "MarginWidget", (m_printer != 0));
00047
00048
00049
00050
00051 QVBoxLayout *l0 = new QVBoxLayout(this, 0, 10);
00052 l0->addWidget(box);
00053 l0->addStretch(1);
00054 }
00055
00056 KPMarginPage::~KPMarginPage()
00057 {
00058 }
00059
00060 void KPMarginPage::initPageSize(const QString& ps, bool landscape)
00061 {
00062
00063 QPrinter prt(QPrinter::PrinterResolution);
00064 prt.setFullPage(true);
00065 prt.setPageSize((QPrinter::PageSize)(ps.isEmpty() ? KGlobal::locale()->pageSize() : ps.toInt()));
00066 QPaintDeviceMetrics metrics(&prt);
00067 float w = metrics.width();
00068 float h = metrics.height();
00069 unsigned int it, il, ib, ir;
00070 prt.margins( &it, &il, &ib, &ir );
00071 float mt = it;
00072 float ml = il;
00073 float mb = ib;
00074 float mr = ir;
00075
00076 if (driver() && m_usedriver )
00077 {
00078 QString pageSize(ps);
00079
00080 if (pageSize.isEmpty())
00081 {
00082 DrListOption *o = (DrListOption*)driver()->findOption("PageSize");
00083 if (o)
00084 pageSize = o->get("default");
00085 }
00086 if (!pageSize.isEmpty())
00087 {
00088 DrPageSize *dps = driver()->findPageSize(pageSize);
00089 if (dps)
00090 {
00091 w = dps->pageWidth();
00092 h = dps->pageHeight();
00093 mt = QMAX( mt, dps->topMargin() );
00094 ml = QMAX( ml, dps->leftMargin() );
00095 mb = QMAX( mb, dps->bottomMargin() );
00096 mr = QMAX( mr, dps->rightMargin() );
00097 }
00098 }
00099 }
00100 m_margin->setPageSize(w, h);
00101 m_margin->setOrientation(landscape ? KPrinter::Landscape : KPrinter::Portrait);
00102 m_margin->setDefaultMargins( mt, mb, ml, mr );
00103 m_margin->setCustomEnabled(false);
00104 }
00105
00106 void KPMarginPage::setOptions(const QMap<QString,QString>& opts)
00107 {
00108 QString orient = opts["orientation-requested"];
00109 bool land = (orient.isEmpty()? opts["kde-orientation"] == "Landscape" : orient == "4" || orient == "5");
00110 QString ps = opts[ "kde-printsize" ];
00111 if ( ps.isEmpty() )
00112 {
00113 m_usedriver = true;
00114 ps = opts[ "PageSize" ];
00115 if (ps.isEmpty())
00116 ps = opts["kde-pagesize"];
00117 }
00118 else
00119 m_usedriver = false;
00120 initPageSize(ps, land);
00121
00122 bool marginset(false);
00123 QString value;
00124 if (!(value=opts["kde-margin-top"]).isEmpty() && value.toFloat() != m_margin->top())
00125 {
00126 marginset = true;
00127 m_margin->setTop(value.toFloat());
00128 }
00129 if (!(value=opts["kde-margin-left"]).isEmpty() && value.toFloat() != m_margin->left())
00130 {
00131 marginset = true;
00132 m_margin->setLeft(value.toFloat());
00133 }
00134 if (!(value=opts["kde-margin-bottom"]).isEmpty() && value.toFloat() != m_margin->bottom())
00135 {
00136 marginset = true;
00137 m_margin->setBottom(value.toFloat());
00138 }
00139 if (!(value=opts["kde-margin-right"]).isEmpty() && value.toFloat() != m_margin->right())
00140 {
00141 marginset = true;
00142 m_margin->setRight(value.toFloat());
00143 }
00144 m_margin->setCustomEnabled(marginset);
00145 }
00146
00147 void KPMarginPage::getOptions(QMap<QString,QString>& opts, bool )
00148 {
00149 if (m_margin->isCustomEnabled() )
00150 {
00151 opts["kde-margin-top"] = QString::number(m_margin->top());
00152 opts["kde-margin-left"] = QString::number(m_margin->left());
00153 opts["kde-margin-bottom"] = QString::number(m_margin->bottom());
00154 opts["kde-margin-right"] = QString::number(m_margin->right());
00155 }
00156 else
00157 {
00158 opts.remove("kde-margin-top");
00159 opts.remove("kde-margin-left");
00160 opts.remove("kde-margin-bottom");
00161 opts.remove("kde-margin-right");
00162 }
00163 }
|