summaryrefslogtreecommitdiff
path: root/libqtaux/oticker.cpp
authordrw <drw>2004-03-02 16:37:21 (UTC)
committer drw <drw>2004-03-02 16:37:21 (UTC)
commitc4c97ef4ccf9d379ff59560c3ae3c32f95fc51d1 (patch) (unidiff)
treecf5b1b8d8dce7a87176a2a78c6acd929bfd097bf /libqtaux/oticker.cpp
parent10d627d55eaab6cda26b03879f1b0fe31d1b273b (diff)
downloadopie-c4c97ef4ccf9d379ff59560c3ae3c32f95fc51d1.zip
opie-c4c97ef4ccf9d379ff59560c3ae3c32f95fc51d1.tar.gz
opie-c4c97ef4ccf9d379ff59560c3ae3c32f95fc51d1.tar.bz2
Added OTicker class to libopie2
Diffstat (limited to 'libqtaux/oticker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libqtaux/oticker.cpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/libqtaux/oticker.cpp b/libqtaux/oticker.cpp
new file mode 100644
index 0000000..c05c2a8
--- a/dev/null
+++ b/libqtaux/oticker.cpp
@@ -0,0 +1,130 @@
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/config.h>
32
33#include <stdlib.h>
34#include <stdio.h>
35
36#include "oticker.h"
37
38OTicker::OTicker( QWidget* parent )
39 : QLabel( parent ) {
40 // : QFrame( parent ) {
41 setTextFormat(Qt::RichText);
42 Config cfg("qpe");
43 cfg.setGroup("Appearance");
44 backgroundcolor = QColor( cfg.readEntry( "Background", "#E5E1D5" ) );
45 foregroundcolor= Qt::black;
46 updateTimerTime = 50;
47 scrollLength = 1;
48}
49
50OTicker::~OTicker() {
51}
52
53void OTicker::setBackgroundColor(const QColor& backcolor) {
54 backgroundcolor = backcolor;
55 update();
56}
57
58void OTicker::setForegroundColor(const QColor& backcolor) {
59 foregroundcolor = backcolor;
60 update();
61}
62
63void OTicker::setFrame(int frameStyle) {
64 setFrameStyle( frameStyle/*WinPanel | Sunken */);
65 update();
66}
67
68void OTicker::setText( const QString& text ) {
69 pos = 0; // reset it everytime the text is changed
70 scrollText = text;
71qDebug(scrollText);
72
73 int pixelLen = 0;
74 bool bigger = false;
75 int contWidth = contentsRect().width();
76 int contHeight = contentsRect().height();
77 int pixelTextLen = fontMetrics().width( text );
78 printf("<<<<<<<height %d, width %d, text width %d %d\n", contHeight, contWidth, pixelTextLen, scrollText.length());
79 if( pixelTextLen < contWidth)
80 {
81 pixelLen = contWidth;
82 }
83 else
84 {
85 bigger = true;
86 pixelLen = pixelTextLen;
87 }
88 QPixmap pm( pixelLen, contHeight);
89// pm.fill( QColor( 167, 212, 167 ));
90
91 pm.fill(backgroundcolor);
92 QPainter pmp( &pm );
93 pmp.setPen(foregroundcolor );
94 pmp.drawText( 0, 0, pixelTextLen, contHeight, AlignVCenter, scrollText );
95 pmp.end();
96 scrollTextPixmap = pm;
97
98 killTimers();
99 // qDebug("Scrollupdate %d", updateTimerTime);
100 if ( bigger /*pixelTextLen > contWidth*/ )
101 startTimer( updateTimerTime);
102 update();
103}
104
105
106void OTicker::timerEvent( QTimerEvent * ) {
107 pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - scrollLength;//1;
108 repaint( FALSE );
109}
110
111void OTicker::drawContents( QPainter *p ) {
112 int pixelLen = scrollTextPixmap.width();
113 p->drawPixmap( pos, contentsRect().y(), scrollTextPixmap );
114 if ( pixelLen > contentsRect().width() ) // Scrolling
115 p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap );
116}
117
118void OTicker::mouseReleaseEvent( QMouseEvent * ) {
119// qDebug("<<<<<<<>>>>>>>>>");
120 emit mousePressed();
121}
122
123void OTicker::setUpdateTime(int time) {
124 updateTimerTime=time;
125}
126
127void OTicker::setScrollLength(int len) {
128scrollLength=len;
129}
130