Bug 131361 - mouse hovering on an external link can produce a tooltip of the URI, as in acroread and evince
Summary: mouse hovering on an external link can produce a tooltip of the URI, as in ac...
Status: RESOLVED FIXED
Alias: None
Product: kpdf
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: RedHat Enterprise Linux Linux
: NOR wishlist
Target Milestone: ---
Assignee: Albert Astals Cid
URL:
Keywords:
: 127387 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-07-25 21:19 UTC by Bob Tennent
Modified: 2007-03-30 23:34 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
patch against ui/pageview.cpp to implement URI tooltips (1.54 KB, patch)
2006-07-25 21:20 UTC, Bob Tennent
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bob Tennent 2006-07-25 21:19:09 UTC
Version:            (using KDE KDE 3.5.3)
Installed from:    RedHat RPMs

mouse hovering on an external link can produce a tooltip of the URI, as in acroread and evince:  easily implemented by the to-be-attached patch against ui/pageview.cpp.
Comment 1 Bob Tennent 2006-07-25 21:20:59 UTC
Created attachment 17126 [details]
patch against ui/pageview.cpp to implement URI tooltips
Comment 2 Albert Astals Cid 2006-07-25 22:12:55 UTC
patch is wrong because noone guarantees you the KPDFLink is a KPDFLinkBrowse so instead of static_casting you should dynamic_cast and check for != 0, another option is introducing a virtual method on KPDFLink that returns the representation of the link in a QString form so for example links to pages inside the same file, etc also get the tooltip.
Comment 3 Albert Astals Cid 2006-07-25 22:18:05 UTC
Pino Toscano just made me realize we already have that virtual funcion on KPDFLink that returns the representation of the link in a QString form in okular so we might really backport that to KDE 3.5.5 in case it is opened for new strings and features.
Comment 4 Pino Toscano 2006-09-27 13:24:33 UTC
*** Bug 127387 has been marked as a duplicate of this bug. ***
Comment 5 Pino Toscano 2007-03-30 23:14:32 UTC
SVN commit 648272 by pino:

Add tooltips for links in presentation mode.
(Not yet in the contents area.)

CCBUGS: 131361
CCMAIL: kde-i18n-doc@kde.org


 M  +50 -0     core/link.cpp  
 M  +5 -0      core/link.h  
 M  +6 -0      ui/presentationwidget.cpp  


--- branches/KDE/3.5/kdegraphics/kpdf/core/link.cpp #648271:648272
@@ -10,6 +10,56 @@
 // local includes
 #include "link.h"
 
+#include <klocale.h>
+
 KPDFLink::~KPDFLink()
 {
 }
+
+QString KPDFLinkGoto::linkTip() const
+{
+    return m_extFileName.isEmpty() ? ( m_vp.pageNumber != -1 ? i18n( "Go to page %1" ).arg( m_vp.pageNumber + 1 ) : "" ) : i18n("Open external file");
+}
+
+QString KPDFLinkExecute::linkTip() const
+{
+    return i18n( "Execute '%1'..." ).arg( m_fileName );
+}
+
+QString KPDFLinkBrowse::linkTip() const
+{
+    return m_url;
+}
+
+QString KPDFLinkAction::linkTip() const
+{
+    switch ( m_type )
+    {
+        case PageFirst:
+            return i18n( "First Page" );
+        case PagePrev:
+            return i18n( "Previous Page" );
+        case PageNext:
+            return i18n( "Next Page" );
+        case PageLast:
+            return i18n( "Last Page" );
+        case HistoryBack:
+            return i18n( "Back" );
+        case HistoryForward:
+            return i18n( "Forward" );
+        case Quit:
+            return i18n( "Quit" );
+        case Presentation:
+            return i18n( "Start Presentation" );
+        case EndPresentation:
+            return i18n( "End Presentation" );
+        case Find:
+            return i18n( "Find..." );
+        case GoToPage:
+            return i18n( "Go To Page..." );
+        case Close:
+        default: ;
+    }
+
+    return QString::null;
+}
--- branches/KDE/3.5/kdegraphics/kpdf/core/link.h #648271:648272
@@ -27,6 +27,7 @@
         // get link type (inherited classes mustreturn an unique identifier)
         enum LinkType { Goto, Execute, Browse, Action, Movie };
         virtual LinkType linkType() const = 0;
