00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "imagelabel.h"
00011 #include <qtimer.h>
00012 #include <qtooltip.h>
00013
00014 ImageLabel::ImageLabel(int ix,int iy,int iw,int ih)
00015 : Meter(ix,iy,iw,ih), zoomed(false), rollover(false)
00016 {
00017
00018 }
00019
00020 ImageLabel::ImageLabel() : Meter(), zoomed(false), rollover(false){
00021
00022
00023 }
00024 ImageLabel::~ImageLabel(){
00025
00026
00027 }
00028
00029 void ImageLabel::setValue(int v){
00030 setValue( QString::number( v ) );
00031 }
00032
00033 void ImageLabel::setValue(QString fn)
00034 {
00035
00036 QStringList sList = QStringList::split( "\n", fn );
00037 QString fileName = *sList.begin();
00038 QFileInfo fileInfo( fileName );
00039 QString path;
00040
00041 QRegExp rx("^http://",false);
00042 bool fileOnNet = (rx.search(fileName)!=-1)?true:false;
00043
00044
00045 if( fileInfo.isRelative() && !fileOnNet )
00046 {
00047 path = themePath + "/" + fileName;
00048 }
00049 else
00050 {
00051 path = fileName;
00052 }
00053
00054 if ( fileOnNet )
00055 {
00056 QString tmpFile;
00057 if(KIO::NetAccess::download(KURL(path), tmpFile, NULL))
00058 {
00059 pixmap = QPixmap(tmpFile);
00060 KIO::NetAccess::removeTempFile(tmpFile);
00061 kdDebug("ImageLabel") << "Downloaded: " << path << " to " << tmpFile << endl;
00062 }
00063 else
00064 {
00065 kdDebug("ImageLabel") << "Error Downloading: " << path << endl;
00066 }
00067 }
00068 else
00069 {
00070 pixmap = QPixmap( path );
00071 }
00072 kdDebug("ImageLabel") << "Pixmap " << pixmap.width() << "x" << pixmap.height() << endl;
00073 if((pixmap.width() > width || pixmap.height() > height) && center == true){
00074 QImage img = pixmap.convertToImage();
00075 QImage tmpImg = img.scale(height, width, QImage::ScaleMin);
00076 pixmap = QPixmap();
00077 pixmap.convertFromImage(tmpImg);
00078 kdDebug("ImageLabel") << "Pixmap now " << pixmap.width() << "x" << pixmap.height() << endl;
00079 }
00080
00081 pixmapWidth = pixmap.width();
00082 pixmapHeight = pixmap.height();
00083
00084 rect_off = QRect(x,y,pixmapWidth,pixmapHeight);
00085 }
00086
00087 void ImageLabel::setCenter(bool c, int w, int h){
00088 if(h == 0 || w == 0){
00089 width = QApplication::desktop()->width();
00090 height = QApplication::desktop()->height();
00091 }
00092 else{
00093 width = w + 2*x;
00094 height = h + 2*y;
00095 }
00096 center = c;
00097 }
00098
00099 void ImageLabel::mUpdate(QPainter* p)
00100 {
00101 if(center == true){
00102 x = width/2 - pixmap.width()/2;
00103 y = height/2 - pixmap.height()/2;
00104 }
00105 if( ( (myKaramba->x() + myKaramba->themeW) >= 0) && ( (myKaramba->x() + x) <= QApplication::desktop()->width()) && ( (myKaramba->y() + myKaramba->themeH) >= 0) && ( (myKaramba->y() + y) <= QApplication::desktop()->height()) ){
00106 p->drawPixmap(x,y,pixmap);
00107 }
00108 }
00109
00110 void ImageLabel::parseImages(QString fn, QString fn_roll, int _xoff, int _yoff, int _xon, int _yon)
00111 {
00112
00113
00114
00115 xoff = _xoff;
00116 yoff = _yoff;
00117 xon = _xon;
00118 yon = _yon;
00119
00120
00121 QStringList sList = QStringList::split( "\n", fn );
00122 QString fileName = *sList.begin();
00123 QFileInfo fileInfo( fileName );
00124 QString path;
00125
00126 QRegExp rx("^http://",false);
00127 bool fileOnNet = (rx.search(fileName)!=-1)?true:false;
00128
00129
00130 if( fileInfo.isRelative() && !fileOnNet )
00131 {
00132 path = themePath + "/" + fileName;
00133 }
00134 else
00135 {
00136 path = fileName;
00137 }
00138
00139 if ( fileOnNet )
00140 {
00141 QString tmpFile;
00142 if(KIO::NetAccess::download(KURL(path), tmpFile, NULL))
00143 {
00144 pixmap_off = QPixmap(tmpFile);
00145 KIO::NetAccess::removeTempFile(tmpFile);
00146 kdDebug("ImageLabel") << "Downloaded: " << path << " to " << tmpFile << endl;
00147 }
00148 else
00149 {
00150 kdDebug("ImageLabel") << "Error Downloading: " << path << endl;
00151 }
00152 }
00153 else
00154 {
00155 pixmap_off = QPixmap( path );
00156 }
00157
00158 pixmapOffWidth = pixmap.width();
00159 pixmapOffHeight = pixmap.height();
00160
00161 rect_off = QRect(xoff,yoff,pixmapWidth,pixmapHeight);
00163 if (fn_roll.isEmpty())
00164 return;
00165
00166 rollover=true;
00167 sList = QStringList::split( "\n", fn_roll );
00168 fileName = *sList.begin();
00169 fileInfo = QFileInfo( fileName );
00170
00171 fileOnNet = (rx.search(fileName)!=-1)?true:false;
00172
00173
00174 if( fileInfo.isRelative() && !fileOnNet )
00175 {
00176 path = themePath + "/" + fileName;
00177 }
00178 else
00179 {
00180 path = fileName;
00181 }
00182
00183 if ( fileOnNet )
00184 {
00185 QString tmpFile;
00186 if(KIO::NetAccess::download(KURL(path), tmpFile, NULL))
00187 {
00188 pixmap_on = QPixmap(tmpFile);
00189 KIO::NetAccess::removeTempFile(tmpFile);
00190 kdDebug("ImageLabel") << "Downloaded: " << path << " to " << tmpFile << endl;
00191 }
00192 else
00193 {
00194 kdDebug("ImageLabel") << "Error Downloading: " << path << endl;
00195 }
00196 }
00197 else
00198 {
00199 pixmap_on = QPixmap( path );
00200 }
00201
00202 pixmapOnWidth = pixmap_on.width();
00203 pixmapOnHeight = pixmap_on.height();
00204
00205 rect_on = QRect(xon,yon,pixmapOnWidth,pixmapOnHeight);
00206 }
00207
00208 void ImageLabel::setKaramba(karamba* k)
00209 {
00210 myKaramba = k;
00211 }
00212
00213 void ImageLabel::rolloverImage(QMouseEvent *e)
00214 {
00215 if (!rollover)
00216 return;
00217
00218 if (zoomed)
00219 {
00220 if (!rect_off.contains(e->pos()))
00221 {
00222
00223
00224 x = xoff;
00225 y = yoff;
00226 pixmap = pixmap_off;
00227 pixmapWidth = pixmapOffWidth;
00228 pixmapHeight = pixmapOffHeight;
00229 zoomed = false;
00230 myKaramba->step();
00231 }
00232 }
00233 else
00234 {
00235 if (rect_off.contains(e->pos()))
00236 {
00237
00238
00239 x = xon;
00240 y = yon;
00241 pixmap = pixmap_on;
00242 pixmapWidth = pixmapOnWidth;
00243 pixmapHeight = pixmapOnHeight;
00244 zoomed = true;
00245 myKaramba->step();
00246 }
00247 }
00248 }
00249
00250 void ImageLabel::setTooltip(QString txt)
00251 {
00252 QRect rect(x,y,pixmapWidth,pixmapHeight);
00253 QToolTip::add(myKaramba, rect, txt);
00254 }