mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-28 03:21:56 +00:00
Only check if place url is mount point once during polish event.
The capacity bars will no longer update when capacity changes. It only checks the size on init. Updating during polish event is only a temporarily solution just to draft code flow for seperating logic from painting. Eventually this logic update should be in a worker thread detached from blocking the rendering thread that blocks launching the dolphin window.
This commit is contained in:
parent
ac6de72048
commit
e75326077b
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "placesitemlistwidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QStyleOption>
|
||||
|
||||
|
@ -18,6 +20,9 @@
|
|||
|
||||
PlacesItemListWidget::PlacesItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) :
|
||||
KStandardItemListWidget(informant, parent)
|
||||
, m_isMountPoint(false)
|
||||
, m_drawCapacityBar(false)
|
||||
, m_capacityBarRatio(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -36,21 +41,49 @@ QPalette::ColorRole PlacesItemListWidget::normalTextColorRole() const
|
|||
return QPalette::WindowText;
|
||||
}
|
||||
|
||||
void PlacesItemListWidget::updateCapacityBar()
|
||||
{
|
||||
const QUrl url = data().value("url").toUrl();
|
||||
if (url.isLocalFile()) {
|
||||
const QString mountPointPath = url.toLocalFile();
|
||||
qDebug() << "url:" << mountPointPath;
|
||||
KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(mountPointPath);
|
||||
m_isMountPoint = (mp && mp->mountPoint() == mountPointPath);
|
||||
qDebug() << " isMountPoint:" << m_isMountPoint;
|
||||
if (m_isMountPoint) {
|
||||
const KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(mountPointPath);
|
||||
m_drawCapacityBar = info.size() != 0;
|
||||
m_capacityBarRatio = (qreal)info.used() / (qreal)info.size();
|
||||
qDebug() << " capacityBarRatio:" << m_capacityBarRatio << "(" << info.used() << "/" << info.size() << ")";
|
||||
|
||||
// update();
|
||||
} else {
|
||||
resetCapacityBar();
|
||||
}
|
||||
} else {
|
||||
resetCapacityBar();
|
||||
}
|
||||
}
|
||||
|
||||
void PlacesItemListWidget::resetCapacityBar()
|
||||
{
|
||||
m_isMountPoint = false;
|
||||
m_drawCapacityBar = false;
|
||||
m_capacityBarRatio = 0;
|
||||
}
|
||||
|
||||
void PlacesItemListWidget::polishEvent()
|
||||
{
|
||||
updateCapacityBar();
|
||||
|
||||
QGraphicsWidget::polishEvent();
|
||||
}
|
||||
|
||||
void PlacesItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
{
|
||||
KStandardItemListWidget::paint(painter, option, widget);
|
||||
|
||||
bool drawCapacityBar = false;
|
||||
const QUrl url = data().value("url").toUrl();
|
||||
if (url.isLocalFile()) {
|
||||
const QString mountPointPath = url.toLocalFile();
|
||||
KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(mountPointPath);
|
||||
bool isMountPoint = (mp && mp->mountPoint() == mountPointPath);
|
||||
|
||||
if (isMountPoint) {
|
||||
const KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(mountPointPath);
|
||||
drawCapacityBar = info.size() != 0;
|
||||
if (drawCapacityBar) {
|
||||
if (m_drawCapacityBar) {
|
||||
const TextInfo* textInfo = m_textInfo.value("text");
|
||||
if (textInfo) { // See KStandarItemListWidget::paint() for info on why we check textInfo.
|
||||
painter->save();
|
||||
|
@ -62,9 +95,6 @@ void PlacesItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIt
|
|||
CAPACITYBAR_HEIGHT
|
||||
);
|
||||
|
||||
const qreal ratio = (qreal)info.used() / (qreal)info.size();
|
||||
// qDebug() << "ratio:" << ratio << "(" << info.used() << "/" << info.size() << ")";
|
||||
|
||||
const QPalette pal = palette();
|
||||
const QPalette::ColorGroup group = isActiveWindow() ? QPalette::Active : QPalette::Inactive;
|
||||
// QColor bgColor = QColor::fromRgb(230, 230, 230);
|
||||
|
@ -98,8 +128,8 @@ void PlacesItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIt
|
|||
// painter->drawRect(outlineRect);
|
||||
|
||||
// Fill
|
||||
const QRect fillRect(capacityRect.x(), capacityRect.y(), capacityRect.width() * ratio, capacityRect.height());
|
||||
if (ratio < 0.95) { // Fill
|
||||
const QRect fillRect(capacityRect.x(), capacityRect.y(), capacityRect.width() * m_capacityBarRatio, capacityRect.height());
|
||||
if (m_capacityBarRatio < 0.95) { // Fill
|
||||
painter->fillRect(fillRect, normalUsedColor);
|
||||
} else {
|
||||
painter->fillRect(fillRect, dangerUsedColor);
|
||||
|
@ -108,6 +138,4 @@ void PlacesItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIt
|
|||
painter->restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,18 @@ public:
|
|||
~PlacesItemListWidget() override;
|
||||
|
||||
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
|
||||
void polishEvent() override;
|
||||
|
||||
protected:
|
||||
bool isHidden() const override;
|
||||
QPalette::ColorRole normalTextColorRole() const override;
|
||||
void updateCapacityBar();
|
||||
void resetCapacityBar();
|
||||
|
||||
private:
|
||||
bool m_isMountPoint;
|
||||
bool m_drawCapacityBar;
|
||||
qreal m_capacityBarRatio;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue