author | mickeyl <mickeyl> | 2003-02-24 15:54:13 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-02-24 15:54:13 (UTC) |
commit | f294a5d101fc9935e1a73f3d44b43ea00d0a03c7 (patch) (unidiff) | |
tree | 3fb4345bb3bacb023c217d55786b734c052de545 /noncore/net/wellenreiter/cornucopia | |
parent | 25725a7cd45731656e3ee3476614512b027dacf8 (diff) | |
download | opie-f294a5d101fc9935e1a73f3d44b43ea00d0a03c7.zip opie-f294a5d101fc9935e1a73f3d44b43ea00d0a03c7.tar.gz opie-f294a5d101fc9935e1a73f3d44b43ea00d0a03c7.tar.bz2 |
visual enhancements for the listview...
Diffstat (limited to 'noncore/net/wellenreiter/cornucopia') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/cornucopia/.cvsignore | 8 | ||||
-rw-r--r-- | noncore/net/wellenreiter/cornucopia/README | 3 | ||||
-rw-r--r-- | noncore/net/wellenreiter/cornucopia/cornucopia.pro | 16 | ||||
-rw-r--r-- | noncore/net/wellenreiter/cornucopia/olistview.cpp | 262 | ||||
-rw-r--r-- | noncore/net/wellenreiter/cornucopia/olistview.h | 168 |
5 files changed, 457 insertions, 0 deletions
diff --git a/noncore/net/wellenreiter/cornucopia/.cvsignore b/noncore/net/wellenreiter/cornucopia/.cvsignore new file mode 100644 index 0000000..724d599 --- a/dev/null +++ b/noncore/net/wellenreiter/cornucopia/.cvsignore | |||
@@ -0,0 +1,8 @@ | |||
1 | *.o | ||
2 | *~ | ||
3 | Makefile* | ||
4 | moc_* | ||
5 | wellenreitertemplate.cpp | ||
6 | wellenreitertemplate.h | ||
7 | configbase.h | ||
8 | configbase.cpp | ||
diff --git a/noncore/net/wellenreiter/cornucopia/README b/noncore/net/wellenreiter/cornucopia/README new file mode 100644 index 0000000..36a6954 --- a/dev/null +++ b/noncore/net/wellenreiter/cornucopia/README | |||
@@ -0,0 +1,3 @@ | |||
1 | --------------------------------------------------------------- | ||
2 | Dies ist ein Testballon für opielibs1.2 - Codename: Cornucopia | ||
3 | --------------------------------------------------------------- | ||
diff --git a/noncore/net/wellenreiter/cornucopia/cornucopia.pro b/noncore/net/wellenreiter/cornucopia/cornucopia.pro new file mode 100644 index 0000000..7ffa202 --- a/dev/null +++ b/noncore/net/wellenreiter/cornucopia/cornucopia.pro | |||
@@ -0,0 +1,16 @@ | |||
1 | DESTDIR = $(OPIEDIR)/lib | ||
2 | MOC_DIR = ./tmp | ||
3 | OBJECTS_DIR = ./tmp | ||
4 | TEMPLATE = lib | ||
5 | CONFIG = qt warn_on debug | ||
6 | VERSION = 0.1 | ||
7 | HEADERS = olistview.h | ||
8 | SOURCES = olistview.cpp | ||
9 | INCLUDEPATH = $(OPIEDIR)/include | ||
10 | DEPENDPATH = $(OPIEDIR)/include | ||
11 | TARGET = cornucopia | ||
12 | |||
13 | !contains( platform, x11 ) { | ||
14 | include ( $(OPIEDIR)/include.pro ) | ||
15 | } | ||
16 | |||
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 | |||
42 | OListView::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 | |||
52 | OListView::~OListView() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | void 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 | |||
64 | bool OListView::fullWidth() const | ||
65 | { | ||
66 | return m_fullWidth; | ||
67 | } | ||
68 | |||
69 | int 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 | |||
81 | int 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 | |||
93 | void 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 | |||
104 | const QColor& OListView::alternateBackground() const | ||
105 | { | ||
106 | return m_alternateBackground; | ||
107 | } | ||
108 | |||
109 | void OListView::setAlternateBackground( const QColor &c ) | ||
110 | { | ||
111 | m_alternateBackground = c; | ||
112 | repaint(); | ||
113 | } | ||
114 | |||
115 | const QPen& OListView::columnSeparator() const | ||
116 | { | ||
117 | return m_columnSeparator; | ||
118 | } | ||
119 | |||
120 | void OListView::setColumnSeparator( const QPen& p ) | ||
121 | { | ||
122 | m_columnSeparator = p; | ||
123 | repaint(); | ||
124 | } | ||
125 | |||
126 | //****************************** OListViewItem *********************************************************************** | ||
127 | |||
128 | OListViewItem::OListViewItem(QListView *parent) | ||
129 | : QListViewItem(parent) | ||
130 | { | ||
131 | init(); | ||
132 | } | ||
133 | |||
134 | OListViewItem::OListViewItem(QListViewItem *parent) | ||
135 | : QListViewItem(parent) | ||
136 | { | ||
137 | init(); | ||
138 | } | ||
139 | |||
140 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) | ||
141 | : QListViewItem(parent, after) | ||
142 | { | ||
143 | init(); | ||
144 | } | ||
145 | |||
146 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) | ||
147 | : QListViewItem(parent, after) | ||
148 | { | ||
149 | init(); | ||
150 | } | ||
151 | |||
152 | OListViewItem::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 | |||
160 | OListViewItem::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 | |||
168 | OListViewItem::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 | |||
176 | OListViewItem::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 | |||
184 | OListViewItem::~OListViewItem() | ||
185 | { | ||
186 | } | ||
187 | |||
188 | void OListViewItem::init() | ||
189 | { | ||
190 | m_known = false; | ||
191 | } | ||
192 | |||
193 | const QColor &OListViewItem::backgroundColor() | ||
194 | { | ||
195 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : | ||
196 | listView()->viewport()->colorGroup().base(); | ||
197 | } | ||
198 | |||
199 | bool 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 | |||
242 | void 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 | } | ||
diff --git a/noncore/net/wellenreiter/cornucopia/olistview.h b/noncore/net/wellenreiter/cornucopia/olistview.h new file mode 100644 index 0000000..4b9e4b0 --- a/dev/null +++ b/noncore/net/wellenreiter/cornucopia/olistview.h | |||
@@ -0,0 +1,168 @@ | |||
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 | #ifndef OLISTVIEW_H | ||
34 | #define OLISTVIEW_H | ||
35 | |||
36 | #include <qlistview.h> | ||
37 | #include <qcolor.h> | ||
38 | #include <qpen.h> | ||
39 | |||
40 | /** | ||
41 | * A @ref QListView variant featuring visual enhancements | ||
42 | * like an alternate background for odd rows and an autostretch | ||
43 | * mode for the width of the widget. | ||
44 | * | ||
45 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
46 | * @short OListView list/tree widget. | ||
47 | */ | ||
48 | class OListView: public QListView | ||
49 | { | ||
50 | public: | ||
51 | /** | ||
52 | * Constructor. | ||
53 | * | ||
54 | * The parameters @p parent and @p name are handled by | ||
55 | * @ref QListView, as usual. | ||
56 | */ | ||
57 | OListView ( QWidget *parent = 0, const char *name = 0 ); | ||
58 | |||
59 | /** | ||
60 | * Destructor. | ||
61 | */ | ||
62 | virtual ~OListView(); | ||
63 | |||
64 | /** | ||
65 | * Let the last column fit exactly all the available width. | ||
66 | */ | ||
67 | void setFullWidth( bool fullWidth ); | ||
68 | |||
69 | /** | ||
70 | * Returns whether the last column is set to fit the available width. | ||
71 | */ | ||
72 | bool fullWidth() const; | ||
73 | |||
74 | /** | ||
75 | * Reimplemented for full width support | ||
76 | */ | ||
77 | virtual int addColumn( const QString& label, int width = -1 ); | ||
78 | |||
79 | /** | ||
80 | * Reimplemented for full width support | ||
81 | */ | ||
82 | virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 ); | ||
83 | |||
84 | /** | ||
85 | * Reimplemented for full width support | ||
86 | */ | ||
87 | virtual void removeColumn(int index); | ||
88 | |||
89 | /** | ||
90 | * sets the alternate background background color. | ||
91 | * This only has an effect if the items are OListViewItems | ||
92 | * | ||
93 | * @param c the color to use for every other item. Set to an invalid | ||
94 | * color to disable alternate colors. | ||
95 | */ | ||
96 | void setAlternateBackground( const QColor &c ); | ||
97 | |||
98 | /** | ||
99 | * sets the column separator pen. | ||
100 | * | ||
101 | * @param p the pen used to draw the column separator. | ||
102 | */ | ||
103 | void setColumnSeparator( const QPen &p ); | ||
104 | |||
105 | /** | ||
106 | * @return the alternate background color | ||
107 | */ | ||
108 | const QColor& alternateBackground() const; | ||
109 | |||
110 | /** | ||
111 | * @return the column separator pen | ||
112 | */ | ||
113 | const QPen& columnSeparator() const; | ||
114 | |||
115 | private: | ||
116 | QColor m_alternateBackground; | ||
117 | bool m_fullWidth; | ||
118 | QPen m_columnSeparator; | ||
119 | |||
120 | }; | ||
121 | |||
122 | //****************************** OListViewItem ****************************************************************** | ||
123 | |||
124 | class OListViewItem: public QListViewItem | ||
125 | { | ||
126 | public: | ||
127 | OListViewItem( QListView * parent ); | ||
128 | OListViewItem( QListViewItem * parent ); | ||
129 | OListViewItem( QListView * parent, QListViewItem * after ); | ||
130 | OListViewItem( QListViewItem * parent, QListViewItem * after ); | ||
131 | |||
132 | OListViewItem( QListView * parent, | ||
133 | QString, QString = QString::null, | ||
134 | QString = QString::null, QString = QString::null, | ||
135 | QString = QString::null, QString = QString::null, | ||
136 | QString = QString::null, QString = QString::null ); | ||
137 | |||
138 | OListViewItem( QListViewItem * parent, | ||
139 | QString, QString = QString::null, | ||
140 | QString = QString::null, QString = QString::null, | ||
141 | QString = QString::null, QString = QString::null, | ||
142 | QString = QString::null, QString = QString::null ); | ||
143 | |||
144 | OListViewItem( QListView * parent, QListViewItem * after, | ||
145 | QString, QString = QString::null, | ||
146 | QString = QString::null, QString = QString::null, | ||
147 | QString = QString::null, QString = QString::null, | ||
148 | QString = QString::null, QString = QString::null ); | ||
149 | |||
150 | OListViewItem( QListViewItem * parent, QListViewItem * after, | ||
151 | QString, QString = QString::null, | ||
152 | QString = QString::null, QString = QString::null, | ||
153 | QString = QString::null, QString = QString::null, | ||
154 | QString = QString::null, QString = QString::null ); | ||
155 | |||
156 | virtual ~OListViewItem(); | ||
157 | |||
158 | const QColor& backgroundColor(); | ||
159 | bool isAlternate(); | ||
160 | void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); | ||
161 | void init(); | ||
162 | |||
163 | private: | ||
164 | bool m_known; | ||
165 | bool m_odd; | ||
166 | }; | ||
167 | |||
168 | #endif | ||