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!";
50 painter
->setRenderHint ( QPainter::Antialiasing
);
53 if (option
.state
& QStyle::State_Selected
)
54 painter
->setPen(Qt::blue
);
56 painter
->setPen(Qt::gray
);
58 painter
->drawRoundRect( option
.rect
.topLeft().x() + 2, option
.rect
.topLeft().y() + 2 ,250,66, 8 ,8 );
60 if (option
.state
& QStyle::State_Selected
)
61 painter
->setPen(Qt::blue
);
63 painter
->setPen(Qt::black
);
65 painter
->setFont(QFont("Arial", 14));
67 painter
->drawPixmap( option
.rect
.topLeft() + QPoint( 4, 4 ) , index
.data( Qt::DecorationRole
).value
<QIcon
>().pixmap( 24, 24 ) );
69 painter
->drawText( option
.rect
.topLeft() + QPoint( 35, 21 ) , index
.data( Qt::DisplayRole
).toString() );
71 painter
->setFont(QFont("Arial", 10));
74 textRect
.setLeft( option
.rect
.topLeft().x() + 6 );
75 textRect
.setTop( option
.rect
.topLeft().y() + 24 );
76 textRect
.setWidth( 248 );
77 textRect
.setHeight( 40 );
79 painter
->drawText ( textRect
, Qt::TextWordWrap
, index
.data( ShortDescriptionRole
).toString() );
81 debug() << "Short description: " << index
.data( ShortDescriptionRole
).toString() ;
88 QSize
ServiceListDelegate::sizeHint(const QStyleOptionViewItem
& option
, const QModelIndex
& index
) const
95 return QSize ( 252, 70 );