richtextitemdelegate.cpp (krename-4.0.9) | : | richtextitemdelegate.cpp (krename-4.90.90) | ||
---|---|---|---|---|
skipping to change at line 19 | skipping to change at line 19 | |||
/*************************************************************************** | /*************************************************************************** | |||
* * | * * | |||
* This program is free software; you can redistribute it and/or modify * | * This program is free software; you can redistribute it and/or modify * | |||
* it under the terms of the GNU General Public License as published by * | * it under the terms of the GNU General Public License as published by * | |||
* the Free Software Foundation; either version 2 of the License, or * | * the Free Software Foundation; either version 2 of the License, or * | |||
* (at your option) any later version. * | * (at your option) any later version. * | |||
* * | * * | |||
***************************************************************************/ | ***************************************************************************/ | |||
#include "richtextitemdelegate.h" | #include "richtextitemdelegate.h" | |||
#include "krenamefile.h" | ||||
#include "krenamemodel.h" | ||||
#include <QPainter> | #include <QPainter> | |||
#include <QRectF> | #include <QRectF> | |||
#include <QTextDocument> | #include <QTextDocument> | |||
RichTextItemDelegate::RichTextItemDelegate(QObject* parent) | RichTextItemDelegate::RichTextItemDelegate(QObject *parent) | |||
: QItemDelegate(parent) | : QItemDelegate(parent) | |||
{ | { | |||
m_document = new QTextDocument(this); | m_document = new QTextDocument(this); | |||
} | } | |||
void RichTextItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const | void RichTextItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex &index) const | |||
{ | { | |||
// prepare | // prepare | |||
painter->save(); | painter->save(); | |||
painter->setClipRect(option.rect); | painter->setClipRect(option.rect); | |||
this->drawBackground(painter, option, index); | this->drawBackground(painter, option, index); | |||
if(option.state & QStyle::State_Selected) | if (option.state & QStyle::State_Selected) { | |||
{ | ||||
painter->fillRect(option.rect, option.palette.highlight()); | painter->fillRect(option.rect, option.palette.highlight()); | |||
} | } | |||
//QItemDelegate::paint(painter, option, index); | //QItemDelegate::paint(painter, option, index); | |||
QPixmap pixmap = index.model()->data(index, Qt::DecorationRole).value<QPixma p>(); | QPixmap pixmap = index.model()->data(index, Qt::DecorationRole).value<QPixma p>(); | |||
QString text = index.model()->data(index, Qt::DisplayRole).toString(); | QString text = index.model()->data(index, Qt::DisplayRole).toString(); | |||
if(!pixmap.isNull()) | if (!pixmap.isNull()) { | |||
{ | int offsetX = qMax(pixmap.width(), KRenameFile::iconSize()); | |||
const int DEFAULT_OFFSET = 80; | ||||
int offsetX = qMax(pixmap.width(), DEFAULT_OFFSET); | ||||
QRect pixmapRect(option.rect.x(), | QRect pixmapRect(option.rect.x(), | |||
option.rect.y(), | option.rect.y(), | |||
pixmap.width(), | pixmap.width(), | |||
option.rect.height()); | option.rect.height()); | |||
QRectF textRect( 0.0, 0.0, | QRectF textRect(0.0, 0.0, | |||
static_cast<qreal>(option.rect.width() - offsetX), | static_cast<qreal>(option.rect.width() - offsetX), | |||
static_cast<qreal>(option.rect.height())); | static_cast<qreal>(option.rect.height())); | |||
this->drawDecoration(painter, option, | this->drawDecoration(painter, option, | |||
pixmapRect, | pixmapRect, | |||
pixmap); | pixmap); | |||
painter->save(); | painter->save(); | |||
painter->translate(option.rect.x() + offsetX, | painter->translate(option.rect.x() + offsetX, | |||
option.rect.y()); | option.rect.y()); | |||
m_document->setHtml(text); | m_document->setHtml(text); | |||
m_document->drawContents(painter, textRect); | m_document->drawContents(painter, textRect); | |||
painter->restore(); | painter->restore(); | |||
} | } else { | |||
else | ||||
{ | ||||
painter->setFont(option.font); | painter->setFont(option.font); | |||
painter->drawText(option.rect, | painter->drawText(option.rect, | |||
option.displayAlignment, | option.displayAlignment, | |||
text); | text); | |||
} | } | |||
this->drawFocus(painter, option, option.rect); | this->drawFocus(painter, option, option.rect); | |||
// done | // done | |||
painter->restore(); | painter->restore(); | |||
} | } | |||
QSize RichTextItemDelegate::sizeHint(const QStyleOptionViewItem& option, const Q ModelIndex& index ) const | QSize RichTextItemDelegate::sizeHint(const QStyleOptionViewItem &option, const Q ModelIndex &index) const | |||
{ | { | |||
return QItemDelegate::sizeHint(option, index); | if (static_cast<const KRenameModel *>(index.model())->isPreviewEnabled()) { | |||
return QSize(KRenameFile::iconSize(), KRenameFile::iconSize()); | ||||
} else { | ||||
return QItemDelegate::sizeHint(option, index); | ||||
} | ||||
} | } | |||
End of changes. 9 change blocks. | ||||
16 lines changed or deleted | 17 lines changed or added |