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