Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions application/widgets/customcontrol/sizeinfowidget.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-only

Expand Down Expand Up @@ -53,13 +53,15 @@ void SizeInfoWidget::setData(PartitionInfo info, QVector<QColor> color, QVector<
m_used = Utils::sectorToUnit(info.m_sectorsUsed, info.m_sectorSize, SIZE_UNIT::UNIT_GIB);
m_totalSpaceSize = Utils::formatSize(info.m_sectorEnd - info.m_sectorStart + 1, info.m_sectorSize);
m_usedSize = Utils::formatSize(info.m_sectorsUsed, info.m_sectorSize);
m_availableSize = Utils::formatSize(info.m_sectorsUnused, info.m_sectorSize);

if (info.m_luksFlag == LUKSFlag::IS_CRYPT_LUKS) {
qDebug() << "Partition is LUKS encrypted.";
LUKS_INFO luksInfo = DMDbusHandler::instance()->probLUKSInfo().m_luksMap.value(info.m_path);
if (luksInfo.isDecrypt) {
qDebug() << "LUKS partition is decrypted, updating used/unused size.";
m_usedSize = Utils::LVMFormatSize(luksInfo.m_mapper.m_fsUsed);
m_availableSize = Utils::LVMFormatSize(luksInfo.m_mapper.m_fsUnused);
m_noused = Utils::LVMSizeToUnit(luksInfo.m_mapper.m_fsUnused, SIZE_UNIT::UNIT_GIB);
m_used = Utils::LVMSizeToUnit(luksInfo.m_mapper.m_fsUsed, SIZE_UNIT::UNIT_GIB);
}
Expand Down Expand Up @@ -97,6 +99,7 @@ void SizeInfoWidget::setData(LVInfo info, QVector<QColor> color, QVector<double>
m_used = Utils::LVMSizeToUnit(info.m_fsUsed, SIZE_UNIT::UNIT_GIB);
m_noused = Utils::LVMSizeToUnit(info.m_fsUnused, SIZE_UNIT::UNIT_GIB);
m_usedSize = Utils::LVMFormatSize(info.m_fsUsed);
m_availableSize = Utils::LVMFormatSize(info.m_fsUnused);

if (info.m_luksFlag == LUKSFlag::IS_CRYPT_LUKS) {
qDebug() << "LV is LUKS encrypted.";
Expand All @@ -105,10 +108,12 @@ void SizeInfoWidget::setData(LVInfo info, QVector<QColor> color, QVector<double>
qDebug() << "LUKS LV is decrypted, updating used/unused size.";
m_usedSize = Utils::LVMFormatSize(luksInfo.m_mapper.m_fsUsed);
m_noused = Utils::LVMSizeToUnit(luksInfo.m_mapper.m_fsUnused, SIZE_UNIT::UNIT_GIB);
m_availableSize = Utils::LVMFormatSize(luksInfo.m_mapper.m_fsUnused);
m_used = Utils::LVMSizeToUnit(luksInfo.m_mapper.m_fsUsed, SIZE_UNIT::UNIT_GIB);
} else {
qDebug() << "LUKS LV is not decrypted, setting used size to '-'.";
m_usedSize = "-";
m_availableSize = "-";
}
}

Expand Down Expand Up @@ -147,13 +152,15 @@ void SizeInfoWidget::setData(DeviceInfo info, QVector<QColor> color, QVector<dou
m_used = 0.00;
m_noused = Utils::LVMSizeToUnit(info.m_length * info.m_sectorSize, SIZE_UNIT::UNIT_GIB);
m_usedSize = Utils::LVMFormatSize(-1 * info.m_sectorSize);
m_availableSize = Utils::LVMFormatSize(-1 * info.m_sectorSize);

if (info.m_luksFlag == LUKSFlag::IS_CRYPT_LUKS && info.m_partition.size() == 0) {
qDebug() << "Device is LUKS encrypted and has no partitions.";
LUKS_INFO luksInfo = DMDbusHandler::instance()->probLUKSInfo().m_luksMap.value(info.m_path);
if (luksInfo.isDecrypt) {
qDebug() << "LUKS device is decrypted, updating used/unused size.";
m_usedSize = Utils::LVMFormatSize(luksInfo.m_mapper.m_fsUsed);
m_availableSize = Utils::LVMFormatSize(luksInfo.m_mapper.m_fsUnused);
m_noused = Utils::LVMSizeToUnit(luksInfo.m_mapper.m_fsUnused, SIZE_UNIT::UNIT_GIB);
m_used = Utils::LVMSizeToUnit(luksInfo.m_mapper.m_fsUsed, SIZE_UNIT::UNIT_GIB);
}
Expand Down Expand Up @@ -284,6 +291,8 @@ void SizeInfoWidget::paintEvent(QPaintEvent *event)
// qDebug() << "Flag is true, drawing information labels.";
DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType();
// qDebug() << "Theme type for info labels:" << themeType;
if (m_availableSize.contains("-"))
m_availableSize = "-";
if (themeType == DGuiApplicationHelper::LightType) {
// qDebug() << "Theme is LightType for info labels.";
int height = 90 - static_cast<int>((QApplication::font().pointSizeF() / 0.75 - 14) * 1);
Expand Down Expand Up @@ -314,7 +323,7 @@ void SizeInfoWidget::paintEvent(QPaintEvent *event)
option.setAlignment(Qt::AlignTop);

QFontMetrics fmCapacity = painter.fontMetrics();
QString textCapacity = QString(m_partitionPath + tr(" Capacity:") + " ");
QString textCapacity = tr(" Available: ");
#if QT_VERSION_MAJOR > 5
int capacityWidth = fmCapacity.boundingRect(textCapacity).width();
#else
Expand All @@ -332,7 +341,7 @@ void SizeInfoWidget::paintEvent(QPaintEvent *event)
QRect rectText = QRect(paintRect.bottomLeft().x() + 28, paintRect.bottomLeft().y() + 17, capacityWidth, 70);
painter.drawText(rectText, textCapacity, option);
// qDebug() << "Drew capacity text.";
// 获取总容量字符串显示的宽度
// 获取可用空间字符串显示的宽度
int capacityNum = rectText.x() + capacityWidth;

font = DFontSizeManager::instance()->get(DFontSizeManager::T8);
Expand All @@ -342,9 +351,9 @@ void SizeInfoWidget::paintEvent(QPaintEvent *event)
QTextOption option1;
option.setAlignment(Qt::AlignLeft);
#if QT_VERSION_MAJOR > 5
QRect rectSizeNum = QRect(paintRect.bottomLeft().x() + capacityNum, paintRect.bottomLeft().y() + 20, painter.fontMetrics().boundingRect(m_totalSpaceSize).width() + 20, 30);
QRect rectSizeNum = QRect(paintRect.bottomLeft().x() + capacityNum, paintRect.bottomLeft().y() + 20, painter.fontMetrics().boundingRect(m_availableSize).width() + 20, 30);
#else
QRect rectSizeNum = QRect(paintRect.bottomLeft().x() + capacityNum, paintRect.bottomLeft().y() + 20, painter.fontMetrics().width(m_totalSpaceSize) + 20, 30);
QRect rectSizeNum = QRect(paintRect.bottomLeft().x() + capacityNum, paintRect.bottomLeft().y() + 20, painter.fontMetrics().width(m_availableSize) + 20, 30);
#endif

int height2 = 21 + static_cast<int>((QApplication::font().pointSizeF() / 0.75 - 14) * 1);
Expand Down Expand Up @@ -390,7 +399,7 @@ void SizeInfoWidget::paintEvent(QPaintEvent *event)
painter.setFont(font);
painter.setPen(text1Color);
option.setAlignment(Qt::AlignLeft);
painter.drawText(rectSizeNum, m_totalSpaceSize, option1);
painter.drawText(rectSizeNum, m_availableSize, option1);
// qDebug() << "Drew total space size for LightType.";

rectSizeNum.moveTo(paintRect.bottomLeft().x() + usedNum, paintRect.bottomLeft().y() + 20);
Expand Down Expand Up @@ -430,7 +439,7 @@ void SizeInfoWidget::paintEvent(QPaintEvent *event)
option.setAlignment(Qt::AlignTop);

QFontMetrics fmCapacity = painter.fontMetrics();
QString textCapacity = QString(m_partitionPath + tr(" Capacity:") + " ");
QString textCapacity = tr(" Available: ");
#if QT_VERSION_MAJOR > 5
int capacityWidth = fmCapacity.boundingRect(textCapacity).width();
#else
Expand All @@ -448,7 +457,7 @@ void SizeInfoWidget::paintEvent(QPaintEvent *event)
QRect rectText = QRect(paintRect.bottomLeft().x() + 28, paintRect.bottomLeft().y() + 17, capacityWidth, 70);
painter.drawText(rectText, textCapacity, option);
// qDebug() << "Drew capacity text for DarkType.";
// 获取总容量字符串显示的宽度
// 获取可用空间字符串显示的宽度
int capacityNum = rectText.x() + capacityWidth;

font = DFontSizeManager::instance()->get(DFontSizeManager::T8);
Expand All @@ -458,9 +467,9 @@ void SizeInfoWidget::paintEvent(QPaintEvent *event)
QTextOption option1;
option.setAlignment(Qt::AlignLeft);
#if QT_VERSION_MAJOR > 5
QRect rectSizeNum = QRect(paintRect.bottomLeft().x() + capacityNum, paintRect.bottomLeft().y() + 20, painter.fontMetrics().boundingRect(m_totalSpaceSize).width() + 20, 30);
QRect rectSizeNum = QRect(paintRect.bottomLeft().x() + capacityNum, paintRect.bottomLeft().y() + 20, painter.fontMetrics().boundingRect(m_availableSize).width() + 20, 30);
#else
QRect rectSizeNum = QRect(paintRect.bottomLeft().x() + capacityNum, paintRect.bottomLeft().y() + 20, painter.fontMetrics().width(m_totalSpaceSize) + 20, 30);
QRect rectSizeNum = QRect(paintRect.bottomLeft().x() + capacityNum, paintRect.bottomLeft().y() + 20, painter.fontMetrics().width(m_availableSize) + 20, 30);
#endif

int height2 = 21 + static_cast<int>((QApplication::font().pointSizeF() / 0.75 - 14) * 1);
Expand Down Expand Up @@ -505,7 +514,7 @@ void SizeInfoWidget::paintEvent(QPaintEvent *event)
painter.setFont(font);
painter.setPen(text1Color);
option.setAlignment(Qt::AlignLeft);
painter.drawText(rectSizeNum, m_totalSpaceSize, option1);
painter.drawText(rectSizeNum, m_availableSize, option1);
// qDebug() << "Drew total space size for DarkType.";

rectSizeNum.moveTo(paintRect.bottomLeft().x() + usedNum, paintRect.bottomLeft().y() + 20);
Expand Down
3 changes: 2 additions & 1 deletion application/widgets/customcontrol/sizeinfowidget.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-only

Expand Down Expand Up @@ -99,6 +99,7 @@ private slots:
DPalette m_parentPb;
QString m_totalSpaceSize;
QString m_usedSize;
QString m_availableSize;
QString m_partitionPath;
};

Expand Down
Loading