40 const int width =
static_cast<int>(
Qgis::UI_SCALE_FACTOR * widget->fontMetrics().horizontalAdvance(
'X' ) * 23 );
41 const int height =
static_cast<int>( width / 1.61803398875 );
43 const int margin =
static_cast<int>( height * 0.1 );
44 QImage icon = QImage( width + 2 * margin, height + 2 * margin, QImage::Format_ARGB32 );
45 icon.fill( Qt::transparent );
51 const QBrush checkBrush = QBrush( widget->transparentBackground() );
52 p.setPen( Qt::NoPen );
53 p.setBrush( checkBrush );
54 p.drawRect( margin, margin, width, height );
57 p.setBrush( QBrush( color ) );
58 p.drawRect( margin, margin, width, height );
60 if ( color.alpha() < 255 )
63 color.setAlpha( 255 );
64 p.setBrush( QBrush( color ) );
65 p.drawRect( margin, margin, width / 2, height );
69 p.setPen( QColor( 197, 197, 197 ) );
70 p.setBrush( Qt::NoBrush );
71 p.drawRect( margin, margin, width, height );
75 QBuffer buffer( &data );
76 icon.save( &buffer,
"PNG", 100 );
78 QString info = u
"<b>HEX</b> %1<br>"_s.arg( color.name() );
80 if ( color.spec() == QColor::Spec::Cmyk )
82 const double cyan = color.cyanF() * 100.;
83 const double magenta = color.magentaF() * 100.;
84 const double yellow = color.yellowF() * 100.;
85 const double black = color.blackF() * 100.;
86 const double alpha = color.alphaF() * 100.;
88 info += u
"<b>CMYKA</b> %1,%2,%3,%4,%5<p>"_s
89 .arg( cyan, 0,
'f', 2 )
90 .arg( magenta, 0,
'f', 2 )
91 .arg( yellow, 0,
'f', 2 )
92 .arg( black, 0,
'f', 2 )
93 .arg( alpha, 0,
'f', 2 );
97 const int hue = color.hue();
98 const int value = color.value();
99 const int saturation = color.saturation();
101 info += QStringLiteral(
"<b>RGBA</b> %1<br>"
102 "<b>HSV</b> %2,%3,%4<p>" )
109 info += u
"<img src='data:image/png;base64, %1'>"_s.arg( QString( data.toBase64() ) );