Improve the hyperlink support, and make it less error-prone. Micro suppport for URL hyperlinks.

svn path=/trunk/playground/graphics/okular/; revision=555968
This commit is contained in:
Pino Toscano 2006-06-28 20:44:12 +00:00
parent e5018d700f
commit c39fdf8f5c
3 changed files with 33 additions and 13 deletions

View file

@ -163,23 +163,33 @@ void DjVuGenerator::djvuPixmapGenerated( int page, const QPixmap & pix )
KDjVu::PageLink* l = static_cast<KDjVu::PageLink*>( (*it) );
bool ok = true;
QString target = l->page();
if ( target.at(0) == QLatin1Char( '#' ) )
if ( ( target.length() > 0 ) && target.at(0) == QLatin1Char( '#' ) )
target.remove( 0, 1 );
int tmppage = target.toInt( &ok );
if ( ok )
if ( ok || target.isEmpty() )
{
DocumentViewport vp;
vp.pageNumber = ( target.at(0) == QLatin1Char( '+' ) || target.at(0) == QLatin1Char( '-' ) ) ? page + tmppage : tmppage - 1;
if ( !target.isEmpty() )
{
vp.pageNumber = ( target.at(0) == QLatin1Char( '+' ) || target.at(0) == QLatin1Char( '-' ) ) ? page + tmppage : tmppage - 1;
}
KPDFLinkGoto* go = new KPDFLinkGoto( QString::null, vp );
const KDjVu::Page* p = m_djvu->pages().at( vp.pageNumber );
const KDjVu::Page* p = m_djvu->pages().at( vp.pageNumber == -1 ? page : vp.pageNumber );
QRect r( QPoint( l->point().x(), p->height() - l->point().y() - l->size().height() ), l->size() );
newlink = new ObjectRect( NormalizedRect( r, p->width(), p->height() ), ObjectRect::Link, go );
}
break;
}
case KDjVu::Link::UrlLink:
// TODO
{
KDjVu::UrlLink* l = static_cast<KDjVu::UrlLink*>( (*it) );
QString url = l->url();
KPDFLinkBrowse* browse = new KPDFLinkBrowse( url );
const KDjVu::Page* p = m_djvu->pages().at( page );
QRect r( QPoint( l->point().x(), p->height() - l->point().y() - l->size().height() ), l->size() );
newlink = new ObjectRect( NormalizedRect( r, p->width(), p->height() ), ObjectRect::Link, browse );
break;
}
}
if ( newlink )
rects.append( newlink );

View file

@ -177,7 +177,7 @@ int KDjVu::UrlLink::type() const
return KDjVu::Link::UrlLink;
}
QUrl KDjVu::UrlLink::url() const
QString KDjVu::UrlLink::url() const
{
return m_url;
}
@ -458,9 +458,19 @@ QList<KDjVu::Link*> KDjVu::linksForPage( int pageNum ) const
KDjVu::Link* link = 0;
if ( miniexp_stringp( miniexp_nth( 1, cur ) ) )
{
KDjVu::PageLink* plink = new KDjVu::PageLink();
plink->m_page = QString::fromUtf8( miniexp_to_str( miniexp_nth( 1, cur ) ) );
link = plink;
QString target = QString::fromUtf8( miniexp_to_str( miniexp_nth( 1, cur ) ) );
if ( target.isEmpty() || ( ( target.length() > 0 ) && target.at(0) == QLatin1Char( '#' ) ) )
{
KDjVu::PageLink* plink = new KDjVu::PageLink();
plink->m_page = target;
link = plink;
}
else
{
KDjVu::UrlLink* ulink = new KDjVu::UrlLink();
ulink->m_url = target;
link = ulink;
}
}
else
{
@ -478,7 +488,8 @@ QList<KDjVu::Link*> KDjVu::linksForPage( int pageNum ) const
}
// TODO: other link shapes
ret.append( link );
if ( !( link->m_point.isNull() || link->m_size.isNull() ) )
ret.append( link );
}
}
return ret;

View file

@ -13,7 +13,6 @@
#include <qobject.h>
#include <qpixmap.h>
#include <qvector.h>
#include <qurl.h>
class QDomDocument;
@ -97,11 +96,11 @@ class KDjVu : public QObject
public:
virtual int type() const;
QUrl url() const;
QString url() const;
private:
UrlLink();
QUrl m_url;
QString m_url;
};