* move Qt 3 support to subdirs which need it
[kdenetwork.git] / knewsticker / itemviews.h
blob0069d3fd04af5392944abe2078348fb0599f13ef
1 /*
2 * itemviews.h
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'.
11 #ifndef ITEMVIEWS_H
12 #define ITEMVIEWS_H
14 #include <QGraphicsItemAnimation>
15 #include <QGraphicsRectItem>
16 #include <QList>
17 #include <QUrl>
18 #include <QObject>
20 struct NewsItem
22 QString text;
23 QString url;
24 QString description;
27 class KNewsTicker;
29 class NewsItemView : public QObject, public QGraphicsRectItem
31 Q_OBJECT
32 public:
33 NewsItemView( KNewsTicker *parent );
35 const QList<NewsItem> &items() const;
36 virtual void setItems( const QList<NewsItem> &items );
37 virtual void reloadSettings();
39 Q_SIGNALS:
40 void itemActivated( const QString &url );
42 protected:
43 KNewsTicker *newsTicker() { return m_newsTicker; }
45 private:
46 QList<NewsItem> m_items;
47 KNewsTicker *m_newsTicker;
50 class HyperlinkItem : public QObject, public QGraphicsSimpleTextItem
52 Q_OBJECT
53 public:
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; }
64 Q_SIGNALS:
65 void activated( const QString &url );
67 protected:
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 );
76 private:
77 QUrl m_url;
80 class SeparatorItem : public QGraphicsSimpleTextItem
82 public:
83 static const int Type = UserType + 2;
85 SeparatorItem( QGraphicsItem *parentItem );
87 virtual int type() const { return Type; }
90 class NewsTickerItem : public QGraphicsItemGroup
92 public:
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; }
107 private:
108 HyperlinkItem *m_headlineItem;
109 SeparatorItem *m_separatorItem;
112 class ScrollingItemView : public NewsItemView
114 Q_OBJECT
115 using NewsItemView::advance;
116 public:
117 ScrollingItemView( KNewsTicker *parent );
119 virtual void setItems( const QList<NewsItem> &items );
120 virtual void reloadSettings();
122 private Q_SLOTS:
123 void advance();
125 private:
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
137 Q_OBJECT
138 public:
139 PagingItemView( KNewsTicker *parent = 0 );
141 virtual void setItems( const QList<NewsItem> &items );
142 virtual void reloadSettings();
144 private Q_SLOTS:
145 void moveItemIn();
146 void itemMovedIn();
147 void moveItemOut();
148 void itemMovedOut();
150 private:
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)