Commit 2f3f5cca authored by Enrico Ros's avatar Enrico Ros

merged patch042,043

svn path=/branches/kpdf/annotations/kdegraphics/kpdf/; revision=424893
parent 371d546c
......@@ -121,6 +121,7 @@ Done (newest features come first):
-> ADD: annotations: PDF1.6 reader (PDF's annotations -> our data structures)
-> ADD: Internal data structures for annotations handling.
-> FIX: rmb when no doc displayed to restore menu
-> ADD: partial implementation of XYZ links
-> ADD: google-like search on thumbnails
-> ADD: use kde wallet for storing passwords of protected files
*> The branch 'kpdf_annotations' was created at this point. [2005-Feb-12]
......
......@@ -739,9 +739,9 @@ bool KPDFDocument::searchText( int searchID, const QString & text, bool fromStar
if ( moveViewport )
{
DocumentViewport searchViewport( currentPage );
searchViewport.reCenter.enabled = true;
searchViewport.reCenter.normalizedCenterX = (match->left + match->right) / 2.0;
searchViewport.reCenter.normalizedCenterY = (match->top + match->bottom) / 2.0;
searchViewport.rePos.enabled = true;
searchViewport.rePos.normalizedX = (match->left + match->right) / 2.0;
searchViewport.rePos.normalizedY = (match->top + match->bottom) / 2.0;
setViewport( searchViewport, -1, true );
}
}
......@@ -896,7 +896,7 @@ void KPDFDocument::processLink( const KPDFLink * link )
const KPDFLinkGoto * go = static_cast< const KPDFLinkGoto * >( link );
d->nextDocumentViewport = go->destViewport();
// Explanation of why d->nextDocumentViewport is needed
// Explanation of why d->nextDocumentViewport is needed:
// all openRelativeFile does is launch a signal telling we
// want to open another URL, the problem is that when the file is
// non local, the loading is done assynchronously so you can't
......@@ -912,7 +912,7 @@ void KPDFDocument::processLink( const KPDFLink * link )
}
else
{
setViewport( d->nextDocumentViewport );
setViewport( d->nextDocumentViewport, -1, true );
d->nextDocumentViewport = DocumentViewport();
}
......@@ -1419,9 +1419,10 @@ DocumentViewport::DocumentViewport( int n )
: pageNumber( n )
{
// default settings
reCenter.enabled = false;
reCenter.normalizedCenterX = 0.5;
reCenter.normalizedCenterY = 0.0;
rePos.enabled = false;
rePos.normalizedX = 0.5;
rePos.normalizedY = 0.0;
rePos.pos = Center;
autoFit.enabled = false;
autoFit.width = false;
autoFit.height = false;
......@@ -1431,9 +1432,10 @@ DocumentViewport::DocumentViewport( const QString & xmlDesc )
: pageNumber( -1 )
{
// default settings (maybe overridden below)
reCenter.enabled = false;
reCenter.normalizedCenterX = 0.5;
reCenter.normalizedCenterY = 0.0;
rePos.enabled = false;
rePos.normalizedX = 0.5;
rePos.normalizedY = 0.0;
rePos.pos = Center;
autoFit.enabled = false;
autoFit.width = false;
autoFit.height = false;
......@@ -1457,9 +1459,18 @@ DocumentViewport::DocumentViewport( const QString & xmlDesc )
}
else if ( token.startsWith( "C1" ) )
{
reCenter.enabled = true;
reCenter.normalizedCenterX = token.section( ':', 1, 1 ).toDouble();
reCenter.normalizedCenterY = token.section( ':', 2, 2 ).toDouble();
rePos.enabled = true;
rePos.normalizedX = token.section( ':', 1, 1 ).toDouble();
rePos.normalizedY = token.section( ':', 2, 2 ).toDouble();
rePos.pos = Center;
}
else if ( token.startsWith( "C2" ) )
{
rePos.enabled = true;
rePos.normalizedX = token.section( ':', 1, 1 ).toDouble();
rePos.normalizedY = token.section( ':', 2, 2 ).toDouble();
if (token.section( ':', 3, 3 ).toInt() == 1) rePos.pos = Center;
else rePos.pos = TopLeft;
}
else if ( token.startsWith( "AF1" ) )
{
......@@ -1478,9 +1489,10 @@ QString DocumentViewport::toString() const
// start string with page number
QString s = QString::number( pageNumber );
// if has center coordinates, save them on string
if ( reCenter.enabled )
s += QString( ";C1:" ) + QString::number( reCenter.normalizedCenterX ) +
':' + QString::number( reCenter.normalizedCenterY );
if ( rePos.enabled )
s += QString( ";C2:" ) + QString::number( rePos.normalizedX ) +
':' + QString::number( rePos.normalizedY ) +
':' + QString::number( rePos.pos );
// if has autofit enabled, save its state on string
if ( autoFit.enabled )
s += QString( ";AF1:" ) + (autoFit.width ? "T" : "F") +
......@@ -1491,13 +1503,13 @@ QString DocumentViewport::toString() const
bool DocumentViewport::operator==( const DocumentViewport & vp ) const
{
bool equal = ( pageNumber == vp.pageNumber ) &&
( reCenter.enabled == vp.reCenter.enabled ) &&
( rePos.enabled == vp.rePos.enabled ) &&
( autoFit.enabled == vp.autoFit.enabled );
if ( !equal )
return false;
if ( reCenter.enabled &&
(( reCenter.normalizedCenterX != vp.reCenter.normalizedCenterX ) ||
( reCenter.normalizedCenterY != vp.reCenter.normalizedCenterY )) )
if ( rePos.enabled &&
(( rePos.normalizedX != vp.rePos.normalizedX) ||
( rePos.normalizedY != vp.rePos.normalizedY ) || rePos.pos != vp.rePos.pos) )
return false;
if ( autoFit.enabled &&
(( autoFit.width != vp.autoFit.width ) ||
......
......@@ -141,12 +141,16 @@ class DocumentViewport
// the page nearest the center of the viewport
int pageNumber;
// enum definitions
enum Position { Center = 1, TopLeft = 2};
// if reCenter.enabled, this contains the viewport center
struct {
bool enabled;
double normalizedCenterX;
double normalizedCenterY;
} reCenter;
double normalizedX;
double normalizedY;
Position pos;
} rePos;
// if autoFit.enabled, page must be autofitted in the viewport
struct {
......
......@@ -381,14 +381,19 @@ DocumentViewport KPDFOutputDev::decodeViewport( GString * namedDest, LinkDest *
switch ( dest->getKind() )
{
case destXYZ:
/* OD -> cvtUserToDev( dest->getLeft(), dest->getTop(), &X, &Y );
if ( dest->getChangeLeft() )
make hor change
if ( dest->getChangeTop() )
make ver change
if ( dest->getChangeZoom() )
make zoom change
*/ break;
if (dest->getChangeLeft() || dest->getChangeTop())
{
int left, top;
cvtUserToDev( dest->getLeft(), dest->getTop(), &left, &top );
vp.rePos.normalizedX = (double)left / (double)m_pixmapWidth;
vp.rePos.normalizedY = (double)top / (double)m_pixmapHeight;
vp.rePos.enabled = true;
vp.rePos.pos = DocumentViewport::TopLeft;
}
// TODO
//if ( dest->getChangeZoom() )
// make zoom change
break;
case destFit:
case destFitB:
......@@ -398,18 +403,18 @@ DocumentViewport KPDFOutputDev::decodeViewport( GString * namedDest, LinkDest *
case destFitH:
case destFitBH:
// read top, fit Width
//read top, fit Width
//vp.fitWidth = true;
break;
case destFitV:
case destFitBV:
// read left, fit Height
//read left, fit Height
//vp.fitHeight = true;
break;
case destFitR:
// read and fit left,bottom,right,top
//read and fit left,bottom,right,top
break;
}
......
......@@ -344,10 +344,19 @@ void PageView::notifyViewportChanged( bool smoothMove )
const QRect & r = item->geometry();
int newCenterX = r.left(),
newCenterY = r.top();
if ( vp.reCenter.enabled )
if ( vp.rePos.enabled )
{
newCenterX += (int)( vp.reCenter.normalizedCenterX * (double)r.width() );
newCenterY += (int)( vp.reCenter.normalizedCenterY * (double)r.height() );
if ( vp.rePos.pos == DocumentViewport::Center )
{
newCenterX += (int)( vp.rePos.normalizedX * (double)r.width() );
newCenterY += (int)( vp.rePos.normalizedY * (double)r.height() );
}
else
{
// TopLeft
newCenterX += (int)( vp.rePos.normalizedX * (double)r.width() + viewport()->width() / 2 );
newCenterY += (int)( vp.rePos.normalizedY * (double)r.height() + viewport()->height() / 2 );
}
}
else
{
......@@ -683,8 +692,8 @@ void PageView::keyPressEvent( QKeyEvent * e )
newViewport.pageNumber -= Settings::viewColumns();
if ( newViewport.pageNumber < 0 )
newViewport.pageNumber = 0;
newViewport.reCenter.enabled = true;
newViewport.reCenter.normalizedCenterY = 1.0;
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedY = 1.0;
d->document->setViewport( newViewport );
}
break;
......@@ -700,13 +709,13 @@ void PageView::keyPressEvent( QKeyEvent * e )
}
else if ( d->document->currentPage() < d->items.count() - 1 )
{
// more optmized than document->setNextPage and then move view to top
// more optimized than document->setNextPage and then move view to top
DocumentViewport newViewport = d->document->viewport();
newViewport.pageNumber += d->document->currentPage() ? Settings::viewColumns() : 1;
if ( newViewport.pageNumber >= (int)d->items.count() )
newViewport.pageNumber = d->items.count() - 1;
newViewport.reCenter.enabled = true;
newViewport.reCenter.normalizedCenterY = 0.0;
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedY = 0.0;
d->document->setViewport( newViewport );
}
break;
......@@ -1220,13 +1229,13 @@ void PageView::wheelEvent( QWheelEvent *e )
// go to next page
if ( d->document->currentPage() < d->items.count() - 1 )
{
// more optmized than document->setNextPage and then move view to top
// more optimized than document->setNextPage and then move view to top
DocumentViewport newViewport = d->document->viewport();
newViewport.pageNumber += d->document->currentPage() ? Settings::viewColumns() : 1;
if ( newViewport.pageNumber >= (int)d->items.count() )
newViewport.pageNumber = d->items.count() - 1;
newViewport.reCenter.enabled = true;
newViewport.reCenter.normalizedCenterY = 0.0;
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedY = 0.0;
d->document->setViewport( newViewport );
}
}
......@@ -1235,13 +1244,13 @@ void PageView::wheelEvent( QWheelEvent *e )
// go to prev page
if ( d->document->currentPage() > 0 )
{
// more optmized than document->setPrevPage and then move view to bottom
// more optimized than document->setPrevPage and then move view to bottom
DocumentViewport newViewport = d->document->viewport();
newViewport.pageNumber -= Settings::viewColumns();
if ( newViewport.pageNumber < 0 )
newViewport.pageNumber = 0;
newViewport.reCenter.enabled = true;
newViewport.reCenter.normalizedCenterY = 1.0;
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedY = 1.0;
d->document->setViewport( newViewport );
}
}
......@@ -1773,8 +1782,8 @@ void PageView::slotRelayoutPages()
int prevX = contentsX(),
prevY = contentsY();
const QRect & geometry = d->items[ vp.pageNumber ]->geometry();
double nX = vp.reCenter.enabled ? vp.reCenter.normalizedCenterX : 0.5,
nY = vp.reCenter.enabled ? vp.reCenter.normalizedCenterY : 0.0;
double nX = vp.rePos.enabled ? vp.rePos.normalizedX : 0.5,
nY = vp.rePos.enabled ? vp.rePos.normalizedY : 0.0;
center( geometry.left() + ROUND( nX * (double)geometry.width() ),
geometry.top() + ROUND( nY * (double)geometry.height() ) );
// center() usually moves the viewport, that requests pixmaps too.
......@@ -1895,9 +1904,9 @@ void PageView::slotRequestVisiblePixmaps( int newLeft, int newTop )
{
// determine the document viewport
DocumentViewport newViewport( nearPageNumber );
newViewport.reCenter.enabled = true;
newViewport.reCenter.normalizedCenterX = focusedX;
newViewport.reCenter.normalizedCenterY = focusedY;
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedX = focusedX;
newViewport.rePos.normalizedY = focusedY;
// set the viewport to other observers
d->document->setViewport( newViewport , PAGEVIEW_ID);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment