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