• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kdf

  • sources
  • kde-4.14
  • kdeutils
  • kdf
kdfitemdelegate.cpp
Go to the documentation of this file.
1 /*
2 * kdfitemdelegate.cpp
3 *
4 * Copyright (c) 2009 Dario Andres Rodriguez <andresbajotierra@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
21 #include "kdfitemdelegate.h"
22 
23 #include <QtGui/QStyleOptionViewItem>
24 #include <QtGui/QPainter>
25 
26 #include <klocale.h>
27 #include <kcapacitybar.h>
28 
29 #include <QPalette>
30 #include <QBrush>
31 
32 #include "kdfwidget.h"
33 #include "kdfutil.h"
34 
35 void KDFItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
36  const QModelIndex &index) const
37 {
38  if ( index.column() == KDFWidget::UsageBarCol )
39  {
40 
41  int progress = index.data( Qt::UserRole ).toInt();
42 
43  if( progress!=-1 )
44  {
45  KCapacityBar bar;
46  bar.setBarHeight( option.rect.height() -2 );
47  bar.setValue( progress );
48  bar.setText( QString::number( progress ) + QLatin1Char( '%' ) );
49  //Draw red bar on >=Full_Percent
50  if ( progress >= Full_Percent )
51  {
52  QPalette p ( bar.palette() );
53  p.setBrush( QPalette::Highlight, QBrush( Qt::red ) );
54  bar.setPalette( p );
55  }
56 
57  if (option.state & QStyle::State_Selected || option.state & QStyle::State_MouseOver)
58  QStyledItemDelegate::paint( painter, option, index );
59 
60  QRect rect(option.rect);
61  bar.drawCapacityBar( painter, rect.adjusted( 0, 0, -2, -1 ) );
62  }
63  else
64  {
65  QStyledItemDelegate::paint( painter, option, index );
66  }
67 
68  }
69  else
70  {
71 
72  QStyledItemDelegate::paint( painter, option, index );
73  }
74 }
75 
QPalette::setBrush
void setBrush(ColorRole role, const QBrush &brush)
QModelIndex
kdfutil.h
QBrush
QRect
kdfwidget.h
QString::number
QString number(int n, int base)
QVariant::toInt
int toInt(bool *ok) const
QStyleOptionViewItem
QStyledItemDelegate::paint
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
QPainter
QRect::adjusted
QRect adjusted(int dx1, int dy1, int dx2, int dy2) const
kdfitemdelegate.h
QLatin1Char
Full_Percent
static const float Full_Percent
Definition: kdfutil.h:24
QModelIndex::data
QVariant data(int role) const
KDFWidget::UsageBarCol
Definition: kdfwidget.h:78
QModelIndex::column
int column() const
KDFItemDelegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: kdfitemdelegate.cpp:35
QPalette
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:23 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdf

Skip menu "kdf"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal