File indexing completed on 2024-04-21 05:50:17

0001 /*
0002     SPDX-FileCopyrightText: 2009 Dario Andres Rodriguez <andresbajotierra@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kdfitemdelegate.h"
0008 
0009 #include "kdfwidget.h"
0010 #include "kdfutil.h"
0011 
0012 #include <KCapacityBar>
0013 
0014 #include <QBrush>
0015 #include <QPainter>
0016 #include <QPalette>
0017 #include <QStyleOptionViewItem>
0018 
0019 void KDFItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
0020                             const QModelIndex &index) const
0021 {
0022     if ( index.column() == KDFWidget::UsageBarCol )
0023     {
0024 
0025         int progress = index.data( Qt::UserRole ).toInt();
0026 
0027         if( progress!=-1 )
0028         {
0029             KCapacityBar bar;
0030             bar.setBarHeight( option.rect.height() -2 );
0031             bar.setValue( progress );
0032             bar.setText(i18nc("Disk percentage", "%1%", progress));
0033             //Draw red bar on >=Full_Percent
0034             if ( progress >= Full_Percent )
0035             {
0036                 QPalette p ( bar.palette() );
0037                 p.setBrush( QPalette::Highlight, QBrush( Qt::red ) );
0038                 bar.setPalette( p );
0039             }
0040 
0041             if (option.state & QStyle::State_Selected || option.state & QStyle::State_MouseOver)
0042                 QStyledItemDelegate::paint( painter, option, index );
0043 
0044             QRect rect(option.rect);
0045             bar.drawCapacityBar( painter, rect.adjusted( 0, 0, -2, -1 ) );
0046         }
0047         else
0048         {
0049             QStyledItemDelegate::paint( painter, option, index );
0050         }
0051 
0052     }
0053     else
0054     {
0055 
0056         QStyledItemDelegate::paint( painter, option, index );
0057     }
0058 }
0059 
0060 
0061 #include "moc_kdfitemdelegate.cpp"