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))
00058 {
00059 pixmap = QPixmap(tmpFile);
00060 KIO::NetAccess::removeTempFile(tmpFile);
00061 qDebug( "Downloaded: " + path + " to " + tmpFile );
00062 }
00063 else
00064 {
00065 qDebug( "Error Downloading: " + path );
00066 }
00067 }
00068 else
00069 {
00070 pixmap = QPixmap( path );
00071 }
00072
00073 pixmapWidth = pixmap.width();
00074 pixmapHeight = pixmap.height();
00075
00076 rect_off = QRect(x,y,pixmapWidth,pixmapHeight);
00077 }
00078
00079 void ImageLabel::mUpdate(QPainter* p)
00080 {
00081 p->drawPixmap(x,y,pixmap);
00082 }
00083
00084 void ImageLabel::parseImages(QString fn, QString fn_roll, int _xoff, int _yoff, int _xon, int _yon)
00085 {
00086
00087
00088
00089 xoff = _xoff;
00090 yoff = _yoff;
00091 xon = _xon;
00092 yon = _yon;
00093
00094
00095 QStringList sList = QStringList::split( "\n", fn );
00096 QString fileName = *sList.begin();
00097 QFileInfo fileInfo( fileName );
00098 QString path;
00099
00100 QRegExp rx("^http://",false);
00101 bool fileOnNet = (rx.search(fileName)!=-1)?true:false;
00102
00103
00104 if( fileInfo.isRelative() && !fileOnNet )
00105 {
00106 path = themePath + "/" + fileName;
00107 }
00108 else
00109 {
00110 path = fileName;
00111 }
00112
00113 if ( fileOnNet )
00114 {
00115 QString tmpFile;
00116 if(KIO::NetAccess::download(KURL(path), tmpFile))
00117 {
00118 pixmap_off = QPixmap(tmpFile);
00119 KIO::NetAccess::removeTempFile(tmpFile);
00120 qDebug( "Downloaded: " + path + " to " + tmpFile );
00121 }
00122 else
00123 {
00124 qDebug( "Error Downloading: " + path );
00125 }
00126 }
00127 else
00128 {
00129 pixmap_off = QPixmap( path );
00130 }
00131
00132 pixmapOffWidth = pixmap.width();
00133 pixmapOffHeight = pixmap.height();
00134
00135 rect_off = QRect(xoff,yoff,pixmapWidth,pixmapHeight);
00137 if (fn_roll.isEmpty())
00138 return;
00139
00140 rollover=true;
00141 sList = QStringList::split( "\n", fn_roll );
00142 fileName = *sList.begin();
00143 fileInfo = QFileInfo( fileName );
00144
00145 fileOnNet = (rx.search(fileName)!=-1)?true:false;
00146
00147
00148 if( fileInfo.isRelative() && !fileOnNet )
00149 {
00150 path = themePath + "/" + fileName;
00151 }
00152 else
00153 {
00154 path = fileName;
00155 }
00156
00157 if ( fileOnNet )
00158 {
00159 QString tmpFile;
00160 if(KIO::NetAccess::download(KURL(path), tmpFile))
00161 {
00162 pixmap_on = QPixmap(tmpFile);
00163 KIO::NetAccess::removeTempFile(tmpFile);
00164 qDebug( "Downloaded: " + path + " to " + tmpFile );
00165 }
00166 else
00167 {
00168 qDebug( "Error Downloading: " + path );
00169 }
00170 }
00171 else
00172 {
00173 pixmap_on = QPixmap( path );
00174 }
00175
00176 pixmapOnWidth = pixmap_on.width();
00177 pixmapOnHeight = pixmap_on.height();
00178
00179 rect_on = QRect(xon,yon,pixmapOnWidth,pixmapOnHeight);
00180 }
00181
00182 void ImageLabel::setKaramba(karamba* k)
00183 {
00184 myKaramba = k;
00185 }
00186
00187 void ImageLabel::rolloverImage(QMouseEvent *e)
00188 {
00189 if (!rollover)
00190 return;
00191
00192 if (zoomed)
00193 {
00194 if (!rect_off.contains(e->pos()))
00195 {
00196
00197
00198 x = xoff;
00199 y = yoff;
00200 pixmap = pixmap_off;
00201 pixmapWidth = pixmapOffWidth;
00202 pixmapHeight = pixmapOffHeight;
00203 zoomed = false;
00204 myKaramba->step();
00205 }
00206 }
00207 else
00208 {
00209 if (rect_off.contains(e->pos()))
00210 {
00211
00212
00213 x = xon;
00214 y = yon;
00215 pixmap = pixmap_on;
00216 pixmapWidth = pixmapOnWidth;
00217 pixmapHeight = pixmapOnHeight;
00218 zoomed = true;
00219 myKaramba->step();
00220 }
00221 }
00222 }
00223
00224 void ImageLabel::setTooltip(QString txt)
00225 {
00226 QRect rect(x,y,pixmapWidth,pixmapHeight);
00227 QToolTip::add(myKaramba, rect, txt);
00228 }