QPainterPath path;
path.addRect(option.rect.left(),
- option.rect.bottom() - 2,
+ option.rect.bottom() - 1,
option.rect.width(),
- 2);
+ 1);
QLinearGradient gradient(option.rect.topLeft(),
option.rect.bottomRight());
if (option.direction == Qt::LeftToRight)
{
- opt.rect.setLeft(opt.rect.left() + (iconSize / 4));
- starRect.setLeft(starRect.left() + (iconSize / 4));
- starRect.setRight(starRect.right() + (iconSize / 4));
+ opt.rect.setLeft(opt.rect.left());
+ starRect.setLeft(starRect.left());
+ starRect.setRight(starRect.right());
}
else
{
- opt.rect.setRight(opt.rect.width() - (iconSize / 4));
- starRect.setLeft(starRect.width() - iconSize);
- starRect.setRight(starRect.width() - (iconSize / 4));
+ opt.rect.setRight(opt.rect.width());
+ starRect.setLeft(starRect.width());
+ starRect.setRight(starRect.width());
}
bool paintIcon = true;
if (paintText) {
opt.rect.setTop(option.rect.top() + (iconSize / 4));
- opt.rect.setBottom(opt.rect.bottom() - 2);
+ opt.rect.setBottom(opt.rect.bottom() - 1);
painter->setPen(color);
QRect textRect = opt.rect;
if (option.direction == Qt::RightToLeft)
{
- textRect.setWidth(textRect.width() - (paintIcon ? icon.width() + (iconSize / 2)
+ textRect.setWidth(textRect.width() - (paintIcon ? icon.width() + (iconSize / 4)
: -(iconSize / 4)));
}
painter->restore();
}
-int DolphinCategoryDrawer::categoryHeight(const QStyleOption &option) const
+int DolphinCategoryDrawer::categoryHeight(const QModelIndex &index, const QStyleOption &option) const
{
int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small);
+ int heightWithoutIcon = option.fontMetrics.height() + (iconSize / 4) * 2 + 1; /* 1 pixel-width gradient */
+ bool paintIcon;
- return qMax(option.fontMetrics.height() + (iconSize / 4) * 2 + 2, iconSize + (iconSize / 4) * 2 + 2) /* 2 gradient */;
+ switch (index.column()) {
+ case KDirModel::Owner:
+ case KDirModel::Type:
+ paintIcon = true;
+ break;
+ default:
+ paintIcon = false;
+ }
+
+ if (paintIcon)
+ return qMax(heightWithoutIcon, iconSize + (iconSize / 4) * 2 + 1) /* 1 pixel-width gradient */;
+
+ return heightWithoutIcon;
}
virtual void drawCategory(const QModelIndex &index, int sortRole,
const QStyleOption &option, QPainter *painter) const;
- virtual int categoryHeight(const QStyleOption &option) const;
+ virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) const;
};
#endif // DOLPHINCATEGORYDRAWER_H
if (listView->layoutDirection() == Qt::LeftToRight)
{
retRect = QRect(listView->spacing(), listView->spacing() * 2 +
- categoryDrawer->categoryHeight(listView->viewOptions()), 0, 0);
+ categoryDrawer->categoryHeight(index, listView->viewOptions()), 0, 0);
}
else
{
retRect = QRect(listView->viewport()->width() - listView->spacing(), listView->spacing() * 2 +
- categoryDrawer->categoryHeight(listView->viewOptions()), 0, 0);
+ categoryDrawer->categoryHeight(index, listView->viewOptions()), 0, 0);
}
int viewportWidth = listView->viewport()->width() - listView->spacing();
retRect.setTop(retRect.top() +
(rowsInt * itemHeight) +
- categoryDrawer->categoryHeight(listView->viewOptions()) +
+ categoryDrawer->categoryHeight(index, listView->viewOptions()) +
listView->spacing() * 2);
if (listView->gridSize().isEmpty())
retRect.setTop(retRect.top() +
(rowsInt * itemHeight) +
- categoryDrawer->categoryHeight(listView->viewOptions()) +
+ categoryDrawer->categoryHeight(index, listView->viewOptions()) +
listView->spacing() * 2);
if (listView->gridSize().isEmpty())
}
}
- retRect.setHeight(categoryDrawer->categoryHeight(listView->viewOptions()));
+ retRect.setHeight(categoryDrawer->categoryHeight(index, listView->viewOptions()));
return retRect;
}
}
void KCategoryDrawer::drawCategory(const QModelIndex &index,
- int sortRole,
+ int /*sortRole*/,
const QStyleOption &option,
QPainter *painter) const
{
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
- QStyleOptionButton opt;
-
- opt.rect = option.rect;
- opt.palette = option.palette;
- opt.direction = option.direction;
- opt.text = category;
-
- int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small);
-
- if (option.direction == Qt::LeftToRight)
- {
- opt.rect.setLeft(opt.rect.left() + (iconSize / 4));
- }
- else
- {
- opt.rect.setRight(opt.rect.width() - (iconSize / 4));
- }
-
if (option.state & QStyle::State_Selected)
{
QColor selected = option.palette.color(QPalette::Highlight);
QFont painterFont = painter->font();
painterFont.setWeight(QFont::Bold);
- painterFont.setPointSize(painterFont.pointSize() + 2);
QFontMetrics metrics(painterFont);
painter->setFont(painterFont);
- QPainterPath path;
- path.addRect(option.rect.left(),
- option.rect.bottom() - 2,
- option.rect.width(),
- 2);
+ QRect lineRect(option.rect.left(),
+ option.rect.bottom() - 1,
+ option.rect.width(),
+ 1);
QLinearGradient gradient(option.rect.topLeft(),
option.rect.bottomRight());
gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
: 0, Qt::transparent);
- painter->setBrush(gradient);
- painter->fillPath(path, gradient);
+ painter->fillRect(lineRect, gradient);
painter->setPen(color);
- painter->drawText(opt.rect, Qt::AlignVCenter | Qt::AlignLeft,
+ painter->drawText(option.rect, Qt::AlignVCenter | Qt::AlignLeft,
metrics.elidedText(category, Qt::ElideRight, option.rect.width()));
painter->restore();
}
-int KCategoryDrawer::categoryHeight(const QStyleOption &option) const
+int KCategoryDrawer::categoryHeight(const QModelIndex &index, const QStyleOption &option) const
{
- return option.fontMetrics.height() + 6 /* 4 separator; 2 gradient */;
+ Q_UNUSED(index);
+
+ return option.fontMetrics.height() + 4 /* 3 separator; 1 gradient */;
}
const QStyleOption &option,
QPainter *painter) const;
- virtual int categoryHeight(const QStyleOption &option) const;
+ virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) const;
};
#endif // KCATEGORYDRAWER_H