mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
Separate width and height info in the layouting code
By separating the width and height info, we can save some unnecessary overhead in terms of memory and CPU cycles, and make the calculation of the height of a row (or the width of a column in Compact View) a bit simpler. To achieve this, this patch extends the concept of "logical rows" (which are actually columns in Compact View) to "logical width" and "logical height" (which is the actual height and width, respectively, in Compact View). The distinction between rows/columns and "logical" rows/columns may be a bit confusing, but the confusion is already in the current code, and I hope that it will be mitigated a bit by prefixing the corresponding variables with "logical". REVIEW: 118454
This commit is contained in:
parent
90e27974a4
commit
e07468c784
|
@ -459,9 +459,9 @@ int KItemListView::lastVisibleIndex() const
|
||||||
return m_layouter->lastVisibleIndex();
|
return m_layouter->lastVisibleIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KItemListView::calculateItemSizeHints(QVector<QSizeF>& sizeHints) const
|
void KItemListView::calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint) const
|
||||||
{
|
{
|
||||||
widgetCreator()->calculateItemSizeHints(sizeHints, this);
|
widgetCreator()->calculateItemSizeHints(logicalHeightHints, logicalWidthHint, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KItemListView::setSupportsItemExpanding(bool supportsExpanding)
|
void KItemListView::setSupportsItemExpanding(bool supportsExpanding)
|
||||||
|
|
|
@ -194,12 +194,14 @@ public:
|
||||||
int lastVisibleIndex() const;
|
int lastVisibleIndex() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Required size for all items in the model.
|
* @return Calculates the required size for all items in the model.
|
||||||
* The returned value might be larger than KItemListView::itemSize().
|
* It might be larger than KItemListView::itemSize().
|
||||||
* In this case the layout grid will be stretched to assure an
|
* In this case the layout grid will be stretched to assure an
|
||||||
* unclipped item.
|
* unclipped item.
|
||||||
|
* NOTE: the logical height (width) is actually the
|
||||||
|
* width (height) if the scroll orientation is Qt::Vertical!
|
||||||
*/
|
*/
|
||||||
void calculateItemSizeHints(QVector<QSizeF>& sizeHints) const;
|
void calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set to true, items having child-items can be expanded to show the child-items as
|
* If set to true, items having child-items can be expanded to show the child-items as
|
||||||
|
@ -805,7 +807,7 @@ public:
|
||||||
|
|
||||||
virtual void recycle(KItemListWidget* widget);
|
virtual void recycle(KItemListWidget* widget);
|
||||||
|
|
||||||
virtual void calculateItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const = 0;
|
virtual void calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const = 0;
|
||||||
|
|
||||||
virtual qreal preferredRoleColumnWidth(const QByteArray& role,
|
virtual qreal preferredRoleColumnWidth(const QByteArray& role,
|
||||||
int index,
|
int index,
|
||||||
|
@ -824,7 +826,7 @@ public:
|
||||||
|
|
||||||
virtual KItemListWidget* create(KItemListView* view);
|
virtual KItemListWidget* create(KItemListView* view);
|
||||||
|
|
||||||
virtual void calculateItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const;
|
virtual void calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
|
||||||
|
|
||||||
virtual qreal preferredRoleColumnWidth(const QByteArray& role,
|
virtual qreal preferredRoleColumnWidth(const QByteArray& role,
|
||||||
int index,
|
int index,
|
||||||
|
@ -857,9 +859,9 @@ KItemListWidget* KItemListWidgetCreator<T>::create(KItemListView* view)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void KItemListWidgetCreator<T>::calculateItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const
|
void KItemListWidgetCreator<T>::calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
|
||||||
{
|
{
|
||||||
return m_informant->calculateItemSizeHints(sizeHints, view);
|
return m_informant->calculateItemSizeHints(logicalHeightHints, logicalWidthHint, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
KItemListWidgetInformant();
|
KItemListWidgetInformant();
|
||||||
virtual ~KItemListWidgetInformant();
|
virtual ~KItemListWidgetInformant();
|
||||||
|
|
||||||
virtual void calculateItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const = 0;
|
virtual void calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const = 0;
|
||||||
|
|
||||||
virtual qreal preferredRoleColumnWidth(const QByteArray& role,
|
virtual qreal preferredRoleColumnWidth(const QByteArray& role,
|
||||||
int index,
|
int index,
|
||||||
|
|
|
@ -55,19 +55,19 @@ KStandardItemListWidgetInformant::~KStandardItemListWidgetInformant()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void KStandardItemListWidgetInformant::calculateItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const
|
void KStandardItemListWidgetInformant::calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
|
||||||
{
|
{
|
||||||
switch (static_cast<const KStandardItemListView*>(view)->itemLayout()) {
|
switch (static_cast<const KStandardItemListView*>(view)->itemLayout()) {
|
||||||
case KStandardItemListWidget::IconsLayout:
|
case KStandardItemListWidget::IconsLayout:
|
||||||
calculateIconsLayoutItemSizeHints(sizeHints, view);
|
calculateIconsLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KStandardItemListWidget::CompactLayout:
|
case KStandardItemListWidget::CompactLayout:
|
||||||
calculateCompactLayoutItemSizeHints(sizeHints, view);
|
calculateCompactLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KStandardItemListWidget::DetailsLayout:
|
case KStandardItemListWidget::DetailsLayout:
|
||||||
calculateDetailsLayoutItemSizeHints(sizeHints, view);
|
calculateDetailsLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -138,7 +138,7 @@ QFont KStandardItemListWidgetInformant::customizedFontForLinks(const QFont& base
|
||||||
return baseFont;
|
return baseFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const
|
void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
|
||||||
{
|
{
|
||||||
const KItemListStyleOption& option = view->styleOption();
|
const KItemListStyleOption& option = view->styleOption();
|
||||||
const QFont& normalFont = option.font;
|
const QFont& normalFont = option.font;
|
||||||
|
@ -154,8 +154,8 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector
|
||||||
QTextOption textOption(Qt::AlignHCenter);
|
QTextOption textOption(Qt::AlignHCenter);
|
||||||
textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
|
textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
|
||||||
|
|
||||||
for (int index = 0; index < sizeHints.count(); ++index) {
|
for (int index = 0; index < logicalHeightHints.count(); ++index) {
|
||||||
if (!sizeHints.at(index).isEmpty()) {
|
if (logicalHeightHints.at(index) > 0.0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,11 +186,13 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector
|
||||||
// Add one line for each additional information
|
// Add one line for each additional information
|
||||||
textHeight += additionalRolesSpacing;
|
textHeight += additionalRolesSpacing;
|
||||||
|
|
||||||
sizeHints[index] = QSizeF(itemWidth, textHeight + spacingAndIconHeight);
|
logicalHeightHints[index] = textHeight + spacingAndIconHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logicalWidthHint = itemWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const
|
void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
|
||||||
{
|
{
|
||||||
const KItemListStyleOption& option = view->styleOption();
|
const KItemListStyleOption& option = view->styleOption();
|
||||||
const QFontMetrics& normalFontMetrics = option.fontMetrics;
|
const QFontMetrics& normalFontMetrics = option.fontMetrics;
|
||||||
|
@ -204,8 +206,8 @@ void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVect
|
||||||
|
|
||||||
const QFontMetrics linkFontMetrics(customizedFontForLinks(option.font));
|
const QFontMetrics linkFontMetrics(customizedFontForLinks(option.font));
|
||||||
|
|
||||||
for (int index = 0; index < sizeHints.count(); ++index) {
|
for (int index = 0; index < logicalHeightHints.count(); ++index) {
|
||||||
if (!sizeHints.at(index).isEmpty()) {
|
if (logicalHeightHints.at(index) > 0.0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,22 +234,18 @@ void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVect
|
||||||
width = maxWidth;
|
width = maxWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
sizeHints[index] = QSizeF(width, height);
|
logicalHeightHints[index] = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logicalWidthHint = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KStandardItemListWidgetInformant::calculateDetailsLayoutItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const
|
void KStandardItemListWidgetInformant::calculateDetailsLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
|
||||||
{
|
{
|
||||||
const KItemListStyleOption& option = view->styleOption();
|
const KItemListStyleOption& option = view->styleOption();
|
||||||
const qreal height = option.padding * 2 + qMax(option.iconSize, option.fontMetrics.height());
|
const qreal height = option.padding * 2 + qMax(option.iconSize, option.fontMetrics.height());
|
||||||
|
logicalHeightHints.fill(height);
|
||||||
for (int index = 0; index < sizeHints.count(); ++index) {
|
logicalWidthHint = -1.0;
|
||||||
if (!sizeHints.at(index).isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
sizeHints[index] = QSizeF(-1, height);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KStandardItemListWidget::KStandardItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) :
|
KStandardItemListWidget::KStandardItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) :
|
||||||
|
|
|
@ -38,7 +38,7 @@ public:
|
||||||
KStandardItemListWidgetInformant();
|
KStandardItemListWidgetInformant();
|
||||||
virtual ~KStandardItemListWidgetInformant();
|
virtual ~KStandardItemListWidgetInformant();
|
||||||
|
|
||||||
virtual void calculateItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const;
|
virtual void calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
|
||||||
|
|
||||||
virtual qreal preferredRoleColumnWidth(const QByteArray& role,
|
virtual qreal preferredRoleColumnWidth(const QByteArray& role,
|
||||||
int index,
|
int index,
|
||||||
|
@ -73,9 +73,9 @@ protected:
|
||||||
*/
|
*/
|
||||||
virtual QFont customizedFontForLinks(const QFont& baseFont) const;
|
virtual QFont customizedFontForLinks(const QFont& baseFont) const;
|
||||||
|
|
||||||
void calculateIconsLayoutItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const;
|
void calculateIconsLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
|
||||||
void calculateCompactLayoutItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const;
|
void calculateCompactLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
|
||||||
void calculateDetailsLayoutItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const;
|
void calculateDetailsLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
|
||||||
|
|
||||||
friend class KStandardItemListWidget; // Accesses roleText()
|
friend class KStandardItemListWidget; // Accesses roleText()
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
|
|
||||||
KItemListSizeHintResolver::KItemListSizeHintResolver(const KItemListView* itemListView) :
|
KItemListSizeHintResolver::KItemListSizeHintResolver(const KItemListView* itemListView) :
|
||||||
m_itemListView(itemListView),
|
m_itemListView(itemListView),
|
||||||
m_sizeHintCache(),
|
m_logicalHeightHintCache(),
|
||||||
|
m_logicalWidthHint(0.0),
|
||||||
m_needsResolving(false)
|
m_needsResolving(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -35,7 +36,7 @@ KItemListSizeHintResolver::~KItemListSizeHintResolver()
|
||||||
QSizeF KItemListSizeHintResolver::sizeHint(int index)
|
QSizeF KItemListSizeHintResolver::sizeHint(int index)
|
||||||
{
|
{
|
||||||
updateCache();
|
updateCache();
|
||||||
return m_sizeHintCache.at(index);
|
return QSizeF(m_logicalWidthHint, m_logicalHeightHintCache.at(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges)
|
void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges)
|
||||||
|
@ -45,15 +46,15 @@ void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges)
|
||||||
insertedCount += range.count;
|
insertedCount += range.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int currentCount = m_sizeHintCache.count();
|
const int currentCount = m_logicalHeightHintCache.count();
|
||||||
m_sizeHintCache.reserve(currentCount + insertedCount);
|
m_logicalHeightHintCache.reserve(currentCount + insertedCount);
|
||||||
|
|
||||||
// We build the new list from the end to the beginning to mimize the
|
// We build the new list from the end to the beginning to mimize the
|
||||||
// number of moves.
|
// number of moves.
|
||||||
m_sizeHintCache.insert(m_sizeHintCache.end(), insertedCount, QSizeF());
|
m_logicalHeightHintCache.insert(m_logicalHeightHintCache.end(), insertedCount, 0.0);
|
||||||
|
|
||||||
int sourceIndex = currentCount - 1;
|
int sourceIndex = currentCount - 1;
|
||||||
int targetIndex = m_sizeHintCache.count() - 1;
|
int targetIndex = m_logicalHeightHintCache.count() - 1;
|
||||||
int itemsToInsertBeforeCurrentRange = insertedCount;
|
int itemsToInsertBeforeCurrentRange = insertedCount;
|
||||||
|
|
||||||
for (int rangeIndex = itemRanges.count() - 1; rangeIndex >= 0; --rangeIndex) {
|
for (int rangeIndex = itemRanges.count() - 1; rangeIndex >= 0; --rangeIndex) {
|
||||||
|
@ -62,33 +63,33 @@ void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges)
|
||||||
|
|
||||||
// First: move all existing items that must be put behind 'range'.
|
// First: move all existing items that must be put behind 'range'.
|
||||||
while (targetIndex >= itemsToInsertBeforeCurrentRange + range.index + range.count) {
|
while (targetIndex >= itemsToInsertBeforeCurrentRange + range.index + range.count) {
|
||||||
m_sizeHintCache[targetIndex] = m_sizeHintCache[sourceIndex];
|
m_logicalHeightHintCache[targetIndex] = m_logicalHeightHintCache[sourceIndex];
|
||||||
--sourceIndex;
|
--sourceIndex;
|
||||||
--targetIndex;
|
--targetIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then: insert QSizeF() for the items which are inserted into 'range'.
|
// Then: insert QSizeF() for the items which are inserted into 'range'.
|
||||||
while (targetIndex >= itemsToInsertBeforeCurrentRange + range.index) {
|
while (targetIndex >= itemsToInsertBeforeCurrentRange + range.index) {
|
||||||
m_sizeHintCache[targetIndex] = QSizeF();
|
m_logicalHeightHintCache[targetIndex] = 0.0;
|
||||||
--targetIndex;
|
--targetIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_needsResolving = true;
|
m_needsResolving = true;
|
||||||
|
|
||||||
Q_ASSERT(m_sizeHintCache.count() == m_itemListView->model()->count());
|
Q_ASSERT(m_logicalHeightHintCache.count() == m_itemListView->model()->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
void KItemListSizeHintResolver::itemsRemoved(const KItemRangeList& itemRanges)
|
void KItemListSizeHintResolver::itemsRemoved(const KItemRangeList& itemRanges)
|
||||||
{
|
{
|
||||||
const QVector<QSizeF>::iterator begin = m_sizeHintCache.begin();
|
const QVector<qreal>::iterator begin = m_logicalHeightHintCache.begin();
|
||||||
const QVector<QSizeF>::iterator end = m_sizeHintCache.end();
|
const QVector<qreal>::iterator end = m_logicalHeightHintCache.end();
|
||||||
|
|
||||||
KItemRangeList::const_iterator rangeIt = itemRanges.constBegin();
|
KItemRangeList::const_iterator rangeIt = itemRanges.constBegin();
|
||||||
const KItemRangeList::const_iterator rangeEnd = itemRanges.constEnd();
|
const KItemRangeList::const_iterator rangeEnd = itemRanges.constEnd();
|
||||||
|
|
||||||
QVector<QSizeF>::iterator destIt = begin + rangeIt->index;
|
QVector<qreal>::iterator destIt = begin + rangeIt->index;
|
||||||
QVector<QSizeF>::iterator srcIt = destIt + rangeIt->count;
|
QVector<qreal>::iterator srcIt = destIt + rangeIt->count;
|
||||||
|
|
||||||
++rangeIt;
|
++rangeIt;
|
||||||
|
|
||||||
|
@ -104,33 +105,33 @@ void KItemListSizeHintResolver::itemsRemoved(const KItemRangeList& itemRanges)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sizeHintCache.erase(destIt, end);
|
m_logicalHeightHintCache.erase(destIt, end);
|
||||||
|
|
||||||
// Note that the cache size might temporarily not match the model size if
|
// Note that the cache size might temporarily not match the model size if
|
||||||
// this function is called from KItemListView::setModel() to empty the cache.
|
// this function is called from KItemListView::setModel() to empty the cache.
|
||||||
if (!m_sizeHintCache.isEmpty() && m_itemListView->model()) {
|
if (!m_logicalHeightHintCache.isEmpty() && m_itemListView->model()) {
|
||||||
Q_ASSERT(m_sizeHintCache.count() == m_itemListView->model()->count());
|
Q_ASSERT(m_logicalHeightHintCache.count() == m_itemListView->model()->count());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KItemListSizeHintResolver::itemsMoved(const KItemRange& range, const QList<int>& movedToIndexes)
|
void KItemListSizeHintResolver::itemsMoved(const KItemRange& range, const QList<int>& movedToIndexes)
|
||||||
{
|
{
|
||||||
QVector<QSizeF> newSizeHintCache(m_sizeHintCache);
|
QVector<qreal> newLogicalHeightHintCache(m_logicalHeightHintCache);
|
||||||
|
|
||||||
const int movedRangeEnd = range.index + range.count;
|
const int movedRangeEnd = range.index + range.count;
|
||||||
for (int i = range.index; i < movedRangeEnd; ++i) {
|
for (int i = range.index; i < movedRangeEnd; ++i) {
|
||||||
const int newIndex = movedToIndexes.at(i - range.index);
|
const int newIndex = movedToIndexes.at(i - range.index);
|
||||||
newSizeHintCache[newIndex] = m_sizeHintCache.at(i);
|
newLogicalHeightHintCache[newIndex] = m_logicalHeightHintCache.at(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sizeHintCache = newSizeHintCache;
|
m_logicalHeightHintCache = newLogicalHeightHintCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KItemListSizeHintResolver::itemsChanged(int index, int count, const QSet<QByteArray>& roles)
|
void KItemListSizeHintResolver::itemsChanged(int index, int count, const QSet<QByteArray>& roles)
|
||||||
{
|
{
|
||||||
Q_UNUSED(roles);
|
Q_UNUSED(roles);
|
||||||
while (count) {
|
while (count) {
|
||||||
m_sizeHintCache[index] = QSizeF();
|
m_logicalHeightHintCache[index] = 0.0;
|
||||||
++index;
|
++index;
|
||||||
--count;
|
--count;
|
||||||
}
|
}
|
||||||
|
@ -140,14 +141,14 @@ void KItemListSizeHintResolver::itemsChanged(int index, int count, const QSet<QB
|
||||||
|
|
||||||
void KItemListSizeHintResolver::clearCache()
|
void KItemListSizeHintResolver::clearCache()
|
||||||
{
|
{
|
||||||
m_sizeHintCache.fill(QSizeF());
|
m_logicalHeightHintCache.fill(0.0);
|
||||||
m_needsResolving = true;
|
m_needsResolving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KItemListSizeHintResolver::updateCache()
|
void KItemListSizeHintResolver::updateCache()
|
||||||
{
|
{
|
||||||
if (m_needsResolving) {
|
if (m_needsResolving) {
|
||||||
m_itemListView->calculateItemSizeHints(m_sizeHintCache);
|
m_itemListView->calculateItemSizeHints(m_logicalHeightHintCache, m_logicalWidthHint);
|
||||||
m_needsResolving = false;
|
m_needsResolving = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const KItemListView* m_itemListView;
|
const KItemListView* m_itemListView;
|
||||||
mutable QVector<QSizeF> m_sizeHintCache;
|
mutable QVector<qreal> m_logicalHeightHintCache;
|
||||||
|
mutable qreal m_logicalWidthHint;
|
||||||
bool m_needsResolving;
|
bool m_needsResolving;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,7 @@ QRectF KItemListViewLayouter::itemRect(int index) const
|
||||||
// to get the physical horizontal direction
|
// to get the physical horizontal direction
|
||||||
QPointF pos(y, x);
|
QPointF pos(y, x);
|
||||||
pos.rx() -= m_scrollOffset;
|
pos.rx() -= m_scrollOffset;
|
||||||
|
sizeHint.transpose();
|
||||||
return QRectF(pos, sizeHint);
|
return QRectF(pos, sizeHint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +283,9 @@ QRectF KItemListViewLayouter::groupHeaderRect(int index) const
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const qreal itemWidth = m_sizeHintResolver->sizeHint(index).width();
|
const qreal itemWidth = (m_scrollOrientation == Qt::Vertical)
|
||||||
|
? m_sizeHintResolver->sizeHint(index).width()
|
||||||
|
: m_sizeHintResolver->sizeHint(index).height();
|
||||||
|
|
||||||
if (itemWidth > headerWidth) {
|
if (itemWidth > headerWidth) {
|
||||||
headerWidth = itemWidth;
|
headerWidth = itemWidth;
|
||||||
|
@ -461,7 +464,7 @@ void KItemListViewLayouter::doLayout()
|
||||||
while (index < itemCount && column < m_columnCount) {
|
while (index < itemCount && column < m_columnCount) {
|
||||||
qreal requiredItemHeight = itemSize.height();
|
qreal requiredItemHeight = itemSize.height();
|
||||||
const QSizeF sizeHint = m_sizeHintResolver->sizeHint(index);
|
const QSizeF sizeHint = m_sizeHintResolver->sizeHint(index);
|
||||||
const qreal sizeHintHeight = horizontalScrolling ? sizeHint.width() : sizeHint.height();
|
const qreal sizeHintHeight = sizeHint.height();
|
||||||
if (sizeHintHeight > requiredItemHeight) {
|
if (sizeHintHeight > requiredItemHeight) {
|
||||||
requiredItemHeight = sizeHintHeight;
|
requiredItemHeight = sizeHintHeight;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue