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 477 Lines • ▼ Show 20 Line(s) | 647 | private: | |||
654 | QRect rect; | 653 | QRect rect; | ||
655 | }; | 654 | }; | ||
656 | 655 | | |||
657 | 656 | | |||
658 | /** PageViewAnnotator **/ | 657 | /** PageViewAnnotator **/ | ||
659 | 658 | | |||
660 | PageViewAnnotator::PageViewAnnotator( PageView * parent, Okular::Document * storage ) | 659 | PageViewAnnotator::PageViewAnnotator( PageView * parent, Okular::Document * storage ) | ||
661 | : QObject( parent ), m_document( storage ), m_pageView( parent ), | 660 | : QObject( parent ), m_document( storage ), m_pageView( parent ), | ||
662 | m_toolBar( nullptr ), m_engine( nullptr ), m_textToolsEnabled( false ), m_toolsEnabled( false ), | 661 | m_actionHandler( nullptr ), m_engine( nullptr ), m_continuousMode( true ), | ||
663 | m_continuousMode( false ), m_hidingWasForced( false ), m_lastToolID( -1 ), m_lockedItem( nullptr ) | 662 | m_lastToolID( -1 ), m_lockedItem( nullptr ) | ||
664 | { | 663 | { | ||
665 | reparseConfig(); | 664 | reparseConfig(); | ||
666 | } | 665 | } | ||
667 | 666 | | |||
668 | void PageViewAnnotator::reparseConfig() | 667 | void PageViewAnnotator::reparseConfig() | ||
669 | { | 668 | { | ||
670 | m_items.clear(); | | |||
671 | | ||||
672 | // Read tool list from configuration. It's a list of XML <tool></tool> elements | 669 | // Read tool list from configuration. It's a list of XML <tool></tool> elements | ||
673 | const QStringList userTools = Okular::Settings::annotationTools(); | 670 | const QStringList userTools = Okular::Settings::annotationTools(); | ||
674 | 671 | | |||
675 | // Populate m_toolsDefinition | 672 | // Populate m_toolsDefinition | ||
676 | QDomDocument doc; | 673 | QDomElement root = m_toolsDefinition.createElement( QStringLiteral("annotatingTools") ); | ||
677 | m_toolsDefinition = doc.createElement( QStringLiteral("annotatingTools") ); | 674 | m_toolsDefinition.appendChild( root ); | ||
678 | foreach ( const QString &toolXml, userTools ) | 675 | foreach ( const QString &toolXml, userTools ) | ||
679 | { | 676 | { | ||
680 | QDomDocument entryParser; | 677 | QDomDocument entryParser; | ||
681 | if ( entryParser.setContent( toolXml ) ) | 678 | if ( entryParser.setContent( toolXml ) ) | ||
682 | m_toolsDefinition.appendChild( doc.importNode( entryParser.documentElement(), true ) ); | 679 | root.appendChild( m_toolsDefinition.importNode( entryParser.documentElement(), true ) ); | ||
683 | else | 680 | else | ||
684 | qCWarning(OkularUiDebug) << "Skipping malformed tool XML in AnnotationTools setting"; | 681 | qCWarning(OkularUiDebug) << "Skipping malformed tool XML in AnnotationTools setting"; | ||
685 | } | 682 | } | ||
686 | 683 | | |||
687 | // Create the AnnotationToolItems from the XML dom tree | 684 | if ( Okular::Settings::identityAuthor().isEmpty() ) | ||
688 | QDomNode toolDescription = m_toolsDefinition.firstChild(); | 685 | detachAnnotation(); | ||
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 | { | | |||
707 | QDomElement engineEl = engineNodeList.item( 0 ).toElement(); | | |||
708 | if ( !engineEl.isNull() && engineEl.hasAttribute( QStringLiteral("type") ) ) | | |||
709 | item.isText = engineEl.attribute( QStringLiteral("type") ) == QLatin1String( "TextSelector" ); | | |||
710 | } | | |||
711 | m_items.push_back( item ); | | |||
712 | } | | |||
713 | toolDescription = toolDescription.nextSibling(); | | |||
714 | } | | |||
715 | } | 686 | } | ||
716 | 687 | | |||
717 | PageViewAnnotator::~PageViewAnnotator() | 688 | PageViewAnnotator::~PageViewAnnotator() | ||
718 | { | 689 | { | ||
719 | delete m_engine; | 690 | delete m_engine; | ||
720 | } | 691 | } | ||
721 | 692 | | |||
722 | void PageViewAnnotator::setEnabled( bool on ) | 693 | void PageViewAnnotator::setEnabled( bool on ) | ||
723 | { | 694 | { | ||
724 | if ( !on ) | 695 | if ( !on ) | ||
725 | { | 696 | { | ||
726 | // remove toolBar | | |||
727 | if ( m_toolBar ) | | |||
728 | m_toolBar->hideAndDestroy(); | | |||
729 | m_toolBar = nullptr; | | |||
730 | // deactivate the active tool, if any | 697 | // deactivate the active tool, if any | ||
731 | slotToolSelected( -1 ); | 698 | selectTool( -1 ); | ||
732 | return; | 699 | return; | ||
733 | } | 700 | } | ||
734 | | ||||
735 | // if no tools are defined, don't show the toolbar | | |||
736 | if ( !m_toolsDefinition.hasChildNodes() ) | | |||
737 | return; | | |||
738 | | ||||
739 | // create toolBar | | |||
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 | | ||||
750 | connect(m_toolBar, &PageViewToolBar::buttonDoubleClicked, this, &PageViewAnnotator::slotToolDoubleClicked); | | |||
751 | m_toolBar->setCursor(Qt::ArrowCursor); | | |||
752 | } | | |||
753 | | ||||
754 | // show the toolBar | | |||
755 | m_toolBar->showAndAnimate(); | | |||
756 | } | 701 | } | ||
757 | 702 | | |||
758 | void PageViewAnnotator::setTextToolsEnabled( bool enabled ) | 703 | void PageViewAnnotator::setTextToolsEnabled( bool enabled ) | ||
759 | { | 704 | { | ||
760 | m_textToolsEnabled = enabled; | 705 | if ( m_actionHandler ) | ||
761 | if ( m_toolBar ) | 706 | m_actionHandler->setTextToolsEnabled( enabled ); | ||
762 | m_toolBar->setTextToolsEnabled( m_textToolsEnabled ); | | |||
763 | } | 707 | } | ||
764 | 708 | | |||
765 | void PageViewAnnotator::setToolsEnabled( bool enabled ) | 709 | void PageViewAnnotator::setToolsEnabled( bool enabled ) | ||
766 | { | 710 | { | ||
767 | m_toolsEnabled = enabled; | 711 | if ( m_actionHandler ) | ||
768 | if ( m_toolBar ) | 712 | m_actionHandler->setToolsEnabled( enabled ); | ||
769 | m_toolBar->setToolsEnabled( m_toolsEnabled ); | | |||
770 | } | | |||
771 | | ||||
772 | void PageViewAnnotator::setHidingForced( bool forced ) | | |||
773 | { | | |||
774 | m_hidingWasForced = forced; | | |||
775 | } | | |||
776 | | ||||
777 | bool PageViewAnnotator::hidingWasForced() const | | |||
778 | { | | |||
779 | return m_hidingWasForced; | | |||
780 | } | 713 | } | ||
781 | 714 | | |||
782 | bool PageViewAnnotator::active() const | 715 | bool PageViewAnnotator::active() const | ||
783 | { | 716 | { | ||
784 | return m_engine && m_toolBar; | 717 | return m_engine != nullptr; | ||
785 | } | 718 | } | ||
786 | 719 | | |||
787 | bool PageViewAnnotator::annotating() const | 720 | bool PageViewAnnotator::annotating() const | ||
788 | { | 721 | { | ||
789 | return active() && m_lockedItem; | 722 | return active() && m_lockedItem; | ||
790 | } | 723 | } | ||
791 | 724 | | |||
792 | QCursor PageViewAnnotator::cursor() const | 725 | QCursor PageViewAnnotator::cursor() const | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 787 | { | |||
859 | annotation->setAuthor( Okular::Settings::identityAuthor() ); | 792 | annotation->setAuthor( Okular::Settings::identityAuthor() ); | ||
860 | m_document->addPageAnnotation( m_lockedItem->pageNumber(), annotation ); | 793 | m_document->addPageAnnotation( m_lockedItem->pageNumber(), annotation ); | ||
861 | 794 | | |||
862 | if ( annotation->openDialogAfterCreation() ) | 795 | if ( annotation->openDialogAfterCreation() ) | ||
863 | m_pageView->openAnnotationWindow( annotation, m_lockedItem->pageNumber() ); | 796 | m_pageView->openAnnotationWindow( annotation, m_lockedItem->pageNumber() ); | ||
864 | } | 797 | } | ||
865 | 798 | | |||
866 | if ( m_continuousMode ) | 799 | if ( m_continuousMode ) | ||
867 | slotToolSelected( m_lastToolID ); | 800 | selectTool( m_lastToolID ); | ||
868 | else | 801 | else | ||
869 | detachAnnotation(); | 802 | detachAnnotation(); | ||
870 | } | 803 | } | ||
871 | 804 | | |||
872 | return modifiedRect; | 805 | return modifiedRect; | ||
873 | } | 806 | } | ||
874 | 807 | | |||
875 | QRect PageViewAnnotator::routeMouseEvent( QMouseEvent * e, PageViewItem * item ) | 808 | QRect PageViewAnnotator::routeMouseEvent( QMouseEvent * e, PageViewItem * item ) | ||
Show All 12 Lines | 820 | { | |||
888 | // Unlike routeMouseEvent, routeTabletEvent must explicitly ignore events it doesn't care about so that | 821 | // Unlike routeMouseEvent, routeTabletEvent must explicitly ignore events it doesn't care about so that | ||
889 | // the corresponding mouse event will later be delivered. | 822 | // the corresponding mouse event will later be delivered. | ||
890 | if ( !item ) | 823 | if ( !item ) | ||
891 | { | 824 | { | ||
892 | e->ignore(); | 825 | e->ignore(); | ||
893 | return QRect(); | 826 | return QRect(); | ||
894 | } | 827 | } | ||
895 | 828 | | |||
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; | 829 | AnnotatorEngine::EventType eventType; | ||
909 | AnnotatorEngine::Button button; | 830 | AnnotatorEngine::Button button; | ||
910 | 831 | | |||
911 | // figure out the event type and button | 832 | // figure out the event type and button | ||
912 | AnnotatorEngine::decodeEvent( e, &eventType, &button ); | 833 | AnnotatorEngine::decodeEvent( e, &eventType, &button ); | ||
913 | 834 | | |||
914 | const QPointF globalPosF = e->globalPosF(); | 835 | const QPointF globalPosF = e->globalPosF(); | ||
915 | const QPointF localPosF = globalPosF - localOriginInGlobal; | 836 | const QPointF localPosF = globalPosF - localOriginInGlobal; | ||
916 | return performRouteMouseOrTabletEvent( eventType, button, localPosF, item ); | 837 | return performRouteMouseOrTabletEvent( eventType, button, localPosF, item ); | ||
917 | } | 838 | } | ||
918 | 839 | | |||
919 | bool PageViewAnnotator::routeKeyEvent( QKeyEvent * event ) | 840 | bool PageViewAnnotator::routeKeyEvent( QKeyEvent * event ) | ||
920 | { | 841 | { | ||
921 | if ( event->key() == Qt::Key_Escape ) | 842 | if ( event->key() == Qt::Key_Escape ) | ||
922 | { | 843 | { | ||
923 | detachAnnotation(); | 844 | detachAnnotation(); | ||
924 | return true; | 845 | return true; | ||
925 | } | 846 | } | ||
926 | return false; | 847 | return false; | ||
927 | } | 848 | } | ||
928 | 849 | | |||
929 | bool PageViewAnnotator::routePaints( const QRect & wantedRect ) const | 850 | bool PageViewAnnotator::routePaints( const QRect & wantedRect ) const | ||
930 | { | 851 | { | ||
931 | return m_engine && m_toolBar && wantedRect.intersects( m_lastDrawnRect ) && m_lockedItem; | 852 | return m_engine && wantedRect.intersects( m_lastDrawnRect ) && m_lockedItem; | ||
932 | } | 853 | } | ||
933 | 854 | | |||
934 | void PageViewAnnotator::routePaint( QPainter * painter, const QRect & paintRect ) | 855 | void PageViewAnnotator::routePaint( QPainter * painter, const QRect & paintRect ) | ||
935 | { | 856 | { | ||
936 | // if there's no locked item, then there's no decided place to draw on | 857 | // if there's no locked item, then there's no decided place to draw on | ||
937 | if ( !m_lockedItem ) | 858 | if ( !m_lockedItem ) | ||
938 | return; | 859 | return; | ||
939 | 860 | | |||
Show All 12 Lines | 865 | #endif | |||
952 | QRect annotRect = paintRect.intersected( m_lastDrawnRect ); | 873 | QRect annotRect = paintRect.intersected( m_lastDrawnRect ); | ||
953 | annotRect.translate( -itemRect.topLeft() ); | 874 | annotRect.translate( -itemRect.topLeft() ); | ||
954 | 875 | | |||
955 | // use current engine for painting (in virtual page coordinates) | 876 | // use current engine for painting (in virtual page coordinates) | ||
956 | m_engine->paint( painter, m_lockedItem->uncroppedWidth(), m_lockedItem->uncroppedHeight(), annotRect ); | 877 | m_engine->paint( painter, m_lockedItem->uncroppedWidth(), m_lockedItem->uncroppedHeight(), annotRect ); | ||
957 | painter->restore(); | 878 | painter->restore(); | ||
958 | } | 879 | } | ||
959 | 880 | | |||
960 | void PageViewAnnotator::slotToolSelected( int toolID ) | 881 | void PageViewAnnotator::selectTool( int toolID ) | ||
961 | { | 882 | { | ||
883 | | ||||
884 | // ask for Author's name if not already set | ||||
885 | if ( toolID > 0 && Okular::Settings::identityAuthor().isEmpty() ) | ||||
886 | { | ||||
887 | // get default username from the kdelibs/kdecore/KUser | ||||
888 | KUser currentUser; | ||||
889 | QString userName = currentUser.property( KUser::FullName ).toString(); | ||||
890 | userName = ""; | ||||
891 | // ask the user for confirmation/change | ||||
892 | if ( userName.isEmpty() ) | ||||
893 | { | ||||
894 | bool ok = false; | ||||
895 | userName = QInputDialog::getText(nullptr, | ||||
896 | i18n( "Annotations author" ), | ||||
897 | i18n( "Please insert your name or initials:" ), | ||||
898 | QLineEdit::Normal, | ||||
899 | QString(), | ||||
900 | &ok ); | ||||
901 | | ||||
902 | if ( !ok ) | ||||
903 | { | ||||
904 | detachAnnotation(); | ||||
905 | return; | ||||
906 | } | ||||
907 | } | ||||
908 | // save the name | ||||
909 | Okular::Settings::setIdentityAuthor( userName ); | ||||
910 | Okular::Settings::self()->save(); | ||||
911 | } | ||||
912 | | ||||
962 | // terminate any previous operation | 913 | // terminate any previous operation | ||
963 | if ( m_engine ) | 914 | if ( m_engine ) | ||
964 | { | 915 | { | ||
965 | delete m_engine; | 916 | delete m_engine; | ||
966 | m_engine = nullptr; | 917 | m_engine = nullptr; | ||
967 | } | 918 | } | ||
968 | m_lockedItem = nullptr; | 919 | m_lockedItem = nullptr; | ||
969 | if ( m_lastDrawnRect.isValid() ) | 920 | if ( m_lastDrawnRect.isValid() ) | ||
970 | { | 921 | { | ||
971 | m_pageView->viewport()->update( m_lastDrawnRect.translated( -m_pageView->contentAreaPosition() ) ); | 922 | m_pageView->viewport()->update( m_lastDrawnRect.translated( -m_pageView->contentAreaPosition() ) ); | ||
972 | m_lastDrawnRect = QRect(); | 923 | m_lastDrawnRect = QRect(); | ||
973 | } | 924 | } | ||
974 | 925 | | |||
975 | if ( toolID != m_lastToolID ) m_continuousMode = false; | | |||
976 | // store current tool for later usage | 926 | // store current tool for later usage | ||
977 | m_lastToolID = toolID; | 927 | m_lastToolID = toolID; | ||
978 | 928 | | |||
979 | // handle tool deselection | 929 | // handle tool deselection | ||
980 | if ( toolID == -1 ) | 930 | if ( toolID == -1 ) | ||
981 | { | 931 | { | ||
982 | m_pageView->displayMessage( QString() ); | 932 | m_pageView->displayMessage( QString() ); | ||
983 | m_pageView->updateCursor(); | 933 | m_pageView->updateCursor(); | ||
984 | return; | 934 | return; | ||
985 | } | 935 | } | ||
986 | 936 | | |||
987 | // for the selected tool create the Engine | 937 | // for the selected tool create the Engine | ||
988 | QDomNode toolNode = m_toolsDefinition.firstChild(); | 938 | QDomElement toolElement = getToolElement( toolID ); | ||
989 | while ( toolNode.isElement() ) | 939 | if ( !toolElement.isNull() ) | ||
990 | { | 940 | { | ||
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 | 941 | // parse tool properties | ||
999 | QDomNode toolSubNode = toolElement.firstChild(); | 942 | QDomElement engineElement = toolElement.firstChildElement( QStringLiteral("engine") ); | ||
1000 | while ( toolSubNode.isElement() ) | 943 | if ( !engineElement.isNull() ) | ||
1001 | { | 944 | { | ||
1002 | QDomElement toolSubElement = toolSubNode.toElement(); | | |||
1003 | toolSubNode = toolSubNode.nextSibling(); | | |||
1004 | | ||||
1005 | // create the AnnotatorEngine | 945 | // create the AnnotatorEngine | ||
1006 | if ( toolSubElement.tagName() == QLatin1String("engine") ) | 946 | QString type = engineElement.attribute( QStringLiteral("type") ); | ||
1007 | { | | |||
1008 | QString type = toolSubElement.attribute( QStringLiteral("type") ); | | |||
1009 | if ( type == QLatin1String("SmoothLine") ) | 947 | if ( type == QLatin1String("SmoothLine") ) | ||
1010 | m_engine = new SmoothPathEngine( toolSubElement ); | 948 | m_engine = new SmoothPathEngine( engineElement ); | ||
1011 | else if ( type == QLatin1String("PickPoint") ) | 949 | else if ( type == QLatin1String("PickPoint") ) | ||
1012 | m_engine = new PickPointEngine( toolSubElement ); | 950 | m_engine = new PickPointEngine( engineElement ); | ||
1013 | else if ( type == QLatin1String("PolyLine") ) | 951 | else if ( type == QLatin1String("PolyLine") ) | ||
1014 | m_engine = new PolyLineEngine( toolSubElement ); | 952 | m_engine = new PolyLineEngine( engineElement ); | ||
1015 | else if ( type == QLatin1String("TextSelector") ) | 953 | else if ( type == QLatin1String("TextSelector") ) | ||
1016 | m_engine = new TextSelectorEngine( toolSubElement, m_pageView ); | 954 | m_engine = new TextSelectorEngine( engineElement, m_pageView ); | ||
1017 | else | 955 | else | ||
1018 | qCWarning(OkularUiDebug).nospace() << "tools.xml: engine type:'" << type << "' is not defined!"; | 956 | qCWarning(OkularUiDebug).nospace() << "tools.xml: engine type:'" << type << "' is not defined!"; | ||
1019 | } | | |||
1020 | 957 | | |||
1021 | // display the tooltip | 958 | // display the tooltip | ||
1022 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | 959 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | ||
1023 | QString tip; | 960 | QString tip; | ||
1024 | 961 | | |||
1025 | if ( annotType == QLatin1String("ellipse") ) | 962 | if ( annotType == QLatin1String("ellipse") ) | ||
1026 | tip = i18nc( "Annotation tool", "Draw an ellipse (drag to select a zone)" ); | 963 | tip = i18nc( "Annotation tool", "Draw an ellipse (drag to select a zone)" ); | ||
1027 | else if ( annotType == QLatin1String("highlight") ) | 964 | else if ( annotType == QLatin1String("highlight") ) | ||
Show All 27 Lines | |||||
1055 | 992 | | |||
1056 | // consistency warning | 993 | // consistency warning | ||
1057 | if ( !m_engine ) | 994 | if ( !m_engine ) | ||
1058 | { | 995 | { | ||
1059 | qCWarning(OkularUiDebug) << "tools.xml: couldn't find good engine description. check xml."; | 996 | qCWarning(OkularUiDebug) << "tools.xml: couldn't find good engine description. check xml."; | ||
1060 | } | 997 | } | ||
1061 | 998 | | |||
1062 | m_pageView->updateCursor(); | 999 | m_pageView->updateCursor(); | ||
1063 | // stop after parsing selected tool's node | | |||
1064 | break; | | |||
1065 | } | 1000 | } | ||
1001 | | ||||
1002 | if( toolID > 0 ) | ||||
1003 | emit toolSelected(); | ||||
1066 | } | 1004 | } | ||
1067 | 1005 | | |||
1068 | void PageViewAnnotator::slotSaveToolbarOrientation( int side ) | 1006 | void PageViewAnnotator::setContinuousMode( bool enabled ) | ||
1069 | { | 1007 | { | ||
1070 | Okular::Settings::setEditToolBarPlacement( (int)side ); | 1008 | m_continuousMode = enabled; | ||
1071 | Okular::Settings::self()->save(); | 1009 | } | ||
1010 | | ||||
1011 | QDomElement PageViewAnnotator::getToolElement( int toolID ) | ||||
1012 | { | ||||
1013 | QDomElement toolElement = m_toolsDefinition.documentElement().firstChildElement(); | ||||
1014 | while( !toolElement.isNull() && toolElement.attribute("id").toInt() != toolID ) { | ||||
1015 | toolElement = toolElement.nextSiblingElement(); | ||||
1016 | } | ||||
1017 | return toolElement; // can return a null element | ||||
1018 | } | ||||
1019 | | ||||
1020 | void PageViewAnnotator::slotAdvancedSettings() | ||||
1021 | { | ||||
1022 | QDomElement toolElement = getToolElement( m_lastToolID ); | ||||
1023 | EditAnnotToolDialog t( nullptr, toolElement); | ||||
1024 | | ||||
1025 | if ( t.exec() != QDialog::Accepted ) | ||||
1026 | return; | ||||
1027 | | ||||
1028 | QDomElement toolElementUpdated = t.toolXml().documentElement(); | ||||
1029 | toolElementUpdated.setAttribute( QStringLiteral("id"), toolElement.attribute( QStringLiteral("id") ) ); | ||||
1030 | toolElementUpdated.setAttribute( QStringLiteral("shortcut"), toolElement.attribute( QStringLiteral("shortcut") ) ); | ||||
1031 | m_toolsDefinition.documentElement().replaceChild( toolElementUpdated, toolElement ); | ||||
1032 | m_actionHandler->parseTool( m_lastToolID ); | ||||
1033 | selectTool( m_lastToolID ); | ||||
1034 | } | ||||
1035 | | ||||
1036 | QDomElement PageViewAnnotator::currentEngineElement() | ||||
1037 | { | ||||
1038 | return getToolElement( m_lastToolID ).firstChildElement( QStringLiteral("engine") ); | ||||
1039 | } | ||||
1040 | | ||||
1041 | QDomElement PageViewAnnotator::currentAnnotationElement() | ||||
1042 | { | ||||
1043 | return currentEngineElement().firstChildElement( QStringLiteral("annotation") ); | ||||
1044 | } | ||||
1045 | | ||||
1046 | void PageViewAnnotator::setAnnotationColor( QColor color ) | ||||
1047 | { | ||||
1048 | currentEngineElement().setAttribute( QStringLiteral( "color" ), color.name(QColor::HexRgb ) ); | ||||
1049 | QDomElement annotationElement = currentAnnotationElement(); | ||||
1050 | QString annotType = annotationElement.attribute( QStringLiteral( "type" ) ); | ||||
1051 | if ( annotType == "Typewriter" || annotType == "FreeText" ) { | ||||
1052 | annotationElement.setAttribute( QStringLiteral( "textColor" ), color.name( QColor::HexRgb ) ); | ||||
1053 | } else { | ||||
1054 | annotationElement.setAttribute( QStringLiteral( "color" ), color.name( QColor::HexRgb ) ); | ||||
1055 | } | ||||
1056 | selectTool( m_lastToolID ); | ||||
1057 | } | ||||
1058 | | ||||
1059 | void PageViewAnnotator::setAnnotationInnerColor( QColor color ) | ||||
1060 | { | ||||
1061 | QDomElement annotationElement = currentAnnotationElement(); | ||||
1062 | QString annotType = annotationElement.attribute( QStringLiteral( "type" ) ); | ||||
1063 | if ( annotType == "FreeText" ) { | ||||
1064 | annotationElement.setAttribute( QStringLiteral( "color" ), color.name( QColor::HexRgb ) ); | ||||
1065 | } else { | ||||
1066 | annotationElement.setAttribute( QStringLiteral( "innerColor" ), color.name( QColor::HexRgb ) ); | ||||
1067 | } | ||||
1068 | selectTool( m_lastToolID ); | ||||
1069 | } | ||||
1070 | | ||||
1071 | void PageViewAnnotator::setAnnotationOpacity( double opacity ) | ||||
1072 | { | ||||
1073 | currentAnnotationElement().setAttribute( QStringLiteral( "opacity" ), opacity ); | ||||
1074 | selectTool( m_lastToolID ); | ||||
1072 | } | 1075 | } | ||
1073 | 1076 | | |||
1074 | void PageViewAnnotator::slotToolDoubleClicked( int /*toolID*/ ) | 1077 | void PageViewAnnotator::setAnnotationFont( QFont font ) | ||
1075 | { | 1078 | { | ||
1076 | m_continuousMode = true; | 1079 | currentAnnotationElement().setAttribute( QStringLiteral( "font" ), font.toString() ); | ||
1080 | | ||||
1081 | selectTool( m_lastToolID ); | ||||
1082 | } | ||||
1083 | | ||||
1084 | void PageViewAnnotator::setAnnotationWidth( double width) | ||||
1085 | { | ||||
1086 | currentAnnotationElement().setAttribute( QStringLiteral( "width" ), width ); | ||||
1087 | | ||||
1088 | selectTool( m_lastToolID ); | ||||
1077 | } | 1089 | } | ||
1078 | 1090 | | |||
1079 | void PageViewAnnotator::detachAnnotation() | 1091 | void PageViewAnnotator::detachAnnotation() | ||
1080 | { | 1092 | { | ||
1081 | m_toolBar->selectButton( -1 ); | 1093 | selectTool( -1 ); | ||
1094 | if( m_actionHandler ) | ||||
1095 | m_actionHandler->deselectAllAnnotationActions(); | ||||
1096 | } | ||||
1097 | | ||||
1098 | void PageViewAnnotator::saveAnnotationTools() | ||||
1099 | { | ||||
1100 | QStringList tools; | ||||
1101 | QDomElement toolElement = m_toolsDefinition.documentElement().firstChildElement(); | ||||
1102 | QString str; | ||||
1103 | QTextStream stream(&str); | ||||
1104 | while( !toolElement.isNull() ) | ||||
1105 | { | ||||
1106 | str.clear(); | ||||
1107 | toolElement.save(stream, -1 /* indent disabled */); | ||||
1108 | tools << str; | ||||
1109 | toolElement = toolElement.nextSiblingElement(); | ||||
1110 | } | ||||
1111 | | ||||
1112 | Okular::Settings::setAnnotationTools(tools); | ||||
1113 | Okular::Settings::self()->save(); | ||||
1082 | } | 1114 | } | ||
1083 | 1115 | | |||
1084 | QString PageViewAnnotator::defaultToolName( const QDomElement &toolElement ) | 1116 | QString PageViewAnnotator::defaultToolName( const QDomElement &toolElement ) | ||
1085 | { | 1117 | { | ||
1086 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | 1118 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | ||
1087 | 1119 | | |||
1088 | if ( annotType == QLatin1String("ellipse") ) | 1120 | if ( annotType == QLatin1String("ellipse") ) | ||
1089 | return i18n( "Ellipse" ); | 1121 | return i18n( "Ellipse" ); | ||
▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Line(s) | 1302 | { | |||
1271 | /* Unrecognized annotation type -- It shouldn't happen */ | 1303 | /* Unrecognized annotation type -- It shouldn't happen */ | ||
1272 | p.setPen( QPen( engineColor ) ); | 1304 | p.setPen( QPen( engineColor ) ); | ||
1273 | p.drawText( QPoint(20, 31), QStringLiteral("?") ); | 1305 | p.drawText( QPoint(20, 31), QStringLiteral("?") ); | ||
1274 | } | 1306 | } | ||
1275 | 1307 | | |||
1276 | return pixmap; | 1308 | return pixmap; | ||
1277 | } | 1309 | } | ||
1278 | 1310 | | |||
1311 | void PageViewAnnotator::setupActions( KActionCollection * ac ) | ||||
1312 | { | ||||
1313 | if ( !m_actionHandler ) | ||||
1314 | { | ||||
1315 | m_actionHandler = new AnnotationActionHandler( this, ac ); | ||||
1316 | connect( m_actionHandler, &AnnotationActionHandler::advancedSettingsTriggered, this, &PageViewAnnotator::slotAdvancedSettings ); | ||||
1317 | } | ||||
1318 | } | ||||
1319 | | ||||
1279 | #include "moc_pageviewannotator.cpp" | 1320 | #include "moc_pageviewannotator.cpp" | ||
1280 | 1321 | | |||
1281 | /* kate: replace-tabs on; indent-width 4; */ | 1322 | /* kate: replace-tabs on; indent-width 4; */ |