1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /***************************************************************************
8 						  sclistwidgetdelegate.cpp  -  description
9 							 -------------------
10 	begin                : Sat June 18 2011
11 	copyright            : (C) 2011 by Franz Schmid
12 	email                : Franz.Schmid@altmuehlnet.de
13  ***************************************************************************/
14 
15 /***************************************************************************
16  *                                                                         *
17  *   This program is free software; you can redistribute it and/or modify  *
18  *   it under the terms of the GNU General Public License as published by  *
19  *   the Free Software Foundation; either version 2 of the License, or     *
20  *   (at your option) any later version.                                   *
21  *                                                                         *
22  ***************************************************************************/
23 
24 #include <QPainter>
25 #include "sclistwidgetdelegate.h"
26 
ScListWidgetDelegate(QListWidget * view,QWidget * parent)27 ScListWidgetDelegate::ScListWidgetDelegate(QListWidget *view, QWidget *parent) : QItemDelegate(parent), m_view(view)
28 {
29 	m_dispIconOnly = false;
30 }
31 
paint(QPainter * painter,const QStyleOptionViewItem & option,const QModelIndex & index) const32 void ScListWidgetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
33 {
34 	if (m_dispIconOnly)
35 	{
36 		painter->save();
37 		QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
38 		painter->drawPixmap(option.rect, icon.pixmap(m_view->iconSize()));
39 		QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
40 		if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
41 			cg = QPalette::Inactive;
42 		if (option.state & QStyle::State_Selected)
43 		{
44 			QColor sele = option.palette.brush(cg, QPalette::Highlight).color();
45 			sele.setAlphaF(0.3);
46 			painter->fillRect(option.rect, sele);
47 		}
48 		painter->restore();
49 	}
50 	else
51 		QItemDelegate::paint(painter, option, index);
52 }
53 
sizeHint(const QStyleOptionViewItem & opt,const QModelIndex & index) const54 QSize ScListWidgetDelegate::sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const
55 {
56 	if (m_dispIconOnly)
57 	{
58 		QSize sz = m_view->iconSize();
59 		return sz;
60 	}
61 	return QItemDelegate::sizeHint(opt, index);
62 }
63 
setIconOnly(bool setter)64 void ScListWidgetDelegate::setIconOnly(bool setter)
65 {
66 	m_dispIconOnly = setter;
67 }
68 
iconOnly()69 bool ScListWidgetDelegate::iconOnly()
70 {
71 	return m_dispIconOnly;
72 }
73