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