/*************************************************************************** * Copyright (C) 2004 by Johan Maes - ON4QZ * * on4qz@telenet.be * * http://users.telenet.be/on4qz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "imageview.h" #include #include #define FW 5 #define FH 5 imageView::imageView(QWidget *parent, const char *name): QScrollView(parent, name) { setMinimumSize( QSize( 320+FW, 256+FH )); // debug("imageview resize"); // pixmap.resize(320,256); // image.create(320,256,32); // pixmap.resize(2,2); image.create(2,2,32); hasContent=FALSE; image.fill(QColor(Qt::darkGray).rgb()); // pixmap.fill(QColor(Qt::darkGray)); viewport()->setBackgroundMode( PaletteBase ); setResizePolicy(QScrollView::Manual); } imageView::~imageView() { } /* void imageView::setPixmap( const QPixmap &pix ) { hasContent=TRUE; pixmap = pix; setNewSize( pixmap.size().width(), pixmap.size().height() ); }*/ void imageView::setNewSize(int w, int h) { QPixmap pm; debug("setNewSize= %dx%d",w,h); // if((w+FW)>MAXWIDTH) wi=MAXSIZE-FW; // if((w+FW)>MAXWIDTH) wi=MAXSIZE-FW; // setFixedSize( QSize( w+FW, h+FH )); setMinimumSize( QSize( 320+FW, 256+FH )); setMaximumSize( QSize( w+FW, h+FH)); pm.resize(w,h); image.create(w,h,32); QPainter p(&pm); p.drawTiledPixmap(QRect(0,0,w,h),QPixmap::fromMimeSource("transparency.png")); image=pm; /* if(!hasContent) { QPainter p(this); p.drawTiledPixmap(QRect(0,0,w,h),QPixmap::fromMimeSource("transparency.xpm")); }*/ resizeContents( w,h) ; viewport()->repaint( FALSE ); emit newSize(w,h); } void imageView::drawContents( QPainter *p, int x, int y, int w, int h) { // if(hasContent) { p->drawImage(x,y,image,x,y,w,h); } } void imageView::drawFullContents() { viewport()->repaint( FALSE ); } void imageView::showLine() { // QPainter p(&pixmap); // p.drawImage(0,line,image,0,line,image.width(),1); viewport()->repaint( FALSE ); } unsigned int *imageView::getLineAddress(uint lineCounter) { return (unsigned int *)image.scanLine(lineCounter); } /* void imageView::showLine(int line,int nbrlines) { QPainter p(&pixmap); p.drawImage(0,line,image,0,line,image.width(),nbrlines); viewport()->repaint( FALSE ); }*/ void imageView::clearToBottom(QColor color) { /* QPainter paint; if(!pixmap.isNull()) { paint.begin(&pixmap); { QRect r(0,startLine,pixmap.width(),pixmap.height()); #ifdef DEBUGPIXMAPVIEW debug(" pxm %d, %d",pixmap.width(),pixmap.height()); #endif paint.fillRect(r,color); } paint.end(); viewport()->repaint(FALSE); } */ image.fill(color.rgb()); } void imageView::clearBackground() { viewport()->setBackgroundPixmap(QPixmap::fromMimeSource("transparency.png")); if((image.width()!=0)&&(image.height()!=0)) { QPixmap pm(image.width(),image.height()); QPainter p(&pm); p.drawTiledPixmap(QRect(0,0,image.width(),image.height()),QPixmap::fromMimeSource("transparency.png")); image=pm; viewport()->repaint(FALSE); } } void imageView::showImage(QImage *ip) { if(ip==NULL) return; /* if(pixmap.isNull()) { debug("NULL pixmap"); } QPainter p(&pixmap); */ /* if((ip->width()==pixmap.width()) && (ip->height()==pixmap.height())) { image=ip->copy(); } else { image=ip->smoothScale(pixmap.width(),pixmap.height()); } p.drawImage(0,0,image); */ if((ip->width()==image.width()) && (ip->height()==image.height())) { image=ip->copy(); } else { image=ip->smoothScale(image.width(),image.height()); } viewport()->repaint(FALSE); }