]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Give feedback to user when clicking on a category and the user is not dragging from...
authorRafael Fernández López <ereslibre@kde.org>
Mon, 17 Sep 2007 06:03:40 +0000 (06:03 +0000)
committerRafael Fernández López <ereslibre@kde.org>
Mon, 17 Sep 2007 06:03:40 +0000 (06:03 +0000)
CCMAIL: peter.penz@gmx.at

svn path=/trunk/KDE/kdebase/apps/; revision=713337

src/dolphincategorydrawer.cpp
src/kcategorizedview.cpp
src/kcategorydrawer.cpp

index 039b395a4553a5e63e60c0de102e7935da31ab13..42f55f47323eb2234154292af992c3467e5c86aa 100644 (file)
@@ -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);
index 7bc0055aed7b189527f08f1dd233be796b61c579..026f56c2437a1f62ea1b5f41f15fe47ab3747e14 100644 (file)
@@ -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)
index 4c59864a09c3c4c6de615c2f6ffd79fe48430427..56c538d4e7ced426c098697ac2c5e1d36e132c22 100644 (file)
@@ -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);
     }