From f6fa2a5614db0cc542e466f2289c92623f808e56 Mon Sep 17 00:00:00 2001 From: Fabio D'Urso Date: Fri, 9 Mar 2012 14:59:24 +0100 Subject: [PATCH] Disable GUI operations on certain types of annotations Modification and removal of *external* annotations are disabled by this patch. Note that this change doesn't remove any functionality, because they have never been implemented (AnnotationProxy is defined by the previous patch). The #if0'd blocks will be enabled by a future patch that provides fallback behavior for generators that don't support saving changes. --- core/annotations.cpp | 7 ++-- core/document.cpp | 55 +++++++++++++++++++++++++++++++ core/document.h | 7 ++++ core/document_p.h | 2 ++ ui/annotationpopup.cpp | 7 ++-- ui/annotationpropertiesdialog.cpp | 2 +- ui/annotwindow.cpp | 5 +++ 7 files changed, 79 insertions(+), 6 deletions(-) diff --git a/core/annotations.cpp b/core/annotations.cpp index adb634d27..6842d9878 100644 --- a/core/annotations.cpp +++ b/core/annotations.cpp @@ -16,6 +16,7 @@ // local includes #include "document.h" +#include "document_p.h" #include "movie.h" #include "page_p.h" #include "sound.h" @@ -735,9 +736,9 @@ void Annotation::setDisposeDataFunction( DisposeDataFunction func ) bool Annotation::canBeMoved() const { Q_D( const Annotation ); - // for now, it is pointless moving external annotations - // as we cannot change them anyway - if ( d->m_flags & External ) + + // Don't move annotations if they cannot be modified + if ( !d->m_page || !d->m_page->m_doc->m_parent->canModifyPageAnnotation(this) ) return false; // highlight "requires" to be "bounded" to text, and that's tricky for now diff --git a/core/document.cpp b/core/document.cpp index fe80cffaf..b2ecdf9e1 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -2360,6 +2360,31 @@ void Document::addPageAnnotation( int page, Annotation * annotation ) } } +bool Document::canModifyPageAnnotation( const Annotation * annotation ) const +{ + if ( !annotation || ( annotation->flags() & Annotation::DenyWrite ) ) + return false; + + if ( !isAllowed(Okular::AllowNotes) ) + return false; + + if ( ( annotation->flags() & Annotation::External ) && !d->canModifyExternalAnnotations() ) + return false; + + switch ( annotation->subType() ) + { + case Annotation::AText: + case Annotation::ALine: + case Annotation::AGeom: + case Annotation::AHighlight: + case Annotation::AStamp: + case Annotation::AInk: + return true; + default: + return false; + } +} + void Document::modifyPageAnnotation( int page, Annotation * annotation ) { modifyPageAnnotation( page, annotation, true ); @@ -2394,6 +2419,9 @@ bool Document::canRemovePageAnnotation( const Annotation * annotation ) const if ( !annotation || ( annotation->flags() & Annotation::DenyDelete ) ) return false; + if ( ( annotation->flags() & Annotation::External ) && !d->canRemoveExternalAnnotations() ) + return false; + switch ( annotation->subType() ) { case Annotation::AText: @@ -2490,6 +2518,33 @@ void Document::removePageAnnotations( int page, const QList< Annotation * > &ann } } +bool DocumentPrivate::canModifyExternalAnnotations() const +{ + /* To be enabled once external annotations are implemented independently + * of save/restoreLocalContents. At the moment, we support editing internal + * annotations only. */ +#if 0 + Okular::SaveInterface * iface = qobject_cast< Okular::SaveInterface * >( d->m_generator ); + + if ( iface && iface->annotationProxy() && + iface->annotationProxy()->supports(AnnotationProxy::Modification) ) + return true; +#endif + return false; +} + +bool DocumentPrivate::canRemoveExternalAnnotations() const +{ +#if 0 /* See canModifyExternalAnnotations */ + Okular::SaveInterface * iface = qobject_cast< Okular::SaveInterface * >( d->m_generator ); + + if ( iface && iface->annotationProxy() && + iface->annotationProxy()->supports(AnnotationProxy::Removal) ) + return true; +#endif + return false; +} + void Document::setPageTextSelection( int page, RegularAreaRect * rect, const QColor & color ) { Page * kp = d->m_pagesVector[ page ]; diff --git a/core/document.h b/core/document.h index 9ff32b641..cd36ae7f1 100644 --- a/core/document.h +++ b/core/document.h @@ -367,6 +367,13 @@ class OKULAR_EXPORT Document : public QObject */ void addPageAnnotation( int page, Annotation *annotation ); + /** + * Tests if the @p annotation can be modified + * + * @since 0.15 (KDE 4.9) + */ + bool canModifyPageAnnotation( const Annotation * annotation ) const; + /** * Modifies the given @p annotation on the given @p page. * diff --git a/core/document_p.h b/core/document_p.h index 4f78d9a14..8ead67f18 100644 --- a/core/document_p.h +++ b/core/document_p.h @@ -114,6 +114,8 @@ class DocumentPrivate bool openDocumentInternal( const KService::Ptr& offer, bool isstdin, const QString& docFile, const QByteArray& filedata ); bool savePageDocumentInfo( KTemporaryFile *infoFile, int what ) const; DocumentViewport nextDocumentViewport() const; + bool canModifyExternalAnnotations() const; + bool canRemoveExternalAnnotations() const; // private slots void saveDocumentInfo() const; diff --git a/ui/annotationpopup.cpp b/ui/annotationpopup.cpp index e665bdcd7..1c3a71714 100644 --- a/ui/annotationpopup.cpp +++ b/ui/annotationpopup.cpp @@ -53,8 +53,11 @@ void AnnotationPopup::exec( const QPoint &point ) deleteNote->setEnabled( mDocument->isAllowed( Okular::AllowNotes ) ); const AnnotPagePair &firstAnnotPagePair = mAnnotations.at(0); - if ( onlyOne && firstAnnotPagePair.annotation->flags() & Okular::Annotation::DenyDelete ) - deleteNote->setEnabled( false ); + foreach ( const AnnotPagePair& pair, mAnnotations ) + { + if ( !mDocument->canRemovePageAnnotation(pair.annotation) ) + deleteNote->setEnabled( false ); + } showProperties = menu.addAction( KIcon( "configure" ), i18n( "&Properties" ) ); showProperties->setEnabled( onlyOne ); diff --git a/ui/annotationpropertiesdialog.cpp b/ui/annotationpropertiesdialog.cpp index 06f92769d..4b0225803 100644 --- a/ui/annotationpropertiesdialog.cpp +++ b/ui/annotationpropertiesdialog.cpp @@ -34,7 +34,7 @@ AnnotsPropertiesDialog::AnnotsPropertiesDialog( QWidget *parent, Okular::Documen { setFaceType( Tabbed ); m_annot=ann; - bool canEditAnnotations = !(ann->flags() & Okular::Annotation::External) && m_document->isAllowed( Okular::AllowNotes ); + const bool canEditAnnotations = m_document->canModifyPageAnnotation( ann ); setCaptionTextbyAnnotType(); if ( canEditAnnotations ) { diff --git a/ui/annotwindow.cpp b/ui/annotwindow.cpp index fce1667be..dc84b6f7e 100644 --- a/ui/annotwindow.cpp +++ b/ui/annotwindow.cpp @@ -190,6 +190,8 @@ AnnotWindow::AnnotWindow( QWidget * parent, Okular::Annotation * annot, Okular:: setFrameStyle( Panel | Raised ); setAttribute( Qt::WA_DeleteOnClose ); + const bool canEditAnnotation = m_document->canModifyPageAnnotation( annot ); + textEdit = new KTextEdit( this ); textEdit->setAcceptRichText( false ); textEdit->setPlainText( GuiUtils::contents( m_annot ) ); @@ -197,6 +199,9 @@ AnnotWindow::AnnotWindow( QWidget * parent, Okular::Annotation * annot, Okular:: connect(textEdit,SIGNAL(textChanged()), this,SLOT(slotsaveWindowText())); + if (!canEditAnnotation) + textEdit->setReadOnly(true); + m_latexRenderer = new GuiUtils::LatexRenderer(); emit containsLatex( GuiUtils::LatexRenderer::mightContainLatex( GuiUtils::contents( m_annot ) ) );