From kde-core-devel Tue Dec 07 21:01:05 2004 From: Martin Koller Date: Tue, 07 Dec 2004 21:01:05 +0000 To: kde-core-devel Subject: Re: [patch] shade sorted column in KListView Message-Id: <200412072201.09961.m.koller () surfeu ! at> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=110245333800595 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--nextPart1433132.NmRSQ9fqEH" --nextPart1433132.NmRSQ9fqEH Content-Type: multipart/mixed; boundary="Boundary-01=_SohtBCT7f9l+lMZ" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_SohtBCT7f9l+lMZ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Tuesday 07 December 2004 21:06, Alexander Neundorf wrote: > if the alternating color is darker than the background color, make the so= rt > 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= =20 make a problem when the background color is white (lighter than white is no= t=20 possible). I think I found a good solution (it's similar to what the=20 calculateAlternateBackgroundColor() method in kglobalsettings does). See attached patch. If there are no objections to the rest of the code, I would commit this=20 tomorrow. =2D-=20 Best regards/Sch=F6ne Gr=FC=DFe Martin () ascii ribbon campaign - against html mail=20 /\ - against microsoft attachments Some operating systems are called 'user friendly', Linux however is 'expert friendly'. --Boundary-01=_SohtBCT7f9l+lMZ Content-Type: text/x-diff; charset="iso-8859-1"; name="59791.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="59791.patch" Index: klistview.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdelibs/kdeui/klistview.cpp,v retrieving revision 1.243 diff -u -3 -p -r1.243 klistview.cpp =2D-- 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), =2D painting (false) + painting (false), + shadeSortColumn (true) { renameable.append(0); connect(editor, SIGNAL(done(QListViewItem*,int)), listview, SLOT(don= eEditing(QListViewItem*,int))); @@ -145,7 +146,7 @@ public: bool fullWidth:1; bool sortAscending:1; bool tabRename:1; =2D + =20 int sortColumn; =20 //+1 means downwards (y increases, -1 means upwards, 0 means not selecte= d), aleXXX @@ -165,7 +166,8 @@ public: QListViewItem *paintAbove; QListViewItem *paintCurrent; QListViewItem *paintBelow; =2D bool painting; + bool painting:1; + bool shadeSortColumn:1; =20 QColor alternateBackground; }; @@ -1985,6 +1987,17 @@ void KListView::setAlternateBackground(c repaint(); } =20 +void KListView::setShadeSortColumn(bool shadeSortColumn) +{ + d->shadeSortColumn =3D 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(); } =20 +QColor KListViewItem::backgroundColor(int column) +{ + KListView* view =3D static_cast< KListView* >(listView()); =20 + QColor color =3D 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 =3D=3D = view->columnSorted()) ) + { + if ( color =3D=3D Qt::black ) + color =3D QColor(110, 110, 110); // dark gray + else + { + int h,s,v; + color.hsv(&h, &s, &v); + if ( v > 175 ) + color =3D color.dark(104); + else + color =3D color.light(120); + } + } + + return color; +} + bool KListViewItem::isAlternate() { KListView* const lv =3D static_cast(listView()); @@ -2263,18 +2302,19 @@ void KListViewItem::paintCell(QPainter * { QColorGroup _cg =3D cg; const QPixmap *pm =3D listView()->viewport()->backgroundPixmap(); + if (pm && !pm->isNull()) { =2D _cg.setBrush(QColorGroup::Base, QBrush(backgroundColor(), *pm)); =2D QPoint o =3D p->brushOrigin(); =2D p->setBrushOrigin( o.x()-listView()->contentsX(), o.y()-listView= ()->contentsY() ); =2D } =2D else if (isAlternate()) =2D if (listView()->viewport()->backgroundMode()=3D=3DQt::FixedColor) =2D _cg.setColor(QColorGroup::Background, static_cast< KListView= * >(listView())->alternateBackground()); =2D else =2D _cg.setColor(QColorGroup::Base, static_cast< KListView* >(listVi= ew())->alternateBackground()); =2D + _cg.setBrush(QColorGroup::Base, QBrush(backgroundColor(column), *pm)); + QPoint o =3D p->brushOrigin(); + p->setBrushOrigin( o.x()-listView()->contentsX(), o.y()-listView()->co= ntentsY() ); + } + else + { + _cg.setColor((listView()->viewport()->backgroundMode() =3D=3D Qt::Fixe= dColor) ? + QColorGroup::Background : QColorGroup::Base, + backgroundColor(column)); + } QListViewItem::paintCell(p, _cg, column, width, alignment); } =20 Index: klistview.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdelibs/kdeui/klistview.h,v retrieving revision 1.127 diff -u -3 -p -r1.127 klistview.h =2D-- 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 setD= ropVisualizerWidth ) Q_PROPERTY( QColor alternateBackground READ alternateBackground WRITE s= etAlternateBackground ) =2D + Q_PROPERTY( bool shadeSortColumn READ shadeSortColumn WRITE setShadeSort= Column ) + =20 Q_OVERRIDE( SelectionModeExt selectionMode READ selectionModeExt WRITE s= etSelectionModeExt ) =20 public: @@ -385,6 +386,17 @@ public: */ virtual void takeItem(QListViewItem *i); =20 + /** + * Set to true if the currently sorted column should be drawn shaded. De= faults to true + * @param shadeSortColumn True if sort column should be shaded. + */ + void setShadeSortColumn(bool shadeSortColumn); + =20 + /** + * See if the sort column should be drawn shaded + * @return true if the sort column should be shaded + */ + bool shadeSortColumn(void) const; signals: =20 /** @@ -1033,7 +1045,6 @@ public: =20 virtual void insertItem(QListViewItem *item); virtual void takeItem(QListViewItem *item); =2D /** * 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 */ =2D const QColor &backgroundColor(); + const QColor &backgroundColor() KDE_DEPRECATED; // #### should be remov= ed 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 =3D -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); =20 virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment); Index: kdebase/konqueror/listview/konq_infolistviewitem.cc =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdebase/konqueror/listview/konq_infolistviewitem.cc,v retrieving revision 1.12 diff -u -3 -p -r1.12 konq_infolistviewitem.cc =2D-- 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 =3D _width; if ( pm && !pm->isNull() ) { =2D cg.setBrush( QColorGroup::Base, QBrush( backgroundColor(), *= pm ) ); + cg.setBrush( QColorGroup::Base, QBrush( backgroundColor(_colum= n), *pm ) ); QPoint o =3D _painter->brushOrigin(); _painter->setBrushOrigin( o.x() - lv->contentsX(), o.y() - lv-= >contentsY() ); const QColorGroup::ColorRole crole =3D=20 @@ -235,19 +235,9 @@ void KonqInfoListViewItem::paintCell( QP _painter->fillRect( newWidth, 0, _width - newWidth, height(), = cg.brush( crole ) ); _painter->setBrushOrigin( o ); } =2D else if ( isAlternate() ) =2D { =2D _painter->fillRect( newWidth, 0, _width - newWidth, height()= ,=20 =2D lv->alternateBackground() ); =2D } else { =2D const QColorGroup::ColorRole crole =3D=20 =2D QPalette::backgroundRoleFromMode( lv->viewport()->backgr= oundMode() ); =2D if ( cg.brush( crole ) !=3D lv->colorGroup().brush( crole ) ) =2D _painter->fillRect( newWidth, 0, _width - newWidth, heig= ht(), cg.brush( crole ) ); =2D else =2D m_pListViewWidget->paintEmptyArea( _painter, QRect( newW= idth, 0, _width - newWidth, height() ) ); + _painter->fillRect( newWidth, 0, _width - newWidth, height(), = backgroundColor(_column) ); } =20 _width =3D newWidth; Index: kdebase/konqueror/listview/konq_listviewitems.cc =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdebase/konqueror/listview/konq_listviewitems.cc,v retrieving revision 1.68 diff -u -3 -p -r1.68 konq_listviewitems.cc =2D-- kdebase/konqueror/listview/konq_listviewitems.cc 9 Nov 2004 17:32:54 = =2D0000 1.68 +++ kdebase/konqueror/listview/konq_listviewitems.cc 6 Dec 2004 20:18:05 -0= 000 @@ -279,7 +279,7 @@ void KonqListViewItem::paintCell( QPaint newWidth =3D _width; if ( pm && !pm->isNull() ) { =2D cg.setBrush( QColorGroup::Base, QBrush( backgroundColor(), *= pm ) ); + cg.setBrush( QColorGroup::Base, QBrush( backgroundColor(_colum= n), *pm ) ); QPoint o =3D _painter->brushOrigin(); _painter->setBrushOrigin( o.x() - lv->contentsX(), o.y() - lv-= >contentsY() ); const QColorGroup::ColorRole crole =3D=20 @@ -287,19 +287,9 @@ void KonqListViewItem::paintCell( QPaint _painter->fillRect( newWidth, 0, _width - newWidth, height(), = cg.brush( crole ) ); _painter->setBrushOrigin( o ); } =2D else if ( isAlternate() ) =2D { =2D _painter->fillRect( newWidth, 0, _width - newWidth, height()= ,=20 =2D lv->alternateBackground() ); =2D } else { =2D const QColorGroup::ColorRole crole =3D=20 =2D QPalette::backgroundRoleFromMode( lv->viewport()->backgr= oundMode() ); =2D if ( cg.brush( crole ) !=3D lv->colorGroup().brush( crole ) ) =2D _painter->fillRect( newWidth, 0, _width - newWidth, heig= ht(), cg.brush( crole ) ); =2D else =2D m_pListViewWidget->paintEmptyArea( _painter, QRect( newW= idth, 0, _width - newWidth, height() ) ); + _painter->fillRect( newWidth, 0, _width - newWidth, height(), = backgroundColor(_column) ); } =20 _width =3D newWidth; --Boundary-01=_SohtBCT7f9l+lMZ-- --nextPart1433132.NmRSQ9fqEH Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQBBthoVUeHBRvgua64RAlyDAJ9CHIf1nRI2y3A3NFHpdkemzPOLFgCeMt5E cHlYLeUDKJYA2XEnAzyaPAA= =U5Fw -----END PGP SIGNATURE----- --nextPart1433132.NmRSQ9fqEH--