Small fixes to delegate rendering.
authorMikko Keinänen <mikko.keinanen@gmail.com>
Sun, 26 Dec 2010 02:15:21 +0000 (04:15 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Sun, 26 Dec 2010 02:15:21 +0000 (04:15 +0200)
doc/tests.txt
src/delegates/stringlistdelegate.cpp
src/delegates/stringlistdelegate.h
src/views/setupeditview.cpp

index cbee2ca..bb9b00c 100644 (file)
@@ -220,13 +220,17 @@ Delete all the platforms and media types first.
 5.2.1 Add setup with no platforms and media types configured
 ------------------------------------------------------------
 - Click Add button
-> 
+> An error message is shown that no platform and/or media types are configured. 
 
 5.2.2 Add setup with no platforms configured
 --------------------------------------------
+- Click Add button
+> An error message is shown that no platform and/or media types are configured. 
 
 5.2.3 Add setup with no media types configured
 ----------------------------------------------
+- Click Add button
+> An error message is shown that no platform and/or media types are configured. 
 
 5.2.3 Add setup with a single media type and a single platform configured
 -------------------------------------------------------------------------
index 991abb0..12d12ef 100644 (file)
@@ -20,6 +20,8 @@
 */
 #include "stringlistdelegate.h"
 #include "fileextensionwidget.h"
+#include <QPainter>
+#include <QDebug>
 
 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();
+       }
+}
index 8deab5a..f7672ce 100644 (file)
@@ -27,11 +27,13 @@ class StringListDelegate : public QStyledItemDelegate
     Q_OBJECT
 public:
     StringListDelegate(QString separator, QObject *parent = 0);
-    //void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
+    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
     QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
     QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
     void setEditorData(QWidget *editor, const QModelIndex &index) const;
     void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
+       static const int WIDTH = 150;
+       static const int HEIGHT = 100;
 
 private slots:
     void commitAndCloseEditor();
index 8c607bb..160b8d3 100644 (file)
@@ -50,6 +50,7 @@ SetupEditView::SetupEditView(PlatformModel *plfModel, MediaTypeModel *mdtModel,
 
     StringListDelegate *fileTypeDelegate = new StringListDelegate(SetupModel::FILE_TYPE_EXTENSION_SEPARATOR, this);
     objectList->setItemDelegateForColumn(SetupModel::Setup_FileTypeExtensions, fileTypeDelegate);
+       objectList->setColumnWidth(SetupModel::Setup_FileTypeExtensions, StringListDelegate::WIDTH);
     postInit();
 }