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., 51 Franklin Street, Fifth Floor,
00018  *  Boston, MA 02110-1301, 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 #include <qwhatsthis.h>
00033 
00034 #include <kiconloader.h>
00035 #include <klocale.h>
00036 #include <kdebug.h>
00037 
00038 #define ORIENT_PORTRAIT_ID  0
00039 #define ORIENT_LANDSCAPE_ID 1
00040 
00041 #define COLORMODE_COLOR_ID  0
00042 #define COLORMODE_GRAYSCALE_ID  1
00043 
00044 #define NUP_1       0
00045 #define NUP_2       1
00046 #define NUP_4       2
00047 #define NUP_OTHER   3
00048 
00049 //*****************************************************************************************************
00050 
00051 KPQtPage::KPQtPage(QWidget *parent, const char *name)
00052 : KPrintDialogPage(parent,name)
00053 {
00054     init();
00055 }
00056 
00057 KPQtPage::KPQtPage(DrMain *driver, QWidget *parent, const char *name)
00058 : KPrintDialogPage(0, (driver && driver->findOption("PageSize") ? driver : 0), parent, name)
00059 {
00060     init();
00061 }
00062 
00063 KPQtPage::~KPQtPage()
00064 {
00065 }
00066 
00067 void KPQtPage::init()
00068 {
00069         //WhatsThis strings.... (added by pfeifle@kde.org)
00070     QString whatsThisColorModeOtPageLabel = i18n( " <qt> "
00071             " <b>Selection of color mode:</b> You can choose between 2 options: "
00072             " <ul><li><b>Color</b> and</li> "
00073                         " <li><b>Grayscale</b></li></ul> "
00074             " <b>Note:</b> This selection field may be grayed out and made inactive. "
00075             " This happens if KDEPrint can not retrieve "
00076             " enough information about your print file. In this case the embedded color- or grayscale information "
00077             " of your printfile, and the default handling of the printer take precedence. "
00078             " </qt>" );
00079     QString whatsThisPageSizeOtPageLabel = i18n( " <qt> "
00080             " <b>Selection of page size:</b> Select paper size to be printed on from "
00081             " the drop-down menu. "
00082             " <p>The exact list of choices depends on the printer driver (\"PPD\") you have installed. "
00083             " </qt>" );
00084     QString whatsThisPagesPerSheetOtPageLabel = i18n( " <qt> "
00085             " <b>Selection of pages per sheet:</b> "
00086                         " You can choose to print more than one page onto each sheet of paper. "
00087                         " This is sometimes useful to save paper. "
00088                         " <p><b>Note 1:</b> the page images get scaled down accordingly to print 2 or 4 pages per sheet. "
00089                         " The page image does not get scaled if you print 1 page per sheet (the default setting.). "
00090                         " <p><b>Note 2:</b> If you select multiple pages per sheet here, the scaling and re-arranging is done "
00091                         " by your printing system. "
00092             " <p><b>Note 3, regarding \"Other\":</b> You cannot really select <em>Other</em> as the number of "
00093             " pages to print on one sheet.\"Other\" is checkmarked here for information purposes only. "
00094             " <p>To select 8, 9, 16 or other numbers of "
00095             " pages per sheet: "
00096             " <ul> "
00097             " <li> go to the tab headlined \"Filter\"</li>"
00098             " <li> enable the <em>Multiple Pages per Sheet</em> filter </li>"
00099             " <li> and configure it (bottom-most button on the right of the \"Filters\" tab). </li>"
00100             " </ul>"
00101             " </qt>" );
00102     QString whatsThisOrientationOtPageLabel = i18n( " <qt> "
00103             " <b>Selection of image orientation:</b> Orientation of the printed "
00104                         " pageimage on your paper is controlled by the radio buttons. By default, "
00105                         " the orientation is <em>Portrait</em> "
00106                         " <p>You can select 2 alternatives: "
00107                         " <ul> "
00108                         " <li> <b>Portrait.</b>.Portrait is the default setting. </li> "
00109                         " <li> <b>Landscape.</b> </li> "
00110                         " </ul> "
00111                         " The icon changes according to your selection."
00112             " </qt>" );
00113     setTitle(i18n("Print Format"));
00114 
00115     // widget creation
00116     m_pagesize = new QComboBox(this);
00117           QWhatsThis::add(m_pagesize, whatsThisPageSizeOtPageLabel);
00118     QLabel  *m_pagesizelabel = new QLabel(i18n("Page s&ize:"), this);
00119     m_pagesizelabel->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
00120     m_pagesizelabel->setBuddy(m_pagesize);
00121     m_orientbox = new QButtonGroup(0, Qt::Vertical, i18n("Orientation"), this);
00122           QWhatsThis::add(m_orientbox, whatsThisOrientationOtPageLabel);
00123     m_colorbox = new QButtonGroup(0, Qt::Vertical, i18n("Color Mode"), this);
00124           QWhatsThis::add(m_colorbox, whatsThisColorModeOtPageLabel);
00125     QRadioButton    *m_portrait = new QRadioButton(i18n("&Portrait"), m_orientbox);
00126           QWhatsThis::add(m_portrait, whatsThisOrientationOtPageLabel);
00127 
00128     QRadioButton    *m_landscape = new QRadioButton(i18n("&Landscape"), m_orientbox);
00129           QWhatsThis::add(m_landscape, whatsThisOrientationOtPageLabel);
00130 
00131     m_orientpix = new QLabel(m_orientbox);
00132     m_orientpix->setAlignment(Qt::AlignCenter);
00133           QWhatsThis::add(m_orientpix, whatsThisOrientationOtPageLabel);
00134 
00135     QRadioButton    *m_color = new QRadioButton(i18n("Colo&r"), m_colorbox);
00136           QWhatsThis::add(m_color, whatsThisColorModeOtPageLabel);
00137 
00138     QRadioButton    *m_grayscale = new QRadioButton(i18n("&Grayscale"), m_colorbox);
00139     m_colorpix = new QLabel(m_colorbox);
00140     m_colorpix->setAlignment(Qt::AlignCenter);
00141           QWhatsThis::add(m_colorpix, whatsThisColorModeOtPageLabel);
00142 
00143     m_nupbox = new QButtonGroup(0, Qt::Vertical, i18n("Pages per Sheet"), this);
00144         //  QWhatsThis::add(m_nupbox, whatsThisPagesPerSheetOtPageLabel);
00145     QRadioButton    *m_nup1 = new QRadioButton("&1", m_nupbox);
00146           QWhatsThis::add(m_nup1, whatsThisPagesPerSheetOtPageLabel);
00147     QRadioButton    *m_nup2 = new QRadioButton("&2", m_nupbox);
00148           QWhatsThis::add(m_nup2, whatsThisPagesPerSheetOtPageLabel);
00149     QRadioButton    *m_nup4 = new QRadioButton("&4", m_nupbox);
00150           QWhatsThis::add(m_nup4, whatsThisPagesPerSheetOtPageLabel);
00151     QRadioButton    *m_nupother = new QRadioButton(i18n("Ot&her"), m_nupbox);
00152           QWhatsThis::add(m_nupother, whatsThisPagesPerSheetOtPageLabel);
00153 
00154     m_nuppix = new QLabel(m_nupbox);
00155     m_nuppix->setAlignment(Qt::AlignCenter);
00156           QWhatsThis::add(m_nuppix, whatsThisPagesPerSheetOtPageLabel);
00157 
00158     // layout creation
00159     QGridLayout *lay0 = new QGridLayout(this, 3, 2, 0, 10);
00160     lay0->setRowStretch(1,1);
00161     lay0->setRowStretch(2,1);
00162     lay0->addWidget(m_pagesizelabel,0,0);
00163     lay0->addWidget(m_pagesize,0,1);
00164     lay0->addWidget(m_orientbox,1,0);
00165     lay0->addWidget(m_colorbox,1,1);
00166     lay0->addWidget(m_nupbox,2,0);
00167     QGridLayout *lay1 = new QGridLayout(m_orientbox->layout(), 2, 2, 10);
00168     lay1->addWidget(m_portrait,0,0);
00169     lay1->addWidget(m_landscape,1,0);
00170     lay1->addMultiCellWidget(m_orientpix,0,1,1,1);
00171     QGridLayout *lay2 = new QGridLayout(m_colorbox->layout(), 2, 2, 10);
00172     lay2->addWidget(m_color,0,0);
00173     lay2->addWidget(m_grayscale,1,0);
00174     lay2->addMultiCellWidget(m_colorpix,0,1,1,1);
00175     QGridLayout *lay3 = new QGridLayout(m_nupbox->layout(), 4, 2, 5);
00176     lay3->addWidget(m_nup1,0,0);
00177     lay3->addWidget(m_nup2,1,0);
00178     lay3->addWidget(m_nup4,2,0);
00179     lay3->addWidget(m_nupother,3,0);
00180     lay3->addMultiCellWidget(m_nuppix,0,3,1,1);
00181 
00182     // initialization
00183     m_portrait->setChecked(true);
00184     slotOrientationChanged(0);
00185     m_color->setChecked(true);
00186     slotColorModeChanged(0);
00187     m_nup1->setChecked(true);
00188     slotNupChanged(0);
00189 
00190     if (!KXmlCommandManager::self()->checkCommand("psnup"))
00191         m_nupbox->setEnabled(false);
00192     if (KPrinter::applicationType() != KPrinter::Dialog
00193             && KPrinter::applicationType() >= 0 )
00194     {
00195         m_orientbox->setEnabled(false);
00196         m_colorbox->setEnabled(false);
00197         m_pagesize->setEnabled(driver());
00198         m_pagesizelabel->setEnabled(driver());
00199     }
00200 
00201     if (!driver())
00202     {
00203         for (int i=0; i<KPrinter::NPageSize-1; i++)
00204             m_pagesize->insertItem(i18n(page_sizes[i].text));
00205         // default page size to locale settings
00206         m_pagesize->setCurrentItem(findIndex((KPrinter::PageSize)(KGlobal::locale()->pageSize())));
00207     }
00208     else
00209     {
00210         DrListOption    *lopt = static_cast<DrListOption*>(driver()->findOption("PageSize"));
00211         QPtrListIterator<DrBase>    it(*(lopt->choices()));
00212         for (; it.current(); ++it)
00213         {
00214             m_pagesize->insertItem(it.current()->get("text"));
00215             if (it.current() == lopt->currentChoice())
00216                 m_pagesize->setCurrentItem(m_pagesize->count()-1);
00217         }
00218     }
00219 
00220     // connections
00221     connect(m_orientbox,SIGNAL(clicked(int)),SLOT(slotOrientationChanged(int)));
00222     connect(m_colorbox,SIGNAL(clicked(int)),SLOT(slotColorModeChanged(int)));
00223     connect(m_nupbox,SIGNAL(clicked(int)),SLOT(slotNupChanged(int)));
00224 }
00225 
00226 void KPQtPage::slotOrientationChanged(int ID)
00227 {
00228     m_orientpix->setPixmap(UserIcon((ID == ORIENT_PORTRAIT_ID ? "kdeprint_portrait" : "kdeprint_landscape")));
00229 }
00230 
00231 void KPQtPage::slotColorModeChanged(int ID)
00232 {
00233     m_colorpix->setPixmap(UserIcon((ID == COLORMODE_COLOR_ID ? "kdeprint_color" : "kdeprint_grayscale")));
00234 }
00235 
00236 void KPQtPage::slotNupChanged(int ID)
00237 {
00238     QString pixstr;
00239     switch (ID)
00240     {
00241         case NUP_1: pixstr = "kdeprint_nup1"; break;
00242         case NUP_2: pixstr = "kdeprint_nup2"; break;
00243         case NUP_4: pixstr = "kdeprint_nup4"; break;
00244         case NUP_OTHER: pixstr = "kdeprint_nupother"; break;
00245     }
00246     m_nuppix->setPixmap(UserIcon(pixstr));
00247 }
00248 
00249 void KPQtPage::setOptions(const QMap<QString,QString>& opts)
00250 {
00251     int     ID = (opts["kde-orientation"] == "Landscape" ? ORIENT_LANDSCAPE_ID : ORIENT_PORTRAIT_ID);
00252     m_orientbox->setButton(ID);
00253     slotOrientationChanged(ID);
00254     ID = (opts["kde-colormode"] == "GrayScale" ? COLORMODE_GRAYSCALE_ID : COLORMODE_COLOR_ID);
00255     m_colorbox->setButton(ID);
00256     slotColorModeChanged(ID);
00257     if (driver())
00258     {
00259         QString val = opts["PageSize"];
00260         if (!val.isEmpty())
00261         {
00262             DrListOption    *opt = static_cast<DrListOption*>(driver()->findOption("PageSize"));
00263             DrBase  *ch = opt->findChoice(val);
00264             if (ch)
00265                 m_pagesize->setCurrentItem(opt->choices()->findRef(ch));
00266         }
00267     }
00268     else if (!opts["kde-pagesize"].isEmpty())
00269         m_pagesize->setCurrentItem(findIndex(opts["kde-pagesize"].toInt()));
00270     ID = NUP_1;
00271     if (opts["_kde-filters"].find("psnup") != -1)
00272     {
00273                if (opts.contains("_kde-psnup-nup")) {
00274                        ID = opts["_kde-psnup-nup"].toInt();
00275                        if (ID == 1 || ID == 2 || ID == 4)
00276                        {
00277                                if (ID == 4) ID = 3;
00278                                ID--;
00279                        }
00280                        else
00281                        {
00282                                ID = NUP_OTHER;
00283                        }
00284                }
00285                else
00286                {
00287                        ID = NUP_1;
00288                }
00289     }
00290     m_nupbox->setButton(ID);
00291     slotNupChanged(ID);
00292 
00293     if ( m_orientbox->isEnabled() )
00294         m_orientbox->setDisabled( opts[ "kde-orientation-fixed" ] == "1" );
00295     if ( m_pagesize->isEnabled() )
00296         m_pagesize->setDisabled( opts[ "kde-pagesize-fixed" ] == "1" );
00297 }
00298 
00299 void KPQtPage::getOptions(QMap<QString,QString>& opts, bool incldef)
00300 {
00301     opts["kde-orientation"] = (m_orientbox->id(m_orientbox->selected()) == ORIENT_LANDSCAPE_ID ? "Landscape" : "Portrait");
00302     opts["kde-colormode"] = (m_colorbox->id(m_colorbox->selected()) == COLORMODE_GRAYSCALE_ID ? "GrayScale" : "Color");
00303     if (driver())
00304     {
00305         DrListOption    *opt = static_cast<DrListOption*>(driver()->findOption("PageSize"));
00306         if (opt)
00307         {
00308             DrBase  *ch = opt->choices()->at(m_pagesize->currentItem());
00309             if (ch && (incldef || ch->name() != opt->get("default")))
00310             {
00311                 opts["PageSize"] = ch->name();
00312             }
00313         }
00314     }
00315     else
00316         opts["kde-pagesize"] = QString::number(page_sizes[m_pagesize->currentItem()].ID);
00317     int ID = m_nupbox->id(m_nupbox->selected());
00318     QString s = opts["_kde-filters"];
00319     if (ID == NUP_1)
00320     {
00321         opts.remove("_kde-psnup-nup");
00322     }
00323     else if (ID != NUP_OTHER)
00324     {
00325         int nup(ID == NUP_2 ? 2 : 4);
00326         if (s.find("psnup") == -1)
00327         {
00328             QStringList fl = QStringList::split(',', s, false);
00329             KXmlCommandManager::self()->insertCommand(fl, "psnup");
00330             s = fl.join(",");
00331         }
00332         opts["_kde-psnup-nup"] = QString::number(nup);
00333     }
00334     opts["_kde-filters"] = s;
00335 }
00336 #include "kpqtpage.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys