summaryrefslogtreecommitdiff
path: root/libopie2/opieui
authorzecke <zecke>2004-03-13 19:51:45 (UTC)
committer zecke <zecke>2004-03-13 19:51:45 (UTC)
commit6d08277737e22b7a1527124623f3571969073ddf (patch) (unidiff)
tree4129e674e21df767b31299e873dd44e33a308e1b /libopie2/opieui
parent8e28911f7199f4450ac5eef09482069f9b9caea2 (diff)
downloadopie-6d08277737e22b7a1527124623f3571969073ddf.zip
opie-6d08277737e22b7a1527124623f3571969073ddf.tar.gz
opie-6d08277737e22b7a1527124623f3571969073ddf.tar.bz2
Move XML class to internal PIM
Add namespaces!!! Opie::Core and Opie::Core::Private Opie::Net and Opie::Net::Private Opie::Ui and Opie::Ui::Private Opie::MM and Opie::MM::Private Opie::DB and Opie::DB::Private PIM classes are not yet converted because we will do other work on it as well
Diffstat (limited to 'libopie2/opieui') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/big-screen/obigscreen_p.h9
-rw-r--r--libopie2/opieui/big-screen/osplitter.cpp13
-rw-r--r--libopie2/opieui/big-screen/osplitter.h15
-rw-r--r--libopie2/opieui/big-screen/owidgetstack.cpp9
-rw-r--r--libopie2/opieui/big-screen/owidgetstack.h7
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.cpp2
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.h7
-rw-r--r--libopie2/opieui/fileselector/ofileselector.cpp9
-rw-r--r--libopie2/opieui/fileselector/ofileselector.h19
-rw-r--r--libopie2/opieui/fileselector/ofileselector_p.h10
-rw-r--r--libopie2/opieui/fileselector/ofileview.h9
-rw-r--r--libopie2/opieui/oclickablelabel.cpp2
-rw-r--r--libopie2/opieui/oclickablelabel.h7
-rw-r--r--libopie2/opieui/odialog.cpp2
-rw-r--r--libopie2/opieui/odialog.h5
-rw-r--r--libopie2/opieui/ofontselector.cpp19
-rw-r--r--libopie2/opieui/ofontselector.h12
-rw-r--r--libopie2/opieui/oimageeffect.cpp7
-rw-r--r--libopie2/opieui/oimageeffect.h5
-rw-r--r--libopie2/opieui/olistview.cpp7
-rw-r--r--libopie2/opieui/olistview.h25
-rw-r--r--libopie2/opieui/opieui.pro3
-rw-r--r--libopie2/opieui/opixmapeffect.cpp2
-rw-r--r--libopie2/opieui/opixmapeffect.h6
-rw-r--r--libopie2/opieui/opixmapprovider.cpp2
-rw-r--r--libopie2/opieui/opixmapprovider.h8
-rw-r--r--libopie2/opieui/opopupmenu.cpp3
-rw-r--r--libopie2/opieui/opopupmenu.h5
-rw-r--r--libopie2/opieui/oselector.cpp18
-rw-r--r--libopie2/opieui/oselector.h5
-rw-r--r--libopie2/opieui/oseparator.cpp2
-rw-r--r--libopie2/opieui/oseparator.h5
-rw-r--r--libopie2/opieui/otabbar.cpp2
-rw-r--r--libopie2/opieui/otabbar.h7
-rw-r--r--libopie2/opieui/otabinfo.h7
-rw-r--r--libopie2/opieui/otabwidget.cpp2
-rw-r--r--libopie2/opieui/otabwidget.h8
-rw-r--r--libopie2/opieui/otaskbarapplet.cpp52
-rw-r--r--libopie2/opieui/otaskbarapplet.h49
-rw-r--r--libopie2/opieui/otimepicker.cpp15
-rw-r--r--libopie2/opieui/otimepicker.h19
-rw-r--r--libopie2/opieui/otimepickerbase.ui38
-rw-r--r--libopie2/opieui/oversatileview.cpp43
-rw-r--r--libopie2/opieui/oversatileview.h83
-rw-r--r--libopie2/opieui/oversatileviewitem.cpp2
-rw-r--r--libopie2/opieui/oversatileviewitem.h5
-rw-r--r--libopie2/opieui/owait.cpp2
-rw-r--r--libopie2/opieui/owait.h6
48 files changed, 378 insertions, 221 deletions
diff --git a/libopie2/opieui/big-screen/obigscreen_p.h b/libopie2/opieui/big-screen/obigscreen_p.h
index db8fc83..a85a56c 100644
--- a/libopie2/opieui/big-screen/obigscreen_p.h
+++ b/libopie2/opieui/big-screen/obigscreen_p.h
@@ -1,28 +1,31 @@
1#ifndef OPIE_BIG_SCREEN_PRIVATE 1#ifndef OPIE_BIG_SCREEN_PRIVATE
2#define OPIE_BIG_SCREEN_PRIVATE 2#define OPIE_BIG_SCREEN_PRIVATE
3 3
4/* QT */ 4/* QT */
5#include <qstring.h> 5#include <qstring.h>
6 6
7class QWidget; 7class QWidget;
8 8
9namespace Opie 9namespace Opie {
10{ 10namespace Ui {
11namespace Private{
11 12
12struct OSplitterContainer 13struct OSplitterContainer
13{ 14{
14 bool operator==( const OSplitterContainer& o) const 15 bool operator==( const OSplitterContainer& o) const
15 { 16 {
16 if (widget != o.widget ) return false; 17 if (widget != o.widget ) return false;
17 if (icon != o.icon ) return false; 18 if (icon != o.icon ) return false;
18 if (name != o.name ) return false; 19 if (name != o.name ) return false;
19 return true; 20 return true;
20 } 21 }
21 QWidget* widget; 22 QWidget* widget;
22 QString icon; 23 QString icon;
23 QString name; 24 QString name;
24}; 25};
25 26
26}; 27}
28}
29}
27 30
28#endif 31#endif
diff --git a/libopie2/opieui/big-screen/osplitter.cpp b/libopie2/opieui/big-screen/osplitter.cpp
index 89f3793..bcfd3a6 100644
--- a/libopie2/opieui/big-screen/osplitter.cpp
+++ b/libopie2/opieui/big-screen/osplitter.cpp
@@ -1,638 +1,639 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org> 3             .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include "osplitter.h" 29#include "osplitter.h"
30 30
31/* OPIE */ 31/* OPIE */
32#include <opie2/otabwidget.h> 32#include <opie2/otabwidget.h>
33 33
34/* QT */ 34/* QT */
35#include <qvaluelist.h> 35#include <qvaluelist.h>
36#include <qvbox.h> 36#include <qvbox.h>
37 37
38using namespace Opie; 38using namespace Opie::Ui;
39using namespace Opie::Ui::Private;
39 40
40/** 41/**
41 * 42 *
42 * This is the constructor of OSplitter 43 * This is the constructor of OSplitter
43 * You might want to call setSizeChange to tell 44 * You might want to call setSizeChange to tell
44 * OSplitter to change its layout when a specefic 45 * OSplitter to change its layout when a specefic
45 * mark was crossed. OSplitter sets a default value. 46 * mark was crossed. OSplitter sets a default value.
46 * 47 *
47 * You cann add widget with addWidget to the OSplitter. 48 * You cann add widget with addWidget to the OSplitter.
48 * OSplitter supports also grouping of Splitters where they 49 * OSplitter supports also grouping of Splitters where they
49 * can share one OTabBar in small screen mode. This can be used 50 * can share one OTabBar in small screen mode. This can be used
50 * for email clients like vies but see the example. 51 * for email clients like vies but see the example.
51 * 52 *
52 * @param orient The orientation wether to layout horizontal or vertical 53 * @param orient The orientation wether to layout horizontal or vertical
53 * @param parent The parent of this widget 54 * @param parent The parent of this widget
54 * @param name The name passed on to QObject 55 * @param name The name passed on to QObject
55 * @param fl Additional widgets flags passed to QWidget 56 * @param fl Additional widgets flags passed to QWidget
56 * 57 *
57 * @short single c'tor of the OSplitter 58 * @short single c'tor of the OSplitter
58 */ 59 */
59OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl ) 60OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl )
60 : QFrame( parent, name, fl ) 61 : QFrame( parent, name, fl )
61{ 62{
62 m_orient = orient; 63 m_orient = orient;
63 m_hbox = 0; 64 m_hbox = 0;
64 m_size_policy = 330; 65 m_size_policy = 330;
65 setFontPropagation( AllChildren ); 66 setFontPropagation( AllChildren );
66 setPalettePropagation( AllChildren ); 67 setPalettePropagation( AllChildren );
67 68
68 /* start by default with the tab widget */ 69 /* start by default with the tab widget */
69 m_tabWidget = 0; 70 m_tabWidget = 0;
70 m_parentTab = 0; 71 m_parentTab = 0;
71 changeTab(); 72 changeTab();
72 73
73} 74}
74 75
75 76
76/** 77/**
77 * Destructor destructs this object and cleans up. All child 78 * Destructor destructs this object and cleans up. All child
78 * widgets will be deleted 79 * widgets will be deleted
79 * @see addWidget 80 * @see addWidget
80 */ 81 */
81OSplitter::~OSplitter() 82OSplitter::~OSplitter()
82{ 83{
83 qWarning("Deleted Splitter"); 84 qWarning("Deleted Splitter");
84 m_splitter.setAutoDelete( true ); 85 m_splitter.setAutoDelete( true );
85 m_splitter.clear(); 86 m_splitter.clear();
86 87
87 delete m_hbox; 88 delete m_hbox;
88 delete m_tabWidget; 89 delete m_tabWidget;
89} 90}
90 91
91 92
92/** 93/**
93 * Sets the label for the Splitter. This label will be used 94 * Sets the label for the Splitter. This label will be used
94 * if a parent splitter is arranged as TabWidget but 95 * if a parent splitter is arranged as TabWidget but
95 * this splitter is in fullscreen mode. Then a tab with OSplitter::label() 96 * this splitter is in fullscreen mode. Then a tab with OSplitter::label()
96 * and iconName() gets added. 97 * and iconName() gets added.
97 * 98 *
98 * @param name The name of the Label 99 * @param name The name of the Label
99 */ 100 */
100void OSplitter::setLabel( const QString& name ) 101void OSplitter::setLabel( const QString& name )
101{ 102{
102 m_name = name; 103 m_name = name;
103} 104}
104 105
105/** 106/**
106 * @see setLabel but this is for the icon retrieved by Resource 107 * @see setLabel but this is for the icon retrieved by Resource
107 * 108 *
108 * @param name The name of the icon in example ( "zoom" ) 109 * @param name The name of the icon in example ( "zoom" )
109 */ 110 */
110void OSplitter::setIconName( const QString& name ) 111void OSplitter::setIconName( const QString& name )
111{ 112{
112 m_icon = name; 113 m_icon = name;
113} 114}
114 115
115 116
116/** 117/**
117 * returns the iconName 118 * returns the iconName
118 * @see setIconName 119 * @see setIconName
119 */ 120 */
120QString OSplitter::iconName()const 121QString OSplitter::iconName()const
121{ 122{
122 return m_icon; 123 return m_icon;
123} 124}
124 125
125/** 126/**
126 * returns the label set with setLabel 127 * returns the label set with setLabel
127 * @see setLabel 128 * @see setLabel
128 */ 129 */
129QString OSplitter::label()const 130QString OSplitter::label()const
130{ 131{
131 return m_name; 132 return m_name;
132} 133}
133 134
134/** 135/**
135 * This function sets the size change policy of the splitter. 136 * This function sets the size change policy of the splitter.
136 * If this size marked is crossed the splitter will relayout. 137 * If this size marked is crossed the splitter will relayout.
137 * Note: that depending on the set Orientation it'll either look 138 * Note: that depending on the set Orientation it'll either look
138 * at the width or height. 139 * at the width or height.
139 * Note: If you want to from side to side view to tabbed view you need 140 * Note: If you want to from side to side view to tabbed view you need
140 * to make sure that the size you supply is not smaller than the minimum 141 * to make sure that the size you supply is not smaller than the minimum
141 * size of your added widgets. Note that if you use widgets like QComboBoxes 142 * size of your added widgets. Note that if you use widgets like QComboBoxes
142 * you need to teach them to accept smaller sizes as well @see QWidget::setSizePolicy 143 * you need to teach them to accept smaller sizes as well @see QWidget::setSizePolicy
143 * 144 *
144 * @param width_height The mark that will be watched. Interpreted depending on the Orientation of the Splitter. 145 * @param width_height The mark that will be watched. Interpreted depending on the Orientation of the Splitter.
145 * @return void 146 * @return void
146 */ 147 */
147void OSplitter::setSizeChange( int width_height ) 148void OSplitter::setSizeChange( int width_height )
148{ 149{
149 m_size_policy = width_height; 150 m_size_policy = width_height;
150 QSize sz(width(), height() ); 151 QSize sz(width(), height() );
151 QResizeEvent ev(sz, sz ); 152 QResizeEvent ev(sz, sz );
152 resizeEvent(&ev); 153 resizeEvent(&ev);
153} 154}
154 155
155/** 156/**
156 * This functions allows to add another OSplitter and to share 157 * This functions allows to add another OSplitter and to share
157 * the OTabBar in small screen mode. The ownerships gets transfered. 158 * the OTabBar in small screen mode. The ownerships gets transfered.
158 * OSplitters are always added after normal widget items 159 * OSplitters are always added after normal widget items
159 */ 160 */
160void OSplitter::addWidget( OSplitter* split ) 161void OSplitter::addWidget( OSplitter* split )
161{ 162{
162 m_splitter.append( split ); 163 m_splitter.append( split );
163 164
164 /* 165 /*
165 * set tab widget 166 * set tab widget
166 */ 167 */
167 if (m_tabWidget ) 168 if (m_tabWidget )
168 setTabWidget( m_parentTab ); 169 setTabWidget( m_parentTab );
169 else 170 else
170 { 171 {
171 Opie::OSplitterContainer con; 172 OSplitterContainer con;
172 con.widget =split; 173 con.widget =split;
173 addToBox( con ); 174 addToBox( con );
174 } 175 }
175} 176}
176 177
177/* 178/*
178 * If in a tab it should be removed 179 * If in a tab it should be removed
179 * and if in a hbox the reparent kills it too 180 * and if in a hbox the reparent kills it too
180 */ 181 */
181/** 182/**
182 * This removes the splitter again. You currently need to call this 183 * This removes the splitter again. You currently need to call this
183 * before you delete or otherwise you can get mem corruption 184 * before you delete or otherwise you can get mem corruption
184 * or other weird behaviour. 185 * or other weird behaviour.
185 * Owner ship gets transfered back to you it's current parent 186 * Owner ship gets transfered back to you it's current parent
186 * is 0 187 * is 0
187 */ 188 */
188void OSplitter::removeWidget( OSplitter* split) 189void OSplitter::removeWidget( OSplitter* split)
189{ 190{
190 split->setTabWidget( 0 ); 191 split->setTabWidget( 0 );
191 split->reparent( 0, 0, QPoint(0, 0) ); 192 split->reparent( 0, 0, QPoint(0, 0) );
192} 193}
193 194
194/** 195/**
195 * Adds a widget to the Splitter. The widgets gets inserted 196 * Adds a widget to the Splitter. The widgets gets inserted
196 * at the end of either the Box or TabWidget. 197 * at the end of either the Box or TabWidget.
197 * Ownership gets transfered and the widgets gets reparented. 198 * Ownership gets transfered and the widgets gets reparented.
198 * Note: icon and label is only available on small screensizes 199 * Note: icon and label is only available on small screensizes
199 * if size is smaller than the mark 200 * if size is smaller than the mark
200 * Warning: No null checking of the widget is done. Only on debug 201 * Warning: No null checking of the widget is done. Only on debug
201 * a message will be outputtet 202 * a message will be outputtet
202 * 203 *
203 * @param wid The widget which will be added 204 * @param wid The widget which will be added
204 * @param icon The icon of the possible Tab 205 * @param icon The icon of the possible Tab
205 * @param label The label of the possible Tab 206 * @param label The label of the possible Tab
206 */ 207 */
207void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& label ) 208void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& label )
208{ 209{
209#ifdef DEBUG 210#ifdef DEBUG
210 if (!wid ) 211 if (!wid )
211 { 212 {
212 qWarning("Widget is not valid!"); 213 qWarning("Widget is not valid!");
213 return; 214 return;
214 } 215 }
215#endif 216#endif
216 Opie::OSplitterContainer cont; 217 OSplitterContainer cont;
217 cont.widget = wid; 218 cont.widget = wid;
218 cont.icon =icon; 219 cont.icon =icon;
219 cont.name = label; 220 cont.name = label;
220 221
221 m_container.append( cont ); 222 m_container.append( cont );
222 223
223 /* 224 /*
224 * 225 *
225 */ 226 */
226 if (!m_splitter.isEmpty() && (m_tabWidget || m_parentTab ) ) 227 if (!m_splitter.isEmpty() && (m_tabWidget || m_parentTab ) )
227 setTabWidget( m_parentTab ); 228 setTabWidget( m_parentTab );
228 else 229 else
229 { 230 {
230 if (m_hbox ) 231 if (m_hbox )
231 addToBox( cont ); 232 addToBox( cont );
232 else 233 else
233 addToTab( cont ); 234 addToTab( cont );
234 } 235 }
235} 236}
236 237
237 238
238/** 239/**
239 * Removes the widget from the tab widgets if necessary. 240 * Removes the widget from the tab widgets if necessary.
240 * OSplitter drops ownership of this widget and the widget 241 * OSplitter drops ownership of this widget and the widget
241 * will be reparented i tto 0. 242 * will be reparented i tto 0.
242 * The widget will not be deleted. 243 * The widget will not be deleted.
243 * 244 *
244 * @param w The widget to be removed 245 * @param w The widget to be removed
245 */ 246 */
246void OSplitter::removeWidget( QWidget* w) 247void OSplitter::removeWidget( QWidget* w)
247{ 248{
248 ContainerList::Iterator it; 249 ContainerList::Iterator it;
249 for ( it = m_container.begin(); it != m_container.end(); ++it ) 250 for ( it = m_container.begin(); it != m_container.end(); ++it )
250 if ( (*it).widget == w ) 251 if ( (*it).widget == w )
251 break; 252 break;
252 253
253 if (it == m_container.end() ) 254 if (it == m_container.end() )
254 return; 255 return;
255 256
256 257
257 /* only tab needs to be removed.. box recognizes it */ 258 /* only tab needs to be removed.. box recognizes it */
258 if ( !m_hbox ) 259 if ( !m_hbox )
259 removeFromTab( w ); 260 removeFromTab( w );
260 261
261 262
262 /* Find reparent it and remove it from our list */ 263 /* Find reparent it and remove it from our list */
263 264
264 w->reparent( 0, 0, QPoint(0, 0)); 265 w->reparent( 0, 0, QPoint(0, 0));
265 it = m_container.remove( it ); 266 it = m_container.remove( it );
266 267
267} 268}
268 269
269 270
270/** 271/**
271 * This method will give focus to the widget. If in a tabwidget 272 * This method will give focus to the widget. If in a tabwidget
272 * the tabbar will be changed 273 * the tabbar will be changed
273 * 274 *
274 * @param w The widget which will be set the current one 275 * @param w The widget which will be set the current one
275 */ 276 */
276void OSplitter::setCurrentWidget( QWidget* w) 277void OSplitter::setCurrentWidget( QWidget* w)
277{ 278{
278 if (m_tabWidget ) 279 if (m_tabWidget )
279 m_tabWidget->setCurrentTab( w ); 280 m_tabWidget->setCurrentTab( w );
280 // else 281 // else
281 // m_hbox->setFocus( w ); 282 // m_hbox->setFocus( w );
282 283
283} 284}
284 285
285/** 286/**
286 * This is an overloaded member function and only differs in the 287 * This is an overloaded member function and only differs in the
287 * argument it takes. 288 * argument it takes.
288 * Searches list of widgets for label. It'll pick the first label it finds 289 * Searches list of widgets for label. It'll pick the first label it finds
289 * 290 *
290 * @param label Label to look for. First match will be taken 291 * @param label Label to look for. First match will be taken
291 */ 292 */
292void OSplitter::setCurrentWidget( const QString& label ) 293void OSplitter::setCurrentWidget( const QString& label )
293{ 294{
294 ContainerList::Iterator it; 295 ContainerList::Iterator it;
295 for (it = m_container.begin(); it != m_container.end(); ++it ) 296 for (it = m_container.begin(); it != m_container.end(); ++it )
296 { 297 {
297 if ( (*it).name == label ) 298 if ( (*it).name == label )
298 { 299 {
299 setCurrentWidget( (*it).widget ); 300 setCurrentWidget( (*it).widget );
300 break; 301 break;
301 } 302 }
302 } 303 }
303} 304}
304 305
305/** 306/**
306 * This will only work when the TabWidget is active 307 * This will only work when the TabWidget is active
307 * If everything is visible this signal is kindly ignored 308 * If everything is visible this signal is kindly ignored
308 * @see OTabWidget::setCurrentTab(int) 309 * @see OTabWidget::setCurrentTab(int)
309 * 310 *
310 * @param tab The tab to make current 311 * @param tab The tab to make current
311 */ 312 */
312void OSplitter::setCurrentWidget( int tab ) 313void OSplitter::setCurrentWidget( int tab )
313{ 314{
314 if (m_tabWidget ) 315 if (m_tabWidget )
315 m_tabWidget->setCurrentTab( tab ); 316 m_tabWidget->setCurrentTab( tab );
316} 317}
317 318
318/** 319/**
319 * return the currently activated widget if in tab widget mode 320 * return the currently activated widget if in tab widget mode
320 * or null because all widgets are visible 321 * or null because all widgets are visible
321 */ 322 */
322QWidget* OSplitter::currentWidget() const 323QWidget* OSplitter::currentWidget() const
323{ 324{
324 if (m_tabWidget) 325 if (m_tabWidget)
325 return m_tabWidget->currentWidget(); 326 return m_tabWidget->currentWidget();
326 else if (m_parentTab ) 327 else if (m_parentTab )
327 return m_parentTab->currentWidget(); 328 return m_parentTab->currentWidget();
328 329
329 return 0l; 330 return 0l;
330} 331}
331/* wrong */ 332/* wrong */
332#if 0 333#if 0
333/** 334/**
334 * @reimplented for internal reasons 335 * @reimplented for internal reasons
335 * returns the sizeHint of one of its sub widgets 336 * returns the sizeHint of one of its sub widgets
336 */ 337 */
337QSize OSplitter::sizeHint()const 338QSize OSplitter::sizeHint()const
338{ 339{
339 if (m_parentTab ) 340 if (m_parentTab )
340 return QFrame::sizeHint(); 341 return QFrame::sizeHint();
341 342
342 if (m_hbox ) 343 if (m_hbox )
343 return m_hbox->sizeHint(); 344 return m_hbox->sizeHint();
344 else 345 else
345 return m_tabWidget->sizeHint(); 346 return m_tabWidget->sizeHint();
346} 347}
347 348
348QSize OSplitter::minimumSizeHint()const 349QSize OSplitter::minimumSizeHint()const
349{ 350{
350 if (m_parentTab ) 351 if (m_parentTab )
351 return QFrame::minimumSizeHint(); 352 return QFrame::minimumSizeHint();
352 if (m_hbox) 353 if (m_hbox)
353 return m_hbox->sizeHint(); 354 return m_hbox->sizeHint();
354 else 355 else
355 return m_tabWidget->sizeHint(); 356 return m_tabWidget->sizeHint();
356} 357}
357#endif 358#endif
358 359
359/** 360/**
360 * @reimplemented for internal reasons 361 * @reimplemented for internal reasons
361 */ 362 */
362void OSplitter::resizeEvent( QResizeEvent* res ) 363void OSplitter::resizeEvent( QResizeEvent* res )
363{ 364{
364 QFrame::resizeEvent( res ); 365 QFrame::resizeEvent( res );
365 /* 366 /*
366 * 367 *
367 */ 368 */
368 // qWarning("Old size was width = %d height = %d", res->oldSize().width(), res->oldSize().height() ); 369 // qWarning("Old size was width = %d height = %d", res->oldSize().width(), res->oldSize().height() );
369 bool mode = true; 370 bool mode = true;
370 qWarning("New size is width = %d height = %d %s", res->size().width(), res->size().height(), name() ); 371 qWarning("New size is width = %d height = %d %s", res->size().width(), res->size().height(), name() );
371 if ( res->size().width() > m_size_policy && 372 if ( res->size().width() > m_size_policy &&
372 m_orient == Horizontal ) 373 m_orient == Horizontal )
373 { 374 {
374 changeHBox(); 375 changeHBox();
375 mode = false; 376 mode = false;
376 } 377 }
377 else if ( (res->size().width() <= m_size_policy && 378 else if ( (res->size().width() <= m_size_policy &&
378 m_orient == Horizontal ) || 379 m_orient == Horizontal ) ||
379 (res->size().height() <= m_size_policy && 380 (res->size().height() <= m_size_policy &&
380 m_orient == Vertical ) ) 381 m_orient == Vertical ) )
381 { 382 {
382 changeTab(); 383 changeTab();
383 } 384 }
384 else if ( res->size().height() > m_size_policy && 385 else if ( res->size().height() > m_size_policy &&
385 m_orient == Vertical ) 386 m_orient == Vertical )
386 { 387 {
387 qWarning("Changng to vbox %s", name() ); 388 qWarning("Changng to vbox %s", name() );
388 changeVBox(); 389 changeVBox();
389 mode = false; 390 mode = false;
390 } 391 }
391 392
392 emit sizeChanged(mode, m_orient ); 393 emit sizeChanged(mode, m_orient );
393} 394}
394 395
395/* 396/*
396 * Adds a container to a tab either the parent tab 397 * Adds a container to a tab either the parent tab
397 * or our own 398 * or our own
398 */ 399 */
399void OSplitter::addToTab( const Opie::OSplitterContainer& con ) 400void OSplitter::addToTab( const Opie::Ui::Private::OSplitterContainer& con )
400{ 401{
401 QWidget *wid = con.widget; 402 QWidget *wid = con.widget;
402 // not needed widgetstack will reparent as well wid.reparent(m_tabWidget, wid->getWFlags(), QPoint(0, 0) ); 403 // not needed widgetstack will reparent as well wid.reparent(m_tabWidget, wid->getWFlags(), QPoint(0, 0) );
403 if (m_parentTab ) 404 if (m_parentTab )
404 m_parentTab->addTab( wid, con.icon, con.name ); 405 m_parentTab->addTab( wid, con.icon, con.name );
405 else 406 else
406 m_tabWidget->addTab( wid, con.icon, con.name ); 407 m_tabWidget->addTab( wid, con.icon, con.name );
407} 408}
408 409
409 410
410/* 411/*
411 * adds a container to the box 412 * adds a container to the box
412 */ 413 */
413void OSplitter::addToBox( const Opie::OSplitterContainer& con ) 414void OSplitter::addToBox( const Opie::Ui::Private::OSplitterContainer& con )
414{ 415{
415 QWidget* wid = con.widget; 416 QWidget* wid = con.widget;
416 wid->reparent(m_hbox, 0, QPoint(0, 0) ); 417 wid->reparent(m_hbox, 0, QPoint(0, 0) );
417} 418}
418 419
419 420
420/* 421/*
421 * Removes a widget from the tab 422 * Removes a widget from the tab
422 */ 423 */
423void OSplitter::removeFromTab( QWidget* wid ) 424void OSplitter::removeFromTab( QWidget* wid )
424{ 425{
425 if (m_parentTab ) 426 if (m_parentTab )
426 m_parentTab->removePage( wid ); 427 m_parentTab->removePage( wid );
427 else 428 else
428 m_tabWidget->removePage( wid ); 429 m_tabWidget->removePage( wid );
429} 430}
430 431
431/* 432/*
432 * switches over to a OTabWidget layout 433 * switches over to a OTabWidget layout
433 * it is recursive 434 * it is recursive
434 */ 435 */
435void OSplitter::changeTab() 436void OSplitter::changeTab()
436{ 437{
437 /* if we're the owner of the tab widget */ 438 /* if we're the owner of the tab widget */
438 if (m_tabWidget ) 439 if (m_tabWidget )
439 { 440 {
440 raise(); 441 raise();
441 show(); 442 show();
442 m_tabWidget->setGeometry( frameRect() ); 443 m_tabWidget->setGeometry( frameRect() );
443 return; 444 return;
444 } 445 }
445 446
446 qWarning(" New Tab Widget %s", name() ); 447 qWarning(" New Tab Widget %s", name() );
447 /* 448 /*
448 * and add all widgets this will reparent them 449 * and add all widgets this will reparent them
449 * delete m_hbox set it to 0 450 * delete m_hbox set it to 0
450 * 451 *
451 */ 452 */
452 OTabWidget *tab; 453 OTabWidget *tab;
453 if ( m_parentTab ) 454 if ( m_parentTab )
454 { 455 {
455 hide(); 456 hide();
456 tab = m_parentTab; 457 tab = m_parentTab;
457 /* expensive but needed cause we're called from setTabWidget and resizeEvent*/ 458 /* expensive but needed cause we're called from setTabWidget and resizeEvent*/
458 if (!m_container.isEmpty() ) 459 if (!m_container.isEmpty() )
459 { 460 {
460 ContainerList::Iterator it = m_container.begin(); 461 ContainerList::Iterator it = m_container.begin();
461 for (; it != m_container.end(); ++it ) 462 for (; it != m_container.end(); ++it )
462 m_parentTab->removePage( (*it).widget ); 463 m_parentTab->removePage( (*it).widget );
463 } 464 }
464 } 465 }
465 else 466 else
466 tab = m_tabWidget = new OTabWidget( this ); 467 tab = m_tabWidget = new OTabWidget( this );
467 468
468 connect(tab, SIGNAL(currentChanged(QWidget*) ), 469 connect(tab, SIGNAL(currentChanged(QWidget*) ),
469 this, SIGNAL(currentChanged(QWidget*) ) ); 470 this, SIGNAL(currentChanged(QWidget*) ) );
470 471
471 for ( ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it ) 472 for ( ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it )
472 { 473 {
473 qWarning("Widget is %s", (*it).name.latin1() ); 474 qWarning("Widget is %s", (*it).name.latin1() );
474 addToTab( (*it) ); 475 addToTab( (*it) );
475 } 476 }
476 477
477 for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() ) 478 for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() )
478 { 479 {
479 split->reparent(this, 0, QPoint(0, 0) ); 480 split->reparent(this, 0, QPoint(0, 0) );
480 split->setTabWidget( tab ); 481 split->setTabWidget( tab );
481 } 482 }
482 483
483 484
484 delete m_hbox; 485 delete m_hbox;
485 m_hbox = 0; 486 m_hbox = 0;
486 if (!m_tabWidget ) 487 if (!m_tabWidget )
487 return; 488 return;
488 489
489 m_tabWidget->setGeometry( frameRect() ); 490 m_tabWidget->setGeometry( frameRect() );
490 m_tabWidget->show(); 491 m_tabWidget->show();
491 492
492} 493}
493 494
494/* 495/*
495 * changes over to a box 496 * changes over to a box
496 * this is recursive as well 497 * this is recursive as well
497 */ 498 */
498void OSplitter::changeHBox() 499void OSplitter::changeHBox()
499{ 500{
500 if (m_hbox ) 501 if (m_hbox )
501 { 502 {
502 m_hbox->setGeometry( frameRect() ); 503 m_hbox->setGeometry( frameRect() );
503 return; 504 return;
504 } 505 }
505 506
506 qWarning("new HBox %s", name() ); 507 qWarning("new HBox %s", name() );
507 m_hbox = new QHBox( this ); 508 m_hbox = new QHBox( this );
508 commonChangeBox(); 509 commonChangeBox();
509} 510}
510 511
511void OSplitter::changeVBox() 512void OSplitter::changeVBox()
512{ 513{
513 if (m_hbox ) 514 if (m_hbox )
514 { 515 {
515 m_hbox->setGeometry( frameRect() ); 516 m_hbox->setGeometry( frameRect() );
516 return; 517 return;
517 } 518 }
518 519
519 qWarning("New VBOX %s", name() ); 520 qWarning("New VBOX %s", name() );
520 m_hbox = new QVBox( this ); 521 m_hbox = new QVBox( this );
521 522
522 commonChangeBox(); 523 commonChangeBox();
523 524
524} 525}
525 526
526/* 527/*
527 * common box code 528 * common box code
528 * first remove and add children 529 * first remove and add children
529 * the other splitters 530 * the other splitters
530 * it is recursive as well due the call to setTabWidget 531 * it is recursive as well due the call to setTabWidget
531 */ 532 */
532void OSplitter::commonChangeBox() 533void OSplitter::commonChangeBox()
533{ 534{
534 qWarning(" Name of Splitters is %s", name() ); 535 qWarning(" Name of Splitters is %s", name() );
535 536
536 for (ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it ) 537 for (ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it )
537 { 538 {
538 /* only if parent tab.. m_tabWidgets gets deleted and would do that as well */ 539 /* only if parent tab.. m_tabWidgets gets deleted and would do that as well */
539 if (m_parentTab ) 540 if (m_parentTab )
540 removeFromTab( (*it).widget ); 541 removeFromTab( (*it).widget );
541 qWarning("Adding to box %s", (*it).name.latin1() ); 542 qWarning("Adding to box %s", (*it).name.latin1() );
542 addToBox( (*it) ); 543 addToBox( (*it) );
543 } 544 }
544 for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() ) 545 for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() )
545 { 546 {
546 /* tell them the world had changed */ 547 /* tell them the world had changed */
547 split->setTabWidget( 0 ); 548 split->setTabWidget( 0 );
548 Opie::OSplitterContainer con; 549 OSplitterContainer con;
549 con.widget = split; 550 con.widget = split;
550 // con.widget = split->m_tabWidget ? static_cast<QWidget*>(split->m_tabWidget) 551 // con.widget = split->m_tabWidget ? static_cast<QWidget*>(split->m_tabWidget)
551 // : static_cast<QWidget*>(split->m_hbox); 552 // : static_cast<QWidget*>(split->m_hbox);
552 addToBox( con ); 553 addToBox( con );
553 } 554 }
554 555
555 556
556 557
557 if (m_parentTab ) 558 if (m_parentTab )
558 m_parentTab->addTab(m_hbox, iconName(), label() ); 559 m_parentTab->addTab(m_hbox, iconName(), label() );
559 else 560 else
560 { 561 {
561 qWarning(" setting Box geometry for %s", name() ); 562 qWarning(" setting Box geometry for %s", name() );
562 m_hbox->setGeometry( frameRect() ); 563 m_hbox->setGeometry( frameRect() );
563 m_hbox->show(); 564 m_hbox->show();
564 delete m_tabWidget; 565 delete m_tabWidget;
565 m_tabWidget = 0; 566 m_tabWidget = 0;
566 show(); // also show this widget 567 show(); // also show this widget
567 } 568 }
568} 569}
569 570
570/* 571/*
571 * sets the tabwidget, removes tabs, and relayouts the widget 572 * sets the tabwidget, removes tabs, and relayouts the widget
572 */ 573 */
573void OSplitter::setTabWidget( OTabWidget* wid) 574void OSplitter::setTabWidget( OTabWidget* wid)
574{ 575{
575 /* clean up cause m_parentTab will not be available for us */ 576 /* clean up cause m_parentTab will not be available for us */
576 if ( m_parentTab ) 577 if ( m_parentTab )
577 { 578 {
578 if (m_hbox ) 579 if (m_hbox )
579 m_parentTab->removePage( m_hbox ); 580 m_parentTab->removePage( m_hbox );
580 else if (!m_container.isEmpty() ) 581 else if (!m_container.isEmpty() )
581 { 582 {
582 ContainerList::Iterator it = m_container.begin(); 583 ContainerList::Iterator it = m_container.begin();
583 for ( ; it != m_container.end(); ++it ) 584 for ( ; it != m_container.end(); ++it )
584 m_parentTab->removePage( (*it).widget ); 585 m_parentTab->removePage( (*it).widget );
585 } 586 }
586 } 587 }
587 /* the parent Splitter changed so either make us indepent or dep */ 588 /* the parent Splitter changed so either make us indepent or dep */
588 589
589 m_parentTab = wid; 590 m_parentTab = wid;
590 591
591 QWidget *tab = m_tabWidget; 592 QWidget *tab = m_tabWidget;
592 QWidget *box = m_hbox; 593 QWidget *box = m_hbox;
593 m_hbox = 0; m_tabWidget = 0; 594 m_hbox = 0; m_tabWidget = 0;
594 595
595 if ( layoutMode() ) 596 if ( layoutMode() )
596 changeTab(); 597 changeTab();
597 else if (m_orient == Horizontal ) 598 else if (m_orient == Horizontal )
598 changeHBox(); 599 changeHBox();
599 else 600 else
600 changeVBox(); 601 changeVBox();
601 602
602 /* our own crap is added and children from change* */ 603 /* our own crap is added and children from change* */
603 delete tab; 604 delete tab;
604 delete box; 605 delete box;
605} 606}
606 607
607#if 0 608#if 0
608void OSplitter::reparentAll() 609void OSplitter::reparentAll()
609{ 610{
610 if (m_container.isEmpty() ) 611 if (m_container.isEmpty() )
611 return; 612 return;
612 613
613 ContainerList::Iterator it = m_container.begin(); 614 ContainerList::Iterator it = m_container.begin();
614 for ( ; it != m_container.end(); ++it ) 615 for ( ; it != m_container.end(); ++it )
615 (*it).wid->reparent(0, 0, QPoint(0, 0) ); 616 (*it).wid->reparent(0, 0, QPoint(0, 0) );
616 617
617 618
618} 619}
619#endif 620#endif
620 621
621/** 622/**
622 * @internal 623 * @internal
623 */ 624 */
624bool OSplitter::layoutMode()const 625bool OSplitter::layoutMode()const
625{ 626{
626 if ( size().width() > m_size_policy && 627 if ( size().width() > m_size_policy &&
627 m_orient == Horizontal ) 628 m_orient == Horizontal )
628 { 629 {
629 return false; 630 return false;
630 } 631 }
631 else if ( size().height() > m_size_policy && 632 else if ( size().height() > m_size_policy &&
632 m_orient == Vertical ) 633 m_orient == Vertical )
633 { 634 {
634 return false; 635 return false;
635 } 636 }
636 637
637 return true; 638 return true;
638} 639}
diff --git a/libopie2/opieui/big-screen/osplitter.h b/libopie2/opieui/big-screen/osplitter.h
index 2daae7f..7b5ea53 100644
--- a/libopie2/opieui/big-screen/osplitter.h
+++ b/libopie2/opieui/big-screen/osplitter.h
@@ -1,150 +1,151 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org> 3             .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#ifndef OSPLITTER_H 29#ifndef OSPLITTER_H
30#define OSPLITTER_H 30#define OSPLITTER_H
31 31
32#include "obigscreen_p.h" 32#include "obigscreen_p.h"
33 33
34/* QT */ 34/* QT */
35#include <qframe.h> 35#include <qframe.h>
36#include <qlist.h> 36#include <qlist.h>
37#include <qstring.h> 37#include <qstring.h>
38#include <qvaluelist.h> 38#include <qvaluelist.h>
39 39
40class QHBox; 40class QHBox;
41 41
42//template class QValueList<Opie::OSplitterContainer>; 42//template class QValueList<Opie::OSplitterContainer>;
43 43
44/* 44/*
45 * TODO 45 * TODO
46 * -check API docu 46 * -check API docu
47 * -one more example 47 * -one more example
48 * -allow inserting at a position 48 * -allow inserting at a position
49 */ 49 */
50 50
51namespace Opie 51namespace Opie{
52{ 52namespace Ui {
53class OTabWidget; 53class OTabWidget;
54 54
55/** 55/**
56 * 56 *
57 * If you've widgets that could be placed side by side but you think 57 * If you've widgets that could be placed side by side but you think
58 * on small resolutions is not enough place but it would really make sense 58 * on small resolutions is not enough place but it would really make sense
59 * on bigger resolutions this class will help you. 59 * on bigger resolutions this class will help you.
60 * You can add as many widgets you want to it. Set a poliy on which width/height it 60 * You can add as many widgets you want to it. Set a poliy on which width/height it
61 * should switch the layout. 61 * should switch the layout.
62 * You can either say to place widgets vertical or horizontal. 62 * You can either say to place widgets vertical or horizontal.
63 * This class uses QHBox, QVBox and QTAbWidget internally. 63 * This class uses QHBox, QVBox and QTAbWidget internally.
64 * OSplitter takes ownership of the widgets 64 * OSplitter takes ownership of the widgets
65 * 65 *
66 * @since 1.2 66 * @since 1.2
67 * 67 *
68 * @short a small dynamically changing its layout to store two or more widgets side by side 68 * @short a small dynamically changing its layout to store two or more widgets side by side
69 * @version 0.1 69 * @version 0.1
70 * @author zecke 70 * @author zecke
71 */ 71 */
72class OSplitter : public QFrame 72class OSplitter : public QFrame
73{ 73{
74 Q_OBJECT 74 Q_OBJECT
75public: 75public:
76 typedef QValueList<Opie::OSplitterContainer> ContainerList; 76 typedef QValueList<Opie::Ui::Private::OSplitterContainer> ContainerList;
77 OSplitter( Qt::Orientation = Horizontal, QWidget *parent = 0, 77 OSplitter( Qt::Orientation = Horizontal, QWidget *parent = 0,
78 const char* name = 0, WFlags fl = 0 ); 78 const char* name = 0, WFlags fl = 0 );
79 ~OSplitter(); 79 ~OSplitter();
80 80
81 void setLabel( const QString& name ); 81 void setLabel( const QString& name );
82 void setIconName( const QString& name ); 82 void setIconName( const QString& name );
83 QString label()const; 83 QString label()const;
84 QString iconName()const; 84 QString iconName()const;
85 85
86 void setSizeChange( int width_height ); 86 void setSizeChange( int width_height );
87 87
88 void addWidget( OSplitter* splitter ); 88 void addWidget( OSplitter* splitter );
89 void addWidget( QWidget* wid, const QString& icon, const QString& label ); 89 void addWidget( QWidget* wid, const QString& icon, const QString& label );
90 void removeWidget( QWidget* ); 90 void removeWidget( QWidget* );
91 void removeWidget( OSplitter* ); 91 void removeWidget( OSplitter* );
92 92
93 void setCurrentWidget( QWidget* ); 93 void setCurrentWidget( QWidget* );
94 void setCurrentWidget( const QString& label ); 94 void setCurrentWidget( const QString& label );
95 void setCurrentWidget( int ); 95 void setCurrentWidget( int );
96 QWidget* currentWidget()const; 96 QWidget* currentWidget()const;
97 97
98 98
99signals: 99signals:
100 /** 100 /**
101 * Emitted if in tab and comes directly from the tab widget 101 * Emitted if in tab and comes directly from the tab widget
102 * 102 *
103 */ 103 */
104 void currentChanged( QWidget* ); 104 void currentChanged( QWidget* );
105 105
106 /** 106 /**
107 * emitted whenever a border is crossed 107 * emitted whenever a border is crossed
108 * true if in small screen mode 108 * true if in small screen mode
109 * false if in bigscreen 109 * false if in bigscreen
110 * this signal is emitted after the layout switch 110 * this signal is emitted after the layout switch
111 * @param b The layout mode 111 * @param b The layout mode
112 * @param ori The orientation 112 * @param ori The orientation
113 */ 113 */
114 void sizeChanged( bool b, Orientation ori); 114 void sizeChanged( bool b, Orientation ori);
115public: 115public:
116 // QSize sizeHint()const; 116 // QSize sizeHint()const;
117 // QSize minimumSizeHint()const; 117 // QSize minimumSizeHint()const;
118 118
119protected: 119protected:
120 void resizeEvent( QResizeEvent* ); 120 void resizeEvent( QResizeEvent* );
121 121
122private: 122private:
123 /* true if OTabMode */ 123 /* true if OTabMode */
124 bool layoutMode()const; 124 bool layoutMode()const;
125 // void reparentAll(); 125 // void reparentAll();
126 void setTabWidget( OTabWidget*); 126 void setTabWidget( OTabWidget*);
127 void addToTab( const Opie::OSplitterContainer& ); 127 void addToTab( const Opie::Ui::Private::OSplitterContainer& );
128 void addToBox( const Opie::OSplitterContainer& ); 128 void addToBox( const Opie::Ui::Private::OSplitterContainer& );
129 void removeFromTab( QWidget* ); 129 void removeFromTab( QWidget* );
130 void changeTab(); 130 void changeTab();
131 void changeHBox(); 131 void changeHBox();
132 void changeVBox(); 132 void changeVBox();
133 void commonChangeBox(); 133 void commonChangeBox();
134 QHBox *m_hbox; 134 QHBox *m_hbox;
135 OTabWidget *m_tabWidget; 135 OTabWidget *m_tabWidget;
136 OTabWidget *m_parentTab; 136 OTabWidget *m_parentTab;
137 Orientation m_orient; 137 Orientation m_orient;
138 int m_size_policy; 138 int m_size_policy;
139 139
140 ContainerList m_container; 140 ContainerList m_container;
141 QList<OSplitter> m_splitter; 141 QList<OSplitter> m_splitter;
142 142
143 QString m_icon, m_name; 143 QString m_icon, m_name;
144 144
145 struct Private; 145 struct Private;
146 Private *d; 146 Private *d;
147}; 147};
148}; 148}
149}
149 150
150#endif 151#endif
diff --git a/libopie2/opieui/big-screen/owidgetstack.cpp b/libopie2/opieui/big-screen/owidgetstack.cpp
index 57e97e3..a0a6355 100644
--- a/libopie2/opieui/big-screen/owidgetstack.cpp
+++ b/libopie2/opieui/big-screen/owidgetstack.cpp
@@ -1,435 +1,438 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org> 3             .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include "owidgetstack.h" 29#include "owidgetstack.h"
30 30
31/* QT */ 31/* QT */
32#include <qapplication.h> 32#include <qapplication.h>
33#include <qwidgetstack.h> 33#include <qwidgetstack.h>
34 34
35namespace { 35namespace Opie {
36namespace Ui {
36 const int mode_size = 330; 37 const int mode_size = 330;
37}
38 38
39using namespace Opie; 39
40 40
41/** 41/**
42 * This is the standard widget. For simple usage see the example. Normally this widget 42 * This is the standard widget. For simple usage see the example. Normally this widget
43 * is the central widget of a QMainWindow. 43 * is the central widget of a QMainWindow.
44 * Use removeWidget before you delete a widget yourself. OWidgetStack does not 44 * Use removeWidget before you delete a widget yourself. OWidgetStack does not
45 * yet recognize removal of children. 45 * yet recognize removal of children.
46 * 46 *
47 * @param parent The parent widget. It maybe 0 but then you need to take care of deletion. 47 * @param parent The parent widget. It maybe 0 but then you need to take care of deletion.
48 * Or you use QPEApplication::showMainWidget(). 48 * Or you use QPEApplication::showMainWidget().
49 * @param name Name will be passed on to QObject 49 * @param name Name will be passed on to QObject
50 * @param fl Additional window flags passed to QFrame. see @Qt::WFlags 50 * @param fl Additional window flags passed to QFrame. see @Qt::WFlags
51 */ 51 */
52OWidgetStack::OWidgetStack( QWidget* parent, const char* name, WFlags fl) 52OWidgetStack::OWidgetStack( QWidget* parent, const char* name, WFlags fl)
53 : QFrame( parent, name, fl ) 53 : QFrame( parent, name, fl )
54{ 54{
55 m_last = m_mWidget = 0; 55 m_last = m_mWidget = 0;
56 m_forced = false; 56 m_forced = false;
57 57
58 QApplication::desktop()->installEventFilter( this ); 58 QApplication::desktop()->installEventFilter( this );
59 setFontPropagation ( AllChildren ); 59 setFontPropagation ( AllChildren );
60 setPalettePropagation( AllChildren ); 60 setPalettePropagation( AllChildren );
61 61
62 /* sets m_mode and initializes more */ 62 /* sets m_mode and initializes more */
63 /* if you change this call change switchTop as well */ 63 /* if you change this call change switchTop as well */
64 m_stack = 0; 64 m_stack = 0;
65 switchStack(); 65 switchStack();
66} 66}
67 67
68/** 68/**
69 * The destructor. It deletes also all added widgets. 69 * The destructor. It deletes also all added widgets.
70 * 70 *
71 */ 71 */
72OWidgetStack::~OWidgetStack() { 72OWidgetStack::~OWidgetStack() {
73 if (m_mode == BigScreen && !m_list.isEmpty() ) { 73 if (m_mode == BigScreen && !m_list.isEmpty() ) {
74 QMap<int, QWidget*>::Iterator it = m_list.begin(); 74 QMap<int, QWidget*>::Iterator it = m_list.begin();
75 for ( ; it != m_list.end(); ++it ) 75 for ( ; it != m_list.end(); ++it )
76 delete it.data(); 76 delete it.data();
77 } 77 }
78 m_list.clear(); 78 m_list.clear();
79 79
80} 80}
81 81
82/** 82/**
83 * return the mode of the desktop. There are currently two modes. SmallScreen 83 * return the mode of the desktop. There are currently two modes. SmallScreen
84 * with a normal PDA resolution and BigScreen with resolutions greater than 84 * with a normal PDA resolution and BigScreen with resolutions greater than
85 * 330 for width and height. 85 * 330 for width and height.
86 * You can also force the mode this widget is in with forceMode() 86 * You can also force the mode this widget is in with forceMode()
87 * Note that NoForce will be never returned from here 87 * Note that NoForce will be never returned from here
88 */ 88 */
89enum OWidgetStack::Mode OWidgetStack::mode()const { 89enum OWidgetStack::Mode OWidgetStack::mode()const {
90 return m_mode; 90 return m_mode;
91} 91}
92 92
93/** 93/**
94 * You can also force one of the modes and then 94 * You can also force one of the modes and then
95 * this widget stops on listening to size changes. You 95 * this widget stops on listening to size changes. You
96 * can revert to the scanning behaviour by setting mode 96 * can revert to the scanning behaviour by setting mode
97 * to NoForce 97 * to NoForce
98 */ 98 */
99void OWidgetStack::forceMode( enum Mode mode) { 99void OWidgetStack::forceMode( enum Mode mode) {
100 m_forced = mode != NoForce; 100 m_forced = mode != NoForce;
101 101
102 /* we need to see which mode we're in */ 102 /* we need to see which mode we're in */
103 if (!m_forced ) { 103 if (!m_forced ) {
104 if ( QApplication::desktop()->width() >= 104 if ( QApplication::desktop()->width() >=
105 mode_size ) 105 mode_size )
106 mode = BigScreen; 106 mode = BigScreen;
107 else 107 else
108 mode = SmallScreen; 108 mode = SmallScreen;
109 } 109 }
110 switch( mode ) { 110 switch( mode ) {
111 case NoForce: 111 case NoForce:
112 case SmallScreen: 112 case SmallScreen:
113 switchStack(); 113 switchStack();
114 break; 114 break;
115 case BigScreen: 115 case BigScreen:
116 switchTop(); 116 switchTop();
117 break; 117 break;
118 118
119 } 119 }
120 120
121 m_mode = mode; 121 m_mode = mode;
122} 122}
123 123
124/** 124/**
125 * Adds a widget to the stack. The first widget added is considered 125 * Adds a widget to the stack. The first widget added is considered
126 * to be the mainwindow. This is important because if Opie is in 126 * to be the mainwindow. This is important because if Opie is in
127 * BigScreen mode the sizeHint of the MainWindow will be returned. 127 * BigScreen mode the sizeHint of the MainWindow will be returned.
128 * In Small Screen the sizeHint of the QWidgetStack is returned. 128 * In Small Screen the sizeHint of the QWidgetStack is returned.
129 * See QWidgetStack::sizeHint. 129 * See QWidgetStack::sizeHint.
130 * This widget takes ownership of the widget and may even reparent. 130 * This widget takes ownership of the widget and may even reparent.
131 * All windows will be hidden 131 * All windows will be hidden
132 * 132 *
133 * @param wid The QWidget to be added 133 * @param wid The QWidget to be added
134 * @param id An ID for the Widget. If the ID is duplicated the 134 * @param id An ID for the Widget. If the ID is duplicated the
135 last set widget will be related to the id 135 last set widget will be related to the id
136 * 136 *
137 */ 137 */
138void OWidgetStack::addWidget( QWidget* wid, int id) { 138void OWidgetStack::addWidget( QWidget* wid, int id) {
139 if (!wid) 139 if (!wid)
140 return; 140 return;
141 141
142 /* set our main widget */ 142 /* set our main widget */
143 if (!m_mWidget) 143 if (!m_mWidget)
144 m_mWidget = wid; 144 m_mWidget = wid;
145 145
146 m_list.insert( id, wid ); 146 m_list.insert( id, wid );
147 147
148 /** 148 /**
149 * adding does not raise any widget 149 * adding does not raise any widget
150 * But for our mainwidget we prepare 150 * But for our mainwidget we prepare
151 * the right position with the right parent 151 * the right position with the right parent
152 */ 152 */
153 if (m_mode == SmallScreen ) 153 if (m_mode == SmallScreen )
154 m_stack->addWidget( wid,id ); 154 m_stack->addWidget( wid,id );
155 else if ( m_mWidget == wid ) { 155 else if ( m_mWidget == wid ) {
156 wid->reparent(this, 0, contentsRect().topLeft() ); 156 wid->reparent(this, 0, contentsRect().topLeft() );
157 wid->hide(); 157 wid->hide();
158 }else { 158 }else {
159 wid->reparent(0, WType_TopLevel, QPoint(10, 10) ); 159 wid->reparent(0, WType_TopLevel, QPoint(10, 10) );
160 wid->hide(); 160 wid->hide();
161 } 161 }
162} 162}
163 163
164 164
165/** 165/**
166 * Remove the widget from the stack it'll be reparented to 0 166 * Remove the widget from the stack it'll be reparented to 0
167 * and ownership is dropped. You need to delete it. 167 * and ownership is dropped. You need to delete it.
168 * If the removed widget was the mainwindow consider 168 * If the removed widget was the mainwindow consider
169 * to call setMainWindow. 169 * to call setMainWindow.
170 * 170 *
171 * @param wid The QWidget to be removed 171 * @param wid The QWidget to be removed
172 */ 172 */
173void OWidgetStack::removeWidget( QWidget* wid) { 173void OWidgetStack::removeWidget( QWidget* wid) {
174 if (!wid) 174 if (!wid)
175 return; 175 return;
176 176
177 if (m_mode == SmallScreen ) 177 if (m_mode == SmallScreen )
178 m_stack->removeWidget( wid ); 178 m_stack->removeWidget( wid );
179 179
180 180
181 wid->reparent(0, 0, QPoint(0, 0) ); 181 wid->reparent(0, 0, QPoint(0, 0) );
182 m_list.remove( id(wid) ); 182 m_list.remove( id(wid) );
183 183
184 if ( wid == m_mWidget ) 184 if ( wid == m_mWidget )
185 m_mWidget = 0; 185 m_mWidget = 0;
186} 186}
187 187
188#if 0 188#if 0
189/** 189/**
190 * @internal_resons 190 * @internal_resons
191 */ 191 */
192QSizeHint OWidgetStack::sizeHint()const { 192QSizeHint OWidgetStack::sizeHint()const {
193 193
194} 194}
195 195
196/** 196/**
197 * @internal_reasons 197 * @internal_reasons
198 */ 198 */
199QSizeHint OWidgetStack::minimumSizeHint()const { 199QSizeHint OWidgetStack::minimumSizeHint()const {
200 200
201} 201}
202#endif 202#endif
203 203
204/** 204/**
205 * This function tries to find the widget with the id. 205 * This function tries to find the widget with the id.
206 * You supplied a possible id in addWIdget. Note that not 206 * You supplied a possible id in addWIdget. Note that not
207 * QWidget::winId() is used. 207 * QWidget::winId() is used.
208 * 208 *
209 * @param id The id to search for 209 * @param id The id to search for
210 * 210 *
211 * @return The widget or null 211 * @return The widget or null
212 * @see addWidget 212 * @see addWidget
213 */ 213 */
214QWidget* OWidgetStack::widget( int id) const { 214QWidget* OWidgetStack::widget( int id) const {
215 return m_list[id]; 215 return m_list[id];
216} 216}
217 217
218/** 218/**
219 * Tries to find the assigned id for the widget 219 * Tries to find the assigned id for the widget
220 * or returns -1 if no widget could be found 220 * or returns -1 if no widget could be found
221 * @param wid The widget to look for 221 * @param wid The widget to look for
222 */ 222 */
223int OWidgetStack::id( QWidget* wid)const{ 223int OWidgetStack::id( QWidget* wid)const{
224 if (m_list.isEmpty() ) 224 if (m_list.isEmpty() )
225 return -1; 225 return -1;
226 226
227 QMap<int, QWidget*>::ConstIterator it = m_list.begin(); 227 QMap<int, QWidget*>::ConstIterator it = m_list.begin();
228 for ( ; it != m_list.end(); ++it ) 228 for ( ; it != m_list.end(); ++it )
229 if ( it.data() == wid ) 229 if ( it.data() == wid )
230 break; 230 break;
231 231
232 /* if not at the end return the key */ 232 /* if not at the end return the key */
233 return it == m_list.end() ? -1 : it.key(); 233 return it == m_list.end() ? -1 : it.key();
234} 234}
235 235
236 236
237/** 237/**
238 * This function returns the currently visible 238 * This function returns the currently visible
239 * widget. In BigScreen mode the mainwindow 239 * widget. In BigScreen mode the mainwindow
240 * is returned 240 * is returned
241 */ 241 */
242QWidget* OWidgetStack::visibleWidget()const { 242QWidget* OWidgetStack::visibleWidget()const {
243 if (m_mode == SmallScreen ) 243 if (m_mode == SmallScreen )
244 return m_stack->visibleWidget(); 244 return m_stack->visibleWidget();
245 else 245 else
246 return m_mWidget; 246 return m_mWidget;
247 247
248} 248}
249 249
250/** 250/**
251 * This method raises the widget wit the specefic id. 251 * This method raises the widget wit the specefic id.
252 * Note that in BigScreen mode the widget is made visible 252 * Note that in BigScreen mode the widget is made visible
253 * but the other ( previous) visible widget(s) will not 253 * but the other ( previous) visible widget(s) will not
254 * be made invisible. If you need this use hideWidget(). 254 * be made invisible. If you need this use hideWidget().
255 * 255 *
256 * @param id Raise the widget with id 256 * @param id Raise the widget with id
257 */ 257 */
258void OWidgetStack::raiseWidget( int id) { 258void OWidgetStack::raiseWidget( int id) {
259 return raiseWidget( widget( id ) ); 259 return raiseWidget( widget( id ) );
260} 260}
261 261
262/** 262/**
263 * This is an overloaded function and only differs in its parameters. 263 * This is an overloaded function and only differs in its parameters.
264 * @see raiseWidget( int ) 264 * @see raiseWidget( int )
265 */ 265 */
266void OWidgetStack::raiseWidget( QWidget* wid) { 266void OWidgetStack::raiseWidget( QWidget* wid) {
267 m_last = wid; 267 m_last = wid;
268 if (m_mode == SmallScreen ) 268 if (m_mode == SmallScreen )
269 m_stack->raiseWidget( wid ); 269 m_stack->raiseWidget( wid );
270 else { 270 else {
271 int ide; 271 int ide;
272 emit aboutToShow( wid ); 272 emit aboutToShow( wid );
273 /* if someone is connected and the widget is actually available */ 273 /* if someone is connected and the widget is actually available */
274 if ( receivers( SIGNAL(aboutToShow(int) ) ) && 274 if ( receivers( SIGNAL(aboutToShow(int) ) ) &&
275 ( (ide = id( wid ) ) != -1 ) ) 275 ( (ide = id( wid ) ) != -1 ) )
276 emit aboutToShow( ide ); 276 emit aboutToShow( ide );
277 277
278 /* ### FIXME PLACE THE WIDGET right */ 278 /* ### FIXME PLACE THE WIDGET right */
279 wid->show(); 279 wid->show();
280 } 280 }
281} 281}
282 282
283/** 283/**
284 * This will hide the currently visible widget 284 * This will hide the currently visible widget
285 * and raise the widget specified by the parameter. 285 * and raise the widget specified by the parameter.
286 * Note that this method does not use visibleWIdget but remembers 286 * Note that this method does not use visibleWIdget but remembers
287 * the last raisedWidget 287 * the last raisedWidget
288 */ 288 */
289void OWidgetStack::hideWidget( int id) { 289void OWidgetStack::hideWidget( int id) {
290 /* hiding our main widget wouldn't be smart */ 290 /* hiding our main widget wouldn't be smart */
291 if ( m_mode == BigScreen && m_last != m_mWidget ) 291 if ( m_mode == BigScreen && m_last != m_mWidget )
292 m_last->hide(); 292 m_last->hide();
293 raiseWidget( id ); 293 raiseWidget( id );
294} 294}
295 295
296/** 296/**
297 * This is overloaded and only differs in the parameters 297 * This is overloaded and only differs in the parameters
298 * it takes. 298 * it takes.
299 */ 299 */
300void OWidgetStack::hideWidget( QWidget* wid) { 300void OWidgetStack::hideWidget( QWidget* wid) {
301 /* still not smart */ 301 /* still not smart */
302 if ( m_mode == BigScreen && m_last != m_mWidget ) 302 if ( m_mode == BigScreen && m_last != m_mWidget )
303 m_last->hide(); 303 m_last->hide();
304 304
305 raiseWidget( wid ); 305 raiseWidget( wid );
306} 306}
307 307
308 308
309bool OWidgetStack::eventFilter( QObject* obj, QEvent* e) { 309bool OWidgetStack::eventFilter( QObject* obj, QEvent* e) {
310 qWarning(" %s %s", obj->name(), obj->className() ); 310 qWarning(" %s %s", obj->name(), obj->className() );
311 if ( e->type() == QEvent::Resize ) { 311 if ( e->type() == QEvent::Resize ) {
312 QResizeEvent *res = static_cast<QResizeEvent*>( e ); 312 QResizeEvent *res = static_cast<QResizeEvent*>( e );
313 QSize size = res->size(); 313 QSize size = res->size();
314 if ( size.width() >= mode_size ) 314 if ( size.width() >= mode_size )
315 switchTop(); 315 switchTop();
316 else 316 else
317 switchStack(); 317 switchStack();
318 } 318 }
319 return false; 319 return false;
320} 320}
321 321
322 322
323/** 323/**
324 * @internal_resons 324 * @internal_resons
325 */ 325 */
326void OWidgetStack::resizeEvent( QResizeEvent* ev ) { 326void OWidgetStack::resizeEvent( QResizeEvent* ev ) {
327 QFrame::resizeEvent( ev ); 327 QFrame::resizeEvent( ev );
328 if (m_mode == SmallScreen ) 328 if (m_mode == SmallScreen )
329 m_stack->setGeometry( frameRect() ); 329 m_stack->setGeometry( frameRect() );
330 else 330 else
331 if (m_mWidget ) 331 if (m_mWidget )
332 m_mWidget->setGeometry( frameRect() ); 332 m_mWidget->setGeometry( frameRect() );
333 333
334} 334}
335 335
336/** 336/**
337 * setMainWindow gives the OWidgetStack a hint which 337 * setMainWindow gives the OWidgetStack a hint which
338 * window should always stay inside the stack. 338 * window should always stay inside the stack.
339 * Normally the first added widget is considered to be 339 * Normally the first added widget is considered to be
340 * the mainwindow but you can change this with this 340 * the mainwindow but you can change this with this
341 * function. 341 * function.
342 * If in BigScreen mode the current mainwindow will be reparented 342 * If in BigScreen mode the current mainwindow will be reparented
343 * and hidden. The position will be taken by the new one. 343 * and hidden. The position will be taken by the new one.
344 * If the old MainWindow was hidden the new window will 344 * If the old MainWindow was hidden the new window will
345 * also be hidden. If the window was visible the new mainwindow 345 * also be hidden. If the window was visible the new mainwindow
346 * will be made visible too and the old one hidden. If there 346 * will be made visible too and the old one hidden. If there
347 * was no mainwindow it will be hidden as well. 347 * was no mainwindow it will be hidden as well.
348 * 348 *
349 * @param wid The new mainwindow 349 * @param wid The new mainwindow
350 */ 350 */
351void OWidgetStack::setMainWindow( QWidget* wid ) { 351void OWidgetStack::setMainWindow( QWidget* wid ) {
352 if (m_mode == BigScreen ) { 352 if (m_mode == BigScreen ) {
353 bool wasVisible = false; 353 bool wasVisible = false;
354 if (m_mWidget ) { 354 if (m_mWidget ) {
355 wasVisible = !m_mWidget->isHidden(); 355 wasVisible = !m_mWidget->isHidden();
356 /* hidden by default */ 356 /* hidden by default */
357 m_mWidget->reparent(0, WType_TopLevel, QPoint(10, 10) ); 357 m_mWidget->reparent(0, WType_TopLevel, QPoint(10, 10) );
358 } 358 }
359 wid->reparent(this, 0, frameRect().topLeft() ); 359 wid->reparent(this, 0, frameRect().topLeft() );
360 360
361 if (wasVisible) 361 if (wasVisible)
362 wid->show(); 362 wid->show();
363 } 363 }
364 364
365 m_mWidget = wid; 365 m_mWidget = wid;
366} 366}
367 367
368/** 368/**
369 * this is an overloaded member and only differs 369 * this is an overloaded member and only differs
370 * in the type of arguments. 370 * in the type of arguments.
371 * @see setMainWindow(QWidget*) 371 * @see setMainWindow(QWidget*)
372 */ 372 */
373void OWidgetStack::setMainWindow( int id) { 373void OWidgetStack::setMainWindow( int id) {
374 setMainWindow( widget( id ) ); 374 setMainWindow( widget( id ) );
375} 375}
376 376
377 377
378/* 378/*
379 * this function switches to a stack ;) 379 * this function switches to a stack ;)
380 */ 380 */
381void OWidgetStack::switchStack() { 381void OWidgetStack::switchStack() {
382 if (m_stack ) { 382 if (m_stack ) {
383 m_stack->setGeometry( frameRect() ); 383 m_stack->setGeometry( frameRect() );
384 return; 384 return;
385 } 385 }
386 386
387 m_mode = SmallScreen; 387 m_mode = SmallScreen;
388 m_stack = new QWidgetStack(this); 388 m_stack = new QWidgetStack(this);
389 389
390 connect(m_stack, SIGNAL(aboutToShow(QWidget*) ), 390 connect(m_stack, SIGNAL(aboutToShow(QWidget*) ),
391 this, SIGNAL(aboutToShow(QWidget*) ) ); 391 this, SIGNAL(aboutToShow(QWidget*) ) );
392 connect(m_stack, SIGNAL(aboutToShow(int) ), 392 connect(m_stack, SIGNAL(aboutToShow(int) ),
393 this, SIGNAL(aboutToShow(int) ) ); 393 this, SIGNAL(aboutToShow(int) ) );
394 394
395 /* now reparent the widgets... luckily QWidgetSatck does most of the work */ 395 /* now reparent the widgets... luckily QWidgetSatck does most of the work */
396 if (m_list.isEmpty() ) 396 if (m_list.isEmpty() )
397 return; 397 return;
398 398
399 QMap<int, QWidget*>::Iterator it = m_list.begin(); 399 QMap<int, QWidget*>::Iterator it = m_list.begin();
400 for ( ; it != m_list.end(); ++it ) 400 for ( ; it != m_list.end(); ++it )
401 m_stack->addWidget( it.data(), it.key() ); 401 m_stack->addWidget( it.data(), it.key() );
402 402
403 403
404} 404}
405 405
406/* 406/*
407 * we will switch to top level mode 407 * we will switch to top level mode
408 * reparent the list of widgets and then delete the stack 408 * reparent the list of widgets and then delete the stack
409 */ 409 */
410void OWidgetStack::switchTop() { 410void OWidgetStack::switchTop() {
411 m_mode = BigScreen; 411 m_mode = BigScreen;
412 /* this works because it is guaranteed that switchStack was called at least once*/ 412 /* this works because it is guaranteed that switchStack was called at least once*/
413 if (!m_stack && m_mWidget) { 413 if (!m_stack && m_mWidget) {
414 m_mWidget->setGeometry( frameRect() ); 414 m_mWidget->setGeometry( frameRect() );
415 return; 415 return;
416 }else if (!m_stack) 416 }else if (!m_stack)
417 return; 417 return;
418 418
419 if (!m_list.isEmpty() ) { 419 if (!m_list.isEmpty() ) {
420 QMap<int, QWidget*>::Iterator it = m_list.begin(); 420 QMap<int, QWidget*>::Iterator it = m_list.begin();
421 for ( ; it != m_list.end(); ++it ) { 421 for ( ; it != m_list.end(); ++it ) {
422 /* better than reparenting twice */ 422 /* better than reparenting twice */
423 if ( it.data() == m_mWidget ) { 423 if ( it.data() == m_mWidget ) {
424 m_mWidget->reparent(this, 0, frameRect().topLeft() ); 424 m_mWidget->reparent(this, 0, frameRect().topLeft() );
425 m_mWidget->setGeometry( frameRect() ); 425 m_mWidget->setGeometry( frameRect() );
426 m_mWidget->show(); 426 m_mWidget->show();
427 }else 427 }else
428 /* ### FIXME we need to place the widget better */ 428 /* ### FIXME we need to place the widget better */
429 it.data()->reparent(0, WType_TopLevel, QPoint(10, 10) ); 429 it.data()->reparent(0, WType_TopLevel, QPoint(10, 10) );
430 } 430 }
431 } 431 }
432 432
433 delete m_stack; 433 delete m_stack;
434 m_stack = 0; 434 m_stack = 0;
435} 435}
436
437}
438} \ No newline at end of file
diff --git a/libopie2/opieui/big-screen/owidgetstack.h b/libopie2/opieui/big-screen/owidgetstack.h
index 53818c8..d2f9a9f 100644
--- a/libopie2/opieui/big-screen/owidgetstack.h
+++ b/libopie2/opieui/big-screen/owidgetstack.h
@@ -1,132 +1,133 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org> 3             .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#ifndef OWIDGETSTACK_H 29#ifndef OWIDGETSTACK_H
30#define OWIDGETSTACK_H 30#define OWIDGETSTACK_H
31 31
32/* QT*/ 32/* QT*/
33#include <qframe.h> 33#include <qframe.h>
34#include <qmap.h> 34#include <qmap.h>
35 35
36class QWidgetStack; 36class QWidgetStack;
37 37
38namespace Opie 38namespace Opie {
39{ 39namespace Ui {
40/** 40/**
41 * 41 *
42 * OWidgetStack is the answer to the problem of using Opie at different screen 42 * OWidgetStack is the answer to the problem of using Opie at different screen
43 * sizes and to have a different behaviour. Most applications use a QWidgetStack 43 * sizes and to have a different behaviour. Most applications use a QWidgetStack
44 * to supply a view on click. And by clicking the (X) you go back but this 44 * to supply a view on click. And by clicking the (X) you go back but this
45 * behaviour feels strange on bigger screens. It's ok on smaller one because 45 * behaviour feels strange on bigger screens. It's ok on smaller one because
46 * one can't determine the difference. 46 * one can't determine the difference.
47 * This stack reads the default out of the size of the desktop widget but 47 * This stack reads the default out of the size of the desktop widget but
48 * can be forced to have either the one or the other behaviour. 48 * can be forced to have either the one or the other behaviour.
49 * The first widget added is considered the 'main' widget and its 49 * The first widget added is considered the 'main' widget and its
50 * sizeHint will be taking if in BigScreen mode. 50 * sizeHint will be taking if in BigScreen mode.
51 * In small screen mode this widget behaves exactly like a QWidgetStack and in BigScreen 51 * In small screen mode this widget behaves exactly like a QWidgetStack and in BigScreen
52 * mode it'll use the MainWindow as child of this widget and arranges the others as 52 * mode it'll use the MainWindow as child of this widget and arranges the others as
53 * hidden top level widgets. 53 * hidden top level widgets.
54 * 54 *
55 * @version 0.1 55 * @version 0.1
56 * @author hOlgAr F. 56 * @author hOlgAr F.
57 * @short Either a true stack or a list of top Level widgets 57 * @short Either a true stack or a list of top Level widgets
58 */ 58 */
59class OWidgetStack : public QFrame { 59class OWidgetStack : public QFrame {
60 Q_OBJECT 60 Q_OBJECT
61public: 61public:
62 enum Mode { SmallScreen, BigScreen, NoForce }; 62 enum Mode { SmallScreen, BigScreen, NoForce };
63 OWidgetStack( QWidget* parent, const char* name = 0, WFlags fl = 0 ); 63 OWidgetStack( QWidget* parent, const char* name = 0, WFlags fl = 0 );
64 ~OWidgetStack(); 64 ~OWidgetStack();
65 65
66 enum Mode mode()const; 66 enum Mode mode()const;
67 void forceMode( enum Mode ); 67 void forceMode( enum Mode );
68 68
69 void addWidget( QWidget* , int ); 69 void addWidget( QWidget* , int );
70 void removeWidget( QWidget* ); 70 void removeWidget( QWidget* );
71 71
72// QSizeHint sizeHint()const; 72// QSizeHint sizeHint()const;
73// QSizeHint minimumSizeHint()const; 73// QSizeHint minimumSizeHint()const;
74 74
75 QWidget *widget( int )const; 75 QWidget *widget( int )const;
76 int id( QWidget* )const; 76 int id( QWidget* )const;
77 77
78 78
79 79
80 QWidget* visibleWidget() const; 80 QWidget* visibleWidget() const;
81 81
82 bool eventFilter( QObject*, QEvent* ); 82 bool eventFilter( QObject*, QEvent* );
83signals: 83signals:
84 /** 84 /**
85 * OWidgetStack monitors the Desktop Widget for 85 * OWidgetStack monitors the Desktop Widget for
86 * size changes if it recignizes a change size it'll 86 * size changes if it recignizes a change size it'll
87 * send a signal and adjust its mode. After the signal 87 * send a signal and adjust its mode. After the signal
88 * was emitted. During the signal a call to mode() the 88 * was emitted. During the signal a call to mode() the
89 * old mode will be returned. Note that if a size change happens 89 * old mode will be returned. Note that if a size change happens
90 * but no modeChange no signal will be emitted 90 * but no modeChange no signal will be emitted
91 * 91 *
92 * 92 *
93 * @param mode The new mode of the desktop 93 * @param mode The new mode of the desktop
94 */ 94 */
95 void modeChanged( enum Mode mode); 95 void modeChanged( enum Mode mode);
96 96
97 /** 97 /**
98 * These two signals are emitted whenever we're about to 98 * These two signals are emitted whenever we're about to
99 * show one of the widgets 99 * show one of the widgets
100 */ 100 */
101 void aboutToShow( QWidget* ); 101 void aboutToShow( QWidget* );
102 void aboutToShow( int ); 102 void aboutToShow( int );
103 103
104public slots: 104public slots:
105 void raiseWidget( int ); 105 void raiseWidget( int );
106 void raiseWidget( QWidget* ); 106 void raiseWidget( QWidget* );
107 void hideWidget( int ); 107 void hideWidget( int );
108 void hideWidget( QWidget* ); 108 void hideWidget( QWidget* );
109 void setMainWindow( QWidget* ); 109 void setMainWindow( QWidget* );
110 void setMainWindow( int ); 110 void setMainWindow( int );
111 111
112protected: 112protected:
113 void resizeEvent( QResizeEvent* ); 113 void resizeEvent( QResizeEvent* );
114 114
115private: 115private:
116 void switchStack(); 116 void switchStack();
117 void switchTop(); 117 void switchTop();
118 QMap<int, QWidget*> m_list; 118 QMap<int, QWidget*> m_list;
119 QWidgetStack *m_stack; 119 QWidgetStack *m_stack;
120 QWidget *m_mWidget; 120 QWidget *m_mWidget;
121 QWidget *m_last; 121 QWidget *m_last;
122 122
123 enum Mode m_mode; 123 enum Mode m_mode;
124 bool m_forced : 1; 124 bool m_forced : 1;
125 125
126 struct Private; 126 struct Private;
127 Private *d; 127 Private *d;
128}; 128};
129 129
130}; 130}
131}
131 132
132#endif 133#endif
diff --git a/libopie2/opieui/fileselector/ofiledialog.cpp b/libopie2/opieui/fileselector/ofiledialog.cpp
index e7daead..beb4d6c 100644
--- a/libopie2/opieui/fileselector/ofiledialog.cpp
+++ b/libopie2/opieui/fileselector/ofiledialog.cpp
@@ -1,222 +1,222 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) Holger Freyther <zecke@handhelds.org> 3             .=l. Copyright (C) Holger Freyther <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29 29
30/* OPIE */ 30/* OPIE */
31#include <opie2/ofiledialog.h> 31#include <opie2/ofiledialog.h>
32#include <qpe/applnk.h> 32#include <qpe/applnk.h>
33#include <qpe/config.h> 33#include <qpe/config.h>
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35 35
36/* QT */ 36/* QT */
37#include <qfileinfo.h> 37#include <qfileinfo.h>
38#include <qstring.h> 38#include <qstring.h>
39#include <qapplication.h> 39#include <qapplication.h>
40#include <qlayout.h> 40#include <qlayout.h>
41 41
42using namespace Opie; 42using namespace Opie::Ui;
43 43
44namespace 44namespace
45{ 45{
46/* 46/*
47 * helper functions to load the start dir 47 * helper functions to load the start dir
48 * and to save it 48 * and to save it
49 * helper to extract the dir out of a file name 49 * helper to extract the dir out of a file name
50 */ 50 */
51/** 51/**
52 * This method will use Config( argv[0] ); 52 * This method will use Config( argv[0] );
53 * @param key The group key used 53 * @param key The group key used
54 */ 54 */
55QString lastUsedDir( const QString& key ) 55QString lastUsedDir( const QString& key )
56{ 56{
57 if ( qApp->argc() < 1 ) 57 if ( qApp->argc() < 1 )
58 return QString::null; 58 return QString::null;
59 59
60 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname 60 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname
61 cfg.setGroup( key ); 61 cfg.setGroup( key );
62 return cfg.readEntry("LastDir", QPEApplication::documentDir() ); 62 return cfg.readEntry("LastDir", QPEApplication::documentDir() );
63} 63}
64 64
65void saveLastDir( const QString& key, const QString& file ) 65void saveLastDir( const QString& key, const QString& file )
66{ 66{
67 if ( qApp->argc() < 1 ) 67 if ( qApp->argc() < 1 )
68 return; 68 return;
69 69
70 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); 70 Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
71 cfg.setGroup( key ); 71 cfg.setGroup( key );
72 QFileInfo inf( file ); 72 QFileInfo inf( file );
73 cfg.writeEntry("LastDir", inf.dirPath( true ) ); 73 cfg.writeEntry("LastDir", inf.dirPath( true ) );
74} 74}
75}; 75};
76 76
77/** 77/**
78 * This constructs a modal dialog 78 * This constructs a modal dialog
79 * 79 *
80 * @param caption The caption of the dialog 80 * @param caption The caption of the dialog
81 * @param wid The parent widget 81 * @param wid The parent widget
82 * @param mode The mode of the OFileSelector @see OFileSelector 82 * @param mode The mode of the OFileSelector @see OFileSelector
83 * @param selector The selector of the OFileSelector 83 * @param selector The selector of the OFileSelector
84 * @param dirName the dir or resource to start from 84 * @param dirName the dir or resource to start from
85 * @param fileName a proposed or existing filename 85 * @param fileName a proposed or existing filename
86 * @param mimetypes The mimeTypes 86 * @param mimetypes The mimeTypes
87 */ 87 */
88OFileDialog::OFileDialog(const QString &caption, 88OFileDialog::OFileDialog(const QString &caption,
89 QWidget *wid, int mode, int selector, 89 QWidget *wid, int mode, int selector,
90 const QString &dirName, 90 const QString &dirName,
91 const QString &fileName, 91 const QString &fileName,
92 const QMap<QString,QStringList>& mimetypes ) 92 const QMap<QString,QStringList>& mimetypes )
93 : QDialog( wid, "OFileDialog", true ) 93 : QDialog( wid, "OFileDialog", true )
94{ 94{
95 // QVBoxLayout *lay = new QVBoxLayout(this); 95 // QVBoxLayout *lay = new QVBoxLayout(this);
96 //showMaximized(); 96 //showMaximized();
97 QVBoxLayout *lay = new QVBoxLayout(this ); 97 QVBoxLayout *lay = new QVBoxLayout(this );
98 file = new OFileSelector(this , mode, selector, 98 file = new OFileSelector(this , mode, selector,
99 dirName, fileName, 99 dirName, fileName,
100 mimetypes ); 100 mimetypes );
101 lay->addWidget( file ); 101 lay->addWidget( file );
102 102
103 //lay->addWidget( file ); 103 //lay->addWidget( file );
104 //showFullScreen(); 104 //showFullScreen();
105 setCaption( caption.isEmpty() ? tr("FileDialog") : caption ); 105 setCaption( caption.isEmpty() ? tr("FileDialog") : caption );
106 connect(file, SIGNAL(fileSelected(const QString&) ), 106 connect(file, SIGNAL(fileSelected(const QString&) ),
107 this, SLOT(slotFileSelected(const QString&) ) ); 107 this, SLOT(slotFileSelected(const QString&) ) );
108 connect(file, SIGNAL(ok() ), 108 connect(file, SIGNAL(ok() ),
109 this, SLOT(slotSelectorOk()) ) ; 109 this, SLOT(slotSelectorOk()) ) ;
110 110
111 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) ); 111 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) );
112 112
113#if 0 113#if 0
114 connect(file, SIGNAL(dirSelected(const QString&) ), 114 connect(file, SIGNAL(dirSelected(const QString&) ),
115 this, SLOT(slotDirSelected(const QString&) ) ); 115 this, SLOT(slotDirSelected(const QString&) ) );
116#endif 116#endif
117} 117}
118/** 118/**
119 * @returns the mimetype of the selected 119 * @returns the mimetype of the selected
120 * currently it return QString::null 120 * currently it return QString::null
121 */ 121 */
122QString OFileDialog::mimetype()const 122QString OFileDialog::mimetype()const
123{ 123{
124 return QString::null; 124 return QString::null;
125} 125}
126 126
127/** 127/**
128 * @return the fileName 128 * @return the fileName
129 */ 129 */
130QString OFileDialog::fileName()const 130QString OFileDialog::fileName()const
131{ 131{
132 return file->selectedName(); 132 return file->selectedName();
133} 133}
134 134
135/** 135/**
136 * return a DocLnk to the current file 136 * return a DocLnk to the current file
137 */ 137 */
138DocLnk OFileDialog::selectedDocument()const 138DocLnk OFileDialog::selectedDocument()const
139{ 139{
140 return file->selectedDocument(); 140 return file->selectedDocument();
141} 141}
142 142
143/** 143/**
144 * This opens up a filedialog in Open mode 144 * This opens up a filedialog in Open mode
145 * 145 *
146 * @param selector the Selector Mode 146 * @param selector the Selector Mode
147 * @param startDir Where to start from 147 * @param startDir Where to start from
148 * @param file A proposed filename 148 * @param file A proposed filename
149 * @param mimes A list of MimeTypes 149 * @param mimes A list of MimeTypes
150 * @param wid the parent 150 * @param wid the parent
151 * @param caption of the dialog if QString::null tr("Open") will be used 151 * @param caption of the dialog if QString::null tr("Open") will be used
152 * @return the fileName or QString::null 152 * @return the fileName or QString::null
153 */ 153 */
154QString OFileDialog::getOpenFileName(int selector, 154QString OFileDialog::getOpenFileName(int selector,
155 const QString &_startDir, 155 const QString &_startDir,
156 const QString &file, 156 const QString &file,
157 const MimeTypes &mimes, 157 const MimeTypes &mimes,
158 QWidget *wid, 158 QWidget *wid,
159 const QString &caption ) 159 const QString &caption )
160{ 160{
161 QString ret; 161 QString ret;
162 QString startDir = _startDir; 162 QString startDir = _startDir;
163 if (startDir.isEmpty() ) 163 if (startDir.isEmpty() )
164 startDir = lastUsedDir( "FileDialog-OPEN" ); 164 startDir = lastUsedDir( "FileDialog-OPEN" );
165 165
166 166
167 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, 167 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
168 wid, OFileSelector::Open, selector, startDir, file, mimes); 168 wid, OFileSelector::Open, selector, startDir, file, mimes);
169 dlg.showMaximized(); 169 dlg.showMaximized();
170 if( dlg.exec() ) 170 if( dlg.exec() )
171 { 171 {
172 ret = dlg.fileName(); 172 ret = dlg.fileName();
173 saveLastDir( "FileDialog-OPEN", ret ); 173 saveLastDir( "FileDialog-OPEN", ret );
174 } 174 }
175 175
176 return ret; 176 return ret;
177} 177}
178 178
179/** 179/**
180 * This opens up a file dialog in save mode 180 * This opens up a file dialog in save mode
181 * @see getOpenFileName 181 * @see getOpenFileName
182 */ 182 */
183QString OFileDialog::getSaveFileName(int selector, 183QString OFileDialog::getSaveFileName(int selector,
184 const QString &_startDir, 184 const QString &_startDir,
185 const QString &file, 185 const QString &file,
186 const MimeTypes &mimes, 186 const MimeTypes &mimes,
187 QWidget *wid, 187 QWidget *wid,
188 const QString &caption ) 188 const QString &caption )
189{ 189{
190 QString ret; 190 QString ret;
191 QString startDir = _startDir; 191 QString startDir = _startDir;
192 if (startDir.isEmpty() ) 192 if (startDir.isEmpty() )
193 startDir = lastUsedDir( "FileDialog-SAVE" ); 193 startDir = lastUsedDir( "FileDialog-SAVE" );
194 194
195 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, 195 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
196 wid, OFileSelector::Save, selector, startDir, file, mimes); 196 wid, OFileSelector::Save, selector, startDir, file, mimes);
197 dlg.showMaximized(); 197 dlg.showMaximized();
198 if( dlg.exec() ) 198 if( dlg.exec() )
199 { 199 {
200 ret = dlg.fileName(); 200 ret = dlg.fileName();
201 saveLastDir( "FileDialog-SAVE", ret ); 201 saveLastDir( "FileDialog-SAVE", ret );
202 } 202 }
203 203
204 return ret; 204 return ret;
205} 205}
206 206
207void OFileDialog::slotFileSelected(const QString & ) 207void OFileDialog::slotFileSelected(const QString & )
208{ 208{
209 accept(); 209 accept();
210} 210}
211 211
212void OFileDialog::slotSelectorOk( ) 212void OFileDialog::slotSelectorOk( )
213{ 213{
214 accept(); 214 accept();
215} 215}
216 216
217void OFileDialog::slotDirSelected(const QString &dir ) 217void OFileDialog::slotDirSelected(const QString &dir )
218{ 218{
219 setCaption( dir ); 219 setCaption( dir );
220 // if mode 220 // if mode
221 //accept(); 221 //accept();
222} 222}
diff --git a/libopie2/opieui/fileselector/ofiledialog.h b/libopie2/opieui/fileselector/ofiledialog.h
index 01a599b..dfecf3d 100644
--- a/libopie2/opieui/fileselector/ofiledialog.h
+++ b/libopie2/opieui/fileselector/ofiledialog.h
@@ -1,109 +1,110 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 zecke <zecke@handhelds.org> 3             .=l. Copyright (c) 2002 zecke <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#ifndef OFILEDIALOG_H 29#ifndef OFILEDIALOG_H
30#define OFILEDIALOG_H 30#define OFILEDIALOG_H
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/ofileselector.h> 33#include <opie2/ofileselector.h>
34 34
35/* QT */ 35/* QT */
36#include <qdialog.h> 36#include <qdialog.h>
37 37
38namespace Opie 38namespace Opie {
39{ 39namespace Ui {
40 40
41/** 41/**
42 * This class places a OFileSelector inside a QDialog. 42 * This class places a OFileSelector inside a QDialog.
43 * It provides static method for letting a user chose 43 * It provides static method for letting a user chose
44 * a file for either opening or saving. 44 * a file for either opening or saving.
45 * Most of the time the c'tor will not be used instead using 45 * Most of the time the c'tor will not be used instead using
46 * the static member functions is prefered. 46 * the static member functions is prefered.
47 * 47 *
48 * <pre> 48 * <pre>
49 * QMap<QString, QStringList> mimeTypes; 49 * QMap<QString, QStringList> mimeTypes;
50 * QStringList types; 50 * QStringList types;
51 * types << "text[slash]* "; 51 * types << "text[slash]* ";
52 * mimeTypes.insert( tr("Text"), types ); 52 * mimeTypes.insert( tr("Text"), types );
53 * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment 53 * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment
54 * QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 54 * QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
55 * "foo","bar", mimeTypes); 55 * "foo","bar", mimeTypes);
56 * </pre> 56 * </pre>
57 * 57 *
58 * @short A small QDialog swalloing a FileSelector 58 * @short A small QDialog swalloing a FileSelector
59 * @see QDialog 59 * @see QDialog
60 * @see OFileSelector 60 * @see OFileSelector
61 * @version 0.1-unfinished 61 * @version 0.1-unfinished
62 * @author Holger Freyther ( zecke@handhelds.org ) 62 * @author Holger Freyther ( zecke@handhelds.org )
63 */ 63 */
64class OFileDialog : public QDialog 64class OFileDialog : public QDialog
65{ 65{
66 Q_OBJECT 66 Q_OBJECT
67public: 67public:
68 OFileDialog(const QString &caption, 68 OFileDialog(const QString &caption,
69 QWidget *, int mode, int selector, 69 QWidget *, int mode, int selector,
70 const QString &dirName, 70 const QString &dirName,
71 const QString &fileName = QString::null, 71 const QString &fileName = QString::null,
72 const MimeTypes &mimetypes = MimeTypes() ); 72 const MimeTypes &mimetypes = MimeTypes() );
73 QString mimetype() const; 73 QString mimetype() const;
74 QString fileName() const; 74 QString fileName() const;
75 DocLnk selectedDocument()const; 75 DocLnk selectedDocument()const;
76 76
77 // static methods 77 // static methods
78 static QString getOpenFileName(int selector, 78 static QString getOpenFileName(int selector,
79 const QString& startDir = QString::null, 79 const QString& startDir = QString::null,
80 const QString &fileName = QString::null, 80 const QString &fileName = QString::null,
81 const MimeTypes& mime = MimeTypes(), 81 const MimeTypes& mime = MimeTypes(),
82 QWidget *wid = 0, 82 QWidget *wid = 0,
83 const QString &caption = QString::null ); 83 const QString &caption = QString::null );
84 84
85 static QString getSaveFileName(int selector, 85 static QString getSaveFileName(int selector,
86 const QString& startDir = QString::null, 86 const QString& startDir = QString::null,
87 const QString& fileName = QString::null, 87 const QString& fileName = QString::null,
88 const MimeTypes& mimefilter = MimeTypes(), 88 const MimeTypes& mimefilter = MimeTypes(),
89 QWidget *wid = 0, 89 QWidget *wid = 0,
90 const QString &caption = QString::null ); 90 const QString &caption = QString::null );
91 91
92 //let's OFileSelector catch up first 92 //let's OFileSelector catch up first
93 //static QString getExistingDirectory(const QString& startDir = QString::null, 93 //static QString getExistingDirectory(const QString& startDir = QString::null,
94 //QWidget *parent = 0, const QString& caption = QString::null ); 94 //QWidget *parent = 0, const QString& caption = QString::null );
95 95
96private: 96private:
97 class OFileDialogPrivate; 97 class OFileDialogPrivate;
98 OFileDialogPrivate *d; 98 OFileDialogPrivate *d;
99 OFileSelector *file; 99 OFileSelector *file;
100 100
101private slots: 101private slots:
102 void slotFileSelected( const QString & ); 102 void slotFileSelected( const QString & );
103 void slotDirSelected(const QString & ); 103 void slotDirSelected(const QString & );
104 void slotSelectorOk(); 104 void slotSelectorOk();
105}; 105};
106 106
107}; 107}
108}
108 109
109#endif 110#endif
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp
index 15cadd4..c4d5033 100644
--- a/libopie2/opieui/fileselector/ofileselector.cpp
+++ b/libopie2/opieui/fileselector/ofileselector.cpp
@@ -1,1166 +1,1173 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> 3             .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29/* hacky but we need to get FileSelector::filter */ 29/* hacky but we need to get FileSelector::filter */
30#define private public 30#define private public
31#include <qpe/fileselector.h> 31#include <qpe/fileselector.h>
32#undef private 32#undef private
33 33
34#include "ofileselector_p.h" 34#include "ofileselector_p.h"
35 35
36/* OPIE */ 36/* OPIE */
37#include <opie2/ofileselector.h> 37#include <opie2/ofileselector.h>
38 38
39#include <qpe/qpeapplication.h> 39#include <qpe/qpeapplication.h>
40#include <qpe/mimetype.h> 40#include <qpe/mimetype.h>
41#include <qpe/resource.h> 41#include <qpe/resource.h>
42#include <qpe/storage.h> 42#include <qpe/storage.h>
43 43
44/* QT */ 44/* QT */
45#include <qcombobox.h> 45#include <qcombobox.h>
46#include <qdir.h> 46#include <qdir.h>
47#include <qhbox.h> 47#include <qhbox.h>
48#include <qheader.h> 48#include <qheader.h>
49#include <qlabel.h> 49#include <qlabel.h>
50#include <qlayout.h> 50#include <qlayout.h>
51#include <qlineedit.h> 51#include <qlineedit.h>
52#include <qlistview.h> 52#include <qlistview.h>
53#include <qpopupmenu.h> 53#include <qpopupmenu.h>
54#include <qwidgetstack.h> 54#include <qwidgetstack.h>
55#include <qregexp.h> 55#include <qregexp.h>
56#include <qobjectlist.h> 56#include <qobjectlist.h>
57 57
58using namespace Opie; 58using namespace Opie::Ui::Private;
59 59
60namespace Opie {
61namespace Ui {
62namespace Private {
60OFileViewInterface::OFileViewInterface( OFileSelector* selector ) 63OFileViewInterface::OFileViewInterface( OFileSelector* selector )
61 : m_selector( selector ) 64 : m_selector( selector )
62{} 65{}
63 66
64OFileViewInterface::~OFileViewInterface() 67OFileViewInterface::~OFileViewInterface()
65{} 68{}
66 69
67QString OFileViewInterface::name()const 70QString OFileViewInterface::name()const
68{ 71{
69 return m_name; 72 return m_name;
70} 73}
71 74
72void OFileViewInterface::setName( const QString& name ) 75void OFileViewInterface::setName( const QString& name )
73{ 76{
74 m_name = name; 77 m_name = name;
75} 78}
76 79
77OFileSelector* OFileViewInterface::selector()const 80OFileSelector* OFileViewInterface::selector()const
78{ 81{
79 return m_selector; 82 return m_selector;
80} 83}
81 84
82DocLnk OFileViewInterface::selectedDocument()const 85DocLnk OFileViewInterface::selectedDocument()const
83{ 86{
84 return DocLnk( selectedName() ); 87 return DocLnk( selectedName() );
85} 88}
86 89
87bool OFileViewInterface::showNew()const 90bool OFileViewInterface::showNew()const
88{ 91{
89 return selector()->showNew(); 92 return selector()->showNew();
90} 93}
91 94
92bool OFileViewInterface::showClose()const 95bool OFileViewInterface::showClose()const
93{ 96{
94 return selector()->showClose(); 97 return selector()->showClose();
95} 98}
96 99
97MimeTypes OFileViewInterface::mimeTypes()const 100MimeTypes OFileViewInterface::mimeTypes()const
98{ 101{
99 return selector()->mimeTypes(); 102 return selector()->mimeTypes();
100} 103}
101 104
102QStringList OFileViewInterface::currentMimeType()const 105QStringList OFileViewInterface::currentMimeType()const
103{ 106{
104 return selector()->currentMimeType(); 107 return selector()->currentMimeType();
105} 108}
106 109
107void OFileViewInterface::activate( const QString& ) 110void OFileViewInterface::activate( const QString& )
108{ 111{
109 // not implemented here 112 // not implemented here
110} 113}
111 114
112void OFileViewInterface::ok() 115void OFileViewInterface::ok()
113{ 116{
114 emit selector()->ok(); 117 emit selector()->ok();
115} 118}
116 119
117void OFileViewInterface::cancel() 120void OFileViewInterface::cancel()
118{ 121{
119 emit selector()->cancel(); 122 emit selector()->cancel();
120} 123}
121 124
122void OFileViewInterface::closeMe() 125void OFileViewInterface::closeMe()
123{ 126{
124 emit selector()->closeMe(); 127 emit selector()->closeMe();
125} 128}
126 129
127void OFileViewInterface::fileSelected( const QString& str) 130void OFileViewInterface::fileSelected( const QString& str)
128{ 131{
129 emit selector()->fileSelected( str); 132 emit selector()->fileSelected( str);
130} 133}
131 134
132void OFileViewInterface::fileSelected( const DocLnk& lnk) 135void OFileViewInterface::fileSelected( const DocLnk& lnk)
133{ 136{
134 emit selector()->fileSelected( lnk ); 137 emit selector()->fileSelected( lnk );
135} 138}
136 139
137void OFileViewInterface::setCurrentFileName( const QString& str ) 140void OFileViewInterface::setCurrentFileName( const QString& str )
138{ 141{
139 selector()->m_lneEdit->setText( str ); 142 selector()->m_lneEdit->setText( str );
140} 143}
141 144
142QString OFileViewInterface::currentFileName()const 145QString OFileViewInterface::currentFileName()const
143{ 146{
144 return selector()->m_lneEdit->text(); 147 return selector()->m_lneEdit->text();
145} 148}
146 149
147QString OFileViewInterface::startDirectory()const 150QString OFileViewInterface::startDirectory()const
148{ 151{
149 return selector()->m_startDir; 152 return selector()->m_startDir;
150} 153}
151 154
152ODocumentFileView::ODocumentFileView( OFileSelector* selector ) 155ODocumentFileView::ODocumentFileView( OFileSelector* selector )
153 :OFileViewInterface( selector ) 156 :OFileViewInterface( selector )
154{ 157{
155 m_selector = 0; 158 m_selector = 0;
156 setName( QObject::tr("Documents") ); 159 setName( QObject::tr("Documents") );
157} 160}
158 161
159ODocumentFileView::~ODocumentFileView() 162ODocumentFileView::~ODocumentFileView()
160{ 163{
161} 164}
162 165
163QString ODocumentFileView::selectedName()const 166QString ODocumentFileView::selectedName()const
164{ 167{
165 if (!m_selector) 168 if (!m_selector)
166 return QString::null; 169 return QString::null;
167 170
168 return m_selector->selectedDocument().file(); 171 return m_selector->selectedDocument().file();
169} 172}
170 173
171QString ODocumentFileView::selectedPath()const 174QString ODocumentFileView::selectedPath()const
172{ 175{
173 return QPEApplication::documentDir(); 176 return QPEApplication::documentDir();
174} 177}
175 178
176QString ODocumentFileView::directory()const 179QString ODocumentFileView::directory()const
177{ 180{
178 return selectedPath(); 181 return selectedPath();
179} 182}
180 183
181void ODocumentFileView::reread() 184void ODocumentFileView::reread()
182{ 185{
183 if (!m_selector) 186 if (!m_selector)
184 return; 187 return;
185 188
186 m_selector->setNewVisible( showNew() ); 189 m_selector->setNewVisible( showNew() );
187 m_selector->setCloseVisible( showClose() ); 190 m_selector->setCloseVisible( showClose() );
188 m_selector->filter = currentMimeType().join(";"); 191 m_selector->filter = currentMimeType().join(";");
189 m_selector->reread(); 192 m_selector->reread();
190} 193}
191 194
192int ODocumentFileView::fileCount()const 195int ODocumentFileView::fileCount()const
193{ 196{
194 if (!m_selector) 197 if (!m_selector)
195 return -1; 198 return -1;
196 199
197 return m_selector->fileCount(); 200 return m_selector->fileCount();
198} 201}
199 202
200DocLnk ODocumentFileView::selectedDocument()const 203DocLnk ODocumentFileView::selectedDocument()const
201{ 204{
202 if (!m_selector) 205 if (!m_selector)
203 return DocLnk(); 206 return DocLnk();
204 207
205 return m_selector->selectedDocument(); 208 return m_selector->selectedDocument();
206} 209}
207 210
208QWidget* ODocumentFileView::widget( QWidget* parent ) 211QWidget* ODocumentFileView::widget( QWidget* parent )
209{ 212{
210 if (!m_selector ) 213 if (!m_selector )
211 { 214 {
212 m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); 215 m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() );
213 QObject::connect(m_selector, SIGNAL(fileSelected(const DocLnk&) ), 216 QObject::connect(m_selector, SIGNAL(fileSelected(const DocLnk&) ),
214 selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); 217 selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) );
215 QObject::connect(m_selector, SIGNAL(closeMe() ), 218 QObject::connect(m_selector, SIGNAL(closeMe() ),
216 selector(), SIGNAL(closeMe() ) ); 219 selector(), SIGNAL(closeMe() ) );
217 QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk&) ), 220 QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk&) ),
218 selector(), SIGNAL(newSelected(const DocLnk&) ) ); 221 selector(), SIGNAL(newSelected(const DocLnk&) ) );
219 } 222 }
220 223
221 return m_selector; 224 return m_selector;
222} 225}
223 226
224/* 227/*
225 * This is the file system view used 228 * This is the file system view used
226 * we use a QListView + QListViewItems for it 229 * we use a QListView + QListViewItems for it
227 */ 230 */
228 231
229OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, 232OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap,
230 const QString& path, const QString& date, 233 const QString& path, const QString& date,
231 const QString& size, const QString& dir, 234 const QString& size, const QString& dir,
232 bool isLocked, bool isDir ) 235 bool isLocked, bool isDir )
233 : QListViewItem( view ) 236 : QListViewItem( view )
234{ 237{
235 setPixmap(0, pixmap ); 238 setPixmap(0, pixmap );
236 setText(1, path ); 239 setText(1, path );
237 setText(2, size ); 240 setText(2, size );
238 setText(3, date ); 241 setText(3, date );
239 m_isDir = isDir; 242 m_isDir = isDir;
240 m_dir = dir; 243 m_dir = dir;
241 m_locked = isLocked; 244 m_locked = isLocked;
242} 245}
243 246
244OFileSelectorItem::~OFileSelectorItem() 247OFileSelectorItem::~OFileSelectorItem()
245{ 248{
246} 249}
247 250
248bool OFileSelectorItem::isLocked()const 251bool OFileSelectorItem::isLocked()const
249{ 252{
250 return m_locked; 253 return m_locked;
251} 254}
252 255
253QString OFileSelectorItem::directory()const 256QString OFileSelectorItem::directory()const
254{ 257{
255 return m_dir; 258 return m_dir;
256} 259}
257 260
258bool OFileSelectorItem::isDir()const 261bool OFileSelectorItem::isDir()const
259{ 262{
260 return m_isDir; 263 return m_isDir;
261} 264}
262 265
263QString OFileSelectorItem::path()const 266QString OFileSelectorItem::path()const
264{ 267{
265 return text( 1 ); 268 return text( 1 );
266} 269}
267 270
268QString OFileSelectorItem::key( int id, bool )const 271QString OFileSelectorItem::key( int id, bool )const
269{ 272{
270 QString ke; 273 QString ke;
271 if( id == 0 || id == 1 ) 274 if( id == 0 || id == 1 )
272 { // name 275 { // name
273 if( m_isDir ) 276 if( m_isDir )
274 { 277 {
275 ke.append("0" ); 278 ke.append("0" );
276 ke.append( text(1) ); 279 ke.append( text(1) );
277 } 280 }
278 else 281 else
279 { 282 {
280 ke.append("1" ); 283 ke.append("1" );
281 ke.append( text(1) ); 284 ke.append( text(1) );
282 } 285 }
283 return ke; 286 return ke;
284 } 287 }
285 else 288 else
286 return text( id ); 289 return text( id );
287 290
288} 291}
289 292
290OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel) 293OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel)
291 :QWidget( parent ), m_sel( sel ) 294 :QWidget( parent ), m_sel( sel )
292{ 295{
293 m_all = false; 296 m_all = false;
294 QVBoxLayout* lay = new QVBoxLayout( this ); 297 QVBoxLayout* lay = new QVBoxLayout( this );
295 m_currentDir = startDir; 298 m_currentDir = startDir;
296 299
297 /* 300 /*
298 * now we add a special bar 301 * now we add a special bar
299 * One Button For Up 302 * One Button For Up
300 * Home 303 * Home
301 * Doc 304 * Doc
302 * And a dropdown menu with FileSystems 305 * And a dropdown menu with FileSystems
303 * FUTURE: one to change dir with lineedit 306 * FUTURE: one to change dir with lineedit
304 * Bookmarks 307 * Bookmarks
305 * Create Dir 308 * Create Dir
306 */ 309 */
307 QHBox* box = new QHBox(this ); 310 QHBox* box = new QHBox(this );
308 box->setBackgroundMode( PaletteButton ); 311 box->setBackgroundMode( PaletteButton );
309 box->setSpacing( 0 ); 312 box->setSpacing( 0 );
310 313
311 QToolButton *btn = new QToolButton( box ); 314 QToolButton *btn = new QToolButton( box );
312 btn->setIconSet( Resource::loadIconSet("up") ); 315 btn->setIconSet( Resource::loadIconSet("up") );
313 connect(btn, SIGNAL(clicked() ), 316 connect(btn, SIGNAL(clicked() ),
314 this, SLOT( cdUP() ) ); 317 this, SLOT( cdUP() ) );
315 318
316 btn = new QToolButton( box ); 319 btn = new QToolButton( box );
317 btn->setIconSet( Resource::loadIconSet("home") ); 320 btn->setIconSet( Resource::loadIconSet("home") );
318 connect(btn, SIGNAL(clicked() ), 321 connect(btn, SIGNAL(clicked() ),
319 this, SLOT( cdHome() ) ); 322 this, SLOT( cdHome() ) );
320 323
321 btn = new QToolButton( box ); 324 btn = new QToolButton( box );
322 btn->setIconSet( Resource::loadIconSet("DocsIcon") ); 325 btn->setIconSet( Resource::loadIconSet("DocsIcon") );
323 connect(btn, SIGNAL(clicked() ), 326 connect(btn, SIGNAL(clicked() ),
324 this, SLOT(cdDoc() ) ); 327 this, SLOT(cdDoc() ) );
325 328
326 m_btnNew = new QToolButton( box ); 329 m_btnNew = new QToolButton( box );
327 m_btnNew->setIconSet( Resource::loadIconSet("new") ); 330 m_btnNew->setIconSet( Resource::loadIconSet("new") );
328 connect(m_btnNew, SIGNAL(clicked() ), 331 connect(m_btnNew, SIGNAL(clicked() ),
329 this, SLOT(slotNew() ) ); 332 this, SLOT(slotNew() ) );
330 333
331 334
332 m_btnClose = new QToolButton( box ); 335 m_btnClose = new QToolButton( box );
333 m_btnClose->setIconSet( Resource::loadIconSet("close") ); 336 m_btnClose->setIconSet( Resource::loadIconSet("close") );
334 connect(m_btnClose, SIGNAL(clicked() ), 337 connect(m_btnClose, SIGNAL(clicked() ),
335 selector(), SIGNAL(closeMe() ) ); 338 selector(), SIGNAL(closeMe() ) );
336 339
337 btn = new QToolButton( box ); 340 btn = new QToolButton( box );
338 btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") ); 341 btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") );
339 342
340 /* let's fill device parts */ 343 /* let's fill device parts */
341 QPopupMenu* pop = new QPopupMenu(this); 344 QPopupMenu* pop = new QPopupMenu(this);
342 connect(pop, SIGNAL( activated(int) ), 345 connect(pop, SIGNAL( activated(int) ),
343 this, SLOT(slotFSActivated(int) ) ); 346 this, SLOT(slotFSActivated(int) ) );
344 347
345 StorageInfo storage; 348 StorageInfo storage;
346 const QList<FileSystem> &fs = storage.fileSystems(); 349 const QList<FileSystem> &fs = storage.fileSystems();
347 QListIterator<FileSystem> it(fs); 350 QListIterator<FileSystem> it(fs);
348 for ( ; it.current(); ++it ) 351 for ( ; it.current(); ++it )
349 { 352 {
350 const QString disk = (*it)->name(); 353 const QString disk = (*it)->name();
351 const QString path = (*it)->path(); 354 const QString path = (*it)->path();
352 m_dev.insert( disk, path ); 355 m_dev.insert( disk, path );
353 pop->insertItem( disk ); 356 pop->insertItem( disk );
354 } 357 }
355 m_fsPop = pop; 358 m_fsPop = pop;
356 359
357 360
358 btn->setPopup( pop ); 361 btn->setPopup( pop );
359 362
360 lay->addWidget( box ); 363 lay->addWidget( box );
361 364
362 m_view = new QListView( this ); 365 m_view = new QListView( this );
363 366
364 m_view->installEventFilter(this); 367 m_view->installEventFilter(this);
365 368
366 QPEApplication::setStylusOperation( m_view->viewport(), 369 QPEApplication::setStylusOperation( m_view->viewport(),
367 QPEApplication::RightOnHold); 370 QPEApplication::RightOnHold);
368 m_view->addColumn(" " ); 371 m_view->addColumn(" " );
369 m_view->addColumn(tr("Name"), 135 ); 372 m_view->addColumn(tr("Name"), 135 );
370 m_view->addColumn(tr("Size"), -1 ); 373 m_view->addColumn(tr("Size"), -1 );
371 m_view->addColumn(tr("Date"), 60 ); 374 m_view->addColumn(tr("Date"), 60 );
372 m_view->addColumn(tr("Mime Type"), -1 ); 375 m_view->addColumn(tr("Mime Type"), -1 );
373 376
374 377
375 m_view->setSorting( 1 ); 378 m_view->setSorting( 1 );
376 m_view->setAllColumnsShowFocus( TRUE ); 379 m_view->setAllColumnsShowFocus( TRUE );
377 380
378 lay->addWidget( m_view, 1000 ); 381 lay->addWidget( m_view, 1000 );
379 connectSlots(); 382 connectSlots();
380} 383}
381 384
382OFileViewFileListView::~OFileViewFileListView() 385OFileViewFileListView::~OFileViewFileListView()
383{ 386{
384} 387}
385 388
386void OFileViewFileListView::slotNew() 389void OFileViewFileListView::slotNew()
387{ 390{
388 DocLnk lnk; 391 DocLnk lnk;
389 emit selector()->newSelected( lnk ); 392 emit selector()->newSelected( lnk );
390} 393}
391 394
392OFileSelectorItem* OFileViewFileListView::currentItem()const 395OFileSelectorItem* OFileViewFileListView::currentItem()const
393{ 396{
394 QListViewItem* item = m_view->currentItem(); 397 QListViewItem* item = m_view->currentItem();
395 if (!item ) 398 if (!item )
396 return 0l; 399 return 0l;
397 400
398 return static_cast<OFileSelectorItem*>(item); 401 return static_cast<OFileSelectorItem*>(item);
399} 402}
400 403
401void OFileViewFileListView::reread( bool all ) 404void OFileViewFileListView::reread( bool all )
402{ 405{
403 m_view->clear(); 406 m_view->clear();
404 407
405 if (selector()->showClose() ) 408 if (selector()->showClose() )
406 m_btnClose->show(); 409 m_btnClose->show();
407 else 410 else
408 m_btnClose->hide(); 411 m_btnClose->hide();
409 412
410 if (selector()->showNew() ) 413 if (selector()->showNew() )
411 m_btnNew->show(); 414 m_btnNew->show();
412 else 415 else
413 m_btnNew->hide(); 416 m_btnNew->hide();
414 417
415 m_mimes = selector()->currentMimeType(); 418 m_mimes = selector()->currentMimeType();
416 m_all = all; 419 m_all = all;
417 420
418 QDir dir( m_currentDir ); 421 QDir dir( m_currentDir );
419 if (!dir.exists() ) 422 if (!dir.exists() )
420 return; 423 return;
421 424
422 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); 425 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed );
423 int filter; 426 int filter;
424 if (m_all ) 427 if (m_all )
425 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; 428 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
426 else 429 else
427 filter = QDir::Files | QDir::Dirs | QDir::All; 430 filter = QDir::Files | QDir::Dirs | QDir::All;
428 dir.setFilter( filter ); 431 dir.setFilter( filter );
429 432
430 // now go through all files 433 // now go through all files
431 const QFileInfoList *list = dir.entryInfoList(); 434 const QFileInfoList *list = dir.entryInfoList();
432 if (!list) 435 if (!list)
433 { 436 {
434 cdUP(); 437 cdUP();
435 return; 438 return;
436 } 439 }
437 440
438 QFileInfoListIterator it( *list ); 441 QFileInfoListIterator it( *list );
439 QFileInfo *fi; 442 QFileInfo *fi;
440 while( (fi=it.current() ) ) 443 while( (fi=it.current() ) )
441 { 444 {
442 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) 445 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") )
443 { 446 {
444 ++it; 447 ++it;
445 continue; 448 continue;
446 } 449 }
447 450
448 /* 451 /*
449 * It is a symlink we try to resolve it now but don't let us attack by DOS 452 * It is a symlink we try to resolve it now but don't let us attack by DOS
450 * 453 *
451 */ 454 */
452 if( fi->isSymLink() ) 455 if( fi->isSymLink() )
453 { 456 {
454 QString file = fi->dirPath( true ) + "/" + fi->readLink(); 457 QString file = fi->dirPath( true ) + "/" + fi->readLink();
455 for( int i = 0; i<=4; i++) 458 for( int i = 0; i<=4; i++)
456 { // 5 tries to prevent dos 459 { // 5 tries to prevent dos
457 QFileInfo info( file ); 460 QFileInfo info( file );
458 if( !info.exists() ) 461 if( !info.exists() )
459 { 462 {
460 addSymlink( fi, TRUE ); 463 addSymlink( fi, TRUE );
461 break; 464 break;
462 } 465 }
463 else if( info.isDir() ) 466 else if( info.isDir() )
464 { 467 {
465 addDir( fi, TRUE ); 468 addDir( fi, TRUE );
466 break; 469 break;
467 } 470 }
468 else if( info.isFile() ) 471 else if( info.isFile() )
469 { 472 {
470 addFile( fi, TRUE ); 473 addFile( fi, TRUE );
471 break; 474 break;
472 } 475 }
473 else if( info.isSymLink() ) 476 else if( info.isSymLink() )
474 { 477 {
475 file = info.dirPath(true ) + "/" + info.readLink() ; 478 file = info.dirPath(true ) + "/" + info.readLink() ;
476 break; 479 break;
477 } 480 }
478 else if( i == 4) 481 else if( i == 4)
479 { // couldn't resolve symlink add it as symlink 482 { // couldn't resolve symlink add it as symlink
480 addSymlink( fi ); 483 addSymlink( fi );
481 } 484 }
482 } // off for loop for symlink resolving 485 } // off for loop for symlink resolving
483 } 486 }
484 else if( fi->isDir() ) 487 else if( fi->isDir() )
485 addDir( fi ); 488 addDir( fi );
486 else if( fi->isFile() ) 489 else if( fi->isFile() )
487 addFile( fi ); 490 addFile( fi );
488 491
489 ++it; 492 ++it;
490 } // of while loop 493 } // of while loop
491 m_view->sort(); 494 m_view->sort();
492 495
493} 496}
494int OFileViewFileListView::fileCount()const 497int OFileViewFileListView::fileCount()const
495{ 498{
496 return m_view->childCount(); 499 return m_view->childCount();
497} 500}
498 501
499QString OFileViewFileListView::currentDir()const 502QString OFileViewFileListView::currentDir()const
500{ 503{
501 return m_currentDir; 504 return m_currentDir;
502} 505}
503 506
504OFileSelector* OFileViewFileListView::selector() 507OFileSelector* OFileViewFileListView::selector()
505{ 508{
506 return m_sel; 509 return m_sel;
507} 510}
508 511
509bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) 512bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e)
510{ 513{
511 if ( e->type() == QEvent::KeyPress ) 514 if ( e->type() == QEvent::KeyPress )
512 { 515 {
513 QKeyEvent *k = (QKeyEvent *)e; 516 QKeyEvent *k = (QKeyEvent *)e;
514 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) 517 if ( (k->key()==Key_Enter) || (k->key()==Key_Return))
515 { 518 {
516 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); 519 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0);
517 return true; 520 return true;
518 } 521 }
519 } 522 }
520 return false; 523 return false;
521} 524}
522 525
523void OFileViewFileListView::connectSlots() 526void OFileViewFileListView::connectSlots()
524{ 527{
525 connect(m_view, SIGNAL(clicked(QListViewItem*) ), 528 connect(m_view, SIGNAL(clicked(QListViewItem*) ),
526 this, SLOT(slotCurrentChanged(QListViewItem*) ) ); 529 this, SLOT(slotCurrentChanged(QListViewItem*) ) );
527 connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), 530 connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ),
528 this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); 531 this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) );
529} 532}
530 533
531void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) 534void OFileViewFileListView::slotCurrentChanged( QListViewItem* item)
532{ 535{
533 if (!item) 536 if (!item)
534 return; 537 return;
535#if 0 538#if 0
536 539
537 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); 540 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
538 541
539 if (!sel->isDir() ) 542 if (!sel->isDir() )
540 { 543 {
541 selector()->m_lneEdit->setText( sel->text(1) ); 544 selector()->m_lneEdit->setText( sel->text(1) );
542 // if in fileselector mode we will emit selected 545 // if in fileselector mode we will emit selected
543 if ( selector()->mode() == OFileSelector::FileSelector ) 546 if ( selector()->mode() == OFileSelector::FileSelector )
544 { 547 {
545 qWarning("slot Current Changed"); 548 qWarning("slot Current Changed");
546 QStringList str = QStringList::split("->", sel->text(1) ); 549 QStringList str = QStringList::split("->", sel->text(1) );
547 QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); 550 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
548 emit selector()->fileSelected( path ); 551 emit selector()->fileSelected( path );
549 DocLnk lnk( path ); 552 DocLnk lnk( path );
550 emit selector()->fileSelected( lnk ); 553 emit selector()->fileSelected( lnk );
551 } 554 }
552 } 555 }
553#endif 556#endif
554} 557}
555 558
556void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) 559void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int )
557{ 560{
558 if (!item || ( button != Qt::LeftButton) ) 561 if (!item || ( button != Qt::LeftButton) )
559 return; 562 return;
560 563
561 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); 564 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
562 if (!sel->isLocked() ) 565 if (!sel->isLocked() )
563 { 566 {
564 QStringList str = QStringList::split("->", sel->text(1) ); 567 QStringList str = QStringList::split("->", sel->text(1) );
565 if (sel->isDir() ) 568 if (sel->isDir() )
566 { 569 {
567 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); 570 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace();
568 emit selector()->dirSelected( m_currentDir ); 571 emit selector()->dirSelected( m_currentDir );
569 reread( m_all ); 572 reread( m_all );
570 } 573 }
571 else 574 else
572 { // file 575 { // file
573 qWarning("slot Clicked"); 576 qWarning("slot Clicked");
574 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); 577 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() );
575 QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); 578 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
576 emit selector()->fileSelected( path ); 579 emit selector()->fileSelected( path );
577 DocLnk lnk( path ); 580 DocLnk lnk( path );
578 emit selector()->fileSelected( lnk ); 581 emit selector()->fileSelected( lnk );
579 } 582 }
580 } // not locked 583 } // not locked
581} 584}
582 585
583void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) 586void OFileViewFileListView::addFile( QFileInfo* info, bool symlink )
584{ 587{
585 MimeType type( info->absFilePath() ); 588 MimeType type( info->absFilePath() );
586 if (!compliesMime( type.id() ) ) 589 if (!compliesMime( type.id() ) )
587 return; 590 return;
588 591
589 QPixmap pix = type.pixmap(); 592 QPixmap pix = type.pixmap();
590 QString dir, name; bool locked; 593 QString dir, name; bool locked;
591 if ( pix.isNull() ) 594 if ( pix.isNull() )
592 { 595 {
593 QWMatrix matrix; 596 QWMatrix matrix;
594 QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); 597 QPixmap pixer(Resource::loadPixmap("UnknownDocument") );
595 matrix.scale( .4, .4 ); 598 matrix.scale( .4, .4 );
596 pix = pixer.xForm( matrix ); 599 pix = pixer.xForm( matrix );
597 } 600 }
598 dir = info->dirPath( true ); 601 dir = info->dirPath( true );
599 locked = false; 602 locked = false;
600 if ( symlink ) 603 if ( symlink )
601 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); 604 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
602 else 605 else
603 { 606 {
604 name = info->fileName(); 607 name = info->fileName();
605 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || 608 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
606 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) 609 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) )
607 { 610 {
608 locked = true; pix = Resource::loadPixmap("locked"); 611 locked = true; pix = Resource::loadPixmap("locked");
609 } 612 }
610 } 613 }
611 (void)new OFileSelectorItem( m_view, pix, name, 614 (void)new OFileSelectorItem( m_view, pix, name,
612 info->lastModified().toString(), QString::number( info->size() ), 615 info->lastModified().toString(), QString::number( info->size() ),
613 dir, locked ); 616 dir, locked );
614} 617}
615 618
616void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) 619void OFileViewFileListView::addDir( QFileInfo* info, bool symlink )
617{ 620{
618 bool locked = false; QString name; QPixmap pix; 621 bool locked = false; QString name; QPixmap pix;
619 622
620 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || 623 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) ||
621 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) 624 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) )
622 { 625 {
623 locked = true; 626 locked = true;
624 if ( symlink ) 627 if ( symlink )
625 pix = Resource::loadPixmap( "opie/symlink" ); 628 pix = Resource::loadPixmap( "opie/symlink" );
626 else 629 else
627 pix = Resource::loadPixmap( "lockedfolder" ); 630 pix = Resource::loadPixmap( "lockedfolder" );
628 } 631 }
629 else 632 else
630 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); 633 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder");
631 634
632 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : 635 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() :
633 info->fileName(); 636 info->fileName();
634 637
635 (void)new OFileSelectorItem( m_view, pix, name, 638 (void)new OFileSelectorItem( m_view, pix, name,
636 info->lastModified().toString(), 639 info->lastModified().toString(),
637 QString::number( info->size() ), 640 QString::number( info->size() ),
638 info->dirPath( true ), locked, true ); 641 info->dirPath( true ), locked, true );
639 642
640 643
641} 644}
642 645
643void OFileViewFileListView::addSymlink( QFileInfo* , bool ) 646void OFileViewFileListView::addSymlink( QFileInfo* , bool )
644{ 647{
645} 648}
646 649
647void OFileViewFileListView::cdUP() 650void OFileViewFileListView::cdUP()
648{ 651{
649 QDir dir( m_currentDir ); 652 QDir dir( m_currentDir );
650 dir.cdUp(); 653 dir.cdUp();
651 654
652 if (!dir.exists() ) 655 if (!dir.exists() )
653 m_currentDir = "/"; 656 m_currentDir = "/";
654 else 657 else
655 m_currentDir = dir.absPath(); 658 m_currentDir = dir.absPath();
656 659
657 emit selector()->dirSelected( m_currentDir ); 660 emit selector()->dirSelected( m_currentDir );
658 reread( m_all ); 661 reread( m_all );
659} 662}
660 663
661void OFileViewFileListView::cdHome() 664void OFileViewFileListView::cdHome()
662{ 665{
663 m_currentDir = QDir::homeDirPath(); 666 m_currentDir = QDir::homeDirPath();
664 emit selector()->dirSelected( m_currentDir ); 667 emit selector()->dirSelected( m_currentDir );
665 reread( m_all ); 668 reread( m_all );
666} 669}
667 670
668void OFileViewFileListView::cdDoc() 671void OFileViewFileListView::cdDoc()
669{ 672{
670 m_currentDir = QPEApplication::documentDir(); 673 m_currentDir = QPEApplication::documentDir();
671 emit selector()->dirSelected( m_currentDir ); 674 emit selector()->dirSelected( m_currentDir );
672 reread( m_all ); 675 reread( m_all );
673} 676}
674 677
675void OFileViewFileListView::changeDir( const QString& dir ) 678void OFileViewFileListView::changeDir( const QString& dir )
676{ 679{
677 m_currentDir = dir; 680 m_currentDir = dir;
678 emit selector()->dirSelected( m_currentDir ); 681 emit selector()->dirSelected( m_currentDir );
679 reread( m_all ); 682 reread( m_all );
680} 683}
681 684
682void OFileViewFileListView::slotFSActivated( int id ) 685void OFileViewFileListView::slotFSActivated( int id )
683{ 686{
684 changeDir ( m_dev[m_fsPop->text(id)] ); 687 changeDir ( m_dev[m_fsPop->text(id)] );
685} 688}
686 689
687/* check if the mimetype in mime 690/* check if the mimetype in mime
688 * complies with the one which is current 691 * complies with the one which is current
689 */ 692 */
690/* 693/*
691 * We've the mimetype of the file 694 * We've the mimetype of the file
692 * We need to get the stringlist of the current mimetype 695 * We need to get the stringlist of the current mimetype
693 * 696 *
694 * mime = image@slashjpeg 697 * mime = image@slashjpeg
695 * QStringList = 'image@slash*' 698 * QStringList = 'image@slash*'
696 * or QStringList = image/jpeg;image/png;application/x-ogg 699 * or QStringList = image/jpeg;image/png;application/x-ogg
697 * or QStringList = application/x-ogg;image@slash*; 700 * or QStringList = application/x-ogg;image@slash*;
698 * with all these mime filters it should get acceptes 701 * with all these mime filters it should get acceptes
699 * to do so we need to look if mime is contained inside 702 * to do so we need to look if mime is contained inside
700 * the stringlist 703 * the stringlist
701 * if it's contained return true 704 * if it's contained return true
702 * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' 705 * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*'
703 * is contained in the mimefilter and then we will 706 * is contained in the mimefilter and then we will
704 * look if both are equal until the '/' 707 * look if both are equal until the '/'
705 */ 708 */
706 709
707bool OFileViewFileListView::compliesMime( const QString& str) 710bool OFileViewFileListView::compliesMime( const QString& str)
708{ 711{
709 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) 712 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() )
710 return true; 713 return true;
711 714
712 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) 715 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it )
713 { 716 {
714 QRegExp reg( (*it) ); 717 QRegExp reg( (*it) );
715 reg.setWildcard( true ); 718 reg.setWildcard( true );
716 if ( str.find( reg ) != -1 ) 719 if ( str.find( reg ) != -1 )
717 return true; 720 return true;
718 721
719 } 722 }
720 return false; 723 return false;
721} 724}
722/* 725/*
723 * The listView giving access to the file system! 726 * The listView giving access to the file system!
724 */ 727 */
725 728
726class OFileViewFileSystem : public OFileViewInterface 729class OFileViewFileSystem : public OFileViewInterface
727{ 730{
728public: 731public:
729 OFileViewFileSystem( OFileSelector* ); 732 OFileViewFileSystem( OFileSelector* );
730 ~OFileViewFileSystem(); 733 ~OFileViewFileSystem();
731 734
732 QString selectedName() const; 735 QString selectedName() const;
733 QString selectedPath() const; 736 QString selectedPath() const;
734 737
735 QString directory()const; 738 QString directory()const;
736 void reread(); 739 void reread();
737 int fileCount()const; 740 int fileCount()const;
738 741
739 QWidget* widget( QWidget* parent ); 742 QWidget* widget( QWidget* parent );
740 void activate( const QString& ); 743 void activate( const QString& );
741private: 744private:
742 OFileViewFileListView* m_view; 745 OFileViewFileListView* m_view;
743 bool m_all : 1; 746 bool m_all : 1;
744}; 747};
745 748
746OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) 749OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel)
747 : OFileViewInterface( sel ) 750 : OFileViewInterface( sel )
748{ 751{
749 m_view = 0; 752 m_view = 0;
750 m_all = false; 753 m_all = false;
751} 754}
752 755
753OFileViewFileSystem::~OFileViewFileSystem() 756OFileViewFileSystem::~OFileViewFileSystem()
754{ 757{
755} 758}
756 759
757QString OFileViewFileSystem::selectedName()const 760QString OFileViewFileSystem::selectedName()const
758{ 761{
759 if (!m_view ) 762 if (!m_view )
760 return QString::null; 763 return QString::null;
761 764
762 QString cFN=currentFileName(); 765 QString cFN=currentFileName();
763 if (cFN.startsWith("/")) return cFN; 766 if (cFN.startsWith("/")) return cFN;
764 return m_view->currentDir() + "/" + cFN; 767 return m_view->currentDir() + "/" + cFN;
765} 768}
766 769
767QString OFileViewFileSystem::selectedPath()const 770QString OFileViewFileSystem::selectedPath()const
768{ 771{
769 return QString::null; 772 return QString::null;
770} 773}
771 774
772QString OFileViewFileSystem::directory()const 775QString OFileViewFileSystem::directory()const
773{ 776{
774 if (!m_view) 777 if (!m_view)
775 return QString::null; 778 return QString::null;
776 779
777 OFileSelectorItem* item = m_view->currentItem(); 780 OFileSelectorItem* item = m_view->currentItem();
778 if (!item ) 781 if (!item )
779 return QString::null; 782 return QString::null;
780 783
781 return QDir(item->directory() ).absPath(); 784 return QDir(item->directory() ).absPath();
782} 785}
783 786
784void OFileViewFileSystem::reread() 787void OFileViewFileSystem::reread()
785{ 788{
786 if (!m_view) 789 if (!m_view)
787 return; 790 return;
788 791
789 m_view->reread( m_all ); 792 m_view->reread( m_all );
790} 793}
791 794
792int OFileViewFileSystem::fileCount()const 795int OFileViewFileSystem::fileCount()const
793{ 796{
794 if (!m_view ) 797 if (!m_view )
795 return -1; 798 return -1;
796 return m_view->fileCount(); 799 return m_view->fileCount();
797} 800}
798 801
799QWidget* OFileViewFileSystem::widget( QWidget* parent ) 802QWidget* OFileViewFileSystem::widget( QWidget* parent )
800{ 803{
801 if (!m_view ) 804 if (!m_view )
802 { 805 {
803 m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); 806 m_view = new OFileViewFileListView( parent, startDirectory(), selector() );
804 } 807 }
805 return m_view; 808 return m_view;
806} 809}
807 810
808void OFileViewFileSystem::activate( const QString& str) 811void OFileViewFileSystem::activate( const QString& str)
809{ 812{
810 m_all = (str != QObject::tr("Files") ); 813 m_all = (str != QObject::tr("Files") );
811} 814}
812 815
816
817}
813/* Selector */ 818/* Selector */
814/** 819/**
815 * @short new and complete c'tor 820 * @short new and complete c'tor
816 * 821 *
817 * Create a OFileSelector to let the user select a file. It can 822 * Create a OFileSelector to let the user select a file. It can
818 * either be used to open a file, select a save name in a dir or 823 * either be used to open a file, select a save name in a dir or
819 * as a dropin for the FileSelector. 824 * as a dropin for the FileSelector.
820 * 825 *
821 * <pre> 826 * <pre>
822 * QMap<QString, QStringList> mimeTypes; 827 * QMap<QString, QStringList> mimeTypes;
823 * QStringList types; 828 * QStringList types;
824 * types << "text@slash* "; 829 * types << "text@slash* ";
825 * types << "audio@slash*"; 830 * types << "audio@slash*";
826 * mimeTypes.insert( tr("Audio and Text"), types ); 831 * mimeTypes.insert( tr("Audio and Text"), types );
827 * mimeTypes.insert( tr("All"), "*@slash*); 832 * mimeTypes.insert( tr("All"), "*@slash*);
828 * 833 *
829 * now you could create your fileselector 834 * now you could create your fileselector
830 * </pre> 835 * </pre>
831 * 836 *
832 * 837 *
833 * @param parent the parent of this widget 838 * @param parent the parent of this widget
834 * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) 839 * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR)
835 * @param sel The selector to be used 840 * @param sel The selector to be used
836 * @param dirName The name of the dir to start int 841 * @param dirName The name of the dir to start int
837 * @param fileName The fileName placed in the fileselector lineedit 842 * @param fileName The fileName placed in the fileselector lineedit
838 * @param mimetypes The MimeType map of used mimetypes 843 * @param mimetypes The MimeType map of used mimetypes
839 * @param showNew Show a New Button. Most likely to be used in the FileSelector view. 844 * @param showNew Show a New Button. Most likely to be used in the FileSelector view.
840 * @param showClose Show a Close Button. Most likely to be used in FileSelector view. 845 * @param showClose Show a Close Button. Most likely to be used in FileSelector view.
841 * 846 *
842 */ 847 */
843OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, 848OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
844 const QString& dirName, const QString& fileName, 849 const QString& dirName, const QString& fileName,
845 const MimeTypes& mimetypes, 850 const MimeTypes& mimetypes,
846 bool showNew, bool showClose) 851 bool showNew, bool showClose)
847 :QWidget( parent, "OFileSelector" ) 852 :QWidget( parent, "OFileSelector" )
848{ 853{
849 m_current = 0; 854 m_current = 0;
850 m_shNew = showNew; 855 m_shNew = showNew;
851 m_shClose = showClose; 856 m_shClose = showClose;
852 m_mimeType = mimetypes; 857 m_mimeType = mimetypes;
853 m_startDir = dirName; 858 m_startDir = dirName;
854 859
855 m_mode = mode; 860 m_mode = mode;
856 m_selector = sel; 861 m_selector = sel;
857 862
858 initUI(); 863 initUI();
859 m_lneEdit->setText( fileName ); 864 m_lneEdit->setText( fileName );
860 initMime(); 865 initMime();
861 initViews(); 866 initViews();
862 867
863 QString str; 868 QString str;
864 switch ( m_selector ) 869 switch ( m_selector )
865 { 870 {
866 default: 871 default:
867 case Normal: 872 case Normal:
868 str = QObject::tr("Documents"); 873 str = QObject::tr("Documents");
869 m_cmbView->setCurrentItem( 0 ); 874 m_cmbView->setCurrentItem( 0 );
870 break; 875 break;
871 case Extended: 876 case Extended:
872 str = QObject::tr("Files"); 877 str = QObject::tr("Files");
873 m_cmbView->setCurrentItem( 1 ); 878 m_cmbView->setCurrentItem( 1 );
874 break; 879 break;
875 case ExtendedAll: 880 case ExtendedAll:
876 str = QObject::tr("All Files"); 881 str = QObject::tr("All Files");
877 m_cmbView->setCurrentItem( 2 ); 882 m_cmbView->setCurrentItem( 2 );
878 break; 883 break;
879 } 884 }
880 slotViewChange( str ); 885 slotViewChange( str );
881 886
882} 887}
883 888
884 889
885/** 890/**
886 * This a convience c'tor to just substitute the use of FileSelector 891 * This a convience c'tor to just substitute the use of FileSelector
887 */ 892 */
888OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, 893OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name,
889 bool showNew, bool showClose ) 894 bool showNew, bool showClose )
890 : QWidget( parent, name ) 895 : QWidget( parent, name )
891{ 896{
892 m_current = 0; 897 m_current = 0;
893 m_shNew = showNew; 898 m_shNew = showNew;
894 m_shClose = showClose; 899 m_shClose = showClose;
895 m_startDir = QPEApplication::documentDir(); 900 m_startDir = QPEApplication::documentDir();
896 901
897 if (!mimeFilter.isEmpty() ) 902 if (!mimeFilter.isEmpty() )
898 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); 903 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) );
899 904
900 m_mode = OFileSelector::FileSelector; 905 m_mode = OFileSelector::FileSelector;
901 m_selector = OFileSelector::Normal; 906 m_selector = OFileSelector::Normal;
902 907
903 initUI(); 908 initUI();
904 initMime(); 909 initMime();
905 initViews(); 910 initViews();
906 m_cmbView->setCurrentItem( 0 ); 911 m_cmbView->setCurrentItem( 0 );
907 slotViewChange( QObject::tr("Documents") ); 912 slotViewChange( QObject::tr("Documents") );
908} 913}
909 914
910/* 915/*
911 * INIT UI will set up the basic GUI 916 * INIT UI will set up the basic GUI
912 * Layout: Simple VBoxLayout 917 * Layout: Simple VBoxLayout
913 * On top a WidgetStack containing the Views... 918 * On top a WidgetStack containing the Views...
914 * - List View 919 * - List View
915 * - Document View 920 * - Document View
916 * Below we will have a Label + LineEdit 921 * Below we will have a Label + LineEdit
917 * Below we will have two ComoBoxes one for choosing the view one for 922 * Below we will have two ComoBoxes one for choosing the view one for
918 * choosing the mimetype 923 * choosing the mimetype
919 */ 924 */
920void OFileSelector::initUI() 925void OFileSelector::initUI()
921{ 926{
922 QVBoxLayout* lay = new QVBoxLayout( this ); 927 QVBoxLayout* lay = new QVBoxLayout( this );
923 928
924 m_stack = new QWidgetStack( this ); 929 m_stack = new QWidgetStack( this );
925 lay->addWidget( m_stack, 1000 ); 930 lay->addWidget( m_stack, 1000 );
926 931
927 m_nameBox = new QHBox( this ); 932 m_nameBox = new QHBox( this );
928 (void)new QLabel( tr("Name:"), m_nameBox ); 933 (void)new QLabel( tr("Name:"), m_nameBox );
929 m_lneEdit = new QLineEdit( m_nameBox ); 934 m_lneEdit = new QLineEdit( m_nameBox );
930 m_lneEdit ->installEventFilter(this); 935 m_lneEdit ->installEventFilter(this);
931 lay->addWidget( m_nameBox ); 936 lay->addWidget( m_nameBox );
932 937
933 m_cmbBox = new QHBox( this ); 938 m_cmbBox = new QHBox( this );
934 m_cmbView = new QComboBox( m_cmbBox ); 939 m_cmbView = new QComboBox( m_cmbBox );
935 m_cmbMime = new QComboBox( m_cmbBox ); 940 m_cmbMime = new QComboBox( m_cmbBox );
936 lay->addWidget( m_cmbBox ); 941 lay->addWidget( m_cmbBox );
937} 942}
938 943
939/* 944/*
940 * This will make sure that the return key in the name edit causes dialogs to close 945 * This will make sure that the return key in the name edit causes dialogs to close
941 */ 946 */
942 947
943bool OFileSelector::eventFilter (QObject *o, QEvent *e) 948bool OFileSelector::eventFilter (QObject *o, QEvent *e)
944{ 949{
945 if ( e->type() == QEvent::KeyPress ) 950 if ( e->type() == QEvent::KeyPress )
946 { 951 {
947 QKeyEvent *k = (QKeyEvent *)e; 952 QKeyEvent *k = (QKeyEvent *)e;
948 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) 953 if ( (k->key()==Key_Enter) || (k->key()==Key_Return))
949 { 954 {
950 emit ok(); 955 emit ok();
951 return true; 956 return true;
952 } 957 }
953 } 958 }
954 return false; 959 return false;
955} 960}
956 961
957/* 962/*
958 * This will insert the MimeTypes into the Combo Box 963 * This will insert the MimeTypes into the Combo Box
959 * And also connect the changed signal 964 * And also connect the changed signal
960 * 965 *
961 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes 966 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes
962 */ 967 */
963void OFileSelector::initMime() 968void OFileSelector::initMime()
964{ 969{
965 MimeTypes::Iterator it; 970 MimeTypes::Iterator it;
966 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) 971 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it )
967 { 972 {
968 m_cmbMime->insertItem( it.key() ); 973 m_cmbMime->insertItem( it.key() );
969 } 974 }
970 m_cmbMime->setCurrentItem( 0 ); 975 m_cmbMime->setCurrentItem( 0 );
971 976
972 connect( m_cmbMime, SIGNAL(activated(int) ), 977 connect( m_cmbMime, SIGNAL(activated(int) ),
973 this, SLOT(slotMimeTypeChanged() ) ); 978 this, SLOT(slotMimeTypeChanged() ) );
974 979
975} 980}
976 981
977void OFileSelector::initViews() 982void OFileSelector::initViews()
978{ 983{
979 m_cmbView->insertItem( QObject::tr("Documents") ); 984 m_cmbView->insertItem( QObject::tr("Documents") );
980 m_cmbView->insertItem( QObject::tr("Files") ); 985 m_cmbView->insertItem( QObject::tr("Files") );
981 m_cmbView->insertItem( QObject::tr("All Files") ); 986 m_cmbView->insertItem( QObject::tr("All Files") );
982 connect(m_cmbView, SIGNAL(activated(const QString&) ), 987 connect(m_cmbView, SIGNAL(activated(const QString&) ),
983 this, SLOT(slotViewChange(const QString&) ) ); 988 this, SLOT(slotViewChange(const QString&) ) );
984 989
985 990
986 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); 991 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
987 992
988 /* see above why add both */ 993 /* see above why add both */
989 OFileViewInterface* in = new OFileViewFileSystem( this ); 994 OFileViewInterface* in = new OFileViewFileSystem( this );
990 m_views.insert( QObject::tr("Files"), in ); 995 m_views.insert( QObject::tr("Files"), in );
991 m_views.insert( QObject::tr("All Files"), in ); 996 m_views.insert( QObject::tr("All Files"), in );
992} 997}
993 998
994/** 999/**
995 * d'tor 1000 * d'tor
996 */ 1001 */
997OFileSelector::~OFileSelector() 1002OFileSelector::~OFileSelector()
998{ 1003{
999} 1004}
1000 1005
1001 1006
1002 1007
1003/** 1008/**
1004 * Convience function for the fileselector 1009 * Convience function for the fileselector
1005 * make sure to delete the DocLnk 1010 * make sure to delete the DocLnk
1006 * 1011 *
1007 * @see DocLnk 1012 * @see DocLnk
1008 * @todo remove in ODP 1013 * @todo remove in ODP
1009 */ 1014 */
1010const DocLnk* OFileSelector::selected() 1015const DocLnk* OFileSelector::selected()
1011{ 1016{
1012 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); 1017 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() );
1013 return lnk; 1018 return lnk;
1014} 1019}
1015 1020
1016/** 1021/**
1017 * 1022 *
1018 * @return the name of the selected file 1023 * @return the name of the selected file
1019 */ 1024 */
1020QString OFileSelector::selectedName()const 1025QString OFileSelector::selectedName()const
1021{ 1026{
1022 return currentView()->selectedName(); 1027 return currentView()->selectedName();
1023} 1028}
1024 1029
1025 1030
1026/** 1031/**
1027 * @return the selected path 1032 * @return the selected path
1028 */ 1033 */
1029QString OFileSelector::selectedPath()const 1034QString OFileSelector::selectedPath()const
1030{ 1035{
1031 return currentView()->selectedPath(); 1036 return currentView()->selectedPath();
1032} 1037}
1033 1038
1034/** 1039/**
1035 * @return the directory name 1040 * @return the directory name
1036 */ 1041 */
1037QString OFileSelector::directory()const 1042QString OFileSelector::directory()const
1038{ 1043{
1039 return currentView()->directory(); 1044 return currentView()->directory();
1040} 1045}
1041 1046
1042/** 1047/**
1043 * @return a DocLnk for the selected document 1048 * @return a DocLnk for the selected document
1044 */ 1049 */
1045DocLnk OFileSelector::selectedDocument()const 1050DocLnk OFileSelector::selectedDocument()const
1046{ 1051{
1047 return currentView()->selectedDocument(); 1052 return currentView()->selectedDocument();
1048} 1053}
1049 1054
1050/** 1055/**
1051 * @return the number of items for the current view 1056 * @return the number of items for the current view
1052 */ 1057 */
1053int OFileSelector::fileCount()const 1058int OFileSelector::fileCount()const
1054{ 1059{
1055 return currentView()->fileCount(); 1060 return currentView()->fileCount();
1056} 1061}
1057 1062
1058/** 1063/**
1059 * @return reparse the file content 1064 * @return reparse the file content
1060 */ 1065 */
1061void OFileSelector::reread() 1066void OFileSelector::reread()
1062{ 1067{
1063 return currentView()->reread(); 1068 return currentView()->reread();
1064} 1069}
1065 1070
1066OFileViewInterface* OFileSelector::currentView()const 1071OFileViewInterface* OFileSelector::currentView()const
1067{ 1072{
1068 return m_current; 1073 return m_current;
1069} 1074}
1070 1075
1071bool OFileSelector::showNew()const 1076bool OFileSelector::showNew()const
1072{ 1077{
1073 return m_shNew; 1078 return m_shNew;
1074} 1079}
1075 1080
1076bool OFileSelector::showClose()const 1081bool OFileSelector::showClose()const
1077{ 1082{
1078 return m_shClose; 1083 return m_shClose;
1079} 1084}
1080 1085
1081MimeTypes OFileSelector::mimeTypes()const 1086MimeTypes OFileSelector::mimeTypes()const
1082{ 1087{
1083 return m_mimeType; 1088 return m_mimeType;
1084} 1089}
1085 1090
1086/** 1091/**
1087 * @return the Mode of the OFileSelector 1092 * @return the Mode of the OFileSelector
1088 */ 1093 */
1089int OFileSelector::mode()const 1094int OFileSelector::mode()const
1090{ 1095{
1091 return m_mode; 1096 return m_mode;
1092} 1097}
1093 1098
1094 1099
1095/** 1100/**
1096 * @return the Selector of the OFileSelector 1101 * @return the Selector of the OFileSelector
1097 */ 1102 */
1098int OFileSelector::selector()const 1103int OFileSelector::selector()const
1099{ 1104{
1100 return m_selector; 1105 return m_selector;
1101} 1106}
1102 1107
1103QStringList OFileSelector::currentMimeType()const 1108QStringList OFileSelector::currentMimeType()const
1104{ 1109{
1105 return m_mimeType[m_cmbMime->currentText()]; 1110 return m_mimeType[m_cmbMime->currentText()];
1106} 1111}
1107 1112
1108void OFileSelector::slotMimeTypeChanged() 1113void OFileSelector::slotMimeTypeChanged()
1109{ 1114{
1110 reread(); 1115 reread();
1111} 1116}
1112 1117
1113void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) 1118void OFileSelector::slotDocLnkBridge( const DocLnk& lnk)
1114{ 1119{
1115 m_lneEdit->setText( lnk.name() ); 1120 m_lneEdit->setText( lnk.name() );
1116 emit fileSelected( lnk ); 1121 emit fileSelected( lnk );
1117 emit fileSelected( lnk.name() ); 1122 emit fileSelected( lnk.name() );
1118} 1123}
1119 1124
1120void OFileSelector::slotFileBridge( const QString& str) 1125void OFileSelector::slotFileBridge( const QString& str)
1121{ 1126{
1122 DocLnk lnk( str ); 1127 DocLnk lnk( str );
1123 emit fileSelected( lnk ); 1128 emit fileSelected( lnk );
1124} 1129}
1125 1130
1126void OFileSelector::slotViewChange( const QString& view ) 1131void OFileSelector::slotViewChange( const QString& view )
1127{ 1132{
1128 OFileViewInterface* interface = m_views[view]; 1133 OFileViewInterface* interface = m_views[view];
1129 if (!interface) 1134 if (!interface)
1130 return; 1135 return;
1131 1136
1132 interface->activate( view ); 1137 interface->activate( view );
1133 if (m_current) 1138 if (m_current)
1134 m_stack->removeWidget( m_current->widget( m_stack ) ); 1139 m_stack->removeWidget( m_current->widget( m_stack ) );
1135 1140
1136 static int id = 1; 1141 static int id = 1;
1137 1142
1138 m_stack->addWidget( interface->widget(m_stack), id ); 1143 m_stack->addWidget( interface->widget(m_stack), id );
1139 m_stack->raiseWidget( id ); 1144 m_stack->raiseWidget( id );
1140 1145
1141 interface->reread(); 1146 interface->reread();
1142 m_current = interface; 1147 m_current = interface;
1143 1148
1144 id++; 1149 id++;
1145} 1150}
1146 1151
1147void OFileSelector::setNewVisible( bool b ) 1152void OFileSelector::setNewVisible( bool b )
1148{ 1153{
1149 m_shNew = b; 1154 m_shNew = b;
1150 currentView()->reread(); 1155 currentView()->reread();
1151} 1156}
1152 1157
1153void OFileSelector::setCloseVisible( bool b ) 1158void OFileSelector::setCloseVisible( bool b )
1154{ 1159{
1155 m_shClose = b; 1160 m_shClose = b;
1156 currentView()->reread(); 1161 currentView()->reread();
1157} 1162}
1158 1163
1159void OFileSelector::setNameVisible( bool b ) 1164void OFileSelector::setNameVisible( bool b )
1160{ 1165{
1161 if ( b ) 1166 if ( b )
1162 m_nameBox->show(); 1167 m_nameBox->show();
1163 else 1168 else
1164 m_nameBox->hide(); 1169 m_nameBox->hide();
1165} 1170}
1166 1171
1172}
1173}
diff --git a/libopie2/opieui/fileselector/ofileselector.h b/libopie2/opieui/fileselector/ofileselector.h
index 7fa657b..2205963 100644
--- a/libopie2/opieui/fileselector/ofileselector.h
+++ b/libopie2/opieui/fileselector/ofileselector.h
@@ -1,219 +1,222 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> 3             .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29/* 29/*
30 This is based on code and ideas of 30 This is based on code and ideas of
31 L. J. Potter ljp@llornkcor.com 31 L. J. Potter ljp@llornkcor.com
32 Thanks a lot 32 Thanks a lot
33*/ 33*/
34 34
35#ifndef OFILESELECTOR_H 35#ifndef OFILESELECTOR_H
36#define OFILESELECTOR_H 36#define OFILESELECTOR_H
37 37
38/* OPIE */ 38/* OPIE */
39#include <qpe/applnk.h> 39#include <qpe/applnk.h>
40 40
41/* QT */ 41/* QT */
42#include <qlist.h> 42#include <qlist.h>
43#include <qwidget.h> 43#include <qwidget.h>
44#include <qmap.h> 44#include <qmap.h>
45#include <qvaluelist.h> 45#include <qvaluelist.h>
46#include <qstringlist.h> 46#include <qstringlist.h>
47 47
48class QLineEdit; 48class QLineEdit;
49class QComboBox; 49class QComboBox;
50class QWidgetStack; 50class QWidgetStack;
51class QHBox; 51class QHBox;
52 52
53typedef QMap<QString, QStringList> MimeTypes; 53typedef QMap<QString, QStringList> MimeTypes;
54 54
55namespace Opie 55namespace Opie {
56{ 56namespace Ui {
57 57
58namespace Private {
58class OFileViewInterface; 59class OFileViewInterface;
59class OFileViewFileListView; 60class OFileViewFileListView;
61}
60 62
61 63
62/** 64/**
63 * @short a dropin replacement for the FileSelector 65 * @short a dropin replacement for the FileSelector
64 * 66 *
65 * This class is first used insert the OFileDialog. 67 * This class is first used insert the OFileDialog.
66 * It supports multiple view and mimetype filtering for now. 68 * It supports multiple view and mimetype filtering for now.
67 * 69 *
68 * @see OFileDialog 70 * @see OFileDialog
69 * @see FileSelector 71 * @see FileSelector
70 * @author zecke 72 * @author zecke
71 * @version 0.1 73 * @version 0.1
72 */ 74 */
73class OFileSelector : public QWidget 75class OFileSelector : public QWidget
74{ 76{
75 Q_OBJECT 77 Q_OBJECT
76 friend class Opie::OFileViewInterface; 78 friend class Private::OFileViewInterface;
77 friend class Opie::OFileViewFileListView; 79 friend class Private::OFileViewFileListView;
78 80
79public: 81public:
80 /** 82 /**
81 * The Mode of the Fileselector 83 * The Mode of the Fileselector
82 * Open = Open A File 84 * Open = Open A File
83 * Save = Save a File 85 * Save = Save a File
84 * FILESELECTOR = As A GUI in a screen to select a file 86 * FILESELECTOR = As A GUI in a screen to select a file
85 */ 87 */
86 enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 }; 88 enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 };
87 // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; 89 // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 };
88 /** 90 /**
89 * Normal = The old FileSelector 91 * Normal = The old FileSelector
90 * Extended = Dir View 92 * Extended = Dir View
91 * ExtendedAll = Dir View with all hidden files 93 * ExtendedAll = Dir View with all hidden files
92 * Default = What the vendor considers best 94 * Default = What the vendor considers best
93 */ 95 */
94 enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 }; 96 enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 };
95 // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; 97 // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2};
96 98
97 OFileSelector(QWidget* parent, int mode, int selector, 99 OFileSelector(QWidget* parent, int mode, int selector,
98 const QString& dirName, 100 const QString& dirName,
99 const QString& fileName, 101 const QString& fileName,
100 const MimeTypes& mimetypes = MimeTypes(), 102 const MimeTypes& mimetypes = MimeTypes(),
101 bool newVisible = FALSE, bool closeVisible = FALSE ); 103 bool newVisible = FALSE, bool closeVisible = FALSE );
102 104
103 OFileSelector(const QString& mimeFilter, QWidget* parent, 105 OFileSelector(const QString& mimeFilter, QWidget* parent,
104 const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); 106 const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE );
105 ~OFileSelector(); 107 ~OFileSelector();
106 108
107 const DocLnk* selected(); 109 const DocLnk* selected();
108 110
109 QString selectedName()const; 111 QString selectedName()const;
110 QString selectedPath()const; 112 QString selectedPath()const;
111 QString directory()const; 113 QString directory()const;
112 114
113 DocLnk selectedDocument()const; 115 DocLnk selectedDocument()const;
114 116
115 int fileCount()const; 117 int fileCount()const;
116 void reread(); 118 void reread();
117 119
118 int mode()const; 120 int mode()const;
119 int selector()const; 121 int selector()const;
120 122
121 /** 123 /**
122 * Set the Icon visible 124 * Set the Icon visible
123 * @param b Show or Hide the New Button 125 * @param b Show or Hide the New Button
124 */ 126 */
125 void setNewVisible( bool b ); 127 void setNewVisible( bool b );
126 128
127 /** 129 /**
128 * Set the Icon visible 130 * Set the Icon visible
129 */ 131 */
130 void setCloseVisible( bool b ); 132 void setCloseVisible( bool b );
131 133
132 /** 134 /**
133 * Set the Name Line visible 135 * Set the Name Line visible
134 */ 136 */
135 void setNameVisible( bool b ); 137 void setNameVisible( bool b );
136 138
137signals: 139signals:
138 /** 140 /**
139 * dirSelected is emitted whenever changed into a different dir 141 * dirSelected is emitted whenever changed into a different dir
140 */ 142 */
141 void dirSelected( const QString& ); 143 void dirSelected( const QString& );
142 144
143 /** 145 /**
144 * fileSelected is emitted when a file is selected 146 * fileSelected is emitted when a file is selected
145 * it uses a DocLnk as parameter 147 * it uses a DocLnk as parameter
146 */ 148 */
147 void fileSelected( const DocLnk& ); 149 void fileSelected( const DocLnk& );
148 150
149 /** 151 /**
150 * fileSelected is emitted when a file is selected 152 * fileSelected is emitted when a file is selected
151 * the complete path is a parameter 153 * the complete path is a parameter
152 */ 154 */
153 void fileSelected( const QString& ); 155 void fileSelected( const QString& );
154 156
155 /** 157 /**
156 * Create a new File with a DocLnk 158 * Create a new File with a DocLnk
157 */ 159 */
158 void newSelected( const DocLnk& ); 160 void newSelected( const DocLnk& );
159 161
160 void closeMe(); 162 void closeMe();
161 163
162 /** 164 /**
163 * Ok is emitted on a Qt::Key_Return or Q::Key_Enter 165 * Ok is emitted on a Qt::Key_Return or Q::Key_Enter
164 * in the line edit 166 * in the line edit
165 */ 167 */
166 void ok(); 168 void ok();
167 void cancel(); 169 void cancel();
168 170
169 /* used by the ViewInterface */ 171 /* used by the ViewInterface */
170private: 172private:
171 bool showNew()const; 173 bool showNew()const;
172 bool showClose()const; 174 bool showClose()const;
173 MimeTypes mimeTypes()const; 175 MimeTypes mimeTypes()const;
174 QStringList currentMimeType()const; 176 QStringList currentMimeType()const;
175 177
176private: 178private:
177 /* inits the Widgets */ 179 /* inits the Widgets */
178 void initUI(); 180 void initUI();
179 /* inits the MimeType ComboBox content + connects signals and slots */ 181 /* inits the MimeType ComboBox content + connects signals and slots */
180 void initMime(); 182 void initMime();
181 /* init the Views :) */ 183 /* init the Views :) */
182 void initViews(); 184 void initViews();
183 185
184private: 186private:
185 QLineEdit* m_lneEdit; // the LineEdit for the Name 187 QLineEdit* m_lneEdit; // the LineEdit for the Name
186 QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType 188 QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType
187 QWidgetStack* m_stack; // our widget stack which will contain the views 189 QWidgetStack* m_stack; // our widget stack which will contain the views
188 OFileViewInterface* currentView() const; // returns the currentView 190 Private::OFileViewInterface* currentView() const; // returns the currentView
189 OFileViewInterface* m_current; // here is the view saved 191 Private::OFileViewInterface* m_current; // here is the view saved
190 bool m_shNew : 1; // should we show New? 192 bool m_shNew : 1; // should we show New?
191 bool m_shClose : 1; // should we show Close? 193 bool m_shClose : 1; // should we show Close?
192 MimeTypes m_mimeType; // list of mimetypes 194 MimeTypes m_mimeType; // list of mimetypes
193 195
194 QMap<QString, OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr 196 QMap<QString, Private::OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr
195 QHBox* m_nameBox; // the LineEdit + Label is hold here 197 QHBox* m_nameBox; // the LineEdit + Label is hold here
196 QHBox* m_cmbBox; // this holds the two combo boxes 198 QHBox* m_cmbBox; // this holds the two combo boxes
197 199
198 QString m_startDir; 200 QString m_startDir;
199 int m_mode; 201 int m_mode;
200 int m_selector; 202 int m_selector;
201 203
202 struct Data; // used for future versions 204 struct Data; // used for future versions
203 Data *d; 205 Data *d;
204 206
205private slots: 207private slots:
206 void slotMimeTypeChanged(); 208 void slotMimeTypeChanged();
207 209
208 /* will set the text of the lineedit and emit a fileChanged signal */ 210 /* will set the text of the lineedit and emit a fileChanged signal */
209 void slotDocLnkBridge( const DocLnk& ); 211 void slotDocLnkBridge( const DocLnk& );
210 void slotFileBridge( const QString& ); 212 void slotFileBridge( const QString& );
211 void slotViewChange( const QString& ); 213 void slotViewChange( const QString& );
212 214
213 bool eventFilter (QObject *o, QEvent *e); 215 bool eventFilter (QObject *o, QEvent *e);
214 216
215}; 217};
216 218
217}; 219}
220}
218 221
219#endif 222#endif
diff --git a/libopie2/opieui/fileselector/ofileselector_p.h b/libopie2/opieui/fileselector/ofileselector_p.h
index 818ced9..376dc98 100644
--- a/libopie2/opieui/fileselector/ofileselector_p.h
+++ b/libopie2/opieui/fileselector/ofileselector_p.h
@@ -1,191 +1,193 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) Holger Freyther <zecke@handhelds.org> 3             .=l. Copyright (C) Holger Freyther <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#ifndef OFILESELECTOR_PRIVATE_H 29#ifndef OFILESELECTOR_PRIVATE_H
30#define OFILESELECTOR_PRIVATE_H 30#define OFILESELECTOR_PRIVATE_H
31 31
32/* OPIE */ 32/* OPIE */
33#include <qpe/applnk.h> 33#include <qpe/applnk.h>
34#include <qpe/fileselector.h> 34#include <qpe/fileselector.h>
35 35
36/* QT */ 36/* QT */
37#include <qmap.h> 37#include <qmap.h>
38#include <qstringlist.h> 38#include <qstringlist.h>
39#include <qwidget.h> 39#include <qwidget.h>
40#include <qlistview.h> 40#include <qlistview.h>
41 41
42/* 42/*
43 * How to avoid having really two different objects 43 * How to avoid having really two different objects
44 * for Extended and ExtendedAll 44 * for Extended and ExtendedAll
45 * The only difference is the Lister... 45 * The only difference is the Lister...
46 * a) static object? 46 * a) static object?
47 * b) leave some object inside the OFileSelector which can be used? 47 * b) leave some object inside the OFileSelector which can be used?
48 * c) when switching views tell which view we want o have.. internally we can switch then 48 * c) when switching views tell which view we want o have.. internally we can switch then
49 * 49 *
50 * I'll take c) -zecke 50 * I'll take c) -zecke
51 */ 51 */
52 52
53typedef QMap<QString, QStringList> MimeTypes; 53typedef QMap<QString, QStringList> MimeTypes;
54 54
55/* the View Interface */ 55/* the View Interface */
56class QFileInfo; 56class QFileInfo;
57class QToolButton; 57class QToolButton;
58 58
59namespace Opie 59namespace Opie{
60{ 60namespace Ui{
61
62class OFileSelector; 61class OFileSelector;
62namespace Private {
63 63
64class OFileViewInterface 64class OFileViewInterface
65{ 65{
66public: 66public:
67 OFileViewInterface( OFileSelector* selector ); 67 OFileViewInterface( OFileSelector* selector );
68 virtual ~OFileViewInterface(); 68 virtual ~OFileViewInterface();
69 virtual QString selectedName()const = 0; 69 virtual QString selectedName()const = 0;
70 virtual QString selectedPath()const = 0; 70 virtual QString selectedPath()const = 0;
71 virtual QString directory()const = 0; 71 virtual QString directory()const = 0;
72 virtual void reread() = 0; 72 virtual void reread() = 0;
73 virtual int fileCount()const = 0; 73 virtual int fileCount()const = 0;
74 virtual DocLnk selectedDocument()const; 74 virtual DocLnk selectedDocument()const;
75 virtual QWidget* widget( QWidget* parent) = 0; 75 virtual QWidget* widget( QWidget* parent) = 0;
76 virtual void activate( const QString& ); 76 virtual void activate( const QString& );
77 QString name()const; 77 QString name()const;
78protected: 78protected:
79 OFileSelector* selector()const; 79 OFileSelector* selector()const;
80 void setName( const QString& ); 80 void setName( const QString& );
81 bool showNew()const; 81 bool showNew()const;
82 bool showClose()const; 82 bool showClose()const;
83 MimeTypes mimeTypes()const; 83 MimeTypes mimeTypes()const;
84 QStringList currentMimeType()const; 84 QStringList currentMimeType()const;
85 QString startDirectory()const; 85 QString startDirectory()const;
86protected: 86protected:
87 void ok(); 87 void ok();
88 void cancel(); 88 void cancel();
89 void closeMe(); 89 void closeMe();
90 void fileSelected( const QString& ); 90 void fileSelected( const QString& );
91 void fileSelected( const DocLnk& ); 91 void fileSelected( const DocLnk& );
92 void setCurrentFileName( const QString& ); 92 void setCurrentFileName( const QString& );
93 QString currentFileName()const; 93 QString currentFileName()const;
94 94
95private: 95private:
96 QString m_name; 96 QString m_name;
97 OFileSelector* m_selector; 97 OFileSelector* m_selector;
98}; 98};
99 99
100 100
101/* THE Document View hosting a FileSelector*/ 101/* THE Document View hosting a FileSelector*/
102class ODocumentFileView : public OFileViewInterface 102class ODocumentFileView : public OFileViewInterface
103{ 103{
104public: 104public:
105 ODocumentFileView( OFileSelector* selector ); 105 ODocumentFileView( OFileSelector* selector );
106 ~ODocumentFileView(); 106 ~ODocumentFileView();
107 107
108 QString selectedName() const; 108 QString selectedName() const;
109 QString selectedPath() const; 109 QString selectedPath() const;
110 110
111 QString directory() const; 111 QString directory() const;
112 void reread(); 112 void reread();
113 int fileCount()const; 113 int fileCount()const;
114 DocLnk selectedDocument()const; 114 DocLnk selectedDocument()const;
115 115
116 QWidget* widget( QWidget* parent ); 116 QWidget* widget( QWidget* parent );
117 117
118private: 118private:
119 mutable FileSelector* m_selector; 119 mutable FileSelector* m_selector;
120 120
121}; 121};
122 122
123 123
124class OFileSelectorItem : public QListViewItem 124class OFileSelectorItem : public QListViewItem
125{ 125{
126public: 126public:
127 OFileSelectorItem( QListView* view, const QPixmap& pixmap, 127 OFileSelectorItem( QListView* view, const QPixmap& pixmap,
128 const QString& path, const QString& date, 128 const QString& path, const QString& date,
129 const QString& size, const QString& mDir, 129 const QString& size, const QString& mDir,
130 bool isLocked = false, bool isDir = false ); 130 bool isLocked = false, bool isDir = false );
131 ~OFileSelectorItem(); 131 ~OFileSelectorItem();
132 bool isLocked()const; 132 bool isLocked()const;
133 bool isDir()const; 133 bool isDir()const;
134 QString directory()const; 134 QString directory()const;
135 QString path()const; 135 QString path()const;
136 QString key(int id, bool )const; 136 QString key(int id, bool )const;
137 137
138private: 138private:
139 bool m_locked : 1; 139 bool m_locked : 1;
140 bool m_isDir : 1; 140 bool m_isDir : 1;
141 QString m_dir; 141 QString m_dir;
142}; 142};
143 143
144class OFileViewFileListView : public QWidget 144class OFileViewFileListView : public QWidget
145{ 145{
146 Q_OBJECT 146 Q_OBJECT
147public: 147public:
148 OFileViewFileListView( QWidget* parent, const QString& dir, OFileSelector* selector ); 148 OFileViewFileListView( QWidget* parent, const QString& dir, OFileSelector* selector );
149 ~OFileViewFileListView(); 149 ~OFileViewFileListView();
150 150
151 OFileSelectorItem* currentItem()const; 151 OFileSelectorItem* currentItem()const;
152 void reread( bool all = false ); 152 void reread( bool all = false );
153 int fileCount()const; 153 int fileCount()const;
154 QString currentDir()const; 154 QString currentDir()const;
155protected: 155protected:
156 bool eventFilter (QObject *o, QEvent *e); 156 bool eventFilter (QObject *o, QEvent *e);
157private slots: 157private slots:
158 void slotNew(); // will emit newSelected 158 void slotNew(); // will emit newSelected
159 void cdUP(); 159 void cdUP();
160 void cdHome(); 160 void cdHome();
161 void cdDoc(); 161 void cdDoc();
162 void changeDir( const QString& ); 162 void changeDir( const QString& );
163 void slotCurrentChanged( QListViewItem* ); 163 void slotCurrentChanged( QListViewItem* );
164 void slotClicked(int, QListViewItem*, const QPoint&, int ); 164 void slotClicked(int, QListViewItem*, const QPoint&, int );
165 void slotFSActivated(int); 165 void slotFSActivated(int);
166 166
167protected: 167protected:
168 OFileSelector* selector(); 168 OFileSelector* selector();
169 169
170private: 170private:
171 QMap<QString, QString> m_dev; 171 QMap<QString, QString> m_dev;
172 bool m_all : 1; 172 bool m_all : 1;
173 OFileSelector* m_sel; 173 OFileSelector* m_sel;
174 QPopupMenu* m_fsPop; 174 QPopupMenu* m_fsPop;
175 bool compliesMime( const QString& ); 175 bool compliesMime( const QString& );
176 QStringList m_mimes; // used in compy mime 176 QStringList m_mimes; // used in compy mime
177 QString m_currentDir; 177 QString m_currentDir;
178 QToolButton *m_btnNew, *m_btnClose; 178 QToolButton *m_btnNew, *m_btnClose;
179 void connectSlots(); 179 void connectSlots();
180 void addFile( QFileInfo* info, bool symlink = FALSE ); 180 void addFile( QFileInfo* info, bool symlink = FALSE );
181 void addDir ( QFileInfo* info, bool symlink = FALSE ); 181 void addDir ( QFileInfo* info, bool symlink = FALSE );
182 void addSymlink( QFileInfo* info, bool = FALSE ); 182 void addSymlink( QFileInfo* info, bool = FALSE );
183 183
184 184
185private: 185private:
186 QListView* m_view; 186 QListView* m_view;
187}; 187};
188 188
189}; 189}
190}
191}
190 192
191#endif 193#endif
diff --git a/libopie2/opieui/fileselector/ofileview.h b/libopie2/opieui/fileselector/ofileview.h
index 495401b..aaf56b1 100644
--- a/libopie2/opieui/fileselector/ofileview.h
+++ b/libopie2/opieui/fileselector/ofileview.h
@@ -1,95 +1,98 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) 2002 Holger Freyther <zecke@handhelds.org> 3             .=l. Copyright (C) 2002 Holger Freyther <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#ifndef OFILEVIEW_H 29#ifndef OFILEVIEW_H
30#define OFILEVIEW_H 30#define OFILEVIEW_H
31 31
32/* QT */ 32/* QT */
33#include <qobject.h> 33#include <qobject.h>
34#include <qwidget.h> 34#include <qwidget.h>
35 35
36class QFileInfo; 36class QFileInfo;
37class QDir; 37class QDir;
38class DocLnk; 38class DocLnk;
39 39
40namespace Opie 40namespace Opie {
41{ 41namespace Ui {
42namespace Private {
42 43
43/** 44/**
44 * A OFileView is a specialised View for the 45 * A OFileView is a specialised View for the
45 * OFileSelector 46 * OFileSelector
46 * With a View you can chage the user visible 47 * With a View you can chage the user visible
47 * representation of a OFileLister 48 * representation of a OFileLister
48 * OFileView is just a basic interface which helps you to 49 * OFileView is just a basic interface which helps you to
49 * write new views 50 * write new views
50 */ 51 */
51class OFileView : public QWidget 52class OFileView : public QWidget
52{ 53{
53 Q_OBJECT 54 Q_OBJECT
54public: 55public:
55 OFileView(QWidget *widget, 56 OFileView(QWidget *widget,
56 const char *name ); 57 const char *name );
57 58
58 OFileView(); 59 OFileView();
59 60
60 virtual void addFile(const QString &mine, 61 virtual void addFile(const QString &mine,
61 QFileInfo *info, 62 QFileInfo *info,
62 bool isSymlink = FALSE ) = 0; 63 bool isSymlink = FALSE ) = 0;
63 64
64 virtual void addDir (const QString &mine, 65 virtual void addDir (const QString &mine,
65 QFileInfo *info, 66 QFileInfo *info,
66 bool isSymlink = FALSE ) = 0; 67 bool isSymlink = FALSE ) = 0;
67 68
68 virtual void addSymlink(const QString &mime, 69 virtual void addSymlink(const QString &mime,
69 QFileInfo *info, 70 QFileInfo *info,
70 bool isSymlink = FALSE ) = 0; 71 bool isSymlink = FALSE ) = 0;
71 72
72 virtual void cd(const QString &path ) = 0; 73 virtual void cd(const QString &path ) = 0;
73signals: 74signals:
74 void fileSelected(const QString &); 75 void fileSelected(const QString &);
75 void fileSelected(const DocLnk & ); 76 void fileSelected(const DocLnk & );
76 void contextMenu(); 77 void contextMenu();
77 void changedDir(const QString &); 78 void changedDir(const QString &);
78 void changedDir(const QDir & ); 79 void changedDir(const QDir & );
79}; 80};
80 81
81 82
82class OFileViewFactory 83class OFileViewFactory
83{ 84{
84 // Q_OBJECT 85 // Q_OBJECT
85public: 86public:
86 OFileViewFactory() {} ; 87 OFileViewFactory() {} ;
87 virtual ~OFileViewFactory() = 0; 88 virtual ~OFileViewFactory() = 0;
88 89
89 OFileView* newView(QWidget *parent, const char *name ); 90 OFileView* newView(QWidget *parent, const char *name );
90 QString name()const; 91 QString name()const;
91}; 92};
92 93
93}; 94}
95}
96}
94 97
95#endif 98#endif
diff --git a/libopie2/opieui/oclickablelabel.cpp b/libopie2/opieui/oclickablelabel.cpp
index 4c4e581..53cb77a 100644
--- a/libopie2/opieui/oclickablelabel.cpp
+++ b/libopie2/opieui/oclickablelabel.cpp
@@ -1,173 +1,173 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Maximillian Reiß <harlekin@handhelds.org> 3 Copyright (C) Maximillian Reiß <harlekin@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include <opie2/oclickablelabel.h> 30#include <opie2/oclickablelabel.h>
31 31
32using namespace Opie; 32using namespace Opie::Ui;
33 33
34/** 34/**
35 * This constructs the clickable ButtonLabel 35 * This constructs the clickable ButtonLabel
36 * 36 *
37 * @param parent The parent of this label 37 * @param parent The parent of this label
38 * @param name A name of this label @see QObject 38 * @param name A name of this label @see QObject
39 * @param fl The windowing flags 39 * @param fl The windowing flags
40 */ 40 */
41OClickableLabel::OClickableLabel(QWidget* parent, const char* name, WFlags fl) 41OClickableLabel::OClickableLabel(QWidget* parent, const char* name, WFlags fl)
42 :QLabel(parent,name,fl) 42 :QLabel(parent,name,fl)
43{ 43{
44 textInverted=false; 44 textInverted=false;
45 isToggle=false; 45 isToggle=false;
46 isDown=false; 46 isDown=false;
47 showState(false); 47 showState(false);
48 setFrameShadow(Sunken); 48 setFrameShadow(Sunken);
49} 49}
50 50
51/** 51/**
52 * This method makes the label behave as a toggle button 52 * This method makes the label behave as a toggle button
53 * 53 *
54 * @param t Whether or not to behave like a toggle button 54 * @param t Whether or not to behave like a toggle button
55 */ 55 */
56void OClickableLabel::setToggleButton(bool t) 56void OClickableLabel::setToggleButton(bool t)
57{ 57{
58 isToggle=t; 58 isToggle=t;
59} 59}
60 60
61/** 61/**
62 * @internal 62 * @internal
63 */ 63 */
64void OClickableLabel::mousePressEvent( QMouseEvent * /*e*/ ) 64void OClickableLabel::mousePressEvent( QMouseEvent * /*e*/ )
65{ 65{
66 if (isToggle && isDown) 66 if (isToggle && isDown)
67 { 67 {
68 showState(false); 68 showState(false);
69 } 69 }
70 else 70 else
71 { 71 {
72 showState(true); 72 showState(true);
73 } 73 }
74} 74}
75 75
76/** 76/**
77 * @internal 77 * @internal
78 */ 78 */
79void OClickableLabel::mouseReleaseEvent( QMouseEvent *e ) 79void OClickableLabel::mouseReleaseEvent( QMouseEvent *e )
80{ 80{
81 if (rect().contains(e->pos()) && isToggle) isDown=!isDown; 81 if (rect().contains(e->pos()) && isToggle) isDown=!isDown;
82 82
83 if (isToggle && isDown) 83 if (isToggle && isDown)
84 { 84 {
85 showState(true); 85 showState(true);
86 } 86 }
87 else 87 else
88 { 88 {
89 showState(false); 89 showState(false);
90 } 90 }
91 91
92 if (rect().contains(e->pos())) 92 if (rect().contains(e->pos()))
93 { 93 {
94 if (isToggle) 94 if (isToggle)
95 { 95 {
96 emit toggled(isDown); 96 emit toggled(isDown);
97 } 97 }
98 emit clicked(); 98 emit clicked();
99 } 99 }
100} 100}
101 101
102/** 102/**
103 * @internal 103 * @internal
104 */ 104 */
105void OClickableLabel::mouseMoveEvent( QMouseEvent *e ) 105void OClickableLabel::mouseMoveEvent( QMouseEvent *e )
106{ 106{
107 if (rect().contains(e->pos())) 107 if (rect().contains(e->pos()))
108 { 108 {
109 if (isToggle && isDown) 109 if (isToggle && isDown)
110 { 110 {
111 showState(false); 111 showState(false);
112 } 112 }
113 else 113 else
114 { 114 {
115 showState(true); 115 showState(true);
116 } 116 }
117 } 117 }
118 else 118 else
119 { 119 {
120 if (isToggle && isDown) 120 if (isToggle && isDown)
121 { 121 {
122 showState(true); 122 showState(true);
123 } 123 }
124 else 124 else
125 { 125 {
126 showState(false); 126 showState(false);
127 } 127 }
128 } 128 }
129} 129}
130 130
131/** 131/**
132 * this toggles the label and inverts the color of 132 * this toggles the label and inverts the color of
133 * the label 133 * the label
134 * @param on 134 * @param on
135 */ 135 */
136void OClickableLabel::showState(bool on) 136void OClickableLabel::showState(bool on)
137{ 137{
138 if (on) 138 if (on)
139 { 139 {
140 //setFrameShape(Panel); 140 //setFrameShape(Panel);
141 setInverted(true); 141 setInverted(true);
142 setBackgroundMode(PaletteHighlight); 142 setBackgroundMode(PaletteHighlight);
143 } 143 }
144 else 144 else
145 { 145 {
146 //setFrameShape(NoFrame); 146 //setFrameShape(NoFrame);
147 setInverted(false); 147 setInverted(false);
148 setBackgroundMode(PaletteBackground); 148 setBackgroundMode(PaletteBackground);
149 } 149 }
150 repaint(); 150 repaint();
151} 151}
152 152
153void OClickableLabel::setInverted(bool on) 153void OClickableLabel::setInverted(bool on)
154{ 154{
155 if ( (!textInverted && on) || (textInverted && !on) ) 155 if ( (!textInverted && on) || (textInverted && !on) )
156 { 156 {
157 QPalette pal=palette(); 157 QPalette pal=palette();
158 QColor col=pal.color(QPalette::Normal, QColorGroup::Foreground); 158 QColor col=pal.color(QPalette::Normal, QColorGroup::Foreground);
159 col.setRgb(255-col.red(),255-col.green(),255-col.blue()); 159 col.setRgb(255-col.red(),255-col.green(),255-col.blue());
160 pal.setColor(QPalette::Normal, QColorGroup::Foreground, col); 160 pal.setColor(QPalette::Normal, QColorGroup::Foreground, col);
161 setPalette(pal); 161 setPalette(pal);
162 textInverted=!textInverted; 162 textInverted=!textInverted;
163 } 163 }
164} 164}
165 165
166/** 166/**
167 * @param on if the Label is down or up 167 * @param on if the Label is down or up
168 */ 168 */
169void OClickableLabel::setOn(bool on) 169void OClickableLabel::setOn(bool on)
170{ 170{
171 isDown=on; 171 isDown=on;
172 showState(isDown); 172 showState(isDown);
173} 173}
diff --git a/libopie2/opieui/oclickablelabel.h b/libopie2/opieui/oclickablelabel.h
index b224d61..90859a0 100644
--- a/libopie2/opieui/oclickablelabel.h
+++ b/libopie2/opieui/oclickablelabel.h
@@ -1,103 +1,104 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Maximillian Reiß <harlekin@handhelds.org> 3 Copyright (C) Maximillian Reiß <harlekin@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#ifndef OCLICKABLELABEL_H 30#ifndef OCLICKABLELABEL_H
31#define OCLICKABLELABEL_H 31#define OCLICKABLELABEL_H
32 32
33/* QT */ 33/* QT */
34#include <qlabel.h> 34#include <qlabel.h>
35 35
36namespace Opie 36namespace Opie{
37{ 37namespace Ui {
38 38
39/** 39/**
40 * This class is a special QLabel which can behave 40 * This class is a special QLabel which can behave
41 * as a QPushButton or QToggleButton. 41 * as a QPushButton or QToggleButton.
42 * The reason to use a clickable is if you want to save space 42 * The reason to use a clickable is if you want to save space
43 * or you want to skip the border of a normal button 43 * or you want to skip the border of a normal button
44 * 44 *
45 * <pre> 45 * <pre>
46 * QLabel* lbl = new OClickableLabel( parent, "PushLabel" ); 46 * QLabel* lbl = new OClickableLabel( parent, "PushLabel" );
47 * lbl->setPixmap( "config" ); 47 * lbl->setPixmap( "config" );
48 * QWhatsThis::add( lbl, tr("Click here to do something") ); 48 * QWhatsThis::add( lbl, tr("Click here to do something") );
49 * </pre> 49 * </pre>
50 * 50 *
51 * @short A Label behaving as button 51 * @short A Label behaving as button
52 * @author Hakan Ardo, Maximillian Reiß ( harlekin@handhelds.org ) 52 * @author Hakan Ardo, Maximillian Reiß ( harlekin@handhelds.org )
53 * @see QLabel 53 * @see QLabel
54 * @see QPushButton 54 * @see QPushButton
55 * @see QToggleButton 55 * @see QToggleButton
56 * @version 1.0 56 * @version 1.0
57 */ 57 */
58 58
59class OClickableLabel: public QLabel 59class OClickableLabel: public QLabel
60{ 60{
61 Q_OBJECT 61 Q_OBJECT
62public: 62public:
63 OClickableLabel(QWidget* parent = 0, const char* name = 0, 63 OClickableLabel(QWidget* parent = 0, const char* name = 0,
64 WFlags fl = 0); 64 WFlags fl = 0);
65 void setToggleButton(bool t); 65 void setToggleButton(bool t);
66 66
67protected: 67protected:
68 /** @internal */ 68 /** @internal */
69 void mousePressEvent( QMouseEvent *e ); 69 void mousePressEvent( QMouseEvent *e );
70 /** @internal */ 70 /** @internal */
71 void mouseReleaseEvent( QMouseEvent *e ); 71 void mouseReleaseEvent( QMouseEvent *e );
72 /** @internal */ 72 /** @internal */
73 void mouseMoveEvent( QMouseEvent *e ); 73 void mouseMoveEvent( QMouseEvent *e );
74 74
75public slots: 75public slots:
76 void setOn(bool on); 76 void setOn(bool on);
77signals: 77signals:
78 /** 78 /**
79 * emitted when the labels gets clicked 79 * emitted when the labels gets clicked
80 */ 80 */
81 void clicked(); 81 void clicked();
82 82
83 /** 83 /**
84 * emitted when the labels gets toggled 84 * emitted when the labels gets toggled
85 * @param on the new new state of the label 85 * @param on the new new state of the label
86 */ 86 */
87 void toggled(bool on); 87 void toggled(bool on);
88private: 88private:
89 bool isToggle : 1; 89 bool isToggle : 1;
90 bool isDown : 1; 90 bool isDown : 1;
91 bool textInverted : 1; 91 bool textInverted : 1;
92 92
93 void showState(bool on); 93 void showState(bool on);
94 void setInverted(bool on); 94 void setInverted(bool on);
95 95
96private: 96private:
97 class Private; 97 class Private;
98 Private *d; // private d pointer 98 Private *d; // private d pointer
99}; 99};
100 100
101}; 101}
102}
102 103
103#endif 104#endif
diff --git a/libopie2/opieui/odialog.cpp b/libopie2/opieui/odialog.cpp
index 4d269d4..27f8d20 100644
--- a/libopie2/opieui/odialog.cpp
+++ b/libopie2/opieui/odialog.cpp
@@ -1,55 +1,57 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> 3              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#include <opie2/odialog.h> 31#include <opie2/odialog.h>
32 32
33#warning Make Margin and Spacing device dependend and configurable! 33#warning Make Margin and Spacing device dependend and configurable!
34 34
35using namespace Opie::Ui;
36
35int ODialog::mMarginSize = 5; 37int ODialog::mMarginSize = 5;
36int ODialog::mSpacingSize = 2; 38int ODialog::mSpacingSize = 2;
37 39
38ODialog::ODialog(QWidget *parent, const char *name, bool modal, WFlags f) 40ODialog::ODialog(QWidget *parent, const char *name, bool modal, WFlags f)
39 :QDialog(parent, name, modal, f) 41 :QDialog(parent, name, modal, f)
40{ 42{
41 // d = new ODialogPrivate(); 43 // d = new ODialogPrivate();
42} 44}
43 45
44int ODialog::marginHint() 46int ODialog::marginHint()
45{ 47{
46 return( mMarginSize ); 48 return( mMarginSize );
47} 49}
48 50
49 51
50int ODialog::spacingHint() 52int ODialog::spacingHint()
51{ 53{
52 return( mSpacingSize ); 54 return( mSpacingSize );
53} 55}
54 56
55// Placeholder for even more sophisticed things 57// Placeholder for even more sophisticed things
diff --git a/libopie2/opieui/odialog.h b/libopie2/opieui/odialog.h
index ceff612..57f534c 100644
--- a/libopie2/opieui/odialog.h
+++ b/libopie2/opieui/odialog.h
@@ -1,91 +1,96 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> 3              (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#ifndef ODIALOG_H 31#ifndef ODIALOG_H
32#define ODIALOG_H 32#define ODIALOG_H
33 33
34class QLayoutItem; 34class QLayoutItem;
35 35
36#include <qdialog.h> 36#include <qdialog.h>
37 37
38/** 38/**
39 * Dialog with extended nonmodal support and methods for OPIE standard 39 * Dialog with extended nonmodal support and methods for OPIE standard
40 * compliance. 40 * compliance.
41 * 41 *
42 * The @ref marginHint() and @ref spacingHint() sizes shall be used 42 * The @ref marginHint() and @ref spacingHint() sizes shall be used
43 * whenever you layout the interior of a dialog. One special note. If 43 * whenever you layout the interior of a dialog. One special note. If
44 * you make your own action buttons (OK, Cancel etc), the space 44 * you make your own action buttons (OK, Cancel etc), the space
45 * beteween the buttons shall be @ref spacingHint(), whereas the space 45 * beteween the buttons shall be @ref spacingHint(), whereas the space
46 * above, below, to the right and to the left shall be @ref marginHint(). 46 * above, below, to the right and to the left shall be @ref marginHint().
47 * If you add a separator line above the buttons, there shall be a 47 * If you add a separator line above the buttons, there shall be a
48 * @ref marginHint() between the buttons and the separator and a 48 * @ref marginHint() between the buttons and the separator and a
49 * @ref marginHint() above the separator as well. 49 * @ref marginHint() above the separator as well.
50 * 50 *
51 * @author Michael 'Mickey' Lauer <mickey@Vanille.de> 51 * @author Michael 'Mickey' Lauer <mickey@Vanille.de>
52 */ 52 */
53 53
54 // lets fix up Qt instead! Size does matter. -zecke 54 // lets fix up Qt instead! Size does matter. -zecke
55 // while that may be true, reducing maintainance effort for the future does also matter - 55 // while that may be true, reducing maintainance effort for the future does also matter -
56 // and I believe that maintaining a patch against QtE is more work than our classes -mml 56 // and I believe that maintaining a patch against QtE is more work than our classes -mml
57 57
58namespace Opie {
59namespace Ui {
60
58class ODialog : public QDialog 61class ODialog : public QDialog
59{ 62{
60 Q_OBJECT 63 Q_OBJECT
61 64
62 public: 65 public:
63 66
64 /** 67 /**
65 * Constructor. 68 * Constructor.
66 * 69 *
67 * Takes the same arguments as @ref QDialog. 70 * Takes the same arguments as @ref QDialog.
68 */ 71 */
69 ODialog(QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags f = 0); 72 ODialog(QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags f = 0);
70 73
71 /** 74 /**
72 * Return the number of pixels you shall use between a 75 * Return the number of pixels you shall use between a
73 * dialog edge and the outermost widget(s) according to the KDE standard. 76 * dialog edge and the outermost widget(s) according to the KDE standard.
74 **/ 77 **/
75 static int marginHint(); 78 static int marginHint();
76 79
77 /** 80 /**
78 * Return the number of pixels you shall use between 81 * Return the number of pixels you shall use between
79 * widgets inside a dialog according to the KDE standard. 82 * widgets inside a dialog according to the KDE standard.
80 */ 83 */
81 static int spacingHint(); 84 static int spacingHint();
82 85
83 private: 86 private:
84 static int mMarginSize; 87 static int mMarginSize;
85 static int mSpacingSize; 88 static int mSpacingSize;
86 89
87 class ODialogPrivate; 90 class ODialogPrivate;
88 ODialogPrivate *d; 91 ODialogPrivate *d;
89 92
90}; 93};
94}
95}
91#endif // ODIALOG_H 96#endif // ODIALOG_H
diff --git a/libopie2/opieui/ofontselector.cpp b/libopie2/opieui/ofontselector.cpp
index f93781f..b19c26e 100644
--- a/libopie2/opieui/ofontselector.cpp
+++ b/libopie2/opieui/ofontselector.cpp
@@ -1,428 +1,429 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Robert Griebl <sandman@handhelds.org> 3 Copyright (C) Robert Griebl <sandman@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30/* OPIE */ 30/* OPIE */
31#include <opie2/ofontselector.h> 31#include <opie2/ofontselector.h>
32#include <qpe/fontdatabase.h> 32#include <qpe/fontdatabase.h>
33 33
34/* QT */ 34/* QT */
35#include <qlayout.h> 35#include <qlayout.h>
36#include <qlistbox.h> 36#include <qlistbox.h>
37#include <qcombobox.h> 37#include <qcombobox.h>
38#include <qlabel.h> 38#include <qlabel.h>
39#include <qmultilineedit.h> 39#include <qmultilineedit.h>
40 40
41using namespace Opie;
42 41
43namespace Opie 42namespace Opie {
44{ 43namespace Ui {
44namespace Private {
45 45
46class OFontSelectorPrivate 46class OFontSelectorPrivate
47{ 47{
48public: 48public:
49 QListBox * m_font_family_list; 49 QListBox * m_font_family_list;
50 QComboBox * m_font_style_list; 50 QComboBox * m_font_style_list;
51 QComboBox * m_font_size_list; 51 QComboBox * m_font_size_list;
52 QMultiLineEdit *m_preview; 52 QMultiLineEdit *m_preview;
53 53
54 bool m_pointbug : 1; 54 bool m_pointbug : 1;
55 55
56 FontDatabase m_fdb; 56 FontDatabase m_fdb;
57}; 57};
58 58
59};
60
61namespace
62{
63
64class FontListItem : public QListBoxText 59class FontListItem : public QListBoxText
65{ 60{
66public: 61public:
67 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText() 62 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText()
68 { 63 {
69 m_name = t; 64 m_name = t;
70 m_styles = styles; 65 m_styles = styles;
71 m_sizes = sizes; 66 m_sizes = sizes;
72 67
73 QString str = t; 68 QString str = t;
74 str [0] = str [0]. upper(); 69 str [0] = str [0]. upper();
75 setText ( str ); 70 setText ( str );
76 } 71 }
77 72
78 QString family() const 73 QString family() const
79 { 74 {
80 return m_name; 75 return m_name;
81 } 76 }
82 77
83 const QStringList &styles() const 78 const QStringList &styles() const
84 { 79 {
85 return m_styles; 80 return m_styles;
86 } 81 }
87 82
88 const QValueList<int> &sizes() const 83 const QValueList<int> &sizes() const
89 { 84 {
90 return m_sizes; 85 return m_sizes;
91 } 86 }
92 87
93private: 88private:
94 QStringList m_styles; 89 QStringList m_styles;
95 QValueList<int> m_sizes; 90 QValueList<int> m_sizes;
96 QString m_name; 91 QString m_name;
97}; 92};
93}
94}
95}
96
98 97
98using namespace Opie::Ui;
99using namespace Opie::Ui::Private;
99 100
100static int findItemCB( QComboBox *box, const QString &str ) 101static int findItemCB( QComboBox *box, const QString &str )
101{ 102{
102 for ( int i = 0; i < box->count(); i++ ) 103 for ( int i = 0; i < box->count(); i++ )
103 { 104 {
104 if ( box->text ( i ) == str ) 105 if ( box->text ( i ) == str )
105 return i; 106 return i;
106 } 107 }
107 return -1; 108 return -1;
108} 109}
109 110
110}
111/* static same as anon. namespace */ 111/* static same as anon. namespace */
112static int qt_version() 112static int qt_version()
113{ 113{
114 const char *qver = qVersion(); 114 const char *qver = qVersion();
115 115
116 return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' ); 116 return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' );
117} 117}
118 118
119/** 119/**
120 * Constructs the Selector object 120 * Constructs the Selector object
121 * @param withpreview If a font preview should be given 121 * @param withpreview If a font preview should be given
122 * @param parent The parent of the Font Selector 122 * @param parent The parent of the Font Selector
123 * @param name The name of the object 123 * @param name The name of the object
124 * @param fl WidgetFlags 124 * @param fl WidgetFlags
125 */ 125 */
126OFontSelector::OFontSelector( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) 126OFontSelector::OFontSelector( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl )
127{ 127{
128 d = new OFontSelectorPrivate(); 128 d = new OFontSelectorPrivate();
129 129
130 QGridLayout *gridLayout = new QGridLayout( this, 0, 0, 4, 4 ); 130 QGridLayout *gridLayout = new QGridLayout( this, 0, 0, 4, 4 );
131 gridLayout->setRowStretch( 4, 10 ); 131 gridLayout->setRowStretch( 4, 10 );
132 132
133 d->m_font_family_list = new QListBox( this, "FontListBox" ); 133 d->m_font_family_list = new QListBox( this, "FontListBox" );
134 gridLayout->addMultiCellWidget( d->m_font_family_list, 0, 4, 0, 0 ); 134 gridLayout->addMultiCellWidget( d->m_font_family_list, 0, 4, 0, 0 );
135 connect( d->m_font_family_list, SIGNAL( highlighted(int) ), this, SLOT( fontFamilyClicked(int) ) ); 135 connect( d->m_font_family_list, SIGNAL( highlighted(int) ), this, SLOT( fontFamilyClicked(int) ) );
136 136
137 QLabel *label = new QLabel( tr( "Style" ), this ); 137 QLabel *label = new QLabel( tr( "Style" ), this );
138 gridLayout->addWidget( label, 0, 1 ); 138 gridLayout->addWidget( label, 0, 1 );
139 139
140 d->m_font_style_list = new QComboBox( this, "StyleListBox" ); 140 d->m_font_style_list = new QComboBox( this, "StyleListBox" );
141 connect( d->m_font_style_list, SIGNAL( activated(int) ), this, SLOT( fontStyleClicked(int) ) ); 141 connect( d->m_font_style_list, SIGNAL( activated(int) ), this, SLOT( fontStyleClicked(int) ) );
142 gridLayout->addWidget( d->m_font_style_list, 1, 1 ); 142 gridLayout->addWidget( d->m_font_style_list, 1, 1 );
143 143
144 label = new QLabel( tr( "Size" ), this ); 144 label = new QLabel( tr( "Size" ), this );
145 gridLayout->addWidget( label, 2, 1 ); 145 gridLayout->addWidget( label, 2, 1 );
146 146
147 d->m_font_size_list = new QComboBox( this, "SizeListBox" ); 147 d->m_font_size_list = new QComboBox( this, "SizeListBox" );
148 connect( d->m_font_size_list, SIGNAL( activated(int) ), 148 connect( d->m_font_size_list, SIGNAL( activated(int) ),
149 this, SLOT( fontSizeClicked(int) ) ); 149 this, SLOT( fontSizeClicked(int) ) );
150 gridLayout->addWidget( d->m_font_size_list, 3, 1 ); 150 gridLayout->addWidget( d->m_font_size_list, 3, 1 );
151 151
152 d->m_pointbug = ( qt_version() <= 233 ); 152 d->m_pointbug = ( qt_version() <= 233 );
153 153
154 if ( withpreview ) 154 if ( withpreview )
155 { 155 {
156 d->m_preview = new QMultiLineEdit ( this, "Preview" ); 156 d->m_preview = new QMultiLineEdit ( this, "Preview" );
157 d->m_preview->setAlignment ( AlignCenter ); 157 d->m_preview->setAlignment ( AlignCenter );
158 d->m_preview->setWordWrap ( QMultiLineEdit::WidgetWidth ); 158 d->m_preview->setWordWrap ( QMultiLineEdit::WidgetWidth );
159 d->m_preview->setMargin ( 3 ); 159 d->m_preview->setMargin ( 3 );
160 d->m_preview->setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); 160 d->m_preview->setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" ));
161 gridLayout->addRowSpacing ( 5, 4 ); 161 gridLayout->addRowSpacing ( 5, 4 );
162 gridLayout->addMultiCellWidget ( d->m_preview, 6, 6, 0, 1 ); 162 gridLayout->addMultiCellWidget ( d->m_preview, 6, 6, 0, 1 );
163 gridLayout->setRowStretch ( 6, 5 ); 163 gridLayout->setRowStretch ( 6, 5 );
164 } 164 }
165 else 165 else
166 d->m_preview = 0; 166 d->m_preview = 0;
167 167
168 loadFonts ( d->m_font_family_list ); 168 loadFonts ( d->m_font_family_list );
169} 169}
170 170
171OFontSelector::~OFontSelector() 171OFontSelector::~OFontSelector()
172{ 172{
173 delete d; 173 delete d;
174} 174}
175 175
176/** 176/**
177 * This methods tries to set the font 177 * This methods tries to set the font
178 * @param f The wishes font 178 * @param f The wishes font
179 * @return success or failure 179 * @return success or failure
180 */ 180 */
181bool OFontSelector::setSelectedFont ( const QFont &f ) 181bool OFontSelector::setSelectedFont ( const QFont &f )
182{ 182{
183 return setSelectedFont ( f. family(), d->m_fdb. styleString ( f ), f. pointSize(), QFont::encodingName ( f. charSet())); 183 return setSelectedFont ( f. family(), d->m_fdb. styleString ( f ), f. pointSize(), QFont::encodingName ( f. charSet()));
184} 184}
185 185
186 186
187/** 187/**
188 * This is an overloaded method @see setSelectedFont 188 * This is an overloaded method @see setSelectedFont
189 * @param familyStr The family of the font 189 * @param familyStr The family of the font
190 * @param styleStr The style of the font 190 * @param styleStr The style of the font
191 * @param sizeVal The size of font 191 * @param sizeVal The size of font
192 * @param charset The charset to be used. Will be deprecated by QT3 192 * @param charset The charset to be used. Will be deprecated by QT3
193 */ 193 */
194bool OFontSelector::setSelectedFont( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) 194bool OFontSelector::setSelectedFont( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset )
195{ 195{
196 QString sizeStr = QString::number ( sizeVal ); 196 QString sizeStr = QString::number ( sizeVal );
197 197
198 QListBoxItem *family = d->m_font_family_list->findItem ( familyStr ); 198 QListBoxItem *family = d->m_font_family_list->findItem ( familyStr );
199 if ( !family ) 199 if ( !family )
200 family = d->m_font_family_list->findItem ( "Helvetica" ); 200 family = d->m_font_family_list->findItem ( "Helvetica" );
201 if ( !family ) 201 if ( !family )
202 family = d->m_font_family_list->firstItem(); 202 family = d->m_font_family_list->firstItem();
203 d->m_font_family_list->setCurrentItem ( family ); 203 d->m_font_family_list->setCurrentItem ( family );
204 fontFamilyClicked ( d->m_font_family_list->index ( family )); 204 fontFamilyClicked ( d->m_font_family_list->index ( family ));
205 205
206 int style = findItemCB ( d->m_font_style_list, styleStr ); 206 int style = findItemCB ( d->m_font_style_list, styleStr );
207 if ( style < 0 ) 207 if ( style < 0 )
208 style = findItemCB ( d->m_font_style_list, "Regular" ); 208 style = findItemCB ( d->m_font_style_list, "Regular" );
209 if ( style < 0 && d->m_font_style_list->count() > 0 ) 209 if ( style < 0 && d->m_font_style_list->count() > 0 )
210 style = 0; 210 style = 0;
211 d->m_font_style_list->setCurrentItem ( style ); 211 d->m_font_style_list->setCurrentItem ( style );
212 fontStyleClicked ( style ); 212 fontStyleClicked ( style );
213 213
214 int size = findItemCB ( d->m_font_size_list, sizeStr ); 214 int size = findItemCB ( d->m_font_size_list, sizeStr );
215 if ( size < 0 ) 215 if ( size < 0 )
216 size = findItemCB ( d->m_font_size_list, "10" ); 216 size = findItemCB ( d->m_font_size_list, "10" );
217 if ( size < 0 && d->m_font_size_list->count() > 0 ) 217 if ( size < 0 && d->m_font_size_list->count() > 0 )
218 size = 0; 218 size = 0;
219 d->m_font_size_list->setCurrentItem ( size ); 219 d->m_font_size_list->setCurrentItem ( size );
220 fontSizeClicked ( size ); 220 fontSizeClicked ( size );
221 221
222 return (( family ) && ( style >= 0 ) && ( size >= 0 )); 222 return (( family ) && ( style >= 0 ) && ( size >= 0 ));
223} 223}
224 224
225/** 225/**
226 * This method returns the name, style and size of the currently selected 226 * This method returns the name, style and size of the currently selected
227 * font or false if no font is selected 227 * font or false if no font is selected
228 * @param family The font family will be written there 228 * @param family The font family will be written there
229 * @param style The style will be written there 229 * @param style The style will be written there
230 * @param size The size will be written there 230 * @param size The size will be written there
231 * @return success or failure 231 * @return success or failure
232 */ 232 */
233bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) 233bool OFontSelector::selectedFont ( QString &family, QString &style, int &size )
234{ 234{
235 QString dummy; 235 QString dummy;
236 return selectedFont ( family, style, size, dummy ); 236 return selectedFont ( family, style, size, dummy );
237} 237}
238 238
239 239
240/** 240/**
241 * This method does return the font family or QString::null if there is 241 * This method does return the font family or QString::null if there is
242 * no font item selected 242 * no font item selected
243 * @return the font family 243 * @return the font family
244 */ 244 */
245QString OFontSelector::fontFamily() const 245QString OFontSelector::fontFamily() const
246{ 246{
247 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); 247 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
248 248
249 return fli ? fli->family() : QString::null; 249 return fli ? fli->family() : QString::null;
250} 250}
251 251
252/** 252/**
253 * This method will return the style of the font or QString::null 253 * This method will return the style of the font or QString::null
254 * @return the style of the font 254 * @return the style of the font
255 */ 255 */
256QString OFontSelector::fontStyle() const 256QString OFontSelector::fontStyle() const
257{ 257{
258 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); 258 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
259 int fst = d->m_font_style_list->currentItem(); 259 int fst = d->m_font_style_list->currentItem();
260 260
261 return ( fli && fst >= 0 ) ? fli->styles() [fst] : QString::null; 261 return ( fli && fst >= 0 ) ? fli->styles() [fst] : QString::null;
262} 262}
263 263
264/** 264/**
265 * This method will return the font size or 10 if no font size is available 265 * This method will return the font size or 10 if no font size is available
266 */ 266 */
267int OFontSelector::fontSize() const 267int OFontSelector::fontSize() const
268{ 268{
269 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); 269 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
270 int fsi = d->m_font_size_list->currentItem(); 270 int fsi = d->m_font_size_list->currentItem();
271 271
272 return ( fli && fsi >= 0 ) ? fli->sizes() [fsi] : 10; 272 return ( fli && fsi >= 0 ) ? fli->sizes() [fsi] : 10;
273} 273}
274 274
275/** 275/**
276 * returns the charset of the font or QString::null 276 * returns the charset of the font or QString::null
277 */ 277 */
278QString OFontSelector::fontCharSet() const 278QString OFontSelector::fontCharSet() const
279{ 279{
280 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); 280 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
281 281
282 return fli ? d->m_fdb. charSets ( fli->family()) [0] : QString::null; 282 return fli ? d->m_fdb. charSets ( fli->family()) [0] : QString::null;
283} 283}
284 284
285/** 285/**
286 * Overloaded member function see above 286 * Overloaded member function see above
287 * @see selectedFont 287 * @see selectedFont
288 */ 288 */
289bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) 289bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset )
290{ 290{
291 int ffa = d->m_font_family_list->currentItem(); 291 int ffa = d->m_font_family_list->currentItem();
292 int fst = d->m_font_style_list->currentItem(); 292 int fst = d->m_font_style_list->currentItem();
293 int fsi = d->m_font_size_list->currentItem(); 293 int fsi = d->m_font_size_list->currentItem();
294 294
295 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa ); 295 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa );
296 296
297 if ( fli ) 297 if ( fli )
298 { 298 {
299 family = fli->family(); 299 family = fli->family();
300 style = fst >= 0 ? fli->styles() [fst] : QString::null; 300 style = fst >= 0 ? fli->styles() [fst] : QString::null;
301 size = fsi >= 0 ? fli->sizes() [fsi] : 10; 301 size = fsi >= 0 ? fli->sizes() [fsi] : 10;
302 charset = d->m_fdb. charSets ( fli->family()) [0]; 302 charset = d->m_fdb. charSets ( fli->family()) [0];
303 303
304 return true; 304 return true;
305 } 305 }
306 else 306 else
307 return false; 307 return false;
308} 308}
309 309
310void OFontSelector::loadFonts ( QListBox *list ) 310void OFontSelector::loadFonts ( QListBox *list )
311{ 311{
312 QStringList f = d->m_fdb. families(); 312 QStringList f = d->m_fdb. families();
313 313
314 for ( QStringList::ConstIterator it = f. begin(); it != f. end(); ++it ) 314 for ( QStringList::ConstIterator it = f. begin(); it != f. end(); ++it )
315 { 315 {
316 QValueList <int> ps = d->m_fdb. pointSizes ( *it ); 316 QValueList <int> ps = d->m_fdb. pointSizes ( *it );
317 317
318 if ( d->m_pointbug ) 318 if ( d->m_pointbug )
319 { 319 {
320 for ( QValueList <int>::Iterator it = ps. begin(); it != ps. end(); it++ ) 320 for ( QValueList <int>::Iterator it = ps. begin(); it != ps. end(); it++ )
321 *it /= 10; 321 *it /= 10;
322 } 322 }
323 323
324 list->insertItem ( new FontListItem ( *it, d->m_fdb. styles ( *it ), ps )); 324 list->insertItem ( new FontListItem ( *it, d->m_fdb. styles ( *it ), ps ));
325 } 325 }
326} 326}
327 327
328void OFontSelector::fontFamilyClicked ( int index ) 328void OFontSelector::fontFamilyClicked ( int index )
329{ 329{
330 QString oldstyle = d->m_font_style_list->currentText(); 330 QString oldstyle = d->m_font_style_list->currentText();
331 QString oldsize = d->m_font_size_list->currentText(); 331 QString oldsize = d->m_font_size_list->currentText();
332 332
333 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( index ); 333 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( index );
334 334
335 d->m_font_style_list->clear(); 335 d->m_font_style_list->clear();
336 d->m_font_style_list->insertStringList ( fli->styles()); 336 d->m_font_style_list->insertStringList ( fli->styles());
337 d->m_font_style_list->setEnabled ( !fli->styles(). isEmpty()); 337 d->m_font_style_list->setEnabled ( !fli->styles(). isEmpty());
338 338
339 int i; 339 int i;
340 340
341 i = findItemCB ( d->m_font_style_list, oldstyle ); 341 i = findItemCB ( d->m_font_style_list, oldstyle );
342 if ( i < 0 ) 342 if ( i < 0 )
343 i = findItemCB ( d->m_font_style_list, "Regular" ); 343 i = findItemCB ( d->m_font_style_list, "Regular" );
344 if (( i < 0 ) && ( d->m_font_style_list->count() > 0 )) 344 if (( i < 0 ) && ( d->m_font_style_list->count() > 0 ))
345 i = 0; 345 i = 0;
346 346
347 if ( i >= 0 ) 347 if ( i >= 0 )
348 { 348 {
349 d->m_font_style_list->setCurrentItem ( i ); 349 d->m_font_style_list->setCurrentItem ( i );
350 fontStyleClicked ( i ); 350 fontStyleClicked ( i );
351 } 351 }
352 352
353 d->m_font_size_list->clear(); 353 d->m_font_size_list->clear();
354 QValueList<int> sl = fli->sizes(); 354 QValueList<int> sl = fli->sizes();
355 355
356 for ( QValueList<int>::Iterator it = sl. begin(); it != sl. end(); ++it ) 356 for ( QValueList<int>::Iterator it = sl. begin(); it != sl. end(); ++it )
357 d->m_font_size_list->insertItem ( QString::number ( *it )); 357 d->m_font_size_list->insertItem ( QString::number ( *it ));
358 358
359 i = findItemCB ( d->m_font_size_list, oldsize ); 359 i = findItemCB ( d->m_font_size_list, oldsize );
360 if ( i < 0 ) 360 if ( i < 0 )
361 i = findItemCB ( d->m_font_size_list, "10" ); 361 i = findItemCB ( d->m_font_size_list, "10" );
362 if (( i < 0 ) && ( d->m_font_size_list->count() > 0 )) 362 if (( i < 0 ) && ( d->m_font_size_list->count() > 0 ))
363 i = 0; 363 i = 0;
364 364
365 if ( i >= 0 ) 365 if ( i >= 0 )
366 { 366 {
367 d->m_font_size_list->setCurrentItem ( i ); 367 d->m_font_size_list->setCurrentItem ( i );
368 fontSizeClicked ( i ); 368 fontSizeClicked ( i );
369 } 369 }
370 changeFont(); 370 changeFont();
371} 371}
372 372
373void OFontSelector::fontStyleClicked ( int /*index*/ ) 373void OFontSelector::fontStyleClicked ( int /*index*/ )
374{ 374{
375 changeFont(); 375 changeFont();
376} 376}
377 377
378void OFontSelector::fontSizeClicked ( int /*index*/ ) 378void OFontSelector::fontSizeClicked ( int /*index*/ )
379{ 379{
380 changeFont(); 380 changeFont();
381} 381}
382 382
383void OFontSelector::changeFont() 383void OFontSelector::changeFont()
384{ 384{
385 QFont f = selectedFont(); 385 QFont f = selectedFont();
386 386
387 if ( d->m_preview ) 387 if ( d->m_preview )
388 d->m_preview->setFont ( f ); 388 d->m_preview->setFont ( f );
389 389
390 emit fontSelected ( f ); 390 emit fontSelected ( f );
391} 391}
392 392
393/** 393/**
394 * Return the selected font 394 * Return the selected font
395 */ 395 */
396QFont OFontSelector::selectedFont() 396QFont OFontSelector::selectedFont()
397{ 397{
398 int ffa = d->m_font_family_list->currentItem(); 398 int ffa = d->m_font_family_list->currentItem();
399 int fst = d->m_font_style_list->currentItem(); 399 int fst = d->m_font_style_list->currentItem();
400 int fsi = d->m_font_size_list->currentItem(); 400 int fsi = d->m_font_size_list->currentItem();
401 401
402 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa ); 402 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa );
403 403
404 if ( fli ) 404 if ( fli )
405 { 405 {
406 return d->m_fdb. font ( fli->family(), \ 406 return d->m_fdb. font ( fli->family(), \
407 fst >= 0 ? fli->styles() [fst] : QString::null, \ 407 fst >= 0 ? fli->styles() [fst] : QString::null, \
408 fsi >= 0 ? fli->sizes() [fsi] : 10, \ 408 fsi >= 0 ? fli->sizes() [fsi] : 10, \
409 d->m_fdb. charSets ( fli->family()) [0] ); 409 d->m_fdb. charSets ( fli->family()) [0] );
410 } 410 }
411 else 411 else
412 return QFont(); 412 return QFont();
413} 413}
414 414
415void OFontSelector::resizeEvent ( QResizeEvent *re ) 415void OFontSelector::resizeEvent ( QResizeEvent *re )
416{ 416{
417 if ( d->m_preview ) 417 if ( d->m_preview )
418 { 418 {
419 d->m_preview->setMinimumHeight ( 1 ); 419 d->m_preview->setMinimumHeight ( 1 );
420 d->m_preview->setMaximumHeight ( 32767 ); 420 d->m_preview->setMaximumHeight ( 32767 );
421 } 421 }
422 422
423 QWidget::resizeEvent ( re ); 423 QWidget::resizeEvent ( re );
424 424
425 if ( d->m_preview ) 425 if ( d->m_preview )
426 d->m_preview->setFixedHeight ( d->m_preview->height()); 426 d->m_preview->setFixedHeight ( d->m_preview->height());
427 427
428} 428}
429
diff --git a/libopie2/opieui/ofontselector.h b/libopie2/opieui/ofontselector.h
index ad51819..1d97233 100644
--- a/libopie2/opieui/ofontselector.h
+++ b/libopie2/opieui/ofontselector.h
@@ -1,104 +1,106 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Robert Griebl <sandman@handhelds.org> 3 Copyright (C) Robert Griebl <sandman@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#ifndef OFONTSELECTOR_H 30#ifndef OFONTSELECTOR_H
31#define OFONTSELECTOR_H 31#define OFONTSELECTOR_H
32 32
33/* QT */ 33/* QT */
34#include <qwidget.h> 34#include <qwidget.h>
35 35
36class QListBox; 36class QListBox;
37 37
38namespace Opie 38namespace Opie {
39{ 39namespace Ui {
40 40namespace Private {
41class OFontSelectorPrivate; 41class OFontSelectorPrivate;
42}
42 43
43/** 44/**
44 * This class lets you chose a Font out of a list of Fonts. 45 * This class lets you chose a Font out of a list of Fonts.
45 * It can show a preview too. This selector will use all available 46 * It can show a preview too. This selector will use all available
46 * fonts 47 * fonts
47 * 48 *
48 * 49 *
49 * @short A widget to select a font 50 * @short A widget to select a font
50 * @see QWidget 51 * @see QWidget
51 * @see QFont 52 * @see QFont
52 * @author Rober Griebl 53 * @author Rober Griebl
53 */ 54 */
54class OFontSelector : public QWidget 55class OFontSelector : public QWidget
55{ 56{
56 Q_OBJECT 57 Q_OBJECT
57 58
58public: 59public:
59 OFontSelector ( bool withpreview, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 60 OFontSelector ( bool withpreview, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
60 virtual ~OFontSelector ( ); 61 virtual ~OFontSelector ( );
61 62
62 bool selectedFont ( QString &family, QString &style, int &size ); 63 bool selectedFont ( QString &family, QString &style, int &size );
63 bool selectedFont ( QString &family, QString &style, int &size, QString &charset ); 64 bool selectedFont ( QString &family, QString &style, int &size, QString &charset );
64 65
65 QFont selectedFont ( ); 66 QFont selectedFont ( );
66 67
67 bool setSelectedFont ( const QFont & ); 68 bool setSelectedFont ( const QFont & );
68 bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 ); 69 bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 );
69 70
70 QString fontFamily ( ) const; 71 QString fontFamily ( ) const;
71 QString fontStyle ( ) const; 72 QString fontStyle ( ) const;
72 int fontSize ( ) const; 73 int fontSize ( ) const;
73 QString fontCharSet ( ) const; 74 QString fontCharSet ( ) const;
74 75
75signals: 76signals:
76 /** 77 /**
77 * This signal gets emitted when a font got chosen 78 * This signal gets emitted when a font got chosen
78 */ 79 */
79 void fontSelected ( const QFont & ); 80 void fontSelected ( const QFont & );
80 81
81protected slots: 82protected slots:
82 /** @internal */ 83 /** @internal */
83 virtual void fontFamilyClicked ( int ); 84 virtual void fontFamilyClicked ( int );
84 /** @internal */ 85 /** @internal */
85 virtual void fontStyleClicked ( int ); 86 virtual void fontStyleClicked ( int );
86 /** @internal */ 87 /** @internal */
87 virtual void fontSizeClicked ( int ); 88 virtual void fontSizeClicked ( int );
88 89
89protected: 90protected:
90 virtual void resizeEvent ( QResizeEvent *re ); 91 virtual void resizeEvent ( QResizeEvent *re );
91 92
92private: 93private:
93 void loadFonts ( QListBox * ); 94 void loadFonts ( QListBox * );
94 95
95 void changeFont ( ); 96 void changeFont ( );
96 97
97private: 98private:
98 OFontSelectorPrivate *d; 99 Private::OFontSelectorPrivate *d;
99}; 100};
100 101
101}; 102}
103}
102 104
103#endif 105#endif
104 106
diff --git a/libopie2/opieui/oimageeffect.cpp b/libopie2/opieui/oimageeffect.cpp
index 9a58bb9..be47eb2 100644
--- a/libopie2/opieui/oimageeffect.cpp
+++ b/libopie2/opieui/oimageeffect.cpp
@@ -1,3768 +1,3773 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1998, 1999, 2001, 2002 Daniel M. Duley <mosfet@kde.org> 2 Copyright (C) 1998, 1999, 2001, 2002 Daniel M. Duley <mosfet@kde.org>
3 (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> 3 (C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
4 (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> 4 (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org>
5 (C) 2000 Josef Weidendorfer <weidendo@in.tum.de> 5 (C) 2000 Josef Weidendorfer <weidendo@in.tum.de>
6 6
7Redistribution and use in source and binary forms, with or without 7Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions 8modification, are permitted provided that the following conditions
9are met: 9are met:
10 10
111. Redistributions of source code must retain the above copyright 111. Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer. 12 notice, this list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright 132. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the 14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution. 15 documentation and/or other materials provided with the distribution.
16 16
17THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28*/ 28*/
29 29
30// $Id$ 30// $Id$
31 31
32#include <math.h> 32#include <math.h>
33 33
34#include <qimage.h> 34#include <qimage.h>
35#include <stdlib.h> 35#include <stdlib.h>
36 36
37#include <opie2/oimageeffect.h> 37#include <opie2/oimageeffect.h>
38#include <opie2/odebug.h> 38#include <opie2/odebug.h>
39 39
40#define MaxRGB 255L 40#define MaxRGB 255L
41#define DegreesToRadians(x) ((x)*M_PI/180.0) 41#define DegreesToRadians(x) ((x)*M_PI/180.0)
42 42
43using namespace std; 43using namespace std;
44using namespace Opie::Core;
45
46namespace Opie {
47namespace Ui {
44 48
45inline unsigned int intensityValue(unsigned int color) 49inline unsigned int intensityValue(unsigned int color)
46{ 50{
47 return((unsigned int)((0.299*qRed(color) + 51 return((unsigned int)((0.299*qRed(color) +
48 0.587*qGreen(color) + 52 0.587*qGreen(color) +
49 0.1140000000000001*qBlue(color)))); 53 0.1140000000000001*qBlue(color))));
50} 54}
51 55
52//====================================================================== 56//======================================================================
53// 57//
54// Gradient effects 58// Gradient effects
55// 59//
56//====================================================================== 60//======================================================================
57 61
58QImage OImageEffect::gradient(const QSize &size, const QColor &ca, 62QImage OImageEffect::gradient(const QSize &size, const QColor &ca,
59 const QColor &cb, GradientType eff, int ncols) 63 const QColor &cb, GradientType eff, int ncols)
60{ 64{
61 int rDiff, gDiff, bDiff; 65 int rDiff, gDiff, bDiff;
62 int rca, gca, bca, rcb, gcb, bcb; 66 int rca, gca, bca, rcb, gcb, bcb;
63 67
64 QImage image(size, 32); 68 QImage image(size, 32);
65 69
66 if (size.width() == 0 || size.height() == 0) { 70 if (size.width() == 0 || size.height() == 0) {
67 odebug << "WARNING: OImageEffect::gradient: invalid image" << oendl; 71 odebug << "WARNING: OImageEffect::gradient: invalid image" << oendl;
68 return image; 72 return image;
69 } 73 }
70 74
71 register int x, y; 75 register int x, y;
72 76
73 rDiff = (rcb = cb.red()) - (rca = ca.red()); 77 rDiff = (rcb = cb.red()) - (rca = ca.red());
74 gDiff = (gcb = cb.green()) - (gca = ca.green()); 78 gDiff = (gcb = cb.green()) - (gca = ca.green());
75 bDiff = (bcb = cb.blue()) - (bca = ca.blue()); 79 bDiff = (bcb = cb.blue()) - (bca = ca.blue());
76 80
77 if( eff == VerticalGradient || eff == HorizontalGradient ){ 81 if( eff == VerticalGradient || eff == HorizontalGradient ){
78 82
79 uint *p; 83 uint *p;
80 uint rgb; 84 uint rgb;
81 85
82 register int rl = rca << 16; 86 register int rl = rca << 16;
83 register int gl = gca << 16; 87 register int gl = gca << 16;
84 register int bl = bca << 16; 88 register int bl = bca << 16;
85 89
86 if( eff == VerticalGradient ) { 90 if( eff == VerticalGradient ) {
87 91
88 int rcdelta = ((1<<16) / size.height()) * rDiff; 92 int rcdelta = ((1<<16) / size.height()) * rDiff;
89 int gcdelta = ((1<<16) / size.height()) * gDiff; 93 int gcdelta = ((1<<16) / size.height()) * gDiff;
90 int bcdelta = ((1<<16) / size.height()) * bDiff; 94 int bcdelta = ((1<<16) / size.height()) * bDiff;
91 95
92 for ( y = 0; y < size.height(); y++ ) { 96 for ( y = 0; y < size.height(); y++ ) {
93 p = (uint *) image.scanLine(y); 97 p = (uint *) image.scanLine(y);
94 98
95 rl += rcdelta; 99 rl += rcdelta;
96 gl += gcdelta; 100 gl += gcdelta;
97 bl += bcdelta; 101 bl += bcdelta;
98 102
99 rgb = qRgb( (rl>>16), (gl>>16), (bl>>16) ); 103 rgb = qRgb( (rl>>16), (gl>>16), (bl>>16) );
100 104
101 for( x = 0; x < size.width(); x++ ) { 105 for( x = 0; x < size.width(); x++ ) {
102 *p = rgb; 106 *p = rgb;
103 p++; 107 p++;
104 } 108 }
105 } 109 }
106 110
107 } 111 }
108 else { // must be HorizontalGradient 112 else { // must be HorizontalGradient
109 113
110 unsigned int *o_src = (unsigned int *)image.scanLine(0); 114 unsigned int *o_src = (unsigned int *)image.scanLine(0);
111 unsigned int *src = o_src; 115 unsigned int *src = o_src;
112 116
113 int rcdelta = ((1<<16) / size.width()) * rDiff; 117 int rcdelta = ((1<<16) / size.width()) * rDiff;
114 int gcdelta = ((1<<16) / size.width()) * gDiff; 118 int gcdelta = ((1<<16) / size.width()) * gDiff;
115 int bcdelta = ((1<<16) / size.width()) * bDiff; 119 int bcdelta = ((1<<16) / size.width()) * bDiff;
116 120
117 for( x = 0; x < size.width(); x++) { 121 for( x = 0; x < size.width(); x++) {
118 122
119 rl += rcdelta; 123 rl += rcdelta;
120 gl += gcdelta; 124 gl += gcdelta;
121 bl += bcdelta; 125 bl += bcdelta;
122 126
123 *src++ = qRgb( (rl>>16), (gl>>16), (bl>>16)); 127 *src++ = qRgb( (rl>>16), (gl>>16), (bl>>16));
124 } 128 }
125 129
126 src = o_src; 130 src = o_src;
127 131
128 // Believe it or not, manually copying in a for loop is faster 132 // Believe it or not, manually copying in a for loop is faster
129 // than calling memcpy for each scanline (on the order of ms...). 133 // than calling memcpy for each scanline (on the order of ms...).
130 // I think this is due to the function call overhead (mosfet). 134 // I think this is due to the function call overhead (mosfet).
131 135
132 for (y = 1; y < size.height(); ++y) { 136 for (y = 1; y < size.height(); ++y) {
133 137
134 p = (unsigned int *)image.scanLine(y); 138 p = (unsigned int *)image.scanLine(y);
135 src = o_src; 139 src = o_src;
136 for(x=0; x < size.width(); ++x) 140 for(x=0; x < size.width(); ++x)
137 *p++ = *src++; 141 *p++ = *src++;
138 } 142 }
139 } 143 }
140 } 144 }
141 145
142 else { 146 else {
143 147
144 float rfd, gfd, bfd; 148 float rfd, gfd, bfd;
145 float rd = rca, gd = gca, bd = bca; 149 float rd = rca, gd = gca, bd = bca;
146 150
147 unsigned char *xtable[3]; 151 unsigned char *xtable[3];
148 unsigned char *ytable[3]; 152 unsigned char *ytable[3];
149 153
150 unsigned int w = size.width(), h = size.height(); 154 unsigned int w = size.width(), h = size.height();
151 xtable[0] = new unsigned char[w]; 155 xtable[0] = new unsigned char[w];
152 xtable[1] = new unsigned char[w]; 156 xtable[1] = new unsigned char[w];
153 xtable[2] = new unsigned char[w]; 157 xtable[2] = new unsigned char[w];
154 ytable[0] = new unsigned char[h]; 158 ytable[0] = new unsigned char[h];
155 ytable[1] = new unsigned char[h]; 159 ytable[1] = new unsigned char[h];
156 ytable[2] = new unsigned char[h]; 160 ytable[2] = new unsigned char[h];
157 w*=2, h*=2; 161 w*=2, h*=2;
158 162
159 if ( eff == DiagonalGradient || eff == CrossDiagonalGradient) { 163 if ( eff == DiagonalGradient || eff == CrossDiagonalGradient) {
160 // Diagonal dgradient code inspired by BlackBox (mosfet) 164 // Diagonal dgradient code inspired by BlackBox (mosfet)
161 // BlackBox dgradient is (C) Brad Hughes, <bhughes@tcac.net> and 165 // BlackBox dgradient is (C) Brad Hughes, <bhughes@tcac.net> and
162 // Mike Cole <mike@mydot.com>. 166 // Mike Cole <mike@mydot.com>.
163 167
164 rfd = (float)rDiff/w; 168 rfd = (float)rDiff/w;
165 gfd = (float)gDiff/w; 169 gfd = (float)gDiff/w;
166 bfd = (float)bDiff/w; 170 bfd = (float)bDiff/w;
167 171
168 int dir; 172 int dir;
169 for (x = 0; x < size.width(); x++, rd+=rfd, gd+=gfd, bd+=bfd) { 173 for (x = 0; x < size.width(); x++, rd+=rfd, gd+=gfd, bd+=bfd) {
170 dir = eff == DiagonalGradient? x : size.width() - x - 1; 174 dir = eff == DiagonalGradient? x : size.width() - x - 1;
171 xtable[0][dir] = (unsigned char) rd; 175 xtable[0][dir] = (unsigned char) rd;
172 xtable[1][dir] = (unsigned char) gd; 176 xtable[1][dir] = (unsigned char) gd;
173 xtable[2][dir] = (unsigned char) bd; 177 xtable[2][dir] = (unsigned char) bd;
174 } 178 }
175 rfd = (float)rDiff/h; 179 rfd = (float)rDiff/h;
176 gfd = (float)gDiff/h; 180 gfd = (float)gDiff/h;
177 bfd = (float)bDiff/h; 181 bfd = (float)bDiff/h;
178 rd = gd = bd = 0; 182 rd = gd = bd = 0;
179 for (y = 0; y < size.height(); y++, rd+=rfd, gd+=gfd, bd+=bfd) { 183 for (y = 0; y < size.height(); y++, rd+=rfd, gd+=gfd, bd+=bfd) {
180 ytable[0][y] = (unsigned char) rd; 184 ytable[0][y] = (unsigned char) rd;
181 ytable[1][y] = (unsigned char) gd; 185 ytable[1][y] = (unsigned char) gd;
182 ytable[2][y] = (unsigned char) bd; 186 ytable[2][y] = (unsigned char) bd;
183 } 187 }
184 188
185 for (y = 0; y < size.height(); y++) { 189 for (y = 0; y < size.height(); y++) {
186 unsigned int *scanline = (unsigned int *)image.scanLine(y); 190 unsigned int *scanline = (unsigned int *)image.scanLine(y);
187 for (x = 0; x < size.width(); x++) { 191 for (x = 0; x < size.width(); x++) {
188 scanline[x] = qRgb(xtable[0][x] + ytable[0][y], 192 scanline[x] = qRgb(xtable[0][x] + ytable[0][y],
189 xtable[1][x] + ytable[1][y], 193 xtable[1][x] + ytable[1][y],
190 xtable[2][x] + ytable[2][y]); 194 xtable[2][x] + ytable[2][y]);
191 } 195 }
192 } 196 }
193 } 197 }
194 198
195 else if (eff == RectangleGradient || 199 else if (eff == RectangleGradient ||
196 eff == PyramidGradient || 200 eff == PyramidGradient ||
197 eff == PipeCrossGradient || 201 eff == PipeCrossGradient ||
198 eff == EllipticGradient) 202 eff == EllipticGradient)
199 { 203 {
200 int rSign = rDiff>0? 1: -1; 204 int rSign = rDiff>0? 1: -1;
201 int gSign = gDiff>0? 1: -1; 205 int gSign = gDiff>0? 1: -1;
202 int bSign = bDiff>0? 1: -1; 206 int bSign = bDiff>0? 1: -1;
203 207
204 rfd = (float)rDiff / size.width(); 208 rfd = (float)rDiff / size.width();
205 gfd = (float)gDiff / size.width(); 209 gfd = (float)gDiff / size.width();
206 bfd = (float)bDiff / size.width(); 210 bfd = (float)bDiff / size.width();
207 211
208 rd = (float)rDiff/2; 212 rd = (float)rDiff/2;
209 gd = (float)gDiff/2; 213 gd = (float)gDiff/2;
210 bd = (float)bDiff/2; 214 bd = (float)bDiff/2;
211 215
212 for (x = 0; x < size.width(); x++, rd-=rfd, gd-=gfd, bd-=bfd) 216 for (x = 0; x < size.width(); x++, rd-=rfd, gd-=gfd, bd-=bfd)
213 { 217 {
214 xtable[0][x] = (unsigned char) abs((int)rd); 218 xtable[0][x] = (unsigned char) abs((int)rd);
215 xtable[1][x] = (unsigned char) abs((int)gd); 219 xtable[1][x] = (unsigned char) abs((int)gd);
216 xtable[2][x] = (unsigned char) abs((int)bd); 220 xtable[2][x] = (unsigned char) abs((int)bd);
217 } 221 }
218 222
219 rfd = (float)rDiff/size.height(); 223 rfd = (float)rDiff/size.height();
220 gfd = (float)gDiff/size.height(); 224 gfd = (float)gDiff/size.height();
221 bfd = (float)bDiff/size.height(); 225 bfd = (float)bDiff/size.height();
222 226
223 rd = (float)rDiff/2; 227 rd = (float)rDiff/2;
224 gd = (float)gDiff/2; 228 gd = (float)gDiff/2;
225 bd = (float)bDiff/2; 229 bd = (float)bDiff/2;
226 230
227 for (y = 0; y < size.height(); y++, rd-=rfd, gd-=gfd, bd-=bfd) 231 for (y = 0; y < size.height(); y++, rd-=rfd, gd-=gfd, bd-=bfd)
228 { 232 {
229 ytable[0][y] = (unsigned char) abs((int)rd); 233 ytable[0][y] = (unsigned char) abs((int)rd);
230 ytable[1][y] = (unsigned char) abs((int)gd); 234 ytable[1][y] = (unsigned char) abs((int)gd);
231 ytable[2][y] = (unsigned char) abs((int)bd); 235 ytable[2][y] = (unsigned char) abs((int)bd);
232 } 236 }
233 unsigned int rgb; 237 unsigned int rgb;
234 int h = (size.height()+1)>>1; 238 int h = (size.height()+1)>>1;
235 for (y = 0; y < h; y++) { 239 for (y = 0; y < h; y++) {
236 unsigned int *sl1 = (unsigned int *)image.scanLine(y); 240 unsigned int *sl1 = (unsigned int *)image.scanLine(y);
237 unsigned int *sl2 = (unsigned int *)image.scanLine(QMAX(size.height()-y-1, y)); 241 unsigned int *sl2 = (unsigned int *)image.scanLine(QMAX(size.height()-y-1, y));
238 242
239 int w = (size.width()+1)>>1; 243 int w = (size.width()+1)>>1;
240 int x2 = size.width()-1; 244 int x2 = size.width()-1;
241 245
242 for (x = 0; x < w; x++, x2--) { 246 for (x = 0; x < w; x++, x2--) {
243 rgb = 0; 247 rgb = 0;
244 if (eff == PyramidGradient) { 248 if (eff == PyramidGradient) {
245 rgb = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]), 249 rgb = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]),
246 gcb-gSign*(xtable[1][x]+ytable[1][y]), 250 gcb-gSign*(xtable[1][x]+ytable[1][y]),
247 bcb-bSign*(xtable[2][x]+ytable[2][y])); 251 bcb-bSign*(xtable[2][x]+ytable[2][y]));
248 } 252 }
249 if (eff == RectangleGradient) { 253 if (eff == RectangleGradient) {
250 rgb = qRgb(rcb - rSign * 254 rgb = qRgb(rcb - rSign *
251 QMAX(xtable[0][x], ytable[0][y]) * 2, 255 QMAX(xtable[0][x], ytable[0][y]) * 2,
252 gcb - gSign * 256 gcb - gSign *
253 QMAX(xtable[1][x], ytable[1][y]) * 2, 257 QMAX(xtable[1][x], ytable[1][y]) * 2,
254 bcb - bSign * 258 bcb - bSign *
255 QMAX(xtable[2][x], ytable[2][y]) * 2); 259 QMAX(xtable[2][x], ytable[2][y]) * 2);
256 } 260 }
257 if (eff == PipeCrossGradient) { 261 if (eff == PipeCrossGradient) {
258 rgb = qRgb(rcb - rSign * 262 rgb = qRgb(rcb - rSign *
259 QMIN(xtable[0][x], ytable[0][y]) * 2, 263 QMIN(xtable[0][x], ytable[0][y]) * 2,
260 gcb - gSign * 264 gcb - gSign *
261 QMIN(xtable[1][x], ytable[1][y]) * 2, 265 QMIN(xtable[1][x], ytable[1][y]) * 2,
262 bcb - bSign * 266 bcb - bSign *
263 QMIN(xtable[2][x], ytable[2][y]) * 2); 267 QMIN(xtable[2][x], ytable[2][y]) * 2);
264 } 268 }
265 if (eff == EllipticGradient) { 269 if (eff == EllipticGradient) {
266 rgb = qRgb(rcb - rSign * 270 rgb = qRgb(rcb - rSign *
267 (int)sqrt((xtable[0][x]*xtable[0][x] + 271 (int)sqrt((xtable[0][x]*xtable[0][x] +
268 ytable[0][y]*ytable[0][y])*2.0), 272 ytable[0][y]*ytable[0][y])*2.0),
269 gcb - gSign * 273 gcb - gSign *
270 (int)sqrt((xtable[1][x]*xtable[1][x] + 274 (int)sqrt((xtable[1][x]*xtable[1][x] +
271 ytable[1][y]*ytable[1][y])*2.0), 275 ytable[1][y]*ytable[1][y])*2.0),
272 bcb - bSign * 276 bcb - bSign *
273 (int)sqrt((xtable[2][x]*xtable[2][x] + 277 (int)sqrt((xtable[2][x]*xtable[2][x] +
274 ytable[2][y]*ytable[2][y])*2.0)); 278 ytable[2][y]*ytable[2][y])*2.0));
275 } 279 }
276 280
277 sl1[x] = sl2[x] = rgb; 281 sl1[x] = sl2[x] = rgb;
278 sl1[x2] = sl2[x2] = rgb; 282 sl1[x2] = sl2[x2] = rgb;
279 } 283 }
280 } 284 }
281 } 285 }
282 286
283 delete [] xtable[0]; 287 delete [] xtable[0];
284 delete [] xtable[1]; 288 delete [] xtable[1];
285 delete [] xtable[2]; 289 delete [] xtable[2];
286 delete [] ytable[0]; 290 delete [] ytable[0];
287 delete [] ytable[1]; 291 delete [] ytable[1];
288 delete [] ytable[2]; 292 delete [] ytable[2];
289 } 293 }
290 294
291 // dither if necessary 295 // dither if necessary
292 if (ncols && (QPixmap::defaultDepth() < 15 )) { 296 if (ncols && (QPixmap::defaultDepth() < 15 )) {
293 if ( ncols < 2 || ncols > 256 ) 297 if ( ncols < 2 || ncols > 256 )
294 ncols = 3; 298 ncols = 3;
295 QColor *dPal = new QColor[ncols]; 299 QColor *dPal = new QColor[ncols];
296 for (int i=0; i<ncols; i++) { 300 for (int i=0; i<ncols; i++) {
297 dPal[i].setRgb ( rca + rDiff * i / ( ncols - 1 ), 301 dPal[i].setRgb ( rca + rDiff * i / ( ncols - 1 ),
298 gca + gDiff * i / ( ncols - 1 ), 302 gca + gDiff * i / ( ncols - 1 ),
299 bca + bDiff * i / ( ncols - 1 ) ); 303 bca + bDiff * i / ( ncols - 1 ) );
300 } 304 }
301 dither(image, dPal, ncols); 305 dither(image, dPal, ncols);
302 delete [] dPal; 306 delete [] dPal;
303 } 307 }
304 308
305 return image; 309 return image;
306} 310}
307 311
308 312
309// ----------------------------------------------------------------------------- 313// -----------------------------------------------------------------------------
310 314
311//CT this was (before Dirk A. Mueller's speedup changes) 315//CT this was (before Dirk A. Mueller's speedup changes)
312// merely the same code as in the above method, but it's supposedly 316// merely the same code as in the above method, but it's supposedly
313// way less performant since it introduces a lot of supplementary tests 317// way less performant since it introduces a lot of supplementary tests
314// and simple math operations for the calculus of the balance. 318// and simple math operations for the calculus of the balance.
315// (surprizingly, it isn't less performant, in the contrary :-) 319// (surprizingly, it isn't less performant, in the contrary :-)
316// Yes, I could have merged them, but then the excellent performance of 320// Yes, I could have merged them, but then the excellent performance of
317// the balanced code would suffer with no other gain than a mere 321// the balanced code would suffer with no other gain than a mere
318// source code and byte code size economy. 322// source code and byte code size economy.
319 323
320QImage OImageEffect::unbalancedGradient(const QSize &size, const QColor &ca, 324QImage OImageEffect::unbalancedGradient(const QSize &size, const QColor &ca,
321 const QColor &cb, GradientType eff, int xfactor, int yfactor, 325 const QColor &cb, GradientType eff, int xfactor, int yfactor,
322 int ncols) 326 int ncols)
323{ 327{
324 int dir; // general parameter used for direction switches 328 int dir; // general parameter used for direction switches
325 329
326 bool _xanti = false , _yanti = false; 330 bool _xanti = false , _yanti = false;
327 331
328 if (xfactor < 0) _xanti = true; // negative on X direction 332 if (xfactor < 0) _xanti = true; // negative on X direction
329 if (yfactor < 0) _yanti = true; // negative on Y direction 333 if (yfactor < 0) _yanti = true; // negative on Y direction
330 334
331 xfactor = abs(xfactor); 335 xfactor = abs(xfactor);
332 yfactor = abs(yfactor); 336 yfactor = abs(yfactor);
333 337
334 if (!xfactor) xfactor = 1; 338 if (!xfactor) xfactor = 1;
335 if (!yfactor) yfactor = 1; 339 if (!yfactor) yfactor = 1;
336 340
337 if (xfactor > 200 ) xfactor = 200; 341 if (xfactor > 200 ) xfactor = 200;
338 if (yfactor > 200 ) yfactor = 200; 342 if (yfactor > 200 ) yfactor = 200;
339 343
340 344
341 // float xbal = xfactor/5000.; 345 // float xbal = xfactor/5000.;
342 // float ybal = yfactor/5000.; 346 // float ybal = yfactor/5000.;
343 float xbal = xfactor/30./size.width(); 347 float xbal = xfactor/30./size.width();
344 float ybal = yfactor/30./size.height(); 348 float ybal = yfactor/30./size.height();
345 float rat; 349 float rat;
346 350
347 int rDiff, gDiff, bDiff; 351 int rDiff, gDiff, bDiff;
348 int rca, gca, bca, rcb, gcb, bcb; 352 int rca, gca, bca, rcb, gcb, bcb;
349 353
350 QImage image(size, 32); 354 QImage image(size, 32);
351 355
352 if (size.width() == 0 || size.height() == 0) { 356 if (size.width() == 0 || size.height() == 0) {
353 odebug << "WARNING: OImageEffect::unbalancedGradient : invalid image" << oendl; 357 odebug << "WARNING: OImageEffect::unbalancedGradient : invalid image" << oendl;
354 return image; 358 return image;
355 } 359 }
356 360
357 register int x, y; 361 register int x, y;
358 unsigned int *scanline; 362 unsigned int *scanline;
359 363
360 rDiff = (rcb = cb.red()) - (rca = ca.red()); 364 rDiff = (rcb = cb.red()) - (rca = ca.red());
361 gDiff = (gcb = cb.green()) - (gca = ca.green()); 365 gDiff = (gcb = cb.green()) - (gca = ca.green());
362 bDiff = (bcb = cb.blue()) - (bca = ca.blue()); 366 bDiff = (bcb = cb.blue()) - (bca = ca.blue());
363 367
364 if( eff == VerticalGradient || eff == HorizontalGradient){ 368 if( eff == VerticalGradient || eff == HorizontalGradient){
365 QColor cRow; 369 QColor cRow;
366 370
367 uint *p; 371 uint *p;
368 uint rgbRow; 372 uint rgbRow;
369 373
370 if( eff == VerticalGradient) { 374 if( eff == VerticalGradient) {
371 for ( y = 0; y < size.height(); y++ ) { 375 for ( y = 0; y < size.height(); y++ ) {
372 dir = _yanti ? y : size.height() - 1 - y; 376 dir = _yanti ? y : size.height() - 1 - y;
373 p = (uint *) image.scanLine(dir); 377 p = (uint *) image.scanLine(dir);
374 rat = 1 - exp( - (float)y * ybal ); 378 rat = 1 - exp( - (float)y * ybal );
375 379
376 cRow.setRgb( rcb - (int) ( rDiff * rat ), 380 cRow.setRgb( rcb - (int) ( rDiff * rat ),
377 gcb - (int) ( gDiff * rat ), 381 gcb - (int) ( gDiff * rat ),
378 bcb - (int) ( bDiff * rat ) ); 382 bcb - (int) ( bDiff * rat ) );
379 383
380 rgbRow = cRow.rgb(); 384 rgbRow = cRow.rgb();
381 385
382 for( x = 0; x < size.width(); x++ ) { 386 for( x = 0; x < size.width(); x++ ) {
383 *p = rgbRow; 387 *p = rgbRow;
384 p++; 388 p++;
385 } 389 }
386 } 390 }
387 } 391 }
388 else { 392 else {
389 393
390 unsigned int *src = (unsigned int *)image.scanLine(0); 394 unsigned int *src = (unsigned int *)image.scanLine(0);
391 for(x = 0; x < size.width(); x++ ) 395 for(x = 0; x < size.width(); x++ )
392 { 396 {
393 dir = _xanti ? x : size.width() - 1 - x; 397 dir = _xanti ? x : size.width() - 1 - x;
394 rat = 1 - exp( - (float)x * xbal ); 398 rat = 1 - exp( - (float)x * xbal );
395 399
396 src[dir] = qRgb(rcb - (int) ( rDiff * rat ), 400 src[dir] = qRgb(rcb - (int) ( rDiff * rat ),
397 gcb - (int) ( gDiff * rat ), 401 gcb - (int) ( gDiff * rat ),
398 bcb - (int) ( bDiff * rat )); 402 bcb - (int) ( bDiff * rat ));
399 } 403 }
400 404
401 // Believe it or not, manually copying in a for loop is faster 405 // Believe it or not, manually copying in a for loop is faster
402 // than calling memcpy for each scanline (on the order of ms...). 406 // than calling memcpy for each scanline (on the order of ms...).
403 // I think this is due to the function call overhead (mosfet). 407 // I think this is due to the function call overhead (mosfet).
404 408
405 for(y = 1; y < size.height(); ++y) 409 for(y = 1; y < size.height(); ++y)
406 { 410 {
407 scanline = (unsigned int *)image.scanLine(y); 411 scanline = (unsigned int *)image.scanLine(y);
408 for(x=0; x < size.width(); ++x) 412 for(x=0; x < size.width(); ++x)
409 scanline[x] = src[x]; 413 scanline[x] = src[x];
410 } 414 }
411 } 415 }
412 } 416 }
413 417
414 else { 418 else {
415 int w=size.width(), h=size.height(); 419 int w=size.width(), h=size.height();
416 420
417 unsigned char *xtable[3]; 421 unsigned char *xtable[3];
418 unsigned char *ytable[3]; 422 unsigned char *ytable[3];
419 xtable[0] = new unsigned char[w]; 423 xtable[0] = new unsigned char[w];
420 xtable[1] = new unsigned char[w]; 424 xtable[1] = new unsigned char[w];
421 xtable[2] = new unsigned char[w]; 425 xtable[2] = new unsigned char[w];
422 ytable[0] = new unsigned char[h]; 426 ytable[0] = new unsigned char[h];
423 ytable[1] = new unsigned char[h]; 427 ytable[1] = new unsigned char[h];
424 ytable[2] = new unsigned char[h]; 428 ytable[2] = new unsigned char[h];
425 429
426 if ( eff == DiagonalGradient || eff == CrossDiagonalGradient) 430 if ( eff == DiagonalGradient || eff == CrossDiagonalGradient)
427 { 431 {
428 for (x = 0; x < w; x++) { 432 for (x = 0; x < w; x++) {
429 dir = _xanti ? x : w - 1 - x; 433 dir = _xanti ? x : w - 1 - x;
430 rat = 1 - exp( - (float)x * xbal ); 434 rat = 1 - exp( - (float)x * xbal );
431 435
432 xtable[0][dir] = (unsigned char) ( rDiff/2 * rat ); 436 xtable[0][dir] = (unsigned char) ( rDiff/2 * rat );
433 xtable[1][dir] = (unsigned char) ( gDiff/2 * rat ); 437 xtable[1][dir] = (unsigned char) ( gDiff/2 * rat );
434 xtable[2][dir] = (unsigned char) ( bDiff/2 * rat ); 438 xtable[2][dir] = (unsigned char) ( bDiff/2 * rat );
435 } 439 }
436 440
437 for (y = 0; y < h; y++) { 441 for (y = 0; y < h; y++) {
438 dir = _yanti ? y : h - 1 - y; 442 dir = _yanti ? y : h - 1 - y;
439 rat = 1 - exp( - (float)y * ybal ); 443 rat = 1 - exp( - (float)y * ybal );
440 444
441 ytable[0][dir] = (unsigned char) ( rDiff/2 * rat ); 445 ytable[0][dir] = (unsigned char) ( rDiff/2 * rat );
442 ytable[1][dir] = (unsigned char) ( gDiff/2 * rat ); 446 ytable[1][dir] = (unsigned char) ( gDiff/2 * rat );
443 ytable[2][dir] = (unsigned char) ( bDiff/2 * rat ); 447 ytable[2][dir] = (unsigned char) ( bDiff/2 * rat );
444 } 448 }
445 449
446 for (y = 0; y < h; y++) { 450 for (y = 0; y < h; y++) {
447 unsigned int *scanline = (unsigned int *)image.scanLine(y); 451 unsigned int *scanline = (unsigned int *)image.scanLine(y);
448 for (x = 0; x < w; x++) { 452 for (x = 0; x < w; x++) {
449 scanline[x] = qRgb(rcb - (xtable[0][x] + ytable[0][y]), 453 scanline[x] = qRgb(rcb - (xtable[0][x] + ytable[0][y]),
450 gcb - (xtable[1][x] + ytable[1][y]), 454 gcb - (xtable[1][x] + ytable[1][y]),
451 bcb - (xtable[2][x] + ytable[2][y])); 455 bcb - (xtable[2][x] + ytable[2][y]));
452 } 456 }
453 } 457 }
454 } 458 }
455 459
456 else if (eff == RectangleGradient || 460 else if (eff == RectangleGradient ||
457 eff == PyramidGradient || 461 eff == PyramidGradient ||
458 eff == PipeCrossGradient || 462 eff == PipeCrossGradient ||
459 eff == EllipticGradient) 463 eff == EllipticGradient)
460 { 464 {
461 int rSign = rDiff>0? 1: -1; 465 int rSign = rDiff>0? 1: -1;
462 int gSign = gDiff>0? 1: -1; 466 int gSign = gDiff>0? 1: -1;
463 int bSign = bDiff>0? 1: -1; 467 int bSign = bDiff>0? 1: -1;
464 468
465 for (x = 0; x < w; x++) 469 for (x = 0; x < w; x++)
466 { 470 {
467 dir = _xanti ? x : w - 1 - x; 471 dir = _xanti ? x : w - 1 - x;
468 rat = 1 - exp( - (float)x * xbal ); 472 rat = 1 - exp( - (float)x * xbal );
469 473
470 xtable[0][dir] = (unsigned char) abs((int)(rDiff*(0.5-rat))); 474 xtable[0][dir] = (unsigned char) abs((int)(rDiff*(0.5-rat)));
471 xtable[1][dir] = (unsigned char) abs((int)(gDiff*(0.5-rat))); 475 xtable[1][dir] = (unsigned char) abs((int)(gDiff*(0.5-rat)));
472 xtable[2][dir] = (unsigned char) abs((int)(bDiff*(0.5-rat))); 476 xtable[2][dir] = (unsigned char) abs((int)(bDiff*(0.5-rat)));
473 } 477 }
474 478
475 for (y = 0; y < h; y++) 479 for (y = 0; y < h; y++)
476 { 480 {
477 dir = _yanti ? y : h - 1 - y; 481 dir = _yanti ? y : h - 1 - y;
478 482
479 rat = 1 - exp( - (float)y * ybal ); 483 rat = 1 - exp( - (float)y * ybal );
480 484
481 ytable[0][dir] = (unsigned char) abs((int)(rDiff*(0.5-rat))); 485 ytable[0][dir] = (unsigned char) abs((int)(rDiff*(0.5-rat)));
482 ytable[1][dir] = (unsigned char) abs((int)(gDiff*(0.5-rat))); 486 ytable[1][dir] = (unsigned char) abs((int)(gDiff*(0.5-rat)));
483 ytable[2][dir] = (unsigned char) abs((int)(bDiff*(0.5-rat))); 487 ytable[2][dir] = (unsigned char) abs((int)(bDiff*(0.5-rat)));
484 } 488 }
485 489
486 for (y = 0; y < h; y++) { 490 for (y = 0; y < h; y++) {
487 unsigned int *scanline = (unsigned int *)image.scanLine(y); 491 unsigned int *scanline = (unsigned int *)image.scanLine(y);
488 for (x = 0; x < w; x++) { 492 for (x = 0; x < w; x++) {
489 if (eff == PyramidGradient) 493 if (eff == PyramidGradient)
490 { 494 {
491 scanline[x] = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]), 495 scanline[x] = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]),
492 gcb-gSign*(xtable[1][x]+ytable[1][y]), 496 gcb-gSign*(xtable[1][x]+ytable[1][y]),
493 bcb-bSign*(xtable[2][x]+ytable[2][y])); 497 bcb-bSign*(xtable[2][x]+ytable[2][y]));
494 } 498 }
495 if (eff == RectangleGradient) 499 if (eff == RectangleGradient)
496 { 500 {
497 scanline[x] = qRgb(rcb - rSign * 501 scanline[x] = qRgb(rcb - rSign *
498 QMAX(xtable[0][x], ytable[0][y]) * 2, 502 QMAX(xtable[0][x], ytable[0][y]) * 2,
499 gcb - gSign * 503 gcb - gSign *
500 QMAX(xtable[1][x], ytable[1][y]) * 2, 504 QMAX(xtable[1][x], ytable[1][y]) * 2,
501 bcb - bSign * 505 bcb - bSign *
502 QMAX(xtable[2][x], ytable[2][y]) * 2); 506 QMAX(xtable[2][x], ytable[2][y]) * 2);
503 } 507 }
504 if (eff == PipeCrossGradient) 508 if (eff == PipeCrossGradient)
505 { 509 {
506 scanline[x] = qRgb(rcb - rSign * 510 scanline[x] = qRgb(rcb - rSign *
507 QMIN(xtable[0][x], ytable[0][y]) * 2, 511 QMIN(xtable[0][x], ytable[0][y]) * 2,
508 gcb - gSign * 512 gcb - gSign *
509 QMIN(xtable[1][x], ytable[1][y]) * 2, 513 QMIN(xtable[1][x], ytable[1][y]) * 2,
510 bcb - bSign * 514 bcb - bSign *
511 QMIN(xtable[2][x], ytable[2][y]) * 2); 515 QMIN(xtable[2][x], ytable[2][y]) * 2);
512 } 516 }
513 if (eff == EllipticGradient) 517 if (eff == EllipticGradient)
514 { 518 {
515 scanline[x] = qRgb(rcb - rSign * 519 scanline[x] = qRgb(rcb - rSign *
516 (int)sqrt((xtable[0][x]*xtable[0][x] + 520 (int)sqrt((xtable[0][x]*xtable[0][x] +
517 ytable[0][y]*ytable[0][y])*2.0), 521 ytable[0][y]*ytable[0][y])*2.0),
518 gcb - gSign * 522 gcb - gSign *
519 (int)sqrt((xtable[1][x]*xtable[1][x] + 523 (int)sqrt((xtable[1][x]*xtable[1][x] +
520 ytable[1][y]*ytable[1][y])*2.0), 524 ytable[1][y]*ytable[1][y])*2.0),
521 bcb - bSign * 525 bcb - bSign *
522 (int)sqrt((xtable[2][x]*xtable[2][x] + 526 (int)sqrt((xtable[2][x]*xtable[2][x] +
523 ytable[2][y]*ytable[2][y])*2.0)); 527 ytable[2][y]*ytable[2][y])*2.0));
524 } 528 }
525 } 529 }
526 } 530 }
527 } 531 }
528 532
529 if (ncols && (QPixmap::defaultDepth() < 15 )) { 533 if (ncols && (QPixmap::defaultDepth() < 15 )) {
530 if ( ncols < 2 || ncols > 256 ) 534 if ( ncols < 2 || ncols > 256 )
531 ncols = 3; 535 ncols = 3;
532 QColor *dPal = new QColor[ncols]; 536 QColor *dPal = new QColor[ncols];
533 for (int i=0; i<ncols; i++) { 537 for (int i=0; i<ncols; i++) {
534 dPal[i].setRgb ( rca + rDiff * i / ( ncols - 1 ), 538 dPal[i].setRgb ( rca + rDiff * i / ( ncols - 1 ),
535 gca + gDiff * i / ( ncols - 1 ), 539 gca + gDiff * i / ( ncols - 1 ),
536 bca + bDiff * i / ( ncols - 1 ) ); 540 bca + bDiff * i / ( ncols - 1 ) );
537 } 541 }
538 dither(image, dPal, ncols); 542 dither(image, dPal, ncols);
539 delete [] dPal; 543 delete [] dPal;
540 } 544 }
541 545
542 delete [] xtable[0]; 546 delete [] xtable[0];
543 delete [] xtable[1]; 547 delete [] xtable[1];
544 delete [] xtable[2]; 548 delete [] xtable[2];
545 delete [] ytable[0]; 549 delete [] ytable[0];
546 delete [] ytable[1]; 550 delete [] ytable[1];
547 delete [] ytable[2]; 551 delete [] ytable[2];
548 552
549 } 553 }
550 554
551 return image; 555 return image;
552} 556}
553 557
554 558
555//====================================================================== 559//======================================================================
556// 560//
557// Intensity effects 561// Intensity effects
558// 562//
559//====================================================================== 563//======================================================================
560 564
561 565
562/* This builds a 256 byte unsigned char lookup table with all 566/* This builds a 256 byte unsigned char lookup table with all
563 * the possible percent values prior to applying the effect, then uses 567 * the possible percent values prior to applying the effect, then uses
564 * integer math for the pixels. For any image larger than 9x9 this will be 568 * integer math for the pixels. For any image larger than 9x9 this will be
565 * less expensive than doing a float operation on the 3 color components of 569 * less expensive than doing a float operation on the 3 color components of
566 * each pixel. (mosfet) 570 * each pixel. (mosfet)
567 */ 571 */
568 572
569QImage& OImageEffect::intensity(QImage &image, float percent) 573QImage& OImageEffect::intensity(QImage &image, float percent)
570{ 574{
571 if (image.width() == 0 || image.height() == 0) { 575 if (image.width() == 0 || image.height() == 0) {
572 odebug << "WARNING: OImageEffect::intensity : invalid image" << oendl; 576 odebug << "WARNING: OImageEffect::intensity : invalid image" << oendl;
573 return image; 577 return image;
574 } 578 }
575 579
576 int segColors = image.depth() > 8 ? 256 : image.numColors(); 580 int segColors = image.depth() > 8 ? 256 : image.numColors();
577 unsigned char *segTbl = new unsigned char[segColors]; 581 unsigned char *segTbl = new unsigned char[segColors];
578 int pixels = image.depth() > 8 ? image.width()*image.height() : 582 int pixels = image.depth() > 8 ? image.width()*image.height() :
579 image.numColors(); 583 image.numColors();
580 unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() : 584 unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() :
581 (unsigned int *)image.colorTable(); 585 (unsigned int *)image.colorTable();
582 586
583 bool brighten = (percent >= 0); 587 bool brighten = (percent >= 0);
584 if(percent < 0) 588 if(percent < 0)
585 percent = -percent; 589 percent = -percent;
586 590
587 if(brighten){ // keep overflow check out of loops 591 if(brighten){ // keep overflow check out of loops
588 for(int i=0; i < segColors; ++i){ 592 for(int i=0; i < segColors; ++i){
589 int tmp = (int)(i*percent); 593 int tmp = (int)(i*percent);
590 if(tmp > 255) 594 if(tmp > 255)
591 tmp = 255; 595 tmp = 255;
592 segTbl[i] = tmp; 596 segTbl[i] = tmp;
593 } 597 }
594 } 598 }
595 else{ 599 else{
596 for(int i=0; i < segColors; ++i){ 600 for(int i=0; i < segColors; ++i){
597 int tmp = (int)(i*percent); 601 int tmp = (int)(i*percent);
598 if(tmp < 0) 602 if(tmp < 0)
599 tmp = 0; 603 tmp = 0;
600 segTbl[i] = tmp; 604 segTbl[i] = tmp;
601 } 605 }
602 } 606 }
603 607
604 if(brighten){ // same here 608 if(brighten){ // same here
605 for(int i=0; i < pixels; ++i){ 609 for(int i=0; i < pixels; ++i){
606 int r = qRed(data[i]); 610 int r = qRed(data[i]);
607 int g = qGreen(data[i]); 611 int g = qGreen(data[i]);
608 int b = qBlue(data[i]); 612 int b = qBlue(data[i]);
609 int a = qAlpha(data[i]); 613 int a = qAlpha(data[i]);
610 r = r + segTbl[r] > 255 ? 255 : r + segTbl[r]; 614 r = r + segTbl[r] > 255 ? 255 : r + segTbl[r];
611 g = g + segTbl[g] > 255 ? 255 : g + segTbl[g]; 615 g = g + segTbl[g] > 255 ? 255 : g + segTbl[g];
612 b = b + segTbl[b] > 255 ? 255 : b + segTbl[b]; 616 b = b + segTbl[b] > 255 ? 255 : b + segTbl[b];
613 data[i] = qRgba(r, g, b,a); 617 data[i] = qRgba(r, g, b,a);
614 } 618 }
615 } 619 }
616 else{ 620 else{
617 for(int i=0; i < pixels; ++i){ 621 for(int i=0; i < pixels; ++i){
618 int r = qRed(data[i]); 622 int r = qRed(data[i]);
619 int g = qGreen(data[i]); 623 int g = qGreen(data[i]);
620 int b = qBlue(data[i]); 624 int b = qBlue(data[i]);
621 int a = qAlpha(data[i]); 625 int a = qAlpha(data[i]);
622 r = r - segTbl[r] < 0 ? 0 : r - segTbl[r]; 626 r = r - segTbl[r] < 0 ? 0 : r - segTbl[r];
623 g = g - segTbl[g] < 0 ? 0 : g - segTbl[g]; 627 g = g - segTbl[g] < 0 ? 0 : g - segTbl[g];
624 b = b - segTbl[b] < 0 ? 0 : b - segTbl[b]; 628 b = b - segTbl[b] < 0 ? 0 : b - segTbl[b];
625 data[i] = qRgba(r, g, b, a); 629 data[i] = qRgba(r, g, b, a);
626 } 630 }
627 } 631 }
628 delete [] segTbl; 632 delete [] segTbl;
629 633
630 return image; 634 return image;
631} 635}
632 636
633QImage& OImageEffect::channelIntensity(QImage &image, float percent, 637QImage& OImageEffect::channelIntensity(QImage &image, float percent,
634 RGBComponent channel) 638 RGBComponent channel)
635{ 639{
636 if (image.width() == 0 || image.height() == 0) { 640 if (image.width() == 0 || image.height() == 0) {
637 odebug << "WARNING: OImageEffect::channelIntensity : invalid image" << oendl; 641 odebug << "WARNING: OImageEffect::channelIntensity : invalid image" << oendl;
638 return image; 642 return image;
639 } 643 }
640 644
641 int segColors = image.depth() > 8 ? 256 : image.numColors(); 645 int segColors = image.depth() > 8 ? 256 : image.numColors();
642 unsigned char *segTbl = new unsigned char[segColors]; 646 unsigned char *segTbl = new unsigned char[segColors];
643 int pixels = image.depth() > 8 ? image.width()*image.height() : 647 int pixels = image.depth() > 8 ? image.width()*image.height() :
644 image.numColors(); 648 image.numColors();
645 unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() : 649 unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() :
646 (unsigned int *)image.colorTable(); 650 (unsigned int *)image.colorTable();
647 bool brighten = (percent >= 0); 651 bool brighten = (percent >= 0);
648 if(percent < 0) 652 if(percent < 0)
649 percent = -percent; 653 percent = -percent;
650 654
651 if(brighten){ // keep overflow check out of loops 655 if(brighten){ // keep overflow check out of loops
652 for(int i=0; i < segColors; ++i){ 656 for(int i=0; i < segColors; ++i){
653 int tmp = (int)(i*percent); 657 int tmp = (int)(i*percent);
654 if(tmp > 255) 658 if(tmp > 255)
655 tmp = 255; 659 tmp = 255;
656 segTbl[i] = tmp; 660 segTbl[i] = tmp;
657 } 661 }
658 } 662 }
659 else{ 663 else{
660 for(int i=0; i < segColors; ++i){ 664 for(int i=0; i < segColors; ++i){
661 int tmp = (int)(i*percent); 665 int tmp = (int)(i*percent);
662 if(tmp < 0) 666 if(tmp < 0)
663 tmp = 0; 667 tmp = 0;
664 segTbl[i] = tmp; 668 segTbl[i] = tmp;
665 } 669 }
666 } 670 }
667 671
668 if(brighten){ // same here 672 if(brighten){ // same here
669 if(channel == Red){ // and here ;-) 673 if(channel == Red){ // and here ;-)
670 for(int i=0; i < pixels; ++i){ 674 for(int i=0; i < pixels; ++i){
671 int c = qRed(data[i]); 675 int c = qRed(data[i]);
672 c = c + segTbl[c] > 255 ? 255 : c + segTbl[c]; 676 c = c + segTbl[c] > 255 ? 255 : c + segTbl[c];
673 data[i] = qRgba(c, qGreen(data[i]), qBlue(data[i]), qAlpha(data[i])); 677 data[i] = qRgba(c, qGreen(data[i]), qBlue(data[i]), qAlpha(data[i]));
674 } 678 }
675 } 679 }
676 if(channel == Green){ 680 if(channel == Green){
677 for(int i=0; i < pixels; ++i){ 681 for(int i=0; i < pixels; ++i){
678 int c = qGreen(data[i]); 682 int c = qGreen(data[i]);
679 c = c + segTbl[c] > 255 ? 255 : c + segTbl[c]; 683 c = c + segTbl[c] > 255 ? 255 : c + segTbl[c];
680 data[i] = qRgba(qRed(data[i]), c, qBlue(data[i]), qAlpha(data[i])); 684 data[i] = qRgba(qRed(data[i]), c, qBlue(data[i]), qAlpha(data[i]));
681 } 685 }
682 } 686 }
683 else{ 687 else{
684 for(int i=0; i < pixels; ++i){ 688 for(int i=0; i < pixels; ++i){
685 int c = qBlue(data[i]); 689 int c = qBlue(data[i]);
686 c = c + segTbl[c] > 255 ? 255 : c + segTbl[c]; 690 c = c + segTbl[c] > 255 ? 255 : c + segTbl[c];
687 data[i] = qRgba(qRed(data[i]), qGreen(data[i]), c, qAlpha(data[i])); 691 data[i] = qRgba(qRed(data[i]), qGreen(data[i]), c, qAlpha(data[i]));
688 } 692 }
689 } 693 }
690 694
691 } 695 }
692 else{ 696 else{
693 if(channel == Red){ 697 if(channel == Red){
694 for(int i=0; i < pixels; ++i){ 698 for(int i=0; i < pixels; ++i){
695 int c = qRed(data[i]); 699 int c = qRed(data[i]);
696 c = c - segTbl[c] < 0 ? 0 : c - segTbl[c]; 700 c = c - segTbl[c] < 0 ? 0 : c - segTbl[c];
697 data[i] = qRgba(c, qGreen(data[i]), qBlue(data[i]), qAlpha(data[i])); 701 data[i] = qRgba(c, qGreen(data[i]), qBlue(data[i]), qAlpha(data[i]));
698 } 702 }
699 } 703 }
700 if(channel == Green){ 704 if(channel == Green){
701 for(int i=0; i < pixels; ++i){ 705 for(int i=0; i < pixels; ++i){
702 int c = qGreen(data[i]); 706 int c = qGreen(data[i]);
703 c = c - segTbl[c] < 0 ? 0 : c - segTbl[c]; 707 c = c - segTbl[c] < 0 ? 0 : c - segTbl[c];
704 data[i] = qRgba(qRed(data[i]), c, qBlue(data[i]), qAlpha(data[i])); 708 data[i] = qRgba(qRed(data[i]), c, qBlue(data[i]), qAlpha(data[i]));
705 } 709 }
706 } 710 }
707 else{ 711 else{
708 for(int i=0; i < pixels; ++i){ 712 for(int i=0; i < pixels; ++i){
709 int c = qBlue(data[i]); 713 int c = qBlue(data[i]);
710 c = c - segTbl[c] < 0 ? 0 : c - segTbl[c]; 714 c = c - segTbl[c] < 0 ? 0 : c - segTbl[c];
711 data[i] = qRgba(qRed(data[i]), qGreen(data[i]), c, qAlpha(data[i])); 715 data[i] = qRgba(qRed(data[i]), qGreen(data[i]), c, qAlpha(data[i]));
712 } 716 }
713 } 717 }
714 } 718 }
715 delete [] segTbl; 719 delete [] segTbl;
716 720
717 return image; 721 return image;
718} 722}
719 723
720// Modulate an image with an RBG channel of another image 724// Modulate an image with an RBG channel of another image
721// 725//
722QImage& OImageEffect::modulate(QImage &image, QImage &modImage, bool reverse, 726QImage& OImageEffect::modulate(QImage &image, QImage &modImage, bool reverse,
723 ModulationType type, int factor, RGBComponent channel) 727 ModulationType type, int factor, RGBComponent channel)
724{ 728{
725 if (image.width() == 0 || image.height() == 0 || 729 if (image.width() == 0 || image.height() == 0 ||
726 modImage.width() == 0 || modImage.height() == 0) { 730 modImage.width() == 0 || modImage.height() == 0) {
727 odebug << "WARNING: OImageEffect::modulate : invalid image" << oendl; 731 odebug << "WARNING: OImageEffect::modulate : invalid image" << oendl;
728 return image; 732 return image;
729 } 733 }
730 734
731 int r, g, b, h, s, v, a; 735 int r, g, b, h, s, v, a;
732 QColor clr; 736 QColor clr;
733 int mod=0; 737 int mod=0;
734 unsigned int x1, x2, y1, y2; 738 unsigned int x1, x2, y1, y2;
735 register int x, y; 739 register int x, y;
736 740
737 // for image, we handle only depth 32 741 // for image, we handle only depth 32
738 if (image.depth()<32) image = image.convertDepth(32); 742 if (image.depth()<32) image = image.convertDepth(32);
739 743
740 // for modImage, we handle depth 8 and 32 744 // for modImage, we handle depth 8 and 32
741 if (modImage.depth()<8) modImage = modImage.convertDepth(8); 745 if (modImage.depth()<8) modImage = modImage.convertDepth(8);
742 746
743 unsigned int *colorTable2 = (modImage.depth()==8) ? 747 unsigned int *colorTable2 = (modImage.depth()==8) ?
744 modImage.colorTable():0; 748 modImage.colorTable():0;
745 unsigned int *data1, *data2; 749 unsigned int *data1, *data2;
746 unsigned char *data2b; 750 unsigned char *data2b;
747 unsigned int color1, color2; 751 unsigned int color1, color2;
748 752
749 x1 = image.width(); y1 = image.height(); 753 x1 = image.width(); y1 = image.height();
750 x2 = modImage.width(); y2 = modImage.height(); 754 x2 = modImage.width(); y2 = modImage.height();
751 755
752 for (y = 0; y < (int)y1; y++) { 756 for (y = 0; y < (int)y1; y++) {
753 data1 = (unsigned int *) image.scanLine(y); 757 data1 = (unsigned int *) image.scanLine(y);
754 data2 = (unsigned int *) modImage.scanLine( y%y2 ); 758 data2 = (unsigned int *) modImage.scanLine( y%y2 );
755 data2b = (unsigned char *) modImage.scanLine( y%y2 ); 759 data2b = (unsigned char *) modImage.scanLine( y%y2 );
756 760
757 x=0; 761 x=0;
758 while(x < (int)x1) { 762 while(x < (int)x1) {
759 color2 = (colorTable2) ? colorTable2[*data2b] : *data2; 763 color2 = (colorTable2) ? colorTable2[*data2b] : *data2;
760 if (reverse) { 764 if (reverse) {
761 color1 = color2; 765 color1 = color2;
762 color2 = *data1; 766 color2 = *data1;
763 } 767 }
764 else 768 else
765 color1 = *data1; 769 color1 = *data1;
766 770
767 if (type == Intensity || type == Contrast) { 771 if (type == Intensity || type == Contrast) {
768 r = qRed(color1); 772 r = qRed(color1);
769 g = qGreen(color1); 773 g = qGreen(color1);
770 b = qBlue(color1); 774 b = qBlue(color1);
771 if (channel != All) { 775 if (channel != All) {
772 mod = (channel == Red) ? qRed(color2) : 776 mod = (channel == Red) ? qRed(color2) :
773 (channel == Green) ? qGreen(color2) : 777 (channel == Green) ? qGreen(color2) :
774 (channel == Blue) ? qBlue(color2) : 778 (channel == Blue) ? qBlue(color2) :
775 (channel == Gray) ? qGray(color2) : 0; 779 (channel == Gray) ? qGray(color2) : 0;
776 mod = mod*factor/50; 780 mod = mod*factor/50;
777 } 781 }
778 782
779 if (type == Intensity) { 783 if (type == Intensity) {
780 if (channel == All) { 784 if (channel == All) {
781 r += r * factor/50 * qRed(color2)/256; 785 r += r * factor/50 * qRed(color2)/256;
782 g += g * factor/50 * qGreen(color2)/256; 786 g += g * factor/50 * qGreen(color2)/256;
783 b += b * factor/50 * qBlue(color2)/256; 787 b += b * factor/50 * qBlue(color2)/256;
784 } 788 }
785 else { 789 else {
786 r += r * mod/256; 790 r += r * mod/256;
787 g += g * mod/256; 791 g += g * mod/256;
788 b += b * mod/256; 792 b += b * mod/256;
789 } 793 }
790 } 794 }
791 else { // Contrast 795 else { // Contrast
792 if (channel == All) { 796 if (channel == All) {
793 r += (r-128) * factor/50 * qRed(color2)/128; 797 r += (r-128) * factor/50 * qRed(color2)/128;
794 g += (g-128) * factor/50 * qGreen(color2)/128; 798 g += (g-128) * factor/50 * qGreen(color2)/128;
795 b += (b-128) * factor/50 * qBlue(color2)/128; 799 b += (b-128) * factor/50 * qBlue(color2)/128;
796 } 800 }
797 else { 801 else {
798 r += (r-128) * mod/128; 802 r += (r-128) * mod/128;
799 g += (g-128) * mod/128; 803 g += (g-128) * mod/128;
800 b += (b-128) * mod/128; 804 b += (b-128) * mod/128;
801 } 805 }
802 } 806 }
803 807
804 if (r<0) r=0; if (r>255) r=255; 808 if (r<0) r=0; if (r>255) r=255;
805 if (g<0) g=0; if (g>255) g=255; 809 if (g<0) g=0; if (g>255) g=255;
806 if (b<0) b=0; if (b>255) b=255; 810 if (b<0) b=0; if (b>255) b=255;
807 a = qAlpha(*data1); 811 a = qAlpha(*data1);
808 *data1 = qRgba(r, g, b, a); 812 *data1 = qRgba(r, g, b, a);
809 } 813 }
810 else if (type == Saturation || type == HueShift) { 814 else if (type == Saturation || type == HueShift) {
811 clr.setRgb(color1); 815 clr.setRgb(color1);
812 clr.hsv(&h, &s, &v); 816 clr.hsv(&h, &s, &v);
813 mod = (channel == Red) ? qRed(color2) : 817 mod = (channel == Red) ? qRed(color2) :
814 (channel == Green) ? qGreen(color2) : 818 (channel == Green) ? qGreen(color2) :
815 (channel == Blue) ? qBlue(color2) : 819 (channel == Blue) ? qBlue(color2) :
816 (channel == Gray) ? qGray(color2) : 0; 820 (channel == Gray) ? qGray(color2) : 0;
817 mod = mod*factor/50; 821 mod = mod*factor/50;
818 822
819 if (type == Saturation) { 823 if (type == Saturation) {
820 s -= s * mod/256; 824 s -= s * mod/256;
821 if (s<0) s=0; if (s>255) s=255; 825 if (s<0) s=0; if (s>255) s=255;
822 } 826 }
823 else { // HueShift 827 else { // HueShift
824 h += mod; 828 h += mod;
825 while(h<0) h+=360; 829 while(h<0) h+=360;
826 h %= 360; 830 h %= 360;
827 } 831 }
828 832
829 clr.setHsv(h, s, v); 833 clr.setHsv(h, s, v);
830 a = qAlpha(*data1); 834 a = qAlpha(*data1);
831 *data1 = clr.rgb() | ((uint)(a & 0xff) << 24); 835 *data1 = clr.rgb() | ((uint)(a & 0xff) << 24);
832 } 836 }
833 data1++; data2++; data2b++; x++; 837 data1++; data2++; data2b++; x++;
834 if ( (x%x2) ==0) { data2 -= x2; data2b -= x2; } 838 if ( (x%x2) ==0) { data2 -= x2; data2b -= x2; }
835 } 839 }
836 } 840 }
837 return image; 841 return image;
838} 842}
839 843
840 844
841 845
842//====================================================================== 846//======================================================================
843// 847//
844// Blend effects 848// Blend effects
845// 849//
846//====================================================================== 850//======================================================================
847 851
848 852
849// Nice and fast direct pixel manipulation 853// Nice and fast direct pixel manipulation
850QImage& OImageEffect::blend(const QColor& clr, QImage& dst, float opacity) 854QImage& OImageEffect::blend(const QColor& clr, QImage& dst, float opacity)
851{ 855{
852 if (dst.width() <= 0 || dst.height() <= 0) 856 if (dst.width() <= 0 || dst.height() <= 0)
853 return dst; 857 return dst;
854 858
855 if (opacity < 0.0 || opacity > 1.0) { 859 if (opacity < 0.0 || opacity > 1.0) {
856 odebug << "WARNING: OImageEffect::blend : invalid opacity. Range [0, 1] " << oendl; 860 odebug << "WARNING: OImageEffect::blend : invalid opacity. Range [0, 1] " << oendl;
857 return dst; 861 return dst;
858 } 862 }
859 863
860 int depth = dst.depth(); 864 int depth = dst.depth();
861 if (depth != 32) 865 if (depth != 32)
862 dst = dst.convertDepth(32); 866 dst = dst.convertDepth(32);
863 867
864 int pixels = dst.width() * dst.height(); 868 int pixels = dst.width() * dst.height();
865 int rcol, gcol, bcol; 869 int rcol, gcol, bcol;
866 clr.rgb(&rcol, &gcol, &bcol); 870 clr.rgb(&rcol, &gcol, &bcol);
867 871
868#ifdef WORDS_BIGENDIAN // ARGB (skip alpha) 872#ifdef WORDS_BIGENDIAN // ARGB (skip alpha)
869 register unsigned char *data = (unsigned char *)dst.bits() + 1; 873 register unsigned char *data = (unsigned char *)dst.bits() + 1;
870#else // BGRA 874#else // BGRA
871 register unsigned char *data = (unsigned char *)dst.bits(); 875 register unsigned char *data = (unsigned char *)dst.bits();
872#endif 876#endif
873 877
874 for (register int i=0; i<pixels; i++) 878 for (register int i=0; i<pixels; i++)
875 { 879 {
876#ifdef WORDS_BIGENDIAN 880#ifdef WORDS_BIGENDIAN
877 *(data++) += (unsigned char)((rcol - *data) * opacity); 881 *(data++) += (unsigned char)((rcol - *data) * opacity);
878 *(data++) += (unsigned char)((gcol - *data) * opacity); 882 *(data++) += (unsigned char)((gcol - *data) * opacity);
879 *(data++) += (unsigned char)((bcol - *data) * opacity); 883 *(data++) += (unsigned char)((bcol - *data) * opacity);
880#else 884#else
881 *(data++) += (unsigned char)((bcol - *data) * opacity); 885 *(data++) += (unsigned char)((bcol - *data) * opacity);
882 *(data++) += (unsigned char)((gcol - *data) * opacity); 886 *(data++) += (unsigned char)((gcol - *data) * opacity);
883 *(data++) += (unsigned char)((rcol - *data) * opacity); 887 *(data++) += (unsigned char)((rcol - *data) * opacity);
884#endif 888#endif
885 data++; // skip alpha 889 data++; // skip alpha
886 } 890 }
887 return dst; 891 return dst;
888} 892}
889 893
890// Nice and fast direct pixel manipulation 894// Nice and fast direct pixel manipulation
891QImage& OImageEffect::blend(QImage& src, QImage& dst, float opacity) 895QImage& OImageEffect::blend(QImage& src, QImage& dst, float opacity)
892{ 896{
893 if (src.width() <= 0 || src.height() <= 0) 897 if (src.width() <= 0 || src.height() <= 0)
894 return dst; 898 return dst;
895 if (dst.width() <= 0 || dst.height() <= 0) 899 if (dst.width() <= 0 || dst.height() <= 0)
896 return dst; 900 return dst;
897 901
898 if (src.width() != dst.width() || src.height() != dst.height()) { 902 if (src.width() != dst.width() || src.height() != dst.height()) {
899 odebug << "WARNING: OImageEffect::blend : src and destination images are not the same size" << oendl; 903 odebug << "WARNING: OImageEffect::blend : src and destination images are not the same size" << oendl;
900 return dst; 904 return dst;
901 } 905 }
902 906
903 if (opacity < 0.0 || opacity > 1.0) { 907 if (opacity < 0.0 || opacity > 1.0) {
904 odebug << "WARNING: OImageEffect::blend : invalid opacity. Range [0, 1]" << oendl; 908 odebug << "WARNING: OImageEffect::blend : invalid opacity. Range [0, 1]" << oendl;
905 return dst; 909 return dst;
906 } 910 }
907 911
908 if (src.depth() != 32) src = src.convertDepth(32); 912 if (src.depth() != 32) src = src.convertDepth(32);
909 if (dst.depth() != 32) dst = dst.convertDepth(32); 913 if (dst.depth() != 32) dst = dst.convertDepth(32);
910 914
911 int pixels = src.width() * src.height(); 915 int pixels = src.width() * src.height();
912#ifdef WORDS_BIGENDIAN // ARGB (skip alpha) 916#ifdef WORDS_BIGENDIAN // ARGB (skip alpha)
913 register unsigned char *data1 = (unsigned char *)dst.bits() + 1; 917 register unsigned char *data1 = (unsigned char *)dst.bits() + 1;
914 register unsigned char *data2 = (unsigned char *)src.bits() + 1; 918 register unsigned char *data2 = (unsigned char *)src.bits() + 1;
915#else // BGRA 919#else // BGRA
916 register unsigned char *data1 = (unsigned char *)dst.bits(); 920 register unsigned char *data1 = (unsigned char *)dst.bits();
917 register unsigned char *data2 = (unsigned char *)src.bits(); 921 register unsigned char *data2 = (unsigned char *)src.bits();
918#endif 922#endif
919 923
920 for (register int i=0; i<pixels; i++) 924 for (register int i=0; i<pixels; i++)
921 { 925 {
922#ifdef WORDS_BIGENDIAN 926#ifdef WORDS_BIGENDIAN
923 *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); 927 *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity);
924 *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); 928 *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity);
925 *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); 929 *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity);
926#else 930#else
927 *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); 931 *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity);
928 *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); 932 *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity);
929 *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); 933 *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity);
930#endif 934#endif
931 data1++; // skip alpha 935 data1++; // skip alpha
932 data2++; 936 data2++;
933 } 937 }
934 938
935 return dst; 939 return dst;
936} 940}
937 941
938 942
939QImage& OImageEffect::blend(QImage &image, float initial_intensity, 943QImage& OImageEffect::blend(QImage &image, float initial_intensity,
940 const QColor &bgnd, GradientType eff, 944 const QColor &bgnd, GradientType eff,
941 bool anti_dir) 945 bool anti_dir)
942{ 946{
943 if (image.width() == 0 || image.height() == 0 || image.depth()!=32 ) { 947 if (image.width() == 0 || image.height() == 0 || image.depth()!=32 ) {
944 odebug << "WARNING: OImageEffect::blend : invalid image" << oendl; 948 odebug << "WARNING: OImageEffect::blend : invalid image" << oendl;
945 return image; 949 return image;
946 } 950 }
947 951
948 int r_bgnd = bgnd.red(), g_bgnd = bgnd.green(), b_bgnd = bgnd.blue(); 952 int r_bgnd = bgnd.red(), g_bgnd = bgnd.green(), b_bgnd = bgnd.blue();
949 int r, g, b; 953 int r, g, b;
950 int ind; 954 int ind;
951 955
952 unsigned int xi, xf, yi, yf; 956 unsigned int xi, xf, yi, yf;
953 unsigned int a; 957 unsigned int a;
954 958
955 // check the boundaries of the initial intesity param 959 // check the boundaries of the initial intesity param
956 float unaffected = 1; 960 float unaffected = 1;
957 if (initial_intensity > 1) initial_intensity = 1; 961 if (initial_intensity > 1) initial_intensity = 1;
958 if (initial_intensity < -1) initial_intensity = -1; 962 if (initial_intensity < -1) initial_intensity = -1;
959 if (initial_intensity < 0) { 963 if (initial_intensity < 0) {
960 unaffected = 1. + initial_intensity; 964 unaffected = 1. + initial_intensity;
961 initial_intensity = 0; 965 initial_intensity = 0;
962 } 966 }
963 967
964 968
965 float intensity = initial_intensity; 969 float intensity = initial_intensity;
966 float var = 1. - initial_intensity; 970 float var = 1. - initial_intensity;
967 971
968 if (anti_dir) { 972 if (anti_dir) {
969 initial_intensity = intensity = 1.; 973 initial_intensity = intensity = 1.;
970 var = -var; 974 var = -var;
971 } 975 }
972 976
973 register int x, y; 977 register int x, y;
974 978
975 unsigned int *data = (unsigned int *)image.bits(); 979 unsigned int *data = (unsigned int *)image.bits();
976 980
977 int image_width = image.width(); //Those can't change 981 int image_width = image.width(); //Those can't change
978 int image_height = image.height(); 982 int image_height = image.height();
979 983
980 984
981 if( eff == VerticalGradient || eff == HorizontalGradient ) { 985 if( eff == VerticalGradient || eff == HorizontalGradient ) {
982 986
983 // set the image domain to apply the effect to 987 // set the image domain to apply the effect to
984 xi = 0, xf = image_width; 988 xi = 0, xf = image_width;
985 yi = 0, yf = image_height; 989 yi = 0, yf = image_height;
986 if (eff == VerticalGradient) { 990 if (eff == VerticalGradient) {
987 if (anti_dir) yf = (int)(image_height * unaffected); 991 if (anti_dir) yf = (int)(image_height * unaffected);
988 else yi = (int)(image_height * (1 - unaffected)); 992 else yi = (int)(image_height * (1 - unaffected));
989 } 993 }
990 else { 994 else {
991 if (anti_dir) xf = (int)(image_width * unaffected); 995 if (anti_dir) xf = (int)(image_width * unaffected);
992 else xi = (int)(image_height * (1 - unaffected)); 996 else xi = (int)(image_height * (1 - unaffected));
993 } 997 }
994 998
995 var /= (eff == VerticalGradient?yf-yi:xf-xi); 999 var /= (eff == VerticalGradient?yf-yi:xf-xi);
996 1000
997 int ind_base; 1001 int ind_base;
998 for (y = yi; y < (int)yf; y++) { 1002 for (y = yi; y < (int)yf; y++) {
999 intensity = eff == VerticalGradient? intensity + var : 1003 intensity = eff == VerticalGradient? intensity + var :
1000 initial_intensity; 1004 initial_intensity;
1001 ind_base = image_width * y ; 1005 ind_base = image_width * y ;
1002 for (x = xi; x < (int)xf ; x++) { 1006 for (x = xi; x < (int)xf ; x++) {
1003 if (eff == HorizontalGradient) intensity += var; 1007 if (eff == HorizontalGradient) intensity += var;
1004 ind = x + ind_base; 1008 ind = x + ind_base;
1005 r = qRed (data[ind]) + (int)(intensity * 1009 r = qRed (data[ind]) + (int)(intensity *
1006 (r_bgnd - qRed (data[ind]))); 1010 (r_bgnd - qRed (data[ind])));
1007 g = qGreen(data[ind]) + (int)(intensity * 1011 g = qGreen(data[ind]) + (int)(intensity *
1008 (g_bgnd - qGreen(data[ind]))); 1012 (g_bgnd - qGreen(data[ind])));
1009 b = qBlue (data[ind]) + (int)(intensity * 1013 b = qBlue (data[ind]) + (int)(intensity *
1010 (b_bgnd - qBlue (data[ind]))); 1014 (b_bgnd - qBlue (data[ind])));
1011 if (r > 255) r = 255; if (r < 0 ) r = 0; 1015 if (r > 255) r = 255; if (r < 0 ) r = 0;
1012 if (g > 255) g = 255; if (g < 0 ) g = 0; 1016 if (g > 255) g = 255; if (g < 0 ) g = 0;
1013 if (b > 255) b = 255; if (b < 0 ) b = 0; 1017 if (b > 255) b = 255; if (b < 0 ) b = 0;
1014 a = qAlpha(data[ind]); 1018 a = qAlpha(data[ind]);
1015 data[ind] = qRgba(r, g, b, a); 1019 data[ind] = qRgba(r, g, b, a);
1016 } 1020 }
1017 } 1021 }
1018 } 1022 }
1019 else if (eff == DiagonalGradient || eff == CrossDiagonalGradient) { 1023 else if (eff == DiagonalGradient || eff == CrossDiagonalGradient) {
1020 float xvar = var / 2 / image_width; // / unaffected; 1024 float xvar = var / 2 / image_width; // / unaffected;
1021 float yvar = var / 2 / image_height; // / unaffected; 1025 float yvar = var / 2 / image_height; // / unaffected;
1022 float tmp; 1026 float tmp;
1023 1027
1024 for (x = 0; x < image_width ; x++) { 1028 for (x = 0; x < image_width ; x++) {
1025 tmp = xvar * (eff == DiagonalGradient? x : image.width()-x-1); 1029 tmp = xvar * (eff == DiagonalGradient? x : image.width()-x-1);
1026 ind = x; 1030 ind = x;
1027 for (y = 0; y < image_height ; y++) { 1031 for (y = 0; y < image_height ; y++) {
1028 intensity = initial_intensity + tmp + yvar * y; 1032 intensity = initial_intensity + tmp + yvar * y;
1029 1033
1030 r = qRed (data[ind]) + (int)(intensity * 1034 r = qRed (data[ind]) + (int)(intensity *
1031 (r_bgnd - qRed (data[ind]))); 1035 (r_bgnd - qRed (data[ind])));
1032 g = qGreen(data[ind]) + (int)(intensity * 1036 g = qGreen(data[ind]) + (int)(intensity *
1033 (g_bgnd - qGreen(data[ind]))); 1037 (g_bgnd - qGreen(data[ind])));
1034 b = qBlue (data[ind]) + (int)(intensity * 1038 b = qBlue (data[ind]) + (int)(intensity *
1035 (b_bgnd - qBlue (data[ind]))); 1039 (b_bgnd - qBlue (data[ind])));
1036 if (r > 255) r = 255; if (r < 0 ) r = 0; 1040 if (r > 255) r = 255; if (r < 0 ) r = 0;
1037 if (g > 255) g = 255; if (g < 0 ) g = 0; 1041 if (g > 255) g = 255; if (g < 0 ) g = 0;
1038 if (b > 255) b = 255; if (b < 0 ) b = 0; 1042 if (b > 255) b = 255; if (b < 0 ) b = 0;
1039 a = qAlpha(data[ind]); 1043 a = qAlpha(data[ind]);
1040 data[ind] = qRgba(r, g, b, a); 1044 data[ind] = qRgba(r, g, b, a);
1041 1045
1042 ind += image_width; 1046 ind += image_width;
1043 } 1047 }
1044 } 1048 }
1045 } 1049 }
1046 1050
1047 else if (eff == RectangleGradient || eff == EllipticGradient) { 1051 else if (eff == RectangleGradient || eff == EllipticGradient) {
1048 float xvar; 1052 float xvar;
1049 float yvar; 1053 float yvar;
1050 1054
1051 for (x = 0; x < image_width / 2 + image_width % 2; x++) { 1055 for (x = 0; x < image_width / 2 + image_width % 2; x++) {
1052 xvar = var / image_width * (image_width - x*2/unaffected-1); 1056 xvar = var / image_width * (image_width - x*2/unaffected-1);
1053 for (y = 0; y < image_height / 2 + image_height % 2; y++) { 1057 for (y = 0; y < image_height / 2 + image_height % 2; y++) {
1054 yvar = var / image_height * (image_height - y*2/unaffected -1); 1058 yvar = var / image_height * (image_height - y*2/unaffected -1);
1055 1059
1056 if (eff == RectangleGradient) 1060 if (eff == RectangleGradient)
1057 intensity = initial_intensity + QMAX(xvar, yvar); 1061 intensity = initial_intensity + QMAX(xvar, yvar);
1058 else 1062 else
1059 intensity = initial_intensity + sqrt(xvar * xvar + yvar * yvar); 1063 intensity = initial_intensity + sqrt(xvar * xvar + yvar * yvar);
1060 if (intensity > 1) intensity = 1; 1064 if (intensity > 1) intensity = 1;
1061 if (intensity < 0) intensity = 0; 1065 if (intensity < 0) intensity = 0;
1062 1066
1063 //NW 1067 //NW
1064 ind = x + image_width * y ; 1068 ind = x + image_width * y ;
1065 r = qRed (data[ind]) + (int)(intensity * 1069 r = qRed (data[ind]) + (int)(intensity *
1066 (r_bgnd - qRed (data[ind]))); 1070 (r_bgnd - qRed (data[ind])));
1067 g = qGreen(data[ind]) + (int)(intensity * 1071 g = qGreen(data[ind]) + (int)(intensity *
1068 (g_bgnd - qGreen(data[ind]))); 1072 (g_bgnd - qGreen(data[ind])));
1069 b = qBlue (data[ind]) + (int)(intensity * 1073 b = qBlue (data[ind]) + (int)(intensity *
1070 (b_bgnd - qBlue (data[ind]))); 1074 (b_bgnd - qBlue (data[ind])));
1071 if (r > 255) r = 255; if (r < 0 ) r = 0; 1075 if (r > 255) r = 255; if (r < 0 ) r = 0;
1072 if (g > 255) g = 255; if (g < 0 ) g = 0; 1076 if (g > 255) g = 255; if (g < 0 ) g = 0;
1073 if (b > 255) b = 255; if (b < 0 ) b = 0; 1077 if (b > 255) b = 255; if (b < 0 ) b = 0;
1074 a = qAlpha(data[ind]); 1078 a = qAlpha(data[ind]);
1075 data[ind] = qRgba(r, g, b, a); 1079 data[ind] = qRgba(r, g, b, a);
1076 1080
1077 //NE 1081 //NE
1078 ind = image_width - x - 1 + image_width * y ; 1082 ind = image_width - x - 1 + image_width * y ;
1079 r = qRed (data[ind]) + (int)(intensity * 1083 r = qRed (data[ind]) + (int)(intensity *
1080 (r_bgnd - qRed (data[ind]))); 1084 (r_bgnd - qRed (data[ind])));
1081 g = qGreen(data[ind]) + (int)(intensity * 1085 g = qGreen(data[ind]) + (int)(intensity *
1082 (g_bgnd - qGreen(data[ind]))); 1086 (g_bgnd - qGreen(data[ind])));
1083 b = qBlue (data[ind]) + (int)(intensity * 1087 b = qBlue (data[ind]) + (int)(intensity *
1084 (b_bgnd - qBlue (data[ind]))); 1088 (b_bgnd - qBlue (data[ind])));
1085 if (r > 255) r = 255; if (r < 0 ) r = 0; 1089 if (r > 255) r = 255; if (r < 0 ) r = 0;
1086 if (g > 255) g = 255; if (g < 0 ) g = 0; 1090 if (g > 255) g = 255; if (g < 0 ) g = 0;
1087 if (b > 255) b = 255; if (b < 0 ) b = 0; 1091 if (b > 255) b = 255; if (b < 0 ) b = 0;
1088 a = qAlpha(data[ind]); 1092 a = qAlpha(data[ind]);
1089 data[ind] = qRgba(r, g, b, a); 1093 data[ind] = qRgba(r, g, b, a);
1090 } 1094 }
1091 } 1095 }
1092 1096
1093 //CT loop is doubled because of stupid central row/column issue. 1097 //CT loop is doubled because of stupid central row/column issue.
1094 // other solution? 1098 // other solution?
1095 for (x = 0; x < image_width / 2; x++) { 1099 for (x = 0; x < image_width / 2; x++) {
1096 xvar = var / image_width * (image_width - x*2/unaffected-1); 1100 xvar = var / image_width * (image_width - x*2/unaffected-1);
1097 for (y = 0; y < image_height / 2; y++) { 1101 for (y = 0; y < image_height / 2; y++) {
1098 yvar = var / image_height * (image_height - y*2/unaffected -1); 1102 yvar = var / image_height * (image_height - y*2/unaffected -1);
1099 1103
1100 if (eff == RectangleGradient) 1104 if (eff == RectangleGradient)
1101 intensity = initial_intensity + QMAX(xvar, yvar); 1105 intensity = initial_intensity + QMAX(xvar, yvar);
1102 else 1106 else
1103 intensity = initial_intensity + sqrt(xvar * xvar + yvar * yvar); 1107 intensity = initial_intensity + sqrt(xvar * xvar + yvar * yvar);
1104 if (intensity > 1) intensity = 1; 1108 if (intensity > 1) intensity = 1;
1105 if (intensity < 0) intensity = 0; 1109 if (intensity < 0) intensity = 0;
1106 1110
1107 //SW 1111 //SW
1108 ind = x + image_width * (image_height - y -1) ; 1112 ind = x + image_width * (image_height - y -1) ;
1109 r = qRed (data[ind]) + (int)(intensity * 1113 r = qRed (data[ind]) + (int)(intensity *
1110 (r_bgnd - qRed (data[ind]))); 1114 (r_bgnd - qRed (data[ind])));
1111 g = qGreen(data[ind]) + (int)(intensity * 1115 g = qGreen(data[ind]) + (int)(intensity *
1112 (g_bgnd - qGreen(data[ind]))); 1116 (g_bgnd - qGreen(data[ind])));
1113 b = qBlue (data[ind]) + (int)(intensity * 1117 b = qBlue (data[ind]) + (int)(intensity *
1114 (b_bgnd - qBlue (data[ind]))); 1118 (b_bgnd - qBlue (data[ind])));
1115 if (r > 255) r = 255; if (r < 0 ) r = 0; 1119 if (r > 255) r = 255; if (r < 0 ) r = 0;
1116 if (g > 255) g = 255; if (g < 0 ) g = 0; 1120 if (g > 255) g = 255; if (g < 0 ) g = 0;
1117 if (b > 255) b = 255; if (b < 0 ) b = 0; 1121 if (b > 255) b = 255; if (b < 0 ) b = 0;
1118 a = qAlpha(data[ind]); 1122 a = qAlpha(data[ind]);
1119 data[ind] = qRgba(r, g, b, a); 1123 data[ind] = qRgba(r, g, b, a);
1120 1124
1121 //SE 1125 //SE
1122 ind = image_width-x-1 + image_width * (image_height - y - 1) ; 1126 ind = image_width-x-1 + image_width * (image_height - y - 1) ;
1123 r = qRed (data[ind]) + (int)(intensity * 1127 r = qRed (data[ind]) + (int)(intensity *
1124 (r_bgnd - qRed (data[ind]))); 1128 (r_bgnd - qRed (data[ind])));
1125 g = qGreen(data[ind]) + (int)(intensity * 1129 g = qGreen(data[ind]) + (int)(intensity *
1126 (g_bgnd - qGreen(data[ind]))); 1130 (g_bgnd - qGreen(data[ind])));
1127 b = qBlue (data[ind]) + (int)(intensity * 1131 b = qBlue (data[ind]) + (int)(intensity *
1128 (b_bgnd - qBlue (data[ind]))); 1132 (b_bgnd - qBlue (data[ind])));
1129 if (r > 255) r = 255; if (r < 0 ) r = 0; 1133 if (r > 255) r = 255; if (r < 0 ) r = 0;
1130 if (g > 255) g = 255; if (g < 0 ) g = 0; 1134 if (g > 255) g = 255; if (g < 0 ) g = 0;
1131 if (b > 255) b = 255; if (b < 0 ) b = 0; 1135 if (b > 255) b = 255; if (b < 0 ) b = 0;
1132 a = qAlpha(data[ind]); 1136 a = qAlpha(data[ind]);
1133 data[ind] = qRgba(r, g, b, a); 1137 data[ind] = qRgba(r, g, b, a);
1134 } 1138 }
1135 } 1139 }
1136 } 1140 }
1137 else odebug << "OImageEffect::blend effect not implemented" << oendl; 1141 else odebug << "OImageEffect::blend effect not implemented" << oendl;
1138 return image; 1142 return image;
1139} 1143}
1140 1144
1141// Not very efficient as we create a third big image... 1145// Not very efficient as we create a third big image...
1142// 1146//
1143QImage& OImageEffect::blend(QImage &image1, QImage &image2, 1147QImage& OImageEffect::blend(QImage &image1, QImage &image2,
1144 GradientType gt, int xf, int yf) 1148 GradientType gt, int xf, int yf)
1145{ 1149{
1146 if (image1.width() == 0 || image1.height() == 0 || 1150 if (image1.width() == 0 || image1.height() == 0 ||
1147 image2.width() == 0 || image2.height() == 0) 1151 image2.width() == 0 || image2.height() == 0)
1148 return image1; 1152 return image1;
1149 1153
1150 QImage image3; 1154 QImage image3;
1151 1155
1152 image3 = OImageEffect::unbalancedGradient(image1.size(), 1156 image3 = OImageEffect::unbalancedGradient(image1.size(),
1153 QColor(0,0,0), QColor(255,255,255), 1157 QColor(0,0,0), QColor(255,255,255),
1154 gt, xf, yf, 0); 1158 gt, xf, yf, 0);
1155 1159
1156 return blend(image1,image2,image3, Red); // Channel to use is arbitrary 1160 return blend(image1,image2,image3, Red); // Channel to use is arbitrary
1157} 1161}
1158 1162
1159// Blend image2 into image1, using an RBG channel of blendImage 1163// Blend image2 into image1, using an RBG channel of blendImage
1160// 1164//
1161QImage& OImageEffect::blend(QImage &image1, QImage &image2, 1165QImage& OImageEffect::blend(QImage &image1, QImage &image2,
1162 QImage &blendImage, RGBComponent channel) 1166 QImage &blendImage, RGBComponent channel)
1163{ 1167{
1164 if (image1.width() == 0 || image1.height() == 0 || 1168 if (image1.width() == 0 || image1.height() == 0 ||
1165 image2.width() == 0 || image2.height() == 0 || 1169 image2.width() == 0 || image2.height() == 0 ||
1166 blendImage.width() == 0 || blendImage.height() == 0) { 1170 blendImage.width() == 0 || blendImage.height() == 0) {
1167 odebug << "OImageEffect::blend effect invalid image" << oendl; 1171 odebug << "OImageEffect::blend effect invalid image" << oendl;
1168 return image1; 1172 return image1;
1169 } 1173 }
1170 1174
1171 int r, g, b; 1175 int r, g, b;
1172 int ind1, ind2, ind3; 1176 int ind1, ind2, ind3;
1173 1177
1174 unsigned int x1, x2, x3, y1, y2, y3; 1178 unsigned int x1, x2, x3, y1, y2, y3;
1175 unsigned int a; 1179 unsigned int a;
1176 1180
1177 register int x, y; 1181 register int x, y;
1178 1182
1179 // for image1 and image2, we only handle depth 32 1183 // for image1 and image2, we only handle depth 32
1180 if (image1.depth()<32) image1 = image1.convertDepth(32); 1184 if (image1.depth()<32) image1 = image1.convertDepth(32);
1181 if (image2.depth()<32) image2 = image2.convertDepth(32); 1185 if (image2.depth()<32) image2 = image2.convertDepth(32);
1182 1186
1183 // for blendImage, we handle depth 8 and 32 1187 // for blendImage, we handle depth 8 and 32
1184 if (blendImage.depth()<8) blendImage = blendImage.convertDepth(8); 1188 if (blendImage.depth()<8) blendImage = blendImage.convertDepth(8);
1185 1189
1186 unsigned int *colorTable3 = (blendImage.depth()==8) ? 1190 unsigned int *colorTable3 = (blendImage.depth()==8) ?
1187 blendImage.colorTable():0; 1191 blendImage.colorTable():0;
1188 1192
1189 unsigned int *data1 = (unsigned int *)image1.bits(); 1193 unsigned int *data1 = (unsigned int *)image1.bits();
1190 unsigned int *data2 = (unsigned int *)image2.bits(); 1194 unsigned int *data2 = (unsigned int *)image2.bits();
1191 unsigned int *data3 = (unsigned int *)blendImage.bits(); 1195 unsigned int *data3 = (unsigned int *)blendImage.bits();
1192 unsigned char *data3b = (unsigned char *)blendImage.bits(); 1196 unsigned char *data3b = (unsigned char *)blendImage.bits();
1193 unsigned int color3; 1197 unsigned int color3;
1194 1198
1195 x1 = image1.width(); y1 = image1.height(); 1199 x1 = image1.width(); y1 = image1.height();
1196 x2 = image2.width(); y2 = image2.height(); 1200 x2 = image2.width(); y2 = image2.height();
1197 x3 = blendImage.width(); y3 = blendImage.height(); 1201 x3 = blendImage.width(); y3 = blendImage.height();
1198 1202
1199 for (y = 0; y < (int)y1; y++) { 1203 for (y = 0; y < (int)y1; y++) {
1200 ind1 = x1*y; 1204 ind1 = x1*y;
1201 ind2 = x2*(y%y2); 1205 ind2 = x2*(y%y2);
1202 ind3 = x3*(y%y3); 1206 ind3 = x3*(y%y3);
1203 1207
1204 x=0; 1208 x=0;
1205 while(x < (int)x1) { 1209 while(x < (int)x1) {
1206 color3 = (colorTable3) ? colorTable3[data3b[ind3]] : data3[ind3]; 1210 color3 = (colorTable3) ? colorTable3[data3b[ind3]] : data3[ind3];
1207 1211
1208 a = (channel == Red) ? qRed(color3) : 1212 a = (channel == Red) ? qRed(color3) :
1209 (channel == Green) ? qGreen(color3) : 1213 (channel == Green) ? qGreen(color3) :
1210 (channel == Blue) ? qBlue(color3) : qGray(color3); 1214 (channel == Blue) ? qBlue(color3) : qGray(color3);
1211 1215
1212 r = (a*qRed(data1[ind1]) + (256-a)*qRed(data2[ind2]))/256; 1216 r = (a*qRed(data1[ind1]) + (256-a)*qRed(data2[ind2]))/256;
1213 g = (a*qGreen(data1[ind1]) + (256-a)*qGreen(data2[ind2]))/256; 1217 g = (a*qGreen(data1[ind1]) + (256-a)*qGreen(data2[ind2]))/256;
1214 b = (a*qBlue(data1[ind1]) + (256-a)*qBlue(data2[ind2]))/256; 1218 b = (a*qBlue(data1[ind1]) + (256-a)*qBlue(data2[ind2]))/256;
1215 1219
1216 a = qAlpha(data1[ind1]); 1220 a = qAlpha(data1[ind1]);
1217 data1[ind1] = qRgba(r, g, b, a); 1221 data1[ind1] = qRgba(r, g, b, a);
1218 1222
1219 ind1++; ind2++; ind3++; x++; 1223 ind1++; ind2++; ind3++; x++;
1220 if ( (x%x2) ==0) ind2 -= x2; 1224 if ( (x%x2) ==0) ind2 -= x2;
1221 if ( (x%x3) ==0) ind3 -= x3; 1225 if ( (x%x3) ==0) ind3 -= x3;
1222 } 1226 }
1223 } 1227 }
1224 return image1; 1228 return image1;
1225} 1229}
1226 1230
1227 1231
1228//====================================================================== 1232//======================================================================
1229// 1233//
1230// Hash effects 1234// Hash effects
1231// 1235//
1232//====================================================================== 1236//======================================================================
1233 1237
1234unsigned int OImageEffect::lHash(unsigned int c) 1238unsigned int OImageEffect::lHash(unsigned int c)
1235{ 1239{
1236 unsigned char r = qRed(c), g = qGreen(c), b = qBlue(c), a = qAlpha(c); 1240 unsigned char r = qRed(c), g = qGreen(c), b = qBlue(c), a = qAlpha(c);
1237 unsigned char nr, ng, nb; 1241 unsigned char nr, ng, nb;
1238 nr =(r >> 1) + (r >> 2); nr = nr > r ? 0 : nr; 1242 nr =(r >> 1) + (r >> 2); nr = nr > r ? 0 : nr;
1239 ng =(g >> 1) + (g >> 2); ng = ng > g ? 0 : ng; 1243 ng =(g >> 1) + (g >> 2); ng = ng > g ? 0 : ng;
1240 nb =(b >> 1) + (b >> 2); nb = nb > b ? 0 : nb; 1244 nb =(b >> 1) + (b >> 2); nb = nb > b ? 0 : nb;
1241 1245
1242 return qRgba(nr, ng, nb, a); 1246 return qRgba(nr, ng, nb, a);
1243} 1247}
1244 1248
1245 1249
1246// ----------------------------------------------------------------------------- 1250// -----------------------------------------------------------------------------
1247 1251
1248unsigned int OImageEffect::uHash(unsigned int c) 1252unsigned int OImageEffect::uHash(unsigned int c)
1249{ 1253{
1250 unsigned char r = qRed(c), g = qGreen(c), b = qBlue(c), a = qAlpha(c); 1254 unsigned char r = qRed(c), g = qGreen(c), b = qBlue(c), a = qAlpha(c);
1251 unsigned char nr, ng, nb; 1255 unsigned char nr, ng, nb;
1252 nr = r + (r >> 3); nr = nr < r ? ~0 : nr; 1256 nr = r + (r >> 3); nr = nr < r ? ~0 : nr;
1253 ng = g + (g >> 3); ng = ng < g ? ~0 : ng; 1257 ng = g + (g >> 3); ng = ng < g ? ~0 : ng;
1254 nb = b + (b >> 3); nb = nb < b ? ~0 : nb; 1258 nb = b + (b >> 3); nb = nb < b ? ~0 : nb;
1255 1259
1256 return qRgba(nr, ng, nb, a); 1260 return qRgba(nr, ng, nb, a);
1257} 1261}
1258 1262
1259 1263
1260// ----------------------------------------------------------------------------- 1264// -----------------------------------------------------------------------------
1261 1265
1262QImage& OImageEffect::hash(QImage &image, Lighting lite, unsigned int spacing) 1266QImage& OImageEffect::hash(QImage &image, Lighting lite, unsigned int spacing)
1263{ 1267{
1264 if (image.width() == 0 || image.height() == 0) { 1268 if (image.width() == 0 || image.height() == 0) {
1265 odebug << "OImageEffect::hash effect invalid image" << oendl; 1269 odebug << "OImageEffect::hash effect invalid image" << oendl;
1266 return image; 1270 return image;
1267 } 1271 }
1268 1272
1269 register int x, y; 1273 register int x, y;
1270 unsigned int *data = (unsigned int *)image.bits(); 1274 unsigned int *data = (unsigned int *)image.bits();
1271 unsigned int ind; 1275 unsigned int ind;
1272 1276
1273 //CT no need to do it if not enough space 1277 //CT no need to do it if not enough space
1274 if ((lite == NorthLite || 1278 if ((lite == NorthLite ||
1275 lite == SouthLite)&& 1279 lite == SouthLite)&&
1276 (unsigned)image.height() < 2+spacing) return image; 1280 (unsigned)image.height() < 2+spacing) return image;
1277 if ((lite == EastLite || 1281 if ((lite == EastLite ||
1278 lite == WestLite)&& 1282 lite == WestLite)&&
1279 (unsigned)image.height() < 2+spacing) return image; 1283 (unsigned)image.height() < 2+spacing) return image;
1280 1284
1281 if (lite == NorthLite || lite == SouthLite) { 1285 if (lite == NorthLite || lite == SouthLite) {
1282 for (y = 0 ; y < image.height(); y = y + 2 + spacing) { 1286 for (y = 0 ; y < image.height(); y = y + 2 + spacing) {
1283 for (x = 0; x < image.width(); x++) { 1287 for (x = 0; x < image.width(); x++) {
1284 ind = x + image.width() * y; 1288 ind = x + image.width() * y;
1285 data[ind] = lite==NorthLite?uHash(data[ind]):lHash(data[ind]); 1289 data[ind] = lite==NorthLite?uHash(data[ind]):lHash(data[ind]);
1286 1290
1287 ind = ind + image.width(); 1291 ind = ind + image.width();
1288 data[ind] = lite==NorthLite?lHash(data[ind]):uHash(data[ind]); 1292 data[ind] = lite==NorthLite?lHash(data[ind]):uHash(data[ind]);
1289 } 1293 }
1290 } 1294 }
1291 } 1295 }
1292 1296
1293 else if (lite == EastLite || lite == WestLite) { 1297 else if (lite == EastLite || lite == WestLite) {
1294 for (y = 0 ; y < image.height(); y++) { 1298 for (y = 0 ; y < image.height(); y++) {
1295 for (x = 0; x < image.width(); x = x + 2 + spacing) { 1299 for (x = 0; x < image.width(); x = x + 2 + spacing) {
1296 ind = x + image.width() * y; 1300 ind = x + image.width() * y;
1297 data[ind] = lite==EastLite?uHash(data[ind]):lHash(data[ind]); 1301 data[ind] = lite==EastLite?uHash(data[ind]):lHash(data[ind]);
1298 1302
1299 ind++; 1303 ind++;
1300 data[ind] = lite==EastLite?lHash(data[ind]):uHash(data[ind]); 1304 data[ind] = lite==EastLite?lHash(data[ind]):uHash(data[ind]);
1301 } 1305 }
1302 } 1306 }
1303 } 1307 }
1304 1308
1305 else if (lite == NWLite || lite == SELite) { 1309 else if (lite == NWLite || lite == SELite) {
1306 for (y = 0 ; y < image.height(); y++) { 1310 for (y = 0 ; y < image.height(); y++) {
1307 for (x = 0; 1311 for (x = 0;
1308 x < (int)(image.width() - ((y & 1)? 1 : 0) * spacing); 1312 x < (int)(image.width() - ((y & 1)? 1 : 0) * spacing);
1309 x = x + 2 + spacing) { 1313 x = x + 2 + spacing) {
1310 ind = x + image.width() * y + ((y & 1)? 1 : 0); 1314 ind = x + image.width() * y + ((y & 1)? 1 : 0);
1311 data[ind] = lite==NWLite?uHash(data[ind]):lHash(data[ind]); 1315 data[ind] = lite==NWLite?uHash(data[ind]):lHash(data[ind]);
1312 1316
1313 ind++; 1317 ind++;
1314 data[ind] = lite==NWLite?lHash(data[ind]):uHash(data[ind]); 1318 data[ind] = lite==NWLite?lHash(data[ind]):uHash(data[ind]);
1315 } 1319 }
1316 } 1320 }
1317 } 1321 }
1318 1322
1319 else if (lite == SWLite || lite == NELite) { 1323 else if (lite == SWLite || lite == NELite) {
1320 for (y = 0 ; y < image.height(); y++) { 1324 for (y = 0 ; y < image.height(); y++) {
1321 for (x = 0 + ((y & 1)? 1 : 0); x < image.width(); x = x + 2 + spacing) { 1325 for (x = 0 + ((y & 1)? 1 : 0); x < image.width(); x = x + 2 + spacing) {
1322 ind = x + image.width() * y - ((y & 1)? 1 : 0); 1326 ind = x + image.width() * y - ((y & 1)? 1 : 0);
1323 data[ind] = lite==SWLite?uHash(data[ind]):lHash(data[ind]); 1327 data[ind] = lite==SWLite?uHash(data[ind]):lHash(data[ind]);
1324 1328
1325 ind++; 1329 ind++;
1326 data[ind] = lite==SWLite?lHash(data[ind]):uHash(data[ind]); 1330 data[ind] = lite==SWLite?lHash(data[ind]):uHash(data[ind]);
1327 } 1331 }
1328 } 1332 }
1329 } 1333 }
1330 1334
1331 return image; 1335 return image;
1332} 1336}
1333 1337
1334 1338
1335//====================================================================== 1339//======================================================================
1336// 1340//
1337// Flatten effects 1341// Flatten effects
1338// 1342//
1339//====================================================================== 1343//======================================================================
1340 1344
1341QImage& OImageEffect::flatten(QImage &img, const QColor &ca, 1345QImage& OImageEffect::flatten(QImage &img, const QColor &ca,
1342 const QColor &cb, int ncols) 1346 const QColor &cb, int ncols)
1343{ 1347{
1344 if (img.width() == 0 || img.height() == 0) 1348 if (img.width() == 0 || img.height() == 0)
1345 return img; 1349 return img;
1346 1350
1347 // a bitmap is easy... 1351 // a bitmap is easy...
1348 if (img.depth() == 1) { 1352 if (img.depth() == 1) {
1349 img.setColor(0, ca.rgb()); 1353 img.setColor(0, ca.rgb());
1350 img.setColor(1, cb.rgb()); 1354 img.setColor(1, cb.rgb());
1351 return img; 1355 return img;
1352 } 1356 }
1353 1357
1354 int r1 = ca.red(); int r2 = cb.red(); 1358 int r1 = ca.red(); int r2 = cb.red();
1355 int g1 = ca.green(); int g2 = cb.green(); 1359 int g1 = ca.green(); int g2 = cb.green();
1356 int b1 = ca.blue(); int b2 = cb.blue(); 1360 int b1 = ca.blue(); int b2 = cb.blue();
1357 int min = 0, max = 255; 1361 int min = 0, max = 255;
1358 1362
1359 QRgb col; 1363 QRgb col;
1360 1364
1361 // Get minimum and maximum greylevel. 1365 // Get minimum and maximum greylevel.
1362 if (img.numColors()) { 1366 if (img.numColors()) {
1363 // pseudocolor 1367 // pseudocolor
1364 for (int i = 0; i < img.numColors(); i++) { 1368 for (int i = 0; i < img.numColors(); i++) {
1365 col = img.color(i); 1369 col = img.color(i);
1366 int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3; 1370 int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3;
1367 min = QMIN(min, mean); 1371 min = QMIN(min, mean);
1368 max = QMAX(max, mean); 1372 max = QMAX(max, mean);
1369 } 1373 }
1370 } else { 1374 } else {
1371 // truecolor 1375 // truecolor
1372 for (int y=0; y < img.height(); y++) 1376 for (int y=0; y < img.height(); y++)
1373 for (int x=0; x < img.width(); x++) { 1377 for (int x=0; x < img.width(); x++) {
1374 col = img.pixel(x, y); 1378 col = img.pixel(x, y);
1375 int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3; 1379 int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3;
1376 min = QMIN(min, mean); 1380 min = QMIN(min, mean);
1377 max = QMAX(max, mean); 1381 max = QMAX(max, mean);
1378 } 1382 }
1379 } 1383 }
1380 1384
1381 // Conversion factors 1385 // Conversion factors
1382 float sr = ((float) r2 - r1) / (max - min); 1386 float sr = ((float) r2 - r1) / (max - min);
1383 float sg = ((float) g2 - g1) / (max - min); 1387 float sg = ((float) g2 - g1) / (max - min);
1384 float sb = ((float) b2 - b1) / (max - min); 1388 float sb = ((float) b2 - b1) / (max - min);
1385 1389
1386 1390
1387 // Repaint the image 1391 // Repaint the image
1388 if (img.numColors()) { 1392 if (img.numColors()) {
1389 for (int i=0; i < img.numColors(); i++) { 1393 for (int i=0; i < img.numColors(); i++) {
1390 col = img.color(i); 1394 col = img.color(i);
1391 int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3; 1395 int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3;
1392 int r = (int) (sr * (mean - min) + r1 + 0.5); 1396 int r = (int) (sr * (mean - min) + r1 + 0.5);
1393 int g = (int) (sg * (mean - min) + g1 + 0.5); 1397 int g = (int) (sg * (mean - min) + g1 + 0.5);
1394 int b = (int) (sb * (mean - min) + b1 + 0.5); 1398 int b = (int) (sb * (mean - min) + b1 + 0.5);
1395 img.setColor(i, qRgba(r, g, b, qAlpha(col))); 1399 img.setColor(i, qRgba(r, g, b, qAlpha(col)));
1396 } 1400 }
1397 } else { 1401 } else {
1398 for (int y=0; y < img.height(); y++) 1402 for (int y=0; y < img.height(); y++)
1399 for (int x=0; x < img.width(); x++) { 1403 for (int x=0; x < img.width(); x++) {
1400 col = img.pixel(x, y); 1404 col = img.pixel(x, y);
1401 int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3; 1405 int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3;
1402 int r = (int) (sr * (mean - min) + r1 + 0.5); 1406 int r = (int) (sr * (mean - min) + r1 + 0.5);
1403 int g = (int) (sg * (mean - min) + g1 + 0.5); 1407 int g = (int) (sg * (mean - min) + g1 + 0.5);
1404 int b = (int) (sb * (mean - min) + b1 + 0.5); 1408 int b = (int) (sb * (mean - min) + b1 + 0.5);
1405 img.setPixel(x, y, qRgba(r, g, b, qAlpha(col))); 1409 img.setPixel(x, y, qRgba(r, g, b, qAlpha(col)));
1406 } 1410 }
1407 } 1411 }
1408 1412
1409 1413
1410 // Dither if necessary 1414 // Dither if necessary
1411 if ( (ncols <= 0) || ((img.numColors() != 0) && (img.numColors() <= ncols))) 1415 if ( (ncols <= 0) || ((img.numColors() != 0) && (img.numColors() <= ncols)))
1412 return img; 1416 return img;
1413 1417
1414 if (ncols == 1) ncols++; 1418 if (ncols == 1) ncols++;
1415 if (ncols > 256) ncols = 256; 1419 if (ncols > 256) ncols = 256;
1416 1420
1417 QColor *pal = new QColor[ncols]; 1421 QColor *pal = new QColor[ncols];
1418 sr = ((float) r2 - r1) / (ncols - 1); 1422 sr = ((float) r2 - r1) / (ncols - 1);
1419 sg = ((float) g2 - g1) / (ncols - 1); 1423 sg = ((float) g2 - g1) / (ncols - 1);
1420 sb = ((float) b2 - b1) / (ncols - 1); 1424 sb = ((float) b2 - b1) / (ncols - 1);
1421 1425
1422 for (int i=0; i<ncols; i++) 1426 for (int i=0; i<ncols; i++)
1423 pal[i] = QColor(r1 + int(sr*i), g1 + int(sg*i), b1 + int(sb*i)); 1427 pal[i] = QColor(r1 + int(sr*i), g1 + int(sg*i), b1 + int(sb*i));
1424 1428
1425 dither(img, pal, ncols); 1429 dither(img, pal, ncols);
1426 1430
1427 delete[] pal; 1431 delete[] pal;
1428 return img; 1432 return img;
1429} 1433}
1430 1434
1431 1435
1432//====================================================================== 1436//======================================================================
1433// 1437//
1434// Fade effects 1438// Fade effects
1435// 1439//
1436//====================================================================== 1440//======================================================================
1437 1441
1438QImage& OImageEffect::fade(QImage &img, float val, const QColor &color) 1442QImage& OImageEffect::fade(QImage &img, float val, const QColor &color)
1439{ 1443{
1440 if (img.width() == 0 || img.height() == 0) 1444 if (img.width() == 0 || img.height() == 0)
1441 return img; 1445 return img;
1442 1446
1443 // We don't handle bitmaps 1447 // We don't handle bitmaps
1444 if (img.depth() == 1) 1448 if (img.depth() == 1)
1445 return img; 1449 return img;
1446 1450
1447 unsigned char tbl[256]; 1451 unsigned char tbl[256];
1448 for (int i=0; i<256; i++) 1452 for (int i=0; i<256; i++)
1449 tbl[i] = (int) (val * i + 0.5); 1453 tbl[i] = (int) (val * i + 0.5);
1450 1454
1451 int red = color.red(); 1455 int red = color.red();
1452 int green = color.green(); 1456 int green = color.green();
1453 int blue = color.blue(); 1457 int blue = color.blue();
1454 1458
1455 QRgb col; 1459 QRgb col;
1456 int r, g, b, cr, cg, cb; 1460 int r, g, b, cr, cg, cb;
1457 1461
1458 if (img.depth() <= 8) { 1462 if (img.depth() <= 8) {
1459 // pseudo color 1463 // pseudo color
1460 for (int i=0; i<img.numColors(); i++) { 1464 for (int i=0; i<img.numColors(); i++) {
1461 col = img.color(i); 1465 col = img.color(i);
1462 cr = qRed(col); cg = qGreen(col); cb = qBlue(col); 1466 cr = qRed(col); cg = qGreen(col); cb = qBlue(col);
1463 if (cr > red) 1467 if (cr > red)
1464 r = cr - tbl[cr - red]; 1468 r = cr - tbl[cr - red];
1465 else 1469 else
1466 r = cr + tbl[red - cr]; 1470 r = cr + tbl[red - cr];
1467 if (cg > green) 1471 if (cg > green)
1468 g = cg - tbl[cg - green]; 1472 g = cg - tbl[cg - green];
1469 else 1473 else
1470 g = cg + tbl[green - cg]; 1474 g = cg + tbl[green - cg];
1471 if (cb > blue) 1475 if (cb > blue)
1472 b = cb - tbl[cb - blue]; 1476 b = cb - tbl[cb - blue];
1473 else 1477 else
1474 b = cb + tbl[blue - cb]; 1478 b = cb + tbl[blue - cb];
1475 img.setColor(i, qRgba(r, g, b, qAlpha(col))); 1479 img.setColor(i, qRgba(r, g, b, qAlpha(col)));
1476 } 1480 }
1477 1481
1478 } else { 1482 } else {
1479 // truecolor 1483 // truecolor
1480 for (int y=0; y<img.height(); y++) { 1484 for (int y=0; y<img.height(); y++) {
1481 QRgb *data = (QRgb *) img.scanLine(y); 1485 QRgb *data = (QRgb *) img.scanLine(y);
1482 for (int x=0; x<img.width(); x++) { 1486 for (int x=0; x<img.width(); x++) {
1483 col = *data; 1487 col = *data;
1484 cr = qRed(col); cg = qGreen(col); cb = qBlue(col); 1488 cr = qRed(col); cg = qGreen(col); cb = qBlue(col);
1485 if (cr > red) 1489 if (cr > red)
1486 r = cr - tbl[cr - red]; 1490 r = cr - tbl[cr - red];
1487 else 1491 else
1488 r = cr + tbl[red - cr]; 1492 r = cr + tbl[red - cr];
1489 if (cg > green) 1493 if (cg > green)
1490 g = cg - tbl[cg - green]; 1494 g = cg - tbl[cg - green];
1491 else 1495 else
1492 g = cg + tbl[green - cg]; 1496 g = cg + tbl[green - cg];
1493 if (cb > blue) 1497 if (cb > blue)
1494 b = cb - tbl[cb - blue]; 1498 b = cb - tbl[cb - blue];
1495 else 1499 else
1496 b = cb + tbl[blue - cb]; 1500 b = cb + tbl[blue - cb];
1497 *data++ = qRgba(r, g, b, qAlpha(col)); 1501 *data++ = qRgba(r, g, b, qAlpha(col));
1498 } 1502 }
1499 } 1503 }
1500 } 1504 }
1501 1505
1502 return img; 1506 return img;
1503} 1507}
1504 1508
1505//====================================================================== 1509//======================================================================
1506// 1510//
1507// Color effects 1511// Color effects
1508// 1512//
1509//====================================================================== 1513//======================================================================
1510 1514
1511// This code is adapted from code (C) Rik Hemsley <rik@kde.org> 1515// This code is adapted from code (C) Rik Hemsley <rik@kde.org>
1512// 1516//
1513// The formula used (r + b + g) /3 is different from the qGray formula 1517// The formula used (r + b + g) /3 is different from the qGray formula
1514// used by Qt. This is because our formula is much much faster. If, 1518// used by Qt. This is because our formula is much much faster. If,
1515// however, it turns out that this is producing sub-optimal images, 1519// however, it turns out that this is producing sub-optimal images,
1516// then it will have to change (kurt) 1520// then it will have to change (kurt)
1517// 1521//
1518// It does produce lower quality grayscale ;-) Use fast == true for the fast 1522// It does produce lower quality grayscale ;-) Use fast == true for the fast
1519// algorithm, false for the higher quality one (mosfet). 1523// algorithm, false for the higher quality one (mosfet).
1520QImage& OImageEffect::toGray(QImage &img, bool fast) 1524QImage& OImageEffect::toGray(QImage &img, bool fast)
1521{ 1525{
1522 if (img.width() == 0 || img.height() == 0) 1526 if (img.width() == 0 || img.height() == 0)
1523 return img; 1527 return img;
1524 1528
1525 if(fast){ 1529 if(fast){
1526 if (img.depth() == 32) { 1530 if (img.depth() == 32) {
1527 register uchar * r(img.bits()); 1531 register uchar * r(img.bits());
1528 register uchar * g(img.bits() + 1); 1532 register uchar * g(img.bits() + 1);
1529 register uchar * b(img.bits() + 2); 1533 register uchar * b(img.bits() + 2);
1530 1534
1531 uchar * end(img.bits() + img.numBytes()); 1535 uchar * end(img.bits() + img.numBytes());
1532 1536
1533 while (r != end) { 1537 while (r != end) {
1534 1538
1535 *r = *g = *b = (((*r + *g) >> 1) + *b) >> 1; // (r + b + g) / 3 1539 *r = *g = *b = (((*r + *g) >> 1) + *b) >> 1; // (r + b + g) / 3
1536 1540
1537 r += 4; 1541 r += 4;
1538 g += 4; 1542 g += 4;
1539 b += 4; 1543 b += 4;
1540 } 1544 }
1541 } 1545 }
1542 else 1546 else
1543 { 1547 {
1544 for (int i = 0; i < img.numColors(); i++) 1548 for (int i = 0; i < img.numColors(); i++)
1545 { 1549 {
1546 register uint r = qRed(img.color(i)); 1550 register uint r = qRed(img.color(i));
1547 register uint g = qGreen(img.color(i)); 1551 register uint g = qGreen(img.color(i));
1548 register uint b = qBlue(img.color(i)); 1552 register uint b = qBlue(img.color(i));
1549 1553
1550 register uint gray = (((r + g) >> 1) + b) >> 1; 1554 register uint gray = (((r + g) >> 1) + b) >> 1;
1551 img.setColor(i, qRgba(gray, gray, gray, qAlpha(img.color(i)))); 1555 img.setColor(i, qRgba(gray, gray, gray, qAlpha(img.color(i))));
1552 } 1556 }
1553 } 1557 }
1554 } 1558 }
1555 else{ 1559 else{
1556 int pixels = img.depth() > 8 ? img.width()*img.height() : 1560 int pixels = img.depth() > 8 ? img.width()*img.height() :
1557 img.numColors(); 1561 img.numColors();
1558 unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() : 1562 unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() :
1559 (unsigned int *)img.colorTable(); 1563 (unsigned int *)img.colorTable();
1560 int val, i; 1564 int val, i;
1561 for(i=0; i < pixels; ++i){ 1565 for(i=0; i < pixels; ++i){
1562 val = qGray(data[i]); 1566 val = qGray(data[i]);
1563 data[i] = qRgba(val, val, val, qAlpha(data[i])); 1567 data[i] = qRgba(val, val, val, qAlpha(data[i]));
1564 } 1568 }
1565 } 1569 }
1566 return img; 1570 return img;
1567} 1571}
1568 1572
1569// CT 29Jan2000 - desaturation algorithms 1573// CT 29Jan2000 - desaturation algorithms
1570QImage& OImageEffect::desaturate(QImage &img, float desat) 1574QImage& OImageEffect::desaturate(QImage &img, float desat)
1571{ 1575{
1572 if (img.width() == 0 || img.height() == 0) 1576 if (img.width() == 0 || img.height() == 0)
1573 return img; 1577 return img;
1574 1578
1575 if (desat < 0) desat = 0.; 1579 if (desat < 0) desat = 0.;
1576 if (desat > 1) desat = 1.; 1580 if (desat > 1) desat = 1.;
1577 int pixels = img.depth() > 8 ? img.width()*img.height() : 1581 int pixels = img.depth() > 8 ? img.width()*img.height() :
1578 img.numColors(); 1582 img.numColors();
1579 unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() : 1583 unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() :
1580 (unsigned int *)img.colorTable(); 1584 (unsigned int *)img.colorTable();
1581 int h, s, v, i; 1585 int h, s, v, i;
1582 QColor clr; // keep constructor out of loop (mosfet) 1586 QColor clr; // keep constructor out of loop (mosfet)
1583 for(i=0; i < pixels; ++i){ 1587 for(i=0; i < pixels; ++i){
1584 clr.setRgb(data[i]); 1588 clr.setRgb(data[i]);
1585 clr.hsv(&h, &s, &v); 1589 clr.hsv(&h, &s, &v);
1586 clr.setHsv(h, (int)(s * (1. - desat)), v); 1590 clr.setHsv(h, (int)(s * (1. - desat)), v);
1587 data[i] = clr.rgb(); 1591 data[i] = clr.rgb();
1588 } 1592 }
1589 return img; 1593 return img;
1590} 1594}
1591 1595
1592// Contrast stuff (mosfet) 1596// Contrast stuff (mosfet)
1593QImage& OImageEffect::contrast(QImage &img, int c) 1597QImage& OImageEffect::contrast(QImage &img, int c)
1594{ 1598{
1595 if (img.width() == 0 || img.height() == 0) 1599 if (img.width() == 0 || img.height() == 0)
1596 return img; 1600 return img;
1597 1601
1598 if(c > 255) 1602 if(c > 255)
1599 c = 255; 1603 c = 255;
1600 if(c < -255) 1604 if(c < -255)
1601 c = -255; 1605 c = -255;
1602 int pixels = img.depth() > 8 ? img.width()*img.height() : 1606 int pixels = img.depth() > 8 ? img.width()*img.height() :
1603 img.numColors(); 1607 img.numColors();
1604 unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() : 1608 unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() :
1605 (unsigned int *)img.colorTable(); 1609 (unsigned int *)img.colorTable();
1606 int i, r, g, b; 1610 int i, r, g, b;
1607 for(i=0; i < pixels; ++i){ 1611 for(i=0; i < pixels; ++i){
1608 r = qRed(data[i]); 1612 r = qRed(data[i]);
1609 g = qGreen(data[i]); 1613 g = qGreen(data[i]);
1610 b = qBlue(data[i]); 1614 b = qBlue(data[i]);
1611 if(qGray(data[i]) <= 127){ 1615 if(qGray(data[i]) <= 127){
1612 if(r - c <= 255) 1616 if(r - c <= 255)
1613 r -= c; 1617 r -= c;
1614 if(g - c <= 255) 1618 if(g - c <= 255)
1615 g -= c; 1619 g -= c;
1616 if(b - c <= 255) 1620 if(b - c <= 255)
1617 b -= c; 1621 b -= c;
1618 } 1622 }
1619 else{ 1623 else{
1620 if(r + c <= 255) 1624 if(r + c <= 255)
1621 r += c; 1625 r += c;
1622 if(g + c <= 255) 1626 if(g + c <= 255)
1623 g += c; 1627 g += c;
1624 if(b + c <= 255) 1628 if(b + c <= 255)
1625 b += c; 1629 b += c;
1626 } 1630 }
1627 data[i] = qRgba(r, g, b, qAlpha(data[i])); 1631 data[i] = qRgba(r, g, b, qAlpha(data[i]));
1628 } 1632 }
1629 return(img); 1633 return(img);
1630} 1634}
1631 1635
1632//====================================================================== 1636//======================================================================
1633// 1637//
1634// Dithering effects 1638// Dithering effects
1635// 1639//
1636//====================================================================== 1640//======================================================================
1637 1641
1638// adapted from kFSDither (C) 1997 Martin Jones (mjones@kde.org) 1642// adapted from kFSDither (C) 1997 Martin Jones (mjones@kde.org)
1639// 1643//
1640// Floyd-Steinberg dithering 1644// Floyd-Steinberg dithering
1641// Ref: Bitmapped Graphics Programming in C++ 1645// Ref: Bitmapped Graphics Programming in C++
1642// Marv Luse, Addison-Wesley Publishing, 1993. 1646// Marv Luse, Addison-Wesley Publishing, 1993.
1643QImage& OImageEffect::dither(QImage &img, const QColor *palette, int size) 1647QImage& OImageEffect::dither(QImage &img, const QColor *palette, int size)
1644{ 1648{
1645 if (img.width() == 0 || img.height() == 0 || 1649 if (img.width() == 0 || img.height() == 0 ||
1646 palette == 0 || img.depth() <= 8) 1650 palette == 0 || img.depth() <= 8)
1647 return img; 1651 return img;
1648 1652
1649 QImage dImage( img.width(), img.height(), 8, size ); 1653 QImage dImage( img.width(), img.height(), 8, size );
1650 int i; 1654 int i;
1651 1655
1652 dImage.setNumColors( size ); 1656 dImage.setNumColors( size );
1653 for ( i = 0; i < size; i++ ) 1657 for ( i = 0; i < size; i++ )
1654 dImage.setColor( i, palette[ i ].rgb() ); 1658 dImage.setColor( i, palette[ i ].rgb() );
1655 1659
1656 int *rerr1 = new int [ img.width() * 2 ]; 1660 int *rerr1 = new int [ img.width() * 2 ];
1657 int *gerr1 = new int [ img.width() * 2 ]; 1661 int *gerr1 = new int [ img.width() * 2 ];
1658 int *berr1 = new int [ img.width() * 2 ]; 1662 int *berr1 = new int [ img.width() * 2 ];
1659 1663
1660 memset( rerr1, 0, sizeof( int ) * img.width() * 2 ); 1664 memset( rerr1, 0, sizeof( int ) * img.width() * 2 );
1661 memset( gerr1, 0, sizeof( int ) * img.width() * 2 ); 1665 memset( gerr1, 0, sizeof( int ) * img.width() * 2 );
1662 memset( berr1, 0, sizeof( int ) * img.width() * 2 ); 1666 memset( berr1, 0, sizeof( int ) * img.width() * 2 );
1663 1667
1664 int *rerr2 = rerr1 + img.width(); 1668 int *rerr2 = rerr1 + img.width();
1665 int *gerr2 = gerr1 + img.width(); 1669 int *gerr2 = gerr1 + img.width();
1666 int *berr2 = berr1 + img.width(); 1670 int *berr2 = berr1 + img.width();
1667 1671
1668 for ( int j = 0; j < img.height(); j++ ) 1672 for ( int j = 0; j < img.height(); j++ )
1669 { 1673 {
1670 uint *ip = (uint * )img.scanLine( j ); 1674 uint *ip = (uint * )img.scanLine( j );
1671 uchar *dp = dImage.scanLine( j ); 1675 uchar *dp = dImage.scanLine( j );
1672 1676
1673 for ( i = 0; i < img.width(); i++ ) 1677 for ( i = 0; i < img.width(); i++ )
1674 { 1678 {
1675 rerr1[i] = rerr2[i] + qRed( *ip ); 1679 rerr1[i] = rerr2[i] + qRed( *ip );
1676 rerr2[i] = 0; 1680 rerr2[i] = 0;
1677 gerr1[i] = gerr2[i] + qGreen( *ip ); 1681 gerr1[i] = gerr2[i] + qGreen( *ip );
1678 gerr2[i] = 0; 1682 gerr2[i] = 0;
1679 berr1[i] = berr2[i] + qBlue( *ip ); 1683 berr1[i] = berr2[i] + qBlue( *ip );
1680 berr2[i] = 0; 1684 berr2[i] = 0;
1681 ip++; 1685 ip++;
1682 } 1686 }
1683 1687
1684 *dp++ = nearestColor( rerr1[0], gerr1[0], berr1[0], palette, size ); 1688 *dp++ = nearestColor( rerr1[0], gerr1[0], berr1[0], palette, size );
1685 1689
1686 for ( i = 1; i < img.width()-1; i++ ) 1690 for ( i = 1; i < img.width()-1; i++ )
1687 { 1691 {
1688 int indx = nearestColor( rerr1[i], gerr1[i], berr1[i], palette, size ); 1692 int indx = nearestColor( rerr1[i], gerr1[i], berr1[i], palette, size );
1689 *dp = indx; 1693 *dp = indx;
1690 1694
1691 int rerr = rerr1[i]; 1695 int rerr = rerr1[i];
1692 rerr -= palette[indx].red(); 1696 rerr -= palette[indx].red();
1693 int gerr = gerr1[i]; 1697 int gerr = gerr1[i];
1694 gerr -= palette[indx].green(); 1698 gerr -= palette[indx].green();
1695 int berr = berr1[i]; 1699 int berr = berr1[i];
1696 berr -= palette[indx].blue(); 1700 berr -= palette[indx].blue();
1697 1701
1698 // diffuse red error 1702 // diffuse red error
1699 rerr1[ i+1 ] += ( rerr * 7 ) >> 4; 1703 rerr1[ i+1 ] += ( rerr * 7 ) >> 4;
1700 rerr2[ i-1 ] += ( rerr * 3 ) >> 4; 1704 rerr2[ i-1 ] += ( rerr * 3 ) >> 4;
1701 rerr2[ i ] += ( rerr * 5 ) >> 4; 1705 rerr2[ i ] += ( rerr * 5 ) >> 4;
1702 rerr2[ i+1 ] += ( rerr ) >> 4; 1706 rerr2[ i+1 ] += ( rerr ) >> 4;
1703 1707
1704 // diffuse green error 1708 // diffuse green error
1705 gerr1[ i+1 ] += ( gerr * 7 ) >> 4; 1709 gerr1[ i+1 ] += ( gerr * 7 ) >> 4;
1706 gerr2[ i-1 ] += ( gerr * 3 ) >> 4; 1710 gerr2[ i-1 ] += ( gerr * 3 ) >> 4;
1707 gerr2[ i ] += ( gerr * 5 ) >> 4; 1711 gerr2[ i ] += ( gerr * 5 ) >> 4;
1708 gerr2[ i+1 ] += ( gerr ) >> 4; 1712 gerr2[ i+1 ] += ( gerr ) >> 4;
1709 1713
1710 // diffuse red error 1714 // diffuse red error
1711 berr1[ i+1 ] += ( berr * 7 ) >> 4; 1715 berr1[ i+1 ] += ( berr * 7 ) >> 4;
1712 berr2[ i-1 ] += ( berr * 3 ) >> 4; 1716 berr2[ i-1 ] += ( berr * 3 ) >> 4;
1713 berr2[ i ] += ( berr * 5 ) >> 4; 1717 berr2[ i ] += ( berr * 5 ) >> 4;
1714 berr2[ i+1 ] += ( berr ) >> 4; 1718 berr2[ i+1 ] += ( berr ) >> 4;
1715 1719
1716 dp++; 1720 dp++;
1717 } 1721 }
1718 1722
1719 *dp = nearestColor( rerr1[i], gerr1[i], berr1[i], palette, size ); 1723 *dp = nearestColor( rerr1[i], gerr1[i], berr1[i], palette, size );
1720 } 1724 }
1721 1725
1722 delete [] rerr1; 1726 delete [] rerr1;
1723 delete [] gerr1; 1727 delete [] gerr1;
1724 delete [] berr1; 1728 delete [] berr1;
1725 1729
1726 img = dImage; 1730 img = dImage;
1727 return img; 1731 return img;
1728} 1732}
1729 1733
1730int OImageEffect::nearestColor( int r, int g, int b, const QColor *palette, int size ) 1734int OImageEffect::nearestColor( int r, int g, int b, const QColor *palette, int size )
1731{ 1735{
1732 if (palette == 0) 1736 if (palette == 0)
1733 return 0; 1737 return 0;
1734 1738
1735 int dr = palette[0].red() - r; 1739 int dr = palette[0].red() - r;
1736 int dg = palette[0].green() - g; 1740 int dg = palette[0].green() - g;
1737 int db = palette[0].blue() - b; 1741 int db = palette[0].blue() - b;
1738 1742
1739 int minDist = dr*dr + dg*dg + db*db; 1743 int minDist = dr*dr + dg*dg + db*db;
1740 int nearest = 0; 1744 int nearest = 0;
1741 1745
1742 for (int i = 1; i < size; i++ ) 1746 for (int i = 1; i < size; i++ )
1743 { 1747 {
1744 dr = palette[i].red() - r; 1748 dr = palette[i].red() - r;
1745 dg = palette[i].green() - g; 1749 dg = palette[i].green() - g;
1746 db = palette[i].blue() - b; 1750 db = palette[i].blue() - b;
1747 1751
1748 int dist = dr*dr + dg*dg + db*db; 1752 int dist = dr*dr + dg*dg + db*db;
1749 1753
1750 if ( dist < minDist ) 1754 if ( dist < minDist )
1751 { 1755 {
1752 minDist = dist; 1756 minDist = dist;
1753 nearest = i; 1757 nearest = i;
1754 } 1758 }
1755 } 1759 }
1756 1760
1757 return nearest; 1761 return nearest;
1758} 1762}
1759 1763
1760bool OImageEffect::blend( 1764bool OImageEffect::blend(
1761 const QImage & upper, 1765 const QImage & upper,
1762 const QImage & lower, 1766 const QImage & lower,
1763 QImage & output 1767 QImage & output
1764) 1768)
1765{ 1769{
1766 if ( 1770 if (
1767 upper.width() > lower.width() || 1771 upper.width() > lower.width() ||
1768 upper.height() > lower.height() || 1772 upper.height() > lower.height() ||
1769 upper.depth() != 32 || 1773 upper.depth() != 32 ||
1770 lower.depth() != 32 1774 lower.depth() != 32
1771 ) 1775 )
1772 { 1776 {
1773 odebug << "OImageEffect::blend : Sizes not correct" << oendl; 1777 odebug << "OImageEffect::blend : Sizes not correct" << oendl;
1774 return false; 1778 return false;
1775 } 1779 }
1776 1780
1777 output = lower.copy(); 1781 output = lower.copy();
1778 1782
1779 register uchar *i, *o; 1783 register uchar *i, *o;
1780 register int a; 1784 register int a;
1781 register int col; 1785 register int col;
1782 register int w = upper.width(); 1786 register int w = upper.width();
1783 int row(upper.height() - 1); 1787 int row(upper.height() - 1);
1784 1788
1785 do { 1789 do {
1786 1790
1787 i = upper.scanLine(row); 1791 i = upper.scanLine(row);
1788 o = output.scanLine(row); 1792 o = output.scanLine(row);
1789 1793
1790 col = w << 2; 1794 col = w << 2;
1791 --col; 1795 --col;
1792 1796
1793 do { 1797 do {
1794 1798
1795 while (!(a = i[col]) && (col != 3)) { 1799 while (!(a = i[col]) && (col != 3)) {
1796 --col; --col; --col; --col; 1800 --col; --col; --col; --col;
1797 } 1801 }
1798 1802
1799 --col; 1803 --col;
1800 o[col] += ((i[col] - o[col]) * a) >> 8; 1804 o[col] += ((i[col] - o[col]) * a) >> 8;
1801 1805
1802 --col; 1806 --col;
1803 o[col] += ((i[col] - o[col]) * a) >> 8; 1807 o[col] += ((i[col] - o[col]) * a) >> 8;
1804 1808
1805 --col; 1809 --col;
1806 o[col] += ((i[col] - o[col]) * a) >> 8; 1810 o[col] += ((i[col] - o[col]) * a) >> 8;
1807 1811
1808 } while (col--); 1812 } while (col--);
1809 1813
1810 } while (row--); 1814 } while (row--);
1811 1815
1812 return true; 1816 return true;
1813} 1817}
1814 1818
1815#if 0 1819#if 0
1816// Not yet... 1820// Not yet...
1817bool OImageEffect::blend( 1821bool OImageEffect::blend(
1818 const QImage & upper, 1822 const QImage & upper,
1819 const QImage & lower, 1823 const QImage & lower,
1820 QImage & output, 1824 QImage & output,
1821 const QRect & destRect 1825 const QRect & destRect
1822) 1826)
1823{ 1827{
1824 output = lower.copy(); 1828 output = lower.copy();
1825 return output; 1829 return output;
1826} 1830}
1827 1831
1828#endif 1832#endif
1829 1833
1830bool OImageEffect::blend( 1834bool OImageEffect::blend(
1831 int &x, int &y, 1835 int &x, int &y,
1832 const QImage & upper, 1836 const QImage & upper,
1833 const QImage & lower, 1837 const QImage & lower,
1834 QImage & output 1838 QImage & output
1835) 1839)
1836{ 1840{
1837 int cx=0, cy=0, cw=upper.width(), ch=upper.height(); 1841 int cx=0, cy=0, cw=upper.width(), ch=upper.height();
1838 1842
1839 if ( upper.width() + x > lower.width() || 1843 if ( upper.width() + x > lower.width() ||
1840 upper.height() + y > lower.height() || 1844 upper.height() + y > lower.height() ||
1841 x < 0 || y < 0 || 1845 x < 0 || y < 0 ||
1842 upper.depth() != 32 || lower.depth() != 32 ) 1846 upper.depth() != 32 || lower.depth() != 32 )
1843 { 1847 {
1844 if ( x > lower.width() || y > lower.height() ) return false; 1848 if ( x > lower.width() || y > lower.height() ) return false;
1845 if ( upper.width()<=0 || upper.height() <= 0 ) return false; 1849 if ( upper.width()<=0 || upper.height() <= 0 ) return false;
1846 if ( lower.width()<=0 || lower.height() <= 0 ) return false; 1850 if ( lower.width()<=0 || lower.height() <= 0 ) return false;
1847 1851
1848 if (x<0) {cx=-x; cw+=x; x=0; }; 1852 if (x<0) {cx=-x; cw+=x; x=0; };
1849 if (cw + x > lower.width()) { cw=lower.width()-x; }; 1853 if (cw + x > lower.width()) { cw=lower.width()-x; };
1850 if (y<0) {cy=-y; ch+=y; y=0; }; 1854 if (y<0) {cy=-y; ch+=y; y=0; };
1851 if (ch + y > lower.height()) { ch=lower.height()-y; }; 1855 if (ch + y > lower.height()) { ch=lower.height()-y; };
1852 1856
1853 if ( cx >= upper.width() || cy >= upper.height() ) return true; 1857 if ( cx >= upper.width() || cy >= upper.height() ) return true;
1854 if ( cw <= 0 || ch <= 0 ) return true; 1858 if ( cw <= 0 || ch <= 0 ) return true;
1855 } 1859 }
1856 1860
1857 output.create(cw,ch,32); 1861 output.create(cw,ch,32);
1858// output.setAlphaBuffer(true); // I should do some benchmarks to see if 1862// output.setAlphaBuffer(true); // I should do some benchmarks to see if
1859 // this is worth the effort 1863 // this is worth the effort
1860 1864
1861 register QRgb *i, *o, *b; 1865 register QRgb *i, *o, *b;
1862 1866
1863 register int a; 1867 register int a;
1864 register int j,k; 1868 register int j,k;
1865 for (j=0; j<ch; j++) 1869 for (j=0; j<ch; j++)
1866 { 1870 {
1867 b=reinterpret_cast<QRgb *>(&lower.scanLine(y+j) [ (x+cw) << 2 ]); 1871 b=reinterpret_cast<QRgb *>(&lower.scanLine(y+j) [ (x+cw) << 2 ]);
1868 i=reinterpret_cast<QRgb *>(&upper.scanLine(cy+j)[ (cx+cw) << 2 ]); 1872 i=reinterpret_cast<QRgb *>(&upper.scanLine(cy+j)[ (cx+cw) << 2 ]);
1869 o=reinterpret_cast<QRgb *>(&output.scanLine(j) [ cw << 2 ]); 1873 o=reinterpret_cast<QRgb *>(&output.scanLine(j) [ cw << 2 ]);
1870 1874
1871 k=cw-1; 1875 k=cw-1;
1872 --b; --i; --o; 1876 --b; --i; --o;
1873 do 1877 do
1874 { 1878 {
1875 while ( !(a=qAlpha(*i)) && k>0 ) 1879 while ( !(a=qAlpha(*i)) && k>0 )
1876 { 1880 {
1877 i--; 1881 i--;
1878 //*o=0; 1882 //*o=0;
1879 *o=*b; 1883 *o=*b;
1880 --o; --b; 1884 --o; --b;
1881 k--; 1885 k--;
1882 }; 1886 };
1883// *o=0xFF; 1887// *o=0xFF;
1884 *o = qRgb(qRed(*b) + (((qRed(*i) - qRed(*b)) * a) >> 8), 1888 *o = qRgb(qRed(*b) + (((qRed(*i) - qRed(*b)) * a) >> 8),
1885 qGreen(*b) + (((qGreen(*i) - qGreen(*b)) * a) >> 8), 1889 qGreen(*b) + (((qGreen(*i) - qGreen(*b)) * a) >> 8),
1886 qBlue(*b) + (((qBlue(*i) - qBlue(*b)) * a) >> 8)); 1890 qBlue(*b) + (((qBlue(*i) - qBlue(*b)) * a) >> 8));
1887 --i; --o; --b; 1891 --i; --o; --b;
1888 } while (k--); 1892 } while (k--);
1889 } 1893 }
1890 1894
1891 return true; 1895 return true;
1892} 1896}
1893 1897
1894bool OImageEffect::blendOnLower( 1898bool OImageEffect::blendOnLower(
1895 int x, int y, 1899 int x, int y,
1896 const QImage & upper, 1900 const QImage & upper,
1897 const QImage & lower 1901 const QImage & lower
1898) 1902)
1899{ 1903{
1900 int cx=0, cy=0, cw=upper.width(), ch=upper.height(); 1904 int cx=0, cy=0, cw=upper.width(), ch=upper.height();
1901 1905
1902 if ( upper.depth() != 32 || lower.depth() != 32 ) return false; 1906 if ( upper.depth() != 32 || lower.depth() != 32 ) return false;
1903 if ( x + cw > lower.width() || 1907 if ( x + cw > lower.width() ||
1904 y + ch > lower.height() || 1908 y + ch > lower.height() ||
1905 x < 0 || y < 0 ) 1909 x < 0 || y < 0 )
1906 { 1910 {
1907 if ( x > lower.width() || y > lower.height() ) return true; 1911 if ( x > lower.width() || y > lower.height() ) return true;
1908 if ( upper.width()<=0 || upper.height() <= 0 ) return true; 1912 if ( upper.width()<=0 || upper.height() <= 0 ) return true;
1909 if ( lower.width()<=0 || lower.height() <= 0 ) return true; 1913 if ( lower.width()<=0 || lower.height() <= 0 ) return true;
1910 1914
1911 if (x<0) {cx=-x; cw+=x; x=0; }; 1915 if (x<0) {cx=-x; cw+=x; x=0; };
1912 if (cw + x > lower.width()) { cw=lower.width()-x; }; 1916 if (cw + x > lower.width()) { cw=lower.width()-x; };
1913 if (y<0) {cy=-y; ch+=y; y=0; }; 1917 if (y<0) {cy=-y; ch+=y; y=0; };
1914 if (ch + y > lower.height()) { ch=lower.height()-y; }; 1918 if (ch + y > lower.height()) { ch=lower.height()-y; };
1915 1919
1916 if ( cx >= upper.width() || cy >= upper.height() ) return true; 1920 if ( cx >= upper.width() || cy >= upper.height() ) return true;
1917 if ( cw <= 0 || ch <= 0 ) return true; 1921 if ( cw <= 0 || ch <= 0 ) return true;
1918 } 1922 }
1919 1923
1920 register uchar *i, *b; 1924 register uchar *i, *b;
1921 register int a; 1925 register int a;
1922 register int k; 1926 register int k;
1923 1927
1924 for (int j=0; j<ch; j++) 1928 for (int j=0; j<ch; j++)
1925 { 1929 {
1926 b=&lower.scanLine(y+j) [ (x+cw) << 2 ]; 1930 b=&lower.scanLine(y+j) [ (x+cw) << 2 ];
1927 i=&upper.scanLine(cy+j)[ (cx+cw) << 2 ]; 1931 i=&upper.scanLine(cy+j)[ (cx+cw) << 2 ];
1928 1932
1929 k=cw-1; 1933 k=cw-1;
1930 --b; --i; 1934 --b; --i;
1931 do 1935 do
1932 { 1936 {
1933#ifndef WORDS_BIGENDIAN 1937#ifndef WORDS_BIGENDIAN
1934 while ( !(a=*i) && k>0 ) 1938 while ( !(a=*i) && k>0 )
1935#else 1939#else
1936 while ( !(a=*(i-3)) && k>0 ) 1940 while ( !(a=*(i-3)) && k>0 )
1937#endif 1941#endif
1938 { 1942 {
1939 i-=4; b-=4; k--; 1943 i-=4; b-=4; k--;
1940 }; 1944 };
1941 1945
1942#ifndef WORDS_BIGENDIAN 1946#ifndef WORDS_BIGENDIAN
1943 --i; --b; 1947 --i; --b;
1944 *b += ( ((*i - *b) * a) >> 8 ); 1948 *b += ( ((*i - *b) * a) >> 8 );
1945 --i; --b; 1949 --i; --b;
1946 *b += ( ((*i - *b) * a) >> 8 ); 1950 *b += ( ((*i - *b) * a) >> 8 );
1947 --i; --b; 1951 --i; --b;
1948 *b += ( ((*i - *b) * a) >> 8 ); 1952 *b += ( ((*i - *b) * a) >> 8 );
1949 --i; --b; 1953 --i; --b;
1950#else 1954#else
1951 *b += ( ((*i - *b) * a) >> 8 ); 1955 *b += ( ((*i - *b) * a) >> 8 );
1952 --i; --b; 1956 --i; --b;
1953 *b += ( ((*i - *b) * a) >> 8 ); 1957 *b += ( ((*i - *b) * a) >> 8 );
1954 --i; --b; 1958 --i; --b;
1955 *b += ( ((*i - *b) * a) >> 8 ); 1959 *b += ( ((*i - *b) * a) >> 8 );
1956 i -= 2; b -= 2; 1960 i -= 2; b -= 2;
1957#endif 1961#endif
1958 } while (k--); 1962 } while (k--);
1959 } 1963 }
1960 1964
1961 return true; 1965 return true;
1962} 1966}
1963 1967
1964// For selected icons 1968// For selected icons
1965QImage& OImageEffect::selectedImage( QImage &img, const QColor &col ) 1969QImage& OImageEffect::selectedImage( QImage &img, const QColor &col )
1966{ 1970{
1967 return blend( col, img, 0.5); 1971 return blend( col, img, 0.5);
1968} 1972}
1969 1973
1970// 1974//
1971// =================================================================== 1975// ===================================================================
1972// Effects originally ported from ImageMagick for PixiePlus, plus a few 1976// Effects originally ported from ImageMagick for PixiePlus, plus a few
1973// new ones. (mosfet 12/29/01) 1977// new ones. (mosfet 12/29/01)
1974// =================================================================== 1978// ===================================================================
1975// 1979//
1976 1980
1977void OImageEffect::normalize(QImage &img) 1981void OImageEffect::normalize(QImage &img)
1978{ 1982{
1979 int *histogram, threshold_intensity, intense; 1983 int *histogram, threshold_intensity, intense;
1980 int x, y, i; 1984 int x, y, i;
1981 1985
1982 unsigned int gray_value; 1986 unsigned int gray_value;
1983 unsigned int *normalize_map; 1987 unsigned int *normalize_map;
1984 unsigned int high, low; 1988 unsigned int high, low;
1985 1989
1986 // allocate histogram and normalize map 1990 // allocate histogram and normalize map
1987 histogram = (int *)calloc(MaxRGB+1, sizeof(int)); 1991 histogram = (int *)calloc(MaxRGB+1, sizeof(int));
1988 normalize_map = (unsigned int *)malloc((MaxRGB+1)*sizeof(unsigned int)); 1992 normalize_map = (unsigned int *)malloc((MaxRGB+1)*sizeof(unsigned int));
1989 if(!normalize_map || !histogram){ 1993 if(!normalize_map || !histogram){
1990 owarn << "Unable to allocate normalize histogram and map" << oendl; 1994 owarn << "Unable to allocate normalize histogram and map" << oendl;
1991 free(normalize_map); 1995 free(normalize_map);
1992 free(histogram); 1996 free(histogram);
1993 return; 1997 return;
1994 } 1998 }
1995 1999
1996 // form histogram 2000 // form histogram
1997 if(img.depth() > 8){ // DirectClass 2001 if(img.depth() > 8){ // DirectClass
1998 unsigned int *data; 2002 unsigned int *data;
1999 for(y=0; y < img.height(); ++y){ 2003 for(y=0; y < img.height(); ++y){
2000 data = (unsigned int *)img.scanLine(y); 2004 data = (unsigned int *)img.scanLine(y);
2001 for(x=0; x < img.width(); ++x){ 2005 for(x=0; x < img.width(); ++x){
2002 gray_value = intensityValue(data[x]); 2006 gray_value = intensityValue(data[x]);
2003 histogram[gray_value]++; 2007 histogram[gray_value]++;
2004 } 2008 }
2005 } 2009 }
2006 } 2010 }
2007 else{ // PsudeoClass 2011 else{ // PsudeoClass
2008 unsigned char *data; 2012 unsigned char *data;
2009 unsigned int *cTable = img.colorTable(); 2013 unsigned int *cTable = img.colorTable();
2010 for(y=0; y < img.height(); ++y){ 2014 for(y=0; y < img.height(); ++y){
2011 data = (unsigned char *)img.scanLine(y); 2015 data = (unsigned char *)img.scanLine(y);
2012 for(x=0; x < img.width(); ++x){ 2016 for(x=0; x < img.width(); ++x){
2013 gray_value = intensityValue(*(cTable+data[x])); 2017 gray_value = intensityValue(*(cTable+data[x]));
2014 histogram[gray_value]++; 2018 histogram[gray_value]++;
2015 } 2019 }
2016 } 2020 }
2017 } 2021 }
2018 2022
2019 // find histogram boundaries by locating the 1 percent levels 2023 // find histogram boundaries by locating the 1 percent levels
2020 threshold_intensity = (img.width()*img.height())/100; 2024 threshold_intensity = (img.width()*img.height())/100;
2021 intense = 0; 2025 intense = 0;
2022 for(low=0; low < MaxRGB; ++low){ 2026 for(low=0; low < MaxRGB; ++low){
2023 intense+=histogram[low]; 2027 intense+=histogram[low];
2024 if(intense > threshold_intensity) 2028 if(intense > threshold_intensity)
2025 break; 2029 break;
2026 } 2030 }
2027 intense=0; 2031 intense=0;
2028 for(high=MaxRGB; high != 0; --high){ 2032 for(high=MaxRGB; high != 0; --high){
2029 intense+=histogram[high]; 2033 intense+=histogram[high];
2030 if(intense > threshold_intensity) 2034 if(intense > threshold_intensity)
2031 break; 2035 break;
2032 } 2036 }
2033 2037
2034 if (low == high){ 2038 if (low == high){
2035 // Unreasonable contrast; use zero threshold to determine boundaries. 2039 // Unreasonable contrast; use zero threshold to determine boundaries.
2036 threshold_intensity=0; 2040 threshold_intensity=0;
2037 intense=0; 2041 intense=0;
2038 for(low=0; low < MaxRGB; ++low){ 2042 for(low=0; low < MaxRGB; ++low){
2039 intense+=histogram[low]; 2043 intense+=histogram[low];
2040 if(intense > threshold_intensity) 2044 if(intense > threshold_intensity)
2041 break; 2045 break;
2042 } 2046 }
2043 intense=0; 2047 intense=0;
2044 for(high=MaxRGB; high != 0; --high) 2048 for(high=MaxRGB; high != 0; --high)
2045 { 2049 {
2046 intense+=histogram[high]; 2050 intense+=histogram[high];
2047 if(intense > threshold_intensity) 2051 if(intense > threshold_intensity)
2048 break; 2052 break;
2049 } 2053 }
2050 if(low == high) 2054 if(low == high)
2051 return; // zero span bound 2055 return; // zero span bound
2052 } 2056 }
2053 2057
2054 // Stretch the histogram to create the normalized image mapping. 2058 // Stretch the histogram to create the normalized image mapping.
2055 for(i=0; i <= MaxRGB; i++){ 2059 for(i=0; i <= MaxRGB; i++){
2056 if (i < (int) low) 2060 if (i < (int) low)
2057 normalize_map[i]=0; 2061 normalize_map[i]=0;
2058 else{ 2062 else{
2059 if(i > (int) high) 2063 if(i > (int) high)
2060 normalize_map[i]=MaxRGB; 2064 normalize_map[i]=MaxRGB;
2061 else 2065 else
2062 normalize_map[i]=(MaxRGB-1)*(i-low)/(high-low); 2066 normalize_map[i]=(MaxRGB-1)*(i-low)/(high-low);
2063 } 2067 }
2064 } 2068 }
2065 // Normalize 2069 // Normalize
2066 if(img.depth() > 8){ // DirectClass 2070 if(img.depth() > 8){ // DirectClass
2067 unsigned int *data; 2071 unsigned int *data;
2068 for(y=0; y < img.height(); ++y){ 2072 for(y=0; y < img.height(); ++y){
2069 data = (unsigned int *)img.scanLine(y); 2073 data = (unsigned int *)img.scanLine(y);
2070 for(x=0; x < img.width(); ++x){ 2074 for(x=0; x < img.width(); ++x){
2071 data[x] = qRgba(normalize_map[qRed(data[x])], 2075 data[x] = qRgba(normalize_map[qRed(data[x])],
2072 normalize_map[qGreen(data[x])], 2076 normalize_map[qGreen(data[x])],
2073 normalize_map[qBlue(data[x])], 2077 normalize_map[qBlue(data[x])],
2074 qAlpha(data[x])); 2078 qAlpha(data[x]));
2075 } 2079 }
2076 } 2080 }
2077 } 2081 }
2078 else{ // PsudeoClass 2082 else{ // PsudeoClass
2079 int colors = img.numColors(); 2083 int colors = img.numColors();
2080 unsigned int *cTable = img.colorTable(); 2084 unsigned int *cTable = img.colorTable();
2081 for(i=0; i < colors; ++i){ 2085 for(i=0; i < colors; ++i){
2082 cTable[i] = qRgba(normalize_map[qRed(cTable[i])], 2086 cTable[i] = qRgba(normalize_map[qRed(cTable[i])],
2083 normalize_map[qGreen(cTable[i])], 2087 normalize_map[qGreen(cTable[i])],
2084 normalize_map[qBlue(cTable[i])], 2088 normalize_map[qBlue(cTable[i])],
2085 qAlpha(cTable[i])); 2089 qAlpha(cTable[i]));
2086 } 2090 }
2087 } 2091 }
2088 free(histogram); 2092 free(histogram);
2089 free(normalize_map); 2093 free(normalize_map);
2090} 2094}
2091 2095
2092 2096
2093void OImageEffect::equalize(QImage &img) 2097void OImageEffect::equalize(QImage &img)
2094{ 2098{
2095 int *histogram, *map, *equalize_map; 2099 int *histogram, *map, *equalize_map;
2096 int x, y, i, j; 2100 int x, y, i, j;
2097 2101
2098 unsigned int high, low; 2102 unsigned int high, low;
2099 2103
2100 // allocate histogram and maps 2104 // allocate histogram and maps
2101 histogram = (int *)calloc(MaxRGB+1, sizeof(int)); 2105 histogram = (int *)calloc(MaxRGB+1, sizeof(int));
2102 map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int)); 2106 map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int));
2103 equalize_map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int)); 2107 equalize_map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int));
2104 2108
2105 if(!histogram || !map || !equalize_map){ 2109 if(!histogram || !map || !equalize_map){
2106 owarn << "Unable to allocate equalize histogram and maps" << oendl; 2110 owarn << "Unable to allocate equalize histogram and maps" << oendl;
2107 free(histogram); 2111 free(histogram);
2108 free(map); 2112 free(map);
2109 free(equalize_map); 2113 free(equalize_map);
2110 return; 2114 return;
2111 } 2115 }
2112 // form histogram 2116 // form histogram
2113 if(img.depth() > 8){ // DirectClass 2117 if(img.depth() > 8){ // DirectClass
2114 unsigned int *data; 2118 unsigned int *data;
2115 for(y=0; y < img.height(); ++y){ 2119 for(y=0; y < img.height(); ++y){
2116 data = (unsigned int *)img.scanLine(y); 2120 data = (unsigned int *)img.scanLine(y);
2117 for(x=0; x < img.width(); ++x){ 2121 for(x=0; x < img.width(); ++x){
2118 histogram[intensityValue(data[x])]++; 2122 histogram[intensityValue(data[x])]++;
2119 } 2123 }
2120 } 2124 }
2121 } 2125 }
2122 else{ // PsudeoClass 2126 else{ // PsudeoClass
2123 unsigned char *data; 2127 unsigned char *data;
2124 unsigned int *cTable = img.colorTable(); 2128 unsigned int *cTable = img.colorTable();
2125 for(y=0; y < img.height(); ++y){ 2129 for(y=0; y < img.height(); ++y){
2126 data = (unsigned char *)img.scanLine(y); 2130 data = (unsigned char *)img.scanLine(y);
2127 for(x=0; x < img.width(); ++x){ 2131 for(x=0; x < img.width(); ++x){
2128 histogram[intensityValue(*(cTable+data[x]))]++; 2132 histogram[intensityValue(*(cTable+data[x]))]++;
2129 } 2133 }
2130 } 2134 }
2131 } 2135 }
2132 2136
2133 // integrate the histogram to get the equalization map. 2137 // integrate the histogram to get the equalization map.
2134 j=0; 2138 j=0;
2135 for(i=0; i <= MaxRGB; i++){ 2139 for(i=0; i <= MaxRGB; i++){
2136 j+=histogram[i]; 2140 j+=histogram[i];
2137 map[i]=j; 2141 map[i]=j;
2138 } 2142 }
2139 free(histogram); 2143 free(histogram);
2140 if(map[MaxRGB] == 0){ 2144 if(map[MaxRGB] == 0){
2141 free(equalize_map); 2145 free(equalize_map);
2142 free(map); 2146 free(map);
2143 return; 2147 return;
2144 } 2148 }
2145 // equalize 2149 // equalize
2146 low=map[0]; 2150 low=map[0];
2147 high=map[MaxRGB]; 2151 high=map[MaxRGB];
2148 for(i=0; i <= MaxRGB; i++) 2152 for(i=0; i <= MaxRGB; i++)
2149 equalize_map[i]=(unsigned int) 2153 equalize_map[i]=(unsigned int)
2150 ((((double) (map[i]-low))*MaxRGB)/QMAX(high-low,1)); 2154 ((((double) (map[i]-low))*MaxRGB)/QMAX(high-low,1));
2151 free(map); 2155 free(map);
2152 // stretch the histogram 2156 // stretch the histogram
2153 if(img.depth() > 8){ // DirectClass 2157 if(img.depth() > 8){ // DirectClass
2154 unsigned int *data; 2158 unsigned int *data;
2155 for(y=0; y < img.height(); ++y){ 2159 for(y=0; y < img.height(); ++y){
2156 data = (unsigned int *)img.scanLine(y); 2160 data = (unsigned int *)img.scanLine(y);
2157 for(x=0; x < img.width(); ++x){ 2161 for(x=0; x < img.width(); ++x){
2158 data[x] = qRgba(equalize_map[qRed(data[x])], 2162 data[x] = qRgba(equalize_map[qRed(data[x])],
2159 equalize_map[qGreen(data[x])], 2163 equalize_map[qGreen(data[x])],
2160 equalize_map[qBlue(data[x])], 2164 equalize_map[qBlue(data[x])],
2161 qAlpha(data[x])); 2165 qAlpha(data[x]));
2162 } 2166 }
2163 } 2167 }
2164 } 2168 }
2165 else{ // PsudeoClass 2169 else{ // PsudeoClass
2166 int colors = img.numColors(); 2170 int colors = img.numColors();
2167 unsigned int *cTable = img.colorTable(); 2171 unsigned int *cTable = img.colorTable();
2168 for(i=0; i < colors; ++i){ 2172 for(i=0; i < colors; ++i){
2169 cTable[i] = qRgba(equalize_map[qRed(cTable[i])], 2173 cTable[i] = qRgba(equalize_map[qRed(cTable[i])],
2170 equalize_map[qGreen(cTable[i])], 2174 equalize_map[qGreen(cTable[i])],
2171 equalize_map[qBlue(cTable[i])], 2175 equalize_map[qBlue(cTable[i])],
2172 qAlpha(cTable[i])); 2176 qAlpha(cTable[i]));
2173 } 2177 }
2174 } 2178 }
2175 free(equalize_map); 2179 free(equalize_map);
2176} 2180}
2177 2181
2178QImage OImageEffect::sample(QImage &src, int w, int h) 2182QImage OImageEffect::sample(QImage &src, int w, int h)
2179{ 2183{
2180 if(w == src.width() && h == src.height()) 2184 if(w == src.width() && h == src.height())
2181 return(src); 2185 return(src);
2182 2186
2183 double *x_offset, *y_offset; 2187 double *x_offset, *y_offset;
2184 int j, k, y; 2188 int j, k, y;
2185 register int x; 2189 register int x;
2186 QImage dest(w, h, src.depth()); 2190 QImage dest(w, h, src.depth());
2187 2191
2188 x_offset = (double *)malloc(w*sizeof(double)); 2192 x_offset = (double *)malloc(w*sizeof(double));
2189 y_offset = (double *)malloc(h*sizeof(double)); 2193 y_offset = (double *)malloc(h*sizeof(double));
2190 if(!x_offset || !y_offset){ 2194 if(!x_offset || !y_offset){
2191 owarn << "Unable to allocate pixels buffer" << oendl; 2195 owarn << "Unable to allocate pixels buffer" << oendl;
2192 free(x_offset); 2196 free(x_offset);
2193 free(y_offset); 2197 free(y_offset);
2194 return(src); 2198 return(src);
2195 } 2199 }
2196 2200
2197 // init pixel offsets 2201 // init pixel offsets
2198 for(x=0; x < w; ++x) 2202 for(x=0; x < w; ++x)
2199 x_offset[x] = x*src.width()/((double)w); 2203 x_offset[x] = x*src.width()/((double)w);
2200 for(y=0; y < h; ++y) 2204 for(y=0; y < h; ++y)
2201 y_offset[y] = y*src.height()/((double)h); 2205 y_offset[y] = y*src.height()/((double)h);
2202 2206
2203 // sample each row 2207 // sample each row
2204 if(src.depth() > 8){ // DirectClass source image 2208 if(src.depth() > 8){ // DirectClass source image
2205 unsigned int *srcData, *destData; 2209 unsigned int *srcData, *destData;
2206 unsigned int *pixels; 2210 unsigned int *pixels;
2207 pixels = (unsigned int *)malloc(src.width()*sizeof(unsigned int)); 2211 pixels = (unsigned int *)malloc(src.width()*sizeof(unsigned int));
2208 if(!pixels){ 2212 if(!pixels){
2209 owarn << "Unable to allocate pixels buffer" << oendl; 2213 owarn << "Unable to allocate pixels buffer" << oendl;
2210 free(pixels); 2214 free(pixels);
2211 free(x_offset); 2215 free(x_offset);
2212 free(y_offset); 2216 free(y_offset);
2213 return(src); 2217 return(src);
2214 } 2218 }
2215 j = (-1); 2219 j = (-1);
2216 for(y=0; y < h; ++y){ 2220 for(y=0; y < h; ++y){
2217 destData = (unsigned int *)dest.scanLine(y); 2221 destData = (unsigned int *)dest.scanLine(y);
2218 if(j != y_offset[y]){ 2222 if(j != y_offset[y]){
2219 // read a scan line 2223 // read a scan line
2220 j = (int)(y_offset[y]); 2224 j = (int)(y_offset[y]);
2221 srcData = (unsigned int *)src.scanLine(j); 2225 srcData = (unsigned int *)src.scanLine(j);
2222 (void)memcpy(pixels, srcData, src.width()*sizeof(unsigned int)); 2226 (void)memcpy(pixels, srcData, src.width()*sizeof(unsigned int));
2223 } 2227 }
2224 // sample each column 2228 // sample each column
2225 for(x=0; x < w; ++x){ 2229 for(x=0; x < w; ++x){
2226 k = (int)(x_offset[x]); 2230 k = (int)(x_offset[x]);
2227 destData[x] = pixels[k]; 2231 destData[x] = pixels[k];
2228 } 2232 }
2229 } 2233 }
2230 free(pixels); 2234 free(pixels);
2231 } 2235 }
2232 else{ // PsudeoClass source image 2236 else{ // PsudeoClass source image
2233 unsigned char *srcData, *destData; 2237 unsigned char *srcData, *destData;
2234 unsigned char *pixels; 2238 unsigned char *pixels;
2235 pixels = (unsigned char *)malloc(src.width()*sizeof(unsigned char)); 2239 pixels = (unsigned char *)malloc(src.width()*sizeof(unsigned char));
2236 if(!pixels){ 2240 if(!pixels){
2237 owarn << "Unable to allocate pixels buffer" << oendl; 2241 owarn << "Unable to allocate pixels buffer" << oendl;
2238 free(pixels); 2242 free(pixels);
2239 free(x_offset); 2243 free(x_offset);
2240 free(y_offset); 2244 free(y_offset);
2241 return(src); 2245 return(src);
2242 } 2246 }
2243 // copy colortable 2247 // copy colortable
2244 dest.setNumColors(src.numColors()); 2248 dest.setNumColors(src.numColors());
2245 (void)memcpy(dest.colorTable(), src.colorTable(), 2249 (void)memcpy(dest.colorTable(), src.colorTable(),
2246 src.numColors()*sizeof(unsigned int)); 2250 src.numColors()*sizeof(unsigned int));
2247 2251
2248 // sample image 2252 // sample image
2249 j = (-1); 2253 j = (-1);
2250 for(y=0; y < h; ++y){ 2254 for(y=0; y < h; ++y){
2251 destData = (unsigned char *)dest.scanLine(y); 2255 destData = (unsigned char *)dest.scanLine(y);
2252 if(j != y_offset[y]){ 2256 if(j != y_offset[y]){
2253 // read a scan line 2257 // read a scan line
2254 j = (int)(y_offset[y]); 2258 j = (int)(y_offset[y]);
2255 srcData = (unsigned char *)src.scanLine(j); 2259 srcData = (unsigned char *)src.scanLine(j);
2256 (void)memcpy(pixels, srcData, src.width()*sizeof(unsigned char)); 2260 (void)memcpy(pixels, srcData, src.width()*sizeof(unsigned char));
2257 } 2261 }
2258 // sample each column 2262 // sample each column
2259 for(x=0; x < w; ++x){ 2263 for(x=0; x < w; ++x){
2260 k = (int)(x_offset[x]); 2264 k = (int)(x_offset[x]);
2261 destData[x] = pixels[k]; 2265 destData[x] = pixels[k];
2262 } 2266 }
2263 } 2267 }
2264 free(pixels); 2268 free(pixels);
2265 } 2269 }
2266 free(x_offset); 2270 free(x_offset);
2267 free(y_offset); 2271 free(y_offset);
2268 return(dest); 2272 return(dest);
2269} 2273}
2270 2274
2271void OImageEffect::threshold(QImage &img, unsigned int threshold) 2275void OImageEffect::threshold(QImage &img, unsigned int threshold)
2272{ 2276{
2273 int i, count; 2277 int i, count;
2274 unsigned int *data; 2278 unsigned int *data;
2275 if(img.depth() > 8){ // DirectClass 2279 if(img.depth() > 8){ // DirectClass
2276 count = img.width()*img.height(); 2280 count = img.width()*img.height();
2277 data = (unsigned int *)img.bits(); 2281 data = (unsigned int *)img.bits();
2278 } 2282 }
2279 else{ // PsudeoClass 2283 else{ // PsudeoClass
2280 count = img.numColors(); 2284 count = img.numColors();
2281 data = (unsigned int *)img.colorTable(); 2285 data = (unsigned int *)img.colorTable();
2282 } 2286 }
2283 for(i=0; i < count; ++i) 2287 for(i=0; i < count; ++i)
2284 data[i] = intensityValue(data[i]) < threshold ? Qt::black.rgb() : Qt::white.rgb(); 2288 data[i] = intensityValue(data[i]) < threshold ? Qt::black.rgb() : Qt::white.rgb();
2285} 2289}
2286 2290
2287QImage OImageEffect::charcoal(QImage &src, double factor) 2291QImage OImageEffect::charcoal(QImage &src, double factor)
2288{ 2292{
2289 QImage dest(src); 2293 QImage dest(src);
2290 dest.detach(); 2294 dest.detach();
2291 toGray(dest); 2295 toGray(dest);
2292 dest = edge(dest, factor); 2296 dest = edge(dest, factor);
2293 dest = blur(dest, factor); 2297 dest = blur(dest, factor);
2294 normalize(dest); 2298 normalize(dest);
2295 dest.invertPixels(false); 2299 dest.invertPixels(false);
2296 return(dest); 2300 return(dest);
2297} 2301}
2298 2302
2299void OImageEffect::hull(const int x_offset, const int y_offset, 2303void OImageEffect::hull(const int x_offset, const int y_offset,
2300 const int polarity, const int columns, 2304 const int polarity, const int columns,
2301 const int rows, 2305 const int rows,
2302 unsigned int *f, unsigned int *g) 2306 unsigned int *f, unsigned int *g)
2303{ 2307{
2304 int x, y; 2308 int x, y;
2305 2309
2306 unsigned int *p, *q, *r, *s; 2310 unsigned int *p, *q, *r, *s;
2307 unsigned int v; 2311 unsigned int v;
2308 if(f == NULL || g == NULL) 2312 if(f == NULL || g == NULL)
2309 return; 2313 return;
2310 p=f+(columns+2); 2314 p=f+(columns+2);
2311 q=g+(columns+2); 2315 q=g+(columns+2);
2312 r=p+(y_offset*(columns+2)+x_offset); 2316 r=p+(y_offset*(columns+2)+x_offset);
2313 for (y=0; y < rows; y++){ 2317 for (y=0; y < rows; y++){
2314 p++; 2318 p++;
2315 q++; 2319 q++;
2316 r++; 2320 r++;
2317 if(polarity > 0) 2321 if(polarity > 0)
2318 for (x=0; x < columns; x++){ 2322 for (x=0; x < columns; x++){
2319 v=(*p); 2323 v=(*p);
2320 if (*r > v) 2324 if (*r > v)
2321 v++; 2325 v++;
2322 *q=v; 2326 *q=v;
2323 p++; 2327 p++;
2324 q++; 2328 q++;
2325 r++; 2329 r++;
2326 } 2330 }
2327 else 2331 else
2328 for(x=0; x < columns; x++){ 2332 for(x=0; x < columns; x++){
2329 v=(*p); 2333 v=(*p);
2330 if (v > (unsigned int) (*r+1)) 2334 if (v > (unsigned int) (*r+1))
2331 v--; 2335 v--;
2332 *q=v; 2336 *q=v;
2333 p++; 2337 p++;
2334 q++; 2338 q++;
2335 r++; 2339 r++;
2336 } 2340 }
2337 p++; 2341 p++;
2338 q++; 2342 q++;
2339 r++; 2343 r++;
2340 } 2344 }
2341 p=f+(columns+2); 2345 p=f+(columns+2);
2342 q=g+(columns+2); 2346 q=g+(columns+2);
2343 r=q+(y_offset*(columns+2)+x_offset); 2347 r=q+(y_offset*(columns+2)+x_offset);
2344 s=q-(y_offset*(columns+2)+x_offset); 2348 s=q-(y_offset*(columns+2)+x_offset);
2345 for(y=0; y < rows; y++){ 2349 for(y=0; y < rows; y++){
2346 p++; 2350 p++;
2347 q++; 2351 q++;
2348 r++; 2352 r++;
2349 s++; 2353 s++;
2350 if(polarity > 0) 2354 if(polarity > 0)
2351 for(x=0; x < (int) columns; x++){ 2355 for(x=0; x < (int) columns; x++){
2352 v=(*q); 2356 v=(*q);
2353 if (((unsigned int) (*s+1) > v) && (*r > v)) 2357 if (((unsigned int) (*s+1) > v) && (*r > v))
2354 v++; 2358 v++;
2355 *p=v; 2359 *p=v;
2356 p++; 2360 p++;
2357 q++; 2361 q++;
2358 r++; 2362 r++;
2359 s++; 2363 s++;
2360 } 2364 }
2361 else 2365 else
2362 for (x=0; x < columns; x++){ 2366 for (x=0; x < columns; x++){
2363 v=(*q); 2367 v=(*q);
2364 if (((unsigned int) (*s+1) < v) && (*r < v)) 2368 if (((unsigned int) (*s+1) < v) && (*r < v))
2365 v--; 2369 v--;
2366 *p=v; 2370 *p=v;
2367 p++; 2371 p++;
2368 q++; 2372 q++;
2369 r++; 2373 r++;
2370 s++; 2374 s++;
2371 } 2375 }
2372 p++; 2376 p++;
2373 q++; 2377 q++;
2374 r++; 2378 r++;
2375 s++; 2379 s++;
2376 } 2380 }
2377} 2381}
2378 2382
2379QImage OImageEffect::despeckle(QImage &src) 2383QImage OImageEffect::despeckle(QImage &src)
2380{ 2384{
2381 int i, j, x, y; 2385 int i, j, x, y;
2382 unsigned int *blue_channel, *red_channel, *green_channel, *buffer, 2386 unsigned int *blue_channel, *red_channel, *green_channel, *buffer,
2383 *alpha_channel; 2387 *alpha_channel;
2384 int packets; 2388 int packets;
2385 static const int 2389 static const int
2386 X[4]= {0, 1, 1,-1}, 2390 X[4]= {0, 1, 1,-1},
2387 Y[4]= {1, 0, 1, 1}; 2391 Y[4]= {1, 0, 1, 1};
2388 2392
2389 unsigned int *destData; 2393 unsigned int *destData;
2390 QImage dest(src.width(), src.height(), 32); 2394 QImage dest(src.width(), src.height(), 32);
2391 2395
2392 packets = (src.width()+2)*(src.height()+2); 2396 packets = (src.width()+2)*(src.height()+2);
2393 red_channel = (unsigned int *)calloc(packets, sizeof(unsigned int)); 2397 red_channel = (unsigned int *)calloc(packets, sizeof(unsigned int));
2394 green_channel = (unsigned int *)calloc(packets, sizeof(unsigned int)); 2398 green_channel = (unsigned int *)calloc(packets, sizeof(unsigned int));
2395 blue_channel = (unsigned int *)calloc(packets, sizeof(unsigned int)); 2399 blue_channel = (unsigned int *)calloc(packets, sizeof(unsigned int));
2396 alpha_channel = (unsigned int *)calloc(packets, sizeof(unsigned int)); 2400 alpha_channel = (unsigned int *)calloc(packets, sizeof(unsigned int));
2397 buffer = (unsigned int *)calloc(packets, sizeof(unsigned int)); 2401 buffer = (unsigned int *)calloc(packets, sizeof(unsigned int));
2398 if(!red_channel || ! green_channel || ! blue_channel || ! alpha_channel || 2402 if(!red_channel || ! green_channel || ! blue_channel || ! alpha_channel ||
2399 !buffer){ 2403 !buffer){
2400 free(red_channel); 2404 free(red_channel);
2401 free(green_channel); 2405 free(green_channel);
2402 free(blue_channel); 2406 free(blue_channel);
2403 free(alpha_channel); 2407 free(alpha_channel);
2404 free(buffer); 2408 free(buffer);
2405 return(src); 2409 return(src);
2406 } 2410 }
2407 2411
2408 // copy image pixels to color component buffers 2412 // copy image pixels to color component buffers
2409 j = src.width()+2; 2413 j = src.width()+2;
2410 if(src.depth() > 8){ // DirectClass source image 2414 if(src.depth() > 8){ // DirectClass source image
2411 unsigned int *srcData; 2415 unsigned int *srcData;
2412 for(y=0; y < src.height(); ++y){ 2416 for(y=0; y < src.height(); ++y){
2413 srcData = (unsigned int *)src.scanLine(y); 2417 srcData = (unsigned int *)src.scanLine(y);
2414 ++j; 2418 ++j;
2415 for(x=0; x < src.width(); ++x){ 2419 for(x=0; x < src.width(); ++x){
2416 red_channel[j] = qRed(srcData[x]); 2420 red_channel[j] = qRed(srcData[x]);
2417 green_channel[j] = qGreen(srcData[x]); 2421 green_channel[j] = qGreen(srcData[x]);
2418 blue_channel[j] = qBlue(srcData[x]); 2422 blue_channel[j] = qBlue(srcData[x]);
2419 alpha_channel[j] = qAlpha(srcData[x]); 2423 alpha_channel[j] = qAlpha(srcData[x]);
2420 ++j; 2424 ++j;
2421 } 2425 }
2422 ++j; 2426 ++j;
2423 } 2427 }
2424 } 2428 }
2425 else{ // PsudeoClass source image 2429 else{ // PsudeoClass source image
2426 unsigned char *srcData; 2430 unsigned char *srcData;
2427 unsigned int *cTable = src.colorTable(); 2431 unsigned int *cTable = src.colorTable();
2428 unsigned int pixel; 2432 unsigned int pixel;
2429 for(y=0; y < src.height(); ++y){ 2433 for(y=0; y < src.height(); ++y){
2430 srcData = (unsigned char *)src.scanLine(y); 2434 srcData = (unsigned char *)src.scanLine(y);
2431 ++j; 2435 ++j;
2432 for(x=0; x < src.width(); ++x){ 2436 for(x=0; x < src.width(); ++x){
2433 pixel = *(cTable+srcData[x]); 2437 pixel = *(cTable+srcData[x]);
2434 red_channel[j] = qRed(pixel); 2438 red_channel[j] = qRed(pixel);
2435 green_channel[j] = qGreen(pixel); 2439 green_channel[j] = qGreen(pixel);
2436 blue_channel[j] = qBlue(pixel); 2440 blue_channel[j] = qBlue(pixel);
2437 alpha_channel[j] = qAlpha(pixel); 2441 alpha_channel[j] = qAlpha(pixel);
2438 ++j; 2442 ++j;
2439 } 2443 }
2440 ++j; 2444 ++j;
2441 } 2445 }
2442 } 2446 }
2443 // reduce speckle in red channel 2447 // reduce speckle in red channel
2444 for(i=0; i < 4; i++){ 2448 for(i=0; i < 4; i++){
2445 hull(X[i],Y[i],1,src.width(),src.height(),red_channel,buffer); 2449 hull(X[i],Y[i],1,src.width(),src.height(),red_channel,buffer);
2446 hull(-X[i],-Y[i],1,src.width(),src.height(),red_channel,buffer); 2450 hull(-X[i],-Y[i],1,src.width(),src.height(),red_channel,buffer);
2447 hull(-X[i],-Y[i],-1,src.width(),src.height(),red_channel,buffer); 2451 hull(-X[i],-Y[i],-1,src.width(),src.height(),red_channel,buffer);
2448 hull(X[i],Y[i],-1,src.width(),src.height(),red_channel,buffer); 2452 hull(X[i],Y[i],-1,src.width(),src.height(),red_channel,buffer);
2449 } 2453 }
2450 // reduce speckle in green channel 2454 // reduce speckle in green channel
2451 for (i=0; i < packets; i++) 2455 for (i=0; i < packets; i++)
2452 buffer[i]=0; 2456 buffer[i]=0;
2453 for (i=0; i < 4; i++){ 2457 for (i=0; i < 4; i++){
2454 hull(X[i],Y[i],1,src.width(),src.height(),green_channel,buffer); 2458 hull(X[i],Y[i],1,src.width(),src.height(),green_channel,buffer);
2455 hull(-X[i],-Y[i],1,src.width(),src.height(),green_channel,buffer); 2459 hull(-X[i],-Y[i],1,src.width(),src.height(),green_channel,buffer);
2456 hull(-X[i],-Y[i],-1,src.width(),src.height(),green_channel,buffer); 2460 hull(-X[i],-Y[i],-1,src.width(),src.height(),green_channel,buffer);
2457 hull(X[i],Y[i],-1,src.width(),src.height(),green_channel,buffer); 2461 hull(X[i],Y[i],-1,src.width(),src.height(),green_channel,buffer);
2458 } 2462 }
2459 // reduce speckle in blue channel 2463 // reduce speckle in blue channel
2460 for (i=0; i < packets; i++) 2464 for (i=0; i < packets; i++)
2461 buffer[i]=0; 2465 buffer[i]=0;
2462 for (i=0; i < 4; i++){ 2466 for (i=0; i < 4; i++){
2463 hull(X[i],Y[i],1,src.width(),src.height(),blue_channel,buffer); 2467 hull(X[i],Y[i],1,src.width(),src.height(),blue_channel,buffer);
2464 hull(-X[i],-Y[i],1,src.width(),src.height(),blue_channel,buffer); 2468 hull(-X[i],-Y[i],1,src.width(),src.height(),blue_channel,buffer);
2465 hull(-X[i],-Y[i],-1,src.width(),src.height(),blue_channel,buffer); 2469 hull(-X[i],-Y[i],-1,src.width(),src.height(),blue_channel,buffer);
2466 hull(X[i],Y[i],-1,src.width(),src.height(),blue_channel,buffer); 2470 hull(X[i],Y[i],-1,src.width(),src.height(),blue_channel,buffer);
2467 } 2471 }
2468 // copy color component buffers to despeckled image 2472 // copy color component buffers to despeckled image
2469 j = dest.width()+2; 2473 j = dest.width()+2;
2470 for(y=0; y < dest.height(); ++y) 2474 for(y=0; y < dest.height(); ++y)
2471 { 2475 {
2472 destData = (unsigned int *)dest.scanLine(y); 2476 destData = (unsigned int *)dest.scanLine(y);
2473 ++j; 2477 ++j;
2474 for (x=0; x < dest.width(); ++x) 2478 for (x=0; x < dest.width(); ++x)
2475 { 2479 {
2476 destData[x] = qRgba(red_channel[j], green_channel[j], 2480 destData[x] = qRgba(red_channel[j], green_channel[j],
2477 blue_channel[j], alpha_channel[j]); 2481 blue_channel[j], alpha_channel[j]);
2478 ++j; 2482 ++j;
2479 } 2483 }
2480 ++j; 2484 ++j;
2481 } 2485 }
2482 free(buffer); 2486 free(buffer);
2483 free(red_channel); 2487 free(red_channel);
2484 free(green_channel); 2488 free(green_channel);
2485 free(blue_channel); 2489 free(blue_channel);
2486 free(alpha_channel); 2490 free(alpha_channel);
2487 return(dest); 2491 return(dest);
2488} 2492}
2489 2493
2490unsigned int OImageEffect::generateNoise(unsigned int pixel, 2494unsigned int OImageEffect::generateNoise(unsigned int pixel,
2491 NoiseType noise_type) 2495 NoiseType noise_type)
2492{ 2496{
2493#define NoiseEpsilon 1.0e-5 2497#define NoiseEpsilon 1.0e-5
2494#define NoiseMask 0x7fff 2498#define NoiseMask 0x7fff
2495#define SigmaUniform 4.0 2499#define SigmaUniform 4.0
2496#define SigmaGaussian 4.0 2500#define SigmaGaussian 4.0
2497#define SigmaImpulse 0.10 2501#define SigmaImpulse 0.10
2498#define SigmaLaplacian 10.0 2502#define SigmaLaplacian 10.0
2499#define SigmaMultiplicativeGaussian 0.5 2503#define SigmaMultiplicativeGaussian 0.5
2500#define SigmaPoisson 0.05 2504#define SigmaPoisson 0.05
2501#define TauGaussian 20.0 2505#define TauGaussian 20.0
2502 2506
2503 double alpha, beta, sigma, value; 2507 double alpha, beta, sigma, value;
2504 alpha=(double) (rand() & NoiseMask)/NoiseMask; 2508 alpha=(double) (rand() & NoiseMask)/NoiseMask;
2505 if (alpha == 0.0) 2509 if (alpha == 0.0)
2506 alpha=1.0; 2510 alpha=1.0;
2507 switch(noise_type){ 2511 switch(noise_type){
2508 case UniformNoise: 2512 case UniformNoise:
2509 default: 2513 default:
2510 { 2514 {
2511 value=(double) pixel+SigmaUniform*(alpha-0.5); 2515 value=(double) pixel+SigmaUniform*(alpha-0.5);
2512 break; 2516 break;
2513 } 2517 }
2514 case GaussianNoise: 2518 case GaussianNoise:
2515 { 2519 {
2516 double tau; 2520 double tau;
2517 2521
2518 beta=(double) (rand() & NoiseMask)/NoiseMask; 2522 beta=(double) (rand() & NoiseMask)/NoiseMask;
2519 sigma=sqrt(-2.0*log(alpha))*cos(2.0*M_PI*beta); 2523 sigma=sqrt(-2.0*log(alpha))*cos(2.0*M_PI*beta);
2520 tau=sqrt(-2.0*log(alpha))*sin(2.0*M_PI*beta); 2524 tau=sqrt(-2.0*log(alpha))*sin(2.0*M_PI*beta);
2521 value=(double) pixel+ 2525 value=(double) pixel+
2522 (sqrt((double) pixel)*SigmaGaussian*sigma)+(TauGaussian*tau); 2526 (sqrt((double) pixel)*SigmaGaussian*sigma)+(TauGaussian*tau);
2523 break; 2527 break;
2524 } 2528 }
2525 case MultiplicativeGaussianNoise: 2529 case MultiplicativeGaussianNoise:
2526 { 2530 {
2527 if (alpha <= NoiseEpsilon) 2531 if (alpha <= NoiseEpsilon)
2528 sigma=MaxRGB; 2532 sigma=MaxRGB;
2529 else 2533 else
2530 sigma=sqrt(-2.0*log(alpha)); 2534 sigma=sqrt(-2.0*log(alpha));
2531 beta=(rand() & NoiseMask)/NoiseMask; 2535 beta=(rand() & NoiseMask)/NoiseMask;
2532 value=(double) pixel+ 2536 value=(double) pixel+
2533 pixel*SigmaMultiplicativeGaussian*sigma*cos(2.0*M_PI*beta); 2537 pixel*SigmaMultiplicativeGaussian*sigma*cos(2.0*M_PI*beta);
2534 break; 2538 break;
2535 } 2539 }
2536 case ImpulseNoise: 2540 case ImpulseNoise:
2537 { 2541 {
2538 if (alpha < (SigmaImpulse/2.0)) 2542 if (alpha < (SigmaImpulse/2.0))
2539 value=0; 2543 value=0;
2540 else 2544 else
2541 if (alpha >= (1.0-(SigmaImpulse/2.0))) 2545 if (alpha >= (1.0-(SigmaImpulse/2.0)))
2542 value=MaxRGB; 2546 value=MaxRGB;
2543 else 2547 else
2544 value=pixel; 2548 value=pixel;
2545 break; 2549 break;
2546 } 2550 }
2547 case LaplacianNoise: 2551 case LaplacianNoise:
2548 { 2552 {
2549 if (alpha <= 0.5) 2553 if (alpha <= 0.5)
2550 { 2554 {
2551 if (alpha <= NoiseEpsilon) 2555 if (alpha <= NoiseEpsilon)
2552 value=(double) pixel-MaxRGB; 2556 value=(double) pixel-MaxRGB;
2553 else 2557 else
2554 value=(double) pixel+SigmaLaplacian*log(2.0*alpha); 2558 value=(double) pixel+SigmaLaplacian*log(2.0*alpha);
2555 break; 2559 break;
2556 } 2560 }
2557 beta=1.0-alpha; 2561 beta=1.0-alpha;
2558 if (beta <= (0.5*NoiseEpsilon)) 2562 if (beta <= (0.5*NoiseEpsilon))
2559 value=(double) pixel+MaxRGB; 2563 value=(double) pixel+MaxRGB;
2560 else 2564 else
2561 value=(double) pixel-SigmaLaplacian*log(2.0*beta); 2565 value=(double) pixel-SigmaLaplacian*log(2.0*beta);
2562 break; 2566 break;
2563 } 2567 }
2564 case PoissonNoise: 2568 case PoissonNoise:
2565 { 2569 {
2566 register int 2570 register int
2567 i; 2571 i;
2568 2572
2569 for (i=0; alpha > exp(-SigmaPoisson*pixel); i++) 2573 for (i=0; alpha > exp(-SigmaPoisson*pixel); i++)
2570 { 2574 {
2571 beta=(double) (rand() & NoiseMask)/NoiseMask; 2575 beta=(double) (rand() & NoiseMask)/NoiseMask;
2572 alpha=alpha*beta; 2576 alpha=alpha*beta;
2573 } 2577 }
2574 value=i/SigmaPoisson; 2578 value=i/SigmaPoisson;
2575 break; 2579 break;
2576 } 2580 }
2577 } 2581 }
2578 if(value < 0.0) 2582 if(value < 0.0)
2579 return(0); 2583 return(0);
2580 if(value > MaxRGB) 2584 if(value > MaxRGB)
2581 return(MaxRGB); 2585 return(MaxRGB);
2582 return((unsigned int) (value+0.5)); 2586 return((unsigned int) (value+0.5));
2583} 2587}
2584 2588
2585QImage OImageEffect::addNoise(QImage &src, NoiseType noise_type) 2589QImage OImageEffect::addNoise(QImage &src, NoiseType noise_type)
2586{ 2590{
2587 int x, y; 2591 int x, y;
2588 QImage dest(src.width(), src.height(), 32); 2592 QImage dest(src.width(), src.height(), 32);
2589 unsigned int *destData; 2593 unsigned int *destData;
2590 2594
2591 if(src.depth() > 8){ // DirectClass source image 2595 if(src.depth() > 8){ // DirectClass source image
2592 unsigned int *srcData; 2596 unsigned int *srcData;
2593 for(y=0; y < src.height(); ++y){ 2597 for(y=0; y < src.height(); ++y){
2594 srcData = (unsigned int *)src.scanLine(y); 2598 srcData = (unsigned int *)src.scanLine(y);
2595 destData = (unsigned int *)dest.scanLine(y); 2599 destData = (unsigned int *)dest.scanLine(y);
2596 for(x=0; x < src.width(); ++x){ 2600 for(x=0; x < src.width(); ++x){
2597 destData[x] = qRgba(generateNoise(qRed(srcData[x]), noise_type), 2601 destData[x] = qRgba(generateNoise(qRed(srcData[x]), noise_type),
2598 generateNoise(qGreen(srcData[x]), noise_type), 2602 generateNoise(qGreen(srcData[x]), noise_type),
2599 generateNoise(qBlue(srcData[x]), noise_type), 2603 generateNoise(qBlue(srcData[x]), noise_type),
2600 qAlpha(srcData[x])); 2604 qAlpha(srcData[x]));
2601 } 2605 }
2602 } 2606 }
2603 } 2607 }
2604 else{ // PsudeoClass source image 2608 else{ // PsudeoClass source image
2605 unsigned char *srcData; 2609 unsigned char *srcData;
2606 unsigned int *cTable = src.colorTable(); 2610 unsigned int *cTable = src.colorTable();
2607 unsigned int pixel; 2611 unsigned int pixel;
2608 for(y=0; y < src.height(); ++y){ 2612 for(y=0; y < src.height(); ++y){
2609 srcData = (unsigned char *)src.scanLine(y); 2613 srcData = (unsigned char *)src.scanLine(y);
2610 destData = (unsigned int *)dest.scanLine(y); 2614 destData = (unsigned int *)dest.scanLine(y);
2611 for(x=0; x < src.width(); ++x){ 2615 for(x=0; x < src.width(); ++x){
2612 pixel = *(cTable+srcData[x]); 2616 pixel = *(cTable+srcData[x]);
2613 destData[x] = qRgba(generateNoise(qRed(pixel), noise_type), 2617 destData[x] = qRgba(generateNoise(qRed(pixel), noise_type),
2614 generateNoise(qGreen(pixel), noise_type), 2618 generateNoise(qGreen(pixel), noise_type),
2615 generateNoise(qBlue(pixel), noise_type), 2619 generateNoise(qBlue(pixel), noise_type),
2616 qAlpha(pixel)); 2620 qAlpha(pixel));
2617 } 2621 }
2618 } 2622 }
2619 2623
2620 } 2624 }
2621 return(dest); 2625 return(dest);
2622} 2626}
2623 2627
2624unsigned int OImageEffect::interpolateColor(QImage *image, double x_offset, 2628unsigned int OImageEffect::interpolateColor(QImage *image, double x_offset,
2625 double y_offset, 2629 double y_offset,
2626 unsigned int background) 2630 unsigned int background)
2627{ 2631{
2628 double alpha, beta; 2632 double alpha, beta;
2629 unsigned int p, q, r, s; 2633 unsigned int p, q, r, s;
2630 int x, y; 2634 int x, y;
2631 2635
2632 x = (int)x_offset; 2636 x = (int)x_offset;
2633 y = (int)y_offset; 2637 y = (int)y_offset;
2634 if((x < -1) || (x >= image->width()) || (y < -1) || (y >= image->height())) 2638 if((x < -1) || (x >= image->width()) || (y < -1) || (y >= image->height()))
2635 return(background); 2639 return(background);
2636 if(image->depth() > 8){ 2640 if(image->depth() > 8){
2637 if((x >= 0) && (y >= 0) && (x < (image->width()-1)) && (y < (image->height()-1))) { 2641 if((x >= 0) && (y >= 0) && (x < (image->width()-1)) && (y < (image->height()-1))) {
2638 unsigned int *t = (unsigned int *)image->scanLine(y); 2642 unsigned int *t = (unsigned int *)image->scanLine(y);
2639 p = t[x]; 2643 p = t[x];
2640 q = t[x+1]; 2644 q = t[x+1];
2641 r = t[x+image->width()]; 2645 r = t[x+image->width()];
2642 s = t[x+image->width()+1]; 2646 s = t[x+image->width()+1];
2643 } 2647 }
2644 else{ 2648 else{
2645 unsigned int *t = (unsigned int *)image->scanLine(y); 2649 unsigned int *t = (unsigned int *)image->scanLine(y);
2646 p = background; 2650 p = background;
2647 if((x >= 0) && (y >= 0)){ 2651 if((x >= 0) && (y >= 0)){
2648 p = t[x]; 2652 p = t[x];
2649 } 2653 }
2650 q = background; 2654 q = background;
2651 if(((x+1) < image->width()) && (y >= 0)){ 2655 if(((x+1) < image->width()) && (y >= 0)){
2652 q = t[x+1]; 2656 q = t[x+1];
2653 } 2657 }
2654 r = background; 2658 r = background;
2655 if((x >= 0) && ((y+1) < image->height())){ 2659 if((x >= 0) && ((y+1) < image->height())){
2656 t = (unsigned int *)image->scanLine(y+1); 2660 t = (unsigned int *)image->scanLine(y+1);
2657 r = t[x+image->width()]; 2661 r = t[x+image->width()];
2658 } 2662 }
2659 s = background; 2663 s = background;
2660 if(((x+1) < image->width()) && ((y+1) < image->height())){ 2664 if(((x+1) < image->width()) && ((y+1) < image->height())){
2661 t = (unsigned int *)image->scanLine(y+1); 2665 t = (unsigned int *)image->scanLine(y+1);
2662 s = t[x+image->width()+1]; 2666 s = t[x+image->width()+1];
2663 } 2667 }
2664 2668
2665 } 2669 }
2666 } 2670 }
2667 else{ 2671 else{
2668 unsigned int *colorTable = (unsigned int *)image->colorTable(); 2672 unsigned int *colorTable = (unsigned int *)image->colorTable();
2669 if((x >= 0) && (y >= 0) && (x < (image->width()-1)) && (y < (image->height()-1))) { 2673 if((x >= 0) && (y >= 0) && (x < (image->width()-1)) && (y < (image->height()-1))) {
2670 unsigned char *t; 2674 unsigned char *t;
2671 t = (unsigned char *)image->scanLine(y); 2675 t = (unsigned char *)image->scanLine(y);
2672 p = *(colorTable+t[x]); 2676 p = *(colorTable+t[x]);
2673 q = *(colorTable+t[x+1]); 2677 q = *(colorTable+t[x+1]);
2674 t = (unsigned char *)image->scanLine(y+1); 2678 t = (unsigned char *)image->scanLine(y+1);
2675 r = *(colorTable+t[x]); 2679 r = *(colorTable+t[x]);
2676 s = *(colorTable+t[x+1]); 2680 s = *(colorTable+t[x+1]);
2677 } 2681 }
2678 else{ 2682 else{
2679 unsigned char *t; 2683 unsigned char *t;
2680 p = background; 2684 p = background;
2681 if((x >= 0) && (y >= 0)){ 2685 if((x >= 0) && (y >= 0)){
2682 t = (unsigned char *)image->scanLine(y); 2686 t = (unsigned char *)image->scanLine(y);
2683 p = *(colorTable+t[x]); 2687 p = *(colorTable+t[x]);
2684 } 2688 }
2685 q = background; 2689 q = background;
2686 if(((x+1) < image->width()) && (y >= 0)){ 2690 if(((x+1) < image->width()) && (y >= 0)){
2687 t = (unsigned char *)image->scanLine(y); 2691 t = (unsigned char *)image->scanLine(y);
2688 q = *(colorTable+t[x+1]); 2692 q = *(colorTable+t[x+1]);
2689 } 2693 }
2690 r = background; 2694 r = background;
2691 if((x >= 0) && ((y+1) < image->height())){ 2695 if((x >= 0) && ((y+1) < image->height())){
2692 t = (unsigned char *)image->scanLine(y+1); 2696 t = (unsigned char *)image->scanLine(y+1);
2693 r = *(colorTable+t[x]); 2697 r = *(colorTable+t[x]);
2694 } 2698 }
2695 s = background; 2699 s = background;
2696 if(((x+1) < image->width()) && ((y+1) < image->height())){ 2700 if(((x+1) < image->width()) && ((y+1) < image->height())){
2697 t = (unsigned char *)image->scanLine(y+1); 2701 t = (unsigned char *)image->scanLine(y+1);
2698 s = *(colorTable+t[x+1]); 2702 s = *(colorTable+t[x+1]);
2699 } 2703 }
2700 2704
2701 } 2705 }
2702 2706
2703 } 2707 }
2704 x_offset -= floor(x_offset); 2708 x_offset -= floor(x_offset);
2705 y_offset -= floor(y_offset); 2709 y_offset -= floor(y_offset);
2706 alpha = 1.0-x_offset; 2710 alpha = 1.0-x_offset;
2707 beta = 1.0-y_offset; 2711 beta = 1.0-y_offset;
2708 2712
2709 return(qRgba((unsigned char)(beta*(alpha*qRed(p)+x_offset*qRed(q))+y_offset*(alpha*qRed(r)+x_offset*qRed(s))), 2713 return(qRgba((unsigned char)(beta*(alpha*qRed(p)+x_offset*qRed(q))+y_offset*(alpha*qRed(r)+x_offset*qRed(s))),
2710 (unsigned char)(beta*(alpha*qGreen(p)+x_offset*qGreen(q))+y_offset*(alpha*qGreen(r)+x_offset*qGreen(s))), 2714 (unsigned char)(beta*(alpha*qGreen(p)+x_offset*qGreen(q))+y_offset*(alpha*qGreen(r)+x_offset*qGreen(s))),
2711 (unsigned char)(beta*(alpha*qBlue(p)+x_offset*qBlue(q))+y_offset*(alpha*qBlue(r)+x_offset*qBlue(s))), 2715 (unsigned char)(beta*(alpha*qBlue(p)+x_offset*qBlue(q))+y_offset*(alpha*qBlue(r)+x_offset*qBlue(s))),
2712 (unsigned char)(beta*(alpha*qAlpha(p)+x_offset*qAlpha(q))+y_offset*(alpha*qAlpha(r)+x_offset*qAlpha(s))))); 2716 (unsigned char)(beta*(alpha*qAlpha(p)+x_offset*qAlpha(q))+y_offset*(alpha*qAlpha(r)+x_offset*qAlpha(s)))));
2713} 2717}
2714 2718
2715QImage OImageEffect::implode(QImage &src, double factor, 2719QImage OImageEffect::implode(QImage &src, double factor,
2716 unsigned int background) 2720 unsigned int background)
2717{ 2721{
2718 double amount, distance, radius; 2722 double amount, distance, radius;
2719 double x_center, x_distance, x_scale; 2723 double x_center, x_distance, x_scale;
2720 double y_center, y_distance, y_scale; 2724 double y_center, y_distance, y_scale;
2721 unsigned int *destData; 2725 unsigned int *destData;
2722 int x, y; 2726 int x, y;
2723 2727
2724 QImage dest(src.width(), src.height(), 32); 2728 QImage dest(src.width(), src.height(), 32);
2725 2729
2726 // compute scaling factor 2730 // compute scaling factor
2727 x_scale = 1.0; 2731 x_scale = 1.0;
2728 y_scale = 1.0; 2732 y_scale = 1.0;
2729 x_center = (double)0.5*src.width(); 2733 x_center = (double)0.5*src.width();
2730 y_center = (double)0.5*src.height(); 2734 y_center = (double)0.5*src.height();
2731 radius=x_center; 2735 radius=x_center;
2732 if(src.width() > src.height()) 2736 if(src.width() > src.height())
2733 y_scale = (double)src.width()/src.height(); 2737 y_scale = (double)src.width()/src.height();
2734 else if(src.width() < src.height()){ 2738 else if(src.width() < src.height()){
2735 x_scale = (double) src.height()/src.width(); 2739 x_scale = (double) src.height()/src.width();
2736 radius = y_center; 2740 radius = y_center;
2737 } 2741 }
2738 amount=factor/10.0; 2742 amount=factor/10.0;
2739 if(amount >= 0) 2743 if(amount >= 0)
2740 amount/=10.0; 2744 amount/=10.0;
2741 if(src.depth() > 8){ // DirectClass source image 2745 if(src.depth() > 8){ // DirectClass source image
2742 unsigned int *srcData; 2746 unsigned int *srcData;
2743 for(y=0; y < src.height(); ++y){ 2747 for(y=0; y < src.height(); ++y){
2744 srcData = (unsigned int *)src.scanLine(y); 2748 srcData = (unsigned int *)src.scanLine(y);
2745 destData = (unsigned int *)dest.scanLine(y); 2749 destData = (unsigned int *)dest.scanLine(y);
2746 y_distance=y_scale*(y-y_center); 2750 y_distance=y_scale*(y-y_center);
2747 for(x=0; x < src.width(); ++x){ 2751 for(x=0; x < src.width(); ++x){
2748 destData[x] = srcData[x]; 2752 destData[x] = srcData[x];
2749 x_distance = x_scale*(x-x_center); 2753 x_distance = x_scale*(x-x_center);
2750 distance= x_distance*x_distance+y_distance*y_distance; 2754 distance= x_distance*x_distance+y_distance*y_distance;
2751 if(distance < (radius*radius)){ 2755 if(distance < (radius*radius)){
2752 double factor; 2756 double factor;
2753 // Implode the pixel. 2757 // Implode the pixel.
2754 factor=1.0; 2758 factor=1.0;
2755 if(distance > 0.0) 2759 if(distance > 0.0)
2756 factor= 2760 factor=
2757 pow(sin(0.5000000000000001*M_PI*sqrt(distance)/radius),-amount); 2761 pow(sin(0.5000000000000001*M_PI*sqrt(distance)/radius),-amount);
2758 destData[x] = interpolateColor(&src, factor*x_distance/x_scale+x_center, 2762 destData[x] = interpolateColor(&src, factor*x_distance/x_scale+x_center,
2759 factor*y_distance/y_scale+y_center, 2763 factor*y_distance/y_scale+y_center,
2760 background); 2764 background);
2761 } 2765 }
2762 } 2766 }
2763 } 2767 }
2764 } 2768 }
2765 else{ // PsudeoClass source image 2769 else{ // PsudeoClass source image
2766 unsigned char *srcData; 2770 unsigned char *srcData;
2767 unsigned char idx; 2771 unsigned char idx;
2768 unsigned int *cTable = src.colorTable(); 2772 unsigned int *cTable = src.colorTable();
2769 for(y=0; y < src.height(); ++y){ 2773 for(y=0; y < src.height(); ++y){
2770 srcData = (unsigned char *)src.scanLine(y); 2774 srcData = (unsigned char *)src.scanLine(y);
2771 destData = (unsigned int *)dest.scanLine(y); 2775 destData = (unsigned int *)dest.scanLine(y);
2772 y_distance=y_scale*(y-y_center); 2776 y_distance=y_scale*(y-y_center);
2773 for(x=0; x < src.width(); ++x){ 2777 for(x=0; x < src.width(); ++x){
2774 idx = srcData[x]; 2778 idx = srcData[x];
2775 destData[x] = cTable[idx]; 2779 destData[x] = cTable[idx];
2776 x_distance = x_scale*(x-x_center); 2780 x_distance = x_scale*(x-x_center);
2777 distance= x_distance*x_distance+y_distance*y_distance; 2781 distance= x_distance*x_distance+y_distance*y_distance;
2778 if(distance < (radius*radius)){ 2782 if(distance < (radius*radius)){
2779 double factor; 2783 double factor;
2780 // Implode the pixel. 2784 // Implode the pixel.
2781 factor=1.0; 2785 factor=1.0;
2782 if(distance > 0.0) 2786 if(distance > 0.0)
2783 factor= 2787 factor=
2784 pow(sin(0.5000000000000001*M_PI*sqrt(distance)/radius),-amount); 2788 pow(sin(0.5000000000000001*M_PI*sqrt(distance)/radius),-amount);
2785 destData[x] = interpolateColor(&src, factor*x_distance/x_scale+x_center, 2789 destData[x] = interpolateColor(&src, factor*x_distance/x_scale+x_center,
2786 factor*y_distance/y_scale+y_center, 2790 factor*y_distance/y_scale+y_center,
2787 background); 2791 background);
2788 } 2792 }
2789 } 2793 }
2790 } 2794 }
2791 2795
2792 } 2796 }
2793 return(dest); 2797 return(dest);
2794} 2798}
2795 2799
2796QImage OImageEffect::rotate(QImage &img, RotateDirection r) 2800QImage OImageEffect::rotate(QImage &img, RotateDirection r)
2797{ 2801{
2798 QImage dest; 2802 QImage dest;
2799 int x, y; 2803 int x, y;
2800 if(img.depth() > 8){ 2804 if(img.depth() > 8){
2801 unsigned int *srcData, *destData; 2805 unsigned int *srcData, *destData;
2802 switch(r){ 2806 switch(r){
2803 case Rotate90: 2807 case Rotate90:
2804 dest.create(img.height(), img.width(), img.depth()); 2808 dest.create(img.height(), img.width(), img.depth());
2805 for(y=0; y < img.height(); ++y){ 2809 for(y=0; y < img.height(); ++y){
2806 srcData = (unsigned int *)img.scanLine(y); 2810 srcData = (unsigned int *)img.scanLine(y);
2807 for(x=0; x < img.width(); ++x){ 2811 for(x=0; x < img.width(); ++x){
2808 destData = (unsigned int *)dest.scanLine(x); 2812 destData = (unsigned int *)dest.scanLine(x);
2809 destData[img.height()-y-1] = srcData[x]; 2813 destData[img.height()-y-1] = srcData[x];
2810 } 2814 }
2811 } 2815 }
2812 break; 2816 break;
2813 case Rotate180: 2817 case Rotate180:
2814 dest.create(img.width(), img.height(), img.depth()); 2818 dest.create(img.width(), img.height(), img.depth());
2815 for(y=0; y < img.height(); ++y){ 2819 for(y=0; y < img.height(); ++y){
2816 srcData = (unsigned int *)img.scanLine(y); 2820 srcData = (unsigned int *)img.scanLine(y);
2817 destData = (unsigned int *)dest.scanLine(img.height()-y-1); 2821 destData = (unsigned int *)dest.scanLine(img.height()-y-1);
2818 for(x=0; x < img.width(); ++x) 2822 for(x=0; x < img.width(); ++x)
2819 destData[img.width()-x-1] = srcData[x]; 2823 destData[img.width()-x-1] = srcData[x];
2820 } 2824 }
2821 break; 2825 break;
2822 case Rotate270: 2826 case Rotate270:
2823 dest.create(img.height(), img.width(), img.depth()); 2827 dest.create(img.height(), img.width(), img.depth());
2824 for(y=0; y < img.height(); ++y){ 2828 for(y=0; y < img.height(); ++y){
2825 srcData = (unsigned int *)img.scanLine(y); 2829 srcData = (unsigned int *)img.scanLine(y);
2826 for(x=0; x < img.width(); ++x){ 2830 for(x=0; x < img.width(); ++x){
2827 destData = (unsigned int *)dest.scanLine(img.width()-x-1); 2831 destData = (unsigned int *)dest.scanLine(img.width()-x-1);
2828 destData[y] = srcData[x]; 2832 destData[y] = srcData[x];
2829 } 2833 }
2830 } 2834 }
2831 break; 2835 break;
2832 default: 2836 default:
2833 dest = img; 2837 dest = img;
2834 break; 2838 break;
2835 } 2839 }
2836 } 2840 }
2837 else{ 2841 else{
2838 unsigned char *srcData, *destData; 2842 unsigned char *srcData, *destData;
2839 unsigned int *srcTable, *destTable; 2843 unsigned int *srcTable, *destTable;
2840 switch(r){ 2844 switch(r){
2841 case Rotate90: 2845 case Rotate90:
2842 dest.create(img.height(), img.width(), img.depth()); 2846 dest.create(img.height(), img.width(), img.depth());
2843 dest.setNumColors(img.numColors()); 2847 dest.setNumColors(img.numColors());
2844 srcTable = (unsigned int *)img.colorTable(); 2848 srcTable = (unsigned int *)img.colorTable();
2845 destTable = (unsigned int *)dest.colorTable(); 2849 destTable = (unsigned int *)dest.colorTable();
2846 for(x=0; x < img.numColors(); ++x) 2850 for(x=0; x < img.numColors(); ++x)
2847 destTable[x] = srcTable[x]; 2851 destTable[x] = srcTable[x];
2848 for(y=0; y < img.height(); ++y){ 2852 for(y=0; y < img.height(); ++y){
2849 srcData = (unsigned char *)img.scanLine(y); 2853 srcData = (unsigned char *)img.scanLine(y);
2850 for(x=0; x < img.width(); ++x){ 2854 for(x=0; x < img.width(); ++x){
2851 destData = (unsigned char *)dest.scanLine(x); 2855 destData = (unsigned char *)dest.scanLine(x);
2852 destData[img.height()-y-1] = srcData[x]; 2856 destData[img.height()-y-1] = srcData[x];
2853 } 2857 }
2854 } 2858 }
2855 break; 2859 break;
2856 case Rotate180: 2860 case Rotate180:
2857 dest.create(img.width(), img.height(), img.depth()); 2861 dest.create(img.width(), img.height(), img.depth());
2858 dest.setNumColors(img.numColors()); 2862 dest.setNumColors(img.numColors());
2859 srcTable = (unsigned int *)img.colorTable(); 2863 srcTable = (unsigned int *)img.colorTable();
2860 destTable = (unsigned int *)dest.colorTable(); 2864 destTable = (unsigned int *)dest.colorTable();
2861 for(x=0; x < img.numColors(); ++x) 2865 for(x=0; x < img.numColors(); ++x)
2862 destTable[x] = srcTable[x]; 2866 destTable[x] = srcTable[x];
2863 for(y=0; y < img.height(); ++y){ 2867 for(y=0; y < img.height(); ++y){
2864 srcData = (unsigned char *)img.scanLine(y); 2868 srcData = (unsigned char *)img.scanLine(y);
2865 destData = (unsigned char *)dest.scanLine(img.height()-y-1); 2869 destData = (unsigned char *)dest.scanLine(img.height()-y-1);
2866 for(x=0; x < img.width(); ++x) 2870 for(x=0; x < img.width(); ++x)
2867 destData[img.width()-x-1] = srcData[x]; 2871 destData[img.width()-x-1] = srcData[x];
2868 } 2872 }
2869 break; 2873 break;
2870 case Rotate270: 2874 case Rotate270:
2871 dest.create(img.height(), img.width(), img.depth()); 2875 dest.create(img.height(), img.width(), img.depth());
2872 dest.setNumColors(img.numColors()); 2876 dest.setNumColors(img.numColors());
2873 srcTable = (unsigned int *)img.colorTable(); 2877 srcTable = (unsigned int *)img.colorTable();
2874 destTable = (unsigned int *)dest.colorTable(); 2878 destTable = (unsigned int *)dest.colorTable();
2875 for(x=0; x < img.numColors(); ++x) 2879 for(x=0; x < img.numColors(); ++x)
2876 destTable[x] = srcTable[x]; 2880 destTable[x] = srcTable[x];
2877 for(y=0; y < img.height(); ++y){ 2881 for(y=0; y < img.height(); ++y){
2878 srcData = (unsigned char *)img.scanLine(y); 2882 srcData = (unsigned char *)img.scanLine(y);
2879 for(x=0; x < img.width(); ++x){ 2883 for(x=0; x < img.width(); ++x){
2880 destData = (unsigned char *)dest.scanLine(img.width()-x-1); 2884 destData = (unsigned char *)dest.scanLine(img.width()-x-1);
2881 destData[y] = srcData[x]; 2885 destData[y] = srcData[x];
2882 } 2886 }
2883 } 2887 }
2884 break; 2888 break;
2885 default: 2889 default:
2886 dest = img; 2890 dest = img;
2887 break; 2891 break;
2888 } 2892 }
2889 2893
2890 } 2894 }
2891 return(dest); 2895 return(dest);
2892} 2896}
2893 2897
2894void OImageEffect::solarize(QImage &img, double factor) 2898void OImageEffect::solarize(QImage &img, double factor)
2895{ 2899{
2896 int i, count; 2900 int i, count;
2897 int threshold; 2901 int threshold;
2898 unsigned int *data; 2902 unsigned int *data;
2899 2903
2900 threshold = (int)(factor*(MaxRGB+1)/100.0); 2904 threshold = (int)(factor*(MaxRGB+1)/100.0);
2901 if(img.depth() < 32){ 2905 if(img.depth() < 32){
2902 data = (unsigned int *)img.colorTable(); 2906 data = (unsigned int *)img.colorTable();
2903 count = img.numColors(); 2907 count = img.numColors();
2904 } 2908 }
2905 else{ 2909 else{
2906 data = (unsigned int *)img.bits(); 2910 data = (unsigned int *)img.bits();
2907 count = img.width()*img.height(); 2911 count = img.width()*img.height();
2908 } 2912 }
2909 for(i=0; i < count; ++i){ 2913 for(i=0; i < count; ++i){
2910 data[i] = qRgba(qRed(data[i]) > threshold ? MaxRGB-qRed(data[i]) : qRed(data[i]), 2914 data[i] = qRgba(qRed(data[i]) > threshold ? MaxRGB-qRed(data[i]) : qRed(data[i]),
2911 qGreen(data[i]) > threshold ? MaxRGB-qGreen(data[i]) : qGreen(data[i]), 2915 qGreen(data[i]) > threshold ? MaxRGB-qGreen(data[i]) : qGreen(data[i]),
2912 qBlue(data[i]) > threshold ? MaxRGB-qBlue(data[i]) : qBlue(data[i]), 2916 qBlue(data[i]) > threshold ? MaxRGB-qBlue(data[i]) : qBlue(data[i]),
2913 qAlpha(data[i])); 2917 qAlpha(data[i]));
2914 } 2918 }
2915} 2919}
2916 2920
2917QImage OImageEffect::spread(QImage &src, unsigned int amount) 2921QImage OImageEffect::spread(QImage &src, unsigned int amount)
2918{ 2922{
2919 int quantum, x, y; 2923 int quantum, x, y;
2920 int x_distance, y_distance; 2924 int x_distance, y_distance;
2921 if(src.width() < 3 || src.height() < 3) 2925 if(src.width() < 3 || src.height() < 3)
2922 return(src); 2926 return(src);
2923 QImage dest(src); 2927 QImage dest(src);
2924 dest.detach(); 2928 dest.detach();
2925 quantum=(amount+1) >> 1; 2929 quantum=(amount+1) >> 1;
2926 if(src.depth() > 8){ // DirectClass source image 2930 if(src.depth() > 8){ // DirectClass source image
2927 unsigned int *p, *q; 2931 unsigned int *p, *q;
2928 for(y=0; y < src.height(); y++){ 2932 for(y=0; y < src.height(); y++){
2929 q = (unsigned int *)dest.scanLine(y); 2933 q = (unsigned int *)dest.scanLine(y);
2930 for(x=0; x < src.width(); x++){ 2934 for(x=0; x < src.width(); x++){
2931 x_distance = x + ((rand() & (amount+1))-quantum); 2935 x_distance = x + ((rand() & (amount+1))-quantum);
2932 y_distance = y + ((rand() & (amount+1))-quantum); 2936 y_distance = y + ((rand() & (amount+1))-quantum);
2933 x_distance = QMIN(x_distance, src.width()-1); 2937 x_distance = QMIN(x_distance, src.width()-1);
2934 y_distance = QMIN(y_distance, src.height()-1); 2938 y_distance = QMIN(y_distance, src.height()-1);
2935 if(x_distance < 0) 2939 if(x_distance < 0)
2936 x_distance = 0; 2940 x_distance = 0;
2937 if(y_distance < 0) 2941 if(y_distance < 0)
2938 y_distance = 0; 2942 y_distance = 0;
2939 p = (unsigned int *)src.scanLine(y_distance); 2943 p = (unsigned int *)src.scanLine(y_distance);
2940 p += x_distance; 2944 p += x_distance;
2941 *q++=(*p); 2945 *q++=(*p);
2942 } 2946 }
2943 } 2947 }
2944 } 2948 }
2945 else{ // PsudeoClass source image 2949 else{ // PsudeoClass source image
2946 // just do colortable values 2950 // just do colortable values
2947 unsigned char *p, *q; 2951 unsigned char *p, *q;
2948 for(y=0; y < src.height(); y++){ 2952 for(y=0; y < src.height(); y++){
2949 q = (unsigned char *)dest.scanLine(y); 2953 q = (unsigned char *)dest.scanLine(y);
2950 for(x=0; x < src.width(); x++){ 2954 for(x=0; x < src.width(); x++){
2951 x_distance = x + ((rand() & (amount+1))-quantum); 2955 x_distance = x + ((rand() & (amount+1))-quantum);
2952 y_distance = y + ((rand() & (amount+1))-quantum); 2956 y_distance = y + ((rand() & (amount+1))-quantum);
2953 x_distance = QMIN(x_distance, src.width()-1); 2957 x_distance = QMIN(x_distance, src.width()-1);
2954 y_distance = QMIN(y_distance, src.height()-1); 2958 y_distance = QMIN(y_distance, src.height()-1);
2955 if(x_distance < 0) 2959 if(x_distance < 0)
2956 x_distance = 0; 2960 x_distance = 0;
2957 if(y_distance < 0) 2961 if(y_distance < 0)
2958 y_distance = 0; 2962 y_distance = 0;
2959 p = (unsigned char *)src.scanLine(y_distance); 2963 p = (unsigned char *)src.scanLine(y_distance);
2960 p += x_distance; 2964 p += x_distance;
2961 *q++=(*p); 2965 *q++=(*p);
2962 } 2966 }
2963 } 2967 }
2964 } 2968 }
2965 return(dest); 2969 return(dest);
2966} 2970}
2967 2971
2968QImage OImageEffect::swirl(QImage &src, double degrees, 2972QImage OImageEffect::swirl(QImage &src, double degrees,
2969 unsigned int background) 2973 unsigned int background)
2970{ 2974{
2971 double cosine, distance, factor, radius, sine, x_center, x_distance, 2975 double cosine, distance, factor, radius, sine, x_center, x_distance,
2972 x_scale, y_center, y_distance, y_scale; 2976 x_scale, y_center, y_distance, y_scale;
2973 int x, y; 2977 int x, y;
2974 unsigned int *q; 2978 unsigned int *q;
2975 QImage dest(src.width(), src.height(), 32); 2979 QImage dest(src.width(), src.height(), 32);
2976 2980
2977 // compute scaling factor 2981 // compute scaling factor
2978 x_center = src.width()/2.0; 2982 x_center = src.width()/2.0;
2979 y_center = src.height()/2.0; 2983 y_center = src.height()/2.0;
2980 radius = QMAX(x_center,y_center); 2984 radius = QMAX(x_center,y_center);
2981 x_scale=1.0; 2985 x_scale=1.0;
2982 y_scale=1.0; 2986 y_scale=1.0;
2983 if(src.width() > src.height()) 2987 if(src.width() > src.height())
2984 y_scale=(double)src.width()/src.height(); 2988 y_scale=(double)src.width()/src.height();
2985 else if(src.width() < src.height()) 2989 else if(src.width() < src.height())
2986 x_scale=(double)src.height()/src.width(); 2990 x_scale=(double)src.height()/src.width();
2987 degrees=DegreesToRadians(degrees); 2991 degrees=DegreesToRadians(degrees);
2988 // swirl each row 2992 // swirl each row
2989 if(src.depth() > 8){ // DirectClass source image 2993 if(src.depth() > 8){ // DirectClass source image
2990 unsigned int *p; 2994 unsigned int *p;
2991 for(y=0; y < src.height(); y++){ 2995 for(y=0; y < src.height(); y++){
2992 p = (unsigned int *)src.scanLine(y); 2996 p = (unsigned int *)src.scanLine(y);
2993 q = (unsigned int *)dest.scanLine(y); 2997 q = (unsigned int *)dest.scanLine(y);
2994 y_distance = y_scale*(y-y_center); 2998 y_distance = y_scale*(y-y_center);
2995 for(x=0; x < src.width(); x++){ 2999 for(x=0; x < src.width(); x++){
2996 // determine if the pixel is within an ellipse 3000 // determine if the pixel is within an ellipse
2997 *q=(*p); 3001 *q=(*p);
2998 x_distance = x_scale*(x-x_center); 3002 x_distance = x_scale*(x-x_center);
2999 distance = x_distance*x_distance+y_distance*y_distance; 3003 distance = x_distance*x_distance+y_distance*y_distance;
3000 if (distance < (radius*radius)){ 3004 if (distance < (radius*radius)){
3001 // swirl 3005 // swirl
3002 factor = 1.0-sqrt(distance)/radius; 3006 factor = 1.0-sqrt(distance)/radius;
3003 sine = sin(degrees*factor*factor); 3007 sine = sin(degrees*factor*factor);
3004 cosine = cos(degrees*factor*factor); 3008 cosine = cos(degrees*factor*factor);
3005 *q = interpolateColor(&src, 3009 *q = interpolateColor(&src,
3006 (cosine*x_distance-sine*y_distance)/x_scale+x_center, 3010 (cosine*x_distance-sine*y_distance)/x_scale+x_center,
3007 (sine*x_distance+cosine*y_distance)/y_scale+y_center, 3011 (sine*x_distance+cosine*y_distance)/y_scale+y_center,
3008 background); 3012 background);
3009 } 3013 }
3010 p++; 3014 p++;
3011 q++; 3015 q++;
3012 } 3016 }
3013 } 3017 }
3014 } 3018 }
3015 else{ // PsudeoClass source image 3019 else{ // PsudeoClass source image
3016 unsigned char *p; 3020 unsigned char *p;
3017 unsigned int *cTable = (unsigned int *)src.colorTable(); 3021 unsigned int *cTable = (unsigned int *)src.colorTable();
3018 for(y=0; y < src.height(); y++){ 3022 for(y=0; y < src.height(); y++){
3019 p = (unsigned char *)src.scanLine(y); 3023 p = (unsigned char *)src.scanLine(y);
3020 q = (unsigned int *)dest.scanLine(y); 3024 q = (unsigned int *)dest.scanLine(y);
3021 y_distance = y_scale*(y-y_center); 3025 y_distance = y_scale*(y-y_center);
3022 for(x=0; x < src.width(); x++){ 3026 for(x=0; x < src.width(); x++){
3023 // determine if the pixel is within an ellipse 3027 // determine if the pixel is within an ellipse
3024 *q = *(cTable+(*p)); 3028 *q = *(cTable+(*p));
3025 x_distance = x_scale*(x-x_center); 3029 x_distance = x_scale*(x-x_center);
3026 distance = x_distance*x_distance+y_distance*y_distance; 3030 distance = x_distance*x_distance+y_distance*y_distance;
3027 if (distance < (radius*radius)){ 3031 if (distance < (radius*radius)){
3028 // swirl 3032 // swirl
3029 factor = 1.0-sqrt(distance)/radius; 3033 factor = 1.0-sqrt(distance)/radius;
3030 sine = sin(degrees*factor*factor); 3034 sine = sin(degrees*factor*factor);
3031 cosine = cos(degrees*factor*factor); 3035 cosine = cos(degrees*factor*factor);
3032 *q = interpolateColor(&src, 3036 *q = interpolateColor(&src,
3033 (cosine*x_distance-sine*y_distance)/x_scale+x_center, 3037 (cosine*x_distance-sine*y_distance)/x_scale+x_center,
3034 (sine*x_distance+cosine*y_distance)/y_scale+y_center, 3038 (sine*x_distance+cosine*y_distance)/y_scale+y_center,
3035 background); 3039 background);
3036 } 3040 }
3037 p++; 3041 p++;
3038 q++; 3042 q++;
3039 } 3043 }
3040 } 3044 }
3041 3045
3042 } 3046 }
3043 return(dest); 3047 return(dest);
3044} 3048}
3045 3049
3046QImage OImageEffect::wave(QImage &src, double amplitude, double wavelength, 3050QImage OImageEffect::wave(QImage &src, double amplitude, double wavelength,
3047 unsigned int background) 3051 unsigned int background)
3048{ 3052{
3049 double *sine_map; 3053 double *sine_map;
3050 int x, y; 3054 int x, y;
3051 unsigned int *q; 3055 unsigned int *q;
3052 3056
3053 QImage dest(src.width(), src.height() + (int)(2*fabs(amplitude)), 32); 3057 QImage dest(src.width(), src.height() + (int)(2*fabs(amplitude)), 32);
3054 // allocate sine map 3058 // allocate sine map
3055 sine_map = (double *)malloc(dest.width()*sizeof(double)); 3059 sine_map = (double *)malloc(dest.width()*sizeof(double));
3056 if(!sine_map) 3060 if(!sine_map)
3057 return(src); 3061 return(src);
3058 for(x=0; x < dest.width(); ++x) 3062 for(x=0; x < dest.width(); ++x)
3059 sine_map[x]=fabs(amplitude)+amplitude*sin((2*M_PI*x)/wavelength); 3063 sine_map[x]=fabs(amplitude)+amplitude*sin((2*M_PI*x)/wavelength);
3060 // wave image 3064 // wave image
3061 for(y=0; y < dest.height(); ++y){ 3065 for(y=0; y < dest.height(); ++y){
3062 q = (unsigned int *)dest.scanLine(y); 3066 q = (unsigned int *)dest.scanLine(y);
3063 for (x=0; x < dest.width(); x++){ 3067 for (x=0; x < dest.width(); x++){
3064 *q=interpolateColor(&src, x, (int)(y-sine_map[x]), background); 3068 *q=interpolateColor(&src, x, (int)(y-sine_map[x]), background);
3065 ++q; 3069 ++q;
3066 } 3070 }
3067 } 3071 }
3068 free(sine_map); 3072 free(sine_map);
3069 return(dest); 3073 return(dest);
3070} 3074}
3071 3075
3072QImage OImageEffect::oilPaint(QImage &src, int radius) 3076QImage OImageEffect::oilPaint(QImage &src, int radius)
3073{ 3077{
3074 // TODO 8bpp src! 3078 // TODO 8bpp src!
3075 if(src.depth() < 32){ 3079 if(src.depth() < 32){
3076 owarn << "Oil Paint source image < 32bpp. Convert before using!" << oendl; 3080 owarn << "Oil Paint source image < 32bpp. Convert before using!" << oendl;
3077 return(src); 3081 return(src);
3078 } 3082 }
3079 int j, k, i, x, y; 3083 int j, k, i, x, y;
3080 unsigned int *histogram; 3084 unsigned int *histogram;
3081 unsigned int *s; 3085 unsigned int *s;
3082 unsigned int count; 3086 unsigned int count;
3083 3087
3084 unsigned int *srcData, *destData; 3088 unsigned int *srcData, *destData;
3085 3089
3086 QImage dest(src); 3090 QImage dest(src);
3087 dest.detach(); 3091 dest.detach();
3088 histogram = (unsigned int *) malloc((MaxRGB+1)*sizeof(unsigned int)); 3092 histogram = (unsigned int *) malloc((MaxRGB+1)*sizeof(unsigned int));
3089 if(!histogram) 3093 if(!histogram)
3090 return(src); 3094 return(src);
3091 // paint each row 3095 // paint each row
3092 k=0; 3096 k=0;
3093 for(y = radius; y < src.height(); ++y){ 3097 for(y = radius; y < src.height(); ++y){
3094 srcData = (unsigned int *)src.scanLine(y-radius); 3098 srcData = (unsigned int *)src.scanLine(y-radius);
3095 destData = (unsigned int *)dest.scanLine(y); 3099 destData = (unsigned int *)dest.scanLine(y);
3096 srcData += radius*src.width()+radius; 3100 srcData += radius*src.width()+radius;
3097 destData += radius; 3101 destData += radius;
3098 for(x=radius; x < src.width()-radius; ++x){ 3102 for(x=radius; x < src.width()-radius; ++x){
3099 // determine most frequent color 3103 // determine most frequent color
3100 count = 0; 3104 count = 0;
3101 for(i=0; i < MaxRGB+1; ++i) 3105 for(i=0; i < MaxRGB+1; ++i)
3102 histogram[i] = 0; 3106 histogram[i] = 0;
3103 for(i=0; i < radius; ++i){ 3107 for(i=0; i < radius; ++i){
3104 s = srcData-(radius-1)*src.width()-i-1; 3108 s = srcData-(radius-1)*src.width()-i-1;
3105 for(j =0; j < (2*i+1); ++j){ 3109 for(j =0; j < (2*i+1); ++j){
3106 k = intensityValue(*s); 3110 k = intensityValue(*s);
3107 histogram[k]++; 3111 histogram[k]++;
3108 if(histogram[k] > count){ 3112 if(histogram[k] > count){
3109 *destData = *s; 3113 *destData = *s;
3110 count = histogram[k]; 3114 count = histogram[k];
3111 } 3115 }
3112 ++s; 3116 ++s;
3113 } 3117 }
3114 s = srcData+(radius-i)*src.width()-i-1; 3118 s = srcData+(radius-i)*src.width()-i-1;
3115 for(j =0; j < (2*i+1); ++j){ 3119 for(j =0; j < (2*i+1); ++j){
3116 k = intensityValue(*s); 3120 k = intensityValue(*s);
3117 histogram[k]++; 3121 histogram[k]++;
3118 if(histogram[k] > count){ 3122 if(histogram[k] > count){
3119 *destData = *s; 3123 *destData = *s;
3120 count = histogram[k]; 3124 count = histogram[k];
3121 } 3125 }
3122 ++s; 3126 ++s;
3123 } 3127 }
3124 } 3128 }
3125 s = srcData-radius; 3129 s = srcData-radius;
3126 for(j =0; j < (2*i+1); ++j){ 3130 for(j =0; j < (2*i+1); ++j){
3127 k = intensityValue(*s); 3131 k = intensityValue(*s);
3128 histogram[k]++; 3132 histogram[k]++;
3129 if(histogram[k] > count){ 3133 if(histogram[k] > count){
3130 *destData = *s; 3134 *destData = *s;
3131 count = histogram[k]; 3135 count = histogram[k];
3132 } 3136 }
3133 ++s; 3137 ++s;
3134 } 3138 }
3135 ++srcData; 3139 ++srcData;
3136 ++destData; 3140 ++destData;
3137 } 3141 }
3138 } 3142 }
3139 free(histogram); 3143 free(histogram);
3140 return(dest); 3144 return(dest);
3141} 3145}
3142 3146
3143// 3147//
3144// The following methods work by computing a value from neighboring pixels 3148// The following methods work by computing a value from neighboring pixels
3145// (mosfet 12/28/01) 3149// (mosfet 12/28/01)
3146// 3150//
3147 3151
3148QImage OImageEffect::edge(QImage &src, double factor) 3152QImage OImageEffect::edge(QImage &src, double factor)
3149{ 3153{
3150#define Edge(weight) \ 3154#define Edge(weight) \
3151 total_red+=(weight)*qRed(*s); \ 3155 total_red+=(weight)*qRed(*s); \
3152 total_green+=(weight)*qGreen(*s); \ 3156 total_green+=(weight)*qGreen(*s); \
3153 total_blue+=(weight)*qBlue(*s); \ 3157 total_blue+=(weight)*qBlue(*s); \
3154 total_opacity+=(weight)*qAlpha(*s); \ 3158 total_opacity+=(weight)*qAlpha(*s); \
3155 s++; 3159 s++;
3156 3160
3157#define Edge256(weight) \ 3161#define Edge256(weight) \
3158 total_red+=(weight)*qRed(*(cTable+(*s))); \ 3162 total_red+=(weight)*qRed(*(cTable+(*s))); \
3159 total_green+=(weight)*qGreen(*(cTable+(*s))); \ 3163 total_green+=(weight)*qGreen(*(cTable+(*s))); \
3160 total_blue+=(weight)*qBlue(*(cTable+(*s))); \ 3164 total_blue+=(weight)*qBlue(*(cTable+(*s))); \
3161 total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \ 3165 total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \
3162 s++; 3166 s++;
3163 3167
3164 if(src.width() < 3 || src.height() < 3) 3168 if(src.width() < 3 || src.height() < 3)
3165 return(src); 3169 return(src);
3166 3170
3167 double total_blue, total_green, total_opacity, total_red, weight; 3171 double total_blue, total_green, total_opacity, total_red, weight;
3168 3172
3169 int x, y; 3173 int x, y;
3170 3174
3171 unsigned int *q; 3175 unsigned int *q;
3172 3176
3173 QImage dest(src.width(), src.height(), 32); 3177 QImage dest(src.width(), src.height(), 32);
3174 weight=factor/8.0; 3178 weight=factor/8.0;
3175 if(src.depth() > 8){ // DirectClass source image 3179 if(src.depth() > 8){ // DirectClass source image
3176 unsigned int *p, *s; 3180 unsigned int *p, *s;
3177 for(y=0; y < src.height(); ++y){ 3181 for(y=0; y < src.height(); ++y){
3178 p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); 3182 p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3));
3179 q = (unsigned int *)dest.scanLine(y); 3183 q = (unsigned int *)dest.scanLine(y);
3180 // edge detect this row of pixels. 3184 // edge detect this row of pixels.
3181 *q++=(*(p+src.width())); 3185 *q++=(*(p+src.width()));
3182 for(x=1; x < src.width()-1; ++x){ 3186 for(x=1; x < src.width()-1; ++x){
3183 // compute weighted average of target pixel color components. 3187 // compute weighted average of target pixel color components.
3184 total_red=0.0; 3188 total_red=0.0;
3185 total_green=0.0; 3189 total_green=0.0;
3186 total_blue=0.0; 3190 total_blue=0.0;
3187 total_opacity=0.0; 3191 total_opacity=0.0;
3188 s=p; 3192 s=p;
3189 Edge(-weight/8); Edge(-weight/8) Edge(-weight/8); 3193 Edge(-weight/8); Edge(-weight/8) Edge(-weight/8);
3190 s=p+src.width(); 3194 s=p+src.width();
3191 Edge(-weight/8); Edge(weight); Edge(-weight/8); 3195 Edge(-weight/8); Edge(weight); Edge(-weight/8);
3192 s=p+2*src.width(); 3196 s=p+2*src.width();
3193 Edge(-weight/8); Edge(-weight/8); Edge(-weight/8); 3197 Edge(-weight/8); Edge(-weight/8); Edge(-weight/8);
3194 *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red), 3198 *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red),
3195 (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green), 3199 (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green),
3196 (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue), 3200 (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue),
3197 (unsigned char)((total_opacity < 0) ? 0 : (total_opacity > MaxRGB) ? MaxRGB : total_opacity)); 3201 (unsigned char)((total_opacity < 0) ? 0 : (total_opacity > MaxRGB) ? MaxRGB : total_opacity));
3198 p++; 3202 p++;
3199 q++; 3203 q++;
3200 } 3204 }
3201 p++; 3205 p++;
3202 *q++=(*p); 3206 *q++=(*p);
3203 } 3207 }
3204 } 3208 }
3205 else{ // PsudeoClass source image 3209 else{ // PsudeoClass source image
3206 unsigned char *p, *p2, *p3, *s; 3210 unsigned char *p, *p2, *p3, *s;
3207 unsigned int *cTable = src.colorTable(); 3211 unsigned int *cTable = src.colorTable();
3208 int scanLineIdx; 3212 int scanLineIdx;
3209 for(y=0; y < src.height(); ++y){ 3213 for(y=0; y < src.height(); ++y){
3210 scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); 3214 scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3);
3211 p = (unsigned char *)src.scanLine(scanLineIdx); 3215 p = (unsigned char *)src.scanLine(scanLineIdx);
3212 p2 = (unsigned char *)src.scanLine(scanLineIdx+1); 3216 p2 = (unsigned char *)src.scanLine(scanLineIdx+1);
3213 p3 = (unsigned char *)src.scanLine(scanLineIdx+2); 3217 p3 = (unsigned char *)src.scanLine(scanLineIdx+2);
3214 q = (unsigned int *)dest.scanLine(y); 3218 q = (unsigned int *)dest.scanLine(y);
3215 // edge detect this row of pixels. 3219 // edge detect this row of pixels.
3216 *q++=(*(cTable+(*p2))); 3220 *q++=(*(cTable+(*p2)));
3217 for(x=1; x < src.width()-1; ++x){ 3221 for(x=1; x < src.width()-1; ++x){
3218 // compute weighted average of target pixel color components. 3222 // compute weighted average of target pixel color components.
3219 total_red=0.0; 3223 total_red=0.0;
3220 total_green=0.0; 3224 total_green=0.0;
3221 total_blue=0.0; 3225 total_blue=0.0;
3222 total_opacity=0.0; 3226 total_opacity=0.0;
3223 s=p; 3227 s=p;
3224 Edge256(-weight/8); Edge256(-weight/8) Edge256(-weight/8); 3228 Edge256(-weight/8); Edge256(-weight/8) Edge256(-weight/8);
3225 s=p2; 3229 s=p2;
3226 Edge256(-weight/8); Edge256(weight); Edge256(-weight/8); 3230 Edge256(-weight/8); Edge256(weight); Edge256(-weight/8);
3227 s=p3; 3231 s=p3;
3228 Edge256(-weight/8); Edge256(-weight/8); Edge256(-weight/8); 3232 Edge256(-weight/8); Edge256(-weight/8); Edge256(-weight/8);
3229 *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red), 3233 *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red),
3230 (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green), 3234 (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green),
3231 (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue), 3235 (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue),
3232 (unsigned char)((total_opacity < 0) ? 0 : (total_opacity > MaxRGB) ? MaxRGB : total_opacity)); 3236 (unsigned char)((total_opacity < 0) ? 0 : (total_opacity > MaxRGB) ? MaxRGB : total_opacity));
3233 p++; 3237 p++;
3234 p2++; 3238 p2++;
3235 p3++; 3239 p3++;
3236 q++; 3240 q++;
3237 } 3241 }
3238 p++; 3242 p++;
3239 *q++=(*(cTable+(*p))); 3243 *q++=(*(cTable+(*p)));
3240 } 3244 }
3241 } 3245 }
3242 return(dest); 3246 return(dest);
3243} 3247}
3244 3248
3245QImage OImageEffect::sharpen(QImage &src, double factor) 3249QImage OImageEffect::sharpen(QImage &src, double factor)
3246{ 3250{
3247#define Sharpen(weight) \ 3251#define Sharpen(weight) \
3248 total_red+=(weight)*qRed(*s); \ 3252 total_red+=(weight)*qRed(*s); \
3249 total_green+=(weight)*qGreen(*s); \ 3253 total_green+=(weight)*qGreen(*s); \
3250 total_blue+=(weight)*qBlue(*s); \ 3254 total_blue+=(weight)*qBlue(*s); \
3251 total_opacity+=(weight)*qAlpha(*s); \ 3255 total_opacity+=(weight)*qAlpha(*s); \
3252 s++; 3256 s++;
3253 3257
3254#define Sharpen256(weight) \ 3258#define Sharpen256(weight) \
3255 total_red+=(weight)*qRed(*(cTable+(*s))); \ 3259 total_red+=(weight)*qRed(*(cTable+(*s))); \
3256 total_green+=(weight)*qGreen(*(cTable+(*s))); \ 3260 total_green+=(weight)*qGreen(*(cTable+(*s))); \
3257 total_blue+=(weight)*qBlue(*(cTable+(*s))); \ 3261 total_blue+=(weight)*qBlue(*(cTable+(*s))); \
3258 total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \ 3262 total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \
3259 s++; 3263 s++;
3260 3264
3261 if(src.width() < 3 || src.height() < 3) 3265 if(src.width() < 3 || src.height() < 3)
3262 return(src); 3266 return(src);
3263 3267
3264 double total_blue, total_green, total_opacity, total_red; 3268 double total_blue, total_green, total_opacity, total_red;
3265 double quantum, weight; 3269 double quantum, weight;
3266 unsigned char r, g, b, a; 3270 unsigned char r, g, b, a;
3267 3271
3268 int x, y; 3272 int x, y;
3269 unsigned int *q; 3273 unsigned int *q;
3270 3274
3271 QImage dest(src.width(), src.height(), 32); 3275 QImage dest(src.width(), src.height(), 32);
3272 weight = ((100.0-factor)/2.0+13.0); 3276 weight = ((100.0-factor)/2.0+13.0);
3273 quantum = QMAX(weight-12.0, 1.0); 3277 quantum = QMAX(weight-12.0, 1.0);
3274 if(src.depth() > 8){ // DirectClass source image 3278 if(src.depth() > 8){ // DirectClass source image
3275 unsigned int *p, *s; 3279 unsigned int *p, *s;
3276 for(y=0; y < src.height(); ++y){ 3280 for(y=0; y < src.height(); ++y){
3277 p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); 3281 p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3));
3278 q = (unsigned int *)dest.scanLine(y); 3282 q = (unsigned int *)dest.scanLine(y);
3279 // sharpen this row of pixels. 3283 // sharpen this row of pixels.
3280 *q++=(*(p+src.width())); 3284 *q++=(*(p+src.width()));
3281 for(x=1; x < src.width()-1; ++x){ 3285 for(x=1; x < src.width()-1; ++x){
3282 // compute weighted average of target pixel color components. 3286 // compute weighted average of target pixel color components.
3283 total_red=0.0; 3287 total_red=0.0;
3284 total_green=0.0; 3288 total_green=0.0;
3285 total_blue=0.0; 3289 total_blue=0.0;
3286 total_opacity=0.0; 3290 total_opacity=0.0;
3287 s=p; 3291 s=p;
3288 Sharpen(-1); Sharpen(-2); Sharpen(-1); 3292 Sharpen(-1); Sharpen(-2); Sharpen(-1);
3289 s=p+src.width(); 3293 s=p+src.width();
3290 Sharpen(-2); Sharpen(weight); Sharpen(-2); 3294 Sharpen(-2); Sharpen(weight); Sharpen(-2);
3291 s=p+2*src.width(); 3295 s=p+2*src.width();
3292 Sharpen(-1); Sharpen(-2); Sharpen(-1); 3296 Sharpen(-1); Sharpen(-2); Sharpen(-1);
3293 if(total_red < 0) 3297 if(total_red < 0)
3294 r=0; 3298 r=0;
3295 else if(total_red > (int)(MaxRGB*quantum)) 3299 else if(total_red > (int)(MaxRGB*quantum))
3296 r = (unsigned char)MaxRGB; 3300 r = (unsigned char)MaxRGB;
3297 else 3301 else
3298 r = (unsigned char)((total_red+(quantum/2.0))/quantum); 3302 r = (unsigned char)((total_red+(quantum/2.0))/quantum);
3299 3303
3300 if(total_green < 0) 3304 if(total_green < 0)
3301 g = 0; 3305 g = 0;
3302 else if(total_green > (int)(MaxRGB*quantum)) 3306 else if(total_green > (int)(MaxRGB*quantum))
3303 g = (unsigned char)MaxRGB; 3307 g = (unsigned char)MaxRGB;
3304 else 3308 else
3305 g = (unsigned char)((total_green+(quantum/2.0))/quantum); 3309 g = (unsigned char)((total_green+(quantum/2.0))/quantum);
3306 3310
3307 if(total_blue < 0) 3311 if(total_blue < 0)
3308 b = 0; 3312 b = 0;
3309 else if(total_blue > (int)(MaxRGB*quantum)) 3313 else if(total_blue > (int)(MaxRGB*quantum))
3310 b = (unsigned char)MaxRGB; 3314 b = (unsigned char)MaxRGB;
3311 else 3315 else
3312 b = (unsigned char)((total_blue+(quantum/2.0))/quantum); 3316 b = (unsigned char)((total_blue+(quantum/2.0))/quantum);
3313 3317
3314 if(total_opacity < 0) 3318 if(total_opacity < 0)
3315 a = 0; 3319 a = 0;
3316 else if(total_opacity > (int)(MaxRGB*quantum)) 3320 else if(total_opacity > (int)(MaxRGB*quantum))
3317 a = (unsigned char)MaxRGB; 3321 a = (unsigned char)MaxRGB;
3318 else 3322 else
3319 a= (unsigned char)((total_opacity+(quantum/2.0))/quantum); 3323 a= (unsigned char)((total_opacity+(quantum/2.0))/quantum);
3320 3324
3321 *q = qRgba(r, g, b, a); 3325 *q = qRgba(r, g, b, a);
3322 3326
3323 p++; 3327 p++;
3324 q++; 3328 q++;
3325 } 3329 }
3326 p++; 3330 p++;
3327 *q++=(*p); 3331 *q++=(*p);
3328 } 3332 }
3329 } 3333 }
3330 else{ // PsudeoClass source image 3334 else{ // PsudeoClass source image
3331 unsigned char *p, *p2, *p3, *s; 3335 unsigned char *p, *p2, *p3, *s;
3332 unsigned int *cTable = src.colorTable(); 3336 unsigned int *cTable = src.colorTable();
3333 int scanLineIdx; 3337 int scanLineIdx;
3334 for(y=0; y < src.height(); ++y){ 3338 for(y=0; y < src.height(); ++y){
3335 scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); 3339 scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3);
3336 p = (unsigned char *)src.scanLine(scanLineIdx); 3340 p = (unsigned char *)src.scanLine(scanLineIdx);
3337 p2 = (unsigned char *)src.scanLine(scanLineIdx+1); 3341 p2 = (unsigned char *)src.scanLine(scanLineIdx+1);
3338 p3 = (unsigned char *)src.scanLine(scanLineIdx+2); 3342 p3 = (unsigned char *)src.scanLine(scanLineIdx+2);
3339 q = (unsigned int *)dest.scanLine(y); 3343 q = (unsigned int *)dest.scanLine(y);
3340 // sharpen this row of pixels. 3344 // sharpen this row of pixels.
3341 *q++=(*(cTable+(*p2))); 3345 *q++=(*(cTable+(*p2)));
3342 for(x=1; x < src.width()-1; ++x){ 3346 for(x=1; x < src.width()-1; ++x){
3343 // compute weighted average of target pixel color components. 3347 // compute weighted average of target pixel color components.
3344 total_red=0.0; 3348 total_red=0.0;
3345 total_green=0.0; 3349 total_green=0.0;
3346 total_blue=0.0; 3350 total_blue=0.0;
3347 total_opacity=0.0; 3351 total_opacity=0.0;
3348 s=p; 3352 s=p;
3349 Sharpen256(-1); Sharpen256(-2); Sharpen256(-1); 3353 Sharpen256(-1); Sharpen256(-2); Sharpen256(-1);
3350 s=p2; 3354 s=p2;
3351 Sharpen256(-2); Sharpen256(weight); Sharpen256(-2); 3355 Sharpen256(-2); Sharpen256(weight); Sharpen256(-2);
3352 s=p3; 3356 s=p3;
3353 Sharpen256(-1); Sharpen256(-2); Sharpen256(-1); 3357 Sharpen256(-1); Sharpen256(-2); Sharpen256(-1);
3354 if(total_red < 0) 3358 if(total_red < 0)
3355 r=0; 3359 r=0;
3356 else if(total_red > (int)(MaxRGB*quantum)) 3360 else if(total_red > (int)(MaxRGB*quantum))
3357 r = (unsigned char)MaxRGB; 3361 r = (unsigned char)MaxRGB;
3358 else 3362 else
3359 r = (unsigned char)((total_red+(quantum/2.0))/quantum); 3363 r = (unsigned char)((total_red+(quantum/2.0))/quantum);
3360 3364
3361 if(total_green < 0) 3365 if(total_green < 0)
3362 g = 0; 3366 g = 0;
3363 else if(total_green > (int)(MaxRGB*quantum)) 3367 else if(total_green > (int)(MaxRGB*quantum))
3364 g = (unsigned char)MaxRGB; 3368 g = (unsigned char)MaxRGB;
3365 else 3369 else
3366 g = (unsigned char)((total_green+(quantum/2.0))/quantum); 3370 g = (unsigned char)((total_green+(quantum/2.0))/quantum);
3367 3371
3368 if(total_blue < 0) 3372 if(total_blue < 0)
3369 b = 0; 3373 b = 0;
3370 else if(total_blue > (int)(MaxRGB*quantum)) 3374 else if(total_blue > (int)(MaxRGB*quantum))
3371 b = (unsigned char)MaxRGB; 3375 b = (unsigned char)MaxRGB;
3372 else 3376 else
3373 b = (unsigned char)((total_blue+(quantum/2.0))/quantum); 3377 b = (unsigned char)((total_blue+(quantum/2.0))/quantum);
3374 3378
3375 if(total_opacity < 0) 3379 if(total_opacity < 0)
3376 a = 0; 3380 a = 0;
3377 else if(total_opacity > (int)(MaxRGB*quantum)) 3381 else if(total_opacity > (int)(MaxRGB*quantum))
3378 a = (unsigned char)MaxRGB; 3382 a = (unsigned char)MaxRGB;
3379 else 3383 else
3380 a = (unsigned char)((total_opacity+(quantum/2.0))/quantum); 3384 a = (unsigned char)((total_opacity+(quantum/2.0))/quantum);
3381 3385
3382 *q = qRgba(r, g, b, a); 3386 *q = qRgba(r, g, b, a);
3383 3387
3384 p++; 3388 p++;
3385 p2++; 3389 p2++;
3386 p3++; 3390 p3++;
3387 q++; 3391 q++;
3388 } 3392 }
3389 p++; 3393 p++;
3390 *q++=(*(cTable+(*p))); 3394 *q++=(*(cTable+(*p)));
3391 } 3395 }
3392 } 3396 }
3393 return(dest); 3397 return(dest);
3394} 3398}
3395 3399
3396QImage OImageEffect::emboss(QImage &src) 3400QImage OImageEffect::emboss(QImage &src)
3397{ 3401{
3398#define Emboss(weight) \ 3402#define Emboss(weight) \
3399 total_red+=(weight)*qRed(*s); \ 3403 total_red+=(weight)*qRed(*s); \
3400 total_green+=(weight)*qGreen(*s); \ 3404 total_green+=(weight)*qGreen(*s); \
3401 total_blue+=(weight)*qBlue(*s); \ 3405 total_blue+=(weight)*qBlue(*s); \
3402 s++; 3406 s++;
3403 3407
3404#define Emboss256(weight) \ 3408#define Emboss256(weight) \
3405 total_red+=(weight)*qRed(*(cTable+(*s))); \ 3409 total_red+=(weight)*qRed(*(cTable+(*s))); \
3406 total_green+=(weight)*qGreen(*(cTable+(*s))); \ 3410 total_green+=(weight)*qGreen(*(cTable+(*s))); \
3407 total_blue+=(weight)*qBlue(*(cTable+(*s))); \ 3411 total_blue+=(weight)*qBlue(*(cTable+(*s))); \
3408 s++; 3412 s++;
3409 3413
3410 if(src.width() < 3 || src.height() < 3) 3414 if(src.width() < 3 || src.height() < 3)
3411 return(src); 3415 return(src);
3412 3416
3413 double total_blue, total_green, total_red; 3417 double total_blue, total_green, total_red;
3414 int x, y; 3418 int x, y;
3415 unsigned int *q; 3419 unsigned int *q;
3416 3420
3417 QImage dest(src.width(), src.height(), 32); 3421 QImage dest(src.width(), src.height(), 32);
3418 if(src.depth() > 8){ // DirectClass source image 3422 if(src.depth() > 8){ // DirectClass source image
3419 unsigned int *p, *s; 3423 unsigned int *p, *s;
3420 for(y=0; y < src.height(); ++y){ 3424 for(y=0; y < src.height(); ++y){
3421 p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); 3425 p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3));
3422 q = (unsigned int *)dest.scanLine(y); 3426 q = (unsigned int *)dest.scanLine(y);
3423 // emboss this row of pixels. 3427 // emboss this row of pixels.
3424 *q++=(*(p+src.width())); 3428 *q++=(*(p+src.width()));
3425 for(x=1; x < src.width()-1; ++x){ 3429 for(x=1; x < src.width()-1; ++x){
3426 // compute weighted average of target pixel color components. 3430 // compute weighted average of target pixel color components.
3427 total_red=0.0; 3431 total_red=0.0;
3428 total_green=0.0; 3432 total_green=0.0;
3429 total_blue=0.0; 3433 total_blue=0.0;
3430 s=p; 3434 s=p;
3431 Emboss(-1); Emboss(-2); Emboss( 0); 3435 Emboss(-1); Emboss(-2); Emboss( 0);
3432 s=p+src.width(); 3436 s=p+src.width();
3433 Emboss(-2); Emboss( 0); Emboss( 2); 3437 Emboss(-2); Emboss( 0); Emboss( 2);
3434 s=p+2*src.width(); 3438 s=p+2*src.width();
3435 Emboss( 0); Emboss( 2); Emboss( 1); 3439 Emboss( 0); Emboss( 2); Emboss( 1);
3436 total_red += (MaxRGB+1)/2; 3440 total_red += (MaxRGB+1)/2;
3437 total_green += (MaxRGB+1)/2; 3441 total_green += (MaxRGB+1)/2;
3438 total_blue += (MaxRGB+1)/2; 3442 total_blue += (MaxRGB+1)/2;
3439 *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red), 3443 *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red),
3440 (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green), 3444 (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green),
3441 (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue), 3445 (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue),
3442 255); 3446 255);
3443 p++; 3447 p++;
3444 q++; 3448 q++;
3445 } 3449 }
3446 p++; 3450 p++;
3447 *q++=(*p); 3451 *q++=(*p);
3448 } 3452 }
3449 } 3453 }
3450 else{ // PsudeoClass source image 3454 else{ // PsudeoClass source image
3451 unsigned char *p, *p2, *p3, *s; 3455 unsigned char *p, *p2, *p3, *s;
3452 unsigned int *cTable = src.colorTable(); 3456 unsigned int *cTable = src.colorTable();
3453 int scanLineIdx; 3457 int scanLineIdx;
3454 for(y=0; y < src.height(); ++y){ 3458 for(y=0; y < src.height(); ++y){
3455 scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); 3459 scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3);
3456 p = (unsigned char *)src.scanLine(scanLineIdx); 3460 p = (unsigned char *)src.scanLine(scanLineIdx);
3457 p2 = (unsigned char *)src.scanLine(scanLineIdx+1); 3461 p2 = (unsigned char *)src.scanLine(scanLineIdx+1);
3458 p3 = (unsigned char *)src.scanLine(scanLineIdx+2); 3462 p3 = (unsigned char *)src.scanLine(scanLineIdx+2);
3459 q = (unsigned int *)dest.scanLine(y); 3463 q = (unsigned int *)dest.scanLine(y);
3460 // emboss this row of pixels. 3464 // emboss this row of pixels.
3461 *q++=(*(cTable+(*p2))); 3465 *q++=(*(cTable+(*p2)));
3462 for(x=1; x < src.width()-1; ++x){ 3466 for(x=1; x < src.width()-1; ++x){
3463 // compute weighted average of target pixel color components. 3467 // compute weighted average of target pixel color components.
3464 total_red=0.0; 3468 total_red=0.0;
3465 total_green=0.0; 3469 total_green=0.0;
3466 total_blue=0.0; 3470 total_blue=0.0;
3467 s=p; 3471 s=p;
3468 Emboss256(-1); Emboss256(-2); Emboss256(0); 3472 Emboss256(-1); Emboss256(-2); Emboss256(0);
3469 s=p2; 3473 s=p2;
3470 Emboss256(-2); Emboss256(0); Emboss256(2); 3474 Emboss256(-2); Emboss256(0); Emboss256(2);
3471 s=p3; 3475 s=p3;
3472 Emboss256(0); Emboss256(2); Emboss256(1); 3476 Emboss256(0); Emboss256(2); Emboss256(1);
3473 total_red += (MaxRGB+1)/2; 3477 total_red += (MaxRGB+1)/2;
3474 total_green += (MaxRGB+1)/2; 3478 total_green += (MaxRGB+1)/2;
3475 total_blue += (MaxRGB+1)/2; 3479 total_blue += (MaxRGB+1)/2;
3476 *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red), 3480 *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red),
3477 (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green), 3481 (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green),
3478 (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue), 3482 (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue),
3479 255); 3483 255);
3480 p++; 3484 p++;
3481 p2++; 3485 p2++;
3482 p3++; 3486 p3++;
3483 q++; 3487 q++;
3484 } 3488 }
3485 p++; 3489 p++;
3486 *q++=(*(cTable+(*p))); 3490 *q++=(*(cTable+(*p)));
3487 } 3491 }
3488 } 3492 }
3489 toGray(dest); 3493 toGray(dest);
3490 normalize(dest); 3494 normalize(dest);
3491 return(dest); 3495 return(dest);
3492} 3496}
3493 3497
3494QImage OImageEffect::shade(QImage &src, bool color_shading, double azimuth, 3498QImage OImageEffect::shade(QImage &src, bool color_shading, double azimuth,
3495 double elevation) 3499 double elevation)
3496{ 3500{
3497 struct PointInfo{ 3501 struct PointInfo{
3498 double x, y, z; 3502 double x, y, z;
3499 }; 3503 };
3500 3504
3501 double distance, normal_distance, shade; 3505 double distance, normal_distance, shade;
3502 int x, y; 3506 int x, y;
3503 3507
3504 struct PointInfo light, normal; 3508 struct PointInfo light, normal;
3505 3509
3506 unsigned int *q; 3510 unsigned int *q;
3507 3511
3508 QImage dest(src.width(), src.height(), 32); 3512 QImage dest(src.width(), src.height(), 32);
3509 3513
3510 azimuth = DegreesToRadians(azimuth); 3514 azimuth = DegreesToRadians(azimuth);
3511 elevation = DegreesToRadians(elevation); 3515 elevation = DegreesToRadians(elevation);
3512 light.x = MaxRGB*cos(azimuth)*cos(elevation); 3516 light.x = MaxRGB*cos(azimuth)*cos(elevation);
3513 light.y = MaxRGB*sin(azimuth)*cos(elevation); 3517 light.y = MaxRGB*sin(azimuth)*cos(elevation);
3514 light.z = MaxRGB*sin(elevation); 3518 light.z = MaxRGB*sin(elevation);
3515 normal.z= 2*MaxRGB; // constant Z of surface normal 3519 normal.z= 2*MaxRGB; // constant Z of surface normal
3516 3520
3517 if(src.depth() > 8){ // DirectClass source image 3521 if(src.depth() > 8){ // DirectClass source image
3518 unsigned int *p, *s0, *s1, *s2; 3522 unsigned int *p, *s0, *s1, *s2;
3519 for(y=0; y < src.height(); ++y){ 3523 for(y=0; y < src.height(); ++y){
3520 p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); 3524 p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3));
3521 q = (unsigned int *)dest.scanLine(y); 3525 q = (unsigned int *)dest.scanLine(y);
3522 // shade this row of pixels. 3526 // shade this row of pixels.
3523 *q++=(*(p+src.width())); 3527 *q++=(*(p+src.width()));
3524 p++; 3528 p++;
3525 s0 = p; 3529 s0 = p;
3526 s1 = p + src.width(); 3530 s1 = p + src.width();
3527 s2 = p + 2*src.width(); 3531 s2 = p + 2*src.width();
3528 for(x=1; x < src.width()-1; ++x){ 3532 for(x=1; x < src.width()-1; ++x){
3529 // determine the surface normal and compute shading. 3533 // determine the surface normal and compute shading.
3530 normal.x=intensityValue(*(s0-1))+intensityValue(*(s1-1))+intensityValue(*(s2-1))- 3534 normal.x=intensityValue(*(s0-1))+intensityValue(*(s1-1))+intensityValue(*(s2-1))-
3531 (double) intensityValue(*(s0+1))-(double) intensityValue(*(s1+1))- 3535 (double) intensityValue(*(s0+1))-(double) intensityValue(*(s1+1))-
3532 (double) intensityValue(*(s2+1)); 3536 (double) intensityValue(*(s2+1));
3533 normal.y=intensityValue(*(s2-1))+intensityValue(*s2)+intensityValue(*(s2+1))- 3537 normal.y=intensityValue(*(s2-1))+intensityValue(*s2)+intensityValue(*(s2+1))-
3534 (double) intensityValue(*(s0-1))-(double) intensityValue(*s0)- 3538 (double) intensityValue(*(s0-1))-(double) intensityValue(*s0)-
3535 (double) intensityValue(*(s0+1)); 3539 (double) intensityValue(*(s0+1));
3536 if((normal.x == 0) && (normal.y == 0)) 3540 if((normal.x == 0) && (normal.y == 0))
3537 shade=light.z; 3541 shade=light.z;
3538 else{ 3542 else{
3539 shade=0.0; 3543 shade=0.0;
3540 distance=normal.x*light.x+normal.y*light.y+normal.z*light.z; 3544 distance=normal.x*light.x+normal.y*light.y+normal.z*light.z;
3541 if (distance > 0.0){ 3545 if (distance > 0.0){
3542 normal_distance= 3546 normal_distance=
3543 normal.x*normal.x+normal.y*normal.y+normal.z*normal.z; 3547 normal.x*normal.x+normal.y*normal.y+normal.z*normal.z;
3544 if(fabs(normal_distance) > 0.0000001) 3548 if(fabs(normal_distance) > 0.0000001)
3545 shade=distance/sqrt(normal_distance); 3549 shade=distance/sqrt(normal_distance);
3546 } 3550 }
3547 } 3551 }
3548 if(!color_shading){ 3552 if(!color_shading){
3549 *q = qRgba((unsigned char)(shade), 3553 *q = qRgba((unsigned char)(shade),
3550 (unsigned char)(shade), 3554 (unsigned char)(shade),
3551 (unsigned char)(shade), 3555 (unsigned char)(shade),
3552 qAlpha(*s1)); 3556 qAlpha(*s1));
3553 } 3557 }
3554 else{ 3558 else{
3555 *q = qRgba((unsigned char)((shade*qRed(*s1))/(MaxRGB+1)), 3559 *q = qRgba((unsigned char)((shade*qRed(*s1))/(MaxRGB+1)),
3556 (unsigned char)((shade*qGreen(*s1))/(MaxRGB+1)), 3560 (unsigned char)((shade*qGreen(*s1))/(MaxRGB+1)),
3557 (unsigned char)((shade*qBlue(*s1))/(MaxRGB+1)), 3561 (unsigned char)((shade*qBlue(*s1))/(MaxRGB+1)),
3558 qAlpha(*s1)); 3562 qAlpha(*s1));
3559 } 3563 }
3560 ++s0; 3564 ++s0;
3561 ++s1; 3565 ++s1;
3562 ++s2; 3566 ++s2;
3563 q++; 3567 q++;
3564 } 3568 }
3565 *q++=(*s1); 3569 *q++=(*s1);
3566 } 3570 }
3567 } 3571 }
3568 else{ // PsudeoClass source image 3572 else{ // PsudeoClass source image
3569 unsigned char *p, *s0, *s1, *s2; 3573 unsigned char *p, *s0, *s1, *s2;
3570 int scanLineIdx; 3574 int scanLineIdx;
3571 unsigned int *cTable = (unsigned int *)src.colorTable(); 3575 unsigned int *cTable = (unsigned int *)src.colorTable();
3572 for(y=0; y < src.height(); ++y){ 3576 for(y=0; y < src.height(); ++y){
3573 scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); 3577 scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3);
3574 p = (unsigned char *)src.scanLine(scanLineIdx); 3578 p = (unsigned char *)src.scanLine(scanLineIdx);
3575 q = (unsigned int *)dest.scanLine(y); 3579 q = (unsigned int *)dest.scanLine(y);
3576 // shade this row of pixels. 3580 // shade this row of pixels.
3577 s0 = p; 3581 s0 = p;
3578 s1 = (unsigned char *) src.scanLine(scanLineIdx+1); 3582 s1 = (unsigned char *) src.scanLine(scanLineIdx+1);
3579 s2 = (unsigned char *) src.scanLine(scanLineIdx+2); 3583 s2 = (unsigned char *) src.scanLine(scanLineIdx+2);
3580 *q++=(*(cTable+(*s1))); 3584 *q++=(*(cTable+(*s1)));
3581 ++p; 3585 ++p;
3582 ++s0; 3586 ++s0;
3583 ++s1; 3587 ++s1;
3584 ++s2; 3588 ++s2;
3585 for(x=1; x < src.width()-1; ++x){ 3589 for(x=1; x < src.width()-1; ++x){
3586 // determine the surface normal and compute shading. 3590 // determine the surface normal and compute shading.
3587 normal.x=intensityValue(*(cTable+(*(s0-1))))+intensityValue(*(cTable+(*(s1-1))))+intensityValue(*(cTable+(*(s2-1))))- 3591 normal.x=intensityValue(*(cTable+(*(s0-1))))+intensityValue(*(cTable+(*(s1-1))))+intensityValue(*(cTable+(*(s2-1))))-
3588 (double) intensityValue(*(cTable+(*(s0+1))))-(double) intensityValue(*(cTable+(*(s1+1))))- 3592 (double) intensityValue(*(cTable+(*(s0+1))))-(double) intensityValue(*(cTable+(*(s1+1))))-
3589 (double) intensityValue(*(cTable+(*(s2+1)))); 3593 (double) intensityValue(*(cTable+(*(s2+1))));
3590 normal.y=intensityValue(*(cTable+(*(s2-1))))+intensityValue(*(cTable+(*s2)))+intensityValue(*(cTable+(*(s2+1))))- 3594 normal.y=intensityValue(*(cTable+(*(s2-1))))+intensityValue(*(cTable+(*s2)))+intensityValue(*(cTable+(*(s2+1))))-
3591 (double) intensityValue(*(cTable+(*(s0-1))))-(double) intensityValue(*(cTable+(*s0)))- 3595 (double) intensityValue(*(cTable+(*(s0-1))))-(double) intensityValue(*(cTable+(*s0)))-
3592 (double) intensityValue(*(cTable+(*(s0+1)))); 3596 (double) intensityValue(*(cTable+(*(s0+1))));
3593 if((normal.x == 0) && (normal.y == 0)) 3597 if((normal.x == 0) && (normal.y == 0))
3594 shade=light.z; 3598 shade=light.z;
3595 else{ 3599 else{
3596 shade=0.0; 3600 shade=0.0;
3597 distance=normal.x*light.x+normal.y*light.y+normal.z*light.z; 3601 distance=normal.x*light.x+normal.y*light.y+normal.z*light.z;
3598 if (distance > 0.0){ 3602 if (distance > 0.0){
3599 normal_distance= 3603 normal_distance=
3600 normal.x*normal.x+normal.y*normal.y+normal.z*normal.z; 3604 normal.x*normal.x+normal.y*normal.y+normal.z*normal.z;
3601 if(fabs(normal_distance) > 0.0000001) 3605 if(fabs(normal_distance) > 0.0000001)
3602 shade=distance/sqrt(normal_distance); 3606 shade=distance/sqrt(normal_distance);
3603 } 3607 }
3604 } 3608 }
3605 if(!color_shading){ 3609 if(!color_shading){
3606 *q = qRgba((unsigned char)(shade), 3610 *q = qRgba((unsigned char)(shade),
3607 (unsigned char)(shade), 3611 (unsigned char)(shade),
3608 (unsigned char)(shade), 3612 (unsigned char)(shade),
3609 qAlpha(*(cTable+(*s1)))); 3613 qAlpha(*(cTable+(*s1))));
3610 } 3614 }
3611 else{ 3615 else{
3612 *q = qRgba((unsigned char)((shade*qRed(*(cTable+(*s1))))/(MaxRGB+1)), 3616 *q = qRgba((unsigned char)((shade*qRed(*(cTable+(*s1))))/(MaxRGB+1)),
3613 (unsigned char)((shade*qGreen(*(cTable+(*s1))))/(MaxRGB+1)), 3617 (unsigned char)((shade*qGreen(*(cTable+(*s1))))/(MaxRGB+1)),
3614 (unsigned char)((shade*qBlue(*(cTable+(*s1))))/(MaxRGB+1)), 3618 (unsigned char)((shade*qBlue(*(cTable+(*s1))))/(MaxRGB+1)),
3615 qAlpha(*s1)); 3619 qAlpha(*s1));
3616 } 3620 }
3617 ++s0; 3621 ++s0;
3618 ++s1; 3622 ++s1;
3619 ++s2; 3623 ++s2;
3620 q++; 3624 q++;
3621 } 3625 }
3622 *q++=(*(cTable+(*s1))); 3626 *q++=(*(cTable+(*s1)));
3623 } 3627 }
3624 } 3628 }
3625 return(dest); 3629 return(dest);
3626} 3630}
3627 3631
3628QImage OImageEffect::blur(QImage &src, double factor) 3632QImage OImageEffect::blur(QImage &src, double factor)
3629{ 3633{
3630 3634
3631#define Blur(weight) \ 3635#define Blur(weight) \
3632 total_red+=(weight)*qRed(*s); \ 3636 total_red+=(weight)*qRed(*s); \
3633 total_green+=(weight)*qGreen(*s); \ 3637 total_green+=(weight)*qGreen(*s); \
3634 total_blue+=(weight)*qBlue(*s); \ 3638 total_blue+=(weight)*qBlue(*s); \
3635 total_opacity+=(weight)*qAlpha(*s); \ 3639 total_opacity+=(weight)*qAlpha(*s); \
3636 s++; 3640 s++;
3637 3641
3638#define Blur256(weight) \ 3642#define Blur256(weight) \
3639 total_red+=(weight)*qRed(*(cTable+(*s))); \ 3643 total_red+=(weight)*qRed(*(cTable+(*s))); \
3640 total_green+=(weight)*qGreen(*(cTable+(*s))); \ 3644 total_green+=(weight)*qGreen(*(cTable+(*s))); \
3641 total_blue+=(weight)*qBlue(*(cTable+(*s))); \ 3645 total_blue+=(weight)*qBlue(*(cTable+(*s))); \
3642 total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \ 3646 total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \
3643 s++; 3647 s++;
3644 3648
3645 if(src.width() < 3 || src.height() < 3) 3649 if(src.width() < 3 || src.height() < 3)
3646 return(src); 3650 return(src);
3647 3651
3648 double quantum, total_blue, total_green, total_opacity, total_red, weight; 3652 double quantum, total_blue, total_green, total_opacity, total_red, weight;
3649 3653
3650 int x, y; 3654 int x, y;
3651 unsigned int *q; 3655 unsigned int *q;
3652 3656
3653 QImage dest(src.width(), src.height(), 32); 3657 QImage dest(src.width(), src.height(), 32);
3654 weight=((100.0-factor)/2)+1; 3658 weight=((100.0-factor)/2)+1;
3655 quantum = QMAX(weight+12.0, 1.0); 3659 quantum = QMAX(weight+12.0, 1.0);
3656 if(src.depth() > 8){ // DirectClass source image 3660 if(src.depth() > 8){ // DirectClass source image
3657 unsigned int *p, *s; 3661 unsigned int *p, *s;
3658 for(y=0; y < src.height(); ++y){ 3662 for(y=0; y < src.height(); ++y){
3659 p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); 3663 p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3));
3660 q = (unsigned int *)dest.scanLine(y); 3664 q = (unsigned int *)dest.scanLine(y);
3661 // blur this row of pixels. 3665 // blur this row of pixels.
3662 *q++=(*(p+src.width())); 3666 *q++=(*(p+src.width()));
3663 for(x=1; x < src.width()-1; ++x){ 3667 for(x=1; x < src.width()-1; ++x){
3664 // compute weighted average of target pixel color components. 3668 // compute weighted average of target pixel color components.
3665 total_red=0.0; 3669 total_red=0.0;
3666 total_green=0.0; 3670 total_green=0.0;
3667 total_blue=0.0; 3671 total_blue=0.0;
3668 total_opacity=0.0; 3672 total_opacity=0.0;
3669 s=p; 3673 s=p;
3670 Blur(1); Blur(2); Blur(1); 3674 Blur(1); Blur(2); Blur(1);
3671 s=p+src.width(); 3675 s=p+src.width();
3672 Blur(2); Blur(weight); Blur(2); 3676 Blur(2); Blur(weight); Blur(2);
3673 s=p+2*src.width(); 3677 s=p+2*src.width();
3674 Blur(1); Blur(2); Blur(1); 3678 Blur(1); Blur(2); Blur(1);
3675 *q = qRgba((unsigned char)((total_red+(quantum/2))/quantum), 3679 *q = qRgba((unsigned char)((total_red+(quantum/2))/quantum),
3676 (unsigned char)((total_green+(quantum/2))/quantum), 3680 (unsigned char)((total_green+(quantum/2))/quantum),
3677 (unsigned char)((total_blue+(quantum/2))/quantum), 3681 (unsigned char)((total_blue+(quantum/2))/quantum),
3678 (unsigned char)((total_opacity+(quantum/2))/quantum)); 3682 (unsigned char)((total_opacity+(quantum/2))/quantum));
3679 p++; 3683 p++;
3680 q++; 3684 q++;
3681 } 3685 }
3682 p++; 3686 p++;
3683 *q++=(*p); 3687 *q++=(*p);
3684 } 3688 }
3685 } 3689 }
3686 else{ // PsudeoClass source image 3690 else{ // PsudeoClass source image
3687 unsigned char *p, *p2, *p3, *s; 3691 unsigned char *p, *p2, *p3, *s;
3688 unsigned int *cTable = src.colorTable(); 3692 unsigned int *cTable = src.colorTable();
3689 int scanLineIdx; 3693 int scanLineIdx;
3690 for(y=0; y < src.height(); ++y){ 3694 for(y=0; y < src.height(); ++y){
3691 scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); 3695 scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3);
3692 p = (unsigned char *)src.scanLine(scanLineIdx); 3696 p = (unsigned char *)src.scanLine(scanLineIdx);
3693 p2 = (unsigned char *)src.scanLine(scanLineIdx+1); 3697 p2 = (unsigned char *)src.scanLine(scanLineIdx+1);
3694 p3 = (unsigned char *)src.scanLine(scanLineIdx+2); 3698 p3 = (unsigned char *)src.scanLine(scanLineIdx+2);
3695 q = (unsigned int *)dest.scanLine(y); 3699 q = (unsigned int *)dest.scanLine(y);
3696 // blur this row of pixels. 3700 // blur this row of pixels.
3697 *q++=(*(cTable+(*p2))); 3701 *q++=(*(cTable+(*p2)));
3698 for(x=1; x < src.width()-1; ++x){ 3702 for(x=1; x < src.width()-1; ++x){
3699 // compute weighted average of target pixel color components. 3703 // compute weighted average of target pixel color components.
3700 total_red=0.0; 3704 total_red=0.0;
3701 total_green=0.0; 3705 total_green=0.0;
3702 total_blue=0.0; 3706 total_blue=0.0;
3703 total_opacity=0.0; 3707 total_opacity=0.0;
3704 s=p; 3708 s=p;
3705 Blur256(1); Blur256(2); Blur256(1); 3709 Blur256(1); Blur256(2); Blur256(1);
3706 s=p2; 3710 s=p2;
3707 Blur256(2); Blur256(weight); Blur256(2); 3711 Blur256(2); Blur256(weight); Blur256(2);
3708 s=p3; 3712 s=p3;
3709 Blur256(1); Blur256(2); Blur256(1); 3713 Blur256(1); Blur256(2); Blur256(1);
3710 *q = qRgba((unsigned char)((total_red+(quantum/2))/quantum), 3714 *q = qRgba((unsigned char)((total_red+(quantum/2))/quantum),
3711 (unsigned char)((total_green+(quantum/2))/quantum), 3715 (unsigned char)((total_green+(quantum/2))/quantum),
3712 (unsigned char)((total_blue+(quantum/2))/quantum), 3716 (unsigned char)((total_blue+(quantum/2))/quantum),
3713 (unsigned char)((total_opacity+(quantum/2))/quantum)); 3717 (unsigned char)((total_opacity+(quantum/2))/quantum));
3714 p++; 3718 p++;
3715 p2++; 3719 p2++;
3716 p3++; 3720 p3++;
3717 q++; 3721 q++;
3718 } 3722 }
3719 p++; 3723 p++;
3720 *q++=(*(cTable+(*p))); 3724 *q++=(*(cTable+(*p)));
3721 } 3725 }
3722 } 3726 }
3723 return(dest); 3727 return(dest);
3724} 3728}
3725 3729
3726// High quality, expensive HSV contrast. You can do a faster one by just 3730// High quality, expensive HSV contrast. You can do a faster one by just
3727// taking a grayscale threshold (ie: 128) and incrementing RGB color 3731// taking a grayscale threshold (ie: 128) and incrementing RGB color
3728// channels above it and decrementing those below it, but this gives much 3732// channels above it and decrementing those below it, but this gives much
3729// better results. (mosfet 12/28/01) 3733// better results. (mosfet 12/28/01)
3730void OImageEffect::contrastHSV(QImage &img, bool sharpen) 3734void OImageEffect::contrastHSV(QImage &img, bool sharpen)
3731{ 3735{
3732 int i, sign; 3736 int i, sign;
3733 unsigned int *data; 3737 unsigned int *data;
3734 int count; 3738 int count;
3735 double brightness, scale, theta; 3739 double brightness, scale, theta;
3736 QColor c; 3740 QColor c;
3737 int h, s, v; 3741 int h, s, v;
3738 3742
3739 sign = sharpen ? 1 : -1; 3743 sign = sharpen ? 1 : -1;
3740 scale=0.5000000000000001; 3744 scale=0.5000000000000001;
3741 if(img.depth() > 8){ 3745 if(img.depth() > 8){
3742 count = img.width()*img.height(); 3746 count = img.width()*img.height();
3743 data = (unsigned int *)img.bits(); 3747 data = (unsigned int *)img.bits();
3744 } 3748 }
3745 else{ 3749 else{
3746 count = img.numColors(); 3750 count = img.numColors();
3747 data = (unsigned int *)img.colorTable(); 3751 data = (unsigned int *)img.colorTable();
3748 } 3752 }
3749 for(i=0; i < count; ++i){ 3753 for(i=0; i < count; ++i){
3750 c.setRgb(data[i]); 3754 c.setRgb(data[i]);
3751 c.hsv(&h, &s, &v); 3755 c.hsv(&h, &s, &v);
3752 brightness = v/255.0; 3756 brightness = v/255.0;
3753 theta=(brightness-0.5)*M_PI; 3757 theta=(brightness-0.5)*M_PI;
3754 brightness+=scale*(((scale*((sin(theta)+1.0)))-brightness)*sign); 3758 brightness+=scale*(((scale*((sin(theta)+1.0)))-brightness)*sign);
3755 if (brightness > 1.0) 3759 if (brightness > 1.0)
3756 brightness=1.0; 3760 brightness=1.0;
3757 else 3761 else
3758 if (brightness < 0) 3762 if (brightness < 0)
3759 brightness=0.0; 3763 brightness=0.0;
3760 v = (int)(brightness*255); 3764 v = (int)(brightness*255);
3761 c.setHsv(h, s, v); 3765 c.setHsv(h, s, v);
3762 data[i] = qRgba(c.red(), c.green(), c.blue(), qAlpha(data[i])); 3766 data[i] = qRgba(c.red(), c.green(), c.blue(), qAlpha(data[i]));
3763 } 3767 }
3764} 3768}
3765 3769
3766 3770
3767 3771
3768 3772}
3773}
diff --git a/libopie2/opieui/oimageeffect.h b/libopie2/opieui/oimageeffect.h
index fb4d22d..4f86d5b 100644
--- a/libopie2/opieui/oimageeffect.h
+++ b/libopie2/opieui/oimageeffect.h
@@ -1,559 +1,564 @@
1//FIXME: Revise for Opie - do we really need such fancy stuff on PDA's? 1//FIXME: Revise for Opie - do we really need such fancy stuff on PDA's?
2//FIXME: Maybe not on SL5xxx, but surely on C700 :)) 2//FIXME: Maybe not on SL5xxx, but surely on C700 :))
3//FIXME: I think we don#t need that -zecke 3//FIXME: I think we don#t need that -zecke
4 4
5/* This file is part of the KDE libraries 5/* This file is part of the KDE libraries
6 Copyright (C) 1998, 1999, 2001, 2002 Daniel M. Duley <mosfet@interaccess.com> 6 Copyright (C) 1998, 1999, 2001, 2002 Daniel M. Duley <mosfet@interaccess.com>
7 (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> 7 (C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
8 (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> 8 (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org>
9 9
10Redistribution and use in source and binary forms, with or without 10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions 11modification, are permitted provided that the following conditions
12are met: 12are met:
13 13
141. Redistributions of source code must retain the above copyright 141. Redistributions of source code must retain the above copyright
15 notice, this list of conditions and the following disclaimer. 15 notice, this list of conditions and the following disclaimer.
162. Redistributions in binary form must reproduce the above copyright 162. Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in the 17 notice, this list of conditions and the following disclaimer in the
18 documentation and/or other materials provided with the distribution. 18 documentation and/or other materials provided with the distribution.
19 19
20THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31*/ 31*/
32 32
33// $Id$ 33// $Id$
34 34
35#ifndef OIMAGEEFFECT_H 35#ifndef OIMAGEEFFECT_H
36#define OIMAGEEFFECT_H 36#define OIMAGEEFFECT_H
37 37
38class QImage; 38class QImage;
39class QSize; 39class QSize;
40class QColor; 40class QColor;
41 41
42namespace Opie {
43namespace Ui {
42/** 44/**
43 * This class includes various @ref QImage based graphical effects. 45 * This class includes various @ref QImage based graphical effects.
44 * 46 *
45 * Everything is 47 * Everything is
46 * static, so there is no need to create an instance of this class. You can 48 * static, so there is no need to create an instance of this class. You can
47 * just call the static methods. They are encapsulated here merely to provide 49 * just call the static methods. They are encapsulated here merely to provide
48 * a common namespace. 50 * a common namespace.
49 */ 51 */
50 52
51class OImageEffect 53class OImageEffect
52{ 54{
53public: 55public:
54 enum GradientType { VerticalGradient, HorizontalGradient, 56 enum GradientType { VerticalGradient, HorizontalGradient,
55 DiagonalGradient, CrossDiagonalGradient, 57 DiagonalGradient, CrossDiagonalGradient,
56 PyramidGradient, RectangleGradient, 58 PyramidGradient, RectangleGradient,
57 PipeCrossGradient, EllipticGradient }; 59 PipeCrossGradient, EllipticGradient };
58 enum RGBComponent { Red, Green, Blue, Gray, All }; 60 enum RGBComponent { Red, Green, Blue, Gray, All };
59 61
60 enum Lighting {NorthLite, NWLite, WestLite, SWLite, 62 enum Lighting {NorthLite, NWLite, WestLite, SWLite,
61 SouthLite, SELite, EastLite, NELite}; 63 SouthLite, SELite, EastLite, NELite};
62 64
63 enum ModulationType { Intensity, Saturation, HueShift, Contrast }; 65 enum ModulationType { Intensity, Saturation, HueShift, Contrast };
64 66
65 enum NoiseType { UniformNoise=0, GaussianNoise, MultiplicativeGaussianNoise, 67 enum NoiseType { UniformNoise=0, GaussianNoise, MultiplicativeGaussianNoise,
66 ImpulseNoise, LaplacianNoise, PoissonNoise}; 68 ImpulseNoise, LaplacianNoise, PoissonNoise};
67 69
68 enum RotateDirection{ Rotate90, Rotate180, Rotate270 }; 70 enum RotateDirection{ Rotate90, Rotate180, Rotate270 };
69 71
70 /** 72 /**
71 * Create a gradient from color a to color b of the specified type. 73 * Create a gradient from color a to color b of the specified type.
72 * 74 *
73 * @param size The desired size of the gradient. 75 * @param size The desired size of the gradient.
74 * @param ca Color a 76 * @param ca Color a
75 * @param cb Color b 77 * @param cb Color b
76 * @param type The type of gradient. 78 * @param type The type of gradient.
77 * @param ncols The number of colors to use when not running on a 79 * @param ncols The number of colors to use when not running on a
78 * truecolor display. The gradient will be dithered to this number of 80 * truecolor display. The gradient will be dithered to this number of
79 * colors. Pass 0 to prevent dithering. 81 * colors. Pass 0 to prevent dithering.
80 */ 82 */
81 static QImage gradient(const QSize &size, const QColor &ca, 83 static QImage gradient(const QSize &size, const QColor &ca,
82 const QColor &cb, GradientType type, int ncols=3); 84 const QColor &cb, GradientType type, int ncols=3);
83 85
84 /** 86 /**
85 * Create an unbalanced gradient. 87 * Create an unbalanced gradient.
86 88
87 * An unbalanced gradient is a gradient where the transition from 89 * An unbalanced gradient is a gradient where the transition from
88 * color a to color b is not linear, but in this case, exponential. 90 * color a to color b is not linear, but in this case, exponential.
89 * 91 *
90 * @param size The desired size of the gradient. 92 * @param size The desired size of the gradient.
91 * @param ca Color a 93 * @param ca Color a
92 * @param cb Color b 94 * @param cb Color b
93 * @param type The type of gradient. 95 * @param type The type of gradient.
94 * @param xfactor The x decay length. Use a value between -200 and 200. 96 * @param xfactor The x decay length. Use a value between -200 and 200.
95 * @param yfactor The y decay length. 97 * @param yfactor The y decay length.
96 * @param ncols The number of colors. See OPixmapEffect:gradient. 98 * @param ncols The number of colors. See OPixmapEffect:gradient.
97 */ 99 */
98 static QImage unbalancedGradient(const QSize &size, const QColor &ca, 100 static QImage unbalancedGradient(const QSize &size, const QColor &ca,
99 const QColor &cb, GradientType type, int xfactor = 100, 101 const QColor &cb, GradientType type, int xfactor = 100,
100 int yfactor = 100, int ncols = 3); 102 int yfactor = 100, int ncols = 3);
101 103
102 /** 104 /**
103 * Blends a color into the destination image, using an opacity 105 * Blends a color into the destination image, using an opacity
104 * value for blending one into another. Very fast direct pixel 106 * value for blending one into another. Very fast direct pixel
105 * manipulation is used. 107 * manipulation is used.
106 * 108 *
107 * @author Karol Szwed (gallium@kde.org) 109 * @author Karol Szwed (gallium@kde.org)
108 * @param clr source color to be blended into the destination image. 110 * @param clr source color to be blended into the destination image.
109 * @param dst destination image in which the source will be blended into. 111 * @param dst destination image in which the source will be blended into.
110 * @param opacity opacity (in percent) which determines how much the source 112 * @param opacity opacity (in percent) which determines how much the source
111 * color will be blended into the destination image. 113 * color will be blended into the destination image.
112 * @return The destination image (dst) containing the result. 114 * @return The destination image (dst) containing the result.
113 */ 115 */
114 static QImage& blend(const QColor& clr, QImage& dst, float opacity); 116 static QImage& blend(const QColor& clr, QImage& dst, float opacity);
115 117
116 /** 118 /**
117 * Blend the src image into the destination image, using an opacity 119 * Blend the src image into the destination image, using an opacity
118 * value for blending one into another. Very fast direct pixel 120 * value for blending one into another. Very fast direct pixel
119 * manipulation is used. 121 * manipulation is used.
120 * 122 *
121 * @author Karol Szwed (gallium@kde.org) 123 * @author Karol Szwed (gallium@kde.org)
122 * @param src source image to be blended into the destination image. 124 * @param src source image to be blended into the destination image.
123 * @param dst destination image in which the source will be blended into. 125 * @param dst destination image in which the source will be blended into.
124 * @param opacity opacity (in percent) which determines how much the source 126 * @param opacity opacity (in percent) which determines how much the source
125 * image will be blended into the destination image. 127 * image will be blended into the destination image.
126 * @return The destination image (dst) containing the result. 128 * @return The destination image (dst) containing the result.
127 */ 129 */
128 static QImage& blend(QImage& src, QImage& dst, float opacity); 130 static QImage& blend(QImage& src, QImage& dst, float opacity);
129 131
130 /** 132 /**
131 * Blend the provided image into a background of the indicated color. 133 * Blend the provided image into a background of the indicated color.
132 * 134 *
133 * @param initial_intensity this parameter takes values from -1 to 1: 135 * @param initial_intensity this parameter takes values from -1 to 1:
134 * a) if positive: how much to fade the image in its 136 * a) if positive: how much to fade the image in its
135 * less affected spot 137 * less affected spot
136 * b) if negative: roughly indicates how much of the image 138 * b) if negative: roughly indicates how much of the image
137 * remains unaffected 139 * remains unaffected
138 * @param bgnd indicates the color of the background to blend in 140 * @param bgnd indicates the color of the background to blend in
139 * @param eff lets you choose what kind of blending you like 141 * @param eff lets you choose what kind of blending you like
140 * @param anti_dir blend in the opposite direction (makes no much sense 142 * @param anti_dir blend in the opposite direction (makes no much sense
141 * with concentric blending effects) 143 * with concentric blending effects)
142 * @param image must be 32bpp 144 * @param image must be 32bpp
143 */ 145 */
144 static QImage& blend(QImage &image, float initial_intensity, 146 static QImage& blend(QImage &image, float initial_intensity,
145 const QColor &bgnd, GradientType eff, 147 const QColor &bgnd, GradientType eff,
146 bool anti_dir=false); 148 bool anti_dir=false);
147 149
148 /** 150 /**
149 * Blend an image into another one, using a gradient type 151 * Blend an image into another one, using a gradient type
150 * for blending from one to another. 152 * for blending from one to another.
151 * 153 *
152 * @param image1 source1 and result of blending 154 * @param image1 source1 and result of blending
153 * @param image2 source2 of blending 155 * @param image2 source2 of blending
154 * @param gt gradient type for blending between source1 and source2 156 * @param gt gradient type for blending between source1 and source2
155 * @param xf x decay length for unbalanced gradient tpye 157 * @param xf x decay length for unbalanced gradient tpye
156 * @param yf y decay length for unbalanced gradient tpye 158 * @param yf y decay length for unbalanced gradient tpye
157 */ 159 */
158 static QImage& blend(QImage &image1,QImage &image2, 160 static QImage& blend(QImage &image1,QImage &image2,
159 GradientType gt, int xf=100, int yf=100); 161 GradientType gt, int xf=100, int yf=100);
160 162
161 /** 163 /**
162 * Blend an image into another one, using a color channel of a 164 * Blend an image into another one, using a color channel of a
163 * third image for the decision of blending from one to another. 165 * third image for the decision of blending from one to another.
164 * 166 *
165 * @param image1 Source 1 and result of blending 167 * @param image1 Source 1 and result of blending
166 * @param image2 Source 2 of blending 168 * @param image2 Source 2 of blending
167 * @param blendImage If the gray value of of pixel is 0, the result 169 * @param blendImage If the gray value of of pixel is 0, the result
168 * for this pixel is that of image1; for a gray value 170 * for this pixel is that of image1; for a gray value
169 * of 1, the pixel of image2 is used; for a value 171 * of 1, the pixel of image2 is used; for a value
170 * inbetween, a corresponding blending is used. 172 * inbetween, a corresponding blending is used.
171 * @param channel The RBG channel to use for the blending decision. 173 * @param channel The RBG channel to use for the blending decision.
172 */ 174 */
173 static QImage& blend(QImage &image1, QImage &image2, 175 static QImage& blend(QImage &image1, QImage &image2,
174 QImage &blendImage, RGBComponent channel); 176 QImage &blendImage, RGBComponent channel);
175 177
176 /** 178 /**
177 * Blend an image into another one, using alpha in the expected way. 179 * Blend an image into another one, using alpha in the expected way.
178 * @author Rik Hemsley (rikkus) <rik@kde.org> 180 * @author Rik Hemsley (rikkus) <rik@kde.org>
179 */ 181 */
180 static bool blend(const QImage & upper, const QImage & lower, QImage & output); 182 static bool blend(const QImage & upper, const QImage & lower, QImage & output);
181// Not yet... static bool blend(const QImage & image1, const QImage & image2, QImage & output, const QRect & destRect); 183// Not yet... static bool blend(const QImage & image1, const QImage & image2, QImage & output, const QRect & destRect);
182 184
183 /** 185 /**
184 * Blend an image into another one, using alpha in the expected way and 186 * Blend an image into another one, using alpha in the expected way and
185 * over coordinates @p x and @p y with respect to the lower image. 187 * over coordinates @p x and @p y with respect to the lower image.
186 * The output is a QImage which is the @p upper image already blended 188 * The output is a QImage which is the @p upper image already blended
187 * with the @p lower one, so its size will be (in general) the same than 189 * with the @p lower one, so its size will be (in general) the same than
188 * @p upper instead of the same size than @p lower like the method above. 190 * @p upper instead of the same size than @p lower like the method above.
189 * In fact, the size of @p output is like upper's one only when it can be 191 * In fact, the size of @p output is like upper's one only when it can be
190 * painted on lower, if there has to be some clipping, output's size will 192 * painted on lower, if there has to be some clipping, output's size will
191 * be the clipped area and x and y will be set to the correct up-left corner 193 * be the clipped area and x and y will be set to the correct up-left corner
192 * where the clipped rectangle begins. 194 * where the clipped rectangle begins.
193 */ 195 */
194 static bool blend(int &x, int &y, const QImage & upper, const QImage & lower, QImage & output); 196 static bool blend(int &x, int &y, const QImage & upper, const QImage & lower, QImage & output);
195 /** 197 /**
196 * Blend an image into another one, using alpha in the expected way and 198 * Blend an image into another one, using alpha in the expected way and
197 * over coordinates @p x and @p y with respect to the lower image. 199 * over coordinates @p x and @p y with respect to the lower image.
198 * The output is painted in the own @p lower image. This is an optimization 200 * The output is painted in the own @p lower image. This is an optimization
199 * of the blend method above provided by convenience. 201 * of the blend method above provided by convenience.
200 */ 202 */
201 static bool blendOnLower(int x, int y, const QImage & upper, const QImage & lower); 203 static bool blendOnLower(int x, int y, const QImage & upper, const QImage & lower);
202 204
203 /** 205 /**
204 * Modifies the intensity of a pixmap's RGB channel component. 206 * Modifies the intensity of a pixmap's RGB channel component.
205 * 207 *
206 * @author Daniel M. Duley (mosfet) 208 * @author Daniel M. Duley (mosfet)
207 * @param image The QImage to process. 209 * @param image The QImage to process.
208 * @param percent Percent value. Use a negative value to dim. 210 * @param percent Percent value. Use a negative value to dim.
209 * @param channel Which channel(s) should be modified 211 * @param channel Which channel(s) should be modified
210 * @return The @p image, provided for convenience. 212 * @return The @p image, provided for convenience.
211 */ 213 */
212 static QImage& channelIntensity(QImage &image, float percent, 214 static QImage& channelIntensity(QImage &image, float percent,
213 RGBComponent channel); 215 RGBComponent channel);
214 216
215 /** 217 /**
216 * Fade an image to a certain background color. 218 * Fade an image to a certain background color.
217 * 219 *
218 * The number of colors will not be changed. 220 * The number of colors will not be changed.
219 * 221 *
220 * @param image The QImage to process. 222 * @param image The QImage to process.
221 * @param val The strength of the effect. 0 <= val <= 1. 223 * @param val The strength of the effect. 0 <= val <= 1.
222 * @param color The background color. 224 * @param color The background color.
223 * @return Returns the @ref image(), provided for convenience. 225 * @return Returns the @ref image(), provided for convenience.
224 */ 226 */
225 static QImage& fade(QImage &img, float val, const QColor &color); 227 static QImage& fade(QImage &img, float val, const QColor &color);
226 228
227 229
228 /** 230 /**
229 * This recolors a pixmap. The most dark color will become color a, 231 * This recolors a pixmap. The most dark color will become color a,
230 * the most bright one color b, and in between. 232 * the most bright one color b, and in between.
231 * 233 *
232 * @param image A QImage to process. 234 * @param image A QImage to process.
233 * @param ca Color a 235 * @param ca Color a
234 * @param cb Color b 236 * @param cb Color b
235 */ 237 */
236 static QImage& flatten(QImage &image, const QColor &ca, 238 static QImage& flatten(QImage &image, const QColor &ca,
237 const QColor &cb, int ncols=0); 239 const QColor &cb, int ncols=0);
238 240
239 /** 241 /**
240 * Build a hash on any given @ref QImage 242 * Build a hash on any given @ref QImage
241 * 243 *
242 * @param image The QImage to process 244 * @param image The QImage to process
243 * @param lite The hash faces the indicated lighting (cardinal poles). 245 * @param lite The hash faces the indicated lighting (cardinal poles).
244 * @param spacing How many unmodified pixels inbetween hashes. 246 * @param spacing How many unmodified pixels inbetween hashes.
245 * @return Returns the @ref image(), provided for convenience. 247 * @return Returns the @ref image(), provided for convenience.
246 */ 248 */
247 static QImage& hash(QImage &image, Lighting lite=NorthLite, 249 static QImage& hash(QImage &image, Lighting lite=NorthLite,
248 unsigned int spacing=0); 250 unsigned int spacing=0);
249 251
250 /** 252 /**
251 * Either brighten or dim the image by a specified percent. 253 * Either brighten or dim the image by a specified percent.
252 * For example, .50 will modify the colors by 50%. 254 * For example, .50 will modify the colors by 50%.
253 * 255 *
254 * @author Daniel M. Duley (mosfet) 256 * @author Daniel M. Duley (mosfet)
255 * @param image The QImage to process. 257 * @param image The QImage to process.
256 * @param percent The percent value. Use a negative value to dim. 258 * @param percent The percent value. Use a negative value to dim.
257 * @return Returns The @ref image(), provided for convenience. 259 * @return Returns The @ref image(), provided for convenience.
258 */ 260 */
259 static QImage& intensity(QImage &image, float percent); 261 static QImage& intensity(QImage &image, float percent);
260 262
261 /** 263 /**
262 * Modulate the image with a color channel of another image. 264 * Modulate the image with a color channel of another image.
263 * 265 *
264 * @param image The QImage to modulate and result. 266 * @param image The QImage to modulate and result.
265 * @param modImage The QImage to use for modulation. 267 * @param modImage The QImage to use for modulation.
266 * @param reverse Invert the meaning of image/modImage; result is image! 268 * @param reverse Invert the meaning of image/modImage; result is image!
267 * @param type The modulation Type to use. 269 * @param type The modulation Type to use.
268 * @param factor The modulation amplitude; with 0 no effect [-200;200]. 270 * @param factor The modulation amplitude; with 0 no effect [-200;200].
269 * @param channel The RBG channel of image2 to use for modulation. 271 * @param channel The RBG channel of image2 to use for modulation.
270 * @return Returns the @ref image(), provided for convenience. 272 * @return Returns the @ref image(), provided for convenience.
271 */ 273 */
272 static QImage& modulate(QImage &image, QImage &modImage, bool reverse, 274 static QImage& modulate(QImage &image, QImage &modImage, bool reverse,
273 ModulationType type, int factor, RGBComponent channel); 275 ModulationType type, int factor, RGBComponent channel);
274 276
275 /** 277 /**
276 * Convert an image to grayscale. 278 * Convert an image to grayscale.
277 * 279 *
278 * @author Daniel M. Duley (mosfet) 280 * @author Daniel M. Duley (mosfet)
279 * @param image The @ref QImage to process. 281 * @param image The @ref QImage to process.
280 * @param fast Set to @p true in order to use a faster but non-photographic 282 * @param fast Set to @p true in order to use a faster but non-photographic
281 * quality algorithm. Appropriate for things such as toolbar icons. 283 * quality algorithm. Appropriate for things such as toolbar icons.
282 * @return Returns the @ref image(), provided for convenience. 284 * @return Returns the @ref image(), provided for convenience.
283 */ 285 */
284 static QImage& toGray(QImage &image, bool fast = false); 286 static QImage& toGray(QImage &image, bool fast = false);
285 287
286 /** 288 /**
287 * Desaturate an image evenly. 289 * Desaturate an image evenly.
288 * 290 *
289 * @param image The QImage to process. 291 * @param image The QImage to process.
290 * @param desat A value between 0 and 1 setting the degree of desaturation 292 * @param desat A value between 0 and 1 setting the degree of desaturation
291 * @return Returns the @ref image(), provided for convenience. 293 * @return Returns the @ref image(), provided for convenience.
292 */ 294 */
293 static QImage& desaturate(QImage &image, float desat = 0.3); 295 static QImage& desaturate(QImage &image, float desat = 0.3);
294 296
295 /** 297 /**
296 * Fast, but low quality contrast of an image. Also see contrastHSV. 298 * Fast, but low quality contrast of an image. Also see contrastHSV.
297 * 299 *
298 * @author Daniel M. Duley (mosfet) 300 * @author Daniel M. Duley (mosfet)
299 * @param image The QImage to process. 301 * @param image The QImage to process.
300 * @param c A contrast value between -255 to 255. 302 * @param c A contrast value between -255 to 255.
301 * @return The @ref image(), provided for convenience. 303 * @return The @ref image(), provided for convenience.
302 */ 304 */
303 static QImage& contrast(QImage &image, int c); 305 static QImage& contrast(QImage &image, int c);
304 306
305 /** 307 /**
306 * Dither an image using Floyd-Steinberg dithering for low-color 308 * Dither an image using Floyd-Steinberg dithering for low-color
307 * situations. 309 * situations.
308 * 310 *
309 * @param image The QImage to process. 311 * @param image The QImage to process.
310 * @param palette The color palette to use 312 * @param palette The color palette to use
311 * @param size The size of the palette 313 * @param size The size of the palette
312 * @return Returns the @ref image(), provided for convenience. 314 * @return Returns the @ref image(), provided for convenience.
313 */ 315 */
314 static QImage& dither(QImage &img, const QColor *palette, int size); 316 static QImage& dither(QImage &img, const QColor *palette, int size);
315 317
316 /** 318 /**
317 * Calculate the image for a selected image, for instance a selected icon 319 * Calculate the image for a selected image, for instance a selected icon
318 * on the desktop. 320 * on the desktop.
319 * @param img the QImage to select 321 * @param img the QImage to select
320 * @param col the selected color, usually from QColorGroup::highlight(). 322 * @param col the selected color, usually from QColorGroup::highlight().
321 */ 323 */
322 static QImage& selectedImage( QImage &img, const QColor &col ); 324 static QImage& selectedImage( QImage &img, const QColor &col );
323 325
324 /** 326 /**
325 * High quality, expensive HSV contrast. You can do a faster one by just 327 * High quality, expensive HSV contrast. You can do a faster one by just
326 * taking a intensity threshold (ie: 128) and incrementing RGB color 328 * taking a intensity threshold (ie: 128) and incrementing RGB color
327 * channels above it and decrementing those below it, but this gives much 329 * channels above it and decrementing those below it, but this gives much
328 * better results. 330 * better results.
329 * 331 *
330 * @author Daniel M. Duley (mosfet) 332 * @author Daniel M. Duley (mosfet)
331 * @param img The QImage to process. 333 * @param img The QImage to process.
332 * @param sharpen If true sharpness is increase, (spiffed). Otherwise 334 * @param sharpen If true sharpness is increase, (spiffed). Otherwise
333 * it is decreased, (dulled). 335 * it is decreased, (dulled).
334 */ 336 */
335 static void contrastHSV(QImage &img, bool sharpen=true); 337 static void contrastHSV(QImage &img, bool sharpen=true);
336 338
337 /** 339 /**
338 * Normalizes the pixel values to span the full range of color values. 340 * Normalizes the pixel values to span the full range of color values.
339 * This is a contrast enhancement technique. 341 * This is a contrast enhancement technique.
340 * @author Daniel M. Duley (mosfet) 342 * @author Daniel M. Duley (mosfet)
341 */ 343 */
342 static void normalize(QImage &img); 344 static void normalize(QImage &img);
343 345
344 /** 346 /**
345 * Performs histogram equalization on the reference 347 * Performs histogram equalization on the reference
346 * image. 348 * image.
347 * @author Daniel M. Duley (mosfet) 349 * @author Daniel M. Duley (mosfet)
348 */ 350 */
349 static void equalize(QImage &img); 351 static void equalize(QImage &img);
350 352
351 /** 353 /**
352 * Thresholds the reference image. You can also threshold images by using 354 * Thresholds the reference image. You can also threshold images by using
353 * ThresholdDither in the various QPixmap/QImage convert methods, but this 355 * ThresholdDither in the various QPixmap/QImage convert methods, but this
354 * lets you specify a threshold value. 356 * lets you specify a threshold value.
355 * 357 *
356 * @author Daniel M. Duley (mosfet) 358 * @author Daniel M. Duley (mosfet)
357 * @param img The QImage to process. 359 * @param img The QImage to process.
358 * @param value The threshold value. 360 * @param value The threshold value.
359 */ 361 */
360 static void threshold(QImage &img, unsigned int value=128); 362 static void threshold(QImage &img, unsigned int value=128);
361 363
362 /** 364 /**
363 * Produces a 'solarization' effect seen when exposing a photographic 365 * Produces a 'solarization' effect seen when exposing a photographic
364 * film to light during the development process. 366 * film to light during the development process.
365 * 367 *
366 * @author Daniel M. Duley (mosfet) 368 * @author Daniel M. Duley (mosfet)
367 * @param img The QImage to process. 369 * @param img The QImage to process.
368 * @param factor The extent of the solarization (0-99.9) 370 * @param factor The extent of the solarization (0-99.9)
369 */ 371 */
370 static void solarize(QImage &img, double factor=50.0); 372 static void solarize(QImage &img, double factor=50.0);
371 373
372 /** 374 /**
373 * Embosses the source image. This involves highlighting the edges 375 * Embosses the source image. This involves highlighting the edges
374 * and applying various other enhancements in order to get a metal 376 * and applying various other enhancements in order to get a metal
375 * effect. 377 * effect.
376 * 378 *
377 * @author Daniel M. Duley (mosfet) 379 * @author Daniel M. Duley (mosfet)
378 * @param src The QImage to process. 380 * @param src The QImage to process.
379 * @return The embossed image. The original is not changed. 381 * @return The embossed image. The original is not changed.
380 */ 382 */
381 static QImage emboss(QImage &src); 383 static QImage emboss(QImage &src);
382 384
383 /** 385 /**
384 * Minimizes speckle noise in the source image using the 8 hull 386 * Minimizes speckle noise in the source image using the 8 hull
385 * algorithm. 387 * algorithm.
386 * 388 *
387 * @author Daniel M. Duley (mosfet) 389 * @author Daniel M. Duley (mosfet)
388 * @param src The QImage to process. 390 * @param src The QImage to process.
389 * @return The despeckled image. The original is not changed. 391 * @return The despeckled image. The original is not changed.
390 */ 392 */
391 static QImage despeckle(QImage &src); 393 static QImage despeckle(QImage &src);
392 394
393 /** 395 /**
394 * Produces a neat little "charcoal" effect. 396 * Produces a neat little "charcoal" effect.
395 * 397 *
396 * @author Daniel M. Duley (mosfet) 398 * @author Daniel M. Duley (mosfet)
397 * @param src The QImage to process. 399 * @param src The QImage to process.
398 * @param factor The factor for detecting lines (0-99.0). 400 * @param factor The factor for detecting lines (0-99.0).
399 * @return The charcoal image. The original is not changed. 401 * @return The charcoal image. The original is not changed.
400 */ 402 */
401 static QImage charcoal(QImage &src, double factor=50.0); 403 static QImage charcoal(QImage &src, double factor=50.0);
402 404
403 /** 405 /**
404 * Rotates the image by the specified amount 406 * Rotates the image by the specified amount
405 * 407 *
406 * @author Daniel M. Duley (mosfet) 408 * @author Daniel M. Duley (mosfet)
407 * @param src The QImage to process. 409 * @param src The QImage to process.
408 * @param r The rotate direction. 410 * @param r The rotate direction.
409 * @return The rotated image. The original is not changed. 411 * @return The rotated image. The original is not changed.
410 */ 412 */
411 static QImage rotate(QImage &src, RotateDirection r); 413 static QImage rotate(QImage &src, RotateDirection r);
412 414
413 /** 415 /**
414 * Scales an image using simple pixel sampling. This does not produce 416 * Scales an image using simple pixel sampling. This does not produce
415 * nearly as nice a result as QImage::smoothScale(), but has the 417 * nearly as nice a result as QImage::smoothScale(), but has the
416 * advantage of being much faster - only a few milliseconds. 418 * advantage of being much faster - only a few milliseconds.
417 * 419 *
418 * @author Daniel M. Duley (mosfet) 420 * @author Daniel M. Duley (mosfet)
419 * @param src The QImage to process. 421 * @param src The QImage to process.
420 * @param w The new width. 422 * @param w The new width.
421 * @param h The new height. 423 * @param h The new height.
422 * @return The scaled image. The original is not changed. 424 * @return The scaled image. The original is not changed.
423 */ 425 */
424 static QImage sample(QImage &src, int w, int h); 426 static QImage sample(QImage &src, int w, int h);
425 427
426 /** 428 /**
427 * Adds noise to an image. 429 * Adds noise to an image.
428 * 430 *
429 * @author Daniel M. Duley (mosfet) 431 * @author Daniel M. Duley (mosfet)
430 * @param src The QImage to process. 432 * @param src The QImage to process.
431 * @param type The algorithm used to generate the noise. 433 * @param type The algorithm used to generate the noise.
432 * @return The image with noise added. The original is not changed. 434 * @return The image with noise added. The original is not changed.
433 */ 435 */
434 static QImage addNoise(QImage &src, NoiseType type = GaussianNoise); 436 static QImage addNoise(QImage &src, NoiseType type = GaussianNoise);
435 437
436 /** 438 /**
437 * Blurs an image by convolving pixel neighborhoods. 439 * Blurs an image by convolving pixel neighborhoods.
438 * 440 *
439 * @author Daniel M. Duley (mosfet) 441 * @author Daniel M. Duley (mosfet)
440 * @param src The QImage to process. 442 * @param src The QImage to process.
441 * @param factor The percent weight to give to the center pixel. 443 * @param factor The percent weight to give to the center pixel.
442 * @return The blurred image. The original is not changed. 444 * @return The blurred image. The original is not changed.
443 */ 445 */
444 static QImage blur(QImage &src, double factor=50.0); 446 static QImage blur(QImage &src, double factor=50.0);
445 447
446 /** 448 /**
447 * Detects edges in an image using pixel neighborhoods and an edge 449 * Detects edges in an image using pixel neighborhoods and an edge
448 * detection mask. 450 * detection mask.
449 * 451 *
450 * @author Daniel M. Duley (mosfet) 452 * @author Daniel M. Duley (mosfet)
451 * @param src The QImage to process. 453 * @param src The QImage to process.
452 * @param factor The percent weight to give to the center pixel. 454 * @param factor The percent weight to give to the center pixel.
453 * @return The image with edges detected. The original is not changed. 455 * @return The image with edges detected. The original is not changed.
454 */ 456 */
455 static QImage edge(QImage &src, double factor=50.0); 457 static QImage edge(QImage &src, double factor=50.0);
456 458
457 /** 459 /**
458 * Implodes an image by a specified percent. 460 * Implodes an image by a specified percent.
459 * 461 *
460 * @author Daniel M. Duley (mosfet) 462 * @author Daniel M. Duley (mosfet)
461 * @param src The QImage to process. 463 * @param src The QImage to process.
462 * @param factor The extent of the implosion. 464 * @param factor The extent of the implosion.
463 * @param background An RGBA value to use for the background. After the 465 * @param background An RGBA value to use for the background. After the
464 * effect some pixels may be "empty". This value is used for those pixels. 466 * effect some pixels may be "empty". This value is used for those pixels.
465 * @return The imploded image. The original is not changed. 467 * @return The imploded image. The original is not changed.
466 */ 468 */
467 static QImage implode(QImage &src, double factor=30.0, 469 static QImage implode(QImage &src, double factor=30.0,
468 unsigned int background = 0xFFFFFFFF); 470 unsigned int background = 0xFFFFFFFF);
469 /** 471 /**
470 * Produces an oil painting effect. 472 * Produces an oil painting effect.
471 * 473 *
472 * @author Daniel M. Duley (mosfet) 474 * @author Daniel M. Duley (mosfet)
473 * @param src The QImage to process. 475 * @param src The QImage to process.
474 * @param radius The radius of the pixel neighborhood used in applying the 476 * @param radius The radius of the pixel neighborhood used in applying the
475 * effect. 477 * effect.
476 * @return The new image. The original is not changed. 478 * @return The new image. The original is not changed.
477 */ 479 */
478 static QImage oilPaint(QImage &src, int radius=3); 480 static QImage oilPaint(QImage &src, int radius=3);
479 481
480 /** 482 /**
481 * Sharpens the pixels in the image using pixel neighborhoods. 483 * Sharpens the pixels in the image using pixel neighborhoods.
482 * 484 *
483 * @author Daniel M. Duley (mosfet) 485 * @author Daniel M. Duley (mosfet)
484 * @param src The QImage to process. 486 * @param src The QImage to process.
485 * @param factor The percent weight to give to the center pixel. 487 * @param factor The percent weight to give to the center pixel.
486 * @return The sharpened image. The original is not changed. 488 * @return The sharpened image. The original is not changed.
487 */ 489 */
488 static QImage sharpen(QImage &src, double factor=30.0); 490 static QImage sharpen(QImage &src, double factor=30.0);
489 491
490 /** 492 /**
491 * Randomly displaces pixels. 493 * Randomly displaces pixels.
492 * 494 *
493 * @author Daniel M. Duley (mosfet) 495 * @author Daniel M. Duley (mosfet)
494 * @param src The QImage to process. 496 * @param src The QImage to process.
495 * @param amount The vicinity for choosing a random pixel to swap. 497 * @param amount The vicinity for choosing a random pixel to swap.
496 * @return The image with pixels displaced. The original is not changed. 498 * @return The image with pixels displaced. The original is not changed.
497 */ 499 */
498 static QImage spread(QImage &src, unsigned int amount=3); 500 static QImage spread(QImage &src, unsigned int amount=3);
499 501
500 /** 502 /**
501 * Shades the image using a distance light source. 503 * Shades the image using a distance light source.
502 * 504 *
503 * @author Daniel M. Duley (mosfet) 505 * @author Daniel M. Duley (mosfet)
504 * @param src The QImage to process. 506 * @param src The QImage to process.
505 * @param color_shading If true do color shading, otherwise do grayscale. 507 * @param color_shading If true do color shading, otherwise do grayscale.
506 * @param azimuth Determines the light source and direction. 508 * @param azimuth Determines the light source and direction.
507 * @param elevation Determines the light source and direction. 509 * @param elevation Determines the light source and direction.
508 * @return The shaded image. The original is not changed. 510 * @return The shaded image. The original is not changed.
509 */ 511 */
510 static QImage shade(QImage &src, bool color_shading=true, double azimuth=30.0, 512 static QImage shade(QImage &src, bool color_shading=true, double azimuth=30.0,
511 double elevation=30.0); 513 double elevation=30.0);
512 /** 514 /**
513 * Swirls the image by a specified amount 515 * Swirls the image by a specified amount
514 * 516 *
515 * @author Daniel M. Duley (mosfet) 517 * @author Daniel M. Duley (mosfet)
516 * @param src The QImage to process. 518 * @param src The QImage to process.
517 * @param degrees The tightness of the swirl. 519 * @param degrees The tightness of the swirl.
518 * @param background An RGBA value to use for the background. After the 520 * @param background An RGBA value to use for the background. After the
519 * effect some pixels may be "empty". This value is used for those pixels. 521 * effect some pixels may be "empty". This value is used for those pixels.
520 * @return The swirled image. The original is not changed. 522 * @return The swirled image. The original is not changed.
521 */ 523 */
522 static QImage swirl(QImage &src, double degrees=50.0, unsigned int background = 524 static QImage swirl(QImage &src, double degrees=50.0, unsigned int background =
523 0xFFFFFFFF); 525 0xFFFFFFFF);
524 526
525 /** 527 /**
526 * Modifies the pixels along a sine wave. 528 * Modifies the pixels along a sine wave.
527 * 529 *
528 * @author Daniel M. Duley (mosfet) 530 * @author Daniel M. Duley (mosfet)
529 * @param src The QImage to process. 531 * @param src The QImage to process.
530 * @param amplitude The amplitude of the sine wave. 532 * @param amplitude The amplitude of the sine wave.
531 * @param wavelength The frequency of the sine wave. 533 * @param wavelength The frequency of the sine wave.
532 * @return The new image. The original is not changed. 534 * @return The new image. The original is not changed.
533 */ 535 */
534 static QImage wave(QImage &src, double amplitude=25.0, double frequency=150.0, 536 static QImage wave(QImage &src, double amplitude=25.0, double frequency=150.0,
535 unsigned int background = 0xFFFFFFFF); 537 unsigned int background = 0xFFFFFFFF);
536 538
537private: 539private:
538 540
539 /** 541 /**
540 * Helper function to fast calc some altered (lighten, shaded) colors 542 * Helper function to fast calc some altered (lighten, shaded) colors
541 * 543 *
542 */ 544 */
543 static unsigned int lHash(unsigned int c); 545 static unsigned int lHash(unsigned int c);
544 static unsigned int uHash(unsigned int c); 546 static unsigned int uHash(unsigned int c);
545 547
546 /** 548 /**
547 * Helper function to find the nearest color to the RBG triplet 549 * Helper function to find the nearest color to the RBG triplet
548 */ 550 */
549 static int nearestColor( int r, int g, int b, const QColor *pal, int size ); 551 static int nearestColor( int r, int g, int b, const QColor *pal, int size );
550 552
551 static void hull(const int x_offset, const int y_offset, const int polarity, 553 static void hull(const int x_offset, const int y_offset, const int polarity,
552 const int width, const int height, 554 const int width, const int height,
553 unsigned int *f, unsigned int *g); 555 unsigned int *f, unsigned int *g);
554 static unsigned int generateNoise(unsigned int pixel, NoiseType type); 556 static unsigned int generateNoise(unsigned int pixel, NoiseType type);
555 static unsigned int interpolateColor(QImage *image, double x, double y, 557 static unsigned int interpolateColor(QImage *image, double x, double y,
556 unsigned int background); 558 unsigned int background);
557}; 559};
558 560
561}
562}
563
559#endif 564#endif
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp
index 0ee2fde..38670b4 100644
--- a/libopie2/opieui/olistview.cpp
+++ b/libopie2/opieui/olistview.cpp
@@ -1,757 +1,764 @@
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
39using namespace Opie::Core;
40
41
42namespace Opie {
43namespace Ui {
39/*====================================================================================== 44/*======================================================================================
40 * OListView 45 * OListView
41 *======================================================================================*/ 46 *======================================================================================*/
42 47
43OListView::OListView( QWidget *parent, const char *name ) 48OListView::OListView( QWidget *parent, const char *name )
44 :QListView( parent, name ) 49 :QListView( parent, name )
45{ 50{
46 //FIXME: get from global settings and calculate ==> see oglobalsettings.* 51 //FIXME: get from global settings and calculate ==> see oglobalsettings.*
47 52
48 m_alternateBackground = QColor( 238, 246, 255 ); 53 m_alternateBackground = QColor( 238, 246, 255 );
49 m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); 54 m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine );
50 m_fullWidth = true; 55 m_fullWidth = true;
51 connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*))); 56 connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*)));
52} 57}
53 58
54OListView::~OListView() 59OListView::~OListView()
55{ 60{
56} 61}
57 62
58void OListView::setFullWidth( bool fullWidth ) 63void OListView::setFullWidth( bool fullWidth )
59{ 64{
60 m_fullWidth = m_fullWidth; 65 m_fullWidth = m_fullWidth;
61 #if QT_VERSION > 290 66 #if QT_VERSION > 290
62 header()->setStretchEnabled( fullWidth, columns()-1 ); 67 header()->setStretchEnabled( fullWidth, columns()-1 );
63 #endif 68 #endif
64} 69}
65 70
66bool OListView::fullWidth() const 71bool OListView::fullWidth() const
67{ 72{
68 return m_fullWidth; 73 return m_fullWidth;
69} 74}
70 75
71int OListView::addColumn( const QString& label, int width ) 76int OListView::addColumn( const QString& label, int width )
72{ 77{
73 int result = QListView::addColumn( label, width ); 78 int result = QListView::addColumn( label, width );
74 #if QT_VERSION > 290 79 #if QT_VERSION > 290
75 if (m_fullWidth) { 80 if (m_fullWidth) {
76 header()->setStretchEnabled( false, columns()-2 ); 81 header()->setStretchEnabled( false, columns()-2 );
77 header()->setStretchEnabled( true, columns()-1 ); 82 header()->setStretchEnabled( true, columns()-1 );
78 } 83 }
79 #endif 84 #endif
80 return result; 85 return result;
81} 86}
82 87
83int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) 88int OListView::addColumn( const QIconSet& iconset, const QString& label, int width )
84{ 89{
85 int result = QListView::addColumn( iconset, label, width ); 90 int result = QListView::addColumn( iconset, label, width );
86 #if QT_VERSION > 290 91 #if QT_VERSION > 290
87 if (m_fullWidth) { 92 if (m_fullWidth) {
88 header()->setStretchEnabled( false, columns()-2 ); 93 header()->setStretchEnabled( false, columns()-2 );
89 header()->setStretchEnabled( true, columns()-1 ); 94 header()->setStretchEnabled( true, columns()-1 );
90 } 95 }
91 #endif 96 #endif
92 return result; 97 return result;
93} 98}
94 99
95void OListView::removeColumn( int index ) 100void OListView::removeColumn( int index )
96{ 101{
97 QListView::removeColumn(index); 102 QListView::removeColumn(index);
98 #if QT_VERSION > 290 103 #if QT_VERSION > 290
99 if ( m_fullWidth && index == columns() ) 104 if ( m_fullWidth && index == columns() )
100 { 105 {
101 header()->setStretchEnabled( true, columns()-1 ); 106 header()->setStretchEnabled( true, columns()-1 );
102 } 107 }
103 #endif 108 #endif
104} 109}
105 110
106const QColor& OListView::alternateBackground() const 111const QColor& OListView::alternateBackground() const
107{ 112{
108 return m_alternateBackground; 113 return m_alternateBackground;
109} 114}
110 115
111void OListView::setAlternateBackground( const QColor &c ) 116void OListView::setAlternateBackground( const QColor &c )
112{ 117{
113 m_alternateBackground = c; 118 m_alternateBackground = c;
114 repaint(); 119 repaint();
115} 120}
116 121
117const QPen& OListView::columnSeparator() const 122const QPen& OListView::columnSeparator() const
118{ 123{
119 return m_columnSeparator; 124 return m_columnSeparator;
120} 125}
121 126
122void OListView::setColumnSeparator( const QPen& p ) 127void OListView::setColumnSeparator( const QPen& p )
123{ 128{
124 m_columnSeparator = p; 129 m_columnSeparator = p;
125 repaint(); 130 repaint();
126} 131}
127 132
128void OListView::expand(QListViewItem *item) 133void OListView::expand(QListViewItem *item)
129{ 134{
130 ((OListViewItem*)item)->expand(); 135 ((OListViewItem*)item)->expand();
131} 136}
132 137
133OListViewItem* OListView::childFactory() 138OListViewItem* OListView::childFactory()
134{ 139{
135 return new OListViewItem( this ); 140 return new OListViewItem( this );
136} 141}
137 142
138#ifndef QT_NO_DATASTREAM 143#ifndef QT_NO_DATASTREAM
139void OListView::serializeTo( QDataStream& s ) const 144void OListView::serializeTo( QDataStream& s ) const
140{ 145{
141 #warning Caution... the binary format is still under construction... 146 #warning Caution... the binary format is still under construction...
142 odebug << "storing OListView..." << oendl; 147 odebug << "storing OListView..." << oendl;
143 148
144 // store number of columns and the labels 149 // store number of columns and the labels
145 s << columns(); 150 s << columns();
146 for ( int i = 0; i < columns(); ++i ) 151 for ( int i = 0; i < columns(); ++i )
147 s << columnText( i ); 152 s << columnText( i );
148 153
149 // calculate the number of top-level items to serialize 154 // calculate the number of top-level items to serialize
150 int items = 0; 155 int items = 0;
151 QListViewItem* item = firstChild(); 156 QListViewItem* item = firstChild();
152 while ( item ) 157 while ( item )
153 { 158 {
154 item = item->nextSibling(); 159 item = item->nextSibling();
155 items++; 160 items++;
156 } 161 }
157 162
158 // store number of items and the items itself 163 // store number of items and the items itself
159 s << items; 164 s << items;
160 item = firstChild(); 165 item = firstChild();
161 for ( int i = 0; i < items; ++i ) 166 for ( int i = 0; i < items; ++i )
162 { 167 {
163 s << *static_cast<OListViewItem*>( item ); 168 s << *static_cast<OListViewItem*>( item );
164 item = item->nextSibling(); 169 item = item->nextSibling();
165 } 170 }
166 171
167 odebug << "OListview stored." << oendl; 172 odebug << "OListview stored." << oendl;
168} 173}
169 174
170void OListView::serializeFrom( QDataStream& s ) 175void OListView::serializeFrom( QDataStream& s )
171{ 176{
172 #warning Caution... the binary format is still under construction... 177 #warning Caution... the binary format is still under construction...
173 odebug << "loading OListView..." << oendl; 178 odebug << "loading OListView..." << oendl;
174 179
175 int cols; 180 int cols;
176 s >> cols; 181 s >> cols;
177 odebug << "read number of columns = " << cols << oendl; 182 odebug << "read number of columns = " << cols << oendl;
178 183
179 while ( columns() < cols ) addColumn( QString::null ); 184 while ( columns() < cols ) addColumn( QString::null );
180 185
181 for ( int i = 0; i < cols; ++i ) 186 for ( int i = 0; i < cols; ++i )
182 { 187 {
183 QString coltext; 188 QString coltext;
184 s >> coltext; 189 s >> coltext;
185 qDebug( "read text '%s' for column %d", (const char*) coltext, i ); 190 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
186 setColumnText( i, coltext ); 191 setColumnText( i, coltext );
187 } 192 }
188 193
189 int items; 194 int items;
190 s >> items; 195 s >> items;
191 odebug << "read number of items = " << items << oendl; 196 odebug << "read number of items = " << items << oendl;
192 197
193 for ( int i = 0; i < items; ++i ) 198 for ( int i = 0; i < items; ++i )
194 { 199 {
195 OListViewItem* item = childFactory(); 200 OListViewItem* item = childFactory();
196 s >> *item; 201 s >> *item;
197 } 202 }
198 203
199 odebug << "OListView loaded." << oendl; 204 odebug << "OListView loaded." << oendl;
200 205
201} 206}
202 207
203 208
204void OListView::expand() 209void OListView::expand()
205{ 210{
206 odebug << "OListView::expand" << oendl; 211 odebug << "OListView::expand" << oendl;
207 212
208 QListViewItemIterator it( this ); 213 QListViewItemIterator it( this );
209 while ( it.current() ) { 214 while ( it.current() ) {
210 it.current()->setOpen( true ); 215 it.current()->setOpen( true );
211 ++it; 216 ++it;
212 } 217 }
213} 218}
214 219
215 220
216void OListView::collapse() 221void OListView::collapse()
217{ 222{
218 odebug << "OListView::collapse" << oendl; 223 odebug << "OListView::collapse" << oendl;
219 QListViewItemIterator it( this ); 224 QListViewItemIterator it( this );
220 while ( it.current() ) { 225 while ( it.current() ) {
221 it.current()->setOpen( false ); 226 it.current()->setOpen( false );
222 ++it; 227 ++it;
223 } 228 }
224} 229}
225 230
226 231
227QDataStream& operator<<( QDataStream& s, const OListView& lv ) 232QDataStream& operator<<( QDataStream& s, const OListView& lv )
228{ 233{
229 lv.serializeTo( s ); 234 lv.serializeTo( s );
230} 235}
231 236
232QDataStream& operator>>( QDataStream& s, OListView& lv ) 237QDataStream& operator>>( QDataStream& s, OListView& lv )
233{ 238{
234 lv.serializeFrom( s ); 239 lv.serializeFrom( s );
235} 240}
236#endif // QT_NO_DATASTREAM 241#endif // QT_NO_DATASTREAM
237 242
238/*====================================================================================== 243/*======================================================================================
239 * OListViewItem 244 * OListViewItem
240 *======================================================================================*/ 245 *======================================================================================*/
241 246
242OListViewItem::OListViewItem(QListView *parent) 247OListViewItem::OListViewItem(QListView *parent)
243 : QListViewItem(parent) 248 : QListViewItem(parent)
244{ 249{
245 init(); 250 init();
246} 251}
247 252
248 253
249OListViewItem::OListViewItem(QListViewItem *parent) 254OListViewItem::OListViewItem(QListViewItem *parent)
250 : QListViewItem(parent) 255 : QListViewItem(parent)
251{ 256{
252 init(); 257 init();
253} 258}
254 259
255 260
256OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) 261OListViewItem::OListViewItem(QListView *parent, QListViewItem *after)
257 : QListViewItem(parent, after) 262 : QListViewItem(parent, after)
258{ 263{
259 init(); 264 init();
260} 265}
261 266
262 267
263OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) 268OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after)
264 : QListViewItem(parent, after) 269 : QListViewItem(parent, after)
265{ 270{
266 init(); 271 init();
267} 272}
268 273
269 274
270OListViewItem::OListViewItem(QListView *parent, 275OListViewItem::OListViewItem(QListView *parent,
271 QString label1, QString label2, QString label3, QString label4, 276 QString label1, QString label2, QString label3, QString label4,
272 QString label5, QString label6, QString label7, QString label8) 277 QString label5, QString label6, QString label7, QString label8)
273 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 278 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
274{ 279{
275 init(); 280 init();
276} 281}
277 282
278 283
279OListViewItem::OListViewItem(QListViewItem *parent, 284OListViewItem::OListViewItem(QListViewItem *parent,
280 QString label1, QString label2, QString label3, QString label4, 285 QString label1, QString label2, QString label3, QString label4,
281 QString label5, QString label6, QString label7, QString label8) 286 QString label5, QString label6, QString label7, QString label8)
282 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 287 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
283{ 288{
284 init(); 289 init();
285} 290}
286 291
287 292
288OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, 293OListViewItem::OListViewItem(QListView *parent, QListViewItem *after,
289 QString label1, QString label2, QString label3, QString label4, 294 QString label1, QString label2, QString label3, QString label4,
290 QString label5, QString label6, QString label7, QString label8) 295 QString label5, QString label6, QString label7, QString label8)
291 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) 296 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
292{ 297{
293 init(); 298 init();
294} 299}
295 300
296 301
297OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, 302OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after,
298 QString label1, QString label2, QString label3, QString label4, 303 QString label1, QString label2, QString label3, QString label4,
299 QString label5, QString label6, QString label7, QString label8) 304 QString label5, QString label6, QString label7, QString label8)
300 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) 305 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
301{ 306{
302 init(); 307 init();
303} 308}
304 309
305 310
306OListViewItem::~OListViewItem() 311OListViewItem::~OListViewItem()
307{ 312{
308} 313}
309 314
310 315
311void OListViewItem::init() 316void OListViewItem::init()
312{ 317{
313 m_known = false; 318 m_known = false;
314} 319}
315 320
316 321
317const QColor &OListViewItem::backgroundColor() 322const QColor &OListViewItem::backgroundColor()
318{ 323{
319 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : 324 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
320 listView()->viewport()->colorGroup().base(); 325 listView()->viewport()->colorGroup().base();
321} 326}
322 327
323 328
324bool OListViewItem::isAlternate() 329bool OListViewItem::isAlternate()
325{ 330{
326 OListView *lv = static_cast<OListView*>( listView() ); 331 OListView *lv = static_cast<OListView*>( listView() );
327 332
328 // check if the item above is an OListViewItem 333 // check if the item above is an OListViewItem
329 OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); 334 OListViewItem *above = static_cast<OListViewItem*>( itemAbove() );
330 /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ 335 /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/
331 336
332 // check if we have a valid alternate background color 337 // check if we have a valid alternate background color
333 if (!(lv && lv->alternateBackground().isValid())) return false; 338 if (!(lv && lv->alternateBackground().isValid())) return false;
334 339
335 m_known = above ? above->m_known : true; 340 m_known = above ? above->m_known : true;
336 if (m_known) 341 if (m_known)
337 { 342 {
338 m_odd = above ? !above->m_odd : false; 343 m_odd = above ? !above->m_odd : false;
339 } 344 }
340 else 345 else
341 { 346 {
342 OListViewItem *item; 347 OListViewItem *item;
343 bool previous = true; 348 bool previous = true;
344 if (parent()) 349 if (parent())
345 { 350 {
346 item = static_cast<OListViewItem *>(parent()); 351 item = static_cast<OListViewItem *>(parent());
347 if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; 352 if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd;
348 item = static_cast<OListViewItem *>(parent()->firstChild()); 353 item = static_cast<OListViewItem *>(parent()->firstChild());
349 /* if ( !item.inherits( "OListViewItem" ) item = 0; */ 354 /* if ( !item.inherits( "OListViewItem" ) item = 0; */
350 } 355 }
351 else 356 else
352 { 357 {
353 item = static_cast<OListViewItem *>(lv->firstChild()); 358 item = static_cast<OListViewItem *>(lv->firstChild());
354 } 359 }
355 360
356 while(item) 361 while(item)
357 { 362 {
358 item->m_odd = previous = !previous; 363 item->m_odd = previous = !previous;
359 item->m_known = true; 364 item->m_known = true;
360 item = static_cast<OListViewItem *>(item->nextSibling()); 365 item = static_cast<OListViewItem *>(item->nextSibling());
361 /* if (!item.inherits( "OListViewItem" ) ) break; */ 366 /* if (!item.inherits( "OListViewItem" ) ) break; */
362 } 367 }
363 } 368 }
364 return m_odd; 369 return m_odd;
365} 370}
366 371
367 372
368void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 373void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
369{ 374{
370 QColorGroup _cg = cg; 375 QColorGroup _cg = cg;
371 const QPixmap *pm = listView()->viewport()->backgroundPixmap(); 376 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
372 if (pm && !pm->isNull()) 377 if (pm && !pm->isNull())
373 { 378 {
374 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); 379 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
375 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); 380 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
376 } 381 }
377 else if ( isAlternate() ) 382 else if ( isAlternate() )
378 { 383 {
379 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); 384 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
380 } 385 }
381 QListViewItem::paintCell( p, _cg, column, width, alignment ); 386 QListViewItem::paintCell( p, _cg, column, width, alignment );
382 387
383 //FIXME: Use styling here! 388 //FIXME: Use styling here!
384 389
385 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); 390 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
386 p->setPen( pen ); 391 p->setPen( pen );
387 p->drawLine( width-1, 0, width-1, height() ); 392 p->drawLine( width-1, 0, width-1, height() );
388} 393}
389 394
390 395
391OListViewItem* OListViewItem::childFactory() 396OListViewItem* OListViewItem::childFactory()
392{ 397{
393 return new OListViewItem( this ); 398 return new OListViewItem( this );
394} 399}
395 400
396 401
397#ifndef QT_NO_DATASTREAM 402#ifndef QT_NO_DATASTREAM
398void OListViewItem::serializeTo( QDataStream& s ) const 403void OListViewItem::serializeTo( QDataStream& s ) const
399{ 404{
400 #warning Caution... the binary format is still under construction... 405 #warning Caution... the binary format is still under construction...
401 odebug << "storing OListViewItem..." << oendl; 406 odebug << "storing OListViewItem..." << oendl;
402 407
403 // store item text 408 // store item text
404 for ( int i = 0; i < listView()->columns(); ++i ) 409 for ( int i = 0; i < listView()->columns(); ++i )
405 { 410 {
406 s << text( i ); 411 s << text( i );
407 } 412 }
408 413
409 // calculate the number of children to serialize 414 // calculate the number of children to serialize
410 int items = 0; 415 int items = 0;
411 QListViewItem* item = firstChild(); 416 QListViewItem* item = firstChild();
412 while ( item ) 417 while ( item )
413 { 418 {
414 item = item->nextSibling(); 419 item = item->nextSibling();
415 items++; 420 items++;
416 } 421 }
417 422
418 // store number of items and the items itself 423 // store number of items and the items itself
419 s << items; 424 s << items;
420 item = firstChild(); 425 item = firstChild();
421 for ( int i = 0; i < items; ++i ) 426 for ( int i = 0; i < items; ++i )
422 { 427 {
423 s << *static_cast<OListViewItem*>( item ); 428 s << *static_cast<OListViewItem*>( item );
424 item = item->nextSibling(); 429 item = item->nextSibling();
425 } 430 }
426 431
427 odebug << "OListviewItem stored." << oendl; 432 odebug << "OListviewItem stored." << oendl;
428} 433}
429 434
430 435
431void OListViewItem::serializeFrom( QDataStream& s ) 436void OListViewItem::serializeFrom( QDataStream& s )
432{ 437{
433 #warning Caution... the binary format is still under construction... 438 #warning Caution... the binary format is still under construction...
434 odebug << "loading OListViewItem..." << oendl; 439 odebug << "loading OListViewItem..." << oendl;
435 440
436 for ( int i = 0; i < listView()->columns(); ++i ) 441 for ( int i = 0; i < listView()->columns(); ++i )
437 { 442 {
438 QString coltext; 443 QString coltext;
439 s >> coltext; 444 s >> coltext;
440 qDebug( "read text '%s' for column %d", (const char*) coltext, i ); 445 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
441 setText( i, coltext ); 446 setText( i, coltext );
442 } 447 }
443 448
444 int items; 449 int items;
445 s >> items; 450 s >> items;
446 qDebug( "read number of items = %d", items ); 451 qDebug( "read number of items = %d", items );
447 452
448 for ( int i = 0; i < items; ++i ) 453 for ( int i = 0; i < items; ++i )
449 { 454 {
450 OListViewItem* item = childFactory(); 455 OListViewItem* item = childFactory();
451 s >> (*item); 456 s >> (*item);
452 } 457 }
453 458
454 odebug << "OListViewItem loaded." << oendl; 459 odebug << "OListViewItem loaded." << oendl;
455} 460}
456 461
457 462
458QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) 463QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi )
459{ 464{
460 lvi.serializeTo( s ); 465 lvi.serializeTo( s );
461} 466}
462 467
463 468
464QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) 469QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
465{ 470{
466 lvi.serializeFrom( s ); 471 lvi.serializeFrom( s );
467} 472}
468#endif // QT_NO_DATASTREAM 473#endif // QT_NO_DATASTREAM
469 474
470 475
471/*====================================================================================== 476/*======================================================================================
472 * OCheckListItem 477 * OCheckListItem
473 *======================================================================================*/ 478 *======================================================================================*/
474 479
475OCheckListItem::OCheckListItem( QCheckListItem* parent, const QString& text, Type t ) 480OCheckListItem::OCheckListItem( QCheckListItem* parent, const QString& text, Type t )
476 :QCheckListItem( parent, text, t ) 481 :QCheckListItem( parent, text, t )
477{ 482{
478 init(); 483 init();
479} 484}
480 485
481 486
482OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, Type t) 487OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, Type t)
483 :QCheckListItem( parent, text, t ) 488 :QCheckListItem( parent, text, t )
484{ 489{
485 init(); 490 init();
486} 491}
487 492
488 493
489OCheckListItem::OCheckListItem( QListView* parent, const QString& text, Type t ) 494OCheckListItem::OCheckListItem( QListView* parent, const QString& text, Type t )
490 :QCheckListItem( parent, text, t ) 495 :QCheckListItem( parent, text, t )
491{ 496{
492 init(); 497 init();
493} 498}
494 499
495 500
496OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, const QPixmap& p ) 501OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, const QPixmap& p )
497 :QCheckListItem( parent, text, p ) 502 :QCheckListItem( parent, text, p )
498{ 503{
499 init(); 504 init();
500} 505}
501 506
502 507
503OCheckListItem::OCheckListItem( QListView* parent, const QString& text, const QPixmap& p ) 508OCheckListItem::OCheckListItem( QListView* parent, const QString& text, const QPixmap& p )
504 :QCheckListItem( parent, text, p ) 509 :QCheckListItem( parent, text, p )
505{ 510{
506 init(); 511 init();
507} 512}
508 513
509 514
510OCheckListItem::~OCheckListItem() 515OCheckListItem::~OCheckListItem()
511{ 516{
512} 517}
513 518
514void OCheckListItem::init() 519void OCheckListItem::init()
515{ 520{
516 m_known = false; 521 m_known = false;
517} 522}
518 523
519 524
520const QColor &OCheckListItem::backgroundColor() 525const QColor &OCheckListItem::backgroundColor()
521{ 526{
522 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : 527 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
523 listView()->viewport()->colorGroup().base(); 528 listView()->viewport()->colorGroup().base();
524} 529}
525 530
526 531
527bool OCheckListItem::isAlternate() 532bool OCheckListItem::isAlternate()
528{ 533{
529 OListView *lv = static_cast<OListView*>( listView() ); 534 OListView *lv = static_cast<OListView*>( listView() );
530 535
531 // check if the item above is an OCheckListItem 536 // check if the item above is an OCheckListItem
532 OCheckListItem *above = static_cast<OCheckListItem*>( itemAbove() ); 537 OCheckListItem *above = static_cast<OCheckListItem*>( itemAbove() );
533 /*if (! itemAbove()->inherits( "OCheckListItem" )) return false;*/ 538 /*if (! itemAbove()->inherits( "OCheckListItem" )) return false;*/
534 539
535 // check if we have a valid alternate background color 540 // check if we have a valid alternate background color
536 if (!(lv && lv->alternateBackground().isValid())) return false; 541 if (!(lv && lv->alternateBackground().isValid())) return false;
537 542
538 m_known = above ? above->m_known : true; 543 m_known = above ? above->m_known : true;
539 if (m_known) 544 if (m_known)
540 { 545 {
541 m_odd = above ? !above->m_odd : false; 546 m_odd = above ? !above->m_odd : false;
542 } 547 }
543 else 548 else
544 { 549 {
545 OCheckListItem *item; 550 OCheckListItem *item;
546 bool previous = true; 551 bool previous = true;
547 if (parent()) 552 if (parent())
548 { 553 {
549 item = static_cast<OCheckListItem *>(parent()); 554 item = static_cast<OCheckListItem *>(parent());
550 if ( item /*&& item->inherits( "OCheckListItem" )*/ ) previous = item->m_odd; 555 if ( item /*&& item->inherits( "OCheckListItem" )*/ ) previous = item->m_odd;
551 item = static_cast<OCheckListItem *>(parent()->firstChild()); 556 item = static_cast<OCheckListItem *>(parent()->firstChild());
552 /* if ( !item.inherits( "OCheckListItem" ) item = 0; */ 557 /* if ( !item.inherits( "OCheckListItem" ) item = 0; */
553 } 558 }
554 else 559 else
555 { 560 {
556 item = static_cast<OCheckListItem *>(lv->firstChild()); 561 item = static_cast<OCheckListItem *>(lv->firstChild());
557 } 562 }
558 563
559 while(item) 564 while(item)
560 { 565 {
561 item->m_odd = previous = !previous; 566 item->m_odd = previous = !previous;
562 item->m_known = true; 567 item->m_known = true;
563 item = static_cast<OCheckListItem *>(item->nextSibling()); 568 item = static_cast<OCheckListItem *>(item->nextSibling());
564 /* if (!item.inherits( "OCheckListItem" ) ) break; */ 569 /* if (!item.inherits( "OCheckListItem" ) ) break; */
565 } 570 }
566 } 571 }
567 return m_odd; 572 return m_odd;
568} 573}
569 574
570 575
571void OCheckListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 576void OCheckListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
572{ 577{
573 QColorGroup _cg = cg; 578 QColorGroup _cg = cg;
574 const QPixmap *pm = listView()->viewport()->backgroundPixmap(); 579 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
575 if (pm && !pm->isNull()) 580 if (pm && !pm->isNull())
576 { 581 {
577 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); 582 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
578 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); 583 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
579 } 584 }
580 else if ( isAlternate() ) 585 else if ( isAlternate() )
581 { 586 {
582 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); 587 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
583 } 588 }
584 QCheckListItem::paintCell( p, _cg, column, width, alignment ); 589 QCheckListItem::paintCell( p, _cg, column, width, alignment );
585 590
586 //FIXME: Use styling here! 591 //FIXME: Use styling here!
587 592
588 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); 593 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
589 p->setPen( pen ); 594 p->setPen( pen );
590 p->drawLine( width-1, 0, width-1, height() ); 595 p->drawLine( width-1, 0, width-1, height() );
591} 596}
592 597
593 598
594/*====================================================================================== 599/*======================================================================================
595 * ONamedListView 600 * ONamedListView
596 *======================================================================================*/ 601 *======================================================================================*/
597 602
598ONamedListView::ONamedListView( QWidget *parent, const char *name ) 603ONamedListView::ONamedListView( QWidget *parent, const char *name )
599 :OListView( parent, name ) 604 :OListView( parent, name )
600{ 605{
601} 606}
602 607
603 608
604ONamedListView::~ONamedListView() 609ONamedListView::~ONamedListView()
605{ 610{
606} 611}
607 612
608 613
609void ONamedListView::addColumns( const QStringList& columns ) 614void ONamedListView::addColumns( const QStringList& columns )
610{ 615{
611 for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) 616 for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it )
612 { 617 {
613 qDebug( "adding column %s", (const char*) *it ); 618 qDebug( "adding column %s", (const char*) *it );
614 addColumn( *it ); 619 addColumn( *it );
615 } 620 }
616} 621}
617 622
618 623
619int ONamedListView::findColumn( const QString& text ) const 624int ONamedListView::findColumn( const QString& text ) const
620{ 625{
621 //FIXME: If used excessively, this will slow down performance of updates 626 //FIXME: If used excessively, this will slow down performance of updates
622 //FIXME: because of the linear search over all column texts. 627 //FIXME: because of the linear search over all column texts.
623 //FIXME: I will optimize later by using a hash map. 628 //FIXME: I will optimize later by using a hash map.
624 for ( int i = 0; i < columns(); ++i ) 629 for ( int i = 0; i < columns(); ++i )
625 if ( columnText( i ) == text ) 630 if ( columnText( i ) == text )
626 return i; 631 return i;
627 return -1; 632 return -1;
628} 633}
629 634
630 635
631ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const 636ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const
632{ 637{
633 return find( (ONamedListViewItem*) firstChild(), column, text, recurse ); 638 return find( (ONamedListViewItem*) firstChild(), column, text, recurse );
634} 639}
635 640
636 641
637ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const 642ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const
638{ 643{
639 ONamedListViewItem* result; 644 ONamedListViewItem* result;
640 while ( item && item->text( column ) != text ) 645 while ( item && item->text( column ) != text )
641 { 646 {
642 qDebug( "checked %s", (const char*) item->text( column ) ); 647 qDebug( "checked %s", (const char*) item->text( column ) );
643 648
644 if ( recurse < 0 || recurse > 0 ) 649 if ( recurse < 0 || recurse > 0 )
645 { 650 {
646 qDebug( "recursion is %d - recursing into...", recurse ); 651 qDebug( "recursion is %d - recursing into...", recurse );
647 result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 ); 652 result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 );
648 if ( result ) return result; 653 if ( result ) return result;
649 } 654 }
650 655
651 656
652 item = (ONamedListViewItem*) item->itemBelow(); 657 item = (ONamedListViewItem*) item->itemBelow();
653 } 658 }
654 if ( item && item->text( column ) == text ) 659 if ( item && item->text( column ) == text )
655 return item; 660 return item;
656 else 661 else
657 return 0; 662 return 0;
658} 663}
659 664
660 665
661ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const 666ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const
662{ 667{
663 int col = findColumn( column ); 668 int col = findColumn( column );
664 if ( col != -1 ) 669 if ( col != -1 )
665 return find( (ONamedListViewItem*) firstChild(), col, text, recurse ); 670 return find( (ONamedListViewItem*) firstChild(), col, text, recurse );
666 else 671 else
667 return 0; 672 return 0;
668} 673}
669 674
670 675
671ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const 676ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const
672{ 677{
673 int col = findColumn( column ); 678 int col = findColumn( column );
674 if ( col != -1 ) 679 if ( col != -1 )
675 return find( item, col, text, recurse ); 680 return find( item, col, text, recurse );
676 else 681 else
677 return 0; 682 return 0;
678} 683}
679 684
680 685
681/*====================================================================================== 686/*======================================================================================
682 * ONamedListViewItem 687 * ONamedListViewItem
683 *======================================================================================*/ 688 *======================================================================================*/
684 689
685ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) 690ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts )
686 :OListViewItem( parent ) 691 :OListViewItem( parent )
687{ 692{
688 setText( texts ); 693 setText( texts );
689} 694}
690 695
691 696
692ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) 697ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts )
693 :OListViewItem( parent ) 698 :OListViewItem( parent )
694{ 699{
695 setText( texts ); 700 setText( texts );
696} 701}
697 702
698 703
699ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) 704ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts )
700 :OListViewItem( parent, after ) 705 :OListViewItem( parent, after )
701{ 706{
702 setText( texts ); 707 setText( texts );
703} 708}
704 709
705 710
706ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) 711ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts )
707 :OListViewItem( parent, after ) 712 :OListViewItem( parent, after )
708{ 713{
709 setText( texts ); 714 setText( texts );
710} 715}
711 716
712 717
713ONamedListViewItem::~ONamedListViewItem() 718ONamedListViewItem::~ONamedListViewItem()
714{ 719{
715} 720}
716 721
717 722
718void ONamedListViewItem::setText( const QStringList& texts ) 723void ONamedListViewItem::setText( const QStringList& texts )
719{ 724{
720 int col = 0; 725 int col = 0;
721 for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) 726 for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it )
722 { 727 {
723 qDebug( "setting column %d = text %s", col, (const char*) *it ); 728 qDebug( "setting column %d = text %s", col, (const char*) *it );
724 OListViewItem::setText( col++, *it ); 729 OListViewItem::setText( col++, *it );
725 } 730 }
726 731
727} 732}
728 733
729 734
730void ONamedListViewItem::setText( const QString& column, const QString& text ) 735void ONamedListViewItem::setText( const QString& column, const QString& text )
731{ 736{
732 //FIXME: If used excessively, this will slow down performance of updates 737 //FIXME: If used excessively, this will slow down performance of updates
733 //FIXME: because of the linear search over all column texts. 738 //FIXME: because of the linear search over all column texts.
734 //FIXME: I will optimize later by using a hash map. 739 //FIXME: I will optimize later by using a hash map.
735 int col = ( (ONamedListView*) listView() )->findColumn( column ); 740 int col = ( (ONamedListView*) listView() )->findColumn( column );
736 if ( col != -1 ) 741 if ( col != -1 )
737 OListViewItem::setText( col, text ); 742 OListViewItem::setText( col, text );
738 else 743 else
739 qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); 744 qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column );
740} 745}
741 746
742 747
743ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const 748ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const
744{ 749{
745 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse ); 750 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse );
746} 751}
747 752
748 753
749ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const 754ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const
750{ 755{
751 int col = ( (ONamedListView*) listView() )->findColumn( column ); 756 int col = ( (ONamedListView*) listView() )->findColumn( column );
752 if ( col != -1 ) 757 if ( col != -1 )
753 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse ); 758 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse );
754 else 759 else
755 return 0; 760 return 0;
756} 761}
757 762
763}
764}
diff --git a/libopie2/opieui/olistview.h b/libopie2/opieui/olistview.h
index 59b0973..8195a62 100644
--- a/libopie2/opieui/olistview.h
+++ b/libopie2/opieui/olistview.h
@@ -1,409 +1,426 @@
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#ifndef OLISTVIEW_H 30#ifndef OLISTVIEW_H
31#define OLISTVIEW_H 31#define OLISTVIEW_H
32 32
33#include <qcolor.h> 33#include <qcolor.h>
34#include <qlistview.h> 34#include <qlistview.h>
35#include <qpen.h> 35#include <qpen.h>
36#include <qdatastream.h> 36#include <qdatastream.h>
37#include <qstringlist.h> 37#include <qstringlist.h>
38 38
39
40namespace Opie {
41namespace Ui {
39class OListViewItem; 42class OListViewItem;
40 43
41 44
42/*====================================================================================== 45/*======================================================================================
43 * OListView 46 * OListView
44 *======================================================================================*/ 47 *======================================================================================*/
45 48
46/** 49/**
47 * @brief A list/tree widget. 50 * @brief A list/tree widget.
48 * 51 *
49 * A @ref QListView variant featuring visual and functional enhancements 52 * A @ref QListView variant featuring visual and functional enhancements
50 * like an alternate background for odd rows, an autostretch mode 53 * like an alternate background for odd rows, an autostretch mode
51 * for the width of the widget ( >= Qt 3 only ) and persistence capabilities. 54 * for the width of the widget ( >= Qt 3 only ) and persistence capabilities.
52 * 55 *
53 * @author Michael 'Mickey' Lauer <mickey@vanille.de> 56 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
54 */ 57 */
55class OListView: public QListView 58class OListView: public QListView
56{ 59{
60 Q_OBJECT
57 public: 61 public:
58 /** 62 /**
59 * Constructor. 63 * Constructor.
60 * 64 *
61 * The parameters @a parent and @a name are handled by 65 * The parameters @a parent and @a name are handled by
62 * @ref QListView, as usual. 66 * @ref QListView, as usual.
63 */ 67 */
64 OListView( QWidget* parent = 0, const char* name = 0 ); 68 OListView( QWidget* parent = 0, const char* name = 0 );
65 /** 69 /**
66 * Destructor. 70 * Destructor.
67 */ 71 */
68 virtual ~OListView(); 72 virtual ~OListView();
69 /** 73 /**
70 * Let the last column fit exactly all the available width. 74 * Let the last column fit exactly all the available width.
71 */ 75 */
72 void setFullWidth( bool fullWidth ); 76 void setFullWidth( bool fullWidth );
73 /** 77 /**
74 * Returns whether the last column is set to fit the available width. 78 * Returns whether the last column is set to fit the available width.
75 */ 79 */
76 bool fullWidth() const; 80 bool fullWidth() const;
77 /** 81 /**
78 * Reimplemented for full width support 82 * Reimplemented for full width support
79 */ 83 */
80 virtual int addColumn( const QString& label, int width = -1 ); 84 virtual int addColumn( const QString& label, int width = -1 );
81 /** 85 /**
82 * Reimplemented for full width support 86 * Reimplemented for full width support
83 */ 87 */
84 virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 ); 88 virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 );
85 /** 89 /**
86 * Reimplemented for full width support 90 * Reimplemented for full width support
87 */ 91 */
88 virtual void removeColumn(int index); 92 virtual void removeColumn(int index);
89 /** 93 /**
90 * Set the alternate background background @a color. 94 * Set the alternate background background @a color.
91 * Set to an invalid color to disable alternate colors. 95 * Set to an invalid color to disable alternate colors.
92 * This only has an effect if the items are OListViewItems 96 * This only has an effect if the items are OListViewItems
93 */ 97 */
94 void setAlternateBackground( const QColor& color ); 98 void setAlternateBackground( const QColor& color );
95 /** 99 /**
96 * Sets the column separator @a pen. 100 * Sets the column separator @a pen.
97 */ 101 */
98 void setColumnSeparator( const QPen& pen ); 102 void setColumnSeparator( const QPen& pen );
99 103
100 /** 104 /**
101 * @returns the alternate background color 105 * @returns the alternate background color
102 */ 106 */
103 const QColor& alternateBackground() const; 107 const QColor& alternateBackground() const;
104 /** 108 /**
105 * @return the column separator pen 109 * @return the column separator pen
106 */ 110 */
107 const QPen& columnSeparator() const; 111 const QPen& columnSeparator() const;
108 /** 112 /**
109 * Create a list view item as child of this object 113 * Create a list view item as child of this object
110 * @returns the new object 114 * @returns the new object
111 */ 115 */
112 virtual OListViewItem* childFactory(); 116 virtual OListViewItem* childFactory();
113#ifndef QT_NO_DATASTREAM 117#ifndef QT_NO_DATASTREAM
114 /** 118 /**
115 * Serialize this object to @ref QDataStream @a stream 119 * Serialize this object to @ref QDataStream @a stream
116 */ 120 */
117 virtual void serializeTo( QDataStream& stream ) const; 121 virtual void serializeTo( QDataStream& stream ) const;
118 /** 122 /**
119 * Serialize this object from a @ref QDataStream @a stream 123 * Serialize this object from a @ref QDataStream @a stream
120 */ 124 */
121 virtual void serializeFrom( QDataStream& s ); 125 virtual void serializeFrom( QDataStream& s );
122#endif 126#endif
123 127
124 public slots: 128 public slots:
125 /** 129 /**
126 * Expand all items 130 * Expand all items
127 */ 131 */
128 void expand(); 132 void expand();
129 /** 133 /**
130 * Collapse all items 134 * Collapse all items
131 */ 135 */
132 void collapse(); 136 void collapse();
133 137
134 protected slots: 138 protected slots:
135 /** 139 /**
136 * expand the current OListViewItem 140 * expand the current OListViewItem
137 */ 141 */
138 void expand(QListViewItem*); 142 void expand(QListViewItem*);
139 143
140 private: 144 private:
141 QColor m_alternateBackground; 145 QColor m_alternateBackground;
142 bool m_fullWidth; 146 bool m_fullWidth : 1;
143 QPen m_columnSeparator; 147 QPen m_columnSeparator;
148 class Private;
149 Private *d;
144}; 150};
145 151
146#ifndef QT_NO_DATASTREAM 152#ifndef QT_NO_DATASTREAM
147/** 153/**
148 * @relates OListView 154 * @relates OListView
149 * Writes @a listview to the @a stream and returns a reference to the stream. 155 * Writes @a listview to the @a stream and returns a reference to the stream.
150 */ 156 */
151QDataStream& operator<<( QDataStream& stream, const OListView& listview ); 157QDataStream& operator<<( QDataStream& stream, const OListView& listview );
152/** 158/**
153 * @relates OListView 159 * @relates OListView
154 * Reads @a listview from the @a stream and returns a reference to the stream. 160 * Reads @a listview from the @a stream and returns a reference to the stream.
155 */ 161 */
156QDataStream& operator>>( QDataStream& stream, OListView& listview ); 162QDataStream& operator>>( QDataStream& stream, OListView& listview );
157#endif // QT_NO_DATASTREAM 163#endif // QT_NO_DATASTREAM
158 164
159/*====================================================================================== 165/*======================================================================================
160 * OListViewItem 166 * OListViewItem
161 *======================================================================================*/ 167 *======================================================================================*/
162 168
163class OListViewItem: public QListViewItem 169class OListViewItem: public QListViewItem
164{ 170{
165 friend class OCheckListItem; 171 friend class OCheckListItem;
166 public: 172 public:
167 /** 173 /**
168 * Constructors. 174 * Constructors.
169 */ 175 */
170 OListViewItem( QListView * parent ); 176 OListViewItem( QListView * parent );
171 OListViewItem( QListViewItem * parent ); 177 OListViewItem( QListViewItem * parent );
172 OListViewItem( QListView * parent, QListViewItem * after ); 178 OListViewItem( QListView * parent, QListViewItem * after );
173 OListViewItem( QListViewItem * parent, QListViewItem * after ); 179 OListViewItem( QListViewItem * parent, QListViewItem * after );
174 180
175 OListViewItem( QListView * parent, 181 OListViewItem( QListView * parent,
176 QString, QString = QString::null, 182 QString, QString = QString::null,
177 QString = QString::null, QString = QString::null, 183 QString = QString::null, QString = QString::null,
178 QString = QString::null, QString = QString::null, 184 QString = QString::null, QString = QString::null,
179 QString = QString::null, QString = QString::null ); 185 QString = QString::null, QString = QString::null );
180 186
181 OListViewItem( QListViewItem * parent, 187 OListViewItem( QListViewItem * parent,
182 QString, QString = QString::null, 188 QString, QString = QString::null,
183 QString = QString::null, QString = QString::null, 189 QString = QString::null, QString = QString::null,
184 QString = QString::null, QString = QString::null, 190 QString = QString::null, QString = QString::null,
185 QString = QString::null, QString = QString::null ); 191 QString = QString::null, QString = QString::null );
186 192
187 OListViewItem( QListView * parent, QListViewItem * after, 193 OListViewItem( QListView * parent, QListViewItem * after,
188 QString, QString = QString::null, 194 QString, QString = QString::null,
189 QString = QString::null, QString = QString::null, 195 QString = QString::null, QString = QString::null,
190 QString = QString::null, QString = QString::null, 196 QString = QString::null, QString = QString::null,
191 QString = QString::null, QString = QString::null ); 197 QString = QString::null, QString = QString::null );
192 198
193 OListViewItem( QListViewItem * parent, QListViewItem * after, 199 OListViewItem( QListViewItem * parent, QListViewItem * after,
194 QString, QString = QString::null, 200 QString, QString = QString::null,
195 QString = QString::null, QString = QString::null, 201 QString = QString::null, QString = QString::null,
196 QString = QString::null, QString = QString::null, 202 QString = QString::null, QString = QString::null,
197 QString = QString::null, QString = QString::null ); 203 QString = QString::null, QString = QString::null );
198 /** 204 /**
199 * Destructor. 205 * Destructor.
200 */ 206 */
201 virtual ~OListViewItem(); 207 virtual ~OListViewItem();
202 /** 208 /**
203 * @returns the background color of the list item. 209 * @returns the background color of the list item.
204 */ 210 */
205 const QColor& backgroundColor(); 211 const QColor& backgroundColor();
206 /** 212 /**
207 * @returns true, if the item is at an odd position and 213 * @returns true, if the item is at an odd position and
208 * thus have to be painted with the alternate background color. 214 * thus have to be painted with the alternate background color.
209 */ 215 */
210 bool isAlternate(); 216 bool isAlternate();
211 /** 217 /**
212 * @note: Reimplemented for internal purposes - the API is not affected 218 * @note: Reimplemented for internal purposes - the API is not affected
213 * 219 *
214 */ 220 */
215 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); 221 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
216 /** 222 /**
217 * Perform object initialization. 223 * Perform object initialization.
218 */ 224 */
219 void init(); 225 void init();
220 /** 226 /**
221 * create a list view item as child of this object 227 * create a list view item as child of this object
222 * @returns the new object 228 * @returns the new object
223 */ 229 */
224 virtual OListViewItem* childFactory(); 230 virtual OListViewItem* childFactory();
225 #ifndef QT_NO_DATASTREAM 231 #ifndef QT_NO_DATASTREAM
226 /** 232 /**
227 * serialize this object to or from a @ref QDataStream 233 * serialize this object to or from a @ref QDataStream
228 * @param s the stream used to serialize this object. 234 * @param s the stream used to serialize this object.
229 */ 235 */
230 virtual void serializeTo( QDataStream& s ) const; 236 virtual void serializeTo( QDataStream& s ) const;
231 237
232 /** 238 /**
233 * serialize this object to or from a @ref QDataStream 239 * serialize this object to or from a @ref QDataStream
234 * @param s the stream used to serialize this object. 240 * @param s the stream used to serialize this object.
235 */ 241 */
236 virtual void serializeFrom( QDataStream& s ); 242 virtual void serializeFrom( QDataStream& s );
237 #endif 243 #endif
238 244
239 /** 245 /**
240 * expand the the item 246 * expand the the item
241 */ 247 */
242 virtual void expand(){}; 248 virtual void expand(){};
243 249
244 private: 250 private:
245 bool m_known; 251 bool m_known : 1;
246 bool m_odd; 252 bool m_odd : 1;
253 class Private;
254 Private *d;
247}; 255};
248 256
249#ifndef QT_NO_DATASTREAM 257#ifndef QT_NO_DATASTREAM
250/** 258/**
251 * @relates QListViewItem 259 * @relates QListViewItem
252 * Writes listview @a item and all subitems recursively to @a stream 260 * Writes listview @a item and all subitems recursively to @a stream
253 * and returns a reference to the stream. 261 * and returns a reference to the stream.
254 */ 262 */
255QDataStream& operator<<( QDataStream& stream, const OListViewItem& item ); 263QDataStream& operator<<( QDataStream& stream, const OListViewItem& item );
256/** 264/**
257 * @relates QListViewItem 265 * @relates QListViewItem
258 * Reads listview @a item from @a stream and returns a reference to the stream. 266 * Reads listview @a item from @a stream and returns a reference to the stream.
259 */ 267 */
260QDataStream& operator>>( QDataStream& stream, OListViewItem& item ); 268QDataStream& operator>>( QDataStream& stream, OListViewItem& item );
261#endif // QT_NO_DATASTREAM 269#endif // QT_NO_DATASTREAM
262 270
263 271
264/*====================================================================================== 272/*======================================================================================
265 * OCheckListItem 273 * OCheckListItem
266 *======================================================================================*/ 274 *======================================================================================*/
267 275
268class OCheckListItem : public QCheckListItem 276class OCheckListItem : public QCheckListItem
269{ 277{
270 public: 278 public:
271 279
272 OCheckListItem( QCheckListItem *parent, const QString &text, 280 OCheckListItem( QCheckListItem *parent, const QString &text,
273 Type = Controller ); 281 Type = Controller );
274 OCheckListItem( QListViewItem *parent, const QString &text, 282 OCheckListItem( QListViewItem *parent, const QString &text,
275 Type = Controller ); 283 Type = Controller );
276 OCheckListItem( QListView *parent, const QString &text, 284 OCheckListItem( QListView *parent, const QString &text,
277 Type = Controller ); 285 Type = Controller );
278 OCheckListItem( QListViewItem *parent, const QString &text, 286 OCheckListItem( QListViewItem *parent, const QString &text,
279 const QPixmap & ); 287 const QPixmap & );
280 OCheckListItem( QListView *parent, const QString &text, 288 OCheckListItem( QListView *parent, const QString &text,
281 const QPixmap & ); 289 const QPixmap & );
282 ~OCheckListItem(); 290 ~OCheckListItem();
283 /** 291 /**
284 * @returns the background color of the list item. 292 * @returns the background color of the list item.
285 */ 293 */
286 const QColor& backgroundColor(); 294 const QColor& backgroundColor();
287 /** 295 /**
288 * @returns true, if the item is at an odd position and 296 * @returns true, if the item is at an odd position and
289 * thus have to be painted with the alternate background color. 297 * thus have to be painted with the alternate background color.
290 */ 298 */
291 bool isAlternate(); 299 bool isAlternate();
292 /** 300 /**
293 * @note: Reimplemented for internal purposes - the API is not affected 301 * @note: Reimplemented for internal purposes - the API is not affected
294 * 302 *
295 */ 303 */
296 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); 304 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
297 /** 305 /**
298 * Perform object initialization. 306 * Perform object initialization.
299 */ 307 */
300 void init(); 308 void init();
301 309
302 private: 310 private:
303 bool m_known; 311 bool m_known;
304 bool m_odd; 312 bool m_odd;
305}; 313};
306 314
307 315
308/*====================================================================================== 316/*======================================================================================
309 * ONamedListView 317 * ONamedListView
310 *======================================================================================*/ 318 *======================================================================================*/
311 319
312class ONamedListViewItem; 320class ONamedListViewItem;
313 321
314/** 322/**
315 * @brief An OListView variant with named columns. 323 * @brief An OListView variant with named columns.
316 * 324 *
317 * This class provides a higher-level interface to an OListView. 325 * This class provides a higher-level interface to an OListView.
318 * 326 *
319 * @author Michael 'Mickey' Lauer <mickey@vanille.de> 327 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
320 */ 328 */
321class ONamedListView: public OListView 329class ONamedListView: public OListView
322{ 330{
323 public: 331 public:
324 /** 332 /**
325 * Constructor. 333 * Constructor.
326 * 334 *
327 * The parameters @a parent and @a name are handled by 335 * The parameters @a parent and @a name are handled by
328 * @ref OListView, as usual. 336 * @ref OListView, as usual.
329 */ 337 */
330 ONamedListView( QWidget* parent = 0, const char* name = 0 ); 338 ONamedListView( QWidget* parent = 0, const char* name = 0 );
331 /** 339 /**
332 * Destructor. 340 * Destructor.
333 */ 341 */
334 virtual ~ONamedListView(); 342 virtual ~ONamedListView();
335 /** 343 /**
336 * Add a number of @a columns to the listview. 344 * Add a number of @a columns to the listview.
337 */ 345 */
338 virtual void addColumns( const QStringList& columns ); 346 virtual void addColumns( const QStringList& columns );
339 /** 347 /**
340 * @returns the column index matching to @a text or -1 if not found. 348 * @returns the column index matching to @a text or -1 if not found.
341 */ 349 */
342 virtual int findColumn( const QString& text ) const; 350 virtual int findColumn( const QString& text ) const;
343 /** 351 /**
344 * @returns the first item which has a @a text in column @a column. 352 * @returns the first item which has a @a text in column @a column.
345 * Set @a recurse to indicate how much subchild levels to search, e.g.<ul> 353 * Set @a recurse to indicate how much subchild levels to search, e.g.<ul>
346 * <li>set it to 0 to search only among direct childs, 354 * <li>set it to 0 to search only among direct childs,
347 * <li>set it to 1 to search direct childs and all 1st order subchilds 355 * <li>set it to 1 to search direct childs and all 1st order subchilds
348 * <li>set it to -1 for maximum recursion. 356 * <li>set it to -1 for maximum recursion.
349 * </ul> 357 * </ul>
350 * @sa ONamedListViewItem::find() 358 * @sa ONamedListViewItem::find()
351 */ 359 */
352 virtual ONamedListViewItem* find( ONamedListViewItem* start, int column, const QString& text, int recurse = -1 ) const; 360 virtual ONamedListViewItem* find( ONamedListViewItem* start, int column, const QString& text, int recurse = -1 ) const;
353 virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const; 361 virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const;
354 362
355 virtual ONamedListViewItem* find( ONamedListViewItem* start, const QString& column, const QString& text, int recurse = -1 ) const; 363 virtual ONamedListViewItem* find( ONamedListViewItem* start, const QString& column, const QString& text, int recurse = -1 ) const;
356 virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const; 364 virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const;
365 private:
366 class Private;
367 Private *d;
357}; 368};
358 369
359/*====================================================================================== 370/*======================================================================================
360 * ONamedListViewItem 371 * ONamedListViewItem
361 *======================================================================================*/ 372 *======================================================================================*/
362 373
363/** 374/**
364 * @brief An OListView variant with named columns. 375 * @brief An OListView variant with named columns.
365 * 376 *
366 * This class provides a higher-level interface to an OListViewItem. 377 * This class provides a higher-level interface to an OListViewItem.
367 * 378 *
368 * @author Michael 'Mickey' Lauer <mickey@vanille.de> 379 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
369 */ 380 */
370class ONamedListViewItem: public OListViewItem 381class ONamedListViewItem: public OListViewItem
371{ 382{
372 public: 383 public:
373 /** 384 /**
374 * Constructor. Accepts the same parameters as a @ref OListViewItem, 385 * Constructor. Accepts the same parameters as a @ref OListViewItem,
375 * plus a @ref QStringList which holds an arbitrary number of @a texts. 386 * plus a @ref QStringList which holds an arbitrary number of @a texts.
376 */ 387 */
377 ONamedListViewItem( QListView* parent, const QStringList& texts ); 388 ONamedListViewItem( QListView* parent, const QStringList& texts );
378 ONamedListViewItem( QListViewItem* parent, const QStringList& texts ); 389 ONamedListViewItem( QListViewItem* parent, const QStringList& texts );
379 ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ); 390 ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts );
380 ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ); 391 ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts );
381 /** 392 /**
382 * Destructor. 393 * Destructor.
383 */ 394 */
384 virtual ~ONamedListViewItem(); 395 virtual ~ONamedListViewItem();
385 /** 396 /**
386 * Sets the text in column @a column to @a text. 397 * Sets the text in column @a column to @a text.
387 * This method differs from @ref QListViewItem::setText() in that it 398 * This method differs from @ref QListViewItem::setText() in that it
388 * accepts a string as column indicator instead of an int. 399 * accepts a string as column indicator instead of an int.
389 */ 400 */
390 virtual void setText( const QString& column, const QString& text ); 401 virtual void setText( const QString& column, const QString& text );
391 /** 402 /**
392 * Sets a number of @a texts for this item. 403 * Sets a number of @a texts for this item.
393 */ 404 */
394 virtual void setText( const QStringList& texts ); 405 virtual void setText( const QStringList& texts );
395 /** 406 /**
396 * @returns the first child which has a @a text in column @a column. 407 * @returns the first child which has a @a text in column @a column.
397 * Set @a recurse to indicate how much subchild levels to search, e.g.<ul> 408 * Set @a recurse to indicate how much subchild levels to search, e.g.<ul>
398 * <li>set it to 0 to search only among direct childs, 409 * <li>set it to 0 to search only among direct childs,
399 * <li>set it to 1 to search direct childs and all 1st order subchilds 410 * <li>set it to 1 to search direct childs and all 1st order subchilds
400 * <li>set it to -1 for maximum recursion. 411 * <li>set it to -1 for maximum recursion.
401 * </ul> 412 * </ul>
402 * @sa ONamedListView::find() 413 * @sa ONamedListView::find()
403 */ 414 */
404 virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const; 415 virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const;
405 virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const; 416 virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const;
406};
407 417
418 private:
419 class Private;
420 Private *d;
421
422};
423}
424}
408 425
409#endif // OLISTVIEW_H 426#endif // OLISTVIEW_H
diff --git a/libopie2/opieui/opieui.pro b/libopie2/opieui/opieui.pro
index 1be8db5..e895edc 100644
--- a/libopie2/opieui/opieui.pro
+++ b/libopie2/opieui/opieui.pro
@@ -1,66 +1,63 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on debug 2CONFIG += qt warn_on debug
3DESTDIR = $(OPIEDIR)/lib 3DESTDIR = $(OPIEDIR)/lib
4HEADERS = oclickablelabel.h \ 4HEADERS = oclickablelabel.h \
5 odialog.h \ 5 odialog.h \
6 ofontselector.h \ 6 ofontselector.h \
7 oimageeffect.h \ 7 oimageeffect.h \
8 olistview.h \ 8 olistview.h \
9 omessagebox.h \
10 opixmapeffect.h \ 9 opixmapeffect.h \
11 opopupmenu.h \ 10 opopupmenu.h \
12 opixmapprovider.h \ 11 opixmapprovider.h \
13 oresource.h \
14 oselector.h \ 12 oselector.h \
15 oseparator.h \ 13 oseparator.h \
16 otabinfo.h \ 14 otabinfo.h \
17 otabbar.h \ 15 otabbar.h \
18 otabwidget.h \ 16 otabwidget.h \
19 otaskbarapplet.h \ 17 otaskbarapplet.h \
20 oticker.h \ 18 oticker.h \
21 otimepicker.h \ 19 otimepicker.h \
22 oversatileview.h \ 20 oversatileview.h \
23 oversatileviewitem.h \ 21 oversatileviewitem.h \
24 owait.h 22 owait.h
25 23
26SOURCES = oclickablelabel.cpp \ 24SOURCES = oclickablelabel.cpp \
27 odialog.cpp \ 25 odialog.cpp \
28 ofontselector.cpp \ 26 ofontselector.cpp \
29 oimageeffect.cpp \ 27 oimageeffect.cpp \
30 olistview.cpp \ 28 olistview.cpp \
31 opixmapeffect.cpp \ 29 opixmapeffect.cpp \
32 opopupmenu.cpp \ 30 opopupmenu.cpp \
33 opixmapprovider.cpp \ 31 opixmapprovider.cpp \
34 oresource.cpp \
35 oselector.cpp \ 32 oselector.cpp \
36 oseparator.cpp \ 33 oseparator.cpp \
37 otabbar.cpp \ 34 otabbar.cpp \
38 otabwidget.cpp \ 35 otabwidget.cpp \
39 otaskbarapplet.cpp \ 36 otaskbarapplet.cpp \
40 oticker.cpp \ 37 oticker.cpp \
41 otimepicker.cpp \ 38 otimepicker.cpp \
42 oversatileview.cpp \ 39 oversatileview.cpp \
43 oversatileviewitem.cpp \ 40 oversatileviewitem.cpp \
44 owait.cpp 41 owait.cpp
45 42
46include ( big-screen/big-screen.pro ) 43include ( big-screen/big-screen.pro )
47include ( fileselector/fileselector.pro ) 44include ( fileselector/fileselector.pro )
48 45
49INTERFACES = otimepickerbase.ui 46INTERFACES = otimepickerbase.ui
50 47
51TARGET = opieui2 48TARGET = opieui2
52VERSION = 1.8.5 49VERSION = 1.8.5
53 50
54INCLUDEPATH += $(OPIEDIR)/include 51INCLUDEPATH += $(OPIEDIR)/include
55DEPENDPATH += $(OPIEDIR)/include 52DEPENDPATH += $(OPIEDIR)/include
56 53
57LIBS += -lopiecore2 54LIBS += -lopiecore2
58 55
59!contains( platform, x11 ) { 56!contains( platform, x11 ) {
60 include ( $(OPIEDIR)/include.pro ) 57 include ( $(OPIEDIR)/include.pro )
61} 58}
62 59
63contains( platform, x11 ) { 60contains( platform, x11 ) {
64 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib 61 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib
65} 62}
66 63
diff --git a/libopie2/opieui/opixmapeffect.cpp b/libopie2/opieui/opixmapeffect.cpp
index 05f851d..794c7b2 100644
--- a/libopie2/opieui/opixmapeffect.cpp
+++ b/libopie2/opieui/opixmapeffect.cpp
@@ -1,328 +1,330 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> 2 Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
3 (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org> 3 (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org>
4 (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> 4 (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org>
5 5
6*/ 6*/
7 7
8// $Id$ 8// $Id$
9 9
10/* QT */ 10/* QT */
11 11
12#include <qimage.h> 12#include <qimage.h>
13#include <qpainter.h> 13#include <qpainter.h>
14 14
15/* OPIE */ 15/* OPIE */
16 16
17#include <opie2/opixmapeffect.h> 17#include <opie2/opixmapeffect.h>
18#include <opie2/oimageeffect.h> 18#include <opie2/oimageeffect.h>
19 19
20
21using namespace Opie::Ui;
20//====================================================================== 22//======================================================================
21// 23//
22// Gradient effects 24// Gradient effects
23// 25//
24//====================================================================== 26//======================================================================
25 27
26 28
27OPixmap& OPixmapEffect::gradient(OPixmap &pixmap, const QColor &ca, 29OPixmap& OPixmapEffect::gradient(OPixmap &pixmap, const QColor &ca,
28 const QColor &cb, GradientType eff, int ncols) 30 const QColor &cb, GradientType eff, int ncols)
29{ 31{
30 if(pixmap.depth() > 8 && 32 if(pixmap.depth() > 8 &&
31 (eff == VerticalGradient || eff == HorizontalGradient)) { 33 (eff == VerticalGradient || eff == HorizontalGradient)) {
32 34
33 int rDiff, gDiff, bDiff; 35 int rDiff, gDiff, bDiff;
34 int rca, gca, bca /*, rcb, gcb, bcb*/; 36 int rca, gca, bca /*, rcb, gcb, bcb*/;
35 37
36 register int x, y; 38 register int x, y;
37 39
38 rDiff = (/*rcb = */ cb.red()) - (rca = ca.red()); 40 rDiff = (/*rcb = */ cb.red()) - (rca = ca.red());
39 gDiff = (/*gcb = */ cb.green()) - (gca = ca.green()); 41 gDiff = (/*gcb = */ cb.green()) - (gca = ca.green());
40 bDiff = (/*bcb = */ cb.blue()) - (bca = ca.blue()); 42 bDiff = (/*bcb = */ cb.blue()) - (bca = ca.blue());
41 43
42 register int rl = rca << 16; 44 register int rl = rca << 16;
43 register int gl = gca << 16; 45 register int gl = gca << 16;
44 register int bl = bca << 16; 46 register int bl = bca << 16;
45 47
46 int rcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * rDiff; 48 int rcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * rDiff;
47 int gcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * gDiff; 49 int gcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * gDiff;
48 int bcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * bDiff; 50 int bcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * bDiff;
49 51
50 QPainter p(&pixmap); 52 QPainter p(&pixmap);
51 53
52 // these for-loops could be merged, but the if's in the inner loop 54 // these for-loops could be merged, but the if's in the inner loop
53 // would make it slow 55 // would make it slow
54 switch(eff) { 56 switch(eff) {
55 case VerticalGradient: 57 case VerticalGradient:
56 for ( y = 0; y < pixmap.height(); y++ ) { 58 for ( y = 0; y < pixmap.height(); y++ ) {
57 rl += rcdelta; 59 rl += rcdelta;
58 gl += gcdelta; 60 gl += gcdelta;
59 bl += bcdelta; 61 bl += bcdelta;
60 62
61 p.setPen(QColor(rl>>16, gl>>16, bl>>16)); 63 p.setPen(QColor(rl>>16, gl>>16, bl>>16));
62 p.drawLine(0, y, pixmap.width()-1, y); 64 p.drawLine(0, y, pixmap.width()-1, y);
63 } 65 }
64 break; 66 break;
65 case HorizontalGradient: 67 case HorizontalGradient:
66 for( x = 0; x < pixmap.width(); x++) { 68 for( x = 0; x < pixmap.width(); x++) {
67 rl += rcdelta; 69 rl += rcdelta;
68 gl += gcdelta; 70 gl += gcdelta;
69 bl += bcdelta; 71 bl += bcdelta;
70 72
71 p.setPen(QColor(rl>>16, gl>>16, bl>>16)); 73 p.setPen(QColor(rl>>16, gl>>16, bl>>16));
72 p.drawLine(x, 0, x, pixmap.height()-1); 74 p.drawLine(x, 0, x, pixmap.height()-1);
73 } 75 }
74 break; 76 break;
75 default: 77 default:
76 ; 78 ;
77 } 79 }
78 } 80 }
79 else { 81 else {
80 QImage image = OImageEffect::gradient(pixmap.size(), ca, cb, 82 QImage image = OImageEffect::gradient(pixmap.size(), ca, cb,
81 (OImageEffect::GradientType) eff, ncols); 83 (OImageEffect::GradientType) eff, ncols);
82 pixmap.convertFromImage(image); 84 pixmap.convertFromImage(image);
83 } 85 }
84 86
85 return pixmap; 87 return pixmap;
86} 88}
87 89
88 90
89// ----------------------------------------------------------------------------- 91// -----------------------------------------------------------------------------
90 92
91OPixmap& OPixmapEffect::unbalancedGradient(OPixmap &pixmap, const QColor &ca, 93OPixmap& OPixmapEffect::unbalancedGradient(OPixmap &pixmap, const QColor &ca,
92 const QColor &cb, GradientType eff, int xfactor, int yfactor, 94 const QColor &cb, GradientType eff, int xfactor, int yfactor,
93 int ncols) 95 int ncols)
94{ 96{
95 QImage image = OImageEffect::unbalancedGradient(pixmap.size(), ca, cb, 97 QImage image = OImageEffect::unbalancedGradient(pixmap.size(), ca, cb,
96 (OImageEffect::GradientType) eff, 98 (OImageEffect::GradientType) eff,
97 xfactor, yfactor, ncols); 99 xfactor, yfactor, ncols);
98 pixmap.convertFromImage(image); 100 pixmap.convertFromImage(image);
99 101
100 return pixmap; 102 return pixmap;
101} 103}
102 104
103 105
104//====================================================================== 106//======================================================================
105// 107//
106// Intensity effects 108// Intensity effects
107// 109//
108//====================================================================== 110//======================================================================
109 111
110 112
111 113
112OPixmap& OPixmapEffect::intensity(OPixmap &pixmap, float percent) 114OPixmap& OPixmapEffect::intensity(OPixmap &pixmap, float percent)
113{ 115{
114 QImage image = pixmap.convertToImage(); 116 QImage image = pixmap.convertToImage();
115 OImageEffect::intensity(image, percent); 117 OImageEffect::intensity(image, percent);
116 pixmap.convertFromImage(image); 118 pixmap.convertFromImage(image);
117 119
118 return pixmap; 120 return pixmap;
119} 121}
120 122
121 123
122// ----------------------------------------------------------------------------- 124// -----------------------------------------------------------------------------
123 125
124OPixmap& OPixmapEffect::channelIntensity(OPixmap &pixmap, float percent, 126OPixmap& OPixmapEffect::channelIntensity(OPixmap &pixmap, float percent,
125 RGBComponent channel) 127 RGBComponent channel)
126{ 128{
127 QImage image = pixmap.convertToImage(); 129 QImage image = pixmap.convertToImage();
128 OImageEffect::channelIntensity(image, percent, 130 OImageEffect::channelIntensity(image, percent,
129 (OImageEffect::RGBComponent) channel); 131 (OImageEffect::RGBComponent) channel);
130 pixmap.convertFromImage(image); 132 pixmap.convertFromImage(image);
131 133
132 return pixmap; 134 return pixmap;
133} 135}
134 136
135 137
136//====================================================================== 138//======================================================================
137// 139//
138// Blend effects 140// Blend effects
139// 141//
140//====================================================================== 142//======================================================================
141 143
142 144
143OPixmap& OPixmapEffect::blend(OPixmap &pixmap, float initial_intensity, 145OPixmap& OPixmapEffect::blend(OPixmap &pixmap, float initial_intensity,
144 const QColor &bgnd, GradientType eff, 146 const QColor &bgnd, GradientType eff,
145 bool anti_dir, int ncols) 147 bool anti_dir, int ncols)
146{ 148{
147 149
148 QImage image = pixmap.convertToImage(); 150 QImage image = pixmap.convertToImage();
149 if (image.depth() <=8) 151 if (image.depth() <=8)
150 image = image.convertDepth(32); //Sloww.. 152 image = image.convertDepth(32); //Sloww..
151 153
152 OImageEffect::blend(image, initial_intensity, bgnd, 154 OImageEffect::blend(image, initial_intensity, bgnd,
153 (OImageEffect::GradientType) eff, anti_dir); 155 (OImageEffect::GradientType) eff, anti_dir);
154 156
155 unsigned int tmp; 157 unsigned int tmp;
156 158
157 if(pixmap.depth() <= 8 ) { 159 if(pixmap.depth() <= 8 ) {
158 if ( ncols < 2 || ncols > 256 ) 160 if ( ncols < 2 || ncols > 256 )
159 ncols = 3; 161 ncols = 3;
160 QColor *dPal = new QColor[ncols]; 162 QColor *dPal = new QColor[ncols];
161 for (int i=0; i<ncols; i++) { 163 for (int i=0; i<ncols; i++) {
162 tmp = 0 + 255 * i / ( ncols - 1 ); 164 tmp = 0 + 255 * i / ( ncols - 1 );
163 dPal[i].setRgb ( tmp, tmp, tmp ); 165 dPal[i].setRgb ( tmp, tmp, tmp );
164 } 166 }
165 OImageEffect::dither(image, dPal, ncols); 167 OImageEffect::dither(image, dPal, ncols);
166 pixmap.convertFromImage(image); 168 pixmap.convertFromImage(image);
167 delete [] dPal; 169 delete [] dPal;
168 } 170 }
169 else 171 else
170 pixmap.convertFromImage(image); 172 pixmap.convertFromImage(image);
171 173
172 return pixmap; 174 return pixmap;
173} 175}
174 176
175 177
176//====================================================================== 178//======================================================================
177// 179//
178// Hash effects 180// Hash effects
179// 181//
180//====================================================================== 182//======================================================================
181 183
182OPixmap& OPixmapEffect::hash(OPixmap &pixmap, Lighting lite, 184OPixmap& OPixmapEffect::hash(OPixmap &pixmap, Lighting lite,
183 unsigned int spacing, int ncols) 185 unsigned int spacing, int ncols)
184{ 186{
185 QImage image = pixmap.convertToImage(); 187 QImage image = pixmap.convertToImage();
186 OImageEffect::hash(image, (OImageEffect::Lighting) lite, spacing); 188 OImageEffect::hash(image, (OImageEffect::Lighting) lite, spacing);
187 189
188 unsigned int tmp; 190 unsigned int tmp;
189 191
190 if(pixmap.depth() <= 8 ) { 192 if(pixmap.depth() <= 8 ) {
191 if ( ncols < 2 || ncols > 256 ) 193 if ( ncols < 2 || ncols > 256 )
192 ncols = 3; 194 ncols = 3;
193 QColor *dPal = new QColor[ncols]; 195 QColor *dPal = new QColor[ncols];
194 for (int i=0; i<ncols; i++) { 196 for (int i=0; i<ncols; i++) {
195 tmp = 0 + 255 * i / ( ncols - 1 ); 197 tmp = 0 + 255 * i / ( ncols - 1 );
196 dPal[i].setRgb ( tmp, tmp, tmp ); 198 dPal[i].setRgb ( tmp, tmp, tmp );
197 } 199 }
198 OImageEffect::dither(image, dPal, ncols); 200 OImageEffect::dither(image, dPal, ncols);
199 pixmap.convertFromImage(image); 201 pixmap.convertFromImage(image);
200 delete [] dPal; 202 delete [] dPal;
201 } 203 }
202 else 204 else
203 pixmap.convertFromImage(image); 205 pixmap.convertFromImage(image);
204 206
205 return pixmap; 207 return pixmap;
206} 208}
207 209
208 210
209//====================================================================== 211//======================================================================
210// 212//
211// Pattern effects 213// Pattern effects
212// 214//
213//====================================================================== 215//======================================================================
214 216
215#if 0 217#if 0
216void OPixmapEffect::pattern(OPixmap &pixmap, const QColor &ca, 218void OPixmapEffect::pattern(OPixmap &pixmap, const QColor &ca,
217 const QColor &cb, unsigned pat[8]) 219 const QColor &cb, unsigned pat[8])
218{ 220{
219 QImage img = pattern(pixmap.size(), ca, cb, pat); 221 QImage img = pattern(pixmap.size(), ca, cb, pat);
220 pixmap.convertFromImage(img); 222 pixmap.convertFromImage(img);
221} 223}
222#endif 224#endif
223 225
224// ----------------------------------------------------------------------------- 226// -----------------------------------------------------------------------------
225 227
226OPixmap OPixmapEffect::pattern(const OPixmap& pmtile, QSize size, 228OPixmap OPixmapEffect::pattern(const OPixmap& pmtile, QSize size,
227 const QColor &ca, const QColor &cb, int ncols) 229 const QColor &ca, const QColor &cb, int ncols)
228{ 230{
229 if (pmtile.depth() > 8) 231 if (pmtile.depth() > 8)
230 ncols = 0; 232 ncols = 0;
231 233
232 QImage img = pmtile.convertToImage(); 234 QImage img = pmtile.convertToImage();
233 OImageEffect::flatten(img, ca, cb, ncols); 235 OImageEffect::flatten(img, ca, cb, ncols);
234 OPixmap pixmap; 236 OPixmap pixmap;
235 pixmap.convertFromImage(img); 237 pixmap.convertFromImage(img);
236 238
237 return OPixmapEffect::createTiled(pixmap, size); 239 return OPixmapEffect::createTiled(pixmap, size);
238} 240}
239 241
240 242
241// ----------------------------------------------------------------------------- 243// -----------------------------------------------------------------------------
242 244
243OPixmap OPixmapEffect::createTiled(const OPixmap& pixmap, QSize size) 245OPixmap OPixmapEffect::createTiled(const OPixmap& pixmap, QSize size)
244{ 246{
245 OPixmap pix; 247 OPixmap pix;
246 248
247 QPainter p(&pix); 249 QPainter p(&pix);
248 p.drawTiledPixmap(0, 0, size.width(), size.height(), pixmap); 250 p.drawTiledPixmap(0, 0, size.width(), size.height(), pixmap);
249 251
250 return pix; 252 return pix;
251} 253}
252 254
253 255
254//====================================================================== 256//======================================================================
255// 257//
256// Fade effects 258// Fade effects
257// 259//
258//====================================================================== 260//======================================================================
259 261
260OPixmap& OPixmapEffect::fade(OPixmap &pixmap, double val, const QColor &color) 262OPixmap& OPixmapEffect::fade(OPixmap &pixmap, double val, const QColor &color)
261{ 263{
262 QImage img = pixmap.convertToImage(); 264 QImage img = pixmap.convertToImage();
263 OImageEffect::fade(img, val, color); 265 OImageEffect::fade(img, val, color);
264 pixmap.convertFromImage(img); 266 pixmap.convertFromImage(img);
265 267
266 return pixmap; 268 return pixmap;
267} 269}
268 270
269 271
270// ----------------------------------------------------------------------------- 272// -----------------------------------------------------------------------------
271OPixmap& OPixmapEffect::toGray(OPixmap &pixmap, bool fast) 273OPixmap& OPixmapEffect::toGray(OPixmap &pixmap, bool fast)
272{ 274{
273 QImage img = pixmap.convertToImage(); 275 QImage img = pixmap.convertToImage();
274 OImageEffect::toGray(img, fast); 276 OImageEffect::toGray(img, fast);
275 pixmap.convertFromImage(img); 277 pixmap.convertFromImage(img);
276 278
277 return pixmap; 279 return pixmap;
278} 280}
279 281
280// ----------------------------------------------------------------------------- 282// -----------------------------------------------------------------------------
281OPixmap& OPixmapEffect::desaturate(OPixmap &pixmap, float desat) 283OPixmap& OPixmapEffect::desaturate(OPixmap &pixmap, float desat)
282{ 284{
283 QImage img = pixmap.convertToImage(); 285 QImage img = pixmap.convertToImage();
284 OImageEffect::desaturate(img, desat); 286 OImageEffect::desaturate(img, desat);
285 pixmap.convertFromImage(img); 287 pixmap.convertFromImage(img);
286 288
287 return pixmap; 289 return pixmap;
288} 290}
289// ----------------------------------------------------------------------------- 291// -----------------------------------------------------------------------------
290OPixmap& OPixmapEffect::contrast(OPixmap &pixmap, int c) 292OPixmap& OPixmapEffect::contrast(OPixmap &pixmap, int c)
291{ 293{
292 QImage img = pixmap.convertToImage(); 294 QImage img = pixmap.convertToImage();
293 OImageEffect::contrast(img, c); 295 OImageEffect::contrast(img, c);
294 pixmap.convertFromImage(img); 296 pixmap.convertFromImage(img);
295 297
296 return pixmap; 298 return pixmap;
297} 299}
298 300
299//====================================================================== 301//======================================================================
300// 302//
301// Dither effects 303// Dither effects
302// 304//
303//====================================================================== 305//======================================================================
304 306
305// ----------------------------------------------------------------------------- 307// -----------------------------------------------------------------------------
306OPixmap& OPixmapEffect::dither(OPixmap &pixmap, const QColor *palette, int size) 308OPixmap& OPixmapEffect::dither(OPixmap &pixmap, const QColor *palette, int size)
307{ 309{
308 QImage img = pixmap.convertToImage(); 310 QImage img = pixmap.convertToImage();
309 OImageEffect::dither(img, palette, size); 311 OImageEffect::dither(img, palette, size);
310 pixmap.convertFromImage(img); 312 pixmap.convertFromImage(img);
311 313
312 return pixmap; 314 return pixmap;
313} 315}
314 316
315//====================================================================== 317//======================================================================
316// 318//
317// Other effects 319// Other effects
318// 320//
319//====================================================================== 321//======================================================================
320 322
321OPixmap OPixmapEffect::selectedPixmap( const OPixmap &pix, const QColor &col ) 323OPixmap OPixmapEffect::selectedPixmap( const OPixmap &pix, const QColor &col )
322{ 324{
323 QImage img = pix.convertToImage(); 325 QImage img = pix.convertToImage();
324 OImageEffect::selectedImage(img, col); 326 OImageEffect::selectedImage(img, col);
325 OPixmap outPix; 327 OPixmap outPix;
326 outPix.convertFromImage(img); 328 outPix.convertFromImage(img);
327 return outPix; 329 return outPix;
328} 330}
diff --git a/libopie2/opieui/opixmapeffect.h b/libopie2/opieui/opixmapeffect.h
index 283fe2d..b780f9f 100644
--- a/libopie2/opieui/opixmapeffect.h
+++ b/libopie2/opieui/opixmapeffect.h
@@ -1,215 +1,219 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> 2 Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
3 (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org> 3 (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org>
4 (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> 4 (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org>
5 5
6*/ 6*/
7 7
8// $Id$ 8// $Id$
9 9
10#ifndef __OPIXMAP_EFFECT_H 10#ifndef __OPIXMAP_EFFECT_H
11#define __OPIXMAP_EFFECT_H 11#define __OPIXMAP_EFFECT_H
12 12
13 13
14#include <qsize.h> 14#include <qsize.h>
15typedef QPixmap OPixmap; 15typedef QPixmap OPixmap;
16class QColor; 16class QColor;
17 17
18
19namespace Opie {
20namespace Ui {
18/** 21/**
19 * This class includes various pixmap-based graphical effects. 22 * This class includes various pixmap-based graphical effects.
20 * 23 *
21 * Everything is 24 * Everything is
22 * static, so there is no need to create an instance of this class. You can 25 * static, so there is no need to create an instance of this class. You can
23 * just call the static methods. They are encapsulated here merely to provide 26 * just call the static methods. They are encapsulated here merely to provide
24 * a common namespace. 27 * a common namespace.
25 */ 28 */
26class OPixmapEffect 29class OPixmapEffect
27{ 30{
28public: 31public:
29 enum GradientType { VerticalGradient, HorizontalGradient, 32 enum GradientType { VerticalGradient, HorizontalGradient,
30 DiagonalGradient, CrossDiagonalGradient, 33 DiagonalGradient, CrossDiagonalGradient,
31 PyramidGradient, RectangleGradient, 34 PyramidGradient, RectangleGradient,
32 PipeCrossGradient, EllipticGradient }; 35 PipeCrossGradient, EllipticGradient };
33 enum RGBComponent { Red, Green, Blue }; 36 enum RGBComponent { Red, Green, Blue };
34 37
35 enum Lighting {NorthLite, NWLite, WestLite, SWLite, 38 enum Lighting {NorthLite, NWLite, WestLite, SWLite,
36 SouthLite, SELite, EastLite, NELite}; 39 SouthLite, SELite, EastLite, NELite};
37 40
38 /** 41 /**
39 * Creates a gradient from color a to color b of the specified type. 42 * Creates a gradient from color a to color b of the specified type.
40 * 43 *
41 * @param pixmap The pixmap to process. 44 * @param pixmap The pixmap to process.
42 * @param ca Color a. 45 * @param ca Color a.
43 * @param cb Color b. 46 * @param cb Color b.
44 * @param type The type of gradient. 47 * @param type The type of gradient.
45 * @param ncols The number of colors to use when not running on a 48 * @param ncols The number of colors to use when not running on a
46 * truecolor display. The gradient will be dithered to this number of 49 * truecolor display. The gradient will be dithered to this number of
47 * colors. Pass 0 to prevent dithering. 50 * colors. Pass 0 to prevent dithering.
48 * @return Returns the generated pixmap, for convenience. 51 * @return Returns the generated pixmap, for convenience.
49 */ 52 */
50 static OPixmap& gradient(OPixmap& pixmap, const QColor &ca, const QColor &cb, 53 static OPixmap& gradient(OPixmap& pixmap, const QColor &ca, const QColor &cb,
51 GradientType type, int ncols=3); 54 GradientType type, int ncols=3);
52 55
53 /** 56 /**
54 * Creates an unbalanced gradient. 57 * Creates an unbalanced gradient.
55 * 58 *
56 * An unbalanced gradient is a gradient where the transition from 59 * An unbalanced gradient is a gradient where the transition from
57 * color a to color b is not linear, but in this case, exponential. 60 * color a to color b is not linear, but in this case, exponential.
58 * 61 *
59 * @param pixmap The pixmap that should be written. 62 * @param pixmap The pixmap that should be written.
60 * @param ca Color a. 63 * @param ca Color a.
61 * @param cb Color b. 64 * @param cb Color b.
62 * @param type The type of gradient. 65 * @param type The type of gradient.
63 * @param xfactor The x decay length. Use a value between -200 and 200. 66 * @param xfactor The x decay length. Use a value between -200 and 200.
64 * @param yfactor The y decay length. 67 * @param yfactor The y decay length.
65 * @param ncols The number of colors. See #gradient. 68 * @param ncols The number of colors. See #gradient.
66 * @return The generated pixmap, for convencience. 69 * @return The generated pixmap, for convencience.
67 */ 70 */
68 static OPixmap& unbalancedGradient(OPixmap& pixmap, const QColor &ca, 71 static OPixmap& unbalancedGradient(OPixmap& pixmap, const QColor &ca,
69 const QColor &cb, GradientType type, int xfactor = 100, 72 const QColor &cb, GradientType type, int xfactor = 100,
70 int yfactor = 100, int ncols=3); 73 int yfactor = 100, int ncols=3);
71 74
72 /** 75 /**
73 * Creates a pixmap of a given size with the given pixmap. 76 * Creates a pixmap of a given size with the given pixmap.
74 * 77 *
75 * if the 78 * if the
76 * given size is bigger than the size of the pixmap, the pixmap is 79 * given size is bigger than the size of the pixmap, the pixmap is
77 * tiled. 80 * tiled.
78 * 81 *
79 * @param pixmap This is the source pixmap 82 * @param pixmap This is the source pixmap
80 * @param size The size the new pixmap should have. 83 * @param size The size the new pixmap should have.
81 * @return The generated, tiled pixmap. 84 * @return The generated, tiled pixmap.
82 */ 85 */
83 static OPixmap createTiled(const OPixmap& pixmap, QSize size); 86 static OPixmap createTiled(const OPixmap& pixmap, QSize size);
84 87
85 /** 88 /**
86 * Either brightens or dims a pixmap by a specified ratio. 89 * Either brightens or dims a pixmap by a specified ratio.
87 * 90 *
88 * @param pixmap The pixmap to process. 91 * @param pixmap The pixmap to process.
89 * @param ratio The ratio to use. Use negative value to dim. 92 * @param ratio The ratio to use. Use negative value to dim.
90 * @return Returns The @ref pixmap(), provided for convenience. 93 * @return Returns The @ref pixmap(), provided for convenience.
91 */ 94 */
92 static OPixmap& intensity(OPixmap& pixmap, float ratio); 95 static OPixmap& intensity(OPixmap& pixmap, float ratio);
93 96
94 /** 97 /**
95 * Modifies the intensity of a pixmap's RGB channel component. 98 * Modifies the intensity of a pixmap's RGB channel component.
96 * 99 *
97 * @param pixmap The pixmap to process. 100 * @param pixmap The pixmap to process.
98 * @param ratio value. Use negative value to dim. 101 * @param ratio value. Use negative value to dim.
99 * @param channel Which channel(s) should be modified 102 * @param channel Which channel(s) should be modified
100 * @return Returns the @ref pixmap(), provided for convenience. 103 * @return Returns the @ref pixmap(), provided for convenience.
101 */ 104 */
102 static OPixmap& channelIntensity(OPixmap& pixmap, float ratio, 105 static OPixmap& channelIntensity(OPixmap& pixmap, float ratio,
103 RGBComponent channel); 106 RGBComponent channel);
104 107
105 /** 108 /**
106 * Blends the provided pixmap into a background of the indicated color. 109 * Blends the provided pixmap into a background of the indicated color.
107 * 110 *
108 * @param pixmap The pixmap to process. 111 * @param pixmap The pixmap to process.
109 * @param initial_intensity this parameter takes values from -1 to 1: 112 * @param initial_intensity this parameter takes values from -1 to 1:
110 * @li If positive, it tells how much to fade the image in its 113 * @li If positive, it tells how much to fade the image in its
111 * less affected spot. 114 * less affected spot.
112 * @li If negative, it tells roughly indicates how much of the image 115 * @li If negative, it tells roughly indicates how much of the image
113 * remains unaffected 116 * remains unaffected
114 * @param bgnd Indicates the color of the background to blend in. 117 * @param bgnd Indicates the color of the background to blend in.
115 * @param eff Lets you choose what kind of blending you like. 118 * @param eff Lets you choose what kind of blending you like.
116 * @param anti_dir Blend in the opposite direction (makes no much sense 119 * @param anti_dir Blend in the opposite direction (makes no much sense
117 * with concentric blending effects). 120 * with concentric blending effects).
118 * @return Returns the @ref pixmap(), provided for convenience. 121 * @return Returns the @ref pixmap(), provided for convenience.
119 */ 122 */
120 static OPixmap& blend(OPixmap& pixmap, float initial_intensity, 123 static OPixmap& blend(OPixmap& pixmap, float initial_intensity,
121 const QColor &bgnd, GradientType eff, 124 const QColor &bgnd, GradientType eff,
122 bool anti_dir=false, int ncols=3); 125 bool anti_dir=false, int ncols=3);
123 126
124 /** 127 /**
125 * Builds a hash on any given pixmap. 128 * Builds a hash on any given pixmap.
126 * 129 *
127 * @param pixmap The pixmap to process. 130 * @param pixmap The pixmap to process.
128 * @param lite The hash faces the indicated lighting (cardinal poles) 131 * @param lite The hash faces the indicated lighting (cardinal poles)
129 * @param spacing How many unmodified pixels inbetween hashes. 132 * @param spacing How many unmodified pixels inbetween hashes.
130 * @return Returns The @ref pixmap(), provided for convenience. 133 * @return Returns The @ref pixmap(), provided for convenience.
131 */ 134 */
132 static OPixmap& hash(OPixmap& pixmap, Lighting lite=NorthLite, 135 static OPixmap& hash(OPixmap& pixmap, Lighting lite=NorthLite,
133 unsigned int spacing=0, int ncols=3); 136 unsigned int spacing=0, int ncols=3);
134 137
135 /** 138 /**
136 * Creates a pattern from a pixmap. 139 * Creates a pattern from a pixmap.
137 * 140 *
138 * The given pixmap is "flattened" 141 * The given pixmap is "flattened"
139 * between color a to color b. 142 * between color a to color b.
140 * 143 *
141 * @param pixmap The pixmap to process. 144 * @param pixmap The pixmap to process.
142 * @param ca Color a. 145 * @param ca Color a.
143 * @param cb Color b. 146 * @param cb Color b.
144 * @param ncols The number of colors to use. The image will be 147 * @param ncols The number of colors to use. The image will be
145 * dithered to this depth. Pass zero to prevent dithering. 148 * dithered to this depth. Pass zero to prevent dithering.
146 * @return The @ref pixmap(), provided for convenience. 149 * @return The @ref pixmap(), provided for convenience.
147 */ 150 */
148 static OPixmap pattern(const OPixmap& pixmap, QSize size, 151 static OPixmap pattern(const OPixmap& pixmap, QSize size,
149 const QColor &ca, const QColor &cb, int ncols=8); 152 const QColor &ca, const QColor &cb, int ncols=8);
150 153
151 /** 154 /**
152 * Recolors a pixmap. 155 * Recolors a pixmap.
153 * 156 *
154 * The most dark color will become color a, 157 * The most dark color will become color a,
155 * the most bright one color b, and in between. 158 * the most bright one color b, and in between.
156 * 159 *
157 * @param pixmap The pixmap to process. 160 * @param pixmap The pixmap to process.
158 * @param ca Color a. 161 * @param ca Color a.
159 * @param cb Color b. 162 * @param cb Color b.
160 * @param ncols The number of colors to use. Pass zero to prevent 163 * @param ncols The number of colors to use. Pass zero to prevent
161 * dithering. 164 * dithering.
162 * @return Returns the @ref pixmap(), provided for convenience. 165 * @return Returns the @ref pixmap(), provided for convenience.
163 */ 166 */
164 static OPixmap& fade(OPixmap& pixmap, double val, const QColor &color); 167 static OPixmap& fade(OPixmap& pixmap, double val, const QColor &color);
165 168
166 /** 169 /**
167 * Converts a pixmap to grayscale. 170 * Converts a pixmap to grayscale.
168 * 171 *
169 * @param pixmap The pixmap to process. 172 * @param pixmap The pixmap to process.
170 * @param fast Set to @p true in order to use a faster but non-photographic 173 * @param fast Set to @p true in order to use a faster but non-photographic
171 * quality algorithm. Appropriate for things such as toolbar icons. 174 * quality algorithm. Appropriate for things such as toolbar icons.
172 * @return Returns the @ref pixmap(), provided for convenience. 175 * @return Returns the @ref pixmap(), provided for convenience.
173 */ 176 */
174 static OPixmap& toGray(OPixmap& pixmap, bool fast=false); 177 static OPixmap& toGray(OPixmap& pixmap, bool fast=false);
175 178
176 /** 179 /**
177 * Desaturates a pixmap. 180 * Desaturates a pixmap.
178 * 181 *
179 * @param pixmap The pixmap to process. 182 * @param pixmap The pixmap to process.
180 * @param desat A value between 0 and 1 setting the degree of desaturation 183 * @param desat A value between 0 and 1 setting the degree of desaturation
181 * @return Returns The @ref pixmap(), provided for convenience. 184 * @return Returns The @ref pixmap(), provided for convenience.
182 */ 185 */
183 static OPixmap& desaturate(OPixmap& pixmap, float desat = 0.3); 186 static OPixmap& desaturate(OPixmap& pixmap, float desat = 0.3);
184 187
185 /** 188 /**
186 * Modifies the contrast of a pixmap. 189 * Modifies the contrast of a pixmap.
187 * 190 *
188 * @param pixmap The pixmap to process. 191 * @param pixmap The pixmap to process.
189 * @param c A contrast value between -255 and 255. 192 * @param c A contrast value between -255 and 255.
190 * @return Returns the @ref pixmap(), provided for convenience. 193 * @return Returns the @ref pixmap(), provided for convenience.
191 */ 194 */
192 static OPixmap& contrast(OPixmap& pixmap, int c); 195 static OPixmap& contrast(OPixmap& pixmap, int c);
193 196
194 /** 197 /**
195 * Dithers a pixmap using Floyd-Steinberg dithering for low-color 198 * Dithers a pixmap using Floyd-Steinberg dithering for low-color
196 * situations. 199 * situations.
197 * 200 *
198 * @param pixmap The pixmap to process. 201 * @param pixmap The pixmap to process.
199 * @param palette The color palette to use. 202 * @param palette The color palette to use.
200 * @param size The size of the palette. 203 * @param size The size of the palette.
201 * @return Returns the @ref pixmap(), provided for convenience. 204 * @return Returns the @ref pixmap(), provided for convenience.
202 */ 205 */
203 static OPixmap& dither(OPixmap &pixmap, const QColor *palette, int size); 206 static OPixmap& dither(OPixmap &pixmap, const QColor *palette, int size);
204 207
205 /** 208 /**
206 * Calculate a 'selected' pixmap, for instance a selected icon 209 * Calculate a 'selected' pixmap, for instance a selected icon
207 * on the desktop. 210 * on the desktop.
208 * @param pixmap the pixmap to select 211 * @param pixmap the pixmap to select
209 * @param col the selected color, usually from QColorGroup::highlight(). 212 * @param col the selected color, usually from QColorGroup::highlight().
210 */ 213 */
211 static OPixmap selectedPixmap( const OPixmap &pixmap, const QColor &col ); 214 static OPixmap selectedPixmap( const OPixmap &pixmap, const QColor &col );
212}; 215};
213 216}
217}
214 218
215#endif 219#endif
diff --git a/libopie2/opieui/opixmapprovider.cpp b/libopie2/opieui/opixmapprovider.cpp
index 7be9e3b..7eb67a2 100644
--- a/libopie2/opieui/opixmapprovider.cpp
+++ b/libopie2/opieui/opixmapprovider.cpp
@@ -1,27 +1,29 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 2
3 Copyright (c) 2000 Carsten Pfeiffer <pfeiffer@kde.org> 3 Copyright (c) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
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 (LGPL) as published by the Free Software Foundation; either 7 License (LGPL) as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <opie2/opixmapprovider.h> 21#include <opie2/opixmapprovider.h>
22 22
23using namespace Opie::Ui;
24
23OPixmapProvider::~OPixmapProvider() {} 25OPixmapProvider::~OPixmapProvider() {}
24 26
25void OPixmapProvider::virtual_hook( int , void* ) 27void OPixmapProvider::virtual_hook( int , void* )
26{ /*BASE::virtual_hook( id, data );*/ } 28{ /*BASE::virtual_hook( id, data );*/ }
27 29
diff --git a/libopie2/opieui/opixmapprovider.h b/libopie2/opieui/opixmapprovider.h
index 5b76647..9d9bd69 100644
--- a/libopie2/opieui/opixmapprovider.h
+++ b/libopie2/opieui/opixmapprovider.h
@@ -1,54 +1,62 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 2
3 Copyright (c) 2000 Carsten Pfeiffer <pfeiffer@kde.org> 3 Copyright (c) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
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 (LGPL) as published by the Free Software Foundation; either 7 License (LGPL) as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#ifndef OPIXMAPPROVIDER_H 21#ifndef OPIXMAPPROVIDER_H
22#define OPIXMAPPROVIDER_H 22#define OPIXMAPPROVIDER_H
23 23
24#include <qpixmap.h> 24#include <qpixmap.h>
25 25
26namespace Opie {
27namespace Ui {
26/** 28/**
29 * \todo make usefull
27 * A tiny abstract class with just one method: 30 * A tiny abstract class with just one method:
28 * @ref pixmapFor() 31 * @ref pixmapFor()
29 * 32 *
30 * It will be called whenever an icon is searched for @p text. 33 * It will be called whenever an icon is searched for @p text.
31 * 34 *
32 * Used e.g. by @ref KHistoryCombo 35 * Used e.g. by @ref KHistoryCombo
33 * 36 *
34 * @author Carsten Pfeiffer <pfeiffer@kde.org> 37 * @author Carsten Pfeiffer <pfeiffer@kde.org>
35 * @short an abstract interface for looking up icons 38 * @short an abstract interface for looking up icons
36 */ 39 */
37class OPixmapProvider 40class OPixmapProvider
38{ 41{
39public: 42public:
40 virtual ~OPixmapProvider(); 43 virtual ~OPixmapProvider();
41 /** 44 /**
42 * You may subclass this and return a pixmap of size @p size for @p text. 45 * You may subclass this and return a pixmap of size @p size for @p text.
43 * @param text the text that is associated with the pixmap 46 * @param text the text that is associated with the pixmap
44 * @param size the size of the icon in pixels, 0 for defaylt size. 47 * @param size the size of the icon in pixels, 0 for defaylt size.
45 * See @ref KIcon::StdSize. 48 * See @ref KIcon::StdSize.
46 * @return the pixmap for the arguments, or null if there is none 49 * @return the pixmap for the arguments, or null if there is none
47 */ 50 */
48 virtual QPixmap pixmapFor( const QString& text, int size = 0 ) = 0; 51 virtual QPixmap pixmapFor( const QString& text, int size = 0 ) = 0;
49protected: 52protected:
50 virtual void virtual_hook( int id, void* data ); 53 virtual void virtual_hook( int id, void* data );
54private:
55 class Private;
56 Private *d;
51}; 57};
52 58
59}
60}
53 61
54#endif // OPIXMAPPROVIDER_H 62#endif // OPIXMAPPROVIDER_H
diff --git a/libopie2/opieui/opopupmenu.cpp b/libopie2/opieui/opopupmenu.cpp
index d5cc575..3ab8490 100644
--- a/libopie2/opieui/opopupmenu.cpp
+++ b/libopie2/opieui/opopupmenu.cpp
@@ -1,597 +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/* QT */ 20/* QT */
21 21
22#include <qdrawutil.h> 22#include <qdrawutil.h>
23#include <qtimer.h> 23#include <qtimer.h>
24 24
25/* OPIE */ 25/* OPIE */
26 26
27#include <opie2/opopupmenu.h> 27#include <opie2/opopupmenu.h>
28#include <opie2/oconfig.h> 28#include <opie2/oconfig.h>
29 29
30using namespace Opie::Core;
31using namespace Opie::Ui;
32
30OPopupTitle::OPopupTitle(QWidget *parent, const char *name) 33OPopupTitle::OPopupTitle(QWidget *parent, const char *name)
31 : QWidget(parent, name) 34 : QWidget(parent, name)
32{ 35{
33 setMinimumSize(16, fontMetrics().height()+8); 36 setMinimumSize(16, fontMetrics().height()+8);
34} 37}
35 38
36OPopupTitle::OPopupTitle(OPixmapEffect::GradientType /* gradient */, 39OPopupTitle::OPopupTitle(OPixmapEffect::GradientType /* gradient */,
37 const QColor &/* color */, const QColor &/* textColor */, 40 const QColor &/* color */, const QColor &/* textColor */,
38 QWidget *parent, const char *name) 41 QWidget *parent, const char *name)
39 : QWidget(parent, name) 42 : QWidget(parent, name)
40{ 43{
41 setMinimumSize(16, fontMetrics().height()+8); 44 setMinimumSize(16, fontMetrics().height()+8);
42} 45}
43 46
44OPopupTitle::OPopupTitle(const OPixmap & /* background */, const QColor &/* color */, 47OPopupTitle::OPopupTitle(const OPixmap & /* background */, const QColor &/* color */,
45 const QColor &/* textColor */, QWidget *parent, 48 const QColor &/* textColor */, QWidget *parent,
46 const char *name) 49 const char *name)
47 : QWidget(parent, name) 50 : QWidget(parent, name)
48{ 51{
49 setMinimumSize(16, fontMetrics().height()+8); 52 setMinimumSize(16, fontMetrics().height()+8);
50} 53}
51 54
52void OPopupTitle::setTitle(const QString &text, const QPixmap *icon) 55void OPopupTitle::setTitle(const QString &text, const QPixmap *icon)
53{ 56{
54 titleStr = text; 57 titleStr = text;
55 if (icon) 58 if (icon)
56 miniicon = *icon; 59 miniicon = *icon;
57 else 60 else
58 miniicon.resize(0, 0); 61 miniicon.resize(0, 0);
59 62
60 int w = miniicon.width()+fontMetrics().width(titleStr); 63 int w = miniicon.width()+fontMetrics().width(titleStr);
61 int h = QMAX( fontMetrics().height(), miniicon.height() ); 64 int h = QMAX( fontMetrics().height(), miniicon.height() );
62 setMinimumSize( w+16, h+8 ); 65 setMinimumSize( w+16, h+8 );
63} 66}
64 67
65void OPopupTitle::setText( const QString &text ) 68void OPopupTitle::setText( const QString &text )
66{ 69{
67 titleStr = text; 70 titleStr = text;
68 int w = miniicon.width()+fontMetrics().width(titleStr); 71 int w = miniicon.width()+fontMetrics().width(titleStr);
69 int h = QMAX( fontMetrics().height(), miniicon.height() ); 72 int h = QMAX( fontMetrics().height(), miniicon.height() );
70 setMinimumSize( w+16, h+8 ); 73 setMinimumSize( w+16, h+8 );
71} 74}
72 75
73void OPopupTitle::setIcon( const QPixmap &pix ) 76void OPopupTitle::setIcon( const QPixmap &pix )
74{ 77{
75 miniicon = pix; 78 miniicon = pix;
76 int w = miniicon.width()+fontMetrics().width(titleStr); 79 int w = miniicon.width()+fontMetrics().width(titleStr);
77 int h = QMAX( fontMetrics().height(), miniicon.height() ); 80 int h = QMAX( fontMetrics().height(), miniicon.height() );
78 setMinimumSize( w+16, h+8 ); 81 setMinimumSize( w+16, h+8 );
79} 82}
80 83
81void OPopupTitle::paintEvent(QPaintEvent *) 84void OPopupTitle::paintEvent(QPaintEvent *)
82{ 85{
83 QRect r(rect()); 86 QRect r(rect());
84 QPainter p(this); 87 QPainter p(this);
85 #if QT_VERSION > 290 88 #if QT_VERSION > 290
86 qApp->style().drawPrimitive(QStyle::PE_HeaderSection, &p, r, palette().active()); 89 qApp->style().drawPrimitive(QStyle::PE_HeaderSection, &p, r, palette().active());
87 #else 90 #else
88 #warning OPopupMenu is not fully functional on Qt2 91 #warning OPopupMenu is not fully functional on Qt2
89 #endif 92 #endif
90 93
91 if (!miniicon.isNull()) 94 if (!miniicon.isNull())
92 p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon); 95 p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon);
93 96
94 if (!titleStr.isNull()) 97 if (!titleStr.isNull())
95 { 98 {
96 p.setPen(palette().active().text()); 99 p.setPen(palette().active().text());
97 QFont f = p.font(); 100 QFont f = p.font();
98 f.setBold(true); 101 f.setBold(true);
99 p.setFont(f); 102 p.setFont(f);
100 if(!miniicon.isNull()) 103 if(!miniicon.isNull())
101 { 104 {
102 p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8), 105 p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8),
103 height(), AlignLeft | AlignVCenter | SingleLine, 106 height(), AlignLeft | AlignVCenter | SingleLine,
104 titleStr); 107 titleStr);
105 } 108 }
106 else 109 else
107 { 110 {
108 p.drawText(0, 0, width(), height(), 111 p.drawText(0, 0, width(), height(),
109 AlignCenter | SingleLine, titleStr); 112 AlignCenter | SingleLine, titleStr);
110 } 113 }
111 } 114 }
112 115
113 p.setPen(palette().active().highlight()); 116 p.setPen(palette().active().highlight());
114 p.drawLine(0, 0, r.right(), 0); 117 p.drawLine(0, 0, r.right(), 0);
115} 118}
116 119
117QSize OPopupTitle::sizeHint() const 120QSize OPopupTitle::sizeHint() const
118{ 121{
119 return(minimumSize()); 122 return(minimumSize());
120} 123}
121 124
122class OPopupMenu::OPopupMenuPrivate 125class OPopupMenu::OPopupMenuPrivate
123{ 126{
124public: 127public:
125 OPopupMenuPrivate () 128 OPopupMenuPrivate ()
126 : noMatches(false) 129 : noMatches(false)
127 , shortcuts(false) 130 , shortcuts(false)
128 , autoExec(false) 131 , autoExec(false)
129 , lastHitIndex(-1) 132 , lastHitIndex(-1)
130 , m_ctxMenu(0) 133 , m_ctxMenu(0)
131 {} 134 {}
132 135
133 ~OPopupMenuPrivate () 136 ~OPopupMenuPrivate ()
134 { 137 {
135 delete m_ctxMenu; 138 delete m_ctxMenu;
136 } 139 }
137 140
138 QString m_lastTitle; 141 QString m_lastTitle;
139 142
140 // variables for keyboard navigation 143 // variables for keyboard navigation
141 QTimer clearTimer; 144 QTimer clearTimer;
142 145
143 bool noMatches : 1; 146 bool noMatches : 1;
144 bool shortcuts : 1; 147 bool shortcuts : 1;
145 bool autoExec : 1; 148 bool autoExec : 1;
146 149
147 QString keySeq; 150 QString keySeq;
148 QString originalText; 151 QString originalText;
149 152
150 int lastHitIndex; 153 int lastHitIndex;
151 154
152 // support for RMB menus on menus 155 // support for RMB menus on menus
153 QPopupMenu* m_ctxMenu; 156 QPopupMenu* m_ctxMenu;
154 static bool s_continueCtxMenuShow; 157 static bool s_continueCtxMenuShow;
155 static int s_highlightedItem; 158 static int s_highlightedItem;
156 static OPopupMenu* s_contextedMenu; 159 static OPopupMenu* s_contextedMenu;
157}; 160};
158 161
159int OPopupMenu::OPopupMenuPrivate::s_highlightedItem(-1); 162int OPopupMenu::OPopupMenuPrivate::s_highlightedItem(-1);
160OPopupMenu* OPopupMenu::OPopupMenuPrivate::s_contextedMenu(0); 163OPopupMenu* OPopupMenu::OPopupMenuPrivate::s_contextedMenu(0);
161bool OPopupMenu::OPopupMenuPrivate::s_continueCtxMenuShow(true); 164bool OPopupMenu::OPopupMenuPrivate::s_continueCtxMenuShow(true);
162 165
163OPopupMenu::OPopupMenu(QWidget *parent, const char *name) 166OPopupMenu::OPopupMenu(QWidget *parent, const char *name)
164 : QPopupMenu(parent, name) 167 : QPopupMenu(parent, name)
165{ 168{
166 d = new OPopupMenuPrivate; 169 d = new OPopupMenuPrivate;
167 resetKeyboardVars(); 170 resetKeyboardVars();
168 connect(&(d->clearTimer), SIGNAL(timeout()), SLOT(resetKeyboardVars())); 171 connect(&(d->clearTimer), SIGNAL(timeout()), SLOT(resetKeyboardVars()));
169} 172}
170 173
171OPopupMenu::~OPopupMenu() 174OPopupMenu::~OPopupMenu()
172{ 175{
173 if (OPopupMenuPrivate::s_contextedMenu == this) 176 if (OPopupMenuPrivate::s_contextedMenu == this)
174 { 177 {
175 OPopupMenuPrivate::s_contextedMenu = 0; 178 OPopupMenuPrivate::s_contextedMenu = 0;
176 OPopupMenuPrivate::s_highlightedItem = -1; 179 OPopupMenuPrivate::s_highlightedItem = -1;
177 } 180 }
178 181
179 delete d; 182 delete d;
180} 183}
181 184
182int OPopupMenu::insertTitle(const QString &text, int id, int index) 185int OPopupMenu::insertTitle(const QString &text, int id, int index)
183{ 186{
184 OPopupTitle *titleItem = new OPopupTitle(); 187 OPopupTitle *titleItem = new OPopupTitle();
185 titleItem->setTitle(text); 188 titleItem->setTitle(text);
186 int ret = insertItem(titleItem, id, index); 189 int ret = insertItem(titleItem, id, index);
187 setItemEnabled(id, false); 190 setItemEnabled(id, false);
188 return ret; 191 return ret;
189} 192}
190 193
191int OPopupMenu::insertTitle(const QPixmap &icon, const QString &text, int id, 194int OPopupMenu::insertTitle(const QPixmap &icon, const QString &text, int id,
192 int index) 195 int index)
193{ 196{
194 OPopupTitle *titleItem = new OPopupTitle(); 197 OPopupTitle *titleItem = new OPopupTitle();
195 titleItem->setTitle(text, &icon); 198 titleItem->setTitle(text, &icon);
196 int ret = insertItem(titleItem, id, index); 199 int ret = insertItem(titleItem, id, index);
197 setItemEnabled(id, false); 200 setItemEnabled(id, false);
198 return ret; 201 return ret;
199} 202}
200 203
201void OPopupMenu::changeTitle(int id, const QString &text) 204void OPopupMenu::changeTitle(int id, const QString &text)
202{ 205{
203 QMenuItem *item = findItem(id); 206 QMenuItem *item = findItem(id);
204 if(item){ 207 if(item){
205 if(item->widget()) 208 if(item->widget())
206 ((OPopupTitle *)item->widget())->setTitle(text); 209 ((OPopupTitle *)item->widget())->setTitle(text);
207#ifndef NDEBUG 210#ifndef NDEBUG
208 else 211 else
209 qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id ); 212 qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id );
210#endif 213#endif
211 } 214 }
212#ifndef NDEBUG 215#ifndef NDEBUG
213 else 216 else
214 qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id ); 217 qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id );
215#endif 218#endif
216} 219}
217 220
218void OPopupMenu::changeTitle(int id, const QPixmap &icon, const QString &text) 221void OPopupMenu::changeTitle(int id, const QPixmap &icon, const QString &text)
219{ 222{
220 QMenuItem *item = findItem(id); 223 QMenuItem *item = findItem(id);
221 if(item){ 224 if(item){
222 if(item->widget()) 225 if(item->widget())
223 ((OPopupTitle *)item->widget())->setTitle(text, &icon); 226 ((OPopupTitle *)item->widget())->setTitle(text, &icon);
224#ifndef NDEBUG 227#ifndef NDEBUG
225 else 228 else
226 qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id ); 229 qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id );
227#endif 230#endif
228 } 231 }
229#ifndef NDEBUG 232#ifndef NDEBUG
230 else 233 else
231 qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id ); 234 qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id );
232#endif 235#endif
233} 236}
234 237
235QString OPopupMenu::title(int id) const 238QString OPopupMenu::title(int id) const
236{ 239{
237 if(id == -1) // obsolete 240 if(id == -1) // obsolete
238 return(d->m_lastTitle); 241 return(d->m_lastTitle);
239 QMenuItem *item = findItem(id); 242 QMenuItem *item = findItem(id);
240 if(item){ 243 if(item){
241 if(item->widget()) 244 if(item->widget())
242 return(((OPopupTitle *)item->widget())->title()); 245 return(((OPopupTitle *)item->widget())->title());
243 else 246 else
244 qWarning("OPopupMenu: title() called with non-title id %d.", id); 247 qWarning("OPopupMenu: title() called with non-title id %d.", id);
245 } 248 }
246 else 249 else
247 qWarning("OPopupMenu: title() called with invalid id %d.", id); 250 qWarning("OPopupMenu: title() called with invalid id %d.", id);
248 return(QString::null); 251 return(QString::null);
249} 252}
250 253
251QPixmap OPopupMenu::titlePixmap(int id) const 254QPixmap OPopupMenu::titlePixmap(int id) const
252{ 255{
253 QMenuItem *item = findItem(id); 256 QMenuItem *item = findItem(id);
254 if(item){ 257 if(item){
255 if(item->widget()) 258 if(item->widget())
256 return(((OPopupTitle *)item->widget())->icon()); 259 return(((OPopupTitle *)item->widget())->icon());
257 else 260 else
258 qWarning("KPopupMenu: titlePixmap() called with non-title id %d.", id); 261 qWarning("KPopupMenu: titlePixmap() called with non-title id %d.", id);
259 } 262 }
260 else 263 else
261 qWarning("KPopupMenu: titlePixmap() called with invalid id %d.", id); 264 qWarning("KPopupMenu: titlePixmap() called with invalid id %d.", id);
262 QPixmap tmp; 265 QPixmap tmp;
263 return(tmp); 266 return(tmp);
264} 267}
265 268
266/** 269/**
267 * This is re-implemented for keyboard navigation. 270 * This is re-implemented for keyboard navigation.
268 */ 271 */
269void OPopupMenu::closeEvent(QCloseEvent*e) 272void OPopupMenu::closeEvent(QCloseEvent*e)
270{ 273{
271 if (d->shortcuts) 274 if (d->shortcuts)
272 resetKeyboardVars(); 275 resetKeyboardVars();
273 QPopupMenu::closeEvent(e); 276 QPopupMenu::closeEvent(e);
274} 277}
275 278
276void OPopupMenu::keyPressEvent(QKeyEvent* e) 279void OPopupMenu::keyPressEvent(QKeyEvent* e)
277{ 280{
278 if (!d->shortcuts) { 281 if (!d->shortcuts) {
279 // continue event processing by Qpopup 282 // continue event processing by Qpopup
280 //e->ignore(); 283 //e->ignore();
281 QPopupMenu::keyPressEvent(e); 284 QPopupMenu::keyPressEvent(e);
282 return; 285 return;
283 } 286 }
284 287
285 int i = 0; 288 int i = 0;
286 bool firstpass = true; 289 bool firstpass = true;
287 QString keyString = e->text(); 290 QString keyString = e->text();
288 291
289 // check for common commands dealt with by QPopup 292 // check for common commands dealt with by QPopup
290 int key = e->key(); 293 int key = e->key();
291 if (key == Key_Escape || key == Key_Return || key == Key_Enter 294 if (key == Key_Escape || key == Key_Return || key == Key_Enter
292 || key == Key_Up || key == Key_Down || key == Key_Left 295 || key == Key_Up || key == Key_Down || key == Key_Left
293 || key == Key_Right || key == Key_F1) { 296 || key == Key_Right || key == Key_F1) {
294 297
295 resetKeyboardVars(); 298 resetKeyboardVars();
296 // continue event processing by Qpopup 299 // continue event processing by Qpopup
297 //e->ignore(); 300 //e->ignore();
298 QPopupMenu::keyPressEvent(e); 301 QPopupMenu::keyPressEvent(e);
299 return; 302 return;
300 } 303 }
301 304
302 // 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)
303 // or clear the sequence (delete) 306 // or clear the sequence (delete)
304 if (!d->keySeq.isNull()) { 307 if (!d->keySeq.isNull()) {
305 308
306 if (key == Key_Backspace) { 309 if (key == Key_Backspace) {
307 310
308 if (d->keySeq.length() == 1) { 311 if (d->keySeq.length() == 1) {
309 resetKeyboardVars(); 312 resetKeyboardVars();
310 return; 313 return;
311 } 314 }
312 315
313 // keep the last sequence in keyString 316 // keep the last sequence in keyString
314 keyString = d->keySeq.left(d->keySeq.length() - 1); 317 keyString = d->keySeq.left(d->keySeq.length() - 1);
315 318
316 // allow sequence matching to be tried again 319 // allow sequence matching to be tried again
317 resetKeyboardVars(); 320 resetKeyboardVars();
318 321
319 } else if (key == Key_Delete) { 322 } else if (key == Key_Delete) {
320 resetKeyboardVars(); 323 resetKeyboardVars();
321 324
322 // clear active item 325 // clear active item
323 setActiveItem(0); 326 setActiveItem(0);
324 return; 327 return;
325 328
326 } else if (d->noMatches) { 329 } else if (d->noMatches) {
327 // clear if there are no matches 330 // clear if there are no matches
328 resetKeyboardVars(); 331 resetKeyboardVars();
329 332
330 // clear active item 333 // clear active item
331 setActiveItem(0); 334 setActiveItem(0);
332 335
333 } else { 336 } else {
334 // the key sequence is not a null string 337 // the key sequence is not a null string
335 // therefore the lastHitIndex is valid 338 // therefore the lastHitIndex is valid
336 i = d->lastHitIndex; 339 i = d->lastHitIndex;
337 } 340 }
338 } else if (key == Key_Backspace && parentMenu) { 341 } else if (key == Key_Backspace && parentMenu) {
339 // backspace with no chars in the buffer... go back a menu. 342 // backspace with no chars in the buffer... go back a menu.
340 hide(); 343 hide();
341 resetKeyboardVars(); 344 resetKeyboardVars();
342 return; 345 return;
343 } 346 }
344 347
345 d->keySeq += keyString; 348 d->keySeq += keyString;
346 int seqLen = d->keySeq.length(); 349 int seqLen = d->keySeq.length();
347 350
348 for (; i < (int)count(); i++) { 351 for (; i < (int)count(); i++) {
349 // compare typed text with text of this entry 352 // compare typed text with text of this entry
350 int j = idAt(i); 353 int j = idAt(i);
351 354
352 // don't search disabled entries 355 // don't search disabled entries
353 if (!isItemEnabled(j)) 356 if (!isItemEnabled(j))
354 continue; 357 continue;
355 358
356 QString thisText; 359 QString thisText;
357 360
358 // retrieve the right text 361 // retrieve the right text
359 // (the last selected item one may have additional ampersands) 362 // (the last selected item one may have additional ampersands)
360 if (i == d->lastHitIndex) 363 if (i == d->lastHitIndex)
361 thisText = d->originalText; 364 thisText = d->originalText;
362 else 365 else
363 thisText = text(j); 366 thisText = text(j);
364 367
365 // if there is an accelerator present, remove it 368 // if there is an accelerator present, remove it
366 if ((int)accel(j) != 0) 369 if ((int)accel(j) != 0)
367 thisText = thisText.replace(QRegExp("&"), ""); 370 thisText = thisText.replace(QRegExp("&"), "");
368 371
369 // chop text to the search length 372 // chop text to the search length
370 thisText = thisText.left(seqLen); 373 thisText = thisText.left(seqLen);
371 374
372 // do the search 375 // do the search
373 if (thisText.find(d->keySeq, 0, false) == 0) { 376 if (thisText.find(d->keySeq, 0, false) == 0) {
374 377
375 if (firstpass) { 378 if (firstpass) {
376 // match 379 // match
377 setActiveItem(i); 380 setActiveItem(i);
378 381
379 // check to see if we're underlining a different item 382 // check to see if we're underlining a different item
380 if (d->lastHitIndex != i) 383 if (d->lastHitIndex != i)
381 // yes; revert the underlining 384 // yes; revert the underlining
382 changeItem(idAt(d->lastHitIndex), d->originalText); 385 changeItem(idAt(d->lastHitIndex), d->originalText);
383 386
384 // set the original text if it's a different item 387 // set the original text if it's a different item
385 if (d->lastHitIndex != i || d->lastHitIndex == -1) 388 if (d->lastHitIndex != i || d->lastHitIndex == -1)
386 d->originalText = text(j); 389 d->originalText = text(j);
387 390
388 // underline the currently selected item 391 // underline the currently selected item
389 changeItem(j, underlineText(d->originalText, d->keySeq.length())); 392 changeItem(j, underlineText(d->originalText, d->keySeq.length()));
390 393
391 // remeber what's going on 394 // remeber what's going on
392 d->lastHitIndex = i; 395 d->lastHitIndex = i;
393 396
394 // start/restart the clear timer 397 // start/restart the clear timer
395 d->clearTimer.start(5000, true); 398 d->clearTimer.start(5000, true);
396 399
397 // go around for another try, to see if we can execute 400 // go around for another try, to see if we can execute
398 firstpass = false; 401 firstpass = false;
399 } else { 402 } else {
400 // don't allow execution 403 // don't allow execution
401 return; 404 return;
402 } 405 }
403 } 406 }
404 407
405 // fall through to allow execution 408 // fall through to allow execution
406 } 409 }
407 410
408 if (!firstpass) { 411 if (!firstpass) {
409 if (d->autoExec) { 412 if (d->autoExec) {
410 // activate anything 413 // activate anything
411 activateItemAt(d->lastHitIndex); 414 activateItemAt(d->lastHitIndex);
412 resetKeyboardVars(); 415 resetKeyboardVars();
413 416
414 } else if (findItem(idAt(d->lastHitIndex)) && 417 } else if (findItem(idAt(d->lastHitIndex)) &&
415 findItem(idAt(d->lastHitIndex))->popup()) { 418 findItem(idAt(d->lastHitIndex))->popup()) {
416 // only activate sub-menus 419 // only activate sub-menus
417 activateItemAt(d->lastHitIndex); 420 activateItemAt(d->lastHitIndex);
418 resetKeyboardVars(); 421 resetKeyboardVars();
419 } 422 }
420 423
421 return; 424 return;
422 } 425 }
423 426
424 // no matches whatsoever, clean up 427 // no matches whatsoever, clean up
425 resetKeyboardVars(true); 428 resetKeyboardVars(true);
426 //e->ignore(); 429 //e->ignore();
427 QPopupMenu::keyPressEvent(e); 430 QPopupMenu::keyPressEvent(e);
428} 431}
429 432
430QString OPopupMenu::underlineText(const QString& text, uint length) 433QString OPopupMenu::underlineText(const QString& text, uint length)
431{ 434{
432 QString ret = text; 435 QString ret = text;
433 for (uint i = 0; i < length; i++) { 436 for (uint i = 0; i < length; i++) {
434 if (ret[2*i] != '&') 437 if (ret[2*i] != '&')
435 ret.insert(2*i, "&"); 438 ret.insert(2*i, "&");
436 } 439 }
437 return ret; 440 return ret;
438} 441}
439 442
440void OPopupMenu::resetKeyboardVars(bool noMatches /* = false */) 443void OPopupMenu::resetKeyboardVars(bool noMatches /* = false */)
441{ 444{
442 // Clean up keyboard variables 445 // Clean up keyboard variables
443 if (d->lastHitIndex != -1) { 446 if (d->lastHitIndex != -1) {
444 changeItem(idAt(d->lastHitIndex), d->originalText); 447 changeItem(idAt(d->lastHitIndex), d->originalText);
445 d->lastHitIndex = -1; 448 d->lastHitIndex = -1;
446 } 449 }
447 450
448 if (!noMatches) { 451 if (!noMatches) {
449 d->keySeq = QString::null; 452 d->keySeq = QString::null;
450 } 453 }
451 454
452 d->noMatches = noMatches; 455 d->noMatches = noMatches;
453} 456}
454 457
455void OPopupMenu::setKeyboardShortcutsEnabled(bool enable) 458void OPopupMenu::setKeyboardShortcutsEnabled(bool enable)
456{ 459{
457 d->shortcuts = enable; 460 d->shortcuts = enable;
458} 461}
459 462
460void OPopupMenu::setKeyboardShortcutsExecute(bool enable) 463void OPopupMenu::setKeyboardShortcutsExecute(bool enable)
461{ 464{
462 d->autoExec = enable; 465 d->autoExec = enable;
463} 466}
464/** 467/**
465 * End keyboard navigation. 468 * End keyboard navigation.
466 */ 469 */
467 470
468/** 471/**
469 * RMB menus on menus 472 * RMB menus on menus
470 */ 473 */
471QPopupMenu* OPopupMenu::contextMenu() 474QPopupMenu* OPopupMenu::contextMenu()
472{ 475{
473 if (!d->m_ctxMenu) 476 if (!d->m_ctxMenu)
474 { 477 {
475 d->m_ctxMenu = new QPopupMenu(this); 478 d->m_ctxMenu = new QPopupMenu(this);
476 installEventFilter(this); 479 installEventFilter(this);
477 connect(d->m_ctxMenu, SIGNAL(aboutToHide()), this, SLOT(ctxMenuHiding())); 480 connect(d->m_ctxMenu, SIGNAL(aboutToHide()), this, SLOT(ctxMenuHiding()));
478 } 481 }
479 482
480 return d->m_ctxMenu; 483 return d->m_ctxMenu;
481} 484}
482 485
483void OPopupMenu::cancelContextMenuShow() 486void OPopupMenu::cancelContextMenuShow()
484{ 487{
485 OPopupMenuPrivate::s_continueCtxMenuShow = false; 488 OPopupMenuPrivate::s_continueCtxMenuShow = false;
486} 489}
487 490
488int OPopupMenu::contextMenuFocusItem() 491int OPopupMenu::contextMenuFocusItem()
489{ 492{
490 return OPopupMenuPrivate::s_highlightedItem; 493 return OPopupMenuPrivate::s_highlightedItem;
491} 494}
492 495
493OPopupMenu* OPopupMenu::contextMenuFocus() 496OPopupMenu* OPopupMenu::contextMenuFocus()
494{ 497{
495 return OPopupMenuPrivate::s_contextedMenu; 498 return OPopupMenuPrivate::s_contextedMenu;
496} 499}
497 500
498void OPopupMenu::itemHighlighted(int /* whichItem */) 501void OPopupMenu::itemHighlighted(int /* whichItem */)
499{ 502{
500 if (!d->m_ctxMenu || !d->m_ctxMenu->isVisible()) 503 if (!d->m_ctxMenu || !d->m_ctxMenu->isVisible())
501 { 504 {
502 return; 505 return;
503 } 506 }
504 507
505 d->m_ctxMenu->hide(); 508 d->m_ctxMenu->hide();
506 showCtxMenu(mapFromGlobal(QCursor::pos())); 509 showCtxMenu(mapFromGlobal(QCursor::pos()));
507} 510}
508 511
509void OPopupMenu::showCtxMenu(QPoint pos) 512void OPopupMenu::showCtxMenu(QPoint pos)
510{ 513{
511 OPopupMenuPrivate::s_highlightedItem = idAt(pos); 514 OPopupMenuPrivate::s_highlightedItem = idAt(pos);
512 515
513 if (OPopupMenuPrivate::s_highlightedItem == -1) 516 if (OPopupMenuPrivate::s_highlightedItem == -1)
514 { 517 {
515 OPopupMenuPrivate::s_contextedMenu = 0; 518 OPopupMenuPrivate::s_contextedMenu = 0;
516 return; 519 return;
517 } 520 }
518 521
519 emit aboutToShowContextMenu(this, OPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu); 522 emit aboutToShowContextMenu(this, OPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu);
520 523
521 if (!OPopupMenuPrivate::s_continueCtxMenuShow) 524 if (!OPopupMenuPrivate::s_continueCtxMenuShow)
522 { 525 {
523 OPopupMenuPrivate::s_continueCtxMenuShow = true; 526 OPopupMenuPrivate::s_continueCtxMenuShow = true;
524 return; 527 return;
525 } 528 }
526 529
527 OPopupMenuPrivate::s_contextedMenu = this; 530 OPopupMenuPrivate::s_contextedMenu = this;
528 d->m_ctxMenu->popup(this->mapToGlobal(pos)); 531 d->m_ctxMenu->popup(this->mapToGlobal(pos));
529 connect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int))); 532 connect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int)));
530} 533}
531 534
532void OPopupMenu::ctxMenuHiding() 535void OPopupMenu::ctxMenuHiding()
533{ 536{
534 disconnect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int))); 537 disconnect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int)));
535 OPopupMenuPrivate::s_continueCtxMenuShow = true; 538 OPopupMenuPrivate::s_continueCtxMenuShow = true;
536} 539}
537 540
538bool OPopupMenu::eventFilter(QObject* obj, QEvent* event) 541bool OPopupMenu::eventFilter(QObject* obj, QEvent* event)
539{ 542{
540 if (d->m_ctxMenu && obj == this) 543 if (d->m_ctxMenu && obj == this)
541 { 544 {
542 if (event->type() == QEvent::MouseButtonRelease) 545 if (event->type() == QEvent::MouseButtonRelease)
543 { 546 {
544 if (d->m_ctxMenu->isVisible()) 547 if (d->m_ctxMenu->isVisible())
545 { 548 {
546 return true; 549 return true;
547 } 550 }
548 } 551 }
549 #if QT_VERSION > 290 552 #if QT_VERSION > 290
550 else if (event->type() == QEvent::ContextMenu) 553 else if (event->type() == QEvent::ContextMenu)
551 #else 554 #else
552 else if ( (event->type() == QEvent::MouseButtonPress) && 555 else if ( (event->type() == QEvent::MouseButtonPress) &&
553 ( (QMouseEvent*) event )->button() == QMouseEvent::RightButton ) 556 ( (QMouseEvent*) event )->button() == QMouseEvent::RightButton )
554 #endif 557 #endif
555 { 558 {
556 showCtxMenu(mapFromGlobal(QCursor::pos())); 559 showCtxMenu(mapFromGlobal(QCursor::pos()));
557 return true; 560 return true;
558 } 561 }
559 } 562 }
560 563
561 return QWidget::eventFilter(obj, event); 564 return QWidget::eventFilter(obj, event);
562} 565}
563 566
564void OPopupMenu::hideEvent(QHideEvent*) 567void OPopupMenu::hideEvent(QHideEvent*)
565{ 568{
566 if (d->m_ctxMenu) 569 if (d->m_ctxMenu)
567 { 570 {
568 d->m_ctxMenu->hide(); 571 d->m_ctxMenu->hide();
569 } 572 }
570} 573}
571/** 574/**
572 * end of RMB menus on menus support 575 * end of RMB menus on menus support
573 */ 576 */
574 577
575// Obsolete 578// Obsolete
576OPopupMenu::OPopupMenu(const QString& title, QWidget *parent, const char *name) 579OPopupMenu::OPopupMenu(const QString& title, QWidget *parent, const char *name)
577 : QPopupMenu(parent, name) 580 : QPopupMenu(parent, name)
578{ 581{
579 d = new OPopupMenuPrivate; 582 d = new OPopupMenuPrivate;
580 setTitle(title); 583 setTitle(title);
581} 584}
582 585
583// Obsolete 586// Obsolete
584void OPopupMenu::setTitle(const QString &title) 587void OPopupMenu::setTitle(const QString &title)
585{ 588{
586 OPopupTitle *titleItem = new OPopupTitle(); 589 OPopupTitle *titleItem = new OPopupTitle();
587 titleItem->setTitle(title); 590 titleItem->setTitle(title);
588 insertItem(titleItem); 591 insertItem(titleItem);
589 d->m_lastTitle = title; 592 d->m_lastTitle = title;
590} 593}
591 594
592void OPopupTitle::virtual_hook( int, void* ) 595void OPopupTitle::virtual_hook( int, void* )
593{ /*BASE::virtual_hook( id, data );*/ } 596{ /*BASE::virtual_hook( id, data );*/ }
594 597
595void OPopupMenu::virtual_hook( int, void* ) 598void OPopupMenu::virtual_hook( int, void* )
596{ /*BASE::virtual_hook( id, data );*/ } 599{ /*BASE::virtual_hook( id, data );*/ }
597 600
diff --git a/libopie2/opieui/opopupmenu.h b/libopie2/opieui/opopupmenu.h
index 54e4301..419a954 100644
--- a/libopie2/opieui/opopupmenu.h
+++ b/libopie2/opieui/opopupmenu.h
@@ -1,259 +1,264 @@
1//FIXME what is ODE? ODE Desktop Environemt? -zecke 1//FIXME what is ODE? ODE Desktop Environemt? -zecke
2//FIXME do we need titles? space is limited that is only eyecandy? -zecke 2//FIXME do we need titles? space is limited that is only eyecandy? -zecke
3//FIXME keyboard navigation is also not that popular on a PDA might be with a keyboard (tuxphone) -zecke 3//FIXME keyboard navigation is also not that popular on a PDA might be with a keyboard (tuxphone) -zecke
4/* This file is part of the ODE libraries 4/* This file is part of the ODE libraries
5 Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org> 5 Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License version 2 as published by the Free Software Foundation. 9 License version 2 as published by the Free Software Foundation.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21#ifndef _OPOPUP_H 21#ifndef _OPOPUP_H
22#define _OPOPUP_H 22#define _OPOPUP_H
23 23
24#define INCLUDE_MENUITEM_DEF 24#define INCLUDE_MENUITEM_DEF
25 25
26/* QT */ 26/* QT */
27 27
28#include <qpopupmenu.h> 28#include <qpopupmenu.h>
29 29
30/* OPIE */ 30/* OPIE */
31 31
32#include <opie2/opixmapeffect.h> 32#include <opie2/opixmapeffect.h>
33 33
34namespace Opie {
35namespace Ui {
34/** 36/**
35 * Title widget for use in @ref OPopupMenu. 37 * Title widget for use in @ref OPopupMenu.
36 * 38 *
37 * You usually don't have to create this manually since 39 * You usually don't have to create this manually since
38 * @ref OPopupMenu::insertTitle will do it for you, but it is allowed if 40 * @ref OPopupMenu::insertTitle will do it for you, but it is allowed if
39 * you wish to customize it's look. 41 * you wish to customize it's look.
40 * 42 *
41 * @author Daniel M. Duley <mosfet@kde.org> 43 * @author Daniel M. Duley <mosfet@kde.org>
42 * @short OPopupMenu title widget. 44 * @short OPopupMenu title widget.
43 */ 45 */
44class OPopupTitle : public QWidget 46class OPopupTitle : public QWidget
45{ 47{
46 Q_OBJECT 48 Q_OBJECT
47 49
48public: 50public:
49 /** 51 /**
50 * Constructs a title widget with the user specified gradient, pixmap, 52 * Constructs a title widget with the user specified gradient, pixmap,
51 * and colors. 53 * and colors.
52 */ 54 */
53 OPopupTitle(QWidget *parent=0, const char *name=0); 55 OPopupTitle(QWidget *parent=0, const char *name=0);
54 /** 56 /**
55 * @deprecated 57 * @deprecated
56 * Constructs a title widget with the specified gradient and colors. 58 * Constructs a title widget with the specified gradient and colors.
57 */ 59 */
58 OPopupTitle(OPixmapEffect::GradientType gradient, const QColor &color, 60 OPopupTitle(OPixmapEffect::GradientType gradient, const QColor &color,
59 const QColor &textColor, QWidget *parent=0, 61 const QColor &textColor, QWidget *parent=0,
60 const char *name=0); 62 const char *name=0);
61 /** 63 /**
62 * @deprecated 64 * @deprecated
63 * Constructs a title widget with the specified pixmap and colors. 65 * Constructs a title widget with the specified pixmap and colors.
64 */ 66 */
65 OPopupTitle(const OPixmap &background, const QColor &color, 67 OPopupTitle(const OPixmap &background, const QColor &color,
66 const QColor &textColor, QWidget *parent=0, 68 const QColor &textColor, QWidget *parent=0,
67 const char *name=0); 69 const char *name=0);
68 /** 70 /**
69 * Sets the title string and optional icon for the title widget. 71 * Sets the title string and optional icon for the title widget.
70 * 72 *
71 * You will want to call this before inserting into a menu. 73 * You will want to call this before inserting into a menu.
72 */ 74 */
73 void setTitle(const QString &text, const QPixmap *icon=NULL); 75 void setTitle(const QString &text, const QPixmap *icon=NULL);
74 /** 76 /**
75 * Returns the current title. 77 * Returns the current title.
76 */ 78 */
77 QString title() const { return(titleStr); } 79 QString title() const { return(titleStr); }
78 /** 80 /**
79 * Returns the current icon. 81 * Returns the current icon.
80 */ 82 */
81 QPixmap icon() const { return(miniicon); } 83 QPixmap icon() const { return(miniicon); }
82 84
83 QSize sizeHint() const; 85 QSize sizeHint() const;
84 86
85public slots: 87public slots:
86 /// @since 3.1 88 /// @since 3.1
87 void setText( const QString &text ); 89 void setText( const QString &text );
88 /// @since 3.1 90 /// @since 3.1
89 void setIcon( const QPixmap &pix ); 91 void setIcon( const QPixmap &pix );
90 92
91protected: 93protected:
92 void paintEvent(QPaintEvent *ev); 94 void paintEvent(QPaintEvent *ev);
93 95
94 QString titleStr; 96 QString titleStr;
95 QPixmap miniicon; 97 QPixmap miniicon;
96 98
97 // Remove in KDE4 99 // Remove in KDE4
98 OPixmapEffect::GradientType grType; 100 OPixmapEffect::GradientType grType;
99 QPixmap fill; 101 QPixmap fill;
100 QColor fgColor, bgColor, grHigh, grLow; 102 QColor fgColor, bgColor, grHigh, grLow;
101 bool useGradient; 103 bool useGradient;
102 104
103protected: 105protected:
104 virtual void virtual_hook( int id, void* data ); 106 virtual void virtual_hook( int id, void* data );
105private: 107private:
106 class OPopupTitlePrivate; 108 class OPopupTitlePrivate;
107 OPopupTitlePrivate *d; 109 OPopupTitlePrivate *d;
108}; 110};
109 111
110/** 112/**
111 * OPopupMenu is a class for menus with standard title items and keyboard 113 * OPopupMenu is a class for menus with standard title items and keyboard
112 * accessibility for popups with many options and/or varying options. It acts 114 * accessibility for popups with many options and/or varying options. It acts
113 * identically to QPopupMenu, with the addition of insertTitle(), 115 * identically to QPopupMenu, with the addition of insertTitle(),
114 * changeTitle(), setKeyboardShortcutsEnabled() and 116 * changeTitle(), setKeyboardShortcutsEnabled() and
115 * setKeyboardShortcutsExecute() methods. 117 * setKeyboardShortcutsExecute() methods.
116 * 118 *
117 * The titles support a text string, an icon, plus user defined gradients, 119 * The titles support a text string, an icon, plus user defined gradients,
118 * colors, and background pixmaps. 120 * colors, and background pixmaps.
119 * 121 *
120 * The keyboard search algorithm is incremental with additional underlining 122 * The keyboard search algorithm is incremental with additional underlining
121 * for user feedback. 123 * for user feedback.
122 * 124 *
123 * @short A menu with title items. 125 * @short A menu with title items.
124 * @author Daniel M. Duley <mosfet@kde.org> 126 * @author Daniel M. Duley <mosfet@kde.org>
125 * @author Hamish Rodda <meddie@yoyo.its.monash.edu.au> 127 * @author Hamish Rodda <meddie@yoyo.its.monash.edu.au>
126 */ 128 */
127class OPopupMenu : public QPopupMenu { 129class OPopupMenu : public QPopupMenu {
128 Q_OBJECT 130 Q_OBJECT
129public: 131public:
130 /** 132 /**
131 * Constructs a OPopupMenu. 133 * Constructs a OPopupMenu.
132 */ 134 */
133 OPopupMenu(QWidget *parent=0, const char *name=0); 135 OPopupMenu(QWidget *parent=0, const char *name=0);
134 136
135 /** 137 /**
136 * Destructs the object 138 * Destructs the object
137 */ 139 */
138 ~OPopupMenu(); 140 ~OPopupMenu();
139 141
140 /** 142 /**
141 * Inserts a title item with no icon. 143 * Inserts a title item with no icon.
142 */ 144 */
143 int insertTitle(const QString &text, int id=-1, int index=-1); 145 int insertTitle(const QString &text, int id=-1, int index=-1);
144 /** 146 /**
145 * Inserts a title item with the given icon and title. 147 * Inserts a title item with the given icon and title.
146 */ 148 */
147 int insertTitle(const QPixmap &icon, const QString &text, int id=-1, 149 int insertTitle(const QPixmap &icon, const QString &text, int id=-1,
148 int index=-1); 150 int index=-1);
149 /** 151 /**
150 * Changes the title of the item at the specified id. If a icon was 152 * Changes the title of the item at the specified id. If a icon was
151 * previously set it is cleared. 153 * previously set it is cleared.
152 */ 154 */
153 void changeTitle(int id, const QString &text); 155 void changeTitle(int id, const QString &text);
154 /** 156 /**
155 * Changes the title and icon of the title item at the specified id. 157 * Changes the title and icon of the title item at the specified id.
156 */ 158 */
157 void changeTitle(int id, const QPixmap &icon, const QString &text); 159 void changeTitle(int id, const QPixmap &icon, const QString &text);
158 /** 160 /**
159 * Returns the title of the title item at the specified id. The default 161 * Returns the title of the title item at the specified id. The default
160 * id of -1 is for backwards compatibility only, you should always specify 162 * id of -1 is for backwards compatibility only, you should always specify
161 * the id. 163 * the id.
162 */ 164 */
163 QString title(int id=-1) const; 165 QString title(int id=-1) const;
164 /** 166 /**
165 * Returns the icon of the title item at the specified id. 167 * Returns the icon of the title item at the specified id.
166 */ 168 */
167 QPixmap titlePixmap(int id) const; 169 QPixmap titlePixmap(int id) const;
168 170
169 /** 171 /**
170 * Enables keyboard navigation by searching for the entered key sequence. 172 * Enables keyboard navigation by searching for the entered key sequence.
171 * Also underlines the currently selected item, providing feedback on the search. 173 * Also underlines the currently selected item, providing feedback on the search.
172 * 174 *
173 * Defaults to off. 175 * Defaults to off.
174 * 176 *
175 * WARNING: calls to text() of currently keyboard-selected items will 177 * WARNING: calls to text() of currently keyboard-selected items will
176 * contain additional ampersand characters. 178 * contain additional ampersand characters.
177 * 179 *
178 * WARNING: though pre-existing keyboard shortcuts will not interfere with the 180 * WARNING: though pre-existing keyboard shortcuts will not interfere with the
179 * operation of this feature, they may be confusing to the user as the existing 181 * operation of this feature, they may be confusing to the user as the existing
180 * shortcuts will not work. 182 * shortcuts will not work.
181 * @since 3.1 183 * @since 3.1
182 */ 184 */
183 void setKeyboardShortcutsEnabled(bool enable); 185 void setKeyboardShortcutsEnabled(bool enable);
184 186
185 /** 187 /**
186 * Enables execution of the menu item once it is uniquely specified. 188 * Enables execution of the menu item once it is uniquely specified.
187 * Defaults to off. 189 * Defaults to off.
188 * @since 3.1 190 * @since 3.1
189 */ 191 */
190 void setKeyboardShortcutsExecute(bool enable); 192 void setKeyboardShortcutsExecute(bool enable);
191 193
192 /** 194 /**
193 * Obsolete method provided for backwards compatibility only. Use the 195 * Obsolete method provided for backwards compatibility only. Use the
194 * normal constructor and insertTitle instead. 196 * normal constructor and insertTitle instead.
195 */ 197 */
196 OPopupMenu(const QString &title, QWidget *parent=0, const char *name=0); 198 OPopupMenu(const QString &title, QWidget *parent=0, const char *name=0);
197 /** 199 /**
198 * Obsolete method provided for backwards compatibility only. Use 200 * Obsolete method provided for backwards compatibility only. Use
199 * insertTitle and changeTitle instead. 201 * insertTitle and changeTitle instead.
200 */ 202 */
201 void setTitle(const QString &title); 203 void setTitle(const QString &title);
202 204
203 /** 205 /**
204 * Returns the context menu associated with this menu 206 * Returns the context menu associated with this menu
205 * @since 3.2 207 * @since 3.2
206 */ 208 */
207 QPopupMenu* contextMenu(); 209 QPopupMenu* contextMenu();
208 210
209 /** 211 /**
210 * Hides the context menu if shown 212 * Hides the context menu if shown
211 * @since 3.2 213 * @since 3.2
212 */ 214 */
213 void cancelContextMenuShow(); 215 void cancelContextMenuShow();
214 216
215 /** 217 /**
216 * Returns the OPopupMenu associated with the current context menu 218 * Returns the OPopupMenu associated with the current context menu
217 * @since 3.2 219 * @since 3.2
218 */ 220 */
219 static OPopupMenu* contextMenuFocus(); 221 static OPopupMenu* contextMenuFocus();
220 222
221 /** 223 /**
222 * returns the ID of the menuitem associated with the current context menu 224 * returns the ID of the menuitem associated with the current context menu
223 * @since 3.2 225 * @since 3.2
224 */ 226 */
225 static int contextMenuFocusItem(); 227 static int contextMenuFocusItem();
226 228
227signals: 229signals:
228 /** 230 /**
229 * connect to this signal to be notified when a context menu is about to be shown 231 * connect to this signal to be notified when a context menu is about to be shown
230 * @param menu The menu that the context menu is about to be shown for 232 * @param menu The menu that the context menu is about to be shown for
231 * @param menuItem The menu item that the context menu is currently on 233 * @param menuItem The menu item that the context menu is currently on
232 * @param ctxMenu The context menu itself 234 * @param ctxMenu The context menu itself
233 * @since 3.2 235 * @since 3.2
234 */ 236 */
235 void aboutToShowContextMenu(OPopupMenu* menu, int menuItem, QPopupMenu* ctxMenu); 237 void aboutToShowContextMenu(OPopupMenu* menu, int menuItem, QPopupMenu* ctxMenu);
236 238
237protected: 239protected:
238 virtual void closeEvent(QCloseEvent *); 240 virtual void closeEvent(QCloseEvent *);
239 virtual void keyPressEvent(QKeyEvent* e); 241 virtual void keyPressEvent(QKeyEvent* e);
240 virtual bool eventFilter(QObject* obj, QEvent* event); 242 virtual bool eventFilter(QObject* obj, QEvent* event);
241 virtual void hideEvent(QHideEvent*); 243 virtual void hideEvent(QHideEvent*);
242 244
243 virtual void virtual_hook( int id, void* data ); 245 virtual void virtual_hook( int id, void* data );
244 246
245protected slots: 247protected slots:
246 /// @since 3.1 248 /// @since 3.1
247 QString underlineText(const QString& text, uint length); 249 QString underlineText(const QString& text, uint length);
248 /// @since 3.1 250 /// @since 3.1
249 void resetKeyboardVars(bool noMatches = false); 251 void resetKeyboardVars(bool noMatches = false);
250 void itemHighlighted(int whichItem); 252 void itemHighlighted(int whichItem);
251 void showCtxMenu(QPoint pos); 253 void showCtxMenu(QPoint pos);
252 void ctxMenuHiding(); 254 void ctxMenuHiding();
253 255
254private: 256private:
255 class OPopupMenuPrivate; 257 class OPopupMenuPrivate;
256 OPopupMenuPrivate *d; 258 OPopupMenuPrivate *d;
257}; 259};
258 260
261}
262}
263
259#endif 264#endif
diff --git a/libopie2/opieui/oselector.cpp b/libopie2/opieui/oselector.cpp
index 23b3ce3..5f6f10f 100644
--- a/libopie2/opieui/oselector.cpp
+++ b/libopie2/opieui/oselector.cpp
@@ -1,715 +1,717 @@
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
39using namespace Opie::Ui;
40
39OXYSelector::OXYSelector( QWidget *parent, const char *name ) 41OXYSelector::OXYSelector( QWidget *parent, const char *name )
40 : QWidget( parent, name ) 42 : QWidget( parent, name )
41{ 43{
42 xPos = 0; 44 xPos = 0;
43 yPos = 0; 45 yPos = 0;
44 minX = 0; 46 minX = 0;
45 minY = 0; 47 minY = 0;
46 maxX = 100; 48 maxX = 100;
47 maxY = 100; 49 maxY = 100;
48 store.setOptimization( QPixmap::BestOptim ); 50 store.setOptimization( QPixmap::BestOptim );
49 store.resize( STORE_W2, STORE_W2 ); 51 store.resize( STORE_W2, STORE_W2 );
50} 52}
51 53
52 54
53OXYSelector::~OXYSelector() 55OXYSelector::~OXYSelector()
54{} 56{}
55 57
56 58
57void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY ) 59void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY )
58{ 60{
59 px = 2; 61 px = 2;
60 py = 2; 62 py = 2;
61 minX = _minX; 63 minX = _minX;
62 minY = _minY; 64 minY = _minY;
63 maxX = _maxX; 65 maxX = _maxX;
64 maxY = _maxY; 66 maxY = _maxY;
65} 67}
66 68
67void OXYSelector::setValues( int _xPos, int _yPos ) 69void OXYSelector::setValues( int _xPos, int _yPos )
68{ 70{
69 xPos = _xPos; 71 xPos = _xPos;
70 yPos = _yPos; 72 yPos = _yPos;
71 73
72 if ( xPos > maxX ) 74 if ( xPos > maxX )
73 xPos = maxX; 75 xPos = maxX;
74 else if ( xPos < minX ) 76 else if ( xPos < minX )
75 xPos = minX; 77 xPos = minX;
76 78
77 if ( yPos > maxY ) 79 if ( yPos > maxY )
78 yPos = maxY; 80 yPos = maxY;
79 else if ( yPos < minY ) 81 else if ( yPos < minY )
80 yPos = minY; 82 yPos = minY;
81 83
82 int xp = 2 + (width() - 4) * xPos / (maxX - minX); 84 int xp = 2 + (width() - 4) * xPos / (maxX - minX);
83 int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY); 85 int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY);
84 86
85 setPosition( xp, yp ); 87 setPosition( xp, yp );
86} 88}
87 89
88QRect OXYSelector::contentsRect() const 90QRect OXYSelector::contentsRect() const
89{ 91{
90 return QRect( 2, 2, width()-4, height()-4 ); 92 return QRect( 2, 2, width()-4, height()-4 );
91} 93}
92 94
93void OXYSelector::paintEvent( QPaintEvent *ev ) 95void OXYSelector::paintEvent( QPaintEvent *ev )
94{ 96{
95 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);
96 QRect paintRect = ev->rect(); 98 QRect paintRect = ev->rect();
97 99
98 QPainter painter; 100 QPainter painter;
99 painter.begin( this ); 101 painter.begin( this );
100 102
101 QBrush brush; 103 QBrush brush;
102 qDrawShadePanel( &painter, 0, 0, width(), height(), colorGroup(), 104 qDrawShadePanel( &painter, 0, 0, width(), height(), colorGroup(),
103 TRUE, 2, &brush ); 105 TRUE, 2, &brush );
104 106
105 drawContents( &painter ); 107 drawContents( &painter );
106 if (paintRect.contains(cursorRect)) 108 if (paintRect.contains(cursorRect))
107 { 109 {
108 bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W, 110 bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W,
109 STORE_W2, STORE_W2, CopyROP ); 111 STORE_W2, STORE_W2, CopyROP );
110 drawCursor( &painter, px, py ); 112 drawCursor( &painter, px, py );
111 } 113 }
112 else if (paintRect.intersects(cursorRect)) 114 else if (paintRect.intersects(cursorRect))
113 { 115 {
114 repaint( cursorRect, false); 116 repaint( cursorRect, false);
115 } 117 }
116 118
117 painter.end(); 119 painter.end();
118} 120}
119 121
120void OXYSelector::mousePressEvent( QMouseEvent *e ) 122void OXYSelector::mousePressEvent( QMouseEvent *e )
121{ 123{
122 int xVal, yVal; 124 int xVal, yVal;
123 valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); 125 valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal );
124 setValues( xVal, yVal ); 126 setValues( xVal, yVal );
125 127
126 emit valueChanged( xPos, yPos ); 128 emit valueChanged( xPos, yPos );
127} 129}
128 130
129void OXYSelector::mouseMoveEvent( QMouseEvent *e ) 131void OXYSelector::mouseMoveEvent( QMouseEvent *e )
130{ 132{
131 int xVal, yVal; 133 int xVal, yVal;
132 valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); 134 valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal );
133 setValues( xVal, yVal ); 135 setValues( xVal, yVal );
134 136
135 emit valueChanged( xPos, yPos ); 137 emit valueChanged( xPos, yPos );
136} 138}
137 139
138void OXYSelector::wheelEvent( QWheelEvent *e ) 140void OXYSelector::wheelEvent( QWheelEvent *e )
139{ 141{
140 #if QT_VERSION > 290 142 #if QT_VERSION > 290
141 if ( e->orientation() == Qt::Horizontal ) 143 if ( e->orientation() == Qt::Horizontal )
142 setValues( xValue() + e->delta()/120, yValue() ); 144 setValues( xValue() + e->delta()/120, yValue() );
143 else 145 else
144 setValues( xValue(), yValue() + e->delta()/120 ); 146 setValues( xValue(), yValue() + e->delta()/120 );
145 147
146 emit valueChanged( xPos, yPos ); 148 emit valueChanged( xPos, yPos );
147 #endif 149 #endif
148} 150}
149 151
150void OXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const 152void OXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const
151{ 153{
152 xVal = ( (maxX-minX) * (x-2) ) / ( width()-4 ); 154 xVal = ( (maxX-minX) * (x-2) ) / ( width()-4 );
153 yVal = maxY - ( ( (maxY-minY) * (y-2) ) / ( height()-4 ) ); 155 yVal = maxY - ( ( (maxY-minY) * (y-2) ) / ( height()-4 ) );
154 156
155 if ( xVal > maxX ) 157 if ( xVal > maxX )
156 xVal = maxX; 158 xVal = maxX;
157 else if ( xVal < minX ) 159 else if ( xVal < minX )
158 xVal = minX; 160 xVal = minX;
159 161
160 if ( yVal > maxY ) 162 if ( yVal > maxY )
161 yVal = maxY; 163 yVal = maxY;
162 else if ( yVal < minY ) 164 else if ( yVal < minY )
163 yVal = minY; 165 yVal = minY;
164} 166}
165 167
166void OXYSelector::setPosition( int xp, int yp ) 168void OXYSelector::setPosition( int xp, int yp )
167{ 169{
168 if ( xp < 2 ) 170 if ( xp < 2 )
169 xp = 2; 171 xp = 2;
170 else if ( xp > width() - 2 ) 172 else if ( xp > width() - 2 )
171 xp = width() - 2; 173 xp = width() - 2;
172 174
173 if ( yp < 2 ) 175 if ( yp < 2 )
174 yp = 2; 176 yp = 2;
175 else if ( yp > height() - 2 ) 177 else if ( yp > height() - 2 )
176 yp = height() - 2; 178 yp = height() - 2;
177 179
178 QPainter painter; 180 QPainter painter;
179 painter.begin( this ); 181 painter.begin( this );
180 182
181 bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0, 183 bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0,
182 STORE_W2, STORE_W2, CopyROP ); 184 STORE_W2, STORE_W2, CopyROP );
183 bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W, 185 bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W,
184 STORE_W2, STORE_W2, CopyROP ); 186 STORE_W2, STORE_W2, CopyROP );
185 drawCursor( &painter, xp, yp ); 187 drawCursor( &painter, xp, yp );
186 px = xp; 188 px = xp;
187 py = yp; 189 py = yp;
188 190
189 painter.end(); 191 painter.end();
190} 192}
191 193
192void OXYSelector::drawContents( QPainter * ) 194void OXYSelector::drawContents( QPainter * )
193{} 195{}
194 196
195 197
196void OXYSelector::drawCursor( QPainter *p, int xp, int yp ) 198void OXYSelector::drawCursor( QPainter *p, int xp, int yp )
197{ 199{
198 p->setPen( QPen( white ) ); 200 p->setPen( QPen( white ) );
199 201
200 p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 ); 202 p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 );
201 p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 ); 203 p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 );
202 p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 ); 204 p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 );
203 p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 ); 205 p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 );
204} 206}
205 207
206//----------------------------------------------------------------------------- 208//-----------------------------------------------------------------------------
207/* 209/*
208 * 1D value selector with contents drawn by derived class. 210 * 1D value selector with contents drawn by derived class.
209 * See OColorDialog for example. 211 * See OColorDialog for example.
210 */ 212 */
211 213
212 214
213OSelector::OSelector( QWidget *parent, const char *name ) 215OSelector::OSelector( QWidget *parent, const char *name )
214 : QWidget( parent, name ), QRangeControl() 216 : QWidget( parent, name ), QRangeControl()
215{ 217{
216 _orientation = Horizontal; 218 _orientation = Horizontal;
217 _indent = TRUE; 219 _indent = TRUE;
218} 220}
219 221
220OSelector::OSelector( Orientation o, QWidget *parent, const char *name ) 222OSelector::OSelector( Orientation o, QWidget *parent, const char *name )
221 : QWidget( parent, name ), QRangeControl() 223 : QWidget( parent, name ), QRangeControl()
222{ 224{
223 _orientation = o; 225 _orientation = o;
224 _indent = TRUE; 226 _indent = TRUE;
225} 227}
226 228
227 229
228OSelector::~OSelector() 230OSelector::~OSelector()
229{} 231{}
230 232
231 233
232QRect OSelector::contentsRect() const 234QRect OSelector::contentsRect() const
233{ 235{
234 if ( orientation() == Vertical ) 236 if ( orientation() == Vertical )
235 return QRect( 2, 5, width()-9, height()-10 ); 237 return QRect( 2, 5, width()-9, height()-10 );
236 else 238 else
237 return QRect( 5, 2, width()-10, height()-9 ); 239 return QRect( 5, 2, width()-10, height()-9 );
238} 240}
239 241
240void OSelector::paintEvent( QPaintEvent * ) 242void OSelector::paintEvent( QPaintEvent * )
241{ 243{
242 QPainter painter; 244 QPainter painter;
243 245
244 painter.begin( this ); 246 painter.begin( this );
245 247
246 drawContents( &painter ); 248 drawContents( &painter );
247 249
248 QBrush brush; 250 QBrush brush;
249 251
250 if ( indent() ) 252 if ( indent() )
251 { 253 {
252 if ( orientation() == Vertical ) 254 if ( orientation() == Vertical )
253 qDrawShadePanel( &painter, 0, 3, width()-5, height()-6, 255 qDrawShadePanel( &painter, 0, 3, width()-5, height()-6,
254 colorGroup(), TRUE, 2, &brush ); 256 colorGroup(), TRUE, 2, &brush );
255 else 257 else
256 qDrawShadePanel( &painter, 3, 0, width()-6, height()-5, 258 qDrawShadePanel( &painter, 3, 0, width()-6, height()-5,
257 colorGroup(), TRUE, 2, &brush ); 259 colorGroup(), TRUE, 2, &brush );
258 } 260 }
259 261
260 QPoint pos = calcArrowPos( value() ); 262 QPoint pos = calcArrowPos( value() );
261 drawArrow( &painter, TRUE, pos ); 263 drawArrow( &painter, TRUE, pos );
262 264
263 painter.end(); 265 painter.end();
264} 266}
265 267
266void OSelector::mousePressEvent( QMouseEvent *e ) 268void OSelector::mousePressEvent( QMouseEvent *e )
267{ 269{
268 moveArrow( e->pos() ); 270 moveArrow( e->pos() );
269} 271}
270 272
271void OSelector::mouseMoveEvent( QMouseEvent *e ) 273void OSelector::mouseMoveEvent( QMouseEvent *e )
272{ 274{
273 moveArrow( e->pos() ); 275 moveArrow( e->pos() );
274} 276}
275 277
276void OSelector::wheelEvent( QWheelEvent *e ) 278void OSelector::wheelEvent( QWheelEvent *e )
277{ 279{
278 int val = value() + e->delta()/120; 280 int val = value() + e->delta()/120;
279 emit valueChanged( val ); 281 emit valueChanged( val );
280 setValue( val ); 282 setValue( val );
281} 283}
282 284
283void OSelector::valueChange() 285void OSelector::valueChange()
284{ 286{
285 QPainter painter; 287 QPainter painter;
286 QPoint pos; 288 QPoint pos;
287 289
288 painter.begin( this ); 290 painter.begin( this );
289 291
290 pos = calcArrowPos( prevValue() ); 292 pos = calcArrowPos( prevValue() );
291 drawArrow( &painter, FALSE, pos ); 293 drawArrow( &painter, FALSE, pos );
292 294
293 pos = calcArrowPos( value() ); 295 pos = calcArrowPos( value() );
294 drawArrow( &painter, TRUE, pos ); 296 drawArrow( &painter, TRUE, pos );
295 297
296 painter.end(); 298 painter.end();
297} 299}
298 300
299void OSelector::moveArrow( const QPoint &pos ) 301void OSelector::moveArrow( const QPoint &pos )
300{ 302{
301 int val; 303 int val;
302 304
303 if ( orientation() == Vertical ) 305 if ( orientation() == Vertical )
304 val = ( maxValue() - minValue() ) * (height()-pos.y()-3) 306 val = ( maxValue() - minValue() ) * (height()-pos.y()-3)
305 / (height()-10) + minValue(); 307 / (height()-10) + minValue();
306 else 308 else
307 val = ( maxValue() - minValue() ) * (width()-pos.x()-3) 309 val = ( maxValue() - minValue() ) * (width()-pos.x()-3)
308 / (width()-10) + minValue(); 310 / (width()-10) + minValue();
309 311
310 if ( val > maxValue() ) 312 if ( val > maxValue() )
311 val = maxValue(); 313 val = maxValue();
312 if ( val < minValue() ) 314 if ( val < minValue() )
313 val = minValue(); 315 val = minValue();
314 316
315 emit valueChanged( val ); 317 emit valueChanged( val );
316 setValue( val ); 318 setValue( val );
317} 319}
318 320
319QPoint OSelector::calcArrowPos( int val ) 321QPoint OSelector::calcArrowPos( int val )
320{ 322{
321 QPoint p; 323 QPoint p;
322 324
323 if ( orientation() == Vertical ) 325 if ( orientation() == Vertical )
324 { 326 {
325 p.setY( height() - ( (height()-10) * val 327 p.setY( height() - ( (height()-10) * val
326 / ( maxValue() - minValue() ) + 5 ) ); 328 / ( maxValue() - minValue() ) + 5 ) );
327 p.setX( width() - 5 ); 329 p.setX( width() - 5 );
328 } 330 }
329 else 331 else
330 { 332 {
331 p.setX( width() - ( (width()-10) * val 333 p.setX( width() - ( (width()-10) * val
332 / ( maxValue() - minValue() ) + 5 ) ); 334 / ( maxValue() - minValue() ) + 5 ) );
333 p.setY( height() - 5 ); 335 p.setY( height() - 5 );
334 } 336 }
335 337
336 return p; 338 return p;
337} 339}
338 340
339void OSelector::drawContents( QPainter * ) 341void OSelector::drawContents( QPainter * )
340{} 342{}
341 343
342void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos ) 344void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos )
343{ 345{
344 if ( show ) 346 if ( show )
345 { 347 {
346 QPointArray array(3); 348 QPointArray array(3);
347 349
348 painter->setPen( QPen() ); 350 painter->setPen( QPen() );
349 painter->setBrush( QBrush( colorGroup().buttonText() ) ); 351 painter->setBrush( QBrush( colorGroup().buttonText() ) );
350 if ( orientation() == Vertical ) 352 if ( orientation() == Vertical )
351 { 353 {
352 array.setPoint( 0, pos.x()+0, pos.y()+0 ); 354 array.setPoint( 0, pos.x()+0, pos.y()+0 );
353 array.setPoint( 1, pos.x()+5, pos.y()+5 ); 355 array.setPoint( 1, pos.x()+5, pos.y()+5 );
354 array.setPoint( 2, pos.x()+5, pos.y()-5 ); 356 array.setPoint( 2, pos.x()+5, pos.y()-5 );
355 } 357 }
356 else 358 else
357 { 359 {
358 array.setPoint( 0, pos.x()+0, pos.y()+0 ); 360 array.setPoint( 0, pos.x()+0, pos.y()+0 );
359 array.setPoint( 1, pos.x()+5, pos.y()+5 ); 361 array.setPoint( 1, pos.x()+5, pos.y()+5 );
360 array.setPoint( 2, pos.x()-5, pos.y()+5 ); 362 array.setPoint( 2, pos.x()-5, pos.y()+5 );
361 } 363 }
362 364
363 painter->drawPolygon( array ); 365 painter->drawPolygon( array );
364 } 366 }
365 else 367 else
366 { 368 {
367 if ( orientation() == Vertical ) 369 if ( orientation() == Vertical )
368 { 370 {
369 repaint(pos.x(), pos.y()-5, 6, 11, true); 371 repaint(pos.x(), pos.y()-5, 6, 11, true);
370 } 372 }
371 else 373 else
372 { 374 {
373 repaint(pos.x()-5, pos.y(), 11, 6, true); 375 repaint(pos.x()-5, pos.y(), 11, 6, true);
374 } 376 }
375 } 377 }
376} 378}
377 379
378//---------------------------------------------------------------------------- 380//----------------------------------------------------------------------------
379 381
380OGradientSelector::OGradientSelector( QWidget *parent, const char *name ) 382OGradientSelector::OGradientSelector( QWidget *parent, const char *name )
381 : OSelector( parent, name ) 383 : OSelector( parent, name )
382{ 384{
383 init(); 385 init();
384} 386}
385 387
386 388
387OGradientSelector::OGradientSelector( Orientation o, QWidget *parent, 389OGradientSelector::OGradientSelector( Orientation o, QWidget *parent,
388 const char *name ) 390 const char *name )
389 : OSelector( o, parent, name ) 391 : OSelector( o, parent, name )
390{ 392{
391 init(); 393 init();
392} 394}
393 395
394 396
395OGradientSelector::~OGradientSelector() 397OGradientSelector::~OGradientSelector()
396{} 398{}
397 399
398 400
399void OGradientSelector::init() 401void OGradientSelector::init()
400{ 402{
401 color1.setRgb( 0, 0, 0 ); 403 color1.setRgb( 0, 0, 0 );
402 color2.setRgb( 255, 255, 255 ); 404 color2.setRgb( 255, 255, 255 );
403 405
404 text1 = text2 = ""; 406 text1 = text2 = "";
405} 407}
406 408
407 409
408void OGradientSelector::drawContents( QPainter *painter ) 410void OGradientSelector::drawContents( QPainter *painter )
409{ 411{
410 QImage image( contentsRect().width(), contentsRect().height(), 32 ); 412 QImage image( contentsRect().width(), contentsRect().height(), 32 );
411 413
412 QColor col; 414 QColor col;
413 float scale; 415 float scale;
414 416
415 int redDiff = color2.red() - color1.red(); 417 int redDiff = color2.red() - color1.red();
416 int greenDiff = color2.green() - color1.green(); 418 int greenDiff = color2.green() - color1.green();
417 int blueDiff = color2.blue() - color1.blue(); 419 int blueDiff = color2.blue() - color1.blue();
418 420
419 if ( orientation() == Vertical ) 421 if ( orientation() == Vertical )
420 { 422 {
421 for ( int y = 0; y < image.height(); y++ ) 423 for ( int y = 0; y < image.height(); y++ )
422 { 424 {
423 scale = 1.0 * y / image.height(); 425 scale = 1.0 * y / image.height();
424 col.setRgb( color1.red() + int(redDiff*scale), 426 col.setRgb( color1.red() + int(redDiff*scale),
425 color1.green() + int(greenDiff*scale), 427 color1.green() + int(greenDiff*scale),
426 color1.blue() + int(blueDiff*scale) ); 428 color1.blue() + int(blueDiff*scale) );
427 429
428 unsigned int *p = (uint *) image.scanLine( y ); 430 unsigned int *p = (uint *) image.scanLine( y );
429 for ( int x = 0; x < image.width(); x++ ) 431 for ( int x = 0; x < image.width(); x++ )
430 *p++ = col.rgb(); 432 *p++ = col.rgb();
431 } 433 }
432 } 434 }
433 else 435 else
434 { 436 {
435 unsigned int *p = (uint *) image.scanLine( 0 ); 437 unsigned int *p = (uint *) image.scanLine( 0 );
436 438
437 for ( int x = 0; x < image.width(); x++ ) 439 for ( int x = 0; x < image.width(); x++ )
438 { 440 {
439 scale = 1.0 * x / image.width(); 441 scale = 1.0 * x / image.width();
440 col.setRgb( color1.red() + int(redDiff*scale), 442 col.setRgb( color1.red() + int(redDiff*scale),
441 color1.green() + int(greenDiff*scale), 443 color1.green() + int(greenDiff*scale),
442 color1.blue() + int(blueDiff*scale) ); 444 color1.blue() + int(blueDiff*scale) );
443 *p++ = col.rgb(); 445 *p++ = col.rgb();
444 } 446 }
445 447
446 for ( int y = 1; y < image.height(); y++ ) 448 for ( int y = 1; y < image.height(); y++ )
447 memcpy( image.scanLine( y ), image.scanLine( y - 1), 449 memcpy( image.scanLine( y ), image.scanLine( y - 1),
448 sizeof( unsigned int ) * image.width() ); 450 sizeof( unsigned int ) * image.width() );
449 } 451 }
450 452
451 QColor ditherPalette[8]; 453 QColor ditherPalette[8];
452 454
453 for ( int s = 0; s < 8; s++ ) 455 for ( int s = 0; s < 8; s++ )
454 ditherPalette[s].setRgb( color1.red() + redDiff * s / 8, 456 ditherPalette[s].setRgb( color1.red() + redDiff * s / 8,
455 color1.green() + greenDiff * s / 8, 457 color1.green() + greenDiff * s / 8,
456 color1.blue() + blueDiff * s / 8 ); 458 color1.blue() + blueDiff * s / 8 );
457 459
458 OImageEffect::dither( image, ditherPalette, 8 ); 460 OImageEffect::dither( image, ditherPalette, 8 );
459 461
460 QPixmap p; 462 QPixmap p;
461 p.convertFromImage( image ); 463 p.convertFromImage( image );
462 464
463 painter->drawPixmap( contentsRect().x(), contentsRect().y(), p ); 465 painter->drawPixmap( contentsRect().x(), contentsRect().y(), p );
464 466
465 if ( orientation() == Vertical ) 467 if ( orientation() == Vertical )
466 { 468 {
467 int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2; 469 int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2;
468 int xPos = contentsRect().left() + (contentsRect().width() - 470 int xPos = contentsRect().left() + (contentsRect().width() -
469 painter->fontMetrics().width( text2 )) / 2; 471 painter->fontMetrics().width( text2 )) / 2;
470 QPen pen( color2 ); 472 QPen pen( color2 );
471 painter->setPen( pen ); 473 painter->setPen( pen );
472 painter->drawText( xPos, yPos, text2 ); 474 painter->drawText( xPos, yPos, text2 );
473 475
474 yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2; 476 yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2;
475 xPos = contentsRect().left() + (contentsRect().width() - 477 xPos = contentsRect().left() + (contentsRect().width() -
476 painter->fontMetrics().width( text1 )) / 2; 478 painter->fontMetrics().width( text1 )) / 2;
477 pen.setColor( color1 ); 479 pen.setColor( color1 );
478 painter->setPen( pen ); 480 painter->setPen( pen );
479 painter->drawText( xPos, yPos, text1 ); 481 painter->drawText( xPos, yPos, text1 );
480 } 482 }
481 else 483 else
482 { 484 {
483 int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2; 485 int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2;
484 486
485 QPen pen( color2 ); 487 QPen pen( color2 );
486 painter->setPen( pen ); 488 painter->setPen( pen );
487 painter->drawText( contentsRect().left() + 2, yPos, text1 ); 489 painter->drawText( contentsRect().left() + 2, yPos, text1 );
488 490
489 pen.setColor( color1 ); 491 pen.setColor( color1 );
490 painter->setPen( pen ); 492 painter->setPen( pen );
491 painter->drawText( contentsRect().right() - 493 painter->drawText( contentsRect().right() -
492 painter->fontMetrics().width( text2 ) - 2, yPos, text2 ); 494 painter->fontMetrics().width( text2 ) - 2, yPos, text2 );
493 } 495 }
494} 496}
495 497
496//----------------------------------------------------------------------------- 498//-----------------------------------------------------------------------------
497 499
498static QColor *standardPalette = 0; 500static QColor *standardPalette = 0;
499 501
500#define STANDARD_PAL_SIZE 17 502#define STANDARD_PAL_SIZE 17
501 503
502OColor::OColor() 504OColor::OColor()
503: QColor() 505: QColor()
504{ 506{
505 r = 0; g = 0; b = 0; h = 0; s = 0; v = 0; 507 r = 0; g = 0; b = 0; h = 0; s = 0; v = 0;
506}; 508};
507 509
508OColor::OColor( const OColor &col) 510OColor::OColor( const OColor &col)
509: QColor( col ) 511: QColor( col )
510{ 512{
511 h = col.h; s = col.s; v = col.v; 513 h = col.h; s = col.s; v = col.v;
512 r = col.r; g = col.g; b = col.b; 514 r = col.r; g = col.g; b = col.b;
513}; 515};
514 516
515OColor::OColor( const QColor &col) 517OColor::OColor( const QColor &col)
516: QColor( col ) 518: QColor( col )
517{ 519{
518 QColor::rgb(&r, &g, &b); 520 QColor::rgb(&r, &g, &b);
519 QColor::hsv(&h, &s, &v); 521 QColor::hsv(&h, &s, &v);
520}; 522};
521 523
522bool OColor::operator==(const OColor& col) const 524bool OColor::operator==(const OColor& col) const
523{ 525{
524 return (h == col.h) && (s == col.s) && (v == col.v) && 526 return (h == col.h) && (s == col.s) && (v == col.v) &&
525 (r == col.r) && (g == col.g) && (b == col.b); 527 (r == col.r) && (g == col.g) && (b == col.b);
526} 528}
527 529
528OColor& OColor::operator=(const OColor& col) 530OColor& OColor::operator=(const OColor& col)
529{ 531{
530 *(QColor *)this = col; 532 *(QColor *)this = col;
531 h = col.h; s = col.s; v = col.v; 533 h = col.h; s = col.s; v = col.v;
532 r = col.r; g = col.g; b = col.b; 534 r = col.r; g = col.g; b = col.b;
533 return *this; 535 return *this;
534} 536}
535 537
536void 538void
537OColor::setHsv(int _h, int _s, int _v) 539OColor::setHsv(int _h, int _s, int _v)
538{ 540{
539 h = _h; s = _s; v = _v; 541 h = _h; s = _s; v = _v;
540 QColor::setHsv(h, s, v); 542 QColor::setHsv(h, s, v);
541 QColor::rgb(&r, &g, &b); 543 QColor::rgb(&r, &g, &b);
542}; 544};
543 545
544void 546void
545OColor::setRgb(int _r, int _g, int _b) 547OColor::setRgb(int _r, int _g, int _b)
546{ 548{
547 r = _r; g = _g; b = _b; 549 r = _r; g = _g; b = _b;
548 QColor::setRgb(r, g, b); 550 QColor::setRgb(r, g, b);
549 QColor::hsv(&h, &s, &v); 551 QColor::hsv(&h, &s, &v);
550} 552}
551 553
552void 554void
553OColor::rgb(int *_r, int *_g, int *_b) const 555OColor::rgb(int *_r, int *_g, int *_b) const
554{ 556{
555 *_r = r; *_g = g; *_b = b; 557 *_r = r; *_g = g; *_b = b;
556} 558}
557 559
558void 560void
559OColor::hsv(int *_h, int *_s, int *_v) const 561OColor::hsv(int *_h, int *_s, int *_v) const
560{ 562{
561 *_h = h; *_s = s; *_v = v; 563 *_h = h; *_s = s; *_v = v;
562} 564}
563 565
564static void createStandardPalette() 566static void createStandardPalette()
565{ 567{
566 if ( standardPalette ) 568 if ( standardPalette )
567 return; 569 return;
568 570
569 standardPalette = new QColor[STANDARD_PAL_SIZE]; 571 standardPalette = new QColor[STANDARD_PAL_SIZE];
570 572
571 int i = 0; 573 int i = 0;
572 574
573 standardPalette[i++] = Qt::red; 575 standardPalette[i++] = Qt::red;
574 standardPalette[i++] = Qt::green; 576 standardPalette[i++] = Qt::green;
575 standardPalette[i++] = Qt::blue; 577 standardPalette[i++] = Qt::blue;
576 standardPalette[i++] = Qt::cyan; 578 standardPalette[i++] = Qt::cyan;
577 standardPalette[i++] = Qt::magenta; 579 standardPalette[i++] = Qt::magenta;
578 standardPalette[i++] = Qt::yellow; 580 standardPalette[i++] = Qt::yellow;
579 standardPalette[i++] = Qt::darkRed; 581 standardPalette[i++] = Qt::darkRed;
580 standardPalette[i++] = Qt::darkGreen; 582 standardPalette[i++] = Qt::darkGreen;
581 standardPalette[i++] = Qt::darkBlue; 583 standardPalette[i++] = Qt::darkBlue;
582 standardPalette[i++] = Qt::darkCyan; 584 standardPalette[i++] = Qt::darkCyan;
583 standardPalette[i++] = Qt::darkMagenta; 585 standardPalette[i++] = Qt::darkMagenta;
584 standardPalette[i++] = Qt::darkYellow; 586 standardPalette[i++] = Qt::darkYellow;
585 standardPalette[i++] = Qt::white; 587 standardPalette[i++] = Qt::white;
586 standardPalette[i++] = Qt::lightGray; 588 standardPalette[i++] = Qt::lightGray;
587 standardPalette[i++] = Qt::gray; 589 standardPalette[i++] = Qt::gray;
588 standardPalette[i++] = Qt::darkGray; 590 standardPalette[i++] = Qt::darkGray;
589 standardPalette[i++] = Qt::black; 591 standardPalette[i++] = Qt::black;
590} 592}
591 593
592 594
593OHSSelector::OHSSelector( QWidget *parent, const char *name ) 595OHSSelector::OHSSelector( QWidget *parent, const char *name )
594 : OXYSelector( parent, name ) 596 : OXYSelector( parent, name )
595{ 597{
596 setRange( 0, 0, 359, 255 ); 598 setRange( 0, 0, 359, 255 );
597} 599}
598 600
599void OHSSelector::updateContents() 601void OHSSelector::updateContents()
600{ 602{
601 drawPalette(&pixmap); 603 drawPalette(&pixmap);
602} 604}
603 605
604void OHSSelector::resizeEvent( QResizeEvent * ) 606void OHSSelector::resizeEvent( QResizeEvent * )
605{ 607{
606 updateContents(); 608 updateContents();
607} 609}
608 610
609void OHSSelector::drawContents( QPainter *painter ) 611void OHSSelector::drawContents( QPainter *painter )
610{ 612{
611 painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap ); 613 painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap );
612} 614}
613 615
614void OHSSelector::drawPalette( QPixmap *pixmap ) 616void OHSSelector::drawPalette( QPixmap *pixmap )
615{ 617{
616 int xSize = contentsRect().width(), ySize = contentsRect().height(); 618 int xSize = contentsRect().width(), ySize = contentsRect().height();
617 QImage image( xSize, ySize, 32 ); 619 QImage image( xSize, ySize, 32 );
618 QColor col; 620 QColor col;
619 int h, s; 621 int h, s;
620 uint *p; 622 uint *p;
621 623
622 for ( s = ySize-1; s >= 0; s-- ) 624 for ( s = ySize-1; s >= 0; s-- )
623 { 625 {
624 p = (uint *) image.scanLine( ySize - s - 1 ); 626 p = (uint *) image.scanLine( ySize - s - 1 );
625 for( h = 0; h < xSize; h++ ) 627 for( h = 0; h < xSize; h++ )
626 { 628 {
627 col.setHsv( 359*h/(xSize-1), 255*s/(ySize-1), 192 ); 629 col.setHsv( 359*h/(xSize-1), 255*s/(ySize-1), 192 );
628 *p = col.rgb(); 630 *p = col.rgb();
629 p++; 631 p++;
630 } 632 }
631 } 633 }
632 634
633 if ( QColor::numBitPlanes() <= 8 ) 635 if ( QColor::numBitPlanes() <= 8 )
634 { 636 {
635 createStandardPalette(); 637 createStandardPalette();
636 OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE ); 638 OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE );
637 } 639 }
638 pixmap->convertFromImage( image ); 640 pixmap->convertFromImage( image );
639} 641}
640 642
641 643
642//----------------------------------------------------------------------------- 644//-----------------------------------------------------------------------------
643 645
644OValueSelector::OValueSelector( QWidget *parent, const char *name ) 646OValueSelector::OValueSelector( QWidget *parent, const char *name )
645 : OSelector( OSelector::Vertical, parent, name ), _hue(0), _sat(0) 647 : OSelector( OSelector::Vertical, parent, name ), _hue(0), _sat(0)
646{ 648{
647 setRange( 0, 255 ); 649 setRange( 0, 255 );
648 pixmap.setOptimization( QPixmap::BestOptim ); 650 pixmap.setOptimization( QPixmap::BestOptim );
649} 651}
650 652
651OValueSelector::OValueSelector(Orientation o, QWidget *parent, const char *name 653OValueSelector::OValueSelector(Orientation o, QWidget *parent, const char *name
652 ) 654 )
653 : OSelector( o, parent, name), _hue(0), _sat(0) 655 : OSelector( o, parent, name), _hue(0), _sat(0)
654{ 656{
655 setRange( 0, 255 ); 657 setRange( 0, 255 );
656 pixmap.setOptimization( QPixmap::BestOptim ); 658 pixmap.setOptimization( QPixmap::BestOptim );
657} 659}
658 660
659void OValueSelector::updateContents() 661void OValueSelector::updateContents()
660{ 662{
661 drawPalette(&pixmap); 663 drawPalette(&pixmap);
662} 664}
663 665
664void OValueSelector::resizeEvent( QResizeEvent * ) 666void OValueSelector::resizeEvent( QResizeEvent * )
665{ 667{
666 updateContents(); 668 updateContents();
667} 669}
668 670
669void OValueSelector::drawContents( QPainter *painter ) 671void OValueSelector::drawContents( QPainter *painter )
670{ 672{
671 painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap ); 673 painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap );
672} 674}
673 675
674void OValueSelector::drawPalette( QPixmap *pixmap ) 676void OValueSelector::drawPalette( QPixmap *pixmap )
675{ 677{
676 int xSize = contentsRect().width(), ySize = contentsRect().height(); 678 int xSize = contentsRect().width(), ySize = contentsRect().height();
677 QImage image( xSize, ySize, 32 ); 679 QImage image( xSize, ySize, 32 );
678 QColor col; 680 QColor col;
679 uint *p; 681 uint *p;
680 QRgb rgb; 682 QRgb rgb;
681 683
682 if ( orientation() == OSelector::Horizontal ) 684 if ( orientation() == OSelector::Horizontal )
683 { 685 {
684 for ( int v = 0; v < ySize; v++ ) 686 for ( int v = 0; v < ySize; v++ )
685 { 687 {
686 p = (uint *) image.scanLine( ySize - v - 1 ); 688 p = (uint *) image.scanLine( ySize - v - 1 );
687 689
688 for( int x = 0; x < xSize; x++ ) 690 for( int x = 0; x < xSize; x++ )
689 { 691 {
690 col.setHsv( _hue, _sat, 255*x/(xSize-1) ); 692 col.setHsv( _hue, _sat, 255*x/(xSize-1) );
691 rgb = col.rgb(); 693 rgb = col.rgb();
692 *p++ = rgb; 694 *p++ = rgb;
693 } 695 }
694 } 696 }
695 } 697 }
696 698
697 if( orientation() == OSelector::Vertical ) 699 if( orientation() == OSelector::Vertical )
698 { 700 {
699 for ( int v = 0; v < ySize; v++ ) 701 for ( int v = 0; v < ySize; v++ )
700 { 702 {
701 p = (uint *) image.scanLine( ySize - v - 1 ); 703 p = (uint *) image.scanLine( ySize - v - 1 );
702 col.setHsv( _hue, _sat, 255*v/(ySize-1) ); 704 col.setHsv( _hue, _sat, 255*v/(ySize-1) );
703 rgb = col.rgb(); 705 rgb = col.rgb();
704 for ( int i = 0; i < xSize; i++ ) 706 for ( int i = 0; i < xSize; i++ )
705 *p++ = rgb; 707 *p++ = rgb;
706 } 708 }
707 } 709 }
708 710
709 if ( QColor::numBitPlanes() <= 8 ) 711 if ( QColor::numBitPlanes() <= 8 )
710 { 712 {
711 createStandardPalette(); 713 createStandardPalette();
712 OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE ); 714 OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE );
713 } 715 }
714 pixmap->convertFromImage( image ); 716 pixmap->convertFromImage( image );
715} 717}
diff --git a/libopie2/opieui/oselector.h b/libopie2/opieui/oselector.h
index f832239..fe75a46 100644
--- a/libopie2/opieui/oselector.h
+++ b/libopie2/opieui/oselector.h
@@ -1,518 +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
31namespace Opie {
32namespace Ui {
30/** 33/**
31 * OXYSelector is the base class for other widgets which 34 * OXYSelector is the base class for other widgets which
32 * provides the ability to choose from a two-dimensional 35 * provides the ability to choose from a two-dimensional
33 * range of values. The currently chosen value is indicated 36 * range of values. The currently chosen value is indicated
34 * by a cross. An example is the @ref OHSSelector which 37 * by a cross. An example is the @ref OHSSelector which
35 * allows to choose from a range of colors, and which is 38 * allows to choose from a range of colors, and which is
36 * used in OColorDialog. 39 * used in OColorDialog.
37 * 40 *
38 * A custom drawing routine for the widget surface has 41 * A custom drawing routine for the widget surface has
39 * to be provided by the subclass. 42 * to be provided by the subclass.
40 */ 43 */
41class OXYSelector : public QWidget 44class OXYSelector : public QWidget
42{ 45{
43 Q_OBJECT 46 Q_OBJECT
44 47
45public: 48public:
46 /** 49 /**
47 * Constructs a two-dimensional selector widget which 50 * Constructs a two-dimensional selector widget which
48 * has a value range of [0..100] in both directions. 51 * has a value range of [0..100] in both directions.
49 */ 52 */
50 OXYSelector( QWidget *parent=0, const char *name=0 ); 53 OXYSelector( QWidget *parent=0, const char *name=0 );
51 /** 54 /**
52 * Destructs the widget. 55 * Destructs the widget.
53 */ 56 */
54 ~OXYSelector(); 57 ~OXYSelector();
55 58
56 /** 59 /**
57 * Sets the current values in horizontal and 60 * Sets the current values in horizontal and
58 * vertical direction. 61 * vertical direction.
59 */ 62 */
60 void setValues( int xPos, int yPos ); 63 void setValues( int xPos, int yPos );
61 /** 64 /**
62 * Sets the range of possible values. 65 * Sets the range of possible values.
63 */ 66 */
64 void setRange( int minX, int minY, int maxX, int maxY ); 67 void setRange( int minX, int minY, int maxX, int maxY );
65 68
66 /** 69 /**
67 * @return the current value in horizontal direction. 70 * @return the current value in horizontal direction.
68 */ 71 */
69 int xValue() const {return xPos; } 72 int xValue() const {return xPos; }
70 /** 73 /**
71 * @return the current value in vertical direction. 74 * @return the current value in vertical direction.
72 */ 75 */
73 int yValue() const {return yPos; } 76 int yValue() const {return yPos; }
74 77
75 /** 78 /**
76 * @return the rectangle on which subclasses should draw. 79 * @return the rectangle on which subclasses should draw.
77 */ 80 */
78 QRect contentsRect() const; 81 QRect contentsRect() const;
79 82
80signals: 83signals:
81 /** 84 /**
82 * This signal is emitted whenever the user chooses a value, 85 * This signal is emitted whenever the user chooses a value,
83 * e.g. by clicking with the mouse on the widget. 86 * e.g. by clicking with the mouse on the widget.
84 */ 87 */
85 void valueChanged( int x, int y ); 88 void valueChanged( int x, int y );
86 89
87protected: 90protected:
88 /** 91 /**
89 * Override this function to draw the contents of the widget. 92 * Override this function to draw the contents of the widget.
90 * The default implementation does nothing. 93 * The default implementation does nothing.
91 * 94 *
92 * Draw within @ref contentsRect() only. 95 * Draw within @ref contentsRect() only.
93 */ 96 */
94 virtual void drawContents( QPainter * ); 97 virtual void drawContents( QPainter * );
95 /** 98 /**
96 * Override this function to draw the cursor which 99 * Override this function to draw the cursor which
97 * indicates the currently selected value pair. 100 * indicates the currently selected value pair.
98 */ 101 */
99 virtual void drawCursor( QPainter *p, int xp, int yp ); 102 virtual void drawCursor( QPainter *p, int xp, int yp );
100 /** 103 /**
101 * @reimplemented 104 * @reimplemented
102 */ 105 */
103 virtual void paintEvent( QPaintEvent *e ); 106 virtual void paintEvent( QPaintEvent *e );
104 /** 107 /**
105 * @reimplemented 108 * @reimplemented
106 */ 109 */
107 virtual void mousePressEvent( QMouseEvent *e ); 110 virtual void mousePressEvent( QMouseEvent *e );
108 /** 111 /**
109 * @reimplemented 112 * @reimplemented
110 */ 113 */
111 virtual void mouseMoveEvent( QMouseEvent *e ); 114 virtual void mouseMoveEvent( QMouseEvent *e );
112 /** 115 /**
113 * @reimplemented 116 * @reimplemented
114 */ 117 */
115 virtual void wheelEvent( QWheelEvent * ); 118 virtual void wheelEvent( QWheelEvent * );
116 /** 119 /**
117 * Converts a pixel position to its corresponding values. 120 * Converts a pixel position to its corresponding values.
118 */ 121 */
119 void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const; 122 void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const;
120 123
121private: 124private:
122 void setPosition( int xp, int yp ); 125 void setPosition( int xp, int yp );
123 int px; 126 int px;
124 int py; 127 int py;
125 int xPos; 128 int xPos;
126 int yPos; 129 int yPos;
127 int minX; 130 int minX;
128 int maxX; 131 int maxX;
129 int minY; 132 int minY;
130 int maxY; 133 int maxY;
131 QPixmap store; 134 QPixmap store;
132 135
133private: 136private:
134 class OXYSelectorPrivate; 137 class OXYSelectorPrivate;
135 OXYSelectorPrivate *d; 138 OXYSelectorPrivate *d;
136}; 139};
137 140
138 141
139/** 142/**
140 * OSelector is the base class for other widgets which 143 * OSelector is the base class for other widgets which
141 * provides the ability to choose from a one-dimensional 144 * provides the ability to choose from a one-dimensional
142 * range of values. An example is the @ref OGradientSelector 145 * range of values. An example is the @ref OGradientSelector
143 * which allows to choose from a range of colors. 146 * which allows to choose from a range of colors.
144 * 147 *
145 * A custom drawing routine for the widget surface has 148 * A custom drawing routine for the widget surface has
146 * to be provided by the subclass. 149 * to be provided by the subclass.
147 */ 150 */
148class OSelector : public QWidget, public QRangeControl 151class OSelector : public QWidget, public QRangeControl
149{ 152{
150 Q_OBJECT 153 Q_OBJECT
151 Q_PROPERTY( int value READ value WRITE setValue ) 154 Q_PROPERTY( int value READ value WRITE setValue )
152 Q_PROPERTY( int minValue READ minValue WRITE setMinValue ) 155 Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
153 Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) 156 Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
154public: 157public:
155 158
156 /** 159 /**
157 * Constructs a horizontal one-dimensional selection widget. 160 * Constructs a horizontal one-dimensional selection widget.
158 */ 161 */
159 OSelector( QWidget *parent=0, const char *name=0 ); 162 OSelector( QWidget *parent=0, const char *name=0 );
160 /** 163 /**
161 * Constructs a one-dimensional selection widget with 164 * Constructs a one-dimensional selection widget with
162 * a given orientation. 165 * a given orientation.
163 */ 166 */
164 OSelector( Orientation o, QWidget *parent = 0L, const char *name = 0L ); 167 OSelector( Orientation o, QWidget *parent = 0L, const char *name = 0L );
165 /* 168 /*
166 * Destructs the widget. 169 * Destructs the widget.
167 */ 170 */
168 ~OSelector(); 171 ~OSelector();
169 172
170 /** 173 /**
171 * @return the orientation of the widget. 174 * @return the orientation of the widget.
172 */ 175 */
173 Orientation orientation() const 176 Orientation orientation() const
174 {return _orientation; } 177 {return _orientation; }
175 178
176 /** 179 /**
177 * @return the rectangle on which subclasses should draw. 180 * @return the rectangle on which subclasses should draw.
178 */ 181 */
179 QRect contentsRect() const; 182 QRect contentsRect() const;
180 183
181 /** 184 /**
182 * Sets the indent option of the widget to i. 185 * Sets the indent option of the widget to i.
183 * This determines whether a shaded frame is drawn. 186 * This determines whether a shaded frame is drawn.
184 */ 187 */
185 void setIndent( bool i ) 188 void setIndent( bool i )
186 {_indent = i; } 189 {_indent = i; }
187 /** 190 /**
188 * @return whether the indent option is set. 191 * @return whether the indent option is set.
189 */ 192 */
190 bool indent() const 193 bool indent() const
191 {return _indent; } 194 {return _indent; }
192 195
193 /** 196 /**
194 * Sets the value. 197 * Sets the value.
195 */ 198 */
196 void setValue(int value) 199 void setValue(int value)
197 { QRangeControl::setValue(value); } 200 { QRangeControl::setValue(value); }
198 201
199 /** 202 /**
200 * @returns the value. 203 * @returns the value.
201 */ 204 */
202 int value() const 205 int value() const
203 { return QRangeControl::value(); } 206 { return QRangeControl::value(); }
204 207
205 /** 208 /**
206 * Sets the min value. 209 * Sets the min value.
207 */ 210 */
208 #if ( QT_VERSION > 290 ) 211 #if ( QT_VERSION > 290 )
209 void setMinValue(int value) { QRangeControl::setMinValue(value); } 212 void setMinValue(int value) { QRangeControl::setMinValue(value); }
210 #else 213 #else
211 void setMinValue(int value) { QRangeControl::setRange(value,QRangeControl::maxValue()); } 214 void setMinValue(int value) { QRangeControl::setRange(value,QRangeControl::maxValue()); }
212 #endif 215 #endif
213 216
214 /** 217 /**
215 * @return the min value. 218 * @return the min value.
216 */ 219 */
217 int minValue() const 220 int minValue() const
218 { return QRangeControl::minValue(); } 221 { return QRangeControl::minValue(); }
219 222
220 /** 223 /**
221 * Sets the max value. 224 * Sets the max value.
222 */ 225 */
223 #if ( QT_VERSION > 290 ) 226 #if ( QT_VERSION > 290 )
224 void setMaxValue(int value) { QRangeControl::setMaxValue(value); } 227 void setMaxValue(int value) { QRangeControl::setMaxValue(value); }
225 #else 228 #else
226 void setMaxValue(int value) { QRangeControl::setRange(QRangeControl::minValue(),value); } 229 void setMaxValue(int value) { QRangeControl::setRange(QRangeControl::minValue(),value); }
227 #endif 230 #endif
228 231
229 /** 232 /**
230 * @return the max value. 233 * @return the max value.
231 */ 234 */
232 int maxValue() const 235 int maxValue() const
233 { return QRangeControl::maxValue(); } 236 { return QRangeControl::maxValue(); }
234 237
235signals: 238signals:
236 /** 239 /**
237 * This signal is emitted whenever the user chooses a value, 240 * This signal is emitted whenever the user chooses a value,
238 * e.g. by clicking with the mouse on the widget. 241 * e.g. by clicking with the mouse on the widget.
239 */ 242 */
240 void valueChanged( int value ); 243 void valueChanged( int value );
241 244
242protected: 245protected:
243 /** 246 /**
244 * Override this function to draw the contents of the control. 247 * Override this function to draw the contents of the control.
245 * The default implementation does nothing. 248 * The default implementation does nothing.
246 * 249 *
247 * Draw only within contentsRect(). 250 * Draw only within contentsRect().
248 */ 251 */
249 virtual void drawContents( QPainter * ); 252 virtual void drawContents( QPainter * );
250 /** 253 /**
251 * Override this function to draw the cursor which 254 * Override this function to draw the cursor which
252 * indicates the current value. This function is 255 * indicates the current value. This function is
253 * always called twice, once with argument show=false 256 * always called twice, once with argument show=false
254 * to clear the old cursor, once with argument show=true 257 * to clear the old cursor, once with argument show=true
255 * to draw the new one. 258 * to draw the new one.
256 */ 259 */
257 virtual void drawArrow( QPainter *painter, bool show, const QPoint &pos ); 260 virtual void drawArrow( QPainter *painter, bool show, const QPoint &pos );
258 261
259 /** 262 /**
260 * @reimplemented 263 * @reimplemented
261 */ 264 */
262 virtual void valueChange(); 265 virtual void valueChange();
263 /** 266 /**
264 * @reimplemented 267 * @reimplemented
265 */ 268 */
266 virtual void paintEvent( QPaintEvent * ); 269 virtual void paintEvent( QPaintEvent * );
267 /** 270 /**
268 * @reimplemented 271 * @reimplemented
269 */ 272 */
270 virtual void mousePressEvent( QMouseEvent *e ); 273 virtual void mousePressEvent( QMouseEvent *e );
271 /** 274 /**
272 * @reimplemented 275 * @reimplemented
273 */ 276 */
274 virtual void mouseMoveEvent( QMouseEvent *e ); 277 virtual void mouseMoveEvent( QMouseEvent *e );
275 /** 278 /**
276 * @reimplemented 279 * @reimplemented
277 */ 280 */
278 virtual void wheelEvent( QWheelEvent * ); 281 virtual void wheelEvent( QWheelEvent * );
279 282
280private: 283private:
281 QPoint calcArrowPos( int val ); 284 QPoint calcArrowPos( int val );
282 void moveArrow( const QPoint &pos ); 285 void moveArrow( const QPoint &pos );
283 286
284 Orientation _orientation; 287 Orientation _orientation;
285 bool _indent; 288 bool _indent;
286 289
287private: 290private:
288 class OSelectorPrivate; 291 class OSelectorPrivate;
289 OSelectorPrivate *d; 292 OSelectorPrivate *d;
290}; 293};
291 294
292 295
293/** 296/**
294 * The OGradientSelector widget allows the user to choose 297 * The OGradientSelector widget allows the user to choose
295 * 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
296 * gradient between two colors provided by the programmer. 299 * gradient between two colors provided by the programmer.
297 */ 300 */
298class OGradientSelector : public OSelector 301class OGradientSelector : public OSelector
299{ 302{
300 Q_OBJECT 303 Q_OBJECT
301 304
302 Q_PROPERTY( QColor firstColor READ firstColor WRITE setFirstColor ) 305 Q_PROPERTY( QColor firstColor READ firstColor WRITE setFirstColor )
303 Q_PROPERTY( QColor secondColor READ secondColor WRITE setSecondColor ) 306 Q_PROPERTY( QColor secondColor READ secondColor WRITE setSecondColor )
304 Q_PROPERTY( QString firstText READ firstText WRITE setFirstText ) 307 Q_PROPERTY( QString firstText READ firstText WRITE setFirstText )
305 Q_PROPERTY( QString secondText READ secondText WRITE setSecondText ) 308 Q_PROPERTY( QString secondText READ secondText WRITE setSecondText )
306 309
307public: 310public:
308 /** 311 /**
309 * Constructs a horizontal color selector which 312 * Constructs a horizontal color selector which
310 * contains a gradient between white and black. 313 * contains a gradient between white and black.
311 */ 314 */
312 OGradientSelector( QWidget *parent=0, const char *name=0 ); 315 OGradientSelector( QWidget *parent=0, const char *name=0 );
313 /** 316 /**
314 * Constructs a colors selector with orientation o which 317 * Constructs a colors selector with orientation o which
315 * contains a gradient between white and black. 318 * contains a gradient between white and black.
316 */ 319 */
317 OGradientSelector( Orientation o, QWidget *parent=0, const char *name=0 ); 320 OGradientSelector( Orientation o, QWidget *parent=0, const char *name=0 );
318 /** 321 /**
319 * Destructs the widget. 322 * Destructs the widget.
320 */ 323 */
321 ~OGradientSelector(); 324 ~OGradientSelector();
322 /** 325 /**
323 * Sets the two colors which span the gradient. 326 * Sets the two colors which span the gradient.
324 */ 327 */
325 void setColors( const QColor &col1, const QColor &col2 ) 328 void setColors( const QColor &col1, const QColor &col2 )
326 {color1 = col1; color2 = col2; update();} 329 {color1 = col1; color2 = col2; update();}
327 void setText( const QString &t1, const QString &t2 ) 330 void setText( const QString &t1, const QString &t2 )
328 {text1 = t1; text2 = t2; update(); } 331 {text1 = t1; text2 = t2; update(); }
329 332
330 /** 333 /**
331 * Set each color on its own. 334 * Set each color on its own.
332 */ 335 */
333 void setFirstColor( const QColor &col ) 336 void setFirstColor( const QColor &col )
334 { color1 = col; update(); } 337 { color1 = col; update(); }
335 void setSecondColor( const QColor &col ) 338 void setSecondColor( const QColor &col )
336 { color2 = col; update(); } 339 { color2 = col; update(); }
337 340
338 /** 341 /**
339 * Set each description on its own 342 * Set each description on its own
340 */ 343 */
341 void setFirstText( const QString &t ) 344 void setFirstText( const QString &t )
342 { text1 = t; update(); } 345 { text1 = t; update(); }
343 void setSecondText( const QString &t ) 346 void setSecondText( const QString &t )
344 { text2 = t; update(); } 347 { text2 = t; update(); }
345 348
346 const QColor firstColor() const 349 const QColor firstColor() const
347 { return color1; } 350 { return color1; }
348 const QColor secondColor() const 351 const QColor secondColor() const
349 { return color2; } 352 { return color2; }
350 353
351 const QString firstText() const 354 const QString firstText() const
352 { return text1; } 355 { return text1; }
353 const QString secondText() const 356 const QString secondText() const
354 { return text2; } 357 { return text2; }
355 358
356protected: 359protected:
357 /** 360 /**
358 * @reimplemented 361 * @reimplemented
359 */ 362 */
360 virtual void drawContents( QPainter * ); 363 virtual void drawContents( QPainter * );
361 364
362 /** 365 /**
363 * @reimplemented 366 * @reimplemented
364 */ 367 */
365 virtual QSize minimumSize() const 368 virtual QSize minimumSize() const
366 { return sizeHint(); } 369 { return sizeHint(); }
367 370
368private: 371private:
369 void init(); 372 void init();
370 QColor color1; 373 QColor color1;
371 QColor color2; 374 QColor color2;
372 QString text1; 375 QString text1;
373 QString text2; 376 QString text2;
374 377
375private: 378private:
376 class OGradientSelectorPrivate; 379 class OGradientSelectorPrivate;
377 OGradientSelectorPrivate *d; 380 OGradientSelectorPrivate *d;
378}; 381};
379 382
380/** 383/**
381 * Widget for Hue/Saturation selection. 384 * Widget for Hue/Saturation selection.
382 * 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
383 * methods. 386 * methods.
384 * 387 *
385 * @see OXYSelector, OValueSelector, OColorDialog 388 * @see OXYSelector, OValueSelector, OColorDialog
386 * @author Martin Jones (mjones@kde.org) 389 * @author Martin Jones (mjones@kde.org)
387 * @version $Id$ 390 * @version $Id$
388*/ 391*/
389class OHSSelector : public OXYSelector 392class OHSSelector : public OXYSelector
390{ 393{
391 Q_OBJECT 394 Q_OBJECT
392 395
393public: 396public:
394 /** 397 /**
395 * Constructs a hue/saturation selection widget. 398 * Constructs a hue/saturation selection widget.
396 */ 399 */
397 OHSSelector( QWidget *parent=0, const char *name=0 ); 400 OHSSelector( QWidget *parent=0, const char *name=0 );
398 401
399protected: 402protected:
400 /** 403 /**
401 * Draws the contents of the widget on a pixmap, 404 * Draws the contents of the widget on a pixmap,
402 * which is used for buffering. 405 * which is used for buffering.
403 */ 406 */
404 virtual void drawPalette( QPixmap *pixmap ); 407 virtual void drawPalette( QPixmap *pixmap );
405 /** 408 /**
406 * @reimplemented 409 * @reimplemented
407 */ 410 */
408 virtual void resizeEvent( QResizeEvent * ); 411 virtual void resizeEvent( QResizeEvent * );
409 /** 412 /**
410 * Reimplemented from OXYSelector. This drawing is 413 * Reimplemented from OXYSelector. This drawing is
411 * buffered in a pixmap here. As real drawing 414 * buffered in a pixmap here. As real drawing
412 * routine, drawPalette() is used. 415 * routine, drawPalette() is used.
413 */ 416 */
414 virtual void drawContents( QPainter *painter ); 417 virtual void drawContents( QPainter *painter );
415 418
416private: 419private:
417 void updateContents(); 420 void updateContents();
418 QPixmap pixmap; 421 QPixmap pixmap;
419 422
420private: 423private:
421 class OHSSelectorPrivate; 424 class OHSSelectorPrivate;
422 OHSSelectorPrivate *d; 425 OHSSelectorPrivate *d;
423}; 426};
424 427
425 428
426class OValueSelectorPrivate; 429class OValueSelectorPrivate;
427/** 430/**
428 * Widget for color value selection. 431 * Widget for color value selection.
429 * 432 *
430 * @see OHSSelector, OColorDialog 433 * @see OHSSelector, OColorDialog
431 * @author Martin Jones (mjones@kde.org) 434 * @author Martin Jones (mjones@kde.org)
432 * @version $Id$ 435 * @version $Id$
433 */ 436 */
434class OValueSelector : public OSelector 437class OValueSelector : public OSelector
435{ 438{
436 Q_OBJECT 439 Q_OBJECT
437 440
438public: 441public:
439 /** 442 /**
440 * Constructs a widget for color selection. 443 * Constructs a widget for color selection.
441 */ 444 */
442 OValueSelector( QWidget *parent=0, const char *name=0 ); 445 OValueSelector( QWidget *parent=0, const char *name=0 );
443 /** 446 /**
444 * Constructs a widget for color selection with a given orientation 447 * Constructs a widget for color selection with a given orientation
445 */ 448 */
446 OValueSelector( Orientation o, QWidget *parent = 0, const char *name = 0 ); 449 OValueSelector( Orientation o, QWidget *parent = 0, const char *name = 0 );
447 450
448 int hue() const 451 int hue() const
449 { return _hue; } 452 { return _hue; }
450 void setHue( int h ) 453 void setHue( int h )
451 { _hue = h; } 454 { _hue = h; }
452 int saturation() const 455 int saturation() const
453 { return _sat; } 456 { return _sat; }
454 void setSaturation( int s ) 457 void setSaturation( int s )
455 { _sat = s; } 458 { _sat = s; }
456 459
457 void updateContents(); 460 void updateContents();
458protected: 461protected:
459 /** 462 /**
460 * Draws the contents of the widget on a pixmap, 463 * Draws the contents of the widget on a pixmap,
461 * which is used for buffering. 464 * which is used for buffering.
462 */ 465 */
463 virtual void drawPalette( QPixmap *pixmap ); 466 virtual void drawPalette( QPixmap *pixmap );
464 /** 467 /**
465 * @reimplemented 468 * @reimplemented
466 */ 469 */
467 virtual void resizeEvent( QResizeEvent * ); 470 virtual void resizeEvent( QResizeEvent * );
468 /** 471 /**
469 * Reimplemented from OSelector. The drawing is 472 * Reimplemented from OSelector. The drawing is
470 * buffered in a pixmap here. As real drawing 473 * buffered in a pixmap here. As real drawing
471 * routine, drawPalette() is used. 474 * routine, drawPalette() is used.
472 */ 475 */
473 virtual void drawContents( QPainter *painter ); 476 virtual void drawContents( QPainter *painter );
474 477
475private: 478private:
476 int _hue; 479 int _hue;
477 int _sat; 480 int _sat;
478 QPixmap pixmap; 481 QPixmap pixmap;
479 482
480private: 483private:
481 class OValueSelectorPrivate; 484 class OValueSelectorPrivate;
482 OValueSelectorPrivate *d; 485 OValueSelectorPrivate *d;
483}; 486};
484 487
485 488
486class OColor : public QColor 489class OColor : public QColor
487{ 490{
488public: 491public:
489 OColor(); 492 OColor();
490 OColor( const OColor &col); 493 OColor( const OColor &col);
491 OColor( const QColor &col); 494 OColor( const QColor &col);
492 495
493 OColor& operator=( const OColor& col); 496 OColor& operator=( const OColor& col);
494 497
495 bool operator==( const OColor& col) const; 498 bool operator==( const OColor& col) const;
496 499
497 void setHsv(int _h, int _s, int _v); 500 void setHsv(int _h, int _s, int _v);
498 void setRgb(int _r, int _g, int _b); 501 void setRgb(int _r, int _g, int _b);
499 502
500 void rgb(int *_r, int *_g, int *_b) const; 503 void rgb(int *_r, int *_g, int *_b) const;
501 void hsv(int *_h, int *_s, int *_v) const; 504 void hsv(int *_h, int *_s, int *_v) const;
502protected: 505protected:
503 int h; 506 int h;
504 int s; 507 int s;
505 int v; 508 int v;
506 int r; 509 int r;
507 int g; 510 int g;
508 int b; 511 int b;
509 512
510private: 513private:
511 class OColorPrivate; 514 class OColorPrivate;
512 OColorPrivate *d; 515 OColorPrivate *d;
513}; 516};
514 517
518}
519}
515 520
516 521
517 #endif // __OSELECT_H__ 522 #endif // __OSELECT_H__
518 523
diff --git a/libopie2/opieui/oseparator.cpp b/libopie2/opieui/oseparator.cpp
index b93c225..bbc4381 100644
--- a/libopie2/opieui/oseparator.cpp
+++ b/libopie2/opieui/oseparator.cpp
@@ -1,127 +1,129 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 3              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
4 Copyright (C) 1997 Michael Roth <mroth@wirlweb.de> 4 Copyright (C) 1997 Michael Roth <mroth@wirlweb.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32/* OPIE */ 32/* OPIE */
33 33
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35#include <opie2/oseparator.h> 35#include <opie2/oseparator.h>
36 36
37/* QT */ 37/* QT */
38 38
39using namespace Opie::Core;
40using namespace Opie::Ui;
39 41
40OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f) 42OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f)
41 : QFrame(parent, name, f) 43 : QFrame(parent, name, f)
42{ 44{
43 setLineWidth(1); 45 setLineWidth(1);
44 setMidLineWidth(0); 46 setMidLineWidth(0);
45 setOrientation( HLine ); 47 setOrientation( HLine );
46} 48}
47 49
48 50
49 51
50OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f) 52OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f)
51 : QFrame(parent, name, f) 53 : QFrame(parent, name, f)
52{ 54{
53 setLineWidth(1); 55 setLineWidth(1);
54 setMidLineWidth(0); 56 setMidLineWidth(0);
55 setOrientation( orientation ); 57 setOrientation( orientation );
56} 58}
57 59
58 60
59 61
60void OSeparator::setOrientation(int orientation) 62void OSeparator::setOrientation(int orientation)
61{ 63{
62 switch(orientation) 64 switch(orientation)
63 { 65 {
64 case Vertical: 66 case Vertical:
65 case VLine: 67 case VLine:
66 setFrameStyle( QFrame::VLine | QFrame::Sunken ); 68 setFrameStyle( QFrame::VLine | QFrame::Sunken );
67 setMinimumSize(2, 0); 69 setMinimumSize(2, 0);
68 break; 70 break;
69 71
70 default: 72 default:
71 owarn << "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" << oendl; 73 owarn << "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" << oendl;
72 74
73 case Horizontal: 75 case Horizontal:
74 case HLine: 76 case HLine:
75 setFrameStyle( QFrame::HLine | QFrame::Sunken ); 77 setFrameStyle( QFrame::HLine | QFrame::Sunken );
76 setMinimumSize(0, 2); 78 setMinimumSize(0, 2);
77 break; 79 break;
78 } 80 }
79} 81}
80 82
81 83
82 84
83int OSeparator::orientation() const 85int OSeparator::orientation() const
84{ 86{
85 if ( frameStyle() & VLine ) 87 if ( frameStyle() & VLine )
86 return VLine; 88 return VLine;
87 89
88 if ( frameStyle() & HLine ) 90 if ( frameStyle() & HLine )
89 return HLine; 91 return HLine;
90 92
91 return 0; 93 return 0;
92} 94}
93 95
94void OSeparator::drawFrame(QPainter *p) 96void OSeparator::drawFrame(QPainter *p)
95{ 97{
96 QPointp1, p2; 98 QPointp1, p2;
97 QRectr = frameRect(); 99 QRectr = frameRect();
98 const QColorGroup & g = colorGroup(); 100 const QColorGroup & g = colorGroup();
99 101
100 if ( frameStyle() & HLine ) { 102 if ( frameStyle() & HLine ) {
101 p1 = QPoint( r.x(), r.height()/2 ); 103 p1 = QPoint( r.x(), r.height()/2 );
102 p2 = QPoint( r.x()+r.width(), p1.y() ); 104 p2 = QPoint( r.x()+r.width(), p1.y() );
103 } 105 }
104 else { 106 else {
105 p1 = QPoint( r.x()+r.width()/2, 0 ); 107 p1 = QPoint( r.x()+r.width()/2, 0 );
106 p2 = QPoint( p1.x(), r.height() ); 108 p2 = QPoint( p1.x(), r.height() );
107 } 109 }
108 110
109#if QT_VERSION < 300 111#if QT_VERSION < 300
110 style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() ); 112 style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() );
111#else 113#else
112 QStyleOption opt( lineWidth(), midLineWidth() ); 114 QStyleOption opt( lineWidth(), midLineWidth() );
113 style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt ); 115 style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt );
114#endif 116#endif
115} 117}
116 118
117 119
118QSize OSeparator::sizeHint() const 120QSize OSeparator::sizeHint() const
119{ 121{
120 if ( frameStyle() & VLine ) 122 if ( frameStyle() & VLine )
121 return QSize(2, 0); 123 return QSize(2, 0);
122 124
123 if ( frameStyle() & HLine ) 125 if ( frameStyle() & HLine )
124 return QSize(0, 2); 126 return QSize(0, 2);
125 127
126 return QSize(-1, -1); 128 return QSize(-1, -1);
127} 129}
diff --git a/libopie2/opieui/oseparator.h b/libopie2/opieui/oseparator.h
index e59b3f4..6fc4344 100644
--- a/libopie2/opieui/oseparator.h
+++ b/libopie2/opieui/oseparator.h
@@ -1,90 +1,95 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 Copyright (C) 1997 Michael Roth <mroth@wirlweb.de> 5 Copyright (C) 1997 Michael Roth <mroth@wirlweb.de>
6 =. 6 =.
7 .=l. 7 .=l.
8           .>+-= 8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can 9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under 10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software 12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License, 13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version. 14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_. 15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that 16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of 18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more 21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details. 22++=   -.     .`     .: details.
23 :     =  ...= . :.=- 23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU 24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with 25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB. 26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation, 27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330, 28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. 29 Boston, MA 02111-1307, USA.
30 30
31*/ 31*/
32 32
33#ifndef OSEPARATOR_H 33#ifndef OSEPARATOR_H
34#define OSEPARATOR_H 34#define OSEPARATOR_H
35 35
36#include <qframe.h> 36#include <qframe.h>
37 37
38namespace Opie {
39namespace Ui {
40
38/** 41/**
39 * Standard horizontal or vertical separator. 42 * Standard horizontal or vertical separator.
40 * 43 *
41 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 44 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
42 * @author Michael Roth <mroth@wirlweb.de> 45 * @author Michael Roth <mroth@wirlweb.de>
43 * @version $Id$ 46 * @version $Id$
44*/ 47*/
45class OSeparator : public QFrame 48class OSeparator : public QFrame
46{ 49{
47 Q_OBJECT 50 Q_OBJECT
48 Q_PROPERTY( int orientation READ orientation WRITE setOrientation ) 51 Q_PROPERTY( int orientation READ orientation WRITE setOrientation )
49 public: 52 public:
50 /** 53 /**
51 * Constructor. 54 * Constructor.
52 **/ 55 **/
53 OSeparator(QWidget* parent=0, const char* name=0, WFlags f=0); 56 OSeparator(QWidget* parent=0, const char* name=0, WFlags f=0);
54 /** 57 /**
55 * Constructor. 58 * Constructor.
56 * 59 *
57 * @param orientation Set the orientation of the separator. 60 * @param orientation Set the orientation of the separator.
58 * Possible values are HLine or Horizontal and VLine or Vertical. 61 * Possible values are HLine or Horizontal and VLine or Vertical.
59 **/ 62 **/
60 OSeparator(int orientation, QWidget* parent=0, const char* name=0, 63 OSeparator(int orientation, QWidget* parent=0, const char* name=0,
61 WFlags f=0); 64 WFlags f=0);
62 65
63 /** 66 /**
64 * Returns the orientation of the separator. 67 * Returns the orientation of the separator.
65 * 68 *
66 * Possible values are VLine and HLine. 69 * Possible values are VLine and HLine.
67 **/ 70 **/
68 int orientation() const; 71 int orientation() const;
69 72
70 /** 73 /**
71 * Set the orientation of the separator to @p orient 74 * Set the orientation of the separator to @p orient
72 * 75 *
73 * Possible values are VLine and HLine. 76 * Possible values are VLine and HLine.
74 */ 77 */
75 void setOrientation(int orient); 78 void setOrientation(int orient);
76 79
77 /** 80 /**
78 * The recommended height (width) for a horizontal (vertical) separator. 81 * The recommended height (width) for a horizontal (vertical) separator.
79 **/ 82 **/
80 virtual QSize sizeHint() const; 83 virtual QSize sizeHint() const;
81 84
82protected: 85protected:
83 virtual void drawFrame( QPainter * ); 86 virtual void drawFrame( QPainter * );
84 87
85private: 88private:
86 class OSeparatorPrivate* d; 89 class OSeparatorPrivate* d;
87}; 90};
88 91
92}
93}
89 94
90#endif // OSEPARATOR_H 95#endif // OSEPARATOR_H
diff --git a/libopie2/opieui/otabbar.cpp b/libopie2/opieui/otabbar.cpp
index cd3a34b..a62e18b 100644
--- a/libopie2/opieui/otabbar.cpp
+++ b/libopie2/opieui/otabbar.cpp
@@ -1,83 +1,83 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include <opie2/otabbar.h> 32#include <opie2/otabbar.h>
33 33
34using namespace Opie; 34using namespace Opie::Ui;
35 35
36OTabBar::OTabBar( QWidget *parent , const char *name ) 36OTabBar::OTabBar( QWidget *parent , const char *name )
37 :QTabBar( parent, name ) 37 :QTabBar( parent, name )
38{} 38{}
39 39
40void OTabBar::paintLabel( QPainter* p, const QRect& br, QTab* t, bool has_focus ) const 40void OTabBar::paintLabel( QPainter* p, const QRect& br, QTab* t, bool has_focus ) const
41{ 41{
42 42
43 QRect r = br; 43 QRect r = br;
44 if ( t->iconset) 44 if ( t->iconset)
45 { 45 {
46 QIconSet::Mode mode = (t->enabled && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled; 46 QIconSet::Mode mode = (t->enabled && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled;
47 if ( mode == QIconSet::Normal && has_focus ) 47 if ( mode == QIconSet::Normal && has_focus )
48 { 48 {
49 mode = QIconSet::Active; 49 mode = QIconSet::Active;
50 } 50 }
51 QPixmap pixmap = t->iconset->pixmap( QIconSet::Small, mode ); 51 QPixmap pixmap = t->iconset->pixmap( QIconSet::Small, mode );
52 int pixw = pixmap.width(); 52 int pixw = pixmap.width();
53 int pixh = pixmap.height(); 53 int pixh = pixmap.height();
54 r.setLeft( r.left() + pixw + 2 ); 54 r.setLeft( r.left() + pixw + 2 );
55 p->drawPixmap( br.left()+2, br.center().y()-pixh/2, pixmap ); 55 p->drawPixmap( br.left()+2, br.center().y()-pixh/2, pixmap );
56 } 56 }
57 57
58 QRect tr = r; 58 QRect tr = r;
59 if ( t->id == currentTab() ) 59 if ( t->id == currentTab() )
60 { 60 {
61 tr.setBottom( tr.bottom() - style().defaultFrameWidth() ); 61 tr.setBottom( tr.bottom() - style().defaultFrameWidth() );
62 } 62 }
63 63
64 if ( t->enabled && isEnabled() ) 64 if ( t->enabled && isEnabled() )
65 { 65 {
66 p->setPen( colorGroup().foreground() ); 66 p->setPen( colorGroup().foreground() );
67 p->drawText( tr, AlignCenter | ShowPrefix, t->label ); 67 p->drawText( tr, AlignCenter | ShowPrefix, t->label );
68 } 68 }
69 else if ( style() == MotifStyle ) 69 else if ( style() == MotifStyle )
70 { 70 {
71 p->setPen( palette().disabled().foreground() ); 71 p->setPen( palette().disabled().foreground() );
72 p->drawText( tr, AlignCenter | ShowPrefix, t->label ); 72 p->drawText( tr, AlignCenter | ShowPrefix, t->label );
73 } 73 }
74 else 74 else
75 { 75 {
76 p->setPen( colorGroup().light() ); 76 p->setPen( colorGroup().light() );
77 QRect wr = tr; 77 QRect wr = tr;
78 wr.moveBy( 1, 1 ); 78 wr.moveBy( 1, 1 );
79 p->drawText( wr, AlignCenter | ShowPrefix, t->label ); 79 p->drawText( wr, AlignCenter | ShowPrefix, t->label );
80 p->setPen( palette().disabled().foreground() ); 80 p->setPen( palette().disabled().foreground() );
81 p->drawText( tr, AlignCenter | ShowPrefix, t->label ); 81 p->drawText( tr, AlignCenter | ShowPrefix, t->label );
82 } 82 }
83} 83}
diff --git a/libopie2/opieui/otabbar.h b/libopie2/opieui/otabbar.h
index 2f35c85..925ae96 100644
--- a/libopie2/opieui/otabbar.h
+++ b/libopie2/opieui/otabbar.h
@@ -1,85 +1,86 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#ifndef OTABBAR_H 32#ifndef OTABBAR_H
33#define OTABBAR_H 33#define OTABBAR_H
34 34
35/* QT */ 35/* QT */
36#include <qtabbar.h> 36#include <qtabbar.h>
37 37
38namespace Opie 38namespace Opie {
39{ 39namespace Ui {
40 40
41/** 41/**
42 * @class OTabBar 42 * @class OTabBar
43 * @brief The OTabBar class is a derivative of QTabBar. 43 * @brief The OTabBar class is a derivative of QTabBar.
44 * 44 *
45 * OTabBar is a derivation of TrollTech's QTabBar which provides 45 * OTabBar is a derivation of TrollTech's QTabBar which provides
46 * a row of tabs for selection. The only difference between this 46 * a row of tabs for selection. The only difference between this
47 * class and QTabBar is that there is no dotted line box around 47 * class and QTabBar is that there is no dotted line box around
48 * the label of the tab with the current focus. 48 * the label of the tab with the current focus.
49 */ 49 */
50class OTabBar : public QTabBar 50class OTabBar : public QTabBar
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54public: 54public:
55 /** 55 /**
56 * @fn OTabBar( QWidget *parent = 0, const char *name = 0 ) 56 * @fn OTabBar( QWidget *parent = 0, const char *name = 0 )
57 * @brief Object constructor. 57 * @brief Object constructor.
58 * 58 *
59 * @param parent Pointer to parent of this control. 59 * @param parent Pointer to parent of this control.
60 * @param name Name of control. 60 * @param name Name of control.
61 * 61 *
62 * Constructs a new OTabBar control with parent and name. 62 * Constructs a new OTabBar control with parent and name.
63 */ 63 */
64 OTabBar( QWidget * = 0, const char * = 0 ); 64 OTabBar( QWidget * = 0, const char * = 0 );
65 65
66protected: 66protected:
67 /** 67 /**
68 * @fn paintLabel( QPainter* p, const QRect& br , QTab* t, bool has_focus)const 68 * @fn paintLabel( QPainter* p, const QRect& br , QTab* t, bool has_focus)const
69 * @brief Internal function to draw a tab's label. 69 * @brief Internal function to draw a tab's label.
70 * 70 *
71 * @param p Pointer to QPainter used for drawing. 71 * @param p Pointer to QPainter used for drawing.
72 * @param br QRect providing region to draw label in. 72 * @param br QRect providing region to draw label in.
73 * @param t Tab to draw label for. 73 * @param t Tab to draw label for.
74 * @param has_focus Boolean value not used, retained for compatibility reasons. 74 * @param has_focus Boolean value not used, retained for compatibility reasons.
75 */ 75 */
76 void paintLabel( QPainter *, const QRect &, QTab *, bool ) const; 76 void paintLabel( QPainter *, const QRect &, QTab *, bool ) const;
77 77
78private: 78private:
79 class Private; 79 class Private;
80 Private *d; 80 Private *d;
81}; 81};
82 82
83}; 83}
84}
84 85
85#endif 86#endif
diff --git a/libopie2/opieui/otabinfo.h b/libopie2/opieui/otabinfo.h
index 4a6ce14..426c45a 100644
--- a/libopie2/opieui/otabinfo.h
+++ b/libopie2/opieui/otabinfo.h
@@ -1,140 +1,141 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#ifndef OTABINFO_H 32#ifndef OTABINFO_H
33#define OTABINFO_H 33#define OTABINFO_H
34 34
35/* QT */ 35/* QT */
36#include <qlist.h> 36#include <qlist.h>
37#include <qstring.h> 37#include <qstring.h>
38 38
39class QWidget; 39class QWidget;
40 40
41namespace Opie 41namespace Opie{
42{ 42namespace Ui {
43 43
44/** 44/**
45 * @class OTabInfo 45 * @class OTabInfo
46 * @brief The OTabInfo class is used internally by OTabWidget to keep track 46 * @brief The OTabInfo class is used internally by OTabWidget to keep track
47 * of widgets added to the control. 47 * of widgets added to the control.
48 * 48 *
49 * OTabInfo provides the following information about a widget added to an 49 * OTabInfo provides the following information about a widget added to an
50 * OTabWidget control: 50 * OTabWidget control:
51 * 51 *
52 * ID - integer tab bar ID 52 * ID - integer tab bar ID
53 * Control - QWidget pointer to child widget 53 * Control - QWidget pointer to child widget
54 * Label - QString text label for OTabWidget selection control 54 * Label - QString text label for OTabWidget selection control
55 * Icon - QString name of icon file 55 * Icon - QString name of icon file
56 */ 56 */
57class OTabInfo 57class OTabInfo
58{ 58{
59public: 59public:
60 /** 60 /**
61 * @fn OTabInfo() 61 * @fn OTabInfo()
62 * @brief Object constructor. 62 * @brief Object constructor.
63 * 63 *
64 * @param parent Pointer to parent of this control. 64 * @param parent Pointer to parent of this control.
65 * @param name Name of control. 65 * @param name Name of control.
66 * @param s Style of widget selection control. 66 * @param s Style of widget selection control.
67 * @param p Position of the widget selection control. 67 * @param p Position of the widget selection control.
68 */ 68 */
69 OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {} 69 OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {}
70 70
71 /** 71 /**
72 * @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) 72 * @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label )
73 * @brief Object constructor. 73 * @brief Object constructor.
74 * 74 *
75 * @param id TabBar identifier for widget. 75 * @param id TabBar identifier for widget.
76 * @param control QWidget pointer to widget. 76 * @param control QWidget pointer to widget.
77 * @param icon QString name of icon file. 77 * @param icon QString name of icon file.
78 * @param label QString text label for OTabWidget selection control. 78 * @param label QString text label for OTabWidget selection control.
79 */ 79 */
80 OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) 80 OTabInfo( int id, QWidget *control, const QString &icon, const QString &label )
81 : i( id ), c( control ), p( icon ), l( label ) {} 81 : i( id ), c( control ), p( icon ), l( label ) {}
82 82
83 /** 83 /**
84 * @fn id()const 84 * @fn id()const
85 * @brief Returns TabBar ID. 85 * @brief Returns TabBar ID.
86 */ 86 */
87 int id() const { return i; } 87 int id() const { return i; }
88 88
89 /** 89 /**
90 * @fn label()const 90 * @fn label()const
91 * @brief Returns text label for widget. 91 * @brief Returns text label for widget.
92 */ 92 */
93 const QString &label() const { return l; } 93 const QString &label() const { return l; }
94 94
95 /** 95 /**
96 * @fn setLabel( const QString &label ) 96 * @fn setLabel( const QString &label )
97 * @brief Set label for tab. 97 * @brief Set label for tab.
98 * 98 *
99 * @param label QString text label for OTabWidget selection control. 99 * @param label QString text label for OTabWidget selection control.
100 */ 100 */
101 void setLabel( const QString &label ) { l = label; } 101 void setLabel( const QString &label ) { l = label; }
102 102
103 /** 103 /**
104 * @fn control()const 104 * @fn control()const
105 * @brief Returns pointer to widget. 105 * @brief Returns pointer to widget.
106 */ 106 */
107 QWidget *control() const { return c; } 107 QWidget *control() const { return c; }
108 108
109 /** 109 /**
110 * @fn icon()const 110 * @fn icon()const
111 * @brief Returns name of icon file. 111 * @brief Returns name of icon file.
112 */ 112 */
113 const QString &icon() const { return p; } 113 const QString &icon() const { return p; }
114 114
115 /** 115 /**
116 * @fn setIcon( const QString &icon ) 116 * @fn setIcon( const QString &icon )
117 * @brief Set icon for tab. 117 * @brief Set icon for tab.
118 * 118 *
119 * @param icon QString name of icon file. 119 * @param icon QString name of icon file.
120 */ 120 */
121 void setIcon( const QString &icon ) { p = icon; } 121 void setIcon( const QString &icon ) { p = icon; }
122 122
123private: 123private:
124 int i; 124 int i;
125 QWidget *c; 125 QWidget *c;
126 QString p; 126 QString p;
127 QString l; 127 QString l;
128 class Private; 128 class Private;
129 Private *d; 129 Private *d;
130}; 130};
131 131
132/** 132/**
133 * @class OTabInfoList 133 * @class OTabInfoList
134 * @brief A list of OTabInfo objects used by OTabWidget. 134 * @brief A list of OTabInfo objects used by OTabWidget.
135 */ 135 */
136typedef QList<OTabInfo> OTabInfoList; 136typedef QList<OTabInfo> OTabInfoList;
137 137
138}; 138}
139}
139 140
140#endif 141#endif
diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp
index f47c90b..a9f7da9 100644
--- a/libopie2/opieui/otabwidget.cpp
+++ b/libopie2/opieui/otabwidget.cpp
@@ -1,423 +1,423 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include <opie2/otabwidget.h> 32#include <opie2/otabwidget.h>
33 33
34/* OPIE */ 34/* OPIE */
35#include <qpe/applnk.h> 35#include <qpe/applnk.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <qpe/resource.h> 37#include <qpe/resource.h>
38#include <opie2/otabbar.h> 38#include <opie2/otabbar.h>
39 39
40/* QT */ 40/* QT */
41#include <qcombobox.h> 41#include <qcombobox.h>
42#include <qwidgetstack.h> 42#include <qwidgetstack.h>
43 43
44using namespace Opie; 44using namespace Opie::Ui;
45 45
46OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) 46OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p )
47 : QWidget( parent, name ) 47 : QWidget( parent, name )
48{ 48{
49 if ( s == Global ) 49 if ( s == Global )
50 { 50 {
51 Config config( "qpe" ); 51 Config config( "qpe" );
52 config.setGroup( "Appearance" ); 52 config.setGroup( "Appearance" );
53 s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); 53 s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab );
54 if ( s <= Global || s > IconList) 54 if ( s <= Global || s > IconList)
55 { 55 {
56 s = IconTab; 56 s = IconTab;
57 } 57 }
58 QString pos = config.readEntry( "TabPosition", "Top"); 58 QString pos = config.readEntry( "TabPosition", "Top");
59 if ( pos == "Bottom" ) 59 if ( pos == "Bottom" )
60 { 60 {
61 p = Bottom; 61 p = Bottom;
62 } 62 }
63 else 63 else
64 { 64 {
65 p = Top; 65 p = Top;
66 } 66 }
67 } 67 }
68 68
69 widgetStack = new QWidgetStack( this, "widgetstack" ); 69 widgetStack = new QWidgetStack( this, "widgetstack" );
70 widgetStack->setFrameStyle( QFrame::NoFrame ); 70 widgetStack->setFrameStyle( QFrame::NoFrame );
71 widgetStack->setLineWidth( style().defaultFrameWidth() ); 71 widgetStack->setLineWidth( style().defaultFrameWidth() );
72 72
73 tabBarStack = new QWidgetStack( this, "tabbarstack" ); 73 tabBarStack = new QWidgetStack( this, "tabbarstack" );
74 74
75 tabBar = new OTabBar( tabBarStack, "tabbar" ); 75 tabBar = new OTabBar( tabBarStack, "tabbar" );
76 tabBarStack->addWidget( tabBar, 0 ); 76 tabBarStack->addWidget( tabBar, 0 );
77 connect( tabBar, SIGNAL( selected(int) ), this, SLOT( slotTabBarSelected(int) ) ); 77 connect( tabBar, SIGNAL( selected(int) ), this, SLOT( slotTabBarSelected(int) ) );
78 78
79 tabList = new QComboBox( false, tabBarStack, "tablist" ); 79 tabList = new QComboBox( false, tabBarStack, "tablist" );
80 tabBarStack->addWidget( tabList, 1 ); 80 tabBarStack->addWidget( tabList, 1 );
81 connect( tabList, SIGNAL( activated(int) ), this, SLOT( slotTabListSelected(int) ) ); 81 connect( tabList, SIGNAL( activated(int) ), this, SLOT( slotTabListSelected(int) ) );
82 82
83 tabBarPosition = p; 83 tabBarPosition = p;
84 setTabStyle( s ); 84 setTabStyle( s );
85 setTabPosition( p ); 85 setTabPosition( p );
86 86
87 currTab= 0x0; 87 currTab= 0x0;
88} 88}
89 89
90OTabWidget::~OTabWidget() 90OTabWidget::~OTabWidget()
91{} 91{}
92 92
93void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) 93void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
94{ 94{
95 QPixmap iconset = loadSmooth( icon ); 95 QPixmap iconset = loadSmooth( icon );
96 96
97 QTab *tab = new QTab(); 97 QTab *tab = new QTab();
98 if ( tabBarStyle == IconTab ) 98 if ( tabBarStyle == IconTab )
99 { 99 {
100 tab->label = QString::null; 100 tab->label = QString::null;
101 } 101 }
102 else 102 else
103 { 103 {
104 tab->label = label; 104 tab->label = label;
105 } 105 }
106 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 106 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
107 { 107 {
108 tab->iconset = new QIconSet( iconset ); 108 tab->iconset = new QIconSet( iconset );
109 } 109 }
110 int tabid = tabBar->addTab( tab ); 110 int tabid = tabBar->addTab( tab );
111 111
112 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 112 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
113 { 113 {
114 tabList->insertItem( iconset, label, -1 ); 114 tabList->insertItem( iconset, label, -1 );
115 } 115 }
116 else 116 else
117 { 117 {
118 tabList->insertItem( label ); 118 tabList->insertItem( label );
119 } 119 }
120 120
121 widgetStack->addWidget( child, tabid ); 121 widgetStack->addWidget( child, tabid );
122 widgetStack->raiseWidget( child ); 122 widgetStack->raiseWidget( child );
123 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); 123 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
124 124
125 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); 125 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
126 tabs.append( tabinfo ); 126 tabs.append( tabinfo );
127 selectTab( tabinfo ); 127 selectTab( tabinfo );
128} 128}
129 129
130void OTabWidget::removePage( QWidget *childwidget ) 130void OTabWidget::removePage( QWidget *childwidget )
131{ 131{
132 if ( childwidget ) 132 if ( childwidget )
133 { 133 {
134 OTabInfo *tab = tabs.first(); 134 OTabInfo *tab = tabs.first();
135 while ( tab && tab->control() != childwidget ) 135 while ( tab && tab->control() != childwidget )
136 { 136 {
137 tab = tabs.next(); 137 tab = tabs.next();
138 } 138 }
139 if ( tab && tab->control() == childwidget ) 139 if ( tab && tab->control() == childwidget )
140 { 140 {
141 tabBar->setTabEnabled( tab->id(), FALSE ); 141 tabBar->setTabEnabled( tab->id(), FALSE );
142 tabBar->removeTab( tabBar->tab( tab->id() ) ); 142 tabBar->removeTab( tabBar->tab( tab->id() ) );
143 int i = 0; 143 int i = 0;
144 while ( i < tabList->count() && tabList->text( i ) != tab->label() ) 144 while ( i < tabList->count() && tabList->text( i ) != tab->label() )
145 { 145 {
146 i++; 146 i++;
147 } 147 }
148 if ( tabList->text( i ) == tab->label() ) 148 if ( tabList->text( i ) == tab->label() )
149 { 149 {
150 tabList->removeItem( i ); 150 tabList->removeItem( i );
151 } 151 }
152 widgetStack->removeWidget( childwidget ); 152 widgetStack->removeWidget( childwidget );
153 tabs.remove( tab ); 153 tabs.remove( tab );
154 delete tab; 154 delete tab;
155 currTab = tabs.current(); 155 currTab = tabs.current();
156 if ( !currTab ) 156 if ( !currTab )
157 { 157 {
158 widgetStack->setFrameStyle( QFrame::NoFrame ); 158 widgetStack->setFrameStyle( QFrame::NoFrame );
159 } 159 }
160 160
161 setUpLayout(); 161 setUpLayout();
162 } 162 }
163 } 163 }
164} 164}
165 165
166void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) 166void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
167{ 167{
168 OTabInfo *currtab = tabs.first(); 168 OTabInfo *currtab = tabs.first();
169 while ( currtab && currtab->control() != widget ) 169 while ( currtab && currtab->control() != widget )
170 { 170 {
171 currtab = tabs.next(); 171 currtab = tabs.next();
172 } 172 }
173 if ( currtab && currtab->control() == widget ) 173 if ( currtab && currtab->control() == widget )
174 { 174 {
175 QTab *tab = tabBar->tab( currtab->id() ); 175 QTab *tab = tabBar->tab( currtab->id() );
176 QPixmap icon( loadSmooth( iconset ) ); 176 QPixmap icon( loadSmooth( iconset ) );
177 tab->setText( label ); 177 tab->setText( label );
178 if ( tabBarStyle == IconTab ) 178 if ( tabBarStyle == IconTab )
179 tab->setIconSet( icon ); 179 tab->setIconSet( icon );
180 int i = 0; 180 int i = 0;
181 while ( i < tabList->count() && tabList->text( i ) != currtab->label() ) 181 while ( i < tabList->count() && tabList->text( i ) != currtab->label() )
182 { 182 {
183 i++; 183 i++;
184 } 184 }
185 if ( i < tabList->count() && tabList->text( i ) == currtab->label() ) 185 if ( i < tabList->count() && tabList->text( i ) == currtab->label() )
186 { 186 {
187 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 187 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
188 { 188 {
189 tabList->changeItem( icon, label, i ); 189 tabList->changeItem( icon, label, i );
190 } 190 }
191 else 191 else
192 { 192 {
193 tabList->changeItem( label, i ); 193 tabList->changeItem( label, i );
194 } 194 }
195 } 195 }
196 currtab->setLabel( label ); 196 currtab->setLabel( label );
197 currtab->setIcon( iconset ); 197 currtab->setIcon( iconset );
198 } 198 }
199 setUpLayout(); 199 setUpLayout();
200} 200}
201 201
202void OTabWidget::setCurrentTab( QWidget *childwidget ) 202void OTabWidget::setCurrentTab( QWidget *childwidget )
203{ 203{
204 OTabInfo *currtab = tabs.first(); 204 OTabInfo *currtab = tabs.first();
205 while ( currtab && currtab->control() != childwidget ) 205 while ( currtab && currtab->control() != childwidget )
206 { 206 {
207 currtab = tabs.next(); 207 currtab = tabs.next();
208 } 208 }
209 if ( currtab && currtab->control() == childwidget ) 209 if ( currtab && currtab->control() == childwidget )
210 { 210 {
211 selectTab( currtab ); 211 selectTab( currtab );
212 } 212 }
213} 213}
214 214
215void OTabWidget::setCurrentTab( const QString &tabname ) 215void OTabWidget::setCurrentTab( const QString &tabname )
216{ 216{
217 OTabInfo *newtab = tabs.first(); 217 OTabInfo *newtab = tabs.first();
218 while ( newtab && newtab->label() != tabname ) 218 while ( newtab && newtab->label() != tabname )
219 { 219 {
220 newtab = tabs.next(); 220 newtab = tabs.next();
221 } 221 }
222 if ( newtab && newtab->label() == tabname ) 222 if ( newtab && newtab->label() == tabname )
223 { 223 {
224 selectTab( newtab ); 224 selectTab( newtab );
225 } 225 }
226} 226}
227 227
228void OTabWidget::setCurrentTab(int tabindex) 228void OTabWidget::setCurrentTab(int tabindex)
229{ 229{
230 OTabInfo *newtab = tabs.first(); 230 OTabInfo *newtab = tabs.first();
231 while ( newtab && newtab->id() != tabindex ) 231 while ( newtab && newtab->id() != tabindex )
232 { 232 {
233 newtab = tabs.next(); 233 newtab = tabs.next();
234 } 234 }
235 if ( newtab && newtab->id() == tabindex ) 235 if ( newtab && newtab->id() == tabindex )
236 { 236 {
237 selectTab( newtab ); 237 selectTab( newtab );
238 } 238 }
239} 239}
240 240
241 241
242OTabWidget::TabStyle OTabWidget::tabStyle() const 242OTabWidget::TabStyle OTabWidget::tabStyle() const
243{ 243{
244 return tabBarStyle; 244 return tabBarStyle;
245} 245}
246 246
247void OTabWidget::setTabStyle( TabStyle s ) 247void OTabWidget::setTabStyle( TabStyle s )
248{ 248{
249 tabBarStyle = s; 249 tabBarStyle = s;
250 if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) 250 if ( tabBarStyle == TextTab || tabBarStyle == IconTab )
251 { 251 {
252 QTab *currtab; 252 QTab *currtab;
253 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) 253 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
254 { 254 {
255 currtab = tabBar->tab( tabinfo->id() ); 255 currtab = tabBar->tab( tabinfo->id() );
256 if ( tabBarStyle == IconTab ) 256 if ( tabBarStyle == IconTab )
257 { 257 {
258 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); 258 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
259 if ( tabinfo == currTab ) 259 if ( tabinfo == currTab )
260 currtab->setText( tabinfo->label() ); 260 currtab->setText( tabinfo->label() );
261 else 261 else
262 currtab->setText( QString::null ); 262 currtab->setText( QString::null );
263 } 263 }
264 else 264 else
265 { 265 {
266 currtab->iconset = 0x0; 266 currtab->iconset = 0x0;
267 currtab->setText( tabinfo->label() ); 267 currtab->setText( tabinfo->label() );
268 } 268 }
269 } 269 }
270 tabBarStack->raiseWidget( tabBar ); 270 tabBarStack->raiseWidget( tabBar );
271 } 271 }
272 else if ( tabBarStyle == TextList || tabBarStyle == IconList ) 272 else if ( tabBarStyle == TextList || tabBarStyle == IconList )
273 { 273 {
274 tabList->clear(); 274 tabList->clear();
275 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) 275 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
276 { 276 {
277 if ( tabBarStyle == IconList ) 277 if ( tabBarStyle == IconList )
278 { 278 {
279 tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); 279 tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() );
280 } 280 }
281 else 281 else
282 { 282 {
283 tabList->insertItem( tabinfo->label() ); 283 tabList->insertItem( tabinfo->label() );
284 } 284 }
285 } 285 }
286 tabBarStack->raiseWidget( tabList ); 286 tabBarStack->raiseWidget( tabList );
287 } 287 }
288 setUpLayout(); 288 setUpLayout();
289} 289}
290 290
291OTabWidget::TabPosition OTabWidget::tabPosition() const 291OTabWidget::TabPosition OTabWidget::tabPosition() const
292{ 292{
293 return tabBarPosition; 293 return tabBarPosition;
294} 294}
295 295
296void OTabWidget::setTabPosition( TabPosition p ) 296void OTabWidget::setTabPosition( TabPosition p )
297{ 297{
298 tabBarPosition = p; 298 tabBarPosition = p;
299 if ( tabBarPosition == Top ) 299 if ( tabBarPosition == Top )
300 { 300 {
301 tabBar->setShape( QTabBar::RoundedAbove ); 301 tabBar->setShape( QTabBar::RoundedAbove );
302 } 302 }
303 else 303 else
304 { 304 {
305 tabBar->setShape( QTabBar::RoundedBelow ); 305 tabBar->setShape( QTabBar::RoundedBelow );
306 } 306 }
307 setUpLayout(); 307 setUpLayout();
308} 308}
309 309
310void OTabWidget::slotTabBarSelected( int id ) 310void OTabWidget::slotTabBarSelected( int id )
311{ 311{
312 OTabInfo *newtab = tabs.first(); 312 OTabInfo *newtab = tabs.first();
313 while ( newtab && newtab->id() != id ) 313 while ( newtab && newtab->id() != id )
314 { 314 {
315 newtab = tabs.next(); 315 newtab = tabs.next();
316 } 316 }
317 if ( newtab && newtab->id() == id ) 317 if ( newtab && newtab->id() == id )
318 { 318 {
319 selectTab( newtab ); 319 selectTab( newtab );
320 } 320 }
321} 321}
322 322
323void OTabWidget::slotTabListSelected( int index ) 323void OTabWidget::slotTabListSelected( int index )
324{ 324{
325 OTabInfo *newtab = tabs.at( index ); 325 OTabInfo *newtab = tabs.at( index );
326 if ( newtab ) 326 if ( newtab )
327 { 327 {
328 selectTab( newtab ); 328 selectTab( newtab );
329 } 329 }
330} 330}
331 331
332QPixmap OTabWidget::loadSmooth( const QString &name ) 332QPixmap OTabWidget::loadSmooth( const QString &name )
333{ 333{
334 QPixmap p; 334 QPixmap p;
335 p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); 335 p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) );
336 return p; 336 return p;
337} 337}
338 338
339void OTabWidget::selectTab( OTabInfo *tab ) 339void OTabWidget::selectTab( OTabInfo *tab )
340{ 340{
341 if ( tabBarStyle == IconTab ) 341 if ( tabBarStyle == IconTab )
342 { 342 {
343 if ( currTab ) 343 if ( currTab )
344 { 344 {
345 tabBar->tab( currTab->id() )->setText( QString::null ); 345 tabBar->tab( currTab->id() )->setText( QString::null );
346 setUpLayout(); 346 setUpLayout();
347 } 347 }
348 tabBar->tab( tab->id() )->setText( tab->label() ); 348 tabBar->tab( tab->id() )->setText( tab->label() );
349 tabBar->setCurrentTab( tab->id() ); 349 tabBar->setCurrentTab( tab->id() );
350 setUpLayout(); 350 setUpLayout();
351 tabBar->update(); 351 tabBar->update();
352 } 352 }
353 else 353 else
354 { 354 {
355 tabBar->setCurrentTab( tab->id() ); 355 tabBar->setCurrentTab( tab->id() );
356 } 356 }
357 357
358 widgetStack->raiseWidget( tab->control() ); 358 widgetStack->raiseWidget( tab->control() );
359 359
360 emit currentChanged( tab->control() ); 360 emit currentChanged( tab->control() );
361 361
362 currTab = tab; 362 currTab = tab;
363} 363}
364 364
365void OTabWidget::setUpLayout() 365void OTabWidget::setUpLayout()
366{ 366{
367 tabBar->layoutTabs(); 367 tabBar->layoutTabs();
368 QSize t( tabBarStack->sizeHint() ); 368 QSize t( tabBarStack->sizeHint() );
369 if ( tabBarStyle == IconTab ) 369 if ( tabBarStyle == IconTab )
370 { 370 {
371 if ( t.width() > width() ) 371 if ( t.width() > width() )
372 t.setWidth( width() ); 372 t.setWidth( width() );
373 } 373 }
374 else 374 else
375 { 375 {
376 t.setWidth( width() ); 376 t.setWidth( width() );
377 } 377 }
378 int lw = widgetStack->lineWidth(); 378 int lw = widgetStack->lineWidth();
379 if ( tabBarPosition == Bottom ) 379 if ( tabBarPosition == Bottom )
380 { 380 {
381 tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); 381 tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
382 widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); 382 widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) );
383 } 383 }
384 else 384 else
385 { 385 {
386 tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); 386 tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
387 widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); 387 widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) );
388 } 388 }
389 389
390 if ( autoMask() ) 390 if ( autoMask() )
391 updateMask(); 391 updateMask();
392} 392}
393 393
394QSize OTabWidget::sizeHint() const 394QSize OTabWidget::sizeHint() const
395{ 395{
396 QSize s( widgetStack->sizeHint() ); 396 QSize s( widgetStack->sizeHint() );
397 QSize t( tabBarStack->sizeHint() ); 397 QSize t( tabBarStack->sizeHint() );
398 return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() ); 398 return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() );
399} 399}
400 400
401void OTabWidget::resizeEvent( QResizeEvent * ) 401void OTabWidget::resizeEvent( QResizeEvent * )
402{ 402{
403 setUpLayout(); 403 setUpLayout();
404} 404}
405 405
406int OTabWidget::currentTab() 406int OTabWidget::currentTab()
407{ 407{
408 if ( currTab ) 408 if ( currTab )
409 { 409 {
410 return currTab->id(); 410 return currTab->id();
411 } 411 }
412 return -1; 412 return -1;
413} 413}
414 414
415QWidget* OTabWidget::currentWidget()const 415QWidget* OTabWidget::currentWidget()const
416{ 416{
417 if ( currTab ) 417 if ( currTab )
418 { 418 {
419 return currTab->control(); 419 return currTab->control();
420 } 420 }
421 421
422 return 0; 422 return 0;
423} 423}
diff --git a/libopie2/opieui/otabwidget.h b/libopie2/opieui/otabwidget.h
index 092f22c..6a64b7d 100644
--- a/libopie2/opieui/otabwidget.h
+++ b/libopie2/opieui/otabwidget.h
@@ -1,292 +1,292 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2002 Dan Williams <williamsdr@acm.org> 3              Copyright (C) 2002 Dan Williams <williamsdr@acm.org>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#ifndef OTABWIDGET_H 31#ifndef OTABWIDGET_H
32#define OTABWIDGET_H 32#define OTABWIDGET_H
33 33
34/* OPIE */ 34/* OPIE */
35#include <opie2/otabinfo.h> 35#include <opie2/otabinfo.h>
36 36
37/* QT */ 37/* QT */
38#include <qwidget.h> 38#include <qwidget.h>
39#include <qlist.h> 39#include <qlist.h>
40 40
41using namespace Opie;
42 41
43class QComboBox; 42class QComboBox;
44class QPixmap; 43class QPixmap;
45class QTabBar; 44class QTabBar;
46class QWidgetStack; 45class QWidgetStack;
47 46
48namespace Opie 47namespace Opie {
49{ 48namespace Ui {
50 49
51class OTabBar; 50class OTabBar;
52 51
53/** 52/**
54 * @class OTabWidget 53 * @class OTabWidget
55 * @brief The OTabWidget class provides a stack of widgets. 54 * @brief The OTabWidget class provides a stack of widgets.
56 * 55 *
57 * OTabWidget is a derivation of TrollTech's QTabWidget which provides 56 * OTabWidget is a derivation of TrollTech's QTabWidget which provides
58 * a stack of widgets. Widgets can be selected using either a tab bar or 57 * a stack of widgets. Widgets can be selected using either a tab bar or
59 * drop down list box. 58 * drop down list box.
60 * 59 *
61 * The normal way to use OTabWidget is to do the following in the 60 * The normal way to use OTabWidget is to do the following in the
62 * constructor: 61 * constructor:
63 * - Create a OTabWidget. 62 * - Create a OTabWidget.
64 * - Create a QWidget for each of the pages in the control, insert 63 * - Create a QWidget for each of the pages in the control, insert
65 * children into it, set up geometry management for it, and use addTab() 64 * children into it, set up geometry management for it, and use addTab()
66 * to add the widget. 65 * to add the widget.
67 */ 66 */
68class OTabWidget : public QWidget 67class OTabWidget : public QWidget
69{ 68{
70 Q_OBJECT 69 Q_OBJECT
71 70
72 public: 71 public:
73/** 72/**
74 * @enum TabStyle 73 * @enum TabStyle
75 * @brief Defines how the widget selection control is displayed. 74 * @brief Defines how the widget selection control is displayed.
76 * 75 *
77 * Valid values: 76 * Valid values:
78 * - Global: use globally selected options (qpe.conf - TabStyle & TabPosition) 77 * - Global: use globally selected options (qpe.conf - TabStyle & TabPosition)
79 * - TextTab: Tabbed widget selection with text labels 78 * - TextTab: Tabbed widget selection with text labels
80 * - IconTab: Tabbed widget selection with icon labels, text label for active widget 79 * - IconTab: Tabbed widget selection with icon labels, text label for active widget
81 * (similar to Opie launcher) 80 * (similar to Opie launcher)
82 * - TextList: Drop down list widget selection with text labels 81 * - TextList: Drop down list widget selection with text labels
83 * - IconList: Drop down list widget selection with icon & text labels 82 * - IconList: Drop down list widget selection with icon & text labels
84 */ 83 */
85 enum TabStyle { Global, TextTab, IconTab, TextList, IconList }; 84 enum TabStyle { Global, TextTab, IconTab, TextList, IconList };
86 85
87/** 86/**
88 * @enum TabPosition 87 * @enum TabPosition
89 * @brief Defines where the widget selection control is drawn. 88 * @brief Defines where the widget selection control is drawn.
90 * 89 *
91 * Valid values: 90 * Valid values:
92 * - Top: Widget selection control is drawn above widgets 91 * - Top: Widget selection control is drawn above widgets
93 * - Bottom: Widget selection control is drawn below widgets 92 * - Bottom: Widget selection control is drawn below widgets
94 */ 93 */
95 enum TabPosition { Top, Bottom }; 94 enum TabPosition { Top, Bottom };
96 95
97/** 96/**
98 * @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top ) 97 * @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top )
99 * @brief Object constructor. 98 * @brief Object constructor.
100 * 99 *
101 * @param parent Pointer to parent of this control. 100 * @param parent Pointer to parent of this control.
102 * @param name Name of control. 101 * @param name Name of control.
103 * @param s Style of widget selection control. 102 * @param s Style of widget selection control.
104 * @param p Position of the widget selection control. 103 * @param p Position of the widget selection control.
105 * 104 *
106 * Constructs a new OTabWidget control with parent and name. The style and position parameters 105 * Constructs a new OTabWidget control with parent and name. The style and position parameters
107 * determine how the widget selection control will be displayed. 106 * determine how the widget selection control will be displayed.
108 */ 107 */
109 OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top ); 108 OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top );
110 109
111/** 110/**
112 * @fn ~OTabWidget() 111 * @fn ~OTabWidget()
113 * @brief Object destructor. 112 * @brief Object destructor.
114 */ 113 */
115 ~OTabWidget(); 114 ~OTabWidget();
116 115
117/** 116/**
118 * @fn addTab( QWidget *child, const QString &icon, const QString &label ) 117 * @fn addTab( QWidget *child, const QString &icon, const QString &label )
119 * @brief Add new widget to control. 118 * @brief Add new widget to control.
120 * 119 *
121 * @param child Widget control. 120 * @param child Widget control.
122 * @param icon Path to icon. 121 * @param icon Path to icon.
123 * @param label Text label. 122 * @param label Text label.
124 */ 123 */
125 void addTab( QWidget *, const QString &, const QString & ); 124 void addTab( QWidget *, const QString &, const QString & );
126 125
127/** 126/**
128 * @fn removePage( QWidget *widget ) 127 * @fn removePage( QWidget *widget )
129 * @brief Remove widget from control. Does not delete widget. 128 * @brief Remove widget from control. Does not delete widget.
130 * 129 *
131 * @param widget Widget control to be removed. 130 * @param widget Widget control to be removed.
132 */ 131 */
133 void removePage( QWidget * ); 132 void removePage( QWidget * );
134 133
135/** 134/**
136 * @fn changeTab( QWidget *widget, const QString &icon, const QString &label ) 135 * @fn changeTab( QWidget *widget, const QString &icon, const QString &label )
137 * @brief Change text and/or icon for existing tab 136 * @brief Change text and/or icon for existing tab
138 * 137 *
139 * @param child Widget control. 138 * @param child Widget control.
140 * @param icon Path to icon. 139 * @param icon Path to icon.
141 * @param label Text label. 140 * @param label Text label.
142 */ 141 */
143 void changeTab( QWidget *, const QString &, const QString & ); 142 void changeTab( QWidget *, const QString &, const QString & );
144 143
145/** 144/**
146 * @fn tabStyle()const 145 * @fn tabStyle()const
147 * @brief Returns current widget selection control style. 146 * @brief Returns current widget selection control style.
148 */ 147 */
149 TabStyle tabStyle() const; 148 TabStyle tabStyle() const;
150 149
151/** 150/**
152 * @fn setTabStyle( TabStyle s ) 151 * @fn setTabStyle( TabStyle s )
153 * @brief Set the current widget selection control style. 152 * @brief Set the current widget selection control style.
154 * 153 *
155 * @param s New style to be used. 154 * @param s New style to be used.
156 */ 155 */
157 void setTabStyle( TabStyle ); 156 void setTabStyle( TabStyle );
158 157
159/** 158/**
160 * @fn tabPosition()const 159 * @fn tabPosition()const
161 * @brief Returns current widget selection control position. 160 * @brief Returns current widget selection control position.
162 */ 161 */
163 TabPosition tabPosition() const; 162 TabPosition tabPosition() const;
164 163
165/** 164/**
166 * @fn setTabPosition( TabPosition p ) 165 * @fn setTabPosition( TabPosition p )
167 * @brief Set the current widget selection control position. 166 * @brief Set the current widget selection control position.
168 * 167 *
169 * @param p New position of widget selection control. 168 * @param p New position of widget selection control.
170 */ 169 */
171 void setTabPosition( TabPosition ); 170 void setTabPosition( TabPosition );
172 171
173/** 172/**
174 * @fn setCurrentTab( QWidget *childwidget ) 173 * @fn setCurrentTab( QWidget *childwidget )
175 * @brief Selects and brings to top the desired widget by using widget pointer. 174 * @brief Selects and brings to top the desired widget by using widget pointer.
176 * 175 *
177 * @param childwidget Widget to select. 176 * @param childwidget Widget to select.
178 */ 177 */
179 void setCurrentTab( QWidget * ); 178 void setCurrentTab( QWidget * );
180 179
181/** 180/**
182 * @fn setCurrentTab( const QString &tabname ) 181 * @fn setCurrentTab( const QString &tabname )
183 * @brief Selects and brings to top the desired widget, by using label. 182 * @brief Selects and brings to top the desired widget, by using label.
184 * 183 *
185 * @param tabname Text label for widget to select. 184 * @param tabname Text label for widget to select.
186 */ 185 */
187 void setCurrentTab( const QString & ); 186 void setCurrentTab( const QString & );
188 187
189/** 188/**
190 * @fn setCurrentTab( int ) 189 * @fn setCurrentTab( int )
191 * @brief Selects and brings to top the desired widget, by using id. 190 * @brief Selects and brings to top the desired widget, by using id.
192 * 191 *
193 * @param tab id for widget to select. 192 * @param tab id for widget to select.
194 */ 193 */
195 void setCurrentTab(int); 194 void setCurrentTab(int);
196 195
197/** 196/**
198 * @fn sizeHint()const 197 * @fn sizeHint()const
199 * @brief Reimplemented for internal purposes. 198 * @brief Reimplemented for internal purposes.
200 */ 199 */
201 QSize sizeHint() const; 200 QSize sizeHint() const;
202 201
203/** 202/**
204 * @fn currentTab( ) 203 * @fn currentTab( )
205 * @brief returns current tab id. 204 * @brief returns current tab id.
206 */ 205 */
207 // ### make const 206 // ### make const
208 int currentTab()/* const */; 207 int currentTab()/* const */;
209/** 208/**
210 * @brief returns the current page of the active tab 209 * @brief returns the current page of the active tab
211 * 210 *
212 * @since 1.2 211 * @since 1.2
213 */ 212 */
214 QWidget* currentWidget()const; 213 QWidget* currentWidget()const;
215 214
216protected: 215protected:
217 216
218/** 217/**
219 * @fn resizeEvent( QResizeEvent * ) 218 * @fn resizeEvent( QResizeEvent * )
220 * @brief Reimplemented for internal purposes. 219 * @brief Reimplemented for internal purposes.
221 */ 220 */
222 void resizeEvent( QResizeEvent * ); 221 void resizeEvent( QResizeEvent * );
223 222
224private: 223private:
225 OTabInfoList tabs; 224 OTabInfoList tabs;
226 OTabInfo *currTab; 225 OTabInfo *currTab;
227 226
228 TabStyle tabBarStyle; 227 TabStyle tabBarStyle;
229 TabPosition tabBarPosition; 228 TabPosition tabBarPosition;
230 229
231 QWidgetStack *tabBarStack; 230 QWidgetStack *tabBarStack;
232 OTabBar *tabBar; 231 OTabBar *tabBar;
233 QComboBox *tabList; 232 QComboBox *tabList;
234 233
235 QWidgetStack *widgetStack; 234 QWidgetStack *widgetStack;
236 class Private; 235 class Private;
237 Private* d; 236 Private* d;
238 237
239/** 238/**
240 * @fn loadSmooth( const QString &name ) 239 * @fn loadSmooth( const QString &name )
241 * @brief Loads icon for widget. 240 * @brief Loads icon for widget.
242 * 241 *
243 * @param name Name of icon image file. 242 * @param name Name of icon image file.
244 */ 243 */
245 QPixmap loadSmooth( const QString & ); 244 QPixmap loadSmooth( const QString & );
246 245
247/** 246/**
248 * @fn selectTab( OTabInfo *tab ) 247 * @fn selectTab( OTabInfo *tab )
249 * @brief Internal function to select desired widget. 248 * @brief Internal function to select desired widget.
250 * 249 *
251 * @param tab Pointer to data for widget. 250 * @param tab Pointer to data for widget.
252 */ 251 */
253 void selectTab( OTabInfo * ); 252 void selectTab( OTabInfo * );
254 253
255/** 254/**
256 * @fn setUpLayout() 255 * @fn setUpLayout()
257 * @brief Internal function to adjust layout. 256 * @brief Internal function to adjust layout.
258 */ 257 */
259 void setUpLayout(); 258 void setUpLayout();
260 259
261 260
262 signals: 261 signals:
263/** 262/**
264 * @fn currentChanegd( QWidget *widget ) 263 * @fn currentChanegd( QWidget *widget )
265 * @brief This signal is emitted whenever the widget has changed. 264 * @brief This signal is emitted whenever the widget has changed.
266 * 265 *
267 * @param widget Pointer to new current widget. 266 * @param widget Pointer to new current widget.
268 */ 267 */
269 void currentChanged( QWidget * ); 268 void currentChanged( QWidget * );
270 269
271 private slots: 270 private slots:
272 271
273/** 272/**
274 * @fn slotTabBarSelected( int id ) 273 * @fn slotTabBarSelected( int id )
275 * @brief Slot which is called when a tab is selected. 274 * @brief Slot which is called when a tab is selected.
276 * 275 *
277 * @param id ID of widget selected. 276 * @param id ID of widget selected.
278 */ 277 */
279 void slotTabBarSelected( int ); 278 void slotTabBarSelected( int );
280 279
281/** 280/**
282 * @fn slotTabListSelected( int index ) 281 * @fn slotTabListSelected( int index )
283 * @brief Slot which is called when a drop down selection is made. 282 * @brief Slot which is called when a drop down selection is made.
284 * 283 *
285 * @param id Index of widget selected. 284 * @param id Index of widget selected.
286 */ 285 */
287 void slotTabListSelected( int ); 286 void slotTabListSelected( int );
288}; 287};
289 288
290}; 289}
290}
291 291
292#endif 292#endif
diff --git a/libopie2/opieui/otaskbarapplet.cpp b/libopie2/opieui/otaskbarapplet.cpp
index a67356d..b5268f0 100644
--- a/libopie2/opieui/otaskbarapplet.cpp
+++ b/libopie2/opieui/otaskbarapplet.cpp
@@ -1,32 +1,82 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31#include <opie2/otaskbarapplet.h>
32
33#include <qpe/qpeapplication.h>
34#include <qframe.h>
35
36using namespace Opie::Ui;
37
38
39/**
40 * \todo no example yet!!!
41 * If you want to implement an Applet for the Opie Taskbar
42 * use this interface.
43 * The only specail thing about applets is that you need to build
44 * it as plugin/library and do EXPORT_OPIE_APPLET_v1( YourApplet )
45 * at the bottom of your application. This takes care of
46 * the activation and implementing the TaskbarAppletInterface.
47 * You also need to add a static int position() functions to your
48 * application.
49 * \code
50 * class MyApplet : public OTaskBarApplet {
51 * public:
52 * static int position() { return 3: }
53 * void doStuff() {
54 * popup( myWidget );
55 * }
56 * };
57 * EXPORT_OPIE_APPLET_v1( MyApplet )
58 * \endcode
59 *
60 * @author Michael Lauer
61 * @version 0.5
62 * @see TaskbarAppletInterface
63 */
64OTaskbarApplet::OTaskbarApplet( QWidget* parent, const char* name )
65 :QWidget( parent, name ){
66 setFixedHeight( 18 );
67 setFixedWidth( 14 );
68}
69
70OTaskbarApplet::~OTaskbarApplet(){
71}
72
73void OTaskbarApplet::popup( QWidget* widget ){
74 QPoint curPos = mapToGlobal( QPoint( 0, 0 ) );
75 int w = widget->sizeHint().width();
76 int x = curPos.x() - (w/2 );
77 if ( (x+w) > QPEApplication::desktop()->width() )
78 x = QPEApplication::desktop()->width()-w;
79 widget->move( x, curPos.y()-widget->sizeHint().height() );
80 widget->show();
81}
31 82
32// Empty on purpose until we shipped Opie 1.0 (see otaskbarapplet.h for explanation)
diff --git a/libopie2/opieui/otaskbarapplet.h b/libopie2/opieui/otaskbarapplet.h
index 074367f..0c85ee7 100644
--- a/libopie2/opieui/otaskbarapplet.h
+++ b/libopie2/opieui/otaskbarapplet.h
@@ -1,130 +1,129 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#ifndef OTASKBARAPPLET_H 32#ifndef OTASKBARAPPLET_H
33#define OTASKBARAPPLET_H 33#define OTASKBARAPPLET_H
34 34
35#include <qpe/taskbarappletinterface.h> 35#include <qpe/taskbarappletinterface.h>
36#include <qpe/qcom.h>
36 37
38#include <qwidget.h>
39
40class QMouseEvent;
41
42namespace Opie {
43namespace Ui {
44namespace Private {
37/*====================================================================================== 45/*======================================================================================
38 * OTaskbarAppletWrapper 46 * OTaskbarAppletWrapper
39 *======================================================================================*/ 47 *======================================================================================*/
40 48
49class OTaskbarAppletWrapperPrivate;
41template<class T> class OTaskbarAppletWrapper : public TaskbarAppletInterface 50template<class T> class OTaskbarAppletWrapper : public TaskbarAppletInterface
42{ 51{
43 public: 52 public:
44 OTaskbarAppletWrapper():_applet( 0 ) 53 OTaskbarAppletWrapper():_applet( 0 )
45 { 54 {
46 } 55 }
47 56
48 virtual ~OTaskbarAppletWrapper() 57 virtual ~OTaskbarAppletWrapper()
49 { 58 {
50 delete _applet; 59 delete _applet;
51 } 60 }
52 61
53 QRESULT queryInterface( const QUuid& uuid, QUnknownInterface** iface ) 62 QRESULT queryInterface( const QUuid& uuid, QUnknownInterface** iface )
54 { 63 {
55 qDebug( "OTaskbarAppletWrapper::queryInterface()" ); 64 qDebug( "OTaskbarAppletWrapper::queryInterface()" );
56 *iface = 0; 65 *iface = 0;
57 if ( uuid == IID_QUnknown ) 66 if ( uuid == IID_QUnknown )
58 *iface = this; 67 *iface = this;
59 else if ( uuid == IID_TaskbarApplet ) 68 else if ( uuid == IID_TaskbarApplet )
60 *iface = this; 69 *iface = this;
61 else 70 else
62 return QS_FALSE; 71 return QS_FALSE;
63 72
64 if ( *iface ) (*iface)->addRef(); 73 if ( *iface ) (*iface)->addRef();
65 return QS_OK; 74 return QS_OK;
66 } 75 }
67 76
68 Q_REFCOUNT 77 Q_REFCOUNT
69 78
70 virtual T* applet( QWidget* parent ) 79 virtual T* applet( QWidget* parent )
71 { 80 {
72 if ( !_applet ) _applet = new T( parent ); 81 if ( !_applet ) _applet = new T( parent );
73 return _applet; 82 return _applet;
74 } 83 }
75 84
76 virtual int position() const 85 virtual int position() const
77 { 86 {
78 return T::position(); 87 return T::position();
79 } 88 }
80 89
81 private: 90 private:
82 T* _applet; 91 T* _applet;
92 OTaskbarAppletWrapperPrivate *d;
83}; 93};
84 94
85#include <qframe.h> 95}
86#include <qwidget.h>
87#include <qpe/qpeapplication.h>
88
89class QMouseEvent;
90
91/*====================================================================================== 96/*======================================================================================
92 * OTaskbarApplet 97 * OTaskbarApplet
93 *======================================================================================*/ 98 *======================================================================================*/
94 99
95// Must be inline until after we shipped Opie 1.0 100// Must be inline until after we shipped Opie 1.0
96 101
97// Having OTaskBarApplet reside in libopieui2 is not possible 102// Having OTaskBarApplet reside in libopieui2 is not possible
98// until we link the launcher binary against libopieui2 - 103// until we link the launcher binary against libopieui2 -
99// otherwise the necessary symbols are not present, when 104// otherwise the necessary symbols are not present, when
100// the dynamic loader [dlopen] tries to resolve an applet which 105// the dynamic loader [dlopen] tries to resolve an applet which
101// inherits OTaskbarApplet 106// inherits OTaskbarApplet
102 107
103class OTaskbarApplet : public QWidget 108class OTaskbarApplet : public QWidget
104{ 109{
105 public: 110 public:
106 OTaskbarApplet( QWidget* parent, const char* name = 0 ):QWidget( parent, name ) 111 OTaskbarApplet( QWidget* parent, const char* name = 0 );
107 { 112 virtual ~OTaskbarApplet();
108 setFixedHeight( 18 );
109 setFixedWidth( 14 );
110 }
111
112 virtual ~OTaskbarApplet()
113 {
114 }
115 113
116 protected: 114 protected:
117 virtual void popup( QWidget* widget ) 115 virtual void popup( QWidget* widget );
118 { 116private:
119 QPoint curPos = mapToGlobal( QPoint( 0, 0 ) ); 117 class Private;
120 int w = widget->sizeHint().width(); 118 Private *d;
121 int x = curPos.x() - (w/2 );
122 if ( (x+w) > QPEApplication::desktop()->width() )
123 x = QPEApplication::desktop()->width()-w;
124 widget->move( x, curPos.y()-widget->sizeHint().height() );
125 widget->show();
126 }
127}; 119};
120}
121}
122
123#define EXPORT_OPIE_APPLET_v1( AppLet ) \
124 Q_EXPORT_INTERFACE() { \
125 Q_CREATE_INSTANCE( Opie::Ui::Private::OTaskbarAppletWrapper<AppLet> ) \
126 }
128 127
129#endif 128#endif
130 129
diff --git a/libopie2/opieui/otimepicker.cpp b/libopie2/opieui/otimepicker.cpp
index 66f9ce0..7de0fd3 100644
--- a/libopie2/opieui/otimepicker.cpp
+++ b/libopie2/opieui/otimepicker.cpp
@@ -1,292 +1,301 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30/* OPIE */
31#include <opie2/otimepicker.h>
32
30/* QT */ 33/* QT */
34#include <qgroupbox.h>
31#include <qlayout.h> 35#include <qlayout.h>
32#include <qlineedit.h> 36#include <qlineedit.h>
33 37
34/* OPIE */
35#include <opie2/otimepicker.h>
36 38
37using namespace Opie; 39
40namespace Opie {
41namespace Ui {
38 42
39/** 43/**
40 * Constructs the widget 44 * Constructs the widget
41 * @param parent The parent of the OTimePicker 45 * @param parent The parent of the OTimePicker
42 * @param name The name of the object 46 * @param name The name of the object
43 * @param fl Window Flags 47 * @param fl Window Flags
44 */ 48 */
45OTimePicker::OTimePicker(QWidget* parent, const char* name, Qt::WFlags fl) 49OTimePicker::OTimePicker(QWidget* parent, const char* name, Qt::WFlags fl)
46 :QWidget(parent,name,fl) 50 :QWidget(parent,name,fl)
47{ 51{
48 QVBoxLayout *vbox=new QVBoxLayout(this); 52 QVBoxLayout *vbox=new QVBoxLayout(this);
49 53
50 OClickableLabel *r; 54 OClickableLabel *r;
51 QString s; 55 QString s;
52 56
53 // Hour Row 57 // Hour Row
54 QWidget *row=new QWidget(this); 58 QWidget *row=new QWidget(this);
55 QHBoxLayout *l=new QHBoxLayout(row); 59 QHBoxLayout *l=new QHBoxLayout(row);
56 vbox->addWidget(row); 60 vbox->addWidget(row);
57 61
58 for (int i=0; i<24; i++) 62 for (int i=0; i<24; i++)
59 { 63 {
60 r=new OClickableLabel(row); 64 r=new OClickableLabel(row);
61 hourLst.append(r); 65 hourLst.append(r);
62 s.sprintf("%.2d",i); 66 s.sprintf("%.2d",i);
63 r->setText(s); 67 r->setText(s);
64 r->setToggleButton(true); 68 r->setToggleButton(true);
65 r->setAlignment(AlignHCenter | AlignVCenter); 69 r->setAlignment(AlignHCenter | AlignVCenter);
66 l->addWidget(r); 70 l->addWidget(r);
67 connect(r, SIGNAL(toggled(bool)), 71 connect(r, SIGNAL(toggled(bool)),
68 this, SLOT(slotHour(bool))); 72 this, SLOT(slotHour(bool)));
69 73
70 if (i==11) 74 if (i==11)
71 { // Second row 75 { // Second row
72 row=new QWidget(this); 76 row=new QWidget(this);
73 l=new QHBoxLayout(row); 77 l=new QHBoxLayout(row);
74 vbox->addWidget(row); 78 vbox->addWidget(row);
75 } 79 }
76 } 80 }
77 81
78 // Minute Row 82 // Minute Row
79 row=new QWidget(this); 83 row=new QWidget(this);
80 l=new QHBoxLayout(row); 84 l=new QHBoxLayout(row);
81 vbox->addWidget(row); 85 vbox->addWidget(row);
82 86
83 for (int i=0; i<60; i+=5) 87 for (int i=0; i<60; i+=5)
84 { 88 {
85 r=new OClickableLabel(row); 89 r=new OClickableLabel(row);
86 minuteLst.append(r); 90 minuteLst.append(r);
87 s.sprintf("%.2d",i); 91 s.sprintf("%.2d",i);
88 r->setText(s); 92 r->setText(s);
89 r->setToggleButton(true); 93 r->setToggleButton(true);
90 r->setAlignment(AlignHCenter | AlignVCenter); 94 r->setAlignment(AlignHCenter | AlignVCenter);
91 l->addWidget(r); 95 l->addWidget(r);
92 connect(r, SIGNAL(toggled(bool)), 96 connect(r, SIGNAL(toggled(bool)),
93 this, SLOT(slotMinute(bool))); 97 this, SLOT(slotMinute(bool)));
94 } 98 }
95} 99}
96 100
97/** 101/**
98 * This method return the current time 102 * This method return the current time
99 * @return the time 103 * @return the time
100 */ 104 */
101QTime OTimePicker::time()const 105QTime OTimePicker::time()const
102{ 106{
103 return tm; 107 return tm;
104} 108}
105 109
106void OTimePicker::slotHour(bool b) 110void OTimePicker::slotHour(bool b)
107{ 111{
108 112
109 OClickableLabel *r = (OClickableLabel *) sender(); 113 OClickableLabel *r = (OClickableLabel *) sender();
110 114
111 if (b) 115 if (b)
112 { 116 {
113 QValueListIterator<OClickableLabel *> it; 117 QValueListIterator<OClickableLabel *> it;
114 for (it=hourLst.begin(); it!=hourLst.end(); it++) 118 for (it=hourLst.begin(); it!=hourLst.end(); it++)
115 { 119 {
116 if (*it != r) (*it)->setOn(false); 120 if (*it != r) (*it)->setOn(false);
117 else tm.setHMS((*it)->text().toInt(), tm.minute(), 0); 121 else tm.setHMS((*it)->text().toInt(), tm.minute(), 0);
118 } 122 }
119 emit timeChanged(tm); 123 emit timeChanged(tm);
120 } 124 }
121 else 125 else
122 { 126 {
123 r->setOn(true); 127 r->setOn(true);
124 } 128 }
125 129
126} 130}
127 131
128void OTimePicker::slotMinute(bool b) 132void OTimePicker::slotMinute(bool b)
129{ 133{
130 134
131 OClickableLabel *r = (OClickableLabel *) sender(); 135 OClickableLabel *r = (OClickableLabel *) sender();
132 136
133 if (b) 137 if (b)
134 { 138 {
135 QValueListIterator<OClickableLabel *> it; 139 QValueListIterator<OClickableLabel *> it;
136 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) 140 for (it=minuteLst.begin(); it!=minuteLst.end(); it++)
137 { 141 {
138 if (*it != r) (*it)->setOn(false); 142 if (*it != r) (*it)->setOn(false);
139 else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0); 143 else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0);
140 } 144 }
141 emit timeChanged(tm); 145 emit timeChanged(tm);
142 } 146 }
143 else 147 else
144 { 148 {
145 r->setOn(true); 149 r->setOn(true);
146 } 150 }
147 151
148} 152}
149 153
150/** 154/**
151 * Method to set the time. No signal gets emitted during this method call 155 * Method to set the time. No signal gets emitted during this method call
152 * Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... ) 156 * Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... )
153 * @param t The time to be set 157 * @param t The time to be set
154 */ 158 */
155void OTimePicker::setTime( const QTime& t) 159void OTimePicker::setTime( const QTime& t)
156{ 160{
157 setTime( t.hour(), t.minute() ); 161 setTime( t.hour(), t.minute() );
158} 162}
159 163
160/** 164/**
161 * Method to set the time. No signal gets emitted during this method call 165 * Method to set the time. No signal gets emitted during this method call
162 * @param h The hour 166 * @param h The hour
163 * @param m The minute. Minutes need to set by 5 minute steps 167 * @param m The minute. Minutes need to set by 5 minute steps
164 */ 168 */
165void OTimePicker::setTime( int h, int m ) 169void OTimePicker::setTime( int h, int m )
166{ 170{
167 setHour(h); 171 setHour(h);
168 setMinute(m); 172 setMinute(m);
169} 173}
170 174
171/* 175/*
172 * FIXME round minutes to the 5 minute arrangement -zecke 176 * FIXME round minutes to the 5 minute arrangement -zecke
173 */ 177 */
174/** 178/**
175 * Method to set the minutes 179 * Method to set the minutes
176 * @param m minutes 180 * @param m minutes
177 */ 181 */
178void OTimePicker::setMinute(int m) 182void OTimePicker::setMinute(int m)
179{ 183{
180 184
181 QString minute; 185 QString minute;
182 minute.sprintf("%.2d",m); 186 minute.sprintf("%.2d",m);
183 187
184 QValueListIterator<OClickableLabel *> it; 188 QValueListIterator<OClickableLabel *> it;
185 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) 189 for (it=minuteLst.begin(); it!=minuteLst.end(); it++)
186 { 190 {
187 if ((*it)->text() == minute) (*it)->setOn(true); 191 if ((*it)->text() == minute) (*it)->setOn(true);
188 else (*it)->setOn(false); 192 else (*it)->setOn(false);
189 } 193 }
190 194
191 tm.setHMS(tm.hour(),m,0); 195 tm.setHMS(tm.hour(),m,0);
192} 196}
193 197
194/** 198/**
195 * Method to set the hour 199 * Method to set the hour
196 */ 200 */
197void OTimePicker::setHour(int h) 201void OTimePicker::setHour(int h)
198{ 202{
199 203
200 QString hour; 204 QString hour;
201 hour.sprintf("%.2d",h); 205 hour.sprintf("%.2d",h);
202 206
203 QValueListIterator<OClickableLabel *> it; 207 QValueListIterator<OClickableLabel *> it;
204 for (it=hourLst.begin(); it!=hourLst.end(); it++) 208 for (it=hourLst.begin(); it!=hourLst.end(); it++)
205 { 209 {
206 if ((*it)->text() == hour) (*it)->setOn(true); 210 if ((*it)->text() == hour) (*it)->setOn(true);
207 else (*it)->setOn(false); 211 else (*it)->setOn(false);
208 } 212 }
209 tm.setHMS(h,tm.minute(),0); 213 tm.setHMS(h,tm.minute(),0);
210} 214}
211 215
212 216
213/** 217/**
214 * This is a modal Dialog. 218 * This is a modal Dialog.
215 * 219 *
216 * @param parent The parent widget 220 * @param parent The parent widget
217 * @param name The name of the object 221 * @param name The name of the object
218 * @param fl Possible window flags 222 * @param fl Possible window flags
219 */ 223 */
220OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl ) 224OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl )
221 : OTimePickerDialogBase (parent , name, true , fl) 225 : OTimePickerDialogBase (parent , name, true , fl)
222{ 226{
227 m_timePicker = new OTimePicker( GroupBox1, "m_timePicker" );
228 GroupBox1Layout->addWidget( m_timePicker, 0, 0 );
223 229
224 connect ( m_timePicker, SIGNAL( timeChanged(const QTime&) ), 230 connect ( m_timePicker, SIGNAL( timeChanged(const QTime&) ),
225 this, SLOT( setTime(const QTime&) ) ); 231 this, SLOT( setTime(const QTime&) ) );
226 connect ( minuteField, SIGNAL( textChanged(const QString&) ), 232 connect ( minuteField, SIGNAL( textChanged(const QString&) ),
227 this, SLOT ( setMinute(const QString&) ) ); 233 this, SLOT ( setMinute(const QString&) ) );
228 connect ( hourField, SIGNAL( textChanged(const QString&) ), 234 connect ( hourField, SIGNAL( textChanged(const QString&) ),
229 this, SLOT ( setHour(const QString&) ) ); 235 this, SLOT ( setHour(const QString&) ) );
230 236
231} 237}
232 238
233/** 239/**
234 * @return the time 240 * @return the time
235 */ 241 */
236QTime OTimePickerDialog::time()const 242QTime OTimePickerDialog::time()const
237{ 243{
238 return m_time; 244 return m_time;
239} 245}
240 246
241/** 247/**
242 * Set the time to time 248 * Set the time to time
243 * @param time The time to be set 249 * @param time The time to be set
244 */ 250 */
245void OTimePickerDialog::setTime( const QTime& time ) 251void OTimePickerDialog::setTime( const QTime& time )
246{ 252{
247 m_time = time; 253 m_time = time;
248 254
249 m_timePicker->setHour ( time.hour() ); 255 m_timePicker->setHour ( time.hour() );
250 m_timePicker->setMinute( time.minute() ); 256 m_timePicker->setMinute( time.minute() );
251 257
252 // Set Textfields 258 // Set Textfields
253 if ( time.hour() < 10 ) 259 if ( time.hour() < 10 )
254 hourField->setText( "0" + QString::number( time.hour() ) ); 260 hourField->setText( "0" + QString::number( time.hour() ) );
255 else 261 else
256 hourField->setText( QString::number( time.hour() ) ); 262 hourField->setText( QString::number( time.hour() ) );
257 263
258 if ( time.minute() < 10 ) 264 if ( time.minute() < 10 )
259 minuteField->setText( "0" + QString::number( time.minute() ) ); 265 minuteField->setText( "0" + QString::number( time.minute() ) );
260 else 266 else
261 minuteField->setText( QString::number( time.minute() ) ); 267 minuteField->setText( QString::number( time.minute() ) );
262 268
263} 269}
264 270
265/** 271/**
266 * This method takes the current minute and tries to set hour 272 * This method takes the current minute and tries to set hour
267 * to hour. This succeeds if the resulting date is valid 273 * to hour. This succeeds if the resulting date is valid
268 * @param hour The hour as a string 274 * @param hour The hour as a string
269 */ 275 */
270void OTimePickerDialog::setHour ( const QString& hour ) 276void OTimePickerDialog::setHour ( const QString& hour )
271{ 277{
272 if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) ) 278 if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) )
273 { 279 {
274 m_time.setHMS ( hour.toInt(), m_time.minute() , 00 ); 280 m_time.setHMS ( hour.toInt(), m_time.minute() , 00 );
275 setTime ( m_time ); 281 setTime ( m_time );
276 } 282 }
277 283
278} 284}
279 285
280/** 286/**
281 * Method to set a new minute. It tries to convert the string to int and 287 * Method to set a new minute. It tries to convert the string to int and
282 * if the resulting date is valid a new date is set. 288 * if the resulting date is valid a new date is set.
283 * @see setHour 289 * @see setHour
284 */ 290 */
285void OTimePickerDialog::setMinute ( const QString& minute ) 291void OTimePickerDialog::setMinute ( const QString& minute )
286{ 292{
287 if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ) 293 if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) )
288 { 294 {
289 m_time.setHMS ( m_time.hour(), minute.toInt(), 00 ); 295 m_time.setHMS ( m_time.hour(), minute.toInt(), 00 );
290 setTime ( m_time ); 296 setTime ( m_time );
291 } 297 }
292} 298}
299
300}
301}
diff --git a/libopie2/opieui/otimepicker.h b/libopie2/opieui/otimepicker.h
index 2da7773..01bb557 100644
--- a/libopie2/opieui/otimepicker.h
+++ b/libopie2/opieui/otimepicker.h
@@ -1,125 +1,132 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#ifndef OTIMEPICKER_H 30#ifndef OTIMEPICKER_H
31#define OTIMEPICKER_H 31#define OTIMEPICKER_H
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/oclickablelabel.h> 34#include <opie2/oclickablelabel.h>
35#include "otimepickerbase.h" 35#include <opie2/otimepickerbase.h>
36 36
37/* QT */ 37/* QT */
38#include <qwidget.h> 38#include <qwidget.h>
39#include <qvaluelist.h> 39#include <qvaluelist.h>
40#include <qdatetime.h> 40#include <qdatetime.h>
41#include <qdialog.h> 41#include <qdialog.h>
42 42
43using namespace Opie;
44 43
45// namespace Opie 44namespace Opie {
46// { 45namespace Ui {
47 46
48/** 47/**
49 * A class to pick time. It uses clickable labels 48 * A class to pick time. It uses clickable labels
50 * internally to allow a quick selection of a time. 49 * internally to allow a quick selection of a time.
51 * A time can be selected by two clicks of a user 50 * A time can be selected by two clicks of a user
52 * 51 *
53 * @short A widget to quickly pick a QTime 52 * @short A widget to quickly pick a QTime
54 * @version 1.0 53 * @version 1.0
55 * @see QWidget 54 * @see QWidget
56 * @see QTime 55 * @see QTime
57 * @author Hakan Ardo, Stefan Eilers 56 * @author Hakan Ardo, Stefan Eilers
58 */ 57 */
59class OTimePicker: public QWidget 58class OTimePicker : public QWidget
60{ 59{
61 Q_OBJECT 60 Q_OBJECT
62 61
63public: 62public:
64 OTimePicker(QWidget* parent = 0, const char* name = 0, WFlags fl = 0); 63 OTimePicker(QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
65 64
66public slots: 65public slots:
67 void setHour(int h); 66 void setHour(int h);
68 void setMinute(int m); 67 void setMinute(int m);
69 void setTime( const QTime& ); 68 void setTime( const QTime& );
70 void setTime( int h, int m ); 69 void setTime( int h, int m );
71 70
72public: 71public:
73 QTime time()const; 72 QTime time()const;
74 73
75private: 74private:
76 QValueList<OClickableLabel *> hourLst; 75 QValueList<OClickableLabel *> hourLst;
77 QValueList<OClickableLabel *> minuteLst; 76 QValueList<OClickableLabel *> minuteLst;
78 QTime tm; 77 QTime tm;
79 struct Private; 78 struct Private;
80 Private *d; 79 Private *d;
81 80
82private slots: 81private slots:
83 void slotHour(bool b); 82 void slotHour(bool b);
84 void slotMinute(bool b); 83 void slotMinute(bool b);
85 84
86signals: 85signals:
87 /** 86 /**
88 * gets emitted when the time got changed by the user 87 * gets emitted when the time got changed by the user
89 */ 88 */
90 void timeChanged(const QTime &); 89 void timeChanged(const QTime &);
91}; 90};
92 91
93/** 92/**
94 * 93 *
95 * @short A small dialog to pick a time 94 * @short A small dialog to pick a time
96 * @version 1.0 95 * @version 1.0
97 * @author Stefan Eilers 96 * @author Stefan Eilers
98 * 97 *
99 **/ 98 **/
100 99
101class OTimePickerDialog: public OTimePickerDialogBase 100class OTimePickerDialog: public OTimePickerDialogBase
102{ 101{
103 Q_OBJECT 102 Q_OBJECT
104 103
105public: 104public:
106 OTimePickerDialog ( QWidget* parent = 0, const char* name = NULL, WFlags fl = 0 ); 105 OTimePickerDialog ( QWidget* parent = 0, const char* name = NULL, WFlags fl = 0 );
107 ~OTimePickerDialog() { }; 106 ~OTimePickerDialog() { };
108 107
109 QTime time()const; 108 QTime time()const;
110 109
111public slots: 110public slots:
112 void setTime( const QTime& time ); 111 void setTime( const QTime& time );
113 void setHour( const QString& hour ); 112 void setHour( const QString& hour );
114 void setMinute( const QString& minute ); 113 void setMinute( const QString& minute );
115 114
116private: 115private:
116 OTimePicker *m_timePicker;
117 QTime m_time; 117 QTime m_time;
118 class Private; 118 class Private;
119 Private* d; 119 Private* d;
120}; 120};
121 121
122// }; 122}
123}
123 124
125/* for Qt2 */
126#if ( QT_VERSION-0 >= 0x030000 )
127#error "Fix the UI File to use namespaces"
128#else
129typedef Opie::Ui::OTimePicker OUIOTimePicker;
130#endif
124#endif 131#endif
125 132
diff --git a/libopie2/opieui/otimepickerbase.ui b/libopie2/opieui/otimepickerbase.ui
index 3e7f2fb..c2eb7c5 100644
--- a/libopie2/opieui/otimepickerbase.ui
+++ b/libopie2/opieui/otimepickerbase.ui
@@ -1,292 +1,256 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>OTimePickerDialogBase</class> 2<class>OTimePickerDialogBase</class>
3<widget> 3<widget>
4 <class>QDialog</class> 4 <class>QDialog</class>
5 <property stdset="1"> 5 <property stdset="1">
6 <name>name</name> 6 <name>name</name>
7 <cstring>OTimePickerDialogBase</cstring> 7 <cstring>OTimePickerDialogBase</cstring>
8 </property> 8 </property>
9 <property stdset="1"> 9 <property stdset="1">
10 <name>geometry</name> 10 <name>geometry</name>
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>210</width> 14 <width>182</width>
15 <height>137</height> 15 <height>137</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>sizePolicy</name> 19 <name>sizePolicy</name>
20 <sizepolicy> 20 <sizepolicy>
21 <hsizetype>3</hsizetype> 21 <hsizetype>3</hsizetype>
22 <vsizetype>1</vsizetype> 22 <vsizetype>1</vsizetype>
23 </sizepolicy> 23 </sizepolicy>
24 </property> 24 </property>
25 <property stdset="1"> 25 <property stdset="1">
26 <name>caption</name> 26 <name>caption</name>
27 <string>OTimePickerDialogBase</string> 27 <string>OTimePickerDialogBase</string>
28 </property> 28 </property>
29 <property> 29 <property>
30 <name>layoutMargin</name> 30 <name>layoutMargin</name>
31 </property> 31 </property>
32 <property> 32 <property>
33 <name>layoutSpacing</name> 33 <name>layoutSpacing</name>
34 </property> 34 </property>
35 <vbox> 35 <vbox>
36 <property stdset="1"> 36 <property stdset="1">
37 <name>margin</name> 37 <name>margin</name>
38 <number>5</number> 38 <number>5</number>
39 </property> 39 </property>
40 <property stdset="1"> 40 <property stdset="1">
41 <name>spacing</name> 41 <name>spacing</name>
42 <number>4</number> 42 <number>4</number>
43 </property> 43 </property>
44 <widget> 44 <widget>
45 <class>QFrame</class> 45 <class>QFrame</class>
46 <property stdset="1"> 46 <property stdset="1">
47 <name>name</name> 47 <name>name</name>
48 <cstring>Frame10</cstring> 48 <cstring>Frame10</cstring>
49 </property> 49 </property>
50 <property stdset="1"> 50 <property stdset="1">
51 <name>sizePolicy</name> 51 <name>sizePolicy</name>
52 <sizepolicy> 52 <sizepolicy>
53 <hsizetype>1</hsizetype> 53 <hsizetype>1</hsizetype>
54 <vsizetype>7</vsizetype> 54 <vsizetype>7</vsizetype>
55 </sizepolicy> 55 </sizepolicy>
56 </property> 56 </property>
57 <property stdset="1"> 57 <property stdset="1">
58 <name>frameShape</name> 58 <name>frameShape</name>
59 <enum>NoFrame</enum> 59 <enum>NoFrame</enum>
60 </property> 60 </property>
61 <property stdset="1"> 61 <property stdset="1">
62 <name>frameShadow</name> 62 <name>frameShadow</name>
63 <enum>Raised</enum> 63 <enum>Raised</enum>
64 </property> 64 </property>
65 <property> 65 <property>
66 <name>layoutMargin</name> 66 <name>layoutMargin</name>
67 </property> 67 </property>
68 <hbox> 68 <hbox>
69 <property stdset="1"> 69 <property stdset="1">
70 <name>margin</name> 70 <name>margin</name>
71 <number>2</number> 71 <number>2</number>
72 </property> 72 </property>
73 <property stdset="1"> 73 <property stdset="1">
74 <name>spacing</name> 74 <name>spacing</name>
75 <number>6</number> 75 <number>6</number>
76 </property> 76 </property>
77 <spacer> 77 <spacer>
78 <property> 78 <property>
79 <name>name</name> 79 <name>name</name>
80 <cstring>Spacer4</cstring> 80 <cstring>Spacer4</cstring>
81 </property> 81 </property>
82 <property stdset="1"> 82 <property stdset="1">
83 <name>orientation</name> 83 <name>orientation</name>
84 <enum>Horizontal</enum> 84 <enum>Horizontal</enum>
85 </property> 85 </property>
86 <property stdset="1"> 86 <property stdset="1">
87 <name>sizeType</name> 87 <name>sizeType</name>
88 <enum>MinimumExpanding</enum> 88 <enum>MinimumExpanding</enum>
89 </property> 89 </property>
90 <property> 90 <property>
91 <name>sizeHint</name> 91 <name>sizeHint</name>
92 <size> 92 <size>
93 <width>20</width> 93 <width>20</width>
94 <height>20</height> 94 <height>20</height>
95 </size> 95 </size>
96 </property> 96 </property>
97 </spacer> 97 </spacer>
98 <widget> 98 <widget>
99 <class>QFrame</class> 99 <class>QFrame</class>
100 <property stdset="1"> 100 <property stdset="1">
101 <name>name</name> 101 <name>name</name>
102 <cstring>Frame4</cstring> 102 <cstring>Frame4</cstring>
103 </property> 103 </property>
104 <property stdset="1"> 104 <property stdset="1">
105 <name>sizePolicy</name> 105 <name>sizePolicy</name>
106 <sizepolicy> 106 <sizepolicy>
107 <hsizetype>4</hsizetype> 107 <hsizetype>4</hsizetype>
108 <vsizetype>4</vsizetype> 108 <vsizetype>4</vsizetype>
109 </sizepolicy> 109 </sizepolicy>
110 </property> 110 </property>
111 <property stdset="1"> 111 <property stdset="1">
112 <name>frameShape</name> 112 <name>frameShape</name>
113 <enum>Box</enum> 113 <enum>Box</enum>
114 </property> 114 </property>
115 <property stdset="1"> 115 <property stdset="1">
116 <name>frameShadow</name> 116 <name>frameShadow</name>
117 <enum>Sunken</enum> 117 <enum>Sunken</enum>
118 </property> 118 </property>
119 <property> 119 <property>
120 <name>layoutMargin</name> 120 <name>layoutMargin</name>
121 </property> 121 </property>
122 <property> 122 <property>
123 <name>layoutSpacing</name> 123 <name>layoutSpacing</name>
124 </property> 124 </property>
125 <hbox> 125 <hbox>
126 <property stdset="1"> 126 <property stdset="1">
127 <name>margin</name> 127 <name>margin</name>
128 <number>4</number> 128 <number>4</number>
129 </property> 129 </property>
130 <property stdset="1"> 130 <property stdset="1">
131 <name>spacing</name> 131 <name>spacing</name>
132 <number>6</number> 132 <number>6</number>
133 </property> 133 </property>
134 <widget> 134 <widget>
135 <class>QLabel</class> 135 <class>QLabel</class>
136 <property stdset="1"> 136 <property stdset="1">
137 <name>name</name> 137 <name>name</name>
138 <cstring>TextLabel1</cstring> 138 <cstring>TextLabel1</cstring>
139 </property> 139 </property>
140 <property stdset="1"> 140 <property stdset="1">
141 <name>text</name> 141 <name>text</name>
142 <string>Time:</string> 142 <string>Time:</string>
143 </property> 143 </property>
144 </widget> 144 </widget>
145 <widget> 145 <widget>
146 <class>QLineEdit</class> 146 <class>QLineEdit</class>
147 <property stdset="1"> 147 <property stdset="1">
148 <name>name</name> 148 <name>name</name>
149 <cstring>hourField</cstring> 149 <cstring>hourField</cstring>
150 </property> 150 </property>
151 <property stdset="1"> 151 <property stdset="1">
152 <name>sizePolicy</name> 152 <name>sizePolicy</name>
153 <sizepolicy> 153 <sizepolicy>
154 <hsizetype>4</hsizetype> 154 <hsizetype>4</hsizetype>
155 <vsizetype>0</vsizetype> 155 <vsizetype>0</vsizetype>
156 </sizepolicy> 156 </sizepolicy>
157 </property> 157 </property>
158 <property stdset="1"> 158 <property stdset="1">
159 <name>alignment</name> 159 <name>alignment</name>
160 <set>AlignHCenter</set> 160 <set>AlignHCenter</set>
161 </property> 161 </property>
162 <property> 162 <property>
163 <name>hAlign</name> 163 <name>hAlign</name>
164 </property> 164 </property>
165 </widget> 165 </widget>
166 <widget> 166 <widget>
167 <class>QLabel</class> 167 <class>QLabel</class>
168 <property stdset="1"> 168 <property stdset="1">
169 <name>name</name> 169 <name>name</name>
170 <cstring>TextLabel1_2</cstring> 170 <cstring>TextLabel1_2</cstring>
171 </property> 171 </property>
172 <property stdset="1"> 172 <property stdset="1">
173 <name>font</name> 173 <name>font</name>
174 <font> 174 <font>
175 <bold>1</bold> 175 <bold>1</bold>
176 </font> 176 </font>
177 </property> 177 </property>
178 <property stdset="1"> 178 <property stdset="1">
179 <name>text</name> 179 <name>text</name>
180 <string>:</string> 180 <string>:</string>
181 </property> 181 </property>
182 </widget> 182 </widget>
183 <widget> 183 <widget>
184 <class>QLineEdit</class> 184 <class>QLineEdit</class>
185 <property stdset="1"> 185 <property stdset="1">
186 <name>name</name> 186 <name>name</name>
187 <cstring>minuteField</cstring> 187 <cstring>minuteField</cstring>
188 </property> 188 </property>
189 <property stdset="1"> 189 <property stdset="1">
190 <name>alignment</name> 190 <name>alignment</name>
191 <set>AlignHCenter</set> 191 <set>AlignHCenter</set>
192 </property> 192 </property>
193 <property> 193 <property>
194 <name>hAlign</name> 194 <name>hAlign</name>
195 </property> 195 </property>
196 </widget> 196 </widget>
197 </hbox> 197 </hbox>
198 </widget> 198 </widget>
199 <spacer> 199 <spacer>
200 <property> 200 <property>
201 <name>name</name> 201 <name>name</name>
202 <cstring>Spacer5</cstring> 202 <cstring>Spacer5</cstring>
203 </property> 203 </property>
204 <property stdset="1"> 204 <property stdset="1">
205 <name>orientation</name> 205 <name>orientation</name>
206 <enum>Horizontal</enum> 206 <enum>Horizontal</enum>
207 </property> 207 </property>
208 <property stdset="1"> 208 <property stdset="1">
209 <name>sizeType</name> 209 <name>sizeType</name>
210 <enum>MinimumExpanding</enum> 210 <enum>MinimumExpanding</enum>
211 </property> 211 </property>
212 <property> 212 <property>
213 <name>sizeHint</name> 213 <name>sizeHint</name>
214 <size> 214 <size>
215 <width>20</width> 215 <width>20</width>
216 <height>20</height> 216 <height>20</height>
217 </size> 217 </size>
218 </property> 218 </property>
219 </spacer> 219 </spacer>
220 </hbox> 220 </hbox>
221 </widget> 221 </widget>
222 <widget> 222 <widget>
223 <class>QGroupBox</class> 223 <class>QGroupBox</class>
224 <property stdset="1"> 224 <property stdset="1">
225 <name>name</name> 225 <name>name</name>
226 <cstring>GroupBox1</cstring> 226 <cstring>GroupBox1</cstring>
227 </property> 227 </property>
228 <property stdset="1"> 228 <property stdset="1">
229 <name>sizePolicy</name> 229 <name>sizePolicy</name>
230 <sizepolicy> 230 <sizepolicy>
231 <hsizetype>3</hsizetype> 231 <hsizetype>3</hsizetype>
232 <vsizetype>3</vsizetype> 232 <vsizetype>3</vsizetype>
233 </sizepolicy> 233 </sizepolicy>
234 </property> 234 </property>
235 <property stdset="1"> 235 <property stdset="1">
236 <name>margin</name> 236 <name>margin</name>
237 <number>0</number> 237 <number>0</number>
238 </property> 238 </property>
239 <property stdset="1"> 239 <property stdset="1">
240 <name>title</name> 240 <name>title</name>
241 <string>Pick Time:</string> 241 <string>Pick Time:</string>
242 </property> 242 </property>
243 <grid> 243 <grid>
244 <property stdset="1"> 244 <property stdset="1">
245 <name>margin</name> 245 <name>margin</name>
246 <number>11</number> 246 <number>11</number>
247 </property> 247 </property>
248 <property stdset="1"> 248 <property stdset="1">
249 <name>spacing</name> 249 <name>spacing</name>
250 <number>6</number> 250 <number>6</number>
251 </property> 251 </property>
252 <widget row="0" column="0" >
253 <class>OTimePicker</class>
254 <property stdset="1">
255 <name>name</name>
256 <cstring>m_timePicker</cstring>
257 </property>
258 <property stdset="1">
259 <name>sizePolicy</name>
260 <sizepolicy>
261 <hsizetype>3</hsizetype>
262 <vsizetype>3</vsizetype>
263 </sizepolicy>
264 </property>
265 </widget>
266 </grid> 252 </grid>
267 </widget> 253 </widget>
268 </vbox> 254 </vbox>
269</widget> 255</widget>
270<customwidgets>
271 <customwidget>
272 <class>OTimePicker</class>
273 <header location="local">otimepicker.h</header>
274 <sizehint>
275 <width>-1</width>
276 <height>-1</height>
277 </sizehint>
278 <container>0</container>
279 <sizepolicy>
280 <hordata>7</hordata>
281 <verdata>1</verdata>
282 </sizepolicy>
283 <pixmap>image0</pixmap>
284 </customwidget>
285</customwidgets>
286<images>
287 <image>
288 <name>image0</name>
289 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753</data>
290 </image>
291</images>
292</UI> 256</UI>
diff --git a/libopie2/opieui/oversatileview.cpp b/libopie2/opieui/oversatileview.cpp
index 78154b7..f6c6410 100644
--- a/libopie2/opieui/oversatileview.cpp
+++ b/libopie2/opieui/oversatileview.cpp
@@ -1,1169 +1,1172 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4 =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4 =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31/* OPIE */ 31/* OPIE */
32 32
33#include <opie2/odebug.h> 33#include <opie2/odebug.h>
34#include <opie2/oversatileview.h> 34#include <opie2/oversatileview.h>
35#include <opie2/oversatileviewitem.h> 35#include <opie2/oversatileviewitem.h>
36#include <opie2/olistview.h> 36#include <opie2/olistview.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qaction.h> 40#include <qaction.h>
41#include <qpopupmenu.h> 41#include <qpopupmenu.h>
42 42
43using namespace Opie::Core;
44using namespace Opie::Ui;
45
43/* XPM */ 46/* XPM */
44static const char * view_icon_xpm[] = { 47static const char * view_icon_xpm[] = {
45"16 16 16 1", 48"16 16 16 1",
46 " c None", 49 " c None",
47 ".c #87BD88", 50 ".c #87BD88",
48 "+c #8BBE8B", 51 "+c #8BBE8B",
49 "@c #81BA81", 52 "@c #81BA81",
50 "#c #6DAF6D", 53 "#c #6DAF6D",
51 "$c #87BD87", 54 "$c #87BD87",
52 "%c #FCFDFC", 55 "%c #FCFDFC",
53 "&c #AED0AE", 56 "&c #AED0AE",
54 "*c #4E9C4C", 57 "*c #4E9C4C",
55 "=c #91BD91", 58 "=c #91BD91",
56 "-c #72B172", 59 "-c #72B172",
57 ";c #448643", 60 ";c #448643",
58 ">c #519F50", 61 ">c #519F50",
59 ",c #499247", 62 ",c #499247",
60 "'c #356A35", 63 "'c #356A35",
61 ")c #686868", 64 ")c #686868",
62" ", 65" ",
63" .+@# .+@# ", 66" .+@# .+@# ",
64" $%&* $%&* ", 67" $%&* $%&* ",
65" @=-; @=-; ", 68" @=-; @=-; ",
66" #>,' #>,' ", 69" #>,' #>,' ",
67" ", 70" ",
68" )))))) )))))) ", 71" )))))) )))))) ",
69" ", 72" ",
70" ", 73" ",
71" .+@# .+@# ", 74" .+@# .+@# ",
72" $%&* $%&* ", 75" $%&* $%&* ",
73" @=-; @=-; ", 76" @=-; @=-; ",
74" #>,' #>,' ", 77" #>,' #>,' ",
75" ", 78" ",
76" )))))) )))))) ", 79" )))))) )))))) ",
77" "}; 80" "};
78 81
79/* XPM */ 82/* XPM */
80static const char * view_tree_xpm[] = { 83static const char * view_tree_xpm[] = {
81"16 16 17 1", 84"16 16 17 1",
82 " c None", 85 " c None",
83 ".c #3A3A3A", 86 ".c #3A3A3A",
84 "+c #87BD88", 87 "+c #87BD88",
85 "@c #8BBE8B", 88 "@c #8BBE8B",
86 "#c #81BA81", 89 "#c #81BA81",
87 "$c #6DAF6D", 90 "$c #6DAF6D",
88 "%c #87BD87", 91 "%c #87BD87",
89 "&c #FCFDFC", 92 "&c #FCFDFC",
90 "*c #AED0AE", 93 "*c #AED0AE",
91 "=c #4E9C4C", 94 "=c #4E9C4C",
92 "-c #91BD91", 95 "-c #91BD91",
93 ";c #72B172", 96 ";c #72B172",
94 ">c #448643", 97 ">c #448643",
95 ",c #686868", 98 ",c #686868",
96 "'c #519F50", 99 "'c #519F50",
97 ")c #499247", 100 ")c #499247",
98 "!c #356A35", 101 "!c #356A35",
99" . ", 102" . ",
100" . ", 103" . ",
101" . +@#$ ", 104" . +@#$ ",
102" . %&*= ", 105" . %&*= ",
103" .. #-;> ,, ,,,", 106" .. #-;> ,, ,,,",
104" . $')! ", 107" . $')! ",
105" . ", 108" . ",
106" . ", 109" . ",
107" . ", 110" . ",
108" . +@#$ ", 111" . +@#$ ",
109" . %&*= ", 112" . %&*= ",
110" .. #-;> ,, ,,,", 113" .. #-;> ,, ,,,",
111" $')! ", 114" $')! ",
112" ", 115" ",
113" ", 116" ",
114" "}; 117" "};
115 118
116OVersatileView::OVersatileView( QWidget* parent, const char* name, int mode ) 119OVersatileView::OVersatileView( QWidget* parent, const char* name, int mode )
117 :QWidgetStack( parent, name ), 120 :QWidgetStack( parent, name ),
118 _viewmode( mode ), _warningpolicy( None ), 121 _viewmode( mode ), _warningpolicy( None ),
119 _treeleaf(), _treeopened(), _treeclosed(), 122 _treeleaf(), _treeopened(), _treeclosed(),
120 _iconleaf(), _iconopened(), _iconclosed() 123 _iconleaf(), _iconopened(), _iconclosed()
121{ 124{
122 // 125 //
123 // Create child widgets and set some reasonable default styles 126 // Create child widgets and set some reasonable default styles
124 // 127 //
125 128
126 _listview = new OListView( this, "oversatileview embedded listview" ); 129 _listview = new OListView( this, "oversatileview embedded listview" );
127 _iconview = new QIconView( this, "oversatileview embedded iconview" ); 130 _iconview = new QIconView( this, "oversatileview embedded iconview" );
128 131
129 _listview->setAllColumnsShowFocus( true ); 132 _listview->setAllColumnsShowFocus( true );
130 _listview->setRootIsDecorated( true ); 133 _listview->setRootIsDecorated( true );
131 _listview->setShowSortIndicator( true ); 134 _listview->setShowSortIndicator( true );
132 _iconview->setGridX( 90 ); 135 _iconview->setGridX( 90 );
133 _iconview->setGridY( 42 ); 136 _iconview->setGridY( 42 );
134 _iconview->setAutoArrange( true ); 137 _iconview->setAutoArrange( true );
135 138
136 #ifdef QWS // TODO: Let this depend on current geometry (rotation) 139 #ifdef QWS // TODO: Let this depend on current geometry (rotation)
137 _iconview->setArrangement( QIconView::TopToBottom ); 140 _iconview->setArrangement( QIconView::TopToBottom );
138 #else 141 #else
139 _iconview->setArrangement( QIconView::LeftToRight ); 142 _iconview->setArrangement( QIconView::LeftToRight );
140 #endif 143 #endif
141 144
142 _iconview->setResizeMode( QIconView::Adjust ); 145 _iconview->setResizeMode( QIconView::Adjust );
143 146
144 // qt-embedded: map stylus right on hold to right button press 147 // qt-embedded: map stylus right on hold to right button press
145 148
146 #ifdef QWS 149 #ifdef QWS
147 ( (QPEApplication*) qApp)->setStylusOperation( _iconview->viewport(), QPEApplication::RightOnHold ); 150 ( (QPEApplication*) qApp)->setStylusOperation( _iconview->viewport(), QPEApplication::RightOnHold );
148 ( (QPEApplication*) qApp)->setStylusOperation( _listview->viewport(), QPEApplication::RightOnHold ); 151 ( (QPEApplication*) qApp)->setStylusOperation( _listview->viewport(), QPEApplication::RightOnHold );
149 #endif 152 #endif
150 153
151 setViewMode( mode ); // TODO: Read last style from config 154 setViewMode( mode ); // TODO: Read last style from config
152 // setSynchronization( true ); // TODO: Implement this 155 // setSynchronization( true ); // TODO: Implement this
153 156
154 // create context menu allowing to switch between the views 157 // create context menu allowing to switch between the views
155 158
156 _contextmenu = new QPopupMenu( 0, "oversatileview contextmenu" ); 159 _contextmenu = new QPopupMenu( 0, "oversatileview contextmenu" );
157 _contextmenu->setCaption( "Style" ); 160 _contextmenu->setCaption( "Style" );
158 _contextmenu->setCheckable( true ); 161 _contextmenu->setCheckable( true );
159 QActionGroup* ag = new QActionGroup( _contextmenu, "style option group" ); 162 QActionGroup* ag = new QActionGroup( _contextmenu, "style option group" );
160 QAction* a1 = new QAction( "View Items in Icon Style", QIconSet( QPixmap( view_icon_xpm ) ), 163 QAction* a1 = new QAction( "View Items in Icon Style", QIconSet( QPixmap( view_icon_xpm ) ),
161 "View Icons", 0, ag, "viewicon action", true ); 164 "View Icons", 0, ag, "viewicon action", true );
162 QAction* a2 = new QAction( "View Items in Tree Style", QIconSet( QPixmap( view_tree_xpm ) ), 165 QAction* a2 = new QAction( "View Items in Tree Style", QIconSet( QPixmap( view_tree_xpm ) ),
163 "View Tree", 0, ag, "viewtree action", true ); 166 "View Tree", 0, ag, "viewtree action", true );
164 ag->addTo( _contextmenu ); 167 ag->addTo( _contextmenu );
165 if ( mode == Icons ) 168 if ( mode == Icons )
166 a1->setOn( true ); 169 a1->setOn( true );
167 else if ( mode == Tree ) 170 else if ( mode == Tree )
168 a2->setOn( true ); 171 a2->setOn( true );
169 connect( a1, SIGNAL( activated() ), this, SLOT( setIconViewMode() ) ); 172 connect( a1, SIGNAL( activated() ), this, SLOT( setIconViewMode() ) );
170 connect( a2, SIGNAL( activated() ), this, SLOT( setTreeViewMode() ) ); 173 connect( a2, SIGNAL( activated() ), this, SLOT( setTreeViewMode() ) );
171 174
172 #if (QT_VERSION >= 0x030000) 175 #if (QT_VERSION >= 0x030000)
173 connect( _listview, SIGNAL( contextMenuRequested(QListViewItem*,const QPoint&,int) ), this, SLOT( contextMenuRequested(QListViewItem*,const QPoint&,int) ) ); 176 connect( _listview, SIGNAL( contextMenuRequested(QListViewItem*,const QPoint&,int) ), this, SLOT( contextMenuRequested(QListViewItem*,const QPoint&,int) ) );
174 connect( _iconview, SIGNAL( contextMenuRequested(QIconViewItem*,const QPoint&) ), this, SLOT( contextMenuRequested(QIconViewItem*,const QPoint&) ) ); 177 connect( _iconview, SIGNAL( contextMenuRequested(QIconViewItem*,const QPoint&) ), this, SLOT( contextMenuRequested(QIconViewItem*,const QPoint&) ) );
175 #else 178 #else
176 connect( _listview, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), this, SLOT( contextMenuRequested(QListViewItem*,const QPoint&,int) ) ); 179 connect( _listview, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), this, SLOT( contextMenuRequested(QListViewItem*,const QPoint&,int) ) );
177 connect( _iconview, SIGNAL( rightButtonPressed(QIconViewItem*,const QPoint&) ), this, SLOT( contextMenuRequested(QIconViewItem*,const QPoint&) ) ); 180 connect( _iconview, SIGNAL( rightButtonPressed(QIconViewItem*,const QPoint&) ), this, SLOT( contextMenuRequested(QIconViewItem*,const QPoint&) ) );
178 #endif 181 #endif
179 182
180 // 183 //
181 // signal forwarders 184 // signal forwarders
182 // 185 //
183 // unfortunately we can't short-circuit all the QListView and QIconView signals 186 // unfortunately we can't short-circuit all the QListView and QIconView signals
184 // to OVersatileView signals, because the signal/slot mechanism doesn't allow 187 // to OVersatileView signals, because the signal/slot mechanism doesn't allow
185 // type-conversion :-( 188 // type-conversion :-(
186 189
187 // common signals for listview 190 // common signals for listview
188 191
189 connect( _listview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); 192 connect( _listview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
190 connect( _listview, SIGNAL( selectionChanged(QListViewItem*) ), this, SLOT( selectionChanged(QListViewItem*) ) ); 193 connect( _listview, SIGNAL( selectionChanged(QListViewItem*) ), this, SLOT( selectionChanged(QListViewItem*) ) );
191 connect( _listview, SIGNAL( currentChanged(QListViewItem*) ), this, SLOT( currentChanged(QListViewItem*) ) ); 194 connect( _listview, SIGNAL( currentChanged(QListViewItem*) ), this, SLOT( currentChanged(QListViewItem*) ) );
192 connect( _listview, SIGNAL( clicked(QListViewItem*) ), this, SLOT( clicked(QListViewItem*) ) ); 195 connect( _listview, SIGNAL( clicked(QListViewItem*) ), this, SLOT( clicked(QListViewItem*) ) );
193 connect( _listview, SIGNAL( pressed(QListViewItem*) ), this, SLOT( pressed(QListViewItem*) ) ); 196 connect( _listview, SIGNAL( pressed(QListViewItem*) ), this, SLOT( pressed(QListViewItem*) ) );
194 197
195 connect( _listview, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( doubleClicked(QListViewItem*) ) ); 198 connect( _listview, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( doubleClicked(QListViewItem*) ) );
196 connect( _listview, SIGNAL( returnPressed(QListViewItem*) ), this, SLOT( returnPressed(QListViewItem*) ) ); 199 connect( _listview, SIGNAL( returnPressed(QListViewItem*) ), this, SLOT( returnPressed(QListViewItem*) ) );
197 200
198 connect( _listview, SIGNAL( onItem(QListViewItem*) ), this, SLOT( onItem(QListViewItem*) ) ); 201 connect( _listview, SIGNAL( onItem(QListViewItem*) ), this, SLOT( onItem(QListViewItem*) ) );
199 connect( _listview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) ); 202 connect( _listview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) );
200 203
201 // common signals for iconview 204 // common signals for iconview
202 205
203 connect( _iconview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); 206 connect( _iconview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
204 connect( _iconview, SIGNAL( selectionChanged(QIconViewItem*) ), this, SLOT( selectionChanged(QIconViewItem*) ) ); 207 connect( _iconview, SIGNAL( selectionChanged(QIconViewItem*) ), this, SLOT( selectionChanged(QIconViewItem*) ) );
205 connect( _iconview, SIGNAL( currentChanged(QIconViewItem*) ), this, SLOT( currentChanged(QIconViewItem*) ) ); 208 connect( _iconview, SIGNAL( currentChanged(QIconViewItem*) ), this, SLOT( currentChanged(QIconViewItem*) ) );
206 connect( _iconview, SIGNAL( clicked(QIconViewItem*) ), this, SLOT( clicked(QIconViewItem*) ) ); 209 connect( _iconview, SIGNAL( clicked(QIconViewItem*) ), this, SLOT( clicked(QIconViewItem*) ) );
207 connect( _iconview, SIGNAL( pressed(QIconViewItem*) ), this, SLOT( pressed(QIconViewItem*) ) ); 210 connect( _iconview, SIGNAL( pressed(QIconViewItem*) ), this, SLOT( pressed(QIconViewItem*) ) );
208 211
209 connect( _iconview, SIGNAL( doubleClicked(QIconViewItem*) ), this, SLOT( doubleClicked(QIconViewItem*) ) ); 212 connect( _iconview, SIGNAL( doubleClicked(QIconViewItem*) ), this, SLOT( doubleClicked(QIconViewItem*) ) );
210 connect( _iconview, SIGNAL( returnPressed(QIconViewItem*) ), this, SLOT( returnPressed(QIconViewItem*) ) ); 213 connect( _iconview, SIGNAL( returnPressed(QIconViewItem*) ), this, SLOT( returnPressed(QIconViewItem*) ) );
211 214
212 connect( _iconview, SIGNAL( onItem(QIconViewItem*) ), this, SLOT( onItem(QIconViewItem*) ) ); 215 connect( _iconview, SIGNAL( onItem(QIconViewItem*) ), this, SLOT( onItem(QIconViewItem*) ) );
213 connect( _iconview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) ); 216 connect( _iconview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) );
214 217
215 // listview only signals 218 // listview only signals
216 219
217 connect( _listview, SIGNAL( expanded(QListViewItem*) ), this, SLOT( expanded(QListViewItem*) ) ); 220 connect( _listview, SIGNAL( expanded(QListViewItem*) ), this, SLOT( expanded(QListViewItem*) ) );
218 connect( _listview, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( collapsed(QListViewItem*) ) ); 221 connect( _listview, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( collapsed(QListViewItem*) ) );
219 222
220 // iconview only signals 223 // iconview only signals
221 224
222 connect( _iconview, SIGNAL( moved() ), this, SIGNAL( moved() ) ); 225 connect( _iconview, SIGNAL( moved() ), this, SIGNAL( moved() ) );
223} 226}
224 227
225OVersatileView::~OVersatileView() 228OVersatileView::~OVersatileView()
226{ 229{
227} 230}
228 231
229QPopupMenu* OVersatileView::contextMenu() const 232QPopupMenu* OVersatileView::contextMenu() const
230{ 233{
231 return _contextmenu; 234 return _contextmenu;
232} 235}
233 236
234void OVersatileView::contextMenuRequested( QListViewItem* item, const QPoint& pos, int col ) 237void OVersatileView::contextMenuRequested( QListViewItem* item, const QPoint& pos, int col )
235{ 238{
236 // can't use QObject::inherits here, because ListViewItems, beit Q, O or K, 239 // can't use QObject::inherits here, because ListViewItems, beit Q, O or K,
237 // do not inherit from QObject - assuming here the programmer is 240 // do not inherit from QObject - assuming here the programmer is
238 // disciplined enough to only add OVersatileViewItems to an OVersatileView 241 // disciplined enough to only add OVersatileViewItems to an OVersatileView
239 popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, col ); 242 popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, col );
240} 243}
241 244
242void OVersatileView::contextMenuRequested( QIconViewItem* item, const QPoint& pos ) 245void OVersatileView::contextMenuRequested( QIconViewItem* item, const QPoint& pos )
243{ 246{
244 // see above 247 // see above
245 popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, -1 ); 248 popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, -1 );
246} 249}
247 250
248void OVersatileView::popupContextMenu( OVersatileViewItem* item, const QPoint& pos, int col ) 251void OVersatileView::popupContextMenu( OVersatileViewItem* item, const QPoint& pos, int col )
249{ 252{
250 if ( !item ) 253 if ( !item )
251 _contextmenu->exec( pos ); 254 _contextmenu->exec( pos );
252 else 255 else
253 emit( contextMenuRequested( item, pos, col ) ); 256 emit( contextMenuRequested( item, pos, col ) );
254} 257}
255 258
256void OVersatileView::setSynchronization( bool sync ) 259void OVersatileView::setSynchronization( bool sync )
257{ 260{
258 _synchronization = sync; 261 _synchronization = sync;
259} 262}
260 263
261bool OVersatileView::synchronization() 264bool OVersatileView::synchronization()
262{ 265{
263 return _synchronization; 266 return _synchronization;
264} 267}
265 268
266void OVersatileView::setDefaultPixmaps( int mode, QPixmap& leaf, QPixmap& opened, QPixmap& closed ) 269void OVersatileView::setDefaultPixmaps( int mode, QPixmap& leaf, QPixmap& opened, QPixmap& closed )
267{ 270{
268 if ( mode == Tree ) 271 if ( mode == Tree )
269 { 272 {
270 _treeleaf = leaf; 273 _treeleaf = leaf;
271 _treeopened = opened; 274 _treeopened = opened;
272 _treeclosed = closed; 275 _treeclosed = closed;
273 } 276 }
274 else if ( mode == Icons ) 277 else if ( mode == Icons )
275 { 278 {
276 _iconleaf = leaf; 279 _iconleaf = leaf;
277 _iconopened = opened; 280 _iconopened = opened;
278 _iconclosed = closed; 281 _iconclosed = closed;
279 } 282 }
280 else 283 else
281 { 284 {
282 odebug << "OVersatileView::setDefaultPixmaps(): invalid mode" << oendl; 285 odebug << "OVersatileView::setDefaultPixmaps(): invalid mode" << oendl;
283 } 286 }
284} 287}
285 288
286QIconView* OVersatileView::iconView() const 289QIconView* OVersatileView::iconView() const
287{ 290{
288 return _iconview; 291 return _iconview;
289} 292}
290 293
291OListView* OVersatileView::listView() const 294OListView* OVersatileView::listView() const
292{ 295{
293 return _listview; 296 return _listview;
294} 297}
295 298
296void OVersatileView::setViewMode( int mode ) 299void OVersatileView::setViewMode( int mode )
297{ 300{
298 if ( mode == Tree ) 301 if ( mode == Tree )
299 { 302 {
300 _viewmode = mode; 303 _viewmode = mode;
301 raiseWidget( _listview ); 304 raiseWidget( _listview );
302 } 305 }
303 else if ( mode == Icons ) 306 else if ( mode == Icons )
304 { 307 {
305 _viewmode = mode; 308 _viewmode = mode;
306 raiseWidget( _iconview ); 309 raiseWidget( _iconview );
307 } 310 }
308 else 311 else
309 { 312 {
310 odebug << "OVersatileView::setViewMode(): invalid mode" << oendl; 313 odebug << "OVersatileView::setViewMode(): invalid mode" << oendl;
311 } 314 }
312} 315}
313 316
314void OVersatileView::setIconViewMode() 317void OVersatileView::setIconViewMode()
315{ 318{
316 setViewMode( Icons ); 319 setViewMode( Icons );
317} 320}
318 321
319void OVersatileView::setTreeViewMode() 322void OVersatileView::setTreeViewMode()
320{ 323{
321 setViewMode( Tree ); 324 setViewMode( Tree );
322} 325}
323 326
324bool OVersatileView::isValidViewMode( int mode ) const 327bool OVersatileView::isValidViewMode( int mode ) const
325{ 328{
326 switch ( _warningpolicy ) 329 switch ( _warningpolicy )
327 { 330 {
328 case OVersatileView::None: 331 case OVersatileView::None:
329 { 332 {
330 return true; 333 return true;
331 } 334 }
332 case OVersatileView::Warn: 335 case OVersatileView::Warn:
333 { 336 {
334 if ( _viewmode != mode ) 337 if ( _viewmode != mode )
335 { 338 {
336 odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl; 339 odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl;
337 return true; 340 return true;
338 } 341 }
339 } 342 }
340 case OVersatileView::WarnReturn: 343 case OVersatileView::WarnReturn:
341 { 344 {
342 if ( _viewmode != mode ) 345 if ( _viewmode != mode )
343 { 346 {
344 odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl; 347 odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl;
345 return false; 348 return false;
346 } 349 }
347 } 350 }
348 default: 351 default:
349 { 352 {
350 owarn << "OVersatileView::isValidViewMode(): Inconsistent object state!" << oendl; 353 owarn << "OVersatileView::isValidViewMode(): Inconsistent object state!" << oendl;
351 return true; 354 return true;
352 } 355 }
353 } 356 }
354} 357}
355void OVersatileView::setWarningPolicy( int policy ) const 358void OVersatileView::setWarningPolicy( int policy ) const
356{ 359{
357 _warningpolicy = policy; 360 _warningpolicy = policy;
358} 361}
359bool OVersatileView::warningPolicy() const 362bool OVersatileView::warningPolicy() const
360{ 363{
361 return _warningpolicy; 364 return _warningpolicy;
362} 365}
363//==============================================================================================// 366//==============================================================================================//
364// Stupid Signal forwarders... 367// Stupid Signal forwarders...
365// Folks, this is why I like python with its dynamic typing: 368// Folks, this is why I like python with its dynamic typing:
366// I can code the following dozens of lines C++ in four Python lines... 369// I can code the following dozens of lines C++ in four Python lines...
367//==============================================================================================// 370//==============================================================================================//
368 371
369void OVersatileView::selectionChanged( QListViewItem * item ) 372void OVersatileView::selectionChanged( QListViewItem * item )
370{ 373{
371 emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) ); 374 emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) );
372} 375}
373 376
374void OVersatileView::selectionChanged( QIconViewItem * item ) 377void OVersatileView::selectionChanged( QIconViewItem * item )
375{ 378{
376 emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) ); 379 emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) );
377} 380}
378 381
379void OVersatileView::currentChanged( QListViewItem * item ) 382void OVersatileView::currentChanged( QListViewItem * item )
380{ 383{
381 emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) ); 384 emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) );
382} 385}
383 386
384void OVersatileView::currentChanged( QIconViewItem * item ) 387void OVersatileView::currentChanged( QIconViewItem * item )
385{ 388{
386 emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) ); 389 emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) );
387} 390}
388 391
389void OVersatileView::clicked( QListViewItem * item ) 392void OVersatileView::clicked( QListViewItem * item )
390{ 393{
391 emit( clicked( static_cast<OVersatileViewItem*>( item ) ) ); 394 emit( clicked( static_cast<OVersatileViewItem*>( item ) ) );
392} 395}
393 396
394void OVersatileView::clicked( QIconViewItem * item ) 397void OVersatileView::clicked( QIconViewItem * item )
395{ 398{
396 emit( clicked( static_cast<OVersatileViewItem*>( item ) ) ); 399 emit( clicked( static_cast<OVersatileViewItem*>( item ) ) );
397} 400}
398 401
399void OVersatileView::pressed( QListViewItem * item ) 402void OVersatileView::pressed( QListViewItem * item )
400{ 403{
401 emit( pressed( static_cast<OVersatileViewItem*>( item ) ) ); 404 emit( pressed( static_cast<OVersatileViewItem*>( item ) ) );
402} 405}
403 406
404void OVersatileView::pressed( QIconViewItem * item ) 407void OVersatileView::pressed( QIconViewItem * item )
405{ 408{
406 emit( pressed( static_cast<OVersatileViewItem*>( item ) ) ); 409 emit( pressed( static_cast<OVersatileViewItem*>( item ) ) );
407} 410}
408 411
409void OVersatileView::doubleClicked( QListViewItem * item ) 412void OVersatileView::doubleClicked( QListViewItem * item )
410{ 413{
411 emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) ); 414 emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) );
412} 415}
413 416
414void OVersatileView::doubleClicked( QIconViewItem * item ) 417void OVersatileView::doubleClicked( QIconViewItem * item )
415{ 418{
416 emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) ); 419 emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) );
417} 420}
418 421
419void OVersatileView::returnPressed( QListViewItem * item ) 422void OVersatileView::returnPressed( QListViewItem * item )
420{ 423{
421 emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) ); 424 emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) );
422} 425}
423 426
424void OVersatileView::returnPressed( QIconViewItem * item ) 427void OVersatileView::returnPressed( QIconViewItem * item )
425{ 428{
426 emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) ); 429 emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) );
427} 430}
428 431
429void OVersatileView::onItem( QListViewItem * item ) 432void OVersatileView::onItem( QListViewItem * item )
430{ 433{
431 emit( onItem( static_cast<OVersatileViewItem*>( item ) ) ); 434 emit( onItem( static_cast<OVersatileViewItem*>( item ) ) );
432} 435}
433 436
434void OVersatileView::onItem( QIconViewItem * item ) 437void OVersatileView::onItem( QIconViewItem * item )
435{ 438{
436 emit( onItem( static_cast<OVersatileViewItem*>( item ) ) ); 439 emit( onItem( static_cast<OVersatileViewItem*>( item ) ) );
437} 440}
438 441
439void OVersatileView::expanded( QListViewItem *item ) // QListView 442void OVersatileView::expanded( QListViewItem *item ) // QListView
440{ 443{
441 //odebug << "OVersatileView::expanded(): opening tree..." << oendl; 444 //odebug << "OVersatileView::expanded(): opening tree..." << oendl;
442 if ( !_treeopened.isNull() ) 445 if ( !_treeopened.isNull() )
443 item->setPixmap( 0, _treeopened ); 446 item->setPixmap( 0, _treeopened );
444 emit( expanded( static_cast<OVersatileViewItem*>( item ) ) ); 447 emit( expanded( static_cast<OVersatileViewItem*>( item ) ) );
445} 448}
446void OVersatileView::collapsed( QListViewItem *item ) // QListView 449void OVersatileView::collapsed( QListViewItem *item ) // QListView
447{ 450{
448 if ( !_treeclosed.isNull() ) 451 if ( !_treeclosed.isNull() )
449 item->setPixmap( 0, _treeclosed ); 452 item->setPixmap( 0, _treeclosed );
450 emit( collapsed( static_cast<OVersatileViewItem*>( item ) ) ); 453 emit( collapsed( static_cast<OVersatileViewItem*>( item ) ) );
451} 454}
452 455
453//=============================================================================================// 456//=============================================================================================//
454// OVersatileView Case I - API only existing in QListView or QIconView but not in both! 457// OVersatileView Case I - API only existing in QListView or QIconView but not in both!
455//==============================================================================================// 458//==============================================================================================//
456 459
457int OVersatileView::treeStepSize() const // QListView 460int OVersatileView::treeStepSize() const // QListView
458{ 461{
459 if ( !isValidViewMode( Tree ) ) 462 if ( !isValidViewMode( Tree ) )
460 { 463 {
461 return -1; 464 return -1;
462 } 465 }
463 return _listview->treeStepSize(); 466 return _listview->treeStepSize();
464} 467}
465 void OVersatileView::setTreeStepSize( int size ) // QListView 468 void OVersatileView::setTreeStepSize( int size ) // QListView
466{ 469{
467 if ( !isValidViewMode( Tree ) ) 470 if ( !isValidViewMode( Tree ) )
468 { 471 {
469 return; 472 return;
470 } 473 }
471 _listview->setTreeStepSize( size ); 474 _listview->setTreeStepSize( size );
472} 475}
473 476
474QHeader * OVersatileView::header() const // QListView 477QHeader * OVersatileView::header() const // QListView
475{ 478{
476 if ( !isValidViewMode( Tree ) ) 479 if ( !isValidViewMode( Tree ) )
477 { 480 {
478 return 0; 481 return 0;
479 } 482 }
480 return _listview->header(); 483 return _listview->header();
481} 484}
482 485
483 int OVersatileView::addColumn( const QString &label, int size ) // QListView 486 int OVersatileView::addColumn( const QString &label, int size ) // QListView
484{ 487{
485 if ( !isValidViewMode( Tree ) ) 488 if ( !isValidViewMode( Tree ) )
486 { 489 {
487 return -1; 490 return -1;
488 } 491 }
489 return _listview->addColumn( label, size ); 492 return _listview->addColumn( label, size );
490} 493}
491 494
492 int OVersatileView::addColumn( const QIconSet& iconset, const QString &label, int size ) // QListView 495 int OVersatileView::addColumn( const QIconSet& iconset, const QString &label, int size ) // QListView
493{ 496{
494 if ( !isValidViewMode( Tree ) ) 497 if ( !isValidViewMode( Tree ) )
495 { 498 {
496 return -1; 499 return -1;
497 } 500 }
498 return _listview->addColumn( iconset, label, size ); 501 return _listview->addColumn( iconset, label, size );
499} 502}
500 503
501void OVersatileView::removeColumn( int index ) // QListView 504void OVersatileView::removeColumn( int index ) // QListView
502{ 505{
503 if ( !isValidViewMode( Tree ) ) 506 if ( !isValidViewMode( Tree ) )
504 { 507 {
505 return; 508 return;
506 } 509 }
507 _listview->removeColumn( index ); 510 _listview->removeColumn( index );
508} 511}
509 void OVersatileView::setColumnText( int column, const QString &label ) // QListView 512 void OVersatileView::setColumnText( int column, const QString &label ) // QListView
510{ 513{
511 if ( !isValidViewMode( Tree ) ) 514 if ( !isValidViewMode( Tree ) )
512 { 515 {
513 return; 516 return;
514 } 517 }
515 _listview->setColumnText( column, label ); 518 _listview->setColumnText( column, label );
516} 519}
517 void OVersatileView::setColumnText( int column, const QIconSet& iconset, const QString &label ) // QListView 520 void OVersatileView::setColumnText( int column, const QIconSet& iconset, const QString &label ) // QListView
518{ 521{
519 if ( !isValidViewMode( Tree ) ) 522 if ( !isValidViewMode( Tree ) )
520 { 523 {
521 return; 524 return;
522 } 525 }
523 _listview->setColumnText( column, iconset, label ); 526 _listview->setColumnText( column, iconset, label );
524} 527}
525QString OVersatileView::columnText( int column ) const // QListView 528QString OVersatileView::columnText( int column ) const // QListView
526{ 529{
527 if ( !isValidViewMode( Tree ) ) 530 if ( !isValidViewMode( Tree ) )
528 { 531 {
529 return QString::null; 532 return QString::null;
530 } 533 }
531 return _listview->columnText( column ); 534 return _listview->columnText( column );
532} 535}
533 void OVersatileView::setColumnWidth( int column, int width ) // QListView 536 void OVersatileView::setColumnWidth( int column, int width ) // QListView
534{ 537{
535 if ( !isValidViewMode( Tree ) ) 538 if ( !isValidViewMode( Tree ) )
536 { 539 {
537 return; 540 return;
538 } 541 }
539 _listview->setColumnWidth( column, width ); 542 _listview->setColumnWidth( column, width );
540} 543}
541int OVersatileView::columnWidth( int column ) const // QListView 544int OVersatileView::columnWidth( int column ) const // QListView
542{ 545{
543 if ( !isValidViewMode( Tree ) ) 546 if ( !isValidViewMode( Tree ) )
544 { 547 {
545 return -1; 548 return -1;
546 } 549 }
547 return _listview->columnWidth( column ); 550 return _listview->columnWidth( column );
548} 551}
549 void OVersatileView::setColumnWidthMode( int column, WidthMode mode ) // QListView 552 void OVersatileView::setColumnWidthMode( int column, WidthMode mode ) // QListView
550{ 553{
551 if ( !isValidViewMode( Tree ) ) 554 if ( !isValidViewMode( Tree ) )
552 { 555 {
553 return; 556 return;
554 } 557 }
555 _listview->setColumnWidth( column, mode ); 558 _listview->setColumnWidth( column, mode );
556} 559}
557int OVersatileView::columns() const // QListView 560int OVersatileView::columns() const // QListView
558{ 561{
559 if ( !isValidViewMode( Tree ) ) 562 if ( !isValidViewMode( Tree ) )
560 { 563 {
561 return -1; 564 return -1;
562 } 565 }
563 return _listview->columns(); 566 return _listview->columns();
564} 567}
565 568
566 void OVersatileView::setColumnAlignment( int column, int align ) // QListView 569 void OVersatileView::setColumnAlignment( int column, int align ) // QListView
567{ 570{
568 if ( !isValidViewMode( Tree ) ) 571 if ( !isValidViewMode( Tree ) )
569 { 572 {
570 return; 573 return;
571 } 574 }
572 _listview->setColumnAlignment( column, align ); 575 _listview->setColumnAlignment( column, align );
573} 576}
574int OVersatileView::columnAlignment( int column ) const // QListView 577int OVersatileView::columnAlignment( int column ) const // QListView
575{ 578{
576 if ( !isValidViewMode( Tree ) ) 579 if ( !isValidViewMode( Tree ) )
577 { 580 {
578 return -1; 581 return -1;
579 } 582 }
580 return _listview->columnAlignment( column ); 583 return _listview->columnAlignment( column );
581} 584}
582 585
583OVersatileViewItem * OVersatileView::itemAt( const QPoint & screenPos ) const // QListView 586OVersatileViewItem * OVersatileView::itemAt( const QPoint & screenPos ) const // QListView
584{ 587{
585 if ( !isValidViewMode( Tree ) ) 588 if ( !isValidViewMode( Tree ) )
586 { 589 {
587 return 0; 590 return 0;
588 } 591 }
589 return static_cast<OVersatileViewItem*>( _listview->itemAt( screenPos ) ); 592 return static_cast<OVersatileViewItem*>( _listview->itemAt( screenPos ) );
590} 593}
591QRect OVersatileView::itemRect( const OVersatileViewItem * item ) const // QListView 594QRect OVersatileView::itemRect( const OVersatileViewItem * item ) const // QListView
592{ 595{
593 if ( !isValidViewMode( Tree ) ) 596 if ( !isValidViewMode( Tree ) )
594 { 597 {
595 return QRect( -1, -1, -1, -1 ); 598 return QRect( -1, -1, -1, -1 );
596 } 599 }
597 return _listview->itemRect( item ); 600 return _listview->itemRect( item );
598} 601}
599int OVersatileView::itemPos( const OVersatileViewItem * item ) // QListView 602int OVersatileView::itemPos( const OVersatileViewItem * item ) // QListView
600{ 603{
601 if ( !isValidViewMode( Tree ) ) 604 if ( !isValidViewMode( Tree ) )
602 { 605 {
603 return -1; 606 return -1;
604 } 607 }
605 return _listview->itemPos( item ); 608 return _listview->itemPos( item );
606} 609}
607 610
608bool OVersatileView::isSelected( const OVersatileViewItem * item ) const // QListView // also in QIconViewItem but !in QIconView *shrug* 611bool OVersatileView::isSelected( const OVersatileViewItem * item ) const // QListView // also in QIconViewItem but !in QIconView *shrug*
609{ 612{
610 if ( !isValidViewMode( Tree ) ) 613 if ( !isValidViewMode( Tree ) )
611 { 614 {
612 return false; 615 return false;
613 } 616 }
614 return _listview->isSelected( item ); 617 return _listview->isSelected( item );
615} 618}
616 619
617 void OVersatileView::setMultiSelection( bool enable ) 620 void OVersatileView::setMultiSelection( bool enable )
618{ 621{
619 _listview->setMultiSelection( enable ); 622 _listview->setMultiSelection( enable );
620} 623}
621bool OVersatileView::isMultiSelection() const 624bool OVersatileView::isMultiSelection() const
622{ 625{
623 return _listview->isMultiSelection(); 626 return _listview->isMultiSelection();
624} 627}
625 628
626OVersatileViewItem * OVersatileView::selectedItem() const // QListView 629OVersatileViewItem * OVersatileView::selectedItem() const // QListView
627{ 630{
628 if ( !isValidViewMode( Tree ) ) 631 if ( !isValidViewMode( Tree ) )
629 { 632 {
630 return 0; 633 return 0;
631 } 634 }
632 return static_cast<OVersatileViewItem*>( _listview->selectedItem() ); 635 return static_cast<OVersatileViewItem*>( _listview->selectedItem() );
633} 636}
634 void OVersatileView::setOpen( OVersatileViewItem * item, bool open ) // QListView 637 void OVersatileView::setOpen( OVersatileViewItem * item, bool open ) // QListView
635{ 638{
636 if ( !isValidViewMode( Tree ) ) 639 if ( !isValidViewMode( Tree ) )
637 { 640 {
638 return; 641 return;
639 } 642 }
640 _listview->setOpen( item, open ); 643 _listview->setOpen( item, open );
641} 644}
642bool OVersatileView::isOpen( const OVersatileViewItem * item ) const // QListView 645bool OVersatileView::isOpen( const OVersatileViewItem * item ) const // QListView
643{ 646{
644 if ( !isValidViewMode( Tree ) ) 647 if ( !isValidViewMode( Tree ) )
645 { 648 {
646 return false; 649 return false;
647 } 650 }
648 return _listview->isOpen( item ); 651 return _listview->isOpen( item );
649} 652}
650 653
651OVersatileViewItem * OVersatileView::firstChild() const // QListView 654OVersatileViewItem * OVersatileView::firstChild() const // QListView
652{ 655{
653 if ( !isValidViewMode( Tree ) ) 656 if ( !isValidViewMode( Tree ) )
654 { 657 {
655 return 0; 658 return 0;
656 } 659 }
657 return static_cast<OVersatileViewItem*>( _listview->firstChild() ); 660 return static_cast<OVersatileViewItem*>( _listview->firstChild() );
658} 661}
659int OVersatileView::childCount() const // QListView 662int OVersatileView::childCount() const // QListView
660{ 663{
661 if ( !isValidViewMode( Tree ) ) 664 if ( !isValidViewMode( Tree ) )
662 { 665 {
663 return -1; 666 return -1;
664 } 667 }
665 return _listview->childCount(); 668 return _listview->childCount();
666} 669}
667 670
668 void OVersatileView::setAllColumnsShowFocus( bool focus ) // QListView 671 void OVersatileView::setAllColumnsShowFocus( bool focus ) // QListView
669{ 672{
670 if ( !isValidViewMode( Tree ) ) 673 if ( !isValidViewMode( Tree ) )
671 { 674 {
672 return; 675 return;
673 } 676 }
674 _listview->setAllColumnsShowFocus( focus ); 677 _listview->setAllColumnsShowFocus( focus );
675} 678}
676bool OVersatileView::allColumnsShowFocus() const // QListView 679bool OVersatileView::allColumnsShowFocus() const // QListView
677{ 680{
678 if ( !isValidViewMode( Tree ) ) 681 if ( !isValidViewMode( Tree ) )
679 { 682 {
680 return false; 683 return false;
681 } 684 }
682 return _listview->allColumnsShowFocus(); 685 return _listview->allColumnsShowFocus();
683} 686}
684 687
685 void OVersatileView::setItemMargin( int margin ) // QListView 688 void OVersatileView::setItemMargin( int margin ) // QListView
686{ 689{
687 if ( !isValidViewMode( Tree ) ) 690 if ( !isValidViewMode( Tree ) )
688 { 691 {
689 return; 692 return;
690 } 693 }
691 _listview->setItemMargin( margin ); 694 _listview->setItemMargin( margin );
692} 695}
693int OVersatileView::itemMargin() const // QListView 696int OVersatileView::itemMargin() const // QListView
694{ 697{
695 if ( !isValidViewMode( Tree ) ) 698 if ( !isValidViewMode( Tree ) )
696 { 699 {
697 return -1; 700 return -1;
698 } 701 }
699 return _listview->itemMargin(); 702 return _listview->itemMargin();
700} 703}
701 704
702 void OVersatileView::setRootIsDecorated( bool decorate ) // QListView 705 void OVersatileView::setRootIsDecorated( bool decorate ) // QListView
703{ 706{
704 if ( !isValidViewMode( Tree ) ) 707 if ( !isValidViewMode( Tree ) )
705 { 708 {
706 return; 709 return;
707 } 710 }
708 _listview->setRootIsDecorated( decorate ); 711 _listview->setRootIsDecorated( decorate );
709} 712}
710bool OVersatileView::rootIsDecorated() const // QListView 713bool OVersatileView::rootIsDecorated() const // QListView
711{ 714{
712 if ( !isValidViewMode( Tree ) ) 715 if ( !isValidViewMode( Tree ) )
713 { 716 {
714 return false; 717 return false;
715 } 718 }
716 return _listview->rootIsDecorated(); 719 return _listview->rootIsDecorated();
717} 720}
718 721
719void OVersatileView::setShowSortIndicator( bool show ) // QListView 722void OVersatileView::setShowSortIndicator( bool show ) // QListView
720{ 723{
721 if ( !isValidViewMode( Tree ) ) 724 if ( !isValidViewMode( Tree ) )
722 { 725 {
723 return; 726 return;
724 } 727 }
725 _listview->setShowSortIndicator( show ); 728 _listview->setShowSortIndicator( show );
726} 729}
727bool OVersatileView::showSortIndicator() const // QListView 730bool OVersatileView::showSortIndicator() const // QListView
728{ 731{
729 if ( !isValidViewMode( Tree ) ) 732 if ( !isValidViewMode( Tree ) )
730 { 733 {
731 return false; 734 return false;
732 } 735 }
733 return _listview->showSortIndicator(); 736 return _listview->showSortIndicator();
734} 737}
735 738
736void OVersatileView::triggerUpdate() // QListView 739void OVersatileView::triggerUpdate() // QListView
737{ 740{
738 if ( !isValidViewMode( Tree ) ) 741 if ( !isValidViewMode( Tree ) )
739 { 742 {
740 return; 743 return;
741 } 744 }
742 _listview->triggerUpdate(); 745 _listview->triggerUpdate();
743} 746}
744 747
745// 748//
746// only in QIconView 749// only in QIconView
747// 750//
748 751
749uint OVersatileView::count() const // QIconView 752uint OVersatileView::count() const // QIconView
750{ 753{
751 if ( !isValidViewMode( Icons ) ) 754 if ( !isValidViewMode( Icons ) )
752 { 755 {
753 return 0; 756 return 0;
754 } 757 }
755 return _iconview->count(); 758 return _iconview->count();
756} 759}
757 760
758int OVersatileView::index( const OVersatileViewItem *item ) const // QIconView 761int OVersatileView::index( const OVersatileViewItem *item ) const // QIconView
759{ 762{
760 if ( !isValidViewMode( Icons ) ) 763 if ( !isValidViewMode( Icons ) )
761 { 764 {
762 return -1; 765 return -1;
763 } 766 }
764 return _iconview->index( item ); 767 return _iconview->index( item );
765} 768}
766 769
767OVersatileViewItem* OVersatileView::firstItem() const // QIconView 770OVersatileViewItem* OVersatileView::firstItem() const // QIconView
768{ 771{
769 if ( !isValidViewMode( Icons ) ) 772 if ( !isValidViewMode( Icons ) )
770 { 773 {
771 return 0; 774 return 0;
772 } 775 }
773 return static_cast<OVersatileViewItem*>( _iconview->firstItem() ); 776 return static_cast<OVersatileViewItem*>( _iconview->firstItem() );
774} 777}
775OVersatileViewItem* OVersatileView::lastItem() const // QIconView 778OVersatileViewItem* OVersatileView::lastItem() const // QIconView
776{ 779{
777 if ( !isValidViewMode( Icons ) ) 780 if ( !isValidViewMode( Icons ) )
778 { 781 {
779 return 0; 782 return 0;
780 } 783 }
781 return static_cast<OVersatileViewItem*>( _iconview->lastItem() ); 784 return static_cast<OVersatileViewItem*>( _iconview->lastItem() );
782} 785}
783 786
784OVersatileViewItem* OVersatileView::findItem( const QPoint &pos ) const // QIconView 787OVersatileViewItem* OVersatileView::findItem( const QPoint &pos ) const // QIconView
785{ 788{
786 if ( !isValidViewMode( Icons ) ) 789 if ( !isValidViewMode( Icons ) )
787 { 790 {
788 return 0; 791 return 0;
789 } 792 }
790 return static_cast<OVersatileViewItem*>( _iconview->findItem( pos ) ); 793 return static_cast<OVersatileViewItem*>( _iconview->findItem( pos ) );
791} 794}
792OVersatileViewItem* OVersatileView::findItem( const QString &text ) const // QIconView 795OVersatileViewItem* OVersatileView::findItem( const QString &text ) const // QIconView
793{ 796{
794 if ( !isValidViewMode( Icons ) ) 797 if ( !isValidViewMode( Icons ) )
795 { 798 {
796 return 0; 799 return 0;
797 } 800 }
798 return static_cast<OVersatileViewItem*>( _iconview->findItem( text ) ); 801 return static_cast<OVersatileViewItem*>( _iconview->findItem( text ) );
799} 802}
800 803
801OVersatileViewItem* OVersatileView::findFirstVisibleItem( const QRect &r ) const // QIconView 804OVersatileViewItem* OVersatileView::findFirstVisibleItem( const QRect &r ) const // QIconView
802{ 805{
803 if ( !isValidViewMode( Icons ) ) 806 if ( !isValidViewMode( Icons ) )
804 { 807 {
805 return 0; 808 return 0;
806 } 809 }
807 return static_cast<OVersatileViewItem*>( _iconview->findFirstVisibleItem( r ) ); 810 return static_cast<OVersatileViewItem*>( _iconview->findFirstVisibleItem( r ) );
808} 811}
809OVersatileViewItem* OVersatileView::findLastVisibleItem( const QRect &r ) const // QIconView 812OVersatileViewItem* OVersatileView::findLastVisibleItem( const QRect &r ) const // QIconView
810{ 813{
811 if ( !isValidViewMode( Icons ) ) 814 if ( !isValidViewMode( Icons ) )
812 { 815 {
813 return 0; 816 return 0;
814 } 817 }
815 return static_cast<OVersatileViewItem*>( _iconview->findLastVisibleItem( r ) ); 818 return static_cast<OVersatileViewItem*>( _iconview->findLastVisibleItem( r ) );
816} 819}
817 820
818 void OVersatileView::setGridX( int rx ) // QIconView 821 void OVersatileView::setGridX( int rx ) // QIconView
819{ 822{
820 if ( !isValidViewMode( Icons ) ) 823 if ( !isValidViewMode( Icons ) )
821 { 824 {
822 return; 825 return;
823 } 826 }
824 _iconview->setGridX( rx ); 827 _iconview->setGridX( rx );
825} 828}
826 void OVersatileView::setGridY( int ry ) // QIconView 829 void OVersatileView::setGridY( int ry ) // QIconView
827{ 830{
828 if ( !isValidViewMode( Icons ) ) 831 if ( !isValidViewMode( Icons ) )
829 { 832 {
830 return; 833 return;
831 } 834 }
832 _iconview->setGridY( ry ); 835 _iconview->setGridY( ry );
833} 836}
834int OVersatileView::gridX() const // QIconView 837int OVersatileView::gridX() const // QIconView
835{ 838{
836 if ( !isValidViewMode( Icons ) ) 839 if ( !isValidViewMode( Icons ) )
837 { 840 {
838 return -1; 841 return -1;
839 } 842 }
840 return _iconview->gridX(); 843 return _iconview->gridX();
841} 844}
842int OVersatileView::gridY() const // QIconView 845int OVersatileView::gridY() const // QIconView
843{ 846{
844 if ( !isValidViewMode( Icons ) ) 847 if ( !isValidViewMode( Icons ) )
845 { 848 {
846 return -1; 849 return -1;
847 } 850 }
848 return _iconview->gridY(); 851 return _iconview->gridY();
849} 852}
850 void OVersatileView::setSpacing( int sp ) // QIconView 853 void OVersatileView::setSpacing( int sp ) // QIconView
851{ 854{
852 if ( !isValidViewMode( Icons ) ) 855 if ( !isValidViewMode( Icons ) )
853 { 856 {
854 return; 857 return;
855 } 858 }
856 _iconview->setSpacing( sp ); 859 _iconview->setSpacing( sp );
857} 860}
858int OVersatileView::spacing() const // QIconView 861int OVersatileView::spacing() const // QIconView
859{ 862{
860 if ( !isValidViewMode( Icons ) ) 863 if ( !isValidViewMode( Icons ) )
861 { 864 {
862 return -1; 865 return -1;
863 } 866 }
864 return _iconview->spacing(); 867 return _iconview->spacing();
865} 868}
866 void OVersatileView::setItemTextPos( QIconView::ItemTextPos pos ) // QIconView 869 void OVersatileView::setItemTextPos( QIconView::ItemTextPos pos ) // QIconView
867{ 870{
868 if ( !isValidViewMode( Icons ) ) 871 if ( !isValidViewMode( Icons ) )
869 { 872 {
870 return; 873 return;
871 } 874 }
872 _iconview->setItemTextPos( pos ); 875 _iconview->setItemTextPos( pos );
873} 876}
874QIconView::ItemTextPos OVersatileView::itemTextPos() const // QIconView 877QIconView::ItemTextPos OVersatileView::itemTextPos() const // QIconView
875{ 878{
876 if ( !isValidViewMode( Icons ) ) 879 if ( !isValidViewMode( Icons ) )
877 { 880 {
878 return (QIconView::ItemTextPos) -1; 881 return (QIconView::ItemTextPos) -1;
879 } 882 }
880 return _iconview->itemTextPos(); 883 return _iconview->itemTextPos();
881} 884}
882 void OVersatileView::setItemTextBackground( const QBrush &b ) // QIconView 885 void OVersatileView::setItemTextBackground( const QBrush &b ) // QIconView
883{ 886{
884 if ( !isValidViewMode( Icons ) ) 887 if ( !isValidViewMode( Icons ) )
885 { 888 {
886 return; 889 return;
887 } 890 }
888 _iconview->setItemTextBackground( b ); 891 _iconview->setItemTextBackground( b );
889} 892}
890QBrush OVersatileView::itemTextBackground() const // QIconView 893QBrush OVersatileView::itemTextBackground() const // QIconView
891{ 894{
892 if ( !isValidViewMode( Icons ) ) 895 if ( !isValidViewMode( Icons ) )
893 { 896 {
894 return QBrush(); 897 return QBrush();
895 } 898 }
896 return _iconview->itemTextBackground(); 899 return _iconview->itemTextBackground();
897} 900}
898 void OVersatileView::setArrangement( QIconView::Arrangement am ) // QIconView 901 void OVersatileView::setArrangement( QIconView::Arrangement am ) // QIconView
899{ 902{
900 if ( !isValidViewMode( Icons ) ) 903 if ( !isValidViewMode( Icons ) )
901 { 904 {
902 return; 905 return;
903 } 906 }
904 _iconview->setArrangement( am ); 907 _iconview->setArrangement( am );
905} 908}
906QIconView::Arrangement OVersatileView::arrangement() const // QIconView 909QIconView::Arrangement OVersatileView::arrangement() const // QIconView
907{ 910{
908 if ( !isValidViewMode( Icons ) ) 911 if ( !isValidViewMode( Icons ) )
909 { 912 {
910 return (QIconView::Arrangement) -1; 913 return (QIconView::Arrangement) -1;
911 } 914 }
912 return _iconview->arrangement(); 915 return _iconview->arrangement();
913} 916}
914 void OVersatileView::setResizeMode( QIconView::ResizeMode am ) // QIconView 917 void OVersatileView::setResizeMode( QIconView::ResizeMode am ) // QIconView
915{ 918{
916 if ( !isValidViewMode( Icons ) ) 919 if ( !isValidViewMode( Icons ) )
917 { 920 {
918 return; 921 return;
919 } 922 }
920 _iconview->setResizeMode( am ); 923 _iconview->setResizeMode( am );
921} 924}
922QIconView::ResizeMode OVersatileView::resizeMode() const // QIconView 925QIconView::ResizeMode OVersatileView::resizeMode() const // QIconView
923{ 926{
924 if ( !isValidViewMode( Icons ) ) 927 if ( !isValidViewMode( Icons ) )
925 { 928 {
926 return (QIconView::ResizeMode) -1; 929 return (QIconView::ResizeMode) -1;
927 } 930 }
928 return _iconview->resizeMode(); 931 return _iconview->resizeMode();
929} 932}
930 void OVersatileView::setMaxItemWidth( int w ) // QIconView 933 void OVersatileView::setMaxItemWidth( int w ) // QIconView
931{ 934{
932 if ( !isValidViewMode( Icons ) ) 935 if ( !isValidViewMode( Icons ) )
933 { 936 {
934 return; 937 return;
935 } 938 }
936 _iconview->setMaxItemWidth( w ); 939 _iconview->setMaxItemWidth( w );
937} 940}
938int OVersatileView::maxItemWidth() const // QIconView 941int OVersatileView::maxItemWidth() const // QIconView
939{ 942{
940 if ( !isValidViewMode( Icons ) ) 943 if ( !isValidViewMode( Icons ) )
941 { 944 {
942 return -1; 945 return -1;
943 } 946 }
944 return _iconview->maxItemWidth(); 947 return _iconview->maxItemWidth();
945} 948}
946 void OVersatileView::setMaxItemTextLength( int w ) // QIconView 949 void OVersatileView::setMaxItemTextLength( int w ) // QIconView
947{ 950{
948 if ( !isValidViewMode( Icons ) ) 951 if ( !isValidViewMode( Icons ) )
949 { 952 {
950 return; 953 return;
951 } 954 }
952 _iconview->setMaxItemTextLength( w ); 955 _iconview->setMaxItemTextLength( w );
953} 956}
954int OVersatileView::maxItemTextLength() const // QIconView 957int OVersatileView::maxItemTextLength() const // QIconView
955{ 958{
956 if ( !isValidViewMode( Icons ) ) 959 if ( !isValidViewMode( Icons ) )
957 { 960 {
958 return -1; 961 return -1;
959 } 962 }
960 return _iconview->maxItemTextLength(); 963 return _iconview->maxItemTextLength();
961} 964}
962 void OVersatileView::setAutoArrange( bool b ) // QIconView 965 void OVersatileView::setAutoArrange( bool b ) // QIconView
963{ 966{
964 if ( !isValidViewMode( Icons ) ) 967 if ( !isValidViewMode( Icons ) )
965 { 968 {
966 return; 969 return;
967 } 970 }
968 _iconview->setAutoArrange( b ); 971 _iconview->setAutoArrange( b );
969} 972}
970bool OVersatileView::autoArrange() const // QIconView 973bool OVersatileView::autoArrange() const // QIconView
971{ 974{
972 if ( !isValidViewMode( Icons ) ) 975 if ( !isValidViewMode( Icons ) )
973 { 976 {
974 return false; 977 return false;
975 } 978 }
976 return _iconview->autoArrange(); 979 return _iconview->autoArrange();
977} 980}
978 void OVersatileView::setShowToolTips( bool b ) // QIconView 981 void OVersatileView::setShowToolTips( bool b ) // QIconView
979{ 982{
980 if ( !isValidViewMode( Icons ) ) 983 if ( !isValidViewMode( Icons ) )
981 { 984 {
982 return; 985 return;
983 } 986 }
984 _iconview->setShowToolTips( b ); 987 _iconview->setShowToolTips( b );
985} 988}
986bool OVersatileView::showToolTips() const // QIconView 989bool OVersatileView::showToolTips() const // QIconView
987{ 990{
988 if ( !isValidViewMode( Icons ) ) 991 if ( !isValidViewMode( Icons ) )
989 { 992 {
990 return false; 993 return false;
991 } 994 }
992 return _iconview->showToolTips(); 995 return _iconview->showToolTips();
993} 996}
994 997
995bool OVersatileView::sorting() const // QIconView 998bool OVersatileView::sorting() const // QIconView
996{ 999{
997 if ( !isValidViewMode( Icons ) ) 1000 if ( !isValidViewMode( Icons ) )
998 { 1001 {
999 return false; 1002 return false;
1000 } 1003 }
1001 return _iconview->sorting(); 1004 return _iconview->sorting();
1002} 1005}
1003bool OVersatileView::sortDirection() const // QIconView 1006bool OVersatileView::sortDirection() const // QIconView
1004{ 1007{
1005 if ( !isValidViewMode( Icons ) ) 1008 if ( !isValidViewMode( Icons ) )
1006 { 1009 {
1007 return false; 1010 return false;
1008 } 1011 }
1009 return _iconview->sortDirection(); 1012 return _iconview->sortDirection();
1010} 1013}
1011 1014
1012 void OVersatileView::setItemsMovable( bool b ) // QIconView 1015 void OVersatileView::setItemsMovable( bool b ) // QIconView
1013{ 1016{
1014 if ( !isValidViewMode( Icons ) ) 1017 if ( !isValidViewMode( Icons ) )
1015 { 1018 {
1016 return; 1019 return;
1017 } 1020 }
1018 _iconview->setItemsMovable( b ); 1021 _iconview->setItemsMovable( b );
1019} 1022}
1020bool OVersatileView::itemsMovable() const // QIconView 1023bool OVersatileView::itemsMovable() const // QIconView
1021{ 1024{
1022 if ( !isValidViewMode( Icons ) ) 1025 if ( !isValidViewMode( Icons ) )
1023 { 1026 {
1024 return false; 1027 return false;
1025 } 1028 }
1026 return _iconview->itemsMovable(); 1029 return _iconview->itemsMovable();
1027} 1030}
1028void OVersatileView::setWordWrapIconText( bool b ) // QIconView 1031void OVersatileView::setWordWrapIconText( bool b ) // QIconView
1029{ 1032{
1030 if ( !isValidViewMode( Icons ) ) 1033 if ( !isValidViewMode( Icons ) )
1031 { 1034 {
1032 return; 1035 return;
1033 } 1036 }
1034 _iconview->setWordWrapIconText( b ); 1037 _iconview->setWordWrapIconText( b );
1035} 1038}
1036bool OVersatileView::wordWrapIconText() const // QIconView 1039bool OVersatileView::wordWrapIconText() const // QIconView
1037{ 1040{
1038 if ( !isValidViewMode( Icons ) ) 1041 if ( !isValidViewMode( Icons ) )
1039 { 1042 {
1040 return false; 1043 return false;
1041 } 1044 }
1042 return _iconview->wordWrapIconText(); 1045 return _iconview->wordWrapIconText();
1043} 1046}
1044 1047
1045void OVersatileView::arrangeItemsInGrid( const QSize &grid, bool update ) // QIconView 1048void OVersatileView::arrangeItemsInGrid( const QSize &grid, bool update ) // QIconView
1046{ 1049{
1047 if ( !isValidViewMode( Icons ) ) 1050 if ( !isValidViewMode( Icons ) )
1048 { 1051 {
1049 return; 1052 return;
1050 } 1053 }
1051 _iconview->arrangeItemsInGrid( grid, update ); 1054 _iconview->arrangeItemsInGrid( grid, update );
1052} 1055}
1053void OVersatileView::arrangeItemsInGrid( bool update ) // QIconView 1056void OVersatileView::arrangeItemsInGrid( bool update ) // QIconView
1054{ 1057{
1055 if ( !isValidViewMode( Icons ) ) 1058 if ( !isValidViewMode( Icons ) )
1056 { 1059 {
1057 return; 1060 return;
1058 } 1061 }
1059 _iconview->arrangeItemsInGrid( update ); 1062 _iconview->arrangeItemsInGrid( update );
1060} 1063}
1061void OVersatileView::updateContents() // QIconView 1064void OVersatileView::updateContents() // QIconView
1062{ 1065{
1063 if ( !isValidViewMode( Icons ) ) 1066 if ( !isValidViewMode( Icons ) )
1064 { 1067 {
1065 return; 1068 return;
1066 } 1069 }
1067 _iconview->updateContents(); 1070 _iconview->updateContents();
1068} 1071}
1069 1072
1070//==============================================================================================// 1073//==============================================================================================//
1071// OVersatileView Case II - QListView / QIconView common API 1074// OVersatileView Case II - QListView / QIconView common API
1072//==============================================================================================// 1075//==============================================================================================//
1073 1076
1074void OVersatileView::clear() 1077void OVersatileView::clear()
1075{ 1078{
1076 _iconview->clear(); 1079 _iconview->clear();
1077 _listview->clear(); 1080 _listview->clear();
1078} 1081}
1079 1082
1080void OVersatileView::setFont( const QFont & font ) 1083void OVersatileView::setFont( const QFont & font )
1081{ 1084{
1082 _iconview->setFont( font ); 1085 _iconview->setFont( font );
1083 _listview->setFont( font ); 1086 _listview->setFont( font );
1084} 1087}
1085void OVersatileView::setPalette( const QPalette & palette ) 1088void OVersatileView::setPalette( const QPalette & palette )
1086{ 1089{
1087 _iconview->setPalette( palette ); 1090 _iconview->setPalette( palette );
1088 _listview->setPalette( palette ); 1091 _listview->setPalette( palette );
1089} 1092}
1090 1093
1091void OVersatileView::takeItem( OVersatileViewItem * item ) 1094void OVersatileView::takeItem( OVersatileViewItem * item )
1092{ 1095{
1093 _iconview->takeItem( item ); 1096 _iconview->takeItem( item );
1094 _listview->takeItem( item ); 1097 _listview->takeItem( item );
1095} 1098}
1096 1099
1097void OVersatileView::setSelectionMode( SelectionMode mode ) 1100void OVersatileView::setSelectionMode( SelectionMode mode )
1098{ 1101{
1099 _iconview->setSelectionMode( (QIconView::SelectionMode) mode ); 1102 _iconview->setSelectionMode( (QIconView::SelectionMode) mode );
1100 _listview->setSelectionMode( (QListView::SelectionMode) mode ); 1103 _listview->setSelectionMode( (QListView::SelectionMode) mode );
1101} 1104}
1102OVersatileView::SelectionMode OVersatileView::selectionMode() const 1105OVersatileView::SelectionMode OVersatileView::selectionMode() const
1103{ 1106{
1104 return (OVersatileView::SelectionMode) _iconview->selectionMode(); 1107 return (OVersatileView::SelectionMode) _iconview->selectionMode();
1105} 1108}
1106 1109
1107void OVersatileView::selectAll( bool select ) 1110void OVersatileView::selectAll( bool select )
1108{ 1111{
1109 _iconview->selectAll( select ); 1112 _iconview->selectAll( select );
1110} 1113}
1111void OVersatileView::clearSelection() 1114void OVersatileView::clearSelection()
1112{ 1115{
1113 _iconview->clearSelection(); 1116 _iconview->clearSelection();
1114 _listview->clearSelection(); 1117 _listview->clearSelection();
1115} 1118}
1116void OVersatileView::invertSelection() 1119void OVersatileView::invertSelection()
1117{ 1120{
1118 _iconview->invertSelection(); 1121 _iconview->invertSelection();
1119 _listview->invertSelection(); 1122 _listview->invertSelection();
1120} 1123}
1121 1124
1122void OVersatileView::ensureItemVisible( const OVersatileViewItem * item ) 1125void OVersatileView::ensureItemVisible( const OVersatileViewItem * item )
1123{ 1126{
1124 _iconview->ensureItemVisible( const_cast<OVersatileViewItem*>( item ) ); 1127 _iconview->ensureItemVisible( const_cast<OVersatileViewItem*>( item ) );
1125 _listview->ensureItemVisible( item ); 1128 _listview->ensureItemVisible( item );
1126} 1129}
1127void OVersatileView::repaintItem( const OVersatileViewItem * item ) const 1130void OVersatileView::repaintItem( const OVersatileViewItem * item ) const
1128{ 1131{
1129 _iconview->repaintItem( const_cast<OVersatileViewItem*>( item ) ); 1132 _iconview->repaintItem( const_cast<OVersatileViewItem*>( item ) );
1130 _listview->repaintItem( item ); 1133 _listview->repaintItem( item );
1131} 1134}
1132 1135
1133void OVersatileView::setCurrentItem( OVersatileViewItem * item ) 1136void OVersatileView::setCurrentItem( OVersatileViewItem * item )
1134{ 1137{
1135 _iconview->setCurrentItem( item ); 1138 _iconview->setCurrentItem( item );
1136 _listview->setCurrentItem( item ); 1139 _listview->setCurrentItem( item );
1137} 1140}
1138OVersatileViewItem * OVersatileView::currentItem() const 1141OVersatileViewItem * OVersatileView::currentItem() const
1139{ 1142{
1140 return static_cast<OVersatileViewItem*>( _listview->currentItem() ); 1143 return static_cast<OVersatileViewItem*>( _listview->currentItem() );
1141} 1144}
1142 1145
1143// bool eventFilter( QObject * o, QEvent * ) // use QWidgetStack implementation 1146// bool eventFilter( QObject * o, QEvent * ) // use QWidgetStack implementation
1144 1147
1145// QSize minimumSizeHint() const // use QWidgetStack implementation 1148// QSize minimumSizeHint() const // use QWidgetStack implementation
1146// QSizePolicy sizePolicy() const // use QWidgetStack implementation 1149// QSizePolicy sizePolicy() const // use QWidgetStack implementation
1147// QSize sizeHint() const // use QWidgetStack implementation 1150// QSize sizeHint() const // use QWidgetStack implementation
1148 1151
1149//==============================================================================================// 1152//==============================================================================================//
1150// OVersatileView Case III - APIs which differ slightly 1153// OVersatileView Case III - APIs which differ slightly
1151//==============================================================================================// 1154//==============================================================================================//
1152 1155
1153/* 1156/*
1154 1157
1155 void OVersatileView::insertItem( OVersatileViewItem * ) // QListView 1158 void OVersatileView::insertItem( OVersatileViewItem * ) // QListView
1156 void OVersatileView::insertItem( OVersatileViewItem *item, OVersatileViewItem *after = 0L ) // QIconView 1159 void OVersatileView::insertItem( OVersatileViewItem *item, OVersatileViewItem *after = 0L ) // QIconView
1157 1160
1158 void OVersatileView::setSelected( OVersatileViewItem *, bool ) // QListView 1161 void OVersatileView::setSelected( OVersatileViewItem *, bool ) // QListView
1159 void OVersatileView::setSelected( OVersatileViewItem *item, bool s, bool cb = FALSE ) // QIconView 1162 void OVersatileView::setSelected( OVersatileViewItem *item, bool s, bool cb = FALSE ) // QIconView
1160 1163
1161 void OVersatileView::setSorting( int column, bool increasing = TRUE ) // QListView 1164 void OVersatileView::setSorting( int column, bool increasing = TRUE ) // QListView
1162void OVersatileView::setSorting( bool sort, bool ascending = TRUE ) // QIconView 1165void OVersatileView::setSorting( bool sort, bool ascending = TRUE ) // QIconView
1163 1166
1164void OVersatileView::sort() // #### make in next major release // QListView 1167void OVersatileView::sort() // #### make in next major release // QListView
1165 void OVersatileView::sort( bool ascending = TRUE ) // QIconView 1168 void OVersatileView::sort( bool ascending = TRUE ) // QIconView
1166 1169
1167*/ 1170*/
1168 1171
1169 1172
diff --git a/libopie2/opieui/oversatileview.h b/libopie2/opieui/oversatileview.h
index 8af21dc..61b61db 100644
--- a/libopie2/opieui/oversatileview.h
+++ b/libopie2/opieui/oversatileview.h
@@ -1,394 +1,399 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4 =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4 =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#ifndef OVERSATILEVIEW_H 31#ifndef OVERSATILEVIEW_H
32#define OVERSATILEVIEW_H 32#define OVERSATILEVIEW_H
33 33
34/* QT */ 34/* QT */
35 35
36#include <qwidgetstack.h> 36#include <qwidgetstack.h>
37#include <qiconview.h> 37#include <qiconview.h>
38 38
39/* OPIE */ 39/* OPIE */
40 40
41#include <opie2/oapplication.h> 41#include <opie2/oapplication.h>
42 42
43/* FORWARDS */ 43/* FORWARDS */
44 44
45class QHeader; 45class QHeader;
46class QIconSet; 46class QIconSet;
47class QIconViewItem; 47class QIconViewItem;
48class OListView;
49class QListViewItem; 48class QListViewItem;
50class QPopupMenu; 49class QPopupMenu;
51class QString; 50class QString;
52 51
53#ifndef QT_NO_DRAGANDDROP 52#ifndef QT_NO_DRAGANDDROP
54class QIconDragItem; 53class QIconDragItem;
55#endif 54#endif
56 55
56namespace Opie {
57namespace Ui {
58class OListView;
59
57class OVersatileView : public QWidgetStack 60class OVersatileView : public QWidgetStack
58{ 61{
59 Q_OBJECT 62 Q_OBJECT
60 63
61 friend class OVersatileViewItem; 64 friend class OVersatileViewItem;
62 65
63 //==============================================================================================// 66 //==============================================================================================//
64 // OVersatileView High Level API 67 // OVersatileView High Level API
65 //==============================================================================================// 68 //==============================================================================================//
66 69
67 public: 70 public:
68 OVersatileView( QWidget* parent = 0, const char* name = 0, int mode = 0 ); 71 OVersatileView( QWidget* parent = 0, const char* name = 0, int mode = 0 );
69 ~OVersatileView(); 72 ~OVersatileView();
70 73
71 QPopupMenu* contextMenu() const; 74 QPopupMenu* contextMenu() const;
72 75
73 void setSynchronization( bool sync ); 76 void setSynchronization( bool sync );
74 bool synchronization(); 77 bool synchronization();
75 78
76 enum ViewMode { Tree = 0, Icons }; 79 enum ViewMode { Tree = 0, Icons };
77 int viewMode(); 80 int viewMode();
78 81
79 QIconView* iconView() const; 82 QIconView* iconView() const;
80 OListView* listView() const; 83 OListView* listView() const;
81 84
82 enum WarningPolicy { None = 0, Warn, WarnReturn }; 85 enum WarningPolicy { None = 0, Warn, WarnReturn };
83 86
84 void setWarningPolicy( int ) const; // warn, if calling a method which doesn't apply to the current viewmode 87 void setWarningPolicy( int ) const; // warn, if calling a method which doesn't apply to the current viewmode
85 bool warningPolicy() const; 88 bool warningPolicy() const;
86 89
87 void setDefaultPixmaps( int mode, QPixmap& leaf, QPixmap& opened, QPixmap& closed ); 90 void setDefaultPixmaps( int mode, QPixmap& leaf, QPixmap& opened, QPixmap& closed );
88 91
89 public slots: 92 public slots:
90 void setViewMode( int mode ); 93 void setViewMode( int mode );
91 void setIconViewMode(); 94 void setIconViewMode();
92 void setTreeViewMode(); 95 void setTreeViewMode();
93 96
94 protected: 97 protected:
95 virtual bool isValidViewMode( int mode ) const; 98 virtual bool isValidViewMode( int mode ) const;
96 virtual void popupContextMenu( OVersatileViewItem* item, const QPoint& pos, int col = 0 ); 99 virtual void popupContextMenu( OVersatileViewItem* item, const QPoint& pos, int col = 0 );
97 100
98 private: 101 private:
99 int _viewmode; 102 int _viewmode;
100 bool _synchronization; 103 bool _synchronization;
101 mutable int _warningpolicy; 104 mutable int _warningpolicy;
102 105
103 OListView* _listview; 106 OListView* _listview;
104 QIconView* _iconview; 107 QIconView* _iconview;
105 108
106 QPixmap _treeleaf; 109 QPixmap _treeleaf;
107 QPixmap _treeopened; 110 QPixmap _treeopened;
108 QPixmap _treeclosed; 111 QPixmap _treeclosed;
109 112
110 QPixmap _iconleaf; 113 QPixmap _iconleaf;
111 QPixmap _iconopened; 114 QPixmap _iconopened;
112 QPixmap _iconclosed; 115 QPixmap _iconclosed;
113 116
114 QPopupMenu* _contextmenu; 117 QPopupMenu* _contextmenu;
115 118
116 int _iconstyle; 119 int _iconstyle;
117 int _treestyle; 120 int _treestyle;
118 121
119 private slots: 122 private slots:
120 123
121 void contextMenuRequested( QListViewItem*, const QPoint&, int ); 124 void contextMenuRequested( QListViewItem*, const QPoint&, int );
122 void contextMenuRequested( QIconViewItem*, const QPoint& ); 125 void contextMenuRequested( QIconViewItem*, const QPoint& );
123 126
124 // type converting signal forwarders 127 // type converting signal forwarders
125 128
126 void selectionChanged( QListViewItem * ); 129 void selectionChanged( QListViewItem * );
127 void currentChanged( QListViewItem * ); 130 void currentChanged( QListViewItem * );
128 void clicked( QListViewItem * ); 131 void clicked( QListViewItem * );
129 void pressed( QListViewItem * ); 132 void pressed( QListViewItem * );
130 void doubleClicked( QListViewItem * ); 133 void doubleClicked( QListViewItem * );
131 void returnPressed( QListViewItem * ); 134 void returnPressed( QListViewItem * );
132 void onItem( QListViewItem * ); 135 void onItem( QListViewItem * );
133 136
134 void selectionChanged( QIconViewItem * ); 137 void selectionChanged( QIconViewItem * );
135 void currentChanged( QIconViewItem * ); 138 void currentChanged( QIconViewItem * );
136 void clicked( QIconViewItem * ); 139 void clicked( QIconViewItem * );
137 void pressed( QIconViewItem * ); 140 void pressed( QIconViewItem * );
138 void doubleClicked( QIconViewItem * ); 141 void doubleClicked( QIconViewItem * );
139 void returnPressed( QIconViewItem * ); 142 void returnPressed( QIconViewItem * );
140 void onItem( QIconViewItem * ); 143 void onItem( QIconViewItem * );
141 144
142 void expanded( QListViewItem * item ); // QListView 145 void expanded( QListViewItem * item ); // QListView
143 void collapsed( QListViewItem * item ); // QListView 146 void collapsed( QListViewItem * item ); // QListView
144 147
145 signals: 148 signals:
146 149
147 void contextMenuRequested( OVersatileViewItem * item, const QPoint& pos, int col ); 150 void contextMenuRequested( OVersatileViewItem * item, const QPoint& pos, int col );
148 151
149 /*#ifndef QT_NO_DRAGANDDROP 152 /*#ifndef QT_NO_DRAGANDDROP
150 void dropped( QDropEvent *e, const QValueList<QIconDragItem> &lst ); // QIconView 153 void dropped( QDropEvent *e, const QValueList<QIconDragItem> &lst ); // QIconView
151 #endif 154 #endif
152 void itemRenamed( OVersatileViewItem *item, const QString & ); // QIconView 155 void itemRenamed( OVersatileViewItem *item, const QString & ); // QIconView
153 void itemRenamed( OVersatileViewItem *item ); // QIconView 156 void itemRenamed( OVersatileViewItem *item ); // QIconView
154 */ 157 */
155 158
156 //==============================================================================================// 159 //==============================================================================================//
157 // "Derived" API - Case 1: Methods existing either only in QListView or only in QIconView 160 // "Derived" API - Case 1: Methods existing either only in QListView or only in QIconView
158 //==============================================================================================// 161 //==============================================================================================//
159 162
160public: 163public:
161 164
162 /* 165 /*
163 enum Arrangement { // QIconView 166 enum Arrangement { // QIconView
164 LeftToRight = 0, 167 LeftToRight = 0,
165 TopToBottom 168 TopToBottom
166 }; 169 };
167 enum ResizeMode { // QIconView 170 enum ResizeMode { // QIconView
168 Fixed = 0, 171 Fixed = 0,
169 Adjust 172 Adjust
170 }; 173 };
171 enum ItemTextPos { // QIconView 174 enum ItemTextPos { // QIconView
172 Bottom = 0, 175 Bottom = 0,
173 Right 176 Right
174 }; 177 };
175 */ 178 */
176 179
177 // 180 //
178 // only in QListView 181 // only in QListView
179 // 182 //
180 183
181 int treeStepSize() const; // QListView 184 int treeStepSize() const; // QListView
182 virtual void setTreeStepSize( int ); // QListView 185 virtual void setTreeStepSize( int ); // QListView
183 186
184 QHeader * header() const; // QListView 187 QHeader * header() const; // QListView
185 188
186 virtual int addColumn( const QString &label, int size = -1); // QListView 189 virtual int addColumn( const QString &label, int size = -1); // QListView
187 virtual int addColumn( const QIconSet& iconset, const QString &label, int size = -1); // QListView 190 virtual int addColumn( const QIconSet& iconset, const QString &label, int size = -1); // QListView
188 void removeColumn( int index ); // #### make virtual in next major release! // QListView 191 void removeColumn( int index ); // #### make virtual in next major release! // QListView
189 virtual void setColumnText( int column, const QString &label ); // QListView 192 virtual void setColumnText( int column, const QString &label ); // QListView
190 virtual void setColumnText( int column, const QIconSet& iconset, const QString &label ); // QListView 193 virtual void setColumnText( int column, const QIconSet& iconset, const QString &label ); // QListView
191 QString columnText( int column ) const; // QListView 194 QString columnText( int column ) const; // QListView
192 virtual void setColumnWidth( int column, int width ); // QListView 195 virtual void setColumnWidth( int column, int width ); // QListView
193 int columnWidth( int column ) const; // QListView 196 int columnWidth( int column ) const; // QListView
194 enum WidthMode { Manual, Maximum }; // QListView 197 enum WidthMode { Manual, Maximum }; // QListView
195 virtual void setColumnWidthMode( int column, WidthMode ); // QListView 198 virtual void setColumnWidthMode( int column, WidthMode ); // QListView
196 WidthMode columnWidthMode( int column ) const; // QListView 199 WidthMode columnWidthMode( int column ) const; // QListView
197 int columns() const; // QListView 200 int columns() const; // QListView
198 201
199 virtual void setColumnAlignment( int, int ); // QListView 202 virtual void setColumnAlignment( int, int ); // QListView
200 int columnAlignment( int ) const; // QListView 203 int columnAlignment( int ) const; // QListView
201 204
202 OVersatileViewItem * itemAt( const QPoint & screenPos ) const; // QListView 205 OVersatileViewItem * itemAt( const QPoint & screenPos ) const; // QListView
203 QRect itemRect( const OVersatileViewItem * ) const; // QListView 206 QRect itemRect( const OVersatileViewItem * ) const; // QListView
204 int itemPos( const OVersatileViewItem * ); // QListView 207 int itemPos( const OVersatileViewItem * ); // QListView
205 208
206 bool isSelected( const OVersatileViewItem * ) const; // QListView // also in QIconViewItem but not in QIconView *shrug* 209 bool isSelected( const OVersatileViewItem * ) const; // QListView // also in QIconViewItem but not in QIconView *shrug*
207 210
208 virtual void setMultiSelection( bool enable ); // QListView 211 virtual void setMultiSelection( bool enable ); // QListView
209 bool isMultiSelection() const; // QListView 212 bool isMultiSelection() const; // QListView
210 213
211 OVersatileViewItem * selectedItem() const; // QListView 214 OVersatileViewItem * selectedItem() const; // QListView
212 virtual void setOpen( OVersatileViewItem *, bool ); // QListView 215 virtual void setOpen( OVersatileViewItem *, bool ); // QListView
213 bool isOpen( const OVersatileViewItem * ) const; // QListView 216 bool isOpen( const OVersatileViewItem * ) const; // QListView
214 217
215 OVersatileViewItem * firstChild() const; // QListView 218 OVersatileViewItem * firstChild() const; // QListView
216 int childCount() const; // QListView 219 int childCount() const; // QListView
217 220
218 virtual void setAllColumnsShowFocus( bool ); // QListView 221 virtual void setAllColumnsShowFocus( bool ); // QListView
219 bool allColumnsShowFocus() const; // QListView 222 bool allColumnsShowFocus() const; // QListView
220 223
221 virtual void setItemMargin( int ); // QListView 224 virtual void setItemMargin( int ); // QListView
222 int itemMargin() const; // QListView 225 int itemMargin() const; // QListView
223 226
224 virtual void setRootIsDecorated( bool ); // QListView 227 virtual void setRootIsDecorated( bool ); // QListView
225 bool rootIsDecorated() const; // QListView 228 bool rootIsDecorated() const; // QListView
226 229
227 void setShowSortIndicator( bool show ); // QListView 230 void setShowSortIndicator( bool show ); // QListView
228 bool showSortIndicator() const; // QListView 231 bool showSortIndicator() const; // QListView
229 232
230 int index( const OVersatileViewItem *item ) const; // QIconView 233 int index( const OVersatileViewItem *item ) const; // QIconView
231 234
232 public slots: 235 public slots:
233 void triggerUpdate(); // QListView 236 void triggerUpdate(); // QListView
234 237
235 signals: 238 signals:
236 void expanded( OVersatileViewItem *item ); // QListView 239 void expanded( OVersatileViewItem *item ); // QListView
237 void collapsed( OVersatileViewItem *item ); // QListView 240 void collapsed( OVersatileViewItem *item ); // QListView
238 241
239 // 242 //
240 // only in QIconView 243 // only in QIconView
241 // 244 //
242 245
243 public: 246 public:
244 uint count() const; // QIconView 247 uint count() const; // QIconView
245 248
246 OVersatileViewItem *firstItem() const; // QIconView 249 OVersatileViewItem *firstItem() const; // QIconView
247 OVersatileViewItem *lastItem() const; // QIconView 250 OVersatileViewItem *lastItem() const; // QIconView
248 251
249 OVersatileViewItem *findItem( const QPoint &pos ) const; // QIconView 252 OVersatileViewItem *findItem( const QPoint &pos ) const; // QIconView
250 OVersatileViewItem *findItem( const QString &text ) const; // QIconView 253 OVersatileViewItem *findItem( const QString &text ) const; // QIconView
251 254
252 OVersatileViewItem* findFirstVisibleItem( const QRect &r ) const; // QIconView 255 OVersatileViewItem* findFirstVisibleItem( const QRect &r ) const; // QIconView
253 OVersatileViewItem* findLastVisibleItem( const QRect &r ) const; // QIconView 256 OVersatileViewItem* findLastVisibleItem( const QRect &r ) const; // QIconView
254 257
255 virtual void setGridX( int rx ); // QIconView 258 virtual void setGridX( int rx ); // QIconView
256 virtual void setGridY( int ry ); // QIconView 259 virtual void setGridY( int ry ); // QIconView
257 int gridX() const; // QIconView 260 int gridX() const; // QIconView
258 int gridY() const; // QIconView 261 int gridY() const; // QIconView
259 virtual void setSpacing( int sp ); // QIconView 262 virtual void setSpacing( int sp ); // QIconView
260 int spacing() const; // QIconView 263 int spacing() const; // QIconView
261 virtual void setItemTextPos( QIconView::ItemTextPos pos ); // QIconView 264 virtual void setItemTextPos( QIconView::ItemTextPos pos ); // QIconView
262 QIconView::ItemTextPos itemTextPos() const; // QIconView 265 QIconView::ItemTextPos itemTextPos() const; // QIconView
263 virtual void setItemTextBackground( const QBrush &b ); // QIconView 266 virtual void setItemTextBackground( const QBrush &b ); // QIconView
264 QBrush itemTextBackground() const; // QIconView 267 QBrush itemTextBackground() const; // QIconView
265 virtual void setArrangement( QIconView::Arrangement am ); // QIconView 268 virtual void setArrangement( QIconView::Arrangement am ); // QIconView
266 QIconView::Arrangement arrangement() const; // QIconView 269 QIconView::Arrangement arrangement() const; // QIconView
267 virtual void setResizeMode( QIconView::ResizeMode am ); // QIconView 270 virtual void setResizeMode( QIconView::ResizeMode am ); // QIconView
268 QIconView::ResizeMode resizeMode() const; // QIconView 271 QIconView::ResizeMode resizeMode() const; // QIconView
269 virtual void setMaxItemWidth( int w ); // QIconView 272 virtual void setMaxItemWidth( int w ); // QIconView
270 int maxItemWidth() const; // QIconView 273 int maxItemWidth() const; // QIconView
271 virtual void setMaxItemTextLength( int w ); // QIconView 274 virtual void setMaxItemTextLength( int w ); // QIconView
272 int maxItemTextLength() const; // QIconView 275 int maxItemTextLength() const; // QIconView
273 virtual void setAutoArrange( bool b ); // QIconView 276 virtual void setAutoArrange( bool b ); // QIconView
274 bool autoArrange() const; // QIconView 277 bool autoArrange() const; // QIconView
275 virtual void setShowToolTips( bool b ); // QIconView 278 virtual void setShowToolTips( bool b ); // QIconView
276 bool showToolTips() const; // QIconView 279 bool showToolTips() const; // QIconView
277 280
278 bool sorting() const; // QIconView 281 bool sorting() const; // QIconView
279 bool sortDirection() const; // QIconView 282 bool sortDirection() const; // QIconView
280 283
281 virtual void setItemsMovable( bool b ); // QIconView 284 virtual void setItemsMovable( bool b ); // QIconView
282 bool itemsMovable() const; // QIconView 285 bool itemsMovable() const; // QIconView
283 virtual void setWordWrapIconText( bool b ); // QIconView 286 virtual void setWordWrapIconText( bool b ); // QIconView
284 bool wordWrapIconText() const; // QIconView 287 bool wordWrapIconText() const; // QIconView
285 288
286 public slots: 289 public slots:
287 virtual void arrangeItemsInGrid( const QSize &grid, bool update = TRUE ); // QIconView 290 virtual void arrangeItemsInGrid( const QSize &grid, bool update = TRUE ); // QIconView
288 virtual void arrangeItemsInGrid( bool update = TRUE ); // QIconView 291 virtual void arrangeItemsInGrid( bool update = TRUE ); // QIconView
289 virtual void updateContents(); // QIconView 292 virtual void updateContents(); // QIconView
290 293
291 signals: 294 signals:
292 /*#ifndef QT_NO_DRAGANDDROP 295 /*#ifndef QT_NO_DRAGANDDROP
293 void dropped( QDropEvent *e, const QValueList<QIconDragItem> &lst ); // QIconView 296 void dropped( QDropEvent *e, const QValueList<QIconDragItem> &lst ); // QIconView
294 #endif 297 #endif
295 */ 298 */
296 void moved(); // QIconView 299 void moved(); // QIconView
297 void itemRenamed( OVersatileViewItem *item, const QString & ); // QIconView 300 void itemRenamed( OVersatileViewItem *item, const QString & ); // QIconView
298 void itemRenamed( OVersatileViewItem *item ); // QIconView 301 void itemRenamed( OVersatileViewItem *item ); // QIconView
299 302
300 //==============================================================================================// 303 //==============================================================================================//
301 // "Derived" API - Case 2: Methods existing in QListView and QIconView with the same signatures 304 // "Derived" API - Case 2: Methods existing in QListView and QIconView with the same signatures
302 //==============================================================================================// 305 //==============================================================================================//
303 306
304 public: 307 public:
305 enum SelectionMode { 308 enum SelectionMode {
306 Single = 0, 309 Single = 0,
307 Multi, 310 Multi,
308 Extended, 311 Extended,
309 NoSelection 312 NoSelection
310 }; 313 };
311 314
312 virtual void clear(); 315 virtual void clear();
313 316
314 virtual void setFont( const QFont & ); 317 virtual void setFont( const QFont & );
315 virtual void setPalette( const QPalette & ); 318 virtual void setPalette( const QPalette & );
316 319
317 virtual void takeItem( OVersatileViewItem * ); 320 virtual void takeItem( OVersatileViewItem * );
318 321
319 void setSelectionMode( SelectionMode mode ); 322 void setSelectionMode( SelectionMode mode );
320 SelectionMode selectionMode() const; 323 SelectionMode selectionMode() const;
321 324
322 virtual void selectAll( bool select ); 325 virtual void selectAll( bool select );
323 virtual void clearSelection(); 326 virtual void clearSelection();
324 virtual void invertSelection(); 327 virtual void invertSelection();
325 328
326 void ensureItemVisible( const OVersatileViewItem * ); 329 void ensureItemVisible( const OVersatileViewItem * );
327 virtual void repaintItem( const OVersatileViewItem * ) const; 330 virtual void repaintItem( const OVersatileViewItem * ) const;
328 331
329 virtual void setCurrentItem( OVersatileViewItem * ); 332 virtual void setCurrentItem( OVersatileViewItem * );
330 OVersatileViewItem * currentItem() const; 333 OVersatileViewItem * currentItem() const;
331 334
332 // bool eventFilter( QObject * o, QEvent * ); // use QWidgetStack implementation 335 // bool eventFilter( QObject * o, QEvent * ); // use QWidgetStack implementation
333 336
334 // QSize minimumSizeHint() const; // use QWidgetStack implementation 337 // QSize minimumSizeHint() const; // use QWidgetStack implementation
335 // QSizePolicy sizePolicy() const; // use QWidgetStack implementation 338 // QSizePolicy sizePolicy() const; // use QWidgetStack implementation
336 // QSize sizeHint() const; // use QWidgetStack implementation 339 // QSize sizeHint() const; // use QWidgetStack implementation
337 340
338 signals: 341 signals:
339 void selectionChanged(); 342 void selectionChanged();
340 void selectionChanged( OVersatileViewItem * ); 343 void selectionChanged( OVersatileViewItem * );
341 void currentChanged( OVersatileViewItem * ); 344 void currentChanged( OVersatileViewItem * );
342 void clicked( OVersatileViewItem * ); 345 void clicked( OVersatileViewItem * );
343 void pressed( OVersatileViewItem * ); 346 void pressed( OVersatileViewItem * );
344 347
345 void doubleClicked( OVersatileViewItem * ); 348 void doubleClicked( OVersatileViewItem * );
346 void returnPressed( OVersatileViewItem * ); 349 void returnPressed( OVersatileViewItem * );
347 350
348 void onItem( OVersatileViewItem * ); 351 void onItem( OVersatileViewItem * );
349 void onViewport(); 352 void onViewport();
350 353
351 //==============================================================================================// 354 //==============================================================================================//
352 // "Derived" API - Case 2: Methods existing in QListView and QIconView with differing signatures 355 // "Derived" API - Case 2: Methods existing in QListView and QIconView with differing signatures
353 //==============================================================================================// 356 //==============================================================================================//
354 357
355 /* 358 /*
356 359
357 public: 360 public:
358 virtual void insertItem( OVersatileViewItem * ); // QListView 361 virtual void insertItem( OVersatileViewItem * ); // QListView
359 virtual void insertItem( OVersatileViewItem *item, OVersatileViewItem *after = 0L ); // QIconView 362 virtual void insertItem( OVersatileViewItem *item, OVersatileViewItem *after = 0L ); // QIconView
360 363
361 virtual void setSelected( OVersatileViewItem *, bool ); // QListView 364 virtual void setSelected( OVersatileViewItem *, bool ); // QListView
362 virtual void setSelected( OVersatileViewItem *item, bool s, bool cb = FALSE ); // QIconView 365 virtual void setSelected( OVersatileViewItem *item, bool s, bool cb = FALSE ); // QIconView
363 366
364 virtual void setSorting( int column, bool increasing = TRUE ); // QListView 367 virtual void setSorting( int column, bool increasing = TRUE ); // QListView
365 void setSorting( bool sort, bool ascending = TRUE ); // QIconView 368 void setSorting( bool sort, bool ascending = TRUE ); // QIconView
366 369
367 void sort(); // #### make virtual in next major release // QListView 370 void sort(); // #### make virtual in next major release // QListView
368 virtual void sort( bool ascending = TRUE ); // QIconView 371 virtual void sort( bool ascending = TRUE ); // QIconView
369 372
370 */ 373 */
371 374
372 signals: 375 signals:
373 void clicked( OVersatileViewItem *, const QPoint &, int ); // QListView 376 void clicked( OVersatileViewItem *, const QPoint &, int ); // QListView
374 void clicked( OVersatileViewItem *, const QPoint & ); // QIconView 377 void clicked( OVersatileViewItem *, const QPoint & ); // QIconView
375 378
376 void pressed( OVersatileViewItem *, const QPoint &, int ); // QListView 379 void pressed( OVersatileViewItem *, const QPoint &, int ); // QListView
377 void pressed( OVersatileViewItem *, const QPoint & ); // QIconView 380 void pressed( OVersatileViewItem *, const QPoint & ); // QIconView
378 381
379 void rightButtonClicked( OVersatileViewItem* item, const QPoint& pos ); // QIconView 382 void rightButtonClicked( OVersatileViewItem* item, const QPoint& pos ); // QIconView
380 void rightButtonClicked( OVersatileViewItem *, const QPoint&, int ); // QListView 383 void rightButtonClicked( OVersatileViewItem *, const QPoint&, int ); // QListView
381 384
382 void rightButtonPressed( OVersatileViewItem* item, const QPoint& pos ); // QIconView 385 void rightButtonPressed( OVersatileViewItem* item, const QPoint& pos ); // QIconView
383 void rightButtonPressed( OVersatileViewItem *, const QPoint&, int ); // QListView 386 void rightButtonPressed( OVersatileViewItem *, const QPoint&, int ); // QListView
384 387
385 void mouseButtonPressed( int, OVersatileViewItem *, const QPoint& , int ); // QListView 388 void mouseButtonPressed( int, OVersatileViewItem *, const QPoint& , int ); // QListView
386 void mouseButtonPressed( int button, OVersatileViewItem* item, const QPoint& pos ); // QIconView 389 void mouseButtonPressed( int button, OVersatileViewItem* item, const QPoint& pos ); // QIconView
387 390
388 void mouseButtonClicked( int, OVersatileViewItem *, const QPoint&, int ); // QListView 391 void mouseButtonClicked( int, OVersatileViewItem *, const QPoint&, int ); // QListView
389 void mouseButtonClicked( int button, OVersatileViewItem* item, const QPoint& pos ); // QIconView 392 void mouseButtonClicked( int button, OVersatileViewItem* item, const QPoint& pos ); // QIconView
390 393
391}; 394};
392 395
396}
397}
393#endif 398#endif
394 399
diff --git a/libopie2/opieui/oversatileviewitem.cpp b/libopie2/opieui/oversatileviewitem.cpp
index 66de8eb..03c6738 100644
--- a/libopie2/opieui/oversatileviewitem.cpp
+++ b/libopie2/opieui/oversatileviewitem.cpp
@@ -1,132 +1,134 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4 =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4 =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#include <opie2/oversatileviewitem.h> 31#include <opie2/oversatileviewitem.h>
32#include <opie2/oversatileview.h> 32#include <opie2/oversatileview.h>
33 33
34using namespace Opie::Ui;
35
34OVersatileViewItem::OVersatileViewItem( OVersatileView * parent ) 36OVersatileViewItem::OVersatileViewItem( OVersatileView * parent )
35 :OListViewItem( parent->_listview ), QIconViewItem( parent->_iconview ), 37 :OListViewItem( parent->_listview ), QIconViewItem( parent->_iconview ),
36 _versatileview( parent ) 38 _versatileview( parent )
37{ 39{
38 init(); 40 init();
39} 41}
40 42
41OVersatileViewItem::OVersatileViewItem( OVersatileView * parent, OVersatileViewItem * after ) 43OVersatileViewItem::OVersatileViewItem( OVersatileView * parent, OVersatileViewItem * after )
42 :OListViewItem( parent->_listview, after ), QIconViewItem( parent->_iconview, after ), 44 :OListViewItem( parent->_listview, after ), QIconViewItem( parent->_iconview, after ),
43 _versatileview( parent ) 45 _versatileview( parent )
44{ 46{
45 init(); 47 init();
46} 48}
47 49
48OVersatileViewItem::OVersatileViewItem( OVersatileView * parent, 50OVersatileViewItem::OVersatileViewItem( OVersatileView * parent,
49 QString a, QString b, QString c, QString d, 51 QString a, QString b, QString c, QString d,
50 QString e, QString f, QString g, QString h ) 52 QString e, QString f, QString g, QString h )
51 :OListViewItem( parent->_listview, a, b, c, d, e, f, g, h ), 53 :OListViewItem( parent->_listview, a, b, c, d, e, f, g, h ),
52 QIconViewItem( parent->_iconview, a ), 54 QIconViewItem( parent->_iconview, a ),
53 _versatileview( parent ) 55 _versatileview( parent )
54{ 56{
55 init(); 57 init();
56} 58}
57 59
58OVersatileViewItem::OVersatileViewItem( OVersatileView * parent, OVersatileViewItem* after, 60OVersatileViewItem::OVersatileViewItem( OVersatileView * parent, OVersatileViewItem* after,
59 QString a, QString b, QString c, QString d, 61 QString a, QString b, QString c, QString d,
60 QString e, QString f, QString g, QString h ) 62 QString e, QString f, QString g, QString h )
61 :OListViewItem( parent->_listview, after, a, b, c, d, e, f, g, h ), 63 :OListViewItem( parent->_listview, after, a, b, c, d, e, f, g, h ),
62 QIconViewItem( parent->_iconview, after, a ), 64 QIconViewItem( parent->_iconview, after, a ),
63 _versatileview( parent ) 65 _versatileview( parent )
64{ 66{
65 init(); 67 init();
66} 68}
67 69
68OVersatileViewItem::OVersatileViewItem( OVersatileViewItem * parent, 70OVersatileViewItem::OVersatileViewItem( OVersatileViewItem * parent,
69 QString a, QString b, QString c, QString d, 71 QString a, QString b, QString c, QString d,
70 QString e, QString f, QString g, QString h ) 72 QString e, QString f, QString g, QString h )
71 :OListViewItem( parent, a, b, c, d, e, f, g, h ), 73 :OListViewItem( parent, a, b, c, d, e, f, g, h ),
72 QIconViewItem( parent->_versatileview->_iconview, a ), 74 QIconViewItem( parent->_versatileview->_iconview, a ),
73 _versatileview( parent->_versatileview ) 75 _versatileview( parent->_versatileview )
74{ 76{
75 init(); 77 init();
76} 78}
77 79
78OVersatileViewItem::OVersatileViewItem( OVersatileViewItem * parent, OVersatileViewItem* after, 80OVersatileViewItem::OVersatileViewItem( OVersatileViewItem * parent, OVersatileViewItem* after,
79 QString a, QString b, QString c, QString d, 81 QString a, QString b, QString c, QString d,
80 QString e, QString f, QString g, QString h ) 82 QString e, QString f, QString g, QString h )
81 :OListViewItem( parent, after, a, b, c, d, e, f, g, h ), 83 :OListViewItem( parent, after, a, b, c, d, e, f, g, h ),
82 QIconViewItem( parent->_versatileview->_iconview, after, a ), 84 QIconViewItem( parent->_versatileview->_iconview, after, a ),
83 _versatileview( parent->_versatileview ) 85 _versatileview( parent->_versatileview )
84{ 86{
85 init(); 87 init();
86} 88}
87 89
88OVersatileViewItem::~OVersatileViewItem() 90OVersatileViewItem::~OVersatileViewItem()
89{ 91{
90} 92}
91 93
92OVersatileView* OVersatileViewItem::versatileView() const 94OVersatileView* OVersatileViewItem::versatileView() const
93{ 95{
94 return _versatileview; 96 return _versatileview;
95} 97}
96 98
97void OVersatileViewItem::init() 99void OVersatileViewItem::init()
98{ 100{
99 if ( !firstChild() ) 101 if ( !firstChild() )
100 { 102 {
101 // I'm a sweet yellow and browne autumn leaf 103 // I'm a sweet yellow and browne autumn leaf
102 104
103 OListViewItem::setPixmap( 0, _versatileview->_treeleaf ); 105 OListViewItem::setPixmap( 0, _versatileview->_treeleaf );
104 QIconViewItem::setPixmap( _versatileview->_iconleaf ); 106 QIconViewItem::setPixmap( _versatileview->_iconleaf );
105 } 107 }
106 else 108 else
107 { 109 {
108 // I'm a node and I have a little baby child 110 // I'm a node and I have a little baby child
109 111
110 if ( isOpen() ) 112 if ( isOpen() )
111 { 113 {
112 OListViewItem::setPixmap( 0, _versatileview->_treeopened ); 114 OListViewItem::setPixmap( 0, _versatileview->_treeopened );
113 QIconViewItem::setPixmap( _versatileview->_iconopened ); 115 QIconViewItem::setPixmap( _versatileview->_iconopened );
114 } 116 }
115 else 117 else
116 { 118 {
117 OListViewItem::setPixmap( 0, _versatileview->_treeclosed ); 119 OListViewItem::setPixmap( 0, _versatileview->_treeclosed );
118 QIconViewItem::setPixmap( _versatileview->_iconclosed ); 120 QIconViewItem::setPixmap( _versatileview->_iconclosed );
119 } 121 }
120 } 122 }
121 123
122} 124}
123 125
124void OVersatileViewItem::setRenameEnabled( bool allow ) 126void OVersatileViewItem::setRenameEnabled( bool allow )
125{ 127{
126 #if (QT_VERSION >= 0x030000) 128 #if (QT_VERSION >= 0x030000)
127 OListViewItem::setRenameEnabled( 0, allow ); // TODO: Backport to Qt-Embedded 2.x? 129 OListViewItem::setRenameEnabled( 0, allow ); // TODO: Backport to Qt-Embedded 2.x?
128 #endif 130 #endif
129 QIconViewItem::setRenameEnabled( allow ); 131 QIconViewItem::setRenameEnabled( allow );
130} 132}
131 133
132 134
diff --git a/libopie2/opieui/oversatileviewitem.h b/libopie2/opieui/oversatileviewitem.h
index ee8ee20..c4977af 100644
--- a/libopie2/opieui/oversatileviewitem.h
+++ b/libopie2/opieui/oversatileviewitem.h
@@ -1,100 +1,105 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#ifndef OVERSATILEVIEWITEM_H 32#ifndef OVERSATILEVIEWITEM_H
33#define OVERSATILEVIEWITEM_H 33#define OVERSATILEVIEWITEM_H
34 34
35/* QT */ 35/* QT */
36 36
37#include <qiconview.h> 37#include <qiconview.h>
38 38
39/* OPIE */ 39/* OPIE */
40 40
41#include <opie2/olistview.h> 41#include <opie2/olistview.h>
42 42
43namespace Opie {
44namespace Ui {
45
43class OVersatileView; 46class OVersatileView;
44 47
45class OVersatileViewItem : public OListViewItem, public QIconViewItem 48class OVersatileViewItem : public OListViewItem, public QIconViewItem
46{ 49{
47 public: 50 public:
48 OVersatileViewItem( OVersatileView * parent ); 51 OVersatileViewItem( OVersatileView * parent );
49 52
50 OVersatileViewItem( OVersatileView * parent, OVersatileViewItem * after ); 53 OVersatileViewItem( OVersatileView * parent, OVersatileViewItem * after );
51 54
52 OVersatileViewItem( OVersatileViewItem * parent, OVersatileViewItem * after ); 55 OVersatileViewItem( OVersatileViewItem * parent, OVersatileViewItem * after );
53 56
54 OVersatileViewItem( OVersatileView * parent, QString, 57 OVersatileViewItem( OVersatileView * parent, QString,
55 QString = QString::null, QString = QString::null, 58 QString = QString::null, QString = QString::null,
56 QString = QString::null, QString = QString::null, 59 QString = QString::null, QString = QString::null,
57 QString = QString::null, QString = QString::null, 60 QString = QString::null, QString = QString::null,
58 QString = QString::null ); 61 QString = QString::null );
59 62
60 OVersatileViewItem( OVersatileViewItem * parent, QString, 63 OVersatileViewItem( OVersatileViewItem * parent, QString,
61 QString = QString::null, QString = QString::null, 64 QString = QString::null, QString = QString::null,
62 QString = QString::null, QString = QString::null, 65 QString = QString::null, QString = QString::null,
63 QString = QString::null, QString = QString::null, 66 QString = QString::null, QString = QString::null,
64 QString = QString::null ); 67 QString = QString::null );
65 68
66 OVersatileViewItem( OVersatileView * parent, OVersatileViewItem * after, QString, 69 OVersatileViewItem( OVersatileView * parent, OVersatileViewItem * after, QString,
67 QString = QString::null, QString = QString::null, 70 QString = QString::null, QString = QString::null,
68 QString = QString::null, QString = QString::null, 71 QString = QString::null, QString = QString::null,
69 QString = QString::null, QString = QString::null, 72 QString = QString::null, QString = QString::null,
70 QString = QString::null ); 73 QString = QString::null );
71 74
72 OVersatileViewItem( OVersatileViewItem * parent, OVersatileViewItem * after, QString, 75 OVersatileViewItem( OVersatileViewItem * parent, OVersatileViewItem * after, QString,
73 QString = QString::null, QString = QString::null, 76 QString = QString::null, QString = QString::null,
74 QString = QString::null, QString = QString::null, 77 QString = QString::null, QString = QString::null,
75 QString = QString::null, QString = QString::null, 78 QString = QString::null, QString = QString::null,
76 QString = QString::null ); 79 QString = QString::null );
77 80
78 virtual ~OVersatileViewItem(); 81 virtual ~OVersatileViewItem();
79 82
80 OVersatileView* versatileView() const; 83 OVersatileView* versatileView() const;
81 84
82 // TODO: Implement the remaining constructors from QIconView 85 // TODO: Implement the remaining constructors from QIconView
83 86
84 /* OIconViewItem( QIconView *parent, const QString &text, const QPixmap &icon ); 87 /* OIconViewItem( QIconView *parent, const QString &text, const QPixmap &icon );
85 OIconViewItem( QIconView *parent, QIconViewItem *after, const QString &text, const QPixmap &icon ); 88 OIconViewItem( QIconView *parent, QIconViewItem *after, const QString &text, const QPixmap &icon );
86 */ 89 */
87 90
88 virtual void setRenameEnabled( bool ); 91 virtual void setRenameEnabled( bool );
89 92
90 // TODO: Implement the remaining method multiplexers 93 // TODO: Implement the remaining method multiplexers
91 94
92 private: 95 private:
93 OVersatileView* _versatileview; 96 OVersatileView* _versatileview;
94 97
95 private: 98 private:
96 void init(); 99 void init();
97 100
98}; 101};
99 102
103}
104}
100#endif 105#endif
diff --git a/libopie2/opieui/owait.cpp b/libopie2/opieui/owait.cpp
index 8bb4ed6..9519888 100644
--- a/libopie2/opieui/owait.cpp
+++ b/libopie2/opieui/owait.cpp
@@ -1,110 +1,112 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3              Copyright (C) 2003 Maximilian Reiss <harlekin@handhelds.org> 3              Copyright (C) 2003 Maximilian Reiss <harlekin@handhelds.org>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#include "owait.h" 31#include "owait.h"
32 32
33/* OPIE */ 33/* OPIE */
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36 36
37/* QT */ 37/* QT */
38#include <qlayout.h> 38#include <qlayout.h>
39#include <qpainter.h> 39#include <qpainter.h>
40 40
41using namespace Opie::Ui;
42
41static int frame = 0; 43static int frame = 0;
42 44
43/** 45/**
44 * This will construct a modal dialog. 46 * This will construct a modal dialog.
45 * 47 *
46 * The default timer length is 10. 48 * The default timer length is 10.
47 * 49 *
48 * @param parent The parent of the widget 50 * @param parent The parent of the widget
49 * @param msg The name of the object 51 * @param msg The name of the object
50 * @param dispIcon Display Icon? 52 * @param dispIcon Display Icon?
51 */ 53 */
52OWait::OWait( QWidget *parent, const char* msg, bool dispIcon ) 54OWait::OWait( QWidget *parent, const char* msg, bool dispIcon )
53 :QDialog( parent, msg, TRUE, WStyle_Customize ) 55 :QDialog( parent, msg, TRUE, WStyle_Customize )
54{ 56{
55 57
56 58
57 QHBoxLayout * hbox = new QHBoxLayout( this ); 59 QHBoxLayout * hbox = new QHBoxLayout( this );
58 60
59 m_lb = new QLabel( this ); 61 m_lb = new QLabel( this );
60 m_lb->setBackgroundMode ( NoBackground ); 62 m_lb->setBackgroundMode ( NoBackground );
61 63
62 hbox->addWidget( m_lb ); 64 hbox->addWidget( m_lb );
63 hbox->activate(); 65 hbox->activate();
64 66
65 m_pix = Resource::loadPixmap( "BigBusy" ); 67 m_pix = Resource::loadPixmap( "BigBusy" );
66 m_aniSize = m_pix.height(); 68 m_aniSize = m_pix.height();
67 resize( m_aniSize, m_aniSize ); 69 resize( m_aniSize, m_aniSize );
68 70
69 m_timerLength = 10; 71 m_timerLength = 10;
70 72
71 m_waitTimer = new QTimer( this ); 73 m_waitTimer = new QTimer( this );
72 connect( m_waitTimer, SIGNAL( timeout() ), this, SLOT( hide() ) ); 74 connect( m_waitTimer, SIGNAL( timeout() ), this, SLOT( hide() ) );
73} 75}
74 76
75void OWait::timerEvent( QTimerEvent * ) 77void OWait::timerEvent( QTimerEvent * )
76{ 78{
77 frame = ( ++frame ) % 4; 79 frame = ( ++frame ) % 4;
78 repaint(); 80 repaint();
79} 81}
80 82
81void OWait::paintEvent( QPaintEvent * ) 83void OWait::paintEvent( QPaintEvent * )
82{ 84{
83 QPainter p( m_lb ); 85 QPainter p( m_lb );
84 p.drawPixmap( 0, 0, m_pix, m_aniSize * frame, 0, m_aniSize, m_aniSize ); 86 p.drawPixmap( 0, 0, m_pix, m_aniSize * frame, 0, m_aniSize, m_aniSize );
85} 87}
86 88
87void OWait::show() 89void OWait::show()
88{ 90{
89 91
90 move( ( ( qApp->desktop() ->width() ) / 2 ) - ( m_aniSize / 2 ), ( ( qApp->desktop() ->height() ) / 2 ) - ( m_aniSize / 2 ) ); 92 move( ( ( qApp->desktop() ->width() ) / 2 ) - ( m_aniSize / 2 ), ( ( qApp->desktop() ->height() ) / 2 ) - ( m_aniSize / 2 ) );
91 startTimer( 300 ); 93 startTimer( 300 );
92 m_waitTimer->start( m_timerLength * 1000, true ); 94 m_waitTimer->start( m_timerLength * 1000, true );
93 QDialog::show(); 95 QDialog::show();
94} 96}
95 97
96void OWait::hide() 98void OWait::hide()
97{ 99{
98 killTimers(); 100 killTimers();
99 m_waitTimer->stop(); 101 m_waitTimer->stop();
100 frame = 0; 102 frame = 0;
101 QDialog::hide(); 103 QDialog::hide();
102} 104}
103 105
104void OWait::setTimerLength( int length ) 106void OWait::setTimerLength( int length )
105{ 107{
106 m_timerLength = length; 108 m_timerLength = length;
107} 109}
108 110
109OWait::~OWait() 111OWait::~OWait()
110{} 112{}
diff --git a/libopie2/opieui/owait.h b/libopie2/opieui/owait.h
index 3267064..03c33e4 100644
--- a/libopie2/opieui/owait.h
+++ b/libopie2/opieui/owait.h
@@ -1,86 +1,90 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3              Copyright (C) 2003 Maximilian Reiss <harlekin@handhelds.org> 3              Copyright (C) 2003 Maximilian Reiss <harlekin@handhelds.org>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#ifndef OWAIT_H 31#ifndef OWAIT_H
32#define OWAIT_H 32#define OWAIT_H
33 33
34/* QT */ 34/* QT */
35#include <qdialog.h> 35#include <qdialog.h>
36#include <qlabel.h> 36#include <qlabel.h>
37#include <qpixmap.h> 37#include <qpixmap.h>
38#include <qtimer.h> 38#include <qtimer.h>
39 39
40
41namespace Opie {
42namespace Ui {
40/** 43/**
41 * This class displays a animated waiting icon in the middle of the screen. 44 * This class displays a animated waiting icon in the middle of the screen.
42 * 45 *
43 * @short modal hour glass dialog 46 * @short modal hour glass dialog
44 * @see QDialog 47 * @see QDialog
45 * @author Maximilian Reiß 48 * @author Maximilian Reiß
46 */ 49 */
47class OWait : public QDialog 50class OWait : public QDialog
48{ 51{
49 Q_OBJECT 52 Q_OBJECT
50 53
51 public: 54 public:
52 OWait( QWidget *parent = 0, const char* name = 0, bool dispIcon = TRUE ); 55 OWait( QWidget *parent = 0, const char* name = 0, bool dispIcon = TRUE );
53 ~OWait(); 56 ~OWait();
54 57
55 /** 58 /**
56 * reimplemented for control reasons 59 * reimplemented for control reasons
57 */ 60 */
58 void show(); 61 void show();
59 62
60 /** 63 /**
61 * Set the time before the icon will be automaticly hidden 64 * Set the time before the icon will be automaticly hidden
62 * The timer will be started once the widget will be shown. 65 * The timer will be started once the widget will be shown.
63 * @param length - time in seconds 66 * @param length - time in seconds
64 */ 67 */
65 void setTimerLength( int length ); 68 void setTimerLength( int length );
66 69
67 public slots: 70 public slots:
68 /** 71 /**
69 * reimplemented for control reasons 72 * reimplemented for control reasons
70 */ 73 */
71 void hide(); 74 void hide();
72 75
73 private: 76 private:
74 void timerEvent( QTimerEvent * ); 77 void timerEvent( QTimerEvent * );
75 void paintEvent( QPaintEvent * ); 78 void paintEvent( QPaintEvent * );
76 79
77 QPixmap m_pix; 80 QPixmap m_pix;
78 QLabel *m_lb; 81 QLabel *m_lb;
79 QTimer *m_waitTimer; 82 QTimer *m_waitTimer;
80 int m_timerLength; 83 int m_timerLength;
81 int m_aniSize; 84 int m_aniSize;
82 class Private; 85 class Private;
83 Private *d; 86 Private *d;
84}; 87};
85 88}
89}
86#endif 90#endif