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 "oticker.h"
00034
00035
00036 #include <opie2/odebug.h>
00037
00038 #include <qpe/config.h>
00039
00040 using namespace Opie::Ui;
00041
00042 OTicker::OTicker( QWidget* parent )
00043 : QLabel( parent )
00044 {
00045 setTextFormat( Qt::RichText );
00046 Config cfg( "qpe" );
00047 cfg.setGroup( "Appearance" );
00048 backgroundcolor = QColor( cfg.readEntry( "Background", "#E5E1D5" ) );
00049 foregroundcolor = Qt::black;
00050 updateTimerTime = 50;
00051 scrollLength = 1;
00052 }
00053
00054 OTicker::~OTicker()
00055 {}
00056
00057 void OTicker::setBackgroundColor( const QColor& backcolor )
00058 {
00059 backgroundcolor = backcolor;
00060 update();
00061 }
00062
00063 void OTicker::setForegroundColor( const QColor& backcolor )
00064 {
00065 foregroundcolor = backcolor;
00066 update();
00067 }
00068
00069 void OTicker::setFrame( int frameStyle )
00070 {
00071 setFrameStyle( frameStyle );
00072 update();
00073 }
00074
00075 void OTicker::setText( const QString& text )
00076 {
00077 pos = 0;
00078 scrollText = text;
00079 odebug << scrollText << oendl;
00080
00081 int pixelLen = 0;
00082 bool bigger = false;
00083 int contWidth = contentsRect().width();
00084 int contHeight = contentsRect().height();
00085 int pixelTextLen = fontMetrics().width( text );
00086 odebug << "<<<<<<<height " << contHeight << ", width " << contWidth << ", text width " << pixelTextLen << " " << scrollText.length() << "\n" << oendl;
00087 if ( pixelTextLen < contWidth )
00088 {
00089 pixelLen = contWidth;
00090 }
00091 else
00092 {
00093 bigger = true;
00094 pixelLen = pixelTextLen;
00095 }
00096 QPixmap pm( pixelLen, contHeight );
00097
00098
00099 pm.fill( backgroundcolor );
00100 QPainter pmp( &pm );
00101 pmp.setPen( foregroundcolor );
00102 pmp.drawText( 0, 0, pixelTextLen, contHeight, AlignVCenter, scrollText );
00103 pmp.end();
00104 scrollTextPixmap = pm;
00105
00106 killTimers();
00107
00108 if ( bigger )
00109 startTimer( updateTimerTime );
00110 update();
00111 }
00112
00113
00114 void OTicker::timerEvent( QTimerEvent * )
00115 {
00116 pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - scrollLength;
00117 repaint( FALSE );
00118 }
00119
00120 void OTicker::drawContents( QPainter *p )
00121 {
00122 int pixelLen = scrollTextPixmap.width();
00123 p->drawPixmap( pos, contentsRect().y(), scrollTextPixmap );
00124 if ( pixelLen > contentsRect().width() )
00125 p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap );
00126 }
00127
00128 void OTicker::mouseReleaseEvent( QMouseEvent * )
00129 {
00130
00131 emit mousePressed();
00132 }
00133
00134 void OTicker::setUpdateTime( int time )
00135 {
00136 updateTimerTime = time;
00137 }
00138
00139 void OTicker::setScrollLength( int len )
00140 {
00141 scrollLength = len;
00142 }
00143