Changeset View
Changeset View
Standalone View
Standalone View
ui/pageviewannotator.h
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2005 by Enrico Ros <eros.kde@email.it> * | 2 | * Copyright (C) 2005 by Enrico Ros <eros.kde@email.it> * | ||
3 | * * | 3 | * * | ||
4 | * This program is free software; you can redistribute it and/or modify * | 4 | * This program is free software; you can redistribute it and/or modify * | ||
5 | * it under the terms of the GNU General Public License as published by * | 5 | * it under the terms of the GNU General Public License as published by * | ||
6 | * the Free Software Foundation; either version 2 of the License, or * | 6 | * the Free Software Foundation; either version 2 of the License, or * | ||
7 | * (at your option) any later version. * | 7 | * (at your option) any later version. * | ||
8 | ***************************************************************************/ | 8 | ***************************************************************************/ | ||
9 | 9 | | |||
10 | #ifndef _OKULAR_PAGEVIEWANNOTATOR_H_ | 10 | #ifndef _OKULAR_PAGEVIEWANNOTATOR_H_ | ||
11 | #define _OKULAR_PAGEVIEWANNOTATOR_H_ | 11 | #define _OKULAR_PAGEVIEWANNOTATOR_H_ | ||
12 | 12 | | |||
13 | #include <qobject.h> | 13 | #include <qobject.h> | ||
14 | #include <qdom.h> | 14 | #include <qdom.h> | ||
15 | #include <qlinkedlist.h> | 15 | #include <qlinkedlist.h> | ||
16 | 16 | | |||
17 | #include <kactioncollection.h> | ||||
18 | | ||||
17 | #include "pageviewutils.h" | 19 | #include "pageviewutils.h" | ||
18 | #include "annotationtools.h" | 20 | #include "annotationtools.h" | ||
19 | 21 | | |||
20 | class QKeyEvent; | 22 | class QKeyEvent; | ||
21 | class QMouseEvent; | 23 | class QMouseEvent; | ||
22 | class QPainter; | 24 | class QPainter; | ||
25 | class AnnotationActionHandler; | ||||
23 | 26 | | |||
24 | namespace Okular | 27 | namespace Okular | ||
25 | { | 28 | { | ||
26 | class Document; | 29 | class Document; | ||
27 | } | 30 | } | ||
28 | 31 | | |||
29 | // engines are defined and implemented in the cpp | 32 | // engines are defined and implemented in the cpp | ||
30 | class AnnotatorEngine; | 33 | class AnnotatorEngine; | ||
34 | class AnnotationTools; | ||||
31 | class PageView; | 35 | class PageView; | ||
32 | 36 | | |||
33 | /** | 37 | /** | ||
34 | * @short PageView object devoted to annotation creation/handling. | 38 | * @short PageView object devoted to annotation creation/handling. | ||
35 | * | 39 | * | ||
36 | * PageViewAnnotator is the okular class used for visually creating annotations. | 40 | * PageViewAnnotator is the okular class used for visually creating annotations. | ||
37 | * It uses internal 'engines' for interacting with user events and attaches | 41 | * It uses internal 'engines' for interacting with user events and attaches | ||
38 | * the newly created annotation to the document when the creation is complete. | 42 | * the newly created annotation to the document when the creation is complete. | ||
39 | * In the meanwhile all PageView events (actually mouse/paint ones) are routed | 43 | * In the meanwhile all PageView events (actually mouse/paint ones) are routed | ||
40 | * to this class that performs a rough visual representation of what the | 44 | * to this class that performs a rough visual representation of what the | ||
41 | * annotation will become when finished. | 45 | * annotation will become when finished. | ||
42 | * | 46 | * | ||
43 | * m_toolsDefinition is a DOM object that contains Annotations/Engine association | 47 | * m_toolsDefinition is a AnnotationTools object that wraps a DOM object that | ||
44 | * for the items placed in the toolbar. The XML is parsed (1) when populating | 48 | * contains Annotations/Engine association for the items placed in the toolbar. | ||
45 | * the toolbar and (2)after selecting a toolbar item, in which case an Ann is | 49 | * The XML is parsed after selecting a toolbar item, in which case an Ann is | ||
46 | * initialized with the values in the XML and an engine is created to handle | 50 | * initialized with the values in the XML and an engine is created to handle | ||
47 | * that annotation. m_toolsDefinition is created in reparseConfig according to | 51 | * that annotation. m_toolsDefinition is created in reparseConfig according to | ||
48 | * user configuration. | 52 | * user configuration. m_toolsDefinition is updated (and saved to disk) (1) each | ||
53 | * time a property of an annotation (color, font, etc) is changed by the user, | ||||
54 | * and (2) each time a "quick annotation" is selected, in which case the properties | ||||
55 | * of the selected quick annotation are written over those of the corresponding | ||||
56 | * builtin tool | ||||
49 | */ | 57 | */ | ||
50 | class PageViewAnnotator : public QObject | 58 | class PageViewAnnotator : public QObject | ||
51 | { | 59 | { | ||
52 | Q_OBJECT | 60 | Q_OBJECT | ||
53 | public: | 61 | public: | ||
62 | static const int STAMP_TOOL_ID; | ||||
63 | | ||||
54 | PageViewAnnotator( PageView * parent, Okular::Document * storage ); | 64 | PageViewAnnotator( PageView * parent, Okular::Document * storage ); | ||
55 | ~PageViewAnnotator(); | 65 | ~PageViewAnnotator(); | ||
56 | 66 | | |||
57 | // called to show/hide the editing toolbar | | |||
58 | void setEnabled( bool enabled ); | | |||
59 | | ||||
60 | // called to toggle the usage of text annotating tools | | |||
61 | void setTextToolsEnabled( bool enabled ); | | |||
62 | | ||||
63 | void setToolsEnabled( bool enabled ); | | |||
64 | | ||||
65 | void setHidingForced( bool forced ); | | |||
66 | bool hidingWasForced() const; | | |||
67 | | ||||
68 | // methods used when creating the annotation | 67 | // methods used when creating the annotation | ||
69 | // @return Is a tool currently selected? | 68 | // @return Is a tool currently selected? | ||
70 | bool active() const; | 69 | bool active() const; | ||
71 | // @return Are we currently annotating (using the selected tool)? | 70 | // @return Are we currently annotating (using the selected tool)? | ||
72 | bool annotating() const; | 71 | bool annotating() const; | ||
73 | 72 | | |||
74 | // returns the preferred cursor for the current tool. call this only | 73 | // returns the preferred cursor for the current tool. call this only | ||
75 | // if active() == true | 74 | // if active() == true | ||
76 | QCursor cursor() const; | 75 | QCursor cursor() const; | ||
77 | 76 | | |||
78 | QRect routeMouseEvent( QMouseEvent * event, PageViewItem * item ); | 77 | QRect routeMouseEvent( QMouseEvent * event, PageViewItem * item ); | ||
79 | QRect routeTabletEvent( QTabletEvent * event, PageViewItem * item, const QPoint & localOriginInGlobal ); | 78 | QRect routeTabletEvent( QTabletEvent * event, PageViewItem * item, const QPoint & localOriginInGlobal ); | ||
80 | QRect performRouteMouseOrTabletEvent( const AnnotatorEngine::EventType & eventType, const AnnotatorEngine::Button & button, | 79 | QRect performRouteMouseOrTabletEvent( const AnnotatorEngine::EventType & eventType, const AnnotatorEngine::Button & button, | ||
81 | const QPointF & pos, PageViewItem * item ); | 80 | const QPointF & pos, PageViewItem * item ); | ||
82 | bool routeKeyEvent( QKeyEvent * event ); | 81 | bool routeKeyEvent( QKeyEvent * event ); | ||
83 | bool routePaints( const QRect & wantedRect ) const; | 82 | bool routePaints( const QRect & wantedRect ) const; | ||
84 | void routePaint( QPainter * painter, const QRect & paintRect ); | 83 | void routePaint( QPainter * painter, const QRect & paintRect ); | ||
85 | 84 | | |||
86 | void reparseConfig(); | 85 | void reparseConfig(); | ||
87 | 86 | | |||
88 | static QString defaultToolName( const QDomElement &toolElement ); | 87 | static QString defaultToolName( const QDomElement &toolElement ); | ||
89 | static QPixmap makeToolPixmap( const QDomElement &toolElement ); | 88 | static QPixmap makeToolPixmap( const QDomElement &toolElement ); | ||
90 | 89 | | |||
91 | private Q_SLOTS: | 90 | // methods related to the annotation actions | ||
92 | void slotToolSelected( int toolID ); | 91 | void setupActions( KActionCollection *ac ); | ||
93 | void slotSaveToolbarOrientation( int side ); | 92 | // @return Is continuous mode active (pin annotation)? | ||
94 | void slotToolDoubleClicked( int toolID ); | 93 | bool continuousMode(); | ||
94 | // enable/disable the annotation actions | ||||
95 | void setToolsEnabled( bool enabled ); | ||||
96 | // enable/disable the text-selection annotation actions | ||||
97 | void setTextToolsEnabled( bool enabled ); | ||||
95 | 98 | | |||
96 | private: | 99 | // selects the active tool | ||
100 | void selectTool( int toolID ); | ||||
101 | // selects a stamp tool and sets the stamp symbol | ||||
102 | void selectStampTool( const QString &stampSymbol ); | ||||
103 | // makes a quick annotation the active tool | ||||
104 | int setQuickTool ( int toolID ); | ||||
105 | // deselects the tool and uncheck all the annotation actions | ||||
97 | void detachAnnotation(); | 106 | void detachAnnotation(); | ||
98 | 107 | | |||
108 | // returns the builtin annotation tool with the given Id | ||||
109 | QDomElement builtinTool( int toolID ); | ||||
110 | // returns the quick annotation tool with the given Id | ||||
111 | QDomElement quickTool( int toolID ); | ||||
112 | | ||||
113 | // methods that write the properties | ||||
114 | void setAnnotationWidth( double width ); | ||||
115 | void setAnnotationColor( const QColor &color ); | ||||
116 | void setAnnotationInnerColor( const QColor &color ); | ||||
117 | void setAnnotationOpacity( double opacity ); | ||||
118 | void setAnnotationFont( const QFont &font ); | ||||
119 | | ||||
120 | public Q_SLOTS: | ||||
121 | void setContinuousMode( bool enabled ); | ||||
122 | void addToQuickAnnotations(); | ||||
123 | void slotAdvancedSettings(); | ||||
124 | | ||||
125 | Q_SIGNALS: | ||||
126 | void toolSelected(); | ||||
127 | | ||||
128 | private: | ||||
129 | // save the annotation tools to Okular settings | ||||
130 | void saveAnnotationTools(); | ||||
131 | // returns the engine QDomElement of the the currently active tool | ||||
132 | QDomElement currentEngineElement(); | ||||
133 | // returns the annotation QDomElement of the the currently active tool | ||||
134 | QDomElement currentAnnotationElement(); | ||||
135 | | ||||
99 | // global class pointers | 136 | // global class pointers | ||
100 | Okular::Document * m_document; | 137 | Okular::Document * m_document; | ||
101 | PageView * m_pageView; | 138 | PageView * m_pageView; | ||
102 | PageViewToolBar * m_toolBar; | 139 | AnnotationActionHandler * m_actionHandler; | ||
103 | AnnotatorEngine * m_engine; | 140 | AnnotatorEngine * m_engine; | ||
104 | QDomElement m_toolsDefinition; | 141 | AnnotationTools * m_toolsDefinition; | ||
105 | QLinkedList<AnnotationToolItem> m_items; | 142 | AnnotationTools * m_quickToolsDefinition; | ||
106 | bool m_textToolsEnabled; | 143 | bool m_textToolsEnabled; | ||
107 | bool m_toolsEnabled; | 144 | bool m_toolsEnabled; | ||
108 | bool m_continuousMode; | 145 | bool m_continuousMode; | ||
109 | bool m_hidingWasForced; | | |||
110 | 146 | | |||
111 | // creation related variables | 147 | // creation related variables | ||
112 | int m_lastToolID; | 148 | int m_lastToolID; | ||
113 | QRect m_lastDrawnRect; | 149 | QRect m_lastDrawnRect; | ||
114 | PageViewItem * m_lockedItem; | 150 | PageViewItem * m_lockedItem; | ||
115 | //selected annotation name | 151 | //selected annotation name | ||
116 | //QString m_selectedAnnotationName; | 152 | //QString m_selectedAnnotationName; | ||
117 | }; | 153 | }; | ||
118 | 154 | | |||
119 | #endif | 155 | #endif | ||
120 | 156 | | |||
121 | /* kate: replace-tabs on; indent-width 4; */ | 157 | /* kate: replace-tabs on; indent-width 4; */ |