+        virtual QString linkTip() const { return QString::null; }
 
         // virtual destructor (remove warnings)
         virtual ~KPDFLink();
@@ -45,6 +46,7 @@
         // create a KPDFLink_Goto
         KPDFLinkGoto( QString extFileName, const DocumentViewport & vp ) { m_extFileName = extFileName; m_vp = vp; }
         LinkType linkType() const { return Goto; }
+        QString linkTip() const;
 
     private:
         QString m_extFileName;
@@ -62,6 +64,7 @@
         // create a KPDFLink_Execute
         KPDFLinkExecute( const QString & file, const QString & params ) { m_fileName = file; m_parameters = params; }
         LinkType linkType() const { return Execute; }
+        QString linkTip() const;
 
     private:
         QString m_fileName;
@@ -78,6 +81,7 @@
         // create a KPDFLink_Browse
         KPDFLinkBrowse( const QString &url ) { m_url = url; }
         LinkType linkType() const { return Browse; }
+        QString linkTip() const;
 
     private:
         QString m_url;
@@ -96,6 +100,7 @@
         // create a KPDFLink_Action
         KPDFLinkAction( enum ActionType actionType ) { m_type = actionType; }
         LinkType linkType() const { return Action; }
+        QString linkTip() const;
 
     private:
         ActionType m_type;
--- branches/KDE/3.5/kdegraphics/kpdf/ui/presentationwidget.cpp #648271:648272
@@ -13,6 +13,7 @@
 #include <qpainter.h>
 #include <qapplication.h>
 #include <qdesktopwidget.h>
+#include <qtooltip.h>
 #include <kapplication.h>
 #include <kcursor.h>
 #include <ktoolbar.h>
@@ -406,6 +407,11 @@
         // change cursor shape
         m_handCursor = link != 0;
         setCursor( m_handCursor ? KCursor::handCursor() : KCursor::arrowCursor());
+
+        // set tooltip over link's rect
+        QString tip = link ? link->linkTip() : "";
+        if ( m_handCursor && !tip.isEmpty() )
+            QToolTip::add( this, linkRect, tip );
     }
 }
 
