Hi guys,

Actually in okular when you want to add a revision (highlight, annotation
exc..), you have to click in the appropriate button of the revision toolbar
and then click on the document in the point in wich you want the revision to
be located. But then the button in the revision toolbar is de-selected and
the revision tool detached from the mouse, so if you want to add another
revision of the same type you have to re-click on the button in the toolbar.

I have made a patch that will allow you to double click on the button in the
toolbar. In this case, it will allow you to add revisions of the same type
without need to re-click on the toolbar button between two revisions. The
revision is not detached from the mouse after you  add the first.
It is especially useful for the highlighter, when you need to highlight lots
of almost continuous text (like when you are studying a book) and do not
want to re-click on the button every time.
The "one click" mode is still the same.

I have implemented it this way: the button, when double clicked, send a
signal to the toolbar, wich send a signal to the PageViewAnnotator class,
wich set an internal variable to true to indicate that we are in "continue
mode" (can't get with a better name sorry :))

I have also implemented a feature which allow to detach the tool with a
right mouse button click.

I have added a //<raffamaiden> comment in the code to easily track my
modifications. You need to remove it if you decide to apply the patch of
course.

Thanks to the guy who helped me compile okular in the chat :) (don't
remember his nickname, i was raffairon)

Let me know what you thinks and if the patch will be applied or not. Critics
are very appreciated :)

Cheers,
Raffaele
Index: ui/pageviewutils.h
===================================================================
--- ui/pageviewutils.h	(revisione 1217837)
+++ ui/pageviewutils.h	(copia locale)
@@ -167,8 +167,15 @@
 
         ToolBarButton( QWidget * parent, const AnnotationToolItem &item );
         int buttonID() const { return m_id; }
-        bool isText() const { return m_isText; }
+        bool isText() const { return m_isText; }        
 
+  	//<raffamaiden>
+  	protected:
+	  void mouseDoubleClickEvent ( QMouseEvent * event ) ;
+	signals:
+	  void buttonDoubleClicked();
+	//</raffamaiden>
+
     private:
         int m_id;
         bool m_isText;
@@ -210,6 +217,8 @@
         void toolSelected( int toolID );
         // orientation has been changed
         void orientationChanged( int side );
+	
+	void buttonDoubleClicked(int buttonID); //<raffamaiden />: a tool button of this toolbar has been double clicked
 
     protected:
         // handle widget events { anchor_resize, paint, animation, drag }
@@ -227,6 +236,7 @@
     private slots:
         void slotAnimate();
         void slotButtonClicked();
+	void slotButtonDoubleClicked(); //<raffamaiden />: a tool button of this toolbar has been double clicked
 };
 
 #endif
Index: ui/pageviewannotator.h
===================================================================
--- ui/pageviewannotator.h	(revisione 1217837)
+++ ui/pageviewannotator.h	(copia locale)
@@ -66,10 +66,14 @@
         bool routeKeyEvent( QKeyEvent * event );
         bool routePaints( const QRect & wantedRect ) const;
         void routePaint( QPainter * painter, const QRect & paintRect );
+	
+	//<raffamaiden />: method to detach the annotation from the mouse
+	inline void detachAnnotation() {this->slotToolSelected(-1); this->m_toolBar->selectButton( -1 ); return;}
 
     private slots:
         void slotToolSelected( int toolID );
         void slotSaveToolbarOrientation( int side );
+	void slotToolDoubleClicked( int toolID ); //<raffamaiden />
 
     private:
         // global class pointers
@@ -81,6 +85,7 @@
         QLinkedList<AnnotationToolItem> m_items;
         bool m_textToolsEnabled;
         bool m_toolsEnabled;
+	bool m_continueMode; //<raffamaiden />
 
         // creation related variables
         int m_lastToolID;
Index: ui/pageviewannotator.cpp
===================================================================
--- ui/pageviewannotator.cpp	(revisione 1217837)
+++ ui/pageviewannotator.cpp	(copia locale)
@@ -603,7 +603,7 @@
 PageViewAnnotator::PageViewAnnotator( PageView * parent, Okular::Document * storage )
     : QObject( parent ), m_document( storage ), m_pageView( parent ),
     m_toolBar( 0 ), m_engine( 0 ), m_textToolsEnabled( false ), m_toolsEnabled( false ),
-    m_lastToolID( -1 ), m_lockedItem( 0 )
+    m_lastToolID( -1 ), m_lockedItem( 0 ), m_continueMode(false) //<raffamaiden />
 {
     // load the tools from the 'xml tools definition' file. store the tree internally.
     QFile infoFile( KStandardDirs::locate("data", "okular/tools.xml") );
@@ -646,6 +646,7 @@
     }
     else
         kWarning() << "Unable to open AnnotatingTools XML definition";
+    
 }
 
 PageViewAnnotator::~PageViewAnnotator()
@@ -682,10 +683,15 @@
                 this, SLOT( slotToolSelected(int) ) );
         connect( m_toolBar, SIGNAL( orientationChanged(int) ),
                 this, SLOT( slotSaveToolbarOrientation(int) ) );
+        
+        //<raffamaiden>
+        connect( m_toolBar, SIGNAL( buttonDoubleClicked(int) ),
+                this, SLOT( slotToolDoubleClicked(int) ) );
+        //<raffamaiden />
     }
 
     // show the toolBar
