- Update the cursor an wheelEvents

- Only put the pointingHandCursor where we are over a rect that is a link and not all the rects

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=373440
This commit is contained in:
Albert Astals Cid 2004-12-26 21:20:17 +00:00
parent ebdff63443
commit 3b0cc84aaf
4 changed files with 40 additions and 22 deletions

View file

@ -75,6 +75,13 @@ bool KPDFPage::hasRect( int mouseX, int mouseY ) const
return false;
}
bool KPDFPage::hasLink( int mouseX, int mouseY ) const
{
const KPDFPageRect *r;
r = getRect( mouseX, mouseY);
return r && r->pointerType() == KPDFPageRect::Link;
}
const KPDFPageRect * KPDFPage::getRect( int mouseX, int mouseY ) const
{
QValueList< KPDFPageRect * >::const_iterator it = m_rects.begin(), end = m_rects.end();

View file

@ -48,6 +48,7 @@ class KPDFPage
bool hasPixmap( int id, int width = -1, int height = -1 ) const;
bool hasSearchPage() const;
bool hasRect( int mouseX, int mouseY ) const;
bool hasLink( int mouseX, int mouseY ) const;
const KPDFPageRect * getRect( int mouseX, int mouseY ) const;
const QString getTextInRect( const QRect & rect, double zoom = 1.0 ) const;

View file

@ -546,28 +546,7 @@ void PageView::contentsMouseMoveEvent( QMouseEvent * e )
}
else // only hovering the page
{
// detect the underlaying page (if present)
PageViewItem * pageItem = pickItemOnPoint( e->x(), e->y() );
if ( pageItem )
{
int pageX = e->x() - pageItem->geometry().left(),
pageY = e->y() - pageItem->geometry().top();
// check if over a KPDFPageRect
bool onRect = pageItem->page()->hasRect( pageX, pageY );
if ( onRect != d->mouseOnRect )
setCursor( (d->mouseOnRect = onRect) ? pointingHandCursor : arrowCursor );
}
else
{
// if there's no page over the cursor and we were showing the pointingHandCursor
// go back to the normal one
if ( d->mouseOnRect )
{
d->mouseOnRect = false;
setCursor( arrowCursor );
}
}
updateCursor( e->pos() );
}
break;
@ -826,6 +805,9 @@ void PageView::wheelEvent( QWheelEvent *e )
}
else
QScrollView::wheelEvent( e );
QPoint cp = viewportToContents(e->pos());
updateCursor(cp);
}
void PageView::dragEnterEvent( QDragEnterEvent * ev )
@ -1120,6 +1102,32 @@ void PageView::updateZoomText()
d->aZoom->setCurrentItem( selIdx );
}
void PageView::updateCursor( const QPoint &p )
{
// detect the underlaying page (if present)
PageViewItem * pageItem = pickItemOnPoint( p.x(), p.y() );
if ( pageItem )
{
int pageX = p.x() - pageItem->geometry().left(),
pageY = p.y() - pageItem->geometry().top();
// check if over a KPDFPageRect
bool onRect = pageItem->page()->hasLink( pageX, pageY );
if ( onRect != d->mouseOnRect )
setCursor( (d->mouseOnRect = onRect) ? pointingHandCursor : arrowCursor );
}
else
{
// if there's no page over the cursor and we were showing the pointingHandCursor
// go back to the normal one
if ( d->mouseOnRect )
{
d->mouseOnRect = false;
setCursor( arrowCursor );
}
}
}
//BEGIN private SLOTS
void PageView::slotRelayoutPages()
// called by: pageSetup, viewportResizeEvent, slotTwoPagesToggled, slotContinousToggled, updateZoom

View file

@ -100,6 +100,8 @@ class PageView : public QScrollView, public KPDFDocumentObserver
void updateZoom( ZoomMode newZm );
// update the text on the label using global zoom value or current page's one
void updateZoomText();
// updates cursor
void updateCursor( const QPoint &p );
// don't want to expose classes in here
class PageViewPrivate * d;