okular/core/documentcommands_p.h
Tobias Deiminger 0957abc39a 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 23:18:17 +01:00

286 lines
9.4 KiB
C++

/***************************************************************************
* 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. *
***************************************************************************/
#ifndef _OKULAR_DOCUMENT_COMMANDS_P_H_
#define _OKULAR_DOCUMENT_COMMANDS_P_H_
#include <QtWidgets/QUndoCommand>
#include <QDomNode>
#include "area.h"
namespace Okular {
class Document;
class Annotation;
class DocumentPrivate;
class FormFieldText;
class FormFieldButton;
class FormFieldChoice;
class AddAnnotationCommand : public QUndoCommand
{
public:
AddAnnotationCommand(Okular::DocumentPrivate * docPriv, Okular::Annotation* annotation, int pageNumber);
virtual ~AddAnnotationCommand();
void undo() override;
void redo() override;
private:
Okular::DocumentPrivate * m_docPriv;
Okular::Annotation* m_annotation;
int m_pageNumber;
bool m_done;
};
class RemoveAnnotationCommand : public QUndoCommand
{
public:
RemoveAnnotationCommand(Okular::DocumentPrivate * doc, Okular::Annotation* annotation, int pageNumber);
virtual ~RemoveAnnotationCommand();
void undo() override;
void redo() override;
private:
Okular::DocumentPrivate * m_docPriv;
Okular::Annotation* m_annotation;
int m_pageNumber;
bool m_done;
};
class ModifyAnnotationPropertiesCommand : public QUndoCommand
{
public:
ModifyAnnotationPropertiesCommand( Okular::DocumentPrivate* docPriv, Okular::Annotation* annotation,
int pageNumber,
QDomNode oldProperties,
QDomNode newProperties );
void undo() override;
void redo() override;
private:
Okular::DocumentPrivate * m_docPriv;
Okular::Annotation* m_annotation;
int m_pageNumber;
QDomNode m_prevProperties;
QDomNode m_newProperties;
};
class TranslateAnnotationCommand : public QUndoCommand
{
public:
TranslateAnnotationCommand(Okular::DocumentPrivate* docPriv,
Okular::Annotation* annotation,
int pageNumber,
const Okular::NormalizedPoint & delta,
bool completeDrag
);
void undo() override;
void redo() override;
int id() const override;
bool mergeWith(const QUndoCommand *uc) override;
Okular::NormalizedPoint minusDelta();
Okular::NormalizedRect translateBoundingRectangle( const Okular::NormalizedPoint & delta );
private:
Okular::DocumentPrivate * m_docPriv;
Okular::Annotation* m_annotation;
int m_pageNumber;
Okular::NormalizedPoint m_delta;
bool m_completeDrag;
};
class AdjustAnnotationCommand : public QUndoCommand
{
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 );
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 QUndoCommand
{
public:
EditTextCommand( const QString & newContents,
int newCursorPos,
const QString & prevContents,
int prevCursorPos,
int prevAnchorPos
);
void undo() override = 0;
void redo() override = 0;
int id() const override = 0;
bool mergeWith(const QUndoCommand *uc) override;
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
);
void undo() override;
void redo() override;
int id() const override;
bool mergeWith(const QUndoCommand *uc) override;
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 );
void undo() override;
void redo() override;
int id() const override;
bool mergeWith( const QUndoCommand *uc ) override;
private:
Okular::DocumentPrivate* m_docPriv;
Okular::FormFieldText* m_form;
int m_pageNumber;
};
class EditFormListCommand : public QUndoCommand
{
public:
EditFormListCommand( Okular::DocumentPrivate* docPriv,
FormFieldChoice* form,
int pageNumber,
const QList< int > & newChoices,
const QList< int > & prevChoices
);
void undo() override;
void redo() 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
);
void undo() override;
void redo() override;
int id() const override;
bool mergeWith( const QUndoCommand *uc ) override;
private:
Okular::DocumentPrivate* m_docPriv;
FormFieldChoice* m_form;
int m_pageNumber;
int m_newIndex;
int m_prevIndex;
};
class EditFormButtonsCommand : public QUndoCommand
{
public:
EditFormButtonsCommand( Okular::DocumentPrivate* docPriv,
int pageNumber,
const QList< FormFieldButton* > & formButtons,
const QList< bool > & newButtonStates
);
void undo() override;
void redo() override;
private:
void clearFormButtonStates();
private:
Okular::DocumentPrivate* m_docPriv;
int m_pageNumber;
QList< FormFieldButton* > m_formButtons;
QList< bool > m_newButtonStates;
QList< bool > m_prevButtonStates;
};
}
#endif
/* kate: replace-tabs on; indent-width 4; */