X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/c8072005fada01d772595ec64adca449134f421e..ac73af7bedeebe2afa451249e8a6500651a6ec00:/src/kcategorydrawer.cpp diff --git a/src/kcategorydrawer.cpp b/src/kcategorydrawer.cpp index ebe77f4de..6d82bf96b 100644 --- a/src/kcategorydrawer.cpp +++ b/src/kcategorydrawer.cpp @@ -1,6 +1,6 @@ /** * This file is part of the KDE project - * Copyright (C) 2007 Rafael Fernández López + * Copyright (C) 2007 Rafael Fernández López * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -23,6 +23,7 @@ #include #include +#include #include KCategoryDrawer::KCategoryDrawer() @@ -34,59 +35,72 @@ KCategoryDrawer::~KCategoryDrawer() } void KCategoryDrawer::drawCategory(const QModelIndex &index, - int sortRole, + int /*sortRole*/, const QStyleOption &option, QPainter *painter) const { - const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryRole).toString(); + const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).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); - QStyleOptionButton opt; + if (option.state & QStyle::State_Selected) + { + QColor selected = option.palette.color(QPalette::Highlight); - opt.rect = option.rect; - opt.palette = option.palette; - opt.direction = option.direction; - opt.text = category; + 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); - if (option.state & QStyle::State_MouseOver) + 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); } 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(0, color); - gradient.setColorAt(1, Qt::transparent); + gradient.setColorAt(option.direction == Qt::LeftToRight ? 0 + : 1, color); + gradient.setColorAt(option.direction == Qt::LeftToRight ? 1 + : 0, Qt::transparent); - painter->setBrush(gradient); - painter->fillPath(path, gradient); + painter->fillRect(lineRect, gradient); painter->setPen(color); @@ -96,7 +110,9 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index, 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 */; }