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