kpposterpage.cpp
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001-2002 Michael Goffioul <tdeprint@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., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, 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 <tqcheckbox.h> 00027 #include <tqcombobox.h> 00028 #include <tqlabel.h> 00029 #include <tqlayout.h> 00030 #include <tqtooltip.h> 00031 #include <tqlineedit.h> 00032 #include <tqwhatsthis.h> 00033 #include <kpushbutton.h> 00034 #include <tdelocale.h> 00035 #include <knuminput.h> 00036 #include <kiconloader.h> 00037 00038 KPPosterPage::KPPosterPage( TQWidget *parent, const char *name ) 00039 : KPrintDialogPage( parent, name ) 00040 { 00041 //WhatsThis strings.... (added by pfeifle@kde.org) 00042 TQString whatsThis5_PosterPage = i18n( " <qt> " 00043 " 5. " 00044 " </qt>" ); 00045 00046 TQString whatsThisEnablePosterPage = i18n( " <qt> " 00047 " <b>Print Poster</b> (enabled or disabled). " 00048 " <p>If you enable this option, you can print posters of different sizes " 00049 " The printout will happen in the form <em>'tiles'</em> printed on smaller " 00050 " paper sizes, which you can stitch together later. <em>If you enable this " 00051 " option here, the <em>'Poster Printing' filter</em> will be auto-loaded in " 00052 " the 'Filters' tab of this dialog. </p>" 00053 " <p>This tab is only visible if the external <em>'poster'</em> utility is " 00054 " discovered by TDEPrint on your system. [<em>'poster'</em> is a commandline " 00055 " utility that enables you to convert PostScript files into tiled printouts " 00056 " which allow for oversized appearance of the stitched-together tiles.] </p>" 00057 " <p><b>Note:</b> The standard version of 'poster' will not work. Your system " 00058 " must use a patched version of 'poster'. Ask your operating system vendor to " 00059 " provide a patched version of 'poster' if he does not already. </p>" 00060 " </qt>" ); 00061 00062 TQString whatsThisTileSelectionPosterPage = i18n( " <qt> " 00063 " <b>Tile Selection widget</b> " 00064 " <p>This GUI element is <em>not only for viewing</em> your selections: it also " 00065 " lets you interactively select the tile(s) you want to print. " 00066 " </p>" 00067 " <p><b>Hints</b> " 00068 " <ul> " 00069 " <li>Click any tile to select it for printing.</li> " 00070 " <li>To select multiple tiles to be printed " 00071 " at once, <em>'shift-click'</em> on the tiles ('shift-click' means: hold down the " 00072 " [SHIFT]-key on your keyboard and click with the mouse while [SHIFT]-key is held.) " 00073 " <em>Be aware</em> that the order " 00074 " of your clicking is also significant to the order of printing the different tiles. </li>" 00075 " </ul> " 00076 " <b>Note 1:</b> The order of your selection (and the order for printout of the tiles) " 00077 " is indicated by the contents of the text field below, " 00078 " labelled as <em>'Tile pages (to be printed):'</em><p>" 00079 " <b>Note 2:</b> By default no tile is selected. Before you can print (a part " 00080 " of) your poster, you must select at least one tile. </p> " 00081 " </qt>" ); 00082 00083 TQString whatsThisPostersizePosterPage = i18n( " <qt> " 00084 " <b>Poster Size</b> " 00085 " <p>Select the poster size you want from the dropdown list. </p> " 00086 " Available sizes are all standard paper sizes up to " 00087 " 'A0'. [A0 is the same size as 16 sheets of A4, or '84cm x 118.2cm'.] </p> " 00088 " <p><b>Notice</b>, how the little preview window below changes with your change of poster " 00089 " size. It indicates to you how many tiles need to be printed to make the poster, " 00090 " given the selected paper size.</p> " 00091 " <p><b>Hint:</b> The little preview window below is not just a passive icon. You can click " 00092 " on its individual tiles to select them for printing. To select multiple tiles to be printed " 00093 " at once, you need to <em>'shift-click'</em> on the tiles ('shift-click' means: hold down the " 00094 " [SHIFT]-key on your keyboard and click with the mouse while [SHIFT]-key is held.) The order " 00095 " of your clicking is significant to the order of printing the different tiles. The order of " 00096 " your selection (and for the printed tiles) is indicated by the contents of the text field " 00097 " labelled as <em>'Tile pages (to be printed):'</em><p>" 00098 " <b>Note:</b> By default no tile is selected. Before you can print (a part " 00099 " of) your poster, you must select at least one tile. </p> " 00100 " </qt>" ); 00101 00102 TQString whatsThisPrintsizePosterPage = i18n( " <qt> " 00103 " <b>Paper Size</b> " 00104 " <p>This field indicates the paper size the poster tiles will be printed on. " 00105 " To select a different paper size for your poster tiles, go to the 'General' tab " 00106 " of this dialog and select one from the dropdown list. </p> " 00107 " Available sizes are most standard paper sizes supported by your printer. Your printer's " 00108 " supported paper sizes are read from the printer driver info (as laid down in the <em>'PPD'</em>, " 00109 " the printer description file). <em>Be aware that the 'Paper Size' selected may not be supported " 00110 " by 'poster' (example: 'HalfLetter') while it may well be supported by your printer.</em> If " 00111 " you hit that obstacle, simply use another, supported Paper Size, like 'A4' or 'Letter'. " 00112 " <p><b>Notice</b>, how the little preview window below changes with your change of paper " 00113 " size. It indicates how many tiles need to be printed to make up the poster, " 00114 " given the selected paper and poster size.</p> " 00115 " <p><b>Hint:</b> The little preview window below is not just a passive icon. You can click " 00116 " on its individual tiles to select them for printing. To select multiple tiles to be printed " 00117 " at once, you need to <em>'shift-click'</em> on the tiles ('shift-click' means: hold down the " 00118 " [SHIFT]-key on your keyboard and click with the mouse while [SHIFT]-key is held.) The order " 00119 " of your clicking is significant to the order of printing the different tiles. The order of " 00120 " your selection (and for the printed tiles) is indicated by the contents of the text field " 00121 " labelled as <em>'Tile pages (to be printed):'</em><p>" 00122 " <b>Note:</b> By default no tile is selected. Before you can print (a part " 00123 " of) your poster, you must select at least one tile. </p> " 00124 " </qt>" ); 00125 00126 TQString whatsThisCutmarginPosterPage = i18n( " <qt> " 00127 " <b>Cut Margin selection</b> " 00128 " <p>Slider and spinbox let you determine a <em>'cut margin'</em> which will be printed onto " 00129 " each tile of your poster to help you cut the pieces as needed. </p>" 00130 " <p><b>Notice</b>, how the little preview window above changes with your change of cut " 00131 " margins. It indicates to you how much space the cut margins will take away from each tile. " 00132 " <p><b>Be aware</b>, that your cut margins need to be equal to or greater than the margins your " 00133 " printer uses. The printer's capabilities are described in the <em>'ImageableArea'</em> " 00134 " keywords of its driver PPD file. </p> " 00135 " </qt>" ); 00136 00137 TQString whatsThisTileOrderSelectionPosterPage = i18n( " <qt> " 00138 " <b>Order and number of tile pages to be printed</b> " 00139 " <p>This field displays and sets the individual tiles to be printed, as well as the order " 00140 " for their printout. </p> " 00141 " You can file the field with 2 different methods: " 00142 " <ul> " 00143 " <li>Either use the interactive thumbnail preview above and '[SHIFT]-click' on the tiles. </li> " 00144 " <li>Or edit this text field accordingly. </li> " 00145 " </ul> " 00146 " <p>When editing the field, you can use a '3-7' syntax instead of a '3,4,5,6,7' one. </p> " 00147 " <p><b>Examples:</b></p> " 00148 " <pre> " 00149 " \"2,3,7,9,3\" " 00150 " <br> " 00151 " \"1-3,6,8-11\" " 00152 " </qt>" ); 00153 00154 setTitle( i18n( "Poster" ) ); 00155 00156 m_postercheck = new TQCheckBox( i18n( "&Print poster" ), this ); 00157 TQWhatsThis::add(m_postercheck, whatsThisEnablePosterPage); 00158 TQWidget *dummy = new TQWidget( this ); 00159 m_preview = new PosterPreview( dummy ); 00160 TQWhatsThis::add(m_preview, whatsThisTileSelectionPosterPage); 00161 m_postersize = new TQComboBox( dummy ); 00162 TQWhatsThis::add(m_postersize, whatsThisPostersizePosterPage); 00163 m_printsize = new TQComboBox( dummy ); 00164 TQWhatsThis::add(m_printsize, whatsThisPrintsizePosterPage); 00165 m_lockbtn = new KPushButton( dummy ); 00166 //TQWhatsThis::add(m_lockbtn, whatsThis5_PosterPage); //FIXME ASK_MICHAEL: which pushbutton would that be? 00167 m_mediasize = new TQLabel( dummy ); 00168 TQWhatsThis::add(m_mediasize, whatsThisPrintsizePosterPage); 00169 m_mediasize->setFrameStyle( TQFrame::Panel|TQFrame::Sunken ); 00170 TQLabel *posterlab = new TQLabel( i18n( "Poste&r size:" ), dummy ); 00171 TQWhatsThis::add(posterlab, whatsThisPostersizePosterPage); 00172 TQLabel *medialab = new TQLabel( i18n( "Media size:" ), dummy ); 00173 TQWhatsThis::add(medialab, whatsThisPrintsizePosterPage); 00174 TQLabel *printlab = new TQLabel( i18n( "Pri&nt size:" ), dummy ); 00175 TQWhatsThis::add(printlab, whatsThisPrintsizePosterPage); 00176 posterlab->setBuddy( m_postersize ); 00177 printlab->setBuddy( m_printsize ); 00178 m_cutmargin = new KIntNumInput( 5, dummy ); 00179 TQWhatsThis::add(m_cutmargin, whatsThisCutmarginPosterPage); 00180 // xgettext:no-c-format 00181 m_cutmargin->setLabel( i18n( "C&ut margin (% of media):" ) ); 00182 m_cutmargin->setRange( 0, 100, 2, true ); // step width was too big, changed from 10 to 2 (-kp-) 00183 m_selection = new TQLineEdit( dummy ); 00184 TQWhatsThis::add(m_selection, whatsThisTileOrderSelectionPosterPage); 00185 TQLabel *selectionlab = new TQLabel( i18n( "&Tile pages (to be printed):" ), dummy ); 00186 TQWhatsThis::add(selectionlab, whatsThisTileOrderSelectionPosterPage); 00187 selectionlab->setBuddy( m_selection ); 00188 m_lockbtn->setToggleButton( true ); 00189 m_lockbtn->setPixmap( SmallIcon( "encrypted" ) ); 00190 m_lockbtn->setOn( true ); 00191 m_lockbtn->setFixedSize( m_lockbtn->sizeHint() ); 00192 TQToolTip::add( m_lockbtn, i18n( "Link/unlink poster and print size" ) ); 00193 00194 for ( int i=0; i<KPrinter::NPageSize-1; i++ ) 00195 { 00196 m_postersize->insertItem( page_sizes[ i ].text ); 00197 m_printsize->insertItem( page_sizes[ i ].text ); 00198 } 00199 m_postersize->setCurrentItem( findIndex( KPrinter::A3 ) ); 00200 slotPosterSizeChanged( m_postersize->currentItem() ); 00201 00202 connect( m_postercheck, TQT_SIGNAL( toggled( bool ) ), dummy, TQT_SLOT( setEnabled( bool ) ) ); 00203 dummy->setEnabled( false ); 00204 connect( m_postersize, TQT_SIGNAL( activated( int ) ), TQT_SLOT( slotPosterSizeChanged( int ) ) ); 00205 connect( m_cutmargin, TQT_SIGNAL( valueChanged( int ) ), TQT_SLOT( slotMarginChanged( int ) ) ); 00206 connect( m_lockbtn, TQT_SIGNAL( toggled( bool ) ), m_printsize, TQT_SLOT( setDisabled( bool ) ) ); 00207 m_printsize->setEnabled( false ); 00208 connect( m_lockbtn, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( slotLockToggled( bool ) ) ); 00209 connect( m_selection, TQT_SIGNAL( textChanged( const TQString& ) ), m_preview, TQT_SLOT( setSelectedPages( const TQString& ) ) ); 00210 connect( m_preview, TQT_SIGNAL( selectionChanged( const TQString& ) ), m_selection, TQT_SLOT( setText( const TQString& ) ) ); 00211 00212 if ( KMFactory::self()->settings()->application != KPrinter::Dialog 00213 && KMFactory::self()->settings()->application >= 0 ) 00214 { 00215 m_printsize->hide(); 00216 m_lockbtn->hide(); 00217 printlab->hide(); 00218 } 00219 00220 TQVBoxLayout *l0 = new TQVBoxLayout( this, 0, 10 ); 00221 l0->addWidget( m_postercheck ); 00222 l0->addWidget( dummy, 1 ); 00223 TQGridLayout *l1 = new TQGridLayout( dummy, 8, 3, 0, 5 ); 00224 l1->addWidget( posterlab, 0, 0 ); 00225 l1->addWidget( m_postersize, 0, 1 ); 00226 l1->addWidget( printlab, 1, 0 ); 00227 l1->addWidget( m_printsize, 1, 1 ); 00228 l1->addWidget( medialab, 2, 0 ); 00229 l1->addWidget( m_mediasize, 2, 1 ); 00230 l1->addMultiCellWidget( m_preview, 4, 4, 0, 2 ); 00231 l1->addMultiCellWidget( m_cutmargin, 6, 6, 0, 2 ); 00232 l1->addMultiCellWidget( m_lockbtn, 0, 1, 2, 2 ); 00233 TQHBoxLayout *l2 = new TQHBoxLayout( 0, 0, 5 ); 00234 l1->addMultiCellLayout( l2, 7, 7, 0, 2 ); 00235 l2->addWidget( selectionlab ); 00236 l2->addWidget( m_selection ); 00237 l1->setColStretch( 1, 1 ); 00238 l1->setRowStretch( 4, 1 ); 00239 l1->addRowSpacing( 3, 10 ); 00240 l1->addRowSpacing( 5, 10 ); 00241 } 00242 00243 KPPosterPage::~KPPosterPage() 00244 { 00245 } 00246 00247 void KPPosterPage::setOptions( const TQMap<TQString,TQString>& opts ) 00248 { 00249 TQString ps = opts[ "PageSize" ]; 00250 if ( ps.isEmpty() && !opts[ "kde-pagesize" ].isEmpty() ) 00251 { 00252 ps = pageSizeToPageName( ( KPrinter::PageSize )opts[ "kde-pagesize" ].toInt() ); 00253 if ( ps.isEmpty() ) 00254 ps = opts[ "_kde-poster-media" ]; 00255 } 00256 if ( ps.isEmpty() ) 00257 m_mediasize->setText( i18n( "Unknown" ) ); 00258 else 00259 m_mediasize->setText( ps ); 00260 m_preview->setMediaSize( ps ); 00261 00262 if ( opts[ "_kde-filters" ].find( "poster" ) != -1 ) 00263 { 00264 m_postercheck->setChecked( true ); 00265 ps = opts[ "_kde-poster-size" ]; 00266 TQString prtsize = opts[ "kde-printsize" ]; 00267 if ( !ps.isEmpty() ) 00268 { 00269 m_postersize->setCurrentItem( findIndex( pageNameToPageSize( ps ) ) ); 00270 m_lockbtn->setOn( !prtsize.isEmpty() && 00271 page_sizes[ m_postersize->currentItem() ].ID == prtsize.toInt() ); 00272 if ( !m_lockbtn->isOn() ) 00273 m_printsize->setCurrentItem( findIndex( prtsize.toInt() ) ); 00274 slotPosterSizeChanged( m_postersize->currentItem() ); 00275 } 00276 if ( !opts[ "_kde-poster-cut" ].isEmpty() ) 00277 m_cutmargin->setValue( opts[ "_kde-poster-cut" ].toInt() ); 00278 m_selection->setText( opts[ "_kde-poster-select" ] ); 00279 } 00280 else 00281 m_postercheck->setChecked( false ); 00282 } 00283 00284 void KPPosterPage::getOptions( TQMap<TQString,TQString>& opts, bool ) 00285 { 00286 TQStringList o = TQStringList::split( ",", opts[ "_kde-filters" ], false ); 00287 if ( !m_postercheck->isChecked() ) 00288 { 00289 o.remove( "poster" ); 00290 opts[ "_kde-filters" ] = o.join( "," ); 00291 opts.remove( "_kde-poster-media" ); 00292 opts.remove( "_kde-poster-size" ); 00293 opts.remove( "_kde-poster-cut" ); 00294 opts.remove( "kde-printsize" ); 00295 opts.remove( "_kde-poster-select" ); 00296 } 00297 else 00298 { 00299 if ( !o.contains( "poster" ) ) 00300 o.append( "poster" ); 00301 opts[ "_kde-filters" ] = o.join( "," ); 00302 opts[ "_kde-poster-media" ] = m_mediasize->text(); 00303 opts[ "_kde-poster-size" ] = pageSizeToPageName( ( KPrinter::PageSize )page_sizes[ m_postersize->currentItem() ].ID ); 00304 opts[ "kde-printsize" ] = TQString::number( page_sizes[ m_printsize->currentItem() ].ID ); 00305 opts[ "_kde-poster-cut" ] = TQString::number( m_cutmargin->value() ); 00306 opts[ "_kde-poster-select" ] = m_selection->text().stripWhiteSpace(); 00307 } 00308 } 00309 00310 bool KPPosterPage::isValid() 00311 { 00312 return true; 00313 } 00314 00315 void KPPosterPage::slotPosterSizeChanged( int value ) 00316 { 00317 int ID = page_sizes[ m_postersize->currentItem() ].ID; 00318 m_preview->setPosterSize( ID ); 00319 if ( m_lockbtn->isOn() ) 00320 m_printsize->setCurrentItem( value ); 00321 } 00322 00323 void KPPosterPage::slotMarginChanged( int value ) 00324 { 00325 m_preview->setCutMargin( value ); 00326 } 00327 00328 void KPPosterPage::slotLockToggled( bool on ) 00329 { 00330 m_lockbtn->setPixmap( SmallIcon( on ? "encrypted" : "decrypted" ) ); 00331 if ( on ) 00332 m_printsize->setCurrentItem( m_postersize->currentItem() ); 00333 } 00334 00335 #include "kpposterpage.moc"