Changeset View
Changeset View
Standalone View
Standalone View
lib/documentview/svgviewadapter.cpp
Show All 23 Lines | |||||
24 | // Qt | 24 | // Qt | ||
25 | #include <QCursor> | 25 | #include <QCursor> | ||
26 | #include <QGraphicsSvgItem> | 26 | #include <QGraphicsSvgItem> | ||
27 | #include <QGraphicsTextItem> | 27 | #include <QGraphicsTextItem> | ||
28 | #include <QGraphicsWidget> | 28 | #include <QGraphicsWidget> | ||
29 | #include <QPainter> | 29 | #include <QPainter> | ||
30 | #include <QSvgRenderer> | 30 | #include <QSvgRenderer> | ||
31 | #include <QDebug> | 31 | #include <QDebug> | ||
32 | #include <QtMath> | ||||
32 | 33 | | |||
33 | // KDE | 34 | // KDE | ||
34 | 35 | | |||
35 | // Local | 36 | // Local | ||
36 | #include "document/documentfactory.h" | 37 | #include "document/documentfactory.h" | ||
37 | #include <qgraphicssceneevent.h> | 38 | #include <qgraphicssceneevent.h> | ||
38 | #include <lib/gvdebug.h> | 39 | #include <lib/gvdebug.h> | ||
39 | #include <lib/gwenviewconfig.h> | 40 | #include <lib/gwenviewconfig.h> | ||
40 | 41 | | |||
41 | namespace Gwenview | 42 | namespace Gwenview | ||
42 | { | 43 | { | ||
43 | 44 | | |||
44 | /// SvgImageView //// | 45 | /// SvgImageView //// | ||
45 | SvgImageView::SvgImageView(QGraphicsItem* parent) | 46 | SvgImageView::SvgImageView(QGraphicsItem* parent) | ||
46 | : AbstractImageView(parent) | 47 | : AbstractImageView(parent) | ||
47 | , mSvgItem(new QGraphicsSvgItem(this)) | 48 | , mSvgItem(new QGraphicsSvgItem(this)) | ||
48 | , mAlphaBackgroundMode(AbstractImageView::AlphaBackgroundCheckBoard) | 49 | , mAlphaBackgroundMode(AbstractImageView::AlphaBackgroundCheckBoard) | ||
49 | , mAlphaBackgroundColor(Qt::black) | 50 | , mAlphaBackgroundColor(Qt::black) | ||
50 | , mImageFullyLoaded(false) | 51 | , mImageFullyLoaded(false) | ||
51 | { | 52 | { | ||
53 | // At certain scales, the SVG can render outside its own bounds up to 1 pixel | ||||
54 | // This clips it so it isn't drawn outside the background or over the selection rect | ||||
55 | mSvgItem->setFlag(ItemClipsToShape); | ||||
56 | | ||||
52 | // So we aren't unnecessarily drawing the background for every paint() | 57 | // So we aren't unnecessarily drawing the background for every paint() | ||
53 | setCacheMode(QGraphicsItem::DeviceCoordinateCache); | 58 | setCacheMode(QGraphicsItem::DeviceCoordinateCache); | ||
54 | } | 59 | } | ||
55 | 60 | | |||
56 | void SvgImageView::loadFromDocument() | 61 | void SvgImageView::loadFromDocument() | ||
57 | { | 62 | { | ||
58 | Document::Ptr doc = document(); | 63 | Document::Ptr doc = document(); | ||
59 | GV_RETURN_IF_FAIL(doc); | 64 | GV_RETURN_IF_FAIL(doc); | ||
Show All 36 Lines | |||||
96 | 101 | | |||
97 | void SvgImageView::onScrollPosChanged(const QPointF& /* oldPos */) | 102 | void SvgImageView::onScrollPosChanged(const QPointF& /* oldPos */) | ||
98 | { | 103 | { | ||
99 | adjustItemPos(); | 104 | adjustItemPos(); | ||
100 | } | 105 | } | ||
101 | 106 | | |||
102 | void SvgImageView::adjustItemPos() | 107 | void SvgImageView::adjustItemPos() | ||
103 | { | 108 | { | ||
104 | mSvgItem->setPos(imageOffset() - scrollPos()); | 109 | mSvgItem->setPos((imageOffset() - scrollPos()).toPoint()); | ||
105 | update(); | 110 | update(); | ||
106 | } | 111 | } | ||
107 | 112 | | |||
108 | void SvgImageView::setAlphaBackgroundMode(AbstractImageView::AlphaBackgroundMode mode) | 113 | void SvgImageView::setAlphaBackgroundMode(AbstractImageView::AlphaBackgroundMode mode) | ||
109 | { | 114 | { | ||
110 | mAlphaBackgroundMode = mode; | 115 | mAlphaBackgroundMode = mode; | ||
111 | update(); | 116 | update(); | ||
112 | } | 117 | } | ||
113 | 118 | | |||
114 | void SvgImageView::setAlphaBackgroundColor(const QColor& color) | 119 | void SvgImageView::setAlphaBackgroundColor(const QColor& color) | ||
115 | { | 120 | { | ||
116 | mAlphaBackgroundColor = color; | 121 | mAlphaBackgroundColor = color; | ||
117 | update(); | 122 | update(); | ||
118 | } | 123 | } | ||
119 | 124 | | |||
120 | void SvgImageView::drawAlphaBackground(QPainter* painter) | 125 | void SvgImageView::drawAlphaBackground(QPainter* painter) | ||
121 | { | 126 | { | ||
122 | const QRectF imageRect = QRectF(imageOffset(), visibleImageSize()); | 127 | // The point and size must be rounded to integers independently, to keep consistency with RasterImageView | ||
128 | const QRect imageRect = QRect(imageOffset().toPoint(), visibleImageSize().toSize()); | ||||
123 | 129 | | |||
124 | switch (mAlphaBackgroundMode) { | 130 | switch (mAlphaBackgroundMode) { | ||
125 | case AbstractImageView::AlphaBackgroundNone: | 131 | case AbstractImageView::AlphaBackgroundNone: | ||
126 | // Unlike RasterImageView, SVGs are rendered directly on the image view, | 132 | // Unlike RasterImageView, SVGs are rendered directly on the image view, | ||
127 | // therefore we can simply not draw a background | 133 | // therefore we can simply not draw a background | ||
128 | break; | 134 | break; | ||
129 | case AbstractImageView::AlphaBackgroundCheckBoard: | 135 | case AbstractImageView::AlphaBackgroundCheckBoard: | ||
130 | painter->drawTiledPixmap(imageRect, alphaBackgroundTexture(), scrollPos()); | 136 | painter->drawTiledPixmap(imageRect, alphaBackgroundTexture(), scrollPos()); | ||
▲ Show 20 Lines • Show All 127 Lines • Show Last 20 Lines |