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

superkaramba

  • superkaramba
  • src
bar.cpp
1/***************************************************************************
2 * Copyright (C) 2003 by Hans Karlsson *
3 * karlsson.h@home.se *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
10
11#include "bar.h"
12#include "karamba.h"
13
14Bar::Bar(karamba* k, int x, int y, int w, int h) : Meter(k, x, y, w, h)
15{
16 value = 0;
17 minValue = 0;
18 maxValue = 100;
19 barValue = 0;
20 vertical = false;
21}
22
23Bar::~Bar()
24{
25}
26
27bool Bar::setImage(TQString fileName)
28{
29 TQFileInfo fileInfo(fileName);
30 bool res = false;
31
32 if(m_karamba->theme().isThemeFile(fileName))
33 {
34 TQByteArray ba = m_karamba->theme().readThemeFile(fileName);
35 res = pixmap.loadFromData(ba);
36 }
37 else
38 {
39 res = pixmap.load(fileName);
40 }
41 pixmapWidth = pixmap.width();
42 pixmapHeight = pixmap.height();
43
44 if(getWidth()==0 || getHeight()==0)
45 {
46 setWidth(pixmapWidth);
47 setHeight(pixmapHeight);
48 }
49 if(res)
50 imagePath = fileName;
51 return res;
52}
53
54void Bar::setValue( long v )
55{
56 if(v > maxValue)
57 {
58 // maxValue = v;
59 v = maxValue;
60 }
61
62 if(v < minValue)
63 {
64 //minValue = v;
65 v = minValue;
66 }
67
68 barValue = v;
69
70 long diff = maxValue - minValue;
71 if(diff != 0)
72 {
73 if(vertical)
74 {
75 value = long((v-minValue)*getHeight() / diff + 0.5);
76 }
77 else // horizontal
78 {
79 value = long((v-minValue)*getWidth() / diff + 0.5);
80 }
81 }
82 else
83 {
84 value = 0;
85 }
86}
87
88void Bar::setValue(TQString v)
89{
90 setValue((long)(v.toDouble() + 0.5));
91}
92
93void Bar::setMax(long m)
94{
95 Meter::setMax(m);
96 recalculateValue();
97}
98
99void Bar::setMin(long m)
100{
101 Meter::setMin(m);
102 recalculateValue();
103}
104
105void Bar::setVertical(bool b)
106{
107 vertical = b;
108}
109
110void Bar::mUpdate(TQPainter *p)
111{
112 int x, y, width, height;
113 x = getX();
114 y = getY();
115 width = getWidth();
116 height = getHeight();
117 //only draw image if not hidden
118 if(hidden == 0)
119 {
120 if(vertical)
121 {
122 // int v = int( (value-minValue)*height / (maxValue-minValue) + 0.5 );
123 p->drawTiledPixmap(x, y+height-value, width, value, pixmap, 0,
124 pixmapHeight-value);
125 }
126 else // horizontal
127 {
128 //int v = int( (value-minValue)*width / (maxValue-minValue) + 0.5 );
129 p->drawTiledPixmap(x, y, value, height, pixmap);
130 }
131 }
132}
133
134#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.9.4
This website is maintained by Timothy Pearson.