~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/kvilib/tal/kvi_tal_itemdelegates.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=============================================================================
2
 
//
3
 
//   File : kvi_tal_itemdelegates.cpp
4
 
//   Creation date : Mon May 05 2008 11:25:08 by Alessandro Carbone
5
 
//
6
 
//   This file is part of the KVirc irc client distribution
7
 
//   Copyright (C) 2008 Alessandro Carbone (elfonol at gmail dot com)
8
 
//
9
 
//   This program is FREE software. You can redistribute it and/or
10
 
//   modify it under the terms of the GNU General Public License
11
 
//   as published by the Free Software Foundation; either version 2
12
 
//   of the License, or (at your opinion) any later version.
13
 
//
14
 
//   This program is distributed in the HOPE that it will be USEFUL,
15
 
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
 
//   See the GNU General Public License for more details.
18
 
//
19
 
//   You should have received a copy of the GNU General Public License
20
 
//   along with this program. If not, write to the Free Software Foundation,
21
 
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
 
//
23
 
//=============================================================================
24
 
 
25
 
#include "kvi_tal_itemdelegates.h"
26
 
 
27
 
#include <QListWidget>
28
 
#include <QPainter>
29
 
#include <QApplication>
30
 
#include <QAbstractTextDocumentLayout>
31
 
 
32
 
KviTalIconAndRichTextItemDelegate::KviTalIconAndRichTextItemDelegate(QAbstractItemView * pWidget)
33
 
: QStyledItemDelegate(pWidget), m_pParent(pWidget), m_pDefaultPix(0)
34
 
{
35
 
}
36
 
 
37
 
KviTalIconAndRichTextItemDelegate::~KviTalIconAndRichTextItemDelegate()
38
 
{
39
 
}
40
 
 
41
 
void KviTalIconAndRichTextItemDelegate::paint(QPainter * pPainter, const QStyleOptionViewItem & option, const QModelIndex & index) const
42
 
{
43
 
        pPainter->save();
44
 
        QStyleOptionViewItemV4 opt = option;
45
 
        initStyleOption(&opt, index);
46
 
 
47
 
        if (opt.state & QStyle::State_Selected)
48
 
                QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem,&opt, pPainter);
49
 
 
50
 
        QString szText = index.data(Qt::DisplayRole).toString();
51
 
        QPixmap pixmap;
52
 
        QRect decorationRect;
53
 
        QVariant value = index.data(Qt::DecorationRole);
54
 
 
55
 
        QIcon ico;
56
 
        if(value.canConvert<QIcon>())
57
 
        {
58
 
                ico = QIcon(value.value<QIcon>());
59
 
                if(ico.isNull())
60
 
                {
61
 
                        if(m_pDefaultPix)
62
 
                                pPainter->drawPixmap(opt.rect.x()+LVI_BORDER,opt.rect.y()+LVI_BORDER,*m_pDefaultPix);
63
 
                } else {
64
 
                        pPainter->drawPixmap(opt.rect.x()+LVI_BORDER,opt.rect.y()+LVI_BORDER,ico.pixmap(LVI_ICON_SIZE,LVI_ICON_SIZE));
65
 
                }
66
 
        } else {
67
 
                if(m_pDefaultPix)
68
 
                        pPainter->drawPixmap(opt.rect.x()+LVI_BORDER,opt.rect.y()+LVI_BORDER,*m_pDefaultPix);
69
 
        }
70
 
 
71
 
        QTextDocument doc;
72
 
        doc.setHtml(szText);
73
 
        doc.setDefaultFont(opt.font);
74
 
        pPainter->translate(opt.rect.x()+LVI_AFTER_ICON,opt.rect.y()+LVI_BORDER);
75
 
        doc.setTextWidth(opt.rect.width()-LVI_AFTER_ICON);
76
 
        QRect cliprect = QRect(QPoint(0,0),QSize(opt.rect.width()-LVI_AFTER_ICON,opt.rect.height()));
77
 
        doc.drawContents(pPainter,cliprect);
78
 
        pPainter->restore();
79
 
}
80
 
 
81
 
QSize KviTalIconAndRichTextItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex & index) const
82
 
{
83
 
        QString szText = index.data(Qt::DisplayRole).toString();
84
 
        QTextDocument doc;
85
 
        doc.setHtml(szText);
86
 
        doc.setDefaultFont(option.font);
87
 
        doc.setTextWidth(option.rect.width()-LVI_AFTER_ICON);
88
 
        int iHeight = doc.documentLayout()->documentSize().toSize().height();
89
 
        if(iHeight < (LVI_ICON_SIZE+(2 * LVI_BORDER)))
90
 
                iHeight = LVI_ICON_SIZE;
91
 
 
92
 
        return QSize(((QListWidget *)parent())->viewport()->size().width(), iHeight + (2 * LVI_BORDER));
93
 
}