Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/kstandarditemlistwidget.cpp
Context not available. | |||||
42 | #include <QPixmapCache> | 42 | #include <QPixmapCache> | ||
---|---|---|---|---|---|
43 | #include <QGuiApplication> | 43 | #include <QGuiApplication> | ||
44 | 44 | | |||
45 | #include "spaceinfoobserver.h" | ||||
46 | #include <KMountPoint> | ||||
47 | | ||||
45 | // #define KSTANDARDITEMLISTWIDGET_DEBUG | 48 | // #define KSTANDARDITEMLISTWIDGET_DEBUG | ||
46 | 49 | | |||
47 | KStandardItemListWidgetInformant::KStandardItemListWidgetInformant() : | 50 | KStandardItemListWidgetInformant::KStandardItemListWidgetInformant() : | ||
Context not available. | |||||
273 | m_additionalInfoTextColor(), | 276 | m_additionalInfoTextColor(), | ||
274 | m_overlay(), | 277 | m_overlay(), | ||
275 | m_rating(), | 278 | m_rating(), | ||
279 | m_isMountPoint(false), | ||||
280 | m_spaceInfoObserver(0), | ||||
281 | m_progressBar(), | ||||
276 | m_roleEditor(nullptr), | 282 | m_roleEditor(nullptr), | ||
277 | m_oldRoleEditor(nullptr) | 283 | m_oldRoleEditor(nullptr) | ||
278 | { | 284 | { | ||
Context not available. | |||||
290 | if (m_oldRoleEditor) { | 296 | if (m_oldRoleEditor) { | ||
291 | m_oldRoleEditor->deleteLater(); | 297 | m_oldRoleEditor->deleteLater(); | ||
292 | } | 298 | } | ||
299 | | ||||
300 | if (m_spaceInfoObserver) { | ||||
301 | m_spaceInfoObserver->deleteLater(); | ||||
302 | } | ||||
293 | } | 303 | } | ||
294 | 304 | | |||
295 | void KStandardItemListWidget::setLayout(Layout layout) | 305 | void KStandardItemListWidget::setLayout(Layout layout) | ||
Context not available. | |||||
411 | painter->setFont(m_customizedFont); | 421 | painter->setFont(m_customizedFont); | ||
412 | 422 | | |||
413 | for (int i = 1; i < m_sortedVisibleRoles.count(); ++i) { | 423 | for (int i = 1; i < m_sortedVisibleRoles.count(); ++i) { | ||
414 | const TextInfo* textInfo = m_textInfo.value(m_sortedVisibleRoles[i]); | 424 | const QByteArray role = m_sortedVisibleRoles[i]; | ||
415 | painter->drawStaticText(textInfo->pos, textInfo->staticText); | 425 | if (role == "size" && !m_progressBar.isNull()) { | ||
426 | // skip | ||||
427 | } else { | ||||
428 | const TextInfo* textInfo = m_textInfo.value(role); | ||||
429 | painter->drawStaticText(textInfo->pos, textInfo->staticText); | ||||
430 | } | ||||
416 | } | 431 | } | ||
417 | 432 | | |||
418 | if (!m_rating.isNull()) { | 433 | if (!m_rating.isNull()) { | ||
Context not available. | |||||
425 | painter->drawPixmap(pos, m_rating); | 440 | painter->drawPixmap(pos, m_rating); | ||
426 | } | 441 | } | ||
427 | 442 | | |||
443 | if (!m_progressBar.isNull()) { | ||||
444 | const TextInfo* sizeTextInfo = m_textInfo.value("size"); | ||||
445 | if (sizeTextInfo) { | ||||
446 | QPointF pos = sizeTextInfo->pos; | ||||
447 | const Qt::Alignment align = sizeTextInfo->staticText.textOption().alignment(); | ||||
448 | if (align & Qt::AlignHCenter) { | ||||
449 | pos.rx() += (size().width() - m_progressBar.width()) / 2 - 2; | ||||
450 | } | ||||
451 | painter->drawPixmap(pos, m_progressBar); | ||||
452 | } | ||||
453 | } | ||||
454 | | ||||
428 | if (clipAdditionalInfoBounds) { | 455 | if (clipAdditionalInfoBounds) { | ||
429 | painter->restore(); | 456 | painter->restore(); | ||
430 | } | 457 | } | ||
Context not available. | |||||
687 | const QUrl itemUrl = data().value("url").toUrl(); | 714 | const QUrl itemUrl = data().value("url").toUrl(); | ||
688 | m_isCut = clipboard->isCut(itemUrl); | 715 | m_isCut = clipboard->isCut(itemUrl); | ||
689 | 716 | | |||
717 | if (itemUrl.isLocalFile()) { | ||||
718 | const QString urlPath = itemUrl.toLocalFile(); | ||||
719 | KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(urlPath); | ||||
720 | m_isMountPoint = (mp && mp->mountPoint() == urlPath); | ||||
721 | if (m_isMountPoint) { | ||||
722 | if (m_spaceInfoObserver) { | ||||
723 | m_spaceInfoObserver->setUrl(itemUrl); | ||||
724 | } else { | ||||
725 | m_spaceInfoObserver = new SpaceInfoObserver(itemUrl); | ||||
726 | } | ||||
727 | // connect(m_spaceInfoObserver, &MountPointObserver::spaceInfoChanged, this, &KStandardItemListWidget::spaceInfoChanged); | ||||
728 | } | ||||
729 | } else { | ||||
730 | m_isMountPoint = false; | ||||
731 | // if (!m_spaceInfoObserver.isNull()) { | ||||
732 | // disconnect(m_spaceInfoObserver, &MountPointObserver::spaceInfoChanged, this, &KStandardItemListWidget::spaceInfoChanged); | ||||
733 | // } | ||||
734 | if (m_spaceInfoObserver) { | ||||
735 | // m_spaceInfoObserver->deleteLater(); | ||||
736 | } | ||||
737 | } | ||||
738 | | ||||
690 | // The icon-state might depend from other roles and hence is | 739 | // The icon-state might depend from other roles and hence is | ||
691 | // marked as dirty whenever a role has been changed | 740 | // marked as dirty whenever a role has been changed | ||
692 | dirtyRoles.insert("iconPixmap"); | 741 | dirtyRoles.insert("iconPixmap"); | ||
Context not available. | |||||
1106 | const QRect rect(QPoint(0, 0), ratingSize.toSize()); | 1155 | const QRect rect(QPoint(0, 0), ratingSize.toSize()); | ||
1107 | const int rating = data().value("rating").toInt(); | 1156 | const int rating = data().value("rating").toInt(); | ||
1108 | KRatingPainter::paintRating(&painter, rect, Qt::AlignJustify | Qt::AlignVCenter, rating); | 1157 | KRatingPainter::paintRating(&painter, rect, Qt::AlignJustify | Qt::AlignVCenter, rating); | ||
1158 | | ||||
1109 | } else if (!m_rating.isNull()) { | 1159 | } else if (!m_rating.isNull()) { | ||
1110 | m_rating = QPixmap(); | 1160 | m_rating = QPixmap(); | ||
1111 | } | 1161 | } | ||
1162 | | ||||
1163 | if (m_isMountPoint) { | ||||
1164 | const KItemListStyleOption& option = styleOption(); | ||||
1165 | QSizeF progressBarSize = preferredRatingSize(option); | ||||
1166 | | ||||
1167 | const qreal availableWidth = (m_layout == DetailsLayout) | ||||
1168 | ? columnWidth("size") - columnPadding(option) | ||||
1169 | : size().width(); | ||||
1170 | if (progressBarSize.width() > availableWidth) { | ||||
1171 | progressBarSize.rwidth() = availableWidth; | ||||
1172 | } | ||||
1173 | m_progressBar = QPixmap(progressBarSize.toSize()); | ||||
1174 | m_progressBar.fill(Qt::transparent); | ||||
1175 | | ||||
1176 | QPainter painter(&m_progressBar); | ||||
1177 | const QRect rect(0, m_progressBar.height() * 2/10, m_progressBar.width(), m_progressBar.height() * 8/10); | ||||
1178 | // const int rating = data().value("rating").toInt(); | ||||
1179 | // KRatingPainter::paintRating(&painter, rect, Qt::AlignJustify | Qt::AlignVCenter, rating); | ||||
1180 | // painter->setPen(..) | ||||
1181 | | ||||
1182 | | ||||
1183 | // CapacityBar test | ||||
1184 | // https://github.com/qt/qtbase/blob/dev/src/widgets/widgets/qprogressbar.cpp#L405 | ||||
1185 | // https://github.com/qt/qtbase/blob/04eba7b538072e2811f074bf66fd41f27c90b35c/src/widgets/styles/qcommonstyle.cpp#L1403 | ||||
1186 | // const quint64 totalSpace = 1238909347; | ||||
1187 | // const quint64 availableSpace = 238909347; | ||||
1188 | | ||||
1189 | quint64 totalSpace = 0; | ||||
1190 | quint64 availableSpace = 0; | ||||
1191 | if (m_spaceInfoObserver) { | ||||
1192 | totalSpace = m_spaceInfoObserver->size(); | ||||
1193 | availableSpace = m_spaceInfoObserver->available(); | ||||
1194 | } | ||||
1195 | if (totalSpace == 0 && availableSpace == 0) { | ||||
1196 | // Empty progressbar | ||||
1197 | totalSpace = 1; | ||||
1198 | availableSpace = 1; | ||||
1199 | } else { | ||||
1200 | totalSpace = totalSpace < 1 ? 1 : totalSpace; // Don't divide by 0 | ||||
1201 | availableSpace = availableSpace > totalSpace ? totalSpace : availableSpace; // Don't go over 100% | ||||
1202 | } | ||||
1203 | const quint64 usedSpace = totalSpace - availableSpace; | ||||
1204 | const qreal ratio = (qreal)usedSpace / (qreal)totalSpace; | ||||
1205 | // const qreal ratio = 0.96; | ||||
1206 | | ||||
1207 | | ||||
1208 | const QPalette pal = palette(); | ||||
1209 | | ||||
1210 | painter.fillRect(rect, QColor::fromRgb(230, 230, 230)); // Background | ||||
1211 | painter.setPen(QColor::fromRgb(208, 208, 208)); | ||||
1212 | painter.drawRect(rect); // Outline | ||||
1213 | | ||||
1214 | const QRect fillRect(rect.x(), rect.y(), rect.width() * ratio, rect.height()); | ||||
1215 | if (ratio < 0.95) { // Fill | ||||
1216 | painter.fillRect(fillRect, QColor::fromRgb(38, 160, 218)); | ||||
1217 | } else { | ||||
1218 | painter.fillRect(fillRect, QColor::fromRgb(218, 38, 38)); | ||||
1219 | } | ||||
1220 | | ||||
1221 | } else if (!m_progressBar.isNull()) { | ||||
1222 | m_progressBar = QPixmap(); | ||||
1223 | } | ||||
1112 | } | 1224 | } | ||
1113 | 1225 | | |||
1114 | void KStandardItemListWidget::updateIconsLayoutTextCache() | 1226 | void KStandardItemListWidget::updateIconsLayoutTextCache() | ||
Context not available. | |||||
1344 | // The column after the name should always be aligned on the same x-position independent | 1456 | // The column after the name should always be aligned on the same x-position independent | ||
1345 | // from the expansion-level shown in the name column | 1457 | // from the expansion-level shown in the name column | ||
1346 | x -= firstColumnInc; | 1458 | x -= firstColumnInc; | ||
1459 | } else if (role == "size" && !m_progressBar.isNull()) { | ||||
1460 | // textInfo->pos.rx() += roleWidth; | ||||
1347 | } else if (isRoleRightAligned(role)) { | 1461 | } else if (isRoleRightAligned(role)) { | ||
1348 | textInfo->pos.rx() += roleWidth - requiredWidth - columnWidthInc; | 1462 | textInfo->pos.rx() += roleWidth - requiredWidth - columnWidthInc; | ||
1349 | } | 1463 | } | ||
Context not available. |