Commit 5130ce2b authored by Gaël de Chalendar's avatar Gaël de Chalendar
Browse files

Corrected the chat dialog items drawing problem

svn path=/trunk/playground/games/ksirk/; revision=645555
parent 1b425561
......@@ -17,7 +17,6 @@
#include "KsirkChatDelegate.h"
#include "KsirkChatItem.h"
#include "KsirkChatModel.h"
#include <kdebug.h>
#include <QPainter>
......@@ -34,13 +33,15 @@ void KsirkChatDelegate::paint(QPainter *painter,
{
kDebug() << "KsirkChatDelegate::paint" << endl;
KsirkChatItem m = index.model()->data(index, Qt::DisplayRole).value<KsirkChatItem>();
if (m.first.size()!=0)
if (!m.first.isEmpty())
{
kDebug() << " " <<m.first << " / " << m.second << endl;
KChatBaseItemDelegate::paint(painter, option, index, m.first, m.second);
return;
}
m.paint(painter, option,index.row());
else
{
m.paint(painter, option,index.row());
}
}
QSize KsirkChatDelegate::sizeHint(const QStyleOptionViewItem & option ,
......@@ -48,7 +49,7 @@ QSize KsirkChatDelegate::sizeHint(const QStyleOptionViewItem & option ,
{
kDebug() << "KsirkChatDelegate::sizeHint" << endl;
KsirkChatItem m = index.model()->data(index, Qt::DisplayRole).value<KsirkChatItem>();
if (m.first.size()!=0)
if (!m.first.isEmpty())
{
return KChatBaseItemDelegate::sizeHint(option, index, m.first, m.second);
}
......@@ -57,10 +58,4 @@ QSize KsirkChatDelegate::sizeHint(const QStyleOptionViewItem & option ,
return result;
}
KChatBaseModel* KsirkChatDelegate::model()
{
kDebug() << "KsirkChatDelegate::model" << endl;
return (KChatBaseModel*)m_model;
}
#include "KsirkChatDelegate.moc"
......@@ -18,11 +18,8 @@
#ifndef KSIRKCHATDELEGATE_H
#define KSIRKCHATDELEGATE_H
#include <kchatbase.h>
#include <kchatbaseitemdelegate.h>
class KsirkChatModel;
class KsirkChatDelegate : public KChatBaseItemDelegate
{
Q_OBJECT
......@@ -36,11 +33,6 @@ public:
QSize sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index ) const;
virtual KChatBaseModel* model();
private:
KsirkChatModel* m_model;
};
#endif // KSIRKCHATDELEGATE_H
......@@ -48,13 +48,20 @@ void KsirkChatItem::paint(QPainter* p,
const QStyleOptionViewItem &option, int row)
{
std::cerr << "KsirkChatItem::paint" << std::endl;
unsigned int h = 20;//height(listBox()) ;
QTextDocument fake; // used to allow to compute lines height
fake.setHtml("gpl");
fake.setDefaultFont(option.font);
fake.adjustSize();
fake.setTextWidth ( -1 );
unsigned int h = fake.size().height();
unsigned int x = 0;
for (int i = 0 ; i < m_order.size(); i++)
{
QTextDocument rt;
rt.setHtml(m_strings[i]);
rt.setDefaultFont(p->font());
rt.setDefaultFont(option.font);
rt.adjustSize();
rt.setTextWidth ( -1 );
QPixmap px(rt.size().toSize());
......@@ -65,7 +72,7 @@ void KsirkChatItem::paint(QPainter* p,
{
case Text:
kDebug() << " paint string '" << m_strings[i] << "' at " << x << ", " << row*h << endl;
p->drawPixmap(x,row*h,px);
p->drawPixmap(option.rect.x()+x,option.rect.y(),px);
x += px.width();
break;
case Pixmap:
......@@ -73,7 +80,7 @@ void KsirkChatItem::paint(QPainter* p,
{
kDebug() << " paint pixmap at " << x << ", " << row*h << endl;
QPixmap scaled = m_pixmaps[i].scaledToHeight(h);
p->drawPixmap(x,row*h,scaled);
p->drawPixmap(option.rect.x()+x,option.rect.y(),scaled);
x+= scaled.width();
}
break;
......@@ -85,7 +92,13 @@ void KsirkChatItem::paint(QPainter* p,
QSize KsirkChatItem::sizeHint(const QStyleOptionViewItem &option)
{
unsigned int w = 0;
unsigned int h = 20;
QTextDocument fake; // used to allow to compute lines height
fake.setHtml("gpl");
fake.setDefaultFont(option.font);
fake.adjustSize();
fake.setTextWidth ( -1 );
unsigned int h = fake.size().height();
for (int i = 0 ; i < m_order.size(); i++)
{
QTextDocument rt;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment