2004-08-26 21:17:24 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2002 by Wilco Greven <greven@kde.org> *
|
|
|
|
* Copyright (C) 2002 by Chris Cheney <ccheney@cheney.cx> *
|
|
|
|
* Copyright (C) 2002 by Malcolm Hunter <malcolm.hunter@gmx.co.uk> *
|
|
|
|
* Copyright (C) 2003-2004 by Christophe Devriese *
|
|
|
|
* <Christophe.Devriese@student.kuleuven.ac.be> *
|
|
|
|
* Copyright (C) 2003 by Daniel Molkentin <molkentin@kde.org> *
|
|
|
|
* Copyright (C) 2003 by Andy Goossens <andygoossens@telenet.be> *
|
|
|
|
* Copyright (C) 2003 by Dirk Mueller <mueller@kde.org> *
|
|
|
|
* Copyright (C) 2003 by Laurent Montel <montel@kde.org> *
|
|
|
|
* Copyright (C) 2004 by Dominique Devriese <devriese@kde.org> *
|
|
|
|
* Copyright (C) 2004 by Christoph Cullmann <crossfire@babylon2k.de> *
|
|
|
|
* Copyright (C) 2004 by Henrique Pinto <stampede@coltec.ufmg.br> *
|
|
|
|
* Copyright (C) 2004 by Waldo Bastian <bastian@kde.org> *
|
|
|
|
* Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es> *
|
2004-09-02 18:11:19 +00:00
|
|
|
* Copyright (C) 2004 by Antti Markus <antti.markus@starman.ee> *
|
2004-08-26 21:17:24 +00:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
#include <qsplitter.h>
|
2004-09-04 22:28:14 +00:00
|
|
|
#include <qpainter.h>
|
2004-09-09 13:25:40 +00:00
|
|
|
#include <qlayout.h>
|
|
|
|
#include <qlabel.h>
|
2004-09-16 21:27:34 +00:00
|
|
|
#include <qvbox.h>
|
2004-09-23 17:16:04 +00:00
|
|
|
#include <qtoolbox.h>
|
2004-09-17 17:58:42 +00:00
|
|
|
#include <qpushbutton.h>
|
2002-08-30 09:14:01 +00:00
|
|
|
|
2004-10-12 11:08:09 +00:00
|
|
|
#include <dcopobject.h>
|
2002-08-30 09:14:01 +00:00
|
|
|
#include <kaction.h>
|
|
|
|
#include <kinstance.h>
|
2002-08-30 12:10:02 +00:00
|
|
|
#include <kprinter.h>
|
2002-08-30 09:14:01 +00:00
|
|
|
#include <kstdaction.h>
|
2004-10-10 13:33:01 +00:00
|
|
|
#include <kdeversion.h>
|
2002-08-30 09:14:01 +00:00
|
|
|
#include <kparts/genericfactory.h>
|
2003-09-15 14:26:37 +00:00
|
|
|
#include <kurldrag.h>
|
2004-08-28 17:59:17 +00:00
|
|
|
#include <kfiledialog.h>
|
2004-08-28 14:18:45 +00:00
|
|
|
#include <kmessagebox.h>
|
2004-09-09 13:25:40 +00:00
|
|
|
#include <kfinddialog.h>
|
|
|
|
#include <knuminput.h>
|
2004-09-17 17:58:42 +00:00
|
|
|
#include <kiconloader.h>
|
2004-09-16 21:27:34 +00:00
|
|
|
#include <kio/netaccess.h>
|
2002-08-30 09:14:01 +00:00
|
|
|
|
2004-08-26 16:36:54 +00:00
|
|
|
#include "kpdf_error.h"
|
2003-07-01 06:08:27 +00:00
|
|
|
|
2002-08-30 09:14:01 +00:00
|
|
|
#include "GlobalParams.h"
|
|
|
|
|
2004-09-16 21:27:34 +00:00
|
|
|
#include "kpdf_part.h"
|
2004-09-26 23:39:39 +00:00
|
|
|
#include "pageview.h"
|
2004-09-16 21:27:34 +00:00
|
|
|
#include "thumbnaillist.h"
|
2004-09-26 23:39:39 +00:00
|
|
|
#include "searchwidget.h"
|
2004-09-08 12:41:14 +00:00
|
|
|
#include "document.h"
|
2004-11-03 21:37:21 +00:00
|
|
|
#include "page.h"
|
2004-09-23 21:33:53 +00:00
|
|
|
#include "toc.h"
|
2004-10-27 14:15:27 +00:00
|
|
|
#include "preferencesdialog.h"
|
|
|
|
#include "settings.h"
|
2003-06-28 01:59:03 +00:00
|
|
|
|
2002-08-30 09:14:01 +00:00
|
|
|
typedef KParts::GenericFactory<KPDF::Part> KPDFPartFactory;
|
2003-09-12 12:36:20 +00:00
|
|
|
K_EXPORT_COMPONENT_FACTORY(libkpdfpart, KPDFPartFactory)
|
2002-08-30 09:14:01 +00:00
|
|
|
|
|
|
|
using namespace KPDF;
|
|
|
|
|
2004-08-26 16:54:06 +00:00
|
|
|
unsigned int Part::m_count = 0;
|
|
|
|
|
2002-08-30 09:14:01 +00:00
|
|
|
Part::Part(QWidget *parentWidget, const char *widgetName,
|
|
|
|
QObject *parent, const char *name,
|
|
|
|
const QStringList & /*args*/ )
|
2004-10-12 11:08:09 +00:00
|
|
|
: DCOPObject("kpdf"), KParts::ReadOnlyPart(parent, name)
|
2002-08-30 09:14:01 +00:00
|
|
|
{
|
2004-09-08 12:41:14 +00:00
|
|
|
// create browser extension (for printing when embedded into browser)
|
|
|
|
new BrowserExtension(this);
|
2002-09-02 21:56:00 +00:00
|
|
|
|
2004-09-18 16:41:23 +00:00
|
|
|
// xpdf 'extern' global class (m_count is a static instance counter)
|
2004-09-10 13:39:26 +00:00
|
|
|
//if ( m_count ) TODO check if we need to insert these lines..
|
|
|
|
// delete globalParams;
|
2004-09-08 12:41:14 +00:00
|
|
|
globalParams = new GlobalParams("");
|
2004-09-09 22:14:04 +00:00
|
|
|
globalParams->setupBaseFonts(NULL);
|
2004-09-08 12:41:14 +00:00
|
|
|
m_count++;
|
2002-08-30 09:14:01 +00:00
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
// we need an instance
|
|
|
|
setInstance(KPDFPartFactory::instance());
|
2002-08-30 09:14:01 +00:00
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
// build the document
|
|
|
|
document = new KPDFDocument();
|
|
|
|
connect( document, SIGNAL( pageChanged() ), this, SLOT( updateActions() ) );
|
|
|
|
|
2004-09-28 13:53:47 +00:00
|
|
|
// widgets: ^searchbar (toolbar containing label and SearchWidget)
|
|
|
|
// m_searchToolBar = new KToolBar( parentWidget, "searchBar" );
|
|
|
|
// m_searchToolBar->boxLayout()->setSpacing( KDialog::spacingHint() );
|
|
|
|
// QLabel * sLabel = new QLabel( i18n( "&Search:" ), m_searchToolBar, "kde toolbar widget" );
|
|
|
|
// m_searchWidget = new SearchWidget( m_searchToolBar, document );
|
|
|
|
// sLabel->setBuddy( m_searchWidget );
|
|
|
|
// m_searchToolBar->setStretchableWidget( m_searchWidget );
|
|
|
|
|
2004-09-23 17:16:04 +00:00
|
|
|
// widgets: [] splitter []
|
2004-09-11 15:59:32 +00:00
|
|
|
m_splitter = new QSplitter( parentWidget, widgetName );
|
|
|
|
m_splitter->setOpaqueResize( true );
|
|
|
|
setWidget( m_splitter );
|
2004-09-02 18:11:19 +00:00
|
|
|
|
2004-09-23 17:16:04 +00:00
|
|
|
// widgets: [left toolbox] | []
|
2004-09-23 21:49:00 +00:00
|
|
|
m_toolBox = new QToolBox( m_splitter );
|
|
|
|
m_toolBox->setMinimumWidth( 60 );
|
|
|
|
m_toolBox->setMaximumWidth( 200 );
|
2004-09-17 17:58:42 +00:00
|
|
|
|
2004-09-23 21:49:00 +00:00
|
|
|
TOC * tocFrame = new TOC( m_toolBox, document );
|
|
|
|
m_toolBox->addItem( tocFrame, QIconSet(SmallIcon("text_left")), i18n("Contents") );
|
|
|
|
connect(tocFrame, SIGNAL(hasTOC(bool)), this, SLOT(enableTOC(bool)));
|
2004-09-28 13:53:47 +00:00
|
|
|
enableTOC( false );
|
2003-09-15 21:57:19 +00:00
|
|
|
|
2004-09-23 21:49:00 +00:00
|
|
|
QVBox * thumbsBox = new ThumbnailsBox( m_toolBox );
|
2004-10-29 10:32:25 +00:00
|
|
|
m_searchWidget = new SearchWidget( thumbsBox, document );
|
|
|
|
m_thumbnailList = new ThumbnailList( thumbsBox, document );
|
2004-09-27 21:36:25 +00:00
|
|
|
connect( m_thumbnailList, SIGNAL( urlDropped( const KURL& ) ), SLOT( openURL( const KURL & )));
|
2004-09-23 21:49:00 +00:00
|
|
|
m_toolBox->addItem( thumbsBox, QIconSet(SmallIcon("thumbnail")), i18n("Thumbnails") );
|
|
|
|
m_toolBox->setCurrentItem( thumbsBox );
|
2004-09-16 21:27:34 +00:00
|
|
|
|
2004-09-23 21:49:00 +00:00
|
|
|
QFrame * bookmarksFrame = new QFrame( m_toolBox );
|
2004-09-28 13:53:47 +00:00
|
|
|
int iIdx = m_toolBox->addItem( bookmarksFrame, QIconSet(SmallIcon("bookmark")), i18n("Bookmarks") );
|
|
|
|
m_toolBox->setItemEnabled( iIdx, false );
|
2004-09-23 17:16:04 +00:00
|
|
|
|
2004-09-23 21:49:00 +00:00
|
|
|
QFrame * editFrame = new QFrame( m_toolBox );
|
2004-09-28 13:53:47 +00:00
|
|
|
iIdx = m_toolBox->addItem( editFrame, QIconSet(SmallIcon("pencil")), i18n("Annotations") );
|
|
|
|
m_toolBox->setItemEnabled( iIdx, false );
|
2004-09-23 17:16:04 +00:00
|
|
|
|
|
|
|
// widgets: [] | [right 'pageView']
|
|
|
|
m_pageView = new PageView( m_splitter, document );
|
|
|
|
connect( m_pageView, SIGNAL( urlDropped( const KURL& ) ), SLOT( openURL( const KURL & )));
|
|
|
|
//connect(m_pageView, SIGNAL( rightClick() ), this, SIGNAL( rightClick() ));
|
|
|
|
|
|
|
|
// add document observers
|
|
|
|
document->addObserver( m_thumbnailList );
|
|
|
|
document->addObserver( m_pageView );
|
2004-09-23 21:33:53 +00:00
|
|
|
document->addObserver( tocFrame );
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
// ACTIONS
|
|
|
|
KActionCollection * ac = actionCollection();
|
|
|
|
|
|
|
|
// Page Traversal actions
|
2004-09-13 17:30:00 +00:00
|
|
|
m_gotoPage = KStdAction::gotoPage( this, SLOT( slotGoToPage() ), ac, "goto_page" );
|
2004-09-16 21:04:49 +00:00
|
|
|
m_gotoPage->setShortcut( "CTRL+G" );
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
m_prevPage = KStdAction::prior(this, SLOT(slotPreviousPage()), ac, "previous_page");
|
|
|
|
m_prevPage->setWhatsThis( i18n( "Moves to the previous page of the document" ) );
|
2004-09-27 21:36:25 +00:00
|
|
|
m_prevPage->setShortcut( "Backspace" );
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
m_nextPage = KStdAction::next(this, SLOT(slotNextPage()), ac, "next_page" );
|
|
|
|
m_nextPage->setWhatsThis( i18n( "Moves to the next page of the document" ) );
|
2004-09-27 21:36:25 +00:00
|
|
|
m_nextPage->setShortcut( "Space" );
|
2004-09-08 12:41:14 +00:00
|
|
|
|
2004-09-13 17:30:00 +00:00
|
|
|
m_firstPage = KStdAction::firstPage( this, SLOT( slotGotoFirst() ), ac, "first_page" );
|
2004-09-08 12:41:14 +00:00
|
|
|
m_firstPage->setWhatsThis( i18n( "Moves to the first page of the document" ) );
|
|
|
|
|
2004-09-27 21:36:25 +00:00
|
|
|
m_lastPage = KStdAction::lastPage( this, SLOT( slotGotoLast() ), ac, "last_page" );
|
2004-09-08 12:41:14 +00:00
|
|
|
m_lastPage->setWhatsThis( i18n( "Moves to the last page of the document" ) );
|
|
|
|
|
2004-09-11 15:59:32 +00:00
|
|
|
// Find and other actions
|
|
|
|
m_find = KStdAction::find( this, SLOT( slotFind() ), ac, "find" );
|
2004-09-08 12:41:14 +00:00
|
|
|
m_find->setEnabled(false);
|
|
|
|
|
2004-09-11 15:59:32 +00:00
|
|
|
m_findNext = KStdAction::findNext( this, SLOT( slotFindNext() ), ac, "find_next" );
|
2004-09-08 12:41:14 +00:00
|
|
|
m_findNext->setEnabled(false);
|
|
|
|
|
2004-09-11 15:59:32 +00:00
|
|
|
KStdAction::saveAs( this, SLOT( slotSaveFileAs() ), ac, "save" );
|
2004-10-27 14:15:27 +00:00
|
|
|
KStdAction::preferences( this, SLOT( slotPreferences() ), ac, "preferences" );
|
2004-09-08 12:41:14 +00:00
|
|
|
KStdAction::printPreview( this, SLOT( slotPrintPreview() ), ac );
|
|
|
|
|
2004-09-11 15:59:32 +00:00
|
|
|
// attach the actions of the 2 children widgets too
|
2004-10-27 14:15:27 +00:00
|
|
|
m_pageView->setupActions( ac );
|
2004-09-08 12:41:14 +00:00
|
|
|
|
2004-10-29 13:33:51 +00:00
|
|
|
// apply configuration (both internal settings and GUI configured items)
|
2004-10-27 14:15:27 +00:00
|
|
|
m_splitter->setSizes( Settings::splitterSizes() );
|
2004-10-29 13:33:51 +00:00
|
|
|
slotNewConfig();
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
// set our XML-UI resource file
|
|
|
|
setXMLFile("kpdf_part.rc");
|
|
|
|
updateActions();
|
2003-09-15 21:57:19 +00:00
|
|
|
}
|
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
Part::~Part()
|
2003-09-15 21:09:49 +00:00
|
|
|
{
|
2004-10-29 13:33:51 +00:00
|
|
|
// save internal settings
|
2004-10-27 14:15:27 +00:00
|
|
|
Settings::setSplitterSizes( m_splitter->sizes() );
|
2004-10-29 13:33:51 +00:00
|
|
|
// write to disk config file
|
2004-10-27 14:15:27 +00:00
|
|
|
Settings::writeConfig();
|
|
|
|
|
|
|
|
delete document;
|
|
|
|
if ( --m_count == 0 )
|
|
|
|
delete globalParams;
|
2003-09-15 21:09:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-12 11:08:09 +00:00
|
|
|
void Part::goToPage(uint i)
|
|
|
|
{
|
|
|
|
if (i <= document->pages())
|
|
|
|
document->slotSetCurrentPage( i - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Part::openDocument(KURL doc)
|
|
|
|
{
|
|
|
|
openURL(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint Part::pages()
|
|
|
|
{
|
|
|
|
return document->pages();
|
|
|
|
}
|
|
|
|
|
2004-09-26 23:39:39 +00:00
|
|
|
//this don't go anywhere but is required by genericfactory.h
|
2004-09-09 13:25:40 +00:00
|
|
|
KAboutData* Part::createAboutData()
|
2003-09-15 14:26:37 +00:00
|
|
|
{
|
2004-09-09 13:25:40 +00:00
|
|
|
// the non-i18n name here must be the same as the directory in
|
|
|
|
// which the part's rc file is installed ('partrcdir' in the
|
|
|
|
// Makefile)
|
|
|
|
KAboutData* aboutData = new KAboutData("kpdfpart", I18N_NOOP("KPDF::Part"), "0.1");
|
|
|
|
aboutData->addAuthor("Wilco Greven", 0, "greven@kde.org");
|
|
|
|
return aboutData;
|
2003-09-15 14:26:37 +00:00
|
|
|
}
|
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
bool Part::openFile()
|
2003-09-15 09:35:55 +00:00
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
bool ok = document->openDocument( m_file );
|
2004-09-11 15:59:32 +00:00
|
|
|
m_find->setEnabled( ok );
|
2004-09-09 13:25:40 +00:00
|
|
|
return ok;
|
2003-09-15 09:35:55 +00:00
|
|
|
}
|
|
|
|
|
2004-09-18 16:41:23 +00:00
|
|
|
bool Part::openURL(const KURL &url)
|
|
|
|
{
|
|
|
|
bool b = KParts::ReadOnlyPart::openURL(url);
|
|
|
|
if (!b) KMessageBox::error(widget(), i18n("Could not open %1").arg(url.prettyURL()));
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
bool Part::closeURL()
|
2003-09-14 21:49:26 +00:00
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
document->closeDocument();
|
2004-09-09 13:25:40 +00:00
|
|
|
return KParts::ReadOnlyPart::closeURL();
|
2003-09-14 21:49:26 +00:00
|
|
|
}
|
2003-09-14 20:46:38 +00:00
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
void Part::updateActions()
|
2003-09-14 21:49:26 +00:00
|
|
|
{
|
2004-09-08 12:41:14 +00:00
|
|
|
if ( document->pages() > 0 )
|
|
|
|
{
|
2004-09-09 13:25:40 +00:00
|
|
|
m_gotoPage->setEnabled(document->pages()>1);
|
|
|
|
m_firstPage->setEnabled(!document->atBegin());
|
|
|
|
m_prevPage->setEnabled(!document->atBegin());
|
|
|
|
m_lastPage->setEnabled(!document->atEnd());
|
|
|
|
m_nextPage->setEnabled(!document->atEnd());
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-09 13:25:40 +00:00
|
|
|
m_gotoPage->setEnabled(false);
|
2004-09-08 12:41:14 +00:00
|
|
|
m_firstPage->setEnabled(false);
|
|
|
|
m_lastPage->setEnabled(false);
|
|
|
|
m_prevPage->setEnabled(false);
|
|
|
|
m_nextPage->setEnabled(false);
|
|
|
|
}
|
2003-09-14 21:49:26 +00:00
|
|
|
}
|
2003-09-14 20:46:38 +00:00
|
|
|
|
2004-09-23 21:49:00 +00:00
|
|
|
void Part::enableTOC(bool enable)
|
|
|
|
{
|
|
|
|
m_toolBox->setItemEnabled(0, enable);
|
|
|
|
}
|
|
|
|
|
2004-09-18 16:41:23 +00:00
|
|
|
//BEGIN go to page dialog
|
2004-09-09 13:25:40 +00:00
|
|
|
class KPDFGotoPageDialog : public KDialogBase
|
2003-09-14 20:46:38 +00:00
|
|
|
{
|
2004-09-09 13:25:40 +00:00
|
|
|
public:
|
|
|
|
KPDFGotoPageDialog(QWidget *p, int current, int max) : KDialogBase(p, 0L, true, i18n("Go to Page"), Ok | Cancel, Ok) {
|
|
|
|
QWidget *w = new QWidget(this);
|
|
|
|
setMainWidget(w);
|
2004-09-18 16:41:23 +00:00
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
QVBoxLayout *topLayout = new QVBoxLayout( w, 0, spacingHint() );
|
|
|
|
e1 = new KIntNumInput(current, w);
|
|
|
|
e1->setRange(1, max);
|
|
|
|
e1->setEditFocus(true);
|
2004-09-18 16:41:23 +00:00
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
QLabel *label = new QLabel( e1,i18n("&Page:"), w );
|
|
|
|
topLayout->addWidget(label);
|
|
|
|
topLayout->addWidget(e1);
|
|
|
|
topLayout->addSpacing(spacingHint()); // A little bit extra space
|
|
|
|
topLayout->addStretch(10);
|
|
|
|
e1->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
int getPage() {
|
|
|
|
return e1->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
KIntNumInput *e1;
|
|
|
|
};
|
2004-09-18 16:41:23 +00:00
|
|
|
//END go to page dialog
|
2004-09-09 13:25:40 +00:00
|
|
|
|
|
|
|
void Part::slotGoToPage()
|
|
|
|
{
|
2004-09-23 17:16:04 +00:00
|
|
|
KPDFGotoPageDialog pageDialog( m_pageView, document->currentPage() + 1, document->pages() );
|
2004-09-09 13:25:40 +00:00
|
|
|
if ( pageDialog.exec() == QDialog::Accepted )
|
|
|
|
document->slotSetCurrentPage( pageDialog.getPage() - 1 );
|
2002-08-30 09:14:01 +00:00
|
|
|
}
|
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
void Part::slotPreviousPage()
|
2003-09-14 20:23:01 +00:00
|
|
|
{
|
2004-09-09 13:25:40 +00:00
|
|
|
if ( !document->atBegin() )
|
|
|
|
document->slotSetCurrentPage( document->currentPage() - 1 );
|
2003-09-14 20:23:01 +00:00
|
|
|
}
|
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
void Part::slotNextPage()
|
2003-09-14 20:23:01 +00:00
|
|
|
{
|
2004-09-09 13:25:40 +00:00
|
|
|
if ( !document->atEnd() )
|
|
|
|
document->slotSetCurrentPage( document->currentPage() + 1 );
|
|
|
|
}
|
|
|
|
|
2004-09-11 15:59:32 +00:00
|
|
|
void Part::slotGotoFirst()
|
2004-09-09 13:25:40 +00:00
|
|
|
{
|
|
|
|
document->slotSetCurrentPage( 0 );
|
2003-09-14 20:23:01 +00:00
|
|
|
}
|
|
|
|
|
2004-09-11 15:59:32 +00:00
|
|
|
void Part::slotGotoLast()
|
2003-09-14 14:54:16 +00:00
|
|
|
{
|
2004-09-09 13:25:40 +00:00
|
|
|
document->slotSetCurrentPage( document->pages() - 1 );
|
2003-09-14 14:54:16 +00:00
|
|
|
}
|
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
void Part::slotFind()
|
2003-09-14 14:54:16 +00:00
|
|
|
{
|
2004-09-16 21:04:49 +00:00
|
|
|
KFindDialog dlg( widget() );
|
2004-10-02 14:22:04 +00:00
|
|
|
dlg.setHasCursor(false);
|
2004-10-10 13:33:01 +00:00
|
|
|
#if KDE_IS_VERSION(3,3,90)
|
2004-10-02 14:22:04 +00:00
|
|
|
dlg.setSupportsBackwardsFind(false);
|
|
|
|
dlg.setSupportsWholeWordsFind(false);
|
|
|
|
dlg.setSupportsRegularExpressionFind(false);
|
2004-10-10 13:33:01 +00:00
|
|
|
#endif
|
2004-09-09 13:25:40 +00:00
|
|
|
if (dlg.exec() == QDialog::Accepted)
|
2004-09-16 21:04:49 +00:00
|
|
|
{
|
|
|
|
m_findNext->setEnabled( true );
|
2004-09-17 17:58:42 +00:00
|
|
|
document->slotFind( dlg.pattern(), dlg.options() & KFindDialog::CaseSensitive );
|
2004-09-16 21:04:49 +00:00
|
|
|
}
|
2003-09-14 21:53:40 +00:00
|
|
|
}
|
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
void Part::slotFindNext()
|
2003-09-14 21:53:40 +00:00
|
|
|
{
|
2004-09-16 21:04:49 +00:00
|
|
|
document->slotFind();
|
2003-09-14 14:22:37 +00:00
|
|
|
}
|
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
void Part::slotSaveFileAs()
|
2004-08-28 17:59:17 +00:00
|
|
|
{
|
2004-10-09 08:10:56 +00:00
|
|
|
KURL saveURL = KFileDialog::getSaveURL(
|
|
|
|
url().isLocalFile() ? url().url() : url().fileName(),
|
|
|
|
QString::null, widget(), QString::null );
|
2004-09-16 21:27:34 +00:00
|
|
|
if( !KIO::NetAccess::upload( url().path(), saveURL, static_cast<QWidget*>( 0 ) ) )
|
2004-10-09 08:10:56 +00:00
|
|
|
KMessageBox::information( 0, i18n("File could not be saved in '%1'. Try to save it to another location.").arg( url().path() ) );
|
2004-04-15 18:36:43 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 14:15:27 +00:00
|
|
|
void Part::slotPreferences()
|
2002-08-30 09:14:01 +00:00
|
|
|
{
|
2004-10-27 14:15:27 +00:00
|
|
|
// an instance the dialog could be already created and could be cached,
|
|
|
|
// in which case you want to display the cached dialog
|
|
|
|
if ( PreferencesDialog::showDialog( "preferences" ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// we didn't find an instance of this dialog, so lets create it
|
2004-10-29 13:33:51 +00:00
|
|
|
PreferencesDialog * dialog = new PreferencesDialog( m_pageView, Settings::self() );
|
2004-10-27 14:15:27 +00:00
|
|
|
// keep us informed when the user changes settings
|
2004-10-29 13:33:51 +00:00
|
|
|
connect( dialog, SIGNAL( settingsChanged() ), this, SLOT( slotNewConfig() ) );
|
2004-10-27 14:15:27 +00:00
|
|
|
|
|
|
|
dialog->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Part::slotNewConfig()
|
|
|
|
{
|
2004-10-29 13:33:51 +00:00
|
|
|
// Apply settings here. A good policy is to check wether the setting has
|
|
|
|
// changed before applying changes.
|
|
|
|
|
|
|
|
// Left Panel and search Widget
|
|
|
|
bool showLeft = Settings::showLeftPanel();
|
|
|
|
if ( m_toolBox->isShown() != showLeft )
|
|
|
|
{
|
|
|
|
// show/hide left qtoolbox
|
|
|
|
m_toolBox->setShown( showLeft );
|
|
|
|
// this needs to be hidden explicitly to disable thumbnails gen
|
|
|
|
m_thumbnailList->setShown( showLeft );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool showSearch = Settings::showSearchBar();
|
|
|
|
if ( m_searchWidget->isShown() != showSearch )
|
|
|
|
m_searchWidget->setShown( showSearch );
|
|
|
|
|
|
|
|
// Main View
|
|
|
|
QScrollView::ScrollBarMode scrollBarMode = Settings::showScrollBars() ?
|
|
|
|
QScrollView::AlwaysOn : QScrollView::AlwaysOff;
|
|
|
|
if ( m_pageView->hScrollBarMode() != scrollBarMode )
|
|
|
|
{
|
|
|
|
m_pageView->setHScrollBarMode( scrollBarMode );
|
|
|
|
m_pageView->setVScrollBarMode( scrollBarMode );
|
|
|
|
}
|
2004-10-09 08:10:56 +00:00
|
|
|
}
|
2002-08-30 09:14:01 +00:00
|
|
|
|
2004-10-09 08:10:56 +00:00
|
|
|
void Part::slotPrintPreview()
|
2002-09-02 21:56:00 +00:00
|
|
|
{
|
2004-11-03 21:37:21 +00:00
|
|
|
if (document->pages() == 0) return;
|
2002-09-02 21:56:00 +00:00
|
|
|
|
2004-10-09 08:10:56 +00:00
|
|
|
double width, height;
|
|
|
|
int landscape, portrait;
|
|
|
|
KPrinter printer;
|
2004-11-03 21:37:21 +00:00
|
|
|
const KPDFPage *page;
|
2004-09-18 16:41:23 +00:00
|
|
|
|
2004-11-03 21:37:21 +00:00
|
|
|
printer.setMinMax(1, document->pages());
|
2004-10-09 08:10:56 +00:00
|
|
|
printer.setPreviewOnly( true );
|
|
|
|
printer.setMargins(0, 0, 0, 0);
|
2004-09-18 16:41:23 +00:00
|
|
|
|
2004-11-03 21:37:21 +00:00
|
|
|
// if some pages are landscape and others are not the most common win as kprinter does
|
|
|
|
// not accept a per page setting
|
2004-10-09 08:10:56 +00:00
|
|
|
landscape = 0;
|
|
|
|
portrait = 0;
|
2004-11-03 21:37:21 +00:00
|
|
|
for (uint i = 0; i < document->pages(); i++)
|
2004-10-09 08:10:56 +00:00
|
|
|
{
|
2004-11-03 21:37:21 +00:00
|
|
|
page = document->page(i);
|
|
|
|
width = page->width();
|
|
|
|
height = page->height();
|
|
|
|
if (page->rotation() == 90 || page->rotation() == 270) qSwap(width, height);
|
|
|
|
if (width > height) landscape++;
|
|
|
|
else portrait++;
|
|
|
|
}
|
2004-10-09 08:10:56 +00:00
|
|
|
if (landscape > portrait) printer.setOption("orientation-requested", "4");
|
2004-09-18 16:41:23 +00:00
|
|
|
|
2004-10-09 08:10:56 +00:00
|
|
|
doPrint(printer);
|
2002-09-02 21:56:00 +00:00
|
|
|
}
|
|
|
|
|
2004-10-09 08:10:56 +00:00
|
|
|
void Part::slotPrint()
|
2004-01-02 17:46:06 +00:00
|
|
|
{
|
2004-11-03 21:37:21 +00:00
|
|
|
if (document->pages() == 0) return;
|
|
|
|
|
|
|
|
double width, height;
|
|
|
|
int landscape, portrait;
|
|
|
|
KPrinter printer;
|
|
|
|
const KPDFPage *page;
|
|
|
|
|
|
|
|
printer.setPageSelection(KPrinter::ApplicationSide);
|
|
|
|
printer.setMinMax(1, document->pages());
|
|
|
|
printer.setCurrentPage(document->currentPage()+1);
|
|
|
|
printer.setMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
// if some pages are landscape and others are not the most common win as kprinter does
|
|
|
|
// not accept a per page setting
|
|
|
|
landscape = 0;
|
|
|
|
portrait = 0;
|
|
|
|
for (uint i = 0; i < document->pages(); i++)
|
|
|
|
{
|
|
|
|
page = document->page(i);
|
|
|
|
width = page->width();
|
|
|
|
height = page->height();
|
|
|
|
if (page->rotation() == 90 || page->rotation() == 270) qSwap(width, height);
|
|
|
|
if (width > height) landscape++;
|
|
|
|
else portrait++;
|
|
|
|
}
|
|
|
|
if (landscape > portrait) printer.setOrientation(KPrinter::Landscape);
|
|
|
|
|
|
|
|
if (printer.setup(widget())) doPrint( printer );
|
2004-01-02 17:46:06 +00:00
|
|
|
}
|
|
|
|
|
2004-11-03 21:37:21 +00:00
|
|
|
void Part::doPrint(KPrinter &printer)
|
2004-01-02 17:46:06 +00:00
|
|
|
{
|
2004-11-03 21:37:21 +00:00
|
|
|
if (!document->okToPrint())
|
|
|
|
{
|
|
|
|
KMessageBox::error(widget(), i18n("Printing this document is not allowed."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!document->print(printer))
|
|
|
|
{
|
|
|
|
KMessageBox::error(widget(), i18n("Could not print the document. Please report to bugs.kde.org"));
|
|
|
|
}
|
2004-01-02 17:46:06 +00:00
|
|
|
}
|
|
|
|
|
2004-11-01 21:56:08 +00:00
|
|
|
void Part::restoreDocument(const KURL &url, int page)
|
|
|
|
{
|
|
|
|
if (openURL(url)) goToPage(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Part::saveDocumentRestoreInfo(KConfig* config)
|
|
|
|
{
|
|
|
|
config->writePathEntry( "URL", url().url() );
|
|
|
|
if (document->pages() > 0) config->writeEntry( "Page", document->currentPage() + 1);
|
|
|
|
}
|
|
|
|
|
2004-09-18 16:41:23 +00:00
|
|
|
/*
|
2004-09-08 12:41:14 +00:00
|
|
|
* BrowserExtension class
|
|
|
|
*/
|
|
|
|
BrowserExtension::BrowserExtension(Part* parent)
|
|
|
|
: KParts::BrowserExtension( parent, "KPDF::BrowserExtension" )
|
2004-08-26 23:25:52 +00:00
|
|
|
{
|
2004-09-08 12:41:14 +00:00
|
|
|
emit enableAction("print", true);
|
|
|
|
setURLDropHandlingEnabled(true);
|
|
|
|
}
|
2004-08-29 11:24:11 +00:00
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
void BrowserExtension::print()
|
|
|
|
{
|
|
|
|
static_cast<Part*>(parent())->slotPrint();
|
2004-08-26 23:25:52 +00:00
|
|
|
}
|
|
|
|
|
2004-09-16 21:27:34 +00:00
|
|
|
#include "kpdf_part.moc"
|