mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-21 17:30:15 +00:00
Add "Dimensions" (width x height) role
It is more convenient to use than individual width and height properties
This commit is contained in:
parent
7c5af3f88e
commit
94262a1c02
|
@ -94,6 +94,11 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray& role,
|
|||
if (dateTime.isValid()) {
|
||||
text = formatDate(dateTime);
|
||||
}
|
||||
} else if (role == "dimensions") {
|
||||
const auto dimensions = roleValue.toSize();
|
||||
if (dimensions.isValid()) {
|
||||
text = i18nc("width x height", "%1 x %2", dimensions.width(), dimensions.height());
|
||||
}
|
||||
} else {
|
||||
text = KStandardItemListWidgetInformant::roleText(role, values);
|
||||
}
|
||||
|
|
|
@ -2089,6 +2089,19 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
|
|||
break;
|
||||
}
|
||||
|
||||
case DimensionsRole: {
|
||||
const QByteArray role = roleForType(m_sortRole);
|
||||
const QSize dimensionsA = a->values.value(role).toSize();
|
||||
const QSize dimensionsB = b->values.value(role).toSize();
|
||||
|
||||
if (dimensionsA.width() == dimensionsB.width()) {
|
||||
result = dimensionsA.height() - dimensionsB.height();
|
||||
} else {
|
||||
result = dimensionsA.width() - dimensionsB.width();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
const QByteArray role = roleForType(m_sortRole);
|
||||
const QString roleValueA = a->values.value(role).toString();
|
||||
|
@ -2596,6 +2609,7 @@ const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count)
|
|||
{ "wordCount", WordCountRole, kli18nc("@label", "Word Count"), kli18nc("@label", "Document"), true, true },
|
||||
{ "lineCount", LineCountRole, kli18nc("@label", "Line Count"), kli18nc("@label", "Document"), true, true },
|
||||
{ "imageDateTime", ImageDateTimeRole, kli18nc("@label", "Date Photographed"), kli18nc("@label", "Image"), true, true },
|
||||
{ "dimensions", DimensionsRole, kli18nc("@label width x height", "Dimensions"), kli18nc("@label", "Image"), true, true },
|
||||
{ "width", WidthRole, kli18nc("@label", "Width"), kli18nc("@label", "Image"), true, true },
|
||||
{ "height", HeightRole, kli18nc("@label", "Height"), kli18nc("@label", "Image"), true, true },
|
||||
{ "orientation", OrientationRole, kli18nc("@label", "Orientation"), kli18nc("@label", "Image"), true, true },
|
||||
|
|
|
@ -292,7 +292,7 @@ private:
|
|||
NoRole, NameRole, SizeRole, ModificationTimeRole, CreationTimeRole, AccessTimeRole, PermissionsRole, OwnerRole,
|
||||
GroupRole, TypeRole, DestinationRole, PathRole, DeletionTimeRole,
|
||||
// User visible roles available with Baloo:
|
||||
CommentRole, TagsRole, RatingRole, WidthRole, HeightRole, ImageDateTimeRole, OrientationRole,
|
||||
CommentRole, TagsRole, RatingRole, DimensionsRole, WidthRole, HeightRole, ImageDateTimeRole, OrientationRole,
|
||||
WordCountRole, TitleRole, LineCountRole, ArtistRole, GenreRole, AlbumRole, DurationRole, TrackRole, ReleaseYearRole,
|
||||
BitrateRole, OriginUrlRole, AspectRatioRole, FrameRateRole,
|
||||
// Non-visible roles:
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <QCollator>
|
||||
#include <QDebug>
|
||||
#include <QSize>
|
||||
#include <QTime>
|
||||
|
||||
namespace {
|
||||
|
@ -117,6 +118,18 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f
|
|||
rangeBegin = rangeEnd;
|
||||
}
|
||||
|
||||
if (roles.contains("dimensions")) {
|
||||
bool widthOk = false;
|
||||
bool heightOk = false;
|
||||
|
||||
const int width = propMap.value(KFileMetaData::Property::Width).toInt(&widthOk);
|
||||
const int height = propMap.value(KFileMetaData::Property::Height).toInt(&heightOk);
|
||||
|
||||
if (widthOk && heightOk && width >= 0 && height >= 0) {
|
||||
values.insert("dimensions", QSize(width, height));
|
||||
}
|
||||
}
|
||||
|
||||
KFileMetaData::UserMetaData::Attributes attributes;
|
||||
if (roles.contains("tags")) {
|
||||
attributes |= KFileMetaData::UserMetaData::Tags;
|
||||
|
@ -160,6 +173,7 @@ KBalooRolesProvider::KBalooRolesProvider()
|
|||
for (const auto& role : propertyRoleMap()) {
|
||||
m_roles.insert(role);
|
||||
}
|
||||
m_roles.insert("dimensions");
|
||||
|
||||
// Display roles provided by UserMetaData
|
||||
m_roles.insert(QByteArrayLiteral("tags"));
|
||||
|
|
Loading…
Reference in a new issue