-rw-r--r-- | kaddressbook/views/cardview.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/kaddressbook/views/cardview.h b/kaddressbook/views/cardview.h index 2ea3771..9c245ea 100644 --- a/kaddressbook/views/cardview.h +++ b/kaddressbook/views/cardview.h | |||
@@ -1,57 +1,65 @@ | |||
1 | #ifndef CARDVIEW_H | 1 | #ifndef CARDVIEW_H |
2 | #define CARDVIEW_H | 2 | #define CARDVIEW_H |
3 | 3 | ||
4 | #include <qscrollview.h> | 4 | #include <q3scrollview.h> |
5 | #include <qptrlist.h> | 5 | #include <q3ptrlist.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qrect.h> | 7 | #include <qrect.h> |
8 | #include <qpair.h> | 8 | #include <qpair.h> |
9 | #include <qpoint.h> | 9 | #include <qpoint.h> |
10 | //Added by qt3to4: | ||
11 | #include <QWheelEvent> | ||
12 | #include <QResizeEvent> | ||
13 | #include <QFocusEvent> | ||
14 | #include <QLabel> | ||
15 | #include <QMouseEvent> | ||
16 | #include <QKeyEvent> | ||
17 | #include <QEvent> | ||
10 | 18 | ||
11 | class QLabel; | 19 | class QLabel; |
12 | class QPainter; | 20 | class QPainter; |
13 | class QResizeEvent; | 21 | class QResizeEvent; |
14 | class QMouseEvent; | 22 | class QMouseEvent; |
15 | class CardView; | 23 | class CardView; |
16 | class CardViewPrivate; | 24 | class CardViewPrivate; |
17 | class CardViewItemPrivate; | 25 | class CardViewItemPrivate; |
18 | class CardViewTip; | 26 | class CardViewTip; |
19 | 27 | ||
20 | /** Represents a single card (item) in the card view. A card has a caption | 28 | /** Represents a single card (item) in the card view. A card has a caption |
21 | * and a list of fields. A Field is a label<->value pair. The labels in a | 29 | * and a list of fields. A Field is a label<->value pair. The labels in a |
22 | * card should be unique, since they will be used to index the values. | 30 | * card should be unique, since they will be used to index the values. |
23 | */ | 31 | */ |
24 | class CardViewItem | 32 | class CardViewItem |
25 | { | 33 | { |
26 | friend class CardView; | 34 | friend class CardView; |
27 | 35 | ||
28 | public: | 36 | public: |
29 | /** A single field in the card view. The first item is the label | 37 | /** A single field in the card view. The first item is the label |
30 | * and the second item is the value. | 38 | * and the second item is the value. |
31 | */ | 39 | */ |
32 | typedef QPair<QString, QString> Field; | 40 | typedef QPair<QString, QString> Field; |
33 | 41 | ||
34 | /** Constructor. | 42 | /** Constructor. |
35 | * | 43 | * |
36 | * @param parent The CardView that this card should be displayed on. | 44 | * @param parent The CardView that this card should be displayed on. |
37 | * @param caption The caption of the card. This is the text that will | 45 | * @param caption The caption of the card. This is the text that will |
38 | * appear at the top of the card. This is also the string that will | 46 | * appear at the top of the card. This is also the string that will |
39 | * be used to sort the cards in the view. | 47 | * be used to sort the cards in the view. |
40 | */ | 48 | */ |
41 | CardViewItem(CardView *parent, QString caption = QString::null); | 49 | CardViewItem(CardView *parent, QString caption = QString::null); |
42 | virtual ~CardViewItem(); | 50 | virtual ~CardViewItem(); |
43 | 51 | ||
44 | /** @return The caption of the card, or QString::null if none was ever | 52 | /** @return The caption of the card, or QString::null if none was ever |
45 | * set. | 53 | * set. |
46 | */ | 54 | */ |
47 | const QString &caption() const; | 55 | const QString &caption() const; |
48 | 56 | ||
49 | /** Sets the caption of the card. This is the text that will | 57 | /** Sets the caption of the card. This is the text that will |
50 | * appear at the top of the card. This is also the string that will | 58 | * appear at the top of the card. This is also the string that will |
51 | * be used to sort the cards in the view. | 59 | * be used to sort the cards in the view. |
52 | */ | 60 | */ |
53 | void setCaption(const QString &caption); | 61 | void setCaption(const QString &caption); |
54 | 62 | ||
55 | /** Paints the card using the given painter and color group. The | 63 | /** Paints the card using the given painter and color group. The |
56 | * card will handle painting itself selected if it is selected. | 64 | * card will handle painting itself selected if it is selected. |
57 | */ | 65 | */ |
@@ -103,97 +111,97 @@ class CardViewItem | |||
103 | * @param itempos the position in item coordinates | 111 | * @param itempos the position in item coordinates |
104 | */ | 112 | */ |
105 | Field *fieldAt( const QPoint &itempos ) const; | 113 | Field *fieldAt( const QPoint &itempos ) const; |
106 | 114 | ||
107 | CardView *cardView() { return mView; }; | 115 | CardView *cardView() { return mView; }; |
108 | 116 | ||
109 | /** @return The height of this item as rendered, in pixels. | 117 | /** @return The height of this item as rendered, in pixels. |
110 | 118 | ||
111 | if @p allowCache is true, the item may use an internally | 119 | if @p allowCache is true, the item may use an internally |
112 | cached value rather than recalculating from scratch. The | 120 | cached value rather than recalculating from scratch. The |
113 | argument is mainly to allow the cardView to change global settings (like | 121 | argument is mainly to allow the cardView to change global settings (like |
114 | maxFieldLines) that might influence the items heights | 122 | maxFieldLines) that might influence the items heights |
115 | */ | 123 | */ |
116 | int height( bool allowCache=true ) const; | 124 | int height( bool allowCache=true ) const; |
117 | 125 | ||
118 | protected: | 126 | protected: |
119 | /** Sets the card as selected. This is usually only called from the | 127 | /** Sets the card as selected. This is usually only called from the |
120 | * card view. | 128 | * card view. |
121 | */ | 129 | */ |
122 | void setSelected(bool selected); | 130 | void setSelected(bool selected); |
123 | 131 | ||
124 | private: | 132 | private: |
125 | /** Sets the default values. | 133 | /** Sets the default values. |
126 | */ | 134 | */ |
127 | void initialize(); | 135 | void initialize(); |
128 | 136 | ||
129 | /** Trims a string to the width <i>width</i> using the font metrics | 137 | /** Trims a string to the width <i>width</i> using the font metrics |
130 | * to determine the width of each char. If the string is longer than | 138 | * to determine the width of each char. If the string is longer than |
131 | * <i>width</i>, then the string will be trimmed and a '...' will | 139 | * <i>width</i>, then the string will be trimmed and a '...' will |
132 | * be appended. | 140 | * be appended. |
133 | */ | 141 | */ |
134 | QString trimString(const QString &text, int width, QFontMetrics &fm); | 142 | QString trimString(const QString &text, int width, QFontMetrics &fm); |
135 | 143 | ||
136 | CardViewItemPrivate *d; | 144 | CardViewItemPrivate *d; |
137 | CardView *mView; | 145 | CardView *mView; |
138 | }; | 146 | }; |
139 | 147 | ||
140 | /** The CardView is a method of displaying data in cards. This idea is | 148 | /** The CardView is a method of displaying data in cards. This idea is |
141 | * similar to the idea of a rolodex or business cards. Each card has a | 149 | * similar to the idea of a rolodex or business cards. Each card has a |
142 | * caption and a list of fields, which are label<->value pairs. The CardView | 150 | * caption and a list of fields, which are label<->value pairs. The CardView |
143 | * displays multiple cards in a grid. The Cards are sorted based on their | 151 | * displays multiple cards in a grid. The Cards are sorted based on their |
144 | * caption. | 152 | * caption. |
145 | * | 153 | * |
146 | * The CardView class is designed to mirror the API of the QListView or | 154 | * The CardView class is designed to mirror the API of the QListView or |
147 | * QIconView. The CardView is also completely independant of KAddressBook and | 155 | * QIconView. The CardView is also completely independant of KAddressBook and |
148 | * can be used elsewhere. With the exception of a few simple config checks, | 156 | * can be used elsewhere. With the exception of a few simple config checks, |
149 | * the CardView is also 100% independant of KDE. | 157 | * the CardView is also 100% independant of KDE. |
150 | */ | 158 | */ |
151 | class CardView : public QScrollView | 159 | class CardView : public Q3ScrollView |
152 | { | 160 | { |
153 | friend class CardViewItem; | 161 | friend class CardViewItem; |
154 | 162 | ||
155 | Q_OBJECT | 163 | Q_OBJECT |
156 | 164 | ||
157 | public: | 165 | public: |
158 | /** Constructor. | 166 | /** Constructor. |
159 | */ | 167 | */ |
160 | CardView(QWidget *parent, const char *name); | 168 | CardView(QWidget *parent, const char *name); |
161 | virtual ~CardView(); | 169 | virtual ~CardView(); |
162 | 170 | ||
163 | /** Inserts the item into the card view. This method does not have | 171 | /** Inserts the item into the card view. This method does not have |
164 | * to be called if you created the item with a proper parent. Once | 172 | * to be called if you created the item with a proper parent. Once |
165 | * inserted, the CardView takes ownership of the item. | 173 | * inserted, the CardView takes ownership of the item. |
166 | */ | 174 | */ |
167 | void insertItem(CardViewItem *item); | 175 | void insertItem(CardViewItem *item); |
168 | 176 | ||
169 | /** Takes the item from the view. The item will not be deleted and | 177 | /** Takes the item from the view. The item will not be deleted and |
170 | * ownership of the item is returned to the caller. | 178 | * ownership of the item is returned to the caller. |
171 | */ | 179 | */ |
172 | void takeItem(CardViewItem *item); | 180 | void takeItem(CardViewItem *item); |
173 | 181 | ||
174 | /** Clears the view and deletes all card view items | 182 | /** Clears the view and deletes all card view items |
175 | */ | 183 | */ |
176 | void clear(); | 184 | void clear(); |
177 | 185 | ||
178 | /** @return The current item, the item that has the focus. | 186 | /** @return The current item, the item that has the focus. |
179 | * Whenever the view has focus, this item has a focus rectangle painted | 187 | * Whenever the view has focus, this item has a focus rectangle painted |
180 | * at it's border. | 188 | * at it's border. |
181 | * @sa setCurrentItem() | 189 | * @sa setCurrentItem() |
182 | */ | 190 | */ |
183 | CardViewItem *currentItem(); | 191 | CardViewItem *currentItem(); |
184 | 192 | ||
185 | /** Sets the CardViewItem @p item to the current item in the view. | 193 | /** Sets the CardViewItem @p item to the current item in the view. |
186 | */ | 194 | */ |
187 | void setCurrentItem( CardViewItem *item ); | 195 | void setCurrentItem( CardViewItem *item ); |
188 | 196 | ||
189 | /** @return The item found at the given point, or 0 if there is no item | 197 | /** @return The item found at the given point, or 0 if there is no item |
190 | * at that point. | 198 | * at that point. |
191 | */ | 199 | */ |
192 | CardViewItem *itemAt(const QPoint &viewPos); | 200 | CardViewItem *itemAt(const QPoint &viewPos); |
193 | 201 | ||
194 | /** @return The bounding rect of the given item. | 202 | /** @return The bounding rect of the given item. |
195 | */ | 203 | */ |
196 | QRect itemRect(const CardViewItem *item); | 204 | QRect itemRect(const CardViewItem *item); |
197 | 205 | ||
198 | /** Ensures that the given item is in the viewable area of the widget | 206 | /** Ensures that the given item is in the viewable area of the widget |
199 | */ | 207 | */ |