#include <QCursor>
#include <QGraphicsSceneMouseEvent>
+#include <QGraphicsView>
#include <QPainter>
#include <QPropertyAnimation>
#include <QStyle>
QPixmap KItemListView::createDragPixmap(const QSet<int>& indexes) const
{
- Q_UNUSED(indexes);
- return QPixmap();
+ QPixmap pixmap;
+
+ if (indexes.count() == 1) {
+ KItemListWidget* item = m_visibleItems.value(indexes.toList().first());
+ QGraphicsView* graphicsView = scene()->views()[0];
+ if (item && graphicsView) {
+ pixmap = item->createDragPixmap(0, graphicsView);
+ }
+ } else {
+ // TODO: Not implemented yet. Probably extend the interface
+ // from KItemListWidget::createDragPixmap() to return a pixmap
+ // that can be used for multiple indexes.
+ }
+
+ return pixmap;
}
void KItemListView::editRole(int index, const QByteArray& role)
m_layouter->markAsDirty();
doLayout(animate ? Animation : NoAnimation);
+ if (m_itemSize.isEmpty()) {
+ updatePreferredColumnWidths();
+ }
+
onStyleOptionChanged(option, previousOption);
}
void KItemListView::onModelChanged(KItemModelBase* current, KItemModelBase* previous)
{
+ Q_UNUSED(current);
Q_UNUSED(previous);
-
- m_sizeHintResolver->clearCache();
- const int itemCount = current->count();
- if (itemCount > 0) {
- m_sizeHintResolver->itemsInserted(0, itemCount);
- }
}
void KItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous)
#endif
m_endTransactionAnimationHint = NoAnimation;
endTransaction();
+
updateSiblingsInformation();
}
+ if (m_grouped && (hasMultipleRanges || itemRanges.first().count < m_model->count())) {
+ // In case if items of the same group have been inserted before an item that
+ // currently represents the first item of the group, the group header of
+ // this item must be removed.
+ updateVisibleGroupHeaders();
+ }
+
if (useAlternateBackgrounds()) {
updateAlternateBackgrounds();
}
updateSiblingsInformation();
}
+ if (m_grouped && (hasMultipleRanges || m_model->count() > 0)) {
+ // In case if the first item of a group has been removed, the group header
+ // must be applied to the next visible item.
+ updateVisibleGroupHeaders();
+ }
+
if (useAlternateBackgrounds()) {
updateAlternateBackgrounds();
}
this, SLOT(slotSortRoleChanged(QByteArray,QByteArray)));
}
+ m_sizeHintResolver->clearCache();
+
m_model = model;
m_layouter->setModel(model);
m_grouped = model->groupedSorting();
this, SLOT(slotSortOrderChanged(Qt::SortOrder,Qt::SortOrder)));
connect(m_model, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
this, SLOT(slotSortRoleChanged(QByteArray,QByteArray)));
+
+ const int itemCount = m_model->count();
+ if (itemCount > 0) {
+ m_sizeHintResolver->itemsInserted(0, itemCount);
+ slotItemsInserted(KItemRangeList() << KItemRange(0, itemCount));
+ }
}
onModelChanged(model, previous);
bool startMovingAnim = false;
- // When having a grid the moving-animation should only be started, if it is done within
- // one row in the vertical scroll-orientation or one column in the horizontal scroll-orientation.
- // Otherwise instead of a moving-animation a create-animation on the new position will be used
- // instead. This is done to prevent overlapping (and confusing) moving-animations.
- const int index = widget->index();
- const Cell cell = m_visibleCells.value(index);
- if (cell.column >= 0 && cell.row >= 0) {
- if (scrollOrientation() == Qt::Vertical) {
- startMovingAnim = (cell.row == m_layouter->itemRow(index));
- } else {
- startMovingAnim = (cell.column == m_layouter->itemColumn(index));
+ if (m_itemSize.isEmpty()) {
+ // The items are not aligned in a grid but either as columns or rows.
+ startMovingAnim = !supportsItemExpanding();
+ } else {
+ // When having a grid the moving-animation should only be started, if it is done within
+ // one row in the vertical scroll-orientation or one column in the horizontal scroll-orientation.
+ // Otherwise instead of a moving-animation a create-animation on the new position will be used
+ // instead. This is done to prevent overlapping (and confusing) moving-animations.
+ const int index = widget->index();
+ const Cell cell = m_visibleCells.value(index);
+ if (cell.column >= 0 && cell.row >= 0) {
+ if (scrollOrientation() == Qt::Vertical) {
+ startMovingAnim = (cell.row == m_layouter->itemRow(index));
+ } else {
+ startMovingAnim = (cell.column == m_layouter->itemColumn(index));
+ }
}
}
}
const QList<QPair<int, QVariant> > groups = model()->groups();
- if (groups.isEmpty()) {
+ if (groups.isEmpty() || !groupHeaderCreator()) {
return;
}
// In the vertical scroll orientation the group header should always span
// the whole width no matter which temporary position the parent widget
// has. In this case the x-position and width will be adjusted manually.
- groupHeader->setPos(-widget->x(), -groupHeaderRect.height());
- groupHeader->resize(size().width(), groupHeaderRect.size().height());
+ const qreal x = -widget->x() - itemOffset();
+ const qreal width = maximumItemOffset();
+ groupHeader->setPos(x, -groupHeaderRect.height());
+ groupHeader->resize(width, groupHeaderRect.size().height());
} else {
groupHeader->setPos(groupHeaderRect.x() - itemRect.x(), -widget->y());
groupHeader->resize(groupHeaderRect.size());
// Stretch the first column to use the whole remaining width
firstColumnWidth += availableWidth - requiredWidth;
m_headerWidget->setColumnWidth(firstRole, firstColumnWidth);
- } else if (requiredWidth > availableWidth) {
+ } else if (requiredWidth > availableWidth && m_visibleRoles.count() > 1) {
// Shrink the first column to be able to show as much other
// columns as possible
qreal shrinkedFirstColumnWidth = firstColumnWidth - requiredWidth + availableWidth;
bool KItemListView::animateChangedItemCount(int changedItemCount) const
{
+ if (m_itemSize.isEmpty()) {
+ // We have only columns or only rows, but no grid: An animation is usually
+ // welcome when inserting or removing items.
+ return !supportsItemExpanding();
+ }
+
if (m_layouter->size().isEmpty() || m_layouter->itemSize().isEmpty()) {
return false;
}