Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

oticker.cpp

Go to the documentation of this file.
00001 /*
00002                             This file is part of the Opie Project
00003                              Copyright (c)  2002 L. Potter <ljp@llornkcor.com>
00004                              Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00005 
00006               =.
00007             .=l.
00008            .>+-=
00009  _;:,     .>    :=|.         This program is free software; you can
00010 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00011 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00012 .="- .-=="i,     .._         License as published by the Free Software
00013  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00014      ._= =}       :          or (at your option) any later version.
00015     .%`+i>       _;_.
00016     .i_,=:_.      -<s.       This program is distributed in the hope that
00017      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00018     : ..    .:,     . . .    without even the implied warranty of
00019     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00020   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00021 ..}^=.=       =       ;      General Public License for more
00022 ++=   -.     .`     .:       details.
00023  :     =  ...= . :.=-
00024  -.   .:....=;==+<;          You should have received a copy of the GNU
00025   -_. . .   )=.  =           General Public License along with
00026     --        :-=`           this; see the file COPYING.LIB.
00027                              If not, write to the Free Software Foundation,
00028                              Inc., 59 Temple Place - Suite 330,
00029                              Boston, MA 02111-1307, USA.
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   //        : QFrame( parent ) {
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/*WinPanel | Sunken */);
00067     update();
00068 }
00069 
00070 void OTicker::setText( const QString& text ) {
00071     pos = 0; // reset it everytime the text is changed
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 //    pm.fill( QColor( 167, 212, 167 ));
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     //    qDebug("Scrollupdate %d", updateTimerTime);
00102     if ( bigger /*pixelTextLen > contWidth*/ )
00103         startTimer( updateTimerTime);
00104     update();
00105 }
00106 
00107 
00108 void OTicker::timerEvent( QTimerEvent * ) {
00109   pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - scrollLength;//1;
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() ) // Scrolling
00117         p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap );
00118 }
00119 
00120 void OTicker::mouseReleaseEvent( QMouseEvent * ) {
00121 //    qDebug("<<<<<<<>>>>>>>>>");
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 

Generated on Sat Nov 5 16:16:30 2005 for OPIE by  doxygen 1.4.2