20#include "moc_qgsprevieweffect.cpp"
24 : QGraphicsEffect( parent )
25 , mMode( PreviewGrayscale )
42 if ( sourceIsPixmap() )
45 pixmap = sourcePixmap( Qt::LogicalCoordinates, &offset );
50 pixmap = sourcePixmap( Qt::DeviceCoordinates, &offset );
51 painter->setWorldTransform( QTransform() );
54 QImage image = pixmap.toImage();
60 const QImage bwImage = image.convertToFormat( QImage::Format_Mono );
61 painter->drawImage( offset, bwImage );
71 for (
int y = 0; y < image.height(); y++ )
73 line = ( QRgb * )image.scanLine( y );
74 for (
int x = 0; x < image.width(); x++ )
76 line[x] = simulateColorBlindness( line[x], mMode );
80 painter->drawImage( offset, image );
89 int red = qRed( originalColor );
90 int green = qGreen( originalColor );
91 int blue = qBlue( originalColor );
103 simulateGrayscale( r, g, b, red, green, blue );
106 simulateProtanope( r, g, b, red, green, blue );
109 simulateDeuteranope( r, g, b, red, green, blue );
112 simulateTritanope( r, g, b, red, green, blue );
119 r = std::max( std::min( 255, r ), 0 );
120 g = std::max( std::min( 255, g ), 0 );
121 b = std::max( std::min( 255, b ), 0 );
123 return qRgb( r, g, b );
126void QgsPreviewEffect::simulateGrayscale(
int &r,
int &g,
int &b,
int &red,
int &green,
int &blue )
128 r = ( 0.2126 * red ) + ( 0.7152 * green ) + ( 0.0722 * blue );
133void QgsPreviewEffect::simulateProtanope(
int &r,
int &g,
int &b,
int &red,
int &green,
int &blue )
135 r = ( 0.152286 * red ) + ( 1.052583 * green ) + ( -0.204868 * blue );
136 g = ( 0.114503 * red ) + ( 0.786281 * green ) + ( 0.099216 * blue );
137 b = ( -0.003882 * red ) + ( -0.048116 * green ) + ( 1.051998 * blue );
140void QgsPreviewEffect::simulateDeuteranope(
int &r,
int &g,
int &b,
int &red,
int &green,
int &blue )
142 r = ( 0.367322 * red ) + ( 0.860646 * green ) + ( -0.227968 * blue );
143 g = ( 0.280085 * red ) + ( 0.672501 * green ) + ( 0.047413 * blue );
144 b = ( -0.011820 * red ) + ( 0.042940 * green ) + ( 0.968881 * blue );
147void QgsPreviewEffect::simulateTritanope(
int &r,
int &g,
int &b,
int &red,
int &green,
int &blue )
149 r = ( 1.255528 * red ) + ( -0.076749 * green ) + ( -0.178779 * blue );
150 g = ( -0.078411 * red ) + ( 0.930809 * green ) + ( 0.147602 * blue );
151 b = ( 0.004733 * red ) + ( 0.691367 * green ) + ( 0.303900 * blue );
void draw(QPainter *painter) override
void setMode(PreviewMode mode)
Sets the mode for the preview effect, which controls how the effect modifies a widgets appearance.
PreviewMode mode() const
Returns the mode used for the preview effect.
QgsPreviewEffect(QObject *parent)