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