-rw-r--r-- | libopie2/opieui/big-screen/obigscreen_p.h | 2 | ||||
-rw-r--r-- | libopie2/opieui/big-screen/osplitter.cpp | 6 | ||||
-rw-r--r-- | libopie2/opieui/big-screen/osplitter.h | 6 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 5 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.h | 12 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector_p.h | 2 | ||||
-rw-r--r-- | libopie2/opieui/ofontselector.cpp | 4 | ||||
-rw-r--r-- | libopie2/opieui/ofontselector.h | 4 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.cpp | 41 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.h | 8 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget_p.h | 2 | ||||
-rw-r--r-- | libopie2/opieui/otaskbarapplet.h | 4 |
12 files changed, 49 insertions, 47 deletions
diff --git a/libopie2/opieui/big-screen/obigscreen_p.h b/libopie2/opieui/big-screen/obigscreen_p.h index a85a56c..baa2bbc 100644 --- a/libopie2/opieui/big-screen/obigscreen_p.h +++ b/libopie2/opieui/big-screen/obigscreen_p.h | |||
@@ -1,31 +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 | ||
7 | class QWidget; | 7 | class QWidget; |
8 | 8 | ||
9 | namespace Opie { | 9 | namespace Opie { |
10 | namespace Ui { | 10 | namespace Ui { |
11 | namespace Private{ | 11 | namespace Internal{ |
12 | 12 | ||
13 | struct OSplitterContainer | 13 | struct OSplitterContainer |
14 | { | 14 | { |
15 | bool operator==( const OSplitterContainer& o) const | 15 | bool operator==( const OSplitterContainer& o) const |
16 | { | 16 | { |
17 | if (widget != o.widget ) return false; | 17 | if (widget != o.widget ) return false; |
18 | if (icon != o.icon ) return false; | 18 | if (icon != o.icon ) return false; |
19 | if (name != o.name ) return false; | 19 | if (name != o.name ) return false; |
20 | return true; | 20 | return true; |
21 | } | 21 | } |
22 | QWidget* widget; | 22 | QWidget* widget; |
23 | QString icon; | 23 | QString icon; |
24 | QString name; | 24 | QString name; |
25 | }; | 25 | }; |
26 | 26 | ||
27 | } | 27 | } |
28 | } | 28 | } |
29 | } | 29 | } |
30 | 30 | ||
31 | #endif | 31 | #endif |
diff --git a/libopie2/opieui/big-screen/osplitter.cpp b/libopie2/opieui/big-screen/osplitter.cpp index bcfd3a6..f0287ed 100644 --- a/libopie2/opieui/big-screen/osplitter.cpp +++ b/libopie2/opieui/big-screen/osplitter.cpp | |||
@@ -1,639 +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 | ||
38 | using namespace Opie::Ui; | 38 | using namespace Opie::Ui; |
39 | using namespace Opie::Ui::Private; | 39 | using namespace Opie::Ui::Internal; |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * | 42 | * |
43 | * This is the constructor of OSplitter | 43 | * This is the constructor of OSplitter |
44 | * You might want to call setSizeChange to tell | 44 | * You might want to call setSizeChange to tell |
45 | * OSplitter to change its layout when a specefic | 45 | * OSplitter to change its layout when a specefic |
46 | * mark was crossed. OSplitter sets a default value. | 46 | * mark was crossed. OSplitter sets a default value. |
47 | * | 47 | * |
48 | * You cann add widget with addWidget to the OSplitter. | 48 | * You cann add widget with addWidget to the OSplitter. |
49 | * OSplitter supports also grouping of Splitters where they | 49 | * OSplitter supports also grouping of Splitters where they |
50 | * 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 |
51 | * for email clients like vies but see the example. | 51 | * for email clients like vies but see the example. |
52 | * | 52 | * |
53 | * @param orient The orientation wether to layout horizontal or vertical | 53 | * @param orient The orientation wether to layout horizontal or vertical |
54 | * @param parent The parent of this widget | 54 | * @param parent The parent of this widget |
55 | * @param name The name passed on to QObject | 55 | * @param name The name passed on to QObject |
56 | * @param fl Additional widgets flags passed to QWidget | 56 | * @param fl Additional widgets flags passed to QWidget |
57 | * | 57 | * |
58 | * @short single c'tor of the OSplitter | 58 | * @short single c'tor of the OSplitter |
59 | */ | 59 | */ |
60 | OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl ) | 60 | OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl ) |
61 | : QFrame( parent, name, fl ) | 61 | : QFrame( parent, name, fl ) |
62 | { | 62 | { |
63 | m_orient = orient; | 63 | m_orient = orient; |
64 | m_hbox = 0; | 64 | m_hbox = 0; |
65 | m_size_policy = 330; | 65 | m_size_policy = 330; |
66 | setFontPropagation( AllChildren ); | 66 | setFontPropagation( AllChildren ); |
67 | setPalettePropagation( AllChildren ); | 67 | setPalettePropagation( AllChildren ); |
68 | 68 | ||
69 | /* start by default with the tab widget */ | 69 | /* start by default with the tab widget */ |
70 | m_tabWidget = 0; | 70 | m_tabWidget = 0; |
71 | m_parentTab = 0; | 71 | m_parentTab = 0; |
72 | changeTab(); | 72 | changeTab(); |
73 | 73 | ||
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Destructor destructs this object and cleans up. All child | 78 | * Destructor destructs this object and cleans up. All child |
79 | * widgets will be deleted | 79 | * widgets will be deleted |
80 | * @see addWidget | 80 | * @see addWidget |
81 | */ | 81 | */ |
82 | OSplitter::~OSplitter() | 82 | OSplitter::~OSplitter() |
83 | { | 83 | { |
84 | qWarning("Deleted Splitter"); | 84 | qWarning("Deleted Splitter"); |
85 | m_splitter.setAutoDelete( true ); | 85 | m_splitter.setAutoDelete( true ); |
86 | m_splitter.clear(); | 86 | m_splitter.clear(); |
87 | 87 | ||
88 | delete m_hbox; | 88 | delete m_hbox; |
89 | delete m_tabWidget; | 89 | delete m_tabWidget; |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | /** | 93 | /** |
94 | * Sets the label for the Splitter. This label will be used | 94 | * Sets the label for the Splitter. This label will be used |
95 | * if a parent splitter is arranged as TabWidget but | 95 | * if a parent splitter is arranged as TabWidget but |
96 | * 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() |
97 | * and iconName() gets added. | 97 | * and iconName() gets added. |
98 | * | 98 | * |
99 | * @param name The name of the Label | 99 | * @param name The name of the Label |
100 | */ | 100 | */ |
101 | void OSplitter::setLabel( const QString& name ) | 101 | void OSplitter::setLabel( const QString& name ) |
102 | { | 102 | { |
103 | m_name = name; | 103 | m_name = name; |
104 | } | 104 | } |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * @see setLabel but this is for the icon retrieved by Resource | 107 | * @see setLabel but this is for the icon retrieved by Resource |
108 | * | 108 | * |
109 | * @param name The name of the icon in example ( "zoom" ) | 109 | * @param name The name of the icon in example ( "zoom" ) |
110 | */ | 110 | */ |
111 | void OSplitter::setIconName( const QString& name ) | 111 | void OSplitter::setIconName( const QString& name ) |
112 | { | 112 | { |
113 | m_icon = name; | 113 | m_icon = name; |
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
117 | /** | 117 | /** |
118 | * returns the iconName | 118 | * returns the iconName |
119 | * @see setIconName | 119 | * @see setIconName |
120 | */ | 120 | */ |
121 | QString OSplitter::iconName()const | 121 | QString OSplitter::iconName()const |
122 | { | 122 | { |
123 | return m_icon; | 123 | return m_icon; |
124 | } | 124 | } |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * returns the label set with setLabel | 127 | * returns the label set with setLabel |
128 | * @see setLabel | 128 | * @see setLabel |
129 | */ | 129 | */ |
130 | QString OSplitter::label()const | 130 | QString OSplitter::label()const |
131 | { | 131 | { |
132 | return m_name; | 132 | return m_name; |
133 | } | 133 | } |
134 | 134 | ||
135 | /** | 135 | /** |
136 | * This function sets the size change policy of the splitter. | 136 | * This function sets the size change policy of the splitter. |
137 | * If this size marked is crossed the splitter will relayout. | 137 | * If this size marked is crossed the splitter will relayout. |
138 | * Note: that depending on the set Orientation it'll either look | 138 | * Note: that depending on the set Orientation it'll either look |
139 | * at the width or height. | 139 | * at the width or height. |
140 | * 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 |
141 | * 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 |
142 | * 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 |
143 | * 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 |
144 | * | 144 | * |
145 | * @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. |
146 | * @return void | 146 | * @return void |
147 | */ | 147 | */ |
148 | void OSplitter::setSizeChange( int width_height ) | 148 | void OSplitter::setSizeChange( int width_height ) |
149 | { | 149 | { |
150 | m_size_policy = width_height; | 150 | m_size_policy = width_height; |
151 | QSize sz(width(), height() ); | 151 | QSize sz(width(), height() ); |
152 | QResizeEvent ev(sz, sz ); | 152 | QResizeEvent ev(sz, sz ); |
153 | resizeEvent(&ev); | 153 | resizeEvent(&ev); |
154 | } | 154 | } |
155 | 155 | ||
156 | /** | 156 | /** |
157 | * This functions allows to add another OSplitter and to share | 157 | * This functions allows to add another OSplitter and to share |
158 | * the OTabBar in small screen mode. The ownerships gets transfered. | 158 | * the OTabBar in small screen mode. The ownerships gets transfered. |
159 | * OSplitters are always added after normal widget items | 159 | * OSplitters are always added after normal widget items |
160 | */ | 160 | */ |
161 | void OSplitter::addWidget( OSplitter* split ) | 161 | void OSplitter::addWidget( OSplitter* split ) |
162 | { | 162 | { |
163 | m_splitter.append( split ); | 163 | m_splitter.append( split ); |
164 | 164 | ||
165 | /* | 165 | /* |
166 | * set tab widget | 166 | * set tab widget |
167 | */ | 167 | */ |
168 | if (m_tabWidget ) | 168 | if (m_tabWidget ) |
169 | setTabWidget( m_parentTab ); | 169 | setTabWidget( m_parentTab ); |
170 | else | 170 | else |
171 | { | 171 | { |
172 | OSplitterContainer con; | 172 | OSplitterContainer con; |
173 | con.widget =split; | 173 | con.widget =split; |
174 | addToBox( con ); | 174 | addToBox( con ); |
175 | } | 175 | } |
176 | } | 176 | } |
177 | 177 | ||
178 | /* | 178 | /* |
179 | * If in a tab it should be removed | 179 | * If in a tab it should be removed |
180 | * and if in a hbox the reparent kills it too | 180 | * and if in a hbox the reparent kills it too |
181 | */ | 181 | */ |
182 | /** | 182 | /** |
183 | * This removes the splitter again. You currently need to call this | 183 | * This removes the splitter again. You currently need to call this |
184 | * before you delete or otherwise you can get mem corruption | 184 | * before you delete or otherwise you can get mem corruption |
185 | * or other weird behaviour. | 185 | * or other weird behaviour. |
186 | * Owner ship gets transfered back to you it's current parent | 186 | * Owner ship gets transfered back to you it's current parent |
187 | * is 0 | 187 | * is 0 |
188 | */ | 188 | */ |
189 | void OSplitter::removeWidget( OSplitter* split) | 189 | void OSplitter::removeWidget( OSplitter* split) |
190 | { | 190 | { |
191 | split->setTabWidget( 0 ); | 191 | split->setTabWidget( 0 ); |
192 | split->reparent( 0, 0, QPoint(0, 0) ); | 192 | split->reparent( 0, 0, QPoint(0, 0) ); |
193 | } | 193 | } |
194 | 194 | ||
195 | /** | 195 | /** |
196 | * Adds a widget to the Splitter. The widgets gets inserted | 196 | * Adds a widget to the Splitter. The widgets gets inserted |
197 | * at the end of either the Box or TabWidget. | 197 | * at the end of either the Box or TabWidget. |
198 | * Ownership gets transfered and the widgets gets reparented. | 198 | * Ownership gets transfered and the widgets gets reparented. |
199 | * Note: icon and label is only available on small screensizes | 199 | * Note: icon and label is only available on small screensizes |
200 | * if size is smaller than the mark | 200 | * if size is smaller than the mark |
201 | * 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 |
202 | * a message will be outputtet | 202 | * a message will be outputtet |
203 | * | 203 | * |
204 | * @param wid The widget which will be added | 204 | * @param wid The widget which will be added |
205 | * @param icon The icon of the possible Tab | 205 | * @param icon The icon of the possible Tab |
206 | * @param label The label of the possible Tab | 206 | * @param label The label of the possible Tab |
207 | */ | 207 | */ |
208 | void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& label ) | 208 | void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& label ) |
209 | { | 209 | { |
210 | #ifdef DEBUG | 210 | #ifdef DEBUG |
211 | if (!wid ) | 211 | if (!wid ) |
212 | { | 212 | { |
213 | qWarning("Widget is not valid!"); | 213 | qWarning("Widget is not valid!"); |
214 | return; | 214 | return; |
215 | } | 215 | } |
216 | #endif | 216 | #endif |
217 | OSplitterContainer cont; | 217 | OSplitterContainer cont; |
218 | cont.widget = wid; | 218 | cont.widget = wid; |
219 | cont.icon =icon; | 219 | cont.icon =icon; |
220 | cont.name = label; | 220 | cont.name = label; |
221 | 221 | ||
222 | m_container.append( cont ); | 222 | m_container.append( cont ); |
223 | 223 | ||
224 | /* | 224 | /* |
225 | * | 225 | * |
226 | */ | 226 | */ |
227 | if (!m_splitter.isEmpty() && (m_tabWidget || m_parentTab ) ) | 227 | if (!m_splitter.isEmpty() && (m_tabWidget || m_parentTab ) ) |
228 | setTabWidget( m_parentTab ); | 228 | setTabWidget( m_parentTab ); |
229 | else | 229 | else |
230 | { | 230 | { |
231 | if (m_hbox ) | 231 | if (m_hbox ) |
232 | addToBox( cont ); | 232 | addToBox( cont ); |
233 | else | 233 | else |
234 | addToTab( cont ); | 234 | addToTab( cont ); |
235 | } | 235 | } |
236 | } | 236 | } |
237 | 237 | ||
238 | 238 | ||
239 | /** | 239 | /** |
240 | * Removes the widget from the tab widgets if necessary. | 240 | * Removes the widget from the tab widgets if necessary. |
241 | * OSplitter drops ownership of this widget and the widget | 241 | * OSplitter drops ownership of this widget and the widget |
242 | * will be reparented i tto 0. | 242 | * will be reparented i tto 0. |
243 | * The widget will not be deleted. | 243 | * The widget will not be deleted. |
244 | * | 244 | * |
245 | * @param w The widget to be removed | 245 | * @param w The widget to be removed |
246 | */ | 246 | */ |
247 | void OSplitter::removeWidget( QWidget* w) | 247 | void OSplitter::removeWidget( QWidget* w) |
248 | { | 248 | { |
249 | ContainerList::Iterator it; | 249 | ContainerList::Iterator it; |
250 | for ( it = m_container.begin(); it != m_container.end(); ++it ) | 250 | for ( it = m_container.begin(); it != m_container.end(); ++it ) |
251 | if ( (*it).widget == w ) | 251 | if ( (*it).widget == w ) |
252 | break; | 252 | break; |
253 | 253 | ||
254 | if (it == m_container.end() ) | 254 | if (it == m_container.end() ) |
255 | return; | 255 | return; |
256 | 256 | ||
257 | 257 | ||
258 | /* only tab needs to be removed.. box recognizes it */ | 258 | /* only tab needs to be removed.. box recognizes it */ |
259 | if ( !m_hbox ) | 259 | if ( !m_hbox ) |
260 | removeFromTab( w ); | 260 | removeFromTab( w ); |
261 | 261 | ||
262 | 262 | ||
263 | /* Find reparent it and remove it from our list */ | 263 | /* Find reparent it and remove it from our list */ |
264 | 264 | ||
265 | w->reparent( 0, 0, QPoint(0, 0)); | 265 | w->reparent( 0, 0, QPoint(0, 0)); |
266 | it = m_container.remove( it ); | 266 | it = m_container.remove( it ); |
267 | 267 | ||
268 | } | 268 | } |
269 | 269 | ||
270 | 270 | ||
271 | /** | 271 | /** |
272 | * 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 |
273 | * the tabbar will be changed | 273 | * the tabbar will be changed |
274 | * | 274 | * |
275 | * @param w The widget which will be set the current one | 275 | * @param w The widget which will be set the current one |
276 | */ | 276 | */ |
277 | void OSplitter::setCurrentWidget( QWidget* w) | 277 | void OSplitter::setCurrentWidget( QWidget* w) |
278 | { | 278 | { |
279 | if (m_tabWidget ) | 279 | if (m_tabWidget ) |
280 | m_tabWidget->setCurrentTab( w ); | 280 | m_tabWidget->setCurrentTab( w ); |
281 | // else | 281 | // else |
282 | // m_hbox->setFocus( w ); | 282 | // m_hbox->setFocus( w ); |
283 | 283 | ||
284 | } | 284 | } |
285 | 285 | ||
286 | /** | 286 | /** |
287 | * This is an overloaded member function and only differs in the | 287 | * This is an overloaded member function and only differs in the |
288 | * argument it takes. | 288 | * argument it takes. |
289 | * 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 |
290 | * | 290 | * |
291 | * @param label Label to look for. First match will be taken | 291 | * @param label Label to look for. First match will be taken |
292 | */ | 292 | */ |
293 | void OSplitter::setCurrentWidget( const QString& label ) | 293 | void OSplitter::setCurrentWidget( const QString& label ) |
294 | { | 294 | { |
295 | ContainerList::Iterator it; | 295 | ContainerList::Iterator it; |
296 | for (it = m_container.begin(); it != m_container.end(); ++it ) | 296 | for (it = m_container.begin(); it != m_container.end(); ++it ) |
297 | { | 297 | { |
298 | if ( (*it).name == label ) | 298 | if ( (*it).name == label ) |
299 | { | 299 | { |
300 | setCurrentWidget( (*it).widget ); | 300 | setCurrentWidget( (*it).widget ); |
301 | break; | 301 | break; |
302 | } | 302 | } |
303 | } | 303 | } |
304 | } | 304 | } |
305 | 305 | ||
306 | /** | 306 | /** |
307 | * This will only work when the TabWidget is active | 307 | * This will only work when the TabWidget is active |
308 | * If everything is visible this signal is kindly ignored | 308 | * If everything is visible this signal is kindly ignored |
309 | * @see OTabWidget::setCurrentTab(int) | 309 | * @see OTabWidget::setCurrentTab(int) |
310 | * | 310 | * |
311 | * @param tab The tab to make current | 311 | * @param tab The tab to make current |
312 | */ | 312 | */ |
313 | void OSplitter::setCurrentWidget( int tab ) | 313 | void OSplitter::setCurrentWidget( int tab ) |
314 | { | 314 | { |
315 | if (m_tabWidget ) | 315 | if (m_tabWidget ) |
316 | m_tabWidget->setCurrentTab( tab ); | 316 | m_tabWidget->setCurrentTab( tab ); |
317 | } | 317 | } |
318 | 318 | ||
319 | /** | 319 | /** |
320 | * return the currently activated widget if in tab widget mode | 320 | * return the currently activated widget if in tab widget mode |
321 | * or null because all widgets are visible | 321 | * or null because all widgets are visible |
322 | */ | 322 | */ |
323 | QWidget* OSplitter::currentWidget() const | 323 | QWidget* OSplitter::currentWidget() const |
324 | { | 324 | { |
325 | if (m_tabWidget) | 325 | if (m_tabWidget) |
326 | return m_tabWidget->currentWidget(); | 326 | return m_tabWidget->currentWidget(); |
327 | else if (m_parentTab ) | 327 | else if (m_parentTab ) |
328 | return m_parentTab->currentWidget(); | 328 | return m_parentTab->currentWidget(); |
329 | 329 | ||
330 | return 0l; | 330 | return 0l; |
331 | } | 331 | } |
332 | /* wrong */ | 332 | /* wrong */ |
333 | #if 0 | 333 | #if 0 |
334 | /** | 334 | /** |
335 | * @reimplented for internal reasons | 335 | * @reimplented for internal reasons |
336 | * returns the sizeHint of one of its sub widgets | 336 | * returns the sizeHint of one of its sub widgets |
337 | */ | 337 | */ |
338 | QSize OSplitter::sizeHint()const | 338 | QSize OSplitter::sizeHint()const |
339 | { | 339 | { |
340 | if (m_parentTab ) | 340 | if (m_parentTab ) |
341 | return QFrame::sizeHint(); | 341 | return QFrame::sizeHint(); |
342 | 342 | ||
343 | if (m_hbox ) | 343 | if (m_hbox ) |
344 | return m_hbox->sizeHint(); | 344 | return m_hbox->sizeHint(); |
345 | else | 345 | else |
346 | return m_tabWidget->sizeHint(); | 346 | return m_tabWidget->sizeHint(); |
347 | } | 347 | } |
348 | 348 | ||
349 | QSize OSplitter::minimumSizeHint()const | 349 | QSize OSplitter::minimumSizeHint()const |
350 | { | 350 | { |
351 | if (m_parentTab ) | 351 | if (m_parentTab ) |
352 | return QFrame::minimumSizeHint(); | 352 | return QFrame::minimumSizeHint(); |
353 | if (m_hbox) | 353 | if (m_hbox) |
354 | return m_hbox->sizeHint(); | 354 | return m_hbox->sizeHint(); |
355 | else | 355 | else |
356 | return m_tabWidget->sizeHint(); | 356 | return m_tabWidget->sizeHint(); |
357 | } | 357 | } |
358 | #endif | 358 | #endif |
359 | 359 | ||
360 | /** | 360 | /** |
361 | * @reimplemented for internal reasons | 361 | * @reimplemented for internal reasons |
362 | */ | 362 | */ |
363 | void OSplitter::resizeEvent( QResizeEvent* res ) | 363 | void OSplitter::resizeEvent( QResizeEvent* res ) |
364 | { | 364 | { |
365 | QFrame::resizeEvent( res ); | 365 | QFrame::resizeEvent( res ); |
366 | /* | 366 | /* |
367 | * | 367 | * |
368 | */ | 368 | */ |
369 | // 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() ); |
370 | bool mode = true; | 370 | bool mode = true; |
371 | 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() ); |
372 | if ( res->size().width() > m_size_policy && | 372 | if ( res->size().width() > m_size_policy && |
373 | m_orient == Horizontal ) | 373 | m_orient == Horizontal ) |
374 | { | 374 | { |
375 | changeHBox(); | 375 | changeHBox(); |
376 | mode = false; | 376 | mode = false; |
377 | } | 377 | } |
378 | else if ( (res->size().width() <= m_size_policy && | 378 | else if ( (res->size().width() <= m_size_policy && |
379 | m_orient == Horizontal ) || | 379 | m_orient == Horizontal ) || |
380 | (res->size().height() <= m_size_policy && | 380 | (res->size().height() <= m_size_policy && |
381 | m_orient == Vertical ) ) | 381 | m_orient == Vertical ) ) |
382 | { | 382 | { |
383 | changeTab(); | 383 | changeTab(); |
384 | } | 384 | } |
385 | else if ( res->size().height() > m_size_policy && | 385 | else if ( res->size().height() > m_size_policy && |
386 | m_orient == Vertical ) | 386 | m_orient == Vertical ) |
387 | { | 387 | { |
388 | qWarning("Changng to vbox %s", name() ); | 388 | qWarning("Changng to vbox %s", name() ); |
389 | changeVBox(); | 389 | changeVBox(); |
390 | mode = false; | 390 | mode = false; |
391 | } | 391 | } |
392 | 392 | ||
393 | emit sizeChanged(mode, m_orient ); | 393 | emit sizeChanged(mode, m_orient ); |
394 | } | 394 | } |
395 | 395 | ||
396 | /* | 396 | /* |
397 | * Adds a container to a tab either the parent tab | 397 | * Adds a container to a tab either the parent tab |
398 | * or our own | 398 | * or our own |
399 | */ | 399 | */ |
400 | void OSplitter::addToTab( const Opie::Ui::Private::OSplitterContainer& con ) | 400 | void OSplitter::addToTab( const Opie::Ui::Internal::OSplitterContainer& con ) |
401 | { | 401 | { |
402 | QWidget *wid = con.widget; | 402 | QWidget *wid = con.widget; |
403 | // 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) ); |
404 | if (m_parentTab ) | 404 | if (m_parentTab ) |
405 | m_parentTab->addTab( wid, con.icon, con.name ); | 405 | m_parentTab->addTab( wid, con.icon, con.name ); |
406 | else | 406 | else |
407 | m_tabWidget->addTab( wid, con.icon, con.name ); | 407 | m_tabWidget->addTab( wid, con.icon, con.name ); |
408 | } | 408 | } |
409 | 409 | ||
410 | 410 | ||
411 | /* | 411 | /* |
412 | * adds a container to the box | 412 | * adds a container to the box |
413 | */ | 413 | */ |
414 | void OSplitter::addToBox( const Opie::Ui::Private::OSplitterContainer& con ) | 414 | void OSplitter::addToBox( const Opie::Ui::Internal::OSplitterContainer& con ) |
415 | { | 415 | { |
416 | QWidget* wid = con.widget; | 416 | QWidget* wid = con.widget; |
417 | wid->reparent(m_hbox, 0, QPoint(0, 0) ); | 417 | wid->reparent(m_hbox, 0, QPoint(0, 0) ); |
418 | } | 418 | } |
419 | 419 | ||
420 | 420 | ||
421 | /* | 421 | /* |
422 | * Removes a widget from the tab | 422 | * Removes a widget from the tab |
423 | */ | 423 | */ |
424 | void OSplitter::removeFromTab( QWidget* wid ) | 424 | void OSplitter::removeFromTab( QWidget* wid ) |
425 | { | 425 | { |
426 | if (m_parentTab ) | 426 | if (m_parentTab ) |
427 | m_parentTab->removePage( wid ); | 427 | m_parentTab->removePage( wid ); |
428 | else | 428 | else |
429 | m_tabWidget->removePage( wid ); | 429 | m_tabWidget->removePage( wid ); |
430 | } | 430 | } |
431 | 431 | ||
432 | /* | 432 | /* |
433 | * switches over to a OTabWidget layout | 433 | * switches over to a OTabWidget layout |
434 | * it is recursive | 434 | * it is recursive |
435 | */ | 435 | */ |
436 | void OSplitter::changeTab() | 436 | void OSplitter::changeTab() |
437 | { | 437 | { |
438 | /* if we're the owner of the tab widget */ | 438 | /* if we're the owner of the tab widget */ |
439 | if (m_tabWidget ) | 439 | if (m_tabWidget ) |
440 | { | 440 | { |
441 | raise(); | 441 | raise(); |
442 | show(); | 442 | show(); |
443 | m_tabWidget->setGeometry( frameRect() ); | 443 | m_tabWidget->setGeometry( frameRect() ); |
444 | return; | 444 | return; |
445 | } | 445 | } |
446 | 446 | ||
447 | qWarning(" New Tab Widget %s", name() ); | 447 | qWarning(" New Tab Widget %s", name() ); |
448 | /* | 448 | /* |
449 | * and add all widgets this will reparent them | 449 | * and add all widgets this will reparent them |
450 | * delete m_hbox set it to 0 | 450 | * delete m_hbox set it to 0 |
451 | * | 451 | * |
452 | */ | 452 | */ |
453 | OTabWidget *tab; | 453 | OTabWidget *tab; |
454 | if ( m_parentTab ) | 454 | if ( m_parentTab ) |
455 | { | 455 | { |
456 | hide(); | 456 | hide(); |
457 | tab = m_parentTab; | 457 | tab = m_parentTab; |
458 | /* expensive but needed cause we're called from setTabWidget and resizeEvent*/ | 458 | /* expensive but needed cause we're called from setTabWidget and resizeEvent*/ |
459 | if (!m_container.isEmpty() ) | 459 | if (!m_container.isEmpty() ) |
460 | { | 460 | { |
461 | ContainerList::Iterator it = m_container.begin(); | 461 | ContainerList::Iterator it = m_container.begin(); |
462 | for (; it != m_container.end(); ++it ) | 462 | for (; it != m_container.end(); ++it ) |
463 | m_parentTab->removePage( (*it).widget ); | 463 | m_parentTab->removePage( (*it).widget ); |
464 | } | 464 | } |
465 | } | 465 | } |
466 | else | 466 | else |
467 | tab = m_tabWidget = new OTabWidget( this ); | 467 | tab = m_tabWidget = new OTabWidget( this ); |
468 | 468 | ||
469 | connect(tab, SIGNAL(currentChanged(QWidget*) ), | 469 | connect(tab, SIGNAL(currentChanged(QWidget*) ), |
470 | this, SIGNAL(currentChanged(QWidget*) ) ); | 470 | this, SIGNAL(currentChanged(QWidget*) ) ); |
471 | 471 | ||
472 | 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 ) |
473 | { | 473 | { |
474 | qWarning("Widget is %s", (*it).name.latin1() ); | 474 | qWarning("Widget is %s", (*it).name.latin1() ); |
475 | addToTab( (*it) ); | 475 | addToTab( (*it) ); |
476 | } | 476 | } |
477 | 477 | ||
478 | for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() ) | 478 | for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() ) |
479 | { | 479 | { |
480 | split->reparent(this, 0, QPoint(0, 0) ); | 480 | split->reparent(this, 0, QPoint(0, 0) ); |
481 | split->setTabWidget( tab ); | 481 | split->setTabWidget( tab ); |
482 | } | 482 | } |
483 | 483 | ||
484 | 484 | ||
485 | delete m_hbox; | 485 | delete m_hbox; |
486 | m_hbox = 0; | 486 | m_hbox = 0; |
487 | if (!m_tabWidget ) | 487 | if (!m_tabWidget ) |
488 | return; | 488 | return; |
489 | 489 | ||
490 | m_tabWidget->setGeometry( frameRect() ); | 490 | m_tabWidget->setGeometry( frameRect() ); |
491 | m_tabWidget->show(); | 491 | m_tabWidget->show(); |
492 | 492 | ||
493 | } | 493 | } |
494 | 494 | ||
495 | /* | 495 | /* |
496 | * changes over to a box | 496 | * changes over to a box |
497 | * this is recursive as well | 497 | * this is recursive as well |
498 | */ | 498 | */ |
499 | void OSplitter::changeHBox() | 499 | void OSplitter::changeHBox() |
500 | { | 500 | { |
501 | if (m_hbox ) | 501 | if (m_hbox ) |
502 | { | 502 | { |
503 | m_hbox->setGeometry( frameRect() ); | 503 | m_hbox->setGeometry( frameRect() ); |
504 | return; | 504 | return; |
505 | } | 505 | } |
506 | 506 | ||
507 | qWarning("new HBox %s", name() ); | 507 | qWarning("new HBox %s", name() ); |
508 | m_hbox = new QHBox( this ); | 508 | m_hbox = new QHBox( this ); |
509 | commonChangeBox(); | 509 | commonChangeBox(); |
510 | } | 510 | } |
511 | 511 | ||
512 | void OSplitter::changeVBox() | 512 | void OSplitter::changeVBox() |
513 | { | 513 | { |
514 | if (m_hbox ) | 514 | if (m_hbox ) |
515 | { | 515 | { |
516 | m_hbox->setGeometry( frameRect() ); | 516 | m_hbox->setGeometry( frameRect() ); |
517 | return; | 517 | return; |
518 | } | 518 | } |
519 | 519 | ||
520 | qWarning("New VBOX %s", name() ); | 520 | qWarning("New VBOX %s", name() ); |
521 | m_hbox = new QVBox( this ); | 521 | m_hbox = new QVBox( this ); |
522 | 522 | ||
523 | commonChangeBox(); | 523 | commonChangeBox(); |
524 | 524 | ||
525 | } | 525 | } |
526 | 526 | ||
527 | /* | 527 | /* |
528 | * common box code | 528 | * common box code |
529 | * first remove and add children | 529 | * first remove and add children |
530 | * the other splitters | 530 | * the other splitters |
531 | * it is recursive as well due the call to setTabWidget | 531 | * it is recursive as well due the call to setTabWidget |
532 | */ | 532 | */ |
533 | void OSplitter::commonChangeBox() | 533 | void OSplitter::commonChangeBox() |
534 | { | 534 | { |
535 | qWarning(" Name of Splitters is %s", name() ); | 535 | qWarning(" Name of Splitters is %s", name() ); |
536 | 536 | ||
537 | 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 ) |
538 | { | 538 | { |
539 | /* 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 */ |
540 | if (m_parentTab ) | 540 | if (m_parentTab ) |
541 | removeFromTab( (*it).widget ); | 541 | removeFromTab( (*it).widget ); |
542 | qWarning("Adding to box %s", (*it).name.latin1() ); | 542 | qWarning("Adding to box %s", (*it).name.latin1() ); |
543 | addToBox( (*it) ); | 543 | addToBox( (*it) ); |
544 | } | 544 | } |
545 | for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() ) | 545 | for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() ) |
546 | { | 546 | { |
547 | /* tell them the world had changed */ | 547 | /* tell them the world had changed */ |
548 | split->setTabWidget( 0 ); | 548 | split->setTabWidget( 0 ); |
549 | OSplitterContainer con; | 549 | OSplitterContainer con; |
550 | con.widget = split; | 550 | con.widget = split; |
551 | // con.widget = split->m_tabWidget ? static_cast<QWidget*>(split->m_tabWidget) | 551 | // con.widget = split->m_tabWidget ? static_cast<QWidget*>(split->m_tabWidget) |
552 | // : static_cast<QWidget*>(split->m_hbox); | 552 | // : static_cast<QWidget*>(split->m_hbox); |
553 | addToBox( con ); | 553 | addToBox( con ); |
554 | } | 554 | } |
555 | 555 | ||
556 | 556 | ||
557 | 557 | ||
558 | if (m_parentTab ) | 558 | if (m_parentTab ) |
559 | m_parentTab->addTab(m_hbox, iconName(), label() ); | 559 | m_parentTab->addTab(m_hbox, iconName(), label() ); |
560 | else | 560 | else |
561 | { | 561 | { |
562 | qWarning(" setting Box geometry for %s", name() ); | 562 | qWarning(" setting Box geometry for %s", name() ); |
563 | m_hbox->setGeometry( frameRect() ); | 563 | m_hbox->setGeometry( frameRect() ); |
564 | m_hbox->show(); | 564 | m_hbox->show(); |
565 | delete m_tabWidget; | 565 | delete m_tabWidget; |
566 | m_tabWidget = 0; | 566 | m_tabWidget = 0; |
567 | show(); // also show this widget | 567 | show(); // also show this widget |
568 | } | 568 | } |
569 | } | 569 | } |
570 | 570 | ||
571 | /* | 571 | /* |
572 | * sets the tabwidget, removes tabs, and relayouts the widget | 572 | * sets the tabwidget, removes tabs, and relayouts the widget |
573 | */ | 573 | */ |
574 | void OSplitter::setTabWidget( OTabWidget* wid) | 574 | void OSplitter::setTabWidget( OTabWidget* wid) |
575 | { | 575 | { |
576 | /* clean up cause m_parentTab will not be available for us */ | 576 | /* clean up cause m_parentTab will not be available for us */ |
577 | if ( m_parentTab ) | 577 | if ( m_parentTab ) |
578 | { | 578 | { |
579 | if (m_hbox ) | 579 | if (m_hbox ) |
580 | m_parentTab->removePage( m_hbox ); | 580 | m_parentTab->removePage( m_hbox ); |
581 | else if (!m_container.isEmpty() ) | 581 | else if (!m_container.isEmpty() ) |
582 | { | 582 | { |
583 | ContainerList::Iterator it = m_container.begin(); | 583 | ContainerList::Iterator it = m_container.begin(); |
584 | for ( ; it != m_container.end(); ++it ) | 584 | for ( ; it != m_container.end(); ++it ) |
585 | m_parentTab->removePage( (*it).widget ); | 585 | m_parentTab->removePage( (*it).widget ); |
586 | } | 586 | } |
587 | } | 587 | } |
588 | /* the parent Splitter changed so either make us indepent or dep */ | 588 | /* the parent Splitter changed so either make us indepent or dep */ |
589 | 589 | ||
590 | m_parentTab = wid; | 590 | m_parentTab = wid; |
591 | 591 | ||
592 | QWidget *tab = m_tabWidget; | 592 | QWidget *tab = m_tabWidget; |
593 | QWidget *box = m_hbox; | 593 | QWidget *box = m_hbox; |
594 | m_hbox = 0; m_tabWidget = 0; | 594 | m_hbox = 0; m_tabWidget = 0; |
595 | 595 | ||
596 | if ( layoutMode() ) | 596 | if ( layoutMode() ) |
597 | changeTab(); | 597 | changeTab(); |
598 | else if (m_orient == Horizontal ) | 598 | else if (m_orient == Horizontal ) |
599 | changeHBox(); | 599 | changeHBox(); |
600 | else | 600 | else |
601 | changeVBox(); | 601 | changeVBox(); |
602 | 602 | ||
603 | /* our own crap is added and children from change* */ | 603 | /* our own crap is added and children from change* */ |
604 | delete tab; | 604 | delete tab; |
605 | delete box; | 605 | delete box; |
606 | } | 606 | } |
607 | 607 | ||
608 | #if 0 | 608 | #if 0 |
609 | void OSplitter::reparentAll() | 609 | void OSplitter::reparentAll() |
610 | { | 610 | { |
611 | if (m_container.isEmpty() ) | 611 | if (m_container.isEmpty() ) |
612 | return; | 612 | return; |
613 | 613 | ||
614 | ContainerList::Iterator it = m_container.begin(); | 614 | ContainerList::Iterator it = m_container.begin(); |
615 | for ( ; it != m_container.end(); ++it ) | 615 | for ( ; it != m_container.end(); ++it ) |
616 | (*it).wid->reparent(0, 0, QPoint(0, 0) ); | 616 | (*it).wid->reparent(0, 0, QPoint(0, 0) ); |
617 | 617 | ||
618 | 618 | ||
619 | } | 619 | } |
620 | #endif | 620 | #endif |
621 | 621 | ||
622 | /** | 622 | /** |
623 | * @internal | 623 | * @internal |
624 | */ | 624 | */ |
625 | bool OSplitter::layoutMode()const | 625 | bool OSplitter::layoutMode()const |
626 | { | 626 | { |
627 | if ( size().width() > m_size_policy && | 627 | if ( size().width() > m_size_policy && |
628 | m_orient == Horizontal ) | 628 | m_orient == Horizontal ) |
629 | { | 629 | { |
630 | return false; | 630 | return false; |
631 | } | 631 | } |
632 | else if ( size().height() > m_size_policy && | 632 | else if ( size().height() > m_size_policy && |
633 | m_orient == Vertical ) | 633 | m_orient == Vertical ) |
634 | { | 634 | { |
635 | return false; | 635 | return false; |
636 | } | 636 | } |
637 | 637 | ||
638 | return true; | 638 | return true; |
639 | } | 639 | } |
diff --git a/libopie2/opieui/big-screen/osplitter.h b/libopie2/opieui/big-screen/osplitter.h index 7b5ea53..46dad05 100644 --- a/libopie2/opieui/big-screen/osplitter.h +++ b/libopie2/opieui/big-screen/osplitter.h | |||
@@ -1,151 +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 | ||
40 | class QHBox; | 40 | class 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 | ||
51 | namespace Opie{ | 51 | namespace Opie{ |
52 | namespace Ui { | 52 | namespace Ui { |
53 | class OTabWidget; | 53 | class 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 | */ |
72 | class OSplitter : public QFrame | 72 | class OSplitter : public QFrame |
73 | { | 73 | { |
74 | Q_OBJECT | 74 | Q_OBJECT |
75 | public: | 75 | public: |
76 | typedef QValueList<Opie::Ui::Private::OSplitterContainer> ContainerList; | 76 | typedef QValueList<Opie::Ui::Internal::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 | ||
99 | signals: | 99 | signals: |
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); |
115 | public: | 115 | public: |
116 | // QSize sizeHint()const; | 116 | // QSize sizeHint()const; |
117 | // QSize minimumSizeHint()const; | 117 | // QSize minimumSizeHint()const; |
118 | 118 | ||
119 | protected: | 119 | protected: |
120 | void resizeEvent( QResizeEvent* ); | 120 | void resizeEvent( QResizeEvent* ); |
121 | 121 | ||
122 | private: | 122 | private: |
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::Ui::Private::OSplitterContainer& ); | 127 | void addToTab( const Opie::Ui::Internal::OSplitterContainer& ); |
128 | void addToBox( const Opie::Ui::Private::OSplitterContainer& ); | 128 | void addToBox( const Opie::Ui::Internal::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 | ||
151 | #endif | 151 | #endif |
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp index c4d5033..a9ec8c4 100644 --- a/libopie2/opieui/fileselector/ofileselector.cpp +++ b/libopie2/opieui/fileselector/ofileselector.cpp | |||
@@ -1,1173 +1,1174 @@ | |||
1 | |||
1 | /* | 2 | /* |
2 | =. This file is part of the OPIE Project | 3 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> | 4 | .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> |
4 | .>+-= | 5 | .>+-= |
5 | _;:, .> :=|. This library is free software; you can | 6 | _;:, .> :=|. This library is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 12 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This library is distributed in the hope that | 13 | .i_,=:_. -<s. This library is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
19 | : = ...= . :.=- | 20 | : = ...= . :.=- |
20 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
22 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
26 | 27 | ||
27 | */ | 28 | */ |
28 | 29 | ||
29 | /* hacky but we need to get FileSelector::filter */ | 30 | /* hacky but we need to get FileSelector::filter */ |
30 | #define private public | 31 | #define private public |
31 | #include <qpe/fileselector.h> | 32 | #include <qpe/fileselector.h> |
32 | #undef private | 33 | #undef private |
33 | 34 | ||
34 | #include "ofileselector_p.h" | 35 | #include "ofileselector_p.h" |
35 | 36 | ||
36 | /* OPIE */ | 37 | /* OPIE */ |
37 | #include <opie2/ofileselector.h> | 38 | #include <opie2/ofileselector.h> |
38 | 39 | ||
39 | #include <qpe/qpeapplication.h> | 40 | #include <qpe/qpeapplication.h> |
40 | #include <qpe/mimetype.h> | 41 | #include <qpe/mimetype.h> |
41 | #include <qpe/resource.h> | 42 | #include <qpe/resource.h> |
42 | #include <qpe/storage.h> | 43 | #include <qpe/storage.h> |
43 | 44 | ||
44 | /* QT */ | 45 | /* QT */ |
45 | #include <qcombobox.h> | 46 | #include <qcombobox.h> |
46 | #include <qdir.h> | 47 | #include <qdir.h> |
47 | #include <qhbox.h> | 48 | #include <qhbox.h> |
48 | #include <qheader.h> | 49 | #include <qheader.h> |
49 | #include <qlabel.h> | 50 | #include <qlabel.h> |
50 | #include <qlayout.h> | 51 | #include <qlayout.h> |
51 | #include <qlineedit.h> | 52 | #include <qlineedit.h> |
52 | #include <qlistview.h> | 53 | #include <qlistview.h> |
53 | #include <qpopupmenu.h> | 54 | #include <qpopupmenu.h> |
54 | #include <qwidgetstack.h> | 55 | #include <qwidgetstack.h> |
55 | #include <qregexp.h> | 56 | #include <qregexp.h> |
56 | #include <qobjectlist.h> | 57 | #include <qobjectlist.h> |
57 | 58 | ||
58 | using namespace Opie::Ui::Private; | 59 | using namespace Opie::Ui::Internal; |
59 | 60 | ||
60 | namespace Opie { | 61 | namespace Opie { |
61 | namespace Ui { | 62 | namespace Ui { |
62 | namespace Private { | 63 | namespace Internal { |
63 | OFileViewInterface::OFileViewInterface( OFileSelector* selector ) | 64 | OFileViewInterface::OFileViewInterface( OFileSelector* selector ) |
64 | : m_selector( selector ) | 65 | : m_selector( selector ) |
65 | {} | 66 | {} |
66 | 67 | ||
67 | OFileViewInterface::~OFileViewInterface() | 68 | OFileViewInterface::~OFileViewInterface() |
68 | {} | 69 | {} |
69 | 70 | ||
70 | QString OFileViewInterface::name()const | 71 | QString OFileViewInterface::name()const |
71 | { | 72 | { |
72 | return m_name; | 73 | return m_name; |
73 | } | 74 | } |
74 | 75 | ||
75 | void OFileViewInterface::setName( const QString& name ) | 76 | void OFileViewInterface::setName( const QString& name ) |
76 | { | 77 | { |
77 | m_name = name; | 78 | m_name = name; |
78 | } | 79 | } |
79 | 80 | ||
80 | OFileSelector* OFileViewInterface::selector()const | 81 | OFileSelector* OFileViewInterface::selector()const |
81 | { | 82 | { |
82 | return m_selector; | 83 | return m_selector; |
83 | } | 84 | } |
84 | 85 | ||
85 | DocLnk OFileViewInterface::selectedDocument()const | 86 | DocLnk OFileViewInterface::selectedDocument()const |
86 | { | 87 | { |
87 | return DocLnk( selectedName() ); | 88 | return DocLnk( selectedName() ); |
88 | } | 89 | } |
89 | 90 | ||
90 | bool OFileViewInterface::showNew()const | 91 | bool OFileViewInterface::showNew()const |
91 | { | 92 | { |
92 | return selector()->showNew(); | 93 | return selector()->showNew(); |
93 | } | 94 | } |
94 | 95 | ||
95 | bool OFileViewInterface::showClose()const | 96 | bool OFileViewInterface::showClose()const |
96 | { | 97 | { |
97 | return selector()->showClose(); | 98 | return selector()->showClose(); |
98 | } | 99 | } |
99 | 100 | ||
100 | MimeTypes OFileViewInterface::mimeTypes()const | 101 | MimeTypes OFileViewInterface::mimeTypes()const |
101 | { | 102 | { |
102 | return selector()->mimeTypes(); | 103 | return selector()->mimeTypes(); |
103 | } | 104 | } |
104 | 105 | ||
105 | QStringList OFileViewInterface::currentMimeType()const | 106 | QStringList OFileViewInterface::currentMimeType()const |
106 | { | 107 | { |
107 | return selector()->currentMimeType(); | 108 | return selector()->currentMimeType(); |
108 | } | 109 | } |
109 | 110 | ||
110 | void OFileViewInterface::activate( const QString& ) | 111 | void OFileViewInterface::activate( const QString& ) |
111 | { | 112 | { |
112 | // not implemented here | 113 | // not implemented here |
113 | } | 114 | } |
114 | 115 | ||
115 | void OFileViewInterface::ok() | 116 | void OFileViewInterface::ok() |
116 | { | 117 | { |
117 | emit selector()->ok(); | 118 | emit selector()->ok(); |
118 | } | 119 | } |
119 | 120 | ||
120 | void OFileViewInterface::cancel() | 121 | void OFileViewInterface::cancel() |
121 | { | 122 | { |
122 | emit selector()->cancel(); | 123 | emit selector()->cancel(); |
123 | } | 124 | } |
124 | 125 | ||
125 | void OFileViewInterface::closeMe() | 126 | void OFileViewInterface::closeMe() |
126 | { | 127 | { |
127 | emit selector()->closeMe(); | 128 | emit selector()->closeMe(); |
128 | } | 129 | } |
129 | 130 | ||
130 | void OFileViewInterface::fileSelected( const QString& str) | 131 | void OFileViewInterface::fileSelected( const QString& str) |
131 | { | 132 | { |
132 | emit selector()->fileSelected( str); | 133 | emit selector()->fileSelected( str); |
133 | } | 134 | } |
134 | 135 | ||
135 | void OFileViewInterface::fileSelected( const DocLnk& lnk) | 136 | void OFileViewInterface::fileSelected( const DocLnk& lnk) |
136 | { | 137 | { |
137 | emit selector()->fileSelected( lnk ); | 138 | emit selector()->fileSelected( lnk ); |
138 | } | 139 | } |
139 | 140 | ||
140 | void OFileViewInterface::setCurrentFileName( const QString& str ) | 141 | void OFileViewInterface::setCurrentFileName( const QString& str ) |
141 | { | 142 | { |
142 | selector()->m_lneEdit->setText( str ); | 143 | selector()->m_lneEdit->setText( str ); |
143 | } | 144 | } |
144 | 145 | ||
145 | QString OFileViewInterface::currentFileName()const | 146 | QString OFileViewInterface::currentFileName()const |
146 | { | 147 | { |
147 | return selector()->m_lneEdit->text(); | 148 | return selector()->m_lneEdit->text(); |
148 | } | 149 | } |
149 | 150 | ||
150 | QString OFileViewInterface::startDirectory()const | 151 | QString OFileViewInterface::startDirectory()const |
151 | { | 152 | { |
152 | return selector()->m_startDir; | 153 | return selector()->m_startDir; |
153 | } | 154 | } |
154 | 155 | ||
155 | ODocumentFileView::ODocumentFileView( OFileSelector* selector ) | 156 | ODocumentFileView::ODocumentFileView( OFileSelector* selector ) |
156 | :OFileViewInterface( selector ) | 157 | :OFileViewInterface( selector ) |
157 | { | 158 | { |
158 | m_selector = 0; | 159 | m_selector = 0; |
159 | setName( QObject::tr("Documents") ); | 160 | setName( QObject::tr("Documents") ); |
160 | } | 161 | } |
161 | 162 | ||
162 | ODocumentFileView::~ODocumentFileView() | 163 | ODocumentFileView::~ODocumentFileView() |
163 | { | 164 | { |
164 | } | 165 | } |
165 | 166 | ||
166 | QString ODocumentFileView::selectedName()const | 167 | QString ODocumentFileView::selectedName()const |
167 | { | 168 | { |
168 | if (!m_selector) | 169 | if (!m_selector) |
169 | return QString::null; | 170 | return QString::null; |
170 | 171 | ||
171 | return m_selector->selectedDocument().file(); | 172 | return m_selector->selectedDocument().file(); |
172 | } | 173 | } |
173 | 174 | ||
174 | QString ODocumentFileView::selectedPath()const | 175 | QString ODocumentFileView::selectedPath()const |
175 | { | 176 | { |
176 | return QPEApplication::documentDir(); | 177 | return QPEApplication::documentDir(); |
177 | } | 178 | } |
178 | 179 | ||
179 | QString ODocumentFileView::directory()const | 180 | QString ODocumentFileView::directory()const |
180 | { | 181 | { |
181 | return selectedPath(); | 182 | return selectedPath(); |
182 | } | 183 | } |
183 | 184 | ||
184 | void ODocumentFileView::reread() | 185 | void ODocumentFileView::reread() |
185 | { | 186 | { |
186 | if (!m_selector) | 187 | if (!m_selector) |
187 | return; | 188 | return; |
188 | 189 | ||
189 | m_selector->setNewVisible( showNew() ); | 190 | m_selector->setNewVisible( showNew() ); |
190 | m_selector->setCloseVisible( showClose() ); | 191 | m_selector->setCloseVisible( showClose() ); |
191 | m_selector->filter = currentMimeType().join(";"); | 192 | m_selector->filter = currentMimeType().join(";"); |
192 | m_selector->reread(); | 193 | m_selector->reread(); |
193 | } | 194 | } |
194 | 195 | ||
195 | int ODocumentFileView::fileCount()const | 196 | int ODocumentFileView::fileCount()const |
196 | { | 197 | { |
197 | if (!m_selector) | 198 | if (!m_selector) |
198 | return -1; | 199 | return -1; |
199 | 200 | ||
200 | return m_selector->fileCount(); | 201 | return m_selector->fileCount(); |
201 | } | 202 | } |
202 | 203 | ||
203 | DocLnk ODocumentFileView::selectedDocument()const | 204 | DocLnk ODocumentFileView::selectedDocument()const |
204 | { | 205 | { |
205 | if (!m_selector) | 206 | if (!m_selector) |
206 | return DocLnk(); | 207 | return DocLnk(); |
207 | 208 | ||
208 | return m_selector->selectedDocument(); | 209 | return m_selector->selectedDocument(); |
209 | } | 210 | } |
210 | 211 | ||
211 | QWidget* ODocumentFileView::widget( QWidget* parent ) | 212 | QWidget* ODocumentFileView::widget( QWidget* parent ) |
212 | { | 213 | { |
213 | if (!m_selector ) | 214 | if (!m_selector ) |
214 | { | 215 | { |
215 | m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); | 216 | m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); |
216 | QObject::connect(m_selector, SIGNAL(fileSelected(const DocLnk&) ), | 217 | QObject::connect(m_selector, SIGNAL(fileSelected(const DocLnk&) ), |
217 | selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); | 218 | selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); |
218 | QObject::connect(m_selector, SIGNAL(closeMe() ), | 219 | QObject::connect(m_selector, SIGNAL(closeMe() ), |
219 | selector(), SIGNAL(closeMe() ) ); | 220 | selector(), SIGNAL(closeMe() ) ); |
220 | QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk&) ), | 221 | QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk&) ), |
221 | selector(), SIGNAL(newSelected(const DocLnk&) ) ); | 222 | selector(), SIGNAL(newSelected(const DocLnk&) ) ); |
222 | } | 223 | } |
223 | 224 | ||
224 | return m_selector; | 225 | return m_selector; |
225 | } | 226 | } |
226 | 227 | ||
227 | /* | 228 | /* |
228 | * This is the file system view used | 229 | * This is the file system view used |
229 | * we use a QListView + QListViewItems for it | 230 | * we use a QListView + QListViewItems for it |
230 | */ | 231 | */ |
231 | 232 | ||
232 | OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, | 233 | OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, |
233 | const QString& path, const QString& date, | 234 | const QString& path, const QString& date, |
234 | const QString& size, const QString& dir, | 235 | const QString& size, const QString& dir, |
235 | bool isLocked, bool isDir ) | 236 | bool isLocked, bool isDir ) |
236 | : QListViewItem( view ) | 237 | : QListViewItem( view ) |
237 | { | 238 | { |
238 | setPixmap(0, pixmap ); | 239 | setPixmap(0, pixmap ); |
239 | setText(1, path ); | 240 | setText(1, path ); |
240 | setText(2, size ); | 241 | setText(2, size ); |
241 | setText(3, date ); | 242 | setText(3, date ); |
242 | m_isDir = isDir; | 243 | m_isDir = isDir; |
243 | m_dir = dir; | 244 | m_dir = dir; |
244 | m_locked = isLocked; | 245 | m_locked = isLocked; |
245 | } | 246 | } |
246 | 247 | ||
247 | OFileSelectorItem::~OFileSelectorItem() | 248 | OFileSelectorItem::~OFileSelectorItem() |
248 | { | 249 | { |
249 | } | 250 | } |
250 | 251 | ||
251 | bool OFileSelectorItem::isLocked()const | 252 | bool OFileSelectorItem::isLocked()const |
252 | { | 253 | { |
253 | return m_locked; | 254 | return m_locked; |
254 | } | 255 | } |
255 | 256 | ||
256 | QString OFileSelectorItem::directory()const | 257 | QString OFileSelectorItem::directory()const |
257 | { | 258 | { |
258 | return m_dir; | 259 | return m_dir; |
259 | } | 260 | } |
260 | 261 | ||
261 | bool OFileSelectorItem::isDir()const | 262 | bool OFileSelectorItem::isDir()const |
262 | { | 263 | { |
263 | return m_isDir; | 264 | return m_isDir; |
264 | } | 265 | } |
265 | 266 | ||
266 | QString OFileSelectorItem::path()const | 267 | QString OFileSelectorItem::path()const |
267 | { | 268 | { |
268 | return text( 1 ); | 269 | return text( 1 ); |
269 | } | 270 | } |
270 | 271 | ||
271 | QString OFileSelectorItem::key( int id, bool )const | 272 | QString OFileSelectorItem::key( int id, bool )const |
272 | { | 273 | { |
273 | QString ke; | 274 | QString ke; |
274 | if( id == 0 || id == 1 ) | 275 | if( id == 0 || id == 1 ) |
275 | { // name | 276 | { // name |
276 | if( m_isDir ) | 277 | if( m_isDir ) |
277 | { | 278 | { |
278 | ke.append("0" ); | 279 | ke.append("0" ); |
279 | ke.append( text(1) ); | 280 | ke.append( text(1) ); |
280 | } | 281 | } |
281 | else | 282 | else |
282 | { | 283 | { |
283 | ke.append("1" ); | 284 | ke.append("1" ); |
284 | ke.append( text(1) ); | 285 | ke.append( text(1) ); |
285 | } | 286 | } |
286 | return ke; | 287 | return ke; |
287 | } | 288 | } |
288 | else | 289 | else |
289 | return text( id ); | 290 | return text( id ); |
290 | 291 | ||
291 | } | 292 | } |
292 | 293 | ||
293 | OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel) | 294 | OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel) |
294 | :QWidget( parent ), m_sel( sel ) | 295 | :QWidget( parent ), m_sel( sel ) |
295 | { | 296 | { |
296 | m_all = false; | 297 | m_all = false; |
297 | QVBoxLayout* lay = new QVBoxLayout( this ); | 298 | QVBoxLayout* lay = new QVBoxLayout( this ); |
298 | m_currentDir = startDir; | 299 | m_currentDir = startDir; |
299 | 300 | ||
300 | /* | 301 | /* |
301 | * now we add a special bar | 302 | * now we add a special bar |
302 | * One Button For Up | 303 | * One Button For Up |
303 | * Home | 304 | * Home |
304 | * Doc | 305 | * Doc |
305 | * And a dropdown menu with FileSystems | 306 | * And a dropdown menu with FileSystems |
306 | * FUTURE: one to change dir with lineedit | 307 | * FUTURE: one to change dir with lineedit |
307 | * Bookmarks | 308 | * Bookmarks |
308 | * Create Dir | 309 | * Create Dir |
309 | */ | 310 | */ |
310 | QHBox* box = new QHBox(this ); | 311 | QHBox* box = new QHBox(this ); |
311 | box->setBackgroundMode( PaletteButton ); | 312 | box->setBackgroundMode( PaletteButton ); |
312 | box->setSpacing( 0 ); | 313 | box->setSpacing( 0 ); |
313 | 314 | ||
314 | QToolButton *btn = new QToolButton( box ); | 315 | QToolButton *btn = new QToolButton( box ); |
315 | btn->setIconSet( Resource::loadIconSet("up") ); | 316 | btn->setIconSet( Resource::loadIconSet("up") ); |
316 | connect(btn, SIGNAL(clicked() ), | 317 | connect(btn, SIGNAL(clicked() ), |
317 | this, SLOT( cdUP() ) ); | 318 | this, SLOT( cdUP() ) ); |
318 | 319 | ||
319 | btn = new QToolButton( box ); | 320 | btn = new QToolButton( box ); |
320 | btn->setIconSet( Resource::loadIconSet("home") ); | 321 | btn->setIconSet( Resource::loadIconSet("home") ); |
321 | connect(btn, SIGNAL(clicked() ), | 322 | connect(btn, SIGNAL(clicked() ), |
322 | this, SLOT( cdHome() ) ); | 323 | this, SLOT( cdHome() ) ); |
323 | 324 | ||
324 | btn = new QToolButton( box ); | 325 | btn = new QToolButton( box ); |
325 | btn->setIconSet( Resource::loadIconSet("DocsIcon") ); | 326 | btn->setIconSet( Resource::loadIconSet("DocsIcon") ); |
326 | connect(btn, SIGNAL(clicked() ), | 327 | connect(btn, SIGNAL(clicked() ), |
327 | this, SLOT(cdDoc() ) ); | 328 | this, SLOT(cdDoc() ) ); |
328 | 329 | ||
329 | m_btnNew = new QToolButton( box ); | 330 | m_btnNew = new QToolButton( box ); |
330 | m_btnNew->setIconSet( Resource::loadIconSet("new") ); | 331 | m_btnNew->setIconSet( Resource::loadIconSet("new") ); |
331 | connect(m_btnNew, SIGNAL(clicked() ), | 332 | connect(m_btnNew, SIGNAL(clicked() ), |
332 | this, SLOT(slotNew() ) ); | 333 | this, SLOT(slotNew() ) ); |
333 | 334 | ||
334 | 335 | ||
335 | m_btnClose = new QToolButton( box ); | 336 | m_btnClose = new QToolButton( box ); |
336 | m_btnClose->setIconSet( Resource::loadIconSet("close") ); | 337 | m_btnClose->setIconSet( Resource::loadIconSet("close") ); |
337 | connect(m_btnClose, SIGNAL(clicked() ), | 338 | connect(m_btnClose, SIGNAL(clicked() ), |
338 | selector(), SIGNAL(closeMe() ) ); | 339 | selector(), SIGNAL(closeMe() ) ); |
339 | 340 | ||
340 | btn = new QToolButton( box ); | 341 | btn = new QToolButton( box ); |
341 | btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") ); | 342 | btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") ); |
342 | 343 | ||
343 | /* let's fill device parts */ | 344 | /* let's fill device parts */ |
344 | QPopupMenu* pop = new QPopupMenu(this); | 345 | QPopupMenu* pop = new QPopupMenu(this); |
345 | connect(pop, SIGNAL( activated(int) ), | 346 | connect(pop, SIGNAL( activated(int) ), |
346 | this, SLOT(slotFSActivated(int) ) ); | 347 | this, SLOT(slotFSActivated(int) ) ); |
347 | 348 | ||
348 | StorageInfo storage; | 349 | StorageInfo storage; |
349 | const QList<FileSystem> &fs = storage.fileSystems(); | 350 | const QList<FileSystem> &fs = storage.fileSystems(); |
350 | QListIterator<FileSystem> it(fs); | 351 | QListIterator<FileSystem> it(fs); |
351 | for ( ; it.current(); ++it ) | 352 | for ( ; it.current(); ++it ) |
352 | { | 353 | { |
353 | const QString disk = (*it)->name(); | 354 | const QString disk = (*it)->name(); |
354 | const QString path = (*it)->path(); | 355 | const QString path = (*it)->path(); |
355 | m_dev.insert( disk, path ); | 356 | m_dev.insert( disk, path ); |
356 | pop->insertItem( disk ); | 357 | pop->insertItem( disk ); |
357 | } | 358 | } |
358 | m_fsPop = pop; | 359 | m_fsPop = pop; |
359 | 360 | ||
360 | 361 | ||
361 | btn->setPopup( pop ); | 362 | btn->setPopup( pop ); |
362 | 363 | ||
363 | lay->addWidget( box ); | 364 | lay->addWidget( box ); |
364 | 365 | ||
365 | m_view = new QListView( this ); | 366 | m_view = new QListView( this ); |
366 | 367 | ||
367 | m_view->installEventFilter(this); | 368 | m_view->installEventFilter(this); |
368 | 369 | ||
369 | QPEApplication::setStylusOperation( m_view->viewport(), | 370 | QPEApplication::setStylusOperation( m_view->viewport(), |
370 | QPEApplication::RightOnHold); | 371 | QPEApplication::RightOnHold); |
371 | m_view->addColumn(" " ); | 372 | m_view->addColumn(" " ); |
372 | m_view->addColumn(tr("Name"), 135 ); | 373 | m_view->addColumn(tr("Name"), 135 ); |
373 | m_view->addColumn(tr("Size"), -1 ); | 374 | m_view->addColumn(tr("Size"), -1 ); |
374 | m_view->addColumn(tr("Date"), 60 ); | 375 | m_view->addColumn(tr("Date"), 60 ); |
375 | m_view->addColumn(tr("Mime Type"), -1 ); | 376 | m_view->addColumn(tr("Mime Type"), -1 ); |
376 | 377 | ||
377 | 378 | ||
378 | m_view->setSorting( 1 ); | 379 | m_view->setSorting( 1 ); |
379 | m_view->setAllColumnsShowFocus( TRUE ); | 380 | m_view->setAllColumnsShowFocus( TRUE ); |
380 | 381 | ||
381 | lay->addWidget( m_view, 1000 ); | 382 | lay->addWidget( m_view, 1000 ); |
382 | connectSlots(); | 383 | connectSlots(); |
383 | } | 384 | } |
384 | 385 | ||
385 | OFileViewFileListView::~OFileViewFileListView() | 386 | OFileViewFileListView::~OFileViewFileListView() |
386 | { | 387 | { |
387 | } | 388 | } |
388 | 389 | ||
389 | void OFileViewFileListView::slotNew() | 390 | void OFileViewFileListView::slotNew() |
390 | { | 391 | { |
391 | DocLnk lnk; | 392 | DocLnk lnk; |
392 | emit selector()->newSelected( lnk ); | 393 | emit selector()->newSelected( lnk ); |
393 | } | 394 | } |
394 | 395 | ||
395 | OFileSelectorItem* OFileViewFileListView::currentItem()const | 396 | OFileSelectorItem* OFileViewFileListView::currentItem()const |
396 | { | 397 | { |
397 | QListViewItem* item = m_view->currentItem(); | 398 | QListViewItem* item = m_view->currentItem(); |
398 | if (!item ) | 399 | if (!item ) |
399 | return 0l; | 400 | return 0l; |
400 | 401 | ||
401 | return static_cast<OFileSelectorItem*>(item); | 402 | return static_cast<OFileSelectorItem*>(item); |
402 | } | 403 | } |
403 | 404 | ||
404 | void OFileViewFileListView::reread( bool all ) | 405 | void OFileViewFileListView::reread( bool all ) |
405 | { | 406 | { |
406 | m_view->clear(); | 407 | m_view->clear(); |
407 | 408 | ||
408 | if (selector()->showClose() ) | 409 | if (selector()->showClose() ) |
409 | m_btnClose->show(); | 410 | m_btnClose->show(); |
410 | else | 411 | else |
411 | m_btnClose->hide(); | 412 | m_btnClose->hide(); |
412 | 413 | ||
413 | if (selector()->showNew() ) | 414 | if (selector()->showNew() ) |
414 | m_btnNew->show(); | 415 | m_btnNew->show(); |
415 | else | 416 | else |
416 | m_btnNew->hide(); | 417 | m_btnNew->hide(); |
417 | 418 | ||
418 | m_mimes = selector()->currentMimeType(); | 419 | m_mimes = selector()->currentMimeType(); |
419 | m_all = all; | 420 | m_all = all; |
420 | 421 | ||
421 | QDir dir( m_currentDir ); | 422 | QDir dir( m_currentDir ); |
422 | if (!dir.exists() ) | 423 | if (!dir.exists() ) |
423 | return; | 424 | return; |
424 | 425 | ||
425 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); | 426 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); |
426 | int filter; | 427 | int filter; |
427 | if (m_all ) | 428 | if (m_all ) |
428 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; | 429 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; |
429 | else | 430 | else |
430 | filter = QDir::Files | QDir::Dirs | QDir::All; | 431 | filter = QDir::Files | QDir::Dirs | QDir::All; |
431 | dir.setFilter( filter ); | 432 | dir.setFilter( filter ); |
432 | 433 | ||
433 | // now go through all files | 434 | // now go through all files |
434 | const QFileInfoList *list = dir.entryInfoList(); | 435 | const QFileInfoList *list = dir.entryInfoList(); |
435 | if (!list) | 436 | if (!list) |
436 | { | 437 | { |
437 | cdUP(); | 438 | cdUP(); |
438 | return; | 439 | return; |
439 | } | 440 | } |
440 | 441 | ||
441 | QFileInfoListIterator it( *list ); | 442 | QFileInfoListIterator it( *list ); |
442 | QFileInfo *fi; | 443 | QFileInfo *fi; |
443 | while( (fi=it.current() ) ) | 444 | while( (fi=it.current() ) ) |
444 | { | 445 | { |
445 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) | 446 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) |
446 | { | 447 | { |
447 | ++it; | 448 | ++it; |
448 | continue; | 449 | continue; |
449 | } | 450 | } |
450 | 451 | ||
451 | /* | 452 | /* |
452 | * It is a symlink we try to resolve it now but don't let us attack by DOS | 453 | * It is a symlink we try to resolve it now but don't let us attack by DOS |
453 | * | 454 | * |
454 | */ | 455 | */ |
455 | if( fi->isSymLink() ) | 456 | if( fi->isSymLink() ) |
456 | { | 457 | { |
457 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); | 458 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); |
458 | for( int i = 0; i<=4; i++) | 459 | for( int i = 0; i<=4; i++) |
459 | { // 5 tries to prevent dos | 460 | { // 5 tries to prevent dos |
460 | QFileInfo info( file ); | 461 | QFileInfo info( file ); |
461 | if( !info.exists() ) | 462 | if( !info.exists() ) |
462 | { | 463 | { |
463 | addSymlink( fi, TRUE ); | 464 | addSymlink( fi, TRUE ); |
464 | break; | 465 | break; |
465 | } | 466 | } |
466 | else if( info.isDir() ) | 467 | else if( info.isDir() ) |
467 | { | 468 | { |
468 | addDir( fi, TRUE ); | 469 | addDir( fi, TRUE ); |
469 | break; | 470 | break; |
470 | } | 471 | } |
471 | else if( info.isFile() ) | 472 | else if( info.isFile() ) |
472 | { | 473 | { |
473 | addFile( fi, TRUE ); | 474 | addFile( fi, TRUE ); |
474 | break; | 475 | break; |
475 | } | 476 | } |
476 | else if( info.isSymLink() ) | 477 | else if( info.isSymLink() ) |
477 | { | 478 | { |
478 | file = info.dirPath(true ) + "/" + info.readLink() ; | 479 | file = info.dirPath(true ) + "/" + info.readLink() ; |
479 | break; | 480 | break; |
480 | } | 481 | } |
481 | else if( i == 4) | 482 | else if( i == 4) |
482 | { // couldn't resolve symlink add it as symlink | 483 | { // couldn't resolve symlink add it as symlink |
483 | addSymlink( fi ); | 484 | addSymlink( fi ); |
484 | } | 485 | } |
485 | } // off for loop for symlink resolving | 486 | } // off for loop for symlink resolving |
486 | } | 487 | } |
487 | else if( fi->isDir() ) | 488 | else if( fi->isDir() ) |
488 | addDir( fi ); | 489 | addDir( fi ); |
489 | else if( fi->isFile() ) | 490 | else if( fi->isFile() ) |
490 | addFile( fi ); | 491 | addFile( fi ); |
491 | 492 | ||
492 | ++it; | 493 | ++it; |
493 | } // of while loop | 494 | } // of while loop |
494 | m_view->sort(); | 495 | m_view->sort(); |
495 | 496 | ||
496 | } | 497 | } |
497 | int OFileViewFileListView::fileCount()const | 498 | int OFileViewFileListView::fileCount()const |
498 | { | 499 | { |
499 | return m_view->childCount(); | 500 | return m_view->childCount(); |
500 | } | 501 | } |
501 | 502 | ||
502 | QString OFileViewFileListView::currentDir()const | 503 | QString OFileViewFileListView::currentDir()const |
503 | { | 504 | { |
504 | return m_currentDir; | 505 | return m_currentDir; |
505 | } | 506 | } |
506 | 507 | ||
507 | OFileSelector* OFileViewFileListView::selector() | 508 | OFileSelector* OFileViewFileListView::selector() |
508 | { | 509 | { |
509 | return m_sel; | 510 | return m_sel; |
510 | } | 511 | } |
511 | 512 | ||
512 | bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) | 513 | bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) |
513 | { | 514 | { |
514 | if ( e->type() == QEvent::KeyPress ) | 515 | if ( e->type() == QEvent::KeyPress ) |
515 | { | 516 | { |
516 | QKeyEvent *k = (QKeyEvent *)e; | 517 | QKeyEvent *k = (QKeyEvent *)e; |
517 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) | 518 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) |
518 | { | 519 | { |
519 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); | 520 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); |
520 | return true; | 521 | return true; |
521 | } | 522 | } |
522 | } | 523 | } |
523 | return false; | 524 | return false; |
524 | } | 525 | } |
525 | 526 | ||
526 | void OFileViewFileListView::connectSlots() | 527 | void OFileViewFileListView::connectSlots() |
527 | { | 528 | { |
528 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), | 529 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), |
529 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); | 530 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); |
530 | connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), | 531 | connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), |
531 | this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); | 532 | this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); |
532 | } | 533 | } |
533 | 534 | ||
534 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) | 535 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) |
535 | { | 536 | { |
536 | if (!item) | 537 | if (!item) |
537 | return; | 538 | return; |
538 | #if 0 | 539 | #if 0 |
539 | 540 | ||
540 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 541 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
541 | 542 | ||
542 | if (!sel->isDir() ) | 543 | if (!sel->isDir() ) |
543 | { | 544 | { |
544 | selector()->m_lneEdit->setText( sel->text(1) ); | 545 | selector()->m_lneEdit->setText( sel->text(1) ); |
545 | // if in fileselector mode we will emit selected | 546 | // if in fileselector mode we will emit selected |
546 | if ( selector()->mode() == OFileSelector::FileSelector ) | 547 | if ( selector()->mode() == OFileSelector::FileSelector ) |
547 | { | 548 | { |
548 | qWarning("slot Current Changed"); | 549 | qWarning("slot Current Changed"); |
549 | QStringList str = QStringList::split("->", sel->text(1) ); | 550 | QStringList str = QStringList::split("->", sel->text(1) ); |
550 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 551 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); |
551 | emit selector()->fileSelected( path ); | 552 | emit selector()->fileSelected( path ); |
552 | DocLnk lnk( path ); | 553 | DocLnk lnk( path ); |
553 | emit selector()->fileSelected( lnk ); | 554 | emit selector()->fileSelected( lnk ); |
554 | } | 555 | } |
555 | } | 556 | } |
556 | #endif | 557 | #endif |
557 | } | 558 | } |
558 | 559 | ||
559 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) | 560 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) |
560 | { | 561 | { |
561 | if (!item || ( button != Qt::LeftButton) ) | 562 | if (!item || ( button != Qt::LeftButton) ) |
562 | return; | 563 | return; |
563 | 564 | ||
564 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 565 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
565 | if (!sel->isLocked() ) | 566 | if (!sel->isLocked() ) |
566 | { | 567 | { |
567 | QStringList str = QStringList::split("->", sel->text(1) ); | 568 | QStringList str = QStringList::split("->", sel->text(1) ); |
568 | if (sel->isDir() ) | 569 | if (sel->isDir() ) |
569 | { | 570 | { |
570 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); | 571 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); |
571 | emit selector()->dirSelected( m_currentDir ); | 572 | emit selector()->dirSelected( m_currentDir ); |
572 | reread( m_all ); | 573 | reread( m_all ); |
573 | } | 574 | } |
574 | else | 575 | else |
575 | { // file | 576 | { // file |
576 | qWarning("slot Clicked"); | 577 | qWarning("slot Clicked"); |
577 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); | 578 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); |
578 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 579 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); |
579 | emit selector()->fileSelected( path ); | 580 | emit selector()->fileSelected( path ); |
580 | DocLnk lnk( path ); | 581 | DocLnk lnk( path ); |
581 | emit selector()->fileSelected( lnk ); | 582 | emit selector()->fileSelected( lnk ); |
582 | } | 583 | } |
583 | } // not locked | 584 | } // not locked |
584 | } | 585 | } |
585 | 586 | ||
586 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) | 587 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) |
587 | { | 588 | { |
588 | MimeType type( info->absFilePath() ); | 589 | MimeType type( info->absFilePath() ); |
589 | if (!compliesMime( type.id() ) ) | 590 | if (!compliesMime( type.id() ) ) |
590 | return; | 591 | return; |
591 | 592 | ||
592 | QPixmap pix = type.pixmap(); | 593 | QPixmap pix = type.pixmap(); |
593 | QString dir, name; bool locked; | 594 | QString dir, name; bool locked; |
594 | if ( pix.isNull() ) | 595 | if ( pix.isNull() ) |
595 | { | 596 | { |
596 | QWMatrix matrix; | 597 | QWMatrix matrix; |
597 | QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); | 598 | QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); |
598 | matrix.scale( .4, .4 ); | 599 | matrix.scale( .4, .4 ); |
599 | pix = pixer.xForm( matrix ); | 600 | pix = pixer.xForm( matrix ); |
600 | } | 601 | } |
601 | dir = info->dirPath( true ); | 602 | dir = info->dirPath( true ); |
602 | locked = false; | 603 | locked = false; |
603 | if ( symlink ) | 604 | if ( symlink ) |
604 | name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); | 605 | name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); |
605 | else | 606 | else |
606 | { | 607 | { |
607 | name = info->fileName(); | 608 | name = info->fileName(); |
608 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || | 609 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || |
609 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) | 610 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) |
610 | { | 611 | { |
611 | locked = true; pix = Resource::loadPixmap("locked"); | 612 | locked = true; pix = Resource::loadPixmap("locked"); |
612 | } | 613 | } |
613 | } | 614 | } |
614 | (void)new OFileSelectorItem( m_view, pix, name, | 615 | (void)new OFileSelectorItem( m_view, pix, name, |
615 | info->lastModified().toString(), QString::number( info->size() ), | 616 | info->lastModified().toString(), QString::number( info->size() ), |
616 | dir, locked ); | 617 | dir, locked ); |
617 | } | 618 | } |
618 | 619 | ||
619 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) | 620 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) |
620 | { | 621 | { |
621 | bool locked = false; QString name; QPixmap pix; | 622 | bool locked = false; QString name; QPixmap pix; |
622 | 623 | ||
623 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || | 624 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || |
624 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) | 625 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) |
625 | { | 626 | { |
626 | locked = true; | 627 | locked = true; |
627 | if ( symlink ) | 628 | if ( symlink ) |
628 | pix = Resource::loadPixmap( "opie/symlink" ); | 629 | pix = Resource::loadPixmap( "opie/symlink" ); |
629 | else | 630 | else |
630 | pix = Resource::loadPixmap( "lockedfolder" ); | 631 | pix = Resource::loadPixmap( "lockedfolder" ); |
631 | } | 632 | } |
632 | else | 633 | else |
633 | pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); | 634 | pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); |
634 | 635 | ||
635 | name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : | 636 | name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : |
636 | info->fileName(); | 637 | info->fileName(); |
637 | 638 | ||
638 | (void)new OFileSelectorItem( m_view, pix, name, | 639 | (void)new OFileSelectorItem( m_view, pix, name, |
639 | info->lastModified().toString(), | 640 | info->lastModified().toString(), |
640 | QString::number( info->size() ), | 641 | QString::number( info->size() ), |
641 | info->dirPath( true ), locked, true ); | 642 | info->dirPath( true ), locked, true ); |
642 | 643 | ||
643 | 644 | ||
644 | } | 645 | } |
645 | 646 | ||
646 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) | 647 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) |
647 | { | 648 | { |
648 | } | 649 | } |
649 | 650 | ||
650 | void OFileViewFileListView::cdUP() | 651 | void OFileViewFileListView::cdUP() |
651 | { | 652 | { |
652 | QDir dir( m_currentDir ); | 653 | QDir dir( m_currentDir ); |
653 | dir.cdUp(); | 654 | dir.cdUp(); |
654 | 655 | ||
655 | if (!dir.exists() ) | 656 | if (!dir.exists() ) |
656 | m_currentDir = "/"; | 657 | m_currentDir = "/"; |
657 | else | 658 | else |
658 | m_currentDir = dir.absPath(); | 659 | m_currentDir = dir.absPath(); |
659 | 660 | ||
660 | emit selector()->dirSelected( m_currentDir ); | 661 | emit selector()->dirSelected( m_currentDir ); |
661 | reread( m_all ); | 662 | reread( m_all ); |
662 | } | 663 | } |
663 | 664 | ||
664 | void OFileViewFileListView::cdHome() | 665 | void OFileViewFileListView::cdHome() |
665 | { | 666 | { |
666 | m_currentDir = QDir::homeDirPath(); | 667 | m_currentDir = QDir::homeDirPath(); |
667 | emit selector()->dirSelected( m_currentDir ); | 668 | emit selector()->dirSelected( m_currentDir ); |
668 | reread( m_all ); | 669 | reread( m_all ); |
669 | } | 670 | } |
670 | 671 | ||
671 | void OFileViewFileListView::cdDoc() | 672 | void OFileViewFileListView::cdDoc() |
672 | { | 673 | { |
673 | m_currentDir = QPEApplication::documentDir(); | 674 | m_currentDir = QPEApplication::documentDir(); |
674 | emit selector()->dirSelected( m_currentDir ); | 675 | emit selector()->dirSelected( m_currentDir ); |
675 | reread( m_all ); | 676 | reread( m_all ); |
676 | } | 677 | } |
677 | 678 | ||
678 | void OFileViewFileListView::changeDir( const QString& dir ) | 679 | void OFileViewFileListView::changeDir( const QString& dir ) |
679 | { | 680 | { |
680 | m_currentDir = dir; | 681 | m_currentDir = dir; |
681 | emit selector()->dirSelected( m_currentDir ); | 682 | emit selector()->dirSelected( m_currentDir ); |
682 | reread( m_all ); | 683 | reread( m_all ); |
683 | } | 684 | } |
684 | 685 | ||
685 | void OFileViewFileListView::slotFSActivated( int id ) | 686 | void OFileViewFileListView::slotFSActivated( int id ) |
686 | { | 687 | { |
687 | changeDir ( m_dev[m_fsPop->text(id)] ); | 688 | changeDir ( m_dev[m_fsPop->text(id)] ); |
688 | } | 689 | } |
689 | 690 | ||
690 | /* check if the mimetype in mime | 691 | /* check if the mimetype in mime |
691 | * complies with the one which is current | 692 | * complies with the one which is current |
692 | */ | 693 | */ |
693 | /* | 694 | /* |
694 | * We've the mimetype of the file | 695 | * We've the mimetype of the file |
695 | * We need to get the stringlist of the current mimetype | 696 | * We need to get the stringlist of the current mimetype |
696 | * | 697 | * |
697 | * mime = image@slashjpeg | 698 | * mime = image@slashjpeg |
698 | * QStringList = 'image@slash*' | 699 | * QStringList = 'image@slash*' |
699 | * or QStringList = image/jpeg;image/png;application/x-ogg | 700 | * or QStringList = image/jpeg;image/png;application/x-ogg |
700 | * or QStringList = application/x-ogg;image@slash*; | 701 | * or QStringList = application/x-ogg;image@slash*; |
701 | * with all these mime filters it should get acceptes | 702 | * with all these mime filters it should get acceptes |
702 | * to do so we need to look if mime is contained inside | 703 | * to do so we need to look if mime is contained inside |
703 | * the stringlist | 704 | * the stringlist |
704 | * if it's contained return true | 705 | * if it's contained return true |
705 | * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' | 706 | * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' |
706 | * is contained in the mimefilter and then we will | 707 | * is contained in the mimefilter and then we will |
707 | * look if both are equal until the '/' | 708 | * look if both are equal until the '/' |
708 | */ | 709 | */ |
709 | 710 | ||
710 | bool OFileViewFileListView::compliesMime( const QString& str) | 711 | bool OFileViewFileListView::compliesMime( const QString& str) |
711 | { | 712 | { |
712 | if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) | 713 | if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) |
713 | return true; | 714 | return true; |
714 | 715 | ||
715 | for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) | 716 | for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) |
716 | { | 717 | { |
717 | QRegExp reg( (*it) ); | 718 | QRegExp reg( (*it) ); |
718 | reg.setWildcard( true ); | 719 | reg.setWildcard( true ); |
719 | if ( str.find( reg ) != -1 ) | 720 | if ( str.find( reg ) != -1 ) |
720 | return true; | 721 | return true; |
721 | 722 | ||
722 | } | 723 | } |
723 | return false; | 724 | return false; |
724 | } | 725 | } |
725 | /* | 726 | /* |
726 | * The listView giving access to the file system! | 727 | * The listView giving access to the file system! |
727 | */ | 728 | */ |
728 | 729 | ||
729 | class OFileViewFileSystem : public OFileViewInterface | 730 | class OFileViewFileSystem : public OFileViewInterface |
730 | { | 731 | { |
731 | public: | 732 | public: |
732 | OFileViewFileSystem( OFileSelector* ); | 733 | OFileViewFileSystem( OFileSelector* ); |
733 | ~OFileViewFileSystem(); | 734 | ~OFileViewFileSystem(); |
734 | 735 | ||
735 | QString selectedName() const; | 736 | QString selectedName() const; |
736 | QString selectedPath() const; | 737 | QString selectedPath() const; |
737 | 738 | ||
738 | QString directory()const; | 739 | QString directory()const; |
739 | void reread(); | 740 | void reread(); |
740 | int fileCount()const; | 741 | int fileCount()const; |
741 | 742 | ||
742 | QWidget* widget( QWidget* parent ); | 743 | QWidget* widget( QWidget* parent ); |
743 | void activate( const QString& ); | 744 | void activate( const QString& ); |
744 | private: | 745 | private: |
745 | OFileViewFileListView* m_view; | 746 | OFileViewFileListView* m_view; |
746 | bool m_all : 1; | 747 | bool m_all : 1; |
747 | }; | 748 | }; |
748 | 749 | ||
749 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) | 750 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) |
750 | : OFileViewInterface( sel ) | 751 | : OFileViewInterface( sel ) |
751 | { | 752 | { |
752 | m_view = 0; | 753 | m_view = 0; |
753 | m_all = false; | 754 | m_all = false; |
754 | } | 755 | } |
755 | 756 | ||
756 | OFileViewFileSystem::~OFileViewFileSystem() | 757 | OFileViewFileSystem::~OFileViewFileSystem() |
757 | { | 758 | { |
758 | } | 759 | } |
759 | 760 | ||
760 | QString OFileViewFileSystem::selectedName()const | 761 | QString OFileViewFileSystem::selectedName()const |
761 | { | 762 | { |
762 | if (!m_view ) | 763 | if (!m_view ) |
763 | return QString::null; | 764 | return QString::null; |
764 | 765 | ||
765 | QString cFN=currentFileName(); | 766 | QString cFN=currentFileName(); |
766 | if (cFN.startsWith("/")) return cFN; | 767 | if (cFN.startsWith("/")) return cFN; |
767 | return m_view->currentDir() + "/" + cFN; | 768 | return m_view->currentDir() + "/" + cFN; |
768 | } | 769 | } |
769 | 770 | ||
770 | QString OFileViewFileSystem::selectedPath()const | 771 | QString OFileViewFileSystem::selectedPath()const |
771 | { | 772 | { |
772 | return QString::null; | 773 | return QString::null; |
773 | } | 774 | } |
774 | 775 | ||
775 | QString OFileViewFileSystem::directory()const | 776 | QString OFileViewFileSystem::directory()const |
776 | { | 777 | { |
777 | if (!m_view) | 778 | if (!m_view) |
778 | return QString::null; | 779 | return QString::null; |
779 | 780 | ||
780 | OFileSelectorItem* item = m_view->currentItem(); | 781 | OFileSelectorItem* item = m_view->currentItem(); |
781 | if (!item ) | 782 | if (!item ) |
782 | return QString::null; | 783 | return QString::null; |
783 | 784 | ||
784 | return QDir(item->directory() ).absPath(); | 785 | return QDir(item->directory() ).absPath(); |
785 | } | 786 | } |
786 | 787 | ||
787 | void OFileViewFileSystem::reread() | 788 | void OFileViewFileSystem::reread() |
788 | { | 789 | { |
789 | if (!m_view) | 790 | if (!m_view) |
790 | return; | 791 | return; |
791 | 792 | ||
792 | m_view->reread( m_all ); | 793 | m_view->reread( m_all ); |
793 | } | 794 | } |
794 | 795 | ||
795 | int OFileViewFileSystem::fileCount()const | 796 | int OFileViewFileSystem::fileCount()const |
796 | { | 797 | { |
797 | if (!m_view ) | 798 | if (!m_view ) |
798 | return -1; | 799 | return -1; |
799 | return m_view->fileCount(); | 800 | return m_view->fileCount(); |
800 | } | 801 | } |
801 | 802 | ||
802 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) | 803 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) |
803 | { | 804 | { |
804 | if (!m_view ) | 805 | if (!m_view ) |
805 | { | 806 | { |
806 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); | 807 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); |
807 | } | 808 | } |
808 | return m_view; | 809 | return m_view; |
809 | } | 810 | } |
810 | 811 | ||
811 | void OFileViewFileSystem::activate( const QString& str) | 812 | void OFileViewFileSystem::activate( const QString& str) |
812 | { | 813 | { |
813 | m_all = (str != QObject::tr("Files") ); | 814 | m_all = (str != QObject::tr("Files") ); |
814 | } | 815 | } |
815 | 816 | ||
816 | 817 | ||
817 | } | 818 | } |
818 | /* Selector */ | 819 | /* Selector */ |
819 | /** | 820 | /** |
820 | * @short new and complete c'tor | 821 | * @short new and complete c'tor |
821 | * | 822 | * |
822 | * Create a OFileSelector to let the user select a file. It can | 823 | * Create a OFileSelector to let the user select a file. It can |
823 | * either be used to open a file, select a save name in a dir or | 824 | * either be used to open a file, select a save name in a dir or |
824 | * as a dropin for the FileSelector. | 825 | * as a dropin for the FileSelector. |
825 | * | 826 | * |
826 | * <pre> | 827 | * <pre> |
827 | * QMap<QString, QStringList> mimeTypes; | 828 | * QMap<QString, QStringList> mimeTypes; |
828 | * QStringList types; | 829 | * QStringList types; |
829 | * types << "text@slash* "; | 830 | * types << "text@slash* "; |
830 | * types << "audio@slash*"; | 831 | * types << "audio@slash*"; |
831 | * mimeTypes.insert( tr("Audio and Text"), types ); | 832 | * mimeTypes.insert( tr("Audio and Text"), types ); |
832 | * mimeTypes.insert( tr("All"), "*@slash*); | 833 | * mimeTypes.insert( tr("All"), "*@slash*); |
833 | * | 834 | * |
834 | * now you could create your fileselector | 835 | * now you could create your fileselector |
835 | * </pre> | 836 | * </pre> |
836 | * | 837 | * |
837 | * | 838 | * |
838 | * @param parent the parent of this widget | 839 | * @param parent the parent of this widget |
839 | * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) | 840 | * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) |
840 | * @param sel The selector to be used | 841 | * @param sel The selector to be used |
841 | * @param dirName The name of the dir to start int | 842 | * @param dirName The name of the dir to start int |
842 | * @param fileName The fileName placed in the fileselector lineedit | 843 | * @param fileName The fileName placed in the fileselector lineedit |
843 | * @param mimetypes The MimeType map of used mimetypes | 844 | * @param mimetypes The MimeType map of used mimetypes |
844 | * @param showNew Show a New Button. Most likely to be used in the FileSelector view. | 845 | * @param showNew Show a New Button. Most likely to be used in the FileSelector view. |
845 | * @param showClose Show a Close Button. Most likely to be used in FileSelector view. | 846 | * @param showClose Show a Close Button. Most likely to be used in FileSelector view. |
846 | * | 847 | * |
847 | */ | 848 | */ |
848 | OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, | 849 | OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, |
849 | const QString& dirName, const QString& fileName, | 850 | const QString& dirName, const QString& fileName, |
850 | const MimeTypes& mimetypes, | 851 | const MimeTypes& mimetypes, |
851 | bool showNew, bool showClose) | 852 | bool showNew, bool showClose) |
852 | :QWidget( parent, "OFileSelector" ) | 853 | :QWidget( parent, "OFileSelector" ) |
853 | { | 854 | { |
854 | m_current = 0; | 855 | m_current = 0; |
855 | m_shNew = showNew; | 856 | m_shNew = showNew; |
856 | m_shClose = showClose; | 857 | m_shClose = showClose; |
857 | m_mimeType = mimetypes; | 858 | m_mimeType = mimetypes; |
858 | m_startDir = dirName; | 859 | m_startDir = dirName; |
859 | 860 | ||
860 | m_mode = mode; | 861 | m_mode = mode; |
861 | m_selector = sel; | 862 | m_selector = sel; |
862 | 863 | ||
863 | initUI(); | 864 | initUI(); |
864 | m_lneEdit->setText( fileName ); | 865 | m_lneEdit->setText( fileName ); |
865 | initMime(); | 866 | initMime(); |
866 | initViews(); | 867 | initViews(); |
867 | 868 | ||
868 | QString str; | 869 | QString str; |
869 | switch ( m_selector ) | 870 | switch ( m_selector ) |
870 | { | 871 | { |
871 | default: | 872 | default: |
872 | case Normal: | 873 | case Normal: |
873 | str = QObject::tr("Documents"); | 874 | str = QObject::tr("Documents"); |
874 | m_cmbView->setCurrentItem( 0 ); | 875 | m_cmbView->setCurrentItem( 0 ); |
875 | break; | 876 | break; |
876 | case Extended: | 877 | case Extended: |
877 | str = QObject::tr("Files"); | 878 | str = QObject::tr("Files"); |
878 | m_cmbView->setCurrentItem( 1 ); | 879 | m_cmbView->setCurrentItem( 1 ); |
879 | break; | 880 | break; |
880 | case ExtendedAll: | 881 | case ExtendedAll: |
881 | str = QObject::tr("All Files"); | 882 | str = QObject::tr("All Files"); |
882 | m_cmbView->setCurrentItem( 2 ); | 883 | m_cmbView->setCurrentItem( 2 ); |
883 | break; | 884 | break; |
884 | } | 885 | } |
885 | slotViewChange( str ); | 886 | slotViewChange( str ); |
886 | 887 | ||
887 | } | 888 | } |
888 | 889 | ||
889 | 890 | ||
890 | /** | 891 | /** |
891 | * This a convience c'tor to just substitute the use of FileSelector | 892 | * This a convience c'tor to just substitute the use of FileSelector |
892 | */ | 893 | */ |
893 | OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, | 894 | OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, |
894 | bool showNew, bool showClose ) | 895 | bool showNew, bool showClose ) |
895 | : QWidget( parent, name ) | 896 | : QWidget( parent, name ) |
896 | { | 897 | { |
897 | m_current = 0; | 898 | m_current = 0; |
898 | m_shNew = showNew; | 899 | m_shNew = showNew; |
899 | m_shClose = showClose; | 900 | m_shClose = showClose; |
900 | m_startDir = QPEApplication::documentDir(); | 901 | m_startDir = QPEApplication::documentDir(); |
901 | 902 | ||
902 | if (!mimeFilter.isEmpty() ) | 903 | if (!mimeFilter.isEmpty() ) |
903 | m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); | 904 | m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); |
904 | 905 | ||
905 | m_mode = OFileSelector::FileSelector; | 906 | m_mode = OFileSelector::FileSelector; |
906 | m_selector = OFileSelector::Normal; | 907 | m_selector = OFileSelector::Normal; |
907 | 908 | ||
908 | initUI(); | 909 | initUI(); |
909 | initMime(); | 910 | initMime(); |
910 | initViews(); | 911 | initViews(); |
911 | m_cmbView->setCurrentItem( 0 ); | 912 | m_cmbView->setCurrentItem( 0 ); |
912 | slotViewChange( QObject::tr("Documents") ); | 913 | slotViewChange( QObject::tr("Documents") ); |
913 | } | 914 | } |
914 | 915 | ||
915 | /* | 916 | /* |
916 | * INIT UI will set up the basic GUI | 917 | * INIT UI will set up the basic GUI |
917 | * Layout: Simple VBoxLayout | 918 | * Layout: Simple VBoxLayout |
918 | * On top a WidgetStack containing the Views... | 919 | * On top a WidgetStack containing the Views... |
919 | * - List View | 920 | * - List View |
920 | * - Document View | 921 | * - Document View |
921 | * Below we will have a Label + LineEdit | 922 | * Below we will have a Label + LineEdit |
922 | * Below we will have two ComoBoxes one for choosing the view one for | 923 | * Below we will have two ComoBoxes one for choosing the view one for |
923 | * choosing the mimetype | 924 | * choosing the mimetype |
924 | */ | 925 | */ |
925 | void OFileSelector::initUI() | 926 | void OFileSelector::initUI() |
926 | { | 927 | { |
927 | QVBoxLayout* lay = new QVBoxLayout( this ); | 928 | QVBoxLayout* lay = new QVBoxLayout( this ); |
928 | 929 | ||
929 | m_stack = new QWidgetStack( this ); | 930 | m_stack = new QWidgetStack( this ); |
930 | lay->addWidget( m_stack, 1000 ); | 931 | lay->addWidget( m_stack, 1000 ); |
931 | 932 | ||
932 | m_nameBox = new QHBox( this ); | 933 | m_nameBox = new QHBox( this ); |
933 | (void)new QLabel( tr("Name:"), m_nameBox ); | 934 | (void)new QLabel( tr("Name:"), m_nameBox ); |
934 | m_lneEdit = new QLineEdit( m_nameBox ); | 935 | m_lneEdit = new QLineEdit( m_nameBox ); |
935 | m_lneEdit ->installEventFilter(this); | 936 | m_lneEdit ->installEventFilter(this); |
936 | lay->addWidget( m_nameBox ); | 937 | lay->addWidget( m_nameBox ); |
937 | 938 | ||
938 | m_cmbBox = new QHBox( this ); | 939 | m_cmbBox = new QHBox( this ); |
939 | m_cmbView = new QComboBox( m_cmbBox ); | 940 | m_cmbView = new QComboBox( m_cmbBox ); |
940 | m_cmbMime = new QComboBox( m_cmbBox ); | 941 | m_cmbMime = new QComboBox( m_cmbBox ); |
941 | lay->addWidget( m_cmbBox ); | 942 | lay->addWidget( m_cmbBox ); |
942 | } | 943 | } |
943 | 944 | ||
944 | /* | 945 | /* |
945 | * This will make sure that the return key in the name edit causes dialogs to close | 946 | * This will make sure that the return key in the name edit causes dialogs to close |
946 | */ | 947 | */ |
947 | 948 | ||
948 | bool OFileSelector::eventFilter (QObject *o, QEvent *e) | 949 | bool OFileSelector::eventFilter (QObject *o, QEvent *e) |
949 | { | 950 | { |
950 | if ( e->type() == QEvent::KeyPress ) | 951 | if ( e->type() == QEvent::KeyPress ) |
951 | { | 952 | { |
952 | QKeyEvent *k = (QKeyEvent *)e; | 953 | QKeyEvent *k = (QKeyEvent *)e; |
953 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) | 954 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) |
954 | { | 955 | { |
955 | emit ok(); | 956 | emit ok(); |
956 | return true; | 957 | return true; |
957 | } | 958 | } |
958 | } | 959 | } |
959 | return false; | 960 | return false; |
960 | } | 961 | } |
961 | 962 | ||
962 | /* | 963 | /* |
963 | * This will insert the MimeTypes into the Combo Box | 964 | * This will insert the MimeTypes into the Combo Box |
964 | * And also connect the changed signal | 965 | * And also connect the changed signal |
965 | * | 966 | * |
966 | * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes | 967 | * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes |
967 | */ | 968 | */ |
968 | void OFileSelector::initMime() | 969 | void OFileSelector::initMime() |
969 | { | 970 | { |
970 | MimeTypes::Iterator it; | 971 | MimeTypes::Iterator it; |
971 | for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) | 972 | for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) |
972 | { | 973 | { |
973 | m_cmbMime->insertItem( it.key() ); | 974 | m_cmbMime->insertItem( it.key() ); |
974 | } | 975 | } |
975 | m_cmbMime->setCurrentItem( 0 ); | 976 | m_cmbMime->setCurrentItem( 0 ); |
976 | 977 | ||
977 | connect( m_cmbMime, SIGNAL(activated(int) ), | 978 | connect( m_cmbMime, SIGNAL(activated(int) ), |
978 | this, SLOT(slotMimeTypeChanged() ) ); | 979 | this, SLOT(slotMimeTypeChanged() ) ); |
979 | 980 | ||
980 | } | 981 | } |
981 | 982 | ||
982 | void OFileSelector::initViews() | 983 | void OFileSelector::initViews() |
983 | { | 984 | { |
984 | m_cmbView->insertItem( QObject::tr("Documents") ); | 985 | m_cmbView->insertItem( QObject::tr("Documents") ); |
985 | m_cmbView->insertItem( QObject::tr("Files") ); | 986 | m_cmbView->insertItem( QObject::tr("Files") ); |
986 | m_cmbView->insertItem( QObject::tr("All Files") ); | 987 | m_cmbView->insertItem( QObject::tr("All Files") ); |
987 | connect(m_cmbView, SIGNAL(activated(const QString&) ), | 988 | connect(m_cmbView, SIGNAL(activated(const QString&) ), |
988 | this, SLOT(slotViewChange(const QString&) ) ); | 989 | this, SLOT(slotViewChange(const QString&) ) ); |
989 | 990 | ||
990 | 991 | ||
991 | m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); | 992 | m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); |
992 | 993 | ||
993 | /* see above why add both */ | 994 | /* see above why add both */ |
994 | OFileViewInterface* in = new OFileViewFileSystem( this ); | 995 | OFileViewInterface* in = new OFileViewFileSystem( this ); |
995 | m_views.insert( QObject::tr("Files"), in ); | 996 | m_views.insert( QObject::tr("Files"), in ); |
996 | m_views.insert( QObject::tr("All Files"), in ); | 997 | m_views.insert( QObject::tr("All Files"), in ); |
997 | } | 998 | } |
998 | 999 | ||
999 | /** | 1000 | /** |
1000 | * d'tor | 1001 | * d'tor |
1001 | */ | 1002 | */ |
1002 | OFileSelector::~OFileSelector() | 1003 | OFileSelector::~OFileSelector() |
1003 | { | 1004 | { |
1004 | } | 1005 | } |
1005 | 1006 | ||
1006 | 1007 | ||
1007 | 1008 | ||
1008 | /** | 1009 | /** |
1009 | * Convience function for the fileselector | 1010 | * Convience function for the fileselector |
1010 | * make sure to delete the DocLnk | 1011 | * make sure to delete the DocLnk |
1011 | * | 1012 | * |
1012 | * @see DocLnk | 1013 | * @see DocLnk |
1013 | * @todo remove in ODP | 1014 | * @todo remove in ODP |
1014 | */ | 1015 | */ |
1015 | const DocLnk* OFileSelector::selected() | 1016 | const DocLnk* OFileSelector::selected() |
1016 | { | 1017 | { |
1017 | DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); | 1018 | DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); |
1018 | return lnk; | 1019 | return lnk; |
1019 | } | 1020 | } |
1020 | 1021 | ||
1021 | /** | 1022 | /** |
1022 | * | 1023 | * |
1023 | * @return the name of the selected file | 1024 | * @return the name of the selected file |
1024 | */ | 1025 | */ |
1025 | QString OFileSelector::selectedName()const | 1026 | QString OFileSelector::selectedName()const |
1026 | { | 1027 | { |
1027 | return currentView()->selectedName(); | 1028 | return currentView()->selectedName(); |
1028 | } | 1029 | } |
1029 | 1030 | ||
1030 | 1031 | ||
1031 | /** | 1032 | /** |
1032 | * @return the selected path | 1033 | * @return the selected path |
1033 | */ | 1034 | */ |
1034 | QString OFileSelector::selectedPath()const | 1035 | QString OFileSelector::selectedPath()const |
1035 | { | 1036 | { |
1036 | return currentView()->selectedPath(); | 1037 | return currentView()->selectedPath(); |
1037 | } | 1038 | } |
1038 | 1039 | ||
1039 | /** | 1040 | /** |
1040 | * @return the directory name | 1041 | * @return the directory name |
1041 | */ | 1042 | */ |
1042 | QString OFileSelector::directory()const | 1043 | QString OFileSelector::directory()const |
1043 | { | 1044 | { |
1044 | return currentView()->directory(); | 1045 | return currentView()->directory(); |
1045 | } | 1046 | } |
1046 | 1047 | ||
1047 | /** | 1048 | /** |
1048 | * @return a DocLnk for the selected document | 1049 | * @return a DocLnk for the selected document |
1049 | */ | 1050 | */ |
1050 | DocLnk OFileSelector::selectedDocument()const | 1051 | DocLnk OFileSelector::selectedDocument()const |
1051 | { | 1052 | { |
1052 | return currentView()->selectedDocument(); | 1053 | return currentView()->selectedDocument(); |
1053 | } | 1054 | } |
1054 | 1055 | ||
1055 | /** | 1056 | /** |
1056 | * @return the number of items for the current view | 1057 | * @return the number of items for the current view |
1057 | */ | 1058 | */ |
1058 | int OFileSelector::fileCount()const | 1059 | int OFileSelector::fileCount()const |
1059 | { | 1060 | { |
1060 | return currentView()->fileCount(); | 1061 | return currentView()->fileCount(); |
1061 | } | 1062 | } |
1062 | 1063 | ||
1063 | /** | 1064 | /** |
1064 | * @return reparse the file content | 1065 | * @return reparse the file content |
1065 | */ | 1066 | */ |
1066 | void OFileSelector::reread() | 1067 | void OFileSelector::reread() |
1067 | { | 1068 | { |
1068 | return currentView()->reread(); | 1069 | return currentView()->reread(); |
1069 | } | 1070 | } |
1070 | 1071 | ||
1071 | OFileViewInterface* OFileSelector::currentView()const | 1072 | OFileViewInterface* OFileSelector::currentView()const |
1072 | { | 1073 | { |
1073 | return m_current; | 1074 | return m_current; |
1074 | } | 1075 | } |
1075 | 1076 | ||
1076 | bool OFileSelector::showNew()const | 1077 | bool OFileSelector::showNew()const |
1077 | { | 1078 | { |
1078 | return m_shNew; | 1079 | return m_shNew; |
1079 | } | 1080 | } |
1080 | 1081 | ||
1081 | bool OFileSelector::showClose()const | 1082 | bool OFileSelector::showClose()const |
1082 | { | 1083 | { |
1083 | return m_shClose; | 1084 | return m_shClose; |
1084 | } | 1085 | } |
1085 | 1086 | ||
1086 | MimeTypes OFileSelector::mimeTypes()const | 1087 | MimeTypes OFileSelector::mimeTypes()const |
1087 | { | 1088 | { |
1088 | return m_mimeType; | 1089 | return m_mimeType; |
1089 | } | 1090 | } |
1090 | 1091 | ||
1091 | /** | 1092 | /** |
1092 | * @return the Mode of the OFileSelector | 1093 | * @return the Mode of the OFileSelector |
1093 | */ | 1094 | */ |
1094 | int OFileSelector::mode()const | 1095 | int OFileSelector::mode()const |
1095 | { | 1096 | { |
1096 | return m_mode; | 1097 | return m_mode; |
1097 | } | 1098 | } |
1098 | 1099 | ||
1099 | 1100 | ||
1100 | /** | 1101 | /** |
1101 | * @return the Selector of the OFileSelector | 1102 | * @return the Selector of the OFileSelector |
1102 | */ | 1103 | */ |
1103 | int OFileSelector::selector()const | 1104 | int OFileSelector::selector()const |
1104 | { | 1105 | { |
1105 | return m_selector; | 1106 | return m_selector; |
1106 | } | 1107 | } |
1107 | 1108 | ||
1108 | QStringList OFileSelector::currentMimeType()const | 1109 | QStringList OFileSelector::currentMimeType()const |
1109 | { | 1110 | { |
1110 | return m_mimeType[m_cmbMime->currentText()]; | 1111 | return m_mimeType[m_cmbMime->currentText()]; |
1111 | } | 1112 | } |
1112 | 1113 | ||
1113 | void OFileSelector::slotMimeTypeChanged() | 1114 | void OFileSelector::slotMimeTypeChanged() |
1114 | { | 1115 | { |
1115 | reread(); | 1116 | reread(); |
1116 | } | 1117 | } |
1117 | 1118 | ||
1118 | void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) | 1119 | void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) |
1119 | { | 1120 | { |
1120 | m_lneEdit->setText( lnk.name() ); | 1121 | m_lneEdit->setText( lnk.name() ); |
1121 | emit fileSelected( lnk ); | 1122 | emit fileSelected( lnk ); |
1122 | emit fileSelected( lnk.name() ); | 1123 | emit fileSelected( lnk.name() ); |
1123 | } | 1124 | } |
1124 | 1125 | ||
1125 | void OFileSelector::slotFileBridge( const QString& str) | 1126 | void OFileSelector::slotFileBridge( const QString& str) |
1126 | { | 1127 | { |
1127 | DocLnk lnk( str ); | 1128 | DocLnk lnk( str ); |
1128 | emit fileSelected( lnk ); | 1129 | emit fileSelected( lnk ); |
1129 | } | 1130 | } |
1130 | 1131 | ||
1131 | void OFileSelector::slotViewChange( const QString& view ) | 1132 | void OFileSelector::slotViewChange( const QString& view ) |
1132 | { | 1133 | { |
1133 | OFileViewInterface* interface = m_views[view]; | 1134 | OFileViewInterface* interface = m_views[view]; |
1134 | if (!interface) | 1135 | if (!interface) |
1135 | return; | 1136 | return; |
1136 | 1137 | ||
1137 | interface->activate( view ); | 1138 | interface->activate( view ); |
1138 | if (m_current) | 1139 | if (m_current) |
1139 | m_stack->removeWidget( m_current->widget( m_stack ) ); | 1140 | m_stack->removeWidget( m_current->widget( m_stack ) ); |
1140 | 1141 | ||
1141 | static int id = 1; | 1142 | static int id = 1; |
1142 | 1143 | ||
1143 | m_stack->addWidget( interface->widget(m_stack), id ); | 1144 | m_stack->addWidget( interface->widget(m_stack), id ); |
1144 | m_stack->raiseWidget( id ); | 1145 | m_stack->raiseWidget( id ); |
1145 | 1146 | ||
1146 | interface->reread(); | 1147 | interface->reread(); |
1147 | m_current = interface; | 1148 | m_current = interface; |
1148 | 1149 | ||
1149 | id++; | 1150 | id++; |
1150 | } | 1151 | } |
1151 | 1152 | ||
1152 | void OFileSelector::setNewVisible( bool b ) | 1153 | void OFileSelector::setNewVisible( bool b ) |
1153 | { | 1154 | { |
1154 | m_shNew = b; | 1155 | m_shNew = b; |
1155 | currentView()->reread(); | 1156 | currentView()->reread(); |
1156 | } | 1157 | } |
1157 | 1158 | ||
1158 | void OFileSelector::setCloseVisible( bool b ) | 1159 | void OFileSelector::setCloseVisible( bool b ) |
1159 | { | 1160 | { |
1160 | m_shClose = b; | 1161 | m_shClose = b; |
1161 | currentView()->reread(); | 1162 | currentView()->reread(); |
1162 | } | 1163 | } |
1163 | 1164 | ||
1164 | void OFileSelector::setNameVisible( bool b ) | 1165 | void OFileSelector::setNameVisible( bool b ) |
1165 | { | 1166 | { |
1166 | if ( b ) | 1167 | if ( b ) |
1167 | m_nameBox->show(); | 1168 | m_nameBox->show(); |
1168 | else | 1169 | else |
1169 | m_nameBox->hide(); | 1170 | m_nameBox->hide(); |
1170 | } | 1171 | } |
1171 | 1172 | ||
1172 | } | 1173 | } |
1173 | } | 1174 | } |
diff --git a/libopie2/opieui/fileselector/ofileselector.h b/libopie2/opieui/fileselector/ofileselector.h index 2205963..8bcd9ee 100644 --- a/libopie2/opieui/fileselector/ofileselector.h +++ b/libopie2/opieui/fileselector/ofileselector.h | |||
@@ -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) 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 | ||
48 | class QLineEdit; | 48 | class QLineEdit; |
49 | class QComboBox; | 49 | class QComboBox; |
50 | class QWidgetStack; | 50 | class QWidgetStack; |
51 | class QHBox; | 51 | class QHBox; |
52 | 52 | ||
53 | typedef QMap<QString, QStringList> MimeTypes; | 53 | typedef QMap<QString, QStringList> MimeTypes; |
54 | 54 | ||
55 | namespace Opie { | 55 | namespace Opie { |
56 | namespace Ui { | 56 | namespace Ui { |
57 | 57 | ||
58 | namespace Private { | 58 | namespace Internal { |
59 | class OFileViewInterface; | 59 | class OFileViewInterface; |
60 | class OFileViewFileListView; | 60 | class OFileViewFileListView; |
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
65 | * @short a dropin replacement for the FileSelector | 65 | * @short a dropin replacement for the FileSelector |
66 | * | 66 | * |
67 | * This class is first used insert the OFileDialog. | 67 | * This class is first used insert the OFileDialog. |
68 | * It supports multiple view and mimetype filtering for now. | 68 | * It supports multiple view and mimetype filtering for now. |
69 | * | 69 | * |
70 | * @see OFileDialog | 70 | * @see OFileDialog |
71 | * @see FileSelector | 71 | * @see FileSelector |
72 | * @author zecke | 72 | * @author zecke |
73 | * @version 0.1 | 73 | * @version 0.1 |
74 | */ | 74 | */ |
75 | class OFileSelector : public QWidget | 75 | class OFileSelector : public QWidget |
76 | { | 76 | { |
77 | Q_OBJECT | 77 | Q_OBJECT |
78 | friend class Private::OFileViewInterface; | 78 | friend class Internal::OFileViewInterface; |
79 | friend class Private::OFileViewFileListView; | 79 | friend class Internal::OFileViewFileListView; |
80 | 80 | ||
81 | public: | 81 | public: |
82 | /** | 82 | /** |
83 | * The Mode of the Fileselector | 83 | * The Mode of the Fileselector |
84 | * Open = Open A File | 84 | * Open = Open A File |
85 | * Save = Save a File | 85 | * Save = Save a File |
86 | * FILESELECTOR = As A GUI in a screen to select a file | 86 | * FILESELECTOR = As A GUI in a screen to select a file |
87 | */ | 87 | */ |
88 | 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 }; |
89 | // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; | 89 | // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; |
90 | /** | 90 | /** |
91 | * Normal = The old FileSelector | 91 | * Normal = The old FileSelector |
92 | * Extended = Dir View | 92 | * Extended = Dir View |
93 | * ExtendedAll = Dir View with all hidden files | 93 | * ExtendedAll = Dir View with all hidden files |
94 | * Default = What the vendor considers best | 94 | * Default = What the vendor considers best |
95 | */ | 95 | */ |
96 | 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 }; |
97 | // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; | 97 | // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; |
98 | 98 | ||
99 | OFileSelector(QWidget* parent, int mode, int selector, | 99 | OFileSelector(QWidget* parent, int mode, int selector, |
100 | const QString& dirName, | 100 | const QString& dirName, |
101 | const QString& fileName, | 101 | const QString& fileName, |
102 | const MimeTypes& mimetypes = MimeTypes(), | 102 | const MimeTypes& mimetypes = MimeTypes(), |
103 | bool newVisible = FALSE, bool closeVisible = FALSE ); | 103 | bool newVisible = FALSE, bool closeVisible = FALSE ); |
104 | 104 | ||
105 | OFileSelector(const QString& mimeFilter, QWidget* parent, | 105 | OFileSelector(const QString& mimeFilter, QWidget* parent, |
106 | const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); | 106 | const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); |
107 | ~OFileSelector(); | 107 | ~OFileSelector(); |
108 | 108 | ||
109 | const DocLnk* selected(); | 109 | const DocLnk* selected(); |
110 | 110 | ||
111 | QString selectedName()const; | 111 | QString selectedName()const; |
112 | QString selectedPath()const; | 112 | QString selectedPath()const; |
113 | QString directory()const; | 113 | QString directory()const; |
114 | 114 | ||
115 | DocLnk selectedDocument()const; | 115 | DocLnk selectedDocument()const; |
116 | 116 | ||
117 | int fileCount()const; | 117 | int fileCount()const; |
118 | void reread(); | 118 | void reread(); |
119 | 119 | ||
120 | int mode()const; | 120 | int mode()const; |
121 | int selector()const; | 121 | int selector()const; |
122 | 122 | ||
123 | /** | 123 | /** |
124 | * Set the Icon visible | 124 | * Set the Icon visible |
125 | * @param b Show or Hide the New Button | 125 | * @param b Show or Hide the New Button |
126 | */ | 126 | */ |
127 | void setNewVisible( bool b ); | 127 | void setNewVisible( bool b ); |
128 | 128 | ||
129 | /** | 129 | /** |
130 | * Set the Icon visible | 130 | * Set the Icon visible |
131 | */ | 131 | */ |
132 | void setCloseVisible( bool b ); | 132 | void setCloseVisible( bool b ); |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * Set the Name Line visible | 135 | * Set the Name Line visible |
136 | */ | 136 | */ |
137 | void setNameVisible( bool b ); | 137 | void setNameVisible( bool b ); |
138 | 138 | ||
139 | signals: | 139 | signals: |
140 | /** | 140 | /** |
141 | * dirSelected is emitted whenever changed into a different dir | 141 | * dirSelected is emitted whenever changed into a different dir |
142 | */ | 142 | */ |
143 | void dirSelected( const QString& ); | 143 | void dirSelected( const QString& ); |
144 | 144 | ||
145 | /** | 145 | /** |
146 | * fileSelected is emitted when a file is selected | 146 | * fileSelected is emitted when a file is selected |
147 | * it uses a DocLnk as parameter | 147 | * it uses a DocLnk as parameter |
148 | */ | 148 | */ |
149 | void fileSelected( const DocLnk& ); | 149 | void fileSelected( const DocLnk& ); |
150 | 150 | ||
151 | /** | 151 | /** |
152 | * fileSelected is emitted when a file is selected | 152 | * fileSelected is emitted when a file is selected |
153 | * the complete path is a parameter | 153 | * the complete path is a parameter |
154 | */ | 154 | */ |
155 | void fileSelected( const QString& ); | 155 | void fileSelected( const QString& ); |
156 | 156 | ||
157 | /** | 157 | /** |
158 | * Create a new File with a DocLnk | 158 | * Create a new File with a DocLnk |
159 | */ | 159 | */ |
160 | void newSelected( const DocLnk& ); | 160 | void newSelected( const DocLnk& ); |
161 | 161 | ||
162 | void closeMe(); | 162 | void closeMe(); |
163 | 163 | ||
164 | /** | 164 | /** |
165 | * 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 |
166 | * in the line edit | 166 | * in the line edit |
167 | */ | 167 | */ |
168 | void ok(); | 168 | void ok(); |
169 | void cancel(); | 169 | void cancel(); |
170 | 170 | ||
171 | /* used by the ViewInterface */ | 171 | /* used by the ViewInterface */ |
172 | private: | 172 | private: |
173 | bool showNew()const; | 173 | bool showNew()const; |
174 | bool showClose()const; | 174 | bool showClose()const; |
175 | MimeTypes mimeTypes()const; | 175 | MimeTypes mimeTypes()const; |
176 | QStringList currentMimeType()const; | 176 | QStringList currentMimeType()const; |
177 | 177 | ||
178 | private: | 178 | private: |
179 | /* inits the Widgets */ | 179 | /* inits the Widgets */ |
180 | void initUI(); | 180 | void initUI(); |
181 | /* inits the MimeType ComboBox content + connects signals and slots */ | 181 | /* inits the MimeType ComboBox content + connects signals and slots */ |
182 | void initMime(); | 182 | void initMime(); |
183 | /* init the Views :) */ | 183 | /* init the Views :) */ |
184 | void initViews(); | 184 | void initViews(); |
185 | 185 | ||
186 | private: | 186 | private: |
187 | QLineEdit* m_lneEdit; // the LineEdit for the Name | 187 | QLineEdit* m_lneEdit; // the LineEdit for the Name |
188 | 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 |
189 | QWidgetStack* m_stack; // our widget stack which will contain the views | 189 | QWidgetStack* m_stack; // our widget stack which will contain the views |
190 | Private::OFileViewInterface* currentView() const; // returns the currentView | 190 | Internal::OFileViewInterface* currentView() const; // returns the currentView |
191 | Private::OFileViewInterface* m_current; // here is the view saved | 191 | Internal::OFileViewInterface* m_current; // here is the view saved |
192 | bool m_shNew : 1; // should we show New? | 192 | bool m_shNew : 1; // should we show New? |
193 | bool m_shClose : 1; // should we show Close? | 193 | bool m_shClose : 1; // should we show Close? |
194 | MimeTypes m_mimeType; // list of mimetypes | 194 | MimeTypes m_mimeType; // list of mimetypes |
195 | 195 | ||
196 | QMap<QString, Private::OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr | 196 | QMap<QString, Internal::OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr |
197 | QHBox* m_nameBox; // the LineEdit + Label is hold here | 197 | QHBox* m_nameBox; // the LineEdit + Label is hold here |
198 | QHBox* m_cmbBox; // this holds the two combo boxes | 198 | QHBox* m_cmbBox; // this holds the two combo boxes |
199 | 199 | ||
200 | QString m_startDir; | 200 | QString m_startDir; |
201 | int m_mode; | 201 | int m_mode; |
202 | int m_selector; | 202 | int m_selector; |
203 | 203 | ||
204 | struct Data; // used for future versions | 204 | struct Data; // used for future versions |
205 | Data *d; | 205 | Data *d; |
206 | 206 | ||
207 | private slots: | 207 | private slots: |
208 | void slotMimeTypeChanged(); | 208 | void slotMimeTypeChanged(); |
209 | 209 | ||
210 | /* 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 */ |
211 | void slotDocLnkBridge( const DocLnk& ); | 211 | void slotDocLnkBridge( const DocLnk& ); |
212 | void slotFileBridge( const QString& ); | 212 | void slotFileBridge( const QString& ); |
213 | void slotViewChange( const QString& ); | 213 | void slotViewChange( const QString& ); |
214 | 214 | ||
215 | bool eventFilter (QObject *o, QEvent *e); | 215 | bool eventFilter (QObject *o, QEvent *e); |
216 | 216 | ||
217 | }; | 217 | }; |
218 | 218 | ||
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | #endif | 222 | #endif |
diff --git a/libopie2/opieui/fileselector/ofileselector_p.h b/libopie2/opieui/fileselector/ofileselector_p.h index 376dc98..a3ef8e2 100644 --- a/libopie2/opieui/fileselector/ofileselector_p.h +++ b/libopie2/opieui/fileselector/ofileselector_p.h | |||
@@ -1,193 +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 | ||
53 | typedef QMap<QString, QStringList> MimeTypes; | 53 | typedef QMap<QString, QStringList> MimeTypes; |
54 | 54 | ||
55 | /* the View Interface */ | 55 | /* the View Interface */ |
56 | class QFileInfo; | 56 | class QFileInfo; |
57 | class QToolButton; | 57 | class QToolButton; |
58 | 58 | ||
59 | namespace Opie{ | 59 | namespace Opie{ |
60 | namespace Ui{ | 60 | namespace Ui{ |
61 | class OFileSelector; | 61 | class OFileSelector; |
62 | namespace Private { | 62 | namespace Internal { |
63 | 63 | ||
64 | class OFileViewInterface | 64 | class OFileViewInterface |
65 | { | 65 | { |
66 | public: | 66 | public: |
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; |
78 | protected: | 78 | protected: |
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; |
86 | protected: | 86 | protected: |
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 | ||
95 | private: | 95 | private: |
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*/ |
102 | class ODocumentFileView : public OFileViewInterface | 102 | class ODocumentFileView : public OFileViewInterface |
103 | { | 103 | { |
104 | public: | 104 | public: |
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 | ||
118 | private: | 118 | private: |
119 | mutable FileSelector* m_selector; | 119 | mutable FileSelector* m_selector; |
120 | 120 | ||
121 | }; | 121 | }; |
122 | 122 | ||
123 | 123 | ||
124 | class OFileSelectorItem : public QListViewItem | 124 | class OFileSelectorItem : public QListViewItem |
125 | { | 125 | { |
126 | public: | 126 | public: |
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 | ||
138 | private: | 138 | private: |
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 | ||
144 | class OFileViewFileListView : public QWidget | 144 | class OFileViewFileListView : public QWidget |
145 | { | 145 | { |
146 | Q_OBJECT | 146 | Q_OBJECT |
147 | public: | 147 | public: |
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; |
155 | protected: | 155 | protected: |
156 | bool eventFilter (QObject *o, QEvent *e); | 156 | bool eventFilter (QObject *o, QEvent *e); |
157 | private slots: | 157 | private 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 | ||
167 | protected: | 167 | protected: |
168 | OFileSelector* selector(); | 168 | OFileSelector* selector(); |
169 | 169 | ||
170 | private: | 170 | private: |
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 | ||
185 | private: | 185 | private: |
186 | QListView* m_view; | 186 | QListView* m_view; |
187 | }; | 187 | }; |
188 | 188 | ||
189 | } | 189 | } |
190 | } | 190 | } |
191 | } | 191 | } |
192 | 192 | ||
193 | #endif | 193 | #endif |
diff --git a/libopie2/opieui/ofontselector.cpp b/libopie2/opieui/ofontselector.cpp index b19c26e..6763ee6 100644 --- a/libopie2/opieui/ofontselector.cpp +++ b/libopie2/opieui/ofontselector.cpp | |||
@@ -1,429 +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 | ||
41 | 41 | ||
42 | namespace Opie { | 42 | namespace Opie { |
43 | namespace Ui { | 43 | namespace Ui { |
44 | namespace Private { | 44 | namespace Internal { |
45 | 45 | ||
46 | class OFontSelectorPrivate | 46 | class OFontSelectorPrivate |
47 | { | 47 | { |
48 | public: | 48 | public: |
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 | class FontListItem : public QListBoxText | 59 | class FontListItem : public QListBoxText |
60 | { | 60 | { |
61 | public: | 61 | public: |
62 | 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() |
63 | { | 63 | { |
64 | m_name = t; | 64 | m_name = t; |
65 | m_styles = styles; | 65 | m_styles = styles; |
66 | m_sizes = sizes; | 66 | m_sizes = sizes; |
67 | 67 | ||
68 | QString str = t; | 68 | QString str = t; |
69 | str [0] = str [0]. upper(); | 69 | str [0] = str [0]. upper(); |
70 | setText ( str ); | 70 | setText ( str ); |
71 | } | 71 | } |
72 | 72 | ||
73 | QString family() const | 73 | QString family() const |
74 | { | 74 | { |
75 | return m_name; | 75 | return m_name; |
76 | } | 76 | } |
77 | 77 | ||
78 | const QStringList &styles() const | 78 | const QStringList &styles() const |
79 | { | 79 | { |
80 | return m_styles; | 80 | return m_styles; |
81 | } | 81 | } |
82 | 82 | ||
83 | const QValueList<int> &sizes() const | 83 | const QValueList<int> &sizes() const |
84 | { | 84 | { |
85 | return m_sizes; | 85 | return m_sizes; |
86 | } | 86 | } |
87 | 87 | ||
88 | private: | 88 | private: |
89 | QStringList m_styles; | 89 | QStringList m_styles; |
90 | QValueList<int> m_sizes; | 90 | QValueList<int> m_sizes; |
91 | QString m_name; | 91 | QString m_name; |
92 | }; | 92 | }; |
93 | } | 93 | } |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | using namespace Opie::Ui; | 98 | using namespace Opie::Ui; |
99 | using namespace Opie::Ui::Private; | 99 | using namespace Opie::Ui::Internal; |
100 | 100 | ||
101 | static int findItemCB( QComboBox *box, const QString &str ) | 101 | static int findItemCB( QComboBox *box, const QString &str ) |
102 | { | 102 | { |
103 | for ( int i = 0; i < box->count(); i++ ) | 103 | for ( int i = 0; i < box->count(); i++ ) |
104 | { | 104 | { |
105 | if ( box->text ( i ) == str ) | 105 | if ( box->text ( i ) == str ) |
106 | return i; | 106 | return i; |
107 | } | 107 | } |
108 | return -1; | 108 | return -1; |
109 | } | 109 | } |
110 | 110 | ||
111 | /* static same as anon. namespace */ | 111 | /* static same as anon. namespace */ |
112 | static int qt_version() | 112 | static 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 | */ |
126 | OFontSelector::OFontSelector( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) | 126 | OFontSelector::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 | ||
171 | OFontSelector::~OFontSelector() | 171 | OFontSelector::~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 | */ |
181 | bool OFontSelector::setSelectedFont ( const QFont &f ) | 181 | bool 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 | */ |
194 | bool OFontSelector::setSelectedFont( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) | 194 | bool 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 | */ |
233 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) | 233 | bool 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 | */ |
245 | QString OFontSelector::fontFamily() const | 245 | QString 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 | */ |
256 | QString OFontSelector::fontStyle() const | 256 | QString 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 | */ |
267 | int OFontSelector::fontSize() const | 267 | int 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 | */ |
278 | QString OFontSelector::fontCharSet() const | 278 | QString 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 | */ |
289 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) | 289 | bool 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 | ||
310 | void OFontSelector::loadFonts ( QListBox *list ) | 310 | void 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 | ||
328 | void OFontSelector::fontFamilyClicked ( int index ) | 328 | void 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 | ||
373 | void OFontSelector::fontStyleClicked ( int /*index*/ ) | 373 | void OFontSelector::fontStyleClicked ( int /*index*/ ) |
374 | { | 374 | { |
375 | changeFont(); | 375 | changeFont(); |
376 | } | 376 | } |
377 | 377 | ||
378 | void OFontSelector::fontSizeClicked ( int /*index*/ ) | 378 | void OFontSelector::fontSizeClicked ( int /*index*/ ) |
379 | { | 379 | { |
380 | changeFont(); | 380 | changeFont(); |
381 | } | 381 | } |
382 | 382 | ||
383 | void OFontSelector::changeFont() | 383 | void 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 | */ |
396 | QFont OFontSelector::selectedFont() | 396 | QFont 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 | ||
415 | void OFontSelector::resizeEvent ( QResizeEvent *re ) | 415 | void 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 | 429 | ||
diff --git a/libopie2/opieui/ofontselector.h b/libopie2/opieui/ofontselector.h index 1d97233..cd134f4 100644 --- a/libopie2/opieui/ofontselector.h +++ b/libopie2/opieui/ofontselector.h | |||
@@ -1,106 +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 | ||
36 | class QListBox; | 36 | class QListBox; |
37 | 37 | ||
38 | namespace Opie { | 38 | namespace Opie { |
39 | namespace Ui { | 39 | namespace Ui { |
40 | namespace Private { | 40 | namespace Internal { |
41 | class OFontSelectorPrivate; | 41 | class OFontSelectorPrivate; |
42 | } | 42 | } |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * 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. |
46 | * 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 |
47 | * fonts | 47 | * fonts |
48 | * | 48 | * |
49 | * | 49 | * |
50 | * @short A widget to select a font | 50 | * @short A widget to select a font |
51 | * @see QWidget | 51 | * @see QWidget |
52 | * @see QFont | 52 | * @see QFont |
53 | * @author Rober Griebl | 53 | * @author Rober Griebl |
54 | */ | 54 | */ |
55 | class OFontSelector : public QWidget | 55 | class OFontSelector : public QWidget |
56 | { | 56 | { |
57 | Q_OBJECT | 57 | Q_OBJECT |
58 | 58 | ||
59 | public: | 59 | public: |
60 | 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 ); |
61 | virtual ~OFontSelector ( ); | 61 | virtual ~OFontSelector ( ); |
62 | 62 | ||
63 | bool selectedFont ( QString &family, QString &style, int &size ); | 63 | bool selectedFont ( QString &family, QString &style, int &size ); |
64 | bool selectedFont ( QString &family, QString &style, int &size, QString &charset ); | 64 | bool selectedFont ( QString &family, QString &style, int &size, QString &charset ); |
65 | 65 | ||
66 | QFont selectedFont ( ); | 66 | QFont selectedFont ( ); |
67 | 67 | ||
68 | bool setSelectedFont ( const QFont & ); | 68 | bool setSelectedFont ( const QFont & ); |
69 | 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 ); |
70 | 70 | ||
71 | QString fontFamily ( ) const; | 71 | QString fontFamily ( ) const; |
72 | QString fontStyle ( ) const; | 72 | QString fontStyle ( ) const; |
73 | int fontSize ( ) const; | 73 | int fontSize ( ) const; |
74 | QString fontCharSet ( ) const; | 74 | QString fontCharSet ( ) const; |
75 | 75 | ||
76 | signals: | 76 | signals: |
77 | /** | 77 | /** |
78 | * This signal gets emitted when a font got chosen | 78 | * This signal gets emitted when a font got chosen |
79 | */ | 79 | */ |
80 | void fontSelected ( const QFont & ); | 80 | void fontSelected ( const QFont & ); |
81 | 81 | ||
82 | protected slots: | 82 | protected slots: |
83 | /** @internal */ | 83 | /** @internal */ |
84 | virtual void fontFamilyClicked ( int ); | 84 | virtual void fontFamilyClicked ( int ); |
85 | /** @internal */ | 85 | /** @internal */ |
86 | virtual void fontStyleClicked ( int ); | 86 | virtual void fontStyleClicked ( int ); |
87 | /** @internal */ | 87 | /** @internal */ |
88 | virtual void fontSizeClicked ( int ); | 88 | virtual void fontSizeClicked ( int ); |
89 | 89 | ||
90 | protected: | 90 | protected: |
91 | virtual void resizeEvent ( QResizeEvent *re ); | 91 | virtual void resizeEvent ( QResizeEvent *re ); |
92 | 92 | ||
93 | private: | 93 | private: |
94 | void loadFonts ( QListBox * ); | 94 | void loadFonts ( QListBox * ); |
95 | 95 | ||
96 | void changeFont ( ); | 96 | void changeFont ( ); |
97 | 97 | ||
98 | private: | 98 | private: |
99 | Private::OFontSelectorPrivate *d; | 99 | Internal::OFontSelectorPrivate *d; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | } | 102 | } |
103 | } | 103 | } |
104 | 104 | ||
105 | #endif | 105 | #endif |
106 | 106 | ||
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp index ef6d713..eb7acbd 100644 --- a/libopie2/opieui/okeyconfigwidget.cpp +++ b/libopie2/opieui/okeyconfigwidget.cpp | |||
@@ -1,1247 +1,1248 @@ | |||
1 | #include "okeyconfigwidget.h" | 1 | #include "okeyconfigwidget.h" |
2 | #include "okeyconfigwidget_p.h" | 2 | #include "okeyconfigwidget_p.h" |
3 | 3 | ||
4 | 4 | ||
5 | #include <qgroupbox.h> | 5 | #include <qgroupbox.h> |
6 | #include <qradiobutton.h> | 6 | #include <qradiobutton.h> |
7 | #include <qpushbutton.h> | 7 | #include <qpushbutton.h> |
8 | #include <qbuttongroup.h> | 8 | #include <qbuttongroup.h> |
9 | #include <qmessagebox.h> | 9 | #include <qmessagebox.h> |
10 | #include <qaccel.h> | 10 | #include <qaccel.h> |
11 | #include <qlayout.h> | 11 | #include <qlayout.h> |
12 | #include <qlabel.h> | 12 | #include <qlabel.h> |
13 | 13 | ||
14 | /* non gui */ | 14 | /* non gui */ |
15 | #include <qtimer.h> | 15 | #include <qtimer.h> |
16 | 16 | ||
17 | 17 | ||
18 | using namespace Opie::Ui; | 18 | using namespace Opie::Ui; |
19 | 19 | ||
20 | 20 | ||
21 | 21 | ||
22 | /** | 22 | /** |
23 | * The default Constructor of a OKeyPair. | 23 | * The default Constructor of a OKeyPair. |
24 | * A Key and a Modifier ( Alt/Shift/Ctrl ) | 24 | * A Key and a Modifier ( Alt/Shift/Ctrl ) |
25 | * needs to be supplied. | 25 | * needs to be supplied. |
26 | * Use Qt::Key for the information. | 26 | * Use Qt::Key for the information. |
27 | * The default arguments create an Empty OKeyPair. If you | 27 | * The default arguments create an Empty OKeyPair. If you |
28 | * want to get an empty OKeyPair use the static method for getting | 28 | * want to get an empty OKeyPair use the static method for getting |
29 | * the emptyKey() | 29 | * the emptyKey() |
30 | * | 30 | * |
31 | * @see OKeyPair OKeyPair::emptyKey() | 31 | * @see OKeyPair OKeyPair::emptyKey() |
32 | */ | 32 | */ |
33 | OKeyPair::OKeyPair( int key, int mod ) | 33 | OKeyPair::OKeyPair( int key, int mod ) |
34 | : m_key( key ), m_mod( mod ) | 34 | : m_key( key ), m_mod( mod ) |
35 | {} | 35 | {} |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * The destructor | 38 | * The destructor |
39 | */ | 39 | */ |
40 | OKeyPair::~OKeyPair() {} | 40 | OKeyPair::~OKeyPair() {} |
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Is this OKeyPair empty/valid? | 44 | * Is this OKeyPair empty/valid? |
45 | */ | 45 | */ |
46 | bool OKeyPair::isEmpty()const { | 46 | bool OKeyPair::isEmpty()const { |
47 | return ( ( m_key == -1 )&& ( m_mod == -1 ) ); | 47 | return ( ( m_key == -1 )&& ( m_mod == -1 ) ); |
48 | } | 48 | } |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * get the keycode for this OKeyPair. The Key relates to Qt::Key. | 51 | * get the keycode for this OKeyPair. The Key relates to Qt::Key. |
52 | * | 52 | * |
53 | * @see Qt::Key | 53 | * @see Qt::Key |
54 | * @see setKey | 54 | * @see setKey |
55 | */ | 55 | */ |
56 | int OKeyPair::keycode()const { | 56 | int OKeyPair::keycode()const { |
57 | return m_key; | 57 | return m_key; |
58 | } | 58 | } |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * get the modifier key for this OKeyPair. The Modifier State relates | 61 | * get the modifier key for this OKeyPair. The Modifier State relates |
62 | * to the Qt::ButtonState | 62 | * to the Qt::ButtonState |
63 | * | 63 | * |
64 | * @see Qt::ButtonState | 64 | * @see Qt::ButtonState |
65 | * @see setModifier | 65 | * @see setModifier |
66 | */ | 66 | */ |
67 | int OKeyPair::modifier()const { | 67 | int OKeyPair::modifier()const { |
68 | return m_mod; | 68 | return m_mod; |
69 | } | 69 | } |
70 | 70 | ||
71 | 71 | ||
72 | /** | 72 | /** |
73 | * Set the keycode | 73 | * Set the keycode |
74 | * @param key The Keycode to set | 74 | * @param key The Keycode to set |
75 | * | 75 | * |
76 | * @see keycode() | 76 | * @see keycode() |
77 | * @see Qt::Key | 77 | * @see Qt::Key |
78 | */ | 78 | */ |
79 | void OKeyPair::setKeycode( int key ) { | 79 | void OKeyPair::setKeycode( int key ) { |
80 | m_key = key; | 80 | m_key = key; |
81 | } | 81 | } |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Set the modifier key | 84 | * Set the modifier key |
85 | * | 85 | * |
86 | * @param the Modifier key | 86 | * @param the Modifier key |
87 | * @see Qt::ButtonState | 87 | * @see Qt::ButtonState |
88 | * @see modifier() | 88 | * @see modifier() |
89 | */ | 89 | */ |
90 | void OKeyPair::setModifier( int mod ) { | 90 | void OKeyPair::setModifier( int mod ) { |
91 | m_mod = mod; | 91 | m_mod = mod; |
92 | } | 92 | } |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * Return an OKeyPair for the Return Key without any modifier. | 95 | * Return an OKeyPair for the Return Key without any modifier. |
96 | */ | 96 | */ |
97 | OKeyPair OKeyPair::returnKey() { | 97 | OKeyPair OKeyPair::returnKey() { |
98 | return OKeyPair( Qt::Key_Return, 0 ); | 98 | return OKeyPair( Qt::Key_Return, 0 ); |
99 | } | 99 | } |
100 | 100 | ||
101 | /** | 101 | /** |
102 | * Return an OKeyPair for the Left Arrow Key | 102 | * Return an OKeyPair for the Left Arrow Key |
103 | * without any modifier Key | 103 | * without any modifier Key |
104 | */ | 104 | */ |
105 | OKeyPair OKeyPair::leftArrowKey() { | 105 | OKeyPair OKeyPair::leftArrowKey() { |
106 | return OKeyPair( Qt::Key_Left, 0 ); | 106 | return OKeyPair( Qt::Key_Left, 0 ); |
107 | } | 107 | } |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * Return an OKeyPair for the Right Arrow Key | 110 | * Return an OKeyPair for the Right Arrow Key |
111 | * without any modifier Key | 111 | * without any modifier Key |
112 | */ | 112 | */ |
113 | OKeyPair OKeyPair::rightArrowKey() { | 113 | OKeyPair OKeyPair::rightArrowKey() { |
114 | return OKeyPair( Qt::Key_Right, 0 ); | 114 | return OKeyPair( Qt::Key_Right, 0 ); |
115 | } | 115 | } |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * Return an OKeyPair for the Up Arrow Key | 118 | * Return an OKeyPair for the Up Arrow Key |
119 | * without any modifier Key | 119 | * without any modifier Key |
120 | */ | 120 | */ |
121 | OKeyPair OKeyPair::upArrowKey() { | 121 | OKeyPair OKeyPair::upArrowKey() { |
122 | return OKeyPair( Qt::Key_Up, 0 ); | 122 | return OKeyPair( Qt::Key_Up, 0 ); |
123 | } | 123 | } |
124 | 124 | ||
125 | /** | 125 | /** |
126 | * Return an OKeyPair for the Down Arrow Key | 126 | * Return an OKeyPair for the Down Arrow Key |
127 | * without any modifier Key | 127 | * without any modifier Key |
128 | */ | 128 | */ |
129 | OKeyPair OKeyPair::downArrowKey() { | 129 | OKeyPair OKeyPair::downArrowKey() { |
130 | return OKeyPair( Qt::Key_Down, 0 ); | 130 | return OKeyPair( Qt::Key_Down, 0 ); |
131 | } | 131 | } |
132 | 132 | ||
133 | /** | 133 | /** |
134 | * Return an Empty OKeyPair | 134 | * Return an Empty OKeyPair |
135 | */ | 135 | */ |
136 | OKeyPair OKeyPair::emptyKey() { | 136 | OKeyPair OKeyPair::emptyKey() { |
137 | return OKeyPair(); | 137 | return OKeyPair(); |
138 | } | 138 | } |
139 | 139 | ||
140 | /** | 140 | /** |
141 | * This functions uses the Opie::Core::ODevice::buttons | 141 | * This functions uses the Opie::Core::ODevice::buttons |
142 | * for OKeyPairList | 142 | * for OKeyPairList |
143 | * | 143 | * |
144 | * @see Opie::Core::ODevice | 144 | * @see Opie::Core::ODevice |
145 | * @see Opie::Core::ODeviceButton | 145 | * @see Opie::Core::ODeviceButton |
146 | * @see Opie::Core::ODevice::button | 146 | * @see Opie::Core::ODevice::button |
147 | */ | 147 | */ |
148 | OKeyPair::List OKeyPair::hardwareKeys() { | 148 | OKeyPair::List OKeyPair::hardwareKeys() { |
149 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); | 149 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); |
150 | OKeyPair::List lst; | 150 | OKeyPair::List lst; |
151 | 151 | ||
152 | for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); | 152 | for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); |
153 | it != but.end(); ++it ) | 153 | it != but.end(); ++it ) |
154 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); | 154 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); |
155 | 155 | ||
156 | 156 | ||
157 | return lst; | 157 | return lst; |
158 | } | 158 | } |
159 | 159 | ||
160 | /** | 160 | /** |
161 | * Equals operator. Check if two OKeyPairs have the same key and modifier | 161 | * Equals operator. Check if two OKeyPairs have the same key and modifier |
162 | * @see operator!= | 162 | * @see operator!= |
163 | */ | 163 | */ |
164 | bool OKeyPair::operator==( const OKeyPair& pair)const { | 164 | bool OKeyPair::operator==( const OKeyPair& pair)const { |
165 | if ( m_key != pair.m_key ) return false; | 165 | if ( m_key != pair.m_key ) return false; |
166 | if ( m_mod != pair.m_mod ) return false; | 166 | if ( m_mod != pair.m_mod ) return false; |
167 | 167 | ||
168 | return true; | 168 | return true; |
169 | } | 169 | } |
170 | 170 | ||
171 | /** | 171 | /** |
172 | * Not equal operator. calls the equal operator internally | 172 | * Not equal operator. calls the equal operator internally |
173 | */ | 173 | */ |
174 | bool OKeyPair::operator!=( const OKeyPair& pair)const { | 174 | bool OKeyPair::operator!=( const OKeyPair& pair)const { |
175 | return !(*this == pair); | 175 | return !(*this == pair); |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
179 | /** | 179 | /** |
180 | * The normal Constructor to create a OKeyConfigItem | 180 | * The normal Constructor to create a OKeyConfigItem |
181 | * | 181 | * |
182 | * You can set the the key paramater of this item but if | 182 | * You can set the the key paramater of this item but if |
183 | * you use this item with the OKeyConfigManager your setting | 183 | * you use this item with the OKeyConfigManager your setting |
184 | * will be overwritten. | 184 | * will be overwritten. |
185 | * You can also specify a QObject and slot which sould get called | 185 | * You can also specify a QObject and slot which sould get called |
186 | * once this item is activated. This slot only works if you | 186 | * once this item is activated. This slot only works if you |
187 | * use the OKeyConfigManager. | 187 | * use the OKeyConfigManager. |
188 | * The actual Key is read by load() | 188 | * The actual Key is read by load() |
189 | * | 189 | * |
190 | * \code | 190 | * \code |
191 | * void MySlot::create(){ | 191 | * void MySlot::create(){ |
192 | * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), | 192 | * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), |
193 | * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), | 193 | * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), |
194 | * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); | 194 | * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); |
195 | * } | 195 | * } |
196 | * \endcode | 196 | * \endcode |
197 | * | 197 | * |
198 | * @param text The text exposed to the user | 198 | * @param text The text exposed to the user |
199 | * @param config_key The key used in the config | 199 | * @param config_key The key used in the config |
200 | * @param pix A Pixmap associated with this Item | 200 | * @param pix A Pixmap associated with this Item |
201 | * @param def The OKeyPair used as default | 201 | * @param def The OKeyPair used as default |
202 | * @param caller The object where the slot exists | 202 | * @param caller The object where the slot exists |
203 | * @param slot The slot which should get called | 203 | * @param slot The slot which should get called |
204 | * | 204 | * |
205 | */ | 205 | */ |
206 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, | 206 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, |
207 | const QPixmap& pix, int id, const OKeyPair& def, | 207 | const QPixmap& pix, int id, const OKeyPair& def, |
208 | QObject *caller, | 208 | QObject *caller, |
209 | const char* slot ) | 209 | const char* slot ) |
210 | : m_text( text ), m_config( config_key ), m_pix( pix ), | 210 | : m_text( text ), m_config( config_key ), m_pix( pix ), |
211 | m_id( id ), m_def( def ), | 211 | m_id( id ), m_def( def ), |
212 | m_obj( caller ), m_str( slot ) {} | 212 | m_obj( caller ), m_str( slot ) {} |
213 | 213 | ||
214 | /** | 214 | /** |
215 | * A special Constructor for converting from an Opie::Core::ODeviceButton | 215 | * A special Constructor for converting from an Opie::Core::ODeviceButton |
216 | * delivered by Opie::Core::ODevice::buttons() | 216 | * delivered by Opie::Core::ODevice::buttons() |
217 | * There is no Config Key set and both default key and key are set | 217 | * There is no Config Key set and both default key and key are set |
218 | * to Opie::Core::ODeviceButton::keycode() and 0 to modifier | 218 | * to Opie::Core::ODeviceButton::keycode() and 0 to modifier |
219 | * | 219 | * |
220 | * @see Opie::Core::ODevice | 220 | * @see Opie::Core::ODevice |
221 | * @see Opie::Core::ODeviceButton | 221 | * @see Opie::Core::ODeviceButton |
222 | * @see Opie::Core::ODevice::buttons() | 222 | * @see Opie::Core::ODevice::buttons() |
223 | */ | 223 | */ |
224 | OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b ) | 224 | OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b ) |
225 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ), | 225 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ), |
226 | m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) ) | 226 | m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) ) |
227 | {} | 227 | {} |
228 | 228 | ||
229 | 229 | ||
230 | /** | 230 | /** |
231 | * Destructor | 231 | * Destructor |
232 | */ | 232 | */ |
233 | OKeyConfigItem::~OKeyConfigItem() {} | 233 | OKeyConfigItem::~OKeyConfigItem() {} |
234 | 234 | ||
235 | 235 | ||
236 | /** | 236 | /** |
237 | * The text exposed to the user | 237 | * The text exposed to the user |
238 | * | 238 | * |
239 | * @see setText | 239 | * @see setText |
240 | */ | 240 | */ |
241 | QString OKeyConfigItem::text()const { | 241 | QString OKeyConfigItem::text()const { |
242 | return m_text; | 242 | return m_text; |
243 | } | 243 | } |
244 | 244 | ||
245 | /** | 245 | /** |
246 | * The pixmap shown to the user for your action/key | 246 | * The pixmap shown to the user for your action/key |
247 | * | 247 | * |
248 | * @see setPixmap | 248 | * @see setPixmap |
249 | */ | 249 | */ |
250 | QPixmap OKeyConfigItem::pixmap()const { | 250 | QPixmap OKeyConfigItem::pixmap()const { |
251 | return m_pix; | 251 | return m_pix; |
252 | } | 252 | } |
253 | 253 | ||
254 | /** | 254 | /** |
255 | * Return the OKeyPair this OKeyConfigItem is configured for. | 255 | * Return the OKeyPair this OKeyConfigItem is configured for. |
256 | * | 256 | * |
257 | * @see setKeyPair | 257 | * @see setKeyPair |
258 | */ | 258 | */ |
259 | OKeyPair OKeyConfigItem::keyPair()const { | 259 | OKeyPair OKeyConfigItem::keyPair()const { |
260 | return m_key; | 260 | return m_key; |
261 | } | 261 | } |
262 | 262 | ||
263 | /** | 263 | /** |
264 | * Return the default OKeyPair | 264 | * Return the default OKeyPair |
265 | * @see setDefaultKeyPair | 265 | * @see setDefaultKeyPair |
266 | */ | 266 | */ |
267 | OKeyPair OKeyConfigItem::defaultKeyPair()const { | 267 | OKeyPair OKeyConfigItem::defaultKeyPair()const { |
268 | return m_def; | 268 | return m_def; |
269 | } | 269 | } |
270 | 270 | ||
271 | 271 | ||
272 | /** | 272 | /** |
273 | * Return the Id you assigned to this item. | 273 | * Return the Id you assigned to this item. |
274 | * setting is only possible by the constructor | 274 | * setting is only possible by the constructor |
275 | */ | 275 | */ |
276 | int OKeyConfigItem::id()const{ | 276 | int OKeyConfigItem::id()const{ |
277 | return m_id; | 277 | return m_id; |
278 | } | 278 | } |
279 | 279 | ||
280 | /** | 280 | /** |
281 | * reutrn the Config Key. Setting it is only possible | 281 | * reutrn the Config Key. Setting it is only possible |
282 | * by the constructor | 282 | * by the constructor |
283 | */ | 283 | */ |
284 | QCString OKeyConfigItem::configKey()const { | 284 | QCString OKeyConfigItem::configKey()const { |
285 | return m_config; | 285 | return m_config; |
286 | } | 286 | } |
287 | 287 | ||
288 | /** | 288 | /** |
289 | * @internal | 289 | * @internal |
290 | */ | 290 | */ |
291 | QObject* OKeyConfigItem::object()const{ | 291 | QObject* OKeyConfigItem::object()const{ |
292 | return m_obj; | 292 | return m_obj; |
293 | } | 293 | } |
294 | 294 | ||
295 | /** | 295 | /** |
296 | * @internal | 296 | * @internal |
297 | */ | 297 | */ |
298 | QCString OKeyConfigItem::slot()const { | 298 | QCString OKeyConfigItem::slot()const { |
299 | return m_str; | 299 | return m_str; |
300 | } | 300 | } |
301 | 301 | ||
302 | /** | 302 | /** |
303 | * Set the text | 303 | * Set the text |
304 | * | 304 | * |
305 | * @param text Set the Text of this Action to text | 305 | * @param text Set the Text of this Action to text |
306 | * @see text() | 306 | * @see text() |
307 | */ | 307 | */ |
308 | void OKeyConfigItem::setText( const QString& text ) { | 308 | void OKeyConfigItem::setText( const QString& text ) { |
309 | m_text = text; | 309 | m_text = text; |
310 | } | 310 | } |
311 | 311 | ||
312 | /** | 312 | /** |
313 | * Set the pixmap of this action | 313 | * Set the pixmap of this action |
314 | * | 314 | * |
315 | * @param pix The Pixmap to set | 315 | * @param pix The Pixmap to set |
316 | * @see pixmap() | 316 | * @see pixmap() |
317 | */ | 317 | */ |
318 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { | 318 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { |
319 | m_pix = pix; | 319 | m_pix = pix; |
320 | } | 320 | } |
321 | 321 | ||
322 | /** | 322 | /** |
323 | * Set the KeyPair the OKeyConfigItem uses. | 323 | * Set the KeyPair the OKeyConfigItem uses. |
324 | * Your set Key could get overwritten if you use | 324 | * Your set Key could get overwritten if you use |
325 | * the manager or GUI to configure the key | 325 | * the manager or GUI to configure the key |
326 | * | 326 | * |
327 | * @param key Set the OKeyPair used | 327 | * @param key Set the OKeyPair used |
328 | * @see keyPair() | 328 | * @see keyPair() |
329 | */ | 329 | */ |
330 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { | 330 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { |
331 | m_key = key; | 331 | m_key = key; |
332 | } | 332 | } |
333 | 333 | ||
334 | /** | 334 | /** |
335 | * Set the default KeyPair. | 335 | * Set the default KeyPair. |
336 | * | 336 | * |
337 | * @param key The default keypair | 337 | * @param key The default keypair |
338 | * @see defaultKeyPair() | 338 | * @see defaultKeyPair() |
339 | */ | 339 | */ |
340 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { | 340 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { |
341 | m_def = key; | 341 | m_def = key; |
342 | } | 342 | } |
343 | 343 | ||
344 | /** | 344 | /** |
345 | * @internal | 345 | * @internal |
346 | */ | 346 | */ |
347 | void OKeyConfigItem::setConfigKey( const QCString& str) { | 347 | void OKeyConfigItem::setConfigKey( const QCString& str) { |
348 | m_config = str; | 348 | m_config = str; |
349 | m_config.detach(); | 349 | m_config.detach(); |
350 | } | 350 | } |
351 | 351 | ||
352 | /** | 352 | /** |
353 | * @internal | 353 | * @internal |
354 | */ | 354 | */ |
355 | void OKeyConfigItem::setId( int id ) { | 355 | void OKeyConfigItem::setId( int id ) { |
356 | m_id = id; | 356 | m_id = id; |
357 | } | 357 | } |
358 | 358 | ||
359 | /** | 359 | /** |
360 | * If the item is not configured isEmpty() will return true | 360 | * If the item is not configured isEmpty() will return true |
361 | * It is empty if no text is present and no default | 361 | * It is empty if no text is present and no default |
362 | * and no configured key | 362 | * and no configured key |
363 | */ | 363 | */ |
364 | bool OKeyConfigItem::isEmpty()const { | 364 | bool OKeyConfigItem::isEmpty()const { |
365 | if ( !m_def.isEmpty() ) return false; | 365 | if ( !m_def.isEmpty() ) return false; |
366 | if ( !m_key.isEmpty() ) return false; | 366 | if ( !m_key.isEmpty() ) return false; |
367 | if ( !m_text.isEmpty() ) return false; | 367 | if ( !m_text.isEmpty() ) return false; |
368 | if ( m_id != -1 ) return false; | 368 | if ( m_id != -1 ) return false; |
369 | 369 | ||
370 | return true; | 370 | return true; |
371 | } | 371 | } |
372 | 372 | ||
373 | /** | 373 | /** |
374 | * Check if the KeyPairs are the same | 374 | * Check if the KeyPairs are the same |
375 | */ | 375 | */ |
376 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const { | 376 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const { |
377 | /* if ( isEmpty() == conf.isEmpty() ) return true; | 377 | /* if ( isEmpty() == conf.isEmpty() ) return true; |
378 | else if ( isEmpty() != conf.isEmpty() ) return false; | 378 | else if ( isEmpty() != conf.isEmpty() ) return false; |
379 | else if ( !isEmpty()!= conf.isEmpty() ) return false; | 379 | else if ( !isEmpty()!= conf.isEmpty() ) return false; |
380 | */ | 380 | */ |
381 | 381 | ||
382 | if ( m_id != conf.m_id ) return false; | 382 | if ( m_id != conf.m_id ) return false; |
383 | if ( m_obj != conf.m_obj ) return false; | 383 | if ( m_obj != conf.m_obj ) return false; |
384 | if ( m_text != conf.m_text ) return false; | 384 | if ( m_text != conf.m_text ) return false; |
385 | if ( m_key != conf.m_key ) return false; | 385 | if ( m_key != conf.m_key ) return false; |
386 | if ( m_def != conf.m_def ) return false; | 386 | if ( m_def != conf.m_def ) return false; |
387 | 387 | ||
388 | 388 | ||
389 | 389 | ||
390 | return true; | 390 | return true; |
391 | 391 | ||
392 | } | 392 | } |
393 | 393 | ||
394 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const { | 394 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const { |
395 | return !( *this == conf ); | 395 | return !( *this == conf ); |
396 | } | 396 | } |
397 | 397 | ||
398 | /** | 398 | /** |
399 | * \brief c'tor | 399 | * \brief c'tor |
400 | * The Constructor for a OKeyConfigManager | 400 | * The Constructor for a OKeyConfigManager |
401 | * | 401 | * |
402 | * You can use this manager in multiple ways. Either make it handle | 402 | * You can use this manager in multiple ways. Either make it handle |
403 | * QKeyEvents | 403 | * QKeyEvents |
404 | * | 404 | * |
405 | * \code | 405 | * \code |
406 | * Opie::Core::Config conf = oApp->config(); | 406 | * Opie::Core::Config conf = oApp->config(); |
407 | * Opie::Ui::OKeyPairList blackList; | 407 | * Opie::Ui::OKeyPairList blackList; |
408 | * blackList.append(Opie::Ui::OKeyPair::leftArrowKey()); | 408 | * blackList.append(Opie::Ui::OKeyPair::leftArrowKey()); |
409 | * blackList.append(Opie::Ui::OKeyPair::rightArrowKey()); | 409 | * blackList.append(Opie::Ui::OKeyPair::rightArrowKey()); |
410 | * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList, | 410 | * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList, |
411 | * false); | 411 | * false); |
412 | * QListView *view = new QListView(); | 412 | * QListView *view = new QListView(); |
413 | * manager->handleWidget(view); | 413 | * manager->handleWidget(view); |
414 | * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey()); | 414 | * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey()); |
415 | * manager->load(); | 415 | * manager->load(); |
416 | * | 416 | * |
417 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), | 417 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), |
418 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); | 418 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); |
419 | * | 419 | * |
420 | * .... | 420 | * .... |
421 | * | 421 | * |
422 | * void update(){ | 422 | * void update(){ |
423 | * QDialog diag(true); | 423 | * QDialog diag(true); |
424 | * QHBoxLayout *lay = new QHBoxLayout(&diag); | 424 | * QHBoxLayout *lay = new QHBoxLayout(&diag); |
425 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); | 425 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); |
426 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); | 426 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); |
427 | * lay->addWidget(wid); | 427 | * lay->addWidget(wid); |
428 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ | 428 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ |
429 | * wid->save(); | 429 | * wid->save(); |
430 | * } | 430 | * } |
431 | * } | 431 | * } |
432 | * | 432 | * |
433 | * .... | 433 | * .... |
434 | * MyListView::keyPressEvent( QKeyEvent* e ){ | 434 | * MyListView::keyPressEvent( QKeyEvent* e ){ |
435 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); | 435 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); |
436 | * if(!item.isEmpty() ){ | 436 | * if(!item.isEmpty() ){ |
437 | * switch(item.id()){ | 437 | * switch(item.id()){ |
438 | * case My_Delete_Key: | 438 | * case My_Delete_Key: |
439 | * break; | 439 | * break; |
440 | * } | 440 | * } |
441 | * } | 441 | * } |
442 | * } | 442 | * } |
443 | * | 443 | * |
444 | * \endcode | 444 | * \endcode |
445 | * | 445 | * |
446 | * @param conf The Config where the KeySetting should be stored | 446 | * @param conf The Config where the KeySetting should be stored |
447 | * @param group The group where the KeySetting will be stored | 447 | * @param group The group where the KeySetting will be stored |
448 | * @param black Which keys shouldn't be allowed to handle | 448 | * @param black Which keys shouldn't be allowed to handle |
449 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons | 449 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons |
450 | * @param par The parent/owner of this manager | 450 | * @param par The parent/owner of this manager |
451 | * @param name The name of this object | 451 | * @param name The name of this object |
452 | */ | 452 | */ |
453 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | 453 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, |
454 | const QString& group, | 454 | const QString& group, |
455 | const OKeyPair::List& black, | 455 | const OKeyPair::List& black, |
456 | bool grabkeyboard, QObject* par, | 456 | bool grabkeyboard, QObject* par, |
457 | const char* name) | 457 | const char* name) |
458 | : QObject( par, name ), m_conf( conf ), m_group( group ), | 458 | : QObject( par, name ), m_conf( conf ), m_group( group ), |
459 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ | 459 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ |
460 | if ( m_grab ) | 460 | if ( m_grab ) |
461 | QPEApplication::grabKeyboard(); | 461 | QPEApplication::grabKeyboard(); |
462 | } | 462 | } |
463 | 463 | ||
464 | 464 | ||
465 | /** | 465 | /** |
466 | * Destructor | 466 | * Destructor |
467 | */ | 467 | */ |
468 | OKeyConfigManager::~OKeyConfigManager() { | 468 | OKeyConfigManager::~OKeyConfigManager() { |
469 | if ( m_grab ) | 469 | if ( m_grab ) |
470 | QPEApplication::ungrabKeyboard(); | 470 | QPEApplication::ungrabKeyboard(); |
471 | } | 471 | } |
472 | 472 | ||
473 | /** | 473 | /** |
474 | * Load the Configuration from the OConfig | 474 | * Load the Configuration from the OConfig |
475 | * If a Key is restricted but was in the config we will | 475 | * If a Key is restricted but was in the config we will |
476 | * make it be the empty key paur | 476 | * make it be the empty key paur |
477 | * We will change the group of the OConfig Item! | 477 | * We will change the group but restore to the previous. |
478 | * | 478 | * |
479 | * @see OKeyPair::emptyKey | 479 | * @see OKeyPair::emptyKey |
480 | */ | 480 | */ |
481 | void OKeyConfigManager::load() { | 481 | void OKeyConfigManager::load() { |
482 | m_conf->setGroup( m_group ); | 482 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); |
483 | 483 | ||
484 | /* | 484 | /* |
485 | * Read each item | 485 | * Read each item |
486 | */ | 486 | */ |
487 | int key, mod; | 487 | int key, mod; |
488 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { | 488 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { |
489 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); | 489 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); |
490 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); | 490 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); |
491 | OKeyPair okey( key, mod ); | 491 | OKeyPair okey( key, mod ); |
492 | 492 | ||
493 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) | 493 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) |
494 | (*it).setKeyPair( OKeyPair(key, mod) ); | 494 | (*it).setKeyPair( OKeyPair(key, mod) ); |
495 | else | 495 | else |
496 | (*it).setKeyPair( OKeyPair::emptyKey() ); | 496 | (*it).setKeyPair( OKeyPair::emptyKey() ); |
497 | } | 497 | } |
498 | delete m_map; m_map = 0; | 498 | delete m_map; m_map = 0; |
499 | } | 499 | } |
500 | 500 | ||
501 | /** | 501 | /** |
502 | * We will save the current configuration | 502 | * We will save the current configuration |
503 | * to the OConfig. We will change the group. | 503 | * to the OConfig. We will change the group but restore |
504 | * to the previous | ||
504 | */ | 505 | */ |
505 | void OKeyConfigManager::save() { | 506 | void OKeyConfigManager::save() { |
506 | m_conf->setGroup( m_group ); | 507 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); |
507 | 508 | ||
508 | /* | 509 | /* |
509 | * Write each item | 510 | * Write each item |
510 | */ | 511 | */ |
511 | for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { | 512 | for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { |
512 | /* skip empty items */ | 513 | /* skip empty items */ |
513 | if ( (*it).isEmpty() ) | 514 | if ( (*it).isEmpty() ) |
514 | continue; | 515 | continue; |
515 | OKeyPair pair = (*it).keyPair(); | 516 | OKeyPair pair = (*it).keyPair(); |
516 | OKeyPair deft = (*it).defaultKeyPair(); | 517 | OKeyPair deft = (*it).defaultKeyPair(); |
517 | /* | 518 | /* |
518 | * don't write if it is the default setting | 519 | * don't write if it is the default setting |
519 | * FIXME allow to remove Keys from config | 520 | * FIXME allow to remove Keys from config |
520 | if ( (pair.keycode() == deft.keycode()) && | 521 | if ( (pair.keycode() == deft.keycode()) && |
521 | (pair.modifier()== deft.modifier() ) ) | 522 | (pair.modifier()== deft.modifier() ) ) |
522 | return; | 523 | return; |
523 | */ | 524 | */ |
524 | 525 | ||
525 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); | 526 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); |
526 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); | 527 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); |
527 | } | 528 | } |
528 | } | 529 | } |
529 | 530 | ||
530 | /** | 531 | /** |
531 | * This is function uses a QMap internally but you can have the same keycode | 532 | * This is function uses a QMap internally but you can have the same keycode |
532 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem | 533 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem |
533 | * with same keycode and modifier key. The GUI takes care that a user can't | 534 | * with same keycode and modifier key. The GUI takes care that a user can't |
534 | * cofigure two keys. | 535 | * cofigure two keys. |
535 | * | 536 | * |
536 | * Make sure you call e->ignore if you don't want to handle this event | 537 | * Make sure you call e->ignore if you don't want to handle this event |
537 | */ | 538 | */ |
538 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | 539 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { |
539 | /* | 540 | /* |
540 | * Fix Up issues with Qt/E, my keybard, and virtual input | 541 | * Fix Up issues with Qt/E, my keybard, and virtual input |
541 | * methods | 542 | * methods |
542 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state | 543 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state |
543 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower | 544 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower |
544 | * case ascii | 545 | * case ascii |
545 | */ | 546 | */ |
546 | int key, mod; | 547 | int key, mod; |
547 | Opie::Ui::Private::fixupKeys( key, mod, e ); | 548 | Opie::Ui::Internal::fixupKeys( key, mod, e ); |
548 | 549 | ||
549 | OKeyConfigItem::List _keyList = keyList( key ); | 550 | OKeyConfigItem::List _keyList = keyList( key ); |
550 | if ( _keyList.isEmpty() ) | 551 | if ( _keyList.isEmpty() ) |
551 | return OKeyConfigItem(); | 552 | return OKeyConfigItem(); |
552 | 553 | ||
553 | OKeyConfigItem item; | 554 | OKeyConfigItem item; |
554 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); | 555 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); |
555 | ++it ) { | 556 | ++it ) { |
556 | if ( (*it).keyPair().modifier() == mod ) { | 557 | if ( (*it).keyPair().modifier() == mod ) { |
557 | item = *it; | 558 | item = *it; |
558 | break; | 559 | break; |
559 | } | 560 | } |
560 | 561 | ||
561 | } | 562 | } |
562 | 563 | ||
563 | return item; | 564 | return item; |
564 | } | 565 | } |
565 | 566 | ||
566 | /** | 567 | /** |
567 | * Return the associated id of the item or -1 if no item | 568 | * Return the associated id of the item or -1 if no item |
568 | * matched the key | 569 | * matched the key |
569 | * | 570 | * |
570 | * @see handleKeyEvent | 571 | * @see handleKeyEvent |
571 | */ | 572 | */ |
572 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { | 573 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { |
573 | return handleKeyEvent( ev ).id(); | 574 | return handleKeyEvent( ev ).id(); |
574 | } | 575 | } |
575 | 576 | ||
576 | /** | 577 | /** |
577 | * Add Key Config to the List of items | 578 | * Add Key Config to the List of items |
578 | */ | 579 | */ |
579 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | 580 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { |
580 | m_keys.append( item ); | 581 | m_keys.append( item ); |
581 | delete m_map; m_map = 0; | 582 | delete m_map; m_map = 0; |
582 | } | 583 | } |
583 | 584 | ||
584 | /** | 585 | /** |
585 | * Remove the Key from the Config. Internal lists will be destroyed | 586 | * Remove the Key from the Config. Internal lists will be destroyed |
586 | * and rebuild on demand later | 587 | * and rebuild on demand later |
587 | */ | 588 | */ |
588 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { | 589 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { |
589 | m_keys.remove( item ); | 590 | m_keys.remove( item ); |
590 | delete m_map; m_map = 0; | 591 | delete m_map; m_map = 0; |
591 | } | 592 | } |
592 | 593 | ||
593 | /** | 594 | /** |
594 | * Clears the complete list | 595 | * Clears the complete list |
595 | */ | 596 | */ |
596 | void OKeyConfigManager::clearKeyConfig() { | 597 | void OKeyConfigManager::clearKeyConfig() { |
597 | m_keys.clear(); | 598 | m_keys.clear(); |
598 | delete m_map; m_map = 0; | 599 | delete m_map; m_map = 0; |
599 | } | 600 | } |
600 | 601 | ||
601 | /** | 602 | /** |
602 | * | 603 | * |
603 | */ | 604 | */ |
604 | Opie::Ui::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ | 605 | Opie::Ui::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ |
605 | return m_keys; | 606 | return m_keys; |
606 | } | 607 | } |
607 | 608 | ||
608 | /** | 609 | /** |
609 | * Add this OKeyPair to the blackList. | 610 | * Add this OKeyPair to the blackList. |
610 | * Internal lists will be destroyed | 611 | * Internal lists will be destroyed |
611 | */ | 612 | */ |
612 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { | 613 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { |
613 | m_blackKeys.append( key ); | 614 | m_blackKeys.append( key ); |
614 | delete m_map; m_map = 0; | 615 | delete m_map; m_map = 0; |
615 | } | 616 | } |
616 | 617 | ||
617 | 618 | ||
618 | /** | 619 | /** |
619 | * Remove this OKeyPair from the black List | 620 | * Remove this OKeyPair from the black List |
620 | * Internal lists will be destroyed | 621 | * Internal lists will be destroyed |
621 | */ | 622 | */ |
622 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { | 623 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { |
623 | m_blackKeys.remove( key ); | 624 | m_blackKeys.remove( key ); |
624 | delete m_map; m_map = 0; | 625 | delete m_map; m_map = 0; |
625 | } | 626 | } |
626 | 627 | ||
627 | 628 | ||
628 | /** | 629 | /** |
629 | * Clear the blackList | 630 | * Clear the blackList |
630 | */ | 631 | */ |
631 | void OKeyConfigManager::clearBlackList() { | 632 | void OKeyConfigManager::clearBlackList() { |
632 | m_blackKeys.clear(); | 633 | m_blackKeys.clear(); |
633 | delete m_map; m_map = 0; | 634 | delete m_map; m_map = 0; |
634 | } | 635 | } |
635 | 636 | ||
636 | 637 | ||
637 | /** | 638 | /** |
638 | * Return a copy of the blackList | 639 | * Return a copy of the blackList |
639 | */ | 640 | */ |
640 | OKeyPair::List OKeyConfigManager::blackList()const { | 641 | OKeyPair::List OKeyConfigManager::blackList()const { |
641 | return m_blackKeys; | 642 | return m_blackKeys; |
642 | } | 643 | } |
643 | 644 | ||
644 | 645 | ||
645 | /** | 646 | /** |
646 | * Ask the Manager to handle KeyEvents for you. | 647 | * Ask the Manager to handle KeyEvents for you. |
647 | * All handled keys will emit a QSignal and return true | 648 | * All handled keys will emit a QSignal and return true |
648 | * that it handled the keyevent | 649 | * that it handled the keyevent |
649 | */ | 650 | */ |
650 | void OKeyConfigManager::handleWidget( QWidget* wid ) { | 651 | void OKeyConfigManager::handleWidget( QWidget* wid ) { |
651 | wid->installEventFilter( this ); | 652 | wid->installEventFilter( this ); |
652 | } | 653 | } |
653 | 654 | ||
654 | /** | 655 | /** |
655 | * @internal | 656 | * @internal |
656 | */ | 657 | */ |
657 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | 658 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { |
658 | if ( !obj->isWidgetType() ) | 659 | if ( !obj->isWidgetType() ) |
659 | return false; | 660 | return false; |
660 | 661 | ||
661 | if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) | 662 | if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) |
662 | return false; | 663 | return false; |
663 | 664 | ||
664 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); | 665 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); |
665 | OKeyConfigItem item = handleKeyEvent( key ); | 666 | OKeyConfigItem item = handleKeyEvent( key ); |
666 | 667 | ||
667 | if ( item.isEmpty() ) | 668 | if ( item.isEmpty() ) |
668 | return false; | 669 | return false; |
669 | 670 | ||
670 | QWidget *wid = static_cast<QWidget*>( obj ); | 671 | QWidget *wid = static_cast<QWidget*>( obj ); |
671 | 672 | ||
672 | if ( item.object() && !item.slot().isEmpty() ) { | 673 | if ( item.object() && !item.slot().isEmpty() ) { |
673 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), | 674 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), |
674 | item.object(), item.slot().data() ); | 675 | item.object(), item.slot().data() ); |
675 | emit actionActivated(wid, key); | 676 | emit actionActivated(wid, key); |
676 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), | 677 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), |
677 | item.object(), item.slot().data() ); | 678 | item.object(), item.slot().data() ); |
678 | } | 679 | } |
679 | emit actionActivated( wid, key, item ); | 680 | emit actionActivated( wid, key, item ); |
680 | 681 | ||
681 | return true; | 682 | return true; |
682 | } | 683 | } |
683 | 684 | ||
684 | /** | 685 | /** |
685 | * @internal | 686 | * @internal |
686 | */ | 687 | */ |
687 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { | 688 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { |
688 | /* | 689 | /* |
689 | * Create the map if not existing anymore | 690 | * Create the map if not existing anymore |
690 | */ | 691 | */ |
691 | if ( !m_map ) { | 692 | if ( !m_map ) { |
692 | m_map = new OKeyMapConfigPrivate; | 693 | m_map = new OKeyMapConfigPrivate; |
693 | /* for every key */ | 694 | /* for every key */ |
694 | for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); | 695 | for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); |
695 | it!= m_keys.end(); ++it ) { | 696 | it!= m_keys.end(); ++it ) { |
696 | 697 | ||
697 | bool add = true; | 698 | bool add = true; |
698 | /* see if this key is blocked */ | 699 | /* see if this key is blocked */ |
699 | OKeyPair pair = (*it).keyPair(); | 700 | OKeyPair pair = (*it).keyPair(); |
700 | for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); | 701 | for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); |
701 | pairIt != m_blackKeys.end(); ++pairIt ) { | 702 | pairIt != m_blackKeys.end(); ++pairIt ) { |
702 | if ( (*pairIt).keycode() == pair.keycode() && | 703 | if ( (*pairIt).keycode() == pair.keycode() && |
703 | (*pairIt).modifier() == pair.modifier() ) { | 704 | (*pairIt).modifier() == pair.modifier() ) { |
704 | add = false; | 705 | add = false; |
705 | break; | 706 | break; |
706 | } | 707 | } |
707 | } | 708 | } |
708 | /* check if we added it */ | 709 | /* check if we added it */ |
709 | if ( add ) | 710 | if ( add ) |
710 | (*m_map)[pair.keycode()].append( *it ); | 711 | (*m_map)[pair.keycode()].append( *it ); |
711 | } | 712 | } |
712 | } | 713 | } |
713 | return (*m_map)[keycode]; | 714 | return (*m_map)[keycode]; |
714 | } | 715 | } |
715 | 716 | ||
716 | 717 | ||
717 | namespace Opie { | 718 | namespace Opie { |
718 | namespace Ui { | 719 | namespace Ui { |
719 | namespace Private { | 720 | namespace Internal { |
720 | 721 | ||
721 | OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) | 722 | OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) |
722 | : Opie::Ui::OListViewItem( parent ), m_manager( man ) { | 723 | : Opie::Ui::OListViewItem( parent ), m_manager( man ) { |
723 | m_origItem = item; | 724 | m_origItem = item; |
724 | setItem( item ); | 725 | setItem( item ); |
725 | } | 726 | } |
726 | OKeyListViewItem::~OKeyListViewItem() {} | 727 | OKeyListViewItem::~OKeyListViewItem() {} |
727 | OKeyConfigItem &OKeyListViewItem::item(){ | 728 | OKeyConfigItem &OKeyListViewItem::item(){ |
728 | return m_item; | 729 | return m_item; |
729 | } | 730 | } |
730 | OKeyConfigItem OKeyListViewItem::origItem() const{ | 731 | OKeyConfigItem OKeyListViewItem::origItem() const{ |
731 | return m_origItem; | 732 | return m_origItem; |
732 | } | 733 | } |
733 | OKeyConfigManager* OKeyListViewItem::manager() { | 734 | OKeyConfigManager* OKeyListViewItem::manager() { |
734 | return m_manager; | 735 | return m_manager; |
735 | } | 736 | } |
736 | void OKeyListViewItem::setItem( const OKeyConfigItem& item ) { | 737 | void OKeyListViewItem::setItem( const OKeyConfigItem& item ) { |
737 | m_item = item; | 738 | m_item = item; |
738 | setPixmap( 0, m_item.pixmap() ); | 739 | setPixmap( 0, m_item.pixmap() ); |
739 | setText ( 1, m_item.text() ); | 740 | setText ( 1, m_item.text() ); |
740 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : | 741 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : |
741 | setText( 2, keyToString( m_item.keyPair() ) ); | 742 | setText( 2, keyToString( m_item.keyPair() ) ); |
742 | 743 | ||
743 | m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : | 744 | m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : |
744 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); | 745 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); |
745 | } | 746 | } |
746 | void OKeyListViewItem::updateText() { | 747 | void OKeyListViewItem::updateText() { |
747 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : | 748 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : |
748 | setText( 2, keyToString( m_item.keyPair() ) ); | 749 | setText( 2, keyToString( m_item.keyPair() ) ); |
749 | } | 750 | } |
750 | 751 | ||
751 | QString keyToString( const OKeyPair& pair ) { | 752 | QString keyToString( const OKeyPair& pair ) { |
752 | int mod = 0; | 753 | int mod = 0; |
753 | if ( pair.modifier() & Qt::ShiftButton ) | 754 | if ( pair.modifier() & Qt::ShiftButton ) |
754 | mod |= Qt::SHIFT; | 755 | mod |= Qt::SHIFT; |
755 | if ( pair.modifier() & Qt::ControlButton ) | 756 | if ( pair.modifier() & Qt::ControlButton ) |
756 | mod |= Qt::CTRL; | 757 | mod |= Qt::CTRL; |
757 | if ( pair.modifier() & Qt::AltButton ) | 758 | if ( pair.modifier() & Qt::AltButton ) |
758 | mod |= Qt::ALT; | 759 | mod |= Qt::ALT; |
759 | 760 | ||
760 | return QAccel::keyToString( mod + pair.keycode() ); | 761 | return QAccel::keyToString( mod + pair.keycode() ); |
761 | } | 762 | } |
762 | 763 | ||
763 | /* | 764 | /* |
764 | * the virtual and hardware key events have both issues... | 765 | * the virtual and hardware key events have both issues... |
765 | */ | 766 | */ |
766 | void fixupKeys( int& key, int &mod, QKeyEvent* e ) { | 767 | void fixupKeys( int& key, int &mod, QKeyEvent* e ) { |
767 | key = e->key(); | 768 | key = e->key(); |
768 | mod = e->state(); | 769 | mod = e->state(); |
769 | /* | 770 | /* |
770 | * virtual keyboard | 771 | * virtual keyboard |
771 | * else change the button mod only | 772 | * else change the button mod only |
772 | */ | 773 | */ |
773 | if ( key == 0 ) { | 774 | if ( key == 0 ) { |
774 | key = e->ascii(); | 775 | key = e->ascii(); |
775 | if ( key > 96 && key < 123) | 776 | if ( key > 96 && key < 123) |
776 | key -= 32; | 777 | key -= 32; |
777 | }else{ | 778 | }else{ |
778 | int new_mod = 0; | 779 | int new_mod = 0; |
779 | if ( mod & 256 ) | 780 | if ( mod & 256 ) |
780 | new_mod |= Qt::ShiftButton; | 781 | new_mod |= Qt::ShiftButton; |
781 | else if ( mod & 512 ) | 782 | else if ( mod & 512 ) |
782 | new_mod |= Qt::ControlButton; | 783 | new_mod |= Qt::ControlButton; |
783 | else if ( mod & 1024 ) | 784 | else if ( mod & 1024 ) |
784 | new_mod |= Qt::AltButton; | 785 | new_mod |= Qt::AltButton; |
785 | 786 | ||
786 | mod = new_mod == 0? mod : new_mod; | 787 | mod = new_mod == 0? mod : new_mod; |
787 | } | 788 | } |
788 | } | 789 | } |
789 | 790 | ||
790 | struct OKeyConfigWidgetPrivate{ | 791 | struct OKeyConfigWidgetPrivate{ |
791 | OKeyConfigWidgetPrivate(const QString& = QString::null, | 792 | OKeyConfigWidgetPrivate(const QString& = QString::null, |
792 | OKeyConfigManager* = 0); | 793 | OKeyConfigManager* = 0); |
793 | bool operator==( const OKeyConfigWidgetPrivate& ); | 794 | bool operator==( const OKeyConfigWidgetPrivate& ); |
794 | QString name; | 795 | QString name; |
795 | OKeyConfigManager *manager; | 796 | OKeyConfigManager *manager; |
796 | }; | 797 | }; |
797 | 798 | ||
798 | OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name, | 799 | OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name, |
799 | OKeyConfigManager* man ) | 800 | OKeyConfigManager* man ) |
800 | : name( _name ), manager( man ){} | 801 | : name( _name ), manager( man ){} |
801 | 802 | ||
802 | bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) { | 803 | bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) { |
803 | if ( manager != item.manager) return false; | 804 | if ( manager != item.manager) return false; |
804 | if ( name != item.name ) return false; | 805 | if ( name != item.name ) return false; |
805 | 806 | ||
806 | return true; | 807 | return true; |
807 | } | 808 | } |
808 | 809 | ||
809 | } | 810 | } |
810 | } | 811 | } |
811 | } | 812 | } |
812 | 813 | ||
813 | 814 | ||
814 | 815 | ||
815 | //////////////////////// | 816 | //////////////////////// |
816 | //////////////////////// | 817 | //////////////////////// |
817 | //////// Widget Starts Here | 818 | //////// Widget Starts Here |
818 | 819 | ||
819 | 820 | ||
820 | 821 | ||
821 | 822 | ||
822 | /** | 823 | /** |
823 | * | 824 | * |
824 | * This is a c'tor. You still need to pass the OKeyConfigManager | 825 | * This is a c'tor. You still need to pass the OKeyConfigManager |
825 | * and then issue a load. | 826 | * and then issue a load. |
826 | * The default mode is Immediate | 827 | * The default mode is Immediate |
827 | * | 828 | * |
828 | */ | 829 | */ |
829 | OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl ) | 830 | OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl ) |
830 | : QWidget( parent, name, fl ) { | 831 | : QWidget( parent, name, fl ) { |
831 | initUi(); | 832 | initUi(); |
832 | } | 833 | } |
833 | 834 | ||
834 | 835 | ||
835 | 836 | ||
836 | /** | 837 | /** |
837 | * c'tor | 838 | * c'tor |
838 | */ | 839 | */ |
839 | OKeyConfigWidget::~OKeyConfigWidget() { | 840 | OKeyConfigWidget::~OKeyConfigWidget() { |
840 | } | 841 | } |
841 | 842 | ||
842 | 843 | ||
843 | /** | 844 | /** |
844 | * @internal | 845 | * @internal |
845 | */ | 846 | */ |
846 | void OKeyConfigWidget::initUi() { | 847 | void OKeyConfigWidget::initUi() { |
847 | QBoxLayout *layout = new QVBoxLayout( this ); | 848 | QBoxLayout *layout = new QVBoxLayout( this ); |
848 | QGridLayout *gridLay = new QGridLayout( 2, 2 ); | 849 | QGridLayout *gridLay = new QGridLayout( 2, 2 ); |
849 | layout->addLayout( gridLay, 10 ); | 850 | layout->addLayout( gridLay, 10 ); |
850 | gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth | 851 | gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth |
851 | 852 | ||
852 | /* | 853 | /* |
853 | * LISTVIEW with the Keys | 854 | * LISTVIEW with the Keys |
854 | */ | 855 | */ |
855 | m_view = new Opie::Ui::OListView( this ); | 856 | m_view = new Opie::Ui::OListView( this ); |
856 | m_view->setFocus(); | 857 | m_view->setFocus(); |
857 | m_view->setAllColumnsShowFocus( true ); | 858 | m_view->setAllColumnsShowFocus( true ); |
858 | m_view->addColumn( tr("Pixmap") ); | 859 | m_view->addColumn( tr("Pixmap") ); |
859 | m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) ); | 860 | m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) ); |
860 | m_view->addColumn( tr("Key" ) ); | 861 | m_view->addColumn( tr("Key" ) ); |
861 | m_view->addColumn( tr("Default Key" ) ); | 862 | m_view->addColumn( tr("Default Key" ) ); |
862 | m_view->setRootIsDecorated( true ); | 863 | m_view->setRootIsDecorated( true ); |
863 | connect(m_view, SIGNAL(currentChanged(QListViewItem*)), | 864 | connect(m_view, SIGNAL(currentChanged(QListViewItem*)), |
864 | this, SLOT(slotListViewItem(QListViewItem*)) ); | 865 | this, SLOT(slotListViewItem(QListViewItem*)) ); |
865 | 866 | ||
866 | gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 ); | 867 | gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 ); |
867 | 868 | ||
868 | /* | 869 | /* |
869 | * GROUP with button info | 870 | * GROUP with button info |
870 | */ | 871 | */ |
871 | 872 | ||
872 | QGroupBox *box = new QGroupBox( this ); | 873 | QGroupBox *box = new QGroupBox( this ); |
873 | box ->setTitle( tr("Shortcut for Selected Action") ); | 874 | box ->setTitle( tr("Shortcut for Selected Action") ); |
874 | box ->setFrameStyle( QFrame::Box | QFrame::Sunken ); | 875 | box ->setFrameStyle( QFrame::Box | QFrame::Sunken ); |
875 | layout->addWidget( box, 1 ); | 876 | layout->addWidget( box, 1 ); |
876 | 877 | ||
877 | gridLay = new QGridLayout( box, 3, 4 ); | 878 | gridLay = new QGridLayout( box, 3, 4 ); |
878 | gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() ); | 879 | gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() ); |
879 | gridLay->setMargin( 4 ); | 880 | gridLay->setMargin( 4 ); |
880 | 881 | ||
881 | QButtonGroup *gr = new QButtonGroup( box ); | 882 | QButtonGroup *gr = new QButtonGroup( box ); |
882 | gr->hide(); | 883 | gr->hide(); |
883 | gr->setExclusive( true ); | 884 | gr->setExclusive( true ); |
884 | 885 | ||
885 | QRadioButton *rad = new QRadioButton( tr( "&None" ), box ); | 886 | QRadioButton *rad = new QRadioButton( tr( "&None" ), box ); |
886 | connect( rad, SIGNAL(clicked()), | 887 | connect( rad, SIGNAL(clicked()), |
887 | this, SLOT(slotNoKey()) ); | 888 | this, SLOT(slotNoKey()) ); |
888 | gr->insert( rad, 10 ); | 889 | gr->insert( rad, 10 ); |
889 | gridLay->addWidget( rad, 1, 0 ); | 890 | gridLay->addWidget( rad, 1, 0 ); |
890 | m_none = rad; | 891 | m_none = rad; |
891 | 892 | ||
892 | rad = new QRadioButton( tr("&Default" ), box ); | 893 | rad = new QRadioButton( tr("&Default" ), box ); |
893 | connect( rad, SIGNAL(clicked()), | 894 | connect( rad, SIGNAL(clicked()), |
894 | this, SLOT(slotDefaultKey()) ); | 895 | this, SLOT(slotDefaultKey()) ); |
895 | gr->insert( rad, 11 ); | 896 | gr->insert( rad, 11 ); |
896 | gridLay->addWidget( rad, 1, 1 ); | 897 | gridLay->addWidget( rad, 1, 1 ); |
897 | m_def = rad; | 898 | m_def = rad; |
898 | 899 | ||
899 | rad = new QRadioButton( tr("C&ustom"), box ); | 900 | rad = new QRadioButton( tr("C&ustom"), box ); |
900 | connect( rad, SIGNAL(clicked()), | 901 | connect( rad, SIGNAL(clicked()), |
901 | this, SLOT(slotCustomKey()) ); | 902 | this, SLOT(slotCustomKey()) ); |
902 | gr->insert( rad, 12 ); | 903 | gr->insert( rad, 12 ); |
903 | gridLay->addWidget( rad, 1, 2 ); | 904 | gridLay->addWidget( rad, 1, 2 ); |
904 | m_cus = rad; | 905 | m_cus = rad; |
905 | 906 | ||
906 | m_btn = new QPushButton( tr("Configure Key"), box ); | 907 | m_btn = new QPushButton( tr("Configure Key"), box ); |
907 | gridLay->addWidget( m_btn, 1, 4 ); | 908 | gridLay->addWidget( m_btn, 1, 4 ); |
908 | 909 | ||
909 | m_lbl= new QLabel( tr( "Default: " ), box ); | 910 | m_lbl= new QLabel( tr( "Default: " ), box ); |
910 | gridLay->addWidget( m_lbl, 2, 0 ); | 911 | gridLay->addWidget( m_lbl, 2, 0 ); |
911 | 912 | ||
912 | connect(m_btn, SIGNAL(clicked()), | 913 | connect(m_btn, SIGNAL(clicked()), |
913 | this, SLOT(slotConfigure())); | 914 | this, SLOT(slotConfigure())); |
914 | 915 | ||
915 | m_box = box; | 916 | m_box = box; |
916 | } | 917 | } |
917 | 918 | ||
918 | /** | 919 | /** |
919 | * Set the ChangeMode. | 920 | * Set the ChangeMode. |
920 | * You need to call this function prior to load | 921 | * You need to call this function prior to load |
921 | * If you call this function past load the behaviour is undefined | 922 | * If you call this function past load the behaviour is undefined |
922 | * But caling load again is safe | 923 | * But caling load again is safe |
923 | */ | 924 | */ |
924 | void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) { | 925 | void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) { |
925 | m_mode = mode; | 926 | m_mode = mode; |
926 | } | 927 | } |
927 | 928 | ||
928 | 929 | ||
929 | /** | 930 | /** |
930 | * return the current mode | 931 | * return the current mode |
931 | */ | 932 | */ |
932 | OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const { | 933 | OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const { |
933 | return m_mode; | 934 | return m_mode; |
934 | } | 935 | } |
935 | 936 | ||
936 | 937 | ||
937 | /** | 938 | /** |
938 | * insert these items before calling load | 939 | * insert these items before calling load |
939 | */ | 940 | */ |
940 | void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) { | 941 | void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) { |
941 | Opie::Ui::Private::OKeyConfigWidgetPrivate root( str, man ); | 942 | Opie::Ui::Internal::OKeyConfigWidgetPrivate root( str, man ); |
942 | m_list.append(root); | 943 | m_list.append(root); |
943 | } | 944 | } |
944 | 945 | ||
945 | 946 | ||
946 | /** | 947 | /** |
947 | * loads the items and allows editing them | 948 | * loads the items and allows editing them |
948 | */ | 949 | */ |
949 | void OKeyConfigWidget::load() { | 950 | void OKeyConfigWidget::load() { |
950 | Opie::Ui::Private::OKeyConfigWidgetPrivateList::Iterator it; | 951 | Opie::Ui::Internal::OKeyConfigWidgetPrivateList::Iterator it; |
951 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | 952 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { |
952 | OListViewItem *item = new OListViewItem( m_view, (*it).name ); | 953 | OListViewItem *item = new OListViewItem( m_view, (*it).name ); |
953 | OKeyConfigItem::List list = (*it).manager->keyConfigList(); | 954 | OKeyConfigItem::List list = (*it).manager->keyConfigList(); |
954 | for (OKeyConfigItem::List::Iterator keyIt = list.begin(); keyIt != list.end();++keyIt ) | 955 | for (OKeyConfigItem::List::Iterator keyIt = list.begin(); keyIt != list.end();++keyIt ) |
955 | (void )new Opie::Ui::Private::OKeyListViewItem(*keyIt, (*it).manager, item ); | 956 | (void )new Opie::Ui::Internal::OKeyListViewItem(*keyIt, (*it).manager, item ); |
956 | 957 | ||
957 | } | 958 | } |
958 | } | 959 | } |
959 | 960 | ||
960 | /** | 961 | /** |
961 | * Saves if in Queue Mode. It'll update the supplied | 962 | * Saves if in Queue Mode. It'll update the supplied |
962 | * OKeyConfigManager objects. | 963 | * OKeyConfigManager objects. |
963 | * If in Queue mode it'll just return | 964 | * If in Queue mode it'll just return |
964 | */ | 965 | */ |
965 | void OKeyConfigWidget::save() { | 966 | void OKeyConfigWidget::save() { |
966 | /* | 967 | /* |
967 | * Iterate over all config items | 968 | * Iterate over all config items |
968 | */ | 969 | */ |
969 | QListViewItemIterator it( m_view ); | 970 | QListViewItemIterator it( m_view ); |
970 | while ( it.current() ) { | 971 | while ( it.current() ) { |
971 | if (it.current()->parent() ) { | 972 | if (it.current()->parent() ) { |
972 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( it.current() ); | 973 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( it.current() ); |
973 | OKeyConfigManager *man = item->manager(); | 974 | OKeyConfigManager *man = item->manager(); |
974 | man->removeKeyConfig( item->origItem() ); | 975 | man->removeKeyConfig( item->origItem() ); |
975 | man->addKeyConfig( item->item() ); | 976 | man->addKeyConfig( item->item() ); |
976 | } | 977 | } |
977 | ++it; | 978 | ++it; |
978 | } | 979 | } |
979 | 980 | ||
980 | 981 | ||
981 | } | 982 | } |
982 | 983 | ||
983 | 984 | ||
984 | /** | 985 | /** |
985 | * @internal | 986 | * @internal |
986 | */ | 987 | */ |
987 | void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { | 988 | void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { |
988 | if ( !_item || !_item->parent() ) { | 989 | if ( !_item || !_item->parent() ) { |
989 | m_box->setEnabled( false ); | 990 | m_box->setEnabled( false ); |
990 | m_none->setChecked( true ); | 991 | m_none->setChecked( true ); |
991 | m_btn ->setEnabled( false ); | 992 | m_btn ->setEnabled( false ); |
992 | m_def ->setChecked( false ); | 993 | m_def ->setChecked( false ); |
993 | m_cus ->setChecked( false ); | 994 | m_cus ->setChecked( false ); |
994 | }else{ | 995 | }else{ |
995 | m_box->setEnabled( true ); | 996 | m_box->setEnabled( true ); |
996 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( _item ); | 997 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( _item ); |
997 | OKeyConfigItem keyItem= item->item(); | 998 | OKeyConfigItem keyItem= item->item(); |
998 | m_lbl->setText( tr("Default: " )+ item->text( 3 ) ); | 999 | m_lbl->setText( tr("Default: " )+ item->text( 3 ) ); |
999 | if ( keyItem.keyPair().isEmpty() ) { | 1000 | if ( keyItem.keyPair().isEmpty() ) { |
1000 | m_none->setChecked( true ); | 1001 | m_none->setChecked( true ); |
1001 | m_btn ->setEnabled( false ); | 1002 | m_btn ->setEnabled( false ); |
1002 | m_def ->setChecked( false ); | 1003 | m_def ->setChecked( false ); |
1003 | m_cus ->setChecked( false ); | 1004 | m_cus ->setChecked( false ); |
1004 | }else { | 1005 | }else { |
1005 | m_none->setChecked( false ); | 1006 | m_none->setChecked( false ); |
1006 | m_cus ->setChecked( true ); | 1007 | m_cus ->setChecked( true ); |
1007 | m_btn ->setEnabled( true ); | 1008 | m_btn ->setEnabled( true ); |
1008 | m_def ->setChecked( false ); | 1009 | m_def ->setChecked( false ); |
1009 | } | 1010 | } |
1010 | } | 1011 | } |
1011 | } | 1012 | } |
1012 | 1013 | ||
1013 | void OKeyConfigWidget::slotNoKey() { | 1014 | void OKeyConfigWidget::slotNoKey() { |
1014 | m_none->setChecked( true ); | 1015 | m_none->setChecked( true ); |
1015 | m_cus ->setChecked( false ); | 1016 | m_cus ->setChecked( false ); |
1016 | m_btn ->setEnabled( false ); | 1017 | m_btn ->setEnabled( false ); |
1017 | m_def ->setChecked( false ); | 1018 | m_def ->setChecked( false ); |
1018 | 1019 | ||
1019 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 1020 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1020 | return; | 1021 | return; |
1021 | 1022 | ||
1022 | 1023 | ||
1023 | 1024 | ||
1024 | /* | 1025 | /* |
1025 | * If immediate we need to remove and readd the key | 1026 | * If immediate we need to remove and readd the key |
1026 | */ | 1027 | */ |
1027 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); | 1028 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); |
1028 | updateItem( item, OKeyPair::emptyKey() ); | 1029 | updateItem( item, OKeyPair::emptyKey() ); |
1029 | } | 1030 | } |
1030 | 1031 | ||
1031 | void OKeyConfigWidget::slotDefaultKey() { | 1032 | void OKeyConfigWidget::slotDefaultKey() { |
1032 | m_none->setChecked( false ); | 1033 | m_none->setChecked( false ); |
1033 | m_cus ->setChecked( false ); | 1034 | m_cus ->setChecked( false ); |
1034 | m_btn ->setEnabled( false ); | 1035 | m_btn ->setEnabled( false ); |
1035 | m_def ->setChecked( true ); | 1036 | m_def ->setChecked( true ); |
1036 | 1037 | ||
1037 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 1038 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1038 | return; | 1039 | return; |
1039 | 1040 | ||
1040 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); | 1041 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); |
1041 | updateItem( item, item->item().defaultKeyPair() ); | 1042 | updateItem( item, item->item().defaultKeyPair() ); |
1042 | } | 1043 | } |
1043 | 1044 | ||
1044 | void OKeyConfigWidget::slotCustomKey() { | 1045 | void OKeyConfigWidget::slotCustomKey() { |
1045 | m_cus ->setChecked( true ); | 1046 | m_cus ->setChecked( true ); |
1046 | m_btn ->setEnabled( true ); | 1047 | m_btn ->setEnabled( true ); |
1047 | m_def ->setChecked( false ); | 1048 | m_def ->setChecked( false ); |
1048 | m_none->setChecked( false ); | 1049 | m_none->setChecked( false ); |
1049 | 1050 | ||
1050 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 1051 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1051 | return; | 1052 | return; |
1052 | 1053 | ||
1053 | 1054 | ||
1054 | } | 1055 | } |
1055 | 1056 | ||
1056 | void OKeyConfigWidget::slotConfigure() { | 1057 | void OKeyConfigWidget::slotConfigure() { |
1057 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 1058 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1058 | return; | 1059 | return; |
1059 | 1060 | ||
1060 | /* FIXME make use of OModalHelper */ | 1061 | /* FIXME make use of OModalHelper */ |
1061 | OKeyChooserConfigDialog dlg( this, "Dialog Name", true ); | 1062 | OKeyChooserConfigDialog dlg( this, "Dialog Name", true ); |
1062 | dlg.setCaption(tr("Configure Key")); | 1063 | dlg.setCaption(tr("Configure Key")); |
1063 | connect(&dlg, SIGNAL(keyCaptured()), &dlg, SLOT(accept()) ); | 1064 | connect(&dlg, SIGNAL(keyCaptured()), &dlg, SLOT(accept()) ); |
1064 | 1065 | ||
1065 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) { | 1066 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) { |
1066 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); | 1067 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); |
1067 | updateItem( item, dlg.keyPair() ); | 1068 | updateItem( item, dlg.keyPair() ); |
1068 | } | 1069 | } |
1069 | 1070 | ||
1070 | 1071 | ||
1071 | } | 1072 | } |
1072 | 1073 | ||
1073 | bool OKeyConfigWidget::sanityCheck( Opie::Ui::Private::OKeyListViewItem* item, | 1074 | bool OKeyConfigWidget::sanityCheck( Opie::Ui::Internal::OKeyListViewItem* item, |
1074 | const OKeyPair& newItem ) { | 1075 | const OKeyPair& newItem ) { |
1075 | OKeyPair::List bList = item->manager()->blackList(); | 1076 | OKeyPair::List bList = item->manager()->blackList(); |
1076 | for ( OKeyPair::List::Iterator it = bList.begin(); it != bList.end(); ++it ) { | 1077 | for ( OKeyPair::List::Iterator it = bList.begin(); it != bList.end(); ++it ) { |
1077 | /* black list matched */ | 1078 | /* black list matched */ |
1078 | if ( *it == newItem ) { | 1079 | if ( *it == newItem ) { |
1079 | QMessageBox::warning( 0, tr("Key is on BlackList" ), | 1080 | QMessageBox::warning( 0, tr("Key is on BlackList" ), |
1080 | tr("<qt>The Key you choose is on the black list " | 1081 | tr("<qt>The Key you choose is on the black list " |
1081 | "and may not be used with this manager. Please " | 1082 | "and may not be used with this manager. Please " |
1082 | "use a different key.</qt>" ) ); | 1083 | "use a different key.</qt>" ) ); |
1083 | return false; | 1084 | return false; |
1084 | } | 1085 | } |
1085 | } | 1086 | } |
1086 | /* no we need to check the other items which is dog slow */ | 1087 | /* no we need to check the other items which is dog slow */ |
1087 | QListViewItemIterator it( item->parent() ); | 1088 | QListViewItemIterator it( item->parent() ); |
1088 | while ( it.current() ) { | 1089 | while ( it.current() ) { |
1089 | /* if not our parent and not us */ | 1090 | /* if not our parent and not us */ |
1090 | if (it.current()->parent() && it.current() != item) { | 1091 | if (it.current()->parent() && it.current() != item) { |
1091 | /* damn already given away*/ | 1092 | /* damn already given away*/ |
1092 | if ( newItem == static_cast<Opie::Ui::Private::OKeyListViewItem*>(it.current() )->item().keyPair() ) { | 1093 | if ( newItem == static_cast<Opie::Ui::Internal::OKeyListViewItem*>(it.current() )->item().keyPair() ) { |
1093 | QMessageBox::warning( 0, tr("Key is already assigned" ), | 1094 | QMessageBox::warning( 0, tr("Key is already assigned" ), |
1094 | tr("<qt>The Key you choose is already taken by " | 1095 | tr("<qt>The Key you choose is already taken by " |
1095 | "a different Item of your config. Please try" | 1096 | "a different Item of your config. Please try" |
1096 | "using a different key.</qt>" ) ); | 1097 | "using a different key.</qt>" ) ); |
1097 | return false; | 1098 | return false; |
1098 | } | 1099 | } |
1099 | } | 1100 | } |
1100 | ++it; | 1101 | ++it; |
1101 | } | 1102 | } |
1102 | 1103 | ||
1103 | return true; | 1104 | return true; |
1104 | } | 1105 | } |
1105 | 1106 | ||
1106 | void OKeyConfigWidget::updateItem( Opie::Ui::Private::OKeyListViewItem *item, | 1107 | void OKeyConfigWidget::updateItem( Opie::Ui::Internal::OKeyListViewItem *item, |
1107 | const OKeyPair& newItem) { | 1108 | const OKeyPair& newItem) { |
1108 | /* sanity check | 1109 | /* sanity check |
1109 | * check against the blacklist of the manager | 1110 | * check against the blacklist of the manager |
1110 | * check if another item uses this key which is o(n) at least | 1111 | * check if another item uses this key which is o(n) at least |
1111 | */ | 1112 | */ |
1112 | if ( !newItem.isEmpty() && !sanityCheck(item, newItem )) | 1113 | if ( !newItem.isEmpty() && !sanityCheck(item, newItem )) |
1113 | return; | 1114 | return; |
1114 | 1115 | ||
1115 | 1116 | ||
1116 | 1117 | ||
1117 | /* | 1118 | /* |
1118 | * If immediate we need to remove and readd the key | 1119 | * If immediate we need to remove and readd the key |
1119 | */ | 1120 | */ |
1120 | if ( m_mode == Imediate ) | 1121 | if ( m_mode == Imediate ) |
1121 | item->manager()->removeKeyConfig( item->item() ); | 1122 | item->manager()->removeKeyConfig( item->item() ); |
1122 | 1123 | ||
1123 | item->item().setKeyPair( newItem ); | 1124 | item->item().setKeyPair( newItem ); |
1124 | item->updateText(); | 1125 | item->updateText(); |
1125 | 1126 | ||
1126 | if ( m_mode == Imediate ) | 1127 | if ( m_mode == Imediate ) |
1127 | item->manager()->addKeyConfig( item->item() ); | 1128 | item->manager()->addKeyConfig( item->item() ); |
1128 | } | 1129 | } |
1129 | 1130 | ||
1130 | 1131 | ||
1131 | 1132 | ||
1132 | ///// | 1133 | ///// |
1133 | OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, | 1134 | OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, |
1134 | bool mod, WFlags fl ) | 1135 | bool mod, WFlags fl ) |
1135 | : QDialog( par, nam, mod, fl ), m_virtKey( false ), m_keyPair( OKeyPair::emptyKey() ) , | 1136 | : QDialog( par, nam, mod, fl ), m_virtKey( false ), m_keyPair( OKeyPair::emptyKey() ) , |
1136 | m_key( 0 ), m_mod( 0 ) { | 1137 | m_key( 0 ), m_mod( 0 ) { |
1137 | setFocusPolicy( StrongFocus ); | 1138 | setFocusPolicy( StrongFocus ); |
1138 | 1139 | ||
1139 | QHBoxLayout *lay = new QHBoxLayout( this ); | 1140 | QHBoxLayout *lay = new QHBoxLayout( this ); |
1140 | 1141 | ||
1141 | QLabel *lbl = new QLabel( tr("Configure Key" ), this ); | 1142 | QLabel *lbl = new QLabel( tr("Configure Key" ), this ); |
1142 | lay->addWidget( lbl ); | 1143 | lay->addWidget( lbl ); |
1143 | lbl->setFocusPolicy( NoFocus ); | 1144 | lbl->setFocusPolicy( NoFocus ); |
1144 | 1145 | ||
1145 | m_lbl = new QLabel( this ); | 1146 | m_lbl = new QLabel( this ); |
1146 | lay->addWidget( m_lbl ); | 1147 | lay->addWidget( m_lbl ); |
1147 | m_lbl->setFocusPolicy( NoFocus ); | 1148 | m_lbl->setFocusPolicy( NoFocus ); |
1148 | 1149 | ||
1149 | m_timer = new QTimer( this ); | 1150 | m_timer = new QTimer( this ); |
1150 | connect(m_timer, SIGNAL(timeout()), | 1151 | connect(m_timer, SIGNAL(timeout()), |
1151 | this, SLOT(slotTimeUp()) ); | 1152 | this, SLOT(slotTimeUp()) ); |
1152 | } | 1153 | } |
1153 | 1154 | ||
1154 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { | 1155 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { |
1155 | } | 1156 | } |
1156 | 1157 | ||
1157 | Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ | 1158 | Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ |
1158 | return m_keyPair; | 1159 | return m_keyPair; |
1159 | } | 1160 | } |
1160 | 1161 | ||
1161 | void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { | 1162 | void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { |
1162 | QDialog::keyPressEvent( ev ); | 1163 | QDialog::keyPressEvent( ev ); |
1163 | 1164 | ||
1164 | if ( ev->isAutoRepeat() ) | 1165 | if ( ev->isAutoRepeat() ) |
1165 | return; | 1166 | return; |
1166 | 1167 | ||
1167 | int mod, key; | 1168 | int mod, key; |
1168 | Opie::Ui::Private::fixupKeys( key,mod, ev ); | 1169 | Opie::Ui::Internal::fixupKeys( key,mod, ev ); |
1169 | 1170 | ||
1170 | /* either we used software keyboard | 1171 | /* either we used software keyboard |
1171 | * or we've true support | 1172 | * or we've true support |
1172 | */ | 1173 | */ |
1173 | if ( !m_virtKey && !ev->key()) { | 1174 | if ( !m_virtKey && !ev->key()) { |
1174 | m_virtKey = true; | 1175 | m_virtKey = true; |
1175 | m_keyPair = OKeyPair( key, mod ); | 1176 | m_keyPair = OKeyPair( key, mod ); |
1176 | }else{ | 1177 | }else{ |
1177 | mod = 0; | 1178 | mod = 0; |
1178 | switch( key ) { | 1179 | switch( key ) { |
1179 | case Qt::Key_Control: | 1180 | case Qt::Key_Control: |
1180 | mod = Qt::ControlButton; | 1181 | mod = Qt::ControlButton; |
1181 | break; | 1182 | break; |
1182 | case Qt::Key_Shift: | 1183 | case Qt::Key_Shift: |
1183 | mod = Qt::ShiftButton; | 1184 | mod = Qt::ShiftButton; |
1184 | break; | 1185 | break; |
1185 | case Qt::Key_Alt: | 1186 | case Qt::Key_Alt: |
1186 | mod = Qt::AltButton; | 1187 | mod = Qt::AltButton; |
1187 | break; | 1188 | break; |
1188 | default: | 1189 | default: |
1189 | break; | 1190 | break; |
1190 | } | 1191 | } |
1191 | if (mod ) { | 1192 | if (mod ) { |
1192 | m_mod |= mod; | 1193 | m_mod |= mod; |
1193 | key = 0; | 1194 | key = 0; |
1194 | }else | 1195 | }else |
1195 | m_key = key; | 1196 | m_key = key; |
1196 | 1197 | ||
1197 | if ( ( !mod || m_key || key ) && !m_timer->isActive() ) | 1198 | if ( ( !mod || m_key || key ) && !m_timer->isActive() ) |
1198 | m_timer->start( 150, true ); | 1199 | m_timer->start( 150, true ); |
1199 | 1200 | ||
1200 | m_keyPair = OKeyPair( m_key, m_mod ); | 1201 | m_keyPair = OKeyPair( m_key, m_mod ); |
1201 | } | 1202 | } |
1202 | 1203 | ||
1203 | m_lbl->setText( Opie::Ui::Private::keyToString( m_keyPair ) ); | 1204 | m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) ); |
1204 | 1205 | ||
1205 | } | 1206 | } |
1206 | 1207 | ||
1207 | void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { | 1208 | void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { |
1208 | m_timer->stop(); | 1209 | m_timer->stop(); |
1209 | QDialog::keyPressEvent( ev ); | 1210 | QDialog::keyPressEvent( ev ); |
1210 | 1211 | ||
1211 | if ( ev->isAutoRepeat() ) | 1212 | if ( ev->isAutoRepeat() ) |
1212 | return; | 1213 | return; |
1213 | 1214 | ||
1214 | 1215 | ||
1215 | if ( m_virtKey && !ev->key()) { | 1216 | if ( m_virtKey && !ev->key()) { |
1216 | m_virtKey = false; | 1217 | m_virtKey = false; |
1217 | slotTimeUp(); | 1218 | slotTimeUp(); |
1218 | }else { | 1219 | }else { |
1219 | int mod = 0; | 1220 | int mod = 0; |
1220 | int key = ev->key(); | 1221 | int key = ev->key(); |
1221 | switch( key ) { | 1222 | switch( key ) { |
1222 | case Qt::Key_Control: | 1223 | case Qt::Key_Control: |
1223 | mod = Qt::ControlButton; | 1224 | mod = Qt::ControlButton; |
1224 | break; | 1225 | break; |
1225 | case Qt::Key_Shift: | 1226 | case Qt::Key_Shift: |
1226 | mod = Qt::ShiftButton; | 1227 | mod = Qt::ShiftButton; |
1227 | break; | 1228 | break; |
1228 | case Qt::Key_Alt: | 1229 | case Qt::Key_Alt: |
1229 | mod = Qt::AltButton; | 1230 | mod = Qt::AltButton; |
1230 | break; | 1231 | break; |
1231 | default: | 1232 | default: |
1232 | break; | 1233 | break; |
1233 | } | 1234 | } |
1234 | if (mod ) | 1235 | if (mod ) |
1235 | m_mod &= ~mod; | 1236 | m_mod &= ~mod; |
1236 | else | 1237 | else |
1237 | m_key = key; | 1238 | m_key = key; |
1238 | m_keyPair = OKeyPair( m_key, m_mod ); | 1239 | m_keyPair = OKeyPair( m_key, m_mod ); |
1239 | m_lbl->setText( Opie::Ui::Private::keyToString( m_keyPair ) ); | 1240 | m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) ); |
1240 | } | 1241 | } |
1241 | } | 1242 | } |
1242 | 1243 | ||
1243 | 1244 | ||
1244 | void OKeyChooserConfigDialog::slotTimeUp() { | 1245 | void OKeyChooserConfigDialog::slotTimeUp() { |
1245 | m_mod = m_key = 0; | 1246 | m_mod = m_key = 0; |
1246 | QTimer::singleShot(0, this, SIGNAL(keyCaptured()) ); | 1247 | QTimer::singleShot(0, this, SIGNAL(keyCaptured()) ); |
1247 | } | 1248 | } |
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h index f75ed99..bb8eb6c 100644 --- a/libopie2/opieui/okeyconfigwidget.h +++ b/libopie2/opieui/okeyconfigwidget.h | |||
@@ -1,322 +1,322 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2004 | 2 | * Copyright (C) 2004 |
3 | * LGPL v2 zecke@handhelds.org | 3 | * LGPL v2 zecke@handhelds.org |
4 | */ | 4 | */ |
5 | 5 | ||
6 | 6 | ||
7 | #ifndef ODP_KEY_CONFIG_WIDGET_H | 7 | #ifndef ODP_KEY_CONFIG_WIDGET_H |
8 | #define ODP_KEY_CONFIG_WIDGET_H | 8 | #define ODP_KEY_CONFIG_WIDGET_H |
9 | 9 | ||
10 | #include <opie2/oconfig.h> | 10 | #include <opie2/oconfig.h> |
11 | #include <opie2/odevice.h> | 11 | #include <opie2/odevice.h> |
12 | 12 | ||
13 | #include <qstring.h> | 13 | #include <qstring.h> |
14 | #include <qpixmap.h> | 14 | #include <qpixmap.h> |
15 | #include <qcstring.h> | 15 | #include <qcstring.h> |
16 | #include <qhbox.h> | 16 | #include <qhbox.h> |
17 | #include <qvaluelist.h> | 17 | #include <qvaluelist.h> |
18 | 18 | ||
19 | class QKeyEvent; | 19 | class QKeyEvent; |
20 | class QLabel; | 20 | class QLabel; |
21 | class QPushButton; | 21 | class QPushButton; |
22 | class QListViewItem; | 22 | class QListViewItem; |
23 | class QRadioButton; | 23 | class QRadioButton; |
24 | class QTimer; | 24 | class QTimer; |
25 | 25 | ||
26 | namespace Opie { | 26 | namespace Opie { |
27 | namespace Ui { | 27 | namespace Ui { |
28 | namespace Private { | 28 | namespace Internal { |
29 | class OKeyConfigWidgetPrivate; | 29 | class OKeyConfigWidgetPrivate; |
30 | typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; | 30 | typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; |
31 | class OKeyListViewItem; | 31 | class OKeyListViewItem; |
32 | } | 32 | } |
33 | class OListViewItem; | 33 | class OListViewItem; |
34 | class OListView; | 34 | class OListView; |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * \brief small class representing a Key with possible modifiers | 37 | * \brief small class representing a Key with possible modifiers |
38 | * This class holds information about key code and possible | 38 | * This class holds information about key code and possible |
39 | * modifier state. That is the lowest level of the key input | 39 | * modifier state. That is the lowest level of the key input |
40 | * functions. | 40 | * functions. |
41 | * There are also static methods to get special keys. | 41 | * There are also static methods to get special keys. |
42 | * OKeyPair will be used with \see OKeyConfigItem | 42 | * OKeyPair will be used with \see OKeyConfigItem |
43 | * | 43 | * |
44 | * @since 1.2 | 44 | * @since 1.2 |
45 | */ | 45 | */ |
46 | class OKeyPair { | 46 | class OKeyPair { |
47 | public: | 47 | public: |
48 | typedef QValueList<OKeyPair> List; | 48 | typedef QValueList<OKeyPair> List; |
49 | OKeyPair( int key = -1, int modifier = -1); | 49 | OKeyPair( int key = -1, int modifier = -1); |
50 | ~OKeyPair(); | 50 | ~OKeyPair(); |
51 | 51 | ||
52 | bool operator==( const OKeyPair& )const; | 52 | bool operator==( const OKeyPair& )const; |
53 | bool operator!=( const OKeyPair& )const; | 53 | bool operator!=( const OKeyPair& )const; |
54 | 54 | ||
55 | bool isEmpty()const; | 55 | bool isEmpty()const; |
56 | 56 | ||
57 | int keycode()const; | 57 | int keycode()const; |
58 | int modifier()const; | 58 | int modifier()const; |
59 | 59 | ||
60 | void setKeycode( int ); | 60 | void setKeycode( int ); |
61 | void setModifier( int ); | 61 | void setModifier( int ); |
62 | 62 | ||
63 | static OKeyPair returnKey(); | 63 | static OKeyPair returnKey(); |
64 | static OKeyPair leftArrowKey(); | 64 | static OKeyPair leftArrowKey(); |
65 | static OKeyPair rightArrowKey(); | 65 | static OKeyPair rightArrowKey(); |
66 | static OKeyPair upArrowKey(); | 66 | static OKeyPair upArrowKey(); |
67 | static OKeyPair downArrowKey(); | 67 | static OKeyPair downArrowKey(); |
68 | static OKeyPair emptyKey(); | 68 | static OKeyPair emptyKey(); |
69 | static OKeyPair::List hardwareKeys(); | 69 | static OKeyPair::List hardwareKeys(); |
70 | 70 | ||
71 | private: | 71 | private: |
72 | int m_key; | 72 | int m_key; |
73 | int m_mod; | 73 | int m_mod; |
74 | class Private; | 74 | class Private; |
75 | Private* d; | 75 | Private* d; |
76 | }; | 76 | }; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * A class to represent an OKeyPair. | 79 | * A class to represent an OKeyPair. |
80 | * It consists out of a Text exposed to the user, Config Key Item, | 80 | * It consists out of a Text exposed to the user, Config Key Item, |
81 | * Pixmap, A default OKeyPair and the set OKeyPair. | 81 | * Pixmap, A default OKeyPair and the set OKeyPair. |
82 | * You can also pass an id to it | 82 | * You can also pass an id to it |
83 | * | 83 | * |
84 | * @since 1.1.2 | 84 | * @since 1.1.2 |
85 | */ | 85 | */ |
86 | class OKeyConfigItem { | 86 | class OKeyConfigItem { |
87 | friend class OKeyConfigManager; | 87 | friend class OKeyConfigManager; |
88 | public: | 88 | public: |
89 | typedef QValueList<OKeyConfigItem> List; | 89 | typedef QValueList<OKeyConfigItem> List; |
90 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), | 90 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), |
91 | const QPixmap& symbol = QPixmap(), | 91 | const QPixmap& symbol = QPixmap(), |
92 | int id = -1, | 92 | int id = -1, |
93 | const OKeyPair& def = OKeyPair::emptyKey(), | 93 | const OKeyPair& def = OKeyPair::emptyKey(), |
94 | QObject *caller = 0, const char* slot = 0); | 94 | QObject *caller = 0, const char* slot = 0); |
95 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); | 95 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); |
96 | ~OKeyConfigItem(); | 96 | ~OKeyConfigItem(); |
97 | 97 | ||
98 | bool operator==( const OKeyConfigItem& )const; | 98 | bool operator==( const OKeyConfigItem& )const; |
99 | bool operator!=( const OKeyConfigItem& )const; | 99 | bool operator!=( const OKeyConfigItem& )const; |
100 | 100 | ||
101 | QString text()const; | 101 | QString text()const; |
102 | QPixmap pixmap()const; | 102 | QPixmap pixmap()const; |
103 | int id()const; | 103 | int id()const; |
104 | 104 | ||
105 | 105 | ||
106 | 106 | ||
107 | OKeyPair keyPair()const; | 107 | OKeyPair keyPair()const; |
108 | OKeyPair defaultKeyPair()const; | 108 | OKeyPair defaultKeyPair()const; |
109 | QCString configKey()const; | 109 | QCString configKey()const; |
110 | 110 | ||
111 | 111 | ||
112 | void setText( const QString& text ); | 112 | void setText( const QString& text ); |
113 | void setPixmap( const QPixmap& ); | 113 | void setPixmap( const QPixmap& ); |
114 | void setKeyPair( const OKeyPair& ); | 114 | void setKeyPair( const OKeyPair& ); |
115 | void setDefaultKeyPair( const OKeyPair& ); | 115 | void setDefaultKeyPair( const OKeyPair& ); |
116 | 116 | ||
117 | bool isEmpty()const; | 117 | bool isEmpty()const; |
118 | 118 | ||
119 | protected: | 119 | protected: |
120 | QObject *object()const; | 120 | QObject *object()const; |
121 | QCString slot()const; | 121 | QCString slot()const; |
122 | void setId( int id ); | 122 | void setId( int id ); |
123 | void setConfigKey( const QCString& ); | 123 | void setConfigKey( const QCString& ); |
124 | 124 | ||
125 | private: | 125 | private: |
126 | QString m_text; | 126 | QString m_text; |
127 | QCString m_config; | 127 | QCString m_config; |
128 | QPixmap m_pix; | 128 | QPixmap m_pix; |
129 | int m_id; | 129 | int m_id; |
130 | OKeyPair m_key; | 130 | OKeyPair m_key; |
131 | OKeyPair m_def; | 131 | OKeyPair m_def; |
132 | QObject *m_obj; | 132 | QObject *m_obj; |
133 | QCString m_str; | 133 | QCString m_str; |
134 | class Private; | 134 | class Private; |
135 | Private *d; | 135 | Private *d; |
136 | }; | 136 | }; |
137 | 137 | ||
138 | 138 | ||
139 | 139 | ||
140 | /** | 140 | /** |
141 | * \brief A manager to load and save Key Actions and get notified | 141 | * \brief A manager to load and save Key Actions and get notified |
142 | * This is the Manager for KeyActions. | 142 | * This is the Manager for KeyActions. |
143 | * You can say from which config and group to read data, to grab the | 143 | * You can say from which config and group to read data, to grab the |
144 | * keyboard to handle hardware keys, you can supply a blacklist of | 144 | * keyboard to handle hardware keys, you can supply a blacklist of |
145 | * keys which should not be used by allowed to be used. | 145 | * keys which should not be used by allowed to be used. |
146 | * You can even pass this manager to a Widget to do the configuration for you. | 146 | * You can even pass this manager to a Widget to do the configuration for you. |
147 | * You need to add OKeyConfigItem for your keys and then issue a load() to | 147 | * You need to add OKeyConfigItem for your keys and then issue a load() to |
148 | * read the Key information. | 148 | * read the Key information. |
149 | * You can either handle the QKeyEvent yourself and ask this class if it is | 149 | * You can either handle the QKeyEvent yourself and ask this class if it is |
150 | * handled by your action and let give you the action. Or you can install | 150 | * handled by your action and let give you the action. Or you can install |
151 | * the event filter and get a signal. | 151 | * the event filter and get a signal. |
152 | * You need to load ans save yourself! | 152 | * You need to load ans save yourself! |
153 | * | 153 | * |
154 | * @since 1.1.2 | 154 | * @since 1.1.2 |
155 | */ | 155 | */ |
156 | class OKeyConfigManager : public QObject { | 156 | class OKeyConfigManager : public QObject { |
157 | Q_OBJECT | 157 | Q_OBJECT |
158 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; | 158 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; |
159 | public: | 159 | public: |
160 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, | 160 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, |
161 | const QString& group = QString::null, | 161 | const QString& group = QString::null, |
162 | const OKeyPair::List &block = OKeyPair::List(), | 162 | const OKeyPair::List &block = OKeyPair::List(), |
163 | bool grabkeyboard = false, QObject * par = 0, | 163 | bool grabkeyboard = false, QObject * par = 0, |
164 | const char* name = 0 ); | 164 | const char* name = 0 ); |
165 | ~OKeyConfigManager(); | 165 | ~OKeyConfigManager(); |
166 | 166 | ||
167 | void load(); | 167 | void load(); |
168 | void save(); | 168 | void save(); |
169 | 169 | ||
170 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); | 170 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); |
171 | int handleKeyEventId( QKeyEvent* ); | 171 | int handleKeyEventId( QKeyEvent* ); |
172 | 172 | ||
173 | void addKeyConfig( const OKeyConfigItem& ); | 173 | void addKeyConfig( const OKeyConfigItem& ); |
174 | void removeKeyConfig( const OKeyConfigItem& ); | 174 | void removeKeyConfig( const OKeyConfigItem& ); |
175 | void clearKeyConfig(); | 175 | void clearKeyConfig(); |
176 | 176 | ||
177 | void addToBlackList( const OKeyPair& ); | 177 | void addToBlackList( const OKeyPair& ); |
178 | void removeFromBlackList( const OKeyPair& ); | 178 | void removeFromBlackList( const OKeyPair& ); |
179 | void clearBlackList(); | 179 | void clearBlackList(); |
180 | OKeyPair::List blackList()const; | 180 | OKeyPair::List blackList()const; |
181 | 181 | ||
182 | void handleWidget( QWidget* ); | 182 | void handleWidget( QWidget* ); |
183 | 183 | ||
184 | bool eventFilter( QObject*, QEvent* ); | 184 | bool eventFilter( QObject*, QEvent* ); |
185 | 185 | ||
186 | OKeyConfigItem::List keyConfigList()const; | 186 | OKeyConfigItem::List keyConfigList()const; |
187 | signals: | 187 | signals: |
188 | /** | 188 | /** |
189 | * The Signals are triggered on KeyPress and KeyRelease! | 189 | * The Signals are triggered on KeyPress and KeyRelease! |
190 | * You can check the isDown of the QKeyEvent | 190 | * You can check the isDown of the QKeyEvent |
191 | * @see QKeyEvent | 191 | * @see QKeyEvent |
192 | */ | 192 | */ |
193 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); | 193 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); |
194 | 194 | ||
195 | /** | 195 | /** |
196 | * This Signal correspondents to the OKeyConfigItem slot | 196 | * This Signal correspondents to the OKeyConfigItem slot |
197 | * and object | 197 | * and object |
198 | * | 198 | * |
199 | * @see OKeyConfigItem::slot | 199 | * @see OKeyConfigItem::slot |
200 | * @see OKeyConfigItem::object | 200 | * @see OKeyConfigItem::object |
201 | */ | 201 | */ |
202 | void actionActivated( QWidget* par, QKeyEvent* key); | 202 | void actionActivated( QWidget* par, QKeyEvent* key); |
203 | 203 | ||
204 | private: | 204 | private: |
205 | OKeyConfigItem::List keyList( int ); | 205 | OKeyConfigItem::List keyList( int ); |
206 | OKeyConfigItem::List m_keys; | 206 | OKeyConfigItem::List m_keys; |
207 | QValueList<QWidget*> m_widgets; | 207 | QValueList<QWidget*> m_widgets; |
208 | Opie::Core::OConfig *m_conf; | 208 | Opie::Core::OConfig *m_conf; |
209 | QString m_group; | 209 | QString m_group; |
210 | OKeyPair::List m_blackKeys; | 210 | OKeyPair::List m_blackKeys; |
211 | bool m_grab : 1; | 211 | bool m_grab : 1; |
212 | OKeyMapConfigPrivate *m_map; | 212 | OKeyMapConfigPrivate *m_map; |
213 | class Private; | 213 | class Private; |
214 | Private *d; | 214 | Private *d; |
215 | }; | 215 | }; |
216 | 216 | ||
217 | 217 | ||
218 | /** | 218 | /** |
219 | * With this Widget you can let the Keyboard Shortcuts | 219 | * With this Widget you can let the Keyboard Shortcuts |
220 | * be configured by the user. | 220 | * be configured by the user. |
221 | * There are two ways you can use this widget. Either in a tab were | 221 | * There are two ways you can use this widget. Either in a tab were |
222 | * all changes are immediately getting into effect or in a queue | 222 | * all changes are immediately getting into effect or in a queue |
223 | * were you ask for saving. Save won't write the data but only set | 223 | * were you ask for saving. Save won't write the data but only set |
224 | * it to the OKeyConfigManager | 224 | * it to the OKeyConfigManager |
225 | * | 225 | * |
226 | * @since 1.2 | 226 | * @since 1.2 |
227 | */ | 227 | */ |
228 | class OKeyConfigWidget : public QWidget { | 228 | class OKeyConfigWidget : public QWidget { |
229 | Q_OBJECT | 229 | Q_OBJECT |
230 | 230 | ||
231 | public: | 231 | public: |
232 | /** | 232 | /** |
233 | * Immediate Apply the change directly to the underlying OKeyConfigManager | 233 | * Immediate Apply the change directly to the underlying OKeyConfigManager |
234 | * Queue Save all items and then apply when you save() | 234 | * Queue Save all items and then apply when you save() |
235 | */ | 235 | */ |
236 | enum ChangeMode { Imediate, Queue }; | 236 | enum ChangeMode { Imediate, Queue }; |
237 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 237 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
238 | ~OKeyConfigWidget(); | 238 | ~OKeyConfigWidget(); |
239 | 239 | ||
240 | void setChangeMode( enum ChangeMode ); | 240 | void setChangeMode( enum ChangeMode ); |
241 | ChangeMode changeMode()const; | 241 | ChangeMode changeMode()const; |
242 | 242 | ||
243 | void insert( const QString& name, OKeyConfigManager* ); | 243 | void insert( const QString& name, OKeyConfigManager* ); |
244 | 244 | ||
245 | void load(); | 245 | void load(); |
246 | void save(); | 246 | void save(); |
247 | 247 | ||
248 | private slots: | 248 | private slots: |
249 | void slotListViewItem( QListViewItem* ); | 249 | void slotListViewItem( QListViewItem* ); |
250 | void slotNoKey(); | 250 | void slotNoKey(); |
251 | void slotDefaultKey(); | 251 | void slotDefaultKey(); |
252 | void slotCustomKey(); | 252 | void slotCustomKey(); |
253 | void slotConfigure(); | 253 | void slotConfigure(); |
254 | 254 | ||
255 | private: | 255 | private: |
256 | static bool sanityCheck( Opie::Ui::Private::OKeyListViewItem* man, | 256 | static bool sanityCheck( Opie::Ui::Internal::OKeyListViewItem* man, |
257 | const OKeyPair& newItem ); | 257 | const OKeyPair& newItem ); |
258 | void updateItem( Opie::Ui::Private::OKeyListViewItem* man, | 258 | void updateItem( Opie::Ui::Internal::OKeyListViewItem* man, |
259 | const OKeyPair& newItem); | 259 | const OKeyPair& newItem); |
260 | void initUi(); | 260 | void initUi(); |
261 | Opie::Ui::OListView *m_view; | 261 | Opie::Ui::OListView *m_view; |
262 | Opie::Ui::Private::OKeyConfigWidgetPrivateList m_list; | 262 | Opie::Ui::Internal::OKeyConfigWidgetPrivateList m_list; |
263 | QLabel *m_lbl; | 263 | QLabel *m_lbl; |
264 | QPushButton *m_btn; | 264 | QPushButton *m_btn; |
265 | QRadioButton *m_def, *m_cus, *m_none; | 265 | QRadioButton *m_def, *m_cus, *m_none; |
266 | QWidget* m_box; | 266 | QWidget* m_box; |
267 | ChangeMode m_mode; | 267 | ChangeMode m_mode; |
268 | class Private; | 268 | class Private; |
269 | Private *d; | 269 | Private *d; |
270 | }; | 270 | }; |
271 | 271 | ||
272 | 272 | ||
273 | /** | 273 | /** |
274 | * This is a small dialog that allows you to | 274 | * This is a small dialog that allows you to |
275 | * capture a key sequence. | 275 | * capture a key sequence. |
276 | * If you want it to close after a key was captured you | 276 | * If you want it to close after a key was captured you |
277 | * can use this code snippet. | 277 | * can use this code snippet. |
278 | * | 278 | * |
279 | * \code | 279 | * \code |
280 | * OKeyChooserConfigDialog diag(0,0,true); | 280 | * OKeyChooserConfigDialog diag(0,0,true); |
281 | * connect(&diag,SIGNAL(keyCaptured()), | 281 | * connect(&diag,SIGNAL(keyCaptured()), |
282 | * this,SLOT(accept())); | 282 | * this,SLOT(accept())); |
283 | * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){ | 283 | * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){ |
284 | * take_the_key_and_do_something | 284 | * take_the_key_and_do_something |
285 | * } | 285 | * } |
286 | * | 286 | * |
287 | * \endcode | 287 | * \endcode |
288 | * | 288 | * |
289 | */ | 289 | */ |
290 | class OKeyChooserConfigDialog : public QDialog { | 290 | class OKeyChooserConfigDialog : public QDialog { |
291 | Q_OBJECT | 291 | Q_OBJECT |
292 | public: | 292 | public: |
293 | OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); | 293 | OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); |
294 | ~OKeyChooserConfigDialog(); | 294 | ~OKeyChooserConfigDialog(); |
295 | 295 | ||
296 | OKeyPair keyPair()const; | 296 | OKeyPair keyPair()const; |
297 | 297 | ||
298 | protected: | 298 | protected: |
299 | void keyPressEvent( QKeyEvent* ); | 299 | void keyPressEvent( QKeyEvent* ); |
300 | void keyReleaseEvent( QKeyEvent* ); | 300 | void keyReleaseEvent( QKeyEvent* ); |
301 | 301 | ||
302 | signals: | 302 | signals: |
303 | void keyCaptured(); | 303 | void keyCaptured(); |
304 | 304 | ||
305 | private slots: | 305 | private slots: |
306 | void slotTimeUp(); | 306 | void slotTimeUp(); |
307 | 307 | ||
308 | private: | 308 | private: |
309 | QTimer *m_timer; | 309 | QTimer *m_timer; |
310 | QLabel *m_lbl; | 310 | QLabel *m_lbl; |
311 | bool m_virtKey : 1; | 311 | bool m_virtKey : 1; |
312 | OKeyPair m_keyPair; | 312 | OKeyPair m_keyPair; |
313 | int m_key, m_mod; | 313 | int m_key, m_mod; |
314 | class Private; | 314 | class Private; |
315 | Private *d; | 315 | Private *d; |
316 | }; | 316 | }; |
317 | 317 | ||
318 | } | 318 | } |
319 | } | 319 | } |
320 | 320 | ||
321 | 321 | ||
322 | #endif | 322 | #endif |
diff --git a/libopie2/opieui/okeyconfigwidget_p.h b/libopie2/opieui/okeyconfigwidget_p.h index e7eaba6..7690846 100644 --- a/libopie2/opieui/okeyconfigwidget_p.h +++ b/libopie2/opieui/okeyconfigwidget_p.h | |||
@@ -1,33 +1,33 @@ | |||
1 | /* | 1 | /* |
2 | * Only Internal implemented in the same .cpp file anyway | 2 | * Only Internal implemented in the same .cpp file anyway |
3 | */ | 3 | */ |
4 | #include <opie2/olistview.h> | 4 | #include <opie2/olistview.h> |
5 | 5 | ||
6 | 6 | ||
7 | namespace Opie { | 7 | namespace Opie { |
8 | namespace Ui { | 8 | namespace Ui { |
9 | namespace Private { | 9 | namespace Internal { |
10 | static QString keyToString( const OKeyPair& ); | 10 | static QString keyToString( const OKeyPair& ); |
11 | static void fixupKeys( int&, int&, QKeyEvent* ); | 11 | static void fixupKeys( int&, int&, QKeyEvent* ); |
12 | class OKeyListViewItem : public Opie::Ui::OListViewItem { | 12 | class OKeyListViewItem : public Opie::Ui::OListViewItem { |
13 | public: | 13 | public: |
14 | OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager*, Opie::Ui::OListViewItem* parent); | 14 | OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager*, Opie::Ui::OListViewItem* parent); |
15 | ~OKeyListViewItem(); | 15 | ~OKeyListViewItem(); |
16 | 16 | ||
17 | void setDefault(); | 17 | void setDefault(); |
18 | 18 | ||
19 | OKeyConfigItem& item(); | 19 | OKeyConfigItem& item(); |
20 | OKeyConfigItem origItem()const; | 20 | OKeyConfigItem origItem()const; |
21 | void setItem( const OKeyConfigItem& item ); | 21 | void setItem( const OKeyConfigItem& item ); |
22 | void updateText(); | 22 | void updateText(); |
23 | 23 | ||
24 | OKeyConfigManager *manager(); | 24 | OKeyConfigManager *manager(); |
25 | private: | 25 | private: |
26 | OKeyConfigItem m_item; | 26 | OKeyConfigItem m_item; |
27 | OKeyConfigItem m_origItem; | 27 | OKeyConfigItem m_origItem; |
28 | OKeyConfigManager* m_manager; | 28 | OKeyConfigManager* m_manager; |
29 | 29 | ||
30 | }; | 30 | }; |
31 | } | 31 | } |
32 | } | 32 | } |
33 | } | 33 | } |
diff --git a/libopie2/opieui/otaskbarapplet.h b/libopie2/opieui/otaskbarapplet.h index 0c85ee7..ec7b9c4 100644 --- a/libopie2/opieui/otaskbarapplet.h +++ b/libopie2/opieui/otaskbarapplet.h | |||
@@ -1,129 +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 | #include <qpe/qcom.h> |
37 | 37 | ||
38 | #include <qwidget.h> | 38 | #include <qwidget.h> |
39 | 39 | ||
40 | class QMouseEvent; | 40 | class QMouseEvent; |
41 | 41 | ||
42 | namespace Opie { | 42 | namespace Opie { |
43 | namespace Ui { | 43 | namespace Ui { |
44 | namespace Private { | 44 | namespace Internal { |
45 | /*====================================================================================== | 45 | /*====================================================================================== |
46 | * OTaskbarAppletWrapper | 46 | * OTaskbarAppletWrapper |
47 | *======================================================================================*/ | 47 | *======================================================================================*/ |
48 | 48 | ||
49 | class OTaskbarAppletWrapperPrivate; | 49 | class OTaskbarAppletWrapperPrivate; |
50 | template<class T> class OTaskbarAppletWrapper : public TaskbarAppletInterface | 50 | template<class T> class OTaskbarAppletWrapper : public TaskbarAppletInterface |
51 | { | 51 | { |
52 | public: | 52 | public: |
53 | OTaskbarAppletWrapper():_applet( 0 ) | 53 | OTaskbarAppletWrapper():_applet( 0 ) |
54 | { | 54 | { |
55 | } | 55 | } |
56 | 56 | ||
57 | virtual ~OTaskbarAppletWrapper() | 57 | virtual ~OTaskbarAppletWrapper() |
58 | { | 58 | { |
59 | delete _applet; | 59 | delete _applet; |
60 | } | 60 | } |
61 | 61 | ||
62 | QRESULT queryInterface( const QUuid& uuid, QUnknownInterface** iface ) | 62 | QRESULT queryInterface( const QUuid& uuid, QUnknownInterface** iface ) |
63 | { | 63 | { |
64 | qDebug( "OTaskbarAppletWrapper::queryInterface()" ); | 64 | qDebug( "OTaskbarAppletWrapper::queryInterface()" ); |
65 | *iface = 0; | 65 | *iface = 0; |
66 | if ( uuid == IID_QUnknown ) | 66 | if ( uuid == IID_QUnknown ) |
67 | *iface = this; | 67 | *iface = this; |
68 | else if ( uuid == IID_TaskbarApplet ) | 68 | else if ( uuid == IID_TaskbarApplet ) |
69 | *iface = this; | 69 | *iface = this; |
70 | else | 70 | else |
71 | return QS_FALSE; | 71 | return QS_FALSE; |
72 | 72 | ||
73 | if ( *iface ) (*iface)->addRef(); | 73 | if ( *iface ) (*iface)->addRef(); |
74 | return QS_OK; | 74 | return QS_OK; |
75 | } | 75 | } |
76 | 76 | ||
77 | Q_REFCOUNT | 77 | Q_REFCOUNT |
78 | 78 | ||
79 | virtual T* applet( QWidget* parent ) | 79 | virtual T* applet( QWidget* parent ) |
80 | { | 80 | { |
81 | if ( !_applet ) _applet = new T( parent ); | 81 | if ( !_applet ) _applet = new T( parent ); |
82 | return _applet; | 82 | return _applet; |
83 | } | 83 | } |
84 | 84 | ||
85 | virtual int position() const | 85 | virtual int position() const |
86 | { | 86 | { |
87 | return T::position(); | 87 | return T::position(); |
88 | } | 88 | } |
89 | 89 | ||
90 | private: | 90 | private: |
91 | T* _applet; | 91 | T* _applet; |
92 | OTaskbarAppletWrapperPrivate *d; | 92 | OTaskbarAppletWrapperPrivate *d; |
93 | }; | 93 | }; |
94 | 94 | ||
95 | } | 95 | } |
96 | /*====================================================================================== | 96 | /*====================================================================================== |
97 | * OTaskbarApplet | 97 | * OTaskbarApplet |
98 | *======================================================================================*/ | 98 | *======================================================================================*/ |
99 | 99 | ||
100 | // Must be inline until after we shipped Opie 1.0 | 100 | // Must be inline until after we shipped Opie 1.0 |
101 | 101 | ||
102 | // Having OTaskBarApplet reside in libopieui2 is not possible | 102 | // Having OTaskBarApplet reside in libopieui2 is not possible |
103 | // until we link the launcher binary against libopieui2 - | 103 | // until we link the launcher binary against libopieui2 - |
104 | // otherwise the necessary symbols are not present, when | 104 | // otherwise the necessary symbols are not present, when |
105 | // the dynamic loader [dlopen] tries to resolve an applet which | 105 | // the dynamic loader [dlopen] tries to resolve an applet which |
106 | // inherits OTaskbarApplet | 106 | // inherits OTaskbarApplet |
107 | 107 | ||
108 | class OTaskbarApplet : public QWidget | 108 | class OTaskbarApplet : public QWidget |
109 | { | 109 | { |
110 | public: | 110 | public: |
111 | OTaskbarApplet( QWidget* parent, const char* name = 0 ); | 111 | OTaskbarApplet( QWidget* parent, const char* name = 0 ); |
112 | virtual ~OTaskbarApplet(); | 112 | virtual ~OTaskbarApplet(); |
113 | 113 | ||
114 | protected: | 114 | protected: |
115 | virtual void popup( QWidget* widget ); | 115 | virtual void popup( QWidget* widget ); |
116 | private: | 116 | private: |
117 | class Private; | 117 | class Private; |
118 | Private *d; | 118 | Private *d; |
119 | }; | 119 | }; |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | #define EXPORT_OPIE_APPLET_v1( AppLet ) \ | 123 | #define EXPORT_OPIE_APPLET_v1( AppLet ) \ |
124 | Q_EXPORT_INTERFACE() { \ | 124 | Q_EXPORT_INTERFACE() { \ |
125 | Q_CREATE_INSTANCE( Opie::Ui::Private::OTaskbarAppletWrapper<AppLet> ) \ | 125 | Q_CREATE_INSTANCE( Opie::Ui::Internal::OTaskbarAppletWrapper<AppLet> ) \ |
126 | } | 126 | } |
127 | 127 | ||
128 | #endif | 128 | #endif |
129 | 129 | ||