39 const int width =
static_cast<int>(
Qgis::UI_SCALE_FACTOR * widget->fontMetrics().horizontalAdvance(
'X' ) * 23 );
40 const int height =
static_cast<int>( width / 1.61803398875 );
42 const int margin =
static_cast<int>( height * 0.1 );
43 QImage icon = QImage( width + 2 * margin, height + 2 * margin, QImage::Format_ARGB32 );
44 icon.fill( Qt::transparent );
50 const QBrush checkBrush = QBrush( widget->transparentBackground() );
51 p.setPen( Qt::NoPen );
52 p.setBrush( checkBrush );
53 p.drawRect( margin, margin, width, height );
56 p.setBrush( QBrush( color ) );
57 p.drawRect( margin, margin, width, height );
59 if ( color.alpha() < 255 )
62 color.setAlpha( 255 );
63 p.setBrush( QBrush( color ) );
64 p.drawRect( margin, margin, width / 2, height );
68 p.setPen( QColor( 197, 197, 197 ) );
69 p.setBrush( Qt::NoBrush );
70 p.drawRect( margin, margin, width, height );
74 QBuffer buffer( &data );
75 icon.save( &buffer,
"PNG", 100 );
77 QString info = u
"<b>HEX</b> %1<br>"_s.arg( color.name() );
79 if ( color.spec() == QColor::Spec::Cmyk )
81 const double cyan = color.cyanF() * 100.;
82 const double magenta = color.magentaF() * 100.;
83 const double yellow = color.yellowF() * 100.;
84 const double black = color.blackF() * 100.;
85 const double alpha = color.alphaF() * 100.;
87 info += u
"<b>CMYKA</b> %1,%2,%3,%4,%5<p>"_s.arg( cyan, 0,
'f', 2 ).arg( magenta, 0,
'f', 2 ).arg( yellow, 0,
'f', 2 ).arg( black, 0,
'f', 2 ).arg( alpha, 0,
'f', 2 );
91 const int hue = color.hue();
92 const int value = color.value();
93 const int saturation = color.saturation();
95 info += QStringLiteral(
97 "<b>HSV</b> %2,%3,%4<p>"
105 info += u
"<img src='data:image/png;base64, %1'>"_s.arg( QString( data.toBase64() ) );