dpr_icon.cpp 884 B

1234567891011121314151617181920212223242526272829303132
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #include "ui/dpr/dpr_icon.h"
  8. namespace dpr {
  9. QImage IconFrame(
  10. const style::icon &icon,
  11. const QColor &color,
  12. double ratio) {
  13. const auto scale = style::Scale() * ratio;
  14. const auto use = (scale > 200. || style::DevicePixelRatio() > 2)
  15. ? (300 / style::DevicePixelRatio())
  16. : (scale > 100.)
  17. ? (200 / style::DevicePixelRatio())
  18. : (100 / style::DevicePixelRatio());
  19. auto image = icon.instance(color, use);
  20. image.setDevicePixelRatio(1.);
  21. const auto desired = icon.size() * ratio;
  22. return (image.size() == desired)
  23. ? image
  24. : image.scaled(
  25. desired,
  26. Qt::IgnoreAspectRatio,
  27. Qt::SmoothTransformation);
  28. }
  29. } // namespace dpr