00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <qpe/config.h>
00034
00035 #include <stdlib.h>
00036 #include <stdio.h>
00037
00038 #include "oticker.h"
00039
00040 OTicker::OTicker( QWidget* parent )
00041 : QLabel( parent ) {
00042
00043 setTextFormat(Qt::RichText);
00044 Config cfg("qpe");
00045 cfg.setGroup("Appearance");
00046 backgroundcolor = QColor( cfg.readEntry( "Background", "#E5E1D5" ) );
00047 foregroundcolor= Qt::black;
00048 updateTimerTime = 50;
00049 scrollLength = 1;
00050 }
00051
00052 OTicker::~OTicker() {
00053 }
00054
00055 void OTicker::setBackgroundColor(const QColor& backcolor) {
00056 backgroundcolor = backcolor;
00057 update();
00058 }
00059
00060 void OTicker::setForegroundColor(const QColor& backcolor) {
00061 foregroundcolor = backcolor;
00062 update();
00063 }
00064
00065 void OTicker::setFrame(int frameStyle) {
00066 setFrameStyle( frameStyle);
00067 update();
00068 }
00069
00070 void OTicker::setText( const QString& text ) {
00071 pos = 0;
00072 scrollText = text;
00073 qDebug(scrollText);
00074
00075 int pixelLen = 0;
00076 bool bigger = false;
00077 int contWidth = contentsRect().width();
00078 int contHeight = contentsRect().height();
00079 int pixelTextLen = fontMetrics().width( text );
00080 printf("<<<<<<<height %d, width %d, text width %d %d\n", contHeight, contWidth, pixelTextLen, scrollText.length());
00081 if( pixelTextLen < contWidth)
00082 {
00083 pixelLen = contWidth;
00084 }
00085 else
00086 {
00087 bigger = true;
00088 pixelLen = pixelTextLen;
00089 }
00090 QPixmap pm( pixelLen, contHeight);
00091
00092
00093 pm.fill(backgroundcolor);
00094 QPainter pmp( &pm );
00095 pmp.setPen(foregroundcolor );
00096 pmp.drawText( 0, 0, pixelTextLen, contHeight, AlignVCenter, scrollText );
00097 pmp.end();
00098 scrollTextPixmap = pm;
00099
00100 killTimers();
00101
00102 if ( bigger )
00103 startTimer( updateTimerTime);
00104 update();
00105 }
00106
00107
00108 void OTicker::timerEvent( QTimerEvent * ) {
00109 pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - scrollLength;
00110 repaint( FALSE );
00111 }
00112
00113 void OTicker::drawContents( QPainter *p ) {
00114 int pixelLen = scrollTextPixmap.width();
00115 p->drawPixmap( pos, contentsRect().y(), scrollTextPixmap );
00116 if ( pixelLen > contentsRect().width() )
00117 p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap );
00118 }
00119
00120 void OTicker::mouseReleaseEvent( QMouseEvent * ) {
00121
00122 emit mousePressed();
00123 }
00124
00125 void OTicker::setUpdateTime(int time) {
00126 updateTimerTime=time;
00127 }
00128
00129 void OTicker::setScrollLength(int len) {
00130 scrollLength=len;
00131 }
00132