From b3db0a708a630d9f59857ab7dcbfe8f29e3e8eb9 Mon Sep 17 00:00:00 2001 From: Rafael Fernández López Date: Mon, 17 Sep 2007 06:03:40 +0000 Subject: Give feedback to user when clicking on a category and the user is not dragging from it. Beauty, come to me :) CCMAIL: peter.penz@gmx.at svn path=/trunk/KDE/kdebase/apps/; revision=713337 --- src/kcategorydrawer.cpp | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'src/kcategorydrawer.cpp') diff --git a/src/kcategorydrawer.cpp b/src/kcategorydrawer.cpp index 4c59864a0..56c538d4e 100644 --- a/src/kcategorydrawer.cpp +++ b/src/kcategorydrawer.cpp @@ -40,7 +40,16 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index, { const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryRole).toString(); - QColor color = option.palette.color(QPalette::Text); + QColor color; + + if (option.state & QStyle::State_Selected) + { + color = option.palette.color(QPalette::HighlightedText); + } + else + { + color = option.palette.color(QPalette::Text); + } painter->save(); painter->setRenderHint(QPainter::Antialiasing); @@ -52,18 +61,30 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index, opt.direction = option.direction; opt.text = category; - if (option.state & QStyle::State_MouseOver) + if (option.state & QStyle::State_Selected) + { + QColor selected = option.palette.color(QPalette::Highlight); + + QLinearGradient gradient(option.rect.topLeft(), + option.rect.bottomRight()); + gradient.setColorAt(option.direction == Qt::LeftToRight ? 0 + : 1, selected); + gradient.setColorAt(option.direction == Qt::LeftToRight ? 1 + : 0, Qt::transparent); + + painter->fillRect(option.rect, gradient); + } + else if (option.state & QStyle::State_MouseOver) { - const QPalette::ColorGroup group = - option.state & QStyle::State_Enabled ? - QPalette::Normal : QPalette::Disabled; + QColor hover = option.palette.color(QPalette::Highlight).light(); + hover.setAlpha(88); QLinearGradient gradient(option.rect.topLeft(), option.rect.bottomRight()); - gradient.setColorAt(0, - option.palette.color(group, - QPalette::Highlight).light()); - gradient.setColorAt(1, Qt::transparent); + gradient.setColorAt(option.direction == Qt::LeftToRight ? 0 + : 1, hover); + gradient.setColorAt(option.direction == Qt::LeftToRight ? 1 + : 0, Qt::transparent); painter->fillRect(option.rect, gradient); } -- cgit v1.3