summaryrefslogtreecommitdiff
authordrw <drw>2004-03-02 16:37:21 (UTC)
committer drw <drw>2004-03-02 16:37:21 (UTC)
commitc4c97ef4ccf9d379ff59560c3ae3c32f95fc51d1 (patch) (unidiff)
treecf5b1b8d8dce7a87176a2a78c6acd929bfd097bf
parent10d627d55eaab6cda26b03879f1b0fe31d1b273b (diff)
downloadopie-c4c97ef4ccf9d379ff59560c3ae3c32f95fc51d1.zip
opie-c4c97ef4ccf9d379ff59560c3ae3c32f95fc51d1.tar.gz
opie-c4c97ef4ccf9d379ff59560c3ae3c32f95fc51d1.tar.bz2
Added OTicker class to libopie2
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/opieui.pro22
-rw-r--r--libqtaux/oticker.cpp130
-rw-r--r--libqtaux/oticker.h146
3 files changed, 288 insertions, 10 deletions
diff --git a/libopie2/opieui/opieui.pro b/libopie2/opieui/opieui.pro
index 8506794..1be8db5 100644
--- a/libopie2/opieui/opieui.pro
+++ b/libopie2/opieui/opieui.pro
@@ -8,2 +8,3 @@ HEADERS = oclickablelabel.h \
8 olistview.h \ 8 olistview.h \
9 omessagebox.h \
9 opixmapeffect.h \ 10 opixmapeffect.h \
@@ -11,3 +12,5 @@ HEADERS = oclickablelabel.h \
11 opixmapprovider.h \ 12 opixmapprovider.h \
13 oresource.h \
12 oselector.h \ 14 oselector.h \
15 oseparator.h \
13 otabinfo.h \ 16 otabinfo.h \
@@ -15,2 +18,4 @@ HEADERS = oclickablelabel.h \
15 otabwidget.h \ 18 otabwidget.h \
19 otaskbarapplet.h \
20 oticker.h \
16 otimepicker.h \ 21 otimepicker.h \
@@ -18,9 +23,6 @@ HEADERS = oclickablelabel.h \
18 oversatileviewitem.h \ 23 oversatileviewitem.h \
19 omessagebox.h \ 24 owait.h
20 oresource.h \
21 otaskbarapplet.h \
22 oseparator.h \
23 owait.h
24 25
25SOURCES = oclickablelabel.cpp \ 26SOURCES = oclickablelabel.cpp \
27 odialog.cpp \
26 ofontselector.cpp \ 28 ofontselector.cpp \
@@ -31,5 +33,9 @@ SOURCES = oclickablelabel.cpp \
31 opixmapprovider.cpp \ 33 opixmapprovider.cpp \
34 oresource.cpp \
32 oselector.cpp \ 35 oselector.cpp \
36 oseparator.cpp \
33 otabbar.cpp \ 37 otabbar.cpp \
34 otabwidget.cpp \ 38 otabwidget.cpp \
39 otaskbarapplet.cpp \
40 oticker.cpp \
35 otimepicker.cpp \ 41 otimepicker.cpp \
@@ -37,7 +43,3 @@ SOURCES = oclickablelabel.cpp \
37 oversatileviewitem.cpp \ 43 oversatileviewitem.cpp \
38 odialog.cpp \ 44 owait.cpp
39 oresource.cpp \
40 otaskbarapplet.cpp \
41 oseparator.cpp \
42 owait.cpp
43 45
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
diff --git a/libqtaux/oticker.h b/libqtaux/oticker.h
new file mode 100644
index 0000000..4026eb5
--- a/dev/null
+++ b/libqtaux/oticker.h
@@ -0,0 +1,146 @@
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#ifndef OTICKER_H
32#define OTICKER_H
33
34#include <qwidget.h>
35#include <qpainter.h>
36#include <qdrawutil.h>
37#include <qpixmap.h>
38#include <qstring.h>
39#include <qslider.h>
40#include <qlabel.h>
41#include <qframe.h>
42#include <qcolor.h>
43
44/**
45 * @class OTicker
46 * @brief The OTicker class provides a QLabel widget that scroll its contents
47 *
48 */
49class OTicker : public QLabel {
50 Q_OBJECT
51
52public:
53
54/*!
55 * @fn OTicker( QWidget* parent = 0 )
56 * @brief Object constructor.
57 *
58 * @param parent Pointer to parent of this control.
59
60 * Constructs a new OTicker control with parent
61 */
62 OTicker( QWidget* parent=0 );
63/*!
64 * @fn ~OTicker()
65 * @brief Object destructor.
66 */
67 ~OTicker();
68/*!
69 * @fn setText(const QString& )
70 * @brief sets text to be displayed
71 * @param text QString text to be displayed.
72 *
73 */
74 void setText( const QString& text ) ;
75/*!
76 * @fn setBackgroundColor(const QColor& color)
77 * @brief sets color of the ticker's background
78 * @param color QColor color to be set.
79 *
80 */
81 void setBackgroundColor(const QColor& color);
82/*!
83 * @fn setForegroundColor(const QColor& color)
84 * @brief sets color of text
85 * @param color QColor color of text
86 *
87 */
88 void setForegroundColor(const QColor& color);
89/*!
90 * @fn setFrame(int style)
91 * @brief sets frame style
92 * @param style int Frame style to be see. See Qt::WidgetFlags.
93 *
94 */
95 void setFrame(int style);
96/*!
97 * @fn setUpdateTime(int timeout)
98 * @brief sets time of update
99 * @param timeout int time in milliseconds between updates.
100 *
101 */
102 void setUpdateTime(int timeout);
103/*!
104 * @fn setScrollLength(int length)
105 * @brief sets amount of scrolling default is 1
106 * @param length int scroll length.
107 *
108 */
109 void setScrollLength(int length);
110signals:
111/*!
112 * @fn mousePressed()
113 * @brief signal mouse press event
114 *
115 */
116 void mousePressed();
117protected:
118/*!
119 * @fn timerEvent( QTimerEvent * e)
120 * @brief timer timeout event
121 * @param e QEvent see QEvent.
122 *
123 */
124 void timerEvent( QTimerEvent * e);
125/*!
126 * @fn drawContents( QPainter *p )
127 * @brief draws widget contents
128 * @param p QPainter. see QPainter
129 *
130 */
131 void drawContents( QPainter *p );
132/*!
133 * @fn mouseReleaseEvent( QMouseEvent *e)
134 * @brief mouse release event
135 * @param e QMouseEvent. see QMouseEvent.
136 *
137 */
138 void mouseReleaseEvent( QMouseEvent *e);
139private:
140 QColor backgroundcolor, foregroundcolor;
141 QString scrollText;
142 QPixmap scrollTextPixmap;
143 int pos, updateTimerTime, scrollLength;
144};
145
146#endif