Diffstat (limited to 'kaddressbook/views/cardview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/views/cardview.cpp | 114 |
1 files changed, 61 insertions, 53 deletions
diff --git a/kaddressbook/views/cardview.cpp b/kaddressbook/views/cardview.cpp index b6e053f..1a29f41 100644 --- a/kaddressbook/views/cardview.cpp +++ b/kaddressbook/views/cardview.cpp | |||
@@ -5,106 +5,114 @@ | |||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | //BEGIN Includes | 24 | //BEGIN Includes |
25 | #include "cardview.h" | 25 | #include "cardview.h" |
26 | 26 | ||
27 | #include <limits.h> | 27 | #include <limits.h> |
28 | 28 | ||
29 | #include <qpainter.h> | 29 | #include <qpainter.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | #include <qdatetime.h> | 31 | #include <qdatetime.h> |
32 | #include <qlabel.h> | 32 | #include <qlabel.h> |
33 | #include <qstyle.h> | 33 | #include <qstyle.h> |
34 | #include <qcursor.h> | 34 | #include <qcursor.h> |
35 | #include <qtooltip.h> | 35 | #include <qtooltip.h> |
36 | #include <qapplication.h> | 36 | #include <qapplication.h> |
37 | //Added by qt3to4: | ||
38 | #include <QKeyEvent> | ||
39 | #include <Q3PtrList> | ||
40 | #include <QResizeEvent> | ||
41 | #include <QFocusEvent> | ||
42 | #include <QMouseEvent> | ||
43 | #include <QEvent> | ||
44 | #include <QWheelEvent> | ||
37 | 45 | ||
38 | #include "kabprefs.h" | 46 | #include "kabprefs.h" |
39 | #include <kdebug.h> | 47 | #include <kdebug.h> |
40 | #include <kglobalsettings.h> | 48 | #include <kglobalsettings.h> |
41 | //END includes | 49 | //END includes |
42 | 50 | ||
43 | #define MIN_ITEM_WIDTH 80 | 51 | #define MIN_ITEM_WIDTH 80 |
44 | 52 | ||
45 | //BEGIN Helpers | 53 | //BEGIN Helpers |
46 | ////////////////////////////////////// | 54 | ////////////////////////////////////// |
47 | // CardViewTip | 55 | // CardViewTip |
48 | class CardViewTip : public QLabel { | 56 | class CardViewTip : public QLabel { |
49 | public: | 57 | public: |
50 | CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name ) | 58 | CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name ) |
51 | { | 59 | { |
52 | setPalette( QToolTip::palette() ); | 60 | setPalette( QToolTip::palette() ); |
53 | setFrameStyle( Panel|Plain ); | 61 | setFrameStyle( Panel|Plain ); |
54 | setMidLineWidth(0); | 62 | setMidLineWidth(0); |
55 | setIndent(1); | 63 | setIndent(1); |
56 | } | 64 | } |
57 | 65 | ||
58 | ~CardViewTip() {}; | 66 | ~CardViewTip() {}; |
59 | protected: | 67 | protected: |
60 | void leaveEvent( QEvent * ) | 68 | void leaveEvent( QEvent * ) |
61 | { | 69 | { |
62 | hide(); | 70 | hide(); |
63 | } | 71 | } |
64 | }; | 72 | }; |
65 | 73 | ||
66 | ////////////////////////////////////// | 74 | ////////////////////////////////////// |
67 | // CardViewItemList | 75 | // CardViewItemList |
68 | 76 | ||
69 | 77 | ||
70 | // | 78 | // |
71 | // Warning: make sure you use findRef() instead of find() to find an | 79 | // Warning: make sure you use findRef() instead of find() to find an |
72 | // item! Only the pointer value is unique in the list. | 80 | // item! Only the pointer value is unique in the list. |
73 | // | 81 | // |
74 | class CardViewItemList : public QPtrList<CardViewItem> | 82 | class CardViewItemList : public Q3PtrList<CardViewItem> |
75 | { | 83 | { |
76 | protected: | 84 | protected: |
77 | virtual int compareItems(QPtrCollection::Item item1, | 85 | virtual int compareItems(Q3PtrCollection::Item item1, |
78 | QPtrCollection::Item item2) | 86 | Q3PtrCollection::Item item2) |
79 | { | 87 | { |
80 | CardViewItem *cItem1 = (CardViewItem*)item1; | 88 | CardViewItem *cItem1 = (CardViewItem*)item1; |
81 | CardViewItem *cItem2 = (CardViewItem*)item2; | 89 | CardViewItem *cItem2 = (CardViewItem*)item2; |
82 | 90 | ||
83 | if ( cItem1 == cItem2 ) | 91 | if ( cItem1 == cItem2 ) |
84 | return 0; | 92 | return 0; |
85 | 93 | ||
86 | if ((cItem1 == 0) || (cItem2 == 0)) | 94 | if ((cItem1 == 0) || (cItem2 == 0)) |
87 | return cItem1 ? -1 : 1; | 95 | return cItem1 ? -1 : 1; |
88 | 96 | ||
89 | if (cItem1->caption() < cItem2->caption()) | 97 | if (cItem1->caption() < cItem2->caption()) |
90 | return -1; | 98 | return -1; |
91 | 99 | ||
92 | else if (cItem1->caption() > cItem2->caption()) | 100 | else if (cItem1->caption() > cItem2->caption()) |
93 | return 1; | 101 | return 1; |
94 | 102 | ||
95 | return 0; | 103 | return 0; |
96 | } | 104 | } |
97 | 105 | ||
98 | private: | 106 | private: |
99 | /*int find( const CardViewItem * ) | 107 | /*int find( const CardViewItem * ) |
100 | { | 108 | { |
101 | qDebug("DON'T USE CardViewItemList::find( item )! Use findRef( item )!"); | 109 | qDebug("DON'T USE CardViewItemList::find( item )! Use findRef( item )!"); |
102 | }*/ | 110 | }*/ |
103 | }; | 111 | }; |
104 | 112 | ||
105 | ////////////////////////////////////// | 113 | ////////////////////////////////////// |
106 | // CardViewSeparator | 114 | // CardViewSeparator |
107 | class CardViewSeparator | 115 | class CardViewSeparator |
108 | { | 116 | { |
109 | friend class CardView; | 117 | friend class CardView; |
110 | 118 | ||
@@ -132,112 +140,112 @@ class CardViewSeparator | |||
132 | CardView *mView; | 140 | CardView *mView; |
133 | QRect mRect; | 141 | QRect mRect; |
134 | }; | 142 | }; |
135 | 143 | ||
136 | //END Helpers | 144 | //END Helpers |
137 | 145 | ||
138 | //BEGIN Private Data | 146 | //BEGIN Private Data |
139 | 147 | ||
140 | class CardViewPrivate | 148 | class CardViewPrivate |
141 | { | 149 | { |
142 | public: | 150 | public: |
143 | CardViewPrivate() | 151 | CardViewPrivate() |
144 | : mSelectionMode( CardView::Multi ), | 152 | : mSelectionMode( CardView::Multi ), |
145 | mDrawCardBorder( true ), | 153 | mDrawCardBorder( true ), |
146 | mDrawFieldLabels( true ), | 154 | mDrawFieldLabels( true ), |
147 | mDrawSeparators( true), | 155 | mDrawSeparators( true), |
148 | mSepWidth( 2 ), | 156 | mSepWidth( 2 ), |
149 | mShowEmptyFields( false ), | 157 | mShowEmptyFields( false ), |
150 | mLayoutDirty( true ), | 158 | mLayoutDirty( true ), |
151 | mLastClickOnItem( false ), | 159 | mLastClickOnItem( false ), |
152 | mItemMargin( 0 ), | 160 | mItemMargin( 0 ), |
153 | mItemSpacing( 10 ), | 161 | mItemSpacing( 10 ), |
154 | mItemWidth( 200 ), | 162 | mItemWidth( 200 ), |
155 | mMaxFieldLines( INT_MAX ), | 163 | mMaxFieldLines( INT_MAX ), |
156 | mCurrentItem( 0L ), | 164 | mCurrentItem( 0L ), |
157 | mLastClickPos( QPoint(0, 0) ), | 165 | mLastClickPos( QPoint(0, 0) ), |
158 | mResizeAnchor(0), | 166 | mResizeAnchor(0), |
159 | mRubberBandAnchor( 0 ), | 167 | mRubberBandAnchor( 0 ), |
160 | mCompText( QString::null ) | 168 | mCompText( QString::null ) |
161 | {}; | 169 | {}; |
162 | 170 | ||
163 | CardViewItemList mItemList; | 171 | CardViewItemList mItemList; |
164 | QPtrList<CardViewSeparator> mSeparatorList; | 172 | Q3PtrList<CardViewSeparator> mSeparatorList; |
165 | QFontMetrics *mFm; | 173 | QFontMetrics *mFm; |
166 | QFontMetrics *mBFm; // bold font | 174 | QFontMetrics *mBFm; // bold font |
167 | QFont mHeaderFont; // custom header font | 175 | QFont mHeaderFont; // custom header font |
168 | CardView::SelectionMode mSelectionMode; | 176 | CardView::SelectionMode mSelectionMode; |
169 | bool mDrawCardBorder; | 177 | bool mDrawCardBorder; |
170 | bool mDrawFieldLabels; | 178 | bool mDrawFieldLabels; |
171 | bool mDrawSeparators; | 179 | bool mDrawSeparators; |
172 | int mSepWidth; | 180 | int mSepWidth; |
173 | bool mShowEmptyFields; | 181 | bool mShowEmptyFields; |
174 | bool mLayoutDirty; | 182 | bool mLayoutDirty; |
175 | bool mLastClickOnItem; | 183 | bool mLastClickOnItem; |
176 | uint mItemMargin; // internal margin in items | 184 | uint mItemMargin; // internal margin in items |
177 | uint mItemSpacing; // spacing between items, column seperators and border | 185 | uint mItemSpacing; // spacing between items, column seperators and border |
178 | int mItemWidth; // width of all items | 186 | int mItemWidth; // width of all items |
179 | uint mMaxFieldLines; // Max lines to dispaly pr field | 187 | uint mMaxFieldLines; // Max lines to dispaly pr field |
180 | CardViewItem *mCurrentItem; | 188 | CardViewItem *mCurrentItem; |
181 | QPoint mLastClickPos; | 189 | QPoint mLastClickPos; |
182 | QTimer *mTimer; // times out if mouse rests for more than 500 msecs | 190 | QTimer *mTimer; // times out if mouse rests for more than 500 msecs |
183 | CardViewTip *mTip; // passed to the item under a resting cursor to display full text | 191 | CardViewTip *mTip; // passed to the item under a resting cursor to display full text |
184 | bool mOnSeparator; // set/reset on mouse movement | 192 | bool mOnSeparator; // set/reset on mouse movement |
185 | // for resizing by dragging the separators | 193 | // for resizing by dragging the separators |
186 | int mResizeAnchor; // uint, ulong? the mouse down separator left | 194 | int mResizeAnchor; // uint, ulong? the mouse down separator left |
187 | int mRubberBandAnchor; // for erasing rubber bands | 195 | int mRubberBandAnchor; // for erasing rubber bands |
188 | // data used for resizing. | 196 | // data used for resizing. |
189 | // as they are beeded by each mouse move while resizing, we store them here, | 197 | // as they are beeded by each mouse move while resizing, we store them here, |
190 | // saving 8 calculations in each mouse move. | 198 | // saving 8 calculations in each mouse move. |
191 | int colspace; // amount of space between items pr column | 199 | int colspace; // amount of space between items pr column |
192 | uint first; // the first col to anchor at for painting rubber bands | 200 | uint first; // the first col to anchor at for painting rubber bands |
193 | int firstX; // X position of first in pixel | 201 | int firstX; // X position of first in pixel |
194 | int pressed; // the colummn that was pressed on at resizing start | 202 | int pressed; // the colummn that was pressed on at resizing start |
195 | int span; // pressed - first | 203 | int span; // pressed - first |
196 | // key completion | 204 | // key completion |
197 | QString mCompText; // current completion string | 205 | QString mCompText; // current completion string |
198 | QDateTime mCompUpdated; // ...was updated at this time | 206 | QDateTime mCompUpdated; // ...was updated at this time |
199 | }; | 207 | }; |
200 | 208 | ||
201 | class CardViewItemPrivate | 209 | class CardViewItemPrivate |
202 | { | 210 | { |
203 | public: | 211 | public: |
204 | CardViewItemPrivate() : | 212 | CardViewItemPrivate() : |
205 | mSelected( false ), | 213 | mSelected( false ), |
206 | x( 0 ), | 214 | x( 0 ), |
207 | y( 0 ){}; | 215 | y( 0 ){}; |
208 | 216 | ||
209 | 217 | ||
210 | QString mCaption; | 218 | QString mCaption; |
211 | QPtrList< CardViewItem::Field > mFieldList; | 219 | Q3PtrList< CardViewItem::Field > mFieldList; |
212 | bool mSelected; | 220 | bool mSelected; |
213 | int x; // horizontal position, set by the view | 221 | int x; // horizontal position, set by the view |
214 | int y; // vertical position, set by the view | 222 | int y; // vertical position, set by the view |
215 | int maxLabelWidth; // the width of the widest label, according to the view font. | 223 | int maxLabelWidth; // the width of the widest label, according to the view font. |
216 | int hcache; // height cache | 224 | int hcache; // height cache |
217 | }; | 225 | }; |
218 | //END Private Data | 226 | //END Private Data |
219 | 227 | ||
220 | //BEGIN CardViewItem | 228 | //BEGIN CardViewItem |
221 | 229 | ||
222 | CardViewItem::CardViewItem(CardView *parent, QString caption) | 230 | CardViewItem::CardViewItem(CardView *parent, QString caption) |
223 | : d(new CardViewItemPrivate()), mView(parent) | 231 | : d(new CardViewItemPrivate()), mView(parent) |
224 | { | 232 | { |
225 | d->mCaption = caption; | 233 | d->mCaption = caption; |
226 | 234 | ||
227 | initialize(); | 235 | initialize(); |
228 | } | 236 | } |
229 | 237 | ||
230 | CardViewItem::~CardViewItem() | 238 | CardViewItem::~CardViewItem() |
231 | { | 239 | { |
232 | // Remove ourself from the view | 240 | // Remove ourself from the view |
233 | if (mView != 0) | 241 | if (mView != 0) |
234 | mView->takeItem(this); | 242 | mView->takeItem(this); |
235 | 243 | ||
236 | delete d; | 244 | delete d; |
237 | d = 0; | 245 | d = 0; |
238 | } | 246 | } |
239 | 247 | ||
240 | void CardViewItem::initialize() | 248 | void CardViewItem::initialize() |
241 | { | 249 | { |
242 | d->mSelected = false; | 250 | d->mSelected = false; |
243 | d->mFieldList.setAutoDelete(true); | 251 | d->mFieldList.setAutoDelete(true); |
@@ -284,65 +292,65 @@ void CardViewItem::paintCard(QPainter *p, QColorGroup &cg) | |||
284 | // Draw a simple box | 292 | // Draw a simple box |
285 | if (isSelected()) | 293 | if (isSelected()) |
286 | pen = QPen(cg.highlight(), 1); | 294 | pen = QPen(cg.highlight(), 1); |
287 | else | 295 | else |
288 | pen = QPen(cg.button(), 1); | 296 | pen = QPen(cg.button(), 1); |
289 | p->setPen(pen); | 297 | p->setPen(pen); |
290 | 298 | ||
291 | // Draw the border - this is only draw if the user asks for it. | 299 | // Draw the border - this is only draw if the user asks for it. |
292 | if (drawBorder) | 300 | if (drawBorder) |
293 | p->drawRect( mg, mg, w, h ); | 301 | p->drawRect( mg, mg, w, h ); |
294 | 302 | ||
295 | // set the proper pen color for the caption box | 303 | // set the proper pen color for the caption box |
296 | if (isSelected()) | 304 | if (isSelected()) |
297 | brush = cg.brush(QColorGroup::Highlight); | 305 | brush = cg.brush(QColorGroup::Highlight); |
298 | else | 306 | else |
299 | brush = cg.brush(QColorGroup::Button); | 307 | brush = cg.brush(QColorGroup::Button); |
300 | 308 | ||
301 | p->fillRect(mg, mg, w, 4 + bFm.height(), brush); | 309 | p->fillRect(mg, mg, w, 4 + bFm.height(), brush); |
302 | 310 | ||
303 | // Now paint the caption | 311 | // Now paint the caption |
304 | p->save(); | 312 | p->save(); |
305 | QFont bFont = mView->headerFont(); | 313 | QFont bFont = mView->headerFont(); |
306 | //bFont.setBold(true); | 314 | //bFont.setBold(true); |
307 | p->setFont(bFont); | 315 | p->setFont(bFont); |
308 | if (isSelected()) | 316 | if (isSelected()) |
309 | p->setPen(cg.highlightedText()); | 317 | p->setPen(cg.highlightedText()); |
310 | else | 318 | else |
311 | p->setPen(cg.buttonText()); | 319 | p->setPen(cg.buttonText()); |
312 | p->drawText(2+mg, 2+mg + bFm.ascent()/*bFm.height()*//*-bFm.descent()*//*-bFm.leading()*/, trimString(d->mCaption, w-4, bFm)); | 320 | p->drawText(2+mg, 2+mg + bFm.ascent()/*bFm.height()*//*-bFm.descent()*//*-bFm.leading()*/, trimString(d->mCaption, w-4, bFm)); |
313 | p->restore(); | 321 | p->restore(); |
314 | 322 | ||
315 | // Go through the fields and draw them | 323 | // Go through the fields and draw them |
316 | QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); | 324 | Q3PtrListIterator< CardViewItem::Field > iter(d->mFieldList); |
317 | QString label, value; | 325 | QString label, value; |
318 | int yPos = mg + 4 + bFm.height()/* + 1*/ + fm.height(); // why the + 1 ??? (anders) | 326 | int yPos = mg + 4 + bFm.height()/* + 1*/ + fm.height(); // why the + 1 ??? (anders) |
319 | p->setPen(cg.text()); | 327 | p->setPen(cg.text()); |
320 | 328 | ||
321 | int fh = fm.height(); | 329 | int fh = fm.height(); |
322 | int cln( 0 ); | 330 | int cln( 0 ); |
323 | QString tmp; | 331 | QString tmp; |
324 | int maxLines = mView->maxFieldLines(); | 332 | int maxLines = mView->maxFieldLines(); |
325 | for (iter.toFirst(); iter.current(); ++iter) | 333 | for (iter.toFirst(); iter.current(); ++iter) |
326 | { | 334 | { |
327 | value = (*iter)->second; | 335 | value = (*iter)->second; |
328 | if ( value.isEmpty() && ! mView->d->mShowEmptyFields ) | 336 | if ( value.isEmpty() && ! mView->d->mShowEmptyFields ) |
329 | continue; | 337 | continue; |
330 | 338 | ||
331 | if (drawLabels) | 339 | if (drawLabels) |
332 | { | 340 | { |
333 | label = trimString((*iter)->first, labelWidth, fm); | 341 | label = trimString((*iter)->first, labelWidth, fm); |
334 | p->drawText(labelXPos, yPos, label + ":"); | 342 | p->drawText(labelXPos, yPos, label + ":"); |
335 | } | 343 | } |
336 | /* US original | 344 | /* US original |
337 | for (cln=0; cln <= maxLines; cln++) | 345 | for (cln=0; cln <= maxLines; cln++) |
338 | { | 346 | { |
339 | tmp = value.section('\n',cln,cln); | 347 | tmp = value.section('\n',cln,cln); |
340 | if ( !tmp.isEmpty() ) p->drawText( valueXPos, yPos + cln*fh, trimString( tmp, valueWidth, fm ) ); | 348 | if ( !tmp.isEmpty() ) p->drawText( valueXPos, yPos + cln*fh, trimString( tmp, valueWidth, fm ) ); |
341 | else break; | 349 | else break; |
342 | } | 350 | } |
343 | */ | 351 | */ |
344 | 352 | ||
345 | //US new implementation | 353 | //US new implementation |
346 | QStringList strlst = QStringList::split('\n', value, true); | 354 | QStringList strlst = QStringList::split('\n', value, true); |
347 | 355 | ||
348 | for (cln=0; cln <= maxLines && cln <= (int)strlst.count(); cln++) | 356 | for (cln=0; cln <= maxLines && cln <= (int)strlst.count(); cln++) |
@@ -379,107 +387,107 @@ void CardViewItem::paintCard(QPainter *p, QColorGroup &cg) | |||
379 | } | 387 | } |
380 | 388 | ||
381 | const QString &CardViewItem::caption() const | 389 | const QString &CardViewItem::caption() const |
382 | { | 390 | { |
383 | return d->mCaption; | 391 | return d->mCaption; |
384 | } | 392 | } |
385 | 393 | ||
386 | 394 | ||
387 | int CardViewItem::height( bool allowCache ) const | 395 | int CardViewItem::height( bool allowCache ) const |
388 | { | 396 | { |
389 | // use cache | 397 | // use cache |
390 | if ( allowCache && d->hcache ) | 398 | if ( allowCache && d->hcache ) |
391 | return d->hcache; | 399 | return d->hcache; |
392 | 400 | ||
393 | // Base height: | 401 | // Base height: |
394 | // 2 for line width | 402 | // 2 for line width |
395 | // 2 for top caption pad | 403 | // 2 for top caption pad |
396 | // 2 for bottom caption pad | 404 | // 2 for bottom caption pad |
397 | // 2 pad for the end | 405 | // 2 pad for the end |
398 | // + 2 times the advised margin | 406 | // + 2 times the advised margin |
399 | int baseHeight = 8 + ( 2 * mView->itemMargin() ); | 407 | int baseHeight = 8 + ( 2 * mView->itemMargin() ); |
400 | 408 | ||
401 | // size of font for each field | 409 | // size of font for each field |
402 | // 2 pad for each field | 410 | // 2 pad for each field |
403 | 411 | ||
404 | // anders: if the view does not show empty fields, check for value | 412 | // anders: if the view does not show empty fields, check for value |
405 | bool sef = mView->showEmptyFields(); | 413 | bool sef = mView->showEmptyFields(); |
406 | int fh = mView->d->mFm->height();//lineSpacing(); // font height | 414 | int fh = mView->d->mFm->height();//lineSpacing(); // font height |
407 | //int sp = QMAX( 0, 2- mView->d->mFm->leading() ); // field spacing NOTE make a property | 415 | //int sp = QMAX( 0, 2- mView->d->mFm->leading() ); // field spacing NOTE make a property |
408 | int fieldHeight = 0; | 416 | int fieldHeight = 0; |
409 | int lines; | 417 | int lines; |
410 | int maxLines( mView->maxFieldLines() ); | 418 | int maxLines( mView->maxFieldLines() ); |
411 | QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); | 419 | Q3PtrListIterator< CardViewItem::Field > iter(d->mFieldList); |
412 | for (iter.toFirst(); iter.current(); ++iter) | 420 | for (iter.toFirst(); iter.current(); ++iter) |
413 | { | 421 | { |
414 | if ( !sef && (*iter)->second.isEmpty() ) | 422 | if ( !sef && (*iter)->second.isEmpty() ) |
415 | continue; | 423 | continue; |
416 | lines = QMIN( (*iter)->second.contains('\n') + 1, maxLines ); | 424 | lines = QMIN( (*iter)->second.count('\n') + 1, maxLines ); |
417 | fieldHeight += ( lines * fh ) + 2;//sp; | 425 | fieldHeight += ( lines * fh ) + 2;//sp; |
418 | } | 426 | } |
419 | 427 | ||
420 | // height of caption font (bold) | 428 | // height of caption font (bold) |
421 | fieldHeight += mView->d->mBFm->height(); | 429 | fieldHeight += mView->d->mBFm->height(); |
422 | d->hcache = baseHeight + fieldHeight; | 430 | d->hcache = baseHeight + fieldHeight; |
423 | return d->hcache; | 431 | return d->hcache; |
424 | } | 432 | } |
425 | 433 | ||
426 | bool CardViewItem::isSelected() const | 434 | bool CardViewItem::isSelected() const |
427 | { | 435 | { |
428 | return d->mSelected; | 436 | return d->mSelected; |
429 | } | 437 | } |
430 | 438 | ||
431 | void CardViewItem::setSelected(bool selected) | 439 | void CardViewItem::setSelected(bool selected) |
432 | { | 440 | { |
433 | d->mSelected = selected; | 441 | d->mSelected = selected; |
434 | } | 442 | } |
435 | 443 | ||
436 | void CardViewItem::insertField(const QString &label, const QString &value) | 444 | void CardViewItem::insertField(const QString &label, const QString &value) |
437 | { | 445 | { |
438 | CardViewItem::Field *f = new CardViewItem::Field(label, value); | 446 | CardViewItem::Field *f = new CardViewItem::Field(label, value); |
439 | d->mFieldList.append(f); | 447 | d->mFieldList.append(f); |
440 | d->hcache=0; | 448 | d->hcache=0; |
441 | 449 | ||
442 | if (mView) | 450 | if (mView) |
443 | { | 451 | { |
444 | mView->setLayoutDirty(true); | 452 | mView->setLayoutDirty(true); |
445 | d->maxLabelWidth = QMAX( mView->d->mFm->width( label ), d->maxLabelWidth ); | 453 | d->maxLabelWidth = QMAX( mView->d->mFm->width( label ), d->maxLabelWidth ); |
446 | } | 454 | } |
447 | } | 455 | } |
448 | 456 | ||
449 | void CardViewItem::removeField(const QString &label) | 457 | void CardViewItem::removeField(const QString &label) |
450 | { | 458 | { |
451 | CardViewItem::Field *f; | 459 | CardViewItem::Field *f; |
452 | 460 | ||
453 | QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); | 461 | Q3PtrListIterator< CardViewItem::Field > iter(d->mFieldList); |
454 | for (iter.toFirst(); iter.current(); ++iter) | 462 | for (iter.toFirst(); iter.current(); ++iter) |
455 | { | 463 | { |
456 | f = *iter; | 464 | f = *iter; |
457 | if (f->first == label) | 465 | if (f->first == label) |
458 | break; | 466 | break; |
459 | } | 467 | } |
460 | 468 | ||
461 | if (*iter) | 469 | if (*iter) |
462 | d->mFieldList.remove(*iter); | 470 | d->mFieldList.remove(*iter); |
463 | d->hcache = 0; | 471 | d->hcache = 0; |
464 | 472 | ||
465 | if (mView) | 473 | if (mView) |
466 | mView->setLayoutDirty(true); | 474 | mView->setLayoutDirty(true); |
467 | } | 475 | } |
468 | 476 | ||
469 | void CardViewItem::clearFields() | 477 | void CardViewItem::clearFields() |
470 | { | 478 | { |
471 | d->mFieldList.clear(); | 479 | d->mFieldList.clear(); |
472 | d->hcache = 0; | 480 | d->hcache = 0; |
473 | 481 | ||
474 | if (mView) | 482 | if (mView) |
475 | mView->setLayoutDirty(true); | 483 | mView->setLayoutDirty(true); |
476 | } | 484 | } |
477 | 485 | ||
478 | QString CardViewItem::trimString(const QString &text, int width, | 486 | QString CardViewItem::trimString(const QString &text, int width, |
479 | QFontMetrics &fm) | 487 | QFontMetrics &fm) |
480 | { | 488 | { |
481 | if (fm.width(text) <= width) | 489 | if (fm.width(text) <= width) |
482 | return text; | 490 | return text; |
483 | 491 | ||
484 | QString dots = "..."; | 492 | QString dots = "..."; |
485 | int dotWidth = fm.width(dots); | 493 | int dotWidth = fm.width(dots); |
@@ -494,204 +502,204 @@ QString CardViewItem::trimString(const QString &text, int width, | |||
494 | 502 | ||
495 | // Now trim the last char, since it put the width over the top | 503 | // Now trim the last char, since it put the width over the top |
496 | trimmed = trimmed.left(trimmed.length()-1); | 504 | trimmed = trimmed.left(trimmed.length()-1); |
497 | trimmed += dots; | 505 | trimmed += dots; |
498 | 506 | ||
499 | return trimmed; | 507 | return trimmed; |
500 | } | 508 | } |
501 | 509 | ||
502 | CardViewItem *CardViewItem::nextItem() | 510 | CardViewItem *CardViewItem::nextItem() |
503 | { | 511 | { |
504 | CardViewItem *item = 0; | 512 | CardViewItem *item = 0; |
505 | 513 | ||
506 | if (mView) | 514 | if (mView) |
507 | item = mView->itemAfter(this); | 515 | item = mView->itemAfter(this); |
508 | 516 | ||
509 | return item; | 517 | return item; |
510 | } | 518 | } |
511 | 519 | ||
512 | void CardViewItem::repaintCard() | 520 | void CardViewItem::repaintCard() |
513 | { | 521 | { |
514 | if (mView) | 522 | if (mView) |
515 | mView->repaintItem(this); | 523 | mView->repaintItem(this); |
516 | } | 524 | } |
517 | 525 | ||
518 | void CardViewItem::setCaption(const QString &caption) | 526 | void CardViewItem::setCaption(const QString &caption) |
519 | { | 527 | { |
520 | d->mCaption = caption; | 528 | d->mCaption = caption; |
521 | repaintCard(); | 529 | repaintCard(); |
522 | } | 530 | } |
523 | 531 | ||
524 | QString CardViewItem::fieldValue(const QString &label) | 532 | QString CardViewItem::fieldValue(const QString &label) |
525 | { | 533 | { |
526 | QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); | 534 | Q3PtrListIterator< CardViewItem::Field > iter(d->mFieldList); |
527 | for (iter.toFirst(); iter.current(); ++iter) | 535 | for (iter.toFirst(); iter.current(); ++iter) |
528 | if ((*iter)->first == label) | 536 | if ((*iter)->first == label) |
529 | return (*iter)->second; | 537 | return (*iter)->second; |
530 | 538 | ||
531 | return QString(); | 539 | return QString(); |
532 | } | 540 | } |
533 | 541 | ||
534 | 542 | ||
535 | void CardViewItem::showFullString( const QPoint &itempos, CardViewTip *tip ) | 543 | void CardViewItem::showFullString( const QPoint &itempos, CardViewTip *tip ) |
536 | { | 544 | { |
537 | bool trimmed( false ); | 545 | bool trimmed( false ); |
538 | QString s; | 546 | QString s; |
539 | int mrg = mView->itemMargin(); | 547 | int mrg = mView->itemMargin(); |
540 | int y = mView->d->mBFm->height() + 6 + mrg; | 548 | int y = mView->d->mBFm->height() + 6 + mrg; |
541 | int w = mView->itemWidth() - (2*mrg); | 549 | int w = mView->itemWidth() - (2*mrg); |
542 | int lw; | 550 | int lw; |
543 | bool drawLabels = mView->drawFieldLabels(); | 551 | bool drawLabels = mView->drawFieldLabels(); |
544 | bool isLabel = drawLabels && itempos.x() < w/2 ? true : false; | 552 | bool isLabel = drawLabels && itempos.x() < w/2 ? true : false; |
545 | 553 | ||
546 | if ( itempos.y() < y ) | 554 | if ( itempos.y() < y ) |
547 | { | 555 | { |
548 | if ( itempos.y() < 8 + mrg || itempos.y() > y - 4 ) | 556 | if ( itempos.y() < 8 + mrg || itempos.y() > y - 4 ) |
549 | return; | 557 | return; |
550 | // this is the caption | 558 | // this is the caption |
551 | s = caption(); | 559 | s = caption(); |
552 | trimmed = mView->d->mBFm->width( s ) > w - 4; | 560 | trimmed = mView->d->mBFm->width( s ) > w - 4; |
553 | y = 2 + mrg; | 561 | y = 2 + mrg; |
554 | lw = 0; | 562 | lw = 0; |
555 | isLabel=true; | 563 | isLabel=true; |
556 | } else { | 564 | } else { |
557 | // find the field | 565 | // find the field |
558 | Field *f = fieldAt( itempos ); | 566 | Field *f = fieldAt( itempos ); |
559 | if ( !f || ( !mView->showEmptyFields() && f->second.isEmpty() ) ) | 567 | if ( !f || ( !mView->showEmptyFields() && f->second.isEmpty() ) ) |
560 | return; | 568 | return; |
561 | 569 | ||
562 | // y position: | 570 | // y position: |
563 | // header font height + 4px hader margin + 2px leading + item margin | 571 | // header font height + 4px hader margin + 2px leading + item margin |
564 | // + actual field index * (fontheight + 2px leading) | 572 | // + actual field index * (fontheight + 2px leading) |
565 | int maxLines = mView->maxFieldLines(); | 573 | int maxLines = mView->maxFieldLines(); |
566 | bool se = mView->showEmptyFields(); | 574 | bool se = mView->showEmptyFields(); |
567 | int fh = mView->d->mFm->height(); | 575 | int fh = mView->d->mFm->height(); |
568 | // { | 576 | // { |
569 | Field *_f; | 577 | Field *_f; |
570 | for (_f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next()) | 578 | for (_f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next()) |
571 | if ( se || ! _f->second.isEmpty() ) | 579 | if ( se || ! _f->second.isEmpty() ) |
572 | y += ( QMIN(_f->second.contains('\n')+1, maxLines) * fh ) + 2; | 580 | y += ( QMIN(_f->second.count('\n')+1, maxLines) * fh ) + 2; |
573 | // } | 581 | // } |
574 | if ( isLabel && itempos.y() > y + fh ) | 582 | if ( isLabel && itempos.y() > y + fh ) |
575 | return; | 583 | return; |
576 | // label or data? | 584 | // label or data? |
577 | s = isLabel ? f->first : f->second; | 585 | s = isLabel ? f->first : f->second; |
578 | // trimmed? | 586 | // trimmed? |
579 | int colonWidth = mView->d->mFm->width(":"); | 587 | int colonWidth = mView->d->mFm->width(":"); |
580 | lw = drawLabels ? // label width | 588 | lw = drawLabels ? // label width |
581 | QMIN( w/2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) : | 589 | QMIN( w/2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) : |
582 | 0; | 590 | 0; |
583 | int mw = isLabel ? lw - colonWidth : w - lw - (mrg*2); // max width for string | 591 | int mw = isLabel ? lw - colonWidth : w - lw - (mrg*2); // max width for string |
584 | if ( isLabel ) | 592 | if ( isLabel ) |
585 | { | 593 | { |
586 | trimmed = mView->d->mFm->width( s ) > mw - colonWidth; | 594 | trimmed = mView->d->mFm->width( s ) > mw - colonWidth; |
587 | } else { | 595 | } else { |
588 | QRect r( mView->d->mFm->boundingRect( 0, 0, INT_MAX, INT_MAX, Qt::AlignTop|Qt::AlignLeft, s ) ); | 596 | QRect r( mView->d->mFm->boundingRect( 0, 0, INT_MAX, INT_MAX, Qt::AlignTop|Qt::AlignLeft, s ) ); |
589 | trimmed = r.width() > mw || r.height()/fh > QMIN(s.contains('\n') + 1, maxLines); | 597 | trimmed = r.width() > mw || r.height()/fh > QMIN(s.count('\n') + 1, maxLines); |
590 | } | 598 | } |
591 | } | 599 | } |
592 | if ( trimmed ) | 600 | if ( trimmed ) |
593 | { | 601 | { |
594 | tip->setFont( (isLabel && !lw) ? mView->headerFont() : mView->font() ); // if condition is true, a header | 602 | tip->setFont( (isLabel && !lw) ? mView->headerFont() : mView->font() ); // if condition is true, a header |
595 | tip->setText( s ); | 603 | tip->setText( s ); |
596 | tip->adjustSize(); | 604 | tip->adjustSize(); |
597 | // find a proper position | 605 | // find a proper position |
598 | int lx; | 606 | int lx; |
599 | lx = isLabel || !drawLabels ? mrg : lw + mrg + 2 /*-1*/; | 607 | lx = isLabel || !drawLabels ? mrg : lw + mrg + 2 /*-1*/; |
600 | QPoint pnt(mView->contentsToViewport( QPoint(d->x, d->y) )); | 608 | QPoint pnt(mView->contentsToViewport( QPoint(d->x, d->y) )); |
601 | pnt += QPoint(lx, y); | 609 | pnt += QPoint(lx, y); |
602 | if ( pnt.x() < 0 ) | 610 | if ( pnt.x() < 0 ) |
603 | pnt.setX( 0 ); | 611 | pnt.setX( 0 ); |
604 | if ( pnt.x() + tip->width() > mView->visibleWidth() ) | 612 | if ( pnt.x() + tip->width() > mView->visibleWidth() ) |
605 | pnt.setX( mView->visibleWidth() - tip->width() ); | 613 | pnt.setX( mView->visibleWidth() - tip->width() ); |
606 | if ( pnt.y() + tip->height() > mView->visibleHeight() ) | 614 | if ( pnt.y() + tip->height() > mView->visibleHeight() ) |
607 | pnt.setY( QMAX( 0, mView->visibleHeight() - tip->height() ) ); | 615 | pnt.setY( QMAX( 0, mView->visibleHeight() - tip->height() ) ); |
608 | // show | 616 | // show |
609 | tip->move( pnt ); | 617 | tip->move( pnt ); |
610 | tip->show(); | 618 | tip->show(); |
611 | } | 619 | } |
612 | } | 620 | } |
613 | 621 | ||
614 | CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const | 622 | CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const |
615 | { | 623 | { |
616 | int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin; | 624 | int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin; |
617 | int iy = itempos.y(); | 625 | int iy = itempos.y(); |
618 | // skip below caption | 626 | // skip below caption |
619 | if ( iy <= ypos ) | 627 | if ( iy <= ypos ) |
620 | return 0; | 628 | return 0; |
621 | // try find a field | 629 | // try find a field |
622 | bool showEmpty = mView->showEmptyFields(); | 630 | bool showEmpty = mView->showEmptyFields(); |
623 | int fh = mView->d->mFm->height(); | 631 | int fh = mView->d->mFm->height(); |
624 | int maxLines = mView->maxFieldLines(); | 632 | int maxLines = mView->maxFieldLines(); |
625 | Field *f; | 633 | Field *f; |
626 | for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() ) | 634 | for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() ) |
627 | { | 635 | { |
628 | if ( showEmpty || !f->second.isEmpty() ) | 636 | if ( showEmpty || !f->second.isEmpty() ) |
629 | ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2; | 637 | ypos += ( QMIN( f->second.count('\n')+1, maxLines ) *fh)+2; |
630 | if ( iy <= ypos ) | 638 | if ( iy <= ypos ) |
631 | break; | 639 | break; |
632 | } | 640 | } |
633 | return f ? f : 0; | 641 | return f ? f : 0; |
634 | } | 642 | } |
635 | //END CardViewItem | 643 | //END CardViewItem |
636 | 644 | ||
637 | //BEGIN CardView | 645 | //BEGIN CardView |
638 | 646 | ||
639 | CardView::CardView(QWidget *parent, const char *name) | 647 | CardView::CardView(QWidget *parent, const char *name) |
640 | : QScrollView(parent, name), | 648 | : Q3ScrollView(parent, name), |
641 | d(new CardViewPrivate()) | 649 | d(new CardViewPrivate()) |
642 | { | 650 | { |
643 | mFlagKeyPressed = false; | 651 | mFlagKeyPressed = false; |
644 | mFlagBlockKeyPressed = false; | 652 | mFlagBlockKeyPressed = false; |
645 | d->mItemList.setAutoDelete(true); | 653 | d->mItemList.setAutoDelete(true); |
646 | d->mSeparatorList.setAutoDelete(true); | 654 | d->mSeparatorList.setAutoDelete(true); |
647 | 655 | ||
648 | QFont f = font(); | 656 | QFont f = font(); |
649 | d->mFm = new QFontMetrics(f); | 657 | d->mFm = new QFontMetrics(f); |
650 | f.setBold(true); | 658 | f.setBold(true); |
651 | d->mHeaderFont = f; | 659 | d->mHeaderFont = f; |
652 | d->mBFm = new QFontMetrics(f); | 660 | d->mBFm = new QFontMetrics(f); |
653 | d->mTip = ( new CardViewTip( viewport() ) ), | 661 | d->mTip = ( new CardViewTip( viewport() ) ), |
654 | d->mTip->hide(); | 662 | d->mTip->hide(); |
655 | d->mTimer = ( new QTimer(this, "mouseTimer") ), | 663 | d->mTimer = ( new QTimer(this, "mouseTimer") ), |
656 | 664 | ||
657 | viewport()->setMouseTracking( true ); | 665 | viewport()->setMouseTracking( true ); |
658 | viewport()->setFocusProxy(this); | 666 | viewport()->setFocusProxy(this); |
659 | viewport()->setFocusPolicy(WheelFocus); | 667 | viewport()->setFocusPolicy(Qt::WheelFocus); |
660 | viewport()->setBackgroundMode(PaletteBase); | 668 | viewport()->setBackgroundMode(Qt::PaletteBase); |
661 | 669 | ||
662 | connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) ); | 670 | connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) ); |
663 | 671 | ||
664 | //US setBackgroundMode(PaletteBackground, PaletteBase); | 672 | //US setBackgroundMode(PaletteBackground, PaletteBase); |
665 | setBackgroundMode(PaletteBackground); | 673 | setBackgroundMode(Qt::PaletteBackground); |
666 | 674 | ||
667 | // no reason for a vertical scrollbar | 675 | // no reason for a vertical scrollbar |
668 | setVScrollBarMode(AlwaysOff); | 676 | setVScrollBarMode(AlwaysOff); |
669 | } | 677 | } |
670 | 678 | ||
671 | CardView::~CardView() | 679 | CardView::~CardView() |
672 | { | 680 | { |
673 | delete d->mFm; | 681 | delete d->mFm; |
674 | delete d->mBFm; | 682 | delete d->mBFm; |
675 | delete d; | 683 | delete d; |
676 | d = 0; | 684 | d = 0; |
677 | } | 685 | } |
678 | 686 | ||
679 | void CardView::insertItem(CardViewItem *item) | 687 | void CardView::insertItem(CardViewItem *item) |
680 | { | 688 | { |
681 | d->mItemList.inSort(item); | 689 | d->mItemList.inSort(item); |
682 | setLayoutDirty(true); | 690 | setLayoutDirty(true); |
683 | } | 691 | } |
684 | 692 | ||
685 | void CardView::takeItem(CardViewItem *item) | 693 | void CardView::takeItem(CardViewItem *item) |
686 | { | 694 | { |
687 | if ( d->mCurrentItem == item ) | 695 | if ( d->mCurrentItem == item ) |
688 | d->mCurrentItem = item->nextItem(); | 696 | d->mCurrentItem = item->nextItem(); |
689 | d->mItemList.take(d->mItemList.findRef(item)); | 697 | d->mItemList.take(d->mItemList.findRef(item)); |
690 | 698 | ||
691 | setLayoutDirty(true); | 699 | setLayoutDirty(true); |
692 | } | 700 | } |
693 | 701 | ||
694 | void CardView::clear() | 702 | void CardView::clear() |
695 | { | 703 | { |
696 | d->mItemList.clear(); | 704 | d->mItemList.clear(); |
697 | 705 | ||
@@ -710,113 +718,113 @@ void CardView::setCurrentItem( CardViewItem *item ) | |||
710 | if ( !item ) | 718 | if ( !item ) |
711 | return; | 719 | return; |
712 | else if ( item->cardView() != this ) | 720 | else if ( item->cardView() != this ) |
713 | { | 721 | { |
714 | kdDebug(5720)<<"CardView::setCurrentItem: Item ("<<item<<") not owned! Backing out.."<<endl; | 722 | kdDebug(5720)<<"CardView::setCurrentItem: Item ("<<item<<") not owned! Backing out.."<<endl; |
715 | return; | 723 | return; |
716 | } | 724 | } |
717 | else if ( item == currentItem() ) | 725 | else if ( item == currentItem() ) |
718 | { | 726 | { |
719 | return; | 727 | return; |
720 | } | 728 | } |
721 | 729 | ||
722 | if ( d->mSelectionMode == Single ) | 730 | if ( d->mSelectionMode == Single ) |
723 | { | 731 | { |
724 | setSelected( item, true ); | 732 | setSelected( item, true ); |
725 | } | 733 | } |
726 | else | 734 | else |
727 | { | 735 | { |
728 | CardViewItem *it = d->mCurrentItem; | 736 | CardViewItem *it = d->mCurrentItem; |
729 | d->mCurrentItem = item; | 737 | d->mCurrentItem = item; |
730 | if ( it ) | 738 | if ( it ) |
731 | it->repaintCard(); | 739 | it->repaintCard(); |
732 | item->repaintCard(); | 740 | item->repaintCard(); |
733 | } | 741 | } |
734 | if ( ! d->mOnSeparator ) | 742 | if ( ! d->mOnSeparator ) |
735 | ensureItemVisible( item ); | 743 | ensureItemVisible( item ); |
736 | emit currentChanged( item ); | 744 | emit currentChanged( item ); |
737 | } | 745 | } |
738 | 746 | ||
739 | CardViewItem *CardView::itemAt(const QPoint &viewPos) | 747 | CardViewItem *CardView::itemAt(const QPoint &viewPos) |
740 | { | 748 | { |
741 | CardViewItem *item = 0; | 749 | CardViewItem *item = 0; |
742 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 750 | Q3PtrListIterator<CardViewItem> iter(d->mItemList); |
743 | bool found = false; | 751 | bool found = false; |
744 | for (iter.toFirst(); iter.current() && !found; ++iter) | 752 | for (iter.toFirst(); iter.current() && !found; ++iter) |
745 | { | 753 | { |
746 | item = *iter; | 754 | item = *iter; |
747 | //if (item->d->mRect.contains(viewPos)) | 755 | //if (item->d->mRect.contains(viewPos)) |
748 | if (QRect(item->d->x, item->d->y, d->mItemWidth, item->height()).contains(viewPos)) | 756 | if (QRect(item->d->x, item->d->y, d->mItemWidth, item->height()).contains(viewPos)) |
749 | found = true; | 757 | found = true; |
750 | } | 758 | } |
751 | 759 | ||
752 | if (found) | 760 | if (found) |
753 | return item; | 761 | return item; |
754 | 762 | ||
755 | return 0; | 763 | return 0; |
756 | } | 764 | } |
757 | 765 | ||
758 | QRect CardView::itemRect(const CardViewItem *item) | 766 | QRect CardView::itemRect(const CardViewItem *item) |
759 | { | 767 | { |
760 | //return item->d->mRect; | 768 | //return item->d->mRect; |
761 | return QRect(item->d->x, item->d->y, d->mItemWidth, item->height()); | 769 | return QRect(item->d->x, item->d->y, d->mItemWidth, item->height()); |
762 | } | 770 | } |
763 | 771 | ||
764 | void CardView::ensureItemVisible(const CardViewItem *item) | 772 | void CardView::ensureItemVisible(const CardViewItem *item) |
765 | { | 773 | { |
766 | ensureVisible(item->d->x , item->d->y, d->mItemSpacing, 0); | 774 | ensureVisible(item->d->x , item->d->y, d->mItemSpacing, 0); |
767 | ensureVisible(item->d->x + d->mItemWidth, item->d->y, d->mItemSpacing, 0); | 775 | ensureVisible(item->d->x + d->mItemWidth, item->d->y, d->mItemSpacing, 0); |
768 | } | 776 | } |
769 | 777 | ||
770 | void CardView::repaintItem(const CardViewItem *item) | 778 | void CardView::repaintItem(const CardViewItem *item) |
771 | { | 779 | { |
772 | //repaintContents(item->d->mRect); | 780 | //repaintContents(item->d->mRect); |
773 | repaintContents( QRect(item->d->x, item->d->y, d->mItemWidth, item->height()) ); | 781 | repaintContents( QRect(item->d->x, item->d->y, d->mItemWidth, item->height()) ); |
774 | } | 782 | } |
775 | 783 | ||
776 | void CardView::setSelectionMode(CardView::SelectionMode mode) | 784 | void CardView::setSelectionMode(CardView::SelectionMode mode) |
777 | { | 785 | { |
778 | selectAll(false); | 786 | selectAll(false); |
779 | 787 | ||
780 | d->mSelectionMode = mode; | 788 | d->mSelectionMode = mode; |
781 | } | 789 | } |
782 | 790 | ||
783 | CardView::SelectionMode CardView::selectionMode() const | 791 | CardView::SelectionMode CardView::selectionMode() const |
784 | { | 792 | { |
785 | return d->mSelectionMode; | 793 | return d->mSelectionMode; |
786 | } | 794 | } |
787 | 795 | ||
788 | void CardView::selectAll(bool state) | 796 | void CardView::selectAll(bool state) |
789 | { | 797 | { |
790 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 798 | Q3PtrListIterator<CardViewItem> iter(d->mItemList); |
791 | if (!state) | 799 | if (!state) |
792 | { | 800 | { |
793 | for (iter.toFirst(); iter.current(); ++iter) | 801 | for (iter.toFirst(); iter.current(); ++iter) |
794 | { | 802 | { |
795 | if ((*iter)->isSelected()) | 803 | if ((*iter)->isSelected()) |
796 | { | 804 | { |
797 | (*iter)->setSelected(false); | 805 | (*iter)->setSelected(false); |
798 | (*iter)->repaintCard(); | 806 | (*iter)->repaintCard(); |
799 | } | 807 | } |
800 | } | 808 | } |
801 | //emit selectionChanged(); // WARNING FIXME | 809 | //emit selectionChanged(); // WARNING FIXME |
802 | emit selectionChanged(0); | 810 | emit selectionChanged(0); |
803 | } | 811 | } |
804 | else if (d->mSelectionMode != CardView::Single) | 812 | else if (d->mSelectionMode != CardView::Single) |
805 | { | 813 | { |
806 | for (iter.toFirst(); iter.current(); ++iter) | 814 | for (iter.toFirst(); iter.current(); ++iter) |
807 | { | 815 | { |
808 | (*iter)->setSelected(true); | 816 | (*iter)->setSelected(true); |
809 | } | 817 | } |
810 | 818 | ||
811 | if (d->mItemList.count() > 0) | 819 | if (d->mItemList.count() > 0) |
812 | { | 820 | { |
813 | // emit, since there must have been at least one selected | 821 | // emit, since there must have been at least one selected |
814 | emit selectionChanged(); | 822 | emit selectionChanged(); |
815 | //repaint();//??? | 823 | //repaint();//??? |
816 | viewport()->update(); | 824 | viewport()->update(); |
817 | } | 825 | } |
818 | } | 826 | } |
819 | } | 827 | } |
820 | 828 | ||
821 | void CardView::setSelected(CardViewItem *item, bool selected) | 829 | void CardView::setSelected(CardViewItem *item, bool selected) |
822 | { | 830 | { |
@@ -849,65 +857,65 @@ void CardView::setSelected(CardViewItem *item, bool selected) | |||
849 | { | 857 | { |
850 | emit selectionChanged(); | 858 | emit selectionChanged(); |
851 | emit selectionChanged(0); | 859 | emit selectionChanged(0); |
852 | } | 860 | } |
853 | } | 861 | } |
854 | else if (d->mSelectionMode == CardView::Multi) | 862 | else if (d->mSelectionMode == CardView::Multi) |
855 | { | 863 | { |
856 | item->setSelected(selected); | 864 | item->setSelected(selected); |
857 | item->repaintCard(); | 865 | item->repaintCard(); |
858 | emit selectionChanged(); | 866 | emit selectionChanged(); |
859 | } | 867 | } |
860 | else if (d->mSelectionMode == CardView::Extended) | 868 | else if (d->mSelectionMode == CardView::Extended) |
861 | { | 869 | { |
862 | bool b = signalsBlocked(); | 870 | bool b = signalsBlocked(); |
863 | blockSignals(true); | 871 | blockSignals(true); |
864 | selectAll(false); | 872 | selectAll(false); |
865 | blockSignals(b); | 873 | blockSignals(b); |
866 | 874 | ||
867 | item->setSelected(selected); | 875 | item->setSelected(selected); |
868 | item->repaintCard(); | 876 | item->repaintCard(); |
869 | emit selectionChanged(); | 877 | emit selectionChanged(); |
870 | } | 878 | } |
871 | } | 879 | } |
872 | 880 | ||
873 | bool CardView::isSelected(CardViewItem *item) const | 881 | bool CardView::isSelected(CardViewItem *item) const |
874 | { | 882 | { |
875 | return (item && item->isSelected()); | 883 | return (item && item->isSelected()); |
876 | } | 884 | } |
877 | 885 | ||
878 | CardViewItem *CardView::selectedItem() const | 886 | CardViewItem *CardView::selectedItem() const |
879 | { | 887 | { |
880 | // find the first selected item | 888 | // find the first selected item |
881 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 889 | Q3PtrListIterator<CardViewItem> iter(d->mItemList); |
882 | for (iter.toFirst(); iter.current(); ++iter) | 890 | for (iter.toFirst(); iter.current(); ++iter) |
883 | { | 891 | { |
884 | if ((*iter)->isSelected()) | 892 | if ((*iter)->isSelected()) |
885 | return *iter; | 893 | return *iter; |
886 | } | 894 | } |
887 | 895 | ||
888 | return 0; | 896 | return 0; |
889 | } | 897 | } |
890 | 898 | ||
891 | CardViewItem *CardView::firstItem() const | 899 | CardViewItem *CardView::firstItem() const |
892 | { | 900 | { |
893 | return d->mItemList.first(); | 901 | return d->mItemList.first(); |
894 | } | 902 | } |
895 | 903 | ||
896 | int CardView::childCount() const | 904 | int CardView::childCount() const |
897 | { | 905 | { |
898 | return d->mItemList.count(); | 906 | return d->mItemList.count(); |
899 | } | 907 | } |
900 | /*US | 908 | /*US |
901 | CardViewItem *CardView::findItem(const QString &text, const QString &label, | 909 | CardViewItem *CardView::findItem(const QString &text, const QString &label, |
902 | Qt::StringComparisonMode compare) | 910 | Qt::StringComparisonMode compare) |
903 | { | 911 | { |
904 | // IF the text is empty, we will return null, since empty text will | 912 | // IF the text is empty, we will return null, since empty text will |
905 | // match anything! | 913 | // match anything! |
906 | if (text.isEmpty()) | 914 | if (text.isEmpty()) |
907 | return 0; | 915 | return 0; |
908 | 916 | ||
909 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 917 | QPtrListIterator<CardViewItem> iter(d->mItemList); |
910 | if (compare & Qt::BeginsWith) | 918 | if (compare & Qt::BeginsWith) |
911 | { | 919 | { |
912 | QString value; | 920 | QString value; |
913 | for (iter.toFirst(); iter.current(); ++iter) | 921 | for (iter.toFirst(); iter.current(); ++iter) |
@@ -926,211 +934,211 @@ CardViewItem *CardView::findItem(const QString &text, const QString &label, | |||
926 | } | 934 | } |
927 | */ | 935 | */ |
928 | 936 | ||
929 | uint CardView::columnWidth() | 937 | uint CardView::columnWidth() |
930 | { | 938 | { |
931 | return d->mDrawSeparators ? | 939 | return d->mDrawSeparators ? |
932 | d->mItemWidth + ( 2 * d->mItemSpacing ) + d->mSepWidth : | 940 | d->mItemWidth + ( 2 * d->mItemSpacing ) + d->mSepWidth : |
933 | d->mItemWidth + d->mItemSpacing; | 941 | d->mItemWidth + d->mItemSpacing; |
934 | } | 942 | } |
935 | 943 | ||
936 | void CardView::drawContents(QPainter *p, int clipx, int clipy, | 944 | void CardView::drawContents(QPainter *p, int clipx, int clipy, |
937 | int clipw, int cliph) | 945 | int clipw, int cliph) |
938 | { | 946 | { |
939 | //QScrollView::drawContents(p, clipx, clipy, clipw, cliph); | 947 | //QScrollView::drawContents(p, clipx, clipy, clipw, cliph); |
940 | if (d->mLayoutDirty) | 948 | if (d->mLayoutDirty) |
941 | calcLayout(); | 949 | calcLayout(); |
942 | 950 | ||
943 | //kdDebug() << "CardView::drawContents: " << clipx << ", " << clipy | 951 | //kdDebug() << "CardView::drawContents: " << clipx << ", " << clipy |
944 | // << ", " << clipw << ", " << cliph << endl; | 952 | // << ", " << clipw << ", " << cliph << endl; |
945 | 953 | ||
946 | QColorGroup cg = viewport()->palette().active(); // allow setting costum colors in the viewport pale | 954 | QColorGroup cg = viewport()->palette().active(); // allow setting costum colors in the viewport pale |
947 | int cX, cY; | 955 | int cX, cY; |
948 | contentsToViewport ( clipx, clipy, cX, cY ); | 956 | contentsToViewport ( clipx, clipy, cX, cY ); |
949 | QRect clipRect(clipx, clipy, clipw, cliph); | 957 | QRect clipRect(clipx, clipy, clipw, cliph); |
950 | QRect cardRect; | 958 | QRect cardRect; |
951 | QRect sepRect; | 959 | QRect sepRect; |
952 | CardViewItem *item; | 960 | CardViewItem *item; |
953 | CardViewSeparator *sep; | 961 | CardViewSeparator *sep; |
954 | // make sure the viewport is a pure background | 962 | // make sure the viewport is a pure background |
955 | viewport()->erase( QRect ( cX, cY , clipw, cliph ) ); | 963 | viewport()->erase( QRect ( cX, cY , clipw, cliph ) ); |
956 | 964 | ||
957 | // Now tell the cards to draw, if they are in the clip region | 965 | // Now tell the cards to draw, if they are in the clip region |
958 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 966 | Q3PtrListIterator<CardViewItem> iter(d->mItemList); |
959 | for (iter.toFirst(); iter.current(); ++iter) | 967 | for (iter.toFirst(); iter.current(); ++iter) |
960 | { | 968 | { |
961 | item = *iter; | 969 | item = *iter; |
962 | cardRect.setRect( item->d->x, item->d->y, d->mItemWidth, item->height() ); | 970 | cardRect.setRect( item->d->x, item->d->y, d->mItemWidth, item->height() ); |
963 | 971 | ||
964 | if (clipRect.intersects(cardRect) || clipRect.contains(cardRect)) | 972 | if (clipRect.intersects(cardRect) || clipRect.contains(cardRect)) |
965 | { | 973 | { |
966 | //kdDebug() << "\trepainting card at: " << cardRect.x() << ", " | 974 | //kdDebug() << "\trepainting card at: " << cardRect.x() << ", " |
967 | // << cardRect.y() << endl; | 975 | // << cardRect.y() << endl; |
968 | 976 | ||
969 | // Tell the card to paint | 977 | // Tell the card to paint |
970 | p->save(); | 978 | p->save(); |
971 | p->translate(cardRect.x(), cardRect.y()); | 979 | p->translate(cardRect.x(), cardRect.y()); |
972 | item->paintCard(p, cg); | 980 | item->paintCard(p, cg); |
973 | p->restore(); | 981 | p->restore(); |
974 | } | 982 | } |
975 | } | 983 | } |
976 | 984 | ||
977 | // Followed by the separators if they are in the clip region | 985 | // Followed by the separators if they are in the clip region |
978 | QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList); | 986 | Q3PtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList); |
979 | for (sepIter.toFirst(); sepIter.current(); ++sepIter) | 987 | for (sepIter.toFirst(); sepIter.current(); ++sepIter) |
980 | { | 988 | { |
981 | sep = *sepIter; | 989 | sep = *sepIter; |
982 | sepRect = sep->mRect; | 990 | sepRect = sep->mRect; |
983 | 991 | ||
984 | if (clipRect.intersects(sepRect) || clipRect.contains(sepRect)) | 992 | if (clipRect.intersects(sepRect) || clipRect.contains(sepRect)) |
985 | { | 993 | { |
986 | p->save(); | 994 | p->save(); |
987 | p->translate(sepRect.x(), sepRect.y()); | 995 | p->translate(sepRect.x(), sepRect.y()); |
988 | sep->paintSeparator(p, cg); | 996 | sep->paintSeparator(p, cg); |
989 | p->restore(); | 997 | p->restore(); |
990 | } | 998 | } |
991 | } | 999 | } |
992 | } | 1000 | } |
993 | 1001 | ||
994 | void CardView::resizeEvent(QResizeEvent *e) | 1002 | void CardView::resizeEvent(QResizeEvent *e) |
995 | { | 1003 | { |
996 | QScrollView::resizeEvent(e); | 1004 | Q3ScrollView::resizeEvent(e); |
997 | 1005 | ||
998 | setLayoutDirty(true); | 1006 | setLayoutDirty(true); |
999 | } | 1007 | } |
1000 | 1008 | ||
1001 | void CardView::calcLayout() | 1009 | void CardView::calcLayout() |
1002 | { | 1010 | { |
1003 | //kdDebug() << "CardView::calcLayout:" << endl; | 1011 | //kdDebug() << "CardView::calcLayout:" << endl; |
1004 | 1012 | ||
1005 | // Start in the upper left corner and layout all the | 1013 | // Start in the upper left corner and layout all the |
1006 | // cars using their height and width | 1014 | // cars using their height and width |
1007 | int maxWidth = 0; | 1015 | int maxWidth = 0; |
1008 | int maxHeight = 0; | 1016 | int maxHeight = 0; |
1009 | int xPos = 0; | 1017 | int xPos = 0; |
1010 | int yPos = 0; | 1018 | int yPos = 0; |
1011 | int cardSpacing = d->mItemSpacing; | 1019 | int cardSpacing = d->mItemSpacing; |
1012 | 1020 | ||
1013 | // delete the old separators | 1021 | // delete the old separators |
1014 | d->mSeparatorList.clear(); | 1022 | d->mSeparatorList.clear(); |
1015 | 1023 | ||
1016 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 1024 | Q3PtrListIterator<CardViewItem> iter(d->mItemList); |
1017 | CardViewItem *item = 0; | 1025 | CardViewItem *item = 0; |
1018 | CardViewSeparator *sep = 0; | 1026 | CardViewSeparator *sep = 0; |
1019 | xPos += cardSpacing; | 1027 | xPos += cardSpacing; |
1020 | 1028 | ||
1021 | for (iter.toFirst(); iter.current(); ++iter) | 1029 | for (iter.toFirst(); iter.current(); ++iter) |
1022 | { | 1030 | { |
1023 | item = *iter; | 1031 | item = *iter; |
1024 | 1032 | ||
1025 | yPos += cardSpacing; | 1033 | yPos += cardSpacing; |
1026 | 1034 | ||
1027 | if (yPos + item->height() + cardSpacing >= height() - horizontalScrollBar()->height()) | 1035 | if (yPos + item->height() + cardSpacing >= height() - horizontalScrollBar()->height()) |
1028 | { | 1036 | { |
1029 | maxHeight = QMAX(maxHeight, yPos); | 1037 | maxHeight = QMAX(maxHeight, yPos); |
1030 | 1038 | ||
1031 | // Drawing in this column would be greater than the height | 1039 | // Drawing in this column would be greater than the height |
1032 | // of the scroll view, so move to next column | 1040 | // of the scroll view, so move to next column |
1033 | yPos = cardSpacing; | 1041 | yPos = cardSpacing; |
1034 | xPos += cardSpacing + maxWidth; | 1042 | xPos += cardSpacing + maxWidth; |
1035 | if (d->mDrawSeparators) | 1043 | if (d->mDrawSeparators) |
1036 | { | 1044 | { |
1037 | // Create a separator since the user asked | 1045 | // Create a separator since the user asked |
1038 | sep = new CardViewSeparator(this); | 1046 | sep = new CardViewSeparator(this); |
1039 | sep->mRect.moveTopLeft(QPoint(xPos, yPos+d->mItemMargin)); | 1047 | sep->mRect.moveTopLeft(QPoint(xPos, yPos+d->mItemMargin)); |
1040 | xPos += d->mSepWidth + cardSpacing; | 1048 | xPos += d->mSepWidth + cardSpacing; |
1041 | d->mSeparatorList.append(sep); | 1049 | d->mSeparatorList.append(sep); |
1042 | } | 1050 | } |
1043 | 1051 | ||
1044 | maxWidth = 0; | 1052 | maxWidth = 0; |
1045 | } | 1053 | } |
1046 | 1054 | ||
1047 | item->d->x = xPos; | 1055 | item->d->x = xPos; |
1048 | item->d->y = yPos; | 1056 | item->d->y = yPos; |
1049 | 1057 | ||
1050 | yPos += item->height(); | 1058 | yPos += item->height(); |
1051 | maxWidth = QMAX(maxWidth, d->mItemWidth); | 1059 | maxWidth = QMAX(maxWidth, d->mItemWidth); |
1052 | } | 1060 | } |
1053 | 1061 | ||
1054 | xPos += maxWidth; | 1062 | xPos += maxWidth; |
1055 | resizeContents( xPos + cardSpacing, maxHeight ); | 1063 | resizeContents( xPos + cardSpacing, maxHeight ); |
1056 | 1064 | ||
1057 | // Update the height of all the separators now that we know the | 1065 | // Update the height of all the separators now that we know the |
1058 | // max height of a column | 1066 | // max height of a column |
1059 | QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList); | 1067 | Q3PtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList); |
1060 | for (sepIter.toFirst(); sepIter.current(); ++sepIter) | 1068 | for (sepIter.toFirst(); sepIter.current(); ++sepIter) |
1061 | { | 1069 | { |
1062 | (*sepIter)->mRect.setHeight(maxHeight - 2*cardSpacing - 2*d->mItemMargin); | 1070 | (*sepIter)->mRect.setHeight(maxHeight - 2*cardSpacing - 2*d->mItemMargin); |
1063 | } | 1071 | } |
1064 | 1072 | ||
1065 | d->mLayoutDirty = false; | 1073 | d->mLayoutDirty = false; |
1066 | } | 1074 | } |
1067 | 1075 | ||
1068 | CardViewItem *CardView::itemAfter(CardViewItem *item) | 1076 | CardViewItem *CardView::itemAfter(CardViewItem *item) |
1069 | { | 1077 | { |
1070 | /*int pos = */d->mItemList.findRef(item); | 1078 | /*int pos = */d->mItemList.findRef(item); |
1071 | return d->mItemList.next();//at(pos+1); | 1079 | return d->mItemList.next();//at(pos+1); |
1072 | } | 1080 | } |
1073 | 1081 | ||
1074 | uint CardView::itemMargin() | 1082 | uint CardView::itemMargin() |
1075 | { | 1083 | { |
1076 | return d->mItemMargin; | 1084 | return d->mItemMargin; |
1077 | } | 1085 | } |
1078 | 1086 | ||
1079 | void CardView::setItemMargin( uint margin ) | 1087 | void CardView::setItemMargin( uint margin ) |
1080 | { | 1088 | { |
1081 | if ( margin == d->mItemMargin ) | 1089 | if ( margin == d->mItemMargin ) |
1082 | return; | 1090 | return; |
1083 | 1091 | ||
1084 | d->mItemMargin = margin; | 1092 | d->mItemMargin = margin; |
1085 | setLayoutDirty( true ); | 1093 | setLayoutDirty( true ); |
1086 | } | 1094 | } |
1087 | 1095 | ||
1088 | uint CardView::itemSpacing() | 1096 | uint CardView::itemSpacing() |
1089 | { | 1097 | { |
1090 | return d->mItemSpacing; | 1098 | return d->mItemSpacing; |
1091 | } | 1099 | } |
1092 | 1100 | ||
1093 | void CardView::setItemSpacing( uint spacing ) | 1101 | void CardView::setItemSpacing( uint spacing ) |
1094 | { | 1102 | { |
1095 | if ( spacing == d->mItemSpacing ) | 1103 | if ( spacing == d->mItemSpacing ) |
1096 | return; | 1104 | return; |
1097 | 1105 | ||
1098 | d->mItemSpacing = spacing; | 1106 | d->mItemSpacing = spacing; |
1099 | setLayoutDirty( true ); | 1107 | setLayoutDirty( true ); |
1100 | } | 1108 | } |
1101 | 1109 | ||
1102 | void CardView::contentsMousePressEvent(QMouseEvent *e) | 1110 | void CardView::contentsMousePressEvent(QMouseEvent *e) |
1103 | { | 1111 | { |
1104 | QScrollView::contentsMousePressEvent(e); | 1112 | Q3ScrollView::contentsMousePressEvent(e); |
1105 | 1113 | ||
1106 | QPoint pos = e->pos(); | 1114 | QPoint pos = e->pos(); |
1107 | d->mLastClickPos = pos; | 1115 | d->mLastClickPos = pos; |
1108 | 1116 | ||
1109 | CardViewItem *item = itemAt(pos); | 1117 | CardViewItem *item = itemAt(pos); |
1110 | 1118 | ||
1111 | if (item == 0) | 1119 | if (item == 0) |
1112 | { | 1120 | { |
1113 | d->mLastClickOnItem = false; | 1121 | d->mLastClickOnItem = false; |
1114 | if ( d->mOnSeparator) | 1122 | if ( d->mOnSeparator) |
1115 | { | 1123 | { |
1116 | d->mResizeAnchor = e->x()+contentsX(); | 1124 | d->mResizeAnchor = e->x()+contentsX(); |
1117 | d->colspace = (2*d->mItemSpacing) /*+ (2*d->mItemMargin)*/; | 1125 | d->colspace = (2*d->mItemSpacing) /*+ (2*d->mItemMargin)*/; |
1118 | int ccw = d->mItemWidth + d->colspace + d->mSepWidth; | 1126 | int ccw = d->mItemWidth + d->colspace + d->mSepWidth; |
1119 | d->first = (contentsX()+d->mSepWidth)/ccw; | 1127 | d->first = (contentsX()+d->mSepWidth)/ccw; |
1120 | d->pressed = (d->mResizeAnchor+d->mSepWidth)/ccw; | 1128 | d->pressed = (d->mResizeAnchor+d->mSepWidth)/ccw; |
1121 | d->span = d->pressed - d->first; | 1129 | d->span = d->pressed - d->first; |
1122 | d->firstX = d->first * ccw; | 1130 | d->firstX = d->first * ccw; |
1123 | if ( d->firstX ) d->firstX -= d->mSepWidth; // (no sep in col 0) | 1131 | if ( d->firstX ) d->firstX -= d->mSepWidth; // (no sep in col 0) |
1124 | } | 1132 | } |
1125 | else | 1133 | else |
1126 | { | 1134 | { |
1127 | selectAll(false); | 1135 | selectAll(false); |
1128 | } | 1136 | } |
1129 | return; | 1137 | return; |
1130 | } | 1138 | } |
1131 | 1139 | ||
1132 | d->mLastClickOnItem = true; | 1140 | d->mLastClickOnItem = true; |
1133 | 1141 | ||
1134 | CardViewItem *other = d->mCurrentItem; | 1142 | CardViewItem *other = d->mCurrentItem; |
1135 | setCurrentItem( item ); | 1143 | setCurrentItem( item ); |
1136 | 1144 | ||
@@ -1142,413 +1150,413 @@ void CardView::contentsMousePressEvent(QMouseEvent *e) | |||
1142 | { | 1150 | { |
1143 | // make sure it isn't already selected | 1151 | // make sure it isn't already selected |
1144 | if (item->isSelected()) | 1152 | if (item->isSelected()) |
1145 | return; | 1153 | return; |
1146 | 1154 | ||
1147 | bool b = signalsBlocked(); | 1155 | bool b = signalsBlocked(); |
1148 | blockSignals(true); | 1156 | blockSignals(true); |
1149 | selectAll(false); | 1157 | selectAll(false); |
1150 | blockSignals(b); | 1158 | blockSignals(b); |
1151 | 1159 | ||
1152 | item->setSelected(true); | 1160 | item->setSelected(true); |
1153 | item->repaintCard(); | 1161 | item->repaintCard(); |
1154 | emit selectionChanged(item); | 1162 | emit selectionChanged(item); |
1155 | } | 1163 | } |
1156 | 1164 | ||
1157 | else if (d->mSelectionMode == CardView::Multi) | 1165 | else if (d->mSelectionMode == CardView::Multi) |
1158 | { | 1166 | { |
1159 | // toggle the selection | 1167 | // toggle the selection |
1160 | item->setSelected(!item->isSelected()); | 1168 | item->setSelected(!item->isSelected()); |
1161 | item->repaintCard(); | 1169 | item->repaintCard(); |
1162 | emit selectionChanged(); | 1170 | emit selectionChanged(); |
1163 | } | 1171 | } |
1164 | 1172 | ||
1165 | else if (d->mSelectionMode == CardView::Extended) | 1173 | else if (d->mSelectionMode == CardView::Extended) |
1166 | { | 1174 | { |
1167 | if ((e->button() & Qt::LeftButton) && | 1175 | if ((e->button() & Qt::LeftButton) && |
1168 | (e->state() & Qt::ShiftButton)) | 1176 | (e->state() & Qt::ShiftButton)) |
1169 | { | 1177 | { |
1170 | if ( item == other ) return; | 1178 | if ( item == other ) return; |
1171 | 1179 | ||
1172 | bool s = ! item->isSelected(); | 1180 | bool s = ! item->isSelected(); |
1173 | 1181 | ||
1174 | if ( s && ! (e->state() & ControlButton) ) | 1182 | if ( s && ! (e->state() & Qt::ControlButton) ) |
1175 | { | 1183 | { |
1176 | bool b = signalsBlocked(); | 1184 | bool b = signalsBlocked(); |
1177 | blockSignals(true); | 1185 | blockSignals(true); |
1178 | selectAll(false); | 1186 | selectAll(false); |
1179 | blockSignals(b); | 1187 | blockSignals(b); |
1180 | } | 1188 | } |
1181 | 1189 | ||
1182 | int from, to, a, b; | 1190 | int from, to, a, b; |
1183 | a = d->mItemList.findRef( item ); | 1191 | a = d->mItemList.findRef( item ); |
1184 | b = d->mItemList.findRef( other ); | 1192 | b = d->mItemList.findRef( other ); |
1185 | from = a < b ? a : b; | 1193 | from = a < b ? a : b; |
1186 | to = a > b ? a : b; | 1194 | to = a > b ? a : b; |
1187 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; | 1195 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; |
1188 | CardViewItem *aItem; | 1196 | CardViewItem *aItem; |
1189 | for ( ; from <= to; from++ ) | 1197 | for ( ; from <= to; from++ ) |
1190 | { | 1198 | { |
1191 | aItem = d->mItemList.at( from ); | 1199 | aItem = d->mItemList.at( from ); |
1192 | aItem->setSelected( s ); | 1200 | aItem->setSelected( s ); |
1193 | repaintItem( aItem ); | 1201 | repaintItem( aItem ); |
1194 | } | 1202 | } |
1195 | emit selectionChanged(); | 1203 | emit selectionChanged(); |
1196 | } | 1204 | } |
1197 | else if ((e->button() & Qt::LeftButton) && | 1205 | else if ((e->button() & Qt::LeftButton) && |
1198 | (e->state() & Qt::ControlButton)) | 1206 | (e->state() & Qt::ControlButton)) |
1199 | { | 1207 | { |
1200 | item->setSelected(!item->isSelected()); | 1208 | item->setSelected(!item->isSelected()); |
1201 | item->repaintCard(); | 1209 | item->repaintCard(); |
1202 | emit selectionChanged(); | 1210 | emit selectionChanged(); |
1203 | } | 1211 | } |
1204 | 1212 | ||
1205 | else if (e->button() & Qt::LeftButton) | 1213 | else if (e->button() & Qt::LeftButton) |
1206 | { | 1214 | { |
1207 | bool b = signalsBlocked(); | 1215 | bool b = signalsBlocked(); |
1208 | blockSignals(true); | 1216 | blockSignals(true); |
1209 | selectAll(false); | 1217 | selectAll(false); |
1210 | blockSignals(b); | 1218 | blockSignals(b); |
1211 | 1219 | ||
1212 | item->setSelected(true); | 1220 | item->setSelected(true); |
1213 | item->repaintCard(); | 1221 | item->repaintCard(); |
1214 | emit selectionChanged(); | 1222 | emit selectionChanged(); |
1215 | } | 1223 | } |
1216 | } | 1224 | } |
1217 | 1225 | ||
1218 | } | 1226 | } |
1219 | 1227 | ||
1220 | void CardView::contentsMouseReleaseEvent(QMouseEvent *e) | 1228 | void CardView::contentsMouseReleaseEvent(QMouseEvent *e) |
1221 | { | 1229 | { |
1222 | QScrollView::contentsMouseReleaseEvent(e); | 1230 | Q3ScrollView::contentsMouseReleaseEvent(e); |
1223 | 1231 | ||
1224 | if ( d->mResizeAnchor ) | 1232 | if ( d->mResizeAnchor ) |
1225 | { | 1233 | { |
1226 | // finish the resizing: | 1234 | // finish the resizing: |
1227 | unsetCursor(); | 1235 | unsetCursor(); |
1228 | // hide rubber bands | 1236 | // hide rubber bands |
1229 | int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor)/d->span); | 1237 | int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor)/d->span); |
1230 | drawRubberBands( 0 ); | 1238 | drawRubberBands( 0 ); |
1231 | // we should move to reflect the new position if we are scrolled. | 1239 | // we should move to reflect the new position if we are scrolled. |
1232 | if ( contentsX() ) | 1240 | if ( contentsX() ) |
1233 | { | 1241 | { |
1234 | int newX = QMAX( 0, ( d->pressed * ( newiw + d->colspace + d->mSepWidth ) ) - e->x() ); | 1242 | int newX = QMAX( 0, ( d->pressed * ( newiw + d->colspace + d->mSepWidth ) ) - e->x() ); |
1235 | setContentsPos( newX, contentsY() ); | 1243 | setContentsPos( newX, contentsY() ); |
1236 | } | 1244 | } |
1237 | // set new item width | 1245 | // set new item width |
1238 | setItemWidth( newiw ); | 1246 | setItemWidth( newiw ); |
1239 | // reset anchors | 1247 | // reset anchors |
1240 | d->mResizeAnchor = 0; | 1248 | d->mResizeAnchor = 0; |
1241 | d->mRubberBandAnchor = 0; | 1249 | d->mRubberBandAnchor = 0; |
1242 | return; | 1250 | return; |
1243 | } | 1251 | } |
1244 | 1252 | ||
1245 | // If there are accel keys, we will not emit signals | 1253 | // If there are accel keys, we will not emit signals |
1246 | if ((e->state() & Qt::ShiftButton) || (e->state() & Qt::ControlButton)) | 1254 | if ((e->state() & Qt::ShiftButton) || (e->state() & Qt::ControlButton)) |
1247 | return; | 1255 | return; |
1248 | 1256 | ||
1249 | // Get the item at this position | 1257 | // Get the item at this position |
1250 | CardViewItem *item = itemAt(e->pos()); | 1258 | CardViewItem *item = itemAt(e->pos()); |
1251 | 1259 | ||
1252 | if (item && KABPrefs::instance()->mHonorSingleClick) | 1260 | if (item && KABPrefs::instance()->mHonorSingleClick) |
1253 | { | 1261 | { |
1254 | emit executed(item); | 1262 | emit executed(item); |
1255 | } | 1263 | } |
1256 | } | 1264 | } |
1257 | 1265 | ||
1258 | void CardView::contentsMouseDoubleClickEvent(QMouseEvent *e) | 1266 | void CardView::contentsMouseDoubleClickEvent(QMouseEvent *e) |
1259 | { | 1267 | { |
1260 | QScrollView::contentsMouseDoubleClickEvent(e); | 1268 | Q3ScrollView::contentsMouseDoubleClickEvent(e); |
1261 | 1269 | ||
1262 | CardViewItem *item = itemAt(e->pos()); | 1270 | CardViewItem *item = itemAt(e->pos()); |
1263 | 1271 | ||
1264 | if (item) | 1272 | if (item) |
1265 | { | 1273 | { |
1266 | d->mCurrentItem = item; | 1274 | d->mCurrentItem = item; |
1267 | } | 1275 | } |
1268 | 1276 | ||
1269 | if (item && !KABPrefs::instance()->mHonorSingleClick) | 1277 | if (item && !KABPrefs::instance()->mHonorSingleClick) |
1270 | { | 1278 | { |
1271 | emit executed(item); | 1279 | emit executed(item); |
1272 | } else | 1280 | } else |
1273 | emit doubleClicked(item); | 1281 | emit doubleClicked(item); |
1274 | } | 1282 | } |
1275 | 1283 | ||
1276 | void CardView::contentsMouseMoveEvent( QMouseEvent *e ) | 1284 | void CardView::contentsMouseMoveEvent( QMouseEvent *e ) |
1277 | { | 1285 | { |
1278 | // resizing | 1286 | // resizing |
1279 | if ( d->mResizeAnchor ) | 1287 | if ( d->mResizeAnchor ) |
1280 | { | 1288 | { |
1281 | int x = e->x(); | 1289 | int x = e->x(); |
1282 | if ( x != d->mRubberBandAnchor ) | 1290 | if ( x != d->mRubberBandAnchor ) |
1283 | drawRubberBands( x ); | 1291 | drawRubberBands( x ); |
1284 | return; | 1292 | return; |
1285 | } | 1293 | } |
1286 | 1294 | ||
1287 | if (d->mLastClickOnItem && (e->state() & Qt::LeftButton) && | 1295 | if (d->mLastClickOnItem && (e->state() & Qt::LeftButton) && |
1288 | ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) { | 1296 | ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) { |
1289 | 1297 | ||
1290 | startDrag(); | 1298 | startDrag(); |
1291 | return; | 1299 | return; |
1292 | } | 1300 | } |
1293 | 1301 | ||
1294 | d->mTimer->start( 500 ); | 1302 | d->mTimer->start( 500 ); |
1295 | 1303 | ||
1296 | // see if we are over a separator | 1304 | // see if we are over a separator |
1297 | // only if we actually have them painted? | 1305 | // only if we actually have them painted? |
1298 | if ( d->mDrawSeparators ) | 1306 | if ( d->mDrawSeparators ) |
1299 | { | 1307 | { |
1300 | int colcontentw = d->mItemWidth + (2*d->mItemSpacing); | 1308 | int colcontentw = d->mItemWidth + (2*d->mItemSpacing); |
1301 | int colw = colcontentw + d->mSepWidth; | 1309 | int colw = colcontentw + d->mSepWidth; |
1302 | int m = e->x()%colw; | 1310 | int m = e->x()%colw; |
1303 | if ( m >= colcontentw && m > 0 ) | 1311 | if ( m >= colcontentw && m > 0 ) |
1304 | { | 1312 | { |
1305 | setCursor( SplitVCursor ); // Why does this fail sometimes? | 1313 | setCursor( Qt::SplitVCursor ); // Why does this fail sometimes? |
1306 | d->mOnSeparator = true; | 1314 | d->mOnSeparator = true; |
1307 | } | 1315 | } |
1308 | else | 1316 | else |
1309 | { | 1317 | { |
1310 | setCursor( ArrowCursor ); | 1318 | setCursor( Qt::ArrowCursor ); |
1311 | d->mOnSeparator = false; | 1319 | d->mOnSeparator = false; |
1312 | } | 1320 | } |
1313 | } | 1321 | } |
1314 | } | 1322 | } |
1315 | 1323 | ||
1316 | void CardView::enterEvent( QEvent * ) | 1324 | void CardView::enterEvent( QEvent * ) |
1317 | { | 1325 | { |
1318 | d->mTimer->start( 500 ); | 1326 | d->mTimer->start( 500 ); |
1319 | } | 1327 | } |
1320 | 1328 | ||
1321 | void CardView::leaveEvent( QEvent * ) | 1329 | void CardView::leaveEvent( QEvent * ) |
1322 | { | 1330 | { |
1323 | d->mTimer->stop(); | 1331 | d->mTimer->stop(); |
1324 | if (d->mOnSeparator) | 1332 | if (d->mOnSeparator) |
1325 | { | 1333 | { |
1326 | d->mOnSeparator = false; | 1334 | d->mOnSeparator = false; |
1327 | setCursor( ArrowCursor ); | 1335 | setCursor( Qt::ArrowCursor ); |
1328 | } | 1336 | } |
1329 | } | 1337 | } |
1330 | 1338 | ||
1331 | void CardView::focusInEvent( QFocusEvent * ) | 1339 | void CardView::focusInEvent( QFocusEvent * ) |
1332 | { | 1340 | { |
1333 | if (!d->mCurrentItem && d->mItemList.count() ) | 1341 | if (!d->mCurrentItem && d->mItemList.count() ) |
1334 | { | 1342 | { |
1335 | setCurrentItem( d->mItemList.first() ); | 1343 | setCurrentItem( d->mItemList.first() ); |
1336 | } | 1344 | } |
1337 | else if ( d->mCurrentItem ) | 1345 | else if ( d->mCurrentItem ) |
1338 | { | 1346 | { |
1339 | d->mCurrentItem->repaintCard(); | 1347 | d->mCurrentItem->repaintCard(); |
1340 | } | 1348 | } |
1341 | } | 1349 | } |
1342 | 1350 | ||
1343 | void CardView::focusOutEvent( QFocusEvent * ) | 1351 | void CardView::focusOutEvent( QFocusEvent * ) |
1344 | { | 1352 | { |
1345 | if (d->mCurrentItem) | 1353 | if (d->mCurrentItem) |
1346 | d->mCurrentItem->repaintCard(); | 1354 | d->mCurrentItem->repaintCard(); |
1347 | } | 1355 | } |
1348 | 1356 | ||
1349 | void CardView::keyPressEvent( QKeyEvent *e ) | 1357 | void CardView::keyPressEvent( QKeyEvent *e ) |
1350 | { | 1358 | { |
1351 | if ( ! ( childCount() && d->mCurrentItem ) ) | 1359 | if ( ! ( childCount() && d->mCurrentItem ) ) |
1352 | { | 1360 | { |
1353 | e->ignore(); | 1361 | e->ignore(); |
1354 | return; | 1362 | return; |
1355 | } | 1363 | } |
1356 | if ( mFlagBlockKeyPressed ) | 1364 | if ( mFlagBlockKeyPressed ) |
1357 | return; | 1365 | return; |
1358 | qApp->processEvents(); | 1366 | qApp->processEvents(); |
1359 | if ( e->isAutoRepeat() && !mFlagKeyPressed ) { | 1367 | if ( e->isAutoRepeat() && !mFlagKeyPressed ) { |
1360 | e->accept(); | 1368 | e->accept(); |
1361 | return; | 1369 | return; |
1362 | } | 1370 | } |
1363 | if (! e->isAutoRepeat() ) | 1371 | if (! e->isAutoRepeat() ) |
1364 | mFlagKeyPressed = true; | 1372 | mFlagKeyPressed = true; |
1365 | uint pos = d->mItemList.findRef( d->mCurrentItem ); | 1373 | uint pos = d->mItemList.findRef( d->mCurrentItem ); |
1366 | CardViewItem *aItem = 0L; // item that gets the focus | 1374 | CardViewItem *aItem = 0L; // item that gets the focus |
1367 | CardViewItem *old = d->mCurrentItem; | 1375 | CardViewItem *old = d->mCurrentItem; |
1368 | 1376 | ||
1369 | switch ( e->key() ) | 1377 | switch ( e->key() ) |
1370 | { | 1378 | { |
1371 | case Key_Up: | 1379 | case Qt::Key_Up: |
1372 | if ( pos > 0 ) | 1380 | if ( pos > 0 ) |
1373 | { | 1381 | { |
1374 | aItem = d->mItemList.at( pos - 1 ); | 1382 | aItem = d->mItemList.at( pos - 1 ); |
1375 | setCurrentItem( aItem ); | 1383 | setCurrentItem( aItem ); |
1376 | } | 1384 | } |
1377 | break; | 1385 | break; |
1378 | case Key_Down: | 1386 | case Qt::Key_Down: |
1379 | if ( pos < d->mItemList.count() - 1 ) | 1387 | if ( pos < d->mItemList.count() - 1 ) |
1380 | { | 1388 | { |
1381 | aItem = d->mItemList.at( pos + 1 ); | 1389 | aItem = d->mItemList.at( pos + 1 ); |
1382 | setCurrentItem( aItem ); | 1390 | setCurrentItem( aItem ); |
1383 | } | 1391 | } |
1384 | break; | 1392 | break; |
1385 | case Key_Left: | 1393 | case Qt::Key_Left: |
1386 | { | 1394 | { |
1387 | // look for an item in the previous/next column, starting from | 1395 | // look for an item in the previous/next column, starting from |
1388 | // the vertical middle of the current item. | 1396 | // the vertical middle of the current item. |
1389 | // FIXME use nice calculatd measures!!! | 1397 | // FIXME use nice calculatd measures!!! |
1390 | QPoint aPoint( d->mCurrentItem->d->x, d->mCurrentItem->d->y ); | 1398 | QPoint aPoint( d->mCurrentItem->d->x, d->mCurrentItem->d->y ); |
1391 | aPoint -= QPoint( 30,-(d->mCurrentItem->height()/2) ); | 1399 | aPoint -= QPoint( 30,-(d->mCurrentItem->height()/2) ); |
1392 | aItem = itemAt( aPoint ); | 1400 | aItem = itemAt( aPoint ); |
1393 | // maybe we hit some space below an item | 1401 | // maybe we hit some space below an item |
1394 | while ( !aItem && aPoint.y() > 27 ) | 1402 | while ( !aItem && aPoint.y() > 27 ) |
1395 | { | 1403 | { |
1396 | aPoint -= QPoint( 0, 16 ); | 1404 | aPoint -= QPoint( 0, 16 ); |
1397 | aItem = itemAt( aPoint ); | 1405 | aItem = itemAt( aPoint ); |
1398 | } | 1406 | } |
1399 | if ( aItem ) | 1407 | if ( aItem ) |
1400 | setCurrentItem( aItem ); | 1408 | setCurrentItem( aItem ); |
1401 | } | 1409 | } |
1402 | break; | 1410 | break; |
1403 | case Key_Right: | 1411 | case Qt::Key_Right: |
1404 | { | 1412 | { |
1405 | // FIXME use nice calculated measures!!! | 1413 | // FIXME use nice calculated measures!!! |
1406 | QPoint aPoint( d->mCurrentItem->d->x + d->mItemWidth, d->mCurrentItem->d->y ); | 1414 | QPoint aPoint( d->mCurrentItem->d->x + d->mItemWidth, d->mCurrentItem->d->y ); |
1407 | aPoint += QPoint( 30,(d->mCurrentItem->height()/2) ); | 1415 | aPoint += QPoint( 30,(d->mCurrentItem->height()/2) ); |
1408 | aItem = itemAt( aPoint ); | 1416 | aItem = itemAt( aPoint ); |
1409 | while ( !aItem && aPoint.y() > 27 ) | 1417 | while ( !aItem && aPoint.y() > 27 ) |
1410 | { | 1418 | { |
1411 | aPoint -= QPoint( 0, 16 ); | 1419 | aPoint -= QPoint( 0, 16 ); |
1412 | aItem = itemAt( aPoint ); | 1420 | aItem = itemAt( aPoint ); |
1413 | } | 1421 | } |
1414 | if ( aItem ) | 1422 | if ( aItem ) |
1415 | setCurrentItem( aItem ); | 1423 | setCurrentItem( aItem ); |
1416 | } | 1424 | } |
1417 | break; | 1425 | break; |
1418 | case Key_Home: | 1426 | case Qt::Key_Home: |
1419 | aItem = d->mItemList.first(); | 1427 | aItem = d->mItemList.first(); |
1420 | setCurrentItem( aItem ); | 1428 | setCurrentItem( aItem ); |
1421 | break; | 1429 | break; |
1422 | case Key_End: | 1430 | case Qt::Key_End: |
1423 | aItem = d->mItemList.last(); | 1431 | aItem = d->mItemList.last(); |
1424 | setCurrentItem( aItem ); | 1432 | setCurrentItem( aItem ); |
1425 | break; | 1433 | break; |
1426 | case Key_Prior: // PageUp | 1434 | case Qt::Key_Prior: // PageUp |
1427 | { | 1435 | { |
1428 | // QListView: "Make the item above the top visible and current" | 1436 | // QListView: "Make the item above the top visible and current" |
1429 | // TODO if contentsY(), pick the top item of the leftmost visible column | 1437 | // TODO if contentsY(), pick the top item of the leftmost visible column |
1430 | if ( contentsX() <= 0 ) | 1438 | if ( contentsX() <= 0 ) |
1431 | return; | 1439 | return; |
1432 | int cw = columnWidth(); | 1440 | int cw = columnWidth(); |
1433 | int theCol = ( QMAX( 0, ( contentsX()/cw) * cw ) ) + d->mItemSpacing; | 1441 | int theCol = ( QMAX( 0, ( contentsX()/cw) * cw ) ) + d->mItemSpacing; |
1434 | aItem = itemAt( QPoint( theCol + 1, d->mItemSpacing + 1 ) ); | 1442 | aItem = itemAt( QPoint( theCol + 1, d->mItemSpacing + 1 ) ); |
1435 | if ( aItem ) | 1443 | if ( aItem ) |
1436 | setCurrentItem( aItem ); | 1444 | setCurrentItem( aItem ); |
1437 | } | 1445 | } |
1438 | break; | 1446 | break; |
1439 | case Key_Next: // PageDown | 1447 | case Qt::Key_Next: // PageDown |
1440 | { | 1448 | { |
1441 | // QListView: "Make the item below the bottom visible and current" | 1449 | // QListView: "Make the item below the bottom visible and current" |
1442 | // find the first not fully visible column. | 1450 | // find the first not fully visible column. |
1443 | // TODO: consider if a partly visible (or even hidden) item at the | 1451 | // TODO: consider if a partly visible (or even hidden) item at the |
1444 | // bottom of the rightmost column exists | 1452 | // bottom of the rightmost column exists |
1445 | int cw = columnWidth(); | 1453 | int cw = columnWidth(); |
1446 | int theCol = ( (( contentsX() + visibleWidth() )/cw) * cw ) + d->mItemSpacing + 1; | 1454 | int theCol = ( (( contentsX() + visibleWidth() )/cw) * cw ) + d->mItemSpacing + 1; |
1447 | // if separators are on, we may need to we may be one column further right if only the spacing/sep is hidden | 1455 | // if separators are on, we may need to we may be one column further right if only the spacing/sep is hidden |
1448 | if ( d->mDrawSeparators && cw - (( contentsX() + visibleWidth() )%cw) <= int( d->mItemSpacing + d->mSepWidth ) ) | 1456 | if ( d->mDrawSeparators && cw - (( contentsX() + visibleWidth() )%cw) <= int( d->mItemSpacing + d->mSepWidth ) ) |
1449 | theCol += cw; | 1457 | theCol += cw; |
1450 | 1458 | ||
1451 | // make sure this is not too far right | 1459 | // make sure this is not too far right |
1452 | while ( theCol > contentsWidth() ) | 1460 | while ( theCol > contentsWidth() ) |
1453 | theCol -= columnWidth(); | 1461 | theCol -= columnWidth(); |
1454 | 1462 | ||
1455 | aItem = itemAt( QPoint( theCol, d->mItemSpacing + 1 ) ); | 1463 | aItem = itemAt( QPoint( theCol, d->mItemSpacing + 1 ) ); |
1456 | 1464 | ||
1457 | if ( aItem ) | 1465 | if ( aItem ) |
1458 | setCurrentItem( aItem ); | 1466 | setCurrentItem( aItem ); |
1459 | } | 1467 | } |
1460 | break; | 1468 | break; |
1461 | case Key_Space: | 1469 | case Qt::Key_Space: |
1462 | setSelected( d->mCurrentItem, !d->mCurrentItem->isSelected() ); | 1470 | setSelected( d->mCurrentItem, !d->mCurrentItem->isSelected() ); |
1463 | emit selectionChanged(); | 1471 | emit selectionChanged(); |
1464 | break; | 1472 | break; |
1465 | case Key_Return: | 1473 | case Qt::Key_Return: |
1466 | case Key_Enter: | 1474 | case Qt::Key_Enter: |
1467 | { | 1475 | { |
1468 | emit returnPressed( d->mCurrentItem ); | 1476 | emit returnPressed( d->mCurrentItem ); |
1469 | emit executed( d->mCurrentItem ); | 1477 | emit executed( d->mCurrentItem ); |
1470 | } | 1478 | } |
1471 | break; | 1479 | break; |
1472 | default: | 1480 | default: |
1473 | if ( (e->state() & ControlButton) && e->key() == Key_A ) | 1481 | if ( (e->state() & Qt::ControlButton) && e->key() == Qt::Key_A ) |
1474 | { | 1482 | { |
1475 | // select all | 1483 | // select all |
1476 | selectAll( true ); | 1484 | selectAll( true ); |
1477 | break; | 1485 | break; |
1478 | } | 1486 | } |
1479 | // if we have a string, do autosearch | 1487 | // if we have a string, do autosearch |
1480 | else if ( ! e->text().isEmpty() && e->text()[0].isPrint() ) | 1488 | else if ( ! e->text().isEmpty() && e->text()[0].isPrint() ) |
1481 | { | 1489 | { |
1482 | 1490 | ||
1483 | } | 1491 | } |
1484 | break; | 1492 | break; |
1485 | } | 1493 | } |
1486 | // handle selection | 1494 | // handle selection |
1487 | if ( aItem ) | 1495 | if ( aItem ) |
1488 | { | 1496 | { |
1489 | if ( d->mSelectionMode == CardView::Extended ) | 1497 | if ( d->mSelectionMode == CardView::Extended ) |
1490 | { | 1498 | { |
1491 | if ( (e->state() & ShiftButton) ) | 1499 | if ( (e->state() & Qt::ShiftButton) ) |
1492 | { | 1500 | { |
1493 | // shift button: toggle range | 1501 | // shift button: toggle range |
1494 | // if control button is pressed, leave all items | 1502 | // if control button is pressed, leave all items |
1495 | // and toggle selection current->old current | 1503 | // and toggle selection current->old current |
1496 | // otherwise, ?????? | 1504 | // otherwise, ?????? |
1497 | bool s = ! aItem->isSelected(); | 1505 | bool s = ! aItem->isSelected(); |
1498 | int from, to, a, b; | 1506 | int from, to, a, b; |
1499 | a = d->mItemList.findRef( aItem ); | 1507 | a = d->mItemList.findRef( aItem ); |
1500 | b = d->mItemList.findRef( old ); | 1508 | b = d->mItemList.findRef( old ); |
1501 | from = a < b ? a : b; | 1509 | from = a < b ? a : b; |
1502 | to = a > b ? a : b; | 1510 | to = a > b ? a : b; |
1503 | 1511 | ||
1504 | if ( to - from > 1 ) | 1512 | if ( to - from > 1 ) |
1505 | { | 1513 | { |
1506 | bool b = signalsBlocked(); | 1514 | bool b = signalsBlocked(); |
1507 | blockSignals(true); | 1515 | blockSignals(true); |
1508 | selectAll(false); | 1516 | selectAll(false); |
1509 | blockSignals(b); | 1517 | blockSignals(b); |
1510 | } | 1518 | } |
1511 | 1519 | ||
1512 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; | 1520 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; |
1513 | CardViewItem *item; | 1521 | CardViewItem *item; |
1514 | for ( ; from <= to; from++ ) | 1522 | for ( ; from <= to; from++ ) |
1515 | { | 1523 | { |
1516 | item = d->mItemList.at( from ); | 1524 | item = d->mItemList.at( from ); |
1517 | item->setSelected( s ); | 1525 | item->setSelected( s ); |
1518 | repaintItem( item ); | 1526 | repaintItem( item ); |
1519 | } | 1527 | } |
1520 | emit selectionChanged(); | 1528 | emit selectionChanged(); |
1521 | } | 1529 | } |
1522 | else if ( (e->state() & ControlButton) ) | 1530 | else if ( (e->state() & Qt::ControlButton) ) |
1523 | { | 1531 | { |
1524 | // control button: do nothing | 1532 | // control button: do nothing |
1525 | } | 1533 | } |
1526 | else | 1534 | else |
1527 | { | 1535 | { |
1528 | // no button: move selection to this item | 1536 | // no button: move selection to this item |
1529 | bool b = signalsBlocked(); | 1537 | bool b = signalsBlocked(); |
1530 | blockSignals(true); | 1538 | blockSignals(true); |
1531 | selectAll(false); | 1539 | selectAll(false); |
1532 | blockSignals(b); | 1540 | blockSignals(b); |
1533 | 1541 | ||
1534 | setSelected( aItem, true ); | 1542 | setSelected( aItem, true ); |
1535 | emit selectionChanged(); | 1543 | emit selectionChanged(); |
1536 | } | 1544 | } |
1537 | } | 1545 | } |
1538 | } | 1546 | } |
1539 | } | 1547 | } |
1540 | 1548 | ||
1541 | void CardView::contentsWheelEvent( QWheelEvent * e ) | 1549 | void CardView::contentsWheelEvent( QWheelEvent * e ) |
1542 | { | 1550 | { |
1543 | scrollBy(2*e->delta()/-3, 0); | 1551 | scrollBy(2*e->delta()/-3, 0); |
1544 | } | 1552 | } |
1545 | 1553 | ||
1546 | void CardView::setLayoutDirty(bool dirty) | 1554 | void CardView::setLayoutDirty(bool dirty) |
1547 | { | 1555 | { |
1548 | if (d->mLayoutDirty != dirty) | 1556 | if (d->mLayoutDirty != dirty) |
1549 | { | 1557 | { |
1550 | d->mLayoutDirty = dirty; | 1558 | d->mLayoutDirty = dirty; |
1551 | repaint(); | 1559 | repaint(); |
1552 | } | 1560 | } |
1553 | } | 1561 | } |
1554 | 1562 | ||
@@ -1609,142 +1617,142 @@ bool CardView::showEmptyFields() const | |||
1609 | } | 1617 | } |
1610 | 1618 | ||
1611 | void CardView::startDrag() | 1619 | void CardView::startDrag() |
1612 | { | 1620 | { |
1613 | // The default implementation is a no-op. It must be | 1621 | // The default implementation is a no-op. It must be |
1614 | // reimplemented in a subclass to be useful | 1622 | // reimplemented in a subclass to be useful |
1615 | } | 1623 | } |
1616 | void CardView::tryShowFullText() | 1624 | void CardView::tryShowFullText() |
1617 | { | 1625 | { |
1618 | d->mTimer->stop(); | 1626 | d->mTimer->stop(); |
1619 | // if we have an item | 1627 | // if we have an item |
1620 | QPoint cpos = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) ); | 1628 | QPoint cpos = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) ); |
1621 | CardViewItem *item = itemAt( cpos ); | 1629 | CardViewItem *item = itemAt( cpos ); |
1622 | if ( item ) | 1630 | if ( item ) |
1623 | { | 1631 | { |
1624 | // query it for a value to display | 1632 | // query it for a value to display |
1625 | //QString s = item ? item->caption() : "(no item)"; | 1633 | //QString s = item ? item->caption() : "(no item)"; |
1626 | //kdDebug()<<"MOUSE REST: "<<s<<endl; | 1634 | //kdDebug()<<"MOUSE REST: "<<s<<endl; |
1627 | QPoint ipos = cpos - itemRect( item ).topLeft(); | 1635 | QPoint ipos = cpos - itemRect( item ).topLeft(); |
1628 | item->showFullString( ipos, d->mTip ); | 1636 | item->showFullString( ipos, d->mTip ); |
1629 | } | 1637 | } |
1630 | } | 1638 | } |
1631 | 1639 | ||
1632 | void CardView::drawRubberBands( int pos ) | 1640 | void CardView::drawRubberBands( int pos ) |
1633 | { | 1641 | { |
1634 | if ( pos && ((pos-d->firstX)/d->span) - d->colspace - d->mSepWidth < MIN_ITEM_WIDTH ) return; | 1642 | if ( pos && ((pos-d->firstX)/d->span) - d->colspace - d->mSepWidth < MIN_ITEM_WIDTH ) return; |
1635 | 1643 | ||
1636 | int tmpcw = (d->mRubberBandAnchor-d->firstX)/d->span; | 1644 | int tmpcw = (d->mRubberBandAnchor-d->firstX)/d->span; |
1637 | int x = d->firstX + tmpcw - d->mSepWidth - contentsX(); | 1645 | int x = d->firstX + tmpcw - d->mSepWidth - contentsX(); |
1638 | int h = visibleHeight(); | 1646 | int h = visibleHeight(); |
1639 | 1647 | ||
1640 | QPainter p( viewport() ); | 1648 | QPainter p( viewport() ); |
1641 | p.setRasterOp( XorROP ); | 1649 | p.setCompositionMode( QPainter::CompositionMode_Xor ); |
1642 | p.setPen( gray ); | 1650 | p.setPen( Qt::gray ); |
1643 | p.setBrush( gray ); | 1651 | p.setBrush( Qt::gray ); |
1644 | uint n = d->first; | 1652 | uint n = d->first; |
1645 | // erase | 1653 | // erase |
1646 | if ( d->mRubberBandAnchor ) | 1654 | if ( d->mRubberBandAnchor ) |
1647 | do { | 1655 | do { |
1648 | p.drawRect( x, 0, 2, h ); | 1656 | p.drawRect( x, 0, 2, h ); |
1649 | x += tmpcw; | 1657 | x += tmpcw; |
1650 | n++; | 1658 | n++; |
1651 | } while ( x < visibleWidth() && n < d->mSeparatorList.count() ); | 1659 | } while ( x < visibleWidth() && n < d->mSeparatorList.count() ); |
1652 | // paint new | 1660 | // paint new |
1653 | if ( ! pos ) return; | 1661 | if ( ! pos ) return; |
1654 | tmpcw = (pos - d->firstX)/d->span; | 1662 | tmpcw = (pos - d->firstX)/d->span; |
1655 | n = d->first; | 1663 | n = d->first; |
1656 | x = d->firstX + tmpcw - d->mSepWidth - contentsX(); | 1664 | x = d->firstX + tmpcw - d->mSepWidth - contentsX(); |
1657 | do { | 1665 | do { |
1658 | p.drawRect( x, 0, 2, h ); | 1666 | p.drawRect( x, 0, 2, h ); |
1659 | x += tmpcw; | 1667 | x += tmpcw; |
1660 | n++; | 1668 | n++; |
1661 | } while ( x < visibleWidth() && n < d->mSeparatorList.count() ); | 1669 | } while ( x < visibleWidth() && n < d->mSeparatorList.count() ); |
1662 | d->mRubberBandAnchor = pos; | 1670 | d->mRubberBandAnchor = pos; |
1663 | } | 1671 | } |
1664 | 1672 | ||
1665 | 1673 | ||
1666 | int CardView::itemWidth() const | 1674 | int CardView::itemWidth() const |
1667 | { | 1675 | { |
1668 | return d->mItemWidth; | 1676 | return d->mItemWidth; |
1669 | } | 1677 | } |
1670 | 1678 | ||
1671 | void CardView::setItemWidth( int w ) | 1679 | void CardView::setItemWidth( int w ) |
1672 | { | 1680 | { |
1673 | if ( w == d->mItemWidth ) | 1681 | if ( w == d->mItemWidth ) |
1674 | return; | 1682 | return; |
1675 | if ( w < MIN_ITEM_WIDTH ) | 1683 | if ( w < MIN_ITEM_WIDTH ) |
1676 | w = MIN_ITEM_WIDTH; | 1684 | w = MIN_ITEM_WIDTH; |
1677 | d->mItemWidth = w; | 1685 | d->mItemWidth = w; |
1678 | setLayoutDirty( true ); | 1686 | setLayoutDirty( true ); |
1679 | #ifndef KAB_EMBEDDED | 1687 | #ifndef KAB_EMBEDDED |
1680 | updateContents(); | 1688 | updateContents(); |
1681 | #else //KAB_EMBEDDED | 1689 | #else //KAB_EMBEDDED |
1682 | //US updateContents( d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight() ); | 1690 | //US updateContents( d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight() ); |
1683 | qDebug("CardView::setItemWidth has to be verified"); | 1691 | qDebug("CardView::setItemWidth has to be verified"); |
1684 | updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); | 1692 | updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); |
1685 | #endif //KAB_EMBEDDED | 1693 | #endif //KAB_EMBEDDED |
1686 | } | 1694 | } |
1687 | 1695 | ||
1688 | void CardView::setHeaderFont( const QFont &fnt ) | 1696 | void CardView::setHeaderFont( const QFont &fnt ) |
1689 | { | 1697 | { |
1690 | d->mHeaderFont = fnt; | 1698 | d->mHeaderFont = fnt; |
1691 | delete d->mBFm; | 1699 | delete d->mBFm; |
1692 | d->mBFm = new QFontMetrics( fnt ); | 1700 | d->mBFm = new QFontMetrics( fnt ); |
1693 | } | 1701 | } |
1694 | 1702 | ||
1695 | QFont CardView::headerFont() const | 1703 | QFont CardView::headerFont() const |
1696 | { | 1704 | { |
1697 | return d->mHeaderFont; | 1705 | return d->mHeaderFont; |
1698 | } | 1706 | } |
1699 | 1707 | ||
1700 | void CardView::setFont( const QFont &fnt ) | 1708 | void CardView::setFont( const QFont &fnt ) |
1701 | { | 1709 | { |
1702 | QScrollView::setFont( fnt ); | 1710 | Q3ScrollView::setFont( fnt ); |
1703 | delete d->mFm; | 1711 | delete d->mFm; |
1704 | d->mFm = new QFontMetrics( fnt ); | 1712 | d->mFm = new QFontMetrics( fnt ); |
1705 | } | 1713 | } |
1706 | 1714 | ||
1707 | int CardView::separatorWidth() | 1715 | int CardView::separatorWidth() |
1708 | { | 1716 | { |
1709 | return d->mSepWidth; | 1717 | return d->mSepWidth; |
1710 | } | 1718 | } |
1711 | 1719 | ||
1712 | void CardView::setSeparatorWidth( int width ) | 1720 | void CardView::setSeparatorWidth( int width ) |
1713 | { | 1721 | { |
1714 | d->mSepWidth = width; | 1722 | d->mSepWidth = width; |
1715 | setLayoutDirty( true ); // hmm, actually I could just adjust the x'es... | 1723 | setLayoutDirty( true ); // hmm, actually I could just adjust the x'es... |
1716 | } | 1724 | } |
1717 | 1725 | ||
1718 | int CardView::maxFieldLines() const | 1726 | int CardView::maxFieldLines() const |
1719 | { | 1727 | { |
1720 | return d->mMaxFieldLines; | 1728 | return d->mMaxFieldLines; |
1721 | } | 1729 | } |
1722 | 1730 | ||
1723 | void CardView::setMaxFieldLines( int howmany ) | 1731 | void CardView::setMaxFieldLines( int howmany ) |
1724 | { | 1732 | { |
1725 | d->mMaxFieldLines = howmany ? howmany : INT_MAX; | 1733 | d->mMaxFieldLines = howmany ? howmany : INT_MAX; |
1726 | // FIXME update, forcing the items to recalc height!! | 1734 | // FIXME update, forcing the items to recalc height!! |
1727 | } | 1735 | } |
1728 | 1736 | ||
1729 | void CardView::keyReleaseEvent ( QKeyEvent * e ) | 1737 | void CardView::keyReleaseEvent ( QKeyEvent * e ) |
1730 | { | 1738 | { |
1731 | if ( mFlagBlockKeyPressed ) | 1739 | if ( mFlagBlockKeyPressed ) |
1732 | return; | 1740 | return; |
1733 | if ( !e->isAutoRepeat() ) { | 1741 | if ( !e->isAutoRepeat() ) { |
1734 | mFlagBlockKeyPressed = true; | 1742 | mFlagBlockKeyPressed = true; |
1735 | qApp->processEvents(); | 1743 | qApp->processEvents(); |
1736 | mFlagBlockKeyPressed = false; | 1744 | mFlagBlockKeyPressed = false; |
1737 | mFlagKeyPressed = false; | 1745 | mFlagKeyPressed = false; |
1738 | } | 1746 | } |
1739 | QScrollView::keyReleaseEvent ( e ); | 1747 | Q3ScrollView::keyReleaseEvent ( e ); |
1740 | } | 1748 | } |
1741 | 1749 | ||
1742 | 1750 | ||
1743 | 1751 | ||
1744 | 1752 | ||
1745 | 1753 | ||
1746 | //END Cardview | 1754 | //END Cardview |
1747 | 1755 | ||
1748 | #ifndef KAB_EMBEDDED | 1756 | #ifndef KAB_EMBEDDED_ |
1749 | #include "cardview.moc" | 1757 | #include "moc_cardview.cpp" |
1750 | #endif //KAB_EMBEDDED | 1758 | #endif //KAB_EMBEDDED |