00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "textlabel.h"
00011
00012 TextLabel::TextLabel( int x,int y,int w,int h)
00013 : Meter(x,y,w,h)
00014 {
00015 lineHeight = QFontMetrics(font).height();
00016 if( h != 0 || w != 0)
00017 clip = 0;
00018 else
00019 clip = Qt::DontClip;
00020
00021 if( h == 0 || w == 0)
00022 {
00023 width = -1;
00024 height = -1;
00025 }
00026 }
00027
00028 TextLabel::TextLabel()
00029 {
00030 }
00031
00032 TextLabel::~TextLabel()
00033 {
00034 }
00035
00036 void TextLabel::setValue( QString text)
00037 {
00038 value = QStringList::split('\n',text);
00039 }
00040
00041 void TextLabel::setValue( int v)
00042 {
00043 value = QStringList( QString::number( v ) );
00044 }
00045
00046 void TextLabel::setColor(int r, int g, int b)
00047 {
00048 color.setRgb(r,g,b);
00049 }
00050
00051 QColor TextLabel::getColor() const
00052 {
00053 return color;
00054 }
00055
00056 void TextLabel::setMove ( int m )
00057 {
00058 move = m;
00059 }
00060
00061 int TextLabel::getMove() const
00062 {
00063 return move;
00064 }
00065
00066 void TextLabel::setMaxMove ( int mx )
00067 {
00068 maxmove = mx;
00069 }
00070
00071 int TextLabel::getMaxMove() const
00072 {
00073 return maxmove;
00074 }
00075
00076 void TextLabel::setBGColor( int r, int g, int b )
00077 {
00078 bgColor.setRgb( r, g, b );
00079 }
00080
00081 QColor TextLabel::getBGColor() const
00082 {
00083 return bgColor;
00084 }
00085
00086
00087 void TextLabel::setFont(QString f)
00088 {
00089 font.setFamily(f);
00090 lineHeight = QFontMetrics(font).height();
00091 }
00092
00093
00094 QString TextLabel::getFont() const
00095 {
00096 return font.family();
00097 }
00098
00099 void TextLabel::setFontSize(int size)
00100 {
00101 font.setPointSize(size);
00102 lineHeight = QFontMetrics(font).height();
00103 }
00104
00105 int TextLabel::getFontSize() const
00106 {
00107 return font.pointSize();
00108 }
00109
00110 void TextLabel::setAlignment( QString align )
00111 {
00112 QString a = align.upper();
00113 if( a == "LEFT" || a == "" )
00114 alignment = Qt::AlignLeft;
00115 if( a == "RIGHT" )
00116 alignment = Qt::AlignRight;
00117 if( a == "CENTER" )
00118 alignment = Qt::AlignHCenter;
00119 }
00120
00121 QString TextLabel::getAlignment() const
00122 {
00123 if( alignment == Qt::AlignHCenter )
00124 return "CENTER";
00125 else if( alignment == Qt::AlignRight )
00126 return "RIGHT";
00127 else
00128 return "LEFT";
00129 }
00130
00131 void TextLabel::setFixedPitch( bool fp)
00132 {
00133 font.setFixedPitch( fp );
00134 }
00135
00136 bool TextLabel::getFixedPitch() const
00137 {
00138 return font.fixedPitch();
00139 }
00140
00141 void TextLabel::setShadow ( int s )
00142 {
00143 shadow = s;
00144 }
00145
00146
00147 int TextLabel::getShadow() const
00148 {
00149 return shadow;
00150 }
00151
00152
00153 void TextLabel::mUpdate(QPainter *p)
00154 {
00155 int i = 0;
00156 int row = 1;
00157 int nx;
00158 if(move != 0){
00159 if(maxmove == 0){
00160 maxmove = 300;
00161 }
00162 if(move > 0){
00163 if(position >= maxmove){
00164 position = 0;
00165 }
00166 else{
00167 position += move;
00168 }
00169 }
00170 else{
00171 if((position + maxmove) < 0){
00172 position = maxmove;
00173 }
00174 else{
00175 position += move;
00176 }
00177 }
00178 nx = position + x;
00179 }
00180 else{
00181 nx = x;
00182 }
00183 p->setFont(font);
00184 QStringList::Iterator it = value.begin();
00185 while( it != value.end() && (row <= height || height == -1 ) )
00186 {
00187 if( shadow != 0)
00188 {
00189 p->setPen( bgColor );
00190 p->drawText(nx+shadow, y+i+shadow, width,
00191 height, alignment | clip | Qt::ExpandTabs,*it);
00192 }
00193 p->setPen( color );
00194 p->drawText(nx,y+i,width,height, alignment | clip | Qt::ExpandTabs,*it);
00195 i += lineHeight;
00196 it++;
00197 row++;
00198 }
00199
00200 }
00201
00202
00203
00204
00205
00206