]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/places/placesitemlistwidget.cpp
52b3baf309063857a7e75b1e8017407e998e11e4
2 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "placesitemlistwidget.h"
9 #include <QGraphicsView>
10 #include <QStyleOption>
12 #include <KDiskFreeSpaceInfo>
13 #include <KMountPoint>
15 #define CAPACITYBAR_HEIGHT 2
16 #define CAPACITYBAR_MARGIN 2
19 PlacesItemListWidget::PlacesItemListWidget(KItemListWidgetInformant
* informant
, QGraphicsItem
* parent
) :
20 KStandardItemListWidget(informant
, parent
)
24 PlacesItemListWidget::~PlacesItemListWidget()
28 bool PlacesItemListWidget::isHidden() const
30 return data().value("isHidden").toBool() ||
31 data().value("isGroupHidden").toBool();
34 QPalette::ColorRole
PlacesItemListWidget::normalTextColorRole() const
36 return QPalette::WindowText
;
39 void PlacesItemListWidget::paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
)
41 KStandardItemListWidget::paint(painter
, option
, widget
);
43 bool drawCapacityBar
= false;
44 const QUrl url
= data().value("url").toUrl();
45 if (url
.isLocalFile()) {
46 const QString mountPointPath
= url
.toLocalFile();
47 KMountPoint::Ptr mp
= KMountPoint::currentMountPoints().findByPath(mountPointPath
);
48 bool isMountPoint
= (mp
&& mp
->mountPoint() == mountPointPath
);
51 const KDiskFreeSpaceInfo info
= KDiskFreeSpaceInfo::freeSpaceInfo(mountPointPath
);
52 drawCapacityBar
= info
.size() != 0;
53 if (drawCapacityBar
) {
54 const TextInfo
* textInfo
= m_textInfo
.value("text");
55 if (textInfo
) { // See KStandarItemListWidget::paint() for info on why we check textInfo.
60 option
->rect
.top() + option
->rect
.height() - CAPACITYBAR_HEIGHT
- CAPACITYBAR_MARGIN
,
61 qMin((qreal
)option
->rect
.width(), selectionRect().width()) - (textInfo
->pos
.x() - option
->rect
.left()),
65 const qreal ratio
= (qreal
)info
.used() / (qreal
)info
.size();
66 // qDebug() << "ratio:" << ratio << "(" << info.used() << "/" << info.size() << ")";
68 const QPalette pal
= palette();
69 const QPalette::ColorGroup group
= isActiveWindow() ? QPalette::Active
: QPalette::Inactive
;
70 // QColor bgColor = QColor::fromRgb(230, 230, 230);
71 // QColor outlineColor = QColor::fromRgb(208, 208, 208);
72 // QColor bgColor = QColor::fromRgb(0, 230, 0);
73 // QColor outlineColor = QColor::fromRgb(208, 0, 0, 127);
74 // QColor normalUsedColor = QColor::fromRgb(38, 160, 218);
75 // QColor dangerUsedColor = QColor::fromRgb(218, 38, 38);
76 // QColor bgColor = pal.base().color().darker(130);
77 // QColor outlineColor = pal.base().color().darker(150);
79 QPalette::ColorRole role
;
80 // role = isSelected() ? QPalette::Highlight : QPalette::Window;
81 // QColor bgColor = styleOption().palette.color(group, role).darker(150);
82 // QColor outlineColor = styleOption().palette.color(group, role).darker(170);
83 QColor bgColor
= isSelected()
84 ? styleOption().palette
.color(group
, QPalette::Highlight
).darker(180)
85 : styleOption().palette
.color(group
, QPalette::Window
).darker(120);
87 role
= isSelected() ? QPalette::HighlightedText
: QPalette::Highlight
;
88 QColor normalUsedColor
= styleOption().palette
.color(group
, role
);
90 QColor dangerUsedColor
= QColor::fromRgb(218, 38, 38);
93 painter
->fillRect(capacityRect
, bgColor
);
96 // const QRect outlineRect(capacityRect.x(), capacityRect.y(), capacityRect.width() - 1, capacityRect.height() - 1);
97 // painter->setPen(outlineColor);
98 // painter->drawRect(outlineRect);
101 const QRect
fillRect(capacityRect
.x(), capacityRect
.y(), capacityRect
.width() * ratio
, capacityRect
.height());
102 if (ratio
< 0.95) { // Fill
103 painter
->fillRect(fillRect
, normalUsedColor
);
105 painter
->fillRect(fillRect
, dangerUsedColor
);