kdeprint Library API Documentation

kpqtpage.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., 59 Temple Place - Suite 330,
00018  *  Boston, MA 02111-1307, USA.
00019  **/
00020 
00021 #include "kpqtpage.h"
00022 #include "kprinter.h"
00023 #include "kxmlcommand.h"
00024 #include "driver.h"
00025 #include "util.h"
00026 
00027 #include <qcombobox.h>
00028 #include <qbuttongroup.h>
00029 #include <qradiobutton.h>
00030 #include <qlabel.h>
00031 #include <qlayout.h>
00032 
00033 #include <kiconloader.h>
00034 #include <klocale.h>
00035 #include <kdebug.h>
00036 
00037 #define ORIENT_PORTRAIT_ID  0
00038 #define ORIENT_LANDSCAPE_ID 1
00039 
00040 #define COLORMODE_COLOR_ID  0
00041 #define COLORMODE_GRAYSCALE_ID  1
00042 
00043 #define NUP_1       0
00044 #define NUP_2       1
00045 #define NUP_4       2
00046 #define NUP_OTHER   3
00047 
00048 //*****************************************************************************************************
00049 
00050 KPQtPage::KPQtPage(QWidget *parent, const char *name)
00051 : KPrintDialogPage(parent,name)
00052 {
00053     init();
00054 }
00055 
00056 KPQtPage::KPQtPage(DrMain *driver, QWidget *parent, const char *name)
00057 : KPrintDialogPage(0, (driver && driver->findOption("PageSize") ? driver : 0), parent, name)
00058 {
00059     init();
00060 }
00061 
00062 KPQtPage::~KPQtPage()
00063 {
00064 }
00065 
00066 void KPQtPage::init()
00067 {
00068     setTitle(i18n("Print Format"));
00069 
00070     // widget creation
00071     m_pagesize = new QComboBox(this);
00072     QLabel  *m_pagesizelabel = new QLabel(i18n("Page s&ize:"), this);
00073     m_pagesizelabel->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
00074     m_pagesizelabel->setBuddy(m_pagesize);
00075     m_orientbox = new QButtonGroup(0, Qt::Vertical, i18n("Orientation"), this);
00076     m_colorbox = new QButtonGroup(0, Qt::Vertical, i18n("Color Mode"), this);
00077     QRadioButton    *m_portrait = new QRadioButton(i18n("&Portrait"), m_orientbox);
00078     QRadioButton    *m_landscape = new QRadioButton(i18n("&Landscape"), m_orientbox);
00079     m_orientpix = new QLabel(m_orientbox);
00080     m_orientpix->setAlignment(Qt::AlignCenter);
00081     QRadioButton    *m_color = new QRadioButton(i18n("Colo&r"), m_colorbox);
00082     QRadioButton    *m_grayscale = new QRadioButton(i18n("&Grayscale"), m_colorbox);
00083     m_colorpix = new QLabel(m_colorbox);
00084     m_colorpix->setAlignment(Qt::AlignCenter);
00085     m_nupbox = new QButtonGroup(0, Qt::Vertical, i18n("Pages per Sheet"), this);
00086     QRadioButton    *m_nup1 = new QRadioButton("&1", m_nupbox);
00087     QRadioButton    *m_nup2 = new QRadioButton("&2", m_nupbox);
00088     QRadioButton    *m_nup4 = new QRadioButton("&4", m_nupbox);
00089     QRadioButton    *m_nupother = new QRadioButton(i18n("Ot&her"), m_nupbox);
00090     m_nuppix = new QLabel(m_nupbox);
00091     m_nuppix->setAlignment(Qt::AlignCenter);
00092 
00093     // layout creation
00094     QGridLayout *lay0 = new QGridLayout(this, 3, 2, 0, 10);
00095     lay0->setRowStretch(1,1);
00096     lay0->setRowStretch(2,1);
00097     lay0->addWidget(m_pagesizelabel,0,0);
00098     lay0->addWidget(m_pagesize,0,1);
00099     lay0->addWidget(m_orientbox,1,0);
00100     lay0->addWidget(m_colorbox,1,1);
00101     lay0->addWidget(m_nupbox,2,0);
00102     QGridLayout *lay1 = new QGridLayout(m_orientbox->layout(), 2, 2, 10);
00103     lay1->addWidget(m_portrait,0,0);
00104     lay1->addWidget(m_landscape,1,0);
00105     lay1->addMultiCellWidget(m_orientpix,0,1,1,1);
00106     QGridLayout *lay2 = new QGridLayout(m_colorbox->layout(), 2, 2, 10);
00107     lay2->addWidget(m_color,0,0);
00108     lay2->addWidget(m_grayscale,1,0);
00109     lay2->addMultiCellWidget(m_colorpix,0,1,1,1);
00110     QGridLayout *lay3 = new QGridLayout(m_nupbox->layout(), 4, 2, 5);
00111     lay3->addWidget(m_nup1,0,0);
00112     lay3->addWidget(m_nup2,1,0);
00113     lay3->addWidget(m_nup4,2,0);
00114     lay3->addWidget(m_nupother,3,0);
00115     lay3->addMultiCellWidget(m_nuppix,0,3,1,1);
00116 
00117     // initialization
00118     m_portrait->setChecked(true);
00119     slotOrientationChanged(0);
00120     m_color->setChecked(true);
00121     slotColorModeChanged(0);
00122     m_nup1->setChecked(true);
00123     slotNupChanged(0);
00124 
00125     if (!KXmlCommandManager::self()->checkCommand("psnup"))
00126         m_nupbox->setEnabled(false);
00127     if (KPrinter::applicationType() != KPrinter::Dialog
00128             && KPrinter::applicationType() >= 0 )
00129     {
00130         m_orientbox->setEnabled(false);
00131         m_colorbox->setEnabled(false);
00132         m_pagesize->setEnabled(driver());
00133         m_pagesizelabel->setEnabled(driver());
00134     }
00135 
00136     if (!driver())
00137     {
00138         for (int i=0; i<KPrinter::NPageSize-1; i++)
00139             m_pagesize->insertItem(i18n(page_sizes[i].text));
00140         // default page size to locale settings
00141         m_pagesize->setCurrentItem(findIndex((KPrinter::PageSize)(KGlobal::locale()->pageSize())));
00142     }
00143     else
00144     {
00145         DrListOption    *lopt = static_cast<DrListOption*>(driver()->findOption("PageSize"));
00146         QPtrListIterator<DrBase>    it(*(lopt->choices()));
00147         for (; it.current(); ++it)
00148         {
00149             m_pagesize->insertItem(it.current()->get("text"));
00150             if (it.current() == lopt->currentChoice())
00151                 m_pagesize->setCurrentItem(m_pagesize->count()-1);
00152         }
00153     }
00154 
00155     // connections
00156     connect(m_orientbox,SIGNAL(clicked(int)),SLOT(slotOrientationChanged(int)));
00157     connect(m_colorbox,SIGNAL(clicked(int)),SLOT(slotColorModeChanged(int)));
00158     connect(m_nupbox,SIGNAL(clicked(int)),SLOT(slotNupChanged(int)));
00159 }
00160 
00161 void KPQtPage::slotOrientationChanged(int ID)
00162 {
00163     m_orientpix->setPixmap(UserIcon((ID == ORIENT_PORTRAIT_ID ? "kdeprint_portrait" : "kdeprint_landscape")));
00164 }
00165 
00166 void KPQtPage::slotColorModeChanged(int ID)
00167 {
00168     m_colorpix->setPixmap(UserIcon((ID == COLORMODE_COLOR_ID ? "kdeprint_color" : "kdeprint_grayscale")));
00169 }
00170 
00171 void KPQtPage::slotNupChanged(int ID)
00172 {
00173     QString pixstr;
00174     switch (ID)
00175     {
00176         case NUP_1: pixstr = "kdeprint_nup1"; break;
00177         case NUP_2: pixstr = "kdeprint_nup2"; break;
00178         case NUP_4: pixstr = "kdeprint_nup4"; break;
00179         case NUP_OTHER: pixstr = "kdeprint_nupother"; break;
00180     }
00181     m_nuppix->setPixmap(UserIcon(pixstr));
00182 }
00183 
00184 void KPQtPage::setOptions(const QMap<QString,QString>& opts)
00185 {
00186     int     ID = (opts["kde-orientation"] == "Landscape" ? ORIENT_LANDSCAPE_ID : ORIENT_PORTRAIT_ID);
00187     m_orientbox->setButton(ID);
00188     slotOrientationChanged(ID);
00189     ID = (opts["kde-colormode"] == "GrayScale" ? COLORMODE_GRAYSCALE_ID : COLORMODE_COLOR_ID);
00190     m_colorbox->setButton(ID);
00191     slotColorModeChanged(ID);
00192     if (driver())
00193     {
00194         QString val = opts["PageSize"];
00195         if (!val.isEmpty())
00196         {
00197             DrListOption    *opt = static_cast<DrListOption*>(driver()->findOption("PageSize"));
00198             DrBase  *ch = opt->findChoice(val);
00199             if (ch)
00200                 m_pagesize->setCurrentItem(opt->choices()->findRef(ch));
00201         }
00202     }
00203     else if (!opts["kde-pagesize"].isEmpty())
00204         m_pagesize->setCurrentItem(findIndex(opts["kde-pagesize"].toInt()));
00205     ID = NUP_1;
00206     if (opts["_kde-filters"].find("psnup") != -1)
00207     {
00208         ID = opts["_kde-psnup-nup"].toInt();
00209         if (ID == 1 || ID == 2 || ID == 4)
00210         {
00211             if (ID == 4) ID = 3;
00212             ID--;
00213         }
00214         else
00215         {
00216             ID = NUP_OTHER;
00217         }
00218     }
00219     m_nupbox->setButton(ID);
00220     slotNupChanged(ID);
00221 
00222     if ( m_orientbox->isEnabled() )
00223         m_orientbox->setDisabled( opts[ "kde-orientation-fixed" ] == "1" );
00224     if ( m_pagesize->isEnabled() )
00225         m_pagesize->setDisabled( opts[ "kde-pagesize-fixed" ] == "1" );
00226 }
00227 
00228 void KPQtPage::getOptions(QMap<QString,QString>& opts, bool incldef)
00229 {
00230     opts["kde-orientation"] = (m_orientbox->id(m_orientbox->selected()) == ORIENT_LANDSCAPE_ID ? "Landscape" : "Portrait");
00231     opts["kde-colormode"] = (m_colorbox->id(m_colorbox->selected()) == COLORMODE_GRAYSCALE_ID ? "GrayScale" : "Color");
00232     if (driver())
00233     {
00234         DrListOption    *opt = static_cast<DrListOption*>(driver()->findOption("PageSize"));
00235         if (opt)
00236         {
00237             DrBase  *ch = opt->choices()->at(m_pagesize->currentItem());
00238             if (ch && (incldef || ch->name() != opt->get("default")))
00239             {
00240                 opts["PageSize"] = ch->name();
00241             }
00242         }
00243     }
00244     else
00245         opts["kde-pagesize"] = QString::number(page_sizes[m_pagesize->currentItem()].ID);
00246     int ID = m_nupbox->id(m_nupbox->selected());
00247     QString s = opts["_kde-filters"];
00248     if (ID == NUP_1)
00249     {
00250         opts.remove("_kde-psnup-nup");
00251     }
00252     else if (ID != NUP_OTHER)
00253     {
00254         int nup(ID == NUP_2 ? 2 : 4);
00255         if (s.find("psnup") == -1)
00256         {
00257             QStringList fl = QStringList::split(',', s, false);
00258             KXmlCommandManager::self()->insertCommand(fl, "psnup");
00259             s = fl.join(",");
00260         }
00261         opts["_kde-psnup-nup"] = QString::number(nup);
00262     }
00263     opts["_kde-filters"] = s;
00264 }
00265 #include "kpqtpage.moc"
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Aug 4 05:28:00 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2003