From bdc00ae3f3f2aee4826bedf13e7f03fc7a33b6cb Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sat, 16 Jul 2005 16:41:03 +0000 Subject: [PATCH] Correct the implementation of Quit link action Add the implementation of close link action That two actions only work within inside kpdf as in konqueror they would be quite shocking Reverse the order link actions are added to m_rects because there are some pdf that have a rect with a link and inside of that another link with a snall rect, and with this order we match acrobat behaviour svn path=/trunk/KDE/kdegraphics/kpdf/; revision=435350 --- core/document.cpp | 5 ++++- core/document.h | 2 ++ core/generator_pdf/gp_outputdev.cpp | 4 +++- core/link.h | 2 +- part.cpp | 24 +++++++++++++++++++++++- part.h | 5 +++++ shell/shell.cpp | 1 + shell/shell.h | 5 +++-- ui/pageview.cpp | 5 +++++ 9 files changed, 47 insertions(+), 6 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index 5d5a4e5cd..7a9ba10d3 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -1025,7 +1025,7 @@ void KPDFDocument::processLink( const KPDFLink * link ) setNextViewport(); break; case KPDFLinkAction::Quit: - kapp->quit(); + emit quit(); break; case KPDFLinkAction::Find: emit linkFind(); @@ -1033,6 +1033,9 @@ void KPDFDocument::processLink( const KPDFLink * link ) case KPDFLinkAction::GoToPage: emit linkGoToPage(); break; + case KPDFLinkAction::Close: + emit close(); + break; } } break; diff --git a/core/document.h b/core/document.h index 5feebf38a..7400f194d 100644 --- a/core/document.h +++ b/core/document.h @@ -102,6 +102,8 @@ class KPDFDocument : public QObject void requestDone( PixmapRequest * request ); signals: + void close(); + void quit(); void linkFind(); void linkGoToPage(); void openURL(const KURL &url); diff --git a/core/generator_pdf/gp_outputdev.cpp b/core/generator_pdf/gp_outputdev.cpp index 88ccd07d3..b46e2900b 100644 --- a/core/generator_pdf/gp_outputdev.cpp +++ b/core/generator_pdf/gp_outputdev.cpp @@ -174,7 +174,7 @@ void KPDFOutputDev::drawLink( Link * link, Catalog * catalog ) // create the rect using normalized coords and attach the KPDFLink to it ObjectRect * rect = new ObjectRect( nl, nt, nr, nb, ObjectRect::Link, l ); // add the ObjectRect to the vector container - m_rects.push_back( rect ); + m_rects.push_front( rect ); } } SplashOutputDev::drawLink( link, catalog ); @@ -325,6 +325,8 @@ KPDFLink * KPDFOutputDev::generateLink( LinkAction * a ) link = new KPDFLinkAction( KPDFLinkAction::GoToPage ); else if ( !strcmp( name, "Find" ) ) link = new KPDFLinkAction( KPDFLinkAction::Find ); + else if ( !strcmp( name, "Close" ) ) + link = new KPDFLinkAction( KPDFLinkAction::Close ); else kdDebug() << "Unknown named action: '" << name << "'" << endl; } diff --git a/core/link.h b/core/link.h index a40f35a2b..2954f7180 100644 --- a/core/link.h +++ b/core/link.h @@ -88,7 +88,7 @@ class KPDFLinkAction : public KPDFLink { public: // define types of actions - enum ActionType { PageFirst, PagePrev, PageNext, PageLast, HistoryBack, HistoryForward, Quit, Find, GoToPage }; + enum ActionType { PageFirst, PagePrev, PageNext, PageLast, HistoryBack, HistoryForward, Quit, Find, GoToPage, Close }; // query for action type ActionType actionType() const { return m_type; } diff --git a/part.cpp b/part.cpp index 5aab591e7..818187e6c 100644 --- a/part.cpp +++ b/part.cpp @@ -106,6 +106,12 @@ Part::Part(QWidget *parentWidget, const char *widgetName, connect( m_document, SIGNAL( linkFind() ), this, SLOT( slotFind() ) ); connect( m_document, SIGNAL( linkGoToPage() ), this, SLOT( slotGoToPage() ) ); connect( m_document, SIGNAL( openURL(const KURL &) ), this, SLOT( openURL(const KURL &) ) ); + connect( m_document, SIGNAL( close() ), this, SLOT( close() ) ); + + if (parent && parent->metaObject()->slotNames(true).contains("slotQuit()")) + 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" ); @@ -431,10 +437,12 @@ bool Part::closeURL() m_printPreview->setEnabled( false ); m_showProperties->setEnabled( false ); m_showPresentation->setEnabled( false ); - updateViewActions(); + emit setWindowCaption(""); + emit enablePrintAction(false); m_searchStarted = false; if (!m_file.isEmpty()) m_watcher->removeFile(m_file); m_document->closeDocument(); + updateViewActions(); m_searchWidget->clearText(); return KParts::ReadOnlyPart::closeURL(); } @@ -483,6 +491,15 @@ void Part::slotDoFileDirty() } } +void Part::close() +{ + if (parent() && strcmp(parent()->name(), "KPDF::Shell") == 0) + { + 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, "warnNoCloseIfNotInKPDF"); +} + void Part::updateViewActions() { bool opened = m_document->pages() > 0; @@ -521,6 +538,11 @@ void Part::psTransformEnded() openFile(); } +void Part::cannotQuit() +{ + KMessageBox::information(widget(), i18n("This link points to a quit application action that does not work when using the embedded viewer."), QString::null, "warnNoQuitIfNotInKPDF"); +} + //BEGIN go to page dialog class KPDFGotoPageDialog : public KDialogBase { diff --git a/part.h b/part.h index 0d914e3b5..a590c25c8 100644 --- a/part.h +++ b/part.h @@ -78,6 +78,9 @@ public: uint currentPage(); KURL currentDocument(); +signals: + void enablePrintAction(bool enable); + protected: // reimplemented from KParts::ReadOnlyPart bool openFile(); @@ -103,10 +106,12 @@ protected slots: void slotShowProperties(); void slotShowLeftPanel(); void slotShowPresentation(); + void close(); // can be connected to widget elements void updateViewActions(); void enableTOC(bool enable); void psTransformEnded(); + void cannotQuit(); public slots: // connected to Shell action (and browserExtension), not local one diff --git a/shell/shell.cpp b/shell/shell.cpp index 8104ffc4e..a3e241a29 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -88,6 +88,7 @@ void Shell::init() } connect( this, SIGNAL( restoreDocument(const KURL &, int) ),m_part, SLOT( restoreDocument(const KURL &, int))); connect( this, SIGNAL( saveDocumentRestoreInfo(KConfig*) ), m_part, SLOT( saveDocumentRestoreInfo(KConfig*))); + connect( m_part, SIGNAL( enablePrintAction(bool) ), m_printAction, SLOT( setEnabled(bool))); readSettings(); if (!KGlobal::config()->hasGroup("MainWindow")) diff --git a/shell/shell.h b/shell/shell.h index a3dabe79b..4e2e2b07c 100644 --- a/shell/shell.h +++ b/shell/shell.h @@ -70,11 +70,12 @@ namespace KPDF void writeSettings(); void setFullScreen( bool ); + public slots: + void slotQuit(); + private slots: void fileOpen(); - void slotQuit(); - void optionsConfigureToolbars(); void applyNewToolbarConfig(); void slotUpdateFullScreen(); diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 40a442fb3..a4741453f 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -272,7 +272,12 @@ void PageView::notifySetup( const QValueVector< KPDFPage * > & pageSet, bool doc // so pages are never relayouted slotRelayoutPages(); else + { + // update the mouse cursor when closing because we may have close through a link and + // want the cursor to come back to the normal cursor + updateCursor( viewportToContents( mapFromGlobal( QCursor::pos() ) ) ); resizeContents( 0, 0 ); + } // OSD to display pages if ( documentChanged && pageSet.count() > 0 && Settings::showOSD() )