Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
Add support for links, hyperlinks and outlines to the pdf print system
Browse files Browse the repository at this point in the history
  • Loading branch information
antialize authored and ashkulz committed Jan 20, 2016
1 parent 017c23f commit baf0626
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/gui/painting/qpaintengine.h
Expand Up @@ -45,6 +45,7 @@
#include <QtCore/qnamespace.h>
#include <QtCore/qobjectdefs.h>
#include <QtCore/qscopedpointer.h>
#include <QtCore/qurl.h>
#include <QtGui/qpainter.h>

QT_BEGIN_HEADER
Expand Down Expand Up @@ -162,6 +163,10 @@ class Q_GUI_EXPORT QPaintEngine
virtual void drawRects(const QRect *rects, int rectCount);
virtual void drawRects(const QRectF *rects, int rectCount);

virtual void addHyperlink(const QRectF &r, const QUrl &url) {Q_UNUSED(r); Q_UNUSED(url);}
virtual void addAnchor(const QRectF &r, const QString &name) {Q_UNUSED(r); Q_UNUSED(name);}
virtual void addLink(const QRectF &r, const QString &anchor) {Q_UNUSED(r); Q_UNUSED(anchor);}

virtual void drawLines(const QLine *lines, int lineCount);
virtual void drawLines(const QLineF *lines, int lineCount);

Expand Down
166 changes: 166 additions & 0 deletions src/gui/painting/qpainter.cpp
Expand Up @@ -7254,6 +7254,172 @@ void QPainter::fillRect(const QRectF &r, const QColor &color)
\since 4.5
*/


/*!
\fn void QPainter::addAnchor(int x, int y, int w, int h, const QString &name);
\overload
Add an anchor to the current page at the rect specified by \a x, \a y, \a w and \a h
named \a name.
Note that for output formats not supporting links, currently all other then PDF,
this call has no effect.
\sa addLink()
\since 4.7
*/

/*!
\fn void QPainter::addAnchor(const QRect &r, const QString &name);
\overload
Add an anchor to the current page at the rect specified by \a r named \a name.
Note that for output formats not supporting links, currently all other then PDF,
this call has no effect.
\sa addLink()
\since 4.7
*/

/*!
\fn void addAnchor(const QRectF &r, const QString &name);
\overload
Add an anchor to the current page at the rect specified by \a r named \a name.
Note that for output formats not supporting links, currently all other then PDF,
this call has no effect.
\sa addLink()
\since 4.7
*/
void QPainter::addAnchor(const QRectF &r, const QString &name)
{
Q_D(QPainter);
if (!d->engine) {
qWarning("QPainter::addAnchor: Painter not active");
return;
}
d->engine->addAnchor(worldTransform().mapRect(r), name);
}

/*!
\fn void QPainter::addLink(int x, int y, int w, int h, const QString &anchor);
\overload
Add a link to the current page at the rect specified by \a x, \a y, \a w and \a h
linking to the anchor named \a anchor.
Note that for output formats not supporting links, currently all other then PDF,
this call has no effect.
\sa addAnchor()
\since 4.7
*/

/*!
\fn void QPainter::addLink(const QRect &r, const QString &anchor);
\overload
Add a link to the current page at the rect specified by \a r
linking to the anchor named \a anchor.
Note that for output formats not supporting links, currently all other then PDF,
this call has no effect.
\sa addAnchor()
\since 4.7
*/

/*!
\fn void QPainter::addLink(const QRectF &r, const QString &anchor);
\overload
Add a link to the current page at the rect specified by \a r
linking to the anchor named \a anchor.
Note that for output formats not supporting links, currently all other then PDF,
this call has no effect.
\sa addAnchor()
\since 4.7
*/
void QPainter::addLink(const QRectF &r, const QString &anchor)
{
Q_D(QPainter);
if (!d->engine) {
qWarning("QPainter::addLink: Painter not active");
return;
}

d->engine->addLink(worldTransform().mapRect(r), anchor);
}


