okular/core/documentcommands_p.h

317 lines
11 KiB
C
Raw Normal View History

2013-04-05 22:39:35 +00:00
/***************************************************************************
* Copyright (C) 2013 Jon Mease <jon.mease@gmail.com> *
* Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group *
* company, info@kdab.com. Work sponsored by the *
* LiMux project of the city of Munich *
2013-04-05 22:39:35 +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. *
***************************************************************************/
#ifndef _OKULAR_DOCUMENT_COMMANDS_P_H_
#define _OKULAR_DOCUMENT_COMMANDS_P_H_
2018-08-31 09:23:45 +00:00
#include <QUndoCommand>
2013-04-05 22:39:35 +00:00
#include <QDomNode>
#include "area.h"
namespace Okular {
class Document;
2013-04-05 22:39:35 +00:00
class Annotation;
class DocumentPrivate;
class FormFieldText;
class FormFieldButton;
class FormFieldChoice;
class Page;
2013-04-05 22:39:35 +00:00
class OkularUndoCommand : public QUndoCommand
{
public:
virtual bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) = 0;
};
class AddAnnotationCommand : public OkularUndoCommand
2013-04-05 22:39:35 +00:00
{
public:
AddAnnotationCommand(Okular::DocumentPrivate * docPriv, Okular::Annotation* annotation, int pageNumber);
virtual ~AddAnnotationCommand();
2017-03-02 19:38:50 +00:00
void undo() override;
2013-04-05 22:39:35 +00:00
2017-03-02 19:38:50 +00:00
void redo() override;
2013-04-05 22:39:35 +00:00
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
2013-04-05 22:39:35 +00:00
private:
Okular::DocumentPrivate * m_docPriv;
Okular::Annotation* m_annotation;
int m_pageNumber;
bool m_done;
};
class RemoveAnnotationCommand : public OkularUndoCommand
2013-04-05 22:39:35 +00:00
{
public:
RemoveAnnotationCommand(Okular::DocumentPrivate * doc, Okular::Annotation* annotation, int pageNumber);
virtual ~RemoveAnnotationCommand();
2017-03-02 19:38:50 +00:00
void undo() override;
void redo() override;
2013-04-05 22:39:35 +00:00
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
2013-04-05 22:39:35 +00:00
private:
Okular::DocumentPrivate * m_docPriv;
2013-04-05 22:39:35 +00:00
Okular::Annotation* m_annotation;
int m_pageNumber;
bool m_done;
};
class ModifyAnnotationPropertiesCommand : public OkularUndoCommand
2013-04-05 22:39:35 +00:00
{
public:
ModifyAnnotationPropertiesCommand( Okular::DocumentPrivate* docPriv, Okular::Annotation* annotation,
int pageNumber,
QDomNode oldProperties,
QDomNode newProperties );
2017-03-02 19:38:50 +00:00
void undo() override;
void redo() override;
2013-04-05 22:39:35 +00:00
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
2013-04-05 22:39:35 +00:00
private:
Okular::DocumentPrivate * m_docPriv;
Okular::Annotation* m_annotation;
int m_pageNumber;
QDomNode m_prevProperties;
QDomNode m_newProperties;
};
class TranslateAnnotationCommand : public OkularUndoCommand
2013-04-05 22:39:35 +00:00
{
public:
TranslateAnnotationCommand(Okular::DocumentPrivate* docPriv,
Okular::Annotation* annotation,
int pageNumber,
const Okular::NormalizedPoint & delta,
bool completeDrag
);
2017-03-02 19:38:50 +00:00
void undo() override;
void redo() override;
int id() const override;
bool mergeWith(const QUndoCommand *uc) override;
2013-04-05 22:39:35 +00:00
Okular::NormalizedPoint minusDelta();
Okular::NormalizedRect translateBoundingRectangle( const Okular::NormalizedPoint & delta );
2013-04-05 22:39:35 +00:00
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
2013-04-05 22:39:35 +00:00
private:
Okular::DocumentPrivate * m_docPriv;
Okular::Annotation* m_annotation;
int m_pageNumber;
Okular::NormalizedPoint m_delta;
bool m_completeDrag;
};
class AdjustAnnotationCommand : public OkularUndoCommand
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
{
public:
AdjustAnnotationCommand(Okular::DocumentPrivate * docPriv,
Okular::Annotation * annotation,
int pageNumber,
const Okular::NormalizedPoint & delta1,
const Okular::NormalizedPoint & delta2,
bool completeDrag
);
void undo() override;
void redo() override;
int id() const override;
bool mergeWith(const QUndoCommand * uc) override;
Okular::NormalizedRect adjustBoundingRectangle(
const Okular::NormalizedPoint & delta1, const Okular::NormalizedPoint & delta2 );
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
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
private:
Okular::DocumentPrivate * m_docPriv;
Okular::Annotation* m_annotation;
int m_pageNumber;
Okular::NormalizedPoint m_delta1;
Okular::NormalizedPoint m_delta2;
bool m_completeDrag;
};
class EditTextCommand : public OkularUndoCommand
2013-04-05 22:39:35 +00:00
{
public:
EditTextCommand( const QString & newContents,
int newCursorPos,
const QString & prevContents,
int prevCursorPos,
int prevAnchorPos
);
2017-03-02 19:38:50 +00:00
void undo() override = 0;
void redo() override = 0;
int id() const override = 0;
bool mergeWith(const QUndoCommand *uc) override;
2013-04-05 22:39:35 +00:00
private:
enum EditType {
CharBackspace, ///< Edit made up of one or more single character backspace operations
CharDelete, ///< Edit made up of one or more single character delete operations
CharInsert, ///< Edit made up of one or more single character insertion operations
OtherEdit ///< All other edit operations (these will not be merged together)
};
QString oldContentsLeftOfCursor();
QString newContentsLeftOfCursor();
QString oldContentsRightOfCursor();
QString newContentsRightOfCursor();
protected:
QString m_newContents;
int m_newCursorPos;
QString m_prevContents;
int m_prevCursorPos;
int m_prevAnchorPos;
EditType m_editType;
};
class EditAnnotationContentsCommand : public EditTextCommand
{
public:
EditAnnotationContentsCommand(Okular::DocumentPrivate* docPriv,
Okular::Annotation* annotation,
int pageNumber,
const QString & newContents,
int newCursorPos,
const QString & prevContents,
int prevCursorPos,
int prevAnchorPos
);
2017-03-02 19:38:50 +00:00
void undo() override;
void redo() override;
int id() const override;
bool mergeWith(const QUndoCommand *uc) override;
2013-04-05 22:39:35 +00:00
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
2013-04-05 22:39:35 +00:00
private:
Okular::DocumentPrivate * m_docPriv;
Okular::Annotation* m_annotation;
int m_pageNumber;
};
class EditFormTextCommand : public EditTextCommand
{
public:
EditFormTextCommand( Okular::DocumentPrivate* docPriv,
Okular::FormFieldText* form,
int pageNumber,
const QString & newContents,
int newCursorPos,
const QString & prevContents,
int prevCursorPos,
int prevAnchorPos );
2017-03-02 19:38:50 +00:00
void undo() override;
void redo() override;
int id() const override;
bool mergeWith( const QUndoCommand *uc ) override;
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
Okular::DocumentPrivate* m_docPriv;
Okular::FormFieldText* m_form;
int m_pageNumber;
};
class EditFormListCommand : public OkularUndoCommand
{
public:
EditFormListCommand( Okular::DocumentPrivate* docPriv,
FormFieldChoice* form,
int pageNumber,
const QList< int > & newChoices,
const QList< int > & prevChoices
);
2017-03-02 19:38:50 +00:00
void undo() override;
void redo() override;
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
Okular::DocumentPrivate* m_docPriv;
FormFieldChoice* m_form;
int m_pageNumber;
QList< int > m_newChoices;
QList< int > m_prevChoices;
};
class EditFormComboCommand : public EditTextCommand
{
public:
EditFormComboCommand( Okular::DocumentPrivate* docPriv,
FormFieldChoice* form,
int pageNumber,
const QString & newText,
int newCursorPos,
const QString & prevText,
int prevCursorPos,
int prevAnchorPos
);
2013-04-05 22:39:35 +00:00
2017-03-02 19:38:50 +00:00
void undo() override;
void redo() override;
int id() const override;
bool mergeWith( const QUndoCommand *uc ) override;
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
Okular::DocumentPrivate* m_docPriv;
FormFieldChoice* m_form;
int m_pageNumber;
int m_newIndex;
int m_prevIndex;
};
class EditFormButtonsCommand : public OkularUndoCommand
{
public:
EditFormButtonsCommand( Okular::DocumentPrivate* docPriv,
int pageNumber,
const QList< FormFieldButton* > & formButtons,
const QList< bool > & newButtonStates
);
2017-03-02 19:38:50 +00:00
void undo() override;
void redo() override;
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
void clearFormButtonStates();
private:
Okular::DocumentPrivate* m_docPriv;
int m_pageNumber;
QList< FormFieldButton* > m_formButtons;
QList< bool > m_newButtonStates;
QList< bool > m_prevButtonStates;
};
}
2013-04-05 22:39:35 +00:00
#endif
/* kate: replace-tabs on; indent-width 4; */