[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: [patch] shade sorted column in KListView
From: Martin Koller <m.koller () surfeu ! at>
Date: 2004-12-06 21:12:47
Message-ID: 200412062212.48470.m.koller () surfeu ! at
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
Hi all,
attached is a patch for
http://bugs.kde.org/show_bug.cgi?id=59791
which adds the possibility to give a visual feedback for the sorted column in
KListView: The column background is a little bit darker than the others.
Also, due to konqis new highlighting of items, the patch includes this, too.
ok to commit ?
--
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: kdelibs/kdeui/klistview.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/klistview.cpp,v
retrieving revision 1.243
diff -u -3 -p -r1.243 klistview.cpp
--- kdelibs/kdeui/klistview.cpp 1 Dec 2004 08:07:17 -0000 1.243
+++ kdelibs/kdeui/klistview.cpp 6 Dec 2004 20:09:56 -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,20 @@ 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();
+
+ //darken the color if the current column is sorted (only if more than 1 \
column) + if ( (view->columns() > 1) && view->shadeSortColumn() && (column \
== view->columnSorted()) ) + color = color.dark(104);
+
+ return color;
+}
+
bool KListViewItem::isAlternate()
{
KListView* const lv = static_cast<KListView *>(listView());
@@ -2263,18 +2290,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: kdelibs/kdeui/klistview.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/klistview.h,v
retrieving revision 1.127
diff -u -3 -p -r1.127 klistview.h
--- kdelibs/kdeui/klistview.h 19 Nov 2004 12:53:00 -0000 1.127
+++ kdelibs/kdeui/klistview.h 6 Dec 2004 20:09:59 -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