[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: [patch] shade sorted column in KListView
From:       Martin Koller <m.koller () surfeu ! at>
Date:       2004-12-07 21:01:05
Message-ID: 200412072201.09961.m.koller () surfeu ! at
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


On Tuesday 07 December 2004 21:06, Alexander Neundorf wrote:
> if the alternating color is darker than the background color, make the sort
> color slightly darker.
> If the alternating color is lighter than the background color, make the
> sort color slightly lighter.

If you invert back/alternating, it will give different results, which would 
make a problem when the background color is white (lighter than white is not 
possible).
I think I found a good solution (it's similar to what the 
calculateAlternateBackgroundColor() method in kglobalsettings does).

See attached patch.

If there are no objections to the rest of the code, I would commit this 
tomorrow.

-- 
Best regards/Schöne Grüße

Martin    ()  ascii ribbon campaign - against html mail 
          /\                        - against microsoft attachments

       Some operating systems are called 'user friendly',
             Linux however is 'expert friendly'.

["59791.patch" (text/x-diff)]

Index: klistview.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/klistview.cpp,v
retrieving revision 1.243
diff -u -3 -p -r1.243 klistview.cpp
--- klistview.cpp	1 Dec 2004 08:07:17 -0000	1.243
+++ klistview.cpp	7 Dec 2004 20:55:40 -0000
@@ -100,7 +100,8 @@ public:
       paintAbove (0),
       paintCurrent (0),
       paintBelow (0),
-      painting (false)
+      painting (false),
+      shadeSortColumn (true)
   {
       renameable.append(0);
       connect(editor, SIGNAL(done(QListViewItem*,int)), listview, \
SLOT(doneEditing(QListViewItem*,int))); @@ -145,7 +146,7 @@ public:
   bool fullWidth:1;
   bool sortAscending:1;
   bool tabRename:1;
-
+  
   int sortColumn;
 
   //+1 means downwards (y increases, -1 means upwards, 0 means not selected), aleXXX
@@ -165,7 +166,8 @@ public:
   QListViewItem *paintAbove;
   QListViewItem *paintCurrent;
   QListViewItem *paintBelow;
-  bool painting;
+  bool painting:1;
+  bool shadeSortColumn:1;
 
   QColor alternateBackground;
 };
@@ -1985,6 +1987,17 @@ void KListView::setAlternateBackground(c
   repaint();
 }
 
+void KListView::setShadeSortColumn(bool shadeSortColumn)
+{
+  d->shadeSortColumn = shadeSortColumn;
+  repaint();
+}
+
+bool KListView::shadeSortColumn() const
+{
+  return d->shadeSortColumn;
+}
+
 void KListView::saveLayout(KConfig *config, const QString &group) const
 {
   KConfigGroupSaver saver(config, group);
@@ -2185,6 +2198,32 @@ const QColor &KListViewItem::backgroundC
   return listView()->viewport()->colorGroup().base();
 }
 
+QColor KListViewItem::backgroundColor(int column)
+{
+  KListView* view = static_cast< KListView* >(listView());  
+  QColor color = isAlternate() ?
+                 view->alternateBackground() :
+                 view->viewport()->colorGroup().base();
+
+  // calculate a different color if the current column is sorted (only if more than \
1 column) +  if ( (view->columns() > 1) && view->shadeSortColumn() && (column == \
view->columnSorted()) ) +  {
+    if ( color == Qt::black )
+      color = QColor(110, 110, 110);  // dark gray
+    else
+    {
+      int h,s,v;
+      color.hsv(&h, &s, &v);
+      if ( v > 175 )
+	color = color.dark(104);
+      else
+	color = color.light(120);
+    }
+  }
+
+  return color;
+}
+
 bool KListViewItem::isAlternate()
 {
   KListView* const lv = static_cast<KListView *>(listView());
@@ -2263,18 +2302,19 @@ void KListViewItem::paintCell(QPainter *
 {
   QColorGroup _cg = cg;
   const QPixmap *pm = listView()->viewport()->backgroundPixmap();
+
   if (pm && !pm->isNull())
   {
-        _cg.setBrush(QColorGroup::Base, QBrush(backgroundColor(), *pm));
-        QPoint o = p->brushOrigin();
-        p->setBrushOrigin( o.x()-listView()->contentsX(), \
                o.y()-listView()->contentsY() );
-  }
-  else if (isAlternate())
-       if (listView()->viewport()->backgroundMode()==Qt::FixedColor)
-            _cg.setColor(QColorGroup::Background, static_cast< KListView* \
                >(listView())->alternateBackground());
-       else
-        _cg.setColor(QColorGroup::Base, static_cast< KListView* \
                >(listView())->alternateBackground());
-
+    _cg.setBrush(QColorGroup::Base, QBrush(backgroundColor(column), *pm));
+    QPoint o = p->brushOrigin();
+    p->setBrushOrigin( o.x()-listView()->contentsX(), o.y()-listView()->contentsY() \
); +  }
+  else
+  {
+    _cg.setColor((listView()->viewport()->backgroundMode() == Qt::FixedColor) ?
+                 QColorGroup::Background : QColorGroup::Base,
+                 backgroundColor(column));
+  }
   QListViewItem::paintCell(p, _cg, column, width, alignment);
 }
 
Index: klistview.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/klistview.h,v
retrieving revision 1.127
diff -u -3 -p -r1.127 klistview.h
--- klistview.h	19 Nov 2004 12:53:00 -0000	1.127
+++ klistview.h	7 Dec 2004 20:55:43 -0000
@@ -65,7 +65,8 @@ class KDEUI_EXPORT KListView : public QL
   Q_PROPERTY( int tooltipColumn READ tooltipColumn WRITE  setTooltipColumn )
   Q_PROPERTY( int dropVisualizerWidth READ dropVisualizerWidth WRITE  \
setDropVisualizerWidth )  Q_PROPERTY( QColor alternateBackground READ \
                alternateBackground WRITE  setAlternateBackground )
-
+  Q_PROPERTY( bool shadeSortColumn READ shadeSortColumn WRITE setShadeSortColumn )
+  
   Q_OVERRIDE( SelectionModeExt selectionMode READ selectionModeExt WRITE \
setSelectionModeExt )  
 public:
@@ -385,6 +386,17 @@ public:
    */
   virtual void takeItem(QListViewItem *i);
 
+  /**
+   * Set to true if the currently sorted column should be drawn shaded. Defaults to \
true +   * @param shadeSortColumn True if sort column should be shaded.
+   */
+  void setShadeSortColumn(bool shadeSortColumn);
+  
+  /**
+   * See if the sort column should be drawn shaded
+   * @return true if the sort column should be shaded
+   */
+  bool shadeSortColumn(void) const;
 signals:
 
   /**
@@ -1033,7 +1045,6 @@ public:
 
   virtual void insertItem(QListViewItem *item);
   virtual void takeItem(QListViewItem *item);
-
   /**
    * returns true if this item is to be drawn with the alternate background
    */
@@ -1041,7 +1052,16 @@ public:
   /**
    * returns the background color for this item
    */
-  const QColor &backgroundColor();
+  const QColor &backgroundColor() KDE_DEPRECATED;  // #### should be removed in 4.0; \
use below instead +
+  /**
+   * returns the background color for this item at given column
+   * This can be different in the column which is sorted due to shading
+   * ### could be merged with above (column = -1) to be source compatible
+   * ### but will only work if sort-shading is not used or the listView has
+   * ### only 1 column
+   */
+  QColor backgroundColor(int column);
 
   virtual void paintCell(QPainter *p, const QColorGroup &cg,
     int column, int width, int alignment);
Index: kdebase/konqueror/listview/konq_infolistviewitem.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/listview/konq_infolistviewitem.cc,v
retrieving revision 1.12
diff -u -3 -p -r1.12 konq_infolistviewitem.cc
--- kdebase/konqueror/listview/konq_infolistviewitem.cc	9 Nov 2004 17:32:54 \
                -0000	1.12
+++ kdebase/konqueror/listview/konq_infolistviewitem.cc	6 Dec 2004 20:18:03 -0000
@@ -227,7 +227,7 @@ void KonqInfoListViewItem::paintCell( QP
             newWidth = _width;
         if ( pm && !pm->isNull() )
         {
-            cg.setBrush( QColorGroup::Base, QBrush( backgroundColor(), *pm ) );
+            cg.setBrush( QColorGroup::Base, QBrush( backgroundColor(_column), *pm ) \
);  QPoint o = _painter->brushOrigin();
             _painter->setBrushOrigin( o.x() - lv->contentsX(), o.y() - \
lv->contentsY() );  const QColorGroup::ColorRole crole = 
@@ -235,19 +235,9 @@ void KonqInfoListViewItem::paintCell( QP
             _painter->fillRect( newWidth, 0, _width - newWidth, height(), cg.brush( \
crole ) );  _painter->setBrushOrigin( o );
         }
-        else if ( isAlternate() )
-        {
-            _painter->fillRect( newWidth, 0, _width - newWidth, height(), 
-                lv->alternateBackground() );
-        }
         else
         {
-            const QColorGroup::ColorRole crole = 
-                QPalette::backgroundRoleFromMode( lv->viewport()->backgroundMode() \
                );
-            if ( cg.brush( crole ) != lv->colorGroup().brush( crole ) )
-                _painter->fillRect( newWidth, 0, _width - newWidth, height(), \
                cg.brush( crole ) );
-            else
-                m_pListViewWidget->paintEmptyArea( _painter, QRect( newWidth, 0, \
_width - newWidth, height() ) ); +            _painter->fillRect( newWidth, 0, _width \
- newWidth, height(), backgroundColor(_column) );  }
 
         _width = newWidth;
Index: kdebase/konqueror/listview/konq_listviewitems.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/listview/konq_listviewitems.cc,v
retrieving revision 1.68
diff -u -3 -p -r1.68 konq_listviewitems.cc
--- kdebase/konqueror/listview/konq_listviewitems.cc	9 Nov 2004 17:32:54 -0000	1.68
+++ kdebase/konqueror/listview/konq_listviewitems.cc	6 Dec 2004 20:18:05 -0000
@@ -279,7 +279,7 @@ void KonqListViewItem::paintCell( QPaint
             newWidth = _width;
         if ( pm && !pm->isNull() )
         {
-            cg.setBrush( QColorGroup::Base, QBrush( backgroundColor(), *pm ) );
+            cg.setBrush( QColorGroup::Base, QBrush( backgroundColor(_column), *pm ) \
);  QPoint o = _painter->brushOrigin();
             _painter->setBrushOrigin( o.x() - lv->contentsX(), o.y() - \
lv->contentsY() );  const QColorGroup::ColorRole crole = 
@@ -287,19 +287,9 @@ void KonqListViewItem::paintCell( QPaint
             _painter->fillRect( newWidth, 0, _width - newWidth, height(), cg.brush( \
crole ) );  _painter->setBrushOrigin( o );
         }
-        else if ( isAlternate() )
-        {
-            _painter->fillRect( newWidth, 0, _width - newWidth, height(), 
-                lv->alternateBackground() );
-        }
         else
         {
-            const QColorGroup::ColorRole crole = 
-                QPalette::backgroundRoleFromMode( lv->viewport()->backgroundMode() \
                );
-            if ( cg.brush( crole ) != lv->colorGroup().brush( crole ) )
-                _painter->fillRect( newWidth, 0, _width - newWidth, height(), \
                cg.brush( crole ) );
-            else
-                m_pListViewWidget->paintEmptyArea( _painter, QRect( newWidth, 0, \
_width - newWidth, height() ) ); +            _painter->fillRect( newWidth, 0, _width \
- newWidth, height(), backgroundColor(_column) );  }
 
         _width = newWidth;


[Attachment #6 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic