summaryrefslogtreecommitdiffabout
path: root/kaddressbook/views
Side-by-side diff
Diffstat (limited to 'kaddressbook/views') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp20
-rw-r--r--kaddressbook/views/kaddressbookcardview.h2
-rw-r--r--kaddressbook/views/kaddressbookiconview.cpp17
-rw-r--r--kaddressbook/views/kaddressbookiconview.h2
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp18
-rw-r--r--kaddressbook/views/kaddressbooktableview.h2
6 files changed, 57 insertions, 4 deletions
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp
index 4babf67..a7bf6c9 100644
--- a/kaddressbook/views/kaddressbookcardview.cpp
+++ b/kaddressbook/views/kaddressbookcardview.cpp
@@ -1,77 +1,78 @@
/*
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())
@@ -124,96 +125,107 @@ void AddresseeCardView::dragEnterEvent(QDragEnterEvent *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()));
}
KAddressBookCardView::~KAddressBookCardView()
{
}
+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() );
}
//custom fonts?
QFont f( font() );
if ( config->readBoolEntry( "EnableCustomFonts", false ) )
{
mCardView->setFont( config->readFontEntry( "TextFont", &f) );
f.setBold( true );
mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
}
else
{
mCardView->setFont( f );
f.setBold( true );
mCardView->setHeaderFont( f );
}
mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true));
mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators",
true));
mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false));
mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false);
@@ -245,98 +257,102 @@ void KAddressBookCardView::writeConfig( KConfig *config )
void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
{
mCardView->clear();
if ( s.isEmpty() || s == "*" ) {
refresh();
return;
}
QString pattern = s.lower()+"*";
QRegExp re;
re.setWildcard(true); // most people understand these better.
re.setCaseSensitive(false);
re.setPattern( pattern );
if (!re.isValid())
return;
mCardView->viewport()->setUpdatesEnabled( false );
KABC::Addressee::List addresseeList = addressees();
KABC::Addressee::List::Iterator it;
if ( field ) {
for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
#if QT_VERSION >= 300
if (re.search(field->value( *it ).lower()) != -1)
#else
if (re.match(field->value( *it ).lower()) != -1)
#endif
new AddresseeCardViewItem(fields(), mShowEmptyFields,
addressBook(), *it, mCardView);
}
} else {
KABC::Field::List fieldList = fields();
KABC::Field::List::ConstIterator fieldIt;
for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
#if QT_VERSION >= 300
if (re.search((*fieldIt)->value( *it ).lower()) != -1)
#else
if (re.match((*fieldIt)->value( *it ).lower()) != -1)
#endif
{
new AddresseeCardViewItem(fields(), mShowEmptyFields,
addressBook(), *it, mCardView);
continue;
}
}
}
}
mCardView->viewport()->setUpdatesEnabled( true );
mCardView->viewport()->update();
- // by default nothing is selected
- emit selected(QString::null);
+ if ( mCardView->firstItem() ) {
+ mCardView->setCurrentItem ( mCardView->firstItem() );
+ mCardView->setSelected ( mCardView->firstItem() , true );
+ }
+ else
+ emit selected(QString::null);
}
QStringList KAddressBookCardView::selectedUids()
{
QStringList uidList;
CardViewItem *item;
AddresseeCardViewItem *aItem;
for (item = mCardView->firstItem(); item; item = item->nextItem())
{
if (item->isSelected())
{
#ifndef KAB_EMBEDDED
aItem = dynamic_cast<AddresseeCardViewItem*>(item);
#else //KAB_EMBEDDED
aItem = (AddresseeCardViewItem*)(item);
#endif //KAB_EMBEDDED
if (aItem)
uidList << aItem->addressee().uid();
}
}
return uidList;
}
void KAddressBookCardView::refresh(QString uid)
{
CardViewItem *item;
AddresseeCardViewItem *aItem;
if (uid.isNull())
{
// Rebuild the view
mCardView->viewport()->setUpdatesEnabled( false );
mCardView->clear();
KABC::Addressee::List addresseeList = addressees();
KABC::Addressee::List::Iterator iter;
for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter)
{
if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") )
continue;
aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields,
addressBook(), *iter, mCardView);
}
mCardView->viewport()->setUpdatesEnabled( true );
mCardView->viewport()->update();
// by default nothing is selected
diff --git a/kaddressbook/views/kaddressbookcardview.h b/kaddressbook/views/kaddressbookcardview.h
index b8efb01..45a9781 100644
--- a/kaddressbook/views/kaddressbookcardview.h
+++ b/kaddressbook/views/kaddressbookcardview.h
@@ -15,96 +15,98 @@
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 <qstring.h>
#ifndef KAB_EMBEDDED
#include <kiconview.h>
#else //KAB_EMBEDDED
#include <klocale.h>
#endif //KAB_EMBEDDED
#include "cardview.h"
#include "kaddressbookview.h"
#include "configurecardviewdialog.h"
class QDragEnterEvent;
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();
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();
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 )
diff --git a/kaddressbook/views/kaddressbookiconview.cpp b/kaddressbook/views/kaddressbookiconview.cpp
index fdc0db9..f4c68b8 100644
--- a/kaddressbook/views/kaddressbookiconview.cpp
+++ b/kaddressbook/views/kaddressbookiconview.cpp
@@ -1,91 +1,92 @@
/*
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.
*/
#ifndef KAB_EMBEDDED
#include <qiconview.h>
#include <qstringlist.h>
#include <kabc/addressee.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <klocale.h>
#else //KAB_EMBEDDED
#endif //KAB_EMBEDDED
#include <kabc/addressbook.h>
#include "kabprefs.h"
#include "viewmanager.h"
#include "kaddressbookiconview.h"
#include <qlayout.h>
#include <qregexp.h>
+#include <qapplication.h>
#include <kglobal.h>
/*US transfered to the headerfile
class IconViewFactory : public ViewFactory
{
public:
KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
{
return new KAddressBookIconView( ab, parent, name );
}
QString type() const { return "Icon"; }
QString description() const { return i18n( "Icons represent contacts. Very simple view." ); }
};
*/
extern "C" {
void *init_libkaddrbk_iconview()
{
return ( new IconViewFactory );
}
}
////////////////////////////////
// AddresseeIconView (internal class)
#ifndef KAB_EMBEDDED
AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
: KIconView(parent, name)
#else //KAB_EMBEDDED
AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
: QIconView(parent, name)
#endif //KAB_EMBEDDED
{
setSelectionMode( QIconView::Extended );
setResizeMode( QIconView::Adjust );
setWordWrapIconText( true );
setGridX( 100 );
setItemsMovable(false);
setSorting(true, true);
//US ??? setMode( KIconView::Select );
#ifndef KAB_EMBEDDED
connect(this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)),
@@ -166,165 +167,181 @@ class AddresseeIconViewItem : public QIconViewItem
icon.convertFromImage(img.smoothScale(32, 32));
#endif //KAB_EMBEDDED
} else
icon = defaultIcon;
setPixmap( icon );
}
private:
KABC::Field::List mFields;
KABC::AddressBook *mDocument;
KABC::Addressee mAddressee;
};
///////////////////////////////
// KAddressBookView
KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab,
QWidget *parent, const char *name)
: KAddressBookView( ab, parent, name )
{
// Init the GUI
QVBoxLayout *layout = new QVBoxLayout(viewWidget());
mIconView = new AddresseeIconView(viewWidget(), "mIconView");
layout->addWidget(mIconView);
// Connect up the signals
//US method executed is part of KIconView
//US connect(mIconView, SIGNAL(executed(QIconViewItem *)),
//US this, SLOT(addresseeExecuted(QIconViewItem *)));
connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
this, SLOT(addresseeExecuted(QIconViewItem *)));
connect(mIconView, SIGNAL(selectionChanged()),
this, SLOT(addresseeSelected()));
connect(mIconView, SIGNAL(addresseeDropped(QDropEvent*)),
this, SIGNAL(dropped(QDropEvent*)));
connect(mIconView, SIGNAL(startAddresseeDrag()),
this, SIGNAL(startDrag()));
}
KAddressBookIconView::~KAddressBookIconView()
{
}
+void KAddressBookIconView::scrollUP()
+{
+ QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
+ QApplication::postEvent( mIconView, ev );
+}
+void KAddressBookIconView::scrollDOWN()
+{
+ QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
+ QApplication::postEvent( mIconView, ev );
+}
void KAddressBookIconView::readConfig(KConfig *config)
{
KAddressBookView::readConfig(config);
//US method executed is part of KIconView
//US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)),
//US this, SLOT(addresseeExecuted(QIconViewItem *)));
disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
this, SLOT(addresseeExecuted(QIconViewItem *)));
//US method executed is part of KIconView. Use selectionChanged instead
/*US
if (KABPrefs::instance()->mHonorSingleClick)
connect(mIconView, SIGNAL(executed(QIconViewItem *)),
this, SLOT(addresseeExecuted(QIconViewItem *)));
else
connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)),
this, SLOT(addresseeExecuted(QIconViewItem *)));
*/
connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
this, SLOT(addresseeExecuted(QIconViewItem *)));
}
void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field )
{
mIconView->clear();
mIconList.clear();
if ( s.isEmpty() || s == "*" ) {
refresh();
return;
}
QString pattern = s.lower()+"*";
QRegExp re;
re.setWildcard(true); // most people understand these better.
re.setCaseSensitive(false);
re.setPattern( pattern );
if (!re.isValid())
return;
KABC::Addressee::List addresseeList = addressees();
KABC::Addressee::List::Iterator it;
if ( field ) {
for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
#if QT_VERSION >= 300
if (re.search(field->value( *it ).lower()) != -1)
#else
if (re.match(field->value( *it ).lower()) != -1)
#endif
mIconList.append(new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
}
} else {
KABC::Field::List fieldList = fields();
KABC::Field::List::ConstIterator fieldIt;
for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
#if QT_VERSION >= 300
if (re.search((*fieldIt)->value( *it ).lower()) != -1)
#else
if (re.match((*fieldIt)->value( *it ).lower()) != -1)
#endif
{
mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
continue;
}
}
}
}
mIconView->arrangeItemsInGrid( true );
+ if ( mIconView->firstItem() ) {
+ mIconView->setCurrentItem ( mIconView->firstItem() );
+ mIconView->setSelected ( mIconView->firstItem() , true );
+ }
+ else
+ emit selected(QString::null);
}
QStringList KAddressBookIconView::selectedUids()
{
QStringList uidList;
QIconViewItem *item;
AddresseeIconViewItem *aItem;
for (item = mIconView->firstItem(); item; item = item->nextItem())
{
if (item->isSelected())
{
#ifndef KAB_EMBEDDED
aItem = dynamic_cast<AddresseeIconViewItem*>(item);
#else //KAB_EMBEDDED
aItem = (AddresseeIconViewItem*)(item);
#endif //KAB_EMBEDDED
if (aItem)
uidList << aItem->addressee().uid();
}
}
return uidList;
}
void KAddressBookIconView::refresh(QString uid)
{
QIconViewItem *item;
AddresseeIconViewItem *aItem;
if ( uid.isNull() ) {
// Rebuild the view
mIconView->clear();
mIconList.clear();
KABC::Addressee::List addresseeList = addressees();
KABC::Addressee::List::Iterator iter;
for ( iter = addresseeList.begin(); iter != addresseeList.end(); ++iter ) {
if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") )
continue;
aItem = new AddresseeIconViewItem( fields(), addressBook(), *iter, mIconView );
}
mIconView->arrangeItemsInGrid( true );
for ( item = mIconView->firstItem(); item; item = item->nextItem() )
{
#ifndef KAB_EMBEDDED
AddresseeIconViewItem* aivi = dynamic_cast<AddresseeIconViewItem*>( item );
diff --git a/kaddressbook/views/kaddressbookiconview.h b/kaddressbook/views/kaddressbookiconview.h
index 963ee7c..acfcd71 100644
--- a/kaddressbook/views/kaddressbookiconview.h
+++ b/kaddressbook/views/kaddressbookiconview.h
@@ -16,96 +16,98 @@
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.
*/
#ifndef KADDRESSBOOKICONVIEW_H
#define KADDRESSBOOKICONVIEW_H
#include <qstring.h>
#ifndef KAB_EMBEDDED
#include <kiconview.h>
#else //KAB_EMBEDDED
#include <qiconview.h>
#include <qptrlist.h>
#include <klocale.h>
#endif //KAB_EMBEDDED
#include "kaddressbookview.h"
class QIconViewItem;
class KConfig;
class AddresseeIconView;
class AddresseeIconViewItem;
class QIconDragItem;
class KAddressBookIconView;
namespace KABC { class AddressBook; }
/** This is an example kaddressbook view that is implemented using
* KIconView. This view is not the most useful view, but it displays
* how simple implementing a new view can be.
*/
class KAddressBookIconView : public KAddressBookView
{
Q_OBJECT
public:
KAddressBookIconView( KABC::AddressBook *ab, QWidget *parent,
const char *name = 0 );
virtual ~KAddressBookIconView();
virtual QStringList selectedUids();
virtual QString type() const { return "Icon"; }
void doSearch( const QString& s ,KABC::Field *field );
virtual void readConfig(KConfig *config);
+ virtual void scrollUP();
+ virtual void scrollDOWN();
public slots:
void refresh(QString uid = QString::null);
#ifndef KAB_EMBEDDED
//MOC_SKIP_BEGIN
void setSelected(QString uid = QString::null, bool selected = true);
//MOC_SKIP_END
#else //KAB_EMBEDDED
//US my MOC do not like default parameters ???
void setSelected(QString uid, bool selected);
#endif //KAB_EMBEDDED
protected slots:
void addresseeExecuted(QIconViewItem *item);
void addresseeSelected();
private:
AddresseeIconView *mIconView;
QPtrList<AddresseeIconViewItem> mIconList;
};
#ifndef KAB_EMBEDDED
//MOC_SKIP_BEGIN
class AddresseeIconView : public KIconView
//MOC_SKIP_END
#else //KAB_EMBEDDED
class AddresseeIconView : public QIconView
#endif //KAB_EMBEDDED
{
Q_OBJECT
public:
AddresseeIconView(QWidget *parent, const char *name);
~AddresseeIconView();
signals:
void addresseeDropped(QDropEvent *);
void startAddresseeDrag();
protected:
virtual QDragObject *dragObject();
protected slots:
void itemDropped(QDropEvent *, const QValueList<QIconDragItem> &);
};
class IconViewFactory : public ViewFactory
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp
index fbfddba..2412170 100644
--- a/kaddressbook/views/kaddressbooktableview.cpp
+++ b/kaddressbook/views/kaddressbooktableview.cpp
@@ -6,97 +6,106 @@
#include <qfile.h>
#include <qimage.h>
#include <qcombobox.h>
#include <qapplication.h>
#include <qdragobject.h>
#include <qevent.h>
#include <qurl.h>
#include <qpixmap.h>
#include <kabc/addressbook.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kcolorbutton.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <klineedit.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kurl.h>
#include <kurlrequester.h>
//US#include "configuretableviewdialog.h"
#include "contactlistview.h"
#include "kabprefs.h"
#include "undocmds.h"
#include "viewmanager.h"
#include <qlayout.h>
#include <qheader.h>
#include <qregexp.h>
#include "kaddressbooktableview.h"
KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab,
QWidget *parent, const char *name )
: KAddressBookView( ab, parent, name )
{
mainLayout = new QVBoxLayout( viewWidget(), 2 );
// The list view will be created when the config is read.
mListView = 0;
}
KAddressBookTableView::~KAddressBookTableView()
{
}
-
+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() );
// 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)
connect(mListView, SIGNAL(executed(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
else
connect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
connect(mListView, SIGNAL(returnPressed(QListViewItem*)),
@@ -114,97 +123,102 @@ void KAddressBookTableView::reconstructListView()
}
void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field )
{
mListView->clear();
if ( s.isEmpty() || s == "*" ) {
refresh();
return;
}
QString pattern = s.lower()+"*";
QRegExp re;
re.setWildcard(true); // most people understand these better.
re.setCaseSensitive(false);
re.setPattern( pattern );
if (!re.isValid())
return;
KABC::Addressee::List addresseeList = addressees();
KABC::Addressee::List::Iterator it;
if ( field ) {
for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
#if QT_VERSION >= 300
if (re.search(field->value( *it ).lower()) != -1)
#else
if (re.match(field->value( *it ).lower()) != -1)
#endif
ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
}
} else {
KABC::Field::List fieldList = fields();
KABC::Field::List::ConstIterator fieldIt;
for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
#if QT_VERSION >= 300
if (re.search((*fieldIt)->value( *it ).lower()) != -1)
#else
if (re.match((*fieldIt)->value( *it ).lower()) != -1)
#endif
{
ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
break;
}
}
}
}
// Sometimes the background pixmap gets messed up when we add lots
// of items.
mListView->repaint();
- emit selected(QString::null);
+ if ( mListView->firstChild() ) {
+ mListView->setCurrentItem ( mListView->firstChild() );
+ mListView->setSelected ( mListView->firstChild(), true );
+ }
+ else
+ emit selected(QString::null);
}
void KAddressBookTableView::writeConfig(KConfig *config)
{
KAddressBookView::writeConfig(config);
mListView->saveLayout(config, config->group());
}
void KAddressBookTableView::readConfig(KConfig *config)
{
KAddressBookView::readConfig( config );
// The config could have changed the fields, so we need to reconstruct
// the listview.
reconstructListView();
// costum colors?
if ( config->readBoolEntry( "EnableCustomColors", false ) )
{
QPalette p( mListView->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 ) );
#ifndef KAB_EMBEDDED
c = KGlobalSettings::alternateBackgroundColor();
#else //KAB_EMBEDDED
c = QColor(240, 240, 240);
#endif //KAB_EMBEDDED
c = config->readColorEntry ("AlternatingBackgroundColor", &c);
mListView->setAlternateColor(c);
//US mListView->viewport()->setPalette( p );
mListView->setPalette( p );
}
else
{
// needed if turned off during a session.
//US mListView->viewport()->setPalette( mListView->palette() );
diff --git a/kaddressbook/views/kaddressbooktableview.h b/kaddressbook/views/kaddressbooktableview.h
index ecfe7a1..865f8d5 100644
--- a/kaddressbook/views/kaddressbooktableview.h
+++ b/kaddressbook/views/kaddressbooktableview.h
@@ -18,96 +18,98 @@
#include <qvaluelist.h>
#include "undo.h"
#else //KAB_EMBEDDED
#include "views/configuretableviewdialog.h"
#endif //KAB_EMBEDDED
#include "klocale.h"
#include "kaddressbookview.h"
class QListViewItem;
class QListBox;
class QVBoxLayout;
class KConfig;
class ContactListViewItem;
class ContactListView;
namespace KABC { class AddressBook; }
/**
* This class is the table view for kaddressbook. This view is a KListView
* with multiple columns for the selected fields.
*
* @short Table View
* @author Don Sanders <dsanders@kde.org>
* @version 0.1
*/
class KAddressBookTableView : public KAddressBookView
{
friend class ContactListView;
Q_OBJECT
public:
KAddressBookTableView( KABC::AddressBook *ab, QWidget *parent,
const char *name = 0 );
virtual ~KAddressBookTableView();
virtual void refresh(QString uid = QString::null);
virtual QStringList selectedUids();
virtual void setSelected(QString uid = QString::null, bool selected = false);
virtual void readConfig(KConfig *config);
virtual void writeConfig(KConfig *config);
virtual QString type() const { return "Table"; }
void doSearch( const QString& s ,KABC::Field *field );
+ virtual void scrollUP();
+ virtual void scrollDOWN();
public slots:
virtual void reconstructListView();
protected slots:
/** Called whenever the user selects an addressee in the list view.
*/
void addresseeSelected();
void addresseeDeleted();
/** Called whenever the user executes an addressee. In terms of the
* list view, this is probably a double click
*/
void addresseeExecuted(QListViewItem*);
private:
QVBoxLayout *mainLayout;
ContactListView *mListView;
};
class TableViewFactory : public ViewFactory
{
public:
KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
{
return new KAddressBookTableView( ab, parent, name );
}
QString type() const { return "Table"; }
QString description() const { return i18n( "A listing of contacts in a table. Each cell of "
"the table holds a field of the contact." ); }
ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent,
const char *name = 0 )
{
return new ConfigureTableViewWidget( ab, parent, name );
}
};
/*US
extern "C" {
void *init_libkaddrbk_tableview()
{
return ( new TableViewFactory );
}
}
*/