summaryrefslogtreecommitdiff
path: root/libopie/oticker.cpp
Unidiff
Diffstat (limited to 'libopie/oticker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/oticker.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/libopie/oticker.cpp b/libopie/oticker.cpp
new file mode 100644
index 0000000..774a49d
--- a/dev/null
+++ b/libopie/oticker.cpp
@@ -0,0 +1,94 @@
1/*
2                This file is part of the Opie Project
3 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
4 =.
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28
29*/
30
31#include <qpe/qpeapplication.h>
32#include <qpe/resource.h>
33#include <qpe/config.h>
34
35#include <qwidget.h>
36#include <qpixmap.h>
37#include <qbutton.h>
38#include <qpainter.h>
39#include <qframe.h>
40#include <qlayout.h>
41#include <qdir.h>
42#include <stdlib.h>
43#include <stdio.h>
44
45#include "oticker.h"
46
47OTicker::OTicker( QWidget* parent=0 ) : QFrame( parent ) {
48 setFrameStyle( NoFrame/*WinPanel | Sunken */);
49}
50
51OTicker::~OTicker() {
52}
53
54void OTicker::setText( const QString& text ) {
55 Config cfg("qpe");
56 cfg.setGroup("Appearance");
57
58 pos = 0; // reset it everytime the text is changed
59 scrollText = text;
60
61 int pixelLen = fontMetrics().width( text );
62 QPixmap pm( pixelLen, contentsRect().height() );
63// pm.fill( QColor( 167, 212, 167 ));
64
65 pm.fill( QColor( cfg.readEntry( "Background", "#E5E1D5" ) ));
66 QPainter pmp( &pm );
67 pmp.setPen( Qt::black );
68 pmp.drawText( 0, 0, pixelLen, contentsRect().height(), AlignVCenter, scrollText );
69 pmp.end();
70 scrollTextPixmap = pm;
71
72 killTimers();
73 if ( pixelLen > contentsRect().width() )
74 startTimer( 50 );
75 update();
76}
77
78
79void OTicker::timerEvent( QTimerEvent * ) {
80 pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - 1;
81 repaint( FALSE );
82}
83
84void OTicker::drawContents( QPainter *p ) {
85 int pixelLen = scrollTextPixmap.width();
86 p->drawPixmap( pos, contentsRect().y(), scrollTextPixmap );
87 if ( pixelLen > contentsRect().width() ) // Scrolling
88 p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap );
89}
90
91void OTicker::mouseReleaseEvent( QMouseEvent * e) {
92// qDebug("<<<<<<<>>>>>>>>>");
93 emit mousePressed();
94}