mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
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:
parent
c6a4a3aa06
commit
743bec3751
5 changed files with 44 additions and 49 deletions
|
@ -118,9 +118,9 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
|
||||||
|
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
path.addRect(option.rect.left(),
|
path.addRect(option.rect.left(),
|
||||||
option.rect.bottom() - 2,
|
option.rect.bottom() - 1,
|
||||||
option.rect.width(),
|
option.rect.width(),
|
||||||
2);
|
1);
|
||||||
|
|
||||||
QLinearGradient gradient(option.rect.topLeft(),
|
QLinearGradient gradient(option.rect.topLeft(),
|
||||||
option.rect.bottomRight());
|
option.rect.bottomRight());
|
||||||
|
@ -134,15 +134,15 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
|
||||||
|
|
||||||
if (option.direction == Qt::LeftToRight)
|
if (option.direction == Qt::LeftToRight)
|
||||||
{
|
{
|
||||||
opt.rect.setLeft(opt.rect.left() + (iconSize / 4));
|
opt.rect.setLeft(opt.rect.left());
|
||||||
starRect.setLeft(starRect.left() + (iconSize / 4));
|
starRect.setLeft(starRect.left());
|
||||||
starRect.setRight(starRect.right() + (iconSize / 4));
|
starRect.setRight(starRect.right());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
opt.rect.setRight(opt.rect.width() - (iconSize / 4));
|
opt.rect.setRight(opt.rect.width());
|
||||||
starRect.setLeft(starRect.width() - iconSize);
|
starRect.setLeft(starRect.width());
|
||||||
starRect.setRight(starRect.width() - (iconSize / 4));
|
starRect.setRight(starRect.width());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool paintIcon = true;
|
bool paintIcon = true;
|
||||||
|
@ -241,14 +241,14 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
|
||||||
|
|
||||||
if (paintText) {
|
if (paintText) {
|
||||||
opt.rect.setTop(option.rect.top() + (iconSize / 4));
|
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);
|
painter->setPen(color);
|
||||||
|
|
||||||
QRect textRect = opt.rect;
|
QRect textRect = opt.rect;
|
||||||
|
|
||||||
if (option.direction == Qt::RightToLeft)
|
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)));
|
: -(iconSize / 4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,9 +259,23 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
|
||||||
painter->restore();
|
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 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
virtual void drawCategory(const QModelIndex &index, int sortRole,
|
virtual void drawCategory(const QModelIndex &index, int sortRole,
|
||||||
const QStyleOption &option, QPainter *painter) const;
|
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
|
#endif // DOLPHINCATEGORYDRAWER_H
|
||||||
|
|
|
@ -129,12 +129,12 @@ QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index)
|
||||||
if (listView->layoutDirection() == Qt::LeftToRight)
|
if (listView->layoutDirection() == Qt::LeftToRight)
|
||||||
{
|
{
|
||||||
retRect = QRect(listView->spacing(), listView->spacing() * 2 +
|
retRect = QRect(listView->spacing(), listView->spacing() * 2 +
|
||||||
categoryDrawer->categoryHeight(listView->viewOptions()), 0, 0);
|
categoryDrawer->categoryHeight(index, listView->viewOptions()), 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
retRect = QRect(listView->viewport()->width() - listView->spacing(), listView->spacing() * 2 +
|
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();
|
int viewportWidth = listView->viewport()->width() - listView->spacing();
|
||||||
|
@ -189,7 +189,7 @@ QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index)
|
||||||
|
|
||||||
retRect.setTop(retRect.top() +
|
retRect.setTop(retRect.top() +
|
||||||
(rowsInt * itemHeight) +
|
(rowsInt * itemHeight) +
|
||||||
categoryDrawer->categoryHeight(listView->viewOptions()) +
|
categoryDrawer->categoryHeight(index, listView->viewOptions()) +
|
||||||
listView->spacing() * 2);
|
listView->spacing() * 2);
|
||||||
|
|
||||||
if (listView->gridSize().isEmpty())
|
if (listView->gridSize().isEmpty())
|
||||||
|
@ -273,7 +273,7 @@ QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &cat
|
||||||
|
|
||||||
retRect.setTop(retRect.top() +
|
retRect.setTop(retRect.top() +
|
||||||
(rowsInt * itemHeight) +
|
(rowsInt * itemHeight) +
|
||||||
categoryDrawer->categoryHeight(listView->viewOptions()) +
|
categoryDrawer->categoryHeight(index, listView->viewOptions()) +
|
||||||
listView->spacing() * 2);
|
listView->spacing() * 2);
|
||||||
|
|
||||||
if (listView->gridSize().isEmpty())
|
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;
|
return retRect;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ KCategoryDrawer::~KCategoryDrawer()
|
||||||
}
|
}
|
||||||
|
|
||||||
void KCategoryDrawer::drawCategory(const QModelIndex &index,
|
void KCategoryDrawer::drawCategory(const QModelIndex &index,
|
||||||
int sortRole,
|
int /*sortRole*/,
|
||||||
const QStyleOption &option,
|
const QStyleOption &option,
|
||||||
QPainter *painter) const
|
QPainter *painter) const
|
||||||
{
|
{
|
||||||
|
@ -55,24 +55,6 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
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)
|
if (option.state & QStyle::State_Selected)
|
||||||
{
|
{
|
||||||
QColor selected = option.palette.color(QPalette::Highlight);
|
QColor selected = option.palette.color(QPalette::Highlight);
|
||||||
|
@ -103,15 +85,13 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
|
||||||
|
|
||||||
QFont painterFont = painter->font();
|
QFont painterFont = painter->font();
|
||||||
painterFont.setWeight(QFont::Bold);
|
painterFont.setWeight(QFont::Bold);
|
||||||
painterFont.setPointSize(painterFont.pointSize() + 2);
|
|
||||||
QFontMetrics metrics(painterFont);
|
QFontMetrics metrics(painterFont);
|
||||||
painter->setFont(painterFont);
|
painter->setFont(painterFont);
|
||||||
|
|
||||||
QPainterPath path;
|
QRect lineRect(option.rect.left(),
|
||||||
path.addRect(option.rect.left(),
|
option.rect.bottom() - 1,
|
||||||
option.rect.bottom() - 2,
|
option.rect.width(),
|
||||||
option.rect.width(),
|
1);
|
||||||
2);
|
|
||||||
|
|
||||||
QLinearGradient gradient(option.rect.topLeft(),
|
QLinearGradient gradient(option.rect.topLeft(),
|
||||||
option.rect.bottomRight());
|
option.rect.bottomRight());
|
||||||
|
@ -120,18 +100,19 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
|
||||||
gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
|
gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
|
||||||
: 0, Qt::transparent);
|
: 0, Qt::transparent);
|
||||||
|
|
||||||
painter->setBrush(gradient);
|
painter->fillRect(lineRect, gradient);
|
||||||
painter->fillPath(path, gradient);
|
|
||||||
|
|
||||||
painter->setPen(color);
|
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()));
|
metrics.elidedText(category, Qt::ElideRight, option.rect.width()));
|
||||||
|
|
||||||
painter->restore();
|
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 */;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
const QStyleOption &option,
|
const QStyleOption &option,
|
||||||
QPainter *painter) const;
|
QPainter *painter) const;
|
||||||
|
|
||||||
virtual int categoryHeight(const QStyleOption &option) const;
|
virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KCATEGORYDRAWER_H
|
#endif // KCATEGORYDRAWER_H
|
||||||
|
|
Loading…
Reference in a new issue