You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

networkstyle.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright (c) 2014-2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #include "networkstyle.h"
  5. #include "guiconstants.h"
  6. #include <QApplication>
  7. static const struct {
  8. const char *networkId;
  9. const char *appName;
  10. const int iconColorHueShift;
  11. const int iconColorSaturationReduction;
  12. const char *titleAddText;
  13. } network_styles[] = {
  14. {"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
  15. {"test", QAPP_APP_NAME_AI, 70, 30, QT_TRANSLATE_NOOP("SplashScreen", "[ai]")},
  16. {"regtest", QAPP_APP_NAME_AI, 160, 30, "[regtest]"}
  17. };
  18. static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
  19. // titleAddText needs to be const char* for tr()
  20. NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *_titleAddText):
  21. appName(_appName),
  22. titleAddText(qApp->translate("SplashScreen", _titleAddText))
  23. {
  24. // load pixmap
  25. QPixmap pixmap(":/icons/starwels");
  26. if(iconColorHueShift != 0 && iconColorSaturationReduction != 0)
  27. {
  28. // generate QImage from QPixmap
  29. QImage img = pixmap.toImage();
  30. int h,s,l,a;
  31. // traverse though lines
  32. for(int y=0;y<img.height();y++)
  33. {
  34. QRgb *scL = reinterpret_cast< QRgb *>( img.scanLine( y ) );
  35. // loop through pixels
  36. for(int x=0;x<img.width();x++)
  37. {
  38. // preserve alpha because QColor::getHsl doesen't return the alpha value
  39. a = qAlpha(scL[x]);
  40. QColor col(scL[x]);
  41. // get hue value
  42. col.getHsl(&h,&s,&l);
  43. // rotate color on RGB color circle
  44. // 70° should end up with the typical "ai" green
  45. h+=iconColorHueShift;
  46. // change saturation value
  47. if(s>iconColorSaturationReduction)
  48. {
  49. s -= iconColorSaturationReduction;
  50. }
  51. col.setHsl(h,s,l,a);
  52. // set the pixel
  53. scL[x] = col.rgba();
  54. }
  55. }
  56. //convert back to QPixmap
  57. #if QT_VERSION >= 0x040700
  58. pixmap.convertFromImage(img);
  59. #else
  60. pixmap = QPixmap::fromImage(img);
  61. #endif
  62. }
  63. appIcon = QIcon(pixmap);
  64. trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256)));
  65. }
  66. const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
  67. {
  68. for (unsigned x=0; x<network_styles_count; ++x)
  69. {
  70. if (networkId == network_styles[x].networkId)
  71. {
  72. return new NetworkStyle(
  73. network_styles[x].appName,
  74. network_styles[x].iconColorHueShift,
  75. network_styles[x].iconColorSaturationReduction,
  76. network_styles[x].titleAddText);
  77. }
  78. }
  79. return 0;
  80. }