author | zautrix <zautrix> | 2005-03-30 10:41:33 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-30 10:41:33 (UTC) |
commit | 597cad3a63e6c22855704bf8435db70e3c2b184f (patch) (unidiff) | |
tree | f7093b331be9a52a07d01a6f2f5c1f26daf42d50 /kaddressbook/views | |
parent | 889d2102fcfe2fb0786b3f8f406dc32b42e38c7a (diff) | |
download | kdepimpi-597cad3a63e6c22855704bf8435db70e3c2b184f.zip kdepimpi-597cad3a63e6c22855704bf8435db70e3c2b184f.tar.gz kdepimpi-597cad3a63e6c22855704bf8435db70e3c2b184f.tar.bz2 |
fix
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp index 2b40909..cce68b9 100644 --- a/kaddressbook/views/kaddressbookcardview.cpp +++ b/kaddressbook/views/kaddressbookcardview.cpp | |||
@@ -1,503 +1,503 @@ | |||
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 | 41 | ||
42 | #include "kaddressbookcardview.h" | 42 | #include "kaddressbookcardview.h" |
43 | 43 | ||
44 | #ifndef KAB_EMBEDDED | 44 | #ifndef KAB_EMBEDDED |
45 | extern "C" { | 45 | extern "C" { |
46 | void *init_libkaddrbk_cardview() | 46 | void *init_libkaddrbk_cardview() |
47 | { | 47 | { |
48 | return ( new CardViewFactory ); | 48 | return ( new CardViewFactory ); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | #endif //KAB_EMBEDDED | 51 | #endif //KAB_EMBEDDED |
52 | 52 | ||
53 | //////////////////////////////// | 53 | //////////////////////////////// |
54 | // AddresseeCardViewItem (internal class) | 54 | // AddresseeCardViewItem (internal class) |
55 | class AddresseeCardViewItem : public CardViewItem | 55 | class AddresseeCardViewItem : public CardViewItem |
56 | { | 56 | { |
57 | public: | 57 | public: |
58 | AddresseeCardViewItem(const KABC::Field::List &fields, | 58 | AddresseeCardViewItem(const KABC::Field::List &fields, |
59 | bool showEmptyFields, | 59 | bool showEmptyFields, |
60 | KABC::AddressBook *doc, const KABC::Addressee &a, | 60 | KABC::AddressBook *doc, const KABC::Addressee &a, |
61 | CardView *parent) | 61 | CardView *parent) |
62 | : CardViewItem(parent, a.formattedName()), | 62 | : CardViewItem(parent, a.realName() ), |
63 | mFields( fields ), mShowEmptyFields(showEmptyFields), | 63 | mFields( fields ), mShowEmptyFields(showEmptyFields), |
64 | mDocument(doc), mAddressee(a) | 64 | mDocument(doc), mAddressee(a) |
65 | { | 65 | { |
66 | if ( mFields.isEmpty() ) { | 66 | if ( mFields.isEmpty() ) { |
67 | mFields = KABC::Field::defaultFields(); | 67 | mFields = KABC::Field::defaultFields(); |
68 | } | 68 | } |
69 | refresh(); | 69 | refresh(); |
70 | } | 70 | } |
71 | 71 | ||
72 | const KABC::Addressee &addressee() const { return mAddressee; } | 72 | const KABC::Addressee &addressee() const { return mAddressee; } |
73 | 73 | ||
74 | void refresh() | 74 | void refresh() |
75 | { | 75 | { |
76 | // Update our addressee, since it may have changed elsewhere | 76 | // Update our addressee, since it may have changed elsewhere |
77 | mAddressee = mDocument->findByUid(mAddressee.uid()); | 77 | mAddressee = mDocument->findByUid(mAddressee.uid()); |
78 | 78 | ||
79 | if (!mAddressee.isEmpty()) | 79 | if (!mAddressee.isEmpty()) |
80 | { | 80 | { |
81 | clearFields(); | 81 | clearFields(); |
82 | 82 | ||
83 | // Try all the selected fields until we find one with text. | 83 | // Try all the selected fields until we find one with text. |
84 | // This will limit the number of unlabeled icons in the view | 84 | // This will limit the number of unlabeled icons in the view |
85 | KABC::Field::List::Iterator iter; | 85 | KABC::Field::List::Iterator iter; |
86 | for (iter = mFields.begin(); iter != mFields.end(); ++iter) | 86 | for (iter = mFields.begin(); iter != mFields.end(); ++iter) |
87 | { | 87 | { |
88 | // insert empty fields or not? not doing so saves a bit of memory and CPU | 88 | // insert empty fields or not? not doing so saves a bit of memory and CPU |
89 | // (during geometry calculations), but prevents having equally | 89 | // (during geometry calculations), but prevents having equally |
90 | // wide label columns in all cards, unless CardViewItem/CardView search | 90 | // wide label columns in all cards, unless CardViewItem/CardView search |
91 | // globally for the widest label. (anders) | 91 | // globally for the widest label. (anders) |
92 | //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) | 92 | //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) |
93 | insertField((*iter)->label(), (*iter)->value( mAddressee )); | 93 | insertField((*iter)->label(), (*iter)->value( mAddressee )); |
94 | } | 94 | } |
95 | 95 | ||
96 | // We might want to make this the first field. hmm... -mpilone | 96 | // We might want to make this the first field. hmm... -mpilone |
97 | setCaption( mAddressee.realName() ); | 97 | setCaption( mAddressee.realName() ); |
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | private: | 101 | private: |
102 | KABC::Field::List mFields; | 102 | KABC::Field::List mFields; |
103 | bool mShowEmptyFields; | 103 | bool mShowEmptyFields; |
104 | KABC::AddressBook *mDocument; | 104 | KABC::AddressBook *mDocument; |
105 | KABC::Addressee mAddressee; | 105 | KABC::Addressee mAddressee; |
106 | }; | 106 | }; |
107 | 107 | ||
108 | /////////////////////////////// | 108 | /////////////////////////////// |
109 | // AddresseeCardView | 109 | // AddresseeCardView |
110 | 110 | ||
111 | AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) | 111 | AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) |
112 | : CardView(parent, name) | 112 | : CardView(parent, name) |
113 | { | 113 | { |
114 | setAcceptDrops(true); | 114 | setAcceptDrops(true); |
115 | } | 115 | } |
116 | 116 | ||
117 | AddresseeCardView::~AddresseeCardView() | 117 | AddresseeCardView::~AddresseeCardView() |
118 | { | 118 | { |
119 | } | 119 | } |
120 | void AddresseeCardView::printMe() | 120 | void AddresseeCardView::printMe() |
121 | { | 121 | { |
122 | #ifdef DESKTOP_VERSION | 122 | #ifdef DESKTOP_VERSION |
123 | QPrinter printer; | 123 | QPrinter printer; |
124 | if (!printer.setup() ) | 124 | if (!printer.setup() ) |
125 | return; | 125 | return; |
126 | QPainter p; | 126 | QPainter p; |
127 | p.begin ( &printer ); | 127 | p.begin ( &printer ); |
128 | QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); | 128 | QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); |
129 | float dx, dy; | 129 | float dx, dy; |
130 | int wid = (m.width() * 9)/10; | 130 | int wid = (m.width() * 9)/10; |
131 | dx = (float) wid/(float)contentsWidth (); | 131 | dx = (float) wid/(float)contentsWidth (); |
132 | dy = (float)(m.height()) / (float)contentsHeight (); | 132 | dy = (float)(m.height()) / (float)contentsHeight (); |
133 | float scale; | 133 | float scale; |
134 | // scale to fit the width or height of the paper | 134 | // scale to fit the width or height of the paper |
135 | if ( dx < dy ) | 135 | if ( dx < dy ) |
136 | scale = dx; | 136 | scale = dx; |
137 | else | 137 | else |
138 | scale = dy; | 138 | scale = dy; |
139 | p.translate( m.width()/10,0 ); | 139 | p.translate( m.width()/10,0 ); |
140 | p.scale( scale, scale ); | 140 | p.scale( scale, scale ); |
141 | drawContents ( &p, 0,0, contentsWidth (), contentsHeight () ); | 141 | drawContents ( &p, 0,0, contentsWidth (), contentsHeight () ); |
142 | p.end(); | 142 | p.end(); |
143 | repaint(); | 143 | repaint(); |
144 | #endif | 144 | #endif |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) | 148 | void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) |
149 | { | 149 | { |
150 | #ifndef KAB_EMBEDDED | 150 | #ifndef KAB_EMBEDDED |
151 | if (QTextDrag::canDecode(e)) | 151 | if (QTextDrag::canDecode(e)) |
152 | e->accept(); | 152 | e->accept(); |
153 | #else //KAB_EMBEDDED | 153 | #else //KAB_EMBEDDED |
154 | qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); | 154 | qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); |
155 | #endif //KAB_EMBEDDED | 155 | #endif //KAB_EMBEDDED |
156 | } | 156 | } |
157 | 157 | ||
158 | void AddresseeCardView::dropEvent(QDropEvent *e) | 158 | void AddresseeCardView::dropEvent(QDropEvent *e) |
159 | { | 159 | { |
160 | emit addresseeDropped(e); | 160 | emit addresseeDropped(e); |
161 | } | 161 | } |
162 | 162 | ||
163 | void AddresseeCardView::startDrag() | 163 | void AddresseeCardView::startDrag() |
164 | { | 164 | { |
165 | emit startAddresseeDrag(); | 165 | emit startAddresseeDrag(); |
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
169 | /////////////////////////////// | 169 | /////////////////////////////// |
170 | // KAddressBookCardView | 170 | // KAddressBookCardView |
171 | 171 | ||
172 | KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, | 172 | KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, |
173 | QWidget *parent, const char *name ) | 173 | QWidget *parent, const char *name ) |
174 | : KAddressBookView( ab, parent, name ) | 174 | : KAddressBookView( ab, parent, name ) |
175 | { | 175 | { |
176 | mShowEmptyFields = false; | 176 | mShowEmptyFields = false; |
177 | 177 | ||
178 | // Init the GUI | 178 | // Init the GUI |
179 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); | 179 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); |
180 | 180 | ||
181 | mCardView = new AddresseeCardView(viewWidget(), "mCardView"); | 181 | mCardView = new AddresseeCardView(viewWidget(), "mCardView"); |
182 | mCardView->setSelectionMode(CardView::Extended); | 182 | mCardView->setSelectionMode(CardView::Extended); |
183 | layout->addWidget(mCardView); | 183 | layout->addWidget(mCardView); |
184 | 184 | ||
185 | // Connect up the signals | 185 | // Connect up the signals |
186 | connect(mCardView, SIGNAL(executed(CardViewItem *)), | 186 | connect(mCardView, SIGNAL(executed(CardViewItem *)), |
187 | this, SLOT(addresseeExecuted(CardViewItem *))); | 187 | this, SLOT(addresseeExecuted(CardViewItem *))); |
188 | connect(mCardView, SIGNAL(selectionChanged()), | 188 | connect(mCardView, SIGNAL(selectionChanged()), |
189 | this, SLOT(addresseeSelected())); | 189 | this, SLOT(addresseeSelected())); |
190 | connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), | 190 | connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), |
191 | this, SIGNAL(dropped(QDropEvent*))); | 191 | this, SIGNAL(dropped(QDropEvent*))); |
192 | connect(mCardView, SIGNAL(startAddresseeDrag()), | 192 | connect(mCardView, SIGNAL(startAddresseeDrag()), |
193 | this, SIGNAL(startDrag())); | 193 | this, SIGNAL(startDrag())); |
194 | connect(this, SIGNAL(printView()), | 194 | connect(this, SIGNAL(printView()), |
195 | mCardView , SLOT(printMe())); | 195 | mCardView , SLOT(printMe())); |
196 | } | 196 | } |
197 | 197 | ||
198 | KAddressBookCardView::~KAddressBookCardView() | 198 | KAddressBookCardView::~KAddressBookCardView() |
199 | { | 199 | { |
200 | } | 200 | } |
201 | void KAddressBookCardView::setFocusAV() | 201 | void KAddressBookCardView::setFocusAV() |
202 | { | 202 | { |
203 | if ( mCardView ) | 203 | if ( mCardView ) |
204 | mCardView->setFocus(); | 204 | mCardView->setFocus(); |
205 | 205 | ||
206 | } | 206 | } |
207 | void KAddressBookCardView::scrollUP() | 207 | void KAddressBookCardView::scrollUP() |
208 | { | 208 | { |
209 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); | 209 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); |
210 | QApplication::postEvent( mCardView, ev ); | 210 | QApplication::postEvent( mCardView, ev ); |
211 | 211 | ||
212 | } | 212 | } |
213 | void KAddressBookCardView::scrollDOWN() | 213 | void KAddressBookCardView::scrollDOWN() |
214 | { | 214 | { |
215 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); | 215 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); |
216 | QApplication::postEvent( mCardView, ev ); | 216 | QApplication::postEvent( mCardView, ev ); |
217 | } | 217 | } |
218 | void KAddressBookCardView::readConfig(KConfig *config) | 218 | void KAddressBookCardView::readConfig(KConfig *config) |
219 | { | 219 | { |
220 | KAddressBookView::readConfig(config); | 220 | KAddressBookView::readConfig(config); |
221 | 221 | ||
222 | // costum colors? | 222 | // costum colors? |
223 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) | 223 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) |
224 | { | 224 | { |
225 | QPalette p( mCardView->palette() ); | 225 | QPalette p( mCardView->palette() ); |
226 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); | 226 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); |
227 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); | 227 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); |
228 | c = p.color(QPalette::Normal, QColorGroup::Text ); | 228 | c = p.color(QPalette::Normal, QColorGroup::Text ); |
229 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); | 229 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); |
230 | c = p.color(QPalette::Normal, QColorGroup::Button ); | 230 | c = p.color(QPalette::Normal, QColorGroup::Button ); |
231 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); | 231 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); |
232 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); | 232 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); |
233 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); | 233 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); |
234 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); | 234 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); |
235 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); | 235 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); |
236 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); | 236 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); |
237 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); | 237 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); |
238 | mCardView->viewport()->setPalette( p ); | 238 | mCardView->viewport()->setPalette( p ); |
239 | } | 239 | } |
240 | else | 240 | else |
241 | { | 241 | { |
242 | // needed if turned off during a session. | 242 | // needed if turned off during a session. |
243 | mCardView->viewport()->setPalette( mCardView->palette() ); | 243 | mCardView->viewport()->setPalette( mCardView->palette() ); |
244 | } | 244 | } |
245 | 245 | ||
246 | //custom fonts? | 246 | //custom fonts? |
247 | QFont f( font() ); | 247 | QFont f( font() ); |
248 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) | 248 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) |
249 | { | 249 | { |
250 | mCardView->setFont( config->readFontEntry( "TextFont", &f) ); | 250 | mCardView->setFont( config->readFontEntry( "TextFont", &f) ); |
251 | f.setBold( true ); | 251 | f.setBold( true ); |
252 | mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); | 252 | mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); |
253 | } | 253 | } |
254 | else | 254 | else |
255 | { | 255 | { |
256 | mCardView->setFont( f ); | 256 | mCardView->setFont( f ); |
257 | f.setBold( true ); | 257 | f.setBold( true ); |
258 | mCardView->setHeaderFont( f ); | 258 | mCardView->setHeaderFont( f ); |
259 | } | 259 | } |
260 | 260 | ||
261 | mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); | 261 | mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); |
262 | mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", | 262 | mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", |
263 | true)); | 263 | true)); |
264 | mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); | 264 | mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); |
265 | mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); | 265 | mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); |
266 | 266 | ||
267 | mCardView->setShowEmptyFields( mShowEmptyFields ); | 267 | mCardView->setShowEmptyFields( mShowEmptyFields ); |
268 | 268 | ||
269 | mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); | 269 | mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); |
270 | mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); | 270 | mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); |
271 | mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); | 271 | mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); |
272 | mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); | 272 | mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); |
273 | 273 | ||
274 | #if 0 | 274 | #if 0 |
275 | // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven | 275 | // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven |
276 | disconnect(mCardView, SIGNAL(executed(CardViewItem *)), | 276 | disconnect(mCardView, SIGNAL(executed(CardViewItem *)), |
277 | this, SLOT(addresseeExecuted(CardViewItem *))); | 277 | this, SLOT(addresseeExecuted(CardViewItem *))); |
278 | 278 | ||
279 | if (KABPrefs::instance()->mHonorSingleClick) | 279 | if (KABPrefs::instance()->mHonorSingleClick) |
280 | connect(mCardView, SIGNAL(executed(CardViewItem *)), | 280 | connect(mCardView, SIGNAL(executed(CardViewItem *)), |
281 | this, SLOT(addresseeExecuted(CardViewItem *))); | 281 | this, SLOT(addresseeExecuted(CardViewItem *))); |
282 | else | 282 | else |
283 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), | 283 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), |
284 | this, SLOT(addresseeExecuted(CardViewItem *))); | 284 | this, SLOT(addresseeExecuted(CardViewItem *))); |
285 | #endif | 285 | #endif |
286 | 286 | ||
287 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), | 287 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), |
288 | this, SLOT(addresseeExecuted(CardViewItem *))); | 288 | this, SLOT(addresseeExecuted(CardViewItem *))); |
289 | } | 289 | } |
290 | 290 | ||
291 | void KAddressBookCardView::writeConfig( KConfig *config ) | 291 | void KAddressBookCardView::writeConfig( KConfig *config ) |
292 | { | 292 | { |
293 | config->writeEntry( "ItemWidth", mCardView->itemWidth() ); | 293 | config->writeEntry( "ItemWidth", mCardView->itemWidth() ); |
294 | KAddressBookView::writeConfig( config ); | 294 | KAddressBookView::writeConfig( config ); |
295 | } | 295 | } |
296 | void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) | 296 | void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) |
297 | { | 297 | { |
298 | mCardView->clear(); | 298 | mCardView->clear(); |
299 | if ( s.isEmpty() || s == "*" ) { | 299 | if ( s.isEmpty() || s == "*" ) { |
300 | refresh(); | 300 | refresh(); |
301 | return; | 301 | return; |
302 | } | 302 | } |
303 | QRegExp re = getRegExp( s ); | 303 | QRegExp re = getRegExp( s ); |
304 | if (!re.isValid()) | 304 | if (!re.isValid()) |
305 | return; | 305 | return; |
306 | mCardView->viewport()->setUpdatesEnabled( false ); | 306 | mCardView->viewport()->setUpdatesEnabled( false ); |
307 | KABC::Addressee::List addresseeList = addressees(); | 307 | KABC::Addressee::List addresseeList = addressees(); |
308 | KABC::Addressee::List::Iterator it; | 308 | KABC::Addressee::List::Iterator it; |
309 | if ( field ) { | 309 | if ( field ) { |
310 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 310 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
311 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) | 311 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) |
312 | continue; | 312 | continue; |
313 | #if QT_VERSION >= 0x030000 | 313 | #if QT_VERSION >= 0x030000 |
314 | if (re.search(field->value( *it ).lower()) != -1) | 314 | if (re.search(field->value( *it ).lower()) != -1) |
315 | #else | 315 | #else |
316 | if (re.match(field->value( *it ).lower()) != -1) | 316 | if (re.match(field->value( *it ).lower()) != -1) |
317 | #endif | 317 | #endif |
318 | new AddresseeCardViewItem(fields(), mShowEmptyFields, | 318 | new AddresseeCardViewItem(fields(), mShowEmptyFields, |
319 | addressBook(), *it, mCardView); | 319 | addressBook(), *it, mCardView); |
320 | 320 | ||
321 | } | 321 | } |
322 | } else { | 322 | } else { |
323 | KABC::Field::List fieldList = allFields(); | 323 | KABC::Field::List fieldList = allFields(); |
324 | KABC::Field::List::ConstIterator fieldIt; | 324 | KABC::Field::List::ConstIterator fieldIt; |
325 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 325 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
326 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) | 326 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) |
327 | continue; | 327 | continue; |
328 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | 328 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { |
329 | #if QT_VERSION >= 0x030000 | 329 | #if QT_VERSION >= 0x030000 |
330 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) | 330 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) |
331 | #else | 331 | #else |
332 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) | 332 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) |
333 | #endif | 333 | #endif |
334 | { | 334 | { |
335 | new AddresseeCardViewItem(fields(), mShowEmptyFields, | 335 | new AddresseeCardViewItem(fields(), mShowEmptyFields, |
336 | addressBook(), *it, mCardView); | 336 | addressBook(), *it, mCardView); |
337 | break; | 337 | break; |
338 | } | 338 | } |
339 | } | 339 | } |
340 | } | 340 | } |
341 | } | 341 | } |
342 | mCardView->viewport()->setUpdatesEnabled( true ); | 342 | mCardView->viewport()->setUpdatesEnabled( true ); |
343 | mCardView->viewport()->update(); | 343 | mCardView->viewport()->update(); |
344 | if ( mCardView->firstItem() ) { | 344 | if ( mCardView->firstItem() ) { |
345 | mCardView->setCurrentItem ( mCardView->firstItem() ); | 345 | mCardView->setCurrentItem ( mCardView->firstItem() ); |
346 | mCardView->setSelected ( mCardView->firstItem() , true ); | 346 | mCardView->setSelected ( mCardView->firstItem() , true ); |
347 | } | 347 | } |
348 | else | 348 | else |
349 | emit selected(QString::null); | 349 | emit selected(QString::null); |
350 | } | 350 | } |
351 | QStringList KAddressBookCardView::selectedUids() | 351 | QStringList KAddressBookCardView::selectedUids() |
352 | { | 352 | { |
353 | QStringList uidList; | 353 | QStringList uidList; |
354 | CardViewItem *item; | 354 | CardViewItem *item; |
355 | AddresseeCardViewItem *aItem; | 355 | AddresseeCardViewItem *aItem; |
356 | 356 | ||
357 | for (item = mCardView->firstItem(); item; item = item->nextItem()) | 357 | for (item = mCardView->firstItem(); item; item = item->nextItem()) |
358 | { | 358 | { |
359 | if (item->isSelected()) | 359 | if (item->isSelected()) |
360 | { | 360 | { |
361 | #ifndef KAB_EMBEDDED | 361 | #ifndef KAB_EMBEDDED |
362 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 362 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
363 | #else //KAB_EMBEDDED | 363 | #else //KAB_EMBEDDED |
364 | aItem = (AddresseeCardViewItem*)(item); | 364 | aItem = (AddresseeCardViewItem*)(item); |
365 | #endif //KAB_EMBEDDED | 365 | #endif //KAB_EMBEDDED |
366 | if (aItem) | 366 | if (aItem) |
367 | uidList << aItem->addressee().uid(); | 367 | uidList << aItem->addressee().uid(); |
368 | } | 368 | } |
369 | } | 369 | } |
370 | 370 | ||
371 | return uidList; | 371 | return uidList; |
372 | } | 372 | } |
373 | 373 | ||
374 | void KAddressBookCardView::refresh(QString uid) | 374 | void KAddressBookCardView::refresh(QString uid) |
375 | { | 375 | { |
376 | CardViewItem *item; | 376 | CardViewItem *item; |
377 | AddresseeCardViewItem *aItem; | 377 | AddresseeCardViewItem *aItem; |
378 | 378 | ||
379 | if (uid.isNull()) | 379 | if (uid.isNull()) |
380 | { | 380 | { |
381 | // Rebuild the view | 381 | // Rebuild the view |
382 | mCardView->viewport()->setUpdatesEnabled( false ); | 382 | mCardView->viewport()->setUpdatesEnabled( false ); |
383 | mCardView->clear(); | 383 | mCardView->clear(); |
384 | 384 | ||
385 | KABC::Addressee::List addresseeList = addressees(); | 385 | KABC::Addressee::List addresseeList = addressees(); |
386 | KABC::Addressee::List::Iterator iter; | 386 | KABC::Addressee::List::Iterator iter; |
387 | for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) | 387 | for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) |
388 | { | 388 | { |
389 | if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) | 389 | if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) |
390 | continue; | 390 | continue; |
391 | aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, | 391 | aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, |
392 | addressBook(), *iter, mCardView); | 392 | addressBook(), *iter, mCardView); |
393 | } | 393 | } |
394 | mCardView->viewport()->setUpdatesEnabled( true ); | 394 | mCardView->viewport()->setUpdatesEnabled( true ); |
395 | mCardView->viewport()->update(); | 395 | mCardView->viewport()->update(); |
396 | 396 | ||
397 | // by default nothing is selected | 397 | // by default nothing is selected |
398 | emit selected(QString::null); | 398 | emit selected(QString::null); |
399 | } | 399 | } |
400 | else | 400 | else |
401 | { | 401 | { |
402 | // Try to find the one to refresh | 402 | // Try to find the one to refresh |
403 | bool found = false; | 403 | bool found = false; |
404 | for (item = mCardView->firstItem(); item && !found; | 404 | for (item = mCardView->firstItem(); item && !found; |
405 | item = item->nextItem()) | 405 | item = item->nextItem()) |
406 | { | 406 | { |
407 | #ifndef KAB_EMBEDDED | 407 | #ifndef KAB_EMBEDDED |
408 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 408 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
409 | #else //KAB_EMBEDDED | 409 | #else //KAB_EMBEDDED |
410 | aItem = (AddresseeCardViewItem*)(item); | 410 | aItem = (AddresseeCardViewItem*)(item); |
411 | #endif //KAB_EMBEDDED | 411 | #endif //KAB_EMBEDDED |
412 | 412 | ||
413 | if ((aItem) && (aItem->addressee().uid() == uid)) | 413 | if ((aItem) && (aItem->addressee().uid() == uid)) |
414 | { | 414 | { |
415 | aItem->refresh(); | 415 | aItem->refresh(); |
416 | found = true; | 416 | found = true; |
417 | } | 417 | } |
418 | } | 418 | } |
419 | } | 419 | } |
420 | } | 420 | } |
421 | 421 | ||
422 | void KAddressBookCardView::setSelected(QString uid, bool selected) | 422 | void KAddressBookCardView::setSelected(QString uid, bool selected) |
423 | { | 423 | { |
424 | CardViewItem *item; | 424 | CardViewItem *item; |
425 | AddresseeCardViewItem *aItem; | 425 | AddresseeCardViewItem *aItem; |
426 | 426 | ||
427 | if (uid.isNull()) | 427 | if (uid.isNull()) |
428 | { | 428 | { |
429 | mCardView->selectAll(selected); | 429 | mCardView->selectAll(selected); |
430 | } | 430 | } |
431 | else | 431 | else |
432 | { | 432 | { |
433 | bool found = false; | 433 | bool found = false; |
434 | for (item = mCardView->firstItem(); item && !found; | 434 | for (item = mCardView->firstItem(); item && !found; |
435 | item = item->nextItem()) | 435 | item = item->nextItem()) |
436 | { | 436 | { |
437 | #ifndef KAB_EMBEDDED | 437 | #ifndef KAB_EMBEDDED |
438 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 438 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
439 | #else //KAB_EMBEDDED | 439 | #else //KAB_EMBEDDED |
440 | aItem = (AddresseeCardViewItem*)(item); | 440 | aItem = (AddresseeCardViewItem*)(item); |
441 | #endif //KAB_EMBEDDED | 441 | #endif //KAB_EMBEDDED |
442 | 442 | ||
443 | if ((aItem) && (aItem->addressee().uid() == uid)) | 443 | if ((aItem) && (aItem->addressee().uid() == uid)) |
444 | { | 444 | { |
445 | mCardView->setSelected(aItem, selected); | 445 | mCardView->setSelected(aItem, selected); |
446 | mCardView->ensureItemVisible(item); | 446 | mCardView->ensureItemVisible(item); |
447 | found = true; | 447 | found = true; |
448 | } | 448 | } |
449 | } | 449 | } |
450 | } | 450 | } |
451 | } | 451 | } |
452 | 452 | ||
453 | //US added an additional method without parameter | 453 | //US added an additional method without parameter |
454 | void KAddressBookCardView::setSelected() | 454 | void KAddressBookCardView::setSelected() |
455 | { | 455 | { |
456 | setSelected(QString::null, true); | 456 | setSelected(QString::null, true); |
457 | } | 457 | } |
458 | 458 | ||
459 | void KAddressBookCardView::addresseeExecuted(CardViewItem *item) | 459 | void KAddressBookCardView::addresseeExecuted(CardViewItem *item) |
460 | { | 460 | { |
461 | #ifndef KAB_EMBEDDED | 461 | #ifndef KAB_EMBEDDED |
462 | AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 462 | AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
463 | #else //KAB_EMBEDDED | 463 | #else //KAB_EMBEDDED |
464 | AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item); | 464 | AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item); |
465 | #endif //KAB_EMBEDDED | 465 | #endif //KAB_EMBEDDED |
466 | if (aItem) | 466 | if (aItem) |
467 | { | 467 | { |
468 | //kdDebug()<<"... even has a valid item:)"<<endl; | 468 | //kdDebug()<<"... even has a valid item:)"<<endl; |
469 | emit executed(aItem->addressee().uid()); | 469 | emit executed(aItem->addressee().uid()); |
470 | } | 470 | } |
471 | } | 471 | } |
472 | 472 | ||
473 | void KAddressBookCardView::addresseeSelected() | 473 | void KAddressBookCardView::addresseeSelected() |
474 | { | 474 | { |
475 | CardViewItem *item; | 475 | CardViewItem *item; |
476 | AddresseeCardViewItem *aItem; | 476 | AddresseeCardViewItem *aItem; |
477 | 477 | ||
478 | bool found = false; | 478 | bool found = false; |
479 | for (item = mCardView->firstItem(); item && !found; | 479 | for (item = mCardView->firstItem(); item && !found; |
480 | item = item->nextItem()) | 480 | item = item->nextItem()) |
481 | { | 481 | { |
482 | if (item->isSelected()) | 482 | if (item->isSelected()) |
483 | { | 483 | { |
484 | #ifndef KAB_EMBEDDED | 484 | #ifndef KAB_EMBEDDED |
485 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 485 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
486 | #else //KAB_EMBEDDED | 486 | #else //KAB_EMBEDDED |
487 | aItem = (AddresseeCardViewItem*)(item); | 487 | aItem = (AddresseeCardViewItem*)(item); |
488 | #endif //KAB_EMBEDDED | 488 | #endif //KAB_EMBEDDED |
489 | if ( aItem ) | 489 | if ( aItem ) |
490 | { | 490 | { |
491 | emit selected(aItem->addressee().uid()); | 491 | emit selected(aItem->addressee().uid()); |
492 | found = true; | 492 | found = true; |
493 | } | 493 | } |
494 | } | 494 | } |
495 | } | 495 | } |
496 | 496 | ||
497 | if (!found) | 497 | if (!found) |
498 | emit selected(QString::null); | 498 | emit selected(QString::null); |
499 | 499 | ||
500 | } | 500 | } |
501 | #ifndef KAB_EMBEDDED | 501 | #ifndef KAB_EMBEDDED |
502 | #include "kaddressbookcardview.moc" | 502 | #include "kaddressbookcardview.moc" |
503 | #endif //KAB_EMBEDDED | 503 | #endif //KAB_EMBEDDED |