23#include "KPrPicturePreview.h"
29KPrPicturePreview::KPrPicturePreview( TQWidget* parent,
const char* name)
30: TQFrame( parent, name )
31, mirrorType( PM_NORMAL )
37 setFrameStyle( WinPanel | Sunken );
38 setMinimumSize( 300, 200 );
42void KPrPicturePreview::drawContents( TQPainter *painter )
44 TQSize ext = contentsRect().size();
46 TQPixmap _pix = origPixmap;
47 TQImage img( _pix.convertToImage().smoothScale( ext.width(),ext.height(), TQImage::ScaleMin ) );
49 bool _horizontal =
false;
50 bool _vertical =
false;
51 if ( mirrorType == PM_HORIZONTAL )
53 else if ( mirrorType == PM_VERTICAL )
55 else if ( mirrorType == PM_HORIZONTALANDVERTICAL ) {
60 img = img.mirror( _horizontal, _vertical );
63 TQImage tmpImg = img.convertDepth( depth );
64 if ( !tmpImg.isNull() )
73 if ( depth == 1 || depth == 8 ) {
74 for (
int i = 0; i < img.numColors(); ++i ) {
75 TQRgb rgb = img.color( i );
76 int gray = tqGray( rgb );
77 rgb = tqRgb( gray, gray, gray );
78 img.setColor( i, rgb );
82 int _width = img.width();
83 int _height = img.height();
87 for ( _x = 0; _x < _width; ++_x ) {
88 for ( _y = 0; _y < _height; ++_y ) {
89 if ( img.valid( _x, _y ) ) {
90 TQRgb rgb = img.pixel( _x, _y );
91 int gray = tqGray( rgb );
92 rgb = tqRgb( gray, gray, gray );
93 img.setPixel( _x, _y, rgb );
102 if ( depth == 1 || depth == 8 ) {
103 for (
int i = 0; i < img.numColors(); ++i ) {
104 TQRgb rgb = img.color( i );
108 rgb = c.light( 100 + bright ).rgb();
110 rgb = c.dark( 100 + abs( bright ) ).rgb();
112 img.setColor( i, rgb );
116 int _width = img.width();
117 int _height = img.height();
121 for ( _x = 0; _x < _width; ++_x ) {
122 for ( _y = 0; _y < _height; ++_y ) {
123 if ( img.valid( _x, _y ) ) {
124 TQRgb rgb = img.pixel( _x, _y );
128 rgb = c.light( 100 + bright ).rgb();
130 rgb = c.dark( 100 + abs( bright ) ).rgb();
132 img.setPixel( _x, _y, rgb );
139 _pix.convertFromImage( img );
141 TQPixmap tmpPix( _pix.size() );
142 tmpPix.fill( TQt::white );
146 _p.drawPixmap( 0, 0, _pix );
149 TQSize _pixSize = _pix.size();
151 int w = _pixSize.width(), h = _pixSize.height();
152 _x = ( ext.width() - w ) / 2;
153 _y = ( ext.height() - h ) / 2;
155 painter->drawPixmap( _x, _y, tmpPix );
159void KPrPicturePreview::slotNormalPicture()
161 if ( mirrorType != PM_NORMAL )
163 mirrorType = PM_NORMAL;
169void KPrPicturePreview::slotHorizontalMirrorPicture()
171 if ( mirrorType != PM_HORIZONTAL )
173 mirrorType = PM_HORIZONTAL;
179void KPrPicturePreview::slotVerticalMirrorPicture()
181 if ( mirrorType != PM_VERTICAL )
183 mirrorType = PM_VERTICAL;
189void KPrPicturePreview::slotHorizontalAndVerticalMirrorPicture()
191 if ( mirrorType != PM_HORIZONTALANDVERTICAL )
193 mirrorType = PM_HORIZONTALANDVERTICAL;
199void KPrPicturePreview::slotPictureDepth0()
209void KPrPicturePreview::slotPictureDepth1()
219void KPrPicturePreview::slotPictureDepth8()
229void KPrPicturePreview::slotPictureDepth16()
239void KPrPicturePreview::slotPictureDepth32()
249void KPrPicturePreview::slotSwapRGBPicture(
bool _on )
251 if ( swapRGB != _on )
259void KPrPicturePreview::slotGrayscalPicture(
bool _on )
261 if ( grayscal != _on )
269void KPrPicturePreview::slotBrightValue(
int _value )
271 if ( bright != _value )
279void KPrPicturePreview::setDepth(
int _depth)
281 if ( _depth != depth )
289void KPrPicturePreview::setMirrorType (PictureMirrorType _t)
291 if ( mirrorType != _t )
299void KPrPicturePreview::setPicturePixmap(
const TQPixmap &_pixmap)
301 origPixmap = _pixmap;
306#include "KPrPicturePreview.moc"