-rw-r--r-- | libopie/oticker.cpp | 8 | ||||
-rw-r--r-- | libopie/oticker.h | 8 |
2 files changed, 10 insertions, 6 deletions
diff --git a/libopie/oticker.cpp b/libopie/oticker.cpp index c05c2a8..b41cab6 100644 --- a/libopie/oticker.cpp +++ b/libopie/oticker.cpp | |||
@@ -1,130 +1,132 @@ | |||
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 | Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
5 | |||
4 | =. | 6 | =. |
5 | .=l. | 7 | .=l. |
6 | .>+-= | 8 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 9 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 10 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 11 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 12 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 14 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 15 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 18 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 21 | ..}^=.= = ; General Public License for more |
20 | ++= -. .` .: details. | 22 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 23 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 24 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 25 | -_. . . )=. = General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 26 | -- :-=` this; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 27 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 28 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 29 | Boston, MA 02111-1307, USA. |
28 | 30 | ||
29 | */ | 31 | */ |
30 | 32 | ||
31 | #include <qpe/config.h> | 33 | #include <qpe/config.h> |
32 | 34 | ||
33 | #include <stdlib.h> | 35 | #include <stdlib.h> |
34 | #include <stdio.h> | 36 | #include <stdio.h> |
35 | 37 | ||
36 | #include "oticker.h" | 38 | #include "oticker.h" |
37 | 39 | ||
38 | OTicker::OTicker( QWidget* parent ) | 40 | OTicker::OTicker( QWidget* parent ) |
39 | : QLabel( parent ) { | 41 | : QLabel( parent ) { |
40 | // : QFrame( parent ) { | 42 | // : QFrame( parent ) { |
41 | setTextFormat(Qt::RichText); | 43 | setTextFormat(Qt::RichText); |
42 | Config cfg("qpe"); | 44 | Config cfg("qpe"); |
43 | cfg.setGroup("Appearance"); | 45 | cfg.setGroup("Appearance"); |
44 | backgroundcolor = QColor( cfg.readEntry( "Background", "#E5E1D5" ) ); | 46 | backgroundcolor = QColor( cfg.readEntry( "Background", "#E5E1D5" ) ); |
45 | foregroundcolor= Qt::black; | 47 | foregroundcolor= Qt::black; |
46 | updateTimerTime = 50; | 48 | updateTimerTime = 50; |
47 | scrollLength = 1; | 49 | scrollLength = 1; |
48 | } | 50 | } |
49 | 51 | ||
50 | OTicker::~OTicker() { | 52 | OTicker::~OTicker() { |
51 | } | 53 | } |
52 | 54 | ||
53 | void OTicker::setBackgroundColor(const QColor& backcolor) { | 55 | void OTicker::setBackgroundColor(const QColor& backcolor) { |
54 | backgroundcolor = backcolor; | 56 | backgroundcolor = backcolor; |
55 | update(); | 57 | update(); |
56 | } | 58 | } |
57 | 59 | ||
58 | void OTicker::setForegroundColor(const QColor& backcolor) { | 60 | void OTicker::setForegroundColor(const QColor& backcolor) { |
59 | foregroundcolor = backcolor; | 61 | foregroundcolor = backcolor; |
60 | update(); | 62 | update(); |
61 | } | 63 | } |
62 | 64 | ||
63 | void OTicker::setFrame(int frameStyle) { | 65 | void OTicker::setFrame(int frameStyle) { |
64 | setFrameStyle( frameStyle/*WinPanel | Sunken */); | 66 | setFrameStyle( frameStyle/*WinPanel | Sunken */); |
65 | update(); | 67 | update(); |
66 | } | 68 | } |
67 | 69 | ||
68 | void OTicker::setText( const QString& text ) { | 70 | void OTicker::setText( const QString& text ) { |
69 | pos = 0; // reset it everytime the text is changed | 71 | pos = 0; // reset it everytime the text is changed |
70 | scrollText = text; | 72 | scrollText = text; |
71 | qDebug(scrollText); | 73 | qDebug(scrollText); |
72 | 74 | ||
73 | int pixelLen = 0; | 75 | int pixelLen = 0; |
74 | bool bigger = false; | 76 | bool bigger = false; |
75 | int contWidth = contentsRect().width(); | 77 | int contWidth = contentsRect().width(); |
76 | int contHeight = contentsRect().height(); | 78 | int contHeight = contentsRect().height(); |
77 | int pixelTextLen = fontMetrics().width( text ); | 79 | int pixelTextLen = fontMetrics().width( text ); |
78 | printf("<<<<<<<height %d, width %d, text width %d %d\n", contHeight, contWidth, pixelTextLen, scrollText.length()); | 80 | printf("<<<<<<<height %d, width %d, text width %d %d\n", contHeight, contWidth, pixelTextLen, scrollText.length()); |
79 | if( pixelTextLen < contWidth) | 81 | if( pixelTextLen < contWidth) |
80 | { | 82 | { |
81 | pixelLen = contWidth; | 83 | pixelLen = contWidth; |
82 | } | 84 | } |
83 | else | 85 | else |
84 | { | 86 | { |
85 | bigger = true; | 87 | bigger = true; |
86 | pixelLen = pixelTextLen; | 88 | pixelLen = pixelTextLen; |
87 | } | 89 | } |
88 | QPixmap pm( pixelLen, contHeight); | 90 | QPixmap pm( pixelLen, contHeight); |
89 | // pm.fill( QColor( 167, 212, 167 )); | 91 | // pm.fill( QColor( 167, 212, 167 )); |
90 | 92 | ||
91 | pm.fill(backgroundcolor); | 93 | pm.fill(backgroundcolor); |
92 | QPainter pmp( &pm ); | 94 | QPainter pmp( &pm ); |
93 | pmp.setPen(foregroundcolor ); | 95 | pmp.setPen(foregroundcolor ); |
94 | pmp.drawText( 0, 0, pixelTextLen, contHeight, AlignVCenter, scrollText ); | 96 | pmp.drawText( 0, 0, pixelTextLen, contHeight, AlignVCenter, scrollText ); |
95 | pmp.end(); | 97 | pmp.end(); |
96 | scrollTextPixmap = pm; | 98 | scrollTextPixmap = pm; |
97 | 99 | ||
98 | killTimers(); | 100 | killTimers(); |
99 | // qDebug("Scrollupdate %d", updateTimerTime); | 101 | // qDebug("Scrollupdate %d", updateTimerTime); |
100 | if ( bigger /*pixelTextLen > contWidth*/ ) | 102 | if ( bigger /*pixelTextLen > contWidth*/ ) |
101 | startTimer( updateTimerTime); | 103 | startTimer( updateTimerTime); |
102 | update(); | 104 | update(); |
103 | } | 105 | } |
104 | 106 | ||
105 | 107 | ||
106 | void OTicker::timerEvent( QTimerEvent * ) { | 108 | void OTicker::timerEvent( QTimerEvent * ) { |
107 | pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - scrollLength;//1; | 109 | pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - scrollLength;//1; |
108 | repaint( FALSE ); | 110 | repaint( FALSE ); |
109 | } | 111 | } |
110 | 112 | ||
111 | void OTicker::drawContents( QPainter *p ) { | 113 | void OTicker::drawContents( QPainter *p ) { |
112 | int pixelLen = scrollTextPixmap.width(); | 114 | int pixelLen = scrollTextPixmap.width(); |
113 | p->drawPixmap( pos, contentsRect().y(), scrollTextPixmap ); | 115 | p->drawPixmap( pos, contentsRect().y(), scrollTextPixmap ); |
114 | if ( pixelLen > contentsRect().width() ) // Scrolling | 116 | if ( pixelLen > contentsRect().width() ) // Scrolling |
115 | p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap ); | 117 | p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap ); |
116 | } | 118 | } |
117 | 119 | ||
118 | void OTicker::mouseReleaseEvent( QMouseEvent * ) { | 120 | void OTicker::mouseReleaseEvent( QMouseEvent * ) { |
119 | // qDebug("<<<<<<<>>>>>>>>>"); | 121 | // qDebug("<<<<<<<>>>>>>>>>"); |
120 | emit mousePressed(); | 122 | emit mousePressed(); |
121 | } | 123 | } |
122 | 124 | ||
123 | void OTicker::setUpdateTime(int time) { | 125 | void OTicker::setUpdateTime(int time) { |
124 | updateTimerTime=time; | 126 | updateTimerTime=time; |
125 | } | 127 | } |
126 | 128 | ||
127 | void OTicker::setScrollLength(int len) { | 129 | void OTicker::setScrollLength(int len) { |
128 | scrollLength=len; | 130 | scrollLength=len; |
129 | } | 131 | } |
130 | 132 | ||
diff --git a/libopie/oticker.h b/libopie/oticker.h index 4026eb5..45bf7ce 100644 --- a/libopie/oticker.h +++ b/libopie/oticker.h | |||
@@ -1,146 +1,148 @@ | |||
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 | Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
5 | |||
4 | =. | 6 | =. |
5 | .=l. | 7 | .=l. |
6 | .>+-= | 8 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 9 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 10 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 11 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 12 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 14 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 15 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 18 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 21 | ..}^=.= = ; General Public License for more |
20 | ++= -. .` .: details. | 22 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 23 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 24 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 25 | -_. . . )=. = General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 26 | -- :-=` this; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 27 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 28 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 29 | Boston, MA 02111-1307, USA. |
28 | 30 | ||
29 | */ | 31 | */ |
30 | 32 | ||
31 | #ifndef OTICKER_H | 33 | #ifndef OTICKER_H |
32 | #define OTICKER_H | 34 | #define OTICKER_H |
33 | 35 | ||
34 | #include <qwidget.h> | 36 | #include <qwidget.h> |
35 | #include <qpainter.h> | 37 | #include <qpainter.h> |
36 | #include <qdrawutil.h> | 38 | #include <qdrawutil.h> |
37 | #include <qpixmap.h> | 39 | #include <qpixmap.h> |
38 | #include <qstring.h> | 40 | #include <qstring.h> |
39 | #include <qslider.h> | 41 | #include <qslider.h> |
40 | #include <qlabel.h> | 42 | #include <qlabel.h> |
41 | #include <qframe.h> | 43 | #include <qframe.h> |
42 | #include <qcolor.h> | 44 | #include <qcolor.h> |
43 | 45 | ||
44 | /** | 46 | /** |
45 | * @class OTicker | 47 | * @class OTicker |
46 | * @brief The OTicker class provides a QLabel widget that scroll its contents | 48 | * @brief The OTicker class provides a QLabel widget that scroll its contents |
47 | * | 49 | * |
48 | */ | 50 | */ |
49 | class OTicker : public QLabel { | 51 | class OTicker : public QLabel { |
50 | Q_OBJECT | 52 | Q_OBJECT |
51 | 53 | ||
52 | public: | 54 | public: |
53 | 55 | ||
54 | /*! | 56 | /*! |
55 | * @fn OTicker( QWidget* parent = 0 ) | 57 | * @fn OTicker( QWidget* parent = 0 ) |
56 | * @brief Object constructor. | 58 | * @brief Object constructor. |
57 | * | 59 | * |
58 | * @param parent Pointer to parent of this control. | 60 | * @param parent Pointer to parent of this control. |
59 | 61 | ||
60 | * Constructs a new OTicker control with parent | 62 | * Constructs a new OTicker control with parent |
61 | */ | 63 | */ |
62 | OTicker( QWidget* parent=0 ); | 64 | OTicker( QWidget* parent=0 ); |
63 | /*! | 65 | /*! |
64 | * @fn ~OTicker() | 66 | * @fn ~OTicker() |
65 | * @brief Object destructor. | 67 | * @brief Object destructor. |
66 | */ | 68 | */ |
67 | ~OTicker(); | 69 | ~OTicker(); |
68 | /*! | 70 | /*! |
69 | * @fn setText(const QString& ) | 71 | * @fn setText(const QString& ) |
70 | * @brief sets text to be displayed | 72 | * @brief sets text to be displayed |
71 | * @param text QString text to be displayed. | 73 | * @param text QString text to be displayed. |
72 | * | 74 | * |
73 | */ | 75 | */ |
74 | void setText( const QString& text ) ; | 76 | void setText( const QString& text ) ; |
75 | /*! | 77 | /*! |
76 | * @fn setBackgroundColor(const QColor& color) | 78 | * @fn setBackgroundColor(const QColor& color) |
77 | * @brief sets color of the ticker's background | 79 | * @brief sets color of the ticker's background |
78 | * @param color QColor color to be set. | 80 | * @param color QColor color to be set. |
79 | * | 81 | * |
80 | */ | 82 | */ |
81 | void setBackgroundColor(const QColor& color); | 83 | void setBackgroundColor(const QColor& color); |
82 | /*! | 84 | /*! |
83 | * @fn setForegroundColor(const QColor& color) | 85 | * @fn setForegroundColor(const QColor& color) |
84 | * @brief sets color of text | 86 | * @brief sets color of text |
85 | * @param color QColor color of text | 87 | * @param color QColor color of text |
86 | * | 88 | * |
87 | */ | 89 | */ |
88 | void setForegroundColor(const QColor& color); | 90 | void setForegroundColor(const QColor& color); |
89 | /*! | 91 | /*! |
90 | * @fn setFrame(int style) | 92 | * @fn setFrame(int style) |
91 | * @brief sets frame style | 93 | * @brief sets frame style |
92 | * @param style int Frame style to be see. See Qt::WidgetFlags. | 94 | * @param style int Frame style to be see. See Qt::WidgetFlags. |
93 | * | 95 | * |
94 | */ | 96 | */ |
95 | void setFrame(int style); | 97 | void setFrame(int style); |
96 | /*! | 98 | /*! |
97 | * @fn setUpdateTime(int timeout) | 99 | * @fn setUpdateTime(int timeout) |
98 | * @brief sets time of update | 100 | * @brief sets time of update |
99 | * @param timeout int time in milliseconds between updates. | 101 | * @param timeout int time in milliseconds between updates. |
100 | * | 102 | * |
101 | */ | 103 | */ |
102 | void setUpdateTime(int timeout); | 104 | void setUpdateTime(int timeout); |
103 | /*! | 105 | /*! |
104 | * @fn setScrollLength(int length) | 106 | * @fn setScrollLength(int length) |
105 | * @brief sets amount of scrolling default is 1 | 107 | * @brief sets amount of scrolling default is 1 |
106 | * @param length int scroll length. | 108 | * @param length int scroll length. |
107 | * | 109 | * |
108 | */ | 110 | */ |
109 | void setScrollLength(int length); | 111 | void setScrollLength(int length); |
110 | signals: | 112 | signals: |
111 | /*! | 113 | /*! |
112 | * @fn mousePressed() | 114 | * @fn mousePressed() |
113 | * @brief signal mouse press event | 115 | * @brief signal mouse press event |
114 | * | 116 | * |
115 | */ | 117 | */ |
116 | void mousePressed(); | 118 | void mousePressed(); |
117 | protected: | 119 | protected: |
118 | /*! | 120 | /*! |
119 | * @fn timerEvent( QTimerEvent * e) | 121 | * @fn timerEvent( QTimerEvent * e) |
120 | * @brief timer timeout event | 122 | * @brief timer timeout event |
121 | * @param e QEvent see QEvent. | 123 | * @param e QEvent see QEvent. |
122 | * | 124 | * |
123 | */ | 125 | */ |
124 | void timerEvent( QTimerEvent * e); | 126 | void timerEvent( QTimerEvent * e); |
125 | /*! | 127 | /*! |
126 | * @fn drawContents( QPainter *p ) | 128 | * @fn drawContents( QPainter *p ) |
127 | * @brief draws widget contents | 129 | * @brief draws widget contents |
128 | * @param p QPainter. see QPainter | 130 | * @param p QPainter. see QPainter |
129 | * | 131 | * |
130 | */ | 132 | */ |
131 | void drawContents( QPainter *p ); | 133 | void drawContents( QPainter *p ); |
132 | /*! | 134 | /*! |
133 | * @fn mouseReleaseEvent( QMouseEvent *e) | 135 | * @fn mouseReleaseEvent( QMouseEvent *e) |
134 | * @brief mouse release event | 136 | * @brief mouse release event |
135 | * @param e QMouseEvent. see QMouseEvent. | 137 | * @param e QMouseEvent. see QMouseEvent. |
136 | * | 138 | * |
137 | */ | 139 | */ |
138 | void mouseReleaseEvent( QMouseEvent *e); | 140 | void mouseReleaseEvent( QMouseEvent *e); |
139 | private: | 141 | private: |
140 | QColor backgroundcolor, foregroundcolor; | 142 | QColor backgroundcolor, foregroundcolor; |
141 | QString scrollText; | 143 | QString scrollText; |
142 | QPixmap scrollTextPixmap; | 144 | QPixmap scrollTextPixmap; |
143 | int pos, updateTimerTime, scrollLength; | 145 | int pos, updateTimerTime, scrollLength; |
144 | }; | 146 | }; |
145 | 147 | ||
146 | #endif | 148 | #endif |