LCOV - code coverage report
Current view: top level - src/qt - networkstyle.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 0 38 0.0 %
Date: 2020-09-26 01:30:44 Functions: 0 3 0.0 %

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

Generated by: LCOV version 1.15