Main Page   Class Hierarchy   Alphabetical List   Compound List   File List  

textlabel.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 #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; //lineHeight;
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     //qDebug("move: "+QString::number(move));
00189     //qDebug(str);
00190     //qDebug("maxmove: "+QString::number(maxmove));
00191     /*qDebug("position: "+QString::number(position));
00192     qDebug("x: "+QString::number(x));
00193     qDebug("nx: "+QString::number(nx));*/
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 

Generated on Tue May 6 09:52:09 2003 for karamba by doxygen1.2.18