summaryrefslogtreecommitdiffabout
path: root/kaddressbook/views/kaddressbookcardview.cpp
Unidiff
Diffstat (limited to 'kaddressbook/views/kaddressbookcardview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp
index 2d7ed08..107be59 100644
--- a/kaddressbook/views/kaddressbookcardview.cpp
+++ b/kaddressbook/views/kaddressbookcardview.cpp
@@ -17,48 +17,49 @@
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#include "kaddressbookcardview.h" 42#include "kaddressbookcardview.h"
42 43
43#ifndef KAB_EMBEDDED 44#ifndef KAB_EMBEDDED
44extern "C" { 45extern "C" {
45 void *init_libkaddrbk_cardview() 46 void *init_libkaddrbk_cardview()
46 { 47 {
47 return ( new CardViewFactory ); 48 return ( new CardViewFactory );
48 } 49 }
49} 50}
50#endif //KAB_EMBEDDED 51#endif //KAB_EMBEDDED
51 52
52//////////////////////////////// 53////////////////////////////////
53// AddresseeCardViewItem (internal class) 54// AddresseeCardViewItem (internal class)
54class AddresseeCardViewItem : public CardViewItem 55class AddresseeCardViewItem : public CardViewItem
55{ 56{
56 public: 57 public:
57 AddresseeCardViewItem(const KABC::Field::List &fields, 58 AddresseeCardViewItem(const KABC::Field::List &fields,
58 bool showEmptyFields, 59 bool showEmptyFields,
59 KABC::AddressBook *doc, const KABC::Addressee &a, 60 KABC::AddressBook *doc, const KABC::Addressee &a,
60 CardView *parent) 61 CardView *parent)
61 : CardViewItem(parent, a.formattedName()), 62 : CardViewItem(parent, a.formattedName()),
62 mFields( fields ), mShowEmptyFields(showEmptyFields), 63 mFields( fields ), mShowEmptyFields(showEmptyFields),
63 mDocument(doc), mAddressee(a) 64 mDocument(doc), mAddressee(a)
64 { 65 {
@@ -95,96 +96,124 @@ class AddresseeCardViewItem : public CardViewItem
95 // We might want to make this the first field. hmm... -mpilone 96 // We might want to make this the first field. hmm... -mpilone
96 setCaption( mAddressee.realName() ); 97 setCaption( mAddressee.realName() );
97 } 98 }
98 } 99 }
99 100
100 private: 101 private:
101 KABC::Field::List mFields; 102 KABC::Field::List mFields;
102 bool mShowEmptyFields; 103 bool mShowEmptyFields;
103 KABC::AddressBook *mDocument; 104 KABC::AddressBook *mDocument;
104 KABC::Addressee mAddressee; 105 KABC::Addressee mAddressee;
105}; 106};
106 107
107/////////////////////////////// 108///////////////////////////////
108// AddresseeCardView 109// AddresseeCardView
109 110
110AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) 111AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name)
111 : CardView(parent, name) 112 : CardView(parent, name)
112{ 113{
113 setAcceptDrops(true); 114 setAcceptDrops(true);
114} 115}
115 116
116AddresseeCardView::~AddresseeCardView() 117AddresseeCardView::~AddresseeCardView()
117{ 118{
118} 119}
120void AddresseeCardView::printMe()
121{
122#ifdef DESKTOP_VERSION
123 QPrinter printer;
124 if (!printer.setup() )
125 return;
126 QPainter p;
127 p.begin ( &printer );
128 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
129 float dx, dy;
130 int wid = (m.width() * 9)/10;
131 dx = (float) wid/(float)contentsWidth ();
132 dy = (float)(m.height()) / (float)contentsHeight ();
133 float scale;
134 // scale to fit the width or height of the paper
135 if ( dx < dy )
136 scale = dx;
137 else
138 scale = dy;
139 p.translate( m.width()/10,0 );
140 p.scale( scale, scale );
141 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
142 p.end();
143 repaint();
144#endif
145}
119 146
120 147
121void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) 148void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e)
122{ 149{
123#ifndef KAB_EMBEDDED 150#ifndef KAB_EMBEDDED
124 if (QTextDrag::canDecode(e)) 151 if (QTextDrag::canDecode(e))
125 e->accept(); 152 e->accept();
126#else //KAB_EMBEDDED 153#else //KAB_EMBEDDED
127qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); 154qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented");
128#endif //KAB_EMBEDDED 155#endif //KAB_EMBEDDED
129} 156}
130 157
131void AddresseeCardView::dropEvent(QDropEvent *e) 158void AddresseeCardView::dropEvent(QDropEvent *e)
132{ 159{
133 emit addresseeDropped(e); 160 emit addresseeDropped(e);
134} 161}
135 162
136void AddresseeCardView::startDrag() 163void AddresseeCardView::startDrag()
137{ 164{
138 emit startAddresseeDrag(); 165 emit startAddresseeDrag();
139} 166}
140 167
141 168
142/////////////////////////////// 169///////////////////////////////
143// KAddressBookCardView 170// KAddressBookCardView
144 171
145KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, 172KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab,
146 QWidget *parent, const char *name ) 173 QWidget *parent, const char *name )
147 : KAddressBookView( ab, parent, name ) 174 : KAddressBookView( ab, parent, name )
148{ 175{
149 mShowEmptyFields = false; 176 mShowEmptyFields = false;
150 177
151 // Init the GUI 178 // Init the GUI
152 QVBoxLayout *layout = new QVBoxLayout(viewWidget()); 179 QVBoxLayout *layout = new QVBoxLayout(viewWidget());
153 180
154 mCardView = new AddresseeCardView(viewWidget(), "mCardView"); 181 mCardView = new AddresseeCardView(viewWidget(), "mCardView");
155 mCardView->setSelectionMode(CardView::Extended); 182 mCardView->setSelectionMode(CardView::Extended);
156 layout->addWidget(mCardView); 183 layout->addWidget(mCardView);
157 184
158 // Connect up the signals 185 // Connect up the signals
159 connect(mCardView, SIGNAL(executed(CardViewItem *)), 186 connect(mCardView, SIGNAL(executed(CardViewItem *)),
160 this, SLOT(addresseeExecuted(CardViewItem *))); 187 this, SLOT(addresseeExecuted(CardViewItem *)));
161 connect(mCardView, SIGNAL(selectionChanged()), 188 connect(mCardView, SIGNAL(selectionChanged()),
162 this, SLOT(addresseeSelected())); 189 this, SLOT(addresseeSelected()));
163 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), 190 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)),
164 this, SIGNAL(dropped(QDropEvent*))); 191 this, SIGNAL(dropped(QDropEvent*)));
165 connect(mCardView, SIGNAL(startAddresseeDrag()), 192 connect(mCardView, SIGNAL(startAddresseeDrag()),
166 this, SIGNAL(startDrag())); 193 this, SIGNAL(startDrag()));
194 connect(this, SIGNAL(printView()),
195 mCardView , SLOT(printMe()));
167} 196}
168 197
169KAddressBookCardView::~KAddressBookCardView() 198KAddressBookCardView::~KAddressBookCardView()
170{ 199{
171} 200}
172void KAddressBookCardView::setFocusAV() 201void KAddressBookCardView::setFocusAV()
173{ 202{
174 if ( mCardView ) 203 if ( mCardView )
175 mCardView->setFocus(); 204 mCardView->setFocus();
176 205
177} 206}
178void KAddressBookCardView::scrollUP() 207void KAddressBookCardView::scrollUP()
179{ 208{
180 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); 209 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
181 QApplication::postEvent( mCardView, ev ); 210 QApplication::postEvent( mCardView, ev );
182 211
183} 212}
184void KAddressBookCardView::scrollDOWN() 213void KAddressBookCardView::scrollDOWN()
185{ 214{
186 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 215 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
187 QApplication::postEvent( mCardView, ev ); 216 QApplication::postEvent( mCardView, ev );
188} 217}
189void KAddressBookCardView::readConfig(KConfig *config) 218void KAddressBookCardView::readConfig(KConfig *config)
190{ 219{