libopie API Documentation

oticker.cpp

00001 /*
00002                             This file is part of the Opie Project
00003                              Copyright (c)  2002 L. Potter <ljp@llornkcor.com>
00004               =.
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
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   //        : QFrame( parent ) {
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/*WinPanel | Sunken */);
00074     update();
00075 }
00076 
00077 void OTicker::setText( const QString& text ) {
00078     pos = 0; // reset it everytime the text is changed
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 //    pm.fill( QColor( 167, 212, 167 ));
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     //    qDebug("Scrollupdate %d", updateTimerTime);
00109     if ( bigger /*pixelTextLen > contWidth*/ )
00110         startTimer( updateTimerTime);
00111     update();
00112 }
00113 
00114 
00115 void OTicker::timerEvent( QTimerEvent * ) {
00116   pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - scrollLength;//1;
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() ) // Scrolling
00124         p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap );
00125 }
00126 
00127 void OTicker::mouseReleaseEvent( QMouseEvent * ) {
00128 //    qDebug("<<<<<<<>>>>>>>>>");
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 
KDE Logo
This file is part of the documentation for OPIE Version 1.1.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:45 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001