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                                                                                                                  and 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 ..}^=.=       =       ;      Library 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 library; 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 "oticker.h"
00034 
00035 /* OPIE */
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 /*WinPanel | Sunken */ );
00072     update();
00073 }
00074 
00075 void OTicker::setText( const QString& text )
00076 {
00077     pos = 0; // reset it everytime the text is changed
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     //    pm.fill( QColor( 167, 212, 167 ));
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     //    odebug << "Scrollupdate " << updateTimerTime << "" << oendl;
00108     if ( bigger /*pixelTextLen > contWidth*/ )
00109         startTimer( updateTimerTime );
00110     update();
00111 }
00112 
00113 
00114 void OTicker::timerEvent( QTimerEvent * )
00115 {
00116     pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - scrollLength; //1;
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() )  // Scrolling
00125         p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap );
00126 }
00127 
00128 void OTicker::mouseReleaseEvent( QMouseEvent * )
00129 {
00130     //    odebug << "<<<<<<<>>>>>>>>>" << oendl;
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 

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