Changeset View
Changeset View
Standalone View
Standalone View
src/panels/places/placesitemlistwidget.cpp
Context not available. | |||||
19 | 19 | | |||
---|---|---|---|---|---|
20 | #include "placesitemlistwidget.h" | 20 | #include "placesitemlistwidget.h" | ||
21 | 21 | | |||
22 | #include <QGraphicsView> | ||||
23 | #include <QStyleOption> | ||||
24 | | ||||
25 | #include <KDiskFreeSpaceInfo> | ||||
26 | #include <KMountPoint> | ||||
27 | | ||||
28 | #define CAPACITYBAR_HEIGHT 2 | ||||
29 | #define CAPACITYBAR_MARGIN 2 | ||||
30 | | ||||
22 | PlacesItemListWidget::PlacesItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) : | 31 | PlacesItemListWidget::PlacesItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) : | ||
23 | KStandardItemListWidget(informant, parent) | 32 | KStandardItemListWidget(informant, parent) | ||
24 | { | 33 | { | ||
Context not available. | |||||
39 | return QPalette::WindowText; | 48 | return QPalette::WindowText; | ||
40 | } | 49 | } | ||
41 | 50 | | |||
51 | void PlacesItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) | ||||
52 | { | ||||
53 | KStandardItemListWidget::paint(painter, option, widget); | ||||
54 | | ||||
55 | bool drawCapacityBar = false; | ||||
56 | const QUrl url = data().value("url").toUrl(); | ||||
57 | if (url.isLocalFile()) { | ||||
58 | const QString mountPointPath = url.toLocalFile(); | ||||
59 | KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(mountPointPath); | ||||
60 | bool isMountPoint = (mp && mp->mountPoint() == mountPointPath); | ||||
61 | | ||||
62 | if (isMountPoint) { | ||||
63 | const KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(mountPointPath); | ||||
64 | drawCapacityBar = info.size() != 0; | ||||
65 | if (drawCapacityBar) { | ||||
66 | const TextInfo* textInfo = m_textInfo.value("text"); | ||||
67 | if (textInfo) { // See KStandarItemListWidget::paint() for info on why we check if textInfo is null. | ||||
68 | painter->save(); | ||||
69 | | ||||
70 | QRect capacityRect( | ||||
71 | textInfo->pos.x(), | ||||
72 | option->rect.top() + option->rect.height() - CAPACITYBAR_HEIGHT - CAPACITYBAR_MARGIN, | ||||
73 | qMin((qreal)option->rect.width(), selectionRect().width()) - (textInfo->pos.x() - option->rect.left()), | ||||
74 | CAPACITYBAR_HEIGHT | ||||
75 | ); | ||||
76 | | ||||
77 | const qreal ratio = (qreal)info.used() / (qreal)info.size(); | ||||
78 | | ||||
79 | const QPalette pal = styleOption().palette; | ||||
80 | const QPalette::ColorGroup group = isActiveWindow() ? QPalette::Active : QPalette::Inactive; | ||||
81 | | ||||
82 | // Background | ||||
83 | const QColor bgColor = isSelected() | ||||
84 | ? pal.color(group, QPalette::Highlight).darker(180) | ||||
85 | : pal.color(group, QPalette::Window).darker(120); | ||||
86 | | ||||
87 | painter->fillRect(capacityRect, bgColor); | ||||
88 | | ||||
89 | | ||||
90 | // Fill | ||||
91 | const QRect fillRect(capacityRect.x(), capacityRect.y(), capacityRect.width() * ratio, capacityRect.height()); | ||||
92 | if (ratio >= 0.95) { // More than 95% full! | ||||
93 | const QColor dangerUsedColor = QColor::fromRgb(218, 38, 38); | ||||
94 | painter->fillRect(fillRect, dangerUsedColor); | ||||
95 | } else { | ||||
96 | const QPalette::ColorRole role = isSelected() ? QPalette::HighlightedText : QPalette::Highlight; | ||||
97 | const QColor normalUsedColor = pal.color(group, role); | ||||
98 | painter->fillRect(fillRect, normalUsedColor); | ||||
99 | } | ||||
100 | | ||||
101 | painter->restore(); | ||||
102 | } | ||||
103 | } | ||||
104 | } | ||||
105 | } | ||||
106 | } | ||||
Context not available. |