Changeset View
Changeset View
Standalone View
Standalone View
ui/guiutils.cpp
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2006-2007 by Pino Toscano <pino@kde.org> * | 2 | * Copyright (C) 2006-2007 by Pino Toscano <pino@kde.org> * | ||
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 | #include "guiutils.h" | 10 | #include "guiutils.h" | ||
11 | 11 | | |||
12 | // qt/kde includes | 12 | // qt/kde includes | ||
13 | #include <QApplication> | ||||
13 | #include <QPainter> | 14 | #include <QPainter> | ||
14 | #include <QSvgRenderer> | 15 | #include <QSvgRenderer> | ||
15 | #include <QTextDocument> | 16 | #include <QTextDocument> | ||
16 | #include <QFileDialog> | 17 | #include <QFileDialog> | ||
17 | #include <QStandardPaths> | 18 | #include <QStandardPaths> | ||
18 | #include <KIconLoader> | 19 | #include <KIconLoader> | ||
19 | #include <KMessageBox> | 20 | #include <KMessageBox> | ||
20 | #include <KLocalizedString> | 21 | #include <KLocalizedString> | ||
▲ Show 20 Lines • Show All 256 Lines • ▼ Show 20 Line(s) | 277 | { | |||
277 | // use destAlpha * sourceAlpha product | 278 | // use destAlpha * sourceAlpha product | ||
278 | if ( destAlpha < 255 ) | 279 | if ( destAlpha < 255 ) | ||
279 | sourceAlpha = qt_div_255( destAlpha * sourceAlpha ); | 280 | sourceAlpha = qt_div_255( destAlpha * sourceAlpha ); | ||
280 | data[i] = qRgba( newR, newG, newB, sourceAlpha ); | 281 | data[i] = qRgba( newR, newG, newB, sourceAlpha ); | ||
281 | } | 282 | } | ||
282 | } | 283 | } | ||
283 | } | 284 | } | ||
284 | 285 | | |||
286 | ToolType toolTypeFromAnnotation(const Okular::Annotation *annotation) | ||||
287 | { | ||||
288 | switch (annotation->subType()) { | ||||
289 | case Okular::Annotation::AText: { | ||||
290 | auto textAnnotation = static_cast< const Okular::TextAnnotation *>( annotation ); | ||||
291 | if (textAnnotation->textType() == Okular::TextAnnotation::Linked) { | ||||
292 | return ToolNoteLinked; | ||||
293 | } else if (textAnnotation->inplaceIntent() == Okular::TextAnnotation::TypeWriter) { | ||||
294 | return ToolTypewriter; | ||||
295 | } else { | ||||
296 | return ToolNoteInline; | ||||
297 | } | ||||
298 | break; | ||||
299 | } | ||||
300 | case Okular::Annotation::AInk: | ||||
301 | return ToolInk; | ||||
302 | break; | ||||
303 | case Okular::Annotation::ALine: { | ||||
304 | auto lineAnnotation = static_cast< const Okular::LineAnnotation *> ( annotation ); | ||||
305 | if (lineAnnotation->linePoints().count() == 2) { | ||||
306 | return ToolStraightLine; | ||||
307 | } else { | ||||
308 | return ToolPolygon; | ||||
309 | } | ||||
310 | break; | ||||
311 | } | ||||
312 | case Okular::Annotation::AHighlight: | ||||
313 | return ToolTextMarkup; | ||||
314 | break; | ||||
315 | case Okular::Annotation::AGeom: | ||||
316 | return ToolGeometricalShape; | ||||
317 | break; | ||||
318 | case Okular::Annotation::AStamp: | ||||
319 | return ToolStamp; | ||||
320 | break; | ||||
321 | default: | ||||
322 | return ToolUnknown; | ||||
323 | } | ||||
324 | | ||||
325 | return ToolUnknown; | ||||
326 | } | ||||
327 | | ||||
328 | QDomDocument annotationIconDescription(const Okular::Annotation *annotation) | ||||
329 | { | ||||
330 | return annotationIconDescription(toolTypeFromAnnotation(annotation), annotation); | ||||
331 | } | ||||
332 | | ||||
333 | QDomDocument annotationIconDescription(ToolType toolType, const Okular::Annotation *annotation) | ||||
334 | { | ||||
335 | QDomDocument doc; | ||||
336 | QDomElement toolElement = doc.createElement( QStringLiteral("tool") ); | ||||
337 | QDomElement engineElement = doc.createElement( QStringLiteral("engine") ); | ||||
338 | QDomElement annotationElement = doc.createElement( QStringLiteral("annotation") ); | ||||
339 | doc.appendChild( toolElement ); | ||||
340 | toolElement.appendChild( engineElement ); | ||||
341 | engineElement.appendChild( annotationElement ); | ||||
342 | | ||||
343 | const QString color = annotation->style().color().name( QColor::HexArgb ); | ||||
344 | const QString textColor = static_cast< const Okular::TextAnnotation * >( annotation )->textColor().name(); | ||||
345 | const QString opacity = QString::number( annotation->style().opacity() ); | ||||
346 | const QString width = QString::number( annotation->style().width() ); | ||||
347 | | ||||
348 | if ( toolType == ToolNoteLinked ) | ||||
349 | { | ||||
350 | const Okular::TextAnnotation * ta = static_cast<const Okular::TextAnnotation*>( annotation ); | ||||
351 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("note-linked") ); | ||||
352 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PickPoint") ); | ||||
353 | engineElement.setAttribute( QStringLiteral("color"), color ); | ||||
354 | engineElement.setAttribute( QStringLiteral("hoverIcon"), QStringLiteral("tool-note") ); | ||||
355 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Text") ); | ||||
356 | annotationElement.setAttribute( QStringLiteral("color"), color ); | ||||
357 | annotationElement.setAttribute( QStringLiteral("icon"), ta->textIcon() ); | ||||
358 | } | ||||
359 | else if ( toolType == ToolNoteInline ) | ||||
360 | { | ||||
361 | const Okular::TextAnnotation * ta = static_cast<const Okular::TextAnnotation*>( annotation ); | ||||
362 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("note-inline") ); | ||||
363 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PickPoint") ); | ||||
364 | engineElement.setAttribute( QStringLiteral("color"), color ); | ||||
365 | engineElement.setAttribute( QStringLiteral("hoverIcon"), QStringLiteral("tool-note-inline") ); | ||||
366 | engineElement.setAttribute( QStringLiteral("block"), QStringLiteral("true") ); | ||||
367 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("FreeText") ); | ||||
368 | annotationElement.setAttribute( QStringLiteral("color"), color ); | ||||
369 | annotationElement.setAttribute( QStringLiteral("width"), width ); | ||||
370 | if ( ta->inplaceAlignment() != 0 ) | ||||
371 | annotationElement.setAttribute( QStringLiteral("align"), ta->inplaceAlignment() ); | ||||
372 | if ( ta->textFont() != QApplication::font() ) | ||||
373 | annotationElement.setAttribute( QStringLiteral("font"), ta->textFont().toString() ); | ||||
374 | } | ||||
375 | else if ( toolType == ToolInk ) | ||||
376 | { | ||||
377 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("ink") ); | ||||
378 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("SmoothLine") ); | ||||
379 | engineElement.setAttribute( QStringLiteral("color"), color ); | ||||
380 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Ink") ); | ||||
381 | annotationElement.setAttribute( QStringLiteral("color"), color ); | ||||
382 | annotationElement.setAttribute( QStringLiteral("width"), width ); | ||||
383 | } | ||||
384 | else if ( toolType == ToolStraightLine ) | ||||
385 | { | ||||
386 | const Okular::LineAnnotation * la = static_cast<const Okular::LineAnnotation*>( annotation ); | ||||
387 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("straight-line") ); | ||||
388 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PolyLine") ); | ||||
389 | engineElement.setAttribute( QStringLiteral("color"), color ); | ||||
390 | engineElement.setAttribute( QStringLiteral("points"), QStringLiteral("2") ); | ||||
391 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Line") ); | ||||
392 | annotationElement.setAttribute( QStringLiteral("color"), color ); | ||||
393 | annotationElement.setAttribute( QStringLiteral("width"), width ); | ||||
394 | if ( la->lineLeadingForwardPoint() != 0 || la->lineLeadingBackwardPoint() != 0 ) | ||||
395 | { | ||||
396 | annotationElement.setAttribute( QStringLiteral("leadFwd"), QString::number( la->lineLeadingForwardPoint() ) ); | ||||
397 | annotationElement.setAttribute( QStringLiteral("leadBack"), QString::number( la->lineLeadingBackwardPoint() ) ); | ||||
398 | } | ||||
399 | annotationElement.setAttribute( QStringLiteral("startStyle"), QString::number( la->lineStartStyle() ) ); | ||||
400 | annotationElement.setAttribute( QStringLiteral("endStyle"), QString::number( la->lineEndStyle() ) ); | ||||
401 | } | ||||
402 | else if ( toolType == ToolPolygon ) | ||||
403 | { | ||||
404 | const Okular::LineAnnotation * la = static_cast<const Okular::LineAnnotation*>( annotation ); | ||||
405 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("polygon") ); | ||||
406 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PolyLine") ); | ||||
407 | engineElement.setAttribute( QStringLiteral("color"), color ); | ||||
408 | engineElement.setAttribute( QStringLiteral("points"), QStringLiteral("-1") ); | ||||
409 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Line") ); | ||||
410 | annotationElement.setAttribute( QStringLiteral("color"), color ); | ||||
411 | annotationElement.setAttribute( QStringLiteral("width"), width ); | ||||
412 | if ( la->lineInnerColor().isValid() ) | ||||
413 | { | ||||
414 | annotationElement.setAttribute( QStringLiteral("innerColor"), la->lineInnerColor().name() ); | ||||
415 | } | ||||
416 | } | ||||
417 | else if ( toolType == ToolTextMarkup ) | ||||
418 | { | ||||
419 | const Okular::HighlightAnnotation * ha = static_cast<const Okular::HighlightAnnotation*>( annotation ); | ||||
420 | | ||||
421 | switch ( ha->highlightType() ) | ||||
422 | { | ||||
423 | case Okular::HighlightAnnotation::Highlight: | ||||
424 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("highlight") ); | ||||
425 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Highlight") ); | ||||
426 | break; | ||||
427 | case Okular::HighlightAnnotation::Squiggly: | ||||
428 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("squiggly") ); | ||||
429 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Squiggly") ); | ||||
430 | break; | ||||
431 | case Okular::HighlightAnnotation::Underline: | ||||
432 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("underline") ); | ||||
433 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Underline") ); | ||||
434 | break; | ||||
435 | case Okular::HighlightAnnotation::StrikeOut: | ||||
436 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("strikeout") ); | ||||
437 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("StrikeOut") ); | ||||
438 | break; | ||||
439 | } | ||||
440 | | ||||
441 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("TextSelector") ); | ||||
442 | engineElement.setAttribute( QStringLiteral("color"), color ); | ||||
443 | annotationElement.setAttribute( QStringLiteral("color"), color ); | ||||
444 | } | ||||
445 | else if ( toolType == ToolGeometricalShape ) | ||||
446 | { | ||||
447 | const Okular::GeomAnnotation * ga = static_cast<const Okular::GeomAnnotation*>( annotation ); | ||||
448 | | ||||
449 | if ( ga->geometricalType() == Okular::GeomAnnotation::InscribedCircle ) | ||||
450 | { | ||||
451 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("ellipse") ); | ||||
452 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("GeomCircle") ); | ||||
453 | } | ||||
454 | else | ||||
455 | { | ||||
456 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("rectangle") ); | ||||
457 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("GeomSquare") ); | ||||
458 | } | ||||
459 | | ||||
460 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PickPoint") ); | ||||
461 | engineElement.setAttribute( QStringLiteral("color"), color ); | ||||
462 | engineElement.setAttribute( QStringLiteral("block"), QStringLiteral("true") ); | ||||
463 | annotationElement.setAttribute( QStringLiteral("color"), color ); | ||||
464 | annotationElement.setAttribute( QStringLiteral("width"), width ); | ||||
465 | | ||||
466 | if ( ga->geometricalInnerColor().isValid() ) | ||||
467 | annotationElement.setAttribute( QStringLiteral("innerColor"), ga->geometricalInnerColor().name() ); | ||||
468 | } | ||||
469 | else if ( toolType == ToolStamp ) | ||||
470 | { | ||||
471 | const Okular::StampAnnotation * sa = static_cast<const Okular::StampAnnotation*>( annotation ); | ||||
472 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("stamp") ); | ||||
473 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PickPoint") ); | ||||
474 | engineElement.setAttribute( QStringLiteral("hoverIcon"), sa->stampIconName() ); | ||||
475 | engineElement.setAttribute( QStringLiteral("size"), QStringLiteral("64") ); | ||||
476 | engineElement.setAttribute( QStringLiteral("block"), QStringLiteral("true") ); | ||||
477 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Stamp") ); | ||||
478 | annotationElement.setAttribute( QStringLiteral("icon"), sa->stampIconName() ); | ||||
479 | } | ||||
480 | else if ( toolType == ToolTypewriter ) | ||||
481 | { | ||||
482 | const Okular::TextAnnotation * ta = static_cast<const Okular::TextAnnotation*>( annotation ); | ||||
483 | toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("typewriter") ); | ||||
484 | engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PickPoint") ); | ||||
485 | engineElement.setAttribute( QStringLiteral("block"), QStringLiteral("true") ); | ||||
486 | annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Typewriter") ); | ||||
487 | annotationElement.setAttribute( QStringLiteral("color"), color ); | ||||
488 | annotationElement.setAttribute( QStringLiteral("textColor"), textColor ); | ||||
489 | annotationElement.setAttribute( QStringLiteral("width"), width ); | ||||
490 | if ( ta->textFont() != QApplication::font() ) | ||||
491 | annotationElement.setAttribute( QStringLiteral("font"), ta->textFont().toString() ); | ||||
492 | } | ||||
493 | | ||||
494 | if ( opacity != QStringLiteral("1") ) | ||||
495 | annotationElement.setAttribute( QStringLiteral("opacity"), opacity ); | ||||
496 | | ||||
497 | return doc; | ||||
498 | } | ||||
499 | | ||||
285 | } | 500 | } |