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