Changeset View
Changeset View
Standalone View
Standalone View
ui/pageviewannotator.cpp
Show First 20 Lines • Show All 607 Lines • ▼ Show 20 Line(s) | 555 | { | |||
---|---|---|---|---|---|
608 | 608 | | |||
609 | selection.reset(); | 609 | selection.reset(); | ||
610 | 610 | | |||
611 | // safety check | 611 | // safety check | ||
612 | if ( !ann ) | 612 | if ( !ann ) | ||
613 | return QList< Okular::Annotation* >(); | 613 | return QList< Okular::Annotation* >(); | ||
614 | 614 | | |||
615 | // set common attributes | 615 | // set common attributes | ||
616 | ann->style().setColor( m_annotElement.hasAttribute( QStringLiteral("color") ) ? | 616 | //FIXME: What'0s the point of the inner color property? Why not always using m_engineColor | ||
617 | m_annotElement.attribute( QStringLiteral("color") ) : m_engineColor ); | 617 | // ann->style().setColor( m_annotElement.hasAttribute( QStringLiteral("color") ) ? | ||
618 | // m_annotElement.attribute( QStringLiteral("color") ) : m_engineColor ); | ||||
619 | ann->style().setColor( m_engineColor ); | ||||
618 | if ( m_annotElement.hasAttribute( QStringLiteral("opacity") ) ) | 620 | if ( m_annotElement.hasAttribute( QStringLiteral("opacity") ) ) | ||
619 | ann->style().setOpacity( m_annotElement.attribute( QStringLiteral("opacity"), QStringLiteral("1.0") ).toDouble() ); | 621 | ann->style().setOpacity( m_annotElement.attribute( QStringLiteral("opacity"), QStringLiteral("1.0") ).toDouble() ); | ||
620 | 622 | | |||
621 | // return annotations | 623 | // return annotations | ||
622 | return QList< Okular::Annotation* >() << ann; | 624 | return QList< Okular::Annotation* >() << ann; | ||
623 | } | 625 | } | ||
624 | 626 | | |||
625 | QCursor cursor() const override | 627 | QCursor cursor() const override | ||
Show All 11 Lines | |||||
637 | }; | 639 | }; | ||
638 | 640 | | |||
639 | 641 | | |||
640 | /** PageViewAnnotator **/ | 642 | /** PageViewAnnotator **/ | ||
641 | 643 | | |||
642 | PageViewAnnotator::PageViewAnnotator( PageView * parent, Okular::Document * storage ) | 644 | PageViewAnnotator::PageViewAnnotator( PageView * parent, Okular::Document * storage ) | ||
643 | : QObject( parent ), m_document( storage ), m_pageView( parent ), | 645 | : QObject( parent ), m_document( storage ), m_pageView( parent ), | ||
644 | m_toolBar( nullptr ), m_engine( nullptr ), m_textToolsEnabled( false ), m_toolsEnabled( false ), | 646 | m_toolBar( nullptr ), m_engine( nullptr ), m_textToolsEnabled( false ), m_toolsEnabled( false ), | ||
645 | m_continuousMode( false ), m_hidingWasForced( false ), m_lastToolID( -1 ), m_lockedItem( nullptr ) | 647 | m_continuousMode( true ), m_hidingWasForced( false ), m_lastToolID( -1 ), m_lockedItem( nullptr ) | ||
646 | { | 648 | { | ||
647 | reparseConfig(); | 649 | reparseConfig(); | ||
648 | } | 650 | } | ||
649 | 651 | | |||
650 | void PageViewAnnotator::reparseConfig() | 652 | void PageViewAnnotator::reparseConfig() | ||
651 | { | 653 | { | ||
652 | m_items.clear(); | 654 | m_items.clear(); | ||
653 | 655 | | |||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 702 | { | |||
701 | delete m_engine; | 703 | delete m_engine; | ||
702 | } | 704 | } | ||
703 | 705 | | |||
704 | void PageViewAnnotator::setEnabled( bool on ) | 706 | void PageViewAnnotator::setEnabled( bool on ) | ||
705 | { | 707 | { | ||
706 | if ( !on ) | 708 | if ( !on ) | ||
707 | { | 709 | { | ||
708 | // remove toolBar | 710 | // remove toolBar | ||
709 | if ( m_toolBar ) | | |||
710 | m_toolBar->hideAndDestroy(); | | |||
711 | m_toolBar = nullptr; | 711 | m_toolBar = nullptr; | ||
712 | // deactivate the active tool, if any | 712 | // deactivate the active tool, if any | ||
713 | slotToolSelected( -1 ); | 713 | slotToolSelected( -1 ); | ||
714 | return; | 714 | return; | ||
715 | } | 715 | } | ||
716 | 716 | | |||
717 | // if no tools are defined, don't show the toolbar | 717 | // if no tools are defined, don't show the toolbar | ||
718 | if ( !m_toolsDefinition.hasChildNodes() ) | 718 | if ( !m_toolsDefinition.hasChildNodes() ) | ||
719 | return; | 719 | return; | ||
720 | 720 | | |||
721 | // create toolBar | 721 | // create toolBar | ||
722 | if ( !m_toolBar ) | 722 | if ( !m_toolBar ) | ||
723 | { | 723 | { | ||
724 | m_toolBar = new PageViewToolBar( m_pageView, m_pageView->viewport() ); | 724 | m_toolBar = new PageViewToolBar( m_pageView ); | ||
725 | m_toolBar->setSide( (PageViewToolBar::Side)Okular::Settings::editToolBarPlacement() ); | 725 | // m_toolBar->setSide( (PageViewToolBar::Side)Okular::Settings::editToolBarPlacement() ); | ||
726 | m_toolBar->setItems( m_items ); | 726 | // m_toolBar->setItems( m_items ); | ||
727 | m_toolBar->setToolsEnabled( m_toolsEnabled ); | 727 | // m_toolBar->setToolsEnabled( m_toolsEnabled ); | ||
728 | m_toolBar->setTextToolsEnabled( m_textToolsEnabled ); | 728 | // m_toolBar->setTextToolsEnabled( m_textToolsEnabled ); | ||
729 | connect(m_toolBar, &PageViewToolBar::toolSelected, this, &PageViewAnnotator::slotToolSelected); | 729 | connect(m_toolBar, &PageViewToolBar::toolSelected, this, &PageViewAnnotator::slotToolSelected); | ||
730 | connect(m_toolBar, &PageViewToolBar::orientationChanged, this, &PageViewAnnotator::slotSaveToolbarOrientation); | 730 | // connect(m_toolBar, &PageViewToolBar::orientationChanged, this, &PageViewAnnotator::slotSaveToolbarOrientation); | ||
731 | 731 | // | |||
732 | connect(m_toolBar, &PageViewToolBar::buttonDoubleClicked, this, &PageViewAnnotator::slotToolDoubleClicked); | 732 | connect(m_toolBar, &PageViewToolBar::pinAnnotationToolToggled, this, &PageViewAnnotator::slotPinAnnotationToolToggled); | ||
733 | m_toolBar->setCursor(Qt::ArrowCursor); | 733 | // m_toolBar->setCursor(Qt::ArrowCursor); | ||
734 | } | 734 | } | ||
735 | 735 | | |||
736 | // show the toolBar | 736 | // show the toolBar | ||
737 | m_toolBar->showAndAnimate(); | 737 | //m_toolBar->showAndAnimate(); | ||
738 | } | 738 | } | ||
739 | 739 | | |||
740 | void PageViewAnnotator::setTextToolsEnabled( bool enabled ) | 740 | void PageViewAnnotator::setTextToolsEnabled( bool enabled ) | ||
741 | { | 741 | { | ||
742 | //FIXME: Add code to enable tools | ||||
742 | m_textToolsEnabled = enabled; | 743 | m_textToolsEnabled = enabled; | ||
743 | if ( m_toolBar ) | 744 | if ( m_toolBar ) | ||
744 | m_toolBar->setTextToolsEnabled( m_textToolsEnabled ); | 745 | m_toolBar->setTextToolsEnabled( m_textToolsEnabled ); | ||
745 | } | 746 | } | ||
746 | 747 | | |||
747 | void PageViewAnnotator::setToolsEnabled( bool enabled ) | 748 | void PageViewAnnotator::setToolsEnabled( bool enabled ) | ||
748 | { | 749 | { | ||
750 | //FIXME: Add code to enable tools | ||||
749 | m_toolsEnabled = enabled; | 751 | m_toolsEnabled = enabled; | ||
750 | if ( m_toolBar ) | 752 | if ( m_toolBar ) | ||
751 | m_toolBar->setToolsEnabled( m_toolsEnabled ); | 753 | m_toolBar->setToolsEnabled( m_toolsEnabled ); | ||
752 | } | 754 | } | ||
753 | 755 | | |||
754 | void PageViewAnnotator::setHidingForced( bool forced ) | 756 | void PageViewAnnotator::setHidingForced( bool forced ) | ||
755 | { | 757 | { | ||
756 | m_hidingWasForced = forced; | 758 | m_hidingWasForced = forced; | ||
757 | } | 759 | } | ||
758 | 760 | | |||
759 | bool PageViewAnnotator::hidingWasForced() const | 761 | bool PageViewAnnotator::hidingWasForced() const | ||
760 | { | 762 | { | ||
761 | return m_hidingWasForced; | 763 | return m_hidingWasForced; | ||
762 | } | 764 | } | ||
763 | 765 | | |||
764 | bool PageViewAnnotator::active() const | 766 | bool PageViewAnnotator::active() const | ||
765 | { | 767 | { | ||
766 | return m_engine && m_toolBar; | 768 | //FIXME: | ||
769 | return m_engine;// && m_toolBar; | ||||
767 | } | 770 | } | ||
768 | 771 | | |||
769 | bool PageViewAnnotator::annotating() const | 772 | bool PageViewAnnotator::annotating() const | ||
770 | { | 773 | { | ||
771 | return active() && m_lockedItem; | 774 | return active() && m_lockedItem; | ||
772 | } | 775 | } | ||
773 | 776 | | |||
774 | QCursor PageViewAnnotator::cursor() const | 777 | QCursor PageViewAnnotator::cursor() const | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 872 | { | |||
870 | // Unlike routeMouseEvent, routeTabletEvent must explicitly ignore events it doesn't care about so that | 873 | // Unlike routeMouseEvent, routeTabletEvent must explicitly ignore events it doesn't care about so that | ||
871 | // the corresponding mouse event will later be delivered. | 874 | // the corresponding mouse event will later be delivered. | ||
872 | if ( !item ) | 875 | if ( !item ) | ||
873 | { | 876 | { | ||
874 | e->ignore(); | 877 | e->ignore(); | ||
875 | return QRect(); | 878 | return QRect(); | ||
876 | } | 879 | } | ||
877 | 880 | | |||
878 | // We set all tablet events that take place over the annotations toolbar to ignore so that corresponding mouse | | |||
879 | // events will be delivered to the toolbar. However, we still allow the annotations code to handle | | |||
880 | // TabletMove and TabletRelease events in case the user is drawing an annotation onto the toolbar. | | |||
881 | const QPoint toolBarPos = m_toolBar->mapFromGlobal( e->globalPos() ); | | |||
882 | const QRect toolBarRect = m_toolBar->rect(); | | |||
883 | if ( toolBarRect.contains( toolBarPos ) ) | | |||
884 | { | | |||
885 | e->ignore(); | | |||
886 | if (e->type() == QEvent::TabletPress) | | |||
887 | return QRect(); | | |||
888 | } | | |||
889 | | ||||
890 | AnnotatorEngine::EventType eventType; | 881 | AnnotatorEngine::EventType eventType; | ||
891 | AnnotatorEngine::Button button; | 882 | AnnotatorEngine::Button button; | ||
892 | 883 | | |||
893 | // figure out the event type and button | 884 | // figure out the event type and button | ||
894 | AnnotatorEngine::decodeEvent( e, &eventType, &button ); | 885 | AnnotatorEngine::decodeEvent( e, &eventType, &button ); | ||
895 | 886 | | |||
896 | const QPointF globalPosF = e->globalPosF(); | 887 | const QPointF globalPosF = e->globalPosF(); | ||
897 | const QPointF localPosF = globalPosF - localOriginInGlobal; | 888 | const QPointF localPosF = globalPosF - localOriginInGlobal; | ||
898 | return performRouteMouseOrTabletEvent( eventType, button, localPosF, item ); | 889 | return performRouteMouseOrTabletEvent( eventType, button, localPosF, item ); | ||
899 | } | 890 | } | ||
900 | 891 | | |||
901 | bool PageViewAnnotator::routeKeyEvent( QKeyEvent * event ) | 892 | bool PageViewAnnotator::routeKeyEvent( QKeyEvent * event ) | ||
902 | { | 893 | { | ||
903 | if ( event->key() == Qt::Key_Escape ) | 894 | if ( event->key() == Qt::Key_Escape ) | ||
904 | { | 895 | { | ||
905 | detachAnnotation(); | 896 | detachAnnotation(); | ||
906 | return true; | 897 | return true; | ||
907 | } | 898 | } | ||
908 | return false; | 899 | return false; | ||
909 | } | 900 | } | ||
910 | 901 | | |||
911 | bool PageViewAnnotator::routePaints( const QRect & wantedRect ) const | 902 | bool PageViewAnnotator::routePaints( const QRect & wantedRect ) const | ||
912 | { | 903 | { | ||
913 | return m_engine && m_toolBar && wantedRect.intersects( m_lastDrawnRect ) && m_lockedItem; | 904 | //FIXME: Add check on annotation toolbar avability | ||
905 | return m_engine && wantedRect.intersects( m_lastDrawnRect ) && m_lockedItem; | ||||
914 | } | 906 | } | ||
915 | 907 | | |||
916 | void PageViewAnnotator::routePaint( QPainter * painter, const QRect & paintRect ) | 908 | void PageViewAnnotator::routePaint( QPainter * painter, const QRect & paintRect ) | ||
917 | { | 909 | { | ||
918 | // if there's no locked item, then there's no decided place to draw on | 910 | // if there's no locked item, then there's no decided place to draw on | ||
919 | if ( !m_lockedItem ) | 911 | if ( !m_lockedItem ) | ||
920 | return; | 912 | return; | ||
921 | 913 | | |||
Show All 27 Lines | 935 | { | |||
949 | } | 941 | } | ||
950 | m_lockedItem = nullptr; | 942 | m_lockedItem = nullptr; | ||
951 | if ( m_lastDrawnRect.isValid() ) | 943 | if ( m_lastDrawnRect.isValid() ) | ||
952 | { | 944 | { | ||
953 | m_pageView->viewport()->update( m_lastDrawnRect.translated( -m_pageView->contentAreaPosition() ) ); | 945 | m_pageView->viewport()->update( m_lastDrawnRect.translated( -m_pageView->contentAreaPosition() ) ); | ||
954 | m_lastDrawnRect = QRect(); | 946 | m_lastDrawnRect = QRect(); | ||
955 | } | 947 | } | ||
956 | 948 | | |||
957 | if ( toolID != m_lastToolID ) m_continuousMode = false; | | |||
958 | // store current tool for later usage | 949 | // store current tool for later usage | ||
959 | m_lastToolID = toolID; | 950 | m_lastToolID = toolID; | ||
960 | 951 | | |||
961 | // handle tool deselection | 952 | // handle tool deselection | ||
962 | if ( toolID == -1 ) | 953 | if ( toolID == -1 ) | ||
963 | { | 954 | { | ||
964 | m_pageView->displayMessage( QString() ); | 955 | m_pageView->displayMessage( QString() ); | ||
965 | m_pageView->updateCursor(); | 956 | m_pageView->updateCursor(); | ||
Show All 16 Lines | 963 | { | |||
982 | while ( toolSubNode.isElement() ) | 973 | while ( toolSubNode.isElement() ) | ||
983 | { | 974 | { | ||
984 | QDomElement toolSubElement = toolSubNode.toElement(); | 975 | QDomElement toolSubElement = toolSubNode.toElement(); | ||
985 | toolSubNode = toolSubNode.nextSibling(); | 976 | toolSubNode = toolSubNode.nextSibling(); | ||
986 | 977 | | |||
987 | // create the AnnotatorEngine | 978 | // create the AnnotatorEngine | ||
988 | if ( toolSubElement.tagName() == QLatin1String("engine") ) | 979 | if ( toolSubElement.tagName() == QLatin1String("engine") ) | ||
989 | { | 980 | { | ||
981 | if ( toolSubElement.hasAttribute( QStringLiteral("color") ) ) | ||||
982 | { | ||||
983 | qDebug() << m_toolBar->annotationColor(); | ||||
984 | toolSubElement.setAttribute( QStringLiteral("color"), m_toolBar->annotationColor()); | ||||
985 | } | ||||
990 | QString type = toolSubElement.attribute( QStringLiteral("type") ); | 986 | QString type = toolSubElement.attribute( QStringLiteral("type") ); | ||
991 | if ( type == QLatin1String("SmoothLine") ) | 987 | if ( type == QLatin1String("SmoothLine") ) | ||
992 | m_engine = new SmoothPathEngine( toolSubElement ); | 988 | m_engine = new SmoothPathEngine( toolSubElement ); | ||
993 | else if ( type == QLatin1String("PickPoint") ) | 989 | else if ( type == QLatin1String("PickPoint") ) | ||
994 | m_engine = new PickPointEngine( toolSubElement ); | 990 | m_engine = new PickPointEngine( toolSubElement ); | ||
995 | else if ( type == QLatin1String("PolyLine") ) | 991 | else if ( type == QLatin1String("PolyLine") ) | ||
996 | m_engine = new PolyLineEngine( toolSubElement ); | 992 | m_engine = new PolyLineEngine( toolSubElement ); | ||
997 | else if ( type == QLatin1String("TextSelector") ) | 993 | else if ( type == QLatin1String("TextSelector") ) | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
1046 | } | 1042 | } | ||
1047 | 1043 | | |||
1048 | void PageViewAnnotator::slotSaveToolbarOrientation( int side ) | 1044 | void PageViewAnnotator::slotSaveToolbarOrientation( int side ) | ||
1049 | { | 1045 | { | ||
1050 | Okular::Settings::setEditToolBarPlacement( (int)side ); | 1046 | Okular::Settings::setEditToolBarPlacement( (int)side ); | ||
1051 | Okular::Settings::self()->save(); | 1047 | Okular::Settings::self()->save(); | ||
1052 | } | 1048 | } | ||
1053 | 1049 | | |||
1054 | void PageViewAnnotator::slotToolDoubleClicked( int /*toolID*/ ) | 1050 | void PageViewAnnotator::slotPinAnnotationToolToggled( bool enabled ) | ||
1055 | { | 1051 | { | ||
1056 | m_continuousMode = true; | 1052 | m_continuousMode = enabled; | ||
1057 | } | 1053 | } | ||
1058 | 1054 | | |||
1059 | void PageViewAnnotator::detachAnnotation() | 1055 | void PageViewAnnotator::detachAnnotation() | ||
1060 | { | 1056 | { | ||
1061 | m_toolBar->selectButton( -1 ); | 1057 | m_toolBar->deselectAllButtons(); | ||
1062 | } | 1058 | } | ||
1063 | 1059 | | |||
1064 | QString PageViewAnnotator::defaultToolName( const QDomElement &toolElement ) | 1060 | QString PageViewAnnotator::defaultToolName( const QDomElement &toolElement ) | ||
1065 | { | 1061 | { | ||
1066 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | 1062 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | ||
1067 | 1063 | | |||
1068 | if ( annotType == QLatin1String("ellipse") ) | 1064 | if ( annotType == QLatin1String("ellipse") ) | ||
1069 | return i18n( "Ellipse" ); | 1065 | return i18n( "Ellipse" ); | ||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Line(s) | 1231 | { | |||
1236 | /* Unrecognized annotation type -- It shouldn't happen */ | 1232 | /* Unrecognized annotation type -- It shouldn't happen */ | ||
1237 | p.setPen( QPen( engineColor ) ); | 1233 | p.setPen( QPen( engineColor ) ); | ||
1238 | p.drawText( QPoint(20, 31), QStringLiteral("?") ); | 1234 | p.drawText( QPoint(20, 31), QStringLiteral("?") ); | ||
1239 | } | 1235 | } | ||
1240 | 1236 | | |||
1241 | return pixmap; | 1237 | return pixmap; | ||
1242 | } | 1238 | } | ||
1243 | 1239 | | |||
1240 | void PageViewAnnotator::setupActions( KActionCollection * ac ) | ||||
1241 | { | ||||
1242 | m_toolBar->setupActions( ac ); | ||||
1243 | } | ||||
1244 | | ||||
1244 | #include "moc_pageviewannotator.cpp" | 1245 | #include "moc_pageviewannotator.cpp" | ||
1245 | 1246 | | |||
1246 | /* kate: replace-tabs on; indent-width 4; */ | 1247 | /* kate: replace-tabs on; indent-width 4; */ |