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