kpmarginpage.cpp
00001
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 float w( -1 ), h( -1 );
00063 float mt( 36 ), mb( mt ), ml( 24 ), mr( ml );
00064 QString m_currentps(ps);
00065 if (driver() && m_usedriver )
00066 {
00067 if (m_currentps.isEmpty())
00068 {
00069 DrListOption *o = (DrListOption*)driver()->findOption("PageSize");
00070 if (o)
00071 m_currentps = o->get("default");
00072 }
00073 if (!m_currentps.isEmpty())
00074 {
00075 DrPageSize *ps = driver()->findPageSize(m_currentps);
00076 if (ps)
00077 {
00078 w = ps->pageWidth();
00079 h = ps->pageHeight();
00080 mt = ps->topMargin();
00081 ml = ps->leftMargin();
00082 mb = ps->bottomMargin();
00083 mr = ps->rightMargin();
00084 }
00085 }
00086 }
00087 else
00088 {
00089
00090 QPrinter prt(QPrinter::PrinterResolution);
00091 prt.setFullPage(true);
00092 prt.setPageSize((QPrinter::PageSize)(m_currentps.isEmpty() ? KGlobal::locale()->pageSize() : ps.toInt()));
00093 QPaintDeviceMetrics metrics(&prt);
00094 w = metrics.width();
00095 h = metrics.height();
00096 unsigned int it, il, ib, ir;
00097 prt.margins( &it, &il, &ib, &ir );
00098 mt = it;
00099 ml = il;
00100 mb = ib;
00101 mr = ir;
00102 }
00103 m_margin->setPageSize(w, h);
00104 m_margin->setOrientation(landscape ? KPrinter::Landscape : KPrinter::Portrait);
00105 m_margin->setDefaultMargins( mt, mb, ml, mr );
00106 m_margin->setCustomEnabled(false);
00107 }
00108
00109 void KPMarginPage::setOptions(const QMap<QString,QString>& opts)
00110 {
00111 QString orient = opts["orientation-requested"];
00112 bool land = (orient.isEmpty()? opts["kde-orientation"] == "Landscape" : orient == "4" || orient == "5");
00113 QString ps = opts[ "kde-printsize" ];
00114 if ( ps.isEmpty() )
00115 {
00116 m_usedriver = true;
00117 ps = opts[ "PageSize" ];
00118 if (ps.isEmpty())
00119 ps = opts["kde-pagesize"];
00120 }
00121 else
00122 m_usedriver = false;
00123 initPageSize(ps, land);
00124
00125 bool marginset(false);
00126 QString value;
00127 if (!(value=opts["kde-margin-top"]).isEmpty() && value.toFloat() != m_margin->top())
00128 {
00129 marginset = true;
00130 m_margin->setTop(value.toFloat());
00131 }
00132 if (!(value=opts["kde-margin-left"]).isEmpty() && value.toFloat() != m_margin->left())
00133 {
00134 marginset = true;
00135 m_margin->setLeft(value.toFloat());
00136 }
00137 if (!(value=opts["kde-margin-bottom"]).isEmpty() && value.toFloat() != m_margin->bottom())
00138 {
00139 marginset = true;
00140 m_margin->setBottom(value.toFloat());
00141 }
00142 if (!(value=opts["kde-margin-right"]).isEmpty() && value.toFloat() != m_margin->right())
00143 {
00144 marginset = true;
00145 m_margin->setRight(value.toFloat());
00146 }
00147 m_margin->setCustomEnabled(marginset);
00148 }
00149
00150 void KPMarginPage::getOptions(QMap<QString,QString>& opts, bool )
00151 {
00152 if (m_margin->isCustomEnabled() )
00153 {
00154 opts["kde-margin-top"] = QString::number(m_margin->top());
00155 opts["kde-margin-left"] = QString::number(m_margin->left());
00156 opts["kde-margin-bottom"] = QString::number(m_margin->bottom());
00157 opts["kde-margin-right"] = QString::number(m_margin->right());
00158 }
00159 else
00160 {
00161 opts.remove("kde-margin-top");
00162 opts.remove("kde-margin-left");
00163 opts.remove("kde-margin-bottom");
00164 opts.remove("kde-margin-right");
00165 }
00166 }
This file is part of the documentation for kdeprint Library Version 3.3.1.