kpresenter

KPrGotoPage.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 "KPrGotoPage.h"
21
22#include <tqlabel.h>
23#include <tqlistbox.h>
24#include <tqlayout.h>
25#include <tqpushbutton.h>
26
27#include <tdelocale.h>
28#include <kdialog.h>
29
30#include "KPrDocument.h"
31#include "KPrPage.h"
32
33KPrGotoPage::KPrGotoPage( const KPrDocument *doc,
34 const TQValueList<int> &slides, int start,
35 TQWidget *parent, const char *name )
36 : KDialogBase( parent, name, true, i18n("Goto Slide..."), Ok|Cancel),
37 oldPage(start)
38{
39
40 TQWidget *page = new TQWidget( this );
41 setMainWidget(page);
42 TQVBoxLayout *ml = new TQVBoxLayout( page, KDialog::marginHint(),
43 KDialog::spacingHint());
44 TQLabel *label = new TQLabel( i18n( "Go to slide:" ), page );
45 ml->addWidget( label );
46 spinbox = new TQListBox( page );
47 connect( spinbox, TQ_SIGNAL(doubleClicked( TQListBoxItem* )),
48 this, TQ_SLOT(accept()) );
49 connect( spinbox, TQ_SIGNAL(returnPressed( TQListBoxItem* )),
50 this, TQ_SLOT(accept()) );
51 ml->addWidget( spinbox );
52
53 TQPtrList<KPrPage> pageList = doc->getPageList(); // because of const doc, we can't do doc->pageList()->at()
54 TQValueList<int>::ConstIterator it = slides.begin();
55 for ( ; it != slides.end(); ++it ) {
56 TQString t( pageList.at( (*it) - 1 )->pageTitle() );
57 // cut ultra long titles...
58 if(t.length() > 30) {
59 t.truncate(30);
60 t+="...";
61 }
62 spinbox->insertItem( TQString( "%1 - %2" ).arg( *it ).arg( t ), -1 );
63 if ( *it == start )
64 spinbox->setCurrentItem( spinbox->count()-1 );
65 }
66
67 if ( parent )
68 parent->setCursor( TQt::forbiddenCursor );
69}
70
71int KPrGotoPage::gotoPage( const KPrDocument *doc,
72 const TQValueList<int> &slides, int start,
73 TQWidget *parent)
74{
75 KPrGotoPage dia( doc, slides, start,parent, 0L );
76 dia.exec();
77 dia.resetCursor();
78 return dia.page();
79}
80
81int KPrGotoPage::page() const {
82 if(result()==TQDialog::Accepted)
83 return spinbox->currentText().left( spinbox->currentText().find( "-" ) - 1 ).toInt();
84 return oldPage;
85}
86
87void KPrGotoPage::resetCursor() {
88 if ( parentWidget() )
89 parentWidget()->setCursor( TQt::blankCursor );
90}