oopapidocs  2.0
simpledelegate.cpp
00001 #include <QDebug>
00002 #include <QApplication>
00003 #include <QMetaType>
00004 #include <QVariant>
00005 #include <QPainter>
00006 #include <QItemEditorFactory>
00007 #include <preference.h>
00008 #include "simpledelegate.h"
00009 #include "preferencecombo.h"
00010 #include "timedisplay.h"
00011 
00012 
00013 //start id=paint
00014 void SimpleDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
00015     QStyleOptionViewItemV4 opt = option;
00016     initStyleOption(&opt, index);
00017 
00018     QStyle *style = QApplication::style();
00019 
00020     QString field = index.model()->headerData(index.column(), Qt::Horizontal).toString();
00021 
00022     QVariant var(index.data(Qt::DisplayRole));
00023     if (var.isNull()) {
00024 //        qDebug() << "mp3fd:paint - variant is null";
00025         return;
00026     }
00027 
00028     if (var.userType() == qMetaTypeId<Preference>()) {
00029         Preference p = var.value<Preference>();
00030         QString s = QString("%1").arg(p.intValue());
00031         //painter->drawText(option.rect, s, QTextOption());
00032         style->drawItemText(painter, option.rect, index.flags(), option.palette, true, s);
00033         return;
00034     }
00035     if (field == "TrackTime") {
00036 
00037         QTime time;
00038         if (var.canConvert(QVariant::Time)) time = var.toTime();
00039         else {
00040             int secs = var.toInt();
00041             time = time.addSecs(secs);
00042         }
00043         QString str = time.toString("m:ss");
00044         // painter->drawText(option.rect, str, QTextOption());
00045         style->drawItemText(painter, option.rect, index.flags(),  option.palette, true, str);
00046         return;
00047     }
00048     SUPER::paint(painter, option, index);
00049 }
00050 //end
00051 
 All Classes Namespaces Functions Enumerations