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 | |||||
86 | img.setDevicePixelRatio( dpr ); | ||||
85 | img.fill( Qt::transparent ); | 87 | img.fill( Qt::transparent ); | ||
86 | QPainter p( &img ); | 88 | QPainter p( &img ); | ||
87 | 89 | | |||
88 | QSvgRenderer renderer( theme.graphicsFilePath() ); | 90 | QSvgRenderer renderer( theme.graphicsFilePath() ); | ||
89 | 91 | | |||
90 | QSizeF size = renderer.boundsOnElement(QStringLiteral("back")).size(); | 92 | QSizeF size = renderer.boundsOnElement(QStringLiteral("back")).size(); | ||
91 | size.scale( 1.5 * d->baseCardSize.width(), d->baseCardSize.height(), Qt::KeepAspectRatio ); | 93 | size.scale( 1.5 * d->baseCardSize.width(), d->baseCardSize.height(), Qt::KeepAspectRatio ); | ||
92 | 94 | | |||
93 | qreal yPos = ( d->previewSize.height() - size.height() ) / 2; | 95 | qreal yPos = ( d->previewSize.height() - size.height() ) / 2; | ||
94 | qreal spacingWidth = d->baseCardSize.width() | 96 | qreal spacingWidth = d->baseCardSize.width() | ||
95 | * ( d->previewSize.width() - d->previewLayout.size() * size.width() ) | 97 | * ( d->previewSize.width() - d->previewLayout.size() * size.width() ) | ||
96 | / ( d->previewSize.width() - d->previewLayout.size() * d->baseCardSize.width() ); | 98 | / ( d->previewSize.width() - d->previewLayout.size() * d->baseCardSize.width() ); | ||
97 | 99 | | |||
98 | qreal xPos = 0; | 100 | qreal xPos = 0; | ||
99 | foreach ( const QList<QString> & pile, d->previewLayout ) | 101 | foreach ( const QList<QString> & pile, d->previewLayout ) | ||
100 | { | 102 | { | ||
101 | foreach ( const QString & card, pile ) | 103 | foreach ( const QString & card, pile ) | ||
102 | { | 104 | { | ||
103 | renderer.render( &p, card, QRectF( QPointF( xPos, yPos ), size ) ); | 105 | renderer.render( &p, card, QRectF( QPointF( xPos, yPos ), size ) ); | ||
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; | 106 | xPos += 0.3 * spacingWidth; | ||
105 | } | 107 | } | ||
106 | xPos += 1 * size.width() + ( 0.1 - 0.3 ) * spacingWidth; | 108 | xPos += 1 * size.width() + ( 0.1 - 0.3 ) * spacingWidth; | ||
107 | } | 109 | } | ||
108 | 110 | | |||
109 | emit previewRendered( theme, img ); | 111 | emit previewRendered( theme, img ); | ||
110 | } | 112 | } | ||
111 | } | 113 | } | ||
Show All 30 Lines | 142 | { | |||
142 | 144 | | |||
143 | beginResetModel(); | 145 | beginResetModel(); | ||
144 | 146 | | |||
145 | m_themes.clear(); | 147 | m_themes.clear(); | ||
146 | qDeleteAll( m_previews ); | 148 | qDeleteAll( m_previews ); | ||
147 | m_previews.clear(); | 149 | m_previews.clear(); | ||
148 | 150 | | |||
149 | QList<KCardTheme> previewsNeeded; | 151 | QList<KCardTheme> previewsNeeded; | ||
152 | const auto dpr = qApp->devicePixelRatio(); | ||||
150 | 153 | | |||
151 | foreach( const KCardTheme & theme, KCardTheme::findAllWithFeatures( d->requiredFeatures ) ) | 154 | foreach( const KCardTheme & theme, KCardTheme::findAllWithFeatures( d->requiredFeatures ) ) | ||
152 | { | 155 | { | ||
153 | if ( !theme.isValid() ) | 156 | if ( !theme.isValid() ) | ||
154 | continue; | 157 | continue; | ||
155 | 158 | | |||
156 | QPixmap * pix = new QPixmap(); | 159 | QPixmap * pix = new QPixmap(); | ||
157 | QDateTime timestamp; | 160 | QDateTime timestamp; | ||
158 | if ( cacheFind( d->cache, timestampKey( theme ), ×tamp ) | 161 | if ( cacheFind( d->cache, timestampKey( theme ), ×tamp ) | ||
159 | && timestamp >= theme.lastModified() | 162 | && timestamp >= theme.lastModified() | ||
160 | && d->cache->findPixmap( previewKey( theme, d->previewString ), pix ) ) | 163 | && d->cache->findPixmap( previewKey( theme, d->previewString ), pix ) | ||
164 | && pix->size() == d->previewSize * dpr ) | ||||
161 | { | 165 | { | ||
166 | pix->setDevicePixelRatio( dpr ); | ||||
162 | m_previews.insert( theme.displayName(), pix ); | 167 | m_previews.insert( theme.displayName(), pix ); | ||
163 | } | 168 | } | ||
164 | else | 169 | else | ||
165 | { | 170 | { | ||
166 | delete pix; | 171 | delete pix; | ||
167 | m_previews.insert( theme.displayName(), 0 ); | 172 | m_previews.insert( theme.displayName(), 0 ); | ||
168 | previewsNeeded << theme; | 173 | previewsNeeded << theme; | ||
169 | } | 174 | } | ||
Show All 24 Lines | |||||
194 | 199 | | |||
195 | 200 | | |||
196 | void CardThemeModel::submitPreview( const KCardTheme & theme, const QImage & image ) | 201 | void CardThemeModel::submitPreview( const KCardTheme & theme, const QImage & image ) | ||
197 | { | 202 | { | ||
198 | d->cache->insertImage( previewKey( theme, d->previewString ), image ); | 203 | d->cache->insertImage( previewKey( theme, d->previewString ), image ); | ||
199 | cacheInsert( d->cache, timestampKey( theme ), theme.lastModified() ); | 204 | cacheInsert( d->cache, timestampKey( theme ), theme.lastModified() ); | ||
200 | 205 | | |||
201 | QPixmap * pix = new QPixmap( QPixmap::fromImage( image ) ); | 206 | QPixmap * pix = new QPixmap( QPixmap::fromImage( image ) ); | ||
202 | delete m_previews.value( theme.displayName(), 0 ); | 207 | delete m_previews.value( theme.displayName(), 0 ); | ||
davidedmundson: why?
The image coming in should have a DPR set. | |||||
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 | | |||
210 | int CardThemeModel::rowCount( const QModelIndex & parent ) const | 215 | int CardThemeModel::rowCount( const QModelIndex & parent ) const | ||
▲ Show 20 Lines • Show All 240 Lines • Show Last 20 Lines |
this image doesn't have the DPR set