Changeset View
Changeset View
Standalone View
Standalone View
src/declarativeitems/lessonpainter.cpp
Context not available. | |||||
181 | 181 | | |||
---|---|---|---|---|---|
182 | void LessonPainter::paint(QPainter* painter) | 182 | void LessonPainter::paint(QPainter* painter) | ||
183 | { | 183 | { | ||
184 | checkImageCache(); | 184 | if (m_imageCacheDirty) | ||
185 | painter->drawPixmap(0, 0, m_imageCache); | 185 | { | ||
186 | const auto device = painter->device(); | ||||
187 | QImage img(QSize(qFloor(device->width()), qFloor(device->height())), QImage::Format_ARGB32_Premultiplied); | ||||
188 | img.setDevicePixelRatio(img.width() / width()); | ||||
189 | img.fill(Qt::transparent); | ||||
190 | QPainter painter(&img); | ||||
191 | painter.scale(m_textScale, m_textScale); | ||||
192 | m_doc->drawContents(&painter); | ||||
193 | m_imageCache = img; | ||||
194 | m_imageCacheDirty = false; | ||||
195 | } | ||||
196 | | ||||
197 | painter->drawImage(0, 0, m_imageCache); | ||||
186 | } | 198 | } | ||
187 | 199 | | |||
188 | void LessonPainter::updateLayout() | 200 | void LessonPainter::updateLayout() | ||
Context not available. | |||||
317 | void LessonPainter::invalidateImageCache() | 329 | void LessonPainter::invalidateImageCache() | ||
318 | { | 330 | { | ||
319 | m_imageCacheDirty = true; | 331 | m_imageCacheDirty = true; | ||
320 | m_imageCache = QPixmap(); | 332 | m_imageCache = QImage(); | ||
321 | } | 333 | } | ||
322 | 334 | | |||
323 | void LessonPainter::checkImageCache() | 335 | void LessonPainter::checkImageCache() | ||
Context not available. | |||||
325 | if (!m_imageCacheDirty) | 337 | if (!m_imageCacheDirty) | ||
326 | return; | 338 | return; | ||
327 | 339 | | |||
328 | QPixmap img(qFloor(width()), qFloor(height())); | 340 | QImage img(QSize(qFloor(width()), qFloor(height())), QImage::Format_ARGB32_Premultiplied); | ||
329 | img.fill(Qt::transparent); | 341 | img.fill(Qt::transparent); | ||
330 | QPainter painter(&img); | 342 | QPainter painter(&img); | ||
331 | painter.scale(m_textScale, m_textScale); | 343 | painter.scale(m_textScale, m_textScale); | ||
Context not available. |