source: trunk/examples/listviews/listviews.h

Last change on this file was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
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
21class QListView;
22class QLabel;
23class QPainter;
24class QColorGroup;
25class QObjectList;
26class QPopupMenu;
27
28// -----------------------------------------------------------------
29
30class MessageHeader
31{
32public:
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
44protected:
45 QString msender, msubject;
46 QDateTime mdatetime;
47
48};
49
50// -----------------------------------------------------------------
51
52class Message
53{
54public:
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
72protected:
73 MessageHeader mheader;
74 QString mbody;
75 State mstate;
76
77};
78
79// -----------------------------------------------------------------
80
81class Folder : public QObject
82{
83 Q_OBJECT
84
85public:
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
98protected:
99 QString fName;
100 QPtrList<Message> lstMessages;
101
102};
103
104// -----------------------------------------------------------------
105
106class FolderListItem : public QListViewItem
107{
108public:
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
116protected:
117 Folder *myFolder;
118
119};
120
121// -----------------------------------------------------------------
122
123class MessageListItem : public QListViewItem
124{
125public:
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
133protected:
134 Message *myMessage;
135
136};
137
138// -----------------------------------------------------------------
139
140class ListViews : public QSplitter
141{
142 Q_OBJECT
143
144public:
145 ListViews( QWidget *parent = 0, const char *name = 0 );
146 ~ListViews()
147 {}
148
149protected:
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
160protected slots:
161 void slotFolderChanged( QListViewItem* );
162 void slotMessageChanged();
163 void slotRMB( QListViewItem*, const QPoint &, int );
164
165};
166
167#endif
Note: See TracBrowser for help on using the repository browser.