author | John Kern <johnk@symbian.org> |
Thu, 09 Sep 2010 20:03:34 -0700 | |
changeset 47 | c6e75ec74fc8 |
parent 42 | b9716e8867f1 |
permissions | -rwxr-xr-x |
42
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
1 |
#include <QFile> |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
2 |
#include <QSvgRenderer> |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
3 |
|
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
4 |
|
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
5 |
#include "zodiacdelegate.h" |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
6 |
|
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
7 |
void ZodiacDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
8 |
const QModelIndex &index) const |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
9 |
{ |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
10 |
painter->save(); |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
11 |
painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing); |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
12 |
|
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
13 |
if (option.state & QStyle::State_Selected) { |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
14 |
painter->fillRect(option.rect, option.palette.highlight()); |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
15 |
} |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
16 |
|
47 | 17 |
// use color assocaited with Zodiac for background. |
18 |
painter->fillRect(option.rect,index.model()->data(index,Qt::BackgroundRole).value<QBrush>()); |
|
19 |
||
42
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
20 |
// draw the svg image. |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
21 |
int xOffset = 10; |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
22 |
int yOffset = 5; |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
23 |
int height = 15; |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
24 |
int width = 15; |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
25 |
QRectF imgRect(option.rect.x()+xOffset,option.rect.y()+yOffset,width,height); |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
26 |
QString svgFile(index.model()->data(index,Qt::DecorationRole).toString()); |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
27 |
QSvgRenderer renderer(svgFile); |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
28 |
renderer.render(painter,imgRect); |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
29 |
|
47 | 30 |
// now we will draw the name |
31 |
// set the pen |
|
32 |
painter->setPen(index.model()->data(index,Qt::TextColorRole).value<QColor>()); |
|
33 |
// determine geometry |
|
42
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
34 |
int xOffsetText = 55; |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
35 |
QRect rect(option.rect.x()+xOffsetText,option.rect.y(),option.rect.width(), option.rect.height()); |
47 | 36 |
// write the name |
42
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
37 |
painter->drawText(rect,Qt::AlignVCenter, |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
38 |
index.model()->data(index,Qt::DisplayRole).toString()); |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
39 |
|
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
40 |
painter->restore(); |
b9716e8867f1
checking in example; variations on List Widgets
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
41 |
} |