4 * Copyright (c) 2007 Frerich Raabe <raabe@kde.org>
6 * This program is distributed in the hope that it will be useful, but WITHOUT
7 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8 * FOR A PARTICULAR PURPOSE. For licensing and distribution details, check the
9 * accompanying file 'COPYING'.
14 #include <QGraphicsItemAnimation>
15 #include <QGraphicsRectItem>
29 class NewsItemView
: public QObject
, public QGraphicsRectItem
33 NewsItemView( KNewsTicker
*parent
);
35 const QList
<NewsItem
> &items() const;
36 virtual void setItems( const QList
<NewsItem
> &items
);
37 virtual void reloadSettings();
40 void itemActivated( const QString
&url
);
43 KNewsTicker
*newsTicker() { return m_newsTicker
; }
46 QList
<NewsItem
> m_items
;
47 KNewsTicker
*m_newsTicker
;
50 class HyperlinkItem
: public QObject
, public QGraphicsSimpleTextItem
54 static const int Type
= UserType
+ 1;
56 HyperlinkItem( const QString
&text
, const QUrl
&url
,
57 QGraphicsItem
*parentItem
);
59 virtual int type() const { return Type
; }
61 const QUrl
&url() const { return m_url
; }
62 void setUrl( const QUrl
&url
) { m_url
= url
; }
65 void activated( const QString
&url
);
68 virtual void hoverEnterEvent( QGraphicsSceneHoverEvent
*e
);
69 virtual void hoverLeaveEvent( QGraphicsSceneHoverEvent
*e
);
71 // empty reimplementation so that we get release events
72 virtual void mousePressEvent( QGraphicsSceneMouseEvent
* ) { }
74 virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent
*e
);
80 class SeparatorItem
: public QGraphicsSimpleTextItem
83 static const int Type
= UserType
+ 2;
85 SeparatorItem( QGraphicsItem
*parentItem
);
87 virtual int type() const { return Type
; }
90 class NewsTickerItem
: public QGraphicsItemGroup
93 static const int Type
= UserType
+ 3;
95 NewsTickerItem( const QString
&text
, const QUrl
&url
,
96 const QString
&description
,
97 QGraphicsItem
*parentItem
);
99 virtual int type() const { return Type
; }
101 const HyperlinkItem
*headlineItem() const { return m_headlineItem
; }
102 HyperlinkItem
*headlineItem() { return m_headlineItem
; }
104 const SeparatorItem
*separatorItem() const { return m_separatorItem
; }
105 SeparatorItem
*separatorItem() { return m_separatorItem
; }
108 HyperlinkItem
*m_headlineItem
;
109 SeparatorItem
*m_separatorItem
;
112 class ScrollingItemView
: public NewsItemView
115 using NewsItemView::advance
;
117 ScrollingItemView( KNewsTicker
*parent
);
119 virtual void setItems( const QList
<NewsItem
> &items
);
120 virtual void reloadSettings();
126 void relayoutItems();
127 void addItemToLayout( const NewsItem
&item
, qreal
*xpos
, qreal
*ypos
);
128 void configureScrollTimer();
130 QTimer
*m_scrollTimer
;
131 QList
<NewsTickerItem
*> m_graphicsItems
;
132 qreal m_steppingWidth
;
135 class PagingItemView
: public NewsItemView
139 PagingItemView( KNewsTicker
*parent
= 0 );
141 virtual void setItems( const QList
<NewsItem
> &items
);
142 virtual void reloadSettings();
151 void updateMoveAnimations();
152 void updateLinkItem();
154 QList
<NewsItem
>::ConstIterator m_currentItem
;
155 HyperlinkItem
*m_linkItem
;
156 QGraphicsItemAnimation
*m_moveInAnimation
;
157 QGraphicsItemAnimation
*m_moveOutAnimation
;
158 bool m_needToReloadSettings
;
161 #endif // !defined(ITEMVIEWS_H)