Changeset View
Changeset View
Standalone View
Standalone View
src/qmlcontrols/kquickcontrolsaddons/qpixmapitem.cpp
Show First 20 Lines • Show All 154 Lines • ▼ Show 20 Line(s) | |||||
155 | 155 | | |||
156 | void QPixmapItem::updatePaintedRect() | 156 | void QPixmapItem::updatePaintedRect() | ||
157 | { | 157 | { | ||
158 | 158 | | |||
159 | if (m_pixmap.isNull()) { | 159 | if (m_pixmap.isNull()) { | ||
160 | return; | 160 | return; | ||
161 | } | 161 | } | ||
162 | 162 | | |||
163 | QRect sourceRect = m_paintedRect; | 163 | QRectF sourceRect = m_paintedRect; | ||
164 | 164 | | |||
165 | QRect destRect; | 165 | QRectF destRect; | ||
166 | 166 | | |||
167 | switch (m_fillMode) { | 167 | switch (m_fillMode) { | ||
168 | case PreserveAspectFit: { | 168 | case PreserveAspectFit: { | ||
169 | QSize scaled = m_pixmap.size(); | 169 | QSizeF scaled = m_pixmap.size(); | ||
170 | 170 | | |||
171 | scaled.scale(boundingRect().size().toSize(), Qt::KeepAspectRatio); | 171 | scaled.scale(boundingRect().size(), Qt::KeepAspectRatio); | ||
172 | destRect = QRect(QPoint(0, 0), scaled); | 172 | destRect = QRectF(QPoint(0, 0), scaled); | ||
173 | destRect.moveCenter(boundingRect().center().toPoint()); | 173 | destRect.moveCenter(boundingRect().center().toPoint()); | ||
174 | | ||||
174 | break; | 175 | break; | ||
175 | } | 176 | } | ||
176 | case PreserveAspectCrop: { | 177 | case PreserveAspectCrop: { | ||
177 | QSize scaled = m_pixmap.size(); | 178 | QSizeF scaled = m_pixmap.size(); | ||
178 | 179 | | |||
179 | scaled.scale(boundingRect().size().toSize(), Qt::KeepAspectRatioByExpanding); | 180 | scaled.scale(boundingRect().size(), Qt::KeepAspectRatioByExpanding); | ||
180 | destRect = QRect(QPoint(0, 0), scaled); | 181 | destRect = QRectF(QPoint(0, 0), scaled); | ||
181 | destRect.moveCenter(boundingRect().center().toPoint()); | 182 | destRect.moveCenter(boundingRect().center().toPoint()); | ||
182 | break; | 183 | break; | ||
183 | } | 184 | } | ||
184 | case TileVertically: { | 185 | case TileVertically: { | ||
185 | destRect = boundingRect().toRect(); | 186 | destRect = boundingRect().toRect(); | ||
186 | destRect.setWidth(destRect.width() / (width()/(qreal)m_pixmap.width())); | 187 | destRect.setWidth(destRect.width() / (width()/(qreal)m_pixmap.width())); | ||
187 | break; | 188 | break; | ||
188 | } | 189 | } | ||
189 | case TileHorizontally: { | 190 | case TileHorizontally: { | ||
190 | destRect = boundingRect().toRect(); | 191 | destRect = boundingRect().toRect(); | ||
191 | destRect.setHeight(destRect.height() / (height()/(qreal)m_pixmap.height())); | 192 | destRect.setHeight(destRect.height() / (height()/(qreal)m_pixmap.height())); | ||
192 | break; | 193 | break; | ||
193 | } | 194 | } | ||
194 | case Stretch: | 195 | case Stretch: | ||
195 | case Tile: | 196 | case Tile: | ||
196 | default: | 197 | default: | ||
197 | destRect = boundingRect().toRect(); | 198 | destRect = boundingRect().toRect(); | ||
198 | } | 199 | } | ||
199 | 200 | | |||
200 | if (destRect != sourceRect) { | 201 | if (destRect != sourceRect) { | ||
201 | m_paintedRect = destRect; | 202 | m_paintedRect = destRect.toRect(); | ||
202 | emit paintedHeightChanged(); | 203 | emit paintedHeightChanged(); | ||
203 | emit paintedWidthChanged(); | 204 | emit paintedWidthChanged(); | ||
204 | } | 205 | } | ||
205 | } | 206 | } | ||
206 | 207 | | |||
207 | void QPixmapItem::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) | 208 | void QPixmapItem::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) | ||
208 | { | 209 | { | ||
209 | QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry); | 210 | QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry); | ||
210 | updatePaintedRect(); | 211 | updatePaintedRect(); | ||
211 | } | 212 | } | ||
212 | 213 | |