#include "kstandarditemlistview.h"
-#include <KDebug>
-#include <KIconLoader>
#include "kstandarditemlistwidget.h"
-#include "kstandarditemlistgroupheader.h"
+
+#include <KIconLoader>
KStandardItemListView::KStandardItemListView(QGraphicsWidget* parent) :
KItemListView(parent),
{
setAcceptDrops(true);
setScrollOrientation(Qt::Vertical);
- setVisibleRoles(QList<QByteArray>() << "text");
+ setVisibleRoles({"text"});
}
KStandardItemListView::~KStandardItemListView()
const ItemLayout previous = m_itemLayout;
m_itemLayout = layout;
- switch (layout) {
- case IconsLayout:
- setScrollOrientation(Qt::Vertical);
- setSupportsItemExpanding(false);
- break;
- case DetailsLayout:
- setScrollOrientation(Qt::Vertical);
- setSupportsItemExpanding(true);
- break;
- case CompactLayout:
- setScrollOrientation(Qt::Horizontal);
- setSupportsItemExpanding(false);
- break;
- default:
- Q_ASSERT(false);
- break;
- }
+ setSupportsItemExpanding(itemLayoutSupportsItemExpanding(layout));
+ setScrollOrientation(layout == CompactLayout ? Qt::Horizontal : Qt::Vertical);
onItemLayoutChanged(layout, previous);
bool KStandardItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray>& changedRoles) const
{
+ // The only thing that can modify the item's size hint is the amount of space
+ // needed to display the text for the visible roles.
// Even if the icons have a different size they are always aligned within
// the area defined by KItemStyleOption.iconSize and hence result in no
// change of the item-size.
- const bool containsIconName = changedRoles.contains("iconName");
- const bool containsIconPixmap = changedRoles.contains("iconPixmap");
- const int count = changedRoles.count();
-
- const bool iconChanged = (containsIconName && containsIconPixmap && count == 2) ||
- (containsIconName && count == 1) ||
- (containsIconPixmap && count == 1);
- return !iconChanged;
+ foreach (const QByteArray& role, visibleRoles()) {
+ if (changedRoles.contains(role)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool KStandardItemListView::itemLayoutSupportsItemExpanding(ItemLayout layout) const
+{
+ return layout == DetailsLayout;
}
void KStandardItemListView::onItemLayoutChanged(ItemLayout current, ItemLayout previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
updateLayoutOfVisibleItems();
}
void KStandardItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
updateLayoutOfVisibleItems();
}
void KStandardItemListView::onSupportsItemExpandingChanged(bool supportsExpanding)
{
- Q_UNUSED(supportsExpanding);
+ Q_UNUSED(supportsExpanding)
updateLayoutOfVisibleItems();
}
void KStandardItemListView::polishEvent()
{
switch (m_itemLayout) {
- case IconsLayout: applyDefaultStyleOption(KIconLoader::SizeMedium, 2, 4, 8); break;
- case CompactLayout: applyDefaultStyleOption(KIconLoader::SizeSmall, 2, 8, 0); break;
- case DetailsLayout: applyDefaultStyleOption(KIconLoader::SizeSmall, 2, 0, 0); break;
+ case IconsLayout: applyDefaultStyleOption(style()->pixelMetric(QStyle::PM_LargeIconSize), 2, 4, 8); break;
+ case CompactLayout: applyDefaultStyleOption(style()->pixelMetric(QStyle::PM_SmallIconSize), 2, 8, 0); break;
+ case DetailsLayout: applyDefaultStyleOption(style()->pixelMetric(QStyle::PM_SmallIconSize), 2, 0, 0); break;
default: Q_ASSERT(false); break;
}
{
KItemListStyleOption option = styleOption();
- bool changed = false;
if (option.iconSize < 0) {
option.iconSize = iconSize;
- changed = true;
}
if (option.padding < 0) {
option.padding = padding;
- changed = true;
}
if (option.horizontalMargin < 0) {
option.horizontalMargin = horizontalMargin;
- changed = true;
}
if (option.verticalMargin < 0) {
option.verticalMargin = verticalMargin;
- changed = true;
}
- if (changed) {
- setStyleOption(option);
- }
+ setStyleOption(option);
}
void KStandardItemListView::updateLayoutOfVisibleItems()
}
}
-#include "kstandarditemlistview.moc"