summaryrefslogtreecommitdiffabout
path: root/kaddressbook/views
Side-by-side diff
Diffstat (limited to 'kaddressbook/views') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/views/contactlistview.cpp27
-rw-r--r--kaddressbook/views/contactlistview.h1
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp29
-rw-r--r--kaddressbook/views/kaddressbookcardview.h2
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp2
5 files changed, 61 insertions, 0 deletions
diff --git a/kaddressbook/views/contactlistview.cpp b/kaddressbook/views/contactlistview.cpp
index 23b091c..e75810e 100644
--- a/kaddressbook/views/contactlistview.cpp
+++ b/kaddressbook/views/contactlistview.cpp
@@ -232,96 +232,123 @@ void ContactListViewItem::refresh()
int i = 0;
KABC::Field::List::ConstIterator it;
for( it = mFields.begin(); it != mFields.end(); ++it ) {
setText( i++, (*it)->value( mAddressee ) );
}
}
///////////////////////////////
// ContactListView
ContactListView::ContactListView(KAddressBookTableView *view,
KABC::AddressBook* /* doc */,
QWidget *parent,
const char *name )
: KListView( parent, name ),
pabWidget( view ),
oldColumn( 0 )
{
mABackground = true;
mSingleLine = false;
mToolTips = true;
#ifndef KAB_EMBEDDED
mAlternateColor = KGlobalSettings::alternateBackgroundColor();
#else //KAB_EMBEDDED
mAlternateColor = QColor(240, 240, 240);
#endif //KAB_EMBEDDED
setAlternateBackgroundEnabled(mABackground);
setAcceptDrops( true );
viewport()->setAcceptDrops( true );
setAllColumnsShowFocus( true );
setShowSortIndicator(true);
setSelectionModeExt( KListView::Extended );
setDropVisualizer(false);
// setFrameStyle(QFrame::NoFrame);
//setLineWidth ( 0 );
//setMidLineWidth ( 0 );
//setMargin ( 0 );
#ifndef KAB_EMBEDDED
connect(this, SIGNAL(dropped(QDropEvent*)),
this, SLOT(itemDropped(QDropEvent*)));
#endif //KAB_EMBEDDED
new DynamicTip( this );
}
+void ContactListView::printMe()
+{
+#ifdef DESKTOP_VERSION
+ QPrinter printer;
+ if (!printer.setup() )
+ return;
+ QPainter p;
+ p.begin ( &printer );
+ QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
+ float dx, dy;
+ int wid = (m.width() * 9)/10;
+ dx = (float) wid/(float)contentsWidth ();
+ dy = (float)(m.height()) / (float)contentsHeight ();
+ float scale;
+ // scale to fit the width or height of the paper
+ if ( dx < dy )
+ scale = dx;
+ else
+ scale = dy;
+ p.translate( m.width()/10,0 );
+ p.scale( scale, scale );
+ qDebug("scale %f ", scale);
+ drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
+ p.end();
+ qDebug("Why does it not print??? ");
+#endif
+}
void ContactListView::setAlternateColor(const QColor &m_AlternateColor)
{
mAlternateColor = m_AlternateColor;
}
void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect )
{
QBrush b = palette().brush(QPalette::Active, QColorGroup::Base);
// Get the brush, which will have the background pixmap if there is one.
if (b.pixmap())
{
p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(),
*(b.pixmap()),
rect.left() + contentsX(),
rect.top() + contentsY() );
}
else
{
// Do a normal paint
KListView::paintEmptyArea(p, rect);
}
}
void ContactListView::contentsMousePressEvent(QMouseEvent* e)
{
presspos = e->pos();
KListView::contentsMousePressEvent(e);
}
// To initiate a drag operation
void ContactListView::contentsMouseMoveEvent( QMouseEvent *e )
{
if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) {
emit startAddresseeDrag();
}
else
KListView::contentsMouseMoveEvent( e );
}
bool ContactListView::acceptDrag(QDropEvent *e) const
{
#ifndef KAB_EMBEDDED
return QTextDrag::canDecode(e);
#else //KAB_EMBEDDED
diff --git a/kaddressbook/views/contactlistview.h b/kaddressbook/views/contactlistview.h
index fad7f38..9d1a672 100644
--- a/kaddressbook/views/contactlistview.h
+++ b/kaddressbook/views/contactlistview.h
@@ -60,70 +60,71 @@ private:
// ContactListView
class ContactListView : public KListView
{
Q_OBJECT
public:
ContactListView(KAddressBookTableView *view,
KABC::AddressBook *doc,
QWidget *parent,
const char *name = 0L );
virtual ~ContactListView() {}
//void resort();
/** Returns true if tooltips should be displayed, false otherwise
*/
bool tooltips() const { return mToolTips; }
void setToolTipsEnabled(bool enabled) { mToolTips = enabled; }
bool alternateBackground() const { return mABackground; }
void setAlternateBackgroundEnabled(bool enabled);
bool singleLine() const { return mSingleLine; }
void setSingleLineEnabled(bool enabled) { mSingleLine = enabled; }
const QColor &alternateColor() const { return mAlternateColor; }
void setAlternateColor(const QColor &mAlternateColor);
/** Sets the background pixmap to <i>filename</i>. If the
* QString is empty (QString::isEmpty()), then the background
* pixmap will be disabled.
*/
void setBackgroundPixmap(const QString &filename);
protected:
/** Paints the background pixmap in the empty area. This method is needed
* since Qt::FixedPixmap will not scroll with the list view.
*/
virtual void paintEmptyArea( QPainter * p, const QRect & rect );
virtual void contentsMousePressEvent(QMouseEvent*);
void contentsMouseMoveEvent( QMouseEvent *e );
void contentsDropEvent( QDropEvent *e );
virtual bool acceptDrag(QDropEvent *e) const;
protected slots:
void itemDropped(QDropEvent *e);
public slots:
+ void printMe();
signals:
void startAddresseeDrag();
void addresseeDropped(QDropEvent *);
private:
KAddressBookTableView *pabWidget;
int oldColumn;
int column;
bool ascending;
bool mABackground;
bool mSingleLine;
bool mToolTips;
QColor mAlternateColor;
QPoint presspos;
};
#endif
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
@@ -1,214 +1,243 @@
/*
This file is part of KAddressBook.
Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
#include <qdragobject.h>
#include <qevent.h>
#include <qiconview.h>
#include <qlayout.h>
#include <qstringlist.h>
#include <qregexp.h>
#include <qapplication.h>
#include <kabc/addressbook.h>
#include <kabc/addressee.h>
#include <kconfig.h>
#include <kdebug.h>
#include <klocale.h>
#include "kabprefs.h"
#include "viewmanager.h"
+
#include "kaddressbookcardview.h"
#ifndef KAB_EMBEDDED
extern "C" {
void *init_libkaddrbk_cardview()
{
return ( new CardViewFactory );
}
}
#endif //KAB_EMBEDDED
////////////////////////////////
// AddresseeCardViewItem (internal class)
class AddresseeCardViewItem : public CardViewItem
{
public:
AddresseeCardViewItem(const KABC::Field::List &fields,
bool showEmptyFields,
KABC::AddressBook *doc, const KABC::Addressee &a,
CardView *parent)
: CardViewItem(parent, a.formattedName()),
mFields( fields ), mShowEmptyFields(showEmptyFields),
mDocument(doc), mAddressee(a)
{
if ( mFields.isEmpty() ) {
mFields = KABC::Field::defaultFields();
}
refresh();
}
const KABC::Addressee &addressee() const { return mAddressee; }
void refresh()
{
// Update our addressee, since it may have changed elsewhere
mAddressee = mDocument->findByUid(mAddressee.uid());
if (!mAddressee.isEmpty())
{
clearFields();
// Try all the selected fields until we find one with text.
// This will limit the number of unlabeled icons in the view
KABC::Field::List::Iterator iter;
for (iter = mFields.begin(); iter != mFields.end(); ++iter)
{
// insert empty fields or not? not doing so saves a bit of memory and CPU
// (during geometry calculations), but prevents having equally
// wide label columns in all cards, unless CardViewItem/CardView search
// globally for the widest label. (anders)
//if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty())
insertField((*iter)->label(), (*iter)->value( mAddressee ));
}
// We might want to make this the first field. hmm... -mpilone
setCaption( mAddressee.realName() );
}
}
private:
KABC::Field::List mFields;
bool mShowEmptyFields;
KABC::AddressBook *mDocument;
KABC::Addressee mAddressee;
};
///////////////////////////////
// AddresseeCardView
AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name)
: CardView(parent, name)
{
setAcceptDrops(true);
}
AddresseeCardView::~AddresseeCardView()
{
}
+void AddresseeCardView::printMe()
+{
+#ifdef DESKTOP_VERSION
+ QPrinter printer;
+ if (!printer.setup() )
+ return;
+ QPainter p;
+ p.begin ( &printer );
+ QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
+ float dx, dy;
+ int wid = (m.width() * 9)/10;
+ dx = (float) wid/(float)contentsWidth ();
+ dy = (float)(m.height()) / (float)contentsHeight ();
+ float scale;
+ // scale to fit the width or height of the paper
+ if ( dx < dy )
+ scale = dx;
+ else
+ scale = dy;
+ p.translate( m.width()/10,0 );
+ p.scale( scale, scale );
+ drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
+ p.end();
+ repaint();
+#endif
+}
void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e)
{
#ifndef KAB_EMBEDDED
if (QTextDrag::canDecode(e))
e->accept();
#else //KAB_EMBEDDED
qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented");
#endif //KAB_EMBEDDED
}
void AddresseeCardView::dropEvent(QDropEvent *e)
{
emit addresseeDropped(e);
}
void AddresseeCardView::startDrag()
{
emit startAddresseeDrag();
}
///////////////////////////////
// KAddressBookCardView
KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab,
QWidget *parent, const char *name )
: KAddressBookView( ab, parent, name )
{
mShowEmptyFields = false;
// Init the GUI
QVBoxLayout *layout = new QVBoxLayout(viewWidget());
mCardView = new AddresseeCardView(viewWidget(), "mCardView");
mCardView->setSelectionMode(CardView::Extended);
layout->addWidget(mCardView);
// Connect up the signals
connect(mCardView, SIGNAL(executed(CardViewItem *)),
this, SLOT(addresseeExecuted(CardViewItem *)));
connect(mCardView, SIGNAL(selectionChanged()),
this, SLOT(addresseeSelected()));
connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)),
this, SIGNAL(dropped(QDropEvent*)));
connect(mCardView, SIGNAL(startAddresseeDrag()),
this, SIGNAL(startDrag()));
+ connect(this, SIGNAL(printView()),
+ mCardView , SLOT(printMe()));
}
KAddressBookCardView::~KAddressBookCardView()
{
}
void KAddressBookCardView::setFocusAV()
{
if ( mCardView )
mCardView->setFocus();
}
void KAddressBookCardView::scrollUP()
{
QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
QApplication::postEvent( mCardView, ev );
}
void KAddressBookCardView::scrollDOWN()
{
QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
QApplication::postEvent( mCardView, ev );
}
void KAddressBookCardView::readConfig(KConfig *config)
{
KAddressBookView::readConfig(config);
// costum colors?
if ( config->readBoolEntry( "EnableCustomColors", false ) )
{
QPalette p( mCardView->palette() );
QColor c = p.color(QPalette::Normal, QColorGroup::Base );
p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
c = p.color(QPalette::Normal, QColorGroup::Text );
p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
c = p.color(QPalette::Normal, QColorGroup::Button );
p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
c = p.color(QPalette::Normal, QColorGroup::ButtonText );
p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
c = p.color(QPalette::Normal, QColorGroup::Highlight );
p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
mCardView->viewport()->setPalette( p );
}
else
{
// needed if turned off during a session.
mCardView->viewport()->setPalette( mCardView->palette() );
diff --git a/kaddressbook/views/kaddressbookcardview.h b/kaddressbook/views/kaddressbookcardview.h
index 8f22d54..2a71f7e 100644
--- a/kaddressbook/views/kaddressbookcardview.h
+++ b/kaddressbook/views/kaddressbookcardview.h
@@ -40,81 +40,83 @@ class QDragEntryEvent;
class QDropEvent;
class KConfig;
class AddresseeCardView;
/**
This view uses the CardView class to create a card view. At some
point in the future I think this will be the default view of
KAddressBook.
*/
class KAddressBookCardView : public KAddressBookView
{
Q_OBJECT
public:
KAddressBookCardView( KABC::AddressBook *ab, QWidget *parent,
const char *name = 0 );
virtual ~KAddressBookCardView();
void doSearch( const QString& s,KABC::Field *field );
virtual QStringList selectedUids();
virtual QString type() const { return "Card"; }
virtual void readConfig(KConfig *config);
virtual void writeConfig(KConfig *);
virtual void scrollUP();
virtual void scrollDOWN();
virtual void setFocusAV();
public slots:
void refresh(QString uid = QString::null);
void setSelected(QString uid/*US = QString::null*/, bool selected/*US = true*/);
//US added an additional method without parameter
void setSelected();
protected slots:
void addresseeExecuted(CardViewItem *item);
void addresseeSelected();
private:
AddresseeCardView *mCardView;
bool mShowEmptyFields;
};
class AddresseeCardView : public CardView
{
Q_OBJECT
public:
AddresseeCardView(QWidget *parent, const char *name = 0);
~AddresseeCardView();
+public slots:
+ void printMe();
signals:
void startAddresseeDrag();
void addresseeDropped(QDropEvent *);
protected:
virtual void dragEnterEvent(QDragEnterEvent *);
virtual void dropEvent(QDropEvent *);
virtual void startDrag();
};
class CardViewFactory : public ViewFactory
{
public:
KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
{
return new KAddressBookCardView( ab, parent, name );
}
QString type() const { return "Card"; }
QString description() const { return i18n( "Rolodex style cards represent contacts." ); }
ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent,
const char *name = 0 )
{
return new ConfigureCardViewWidget( ab, parent, name );
}
};
#endif
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp
index 61703ee..ecd6f05 100644
--- a/kaddressbook/views/kaddressbooktableview.cpp
+++ b/kaddressbook/views/kaddressbooktableview.cpp
@@ -44,96 +44,98 @@ KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab,
{
mainLayout = new QVBoxLayout( viewWidget(), 2 );
// The list view will be created when the config is read.
mListView = 0;
}
KAddressBookTableView::~KAddressBookTableView()
{
}
void KAddressBookTableView::setFocusAV()
{
if ( mListView )
mListView->setFocus();
}
void KAddressBookTableView::scrollUP()
{
QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
QApplication::postEvent( mListView, ev );
}
void KAddressBookTableView::scrollDOWN()
{
QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
QApplication::postEvent( mListView, ev );
}
void KAddressBookTableView::reconstructListView()
{
if (mListView)
{
disconnect(mListView, SIGNAL(selectionChanged()),
this, SLOT(addresseeSelected()));
disconnect(mListView, SIGNAL(executed(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
disconnect(mListView, SIGNAL(startAddresseeDrag()), this,
SIGNAL(startDrag()));
disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
SIGNAL(dropped(QDropEvent*)));
delete mListView;
}
mListView = new ContactListView( this, addressBook(), viewWidget() );
+ connect(this, SIGNAL(printView()),
+ mListView , SLOT(printMe()));
//US set singleClick manually, because it is no global configparameter in embedded space
mListView->setSingleClick(KABPrefs::instance()->mHonorSingleClick);
// Add the columns
KABC::Field::List fieldList = fields();
KABC::Field::List::ConstIterator it;
int c = 0;
for( it = fieldList.begin(); it != fieldList.end(); ++it ) {
mListView->addColumn( (*it)->label() );
mListView->setColumnWidthMode(c++, QListView::Manual);
//US
// qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1());
}
connect(mListView, SIGNAL(selectionChanged()),
this, SLOT(addresseeSelected()));
connect(mListView, SIGNAL(startAddresseeDrag()), this,
SIGNAL(startDrag()));
connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
SIGNAL(dropped(QDropEvent*)));
if (KABPrefs::instance()->mHonorSingleClick) {
// qDebug("KAddressBookTableView::reconstructListView single");
connect(mListView, SIGNAL(executed(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
} else {
// qDebug("KAddressBookTableView::reconstructListView double");
connect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
}
connect(mListView, SIGNAL(returnPressed(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
connect(mListView, SIGNAL(signalDelete()),
this, SLOT(addresseeDeleted()));
//US performceimprovement. Refresh is done from the outside
//US refresh();
mListView->setSorting( 0, true );
mainLayout->addWidget( mListView );
mainLayout->activate();
mListView->show();
}
void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field )
{
mListView->clear();