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 > *
2007-01-26 18:54:41 +00:00
* Copyright ( C ) 2004 - 2007 by Albert Astals Cid < aacid @ kde . org > *
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 . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-01-02 14:55:14 +00:00
// qt/kde includes
2007-01-05 19:02:39 +00:00
# include <qapplication.h>
2004-09-09 13:25:40 +00:00
# include <qsplitter.h>
# include <qlayout.h>
# include <qlabel.h>
2006-03-24 21:31:46 +00:00
# include <kvbox.h>
2004-09-23 17:16:04 +00:00
# include <qtoolbox.h>
2007-03-07 18:15:00 +00:00
# include <kaboutapplicationdialog.h>
2002-08-30 09:14:01 +00:00
# include <kaction.h>
2006-05-13 14:59:50 +00:00
# include <kactioncollection.h>
2004-12-01 22:18:27 +00:00
# include <kdirwatch.h>
2002-08-30 12:10:02 +00:00
# include <kprinter.h>
2006-12-19 12:23:43 +00:00
# include <kstandardaction.h>
2002-08-30 09:14:01 +00:00
# include <kparts/genericfactory.h>
2004-08-28 17:59:17 +00:00
# include <kfiledialog.h>
2006-03-24 22:57:41 +00:00
# include <kfind.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-16 21:27:34 +00:00
# include <kio/netaccess.h>
2006-03-24 22:57:41 +00:00
# include <kmenu.h>
2004-12-04 23:23:18 +00:00
# include <kxmlguiclient.h>
# include <kxmlguifactory.h>
2005-07-15 18:20:57 +00:00
# include <kprocess.h>
2006-05-22 14:02:24 +00:00
# include <kservicetypetrader.h>
2005-07-15 18:20:57 +00:00
# include <kstandarddirs.h>
2006-10-16 17:57:44 +00:00
# include <ktemporaryfile.h>
2006-05-08 18:57:49 +00:00
# include <ktoggleaction.h>
2006-05-13 14:59:50 +00:00
# include <ktogglefullscreenaction.h>
2005-11-04 11:59:51 +00:00
# include <kio/job.h>
2006-08-05 10:35:03 +00:00
# include <kicon.h>
2007-01-12 23:54:26 +00:00
# include <kfilterdev.h>
2005-01-02 14:55:14 +00:00
// local includes
2007-03-10 23:45:12 +00:00
# include "aboutdata.h"
2005-01-02 14:29:37 +00:00
# include "part.h"
# include "ui/pageview.h"
# include "ui/toc.h"
2005-03-24 19:50:28 +00:00
# include "ui/searchwidget.h"
# include "ui/thumbnaillist.h"
# include "ui/side_reviews.h"
2005-01-26 10:42:07 +00:00
# include "ui/minibar.h"
2005-04-16 00:25:26 +00:00
# include "ui/newstuff.h"
2006-05-28 16:54:54 +00:00
# include "ui/embeddedfilesdialog.h"
2005-01-02 14:29:37 +00:00
# include "ui/propertiesdialog.h"
# include "ui/presentationwidget.h"
2006-10-15 19:37:14 +00:00
# include "ui/pagesizelabel.h"
2006-12-27 16:04:49 +00:00
# include "ui/bookmarklist.h"
2005-01-02 14:29:37 +00:00
# include "conf/preferencesdialog.h"
2006-03-28 22:22:10 +00:00
# include "settings.h"
2007-01-13 17:28:54 +00:00
# include "core/bookmarkmanager.h"
2005-01-02 14:29:37 +00:00
# include "core/document.h"
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
# include "core/generator.h"
2005-01-02 14:29:37 +00:00
# include "core/page.h"
2007-01-03 14:30:48 +00:00
# include "interfaces/configinterface.h"
2003-06-28 01:59:03 +00:00
2006-09-21 08:45:36 +00:00
typedef KParts : : GenericFactory < Part > okularPartFactory ;
2006-06-12 18:25:18 +00:00
K_EXPORT_COMPONENT_FACTORY ( libokularpart , okularPartFactory )
2002-08-30 09:14:01 +00:00
2007-03-10 21:32:09 +00:00
static QAction * actionForExportFormat ( const Okular : : ExportFormat & format , QObject * parent = 0 )
{
QAction * act = new QAction ( format . description ( ) , parent ) ;
if ( ! format . icon ( ) . isNull ( ) )
{
act - > setIcon ( format . icon ( ) ) ;
}
return act ;
}
2006-05-08 18:57:49 +00:00
Part : : Part ( QWidget * parentWidget ,
2007-01-13 00:33:50 +00:00
QObject * parent ,
const QStringList & /*args*/ )
: KParts : : ReadOnlyPart ( parent ) ,
m_showMenuBarAction ( 0 ) , m_showFullScreenAction ( 0 ) , m_actionsSearched ( false ) ,
m_searchStarted ( false ) , m_cliPresentation ( false )
2002-08-30 09:14:01 +00:00
{
2007-01-13 00:33:50 +00:00
QDBusConnection : : sessionBus ( ) . registerObject ( " /okular " , this , QDBusConnection : : ExportScriptableSlots ) ;
// 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 " ) ;
m_tempfile = 0L ;
// create browser extension (for printing when embedded into browser)
m_bExtension = new BrowserExtension ( this ) ;
// we need an instance
2007-01-29 20:18:39 +00:00
setComponentData ( okularPartFactory : : componentData ( ) ) ;
2007-01-13 00:33:50 +00:00
// build the document
2007-01-28 15:46:10 +00:00
m_document = new Okular : : Document ( ) ;
2007-01-13 00:33:50 +00:00
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 & ) ) ) ;
2007-01-13 17:28:54 +00:00
connect ( m_document - > bookmarkManager ( ) , SIGNAL ( openUrl ( const KUrl & ) ) , this , SLOT ( openUrlFromBookmarks ( const KUrl & ) ) ) ;
2007-01-13 00:33:50 +00:00
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 ) ;
m_splitter - > setCollapsible ( 0 , true ) ;
// 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 ) ) ) ;
2007-03-08 21:41:46 +00:00
tbIndex = m_toolBox - > addItem ( m_toc , KIcon ( QApplication : : isLeftToRight ( ) ? " leftjust " : " format-justify-right " ) , i18n ( " Contents " ) ) ;
2007-01-13 00:33:50 +00:00
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 Okular : : Page * , const QPoint & ) ) , this , SLOT ( slotShowMenu ( const Okular : : Page * , const QPoint & ) ) ) ;
2007-03-08 21:41:46 +00:00
tbIndex = m_toolBox - > addItem ( thumbsBox , KIcon ( " thumbnail-show " ) , i18n ( " Thumbnails " ) ) ;
2007-01-13 00:33:50 +00:00
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 , KIcon ( " pencil " ) , i18n ( " Reviews " ) ) ;
// [left toolbox: Bookmarks] | []
BookmarkList * bookmarkList = new BookmarkList ( m_document , m_toolBox ) ;
connect ( bookmarkList , SIGNAL ( openUrl ( const KUrl & ) ) , this , SLOT ( openUrlFromDocument ( const KUrl & ) ) ) ;
m_toolBox - > addItem ( bookmarkList , KIcon ( " bookmark " ) , i18n ( " Bookmarks " ) ) ;
// widgets: [../miniBarContainer] | []
QWidget * miniBarContainer = new QWidget ( m_leftPanel ) ;
leftPanelLayout - > addWidget ( miniBarContainer ) ;
QVBoxLayout * miniBarLayout = new QVBoxLayout ( miniBarContainer ) ;
miniBarLayout - > setMargin ( 0 ) ;
// widgets: [../[spacer/..]] | []
miniBarLayout - > addItem ( new QSpacerItem ( 6 , 6 , QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ) ;
// widgets: [../[../MiniBar]] | []
QFrame * bevelContainer = new QFrame ( miniBarContainer ) ;
bevelContainer - > setFrameStyle ( QFrame : : StyledPanel | QFrame : : Sunken ) ;
QVBoxLayout * bevelContainerLayout = new QVBoxLayout ( bevelContainer ) ;
bevelContainerLayout - > setMargin ( 4 ) ;
m_progressWidget = new ProgressWidget ( bevelContainer , m_document ) ;
bevelContainerLayout - > addWidget ( m_progressWidget ) ;
miniBarLayout - > addWidget ( bevelContainer ) ;
miniBarLayout - > addItem ( new QSpacerItem ( 6 , 6 , QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ) ;
// widgets: [] | [right 'pageView']
QWidget * rightContainer = new QWidget ( m_splitter ) ;
QVBoxLayout * rightLayout = new QVBoxLayout ( rightContainer ) ;
rightLayout - > setMargin ( 0 ) ;
rightLayout - > setSpacing ( 0 ) ;
// KToolBar * rtb = new KToolBar( rightContainer, "mainToolBarSS" );
// rightLayout->addWidget( rtb );
m_topMessage = new PageViewTopMessage ( rightContainer ) ;
2007-02-23 10:54:30 +00:00
m_topMessage - > setup ( i18n ( " This document has embedded files. <a href= \" okular:/embeddedfiles \" >Click here to see them</a> or go to File -> Embedded Files. " ) , KIcon ( " attach " ) ) ;
2007-01-13 00:33:50 +00:00
connect ( m_topMessage , SIGNAL ( action ( ) ) , this , SLOT ( slotShowEmbeddedFiles ( ) ) ) ;
rightLayout - > addWidget ( m_topMessage ) ;
2007-02-25 00:07:59 +00:00
m_formsMessage = new PageViewTopMessage ( rightContainer ) ;
m_formsMessage - > setup ( i18n ( " This document has forms. Click on the button to interact with them, or use View -> Show Forms. " ) ) ;
rightLayout - > addWidget ( m_formsMessage ) ;
2007-01-13 00:33:50 +00:00
m_pageView = new PageView ( rightContainer , m_document ) ;
m_pageView - > setFocus ( ) ; //usability setting
2007-01-31 19:23:12 +00:00
m_splitter - > setFocusProxy ( m_pageView ) ;
2007-01-13 00:33:50 +00:00
connect ( m_pageView , SIGNAL ( urlDropped ( const KUrl & ) ) , SLOT ( openUrlFromDocument ( const KUrl & ) ) ) ;
connect ( m_pageView , SIGNAL ( rightClick ( const Okular : : Page * , const QPoint & ) ) , this , SLOT ( slotShowMenu ( const Okular : : Page * , 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 ) ;
QWidget * bottomBar = new QWidget ( rightContainer ) ;
QHBoxLayout * bottomBarLayout = new QHBoxLayout ( bottomBar ) ;
m_pageSizeLabel = new PageSizeLabel ( bottomBar , m_document ) ;
bottomBarLayout - > setMargin ( 0 ) ;
bottomBarLayout - > setSpacing ( 0 ) ;
bottomBarLayout - > addWidget ( m_pageSizeLabel - > antiWidget ( ) ) ;
bottomBarLayout - > addItem ( new QSpacerItem ( 5 , 5 , QSizePolicy : : Expanding , QSizePolicy : : Minimum ) ) ;
m_miniBar = new MiniBar ( bottomBar , m_document ) ;
bottomBarLayout - > addWidget ( m_miniBar ) ;
bottomBarLayout - > addItem ( new QSpacerItem ( 5 , 5 , QSizePolicy : : Expanding , QSizePolicy : : Minimum ) ) ;
bottomBarLayout - > addWidget ( m_pageSizeLabel ) ;
rightLayout - > addWidget ( bottomBar ) ;
2004-09-23 17:16:04 +00:00
2006-12-30 12:40:54 +00:00
connect ( reviewsWidget , SIGNAL ( setAnnotationWindow ( Okular : : Annotation * ) ) ,
2007-01-13 00:33:50 +00:00
m_pageView , SLOT ( setAnnotationWindow ( Okular : : Annotation * ) ) ) ;
2006-12-30 12:40:54 +00:00
connect ( reviewsWidget , SIGNAL ( removeAnnotationWindow ( Okular : : Annotation * ) ) ,
2007-01-13 00:33:50 +00:00
m_pageView , SLOT ( removeAnnotationWindow ( Okular : : Annotation * ) ) ) ;
// 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 ( m_progressWidget ) ;
m_document - > addObserver ( reviewsWidget ) ;
m_document - > addObserver ( m_pageSizeLabel ) ;
m_document - > addObserver ( bookmarkList ) ;
// ACTIONS
KActionCollection * ac = actionCollection ( ) ;
// Page Traversal actions
m_gotoPage = KStandardAction : : gotoPage ( this , SLOT ( slotGoToPage ( ) ) , ac ) ;
ac - > addAction ( " goto_page " , m_gotoPage ) ;
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 = KStandardAction : : prior ( this , SLOT ( slotPreviousPage ( ) ) , ac ) ;
ac - > addAction ( " previous_page " , m_prevPage ) ;
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 ( ) ) ) ;
connect ( m_progressWidget , SIGNAL ( prevPage ( ) ) , m_prevPage , SLOT ( trigger ( ) ) ) ;
m_nextPage = KStandardAction : : next ( this , SLOT ( slotNextPage ( ) ) , ac ) ;
ac - > addAction ( " next_page " , m_nextPage ) ;
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 ( ) ) ) ;
connect ( m_progressWidget , SIGNAL ( nextPage ( ) ) , m_nextPage , SLOT ( trigger ( ) ) ) ;
m_firstPage = KStandardAction : : firstPage ( this , SLOT ( slotGotoFirst ( ) ) , ac ) ;
ac - > addAction ( " first_page " , m_firstPage ) ;
m_firstPage - > setWhatsThis ( i18n ( " Moves to the first page of the document " ) ) ;
m_lastPage = KStandardAction : : lastPage ( this , SLOT ( slotGotoLast ( ) ) , ac ) ;
ac - > addAction ( " last_page " , m_lastPage ) ;
m_lastPage - > setWhatsThis ( i18n ( " Moves to the last page of the document " ) ) ;
m_historyBack = KStandardAction : : back ( this , SLOT ( slotHistoryBack ( ) ) , ac ) ;
ac - > addAction ( " history_back " , m_historyBack ) ;
m_historyBack - > setWhatsThis ( i18n ( " Go to the place you were before " ) ) ;
m_historyNext = KStandardAction : : forward ( this , SLOT ( slotHistoryNext ( ) ) , ac ) ;
ac - > addAction ( " history_forward " , m_historyNext ) ;
m_historyNext - > setWhatsThis ( i18n ( " Go to the place you were after " ) ) ;
m_prevBookmark = ac - > addAction ( " previous_bookmark " ) ;
m_prevBookmark - > setText ( i18n ( " Previous Bookmark " ) ) ;
2007-03-08 21:41:46 +00:00
m_prevBookmark - > setIcon ( KIcon ( " find-previous " ) ) ;
2007-01-13 00:33:50 +00:00
m_prevBookmark - > setWhatsThis ( i18n ( " Go to the previous bookmarked page " ) ) ;
connect ( m_prevBookmark , SIGNAL ( triggered ( ) ) , this , SLOT ( slotPreviousBookmark ( ) ) ) ;
m_nextBookmark = ac - > addAction ( " next_bookmark " ) ;
m_nextBookmark - > setText ( i18n ( " Next Bookmark " ) ) ;
2007-03-08 21:41:46 +00:00
m_nextBookmark - > setIcon ( KIcon ( " find-next " ) ) ;
2007-01-13 00:33:50 +00:00
m_nextBookmark - > setWhatsThis ( i18n ( " Go to the next bookmarked page " ) ) ;
connect ( m_nextBookmark , SIGNAL ( triggered ( ) ) , this , SLOT ( slotNextBookmark ( ) ) ) ;
m_copy = KStandardAction : : create ( KStandardAction : : Copy , m_pageView , SLOT ( copyTextSelection ( ) ) , ac ) ;
ac - > addAction ( " edit_copy " , m_copy ) ;
// Find and other actions
m_find = KStandardAction : : find ( this , SLOT ( slotFind ( ) ) , ac ) ;
ac - > addAction ( " find " , m_find ) ;
m_find - > setEnabled ( false ) ;
m_findNext = KStandardAction : : findNext ( this , SLOT ( slotFindNext ( ) ) , ac ) ;
ac - > addAction ( " find_next " , m_findNext ) ;
m_findNext - > setEnabled ( false ) ;
m_saveAs = KStandardAction : : saveAs ( this , SLOT ( slotSaveFileAs ( ) ) , ac ) ;
ac - > addAction ( " save " , m_saveAs ) ;
m_saveAs - > setEnabled ( false ) ;
QAction * prefs = KStandardAction : : preferences ( this , SLOT ( slotPreferences ( ) ) , ac ) ;
ac - > addAction ( " preferences " , prefs ) ;
if ( parent & & ( parent - > objectName ( ) = = QLatin1String ( " okular::Shell " ) ) )
{
prefs - > setText ( i18n ( " Configure okular... " ) ) ;
}
else
{
// TODO: improve this message
prefs - > setText ( i18n ( " Configure Viewer... " ) ) ;
}
QAction * genPrefs = KStandardAction : : preferences ( this , SLOT ( slotGeneratorPreferences ( ) ) , ac ) ;
ac - > addAction ( " generator_prefs " , genPrefs ) ;
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 = KStandardAction : : printPreview ( this , SLOT ( slotPrintPreview ( ) ) , ac ) ;
m_printPreview - > setEnabled ( false ) ;
m_showLeftPanel = ac - > add < KToggleAction > ( " show_leftpanel " ) ;
m_showLeftPanel - > setText ( i18n ( " Show &Navigation Panel " ) ) ;
m_showLeftPanel - > setIcon ( KIcon ( " show_side_panel " ) ) ;
connect ( m_showLeftPanel , SIGNAL ( toggled ( bool ) ) , this , SLOT ( slotShowLeftPanel ( ) ) ) ;
m_showLeftPanel - > setShortcut ( QKeySequence ( Qt : : CTRL + Qt : : Key_L ) ) ;
m_showLeftPanel - > setCheckedState ( KGuiItem ( i18n ( " Hide &Navigation Panel " ) ) ) ;
m_showLeftPanel - > setChecked ( Okular : : Settings : : showLeftPanel ( ) ) ;
slotShowLeftPanel ( ) ;
QAction * importPS = ac - > addAction ( " import_ps " ) ;
importPS - > setText ( i18n ( " &Import Postscript as PDF... " ) ) ;
importPS - > setIcon ( KIcon ( " psimport " ) ) ;
connect ( importPS , SIGNAL ( triggered ( ) ) , this , SLOT ( slotImportPSFile ( ) ) ) ;
QAction * ghns = ac - > addAction ( " get_new_stuff " ) ;
ghns - > setText ( i18n ( " &Get Books From Internet... " ) ) ;
2007-03-08 21:41:46 +00:00
ghns - > setIcon ( KIcon ( " get-hot-new-stuff " ) ) ;
2007-01-13 00:33:50 +00:00
connect ( ghns , SIGNAL ( triggered ( ) ) , this , SLOT ( slotGetNewStuff ( ) ) ) ;
// TEMP, REMOVE ME!
ghns - > setShortcut ( Qt : : Key_G ) ;
m_showProperties = ac - > addAction ( " properties " ) ;
m_showProperties - > setText ( i18n ( " &Properties " ) ) ;
2007-03-08 21:41:46 +00:00
m_showProperties - > setIcon ( KIcon ( " document-properties " ) ) ;
2007-01-13 00:33:50 +00:00
connect ( m_showProperties , SIGNAL ( triggered ( ) ) , this , SLOT ( slotShowProperties ( ) ) ) ;
m_showProperties - > setEnabled ( false ) ;
m_showEmbeddedFiles = ac - > addAction ( " embedded_files " ) ;
m_showEmbeddedFiles - > setText ( i18n ( " &Embedded Files " ) ) ;
connect ( m_showEmbeddedFiles , SIGNAL ( triggered ( ) ) , this , SLOT ( slotShowEmbeddedFiles ( ) ) ) ;
m_showEmbeddedFiles - > setEnabled ( false ) ;
m_showPresentation = ac - > addAction ( " presentation " ) ;
m_showPresentation - > setText ( i18n ( " P&resentation " ) ) ;
m_showPresentation - > setIcon ( KIcon ( " kpresenter_kpr " ) ) ;
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 = ac - > addAction ( " file_export_as " ) ;
m_exportAs - > setText ( i18n ( " E&xport As " ) ) ;
QMenu * menu = new QMenu ( widget ( ) ) ;
connect ( menu , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( slotExportAs ( QAction * ) ) ) ;
m_exportAs - > setMenu ( menu ) ;
2007-03-10 21:32:09 +00:00
m_exportAsText = actionForExportFormat ( Okular : : ExportFormat : : plainText ( ) , menu ) ;
menu - > addAction ( m_exportAsText ) ;
2007-01-13 00:33:50 +00:00
m_exportAsText - > setEnabled ( false ) ;
2007-03-07 18:15:00 +00:00
m_aboutBackend = ac - > addAction ( " help_about_backend " ) ;
m_aboutBackend - > setText ( i18n ( " About backend... " ) ) ;
connect ( m_aboutBackend , SIGNAL ( triggered ( ) ) , this , SLOT ( slotAboutBackend ( ) ) ) ;
2007-01-13 00:33:50 +00:00
// attach the actions of the children widgets too
m_pageView - > setupActions ( ac ) ;
2007-02-25 00:07:59 +00:00
m_formsMessage - > setActionButton ( m_pageView - > toggleFormsAction ( ) ) ;
2007-01-13 00:33:50 +00:00
// apply configuration (both internal settings and GUI configured items)
QList < int > splitterSizes = Okular : : Settings : : 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
connect ( m_splitter , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( splitterMoved ( int , int ) ) ) ;
// 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 ( " DBUS/Text-to-Speech " , " Name == 'KTTSD' " ) ;
Okular : : Settings : : setUseKTTSD ( ! offers . isEmpty ( ) ) ;
Okular : : Settings : : writeConfig ( ) ;
2007-01-13 17:28:54 +00:00
rebuildBookmarkMenu ( false ) ;
2007-01-13 00:33:50 +00:00
// set our XML-UI resource file
setXMLFile ( " part.rc " ) ;
//
updateViewActions ( ) ;
2003-09-15 21:57:19 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-08 12:41:14 +00:00
Part : : ~ Part ( )
2003-09-15 21:09:49 +00:00
{
2006-02-18 12:06:52 +00:00
delete m_toc ;
delete m_pageView ;
delete m_thumbnailList ;
delete m_miniBar ;
2006-10-15 15:59:22 +00:00
delete m_progressWidget ;
2006-10-15 19:37:14 +00:00
delete m_pageSizeLabel ;
2006-02-18 12:06:52 +00:00
2004-11-09 17:20:19 +00:00
delete m_document ;
2007-01-13 21:42:39 +00:00
delete m_tempfile ;
2007-01-13 17:28:54 +00:00
qDeleteAll ( m_bookmarkActions ) ;
2003-09-15 21:09:49 +00:00
}
2007-01-13 00:33:50 +00:00
2007-01-04 00:20:50 +00:00
bool Part : : openDocument ( const KUrl & url , uint page )
{
Okular : : DocumentViewport vp ( page - 1 ) ;
if ( vp . isValid ( ) )
m_document - > setNextDocumentViewport ( vp ) ;
return openUrl ( url ) ;
}
2007-01-13 00:33:50 +00:00
2007-01-04 00:20:50 +00:00
void Part : : startPresentation ( )
{
m_cliPresentation = true ;
}
2007-01-13 00:33:50 +00:00
2006-08-30 13:02:48 +00:00
void Part : : openUrlFromDocument ( const KUrl & url )
2005-11-04 11:59:51 +00:00
{
2006-08-29 21:09:55 +00:00
m_bExtension - > openUrlNotify ( ) ;
m_bExtension - > setLocationBarUrl ( url . prettyUrl ( ) ) ;
openUrl ( url ) ;
2005-11-04 11:59:51 +00:00
}
2007-01-13 17:28:54 +00:00
void Part : : openUrlFromBookmarks ( const KUrl & _url )
{
KUrl url = _url ;
Okular : : DocumentViewport vp ( _url . htmlRef ( ) ) ;
if ( vp . isValid ( ) )
m_document - > setNextDocumentViewport ( vp ) ;
url . setHTMLRef ( QString ( ) ) ;
if ( m_document - > currentDocument ( ) = = url )
{
if ( vp . isValid ( ) )
m_document - > setViewport ( vp ) ;
}
else
openUrl ( url ) ;
}
2005-11-04 11:59:51 +00:00
void Part : : setMimeTypes ( KIO : : Job * job )
{
if ( job )
{
2007-01-28 15:46:10 +00:00
QStringList supportedMimeTypes = m_document - > supportedMimeTypes ( ) ;
job - > addMetaData ( " accept " , supportedMimeTypes . join ( " , " ) + " , */*;q=0.5 " ) ;
2007-01-26 18:54:41 +00:00
connect ( job , SIGNAL ( mimetype ( KIO : : Job * , const QString & ) ) , this , SLOT ( readMimeType ( KIO : : Job * , const QString & ) ) ) ;
2005-11-04 11:59:51 +00:00
}
}
2007-01-26 18:54:41 +00:00
void Part : : readMimeType ( KIO : : Job * , const QString & mime )
{
m_jobMime = mime ;
}
2007-01-13 00:33:50 +00:00
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
void Part : : slotGeneratorPreferences ( )
{
// an instance the dialog could be already created and could be cached,
// in which case you want to display the cached dialog
if ( KConfigDialog : : showDialog ( " generator_prefs " ) )
return ;
// we didn't find an instance of this dialog, so lets create it
2006-09-21 08:45:36 +00:00
KConfigDialog * dialog = new KConfigDialog ( m_pageView , " generator_prefs " , Okular : : Settings : : self ( ) ) ;
2006-06-17 11:11:48 +00:00
dialog - > setCaption ( i18n ( " Configure Backends " ) ) ;
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
2007-01-28 15:46:10 +00:00
m_document - > fillConfigDialog ( dialog ) ;
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
2006-10-21 22:07:05 +00:00
// (for now don't FIXME) keep us informed when the user changes settings
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
// connect( dialog, SIGNAL( settingsChanged() ), this, SLOT( slotNewConfig() ) );
dialog - > show ( ) ;
}
2007-01-13 00:33:50 +00:00
2007-01-13 17:28:54 +00:00
void Part : : notifySetup ( const QVector < Okular : : Page * > & /*pages*/ , bool documentChanged )
{
if ( ! documentChanged )
return ;
rebuildBookmarkMenu ( ) ;
2007-03-07 18:15:00 +00:00
updateAboutBackendAction ( ) ;
2007-01-13 17:28:54 +00:00
}
2005-02-01 18:23:55 +00:00
void Part : : notifyViewportChanged ( bool /*smoothMove*/ )
2004-11-09 17:20:19 +00:00
{
2005-01-09 23:37:07 +00:00
// update actions if the page is changed
static int lastPage = - 1 ;
int viewportPage = m_document - > viewport ( ) . pageNumber ;
if ( viewportPage ! = lastPage )
{
2005-02-02 18:18:26 +00:00
updateViewActions ( ) ;
2005-01-09 23:37:07 +00:00
lastPage = viewportPage ;
}
2004-11-09 17:20:19 +00:00
}
2007-01-13 17:28:54 +00:00
void Part : : notifyPageChanged ( int /*page*/ , int flags )
{
if ( ! ( flags & Okular : : DocumentObserver : : Bookmark ) )
return ;
rebuildBookmarkMenu ( ) ;
}
2007-01-13 00:33:50 +00:00
2004-10-12 11:08:09 +00:00
void Part : : goToPage ( uint i )
{
2004-11-09 17:20:19 +00:00
if ( i < = m_document - > pages ( ) )
2005-01-09 23:37:07 +00:00
m_document - > setViewportPage ( i - 1 ) ;
2004-10-12 11:08:09 +00:00
}
2007-01-13 00:33:50 +00:00
2006-03-24 21:31:46 +00:00
void Part : : openDocument ( KUrl doc )
2004-10-12 11:08:09 +00:00
{
2006-08-30 13:02:48 +00:00
openUrl ( doc ) ;
2004-10-12 11:08:09 +00:00
}
2007-01-13 00:33:50 +00:00
2004-10-12 11:08:09 +00:00
uint Part : : pages ( )
{
2005-06-13 17:39:58 +00:00
return m_document - > pages ( ) ;
}
2007-01-13 00:33:50 +00:00
2005-06-13 17:39:58 +00:00
uint Part : : currentPage ( )
{
return m_document - > pages ( ) ? m_document - > currentPage ( ) + 1 : 0 ;
}
2007-01-13 00:33:50 +00:00
2006-03-24 21:31:46 +00:00
KUrl Part : : currentDocument ( )
2005-06-13 17:39:58 +00:00
{
return m_document - > currentDocument ( ) ;
2004-10-12 11:08:09 +00:00
}
2007-01-13 00:33:50 +00:00
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
{
2007-01-13 00:33:50 +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)
2007-03-10 23:45:12 +00:00
KAboutData * aboutData = okularAboutData ( " okularpart " , I18N_NOOP ( " okularpart " ) ) ;
2007-01-13 00:33:50 +00:00
aboutData - > addAuthor ( " Wilco Greven " , 0 , " greven@kde.org " ) ;
return aboutData ;
2003-09-15 14:26:37 +00:00
}
2007-01-13 00:33:50 +00:00
2005-07-15 18:20:57 +00:00
bool Part : : slotImportPSFile ( )
{
2007-01-13 00:33:50 +00:00
QString app = KStandardDirs : : findExe ( " ps2pdf " ) ;
if ( app . isEmpty ( ) )
{
// TODO point the user to their distro packages?
KMessageBox : : error ( widget ( ) , i18n ( " The program \" ps2pdf \" was not found, so okular can not import PS files using it. " ) , i18n ( " ps2pdf not found " ) ) ;
return false ;
}
2006-04-13 11:57:16 +00:00
2006-07-04 23:09:39 +00:00
KUrl url = KFileDialog : : getOpenUrl ( KUrl ( ) , " application/postscript " , this - > widget ( ) ) ;
2006-10-16 17:57:44 +00:00
if ( url . isLocalFile ( ) )
2005-07-15 18:20:57 +00:00
{
2006-10-16 17:57:44 +00:00
KTemporaryFile tf ;
tf . setSuffix ( " .pdf " ) ;
tf . setAutoRemove ( false ) ;
if ( ! tf . open ( ) )
return false ;
m_temporaryLocalFile = tf . fileName ( ) ;
2005-07-15 18:20:57 +00:00
tf . close ( ) ;
2006-10-16 17:57:44 +00:00
2007-03-13 20:01:56 +00:00
setLocalFilePath ( url . path ( ) ) ;
2005-07-15 18:20:57 +00:00
KProcess * p = new KProcess ;
* p < < app ;
2007-03-13 20:01:56 +00:00
* p < < localFilePath ( ) < < m_temporaryLocalFile ;
2005-07-15 18:20:57 +00:00
m_pageView - > displayMessage ( i18n ( " Importing PS file as PDF (this may take a while)... " ) ) ;
connect ( p , SIGNAL ( processExited ( KProcess * ) ) , this , SLOT ( psTransformEnded ( ) ) ) ;
p - > start ( ) ;
return true ;
}
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
2006-11-18 21:36:56 +00:00
m_temporaryLocalFile . clear ( ) ;
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
return false ;
2005-07-15 18:20:57 +00:00
}
2005-11-04 11:59:51 +00:00
2007-01-13 00:33:50 +00:00
2004-09-09 13:25:40 +00:00
bool Part : : openFile ( )
2003-09-15 09:35:55 +00:00
{
2005-11-04 11:59:51 +00:00
KMimeType : : Ptr mime ;
if ( m_bExtension - > urlArgs ( ) . serviceType . isEmpty ( ) )
{
2007-01-26 18:54:41 +00:00
if ( ! m_jobMime . isEmpty ( ) )
{
mime = KMimeType : : mimeType ( m_jobMime ) ;
if ( ! mime )
{
2007-03-13 20:01:56 +00:00
mime = KMimeType : : findByPath ( localFilePath ( ) ) ;
2007-01-26 18:54:41 +00:00
}
}
else
{
2007-03-13 20:01:56 +00:00
mime = KMimeType : : findByPath ( localFilePath ( ) ) ;
2007-01-26 18:54:41 +00:00
}
2005-11-04 11:59:51 +00:00
}
else
{
mime = KMimeType : : mimeType ( m_bExtension - > urlArgs ( ) . serviceType ) ;
}
2007-03-13 20:01:56 +00:00
bool ok = m_document - > openDocument ( localFilePath ( ) , url ( ) , mime ) ;
2005-06-24 16:45:25 +00:00
bool canSearch = m_document - > supportsSearching ( ) ;
2005-01-27 17:31:07 +00:00
// update one-time actions
2005-06-24 16:45:25 +00:00
m_find - > setEnabled ( ok & & canSearch ) ;
m_findNext - > setEnabled ( ok & & canSearch ) ;
2005-01-27 17:31:07 +00:00
m_saveAs - > setEnabled ( ok ) ;
m_printPreview - > setEnabled ( ok ) ;
2005-02-02 18:18:26 +00:00
m_showProperties - > setEnabled ( ok ) ;
2006-10-03 10:11:16 +00:00
bool hasEmbeddedFiles = ok & & m_document - > embeddedFiles ( ) & & m_document - > embeddedFiles ( ) - > count ( ) > 0 ;
m_showEmbeddedFiles - > setEnabled ( hasEmbeddedFiles ) ;
2007-02-23 10:54:30 +00:00
m_topMessage - > setVisible ( hasEmbeddedFiles ) ;
2007-02-25 00:07:59 +00:00
m_formsMessage - > setVisible ( ok & & m_pageView - > toggleFormsAction ( ) - > isEnabled ( ) ) ;
2005-02-02 18:18:26 +00:00
m_showPresentation - > setEnabled ( ok ) ;
2006-07-01 22:17:53 +00:00
if ( ok )
{
2006-10-25 15:35:53 +00:00
m_exportFormats = m_document - > exportFormats ( ) ;
QList < Okular : : ExportFormat > : : ConstIterator it = m_exportFormats . constBegin ( ) ;
QList < Okular : : ExportFormat > : : ConstIterator itEnd = m_exportFormats . constEnd ( ) ;
2006-07-01 22:17:53 +00:00
QMenu * menu = m_exportAs - > menu ( ) ;
for ( ; it ! = itEnd ; + + it )
{
2007-03-10 21:32:09 +00:00
menu - > addAction ( actionForExportFormat ( * it ) ) ;
2006-07-01 22:17:53 +00:00
}
}
m_exportAsText - > setEnabled ( ok & & m_document - > canExportToText ( ) ) ;
2005-01-27 17:31:07 +00:00
// update viewing actions
2005-02-02 18:18:26 +00:00
updateViewActions ( ) ;
2005-01-01 15:44:44 +00:00
2005-01-27 17:31:07 +00:00
if ( ! ok )
{
// if can't open document, update windows so they display blank contents
2006-10-07 14:40:32 +00:00
m_pageView - > widget ( ) - > update ( ) ;
2006-05-05 21:12:04 +00:00
m_thumbnailList - > update ( ) ;
2005-01-27 17:31:07 +00:00
return false ;
}
// set the file to the fileWatcher
2007-03-13 20:01:56 +00:00
if ( ! m_watcher - > contains ( localFilePath ( ) ) )
m_watcher - > addFile ( localFilePath ( ) ) ;
2005-01-27 17:31:07 +00:00
2006-10-28 18:21:55 +00:00
// if the 'OpenTOC' flag is set, start presentation
2007-01-02 22:37:55 +00:00
if ( m_document - > metaData ( " OpenTOC " ) . toBool ( ) & & m_toolBox - > isItemEnabled ( 0 ) )
2006-10-28 18:21:55 +00:00
{
m_toolBox - > setCurrentIndex ( 0 ) ;
}
2007-01-04 00:20:50 +00:00
// if the 'StartFullScreen' flag is set, or the command line flag was
// specified, start presentation
if ( m_document - > metaData ( " StartFullScreen " ) . toBool ( ) | | m_cliPresentation )
2005-06-13 16:55:57 +00:00
{
2007-01-04 00:20:50 +00:00
if ( ! m_cliPresentation )
KMessageBox : : information ( m_presentationWidget , i18n ( " The document is going to be launched on presentation mode because the file requested it. " ) , QString : : null , " autoPresentationWarning " ) ;
m_cliPresentation = false ;
QMetaObject : : invokeMethod ( this , " slotShowPresentation " , Qt : : QueuedConnection ) ;
2005-06-13 16:55:57 +00:00
}
2007-01-13 00:33:50 +00:00
/* if (m_document->getXMLFile() != QString::null)
setXMLFile ( m_document - > getXMLFile ( ) , true ) ; */
2007-01-02 16:40:22 +00:00
m_document - > setupGui ( actionCollection ( ) , m_toolBox ) ;
2005-01-27 17:31:07 +00:00
return true ;
2003-09-15 09:35:55 +00:00
}
2007-01-13 00:33:50 +00:00
2006-08-30 13:02:48 +00:00
bool Part : : openUrl ( const KUrl & url )
2004-09-18 16:41:23 +00:00
{
2005-02-01 18:23:55 +00:00
// note: this can be the right place to check the file for gz or bz2 extension
// if it matches then: download it (if not local) extract to a temp file using
// KTar and proceed with the URL of the temporary file
2007-01-26 18:54:41 +00:00
m_jobMime . clear ( ) ;
2007-01-13 00:33:50 +00:00
const QString path = url . path ( ) ;
const KMimeType : : Ptr mimetype = KMimeType : : findByPath ( path ) ;
bool isCompressedFile = false ;
KUrl tempUrl ;
if ( ( mimetype - > name ( ) = = " application/x-gzip " )
| | ( mimetype - > name ( ) = = " application/x-bzip2 " )
| | ( mimetype - > parentMimeType ( ) = = " application/x-gzip " )
| | ( mimetype - > parentMimeType ( ) = = " application/x-bzip2 " )
)
{
isCompressedFile = handleCompressed ( tempUrl , path , mimetype ) ;
}
2007-01-12 23:54:26 +00:00
2006-08-30 13:02:48 +00:00
// this calls in sequence the 'closeUrl' and 'openFile' methods
2007-01-12 23:54:26 +00:00
bool openOk ;
if ( ! isCompressedFile )
2007-01-13 00:33:50 +00:00
openOk = KParts : : ReadOnlyPart : : openUrl ( url ) ;
2007-01-12 23:54:26 +00:00
else openOk = KParts : : ReadOnlyPart : : openUrl ( tempUrl ) ;
2005-07-15 18:20:57 +00:00
2005-06-24 16:39:57 +00:00
if ( openOk )
2006-07-30 23:37:50 +00:00
{
2006-10-15 12:26:16 +00:00
m_viewportDirty . pageNumber = - 1 ;
2006-07-30 23:37:50 +00:00
// if the document have a 'DocumentTitle' flag set (and it is not empty), set it as title
2007-01-02 22:37:55 +00:00
QString title = m_document - > metaData ( " DocumentTitle " ) . toString ( ) ;
2006-07-30 23:37:50 +00:00
if ( ! title . isEmpty ( ) & & ! title . trimmed ( ) . isEmpty ( ) )
{
emit setWindowCaption ( title ) ;
}
2006-10-21 23:21:11 +00:00
else
{
emit setWindowCaption ( url . fileName ( ) ) ;
}
2006-07-30 23:37:50 +00:00
}
2007-01-26 18:35:28 +00:00
2006-04-28 18:08:04 +00:00
emit enablePrintAction ( openOk ) ;
2005-06-24 16:39:57 +00:00
return openOk ;
2004-09-18 16:41:23 +00:00
}
2007-01-13 00:33:50 +00:00
2006-08-30 13:02:48 +00:00
bool Part : : closeUrl ( )
2005-02-02 18:18:26 +00:00
{
2005-07-15 18:20:57 +00:00
if ( ! m_temporaryLocalFile . isNull ( ) )
{
QFile : : remove ( m_temporaryLocalFile ) ;
2006-11-18 21:36:56 +00:00
m_temporaryLocalFile . clear ( ) ;
2005-07-15 18:20:57 +00:00
}
2005-11-04 11:59:51 +00:00
slotHidePresentation ( ) ;
2005-02-02 18:18:26 +00:00
m_find - > setEnabled ( false ) ;
m_findNext - > setEnabled ( false ) ;
m_saveAs - > setEnabled ( false ) ;
m_printPreview - > setEnabled ( false ) ;
m_showProperties - > setEnabled ( false ) ;
2006-05-28 16:54:54 +00:00
m_showEmbeddedFiles - > setEnabled ( false ) ;
2006-07-01 22:17:53 +00:00
m_exportAsText - > setEnabled ( false ) ;
2006-10-25 15:35:53 +00:00
m_exportFormats . clear ( ) ;
2006-07-01 22:17:53 +00:00
QMenu * menu = m_exportAs - > menu ( ) ;
QList < QAction * > acts = menu - > actions ( ) ;
int num = acts . count ( ) ;
for ( int i = 1 ; i < num ; + + i )
{
menu - > removeAction ( acts . at ( i ) ) ;
delete acts . at ( i ) ;
}
2005-02-02 18:18:26 +00:00
m_showPresentation - > setEnabled ( false ) ;
2005-11-04 11:59:51 +00:00
emit setWindowCaption ( " " ) ;
emit enablePrintAction ( false ) ;
2005-02-02 18:18:26 +00:00
m_searchStarted = false ;
2007-03-13 20:01:56 +00:00
if ( ! localFilePath ( ) . isEmpty ( ) ) m_watcher - > removeFile ( localFilePath ( ) ) ;
2005-02-02 18:18:26 +00:00
m_document - > closeDocument ( ) ;
2005-11-04 11:59:51 +00:00
updateViewActions ( ) ;
2006-03-31 23:08:20 +00:00
m_searchWidget - > clearText ( ) ;
2006-08-29 21:09:55 +00:00
return KParts : : ReadOnlyPart : : closeUrl ( ) ;
2005-02-02 18:18:26 +00:00
}
2007-01-13 00:33:50 +00:00
2005-11-04 11:59:51 +00:00
void Part : : close ( )
{
2007-01-13 00:33:50 +00:00
if ( parent ( ) & & ( parent ( ) - > objectName ( ) = = QLatin1String ( " okular::Shell " ) ) )
{
closeUrl ( ) ;
}
else KMessageBox : : information ( widget ( ) , i18n ( " This link points to a close document action that does not work when using the embedded viewer. " ) , QString : : null , " warnNoCloseIfNotInOkular " ) ;
2005-11-04 11:59:51 +00:00
}
2007-01-13 00:33:50 +00:00
2005-11-04 11:59:51 +00:00
void Part : : cannotQuit ( )
{
2006-10-28 19:30:00 +00:00
KMessageBox : : information ( widget ( ) , i18n ( " This link points to a quit application action that does not work when using the embedded viewer. " ) , QString : : null , " warnNoQuitIfNotInOkular " ) ;
2005-11-04 11:59:51 +00:00
}
2007-01-13 00:33:50 +00:00
2006-10-13 19:30:39 +00:00
void Part : : splitterMoved ( int /*pos*/ , int index )
2005-04-07 12:47:24 +00:00
{
// if pageView has been resized, save splitter sizes
2006-10-13 19:30:39 +00:00
if ( index = = 1 )
2005-11-04 11:59:51 +00:00
saveSplitterSize ( ) ;
2005-04-07 12:47:24 +00:00
}
2007-01-13 00:33:50 +00:00
2005-03-12 15:39:04 +00:00
void Part : : slotShowLeftPanel ( )
2004-12-01 22:18:27 +00:00
{
2005-03-12 15:39:04 +00:00
bool showLeft = m_showLeftPanel - > isChecked ( ) ;
2006-09-21 08:45:36 +00:00
Okular : : Settings : : setShowLeftPanel ( showLeft ) ;
Okular : : Settings : : writeConfig ( ) ;
2005-03-13 13:14:44 +00:00
// show/hide left panel
2006-03-29 16:46:09 +00:00
m_leftPanel - > setVisible ( showLeft ) ;
2005-03-12 15:39:04 +00:00
// this needs to be hidden explicitly to disable thumbnails gen
2006-03-29 16:46:09 +00:00
m_thumbnailList - > setVisible ( showLeft ) ;
2004-12-01 22:18:27 +00:00
}
2007-01-13 00:33:50 +00:00
2005-11-04 11:59:51 +00:00
void Part : : saveSplitterSize ( )
{
2006-09-21 08:45:36 +00:00
Okular : : Settings : : setSplitterSizes ( m_splitter - > sizes ( ) ) ;
Okular : : Settings : : writeConfig ( ) ;
2005-11-04 11:59:51 +00:00
}
2007-01-13 00:33:50 +00:00
2005-01-27 17:31:07 +00:00
void Part : : slotFileDirty ( const QString & fileName )
2004-12-01 22:18:27 +00:00
{
2007-01-13 00:33:50 +00:00
// The beauty of this is that each start cancels the previous one.
// This means that timeout() is only fired when there have
// no changes to the file for the last 750 milisecs.
// This ensures that we don't update on every other byte that gets
// written to the file.
2007-03-13 20:01:56 +00:00
if ( fileName = = localFilePath ( ) )
2007-01-13 00:33:50 +00:00
{
m_dirtyHandler - > start ( 750 ) ;
}
2004-12-01 22:18:27 +00:00
}
2007-01-13 00:33:50 +00:00
2005-01-27 17:31:07 +00:00
void Part : : slotDoFileDirty ( )
2004-12-01 22:18:27 +00:00
{
2005-06-24 16:39:57 +00:00
// do the following the first time the file is reloaded
2005-07-15 18:20:57 +00:00
if ( m_viewportDirty . pageNumber = = - 1 )
2005-06-24 16:39:57 +00:00
{
// store the current viewport
2006-10-15 12:26:16 +00:00
m_viewportDirty = m_document - > viewport ( ) ;
// store if presentation view was open
m_wasPresentationOpen = ( ( PresentationWidget * ) m_presentationWidget ! = 0 ) ;
2005-06-24 16:39:57 +00:00
// inform the user about the operation in progress
m_pageView - > displayMessage ( i18n ( " Reloading the document... " ) ) ;
}
// close and (try to) reopen the document
2007-03-13 20:01:56 +00:00
if ( KParts : : ReadOnlyPart : : openUrl ( url ( ) ) )
2005-06-24 16:39:57 +00:00
{
2006-12-28 16:58:56 +00:00
// on successful opening, restore the previous viewport
2007-01-13 00:33:50 +00:00
if ( m_viewportDirty . pageNumber > = ( int ) m_document - > pages ( ) )
2005-07-15 18:20:57 +00:00
m_viewportDirty . pageNumber = ( int ) m_document - > pages ( ) - 1 ;
m_document - > setViewport ( m_viewportDirty ) ;
m_viewportDirty . pageNumber = - 1 ;
2006-10-15 12:26:16 +00:00
if ( m_wasPresentationOpen ) slotShowPresentation ( ) ;
2005-11-04 11:59:51 +00:00
emit enablePrintAction ( true ) ;
2005-06-24 16:39:57 +00:00
}
else
{
// start watching the file again (since we dropped it on close)
2007-03-13 20:01:56 +00:00
m_watcher - > addFile ( localFilePath ( ) ) ;
2006-05-13 11:33:36 +00:00
m_dirtyHandler - > start ( 750 ) ;
2005-06-24 16:39:57 +00:00
}
2004-12-01 22:18:27 +00:00
}
2007-01-13 00:33:50 +00:00
2005-02-02 18:18:26 +00:00
void Part : : updateViewActions ( )
2003-09-14 21:49:26 +00:00
{
2005-02-02 18:18:26 +00:00
bool opened = m_document - > pages ( ) > 0 ;
if ( opened )
2004-11-09 17:20:19 +00:00
{
bool atBegin = m_document - > currentPage ( ) < 1 ;
bool atEnd = m_document - > currentPage ( ) > = ( m_document - > pages ( ) - 1 ) ;
m_gotoPage - > setEnabled ( m_document - > pages ( ) > 1 ) ;
m_firstPage - > setEnabled ( ! atBegin ) ;
m_prevPage - > setEnabled ( ! atBegin ) ;
m_lastPage - > setEnabled ( ! atEnd ) ;
m_nextPage - > setEnabled ( ! atEnd ) ;
2005-01-27 17:31:07 +00:00
m_historyBack - > setEnabled ( ! m_document - > historyAtBegin ( ) ) ;
m_historyNext - > setEnabled ( ! m_document - > historyAtEnd ( ) ) ;
2004-11-09 17:20:19 +00:00
}
else
{
m_gotoPage - > setEnabled ( false ) ;
m_firstPage - > setEnabled ( false ) ;
m_lastPage - > setEnabled ( false ) ;
m_prevPage - > setEnabled ( false ) ;
m_nextPage - > setEnabled ( false ) ;
2005-01-27 17:31:07 +00:00
m_historyBack - > setEnabled ( false ) ;
m_historyNext - > setEnabled ( false ) ;
2004-11-09 17:20:19 +00:00
}
2003-09-14 21:49:26 +00:00
}
2003-09-14 20:46:38 +00:00
2007-01-13 00:33:50 +00:00
2004-09-23 21:49:00 +00:00
void Part : : enableTOC ( bool enable )
{
2007-01-13 00:33:50 +00:00
m_toolBox - > setItemEnabled ( 0 , enable ) ;
2004-09-23 21:49:00 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-18 16:41:23 +00:00
//BEGIN go to page dialog
2006-09-21 08:45:36 +00:00
class GotoPageDialog : public KDialog
2003-09-14 20:46:38 +00:00
{
2007-01-13 00:33:50 +00:00
public :
GotoPageDialog ( QWidget * p , int current , int max ) : KDialog ( p )
{
setCaption ( i18n ( " Go to Page " ) ) ;
setButtons ( Ok | Cancel ) ;
setDefaultButton ( Ok ) ;
QWidget * w = new QWidget ( this ) ;
setMainWidget ( w ) ;
QVBoxLayout * topLayout = new QVBoxLayout ( w ) ;
topLayout - > setMargin ( 0 ) ;
topLayout - > setSpacing ( spacingHint ( ) ) ;
e1 = new KIntNumInput ( current , w ) ;
e1 - > setRange ( 1 , max ) ;
e1 - > setEditFocus ( true ) ;
QLabel * label = new QLabel ( i18n ( " &Page: " ) , w ) ;
label - > setBuddy ( e1 ) ;
topLayout - > addWidget ( label ) ;
topLayout - > addWidget ( e1 ) ;
// A little bit extra space
topLayout - > addSpacing ( spacingHint ( ) ) ;
topLayout - > addStretch ( 10 ) ;
e1 - > setFocus ( ) ;
}
int getPage ( ) const
{
return e1 - > value ( ) ;
}
protected :
KIntNumInput * e1 ;
2004-09-09 13:25:40 +00:00
} ;
2004-09-18 16:41:23 +00:00
//END go to page dialog
2004-09-09 13:25:40 +00:00
void Part : : slotGoToPage ( )
{
2006-09-21 08:45:36 +00:00
GotoPageDialog pageDialog ( m_pageView , m_document - > currentPage ( ) + 1 , m_document - > pages ( ) ) ;
2004-11-09 17:20:19 +00:00
if ( pageDialog . exec ( ) = = QDialog : : Accepted )
2005-01-09 23:37:07 +00:00
m_document - > setViewportPage ( pageDialog . getPage ( ) - 1 ) ;
2002-08-30 09:14:01 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-09 13:25:40 +00:00
void Part : : slotPreviousPage ( )
2003-09-14 20:23:01 +00:00
{
2006-05-14 16:28:53 +00:00
if ( m_document - > isOpened ( ) & & ! ( m_document - > currentPage ( ) < 1 ) )
2005-01-09 23:37:07 +00:00
m_document - > setViewportPage ( m_document - > currentPage ( ) - 1 ) ;
2003-09-14 20:23:01 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-09 13:25:40 +00:00
void Part : : slotNextPage ( )
2003-09-14 20:23:01 +00:00
{
2005-11-04 11:59:51 +00:00
if ( m_document - > isOpened ( ) & & m_document - > currentPage ( ) < ( m_document - > pages ( ) - 1 ) )
2005-01-09 23:37:07 +00:00
m_document - > setViewportPage ( m_document - > currentPage ( ) + 1 ) ;
2004-09-09 13:25:40 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-11 15:59:32 +00:00
void Part : : slotGotoFirst ( )
2004-09-09 13:25:40 +00:00
{
2005-11-04 11:59:51 +00:00
if ( m_document - > isOpened ( ) )
m_document - > setViewportPage ( 0 ) ;
2003-09-14 20:23:01 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-11 15:59:32 +00:00
void Part : : slotGotoLast ( )
2003-09-14 14:54:16 +00:00
{
2005-11-04 11:59:51 +00:00
if ( m_document - > isOpened ( ) )
m_document - > setViewportPage ( m_document - > pages ( ) - 1 ) ;
2003-09-14 14:54:16 +00:00
}
2007-01-13 00:33:50 +00:00
2005-01-27 17:31:07 +00:00
void Part : : slotHistoryBack ( )
{
m_document - > setPrevViewport ( ) ;
}
2007-01-13 00:33:50 +00:00
2005-01-27 17:31:07 +00:00
void Part : : slotHistoryNext ( )
{
m_document - > setNextViewport ( ) ;
}
2007-01-13 00:33:50 +00:00
2006-06-24 10:56:06 +00:00
void Part : : slotPreviousBookmark ( )
{
uint current = m_document - > currentPage ( ) ;
// we are at the first page
if ( current = = 0 )
return ;
for ( int i = current - 1 ; i > = 0 ; - - i )
{
2006-12-27 16:04:49 +00:00
if ( m_document - > isBookmarked ( i ) )
2006-06-24 10:56:06 +00:00
{
m_document - > setViewportPage ( i ) ;
break ;
}
}
}
2007-01-13 00:33:50 +00:00
2006-06-24 10:56:06 +00:00
void Part : : slotNextBookmark ( )
{
uint current = m_document - > currentPage ( ) ;
uint pages = m_document - > pages ( ) ;
// we are at the last page
if ( current = = pages )
return ;
for ( uint i = current + 1 ; i < pages ; + + i )
{
2006-12-27 16:04:49 +00:00
if ( m_document - > isBookmarked ( i ) )
2006-06-24 10:56:06 +00:00
{
m_document - > setViewportPage ( i ) ;
break ;
}
}
}
2007-01-13 00:33:50 +00:00
2004-09-09 13:25:40 +00:00
void Part : : slotFind ( )
2003-09-14 14:54:16 +00:00
{
2004-11-09 17:20:19 +00:00
KFindDialog dlg ( widget ( ) ) ;
dlg . setHasCursor ( false ) ;
2006-07-11 19:57:17 +00:00
if ( ! m_searchHistory . empty ( ) )
dlg . setFindHistory ( m_searchHistory ) ;
2004-11-09 17:20:19 +00:00
dlg . setSupportsBackwardsFind ( false ) ;
dlg . setSupportsWholeWordsFind ( false ) ;
dlg . setSupportsRegularExpressionFind ( false ) ;
if ( dlg . exec ( ) = = QDialog : : Accepted )
{
2006-07-11 19:57:17 +00:00
m_searchHistory = dlg . findHistory ( ) ;
2005-02-02 18:18:26 +00:00
m_searchStarted = true ;
2005-02-03 17:09:33 +00:00
m_document - > resetSearch ( PART_SEARCH_ID ) ;
2006-11-23 16:54:28 +00:00
m_document - > searchText ( PART_SEARCH_ID , dlg . pattern ( ) , false ,
2007-01-13 00:33:50 +00:00
dlg . options ( ) & KFind : : CaseSensitive ? Qt : : CaseSensitive : Qt : : CaseInsensitive ,
Okular : : Document : : NextMatch , true , qRgb ( 255 , 255 , 64 ) ) ;
2004-11-09 17:20:19 +00:00
}
2003-09-14 21:53:40 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-09 13:25:40 +00:00
void Part : : slotFindNext ( )
2003-09-14 21:53:40 +00:00
{
2006-07-11 19:57:17 +00:00
if ( ! m_document - > continueLastSearch ( ) )
2005-02-02 18:18:26 +00:00
slotFind ( ) ;
2003-09-14 14:22:37 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-08 12:41:14 +00:00
void Part : : slotSaveFileAs ( )
2004-08-28 17:59:17 +00:00
{
2006-08-30 13:02:48 +00:00
KUrl saveUrl = KFileDialog : : getSaveUrl ( url ( ) . isLocalFile ( ) ? url ( ) . url ( ) : url ( ) . fileName ( ) , QString : : null , widget ( ) ) ;
if ( saveUrl . isValid ( ) & & ! saveUrl . isEmpty ( ) )
2004-11-05 01:52:48 +00:00
{
2006-08-30 13:02:48 +00:00
if ( KIO : : NetAccess : : exists ( saveUrl , false , widget ( ) ) )
2005-06-13 16:08:31 +00:00
{
2006-09-15 11:57:39 +00:00
if ( KMessageBox : : warningContinueCancel ( widget ( ) , i18n ( " A file named \" %1 \" already exists. Are you sure you want to overwrite it? " , saveUrl . fileName ( ) ) , QString : : null , KGuiItem ( i18n ( " Overwrite " ) ) ) ! = KMessageBox : : Continue )
2005-06-13 16:08:31 +00:00
return ;
}
2006-08-30 13:02:48 +00:00
if ( ! KIO : : NetAccess : : file_copy ( url ( ) , saveUrl , - 1 , true ) )
KMessageBox : : information ( widget ( ) , i18n ( " File could not be saved in '%1'. Try to save it to another location. " , saveUrl . prettyUrl ( ) ) ) ;
2004-11-05 01:52:48 +00:00
}
2004-04-15 18:36:43 +00:00
}
2007-01-13 00:33:50 +00:00
2005-04-16 00:25:26 +00:00
void Part : : slotGetNewStuff ( )
{
// show the modal dialog over pageview and execute it
NewStuffDialog * dialog = new NewStuffDialog ( m_pageView ) ;
2006-11-14 00:22:23 +00:00
connect ( dialog , SIGNAL ( loadItemClicked ( const KUrl & ) ) , this , SLOT ( openUrlFromDocument ( const KUrl & ) ) ) ;
2005-04-16 00:25:26 +00:00
dialog - > exec ( ) ;
delete dialog ;
}
2007-01-13 00:33:50 +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
2006-09-21 08:45:36 +00:00
PreferencesDialog * dialog = new PreferencesDialog ( m_pageView , Okular : : Settings : : self ( ) ) ;
2004-10-27 14:15:27 +00:00
// keep us informed when the user changes settings
2006-03-30 13:23:38 +00:00
connect ( dialog , SIGNAL ( settingsChanged ( const QString & ) ) , this , SLOT ( slotNewConfig ( ) ) ) ;
2004-10-27 14:15:27 +00:00
dialog - > show ( ) ;
}
2007-01-13 00:33:50 +00:00
2004-10-27 14:15:27 +00:00
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.
2005-03-12 15:39:04 +00:00
// Watch File
2006-09-21 08:45:36 +00:00
bool watchFile = Okular : : Settings : : watchFile ( ) ;
2005-03-12 15:39:04 +00:00
if ( watchFile & & m_watcher - > isStopped ( ) )
m_watcher - > startScan ( ) ;
if ( ! watchFile & & ! m_watcher - > isStopped ( ) )
2004-10-29 13:33:51 +00:00
{
2005-03-12 15:39:04 +00:00
m_dirtyHandler - > stop ( ) ;
m_watcher - > stopScan ( ) ;
2004-10-29 13:33:51 +00:00
}
2005-03-12 15:39:04 +00:00
2006-09-21 08:45:36 +00:00
bool showSearch = Okular : : Settings : : showSearchBar ( ) ;
2006-05-13 11:33:36 +00:00
if ( ! m_searchWidget - > isHidden ( ) ! = showSearch )
2006-04-03 20:48:26 +00:00
m_searchWidget - > setVisible ( showSearch ) ;
2004-10-29 13:33:51 +00:00
2004-11-05 18:14:20 +00:00
// Main View (pageView)
2006-10-28 22:58:05 +00:00
m_pageView - > reparseConfig ( ) ;
2004-11-06 01:48:52 +00:00
2004-11-09 17:20:19 +00:00
// update document settings
m_document - > reparseConfig ( ) ;
2006-12-22 20:42:36 +00:00
// update TOC settings
if ( m_toolBox - > isItemEnabled ( 0 ) )
m_toc - > reparseConfig ( ) ;
2006-10-28 22:58:05 +00:00
// update ThumbnailList contents
2006-09-21 08:45:36 +00:00
if ( Okular : : Settings : : showLeftPanel ( ) & & ! m_thumbnailList - > isHidden ( ) )
2004-11-07 11:20:27 +00:00
m_thumbnailList - > updateWidgets ( ) ;
2004-10-09 08:10:56 +00:00
}
2002-08-30 09:14:01 +00:00
2007-01-13 00:33:50 +00:00
2004-10-09 08:10:56 +00:00
void Part : : slotPrintPreview ( )
2002-09-02 21:56:00 +00:00
{
2004-11-09 17:20:19 +00:00
if ( m_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 ;
2006-09-21 08:45:36 +00:00
const Okular : : Page * page ;
2004-09-18 16:41:23 +00:00
2004-11-09 17:20:19 +00:00
printer . setMinMax ( 1 , m_document - > pages ( ) ) ;
2004-10-09 08:10:56 +00:00
printer . setPreviewOnly ( true ) ;
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-09 17:20:19 +00:00
for ( uint i = 0 ; i < m_document - > pages ( ) ; i + + )
2004-10-09 08:10:56 +00:00
{
2004-11-09 17:20:19 +00:00
page = m_document - > page ( i ) ;
2004-11-03 21:37:21 +00:00
width = page - > width ( ) ;
height = page - > height ( ) ;
2006-06-02 20:42:57 +00:00
if ( page - > orientation ( ) = = 90 | | page - > orientation ( ) = = 270 ) qSwap ( width , height ) ;
2004-11-03 21:37:21 +00:00
if ( width > height ) landscape + + ;
else portrait + + ;
}
2006-11-01 22:24:57 +00:00
if ( landscape > portrait )
{
2007-01-13 00:33:50 +00:00
// printer.setOption("orientation-requested", "4");
2006-11-01 22:24:57 +00:00
printer . setOrientation ( KPrinter : : Landscape ) ;
}
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
}
2007-01-13 00:33:50 +00:00
2006-09-21 08:45:36 +00:00
void Part : : slotShowMenu ( const Okular : : Page * page , const QPoint & point )
2004-12-04 23:23:18 +00:00
{
2007-01-13 00:33:50 +00:00
bool reallyShow = false ;
if ( ! m_actionsSearched )
{
// the quest for options_show_menubar
KActionCollection * ac ;
QAction * act ;
if ( factory ( ) )
{
QList < KXMLGUIClient * > clients ( factory ( ) - > clients ( ) ) ;
for ( int i = 0 ; ( ! m_showMenuBarAction | | ! m_showFullScreenAction ) & & i < clients . size ( ) ; + + i )
{
ac = clients . at ( i ) - > actionCollection ( ) ;
// show_menubar
act = ac - > action ( " options_show_menubar " ) ;
if ( act & & qobject_cast < KToggleAction * > ( act ) )
m_showMenuBarAction = qobject_cast < KToggleAction * > ( act ) ;
// fullscreen
act = ac - > action ( " fullscreen " ) ;
if ( act & & qobject_cast < KToggleFullScreenAction * > ( act ) )
m_showFullScreenAction = qobject_cast < KToggleFullScreenAction * > ( act ) ;
}
2006-03-24 22:57:41 +00:00
}
2007-01-13 00:33:50 +00:00
m_actionsSearched = true ;
}
KMenu * popup = new KMenu ( widget ( ) ) ;
2007-01-13 14:45:51 +00:00
QAction * addBookmark = 0 ;
QAction * removeBookmark = 0 ;
QAction * fitPageWidth = 0 ;
2007-01-13 00:33:50 +00:00
if ( page )
{
popup - > addTitle ( i18n ( " Page %1 " , page - > number ( ) + 1 ) ) ;
2007-01-13 14:45:51 +00:00
if ( m_document - > isBookmarked ( page - > number ( ) ) )
removeBookmark = popup - > addAction ( KIcon ( " bookmark " ) , i18n ( " Remove Bookmark " ) ) ;
else
2007-03-08 21:41:46 +00:00
addBookmark = popup - > addAction ( KIcon ( " bookmark-new " ) , i18n ( " Add Bookmark " ) ) ;
2007-01-13 00:33:50 +00:00
if ( m_pageView - > canFitPageWidth ( ) )
2007-03-08 21:41:46 +00:00
fitPageWidth = popup - > addAction ( KIcon ( " zoom-best-fit " ) , i18n ( " Fit Width " ) ) ;
2007-01-13 00:33:50 +00:00
//popup->insertItem( SmallIcon("pencil"), i18n("Edit"), 3 );
//popup->setItemEnabled( 3, false );
popup - > addAction ( m_prevBookmark ) ;
popup - > addAction ( m_nextBookmark ) ;
reallyShow = true ;
}
/*
//Albert says: I have not ported this as i don't see it does anything
if ( d - > mouseOnRect ) // and rect->objectType() == ObjectRect::Image ...
{
2007-03-08 21:41:46 +00:00
m_popup - > insertItem ( SmallIcon ( " document-save " ) , i18n ( " Save Image... " ) , 4 ) ;
2007-01-13 00:33:50 +00:00
m_popup - > setItemEnabled ( 4 , false ) ;
} */
if ( ( m_showMenuBarAction & & ! m_showMenuBarAction - > isChecked ( ) ) | | ( m_showFullScreenAction & & m_showFullScreenAction - > isChecked ( ) ) )
{
popup - > addTitle ( i18n ( " Tools " ) ) ;
if ( m_showMenuBarAction & & ! m_showMenuBarAction - > isChecked ( ) ) popup - > addAction ( m_showMenuBarAction ) ;
if ( m_showFullScreenAction & & m_showFullScreenAction - > isChecked ( ) ) popup - > addAction ( m_showFullScreenAction ) ;
reallyShow = true ;
}
if ( reallyShow )
{
QAction * res = popup - > exec ( point ) ;
if ( res )
{
2007-01-13 14:45:51 +00:00
if ( res = = addBookmark ) m_document - > addBookmark ( page - > number ( ) ) ;
else if ( res = = removeBookmark ) m_document - > removeBookmark ( page - > number ( ) ) ;
2007-01-13 00:33:50 +00:00
else if ( res = = fitPageWidth ) m_pageView - > fitPageWidth ( page - > number ( ) ) ;
}
}
delete popup ;
2004-12-04 23:23:18 +00:00
}
2007-01-13 00:33:50 +00:00
2004-12-05 22:47:32 +00:00
void Part : : slotShowProperties ( )
{
2007-01-13 00:33:50 +00:00
PropertiesDialog * d = new PropertiesDialog ( widget ( ) , m_document ) ;
d - > exec ( ) ;
delete d ;
2004-12-05 22:47:32 +00:00
}
2007-01-13 00:33:50 +00:00
2006-05-28 16:54:54 +00:00
void Part : : slotShowEmbeddedFiles ( )
{
2007-01-13 00:33:50 +00:00
EmbeddedFilesDialog * d = new EmbeddedFilesDialog ( widget ( ) , m_document ) ;
d - > exec ( ) ;
delete d ;
2006-05-28 16:54:54 +00:00
}
2007-01-13 00:33:50 +00:00
2004-12-17 17:14:46 +00:00
void Part : : slotShowPresentation ( )
{
2005-06-13 16:55:57 +00:00
if ( ! m_presentationWidget )
2006-06-25 16:34:11 +00:00
{
2005-06-13 16:55:57 +00:00
m_presentationWidget = new PresentationWidget ( widget ( ) , m_document ) ;
2006-06-25 16:34:11 +00:00
m_presentationWidget - > setupActions ( actionCollection ( ) ) ;
}
2004-12-17 17:14:46 +00:00
}
2007-01-13 00:33:50 +00:00
2005-04-07 09:53:15 +00:00
void Part : : slotHidePresentation ( )
{
if ( m_presentationWidget )
delete ( PresentationWidget * ) m_presentationWidget ;
}
2007-01-13 00:33:50 +00:00
2007-03-07 18:15:00 +00:00
void Part : : slotAboutBackend ( )
{
const KComponentData * data = m_document - > componentData ( ) ;
if ( ! data )
return ;
KAboutApplicationDialog dlg ( data - > aboutData ( ) , widget ( ) ) ;
dlg . exec ( ) ;
}
2006-07-01 22:17:53 +00:00
void Part : : slotExportAs ( QAction * act )
{
QList < QAction * > acts = m_exportAs - > menu ( ) ? m_exportAs - > menu ( ) - > actions ( ) : QList < QAction * > ( ) ;
int id = acts . indexOf ( act ) ;
if ( ( id < 0 ) | | ( id > = acts . count ( ) ) )
return ;
2006-10-25 15:35:53 +00:00
QString filter = id = = 0 ? " text/plain " : m_exportFormats . at ( id - 1 ) . mimeType ( ) - > name ( ) ;
2006-07-01 22:17:53 +00:00
QString fileName = KFileDialog : : getSaveFileName ( url ( ) . isLocalFile ( ) ? url ( ) . fileName ( ) : QString : : null , filter , widget ( ) ) ;
if ( ! fileName . isEmpty ( ) )
{
2006-10-25 15:35:53 +00:00
bool saved = id = = 0 ? m_document - > exportToText ( fileName ) : m_document - > exportTo ( fileName , m_exportFormats . at ( id - 1 ) ) ;
2006-07-01 22:17:53 +00:00
if ( ! saved )
KMessageBox : : information ( widget ( ) , i18n ( " File could not be saved in '%1'. Try to save it to another location. " , fileName ) ) ;
}
}
2007-01-13 00:33:50 +00:00
2004-10-09 08:10:56 +00:00
void Part : : slotPrint ( )
2004-01-02 17:46:06 +00:00
{
2004-11-09 17:20:19 +00:00
if ( m_document - > pages ( ) = = 0 ) return ;
2004-11-03 21:37:21 +00:00
double width , height ;
int landscape , portrait ;
KPrinter printer ;
2006-09-21 08:45:36 +00:00
const Okular : : Page * page ;
2004-11-03 21:37:21 +00:00
printer . setPageSelection ( KPrinter : : ApplicationSide ) ;
2004-11-09 17:20:19 +00:00
printer . setMinMax ( 1 , m_document - > pages ( ) ) ;
printer . setCurrentPage ( m_document - > currentPage ( ) + 1 ) ;
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
landscape = 0 ;
portrait = 0 ;
2004-11-09 17:20:19 +00:00
for ( uint i = 0 ; i < m_document - > pages ( ) ; i + + )
2004-11-03 21:37:21 +00:00
{
2004-11-09 17:20:19 +00:00
page = m_document - > page ( i ) ;
2004-11-03 21:37:21 +00:00
width = page - > width ( ) ;
height = page - > height ( ) ;
2006-06-02 20:42:57 +00:00
if ( page - > orientation ( ) = = 90 | | page - > orientation ( ) = = 270 ) qSwap ( width , height ) ;
2004-11-03 21:37:21 +00:00
if ( width > height ) landscape + + ;
else portrait + + ;
}
if ( landscape > portrait ) printer . setOrientation ( KPrinter : : Landscape ) ;
2006-11-09 21:39:17 +00:00
// range detecting
QString range ;
uint pages = m_document - > pages ( ) ;
int startId = - 1 ;
int endId = - 1 ;
for ( uint i = 0 ; i < pages ; + + i )
{
2006-12-27 16:04:49 +00:00
if ( m_document - > isBookmarked ( i ) )
2006-11-09 21:39:17 +00:00
{
if ( startId < 0 )
startId = i ;
if ( endId < 0 )
endId = startId ;
else
+ + endId ;
}
else if ( startId > = 0 & & endId > = 0 )
{
if ( ! range . isEmpty ( ) )
range + = ' , ' ;
if ( endId - startId > 0 )
range + = QString ( " %1-%2 " ) . arg ( startId + 1 ) . arg ( endId + 1 ) ;
else
range + = QString : : number ( startId + 1 ) ;
startId = - 1 ;
endId = - 1 ;
}
}
if ( startId > = 0 & & endId > = 0 )
{
if ( ! range . isEmpty ( ) )
range + = ' , ' ;
if ( endId - startId > 0 )
range + = QString ( " %1-%2 " ) . arg ( startId + 1 ) . arg ( endId + 1 ) ;
else
range + = QString : : number ( startId + 1 ) ;
}
printer . setOption ( " kde-range " , range ) ;
2007-03-04 23:19:43 +00:00
// title
QString title = m_document - > metaData ( " DocumentTitle " ) . toString ( ) ;
if ( title . isEmpty ( ) )
{
title = m_document - > currentDocument ( ) . fileName ( ) ;
}
if ( ! title . isEmpty ( ) )
{
printer . setDocName ( title ) ;
}
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
if ( m_document - > canConfigurePrinter ( ) )
2007-01-02 16:11:40 +00:00
{
2007-01-12 23:48:29 +00:00
KPrintDialogPage * w = m_document - > printConfigurationWidget ( ) ;
2007-01-02 16:11:40 +00:00
if ( w )
{
printer . addDialogPage ( w ) ;
}
}
if ( printer . setup ( widget ( ) ) )
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
doPrint ( printer ) ;
2004-01-02 17:46:06 +00:00
}
2007-01-13 00:33:50 +00:00
2004-11-03 21:37:21 +00:00
void Part : : doPrint ( KPrinter & printer )
2004-01-02 17:46:06 +00:00
{
2007-01-02 22:37:55 +00:00
if ( ! m_document - > isAllowed ( Okular : : AllowPrint ) )
2004-11-03 21:37:21 +00:00
{
KMessageBox : : error ( widget ( ) , i18n ( " Printing this document is not allowed. " ) ) ;
return ;
}
2004-11-09 17:20:19 +00:00
if ( ! m_document - > print ( printer ) )
2004-11-03 21:37:21 +00:00
{
2007-01-13 00:33:50 +00:00
KMessageBox : : error ( widget ( ) , i18n ( " Could not print the document. Please report to bugs.kde.org " ) ) ;
2004-11-03 21:37:21 +00:00
}
2004-01-02 17:46:06 +00:00
}
2007-01-13 00:33:50 +00:00
2007-02-21 15:12:57 +00:00
void Part : : restoreDocument ( const KConfigGroup & group )
2004-11-01 21:56:08 +00:00
{
2007-02-20 15:48:18 +00:00
KUrl url ( group . readPathEntry ( " URL " ) ) ;
2007-01-13 00:33:50 +00:00
if ( url . isValid ( ) )
{
2007-02-20 15:48:18 +00:00
QString viewport = group . readEntry ( " Viewport " ) ;
2007-01-13 00:33:50 +00:00
if ( ! viewport . isEmpty ( ) ) m_document - > setNextDocumentViewport ( Okular : : DocumentViewport ( viewport ) ) ;
openUrl ( url ) ;
}
2004-11-01 21:56:08 +00:00
}
2007-01-13 00:33:50 +00:00
2007-02-20 15:48:18 +00:00
void Part : : saveDocumentRestoreInfo ( KConfigGroup & group )
2004-11-01 21:56:08 +00:00
{
2007-02-20 15:48:18 +00:00
group . writePathEntry ( " URL " , url ( ) . url ( ) ) ;
group . writeEntry ( " Viewport " , m_document - > viewport ( ) . toString ( ) ) ;
2004-11-01 21:56:08 +00:00
}
2007-01-13 00:33:50 +00:00
2005-07-15 18:20:57 +00:00
void Part : : psTransformEnded ( )
{
2007-03-13 20:01:56 +00:00
setLocalFilePath ( m_temporaryLocalFile ) ;
2007-01-13 00:33:50 +00:00
openFile ( ) ;
2005-07-15 18:20:57 +00:00
}
2007-01-13 00:33:50 +00:00
2007-01-12 23:54:26 +00:00
bool Part : : handleCompressed ( KUrl & url , const QString & path , const KMimeType : : Ptr mimetype )
{
// we are working with a compressed file, decompressing
// temporary file for decompressing
2007-01-13 00:18:44 +00:00
m_tempfile = new KTemporaryFile ;
2007-01-12 23:54:26 +00:00
if ( ! m_tempfile )
{
2007-01-13 00:33:50 +00:00
KMessageBox : : error ( 0 ,
2007-01-12 23:54:26 +00:00
i18n ( " <qt><strong>File Error!</strong> Could not create "
" temporary file.</qt> " ) ) ;
return false ;
}
m_tempfile - > setAutoRemove ( true ) ;
if ( ! m_tempfile - > open ( ) )
{
2007-01-13 00:33:50 +00:00
KMessageBox : : error ( 0 ,
2007-01-12 23:54:26 +00:00
i18n ( " <qt><strong>File Error!</strong> Could not create temporary file "
2007-01-13 00:33:50 +00:00
" <nobr><strong>%1</strong></nobr>.</qt> " ,
strerror ( m_tempfile - > error ( ) ) ) ) ;
delete m_tempfile ;
return false ;
2007-01-12 23:54:26 +00:00
}
// decompression filer
QIODevice * filterDev ;
if ( ( mimetype - > parentMimeType ( ) = = " application/x-gzip " ) | |
( mimetype - > parentMimeType ( ) = = " application/x-bzip2 " ) )
2007-01-13 00:33:50 +00:00
filterDev = KFilterDev : : deviceForFile ( path , mimetype - > parentMimeType ( ) ) ;
2007-01-12 23:54:26 +00:00
else
2007-01-13 00:33:50 +00:00
filterDev = KFilterDev : : deviceForFile ( path ) ;
2007-01-12 23:54:26 +00:00
if ( ! filterDev )
{
delete m_tempfile ;
return false ;
}
if ( ! filterDev - > open ( QIODevice : : ReadOnly ) )
{
2007-01-13 00:33:50 +00:00
KMessageBox : : detailedError ( 0 ,
2007-01-12 23:54:26 +00:00
i18n ( " <qt><strong>File Error!</strong> Could not open the file "
" <nobr><strong>%1</strong></nobr> for uncompression. "
" The file will not be loaded.</qt> " , path ) ,
i18n ( " <qt>This error typically occurs if you do "
2007-01-13 00:33:50 +00:00
" not have enough permissions to read the file. "
2007-01-12 23:54:26 +00:00
" You can check ownership and permissions if you "
" right-click on the file in the Konqueror "
" file manager and then choose the 'Properties' menu.</qt> " ) ) ;
2007-01-13 00:33:50 +00:00
delete filterDev ;
delete m_tempfile ;
return false ;
2007-01-12 23:54:26 +00:00
}
QByteArray buf ( 1024 , ' \0 ' ) ;
int read = 0 , wrtn = 0 ;
while ( ( read = filterDev - > read ( buf . data ( ) , buf . size ( ) ) ) > 0 )
{
wrtn = m_tempfile - > write ( buf . data ( ) , read ) ;
if ( read ! = wrtn )
break ;
}
delete filterDev ;
if ( ( read ! = 0 ) | | ( m_tempfile - > size ( ) = = 0 ) )
{
2007-01-13 00:33:50 +00:00
KMessageBox : : detailedError ( 0 ,
2007-01-12 23:54:26 +00:00
i18n ( " <qt><strong>File Error!</strong> Could not uncompress "
" the file <nobr><strong>%1</strong></nobr>. "
" The file will not be loaded.</qt> " , path ) ,
i18n ( " <qt>This error typically occurs if the file is corrupt. "
" If you want to be sure, try to decompress the file manually "
" using command-line tools.</qt> " ) ) ;
delete m_tempfile ;
return false ;
}
url = m_tempfile - > fileName ( ) ;
return true ;
}
2007-01-13 17:28:54 +00:00
void Part : : rebuildBookmarkMenu ( bool unplugActions )
{
if ( unplugActions )
{
unplugActionList ( " bookmarks_currentdocument " ) ;
qDeleteAll ( m_bookmarkActions ) ;
m_bookmarkActions . clear ( ) ;
}
KUrl u = m_document - > currentDocument ( ) ;
if ( u . isValid ( ) )
{
m_bookmarkActions = m_document - > bookmarkManager ( ) - > actionsForUrl ( u ) ;
}
2007-01-28 16:37:13 +00:00
bool havebookmarks = true ;
2007-01-13 17:28:54 +00:00
if ( m_bookmarkActions . isEmpty ( ) )
{
2007-01-28 16:37:13 +00:00
havebookmarks = false ;
2007-01-13 17:28:54 +00:00
QAction * a = new QAction ( 0 ) ;
a - > setText ( i18n ( " No Bookmarks " ) ) ;
a - > setEnabled ( false ) ;
m_bookmarkActions . append ( a ) ;
}
for ( int i = 0 ; i < m_bookmarkActions . count ( ) ; + + i )
{
actionCollection ( ) - > addAction ( QString ( " bookmark_action_%1 " ) . arg ( i ) , m_bookmarkActions . at ( i ) ) ;
}
plugActionList ( " bookmarks_currentdocument " , m_bookmarkActions ) ;
2007-01-28 16:37:13 +00:00
m_prevBookmark - > setEnabled ( havebookmarks ) ;
m_nextBookmark - > setEnabled ( havebookmarks ) ;
2007-01-13 17:28:54 +00:00
}
2007-03-07 18:15:00 +00:00
void Part : : updateAboutBackendAction ( )
{
const KComponentData * data = m_document - > componentData ( ) ;
if ( data )
{
m_aboutBackend - > setEnabled ( true ) ;
}
else
{
m_aboutBackend - > setEnabled ( false ) ;
}
}
2007-01-12 23:54:26 +00:00
2004-09-18 16:41:23 +00:00
/*
2007-01-13 00:33:50 +00:00
* BrowserExtension class
*/
2004-09-08 12:41:14 +00:00
BrowserExtension : : BrowserExtension ( Part * parent )
2007-03-10 22:50:40 +00:00
: KParts : : BrowserExtension ( parent ) , m_part ( parent )
2004-08-26 23:25:52 +00:00
{
2007-01-13 00:33:50 +00:00
emit enableAction ( " print " , true ) ;
setURLDropHandlingEnabled ( true ) ;
2004-09-08 12:41:14 +00:00
}
2004-08-29 11:24:11 +00:00
2007-01-13 00:33:50 +00:00
2004-09-08 12:41:14 +00:00
void BrowserExtension : : print ( )
{
2007-03-10 22:50:40 +00:00
m_part - > slotPrint ( ) ;
2004-08-26 23:25:52 +00:00
}
2007-01-13 00:33:50 +00:00
2005-01-02 14:29:37 +00:00
# include "part.moc"