1 /***************************************************************************
2 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhnFreespirit@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
20 #include "ServiceListDelegate.h"
23 #include "servicebase.h"
24 #include "ServiceListModel.h"
29 ServiceListDelegate::ServiceListDelegate()
34 ServiceListDelegate::~ServiceListDelegate()
38 void ServiceListDelegate::paint(QPainter
* painter
, const QStyleOptionViewItem
& option
, const QModelIndex
& index
) const
42 //ServiceBase * service = static_cast< ServiceBase * >( index.internalPointer() );
43 //if ( ! service ) return;
45 debug() << "Look ma' I am painting!";
48 painter
->setPen(Qt::gray
);
50 painter
->setRenderHint ( QPainter::Antialiasing
);
53 painter
->drawRoundRect( option
.rect
.topLeft().x() + 2, option
.rect
.topLeft().y() + 2 ,250,100, 10 ,10 );
55 if (option
.state
& QStyle::State_Selected
)
56 painter
->setPen(Qt::blue
);
58 painter
->setPen(Qt::black
);
60 painter
->setFont(QFont("Arial", 16));
62 painter
->drawPixmap( option
.rect
.topLeft() + QPoint( 4, 4 ) , index
.data( Qt::DecorationRole
).value
<QIcon
>().pixmap( 50, 50 ) );
64 painter
->drawText( option
.rect
.topLeft() + QPoint( 55, 35 ) , index
.data( Qt::DisplayRole
).toString() );
66 painter
->setFont(QFont("Arial", 12));
70 textRect
.setLeft( option
.rect
.topLeft().x() + 6 );
71 textRect
.setTop( option
.rect
.topLeft().y() + 48 );
72 textRect
.setWidth( 250 );
73 textRect
.setHeight( 100 - textRect
.top() );
75 painter
->drawText ( textRect
, Qt::TextWordWrap
, index
.data( ShortDescriptionRole
).toString() );
82 QSize
ServiceListDelegate::sizeHint(const QStyleOptionViewItem
& option
, const QModelIndex
& index
) const
89 return QSize ( 252, 102 );