kpresenter

KPrSlideTransitionDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Ariya Hidayat <ariya@kde.org>
3 Copyright (C) 2004 Thorsten Zachmann <zachmann@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KPrSlideTransitionDia.h"
22
23#include <tdefiledialog.h>
24#include <tdelocale.h>
25#include <knuminput.h>
26#include <kstandarddirs.h>
27#include <kurlrequester.h>
28
29#include <tqcheckbox.h>
30#include <tqcombobox.h>
31#include <tqimage.h>
32#include <tqlabel.h>
33#include <tqpushbutton.h>
34
35#include "KPrBackground.h"
36#include "KPrCanvas.h"
37#include "KPrCommand.h"
38#include "KPrDocument.h"
39#include "KPrSoundPlayer.h"
40#include "KPrView.h"
41#include "KPrPage.h"
42#include "KPrPageEffects.h"
43#include "slidetransitionwidget.h"
44
45KPrSlideTransitionDia::KPrSlideTransitionDia( TQWidget *parent, const char *name, KPrView *view )
46: KDialogBase( parent, name, true, i18n( "Slide Transition" ), User1|Ok|Cancel, Ok, true )
47, m_dialog( new SlideTransitionWidget( this ) ), m_view( view ), m_soundPlayer(0), m_pageEffect( 0 )
48{
49 int pgnum = m_view->getCurrPgNum() - 1;
50 KPrPage *page = m_view->kPresenterDoc()->pageList().at( pgnum );
51 m_effect = page->getPageEffect();
52 m_effectSpeed = page->getPageEffectSpeed();
53 m_soundEffect = page->getPageSoundEffect();
54 m_soundFileName = page->getPageSoundFileName();
55 m_slideTime = page->getPageTimer();
56
57 // draw preview pix
58 m_view->getCanvas()->drawPageInPix( m_pixmap, pgnum, 60 );
59 int w = m_pixmap.width();
60 int h = m_pixmap.height();
61
62 if ( w > h )
63 {
64 h = 300 * h / w;
65 w = 300;
66 }
67 else
68 {
69 w = 300 * w / h;
70 h = 300;
71 }
72
73 const TQImage img(m_pixmap.convertToImage().smoothScale( w, h ));
74 m_pixmap.convertFromImage(img);
75
76 m_dialog->previewPixmap->setPixmap( m_pixmap );
77 m_dialog->previewPixmap->setFixedSize( w, h );
78 m_target.resize( m_pixmap.size() );
79 m_target.fill( TQt::black );
80
81 // fill effect combo
82 m_dialog->effectCombo->insertItem( i18n( "No Effect" ) );
83 m_dialog->effectCombo->insertItem( i18n( "Close Horizontal" ) );
84 m_dialog->effectCombo->insertItem( i18n( "Close Vertical" ) );
85 m_dialog->effectCombo->insertItem( i18n( "Close From All Directions" ) );
86 m_dialog->effectCombo->insertItem( i18n( "Open Horizontal" ) );
87 m_dialog->effectCombo->insertItem( i18n( "Open Vertical" ) );
88 m_dialog->effectCombo->insertItem( i18n( "Open From All Directions" ) );
89 m_dialog->effectCombo->insertItem( i18n( "Interlocking Horizontal 1" ) );
90 m_dialog->effectCombo->insertItem( i18n( "Interlocking Horizontal 2" ) );
91 m_dialog->effectCombo->insertItem( i18n( "Interlocking Vertical 1" ) );
92 m_dialog->effectCombo->insertItem( i18n( "Interlocking Vertical 2" ) );
93 m_dialog->effectCombo->insertItem( i18n( "Surround 1" ) );
94 m_dialog->effectCombo->insertItem( i18n( "Fly Away 1" ) );
95 m_dialog->effectCombo->insertItem( i18n( "Blinds Horizontal" ) );
96 m_dialog->effectCombo->insertItem( i18n( "Blinds Vertical" ) );
97 m_dialog->effectCombo->insertItem( i18n( "Box In" ) );
98 m_dialog->effectCombo->insertItem( i18n( "Box Out" ) );
99 m_dialog->effectCombo->insertItem( i18n( "Checkerboard Across" ) );
100 m_dialog->effectCombo->insertItem( i18n( "Checkerboard Down" ) );
101 m_dialog->effectCombo->insertItem( i18n( "Cover Down" ) );
102 m_dialog->effectCombo->insertItem( i18n( "Uncover Down" ) );
103 m_dialog->effectCombo->insertItem( i18n( "Cover Up" ) );
104 m_dialog->effectCombo->insertItem( i18n( "Uncover Up" ) );
105 m_dialog->effectCombo->insertItem( i18n( "Cover Left" ) );
106 m_dialog->effectCombo->insertItem( i18n( "Uncover Left" ) );
107 m_dialog->effectCombo->insertItem( i18n( "Cover Right" ) );
108 m_dialog->effectCombo->insertItem( i18n( "Uncover Right" ) );
109 m_dialog->effectCombo->insertItem( i18n( "Cover Left-Up" ) );
110 m_dialog->effectCombo->insertItem( i18n( "Uncover Left-Up" ) );
111 m_dialog->effectCombo->insertItem( i18n( "Cover Left-Down" ) );
112 m_dialog->effectCombo->insertItem( i18n( "Uncover Left-Down" ) );
113 m_dialog->effectCombo->insertItem( i18n( "Cover Right-Up" ) );
114 m_dialog->effectCombo->insertItem( i18n( "Uncover Right-Up" ) );
115 //TODO change the strings to use Down instead of Bottome to make them consistent
116 m_dialog->effectCombo->insertItem( i18n( "Cover Right-Bottom" ) );
117 m_dialog->effectCombo->insertItem( i18n( "Uncover Right-Bottom" ) );
118 m_dialog->effectCombo->insertItem( i18n( "Dissolve" ) );
119 m_dialog->effectCombo->insertItem( i18n( "Strips Left-Up" ) );
120 m_dialog->effectCombo->insertItem( i18n( "Strips Left-Down" ) );
121 m_dialog->effectCombo->insertItem( i18n( "Strips Right-Up" ) );
122 m_dialog->effectCombo->insertItem( i18n( "Strips Right-Down" ) );
123 m_dialog->effectCombo->insertItem( i18n( "Melting" ) );
124 m_dialog->effectCombo->insertItem( i18n( "Random Transition" ) );
125 m_dialog->effectCombo->setCurrentItem( static_cast<int>( m_effect ) );
126
127 // workaround, because Random Effect is always negative
128 if( m_effect == PEF_RANDOM )
129 m_dialog->effectCombo->setCurrentItem( m_dialog->effectCombo->count()-1 );
130
131 connect( m_dialog->effectCombo, TQ_SIGNAL( activated( int ) ), this, TQ_SLOT( effectChanged( int ) ) );
132
133 // setup speed combo
134 m_dialog->speedCombo->insertItem( i18n("Slow") );
135 m_dialog->speedCombo->insertItem( i18n("Medium") );
136 m_dialog->speedCombo->insertItem( i18n("Fast") );
137
138 m_dialog->speedCombo->setCurrentItem( m_effectSpeed );
139
140 connect( m_dialog->speedCombo, TQ_SIGNAL( activated( int ) ), this, TQ_SLOT( effectChanged( int ) ) );
141
142 // set up sound
143 m_dialog->soundCheckBox->setChecked( m_soundEffect );
144 m_dialog->soundRequester->setURL( m_soundFileName );
145 soundEffectChanged();
146 m_dialog->playButton->setIconSet( SmallIconSet( "media-playback-start" ) );
147 m_dialog->stopButton->setIconSet( SmallIconSet( "media-playback-stop" ) );
148 connect( m_dialog->playButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( playSound() ) );
149 connect( m_dialog->stopButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( stopSound() ) );
150
151 connect( m_dialog->soundCheckBox, TQ_SIGNAL( clicked()), this, TQ_SLOT( soundEffectChanged() ) );
152 connect( m_dialog->soundRequester, TQ_SIGNAL( openFileDialog( KURLRequester * ) ), this, TQ_SLOT( slotRequesterClicked( KURLRequester * ) ) );
153 connect( m_dialog->soundRequester, TQ_SIGNAL( textChanged( const TQString& ) ), this, TQ_SLOT( slotSoundFileChanged( const TQString& ) ) );
154
155 // set up automatic tansition
156 m_dialog->automaticTransitionInput->setRange( 1, 600, 1 );
157 m_dialog->automaticTransitionInput->setValue( m_slideTime );
158
159 // set up preview button
160 connect( m_dialog->previewButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( preview() ) );
161
162 setButtonText(KDialogBase::User1,i18n( "Apply &Global" ));
163
164 connect( this, TQ_SIGNAL( okClicked() ), this, TQ_SLOT( slotOk() ) );
165 connect( this, TQ_SIGNAL( user1Clicked() ), this, TQ_SLOT( slotUser1() ) );
166
167 setMainWidget( m_dialog );
168}
169
170
171KPrSlideTransitionDia::~KPrSlideTransitionDia()
172{
173 delete m_dialog;
174}
175
176
177void KPrSlideTransitionDia::effectChanged( int )
178{
179 preview();
180}
181
182
183void KPrSlideTransitionDia::preview()
184{
185 PageEffect effect = static_cast<PageEffect>( m_dialog->effectCombo->currentItem() );
186 if ( m_dialog->effectCombo->currentText() == i18n( "Random Transition" ) )
187 effect = PEF_RANDOM;
188
189 EffectSpeed effectSpeed = static_cast<EffectSpeed>( m_dialog->speedCombo->currentItem() );
190
191 if ( m_pageEffect )
192 {
193 m_pageEffectTimer.stop();
194 TQObject::disconnect( &m_pageEffectTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( slotDoPageEffect() ) );
195
196 m_pageEffect->finish();
197
198 delete m_pageEffect;
199 m_pageEffect = 0;
200 m_dialog->previewPixmap->repaint();
201 }
202
203 m_pageEffect = new KPrPageEffects( m_dialog->previewPixmap, m_target, effect, effectSpeed );
204 if ( m_pageEffect->doEffect() )
205 {
206 delete m_pageEffect;
207 m_pageEffect = 0;
208 m_dialog->previewPixmap->update();
209 }
210 else
211 {
212 connect( &m_pageEffectTimer, TQ_SIGNAL( timeout() ), TQ_SLOT( slotDoPageEffect() ) );
213 m_pageEffectTimer.start( 50, true );
214 }
215}
216
217
218void KPrSlideTransitionDia::slotDoPageEffect()
219{
220 if ( m_pageEffect->doEffect() )
221 {
222 m_pageEffectTimer.stop();
223 TQObject::disconnect( &m_pageEffectTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( slotDoPageEffect() ) );
224 delete m_pageEffect;
225 m_pageEffect = 0;
226 m_dialog->previewPixmap->update();
227 }
228 else
229 {
230 m_pageEffectTimer.start( 50, true );
231 }
232}
233
234
235void KPrSlideTransitionDia::slotRequesterClicked( KURLRequester * )
236{
237 TQString filter( getSoundFileFilter() );
238 m_dialog->soundRequester->fileDialog()->setFilter( filter );
239
240 // find the first "sound"-resource that contains files
241 TQStringList soundDirs = TDEGlobal::dirs()->resourceDirs( "sound" );
242 if ( !soundDirs.isEmpty() ) {
243 KURL soundURL;
244 TQDir dir;
245 dir.setFilter( TQDir::Files | TQDir::Readable );
246 TQStringList::ConstIterator it = soundDirs.begin();
247 while ( it != soundDirs.end() ) {
248 dir = *it;
249 if ( dir.isReadable() && dir.count() > 2 ) {
250 soundURL.setPath( *it );
251 m_dialog->soundRequester->fileDialog()->setURL( soundURL );
252 break;
253 }
254 ++it;
255 }
256 }
257}
258
259
260TQString KPrSlideTransitionDia::getSoundFileFilter()
261{
262 TQStringList fileList;
263 fileList << "wav" << "au" << "mp3" << "mp1" << "mp2" << "mpg" << "dat"
264 << "mpeg" << "ogg" << "cdda" << "cda " << "vcd" << "null";
265 fileList.sort();
266
267 bool comma = false;
268 TQString full, str;
269 for ( TQStringList::ConstIterator it = fileList.begin(); it != fileList.end(); ++it ) {
270 if ( comma )
271 str += '\n';
272 comma = true;
273 str += TQString( i18n( "*.%1|%2 Files" ) ).arg( *it ).arg( (*it).upper() );
274
275 full += TQString( "*.") + (*it) + ' ';
276 }
277
278 str = full + '|' + i18n( "All Supported Files" ) + '\n' + str;
279 str += "\n*|" + i18n( "All Files" );
280
281 return str;
282}
283
284
285void KPrSlideTransitionDia::soundEffectChanged()
286{
287 bool soundEffect = m_dialog->soundCheckBox->isChecked();
288
289 m_dialog->soundLabel->setEnabled( soundEffect );
290 m_dialog->soundRequester->setEnabled( soundEffect );
291
292 if ( !m_dialog->soundRequester->url().isEmpty() ) {
293 m_dialog->playButton->setEnabled( soundEffect );
294 m_dialog->stopButton->setEnabled( soundEffect );
295 }
296 else {
297 m_dialog->playButton->setEnabled( false );
298 m_dialog->stopButton->setEnabled( false );
299 }
300}
301
302
303void KPrSlideTransitionDia::slotSoundFileChanged( const TQString& text )
304{
305 m_dialog->playButton->setEnabled( !text.isEmpty() );
306 m_dialog->stopButton->setEnabled( !text.isEmpty() );
307}
308
309
310void KPrSlideTransitionDia::slotOk()
311{
312 apply( false );
313}
314
315
316void KPrSlideTransitionDia::slotUser1()
317{
318 apply( true );
319}
320
321
322void KPrSlideTransitionDia::apply( bool global )
323{
324 PageEffect effect = static_cast<PageEffect>( m_dialog->effectCombo->currentItem() );
325 if ( m_dialog->effectCombo->currentText() == i18n( "Random Transition" ) )
326 effect = PEF_RANDOM;
327
328 EffectSpeed effectSpeed = static_cast<EffectSpeed>( m_dialog->speedCombo->currentItem() );
329 bool soundEffect = m_dialog->soundCheckBox->isChecked();
330 TQString soundFileName = m_dialog->soundRequester->url();
331 int slideTime = m_dialog->automaticTransitionInput->value();
332
333 if ( effect != m_effect ||
334 effectSpeed != m_effectSpeed ||
335 soundEffect != m_soundEffect ||
336 soundFileName != m_soundFileName ||
337 slideTime != m_slideTime )
338 {
339 KPrTransEffectCmd::PageEffectSettings newSettings;
340
341 newSettings.pageEffect = effect;
342 newSettings.effectSpeed = effectSpeed;
343 newSettings.soundEffect = soundEffect;
344 newSettings.soundFileName = soundFileName;
345 newSettings.autoAdvance = /*TODO */ false;
346 newSettings.slideTime = slideTime;
347
348 // Collect info about current settings
349 TQValueVector<KPrTransEffectCmd::PageEffectSettings> oldSettings;
350 KPrPage *page = 0;
351 if ( global )
352 {
353 oldSettings.resize( m_view->kPresenterDoc()->getPageList().count() );
354 int i = 0;
355 for( TQPtrListIterator<KPrPage> it( m_view->kPresenterDoc()->getPageList() ); *it; ++it, ++i )
356 {
357 oldSettings[i].pageEffect = it.current()->getPageEffect();
358 oldSettings[i].effectSpeed = it.current()->getPageEffectSpeed();
359 oldSettings[i].soundEffect = it.current()->getPageSoundEffect();
360 oldSettings[i].soundFileName = it.current()->getPageSoundFileName();
361 oldSettings[i].autoAdvance = /*TODO it.current()->getAutoAdvance() */ false;
362 oldSettings[i].slideTime = it.current()->getPageTimer();
363 }
364 }
365 else
366 {
367 int pgnum = m_view->getCurrPgNum() - 1;
368 page = m_view->kPresenterDoc()->pageList().at( pgnum );
369 oldSettings.resize( 1 );
370 oldSettings[0].pageEffect = page->getPageEffect();
371 oldSettings[0].effectSpeed = page->getPageEffectSpeed();
372 oldSettings[0].soundEffect = page->getPageSoundEffect();
373 oldSettings[0].soundFileName = page->getPageSoundFileName();
374 oldSettings[0].autoAdvance = /*TODO page->getAutoAdvance() */ false;
375 oldSettings[0].slideTime = page->getPageTimer();
376 }
377 KPrTransEffectCmd *transEffectCmd = new KPrTransEffectCmd( oldSettings, newSettings,
378 global ? 0 : page, m_view->kPresenterDoc() );
379 transEffectCmd->execute();
380 m_view->kPresenterDoc()->addCommand( transEffectCmd );
381 }
382
383 accept();
384}
385
386
387void KPrSlideTransitionDia::playSound()
388{
389 delete m_soundPlayer;
390
391 m_soundPlayer = new KPrSoundPlayer( m_dialog->soundRequester->url() );
392 m_soundPlayer->play();
393
394 m_dialog->playButton->setEnabled( false );
395 m_dialog->stopButton->setEnabled( true );
396}
397
398
399void KPrSlideTransitionDia::stopSound()
400{
401 if ( m_soundPlayer ) {
402 m_soundPlayer->stop();
403 delete m_soundPlayer;
404 m_soundPlayer = 0;
405
406 m_dialog->playButton->setEnabled( true );
407 m_dialog->stopButton->setEnabled( false );
408 }
409}
410
411
412#include "KPrSlideTransitionDia.moc"