kpresenter

KPrBackDia.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
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 as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
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 <KoPictureFilePreview.h>
00022 #include "KPrBackDia.h"
00023 #include "KPrBackground.h"
00024 #include "KPrDocument.h"
00025 #include "KPrPage.h"
00026 
00027 #include <qlabel.h>
00028 #include <qpainter.h>
00029 #include <qcombobox.h>
00030 #include <qslider.h>
00031 #include <qlayout.h>
00032 #include <qtabwidget.h>
00033 #include <qvbox.h>
00034 #include <qcheckbox.h>
00035 #include <qdatetime.h>
00036 
00037 #include <kcolorbutton.h>
00038 #include <klocale.h>
00039 #include <kfiledialog.h>
00040 #include <kimageio.h>
00041 #include <kbuttonbox.h>
00042 #include <kurlrequester.h>
00043 
00044 #include <KoPicture.h>
00045 
00046 KPrBackPreview::KPrBackPreview( QWidget *parent, KPrPage *page )
00047     : QFrame( parent )
00048 {
00049     setFrameStyle( WinPanel | Sunken );
00050     back = new KPrBackGround( page );
00051     setMinimumSize( 300, 200 );
00052 }
00053 
00054 KPrBackPreview::~KPrBackPreview()
00055 {
00056     delete back;
00057 }
00058 
00059 void KPrBackPreview::drawContents( QPainter *p )
00060 {
00061     QFrame::drawContents( p );
00062     p->save();
00063     p->translate( contentsRect().x(), contentsRect().y() );
00064     back->drawBackground( p, contentsRect().size(), contentsRect(), false );
00065     p->restore();
00066 }
00067 
00068 KPrBackDialog::KPrBackDialog( QWidget* parent, const char* name,
00069                   BackType backType, const QColor &backColor1,
00070                   const QColor &backColor2, BCType _bcType,
00071                   const KoPicture &backPic,
00072                   BackView backPicView, bool _unbalanced,
00073                   int _xfactor, int _yfactor, KPrPage *_page )
00074     : KDialogBase( parent, name, true, "",KDialogBase::Ok|KDialogBase::Apply|KDialogBase::Cancel|
00075                    KDialogBase::User1|KDialogBase::User2 ),
00076       m_useMasterBackground( 0 ), m_picture(backPic),m_oldpicture(backPic), m_page( _page )
00077 {
00078     lockUpdate = true;
00079 
00080     oldUseMasterBackground=m_page->useMasterBackground();
00081     oldBackType=backType;
00082     oldBackColor1=backColor1;
00083     oldBackColor2 = backColor2;
00084     oldBcType= _bcType;
00085     oldBackPicView=backPicView;
00086     oldUnbalanced=_unbalanced;
00087     oldXFactor=_xfactor;
00088     oldYFactor=_yfactor;
00089 
00090     QWidget *page = new QWidget( this );
00091     setMainWidget(page);
00092     QVBoxLayout *layout = new QVBoxLayout( page, 0, spacingHint() );
00093 
00094 
00095     QHBoxLayout *hbox = new QHBoxLayout( layout );
00096     hbox->setSpacing( KDialog::spacingHint() );
00097     QVBoxLayout *vbox = new QVBoxLayout( hbox );
00098     vbox->setSpacing( KDialog::spacingHint() );
00099 
00100     if ( !m_page->isMasterPage() )
00101     {
00102         m_useMasterBackground = new QCheckBox( i18n( "Use slide master background" ), page );
00103         connect( m_useMasterBackground, SIGNAL( clicked() ),
00104                  this, SLOT( updateConfiguration() ) );
00105         m_useMasterBackground->setChecked( m_page->useMasterBackground() );
00106         vbox->addWidget( m_useMasterBackground );
00107     }
00108     vbox->addWidget( new QLabel( i18n( "Background type:" ), page ) );
00109 
00110     backCombo = new QComboBox( false, page );
00111     backCombo->insertItem( i18n( "Color/Gradient" ) );
00112     backCombo->insertItem( i18n( "Picture" ) );
00113     backCombo->setCurrentItem( (int)backType );
00114     connect( backCombo, SIGNAL( activated( int ) ),
00115              this, SLOT( changeComboText(int) ) );
00116 
00117     vbox->addWidget( backCombo );
00118 
00119     tabWidget = new QTabWidget( page );
00120     vbox->addWidget( tabWidget );
00121 
00122     // color/gradient tab ---------------
00123 
00124     QVBox *colorTab = new QVBox( tabWidget );
00125     colorTab->setSpacing( KDialog::spacingHint() );
00126     colorTab->setMargin( 5 );
00127 
00128     cType = new QComboBox( false, colorTab );
00129     cType->insertItem( i18n( "Plain" ) );
00130     cType->insertItem( i18n( "Vertical Gradient" ) );
00131     cType->insertItem( i18n( "Horizontal Gradient" ) );
00132     cType->insertItem( i18n( "Diagonal Gradient 1" ) );
00133     cType->insertItem( i18n( "Diagonal Gradient 2" ) );
00134     cType->insertItem( i18n( "Circle Gradient" ) );
00135     cType->insertItem( i18n( "Rectangle Gradient" ) );
00136     cType->insertItem( i18n( "PipeCross Gradient" ) );
00137     cType->insertItem( i18n( "Pyramid Gradient" ) );
00138     cType->setCurrentItem( _bcType );
00139     connect( cType, SIGNAL( activated( int ) ),
00140              this, SLOT( updateConfiguration() ) );
00141 
00142     color1Choose = new KColorButton( backColor1, colorTab );
00143     connect( color1Choose, SIGNAL( changed( const QColor& ) ),
00144              this, SLOT( updateConfiguration() ) );
00145 
00146     color2Choose = new KColorButton( backColor2, colorTab );
00147     connect( color2Choose, SIGNAL( changed( const QColor& ) ),
00148              this, SLOT( updateConfiguration() ) );
00149 
00150     unbalanced = new QCheckBox( i18n( "Unbalanced" ), colorTab );
00151     connect( unbalanced, SIGNAL( clicked() ),
00152              this, SLOT( updateConfiguration() ) );
00153     unbalanced->setChecked( _unbalanced );
00154 
00155     labXFactor =new QLabel( i18n( "X-factor:" ), colorTab );
00156 
00157     xfactor = new QSlider( -200, 200, 1, 100, QSlider::Horizontal, colorTab );
00158     connect( xfactor, SIGNAL( valueChanged( int ) ),
00159              this, SLOT( updateConfiguration() ) );
00160     xfactor->setValue( _xfactor );
00161 
00162     labYFactor=new QLabel( i18n( "Y-factor:" ), colorTab );
00163 
00164     yfactor = new QSlider( -200, 200, 1, 100, QSlider::Horizontal, colorTab );
00165     connect( yfactor, SIGNAL( valueChanged( int ) ),
00166              this, SLOT( updateConfiguration() ) );
00167     yfactor->setValue( _yfactor );
00168 
00169     tabWidget->addTab( colorTab, i18n( "Color/Gradient" ) );
00170 
00171     // picture tab ---------------------
00172 
00173     QVBox *picTab = new QVBox( tabWidget );
00174     picTab->setSpacing( KDialog::spacingHint() );
00175     picTab->setMargin( 5 );
00176 
00177     QLabel *l = new QLabel( i18n( "View mode:" ), picTab );
00178     l->setFixedHeight( l->sizeHint().height() );
00179 
00180     picView = new QComboBox( false, picTab );
00181     picView->insertItem( i18n( "Scaled" ) );
00182     picView->insertItem( i18n( "Centered" ) );
00183     picView->insertItem( i18n( "Tiled" ) );
00184     picView->setCurrentItem( (int)backPicView );
00185     connect( picView, SIGNAL( activated( int ) ),
00186              this, SLOT( updateConfiguration() ) );
00187 
00188     picChooseLabel = new QLabel( i18n("&Location:"), picTab );
00189     picChooseLabel->setFixedHeight( picChooseLabel->sizeHint().height() );
00190 
00191     picChoose = new KURLRequester( picTab, "picChoose" );
00192     picChoose->setFixedHeight( picChoose->sizeHint().height() );
00193     picChoose->setMode( KFile::ExistingOnly );
00194     connect( picChoose, SIGNAL( openFileDialog( KURLRequester * ) ),
00195              SLOT( aboutToSelectPic() ) );
00196     connect( picChoose, SIGNAL( urlSelected( const QString & ) ),
00197              SLOT( afterSelectPic( const QString & ) ) );
00198 
00199     picChooseLabel->setBuddy( picChoose );
00200 
00201     (void)new QWidget( picTab );
00202 
00203     tabWidget->addTab( picTab, i18n( "Picture" ) );
00204 
00205     // ------------------------ preview
00206 
00207     preview = new KPrBackPreview( page, m_page );
00208     hbox->addWidget( preview );
00209 
00210     // ------------------------ buttons
00211 
00212     connect( this, SIGNAL( okClicked() ),
00213              this, SLOT( Ok() ) );
00214     connect( this, SIGNAL( applyClicked() ),
00215              this, SLOT( Apply() ) );
00216     connect( this, SIGNAL(  user1Clicked() ),
00217              this, SLOT( ApplyGlobal() ) );
00218 
00219     connect( this, SIGNAL(  user2Clicked() ),
00220              this, SLOT( slotReset() ) );
00221 
00222     connect( this, SIGNAL( okClicked() ),
00223              this, SLOT( accept() ) );
00224     setButtonText(KDialogBase::User1,i18n( "Apply &Global" ));
00225     setButtonText(KDialogBase::User2,i18n( "&Reset" ));
00226     picChanged = true;
00227     lockUpdate = false;
00228     updateConfiguration();
00229 }
00230 
00231 void KPrBackDialog::slotReset()
00232 {
00233     if ( m_useMasterBackground )
00234         m_useMasterBackground->setChecked( oldUseMasterBackground );
00235     backCombo->setCurrentItem( (int)oldBackType );
00236     color1Choose->setColor( oldBackColor1 );
00237     color2Choose->setColor( oldBackColor2 );
00238     cType->setCurrentItem( oldBcType );
00239 
00240     m_picture=m_oldpicture;
00241 
00242     if ( !m_picture.isNull() )
00243         picChoose->setURL( m_picture.getKey().filename() );
00244     else
00245         picChoose->setURL( QString::null );
00246 
00247     picView->setCurrentItem( (int)oldBackPicView );
00248     unbalanced->setChecked( oldUnbalanced );
00249     xfactor->setValue( oldXFactor );
00250     yfactor->setValue( oldYFactor );
00251     updateConfiguration();
00252 }
00253 
00254 void KPrBackDialog::changeComboText(int _p)
00255 {
00256     if(_p!=tabWidget->currentPageIndex ())
00257         tabWidget->setCurrentPage(_p);
00258     updateConfiguration();
00259 }
00260 
00261 void KPrBackDialog::showEvent( QShowEvent *e )
00262 {
00263     QDialog::showEvent( e );
00264     lockUpdate = false;
00265     updateConfiguration();
00266 }
00267 
00268 void KPrBackDialog::updateConfiguration()
00269 {
00270     if ( lockUpdate )
00271         return;
00272 
00273     if ( m_useMasterBackground )
00274     {
00275         tabWidget->setEnabled( !m_useMasterBackground->isChecked() );
00276         backCombo->setEnabled( !m_useMasterBackground->isChecked() );
00277     }
00278     else
00279     {
00280         tabWidget->setEnabled( true );
00281         backCombo->setEnabled( true );
00282     }
00283     if ( getBackColorType() == BCT_PLAIN )
00284     {
00285         unbalanced->setEnabled( false );
00286         xfactor->setEnabled( false );
00287         yfactor->setEnabled( false );
00288         labXFactor->setEnabled(false);
00289         labYFactor->setEnabled(false);
00290         color2Choose->setEnabled( false );
00291     }
00292     else
00293     {
00294         unbalanced->setEnabled( true );
00295         if ( unbalanced->isChecked() )
00296         {
00297             xfactor->setEnabled( true );
00298             yfactor->setEnabled( true );
00299             labXFactor->setEnabled(true);
00300             labYFactor->setEnabled(true);
00301         }
00302         else
00303         {
00304             xfactor->setEnabled( false );
00305             yfactor->setEnabled( false );
00306             labXFactor->setEnabled(false);
00307             labYFactor->setEnabled(false);
00308         }
00309         color2Choose->setEnabled( true );
00310     }
00311 
00312     if ( m_useMasterBackground && m_useMasterBackground->isChecked() )
00313     {
00314         kdDebug(33001) << "set backgound to master" << endl;
00315         preview->backGround()->setBackGround( m_page->masterPage()->background()->getBackGround() );
00316         preview->repaint( true );
00317     }
00318     else
00319     {
00320         picChanged = (getBackType() == BT_PICTURE);
00321         preview->backGround()->setBackType( getBackType() );
00322         preview->backGround()->setBackView( getBackView() );
00323         preview->backGround()->setBackColor1( getBackColor1() );
00324         preview->backGround()->setBackColor2( getBackColor2() );
00325         preview->backGround()->setBackColorType( getBackColorType() );
00326         preview->backGround()->setBackUnbalanced( getBackUnbalanced() );
00327         preview->backGround()->setBackXFactor( getBackXFactor() );
00328         preview->backGround()->setBackYFactor( getBackYFactor() );
00329         if ( !m_picture.isNull() && picChanged )
00330             preview->backGround()->setBackPicture( m_picture );
00331         preview->backGround()->setBackType( getBackType() );
00332         if ( preview->isVisible() && isVisible() ) {
00333             preview->backGround()->reload(); // ### TODO: instead of reloading, load or remove the picture correctly.
00334             preview->repaint( true );
00335         }
00336 
00337         picChanged  = false;
00338     }
00339 }
00340 
00341 BackType KPrBackDialog::getBackType() const
00342 {
00343     return (BackType)backCombo->currentItem();
00344 }
00345 
00346 BackView KPrBackDialog::getBackView() const
00347 {
00348     return (BackView)picView->currentItem();
00349 }
00350 
00351 QColor KPrBackDialog::getBackColor1() const
00352 {
00353     return color1Choose->color();
00354 }
00355 
00356 QColor KPrBackDialog::getBackColor2() const
00357 {
00358     return color2Choose->color();
00359 }
00360 
00361 BCType KPrBackDialog::getBackColorType() const
00362 {
00363     return (BCType)cType->currentItem();
00364 }
00365 
00366 bool KPrBackDialog::getBackUnbalanced() const
00367 {
00368     return unbalanced->isChecked();
00369 }
00370 
00371 int KPrBackDialog::getBackXFactor() const
00372 {
00373     return xfactor->value();
00374 }
00375 
00376 int KPrBackDialog::getBackYFactor() const
00377 {
00378     return yfactor->value();
00379 }
00380 
00381 KPrBackGround::Settings KPrBackDialog::getBackGround() const
00382 {
00383     return KPrBackGround::Settings( getBackType(), getBackColor1(),
00384                                    getBackColor2(), getBackColorType(),
00385                                    getBackUnbalanced(), getBackXFactor(),
00386                                    getBackYFactor(), getBackPicture().getKey(),
00387                                    getBackView() );
00388 }
00389 
00390 bool KPrBackDialog::useMasterBackground() const
00391 {
00392     return m_useMasterBackground ? m_useMasterBackground->isChecked():false;
00393 }
00394 
00395 void KPrBackDialog::aboutToSelectPic()
00396 {
00397     QStringList mimetypes;
00398     mimetypes += KImageIO::mimeTypes( KImageIO::Reading );
00399     mimetypes += KoPictureFilePreview::clipartMimeTypes();
00400 
00401     picChoose->fileDialog()->setMimeFilter( mimetypes );
00402     picChoose->fileDialog()->setPreviewWidget( new KoPictureFilePreview( picChoose->fileDialog() ) );
00403 }
00404 
00405 void KPrBackDialog::afterSelectPic( const QString &url )
00406 {
00407     KoPicture picture;
00408     picture.setKeyAndDownloadPicture(url, tabWidget);
00409 
00410     if ( picture.isNull() )
00411         return;
00412 
00413     backCombo->setCurrentItem( 1 );
00414     m_picture=picture;
00415     picChanged = true;
00416     updateConfiguration();
00417 }
00418 
00419 #include "KPrGradient.h"
00420 #include "KPrBackDia.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys