kdeprint Library API Documentation

kptextpage.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  *  Boston, MA 02111-1307, USA.
00018  **/
00019 
00020 #include "kptextpage.h"
00021 #include "marginwidget.h"
00022 #include "driver.h"
00023 #include "kprinter.h"
00024 
00025 #include <qbuttongroup.h>
00026 #include <qgroupbox.h>
00027 #include <qlayout.h>
00028 #include <qlabel.h>
00029 #include <qradiobutton.h>
00030 #include <knuminput.h>
00031 #include <klocale.h>
00032 #include <kiconloader.h>
00033 #include <kseparator.h>
00034 #include <kdebug.h>
00035 
00036 KPTextPage::KPTextPage(DrMain *driver, QWidget *parent, const char *name)
00037 : KPrintDialogPage(0, driver, parent, name)
00038 {
00039     setTitle(i18n("Text"));
00040     m_block = false;
00041 
00042     QGroupBox   *formatbox = new QGroupBox(0, Qt::Vertical, i18n("Text Format"), this);
00043     QGroupBox   *prettybox = new QGroupBox(0, Qt::Vertical, i18n("Syntax Highlighting"), this);
00044     QGroupBox   *marginbox = new QGroupBox(0, Qt::Vertical, i18n("Margins"), this);
00045 
00046     m_cpi = new KIntNumInput(10, formatbox);
00047     m_cpi->setLabel(i18n("&Chars per inch:"), Qt::AlignLeft|Qt::AlignVCenter);
00048     m_cpi->setRange(1, 999, 1, false);
00049     m_lpi = new KIntNumInput(m_cpi, 6, formatbox);
00050     m_lpi->setLabel(i18n("&Lines per inch:"), Qt::AlignLeft|Qt::AlignVCenter);
00051     m_lpi->setRange(1, 999, 1, false);
00052     m_columns = new KIntNumInput(m_lpi, 1, formatbox);
00053     m_columns->setLabel(i18n("C&olumns:"), Qt::AlignLeft|Qt::AlignVCenter);
00054     m_columns->setRange(1, 10, 1, false);
00055     KSeparator  *sep = new KSeparator(Qt::Horizontal, formatbox);
00056     connect(m_columns, SIGNAL(valueChanged(int)), SLOT(slotColumnsChanged(int)));
00057 
00058     m_prettypix = new QLabel(prettybox);
00059     m_prettypix->setAlignment(Qt::AlignCenter);
00060     QRadioButton    *off = new QRadioButton(i18n("&Disabled"), prettybox);
00061     QRadioButton    *on = new QRadioButton(i18n("&Enabled"), prettybox);
00062     m_prettyprint = new QButtonGroup(prettybox);
00063     m_prettyprint->hide();
00064     m_prettyprint->insert(off, 0);
00065     m_prettyprint->insert(on, 1);
00066     m_prettyprint->setButton(0);
00067     connect(m_prettyprint, SIGNAL(clicked(int)), SLOT(slotPrettyChanged(int)));
00068     slotPrettyChanged(0);
00069 
00070     m_margin = new MarginWidget(marginbox);
00071     m_margin->setPageSize(595, 842);
00072 
00073     QGridLayout *l0 = new QGridLayout(this, 2, 2, 0, 10);
00074     l0->addWidget(formatbox, 0, 0);
00075     l0->addWidget(prettybox, 0, 1);
00076     l0->addMultiCellWidget(marginbox, 1, 1, 0, 1);
00077     QVBoxLayout *l1 = new QVBoxLayout(formatbox->layout(), 5);
00078     l1->addWidget(m_cpi);
00079     l1->addWidget(m_lpi);
00080     l1->addWidget(sep);
00081     l1->addWidget(m_columns);
00082     QGridLayout *l2 = new QGridLayout(prettybox->layout(), 2, 2, 10);
00083     l2->addWidget(off, 0, 0);
00084     l2->addWidget(on, 1, 0);
00085     l2->addMultiCellWidget(m_prettypix, 0, 1, 1, 1);
00086     QVBoxLayout *l3 = new QVBoxLayout(marginbox->layout(), 10);
00087     l3->addWidget(m_margin);
00088 }
00089 
00090 KPTextPage::~KPTextPage()
00091 {
00092 }
00093 
00094 void KPTextPage::setOptions(const QMap<QString,QString>& opts)
00095 {
00096     QString value;
00097 
00098     if (!(value=opts["cpi"]).isEmpty())
00099         m_cpi->setValue(value.toInt());
00100     if (!(value=opts["lpi"]).isEmpty())
00101         m_lpi->setValue(value.toInt());
00102     if (!(value=opts["columns"]).isEmpty())
00103         m_columns->setValue(value.toInt());
00104     int ID(0);
00105     if (opts.contains("prettyprint") && (opts["prettyprint"].isEmpty() || opts["prettyprint"] == "true"))
00106         ID = 1;
00107     m_prettyprint->setButton(ID);
00108     slotPrettyChanged(ID);
00109 
00110     // get default margins
00111     m_currentps = opts["PageSize"];
00112     QString orient = opts["orientation-requested"];
00113     bool    landscape = (orient == "4" || orient == "5");
00114     initPageSize(landscape);
00115 
00116     bool    marginset(false);
00117     if (!(value=opts["page-top"]).isEmpty() && value.toFloat() != m_margin->top())
00118     {
00119         marginset = true;
00120         m_margin->setTop(value.toFloat());
00121     }
00122     if (!(value=opts["page-bottom"]).isEmpty() && value.toFloat() != m_margin->bottom())
00123     {
00124         marginset = true;
00125         m_margin->setBottom(value.toFloat());
00126     }
00127     if (!(value=opts["page-left"]).isEmpty() && value.toFloat() != m_margin->left())
00128     {
00129         marginset = true;
00130         m_margin->setLeft(value.toFloat());
00131     }
00132     if (!(value=opts["page-right"]).isEmpty() && value.toFloat() != m_margin->right())
00133     {
00134         marginset = true;
00135         m_margin->setRight(value.toFloat());
00136     }
00137     m_margin->setCustomEnabled(marginset);
00138 }
00139 
00140 void KPTextPage::getOptions(QMap<QString,QString>& opts, bool incldef)
00141 {
00142     if (incldef || m_cpi->value() != 10)
00143         opts["cpi"] = QString::number(m_cpi->value());
00144     if (incldef || m_lpi->value() != 6)
00145         opts["lpi"] = QString::number(m_lpi->value());
00146     if (incldef || m_columns->value() != 1)
00147         opts["columns"] = QString::number(m_columns->value());
00148 
00149     //if (m_margin->isCustomEnabled() || incldef)
00150     if (m_margin->isCustomEnabled())
00151     {
00152         opts["page-top"] = QString::number(( int )( m_margin->top()+0.5 ));
00153         opts["page-bottom"] = QString::number(( int )( m_margin->bottom()+0.5 ));
00154         opts["page-left"] = QString::number(( int )( m_margin->left()+0.5 ));
00155         opts["page-right"] = QString::number(( int )( m_margin->right()+0.5 ));
00156     }
00157     else
00158     {
00159         opts.remove("page-top");
00160         opts.remove("page-bottom");
00161         opts.remove("page-left");
00162         opts.remove("page-right");
00163     }
00164 
00165     if (m_prettyprint->id(m_prettyprint->selected()) == 1)
00166         opts["prettyprint"] = "true";
00167     else if (incldef)
00168         opts["prettyprint"] = "false";
00169     else
00170         opts.remove("prettyprint");
00171 }
00172 
00173 void KPTextPage::slotPrettyChanged(int ID)
00174 {
00175     QString iconstr = (ID == 0 ? "kdeprint_nup1" : "kdeprint_prettyprint");
00176     m_prettypix->setPixmap(UserIcon(iconstr));
00177 }
00178 
00179 void KPTextPage::slotColumnsChanged(int)
00180 {
00181     // TO BE IMPLEMENTED
00182 }
00183 
00184 void KPTextPage::initPageSize(bool landscape)
00185 {
00186     float w( -1 ), h( -1 );
00187     float mt( 36 ), mb( mt ), ml( 18 ), mr( ml );
00188     if (driver())
00189     {
00190         if (m_currentps.isEmpty())
00191         {
00192             DrListOption    *o = (DrListOption*)driver()->findOption("PageSize");
00193             if (o)
00194                 m_currentps = o->get("default");
00195         }
00196         if (!m_currentps.isEmpty())
00197         {
00198             DrPageSize  *ps = driver()->findPageSize(m_currentps);
00199             if (ps)
00200             {
00201                 w = ps->pageWidth();
00202                 h = ps->pageHeight();
00203                 mt = ps->topMargin();
00204                 ml = ps->leftMargin();
00205                 mr = ps->rightMargin();
00206                 mb = ps->bottomMargin();
00207             }
00208         }
00209     }
00210     m_margin->setPageSize(w, h);
00211     m_margin->setOrientation(landscape ? KPrinter::Landscape : KPrinter::Portrait);
00212     m_margin->setDefaultMargins( mt, mb, ml, mr );
00213     m_margin->setCustomEnabled(false);
00214 }
00215 
00216 #include "kptextpage.moc"
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed May 12 09:08:51 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2003