Comment 6 Nicolas Goutte 2007-03-30 23:29:30 UTC
On Friday 30 March 2007, Pino Toscano wrote:
> SVN commit 648272 by pino:
>
> Add tooltips for links in presentation mode.
> (Not yet in the contents area.)
>
> CCBUGS: 131361
> CCMAIL: kde-i18n-doc@kde.org
>
>
>  M  +50 -0     core/link.cpp
>  M  +5 -0      core/link.h
>  M  +6 -0      ui/presentationwidget.cpp
>
>
> --- branches/KDE/3.5/kdegraphics/kpdf/core/link.cpp #648271:648272
> @@ -10,6 +10,56 @@
>  // local includes
>  #include "link.h"
>
> +#include <klocale.h>
> +
>  KPDFLink::~KPDFLink()
>  {
>  }
> +
> +QString KPDFLinkGoto::linkTip() const
> +{
> +    return m_extFileName.isEmpty() ? ( m_vp.pageNumber != -1 ? i18n( "Go
> to page %1" ).arg( m_vp.pageNumber + 1 ) : "" ) : i18n("Open external
> file"); +}


As i18n returns a QString, I suppose that using QString() (or QString::null ) 
instead of "" would be better to avoid potential compilation errors.

> +

[...]
> --- branches/KDE/3.5/kdegraphics/kpdf/ui/presentationwidget.cpp
> #648271:648272 @@ -13,6 +13,7 @@
>  #include <qpainter.h>
>  #include <qapplication.h>
>  #include <qdesktopwidget.h>
> +#include <qtooltip.h>
>  #include <kapplication.h>
>  #include <kcursor.h>
>  #include <ktoolbar.h>
> @@ -406,6 +407,11 @@
>          // change cursor shape
>          m_handCursor = link != 0;
>          setCursor( m_handCursor ? KCursor::handCursor() :
> KCursor::arrowCursor()); +
> +        // set tooltip over link's rect
> +        QString tip = link ? link->linkTip() : "";


And probably the same here.

> +        if ( m_handCursor && !tip.isEmpty() )
> +            QToolTip::add( this, linkRect, tip );
>      }
>  }


Have a nice day!
Comment 7 Pino Toscano 2007-03-30 23:34:41 UTC
SVN commit 648280 by pino:

Show a tooltip of the link under the mouse even in the content area.

BUG: 131361


 M  +52 -0     pageview.cpp  
 M  +3 -0      pageview.h  


--- branches/KDE/3.5/kdegraphics/kpdf/ui/pageview.cpp #648279:648280
@@ -22,6 +22,7 @@
 #include <qtimer.h>
 #include <qdatetime.h>
 #include <qpushbutton.h>
+#include <qtooltip.h>
 #include <qapplication.h>
 #include <qclipboard.h>
 #include <dcopclient.h>
@@ -58,6 +59,53 @@
 // definition of searchID for this class
 #define PAGEVIEW_SEARCH_ID 2
 
+class PageViewTip : public QToolTip
+{
+    public:
+        PageViewTip( PageView * view )
+            : QToolTip( view->viewport() ), m_view( view )
+        {
+        }
+
+        ~PageViewTip()
+        {
+            remove( m_view->viewport() );
+        }
+
+
+    protected:
+        void maybeTip( const QPoint &p );
+
+    private:
+        PageView * m_view;
+};
+
+void PageViewTip::maybeTip( const QPoint &_p )
+{
+    QPoint p( _p.x() + m_view->contentsX(), _p.y() + m_view->contentsY() );
+    PageViewItem * pageItem = m_view->pickItemOnPoint( p.x(), p.y() );
+    if ( pageItem )
+    {
+        double nX = (double)(p.x() - pageItem->geometry().left()) / (double)pageItem->width(),
+               nY = (double)(p.y() - pageItem->geometry().top()) / (double)pageItem->height();
+
+        // if over a ObjectRect (of type Link) change cursor to hand
+        const ObjectRect * object = pageItem->page()->hasObject( ObjectRect::Link, nX, nY );
+        if ( object )
+        {
+            // set tooltip over link's rect
+            KPDFLink *link = (KPDFLink *)object->pointer();
+            QString strtip = link->linkTip();
+            if ( !strtip.isEmpty() )
+            {
+                QRect linkRect = object->geometry( pageItem->width(), pageItem->height() );
+                linkRect.moveBy( - m_view->contentsX() + pageItem->geometry().left(), - m_view->contentsY() + pageItem->geometry().top() );
+                tip( linkRect, strtip );
+            }
+        }
+    }
+}
+
 // structure used internally by PageView for data storage
 class PageViewPrivate
 {
@@ -96,6 +144,7 @@
     bool blockViewport;                 // prevents changes to viewport
     bool blockPixmapsRequest;           // prevent pixmap requests
     PageViewMessage * messageWindow;    // in pageviewutils.h
+    PageViewTip * tip;
 
     // drag scroll
     QPoint dragScrollVector;
@@ -148,6 +197,7 @@
     d->blockViewport = false;
     d->blockPixmapsRequest = false;
     d->messageWindow = new PageViewMessage(this);
+    d->tip = new PageViewTip( this );
     d->aPrevAction = 0;
 
     // widget setup: setup focus, accept drops and track mouse
@@ -182,6 +232,8 @@
     QValueVector< PageViewItem * >::iterator dIt = d->items.begin(), dEnd = d->items.end();
     for ( ; dIt != dEnd; ++dIt )
         delete *dIt;
+    delete d->tip;
+    d->tip = 0;
     d->document->removeObserver( this );
     delete d;
 }
--- branches/KDE/3.5/kdegraphics/kpdf/ui/pageview.h #648279:648280
@@ -29,6 +29,7 @@
 class KPDFDocument;
 class PageViewItem;
 class PageViewPrivate;
+class PageViewTip;
 
 /**
  * @short The main view. Handles zoom and continuous mode.. oh, and page
@@ -39,6 +40,8 @@
 {
     Q_OBJECT
 
+        friend class PageViewTip;
+
     public:
         PageView( QWidget *parent, KPDFDocument *document );
         ~PageView();