┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Fernández López <[email protected]>2008-01-02 01:21:39 +0000
committerRafael Fernández López <[email protected]>2008-01-02 01:21:39 +0000
commit743bec375187a51ed6b88256ff070e9f7e9f4929 (patch)
treecc6948abd9d21ecc0b5074883f7d4dcaa21f9382
parentc6a4a3aa063fb25e163bed8dac8587efef8c02b5 (diff)
Better looking categories. Thanks to Aurélien Gâteau for the original patch.
CCMAIL: [email protected] svn path=/trunk/KDE/kdebase/apps/; revision=755674
-rw-r--r--src/dolphincategorydrawer.cpp38
-rw-r--r--src/dolphincategorydrawer.h2
-rw-r--r--src/kcategorizedview.cpp10
-rw-r--r--src/kcategorydrawer.cpp41
-rw-r--r--src/kcategorydrawer.h2
5 files changed, 44 insertions, 49 deletions
diff --git a/src/dolphincategorydrawer.cpp b/src/dolphincategorydrawer.cpp
index 7f82a215f..8148a7b8e 100644
--- a/src/dolphincategorydrawer.cpp
+++ b/src/dolphincategorydrawer.cpp
@@ -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;
}
diff --git a/src/dolphincategorydrawer.h b/src/dolphincategorydrawer.h
index a8e196b0d..ea70a922b 100644
--- a/src/dolphincategorydrawer.h
+++ b/src/dolphincategorydrawer.h
@@ -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
diff --git a/src/kcategorizedview.cpp b/src/kcategorizedview.cpp
index b2504a14b..51b4a000b 100644
--- a/src/kcategorizedview.cpp
+++ b/src/kcategorizedview.cpp
@@ -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;
}
diff --git a/src/kcategorydrawer.cpp b/src/kcategorydrawer.cpp
index 53cf059f1..6d82bf96b 100644
--- a/src/kcategorydrawer.cpp
+++ b/src/kcategorydrawer.cpp
@@ -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 */;
}
diff --git a/src/kcategorydrawer.h b/src/kcategorydrawer.h
index 743dafa90..6af0d73cd 100644
--- a/src/kcategorydrawer.h
+++ b/src/kcategorydrawer.h
@@ -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