-rw-r--r-- | libopie/oticker.cpp | 25 |
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 | |||
@@ -68,39 +68,54 @@ void OTicker::setForegroundColor(QColor backcolor) { | |||
68 | foregroundcolor = backcolor; | 68 | foregroundcolor = backcolor; |
69 | update(); | 69 | update(); |
70 | } | 70 | } |
71 | 71 | ||
72 | void OTicker::setFrame(int frameStyle) { | 72 | void OTicker::setFrame(int frameStyle) { |
73 | setFrameStyle( frameStyle/*WinPanel | Sunken */); | 73 | setFrameStyle( frameStyle/*WinPanel | Sunken */); |
74 | update(); | 74 | update(); |
75 | } | 75 | } |
76 | 76 | ||
77 | void OTicker::setText( const QString& text ) { | 77 | void 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 | 80 | qDebug(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 | ||
100 | void OTicker::timerEvent( QTimerEvent * ) { | 115 | void 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 | ||
105 | void OTicker::drawContents( QPainter *p ) { | 120 | void OTicker::drawContents( QPainter *p ) { |
106 | int pixelLen = scrollTextPixmap.width(); | 121 | int pixelLen = scrollTextPixmap.width(); |