-    m_toolBar->showAndAnimate();
+    m_toolBar->showAndAnimate();    
 }
 
 void PageViewAnnotator::setTextToolsEnabled( bool enabled )
@@ -710,13 +716,27 @@
 QRect PageViewAnnotator::routeEvent( QMouseEvent * e, PageViewItem * item )
 {
     if ( !item ) return QRect();
-
+    
     AnnotatorEngine::EventType eventType;
     AnnotatorEngine::Button button;
 
     // figure out the event type and button
     AnnotatorEngine::decodeEvent( e, &eventType, &button );
-
+    
+    //<raffamaiden>
+    // if the right mouse button was pressed, we simply do nothing. In this way, we are still editing the annotation
+    // and so this function will receive and process the right mouse button release event too. If we detach now the annotation tool, 
+    // the release event will be processed by the PageView class which would create the annotation property widget, and we do not want this.
+    if(button == AnnotatorEngine::Right && eventType == AnnotatorEngine::Press)
+        return QRect(); 
+    
+    else if(button == AnnotatorEngine::Right && eventType == AnnotatorEngine::Release)
+    {
+        this->detachAnnotation();
+        return QRect(); 
+    }
+    //</raffamaiden>
+    
     // find out normalized mouse coords inside current item
     const QRect & itemRect = item->uncroppedGeometry();
     const QPoint eventPos = m_pageView->contentAreaPoint( e->pos() );
@@ -771,11 +791,14 @@
                 m_pageView->setAnnotationWindow( annotation );
         }
 
-        // go on creating annotations of the same type
-        // for now, disable the "construct again the same annotation"
-        //slotToolSelected( m_lastToolID );
-        slotToolSelected( -1 );
-        m_toolBar->selectButton( -1 );
+        //<raffamaiden>
+        // go on creating annotations of the same type if we are in "continue" mode
+        if(this->m_continueMode)
+            slotToolSelected( m_lastToolID );
+        else
+            this->detachAnnotation();
+        //m_toolBar->selectButton( m_lastToolID );
+        //</raffamaiden>
     }
 
     return modifiedRect;
@@ -822,6 +845,16 @@
     painter->restore();
 }
 
+//<raffamaiden>
+void PageViewAnnotator::slotToolDoubleClicked( int toolID )
+{
+    // If the user double clicked on a toolbar button, set continue mode to true
+    this->m_continueMode = true;
+    // really necessary?
+    //this->slotToolSelected( this->m_lastToolID);
+}
+//</raffamaiden>
+
 void PageViewAnnotator::slotToolSelected( int toolID )
 {
     // terminate any previous operation
@@ -837,6 +870,9 @@
         m_lastDrawnRect = QRect();
     }
 
+    //<raffamaiden>
+    // if the user selected another tool, we select continue mode to false. Eventually, if the user double-clicked on it, the appropiate function will reset this to true (this need to be further tested by the way). This is still valid if we pass -1
+    if(toolID != m_lastToolID) this->m_continueMode = false;
     // store current tool for later usage
     m_lastToolID = toolID;
 
Index: ui/pageview.h
===================================================================
--- ui/pageview.h	(revisione 1217837)
+++ ui/pageview.h	(copia locale)
@@ -127,7 +127,7 @@
     protected:
         void resizeEvent( QResizeEvent* );
 
-        // mouse / keyboard events
+        // mouse / keyboard events (inherited from QAbstractScrollArea)
         void keyPressEvent( QKeyEvent* );
         void keyReleaseEvent( QKeyEvent* );
         void inputMethodEvent( QInputMethodEvent * );
Index: ui/pageviewutils.cpp
===================================================================
--- ui/pageviewutils.cpp	(revisione 1217837)
+++ ui/pageviewutils.cpp	(copia locale)
@@ -464,6 +464,13 @@
         setToolTip( item.text );
 }
 
+//<raffamaiden>
+void ToolBarButton::mouseDoubleClickEvent ( QMouseEvent * event )
+{
+  emit this->buttonDoubleClicked();
+}
+//</raffamaiden>
+
 /* PageViewToolBar */
 
 static const int toolBarGridSize = 40;
@@ -542,6 +549,7 @@
     {
         ToolBarButton * button = new ToolBarButton( this, *it );
         connect( button, SIGNAL( clicked() ), this, SLOT( slotButtonClicked() ) );
+	connect( button, SIGNAL( buttonDoubleClicked() ), this, SLOT( slotButtonDoubleClicked() ) ); //<raffamaiden />
         d->buttons.append( button );
     }
 
@@ -915,6 +923,14 @@
     d->selectButton( button );
 }
 
+//<raffamaiden>
+void PageViewToolBar::slotButtonDoubleClicked()
+{
+    ToolBarButton * button = qobject_cast<ToolBarButton *>( sender() );
+    emit this->buttonDoubleClicked(button->buttonID());
+}
+//</raffamaiden>
+
 void ToolBarPrivate::selectButton( ToolBarButton * button )
 {
     if ( button )
_______________________________________________
Okular-devel mailing list
Okular-devel@kde.org
https://mail.kde.org/mailman/listinfo/okular-devel

Reply via email to