23 #include <QFontMetrics>
24 #include <QStyleOptionViewItem>
25 #include <QModelIndex>
27 #include <QLinearGradient>
29 QAbstractItemDelegate( parent ),
31 mpCheckBox( new QCheckBox() )
47 const QStyleOptionViewItem & theOption,
48 const QModelIndex & theIndex )
const
52 if ( qVariantCanConvert<QgsDetailedItemData>( theIndex.data( Qt::UserRole ) ) )
55 qVariantValue<QgsDetailedItemData>( theIndex.data( Qt::UserRole ) );
65 thepPainter->restore();
71 const QStyleOptionViewItem & theOption,
72 const QModelIndex & theIndex )
const
74 if ( qVariantCanConvert<QgsDetailedItemData>( theIndex.data( Qt::UserRole ) ) )
77 qVariantValue<QgsDetailedItemData>( theIndex.data( Qt::UserRole ) );
80 return QSize( 378,
mpWidget->height() );
85 return QSize( 50,
height( theOption, myData ) );
91 return QSize( 50, 50 );
96 const QStyleOptionViewItem & theOption,
112 QFontMetrics myTitleMetrics(
titleFont( theOption ) );
113 QFontMetrics myDetailMetrics(
detailFont( theOption ) );
114 QFontMetrics myCategoryMetrics(
categoryFont( theOption ) );
122 if ( theOption.state & QStyle::State_Selected )
125 thepPainter->setPen( theOption.palette.highlightedText().color() );
129 thepPainter->setPen( theOption.palette.text().color() );
138 thepPainter->drawPixmap( theOption.rect.x(),
146 bool myIconFlag =
false;
147 QPixmap myDecoPixmap = theData.
icon();
148 if ( !myDecoPixmap.isNull() )
150 int iconWidth = 32, iconHeight = 32;
152 if ( myDecoPixmap.width() <= iconWidth && myDecoPixmap.height() <= iconHeight )
155 int offsetX = 0, offsetY = 0;
156 if ( myDecoPixmap.width() < iconWidth )
157 offsetX = ( iconWidth - myDecoPixmap.width() ) / 2;
158 if ( myDecoPixmap.height() < iconHeight )
159 offsetY = ( iconHeight - myDecoPixmap.height() ) / 2;
161 thepPainter->drawPixmap( myTextStartX + offsetX,
162 myTextStartY + offsetY,
168 thepPainter->drawPixmap( myTextStartX, myTextStartY, iconWidth, iconHeight, myDecoPixmap );
176 myTextStartY += myHeight / 2;
177 thepPainter->setFont(
titleFont( theOption ) );
178 thepPainter->drawText( myTextStartX,
184 thepPainter->setFont(
detailFont( theOption ) );
194 wordWrap( theData.
detail(), myDetailMetrics, theOption.rect.width() - myTextStartX );
195 QStringListIterator myLineWrapIterator( myList );
196 while ( myLineWrapIterator.hasNext() )
198 QString myLine = myLineWrapIterator.next();
199 thepPainter->drawText( myTextStartX,
209 thepPainter->drawText( myTextStartX,
242 const QStyleOptionViewItem & theOption,
249 mpWidget->setAutoFillBackground(
true );
252 if ( theOption.state & QStyle::State_Selected )
256 QPixmap myPixmap = QPixmap::grabWidget(
mpWidget );
257 thepPainter->drawPixmap( theOption.rect.x(),
263 QPainter * thepPainter,
264 int theHeight )
const
266 QColor myColor1 = theOption.palette.highlight().color();
267 QColor myColor2 = myColor1;
268 myColor2 = myColor2.lighter( 110 );
269 QLinearGradient myGradient( QPointF( 0, theOption.rect.y() ),
270 QPointF( 0, theOption.rect.y() + theHeight ) );
271 myGradient.setColorAt( 0, myColor1 );
272 myGradient.setColorAt( 0.1, myColor2 );
273 myGradient.setColorAt( 0.5, myColor1 );
274 myGradient.setColorAt( 0.9, myColor2 );
275 myGradient.setColorAt( 1, myColor2 );
276 thepPainter->fillRect( theOption.rect, QBrush( myGradient ) );
282 QFontMetrics myTitleMetrics(
titleFont( theOption ) );
283 QFontMetrics myDetailMetrics(
detailFont( theOption ) );
284 QFontMetrics myCategoryMetrics(
categoryFont( theOption ) );
291 myHeight += ( myList.count() + 1 ) * ( myDetailMetrics.height() -
verticalSpacing() );
305 QFont myFont = theOption.font;
311 QFont myFont = theOption.font;
312 myFont.setBold(
true );
319 myTitleFont.setBold(
true );
320 myTitleFont.setPointSize( myTitleFont.pointSize() );
326 QFontMetrics theMetrics,
329 if ( theString.isEmpty() )
330 return QStringList();
331 if ( 50 >= theWidth )
332 return QStringList() << theString;
337 QString myCumulativeLine =
"";
338 QString myStringToPreviousSpace =
"";
339 int myPreviousSpacePos = 0;
340 for (
int i = 0; i < theString.count(); ++i )
342 QChar myChar = theString.at( i );
343 if ( myChar == QChar(
' ' ) )
345 myStringToPreviousSpace = myCumulativeLine;
346 myPreviousSpacePos = i;
348 myCumulativeLine += myChar;
349 if ( theMetrics.width( myCumulativeLine ) >= theWidth )
354 myList << myStringToPreviousSpace.trimmed();
355 i = myPreviousSpacePos;
356 myStringToPreviousSpace =
"";
357 myCumulativeLine =
"";
361 if ( !myCumulativeLine.trimmed().isEmpty() )
363 myList << myCumulativeLine.trimmed();