┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/private
diff options
context:
space:
mode:
Diffstat (limited to 'src/kitemviews/private')
-rw-r--r--src/kitemviews/private/kbaloorolesprovider.cpp184
-rw-r--r--src/kitemviews/private/kbaloorolesprovider.h (renamed from src/kitemviews/private/knepomukrolesprovider.h)30
-rw-r--r--src/kitemviews/private/kdirectorycontentscounter.cpp23
-rw-r--r--src/kitemviews/private/kdirectorycontentscounter.h4
-rw-r--r--src/kitemviews/private/kitemlistheaderwidget.cpp16
-rw-r--r--src/kitemviews/private/kitemlistheaderwidget.h1
-rw-r--r--src/kitemviews/private/kitemlistsizehintresolver.cpp26
-rw-r--r--src/kitemviews/private/kitemlistsizehintresolver.h4
-rw-r--r--src/kitemviews/private/kitemlistviewlayouter.cpp77
-rw-r--r--src/kitemviews/private/kitemlistviewlayouter.h8
-rw-r--r--src/kitemviews/private/knepomukrolesprovider.cpp201
11 files changed, 311 insertions, 263 deletions
diff --git a/src/kitemviews/private/kbaloorolesprovider.cpp b/src/kitemviews/private/kbaloorolesprovider.cpp
new file mode 100644
index 000000000..c0ae0c544
--- /dev/null
+++ b/src/kitemviews/private/kbaloorolesprovider.cpp
@@ -0,0 +1,184 @@
+/***************************************************************************
+ * Copyright (C) 2012 by Peter Penz <[email protected]> *
+ * Copyright (C) 2013 by Vishesh Handa <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#include "kbaloorolesprovider.h"
+
+#include <KDebug>
+#include <KGlobal>
+#include <KLocale>
+
+#include <baloo/file.h>
+#include <kfilemetadata/propertyinfo.h>
+
+#include <QTime>
+#include <QMap>
+
+struct KBalooRolesProviderSingleton
+{
+ KBalooRolesProvider instance;
+};
+K_GLOBAL_STATIC(KBalooRolesProviderSingleton, s_balooRolesProvider)
+
+
+KBalooRolesProvider& KBalooRolesProvider::instance()
+{
+ return s_balooRolesProvider->instance;
+}
+
+KBalooRolesProvider::~KBalooRolesProvider()
+{
+}
+
+QSet<QByteArray> KBalooRolesProvider::roles() const
+{
+ return m_roles;
+}
+
+QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& file,
+ const QSet<QByteArray>& roles) const
+{
+ QHash<QByteArray, QVariant> values;
+
+ int width = -1;
+ int height = -1;
+
+ QMapIterator<KFileMetaData::Property::Property, QVariant> it(file.properties());
+ while (it.hasNext()) {
+ it.next();
+
+ const KFileMetaData::PropertyInfo pi(it.key());
+ const QString property = pi.name();
+ const QByteArray role = roleForProperty(property);
+ if (role.isEmpty() || !roles.contains(role)) {
+ continue;
+ }
+
+ const QVariant value = it.value();
+
+ if (role == "imageSize") {
+ // Merge the two properties for width and height
+ // as one string into the "imageSize" role
+ if (property == QLatin1String("width")) {
+ width = value.toInt();
+ }
+ else if (property == QLatin1String("height")) {
+ height = value.toInt();
+ }
+
+ if (width >= 0 && height >= 0) {
+ QString widthAndHeight = QString::number(width);
+ widthAndHeight += QLatin1String(" x ");
+ widthAndHeight += QString::number(height);
+ values.insert(role, widthAndHeight);
+ }
+ } else if (role == "orientation") {
+ const QString orientation = orientationFromValue(value.toInt());
+ values.insert(role, orientation);
+ } else if (role == "duration") {
+ const QString duration = durationFromValue(value.toInt());
+ values.insert(role, duration);
+ } else {
+ values.insert(role, value.toString());
+ }
+ }
+
+ if (roles.contains("tags")) {
+ values.insert("tags", tagsFromValues(file.tags()));
+ }
+ if (roles.contains("rating")) {
+ values.insert("rating", QString::number(file.rating()));
+ }
+ if (roles.contains("comment")) {
+ values.insert("comment", file.userComment());
+ }
+
+ return values;
+}
+
+QByteArray KBalooRolesProvider::roleForProperty(const QString& property) const
+{
+ return m_roleForProperty.value(property);
+}
+
+KBalooRolesProvider::KBalooRolesProvider() :
+ m_roles(),
+ m_roleForProperty()
+{
+ struct PropertyInfo
+ {
+ const char* const property;
+ const char* const role;
+ };
+
+ // Mapping from the URIs to the KFileItemModel roles. Note that this must not be
+ // a 1:1 mapping: One role may contain several URI-values (e.g. the URIs for height and
+ // width of an image are mapped to the role "imageSize")
+ static const PropertyInfo propertyInfoList[] = {
+ { "rating", "rating" },
+ { "tag", "tags" },
+ { "comment", "comment" },
+ { "wordCount", "wordCount" },
+ { "lineCount", "lineCount" },
+ { "width", "imageSize" },
+ { "height", "imageSize" },
+ { "nexif.orientation", "orientation", },
+ { "artist", "artist" },
+ { "album", "album" },
+ { "duration", "duration" },
+ { "trackNumber", "track" }
+ // { "http://www.semanticdesktop.org/ontologies/2010/04/30/ndo#copiedFrom", "copiedFrom" }
+ };
+
+ for (unsigned int i = 0; i < sizeof(propertyInfoList) / sizeof(PropertyInfo); ++i) {
+ m_roleForProperty.insert(propertyInfoList[i].property, propertyInfoList[i].role);
+ m_roles.insert(propertyInfoList[i].role);
+ }
+}
+
+QString KBalooRolesProvider::tagsFromValues(const QStringList& values) const
+{
+ return values.join(", ");
+}
+
+QString KBalooRolesProvider::orientationFromValue(int value) const
+{
+ QString string;
+ switch (value) {
+ case 1: string = i18nc("@item:intable Image orientation", "Unchanged"); break;
+ case 2: string = i18nc("@item:intable Image orientation", "Horizontally flipped"); break;
+ case 3: string = i18nc("@item:intable image orientation", "180° rotated"); break;
+ case 4: string = i18nc("@item:intable image orientation", "Vertically flipped"); break;
+ case 5: string = i18nc("@item:intable image orientation", "Transposed"); break;
+ case 6: string = i18nc("@item:intable image orientation", "90° rotated"); break;
+ case 7: string = i18nc("@item:intable image orientation", "Transversed"); break;
+ case 8: string = i18nc("@item:intable image orientation", "270° rotated"); break;
+ default:
+ break;
+ }
+ return string;
+}
+
+QString KBalooRolesProvider::durationFromValue(int value) const
+{
+ QTime duration;
+ duration = duration.addSecs(value);
+ return duration.toString("hh:mm:ss");
+}
+
diff --git a/src/kitemviews/private/knepomukrolesprovider.h b/src/kitemviews/private/kbaloorolesprovider.h
index 68a4027e1..f1ad5c740 100644
--- a/src/kitemviews/private/knepomukrolesprovider.h
+++ b/src/kitemviews/private/kbaloorolesprovider.h
@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (C) 2012 by Peter Penz <[email protected]> *
+ * Copyright (C) 2013 by Vishesh Handa <[email protected]> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -17,8 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
-#ifndef KNEPOMUKROLESPROVIDER_H
-#define KNEPOMUKROLESPROVIDER_H
+#ifndef KBALOO_ROLESPROVIDER_H
+#define KBALOO_ROLESPROVIDER_H
#include <libdolphin_export.h>
@@ -26,25 +27,24 @@
#include <QSet>
#include <QUrl>
-namespace Nepomuk2
-{
- class Resource;
+namespace Baloo {
+ class File;
}
/**
* @brief Allows accessing metadata of a file by providing KFileItemModel roles.
*
* Is a helper class for KFileItemModelRolesUpdater to retrieve roles that
- * are only accessible with Nepomuk.
+ * are only accessible with Baloo.
*/
-class LIBDOLPHINPRIVATE_EXPORT KNepomukRolesProvider
+class LIBDOLPHINPRIVATE_EXPORT KBalooRolesProvider
{
public:
- static KNepomukRolesProvider& instance();
- virtual ~KNepomukRolesProvider();
+ static KBalooRolesProvider& instance();
+ virtual ~KBalooRolesProvider();
/**
- * @return Roles that can be provided by KNepomukRolesProvider.
+ * @return Roles that can be provided by KBalooRolesProvider.
*/
QSet<QByteArray> roles() const;
@@ -52,13 +52,13 @@ public:
* @return Values for the roles \a roles that can be determined from the file
* with the URL \a url.
*/
- QHash<QByteArray, QVariant> roleValues(const Nepomuk2::Resource& resource,
+ QHash<QByteArray, QVariant> roleValues(const Baloo::File& file,
const QSet<QByteArray>& roles) const;
- QByteArray roleForPropertyUri(const QUrl& uri) const;
+ QByteArray roleForProperty(const QString& property) const;
protected:
- KNepomukRolesProvider();
+ KBalooRolesProvider();
private:
/**
@@ -81,9 +81,9 @@ private:
private:
QSet<QByteArray> m_roles;
- QHash<QUrl, QByteArray> m_roleForUri;
+ QHash<QString, QByteArray> m_roleForProperty;
- friend class KNepomukRolesProviderSingleton;
+ friend class KBalooRolesProviderSingleton;
};
#endif
diff --git a/src/kitemviews/private/kdirectorycontentscounter.cpp b/src/kitemviews/private/kdirectorycontentscounter.cpp
index fd8479feb..65afb7c3e 100644
--- a/src/kitemviews/private/kdirectorycontentscounter.cpp
+++ b/src/kitemviews/private/kdirectorycontentscounter.cpp
@@ -30,7 +30,6 @@ KDirectoryContentsCounter::KDirectoryContentsCounter(KFileItemModel* model, QObj
QObject(parent),
m_model(model),
m_queue(),
- m_workerThread(0),
m_worker(0),
m_workerIsBusy(false),
m_dirWatcher(0),
@@ -39,25 +38,34 @@ KDirectoryContentsCounter::KDirectoryContentsCounter(KFileItemModel* model, QObj
connect(m_model, SIGNAL(itemsRemoved(KItemRangeList)),
this, SLOT(slotItemsRemoved()));
- m_workerThread = new QThread(this);
+ if (!m_workerThread) {
+ m_workerThread = new QThread();
+ m_workerThread->start();
+ }
+
m_worker = new KDirectoryContentsCounterWorker();
m_worker->moveToThread(m_workerThread);
+ ++m_workersCount;
connect(this, SIGNAL(requestDirectoryContentsCount(QString,KDirectoryContentsCounterWorker::Options)),
m_worker, SLOT(countDirectoryContents(QString,KDirectoryContentsCounterWorker::Options)));
connect(m_worker, SIGNAL(result(QString,int)),
this, SLOT(slotResult(QString,int)));
- m_workerThread->start();
-
m_dirWatcher = new KDirWatch(this);
connect(m_dirWatcher, SIGNAL(dirty(QString)), this, SLOT(slotDirWatchDirty(QString)));
}
KDirectoryContentsCounter::~KDirectoryContentsCounter()
{
- m_workerThread->quit();
- m_workerThread->wait();
+ --m_workersCount;
+
+ if (m_workersCount == 0) {
+ m_workerThread->quit();
+ m_workerThread->wait();
+ delete m_workerThread;
+ m_workerThread = 0;
+ }
delete m_worker;
}
@@ -162,3 +170,6 @@ void KDirectoryContentsCounter::startWorker(const QString& path)
m_workerIsBusy = true;
}
}
+
+QThread* KDirectoryContentsCounter::m_workerThread = 0;
+int KDirectoryContentsCounter::m_workersCount = 0; \ No newline at end of file
diff --git a/src/kitemviews/private/kdirectorycontentscounter.h b/src/kitemviews/private/kdirectorycontentscounter.h
index 425c3632a..c03d0249c 100644
--- a/src/kitemviews/private/kdirectorycontentscounter.h
+++ b/src/kitemviews/private/kdirectorycontentscounter.h
@@ -78,7 +78,9 @@ private:
QQueue<QString> m_queue;
- QThread* m_workerThread;
+ static QThread* m_workerThread;
+ static int m_workersCount;
+
KDirectoryContentsCounterWorker* m_worker;
bool m_workerIsBusy;
diff --git a/src/kitemviews/private/kitemlistheaderwidget.cpp b/src/kitemviews/private/kitemlistheaderwidget.cpp
index b55ba1eb5..1f210ab5a 100644
--- a/src/kitemviews/private/kitemlistheaderwidget.cpp
+++ b/src/kitemviews/private/kitemlistheaderwidget.cpp
@@ -327,6 +327,22 @@ void KItemListHeaderWidget::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
}
}
+void KItemListHeaderWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
+{
+ QGraphicsItem::mouseDoubleClickEvent(event);
+
+ const int roleIndex = roleIndexAt(event->pos());
+ if (roleIndex >= 0 && isAboveRoleGrip(event->pos(), roleIndex)) {
+ const QByteArray role = m_columns.at(roleIndex);
+
+ qreal previousWidth = columnWidth(role);
+ setColumnWidth(role, preferredColumnWidth(role));
+ qreal currentWidth = columnWidth(role);
+
+ emit columnWidthChanged(role, currentWidth, previousWidth);
+ }
+}
+
void KItemListHeaderWidget::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
QGraphicsWidget::hoverEnterEvent(event);
diff --git a/src/kitemviews/private/kitemlistheaderwidget.h b/src/kitemviews/private/kitemlistheaderwidget.h
index f8bba977b..b99f45f35 100644
--- a/src/kitemviews/private/kitemlistheaderwidget.h
+++ b/src/kitemviews/private/kitemlistheaderwidget.h
@@ -100,6 +100,7 @@ protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
+ virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* event);
diff --git a/src/kitemviews/private/kitemlistsizehintresolver.cpp b/src/kitemviews/private/kitemlistsizehintresolver.cpp
index 0e2286b45..029beddf9 100644
--- a/src/kitemviews/private/kitemlistsizehintresolver.cpp
+++ b/src/kitemviews/private/kitemlistsizehintresolver.cpp
@@ -23,7 +23,8 @@
KItemListSizeHintResolver::KItemListSizeHintResolver(const KItemListView* itemListView) :
m_itemListView(itemListView),
- m_sizeHintCache()
+ m_sizeHintCache(),
+ m_needsResolving(false)
{
}
@@ -31,14 +32,10 @@ KItemListSizeHintResolver::~KItemListSizeHintResolver()
{
}
-QSizeF KItemListSizeHintResolver::sizeHint(int index) const
+QSizeF KItemListSizeHintResolver::sizeHint(int index)
{
- QSizeF size = m_sizeHintCache.at(index);
- if (size.isEmpty()) {
- size = m_itemListView->itemSizeHint(index);
- m_sizeHintCache[index] = size;
- }
- return size;
+ updateCache();
+ return m_sizeHintCache.at(index);
}
void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges)
@@ -77,6 +74,8 @@ void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges)
}
}
+ m_needsResolving = true;
+
Q_ASSERT(m_sizeHintCache.count() == m_itemListView->model()->count());
}
@@ -135,9 +134,20 @@ void KItemListSizeHintResolver::itemsChanged(int index, int count, const QSet<QB
++index;
--count;
}
+
+ m_needsResolving = true;
}
void KItemListSizeHintResolver::clearCache()
{
m_sizeHintCache.fill(QSizeF());
+ m_needsResolving = true;
+}
+
+void KItemListSizeHintResolver::updateCache()
+{
+ if (m_needsResolving) {
+ m_itemListView->calculateItemSizeHints(m_sizeHintCache);
+ m_needsResolving = false;
+ }
}
diff --git a/src/kitemviews/private/kitemlistsizehintresolver.h b/src/kitemviews/private/kitemlistsizehintresolver.h
index 486f9b631..86580bf7b 100644
--- a/src/kitemviews/private/kitemlistsizehintresolver.h
+++ b/src/kitemviews/private/kitemlistsizehintresolver.h
@@ -36,7 +36,7 @@ class LIBDOLPHINPRIVATE_EXPORT KItemListSizeHintResolver
public:
KItemListSizeHintResolver(const KItemListView* itemListView);
virtual ~KItemListSizeHintResolver();
- QSizeF sizeHint(int index) const;
+ QSizeF sizeHint(int index);
void itemsInserted(const KItemRangeList& itemRanges);
void itemsRemoved(const KItemRangeList& itemRanges);
@@ -44,10 +44,12 @@ public:
void itemsChanged(int index, int count, const QSet<QByteArray>& roles);
void clearCache();
+ void updateCache();
private:
const KItemListView* m_itemListView;
mutable QVector<QSizeF> m_sizeHintCache;
+ bool m_needsResolving;
};
#endif
diff --git a/src/kitemviews/private/kitemlistviewlayouter.cpp b/src/kitemviews/private/kitemlistviewlayouter.cpp
index f5f63d5ab..73f3d6182 100644
--- a/src/kitemviews/private/kitemlistviewlayouter.cpp
+++ b/src/kitemviews/private/kitemlistviewlayouter.cpp
@@ -46,6 +46,8 @@ KItemListViewLayouter::KItemListViewLayouter(QObject* parent) :
m_columnWidth(0),
m_xPosInc(0),
m_columnCount(0),
+ m_rowOffsets(),
+ m_columnOffsets(),
m_groupItemIndexes(),
m_groupHeaderHeight(0),
m_groupHeaderMargin(0),
@@ -207,7 +209,7 @@ const KItemModelBase* KItemListViewLayouter::model() const
return m_model;
}
-void KItemListViewLayouter::setSizeHintResolver(const KItemListSizeHintResolver* sizeHintResolver)
+void KItemListViewLayouter::setSizeHintResolver(KItemListSizeHintResolver* sizeHintResolver)
{
if (m_sizeHintResolver != sizeHintResolver) {
m_sizeHintResolver = sizeHintResolver;
@@ -246,11 +248,13 @@ QRectF KItemListViewLayouter::itemRect(int index) const
sizeHint = m_itemSize;
}
+ const qreal x = m_columnOffsets.at(m_itemInfos.at(index).column);
+ const qreal y = m_rowOffsets.at(m_itemInfos.at(index).row);
+
if (m_scrollOrientation == Qt::Horizontal) {
// Rotate the logical direction which is always vertical by 90°
// to get the physical horizontal direction
- const QPointF logicalPos = m_itemInfos[index].pos;
- QPointF pos(logicalPos.y(), logicalPos.x());
+ QPointF pos(y, x);
pos.rx() -= m_scrollOffset;
return QRectF(pos, sizeHint);
}
@@ -260,8 +264,7 @@ QRectF KItemListViewLayouter::itemRect(int index) const
sizeHint.rwidth() = m_itemSize.width();
}
- QPointF pos = m_itemInfos[index].pos;
- pos -= QPointF(m_itemOffset, m_scrollOffset);
+ const QPointF pos(x - m_itemOffset, y - m_scrollOffset);
return QRectF(pos, sizeHint);
}
@@ -284,16 +287,15 @@ QRectF KItemListViewLayouter::groupHeaderRect(int index) const
pos.rx() -= m_itemMargin.width();
pos.ry() = 0;
- // Determine the maximum width used in the
- // current column. As the scroll-direction is
- // Qt::Horizontal and m_itemRects is accessed directly,
- // the logical height represents the visual width.
+ // Determine the maximum width used in the current column. As the
+ // scroll-direction is Qt::Horizontal and m_itemRects is accessed
+ // directly, the logical height represents the visual width, and
+ // the logical row represents the column.
qreal headerWidth = minimumGroupHeaderWidth();
- const qreal y = m_itemInfos[index].pos.y();
+ const int row = m_itemInfos[index].row;
const int maxIndex = m_itemInfos.count() - 1;
while (index <= maxIndex) {
- const QPointF pos = m_itemInfos[index].pos;
- if (pos.y() != y) {
+ if (m_itemInfos[index].row != row) {
break;
}
@@ -422,21 +424,40 @@ void KItemListViewLayouter::doLayout()
m_itemInfos.resize(itemCount);
+ // Calculate the offset of each column, i.e., the x-coordinate where the column starts.
+ m_columnOffsets.resize(m_columnCount);
+ qreal currentOffset = m_xPosInc;
+
+ if (grouped && horizontalScrolling) {
+ // All group headers will always be aligned on the top and not
+ // flipped like the other properties.
+ currentOffset += m_groupHeaderHeight;
+ }
+
+ for (int column = 0; column < m_columnCount; ++column) {
+ m_columnOffsets[column] = currentOffset;
+ currentOffset += m_columnWidth;
+ }
+
+ // Prepare the QVector which stores the y-coordinate for each new row.
+ int numberOfRows = (itemCount + m_columnCount - 1) / m_columnCount;
+ if (grouped && m_columnCount > 1) {
+ // In the worst case, a new row will be started for every group.
+ // We could calculate the exact number of rows now to prevent that we reserve
+ // too much memory, but the code required to do that might need much more
+ // memory than it would save in the average case.
+ numberOfRows += m_groupItemIndexes.count();
+ }
+ m_rowOffsets.resize(numberOfRows);
+
qreal y = m_headerHeight + itemMargin.height();
int row = 0;
int index = 0;
while (index < itemCount) {
- qreal x = m_xPosInc;
qreal maxItemHeight = itemSize.height();
if (grouped) {
- if (horizontalScrolling) {
- // All group headers will always be aligned on the top and not
- // flipped like the other properties
- x += m_groupHeaderHeight;
- }
-
if (m_groupItemIndexes.contains(index)) {
// The item is the first item of a group.
// Increase the y-position to provide space
@@ -456,6 +477,8 @@ void KItemListViewLayouter::doLayout()
}
}
+ m_rowOffsets[row] = y;
+
int column = 0;
while (index < itemCount && column < m_columnCount) {
qreal requiredItemHeight = itemSize.height();
@@ -468,7 +491,6 @@ void KItemListViewLayouter::doLayout()
}
ItemInfo& itemInfo = m_itemInfos[index];
- itemInfo.pos = QPointF(x, y);
itemInfo.column = column;
itemInfo.row = row;
@@ -492,7 +514,6 @@ void KItemListViewLayouter::doLayout()
}
maxItemHeight = qMax(maxItemHeight, requiredItemHeight);
- x += m_columnWidth;
++index;
++column;
@@ -547,7 +568,7 @@ void KItemListViewLayouter::updateVisibleIndexes()
int mid = 0;
do {
mid = (min + max) / 2;
- if (m_itemInfos[mid].pos.y() < m_scrollOffset) {
+ if (m_rowOffsets.at(m_itemInfos[mid].row) < m_scrollOffset) {
min = mid + 1;
} else {
max = mid - 1;
@@ -557,13 +578,13 @@ void KItemListViewLayouter::updateVisibleIndexes()
if (mid > 0) {
// Include the row before the first fully visible index, as it might
// be partly visible
- if (m_itemInfos[mid].pos.y() >= m_scrollOffset) {
+ if (m_rowOffsets.at(m_itemInfos[mid].row) >= m_scrollOffset) {
--mid;
- Q_ASSERT(m_itemInfos[mid].pos.y() < m_scrollOffset);
+ Q_ASSERT(m_rowOffsets.at(m_itemInfos[mid].row) < m_scrollOffset);
}
- const qreal rowTop = m_itemInfos[mid].pos.y();
- while (mid > 0 && m_itemInfos[mid - 1].pos.y() == rowTop) {
+ const int firstVisibleRow = m_itemInfos[mid].row;
+ while (mid > 0 && m_itemInfos[mid - 1].row == firstVisibleRow) {
--mid;
}
}
@@ -580,14 +601,14 @@ void KItemListViewLayouter::updateVisibleIndexes()
max = maxIndex;
do {
mid = (min + max) / 2;
- if (m_itemInfos[mid].pos.y() <= bottom) {
+ if (m_rowOffsets.at(m_itemInfos[mid].row) <= bottom) {
min = mid + 1;
} else {
max = mid - 1;
}
} while (min <= max);
- while (mid > 0 && m_itemInfos[mid].pos.y() > bottom) {
+ while (mid > 0 && m_rowOffsets.at(m_itemInfos[mid].row) > bottom) {
--mid;
}
m_lastVisibleIndex = mid;
diff --git a/src/kitemviews/private/kitemlistviewlayouter.h b/src/kitemviews/private/kitemlistviewlayouter.h
index a3b0893a1..5ae472411 100644
--- a/src/kitemviews/private/kitemlistviewlayouter.h
+++ b/src/kitemviews/private/kitemlistviewlayouter.h
@@ -103,7 +103,7 @@ public:
void setModel(const KItemModelBase* model);
const KItemModelBase* model() const;
- void setSizeHintResolver(const KItemListSizeHintResolver* sizeHintResolver);
+ void setSizeHintResolver(KItemListSizeHintResolver* sizeHintResolver);
const KItemListSizeHintResolver* sizeHintResolver() const;
/**
@@ -205,7 +205,7 @@ private:
QSizeF m_itemMargin;
qreal m_headerHeight;
const KItemModelBase* m_model;
- const KItemListSizeHintResolver* m_sizeHintResolver;
+ KItemListSizeHintResolver* m_sizeHintResolver;
qreal m_scrollOffset;
qreal m_maximumScrollOffset;
@@ -220,6 +220,9 @@ private:
qreal m_xPosInc;
int m_columnCount;
+ QVector<qreal> m_rowOffsets;
+ QVector<qreal> m_columnOffsets;
+
// Stores all item indexes that are the first item of a group.
// Assures fast access for KItemListViewLayouter::isFirstGroupItem().
QSet<int> m_groupItemIndexes;
@@ -227,7 +230,6 @@ private:
qreal m_groupHeaderMargin;
struct ItemInfo {
- QPointF pos;
int column;
int row;
};
diff --git a/src/kitemviews/private/knepomukrolesprovider.cpp b/src/kitemviews/private/knepomukrolesprovider.cpp
deleted file mode 100644
index e237f948f..000000000
--- a/src/kitemviews/private/knepomukrolesprovider.cpp
+++ /dev/null
@@ -1,201 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2012 by Peter Penz <[email protected]> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
-
-#include "knepomukrolesprovider.h"
-
-#include <KDebug>
-#include <KGlobal>
-#include <KLocale>
-
-#include <Nepomuk2/Resource>
-#include <Nepomuk2/Tag>
-#include <Nepomuk2/Types/Property>
-#include <Nepomuk2/Variant>
-
-#include <QTime>
-
-struct KNepomukRolesProviderSingleton
-{
- KNepomukRolesProvider instance;
-};
-K_GLOBAL_STATIC(KNepomukRolesProviderSingleton, s_nepomukRolesProvider)
-
-
-KNepomukRolesProvider& KNepomukRolesProvider::instance()
-{
- return s_nepomukRolesProvider->instance;
-}
-
-KNepomukRolesProvider::~KNepomukRolesProvider()
-{
-}
-
-QSet<QByteArray> KNepomukRolesProvider::roles() const
-{
- return m_roles;
-}
-
-QHash<QByteArray, QVariant> KNepomukRolesProvider::roleValues(const Nepomuk2::Resource& resource,
- const QSet<QByteArray>& roles) const
-{
- if (!resource.isValid()) {
- return QHash<QByteArray, QVariant>();
- }
-
- QHash<QByteArray, QVariant> values;
-
- int width = -1;
- int height = -1;
-
- QHashIterator<QUrl, Nepomuk2::Variant> it(resource.properties());
- while (it.hasNext()) {
- it.next();
-
- const Nepomuk2::Types::Property property = it.key();
- const QByteArray role = roleForPropertyUri(property.uri());
- if (role.isEmpty() || !roles.contains(role)) {
- continue;
- }
-
- const Nepomuk2::Variant value = it.value();
-
- if (role == "imageSize") {
- // Merge the two Nepomuk properties for width and height
- // as one string into the "imageSize" role
- const QString uri = property.uri().toString();
- if (uri.endsWith(QLatin1String("#width"))) {
- width = value.toInt();
- } else if (uri.endsWith(QLatin1String("#height"))) {
- height = value.toInt();
- }
-
- if (width >= 0 && height >= 0) {
- const QString widthAndHeight = QString::number(width) +
- QLatin1String(" x ") +
- QString::number(height);
- values.insert(role, widthAndHeight);
- }
- } else if (role == "tags") {
- const QString tags = tagsFromValues(value.toStringList());
- values.insert(role, tags);
- } else if (role == "orientation") {
- const QString orientation = orientationFromValue(value.toInt());
- values.insert(role, orientation);
- } else if (role == "duration") {
- const QString duration = durationFromValue(value.toInt());
- values.insert(role, duration);
- } else if (value.isResource()) {
- const Nepomuk2::Resource resource = value.toResource();
- values.insert(role, resource.genericLabel());
- } else if (value.isResourceList()) {
- const QList<Nepomuk2::Resource> resList = value.toResourceList();
- QStringList strList;
- foreach (const Nepomuk2::Resource& res, resList) {
- strList << res.genericLabel();
- }
- values.insert(role, strList.join(QLatin1String(", ")));
- } else {
- values.insert(role, value.toString());
- }
- }
-
- return values;
-}
-
-QByteArray KNepomukRolesProvider::roleForPropertyUri(const QUrl& uri) const
-{
- return m_roleForUri.value(uri);
-}
-
-KNepomukRolesProvider::KNepomukRolesProvider() :
- m_roles(),
- m_roleForUri()
-{
- struct UriInfo
- {
- const char* const uri;
- const char* const role;
- };
-
- // Mapping from the URIs to the KFileItemModel roles. Note that this must not be
- // a 1:1 mapping: One role may contain several URI-values (e.g. the URIs for height and
- // width of an image are mapped to the role "imageSize")
- static const UriInfo uriInfoList[] = {
- { "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#numericRating", "rating" },
- { "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#hasTag", "tags" },
- { "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#description", "comment" },
- { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#wordCount", "wordCount" },
- { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#lineCount", "lineCount" },
- { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#width", "imageSize" },
- { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#height", "imageSize" },
- { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#orientation", "orientation", },
- { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#performer", "artist" },
- { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#musicAlbum", "album" },
- { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#duration", "duration" },
- { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#trackNumber", "track" },
- { "http://www.semanticdesktop.org/ontologies/2010/04/30/ndo#copiedFrom", "copiedFrom" }
- };
-
- for (unsigned int i = 0; i < sizeof(uriInfoList) / sizeof(UriInfo); ++i) {
- m_roleForUri.insert(QUrl(uriInfoList[i].uri), uriInfoList[i].role);
- m_roles.insert(uriInfoList[i].role);
- }
-}
-
-QString KNepomukRolesProvider::tagsFromValues(const QStringList& values) const
-{
- QString tags;
-
- for (int i = 0; i < values.count(); ++i) {
- if (i > 0) {
- tags.append(QLatin1String(", "));
- }
-
- const Nepomuk2::Tag tag(values[i]);
- tags += tag.genericLabel();
- }
-
- return tags;
-}
-
-QString KNepomukRolesProvider::orientationFromValue(int value) const
-{
- QString string;
- switch (value) {
- case 1: string = i18nc("@item:intable Image orientation", "Unchanged"); break;
- case 2: string = i18nc("@item:intable Image orientation", "Horizontally flipped"); break;
- case 3: string = i18nc("@item:intable image orientation", "180° rotated"); break;
- case 4: string = i18nc("@item:intable image orientation", "Vertically flipped"); break;
- case 5: string = i18nc("@item:intable image orientation", "Transposed"); break;
- case 6: string = i18nc("@item:intable image orientation", "90° rotated"); break;
- case 7: string = i18nc("@item:intable image orientation", "Transversed"); break;
- case 8: string = i18nc("@item:intable image orientation", "270° rotated"); break;
- default:
- break;
- }
- return string;
-}
-
-QString KNepomukRolesProvider::durationFromValue(int value) const
-{
- QTime duration;
- duration = duration.addSecs(value);
- return duration.toString("hh:mm:ss");
-}
-