| 214 | } |
| 215 | |
| 216 | void ListModel::logoLoaded(QString logo, bool stale) |
| 217 | { |
| 218 | auto & logoObj = m_logoMap[logo]; |
| 219 | logoObj.downloadJob.reset(); |
| 220 | QString smallPath = logoObj.fullpath + ".small"; |
| 221 | |
| 222 | QFileInfo smallInfo(smallPath); |
| 223 | |
| 224 | if(stale || !smallInfo.exists()) { |
| 225 | QImage image(logoObj.fullpath); |
| 226 | if (image.isNull()) |
| 227 | { |
| 228 | logoObj.failed = true; |
| 229 | return; |
| 230 | } |
| 231 | QImage small; |
| 232 | if (image.width() > image.height()) { |
| 233 | small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation); |
| 234 | } |
| 235 | else { |
| 236 | small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation); |
| 237 | } |
| 238 | QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2); |
| 239 | QImage square(QSize(256, 256), QImage::Format_ARGB32); |
| 240 | square.fill(Qt::transparent); |
| 241 | |
| 242 | QPainter painter(&square); |
| 243 | painter.drawImage(offset, small); |
| 244 | painter.end(); |
| 245 | |
| 246 | square.save(logoObj.fullpath + ".small", "PNG"); |
| 247 | } |
| 248 | |
| 249 | logoObj.result = QIcon(logoObj.fullpath + ".small"); |
| 250 | for(int i = 0; i < modpacks.size(); i++) { |
| 251 | if(modpacks[i].name == logo) { |
| 252 | emit dataChanged(createIndex(i, 0), createIndex(i, 0), {Qt::DecorationRole}); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | void ListModel::logoFailed(QString logo) |
| 258 | { |