コード例 #1
0
void ActionColumnItemDelegate::drawDownloadProgressBar(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QStyleOptionProgressBarV2 opt;
    opt.initFrom(bar);
    opt.rect = option.rect;
    opt.rect.adjust(3,3,-3,-3);
    opt.textVisible = true;
    opt.textAlignment = Qt::AlignCenter;
    opt.state = QStyle::State_Enabled | QStyle::State_Active | QStyle::State_Raised;

    // get progress
    QMap<QString, QVariant> progress = index.model()->data(index).toMap();

    QString text = QString::fromLatin1(" %1 %2 %3 ").arg(progress["percentage"].toString())
                                                       .arg(progress["size"].toString())
                                                       .arg(progress["speed"].toString());
                                                       //.arg(progress["time"].toString());
                                                       //.arg(progress["eta"].toString());

    // set progress
    opt.minimum  = 0;
    opt.maximum  = progress["bytesTotal"].toFloat();
    opt.progress = progress["bytesReceived"].toFloat();
    opt.text     = text;

    bar->style()->drawControl(QStyle::CE_ProgressBar,&opt,painter,bar);
}
コード例 #2
0
ファイル: SliderDoubleSpinBox.cpp プロジェクト: KDE/tikzkit
QStyleOptionProgressBarV2 SliderDoubleSpinBoxPrivate::progressBarOptions() const
{
    QStyleOptionSpinBox spinOpts = spinBoxOptions();

    // scale up to model requrested precision with int
    const double factor = std::pow(10.0, q->decimals());

    //Create opts for drawing the progress portion
    QStyleOptionProgressBarV2 progressOpts;
    progressOpts.initFrom(q);
    progressOpts.maximum = q->maximum() * factor;
    progressOpts.minimum = q->minimum() * factor;
    progressOpts.progress = q->value() * factor;
    progressOpts.text = QString::number(q->value(), 'f', q->decimals()) + q->suffix();
    progressOpts.textAlignment = Qt::AlignCenter;
    progressOpts.textVisible = ! q->lineEdit()->isVisible();

    //Change opts rect to be only the ComboBox's text area
    progressOpts.rect = progressRect(spinOpts);

    return progressOpts;
}
コード例 #3
0
void PartitionDelegate::paint( QPainter* painter, const QStyleOptionViewItem& _option, const QModelIndex& index ) const
{
    QStyleOptionViewItemV4 option = _option;
    initStyleOption( &option, index );
    option.palette = mStyle->standardPalette();
#if defined( Q_OS_MAC )
    option.font.setPointSize( option.font.pointSize() -2 );
#endif
    
    const bool selected = option.state & QStyle::State_Selected;
    const bool hovered = option.state & QStyle::State_MouseOver;
    const int margin = option.widget->inherits( "QAbstractItemView" ) ? 3 : 0;
    const qint64 wbfsFSId = 0x25;
    pPartition partition = mModel->partition( index );
    
    if ( partition.property( pPartition::FileSystemId ).toLongLong() == wbfsFSId ) {
        // update wbfs partitions informations
        if ( partition.property( pPartition::LastCheck ).toDateTime() < QDateTime::currentDateTime()
            && ( partition.property( pPartition::UsedSize ).toLongLong() == -1 || partition.property( pPartition::FreeSize ).toLongLong() == -1 ) ) {
            // use a scope to avoid problems with windows partition read locked
            {
                bool created = false;
                QWBFS::Partition::Handle handle = QWBFS::Driver::getHandle( partition.property( pPartition::DevicePath ).toString(), &created );
                QWBFS::Driver driver( handle );
                QWBFS::Partition::Status status;
                
                driver.status( status );
                partition.updateSizes( status.size, status.free );
                
                if ( created ) {
                    QWBFS::Driver::closeHandle( handle );
                }
            }
            
            mModel->updatePartition( partition );
        }
    }
    
    int total = 100;
    int used = ( (qreal)partition.property( pPartition::UsedSize ).toLongLong() /(qreal)partition.property( pPartition::TotalSize ).toLongLong() ) *(qreal)100;
    
    QStyleOptionProgressBarV2 pbOption;
    pbOption.initFrom( option.widget );
    pbOption.state = option.state;
    pbOption.palette = option.palette;
    pbOption.rect = option.rect.adjusted( margin, margin, -margin, -margin );
    pbOption.bottomToTop = false;
    pbOption.invertedAppearance = false;
    pbOption.orientation = Qt::Horizontal;
    pbOption.maximum = total;
    pbOption.minimum = 0;
    pbOption.progress = used;
    pbOption.text = QString::null;
    pbOption.textAlignment = Qt::AlignCenter;
    pbOption.textVisible = false;
    
    pbOption.palette.setColor( QPalette::Highlight, QColor( 0, 160, 0, 100 ) );
    
    QStyleOptionButton bOption;
    bOption.initFrom( option.widget );
    bOption.state = option.state;
    bOption.palette = option.palette;
    bOption.rect = option.rect.adjusted( margin, margin, -margin, -margin );
    //bOption.icon = partition.fileSystem == "WBFS" ? QIcon( ":/icons/256/wii.png" ) : partition.icon();
    bOption.iconSize = QSize( bOption.rect.height() -5, bOption.rect.height() -5 );
    bOption.text = QString( "%1 - %2" )
        .arg( partition.property( pPartition::DisplayText ).toString() )
        .arg( pCoreUtils::fileSizeToString( partition.property( pPartition::TotalSize ).toLongLong() ) )
        ;
    
    if ( selected || hovered ) {
        paintFrame( painter, &option, selected );
    }
    
    painter->setFont( option.font );
    
    mStyle->drawControl( QStyle::CE_ProgressBar, &pbOption, painter, option.widget );
    mStyle->drawControl( QStyle::CE_PushButtonLabel, &bOption, painter, option.widget );
}