From: Rafael Fernández López Date: Mon, 17 Sep 2007 06:03:40 +0000 (+0000) Subject: Give feedback to user when clicking on a category and the user is not dragging from... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/b3db0a708a630d9f59857ab7dcbfe8f29e3e8eb9 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 --- diff --git a/src/dolphincategorydrawer.cpp b/src/dolphincategorydrawer.cpp index 039b395a4..42f55f473 100644 --- a/src/dolphincategorydrawer.cpp +++ b/src/dolphincategorydrawer.cpp @@ -62,7 +62,16 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole, const QString category = categoryVariant.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); @@ -74,7 +83,20 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole, 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) { QColor hover = option.palette.color(QPalette::Highlight).light(); hover.setAlpha(88); diff --git a/src/kcategorizedview.cpp b/src/kcategorizedview.cpp index 7bc0055ae..026f56c24 100644 --- a/src/kcategorizedview.cpp +++ b/src/kcategorizedview.cpp @@ -357,10 +357,23 @@ void KCategorizedView::Private::drawNewCategory(const QModelIndex &index, QStyleOption optionCopy = option; const QString category = proxyModel->data(index, KCategorizedSortFilterProxyModel::CategoryRole).toString(); + optionCopy.state &= ~QStyle::State_Selected; + if ((category == hoveredCategory) && !mouseButtonPressed) { optionCopy.state |= QStyle::State_MouseOver; } + else if ((category == hoveredCategory) && mouseButtonPressed) + { + QPoint initialPressPosition = listView->viewport()->mapFromGlobal(QCursor::pos()); + initialPressPosition.setY(initialPressPosition.y() + listView->verticalOffset()); + initialPressPosition.setX(initialPressPosition.x() + listView->horizontalOffset()); + + if (initialPressPosition == this->initialPressPosition) + { + optionCopy.state |= QStyle::State_Selected; + } + } categoryDrawer->drawCategory(index, sortRole, @@ -891,6 +904,8 @@ void KCategorizedView::mousePressEvent(QMouseEvent *event) } QListView::mousePressEvent(event); + + viewport()->update(d->categoryVisualRect(d->hoveredCategory)); } void KCategorizedView::mouseReleaseEvent(QMouseEvent *event) 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); }