Diffstat (limited to 'kaddressbook/views/kaddressbookcardview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp index b503652..1e5a556 100644 --- a/kaddressbook/views/kaddressbookcardview.cpp +++ b/kaddressbook/views/kaddressbookcardview.cpp | |||
@@ -1,62 +1,67 @@ | |||
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 <q3dragobject.h> |
25 | #include <qevent.h> | 25 | #include <qevent.h> |
26 | #include <qiconview.h> | 26 | #include <q3iconview.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 | //Added by qt3to4: | ||
32 | #include <QDropEvent> | ||
33 | #include <QKeyEvent> | ||
34 | #include <Q3VBoxLayout> | ||
35 | #include <QDragEnterEvent> | ||
31 | 36 | ||
32 | #include <kabc/addressbook.h> | 37 | #include <kabc/addressbook.h> |
33 | #include <kabc/addressee.h> | 38 | #include <kabc/addressee.h> |
34 | #include <kconfig.h> | 39 | #include <kconfig.h> |
35 | #include <kdebug.h> | 40 | #include <kdebug.h> |
36 | #include <klocale.h> | 41 | #include <klocale.h> |
37 | 42 | ||
38 | #include "kabprefs.h" | 43 | #include "kabprefs.h" |
39 | #include "viewmanager.h" | 44 | #include "viewmanager.h" |
40 | 45 | ||
41 | 46 | ||
42 | #include "kaddressbookcardview.h" | 47 | #include "kaddressbookcardview.h" |
43 | 48 | ||
44 | #ifndef KAB_EMBEDDED | 49 | #ifndef KAB_EMBEDDED |
45 | extern "C" { | 50 | extern "C" { |
46 | void *init_libkaddrbk_cardview() | 51 | void *init_libkaddrbk_cardview() |
47 | { | 52 | { |
48 | return ( new CardViewFactory ); | 53 | return ( new CardViewFactory ); |
49 | } | 54 | } |
50 | } | 55 | } |
51 | #endif //KAB_EMBEDDED | 56 | #endif //KAB_EMBEDDED |
52 | 57 | ||
53 | //////////////////////////////// | 58 | //////////////////////////////// |
54 | // AddresseeCardViewItem (internal class) | 59 | // AddresseeCardViewItem (internal class) |
55 | class AddresseeCardViewItem : public CardViewItem | 60 | class AddresseeCardViewItem : public CardViewItem |
56 | { | 61 | { |
57 | public: | 62 | public: |
58 | AddresseeCardViewItem(const KABC::Field::List &fields, | 63 | AddresseeCardViewItem(const KABC::Field::List &fields, |
59 | bool showEmptyFields, | 64 | bool showEmptyFields, |
60 | KABC::AddressBook *doc, const KABC::Addressee &a, | 65 | KABC::AddressBook *doc, const KABC::Addressee &a, |
61 | CardView *parent) | 66 | CardView *parent) |
62 | : CardViewItem(parent, a.realName() ), | 67 | : CardViewItem(parent, a.realName() ), |
@@ -96,116 +101,116 @@ class AddresseeCardViewItem : public CardViewItem | |||
96 | // We might want to make this the first field. hmm... -mpilone | 101 | // We might want to make this the first field. hmm... -mpilone |
97 | setCaption( mAddressee.realName() ); | 102 | setCaption( mAddressee.realName() ); |
98 | } | 103 | } |
99 | } | 104 | } |
100 | 105 | ||
101 | private: | 106 | private: |
102 | KABC::Field::List mFields; | 107 | KABC::Field::List mFields; |
103 | bool mShowEmptyFields; | 108 | bool mShowEmptyFields; |
104 | KABC::AddressBook *mDocument; | 109 | KABC::AddressBook *mDocument; |
105 | KABC::Addressee mAddressee; | 110 | KABC::Addressee mAddressee; |
106 | }; | 111 | }; |
107 | 112 | ||
108 | /////////////////////////////// | 113 | /////////////////////////////// |
109 | // AddresseeCardView | 114 | // AddresseeCardView |
110 | 115 | ||
111 | AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) | 116 | AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) |
112 | : CardView(parent, name) | 117 | : CardView(parent, name) |
113 | { | 118 | { |
114 | setAcceptDrops(true); | 119 | setAcceptDrops(true); |
115 | } | 120 | } |
116 | 121 | ||
117 | AddresseeCardView::~AddresseeCardView() | 122 | AddresseeCardView::~AddresseeCardView() |
118 | { | 123 | { |
119 | } | 124 | } |
120 | void AddresseeCardView::printMe() | 125 | void AddresseeCardView::printMe() |
121 | { | 126 | { |
122 | #ifdef DESKTOP_VERSION | 127 | #ifdef DESKTOP_VERSION |
123 | QPrinter printer; | 128 | QPrinter printer; |
124 | if (!printer.setup() ) | 129 | if (!printer.setup() ) |
125 | return; | 130 | return; |
126 | QPainter p; | 131 | QPainter p; |
127 | p.begin ( &printer ); | 132 | p.begin ( &printer ); |
128 | QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); | 133 | Q3PaintDeviceMetrics m = Q3PaintDeviceMetrics ( &printer ); |
129 | float dx, dy; | 134 | float dx, dy; |
130 | int wid = (m.width() * 9)/10; | 135 | int wid = (m.width() * 9)/10; |
131 | dx = (float) wid/(float)contentsWidth (); | 136 | dx = (float) wid/(float)contentsWidth (); |
132 | dy = (float)(m.height()) / (float)contentsHeight (); | 137 | dy = (float)(m.height()) / (float)contentsHeight (); |
133 | float scale; | 138 | float scale; |
134 | // scale to fit the width or height of the paper | 139 | // scale to fit the width or height of the paper |
135 | if ( dx < dy ) | 140 | if ( dx < dy ) |
136 | scale = dx; | 141 | scale = dx; |
137 | else | 142 | else |
138 | scale = dy; | 143 | scale = dy; |
139 | p.translate( m.width()/10,0 ); | 144 | p.translate( m.width()/10,0 ); |
140 | p.scale( scale, scale ); | 145 | p.scale( scale, scale ); |
141 | drawContents ( &p, 0,0, contentsWidth (), contentsHeight () ); | 146 | drawContents ( &p, 0,0, contentsWidth (), contentsHeight () ); |
142 | p.end(); | 147 | p.end(); |
143 | repaint(); | 148 | repaint(); |
144 | #endif | 149 | #endif |
145 | } | 150 | } |
146 | 151 | ||
147 | 152 | ||
148 | void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) | 153 | void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) |
149 | { | 154 | { |
150 | #ifndef KAB_EMBEDDED | 155 | #ifndef KAB_EMBEDDED |
151 | if (QTextDrag::canDecode(e)) | 156 | if (Q3TextDrag::canDecode(e)) |
152 | e->accept(); | 157 | e->accept(); |
153 | #else //KAB_EMBEDDED | 158 | #else //KAB_EMBEDDED |
154 | qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); | 159 | qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); |
155 | #endif //KAB_EMBEDDED | 160 | #endif //KAB_EMBEDDED |
156 | } | 161 | } |
157 | 162 | ||
158 | void AddresseeCardView::dropEvent(QDropEvent *e) | 163 | void AddresseeCardView::dropEvent(QDropEvent *e) |
159 | { | 164 | { |
160 | emit addresseeDropped(e); | 165 | emit addresseeDropped(e); |
161 | } | 166 | } |
162 | 167 | ||
163 | void AddresseeCardView::startDrag() | 168 | void AddresseeCardView::startDrag() |
164 | { | 169 | { |
165 | emit startAddresseeDrag(); | 170 | emit startAddresseeDrag(); |
166 | } | 171 | } |
167 | 172 | ||
168 | 173 | ||
169 | /////////////////////////////// | 174 | /////////////////////////////// |
170 | // KAddressBookCardView | 175 | // KAddressBookCardView |
171 | 176 | ||
172 | KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, | 177 | KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, |
173 | QWidget *parent, const char *name ) | 178 | QWidget *parent, const char *name ) |
174 | : KAddressBookView( ab, parent, name ) | 179 | : KAddressBookView( ab, parent, name ) |
175 | { | 180 | { |
176 | mShowEmptyFields = false; | 181 | mShowEmptyFields = false; |
177 | 182 | ||
178 | // Init the GUI | 183 | // Init the GUI |
179 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); | 184 | Q3VBoxLayout *layout = new Q3VBoxLayout(viewWidget()); |
180 | 185 | ||
181 | mCardView = new AddresseeCardView(viewWidget(), "mCardView"); | 186 | mCardView = new AddresseeCardView(viewWidget(), "mCardView"); |
182 | mCardView->setSelectionMode(CardView::Extended); | 187 | mCardView->setSelectionMode(CardView::Extended); |
183 | layout->addWidget(mCardView); | 188 | layout->addWidget(mCardView); |
184 | 189 | ||
185 | // Connect up the signals | 190 | // Connect up the signals |
186 | connect(mCardView, SIGNAL(executed(CardViewItem *)), | 191 | connect(mCardView, SIGNAL(executed(CardViewItem *)), |
187 | this, SLOT(addresseeExecuted(CardViewItem *))); | 192 | this, SLOT(addresseeExecuted(CardViewItem *))); |
188 | connect(mCardView, SIGNAL(selectionChanged()), | 193 | connect(mCardView, SIGNAL(selectionChanged()), |
189 | this, SLOT(addresseeSelected())); | 194 | this, SLOT(addresseeSelected())); |
190 | connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), | 195 | connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), |
191 | this, SIGNAL(dropped(QDropEvent*))); | 196 | this, SIGNAL(dropped(QDropEvent*))); |
192 | connect(mCardView, SIGNAL(startAddresseeDrag()), | 197 | connect(mCardView, SIGNAL(startAddresseeDrag()), |
193 | this, SIGNAL(startDrag())); | 198 | this, SIGNAL(startDrag())); |
194 | connect(this, SIGNAL(printView()), | 199 | connect(this, SIGNAL(printView()), |
195 | mCardView , SLOT(printMe())); | 200 | mCardView , SLOT(printMe())); |
196 | } | 201 | } |
197 | 202 | ||
198 | KAddressBookCardView::~KAddressBookCardView() | 203 | KAddressBookCardView::~KAddressBookCardView() |
199 | { | 204 | { |
200 | } | 205 | } |
201 | void KAddressBookCardView::setFocusAV() | 206 | void KAddressBookCardView::setFocusAV() |
202 | { | 207 | { |
203 | if ( mCardView ) | 208 | if ( mCardView ) |
204 | mCardView->setFocus(); | 209 | mCardView->setFocus(); |
205 | 210 | ||
206 | } | 211 | } |
207 | void KAddressBookCardView::scrollUP() | 212 | void KAddressBookCardView::scrollUP() |
208 | { | 213 | { |
209 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); | 214 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); |
210 | QApplication::postEvent( mCardView, ev ); | 215 | QApplication::postEvent( mCardView, ev ); |
211 | ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Up, 0,0 ); | 216 | ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Up, 0,0 ); |
@@ -491,35 +496,35 @@ void KAddressBookCardView::addresseeExecuted(CardViewItem *item) | |||
491 | emit executed(aItem->addressee().uid()); | 496 | emit executed(aItem->addressee().uid()); |
492 | } | 497 | } |
493 | } | 498 | } |
494 | 499 | ||
495 | void KAddressBookCardView::addresseeSelected() | 500 | void KAddressBookCardView::addresseeSelected() |
496 | { | 501 | { |
497 | CardViewItem *item; | 502 | CardViewItem *item; |
498 | AddresseeCardViewItem *aItem; | 503 | AddresseeCardViewItem *aItem; |
499 | 504 | ||
500 | bool found = false; | 505 | bool found = false; |
501 | for (item = mCardView->firstItem(); item && !found; | 506 | for (item = mCardView->firstItem(); item && !found; |
502 | item = item->nextItem()) | 507 | item = item->nextItem()) |
503 | { | 508 | { |
504 | if (item->isSelected()) | 509 | if (item->isSelected()) |
505 | { | 510 | { |
506 | #ifndef KAB_EMBEDDED | 511 | #ifndef KAB_EMBEDDED |
507 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 512 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
508 | #else //KAB_EMBEDDED | 513 | #else //KAB_EMBEDDED |
509 | aItem = (AddresseeCardViewItem*)(item); | 514 | aItem = (AddresseeCardViewItem*)(item); |
510 | #endif //KAB_EMBEDDED | 515 | #endif //KAB_EMBEDDED |
511 | if ( aItem ) | 516 | if ( aItem ) |
512 | { | 517 | { |
513 | emit selected(aItem->addressee().uid()); | 518 | emit selected(aItem->addressee().uid()); |
514 | found = true; | 519 | found = true; |
515 | } | 520 | } |
516 | } | 521 | } |
517 | } | 522 | } |
518 | 523 | ||
519 | if (!found) | 524 | if (!found) |
520 | emit selected(QString::null); | 525 | emit selected(QString::null); |
521 | 526 | ||
522 | } | 527 | } |
523 | #ifndef KAB_EMBEDDED | 528 | #ifndef KAB_EMBEDDED_ |
524 | #include "kaddressbookcardview.moc" | 529 | #include "moc_kaddressbookcardview.cpp" |
525 | #endif //KAB_EMBEDDED | 530 | #endif //KAB_EMBEDDED |