summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-02-16 20:23:42 (UTC)
committer llornkcor <llornkcor>2003-02-16 20:23:42 (UTC)
commitb24a37c7e412cdf49f5d93c8ab51786b6cda24fb (patch) (unidiff)
tree3a4240d95dd2d2055a963e7a70703b69b19eb604
parent0a64464dc16e6167402590ea8c30d9d56d9e5c3f (diff)
downloadopie-b24a37c7e412cdf49f5d93c8ab51786b6cda24fb.zip
opie-b24a37c7e412cdf49f5d93c8ab51786b6cda24fb.tar.gz
opie-b24a37c7e412cdf49f5d93c8ab51786b6cda24fb.tar.bz2
attempt to fix bug. please test
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/oticker.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/libopie/oticker.cpp b/libopie/oticker.cpp
index 6cd0dc8..9a7044d 100644
--- a/libopie/oticker.cpp
+++ b/libopie/oticker.cpp
@@ -1,124 +1,139 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 3 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU General Public 9:`=1 )Y*s>-.--   : the terms of the GNU General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
32#include <qpe/resource.h> 32#include <qpe/resource.h>
33#include <qpe/config.h> 33#include <qpe/config.h>
34 34
35#include <qwidget.h> 35#include <qwidget.h>
36#include <qpixmap.h> 36#include <qpixmap.h>
37#include <qbutton.h> 37#include <qbutton.h>
38#include <qpainter.h> 38#include <qpainter.h>
39#include <qframe.h> 39#include <qframe.h>
40#include <qlayout.h> 40#include <qlayout.h>
41#include <qdir.h> 41#include <qdir.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <stdio.h> 43#include <stdio.h>
44 44
45#include "oticker.h" 45#include "oticker.h"
46 46
47OTicker::OTicker( QWidget* parent ) 47OTicker::OTicker( QWidget* parent )
48 : QLabel( parent ) { 48 : QLabel( parent ) {
49 // : QFrame( parent ) { 49 // : QFrame( parent ) {
50 setTextFormat(Qt::RichText); 50 setTextFormat(Qt::RichText);
51 Config cfg("qpe"); 51 Config cfg("qpe");
52 cfg.setGroup("Appearance"); 52 cfg.setGroup("Appearance");
53 backgroundcolor = QColor( cfg.readEntry( "Background", "#E5E1D5" ) ); 53 backgroundcolor = QColor( cfg.readEntry( "Background", "#E5E1D5" ) );
54 foregroundcolor= Qt::black; 54 foregroundcolor= Qt::black;
55 updateTimerTime = 50; 55 updateTimerTime = 50;
56 scrollLength = 1; 56 scrollLength = 1;
57} 57}
58 58
59OTicker::~OTicker() { 59OTicker::~OTicker() {
60} 60}
61 61
62void OTicker::setBackgroundColor(QColor backcolor) { 62void OTicker::setBackgroundColor(QColor backcolor) {
63 backgroundcolor = backcolor; 63 backgroundcolor = backcolor;
64 update(); 64 update();
65} 65}
66 66
67void OTicker::setForegroundColor(QColor backcolor) { 67void OTicker::setForegroundColor(QColor backcolor) {
68 foregroundcolor = backcolor; 68 foregroundcolor = backcolor;
69 update(); 69 update();
70} 70}
71 71
72void OTicker::setFrame(int frameStyle) { 72void OTicker::setFrame(int frameStyle) {
73 setFrameStyle( frameStyle/*WinPanel | Sunken */); 73 setFrameStyle( frameStyle/*WinPanel | Sunken */);
74 update(); 74 update();
75} 75}
76 76
77void OTicker::setText( const QString& text ) { 77void OTicker::setText( const QString& text ) {
78 pos = 0; // reset it everytime the text is changed 78 pos = 0; // reset it everytime the text is changed
79 scrollText = text; 79 scrollText = text;
80 80qDebug(scrollText);
81 int pixelLen = fontMetrics().width( text ); 81
82 QPixmap pm( pixelLen, contentsRect().height() ); 82 int pixelLen = 0;
83 bool bigger = false;
84 int contWidth = contentsRect().width();
85 int contHeight = contentsRect().height();
86 int pixelTextLen = fontMetrics().width( text );
87 printf("<<<<<<<height %d, width %d, text width %d %d\n", contHeight, contWidth, pixelTextLen, scrollText.length());
88 if( pixelTextLen < contWidth)
89 {
90 pixelLen = contWidth;
91 }
92 else
93 {
94 bigger = true;
95 pixelLen = pixelTextLen;
96 }
97 QPixmap pm( pixelLen, contHeight);
83// pm.fill( QColor( 167, 212, 167 )); 98// pm.fill( QColor( 167, 212, 167 ));
84 99
85 pm.fill(backgroundcolor); 100 pm.fill(backgroundcolor);
86 QPainter pmp( &pm ); 101 QPainter pmp( &pm );
87 pmp.setPen(foregroundcolor ); 102 pmp.setPen(foregroundcolor );
88 pmp.drawText( 0, 0, pixelLen, contentsRect().height(), AlignVCenter, scrollText ); 103 pmp.drawText( 0, 0, pixelTextLen, contHeight, AlignVCenter, scrollText );
89 pmp.end(); 104 pmp.end();
90 scrollTextPixmap = pm; 105 scrollTextPixmap = pm;
91 106
92 killTimers(); 107 killTimers();
93 // qDebug("Scrollupdate %d", updateTimerTime); 108 // qDebug("Scrollupdate %d", updateTimerTime);
94 if ( pixelLen > contentsRect().width() ) 109 if ( bigger /*pixelTextLen > contWidth*/ )
95 startTimer( updateTimerTime); 110 startTimer( updateTimerTime);
96 update(); 111 update();
97} 112}
98 113
99 114
100void OTicker::timerEvent( QTimerEvent * ) { 115void OTicker::timerEvent( QTimerEvent * ) {
101 pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - scrollLength;//1; 116 pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - scrollLength;//1;
102 repaint( FALSE ); 117 repaint( FALSE );
103} 118}
104 119
105void OTicker::drawContents( QPainter *p ) { 120void OTicker::drawContents( QPainter *p ) {
106 int pixelLen = scrollTextPixmap.width(); 121 int pixelLen = scrollTextPixmap.width();
107 p->drawPixmap( pos, contentsRect().y(), scrollTextPixmap ); 122 p->drawPixmap( pos, contentsRect().y(), scrollTextPixmap );
108 if ( pixelLen > contentsRect().width() ) // Scrolling 123 if ( pixelLen > contentsRect().width() ) // Scrolling
109 p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap ); 124 p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap );
110} 125}
111 126
112void OTicker::mouseReleaseEvent( QMouseEvent * ) { 127void OTicker::mouseReleaseEvent( QMouseEvent * ) {
113// qDebug("<<<<<<<>>>>>>>>>"); 128// qDebug("<<<<<<<>>>>>>>>>");
114 emit mousePressed(); 129 emit mousePressed();
115} 130}
116 131
117void OTicker::setUpdateTime(int time) { 132void OTicker::setUpdateTime(int time) {
118 updateTimerTime=time; 133 updateTimerTime=time;
119} 134}
120 135
121void OTicker::setScrollLength(int len) { 136void OTicker::setScrollLength(int len) {
122scrollLength=len; 137scrollLength=len;
123} 138}
124 139