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
@@ -6,48 +6,49 @@
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
@@ -148,48 +149,59 @@ KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab,
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
{
@@ -269,50 +281,54 @@ void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
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;
}
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
@@ -39,48 +39,50 @@ 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:
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
@@ -20,48 +20,49 @@
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 );
}
}
@@ -190,48 +191,58 @@ KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab,
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 )
@@ -259,48 +270,54 @@ void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field )
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;
}
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
@@ -40,48 +40,50 @@ 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
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
@@ -30,49 +30,58 @@
#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();
@@ -138,49 +147,54 @@ void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field )
#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 ) );
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
@@ -42,48 +42,50 @@ namespace KABC { class AddressBook; }
* 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: