MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / run

Method run

launcher/ui/pages/instance/ScreenshotsPage.cpp:91–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89 m_cache = cache;
90 }
91 void run()
92 {
93 QFileInfo info(m_path);
94 if (info.isDir())
95 return;
96 if ((info.suffix().compare("png", Qt::CaseInsensitive) != 0))
97 return;
98 int tries = 5;
99 while (tries)
100 {
101 if (!m_cache->stale(m_path))
102 return;
103 QImage image(m_path);
104 if (image.isNull())
105 {
106 QThread::msleep(500);
107 tries--;
108 continue;
109 }
110 QImage small;
111 if (image.width() > image.height())
112 small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation);
113 else
114 small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation);
115 QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2);
116 QImage square(QSize(256, 256), QImage::Format_ARGB32);
117 square.fill(Qt::transparent);
118
119 QPainter painter(&square);
120 painter.drawImage(offset, small);
121 painter.end();
122
123 QIcon icon(QPixmap::fromImage(square));
124 m_cache->add(m_path, icon);
125 m_resultEmitter.emitResultsReady(m_path);
126 return;
127 }
128 m_resultEmitter.emitResultsFailed(m_path);
129 }
130 QString m_path;
131 SharedIconCachePtr m_cache;
132 ThumbnailingResult m_resultEmitter;

Callers 2

Calls 6

staleMethod · 0.80
fillMethod · 0.80
endMethod · 0.80
emitResultsFailedMethod · 0.80
compareMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected