Images: Instead of showing the meta data for "Width:" and "Height:" separately with other items in between, they are merged as "Width x Height:" and added to the top of the sort order.

CCBUG: 193592

svn path=/trunk/KDE/kdebase/apps/; revision=1047680
This commit is contained in:
Peter Penz 2009-11-11 19:47:07 +00:00
parent 36ae0b6185
commit 98f0289c76

View file

@ -102,6 +102,11 @@ public:
*/
void startChangeDataJob(KJob* job);
/**
* Merges items like 'width' and 'height' as one item.
*/
QList<KLoadMetaDataThread::Item> mergedItems(const QList<KLoadMetaDataThread::Item>& items);
bool m_sizeVisible;
bool m_readOnly;
MetaDataTypes m_visibleDataTypes;
@ -341,7 +346,7 @@ void KMetaDataWidget::Private::slotLoadingFinished()
const int rowCount = m_rows.count();
Q_ASSERT(rowCount >= index);
const QList<KLoadMetaDataThread::Item> items = m_loadMetaDataThread->items();
const QList<KLoadMetaDataThread::Item> items = mergedItems(m_loadMetaDataThread->items());
foreach (const KLoadMetaDataThread::Item& item, items) {
if (index < rowCount) {
// adjust texts of the current row
@ -362,7 +367,7 @@ void KMetaDataWidget::Private::slotLoadingFinished()
}
// remove rows that are not needed anymore
for (int i = m_rows.count() - 1; i > index; --i) {
for (int i = m_rows.count() - 1; i >= index; --i) {
delete m_rows[i].label;
delete m_rows[i].infoWidget;
m_rows.pop_back();
@ -429,6 +434,55 @@ void KMetaDataWidget::Private::startChangeDataJob(KJob* job)
}
#endif
QList<KLoadMetaDataThread::Item>
KMetaDataWidget::Private::mergedItems(const QList<KLoadMetaDataThread::Item>& items)
{
// TODO: Currently only "width" and "height" are merged as "width x height". If
// other kind of merges should be done too, a more general approach is required.
QList<KLoadMetaDataThread::Item> mergedItems;
KLoadMetaDataThread::Item width;
KLoadMetaDataThread::Item height;
foreach (const KLoadMetaDataThread::Item& item, items) {
if (item.name == "width") {
width = item;
} else if (item.name == "height") {
height = item;
} else {
// insert the item sorted by the label
bool inserted = false;
int i = 0;
const int count = mergedItems.count();
while (!inserted && (i < count)) {
if (item.label < mergedItems[i].label) {
mergedItems.insert(i, item);
inserted = true;
}
++i;
}
if (!inserted) {
mergedItems.append(item);
}
}
}
const bool foundWidth = !width.name.isEmpty();
const bool foundHeight = !height.name.isEmpty();
if (foundWidth && !foundHeight) {
mergedItems.insert(0, width);
} else if (foundHeight && !foundWidth) {
mergedItems.insert(0, height);
} else if (foundWidth && foundHeight) {
KLoadMetaDataThread::Item size;
size.label = i18nc("@label", "Width x Height:");
size.value = width.value + " x " + height.value;
mergedItems.insert(0, size);
}
return mergedItems;
}
KMetaDataWidget::KMetaDataWidget(QWidget* parent) :
QWidget(parent),
d(new Private(this))