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
00040
00041 #include <plasma/plasma.h>
00042
00043 using namespace Kickoff;
00044
00045 ItemDelegate::ItemDelegate(QObject *parent)
00046 : Plasma::Delegate(parent)
00047 {
00048 }
00049
00050 void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
00051 {
00052 Plasma::Delegate::paint(painter, option, index);
00053
00054 qreal freeSpace = -1;
00055 qreal usedSpace = -1;
00056 if (!index.data(DiskFreeSpaceRole).isNull()) {
00057 freeSpace = index.data(DiskFreeSpaceRole).value<int>()/1024.0/1024.0;
00058 usedSpace = index.data(DiskUsedSpaceRole).value<int>()/1024.0/1024.0;
00059 }
00060
00061
00062
00063 if (usedSpace >= 0) {
00064 painter->save();
00065
00066 QRect emptyRect = rectAfterTitle(option, index);
00067
00068 QSize barSize = QSize(qMin(emptyRect.width(), option.rect.width()/3), emptyRect.height());
00069
00070 if (barSize.width() > 0) {
00071
00072
00073 if (barSize.width() < 20.0) {
00074 painter->setOpacity(barSize.width()/20.0);
00075 }
00076
00077 QRectF spaceRect = QStyle::alignedRect(option.direction,
00078 Qt::AlignRight, barSize, emptyRect);
00079
00080 QStyleOptionProgressBar optionPBar;
00081
00082 if (!(option.state & (QStyle::State_Selected|QStyle::State_MouseOver|QStyle::State_HasFocus))) {
00083 painter->setOpacity(painter->opacity()/2.5);
00084 optionPBar.state = QStyle::State_None;
00085 } else {
00086 optionPBar.state = QStyle::State_Enabled;
00087 }
00088
00089 optionPBar.rect = spaceRect.toRect();
00090 optionPBar.minimum = 0;
00091 optionPBar.maximum = 100;
00092 optionPBar.progress = (usedSpace / (freeSpace + usedSpace))*100;
00093
00094 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &optionPBar, painter);
00095
00096
00097
00098
00099
00100
00101
00102 }
00103
00104 painter->restore();
00105 }
00106
00107 }
00108
00109 bool ItemDelegate::isVisible(const QModelIndex& index) const
00110 {
00111 Q_ASSERT(index.isValid());
00112
00113 if (index.model()->hasChildren(index)) {
00114 int childCount = index.model()->rowCount(index);
00115 for (int i=0; i<childCount; ++i) {
00116 QModelIndex child = index.model()->index(i, 0, index);
00117 if (!child.data(UrlRole).isNull()) {
00118 return true;
00119 }
00120 }
00121 return false;
00122 }
00123
00124 return !index.data(UrlRole).isNull();
00125 }
00126