00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "iconlabel.h"
00011
00012 IconLabel::IconLabel(int ix,int iy,int iw,int ih): Meter(ix,iy,iw,ih), zoomed(false), rollover(false){
00013 i = new KIconLoader;
00014 kdDebug("IconLabel") << "New IconLabel" << endl;
00015
00016 }
00017
00018 IconLabel::IconLabel() : Meter(), zoomed(false), rollover(false){
00019 }
00020
00021 IconLabel::~IconLabel(){
00022 }
00023
00024 void IconLabel::setValue(int v){
00025 setValue( QString::number( v ) );
00026 }
00027
00028 void IconLabel::setValue(QString fn){
00029 icon = fn;
00030
00031 pixmap = i->loadIcon( icon, KIcon::Group(2), woff );
00032 pixmapWidth = woff;
00033 pixmapHeight = woff;
00034 rect_off = QRect(x,y,pixmapWidth,pixmapHeight);
00035 }
00036
00037 void IconLabel::setSize(int s){
00038 woff = (s != 0)?s:32;
00039 kdDebug("IconLabel") << "Icon size: " << woff << endl;
00040 }
00041
00042 void IconLabel::setCenter(bool c, int w, int h){
00043 if(h == 0 || w == 0){
00044 width = QApplication::desktop()->width();
00045 height = QApplication::desktop()->height();
00046 }
00047 else{
00048 width = w + 2*x;
00049 height = h + 2*y;
00050 }
00051 center = c;
00052 }
00053
00054 void IconLabel::mUpdate(QPainter* p){
00055 if(center == true){
00056 x = width/2 - pixmap.width()/2;
00057 y = height/2 - pixmap.height()/2;
00058 }
00059 if( ( (myKaramba->x() + myKaramba->themeW) >= 0) && ( (myKaramba->x() + x) <= QApplication::desktop()->width()) && ( (myKaramba->y() + myKaramba->themeH) >= 0) && ( (myKaramba->y() + y) <= QApplication::desktop()->height()) ){
00060 p->drawPixmap(x,y,pixmap);
00061 }
00062 }
00063
00064 void IconLabel::parseImages(QString fn, int _xoff, int _yoff, int _xon, int _yon, int won){
00065 xoff = _xoff;
00066 yoff = _yoff;
00067 xon = _xon;
00068 yon = _yon;
00069 icon = fn;
00070 kdDebug("IconLabel") << "Icon position: " << xoff << "x" << yoff << endl;
00071 pixmap_off = i->loadIcon( icon, KIcon::Group(2), woff );
00072 rect_off = QRect(xoff,yoff,woff,woff);
00073 if (won == 0){
00074 return;
00075 }
00076 rollover=true;
00077 pixmap_on = i->loadIcon( icon, KIcon::Group(2), won );
00078 rect_on = QRect(xon,yon,won,won);
00079 }
00080
00081 void IconLabel::setKaramba(karamba* k){
00082 myKaramba = k;
00083 }
00084
00085 void IconLabel::rolloverImage(QMouseEvent *e){
00086 if (!rollover){
00087 return;
00088 }
00089
00090 if (zoomed){
00091 if (!rect_off.contains(e->pos())){
00092
00093 x = xoff;
00094 y = yoff;
00095 pixmap = pixmap_off;
00096 pixmapWidth = woff;
00097 pixmapHeight = woff;
00098 zoomed = false;
00099 myKaramba->step();
00100 }
00101 }
00102 else{
00103 if (rect_off.contains(e->pos())){
00104
00105 x = xon;
00106 y = yon;
00107 pixmap = pixmap_on;
00108 pixmapWidth = won;
00109 pixmapHeight = won;
00110 zoomed = true;
00111 myKaramba->step();
00112 }
00113 }
00114 }
00115
00116 void IconLabel::setTooltip(QString txt){
00117 QRect rect(x,y,pixmapWidth,pixmapHeight);
00118 QToolTip::add(myKaramba, rect, txt);
00119 }