X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fdelegates%2Fstringlistdelegate.cpp;fp=src%2Fdelegates%2Fstringlistdelegate.cpp;h=12d12ef52f5c9eb25e9e8886502a67b45bb163dc;hb=c05076dcd4d93a240d93c21750084434e906b913;hp=991abb0fac87f27d0eef9b87ec56b0bfd3431111;hpb=b98fce7167dd8e35d165e28d3a1bdec16a5470a3;p=emufront diff --git a/src/delegates/stringlistdelegate.cpp b/src/delegates/stringlistdelegate.cpp index 991abb0..12d12ef 100644 --- a/src/delegates/stringlistdelegate.cpp +++ b/src/delegates/stringlistdelegate.cpp @@ -20,6 +20,8 @@ */ #include "stringlistdelegate.h" #include "fileextensionwidget.h" +#include +#include StringListDelegate::StringListDelegate(QString separator, QObject *parent) : QStyledItemDelegate(parent), separator(separator) @@ -35,6 +37,7 @@ StringListDelegate::StringListDelegate(QString separator, QObject *parent) : QWidget* StringListDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { StringListWidget *editor = new StringListWidget(parent); + editor->setFixedSize(WIDTH, HEIGHT); QString str = index.model()->data(index, Qt::DisplayRole).toString(); editor->setItems(str.split(separator, QString::SkipEmptyParts)); connect(editor, SIGNAL(stringListUpdated()), this, SLOT(commitAndCloseEditor())); @@ -64,6 +67,23 @@ void StringListDelegate::commitAndCloseEditor() QSize StringListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - QSize sz(300,300); + QSize sz(WIDTH, HEIGHT); return sz; } + +void StringListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + if (option.state & QStyle::State_Editing) { + QRect rc(option.rect.x(), option.rect.y(), WIDTH, HEIGHT); + painter->fillRect(rc, option.palette.highlight()); + } + else { + painter->save(); + QRect rc(option.rect.x(), option.rect.y(), WIDTH, HEIGHT); + painter->fillRect(rc, (option.state & QStyle::State_Selected) ? option.palette.highlight() : option.palette.light() ); + QString str = index.model()->data(index, Qt::DisplayRole).toString(); + painter->setBrush(option.palette.foreground()); + painter->drawText(rc, str); + painter->restore(); + } +}