• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

bar.cpp
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 
00011 #include "bar.h"
00012 #include "karamba.h"
00013 
00014 Bar::Bar(karamba* k, int x, int y, int w, int h) : Meter(k, x, y, w, h)
00015 {
00016   value = 0;
00017   minValue = 0;
00018   maxValue = 100;
00019   barValue = 0;
00020   vertical = false;
00021 }
00022 
00023 Bar::~Bar()
00024 {
00025 }
00026 
00027 bool Bar::setImage(TQString fileName)
00028 {
00029   TQFileInfo fileInfo(fileName);
00030   bool res = false;
00031 
00032   if(m_karamba->theme().isThemeFile(fileName))
00033   {
00034     TQByteArray ba = m_karamba->theme().readThemeFile(fileName);
00035     res = pixmap.loadFromData(ba);
00036   }
00037   else
00038   {
00039     res = pixmap.load(fileName);
00040   }
00041   pixmapWidth = pixmap.width();
00042   pixmapHeight = pixmap.height();
00043 
00044   if(getWidth()==0 || getHeight()==0)
00045   {
00046     setWidth(pixmapWidth);
00047     setHeight(pixmapHeight);
00048   }
00049   if(res)
00050     imagePath = fileName;
00051   return res;
00052 }
00053 
00054 void Bar::setValue( long v )
00055 {
00056   if(v > maxValue)
00057   {
00058     // maxValue = v;
00059     v = maxValue;
00060   }
00061 
00062   if(v < minValue)
00063   {
00064     //minValue = v;
00065     v = minValue;
00066   }
00067 
00068   barValue = v;
00069 
00070   long diff = maxValue - minValue;
00071   if(diff != 0)
00072   {
00073     if(vertical)
00074     {
00075       value = long((v-minValue)*getHeight() / diff + 0.5);
00076     }
00077     else // horizontal
00078     {
00079       value = long((v-minValue)*getWidth() / diff + 0.5);
00080     }
00081   }
00082   else
00083   {
00084     value = 0;
00085   }
00086 }
00087 
00088 void Bar::setValue(TQString v)
00089 {
00090   setValue((long)(v.toDouble() + 0.5));
00091 }
00092 
00093 void Bar::setMax(long m)
00094 {
00095   Meter::setMax(m);
00096   recalculateValue();
00097 }
00098 
00099 void Bar::setMin(long m)
00100 {
00101   Meter::setMin(m);
00102   recalculateValue();
00103 }
00104 
00105 void Bar::setVertical(bool b)
00106 {
00107   vertical = b;
00108 }
00109 
00110 void Bar::mUpdate(TQPainter *p)
00111 {
00112   int x, y, width, height;
00113   x = getX();
00114   y = getY();
00115   width = getWidth();
00116   height = getHeight();
00117   //only draw image if not hidden
00118   if(hidden == 0)
00119   {
00120     if(vertical)
00121     {
00122       //  int v = int( (value-minValue)*height / (maxValue-minValue) + 0.5 );
00123       p->drawTiledPixmap(x, y+height-value, width, value, pixmap, 0,
00124                          pixmapHeight-value);
00125     }
00126     else // horizontal
00127     {
00128       //int v = int( (value-minValue)*width / (maxValue-minValue) + 0.5 );
00129       p->drawTiledPixmap(x, y, value, height, pixmap);
00130     }
00131   }
00132 }
00133 
00134 #include "bar.moc"

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.