{
painter
->setRenderHint
(QPainter::TextAntialiasing);
if (option.
state==QStyle::State_Selected) painter->setBrush(Qxygen->roster()->palette().highlight());
else
painter
->setBrush
(QBrush(Qt
::white));
rosterItem *item = static_cast<rosterItem*>(index.internalPointer());
int width=Qxygen->viewWidth(), height;
QImage img
=Qxygen
->model
()->data
(index, Qt
::DecorationRole).
value<QImage>
();
QRect irect
(option.
rect.
x(), option.
rect.
y()+2, img.
width(), img.
height());
QRect nrect
(option.
rect.
x()+img.
width()+2, option.
rect.
y()+2, width
-img.
width()-2, fmetrics.
height());
painter->drawImage(irect, img);
// CONTACT NAME
painter->drawText(nrect, Qt::AlignLeft|Qt::AlignTop, elidedText(static_cast<const QFontMetrics&>(Qxygen->roster()->fontMetrics()), nrect.width(),Qt::ElideRight,item->data(0)));
if(!item->data(1).isEmpty())
{
int height=fmetrics.height()*qRound(fmetrics.width(item->data(1))/width);
if(fmetrics.width(item->data(1))%width>0)
height+=fmetrics.height();
QRect drect
(option.
rect.
x(), option.
rect.
y()+img.
height()+2, width, height
);
// DESCRIPTION
painter->drawText(drect, Qt::TextWordWrap|Qt::AlignLeft|Qt::AlignTop, item->data(1));
}
}
{
rosterItem *item = static_cast<rosterItem*>(index.internalPointer());
int width=Qxygen->viewWidth(), height;
QImage img
(Qxygen
->model
()->data
(index, Qt
::DecorationRole).
value<QImage>
());
if(item->data(1).isEmpty())
{
height=img.height()+2;
}
else
{
height=img.height()+2+fmetrics.height()*qRound(fmetrics.width(item->data(1))/width);
printf("%d %d\n", height, qRound(fmetrics.width(item->data(1))/width));
if(fmetrics.width(item->data(1))%width>0)
height+=fmetrics.height();
}
return QSize(width, height
+2);
}
void rosterDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->setRenderHint(QPainter::TextAntialiasing);
if (option.state==QStyle::State_Selected)
painter->setBrush(Qxygen->roster()->palette().highlight());
else
painter->setBrush(QBrush(Qt::white));
QTextOption textOption;
textOption.setWrapMode(QTextOption::WordWrap);
rosterItem *item = static_cast<rosterItem*>(index.internalPointer());
int width=Qxygen->viewWidth(), height;
QFontMetrics fmetrics=Qxygen->fontMetrics();
QImage img=Qxygen->model()->data(index, Qt::DecorationRole).value<QImage>();
QRect irect(option.rect.x(), option.rect.y()+2, img.width(), img.height());
QRect nrect(option.rect.x()+img.width()+2, option.rect.y()+2, width-img.width()-2, fmetrics.height());
painter->drawImage(irect, img);
// CONTACT NAME
painter->drawText(nrect, Qt::AlignLeft|Qt::AlignTop, elidedText(static_cast<const QFontMetrics&>(Qxygen->roster()->fontMetrics()), nrect.width(),Qt::ElideRight,item->data(0)));
if(!item->data(1).isEmpty())
{
int height=fmetrics.height()*qRound(fmetrics.width(item->data(1))/width);
if(fmetrics.width(item->data(1))%width>0)
height+=fmetrics.height();
QRect drect(option.rect.x(), option.rect.y()+img.height()+2, width, height);
// DESCRIPTION
painter->drawText(drect, Qt::TextWordWrap|Qt::AlignLeft|Qt::AlignTop, item->data(1));
}
}
QSize rosterDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
rosterItem *item = static_cast<rosterItem*>(index.internalPointer());
int width=Qxygen->viewWidth(), height;
QFontMetrics fmetrics=Qxygen->fontMetrics();
QImage img(Qxygen->model()->data(index, Qt::DecorationRole).value<QImage>());
if(item->data(1).isEmpty())
{
height=img.height()+2;
}
else
{
height=img.height()+2+fmetrics.height()*qRound(fmetrics.width(item->data(1))/width);
printf("%d %d\n", height, qRound(fmetrics.width(item->data(1))/width));
if(fmetrics.width(item->data(1))%width>0)
height+=fmetrics.height();
}
return QSize(width, height+2);
}
To copy to clipboard, switch view to plain text mode
Bookmarks