void ItemsViewDelegate::updateItemWidgets( const QList<QWidget*> widgets,
        const QStyleOptionViewItem& option,
        const QPersistentModelIndex& index ) const
{
    const GluonPlayer::GameItemsModel* model = qobject_cast<const GluonPlayer::GameItemsModel*>( index.model() );
    if( !model )
    {
        kDebug() << "Warning - Invalid Model!";
        return;
    }

    // setup the install button
    int margin = option.fontMetrics.height() / 2;
    int right = option.rect.width();

    const_cast<QSize&>( m_buttonSize ) = QSize( 32, 32 );

    KPushButton* playButton = qobject_cast<KPushButton*>( widgets.at( DelegatePlayButton ) );
    if( playButton )
    {
        playButton->setIcon( KIcon( "media-playback-start" ) );
        playButton->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::MinimumExpanding );
        playButton->resize( m_buttonSize );
        playButton->move( right - playButton->width() - margin, option.fontMetrics.height() + playButton->height() * 0.5 );
    }

    GameTextLabel* gameName = qobject_cast<GameTextLabel*>( widgets.at( DelegateGameName ) );
    // gameName->setWordWrap(true);
    if( gameName )
    {
        gameName->move( margin + m_buttonSize.width() * 3, option.fontMetrics.height() );
        gameName->resize( QSize( option.rect.width() - ( margin * 4 ) - m_buttonSize.width() * 4, option.fontMetrics.height() * 2 ) );
        gameName->setText( index.data( GluonPlayer::GameItemsModel::GameNameRole ).toString() );
    }

    GameTextLabel* gameDescription = qobject_cast<GameTextLabel*>( widgets.at( DelegateGameDescription ) );
    // gameName->setWordWrap(true);
    if( gameDescription )
    {
        gameDescription->move( margin + m_buttonSize.width() * 3,  option.fontMetrics.height() * 1 + gameName->size().height() );
        gameDescription->resize( QSize( option.rect.width() - ( margin * 4 ) - m_buttonSize.width() * 4, option.fontMetrics.height() * 2 ) );
        gameDescription->setText( index.data( GluonPlayer::GameItemsModel::GameDescriptionRole ).toString() );
    }

}
void ServiceItemDelegate::updateItemWidgets(const QList<QWidget*> widgets,
                                              const QStyleOptionViewItem& option,
                                              const QPersistentModelIndex& index) const
{
    QCheckBox* checkBox = static_cast<QCheckBox*>(widgets[0]);
    KPushButton *configureButton = static_cast<KPushButton*>(widgets[1]);

    const int itemHeight = sizeHint(option, index).height();

    // Update the checkbox showing the service name and icon
    const QAbstractItemModel* model = index.model();
    checkBox->setText(model->data(index).toString());
    const QString iconName = model->data(index, Qt::DecorationRole).toString();
    if (!iconName.isEmpty()) {
        checkBox->setIcon(KIcon(iconName));
    }
    checkBox->setChecked(model->data(index, Qt::CheckStateRole).toBool());

    const bool configurable = model->data(index, ServiceModel::ConfigurableRole).toBool();

    int checkBoxWidth = option.rect.width();
    if (configurable) {
        checkBoxWidth -= configureButton->sizeHint().width();
    }
    checkBox->resize(checkBoxWidth, checkBox->sizeHint().height());
    checkBox->move(0, (itemHeight - checkBox->height()) / 2);

    // Update the configuration button
    if (configurable) {
        configureButton->setEnabled(checkBox->isChecked());
        configureButton->setIcon(KIcon("configure"));
        configureButton->resize(configureButton->sizeHint());
        configureButton->move(option.rect.right() - configureButton->width(),
                              (itemHeight - configureButton->height()) / 2);
    }
    configureButton->setVisible(configurable);
}
void CommentItemsViewDelegate::updateItemWidgets( const QList<QWidget*> widgets,
        const QStyleOptionViewItem& option,
        const QPersistentModelIndex& index ) const
{
    const GluonPlayer::CommentItemsModel* model = qobject_cast<const GluonPlayer::CommentItemsModel*>( index.model() );
    if( !model )
    {
        kDebug() << "Warning - Invalid Model!";
        return;
    }

    // setup the install button
    int margin = option.fontMetrics.height() / 2;
    int right = option.rect.width();
    int bottom = option.rect.height();

    const_cast<QSize&>( m_buttonSize ) = QSize( 32, 32 );

    KPushButton* replyButton = qobject_cast<KPushButton*>( widgets.at( DelegateCommentReplyButton ) );
    if( replyButton )
    {
        replyButton->setVisible( const_cast<GluonPlayer::CommentItemsModel*>( model )->isOnline() );
        replyButton->setIcon( KIcon( "edit-undo" ) );
        replyButton->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::MinimumExpanding );
        replyButton->resize( m_buttonSize );
        replyButton->move( right - replyButton->width() - margin, bottom - m_buttonSize.height() * 1.5 );
    }

    KSqueezedTextLabel* author = qobject_cast<KSqueezedTextLabel*>( widgets.at( DelegateCommentAuthor ) );
    if( author )
    {
        author->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::MinimumExpanding );
        author->resize( right / 5, m_buttonSize.height() );
        author->move( margin, option.fontMetrics.height() );
        author->setText( index.data( GluonPlayer::CommentItemsModel::AuthorRole ).toString() );
    }

    KSqueezedTextLabel* dateTime = qobject_cast<KSqueezedTextLabel*>( widgets.at( DelegateCommentDateTime ) );
    if( dateTime )
    {
        dateTime->resize( author->size().width(), author->size().height() );
        dateTime->move( author->x() + author->size().width(), author->y() );
        dateTime->setText( index.data( GluonPlayer::CommentItemsModel::DateTimeRole ).toString() );
    }

    KSqueezedTextLabel* title = qobject_cast<KSqueezedTextLabel*>( widgets.at( DelegateCommentTitle ) );
    if( title )
    {
        title->resize( dateTime->size().width(), dateTime->size().height() );
        title->move( dateTime->x() + dateTime->size().width(), dateTime->y() );
        title->setText( index.data( GluonPlayer::CommentItemsModel::TitleRole ).toString() );
    }

    KSqueezedTextLabel* rating = qobject_cast<KSqueezedTextLabel*>( widgets.at( DelegateCommentRating ) );
    if( rating )
    {
        rating->resize( title->size().width(), title->size().height() );
        rating->move( title->x() + title->size().width(), title->y() );
        rating->setText( index.data( GluonPlayer::CommentItemsModel::RatingRole ).toString() );
    }

    KSqueezedTextLabel* body = qobject_cast<KSqueezedTextLabel*>( widgets.at( DelegateCommentBody ) );
    if( body )
    {
        body->resize( right - 2 * margin, bottom - author->size().height() - 2 * margin );
        body->move( margin, option.fontMetrics.height()  + author->size().height() );
        body->setText( index.data( GluonPlayer::CommentItemsModel::BodyRole ).toString() );
    }
}