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