Changeset View
Changeset View
Standalone View
Standalone View
ui/pageviewannotator.cpp
Show All 27 Lines | |||||
28 | #include <qmenu.h> | 28 | #include <qmenu.h> | ||
29 | 29 | | |||
30 | // system includes | 30 | // system includes | ||
31 | #include <math.h> | 31 | #include <math.h> | ||
32 | #include <memory> | 32 | #include <memory> | ||
33 | #include <QStandardPaths> | 33 | #include <QStandardPaths> | ||
34 | 34 | | |||
35 | // local includes | 35 | // local includes | ||
36 | #include "conf/editannottooldialog.h" | ||||
36 | #include "core/area.h" | 37 | #include "core/area.h" | ||
37 | #include "core/document.h" | 38 | #include "core/document.h" | ||
38 | #include "core/page.h" | 39 | #include "core/page.h" | ||
39 | #include "core/annotations.h" | 40 | #include "core/annotations.h" | ||
41 | #include "ui/annotationactionhandler.h" | ||||
40 | #include "settings.h" | 42 | #include "settings.h" | ||
41 | #include "annotationtools.h" | 43 | #include "annotationtools.h" | ||
42 | #include "guiutils.h" | 44 | #include "guiutils.h" | ||
43 | #include "pageview.h" | 45 | #include "pageview.h" | ||
44 | #include "debug_ui.h" | 46 | #include "debug_ui.h" | ||
45 | 47 | | |||
46 | /** @short PickPointEngine */ | 48 | /** @short PickPointEngine */ | ||
47 | class PickPointEngine : public AnnotatorEngine | 49 | class PickPointEngine : public AnnotatorEngine | ||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | 147 | { | |||
157 | { | 159 | { | ||
158 | QFont f; | 160 | QFont f; | ||
159 | f.fromString( m_annotElement.attribute( QStringLiteral("font") ) ); | 161 | f.fromString( m_annotElement.attribute( QStringLiteral("font") ) ); | ||
160 | ta->setTextFont( f ); | 162 | ta->setTextFont( f ); | ||
161 | } | 163 | } | ||
162 | // set font color | 164 | // set font color | ||
163 | if ( m_annotElement.hasAttribute( QStringLiteral("textColor") ) ) | 165 | if ( m_annotElement.hasAttribute( QStringLiteral("textColor") ) ) | ||
164 | { | 166 | { | ||
165 | if ( inplaceIntent == Okular::TextAnnotation::TypeWriter ) | | |||
166 | ta->setTextColor( m_annotElement.attribute( QStringLiteral("textColor") ) ); | 167 | ta->setTextColor( m_annotElement.attribute( QStringLiteral("textColor") ) ); | ||
167 | else | | |||
168 | ta->setTextColor( Qt::black ); | | |||
169 | } | 168 | } | ||
170 | //set width | 169 | //set width | ||
171 | if ( m_annotElement.hasAttribute( QStringLiteral ( "width" ) ) ) | 170 | if ( m_annotElement.hasAttribute( QStringLiteral ( "width" ) ) ) | ||
172 | { | 171 | { | ||
173 | ta->style().setWidth( m_annotElement.attribute( QStringLiteral ( "width" ) ).toDouble() ); | 172 | ta->style().setWidth( m_annotElement.attribute( QStringLiteral ( "width" ) ).toDouble() ); | ||
174 | } | 173 | } | ||
175 | //set boundary | 174 | //set boundary | ||
176 | rect.left = qMin(startpoint.x,point.x); | 175 | rect.left = qMin(startpoint.x,point.x); | ||
▲ Show 20 Lines • Show All 474 Lines • ▼ Show 20 Line(s) | 649 | private: | |||
651 | // data | 650 | // data | ||
652 | PageView * m_pageView; | 651 | PageView * m_pageView; | ||
653 | // TODO: support more pages | 652 | // TODO: support more pages | ||
654 | std::unique_ptr<Okular::RegularAreaRect> selection; | 653 | std::unique_ptr<Okular::RegularAreaRect> selection; | ||
655 | Okular::NormalizedPoint lastPoint; | 654 | Okular::NormalizedPoint lastPoint; | ||
656 | QRect rect; | 655 | QRect rect; | ||
657 | }; | 656 | }; | ||
658 | 657 | | |||
659 | 658 | /** @short AnnotationTools*/ | |||
660 | /** PageViewAnnotator **/ | 659 | class AnnotationTools | ||
661 | | ||||
662 | PageViewAnnotator::PageViewAnnotator( PageView * parent, Okular::Document * storage ) | | |||
663 | : QObject( parent ), m_document( storage ), m_pageView( parent ), | | |||
664 | m_toolBar( nullptr ), m_engine( nullptr ), m_textToolsEnabled( false ), m_toolsEnabled( false ), | | |||
665 | m_continuousMode( false ), m_hidingWasForced( false ), m_lastToolID( -1 ), m_lockedItem( nullptr ) | | |||
666 | { | 660 | { | ||
667 | reparseConfig(); | 661 | public: | ||
668 | } | 662 | AnnotationTools() : m_toolsCount( 0 ) {} | ||
669 | 663 | | |||
670 | void PageViewAnnotator::reparseConfig() | 664 | void setTools( QStringList tools ) | ||
671 | { | 665 | { | ||
672 | m_items.clear(); | | |||
673 | | ||||
674 | // Read tool list from configuration. It's a list of XML <tool></tool> elements | | |||
675 | const QStringList userTools = Okular::Settings::annotationTools(); | | |||
676 | | ||||
677 | // Populate m_toolsDefinition | 666 | // Populate m_toolsDefinition | ||
678 | QDomDocument doc; | 667 | m_toolsCount = 0; | ||
679 | m_toolsDefinition = doc.createElement( QStringLiteral("annotatingTools") ); | 668 | m_toolsDefinition.clear(); | ||
680 | foreach ( const QString &toolXml, userTools ) | 669 | QDomElement root = m_toolsDefinition.createElement( QStringLiteral( "root" ) ); | ||
670 | m_toolsDefinition.appendChild( root ); | ||||
671 | foreach ( const QString &toolXml, tools ) | ||||
681 | { | 672 | { | ||
682 | QDomDocument entryParser; | 673 | QDomDocument entryParser; | ||
683 | if ( entryParser.setContent( toolXml ) ) | 674 | if ( entryParser.setContent( toolXml ) ) { | ||
684 | m_toolsDefinition.appendChild( doc.importNode( entryParser.documentElement(), true ) ); | 675 | root.appendChild( m_toolsDefinition.importNode( entryParser.documentElement(), true ) ); | ||
685 | else | 676 | m_toolsCount++; | ||
677 | } else { | ||||
686 | qCWarning(OkularUiDebug) << "Skipping malformed tool XML in AnnotationTools setting"; | 678 | qCWarning(OkularUiDebug) << "Skipping malformed tool XML in AnnotationTools setting"; | ||
687 | } | 679 | } | ||
680 | } | ||||
681 | } | ||||
688 | 682 | | |||
689 | // Create the AnnotationToolItems from the XML dom tree | 683 | QStringList toStringList() | ||
690 | QDomNode toolDescription = m_toolsDefinition.firstChild(); | | |||
691 | while ( toolDescription.isElement() ) | | |||
692 | { | | |||
693 | QDomElement toolElement = toolDescription.toElement(); | | |||
694 | if ( toolElement.tagName() == QLatin1String("tool") ) | | |||
695 | { | | |||
696 | AnnotationToolItem item; | | |||
697 | item.id = toolElement.attribute(QStringLiteral("id")).toInt(); | | |||
698 | if ( toolElement.hasAttribute( QStringLiteral("name") ) ) | | |||
699 | item.text = toolElement.attribute( QStringLiteral("name") ); | | |||
700 | else | | |||
701 | item.text = defaultToolName( toolElement ); | | |||
702 | item.pixmap = makeToolPixmap( toolElement ); | | |||
703 | QDomNode shortcutNode = toolElement.elementsByTagName( QStringLiteral("shortcut") ).item( 0 ); | | |||
704 | if ( shortcutNode.isElement() ) | | |||
705 | item.shortcut = shortcutNode.toElement().text(); | | |||
706 | QDomNodeList engineNodeList = toolElement.elementsByTagName( QStringLiteral("engine") ); | | |||
707 | if ( engineNodeList.size() > 0 ) | | |||
708 | { | 684 | { | ||
709 | QDomElement engineEl = engineNodeList.item( 0 ).toElement(); | 685 | QStringList tools; | ||
710 | if ( !engineEl.isNull() && engineEl.hasAttribute( QStringLiteral("type") ) ) | 686 | QDomElement toolElement = m_toolsDefinition.documentElement().firstChildElement(); | ||
711 | item.isText = engineEl.attribute( QStringLiteral("type") ) == QLatin1String( "TextSelector" ); | 687 | QString str; | ||
688 | QTextStream stream(&str); | ||||
689 | while( !toolElement.isNull() ) | ||||
690 | { | ||||
691 | str.clear(); | ||||
692 | toolElement.save(stream, -1 /* indent disabled */); | ||||
693 | tools << str; | ||||
694 | toolElement = toolElement.nextSiblingElement(); | ||||
712 | } | 695 | } | ||
713 | m_items.push_back( item ); | 696 | return tools; | ||
714 | } | 697 | } | ||
715 | toolDescription = toolDescription.nextSibling(); | 698 | | ||
699 | QDomElement tool( int toolID ) | ||||
700 | { | ||||
701 | QDomElement toolElement = m_toolsDefinition.documentElement().firstChildElement(); | ||||
702 | while( !toolElement.isNull() && toolElement.attribute("id").toInt() != toolID ) { | ||||
703 | toolElement = toolElement.nextSiblingElement(); | ||||
716 | } | 704 | } | ||
705 | return toolElement; // can return a null element | ||||
717 | } | 706 | } | ||
718 | 707 | | |||
719 | PageViewAnnotator::~PageViewAnnotator() | 708 | void appendTool( QDomElement toolElement ) | ||
720 | { | 709 | { | ||
721 | delete m_engine; | 710 | toolElement = toolElement.cloneNode().toElement(); | ||
711 | toolElement.setAttribute( QStringLiteral( "id" ), ++m_toolsCount ); | ||||
712 | m_toolsDefinition.documentElement().appendChild( toolElement ); | ||||
722 | } | 713 | } | ||
723 | 714 | | |||
724 | void PageViewAnnotator::setEnabled( bool on ) | 715 | bool updateTool( QDomElement newToolElement, int toolID ) | ||
725 | { | 716 | { | ||
726 | if ( !on ) | 717 | newToolElement = newToolElement.cloneNode().toElement(); | ||
727 | { | 718 | newToolElement.setAttribute( QStringLiteral( "id" ), toolID ); | ||
728 | // remove toolBar | 719 | QDomElement toolElement = tool( toolID ); | ||
729 | if ( m_toolBar ) | 720 | QDomNode oldTool = m_toolsDefinition.documentElement().replaceChild( newToolElement, toolElement ); | ||
730 | m_toolBar->hideAndDestroy(); | 721 | bool success = !oldTool.isNull(); | ||
731 | m_toolBar = nullptr; | 722 | return success; | ||
732 | // deactivate the active tool, if any | | |||
733 | slotToolSelected( -1 ); | | |||
734 | return; | | |||
735 | } | 723 | } | ||
736 | 724 | | |||
737 | // if no tools are defined, don't show the toolbar | 725 | private: | ||
738 | if ( !m_toolsDefinition.hasChildNodes() ) | 726 | QDomDocument m_toolsDefinition; | ||
739 | return; | 727 | int m_toolsCount; | ||
740 | 728 | | |||
741 | // create toolBar | 729 | }; | ||
742 | if ( !m_toolBar ) | | |||
743 | { | | |||
744 | m_toolBar = new PageViewToolBar( m_pageView, m_pageView->viewport() ); | | |||
745 | m_toolBar->setSide( (PageViewToolBar::Side)Okular::Settings::editToolBarPlacement() ); | | |||
746 | m_toolBar->setItems( m_items ); | | |||
747 | m_toolBar->setToolsEnabled( m_toolsEnabled ); | | |||
748 | m_toolBar->setTextToolsEnabled( m_textToolsEnabled ); | | |||
749 | connect(m_toolBar, &PageViewToolBar::toolSelected, this, &PageViewAnnotator::slotToolSelected); | | |||
750 | connect(m_toolBar, &PageViewToolBar::orientationChanged, this, &PageViewAnnotator::slotSaveToolbarOrientation); | | |||
751 | 730 | | |||
752 | connect(m_toolBar, &PageViewToolBar::buttonDoubleClicked, this, &PageViewAnnotator::slotToolDoubleClicked); | 731 | /** PageViewAnnotator **/ | ||
753 | m_toolBar->setCursor(Qt::ArrowCursor); | 732 | PageViewAnnotator::PageViewAnnotator( PageView * parent, Okular::Document * storage ) | ||
733 | : QObject( parent ), m_document( storage ), m_pageView( parent ), | ||||
734 | m_actionHandler( nullptr ), m_engine( nullptr ), m_toolsDefinition( nullptr ), | ||||
735 | m_favoriteToolsDefinition( nullptr ), m_continuousMode( true ), m_lastToolID( -1 ), | ||||
736 | m_lockedItem( nullptr ) | ||||
737 | { | ||||
738 | reparseConfig(); | ||||
754 | } | 739 | } | ||
755 | 740 | | |||
756 | // show the toolBar | 741 | void PageViewAnnotator::reparseConfig() | ||
757 | m_toolBar->showAndAnimate(); | 742 | { | ||
743 | // Read tool list from configuration. It's a list of XML <tool></tool> elements | ||||
744 | if( !m_toolsDefinition ) | ||||
745 | m_toolsDefinition = new AnnotationTools(); | ||||
746 | m_toolsDefinition->setTools( Okular::Settings::annotationTools() ); | ||||
747 | | ||||
748 | if( !m_favoriteToolsDefinition ) | ||||
749 | m_favoriteToolsDefinition = new AnnotationTools(); | ||||
750 | m_favoriteToolsDefinition->setTools( Okular::Settings::favoriteAnnotationTools() ); | ||||
751 | | ||||
752 | m_continuousMode = Okular::Settings::annotationContinuousMode(); | ||||
753 | | ||||
754 | if ( Okular::Settings::identityAuthor().isEmpty() ) | ||||
755 | detachAnnotation(); | ||||
756 | | ||||
757 | if( m_actionHandler ) | ||||
758 | m_actionHandler->reparseTools(); | ||||
758 | } | 759 | } | ||
759 | 760 | | |||
760 | void PageViewAnnotator::setTextToolsEnabled( bool enabled ) | 761 | PageViewAnnotator::~PageViewAnnotator() | ||
761 | { | 762 | { | ||
762 | m_textToolsEnabled = enabled; | 763 | delete m_engine; | ||
763 | if ( m_toolBar ) | | |||
764 | m_toolBar->setTextToolsEnabled( m_textToolsEnabled ); | | |||
765 | } | 764 | } | ||
766 | 765 | | |||
767 | void PageViewAnnotator::setToolsEnabled( bool enabled ) | 766 | void PageViewAnnotator::setEnabled( bool on ) | ||
768 | { | 767 | { | ||
769 | m_toolsEnabled = enabled; | 768 | if ( !on ) | ||
770 | if ( m_toolBar ) | 769 | { | ||
771 | m_toolBar->setToolsEnabled( m_toolsEnabled ); | 770 | // deactivate the active tool, if any | ||
771 | selectTool( -1 ); | ||||
772 | return; | ||||
773 | } | ||||
772 | } | 774 | } | ||
773 | 775 | | |||
774 | void PageViewAnnotator::setHidingForced( bool forced ) | 776 | void PageViewAnnotator::setTextToolsEnabled( bool enabled ) | ||
775 | { | 777 | { | ||
776 | m_hidingWasForced = forced; | 778 | if ( m_actionHandler ) | ||
779 | m_actionHandler->setTextToolsEnabled( enabled ); | ||||
777 | } | 780 | } | ||
778 | 781 | | |||
779 | bool PageViewAnnotator::hidingWasForced() const | 782 | void PageViewAnnotator::setToolsEnabled( bool enabled ) | ||
780 | { | 783 | { | ||
781 | return m_hidingWasForced; | 784 | if ( m_actionHandler ) | ||
785 | m_actionHandler->setToolsEnabled( enabled ); | ||||
782 | } | 786 | } | ||
783 | 787 | | |||
784 | bool PageViewAnnotator::active() const | 788 | bool PageViewAnnotator::active() const | ||
785 | { | 789 | { | ||
786 | return m_engine && m_toolBar; | 790 | return m_engine != nullptr; | ||
787 | } | 791 | } | ||
788 | 792 | | |||
789 | bool PageViewAnnotator::annotating() const | 793 | bool PageViewAnnotator::annotating() const | ||
790 | { | 794 | { | ||
791 | return active() && m_lockedItem; | 795 | return active() && m_lockedItem; | ||
792 | } | 796 | } | ||
793 | 797 | | |||
794 | QCursor PageViewAnnotator::cursor() const | 798 | QCursor PageViewAnnotator::cursor() const | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 860 | { | |||
861 | annotation->setAuthor( Okular::Settings::identityAuthor() ); | 865 | annotation->setAuthor( Okular::Settings::identityAuthor() ); | ||
862 | m_document->addPageAnnotation( m_lockedItem->pageNumber(), annotation ); | 866 | m_document->addPageAnnotation( m_lockedItem->pageNumber(), annotation ); | ||
863 | 867 | | |||
864 | if ( annotation->openDialogAfterCreation() ) | 868 | if ( annotation->openDialogAfterCreation() ) | ||
865 | m_pageView->openAnnotationWindow( annotation, m_lockedItem->pageNumber() ); | 869 | m_pageView->openAnnotationWindow( annotation, m_lockedItem->pageNumber() ); | ||
866 | } | 870 | } | ||
867 | 871 | | |||
868 | if ( m_continuousMode ) | 872 | if ( m_continuousMode ) | ||
869 | slotToolSelected( m_lastToolID ); | 873 | selectTool( m_lastToolID ); | ||
870 | else | 874 | else | ||
871 | detachAnnotation(); | 875 | detachAnnotation(); | ||
872 | } | 876 | } | ||
873 | 877 | | |||
874 | return modifiedRect; | 878 | return modifiedRect; | ||
875 | } | 879 | } | ||
876 | 880 | | |||
877 | QRect PageViewAnnotator::routeMouseEvent( QMouseEvent * e, PageViewItem * item ) | 881 | QRect PageViewAnnotator::routeMouseEvent( QMouseEvent * e, PageViewItem * item ) | ||
Show All 12 Lines | 893 | { | |||
890 | // Unlike routeMouseEvent, routeTabletEvent must explicitly ignore events it doesn't care about so that | 894 | // Unlike routeMouseEvent, routeTabletEvent must explicitly ignore events it doesn't care about so that | ||
891 | // the corresponding mouse event will later be delivered. | 895 | // the corresponding mouse event will later be delivered. | ||
892 | if ( !item ) | 896 | if ( !item ) | ||
893 | { | 897 | { | ||
894 | e->ignore(); | 898 | e->ignore(); | ||
895 | return QRect(); | 899 | return QRect(); | ||
896 | } | 900 | } | ||
897 | 901 | | |||
898 | // We set all tablet events that take place over the annotations toolbar to ignore so that corresponding mouse | | |||
899 | // events will be delivered to the toolbar. However, we still allow the annotations code to handle | | |||
900 | // TabletMove and TabletRelease events in case the user is drawing an annotation onto the toolbar. | | |||
901 | const QPoint toolBarPos = m_toolBar->mapFromGlobal( e->globalPos() ); | | |||
902 | const QRect toolBarRect = m_toolBar->rect(); | | |||
903 | if ( toolBarRect.contains( toolBarPos ) ) | | |||
904 | { | | |||
905 | e->ignore(); | | |||
906 | if (e->type() == QEvent::TabletPress) | | |||
907 | return QRect(); | | |||
908 | } | | |||
909 | | ||||
910 | AnnotatorEngine::EventType eventType; | 902 | AnnotatorEngine::EventType eventType; | ||
911 | AnnotatorEngine::Button button; | 903 | AnnotatorEngine::Button button; | ||
912 | 904 | | |||
913 | // figure out the event type and button | 905 | // figure out the event type and button | ||
914 | AnnotatorEngine::decodeEvent( e, &eventType, &button ); | 906 | AnnotatorEngine::decodeEvent( e, &eventType, &button ); | ||
915 | 907 | | |||
916 | const QPointF globalPosF = e->globalPosF(); | 908 | const QPointF globalPosF = e->globalPosF(); | ||
917 | const QPointF localPosF = globalPosF - localOriginInGlobal; | 909 | const QPointF localPosF = globalPosF - localOriginInGlobal; | ||
918 | return performRouteMouseOrTabletEvent( eventType, button, localPosF, item ); | 910 | return performRouteMouseOrTabletEvent( eventType, button, localPosF, item ); | ||
919 | } | 911 | } | ||
920 | 912 | | |||
921 | bool PageViewAnnotator::routeKeyEvent( QKeyEvent * event ) | 913 | bool PageViewAnnotator::routeKeyEvent( QKeyEvent * event ) | ||
922 | { | 914 | { | ||
923 | if ( event->key() == Qt::Key_Escape ) | 915 | if ( event->key() == Qt::Key_Escape ) | ||
924 | { | 916 | { | ||
925 | detachAnnotation(); | 917 | detachAnnotation(); | ||
926 | return true; | 918 | return true; | ||
927 | } | 919 | } | ||
928 | return false; | 920 | return false; | ||
929 | } | 921 | } | ||
930 | 922 | | |||
931 | bool PageViewAnnotator::routePaints( const QRect & wantedRect ) const | 923 | bool PageViewAnnotator::routePaints( const QRect & wantedRect ) const | ||
932 | { | 924 | { | ||
933 | return m_engine && m_toolBar && wantedRect.intersects( m_lastDrawnRect ) && m_lockedItem; | 925 | return m_engine && wantedRect.intersects( m_lastDrawnRect ) && m_lockedItem; | ||
934 | } | 926 | } | ||
935 | 927 | | |||
936 | void PageViewAnnotator::routePaint( QPainter * painter, const QRect & paintRect ) | 928 | void PageViewAnnotator::routePaint( QPainter * painter, const QRect & paintRect ) | ||
937 | { | 929 | { | ||
938 | // if there's no locked item, then there's no decided place to draw on | 930 | // if there's no locked item, then there's no decided place to draw on | ||
939 | if ( !m_lockedItem ) | 931 | if ( !m_lockedItem ) | ||
940 | return; | 932 | return; | ||
941 | 933 | | |||
Show All 12 Lines | 938 | #endif | |||
954 | QRect annotRect = paintRect.intersected( m_lastDrawnRect ); | 946 | QRect annotRect = paintRect.intersected( m_lastDrawnRect ); | ||
955 | annotRect.translate( -itemRect.topLeft() ); | 947 | annotRect.translate( -itemRect.topLeft() ); | ||
956 | 948 | | |||
957 | // use current engine for painting (in virtual page coordinates) | 949 | // use current engine for painting (in virtual page coordinates) | ||
958 | m_engine->paint( painter, m_lockedItem->uncroppedWidth(), m_lockedItem->uncroppedHeight(), annotRect ); | 950 | m_engine->paint( painter, m_lockedItem->uncroppedWidth(), m_lockedItem->uncroppedHeight(), annotRect ); | ||
959 | painter->restore(); | 951 | painter->restore(); | ||
960 | } | 952 | } | ||
961 | 953 | | |||
962 | void PageViewAnnotator::slotToolSelected( int toolID ) | 954 | void PageViewAnnotator::selectTool( int toolID ) | ||
955 | { | ||||
956 | | ||||
957 | // ask for Author's name if not already set | ||||
958 | if ( toolID > 0 && Okular::Settings::identityAuthor().isEmpty() ) | ||||
963 | { | 959 | { | ||
960 | // get default username from the kdelibs/kdecore/KUser | ||||
961 | KUser currentUser; | ||||
962 | QString userName = currentUser.property( KUser::FullName ).toString(); | ||||
963 | userName = ""; | ||||
964 | // ask the user for confirmation/change | ||||
965 | if ( userName.isEmpty() ) | ||||
966 | { | ||||
967 | bool ok = false; | ||||
968 | userName = QInputDialog::getText(nullptr, | ||||
969 | i18n( "Bookmark annotation" ), | ||||
970 | i18n( "Insert a custom name for the annotation:" ), | ||||
971 | QLineEdit::Normal, | ||||
972 | QString(), | ||||
973 | &ok ); | ||||
974 | | ||||
975 | if ( !ok ) | ||||
976 | { | ||||
977 | detachAnnotation(); | ||||
978 | return; | ||||
979 | } | ||||
980 | } | ||||
981 | // save the name | ||||
982 | Okular::Settings::setIdentityAuthor( userName ); | ||||
983 | Okular::Settings::self()->save(); | ||||
984 | } | ||||
985 | | ||||
964 | // terminate any previous operation | 986 | // terminate any previous operation | ||
965 | if ( m_engine ) | 987 | if ( m_engine ) | ||
966 | { | 988 | { | ||
967 | delete m_engine; | 989 | delete m_engine; | ||
968 | m_engine = nullptr; | 990 | m_engine = nullptr; | ||
969 | } | 991 | } | ||
970 | m_lockedItem = nullptr; | 992 | m_lockedItem = nullptr; | ||
971 | if ( m_lastDrawnRect.isValid() ) | 993 | if ( m_lastDrawnRect.isValid() ) | ||
972 | { | 994 | { | ||
973 | m_pageView->viewport()->update( m_lastDrawnRect.translated( -m_pageView->contentAreaPosition() ) ); | 995 | m_pageView->viewport()->update( m_lastDrawnRect.translated( -m_pageView->contentAreaPosition() ) ); | ||
974 | m_lastDrawnRect = QRect(); | 996 | m_lastDrawnRect = QRect(); | ||
975 | } | 997 | } | ||
976 | 998 | | |||
977 | if ( toolID != m_lastToolID ) m_continuousMode = false; | | |||
978 | // store current tool for later usage | 999 | // store current tool for later usage | ||
979 | m_lastToolID = toolID; | 1000 | m_lastToolID = toolID; | ||
980 | 1001 | | |||
981 | // handle tool deselection | 1002 | // handle tool deselection | ||
982 | if ( toolID == -1 ) | 1003 | if ( toolID == -1 ) | ||
983 | { | 1004 | { | ||
984 | m_pageView->displayMessage( QString() ); | 1005 | m_pageView->displayMessage( QString() ); | ||
985 | m_pageView->updateCursor(); | 1006 | m_pageView->updateCursor(); | ||
986 | return; | 1007 | return; | ||
987 | } | 1008 | } | ||
988 | 1009 | | |||
989 | // for the selected tool create the Engine | 1010 | // for the selected tool create the Engine | ||
990 | QDomNode toolNode = m_toolsDefinition.firstChild(); | 1011 | QDomElement toolElement = m_toolsDefinition->tool( toolID ); | ||
991 | while ( toolNode.isElement() ) | 1012 | if ( !toolElement.isNull() ) | ||
992 | { | 1013 | { | ||
993 | QDomElement toolElement = toolNode.toElement(); | | |||
994 | toolNode = toolNode.nextSibling(); | | |||
995 | | ||||
996 | // only find out the element describing selected tool | | |||
997 | if ( toolElement.tagName() != QLatin1String("tool") || toolElement.attribute(QStringLiteral("id")).toInt() != toolID ) | | |||
998 | continue; | | |||
999 | | ||||
1000 | // parse tool properties | 1014 | // parse tool properties | ||
1001 | QDomNode toolSubNode = toolElement.firstChild(); | 1015 | QDomElement engineElement = toolElement.firstChildElement( QStringLiteral("engine") ); | ||
1002 | while ( toolSubNode.isElement() ) | 1016 | if ( !engineElement.isNull() ) | ||
1003 | { | 1017 | { | ||
1004 | QDomElement toolSubElement = toolSubNode.toElement(); | | |||
1005 | toolSubNode = toolSubNode.nextSibling(); | | |||
1006 | | ||||
1007 | // create the AnnotatorEngine | 1018 | // create the AnnotatorEngine | ||
1008 | if ( toolSubElement.tagName() == QLatin1String("engine") ) | 1019 | QString type = engineElement.attribute( QStringLiteral("type") ); | ||
1009 | { | | |||
1010 | QString type = toolSubElement.attribute( QStringLiteral("type") ); | | |||
1011 | if ( type == QLatin1String("SmoothLine") ) | 1020 | if ( type == QLatin1String("SmoothLine") ) | ||
1012 | m_engine = new SmoothPathEngine( toolSubElement ); | 1021 | m_engine = new SmoothPathEngine( engineElement ); | ||
1013 | else if ( type == QLatin1String("PickPoint") ) | 1022 | else if ( type == QLatin1String("PickPoint") ) | ||
1014 | m_engine = new PickPointEngine( toolSubElement ); | 1023 | m_engine = new PickPointEngine( engineElement ); | ||
1015 | else if ( type == QLatin1String("PolyLine") ) | 1024 | else if ( type == QLatin1String("PolyLine") ) | ||
1016 | m_engine = new PolyLineEngine( toolSubElement ); | 1025 | m_engine = new PolyLineEngine( engineElement ); | ||
1017 | else if ( type == QLatin1String("TextSelector") ) | 1026 | else if ( type == QLatin1String("TextSelector") ) | ||
1018 | m_engine = new TextSelectorEngine( toolSubElement, m_pageView ); | 1027 | m_engine = new TextSelectorEngine( engineElement, m_pageView ); | ||
1019 | else | 1028 | else | ||
1020 | qCWarning(OkularUiDebug).nospace() << "tools.xml: engine type:'" << type << "' is not defined!"; | 1029 | qCWarning(OkularUiDebug).nospace() << "tools.xml: engine type:'" << type << "' is not defined!"; | ||
1021 | } | | |||
1022 | 1030 | | |||
1023 | // display the tooltip | 1031 | // display the tooltip | ||
1024 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | 1032 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | ||
1025 | QString tip; | 1033 | QString tip; | ||
1026 | 1034 | | |||
1027 | if ( annotType == QLatin1String("ellipse") ) | 1035 | if ( annotType == QLatin1String("ellipse") ) | ||
1028 | tip = i18nc( "Annotation tool", "Draw an ellipse (drag to select a zone)" ); | 1036 | tip = i18nc( "Annotation tool", "Draw an ellipse (drag to select a zone)" ); | ||
1029 | else if ( annotType == QLatin1String("highlight") ) | 1037 | else if ( annotType == QLatin1String("highlight") ) | ||
Show All 27 Lines | |||||
1057 | 1065 | | |||
1058 | // consistency warning | 1066 | // consistency warning | ||
1059 | if ( !m_engine ) | 1067 | if ( !m_engine ) | ||
1060 | { | 1068 | { | ||
1061 | qCWarning(OkularUiDebug) << "tools.xml: couldn't find good engine description. check xml."; | 1069 | qCWarning(OkularUiDebug) << "tools.xml: couldn't find good engine description. check xml."; | ||
1062 | } | 1070 | } | ||
1063 | 1071 | | |||
1064 | m_pageView->updateCursor(); | 1072 | m_pageView->updateCursor(); | ||
1065 | // stop after parsing selected tool's node | | |||
1066 | break; | | |||
1067 | } | 1073 | } | ||
1074 | | ||||
1075 | if( toolID > 0 ) | ||||
1076 | emit toolSelected(); | ||||
1077 | } | ||||
1078 | | ||||
1079 | int PageViewAnnotator::setFavoriteTool( int favToolID ) | ||||
1080 | { | ||||
1081 | QDomElement favToolElement = m_favoriteToolsDefinition->tool( favToolID ); | ||||
1082 | int toolID = favToolElement.attribute( QStringLiteral("sourceId") ).toInt(); | ||||
1083 | m_toolsDefinition->updateTool( favToolElement, toolID ); | ||||
1084 | saveAnnotationTools(); | ||||
1085 | return toolID; | ||||
1086 | } | ||||
1087 | | ||||
1088 | void PageViewAnnotator::setStampSymbol( QString stampSymbol ) | ||||
1089 | { | ||||
1090 | QDomElement toolElement = builtinTool( 14 ); | ||||
1091 | QDomElement engineElement = toolElement.firstChildElement( QStringLiteral("engine") ); | ||||
1092 | QDomElement annotationElement = engineElement.firstChildElement( QStringLiteral("annotation") ); | ||||
1093 | engineElement.setAttribute( QStringLiteral( "hoverIcon" ), stampSymbol ); | ||||
1094 | annotationElement.setAttribute( QStringLiteral( "icon" ), stampSymbol ); | ||||
1095 | saveAnnotationTools(); | ||||
1068 | } | 1096 | } | ||
1069 | 1097 | | |||
1070 | void PageViewAnnotator::slotSaveToolbarOrientation( int side ) | 1098 | void PageViewAnnotator::bookmarkAnnotation() | ||
1071 | { | 1099 | { | ||
1072 | Okular::Settings::setEditToolBarPlacement( (int)side ); | 1100 | QDomElement sourceToolElement = m_toolsDefinition->tool( m_lastToolID ); | ||
1101 | if( sourceToolElement.isNull() ) | ||||
1102 | return; | ||||
1103 | | ||||
1104 | bool ok = false; | ||||
1105 | QString itemText = QInputDialog::getText(nullptr, | ||||
1106 | i18n( "Add favorite annotation" ), | ||||
1107 | i18n( "Custom annotation name:" ), | ||||
1108 | QLineEdit::Normal, | ||||
1109 | defaultToolName( sourceToolElement ), | ||||
1110 | &ok ); | ||||
1111 | if( !ok ) | ||||
1112 | return; | ||||
1113 | | ||||
1114 | QDomElement toolElement = sourceToolElement.cloneNode().toElement(); | ||||
1115 | // Store name attribute only if the user specified a customized name | ||||
1116 | if ( !itemText.isEmpty() ) | ||||
1117 | toolElement.setAttribute( QStringLiteral("name"), itemText ); | ||||
1118 | toolElement.setAttribute( QStringLiteral("sourceId"), sourceToolElement.attribute( QStringLiteral("id") ) ); | ||||
1119 | m_favoriteToolsDefinition->appendTool( toolElement ); | ||||
1120 | saveAnnotationTools(); | ||||
1121 | } | ||||
1122 | | ||||
1123 | void PageViewAnnotator::setContinuousMode( bool enabled ) | ||||
1124 | { | ||||
1125 | m_continuousMode = enabled; | ||||
1126 | Okular::Settings::setAnnotationContinuousMode( enabled ); | ||||
1073 | Okular::Settings::self()->save(); | 1127 | Okular::Settings::self()->save(); | ||
1074 | } | 1128 | } | ||
1075 | 1129 | | |||
1076 | void PageViewAnnotator::slotToolDoubleClicked( int /*toolID*/ ) | 1130 | void PageViewAnnotator::slotAdvancedSettings() | ||
1131 | { | ||||
1132 | QDomElement toolElement = m_toolsDefinition->tool( m_lastToolID ); | ||||
1133 | EditAnnotToolDialog t( nullptr, toolElement, true ); | ||||
1134 | | ||||
1135 | if ( t.exec() != QDialog::Accepted ) | ||||
1136 | return; | ||||
1137 | | ||||
1138 | QDomElement toolElementUpdated = t.toolXml().documentElement(); | ||||
1139 | int toolID = toolElement.attribute( QStringLiteral("id") ).toInt(); | ||||
1140 | m_toolsDefinition->updateTool( toolElementUpdated, toolID ); | ||||
1141 | saveAnnotationTools(); | ||||
1142 | selectTool( m_lastToolID ); | ||||
1143 | } | ||||
1144 | | ||||
1145 | QDomElement PageViewAnnotator::builtinTool( int toolID ) | ||||
1146 | { | ||||
1147 | return m_toolsDefinition->tool( toolID ); | ||||
1148 | } | ||||
1149 | | ||||
1150 | QDomElement PageViewAnnotator::favoriteTool( int toolID ) | ||||
1077 | { | 1151 | { | ||
1078 | m_continuousMode = true; | 1152 | return m_favoriteToolsDefinition->tool( toolID ); | ||
1153 | } | ||||
1154 | | ||||
1155 | QDomElement PageViewAnnotator::currentEngineElement() | ||||
1156 | { | ||||
1157 | return m_toolsDefinition->tool( m_lastToolID ).firstChildElement( QStringLiteral("engine") ); | ||||
1158 | } | ||||
1159 | | ||||
1160 | QDomElement PageViewAnnotator::currentAnnotationElement() | ||||
1161 | { | ||||
1162 | return currentEngineElement().firstChildElement( QStringLiteral("annotation") ); | ||||
1163 | } | ||||
1164 | | ||||
1165 | bool PageViewAnnotator::continuousMode() | ||||
1166 | { | ||||
1167 | return m_continuousMode; | ||||
1168 | } | ||||
1169 | | ||||
1170 | void PageViewAnnotator::setAnnotationColor( QColor color ) | ||||
1171 | { | ||||
1172 | currentEngineElement().setAttribute( QStringLiteral( "color" ), color.name(QColor::HexRgb ) ); | ||||
1173 | QDomElement annotationElement = currentAnnotationElement(); | ||||
1174 | QString annotType = annotationElement.attribute( QStringLiteral( "type" ) ); | ||||
1175 | if ( annotType == "Typewriter" || annotType == "FreeText" ) { | ||||
1176 | annotationElement.setAttribute( QStringLiteral( "textColor" ), color.name( QColor::HexRgb ) ); | ||||
1177 | } else { | ||||
1178 | annotationElement.setAttribute( QStringLiteral( "color" ), color.name( QColor::HexRgb ) ); | ||||
1179 | } | ||||
1180 | saveAnnotationTools(); | ||||
1181 | selectTool( m_lastToolID ); | ||||
1182 | } | ||||
1183 | | ||||
1184 | void PageViewAnnotator::setAnnotationInnerColor( QColor color ) | ||||
1185 | { | ||||
1186 | QDomElement annotationElement = currentAnnotationElement(); | ||||
1187 | QString annotType = annotationElement.attribute( QStringLiteral( "type" ) ); | ||||
1188 | if ( annotType == "FreeText" ) { | ||||
1189 | annotationElement.setAttribute( QStringLiteral( "color" ), color.name( QColor::HexRgb ) ); | ||||
1190 | } else { | ||||
1191 | annotationElement.setAttribute( QStringLiteral( "innerColor" ), color.name( QColor::HexRgb ) ); | ||||
1192 | } | ||||
1193 | saveAnnotationTools(); | ||||
1194 | selectTool( m_lastToolID ); | ||||
1195 | } | ||||
1196 | | ||||
1197 | void PageViewAnnotator::setAnnotationOpacity( double opacity ) | ||||
1198 | { | ||||
1199 | currentAnnotationElement().setAttribute( QStringLiteral( "opacity" ), opacity ); | ||||
1200 | saveAnnotationTools(); | ||||
1201 | selectTool( m_lastToolID ); | ||||
1202 | } | ||||
1203 | | ||||
1204 | void PageViewAnnotator::setAnnotationFont( QFont font ) | ||||
1205 | { | ||||
1206 | currentAnnotationElement().setAttribute( QStringLiteral( "font" ), font.toString() ); | ||||
1207 | saveAnnotationTools(); | ||||
1208 | selectTool( m_lastToolID ); | ||||
1209 | } | ||||
1210 | | ||||
1211 | void PageViewAnnotator::setAnnotationWidth( double width) | ||||
1212 | { | ||||
1213 | currentAnnotationElement().setAttribute( QStringLiteral( "width" ), width ); | ||||
1214 | saveAnnotationTools(); | ||||
1215 | selectTool( m_lastToolID ); | ||||
1079 | } | 1216 | } | ||
1080 | 1217 | | |||
1081 | void PageViewAnnotator::detachAnnotation() | 1218 | void PageViewAnnotator::detachAnnotation() | ||
1082 | { | 1219 | { | ||
1083 | m_toolBar->selectButton( -1 ); | 1220 | selectTool( -1 ); | ||
1221 | if( m_actionHandler ) | ||||
1222 | m_actionHandler->deselectAllAnnotationActions(); | ||||
1223 | } | ||||
1224 | | ||||
1225 | void PageViewAnnotator::saveAnnotationTools() | ||||
1226 | { | ||||
1227 | Okular::Settings::setAnnotationTools( m_toolsDefinition->toStringList() ); | ||||
1228 | Okular::Settings::setFavoriteAnnotationTools( m_favoriteToolsDefinition->toStringList() ); | ||||
1229 | Okular::Settings::self()->save(); | ||||
1084 | } | 1230 | } | ||
1085 | 1231 | | |||
1086 | QString PageViewAnnotator::defaultToolName( const QDomElement &toolElement ) | 1232 | QString PageViewAnnotator::defaultToolName( const QDomElement &toolElement ) | ||
1087 | { | 1233 | { | ||
1088 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | 1234 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | ||
1089 | 1235 | | |||
1090 | if ( annotType == QLatin1String("ellipse") ) | 1236 | if ( annotType == QLatin1String("ellipse") ) | ||
1091 | return i18n( "Ellipse" ); | 1237 | return i18n( "Ellipse" ); | ||
▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Line(s) | 1418 | { | |||
1273 | /* Unrecognized annotation type -- It shouldn't happen */ | 1419 | /* Unrecognized annotation type -- It shouldn't happen */ | ||
1274 | p.setPen( QPen( engineColor ) ); | 1420 | p.setPen( QPen( engineColor ) ); | ||
1275 | p.drawText( QPoint(20, 31), QStringLiteral("?") ); | 1421 | p.drawText( QPoint(20, 31), QStringLiteral("?") ); | ||
1276 | } | 1422 | } | ||
1277 | 1423 | | |||
1278 | return pixmap; | 1424 | return pixmap; | ||
1279 | } | 1425 | } | ||
1280 | 1426 | | |||
1427 | void PageViewAnnotator::setupActions( KActionCollection * ac ) | ||||
1428 | { | ||||
1429 | if ( !m_actionHandler ) | ||||
1430 | { | ||||
1431 | m_actionHandler = new AnnotationActionHandler( this, ac ); | ||||
1432 | connect( m_actionHandler, &AnnotationActionHandler::advancedSettingsTriggered, this, &PageViewAnnotator::slotAdvancedSettings ); | ||||
1433 | } | ||||
1434 | } | ||||
1435 | | ||||
1281 | #include "moc_pageviewannotator.cpp" | 1436 | #include "moc_pageviewannotator.cpp" | ||
1282 | 1437 | | |||
1283 | /* kate: replace-tabs on; indent-width 4; */ | 1438 | /* kate: replace-tabs on; indent-width 4; */ |