kdeprint Library API Documentation

kpcopiespage.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 "kpcopiespage.h"
00021 #include "kmfactory.h"
00022 #include "kmuimanager.h"
00023 #include "kprinter.h"
00024 #include "kxmlcommand.h"
00025 
00026 #include <qlabel.h>
00027 #include <qcombobox.h>
00028 #include <qspinbox.h>
00029 #include <qbuttongroup.h>
00030 #include <qradiobutton.h>
00031 #include <qlineedit.h>
00032 #include <qcheckbox.h>
00033 #include <qtooltip.h>
00034 #include <qwhatsthis.h>
00035 #include <qlayout.h>
00036 
00037 #include <kapplication.h>
00038 #include <klocale.h>
00039 #include <kiconloader.h>
00040 #include <kseparator.h>
00041 
00042 KPCopiesPage::KPCopiesPage(KPrinter *prt, QWidget *parent, const char *name)
00043 : KPrintDialogPage(parent,name)
00044 {
00045     //WhatsThis strings.... (added by pfeifle@kde.org)
00046     QString whatsThisPageSelectionLabel = i18n(  " <qt>Here you can determine to print a certain selection only out of all"
00047                         " pages from the complete document.</qt>" );
00048     QString whatsThisAllPagesLabel = i18n(  " <qt>Select \"All\" to print the complete document. Since this is the default,"
00049                         " it is pre-selected.</qt>" );
00050     QString whatsThisCurrentPagesLabel = i18n(  " <qt><p>Select <em>\"Current\"</em> if you want to print the page currently visible"
00051                         " in your KDE application.</p>"
00052                         " <p><b>Note:</b> this field is disabled if you print from"
00053                         " non-KDE applications like Mozilla or OpenOffice.org, since here KDEPrint has no"
00054                         " means to determine which document page you are currently viewing.</p></qt>" );
00055     QString whatsThisPageRangeLabel = i18n(  " <qt><p>Choose a \"Page Range\" to select a subset of the complete document pages"
00056                         " to be printed. The format is <em>\"n,m,o-p,q,r,s-t, u\"</em>.</p>"
00057                         " <p><b>Example:</b> <em>\"4,6,10-13,17,20,23-25\"</em> will print"
00058                         " the pages 4, 6, 10, 11, 12, 13, 17, 20, 23, 24, 25 of your document.</p></qt>" );
00059     QString whatsThisPageSetLabel = i18n(  " <qt>Choose <em>\"All Pages\"</em>, <em>\"Even Pages\"</em> or <em>\"Odd Pages\"</em>"
00060                         " if you want to print a page selection matching one of these terms. The default"
00061                         " is <em>\"All Pages\"</em>.</p>"
00062                         " <p><b>Note:</b> If you combine a selection of a <em>\"Page Range\"</em> with a"
00063                         " <em>\"Page Set\"</em> of <em>\"Odd\"</em> or <em>\"Even\"</em>, you will only get the"
00064                         " odd or even pages from the originally selected page range. This is useful if you"
00065                         " want to print a page range in duplex on a simplex-only printer. In this case you"
00066                         " can feed the paper to the printer twice; in the first pass, select \"Odd\" or"
00067                         " \"Even\" (depending on your printer model), in second pass select the other"
00068                         " option. You may need to <em>\"Reverse\"</em> the output in one of the passes (depending"
00069                         " on your printer model).</p> "
00070                         " </qt>" );
00071     QString whatsThisCopiesLabel = i18n(  " <qt>Here you can determine the number of copies, the output order and the collate"
00072                         " mode of your printjob.</qt>" );
00073     QString whatsThisNumberOfCopiesLabel = i18n(  " <qt>Determine the number of requested copies here. You can increase or decrease"
00074                         " the number by clicking on the up and down arrows. You can also type the figure"
00075                         " directly into the box.</qt>" );
00076     QString whatsThisCollateLabel = i18n(  " <qt><p>If the <em>\"Collate\"</em> checkbox is enabled (default), the output order of"
00077                         " a multi-page document will be \"1-2-3-..., 1-2-3-..., 1-2-3-...\".</p>"
00078                         " <p>If the <em>\"Collate\"</em> checkbox is disabled, the output order of"
00079                         " a multi-page document will be \"1-1-1-..., 2-2-2-..., 3-3-3-...\".</p></qt>" );
00080     QString whatsThisReverseLabel = i18n(  " <qt><p>If the <em>\"Reverse\"</em> checkbox is enabled, the output order of"
00081                         " a multi-page document will be \"...-3-2-1, ...-3-2-1, ...-3-2-1\", if you"
00082                         " also have <em>en</em>abled the <em>\"Collate\"</em> checkbox at the same time"
00083                         " (the usual usecase).</p>"
00084                         " <p>If the <em>\"Reverse\"</em> checkbox is enabled, the output order of"
00085                         " a multi-page document will be \"...-3-3-3, ...-2-2-2, ...-1-1-1\", if you"
00086                         " have <em>dis</em>abled the <em>\"Collate\"</em> checkbox at the same time."
00087                         "</p></qt>" );
00088     m_printer = prt;
00089     m_useplugin = true;
00090 
00091     setTitle(i18n("C&opies"));
00092     setId(KPrinter::CopiesPage);
00093 
00094     // widget creation
00095     QButtonGroup    *m_pagebox = new QButtonGroup(0, Qt::Vertical, i18n("Page Selection"), this);
00096     QWhatsThis::add(m_pagebox, whatsThisPageSelectionLabel);
00097     m_all = new QRadioButton(i18n("&All"), m_pagebox);
00098     QWhatsThis::add(m_all, whatsThisAllPagesLabel);
00099     m_current = new QRadioButton(i18n("Cu&rrent"), m_pagebox);
00100     QWhatsThis::add(m_current, whatsThisCurrentPagesLabel);
00101     m_range = new QRadioButton(i18n("Ran&ge"), m_pagebox);
00102     QWhatsThis::add(m_range, whatsThisPageRangeLabel);
00103     m_rangeedit = new QLineEdit(m_pagebox);
00104     QWhatsThis::add(m_rangeedit, whatsThisPageRangeLabel);
00105     connect(m_range, SIGNAL(clicked()), m_rangeedit, SLOT(setFocus()));
00106     QToolTip::add(m_rangeedit, i18n("<p>Enter pages or group of pages to print separated by commas (1,2-5,8).</p>"));
00107 //  QWhatsThis::add(m_rangeedit, i18n("<p>Enter pages or group of pages to print separated by commas (1,2-5,8).</p>"));
00108     //QLabel    *m_rangeexpl = new QLabel(m_pagebox);
00109     //m_rangeexpl->setText(i18n("<p>Enter pages or group of pages to print separated by commas (1,2-5,8).</p>"));
00110     QGroupBox   *m_copybox = new QGroupBox(0, Qt::Vertical, i18n("Copies"), this);
00111     QWhatsThis::add(m_copybox, whatsThisCopiesLabel);
00112     m_collate = new QCheckBox(i18n("Co&llate"), m_copybox);
00113     QWhatsThis::add(m_collate, whatsThisCollateLabel);
00114     m_order = new QCheckBox(i18n("Re&verse"), m_copybox);
00115     QWhatsThis::add(m_order, whatsThisReverseLabel);
00116     m_collatepix = new QLabel(m_copybox);
00117     m_collatepix->setAlignment(Qt::AlignCenter);
00118     m_collatepix->setMinimumHeight(70);
00119     QLabel  *m_copieslabel = new QLabel(i18n("Cop&ies:"), m_copybox);
00120     m_copies = new QSpinBox(m_copybox);
00121     m_copies->setRange(1,999);
00122     QWhatsThis::add(m_copies, whatsThisNumberOfCopiesLabel);
00123     m_copieslabel->setBuddy(m_copies);
00124     QWhatsThis::add(m_copieslabel, whatsThisNumberOfCopiesLabel);
00125     m_pageset = new QComboBox(m_pagebox);
00126     m_pageset->insertItem(i18n("All Pages"));
00127     m_pageset->insertItem(i18n("Odd Pages"));
00128     m_pageset->insertItem(i18n("Even Pages"));
00129     QWhatsThis::add(m_pageset, whatsThisPageSetLabel);
00130     QLabel  *m_pagesetlabel = new QLabel(i18n("Page &set:"), m_pagebox);
00131     m_pagesetlabel->setBuddy(m_pageset);
00132     QWhatsThis::add(m_pagesetlabel, whatsThisPageSetLabel);
00133     KSeparator  *sepline = new KSeparator(Horizontal, m_pagebox);
00134     sepline->setMinimumHeight(10);
00135 
00136     QWidget::setTabOrder( m_all, m_current );
00137     QWidget::setTabOrder( m_current, m_range );
00138     QWidget::setTabOrder( m_range, m_rangeedit );
00139     QWidget::setTabOrder( m_rangeedit, m_pageset );
00140     QWidget::setTabOrder( m_pageset, m_copies );
00141     QWidget::setTabOrder( m_copies, m_collate );
00142     QWidget::setTabOrder( m_collate, m_order );
00143 
00144     // layout creation
00145     QGridLayout *l1 = new QGridLayout(this, 2, 2, 0, 5);
00146     l1->setRowStretch(1,1);
00147     l1->setColStretch(0,1);
00148     l1->setColStretch(1,1);
00149     l1->addWidget(m_pagebox,0,0);
00150     l1->addWidget(m_copybox,0,1);
00151     QVBoxLayout *l3 = new QVBoxLayout(m_pagebox->layout(), 5);
00152     l3->addWidget(m_all);
00153     l3->addWidget(m_current);
00154     QHBoxLayout *l4 = new QHBoxLayout(0, 0, 5);
00155     l3->addLayout(l4);
00156     l4->addWidget(m_range,0);
00157     l4->addWidget(m_rangeedit,1);
00158     //l3->addWidget(m_rangeexpl);
00159     l3->addWidget(sepline);
00160     QHBoxLayout *l2 = new QHBoxLayout(0, 0, 5);
00161     l3->addLayout(l2);
00162     l2->addWidget(m_pagesetlabel,0);
00163     l2->addWidget(m_pageset,1);
00164     QGridLayout *l5 = new QGridLayout(m_copybox->layout(), 4, 2, 10);
00165     l5->setRowStretch(4,1);
00166     l5->addWidget(m_copieslabel,0,0);
00167     l5->addWidget(m_copies,0,1);
00168     l5->addMultiCellWidget(m_collatepix,1,2,0,0);
00169     l5->addWidget(m_collate,1,1);
00170     l5->addWidget(m_order,2,1);
00171 
00172     // some initialization
00173     m_all->setChecked(true);
00174     m_copies->setValue(1);
00175     initialize(m_useplugin);
00176     slotCollateClicked();
00177 
00178     // connections
00179     connect(m_rangeedit,SIGNAL(textChanged(const QString&)),SLOT(slotRangeEntered()));
00180     connect(m_collate,SIGNAL(clicked()),SLOT(slotCollateClicked()));
00181     connect(m_order,SIGNAL(clicked()),SLOT(slotCollateClicked()));
00182 
00183     if (!kapp->authorize("print/copies"))
00184     {
00185         setTitle(i18n("Pages"));
00186         m_copybox->hide();
00187     }
00188 }
00189 
00190 KPCopiesPage::~KPCopiesPage()
00191 {
00192 }
00193 
00194 void KPCopiesPage::slotRangeEntered()
00195 {
00196     m_range->setChecked(true);
00197 }
00198 
00199 void KPCopiesPage::slotCollateClicked()
00200 {
00201     QString s("kdeprint_");
00202     s.append((m_collate->isChecked() ? "collate" : "uncollate"));
00203     if (m_order->isChecked()) s.append("_reverse");
00204     m_collatepix->setPixmap(UserIcon(s));
00205 }
00206 
00207 void KPCopiesPage::initialize(bool usePlugin)
00208 {
00209     m_useplugin = usePlugin;
00210     int f = KMFactory::self()->uiManager()->copyFlags(m_printer, m_useplugin);
00211 
00212     m_current->setEnabled((f & KMUiManager::Current));
00213     m_range->setEnabled((f & KMUiManager::Range));
00214     m_rangeedit->setEnabled((f & KMUiManager::Range));
00215     m_collate->setEnabled((f & KMUiManager::Collate));
00216     m_order->setEnabled((f & KMUiManager::Order));
00217     m_pageset->setEnabled((f & KMUiManager::PageSet));
00218 
00219     // by default, if collate disabled, set it to true
00220     m_collate->setChecked(!(f & KMUiManager::NoAutoCollate));
00221     slotCollateClicked();
00222 }
00223 
00224 void KPCopiesPage::setOptions(const QMap<QString,QString>& options)
00225 {
00226     QString value;
00227     // copies
00228     value = options["kde-copies"];
00229     if (!value.isEmpty()) m_copies->setValue(value.toInt());
00230     // output order
00231     value = options["kde-pageorder"];
00232     if (m_order->isEnabled()) m_order->setChecked(value == "Reverse");
00233     // collate
00234     value = options["kde-collate"];
00235     if (m_collate->isEnabled()) m_collate->setChecked(!(value == "Uncollate"));
00236     // update pixmap
00237     slotCollateClicked();
00238     // page ranges
00239     value = options["kde-range"];
00240     if (!value.isEmpty() && m_range->isEnabled() && value != "1-")
00241     {
00242         m_rangeedit->setText(value);
00243         m_range->setChecked(true);
00244     }
00245     else if (options["kde-current"] == "1")
00246         m_current->setChecked(true);
00247     else
00248         m_all->setChecked(true);
00249     // page set
00250     value = options["kde-pageset"];
00251     if (!value.isEmpty() && m_pageset->isEnabled())
00252         m_pageset->setCurrentItem(value.toInt());
00253     else
00254         m_pageset->setCurrentItem(0);
00255 }
00256 
00257 void KPCopiesPage::getOptions(QMap<QString,QString>& options, bool incldef)
00258 {
00259     // copies
00260     options["kde-copies"] = m_copies->text();
00261     // output order
00262     options["kde-pageorder"] = (m_order->isChecked() ? "Reverse" : "Forward");
00263     // collate
00264     options["kde-collate"] = (m_collate->isChecked() ? "Collate" : "Uncollate");
00265     // ranges
00266     options["kde-current"] = (m_current->isChecked() ? "1" : "0");
00267     options["kde-range"] = (m_range->isChecked() ? m_rangeedit->text() : (incldef ? QString::fromLatin1("1-") : QString::fromLatin1("")));
00268     // page set
00269     options["kde-pageset"] = QString::number(m_pageset->currentItem());
00270 }
00271 
00272 void KPCopiesPage::reload()
00273 {
00274     initialize(m_useplugin);
00275 }
00276 
00277 #include "kpcopiespage.moc"
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Jan 15 13:34:10 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003