Better looking categories. Thanks to Aurélien Gâteau for the original patch.

CCMAIL: kde-core-devel@kde.org

svn path=/trunk/KDE/kdebase/apps/; revision=755674
This commit is contained in:
Rafael Fernández López 2008-01-02 01:21:39 +00:00
parent c6a4a3aa06
commit 743bec3751
5 changed files with 44 additions and 49 deletions

View file

@ -118,9 +118,9 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
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());
@ -134,15 +134,15 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
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;
@ -241,14 +241,14 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
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)));
}
@ -259,9 +259,23 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
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;
}

View file

@ -39,7 +39,7 @@ public:
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

View file

@ -129,12 +129,12 @@ QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index)
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();
@ -189,7 +189,7 @@ QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index)
retRect.setTop(retRect.top() +
(rowsInt * itemHeight) +
categoryDrawer->categoryHeight(listView->viewOptions()) +
categoryDrawer->categoryHeight(index, listView->viewOptions()) +
listView->spacing() * 2);
if (listView->gridSize().isEmpty())
@ -273,7 +273,7 @@ QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &cat
retRect.setTop(retRect.top() +
(rowsInt * itemHeight) +
categoryDrawer->categoryHeight(listView->viewOptions()) +
categoryDrawer->categoryHeight(index, listView->viewOptions()) +
listView->spacing() * 2);
if (listView->gridSize().isEmpty())
@ -283,7 +283,7 @@ QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &cat
}
}
retRect.setHeight(categoryDrawer->categoryHeight(listView->viewOptions()));
retRect.setHeight(categoryDrawer->categoryHeight(index, listView->viewOptions()));
return retRect;
}

View file

@ -35,7 +35,7 @@ KCategoryDrawer::~KCategoryDrawer()
}
void KCategoryDrawer::drawCategory(const QModelIndex &index,
int sortRole,
int /*sortRole*/,
const QStyleOption &option,
QPainter *painter) const
{
@ -55,24 +55,6 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
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);
@ -103,15 +85,13 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
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());
@ -120,18 +100,19 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
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 */;
}

View file

@ -46,7 +46,7 @@ public:
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