X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/b7fa85a33d6b5c1b2a5b60b64a78f7f208ea304c..1e5bc5b3d6ba344da09369802d822f6cd6da7c4c:/src/kitemviews/kfileitemlistwidget.cpp diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp index d9644bef5..e1da7192a 100644 --- a/src/kitemviews/kfileitemlistwidget.cpp +++ b/src/kitemviews/kfileitemlistwidget.cpp @@ -9,7 +9,7 @@ #include "kfileitemmodel.h" #include "kitemlistview.h" -#include "dolphin_detailsmodesettings.h" +#include "dolphin_contentdisplaysettings.h" #include #include @@ -45,7 +45,7 @@ bool KFileItemListWidgetInformant::itemIsLink(int index, const KItemListView *vi return item.isLink(); } -QString KFileItemListWidgetInformant::roleText(const QByteArray &role, const QHash &values) const +QString KFileItemListWidgetInformant::roleText(const QByteArray &role, const QHash &values, ForUsageAs forUsageAs) const { QString text; const QVariant roleValue = values.value(role); @@ -55,11 +55,13 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray &role, const QHa // Implementation note: In case if more roles require a custom handling // use a hash + switch for a linear runtime. - auto formatDate = [formatter, local](const QDateTime &time) { - if (DetailsModeSettings::useShortRelativeDates()) { - return formatter.formatRelativeDateTime(time, QLocale::ShortFormat); + auto formatDate = [formatter, local, forUsageAs](const QDateTime &time) { + if (ContentDisplaySettings::useShortRelativeDates()) { + return formatter.formatRelativeDateTime(time, + forUsageAs == KStandardItemListWidgetInformant::ForUsageAs::DisplayedText ? QLocale::ShortFormat + : QLocale::LongFormat); } else { - return local.toString(time, QLocale::ShortFormat); + return local.toString(time, forUsageAs == KStandardItemListWidgetInformant::ForUsageAs::DisplayedText ? QLocale::ShortFormat : QLocale::LongFormat); } }; @@ -67,7 +69,8 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray &role, const QHa if (values.value("isDir").toBool()) { if (!roleValue.isNull() && roleValue != -1) { // The item represents a directory. - if (DetailsModeSettings::directorySizeCount()) { + if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount + || roleValue == -2 /* size is invalid */) { // Show the number of sub directories instead of the file size of the directory. const int count = values.value("count").toInt(); text = i18ncp("@item:intable", "%1 item", "%1 items", count); @@ -101,19 +104,19 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray &role, const QHa } else if (role == "permissions") { const auto permissions = roleValue.value(); - switch (DetailsModeSettings::usePermissionsFormat()) { - case DetailsModeSettings::EnumUsePermissionsFormat::SymbolicFormat: + switch (ContentDisplaySettings::usePermissionsFormat()) { + case ContentDisplaySettings::EnumUsePermissionsFormat::SymbolicFormat: text = permissions.at(0).toString(); break; - case DetailsModeSettings::EnumUsePermissionsFormat::NumericFormat: + case ContentDisplaySettings::EnumUsePermissionsFormat::NumericFormat: text = QString::number(permissions.at(1).toInt(), 8); break; - case DetailsModeSettings::EnumUsePermissionsFormat::CombinedFormat: - text = QString("%1 (%2)").arg(permissions.at(0).toString()).arg(permissions.at(1).toInt(), 0, 8); + case ContentDisplaySettings::EnumUsePermissionsFormat::CombinedFormat: + text = QLatin1String("%1 (%2)").arg(permissions.at(0).toString()).arg(permissions.at(1).toInt(), 0, 8); break; } } else { - text = KStandardItemListWidgetInformant::roleText(role, values); + text = KStandardItemListWidgetInformant::roleText(role, values, forUsageAs); } return text; @@ -161,33 +164,31 @@ QFont KFileItemListWidget::customizedFont(const QFont &baseFont) const int KFileItemListWidget::selectionLength(const QString &text) const { - // Select the text without MIME-type extension - int selectionLength = text.length(); - // If item is a directory, use the whole text length for // selection (ignore all points) if (data().value("isDir").toBool()) { - return selectionLength; + return numberOfUnicodeCharactersIn(text); } + int indexOfExtension = text.length(); + QMimeDatabase db; const QString extension = db.suffixForFileName(text); if (extension.isEmpty()) { // For an unknown extension just exclude the extension after - // the last point. This does not work for multiple extensions like + // the last dot. This does not work for multiple extensions like // *.tar.gz but usually this is anyhow a known extension. - selectionLength = text.lastIndexOf(QLatin1Char('.')); + indexOfExtension = text.lastIndexOf(QLatin1Char('.')); - // If no point could be found, use whole text length for selection. - if (selectionLength < 1) { - selectionLength = text.length(); + // if there either is no dot, or the last dot is the first or last char, treat as no extension. + if (indexOfExtension < 1 || indexOfExtension == text.length() - 1) { + indexOfExtension = text.length(); } - } else { - selectionLength -= extension.length() + 1; + indexOfExtension -= extension.length() + 1; } - return selectionLength; + return numberOfUnicodeCharactersIn(text.left(indexOfExtension)); } void KFileItemListWidget::hoverSequenceStarted() @@ -203,6 +204,17 @@ void KFileItemListWidget::hoverSequenceStarted() view->setHoverSequenceState(itemUrl, 0); } +void KFileItemListWidget::forceUpdate() +{ + updateAdditionalInfoTextColor(); + // icon layout does not include the icons in the item selection rectangle + // so its icon does not need updating + if (listView()->itemLayout() != KStandardItemListView::ItemLayout::IconsLayout) { + invalidateIconCache(); + } + update(); +} + void KFileItemListWidget::hoverSequenceIndexChanged(int sequenceIndex) { KFileItemListView *view = listView(); @@ -235,3 +247,5 @@ KFileItemListView *KFileItemListWidget::listView() { return dynamic_cast(parentItem()); } + +#include "moc_kfileitemlistwidget.cpp"