Applets
itemdelegate.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "ui/itemdelegate.h"
00023
00024
00025 #include <QApplication>
00026 #include <QFontMetrics>
00027 #include <QIcon>
00028 #include <QModelIndex>
00029 #include <QPainter>
00030 #include <QStyle>
00031 #include <QStyleOptionViewItem>
00032 #include <QStyleOptionProgressBar>
00033
00034
00035 #include <KColorUtils>
00036 #include <KDebug>
00037 #include <KGlobal>
00038 #include <KGlobalSettings>
00039 #include <kcapacitybar.h>
00040
00041
00042 #include <Plasma/Plasma>
00043
00044 using namespace Kickoff;
00045
00046 ItemDelegate::ItemDelegate(QObject *parent)
00047 : Plasma::Delegate(parent)
00048 {
00049 }
00050
00051 void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
00052 {
00053 Plasma::Delegate::paint(painter, option, index);
00054
00055 qreal freeSpace = -1;
00056 qreal usedSpace = -1;
00057 if (!index.data(DiskFreeSpaceRole).isNull()) {
00058 freeSpace = index.data(DiskFreeSpaceRole).value<int>() / 1024.0 / 1024.0;
00059 usedSpace = index.data(DiskUsedSpaceRole).value<int>() / 1024.0 / 1024.0;
00060 }
00061
00062
00063
00064 if (usedSpace >= 0) {
00065 painter->save();
00066
00067 QRect emptyRect = rectAfterTitle(option, index);
00068
00069 QSize barSize = QSize(qMin(emptyRect.width(), option.rect.width() / 3), emptyRect.height());
00070
00071 if (barSize.width() > 0) {
00072
00073
00074 if (barSize.width() < 20.0) {
00075 painter->setOpacity(barSize.width() / 20.0);
00076 }
00077
00078 QRect spaceRect = QStyle::alignedRect(option.direction,
00079 Qt::AlignRight, barSize, emptyRect);
00080
00081 if (!(option.state & (QStyle::State_Selected | QStyle::State_MouseOver | QStyle::State_HasFocus))) {
00082 painter->setOpacity(painter->opacity() / 2.5);
00083 } else {
00084 }
00085
00086 KCapacityBar capacityBar(KCapacityBar::DrawTextInline);
00087 capacityBar.setValue((usedSpace / (freeSpace + usedSpace))*100);
00088 capacityBar.drawCapacityBar(painter, spaceRect);
00089
00090
00091
00092
00093
00094
00095
00096 }
00097
00098 painter->restore();
00099 }
00100
00101 }
00102
00103 bool ItemDelegate::isVisible(const QModelIndex& index) const
00104 {
00105 Q_ASSERT(index.isValid());
00106
00107 if (index.model()->hasChildren(index)) {
00108 int childCount = index.model()->rowCount(index);
00109 for (int i = 0; i < childCount; ++i) {
00110 QModelIndex child = index.model()->index(i, 0, index);
00111 if (!child.data(UrlRole).isNull()) {
00112 return true;
00113 }
00114 }
00115 return false;
00116 }
00117
00118 return !index.data(UrlRole).isNull();
00119 }
00120