Hello. So we are going soon or later to drop the Q3ListView stuff for the contactlist.
I have made an experimental contactlist using QAbstractItemModel. I have to say i'm still not convinced by the supposed advantage of QAbstractItemModel. We could as well use QTreeWidget, and have subclass of QTreeWidgetItem for MetaContactLVI and GroupLVI like we have now. Could you explain me how having his own model is better ? thanks. Anyway, i think that Kopete::ContactList (KCL) and ContactListModel (CLM) must be two separate class. KCL, in libkopete, is the central storage class (in memory) which make the interface between protocols, plugins, and the contact list ui CLM is part of the contact list ui. There is no reason to have it in libkopete, and let plugins see that. I'm not talking about the storage backend in this mail. Is my attached draft the way to go ? Or am I completely wrong ? I'm still discovering the inter view stuff. -- Olivier P.S: How will we do the small contact icons ? There is of course virtual QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex & index ) which could be implemented like in our old code. But what will be in the model ?
/*
Kopete Contactlist GUI
Copyright (c) 2006 by Olivier Goffart <ogoffart at kde.org>
Kopete (c) 2006 by the Kopete developers <[email protected]>
*************************************************************************
* *
* 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. *
* *
*************************************************************************
*/
#include "kopetecontactlistmodel.h"
#include <kopetemetacontact.h>
#include <kopetecontactlist.h>
#include <kopetegroup.h>
#include <kopetepicture.h>
#include <QVariant>
#include <QImage>
#include <QTimer>
#include <kiconeffect.h>
#include <kimageeffect.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kdebug.h>
KopeteContactListModel::KopeteContactListModel(QObject *parent)
: QAbstractItemModel(parent)
{
Kopete::ContactList *contactlist=Kopete::ContactList::self();
connect(contactlist, SIGNAL(groupAdded(Kopete::Group*)) , this, SLOT(modified()));
connect(contactlist, SIGNAL(metaContactAdded(Kopete::MetaContact*)) , this, SLOT(modified()));
//bha
QTimer *t=new QTimer(this);
t->setInterval(100000);
t->start();
connect(t, SIGNAL(timeout()) , this , SLOT(modified()));
}
KopeteContactListModel::~ KopeteContactListModel()
{
}
QModelIndex KopeteContactListModel::index(int row, int column, const QModelIndex & parent) const
{
QObject *ptr=parent.isValid() ? static_cast<Kopete::ContactListElement*>(parent.internalPointer()) :0;
if(!ptr)
{
if(row < 0 || row >= Kopete::ContactList::self()->groups().count())
return QModelIndex();
return createIndex(row,column,Kopete::ContactList::self()->groups().at(row));
}
Kopete::Group *parent_group=qobject_cast<Kopete::Group*>(ptr);
if(!parent_group) //metacontact has no subitems
return QModelIndex();
if(row < 0 || row >= parent_group->members().count())
return QModelIndex();
return createIndex(row,column,parent_group->members().at(row));
}
//FIXME TO BE REDO (handle top level contact, and multi group
QModelIndex KopeteContactListModel::parent(const QModelIndex & child) const
{
QObject *ptr=child.isValid() ? static_cast<Kopete::ContactListElement*>(child.internalPointer()) :0;
if(!ptr)
return QModelIndex();
Kopete::MetaContact *metacontact=qobject_cast<Kopete::MetaContact*>(ptr);
if(!metacontact || metacontact->groups().isEmpty())
return QModelIndex();
Kopete::Group *parent_group=metacontact->groups().first();
if(!parent_group) //metacontact has no subitems
return QModelIndex();
return createIndex(Kopete::ContactList::self()->groups().indexOf(parent_group),0,parent_group);
}
int KopeteContactListModel::rowCount(const QModelIndex & parent) const
{
QObject *ptr=parent.isValid() ? static_cast<Kopete::ContactListElement*>(parent.internalPointer()) :0;
if(!ptr)
return Kopete::ContactList::self()->groups().count();
Kopete::Group *parent_group=qobject_cast<Kopete::Group*>(ptr);
if(!parent_group) //metacontact has no subitems
return 0;
return parent_group->members().count();
}
int KopeteContactListModel::columnCount(const QModelIndex & /*parent*/) const
{
return 1;
}
QVariant KopeteContactListModel::data(const QModelIndex & index, int role) const
{
QObject *ptr=index.isValid() ? static_cast<Kopete::ContactListElement*>(index.internalPointer()) :0;
if(!ptr)
return QVariant();
Kopete::MetaContact *metacontact=qobject_cast<Kopete::MetaContact*>(ptr);
if(metacontact)
{
switch(role)
{
case Qt::DisplayRole:
return metacontact->displayName();
case Qt::DecorationRole:
{
QImage photoImg = metacontact->picture().image();
if ( !photoImg.isNull() && (photoImg.width() > 0) && (photoImg.height() > 0) )
{
int photoSize = 22;
photoImg = photoImg.scaled( photoSize, photoSize, Qt::KeepAspectRatio, Qt::SmoothTransformation );
KImageEffect *effect = 0L;
switch ( metacontact->status() )
{
case Kopete::OnlineStatus::Online:
break;
case Kopete::OnlineStatus::Away:
effect = new KImageEffect();
effect->fade(photoImg, 0.5, Qt::white);
break;
case Kopete::OnlineStatus::Offline:
effect = new KImageEffect();
effect->fade(photoImg, 0.4, Qt::white);
effect->toGray(photoImg);
break;
case Kopete::OnlineStatus::Unknown:
default:
effect = new KImageEffect();
effect->fade(photoImg, 0.8, Qt::white);
}
delete effect;
return photoImg;
}
else
return SmallIcon(metacontact->statusIcon());
}
default:
return QVariant();
}
}
Kopete::Group *group=qobject_cast<Kopete::Group*>(ptr);
if(group)
{
switch(role)
{
case Qt::DisplayRole:
return group->displayName();
case Qt::DecorationRole:
if ( group->useCustomIcon() && !group->icon( Kopete::ContactListElement::Open ).isEmpty() )
return SmallIcon( group->icon( Kopete::ContactListElement::Open ) );
else
return SmallIcon( "folder" );
default:
return QVariant();
}
}
return QVariant();
}
void KopeteContactListModel::modified()
{
reset();
}
/*
TODO
- smarter update
- open/close
- group count
- tooltip
- small constact icons
- popup menu
- photo blink
*/
#include "kopetecontactlistmodel.moc"
/*
Kopete Contactlist GUI
Copyright (c) 2006 by Olivier Goffart <ogoffart at kde.org>
Kopete (c) 2006 by the Kopete developers <[email protected]>
*************************************************************************
* *
* 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. *
* *
*************************************************************************
*/
#ifndef KOPETE_CONTACTLISTVIEW_H
#define KOPETE_CONTACTLISTVIEW_H
#include <QTreeView>
class KopeteContactListModel;
class KopeteContactListView : public QTreeView
{
Q_OBJECT
public:
KopeteContactListView( QWidget *parent = 0 );
~KopeteContactListView();
private:
KopeteContactListModel *m_model;
};
#endif
/*
Kopete Contactlist GUI
Copyright (c) 2006 by Olivier Goffart <ogoffart at kde.org>
Kopete (c) 2006 by the Kopete developers <[email protected]>
*************************************************************************
* *
* 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. *
* *
*************************************************************************
*/
#ifndef KOPETE_CONTACTLISTMODEL_H
#define KOPETE_CONTACTLISTMODEL_H
#include <QAbstractItemModel>
class KopeteContactListModel : public QAbstractItemModel
{
Q_OBJECT
public:
/*enum Roles {
FileIconRole = Qt::DecorationRole,
FilePathRole = Qt::UserRole + 1,
FileNameRole
};*/
explicit KopeteContactListModel(QObject *parent = 0);
~KopeteContactListModel();
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &child) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
// QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
// bool hasChildren(const QModelIndex &index = QModelIndex()) const;
// Qt::ItemFlags flags(const QModelIndex &index) const;
// void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
private slots:
void modified();
};
#endif
// vim: set noet ts=4 sts=4 sw=4:
/*
Kopete Contactlist GUI
Copyright (c) 2006 by Olivier Goffart <ogoffart at kde.org>
Kopete (c) 2006 by the Kopete developers <[email protected]>
*************************************************************************
* *
* 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. *
* *
*************************************************************************
*/
#include "kopetecontactlistview.h"
#include "kopetecontactlistmodel.h"
KopeteContactListView::KopeteContactListView(QWidget * parent)
: QTreeView(parent) , m_model(new KopeteContactListModel(this))
{
setModel(m_model);
}
KopeteContactListView::~ KopeteContactListView()
{
}
#include "kopetecontactlistview.moc"
pgpy3maX9kbJU.pgp
Description: PGP signature
_______________________________________________ kopete-devel mailing list [email protected] https://mail.kde.org/mailman/listinfo/kopete-devel
