SVN commit 855479 by josebur: Continuing to implement the new delegate...not quite working yet M +3 -0 createpackage.ui M +24 -3 structuredelegate.cpp M +4 -0 structuredelegate.h M +5 -5 structuremodel.cpp --- trunk/playground/base/plasmagik/createpackage.ui #855478:855479 @@ -93,6 +93,9 @@ true + + true + --- trunk/playground/base/plasmagik/structuredelegate.cpp #855478:855479 @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -37,11 +38,22 @@ void StructureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { + if (index.column() == 0) { + paintMainColumn(painter, option, index); + } else if (index.column() == 1) { + paintWidgetColumn(painter, option, index); + } else { + kDebug() << "Unexpected column number"; + } +} + +void StructureDelegate::paintMainColumn(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ const int left = option.rect.left(); const int top = option.rect.top(); const int width = option.rect.width(); const int height = calcItemHeight(option); - + bool leftToRight = (painter->layoutDirection() == Qt::LeftToRight); QIcon::Mode iconMode = QIcon::Normal; @@ -79,7 +91,7 @@ Qt::AlignTop | Qt::AlignLeft, userPath); // Main icon - + // index.icon(index).paint(&p, // leftToRight ? left + UNIVERSAL_PADDING : left + width - UNIVERSAL_PADDING - MAIN_ICON_SIZE, // top + UNIVERSAL_PADDING, @@ -101,13 +113,22 @@ QRect paintRect = option.rect; p.setCompositionMode(QPainter::CompositionMode_DestinationIn); p.fillRect(paintRect, gradient); + p.end(); painter->drawPixmap(option.rect.topLeft(), pixmap); } +void StructureDelegate::paintWidgetColumn(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QPushButton *fileButton = new QPushButton(); + fileButton->setIcon(KIcon("document-open")); + fileButton->show(); +} + QSize StructureDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - return QSize(0, calcItemHeight(option)); + int width = (index.column() == 0) ? 0 : 90; + return QSize(width, calcItemHeight(option)); } void StructureDelegate::getFileData() --- trunk/playground/base/plasmagik/structuredelegate.h #855478:855479 @@ -19,6 +19,10 @@ private slots: void getFileData(); void getDirectoryData(); + + private: + void paintMainColumn(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + void paintWidgetColumn(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; }; #endif --- trunk/playground/base/plasmagik/structuremodel.cpp #855478:855479 @@ -79,7 +79,7 @@ int StructureModel::columnCount(const QModelIndex &/*parent*/) const { - return 1; + return 2; } QVariant StructureModel::data(const QModelIndex &index, int role) const @@ -122,7 +122,7 @@ if (section == 0) { return i18n("Package"); } else if (section == 1) { - return i18n("Your Data"); + return i18n("Widget"); } } return QVariant(); @@ -131,9 +131,9 @@ Qt::ItemFlags StructureModel::flags(const QModelIndex &index) const { Qt::ItemFlags flags = QAbstractItemModel::flags(index); - if (index.column() == 1) { - flags |= Qt::ItemIsEditable; - } +// if (index.column() == 1) { +// flags |= Qt::ItemIsEditable; +// } return flags; }