kpresenter

KPrBackDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <KoPictureFilePreview.h>
21#include "KPrBackDia.h"
22#include "KPrBackground.h"
23#include "KPrDocument.h"
24#include "KPrPage.h"
25
26#include <tqlabel.h>
27#include <tqpainter.h>
28#include <tqcombobox.h>
29#include <tqslider.h>
30#include <tqlayout.h>
31#include <tqtabwidget.h>
32#include <tqvbox.h>
33#include <tqcheckbox.h>
34#include <tqdatetime.h>
35
36#include <kcolorbutton.h>
37#include <tdelocale.h>
38#include <tdefiledialog.h>
39#include <kimageio.h>
40#include <kbuttonbox.h>
41#include <kurlrequester.h>
42
43#include <KoPicture.h>
44
45KPrBackPreview::KPrBackPreview( TQWidget *parent, KPrPage *page )
46 : TQFrame( parent )
47{
48 setFrameStyle( WinPanel | Sunken );
49 back = new KPrBackGround( page );
50 setMinimumSize( 300, 200 );
51}
52
53KPrBackPreview::~KPrBackPreview()
54{
55 delete back;
56}
57
58void KPrBackPreview::drawContents( TQPainter *p )
59{
60 TQFrame::drawContents( p );
61 p->save();
62 p->translate( contentsRect().x(), contentsRect().y() );
63 back->drawBackground( p, contentsRect().size(), contentsRect(), false );
64 p->restore();
65}
66
67KPrBackDialog::KPrBackDialog( TQWidget* parent, const char* name,
68 BackType backType, const TQColor &backColor1,
69 const TQColor &backColor2, BCType _bcType,
70 const KoPicture &backPic,
71 BackView backPicView, bool _unbalanced,
72 int _xfactor, int _yfactor, KPrPage *_page )
73 : KDialogBase( parent, name, true, "",KDialogBase::Ok|KDialogBase::Apply|KDialogBase::Cancel|
74 KDialogBase::User1|KDialogBase::User2 ),
75 m_useMasterBackground( 0 ), m_picture(backPic),m_oldpicture(backPic), m_page( _page )
76{
77 lockUpdate = true;
78
79 oldUseMasterBackground=m_page->useMasterBackground();
80 oldBackType=backType;
81 oldBackColor1=backColor1;
82 oldBackColor2 = backColor2;
83 oldBcType= _bcType;
84 oldBackPicView=backPicView;
85 oldUnbalanced=_unbalanced;
86 oldXFactor=_xfactor;
87 oldYFactor=_yfactor;
88
89 TQWidget *page = new TQWidget( this );
90 setMainWidget(page);
91 TQVBoxLayout *layout = new TQVBoxLayout( page, 0, spacingHint() );
92
93
94 TQHBoxLayout *hbox = new TQHBoxLayout( layout );
95 hbox->setSpacing( KDialog::spacingHint() );
96 TQVBoxLayout *vbox = new TQVBoxLayout( hbox );
97 vbox->setSpacing( KDialog::spacingHint() );
98
99 if ( !m_page->isMasterPage() )
100 {
101 m_useMasterBackground = new TQCheckBox( i18n( "Use slide master background" ), page );
102 connect( m_useMasterBackground, TQ_SIGNAL( clicked() ),
103 this, TQ_SLOT( updateConfiguration() ) );
104 m_useMasterBackground->setChecked( m_page->useMasterBackground() );
105 vbox->addWidget( m_useMasterBackground );
106 }
107 vbox->addWidget( new TQLabel( i18n( "Background type:" ), page ) );
108
109 backCombo = new TQComboBox( false, page );
110 backCombo->insertItem( i18n( "Color/Gradient" ) );
111 backCombo->insertItem( i18n( "Picture" ) );
112 backCombo->setCurrentItem( (int)backType );
113 connect( backCombo, TQ_SIGNAL( activated( int ) ),
114 this, TQ_SLOT( changeComboText(int) ) );
115
116 vbox->addWidget( backCombo );
117
118 tabWidget = new TQTabWidget( page );
119 vbox->addWidget( tabWidget );
120
121 // color/gradient tab ---------------
122
123 TQVBox *colorTab = new TQVBox( tabWidget );
124 colorTab->setSpacing( KDialog::spacingHint() );
125 colorTab->setMargin( 5 );
126
127 cType = new TQComboBox( false, colorTab );
128 cType->insertItem( i18n( "Plain" ) );
129 cType->insertItem( i18n( "Vertical Gradient" ) );
130 cType->insertItem( i18n( "Horizontal Gradient" ) );
131 cType->insertItem( i18n( "Diagonal Gradient 1" ) );
132 cType->insertItem( i18n( "Diagonal Gradient 2" ) );
133 cType->insertItem( i18n( "Circle Gradient" ) );
134 cType->insertItem( i18n( "Rectangle Gradient" ) );
135 cType->insertItem( i18n( "PipeCross Gradient" ) );
136 cType->insertItem( i18n( "Pyramid Gradient" ) );
137 cType->setCurrentItem( _bcType );
138 connect( cType, TQ_SIGNAL( activated( int ) ),
139 this, TQ_SLOT( updateConfiguration() ) );
140
141 color1Choose = new KColorButton( backColor1, colorTab );
142 connect( color1Choose, TQ_SIGNAL( changed( const TQColor& ) ),
143 this, TQ_SLOT( updateConfiguration() ) );
144
145 color2Choose = new KColorButton( backColor2, colorTab );
146 connect( color2Choose, TQ_SIGNAL( changed( const TQColor& ) ),
147 this, TQ_SLOT( updateConfiguration() ) );
148
149 unbalanced = new TQCheckBox( i18n( "Unbalanced" ), colorTab );
150 connect( unbalanced, TQ_SIGNAL( clicked() ),
151 this, TQ_SLOT( updateConfiguration() ) );
152 unbalanced->setChecked( _unbalanced );
153
154 labXFactor =new TQLabel( i18n( "X-factor:" ), colorTab );
155
156 xfactor = new TQSlider( -200, 200, 1, 100, TQt::Horizontal, colorTab );
157 connect( xfactor, TQ_SIGNAL( valueChanged( int ) ),
158 this, TQ_SLOT( updateConfiguration() ) );
159 xfactor->setValue( _xfactor );
160
161 labYFactor=new TQLabel( i18n( "Y-factor:" ), colorTab );
162
163 yfactor = new TQSlider( -200, 200, 1, 100, TQt::Horizontal, colorTab );
164 connect( yfactor, TQ_SIGNAL( valueChanged( int ) ),
165 this, TQ_SLOT( updateConfiguration() ) );
166 yfactor->setValue( _yfactor );
167
168 tabWidget->addTab( colorTab, i18n( "Color/Gradient" ) );
169
170 // picture tab ---------------------
171
172 TQVBox *picTab = new TQVBox( tabWidget );
173 picTab->setSpacing( KDialog::spacingHint() );
174 picTab->setMargin( 5 );
175
176 TQLabel *l = new TQLabel( i18n( "View mode:" ), picTab );
177 l->setFixedHeight( l->sizeHint().height() );
178
179 picView = new TQComboBox( false, picTab );
180 picView->insertItem( i18n( "Scaled" ) );
181 picView->insertItem( i18n( "Centered" ) );
182 picView->insertItem( i18n( "Tiled" ) );
183 picView->setCurrentItem( (int)backPicView );
184 connect( picView, TQ_SIGNAL( activated( int ) ),
185 this, TQ_SLOT( updateConfiguration() ) );
186
187 picChooseLabel = new TQLabel( i18n("&Location:"), picTab );
188 picChooseLabel->setFixedHeight( picChooseLabel->sizeHint().height() );
189
190 picChoose = new KURLRequester( picTab, "picChoose" );
191 picChoose->setFixedHeight( picChoose->sizeHint().height() );
192 picChoose->setMode( KFile::ExistingOnly );
193 connect( picChoose, TQ_SIGNAL( openFileDialog( KURLRequester * ) ),
194 TQ_SLOT( aboutToSelectPic() ) );
195 connect( picChoose, TQ_SIGNAL( urlSelected( const TQString & ) ),
196 TQ_SLOT( afterSelectPic( const TQString & ) ) );
197
198 picChooseLabel->setBuddy( picChoose );
199
200 (void)new TQWidget( picTab );
201
202 tabWidget->addTab( picTab, i18n( "Picture" ) );
203
204 // ------------------------ preview
205
206 preview = new KPrBackPreview( page, m_page );
207 hbox->addWidget( preview );
208
209 // ------------------------ buttons
210
211 connect( this, TQ_SIGNAL( okClicked() ),
212 this, TQ_SLOT( Ok() ) );
213 connect( this, TQ_SIGNAL( applyClicked() ),
214 this, TQ_SLOT( Apply() ) );
215 connect( this, TQ_SIGNAL( user1Clicked() ),
216 this, TQ_SLOT( ApplyGlobal() ) );
217
218 connect( this, TQ_SIGNAL( user2Clicked() ),
219 this, TQ_SLOT( slotReset() ) );
220
221 connect( this, TQ_SIGNAL( okClicked() ),
222 this, TQ_SLOT( accept() ) );
223 setButtonText(KDialogBase::User1,i18n( "Apply &Global" ));
224 setButtonText(KDialogBase::User2,i18n( "&Reset" ));
225 picChanged = true;
226 lockUpdate = false;
227 updateConfiguration();
228}
229
230void KPrBackDialog::slotReset()
231{
232 if ( m_useMasterBackground )
233 m_useMasterBackground->setChecked( oldUseMasterBackground );
234 backCombo->setCurrentItem( (int)oldBackType );
235 color1Choose->setColor( oldBackColor1 );
236 color2Choose->setColor( oldBackColor2 );
237 cType->setCurrentItem( oldBcType );
238
239 m_picture=m_oldpicture;
240
241 if ( !m_picture.isNull() )
242 picChoose->setURL( m_picture.getKey().filename() );
243 else
244 picChoose->setURL( TQString() );
245
246 picView->setCurrentItem( (int)oldBackPicView );
247 unbalanced->setChecked( oldUnbalanced );
248 xfactor->setValue( oldXFactor );
249 yfactor->setValue( oldYFactor );
250 updateConfiguration();
251}
252
253void KPrBackDialog::changeComboText(int _p)
254{
255 if(_p!=tabWidget->currentPageIndex ())
256 tabWidget->setCurrentPage(_p);
257 updateConfiguration();
258}
259
260void KPrBackDialog::showEvent( TQShowEvent *e )
261{
262 TQDialog::showEvent( e );
263 lockUpdate = false;
264 updateConfiguration();
265}
266
267void KPrBackDialog::updateConfiguration()
268{
269 if ( lockUpdate )
270 return;
271
272 if ( m_useMasterBackground )
273 {
274 tabWidget->setEnabled( !m_useMasterBackground->isChecked() );
275 backCombo->setEnabled( !m_useMasterBackground->isChecked() );
276 }
277 else
278 {
279 tabWidget->setEnabled( true );
280 backCombo->setEnabled( true );
281 }
282 if ( getBackColorType() == BCT_PLAIN )
283 {
284 unbalanced->setEnabled( false );
285 xfactor->setEnabled( false );
286 yfactor->setEnabled( false );
287 labXFactor->setEnabled(false);
288 labYFactor->setEnabled(false);
289 color2Choose->setEnabled( false );
290 }
291 else
292 {
293 unbalanced->setEnabled( true );
294 if ( unbalanced->isChecked() )
295 {
296 xfactor->setEnabled( true );
297 yfactor->setEnabled( true );
298 labXFactor->setEnabled(true);
299 labYFactor->setEnabled(true);
300 }
301 else
302 {
303 xfactor->setEnabled( false );
304 yfactor->setEnabled( false );
305 labXFactor->setEnabled(false);
306 labYFactor->setEnabled(false);
307 }
308 color2Choose->setEnabled( true );
309 }
310
311 if ( m_useMasterBackground && m_useMasterBackground->isChecked() )
312 {
313 kdDebug(33001) << "set backgound to master" << endl;
314 preview->backGround()->setBackGround( m_page->masterPage()->background()->getBackGround() );
315 preview->repaint( true );
316 }
317 else
318 {
319 picChanged = (getBackType() == BT_PICTURE);
320 preview->backGround()->setBackType( getBackType() );
321 preview->backGround()->setBackView( getBackView() );
322 preview->backGround()->setBackColor1( getBackColor1() );
323 preview->backGround()->setBackColor2( getBackColor2() );
324 preview->backGround()->setBackColorType( getBackColorType() );
325 preview->backGround()->setBackUnbalanced( getBackUnbalanced() );
326 preview->backGround()->setBackXFactor( getBackXFactor() );
327 preview->backGround()->setBackYFactor( getBackYFactor() );
328 if ( !m_picture.isNull() && picChanged )
329 preview->backGround()->setBackPicture( m_picture );
330 preview->backGround()->setBackType( getBackType() );
331 if ( preview->isVisible() && isVisible() ) {
332 preview->backGround()->reload(); // ### TODO: instead of reloading, load or remove the picture correctly.
333 preview->repaint( true );
334 }
335
336 picChanged = false;
337 }
338}
339
340BackType KPrBackDialog::getBackType() const
341{
342 return (BackType)backCombo->currentItem();
343}
344
345BackView KPrBackDialog::getBackView() const
346{
347 return (BackView)picView->currentItem();
348}
349
350TQColor KPrBackDialog::getBackColor1() const
351{
352 return color1Choose->color();
353}
354
355TQColor KPrBackDialog::getBackColor2() const
356{
357 return color2Choose->color();
358}
359
360BCType KPrBackDialog::getBackColorType() const
361{
362 return (BCType)cType->currentItem();
363}
364
365bool KPrBackDialog::getBackUnbalanced() const
366{
367 return unbalanced->isChecked();
368}
369
370int KPrBackDialog::getBackXFactor() const
371{
372 return xfactor->value();
373}
374
375int KPrBackDialog::getBackYFactor() const
376{
377 return yfactor->value();
378}
379
380KPrBackGround::Settings KPrBackDialog::getBackGround() const
381{
382 return KPrBackGround::Settings( getBackType(), getBackColor1(),
383 getBackColor2(), getBackColorType(),
384 getBackUnbalanced(), getBackXFactor(),
385 getBackYFactor(), getBackPicture().getKey(),
386 getBackView() );
387}
388
389bool KPrBackDialog::useMasterBackground() const
390{
391 return m_useMasterBackground ? m_useMasterBackground->isChecked():false;
392}
393
394void KPrBackDialog::aboutToSelectPic()
395{
396 TQStringList mimetypes;
397 mimetypes += KImageIO::mimeTypes( KImageIO::Reading );
398 mimetypes += KoPictureFilePreview::clipartMimeTypes();
399
400 picChoose->fileDialog()->setMimeFilter( mimetypes );
401 picChoose->fileDialog()->setPreviewWidget( new KoPictureFilePreview( picChoose->fileDialog() ) );
402}
403
404void KPrBackDialog::afterSelectPic( const TQString &url )
405{
406 KoPicture picture;
407 picture.setKeyAndDownloadPicture(url, tabWidget);
408
409 if ( picture.isNull() )
410 return;
411
412 backCombo->setCurrentItem( 1 );
413 m_picture=picture;
414 picChanged = true;
415 updateConfiguration();
416}
417
418#include "KPrGradient.h"
419#include "KPrBackDia.moc"