summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/cornucopia/olistview.cpp
Unidiff
Diffstat (limited to 'noncore/net/wellenreiter/cornucopia/olistview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/cornucopia/olistview.cpp262
1 files changed, 262 insertions, 0 deletions
diff --git a/noncore/net/wellenreiter/cornucopia/olistview.cpp b/noncore/net/wellenreiter/cornucopia/olistview.cpp
new file mode 100644
index 0000000..bca17b2
--- a/dev/null
+++ b/noncore/net/wellenreiter/cornucopia/olistview.cpp
@@ -0,0 +1,262 @@
1/*
2                 This file is part of the Opie Project
3
4              Copyright (C) 2003 Michael 'Mickey' Lauer
5 <mickey@tm.informatik.uni-frankfurt.de>
6 =.
7 .=l.
8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details.
23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA.
30
31*/
32
33#include <qcolor.h>
34#include <qheader.h>
35#include <qpainter.h>
36#include <qpixmap.h>
37
38#include "olistview.h"
39
40//****************************** OListView **************************************************************************
41
42OListView::OListView( QWidget *parent, const char *name )
43 :QListView( parent, name )
44{
45 //FIXME: get from global settings and calculate ==> see oglobalsettings.*
46
47 m_alternateBackground = QColor( 238, 246, 255 );
48 m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine );
49 m_fullWidth = true;
50}
51
52OListView::~OListView()
53{
54}
55
56void OListView::setFullWidth( bool fullWidth )
57{
58 m_fullWidth = m_fullWidth;
59 #if QT_VERSION > 290
60 header()->setStretchEnabled( fullWidth, columns()-1 );
61 #endif
62}
63
64bool OListView::fullWidth() const
65{
66 return m_fullWidth;
67}
68
69int OListView::addColumn( const QString& label, int width )
70{
71 int result = QListView::addColumn( label, width );
72 #if QT_VERSION > 290
73 if (m_fullWidth) {
74 header()->setStretchEnabled( false, columns()-2 );
75 header()->setStretchEnabled( true, columns()-1 );
76 }
77 #endif
78 return result;
79}
80
81int OListView::addColumn( const QIconSet& iconset, const QString& label, int width )
82{
83 int result = QListView::addColumn( iconset, label, width );
84 #if QT_VERSION > 290
85 if (m_fullWidth) {
86 header()->setStretchEnabled( false, columns()-2 );
87 header()->setStretchEnabled( true, columns()-1 );
88 }
89 #endif
90 return result;
91}
92
93void OListView::removeColumn( int index )
94{
95 QListView::removeColumn(index);
96 #if QT_VERSION > 290
97 if ( m_fullWidth && index == columns() )
98 {
99 header()->setStretchEnabled( true, columns()-1 );
100 }
101 #endif
102}
103
104const QColor& OListView::alternateBackground() const
105{
106 return m_alternateBackground;
107}
108
109void OListView::setAlternateBackground( const QColor &c )
110{
111 m_alternateBackground = c;
112 repaint();
113}
114
115const QPen& OListView::columnSeparator() const
116{
117 return m_columnSeparator;
118}
119
120void OListView::setColumnSeparator( const QPen& p )
121{
122 m_columnSeparator = p;
123 repaint();
124}
125
126//****************************** OListViewItem ***********************************************************************
127
128OListViewItem::OListViewItem(QListView *parent)
129 : QListViewItem(parent)
130{
131 init();
132}
133
134OListViewItem::OListViewItem(QListViewItem *parent)
135 : QListViewItem(parent)
136{
137 init();
138}
139
140OListViewItem::OListViewItem(QListView *parent, QListViewItem *after)
141 : QListViewItem(parent, after)
142{
143 init();
144}
145
146OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after)
147 : QListViewItem(parent, after)
148{
149 init();
150}
151
152OListViewItem::OListViewItem(QListView *parent,
153 QString label1, QString label2, QString label3, QString label4,
154 QString label5, QString label6, QString label7, QString label8)
155 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
156{
157 init();
158}
159
160OListViewItem::OListViewItem(QListViewItem *parent,
161 QString label1, QString label2, QString label3, QString label4,
162 QString label5, QString label6, QString label7, QString label8)
163 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
164{
165 init();
166}
167
168OListViewItem::OListViewItem(QListView *parent, QListViewItem *after,
169 QString label1, QString label2, QString label3, QString label4,
170 QString label5, QString label6, QString label7, QString label8)
171 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
172{
173 init();
174}
175
176OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after,
177 QString label1, QString label2, QString label3, QString label4,
178 QString label5, QString label6, QString label7, QString label8)
179 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
180{
181 init();
182}
183
184OListViewItem::~OListViewItem()
185{
186}
187
188void OListViewItem::init()
189{
190 m_known = false;
191}
192
193const QColor &OListViewItem::backgroundColor()
194{
195 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
196 listView()->viewport()->colorGroup().base();
197}
198
199bool OListViewItem::isAlternate()
200{
201 OListView *lv = static_cast<OListView*>( listView() );
202
203 // check if the item above is an OListViewItem
204 OListViewItem *above = static_cast<OListViewItem*>( itemAbove() );
205 /*if (not itemAbove()->inherits( "OListViewItem" )) return false;*/
206
207 // check if we have a valid alternate background color
208 if (not (lv && lv->alternateBackground().isValid())) return false;
209
210 m_known = above ? above->m_known : true;
211 if (m_known)
212 {
213 m_odd = above ? !above->m_odd : false;
214 }
215 else
216 {
217 OListViewItem *item;
218 bool previous = true;
219 if (parent())
220 {
221 item = static_cast<OListViewItem *>(parent());
222 if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd;
223 item = static_cast<OListViewItem *>(parent()->firstChild());
224 /* if !( item.inherits( "OListViewItem" ) item = 0; */
225 }
226 else
227 {
228 item = static_cast<OListViewItem *>(lv->firstChild());
229 }
230
231 while(item)
232 {
233 item->m_odd = previous = !previous;
234 item->m_known = true;
235 item = static_cast<OListViewItem *>(item->nextSibling());
236 /* if !(item.inherits( "OListViewItem" ) ) break; */
237 }
238 }
239 return m_odd;
240}
241
242void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
243{
244 QColorGroup _cg = cg;
245 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
246 if (pm && !pm->isNull())
247 {
248 _cg.setBrush(QColorGroup::Base, QBrush(backgroundColor(), *pm));
249 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
250 }
251 else if ( isAlternate() )
252 {
253 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
254 }
255 QListViewItem::paintCell(p, _cg, column, width, alignment);
256
257 //FIXME: Use styling here?
258
259 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
260 p->setPen( pen );
261 p->drawLine( width-1, 0, width-1, height() );
262}