Changeset View
Changeset View
Standalone View
Standalone View
libkcardgame/kcardthemewidget.cpp
Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | 75 | { | |||
---|---|---|---|---|---|
76 | foreach( const KCardTheme & theme, m_themes ) | 76 | foreach( const KCardTheme & theme, m_themes ) | ||
77 | { | 77 | { | ||
78 | { | 78 | { | ||
79 | QMutexLocker l( &m_haltMutex ); | 79 | QMutexLocker l( &m_haltMutex ); | ||
80 | if ( m_haltFlag ) | 80 | if ( m_haltFlag ) | ||
81 | return; | 81 | return; | ||
82 | } | 82 | } | ||
83 | 83 | | |||
84 | QImage img( d->previewSize, QImage::Format_ARGB32 ); | 84 | const auto dpr = qApp->devicePixelRatio(); | ||
85 | QImage img( d->previewSize * dpr, QImage::Format_ARGB32 ); | ||||
davidedmundson: this image doesn't have the DPR set | |||||
85 | img.fill( Qt::transparent ); | 86 | img.fill( Qt::transparent ); | ||
86 | QPainter p( &img ); | 87 | QPainter p( &img ); | ||
87 | 88 | | |||
88 | QSvgRenderer renderer( theme.graphicsFilePath() ); | 89 | QSvgRenderer renderer( theme.graphicsFilePath() ); | ||
89 | 90 | | |||
90 | QSizeF size = renderer.boundsOnElement(QStringLiteral("back")).size(); | 91 | QSizeF size = renderer.boundsOnElement(QStringLiteral("back")).size(); | ||
91 | size.scale( 1.5 * d->baseCardSize.width(), d->baseCardSize.height(), Qt::KeepAspectRatio ); | 92 | size.scale( 1.5 * d->baseCardSize.width(), d->baseCardSize.height(), Qt::KeepAspectRatio ); | ||
92 | 93 | | |||
93 | qreal yPos = ( d->previewSize.height() - size.height() ) / 2; | 94 | qreal yPos = ( d->previewSize.height() - size.height() ) / 2; | ||
94 | qreal spacingWidth = d->baseCardSize.width() | 95 | qreal spacingWidth = d->baseCardSize.width() | ||
95 | * ( d->previewSize.width() - d->previewLayout.size() * size.width() ) | 96 | * ( d->previewSize.width() - d->previewLayout.size() * size.width() ) | ||
96 | / ( d->previewSize.width() - d->previewLayout.size() * d->baseCardSize.width() ); | 97 | / ( d->previewSize.width() - d->previewLayout.size() * d->baseCardSize.width() ); | ||
97 | 98 | | |||
98 | qreal xPos = 0; | 99 | qreal xPos = 0; | ||
99 | foreach ( const QList<QString> & pile, d->previewLayout ) | 100 | foreach ( const QList<QString> & pile, d->previewLayout ) | ||
100 | { | 101 | { | ||
101 | foreach ( const QString & card, pile ) | 102 | foreach ( const QString & card, pile ) | ||
102 | { | 103 | { | ||
103 | renderer.render( &p, card, QRectF( QPointF( xPos, yPos ), size ) ); | 104 | renderer.render( &p, card, QRectF( QPointF( xPos, yPos ) * dpr, size * dpr ) ); | ||
Any patch that has code to render bigger is normally a bad sign. We should only be resizing the backing stores and having the DPR set on that backing store. The rest will implicitly "just work". davidedmundson: Any patch that has code to render bigger is normally a bad sign.
We should only be resizing… | |||||
104 | xPos += 0.3 * spacingWidth; | 105 | xPos += 0.3 * spacingWidth; | ||
105 | } | 106 | } | ||
106 | xPos += 1 * size.width() + ( 0.1 - 0.3 ) * spacingWidth; | 107 | xPos += 1 * size.width() + ( 0.1 - 0.3 ) * spacingWidth; | ||
107 | } | 108 | } | ||
108 | 109 | | |||
109 | emit previewRendered( theme, img ); | 110 | emit previewRendered( theme, img ); | ||
110 | } | 111 | } | ||
111 | } | 112 | } | ||
Show All 30 Lines | 141 | { | |||
142 | 143 | | |||
143 | beginResetModel(); | 144 | beginResetModel(); | ||
144 | 145 | | |||
145 | m_themes.clear(); | 146 | m_themes.clear(); | ||
146 | qDeleteAll( m_previews ); | 147 | qDeleteAll( m_previews ); | ||
147 | m_previews.clear(); | 148 | m_previews.clear(); | ||
148 | 149 | | |||
149 | QList<KCardTheme> previewsNeeded; | 150 | QList<KCardTheme> previewsNeeded; | ||
151 | const auto dpr = qApp->devicePixelRatio(); | ||||
150 | 152 | | |||
151 | foreach( const KCardTheme & theme, KCardTheme::findAllWithFeatures( d->requiredFeatures ) ) | 153 | foreach( const KCardTheme & theme, KCardTheme::findAllWithFeatures( d->requiredFeatures ) ) | ||
152 | { | 154 | { | ||
153 | if ( !theme.isValid() ) | 155 | if ( !theme.isValid() ) | ||
154 | continue; | 156 | continue; | ||
155 | 157 | | |||
156 | QPixmap * pix = new QPixmap(); | 158 | QPixmap * pix = new QPixmap(); | ||
157 | QDateTime timestamp; | 159 | QDateTime timestamp; | ||
158 | if ( cacheFind( d->cache, timestampKey( theme ), ×tamp ) | 160 | if ( cacheFind( d->cache, timestampKey( theme ), ×tamp ) | ||
159 | && timestamp >= theme.lastModified() | 161 | && timestamp >= theme.lastModified() | ||
160 | && d->cache->findPixmap( previewKey( theme, d->previewString ), pix ) ) | 162 | && d->cache->findPixmap( previewKey( theme, d->previewString ), pix ) | ||
163 | && pix->size() == d->previewSize * dpr ) | ||||
161 | { | 164 | { | ||
165 | pix->setDevicePixelRatio( dpr ); | ||||
162 | m_previews.insert( theme.displayName(), pix ); | 166 | m_previews.insert( theme.displayName(), pix ); | ||
163 | } | 167 | } | ||
164 | else | 168 | else | ||
165 | { | 169 | { | ||
166 | delete pix; | 170 | delete pix; | ||
167 | m_previews.insert( theme.displayName(), 0 ); | 171 | m_previews.insert( theme.displayName(), 0 ); | ||
168 | previewsNeeded << theme; | 172 | previewsNeeded << theme; | ||
169 | } | 173 | } | ||
Show All 24 Lines | |||||
194 | 198 | | |||
195 | 199 | | |||
196 | void CardThemeModel::submitPreview( const KCardTheme & theme, const QImage & image ) | 200 | void CardThemeModel::submitPreview( const KCardTheme & theme, const QImage & image ) | ||
197 | { | 201 | { | ||
198 | d->cache->insertImage( previewKey( theme, d->previewString ), image ); | 202 | d->cache->insertImage( previewKey( theme, d->previewString ), image ); | ||
199 | cacheInsert( d->cache, timestampKey( theme ), theme.lastModified() ); | 203 | cacheInsert( d->cache, timestampKey( theme ), theme.lastModified() ); | ||
200 | 204 | | |||
201 | QPixmap * pix = new QPixmap( QPixmap::fromImage( image ) ); | 205 | QPixmap * pix = new QPixmap( QPixmap::fromImage( image ) ); | ||
206 | pix->setDevicePixelRatio( qApp->devicePixelRatio() ); | ||||
davidedmundson: why?
The image coming in should have a DPR set. | |||||
202 | delete m_previews.value( theme.displayName(), 0 ); | 207 | delete m_previews.value( theme.displayName(), 0 ); | ||
203 | m_previews.insert( theme.displayName(), pix ); | 208 | m_previews.insert( theme.displayName(), pix ); | ||
204 | 209 | | |||
205 | QModelIndex index = indexOf( theme.dirName() ); | 210 | QModelIndex index = indexOf( theme.dirName() ); | ||
206 | emit dataChanged( index, index ); | 211 | emit dataChanged( index, index ); | ||
207 | } | 212 | } | ||
208 | 213 | | |||
209 | 214 | | |||
▲ Show 20 Lines • Show All 241 Lines • Show Last 20 Lines |
this image doesn't have the DPR set