Commit d0e3a77d authored by Tobias Deiminger's avatar Tobias Deiminger

Add line annotation ending arrows for non PDF documents

Summary:
This implements drawing the various line ending styles for 2 point lines in non-PDF documents.

Looks like this:
{F6833437}

CCBUG: 381629

Test Plan:
- open a *.txt document
- draw line annotations with different arrow styles: Square, Diamond, OpenArrow, ClosedArrow, ROpenArrow, RClosedArrow, Butt, Slash, Circle
- ... as start and as end style (start needs D21238 to be configurable in GUI)
- ... filled or not (fill color can't be configured in GUI yet)
- ... with different leader line settings
- ... at various angles
- rotate and scale page
- leader line with setting 100 gives 100 pixel line at 100% zoom (use kruler to verify)

Reviewers: #okular, aacid, sander

Reviewed By: sander

Subscribers: ngraham, sander, knambiar, okular-devel

Tags: #okular

Differential Revision: https://phabricator.kde.org/D21248
parent 951004fd
......@@ -529,10 +529,6 @@ QWidget * LineAnnotationWidget::createStyleWidget()
tmplabel4->setBuddy( m_endStyleCombo );
gridlay2->addWidget( m_startStyleCombo, 1, 1, Qt::AlignLeft );
gridlay2->addWidget( m_endStyleCombo, 2, 1, Qt::AlignLeft );
tmplabel3->setToolTip( i18n("Only for PDF documents") );
tmplabel4->setToolTip( i18n("Only for PDF documents") );
m_startStyleCombo->setToolTip( i18n("Only for PDF documents") );
m_endStyleCombo->setToolTip( i18n("Only for PDF documents") );
for ( const QString &i: { i18n( "Square" ), i18n( "Circle" ), i18n( "Diamond" ), i18n( "Open Arrow" ), i18n( "Closed Arrow" ),
i18n( "None" ), i18n( "Butt" ), i18n( "Right Open Arrow" ), i18n( "Right Closed Arrow" ), i18n( "Slash" ) } )
......
This diff is collapsed.
......@@ -14,6 +14,7 @@
#include <QImage>
#include <QPen>
#include "core/annotations.h"
#include "core/area.h" // for NormalizedPoint
class QPainter;
......@@ -72,6 +73,56 @@ class Q_DECL_EXPORT PagePainter
RasterOperation op = Normal
//float antiAliasRadius = 1.0
);
static void drawEllipseOnImage(
QImage & image,
const NormalizedPath & rect,
const QPen & pen,
const QBrush & brush,
double penWidthMultiplier,
RasterOperation op
);
friend class LineAnnotPainter;
};
class LineAnnotPainter {
public:
LineAnnotPainter( const Okular::LineAnnotation * a, QSizeF pageSizeA, double pageScale, const QTransform &toNormalizedImage );
void draw( QImage &image ) const;
private:
void drawMainLine( QImage &image ) const;
void drawShortenedLine( double mainSegmentLength, double size, QImage &image, const QTransform& toNormalizedPage ) const;
void drawLineEnds( double mainSegmentLength, double size, QImage &image, const QTransform& transform ) const;
void drawLineEndArrow( double xEndPos, double size, double flipX, bool close, const QTransform& toNormalizedPage, QImage &image ) const;
void drawLineEndButt( double xEndPos, double size, const QTransform& toNormalizedPage, QImage &image ) const;
void drawLineEndCircle( double xEndPos, double size, const QTransform& toNormalizedPage, QImage &image ) const;
void drawLineEndSquare( double xEndPos, double size, const QTransform& toNormalizedPage, QImage &image ) const;
void drawLineEndDiamond( double xEndPos, double size, const QTransform& toNormalizedPage, QImage &image ) const;
void drawLineEndSlash( double xEndPos, double size, const QTransform& toNormalizedPage, QImage &image ) const;
void drawLeaderLine( double xEndPos, QImage &image, const QTransform& toNormalizedPage ) const;
template <typename T> QList<Okular::NormalizedPoint> transformPath( const T& path, const QTransform& transform ) const
{
QList<Okular::NormalizedPoint> transformedPath;
for( const Okular::NormalizedPoint &item : path )
{
Okular::NormalizedPoint p;
transform.map( item.x, item.y, &p.x, &p.y );
transformedPath.append(p);
}
return transformedPath;
}
static double shortenForArrow( double size, Okular::LineAnnotation::TermStyle endStyle );
private:
const Okular::LineAnnotation* la;
QSizeF pageSize;
double pageScale;
QTransform toNormalizedImage;
double aspectRatio;
const QPen linePen;
QBrush fillBrush;
};
#endif
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