File indexing completed on 2022-11-22 14:17:17

0001 /*
0002  * Abstract Contact Delegate - base class for other delegates
0003  *
0004  * Copyright (C) 2011 Martin Klapetek <martin.klapetek@gmail.com>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Lesser General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2.1 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Lesser General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public
0017  * License along with this library; if not, write to the Free Software
0018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0019  */
0020 
0021 
0022 #ifndef ABSTRACT_CONTACT_DELEGATE_H
0023 #define ABSTRACT_CONTACT_DELEGATE_H
0024 
0025 #include <QStyledItemDelegate>
0026 
0027 class AbstractContactDelegate : public QStyledItemDelegate
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     AbstractContactDelegate(QObject *parent = 0);
0033     virtual ~AbstractContactDelegate();
0034 
0035     virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0036     virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
0037 
0038 public Q_SLOTS:
0039     /**
0040      * Reimplements the help tooltip for the contact delegate.
0041      *
0042      * When the user hovers over a contact it will display their information like Alias, which contact belongs to what account,
0043      * is this contact blocked, their status message if their is one, etc.
0044      */
0045     bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index);
0046 
0047 Q_SIGNALS:
0048     void repaintItem(QModelIndex);
0049 
0050 protected:
0051     /** Paint contact items. Pure virtual, items should be subclass this for painting*/
0052     virtual void paintContact(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const = 0;
0053     /** The size hint for painting contact items*/
0054     virtual QSize sizeHintContact(const QStyleOptionViewItem &option, const QModelIndex &index) const = 0;
0055     virtual QSize sizeHintHeader(const QStyleOptionViewItem &option, const QModelIndex &index) const;
0056     virtual void avatarToGray(QPixmap &avatar) const;
0057 
0058 private:
0059     /** Paints header items*/
0060     void paintHeader(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0061 };
0062 
0063 #endif // ABSTRACT_CONTACT_DELEGATE_H