38 const int width =
static_cast<int>(
Qgis::UI_SCALE_FACTOR * widget->fontMetrics().horizontalAdvance(
'X' ) * 23 );
39 const int height =
static_cast<int>( width / 1.61803398875 );
41 const int margin =
static_cast<int>( height * 0.1 );
42 QImage icon = QImage( width + 2 * margin, height + 2 * margin, QImage::Format_ARGB32 );
43 icon.fill( Qt::transparent );
49 const QBrush checkBrush = QBrush( widget->transparentBackground() );
50 p.setPen( Qt::NoPen );
51 p.setBrush( checkBrush );
52 p.drawRect( margin, margin, width, height );
55 p.setBrush( QBrush( color ) );
56 p.drawRect( margin, margin, width, height );
58 if ( color.alpha() < 255 )
61 color.setAlpha( 255 );
62 p.setBrush( QBrush( color ) );
63 p.drawRect( margin, margin, width / 2, height );
67 p.setPen( QColor( 197, 197, 197 ) );
68 p.setBrush( Qt::NoBrush );
69 p.drawRect( margin, margin, width, height );
73 QBuffer buffer( &data );
74 icon.save( &buffer,
"PNG", 100 );
76 QString info = QStringLiteral(
"<b>HEX</b> %1<br>" ).arg( color.name() );
78 if ( color.spec() == QColor::Spec::Cmyk )
80 const double cyan = color.cyanF() * 100.;
81 const double magenta = color.magentaF() * 100.;
82 const double yellow = color.yellowF() * 100.;
83 const double black = color.blackF() * 100.;
84 const double alpha = color.alphaF() * 100.;
86 info += QStringLiteral(
"<b>CMYKA</b> %1,%2,%3,%4,%5<p>" )
87 .arg( cyan, 0,
'f', 2 )
88 .arg( magenta, 0,
'f', 2 )
89 .arg( yellow, 0,
'f', 2 )
90 .arg( black, 0,
'f', 2 )
91 .arg( alpha, 0,
'f', 2 );
95 const int hue = color.hue();
96 const int value = color.value();
97 const int saturation = color.saturation();
99 info += QStringLiteral(
"<b>RGBA</b> %1<br>"
100 "<b>HSV</b> %2,%3,%4<p>" )
107 info += QStringLiteral(
"<img src='data:image/png;base64, %1'>" ).arg( QString( data.toBase64() ) );