const qreal PrettyItemDelegate::THUMB_HEIGHT = 50.0;
const qreal PrettyItemDelegate::THUMB_WIDTH = 50.0;
const qreal PrettyItemDelegate::PADDING = 10.0;
const qreal PrettyItemDelegate::ITEM_HEIGHT = THUMB_HEIGHT+20;
const qreal PrettyItemDelegate::ITEM_WIDTH = THUMB_WIDTH+20;
PrettyItemDelegate
::PrettyItemDelegate(QObject* parent
) : QStyledItemDelegate(parent), downloadInfo(true) {
boldFont.setBold(true);
smallerBoldFont = FontUtils::smallBold();
smallerFont = FontUtils::small();
}
{
editor
->setGeometry
(QRect(40,
30,
401,
31));
editor->setLayoutDirection(Qt::LeftToRight);
//editor->setAutoFillBackground(false);
//editor->setStyleSheet(QString::fromUtf8("background-color: transparent;;"));
editor
->setFrameShape
(QFrame::WinPanel);
// editor->setFrameShadow(QFrame::Plain);
editor->setLineWidth(2);
editor->setReadOnly(true);
editor->setText("This is text test!!1");
return editor;
}
{
QTextEdit * textEdit
= static_cast<QTextEdit
*>
(editor
);
//int value = index.model()->data(index, Qt::EditRole).toUInt();
// do somthing with the widgets
}
{
QTextEdit * textEdit
= static_cast<QTextEdit
*>
(editor
);
//model->setData(index, comboBox->currentIndex(), Qt::EditRole);
}
{
editor->setGeometry(option.rect);
}
PrettyItemDelegate::~PrettyItemDelegate() { }
QSize PrettyItemDelegate
::sizeHint( const QStyleOptionViewItem
& /*option*/,
const QModelIndex& /*index*/ ) const
{
return QSize( 256, THUMB_HEIGHT
+20.0);
}
void PrettyItemDelegate
::paint( QPainter* painter,
const QStyleOptionViewItem& option, const QModelIndex& index ) const {
int itemType = index.data(ItemTypeRole).toInt();
if (itemType == ItemTypeVideo) {
paintBody( painter, option, index );
} else
QStyledItemDelegate::paint( painter, option, index );
}
void PrettyItemDelegate
::paintBody( QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const {
painter->save();
painter->translate( option.rect.topLeft() );
QRectF line
(0,
0, option.
rect.
width(), option.
rect.
height());
if (downloadInfo) line.setWidth(line.width());
painter->setClipRect(line);
// get the video metadata
const StreamItemPointer pStreamItemPointer = index.data( VideoRole ).value<StreamItemPointer>();
const StreamItem *pStreamItem = pStreamItemPointer.data();
// thumb
if (!pStreamItem->thumbnail().isNull()) {
painter
->drawImage
(QRect(0,
0, THUMB_WIDTH, THUMB_HEIGHT
), pStreamItem
->thumbnail
());
}
// media thumb
if(!pStreamItem->Mediathumbnail().isNull())
{
painter
->drawImage
(QRect(THUMB_WIDTH
+10,
0, THUMB_WIDTH, THUMB_HEIGHT
), pStreamItem
->Mediathumbnail
());
}
//save state
painter->save();
painter->restore();
// separator button line on each item
painter->setClipping(false);
painter
->setPen
(option.
palette.
color(QPalette::Midlight));
painter->drawLine(0, ITEM_HEIGHT-1, option.rect.width(), ITEM_HEIGHT-1);
painter->restore();
}
const qreal PrettyItemDelegate::THUMB_HEIGHT = 50.0;
const qreal PrettyItemDelegate::THUMB_WIDTH = 50.0;
const qreal PrettyItemDelegate::PADDING = 10.0;
const qreal PrettyItemDelegate::ITEM_HEIGHT = THUMB_HEIGHT+20;
const qreal PrettyItemDelegate::ITEM_WIDTH = THUMB_WIDTH+20;
PrettyItemDelegate::PrettyItemDelegate(QObject* parent)
: QStyledItemDelegate(parent), downloadInfo(true) {
boldFont.setBold(true);
smallerBoldFont = FontUtils::smallBold();
smallerFont = FontUtils::small();
}
QWidget *PrettyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const
{
QTextEdit *editor = new QTextEdit(parent);
editor->setGeometry(QRect(40, 30, 401, 31));
editor->setLayoutDirection(Qt::LeftToRight);
//editor->setAutoFillBackground(false);
//editor->setStyleSheet(QString::fromUtf8("background-color: transparent;;"));
editor->setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
editor->setFrameShape(QFrame::WinPanel);
// editor->setFrameShadow(QFrame::Plain);
editor->setLineWidth(2);
editor->setReadOnly(true);
editor->setText("This is text test!!1");
return editor;
}
void PrettyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QTextEdit * textEdit = static_cast<QTextEdit*>(editor);
//int value = index.model()->data(index, Qt::EditRole).toUInt();
// do somthing with the widgets
}
void PrettyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
QTextEdit * textEdit = static_cast<QTextEdit*>(editor);
//model->setData(index, comboBox->currentIndex(), Qt::EditRole);
}
void PrettyItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
PrettyItemDelegate::~PrettyItemDelegate() { }
QSize PrettyItemDelegate::sizeHint( const QStyleOptionViewItem& /*option*/,
const QModelIndex& /*index*/ ) const
{
return QSize( 256, THUMB_HEIGHT+20.0);
}
void PrettyItemDelegate::paint( QPainter* painter,
const QStyleOptionViewItem& option, const QModelIndex& index ) const {
int itemType = index.data(ItemTypeRole).toInt();
if (itemType == ItemTypeVideo) {
QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter );
paintBody( painter, option, index );
} else
QStyledItemDelegate::paint( painter, option, index );
}
void PrettyItemDelegate::paintBody( QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const {
painter->save();
painter->translate( option.rect.topLeft() );
QRectF line(0, 0, option.rect.width(), option.rect.height());
if (downloadInfo) line.setWidth(line.width());
painter->setClipRect(line);
// get the video metadata
const StreamItemPointer pStreamItemPointer = index.data( VideoRole ).value<StreamItemPointer>();
const StreamItem *pStreamItem = pStreamItemPointer.data();
// thumb
if (!pStreamItem->thumbnail().isNull()) {
painter->drawImage(QRect(0, 0, THUMB_WIDTH, THUMB_HEIGHT), pStreamItem->thumbnail());
}
// media thumb
if(!pStreamItem->Mediathumbnail().isNull())
{
painter->drawImage(QRect(THUMB_WIDTH+10, 0, THUMB_WIDTH, THUMB_HEIGHT), pStreamItem->Mediathumbnail());
}
//save state
painter->save();
painter->restore();
// separator button line on each item
painter->setClipping(false);
painter->setPen(option.palette.color(QPalette::Midlight));
painter->drawLine(0, ITEM_HEIGHT-1, option.rect.width(), ITEM_HEIGHT-1);
painter->restore();
}
To copy to clipboard, switch view to plain text mode
Bookmarks