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

kdeprint

kpmarginpage.cpp
00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
00004  *
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Library General Public
00008  *  License version 2 as published by the Free Software Foundation.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Library General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Library General Public License
00016  *  along with this library; see the file COPYING.LIB.  If not, write to
00017  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  *  Boston, MA 02110-1301, USA.
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 <tqgroupbox.h>
00029 #include <tqlayout.h>
00030 #include <tqprinter.h>
00031 #include <tqpaintdevicemetrics.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, TQWidget *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     TQGroupBox  *box = new TQGroupBox(1, Qt::Vertical, i18n("Margins"), this);
00046     m_margin = new MarginWidget(box, "MarginWidget", (m_printer != 0));
00047     //m_margin->setSymetricMargins(true);
00048     //if (m_printer)
00049     //  m_margin->setResolution(m_printer->resolution());
00050 
00051     TQVBoxLayout    *l0 = new TQVBoxLayout(this, 0, 10);
00052     l0->addWidget(box);
00053     l0->addStretch(1);
00054 }
00055 
00056 KPMarginPage::~KPMarginPage()
00057 {
00058 }
00059 
00060 void KPMarginPage::initPageSize(const TQString& ps, bool landscape)
00061 {
00062     // first retrieve the Qt values for page size and margins
00063     TQPrinter   prt(TQPrinter::PrinterResolution);
00064     prt.setFullPage(true);
00065     prt.setPageSize((TQPrinter::PageSize)(ps.isEmpty() ? KGlobal::locale()->pageSize() : ps.toInt()));
00066     TQPaintDeviceMetrics    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 TQMap<TQString,TQString>& opts)
00107 {
00108     QString orient = opts["orientation-requested"];
00109     bool    land = (orient.isEmpty()? opts["kde-orientation"] == "Landscape" : orient == "4" || orient == "5");
00110     TQString 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(TQMap<TQString,TQString>& opts, bool /* incldef */)
00148 {
00149     if (m_margin->isCustomEnabled() /*|| incldef*/)
00150     {
00151         opts["kde-margin-top"] = TQString::number(m_margin->top());
00152         opts["kde-margin-left"] = TQString::number(m_margin->left());
00153         opts["kde-margin-bottom"] = TQString::number(m_margin->bottom());
00154         opts["kde-margin-right"] = TQString::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 }

kdeprint

Skip menu "kdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdeprint

Skip menu "kdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeprint by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |