kdeprint Library API Documentation

kpposterpage.cpp

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001-2002 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 "kpposterpage.h" 00021 #include "posterpreview.h" 00022 #include "kprinter.h" 00023 #include "kmfactory.h" 00024 #include "util.h" 00025 00026 #include <qcheckbox.h> 00027 #include <qcombobox.h> 00028 #include <qlabel.h> 00029 #include <qlayout.h> 00030 #include <qtooltip.h> 00031 #include <qlineedit.h> 00032 #include <kpushbutton.h> 00033 #include <klocale.h> 00034 #include <knuminput.h> 00035 #include <kiconloader.h> 00036 00037 KPPosterPage::KPPosterPage( QWidget *parent, const char *name ) 00038 : KPrintDialogPage( parent, name ) 00039 { 00040 setTitle( i18n( "Poster" ) ); 00041 00042 m_postercheck = new QCheckBox( i18n( "&Print poster" ), this ); 00043 QWidget *dummy = new QWidget( this ); 00044 m_preview = new PosterPreview( dummy ); 00045 m_postersize = new QComboBox( dummy ); 00046 m_printsize = new QComboBox( dummy ); 00047 m_lockbtn = new KPushButton( dummy ); 00048 m_mediasize = new QLabel( dummy ); 00049 m_mediasize->setFrameStyle( QFrame::Panel|QFrame::Sunken ); 00050 QLabel *posterlab = new QLabel( i18n( "Poste&r size:" ), dummy ); 00051 QLabel *medialab = new QLabel( i18n( "Media size:" ), dummy ); 00052 QLabel *printlab = new QLabel( i18n( "Pri&nt size:" ), dummy ); 00053 posterlab->setBuddy( m_postersize ); 00054 printlab->setBuddy( m_printsize ); 00055 m_cutmargin = new KIntNumInput( 5, dummy ); 00056 // xgettext:no-c-format 00057 m_cutmargin->setLabel( i18n( "C&ut margin (% of media):" ) ); 00058 m_cutmargin->setRange( 0, 100, 10, true ); 00059 m_selection = new QLineEdit( dummy ); 00060 QLabel *selectionlab = new QLabel( i18n( "&Tile pages (to be printed):" ), dummy ); 00061 selectionlab->setBuddy( m_selection ); 00062 m_lockbtn->setToggleButton( true ); 00063 m_lockbtn->setPixmap( SmallIcon( "encrypted" ) ); 00064 m_lockbtn->setOn( true ); 00065 m_lockbtn->setFixedSize( m_lockbtn->sizeHint() ); 00066 QToolTip::add( m_lockbtn, i18n( "Link/unlink poster and print size" ) ); 00067 00068 for ( int i=0; i<KPrinter::NPageSize-1; i++ ) 00069 { 00070 m_postersize->insertItem( page_sizes[ i ].text ); 00071 m_printsize->insertItem( page_sizes[ i ].text ); 00072 } 00073 m_postersize->setCurrentItem( findIndex( KPrinter::A3 ) ); 00074 slotPosterSizeChanged( m_postersize->currentItem() ); 00075 00076 connect( m_postercheck, SIGNAL( toggled( bool ) ), dummy, SLOT( setEnabled( bool ) ) ); 00077 dummy->setEnabled( false ); 00078 connect( m_postersize, SIGNAL( activated( int ) ), SLOT( slotPosterSizeChanged( int ) ) ); 00079 connect( m_cutmargin, SIGNAL( valueChanged( int ) ), SLOT( slotMarginChanged( int ) ) ); 00080 connect( m_lockbtn, SIGNAL( toggled( bool ) ), m_printsize, SLOT( setDisabled( bool ) ) ); 00081 m_printsize->setEnabled( false ); 00082 connect( m_lockbtn, SIGNAL( toggled( bool ) ), SLOT( slotLockToggled( bool ) ) ); 00083 connect( m_selection, SIGNAL( textChanged( const QString& ) ), m_preview, SLOT( setSelectedPages( const QString& ) ) ); 00084 connect( m_preview, SIGNAL( selectionChanged( const QString& ) ), m_selection, SLOT( setText( const QString& ) ) ); 00085 00086 if ( KMFactory::self()->settings()->application != KPrinter::Dialog 00087 && KMFactory::self()->settings()->application >= 0 ) 00088 { 00089 m_printsize->hide(); 00090 m_lockbtn->hide(); 00091 printlab->hide(); 00092 } 00093 00094 QVBoxLayout *l0 = new QVBoxLayout( this, 0, 10 ); 00095 l0->addWidget( m_postercheck ); 00096 l0->addWidget( dummy, 1 ); 00097 QGridLayout *l1 = new QGridLayout( dummy, 8, 3, 0, 5 ); 00098 l1->addWidget( posterlab, 0, 0 ); 00099 l1->addWidget( m_postersize, 0, 1 ); 00100 l1->addWidget( printlab, 1, 0 ); 00101 l1->addWidget( m_printsize, 1, 1 ); 00102 l1->addWidget( medialab, 2, 0 ); 00103 l1->addWidget( m_mediasize, 2, 1 ); 00104 l1->addMultiCellWidget( m_preview, 4, 4, 0, 2 ); 00105 l1->addMultiCellWidget( m_cutmargin, 6, 6, 0, 2 ); 00106 l1->addMultiCellWidget( m_lockbtn, 0, 1, 2, 2 ); 00107 QHBoxLayout *l2 = new QHBoxLayout( 0, 0, 5 ); 00108 l1->addMultiCellLayout( l2, 7, 7, 0, 2 ); 00109 l2->addWidget( selectionlab ); 00110 l2->addWidget( m_selection ); 00111 l1->setColStretch( 1, 1 ); 00112 l1->setRowStretch( 4, 1 ); 00113 l1->addRowSpacing( 3, 10 ); 00114 l1->addRowSpacing( 5, 10 ); 00115 } 00116 00117 KPPosterPage::~KPPosterPage() 00118 { 00119 } 00120 00121 void KPPosterPage::setOptions( const QMap<QString,QString>& opts ) 00122 { 00123 QString ps = opts[ "PageSize" ]; 00124 if ( ps.isEmpty() && !opts[ "kde-pagesize" ].isEmpty() ) 00125 { 00126 ps = pageSizeToPageName( ( KPrinter::PageSize )opts[ "kde-pagesize" ].toInt() ); 00127 if ( ps.isEmpty() ) 00128 ps = opts[ "_kde-poster-media" ]; 00129 } 00130 if ( ps.isEmpty() ) 00131 m_mediasize->setText( i18n( "Unknown" ) ); 00132 else 00133 m_mediasize->setText( ps ); 00134 m_preview->setMediaSize( ps ); 00135 00136 if ( opts[ "_kde-filters" ].find( "poster" ) != -1 ) 00137 { 00138 m_postercheck->setChecked( true ); 00139 ps = opts[ "_kde-poster-size" ]; 00140 QString prtsize = opts[ "kde-printsize" ]; 00141 if ( !ps.isEmpty() ) 00142 { 00143 m_postersize->setCurrentItem( findIndex( pageNameToPageSize( ps ) ) ); 00144 m_lockbtn->setOn( !prtsize.isEmpty() && 00145 page_sizes[ m_postersize->currentItem() ].ID == prtsize.toInt() ); 00146 if ( !m_lockbtn->isOn() ) 00147 m_printsize->setCurrentItem( findIndex( prtsize.toInt() ) ); 00148 slotPosterSizeChanged( m_postersize->currentItem() ); 00149 } 00150 if ( !opts[ "_kde-poster-cut" ].isEmpty() ) 00151 m_cutmargin->setValue( opts[ "_kde-poster-cut" ].toInt() ); 00152 m_selection->setText( opts[ "_kde-poster-select" ] ); 00153 } 00154 else 00155 m_postercheck->setChecked( false ); 00156 } 00157 00158 void KPPosterPage::getOptions( QMap<QString,QString>& opts, bool ) 00159 { 00160 QStringList o = QStringList::split( ",", opts[ "_kde-filters" ], false ); 00161 if ( !m_postercheck->isChecked() ) 00162 { 00163 o.remove( "poster" ); 00164 opts[ "_kde-filters" ] = o.join( "," ); 00165 opts.remove( "_kde-poster-media" ); 00166 opts.remove( "_kde-poster-size" ); 00167 opts.remove( "_kde-poster-cut" ); 00168 opts.remove( "kde-printsize" ); 00169 opts.remove( "_kde-poster-select" ); 00170 } 00171 else 00172 { 00173 if ( !o.contains( "poster" ) ) 00174 o.append( "poster" ); 00175 opts[ "_kde-filters" ] = o.join( "," ); 00176 opts[ "_kde-poster-media" ] = m_mediasize->text(); 00177 opts[ "_kde-poster-size" ] = pageSizeToPageName( ( KPrinter::PageSize )page_sizes[ m_postersize->currentItem() ].ID ); 00178 opts[ "kde-printsize" ] = QString::number( page_sizes[ m_printsize->currentItem() ].ID ); 00179 opts[ "_kde-poster-cut" ] = QString::number( m_cutmargin->value() ); 00180 opts[ "_kde-poster-select" ] = m_selection->text().stripWhiteSpace(); 00181 } 00182 } 00183 00184 bool KPPosterPage::isValid() 00185 { 00186 return true; 00187 } 00188 00189 void KPPosterPage::slotPosterSizeChanged( int value ) 00190 { 00191 int ID = page_sizes[ m_postersize->currentItem() ].ID; 00192 m_preview->setPosterSize( ID ); 00193 if ( m_lockbtn->isOn() ) 00194 m_printsize->setCurrentItem( value ); 00195 } 00196 00197 void KPPosterPage::slotMarginChanged( int value ) 00198 { 00199 m_preview->setCutMargin( value ); 00200 } 00201 00202 void KPPosterPage::slotLockToggled( bool on ) 00203 { 00204 m_lockbtn->setPixmap( SmallIcon( on ? "encrypted" : "decrypted" ) ); 00205 if ( on ) 00206 m_printsize->setCurrentItem( m_postersize->currentItem() ); 00207 } 00208 00209 #include "kpposterpage.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 Mar 16 17:23:18 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003