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