Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

bar.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Hans Karlsson                                   *
00003  *   karlsson.h@home.se                                                      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 #include "bar.h"
00011 Bar::Bar( int  x  , int y, int w, int h ) : Meter(x, y, w, h)
00012 {
00013     value = 0;
00014     minValue = 0;
00015     maxValue = 100;
00016 }
00017 
00018 Bar::~Bar()
00019 {}
00020 
00021 void Bar::setImage( QString fileName )
00022 {
00023   QFileInfo fileInfo( fileName );
00024   QString path;
00025 
00026   if( fileInfo.isRelative() )
00027   {
00028      path = themePath + "/" + fileName;
00029   }
00030   else
00031   {
00032      path = fileName;
00033   }
00034     //qDebug( "bar: fileName=" + path );
00035     pixmap.load( path );
00036     pixmapWidth = pixmap.width();
00037     pixmapHeight = pixmap.height();
00038 
00039     if( width==0 || height==0)
00040     {
00041         width = pixmapWidth;
00042         height = pixmapHeight;
00043     }
00044 }
00045 
00046 void Bar::setValue( int v )
00047 {
00048     if ( v > maxValue )
00049     {
00050        // maxValue = v;
00051        v = maxValue;
00052     }
00053 
00054     if ( v < minValue )
00055     {
00056         //minValue = v;
00057         v = minValue;
00058     }
00059 
00060     int diff = maxValue-minValue;
00061     if ( diff != 0)
00062     {
00063         if( vertical )
00064         {
00065             value = int( (v-minValue)*height / diff + 0.5 );
00066         }
00067         else // horizontal
00068         {
00069             value = int( (v-minValue)*width / diff + 0.5 );
00070         }
00071     }
00072     else
00073     {
00074         value = 0;
00075     }
00076 }
00077 
00078 void Bar::setValue( QString v )
00079 {
00080     setValue( (int) (v.toDouble() + 0.5 ) );
00081 }
00082 
00083 void Bar::setMax( int m )
00084 {
00085     maxValue = m;
00086 }
00087 
00088 void Bar::setMin( int m )
00089 {
00090     minValue = m;
00091 }
00092 
00093 void Bar::setVertical( bool b )
00094 {
00095     vertical = b;
00096 }
00097 
00098 
00099 void Bar::mUpdate( QPainter *p )
00100 {
00101     if( vertical )
00102     {
00103         //  int v = int( (value-minValue)*height / (maxValue-minValue) + 0.5 );
00104         p->drawTiledPixmap(x,y+height-value, width, value, pixmap, 0, pixmapHeight-value );
00105     }
00106     else // horizontal
00107     {
00108         //int v = int( (value-minValue)*width / (maxValue-minValue) + 0.5 );
00109         p->drawTiledPixmap( x, y, value, height, pixmap);
00110     }
00111 }

Generated on Mon May 16 13:59:20 2005 for karamba by  doxygen 1.3.9.1