/*!
\fn void QPainter::addHyperlink(int x, int y, int w, int h, const QUrl &url);
\overload
Add a link to the current page at the rect specified by \a x, \a y, \a w and \a h
linking to \a url.
Note that for output formats not supporting links, currently all other then PDF,
this call has no effect.
\since 4.7
*/

/*!
\fn void QPainter::addHyperlink(const QRect &r, const QUrl &url);
\overload
Add a link to the current page at the rect specified by \a r
linking to \a url.
Note that for output formats not supporting links, currently all other then PDF,
this call has no effect.
\since 4.7
*/

/*!
\fn void QPainter::addHyperlink(const QRectF &r, const QUrl &url);
\overload
Add a link to the current page at the rect specified by \a r
linking to \a url.
Note that for output formats not supporting links, currently all other then PDF,
this call has no effect.
\since 4.7
*/
void QPainter::addHyperlink(const QRectF &r, const QUrl &url)
{
Q_D(QPainter);
if (!d->engine) {
qWarning("QPainter::addHyperlink: Painter not active");
return;
}
d->engine->addHyperlink(worldTransform().mapRect(r), url);
}

/*!
Sets the given render \a hint on the painter if \a on is true;
otherwise clears the render hint.
Expand Down
41 changes: 41 additions & 0 deletions src/gui/painting/qpainter.h
Expand Up @@ -447,6 +447,18 @@ class Q_GUI_EXPORT QPainter
inline void fillRect(const QRect &r, Qt::BrushStyle style);
inline void fillRect(const QRectF &r, Qt::BrushStyle style);

inline void addAnchor(int x, int y, int w, int h, const QString &name);
inline void addAnchor(const QRect &r, const QString &name);
void addAnchor(const QRectF &r, const QString &name);

inline void addLink(int x, int y, int w, int h, const QString &anchor);
inline void addLink(const QRect &r, const QString &anchor);
void addLink(const QRectF &r, const QString &anchor);

inline void addHyperlink(int x, int y, int w, int h, const QUrl &url);
inline void addHyperlink(const QRect &r, const QUrl &url);
void addHyperlink(const QRectF &r, const QUrl &url);

void eraseRect(const QRectF &);
inline void eraseRect(int x, int y, int w, int h);
inline void eraseRect(const QRect &);
Expand Down Expand Up @@ -821,6 +833,35 @@ inline void QPainter::fillRect(const QRectF &r, Qt::BrushStyle style)
fillRect(r, QBrush(style));
}

inline void QPainter::addAnchor(int x, int y, int w, int h, const QString &name)
{
addAnchor(QRectF(x, y, w, h), name);
}

inline void QPainter::addAnchor(const QRect &r, const QString &name)
{
addAnchor(QRectF(r), name);
}

inline void QPainter::addLink(int x, int y, int w, int h, const QString &anchor)
{
addLink(QRectF(x, y, w, h), anchor);
}

inline void QPainter::addLink(const QRect &r, const QString &anchor)
{
addLink(QRectF(r), anchor);
}

inline void QPainter::addHyperlink(int x, int y, int w, int h, const QUrl &url)
{
addHyperlink(QRectF(x, y, w, h), url);
}

inline void QPainter::addHyperlink(const QRect &r, const QUrl &url)
{
addHyperlink(QRectF(r), url);
}

inline void QPainter::setBrushOrigin(int x, int y)
{
Expand Down
2 changes: 2 additions & 0 deletions src/gui/painting/qprintengine.h
Expand Up @@ -97,6 +97,8 @@ class Q_GUI_EXPORT QPrintEngine
virtual QVariant property(PrintEnginePropertyKey key) const = 0;

virtual bool newPage() = 0;
virtual void beginSectionOutline(const QString &text, const QString &anchor) {Q_UNUSED(text); Q_UNUSED(anchor);}
virtual void endSectionOutline() {}
virtual bool abort() = 0;

virtual int metric(QPaintDevice::PaintDeviceMetric) const = 0;
Expand Down

0 comments on commit baf0626

Please sign in to comment.