1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
/* This file is part of the KDE project
Copyright (C) 2004 Laurent Montel <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqlistbox.h>
#include <tqpushbutton.h>
#include <tqtoolbutton.h>
#include <tqapplication.h>
#include <tqlayout.h>
#include <kdebug.h>
#include <tdemessagebox.h>
#include <tdelocale.h>
#include "KPrPage.h"
#include "KPrDocument.h"
#include "KPrView.h"
#include "KPrCustomSlideShowDia.h"
KPrCustomSlideShowDia::KPrCustomSlideShowDia( KPrView* _view, KPrDocument *_doc, const char* name )
: KDialogBase( _view, name, true, i18n("Custom Slide Show"), Ok|Cancel ), m_doc( _doc ), m_view( _view )
, m_customSlideShowMap( m_doc->customSlideShows() )
{
TQWidget* page = new TQWidget( this );
setMainWidget( page );
TQGridLayout *grid1 = new TQGridLayout( page,10,3,KDialog::marginHint(), KDialog::spacingHint());
list=new TQListBox(page);
grid1->addMultiCellWidget(list,0,8,0,0);
m_pAdd=new TQPushButton(i18n("&Add..."),page);
grid1->addWidget(m_pAdd,1,2);
m_pModify=new TQPushButton(i18n("&Modify..."),page);
grid1->addWidget(m_pModify,2,2);
m_pRemove=new TQPushButton(i18n("&Remove"),page);
grid1->addWidget(m_pRemove,3,2);
m_pCopy=new TQPushButton(i18n("Co&py"),page);
grid1->addWidget(m_pCopy,4,2);
m_pTest=new TQPushButton(i18n("Test"),page);
grid1->addWidget(m_pTest,5,2);
connect( m_pRemove, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotRemove() ) );
connect( m_pAdd, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotAdd() ) );
connect( m_pModify, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotModify() ) );
connect( m_pCopy, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotCopy() ) );
connect( m_pTest, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotTest() ) );
connect( list, TQT_SIGNAL(doubleClicked(TQListBoxItem *)),this,TQT_SLOT(slotDoubleClicked(TQListBoxItem *)));
connect( list, TQT_SIGNAL(clicked ( TQListBoxItem * )),this,TQT_SLOT(slotTextClicked(TQListBoxItem * )));
connect( m_view, TQT_SIGNAL( presentationFinished() ), this, TQT_SLOT( slotPresentationFinished() ) );
init();
updateButton();
resize( 600, 250 );
m_bChanged=false;
}
KPrCustomSlideShowDia::~KPrCustomSlideShowDia()
{
kdDebug()<<"KPrCustomSlideShowDia::~KPrCustomSlideShowDia()********************\n";
}
void KPrCustomSlideShowDia::init()
{
CustomSlideShowMap::ConstIterator it( m_customSlideShowMap.begin() );
for ( ; it != m_customSlideShowMap.end(); ++it )
{
list->insertItem( it.key() );
}
}
void KPrCustomSlideShowDia::updateButton()
{
bool state = ( list->currentItem() >= 0 );
m_pRemove->setEnabled( state );
m_pModify->setEnabled( state );
m_pCopy->setEnabled( state );
m_pTest->setEnabled( state );
}
void KPrCustomSlideShowDia::slotTextClicked(TQListBoxItem*)
{
updateButton();
}
void KPrCustomSlideShowDia::slotDoubleClicked(TQListBoxItem *)
{
updateButton();
slotModify();
}
void KPrCustomSlideShowDia::slotPresentationFinished()
{
kdDebug()<<"void KPrCustomSlideShowDia::slotPresentationFinished()*************************\n";
show();
}
void KPrCustomSlideShowDia::hideEvent( TQHideEvent* )
{
}
void KPrCustomSlideShowDia::slotTest()
{
TQListBoxItem *item = list->selectedItem();
if ( item )
{
m_doc->testCustomSlideShow( m_customSlideShowMap[item->text()], m_view );
hide();
}
}
void KPrCustomSlideShowDia::slotAdd()
{
TQStringList listCustomName;
CustomSlideShowMap::Iterator it( m_customSlideShowMap.begin() ) ;
for ( ; it != m_customSlideShowMap.end(); ++it )
{
listCustomName.append( it.key() );
}
KPrDefineCustomSlideShow * dlg = new KPrDefineCustomSlideShow( this, listCustomName, m_doc->getPageList() );
if ( dlg->exec() )
{
//insert new element
m_customSlideShowMap.insert( dlg->customSlideShowName(), dlg->customSlides() );
list->insertItem( dlg->customSlideShowName() );
updateButton();
}
delete dlg;
}
void KPrCustomSlideShowDia::slotRemove()
{
if (list->selectedItem() )
{
m_customSlideShowMap.remove( list->selectedItem()->text() );
list->removeItem( list->currentItem() );
updateButton();
}
}
void KPrCustomSlideShowDia::slotOk()
{
m_doc->setCustomSlideShows( m_customSlideShowMap );
accept();
}
void KPrCustomSlideShowDia::slotModify()
{
TQListBoxItem *item = list->selectedItem();
if ( item )
{
TQStringList listCustomName;
CustomSlideShowMap::ConstIterator it( m_customSlideShowMap.begin() );
for ( ; it != m_customSlideShowMap.end(); ++it )
{
if ( it.key() !=item->text() )
listCustomName.append( it.key() );
}
KPrDefineCustomSlideShow * dlg = new KPrDefineCustomSlideShow( this, item->text(), listCustomName,
m_doc->getPageList(), m_customSlideShowMap[item->text()]);
if ( dlg->exec() )
{
//insert new element
m_customSlideShowMap.remove( list->selectedItem()->text() );
m_customSlideShowMap.insert( dlg->customSlideShowName(), dlg->customSlides() );
list->changeItem( dlg->customSlideShowName(), list->currentItem() );
}
delete dlg;
}
}
void KPrCustomSlideShowDia::slotCopy()
{
TQListBoxItem *item = list->selectedItem();
if ( item )
{
TQString str( list->selectedItem()->text() );
str+=i18n( "(Copy %1)" );
for ( int i =1;; ++i )
{
if ( !uniqueName( i, str ) )
{
str = str.arg( i );
m_customSlideShowMap.insert( str, m_customSlideShowMap[item->text()] );
list->insertItem( str );
break;
}
}
}
}
bool KPrCustomSlideShowDia::uniqueName( int val, const TQString & name ) const
{
TQString str = name.arg( val );
for ( int i= 0; i < ( int )list->count(); ++i )
{
if ( list->text ( i ) == str )
return true;
}
return false;
}
KPrCustomSlideShowItem::KPrCustomSlideShowItem( TQListBox * listbox, KPrPage * page )
: TQListBoxText( listbox, page->pageTitle() )
, m_page( page )
{
}
KPrCustomSlideShowItem::KPrCustomSlideShowItem( KPrPage * page )
: TQListBoxText( page->pageTitle() )
, m_page( page )
{
}
KPrCustomSlideShowItem::KPrCustomSlideShowItem( TQListBox * listbox, KPrPage * page, TQListBoxItem * after )
: TQListBoxText( listbox, page->pageTitle(), after )
, m_page( page )
{
}
KPrDefineCustomSlideShow::KPrDefineCustomSlideShow( TQWidget* parent, TQStringList &_listNameSlideShow,
const TQPtrList<KPrPage> &pages, const char *name )
: KDialogBase( parent, name, true, i18n("Define Custom Slide Show"), Ok|Cancel )
, listNameCustomSlideShow( _listNameSlideShow )
{
init();
for ( TQPtrList<KPrPage>::ConstIterator it = pages.begin(); it != pages.end(); ++it )
{
listSlide->insertItem( new KPrCustomSlideShowItem( *it ) );
}
}
KPrDefineCustomSlideShow::KPrDefineCustomSlideShow( TQWidget* parent, const TQString &_customName, TQStringList &_listNameSlideShow,
const TQPtrList<KPrPage> &pages, TQValueList<KPrPage *> &customPages, const char* name )
: KDialogBase( parent, name, true, i18n("Define Custom Slide Show"), Ok|Cancel )
, listNameCustomSlideShow( _listNameSlideShow )
{
init();
m_name->setText( _customName );
for ( TQPtrList<KPrPage>::ConstIterator it = pages.begin(); it != pages.end(); ++it )
{
listSlide->insertItem( new KPrCustomSlideShowItem( *it ) );
}
for ( TQValueList<KPrPage *>::ConstIterator it = customPages.begin(); it != customPages.end(); ++it )
{
listSlideShow->insertItem( new KPrCustomSlideShowItem( *it ) );
}
}
void KPrDefineCustomSlideShow::init()
{
TQWidget* page = new TQWidget( this );
setMainWidget( page );
TQVBoxLayout *lov = new TQVBoxLayout( page );
lov->setSpacing( KDialog::spacingHint() );
TQHBoxLayout *loh = new TQHBoxLayout( lov );
TQLabel *lab = new TQLabel( i18n( "Name:" ), page );
loh->addWidget( lab );
m_name = new TQLineEdit( page );
loh->addWidget( m_name );
TQHBoxLayout *lo = new TQHBoxLayout( lov );
lo->setSpacing( KDialog::spacingHint() );
TQVBoxLayout *loAv = new TQVBoxLayout( lo );
lab = new TQLabel( i18n("Existing slides:"), page );
loAv->addWidget( lab );
listSlide = new TQListBox( page );
loAv->addWidget( listSlide );
lab->setBuddy( listSlide );
TQVBoxLayout *loHBtns = new TQVBoxLayout( lo );
loHBtns->addStretch( 1 );
m_insertSlide = new TQToolButton( page );
loHBtns->addWidget( m_insertSlide );
m_removeSlide = new TQToolButton( page );
loHBtns->addWidget( m_removeSlide );
loHBtns->addStretch( 1 );
TQVBoxLayout *loS = new TQVBoxLayout( lo );
lab = new TQLabel( i18n("Selected slides:"), page );
loS->addWidget( lab );
listSlideShow = new TQListBox( page );
loS->addWidget( listSlideShow );
lab->setBuddy( listSlideShow );
TQVBoxLayout *loVBtns = new TQVBoxLayout( lo );
loVBtns->addStretch( 1 );
m_moveUpSlide = new TQToolButton( page );
m_moveUpSlide->setAutoRepeat( true );
loVBtns->addWidget( m_moveUpSlide );
m_moveDownSlide = new TQToolButton( page );
m_moveDownSlide->setAutoRepeat( true );
loVBtns->addWidget( m_moveDownSlide );
loVBtns->addStretch( 1 );
m_name->setFocus();
connect( m_insertSlide, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotMoveInsertSlide() ) );
connect( m_removeSlide, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotMoveRemoveSlide()) );
connect( m_moveUpSlide, TQT_SIGNAL(clicked()), this, TQT_SLOT( slotMoveUpSlide() ) );
connect( m_moveDownSlide, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotMoveDownSlide()) );
connect( m_name, TQT_SIGNAL( textChanged ( const TQString & ) ), this, TQT_SLOT( slideNameChanged( const TQString & ) ) );
connect( listSlideShow, TQT_SIGNAL( clicked ( TQListBoxItem * ) ), this, TQT_SLOT( updateButton() ) );
connect( listSlide, TQT_SIGNAL( clicked ( TQListBoxItem * ) ), this, TQT_SLOT( updateButton() ) );
connect( listSlide, TQT_SIGNAL( doubleClicked ( TQListBoxItem * ) ), this, TQT_SLOT( slotMoveInsertSlide() ) );
connect( listSlideShow, TQT_SIGNAL( doubleClicked( TQListBoxItem * ) ), this, TQT_SLOT( slotMoveRemoveSlide() ) );
m_insertSlide->setIconSet( SmallIconSet( ( TQApplication::reverseLayout() ? "back" : "forward" ) ) );
m_removeSlide->setIconSet( SmallIconSet( ( TQApplication::reverseLayout() ? "forward" : "back") ) );
m_moveUpSlide->setIconSet( SmallIconSet( "go-up" ) );
m_moveDownSlide->setIconSet( SmallIconSet( "go-down" ) );
slideNameChanged( m_name->text() );
updateButton();
resize( 600, 250 );
}
void KPrDefineCustomSlideShow::slideNameChanged( const TQString & _name)
{
enableButtonOK( !_name.isEmpty() );
}
void KPrDefineCustomSlideShow::updateButton()
{
int pos = listSlideShow->currentItem();
m_moveUpSlide->setEnabled( pos>0 );
m_moveDownSlide->setEnabled( pos< (( int ) listSlideShow->count()-1 ) );
m_removeSlide->setEnabled( listSlideShow->count()>0 );
m_insertSlide->setEnabled( listSlide->currentItem()>-1 );
}
void KPrDefineCustomSlideShow::slotMoveUpSlide()
{
int c = listSlideShow->currentItem();
if ( c < 1 ) return;
TQListBoxItem *item = listSlideShow->item( c );
listSlideShow->takeItem( item );
listSlideShow->insertItem( item, c-1 );
listSlideShow->setCurrentItem( item );
updateButton();
}
void KPrDefineCustomSlideShow::slotMoveDownSlide()
{
int c = listSlideShow->currentItem();
if ( c < 0 || c == int( listSlideShow->count() ) - 1 ) return;
TQListBoxItem *item = listSlideShow->item( c );
listSlideShow->takeItem( item );
listSlideShow->insertItem( item, c+1 );
listSlideShow->setCurrentItem( item );
updateButton();
}
void KPrDefineCustomSlideShow::slotMoveRemoveSlide()
{
// move all selected items from selected to available listbox
TQListBoxItem *item = listSlideShow->firstItem();
while ( item ) {
if ( item->isSelected() ) {
listSlideShow->takeItem( item );
}
item = item->next();
}
updateButton();
}
void KPrDefineCustomSlideShow::slotMoveInsertSlide()
{
TQListBoxItem *item = listSlide->firstItem();
while ( item ) {
if ( item->isSelected() ) {
KPrCustomSlideShowItem * i = dynamic_cast<KPrCustomSlideShowItem *>( item );
if ( i )
{
listSlideShow->insertItem( new KPrCustomSlideShowItem( i->getPage() ), ( listSlideShow->count() ) );
}
}
item = item->next();
}
listSlideShow->setFocus();
updateButton();
}
TQValueList<KPrPage *> KPrDefineCustomSlideShow::customSlides()
{
TQValueList<KPrPage *> pages;
TQListBoxItem *item = listSlideShow->firstItem();
while ( item )
{
KPrCustomSlideShowItem * i = dynamic_cast<KPrCustomSlideShowItem *>( item );
if ( i )
{
pages.push_back( i->getPage() );
}
item = item->next();
}
return pages;
}
TQString KPrDefineCustomSlideShow::customSlideShowName() const
{
return m_name->text();
}
void KPrDefineCustomSlideShow::slotOk()
{
if ( listNameCustomSlideShow.contains( m_name->text() ) )
{
KMessageBox::error(this, i18n("Custom Slide Show name is already used."), i18n("Define Custom Slide Show"));
}
else
{
if ( listSlideShow->count() == 0 )
KMessageBox::error(this, i18n("You did not select any slides. Please select some slides."), i18n("Define Custom Slide Show"));
else
accept();
}
}
#include "KPrCustomSlideShowDia.moc"
|