Changeset View
Changeset View
Standalone View
Standalone View
conf/editannottooldialog.cpp
Show All 25 Lines | |||||
26 | #include <QStackedWidget> | 26 | #include <QStackedWidget> | ||
27 | #include <QDomDocument> | 27 | #include <QDomDocument> | ||
28 | #include <QDomElement> | 28 | #include <QDomElement> | ||
29 | #include <KConfigGroup> | 29 | #include <KConfigGroup> | ||
30 | #include <QDialogButtonBox> | 30 | #include <QDialogButtonBox> | ||
31 | 31 | | |||
32 | #include "core/annotations.h" | 32 | #include "core/annotations.h" | ||
33 | #include "ui/annotationwidgets.h" | 33 | #include "ui/annotationwidgets.h" | ||
34 | #include "ui/guiutils.h" | ||||
34 | #include "ui/pageviewannotator.h" | 35 | #include "ui/pageviewannotator.h" | ||
35 | 36 | | |||
37 | namespace { | ||||
38 | GuiUtils::ToolType toolTypeToGuiUtilsToolType(EditAnnotToolDialog::ToolType toolType) { | ||||
39 | switch (toolType) { | ||||
40 | case EditAnnotToolDialog::ToolNoteLinked: | ||||
41 | return GuiUtils::ToolNoteLinked; | ||||
42 | break; | ||||
43 | case EditAnnotToolDialog::ToolNoteInline: | ||||
44 | return GuiUtils::ToolNoteInline; | ||||
45 | break; | ||||
46 | case EditAnnotToolDialog::ToolInk: | ||||
47 | return GuiUtils::ToolInk; | ||||
48 | break; | ||||
49 | case EditAnnotToolDialog::ToolStraightLine: | ||||
50 | return GuiUtils::ToolStraightLine; | ||||
51 | break; | ||||
52 | case EditAnnotToolDialog::ToolPolygon: | ||||
53 | return GuiUtils::ToolPolygon; | ||||
54 | break; | ||||
55 | case EditAnnotToolDialog::ToolTextMarkup: | ||||
56 | return GuiUtils::ToolTextMarkup; | ||||
57 | break; | ||||
58 | case EditAnnotToolDialog::ToolGeometricalShape: | ||||
59 | return GuiUtils::ToolGeometricalShape; | ||||
60 | break; | ||||
61 | case EditAnnotToolDialog::ToolStamp: | ||||
62 | return GuiUtils::ToolStamp; | ||||
63 | break; | ||||
64 | case EditAnnotToolDialog::ToolTypewriter: | ||||
65 | return GuiUtils::ToolTypewriter; | ||||
66 | break; | ||||
67 | } | ||||
68 | return GuiUtils::ToolUnknown; | ||||
69 | } | ||||
70 | } | ||||
71 | | ||||
36 | 72 | | |||
37 | EditAnnotToolDialog::EditAnnotToolDialog( QWidget *parent, const QDomElement &initialState ) | 73 | EditAnnotToolDialog::EditAnnotToolDialog( QWidget *parent, const QDomElement &initialState ) | ||
38 | : QDialog( parent ), m_stubann( nullptr ), m_annotationWidget( nullptr ) | 74 | : QDialog( parent ), m_stubann( nullptr ), m_annotationWidget( nullptr ) | ||
39 | { | 75 | { | ||
40 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); | 76 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); | ||
41 | QVBoxLayout *mainLayout = new QVBoxLayout; | 77 | QVBoxLayout *mainLayout = new QVBoxLayout; | ||
42 | setLayout(mainLayout); | 78 | setLayout(mainLayout); | ||
43 | QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); | 79 | QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); | ||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | |||||
119 | QString EditAnnotToolDialog::name() const | 155 | QString EditAnnotToolDialog::name() const | ||
120 | { | 156 | { | ||
121 | return m_name->text(); | 157 | return m_name->text(); | ||
122 | } | 158 | } | ||
123 | 159 | | |||
124 | QDomDocument EditAnnotToolDialog::toolXml() const | 160 | QDomDocument EditAnnotToolDialog::toolXml() const | ||
125 | { | 161 | { | ||
126 | const ToolType toolType = m_type->itemData( m_type->currentIndex() ).value<ToolType>(); | 162 | const ToolType toolType = m_type->itemData( m_type->currentIndex() ).value<ToolType>(); | ||
127 | 163 | const GuiUtils::ToolType gToolType = toolTypeToGuiUtilsToolType(toolType); | |||
128 | QDomDocument doc; | 164 | return GuiUtils::annotationIconDescription(gToolType, m_stubann); | ||
129 | QDomElement toolElement = doc.createElement( QStringLiteral("tool") ); | | |||
130 | QDomElement engineElement = doc.createElement( QStringLiteral("engine") ); | | |||
131 | QDomElement annotationElement = doc.createElement( QStringLiteral("annotation") ); | | |||
132 | doc.appendChild( toolElement ); | | |||
133 | toolElement.appendChild( engineElement ); | | |||
134 | engineElement.appendChild( annotationElement ); | | |||
135 | | ||||
136 | const QString color = m_stubann->style().color().name( QColor::HexArgb ); | | |||
137 | const QString textColor = static_cast< Okular::TextAnnotation * >( m_stubann )->textColor().name(); | | |||
138 | const QString opacity = QString::number( m_stubann->style().opacity() ); | | |||
139 | const QString width = QString::number( m_stubann->style().width() ); | | |||
140 | | ||||
141 | if ( toolType == ToolNoteLinked ) | | |||
142 | { | | |||
143 | Okular::TextAnnotation * ta = static_cast<Okular::TextAnnotation*>( m_stubann ); | | |||
144 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("note-linked") ); | | |||
145 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PickPoint") ); | | |||
146 | engineElement.setAttribute( QStringLiteral("color"), color ); | | |||
147 | engineElement.setAttribute( QStringLiteral("hoverIcon"), QStringLiteral("tool-note") ); | | |||
148 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Text") ); | | |||
149 | annotationElement.setAttribute( QStringLiteral("color"), color ); | | |||
150 | annotationElement.setAttribute( QStringLiteral("icon"), ta->textIcon() ); | | |||
151 | } | | |||
152 | else if ( toolType == ToolNoteInline ) | | |||
153 | { | | |||
154 | Okular::TextAnnotation * ta = static_cast<Okular::TextAnnotation*>( m_stubann ); | | |||
155 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("note-inline") ); | | |||
156 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PickPoint") ); | | |||
157 | engineElement.setAttribute( QStringLiteral("color"), color ); | | |||
158 | engineElement.setAttribute( QStringLiteral("hoverIcon"), QStringLiteral("tool-note-inline") ); | | |||
159 | engineElement.setAttribute( QStringLiteral("block"), QStringLiteral("true") ); | | |||
160 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("FreeText") ); | | |||
161 | annotationElement.setAttribute( QStringLiteral("color"), color ); | | |||
162 | annotationElement.setAttribute( QStringLiteral("width"), width ); | | |||
163 | if ( ta->inplaceAlignment() != 0 ) | | |||
164 | annotationElement.setAttribute( QStringLiteral("align"), ta->inplaceAlignment() ); | | |||
165 | if ( ta->textFont() != QApplication::font() ) | | |||
166 | annotationElement.setAttribute( QStringLiteral("font"), ta->textFont().toString() ); | | |||
167 | } | | |||
168 | else if ( toolType == ToolInk ) | | |||
169 | { | | |||
170 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("ink") ); | | |||
171 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("SmoothLine") ); | | |||
172 | engineElement.setAttribute( QStringLiteral("color"), color ); | | |||
173 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Ink") ); | | |||
174 | annotationElement.setAttribute( QStringLiteral("color"), color ); | | |||
175 | annotationElement.setAttribute( QStringLiteral("width"), width ); | | |||
176 | } | | |||
177 | else if ( toolType == ToolStraightLine ) | | |||
178 | { | | |||
179 | Okular::LineAnnotation * la = static_cast<Okular::LineAnnotation*>( m_stubann ); | | |||
180 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("straight-line") ); | | |||
181 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PolyLine") ); | | |||
182 | engineElement.setAttribute( QStringLiteral("color"), color ); | | |||
183 | engineElement.setAttribute( QStringLiteral("points"), QStringLiteral("2") ); | | |||
184 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Line") ); | | |||
185 | annotationElement.setAttribute( QStringLiteral("color"), color ); | | |||
186 | annotationElement.setAttribute( QStringLiteral("width"), width ); | | |||
187 | if ( la->lineLeadingForwardPoint() != 0 || la->lineLeadingBackwardPoint() != 0 ) | | |||
188 | { | | |||
189 | annotationElement.setAttribute( QStringLiteral("leadFwd"), QString::number( la->lineLeadingForwardPoint() ) ); | | |||
190 | annotationElement.setAttribute( QStringLiteral("leadBack"), QString::number( la->lineLeadingBackwardPoint() ) ); | | |||
191 | } | | |||
192 | annotationElement.setAttribute( QStringLiteral("startStyle"), QString::number( la->lineStartStyle() ) ); | | |||
193 | annotationElement.setAttribute( QStringLiteral("endStyle"), QString::number( la->lineEndStyle() ) ); | | |||
194 | } | | |||
195 | else if ( toolType == ToolPolygon ) | | |||
196 | { | | |||
197 | Okular::LineAnnotation * la = static_cast<Okular::LineAnnotation*>( m_stubann ); | | |||
198 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("polygon") ); | | |||
199 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PolyLine") ); | | |||
200 | engineElement.setAttribute( QStringLiteral("color"), color ); | | |||
201 | engineElement.setAttribute( QStringLiteral("points"), QStringLiteral("-1") ); | | |||
202 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Line") ); | | |||
203 | annotationElement.setAttribute( QStringLiteral("color"), color ); | | |||
204 | annotationElement.setAttribute( QStringLiteral("width"), width ); | | |||
205 | if ( la->lineInnerColor().isValid() ) | | |||
206 | { | | |||
207 | annotationElement.setAttribute( QStringLiteral("innerColor"), la->lineInnerColor().name() ); | | |||
208 | } | | |||
209 | } | | |||
210 | else if ( toolType == ToolTextMarkup ) | | |||
211 | { | | |||
212 | Okular::HighlightAnnotation * ha = static_cast<Okular::HighlightAnnotation*>( m_stubann ); | | |||
213 | | ||||
214 | switch ( ha->highlightType() ) | | |||
215 | { | | |||
216 | case Okular::HighlightAnnotation::Highlight: | | |||
217 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("highlight") ); | | |||
218 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Highlight") ); | | |||
219 | break; | | |||
220 | case Okular::HighlightAnnotation::Squiggly: | | |||
221 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("squiggly") ); | | |||
222 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Squiggly") ); | | |||
223 | break; | | |||
224 | case Okular::HighlightAnnotation::Underline: | | |||
225 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("underline") ); | | |||
226 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Underline") ); | | |||
227 | break; | | |||
228 | case Okular::HighlightAnnotation::StrikeOut: | | |||
229 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("strikeout") ); | | |||
230 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("StrikeOut") ); | | |||
231 | break; | | |||
232 | } | | |||
233 | | ||||
234 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("TextSelector") ); | | |||
235 | engineElement.setAttribute( QStringLiteral("color"), color ); | | |||
236 | annotationElement.setAttribute( QStringLiteral("color"), color ); | | |||
237 | } | | |||
238 | else if ( toolType == ToolGeometricalShape ) | | |||
239 | { | | |||
240 | Okular::GeomAnnotation * ga = static_cast<Okular::GeomAnnotation*>( m_stubann ); | | |||
241 | | ||||
242 | if ( ga->geometricalType() == Okular::GeomAnnotation::InscribedCircle ) | | |||
243 | { | | |||
244 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("ellipse") ); | | |||
245 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("GeomCircle") ); | | |||
246 | } | | |||
247 | else | | |||
248 | { | | |||
249 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("rectangle") ); | | |||
250 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("GeomSquare") ); | | |||
251 | } | | |||
252 | | ||||
253 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PickPoint") ); | | |||
254 | engineElement.setAttribute( QStringLiteral("color"), color ); | | |||
255 | engineElement.setAttribute( QStringLiteral("block"), QStringLiteral("true") ); | | |||
256 | annotationElement.setAttribute( QStringLiteral("color"), color ); | | |||
257 | annotationElement.setAttribute( QStringLiteral("width"), width ); | | |||
258 | | ||||
259 | if ( ga->geometricalInnerColor().isValid() ) | | |||
260 | annotationElement.setAttribute( QStringLiteral("innerColor"), ga->geometricalInnerColor().name() ); | | |||
261 | } | | |||
262 | else if ( toolType == ToolStamp ) | | |||
263 | { | | |||
264 | Okular::StampAnnotation * sa = static_cast<Okular::StampAnnotation*>( m_stubann ); | | |||
265 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("stamp") ); | | |||
266 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PickPoint") ); | | |||
267 | engineElement.setAttribute( QStringLiteral("hoverIcon"), sa->stampIconName() ); | | |||
268 | engineElement.setAttribute( QStringLiteral("size"), QStringLiteral("64") ); | | |||
269 | engineElement.setAttribute( QStringLiteral("block"), QStringLiteral("true") ); | | |||
270 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Stamp") ); | | |||
271 | annotationElement.setAttribute( QStringLiteral("icon"), sa->stampIconName() ); | | |||
272 | } | | |||
273 | else if ( toolType == ToolTypewriter ) | | |||
274 | { | | |||
275 | Okular::TextAnnotation * ta = static_cast<Okular::TextAnnotation*>( m_stubann ); | | |||
276 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("typewriter") ); | | |||
277 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PickPoint") ); | | |||
278 | engineElement.setAttribute( QStringLiteral("block"), QStringLiteral("true") ); | | |||
279 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Typewriter") ); | | |||
280 | annotationElement.setAttribute( QStringLiteral("color"), color ); | | |||
281 | annotationElement.setAttribute( QStringLiteral("textColor"), textColor ); | | |||
282 | annotationElement.setAttribute( QStringLiteral("width"), width ); | | |||
283 | if ( ta->textFont() != QApplication::font() ) | | |||
284 | annotationElement.setAttribute( QStringLiteral("font"), ta->textFont().toString() ); | | |||
285 | } | | |||
286 | | ||||
287 | if ( opacity != QStringLiteral("1") ) | | |||
288 | annotationElement.setAttribute( QStringLiteral("opacity"), opacity ); | | |||
289 | | ||||
290 | return doc; | | |||
291 | } | 165 | } | ||
292 | 166 | | |||
293 | void EditAnnotToolDialog::createStubAnnotation() | 167 | void EditAnnotToolDialog::createStubAnnotation() | ||
294 | { | 168 | { | ||
295 | const ToolType toolType = m_type->itemData( m_type->currentIndex() ).value<ToolType>(); | 169 | const ToolType toolType = m_type->itemData( m_type->currentIndex() ).value<ToolType>(); | ||
296 | 170 | | |||
297 | // Delete previous stub annotation, if any | 171 | // Delete previous stub annotation, if any | ||
298 | delete m_stubann; | 172 | delete m_stubann; | ||
▲ Show 20 Lines • Show All 247 Lines • Show Last 20 Lines |