📄 part.cpp.svn-base
字号:
/*************************************************************************** * 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-2006 by Albert Astals Cid <tsdgeos@terra.es> * * Copyright (C) 2004 by Antti Markus <antti.markus@starman.ee> * * * * 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. * ***************************************************************************/// qt/kde includes#include <qsplitter.h>#include <qpainter.h>#include <qlayout.h>#include <qlabel.h>#include <kvbox.h>#include <qtoolbox.h>#include <kaction.h>#include <kactioncollection.h>#include <kdirwatch.h>#include <kinstance.h>#include <kprinter.h>#include <kstdaction.h>#include <kdeversion.h>#include <kparts/genericfactory.h>#include <kfiledialog.h>#include <kfind.h>#include <kmessagebox.h>#include <kmimetypetrader.h>#include <kfinddialog.h>#include <knuminput.h>#include <kiconloader.h>#include <kio/netaccess.h>#include <kmenu.h>#include <kxmlguiclient.h>#include <kxmlguifactory.h>#include <kprocess.h>#include <kservicetypetrader.h>#include <kstandarddirs.h>#include <ktempfile.h>#include <ktoggleaction.h>#include <ktogglefullscreenaction.h>#include <kio/job.h>#include <kicon.h>// local includes#include "part.h"#include "ui/pageview.h"#include "ui/toc.h"#include "ui/searchwidget.h"#include "ui/thumbnaillist.h"#include "ui/side_reviews.h"#include "ui/minibar.h"#include "ui/newstuff.h"#include "ui/embeddedfilesdialog.h"#include "ui/propertiesdialog.h"#include "ui/presentationwidget.h"#include "conf/preferencesdialog.h"#include "settings.h"#include "core/document.h"#include "core/generator.h"#include "core/page.h"typedef KParts::GenericFactory<okular::Part> okularPartFactory;K_EXPORT_COMPONENT_FACTORY(libokularpart, okularPartFactory)using namespace okular;Part::Part(QWidget *parentWidget, QObject *parent, const QStringList & /*args*/ ) : KParts::ReadOnlyPart(parent), m_viewportDirty( 0 ), m_showMenuBarAction(0), m_showFullScreenAction(0), m_actionsSearched(false), m_searchStarted(false){ QDBus::sessionBus().registerObject("/okular", this, QDBusConnection::ExportSlots); // connect the started signal to tell the job the mimetypes we like connect(this, SIGNAL(started(KIO::Job *)), this, SLOT(setMimeTypes(KIO::Job *))); // load catalog for translation KGlobal::locale()->insertCatalog("okular"); // create browser extension (for printing when embedded into browser) m_bExtension = new BrowserExtension(this); // we need an instance setInstance(okularPartFactory::instance()); // build the document m_document = new KPDFDocument(&m_loadedGenerators); connect( m_document, SIGNAL( linkFind() ), this, SLOT( slotFind() ) ); connect( m_document, SIGNAL( linkGoToPage() ), this, SLOT( slotGoToPage() ) ); connect( m_document, SIGNAL( linkPresentation() ), this, SLOT( slotShowPresentation() ) ); connect( m_document, SIGNAL( linkEndPresentation() ), this, SLOT( slotHidePresentation() ) ); connect( m_document, SIGNAL( openURL(const KUrl &) ), this, SLOT( openURLFromDocument(const KUrl &) ) ); connect( m_document, SIGNAL( close() ), this, SLOT( close() ) ); if ( parent && parent->metaObject()->indexOfSlot( SLOT( slotQuit() ) ) != -1 ) connect( m_document, SIGNAL( quit() ), parent, SLOT( slotQuit() ) ); else connect( m_document, SIGNAL( quit() ), this, SLOT( cannotQuit() ) ); // 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, m_document );// sLabel->setBuddy( m_searchWidget );// m_searchToolBar->setStretchableWidget( m_searchWidget ); // widgets: [] splitter [] m_splitter = new QSplitter( parentWidget ); m_splitter->setOpaqueResize( true ); m_splitter->setChildrenCollapsible( false ); setWidget( m_splitter ); // widgets: [left panel] | [] m_leftPanel = new QWidget( m_splitter ); m_leftPanel->setMinimumWidth( 90 ); m_leftPanel->setMaximumWidth( 300 ); QVBoxLayout * leftPanelLayout = new QVBoxLayout( m_leftPanel ); leftPanelLayout->setMargin( 0 ); // widgets: [left toolbox/..] | [] m_toolBox = new QToolBox( m_leftPanel ); leftPanelLayout->addWidget( m_toolBox ); int tbIndex; // [left toolbox: Table of Contents] | [] m_toc = new TOC( m_toolBox, m_document ); connect( m_toc, SIGNAL( hasTOC( bool ) ), this, SLOT( enableTOC( bool ) ) ); tbIndex = m_toolBox->addItem( m_toc, SmallIconSet("text_left"), i18n("Contents") ); m_toolBox->setItemToolTip( tbIndex, i18n("Contents") ); enableTOC( false ); // [left toolbox: Thumbnails and Bookmarks] | [] KVBox * thumbsBox = new ThumbnailsBox( m_toolBox ); thumbsBox->setSpacing( 4 ); m_searchWidget = new SearchWidget( thumbsBox, m_document ); m_thumbnailList = new ThumbnailList( thumbsBox, m_document );// ThumbnailController * m_tc = new ThumbnailController( thumbsBox, m_thumbnailList ); connect( m_thumbnailList, SIGNAL( urlDropped( const KUrl& ) ), SLOT( openURLFromDocument( const KUrl & )) ); connect( m_thumbnailList, SIGNAL( rightClick(const KPDFPage *, const QPoint &) ), this, SLOT( slotShowMenu(const KPDFPage *, const QPoint &) ) ); tbIndex = m_toolBox->addItem( thumbsBox, SmallIconSet("thumbnail"), i18n("Thumbnails") ); m_toolBox->setItemToolTip( tbIndex, i18n("Thumbnails") ); m_toolBox->setCurrentIndex( m_toolBox->indexOf( thumbsBox ) ); // [left toolbox: Reviews] | [] Reviews * reviewsWidget = new Reviews( m_toolBox, m_document ); m_toolBox->addItem( reviewsWidget, SmallIconSet("pencil"), i18n("Reviews") ); // widgets: [../miniBarContainer] | [] QWidget * miniBarContainer = new QWidget( m_leftPanel ); leftPanelLayout->addWidget( miniBarContainer ); QVBoxLayout * miniBarLayout = new QVBoxLayout( miniBarContainer ); miniBarLayout->setMargin( 0 ); // widgets: [../[spacer/..]] | [] QWidget * miniSpacer = new QWidget( miniBarContainer ); miniSpacer->setFixedHeight( 6 ); miniBarLayout->addWidget( miniSpacer ); // widgets: [../[../MiniBar]] | [] m_miniBar = new MiniBar( miniBarContainer, m_document ); miniBarLayout->addWidget( m_miniBar ); // widgets: [] | [right 'pageView']// QWidget * rightContainer = new QWidget( m_splitter );// QVBoxLayout * rightLayout = new QVBoxLayout( rightContainer );// KToolBar * rtb = new KToolBar( rightContainer, "mainToolBarSS" );// rightLayout->addWidget( rtb ); m_pageView = new PageView( m_splitter, m_document ); m_pageView->setFocus(); //usability setting connect( m_pageView, SIGNAL( urlDropped( const KUrl& ) ), SLOT( openURLFromDocument( const KUrl & ))); connect( m_pageView, SIGNAL( rightClick(const KPDFPage *, const QPoint &) ), this, SLOT( slotShowMenu(const KPDFPage *, const QPoint &) ) ); connect( m_document, SIGNAL( error( const QString&, int ) ), m_pageView, SLOT( errorMessage( const QString&, int ) ) ); connect( m_document, SIGNAL( warning( const QString&, int ) ), m_pageView, SLOT( warningMessage( const QString&, int ) ) ); connect( m_document, SIGNAL( notice( const QString&, int ) ), m_pageView, SLOT( noticeMessage( const QString&, int ) ) );// rightLayout->addWidget( m_pageView ); // add document observers m_document->addObserver( this ); m_document->addObserver( m_thumbnailList ); m_document->addObserver( m_pageView ); m_document->addObserver( m_toc ); m_document->addObserver( m_miniBar ); m_document->addObserver( reviewsWidget ); // ACTIONS KActionCollection * ac = actionCollection(); // Page Traversal actions m_gotoPage = KStdAction::gotoPage( this, SLOT( slotGoToPage() ), ac, "goto_page" ); m_gotoPage->setShortcut( QKeySequence(Qt::CTRL + Qt::Key_G) ); // dirty way to activate gotopage when pressing miniBar's button connect( m_miniBar, SIGNAL( gotoPage() ), m_gotoPage, SLOT( trigger() ) ); m_prevPage = KStdAction::prior(this, SLOT(slotPreviousPage()), ac, "previous_page"); m_prevPage->setWhatsThis( i18n( "Moves to the previous page of the document" ) ); m_prevPage->setShortcut( 0 ); // dirty way to activate prev page when pressing miniBar's button connect( m_miniBar, SIGNAL( prevPage() ), m_prevPage, SLOT( trigger() ) ); m_nextPage = KStdAction::next(this, SLOT(slotNextPage()), ac, "next_page" ); m_nextPage->setWhatsThis( i18n( "Moves to the next page of the document" ) ); m_nextPage->setShortcut( 0 ); // dirty way to activate next page when pressing miniBar's button connect( m_miniBar, SIGNAL( nextPage() ), m_nextPage, SLOT( trigger() ) ); m_firstPage = KStdAction::firstPage( this, SLOT( slotGotoFirst() ), ac, "first_page" ); m_firstPage->setWhatsThis( i18n( "Moves to the first page of the document" ) ); m_lastPage = KStdAction::lastPage( this, SLOT( slotGotoLast() ), ac, "last_page" ); m_lastPage->setWhatsThis( i18n( "Moves to the last page of the document" ) ); m_historyBack = KStdAction::back( this, SLOT( slotHistoryBack() ), ac, "history_back" ); m_historyBack->setWhatsThis( i18n( "Go to the place you were before" ) ); m_historyNext = KStdAction::forward( this, SLOT( slotHistoryNext() ), ac, "history_forward" ); m_historyNext->setWhatsThis( i18n( "Go to the place you were after" ) ); m_prevBookmark = new KAction( KIcon( "previous" ), i18n( "Previous Bookmark" ), ac, "previous_bookmark" ); m_prevBookmark->setWhatsThis( i18n( "Go to the previous bookmarked page" ) ); connect( m_prevBookmark, SIGNAL( triggered() ), this, SLOT( slotPreviousBookmark() ) ); m_nextBookmark = new KAction( KIcon( "next" ), i18n( "Next Bookmark" ), ac, "next_bookmark" ); m_nextBookmark->setWhatsThis( i18n( "Go to the next bookmarked page" ) ); connect( m_nextBookmark, SIGNAL( triggered() ), this, SLOT( slotNextBookmark() ) ); // Find and other actions m_find = KStdAction::find( this, SLOT( slotFind() ), ac, "find" ); m_find->setEnabled( false ); m_findNext = KStdAction::findNext( this, SLOT( slotFindNext() ), ac, "find_next" ); m_findNext->setEnabled( false ); m_saveAs = KStdAction::saveAs( this, SLOT( slotSaveFileAs() ), ac, "save" ); m_saveAs->setEnabled( false ); KAction * prefs = KStdAction::preferences( this, SLOT( slotPreferences() ), ac, "preferences" ); if ( parent && ( parent->objectName() == QLatin1String( "okular::Shell" ) ) ) { prefs->setText( i18n( "Configure okular..." ) ); } else { prefs->setText( i18n( "Configure Viewer..." ) ); // TODO: improve this message } KAction * genPrefs = KStdAction::preferences( this, SLOT( slotGeneratorPreferences() ), ac, "generator_prefs" ); genPrefs->setText( i18n( "Configure Backends..." ) ); QString constraint("([X-KDE-Priority] > 0) and (exist Library) and ([X-KDE-okularHasInternalSettings])") ; KService::List gens = KServiceTypeTrader::self()->query("okular/Generator",constraint); if (gens.count() <= 0) { genPrefs->setEnabled( false ); } m_printPreview = KStdAction::printPreview( this, SLOT( slotPrintPreview() ), ac ); m_printPreview->setEnabled( false ); m_showLeftPanel = new KToggleAction( KIcon( "show_side_panel" ), i18n( "Show &Navigation Panel"), ac, "show_leftpanel" ); connect( m_showLeftPanel, SIGNAL( toggled( bool ) ), this, SLOT( slotShowLeftPanel() ) ); m_showLeftPanel->setShortcut( QKeySequence(Qt::CTRL + Qt::Key_L) ); m_showLeftPanel->setCheckedState( i18n( "Hide &Navigation Panel" ) ); m_showLeftPanel->setChecked( KpdfSettings::showLeftPanel() ); slotShowLeftPanel(); KAction * importPS= new KAction(KIcon("psimport"), i18n("&Import Postscript as PDF..."), ac, "import_ps"); connect(importPS, SIGNAL(triggered()), this, SLOT(slotImportPSFile())); KAction * ghns = new KAction(KIcon("knewstuff"), i18n("&Get Books From Internet..."), ac, "get_new_stuff"); connect(ghns, SIGNAL(triggered()), this, SLOT(slotGetNewStuff())); ghns->setShortcut( Qt::Key_G ); // TEMP, REMOVE ME! m_showProperties = new KAction(KIcon("info"), i18n("&Properties"), ac, "properties"); connect(m_showProperties, SIGNAL(triggered()), this, SLOT(slotShowProperties())); m_showProperties->setEnabled( false ); m_showEmbeddedFiles = new KAction(i18n("&Embedded Files"), ac, "embeddedFiles"); connect(m_showEmbeddedFiles, SIGNAL(triggered()), this, SLOT(slotShowEmbeddedFiles())); m_showEmbeddedFiles->setEnabled( false ); m_showPresentation = new KAction( KIcon( "kpresenter_kpr" ), i18n("P&resentation"), ac, "presentation"); connect(m_showPresentation, SIGNAL(triggered()), this, SLOT(slotShowPresentation())); m_showPresentation->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_P ) ); m_showPresentation->setEnabled( false ); m_exportAs = new KAction(i18n("E&xport As"), ac, "file_export_as"); QMenu *menu = new QMenu(); connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(slotExportAs(QAction *))); m_exportAs->setMenu( menu ); m_exportAsText = menu->addAction( KIcon( "text" ), i18n( "Text..." ) ); m_exportAsText->setEnabled( false ); // attach the actions of the children widgets too m_pageView->setupActions( ac ); // apply configuration (both internal settings and GUI configured items) QList<int> splitterSizes = KpdfSettings::splitterSizes(); if ( !splitterSizes.count() ) { // the first time use 1/10 for the panel and 9/10 for the pageView splitterSizes.push_back( 50 ); splitterSizes.push_back( 500 ); } m_splitter->setSizes( splitterSizes ); // get notified about splitter size changes (HACK that will be removed // by connecting to Qt4::QSplitter's sliderMoved()) m_pageView->installEventFilter( this ); // document watcher and reloader m_watcher = new KDirWatch( this ); connect( m_watcher, SIGNAL( dirty( const QString& ) ), this, SLOT( slotFileDirty( const QString& ) ) ); m_dirtyHandler = new QTimer( this ); m_dirtyHandler->setSingleShot( true ); connect( m_dirtyHandler, SIGNAL( timeout() ),this, SLOT( slotDoFileDirty() ) ); slotNewConfig(); // [SPEECH] check for KTTSD presence and usability KService::List offers = KServiceTypeTrader::self()->query("DCOP/Text-to-Speech", "Name == 'KTTSD'"); KpdfSettings::setUseKTTSD( !offers.isEmpty() ); KpdfSettings::writeConfig(); // set our XML-UI resource file setXMLFile("part.rc"); // updateViewActions();}Part::~Part(){ delete m_toc; delete m_pageView; delete m_thumbnailList; delete m_miniBar; delete m_document;}void Part::openURLFromDocument(const KUrl &url){ m_bExtension->openURLNotify(); m_bExtension->setLocationBarURL(url.prettyUrl()); openURL(url);}void Part::supportedMimetypes(){ m_supportedMimeTypes.clear(); QString constraint("([X-KDE-Priority] > 0) and (exist Library) ") ; KService::List offers = KServiceTypeTrader::self()->query("okular/Generator",constraint); KService::List::ConstIterator iterator = offers.begin(); KService::List::ConstIterator end = offers.end(); QStringList::Iterator mimeType; for (; iterator != end; ++iterator) { KService::Ptr service = *iterator; QStringList mimeTypes = service->serviceTypes(); for (mimeType=mimeTypes.begin();mimeType!=mimeTypes.end();++mimeType) if (! (*mimeType).contains("okular")) m_supportedMimeTypes << *mimeType; }}void Part::setMimeTypes(KIO::Job *job){ if (job) { if (m_supportedMimeTypes.count() <= 0) supportedMimetypes(); job->addMetaData("accept", m_supportedMimeTypes.join(", ") + ", */*;q=0.5"); }}void Part::fillGenerators(){ QString constraint("([X-KDE-Priority] > 0) and (exist Library) and ([X-KDE-okularHasInternalSettings])") ; KService::List offers = KServiceTypeTrader::self()->query("okular/Generator", constraint); QString propName; int count=offers.count(); if (count > 0) { KLibLoader *loader = KLibLoader::self(); if (!loader) { kWarning() << "Could not start library loader: '" << loader->lastErrorMessage() << "'." << endl; return; } for (int i=0;i<count;i++) { propName=offers[i]->property("Name").toString(); // dont load already loaded generators if (! m_loadedGenerators.take( propName ) ) { KLibrary *lib = loader->globalLibrary( QFile::encodeName( offers[i]->library() ) ); if (!lib) { kWarning() << "Could not load '" << offers[i]->library() << "' library." << endl; continue; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -