* Boston, MA 02110-1301, USA.
*/
-#include "klistview.h"
-#include "klistview_p.h"
+#include "kcategorizedview.h"
+#include "kcategorizedview_p.h"
#include <math.h> // trunc on C99 compliant systems
#include <kdefakes.h> // trunc for not C99 compliant systems
//==============================================================================
-KListView::Private::Private(KListView *listView)
+KCategorizedView::Private::Private(KCategorizedView *listView)
: listView(listView)
, itemCategorizer(0)
, mouseButtonPressed(false)
{
}
-KListView::Private::~Private()
+KCategorizedView::Private::~Private()
{
}
-const QModelIndexList &KListView::Private::intersectionSet(const QRect &rect)
+const QModelIndexList &KCategorizedView::Private::intersectionSet(const QRect &rect)
{
QModelIndex index;
QRect indexVisualRect;
return intersectedIndexes;
}
-QRect KListView::Private::visualRectInViewport(const QModelIndex &index) const
+QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index) const
{
if (!index.isValid())
return QRect();
return retRect;
}
-QRect KListView::Private::visualCategoryRectInViewport(const QString &category)
+QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &category)
const
{
QRect retRect(listView->spacing(),
}
// We're sure elementsPosition doesn't contain index
-const QRect &KListView::Private::cacheIndex(const QModelIndex &index)
+const QRect &KCategorizedView::Private::cacheIndex(const QModelIndex &index)
{
QRect rect = visualRectInViewport(index);
elementsPosition[index] = rect;
}
// We're sure categoriesPosition doesn't contain category
-const QRect &KListView::Private::cacheCategory(const QString &category)
+const QRect &KCategorizedView::Private::cacheCategory(const QString &category)
{
QRect rect = visualCategoryRectInViewport(category);
categoriesPosition[category] = rect;
return categoriesPosition[category];
}
-const QRect &KListView::Private::cachedRectIndex(const QModelIndex &index)
+const QRect &KCategorizedView::Private::cachedRectIndex(const QModelIndex &index)
{
if (elementsPosition.contains(index)) // If we have it cached
{ // return it
}
}
-const QRect &KListView::Private::cachedRectCategory(const QString &category)
+const QRect &KCategorizedView::Private::cachedRectCategory(const QString &category)
{
if (categoriesPosition.contains(category)) // If we have it cached
{ // return it
}
}
-QRect KListView::Private::visualRect(const QModelIndex &index)
+QRect KCategorizedView::Private::visualRect(const QModelIndex &index)
{
QModelIndex mappedIndex = proxyModel->mapToSource(index);
return retRect;
}
-QRect KListView::Private::categoryVisualRect(const QString &category)
+QRect KCategorizedView::Private::categoryVisualRect(const QString &category)
{
QRect retRect = cachedRectCategory(category);
int dx = -listView->horizontalOffset();
return retRect;
}
-void KListView::Private::drawNewCategory(const QModelIndex &index,
+void KCategorizedView::Private::drawNewCategory(const QModelIndex &index,
int sortRole,
const QStyleOption &option,
QPainter *painter)
}
-void KListView::Private::updateScrollbars()
+void KCategorizedView::Private::updateScrollbars()
{
int lastItemBottom = cachedRectIndex(lastIndex).bottom() +
listView->spacing() - listView->viewport()->height();
listView->verticalScrollBar()->setRange(0, lastItemBottom);
}
-void KListView::Private::drawDraggedItems(QPainter *painter)
+void KCategorizedView::Private::drawDraggedItems(QPainter *painter)
{
QStyleOptionViewItemV3 option = listView->viewOptions();
option.state &= ~QStyle::State_MouseOver;
}
}
-void KListView::Private::drawDraggedItems()
+void KCategorizedView::Private::drawDraggedItems()
{
QRect rectToUpdate;
QRect currentRect;
//==============================================================================
-KListView::KListView(QWidget *parent)
+KCategorizedView::KCategorizedView(QWidget *parent)
: QListView(parent)
, d(new Private(this))
{
}
-KListView::~KListView()
+KCategorizedView::~KCategorizedView()
{
delete d;
}
-void KListView::setModel(QAbstractItemModel *model)
+void KCategorizedView::setModel(QAbstractItemModel *model)
{
d->lastSelection = QItemSelection();
d->currentViewIndex = QModelIndex();
}
}
-QRect KListView::visualRect(const QModelIndex &index) const
+QRect KCategorizedView::visualRect(const QModelIndex &index) const
{
- if ((viewMode() != KListView::IconMode) || !d->proxyModel ||
+ if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
!d->itemCategorizer)
{
return QListView::visualRect(index);
return d->visualRect(index);
}
-KItemCategorizer *KListView::itemCategorizer() const
+KItemCategorizer *KCategorizedView::itemCategorizer() const
{
return d->itemCategorizer;
}
-void KListView::setItemCategorizer(KItemCategorizer *itemCategorizer)
+void KCategorizedView::setItemCategorizer(KItemCategorizer *itemCategorizer)
{
d->lastSelection = QItemSelection();
d->currentViewIndex = QModelIndex();
}
}
-QModelIndex KListView::indexAt(const QPoint &point) const
+QModelIndex KCategorizedView::indexAt(const QPoint &point) const
{
- if ((viewMode() != KListView::IconMode) || !d->proxyModel ||
+ if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
!d->itemCategorizer)
{
return QListView::indexAt(point);
return index;
}
-void KListView::reset()
+void KCategorizedView::reset()
{
QListView::reset();
d->mouseButtonPressed = false;
}
-void KListView::paintEvent(QPaintEvent *event)
+void KCategorizedView::paintEvent(QPaintEvent *event)
{
- if ((viewMode() != KListView::IconMode) || !d->proxyModel ||
+ if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
!d->itemCategorizer)
{
QListView::paintEvent(event);
painter.restore();
}
-void KListView::resizeEvent(QResizeEvent *event)
+void KCategorizedView::resizeEvent(QResizeEvent *event)
{
QListView::resizeEvent(event);
d->categoriesPosition.clear();
d->forcedSelectionPosition = 0;
- if ((viewMode() != KListView::IconMode) || !d->proxyModel ||
+ if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
!d->itemCategorizer)
{
return;
d->updateScrollbars();
}
-void KListView::setSelection(const QRect &rect,
+void KCategorizedView::setSelection(const QRect &rect,
QItemSelectionModel::SelectionFlags flags)
{
- if ((viewMode() != KListView::IconMode) || !d->proxyModel ||
+ if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
!d->itemCategorizer)
{
QListView::setSelection(rect, flags);
selectionModel()->select(selection, flags);
}
-void KListView::mouseMoveEvent(QMouseEvent *event)
+void KCategorizedView::mouseMoveEvent(QMouseEvent *event)
{
QListView::mouseMoveEvent(event);
- if ((viewMode() != KListView::IconMode) || !d->proxyModel ||
+ if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
!d->itemCategorizer)
{
return;
}
}
-void KListView::mousePressEvent(QMouseEvent *event)
+void KCategorizedView::mousePressEvent(QMouseEvent *event)
{
d->dragLeftViewport = false;
QListView::mousePressEvent(event);
}
-void KListView::mouseReleaseEvent(QMouseEvent *event)
+void KCategorizedView::mouseReleaseEvent(QMouseEvent *event)
{
d->mouseButtonPressed = false;
QListView::mouseReleaseEvent(event);
- if ((viewMode() != KListView::IconMode) || !d->proxyModel ||
+ if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
!d->itemCategorizer)
{
return;
viewport()->update(d->categoryVisualRect(d->hoveredCategory));
}
-void KListView::leaveEvent(QEvent *event)
+void KCategorizedView::leaveEvent(QEvent *event)
{
d->hovered = QModelIndex();
d->hoveredCategory = QString();
QListView::leaveEvent(event);
}
-void KListView::startDrag(Qt::DropActions supportedActions)
+void KCategorizedView::startDrag(Qt::DropActions supportedActions)
{
QListView::startDrag(supportedActions);
viewport()->update(d->lastDraggedItemsRect);
}
-void KListView::dragMoveEvent(QDragMoveEvent *event)
+void KCategorizedView::dragMoveEvent(QDragMoveEvent *event)
{
d->mousePosition = event->pos();
d->dragLeftViewport = false;
- if ((viewMode() != KListView::IconMode) || !d->proxyModel ||
+ if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
!d->itemCategorizer)
{
QListView::dragMoveEvent(event);
d->drawDraggedItems();
}
-void KListView::dragLeaveEvent(QDragLeaveEvent *event)
+void KCategorizedView::dragLeaveEvent(QDragLeaveEvent *event)
{
d->dragLeftViewport = true;
QListView::dragLeaveEvent(event);
}
-QModelIndex KListView::moveCursor(CursorAction cursorAction,
+QModelIndex KCategorizedView::moveCursor(CursorAction cursorAction,
Qt::KeyboardModifiers modifiers)
{
- if ((viewMode() != KListView::IconMode) || !d->proxyModel ||
+ if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
!d->itemCategorizer)
{
return QListView::moveCursor(cursorAction, modifiers);
return QListView::moveCursor(cursorAction, modifiers);
}
-void KListView::rowsInserted(const QModelIndex &parent,
+void KCategorizedView::rowsInserted(const QModelIndex &parent,
int start,
int end)
{
QListView::rowsInserted(parent, start, end);
- if ((viewMode() != KListView::IconMode) || !d->proxyModel ||
+ if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
!d->itemCategorizer)
{
d->lastSelection = QItemSelection();
rowsInsertedArtifficial(parent, start, end);
}
-void KListView::rowsInsertedArtifficial(const QModelIndex &parent,
+void KCategorizedView::rowsInsertedArtifficial(const QModelIndex &parent,
int start,
int end)
{
d->updateScrollbars();
}
-void KListView::rowsRemoved(const QModelIndex &parent,
+void KCategorizedView::rowsRemoved(const QModelIndex &parent,
int start,
int end)
{
- if ((viewMode() == KListView::IconMode) && d->proxyModel &&
+ if ((viewMode() == KCategorizedView::IconMode) && d->proxyModel &&
d->itemCategorizer)
{
// Force the view to update all elements
}
}
-void KListView::updateGeometries()
+void KCategorizedView::updateGeometries()
{
- if ((viewMode() != KListView::IconMode) || !d->proxyModel ||
+ if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
!d->itemCategorizer)
{
QListView::updateGeometries();
QAbstractItemView::updateGeometries();
}
-void KListView::slotSortingRoleChanged()
+void KCategorizedView::slotSortingRoleChanged()
{
- if ((viewMode() == KListView::IconMode) && d->proxyModel &&
+ if ((viewMode() == KCategorizedView::IconMode) && d->proxyModel &&
d->itemCategorizer)
{
// Force the view to update all elements
}
}
-#include "klistview.moc"
+#include "kcategorizedview.moc"