~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to kde/src/widgets/imtab.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2012-2013 by Savoir-Faire Linux                         *
3
 
 *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>*
4
 
 *                                                                         *
5
 
 *   This program is free software; you can redistribute it and/or modify  *
6
 
 *   it under the terms of the GNU General Public License as published by  *
7
 
 *   the Free Software Foundation; either version 3 of the License, or     *
8
 
 *   (at your option) any later version.                                   *
9
 
 *                                                                         *
10
 
 *   This program is distributed in the hope that it will be useful,       *
11
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 
 *   GNU General Public License for more details.                          *
14
 
 *                                                                         *
15
 
 *   You should have received a copy of the GNU General Public License     *
16
 
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
17
 
 **************************************************************************/
18
 
#include "imtab.h"
19
 
 
20
 
#include "../lib/instantmessagingmodel.h"
21
 
#include "../lib/call.h"
22
 
#include <QtGui/QPainter>
23
 
#include <KDebug>
24
 
#include <KIcon>
25
 
#include <QtGui/QFont>
26
 
 
27
 
///Delegate contructor
28
 
ImDelegates::ImDelegates(IMTab* parent) : QStyledItemDelegate(parent),m_pParent(parent)
29
 
{
30
 
 
31
 
}
32
 
 
33
 
///Delegate size hint
34
 
QSize ImDelegates::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const {
35
 
   int height = 0;
36
 
   QPixmap* icon = (QPixmap*)index.data(InstantMessagingModel::MESSAGE_IMAGE_ROLE).value<void*>();
37
 
   QFontMetrics metric( option.font);
38
 
   QRect requiredRect = metric.boundingRect(0,0,m_pParent->width()-30 - 48 - 10 /*margin*/,500,Qt::TextWordWrap|Qt::AlignLeft,index.data(InstantMessagingModel::MESSAGE_TYPE_ROLE).toString());
39
 
   height+=requiredRect.height();
40
 
   height+=metric.height()+10;
41
 
   if (icon && dynamic_cast<QPixmap*>(icon) && height < icon->height()) {
42
 
      height = icon->height();
43
 
   }
44
 
   return QSize(m_pParent->width()-30,height);
45
 
}
46
 
 
47
 
///Delegate painter
48
 
void ImDelegates::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
49
 
{
50
 
   Q_ASSERT(index.isValid());
51
 
   QPixmap* icon = (QPixmap*)index.data(InstantMessagingModel::MESSAGE_IMAGE_ROLE).value<void*>();
52
 
   int icnWidth = 50;
53
 
   if (icon && dynamic_cast<QPixmap*>(icon)) {
54
 
      painter->drawPixmap(option.rect.x()+5,option.rect.y()+(option.rect.height()/2)-(icon->height()/2),*icon);
55
 
      icnWidth = icon->width();
56
 
   }
57
 
   else {
58
 
      ((QAbstractListModel*) index.model())->setData(index,QPixmap(KIcon("user-identity").pixmap(QSize(48,48))),InstantMessagingModel::MESSAGE_IMAGE_ROLE);
59
 
   }
60
 
 
61
 
   QFontMetrics metric(painter->font());
62
 
   QString text = index.data(InstantMessagingModel::MESSAGE_TYPE_ROLE).toString();
63
 
   QRect requiredRect = metric.boundingRect(option.rect.x()+icnWidth+10,option.rect.y()+metric.height()+5,option.rect.width() - icnWidth - 10 /*margin*/,500,Qt::TextWordWrap|Qt::AlignLeft,text);
64
 
   painter->drawText(requiredRect,Qt::AlignLeft|Qt::TextWordWrap,text);
65
 
 
66
 
   QFont font = painter->font();
67
 
   font.setBold(true);
68
 
   painter->setFont(font);
69
 
   painter->drawText(option.rect.x()+icnWidth+10,option.rect.y()+metric.height(),index.data(InstantMessagingModel::MESSAGE_FROM_ROLE).toString());
70
 
   font.setBold(false);
71
 
   painter->setFont(font);
72
 
 
73
 
}
74
 
 
75
 
///Constructor
76
 
IMTab::IMTab(InstantMessagingModel* model,QWidget* parent) : QListView(parent)
77
 
{
78
 
   setModel(model);
79
 
   setAlternatingRowColors(true);
80
 
//    setWrapping(true);
81
 
   setUniformItemSizes(false);
82
 
   setItemDelegate(new ImDelegates(this));
83
 
   setVerticalScrollMode(ScrollPerPixel);
84
 
   connect(model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),this,SLOT(scrollBottom()));
85
 
}
86
 
 
87
 
///Scroll to last message
88
 
void IMTab::scrollBottom()
89
 
{
90
 
   scrollTo(model()->index(model()->rowCount()-1,0));
91
 
}