15TextLabel::TextLabel(karamba *k,
int x,
int y,
int w,
int h):
16 Meter(k, x,y,w,h), alignment(TQt::AlignLeft), clip(0), bgColor(0, 0, 0),
17 lineHeight(0), shadow(0), scrollSpeed(0, 0), scrollPos(0, 0), scrollGap(0),
18 scrollPause(0), pauseCounter(0), scrollType(ScrollNone)
33TextLabel::TextLabel(karamba *k):
34 Meter(k, 0, 0, 0, 0), alignment(TQt::AlignLeft), clip(0), bgColor(0, 0, 0),
35 lineHeight(0), shadow(0), scrollSpeed(0, 0), scrollPos(0, 0), scrollGap(0),
36 scrollPause(0), pauseCounter(0), scrollType(ScrollNone)
40TextLabel::~TextLabel()
56void TextLabel::setTextProps(
TextField* t )
62 shadow = t->getShadow();
63 alignment = t->getAlignment();
64 setFontSize(t->getFontSize());
65 setFont(t->getFont());
67 setColor(t->getColor());
68 setBGColor(t->getBGColor());
73void TextLabel::calculateTextSize()
76 TQFontMetrics fm(font);
77 lineHeight = fm.height();
79 textSize.setHeight(lineHeight * value.count());
80 TQStringList::Iterator it = value.begin();
81 while(it != value.end())
84 if(tmp > textSize.width())
85 textSize.setWidth(tmp);
90void TextLabel::setValue( TQString text)
92 value = TQStringList::split(
'\n',text);
96void TextLabel::setValue(
long v)
98 value = TQStringList( TQString::number( v ) );
102void TextLabel::setBGColor(TQColor clr)
107TQColor TextLabel::getBGColor()
const
112void TextLabel::setFont(TQString f)
118TQString TextLabel::getFont()
const
120 return font.family();
123void TextLabel::setFontSize(
int size)
125 font.setPixelSize(size);
129int TextLabel::getFontSize()
const
131 return font.pixelSize();
134void TextLabel::setAlignment( TQString align )
136 TQString a = align.upper();
137 if( a ==
"LEFT" || a.isEmpty() )
138 alignment = TQt::AlignLeft;
140 alignment = TQt::AlignRight;
142 alignment = TQt::AlignHCenter;
145TQString TextLabel::getAlignment()
const
147 if( alignment == TQt::AlignHCenter )
149 else if( alignment == TQt::AlignRight )
155void TextLabel::setFixedPitch(
bool fp)
157 font.setFixedPitch( fp );
160bool TextLabel::getFixedPitch()
const
162 return font.fixedPitch();
165void TextLabel::setShadow (
int s )
170int TextLabel::getShadow()
const
175void TextLabel::setScroll(
char* type, TQPoint speed,
int gap,
int pause)
177 ScrollType t = TextLabel::ScrollNone;
181 t = TextLabel::ScrollNone;
182 else if( a ==
"NORMAL" )
183 t = TextLabel::ScrollNormal;
184 else if( a ==
"BACKANDFORTH" )
185 t = TextLabel::ScrollBackAndForth;
186 else if( a ==
"ONEPASS" )
187 t = TextLabel::ScrollOnePass;
188 setScroll(t, speed, gap, pause);
191void TextLabel::setScroll(ScrollType type, TQPoint speed,
int gap,
int pause)
203 x = -1 * textSize.width();
204 else if(speed.x() < 0)
207 x = -1 * textSize.height();
208 else if(speed.y() < 0)
210 scrollPos = TQPoint(x,y);
214 case ScrollBackAndForth:
216 scrollPos = TQPoint(0,0);
224int TextLabel::drawText(TQPainter *p,
int x,
int y,
int width,
int height,
229 p->setPen(getBGColor());
230 p->drawText(x + shadow, y + shadow, width, height,
231 alignment | clip | TQt::ExpandTabs, text);
233 p->setPen(getColor());
234 p->drawText(x, y, width, height, alignment | clip | TQt::ExpandTabs, text);
238bool TextLabel::calculateScrollCoords(TQRect meterRect, TQRect &textRect,
239 TQPoint &next,
int &x,
int &y)
241 if(scrollType == ScrollBackAndForth &&
242 (scrollSpeed.x() != 0 && textSize.width() < getWidth() ||
243 scrollSpeed.y() != 0 && textSize.height() < getHeight()))
251 scrollPos += scrollSpeed;
254 TQPoint direction(scrollSpeed.x()/abs((scrollSpeed.x() == 0)?
256 scrollSpeed.y()/abs((scrollSpeed.y() == 0)?
258 next = TQPoint(-1 * direction.x() * (scrollGap + textSize.width()),
259 -1 * direction.y() * (scrollGap + textSize.height()));
260 textRect.setCoords(x, y, x + textSize.width(), y + textSize.height());
262 if(scrollType == ScrollBackAndForth)
264 if(direction.x() < 0 && textRect.right() <= meterRect.right() ||
265 direction.x() > 0 && textRect.left() >= meterRect.left())
267 scrollSpeed.setX(scrollSpeed.x() * -1);
268 pauseCounter = scrollPause;
270 if(direction.y() < 0 && textRect.bottom() <= meterRect.bottom() ||
271 direction.y() > 0 && textRect.top() >= meterRect.top())
273 scrollSpeed.setY(scrollSpeed.y() * -1);
274 pauseCounter = scrollPause;
277 else if(!textRect.intersects(meterRect))
279 if(scrollType == ScrollNormal)
281 else if(scrollType == ScrollOnePass)
290void TextLabel::mUpdate(TQPainter *p)
298 int width = getWidth();
299 int height = getHeight();
300 TQRect meterRect(x, y, width, height);
305 if(scrollType != ScrollNone)
307 p->setClipRect(x, y, width, height);
308 if(!calculateScrollCoords(meterRect, textRect, next, x, y))
310 p->setClipping(
false);
313 width = textSize.width();
314 height = textSize.height();
316 TQStringList::Iterator it = value.begin();
317 while(it != value.end() && (row <= height || height == -1 ))
319 drawText(p, x, y + i, width, height, *it);
322 if(scrollType == ScrollNormal)
324 textRect.addCoords(next.x(), next.y(), next.x(), next.y());
325 while(textRect.intersects(meterRect))
327 drawText(p, textRect.x(), textRect.y() + i, width, height, *it);
328 textRect.addCoords(next.x(), next.y(), next.x(), next.y());
335 if(scrollType != ScrollNone)
336 p->setClipping(
false);
340bool TextLabel::click(TQMouseEvent* e)
342 if (getBoundingBox().contains(e -> x(), e -> y()) && isEnabled())
345 if (e -> button() == TQt::LeftButton)
347 program = leftButtonAction;
349 else if (e -> button() == TQt::MidButton)
351 program = middleButtonAction;
353 else if (e -> button() == TQt::RightButton)
355 program = rightButtonAction;
358 if( !program.isEmpty() )
360 KRun::runCommand(program);
370void TextLabel::attachClickArea(TQString leftMouseButton,
371 TQString middleMouseButton,
372 TQString rightMouseButton)
374 leftButtonAction = leftMouseButton;
375 middleButtonAction = middleMouseButton;
376 rightButtonAction = rightMouseButton;
379#include "textlabel.moc"