Fix some issues spotted by David Faure.
In particular, add a check for partition capacity to be positive.
This commit is contained in:
parent
a2a9bb8301
commit
cacdb7b634
|
@ -93,21 +93,22 @@ void PartWidget::paintEvent(QPaintEvent*)
|
||||||
if (partition() == nullptr)
|
if (partition() == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int usedPercentage = static_cast<int>(partition()->used() * 100 / partition()->capacity());
|
auto partitionCapacity = partition()->capacity();
|
||||||
|
if (partitionCapacity <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const int usedPercentage = static_cast<int>(partition()->used() * 100 / partitionCapacity);
|
||||||
const int w = width() * usedPercentage / 100;
|
const int w = width() * usedPercentage / 100;
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHints(QPainter::Antialiasing);
|
painter.setRenderHints(QPainter::Antialiasing);
|
||||||
|
|
||||||
|
const QColor base = activeColor(m_fileSystemColorCode[ static_cast<int>(partition()->fileSystem().type()) ]);
|
||||||
if (partition()->roles().has(PartitionRole::Extended)) {
|
if (partition()->roles().has(PartitionRole::Extended)) {
|
||||||
drawGradient(&painter, activeColor(
|
drawGradient(&painter, base, QRect(0, 0, width(), height()));
|
||||||
m_fileSystemColorCode[ static_cast<int>(partition()->fileSystem().type()) ]),
|
|
||||||
QRect(0, 0, width(), height()));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QColor base = activeColor(m_fileSystemColorCode[ static_cast<int>(partition()->fileSystem().type()) ]);
|
|
||||||
|
|
||||||
if (!partition()->roles().has(PartitionRole::Unallocated)) {
|
if (!partition()->roles().has(PartitionRole::Unallocated)) {
|
||||||
const QColor dark = base.darker(105);
|
const QColor dark = base.darker(105);
|
||||||
const QColor light = base.lighter(120);
|
const QColor light = base.lighter(120);
|
||||||
|
@ -124,11 +125,11 @@ void PartWidget::paintEvent(QPaintEvent*)
|
||||||
QString text = partition()->deviceNode().remove(QStringLiteral("/dev/")) + QStringLiteral("\n") + QString(Capacity::formatByteSize(partition()->capacity()));
|
QString text = partition()->deviceNode().remove(QStringLiteral("/dev/")) + QStringLiteral("\n") + QString(Capacity::formatByteSize(partition()->capacity()));
|
||||||
|
|
||||||
const QRect textRect(0, 0, width() - 1, height() - 1);
|
const QRect textRect(0, 0, width() - 1, height() - 1);
|
||||||
const QRect boundingRect = painter.boundingRect(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text);
|
const QRect boundingRect = painter.boundingRect(textRect, Qt::AlignCenter, text);
|
||||||
if (boundingRect.x() > PartWidgetBase::borderWidth() && boundingRect.y() > PartWidgetBase::borderHeight()) {
|
if (boundingRect.x() > PartWidgetBase::borderWidth() && boundingRect.y() > PartWidgetBase::borderHeight()) {
|
||||||
if (isActive())
|
if (isActive())
|
||||||
painter.setPen(QColor(255, 255, 255));
|
painter.setPen(Qt::white);
|
||||||
painter.drawText(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text);
|
painter.drawText(textRect, Qt::AlignCenter, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue