kpresenter

KPrGotoPage.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 "KPrGotoPage.h"
00022 
00023 #include <qlabel.h>
00024 #include <qlistbox.h>
00025 #include <qlayout.h>
00026 #include <qpushbutton.h>
00027 
00028 #include <klocale.h>
00029 #include <kdialog.h>
00030 
00031 #include "KPrDocument.h"
00032 #include "KPrPage.h"
00033 
00034 KPrGotoPage::KPrGotoPage( const KPrDocument *doc,
00035                         const QValueList<int> &slides, int start,
00036                         QWidget *parent, const char *name )
00037     : KDialogBase( parent, name, true, i18n("Goto Slide..."), Ok|Cancel),
00038       oldPage(start)
00039 {
00040 
00041     QWidget *page = new QWidget( this );
00042     setMainWidget(page);
00043     QVBoxLayout *ml = new QVBoxLayout( page, KDialog::marginHint(),
00044                                        KDialog::spacingHint());
00045     QLabel *label = new QLabel( i18n( "Go to slide:" ), page );
00046     ml->addWidget( label );
00047     spinbox = new QListBox( page );
00048     connect( spinbox, SIGNAL(doubleClicked( QListBoxItem* )),
00049              this, SLOT(accept()) );
00050     connect( spinbox, SIGNAL(returnPressed( QListBoxItem* )),
00051              this, SLOT(accept()) );
00052     ml->addWidget( spinbox );
00053 
00054     QPtrList<KPrPage> pageList = doc->getPageList(); // because of const doc, we can't do doc->pageList()->at()
00055     QValueList<int>::ConstIterator it = slides.begin();
00056     for ( ; it != slides.end(); ++it ) {
00057         QString t( pageList.at( (*it) - 1 )->pageTitle() );
00058         // cut ultra long titles...
00059         if(t.length() > 30) {
00060             t.truncate(30);
00061             t+="...";
00062         }
00063         spinbox->insertItem( QString( "%1 - %2" ).arg( *it ).arg( t ), -1 );
00064         if ( *it == start )
00065             spinbox->setCurrentItem( spinbox->count()-1 );
00066     }
00067 
00068     if ( parent )
00069         parent->setCursor( Qt::forbiddenCursor );
00070 }
00071 
00072 int KPrGotoPage::gotoPage( const KPrDocument *doc,
00073                           const QValueList<int> &slides, int start,
00074                           QWidget *parent)
00075 {
00076     KPrGotoPage dia( doc, slides, start,parent, 0L );
00077     dia.exec();
00078     dia.resetCursor();
00079     return dia.page();
00080 }
00081 
00082 int KPrGotoPage::page() const {
00083     if(result()==QDialog::Accepted)
00084         return spinbox->currentText().left( spinbox->currentText().find( "-" ) - 1 ).toInt();
00085     return oldPage;
00086 }
00087 
00088 void KPrGotoPage::resetCursor() {
00089     if ( parentWidget() )
00090         parentWidget()->setCursor( Qt::blankCursor );
00091 }
KDE Home | KDE Accessibility Home | Description of Access Keys