-rw-r--r-- | libopie2/opieui/olistview.cpp | 8 | ||||
-rw-r--r-- | libopie2/opieui/opopupmenu.cpp | 4 | ||||
-rw-r--r-- | libopie2/opieui/oselector.cpp | 2 | ||||
-rw-r--r-- | libopie2/opieui/oselector.h | 4 |
4 files changed, 9 insertions, 9 deletions
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp index 67b4b83..4386e0e 100644 --- a/libopie2/opieui/olistview.cpp +++ b/libopie2/opieui/olistview.cpp | |||
@@ -1,768 +1,768 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | .=l. | 4 | .=l. |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | /* QT */ | 30 | /* QT */ |
31 | 31 | ||
32 | #include <qpixmap.h> | 32 | #include <qpixmap.h> |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | 35 | ||
36 | #include <opie2/odebug.h> | 36 | #include <opie2/odebug.h> |
37 | #include <opie2/olistview.h> | 37 | #include <opie2/olistview.h> |
38 | 38 | ||
39 | using namespace Opie::Core; | 39 | using namespace Opie::Core; |
40 | 40 | ||
41 | 41 | ||
42 | namespace Opie { | 42 | namespace Opie { |
43 | namespace Ui { | 43 | namespace Ui { |
44 | /*====================================================================================== | 44 | /*====================================================================================== |
45 | * OListView | 45 | * OListView |
46 | *======================================================================================*/ | 46 | *======================================================================================*/ |
47 | 47 | ||
48 | OListView::OListView( QWidget *parent, const char *name, WFlags fl ) | 48 | OListView::OListView( QWidget *parent, const char *name, WFlags fl ) |
49 | :QListView( parent, name, fl ) | 49 | :QListView( parent, name, fl ) |
50 | { | 50 | { |
51 | //FIXME: get from global settings and calculate ==> see oglobalsettings.* | 51 | //FIXME: get from global settings and calculate ==> see oglobalsettings.* |
52 | 52 | ||
53 | m_alternateBackground = QColor( 238, 246, 255 ); | 53 | m_alternateBackground = QColor( 238, 246, 255 ); |
54 | m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); | 54 | m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); |
55 | m_fullWidth = true; | 55 | m_fullWidth = true; |
56 | connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*))); | 56 | connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*))); |
57 | } | 57 | } |
58 | 58 | ||
59 | OListView::~OListView() | 59 | OListView::~OListView() |
60 | { | 60 | { |
61 | } | 61 | } |
62 | 62 | ||
63 | void OListView::setFullWidth( bool fullWidth ) | 63 | void OListView::setFullWidth( bool fullWidth ) |
64 | { | 64 | { |
65 | m_fullWidth = fullWidth; | 65 | m_fullWidth = fullWidth; |
66 | #if QT_VERSION > 290 | 66 | #if QT_VERSION >= 0x030000 |
67 | header()->setStretchEnabled( fullWidth, columns()-1 ); | 67 | header()->setStretchEnabled( fullWidth, columns()-1 ); |
68 | #endif | 68 | #endif |
69 | } | 69 | } |
70 | 70 | ||
71 | bool OListView::fullWidth() const | 71 | bool OListView::fullWidth() const |
72 | { | 72 | { |
73 | return m_fullWidth; | 73 | return m_fullWidth; |
74 | } | 74 | } |
75 | 75 | ||
76 | int OListView::addColumn( const QString& label, int width ) | 76 | int OListView::addColumn( const QString& label, int width ) |
77 | { | 77 | { |
78 | int result = QListView::addColumn( label, width ); | 78 | int result = QListView::addColumn( label, width ); |
79 | #if QT_VERSION > 290 | 79 | #if QT_VERSION >= 0x030000 |
80 | if (m_fullWidth) { | 80 | if (m_fullWidth) { |
81 | header()->setStretchEnabled( false, columns()-2 ); | 81 | header()->setStretchEnabled( false, columns()-2 ); |
82 | header()->setStretchEnabled( true, columns()-1 ); | 82 | header()->setStretchEnabled( true, columns()-1 ); |
83 | } | 83 | } |
84 | #endif | 84 | #endif |
85 | return result; | 85 | return result; |
86 | } | 86 | } |
87 | 87 | ||
88 | int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) | 88 | int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) |
89 | { | 89 | { |
90 | int result = QListView::addColumn( iconset, label, width ); | 90 | int result = QListView::addColumn( iconset, label, width ); |
91 | #if QT_VERSION > 290 | 91 | #if QT_VERSION >= 0x030000 |
92 | if (m_fullWidth) { | 92 | if (m_fullWidth) { |
93 | header()->setStretchEnabled( false, columns()-2 ); | 93 | header()->setStretchEnabled( false, columns()-2 ); |
94 | header()->setStretchEnabled( true, columns()-1 ); | 94 | header()->setStretchEnabled( true, columns()-1 ); |
95 | } | 95 | } |
96 | #endif | 96 | #endif |
97 | return result; | 97 | return result; |
98 | } | 98 | } |
99 | 99 | ||
100 | void OListView::removeColumn( int index ) | 100 | void OListView::removeColumn( int index ) |
101 | { | 101 | { |
102 | QListView::removeColumn(index); | 102 | QListView::removeColumn(index); |
103 | #if QT_VERSION > 290 | 103 | #if QT_VERSION >= 0x030000 |
104 | if ( m_fullWidth && index == columns() ) | 104 | if ( m_fullWidth && index == columns() ) |
105 | { | 105 | { |
106 | header()->setStretchEnabled( true, columns()-1 ); | 106 | header()->setStretchEnabled( true, columns()-1 ); |
107 | } | 107 | } |
108 | #endif | 108 | #endif |
109 | } | 109 | } |
110 | 110 | ||
111 | const QColor& OListView::alternateBackground() const | 111 | const QColor& OListView::alternateBackground() const |
112 | { | 112 | { |
113 | return m_alternateBackground; | 113 | return m_alternateBackground; |
114 | } | 114 | } |
115 | 115 | ||
116 | void OListView::setAlternateBackground( const QColor &c ) | 116 | void OListView::setAlternateBackground( const QColor &c ) |
117 | { | 117 | { |
118 | m_alternateBackground = c; | 118 | m_alternateBackground = c; |
119 | repaint(); | 119 | repaint(); |
120 | } | 120 | } |
121 | 121 | ||
122 | const QPen& OListView::columnSeparator() const | 122 | const QPen& OListView::columnSeparator() const |
123 | { | 123 | { |
124 | return m_columnSeparator; | 124 | return m_columnSeparator; |
125 | } | 125 | } |
126 | 126 | ||
127 | void OListView::setColumnSeparator( const QPen& p ) | 127 | void OListView::setColumnSeparator( const QPen& p ) |
128 | { | 128 | { |
129 | m_columnSeparator = p; | 129 | m_columnSeparator = p; |
130 | repaint(); | 130 | repaint(); |
131 | } | 131 | } |
132 | 132 | ||
133 | void OListView::expand(QListViewItem *item) | 133 | void OListView::expand(QListViewItem *item) |
134 | { | 134 | { |
135 | ((OListViewItem*)item)->expand(); | 135 | ((OListViewItem*)item)->expand(); |
136 | } | 136 | } |
137 | 137 | ||
138 | OListViewItem* OListView::childFactory() | 138 | OListViewItem* OListView::childFactory() |
139 | { | 139 | { |
140 | return new OListViewItem( this ); | 140 | return new OListViewItem( this ); |
141 | } | 141 | } |
142 | 142 | ||
143 | #ifndef QT_NO_DATASTREAM | 143 | #ifndef QT_NO_DATASTREAM |
144 | void OListView::serializeTo( QDataStream& s ) const | 144 | void OListView::serializeTo( QDataStream& s ) const |
145 | { | 145 | { |
146 | #warning Caution... the binary format is still under construction... | 146 | #warning Caution... the binary format is still under construction... |
147 | odebug << "storing OListView..." << oendl; | 147 | odebug << "storing OListView..." << oendl; |
148 | 148 | ||
149 | // store number of columns and the labels | 149 | // store number of columns and the labels |
150 | s << columns(); | 150 | s << columns(); |
151 | for ( int i = 0; i < columns(); ++i ) | 151 | for ( int i = 0; i < columns(); ++i ) |
152 | s << columnText( i ); | 152 | s << columnText( i ); |
153 | 153 | ||
154 | // calculate the number of top-level items to serialize | 154 | // calculate the number of top-level items to serialize |
155 | int items = 0; | 155 | int items = 0; |
156 | QListViewItem* item = firstChild(); | 156 | QListViewItem* item = firstChild(); |
157 | while ( item ) | 157 | while ( item ) |
158 | { | 158 | { |
159 | item = item->nextSibling(); | 159 | item = item->nextSibling(); |
160 | items++; | 160 | items++; |
161 | } | 161 | } |
162 | 162 | ||
163 | // store number of items and the items itself | 163 | // store number of items and the items itself |
164 | s << items; | 164 | s << items; |
165 | item = firstChild(); | 165 | item = firstChild(); |
166 | for ( int i = 0; i < items; ++i ) | 166 | for ( int i = 0; i < items; ++i ) |
167 | { | 167 | { |
168 | s << *static_cast<OListViewItem*>( item ); | 168 | s << *static_cast<OListViewItem*>( item ); |
169 | item = item->nextSibling(); | 169 | item = item->nextSibling(); |
170 | } | 170 | } |
171 | 171 | ||
172 | odebug << "OListview stored." << oendl; | 172 | odebug << "OListview stored." << oendl; |
173 | } | 173 | } |
174 | 174 | ||
175 | void OListView::serializeFrom( QDataStream& s ) | 175 | void OListView::serializeFrom( QDataStream& s ) |
176 | { | 176 | { |
177 | #warning Caution... the binary format is still under construction... | 177 | #warning Caution... the binary format is still under construction... |
178 | odebug << "loading OListView..." << oendl; | 178 | odebug << "loading OListView..." << oendl; |
179 | 179 | ||
180 | int cols; | 180 | int cols; |
181 | s >> cols; | 181 | s >> cols; |
182 | odebug << "read number of columns = " << cols << oendl; | 182 | odebug << "read number of columns = " << cols << oendl; |
183 | 183 | ||
184 | while ( columns() < cols ) addColumn( QString::null ); | 184 | while ( columns() < cols ) addColumn( QString::null ); |
185 | 185 | ||
186 | for ( int i = 0; i < cols; ++i ) | 186 | for ( int i = 0; i < cols; ++i ) |
187 | { | 187 | { |
188 | QString coltext; | 188 | QString coltext; |
189 | s >> coltext; | 189 | s >> coltext; |
190 | odebug << "read text '" << coltext << "' for column " << i << "" << oendl; | 190 | odebug << "read text '" << coltext << "' for column " << i << "" << oendl; |
191 | setColumnText( i, coltext ); | 191 | setColumnText( i, coltext ); |
192 | } | 192 | } |
193 | 193 | ||
194 | int items; | 194 | int items; |
195 | s >> items; | 195 | s >> items; |
196 | odebug << "read number of items = " << items << oendl; | 196 | odebug << "read number of items = " << items << oendl; |
197 | 197 | ||
198 | for ( int i = 0; i < items; ++i ) | 198 | for ( int i = 0; i < items; ++i ) |
199 | { | 199 | { |
200 | OListViewItem* item = childFactory(); | 200 | OListViewItem* item = childFactory(); |
201 | s >> *item; | 201 | s >> *item; |
202 | } | 202 | } |
203 | 203 | ||
204 | odebug << "OListView loaded." << oendl; | 204 | odebug << "OListView loaded." << oendl; |
205 | 205 | ||
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | void OListView::expand() | 209 | void OListView::expand() |
210 | { | 210 | { |
211 | odebug << "OListView::expand" << oendl; | 211 | odebug << "OListView::expand" << oendl; |
212 | 212 | ||
213 | QListViewItemIterator it( this ); | 213 | QListViewItemIterator it( this ); |
214 | while ( it.current() ) { | 214 | while ( it.current() ) { |
215 | it.current()->setOpen( true ); | 215 | it.current()->setOpen( true ); |
216 | ++it; | 216 | ++it; |
217 | } | 217 | } |
218 | } | 218 | } |
219 | 219 | ||
220 | 220 | ||
221 | void OListView::collapse() | 221 | void OListView::collapse() |
222 | { | 222 | { |
223 | odebug << "OListView::collapse" << oendl; | 223 | odebug << "OListView::collapse" << oendl; |
224 | QListViewItemIterator it( this ); | 224 | QListViewItemIterator it( this ); |
225 | while ( it.current() ) { | 225 | while ( it.current() ) { |
226 | it.current()->setOpen( false ); | 226 | it.current()->setOpen( false ); |
227 | ++it; | 227 | ++it; |
228 | } | 228 | } |
229 | } | 229 | } |
230 | 230 | ||
231 | 231 | ||
232 | QDataStream& operator<<( QDataStream& s, const OListView& lv ) | 232 | QDataStream& operator<<( QDataStream& s, const OListView& lv ) |
233 | { | 233 | { |
234 | lv.serializeTo( s ); | 234 | lv.serializeTo( s ); |
235 | return s; | 235 | return s; |
236 | } | 236 | } |
237 | 237 | ||
238 | QDataStream& operator>>( QDataStream& s, OListView& lv ) | 238 | QDataStream& operator>>( QDataStream& s, OListView& lv ) |
239 | { | 239 | { |
240 | lv.serializeFrom( s ); | 240 | lv.serializeFrom( s ); |
241 | return s; | 241 | return s; |
242 | } | 242 | } |
243 | #endif // QT_NO_DATASTREAM | 243 | #endif // QT_NO_DATASTREAM |
244 | 244 | ||
245 | /*====================================================================================== | 245 | /*====================================================================================== |
246 | * OListViewItem | 246 | * OListViewItem |
247 | *======================================================================================*/ | 247 | *======================================================================================*/ |
248 | 248 | ||
249 | OListViewItem::OListViewItem(QListView *parent) | 249 | OListViewItem::OListViewItem(QListView *parent) |
250 | : QListViewItem(parent) | 250 | : QListViewItem(parent) |
251 | { | 251 | { |
252 | init(); | 252 | init(); |
253 | } | 253 | } |
254 | 254 | ||
255 | 255 | ||
256 | OListViewItem::OListViewItem(QListViewItem *parent) | 256 | OListViewItem::OListViewItem(QListViewItem *parent) |
257 | : QListViewItem(parent) | 257 | : QListViewItem(parent) |
258 | { | 258 | { |
259 | init(); | 259 | init(); |
260 | } | 260 | } |
261 | 261 | ||
262 | 262 | ||
263 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) | 263 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) |
264 | : QListViewItem(parent, after) | 264 | : QListViewItem(parent, after) |
265 | { | 265 | { |
266 | init(); | 266 | init(); |
267 | } | 267 | } |
268 | 268 | ||
269 | 269 | ||
270 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) | 270 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) |
271 | : QListViewItem(parent, after) | 271 | : QListViewItem(parent, after) |
272 | { | 272 | { |
273 | init(); | 273 | init(); |
274 | } | 274 | } |
275 | 275 | ||
276 | 276 | ||
277 | OListViewItem::OListViewItem(QListView *parent, | 277 | OListViewItem::OListViewItem(QListView *parent, |
278 | QString label1, QString label2, QString label3, QString label4, | 278 | QString label1, QString label2, QString label3, QString label4, |
279 | QString label5, QString label6, QString label7, QString label8) | 279 | QString label5, QString label6, QString label7, QString label8) |
280 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 280 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
281 | { | 281 | { |
282 | init(); | 282 | init(); |
283 | } | 283 | } |
284 | 284 | ||
285 | 285 | ||
286 | OListViewItem::OListViewItem(QListViewItem *parent, | 286 | OListViewItem::OListViewItem(QListViewItem *parent, |
287 | QString label1, QString label2, QString label3, QString label4, | 287 | QString label1, QString label2, QString label3, QString label4, |
288 | QString label5, QString label6, QString label7, QString label8) | 288 | QString label5, QString label6, QString label7, QString label8) |
289 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 289 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
290 | { | 290 | { |
291 | init(); | 291 | init(); |
292 | } | 292 | } |
293 | 293 | ||
294 | 294 | ||
295 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, | 295 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, |
296 | QString label1, QString label2, QString label3, QString label4, | 296 | QString label1, QString label2, QString label3, QString label4, |
297 | QString label5, QString label6, QString label7, QString label8) | 297 | QString label5, QString label6, QString label7, QString label8) |
298 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 298 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
299 | { | 299 | { |
300 | init(); | 300 | init(); |
301 | } | 301 | } |
302 | 302 | ||
303 | 303 | ||
304 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, | 304 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, |
305 | QString label1, QString label2, QString label3, QString label4, | 305 | QString label1, QString label2, QString label3, QString label4, |
306 | QString label5, QString label6, QString label7, QString label8) | 306 | QString label5, QString label6, QString label7, QString label8) |
307 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 307 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
308 | { | 308 | { |
309 | init(); | 309 | init(); |
310 | } | 310 | } |
311 | 311 | ||
312 | 312 | ||
313 | OListViewItem::~OListViewItem() | 313 | OListViewItem::~OListViewItem() |
314 | { | 314 | { |
315 | } | 315 | } |
316 | 316 | ||
317 | 317 | ||
318 | void OListViewItem::init() | 318 | void OListViewItem::init() |
319 | { | 319 | { |
320 | m_known = false; | 320 | m_known = false; |
321 | } | 321 | } |
322 | 322 | ||
323 | 323 | ||
324 | const QColor &OListViewItem::backgroundColor() | 324 | const QColor &OListViewItem::backgroundColor() |
325 | { | 325 | { |
326 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : | 326 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : |
327 | listView()->viewport()->colorGroup().base(); | 327 | listView()->viewport()->colorGroup().base(); |
328 | } | 328 | } |
329 | 329 | ||
330 | 330 | ||
331 | bool OListViewItem::isAlternate() | 331 | bool OListViewItem::isAlternate() |
332 | { | 332 | { |
333 | OListView *lv = static_cast<OListView*>( listView() ); | 333 | OListView *lv = static_cast<OListView*>( listView() ); |
334 | 334 | ||
335 | // check if the item above is an OListViewItem | 335 | // check if the item above is an OListViewItem |
336 | OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); | 336 | OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); |
337 | /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ | 337 | /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ |
338 | 338 | ||
339 | // check if we have a valid alternate background color | 339 | // check if we have a valid alternate background color |
340 | if (!(lv && lv->alternateBackground().isValid())) return false; | 340 | if (!(lv && lv->alternateBackground().isValid())) return false; |
341 | 341 | ||
342 | m_known = above ? above->m_known : true; | 342 | m_known = above ? above->m_known : true; |
343 | if (m_known) | 343 | if (m_known) |
344 | { | 344 | { |
345 | m_odd = above ? !above->m_odd : false; | 345 | m_odd = above ? !above->m_odd : false; |
346 | } | 346 | } |
347 | else | 347 | else |
348 | { | 348 | { |
349 | OListViewItem *item; | 349 | OListViewItem *item; |
350 | bool previous = true; | 350 | bool previous = true; |
351 | if (parent()) | 351 | if (parent()) |
352 | { | 352 | { |
353 | item = static_cast<OListViewItem *>(parent()); | 353 | item = static_cast<OListViewItem *>(parent()); |
354 | if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; | 354 | if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; |
355 | item = static_cast<OListViewItem *>(parent()->firstChild()); | 355 | item = static_cast<OListViewItem *>(parent()->firstChild()); |
356 | /* if ( !item.inherits( "OListViewItem" ) item = 0; */ | 356 | /* if ( !item.inherits( "OListViewItem" ) item = 0; */ |
357 | } | 357 | } |
358 | else | 358 | else |
359 | { | 359 | { |
360 | item = static_cast<OListViewItem *>(lv->firstChild()); | 360 | item = static_cast<OListViewItem *>(lv->firstChild()); |
361 | } | 361 | } |
362 | 362 | ||
363 | while(item) | 363 | while(item) |
364 | { | 364 | { |
365 | item->m_odd = previous = !previous; | 365 | item->m_odd = previous = !previous; |
366 | item->m_known = true; | 366 | item->m_known = true; |
367 | item = static_cast<OListViewItem *>(item->nextSibling()); | 367 | item = static_cast<OListViewItem *>(item->nextSibling()); |
368 | /* if (!item.inherits( "OListViewItem" ) ) break; */ | 368 | /* if (!item.inherits( "OListViewItem" ) ) break; */ |
369 | } | 369 | } |
370 | } | 370 | } |
371 | return m_odd; | 371 | return m_odd; |
372 | } | 372 | } |
373 | 373 | ||
374 | 374 | ||
375 | void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) | 375 | void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) |
376 | { | 376 | { |
377 | QColorGroup _cg = cg; | 377 | QColorGroup _cg = cg; |
378 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); | 378 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); |
379 | if (pm && !pm->isNull()) | 379 | if (pm && !pm->isNull()) |
380 | { | 380 | { |
381 | _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); | 381 | _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); |
382 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); | 382 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); |
383 | } | 383 | } |
384 | else if ( isAlternate() ) | 384 | else if ( isAlternate() ) |
385 | { | 385 | { |
386 | _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); | 386 | _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); |
387 | } | 387 | } |
388 | QListViewItem::paintCell( p, _cg, column, width, alignment ); | 388 | QListViewItem::paintCell( p, _cg, column, width, alignment ); |
389 | 389 | ||
390 | //FIXME: Use styling here! | 390 | //FIXME: Use styling here! |
391 | 391 | ||
392 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); | 392 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); |
393 | p->setPen( pen ); | 393 | p->setPen( pen ); |
394 | p->drawLine( width-1, 0, width-1, height() ); | 394 | p->drawLine( width-1, 0, width-1, height() ); |
395 | } | 395 | } |
396 | 396 | ||
397 | 397 | ||
398 | OListViewItem* OListViewItem::childFactory() | 398 | OListViewItem* OListViewItem::childFactory() |
399 | { | 399 | { |
400 | return new OListViewItem( this ); | 400 | return new OListViewItem( this ); |
401 | } | 401 | } |
402 | 402 | ||
403 | 403 | ||
404 | #ifndef QT_NO_DATASTREAM | 404 | #ifndef QT_NO_DATASTREAM |
405 | void OListViewItem::serializeTo( QDataStream& s ) const | 405 | void OListViewItem::serializeTo( QDataStream& s ) const |
406 | { | 406 | { |
407 | #warning Caution... the binary format is still under construction... | 407 | #warning Caution... the binary format is still under construction... |
408 | odebug << "storing OListViewItem..." << oendl; | 408 | odebug << "storing OListViewItem..." << oendl; |
409 | 409 | ||
410 | // store item text | 410 | // store item text |
411 | for ( int i = 0; i < listView()->columns(); ++i ) | 411 | for ( int i = 0; i < listView()->columns(); ++i ) |
412 | { | 412 | { |
413 | s << text( i ); | 413 | s << text( i ); |
414 | } | 414 | } |
415 | 415 | ||
416 | // calculate the number of children to serialize | 416 | // calculate the number of children to serialize |
417 | int items = 0; | 417 | int items = 0; |
418 | QListViewItem* item = firstChild(); | 418 | QListViewItem* item = firstChild(); |
419 | while ( item ) | 419 | while ( item ) |
420 | { | 420 | { |
421 | item = item->nextSibling(); | 421 | item = item->nextSibling(); |
422 | items++; | 422 | items++; |
423 | } | 423 | } |
424 | 424 | ||
425 | // store number of items and the items itself | 425 | // store number of items and the items itself |
426 | s << items; | 426 | s << items; |
427 | item = firstChild(); | 427 | item = firstChild(); |
428 | for ( int i = 0; i < items; ++i ) | 428 | for ( int i = 0; i < items; ++i ) |
429 | { | 429 | { |
430 | s << *static_cast<OListViewItem*>( item ); | 430 | s << *static_cast<OListViewItem*>( item ); |
431 | item = item->nextSibling(); | 431 | item = item->nextSibling(); |
432 | } | 432 | } |
433 | 433 | ||
434 | odebug << "OListviewItem stored." << oendl; | 434 | odebug << "OListviewItem stored." << oendl; |
435 | } | 435 | } |
436 | 436 | ||
437 | 437 | ||
438 | void OListViewItem::serializeFrom( QDataStream& s ) | 438 | void OListViewItem::serializeFrom( QDataStream& s ) |
439 | { | 439 | { |
440 | #warning Caution... the binary format is still under construction... | 440 | #warning Caution... the binary format is still under construction... |
441 | odebug << "loading OListViewItem..." << oendl; | 441 | odebug << "loading OListViewItem..." << oendl; |
442 | 442 | ||
443 | for ( int i = 0; i < listView()->columns(); ++i ) | 443 | for ( int i = 0; i < listView()->columns(); ++i ) |
444 | { | 444 | { |
445 | QString coltext; | 445 | QString coltext; |
446 | s >> coltext; | 446 | s >> coltext; |
447 | odebug << "read text '" << coltext << "' for column " << i << "" << oendl; | 447 | odebug << "read text '" << coltext << "' for column " << i << "" << oendl; |
448 | setText( i, coltext ); | 448 | setText( i, coltext ); |
449 | } | 449 | } |
450 | 450 | ||
451 | int items; | 451 | int items; |
452 | s >> items; | 452 | s >> items; |
453 | odebug << "read number of items = " << items << "" << oendl; | 453 | odebug << "read number of items = " << items << "" << oendl; |
454 | 454 | ||
455 | for ( int i = 0; i < items; ++i ) | 455 | for ( int i = 0; i < items; ++i ) |
456 | { | 456 | { |
457 | OListViewItem* item = childFactory(); | 457 | OListViewItem* item = childFactory(); |
458 | s >> (*item); | 458 | s >> (*item); |
459 | } | 459 | } |
460 | 460 | ||
461 | odebug << "OListViewItem loaded." << oendl; | 461 | odebug << "OListViewItem loaded." << oendl; |
462 | } | 462 | } |
463 | 463 | ||
464 | 464 | ||
465 | QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) | 465 | QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) |
466 | { | 466 | { |
467 | lvi.serializeTo( s ); | 467 | lvi.serializeTo( s ); |
468 | return s; | 468 | return s; |
469 | } | 469 | } |
470 | 470 | ||
471 | 471 | ||
472 | QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) | 472 | QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) |
473 | { | 473 | { |
474 | lvi.serializeFrom( s ); | 474 | lvi.serializeFrom( s ); |
475 | return s; | 475 | return s; |
476 | } | 476 | } |
477 | #endif // QT_NO_DATASTREAM | 477 | #endif // QT_NO_DATASTREAM |
478 | 478 | ||
479 | 479 | ||
480 | /*====================================================================================== | 480 | /*====================================================================================== |
481 | * OCheckListItem | 481 | * OCheckListItem |
482 | *======================================================================================*/ | 482 | *======================================================================================*/ |
483 | 483 | ||
484 | OCheckListItem::OCheckListItem( QCheckListItem* parent, const QString& text, Type t ) | 484 | OCheckListItem::OCheckListItem( QCheckListItem* parent, const QString& text, Type t ) |
485 | :QCheckListItem( parent, text, t ) | 485 | :QCheckListItem( parent, text, t ) |
486 | { | 486 | { |
487 | init(); | 487 | init(); |
488 | } | 488 | } |
489 | 489 | ||
490 | 490 | ||
491 | OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, Type t) | 491 | OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, Type t) |
492 | :QCheckListItem( parent, text, t ) | 492 | :QCheckListItem( parent, text, t ) |
493 | { | 493 | { |
494 | init(); | 494 | init(); |
495 | } | 495 | } |
496 | 496 | ||
497 | 497 | ||
498 | OCheckListItem::OCheckListItem( QListView* parent, const QString& text, Type t ) | 498 | OCheckListItem::OCheckListItem( QListView* parent, const QString& text, Type t ) |
499 | :QCheckListItem( parent, text, t ) | 499 | :QCheckListItem( parent, text, t ) |
500 | { | 500 | { |
501 | init(); | 501 | init(); |
502 | } | 502 | } |
503 | 503 | ||
504 | 504 | ||
505 | OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, const QPixmap& p ) | 505 | OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, const QPixmap& p ) |
506 | :QCheckListItem( parent, text, p ) | 506 | :QCheckListItem( parent, text, p ) |
507 | { | 507 | { |
508 | init(); | 508 | init(); |
509 | } | 509 | } |
510 | 510 | ||
511 | 511 | ||
512 | OCheckListItem::OCheckListItem( QListView* parent, const QString& text, const QPixmap& p ) | 512 | OCheckListItem::OCheckListItem( QListView* parent, const QString& text, const QPixmap& p ) |
513 | :QCheckListItem( parent, text, p ) | 513 | :QCheckListItem( parent, text, p ) |
514 | { | 514 | { |
515 | init(); | 515 | init(); |
516 | } | 516 | } |
517 | 517 | ||
518 | 518 | ||
519 | OCheckListItem::~OCheckListItem() | 519 | OCheckListItem::~OCheckListItem() |
520 | { | 520 | { |
521 | } | 521 | } |
522 | 522 | ||
523 | void OCheckListItem::init() | 523 | void OCheckListItem::init() |
524 | { | 524 | { |
525 | m_known = false; | 525 | m_known = false; |
526 | } | 526 | } |
527 | 527 | ||
528 | 528 | ||
529 | const QColor &OCheckListItem::backgroundColor() | 529 | const QColor &OCheckListItem::backgroundColor() |
530 | { | 530 | { |
531 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : | 531 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : |
532 | listView()->viewport()->colorGroup().base(); | 532 | listView()->viewport()->colorGroup().base(); |
533 | } | 533 | } |
534 | 534 | ||
535 | 535 | ||
536 | bool OCheckListItem::isAlternate() | 536 | bool OCheckListItem::isAlternate() |
537 | { | 537 | { |
538 | OListView *lv = static_cast<OListView*>( listView() ); | 538 | OListView *lv = static_cast<OListView*>( listView() ); |
539 | 539 | ||
540 | // check if the item above is an OCheckListItem | 540 | // check if the item above is an OCheckListItem |
541 | OCheckListItem *above = static_cast<OCheckListItem*>( itemAbove() ); | 541 | OCheckListItem *above = static_cast<OCheckListItem*>( itemAbove() ); |
542 | /*if (! itemAbove()->inherits( "OCheckListItem" )) return false;*/ | 542 | /*if (! itemAbove()->inherits( "OCheckListItem" )) return false;*/ |
543 | 543 | ||
544 | // check if we have a valid alternate background color | 544 | // check if we have a valid alternate background color |
545 | if (!(lv && lv->alternateBackground().isValid())) return false; | 545 | if (!(lv && lv->alternateBackground().isValid())) return false; |
546 | 546 | ||
547 | m_known = above ? above->m_known : true; | 547 | m_known = above ? above->m_known : true; |
548 | if (m_known) | 548 | if (m_known) |
549 | { | 549 | { |
550 | m_odd = above ? !above->m_odd : false; | 550 | m_odd = above ? !above->m_odd : false; |
551 | } | 551 | } |
552 | else | 552 | else |
553 | { | 553 | { |
554 | OCheckListItem *item; | 554 | OCheckListItem *item; |
555 | bool previous = true; | 555 | bool previous = true; |
556 | if (parent()) | 556 | if (parent()) |
557 | { | 557 | { |
558 | item = static_cast<OCheckListItem *>(parent()); | 558 | item = static_cast<OCheckListItem *>(parent()); |
559 | if ( item /*&& item->inherits( "OCheckListItem" )*/ ) previous = item->m_odd; | 559 | if ( item /*&& item->inherits( "OCheckListItem" )*/ ) previous = item->m_odd; |
560 | item = static_cast<OCheckListItem *>(parent()->firstChild()); | 560 | item = static_cast<OCheckListItem *>(parent()->firstChild()); |
561 | /* if ( !item.inherits( "OCheckListItem" ) item = 0; */ | 561 | /* if ( !item.inherits( "OCheckListItem" ) item = 0; */ |
562 | } | 562 | } |
563 | else | 563 | else |
564 | { | 564 | { |
565 | item = static_cast<OCheckListItem *>(lv->firstChild()); | 565 | item = static_cast<OCheckListItem *>(lv->firstChild()); |
566 | } | 566 | } |
567 | 567 | ||
568 | while(item) | 568 | while(item) |
569 | { | 569 | { |
570 | item->m_odd = previous = !previous; | 570 | item->m_odd = previous = !previous; |
571 | item->m_known = true; | 571 | item->m_known = true; |
572 | item = static_cast<OCheckListItem *>(item->nextSibling()); | 572 | item = static_cast<OCheckListItem *>(item->nextSibling()); |
573 | /* if (!item.inherits( "OCheckListItem" ) ) break; */ | 573 | /* if (!item.inherits( "OCheckListItem" ) ) break; */ |
574 | } | 574 | } |
575 | } | 575 | } |
576 | return m_odd; | 576 | return m_odd; |
577 | } | 577 | } |
578 | 578 | ||
579 | 579 | ||
580 | void OCheckListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) | 580 | void OCheckListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) |
581 | { | 581 | { |
582 | QColorGroup _cg = cg; | 582 | QColorGroup _cg = cg; |
583 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); | 583 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); |
584 | if (pm && !pm->isNull()) | 584 | if (pm && !pm->isNull()) |
585 | { | 585 | { |
586 | _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); | 586 | _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); |
587 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); | 587 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); |
588 | } | 588 | } |
589 | else if ( isAlternate() ) | 589 | else if ( isAlternate() ) |
590 | { | 590 | { |
591 | _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); | 591 | _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); |
592 | } | 592 | } |
593 | QCheckListItem::paintCell( p, _cg, column, width, alignment ); | 593 | QCheckListItem::paintCell( p, _cg, column, width, alignment ); |
594 | 594 | ||
595 | //FIXME: Use styling here! | 595 | //FIXME: Use styling here! |
596 | 596 | ||
597 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); | 597 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); |
598 | p->setPen( pen ); | 598 | p->setPen( pen ); |
599 | p->drawLine( width-1, 0, width-1, height() ); | 599 | p->drawLine( width-1, 0, width-1, height() ); |
600 | } | 600 | } |
601 | 601 | ||
602 | 602 | ||
603 | /*====================================================================================== | 603 | /*====================================================================================== |
604 | * ONamedListView | 604 | * ONamedListView |
605 | *======================================================================================*/ | 605 | *======================================================================================*/ |
606 | 606 | ||
607 | ONamedListView::ONamedListView( QWidget *parent, const char *name ) | 607 | ONamedListView::ONamedListView( QWidget *parent, const char *name ) |
608 | :OListView( parent, name ) | 608 | :OListView( parent, name ) |
609 | { | 609 | { |
610 | } | 610 | } |
611 | 611 | ||
612 | 612 | ||
613 | ONamedListView::~ONamedListView() | 613 | ONamedListView::~ONamedListView() |
614 | { | 614 | { |
615 | } | 615 | } |
616 | 616 | ||
617 | 617 | ||
618 | void ONamedListView::addColumns( const QStringList& columns ) | 618 | void ONamedListView::addColumns( const QStringList& columns ) |
619 | { | 619 | { |
620 | for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) | 620 | for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) |
621 | { | 621 | { |
622 | odebug << "adding column " << *it << "" << oendl; | 622 | odebug << "adding column " << *it << "" << oendl; |
623 | addColumn( *it ); | 623 | addColumn( *it ); |
624 | } | 624 | } |
625 | } | 625 | } |
626 | 626 | ||
627 | 627 | ||
628 | int ONamedListView::findColumn( const QString& text ) const | 628 | int ONamedListView::findColumn( const QString& text ) const |
629 | { | 629 | { |
630 | //FIXME: If used excessively, this will slow down performance of updates | 630 | //FIXME: If used excessively, this will slow down performance of updates |
631 | //FIXME: because of the linear search over all column texts. | 631 | //FIXME: because of the linear search over all column texts. |
632 | //FIXME: I will optimize later by using a hash map. | 632 | //FIXME: I will optimize later by using a hash map. |
633 | for ( int i = 0; i < columns(); ++i ) | 633 | for ( int i = 0; i < columns(); ++i ) |
634 | if ( columnText( i ) == text ) | 634 | if ( columnText( i ) == text ) |
635 | return i; | 635 | return i; |
636 | return -1; | 636 | return -1; |
637 | } | 637 | } |
638 | 638 | ||
639 | 639 | ||
640 | ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const | 640 | ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const |
641 | { | 641 | { |
642 | return find( (ONamedListViewItem*) firstChild(), column, text, recurse ); | 642 | return find( (ONamedListViewItem*) firstChild(), column, text, recurse ); |
643 | } | 643 | } |
644 | 644 | ||
645 | 645 | ||
646 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const | 646 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const |
647 | { | 647 | { |
648 | ONamedListViewItem* result; | 648 | ONamedListViewItem* result; |
649 | while ( item && item->text( column ) != text ) | 649 | while ( item && item->text( column ) != text ) |
650 | { | 650 | { |
651 | odebug << "checked " << item->text( column ) << "" << oendl; | 651 | odebug << "checked " << item->text( column ) << "" << oendl; |
652 | 652 | ||
653 | if ( recurse < 0 || recurse > 0 ) | 653 | if ( recurse < 0 || recurse > 0 ) |
654 | { | 654 | { |
655 | odebug << "recursion is " << recurse << " - recursing into..." << oendl; | 655 | odebug << "recursion is " << recurse << " - recursing into..." << oendl; |
656 | result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 ); | 656 | result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 ); |
657 | if ( result ) return result; | 657 | if ( result ) return result; |
658 | } | 658 | } |
659 | 659 | ||
660 | 660 | ||
661 | item = (ONamedListViewItem*) item->itemBelow(); | 661 | item = (ONamedListViewItem*) item->itemBelow(); |
662 | } | 662 | } |
663 | if ( item && item->text( column ) == text ) | 663 | if ( item && item->text( column ) == text ) |
664 | return item; | 664 | return item; |
665 | else | 665 | else |
666 | return 0; | 666 | return 0; |
667 | } | 667 | } |
668 | 668 | ||
669 | 669 | ||
670 | ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const | 670 | ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const |
671 | { | 671 | { |
672 | int col = findColumn( column ); | 672 | int col = findColumn( column ); |
673 | if ( col != -1 ) | 673 | if ( col != -1 ) |
674 | return find( (ONamedListViewItem*) firstChild(), col, text, recurse ); | 674 | return find( (ONamedListViewItem*) firstChild(), col, text, recurse ); |
675 | else | 675 | else |
676 | return 0; | 676 | return 0; |
677 | } | 677 | } |
678 | 678 | ||
679 | 679 | ||
680 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const | 680 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const |
681 | { | 681 | { |
682 | int col = findColumn( column ); | 682 | int col = findColumn( column ); |
683 | if ( col != -1 ) | 683 | if ( col != -1 ) |
684 | return find( item, col, text, recurse ); | 684 | return find( item, col, text, recurse ); |
685 | else | 685 | else |
686 | return 0; | 686 | return 0; |
687 | } | 687 | } |
688 | 688 | ||
689 | 689 | ||
690 | /*====================================================================================== | 690 | /*====================================================================================== |
691 | * ONamedListViewItem | 691 | * ONamedListViewItem |
692 | *======================================================================================*/ | 692 | *======================================================================================*/ |
693 | 693 | ||
694 | ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) | 694 | ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) |
695 | :OListViewItem( parent ) | 695 | :OListViewItem( parent ) |
696 | { | 696 | { |
697 | setText( texts ); | 697 | setText( texts ); |
698 | } | 698 | } |
699 | 699 | ||
700 | 700 | ||
701 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) | 701 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) |
702 | :OListViewItem( parent ) | 702 | :OListViewItem( parent ) |
703 | { | 703 | { |
704 | setText( texts ); | 704 | setText( texts ); |
705 | } | 705 | } |
706 | 706 | ||
707 | 707 | ||
708 | ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) | 708 | ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) |
709 | :OListViewItem( parent, after ) | 709 | :OListViewItem( parent, after ) |
710 | { | 710 | { |
711 | setText( texts ); | 711 | setText( texts ); |
712 | } | 712 | } |
713 | 713 | ||
714 | 714 | ||
715 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) | 715 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) |
716 | :OListViewItem( parent, after ) | 716 | :OListViewItem( parent, after ) |
717 | { | 717 | { |
718 | setText( texts ); | 718 | setText( texts ); |
719 | } | 719 | } |
720 | 720 | ||
721 | 721 | ||
722 | ONamedListViewItem::~ONamedListViewItem() | 722 | ONamedListViewItem::~ONamedListViewItem() |
723 | { | 723 | { |
724 | } | 724 | } |
725 | 725 | ||
726 | 726 | ||
727 | void ONamedListViewItem::setText( const QStringList& texts ) | 727 | void ONamedListViewItem::setText( const QStringList& texts ) |
728 | { | 728 | { |
729 | int col = 0; | 729 | int col = 0; |
730 | for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) | 730 | for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) |
731 | { | 731 | { |
732 | odebug << "setting column " << col << " = text " << *it << "" << oendl; | 732 | odebug << "setting column " << col << " = text " << *it << "" << oendl; |
733 | OListViewItem::setText( col++, *it ); | 733 | OListViewItem::setText( col++, *it ); |
734 | } | 734 | } |
735 | 735 | ||
736 | } | 736 | } |
737 | 737 | ||
738 | 738 | ||
739 | void ONamedListViewItem::setText( const QString& column, const QString& text ) | 739 | void ONamedListViewItem::setText( const QString& column, const QString& text ) |
740 | { | 740 | { |
741 | //FIXME: If used excessively, this will slow down performance of updates | 741 | //FIXME: If used excessively, this will slow down performance of updates |
742 | //FIXME: because of the linear search over all column texts. | 742 | //FIXME: because of the linear search over all column texts. |
743 | //FIXME: I will optimize later by using a hash map. | 743 | //FIXME: I will optimize later by using a hash map. |
744 | int col = ( (ONamedListView*) listView() )->findColumn( column ); | 744 | int col = ( (ONamedListView*) listView() )->findColumn( column ); |
745 | if ( col != -1 ) | 745 | if ( col != -1 ) |
746 | OListViewItem::setText( col, text ); | 746 | OListViewItem::setText( col, text ); |
747 | else | 747 | else |
748 | owarn << "ONamedListViewItem::setText(): Warning! Columntext '" << column << "' not found." << oendl; | 748 | owarn << "ONamedListViewItem::setText(): Warning! Columntext '" << column << "' not found." << oendl; |
749 | } | 749 | } |
750 | 750 | ||
751 | 751 | ||
752 | ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const | 752 | ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const |
753 | { | 753 | { |
754 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse ); | 754 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse ); |
755 | } | 755 | } |
756 | 756 | ||
757 | 757 | ||
758 | ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const | 758 | ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const |
759 | { | 759 | { |
760 | int col = ( (ONamedListView*) listView() )->findColumn( column ); | 760 | int col = ( (ONamedListView*) listView() )->findColumn( column ); |
761 | if ( col != -1 ) | 761 | if ( col != -1 ) |
762 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse ); | 762 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse ); |
763 | else | 763 | else |
764 | return 0; | 764 | return 0; |
765 | } | 765 | } |
766 | 766 | ||
767 | } | 767 | } |
768 | } | 768 | } |
diff --git a/libopie2/opieui/opopupmenu.cpp b/libopie2/opieui/opopupmenu.cpp index 50c613f..5ce048e 100644 --- a/libopie2/opieui/opopupmenu.cpp +++ b/libopie2/opieui/opopupmenu.cpp | |||
@@ -1,600 +1,600 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org> | 2 | Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org> |
3 | Copyright (C) 2002 Hamish Rodda <meddie@yoyo.its.monash.edu.au> | 3 | Copyright (C) 2002 Hamish Rodda <meddie@yoyo.its.monash.edu.au> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License version 2 as published by the Free Software Foundation. | 7 | License version 2 as published by the Free Software Foundation. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | /* OPIE */ | 20 | /* OPIE */ |
21 | #include <opie2/opopupmenu.h> | 21 | #include <opie2/opopupmenu.h> |
22 | #include <opie2/oconfig.h> | 22 | #include <opie2/oconfig.h> |
23 | #include <opie2/odebug.h> | 23 | #include <opie2/odebug.h> |
24 | 24 | ||
25 | /* QT */ | 25 | /* QT */ |
26 | #include <qdrawutil.h> | 26 | #include <qdrawutil.h> |
27 | #include <qtimer.h> | 27 | #include <qtimer.h> |
28 | 28 | ||
29 | 29 | ||
30 | using namespace Opie::Core; | 30 | using namespace Opie::Core; |
31 | using namespace Opie::Ui; | 31 | using namespace Opie::Ui; |
32 | 32 | ||
33 | OPopupTitle::OPopupTitle(QWidget *parent, const char *name) | 33 | OPopupTitle::OPopupTitle(QWidget *parent, const char *name) |
34 | : QWidget(parent, name) | 34 | : QWidget(parent, name) |
35 | { | 35 | { |
36 | setMinimumSize(16, fontMetrics().height()+8); | 36 | setMinimumSize(16, fontMetrics().height()+8); |
37 | } | 37 | } |
38 | 38 | ||
39 | OPopupTitle::OPopupTitle(OPixmapEffect::GradientType /* gradient */, | 39 | OPopupTitle::OPopupTitle(OPixmapEffect::GradientType /* gradient */, |
40 | const QColor &/* color */, const QColor &/* textColor */, | 40 | const QColor &/* color */, const QColor &/* textColor */, |
41 | QWidget *parent, const char *name) | 41 | QWidget *parent, const char *name) |
42 | : QWidget(parent, name) | 42 | : QWidget(parent, name) |
43 | { | 43 | { |
44 | setMinimumSize(16, fontMetrics().height()+8); | 44 | setMinimumSize(16, fontMetrics().height()+8); |
45 | } | 45 | } |
46 | 46 | ||
47 | OPopupTitle::OPopupTitle(const OPixmap & /* background */, const QColor &/* color */, | 47 | OPopupTitle::OPopupTitle(const OPixmap & /* background */, const QColor &/* color */, |
48 | const QColor &/* textColor */, QWidget *parent, | 48 | const QColor &/* textColor */, QWidget *parent, |
49 | const char *name) | 49 | const char *name) |
50 | : QWidget(parent, name) | 50 | : QWidget(parent, name) |
51 | { | 51 | { |
52 | setMinimumSize(16, fontMetrics().height()+8); | 52 | setMinimumSize(16, fontMetrics().height()+8); |
53 | } | 53 | } |
54 | 54 | ||
55 | void OPopupTitle::setTitle(const QString &text, const QPixmap *icon) | 55 | void OPopupTitle::setTitle(const QString &text, const QPixmap *icon) |
56 | { | 56 | { |
57 | titleStr = text; | 57 | titleStr = text; |
58 | if (icon) | 58 | if (icon) |
59 | miniicon = *icon; | 59 | miniicon = *icon; |
60 | else | 60 | else |
61 | miniicon.resize(0, 0); | 61 | miniicon.resize(0, 0); |
62 | 62 | ||
63 | int w = miniicon.width()+fontMetrics().width(titleStr); | 63 | int w = miniicon.width()+fontMetrics().width(titleStr); |
64 | int h = QMAX( fontMetrics().height(), miniicon.height() ); | 64 | int h = QMAX( fontMetrics().height(), miniicon.height() ); |
65 | setMinimumSize( w+16, h+8 ); | 65 | setMinimumSize( w+16, h+8 ); |
66 | } | 66 | } |
67 | 67 | ||
68 | void OPopupTitle::setText( const QString &text ) | 68 | void OPopupTitle::setText( const QString &text ) |
69 | { | 69 | { |
70 | titleStr = text; | 70 | titleStr = text; |
71 | int w = miniicon.width()+fontMetrics().width(titleStr); | 71 | int w = miniicon.width()+fontMetrics().width(titleStr); |
72 | int h = QMAX( fontMetrics().height(), miniicon.height() ); | 72 | int h = QMAX( fontMetrics().height(), miniicon.height() ); |
73 | setMinimumSize( w+16, h+8 ); | 73 | setMinimumSize( w+16, h+8 ); |
74 | } | 74 | } |
75 | 75 | ||
76 | void OPopupTitle::setIcon( const QPixmap &pix ) | 76 | void OPopupTitle::setIcon( const QPixmap &pix ) |
77 | { | 77 | { |
78 | miniicon = pix; | 78 | miniicon = pix; |
79 | int w = miniicon.width()+fontMetrics().width(titleStr); | 79 | int w = miniicon.width()+fontMetrics().width(titleStr); |
80 | int h = QMAX( fontMetrics().height(), miniicon.height() ); | 80 | int h = QMAX( fontMetrics().height(), miniicon.height() ); |
81 | setMinimumSize( w+16, h+8 ); | 81 | setMinimumSize( w+16, h+8 ); |
82 | } | 82 | } |
83 | 83 | ||
84 | void OPopupTitle::paintEvent(QPaintEvent *) | 84 | void OPopupTitle::paintEvent(QPaintEvent *) |
85 | { | 85 | { |
86 | QRect r(rect()); | 86 | QRect r(rect()); |
87 | QPainter p(this); | 87 | QPainter p(this); |
88 | #if QT_VERSION > 290 | 88 | #if QT_VERSION >= 0x030000 |
89 | qApp->style().drawPrimitive(QStyle::PE_HeaderSection, &p, r, palette().active()); | 89 | qApp->style().drawPrimitive(QStyle::PE_HeaderSection, &p, r, palette().active()); |
90 | #else | 90 | #else |
91 | #warning OPopupMenu is not fully functional on Qt2 | 91 | #warning OPopupMenu is not fully functional on Qt2 |
92 | #endif | 92 | #endif |
93 | 93 | ||
94 | if (!miniicon.isNull()) | 94 | if (!miniicon.isNull()) |
95 | p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon); | 95 | p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon); |
96 | 96 | ||
97 | if (!titleStr.isNull()) | 97 | if (!titleStr.isNull()) |
98 | { | 98 | { |
99 | p.setPen(palette().active().text()); | 99 | p.setPen(palette().active().text()); |
100 | QFont f = p.font(); | 100 | QFont f = p.font(); |
101 | f.setBold(true); | 101 | f.setBold(true); |
102 | p.setFont(f); | 102 | p.setFont(f); |
103 | if(!miniicon.isNull()) | 103 | if(!miniicon.isNull()) |
104 | { | 104 | { |
105 | p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8), | 105 | p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8), |
106 | height(), AlignLeft | AlignVCenter | SingleLine, | 106 | height(), AlignLeft | AlignVCenter | SingleLine, |
107 | titleStr); | 107 | titleStr); |
108 | } | 108 | } |
109 | else | 109 | else |
110 | { | 110 | { |
111 | p.drawText(0, 0, width(), height(), | 111 | p.drawText(0, 0, width(), height(), |
112 | AlignCenter | SingleLine, titleStr); | 112 | AlignCenter | SingleLine, titleStr); |
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | p.setPen(palette().active().highlight()); | 116 | p.setPen(palette().active().highlight()); |
117 | p.drawLine(0, 0, r.right(), 0); | 117 | p.drawLine(0, 0, r.right(), 0); |
118 | } | 118 | } |
119 | 119 | ||
120 | QSize OPopupTitle::sizeHint() const | 120 | QSize OPopupTitle::sizeHint() const |
121 | { | 121 | { |
122 | return(minimumSize()); | 122 | return(minimumSize()); |
123 | } | 123 | } |
124 | 124 | ||
125 | class OPopupMenu::OPopupMenuPrivate | 125 | class OPopupMenu::OPopupMenuPrivate |
126 | { | 126 | { |
127 | public: | 127 | public: |
128 | OPopupMenuPrivate () | 128 | OPopupMenuPrivate () |
129 | : noMatches(false) | 129 | : noMatches(false) |
130 | , shortcuts(false) | 130 | , shortcuts(false) |
131 | , autoExec(false) | 131 | , autoExec(false) |
132 | , lastHitIndex(-1) | 132 | , lastHitIndex(-1) |
133 | , m_ctxMenu(0) | 133 | , m_ctxMenu(0) |
134 | {} | 134 | {} |
135 | 135 | ||
136 | ~OPopupMenuPrivate () | 136 | ~OPopupMenuPrivate () |
137 | { | 137 | { |
138 | delete m_ctxMenu; | 138 | delete m_ctxMenu; |
139 | } | 139 | } |
140 | 140 | ||
141 | QString m_lastTitle; | 141 | QString m_lastTitle; |
142 | 142 | ||
143 | // variables for keyboard navigation | 143 | // variables for keyboard navigation |
144 | QTimer clearTimer; | 144 | QTimer clearTimer; |
145 | 145 | ||
146 | bool noMatches : 1; | 146 | bool noMatches : 1; |
147 | bool shortcuts : 1; | 147 | bool shortcuts : 1; |
148 | bool autoExec : 1; | 148 | bool autoExec : 1; |
149 | 149 | ||
150 | QString keySeq; | 150 | QString keySeq; |
151 | QString originalText; | 151 | QString originalText; |
152 | 152 | ||
153 | int lastHitIndex; | 153 | int lastHitIndex; |
154 | 154 | ||
155 | // support for RMB menus on menus | 155 | // support for RMB menus on menus |
156 | QPopupMenu* m_ctxMenu; | 156 | QPopupMenu* m_ctxMenu; |
157 | static bool s_continueCtxMenuShow; | 157 | static bool s_continueCtxMenuShow; |
158 | static int s_highlightedItem; | 158 | static int s_highlightedItem; |
159 | static OPopupMenu* s_contextedMenu; | 159 | static OPopupMenu* s_contextedMenu; |
160 | }; | 160 | }; |
161 | 161 | ||
162 | int OPopupMenu::OPopupMenuPrivate::s_highlightedItem(-1); | 162 | int OPopupMenu::OPopupMenuPrivate::s_highlightedItem(-1); |
163 | OPopupMenu* OPopupMenu::OPopupMenuPrivate::s_contextedMenu(0); | 163 | OPopupMenu* OPopupMenu::OPopupMenuPrivate::s_contextedMenu(0); |
164 | bool OPopupMenu::OPopupMenuPrivate::s_continueCtxMenuShow(true); | 164 | bool OPopupMenu::OPopupMenuPrivate::s_continueCtxMenuShow(true); |
165 | 165 | ||
166 | OPopupMenu::OPopupMenu(QWidget *parent, const char *name) | 166 | OPopupMenu::OPopupMenu(QWidget *parent, const char *name) |
167 | : QPopupMenu(parent, name) | 167 | : QPopupMenu(parent, name) |
168 | { | 168 | { |
169 | d = new OPopupMenuPrivate; | 169 | d = new OPopupMenuPrivate; |
170 | resetKeyboardVars(); | 170 | resetKeyboardVars(); |
171 | connect(&(d->clearTimer), SIGNAL(timeout()), SLOT(resetKeyboardVars())); | 171 | connect(&(d->clearTimer), SIGNAL(timeout()), SLOT(resetKeyboardVars())); |
172 | } | 172 | } |
173 | 173 | ||
174 | OPopupMenu::~OPopupMenu() | 174 | OPopupMenu::~OPopupMenu() |
175 | { | 175 | { |
176 | if (OPopupMenuPrivate::s_contextedMenu == this) | 176 | if (OPopupMenuPrivate::s_contextedMenu == this) |
177 | { | 177 | { |
178 | OPopupMenuPrivate::s_contextedMenu = 0; | 178 | OPopupMenuPrivate::s_contextedMenu = 0; |
179 | OPopupMenuPrivate::s_highlightedItem = -1; | 179 | OPopupMenuPrivate::s_highlightedItem = -1; |
180 | } | 180 | } |
181 | 181 | ||
182 | delete d; | 182 | delete d; |
183 | } | 183 | } |
184 | 184 | ||
185 | int OPopupMenu::insertTitle(const QString &text, int id, int index) | 185 | int OPopupMenu::insertTitle(const QString &text, int id, int index) |
186 | { | 186 | { |
187 | OPopupTitle *titleItem = new OPopupTitle(); | 187 | OPopupTitle *titleItem = new OPopupTitle(); |
188 | titleItem->setTitle(text); | 188 | titleItem->setTitle(text); |
189 | int ret = insertItem(titleItem, id, index); | 189 | int ret = insertItem(titleItem, id, index); |
190 | setItemEnabled(id, false); | 190 | setItemEnabled(id, false); |
191 | return ret; | 191 | return ret; |
192 | } | 192 | } |
193 | 193 | ||
194 | int OPopupMenu::insertTitle(const QPixmap &icon, const QString &text, int id, | 194 | int OPopupMenu::insertTitle(const QPixmap &icon, const QString &text, int id, |
195 | int index) | 195 | int index) |
196 | { | 196 | { |
197 | OPopupTitle *titleItem = new OPopupTitle(); | 197 | OPopupTitle *titleItem = new OPopupTitle(); |
198 | titleItem->setTitle(text, &icon); | 198 | titleItem->setTitle(text, &icon); |
199 | int ret = insertItem(titleItem, id, index); | 199 | int ret = insertItem(titleItem, id, index); |
200 | setItemEnabled(id, false); | 200 | setItemEnabled(id, false); |
201 | return ret; | 201 | return ret; |
202 | } | 202 | } |
203 | 203 | ||
204 | void OPopupMenu::changeTitle(int id, const QString &text) | 204 | void OPopupMenu::changeTitle(int id, const QString &text) |
205 | { | 205 | { |
206 | QMenuItem *item = findItem(id); | 206 | QMenuItem *item = findItem(id); |
207 | if(item){ | 207 | if(item){ |
208 | if(item->widget()) | 208 | if(item->widget()) |
209 | ((OPopupTitle *)item->widget())->setTitle(text); | 209 | ((OPopupTitle *)item->widget())->setTitle(text); |
210 | #ifndef NDEBUG | 210 | #ifndef NDEBUG |
211 | else | 211 | else |
212 | owarn << "KPopupMenu: changeTitle() called with non-title id " << id << "" << oendl; | 212 | owarn << "KPopupMenu: changeTitle() called with non-title id " << id << "" << oendl; |
213 | #endif | 213 | #endif |
214 | } | 214 | } |
215 | #ifndef NDEBUG | 215 | #ifndef NDEBUG |
216 | else | 216 | else |
217 | owarn << "KPopupMenu: changeTitle() called with invalid id " << id << "" << oendl; | 217 | owarn << "KPopupMenu: changeTitle() called with invalid id " << id << "" << oendl; |
218 | #endif | 218 | #endif |
219 | } | 219 | } |
220 | 220 | ||
221 | void OPopupMenu::changeTitle(int id, const QPixmap &icon, const QString &text) | 221 | void OPopupMenu::changeTitle(int id, const QPixmap &icon, const QString &text) |
222 | { | 222 | { |
223 | QMenuItem *item = findItem(id); | 223 | QMenuItem *item = findItem(id); |
224 | if(item){ | 224 | if(item){ |
225 | if(item->widget()) | 225 | if(item->widget()) |
226 | ((OPopupTitle *)item->widget())->setTitle(text, &icon); | 226 | ((OPopupTitle *)item->widget())->setTitle(text, &icon); |
227 | #ifndef NDEBUG | 227 | #ifndef NDEBUG |
228 | else | 228 | else |
229 | owarn << "KPopupMenu: changeTitle() called with non-title id " << id << "" << oendl; | 229 | owarn << "KPopupMenu: changeTitle() called with non-title id " << id << "" << oendl; |
230 | #endif | 230 | #endif |
231 | } | 231 | } |
232 | #ifndef NDEBUG | 232 | #ifndef NDEBUG |
233 | else | 233 | else |
234 | owarn << "KPopupMenu: changeTitle() called with invalid id " << id << "" << oendl; | 234 | owarn << "KPopupMenu: changeTitle() called with invalid id " << id << "" << oendl; |
235 | #endif | 235 | #endif |
236 | } | 236 | } |
237 | 237 | ||
238 | QString OPopupMenu::title(int id) const | 238 | QString OPopupMenu::title(int id) const |
239 | { | 239 | { |
240 | if(id == -1) // obsolete | 240 | if(id == -1) // obsolete |
241 | return(d->m_lastTitle); | 241 | return(d->m_lastTitle); |
242 | QMenuItem *item = findItem(id); | 242 | QMenuItem *item = findItem(id); |
243 | if(item){ | 243 | if(item){ |
244 | if(item->widget()) | 244 | if(item->widget()) |
245 | return(((OPopupTitle *)item->widget())->title()); | 245 | return(((OPopupTitle *)item->widget())->title()); |
246 | else | 246 | else |
247 | owarn << "OPopupMenu: title() called with non-title id " << id << "." << oendl; | 247 | owarn << "OPopupMenu: title() called with non-title id " << id << "." << oendl; |
248 | } | 248 | } |
249 | else | 249 | else |
250 | owarn << "OPopupMenu: title() called with invalid id " << id << "." << oendl; | 250 | owarn << "OPopupMenu: title() called with invalid id " << id << "." << oendl; |
251 | return(QString::null); | 251 | return(QString::null); |
252 | } | 252 | } |
253 | 253 | ||
254 | QPixmap OPopupMenu::titlePixmap(int id) const | 254 | QPixmap OPopupMenu::titlePixmap(int id) const |
255 | { | 255 | { |
256 | QMenuItem *item = findItem(id); | 256 | QMenuItem *item = findItem(id); |
257 | if(item){ | 257 | if(item){ |
258 | if(item->widget()) | 258 | if(item->widget()) |
259 | return(((OPopupTitle *)item->widget())->icon()); | 259 | return(((OPopupTitle *)item->widget())->icon()); |
260 | else | 260 | else |
261 | owarn << "KPopupMenu: titlePixmap() called with non-title id " << id << "." << oendl; | 261 | owarn << "KPopupMenu: titlePixmap() called with non-title id " << id << "." << oendl; |
262 | } | 262 | } |
263 | else | 263 | else |
264 | owarn << "KPopupMenu: titlePixmap() called with invalid id " << id << "." << oendl; | 264 | owarn << "KPopupMenu: titlePixmap() called with invalid id " << id << "." << oendl; |
265 | QPixmap tmp; | 265 | QPixmap tmp; |
266 | return(tmp); | 266 | return(tmp); |
267 | } | 267 | } |
268 | 268 | ||
269 | /** | 269 | /** |
270 | * This is re-implemented for keyboard navigation. | 270 | * This is re-implemented for keyboard navigation. |
271 | */ | 271 | */ |
272 | void OPopupMenu::closeEvent(QCloseEvent*e) | 272 | void OPopupMenu::closeEvent(QCloseEvent*e) |
273 | { | 273 | { |
274 | if (d->shortcuts) | 274 | if (d->shortcuts) |
275 | resetKeyboardVars(); | 275 | resetKeyboardVars(); |
276 | QPopupMenu::closeEvent(e); | 276 | QPopupMenu::closeEvent(e); |
277 | } | 277 | } |
278 | 278 | ||
279 | void OPopupMenu::keyPressEvent(QKeyEvent* e) | 279 | void OPopupMenu::keyPressEvent(QKeyEvent* e) |
280 | { | 280 | { |
281 | if (!d->shortcuts) { | 281 | if (!d->shortcuts) { |
282 | // continue event processing by Qpopup | 282 | // continue event processing by Qpopup |
283 | //e->ignore(); | 283 | //e->ignore(); |
284 | QPopupMenu::keyPressEvent(e); | 284 | QPopupMenu::keyPressEvent(e); |
285 | return; | 285 | return; |
286 | } | 286 | } |
287 | 287 | ||
288 | int i = 0; | 288 | int i = 0; |
289 | bool firstpass = true; | 289 | bool firstpass = true; |
290 | QString keyString = e->text(); | 290 | QString keyString = e->text(); |
291 | 291 | ||
292 | // check for common commands dealt with by QPopup | 292 | // check for common commands dealt with by QPopup |
293 | int key = e->key(); | 293 | int key = e->key(); |
294 | if (key == Key_Escape || key == Key_Return || key == Key_Enter | 294 | if (key == Key_Escape || key == Key_Return || key == Key_Enter |
295 | || key == Key_Up || key == Key_Down || key == Key_Left | 295 | || key == Key_Up || key == Key_Down || key == Key_Left |
296 | || key == Key_Right || key == Key_F1) { | 296 | || key == Key_Right || key == Key_F1) { |
297 | 297 | ||
298 | resetKeyboardVars(); | 298 | resetKeyboardVars(); |
299 | // continue event processing by Qpopup | 299 | // continue event processing by Qpopup |
300 | //e->ignore(); | 300 | //e->ignore(); |
301 | QPopupMenu::keyPressEvent(e); | 301 | QPopupMenu::keyPressEvent(e); |
302 | return; | 302 | return; |
303 | } | 303 | } |
304 | 304 | ||
305 | // check to see if the user wants to remove a key from the sequence (backspace) | 305 | // check to see if the user wants to remove a key from the sequence (backspace) |
306 | // or clear the sequence (delete) | 306 | // or clear the sequence (delete) |
307 | if (!d->keySeq.isNull()) { | 307 | if (!d->keySeq.isNull()) { |
308 | 308 | ||
309 | if (key == Key_Backspace) { | 309 | if (key == Key_Backspace) { |
310 | 310 | ||
311 | if (d->keySeq.length() == 1) { | 311 | if (d->keySeq.length() == 1) { |
312 | resetKeyboardVars(); | 312 | resetKeyboardVars(); |
313 | return; | 313 | return; |
314 | } | 314 | } |
315 | 315 | ||
316 | // keep the last sequence in keyString | 316 | // keep the last sequence in keyString |
317 | keyString = d->keySeq.left(d->keySeq.length() - 1); | 317 | keyString = d->keySeq.left(d->keySeq.length() - 1); |
318 | 318 | ||
319 | // allow sequence matching to be tried again | 319 | // allow sequence matching to be tried again |
320 | resetKeyboardVars(); | 320 | resetKeyboardVars(); |
321 | 321 | ||
322 | } else if (key == Key_Delete) { | 322 | } else if (key == Key_Delete) { |
323 | resetKeyboardVars(); | 323 | resetKeyboardVars(); |
324 | 324 | ||
325 | // clear active item | 325 | // clear active item |
326 | setActiveItem(0); | 326 | setActiveItem(0); |
327 | return; | 327 | return; |
328 | 328 | ||
329 | } else if (d->noMatches) { | 329 | } else if (d->noMatches) { |
330 | // clear if there are no matches | 330 | // clear if there are no matches |
331 | resetKeyboardVars(); | 331 | resetKeyboardVars(); |
332 | 332 | ||
333 | // clear active item | 333 | // clear active item |
334 | setActiveItem(0); | 334 | setActiveItem(0); |
335 | 335 | ||
336 | } else { | 336 | } else { |
337 | // the key sequence is not a null string | 337 | // the key sequence is not a null string |
338 | // therefore the lastHitIndex is valid | 338 | // therefore the lastHitIndex is valid |
339 | i = d->lastHitIndex; | 339 | i = d->lastHitIndex; |
340 | } | 340 | } |
341 | } else if (key == Key_Backspace && parentMenu) { | 341 | } else if (key == Key_Backspace && parentMenu) { |
342 | // backspace with no chars in the buffer... go back a menu. | 342 | // backspace with no chars in the buffer... go back a menu. |
343 | hide(); | 343 | hide(); |
344 | resetKeyboardVars(); | 344 | resetKeyboardVars(); |
345 | return; | 345 | return; |
346 | } | 346 | } |
347 | 347 | ||
348 | d->keySeq += keyString; | 348 | d->keySeq += keyString; |
349 | int seqLen = d->keySeq.length(); | 349 | int seqLen = d->keySeq.length(); |
350 | 350 | ||
351 | for (; i < (int)count(); i++) { | 351 | for (; i < (int)count(); i++) { |
352 | // compare typed text with text of this entry | 352 | // compare typed text with text of this entry |
353 | int j = idAt(i); | 353 | int j = idAt(i); |
354 | 354 | ||
355 | // don't search disabled entries | 355 | // don't search disabled entries |
356 | if (!isItemEnabled(j)) | 356 | if (!isItemEnabled(j)) |
357 | continue; | 357 | continue; |
358 | 358 | ||
359 | QString thisText; | 359 | QString thisText; |
360 | 360 | ||
361 | // retrieve the right text | 361 | // retrieve the right text |
362 | // (the last selected item one may have additional ampersands) | 362 | // (the last selected item one may have additional ampersands) |
363 | if (i == d->lastHitIndex) | 363 | if (i == d->lastHitIndex) |
364 | thisText = d->originalText; | 364 | thisText = d->originalText; |
365 | else | 365 | else |
366 | thisText = text(j); | 366 | thisText = text(j); |
367 | 367 | ||
368 | // if there is an accelerator present, remove it | 368 | // if there is an accelerator present, remove it |
369 | if ((int)accel(j) != 0) | 369 | if ((int)accel(j) != 0) |
370 | thisText = thisText.replace(QRegExp("&"), ""); | 370 | thisText = thisText.replace(QRegExp("&"), ""); |
371 | 371 | ||
372 | // chop text to the search length | 372 | // chop text to the search length |
373 | thisText = thisText.left(seqLen); | 373 | thisText = thisText.left(seqLen); |
374 | 374 | ||
375 | // do the search | 375 | // do the search |
376 | if (thisText.find(d->keySeq, 0, false) == 0) { | 376 | if (thisText.find(d->keySeq, 0, false) == 0) { |
377 | 377 | ||
378 | if (firstpass) { | 378 | if (firstpass) { |
379 | // match | 379 | // match |
380 | setActiveItem(i); | 380 | setActiveItem(i); |
381 | 381 | ||
382 | // check to see if we're underlining a different item | 382 | // check to see if we're underlining a different item |
383 | if (d->lastHitIndex != i) | 383 | if (d->lastHitIndex != i) |
384 | // yes; revert the underlining | 384 | // yes; revert the underlining |
385 | changeItem(idAt(d->lastHitIndex), d->originalText); | 385 | changeItem(idAt(d->lastHitIndex), d->originalText); |
386 | 386 | ||
387 | // set the original text if it's a different item | 387 | // set the original text if it's a different item |
388 | if (d->lastHitIndex != i || d->lastHitIndex == -1) | 388 | if (d->lastHitIndex != i || d->lastHitIndex == -1) |
389 | d->originalText = text(j); | 389 | d->originalText = text(j); |
390 | 390 | ||
391 | // underline the currently selected item | 391 | // underline the currently selected item |
392 | changeItem(j, underlineText(d->originalText, d->keySeq.length())); | 392 | changeItem(j, underlineText(d->originalText, d->keySeq.length())); |
393 | 393 | ||
394 | // remeber what's going on | 394 | // remeber what's going on |
395 | d->lastHitIndex = i; | 395 | d->lastHitIndex = i; |
396 | 396 | ||
397 | // start/restart the clear timer | 397 | // start/restart the clear timer |
398 | d->clearTimer.start(5000, true); | 398 | d->clearTimer.start(5000, true); |
399 | 399 | ||
400 | // go around for another try, to see if we can execute | 400 | // go around for another try, to see if we can execute |
401 | firstpass = false; | 401 | firstpass = false; |
402 | } else { | 402 | } else { |
403 | // don't allow execution | 403 | // don't allow execution |
404 | return; | 404 | return; |
405 | } | 405 | } |
406 | } | 406 | } |
407 | 407 | ||
408 | // fall through to allow execution | 408 | // fall through to allow execution |
409 | } | 409 | } |
410 | 410 | ||
411 | if (!firstpass) { | 411 | if (!firstpass) { |
412 | if (d->autoExec) { | 412 | if (d->autoExec) { |
413 | // activate anything | 413 | // activate anything |
414 | activateItemAt(d->lastHitIndex); | 414 | activateItemAt(d->lastHitIndex); |
415 | resetKeyboardVars(); | 415 | resetKeyboardVars(); |
416 | 416 | ||
417 | } else if (findItem(idAt(d->lastHitIndex)) && | 417 | } else if (findItem(idAt(d->lastHitIndex)) && |
418 | findItem(idAt(d->lastHitIndex))->popup()) { | 418 | findItem(idAt(d->lastHitIndex))->popup()) { |
419 | // only activate sub-menus | 419 | // only activate sub-menus |
420 | activateItemAt(d->lastHitIndex); | 420 | activateItemAt(d->lastHitIndex); |
421 | resetKeyboardVars(); | 421 | resetKeyboardVars(); |
422 | } | 422 | } |
423 | 423 | ||
424 | return; | 424 | return; |
425 | } | 425 | } |
426 | 426 | ||
427 | // no matches whatsoever, clean up | 427 | // no matches whatsoever, clean up |
428 | resetKeyboardVars(true); | 428 | resetKeyboardVars(true); |
429 | //e->ignore(); | 429 | //e->ignore(); |
430 | QPopupMenu::keyPressEvent(e); | 430 | QPopupMenu::keyPressEvent(e); |
431 | } | 431 | } |
432 | 432 | ||
433 | QString OPopupMenu::underlineText(const QString& text, uint length) | 433 | QString OPopupMenu::underlineText(const QString& text, uint length) |
434 | { | 434 | { |
435 | QString ret = text; | 435 | QString ret = text; |
436 | for (uint i = 0; i < length; i++) { | 436 | for (uint i = 0; i < length; i++) { |
437 | if (ret[2*i] != '&') | 437 | if (ret[2*i] != '&') |
438 | ret.insert(2*i, "&"); | 438 | ret.insert(2*i, "&"); |
439 | } | 439 | } |
440 | return ret; | 440 | return ret; |
441 | } | 441 | } |
442 | 442 | ||
443 | void OPopupMenu::resetKeyboardVars(bool noMatches /* = false */) | 443 | void OPopupMenu::resetKeyboardVars(bool noMatches /* = false */) |
444 | { | 444 | { |
445 | // Clean up keyboard variables | 445 | // Clean up keyboard variables |
446 | if (d->lastHitIndex != -1) { | 446 | if (d->lastHitIndex != -1) { |
447 | changeItem(idAt(d->lastHitIndex), d->originalText); | 447 | changeItem(idAt(d->lastHitIndex), d->originalText); |
448 | d->lastHitIndex = -1; | 448 | d->lastHitIndex = -1; |
449 | } | 449 | } |
450 | 450 | ||
451 | if (!noMatches) { | 451 | if (!noMatches) { |
452 | d->keySeq = QString::null; | 452 | d->keySeq = QString::null; |
453 | } | 453 | } |
454 | 454 | ||
455 | d->noMatches = noMatches; | 455 | d->noMatches = noMatches; |
456 | } | 456 | } |
457 | 457 | ||
458 | void OPopupMenu::setKeyboardShortcutsEnabled(bool enable) | 458 | void OPopupMenu::setKeyboardShortcutsEnabled(bool enable) |
459 | { | 459 | { |
460 | d->shortcuts = enable; | 460 | d->shortcuts = enable; |
461 | } | 461 | } |
462 | 462 | ||
463 | void OPopupMenu::setKeyboardShortcutsExecute(bool enable) | 463 | void OPopupMenu::setKeyboardShortcutsExecute(bool enable) |
464 | { | 464 | { |
465 | d->autoExec = enable; | 465 | d->autoExec = enable; |
466 | } | 466 | } |
467 | /** | 467 | /** |
468 | * End keyboard navigation. | 468 | * End keyboard navigation. |
469 | */ | 469 | */ |
470 | 470 | ||
471 | /** | 471 | /** |
472 | * RMB menus on menus | 472 | * RMB menus on menus |
473 | */ | 473 | */ |
474 | QPopupMenu* OPopupMenu::contextMenu() | 474 | QPopupMenu* OPopupMenu::contextMenu() |
475 | { | 475 | { |
476 | if (!d->m_ctxMenu) | 476 | if (!d->m_ctxMenu) |
477 | { | 477 | { |
478 | d->m_ctxMenu = new QPopupMenu(this); | 478 | d->m_ctxMenu = new QPopupMenu(this); |
479 | installEventFilter(this); | 479 | installEventFilter(this); |
480 | connect(d->m_ctxMenu, SIGNAL(aboutToHide()), this, SLOT(ctxMenuHiding())); | 480 | connect(d->m_ctxMenu, SIGNAL(aboutToHide()), this, SLOT(ctxMenuHiding())); |
481 | } | 481 | } |
482 | 482 | ||
483 | return d->m_ctxMenu; | 483 | return d->m_ctxMenu; |
484 | } | 484 | } |
485 | 485 | ||
486 | void OPopupMenu::cancelContextMenuShow() | 486 | void OPopupMenu::cancelContextMenuShow() |
487 | { | 487 | { |
488 | OPopupMenuPrivate::s_continueCtxMenuShow = false; | 488 | OPopupMenuPrivate::s_continueCtxMenuShow = false; |
489 | } | 489 | } |
490 | 490 | ||
491 | int OPopupMenu::contextMenuFocusItem() | 491 | int OPopupMenu::contextMenuFocusItem() |
492 | { | 492 | { |
493 | return OPopupMenuPrivate::s_highlightedItem; | 493 | return OPopupMenuPrivate::s_highlightedItem; |
494 | } | 494 | } |
495 | 495 | ||
496 | OPopupMenu* OPopupMenu::contextMenuFocus() | 496 | OPopupMenu* OPopupMenu::contextMenuFocus() |
497 | { | 497 | { |
498 | return OPopupMenuPrivate::s_contextedMenu; | 498 | return OPopupMenuPrivate::s_contextedMenu; |
499 | } | 499 | } |
500 | 500 | ||
501 | void OPopupMenu::itemHighlighted(int /* whichItem */) | 501 | void OPopupMenu::itemHighlighted(int /* whichItem */) |
502 | { | 502 | { |
503 | if (!d->m_ctxMenu || !d->m_ctxMenu->isVisible()) | 503 | if (!d->m_ctxMenu || !d->m_ctxMenu->isVisible()) |
504 | { | 504 | { |
505 | return; | 505 | return; |
506 | } | 506 | } |
507 | 507 | ||
508 | d->m_ctxMenu->hide(); | 508 | d->m_ctxMenu->hide(); |
509 | showCtxMenu(mapFromGlobal(QCursor::pos())); | 509 | showCtxMenu(mapFromGlobal(QCursor::pos())); |
510 | } | 510 | } |
511 | 511 | ||
512 | void OPopupMenu::showCtxMenu(QPoint pos) | 512 | void OPopupMenu::showCtxMenu(QPoint pos) |
513 | { | 513 | { |
514 | OPopupMenuPrivate::s_highlightedItem = idAt(pos); | 514 | OPopupMenuPrivate::s_highlightedItem = idAt(pos); |
515 | 515 | ||
516 | if (OPopupMenuPrivate::s_highlightedItem == -1) | 516 | if (OPopupMenuPrivate::s_highlightedItem == -1) |
517 | { | 517 | { |
518 | OPopupMenuPrivate::s_contextedMenu = 0; | 518 | OPopupMenuPrivate::s_contextedMenu = 0; |
519 | return; | 519 | return; |
520 | } | 520 | } |
521 | 521 | ||
522 | emit aboutToShowContextMenu(this, OPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu); | 522 | emit aboutToShowContextMenu(this, OPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu); |
523 | 523 | ||
524 | if (!OPopupMenuPrivate::s_continueCtxMenuShow) | 524 | if (!OPopupMenuPrivate::s_continueCtxMenuShow) |
525 | { | 525 | { |
526 | OPopupMenuPrivate::s_continueCtxMenuShow = true; | 526 | OPopupMenuPrivate::s_continueCtxMenuShow = true; |
527 | return; | 527 | return; |
528 | } | 528 | } |
529 | 529 | ||
530 | OPopupMenuPrivate::s_contextedMenu = this; | 530 | OPopupMenuPrivate::s_contextedMenu = this; |
531 | d->m_ctxMenu->popup(this->mapToGlobal(pos)); | 531 | d->m_ctxMenu->popup(this->mapToGlobal(pos)); |
532 | connect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int))); | 532 | connect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int))); |
533 | } | 533 | } |
534 | 534 | ||
535 | void OPopupMenu::ctxMenuHiding() | 535 | void OPopupMenu::ctxMenuHiding() |
536 | { | 536 | { |
537 | disconnect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int))); | 537 | disconnect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int))); |
538 | OPopupMenuPrivate::s_continueCtxMenuShow = true; | 538 | OPopupMenuPrivate::s_continueCtxMenuShow = true; |
539 | } | 539 | } |
540 | 540 | ||
541 | bool OPopupMenu::eventFilter(QObject* obj, QEvent* event) | 541 | bool OPopupMenu::eventFilter(QObject* obj, QEvent* event) |
542 | { | 542 | { |
543 | if (d->m_ctxMenu && obj == this) | 543 | if (d->m_ctxMenu && obj == this) |
544 | { | 544 | { |
545 | if (event->type() == QEvent::MouseButtonRelease) | 545 | if (event->type() == QEvent::MouseButtonRelease) |
546 | { | 546 | { |
547 | if (d->m_ctxMenu->isVisible()) | 547 | if (d->m_ctxMenu->isVisible()) |
548 | { | 548 | { |
549 | return true; | 549 | return true; |
550 | } | 550 | } |
551 | } | 551 | } |
552 | #if QT_VERSION > 290 | 552 | #if QT_VERSION >= 0x030000 |
553 | else if (event->type() == QEvent::ContextMenu) | 553 | else if (event->type() == QEvent::ContextMenu) |
554 | #else | 554 | #else |
555 | else if ( (event->type() == QEvent::MouseButtonPress) && | 555 | else if ( (event->type() == QEvent::MouseButtonPress) && |
556 | ( (QMouseEvent*) event )->button() == QMouseEvent::RightButton ) | 556 | ( (QMouseEvent*) event )->button() == QMouseEvent::RightButton ) |
557 | #endif | 557 | #endif |
558 | { | 558 | { |
559 | showCtxMenu(mapFromGlobal(QCursor::pos())); | 559 | showCtxMenu(mapFromGlobal(QCursor::pos())); |
560 | return true; | 560 | return true; |
561 | } | 561 | } |
562 | } | 562 | } |
563 | 563 | ||
564 | return QWidget::eventFilter(obj, event); | 564 | return QWidget::eventFilter(obj, event); |
565 | } | 565 | } |
566 | 566 | ||
567 | void OPopupMenu::hideEvent(QHideEvent*) | 567 | void OPopupMenu::hideEvent(QHideEvent*) |
568 | { | 568 | { |
569 | if (d->m_ctxMenu) | 569 | if (d->m_ctxMenu) |
570 | { | 570 | { |
571 | d->m_ctxMenu->hide(); | 571 | d->m_ctxMenu->hide(); |
572 | } | 572 | } |
573 | } | 573 | } |
574 | /** | 574 | /** |
575 | * end of RMB menus on menus support | 575 | * end of RMB menus on menus support |
576 | */ | 576 | */ |
577 | 577 | ||
578 | // Obsolete | 578 | // Obsolete |
579 | OPopupMenu::OPopupMenu(const QString& title, QWidget *parent, const char *name) | 579 | OPopupMenu::OPopupMenu(const QString& title, QWidget *parent, const char *name) |
580 | : QPopupMenu(parent, name) | 580 | : QPopupMenu(parent, name) |
581 | { | 581 | { |
582 | d = new OPopupMenuPrivate; | 582 | d = new OPopupMenuPrivate; |
583 | setTitle(title); | 583 | setTitle(title); |
584 | } | 584 | } |
585 | 585 | ||
586 | // Obsolete | 586 | // Obsolete |
587 | void OPopupMenu::setTitle(const QString &title) | 587 | void OPopupMenu::setTitle(const QString &title) |
588 | { | 588 | { |
589 | OPopupTitle *titleItem = new OPopupTitle(); | 589 | OPopupTitle *titleItem = new OPopupTitle(); |
590 | titleItem->setTitle(title); | 590 | titleItem->setTitle(title); |
591 | insertItem(titleItem); | 591 | insertItem(titleItem); |
592 | d->m_lastTitle = title; | 592 | d->m_lastTitle = title; |
593 | } | 593 | } |
594 | 594 | ||
595 | void OPopupTitle::virtual_hook( int, void* ) | 595 | void OPopupTitle::virtual_hook( int, void* ) |
596 | { /*BASE::virtual_hook( id, data );*/ } | 596 | { /*BASE::virtual_hook( id, data );*/ } |
597 | 597 | ||
598 | void OPopupMenu::virtual_hook( int, void* ) | 598 | void OPopupMenu::virtual_hook( int, void* ) |
599 | { /*BASE::virtual_hook( id, data );*/ } | 599 | { /*BASE::virtual_hook( id, data );*/ } |
600 | 600 | ||
diff --git a/libopie2/opieui/oselector.cpp b/libopie2/opieui/oselector.cpp index 05543c5..936dfe6 100644 --- a/libopie2/opieui/oselector.cpp +++ b/libopie2/opieui/oselector.cpp | |||
@@ -1,719 +1,719 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1997 Martin Jones (mjones@kde.org) | 2 | Copyright (C) 1997 Martin Jones (mjones@kde.org) |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | /* QT */ | 20 | /* QT */ |
21 | 21 | ||
22 | #include <qimage.h> | 22 | #include <qimage.h> |
23 | #include <qdrawutil.h> | 23 | #include <qdrawutil.h> |
24 | 24 | ||
25 | /* OPIE */ | 25 | /* OPIE */ |
26 | 26 | ||
27 | #include <opie2/oimageeffect.h> | 27 | #include <opie2/oimageeffect.h> |
28 | #include <opie2/oselector.h> | 28 | #include <opie2/oselector.h> |
29 | 29 | ||
30 | #define STORE_W 8 | 30 | #define STORE_W 8 |
31 | #define STORE_W2 STORE_W * 2 | 31 | #define STORE_W2 STORE_W * 2 |
32 | 32 | ||
33 | //----------------------------------------------------------------------------- | 33 | //----------------------------------------------------------------------------- |
34 | /* | 34 | /* |
35 | * 2D value selector. | 35 | * 2D value selector. |
36 | * The contents of the selector are drawn by derived class. | 36 | * The contents of the selector are drawn by derived class. |
37 | */ | 37 | */ |
38 | 38 | ||
39 | using namespace Opie::Ui; | 39 | using namespace Opie::Ui; |
40 | 40 | ||
41 | OXYSelector::OXYSelector( QWidget *parent, const char *name ) | 41 | OXYSelector::OXYSelector( QWidget *parent, const char *name ) |
42 | : QWidget( parent, name ) | 42 | : QWidget( parent, name ) |
43 | { | 43 | { |
44 | xPos = 0; | 44 | xPos = 0; |
45 | yPos = 0; | 45 | yPos = 0; |
46 | minX = 0; | 46 | minX = 0; |
47 | minY = 0; | 47 | minY = 0; |
48 | maxX = 100; | 48 | maxX = 100; |
49 | maxY = 100; | 49 | maxY = 100; |
50 | store.setOptimization( QPixmap::BestOptim ); | 50 | store.setOptimization( QPixmap::BestOptim ); |
51 | store.resize( STORE_W2, STORE_W2 ); | 51 | store.resize( STORE_W2, STORE_W2 ); |
52 | } | 52 | } |
53 | 53 | ||
54 | 54 | ||
55 | OXYSelector::~OXYSelector() | 55 | OXYSelector::~OXYSelector() |
56 | {} | 56 | {} |
57 | 57 | ||
58 | 58 | ||
59 | void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY ) | 59 | void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY ) |
60 | { | 60 | { |
61 | px = 2; | 61 | px = 2; |
62 | py = 2; | 62 | py = 2; |
63 | minX = _minX; | 63 | minX = _minX; |
64 | minY = _minY; | 64 | minY = _minY; |
65 | maxX = _maxX; | 65 | maxX = _maxX; |
66 | maxY = _maxY; | 66 | maxY = _maxY; |
67 | } | 67 | } |
68 | 68 | ||
69 | void OXYSelector::setValues( int _xPos, int _yPos ) | 69 | void OXYSelector::setValues( int _xPos, int _yPos ) |
70 | { | 70 | { |
71 | xPos = _xPos; | 71 | xPos = _xPos; |
72 | yPos = _yPos; | 72 | yPos = _yPos; |
73 | 73 | ||
74 | if ( xPos > maxX ) | 74 | if ( xPos > maxX ) |
75 | xPos = maxX; | 75 | xPos = maxX; |
76 | else if ( xPos < minX ) | 76 | else if ( xPos < minX ) |
77 | xPos = minX; | 77 | xPos = minX; |
78 | 78 | ||
79 | if ( yPos > maxY ) | 79 | if ( yPos > maxY ) |
80 | yPos = maxY; | 80 | yPos = maxY; |
81 | else if ( yPos < minY ) | 81 | else if ( yPos < minY ) |
82 | yPos = minY; | 82 | yPos = minY; |
83 | 83 | ||
84 | int xp = 2 + (width() - 4) * xPos / (maxX - minX); | 84 | int xp = 2 + (width() - 4) * xPos / (maxX - minX); |
85 | int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY); | 85 | int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY); |
86 | 86 | ||
87 | setPosition( xp, yp ); | 87 | setPosition( xp, yp ); |
88 | } | 88 | } |
89 | 89 | ||
90 | QRect OXYSelector::contentsRect() const | 90 | QRect OXYSelector::contentsRect() const |
91 | { | 91 | { |
92 | return QRect( 2, 2, width()-4, height()-4 ); | 92 | return QRect( 2, 2, width()-4, height()-4 ); |
93 | } | 93 | } |
94 | 94 | ||
95 | void OXYSelector::paintEvent( QPaintEvent *ev ) | 95 | void OXYSelector::paintEvent( QPaintEvent *ev ) |
96 | { | 96 | { |
97 | QRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2); | 97 | QRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2); |
98 | QRect paintRect = ev->rect(); | 98 | QRect paintRect = ev->rect(); |
99 | 99 | ||
100 | QPainter painter; | 100 | QPainter painter; |
101 | painter.begin( this ); | 101 | painter.begin( this ); |
102 | 102 | ||
103 | QBrush brush; | 103 | QBrush brush; |
104 | qDrawShadePanel( &painter, 0, 0, width(), height(), colorGroup(), | 104 | qDrawShadePanel( &painter, 0, 0, width(), height(), colorGroup(), |
105 | TRUE, 2, &brush ); | 105 | TRUE, 2, &brush ); |
106 | 106 | ||
107 | drawContents( &painter ); | 107 | drawContents( &painter ); |
108 | if (paintRect.contains(cursorRect)) | 108 | if (paintRect.contains(cursorRect)) |
109 | { | 109 | { |
110 | bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W, | 110 | bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W, |
111 | STORE_W2, STORE_W2, CopyROP ); | 111 | STORE_W2, STORE_W2, CopyROP ); |
112 | drawCursor( &painter, px, py ); | 112 | drawCursor( &painter, px, py ); |
113 | } | 113 | } |
114 | else if (paintRect.intersects(cursorRect)) | 114 | else if (paintRect.intersects(cursorRect)) |
115 | { | 115 | { |
116 | repaint( cursorRect, false); | 116 | repaint( cursorRect, false); |
117 | } | 117 | } |
118 | 118 | ||
119 | painter.end(); | 119 | painter.end(); |
120 | } | 120 | } |
121 | 121 | ||
122 | void OXYSelector::mousePressEvent( QMouseEvent *e ) | 122 | void OXYSelector::mousePressEvent( QMouseEvent *e ) |
123 | { | 123 | { |
124 | int xVal, yVal; | 124 | int xVal, yVal; |
125 | valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); | 125 | valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); |
126 | setValues( xVal, yVal ); | 126 | setValues( xVal, yVal ); |
127 | 127 | ||
128 | emit valueChanged( xPos, yPos ); | 128 | emit valueChanged( xPos, yPos ); |
129 | } | 129 | } |
130 | 130 | ||
131 | void OXYSelector::mouseMoveEvent( QMouseEvent *e ) | 131 | void OXYSelector::mouseMoveEvent( QMouseEvent *e ) |
132 | { | 132 | { |
133 | int xVal, yVal; | 133 | int xVal, yVal; |
134 | valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); | 134 | valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); |
135 | setValues( xVal, yVal ); | 135 | setValues( xVal, yVal ); |
136 | 136 | ||
137 | emit valueChanged( xPos, yPos ); | 137 | emit valueChanged( xPos, yPos ); |
138 | } | 138 | } |
139 | 139 | ||
140 | void OXYSelector::wheelEvent( QWheelEvent *e ) | 140 | void OXYSelector::wheelEvent( QWheelEvent *e ) |
141 | { | 141 | { |
142 | #if QT_VERSION > 290 | 142 | #if QT_VERSION >= 0x030000 |
143 | if ( e->orientation() == Qt::Horizontal ) | 143 | if ( e->orientation() == Qt::Horizontal ) |
144 | setValues( xValue() + e->delta()/120, yValue() ); | 144 | setValues( xValue() + e->delta()/120, yValue() ); |
145 | else | 145 | else |
146 | setValues( xValue(), yValue() + e->delta()/120 ); | 146 | setValues( xValue(), yValue() + e->delta()/120 ); |
147 | 147 | ||
148 | emit valueChanged( xPos, yPos ); | 148 | emit valueChanged( xPos, yPos ); |
149 | #else | 149 | #else |
150 | Q_UNUSED( e ) | 150 | Q_UNUSED( e ) |
151 | #endif | 151 | #endif |
152 | } | 152 | } |
153 | 153 | ||
154 | void OXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const | 154 | void OXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const |
155 | { | 155 | { |
156 | xVal = ( (maxX-minX) * (x-2) ) / ( width()-4 ); | 156 | xVal = ( (maxX-minX) * (x-2) ) / ( width()-4 ); |
157 | yVal = maxY - ( ( (maxY-minY) * (y-2) ) / ( height()-4 ) ); | 157 | yVal = maxY - ( ( (maxY-minY) * (y-2) ) / ( height()-4 ) ); |
158 | 158 | ||
159 | if ( xVal > maxX ) | 159 | if ( xVal > maxX ) |
160 | xVal = maxX; | 160 | xVal = maxX; |
161 | else if ( xVal < minX ) | 161 | else if ( xVal < minX ) |
162 | xVal = minX; | 162 | xVal = minX; |
163 | 163 | ||
164 | if ( yVal > maxY ) | 164 | if ( yVal > maxY ) |
165 | yVal = maxY; | 165 | yVal = maxY; |
166 | else if ( yVal < minY ) | 166 | else if ( yVal < minY ) |
167 | yVal = minY; | 167 | yVal = minY; |
168 | } | 168 | } |
169 | 169 | ||
170 | void OXYSelector::setPosition( int xp, int yp ) | 170 | void OXYSelector::setPosition( int xp, int yp ) |
171 | { | 171 | { |
172 | if ( xp < 2 ) | 172 | if ( xp < 2 ) |
173 | xp = 2; | 173 | xp = 2; |
174 | else if ( xp > width() - 2 ) | 174 | else if ( xp > width() - 2 ) |
175 | xp = width() - 2; | 175 | xp = width() - 2; |
176 | 176 | ||
177 | if ( yp < 2 ) | 177 | if ( yp < 2 ) |
178 | yp = 2; | 178 | yp = 2; |
179 | else if ( yp > height() - 2 ) | 179 | else if ( yp > height() - 2 ) |
180 | yp = height() - 2; | 180 | yp = height() - 2; |
181 | 181 | ||
182 | QPainter painter; | 182 | QPainter painter; |
183 | painter.begin( this ); | 183 | painter.begin( this ); |
184 | 184 | ||
185 | bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0, | 185 | bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0, |
186 | STORE_W2, STORE_W2, CopyROP ); | 186 | STORE_W2, STORE_W2, CopyROP ); |
187 | bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W, | 187 | bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W, |
188 | STORE_W2, STORE_W2, CopyROP ); | 188 | STORE_W2, STORE_W2, CopyROP ); |
189 | drawCursor( &painter, xp, yp ); | 189 | drawCursor( &painter, xp, yp ); |
190 | px = xp; | 190 | px = xp; |
191 | py = yp; | 191 | py = yp; |
192 | 192 | ||
193 | painter.end(); | 193 | painter.end(); |
194 | } | 194 | } |
195 | 195 | ||
196 | void OXYSelector::drawContents( QPainter * ) | 196 | void OXYSelector::drawContents( QPainter * ) |
197 | {} | 197 | {} |
198 | 198 | ||
199 | 199 | ||
200 | void OXYSelector::drawCursor( QPainter *p, int xp, int yp ) | 200 | void OXYSelector::drawCursor( QPainter *p, int xp, int yp ) |
201 | { | 201 | { |
202 | p->setPen( QPen( white ) ); | 202 | p->setPen( QPen( white ) ); |
203 | 203 | ||
204 | p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 ); | 204 | p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 ); |
205 | p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 ); | 205 | p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 ); |
206 | p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 ); | 206 | p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 ); |
207 | p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 ); | 207 | p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 ); |
208 | } | 208 | } |
209 | 209 | ||
210 | //----------------------------------------------------------------------------- | 210 | //----------------------------------------------------------------------------- |
211 | /* | 211 | /* |
212 | * 1D value selector with contents drawn by derived class. | 212 | * 1D value selector with contents drawn by derived class. |
213 | * See OColorDialog for example. | 213 | * See OColorDialog for example. |
214 | */ | 214 | */ |
215 | 215 | ||
216 | 216 | ||
217 | OSelector::OSelector( QWidget *parent, const char *name ) | 217 | OSelector::OSelector( QWidget *parent, const char *name ) |
218 | : QWidget( parent, name ), QRangeControl() | 218 | : QWidget( parent, name ), QRangeControl() |
219 | { | 219 | { |
220 | _orientation = Horizontal; | 220 | _orientation = Horizontal; |
221 | _indent = TRUE; | 221 | _indent = TRUE; |
222 | } | 222 | } |
223 | 223 | ||
224 | OSelector::OSelector( Orientation o, QWidget *parent, const char *name ) | 224 | OSelector::OSelector( Orientation o, QWidget *parent, const char *name ) |
225 | : QWidget( parent, name ), QRangeControl() | 225 | : QWidget( parent, name ), QRangeControl() |
226 | { | 226 | { |
227 | _orientation = o; | 227 | _orientation = o; |
228 | _indent = TRUE; | 228 | _indent = TRUE; |
229 | } | 229 | } |
230 | 230 | ||
231 | 231 | ||
232 | OSelector::~OSelector() | 232 | OSelector::~OSelector() |
233 | {} | 233 | {} |
234 | 234 | ||
235 | 235 | ||
236 | QRect OSelector::contentsRect() const | 236 | QRect OSelector::contentsRect() const |
237 | { | 237 | { |
238 | if ( orientation() == Vertical ) | 238 | if ( orientation() == Vertical ) |
239 | return QRect( 2, 5, width()-9, height()-10 ); | 239 | return QRect( 2, 5, width()-9, height()-10 ); |
240 | else | 240 | else |
241 | return QRect( 5, 2, width()-10, height()-9 ); | 241 | return QRect( 5, 2, width()-10, height()-9 ); |
242 | } | 242 | } |
243 | 243 | ||
244 | void OSelector::paintEvent( QPaintEvent * ) | 244 | void OSelector::paintEvent( QPaintEvent * ) |
245 | { | 245 | { |
246 | QPainter painter; | 246 | QPainter painter; |
247 | 247 | ||
248 | painter.begin( this ); | 248 | painter.begin( this ); |
249 | 249 | ||
250 | drawContents( &painter ); | 250 | drawContents( &painter ); |
251 | 251 | ||
252 | QBrush brush; | 252 | QBrush brush; |
253 | 253 | ||
254 | if ( indent() ) | 254 | if ( indent() ) |
255 | { | 255 | { |
256 | if ( orientation() == Vertical ) | 256 | if ( orientation() == Vertical ) |
257 | qDrawShadePanel( &painter, 0, 3, width()-5, height()-6, | 257 | qDrawShadePanel( &painter, 0, 3, width()-5, height()-6, |
258 | colorGroup(), TRUE, 2, &brush ); | 258 | colorGroup(), TRUE, 2, &brush ); |
259 | else | 259 | else |
260 | qDrawShadePanel( &painter, 3, 0, width()-6, height()-5, | 260 | qDrawShadePanel( &painter, 3, 0, width()-6, height()-5, |
261 | colorGroup(), TRUE, 2, &brush ); | 261 | colorGroup(), TRUE, 2, &brush ); |
262 | } | 262 | } |
263 | 263 | ||
264 | QPoint pos = calcArrowPos( value() ); | 264 | QPoint pos = calcArrowPos( value() ); |
265 | drawArrow( &painter, TRUE, pos ); | 265 | drawArrow( &painter, TRUE, pos ); |
266 | 266 | ||
267 | painter.end(); | 267 | painter.end(); |
268 | } | 268 | } |
269 | 269 | ||
270 | void OSelector::mousePressEvent( QMouseEvent *e ) | 270 | void OSelector::mousePressEvent( QMouseEvent *e ) |
271 | { | 271 | { |
272 | moveArrow( e->pos() ); | 272 | moveArrow( e->pos() ); |
273 | } | 273 | } |
274 | 274 | ||
275 | void OSelector::mouseMoveEvent( QMouseEvent *e ) | 275 | void OSelector::mouseMoveEvent( QMouseEvent *e ) |
276 | { | 276 | { |
277 | moveArrow( e->pos() ); | 277 | moveArrow( e->pos() ); |
278 | } | 278 | } |
279 | 279 | ||
280 | void OSelector::wheelEvent( QWheelEvent *e ) | 280 | void OSelector::wheelEvent( QWheelEvent *e ) |
281 | { | 281 | { |
282 | int val = value() + e->delta()/120; | 282 | int val = value() + e->delta()/120; |
283 | emit valueChanged( val ); | 283 | emit valueChanged( val ); |
284 | setValue( val ); | 284 | setValue( val ); |
285 | } | 285 | } |
286 | 286 | ||
287 | void OSelector::valueChange() | 287 | void OSelector::valueChange() |
288 | { | 288 | { |
289 | QPainter painter; | 289 | QPainter painter; |
290 | QPoint pos; | 290 | QPoint pos; |
291 | 291 | ||
292 | painter.begin( this ); | 292 | painter.begin( this ); |
293 | 293 | ||
294 | pos = calcArrowPos( prevValue() ); | 294 | pos = calcArrowPos( prevValue() ); |
295 | drawArrow( &painter, FALSE, pos ); | 295 | drawArrow( &painter, FALSE, pos ); |
296 | 296 | ||
297 | pos = calcArrowPos( value() ); | 297 | pos = calcArrowPos( value() ); |
298 | drawArrow( &painter, TRUE, pos ); | 298 | drawArrow( &painter, TRUE, pos ); |
299 | 299 | ||
300 | painter.end(); | 300 | painter.end(); |
301 | } | 301 | } |
302 | 302 | ||
303 | void OSelector::moveArrow( const QPoint &pos ) | 303 | void OSelector::moveArrow( const QPoint &pos ) |
304 | { | 304 | { |
305 | int val; | 305 | int val; |
306 | 306 | ||
307 | if ( orientation() == Vertical ) | 307 | if ( orientation() == Vertical ) |
308 | val = ( maxValue() - minValue() ) * (height()-pos.y()-3) | 308 | val = ( maxValue() - minValue() ) * (height()-pos.y()-3) |
309 | / (height()-10) + minValue(); | 309 | / (height()-10) + minValue(); |
310 | else | 310 | else |
311 | val = ( maxValue() - minValue() ) * (width()-pos.x()-3) | 311 | val = ( maxValue() - minValue() ) * (width()-pos.x()-3) |
312 | / (width()-10) + minValue(); | 312 | / (width()-10) + minValue(); |
313 | 313 | ||
314 | if ( val > maxValue() ) | 314 | if ( val > maxValue() ) |
315 | val = maxValue(); | 315 | val = maxValue(); |
316 | if ( val < minValue() ) | 316 | if ( val < minValue() ) |
317 | val = minValue(); | 317 | val = minValue(); |
318 | 318 | ||
319 | emit valueChanged( val ); | 319 | emit valueChanged( val ); |
320 | setValue( val ); | 320 | setValue( val ); |
321 | } | 321 | } |
322 | 322 | ||
323 | QPoint OSelector::calcArrowPos( int val ) | 323 | QPoint OSelector::calcArrowPos( int val ) |
324 | { | 324 | { |
325 | QPoint p; | 325 | QPoint p; |
326 | 326 | ||
327 | if ( orientation() == Vertical ) | 327 | if ( orientation() == Vertical ) |
328 | { | 328 | { |
329 | p.setY( height() - ( (height()-10) * val | 329 | p.setY( height() - ( (height()-10) * val |
330 | / ( maxValue() - minValue() ) + 5 ) ); | 330 | / ( maxValue() - minValue() ) + 5 ) ); |
331 | p.setX( width() - 5 ); | 331 | p.setX( width() - 5 ); |
332 | } | 332 | } |
333 | else | 333 | else |
334 | { | 334 | { |
335 | p.setX( width() - ( (width()-10) * val | 335 | p.setX( width() - ( (width()-10) * val |
336 | / ( maxValue() - minValue() ) + 5 ) ); | 336 | / ( maxValue() - minValue() ) + 5 ) ); |
337 | p.setY( height() - 5 ); | 337 | p.setY( height() - 5 ); |
338 | } | 338 | } |
339 | 339 | ||
340 | return p; | 340 | return p; |
341 | } | 341 | } |
342 | 342 | ||
343 | void OSelector::drawContents( QPainter * ) | 343 | void OSelector::drawContents( QPainter * ) |
344 | {} | 344 | {} |
345 | 345 | ||
346 | void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos ) | 346 | void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos ) |
347 | { | 347 | { |
348 | if ( show ) | 348 | if ( show ) |
349 | { | 349 | { |
350 | QPointArray array(3); | 350 | QPointArray array(3); |
351 | 351 | ||
352 | painter->setPen( QPen() ); | 352 | painter->setPen( QPen() ); |
353 | painter->setBrush( QBrush( colorGroup().buttonText() ) ); | 353 | painter->setBrush( QBrush( colorGroup().buttonText() ) ); |
354 | if ( orientation() == Vertical ) | 354 | if ( orientation() == Vertical ) |
355 | { | 355 | { |
356 | array.setPoint( 0, pos.x()+0, pos.y()+0 ); | 356 | array.setPoint( 0, pos.x()+0, pos.y()+0 ); |
357 | array.setPoint( 1, pos.x()+5, pos.y()+5 ); | 357 | array.setPoint( 1, pos.x()+5, pos.y()+5 ); |
358 | array.setPoint( 2, pos.x()+5, pos.y()-5 ); | 358 | array.setPoint( 2, pos.x()+5, pos.y()-5 ); |
359 | } | 359 | } |
360 | else | 360 | else |
361 | { | 361 | { |
362 | array.setPoint( 0, pos.x()+0, pos.y()+0 ); | 362 | array.setPoint( 0, pos.x()+0, pos.y()+0 ); |
363 | array.setPoint( 1, pos.x()+5, pos.y()+5 ); | 363 | array.setPoint( 1, pos.x()+5, pos.y()+5 ); |
364 | array.setPoint( 2, pos.x()-5, pos.y()+5 ); | 364 | array.setPoint( 2, pos.x()-5, pos.y()+5 ); |
365 | } | 365 | } |
366 | 366 | ||
367 | painter->drawPolygon( array ); | 367 | painter->drawPolygon( array ); |
368 | } | 368 | } |
369 | else | 369 | else |
370 | { | 370 | { |
371 | if ( orientation() == Vertical ) | 371 | if ( orientation() == Vertical ) |
372 | { | 372 | { |
373 | repaint(pos.x(), pos.y()-5, 6, 11, true); | 373 | repaint(pos.x(), pos.y()-5, 6, 11, true); |
374 | } | 374 | } |
375 | else | 375 | else |
376 | { | 376 | { |
377 | repaint(pos.x()-5, pos.y(), 11, 6, true); | 377 | repaint(pos.x()-5, pos.y(), 11, 6, true); |
378 | } | 378 | } |
379 | } | 379 | } |
380 | } | 380 | } |
381 | 381 | ||
382 | //---------------------------------------------------------------------------- | 382 | //---------------------------------------------------------------------------- |
383 | 383 | ||
384 | OGradientSelector::OGradientSelector( QWidget *parent, const char *name ) | 384 | OGradientSelector::OGradientSelector( QWidget *parent, const char *name ) |
385 | : OSelector( parent, name ) | 385 | : OSelector( parent, name ) |
386 | { | 386 | { |
387 | init(); | 387 | init(); |
388 | } | 388 | } |
389 | 389 | ||
390 | 390 | ||
391 | OGradientSelector::OGradientSelector( Orientation o, QWidget *parent, | 391 | OGradientSelector::OGradientSelector( Orientation o, QWidget *parent, |
392 | const char *name ) | 392 | const char *name ) |
393 | : OSelector( o, parent, name ) | 393 | : OSelector( o, parent, name ) |
394 | { | 394 | { |
395 | init(); | 395 | init(); |
396 | } | 396 | } |
397 | 397 | ||
398 | 398 | ||
399 | OGradientSelector::~OGradientSelector() | 399 | OGradientSelector::~OGradientSelector() |
400 | {} | 400 | {} |
401 | 401 | ||
402 | 402 | ||
403 | void OGradientSelector::init() | 403 | void OGradientSelector::init() |
404 | { | 404 | { |
405 | color1.setRgb( 0, 0, 0 ); | 405 | color1.setRgb( 0, 0, 0 ); |
406 | color2.setRgb( 255, 255, 255 ); | 406 | color2.setRgb( 255, 255, 255 ); |
407 | 407 | ||
408 | text1 = text2 = ""; | 408 | text1 = text2 = ""; |
409 | } | 409 | } |
410 | 410 | ||
411 | 411 | ||
412 | void OGradientSelector::drawContents( QPainter *painter ) | 412 | void OGradientSelector::drawContents( QPainter *painter ) |
413 | { | 413 | { |
414 | QImage image( contentsRect().width(), contentsRect().height(), 32 ); | 414 | QImage image( contentsRect().width(), contentsRect().height(), 32 ); |
415 | 415 | ||
416 | QColor col; | 416 | QColor col; |
417 | float scale; | 417 | float scale; |
418 | 418 | ||
419 | int redDiff = color2.red() - color1.red(); | 419 | int redDiff = color2.red() - color1.red(); |
420 | int greenDiff = color2.green() - color1.green(); | 420 | int greenDiff = color2.green() - color1.green(); |
421 | int blueDiff = color2.blue() - color1.blue(); | 421 | int blueDiff = color2.blue() - color1.blue(); |
422 | 422 | ||
423 | if ( orientation() == Vertical ) | 423 | if ( orientation() == Vertical ) |
424 | { | 424 | { |
425 | for ( int y = 0; y < image.height(); y++ ) | 425 | for ( int y = 0; y < image.height(); y++ ) |
426 | { | 426 | { |
427 | scale = 1.0 * y / image.height(); | 427 | scale = 1.0 * y / image.height(); |
428 | col.setRgb( color1.red() + int(redDiff*scale), | 428 | col.setRgb( color1.red() + int(redDiff*scale), |
429 | color1.green() + int(greenDiff*scale), | 429 | color1.green() + int(greenDiff*scale), |
430 | color1.blue() + int(blueDiff*scale) ); | 430 | color1.blue() + int(blueDiff*scale) ); |
431 | 431 | ||
432 | unsigned int *p = (uint *) image.scanLine( y ); | 432 | unsigned int *p = (uint *) image.scanLine( y ); |
433 | for ( int x = 0; x < image.width(); x++ ) | 433 | for ( int x = 0; x < image.width(); x++ ) |
434 | *p++ = col.rgb(); | 434 | *p++ = col.rgb(); |
435 | } | 435 | } |
436 | } | 436 | } |
437 | else | 437 | else |
438 | { | 438 | { |
439 | unsigned int *p = (uint *) image.scanLine( 0 ); | 439 | unsigned int *p = (uint *) image.scanLine( 0 ); |
440 | 440 | ||
441 | for ( int x = 0; x < image.width(); x++ ) | 441 | for ( int x = 0; x < image.width(); x++ ) |
442 | { | 442 | { |
443 | scale = 1.0 * x / image.width(); | 443 | scale = 1.0 * x / image.width(); |
444 | col.setRgb( color1.red() + int(redDiff*scale), | 444 | col.setRgb( color1.red() + int(redDiff*scale), |
445 | color1.green() + int(greenDiff*scale), | 445 | color1.green() + int(greenDiff*scale), |
446 | color1.blue() + int(blueDiff*scale) ); | 446 | color1.blue() + int(blueDiff*scale) ); |
447 | *p++ = col.rgb(); | 447 | *p++ = col.rgb(); |
448 | } | 448 | } |
449 | 449 | ||
450 | for ( int y = 1; y < image.height(); y++ ) | 450 | for ( int y = 1; y < image.height(); y++ ) |
451 | memcpy( image.scanLine( y ), image.scanLine( y - 1), | 451 | memcpy( image.scanLine( y ), image.scanLine( y - 1), |
452 | sizeof( unsigned int ) * image.width() ); | 452 | sizeof( unsigned int ) * image.width() ); |
453 | } | 453 | } |
454 | 454 | ||
455 | QColor ditherPalette[8]; | 455 | QColor ditherPalette[8]; |
456 | 456 | ||
457 | for ( int s = 0; s < 8; s++ ) | 457 | for ( int s = 0; s < 8; s++ ) |
458 | ditherPalette[s].setRgb( color1.red() + redDiff * s / 8, | 458 | ditherPalette[s].setRgb( color1.red() + redDiff * s / 8, |
459 | color1.green() + greenDiff * s / 8, | 459 | color1.green() + greenDiff * s / 8, |
460 | color1.blue() + blueDiff * s / 8 ); | 460 | color1.blue() + blueDiff * s / 8 ); |
461 | 461 | ||
462 | OImageEffect::dither( image, ditherPalette, 8 ); | 462 | OImageEffect::dither( image, ditherPalette, 8 ); |
463 | 463 | ||
464 | QPixmap p; | 464 | QPixmap p; |
465 | p.convertFromImage( image ); | 465 | p.convertFromImage( image ); |
466 | 466 | ||
467 | painter->drawPixmap( contentsRect().x(), contentsRect().y(), p ); | 467 | painter->drawPixmap( contentsRect().x(), contentsRect().y(), p ); |
468 | 468 | ||
469 | if ( orientation() == Vertical ) | 469 | if ( orientation() == Vertical ) |
470 | { | 470 | { |
471 | int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2; | 471 | int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2; |
472 | int xPos = contentsRect().left() + (contentsRect().width() - | 472 | int xPos = contentsRect().left() + (contentsRect().width() - |
473 | painter->fontMetrics().width( text2 )) / 2; | 473 | painter->fontMetrics().width( text2 )) / 2; |
474 | QPen pen( color2 ); | 474 | QPen pen( color2 ); |
475 | painter->setPen( pen ); | 475 | painter->setPen( pen ); |
476 | painter->drawText( xPos, yPos, text2 ); | 476 | painter->drawText( xPos, yPos, text2 ); |
477 | 477 | ||
478 | yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2; | 478 | yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2; |
479 | xPos = contentsRect().left() + (contentsRect().width() - | 479 | xPos = contentsRect().left() + (contentsRect().width() - |
480 | painter->fontMetrics().width( text1 )) / 2; | 480 | painter->fontMetrics().width( text1 )) / 2; |
481 | pen.setColor( color1 ); | 481 | pen.setColor( color1 ); |
482 | painter->setPen( pen ); | 482 | painter->setPen( pen ); |
483 | painter->drawText( xPos, yPos, text1 ); | 483 | painter->drawText( xPos, yPos, text1 ); |
484 | } | 484 | } |
485 | else | 485 | else |
486 | { | 486 | { |
487 | int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2; | 487 | int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2; |
488 | 488 | ||
489 | QPen pen( color2 ); | 489 | QPen pen( color2 ); |
490 | painter->setPen( pen ); | 490 | painter->setPen( pen ); |
491 | painter->drawText( contentsRect().left() + 2, yPos, text1 ); | 491 | painter->drawText( contentsRect().left() + 2, yPos, text1 ); |
492 | 492 | ||
493 | pen.setColor( color1 ); | 493 | pen.setColor( color1 ); |
494 | painter->setPen( pen ); | 494 | painter->setPen( pen ); |
495 | painter->drawText( contentsRect().right() - | 495 | painter->drawText( contentsRect().right() - |
496 | painter->fontMetrics().width( text2 ) - 2, yPos, text2 ); | 496 | painter->fontMetrics().width( text2 ) - 2, yPos, text2 ); |
497 | } | 497 | } |
498 | } | 498 | } |
499 | 499 | ||
500 | //----------------------------------------------------------------------------- | 500 | //----------------------------------------------------------------------------- |
501 | 501 | ||
502 | static QColor *standardPalette = 0; | 502 | static QColor *standardPalette = 0; |
503 | 503 | ||
504 | #define STANDARD_PAL_SIZE 17 | 504 | #define STANDARD_PAL_SIZE 17 |
505 | 505 | ||
506 | OColor::OColor() | 506 | OColor::OColor() |
507 | : QColor() | 507 | : QColor() |
508 | { | 508 | { |
509 | r = 0; g = 0; b = 0; h = 0; s = 0; v = 0; | 509 | r = 0; g = 0; b = 0; h = 0; s = 0; v = 0; |
510 | }; | 510 | }; |
511 | 511 | ||
512 | OColor::OColor( const OColor &col) | 512 | OColor::OColor( const OColor &col) |
513 | : QColor( col ) | 513 | : QColor( col ) |
514 | { | 514 | { |
515 | h = col.h; s = col.s; v = col.v; | 515 | h = col.h; s = col.s; v = col.v; |
516 | r = col.r; g = col.g; b = col.b; | 516 | r = col.r; g = col.g; b = col.b; |
517 | }; | 517 | }; |
518 | 518 | ||
519 | OColor::OColor( const QColor &col) | 519 | OColor::OColor( const QColor &col) |
520 | : QColor( col ) | 520 | : QColor( col ) |
521 | { | 521 | { |
522 | QColor::rgb(&r, &g, &b); | 522 | QColor::rgb(&r, &g, &b); |
523 | QColor::hsv(&h, &s, &v); | 523 | QColor::hsv(&h, &s, &v); |
524 | }; | 524 | }; |
525 | 525 | ||
526 | bool OColor::operator==(const OColor& col) const | 526 | bool OColor::operator==(const OColor& col) const |
527 | { | 527 | { |
528 | return (h == col.h) && (s == col.s) && (v == col.v) && | 528 | return (h == col.h) && (s == col.s) && (v == col.v) && |
529 | (r == col.r) && (g == col.g) && (b == col.b); | 529 | (r == col.r) && (g == col.g) && (b == col.b); |
530 | } | 530 | } |
531 | 531 | ||
532 | OColor& OColor::operator=(const OColor& col) | 532 | OColor& OColor::operator=(const OColor& col) |
533 | { | 533 | { |
534 | *(QColor *)this = col; | 534 | *(QColor *)this = col; |
535 | h = col.h; s = col.s; v = col.v; | 535 | h = col.h; s = col.s; v = col.v; |
536 | r = col.r; g = col.g; b = col.b; | 536 | r = col.r; g = col.g; b = col.b; |
537 | return *this; | 537 | return *this; |
538 | } | 538 | } |
539 | 539 | ||
540 | void | 540 | void |
541 | OColor::setHsv(int _h, int _s, int _v) | 541 | OColor::setHsv(int _h, int _s, int _v) |
542 | { | 542 | { |
543 | h = _h; s = _s; v = _v; | 543 | h = _h; s = _s; v = _v; |
544 | QColor::setHsv(h, s, v); | 544 | QColor::setHsv(h, s, v); |
545 | QColor::rgb(&r, &g, &b); | 545 | QColor::rgb(&r, &g, &b); |
546 | }; | 546 | }; |
547 | 547 | ||
548 | void | 548 | void |
549 | OColor::setRgb(int _r, int _g, int _b) | 549 | OColor::setRgb(int _r, int _g, int _b) |
550 | { | 550 | { |
551 | r = _r; g = _g; b = _b; | 551 | r = _r; g = _g; b = _b; |
552 | QColor::setRgb(r, g, b); | 552 | QColor::setRgb(r, g, b); |
553 | QColor::hsv(&h, &s, &v); | 553 | QColor::hsv(&h, &s, &v); |
554 | } | 554 | } |
555 | 555 | ||
556 | void | 556 | void |
557 | OColor::rgb(int *_r, int *_g, int *_b) const | 557 | OColor::rgb(int *_r, int *_g, int *_b) const |
558 | { | 558 | { |
559 | *_r = r; *_g = g; *_b = b; | 559 | *_r = r; *_g = g; *_b = b; |
560 | } | 560 | } |
561 | 561 | ||
562 | void | 562 | void |
563 | OColor::hsv(int *_h, int *_s, int *_v) const | 563 | OColor::hsv(int *_h, int *_s, int *_v) const |
564 | { | 564 | { |
565 | *_h = h; *_s = s; *_v = v; | 565 | *_h = h; *_s = s; *_v = v; |
566 | } | 566 | } |
567 | 567 | ||
568 | static void createStandardPalette() | 568 | static void createStandardPalette() |
569 | { | 569 | { |
570 | if ( standardPalette ) | 570 | if ( standardPalette ) |
571 | return; | 571 | return; |
572 | 572 | ||
573 | standardPalette = new QColor[STANDARD_PAL_SIZE]; | 573 | standardPalette = new QColor[STANDARD_PAL_SIZE]; |
574 | 574 | ||
575 | int i = 0; | 575 | int i = 0; |
576 | 576 | ||
577 | standardPalette[i++] = Qt::red; | 577 | standardPalette[i++] = Qt::red; |
578 | standardPalette[i++] = Qt::green; | 578 | standardPalette[i++] = Qt::green; |
579 | standardPalette[i++] = Qt::blue; | 579 | standardPalette[i++] = Qt::blue; |
580 | standardPalette[i++] = Qt::cyan; | 580 | standardPalette[i++] = Qt::cyan; |
581 | standardPalette[i++] = Qt::magenta; | 581 | standardPalette[i++] = Qt::magenta; |
582 | standardPalette[i++] = Qt::yellow; | 582 | standardPalette[i++] = Qt::yellow; |
583 | standardPalette[i++] = Qt::darkRed; | 583 | standardPalette[i++] = Qt::darkRed; |
584 | standardPalette[i++] = Qt::darkGreen; | 584 | standardPalette[i++] = Qt::darkGreen; |
585 | standardPalette[i++] = Qt::darkBlue; | 585 | standardPalette[i++] = Qt::darkBlue; |
586 | standardPalette[i++] = Qt::darkCyan; | 586 | standardPalette[i++] = Qt::darkCyan; |
587 | standardPalette[i++] = Qt::darkMagenta; | 587 | standardPalette[i++] = Qt::darkMagenta; |
588 | standardPalette[i++] = Qt::darkYellow; | 588 | standardPalette[i++] = Qt::darkYellow; |
589 | standardPalette[i++] = Qt::white; | 589 | standardPalette[i++] = Qt::white; |
590 | standardPalette[i++] = Qt::lightGray; | 590 | standardPalette[i++] = Qt::lightGray; |
591 | standardPalette[i++] = Qt::gray; | 591 | standardPalette[i++] = Qt::gray; |
592 | standardPalette[i++] = Qt::darkGray; | 592 | standardPalette[i++] = Qt::darkGray; |
593 | standardPalette[i++] = Qt::black; | 593 | standardPalette[i++] = Qt::black; |
594 | } | 594 | } |
595 | 595 | ||
596 | 596 | ||
597 | OHSSelector::OHSSelector( QWidget *parent, const char *name ) | 597 | OHSSelector::OHSSelector( QWidget *parent, const char *name ) |
598 | : OXYSelector( parent, name ) | 598 | : OXYSelector( parent, name ) |
599 | { | 599 | { |
600 | setRange( 0, 0, 359, 255 ); | 600 | setRange( 0, 0, 359, 255 ); |
601 | } | 601 | } |
602 | 602 | ||
603 | void OHSSelector::updateContents() | 603 | void OHSSelector::updateContents() |
604 | { | 604 | { |
605 | drawPalette(&pixmap); | 605 | drawPalette(&pixmap); |
606 | } | 606 | } |
607 | 607 | ||
608 | void OHSSelector::resizeEvent( QResizeEvent * ) | 608 | void OHSSelector::resizeEvent( QResizeEvent * ) |
609 | { | 609 | { |
610 | updateContents(); | 610 | updateContents(); |
611 | } | 611 | } |
612 | 612 | ||
613 | void OHSSelector::drawContents( QPainter *painter ) | 613 | void OHSSelector::drawContents( QPainter *painter ) |
614 | { | 614 | { |
615 | painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap ); | 615 | painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap ); |
616 | } | 616 | } |
617 | 617 | ||
618 | void OHSSelector::drawPalette( QPixmap *pixmap ) | 618 | void OHSSelector::drawPalette( QPixmap *pixmap ) |
619 | { | 619 | { |
620 | int xSize = contentsRect().width(), ySize = contentsRect().height(); | 620 | int xSize = contentsRect().width(), ySize = contentsRect().height(); |
621 | QImage image( xSize, ySize, 32 ); | 621 | QImage image( xSize, ySize, 32 ); |
622 | QColor col; | 622 | QColor col; |
623 | int h, s; | 623 | int h, s; |
624 | uint *p; | 624 | uint *p; |
625 | 625 | ||
626 | for ( s = ySize-1; s >= 0; s-- ) | 626 | for ( s = ySize-1; s >= 0; s-- ) |
627 | { | 627 | { |
628 | p = (uint *) image.scanLine( ySize - s - 1 ); | 628 | p = (uint *) image.scanLine( ySize - s - 1 ); |
629 | for( h = 0; h < xSize; h++ ) | 629 | for( h = 0; h < xSize; h++ ) |
630 | { | 630 | { |
631 | col.setHsv( 359*h/(xSize-1), 255*s/(ySize-1), 192 ); | 631 | col.setHsv( 359*h/(xSize-1), 255*s/(ySize-1), 192 ); |
632 | *p = col.rgb(); | 632 | *p = col.rgb(); |
633 | p++; | 633 | p++; |
634 | } | 634 | } |
635 | } | 635 | } |
636 | 636 | ||
637 | if ( QColor::numBitPlanes() <= 8 ) | 637 | if ( QColor::numBitPlanes() <= 8 ) |
638 | { | 638 | { |
639 | createStandardPalette(); | 639 | createStandardPalette(); |
640 | OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE ); | 640 | OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE ); |
641 | } | 641 | } |
642 | pixmap->convertFromImage( image ); | 642 | pixmap->convertFromImage( image ); |
643 | } | 643 | } |
644 | 644 | ||
645 | 645 | ||
646 | //----------------------------------------------------------------------------- | 646 | //----------------------------------------------------------------------------- |
647 | 647 | ||
648 | OValueSelector::OValueSelector( QWidget *parent, const char *name ) | 648 | OValueSelector::OValueSelector( QWidget *parent, const char *name ) |
649 | : OSelector( OSelector::Vertical, parent, name ), _hue(0), _sat(0) | 649 | : OSelector( OSelector::Vertical, parent, name ), _hue(0), _sat(0) |
650 | { | 650 | { |
651 | setRange( 0, 255 ); | 651 | setRange( 0, 255 ); |
652 | pixmap.setOptimization( QPixmap::BestOptim ); | 652 | pixmap.setOptimization( QPixmap::BestOptim ); |
653 | } | 653 | } |
654 | 654 | ||
655 | OValueSelector::OValueSelector(Orientation o, QWidget *parent, const char *name | 655 | OValueSelector::OValueSelector(Orientation o, QWidget *parent, const char *name |
656 | ) | 656 | ) |
657 | : OSelector( o, parent, name), _hue(0), _sat(0) | 657 | : OSelector( o, parent, name), _hue(0), _sat(0) |
658 | { | 658 | { |
659 | setRange( 0, 255 ); | 659 | setRange( 0, 255 ); |
660 | pixmap.setOptimization( QPixmap::BestOptim ); | 660 | pixmap.setOptimization( QPixmap::BestOptim ); |
661 | } | 661 | } |
662 | 662 | ||
663 | void OValueSelector::updateContents() | 663 | void OValueSelector::updateContents() |
664 | { | 664 | { |
665 | drawPalette(&pixmap); | 665 | drawPalette(&pixmap); |
666 | } | 666 | } |
667 | 667 | ||
668 | void OValueSelector::resizeEvent( QResizeEvent * ) | 668 | void OValueSelector::resizeEvent( QResizeEvent * ) |
669 | { | 669 | { |
670 | updateContents(); | 670 | updateContents(); |
671 | } | 671 | } |
672 | 672 | ||
673 | void OValueSelector::drawContents( QPainter *painter ) | 673 | void OValueSelector::drawContents( QPainter *painter ) |
674 | { | 674 | { |
675 | painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap ); | 675 | painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap ); |
676 | } | 676 | } |
677 | 677 | ||
678 | void OValueSelector::drawPalette( QPixmap *pixmap ) | 678 | void OValueSelector::drawPalette( QPixmap *pixmap ) |
679 | { | 679 | { |
680 | int xSize = contentsRect().width(), ySize = contentsRect().height(); | 680 | int xSize = contentsRect().width(), ySize = contentsRect().height(); |
681 | QImage image( xSize, ySize, 32 ); | 681 | QImage image( xSize, ySize, 32 ); |
682 | QColor col; | 682 | QColor col; |
683 | uint *p; | 683 | uint *p; |
684 | QRgb rgb; | 684 | QRgb rgb; |
685 | 685 | ||
686 | if ( orientation() == OSelector::Horizontal ) | 686 | if ( orientation() == OSelector::Horizontal ) |
687 | { | 687 | { |
688 | for ( int v = 0; v < ySize; v++ ) | 688 | for ( int v = 0; v < ySize; v++ ) |
689 | { | 689 | { |
690 | p = (uint *) image.scanLine( ySize - v - 1 ); | 690 | p = (uint *) image.scanLine( ySize - v - 1 ); |
691 | 691 | ||
692 | for( int x = 0; x < xSize; x++ ) | 692 | for( int x = 0; x < xSize; x++ ) |
693 | { | 693 | { |
694 | col.setHsv( _hue, _sat, 255*x/(xSize-1) ); | 694 | col.setHsv( _hue, _sat, 255*x/(xSize-1) ); |
695 | rgb = col.rgb(); | 695 | rgb = col.rgb(); |
696 | *p++ = rgb; | 696 | *p++ = rgb; |
697 | } | 697 | } |
698 | } | 698 | } |
699 | } | 699 | } |
700 | 700 | ||
701 | if( orientation() == OSelector::Vertical ) | 701 | if( orientation() == OSelector::Vertical ) |
702 | { | 702 | { |
703 | for ( int v = 0; v < ySize; v++ ) | 703 | for ( int v = 0; v < ySize; v++ ) |
704 | { | 704 | { |
705 | p = (uint *) image.scanLine( ySize - v - 1 ); | 705 | p = (uint *) image.scanLine( ySize - v - 1 ); |
706 | col.setHsv( _hue, _sat, 255*v/(ySize-1) ); | 706 | col.setHsv( _hue, _sat, 255*v/(ySize-1) ); |
707 | rgb = col.rgb(); | 707 | rgb = col.rgb(); |
708 | for ( int i = 0; i < xSize; i++ ) | 708 | for ( int i = 0; i < xSize; i++ ) |
709 | *p++ = rgb; | 709 | *p++ = rgb; |
710 | } | 710 | } |
711 | } | 711 | } |
712 | 712 | ||
713 | if ( QColor::numBitPlanes() <= 8 ) | 713 | if ( QColor::numBitPlanes() <= 8 ) |
714 | { | 714 | { |
715 | createStandardPalette(); | 715 | createStandardPalette(); |
716 | OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE ); | 716 | OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE ); |
717 | } | 717 | } |
718 | pixmap->convertFromImage( image ); | 718 | pixmap->convertFromImage( image ); |
719 | } | 719 | } |
diff --git a/libopie2/opieui/oselector.h b/libopie2/opieui/oselector.h index fe75a46..3dbdb38 100644 --- a/libopie2/opieui/oselector.h +++ b/libopie2/opieui/oselector.h | |||
@@ -1,523 +1,523 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1997 Martin Jones (mjones@kde.org) | 2 | Copyright (C) 1997 Martin Jones (mjones@kde.org) |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | //----------------------------------------------------------------------------- | 19 | //----------------------------------------------------------------------------- |
20 | // Selector widgets for KDE Color Selector, but probably useful for other | 20 | // Selector widgets for KDE Color Selector, but probably useful for other |
21 | // stuff also. | 21 | // stuff also. |
22 | 22 | ||
23 | #ifndef __OSELECT_H__ | 23 | #ifndef __OSELECT_H__ |
24 | #define __OSELECT_H__ | 24 | #define __OSELECT_H__ |
25 | 25 | ||
26 | #include <qwidget.h> | 26 | #include <qwidget.h> |
27 | #include <qrangecontrol.h> | 27 | #include <qrangecontrol.h> |
28 | #include <qpixmap.h> | 28 | #include <qpixmap.h> |
29 | 29 | ||
30 | 30 | ||
31 | namespace Opie { | 31 | namespace Opie { |
32 | namespace Ui { | 32 | namespace Ui { |
33 | /** | 33 | /** |
34 | * OXYSelector is the base class for other widgets which | 34 | * OXYSelector is the base class for other widgets which |
35 | * provides the ability to choose from a two-dimensional | 35 | * provides the ability to choose from a two-dimensional |
36 | * range of values. The currently chosen value is indicated | 36 | * range of values. The currently chosen value is indicated |
37 | * by a cross. An example is the @ref OHSSelector which | 37 | * by a cross. An example is the @ref OHSSelector which |
38 | * allows to choose from a range of colors, and which is | 38 | * allows to choose from a range of colors, and which is |
39 | * used in OColorDialog. | 39 | * used in OColorDialog. |
40 | * | 40 | * |
41 | * A custom drawing routine for the widget surface has | 41 | * A custom drawing routine for the widget surface has |
42 | * to be provided by the subclass. | 42 | * to be provided by the subclass. |
43 | */ | 43 | */ |
44 | class OXYSelector : public QWidget | 44 | class OXYSelector : public QWidget |
45 | { | 45 | { |
46 | Q_OBJECT | 46 | Q_OBJECT |
47 | 47 | ||
48 | public: | 48 | public: |
49 | /** | 49 | /** |
50 | * Constructs a two-dimensional selector widget which | 50 | * Constructs a two-dimensional selector widget which |
51 | * has a value range of [0..100] in both directions. | 51 | * has a value range of [0..100] in both directions. |
52 | */ | 52 | */ |
53 | OXYSelector( QWidget *parent=0, const char *name=0 ); | 53 | OXYSelector( QWidget *parent=0, const char *name=0 ); |
54 | /** | 54 | /** |
55 | * Destructs the widget. | 55 | * Destructs the widget. |
56 | */ | 56 | */ |
57 | ~OXYSelector(); | 57 | ~OXYSelector(); |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Sets the current values in horizontal and | 60 | * Sets the current values in horizontal and |
61 | * vertical direction. | 61 | * vertical direction. |
62 | */ | 62 | */ |
63 | void setValues( int xPos, int yPos ); | 63 | void setValues( int xPos, int yPos ); |
64 | /** | 64 | /** |
65 | * Sets the range of possible values. | 65 | * Sets the range of possible values. |
66 | */ | 66 | */ |
67 | void setRange( int minX, int minY, int maxX, int maxY ); | 67 | void setRange( int minX, int minY, int maxX, int maxY ); |
68 | 68 | ||
69 | /** | 69 | /** |
70 | * @return the current value in horizontal direction. | 70 | * @return the current value in horizontal direction. |
71 | */ | 71 | */ |
72 | int xValue() const {return xPos; } | 72 | int xValue() const {return xPos; } |
73 | /** | 73 | /** |
74 | * @return the current value in vertical direction. | 74 | * @return the current value in vertical direction. |
75 | */ | 75 | */ |
76 | int yValue() const {return yPos; } | 76 | int yValue() const {return yPos; } |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * @return the rectangle on which subclasses should draw. | 79 | * @return the rectangle on which subclasses should draw. |
80 | */ | 80 | */ |
81 | QRect contentsRect() const; | 81 | QRect contentsRect() const; |
82 | 82 | ||
83 | signals: | 83 | signals: |
84 | /** | 84 | /** |
85 | * This signal is emitted whenever the user chooses a value, | 85 | * This signal is emitted whenever the user chooses a value, |
86 | * e.g. by clicking with the mouse on the widget. | 86 | * e.g. by clicking with the mouse on the widget. |
87 | */ | 87 | */ |
88 | void valueChanged( int x, int y ); | 88 | void valueChanged( int x, int y ); |
89 | 89 | ||
90 | protected: | 90 | protected: |
91 | /** | 91 | /** |
92 | * Override this function to draw the contents of the widget. | 92 | * Override this function to draw the contents of the widget. |
93 | * The default implementation does nothing. | 93 | * The default implementation does nothing. |
94 | * | 94 | * |
95 | * Draw within @ref contentsRect() only. | 95 | * Draw within @ref contentsRect() only. |
96 | */ | 96 | */ |
97 | virtual void drawContents( QPainter * ); | 97 | virtual void drawContents( QPainter * ); |
98 | /** | 98 | /** |
99 | * Override this function to draw the cursor which | 99 | * Override this function to draw the cursor which |
100 | * indicates the currently selected value pair. | 100 | * indicates the currently selected value pair. |
101 | */ | 101 | */ |
102 | virtual void drawCursor( QPainter *p, int xp, int yp ); | 102 | virtual void drawCursor( QPainter *p, int xp, int yp ); |
103 | /** | 103 | /** |
104 | * @reimplemented | 104 | * @reimplemented |
105 | */ | 105 | */ |
106 | virtual void paintEvent( QPaintEvent *e ); | 106 | virtual void paintEvent( QPaintEvent *e ); |
107 | /** | 107 | /** |
108 | * @reimplemented | 108 | * @reimplemented |
109 | */ | 109 | */ |
110 | virtual void mousePressEvent( QMouseEvent *e ); | 110 | virtual void mousePressEvent( QMouseEvent *e ); |
111 | /** | 111 | /** |
112 | * @reimplemented | 112 | * @reimplemented |
113 | */ | 113 | */ |
114 | virtual void mouseMoveEvent( QMouseEvent *e ); | 114 | virtual void mouseMoveEvent( QMouseEvent *e ); |
115 | /** | 115 | /** |
116 | * @reimplemented | 116 | * @reimplemented |
117 | */ | 117 | */ |
118 | virtual void wheelEvent( QWheelEvent * ); | 118 | virtual void wheelEvent( QWheelEvent * ); |
119 | /** | 119 | /** |
120 | * Converts a pixel position to its corresponding values. | 120 | * Converts a pixel position to its corresponding values. |
121 | */ | 121 | */ |
122 | void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const; | 122 | void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const; |
123 | 123 | ||
124 | private: | 124 | private: |
125 | void setPosition( int xp, int yp ); | 125 | void setPosition( int xp, int yp ); |
126 | int px; | 126 | int px; |
127 | int py; | 127 | int py; |
128 | int xPos; | 128 | int xPos; |
129 | int yPos; | 129 | int yPos; |
130 | int minX; | 130 | int minX; |
131 | int maxX; | 131 | int maxX; |
132 | int minY; | 132 | int minY; |
133 | int maxY; | 133 | int maxY; |
134 | QPixmap store; | 134 | QPixmap store; |
135 | 135 | ||
136 | private: | 136 | private: |
137 | class OXYSelectorPrivate; | 137 | class OXYSelectorPrivate; |
138 | OXYSelectorPrivate *d; | 138 | OXYSelectorPrivate *d; |
139 | }; | 139 | }; |
140 | 140 | ||
141 | 141 | ||
142 | /** | 142 | /** |
143 | * OSelector is the base class for other widgets which | 143 | * OSelector is the base class for other widgets which |
144 | * provides the ability to choose from a one-dimensional | 144 | * provides the ability to choose from a one-dimensional |
145 | * range of values. An example is the @ref OGradientSelector | 145 | * range of values. An example is the @ref OGradientSelector |
146 | * which allows to choose from a range of colors. | 146 | * which allows to choose from a range of colors. |
147 | * | 147 | * |
148 | * A custom drawing routine for the widget surface has | 148 | * A custom drawing routine for the widget surface has |
149 | * to be provided by the subclass. | 149 | * to be provided by the subclass. |
150 | */ | 150 | */ |
151 | class OSelector : public QWidget, public QRangeControl | 151 | class OSelector : public QWidget, public QRangeControl |
152 | { | 152 | { |
153 | Q_OBJECT | 153 | Q_OBJECT |
154 | Q_PROPERTY( int value READ value WRITE setValue ) | 154 | Q_PROPERTY( int value READ value WRITE setValue ) |
155 | Q_PROPERTY( int minValue READ minValue WRITE setMinValue ) | 155 | Q_PROPERTY( int minValue READ minValue WRITE setMinValue ) |
156 | Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) | 156 | Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) |
157 | public: | 157 | public: |
158 | 158 | ||
159 | /** | 159 | /** |
160 | * Constructs a horizontal one-dimensional selection widget. | 160 | * Constructs a horizontal one-dimensional selection widget. |
161 | */ | 161 | */ |
162 | OSelector( QWidget *parent=0, const char *name=0 ); | 162 | OSelector( QWidget *parent=0, const char *name=0 ); |
163 | /** | 163 | /** |
164 | * Constructs a one-dimensional selection widget with | 164 | * Constructs a one-dimensional selection widget with |
165 | * a given orientation. | 165 | * a given orientation. |
166 | */ | 166 | */ |
167 | OSelector( Orientation o, QWidget *parent = 0L, const char *name = 0L ); | 167 | OSelector( Orientation o, QWidget *parent = 0L, const char *name = 0L ); |
168 | /* | 168 | /* |
169 | * Destructs the widget. | 169 | * Destructs the widget. |
170 | */ | 170 | */ |
171 | ~OSelector(); | 171 | ~OSelector(); |
172 | 172 | ||
173 | /** | 173 | /** |
174 | * @return the orientation of the widget. | 174 | * @return the orientation of the widget. |
175 | */ | 175 | */ |
176 | Orientation orientation() const | 176 | Orientation orientation() const |
177 | {return _orientation; } | 177 | {return _orientation; } |
178 | 178 | ||
179 | /** | 179 | /** |
180 | * @return the rectangle on which subclasses should draw. | 180 | * @return the rectangle on which subclasses should draw. |
181 | */ | 181 | */ |
182 | QRect contentsRect() const; | 182 | QRect contentsRect() const; |
183 | 183 | ||
184 | /** | 184 | /** |
185 | * Sets the indent option of the widget to i. | 185 | * Sets the indent option of the widget to i. |
186 | * This determines whether a shaded frame is drawn. | 186 | * This determines whether a shaded frame is drawn. |
187 | */ | 187 | */ |
188 | void setIndent( bool i ) | 188 | void setIndent( bool i ) |
189 | {_indent = i; } | 189 | {_indent = i; } |
190 | /** | 190 | /** |
191 | * @return whether the indent option is set. | 191 | * @return whether the indent option is set. |
192 | */ | 192 | */ |
193 | bool indent() const | 193 | bool indent() const |
194 | {return _indent; } | 194 | {return _indent; } |
195 | 195 | ||
196 | /** | 196 | /** |
197 | * Sets the value. | 197 | * Sets the value. |
198 | */ | 198 | */ |
199 | void setValue(int value) | 199 | void setValue(int value) |
200 | { QRangeControl::setValue(value); } | 200 | { QRangeControl::setValue(value); } |
201 | 201 | ||
202 | /** | 202 | /** |
203 | * @returns the value. | 203 | * @returns the value. |
204 | */ | 204 | */ |
205 | int value() const | 205 | int value() const |
206 | { return QRangeControl::value(); } | 206 | { return QRangeControl::value(); } |
207 | 207 | ||
208 | /** | 208 | /** |
209 | * Sets the min value. | 209 | * Sets the min value. |
210 | */ | 210 | */ |
211 | #if ( QT_VERSION > 290 ) | 211 | #if ( QT_VERSION >= 0x030000 ) |
212 | void setMinValue(int value) { QRangeControl::setMinValue(value); } | 212 | void setMinValue(int value) { QRangeControl::setMinValue(value); } |
213 | #else | 213 | #else |
214 | void setMinValue(int value) { QRangeControl::setRange(value,QRangeControl::maxValue()); } | 214 | void setMinValue(int value) { QRangeControl::setRange(value,QRangeControl::maxValue()); } |
215 | #endif | 215 | #endif |
216 | 216 | ||
217 | /** | 217 | /** |
218 | * @return the min value. | 218 | * @return the min value. |
219 | */ | 219 | */ |
220 | int minValue() const | 220 | int minValue() const |
221 | { return QRangeControl::minValue(); } | 221 | { return QRangeControl::minValue(); } |
222 | 222 | ||
223 | /** | 223 | /** |
224 | * Sets the max value. | 224 | * Sets the max value. |
225 | */ | 225 | */ |
226 | #if ( QT_VERSION > 290 ) | 226 | #if ( QT_VERSION >= 0x030000 ) |
227 | void setMaxValue(int value) { QRangeControl::setMaxValue(value); } | 227 | void setMaxValue(int value) { QRangeControl::setMaxValue(value); } |
228 | #else | 228 | #else |
229 | void setMaxValue(int value) { QRangeControl::setRange(QRangeControl::minValue(),value); } | 229 | void setMaxValue(int value) { QRangeControl::setRange(QRangeControl::minValue(),value); } |
230 | #endif | 230 | #endif |
231 | 231 | ||
232 | /** | 232 | /** |
233 | * @return the max value. | 233 | * @return the max value. |
234 | */ | 234 | */ |
235 | int maxValue() const | 235 | int maxValue() const |
236 | { return QRangeControl::maxValue(); } | 236 | { return QRangeControl::maxValue(); } |
237 | 237 | ||
238 | signals: | 238 | signals: |
239 | /** | 239 | /** |
240 | * This signal is emitted whenever the user chooses a value, | 240 | * This signal is emitted whenever the user chooses a value, |
241 | * e.g. by clicking with the mouse on the widget. | 241 | * e.g. by clicking with the mouse on the widget. |
242 | */ | 242 | */ |
243 | void valueChanged( int value ); | 243 | void valueChanged( int value ); |
244 | 244 | ||
245 | protected: | 245 | protected: |
246 | /** | 246 | /** |
247 | * Override this function to draw the contents of the control. | 247 | * Override this function to draw the contents of the control. |
248 | * The default implementation does nothing. | 248 | * The default implementation does nothing. |
249 | * | 249 | * |
250 | * Draw only within contentsRect(). | 250 | * Draw only within contentsRect(). |
251 | */ | 251 | */ |
252 | virtual void drawContents( QPainter * ); | 252 | virtual void drawContents( QPainter * ); |
253 | /** | 253 | /** |
254 | * Override this function to draw the cursor which | 254 | * Override this function to draw the cursor which |
255 | * indicates the current value. This function is | 255 | * indicates the current value. This function is |
256 | * always called twice, once with argument show=false | 256 | * always called twice, once with argument show=false |
257 | * to clear the old cursor, once with argument show=true | 257 | * to clear the old cursor, once with argument show=true |
258 | * to draw the new one. | 258 | * to draw the new one. |
259 | */ | 259 | */ |
260 | virtual void drawArrow( QPainter *painter, bool show, const QPoint &pos ); | 260 | virtual void drawArrow( QPainter *painter, bool show, const QPoint &pos ); |
261 | 261 | ||
262 | /** | 262 | /** |
263 | * @reimplemented | 263 | * @reimplemented |
264 | */ | 264 | */ |
265 | virtual void valueChange(); | 265 | virtual void valueChange(); |
266 | /** | 266 | /** |
267 | * @reimplemented | 267 | * @reimplemented |
268 | */ | 268 | */ |
269 | virtual void paintEvent( QPaintEvent * ); | 269 | virtual void paintEvent( QPaintEvent * ); |
270 | /** | 270 | /** |
271 | * @reimplemented | 271 | * @reimplemented |
272 | */ | 272 | */ |
273 | virtual void mousePressEvent( QMouseEvent *e ); | 273 | virtual void mousePressEvent( QMouseEvent *e ); |
274 | /** | 274 | /** |
275 | * @reimplemented | 275 | * @reimplemented |
276 | */ | 276 | */ |
277 | virtual void mouseMoveEvent( QMouseEvent *e ); | 277 | virtual void mouseMoveEvent( QMouseEvent *e ); |
278 | /** | 278 | /** |
279 | * @reimplemented | 279 | * @reimplemented |
280 | */ | 280 | */ |
281 | virtual void wheelEvent( QWheelEvent * ); | 281 | virtual void wheelEvent( QWheelEvent * ); |
282 | 282 | ||
283 | private: | 283 | private: |
284 | QPoint calcArrowPos( int val ); | 284 | QPoint calcArrowPos( int val ); |
285 | void moveArrow( const QPoint &pos ); | 285 | void moveArrow( const QPoint &pos ); |
286 | 286 | ||
287 | Orientation _orientation; | 287 | Orientation _orientation; |
288 | bool _indent; | 288 | bool _indent; |
289 | 289 | ||
290 | private: | 290 | private: |
291 | class OSelectorPrivate; | 291 | class OSelectorPrivate; |
292 | OSelectorPrivate *d; | 292 | OSelectorPrivate *d; |
293 | }; | 293 | }; |
294 | 294 | ||
295 | 295 | ||
296 | /** | 296 | /** |
297 | * The OGradientSelector widget allows the user to choose | 297 | * The OGradientSelector widget allows the user to choose |
298 | * from a one-dimensional range of colors which is given as a | 298 | * from a one-dimensional range of colors which is given as a |
299 | * gradient between two colors provided by the programmer. | 299 | * gradient between two colors provided by the programmer. |
300 | */ | 300 | */ |
301 | class OGradientSelector : public OSelector | 301 | class OGradientSelector : public OSelector |
302 | { | 302 | { |
303 | Q_OBJECT | 303 | Q_OBJECT |
304 | 304 | ||
305 | Q_PROPERTY( QColor firstColor READ firstColor WRITE setFirstColor ) | 305 | Q_PROPERTY( QColor firstColor READ firstColor WRITE setFirstColor ) |
306 | Q_PROPERTY( QColor secondColor READ secondColor WRITE setSecondColor ) | 306 | Q_PROPERTY( QColor secondColor READ secondColor WRITE setSecondColor ) |
307 | Q_PROPERTY( QString firstText READ firstText WRITE setFirstText ) | 307 | Q_PROPERTY( QString firstText READ firstText WRITE setFirstText ) |
308 | Q_PROPERTY( QString secondText READ secondText WRITE setSecondText ) | 308 | Q_PROPERTY( QString secondText READ secondText WRITE setSecondText ) |
309 | 309 | ||
310 | public: | 310 | public: |
311 | /** | 311 | /** |
312 | * Constructs a horizontal color selector which | 312 | * Constructs a horizontal color selector which |
313 | * contains a gradient between white and black. | 313 | * contains a gradient between white and black. |
314 | */ | 314 | */ |
315 | OGradientSelector( QWidget *parent=0, const char *name=0 ); | 315 | OGradientSelector( QWidget *parent=0, const char *name=0 ); |
316 | /** | 316 | /** |
317 | * Constructs a colors selector with orientation o which | 317 | * Constructs a colors selector with orientation o which |
318 | * contains a gradient between white and black. | 318 | * contains a gradient between white and black. |
319 | */ | 319 | */ |
320 | OGradientSelector( Orientation o, QWidget *parent=0, const char *name=0 ); | 320 | OGradientSelector( Orientation o, QWidget *parent=0, const char *name=0 ); |
321 | /** | 321 | /** |
322 | * Destructs the widget. | 322 | * Destructs the widget. |
323 | */ | 323 | */ |
324 | ~OGradientSelector(); | 324 | ~OGradientSelector(); |
325 | /** | 325 | /** |
326 | * Sets the two colors which span the gradient. | 326 | * Sets the two colors which span the gradient. |
327 | */ | 327 | */ |
328 | void setColors( const QColor &col1, const QColor &col2 ) | 328 | void setColors( const QColor &col1, const QColor &col2 ) |
329 | {color1 = col1; color2 = col2; update();} | 329 | {color1 = col1; color2 = col2; update();} |
330 | void setText( const QString &t1, const QString &t2 ) | 330 | void setText( const QString &t1, const QString &t2 ) |
331 | {text1 = t1; text2 = t2; update(); } | 331 | {text1 = t1; text2 = t2; update(); } |
332 | 332 | ||
333 | /** | 333 | /** |
334 | * Set each color on its own. | 334 | * Set each color on its own. |
335 | */ | 335 | */ |
336 | void setFirstColor( const QColor &col ) | 336 | void setFirstColor( const QColor &col ) |
337 | { color1 = col; update(); } | 337 | { color1 = col; update(); } |
338 | void setSecondColor( const QColor &col ) | 338 | void setSecondColor( const QColor &col ) |
339 | { color2 = col; update(); } | 339 | { color2 = col; update(); } |
340 | 340 | ||
341 | /** | 341 | /** |
342 | * Set each description on its own | 342 | * Set each description on its own |
343 | */ | 343 | */ |
344 | void setFirstText( const QString &t ) | 344 | void setFirstText( const QString &t ) |
345 | { text1 = t; update(); } | 345 | { text1 = t; update(); } |
346 | void setSecondText( const QString &t ) | 346 | void setSecondText( const QString &t ) |
347 | { text2 = t; update(); } | 347 | { text2 = t; update(); } |
348 | 348 | ||
349 | const QColor firstColor() const | 349 | const QColor firstColor() const |
350 | { return color1; } | 350 | { return color1; } |
351 | const QColor secondColor() const | 351 | const QColor secondColor() const |
352 | { return color2; } | 352 | { return color2; } |
353 | 353 | ||
354 | const QString firstText() const | 354 | const QString firstText() const |
355 | { return text1; } | 355 | { return text1; } |
356 | const QString secondText() const | 356 | const QString secondText() const |
357 | { return text2; } | 357 | { return text2; } |
358 | 358 | ||
359 | protected: | 359 | protected: |
360 | /** | 360 | /** |
361 | * @reimplemented | 361 | * @reimplemented |
362 | */ | 362 | */ |
363 | virtual void drawContents( QPainter * ); | 363 | virtual void drawContents( QPainter * ); |
364 | 364 | ||
365 | /** | 365 | /** |
366 | * @reimplemented | 366 | * @reimplemented |
367 | */ | 367 | */ |
368 | virtual QSize minimumSize() const | 368 | virtual QSize minimumSize() const |
369 | { return sizeHint(); } | 369 | { return sizeHint(); } |
370 | 370 | ||
371 | private: | 371 | private: |
372 | void init(); | 372 | void init(); |
373 | QColor color1; | 373 | QColor color1; |
374 | QColor color2; | 374 | QColor color2; |
375 | QString text1; | 375 | QString text1; |
376 | QString text2; | 376 | QString text2; |
377 | 377 | ||
378 | private: | 378 | private: |
379 | class OGradientSelectorPrivate; | 379 | class OGradientSelectorPrivate; |
380 | OGradientSelectorPrivate *d; | 380 | OGradientSelectorPrivate *d; |
381 | }; | 381 | }; |
382 | 382 | ||
383 | /** | 383 | /** |
384 | * Widget for Hue/Saturation selection. | 384 | * Widget for Hue/Saturation selection. |
385 | * The actual values can be fetched using the inherited xValue and yValue | 385 | * The actual values can be fetched using the inherited xValue and yValue |
386 | * methods. | 386 | * methods. |
387 | * | 387 | * |
388 | * @see OXYSelector, OValueSelector, OColorDialog | 388 | * @see OXYSelector, OValueSelector, OColorDialog |
389 | * @author Martin Jones (mjones@kde.org) | 389 | * @author Martin Jones (mjones@kde.org) |
390 | * @version $Id$ | 390 | * @version $Id$ |
391 | */ | 391 | */ |
392 | class OHSSelector : public OXYSelector | 392 | class OHSSelector : public OXYSelector |
393 | { | 393 | { |
394 | Q_OBJECT | 394 | Q_OBJECT |
395 | 395 | ||
396 | public: | 396 | public: |
397 | /** | 397 | /** |
398 | * Constructs a hue/saturation selection widget. | 398 | * Constructs a hue/saturation selection widget. |
399 | */ | 399 | */ |
400 | OHSSelector( QWidget *parent=0, const char *name=0 ); | 400 | OHSSelector( QWidget *parent=0, const char *name=0 ); |
401 | 401 | ||
402 | protected: | 402 | protected: |
403 | /** | 403 | /** |
404 | * Draws the contents of the widget on a pixmap, | 404 | * Draws the contents of the widget on a pixmap, |
405 | * which is used for buffering. | 405 | * which is used for buffering. |
406 | */ | 406 | */ |
407 | virtual void drawPalette( QPixmap *pixmap ); | 407 | virtual void drawPalette( QPixmap *pixmap ); |
408 | /** | 408 | /** |
409 | * @reimplemented | 409 | * @reimplemented |
410 | */ | 410 | */ |
411 | virtual void resizeEvent( QResizeEvent * ); | 411 | virtual void resizeEvent( QResizeEvent * ); |
412 | /** | 412 | /** |
413 | * Reimplemented from OXYSelector. This drawing is | 413 | * Reimplemented from OXYSelector. This drawing is |
414 | * buffered in a pixmap here. As real drawing | 414 | * buffered in a pixmap here. As real drawing |
415 | * routine, drawPalette() is used. | 415 | * routine, drawPalette() is used. |
416 | */ | 416 | */ |
417 | virtual void drawContents( QPainter *painter ); | 417 | virtual void drawContents( QPainter *painter ); |
418 | 418 | ||
419 | private: | 419 | private: |
420 | void updateContents(); | 420 | void updateContents(); |
421 | QPixmap pixmap; | 421 | QPixmap pixmap; |
422 | 422 | ||
423 | private: | 423 | private: |
424 | class OHSSelectorPrivate; | 424 | class OHSSelectorPrivate; |
425 | OHSSelectorPrivate *d; | 425 | OHSSelectorPrivate *d; |
426 | }; | 426 | }; |
427 | 427 | ||
428 | 428 | ||
429 | class OValueSelectorPrivate; | 429 | class OValueSelectorPrivate; |
430 | /** | 430 | /** |
431 | * Widget for color value selection. | 431 | * Widget for color value selection. |
432 | * | 432 | * |
433 | * @see OHSSelector, OColorDialog | 433 | * @see OHSSelector, OColorDialog |
434 | * @author Martin Jones (mjones@kde.org) | 434 | * @author Martin Jones (mjones@kde.org) |
435 | * @version $Id$ | 435 | * @version $Id$ |
436 | */ | 436 | */ |
437 | class OValueSelector : public OSelector | 437 | class OValueSelector : public OSelector |
438 | { | 438 | { |
439 | Q_OBJECT | 439 | Q_OBJECT |
440 | 440 | ||
441 | public: | 441 | public: |
442 | /** | 442 | /** |
443 | * Constructs a widget for color selection. | 443 | * Constructs a widget for color selection. |
444 | */ | 444 | */ |
445 | OValueSelector( QWidget *parent=0, const char *name=0 ); | 445 | OValueSelector( QWidget *parent=0, const char *name=0 ); |
446 | /** | 446 | /** |
447 | * Constructs a widget for color selection with a given orientation | 447 | * Constructs a widget for color selection with a given orientation |
448 | */ | 448 | */ |
449 | OValueSelector( Orientation o, QWidget *parent = 0, const char *name = 0 ); | 449 | OValueSelector( Orientation o, QWidget *parent = 0, const char *name = 0 ); |
450 | 450 | ||
451 | int hue() const | 451 | int hue() const |
452 | { return _hue; } | 452 | { return _hue; } |
453 | void setHue( int h ) | 453 | void setHue( int h ) |
454 | { _hue = h; } | 454 | { _hue = h; } |
455 | int saturation() const | 455 | int saturation() const |
456 | { return _sat; } | 456 | { return _sat; } |
457 | void setSaturation( int s ) | 457 | void setSaturation( int s ) |
458 | { _sat = s; } | 458 | { _sat = s; } |
459 | 459 | ||
460 | void updateContents(); | 460 | void updateContents(); |
461 | protected: | 461 | protected: |
462 | /** | 462 | /** |
463 | * Draws the contents of the widget on a pixmap, | 463 | * Draws the contents of the widget on a pixmap, |
464 | * which is used for buffering. | 464 | * which is used for buffering. |
465 | */ | 465 | */ |
466 | virtual void drawPalette( QPixmap *pixmap ); | 466 | virtual void drawPalette( QPixmap *pixmap ); |
467 | /** | 467 | /** |
468 | * @reimplemented | 468 | * @reimplemented |
469 | */ | 469 | */ |
470 | virtual void resizeEvent( QResizeEvent * ); | 470 | virtual void resizeEvent( QResizeEvent * ); |
471 | /** | 471 | /** |
472 | * Reimplemented from OSelector. The drawing is | 472 | * Reimplemented from OSelector. The drawing is |
473 | * buffered in a pixmap here. As real drawing | 473 | * buffered in a pixmap here. As real drawing |
474 | * routine, drawPalette() is used. | 474 | * routine, drawPalette() is used. |
475 | */ | 475 | */ |
476 | virtual void drawContents( QPainter *painter ); | 476 | virtual void drawContents( QPainter *painter ); |
477 | 477 | ||
478 | private: | 478 | private: |
479 | int _hue; | 479 | int _hue; |
480 | int _sat; | 480 | int _sat; |
481 | QPixmap pixmap; | 481 | QPixmap pixmap; |
482 | 482 | ||
483 | private: | 483 | private: |
484 | class OValueSelectorPrivate; | 484 | class OValueSelectorPrivate; |
485 | OValueSelectorPrivate *d; | 485 | OValueSelectorPrivate *d; |
486 | }; | 486 | }; |
487 | 487 | ||
488 | 488 | ||
489 | class OColor : public QColor | 489 | class OColor : public QColor |
490 | { | 490 | { |
491 | public: | 491 | public: |
492 | OColor(); | 492 | OColor(); |
493 | OColor( const OColor &col); | 493 | OColor( const OColor &col); |
494 | OColor( const QColor &col); | 494 | OColor( const QColor &col); |
495 | 495 | ||
496 | OColor& operator=( const OColor& col); | 496 | OColor& operator=( const OColor& col); |
497 | 497 | ||
498 | bool operator==( const OColor& col) const; | 498 | bool operator==( const OColor& col) const; |
499 | 499 | ||
500 | void setHsv(int _h, int _s, int _v); | 500 | void setHsv(int _h, int _s, int _v); |
501 | void setRgb(int _r, int _g, int _b); | 501 | void setRgb(int _r, int _g, int _b); |
502 | 502 | ||
503 | void rgb(int *_r, int *_g, int *_b) const; | 503 | void rgb(int *_r, int *_g, int *_b) const; |
504 | void hsv(int *_h, int *_s, int *_v) const; | 504 | void hsv(int *_h, int *_s, int *_v) const; |
505 | protected: | 505 | protected: |
506 | int h; | 506 | int h; |
507 | int s; | 507 | int s; |
508 | int v; | 508 | int v; |
509 | int r; | 509 | int r; |
510 | int g; | 510 | int g; |
511 | int b; | 511 | int b; |
512 | 512 | ||
513 | private: | 513 | private: |
514 | class OColorPrivate; | 514 | class OColorPrivate; |
515 | OColorPrivate *d; | 515 | OColorPrivate *d; |
516 | }; | 516 | }; |
517 | 517 | ||
518 | } | 518 | } |
519 | } | 519 | } |
520 | 520 | ||
521 | 521 | ||
522 | #endif // __OSELECT_H__ | 522 | #endif // __OSELECT_H__ |
523 | 523 | ||