Changeset View
Changeset View
Standalone View
Standalone View
src/widgetfactory.cpp
Show All 31 Lines | |||||
32 | #include <QCollator> | 32 | #include <QCollator> | ||
33 | #include <QTime> | 33 | #include <QTime> | ||
34 | #include <QUrl> | 34 | #include <QUrl> | ||
35 | #include <QLocale> | 35 | #include <QLocale> | ||
36 | 36 | | |||
37 | #include <KJob> | 37 | #include <KJob> | ||
38 | #include <KFormat> | 38 | #include <KFormat> | ||
39 | #include <KLocalizedString> | 39 | #include <KLocalizedString> | ||
40 | #include <KStringHandler> | ||||
40 | 41 | | |||
41 | namespace { | 42 | namespace { | ||
42 | static QString plainText(const QString& richText) | 43 | static QString plainText(const QString& richText) | ||
43 | { | 44 | { | ||
44 | QString plainText; | 45 | QString plainText; | ||
45 | plainText.reserve(richText.length()); | 46 | plainText.reserve(richText.length()); | ||
46 | 47 | | |||
47 | bool skip = false; | 48 | bool skip = false; | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 83 | switch (value.type()) { | |||
98 | default: | 99 | default: | ||
99 | return value.toString(); | 100 | return value.toString(); | ||
100 | } | 101 | } | ||
101 | } | 102 | } | ||
102 | 103 | | |||
103 | QWidget* WidgetFactory::createWidget(const QString& prop, const QVariant& value, QWidget* parent) | 104 | QWidget* WidgetFactory::createWidget(const QString& prop, const QVariant& value, QWidget* parent) | ||
104 | { | 105 | { | ||
105 | QWidget* widget = nullptr; | 106 | QWidget* widget = nullptr; | ||
107 | const int maxUrlLength = 80; | ||||
elvisangelaccio: Space before/after = also here ;) | |||||
106 | 108 | | |||
107 | if (prop == QLatin1String("rating")) { | 109 | if (prop == QLatin1String("rating")) { | ||
108 | widget = createRatingWidget( value.toInt(), parent ); | 110 | widget = createRatingWidget( value.toInt(), parent ); | ||
109 | } | 111 | } | ||
110 | else if (prop == QLatin1String("userComment")) { | 112 | else if (prop == QLatin1String("userComment")) { | ||
111 | widget = createCommentWidget( value.toString(), parent ); | 113 | widget = createCommentWidget( value.toString(), parent ); | ||
112 | } | 114 | } | ||
113 | else if (prop == QLatin1String("tags")) { | 115 | else if (prop == QLatin1String("tags")) { | ||
114 | QStringList tags = value.toStringList(); | 116 | QStringList tags = value.toStringList(); | ||
115 | QCollator coll; | 117 | QCollator coll; | ||
116 | coll.setNumericMode(true); | 118 | coll.setNumericMode(true); | ||
117 | std::sort(tags.begin(), tags.end(), [&](const QString& s1, const QString& s2){ return coll.compare(s1, s2) < 0; }); | 119 | std::sort(tags.begin(), tags.end(), [&](const QString& s1, const QString& s2){ return coll.compare(s1, s2) < 0; }); | ||
118 | widget = createTagWidget( tags, parent ); | 120 | widget = createTagWidget( tags, parent ); | ||
119 | } | 121 | } | ||
120 | else { | 122 | else { | ||
121 | QString valueString; | 123 | QString valueString; | ||
122 | auto pi = KFileMetaData::PropertyInfo::fromName(prop); | 124 | auto pi = KFileMetaData::PropertyInfo::fromName(prop); | ||
123 | if (pi.name() == QLatin1String("originUrl")) { | 125 | if (pi.name() == QLatin1String("originUrl")) { | ||
124 | if (m_noLinks) { | 126 | //Won't make sense to shrink originUrl with noLinks, | ||
127 | //since it would make original URL unobtainable | ||||
125 | valueString = value.toString(); | 128 | valueString = value.toString(); | ||
126 | } else { | 129 | if (!m_noLinks) { | ||
127 | valueString = QStringLiteral("<a href=\"%1\">%1</a>").arg(value.toString()); | 130 | //Shrink link name. | ||
131 | auto labelString = valueString; | ||||
132 | if (labelString.size() > maxUrlLength) { | ||||
133 | labelString = KStringHandler::csqueeze(labelString, maxUrlLength); | ||||
Please put the 80 constant in a variable. Please add spaces before/after the > operator. elvisangelaccio: Please put the `80` constant in a variable.
Please add spaces before/after the `>` operator. | |||||
134 | } | ||||
135 | valueString = QStringLiteral("<a href=\"%1\">%2</a>").arg(valueString, labelString); | ||||
128 | } | 136 | } | ||
129 | } else if (pi.name() != QLatin1String("empty")) { | 137 | } else if (pi.name() != QLatin1String("empty")) { | ||
130 | valueString = pi.formatAsDisplayString(value); | 138 | valueString = pi.formatAsDisplayString(value); | ||
131 | } else { | 139 | } else { | ||
132 | // Check if Date/DateTime | 140 | // Check if Date/DateTime | ||
133 | QDateTime dt = QDateTime::fromString(value.toString(), Qt::ISODate); | 141 | QDateTime dt = QDateTime::fromString(value.toString(), Qt::ISODate); | ||
134 | if (dt.isValid()) { | 142 | if (dt.isValid()) { | ||
135 | KFormat form; | 143 | KFormat form; | ||
▲ Show 20 Lines • Show All 201 Lines • Show Last 20 Lines |
Space before/after = also here ;)