1 | /****************************************************************************
|
---|
2 | ** $Id: listviews.h 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
---|
5 | **
|
---|
6 | ** This file is part of an example program for Qt. This example
|
---|
7 | ** program may be used, distributed and modified without limitation.
|
---|
8 | **
|
---|
9 | *****************************************************************************/
|
---|
10 |
|
---|
11 | #ifndef LISTVIEWS_H
|
---|
12 | #define LISTVIEWS_H
|
---|
13 |
|
---|
14 | #include <qsplitter.h>
|
---|
15 | #include <qstring.h>
|
---|
16 | #include <qobject.h>
|
---|
17 | #include <qdatetime.h>
|
---|
18 | #include <qptrlist.h>
|
---|
19 | #include <qlistview.h>
|
---|
20 |
|
---|
21 | class QListView;
|
---|
22 | class QLabel;
|
---|
23 | class QPainter;
|
---|
24 | class QColorGroup;
|
---|
25 | class QObjectList;
|
---|
26 | class QPopupMenu;
|
---|
27 |
|
---|
28 | // -----------------------------------------------------------------
|
---|
29 |
|
---|
30 | class MessageHeader
|
---|
31 | {
|
---|
32 | public:
|
---|
33 | MessageHeader( const QString &_sender, const QString &_subject, const QDateTime &_datetime )
|
---|
34 | : msender( _sender ), msubject( _subject ), mdatetime( _datetime )
|
---|
35 | {}
|
---|
36 |
|
---|
37 | MessageHeader( const MessageHeader &mh );
|
---|
38 | MessageHeader &operator=( const MessageHeader &mh );
|
---|
39 |
|
---|
40 | QString sender() { return msender; }
|
---|
41 | QString subject() { return msubject; }
|
---|
42 | QDateTime datetime() { return mdatetime; }
|
---|
43 |
|
---|
44 | protected:
|
---|
45 | QString msender, msubject;
|
---|
46 | QDateTime mdatetime;
|
---|
47 |
|
---|
48 | };
|
---|
49 |
|
---|
50 | // -----------------------------------------------------------------
|
---|
51 |
|
---|
52 | class Message
|
---|
53 | {
|
---|
54 | public:
|
---|
55 | enum State { Read = 0,
|
---|
56 | Unread};
|
---|
57 |
|
---|
58 | Message( const MessageHeader &mh, const QString &_body )
|
---|
59 | : mheader( mh ), mbody( _body ), mstate( Unread )
|
---|
60 | {}
|
---|
61 |
|
---|
62 | Message( const Message &m )
|
---|
63 | : mheader( m.mheader ), mbody( m.mbody ), mstate( m.mstate )
|
---|
64 | {}
|
---|
65 |
|
---|
66 | MessageHeader header() { return mheader; }
|
---|
67 | QString body() { return mbody; }
|
---|
68 |
|
---|
69 | void setState( const State &s ) { mstate = s; }
|
---|
70 | State state() { return mstate; }
|
---|
71 |
|
---|
72 | protected:
|
---|
73 | MessageHeader mheader;
|
---|
74 | QString mbody;
|
---|
75 | State mstate;
|
---|
76 |
|
---|
77 | };
|
---|
78 |
|
---|
79 | // -----------------------------------------------------------------
|
---|
80 |
|
---|
81 | class Folder : public QObject
|
---|
82 | {
|
---|
83 | Q_OBJECT
|
---|
84 |
|
---|
85 | public:
|
---|
86 | Folder( Folder *parent, const QString &name );
|
---|
87 | ~Folder()
|
---|
88 | {}
|
---|
89 |
|
---|
90 | void addMessage( Message *m )
|
---|
91 | { lstMessages.append( m ); }
|
---|
92 |
|
---|
93 | QString folderName() { return fName; }
|
---|
94 |
|
---|
95 | Message *firstMessage() { return lstMessages.first(); }
|
---|
96 | Message *nextMessage() { return lstMessages.next(); }
|
---|
97 |
|
---|
98 | protected:
|
---|
99 | QString fName;
|
---|
100 | QPtrList<Message> lstMessages;
|
---|
101 |
|
---|
102 | };
|
---|
103 |
|
---|
104 | // -----------------------------------------------------------------
|
---|
105 |
|
---|
106 | class FolderListItem : public QListViewItem
|
---|
107 | {
|
---|
108 | public:
|
---|
109 | FolderListItem( QListView *parent, Folder *f );
|
---|
110 | FolderListItem( FolderListItem *parent, Folder *f );
|
---|
111 |
|
---|
112 | void insertSubFolders( const QObjectList *lst );
|
---|
113 |
|
---|
114 | Folder *folder() { return myFolder; }
|
---|
115 |
|
---|
116 | protected:
|
---|
117 | Folder *myFolder;
|
---|
118 |
|
---|
119 | };
|
---|
120 |
|
---|
121 | // -----------------------------------------------------------------
|
---|
122 |
|
---|
123 | class MessageListItem : public QListViewItem
|
---|
124 | {
|
---|
125 | public:
|
---|
126 | MessageListItem( QListView *parent, Message *m );
|
---|
127 |
|
---|
128 | virtual void paintCell( QPainter *p, const QColorGroup &cg,
|
---|
129 | int column, int width, int alignment );
|
---|
130 |
|
---|
131 | Message *message() { return myMessage; }
|
---|
132 |
|
---|
133 | protected:
|
---|
134 | Message *myMessage;
|
---|
135 |
|
---|
136 | };
|
---|
137 |
|
---|
138 | // -----------------------------------------------------------------
|
---|
139 |
|
---|
140 | class ListViews : public QSplitter
|
---|
141 | {
|
---|
142 | Q_OBJECT
|
---|
143 |
|
---|
144 | public:
|
---|
145 | ListViews( QWidget *parent = 0, const char *name = 0 );
|
---|
146 | ~ListViews()
|
---|
147 | {}
|
---|
148 |
|
---|
149 | protected:
|
---|
150 | void initFolders();
|
---|
151 | void initFolder( Folder *folder, unsigned int &count );
|
---|
152 | void setupFolders();
|
---|
153 |
|
---|
154 | QListView *messages, *folders;
|
---|
155 | QLabel *message;
|
---|
156 | QPopupMenu* menu;
|
---|
157 |
|
---|
158 | QPtrList<Folder> lstFolders;
|
---|
159 |
|
---|
160 | protected slots:
|
---|
161 | void slotFolderChanged( QListViewItem* );
|
---|
162 | void slotMessageChanged();
|
---|
163 | void slotRMB( QListViewItem*, const QPoint &, int );
|
---|
164 |
|
---|
165 | };
|
---|
166 |
|
---|
167 | #endif
|
---|