Beispiel #1
0
KPushButton * PostWidget::addButton(const QString & objName, const QString & toolTip, const KIcon & icon)
{
    KPushButton * button = new KPushButton(icon, QString(), _mainWidget);
    button->setObjectName(objName);
    button->setToolTip(toolTip);
    button->setIconSize(QSize(16,16));
    button->setMinimumSize(QSize(20, 20));
    button->setMaximumSize(QSize(20, 20));
    button->setFlat(true);
    button->setVisible(false);
    button->setCursor(Qt::PointingHandCursor);

    d->mUiButtons.insert(objName, button);
    d->buttonsLayout->addWidget( button, 1, d->mUiButtons.count() );
    return button;
}
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() );
    }
}