2013-04-05 22:39:35 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2013 Jon Mease <jon.mease@gmail.com> *
|
2017-11-16 08:57:58 +00:00
|
|
|
* 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_
|
|
|
|
|
2014-08-07 23:35:27 +00:00
|
|
|
#include <QtWidgets/QUndoCommand>
|
2013-04-05 22:39:35 +00:00
|
|
|
#include <QDomNode>
|
|
|
|
|
|
|
|
#include "area.h"
|
|
|
|
|
|
|
|
namespace Okular {
|
|
|
|
|
2013-06-03 20:46:41 +00:00
|
|
|
class Document;
|
2013-04-05 22:39:35 +00:00
|
|
|
class Annotation;
|
|
|
|
class DocumentPrivate;
|
2013-06-03 20:46:41 +00:00
|
|
|
class FormFieldText;
|
|
|
|
class FormFieldButton;
|
|
|
|
class FormFieldChoice;
|
2017-10-26 07:47:18 +00:00
|
|
|
class Page;
|
2013-04-05 22:39:35 +00:00
|
|
|
|
2017-10-26 07:47:18 +00:00
|
|
|
class OkularUndoCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
public:
|
2017-11-14 08:57:38 +00:00
|
|
|
virtual bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) = 0;
|
2017-10-26 07:47:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-11-14 08:57:38 +00:00
|
|
|
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
|
2017-10-26 07:47:18 +00:00
|
|
|
|
2013-04-05 22:39:35 +00:00
|
|
|
private:
|
|
|
|
Okular::DocumentPrivate * m_docPriv;
|
|
|
|
Okular::Annotation* m_annotation;
|
|
|
|
int m_pageNumber;
|
|
|
|
bool m_done;
|
|
|
|
};
|
|
|
|
|
2017-10-26 07:47:18 +00:00
|
|
|
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
|
|
|
|
2017-11-14 08:57:38 +00:00
|
|
|
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
|
2017-10-26 07:47:18 +00:00
|
|
|
|
2013-04-05 22:39:35 +00:00
|
|
|
private:
|
2013-12-29 22:27:30 +00:00
|
|
|
Okular::DocumentPrivate * m_docPriv;
|
2013-04-05 22:39:35 +00:00
|
|
|
Okular::Annotation* m_annotation;
|
|
|
|
int m_pageNumber;
|
|
|
|
bool m_done;
|
|
|
|
};
|
|
|
|
|
2017-10-26 07:47:18 +00:00
|
|
|
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
|
|
|
|
2017-11-14 08:57:38 +00:00
|
|
|
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
|
2017-10-26 07:47:18 +00:00
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2017-10-26 07:47:18 +00:00
|
|
|
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();
|
2013-12-29 22:27:30 +00:00
|
|
|
Okular::NormalizedRect translateBoundingRectangle( const Okular::NormalizedPoint & delta );
|
2013-04-05 22:39:35 +00:00
|
|
|
|
2017-11-14 08:57:38 +00:00
|
|
|
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
|
2017-10-26 07:47:18 +00:00
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2017-10-26 07:47:18 +00:00
|
|
|
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 );
|
|
|
|
|
2017-11-14 08:57:38 +00:00
|
|
|
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
|
2017-10-26 07:47:18 +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
|
|
|
private:
|
|
|
|
Okular::DocumentPrivate * m_docPriv;
|
|
|
|
Okular::Annotation* m_annotation;
|
|
|
|
int m_pageNumber;
|
|
|
|
Okular::NormalizedPoint m_delta1;
|
|
|
|
Okular::NormalizedPoint m_delta2;
|
|
|
|
bool m_completeDrag;
|
|
|
|
};
|
|
|
|
|
2017-10-26 07:47:18 +00:00
|
|
|
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
|
|
|
|
2017-11-14 08:57:38 +00:00
|
|
|
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
|
2017-10-26 07:47:18 +00:00
|
|
|
|
2013-04-05 22:39:35 +00:00
|
|
|
private:
|
|
|
|
Okular::DocumentPrivate * m_docPriv;
|
|
|
|
Okular::Annotation* m_annotation;
|
|
|
|
int m_pageNumber;
|
|
|
|
};
|
|
|
|
|
2013-06-03 20:46:41 +00:00
|
|
|
class EditFormTextCommand : public EditTextCommand
|
|
|
|
{
|
|
|
|
public:
|
2013-12-29 22:27:30 +00:00
|
|
|
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 );
|
2017-03-02 19:38:50 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
int id() const override;
|
|
|
|
bool mergeWith( const QUndoCommand *uc ) override;
|
2017-10-26 07:47:18 +00:00
|
|
|
|
2017-11-14 08:57:38 +00:00
|
|
|
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
|
2017-10-26 07:47:18 +00:00
|
|
|
|
2013-06-03 20:46:41 +00:00
|
|
|
private:
|
2013-12-29 22:27:30 +00:00
|
|
|
Okular::DocumentPrivate* m_docPriv;
|
2013-06-03 20:46:41 +00:00
|
|
|
Okular::FormFieldText* m_form;
|
|
|
|
int m_pageNumber;
|
|
|
|
};
|
|
|
|
|
2017-10-26 07:47:18 +00:00
|
|
|
class EditFormListCommand : public OkularUndoCommand
|
2013-06-03 20:46:41 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-12-29 22:27:30 +00:00
|
|
|
EditFormListCommand( Okular::DocumentPrivate* docPriv,
|
2013-06-03 20:46:41 +00:00
|
|
|
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;
|
2013-06-03 20:46:41 +00:00
|
|
|
|
2017-11-14 08:57:38 +00:00
|
|
|
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
|
2017-10-26 07:47:18 +00:00
|
|
|
|
2013-06-03 20:46:41 +00:00
|
|
|
private:
|
2013-12-29 22:27:30 +00:00
|
|
|
Okular::DocumentPrivate* m_docPriv;
|
2013-06-03 20:46:41 +00:00
|
|
|
FormFieldChoice* m_form;
|
|
|
|
int m_pageNumber;
|
|
|
|
QList< int > m_newChoices;
|
|
|
|
QList< int > m_prevChoices;
|
|
|
|
};
|
|
|
|
|
|
|
|
class EditFormComboCommand : public EditTextCommand
|
|
|
|
{
|
|
|
|
public:
|
2013-12-29 22:27:30 +00:00
|
|
|
EditFormComboCommand( Okular::DocumentPrivate* docPriv,
|
2013-06-03 20:46:41 +00:00
|
|
|
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;
|
2013-06-03 20:46:41 +00:00
|
|
|
|
2017-11-14 08:57:38 +00:00
|
|
|
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
|
2017-10-26 07:47:18 +00:00
|
|
|
|
2013-06-03 20:46:41 +00:00
|
|
|
private:
|
2013-12-29 22:27:30 +00:00
|
|
|
Okular::DocumentPrivate* m_docPriv;
|
2013-06-03 20:46:41 +00:00
|
|
|
FormFieldChoice* m_form;
|
|
|
|
int m_pageNumber;
|
|
|
|
int m_newIndex;
|
|
|
|
int m_prevIndex;
|
|
|
|
};
|
|
|
|
|
2017-10-26 07:47:18 +00:00
|
|
|
class EditFormButtonsCommand : public OkularUndoCommand
|
2013-06-03 20:46:41 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-12-29 22:27:30 +00:00
|
|
|
EditFormButtonsCommand( Okular::DocumentPrivate* docPriv,
|
2013-06-03 20:46:41 +00:00
|
|
|
int pageNumber,
|
|
|
|
const QList< FormFieldButton* > & formButtons,
|
|
|
|
const QList< bool > & newButtonStates
|
|
|
|
);
|
|
|
|
|
2017-03-02 19:38:50 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2013-06-03 20:46:41 +00:00
|
|
|
|
2017-11-14 08:57:38 +00:00
|
|
|
bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
|
2017-10-26 07:47:18 +00:00
|
|
|
|
2013-06-03 20:46:41 +00:00
|
|
|
private:
|
|
|
|
void clearFormButtonStates();
|
|
|
|
|
|
|
|
private:
|
2013-12-29 22:27:30 +00:00
|
|
|
Okular::DocumentPrivate* m_docPriv;
|
2013-06-03 20:46:41 +00:00
|
|
|
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; */
|