Commit 468ea6c7 authored by Peter Penz's avatar Peter Penz
Browse files

Do a synchronous layout for dynamic item sizes when changing the geometry

This prevents a delayed update when resizing the window e.g. in the details
view. As no animated item position changes can happen for dynamic item sizes
the synchronous relayout is fine from a performance point of view.

BUG: 290953
FIXED-IN: 4.8.0
parent 30ebc032
......@@ -355,20 +355,55 @@ void KItemListView::setGeometry(const QRectF& rect)
return;
}
if (m_model->count() > 0) {
prepareLayoutForIncreasedItemCount(rect.size(), LayouterSize);
const QSizeF newSize = rect.size();
if (m_itemSize.isEmpty()) {
// The item size is dynamic:
// Changing the geometry does not require to do an expensive
// update of the visible-roles sizes, only the stretched sizes
// need to be adjusted to the new size.
updateStretchedVisibleRolesSizes();
if (m_useHeaderWidths) {
QSizeF dynamicItemSize = m_layouter->itemSize();
if (m_itemSize.width() < 0) {
const qreal requiredWidth = visibleRolesSizesWidthSum();
if (newSize.width() > requiredWidth) {
dynamicItemSize.setWidth(newSize.width());
}
const qreal headerWidth = qMax(newSize.width(), requiredWidth);
m_header->resize(headerWidth, m_header->size().height());
}
if (m_itemSize.height() < 0) {
const qreal requiredHeight = visibleRolesSizesHeightSum();
if (newSize.height() > requiredHeight) {
dynamicItemSize.setHeight(newSize.height());
}
// TODO: KItemListHeader is not prepared for vertical alignment
}
m_layouter->setItemSize(dynamicItemSize);
}
// Triggering a synchronous layout is fine from a performance point of view,
// as with dynamic item sizes no moving animation must be done.
m_layouter->setSize(newSize);
doLayout(Animation);
} else {
m_layouter->setSize(rect.size());
}
// The item size is not dynamic and most probably the geometry change results
// in animated position changes of the items. Trigger an asynchronous relayout
// with m_layoutTimer to prevent performance bottlenecks.
if (m_model->count() > 0) {
prepareLayoutForIncreasedItemCount(newSize, LayouterSize);
} else {
m_layouter->setSize(newSize);
}
if (!m_layoutTimer->isActive()) {
m_layoutTimer->start();
if (!m_layoutTimer->isActive()) {
m_layoutTimer->start();
}
}
// Changing the geometry does not require to do an expensive
// update of the visible-roles sizes, only the stretched sizes
// need to be adjusted to the new size.
updateStretchedVisibleRolesSizes();
}
int KItemListView::itemAt(const QPointF& pos) const
......@@ -707,34 +742,6 @@ QList<KItemListWidget*> KItemListView::visibleItemListWidgets() const
return m_visibleItems.values();
}
void KItemListView::resizeEvent(QGraphicsSceneResizeEvent* event)
{
QGraphicsWidget::resizeEvent(event);
if (m_itemSize.isEmpty() && m_useHeaderWidths) {
QSizeF dynamicItemSize = m_layouter->itemSize();
const QSizeF newSize = event->newSize();
if (m_itemSize.width() < 0) {
const qreal requiredWidth = visibleRolesSizesWidthSum();
if (newSize.width() > requiredWidth) {
dynamicItemSize.setWidth(newSize.width());
}
const qreal headerWidth = qMax(newSize.width(), requiredWidth);
m_header->resize(headerWidth, m_header->size().height());
}
if (m_itemSize.height() < 0) {
const qreal requiredHeight = visibleRolesSizesHeightSum();
if (newSize.height() > requiredHeight) {
dynamicItemSize.setHeight(newSize.height());
}
// TODO: KItemListHeader is not prepared for vertical alignment
}
m_layouter->setItemSize(dynamicItemSize);
}
}
void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
{
updateVisibleRolesSizes(itemRanges);
......
......@@ -286,9 +286,6 @@ protected:
QList<KItemListWidget*> visibleItemListWidgets() const;
/** @reimp */
virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
protected slots:
virtual void slotItemsInserted(const KItemRangeList& itemRanges);
virtual void slotItemsRemoved(const KItemRangeList& itemRanges);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment