| 1310 | } |
| 1311 | |
| 1312 | void setUpFallbackIconPaths(QWidget* parent) { |
| 1313 | /** |
| 1314 | * Qt 5.12 adds a feature to add fallback paths for icons. This is a very simple way to automatically load custom |
| 1315 | * icons when the icon theme doesn't provide a suitable alternative. |
| 1316 | * However, we need to support a much older Qt version. Therefore we cannot use this very very handy feature. |
| 1317 | * We basically iterate over all buttons which carry an icon and (re)load it, but this time provide a fallback |
| 1318 | * loaded from our private data directory. |
| 1319 | */ |
| 1320 | |
| 1321 | // for now we only support buttons |
| 1322 | // we could always add more widgets which provide an icon property |
| 1323 | const auto buttons = parent->findChildren<QAbstractButton*>(); |
| 1324 | |
| 1325 | for (const auto& button : buttons) { |
| 1326 | const auto iconName = button->icon().name(); |
| 1327 | |
| 1328 | // sort out buttons without an icon |
| 1329 | if (iconName.length() <= 0) |
| 1330 | continue; |
| 1331 | |
| 1332 | // load icon from theme, providing the bundled icon as a fallback |
| 1333 | // loading an "empty" (i.e., isNull() returns true) icon as fallback, as returned by loadIconWithFallback(...), |
| 1334 | // works just fine |
| 1335 | auto fallbackIcon = loadIconWithFallback(iconName); |
| 1336 | auto newIcon = QIcon::fromTheme(iconName, fallbackIcon); |
| 1337 | |
| 1338 | if (newIcon.isNull() || newIcon.pixmap(16, 16).isNull()) |
| 1339 | newIcon = fallbackIcon; |
| 1340 | |
| 1341 | // now replace the button's actual icon with the fallback-enabled one |
| 1342 | button->setIcon(newIcon); |
| 1343 | } |
| 1344 | } |
no test coverage detected