summaryrefslogtreecommitdiffabout
path: root/kaddressbook
Unidiff
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/views/contactlistview.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/kaddressbook/views/contactlistview.cpp b/kaddressbook/views/contactlistview.cpp
index 4cc22ea..c74f8cf 100644
--- a/kaddressbook/views/contactlistview.cpp
+++ b/kaddressbook/views/contactlistview.cpp
@@ -1,345 +1,371 @@
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 <qheader.h> 24#include <qheader.h>
25#include <qiconset.h> 25#include <qiconset.h>
26#include <qimage.h> 26#include <qimage.h>
27#include <qdragobject.h> 27#include <qdragobject.h>
28#include <qcombobox.h> 28#include <qcombobox.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qbrush.h> 30#include <qbrush.h>
31#include <qevent.h> 31#include <qevent.h>
32 32
33#include <klocale.h> 33#include <klocale.h>
34#include <kglobalsettings.h> 34#include <kglobalsettings.h>
35#include <kiconloader.h> 35#include <kiconloader.h>
36#include <kdebug.h> 36#include <kdebug.h>
37#include <kconfig.h> 37#include <kconfig.h>
38#include <kapplication.h> 38#include <kapplication.h>
39#include <kurl.h> 39#include <kurl.h>
40 40
41#include "kaddressbooktableview.h" 41#include "kaddressbooktableview.h"
42 42
43#include "contactlistview.h" 43#include "contactlistview.h"
44 44
45///////////////////////////////// 45/////////////////////////////////
46// DynamicTip Methods 46// DynamicTip Methods
47 47
48DynamicTip::DynamicTip( ContactListView *parent) 48DynamicTip::DynamicTip( ContactListView *parent)
49 : QToolTip( parent ) 49 : QToolTip( parent )
50{ 50{
51} 51}
52 52
53void DynamicTip::maybeTip( const QPoint &pos ) 53void DynamicTip::maybeTip( const QPoint &pos )
54{ 54{
55 static bool ishidden = true; 55 static bool ishidden = true;
56 if (!parentWidget()->inherits( "ContactListView" )) 56 if (!parentWidget()->inherits( "ContactListView" ))
57 return; 57 return;
58 58
59 ContactListView *plv = (ContactListView*)parentWidget(); 59 ContactListView *plv = (ContactListView*)parentWidget();
60 if (!plv->tooltips()) 60 if (!plv->tooltips())
61 return; 61 return;
62 62
63 QPoint posVp = plv->viewport()->pos(); 63 QPoint posVp = plv->viewport()->pos();
64 64
65 QListViewItem *lvi = plv->itemAt( pos - posVp ); 65 QListViewItem *lvi = plv->itemAt( pos - posVp );
66 if (!lvi) 66 if (!lvi)
67 return; 67 return;
68 68
69#ifndef KAB_EMBEDDED 69#ifndef KAB_EMBEDDED
70 ContactListViewItem *plvi = dynamic_cast< ContactListViewItem* >(lvi); 70 ContactListViewItem *plvi = dynamic_cast< ContactListViewItem* >(lvi);
71#else //KAB_EMBEDDED 71#else //KAB_EMBEDDED
72 ContactListViewItem *plvi = (ContactListViewItem*)(lvi); 72 ContactListViewItem *plvi = (ContactListViewItem*)(lvi);
73#endif //KAB_EMBEDDED 73#endif //KAB_EMBEDDED
74 74
75 if (!plvi) 75 if (!plvi)
76 return; 76 return;
77 77
78 if (ishidden) { 78 if (ishidden) {
79 QString s; 79 QString s;
80 QRect r = plv->itemRect( lvi ); 80 QRect r = plv->itemRect( lvi );
81 r.moveBy( posVp.x(), posVp.y() ); 81 r.moveBy( posVp.x(), posVp.y() );
82 82
83 //kdDebug() << "Tip rec: " << r.x() << "," << r.y() << "," << r.width() 83 //kdDebug() << "Tip rec: " << r.x() << "," << r.y() << "," << r.width()
84 // << "," << r.height() << endl; 84 // << "," << r.height() << endl;
85 85
86 KABC::Addressee a = plvi->addressee(); 86 KABC::Addressee a = plvi->addressee();
87 if (a.isEmpty()) 87 if (a.isEmpty())
88 return; 88 return;
89 89
90 s += i18n("label: value", "%1: %2").arg(a.formattedNameLabel()) 90 s += i18n("label: value", "%1: %2").arg(a.formattedNameLabel())
91 .arg(a.formattedName()); 91 .arg(a.formattedName());
92 92
93 s += '\n'; 93 s += '\n';
94 s += i18n("label: value", "%1: %2").arg(a.organizationLabel()) 94 s += i18n("label: value", "%1: %2").arg(a.organizationLabel())
95 .arg(a.organization()); 95 .arg(a.organization());
96 96
97 QString notes = a.note().stripWhiteSpace(); 97 QString notes = a.note().stripWhiteSpace();
98 if ( !notes.isEmpty() ) { 98 if ( !notes.isEmpty() ) {
99 notes += '\n'; 99 notes += '\n';
100 s += '\n' + i18n("label: value", "%1: \n").arg(a.noteLabel()); 100 s += '\n' + i18n("label: value", "%1: \n").arg(a.noteLabel());
101 QFontMetrics fm( font() ); 101 QFontMetrics fm( font() );
102 102
103 // Begin word wrap code based on QMultiLineEdit code 103 // Begin word wrap code based on QMultiLineEdit code
104 int i = 0; 104 int i = 0;
105 bool doBreak = false; 105 bool doBreak = false;
106 int linew = 0; 106 int linew = 0;
107 int lastSpace = -1; 107 int lastSpace = -1;
108 int a = 0; 108 int a = 0;
109 int lastw = 0; 109 int lastw = 0;
110 110
111 while ( i < int(notes.length()) ) { 111 while ( i < int(notes.length()) ) {
112 doBreak = FALSE; 112 doBreak = FALSE;
113 if ( notes[i] != '\n' ) 113 if ( notes[i] != '\n' )
114 linew += fm.width( notes[i] ); 114 linew += fm.width( notes[i] );
115 115
116 if ( lastSpace >= a && notes[i] != '\n' ) 116 if ( lastSpace >= a && notes[i] != '\n' )
117 if (linew >= parentWidget()->width()) { 117 if (linew >= parentWidget()->width()) {
118 doBreak = TRUE; 118 doBreak = TRUE;
119 if ( lastSpace > a ) { 119 if ( lastSpace > a ) {
120 i = lastSpace; 120 i = lastSpace;
121 linew = lastw; 121 linew = lastw;
122 } 122 }
123 else 123 else
124 i = QMAX( a, i-1 ); 124 i = QMAX( a, i-1 );
125 } 125 }
126 126
127 if ( notes[i] == '\n' || doBreak ) { 127 if ( notes[i] == '\n' || doBreak ) {
128 s += notes.mid( a, i - a + (doBreak?1:0) ) +"\n"; 128 s += notes.mid( a, i - a + (doBreak?1:0) ) +"\n";
129 129
130 a = i + 1; 130 a = i + 1;
131 lastSpace = a; 131 lastSpace = a;
132 linew = 0; 132 linew = 0;
133 } 133 }
134 134
135 if ( notes[i].isSpace() ) { 135 if ( notes[i].isSpace() ) {
136 lastSpace = i; 136 lastSpace = i;
137 lastw = linew; 137 lastw = linew;
138 } 138 }
139 139
140 if ( lastSpace <= a ) { 140 if ( lastSpace <= a ) {
141 lastw = linew; 141 lastw = linew;
142 } 142 }
143 143
144 ++i; 144 ++i;
145 } 145 }
146 } 146 }
147 147
148 tip( r, s ); 148 tip( r, s );
149 } 149 }
150 else 150 else
151 hide(); 151 hide();
152 ishidden = !ishidden; 152 ishidden = !ishidden;
153 153
154} 154}
155 155
156/////////////////////////// 156///////////////////////////
157// ContactListViewItem Methods 157// ContactListViewItem Methods
158 158
159ContactListViewItem::ContactListViewItem(const KABC::Addressee &a, 159ContactListViewItem::ContactListViewItem(const KABC::Addressee &a,
160 ContactListView *parent, 160 ContactListView *parent,
161 KABC::AddressBook *doc, 161 KABC::AddressBook *doc,
162 const KABC::Field::List &fields ) 162 const KABC::Field::List &fields )
163 : KListViewItem(parent), mAddressee(a), mFields( fields ), 163 : KListViewItem(parent), mAddressee(a), mFields( fields ),
164 parentListView( parent ), mDocument(doc) 164 parentListView( parent ), mDocument(doc)
165{ 165{
166 refresh(); 166 refresh();
167} 167}
168 168
169QString ContactListViewItem::key(int column, bool ascending) const 169QString ContactListViewItem::key(int column, bool ascending) const
170{ 170{
171 return QListViewItem::key(column, ascending).lower(); 171 int lan = KGlobal::locale()->language();
172 //qDebug("language %d ", lan);
173 if ( lan == 1 ) { //GERMAN
174 QString ret = QListViewItem::key(column, ascending).utf8();
175 int start = -1;
176 while ( (start = ret.find( 'ä', start+1)) > 0 ) {
177 ret.at(start-1) = 'a';
178 }
179 start = -1;
180 while ( (start = ret.find( 'ö', start+1)) > 0 ) {
181 ret.at(start-1) = 'o';
182 }
183 start = -1;
184 while ( (start = ret.find( 'ü', start+1)) > 0 ) {
185 ret.at(start-1) = 'o';
186 }
187 start = -1;
188 while ( (start = ret.find( 'ß', start+1)) > 0 ) {
189 ret.at(start-1) = 's';
190 }
191 //qDebug("conv string %s ", ret.latin1());
192
193 return ret;
194
195 }
196 else
197 return QListViewItem::key(column, ascending).lower();
172} 198}
173 199
174void ContactListViewItem::paintCell(QPainter * p, 200void ContactListViewItem::paintCell(QPainter * p,
175 const QColorGroup & cg, 201 const QColorGroup & cg,
176 int column, 202 int column,
177 int width, 203 int width,
178 int align) 204 int align)
179{ 205{
180 KListViewItem::paintCell(p, cg, column, width, align); 206 KListViewItem::paintCell(p, cg, column, width, align);
181 207
182 if ( !p ) 208 if ( !p )
183 return; 209 return;
184 210
185 if (parentListView->singleLine()) { 211 if (parentListView->singleLine()) {
186 p->setPen( parentListView->alternateColor() ); 212 p->setPen( parentListView->alternateColor() );
187 p->drawLine( 0, height() - 1, width, height() - 1 ); 213 p->drawLine( 0, height() - 1, width, height() - 1 );
188 } 214 }
189} 215}
190 216
191 217
192ContactListView *ContactListViewItem::parent() 218ContactListView *ContactListViewItem::parent()
193{ 219{
194 return parentListView; 220 return parentListView;
195} 221}
196 222
197 223
198void ContactListViewItem::refresh() 224void ContactListViewItem::refresh()
199{ 225{
200 // Update our addressee, since it may have changed else were 226 // Update our addressee, since it may have changed else were
201 mAddressee = mDocument->findByUid(mAddressee.uid()); 227 mAddressee = mDocument->findByUid(mAddressee.uid());
202 if (mAddressee.isEmpty()) 228 if (mAddressee.isEmpty())
203 return; 229 return;
204 230
205 int i = 0; 231 int i = 0;
206 KABC::Field::List::ConstIterator it; 232 KABC::Field::List::ConstIterator it;
207 for( it = mFields.begin(); it != mFields.end(); ++it ) { 233 for( it = mFields.begin(); it != mFields.end(); ++it ) {
208 setText( i++, (*it)->value( mAddressee ) ); 234 setText( i++, (*it)->value( mAddressee ) );
209 } 235 }
210} 236}
211 237
212/////////////////////////////// 238///////////////////////////////
213// ContactListView 239// ContactListView
214 240
215ContactListView::ContactListView(KAddressBookTableView *view, 241ContactListView::ContactListView(KAddressBookTableView *view,
216 KABC::AddressBook* /* doc */, 242 KABC::AddressBook* /* doc */,
217 QWidget *parent, 243 QWidget *parent,
218 const char *name ) 244 const char *name )
219 : KListView( parent, name ), 245 : KListView( parent, name ),
220 pabWidget( view ), 246 pabWidget( view ),
221 oldColumn( 0 ) 247 oldColumn( 0 )
222{ 248{
223 mABackground = true; 249 mABackground = true;
224 mSingleLine = false; 250 mSingleLine = false;
225 mToolTips = true; 251 mToolTips = true;
226#ifndef KAB_EMBEDDED 252#ifndef KAB_EMBEDDED
227 mAlternateColor = KGlobalSettings::alternateBackgroundColor(); 253 mAlternateColor = KGlobalSettings::alternateBackgroundColor();
228#else //KAB_EMBEDDED 254#else //KAB_EMBEDDED
229 mAlternateColor = QColor(240, 240, 240); 255 mAlternateColor = QColor(240, 240, 240);
230#endif //KAB_EMBEDDED 256#endif //KAB_EMBEDDED
231 257
232 setAlternateBackgroundEnabled(mABackground); 258 setAlternateBackgroundEnabled(mABackground);
233 setAcceptDrops( true ); 259 setAcceptDrops( true );
234 viewport()->setAcceptDrops( true ); 260 viewport()->setAcceptDrops( true );
235 setAllColumnsShowFocus( true ); 261 setAllColumnsShowFocus( true );
236 setShowSortIndicator(true); 262 setShowSortIndicator(true);
237 263
238 setSelectionModeExt( KListView::Extended ); 264 setSelectionModeExt( KListView::Extended );
239 setDropVisualizer(false); 265 setDropVisualizer(false);
240 // setFrameStyle(QFrame::NoFrame); 266 // setFrameStyle(QFrame::NoFrame);
241 //setLineWidth ( 0 ); 267 //setLineWidth ( 0 );
242 //setMidLineWidth ( 0 ); 268 //setMidLineWidth ( 0 );
243 //setMargin ( 0 ); 269 //setMargin ( 0 );
244#ifndef KAB_EMBEDDED 270#ifndef KAB_EMBEDDED
245 connect(this, SIGNAL(dropped(QDropEvent*)), 271 connect(this, SIGNAL(dropped(QDropEvent*)),
246 this, SLOT(itemDropped(QDropEvent*))); 272 this, SLOT(itemDropped(QDropEvent*)));
247#endif //KAB_EMBEDDED 273#endif //KAB_EMBEDDED
248 274
249 275
250 new DynamicTip( this ); 276 new DynamicTip( this );
251} 277}
252 278
253void ContactListView::setAlternateColor(const QColor &m_AlternateColor) 279void ContactListView::setAlternateColor(const QColor &m_AlternateColor)
254{ 280{
255 mAlternateColor = m_AlternateColor; 281 mAlternateColor = m_AlternateColor;
256} 282}
257 283
258void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect ) 284void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect )
259{ 285{
260 QBrush b = palette().brush(QPalette::Active, QColorGroup::Base); 286 QBrush b = palette().brush(QPalette::Active, QColorGroup::Base);
261 287
262 // Get the brush, which will have the background pixmap if there is one. 288 // Get the brush, which will have the background pixmap if there is one.
263 if (b.pixmap()) 289 if (b.pixmap())
264 { 290 {
265 p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(), 291 p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(),
266 *(b.pixmap()), 292 *(b.pixmap()),
267 rect.left() + contentsX(), 293 rect.left() + contentsX(),
268 rect.top() + contentsY() ); 294 rect.top() + contentsY() );
269 } 295 }
270 296
271 else 297 else
272 { 298 {
273 // Do a normal paint 299 // Do a normal paint
274 KListView::paintEmptyArea(p, rect); 300 KListView::paintEmptyArea(p, rect);
275 } 301 }
276} 302}
277 303
278void ContactListView::contentsMousePressEvent(QMouseEvent* e) 304void ContactListView::contentsMousePressEvent(QMouseEvent* e)
279{ 305{
280 presspos = e->pos(); 306 presspos = e->pos();
281 KListView::contentsMousePressEvent(e); 307 KListView::contentsMousePressEvent(e);
282} 308}
283 309
284 310
285// To initiate a drag operation 311// To initiate a drag operation
286void ContactListView::contentsMouseMoveEvent( QMouseEvent *e ) 312void ContactListView::contentsMouseMoveEvent( QMouseEvent *e )
287{ 313{
288 if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) { 314 if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) {
289 emit startAddresseeDrag(); 315 emit startAddresseeDrag();
290 } 316 }
291 else 317 else
292 KListView::contentsMouseMoveEvent( e ); 318 KListView::contentsMouseMoveEvent( e );
293} 319}
294 320
295bool ContactListView::acceptDrag(QDropEvent *e) const 321bool ContactListView::acceptDrag(QDropEvent *e) const
296{ 322{
297#ifndef KAB_EMBEDDED 323#ifndef KAB_EMBEDDED
298 return QTextDrag::canDecode(e); 324 return QTextDrag::canDecode(e);
299#else //KAB_EMBEDDED 325#else //KAB_EMBEDDED
300qDebug("ContactListView::acceptDrag has to be fixed"); 326qDebug("ContactListView::acceptDrag has to be fixed");
301 return false; 327 return false;
302#endif //KAB_EMBEDDED 328#endif //KAB_EMBEDDED
303} 329}
304 330
305void ContactListView::itemDropped(QDropEvent *e) 331void ContactListView::itemDropped(QDropEvent *e)
306{ 332{
307 contentsDropEvent(e); 333 contentsDropEvent(e);
308} 334}
309 335
310void ContactListView::contentsDropEvent( QDropEvent *e ) 336void ContactListView::contentsDropEvent( QDropEvent *e )
311{ 337{
312 emit addresseeDropped(e); 338 emit addresseeDropped(e);
313} 339}
314 340
315void ContactListView::setAlternateBackgroundEnabled(bool enabled) 341void ContactListView::setAlternateBackgroundEnabled(bool enabled)
316{ 342{
317 mABackground = enabled; 343 mABackground = enabled;
318 344
319 if (mABackground) 345 if (mABackground)
320 { 346 {
321 setAlternateBackground(mAlternateColor); 347 setAlternateBackground(mAlternateColor);
322 } 348 }
323 else 349 else
324 { 350 {
325 setAlternateBackground(QColor()); 351 setAlternateBackground(QColor());
326 } 352 }
327} 353}
328 354
329void ContactListView::setBackgroundPixmap(const QString &filename) 355void ContactListView::setBackgroundPixmap(const QString &filename)
330{ 356{
331 if (filename.isEmpty()) 357 if (filename.isEmpty())
332 { 358 {
333 unsetPalette(); 359 unsetPalette();
334 } 360 }
335 else 361 else
336 { 362 {
337 qDebug("ContactListView::setBackgroundPixmap has to be verified"); 363 qDebug("ContactListView::setBackgroundPixmap has to be verified");
338//US setPaletteBackgroundPixmap(QPixmap(filename)); 364//US setPaletteBackgroundPixmap(QPixmap(filename));
339 KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename)); 365 KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename));
340 } 366 }
341 367
342} 368}
343#ifndef KAB_EMBEDDED 369#ifndef KAB_EMBEDDED
344#include "contactlistview.moc" 370#include "contactlistview.moc"
345#endif //KAB_EMBEDDED 371#endif //KAB_EMBEDDED