mirror of
https://invent.kde.org/graphics/okular
synced 2024-10-02 14:14:10 +00:00
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.
This commit is contained in:
parent
ec9f068d77
commit
f6fa2a5614
|
@ -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
|
||||
|
|
|
@ -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 ];
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 ) ) );
|
||||
|
||||
|
|
Loading…
Reference in a new issue