2013-04-05 22:39:35 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2013 Jon Mease <jon.mease@gmail.com> *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "documentcommands_p.h"
|
|
|
|
|
|
|
|
#include "annotations.h"
|
|
|
|
#include "debug_p.h"
|
|
|
|
#include "document_p.h"
|
2013-06-03 20:46:41 +00:00
|
|
|
#include "form.h"
|
2013-12-29 22:27:30 +00:00
|
|
|
#include "utils_p.h"
|
|
|
|
#include "page.h"
|
2013-04-05 22:39:35 +00:00
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
|
|
namespace Okular {
|
|
|
|
|
2013-12-29 22:27:30 +00:00
|
|
|
void moveViewportIfBoundingRectNotFullyVisible( Okular::NormalizedRect boundingRect,
|
|
|
|
DocumentPrivate *docPriv,
|
|
|
|
int pageNumber )
|
|
|
|
{
|
|
|
|
const Rotation pageRotation = docPriv->m_parent->page( pageNumber )->rotation();
|
|
|
|
const QTransform rotationMatrix = Okular::buildRotationMatrix( pageRotation );
|
|
|
|
boundingRect.transform( rotationMatrix );
|
|
|
|
if ( !docPriv->isNormalizedRectangleFullyVisible( boundingRect, pageNumber ) )
|
|
|
|
{
|
|
|
|
DocumentViewport searchViewport( pageNumber );
|
|
|
|
searchViewport.rePos.enabled = true;
|
|
|
|
searchViewport.rePos.normalizedX = ( boundingRect.left + boundingRect.right ) / 2.0;
|
|
|
|
searchViewport.rePos.normalizedY = ( boundingRect.top + boundingRect.bottom ) / 2.0;
|
|
|
|
docPriv->m_parent->setViewport( searchViewport, 0, true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Okular::NormalizedRect buildBoundingRectangleForButtons( const QList<Okular::FormFieldButton*> & formButtons )
|
|
|
|
{
|
|
|
|
// Initialize coordinates of the bounding rect
|
|
|
|
double left = 1.0;
|
|
|
|
double top = 1.0;
|
|
|
|
double right = 0.0;
|
|
|
|
double bottom = 0.0;
|
|
|
|
|
|
|
|
foreach( FormFieldButton* formButton, formButtons )
|
|
|
|
{
|
|
|
|
left = qMin<double>( left, formButton->rect().left );
|
|
|
|
top = qMin<double>( top, formButton->rect().top );
|
|
|
|
right = qMax<double>( right, formButton->rect().right );
|
|
|
|
bottom = qMax<double>( bottom, formButton->rect().bottom );
|
|
|
|
}
|
|
|
|
Okular::NormalizedRect boundingRect( left, top, right, bottom );
|
|
|
|
return boundingRect;
|
|
|
|
}
|
|
|
|
|
2013-04-05 22:39:35 +00:00
|
|
|
AddAnnotationCommand::AddAnnotationCommand( Okular::DocumentPrivate * docPriv, Okular::Annotation* annotation, int pageNumber )
|
|
|
|
: m_docPriv( docPriv ),
|
|
|
|
m_annotation( annotation ),
|
|
|
|
m_pageNumber( pageNumber ),
|
|
|
|
m_done( false )
|
|
|
|
{
|
|
|
|
setText( i18nc ("Add an annotation to the page", "add annotation" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
AddAnnotationCommand::~AddAnnotationCommand()
|
|
|
|
{
|
|
|
|
if ( !m_done )
|
|
|
|
{
|
|
|
|
delete m_annotation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddAnnotationCommand::undo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_annotation->boundingRectangle(), m_docPriv, m_pageNumber );
|
2013-04-05 22:39:35 +00:00
|
|
|
m_docPriv->performRemovePageAnnotation( m_pageNumber, m_annotation );
|
|
|
|
m_done = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddAnnotationCommand::redo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_annotation->boundingRectangle(), m_docPriv, m_pageNumber );
|
2013-04-05 22:39:35 +00:00
|
|
|
m_docPriv->performAddPageAnnotation( m_pageNumber, m_annotation );
|
|
|
|
m_done = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RemoveAnnotationCommand::RemoveAnnotationCommand(Okular::DocumentPrivate * doc, Okular::Annotation* annotation, int pageNumber)
|
2013-12-29 22:27:30 +00:00
|
|
|
: m_docPriv( doc ),
|
2013-04-05 22:39:35 +00:00
|
|
|
m_annotation( annotation ),
|
|
|
|
m_pageNumber( pageNumber ),
|
|
|
|
m_done( false )
|
|
|
|
{
|
|
|
|
setText( i18nc( "Remove an annotation from the page", "remove annotation" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveAnnotationCommand::~RemoveAnnotationCommand()
|
|
|
|
{
|
|
|
|
if ( m_done )
|
|
|
|
{
|
|
|
|
delete m_annotation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveAnnotationCommand::undo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_annotation->boundingRectangle(), m_docPriv, m_pageNumber );
|
|
|
|
m_docPriv->performAddPageAnnotation( m_pageNumber, m_annotation );
|
2013-04-05 22:39:35 +00:00
|
|
|
m_done = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveAnnotationCommand::redo(){
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_annotation->boundingRectangle(), m_docPriv, m_pageNumber );
|
|
|
|
m_docPriv->performRemovePageAnnotation( m_pageNumber, m_annotation );
|
2013-04-05 22:39:35 +00:00
|
|
|
m_done = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ModifyAnnotationPropertiesCommand::ModifyAnnotationPropertiesCommand( DocumentPrivate* docPriv,
|
|
|
|
Annotation* annotation,
|
|
|
|
int pageNumber,
|
|
|
|
QDomNode oldProperties,
|
|
|
|
QDomNode newProperties )
|
|
|
|
: m_docPriv( docPriv ),
|
|
|
|
m_annotation( annotation ),
|
|
|
|
m_pageNumber( pageNumber ),
|
|
|
|
m_prevProperties( oldProperties ),
|
|
|
|
m_newProperties( newProperties )
|
|
|
|
{
|
|
|
|
setText(i18nc("Modify an annotation's internal properties (Color, line-width, etc.)", "modify annotation properties"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModifyAnnotationPropertiesCommand::undo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_annotation->boundingRectangle(), m_docPriv, m_pageNumber );
|
2013-04-05 22:39:35 +00:00
|
|
|
m_annotation->setAnnotationProperties( m_prevProperties );
|
|
|
|
m_docPriv->performModifyPageAnnotation( m_pageNumber, m_annotation, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModifyAnnotationPropertiesCommand::redo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_annotation->boundingRectangle(), m_docPriv, m_pageNumber );
|
2013-04-05 22:39:35 +00:00
|
|
|
m_annotation->setAnnotationProperties( m_newProperties );
|
|
|
|
m_docPriv->performModifyPageAnnotation( m_pageNumber, m_annotation, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
TranslateAnnotationCommand::TranslateAnnotationCommand( DocumentPrivate* docPriv,
|
|
|
|
Annotation* annotation,
|
|
|
|
int pageNumber,
|
|
|
|
const Okular::NormalizedPoint & delta,
|
|
|
|
bool completeDrag )
|
|
|
|
: m_docPriv( docPriv ),
|
|
|
|
m_annotation( annotation ),
|
|
|
|
m_pageNumber( pageNumber ),
|
|
|
|
m_delta( delta ),
|
|
|
|
m_completeDrag( completeDrag )
|
|
|
|
{
|
|
|
|
setText( i18nc( "Translate an annotation's position on the page", "translate annotation" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void TranslateAnnotationCommand::undo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible(translateBoundingRectangle( minusDelta() ), m_docPriv, m_pageNumber );
|
2013-04-05 22:39:35 +00:00
|
|
|
m_annotation->translate( minusDelta() );
|
|
|
|
m_docPriv->performModifyPageAnnotation( m_pageNumber, m_annotation, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
void TranslateAnnotationCommand::redo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible(translateBoundingRectangle( m_delta ), m_docPriv, m_pageNumber );
|
2013-04-05 22:39:35 +00:00
|
|
|
m_annotation->translate( m_delta );
|
|
|
|
m_docPriv->performModifyPageAnnotation( m_pageNumber, m_annotation, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
int TranslateAnnotationCommand::id() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TranslateAnnotationCommand::mergeWith( const QUndoCommand* uc )
|
|
|
|
{
|
|
|
|
TranslateAnnotationCommand *tuc = (TranslateAnnotationCommand*)uc;
|
|
|
|
|
|
|
|
if ( tuc->m_annotation != m_annotation )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( m_completeDrag )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_delta = Okular::NormalizedPoint( tuc->m_delta.x + m_delta.x, tuc->m_delta.y + m_delta.y );
|
|
|
|
m_completeDrag = tuc->m_completeDrag;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Okular::NormalizedPoint TranslateAnnotationCommand::minusDelta()
|
|
|
|
{
|
|
|
|
return Okular::NormalizedPoint( -m_delta.x, -m_delta.y );
|
|
|
|
}
|
|
|
|
|
2013-12-29 22:27:30 +00:00
|
|
|
Okular::NormalizedRect TranslateAnnotationCommand::translateBoundingRectangle( const Okular::NormalizedPoint & delta )
|
|
|
|
{
|
|
|
|
Okular::NormalizedRect annotBoundingRect = m_annotation->boundingRectangle();
|
|
|
|
double left = qMin<double>( annotBoundingRect.left, annotBoundingRect.left + delta.x );
|
|
|
|
double right = qMax<double>( annotBoundingRect.right, annotBoundingRect.right + delta.x );
|
|
|
|
double top = qMin<double>( annotBoundingRect.top, annotBoundingRect.top + delta.y );
|
|
|
|
double bottom = qMax<double>( annotBoundingRect.bottom, annotBoundingRect.bottom + delta.y );
|
|
|
|
Okular::NormalizedRect boundingRect( left, top, right, bottom );
|
|
|
|
return boundingRect;
|
|
|
|
}
|
2013-04-05 22:39:35 +00:00
|
|
|
|
Add annotation resize functionality
Usage:
If you left-click an annotation, it gets selected. Resize handles appear on the selection rectangle. When cursor is moved over one of the 8 resize handles on the corners/edges, the cursor shape changes to indicate resize mode. Everywhere else on the annotation means "move", just as it was before resize feature was added. Pressing ESC or clicking an area outside the annotation cancels a selection. Pressing Del deletes a selected annotation.
Feature is only applicable for annotation types AText, AStamp and AGeom.
Implementation:
It works by eventually changing AnnotationPrivate::m_boundary and notifying generator (i.e. poppler) about that change. Annotation state handling is shifted out of PageView into a new class MouseAnnotation (ui/pageviewmouseannotation.cpp). Some functionality not related to resizing but to annotation interaction in general is also shifted to class MouseAnnotation, to build a single place of responsiblity.
Other changes:
Add method Document::adjustPageAnnotation, backed by a QUndoCommand.
class Okular::AdjustAnnotationCommand.
Add Annotation::adjust and Annotation::canBeResized methods.
Draw resize handles in PagePainter::paintCroppedPageOnPainter.
Resize and move work
-for types AText, AStamp and AGeom
-on all pages of document
-when viewport position changes
-when zoom level changes
-for all page rotations (0°, 90°, 180°, 270°)
Selection is canceled
-when currently selected annotation is deleted
-on mouse click outside of currently selected annotation
-ESC is pressed
Viewport is shifted when mouse cursor during move/resize comes close to viewport border.
Resize to negative is prevented.
Tiny annotations are still selectable.
If mouse is moved over an annotation type that we can focus, and the annotation is not yet focused, mouse cursor shape changes to arrow.
If mouse cursor rests over an annotation A, while annotation B is focused, a tooltip for annotation A is shown.
Selected Annotation is deleted when Del is pressed.
Test for regressions:
-Annotation interaction (focus, move, resize, start playback, ...) are only done in mode EnumMouseMode::Browse.
-If mouse is moved over an annotation type where we can start an action, mouse cursor shape changes to pointing hand.
-If mouse is moved over an annotation type that we can't interact with, mouse cursor shape stays a open hand.
-If mouse cursor rests over an annotation of any type, a tooltip for that annotation is shown.
-Grab/move scroll area (on left click + mouse move) is prevented, if mouse is over focused annotation, or over AMovie/AScreen/AFileAttachment annotation.
-A double click on a annotation starts the "annotator".
REVIEW: 127366
BUG: 177778
BUG: 314843
BUG: 358060
2017-03-19 22:16:06 +00:00
|
|
|
AdjustAnnotationCommand::AdjustAnnotationCommand(Okular::DocumentPrivate * docPriv,
|
|
|
|
Okular::Annotation * annotation,
|
|
|
|
int pageNumber,
|
|
|
|
const Okular::NormalizedPoint & delta1,
|
|
|
|
const Okular::NormalizedPoint & delta2,
|
|
|
|
bool completeDrag )
|
|
|
|
: m_docPriv( docPriv ),
|
|
|
|
m_annotation( annotation ),
|
|
|
|
m_pageNumber( pageNumber ),
|
|
|
|
m_delta1( delta1 ),
|
|
|
|
m_delta2( delta2 ),
|
|
|
|
m_completeDrag( completeDrag )
|
|
|
|
{
|
|
|
|
setText( i18nc( "Change an annotation's size", "adjust annotation" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdjustAnnotationCommand::undo()
|
|
|
|
{
|
|
|
|
const NormalizedPoint minusDelta1 = Okular::NormalizedPoint( -m_delta1.x, -m_delta1.y );
|
|
|
|
const NormalizedPoint minusDelta2 = Okular::NormalizedPoint( -m_delta2.x, -m_delta2.y );
|
|
|
|
moveViewportIfBoundingRectNotFullyVisible( adjustBoundingRectangle( minusDelta1, minusDelta2 ), m_docPriv, m_pageNumber );
|
|
|
|
m_annotation->adjust( minusDelta1, minusDelta2 );
|
|
|
|
m_docPriv->performModifyPageAnnotation( m_pageNumber, m_annotation, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdjustAnnotationCommand::redo()
|
|
|
|
{
|
|
|
|
moveViewportIfBoundingRectNotFullyVisible( adjustBoundingRectangle( m_delta1, m_delta2 ), m_docPriv, m_pageNumber );
|
|
|
|
m_annotation->adjust( m_delta1, m_delta2 );
|
|
|
|
m_docPriv->performModifyPageAnnotation( m_pageNumber, m_annotation, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
int AdjustAnnotationCommand::id() const
|
|
|
|
{
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdjustAnnotationCommand::mergeWith( const QUndoCommand * uc )
|
|
|
|
{
|
|
|
|
AdjustAnnotationCommand *tuc = (AdjustAnnotationCommand *)uc;
|
|
|
|
|
|
|
|
if ( tuc->m_annotation != m_annotation )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( m_completeDrag )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_delta1 = Okular::NormalizedPoint( tuc->m_delta1.x + m_delta1.x, tuc->m_delta1.y + m_delta1.y );
|
|
|
|
m_delta2 = Okular::NormalizedPoint( tuc->m_delta2.x + m_delta2.x, tuc->m_delta2.y + m_delta2.y );
|
|
|
|
m_completeDrag = tuc->m_completeDrag;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Okular::NormalizedRect AdjustAnnotationCommand::adjustBoundingRectangle(
|
|
|
|
const Okular::NormalizedPoint & delta1, const Okular::NormalizedPoint & delta2 )
|
|
|
|
{
|
|
|
|
const Okular::NormalizedRect annotBoundingRect = m_annotation->boundingRectangle();
|
|
|
|
const double left = qMin<double>( annotBoundingRect.left, annotBoundingRect.left + delta1.x );
|
|
|
|
const double right = qMax<double>( annotBoundingRect.right, annotBoundingRect.right + delta2.x );
|
|
|
|
const double top = qMin<double>( annotBoundingRect.top, annotBoundingRect.top + delta1.y );
|
|
|
|
const double bottom = qMax<double>( annotBoundingRect.bottom, annotBoundingRect.bottom + delta2.y );
|
|
|
|
return Okular::NormalizedRect( left, top, right, bottom );
|
|
|
|
}
|
|
|
|
|
2013-04-05 22:39:35 +00:00
|
|
|
EditTextCommand::EditTextCommand( const QString & newContents,
|
|
|
|
int newCursorPos,
|
|
|
|
const QString & prevContents,
|
|
|
|
int prevCursorPos,
|
|
|
|
int prevAnchorPos )
|
|
|
|
: m_newContents( newContents ),
|
|
|
|
m_newCursorPos( newCursorPos ),
|
|
|
|
m_prevContents( prevContents ),
|
|
|
|
m_prevCursorPos( prevCursorPos ),
|
|
|
|
m_prevAnchorPos( prevAnchorPos )
|
|
|
|
{
|
|
|
|
setText( i18nc( "Generic text edit command", "edit text" ) );
|
|
|
|
|
|
|
|
//// Determine edit type
|
|
|
|
// If There was a selection then edit was not a simple single character backspace, delete, or insert
|
|
|
|
if (m_prevCursorPos != m_prevAnchorPos)
|
|
|
|
{
|
2014-09-11 17:36:01 +00:00
|
|
|
qCDebug(OkularCoreDebug) << "OtherEdit, selection";
|
2013-04-05 22:39:35 +00:00
|
|
|
m_editType = OtherEdit;
|
|
|
|
}
|
|
|
|
else if ( newContentsRightOfCursor() == oldContentsRightOfCursor() &&
|
|
|
|
newContentsLeftOfCursor() == oldContentsLeftOfCursor().left(oldContentsLeftOfCursor().length() - 1) &&
|
2015-10-29 12:37:11 +00:00
|
|
|
oldContentsLeftOfCursor().right(1) != QLatin1String("\n") )
|
2013-04-05 22:39:35 +00:00
|
|
|
{
|
2014-09-11 17:36:01 +00:00
|
|
|
qCDebug(OkularCoreDebug) << "CharBackspace";
|
2013-04-05 22:39:35 +00:00
|
|
|
m_editType = CharBackspace;
|
|
|
|
}
|
|
|
|
else if ( newContentsLeftOfCursor() == oldContentsLeftOfCursor() &&
|
|
|
|
newContentsRightOfCursor() == oldContentsRightOfCursor().right(oldContentsRightOfCursor().length() - 1) &&
|
2015-10-29 12:37:11 +00:00
|
|
|
oldContentsRightOfCursor().left(1) != QLatin1String("\n") )
|
2013-04-05 22:39:35 +00:00
|
|
|
{
|
2014-09-11 17:36:01 +00:00
|
|
|
qCDebug(OkularCoreDebug) << "CharDelete";
|
2013-04-05 22:39:35 +00:00
|
|
|
m_editType = CharDelete;
|
|
|
|
}
|
|
|
|
else if ( newContentsRightOfCursor() == oldContentsRightOfCursor() &&
|
|
|
|
newContentsLeftOfCursor().left( newContentsLeftOfCursor().length() - 1) == oldContentsLeftOfCursor() &&
|
2015-10-29 12:37:11 +00:00
|
|
|
newContentsLeftOfCursor().right(1) != QLatin1String("\n") )
|
2013-04-05 22:39:35 +00:00
|
|
|
{
|
2014-09-11 17:36:01 +00:00
|
|
|
qCDebug(OkularCoreDebug) << "CharInsert";
|
2013-04-05 22:39:35 +00:00
|
|
|
m_editType = CharInsert;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-11 17:36:01 +00:00
|
|
|
qCDebug(OkularCoreDebug) << "OtherEdit";
|
2013-04-05 22:39:35 +00:00
|
|
|
m_editType = OtherEdit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditTextCommand::mergeWith(const QUndoCommand* uc)
|
|
|
|
{
|
|
|
|
EditTextCommand *euc = (EditTextCommand*)uc;
|
|
|
|
|
|
|
|
// Only attempt merge of euc into this if our new state matches euc's old state and
|
|
|
|
// the editTypes match and are not type OtherEdit
|
|
|
|
if ( m_newContents == euc->m_prevContents
|
|
|
|
&& m_newCursorPos == euc->m_prevCursorPos
|
|
|
|
&& m_editType == euc->m_editType
|
|
|
|
&& m_editType != OtherEdit )
|
|
|
|
{
|
|
|
|
m_newContents = euc->m_newContents;
|
|
|
|
m_newCursorPos = euc->m_newCursorPos;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString EditTextCommand::oldContentsLeftOfCursor()
|
|
|
|
{
|
|
|
|
return m_prevContents.left(m_prevCursorPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString EditTextCommand::oldContentsRightOfCursor()
|
|
|
|
{
|
|
|
|
return m_prevContents.right(m_prevContents.length() - m_prevCursorPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString EditTextCommand::newContentsLeftOfCursor()
|
|
|
|
{
|
|
|
|
return m_newContents.left(m_newCursorPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString EditTextCommand::newContentsRightOfCursor()
|
|
|
|
{
|
|
|
|
return m_newContents.right(m_newContents.length() - m_newCursorPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
EditAnnotationContentsCommand::EditAnnotationContentsCommand( DocumentPrivate* docPriv,
|
|
|
|
Annotation* annotation,
|
|
|
|
int pageNumber,
|
|
|
|
const QString & newContents,
|
|
|
|
int newCursorPos,
|
|
|
|
const QString & prevContents,
|
|
|
|
int prevCursorPos,
|
|
|
|
int prevAnchorPos )
|
|
|
|
: EditTextCommand( newContents, newCursorPos, prevContents, prevCursorPos, prevAnchorPos ),
|
|
|
|
m_docPriv( docPriv ),
|
|
|
|
m_annotation( annotation ),
|
|
|
|
m_pageNumber( pageNumber )
|
|
|
|
{
|
|
|
|
setText( i18nc( "Edit an annotation's text contents", "edit annotation contents" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditAnnotationContentsCommand::undo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_annotation->boundingRectangle(), m_docPriv, m_pageNumber );
|
2013-04-05 22:39:35 +00:00
|
|
|
m_docPriv->performSetAnnotationContents( m_prevContents, m_annotation, m_pageNumber );
|
|
|
|
emit m_docPriv->m_parent->annotationContentsChangedByUndoRedo( m_annotation, m_prevContents, m_prevCursorPos, m_prevAnchorPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditAnnotationContentsCommand::redo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_annotation->boundingRectangle(), m_docPriv, m_pageNumber );
|
2013-04-05 22:39:35 +00:00
|
|
|
m_docPriv->performSetAnnotationContents( m_newContents, m_annotation, m_pageNumber );
|
|
|
|
emit m_docPriv->m_parent->annotationContentsChangedByUndoRedo( m_annotation, m_newContents, m_newCursorPos, m_newCursorPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
int EditAnnotationContentsCommand::id() const
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditAnnotationContentsCommand::mergeWith(const QUndoCommand* uc)
|
|
|
|
{
|
|
|
|
EditAnnotationContentsCommand *euc = (EditAnnotationContentsCommand*)uc;
|
|
|
|
// Only attempt merge of euc into this if they modify the same annotation
|
|
|
|
if ( m_annotation == euc->m_annotation )
|
|
|
|
{
|
|
|
|
return EditTextCommand::mergeWith( uc );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-29 22:27:30 +00:00
|
|
|
EditFormTextCommand::EditFormTextCommand( Okular::DocumentPrivate* docPriv,
|
2013-06-03 20:46:41 +00:00
|
|
|
Okular::FormFieldText* form,
|
|
|
|
int pageNumber,
|
|
|
|
const QString & newContents,
|
|
|
|
int newCursorPos,
|
|
|
|
const QString & prevContents,
|
|
|
|
int prevCursorPos,
|
|
|
|
int prevAnchorPos )
|
|
|
|
: EditTextCommand( newContents, newCursorPos, prevContents, prevCursorPos, prevAnchorPos ),
|
2013-12-29 22:27:30 +00:00
|
|
|
m_docPriv ( docPriv ),
|
2013-06-03 20:46:41 +00:00
|
|
|
m_form( form ),
|
|
|
|
m_pageNumber( pageNumber )
|
|
|
|
{
|
|
|
|
setText( i18nc( "Edit an form's text contents", "edit form contents" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditFormTextCommand::undo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_form->rect(), m_docPriv, m_pageNumber );
|
2013-06-03 20:46:41 +00:00
|
|
|
m_form->setText( m_prevContents );
|
2014-05-11 11:45:34 +00:00
|
|
|
emit m_docPriv->m_parent->formTextChangedByUndoRedo( m_pageNumber, m_form, m_prevContents, m_prevCursorPos, m_prevAnchorPos );
|
2013-06-03 20:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditFormTextCommand::redo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_form->rect(), m_docPriv, m_pageNumber );
|
2013-06-03 20:46:41 +00:00
|
|
|
m_form->setText( m_newContents );
|
2014-05-11 11:45:34 +00:00
|
|
|
emit m_docPriv->m_parent->formTextChangedByUndoRedo( m_pageNumber, m_form, m_newContents, m_newCursorPos, m_newCursorPos );
|
2013-06-03 20:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int EditFormTextCommand::id() const
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditFormTextCommand::mergeWith(const QUndoCommand* uc)
|
|
|
|
{
|
|
|
|
EditFormTextCommand *euc = (EditFormTextCommand*)uc;
|
|
|
|
// Only attempt merge of euc into this if they modify the same form
|
|
|
|
if ( m_form == euc->m_form )
|
|
|
|
{
|
|
|
|
return EditTextCommand::mergeWith( uc );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-29 22:27:30 +00:00
|
|
|
EditFormListCommand::EditFormListCommand( Okular::DocumentPrivate* docPriv,
|
2013-06-03 20:46:41 +00:00
|
|
|
FormFieldChoice* form,
|
|
|
|
int pageNumber,
|
|
|
|
const QList< int > & newChoices,
|
|
|
|
const QList< int > & prevChoices )
|
2013-12-29 22:27:30 +00:00
|
|
|
: m_docPriv( docPriv ),
|
2013-06-03 20:46:41 +00:00
|
|
|
m_form( form ),
|
|
|
|
m_pageNumber( pageNumber ),
|
|
|
|
m_newChoices( newChoices ),
|
|
|
|
m_prevChoices( prevChoices )
|
|
|
|
{
|
|
|
|
setText( i18nc( "Edit a list form's choices", "edit list form choices" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditFormListCommand::undo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_form->rect(), m_docPriv, m_pageNumber );
|
2013-06-03 20:46:41 +00:00
|
|
|
m_form->setCurrentChoices( m_prevChoices );
|
2014-05-11 11:45:34 +00:00
|
|
|
emit m_docPriv->m_parent->formListChangedByUndoRedo( m_pageNumber, m_form, m_prevChoices );
|
2013-06-03 20:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditFormListCommand::redo()
|
|
|
|
{
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_form->rect(), m_docPriv, m_pageNumber );
|
2013-06-03 20:46:41 +00:00
|
|
|
m_form->setCurrentChoices( m_newChoices );
|
2014-05-11 11:45:34 +00:00
|
|
|
emit m_docPriv->m_parent->formListChangedByUndoRedo( m_pageNumber, m_form, m_newChoices );
|
2013-06-03 20:46:41 +00:00
|
|
|
}
|
|
|
|
|
2013-12-29 22:27:30 +00:00
|
|
|
EditFormComboCommand::EditFormComboCommand( Okular::DocumentPrivate* docPriv,
|
2013-06-03 20:46:41 +00:00
|
|
|
FormFieldChoice* form,
|
|
|
|
int pageNumber,
|
|
|
|
const QString & newContents,
|
|
|
|
int newCursorPos,
|
|
|
|
const QString & prevContents,
|
|
|
|
int prevCursorPos,
|
|
|
|
int prevAnchorPos )
|
|
|
|
: EditTextCommand( newContents, newCursorPos, prevContents, prevCursorPos, prevAnchorPos ),
|
2013-12-29 22:27:30 +00:00
|
|
|
m_docPriv( docPriv ),
|
2013-06-03 20:46:41 +00:00
|
|
|
m_form( form ),
|
|
|
|
m_pageNumber( pageNumber ),
|
|
|
|
m_newIndex( -1 ),
|
|
|
|
m_prevIndex( -1 )
|
|
|
|
{
|
|
|
|
setText( i18nc( "Edit a combo form's selection", "edit combo form selection" ) );
|
|
|
|
|
|
|
|
// Determine new and previous choice indices (if any)
|
|
|
|
for ( int i = 0; i < m_form->choices().size(); i++ )
|
|
|
|
{
|
|
|
|
if ( m_form->choices()[i] == m_prevContents )
|
|
|
|
{
|
|
|
|
m_prevIndex = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_form->choices()[i] == m_newContents )
|
|
|
|
{
|
|
|
|
m_newIndex = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditFormComboCommand::undo()
|
|
|
|
{
|
|
|
|
if ( m_prevIndex != -1 )
|
|
|
|
{
|
|
|
|
m_form->setCurrentChoices( QList<int>() << m_prevIndex );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_form->setEditChoice( m_prevContents );
|
|
|
|
}
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_form->rect(), m_docPriv, m_pageNumber );
|
2014-05-11 11:45:34 +00:00
|
|
|
emit m_docPriv->m_parent->formComboChangedByUndoRedo( m_pageNumber, m_form, m_prevContents, m_prevCursorPos, m_prevAnchorPos );
|
2013-06-03 20:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditFormComboCommand::redo()
|
|
|
|
{
|
|
|
|
if ( m_newIndex != -1 )
|
|
|
|
{
|
|
|
|
m_form->setCurrentChoices( QList<int>() << m_newIndex );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_form->setEditChoice( m_newContents );
|
|
|
|
}
|
2013-12-29 22:27:30 +00:00
|
|
|
moveViewportIfBoundingRectNotFullyVisible( m_form->rect(), m_docPriv, m_pageNumber );
|
2014-05-11 11:45:34 +00:00
|
|
|
emit m_docPriv->m_parent->formComboChangedByUndoRedo( m_pageNumber, m_form, m_newContents, m_newCursorPos, m_newCursorPos );
|
2013-06-03 20:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int EditFormComboCommand::id() const
|
|
|
|
{
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditFormComboCommand::mergeWith( const QUndoCommand *uc )
|
|
|
|
{
|
|
|
|
EditFormComboCommand *euc = (EditFormComboCommand*)uc;
|
|
|
|
// Only attempt merge of euc into this if they modify the same form
|
|
|
|
if ( m_form == euc->m_form )
|
|
|
|
{
|
|
|
|
bool shouldMerge = EditTextCommand::mergeWith( uc );
|
|
|
|
if( shouldMerge )
|
|
|
|
{
|
|
|
|
m_newIndex = euc->m_newIndex;
|
|
|
|
}
|
|
|
|
return shouldMerge;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-29 22:27:30 +00:00
|
|
|
EditFormButtonsCommand::EditFormButtonsCommand( Okular::DocumentPrivate* docPriv,
|
2013-06-03 20:46:41 +00:00
|
|
|
int pageNumber,
|
|
|
|
const QList< FormFieldButton* > & formButtons,
|
|
|
|
const QList< bool > & newButtonStates )
|
2013-12-29 22:27:30 +00:00
|
|
|
: m_docPriv( docPriv ),
|
2013-06-03 20:46:41 +00:00
|
|
|
m_pageNumber( pageNumber ),
|
|
|
|
m_formButtons( formButtons ),
|
|
|
|
m_newButtonStates( newButtonStates ),
|
|
|
|
m_prevButtonStates( QList< bool >() )
|
|
|
|
{
|
|
|
|
setText( i18nc( "Edit the state of a group of form buttons", "edit form button states" ) );
|
|
|
|
foreach( FormFieldButton* formButton, m_formButtons )
|
|
|
|
{
|
|
|
|
m_prevButtonStates.append( formButton->state() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditFormButtonsCommand::undo()
|
|
|
|
{
|
|
|
|
clearFormButtonStates();
|
|
|
|
for( int i = 0; i < m_formButtons.size(); i++ )
|
|
|
|
{
|
|
|
|
bool checked = m_prevButtonStates.at( i );
|
|
|
|
if ( checked )
|
|
|
|
m_formButtons.at( i )->setState( checked );
|
|
|
|
}
|
2013-12-29 22:27:30 +00:00
|
|
|
|
|
|
|
Okular::NormalizedRect boundingRect = buildBoundingRectangleForButtons( m_formButtons );
|
|
|
|
moveViewportIfBoundingRectNotFullyVisible( boundingRect, m_docPriv, m_pageNumber );
|
2014-05-11 11:45:34 +00:00
|
|
|
emit m_docPriv->m_parent->formButtonsChangedByUndoRedo( m_pageNumber, m_formButtons );
|
2013-06-03 20:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditFormButtonsCommand::redo()
|
|
|
|
{
|
|
|
|
clearFormButtonStates();
|
|
|
|
for( int i = 0; i < m_formButtons.size(); i++ )
|
|
|
|
{
|
|
|
|
bool checked = m_newButtonStates.at( i );
|
|
|
|
if ( checked )
|
|
|
|
m_formButtons.at( i )->setState( checked );
|
|
|
|
}
|
2013-12-29 22:27:30 +00:00
|
|
|
|
|
|
|
Okular::NormalizedRect boundingRect = buildBoundingRectangleForButtons( m_formButtons );
|
|
|
|
moveViewportIfBoundingRectNotFullyVisible( boundingRect, m_docPriv, m_pageNumber );
|
2014-05-11 11:45:34 +00:00
|
|
|
emit m_docPriv->m_parent->formButtonsChangedByUndoRedo( m_pageNumber, m_formButtons );
|
2013-06-03 20:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditFormButtonsCommand::clearFormButtonStates()
|
|
|
|
{
|
|
|
|
foreach( FormFieldButton* formButton, m_formButtons )
|
|
|
|
{
|
|
|
|
formButton->setState( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-05 22:39:35 +00:00
|
|
|
}
|
|
|
|
|