-rw-r--r-- | libopie2/opieui/ofontselector.cpp | 1 | ||||
-rw-r--r-- | libopie2/opieui/olistview.cpp | 3 | ||||
-rw-r--r-- | libopie2/opieui/opopupmenu.cpp | 7 | ||||
-rw-r--r-- | libopie2/opieui/oselector.cpp | 1 | ||||
-rw-r--r-- | libopie2/opieui/oseparator.cpp | 1 | ||||
-rw-r--r-- | libopie2/opieui/otimepicker.cpp | 3 | ||||
-rw-r--r-- | libopie2/opieui/oversatileview.cpp | 11 |
7 files changed, 0 insertions, 27 deletions
diff --git a/libopie2/opieui/ofontselector.cpp b/libopie2/opieui/ofontselector.cpp index 49628c9..49ddeb6 100644 --- a/libopie2/opieui/ofontselector.cpp +++ b/libopie2/opieui/ofontselector.cpp | |||
@@ -1,429 +1,428 @@ | |||
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 <qfont.h> | ||
40 | #include <qmultilineedit.h> | 39 | #include <qmultilineedit.h> |
41 | 40 | ||
42 | using namespace Opie; | 41 | using namespace Opie; |
43 | 42 | ||
44 | namespace Opie | 43 | namespace Opie |
45 | { | 44 | { |
46 | 45 | ||
47 | class OFontSelectorPrivate | 46 | class OFontSelectorPrivate |
48 | { | 47 | { |
49 | public: | 48 | public: |
50 | QListBox * m_font_family_list; | 49 | QListBox * m_font_family_list; |
51 | QComboBox * m_font_style_list; | 50 | QComboBox * m_font_style_list; |
52 | QComboBox * m_font_size_list; | 51 | QComboBox * m_font_size_list; |
53 | QMultiLineEdit *m_preview; | 52 | QMultiLineEdit *m_preview; |
54 | 53 | ||
55 | bool m_pointbug : 1; | 54 | bool m_pointbug : 1; |
56 | 55 | ||
57 | FontDatabase m_fdb; | 56 | FontDatabase m_fdb; |
58 | }; | 57 | }; |
59 | 58 | ||
60 | }; | 59 | }; |
61 | 60 | ||
62 | namespace | 61 | namespace |
63 | { | 62 | { |
64 | 63 | ||
65 | class FontListItem : public QListBoxText | 64 | class FontListItem : public QListBoxText |
66 | { | 65 | { |
67 | public: | 66 | public: |
68 | FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText() | 67 | FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText() |
69 | { | 68 | { |
70 | m_name = t; | 69 | m_name = t; |
71 | m_styles = styles; | 70 | m_styles = styles; |
72 | m_sizes = sizes; | 71 | m_sizes = sizes; |
73 | 72 | ||
74 | QString str = t; | 73 | QString str = t; |
75 | str [0] = str [0]. upper(); | 74 | str [0] = str [0]. upper(); |
76 | setText ( str ); | 75 | setText ( str ); |
77 | } | 76 | } |
78 | 77 | ||
79 | QString family() const | 78 | QString family() const |
80 | { | 79 | { |
81 | return m_name; | 80 | return m_name; |
82 | } | 81 | } |
83 | 82 | ||
84 | const QStringList &styles() const | 83 | const QStringList &styles() const |
85 | { | 84 | { |
86 | return m_styles; | 85 | return m_styles; |
87 | } | 86 | } |
88 | 87 | ||
89 | const QValueList<int> &sizes() const | 88 | const QValueList<int> &sizes() const |
90 | { | 89 | { |
91 | return m_sizes; | 90 | return m_sizes; |
92 | } | 91 | } |
93 | 92 | ||
94 | private: | 93 | private: |
95 | QStringList m_styles; | 94 | QStringList m_styles; |
96 | QValueList<int> m_sizes; | 95 | QValueList<int> m_sizes; |
97 | QString m_name; | 96 | QString m_name; |
98 | }; | 97 | }; |
99 | 98 | ||
100 | 99 | ||
101 | static int findItemCB( QComboBox *box, const QString &str ) | 100 | static int findItemCB( QComboBox *box, const QString &str ) |
102 | { | 101 | { |
103 | for ( int i = 0; i < box->count(); i++ ) | 102 | for ( int i = 0; i < box->count(); i++ ) |
104 | { | 103 | { |
105 | if ( box->text ( i ) == str ) | 104 | if ( box->text ( i ) == str ) |
106 | return i; | 105 | return i; |
107 | } | 106 | } |
108 | return -1; | 107 | return -1; |
109 | } | 108 | } |
110 | 109 | ||
111 | } | 110 | } |
112 | /* static same as anon. namespace */ | 111 | /* static same as anon. namespace */ |
113 | static int qt_version() | 112 | static int qt_version() |
114 | { | 113 | { |
115 | const char *qver = qVersion(); | 114 | const char *qver = qVersion(); |
116 | 115 | ||
117 | 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' ); |
118 | } | 117 | } |
119 | 118 | ||
120 | /** | 119 | /** |
121 | * Constructs the Selector object | 120 | * Constructs the Selector object |
122 | * @param withpreview If a font preview should be given | 121 | * @param withpreview If a font preview should be given |
123 | * @param parent The parent of the Font Selector | 122 | * @param parent The parent of the Font Selector |
124 | * @param name The name of the object | 123 | * @param name The name of the object |
125 | * @param fl WidgetFlags | 124 | * @param fl WidgetFlags |
126 | */ | 125 | */ |
127 | 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 ) |
128 | { | 127 | { |
129 | d = new OFontSelectorPrivate(); | 128 | d = new OFontSelectorPrivate(); |
130 | 129 | ||
131 | QGridLayout *gridLayout = new QGridLayout( this, 0, 0, 4, 4 ); | 130 | QGridLayout *gridLayout = new QGridLayout( this, 0, 0, 4, 4 ); |
132 | gridLayout->setRowStretch( 4, 10 ); | 131 | gridLayout->setRowStretch( 4, 10 ); |
133 | 132 | ||
134 | d->m_font_family_list = new QListBox( this, "FontListBox" ); | 133 | d->m_font_family_list = new QListBox( this, "FontListBox" ); |
135 | gridLayout->addMultiCellWidget( d->m_font_family_list, 0, 4, 0, 0 ); | 134 | gridLayout->addMultiCellWidget( d->m_font_family_list, 0, 4, 0, 0 ); |
136 | 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 ) ) ); |
137 | 136 | ||
138 | QLabel *label = new QLabel( tr( "Style" ), this ); | 137 | QLabel *label = new QLabel( tr( "Style" ), this ); |
139 | gridLayout->addWidget( label, 0, 1 ); | 138 | gridLayout->addWidget( label, 0, 1 ); |
140 | 139 | ||
141 | d->m_font_style_list = new QComboBox( this, "StyleListBox" ); | 140 | d->m_font_style_list = new QComboBox( this, "StyleListBox" ); |
142 | 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 ) ) ); |
143 | gridLayout->addWidget( d->m_font_style_list, 1, 1 ); | 142 | gridLayout->addWidget( d->m_font_style_list, 1, 1 ); |
144 | 143 | ||
145 | label = new QLabel( tr( "Size" ), this ); | 144 | label = new QLabel( tr( "Size" ), this ); |
146 | gridLayout->addWidget( label, 2, 1 ); | 145 | gridLayout->addWidget( label, 2, 1 ); |
147 | 146 | ||
148 | d->m_font_size_list = new QComboBox( this, "SizeListBox" ); | 147 | d->m_font_size_list = new QComboBox( this, "SizeListBox" ); |
149 | connect( d->m_font_size_list, SIGNAL( activated( int ) ), | 148 | connect( d->m_font_size_list, SIGNAL( activated( int ) ), |
150 | this, SLOT( fontSizeClicked( int ) ) ); | 149 | this, SLOT( fontSizeClicked( int ) ) ); |
151 | gridLayout->addWidget( d->m_font_size_list, 3, 1 ); | 150 | gridLayout->addWidget( d->m_font_size_list, 3, 1 ); |
152 | 151 | ||
153 | d->m_pointbug = ( qt_version() <= 233 ); | 152 | d->m_pointbug = ( qt_version() <= 233 ); |
154 | 153 | ||
155 | if ( withpreview ) | 154 | if ( withpreview ) |
156 | { | 155 | { |
157 | d->m_preview = new QMultiLineEdit ( this, "Preview" ); | 156 | d->m_preview = new QMultiLineEdit ( this, "Preview" ); |
158 | d->m_preview->setAlignment ( AlignCenter ); | 157 | d->m_preview->setAlignment ( AlignCenter ); |
159 | d->m_preview->setWordWrap ( QMultiLineEdit::WidgetWidth ); | 158 | d->m_preview->setWordWrap ( QMultiLineEdit::WidgetWidth ); |
160 | d->m_preview->setMargin ( 3 ); | 159 | d->m_preview->setMargin ( 3 ); |
161 | 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" )); |
162 | gridLayout->addRowSpacing ( 5, 4 ); | 161 | gridLayout->addRowSpacing ( 5, 4 ); |
163 | gridLayout->addMultiCellWidget ( d->m_preview, 6, 6, 0, 1 ); | 162 | gridLayout->addMultiCellWidget ( d->m_preview, 6, 6, 0, 1 ); |
164 | gridLayout->setRowStretch ( 6, 5 ); | 163 | gridLayout->setRowStretch ( 6, 5 ); |
165 | } | 164 | } |
166 | else | 165 | else |
167 | d->m_preview = 0; | 166 | d->m_preview = 0; |
168 | 167 | ||
169 | loadFonts ( d->m_font_family_list ); | 168 | loadFonts ( d->m_font_family_list ); |
170 | } | 169 | } |
171 | 170 | ||
172 | OFontSelector::~OFontSelector() | 171 | OFontSelector::~OFontSelector() |
173 | { | 172 | { |
174 | delete d; | 173 | delete d; |
175 | } | 174 | } |
176 | 175 | ||
177 | /** | 176 | /** |
178 | * This methods tries to set the font | 177 | * This methods tries to set the font |
179 | * @param f The wishes font | 178 | * @param f The wishes font |
180 | * @return success or failure | 179 | * @return success or failure |
181 | */ | 180 | */ |
182 | bool OFontSelector::setSelectedFont ( const QFont &f ) | 181 | bool OFontSelector::setSelectedFont ( const QFont &f ) |
183 | { | 182 | { |
184 | 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())); |
185 | } | 184 | } |
186 | 185 | ||
187 | 186 | ||
188 | /** | 187 | /** |
189 | * This is an overloaded method @see setSelectedFont | 188 | * This is an overloaded method @see setSelectedFont |
190 | * @param familyStr The family of the font | 189 | * @param familyStr The family of the font |
191 | * @param styleStr The style of the font | 190 | * @param styleStr The style of the font |
192 | * @param sizeVal The size of font | 191 | * @param sizeVal The size of font |
193 | * @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 |
194 | */ | 193 | */ |
195 | 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 ) |
196 | { | 195 | { |
197 | QString sizeStr = QString::number ( sizeVal ); | 196 | QString sizeStr = QString::number ( sizeVal ); |
198 | 197 | ||
199 | QListBoxItem *family = d->m_font_family_list->findItem ( familyStr ); | 198 | QListBoxItem *family = d->m_font_family_list->findItem ( familyStr ); |
200 | if ( !family ) | 199 | if ( !family ) |
201 | family = d->m_font_family_list->findItem ( "Helvetica" ); | 200 | family = d->m_font_family_list->findItem ( "Helvetica" ); |
202 | if ( !family ) | 201 | if ( !family ) |
203 | family = d->m_font_family_list->firstItem(); | 202 | family = d->m_font_family_list->firstItem(); |
204 | d->m_font_family_list->setCurrentItem ( family ); | 203 | d->m_font_family_list->setCurrentItem ( family ); |
205 | fontFamilyClicked ( d->m_font_family_list->index ( family )); | 204 | fontFamilyClicked ( d->m_font_family_list->index ( family )); |
206 | 205 | ||
207 | int style = findItemCB ( d->m_font_style_list, styleStr ); | 206 | int style = findItemCB ( d->m_font_style_list, styleStr ); |
208 | if ( style < 0 ) | 207 | if ( style < 0 ) |
209 | style = findItemCB ( d->m_font_style_list, "Regular" ); | 208 | style = findItemCB ( d->m_font_style_list, "Regular" ); |
210 | if ( style < 0 && d->m_font_style_list->count() > 0 ) | 209 | if ( style < 0 && d->m_font_style_list->count() > 0 ) |
211 | style = 0; | 210 | style = 0; |
212 | d->m_font_style_list->setCurrentItem ( style ); | 211 | d->m_font_style_list->setCurrentItem ( style ); |
213 | fontStyleClicked ( style ); | 212 | fontStyleClicked ( style ); |
214 | 213 | ||
215 | int size = findItemCB ( d->m_font_size_list, sizeStr ); | 214 | int size = findItemCB ( d->m_font_size_list, sizeStr ); |
216 | if ( size < 0 ) | 215 | if ( size < 0 ) |
217 | size = findItemCB ( d->m_font_size_list, "10" ); | 216 | size = findItemCB ( d->m_font_size_list, "10" ); |
218 | if ( size < 0 && d->m_font_size_list->count() > 0 ) | 217 | if ( size < 0 && d->m_font_size_list->count() > 0 ) |
219 | size = 0; | 218 | size = 0; |
220 | d->m_font_size_list->setCurrentItem ( size ); | 219 | d->m_font_size_list->setCurrentItem ( size ); |
221 | fontSizeClicked ( size ); | 220 | fontSizeClicked ( size ); |
222 | 221 | ||
223 | return (( family ) && ( style >= 0 ) && ( size >= 0 )); | 222 | return (( family ) && ( style >= 0 ) && ( size >= 0 )); |
224 | } | 223 | } |
225 | 224 | ||
226 | /** | 225 | /** |
227 | * 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 |
228 | * font or false if no font is selected | 227 | * font or false if no font is selected |
229 | * @param family The font family will be written there | 228 | * @param family The font family will be written there |
230 | * @param style The style will be written there | 229 | * @param style The style will be written there |
231 | * @param size The size will be written there | 230 | * @param size The size will be written there |
232 | * @return success or failure | 231 | * @return success or failure |
233 | */ | 232 | */ |
234 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) | 233 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) |
235 | { | 234 | { |
236 | QString dummy; | 235 | QString dummy; |
237 | return selectedFont ( family, style, size, dummy ); | 236 | return selectedFont ( family, style, size, dummy ); |
238 | } | 237 | } |
239 | 238 | ||
240 | 239 | ||
241 | /** | 240 | /** |
242 | * 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 |
243 | * no font item selected | 242 | * no font item selected |
244 | * @return the font family | 243 | * @return the font family |
245 | */ | 244 | */ |
246 | QString OFontSelector::fontFamily() const | 245 | QString OFontSelector::fontFamily() const |
247 | { | 246 | { |
248 | 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()); |
249 | 248 | ||
250 | return fli ? fli->family() : QString::null; | 249 | return fli ? fli->family() : QString::null; |
251 | } | 250 | } |
252 | 251 | ||
253 | /** | 252 | /** |
254 | * 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 |
255 | * @return the style of the font | 254 | * @return the style of the font |
256 | */ | 255 | */ |
257 | QString OFontSelector::fontStyle() const | 256 | QString OFontSelector::fontStyle() const |
258 | { | 257 | { |
259 | 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()); |
260 | int fst = d->m_font_style_list->currentItem(); | 259 | int fst = d->m_font_style_list->currentItem(); |
261 | 260 | ||
262 | return ( fli && fst >= 0 ) ? fli->styles() [fst] : QString::null; | 261 | return ( fli && fst >= 0 ) ? fli->styles() [fst] : QString::null; |
263 | } | 262 | } |
264 | 263 | ||
265 | /** | 264 | /** |
266 | * 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 |
267 | */ | 266 | */ |
268 | int OFontSelector::fontSize() const | 267 | int OFontSelector::fontSize() const |
269 | { | 268 | { |
270 | 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()); |
271 | int fsi = d->m_font_size_list->currentItem(); | 270 | int fsi = d->m_font_size_list->currentItem(); |
272 | 271 | ||
273 | return ( fli && fsi >= 0 ) ? fli->sizes() [fsi] : 10; | 272 | return ( fli && fsi >= 0 ) ? fli->sizes() [fsi] : 10; |
274 | } | 273 | } |
275 | 274 | ||
276 | /** | 275 | /** |
277 | * returns the charset of the font or QString::null | 276 | * returns the charset of the font or QString::null |
278 | */ | 277 | */ |
279 | QString OFontSelector::fontCharSet() const | 278 | QString OFontSelector::fontCharSet() const |
280 | { | 279 | { |
281 | 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()); |
282 | 281 | ||
283 | return fli ? d->m_fdb. charSets ( fli->family()) [0] : QString::null; | 282 | return fli ? d->m_fdb. charSets ( fli->family()) [0] : QString::null; |
284 | } | 283 | } |
285 | 284 | ||
286 | /** | 285 | /** |
287 | * Overloaded member function see above | 286 | * Overloaded member function see above |
288 | * @see selectedFont | 287 | * @see selectedFont |
289 | */ | 288 | */ |
290 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) | 289 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) |
291 | { | 290 | { |
292 | int ffa = d->m_font_family_list->currentItem(); | 291 | int ffa = d->m_font_family_list->currentItem(); |
293 | int fst = d->m_font_style_list->currentItem(); | 292 | int fst = d->m_font_style_list->currentItem(); |
294 | int fsi = d->m_font_size_list->currentItem(); | 293 | int fsi = d->m_font_size_list->currentItem(); |
295 | 294 | ||
296 | FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa ); | 295 | FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa ); |
297 | 296 | ||
298 | if ( fli ) | 297 | if ( fli ) |
299 | { | 298 | { |
300 | family = fli->family(); | 299 | family = fli->family(); |
301 | style = fst >= 0 ? fli->styles() [fst] : QString::null; | 300 | style = fst >= 0 ? fli->styles() [fst] : QString::null; |
302 | size = fsi >= 0 ? fli->sizes() [fsi] : 10; | 301 | size = fsi >= 0 ? fli->sizes() [fsi] : 10; |
303 | charset = d->m_fdb. charSets ( fli->family()) [0]; | 302 | charset = d->m_fdb. charSets ( fli->family()) [0]; |
304 | 303 | ||
305 | return true; | 304 | return true; |
306 | } | 305 | } |
307 | else | 306 | else |
308 | return false; | 307 | return false; |
309 | } | 308 | } |
310 | 309 | ||
311 | void OFontSelector::loadFonts ( QListBox *list ) | 310 | void OFontSelector::loadFonts ( QListBox *list ) |
312 | { | 311 | { |
313 | QStringList f = d->m_fdb. families(); | 312 | QStringList f = d->m_fdb. families(); |
314 | 313 | ||
315 | for ( QStringList::ConstIterator it = f. begin(); it != f. end(); ++it ) | 314 | for ( QStringList::ConstIterator it = f. begin(); it != f. end(); ++it ) |
316 | { | 315 | { |
317 | QValueList <int> ps = d->m_fdb. pointSizes ( *it ); | 316 | QValueList <int> ps = d->m_fdb. pointSizes ( *it ); |
318 | 317 | ||
319 | if ( d->m_pointbug ) | 318 | if ( d->m_pointbug ) |
320 | { | 319 | { |
321 | for ( QValueList <int>::Iterator it = ps. begin(); it != ps. end(); it++ ) | 320 | for ( QValueList <int>::Iterator it = ps. begin(); it != ps. end(); it++ ) |
322 | *it /= 10; | 321 | *it /= 10; |
323 | } | 322 | } |
324 | 323 | ||
325 | list->insertItem ( new FontListItem ( *it, d->m_fdb. styles ( *it ), ps )); | 324 | list->insertItem ( new FontListItem ( *it, d->m_fdb. styles ( *it ), ps )); |
326 | } | 325 | } |
327 | } | 326 | } |
328 | 327 | ||
329 | void OFontSelector::fontFamilyClicked ( int index ) | 328 | void OFontSelector::fontFamilyClicked ( int index ) |
330 | { | 329 | { |
331 | QString oldstyle = d->m_font_style_list->currentText(); | 330 | QString oldstyle = d->m_font_style_list->currentText(); |
332 | QString oldsize = d->m_font_size_list->currentText(); | 331 | QString oldsize = d->m_font_size_list->currentText(); |
333 | 332 | ||
334 | FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( index ); | 333 | FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( index ); |
335 | 334 | ||
336 | d->m_font_style_list->clear(); | 335 | d->m_font_style_list->clear(); |
337 | d->m_font_style_list->insertStringList ( fli->styles()); | 336 | d->m_font_style_list->insertStringList ( fli->styles()); |
338 | d->m_font_style_list->setEnabled ( !fli->styles(). isEmpty()); | 337 | d->m_font_style_list->setEnabled ( !fli->styles(). isEmpty()); |
339 | 338 | ||
340 | int i; | 339 | int i; |
341 | 340 | ||
342 | i = findItemCB ( d->m_font_style_list, oldstyle ); | 341 | i = findItemCB ( d->m_font_style_list, oldstyle ); |
343 | if ( i < 0 ) | 342 | if ( i < 0 ) |
344 | i = findItemCB ( d->m_font_style_list, "Regular" ); | 343 | i = findItemCB ( d->m_font_style_list, "Regular" ); |
345 | if (( i < 0 ) && ( d->m_font_style_list->count() > 0 )) | 344 | if (( i < 0 ) && ( d->m_font_style_list->count() > 0 )) |
346 | i = 0; | 345 | i = 0; |
347 | 346 | ||
348 | if ( i >= 0 ) | 347 | if ( i >= 0 ) |
349 | { | 348 | { |
350 | d->m_font_style_list->setCurrentItem ( i ); | 349 | d->m_font_style_list->setCurrentItem ( i ); |
351 | fontStyleClicked ( i ); | 350 | fontStyleClicked ( i ); |
352 | } | 351 | } |
353 | 352 | ||
354 | d->m_font_size_list->clear(); | 353 | d->m_font_size_list->clear(); |
355 | QValueList<int> sl = fli->sizes(); | 354 | QValueList<int> sl = fli->sizes(); |
356 | 355 | ||
357 | for ( QValueList<int>::Iterator it = sl. begin(); it != sl. end(); ++it ) | 356 | for ( QValueList<int>::Iterator it = sl. begin(); it != sl. end(); ++it ) |
358 | d->m_font_size_list->insertItem ( QString::number ( *it )); | 357 | d->m_font_size_list->insertItem ( QString::number ( *it )); |
359 | 358 | ||
360 | i = findItemCB ( d->m_font_size_list, oldsize ); | 359 | i = findItemCB ( d->m_font_size_list, oldsize ); |
361 | if ( i < 0 ) | 360 | if ( i < 0 ) |
362 | i = findItemCB ( d->m_font_size_list, "10" ); | 361 | i = findItemCB ( d->m_font_size_list, "10" ); |
363 | if (( i < 0 ) && ( d->m_font_size_list->count() > 0 )) | 362 | if (( i < 0 ) && ( d->m_font_size_list->count() > 0 )) |
364 | i = 0; | 363 | i = 0; |
365 | 364 | ||
366 | if ( i >= 0 ) | 365 | if ( i >= 0 ) |
367 | { | 366 | { |
368 | d->m_font_size_list->setCurrentItem ( i ); | 367 | d->m_font_size_list->setCurrentItem ( i ); |
369 | fontSizeClicked ( i ); | 368 | fontSizeClicked ( i ); |
370 | } | 369 | } |
371 | changeFont(); | 370 | changeFont(); |
372 | } | 371 | } |
373 | 372 | ||
374 | void OFontSelector::fontStyleClicked ( int /*index*/ ) | 373 | void OFontSelector::fontStyleClicked ( int /*index*/ ) |
375 | { | 374 | { |
376 | changeFont(); | 375 | changeFont(); |
377 | } | 376 | } |
378 | 377 | ||
379 | void OFontSelector::fontSizeClicked ( int /*index*/ ) | 378 | void OFontSelector::fontSizeClicked ( int /*index*/ ) |
380 | { | 379 | { |
381 | changeFont(); | 380 | changeFont(); |
382 | } | 381 | } |
383 | 382 | ||
384 | void OFontSelector::changeFont() | 383 | void OFontSelector::changeFont() |
385 | { | 384 | { |
386 | QFont f = selectedFont(); | 385 | QFont f = selectedFont(); |
387 | 386 | ||
388 | if ( d->m_preview ) | 387 | if ( d->m_preview ) |
389 | d->m_preview->setFont ( f ); | 388 | d->m_preview->setFont ( f ); |
390 | 389 | ||
391 | emit fontSelected ( f ); | 390 | emit fontSelected ( f ); |
392 | } | 391 | } |
393 | 392 | ||
394 | /** | 393 | /** |
395 | * Return the selected font | 394 | * Return the selected font |
396 | */ | 395 | */ |
397 | QFont OFontSelector::selectedFont() | 396 | QFont OFontSelector::selectedFont() |
398 | { | 397 | { |
399 | int ffa = d->m_font_family_list->currentItem(); | 398 | int ffa = d->m_font_family_list->currentItem(); |
400 | int fst = d->m_font_style_list->currentItem(); | 399 | int fst = d->m_font_style_list->currentItem(); |
401 | int fsi = d->m_font_size_list->currentItem(); | 400 | int fsi = d->m_font_size_list->currentItem(); |
402 | 401 | ||
403 | FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa ); | 402 | FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa ); |
404 | 403 | ||
405 | if ( fli ) | 404 | if ( fli ) |
406 | { | 405 | { |
407 | return d->m_fdb. font ( fli->family(), \ | 406 | return d->m_fdb. font ( fli->family(), \ |
408 | fst >= 0 ? fli->styles() [fst] : QString::null, \ | 407 | fst >= 0 ? fli->styles() [fst] : QString::null, \ |
409 | fsi >= 0 ? fli->sizes() [fsi] : 10, \ | 408 | fsi >= 0 ? fli->sizes() [fsi] : 10, \ |
410 | d->m_fdb. charSets ( fli->family()) [0] ); | 409 | d->m_fdb. charSets ( fli->family()) [0] ); |
411 | } | 410 | } |
412 | else | 411 | else |
413 | return QFont(); | 412 | return QFont(); |
414 | } | 413 | } |
415 | 414 | ||
416 | void OFontSelector::resizeEvent ( QResizeEvent *re ) | 415 | void OFontSelector::resizeEvent ( QResizeEvent *re ) |
417 | { | 416 | { |
418 | if ( d->m_preview ) | 417 | if ( d->m_preview ) |
419 | { | 418 | { |
420 | d->m_preview->setMinimumHeight ( 1 ); | 419 | d->m_preview->setMinimumHeight ( 1 ); |
421 | d->m_preview->setMaximumHeight ( 32767 ); | 420 | d->m_preview->setMaximumHeight ( 32767 ); |
422 | } | 421 | } |
423 | 422 | ||
424 | QWidget::resizeEvent ( re ); | 423 | QWidget::resizeEvent ( re ); |
425 | 424 | ||
426 | if ( d->m_preview ) | 425 | if ( d->m_preview ) |
427 | d->m_preview->setFixedHeight ( d->m_preview->height()); | 426 | d->m_preview->setFixedHeight ( d->m_preview->height()); |
428 | 427 | ||
429 | } | 428 | } |
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp index 38f3fe2..84617f8 100644 --- a/libopie2/opieui/olistview.cpp +++ b/libopie2/opieui/olistview.cpp | |||
@@ -1,613 +1,610 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | .=l. | 4 | .=l. |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | /* QT */ | 30 | /* QT */ |
31 | 31 | ||
32 | #include <qcolor.h> | ||
33 | #include <qheader.h> | ||
34 | #include <qpainter.h> | ||
35 | #include <qpixmap.h> | 32 | #include <qpixmap.h> |
36 | 33 | ||
37 | /* OPIE */ | 34 | /* OPIE */ |
38 | 35 | ||
39 | #include <opie2/odebug.h> | 36 | #include <opie2/odebug.h> |
40 | #include <opie2/olistview.h> | 37 | #include <opie2/olistview.h> |
41 | 38 | ||
42 | /*====================================================================================== | 39 | /*====================================================================================== |
43 | * OListView | 40 | * OListView |
44 | *======================================================================================*/ | 41 | *======================================================================================*/ |
45 | 42 | ||
46 | OListView::OListView( QWidget *parent, const char *name ) | 43 | OListView::OListView( QWidget *parent, const char *name ) |
47 | :QListView( parent, name ) | 44 | :QListView( parent, name ) |
48 | { | 45 | { |
49 | //FIXME: get from global settings and calculate ==> see oglobalsettings.* | 46 | //FIXME: get from global settings and calculate ==> see oglobalsettings.* |
50 | 47 | ||
51 | m_alternateBackground = QColor( 238, 246, 255 ); | 48 | m_alternateBackground = QColor( 238, 246, 255 ); |
52 | m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); | 49 | m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); |
53 | m_fullWidth = true; | 50 | m_fullWidth = true; |
54 | connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*))); | 51 | connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*))); |
55 | } | 52 | } |
56 | 53 | ||
57 | OListView::~OListView() | 54 | OListView::~OListView() |
58 | { | 55 | { |
59 | } | 56 | } |
60 | 57 | ||
61 | void OListView::setFullWidth( bool fullWidth ) | 58 | void OListView::setFullWidth( bool fullWidth ) |
62 | { | 59 | { |
63 | m_fullWidth = m_fullWidth; | 60 | m_fullWidth = m_fullWidth; |
64 | #if QT_VERSION > 290 | 61 | #if QT_VERSION > 290 |
65 | header()->setStretchEnabled( fullWidth, columns()-1 ); | 62 | header()->setStretchEnabled( fullWidth, columns()-1 ); |
66 | #endif | 63 | #endif |
67 | } | 64 | } |
68 | 65 | ||
69 | bool OListView::fullWidth() const | 66 | bool OListView::fullWidth() const |
70 | { | 67 | { |
71 | return m_fullWidth; | 68 | return m_fullWidth; |
72 | } | 69 | } |
73 | 70 | ||
74 | int OListView::addColumn( const QString& label, int width ) | 71 | int OListView::addColumn( const QString& label, int width ) |
75 | { | 72 | { |
76 | int result = QListView::addColumn( label, width ); | 73 | int result = QListView::addColumn( label, width ); |
77 | #if QT_VERSION > 290 | 74 | #if QT_VERSION > 290 |
78 | if (m_fullWidth) { | 75 | if (m_fullWidth) { |
79 | header()->setStretchEnabled( false, columns()-2 ); | 76 | header()->setStretchEnabled( false, columns()-2 ); |
80 | header()->setStretchEnabled( true, columns()-1 ); | 77 | header()->setStretchEnabled( true, columns()-1 ); |
81 | } | 78 | } |
82 | #endif | 79 | #endif |
83 | return result; | 80 | return result; |
84 | } | 81 | } |
85 | 82 | ||
86 | int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) | 83 | int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) |
87 | { | 84 | { |
88 | int result = QListView::addColumn( iconset, label, width ); | 85 | int result = QListView::addColumn( iconset, label, width ); |
89 | #if QT_VERSION > 290 | 86 | #if QT_VERSION > 290 |
90 | if (m_fullWidth) { | 87 | if (m_fullWidth) { |
91 | header()->setStretchEnabled( false, columns()-2 ); | 88 | header()->setStretchEnabled( false, columns()-2 ); |
92 | header()->setStretchEnabled( true, columns()-1 ); | 89 | header()->setStretchEnabled( true, columns()-1 ); |
93 | } | 90 | } |
94 | #endif | 91 | #endif |
95 | return result; | 92 | return result; |
96 | } | 93 | } |
97 | 94 | ||
98 | void OListView::removeColumn( int index ) | 95 | void OListView::removeColumn( int index ) |
99 | { | 96 | { |
100 | QListView::removeColumn(index); | 97 | QListView::removeColumn(index); |
101 | #if QT_VERSION > 290 | 98 | #if QT_VERSION > 290 |
102 | if ( m_fullWidth && index == columns() ) | 99 | if ( m_fullWidth && index == columns() ) |
103 | { | 100 | { |
104 | header()->setStretchEnabled( true, columns()-1 ); | 101 | header()->setStretchEnabled( true, columns()-1 ); |
105 | } | 102 | } |
106 | #endif | 103 | #endif |
107 | } | 104 | } |
108 | 105 | ||
109 | const QColor& OListView::alternateBackground() const | 106 | const QColor& OListView::alternateBackground() const |
110 | { | 107 | { |
111 | return m_alternateBackground; | 108 | return m_alternateBackground; |
112 | } | 109 | } |
113 | 110 | ||
114 | void OListView::setAlternateBackground( const QColor &c ) | 111 | void OListView::setAlternateBackground( const QColor &c ) |
115 | { | 112 | { |
116 | m_alternateBackground = c; | 113 | m_alternateBackground = c; |
117 | repaint(); | 114 | repaint(); |
118 | } | 115 | } |
119 | 116 | ||
120 | const QPen& OListView::columnSeparator() const | 117 | const QPen& OListView::columnSeparator() const |
121 | { | 118 | { |
122 | return m_columnSeparator; | 119 | return m_columnSeparator; |
123 | } | 120 | } |
124 | 121 | ||
125 | void OListView::setColumnSeparator( const QPen& p ) | 122 | void OListView::setColumnSeparator( const QPen& p ) |
126 | { | 123 | { |
127 | m_columnSeparator = p; | 124 | m_columnSeparator = p; |
128 | repaint(); | 125 | repaint(); |
129 | } | 126 | } |
130 | 127 | ||
131 | void OListView::expand(QListViewItem *item) | 128 | void OListView::expand(QListViewItem *item) |
132 | { | 129 | { |
133 | ((OListViewItem*)item)->expand(); | 130 | ((OListViewItem*)item)->expand(); |
134 | } | 131 | } |
135 | 132 | ||
136 | OListViewItem* OListView::childFactory() | 133 | OListViewItem* OListView::childFactory() |
137 | { | 134 | { |
138 | return new OListViewItem( this ); | 135 | return new OListViewItem( this ); |
139 | } | 136 | } |
140 | 137 | ||
141 | #ifndef QT_NO_DATASTREAM | 138 | #ifndef QT_NO_DATASTREAM |
142 | void OListView::serializeTo( QDataStream& s ) const | 139 | void OListView::serializeTo( QDataStream& s ) const |
143 | { | 140 | { |
144 | #warning Caution... the binary format is still under construction... | 141 | #warning Caution... the binary format is still under construction... |
145 | odebug << "storing OListView..." << oendl; | 142 | odebug << "storing OListView..." << oendl; |
146 | 143 | ||
147 | // store number of columns and the labels | 144 | // store number of columns and the labels |
148 | s << columns(); | 145 | s << columns(); |
149 | for ( int i = 0; i < columns(); ++i ) | 146 | for ( int i = 0; i < columns(); ++i ) |
150 | s << columnText( i ); | 147 | s << columnText( i ); |
151 | 148 | ||
152 | // calculate the number of top-level items to serialize | 149 | // calculate the number of top-level items to serialize |
153 | int items = 0; | 150 | int items = 0; |
154 | QListViewItem* item = firstChild(); | 151 | QListViewItem* item = firstChild(); |
155 | while ( item ) | 152 | while ( item ) |
156 | { | 153 | { |
157 | item = item->nextSibling(); | 154 | item = item->nextSibling(); |
158 | items++; | 155 | items++; |
159 | } | 156 | } |
160 | 157 | ||
161 | // store number of items and the items itself | 158 | // store number of items and the items itself |
162 | s << items; | 159 | s << items; |
163 | item = firstChild(); | 160 | item = firstChild(); |
164 | for ( int i = 0; i < items; ++i ) | 161 | for ( int i = 0; i < items; ++i ) |
165 | { | 162 | { |
166 | s << *static_cast<OListViewItem*>( item ); | 163 | s << *static_cast<OListViewItem*>( item ); |
167 | item = item->nextSibling(); | 164 | item = item->nextSibling(); |
168 | } | 165 | } |
169 | 166 | ||
170 | odebug << "OListview stored." << oendl; | 167 | odebug << "OListview stored." << oendl; |
171 | } | 168 | } |
172 | 169 | ||
173 | void OListView::serializeFrom( QDataStream& s ) | 170 | void OListView::serializeFrom( QDataStream& s ) |
174 | { | 171 | { |
175 | #warning Caution... the binary format is still under construction... | 172 | #warning Caution... the binary format is still under construction... |
176 | odebug << "loading OListView..." << oendl; | 173 | odebug << "loading OListView..." << oendl; |
177 | 174 | ||
178 | int cols; | 175 | int cols; |
179 | s >> cols; | 176 | s >> cols; |
180 | qDebug( "read number of columns = %d", cols ); | 177 | qDebug( "read number of columns = %d", cols ); |
181 | 178 | ||
182 | while ( columns() < cols ) addColumn( QString::null ); | 179 | while ( columns() < cols ) addColumn( QString::null ); |
183 | 180 | ||
184 | for ( int i = 0; i < cols; ++i ) | 181 | for ( int i = 0; i < cols; ++i ) |
185 | { | 182 | { |
186 | QString coltext; | 183 | QString coltext; |
187 | s >> coltext; | 184 | s >> coltext; |
188 | qDebug( "read text '%s' for column %d", (const char*) coltext, i ); | 185 | qDebug( "read text '%s' for column %d", (const char*) coltext, i ); |
189 | setColumnText( i, coltext ); | 186 | setColumnText( i, coltext ); |
190 | } | 187 | } |
191 | 188 | ||
192 | int items; | 189 | int items; |
193 | s >> items; | 190 | s >> items; |
194 | qDebug( "read number of items = %d", items ); | 191 | qDebug( "read number of items = %d", items ); |
195 | 192 | ||
196 | for ( int i = 0; i < items; ++i ) | 193 | for ( int i = 0; i < items; ++i ) |
197 | { | 194 | { |
198 | OListViewItem* item = childFactory(); | 195 | OListViewItem* item = childFactory(); |
199 | s >> *item; | 196 | s >> *item; |
200 | } | 197 | } |
201 | 198 | ||
202 | odebug << "OListView loaded." << oendl; | 199 | odebug << "OListView loaded." << oendl; |
203 | 200 | ||
204 | } | 201 | } |
205 | 202 | ||
206 | QDataStream& operator<<( QDataStream& s, const OListView& lv ) | 203 | QDataStream& operator<<( QDataStream& s, const OListView& lv ) |
207 | { | 204 | { |
208 | lv.serializeTo( s ); | 205 | lv.serializeTo( s ); |
209 | } | 206 | } |
210 | 207 | ||
211 | QDataStream& operator>>( QDataStream& s, OListView& lv ) | 208 | QDataStream& operator>>( QDataStream& s, OListView& lv ) |
212 | { | 209 | { |
213 | lv.serializeFrom( s ); | 210 | lv.serializeFrom( s ); |
214 | } | 211 | } |
215 | #endif // QT_NO_DATASTREAM | 212 | #endif // QT_NO_DATASTREAM |
216 | 213 | ||
217 | /*====================================================================================== | 214 | /*====================================================================================== |
218 | * OListViewItem | 215 | * OListViewItem |
219 | *======================================================================================*/ | 216 | *======================================================================================*/ |
220 | 217 | ||
221 | OListViewItem::OListViewItem(QListView *parent) | 218 | OListViewItem::OListViewItem(QListView *parent) |
222 | : QListViewItem(parent) | 219 | : QListViewItem(parent) |
223 | { | 220 | { |
224 | init(); | 221 | init(); |
225 | } | 222 | } |
226 | 223 | ||
227 | 224 | ||
228 | OListViewItem::OListViewItem(QListViewItem *parent) | 225 | OListViewItem::OListViewItem(QListViewItem *parent) |
229 | : QListViewItem(parent) | 226 | : QListViewItem(parent) |
230 | { | 227 | { |
231 | init(); | 228 | init(); |
232 | } | 229 | } |
233 | 230 | ||
234 | 231 | ||
235 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) | 232 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) |
236 | : QListViewItem(parent, after) | 233 | : QListViewItem(parent, after) |
237 | { | 234 | { |
238 | init(); | 235 | init(); |
239 | } | 236 | } |
240 | 237 | ||
241 | 238 | ||
242 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) | 239 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) |
243 | : QListViewItem(parent, after) | 240 | : QListViewItem(parent, after) |
244 | { | 241 | { |
245 | init(); | 242 | init(); |
246 | } | 243 | } |
247 | 244 | ||
248 | 245 | ||
249 | OListViewItem::OListViewItem(QListView *parent, | 246 | OListViewItem::OListViewItem(QListView *parent, |
250 | QString label1, QString label2, QString label3, QString label4, | 247 | QString label1, QString label2, QString label3, QString label4, |
251 | QString label5, QString label6, QString label7, QString label8) | 248 | QString label5, QString label6, QString label7, QString label8) |
252 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 249 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
253 | { | 250 | { |
254 | init(); | 251 | init(); |
255 | } | 252 | } |
256 | 253 | ||
257 | 254 | ||
258 | OListViewItem::OListViewItem(QListViewItem *parent, | 255 | OListViewItem::OListViewItem(QListViewItem *parent, |
259 | QString label1, QString label2, QString label3, QString label4, | 256 | QString label1, QString label2, QString label3, QString label4, |
260 | QString label5, QString label6, QString label7, QString label8) | 257 | QString label5, QString label6, QString label7, QString label8) |
261 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 258 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
262 | { | 259 | { |
263 | init(); | 260 | init(); |
264 | } | 261 | } |
265 | 262 | ||
266 | 263 | ||
267 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, | 264 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, |
268 | QString label1, QString label2, QString label3, QString label4, | 265 | QString label1, QString label2, QString label3, QString label4, |
269 | QString label5, QString label6, QString label7, QString label8) | 266 | QString label5, QString label6, QString label7, QString label8) |
270 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 267 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
271 | { | 268 | { |
272 | init(); | 269 | init(); |
273 | } | 270 | } |
274 | 271 | ||
275 | 272 | ||
276 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, | 273 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, |
277 | QString label1, QString label2, QString label3, QString label4, | 274 | QString label1, QString label2, QString label3, QString label4, |
278 | QString label5, QString label6, QString label7, QString label8) | 275 | QString label5, QString label6, QString label7, QString label8) |
279 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 276 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
280 | { | 277 | { |
281 | init(); | 278 | init(); |
282 | } | 279 | } |
283 | 280 | ||
284 | 281 | ||
285 | OListViewItem::~OListViewItem() | 282 | OListViewItem::~OListViewItem() |
286 | { | 283 | { |
287 | } | 284 | } |
288 | 285 | ||
289 | 286 | ||
290 | void OListViewItem::init() | 287 | void OListViewItem::init() |
291 | { | 288 | { |
292 | m_known = false; | 289 | m_known = false; |
293 | } | 290 | } |
294 | 291 | ||
295 | 292 | ||
296 | const QColor &OListViewItem::backgroundColor() | 293 | const QColor &OListViewItem::backgroundColor() |
297 | { | 294 | { |
298 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : | 295 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : |
299 | listView()->viewport()->colorGroup().base(); | 296 | listView()->viewport()->colorGroup().base(); |
300 | } | 297 | } |
301 | 298 | ||
302 | 299 | ||
303 | bool OListViewItem::isAlternate() | 300 | bool OListViewItem::isAlternate() |
304 | { | 301 | { |
305 | OListView *lv = static_cast<OListView*>( listView() ); | 302 | OListView *lv = static_cast<OListView*>( listView() ); |
306 | 303 | ||
307 | // check if the item above is an OListViewItem | 304 | // check if the item above is an OListViewItem |
308 | OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); | 305 | OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); |
309 | /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ | 306 | /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ |
310 | 307 | ||
311 | // check if we have a valid alternate background color | 308 | // check if we have a valid alternate background color |
312 | if (!(lv && lv->alternateBackground().isValid())) return false; | 309 | if (!(lv && lv->alternateBackground().isValid())) return false; |
313 | 310 | ||
314 | m_known = above ? above->m_known : true; | 311 | m_known = above ? above->m_known : true; |
315 | if (m_known) | 312 | if (m_known) |
316 | { | 313 | { |
317 | m_odd = above ? !above->m_odd : false; | 314 | m_odd = above ? !above->m_odd : false; |
318 | } | 315 | } |
319 | else | 316 | else |
320 | { | 317 | { |
321 | OListViewItem *item; | 318 | OListViewItem *item; |
322 | bool previous = true; | 319 | bool previous = true; |
323 | if (parent()) | 320 | if (parent()) |
324 | { | 321 | { |
325 | item = static_cast<OListViewItem *>(parent()); | 322 | item = static_cast<OListViewItem *>(parent()); |
326 | if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; | 323 | if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; |
327 | item = static_cast<OListViewItem *>(parent()->firstChild()); | 324 | item = static_cast<OListViewItem *>(parent()->firstChild()); |
328 | /* if ( !item.inherits( "OListViewItem" ) item = 0; */ | 325 | /* if ( !item.inherits( "OListViewItem" ) item = 0; */ |
329 | } | 326 | } |
330 | else | 327 | else |
331 | { | 328 | { |
332 | item = static_cast<OListViewItem *>(lv->firstChild()); | 329 | item = static_cast<OListViewItem *>(lv->firstChild()); |
333 | } | 330 | } |
334 | 331 | ||
335 | while(item) | 332 | while(item) |
336 | { | 333 | { |
337 | item->m_odd = previous = !previous; | 334 | item->m_odd = previous = !previous; |
338 | item->m_known = true; | 335 | item->m_known = true; |
339 | item = static_cast<OListViewItem *>(item->nextSibling()); | 336 | item = static_cast<OListViewItem *>(item->nextSibling()); |
340 | /* if (!item.inherits( "OListViewItem" ) ) break; */ | 337 | /* if (!item.inherits( "OListViewItem" ) ) break; */ |
341 | } | 338 | } |
342 | } | 339 | } |
343 | return m_odd; | 340 | return m_odd; |
344 | } | 341 | } |
345 | 342 | ||
346 | 343 | ||
347 | void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) | 344 | void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) |
348 | { | 345 | { |
349 | QColorGroup _cg = cg; | 346 | QColorGroup _cg = cg; |
350 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); | 347 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); |
351 | if (pm && !pm->isNull()) | 348 | if (pm && !pm->isNull()) |
352 | { | 349 | { |
353 | _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); | 350 | _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); |
354 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); | 351 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); |
355 | } | 352 | } |
356 | else if ( isAlternate() ) | 353 | else if ( isAlternate() ) |
357 | { | 354 | { |
358 | _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); | 355 | _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); |
359 | } | 356 | } |
360 | QListViewItem::paintCell( p, _cg, column, width, alignment ); | 357 | QListViewItem::paintCell( p, _cg, column, width, alignment ); |
361 | 358 | ||
362 | //FIXME: Use styling here! | 359 | //FIXME: Use styling here! |
363 | 360 | ||
364 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); | 361 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); |
365 | p->setPen( pen ); | 362 | p->setPen( pen ); |
366 | p->drawLine( width-1, 0, width-1, height() ); | 363 | p->drawLine( width-1, 0, width-1, height() ); |
367 | } | 364 | } |
368 | 365 | ||
369 | 366 | ||
370 | OListViewItem* OListViewItem::childFactory() | 367 | OListViewItem* OListViewItem::childFactory() |
371 | { | 368 | { |
372 | return new OListViewItem( this ); | 369 | return new OListViewItem( this ); |
373 | } | 370 | } |
374 | 371 | ||
375 | 372 | ||
376 | #ifndef QT_NO_DATASTREAM | 373 | #ifndef QT_NO_DATASTREAM |
377 | void OListViewItem::serializeTo( QDataStream& s ) const | 374 | void OListViewItem::serializeTo( QDataStream& s ) const |
378 | { | 375 | { |
379 | #warning Caution... the binary format is still under construction... | 376 | #warning Caution... the binary format is still under construction... |
380 | odebug << "storing OListViewItem..." << oendl; | 377 | odebug << "storing OListViewItem..." << oendl; |
381 | 378 | ||
382 | // store item text | 379 | // store item text |
383 | for ( int i = 0; i < listView()->columns(); ++i ) | 380 | for ( int i = 0; i < listView()->columns(); ++i ) |
384 | { | 381 | { |
385 | s << text( i ); | 382 | s << text( i ); |
386 | } | 383 | } |
387 | 384 | ||
388 | // calculate the number of children to serialize | 385 | // calculate the number of children to serialize |
389 | int items = 0; | 386 | int items = 0; |
390 | QListViewItem* item = firstChild(); | 387 | QListViewItem* item = firstChild(); |
391 | while ( item ) | 388 | while ( item ) |
392 | { | 389 | { |
393 | item = item->nextSibling(); | 390 | item = item->nextSibling(); |
394 | items++; | 391 | items++; |
395 | } | 392 | } |
396 | 393 | ||
397 | // store number of items and the items itself | 394 | // store number of items and the items itself |
398 | s << items; | 395 | s << items; |
399 | item = firstChild(); | 396 | item = firstChild(); |
400 | for ( int i = 0; i < items; ++i ) | 397 | for ( int i = 0; i < items; ++i ) |
401 | { | 398 | { |
402 | s << *static_cast<OListViewItem*>( item ); | 399 | s << *static_cast<OListViewItem*>( item ); |
403 | item = item->nextSibling(); | 400 | item = item->nextSibling(); |
404 | } | 401 | } |
405 | 402 | ||
406 | odebug << "OListviewItem stored." << oendl; | 403 | odebug << "OListviewItem stored." << oendl; |
407 | } | 404 | } |
408 | 405 | ||
409 | 406 | ||
410 | void OListViewItem::serializeFrom( QDataStream& s ) | 407 | void OListViewItem::serializeFrom( QDataStream& s ) |
411 | { | 408 | { |
412 | #warning Caution... the binary format is still under construction... | 409 | #warning Caution... the binary format is still under construction... |
413 | odebug << "loading OListViewItem..." << oendl; | 410 | odebug << "loading OListViewItem..." << oendl; |
414 | 411 | ||
415 | for ( int i = 0; i < listView()->columns(); ++i ) | 412 | for ( int i = 0; i < listView()->columns(); ++i ) |
416 | { | 413 | { |
417 | QString coltext; | 414 | QString coltext; |
418 | s >> coltext; | 415 | s >> coltext; |
419 | qDebug( "read text '%s' for column %d", (const char*) coltext, i ); | 416 | qDebug( "read text '%s' for column %d", (const char*) coltext, i ); |
420 | setText( i, coltext ); | 417 | setText( i, coltext ); |
421 | } | 418 | } |
422 | 419 | ||
423 | int items; | 420 | int items; |
424 | s >> items; | 421 | s >> items; |
425 | qDebug( "read number of items = %d", items ); | 422 | qDebug( "read number of items = %d", items ); |
426 | 423 | ||
427 | for ( int i = 0; i < items; ++i ) | 424 | for ( int i = 0; i < items; ++i ) |
428 | { | 425 | { |
429 | OListViewItem* item = childFactory(); | 426 | OListViewItem* item = childFactory(); |
430 | s >> (*item); | 427 | s >> (*item); |
431 | } | 428 | } |
432 | 429 | ||
433 | odebug << "OListViewItem loaded." << oendl; | 430 | odebug << "OListViewItem loaded." << oendl; |
434 | } | 431 | } |
435 | 432 | ||
436 | 433 | ||
437 | QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) | 434 | QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) |
438 | { | 435 | { |
439 | lvi.serializeTo( s ); | 436 | lvi.serializeTo( s ); |
440 | } | 437 | } |
441 | 438 | ||
442 | 439 | ||
443 | QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) | 440 | QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) |
444 | { | 441 | { |
445 | lvi.serializeFrom( s ); | 442 | lvi.serializeFrom( s ); |
446 | } | 443 | } |
447 | #endif // QT_NO_DATASTREAM | 444 | #endif // QT_NO_DATASTREAM |
448 | 445 | ||
449 | 446 | ||
450 | /*====================================================================================== | 447 | /*====================================================================================== |
451 | * ONamedListView | 448 | * ONamedListView |
452 | *======================================================================================*/ | 449 | *======================================================================================*/ |
453 | 450 | ||
454 | ONamedListView::ONamedListView( QWidget *parent, const char *name ) | 451 | ONamedListView::ONamedListView( QWidget *parent, const char *name ) |
455 | :OListView( parent, name ) | 452 | :OListView( parent, name ) |
456 | { | 453 | { |
457 | } | 454 | } |
458 | 455 | ||
459 | 456 | ||
460 | ONamedListView::~ONamedListView() | 457 | ONamedListView::~ONamedListView() |
461 | { | 458 | { |
462 | } | 459 | } |
463 | 460 | ||
464 | 461 | ||
465 | void ONamedListView::addColumns( const QStringList& columns ) | 462 | void ONamedListView::addColumns( const QStringList& columns ) |
466 | { | 463 | { |
467 | for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) | 464 | for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) |
468 | { | 465 | { |
469 | qDebug( "adding column %s", (const char*) *it ); | 466 | qDebug( "adding column %s", (const char*) *it ); |
470 | addColumn( *it ); | 467 | addColumn( *it ); |
471 | } | 468 | } |
472 | } | 469 | } |
473 | 470 | ||
474 | 471 | ||
475 | int ONamedListView::findColumn( const QString& text ) const | 472 | int ONamedListView::findColumn( const QString& text ) const |
476 | { | 473 | { |
477 | //FIXME: If used excessively, this will slow down performance of updates | 474 | //FIXME: If used excessively, this will slow down performance of updates |
478 | //FIXME: because of the linear search over all column texts. | 475 | //FIXME: because of the linear search over all column texts. |
479 | //FIXME: I will optimize later by using a hash map. | 476 | //FIXME: I will optimize later by using a hash map. |
480 | for ( int i = 0; i < columns(); ++i ) | 477 | for ( int i = 0; i < columns(); ++i ) |
481 | if ( columnText( i ) == text ) | 478 | if ( columnText( i ) == text ) |
482 | return i; | 479 | return i; |
483 | return -1; | 480 | return -1; |
484 | } | 481 | } |
485 | 482 | ||
486 | 483 | ||
487 | ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const | 484 | ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const |
488 | { | 485 | { |
489 | return find( (ONamedListViewItem*) firstChild(), column, text, recurse ); | 486 | return find( (ONamedListViewItem*) firstChild(), column, text, recurse ); |
490 | } | 487 | } |
491 | 488 | ||
492 | 489 | ||
493 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const | 490 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const |
494 | { | 491 | { |
495 | ONamedListViewItem* result; | 492 | ONamedListViewItem* result; |
496 | while ( item && item->text( column ) != text ) | 493 | while ( item && item->text( column ) != text ) |
497 | { | 494 | { |
498 | qDebug( "checked %s", (const char*) item->text( column ) ); | 495 | qDebug( "checked %s", (const char*) item->text( column ) ); |
499 | 496 | ||
500 | if ( recurse < 0 || recurse > 0 ) | 497 | if ( recurse < 0 || recurse > 0 ) |
501 | { | 498 | { |
502 | qDebug( "recursion is %d - recursing into...", recurse ); | 499 | qDebug( "recursion is %d - recursing into...", recurse ); |
503 | result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 ); | 500 | result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 ); |
504 | if ( result ) return result; | 501 | if ( result ) return result; |
505 | } | 502 | } |
506 | 503 | ||
507 | 504 | ||
508 | item = (ONamedListViewItem*) item->itemBelow(); | 505 | item = (ONamedListViewItem*) item->itemBelow(); |
509 | } | 506 | } |
510 | if ( item && item->text( column ) == text ) | 507 | if ( item && item->text( column ) == text ) |
511 | return item; | 508 | return item; |
512 | else | 509 | else |
513 | return 0; | 510 | return 0; |
514 | } | 511 | } |
515 | 512 | ||
516 | 513 | ||
517 | ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const | 514 | ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const |
518 | { | 515 | { |
519 | int col = findColumn( column ); | 516 | int col = findColumn( column ); |
520 | if ( col != -1 ) | 517 | if ( col != -1 ) |
521 | return find( (ONamedListViewItem*) firstChild(), col, text, recurse ); | 518 | return find( (ONamedListViewItem*) firstChild(), col, text, recurse ); |
522 | else | 519 | else |
523 | return 0; | 520 | return 0; |
524 | } | 521 | } |
525 | 522 | ||
526 | 523 | ||
527 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const | 524 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const |
528 | { | 525 | { |
529 | int col = findColumn( column ); | 526 | int col = findColumn( column ); |
530 | if ( col != -1 ) | 527 | if ( col != -1 ) |
531 | return find( item, col, text, recurse ); | 528 | return find( item, col, text, recurse ); |
532 | else | 529 | else |
533 | return 0; | 530 | return 0; |
534 | } | 531 | } |
535 | 532 | ||
536 | 533 | ||
537 | /*====================================================================================== | 534 | /*====================================================================================== |
538 | * ONamedListViewItem | 535 | * ONamedListViewItem |
539 | *======================================================================================*/ | 536 | *======================================================================================*/ |
540 | 537 | ||
541 | ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) | 538 | ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) |
542 | :OListViewItem( parent ) | 539 | :OListViewItem( parent ) |
543 | { | 540 | { |
544 | setText( texts ); | 541 | setText( texts ); |
545 | } | 542 | } |
546 | 543 | ||
547 | 544 | ||
548 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) | 545 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) |
549 | :OListViewItem( parent ) | 546 | :OListViewItem( parent ) |
550 | { | 547 | { |
551 | setText( texts ); | 548 | setText( texts ); |
552 | } | 549 | } |
553 | 550 | ||
554 | 551 | ||
555 | ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) | 552 | ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) |
556 | :OListViewItem( parent, after ) | 553 | :OListViewItem( parent, after ) |
557 | { | 554 | { |
558 | setText( texts ); | 555 | setText( texts ); |
559 | } | 556 | } |
560 | 557 | ||
561 | 558 | ||
562 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) | 559 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) |
563 | :OListViewItem( parent, after ) | 560 | :OListViewItem( parent, after ) |
564 | { | 561 | { |
565 | setText( texts ); | 562 | setText( texts ); |
566 | } | 563 | } |
567 | 564 | ||
568 | 565 | ||
569 | ONamedListViewItem::~ONamedListViewItem() | 566 | ONamedListViewItem::~ONamedListViewItem() |
570 | { | 567 | { |
571 | } | 568 | } |
572 | 569 | ||
573 | 570 | ||
574 | void ONamedListViewItem::setText( const QStringList& texts ) | 571 | void ONamedListViewItem::setText( const QStringList& texts ) |
575 | { | 572 | { |
576 | int col = 0; | 573 | int col = 0; |
577 | for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) | 574 | for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) |
578 | { | 575 | { |
579 | qDebug( "setting column %d = text %s", col, (const char*) *it ); | 576 | qDebug( "setting column %d = text %s", col, (const char*) *it ); |
580 | OListViewItem::setText( col++, *it ); | 577 | OListViewItem::setText( col++, *it ); |
581 | } | 578 | } |
582 | 579 | ||
583 | } | 580 | } |
584 | 581 | ||
585 | 582 | ||
586 | void ONamedListViewItem::setText( const QString& column, const QString& text ) | 583 | void ONamedListViewItem::setText( const QString& column, const QString& text ) |
587 | { | 584 | { |
588 | //FIXME: If used excessively, this will slow down performance of updates | 585 | //FIXME: If used excessively, this will slow down performance of updates |
589 | //FIXME: because of the linear search over all column texts. | 586 | //FIXME: because of the linear search over all column texts. |
590 | //FIXME: I will optimize later by using a hash map. | 587 | //FIXME: I will optimize later by using a hash map. |
591 | int col = ( (ONamedListView*) listView() )->findColumn( column ); | 588 | int col = ( (ONamedListView*) listView() )->findColumn( column ); |
592 | if ( col != -1 ) | 589 | if ( col != -1 ) |
593 | OListViewItem::setText( col, text ); | 590 | OListViewItem::setText( col, text ); |
594 | else | 591 | else |
595 | qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); | 592 | qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); |
596 | } | 593 | } |
597 | 594 | ||
598 | 595 | ||
599 | ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const | 596 | ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const |
600 | { | 597 | { |
601 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse ); | 598 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse ); |
602 | } | 599 | } |
603 | 600 | ||
604 | 601 | ||
605 | ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const | 602 | ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const |
606 | { | 603 | { |
607 | int col = ( (ONamedListView*) listView() )->findColumn( column ); | 604 | int col = ( (ONamedListView*) listView() )->findColumn( column ); |
608 | if ( col != -1 ) | 605 | if ( col != -1 ) |
609 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse ); | 606 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse ); |
610 | else | 607 | else |
611 | return 0; | 608 | return 0; |
612 | } | 609 | } |
613 | 610 | ||
diff --git a/libopie2/opieui/opopupmenu.cpp b/libopie2/opieui/opopupmenu.cpp index ac73188..d5cc575 100644 --- a/libopie2/opieui/opopupmenu.cpp +++ b/libopie2/opieui/opopupmenu.cpp | |||
@@ -1,604 +1,597 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org> | 2 | Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org> |
3 | Copyright (C) 2002 Hamish Rodda <meddie@yoyo.its.monash.edu.au> | 3 | Copyright (C) 2002 Hamish Rodda <meddie@yoyo.its.monash.edu.au> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License version 2 as published by the Free Software Foundation. | 7 | License version 2 as published by the Free Software Foundation. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | /* QT */ | 20 | /* QT */ |
21 | 21 | ||
22 | #include <qapplication.h> | ||
23 | #include <qcursor.h> | ||
24 | #include <qpainter.h> | ||
25 | #include <qdrawutil.h> | 22 | #include <qdrawutil.h> |
26 | #include <qtimer.h> | 23 | #include <qtimer.h> |
27 | #include <qfont.h> | ||
28 | #include <qfontmetrics.h> | ||
29 | #include <qregexp.h> | ||
30 | #include <qstyle.h> | ||
31 | 24 | ||
32 | /* OPIE */ | 25 | /* OPIE */ |
33 | 26 | ||
34 | #include <opie2/opopupmenu.h> | 27 | #include <opie2/opopupmenu.h> |
35 | #include <opie2/oconfig.h> | 28 | #include <opie2/oconfig.h> |
36 | 29 | ||
37 | OPopupTitle::OPopupTitle(QWidget *parent, const char *name) | 30 | OPopupTitle::OPopupTitle(QWidget *parent, const char *name) |
38 | : QWidget(parent, name) | 31 | : QWidget(parent, name) |
39 | { | 32 | { |
40 | setMinimumSize(16, fontMetrics().height()+8); | 33 | setMinimumSize(16, fontMetrics().height()+8); |
41 | } | 34 | } |
42 | 35 | ||
43 | OPopupTitle::OPopupTitle(OPixmapEffect::GradientType /* gradient */, | 36 | OPopupTitle::OPopupTitle(OPixmapEffect::GradientType /* gradient */, |
44 | const QColor &/* color */, const QColor &/* textColor */, | 37 | const QColor &/* color */, const QColor &/* textColor */, |
45 | QWidget *parent, const char *name) | 38 | QWidget *parent, const char *name) |
46 | : QWidget(parent, name) | 39 | : QWidget(parent, name) |
47 | { | 40 | { |
48 | setMinimumSize(16, fontMetrics().height()+8); | 41 | setMinimumSize(16, fontMetrics().height()+8); |
49 | } | 42 | } |
50 | 43 | ||
51 | OPopupTitle::OPopupTitle(const OPixmap & /* background */, const QColor &/* color */, | 44 | OPopupTitle::OPopupTitle(const OPixmap & /* background */, const QColor &/* color */, |
52 | const QColor &/* textColor */, QWidget *parent, | 45 | const QColor &/* textColor */, QWidget *parent, |
53 | const char *name) | 46 | const char *name) |
54 | : QWidget(parent, name) | 47 | : QWidget(parent, name) |
55 | { | 48 | { |
56 | setMinimumSize(16, fontMetrics().height()+8); | 49 | setMinimumSize(16, fontMetrics().height()+8); |
57 | } | 50 | } |
58 | 51 | ||
59 | void OPopupTitle::setTitle(const QString &text, const QPixmap *icon) | 52 | void OPopupTitle::setTitle(const QString &text, const QPixmap *icon) |
60 | { | 53 | { |
61 | titleStr = text; | 54 | titleStr = text; |
62 | if (icon) | 55 | if (icon) |
63 | miniicon = *icon; | 56 | miniicon = *icon; |
64 | else | 57 | else |
65 | miniicon.resize(0, 0); | 58 | miniicon.resize(0, 0); |
66 | 59 | ||
67 | int w = miniicon.width()+fontMetrics().width(titleStr); | 60 | int w = miniicon.width()+fontMetrics().width(titleStr); |
68 | int h = QMAX( fontMetrics().height(), miniicon.height() ); | 61 | int h = QMAX( fontMetrics().height(), miniicon.height() ); |
69 | setMinimumSize( w+16, h+8 ); | 62 | setMinimumSize( w+16, h+8 ); |
70 | } | 63 | } |
71 | 64 | ||
72 | void OPopupTitle::setText( const QString &text ) | 65 | void OPopupTitle::setText( const QString &text ) |
73 | { | 66 | { |
74 | titleStr = text; | 67 | titleStr = text; |
75 | int w = miniicon.width()+fontMetrics().width(titleStr); | 68 | int w = miniicon.width()+fontMetrics().width(titleStr); |
76 | int h = QMAX( fontMetrics().height(), miniicon.height() ); | 69 | int h = QMAX( fontMetrics().height(), miniicon.height() ); |
77 | setMinimumSize( w+16, h+8 ); | 70 | setMinimumSize( w+16, h+8 ); |
78 | } | 71 | } |
79 | 72 | ||
80 | void OPopupTitle::setIcon( const QPixmap &pix ) | 73 | void OPopupTitle::setIcon( const QPixmap &pix ) |
81 | { | 74 | { |
82 | miniicon = pix; | 75 | miniicon = pix; |
83 | int w = miniicon.width()+fontMetrics().width(titleStr); | 76 | int w = miniicon.width()+fontMetrics().width(titleStr); |
84 | int h = QMAX( fontMetrics().height(), miniicon.height() ); | 77 | int h = QMAX( fontMetrics().height(), miniicon.height() ); |
85 | setMinimumSize( w+16, h+8 ); | 78 | setMinimumSize( w+16, h+8 ); |
86 | } | 79 | } |
87 | 80 | ||
88 | void OPopupTitle::paintEvent(QPaintEvent *) | 81 | void OPopupTitle::paintEvent(QPaintEvent *) |
89 | { | 82 | { |
90 | QRect r(rect()); | 83 | QRect r(rect()); |
91 | QPainter p(this); | 84 | QPainter p(this); |
92 | #if QT_VERSION > 290 | 85 | #if QT_VERSION > 290 |
93 | qApp->style().drawPrimitive(QStyle::PE_HeaderSection, &p, r, palette().active()); | 86 | qApp->style().drawPrimitive(QStyle::PE_HeaderSection, &p, r, palette().active()); |
94 | #else | 87 | #else |
95 | #warning OPopupMenu is not fully functional on Qt2 | 88 | #warning OPopupMenu is not fully functional on Qt2 |
96 | #endif | 89 | #endif |
97 | 90 | ||
98 | if (!miniicon.isNull()) | 91 | if (!miniicon.isNull()) |
99 | p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon); | 92 | p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon); |
100 | 93 | ||
101 | if (!titleStr.isNull()) | 94 | if (!titleStr.isNull()) |
102 | { | 95 | { |
103 | p.setPen(palette().active().text()); | 96 | p.setPen(palette().active().text()); |
104 | QFont f = p.font(); | 97 | QFont f = p.font(); |
105 | f.setBold(true); | 98 | f.setBold(true); |
106 | p.setFont(f); | 99 | p.setFont(f); |
107 | if(!miniicon.isNull()) | 100 | if(!miniicon.isNull()) |
108 | { | 101 | { |
109 | p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8), | 102 | p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8), |
110 | height(), AlignLeft | AlignVCenter | SingleLine, | 103 | height(), AlignLeft | AlignVCenter | SingleLine, |
111 | titleStr); | 104 | titleStr); |
112 | } | 105 | } |
113 | else | 106 | else |
114 | { | 107 | { |
115 | p.drawText(0, 0, width(), height(), | 108 | p.drawText(0, 0, width(), height(), |
116 | AlignCenter | SingleLine, titleStr); | 109 | AlignCenter | SingleLine, titleStr); |
117 | } | 110 | } |
118 | } | 111 | } |
119 | 112 | ||
120 | p.setPen(palette().active().highlight()); | 113 | p.setPen(palette().active().highlight()); |
121 | p.drawLine(0, 0, r.right(), 0); | 114 | p.drawLine(0, 0, r.right(), 0); |
122 | } | 115 | } |
123 | 116 | ||
124 | QSize OPopupTitle::sizeHint() const | 117 | QSize OPopupTitle::sizeHint() const |
125 | { | 118 | { |
126 | return(minimumSize()); | 119 | return(minimumSize()); |
127 | } | 120 | } |
128 | 121 | ||
129 | class OPopupMenu::OPopupMenuPrivate | 122 | class OPopupMenu::OPopupMenuPrivate |
130 | { | 123 | { |
131 | public: | 124 | public: |
132 | OPopupMenuPrivate () | 125 | OPopupMenuPrivate () |
133 | : noMatches(false) | 126 | : noMatches(false) |
134 | , shortcuts(false) | 127 | , shortcuts(false) |
135 | , autoExec(false) | 128 | , autoExec(false) |
136 | , lastHitIndex(-1) | 129 | , lastHitIndex(-1) |
137 | , m_ctxMenu(0) | 130 | , m_ctxMenu(0) |
138 | {} | 131 | {} |
139 | 132 | ||
140 | ~OPopupMenuPrivate () | 133 | ~OPopupMenuPrivate () |
141 | { | 134 | { |
142 | delete m_ctxMenu; | 135 | delete m_ctxMenu; |
143 | } | 136 | } |
144 | 137 | ||
145 | QString m_lastTitle; | 138 | QString m_lastTitle; |
146 | 139 | ||
147 | // variables for keyboard navigation | 140 | // variables for keyboard navigation |
148 | QTimer clearTimer; | 141 | QTimer clearTimer; |
149 | 142 | ||
150 | bool noMatches : 1; | 143 | bool noMatches : 1; |
151 | bool shortcuts : 1; | 144 | bool shortcuts : 1; |
152 | bool autoExec : 1; | 145 | bool autoExec : 1; |
153 | 146 | ||
154 | QString keySeq; | 147 | QString keySeq; |
155 | QString originalText; | 148 | QString originalText; |
156 | 149 | ||
157 | int lastHitIndex; | 150 | int lastHitIndex; |
158 | 151 | ||
159 | // support for RMB menus on menus | 152 | // support for RMB menus on menus |
160 | QPopupMenu* m_ctxMenu; | 153 | QPopupMenu* m_ctxMenu; |
161 | static bool s_continueCtxMenuShow; | 154 | static bool s_continueCtxMenuShow; |
162 | static int s_highlightedItem; | 155 | static int s_highlightedItem; |
163 | static OPopupMenu* s_contextedMenu; | 156 | static OPopupMenu* s_contextedMenu; |
164 | }; | 157 | }; |
165 | 158 | ||
166 | int OPopupMenu::OPopupMenuPrivate::s_highlightedItem(-1); | 159 | int OPopupMenu::OPopupMenuPrivate::s_highlightedItem(-1); |
167 | OPopupMenu* OPopupMenu::OPopupMenuPrivate::s_contextedMenu(0); | 160 | OPopupMenu* OPopupMenu::OPopupMenuPrivate::s_contextedMenu(0); |
168 | bool OPopupMenu::OPopupMenuPrivate::s_continueCtxMenuShow(true); | 161 | bool OPopupMenu::OPopupMenuPrivate::s_continueCtxMenuShow(true); |
169 | 162 | ||
170 | OPopupMenu::OPopupMenu(QWidget *parent, const char *name) | 163 | OPopupMenu::OPopupMenu(QWidget *parent, const char *name) |
171 | : QPopupMenu(parent, name) | 164 | : QPopupMenu(parent, name) |
172 | { | 165 | { |
173 | d = new OPopupMenuPrivate; | 166 | d = new OPopupMenuPrivate; |
174 | resetKeyboardVars(); | 167 | resetKeyboardVars(); |
175 | connect(&(d->clearTimer), SIGNAL(timeout()), SLOT(resetKeyboardVars())); | 168 | connect(&(d->clearTimer), SIGNAL(timeout()), SLOT(resetKeyboardVars())); |
176 | } | 169 | } |
177 | 170 | ||
178 | OPopupMenu::~OPopupMenu() | 171 | OPopupMenu::~OPopupMenu() |
179 | { | 172 | { |
180 | if (OPopupMenuPrivate::s_contextedMenu == this) | 173 | if (OPopupMenuPrivate::s_contextedMenu == this) |
181 | { | 174 | { |
182 | OPopupMenuPrivate::s_contextedMenu = 0; | 175 | OPopupMenuPrivate::s_contextedMenu = 0; |
183 | OPopupMenuPrivate::s_highlightedItem = -1; | 176 | OPopupMenuPrivate::s_highlightedItem = -1; |
184 | } | 177 | } |
185 | 178 | ||
186 | delete d; | 179 | delete d; |
187 | } | 180 | } |
188 | 181 | ||
189 | int OPopupMenu::insertTitle(const QString &text, int id, int index) | 182 | int OPopupMenu::insertTitle(const QString &text, int id, int index) |
190 | { | 183 | { |
191 | OPopupTitle *titleItem = new OPopupTitle(); | 184 | OPopupTitle *titleItem = new OPopupTitle(); |
192 | titleItem->setTitle(text); | 185 | titleItem->setTitle(text); |
193 | int ret = insertItem(titleItem, id, index); | 186 | int ret = insertItem(titleItem, id, index); |
194 | setItemEnabled(id, false); | 187 | setItemEnabled(id, false); |
195 | return ret; | 188 | return ret; |
196 | } | 189 | } |
197 | 190 | ||
198 | int OPopupMenu::insertTitle(const QPixmap &icon, const QString &text, int id, | 191 | int OPopupMenu::insertTitle(const QPixmap &icon, const QString &text, int id, |
199 | int index) | 192 | int index) |
200 | { | 193 | { |
201 | OPopupTitle *titleItem = new OPopupTitle(); | 194 | OPopupTitle *titleItem = new OPopupTitle(); |
202 | titleItem->setTitle(text, &icon); | 195 | titleItem->setTitle(text, &icon); |
203 | int ret = insertItem(titleItem, id, index); | 196 | int ret = insertItem(titleItem, id, index); |
204 | setItemEnabled(id, false); | 197 | setItemEnabled(id, false); |
205 | return ret; | 198 | return ret; |
206 | } | 199 | } |
207 | 200 | ||
208 | void OPopupMenu::changeTitle(int id, const QString &text) | 201 | void OPopupMenu::changeTitle(int id, const QString &text) |
209 | { | 202 | { |
210 | QMenuItem *item = findItem(id); | 203 | QMenuItem *item = findItem(id); |
211 | if(item){ | 204 | if(item){ |
212 | if(item->widget()) | 205 | if(item->widget()) |
213 | ((OPopupTitle *)item->widget())->setTitle(text); | 206 | ((OPopupTitle *)item->widget())->setTitle(text); |
214 | #ifndef NDEBUG | 207 | #ifndef NDEBUG |
215 | else | 208 | else |
216 | qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id ); | 209 | qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id ); |
217 | #endif | 210 | #endif |
218 | } | 211 | } |
219 | #ifndef NDEBUG | 212 | #ifndef NDEBUG |
220 | else | 213 | else |
221 | qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id ); | 214 | qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id ); |
222 | #endif | 215 | #endif |
223 | } | 216 | } |
224 | 217 | ||
225 | void OPopupMenu::changeTitle(int id, const QPixmap &icon, const QString &text) | 218 | void OPopupMenu::changeTitle(int id, const QPixmap &icon, const QString &text) |
226 | { | 219 | { |
227 | QMenuItem *item = findItem(id); | 220 | QMenuItem *item = findItem(id); |
228 | if(item){ | 221 | if(item){ |
229 | if(item->widget()) | 222 | if(item->widget()) |
230 | ((OPopupTitle *)item->widget())->setTitle(text, &icon); | 223 | ((OPopupTitle *)item->widget())->setTitle(text, &icon); |
231 | #ifndef NDEBUG | 224 | #ifndef NDEBUG |
232 | else | 225 | else |
233 | qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id ); | 226 | qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id ); |
234 | #endif | 227 | #endif |
235 | } | 228 | } |
236 | #ifndef NDEBUG | 229 | #ifndef NDEBUG |
237 | else | 230 | else |
238 | qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id ); | 231 | qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id ); |
239 | #endif | 232 | #endif |
240 | } | 233 | } |
241 | 234 | ||
242 | QString OPopupMenu::title(int id) const | 235 | QString OPopupMenu::title(int id) const |
243 | { | 236 | { |
244 | if(id == -1) // obsolete | 237 | if(id == -1) // obsolete |
245 | return(d->m_lastTitle); | 238 | return(d->m_lastTitle); |
246 | QMenuItem *item = findItem(id); | 239 | QMenuItem *item = findItem(id); |
247 | if(item){ | 240 | if(item){ |
248 | if(item->widget()) | 241 | if(item->widget()) |
249 | return(((OPopupTitle *)item->widget())->title()); | 242 | return(((OPopupTitle *)item->widget())->title()); |
250 | else | 243 | else |
251 | qWarning("OPopupMenu: title() called with non-title id %d.", id); | 244 | qWarning("OPopupMenu: title() called with non-title id %d.", id); |
252 | } | 245 | } |
253 | else | 246 | else |
254 | qWarning("OPopupMenu: title() called with invalid id %d.", id); | 247 | qWarning("OPopupMenu: title() called with invalid id %d.", id); |
255 | return(QString::null); | 248 | return(QString::null); |
256 | } | 249 | } |
257 | 250 | ||
258 | QPixmap OPopupMenu::titlePixmap(int id) const | 251 | QPixmap OPopupMenu::titlePixmap(int id) const |
259 | { | 252 | { |
260 | QMenuItem *item = findItem(id); | 253 | QMenuItem *item = findItem(id); |
261 | if(item){ | 254 | if(item){ |
262 | if(item->widget()) | 255 | if(item->widget()) |
263 | return(((OPopupTitle *)item->widget())->icon()); | 256 | return(((OPopupTitle *)item->widget())->icon()); |
264 | else | 257 | else |
265 | qWarning("KPopupMenu: titlePixmap() called with non-title id %d.", id); | 258 | qWarning("KPopupMenu: titlePixmap() called with non-title id %d.", id); |
266 | } | 259 | } |
267 | else | 260 | else |
268 | qWarning("KPopupMenu: titlePixmap() called with invalid id %d.", id); | 261 | qWarning("KPopupMenu: titlePixmap() called with invalid id %d.", id); |
269 | QPixmap tmp; | 262 | QPixmap tmp; |
270 | return(tmp); | 263 | return(tmp); |
271 | } | 264 | } |
272 | 265 | ||
273 | /** | 266 | /** |
274 | * This is re-implemented for keyboard navigation. | 267 | * This is re-implemented for keyboard navigation. |
275 | */ | 268 | */ |
276 | void OPopupMenu::closeEvent(QCloseEvent*e) | 269 | void OPopupMenu::closeEvent(QCloseEvent*e) |
277 | { | 270 | { |
278 | if (d->shortcuts) | 271 | if (d->shortcuts) |
279 | resetKeyboardVars(); | 272 | resetKeyboardVars(); |
280 | QPopupMenu::closeEvent(e); | 273 | QPopupMenu::closeEvent(e); |
281 | } | 274 | } |
282 | 275 | ||
283 | void OPopupMenu::keyPressEvent(QKeyEvent* e) | 276 | void OPopupMenu::keyPressEvent(QKeyEvent* e) |
284 | { | 277 | { |
285 | if (!d->shortcuts) { | 278 | if (!d->shortcuts) { |
286 | // continue event processing by Qpopup | 279 | // continue event processing by Qpopup |
287 | //e->ignore(); | 280 | //e->ignore(); |
288 | QPopupMenu::keyPressEvent(e); | 281 | QPopupMenu::keyPressEvent(e); |
289 | return; | 282 | return; |
290 | } | 283 | } |
291 | 284 | ||
292 | int i = 0; | 285 | int i = 0; |
293 | bool firstpass = true; | 286 | bool firstpass = true; |
294 | QString keyString = e->text(); | 287 | QString keyString = e->text(); |
295 | 288 | ||
296 | // check for common commands dealt with by QPopup | 289 | // check for common commands dealt with by QPopup |
297 | int key = e->key(); | 290 | int key = e->key(); |
298 | if (key == Key_Escape || key == Key_Return || key == Key_Enter | 291 | if (key == Key_Escape || key == Key_Return || key == Key_Enter |
299 | || key == Key_Up || key == Key_Down || key == Key_Left | 292 | || key == Key_Up || key == Key_Down || key == Key_Left |
300 | || key == Key_Right || key == Key_F1) { | 293 | || key == Key_Right || key == Key_F1) { |
301 | 294 | ||
302 | resetKeyboardVars(); | 295 | resetKeyboardVars(); |
303 | // continue event processing by Qpopup | 296 | // continue event processing by Qpopup |
304 | //e->ignore(); | 297 | //e->ignore(); |
305 | QPopupMenu::keyPressEvent(e); | 298 | QPopupMenu::keyPressEvent(e); |
306 | return; | 299 | return; |
307 | } | 300 | } |
308 | 301 | ||
309 | // check to see if the user wants to remove a key from the sequence (backspace) | 302 | // check to see if the user wants to remove a key from the sequence (backspace) |
310 | // or clear the sequence (delete) | 303 | // or clear the sequence (delete) |
311 | if (!d->keySeq.isNull()) { | 304 | if (!d->keySeq.isNull()) { |
312 | 305 | ||
313 | if (key == Key_Backspace) { | 306 | if (key == Key_Backspace) { |
314 | 307 | ||
315 | if (d->keySeq.length() == 1) { | 308 | if (d->keySeq.length() == 1) { |
316 | resetKeyboardVars(); | 309 | resetKeyboardVars(); |
317 | return; | 310 | return; |
318 | } | 311 | } |
319 | 312 | ||
320 | // keep the last sequence in keyString | 313 | // keep the last sequence in keyString |
321 | keyString = d->keySeq.left(d->keySeq.length() - 1); | 314 | keyString = d->keySeq.left(d->keySeq.length() - 1); |
322 | 315 | ||
323 | // allow sequence matching to be tried again | 316 | // allow sequence matching to be tried again |
324 | resetKeyboardVars(); | 317 | resetKeyboardVars(); |
325 | 318 | ||
326 | } else if (key == Key_Delete) { | 319 | } else if (key == Key_Delete) { |
327 | resetKeyboardVars(); | 320 | resetKeyboardVars(); |
328 | 321 | ||
329 | // clear active item | 322 | // clear active item |
330 | setActiveItem(0); | 323 | setActiveItem(0); |
331 | return; | 324 | return; |
332 | 325 | ||
333 | } else if (d->noMatches) { | 326 | } else if (d->noMatches) { |
334 | // clear if there are no matches | 327 | // clear if there are no matches |
335 | resetKeyboardVars(); | 328 | resetKeyboardVars(); |
336 | 329 | ||
337 | // clear active item | 330 | // clear active item |
338 | setActiveItem(0); | 331 | setActiveItem(0); |
339 | 332 | ||
340 | } else { | 333 | } else { |
341 | // the key sequence is not a null string | 334 | // the key sequence is not a null string |
342 | // therefore the lastHitIndex is valid | 335 | // therefore the lastHitIndex is valid |
343 | i = d->lastHitIndex; | 336 | i = d->lastHitIndex; |
344 | } | 337 | } |
345 | } else if (key == Key_Backspace && parentMenu) { | 338 | } else if (key == Key_Backspace && parentMenu) { |
346 | // backspace with no chars in the buffer... go back a menu. | 339 | // backspace with no chars in the buffer... go back a menu. |
347 | hide(); | 340 | hide(); |
348 | resetKeyboardVars(); | 341 | resetKeyboardVars(); |
349 | return; | 342 | return; |
350 | } | 343 | } |
351 | 344 | ||
352 | d->keySeq += keyString; | 345 | d->keySeq += keyString; |
353 | int seqLen = d->keySeq.length(); | 346 | int seqLen = d->keySeq.length(); |
354 | 347 | ||
355 | for (; i < (int)count(); i++) { | 348 | for (; i < (int)count(); i++) { |
356 | // compare typed text with text of this entry | 349 | // compare typed text with text of this entry |
357 | int j = idAt(i); | 350 | int j = idAt(i); |
358 | 351 | ||
359 | // don't search disabled entries | 352 | // don't search disabled entries |
360 | if (!isItemEnabled(j)) | 353 | if (!isItemEnabled(j)) |
361 | continue; | 354 | continue; |
362 | 355 | ||
363 | QString thisText; | 356 | QString thisText; |
364 | 357 | ||
365 | // retrieve the right text | 358 | // retrieve the right text |
366 | // (the last selected item one may have additional ampersands) | 359 | // (the last selected item one may have additional ampersands) |
367 | if (i == d->lastHitIndex) | 360 | if (i == d->lastHitIndex) |
368 | thisText = d->originalText; | 361 | thisText = d->originalText; |
369 | else | 362 | else |
370 | thisText = text(j); | 363 | thisText = text(j); |
371 | 364 | ||
372 | // if there is an accelerator present, remove it | 365 | // if there is an accelerator present, remove it |
373 | if ((int)accel(j) != 0) | 366 | if ((int)accel(j) != 0) |
374 | thisText = thisText.replace(QRegExp("&"), ""); | 367 | thisText = thisText.replace(QRegExp("&"), ""); |
375 | 368 | ||
376 | // chop text to the search length | 369 | // chop text to the search length |
377 | thisText = thisText.left(seqLen); | 370 | thisText = thisText.left(seqLen); |
378 | 371 | ||
379 | // do the search | 372 | // do the search |
380 | if (thisText.find(d->keySeq, 0, false) == 0) { | 373 | if (thisText.find(d->keySeq, 0, false) == 0) { |
381 | 374 | ||
382 | if (firstpass) { | 375 | if (firstpass) { |
383 | // match | 376 | // match |
384 | setActiveItem(i); | 377 | setActiveItem(i); |
385 | 378 | ||
386 | // check to see if we're underlining a different item | 379 | // check to see if we're underlining a different item |
387 | if (d->lastHitIndex != i) | 380 | if (d->lastHitIndex != i) |
388 | // yes; revert the underlining | 381 | // yes; revert the underlining |
389 | changeItem(idAt(d->lastHitIndex), d->originalText); | 382 | changeItem(idAt(d->lastHitIndex), d->originalText); |
390 | 383 | ||
391 | // set the original text if it's a different item | 384 | // set the original text if it's a different item |
392 | if (d->lastHitIndex != i || d->lastHitIndex == -1) | 385 | if (d->lastHitIndex != i || d->lastHitIndex == -1) |
393 | d->originalText = text(j); | 386 | d->originalText = text(j); |
394 | 387 | ||
395 | // underline the currently selected item | 388 | // underline the currently selected item |
396 | changeItem(j, underlineText(d->originalText, d->keySeq.length())); | 389 | changeItem(j, underlineText(d->originalText, d->keySeq.length())); |
397 | 390 | ||
398 | // remeber what's going on | 391 | // remeber what's going on |
399 | d->lastHitIndex = i; | 392 | d->lastHitIndex = i; |
400 | 393 | ||
401 | // start/restart the clear timer | 394 | // start/restart the clear timer |
402 | d->clearTimer.start(5000, true); | 395 | d->clearTimer.start(5000, true); |
403 | 396 | ||
404 | // go around for another try, to see if we can execute | 397 | // go around for another try, to see if we can execute |
405 | firstpass = false; | 398 | firstpass = false; |
406 | } else { | 399 | } else { |
407 | // don't allow execution | 400 | // don't allow execution |
408 | return; | 401 | return; |
409 | } | 402 | } |
410 | } | 403 | } |
411 | 404 | ||
412 | // fall through to allow execution | 405 | // fall through to allow execution |
413 | } | 406 | } |
414 | 407 | ||
415 | if (!firstpass) { | 408 | if (!firstpass) { |
416 | if (d->autoExec) { | 409 | if (d->autoExec) { |
417 | // activate anything | 410 | // activate anything |
418 | activateItemAt(d->lastHitIndex); | 411 | activateItemAt(d->lastHitIndex); |
419 | resetKeyboardVars(); | 412 | resetKeyboardVars(); |
420 | 413 | ||
421 | } else if (findItem(idAt(d->lastHitIndex)) && | 414 | } else if (findItem(idAt(d->lastHitIndex)) && |
422 | findItem(idAt(d->lastHitIndex))->popup()) { | 415 | findItem(idAt(d->lastHitIndex))->popup()) { |
423 | // only activate sub-menus | 416 | // only activate sub-menus |
424 | activateItemAt(d->lastHitIndex); | 417 | activateItemAt(d->lastHitIndex); |
425 | resetKeyboardVars(); | 418 | resetKeyboardVars(); |
426 | } | 419 | } |
427 | 420 | ||
428 | return; | 421 | return; |
429 | } | 422 | } |
430 | 423 | ||
431 | // no matches whatsoever, clean up | 424 | // no matches whatsoever, clean up |
432 | resetKeyboardVars(true); | 425 | resetKeyboardVars(true); |
433 | //e->ignore(); | 426 | //e->ignore(); |
434 | QPopupMenu::keyPressEvent(e); | 427 | QPopupMenu::keyPressEvent(e); |
435 | } | 428 | } |
436 | 429 | ||
437 | QString OPopupMenu::underlineText(const QString& text, uint length) | 430 | QString OPopupMenu::underlineText(const QString& text, uint length) |
438 | { | 431 | { |
439 | QString ret = text; | 432 | QString ret = text; |
440 | for (uint i = 0; i < length; i++) { | 433 | for (uint i = 0; i < length; i++) { |
441 | if (ret[2*i] != '&') | 434 | if (ret[2*i] != '&') |
442 | ret.insert(2*i, "&"); | 435 | ret.insert(2*i, "&"); |
443 | } | 436 | } |
444 | return ret; | 437 | return ret; |
445 | } | 438 | } |
446 | 439 | ||
447 | void OPopupMenu::resetKeyboardVars(bool noMatches /* = false */) | 440 | void OPopupMenu::resetKeyboardVars(bool noMatches /* = false */) |
448 | { | 441 | { |
449 | // Clean up keyboard variables | 442 | // Clean up keyboard variables |
450 | if (d->lastHitIndex != -1) { | 443 | if (d->lastHitIndex != -1) { |
451 | changeItem(idAt(d->lastHitIndex), d->originalText); | 444 | changeItem(idAt(d->lastHitIndex), d->originalText); |
452 | d->lastHitIndex = -1; | 445 | d->lastHitIndex = -1; |
453 | } | 446 | } |
454 | 447 | ||
455 | if (!noMatches) { | 448 | if (!noMatches) { |
456 | d->keySeq = QString::null; | 449 | d->keySeq = QString::null; |
457 | } | 450 | } |
458 | 451 | ||
459 | d->noMatches = noMatches; | 452 | d->noMatches = noMatches; |
460 | } | 453 | } |
461 | 454 | ||
462 | void OPopupMenu::setKeyboardShortcutsEnabled(bool enable) | 455 | void OPopupMenu::setKeyboardShortcutsEnabled(bool enable) |
463 | { | 456 | { |
464 | d->shortcuts = enable; | 457 | d->shortcuts = enable; |
465 | } | 458 | } |
466 | 459 | ||
467 | void OPopupMenu::setKeyboardShortcutsExecute(bool enable) | 460 | void OPopupMenu::setKeyboardShortcutsExecute(bool enable) |
468 | { | 461 | { |
469 | d->autoExec = enable; | 462 | d->autoExec = enable; |
470 | } | 463 | } |
471 | /** | 464 | /** |
472 | * End keyboard navigation. | 465 | * End keyboard navigation. |
473 | */ | 466 | */ |
474 | 467 | ||
475 | /** | 468 | /** |
476 | * RMB menus on menus | 469 | * RMB menus on menus |
477 | */ | 470 | */ |
478 | QPopupMenu* OPopupMenu::contextMenu() | 471 | QPopupMenu* OPopupMenu::contextMenu() |
479 | { | 472 | { |
480 | if (!d->m_ctxMenu) | 473 | if (!d->m_ctxMenu) |
481 | { | 474 | { |
482 | d->m_ctxMenu = new QPopupMenu(this); | 475 | d->m_ctxMenu = new QPopupMenu(this); |
483 | installEventFilter(this); | 476 | installEventFilter(this); |
484 | connect(d->m_ctxMenu, SIGNAL(aboutToHide()), this, SLOT(ctxMenuHiding())); | 477 | connect(d->m_ctxMenu, SIGNAL(aboutToHide()), this, SLOT(ctxMenuHiding())); |
485 | } | 478 | } |
486 | 479 | ||
487 | return d->m_ctxMenu; | 480 | return d->m_ctxMenu; |
488 | } | 481 | } |
489 | 482 | ||
490 | void OPopupMenu::cancelContextMenuShow() | 483 | void OPopupMenu::cancelContextMenuShow() |
491 | { | 484 | { |
492 | OPopupMenuPrivate::s_continueCtxMenuShow = false; | 485 | OPopupMenuPrivate::s_continueCtxMenuShow = false; |
493 | } | 486 | } |
494 | 487 | ||
495 | int OPopupMenu::contextMenuFocusItem() | 488 | int OPopupMenu::contextMenuFocusItem() |
496 | { | 489 | { |
497 | return OPopupMenuPrivate::s_highlightedItem; | 490 | return OPopupMenuPrivate::s_highlightedItem; |
498 | } | 491 | } |
499 | 492 | ||
500 | OPopupMenu* OPopupMenu::contextMenuFocus() | 493 | OPopupMenu* OPopupMenu::contextMenuFocus() |
501 | { | 494 | { |
502 | return OPopupMenuPrivate::s_contextedMenu; | 495 | return OPopupMenuPrivate::s_contextedMenu; |
503 | } | 496 | } |
504 | 497 | ||
505 | void OPopupMenu::itemHighlighted(int /* whichItem */) | 498 | void OPopupMenu::itemHighlighted(int /* whichItem */) |
506 | { | 499 | { |
507 | if (!d->m_ctxMenu || !d->m_ctxMenu->isVisible()) | 500 | if (!d->m_ctxMenu || !d->m_ctxMenu->isVisible()) |
508 | { | 501 | { |
509 | return; | 502 | return; |
510 | } | 503 | } |
511 | 504 | ||
512 | d->m_ctxMenu->hide(); | 505 | d->m_ctxMenu->hide(); |
513 | showCtxMenu(mapFromGlobal(QCursor::pos())); | 506 | showCtxMenu(mapFromGlobal(QCursor::pos())); |
514 | } | 507 | } |
515 | 508 | ||
516 | void OPopupMenu::showCtxMenu(QPoint pos) | 509 | void OPopupMenu::showCtxMenu(QPoint pos) |
517 | { | 510 | { |
518 | OPopupMenuPrivate::s_highlightedItem = idAt(pos); | 511 | OPopupMenuPrivate::s_highlightedItem = idAt(pos); |
519 | 512 | ||
520 | if (OPopupMenuPrivate::s_highlightedItem == -1) | 513 | if (OPopupMenuPrivate::s_highlightedItem == -1) |
521 | { | 514 | { |
522 | OPopupMenuPrivate::s_contextedMenu = 0; | 515 | OPopupMenuPrivate::s_contextedMenu = 0; |
523 | return; | 516 | return; |
524 | } | 517 | } |
525 | 518 | ||
526 | emit aboutToShowContextMenu(this, OPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu); | 519 | emit aboutToShowContextMenu(this, OPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu); |
527 | 520 | ||
528 | if (!OPopupMenuPrivate::s_continueCtxMenuShow) | 521 | if (!OPopupMenuPrivate::s_continueCtxMenuShow) |
529 | { | 522 | { |
530 | OPopupMenuPrivate::s_continueCtxMenuShow = true; | 523 | OPopupMenuPrivate::s_continueCtxMenuShow = true; |
531 | return; | 524 | return; |
532 | } | 525 | } |
533 | 526 | ||
534 | OPopupMenuPrivate::s_contextedMenu = this; | 527 | OPopupMenuPrivate::s_contextedMenu = this; |
535 | d->m_ctxMenu->popup(this->mapToGlobal(pos)); | 528 | d->m_ctxMenu->popup(this->mapToGlobal(pos)); |
536 | connect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int))); | 529 | connect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int))); |
537 | } | 530 | } |
538 | 531 | ||
539 | void OPopupMenu::ctxMenuHiding() | 532 | void OPopupMenu::ctxMenuHiding() |
540 | { | 533 | { |
541 | disconnect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int))); | 534 | disconnect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int))); |
542 | OPopupMenuPrivate::s_continueCtxMenuShow = true; | 535 | OPopupMenuPrivate::s_continueCtxMenuShow = true; |
543 | } | 536 | } |
544 | 537 | ||
545 | bool OPopupMenu::eventFilter(QObject* obj, QEvent* event) | 538 | bool OPopupMenu::eventFilter(QObject* obj, QEvent* event) |
546 | { | 539 | { |
547 | if (d->m_ctxMenu && obj == this) | 540 | if (d->m_ctxMenu && obj == this) |
548 | { | 541 | { |
549 | if (event->type() == QEvent::MouseButtonRelease) | 542 | if (event->type() == QEvent::MouseButtonRelease) |
550 | { | 543 | { |
551 | if (d->m_ctxMenu->isVisible()) | 544 | if (d->m_ctxMenu->isVisible()) |
552 | { | 545 | { |
553 | return true; | 546 | return true; |
554 | } | 547 | } |
555 | } | 548 | } |
556 | #if QT_VERSION > 290 | 549 | #if QT_VERSION > 290 |
557 | else if (event->type() == QEvent::ContextMenu) | 550 | else if (event->type() == QEvent::ContextMenu) |
558 | #else | 551 | #else |
559 | else if ( (event->type() == QEvent::MouseButtonPress) && | 552 | else if ( (event->type() == QEvent::MouseButtonPress) && |
560 | ( (QMouseEvent*) event )->button() == QMouseEvent::RightButton ) | 553 | ( (QMouseEvent*) event )->button() == QMouseEvent::RightButton ) |
561 | #endif | 554 | #endif |
562 | { | 555 | { |
563 | showCtxMenu(mapFromGlobal(QCursor::pos())); | 556 | showCtxMenu(mapFromGlobal(QCursor::pos())); |
564 | return true; | 557 | return true; |
565 | } | 558 | } |
566 | } | 559 | } |
567 | 560 | ||
568 | return QWidget::eventFilter(obj, event); | 561 | return QWidget::eventFilter(obj, event); |
569 | } | 562 | } |
570 | 563 | ||
571 | void OPopupMenu::hideEvent(QHideEvent*) | 564 | void OPopupMenu::hideEvent(QHideEvent*) |
572 | { | 565 | { |
573 | if (d->m_ctxMenu) | 566 | if (d->m_ctxMenu) |
574 | { | 567 | { |
575 | d->m_ctxMenu->hide(); | 568 | d->m_ctxMenu->hide(); |
576 | } | 569 | } |
577 | } | 570 | } |
578 | /** | 571 | /** |
579 | * end of RMB menus on menus support | 572 | * end of RMB menus on menus support |
580 | */ | 573 | */ |
581 | 574 | ||
582 | // Obsolete | 575 | // Obsolete |
583 | OPopupMenu::OPopupMenu(const QString& title, QWidget *parent, const char *name) | 576 | OPopupMenu::OPopupMenu(const QString& title, QWidget *parent, const char *name) |
584 | : QPopupMenu(parent, name) | 577 | : QPopupMenu(parent, name) |
585 | { | 578 | { |
586 | d = new OPopupMenuPrivate; | 579 | d = new OPopupMenuPrivate; |
587 | setTitle(title); | 580 | setTitle(title); |
588 | } | 581 | } |
589 | 582 | ||
590 | // Obsolete | 583 | // Obsolete |
591 | void OPopupMenu::setTitle(const QString &title) | 584 | void OPopupMenu::setTitle(const QString &title) |
592 | { | 585 | { |
593 | OPopupTitle *titleItem = new OPopupTitle(); | 586 | OPopupTitle *titleItem = new OPopupTitle(); |
594 | titleItem->setTitle(title); | 587 | titleItem->setTitle(title); |
595 | insertItem(titleItem); | 588 | insertItem(titleItem); |
596 | d->m_lastTitle = title; | 589 | d->m_lastTitle = title; |
597 | } | 590 | } |
598 | 591 | ||
599 | void OPopupTitle::virtual_hook( int, void* ) | 592 | void OPopupTitle::virtual_hook( int, void* ) |
600 | { /*BASE::virtual_hook( id, data );*/ } | 593 | { /*BASE::virtual_hook( id, data );*/ } |
601 | 594 | ||
602 | void OPopupMenu::virtual_hook( int, void* ) | 595 | void OPopupMenu::virtual_hook( int, void* ) |
603 | { /*BASE::virtual_hook( id, data );*/ } | 596 | { /*BASE::virtual_hook( id, data );*/ } |
604 | 597 | ||
diff --git a/libopie2/opieui/oselector.cpp b/libopie2/opieui/oselector.cpp index ec5af6b..23b3ce3 100644 --- a/libopie2/opieui/oselector.cpp +++ b/libopie2/opieui/oselector.cpp | |||
@@ -1,716 +1,715 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1997 Martin Jones (mjones@kde.org) | 2 | Copyright (C) 1997 Martin Jones (mjones@kde.org) |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | /* QT */ | 20 | /* QT */ |
21 | 21 | ||
22 | #include <qimage.h> | 22 | #include <qimage.h> |
23 | #include <qpainter.h> | ||
24 | #include <qdrawutil.h> | 23 | #include <qdrawutil.h> |
25 | 24 | ||
26 | /* OPIE */ | 25 | /* OPIE */ |
27 | 26 | ||
28 | #include <opie2/oimageeffect.h> | 27 | #include <opie2/oimageeffect.h> |
29 | #include <opie2/oselector.h> | 28 | #include <opie2/oselector.h> |
30 | 29 | ||
31 | #define STORE_W 8 | 30 | #define STORE_W 8 |
32 | #define STORE_W2 STORE_W * 2 | 31 | #define STORE_W2 STORE_W * 2 |
33 | 32 | ||
34 | //----------------------------------------------------------------------------- | 33 | //----------------------------------------------------------------------------- |
35 | /* | 34 | /* |
36 | * 2D value selector. | 35 | * 2D value selector. |
37 | * The contents of the selector are drawn by derived class. | 36 | * The contents of the selector are drawn by derived class. |
38 | */ | 37 | */ |
39 | 38 | ||
40 | OXYSelector::OXYSelector( QWidget *parent, const char *name ) | 39 | OXYSelector::OXYSelector( QWidget *parent, const char *name ) |
41 | : QWidget( parent, name ) | 40 | : QWidget( parent, name ) |
42 | { | 41 | { |
43 | xPos = 0; | 42 | xPos = 0; |
44 | yPos = 0; | 43 | yPos = 0; |
45 | minX = 0; | 44 | minX = 0; |
46 | minY = 0; | 45 | minY = 0; |
47 | maxX = 100; | 46 | maxX = 100; |
48 | maxY = 100; | 47 | maxY = 100; |
49 | store.setOptimization( QPixmap::BestOptim ); | 48 | store.setOptimization( QPixmap::BestOptim ); |
50 | store.resize( STORE_W2, STORE_W2 ); | 49 | store.resize( STORE_W2, STORE_W2 ); |
51 | } | 50 | } |
52 | 51 | ||
53 | 52 | ||
54 | OXYSelector::~OXYSelector() | 53 | OXYSelector::~OXYSelector() |
55 | {} | 54 | {} |
56 | 55 | ||
57 | 56 | ||
58 | void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY ) | 57 | void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY ) |
59 | { | 58 | { |
60 | px = 2; | 59 | px = 2; |
61 | py = 2; | 60 | py = 2; |
62 | minX = _minX; | 61 | minX = _minX; |
63 | minY = _minY; | 62 | minY = _minY; |
64 | maxX = _maxX; | 63 | maxX = _maxX; |
65 | maxY = _maxY; | 64 | maxY = _maxY; |
66 | } | 65 | } |
67 | 66 | ||
68 | void OXYSelector::setValues( int _xPos, int _yPos ) | 67 | void OXYSelector::setValues( int _xPos, int _yPos ) |
69 | { | 68 | { |
70 | xPos = _xPos; | 69 | xPos = _xPos; |
71 | yPos = _yPos; | 70 | yPos = _yPos; |
72 | 71 | ||
73 | if ( xPos > maxX ) | 72 | if ( xPos > maxX ) |
74 | xPos = maxX; | 73 | xPos = maxX; |
75 | else if ( xPos < minX ) | 74 | else if ( xPos < minX ) |
76 | xPos = minX; | 75 | xPos = minX; |
77 | 76 | ||
78 | if ( yPos > maxY ) | 77 | if ( yPos > maxY ) |
79 | yPos = maxY; | 78 | yPos = maxY; |
80 | else if ( yPos < minY ) | 79 | else if ( yPos < minY ) |
81 | yPos = minY; | 80 | yPos = minY; |
82 | 81 | ||
83 | int xp = 2 + (width() - 4) * xPos / (maxX - minX); | 82 | int xp = 2 + (width() - 4) * xPos / (maxX - minX); |
84 | int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY); | 83 | int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY); |
85 | 84 | ||
86 | setPosition( xp, yp ); | 85 | setPosition( xp, yp ); |
87 | } | 86 | } |
88 | 87 | ||
89 | QRect OXYSelector::contentsRect() const | 88 | QRect OXYSelector::contentsRect() const |
90 | { | 89 | { |
91 | return QRect( 2, 2, width()-4, height()-4 ); | 90 | return QRect( 2, 2, width()-4, height()-4 ); |
92 | } | 91 | } |
93 | 92 | ||
94 | void OXYSelector::paintEvent( QPaintEvent *ev ) | 93 | void OXYSelector::paintEvent( QPaintEvent *ev ) |
95 | { | 94 | { |
96 | QRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2); | 95 | QRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2); |
97 | QRect paintRect = ev->rect(); | 96 | QRect paintRect = ev->rect(); |
98 | 97 | ||
99 | QPainter painter; | 98 | QPainter painter; |
100 | painter.begin( this ); | 99 | painter.begin( this ); |
101 | 100 | ||
102 | QBrush brush; | 101 | QBrush brush; |
103 | qDrawShadePanel( &painter, 0, 0, width(), height(), colorGroup(), | 102 | qDrawShadePanel( &painter, 0, 0, width(), height(), colorGroup(), |
104 | TRUE, 2, &brush ); | 103 | TRUE, 2, &brush ); |
105 | 104 | ||
106 | drawContents( &painter ); | 105 | drawContents( &painter ); |
107 | if (paintRect.contains(cursorRect)) | 106 | if (paintRect.contains(cursorRect)) |
108 | { | 107 | { |
109 | bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W, | 108 | bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W, |
110 | STORE_W2, STORE_W2, CopyROP ); | 109 | STORE_W2, STORE_W2, CopyROP ); |
111 | drawCursor( &painter, px, py ); | 110 | drawCursor( &painter, px, py ); |
112 | } | 111 | } |
113 | else if (paintRect.intersects(cursorRect)) | 112 | else if (paintRect.intersects(cursorRect)) |
114 | { | 113 | { |
115 | repaint( cursorRect, false); | 114 | repaint( cursorRect, false); |
116 | } | 115 | } |
117 | 116 | ||
118 | painter.end(); | 117 | painter.end(); |
119 | } | 118 | } |
120 | 119 | ||
121 | void OXYSelector::mousePressEvent( QMouseEvent *e ) | 120 | void OXYSelector::mousePressEvent( QMouseEvent *e ) |
122 | { | 121 | { |
123 | int xVal, yVal; | 122 | int xVal, yVal; |
124 | valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); | 123 | valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); |
125 | setValues( xVal, yVal ); | 124 | setValues( xVal, yVal ); |
126 | 125 | ||
127 | emit valueChanged( xPos, yPos ); | 126 | emit valueChanged( xPos, yPos ); |
128 | } | 127 | } |
129 | 128 | ||
130 | void OXYSelector::mouseMoveEvent( QMouseEvent *e ) | 129 | void OXYSelector::mouseMoveEvent( QMouseEvent *e ) |
131 | { | 130 | { |
132 | int xVal, yVal; | 131 | int xVal, yVal; |
133 | valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); | 132 | valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); |
134 | setValues( xVal, yVal ); | 133 | setValues( xVal, yVal ); |
135 | 134 | ||
136 | emit valueChanged( xPos, yPos ); | 135 | emit valueChanged( xPos, yPos ); |
137 | } | 136 | } |
138 | 137 | ||
139 | void OXYSelector::wheelEvent( QWheelEvent *e ) | 138 | void OXYSelector::wheelEvent( QWheelEvent *e ) |
140 | { | 139 | { |
141 | #if QT_VERSION > 290 | 140 | #if QT_VERSION > 290 |
142 | if ( e->orientation() == Qt::Horizontal ) | 141 | if ( e->orientation() == Qt::Horizontal ) |
143 | setValues( xValue() + e->delta()/120, yValue() ); | 142 | setValues( xValue() + e->delta()/120, yValue() ); |
144 | else | 143 | else |
145 | setValues( xValue(), yValue() + e->delta()/120 ); | 144 | setValues( xValue(), yValue() + e->delta()/120 ); |
146 | 145 | ||
147 | emit valueChanged( xPos, yPos ); | 146 | emit valueChanged( xPos, yPos ); |
148 | #endif | 147 | #endif |
149 | } | 148 | } |
150 | 149 | ||
151 | void OXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const | 150 | void OXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const |
152 | { | 151 | { |
153 | xVal = ( (maxX-minX) * (x-2) ) / ( width()-4 ); | 152 | xVal = ( (maxX-minX) * (x-2) ) / ( width()-4 ); |
154 | yVal = maxY - ( ( (maxY-minY) * (y-2) ) / ( height()-4 ) ); | 153 | yVal = maxY - ( ( (maxY-minY) * (y-2) ) / ( height()-4 ) ); |
155 | 154 | ||
156 | if ( xVal > maxX ) | 155 | if ( xVal > maxX ) |
157 | xVal = maxX; | 156 | xVal = maxX; |
158 | else if ( xVal < minX ) | 157 | else if ( xVal < minX ) |
159 | xVal = minX; | 158 | xVal = minX; |
160 | 159 | ||
161 | if ( yVal > maxY ) | 160 | if ( yVal > maxY ) |
162 | yVal = maxY; | 161 | yVal = maxY; |
163 | else if ( yVal < minY ) | 162 | else if ( yVal < minY ) |
164 | yVal = minY; | 163 | yVal = minY; |
165 | } | 164 | } |
166 | 165 | ||
167 | void OXYSelector::setPosition( int xp, int yp ) | 166 | void OXYSelector::setPosition( int xp, int yp ) |
168 | { | 167 | { |
169 | if ( xp < 2 ) | 168 | if ( xp < 2 ) |
170 | xp = 2; | 169 | xp = 2; |
171 | else if ( xp > width() - 2 ) | 170 | else if ( xp > width() - 2 ) |
172 | xp = width() - 2; | 171 | xp = width() - 2; |
173 | 172 | ||
174 | if ( yp < 2 ) | 173 | if ( yp < 2 ) |
175 | yp = 2; | 174 | yp = 2; |
176 | else if ( yp > height() - 2 ) | 175 | else if ( yp > height() - 2 ) |
177 | yp = height() - 2; | 176 | yp = height() - 2; |
178 | 177 | ||
179 | QPainter painter; | 178 | QPainter painter; |
180 | painter.begin( this ); | 179 | painter.begin( this ); |
181 | 180 | ||
182 | bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0, | 181 | bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0, |
183 | STORE_W2, STORE_W2, CopyROP ); | 182 | STORE_W2, STORE_W2, CopyROP ); |
184 | bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W, | 183 | bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W, |
185 | STORE_W2, STORE_W2, CopyROP ); | 184 | STORE_W2, STORE_W2, CopyROP ); |
186 | drawCursor( &painter, xp, yp ); | 185 | drawCursor( &painter, xp, yp ); |
187 | px = xp; | 186 | px = xp; |
188 | py = yp; | 187 | py = yp; |
189 | 188 | ||
190 | painter.end(); | 189 | painter.end(); |
191 | } | 190 | } |
192 | 191 | ||
193 | void OXYSelector::drawContents( QPainter * ) | 192 | void OXYSelector::drawContents( QPainter * ) |
194 | {} | 193 | {} |
195 | 194 | ||
196 | 195 | ||
197 | void OXYSelector::drawCursor( QPainter *p, int xp, int yp ) | 196 | void OXYSelector::drawCursor( QPainter *p, int xp, int yp ) |
198 | { | 197 | { |
199 | p->setPen( QPen( white ) ); | 198 | p->setPen( QPen( white ) ); |
200 | 199 | ||
201 | p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 ); | 200 | p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 ); |
202 | p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 ); | 201 | p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 ); |
203 | p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 ); | 202 | p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 ); |
204 | p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 ); | 203 | p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 ); |
205 | } | 204 | } |
206 | 205 | ||
207 | //----------------------------------------------------------------------------- | 206 | //----------------------------------------------------------------------------- |
208 | /* | 207 | /* |
209 | * 1D value selector with contents drawn by derived class. | 208 | * 1D value selector with contents drawn by derived class. |
210 | * See OColorDialog for example. | 209 | * See OColorDialog for example. |
211 | */ | 210 | */ |
212 | 211 | ||
213 | 212 | ||
214 | OSelector::OSelector( QWidget *parent, const char *name ) | 213 | OSelector::OSelector( QWidget *parent, const char *name ) |
215 | : QWidget( parent, name ), QRangeControl() | 214 | : QWidget( parent, name ), QRangeControl() |
216 | { | 215 | { |
217 | _orientation = Horizontal; | 216 | _orientation = Horizontal; |
218 | _indent = TRUE; | 217 | _indent = TRUE; |
219 | } | 218 | } |
220 | 219 | ||
221 | OSelector::OSelector( Orientation o, QWidget *parent, const char *name ) | 220 | OSelector::OSelector( Orientation o, QWidget *parent, const char *name ) |
222 | : QWidget( parent, name ), QRangeControl() | 221 | : QWidget( parent, name ), QRangeControl() |
223 | { | 222 | { |
224 | _orientation = o; | 223 | _orientation = o; |
225 | _indent = TRUE; | 224 | _indent = TRUE; |
226 | } | 225 | } |
227 | 226 | ||
228 | 227 | ||
229 | OSelector::~OSelector() | 228 | OSelector::~OSelector() |
230 | {} | 229 | {} |
231 | 230 | ||
232 | 231 | ||
233 | QRect OSelector::contentsRect() const | 232 | QRect OSelector::contentsRect() const |
234 | { | 233 | { |
235 | if ( orientation() == Vertical ) | 234 | if ( orientation() == Vertical ) |
236 | return QRect( 2, 5, width()-9, height()-10 ); | 235 | return QRect( 2, 5, width()-9, height()-10 ); |
237 | else | 236 | else |
238 | return QRect( 5, 2, width()-10, height()-9 ); | 237 | return QRect( 5, 2, width()-10, height()-9 ); |
239 | } | 238 | } |
240 | 239 | ||
241 | void OSelector::paintEvent( QPaintEvent * ) | 240 | void OSelector::paintEvent( QPaintEvent * ) |
242 | { | 241 | { |
243 | QPainter painter; | 242 | QPainter painter; |
244 | 243 | ||
245 | painter.begin( this ); | 244 | painter.begin( this ); |
246 | 245 | ||
247 | drawContents( &painter ); | 246 | drawContents( &painter ); |
248 | 247 | ||
249 | QBrush brush; | 248 | QBrush brush; |
250 | 249 | ||
251 | if ( indent() ) | 250 | if ( indent() ) |
252 | { | 251 | { |
253 | if ( orientation() == Vertical ) | 252 | if ( orientation() == Vertical ) |
254 | qDrawShadePanel( &painter, 0, 3, width()-5, height()-6, | 253 | qDrawShadePanel( &painter, 0, 3, width()-5, height()-6, |
255 | colorGroup(), TRUE, 2, &brush ); | 254 | colorGroup(), TRUE, 2, &brush ); |
256 | else | 255 | else |
257 | qDrawShadePanel( &painter, 3, 0, width()-6, height()-5, | 256 | qDrawShadePanel( &painter, 3, 0, width()-6, height()-5, |
258 | colorGroup(), TRUE, 2, &brush ); | 257 | colorGroup(), TRUE, 2, &brush ); |
259 | } | 258 | } |
260 | 259 | ||
261 | QPoint pos = calcArrowPos( value() ); | 260 | QPoint pos = calcArrowPos( value() ); |
262 | drawArrow( &painter, TRUE, pos ); | 261 | drawArrow( &painter, TRUE, pos ); |
263 | 262 | ||
264 | painter.end(); | 263 | painter.end(); |
265 | } | 264 | } |
266 | 265 | ||
267 | void OSelector::mousePressEvent( QMouseEvent *e ) | 266 | void OSelector::mousePressEvent( QMouseEvent *e ) |
268 | { | 267 | { |
269 | moveArrow( e->pos() ); | 268 | moveArrow( e->pos() ); |
270 | } | 269 | } |
271 | 270 | ||
272 | void OSelector::mouseMoveEvent( QMouseEvent *e ) | 271 | void OSelector::mouseMoveEvent( QMouseEvent *e ) |
273 | { | 272 | { |
274 | moveArrow( e->pos() ); | 273 | moveArrow( e->pos() ); |
275 | } | 274 | } |
276 | 275 | ||
277 | void OSelector::wheelEvent( QWheelEvent *e ) | 276 | void OSelector::wheelEvent( QWheelEvent *e ) |
278 | { | 277 | { |
279 | int val = value() + e->delta()/120; | 278 | int val = value() + e->delta()/120; |
280 | emit valueChanged( val ); | 279 | emit valueChanged( val ); |
281 | setValue( val ); | 280 | setValue( val ); |
282 | } | 281 | } |
283 | 282 | ||
284 | void OSelector::valueChange() | 283 | void OSelector::valueChange() |
285 | { | 284 | { |
286 | QPainter painter; | 285 | QPainter painter; |
287 | QPoint pos; | 286 | QPoint pos; |
288 | 287 | ||
289 | painter.begin( this ); | 288 | painter.begin( this ); |
290 | 289 | ||
291 | pos = calcArrowPos( prevValue() ); | 290 | pos = calcArrowPos( prevValue() ); |
292 | drawArrow( &painter, FALSE, pos ); | 291 | drawArrow( &painter, FALSE, pos ); |
293 | 292 | ||
294 | pos = calcArrowPos( value() ); | 293 | pos = calcArrowPos( value() ); |
295 | drawArrow( &painter, TRUE, pos ); | 294 | drawArrow( &painter, TRUE, pos ); |
296 | 295 | ||
297 | painter.end(); | 296 | painter.end(); |
298 | } | 297 | } |
299 | 298 | ||
300 | void OSelector::moveArrow( const QPoint &pos ) | 299 | void OSelector::moveArrow( const QPoint &pos ) |
301 | { | 300 | { |
302 | int val; | 301 | int val; |
303 | 302 | ||
304 | if ( orientation() == Vertical ) | 303 | if ( orientation() == Vertical ) |
305 | val = ( maxValue() - minValue() ) * (height()-pos.y()-3) | 304 | val = ( maxValue() - minValue() ) * (height()-pos.y()-3) |
306 | / (height()-10) + minValue(); | 305 | / (height()-10) + minValue(); |
307 | else | 306 | else |
308 | val = ( maxValue() - minValue() ) * (width()-pos.x()-3) | 307 | val = ( maxValue() - minValue() ) * (width()-pos.x()-3) |
309 | / (width()-10) + minValue(); | 308 | / (width()-10) + minValue(); |
310 | 309 | ||
311 | if ( val > maxValue() ) | 310 | if ( val > maxValue() ) |
312 | val = maxValue(); | 311 | val = maxValue(); |
313 | if ( val < minValue() ) | 312 | if ( val < minValue() ) |
314 | val = minValue(); | 313 | val = minValue(); |
315 | 314 | ||
316 | emit valueChanged( val ); | 315 | emit valueChanged( val ); |
317 | setValue( val ); | 316 | setValue( val ); |
318 | } | 317 | } |
319 | 318 | ||
320 | QPoint OSelector::calcArrowPos( int val ) | 319 | QPoint OSelector::calcArrowPos( int val ) |
321 | { | 320 | { |
322 | QPoint p; | 321 | QPoint p; |
323 | 322 | ||
324 | if ( orientation() == Vertical ) | 323 | if ( orientation() == Vertical ) |
325 | { | 324 | { |
326 | p.setY( height() - ( (height()-10) * val | 325 | p.setY( height() - ( (height()-10) * val |
327 | / ( maxValue() - minValue() ) + 5 ) ); | 326 | / ( maxValue() - minValue() ) + 5 ) ); |
328 | p.setX( width() - 5 ); | 327 | p.setX( width() - 5 ); |
329 | } | 328 | } |
330 | else | 329 | else |
331 | { | 330 | { |
332 | p.setX( width() - ( (width()-10) * val | 331 | p.setX( width() - ( (width()-10) * val |
333 | / ( maxValue() - minValue() ) + 5 ) ); | 332 | / ( maxValue() - minValue() ) + 5 ) ); |
334 | p.setY( height() - 5 ); | 333 | p.setY( height() - 5 ); |
335 | } | 334 | } |
336 | 335 | ||
337 | return p; | 336 | return p; |
338 | } | 337 | } |
339 | 338 | ||
340 | void OSelector::drawContents( QPainter * ) | 339 | void OSelector::drawContents( QPainter * ) |
341 | {} | 340 | {} |
342 | 341 | ||
343 | void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos ) | 342 | void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos ) |
344 | { | 343 | { |
345 | if ( show ) | 344 | if ( show ) |
346 | { | 345 | { |
347 | QPointArray array(3); | 346 | QPointArray array(3); |
348 | 347 | ||
349 | painter->setPen( QPen() ); | 348 | painter->setPen( QPen() ); |
350 | painter->setBrush( QBrush( colorGroup().buttonText() ) ); | 349 | painter->setBrush( QBrush( colorGroup().buttonText() ) ); |
351 | if ( orientation() == Vertical ) | 350 | if ( orientation() == Vertical ) |
352 | { | 351 | { |
353 | array.setPoint( 0, pos.x()+0, pos.y()+0 ); | 352 | array.setPoint( 0, pos.x()+0, pos.y()+0 ); |
354 | array.setPoint( 1, pos.x()+5, pos.y()+5 ); | 353 | array.setPoint( 1, pos.x()+5, pos.y()+5 ); |
355 | array.setPoint( 2, pos.x()+5, pos.y()-5 ); | 354 | array.setPoint( 2, pos.x()+5, pos.y()-5 ); |
356 | } | 355 | } |
357 | else | 356 | else |
358 | { | 357 | { |
359 | array.setPoint( 0, pos.x()+0, pos.y()+0 ); | 358 | array.setPoint( 0, pos.x()+0, pos.y()+0 ); |
360 | array.setPoint( 1, pos.x()+5, pos.y()+5 ); | 359 | array.setPoint( 1, pos.x()+5, pos.y()+5 ); |
361 | array.setPoint( 2, pos.x()-5, pos.y()+5 ); | 360 | array.setPoint( 2, pos.x()-5, pos.y()+5 ); |
362 | } | 361 | } |
363 | 362 | ||
364 | painter->drawPolygon( array ); | 363 | painter->drawPolygon( array ); |
365 | } | 364 | } |
366 | else | 365 | else |
367 | { | 366 | { |
368 | if ( orientation() == Vertical ) | 367 | if ( orientation() == Vertical ) |
369 | { | 368 | { |
370 | repaint(pos.x(), pos.y()-5, 6, 11, true); | 369 | repaint(pos.x(), pos.y()-5, 6, 11, true); |
371 | } | 370 | } |
372 | else | 371 | else |
373 | { | 372 | { |
374 | repaint(pos.x()-5, pos.y(), 11, 6, true); | 373 | repaint(pos.x()-5, pos.y(), 11, 6, true); |
375 | } | 374 | } |
376 | } | 375 | } |
377 | } | 376 | } |
378 | 377 | ||
379 | //---------------------------------------------------------------------------- | 378 | //---------------------------------------------------------------------------- |
380 | 379 | ||
381 | OGradientSelector::OGradientSelector( QWidget *parent, const char *name ) | 380 | OGradientSelector::OGradientSelector( QWidget *parent, const char *name ) |
382 | : OSelector( parent, name ) | 381 | : OSelector( parent, name ) |
383 | { | 382 | { |
384 | init(); | 383 | init(); |
385 | } | 384 | } |
386 | 385 | ||
387 | 386 | ||
388 | OGradientSelector::OGradientSelector( Orientation o, QWidget *parent, | 387 | OGradientSelector::OGradientSelector( Orientation o, QWidget *parent, |
389 | const char *name ) | 388 | const char *name ) |
390 | : OSelector( o, parent, name ) | 389 | : OSelector( o, parent, name ) |
391 | { | 390 | { |
392 | init(); | 391 | init(); |
393 | } | 392 | } |
394 | 393 | ||
395 | 394 | ||
396 | OGradientSelector::~OGradientSelector() | 395 | OGradientSelector::~OGradientSelector() |
397 | {} | 396 | {} |
398 | 397 | ||
399 | 398 | ||
400 | void OGradientSelector::init() | 399 | void OGradientSelector::init() |
401 | { | 400 | { |
402 | color1.setRgb( 0, 0, 0 ); | 401 | color1.setRgb( 0, 0, 0 ); |
403 | color2.setRgb( 255, 255, 255 ); | 402 | color2.setRgb( 255, 255, 255 ); |
404 | 403 | ||
405 | text1 = text2 = ""; | 404 | text1 = text2 = ""; |
406 | } | 405 | } |
407 | 406 | ||
408 | 407 | ||
409 | void OGradientSelector::drawContents( QPainter *painter ) | 408 | void OGradientSelector::drawContents( QPainter *painter ) |
410 | { | 409 | { |
411 | QImage image( contentsRect().width(), contentsRect().height(), 32 ); | 410 | QImage image( contentsRect().width(), contentsRect().height(), 32 ); |
412 | 411 | ||
413 | QColor col; | 412 | QColor col; |
414 | float scale; | 413 | float scale; |
415 | 414 | ||
416 | int redDiff = color2.red() - color1.red(); | 415 | int redDiff = color2.red() - color1.red(); |
417 | int greenDiff = color2.green() - color1.green(); | 416 | int greenDiff = color2.green() - color1.green(); |
418 | int blueDiff = color2.blue() - color1.blue(); | 417 | int blueDiff = color2.blue() - color1.blue(); |
419 | 418 | ||
420 | if ( orientation() == Vertical ) | 419 | if ( orientation() == Vertical ) |
421 | { | 420 | { |
422 | for ( int y = 0; y < image.height(); y++ ) | 421 | for ( int y = 0; y < image.height(); y++ ) |
423 | { | 422 | { |
424 | scale = 1.0 * y / image.height(); | 423 | scale = 1.0 * y / image.height(); |
425 | col.setRgb( color1.red() + int(redDiff*scale), | 424 | col.setRgb( color1.red() + int(redDiff*scale), |
426 | color1.green() + int(greenDiff*scale), | 425 | color1.green() + int(greenDiff*scale), |
427 | color1.blue() + int(blueDiff*scale) ); | 426 | color1.blue() + int(blueDiff*scale) ); |
428 | 427 | ||
429 | unsigned int *p = (uint *) image.scanLine( y ); | 428 | unsigned int *p = (uint *) image.scanLine( y ); |
430 | for ( int x = 0; x < image.width(); x++ ) | 429 | for ( int x = 0; x < image.width(); x++ ) |
431 | *p++ = col.rgb(); | 430 | *p++ = col.rgb(); |
432 | } | 431 | } |
433 | } | 432 | } |
434 | else | 433 | else |
435 | { | 434 | { |
436 | unsigned int *p = (uint *) image.scanLine( 0 ); | 435 | unsigned int *p = (uint *) image.scanLine( 0 ); |
437 | 436 | ||
438 | for ( int x = 0; x < image.width(); x++ ) | 437 | for ( int x = 0; x < image.width(); x++ ) |
439 | { | 438 | { |
440 | scale = 1.0 * x / image.width(); | 439 | scale = 1.0 * x / image.width(); |
441 | col.setRgb( color1.red() + int(redDiff*scale), | 440 | col.setRgb( color1.red() + int(redDiff*scale), |
442 | color1.green() + int(greenDiff*scale), | 441 | color1.green() + int(greenDiff*scale), |
443 | color1.blue() + int(blueDiff*scale) ); | 442 | color1.blue() + int(blueDiff*scale) ); |
444 | *p++ = col.rgb(); | 443 | *p++ = col.rgb(); |
445 | } | 444 | } |
446 | 445 | ||
447 | for ( int y = 1; y < image.height(); y++ ) | 446 | for ( int y = 1; y < image.height(); y++ ) |
448 | memcpy( image.scanLine( y ), image.scanLine( y - 1), | 447 | memcpy( image.scanLine( y ), image.scanLine( y - 1), |
449 | sizeof( unsigned int ) * image.width() ); | 448 | sizeof( unsigned int ) * image.width() ); |
450 | } | 449 | } |
451 | 450 | ||
452 | QColor ditherPalette[8]; | 451 | QColor ditherPalette[8]; |
453 | 452 | ||
454 | for ( int s = 0; s < 8; s++ ) | 453 | for ( int s = 0; s < 8; s++ ) |
455 | ditherPalette[s].setRgb( color1.red() + redDiff * s / 8, | 454 | ditherPalette[s].setRgb( color1.red() + redDiff * s / 8, |
456 | color1.green() + greenDiff * s / 8, | 455 | color1.green() + greenDiff * s / 8, |
457 | color1.blue() + blueDiff * s / 8 ); | 456 | color1.blue() + blueDiff * s / 8 ); |
458 | 457 | ||
459 | OImageEffect::dither( image, ditherPalette, 8 ); | 458 | OImageEffect::dither( image, ditherPalette, 8 ); |
460 | 459 | ||
461 | QPixmap p; | 460 | QPixmap p; |
462 | p.convertFromImage( image ); | 461 | p.convertFromImage( image ); |
463 | 462 | ||
464 | painter->drawPixmap( contentsRect().x(), contentsRect().y(), p ); | 463 | painter->drawPixmap( contentsRect().x(), contentsRect().y(), p ); |
465 | 464 | ||
466 | if ( orientation() == Vertical ) | 465 | if ( orientation() == Vertical ) |
467 | { | 466 | { |
468 | int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2; | 467 | int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2; |
469 | int xPos = contentsRect().left() + (contentsRect().width() - | 468 | int xPos = contentsRect().left() + (contentsRect().width() - |
470 | painter->fontMetrics().width( text2 )) / 2; | 469 | painter->fontMetrics().width( text2 )) / 2; |
471 | QPen pen( color2 ); | 470 | QPen pen( color2 ); |
472 | painter->setPen( pen ); | 471 | painter->setPen( pen ); |
473 | painter->drawText( xPos, yPos, text2 ); | 472 | painter->drawText( xPos, yPos, text2 ); |
474 | 473 | ||
475 | yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2; | 474 | yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2; |
476 | xPos = contentsRect().left() + (contentsRect().width() - | 475 | xPos = contentsRect().left() + (contentsRect().width() - |
477 | painter->fontMetrics().width( text1 )) / 2; | 476 | painter->fontMetrics().width( text1 )) / 2; |
478 | pen.setColor( color1 ); | 477 | pen.setColor( color1 ); |
479 | painter->setPen( pen ); | 478 | painter->setPen( pen ); |
480 | painter->drawText( xPos, yPos, text1 ); | 479 | painter->drawText( xPos, yPos, text1 ); |
481 | } | 480 | } |
482 | else | 481 | else |
483 | { | 482 | { |
484 | int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2; | 483 | int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2; |
485 | 484 | ||
486 | QPen pen( color2 ); | 485 | QPen pen( color2 ); |
487 | painter->setPen( pen ); | 486 | painter->setPen( pen ); |
488 | painter->drawText( contentsRect().left() + 2, yPos, text1 ); | 487 | painter->drawText( contentsRect().left() + 2, yPos, text1 ); |
489 | 488 | ||
490 | pen.setColor( color1 ); | 489 | pen.setColor( color1 ); |
491 | painter->setPen( pen ); | 490 | painter->setPen( pen ); |
492 | painter->drawText( contentsRect().right() - | 491 | painter->drawText( contentsRect().right() - |
493 | painter->fontMetrics().width( text2 ) - 2, yPos, text2 ); | 492 | painter->fontMetrics().width( text2 ) - 2, yPos, text2 ); |
494 | } | 493 | } |
495 | } | 494 | } |
496 | 495 | ||
497 | //----------------------------------------------------------------------------- | 496 | //----------------------------------------------------------------------------- |
498 | 497 | ||
499 | static QColor *standardPalette = 0; | 498 | static QColor *standardPalette = 0; |
500 | 499 | ||
501 | #define STANDARD_PAL_SIZE 17 | 500 | #define STANDARD_PAL_SIZE 17 |
502 | 501 | ||
503 | OColor::OColor() | 502 | OColor::OColor() |
504 | : QColor() | 503 | : QColor() |
505 | { | 504 | { |
506 | r = 0; g = 0; b = 0; h = 0; s = 0; v = 0; | 505 | r = 0; g = 0; b = 0; h = 0; s = 0; v = 0; |
507 | }; | 506 | }; |
508 | 507 | ||
509 | OColor::OColor( const OColor &col) | 508 | OColor::OColor( const OColor &col) |
510 | : QColor( col ) | 509 | : QColor( col ) |
511 | { | 510 | { |
512 | h = col.h; s = col.s; v = col.v; | 511 | h = col.h; s = col.s; v = col.v; |
513 | r = col.r; g = col.g; b = col.b; | 512 | r = col.r; g = col.g; b = col.b; |
514 | }; | 513 | }; |
515 | 514 | ||
516 | OColor::OColor( const QColor &col) | 515 | OColor::OColor( const QColor &col) |
517 | : QColor( col ) | 516 | : QColor( col ) |
518 | { | 517 | { |
519 | QColor::rgb(&r, &g, &b); | 518 | QColor::rgb(&r, &g, &b); |
520 | QColor::hsv(&h, &s, &v); | 519 | QColor::hsv(&h, &s, &v); |
521 | }; | 520 | }; |
522 | 521 | ||
523 | bool OColor::operator==(const OColor& col) const | 522 | bool OColor::operator==(const OColor& col) const |
524 | { | 523 | { |
525 | return (h == col.h) && (s == col.s) && (v == col.v) && | 524 | return (h == col.h) && (s == col.s) && (v == col.v) && |
526 | (r == col.r) && (g == col.g) && (b == col.b); | 525 | (r == col.r) && (g == col.g) && (b == col.b); |
527 | } | 526 | } |
528 | 527 | ||
529 | OColor& OColor::operator=(const OColor& col) | 528 | OColor& OColor::operator=(const OColor& col) |
530 | { | 529 | { |
531 | *(QColor *)this = col; | 530 | *(QColor *)this = col; |
532 | h = col.h; s = col.s; v = col.v; | 531 | h = col.h; s = col.s; v = col.v; |
533 | r = col.r; g = col.g; b = col.b; | 532 | r = col.r; g = col.g; b = col.b; |
534 | return *this; | 533 | return *this; |
535 | } | 534 | } |
536 | 535 | ||
537 | void | 536 | void |
538 | OColor::setHsv(int _h, int _s, int _v) | 537 | OColor::setHsv(int _h, int _s, int _v) |
539 | { | 538 | { |
540 | h = _h; s = _s; v = _v; | 539 | h = _h; s = _s; v = _v; |
541 | QColor::setHsv(h, s, v); | 540 | QColor::setHsv(h, s, v); |
542 | QColor::rgb(&r, &g, &b); | 541 | QColor::rgb(&r, &g, &b); |
543 | }; | 542 | }; |
544 | 543 | ||
545 | void | 544 | void |
546 | OColor::setRgb(int _r, int _g, int _b) | 545 | OColor::setRgb(int _r, int _g, int _b) |
547 | { | 546 | { |
548 | r = _r; g = _g; b = _b; | 547 | r = _r; g = _g; b = _b; |
549 | QColor::setRgb(r, g, b); | 548 | QColor::setRgb(r, g, b); |
550 | QColor::hsv(&h, &s, &v); | 549 | QColor::hsv(&h, &s, &v); |
551 | } | 550 | } |
552 | 551 | ||
553 | void | 552 | void |
554 | OColor::rgb(int *_r, int *_g, int *_b) const | 553 | OColor::rgb(int *_r, int *_g, int *_b) const |
555 | { | 554 | { |
556 | *_r = r; *_g = g; *_b = b; | 555 | *_r = r; *_g = g; *_b = b; |
557 | } | 556 | } |
558 | 557 | ||
559 | void | 558 | void |
560 | OColor::hsv(int *_h, int *_s, int *_v) const | 559 | OColor::hsv(int *_h, int *_s, int *_v) const |
561 | { | 560 | { |
562 | *_h = h; *_s = s; *_v = v; | 561 | *_h = h; *_s = s; *_v = v; |
563 | } | 562 | } |
564 | 563 | ||
565 | static void createStandardPalette() | 564 | static void createStandardPalette() |
566 | { | 565 | { |
567 | if ( standardPalette ) | 566 | if ( standardPalette ) |
568 | return; | 567 | return; |
569 | 568 | ||
570 | standardPalette = new QColor[STANDARD_PAL_SIZE]; | 569 | standardPalette = new QColor[STANDARD_PAL_SIZE]; |
571 | 570 | ||
572 | int i = 0; | 571 | int i = 0; |
573 | 572 | ||
574 | standardPalette[i++] = Qt::red; | 573 | standardPalette[i++] = Qt::red; |
575 | standardPalette[i++] = Qt::green; | 574 | standardPalette[i++] = Qt::green; |
576 | standardPalette[i++] = Qt::blue; | 575 | standardPalette[i++] = Qt::blue; |
577 | standardPalette[i++] = Qt::cyan; | 576 | standardPalette[i++] = Qt::cyan; |
578 | standardPalette[i++] = Qt::magenta; | 577 | standardPalette[i++] = Qt::magenta; |
579 | standardPalette[i++] = Qt::yellow; | 578 | standardPalette[i++] = Qt::yellow; |
580 | standardPalette[i++] = Qt::darkRed; | 579 | standardPalette[i++] = Qt::darkRed; |
581 | standardPalette[i++] = Qt::darkGreen; | 580 | standardPalette[i++] = Qt::darkGreen; |
582 | standardPalette[i++] = Qt::darkBlue; | 581 | standardPalette[i++] = Qt::darkBlue; |
583 | standardPalette[i++] = Qt::darkCyan; | 582 | standardPalette[i++] = Qt::darkCyan; |
584 | standardPalette[i++] = Qt::darkMagenta; | 583 | standardPalette[i++] = Qt::darkMagenta; |
585 | standardPalette[i++] = Qt::darkYellow; | 584 | standardPalette[i++] = Qt::darkYellow; |
586 | standardPalette[i++] = Qt::white; | 585 | standardPalette[i++] = Qt::white; |
587 | standardPalette[i++] = Qt::lightGray; | 586 | standardPalette[i++] = Qt::lightGray; |
588 | standardPalette[i++] = Qt::gray; | 587 | standardPalette[i++] = Qt::gray; |
589 | standardPalette[i++] = Qt::darkGray; | 588 | standardPalette[i++] = Qt::darkGray; |
590 | standardPalette[i++] = Qt::black; | 589 | standardPalette[i++] = Qt::black; |
591 | } | 590 | } |
592 | 591 | ||
593 | 592 | ||
594 | OHSSelector::OHSSelector( QWidget *parent, const char *name ) | 593 | OHSSelector::OHSSelector( QWidget *parent, const char *name ) |
595 | : OXYSelector( parent, name ) | 594 | : OXYSelector( parent, name ) |
596 | { | 595 | { |
597 | setRange( 0, 0, 359, 255 ); | 596 | setRange( 0, 0, 359, 255 ); |
598 | } | 597 | } |
599 | 598 | ||
600 | void OHSSelector::updateContents() | 599 | void OHSSelector::updateContents() |
601 | { | 600 | { |
602 | drawPalette(&pixmap); | 601 | drawPalette(&pixmap); |
603 | } | 602 | } |
604 | 603 | ||
605 | void OHSSelector::resizeEvent( QResizeEvent * ) | 604 | void OHSSelector::resizeEvent( QResizeEvent * ) |
606 | { | 605 | { |
607 | updateContents(); | 606 | updateContents(); |
608 | } | 607 | } |
609 | 608 | ||
610 | void OHSSelector::drawContents( QPainter *painter ) | 609 | void OHSSelector::drawContents( QPainter *painter ) |
611 | { | 610 | { |
612 | painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap ); | 611 | painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap ); |
613 | } | 612 | } |
614 | 613 | ||
615 | void OHSSelector::drawPalette( QPixmap *pixmap ) | 614 | void OHSSelector::drawPalette( QPixmap *pixmap ) |
616 | { | 615 | { |
617 | int xSize = contentsRect().width(), ySize = contentsRect().height(); | 616 | int xSize = contentsRect().width(), ySize = contentsRect().height(); |
618 | QImage image( xSize, ySize, 32 ); | 617 | QImage image( xSize, ySize, 32 ); |
619 | QColor col; | 618 | QColor col; |
620 | int h, s; | 619 | int h, s; |
621 | uint *p; | 620 | uint *p; |
622 | 621 | ||
623 | for ( s = ySize-1; s >= 0; s-- ) | 622 | for ( s = ySize-1; s >= 0; s-- ) |
624 | { | 623 | { |
625 | p = (uint *) image.scanLine( ySize - s - 1 ); | 624 | p = (uint *) image.scanLine( ySize - s - 1 ); |
626 | for( h = 0; h < xSize; h++ ) | 625 | for( h = 0; h < xSize; h++ ) |
627 | { | 626 | { |
628 | col.setHsv( 359*h/(xSize-1), 255*s/(ySize-1), 192 ); | 627 | col.setHsv( 359*h/(xSize-1), 255*s/(ySize-1), 192 ); |
629 | *p = col.rgb(); | 628 | *p = col.rgb(); |
630 | p++; | 629 | p++; |
631 | } | 630 | } |
632 | } | 631 | } |
633 | 632 | ||
634 | if ( QColor::numBitPlanes() <= 8 ) | 633 | if ( QColor::numBitPlanes() <= 8 ) |
635 | { | 634 | { |
636 | createStandardPalette(); | 635 | createStandardPalette(); |
637 | OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE ); | 636 | OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE ); |
638 | } | 637 | } |
639 | pixmap->convertFromImage( image ); | 638 | pixmap->convertFromImage( image ); |
640 | } | 639 | } |
641 | 640 | ||
642 | 641 | ||
643 | //----------------------------------------------------------------------------- | 642 | //----------------------------------------------------------------------------- |
644 | 643 | ||
645 | OValueSelector::OValueSelector( QWidget *parent, const char *name ) | 644 | OValueSelector::OValueSelector( QWidget *parent, const char *name ) |
646 | : OSelector( OSelector::Vertical, parent, name ), _hue(0), _sat(0) | 645 | : OSelector( OSelector::Vertical, parent, name ), _hue(0), _sat(0) |
647 | { | 646 | { |
648 | setRange( 0, 255 ); | 647 | setRange( 0, 255 ); |
649 | pixmap.setOptimization( QPixmap::BestOptim ); | 648 | pixmap.setOptimization( QPixmap::BestOptim ); |
650 | } | 649 | } |
651 | 650 | ||
652 | OValueSelector::OValueSelector(Orientation o, QWidget *parent, const char *name | 651 | OValueSelector::OValueSelector(Orientation o, QWidget *parent, const char *name |
653 | ) | 652 | ) |
654 | : OSelector( o, parent, name), _hue(0), _sat(0) | 653 | : OSelector( o, parent, name), _hue(0), _sat(0) |
655 | { | 654 | { |
656 | setRange( 0, 255 ); | 655 | setRange( 0, 255 ); |
657 | pixmap.setOptimization( QPixmap::BestOptim ); | 656 | pixmap.setOptimization( QPixmap::BestOptim ); |
658 | } | 657 | } |
659 | 658 | ||
660 | void OValueSelector::updateContents() | 659 | void OValueSelector::updateContents() |
661 | { | 660 | { |
662 | drawPalette(&pixmap); | 661 | drawPalette(&pixmap); |
663 | } | 662 | } |
664 | 663 | ||
665 | void OValueSelector::resizeEvent( QResizeEvent * ) | 664 | void OValueSelector::resizeEvent( QResizeEvent * ) |
666 | { | 665 | { |
667 | updateContents(); | 666 | updateContents(); |
668 | } | 667 | } |
669 | 668 | ||
670 | void OValueSelector::drawContents( QPainter *painter ) | 669 | void OValueSelector::drawContents( QPainter *painter ) |
671 | { | 670 | { |
672 | painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap ); | 671 | painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap ); |
673 | } | 672 | } |
674 | 673 | ||
675 | void OValueSelector::drawPalette( QPixmap *pixmap ) | 674 | void OValueSelector::drawPalette( QPixmap *pixmap ) |
676 | { | 675 | { |
677 | int xSize = contentsRect().width(), ySize = contentsRect().height(); | 676 | int xSize = contentsRect().width(), ySize = contentsRect().height(); |
678 | QImage image( xSize, ySize, 32 ); | 677 | QImage image( xSize, ySize, 32 ); |
679 | QColor col; | 678 | QColor col; |
680 | uint *p; | 679 | uint *p; |
681 | QRgb rgb; | 680 | QRgb rgb; |
682 | 681 | ||
683 | if ( orientation() == OSelector::Horizontal ) | 682 | if ( orientation() == OSelector::Horizontal ) |
684 | { | 683 | { |
685 | for ( int v = 0; v < ySize; v++ ) | 684 | for ( int v = 0; v < ySize; v++ ) |
686 | { | 685 | { |
687 | p = (uint *) image.scanLine( ySize - v - 1 ); | 686 | p = (uint *) image.scanLine( ySize - v - 1 ); |
688 | 687 | ||
689 | for( int x = 0; x < xSize; x++ ) | 688 | for( int x = 0; x < xSize; x++ ) |
690 | { | 689 | { |
691 | col.setHsv( _hue, _sat, 255*x/(xSize-1) ); | 690 | col.setHsv( _hue, _sat, 255*x/(xSize-1) ); |
692 | rgb = col.rgb(); | 691 | rgb = col.rgb(); |
693 | *p++ = rgb; | 692 | *p++ = rgb; |
694 | } | 693 | } |
695 | } | 694 | } |
696 | } | 695 | } |
697 | 696 | ||
698 | if( orientation() == OSelector::Vertical ) | 697 | if( orientation() == OSelector::Vertical ) |
699 | { | 698 | { |
700 | for ( int v = 0; v < ySize; v++ ) | 699 | for ( int v = 0; v < ySize; v++ ) |
701 | { | 700 | { |
702 | p = (uint *) image.scanLine( ySize - v - 1 ); | 701 | p = (uint *) image.scanLine( ySize - v - 1 ); |
703 | col.setHsv( _hue, _sat, 255*v/(ySize-1) ); | 702 | col.setHsv( _hue, _sat, 255*v/(ySize-1) ); |
704 | rgb = col.rgb(); | 703 | rgb = col.rgb(); |
705 | for ( int i = 0; i < xSize; i++ ) | 704 | for ( int i = 0; i < xSize; i++ ) |
706 | *p++ = rgb; | 705 | *p++ = rgb; |
707 | } | 706 | } |
708 | } | 707 | } |
709 | 708 | ||
710 | if ( QColor::numBitPlanes() <= 8 ) | 709 | if ( QColor::numBitPlanes() <= 8 ) |
711 | { | 710 | { |
712 | createStandardPalette(); | 711 | createStandardPalette(); |
713 | OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE ); | 712 | OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE ); |
714 | } | 713 | } |
715 | pixmap->convertFromImage( image ); | 714 | pixmap->convertFromImage( image ); |
716 | } | 715 | } |
diff --git a/libopie2/opieui/oseparator.cpp b/libopie2/opieui/oseparator.cpp index 98d42c7..b93c225 100644 --- a/libopie2/opieui/oseparator.cpp +++ b/libopie2/opieui/oseparator.cpp | |||
@@ -1,128 +1,127 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
4 | Copyright (C) 1997 Michael Roth <mroth@wirlweb.de> | 4 | Copyright (C) 1997 Michael Roth <mroth@wirlweb.de> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* OPIE */ | 32 | /* OPIE */ |
33 | 33 | ||
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | #include <opie2/oseparator.h> | 35 | #include <opie2/oseparator.h> |
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | 38 | ||
39 | #include <qstyle.h> | ||
40 | 39 | ||
41 | OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f) | 40 | OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f) |
42 | : QFrame(parent, name, f) | 41 | : QFrame(parent, name, f) |
43 | { | 42 | { |
44 | setLineWidth(1); | 43 | setLineWidth(1); |
45 | setMidLineWidth(0); | 44 | setMidLineWidth(0); |
46 | setOrientation( HLine ); | 45 | setOrientation( HLine ); |
47 | } | 46 | } |
48 | 47 | ||
49 | 48 | ||
50 | 49 | ||
51 | OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f) | 50 | OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f) |
52 | : QFrame(parent, name, f) | 51 | : QFrame(parent, name, f) |
53 | { | 52 | { |
54 | setLineWidth(1); | 53 | setLineWidth(1); |
55 | setMidLineWidth(0); | 54 | setMidLineWidth(0); |
56 | setOrientation( orientation ); | 55 | setOrientation( orientation ); |
57 | } | 56 | } |
58 | 57 | ||
59 | 58 | ||
60 | 59 | ||
61 | void OSeparator::setOrientation(int orientation) | 60 | void OSeparator::setOrientation(int orientation) |
62 | { | 61 | { |
63 | switch(orientation) | 62 | switch(orientation) |
64 | { | 63 | { |
65 | case Vertical: | 64 | case Vertical: |
66 | case VLine: | 65 | case VLine: |
67 | setFrameStyle( QFrame::VLine | QFrame::Sunken ); | 66 | setFrameStyle( QFrame::VLine | QFrame::Sunken ); |
68 | setMinimumSize(2, 0); | 67 | setMinimumSize(2, 0); |
69 | break; | 68 | break; |
70 | 69 | ||
71 | default: | 70 | default: |
72 | owarn << "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" << oendl; | 71 | owarn << "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" << oendl; |
73 | 72 | ||
74 | case Horizontal: | 73 | case Horizontal: |
75 | case HLine: | 74 | case HLine: |
76 | setFrameStyle( QFrame::HLine | QFrame::Sunken ); | 75 | setFrameStyle( QFrame::HLine | QFrame::Sunken ); |
77 | setMinimumSize(0, 2); | 76 | setMinimumSize(0, 2); |
78 | break; | 77 | break; |
79 | } | 78 | } |
80 | } | 79 | } |
81 | 80 | ||
82 | 81 | ||
83 | 82 | ||
84 | int OSeparator::orientation() const | 83 | int OSeparator::orientation() const |
85 | { | 84 | { |
86 | if ( frameStyle() & VLine ) | 85 | if ( frameStyle() & VLine ) |
87 | return VLine; | 86 | return VLine; |
88 | 87 | ||
89 | if ( frameStyle() & HLine ) | 88 | if ( frameStyle() & HLine ) |
90 | return HLine; | 89 | return HLine; |
91 | 90 | ||
92 | return 0; | 91 | return 0; |
93 | } | 92 | } |
94 | 93 | ||
95 | void OSeparator::drawFrame(QPainter *p) | 94 | void OSeparator::drawFrame(QPainter *p) |
96 | { | 95 | { |
97 | QPointp1, p2; | 96 | QPointp1, p2; |
98 | QRectr = frameRect(); | 97 | QRectr = frameRect(); |
99 | const QColorGroup & g = colorGroup(); | 98 | const QColorGroup & g = colorGroup(); |
100 | 99 | ||
101 | if ( frameStyle() & HLine ) { | 100 | if ( frameStyle() & HLine ) { |
102 | p1 = QPoint( r.x(), r.height()/2 ); | 101 | p1 = QPoint( r.x(), r.height()/2 ); |
103 | p2 = QPoint( r.x()+r.width(), p1.y() ); | 102 | p2 = QPoint( r.x()+r.width(), p1.y() ); |
104 | } | 103 | } |
105 | else { | 104 | else { |
106 | p1 = QPoint( r.x()+r.width()/2, 0 ); | 105 | p1 = QPoint( r.x()+r.width()/2, 0 ); |
107 | p2 = QPoint( p1.x(), r.height() ); | 106 | p2 = QPoint( p1.x(), r.height() ); |
108 | } | 107 | } |
109 | 108 | ||
110 | #if QT_VERSION < 300 | 109 | #if QT_VERSION < 300 |
111 | style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() ); | 110 | style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() ); |
112 | #else | 111 | #else |
113 | QStyleOption opt( lineWidth(), midLineWidth() ); | 112 | QStyleOption opt( lineWidth(), midLineWidth() ); |
114 | style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt ); | 113 | style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt ); |
115 | #endif | 114 | #endif |
116 | } | 115 | } |
117 | 116 | ||
118 | 117 | ||
119 | QSize OSeparator::sizeHint() const | 118 | QSize OSeparator::sizeHint() const |
120 | { | 119 | { |
121 | if ( frameStyle() & VLine ) | 120 | if ( frameStyle() & VLine ) |
122 | return QSize(2, 0); | 121 | return QSize(2, 0); |
123 | 122 | ||
124 | if ( frameStyle() & HLine ) | 123 | if ( frameStyle() & HLine ) |
125 | return QSize(0, 2); | 124 | return QSize(0, 2); |
126 | 125 | ||
127 | return QSize(-1, -1); | 126 | return QSize(-1, -1); |
128 | } | 127 | } |
diff --git a/libopie2/opieui/otimepicker.cpp b/libopie2/opieui/otimepicker.cpp index 9f9f2c2..d4712a4 100644 --- a/libopie2/opieui/otimepicker.cpp +++ b/libopie2/opieui/otimepicker.cpp | |||
@@ -1,295 +1,292 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> | 3 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | /* QT */ | 30 | /* QT */ |
31 | #include <qbuttongroup.h> | ||
32 | #include <qlayout.h> | 31 | #include <qlayout.h> |
33 | #include <qlineedit.h> | 32 | #include <qlineedit.h> |
34 | #include <qstring.h> | ||
35 | #include <qtoolbutton.h> | ||
36 | 33 | ||
37 | /* OPIE */ | 34 | /* OPIE */ |
38 | #include <opie2/otimepicker.h> | 35 | #include <opie2/otimepicker.h> |
39 | 36 | ||
40 | using namespace Opie; | 37 | using namespace Opie; |
41 | 38 | ||
42 | /** | 39 | /** |
43 | * Constructs the widget | 40 | * Constructs the widget |
44 | * @param parent The parent of the OTimePicker | 41 | * @param parent The parent of the OTimePicker |
45 | * @param name The name of the object | 42 | * @param name The name of the object |
46 | * @param fl Window Flags | 43 | * @param fl Window Flags |
47 | */ | 44 | */ |
48 | OTimePicker::OTimePicker(QWidget* parent, const char* name, Qt::WFlags fl) | 45 | OTimePicker::OTimePicker(QWidget* parent, const char* name, Qt::WFlags fl) |
49 | :QWidget(parent,name,fl) | 46 | :QWidget(parent,name,fl) |
50 | { | 47 | { |
51 | QVBoxLayout *vbox=new QVBoxLayout(this); | 48 | QVBoxLayout *vbox=new QVBoxLayout(this); |
52 | 49 | ||
53 | OClickableLabel *r; | 50 | OClickableLabel *r; |
54 | QString s; | 51 | QString s; |
55 | 52 | ||
56 | // Hour Row | 53 | // Hour Row |
57 | QWidget *row=new QWidget(this); | 54 | QWidget *row=new QWidget(this); |
58 | QHBoxLayout *l=new QHBoxLayout(row); | 55 | QHBoxLayout *l=new QHBoxLayout(row); |
59 | vbox->addWidget(row); | 56 | vbox->addWidget(row); |
60 | 57 | ||
61 | for (int i=0; i<24; i++) | 58 | for (int i=0; i<24; i++) |
62 | { | 59 | { |
63 | r=new OClickableLabel(row); | 60 | r=new OClickableLabel(row); |
64 | hourLst.append(r); | 61 | hourLst.append(r); |
65 | s.sprintf("%.2d",i); | 62 | s.sprintf("%.2d",i); |
66 | r->setText(s); | 63 | r->setText(s); |
67 | r->setToggleButton(true); | 64 | r->setToggleButton(true); |
68 | r->setAlignment(AlignHCenter | AlignVCenter); | 65 | r->setAlignment(AlignHCenter | AlignVCenter); |
69 | l->addWidget(r); | 66 | l->addWidget(r); |
70 | connect(r, SIGNAL(toggled(bool)), | 67 | connect(r, SIGNAL(toggled(bool)), |
71 | this, SLOT(slotHour(bool))); | 68 | this, SLOT(slotHour(bool))); |
72 | 69 | ||
73 | if (i==11) | 70 | if (i==11) |
74 | { // Second row | 71 | { // Second row |
75 | row=new QWidget(this); | 72 | row=new QWidget(this); |
76 | l=new QHBoxLayout(row); | 73 | l=new QHBoxLayout(row); |
77 | vbox->addWidget(row); | 74 | vbox->addWidget(row); |
78 | } | 75 | } |
79 | } | 76 | } |
80 | 77 | ||
81 | // Minute Row | 78 | // Minute Row |
82 | row=new QWidget(this); | 79 | row=new QWidget(this); |
83 | l=new QHBoxLayout(row); | 80 | l=new QHBoxLayout(row); |
84 | vbox->addWidget(row); | 81 | vbox->addWidget(row); |
85 | 82 | ||
86 | for (int i=0; i<60; i+=5) | 83 | for (int i=0; i<60; i+=5) |
87 | { | 84 | { |
88 | r=new OClickableLabel(row); | 85 | r=new OClickableLabel(row); |
89 | minuteLst.append(r); | 86 | minuteLst.append(r); |
90 | s.sprintf("%.2d",i); | 87 | s.sprintf("%.2d",i); |
91 | r->setText(s); | 88 | r->setText(s); |
92 | r->setToggleButton(true); | 89 | r->setToggleButton(true); |
93 | r->setAlignment(AlignHCenter | AlignVCenter); | 90 | r->setAlignment(AlignHCenter | AlignVCenter); |
94 | l->addWidget(r); | 91 | l->addWidget(r); |
95 | connect(r, SIGNAL(toggled(bool)), | 92 | connect(r, SIGNAL(toggled(bool)), |
96 | this, SLOT(slotMinute(bool))); | 93 | this, SLOT(slotMinute(bool))); |
97 | } | 94 | } |
98 | } | 95 | } |
99 | 96 | ||
100 | /** | 97 | /** |
101 | * This method return the current time | 98 | * This method return the current time |
102 | * @return the time | 99 | * @return the time |
103 | */ | 100 | */ |
104 | QTime OTimePicker::time()const | 101 | QTime OTimePicker::time()const |
105 | { | 102 | { |
106 | return tm; | 103 | return tm; |
107 | } | 104 | } |
108 | 105 | ||
109 | void OTimePicker::slotHour(bool b) | 106 | void OTimePicker::slotHour(bool b) |
110 | { | 107 | { |
111 | 108 | ||
112 | OClickableLabel *r = (OClickableLabel *) sender(); | 109 | OClickableLabel *r = (OClickableLabel *) sender(); |
113 | 110 | ||
114 | if (b) | 111 | if (b) |
115 | { | 112 | { |
116 | QValueListIterator<OClickableLabel *> it; | 113 | QValueListIterator<OClickableLabel *> it; |
117 | for (it=hourLst.begin(); it!=hourLst.end(); it++) | 114 | for (it=hourLst.begin(); it!=hourLst.end(); it++) |
118 | { | 115 | { |
119 | if (*it != r) (*it)->setOn(false); | 116 | if (*it != r) (*it)->setOn(false); |
120 | else tm.setHMS((*it)->text().toInt(), tm.minute(), 0); | 117 | else tm.setHMS((*it)->text().toInt(), tm.minute(), 0); |
121 | } | 118 | } |
122 | emit timeChanged(tm); | 119 | emit timeChanged(tm); |
123 | } | 120 | } |
124 | else | 121 | else |
125 | { | 122 | { |
126 | r->setOn(true); | 123 | r->setOn(true); |
127 | } | 124 | } |
128 | 125 | ||
129 | } | 126 | } |
130 | 127 | ||
131 | void OTimePicker::slotMinute(bool b) | 128 | void OTimePicker::slotMinute(bool b) |
132 | { | 129 | { |
133 | 130 | ||
134 | OClickableLabel *r = (OClickableLabel *) sender(); | 131 | OClickableLabel *r = (OClickableLabel *) sender(); |
135 | 132 | ||
136 | if (b) | 133 | if (b) |
137 | { | 134 | { |
138 | QValueListIterator<OClickableLabel *> it; | 135 | QValueListIterator<OClickableLabel *> it; |
139 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) | 136 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) |
140 | { | 137 | { |
141 | if (*it != r) (*it)->setOn(false); | 138 | if (*it != r) (*it)->setOn(false); |
142 | else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0); | 139 | else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0); |
143 | } | 140 | } |
144 | emit timeChanged(tm); | 141 | emit timeChanged(tm); |
145 | } | 142 | } |
146 | else | 143 | else |
147 | { | 144 | { |
148 | r->setOn(true); | 145 | r->setOn(true); |
149 | } | 146 | } |
150 | 147 | ||
151 | } | 148 | } |
152 | 149 | ||
153 | /** | 150 | /** |
154 | * Method to set the time. No signal gets emitted during this method call | 151 | * Method to set the time. No signal gets emitted during this method call |
155 | * Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... ) | 152 | * Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... ) |
156 | * @param t The time to be set | 153 | * @param t The time to be set |
157 | */ | 154 | */ |
158 | void OTimePicker::setTime( const QTime& t) | 155 | void OTimePicker::setTime( const QTime& t) |
159 | { | 156 | { |
160 | setTime( t.hour(), t.minute() ); | 157 | setTime( t.hour(), t.minute() ); |
161 | } | 158 | } |
162 | 159 | ||
163 | /** | 160 | /** |
164 | * Method to set the time. No signal gets emitted during this method call | 161 | * Method to set the time. No signal gets emitted during this method call |
165 | * @param h The hour | 162 | * @param h The hour |
166 | * @param m The minute. Minutes need to set by 5 minute steps | 163 | * @param m The minute. Minutes need to set by 5 minute steps |
167 | */ | 164 | */ |
168 | void OTimePicker::setTime( int h, int m ) | 165 | void OTimePicker::setTime( int h, int m ) |
169 | { | 166 | { |
170 | setHour(h); | 167 | setHour(h); |
171 | setMinute(m); | 168 | setMinute(m); |
172 | } | 169 | } |
173 | 170 | ||
174 | /* | 171 | /* |
175 | * FIXME round minutes to the 5 minute arrangement -zecke | 172 | * FIXME round minutes to the 5 minute arrangement -zecke |
176 | */ | 173 | */ |
177 | /** | 174 | /** |
178 | * Method to set the minutes | 175 | * Method to set the minutes |
179 | * @param m minutes | 176 | * @param m minutes |
180 | */ | 177 | */ |
181 | void OTimePicker::setMinute(int m) | 178 | void OTimePicker::setMinute(int m) |
182 | { | 179 | { |
183 | 180 | ||
184 | QString minute; | 181 | QString minute; |
185 | minute.sprintf("%.2d",m); | 182 | minute.sprintf("%.2d",m); |
186 | 183 | ||
187 | QValueListIterator<OClickableLabel *> it; | 184 | QValueListIterator<OClickableLabel *> it; |
188 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) | 185 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) |
189 | { | 186 | { |
190 | if ((*it)->text() == minute) (*it)->setOn(true); | 187 | if ((*it)->text() == minute) (*it)->setOn(true); |
191 | else (*it)->setOn(false); | 188 | else (*it)->setOn(false); |
192 | } | 189 | } |
193 | 190 | ||
194 | tm.setHMS(tm.hour(),m,0); | 191 | tm.setHMS(tm.hour(),m,0); |
195 | } | 192 | } |
196 | 193 | ||
197 | /** | 194 | /** |
198 | * Method to set the hour | 195 | * Method to set the hour |
199 | */ | 196 | */ |
200 | void OTimePicker::setHour(int h) | 197 | void OTimePicker::setHour(int h) |
201 | { | 198 | { |
202 | 199 | ||
203 | QString hour; | 200 | QString hour; |
204 | hour.sprintf("%.2d",h); | 201 | hour.sprintf("%.2d",h); |
205 | 202 | ||
206 | QValueListIterator<OClickableLabel *> it; | 203 | QValueListIterator<OClickableLabel *> it; |
207 | for (it=hourLst.begin(); it!=hourLst.end(); it++) | 204 | for (it=hourLst.begin(); it!=hourLst.end(); it++) |
208 | { | 205 | { |
209 | if ((*it)->text() == hour) (*it)->setOn(true); | 206 | if ((*it)->text() == hour) (*it)->setOn(true); |
210 | else (*it)->setOn(false); | 207 | else (*it)->setOn(false); |
211 | } | 208 | } |
212 | tm.setHMS(h,tm.minute(),0); | 209 | tm.setHMS(h,tm.minute(),0); |
213 | } | 210 | } |
214 | 211 | ||
215 | 212 | ||
216 | /** | 213 | /** |
217 | * This is a modal Dialog. | 214 | * This is a modal Dialog. |
218 | * | 215 | * |
219 | * @param parent The parent widget | 216 | * @param parent The parent widget |
220 | * @param name The name of the object | 217 | * @param name The name of the object |
221 | * @param fl Possible window flags | 218 | * @param fl Possible window flags |
222 | */ | 219 | */ |
223 | OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl ) | 220 | OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl ) |
224 | : OTimePickerDialogBase (parent , name, true , fl) | 221 | : OTimePickerDialogBase (parent , name, true , fl) |
225 | { | 222 | { |
226 | 223 | ||
227 | connect ( m_timePicker, SIGNAL( timeChanged( const QTime& ) ), | 224 | connect ( m_timePicker, SIGNAL( timeChanged( const QTime& ) ), |
228 | this, SLOT( setTime ( const QTime& ) ) ); | 225 | this, SLOT( setTime ( const QTime& ) ) ); |
229 | connect ( minuteField, SIGNAL( textChanged ( const QString& ) ), | 226 | connect ( minuteField, SIGNAL( textChanged ( const QString& ) ), |
230 | this, SLOT ( setMinute ( const QString& ) ) ); | 227 | this, SLOT ( setMinute ( const QString& ) ) ); |
231 | connect ( hourField, SIGNAL( textChanged ( const QString& ) ), | 228 | connect ( hourField, SIGNAL( textChanged ( const QString& ) ), |
232 | this, SLOT ( setHour ( const QString& ) ) ); | 229 | this, SLOT ( setHour ( const QString& ) ) ); |
233 | 230 | ||
234 | } | 231 | } |
235 | 232 | ||
236 | /** | 233 | /** |
237 | * @return the time | 234 | * @return the time |
238 | */ | 235 | */ |
239 | QTime OTimePickerDialog::time()const | 236 | QTime OTimePickerDialog::time()const |
240 | { | 237 | { |
241 | return m_time; | 238 | return m_time; |
242 | } | 239 | } |
243 | 240 | ||
244 | /** | 241 | /** |
245 | * Set the time to time | 242 | * Set the time to time |
246 | * @param time The time to be set | 243 | * @param time The time to be set |
247 | */ | 244 | */ |
248 | void OTimePickerDialog::setTime( const QTime& time ) | 245 | void OTimePickerDialog::setTime( const QTime& time ) |
249 | { | 246 | { |
250 | m_time = time; | 247 | m_time = time; |
251 | 248 | ||
252 | m_timePicker->setHour ( time.hour() ); | 249 | m_timePicker->setHour ( time.hour() ); |
253 | m_timePicker->setMinute( time.minute() ); | 250 | m_timePicker->setMinute( time.minute() ); |
254 | 251 | ||
255 | // Set Textfields | 252 | // Set Textfields |
256 | if ( time.hour() < 10 ) | 253 | if ( time.hour() < 10 ) |
257 | hourField->setText( "0" + QString::number( time.hour() ) ); | 254 | hourField->setText( "0" + QString::number( time.hour() ) ); |
258 | else | 255 | else |
259 | hourField->setText( QString::number( time.hour() ) ); | 256 | hourField->setText( QString::number( time.hour() ) ); |
260 | 257 | ||
261 | if ( time.minute() < 10 ) | 258 | if ( time.minute() < 10 ) |
262 | minuteField->setText( "0" + QString::number( time.minute() ) ); | 259 | minuteField->setText( "0" + QString::number( time.minute() ) ); |
263 | else | 260 | else |
264 | minuteField->setText( QString::number( time.minute() ) ); | 261 | minuteField->setText( QString::number( time.minute() ) ); |
265 | 262 | ||
266 | } | 263 | } |
267 | 264 | ||
268 | /** | 265 | /** |
269 | * This method takes the current minute and tries to set hour | 266 | * This method takes the current minute and tries to set hour |
270 | * to hour. This succeeds if the resulting date is valid | 267 | * to hour. This succeeds if the resulting date is valid |
271 | * @param hour The hour as a string | 268 | * @param hour The hour as a string |
272 | */ | 269 | */ |
273 | void OTimePickerDialog::setHour ( const QString& hour ) | 270 | void OTimePickerDialog::setHour ( const QString& hour ) |
274 | { | 271 | { |
275 | if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) ) | 272 | if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) ) |
276 | { | 273 | { |
277 | m_time.setHMS ( hour.toInt(), m_time.minute() , 00 ); | 274 | m_time.setHMS ( hour.toInt(), m_time.minute() , 00 ); |
278 | setTime ( m_time ); | 275 | setTime ( m_time ); |
279 | } | 276 | } |
280 | 277 | ||
281 | } | 278 | } |
282 | 279 | ||
283 | /** | 280 | /** |
284 | * Method to set a new minute. It tries to convert the string to int and | 281 | * Method to set a new minute. It tries to convert the string to int and |
285 | * if the resulting date is valid a new date is set. | 282 | * if the resulting date is valid a new date is set. |
286 | * @see setHour | 283 | * @see setHour |
287 | */ | 284 | */ |
288 | void OTimePickerDialog::setMinute ( const QString& minute ) | 285 | void OTimePickerDialog::setMinute ( const QString& minute ) |
289 | { | 286 | { |
290 | if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ) | 287 | if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ) |
291 | { | 288 | { |
292 | m_time.setHMS ( m_time.hour(), minute.toInt(), 00 ); | 289 | m_time.setHMS ( m_time.hour(), minute.toInt(), 00 ); |
293 | setTime ( m_time ); | 290 | setTime ( m_time ); |
294 | } | 291 | } |
295 | } | 292 | } |
diff --git a/libopie2/opieui/oversatileview.cpp b/libopie2/opieui/oversatileview.cpp index 65fe3d8..8839456 100644 --- a/libopie2/opieui/oversatileview.cpp +++ b/libopie2/opieui/oversatileview.cpp | |||
@@ -1,1180 +1,1169 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 4 | =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | /* OPIE */ | 31 | /* OPIE */ |
32 | 32 | ||
33 | #include <opie2/odebug.h> | 33 | #include <opie2/odebug.h> |
34 | #include <opie2/oversatileview.h> | 34 | #include <opie2/oversatileview.h> |
35 | #include <opie2/oversatileviewitem.h> | 35 | #include <opie2/oversatileviewitem.h> |
36 | #include <opie2/olistview.h> | 36 | #include <opie2/olistview.h> |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | 39 | ||
40 | #include <qaction.h> | 40 | #include <qaction.h> |
41 | #include <qbrush.h> | ||
42 | #include <qfont.h> | ||
43 | #include <qiconset.h> | ||
44 | #include <qiconview.h> | ||
45 | #include <qlistview.h> | ||
46 | #include <qpalette.h> | ||
47 | #include <qpoint.h> | ||
48 | #include <qpopupmenu.h> | 41 | #include <qpopupmenu.h> |
49 | #include <qrect.h> | ||
50 | #include <qsize.h> | ||
51 | #include <qstring.h> | ||
52 | #include <qwidgetstack.h> | ||
53 | 42 | ||
54 | /* XPM */ | 43 | /* XPM */ |
55 | static const char * view_icon_xpm[] = { | 44 | static const char * view_icon_xpm[] = { |
56 | "16 16 16 1", | 45 | "16 16 16 1", |
57 | " c None", | 46 | " c None", |
58 | ".c #87BD88", | 47 | ".c #87BD88", |
59 | "+c #8BBE8B", | 48 | "+c #8BBE8B", |
60 | "@c #81BA81", | 49 | "@c #81BA81", |
61 | "#c #6DAF6D", | 50 | "#c #6DAF6D", |
62 | "$c #87BD87", | 51 | "$c #87BD87", |
63 | "%c #FCFDFC", | 52 | "%c #FCFDFC", |
64 | "&c #AED0AE", | 53 | "&c #AED0AE", |
65 | "*c #4E9C4C", | 54 | "*c #4E9C4C", |
66 | "=c #91BD91", | 55 | "=c #91BD91", |
67 | "-c #72B172", | 56 | "-c #72B172", |
68 | ";c #448643", | 57 | ";c #448643", |
69 | ">c #519F50", | 58 | ">c #519F50", |
70 | ",c #499247", | 59 | ",c #499247", |
71 | "'c #356A35", | 60 | "'c #356A35", |
72 | ")c #686868", | 61 | ")c #686868", |
73 | " ", | 62 | " ", |
74 | " .+@# .+@# ", | 63 | " .+@# .+@# ", |
75 | " $%&* $%&* ", | 64 | " $%&* $%&* ", |
76 | " @=-; @=-; ", | 65 | " @=-; @=-; ", |
77 | " #>,' #>,' ", | 66 | " #>,' #>,' ", |
78 | " ", | 67 | " ", |
79 | " )))))) )))))) ", | 68 | " )))))) )))))) ", |
80 | " ", | 69 | " ", |
81 | " ", | 70 | " ", |
82 | " .+@# .+@# ", | 71 | " .+@# .+@# ", |
83 | " $%&* $%&* ", | 72 | " $%&* $%&* ", |
84 | " @=-; @=-; ", | 73 | " @=-; @=-; ", |
85 | " #>,' #>,' ", | 74 | " #>,' #>,' ", |
86 | " ", | 75 | " ", |
87 | " )))))) )))))) ", | 76 | " )))))) )))))) ", |
88 | " "}; | 77 | " "}; |
89 | 78 | ||
90 | /* XPM */ | 79 | /* XPM */ |
91 | static const char * view_tree_xpm[] = { | 80 | static const char * view_tree_xpm[] = { |
92 | "16 16 17 1", | 81 | "16 16 17 1", |
93 | " c None", | 82 | " c None", |
94 | ".c #3A3A3A", | 83 | ".c #3A3A3A", |
95 | "+c #87BD88", | 84 | "+c #87BD88", |
96 | "@c #8BBE8B", | 85 | "@c #8BBE8B", |
97 | "#c #81BA81", | 86 | "#c #81BA81", |
98 | "$c #6DAF6D", | 87 | "$c #6DAF6D", |
99 | "%c #87BD87", | 88 | "%c #87BD87", |
100 | "&c #FCFDFC", | 89 | "&c #FCFDFC", |
101 | "*c #AED0AE", | 90 | "*c #AED0AE", |
102 | "=c #4E9C4C", | 91 | "=c #4E9C4C", |
103 | "-c #91BD91", | 92 | "-c #91BD91", |
104 | ";c #72B172", | 93 | ";c #72B172", |
105 | ">c #448643", | 94 | ">c #448643", |
106 | ",c #686868", | 95 | ",c #686868", |
107 | "'c #519F50", | 96 | "'c #519F50", |
108 | ")c #499247", | 97 | ")c #499247", |
109 | "!c #356A35", | 98 | "!c #356A35", |
110 | " . ", | 99 | " . ", |
111 | " . ", | 100 | " . ", |
112 | " . +@#$ ", | 101 | " . +@#$ ", |
113 | " . %&*= ", | 102 | " . %&*= ", |
114 | " .. #-;> ,, ,,,", | 103 | " .. #-;> ,, ,,,", |
115 | " . $')! ", | 104 | " . $')! ", |
116 | " . ", | 105 | " . ", |
117 | " . ", | 106 | " . ", |
118 | " . ", | 107 | " . ", |
119 | " . +@#$ ", | 108 | " . +@#$ ", |
120 | " . %&*= ", | 109 | " . %&*= ", |
121 | " .. #-;> ,, ,,,", | 110 | " .. #-;> ,, ,,,", |
122 | " $')! ", | 111 | " $')! ", |
123 | " ", | 112 | " ", |
124 | " ", | 113 | " ", |
125 | " "}; | 114 | " "}; |
126 | 115 | ||
127 | OVersatileView::OVersatileView( QWidget* parent, const char* name, int mode ) | 116 | OVersatileView::OVersatileView( QWidget* parent, const char* name, int mode ) |
128 | :QWidgetStack( parent, name ), | 117 | :QWidgetStack( parent, name ), |
129 | _viewmode( mode ), _warningpolicy( None ), | 118 | _viewmode( mode ), _warningpolicy( None ), |
130 | _treeleaf(), _treeopened(), _treeclosed(), | 119 | _treeleaf(), _treeopened(), _treeclosed(), |
131 | _iconleaf(), _iconopened(), _iconclosed() | 120 | _iconleaf(), _iconopened(), _iconclosed() |
132 | { | 121 | { |
133 | // | 122 | // |
134 | // Create child widgets and set some reasonable default styles | 123 | // Create child widgets and set some reasonable default styles |
135 | // | 124 | // |
136 | 125 | ||
137 | _listview = new OListView( this, "oversatileview embedded listview" ); | 126 | _listview = new OListView( this, "oversatileview embedded listview" ); |
138 | _iconview = new QIconView( this, "oversatileview embedded iconview" ); | 127 | _iconview = new QIconView( this, "oversatileview embedded iconview" ); |
139 | 128 | ||
140 | _listview->setAllColumnsShowFocus( true ); | 129 | _listview->setAllColumnsShowFocus( true ); |
141 | _listview->setRootIsDecorated( true ); | 130 | _listview->setRootIsDecorated( true ); |
142 | _listview->setShowSortIndicator( true ); | 131 | _listview->setShowSortIndicator( true ); |
143 | _iconview->setGridX( 90 ); | 132 | _iconview->setGridX( 90 ); |
144 | _iconview->setGridY( 42 ); | 133 | _iconview->setGridY( 42 ); |
145 | _iconview->setAutoArrange( true ); | 134 | _iconview->setAutoArrange( true ); |
146 | 135 | ||
147 | #ifdef QWS // TODO: Let this depend on current geometry (rotation) | 136 | #ifdef QWS // TODO: Let this depend on current geometry (rotation) |
148 | _iconview->setArrangement( QIconView::TopToBottom ); | 137 | _iconview->setArrangement( QIconView::TopToBottom ); |
149 | #else | 138 | #else |
150 | _iconview->setArrangement( QIconView::LeftToRight ); | 139 | _iconview->setArrangement( QIconView::LeftToRight ); |
151 | #endif | 140 | #endif |
152 | 141 | ||
153 | _iconview->setResizeMode( QIconView::Adjust ); | 142 | _iconview->setResizeMode( QIconView::Adjust ); |
154 | 143 | ||
155 | // qt-embedded: map stylus right on hold to right button press | 144 | // qt-embedded: map stylus right on hold to right button press |
156 | 145 | ||
157 | #ifdef QWS | 146 | #ifdef QWS |
158 | ( (QPEApplication*) qApp)->setStylusOperation( _iconview->viewport(), QPEApplication::RightOnHold ); | 147 | ( (QPEApplication*) qApp)->setStylusOperation( _iconview->viewport(), QPEApplication::RightOnHold ); |
159 | ( (QPEApplication*) qApp)->setStylusOperation( _listview->viewport(), QPEApplication::RightOnHold ); | 148 | ( (QPEApplication*) qApp)->setStylusOperation( _listview->viewport(), QPEApplication::RightOnHold ); |
160 | #endif | 149 | #endif |
161 | 150 | ||
162 | setViewMode( mode ); // TODO: Read last style from config | 151 | setViewMode( mode ); // TODO: Read last style from config |
163 | // setSynchronization( true ); // TODO: Implement this | 152 | // setSynchronization( true ); // TODO: Implement this |
164 | 153 | ||
165 | // create context menu allowing to switch between the views | 154 | // create context menu allowing to switch between the views |
166 | 155 | ||
167 | _contextmenu = new QPopupMenu( 0, "oversatileview contextmenu" ); | 156 | _contextmenu = new QPopupMenu( 0, "oversatileview contextmenu" ); |
168 | _contextmenu->setCaption( "Style" ); | 157 | _contextmenu->setCaption( "Style" ); |
169 | _contextmenu->setCheckable( true ); | 158 | _contextmenu->setCheckable( true ); |
170 | QActionGroup* ag = new QActionGroup( _contextmenu, "style option group" ); | 159 | QActionGroup* ag = new QActionGroup( _contextmenu, "style option group" ); |
171 | QAction* a1 = new QAction( "View Items in Icon Style", QIconSet( QPixmap( view_icon_xpm ) ), | 160 | QAction* a1 = new QAction( "View Items in Icon Style", QIconSet( QPixmap( view_icon_xpm ) ), |
172 | "View Icons", 0, ag, "viewicon action", true ); | 161 | "View Icons", 0, ag, "viewicon action", true ); |
173 | QAction* a2 = new QAction( "View Items in Tree Style", QIconSet( QPixmap( view_tree_xpm ) ), | 162 | QAction* a2 = new QAction( "View Items in Tree Style", QIconSet( QPixmap( view_tree_xpm ) ), |
174 | "View Tree", 0, ag, "viewtree action", true ); | 163 | "View Tree", 0, ag, "viewtree action", true ); |
175 | ag->addTo( _contextmenu ); | 164 | ag->addTo( _contextmenu ); |
176 | if ( mode == Icons ) | 165 | if ( mode == Icons ) |
177 | a1->setOn( true ); | 166 | a1->setOn( true ); |
178 | else if ( mode == Tree ) | 167 | else if ( mode == Tree ) |
179 | a2->setOn( true ); | 168 | a2->setOn( true ); |
180 | connect( a1, SIGNAL( activated() ), this, SLOT( setIconViewMode() ) ); | 169 | connect( a1, SIGNAL( activated() ), this, SLOT( setIconViewMode() ) ); |
181 | connect( a2, SIGNAL( activated() ), this, SLOT( setTreeViewMode() ) ); | 170 | connect( a2, SIGNAL( activated() ), this, SLOT( setTreeViewMode() ) ); |
182 | 171 | ||
183 | #if (QT_VERSION >= 0x030000) | 172 | #if (QT_VERSION >= 0x030000) |
184 | connect( _listview, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ), this, SLOT( contextMenuRequested( QListViewItem*, const QPoint&, int ) ) ); | 173 | connect( _listview, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ), this, SLOT( contextMenuRequested( QListViewItem*, const QPoint&, int ) ) ); |
185 | connect( _iconview, SIGNAL( contextMenuRequested( QIconViewItem*, const QPoint& ) ), this, SLOT( contextMenuRequested( QIconViewItem*, const QPoint& ) ) ); | 174 | connect( _iconview, SIGNAL( contextMenuRequested( QIconViewItem*, const QPoint& ) ), this, SLOT( contextMenuRequested( QIconViewItem*, const QPoint& ) ) ); |
186 | #else | 175 | #else |
187 | connect( _listview, SIGNAL( rightButtonPressed( QListViewItem*, const QPoint&, int ) ), this, SLOT( contextMenuRequested( QListViewItem*, const QPoint&, int ) ) ); | 176 | connect( _listview, SIGNAL( rightButtonPressed( QListViewItem*, const QPoint&, int ) ), this, SLOT( contextMenuRequested( QListViewItem*, const QPoint&, int ) ) ); |
188 | connect( _iconview, SIGNAL( rightButtonPressed( QIconViewItem*, const QPoint& ) ), this, SLOT( contextMenuRequested( QIconViewItem*, const QPoint& ) ) ); | 177 | connect( _iconview, SIGNAL( rightButtonPressed( QIconViewItem*, const QPoint& ) ), this, SLOT( contextMenuRequested( QIconViewItem*, const QPoint& ) ) ); |
189 | #endif | 178 | #endif |
190 | 179 | ||
191 | // | 180 | // |
192 | // signal forwarders | 181 | // signal forwarders |
193 | // | 182 | // |
194 | // unfortunately we can't short-circuit all the QListView and QIconView signals | 183 | // unfortunately we can't short-circuit all the QListView and QIconView signals |
195 | // to OVersatileView signals, because the signal/slot mechanism doesn't allow | 184 | // to OVersatileView signals, because the signal/slot mechanism doesn't allow |
196 | // type-conversion :-( | 185 | // type-conversion :-( |
197 | 186 | ||
198 | // common signals for listview | 187 | // common signals for listview |
199 | 188 | ||
200 | connect( _listview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); | 189 | connect( _listview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); |
201 | connect( _listview, SIGNAL( selectionChanged( QListViewItem * ) ), this, SLOT( selectionChanged( QListViewItem * ) ) ); | 190 | connect( _listview, SIGNAL( selectionChanged( QListViewItem * ) ), this, SLOT( selectionChanged( QListViewItem * ) ) ); |
202 | connect( _listview, SIGNAL( currentChanged( QListViewItem * ) ), this, SLOT( currentChanged( QListViewItem * ) ) ); | 191 | connect( _listview, SIGNAL( currentChanged( QListViewItem * ) ), this, SLOT( currentChanged( QListViewItem * ) ) ); |
203 | connect( _listview, SIGNAL( clicked( QListViewItem * ) ), this, SLOT( clicked( QListViewItem * ) ) ); | 192 | connect( _listview, SIGNAL( clicked( QListViewItem * ) ), this, SLOT( clicked( QListViewItem * ) ) ); |
204 | connect( _listview, SIGNAL( pressed( QListViewItem * ) ), this, SLOT( pressed( QListViewItem * ) ) ); | 193 | connect( _listview, SIGNAL( pressed( QListViewItem * ) ), this, SLOT( pressed( QListViewItem * ) ) ); |
205 | 194 | ||
206 | connect( _listview, SIGNAL( doubleClicked( QListViewItem * ) ), this, SLOT( doubleClicked( QListViewItem * ) ) ); | 195 | connect( _listview, SIGNAL( doubleClicked( QListViewItem * ) ), this, SLOT( doubleClicked( QListViewItem * ) ) ); |
207 | connect( _listview, SIGNAL( returnPressed( QListViewItem * ) ), this, SLOT( returnPressed( QListViewItem * ) ) ); | 196 | connect( _listview, SIGNAL( returnPressed( QListViewItem * ) ), this, SLOT( returnPressed( QListViewItem * ) ) ); |
208 | 197 | ||
209 | connect( _listview, SIGNAL( onItem( QListViewItem * ) ), this, SLOT( onItem( QListViewItem * ) ) ); | 198 | connect( _listview, SIGNAL( onItem( QListViewItem * ) ), this, SLOT( onItem( QListViewItem * ) ) ); |
210 | connect( _listview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) ); | 199 | connect( _listview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) ); |
211 | 200 | ||
212 | // common signals for iconview | 201 | // common signals for iconview |
213 | 202 | ||
214 | connect( _iconview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); | 203 | connect( _iconview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); |
215 | connect( _iconview, SIGNAL( selectionChanged( QIconViewItem * ) ), this, SLOT( selectionChanged( QIconViewItem * ) ) ); | 204 | connect( _iconview, SIGNAL( selectionChanged( QIconViewItem * ) ), this, SLOT( selectionChanged( QIconViewItem * ) ) ); |
216 | connect( _iconview, SIGNAL( currentChanged( QIconViewItem * ) ), this, SLOT( currentChanged( QIconViewItem * ) ) ); | 205 | connect( _iconview, SIGNAL( currentChanged( QIconViewItem * ) ), this, SLOT( currentChanged( QIconViewItem * ) ) ); |
217 | connect( _iconview, SIGNAL( clicked( QIconViewItem * ) ), this, SLOT( clicked( QIconViewItem * ) ) ); | 206 | connect( _iconview, SIGNAL( clicked( QIconViewItem * ) ), this, SLOT( clicked( QIconViewItem * ) ) ); |
218 | connect( _iconview, SIGNAL( pressed( QIconViewItem * ) ), this, SLOT( pressed( QIconViewItem * ) ) ); | 207 | connect( _iconview, SIGNAL( pressed( QIconViewItem * ) ), this, SLOT( pressed( QIconViewItem * ) ) ); |
219 | 208 | ||
220 | connect( _iconview, SIGNAL( doubleClicked( QIconViewItem * ) ), this, SLOT( doubleClicked( QIconViewItem * ) ) ); | 209 | connect( _iconview, SIGNAL( doubleClicked( QIconViewItem * ) ), this, SLOT( doubleClicked( QIconViewItem * ) ) ); |
221 | connect( _iconview, SIGNAL( returnPressed( QIconViewItem * ) ), this, SLOT( returnPressed( QIconViewItem * ) ) ); | 210 | connect( _iconview, SIGNAL( returnPressed( QIconViewItem * ) ), this, SLOT( returnPressed( QIconViewItem * ) ) ); |
222 | 211 | ||
223 | connect( _iconview, SIGNAL( onItem( QIconViewItem * ) ), this, SLOT( onItem( QIconViewItem * ) ) ); | 212 | connect( _iconview, SIGNAL( onItem( QIconViewItem * ) ), this, SLOT( onItem( QIconViewItem * ) ) ); |
224 | connect( _iconview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) ); | 213 | connect( _iconview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) ); |
225 | 214 | ||
226 | // listview only signals | 215 | // listview only signals |
227 | 216 | ||
228 | connect( _listview, SIGNAL( expanded( QListViewItem * ) ), this, SLOT( expanded( QListViewItem * ) ) ); | 217 | connect( _listview, SIGNAL( expanded( QListViewItem * ) ), this, SLOT( expanded( QListViewItem * ) ) ); |
229 | connect( _listview, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( collapsed( QListViewItem * ) ) ); | 218 | connect( _listview, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( collapsed( QListViewItem * ) ) ); |
230 | 219 | ||
231 | // iconview only signals | 220 | // iconview only signals |
232 | 221 | ||
233 | connect( _iconview, SIGNAL( moved() ), this, SIGNAL( moved() ) ); | 222 | connect( _iconview, SIGNAL( moved() ), this, SIGNAL( moved() ) ); |
234 | } | 223 | } |
235 | 224 | ||
236 | OVersatileView::~OVersatileView() | 225 | OVersatileView::~OVersatileView() |
237 | { | 226 | { |
238 | } | 227 | } |
239 | 228 | ||
240 | QPopupMenu* OVersatileView::contextMenu() const | 229 | QPopupMenu* OVersatileView::contextMenu() const |
241 | { | 230 | { |
242 | return _contextmenu; | 231 | return _contextmenu; |
243 | } | 232 | } |
244 | 233 | ||
245 | void OVersatileView::contextMenuRequested( QListViewItem* item, const QPoint& pos, int col ) | 234 | void OVersatileView::contextMenuRequested( QListViewItem* item, const QPoint& pos, int col ) |
246 | { | 235 | { |
247 | // can't use QObject::inherits here, because ListViewItems, beit Q, O or K, | 236 | // can't use QObject::inherits here, because ListViewItems, beit Q, O or K, |
248 | // do not inherit from QObject - assuming here the programmer is | 237 | // do not inherit from QObject - assuming here the programmer is |
249 | // disciplined enough to only add OVersatileViewItems to an OVersatileView | 238 | // disciplined enough to only add OVersatileViewItems to an OVersatileView |
250 | popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, col ); | 239 | popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, col ); |
251 | } | 240 | } |
252 | 241 | ||
253 | void OVersatileView::contextMenuRequested( QIconViewItem* item, const QPoint& pos ) | 242 | void OVersatileView::contextMenuRequested( QIconViewItem* item, const QPoint& pos ) |
254 | { | 243 | { |
255 | // see above | 244 | // see above |
256 | popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, -1 ); | 245 | popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, -1 ); |
257 | } | 246 | } |
258 | 247 | ||
259 | void OVersatileView::popupContextMenu( OVersatileViewItem* item, const QPoint& pos, int col ) | 248 | void OVersatileView::popupContextMenu( OVersatileViewItem* item, const QPoint& pos, int col ) |
260 | { | 249 | { |
261 | if ( !item ) | 250 | if ( !item ) |
262 | _contextmenu->exec( pos ); | 251 | _contextmenu->exec( pos ); |
263 | else | 252 | else |
264 | emit( contextMenuRequested( item, pos, col ) ); | 253 | emit( contextMenuRequested( item, pos, col ) ); |
265 | } | 254 | } |
266 | 255 | ||
267 | void OVersatileView::setSynchronization( bool sync ) | 256 | void OVersatileView::setSynchronization( bool sync ) |
268 | { | 257 | { |
269 | _synchronization = sync; | 258 | _synchronization = sync; |
270 | } | 259 | } |
271 | 260 | ||
272 | bool OVersatileView::synchronization() | 261 | bool OVersatileView::synchronization() |
273 | { | 262 | { |
274 | return _synchronization; | 263 | return _synchronization; |
275 | } | 264 | } |
276 | 265 | ||
277 | void OVersatileView::setDefaultPixmaps( int mode, QPixmap& leaf, QPixmap& opened, QPixmap& closed ) | 266 | void OVersatileView::setDefaultPixmaps( int mode, QPixmap& leaf, QPixmap& opened, QPixmap& closed ) |
278 | { | 267 | { |
279 | if ( mode == Tree ) | 268 | if ( mode == Tree ) |
280 | { | 269 | { |
281 | _treeleaf = leaf; | 270 | _treeleaf = leaf; |
282 | _treeopened = opened; | 271 | _treeopened = opened; |
283 | _treeclosed = closed; | 272 | _treeclosed = closed; |
284 | } | 273 | } |
285 | else if ( mode == Icons ) | 274 | else if ( mode == Icons ) |
286 | { | 275 | { |
287 | _iconleaf = leaf; | 276 | _iconleaf = leaf; |
288 | _iconopened = opened; | 277 | _iconopened = opened; |
289 | _iconclosed = closed; | 278 | _iconclosed = closed; |
290 | } | 279 | } |
291 | else | 280 | else |
292 | { | 281 | { |
293 | odebug << "OVersatileView::setDefaultPixmaps(): invalid mode" << oendl; | 282 | odebug << "OVersatileView::setDefaultPixmaps(): invalid mode" << oendl; |
294 | } | 283 | } |
295 | } | 284 | } |
296 | 285 | ||
297 | QIconView* OVersatileView::iconView() const | 286 | QIconView* OVersatileView::iconView() const |
298 | { | 287 | { |
299 | return _iconview; | 288 | return _iconview; |
300 | } | 289 | } |
301 | 290 | ||
302 | OListView* OVersatileView::listView() const | 291 | OListView* OVersatileView::listView() const |
303 | { | 292 | { |
304 | return _listview; | 293 | return _listview; |
305 | } | 294 | } |
306 | 295 | ||
307 | void OVersatileView::setViewMode( int mode ) | 296 | void OVersatileView::setViewMode( int mode ) |
308 | { | 297 | { |
309 | if ( mode == Tree ) | 298 | if ( mode == Tree ) |
310 | { | 299 | { |
311 | _viewmode = mode; | 300 | _viewmode = mode; |
312 | raiseWidget( _listview ); | 301 | raiseWidget( _listview ); |
313 | } | 302 | } |
314 | else if ( mode == Icons ) | 303 | else if ( mode == Icons ) |
315 | { | 304 | { |
316 | _viewmode = mode; | 305 | _viewmode = mode; |
317 | raiseWidget( _iconview ); | 306 | raiseWidget( _iconview ); |
318 | } | 307 | } |
319 | else | 308 | else |
320 | { | 309 | { |
321 | odebug << "OVersatileView::setViewMode(): invalid mode" << oendl; | 310 | odebug << "OVersatileView::setViewMode(): invalid mode" << oendl; |
322 | } | 311 | } |
323 | } | 312 | } |
324 | 313 | ||
325 | void OVersatileView::setIconViewMode() | 314 | void OVersatileView::setIconViewMode() |
326 | { | 315 | { |
327 | setViewMode( Icons ); | 316 | setViewMode( Icons ); |
328 | } | 317 | } |
329 | 318 | ||
330 | void OVersatileView::setTreeViewMode() | 319 | void OVersatileView::setTreeViewMode() |
331 | { | 320 | { |
332 | setViewMode( Tree ); | 321 | setViewMode( Tree ); |
333 | } | 322 | } |
334 | 323 | ||
335 | bool OVersatileView::isValidViewMode( int mode ) const | 324 | bool OVersatileView::isValidViewMode( int mode ) const |
336 | { | 325 | { |
337 | switch ( _warningpolicy ) | 326 | switch ( _warningpolicy ) |
338 | { | 327 | { |
339 | case OVersatileView::None: | 328 | case OVersatileView::None: |
340 | { | 329 | { |
341 | return true; | 330 | return true; |
342 | } | 331 | } |
343 | case OVersatileView::Warn: | 332 | case OVersatileView::Warn: |
344 | { | 333 | { |
345 | if ( _viewmode != mode ) | 334 | if ( _viewmode != mode ) |
346 | { | 335 | { |
347 | odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl; | 336 | odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl; |
348 | return true; | 337 | return true; |
349 | } | 338 | } |
350 | } | 339 | } |
351 | case OVersatileView::WarnReturn: | 340 | case OVersatileView::WarnReturn: |
352 | { | 341 | { |
353 | if ( _viewmode != mode ) | 342 | if ( _viewmode != mode ) |
354 | { | 343 | { |
355 | odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl; | 344 | odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl; |
356 | return false; | 345 | return false; |
357 | } | 346 | } |
358 | } | 347 | } |
359 | default: | 348 | default: |
360 | { | 349 | { |
361 | owarn << "OVersatileView::isValidViewMode(): Inconsistent object state!" << oendl; | 350 | owarn << "OVersatileView::isValidViewMode(): Inconsistent object state!" << oendl; |
362 | return true; | 351 | return true; |
363 | } | 352 | } |
364 | } | 353 | } |
365 | } | 354 | } |
366 | void OVersatileView::setWarningPolicy( int policy ) const | 355 | void OVersatileView::setWarningPolicy( int policy ) const |
367 | { | 356 | { |
368 | _warningpolicy = policy; | 357 | _warningpolicy = policy; |
369 | } | 358 | } |
370 | bool OVersatileView::warningPolicy() const | 359 | bool OVersatileView::warningPolicy() const |
371 | { | 360 | { |
372 | return _warningpolicy; | 361 | return _warningpolicy; |
373 | } | 362 | } |
374 | //==============================================================================================// | 363 | //==============================================================================================// |
375 | // Stupid Signal forwarders... | 364 | // Stupid Signal forwarders... |
376 | // Folks, this is why I like python with its dynamic typing: | 365 | // Folks, this is why I like python with its dynamic typing: |
377 | // I can code the following dozens of lines C++ in four Python lines... | 366 | // I can code the following dozens of lines C++ in four Python lines... |
378 | //==============================================================================================// | 367 | //==============================================================================================// |
379 | 368 | ||
380 | void OVersatileView::selectionChanged( QListViewItem * item ) | 369 | void OVersatileView::selectionChanged( QListViewItem * item ) |
381 | { | 370 | { |
382 | emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) ); | 371 | emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) ); |
383 | } | 372 | } |
384 | 373 | ||
385 | void OVersatileView::selectionChanged( QIconViewItem * item ) | 374 | void OVersatileView::selectionChanged( QIconViewItem * item ) |
386 | { | 375 | { |
387 | emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) ); | 376 | emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) ); |
388 | } | 377 | } |
389 | 378 | ||
390 | void OVersatileView::currentChanged( QListViewItem * item ) | 379 | void OVersatileView::currentChanged( QListViewItem * item ) |
391 | { | 380 | { |
392 | emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) ); | 381 | emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) ); |
393 | } | 382 | } |
394 | 383 | ||
395 | void OVersatileView::currentChanged( QIconViewItem * item ) | 384 | void OVersatileView::currentChanged( QIconViewItem * item ) |
396 | { | 385 | { |
397 | emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) ); | 386 | emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) ); |
398 | } | 387 | } |
399 | 388 | ||
400 | void OVersatileView::clicked( QListViewItem * item ) | 389 | void OVersatileView::clicked( QListViewItem * item ) |
401 | { | 390 | { |
402 | emit( clicked( static_cast<OVersatileViewItem*>( item ) ) ); | 391 | emit( clicked( static_cast<OVersatileViewItem*>( item ) ) ); |
403 | } | 392 | } |
404 | 393 | ||
405 | void OVersatileView::clicked( QIconViewItem * item ) | 394 | void OVersatileView::clicked( QIconViewItem * item ) |
406 | { | 395 | { |
407 | emit( clicked( static_cast<OVersatileViewItem*>( item ) ) ); | 396 | emit( clicked( static_cast<OVersatileViewItem*>( item ) ) ); |
408 | } | 397 | } |
409 | 398 | ||
410 | void OVersatileView::pressed( QListViewItem * item ) | 399 | void OVersatileView::pressed( QListViewItem * item ) |
411 | { | 400 | { |
412 | emit( pressed( static_cast<OVersatileViewItem*>( item ) ) ); | 401 | emit( pressed( static_cast<OVersatileViewItem*>( item ) ) ); |
413 | } | 402 | } |
414 | 403 | ||
415 | void OVersatileView::pressed( QIconViewItem * item ) | 404 | void OVersatileView::pressed( QIconViewItem * item ) |
416 | { | 405 | { |
417 | emit( pressed( static_cast<OVersatileViewItem*>( item ) ) ); | 406 | emit( pressed( static_cast<OVersatileViewItem*>( item ) ) ); |
418 | } | 407 | } |
419 | 408 | ||
420 | void OVersatileView::doubleClicked( QListViewItem * item ) | 409 | void OVersatileView::doubleClicked( QListViewItem * item ) |
421 | { | 410 | { |
422 | emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) ); | 411 | emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) ); |
423 | } | 412 | } |
424 | 413 | ||
425 | void OVersatileView::doubleClicked( QIconViewItem * item ) | 414 | void OVersatileView::doubleClicked( QIconViewItem * item ) |
426 | { | 415 | { |
427 | emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) ); | 416 | emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) ); |
428 | } | 417 | } |
429 | 418 | ||
430 | void OVersatileView::returnPressed( QListViewItem * item ) | 419 | void OVersatileView::returnPressed( QListViewItem * item ) |
431 | { | 420 | { |
432 | emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) ); | 421 | emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) ); |
433 | } | 422 | } |
434 | 423 | ||
435 | void OVersatileView::returnPressed( QIconViewItem * item ) | 424 | void OVersatileView::returnPressed( QIconViewItem * item ) |
436 | { | 425 | { |
437 | emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) ); | 426 | emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) ); |
438 | } | 427 | } |
439 | 428 | ||
440 | void OVersatileView::onItem( QListViewItem * item ) | 429 | void OVersatileView::onItem( QListViewItem * item ) |
441 | { | 430 | { |
442 | emit( onItem( static_cast<OVersatileViewItem*>( item ) ) ); | 431 | emit( onItem( static_cast<OVersatileViewItem*>( item ) ) ); |
443 | } | 432 | } |
444 | 433 | ||
445 | void OVersatileView::onItem( QIconViewItem * item ) | 434 | void OVersatileView::onItem( QIconViewItem * item ) |
446 | { | 435 | { |
447 | emit( onItem( static_cast<OVersatileViewItem*>( item ) ) ); | 436 | emit( onItem( static_cast<OVersatileViewItem*>( item ) ) ); |
448 | } | 437 | } |
449 | 438 | ||
450 | void OVersatileView::expanded( QListViewItem *item ) // QListView | 439 | void OVersatileView::expanded( QListViewItem *item ) // QListView |
451 | { | 440 | { |
452 | //odebug << "OVersatileView::expanded(): opening tree..." << oendl; | 441 | //odebug << "OVersatileView::expanded(): opening tree..." << oendl; |
453 | if ( !_treeopened.isNull() ) | 442 | if ( !_treeopened.isNull() ) |
454 | item->setPixmap( 0, _treeopened ); | 443 | item->setPixmap( 0, _treeopened ); |
455 | emit( expanded( static_cast<OVersatileViewItem*>( item ) ) ); | 444 | emit( expanded( static_cast<OVersatileViewItem*>( item ) ) ); |
456 | } | 445 | } |
457 | void OVersatileView::collapsed( QListViewItem *item ) // QListView | 446 | void OVersatileView::collapsed( QListViewItem *item ) // QListView |
458 | { | 447 | { |
459 | if ( !_treeclosed.isNull() ) | 448 | if ( !_treeclosed.isNull() ) |
460 | item->setPixmap( 0, _treeclosed ); | 449 | item->setPixmap( 0, _treeclosed ); |
461 | emit( collapsed( static_cast<OVersatileViewItem*>( item ) ) ); | 450 | emit( collapsed( static_cast<OVersatileViewItem*>( item ) ) ); |
462 | } | 451 | } |
463 | 452 | ||
464 | //=============================================================================================// | 453 | //=============================================================================================// |
465 | // OVersatileView Case I - API only existing in QListView or QIconView but not in both! | 454 | // OVersatileView Case I - API only existing in QListView or QIconView but not in both! |
466 | //==============================================================================================// | 455 | //==============================================================================================// |
467 | 456 | ||
468 | int OVersatileView::treeStepSize() const // QListView | 457 | int OVersatileView::treeStepSize() const // QListView |
469 | { | 458 | { |
470 | if ( !isValidViewMode( Tree ) ) | 459 | if ( !isValidViewMode( Tree ) ) |
471 | { | 460 | { |
472 | return -1; | 461 | return -1; |
473 | } | 462 | } |
474 | return _listview->treeStepSize(); | 463 | return _listview->treeStepSize(); |
475 | } | 464 | } |
476 | void OVersatileView::setTreeStepSize( int size ) // QListView | 465 | void OVersatileView::setTreeStepSize( int size ) // QListView |
477 | { | 466 | { |
478 | if ( !isValidViewMode( Tree ) ) | 467 | if ( !isValidViewMode( Tree ) ) |
479 | { | 468 | { |
480 | return; | 469 | return; |
481 | } | 470 | } |
482 | _listview->setTreeStepSize( size ); | 471 | _listview->setTreeStepSize( size ); |
483 | } | 472 | } |
484 | 473 | ||
485 | QHeader * OVersatileView::header() const // QListView | 474 | QHeader * OVersatileView::header() const // QListView |
486 | { | 475 | { |
487 | if ( !isValidViewMode( Tree ) ) | 476 | if ( !isValidViewMode( Tree ) ) |
488 | { | 477 | { |
489 | return 0; | 478 | return 0; |
490 | } | 479 | } |
491 | return _listview->header(); | 480 | return _listview->header(); |
492 | } | 481 | } |
493 | 482 | ||
494 | int OVersatileView::addColumn( const QString &label, int size ) // QListView | 483 | int OVersatileView::addColumn( const QString &label, int size ) // QListView |
495 | { | 484 | { |
496 | if ( !isValidViewMode( Tree ) ) | 485 | if ( !isValidViewMode( Tree ) ) |
497 | { | 486 | { |
498 | return -1; | 487 | return -1; |
499 | } | 488 | } |
500 | return _listview->addColumn( label, size ); | 489 | return _listview->addColumn( label, size ); |
501 | } | 490 | } |
502 | 491 | ||
503 | int OVersatileView::addColumn( const QIconSet& iconset, const QString &label, int size ) // QListView | 492 | int OVersatileView::addColumn( const QIconSet& iconset, const QString &label, int size ) // QListView |
504 | { | 493 | { |
505 | if ( !isValidViewMode( Tree ) ) | 494 | if ( !isValidViewMode( Tree ) ) |
506 | { | 495 | { |
507 | return -1; | 496 | return -1; |
508 | } | 497 | } |
509 | return _listview->addColumn( iconset, label, size ); | 498 | return _listview->addColumn( iconset, label, size ); |
510 | } | 499 | } |
511 | 500 | ||
512 | void OVersatileView::removeColumn( int index ) // QListView | 501 | void OVersatileView::removeColumn( int index ) // QListView |
513 | { | 502 | { |
514 | if ( !isValidViewMode( Tree ) ) | 503 | if ( !isValidViewMode( Tree ) ) |
515 | { | 504 | { |
516 | return; | 505 | return; |
517 | } | 506 | } |
518 | _listview->removeColumn( index ); | 507 | _listview->removeColumn( index ); |
519 | } | 508 | } |
520 | void OVersatileView::setColumnText( int column, const QString &label ) // QListView | 509 | void OVersatileView::setColumnText( int column, const QString &label ) // QListView |
521 | { | 510 | { |
522 | if ( !isValidViewMode( Tree ) ) | 511 | if ( !isValidViewMode( Tree ) ) |
523 | { | 512 | { |
524 | return; | 513 | return; |
525 | } | 514 | } |
526 | _listview->setColumnText( column, label ); | 515 | _listview->setColumnText( column, label ); |
527 | } | 516 | } |
528 | void OVersatileView::setColumnText( int column, const QIconSet& iconset, const QString &label ) // QListView | 517 | void OVersatileView::setColumnText( int column, const QIconSet& iconset, const QString &label ) // QListView |
529 | { | 518 | { |
530 | if ( !isValidViewMode( Tree ) ) | 519 | if ( !isValidViewMode( Tree ) ) |
531 | { | 520 | { |
532 | return; | 521 | return; |
533 | } | 522 | } |
534 | _listview->setColumnText( column, iconset, label ); | 523 | _listview->setColumnText( column, iconset, label ); |
535 | } | 524 | } |
536 | QString OVersatileView::columnText( int column ) const // QListView | 525 | QString OVersatileView::columnText( int column ) const // QListView |
537 | { | 526 | { |
538 | if ( !isValidViewMode( Tree ) ) | 527 | if ( !isValidViewMode( Tree ) ) |
539 | { | 528 | { |
540 | return QString::null; | 529 | return QString::null; |
541 | } | 530 | } |
542 | return _listview->columnText( column ); | 531 | return _listview->columnText( column ); |
543 | } | 532 | } |
544 | void OVersatileView::setColumnWidth( int column, int width ) // QListView | 533 | void OVersatileView::setColumnWidth( int column, int width ) // QListView |
545 | { | 534 | { |
546 | if ( !isValidViewMode( Tree ) ) | 535 | if ( !isValidViewMode( Tree ) ) |
547 | { | 536 | { |
548 | return; | 537 | return; |
549 | } | 538 | } |
550 | _listview->setColumnWidth( column, width ); | 539 | _listview->setColumnWidth( column, width ); |
551 | } | 540 | } |
552 | int OVersatileView::columnWidth( int column ) const // QListView | 541 | int OVersatileView::columnWidth( int column ) const // QListView |
553 | { | 542 | { |
554 | if ( !isValidViewMode( Tree ) ) | 543 | if ( !isValidViewMode( Tree ) ) |
555 | { | 544 | { |
556 | return -1; | 545 | return -1; |
557 | } | 546 | } |
558 | return _listview->columnWidth( column ); | 547 | return _listview->columnWidth( column ); |
559 | } | 548 | } |
560 | void OVersatileView::setColumnWidthMode( int column, WidthMode mode ) // QListView | 549 | void OVersatileView::setColumnWidthMode( int column, WidthMode mode ) // QListView |
561 | { | 550 | { |
562 | if ( !isValidViewMode( Tree ) ) | 551 | if ( !isValidViewMode( Tree ) ) |
563 | { | 552 | { |
564 | return; | 553 | return; |
565 | } | 554 | } |
566 | _listview->setColumnWidth( column, mode ); | 555 | _listview->setColumnWidth( column, mode ); |
567 | } | 556 | } |
568 | int OVersatileView::columns() const // QListView | 557 | int OVersatileView::columns() const // QListView |
569 | { | 558 | { |
570 | if ( !isValidViewMode( Tree ) ) | 559 | if ( !isValidViewMode( Tree ) ) |
571 | { | 560 | { |
572 | return -1; | 561 | return -1; |
573 | } | 562 | } |
574 | return _listview->columns(); | 563 | return _listview->columns(); |
575 | } | 564 | } |
576 | 565 | ||
577 | void OVersatileView::setColumnAlignment( int column, int align ) // QListView | 566 | void OVersatileView::setColumnAlignment( int column, int align ) // QListView |
578 | { | 567 | { |
579 | if ( !isValidViewMode( Tree ) ) | 568 | if ( !isValidViewMode( Tree ) ) |
580 | { | 569 | { |
581 | return; | 570 | return; |
582 | } | 571 | } |
583 | _listview->setColumnAlignment( column, align ); | 572 | _listview->setColumnAlignment( column, align ); |
584 | } | 573 | } |
585 | int OVersatileView::columnAlignment( int column ) const // QListView | 574 | int OVersatileView::columnAlignment( int column ) const // QListView |
586 | { | 575 | { |
587 | if ( !isValidViewMode( Tree ) ) | 576 | if ( !isValidViewMode( Tree ) ) |
588 | { | 577 | { |
589 | return -1; | 578 | return -1; |
590 | } | 579 | } |
591 | return _listview->columnAlignment( column ); | 580 | return _listview->columnAlignment( column ); |
592 | } | 581 | } |
593 | 582 | ||
594 | OVersatileViewItem * OVersatileView::itemAt( const QPoint & screenPos ) const // QListView | 583 | OVersatileViewItem * OVersatileView::itemAt( const QPoint & screenPos ) const // QListView |
595 | { | 584 | { |
596 | if ( !isValidViewMode( Tree ) ) | 585 | if ( !isValidViewMode( Tree ) ) |
597 | { | 586 | { |
598 | return 0; | 587 | return 0; |
599 | } | 588 | } |
600 | return static_cast<OVersatileViewItem*>( _listview->itemAt( screenPos ) ); | 589 | return static_cast<OVersatileViewItem*>( _listview->itemAt( screenPos ) ); |
601 | } | 590 | } |
602 | QRect OVersatileView::itemRect( const OVersatileViewItem * item ) const // QListView | 591 | QRect OVersatileView::itemRect( const OVersatileViewItem * item ) const // QListView |
603 | { | 592 | { |
604 | if ( !isValidViewMode( Tree ) ) | 593 | if ( !isValidViewMode( Tree ) ) |
605 | { | 594 | { |
606 | return QRect( -1, -1, -1, -1 ); | 595 | return QRect( -1, -1, -1, -1 ); |
607 | } | 596 | } |
608 | return _listview->itemRect( item ); | 597 | return _listview->itemRect( item ); |
609 | } | 598 | } |
610 | int OVersatileView::itemPos( const OVersatileViewItem * item ) // QListView | 599 | int OVersatileView::itemPos( const OVersatileViewItem * item ) // QListView |
611 | { | 600 | { |
612 | if ( !isValidViewMode( Tree ) ) | 601 | if ( !isValidViewMode( Tree ) ) |
613 | { | 602 | { |
614 | return -1; | 603 | return -1; |
615 | } | 604 | } |
616 | return _listview->itemPos( item ); | 605 | return _listview->itemPos( item ); |
617 | } | 606 | } |
618 | 607 | ||
619 | bool OVersatileView::isSelected( const OVersatileViewItem * item ) const // QListView // also in QIconViewItem but !in QIconView *shrug* | 608 | bool OVersatileView::isSelected( const OVersatileViewItem * item ) const // QListView // also in QIconViewItem but !in QIconView *shrug* |
620 | { | 609 | { |
621 | if ( !isValidViewMode( Tree ) ) | 610 | if ( !isValidViewMode( Tree ) ) |
622 | { | 611 | { |
623 | return false; | 612 | return false; |
624 | } | 613 | } |
625 | return _listview->isSelected( item ); | 614 | return _listview->isSelected( item ); |
626 | } | 615 | } |
627 | 616 | ||
628 | void OVersatileView::setMultiSelection( bool enable ) | 617 | void OVersatileView::setMultiSelection( bool enable ) |
629 | { | 618 | { |
630 | _listview->setMultiSelection( enable ); | 619 | _listview->setMultiSelection( enable ); |
631 | } | 620 | } |
632 | bool OVersatileView::isMultiSelection() const | 621 | bool OVersatileView::isMultiSelection() const |
633 | { | 622 | { |
634 | return _listview->isMultiSelection(); | 623 | return _listview->isMultiSelection(); |
635 | } | 624 | } |
636 | 625 | ||
637 | OVersatileViewItem * OVersatileView::selectedItem() const // QListView | 626 | OVersatileViewItem * OVersatileView::selectedItem() const // QListView |
638 | { | 627 | { |
639 | if ( !isValidViewMode( Tree ) ) | 628 | if ( !isValidViewMode( Tree ) ) |
640 | { | 629 | { |
641 | return 0; | 630 | return 0; |
642 | } | 631 | } |
643 | return static_cast<OVersatileViewItem*>( _listview->selectedItem() ); | 632 | return static_cast<OVersatileViewItem*>( _listview->selectedItem() ); |
644 | } | 633 | } |
645 | void OVersatileView::setOpen( OVersatileViewItem * item, bool open ) // QListView | 634 | void OVersatileView::setOpen( OVersatileViewItem * item, bool open ) // QListView |
646 | { | 635 | { |
647 | if ( !isValidViewMode( Tree ) ) | 636 | if ( !isValidViewMode( Tree ) ) |
648 | { | 637 | { |
649 | return; | 638 | return; |
650 | } | 639 | } |
651 | _listview->setOpen( item, open ); | 640 | _listview->setOpen( item, open ); |
652 | } | 641 | } |
653 | bool OVersatileView::isOpen( const OVersatileViewItem * item ) const // QListView | 642 | bool OVersatileView::isOpen( const OVersatileViewItem * item ) const // QListView |
654 | { | 643 | { |
655 | if ( !isValidViewMode( Tree ) ) | 644 | if ( !isValidViewMode( Tree ) ) |
656 | { | 645 | { |
657 | return false; | 646 | return false; |
658 | } | 647 | } |
659 | return _listview->isOpen( item ); | 648 | return _listview->isOpen( item ); |
660 | } | 649 | } |
661 | 650 | ||
662 | OVersatileViewItem * OVersatileView::firstChild() const // QListView | 651 | OVersatileViewItem * OVersatileView::firstChild() const // QListView |
663 | { | 652 | { |
664 | if ( !isValidViewMode( Tree ) ) | 653 | if ( !isValidViewMode( Tree ) ) |
665 | { | 654 | { |
666 | return 0; | 655 | return 0; |
667 | } | 656 | } |
668 | return static_cast<OVersatileViewItem*>( _listview->firstChild() ); | 657 | return static_cast<OVersatileViewItem*>( _listview->firstChild() ); |
669 | } | 658 | } |
670 | int OVersatileView::childCount() const // QListView | 659 | int OVersatileView::childCount() const // QListView |
671 | { | 660 | { |
672 | if ( !isValidViewMode( Tree ) ) | 661 | if ( !isValidViewMode( Tree ) ) |
673 | { | 662 | { |
674 | return -1; | 663 | return -1; |
675 | } | 664 | } |
676 | return _listview->childCount(); | 665 | return _listview->childCount(); |
677 | } | 666 | } |
678 | 667 | ||
679 | void OVersatileView::setAllColumnsShowFocus( bool focus ) // QListView | 668 | void OVersatileView::setAllColumnsShowFocus( bool focus ) // QListView |
680 | { | 669 | { |
681 | if ( !isValidViewMode( Tree ) ) | 670 | if ( !isValidViewMode( Tree ) ) |
682 | { | 671 | { |
683 | return; | 672 | return; |
684 | } | 673 | } |
685 | _listview->setAllColumnsShowFocus( focus ); | 674 | _listview->setAllColumnsShowFocus( focus ); |
686 | } | 675 | } |
687 | bool OVersatileView::allColumnsShowFocus() const // QListView | 676 | bool OVersatileView::allColumnsShowFocus() const // QListView |
688 | { | 677 | { |
689 | if ( !isValidViewMode( Tree ) ) | 678 | if ( !isValidViewMode( Tree ) ) |
690 | { | 679 | { |
691 | return false; | 680 | return false; |
692 | } | 681 | } |
693 | return _listview->allColumnsShowFocus(); | 682 | return _listview->allColumnsShowFocus(); |
694 | } | 683 | } |
695 | 684 | ||
696 | void OVersatileView::setItemMargin( int margin ) // QListView | 685 | void OVersatileView::setItemMargin( int margin ) // QListView |
697 | { | 686 | { |
698 | if ( !isValidViewMode( Tree ) ) | 687 | if ( !isValidViewMode( Tree ) ) |
699 | { | 688 | { |
700 | return; | 689 | return; |
701 | } | 690 | } |
702 | _listview->setItemMargin( margin ); | 691 | _listview->setItemMargin( margin ); |
703 | } | 692 | } |
704 | int OVersatileView::itemMargin() const // QListView | 693 | int OVersatileView::itemMargin() const // QListView |
705 | { | 694 | { |
706 | if ( !isValidViewMode( Tree ) ) | 695 | if ( !isValidViewMode( Tree ) ) |
707 | { | 696 | { |
708 | return -1; | 697 | return -1; |
709 | } | 698 | } |
710 | return _listview->itemMargin(); | 699 | return _listview->itemMargin(); |
711 | } | 700 | } |
712 | 701 | ||
713 | void OVersatileView::setRootIsDecorated( bool decorate ) // QListView | 702 | void OVersatileView::setRootIsDecorated( bool decorate ) // QListView |
714 | { | 703 | { |
715 | if ( !isValidViewMode( Tree ) ) | 704 | if ( !isValidViewMode( Tree ) ) |
716 | { | 705 | { |
717 | return; | 706 | return; |
718 | } | 707 | } |
719 | _listview->setRootIsDecorated( decorate ); | 708 | _listview->setRootIsDecorated( decorate ); |
720 | } | 709 | } |
721 | bool OVersatileView::rootIsDecorated() const // QListView | 710 | bool OVersatileView::rootIsDecorated() const // QListView |
722 | { | 711 | { |
723 | if ( !isValidViewMode( Tree ) ) | 712 | if ( !isValidViewMode( Tree ) ) |
724 | { | 713 | { |
725 | return false; | 714 | return false; |
726 | } | 715 | } |
727 | return _listview->rootIsDecorated(); | 716 | return _listview->rootIsDecorated(); |
728 | } | 717 | } |
729 | 718 | ||
730 | void OVersatileView::setShowSortIndicator( bool show ) // QListView | 719 | void OVersatileView::setShowSortIndicator( bool show ) // QListView |
731 | { | 720 | { |
732 | if ( !isValidViewMode( Tree ) ) | 721 | if ( !isValidViewMode( Tree ) ) |
733 | { | 722 | { |
734 | return; | 723 | return; |
735 | } | 724 | } |
736 | _listview->setShowSortIndicator( show ); | 725 | _listview->setShowSortIndicator( show ); |
737 | } | 726 | } |
738 | bool OVersatileView::showSortIndicator() const // QListView | 727 | bool OVersatileView::showSortIndicator() const // QListView |
739 | { | 728 | { |
740 | if ( !isValidViewMode( Tree ) ) | 729 | if ( !isValidViewMode( Tree ) ) |
741 | { | 730 | { |
742 | return false; | 731 | return false; |
743 | } | 732 | } |
744 | return _listview->showSortIndicator(); | 733 | return _listview->showSortIndicator(); |
745 | } | 734 | } |
746 | 735 | ||
747 | void OVersatileView::triggerUpdate() // QListView | 736 | void OVersatileView::triggerUpdate() // QListView |
748 | { | 737 | { |
749 | if ( !isValidViewMode( Tree ) ) | 738 | if ( !isValidViewMode( Tree ) ) |
750 | { | 739 | { |
751 | return; | 740 | return; |
752 | } | 741 | } |
753 | _listview->triggerUpdate(); | 742 | _listview->triggerUpdate(); |
754 | } | 743 | } |
755 | 744 | ||
756 | // | 745 | // |
757 | // only in QIconView | 746 | // only in QIconView |
758 | // | 747 | // |
759 | 748 | ||
760 | uint OVersatileView::count() const // QIconView | 749 | uint OVersatileView::count() const // QIconView |
761 | { | 750 | { |
762 | if ( !isValidViewMode( Icons ) ) | 751 | if ( !isValidViewMode( Icons ) ) |
763 | { | 752 | { |
764 | return 0; | 753 | return 0; |
765 | } | 754 | } |
766 | return _iconview->count(); | 755 | return _iconview->count(); |
767 | } | 756 | } |
768 | 757 | ||
769 | int OVersatileView::index( const OVersatileViewItem *item ) const // QIconView | 758 | int OVersatileView::index( const OVersatileViewItem *item ) const // QIconView |
770 | { | 759 | { |
771 | if ( !isValidViewMode( Icons ) ) | 760 | if ( !isValidViewMode( Icons ) ) |
772 | { | 761 | { |
773 | return -1; | 762 | return -1; |
774 | } | 763 | } |
775 | return _iconview->index( item ); | 764 | return _iconview->index( item ); |
776 | } | 765 | } |
777 | 766 | ||
778 | OVersatileViewItem* OVersatileView::firstItem() const // QIconView | 767 | OVersatileViewItem* OVersatileView::firstItem() const // QIconView |
779 | { | 768 | { |
780 | if ( !isValidViewMode( Icons ) ) | 769 | if ( !isValidViewMode( Icons ) ) |
781 | { | 770 | { |
782 | return 0; | 771 | return 0; |
783 | } | 772 | } |
784 | return static_cast<OVersatileViewItem*>( _iconview->firstItem() ); | 773 | return static_cast<OVersatileViewItem*>( _iconview->firstItem() ); |
785 | } | 774 | } |
786 | OVersatileViewItem* OVersatileView::lastItem() const // QIconView | 775 | OVersatileViewItem* OVersatileView::lastItem() const // QIconView |
787 | { | 776 | { |
788 | if ( !isValidViewMode( Icons ) ) | 777 | if ( !isValidViewMode( Icons ) ) |
789 | { | 778 | { |
790 | return 0; | 779 | return 0; |
791 | } | 780 | } |
792 | return static_cast<OVersatileViewItem*>( _iconview->lastItem() ); | 781 | return static_cast<OVersatileViewItem*>( _iconview->lastItem() ); |
793 | } | 782 | } |
794 | 783 | ||
795 | OVersatileViewItem* OVersatileView::findItem( const QPoint &pos ) const // QIconView | 784 | OVersatileViewItem* OVersatileView::findItem( const QPoint &pos ) const // QIconView |
796 | { | 785 | { |
797 | if ( !isValidViewMode( Icons ) ) | 786 | if ( !isValidViewMode( Icons ) ) |
798 | { | 787 | { |
799 | return 0; | 788 | return 0; |
800 | } | 789 | } |
801 | return static_cast<OVersatileViewItem*>( _iconview->findItem( pos ) ); | 790 | return static_cast<OVersatileViewItem*>( _iconview->findItem( pos ) ); |
802 | } | 791 | } |
803 | OVersatileViewItem* OVersatileView::findItem( const QString &text ) const // QIconView | 792 | OVersatileViewItem* OVersatileView::findItem( const QString &text ) const // QIconView |
804 | { | 793 | { |
805 | if ( !isValidViewMode( Icons ) ) | 794 | if ( !isValidViewMode( Icons ) ) |
806 | { | 795 | { |
807 | return 0; | 796 | return 0; |
808 | } | 797 | } |
809 | return static_cast<OVersatileViewItem*>( _iconview->findItem( text ) ); | 798 | return static_cast<OVersatileViewItem*>( _iconview->findItem( text ) ); |
810 | } | 799 | } |
811 | 800 | ||
812 | OVersatileViewItem* OVersatileView::findFirstVisibleItem( const QRect &r ) const // QIconView | 801 | OVersatileViewItem* OVersatileView::findFirstVisibleItem( const QRect &r ) const // QIconView |
813 | { | 802 | { |
814 | if ( !isValidViewMode( Icons ) ) | 803 | if ( !isValidViewMode( Icons ) ) |
815 | { | 804 | { |
816 | return 0; | 805 | return 0; |
817 | } | 806 | } |
818 | return static_cast<OVersatileViewItem*>( _iconview->findFirstVisibleItem( r ) ); | 807 | return static_cast<OVersatileViewItem*>( _iconview->findFirstVisibleItem( r ) ); |
819 | } | 808 | } |
820 | OVersatileViewItem* OVersatileView::findLastVisibleItem( const QRect &r ) const // QIconView | 809 | OVersatileViewItem* OVersatileView::findLastVisibleItem( const QRect &r ) const // QIconView |
821 | { | 810 | { |
822 | if ( !isValidViewMode( Icons ) ) | 811 | if ( !isValidViewMode( Icons ) ) |
823 | { | 812 | { |
824 | return 0; | 813 | return 0; |
825 | } | 814 | } |
826 | return static_cast<OVersatileViewItem*>( _iconview->findLastVisibleItem( r ) ); | 815 | return static_cast<OVersatileViewItem*>( _iconview->findLastVisibleItem( r ) ); |
827 | } | 816 | } |
828 | 817 | ||
829 | void OVersatileView::setGridX( int rx ) // QIconView | 818 | void OVersatileView::setGridX( int rx ) // QIconView |
830 | { | 819 | { |
831 | if ( !isValidViewMode( Icons ) ) | 820 | if ( !isValidViewMode( Icons ) ) |
832 | { | 821 | { |
833 | return; | 822 | return; |
834 | } | 823 | } |
835 | _iconview->setGridX( rx ); | 824 | _iconview->setGridX( rx ); |
836 | } | 825 | } |
837 | void OVersatileView::setGridY( int ry ) // QIconView | 826 | void OVersatileView::setGridY( int ry ) // QIconView |
838 | { | 827 | { |
839 | if ( !isValidViewMode( Icons ) ) | 828 | if ( !isValidViewMode( Icons ) ) |
840 | { | 829 | { |
841 | return; | 830 | return; |
842 | } | 831 | } |
843 | _iconview->setGridY( ry ); | 832 | _iconview->setGridY( ry ); |
844 | } | 833 | } |
845 | int OVersatileView::gridX() const // QIconView | 834 | int OVersatileView::gridX() const // QIconView |
846 | { | 835 | { |
847 | if ( !isValidViewMode( Icons ) ) | 836 | if ( !isValidViewMode( Icons ) ) |
848 | { | 837 | { |
849 | return -1; | 838 | return -1; |
850 | } | 839 | } |
851 | return _iconview->gridX(); | 840 | return _iconview->gridX(); |
852 | } | 841 | } |
853 | int OVersatileView::gridY() const // QIconView | 842 | int OVersatileView::gridY() const // QIconView |
854 | { | 843 | { |
855 | if ( !isValidViewMode( Icons ) ) | 844 | if ( !isValidViewMode( Icons ) ) |
856 | { | 845 | { |
857 | return -1; | 846 | return -1; |
858 | } | 847 | } |
859 | return _iconview->gridY(); | 848 | return _iconview->gridY(); |
860 | } | 849 | } |
861 | void OVersatileView::setSpacing( int sp ) // QIconView | 850 | void OVersatileView::setSpacing( int sp ) // QIconView |
862 | { | 851 | { |
863 | if ( !isValidViewMode( Icons ) ) | 852 | if ( !isValidViewMode( Icons ) ) |
864 | { | 853 | { |
865 | return; | 854 | return; |
866 | } | 855 | } |
867 | _iconview->setSpacing( sp ); | 856 | _iconview->setSpacing( sp ); |
868 | } | 857 | } |
869 | int OVersatileView::spacing() const // QIconView | 858 | int OVersatileView::spacing() const // QIconView |
870 | { | 859 | { |
871 | if ( !isValidViewMode( Icons ) ) | 860 | if ( !isValidViewMode( Icons ) ) |
872 | { | 861 | { |
873 | return -1; | 862 | return -1; |
874 | } | 863 | } |
875 | return _iconview->spacing(); | 864 | return _iconview->spacing(); |
876 | } | 865 | } |
877 | void OVersatileView::setItemTextPos( QIconView::ItemTextPos pos ) // QIconView | 866 | void OVersatileView::setItemTextPos( QIconView::ItemTextPos pos ) // QIconView |
878 | { | 867 | { |
879 | if ( !isValidViewMode( Icons ) ) | 868 | if ( !isValidViewMode( Icons ) ) |
880 | { | 869 | { |
881 | return; | 870 | return; |
882 | } | 871 | } |
883 | _iconview->setItemTextPos( pos ); | 872 | _iconview->setItemTextPos( pos ); |
884 | } | 873 | } |
885 | QIconView::ItemTextPos OVersatileView::itemTextPos() const // QIconView | 874 | QIconView::ItemTextPos OVersatileView::itemTextPos() const // QIconView |
886 | { | 875 | { |
887 | if ( !isValidViewMode( Icons ) ) | 876 | if ( !isValidViewMode( Icons ) ) |
888 | { | 877 | { |
889 | return (QIconView::ItemTextPos) -1; | 878 | return (QIconView::ItemTextPos) -1; |
890 | } | 879 | } |
891 | return _iconview->itemTextPos(); | 880 | return _iconview->itemTextPos(); |
892 | } | 881 | } |
893 | void OVersatileView::setItemTextBackground( const QBrush &b ) // QIconView | 882 | void OVersatileView::setItemTextBackground( const QBrush &b ) // QIconView |
894 | { | 883 | { |
895 | if ( !isValidViewMode( Icons ) ) | 884 | if ( !isValidViewMode( Icons ) ) |
896 | { | 885 | { |
897 | return; | 886 | return; |
898 | } | 887 | } |
899 | _iconview->setItemTextBackground( b ); | 888 | _iconview->setItemTextBackground( b ); |
900 | } | 889 | } |
901 | QBrush OVersatileView::itemTextBackground() const // QIconView | 890 | QBrush OVersatileView::itemTextBackground() const // QIconView |
902 | { | 891 | { |
903 | if ( !isValidViewMode( Icons ) ) | 892 | if ( !isValidViewMode( Icons ) ) |
904 | { | 893 | { |
905 | return QBrush(); | 894 | return QBrush(); |
906 | } | 895 | } |
907 | return _iconview->itemTextBackground(); | 896 | return _iconview->itemTextBackground(); |
908 | } | 897 | } |
909 | void OVersatileView::setArrangement( QIconView::Arrangement am ) // QIconView | 898 | void OVersatileView::setArrangement( QIconView::Arrangement am ) // QIconView |
910 | { | 899 | { |
911 | if ( !isValidViewMode( Icons ) ) | 900 | if ( !isValidViewMode( Icons ) ) |
912 | { | 901 | { |
913 | return; | 902 | return; |
914 | } | 903 | } |
915 | _iconview->setArrangement( am ); | 904 | _iconview->setArrangement( am ); |
916 | } | 905 | } |
917 | QIconView::Arrangement OVersatileView::arrangement() const // QIconView | 906 | QIconView::Arrangement OVersatileView::arrangement() const // QIconView |
918 | { | 907 | { |
919 | if ( !isValidViewMode( Icons ) ) | 908 | if ( !isValidViewMode( Icons ) ) |
920 | { | 909 | { |
921 | return (QIconView::Arrangement) -1; | 910 | return (QIconView::Arrangement) -1; |
922 | } | 911 | } |
923 | return _iconview->arrangement(); | 912 | return _iconview->arrangement(); |
924 | } | 913 | } |
925 | void OVersatileView::setResizeMode( QIconView::ResizeMode am ) // QIconView | 914 | void OVersatileView::setResizeMode( QIconView::ResizeMode am ) // QIconView |
926 | { | 915 | { |
927 | if ( !isValidViewMode( Icons ) ) | 916 | if ( !isValidViewMode( Icons ) ) |
928 | { | 917 | { |
929 | return; | 918 | return; |
930 | } | 919 | } |
931 | _iconview->setResizeMode( am ); | 920 | _iconview->setResizeMode( am ); |
932 | } | 921 | } |
933 | QIconView::ResizeMode OVersatileView::resizeMode() const // QIconView | 922 | QIconView::ResizeMode OVersatileView::resizeMode() const // QIconView |
934 | { | 923 | { |
935 | if ( !isValidViewMode( Icons ) ) | 924 | if ( !isValidViewMode( Icons ) ) |
936 | { | 925 | { |
937 | return (QIconView::ResizeMode) -1; | 926 | return (QIconView::ResizeMode) -1; |
938 | } | 927 | } |
939 | return _iconview->resizeMode(); | 928 | return _iconview->resizeMode(); |
940 | } | 929 | } |
941 | void OVersatileView::setMaxItemWidth( int w ) // QIconView | 930 | void OVersatileView::setMaxItemWidth( int w ) // QIconView |
942 | { | 931 | { |
943 | if ( !isValidViewMode( Icons ) ) | 932 | if ( !isValidViewMode( Icons ) ) |
944 | { | 933 | { |
945 | return; | 934 | return; |
946 | } | 935 | } |
947 | _iconview->setMaxItemWidth( w ); | 936 | _iconview->setMaxItemWidth( w ); |
948 | } | 937 | } |
949 | int OVersatileView::maxItemWidth() const // QIconView | 938 | int OVersatileView::maxItemWidth() const // QIconView |
950 | { | 939 | { |
951 | if ( !isValidViewMode( Icons ) ) | 940 | if ( !isValidViewMode( Icons ) ) |
952 | { | 941 | { |
953 | return -1; | 942 | return -1; |
954 | } | 943 | } |
955 | return _iconview->maxItemWidth(); | 944 | return _iconview->maxItemWidth(); |
956 | } | 945 | } |
957 | void OVersatileView::setMaxItemTextLength( int w ) // QIconView | 946 | void OVersatileView::setMaxItemTextLength( int w ) // QIconView |
958 | { | 947 | { |
959 | if ( !isValidViewMode( Icons ) ) | 948 | if ( !isValidViewMode( Icons ) ) |
960 | { | 949 | { |
961 | return; | 950 | return; |
962 | } | 951 | } |
963 | _iconview->setMaxItemTextLength( w ); | 952 | _iconview->setMaxItemTextLength( w ); |
964 | } | 953 | } |
965 | int OVersatileView::maxItemTextLength() const // QIconView | 954 | int OVersatileView::maxItemTextLength() const // QIconView |
966 | { | 955 | { |
967 | if ( !isValidViewMode( Icons ) ) | 956 | if ( !isValidViewMode( Icons ) ) |
968 | { | 957 | { |
969 | return -1; | 958 | return -1; |
970 | } | 959 | } |
971 | return _iconview->maxItemTextLength(); | 960 | return _iconview->maxItemTextLength(); |
972 | } | 961 | } |
973 | void OVersatileView::setAutoArrange( bool b ) // QIconView | 962 | void OVersatileView::setAutoArrange( bool b ) // QIconView |
974 | { | 963 | { |
975 | if ( !isValidViewMode( Icons ) ) | 964 | if ( !isValidViewMode( Icons ) ) |
976 | { | 965 | { |
977 | return; | 966 | return; |
978 | } | 967 | } |
979 | _iconview->setAutoArrange( b ); | 968 | _iconview->setAutoArrange( b ); |
980 | } | 969 | } |
981 | bool OVersatileView::autoArrange() const // QIconView | 970 | bool OVersatileView::autoArrange() const // QIconView |
982 | { | 971 | { |
983 | if ( !isValidViewMode( Icons ) ) | 972 | if ( !isValidViewMode( Icons ) ) |
984 | { | 973 | { |
985 | return false; | 974 | return false; |
986 | } | 975 | } |
987 | return _iconview->autoArrange(); | 976 | return _iconview->autoArrange(); |
988 | } | 977 | } |
989 | void OVersatileView::setShowToolTips( bool b ) // QIconView | 978 | void OVersatileView::setShowToolTips( bool b ) // QIconView |
990 | { | 979 | { |
991 | if ( !isValidViewMode( Icons ) ) | 980 | if ( !isValidViewMode( Icons ) ) |
992 | { | 981 | { |
993 | return; | 982 | return; |
994 | } | 983 | } |
995 | _iconview->setShowToolTips( b ); | 984 | _iconview->setShowToolTips( b ); |
996 | } | 985 | } |
997 | bool OVersatileView::showToolTips() const // QIconView | 986 | bool OVersatileView::showToolTips() const // QIconView |
998 | { | 987 | { |
999 | if ( !isValidViewMode( Icons ) ) | 988 | if ( !isValidViewMode( Icons ) ) |
1000 | { | 989 | { |
1001 | return false; | 990 | return false; |
1002 | } | 991 | } |
1003 | return _iconview->showToolTips(); | 992 | return _iconview->showToolTips(); |
1004 | } | 993 | } |
1005 | 994 | ||
1006 | bool OVersatileView::sorting() const // QIconView | 995 | bool OVersatileView::sorting() const // QIconView |
1007 | { | 996 | { |
1008 | if ( !isValidViewMode( Icons ) ) | 997 | if ( !isValidViewMode( Icons ) ) |
1009 | { | 998 | { |
1010 | return false; | 999 | return false; |
1011 | } | 1000 | } |
1012 | return _iconview->sorting(); | 1001 | return _iconview->sorting(); |
1013 | } | 1002 | } |
1014 | bool OVersatileView::sortDirection() const // QIconView | 1003 | bool OVersatileView::sortDirection() const // QIconView |
1015 | { | 1004 | { |
1016 | if ( !isValidViewMode( Icons ) ) | 1005 | if ( !isValidViewMode( Icons ) ) |
1017 | { | 1006 | { |
1018 | return false; | 1007 | return false; |
1019 | } | 1008 | } |
1020 | return _iconview->sortDirection(); | 1009 | return _iconview->sortDirection(); |
1021 | } | 1010 | } |
1022 | 1011 | ||
1023 | void OVersatileView::setItemsMovable( bool b ) // QIconView | 1012 | void OVersatileView::setItemsMovable( bool b ) // QIconView |
1024 | { | 1013 | { |
1025 | if ( !isValidViewMode( Icons ) ) | 1014 | if ( !isValidViewMode( Icons ) ) |
1026 | { | 1015 | { |
1027 | return; | 1016 | return; |
1028 | } | 1017 | } |
1029 | _iconview->setItemsMovable( b ); | 1018 | _iconview->setItemsMovable( b ); |
1030 | } | 1019 | } |
1031 | bool OVersatileView::itemsMovable() const // QIconView | 1020 | bool OVersatileView::itemsMovable() const // QIconView |
1032 | { | 1021 | { |
1033 | if ( !isValidViewMode( Icons ) ) | 1022 | if ( !isValidViewMode( Icons ) ) |
1034 | { | 1023 | { |
1035 | return false; | 1024 | return false; |
1036 | } | 1025 | } |
1037 | return _iconview->itemsMovable(); | 1026 | return _iconview->itemsMovable(); |
1038 | } | 1027 | } |
1039 | void OVersatileView::setWordWrapIconText( bool b ) // QIconView | 1028 | void OVersatileView::setWordWrapIconText( bool b ) // QIconView |
1040 | { | 1029 | { |
1041 | if ( !isValidViewMode( Icons ) ) | 1030 | if ( !isValidViewMode( Icons ) ) |
1042 | { | 1031 | { |
1043 | return; | 1032 | return; |
1044 | } | 1033 | } |
1045 | _iconview->setWordWrapIconText( b ); | 1034 | _iconview->setWordWrapIconText( b ); |
1046 | } | 1035 | } |
1047 | bool OVersatileView::wordWrapIconText() const // QIconView | 1036 | bool OVersatileView::wordWrapIconText() const // QIconView |
1048 | { | 1037 | { |
1049 | if ( !isValidViewMode( Icons ) ) | 1038 | if ( !isValidViewMode( Icons ) ) |
1050 | { | 1039 | { |
1051 | return false; | 1040 | return false; |
1052 | } | 1041 | } |
1053 | return _iconview->wordWrapIconText(); | 1042 | return _iconview->wordWrapIconText(); |
1054 | } | 1043 | } |
1055 | 1044 | ||
1056 | void OVersatileView::arrangeItemsInGrid( const QSize &grid, bool update ) // QIconView | 1045 | void OVersatileView::arrangeItemsInGrid( const QSize &grid, bool update ) // QIconView |
1057 | { | 1046 | { |
1058 | if ( !isValidViewMode( Icons ) ) | 1047 | if ( !isValidViewMode( Icons ) ) |
1059 | { | 1048 | { |
1060 | return; | 1049 | return; |
1061 | } | 1050 | } |
1062 | _iconview->arrangeItemsInGrid( grid, update ); | 1051 | _iconview->arrangeItemsInGrid( grid, update ); |
1063 | } | 1052 | } |
1064 | void OVersatileView::arrangeItemsInGrid( bool update ) // QIconView | 1053 | void OVersatileView::arrangeItemsInGrid( bool update ) // QIconView |
1065 | { | 1054 | { |
1066 | if ( !isValidViewMode( Icons ) ) | 1055 | if ( !isValidViewMode( Icons ) ) |
1067 | { | 1056 | { |
1068 | return; | 1057 | return; |
1069 | } | 1058 | } |
1070 | _iconview->arrangeItemsInGrid( update ); | 1059 | _iconview->arrangeItemsInGrid( update ); |
1071 | } | 1060 | } |
1072 | void OVersatileView::updateContents() // QIconView | 1061 | void OVersatileView::updateContents() // QIconView |
1073 | { | 1062 | { |
1074 | if ( !isValidViewMode( Icons ) ) | 1063 | if ( !isValidViewMode( Icons ) ) |
1075 | { | 1064 | { |
1076 | return; | 1065 | return; |
1077 | } | 1066 | } |
1078 | _iconview->updateContents(); | 1067 | _iconview->updateContents(); |
1079 | } | 1068 | } |
1080 | 1069 | ||
1081 | //==============================================================================================// | 1070 | //==============================================================================================// |
1082 | // OVersatileView Case II - QListView / QIconView common API | 1071 | // OVersatileView Case II - QListView / QIconView common API |
1083 | //==============================================================================================// | 1072 | //==============================================================================================// |
1084 | 1073 | ||
1085 | void OVersatileView::clear() | 1074 | void OVersatileView::clear() |
1086 | { | 1075 | { |
1087 | _iconview->clear(); | 1076 | _iconview->clear(); |
1088 | _listview->clear(); | 1077 | _listview->clear(); |
1089 | } | 1078 | } |
1090 | 1079 | ||
1091 | void OVersatileView::setFont( const QFont & font ) | 1080 | void OVersatileView::setFont( const QFont & font ) |
1092 | { | 1081 | { |
1093 | _iconview->setFont( font ); | 1082 | _iconview->setFont( font ); |
1094 | _listview->setFont( font ); | 1083 | _listview->setFont( font ); |
1095 | } | 1084 | } |
1096 | void OVersatileView::setPalette( const QPalette & palette ) | 1085 | void OVersatileView::setPalette( const QPalette & palette ) |
1097 | { | 1086 | { |
1098 | _iconview->setPalette( palette ); | 1087 | _iconview->setPalette( palette ); |
1099 | _listview->setPalette( palette ); | 1088 | _listview->setPalette( palette ); |
1100 | } | 1089 | } |
1101 | 1090 | ||
1102 | void OVersatileView::takeItem( OVersatileViewItem * item ) | 1091 | void OVersatileView::takeItem( OVersatileViewItem * item ) |
1103 | { | 1092 | { |
1104 | _iconview->takeItem( item ); | 1093 | _iconview->takeItem( item ); |
1105 | _listview->takeItem( item ); | 1094 | _listview->takeItem( item ); |
1106 | } | 1095 | } |
1107 | 1096 | ||
1108 | void OVersatileView::setSelectionMode( SelectionMode mode ) | 1097 | void OVersatileView::setSelectionMode( SelectionMode mode ) |
1109 | { | 1098 | { |
1110 | _iconview->setSelectionMode( (QIconView::SelectionMode) mode ); | 1099 | _iconview->setSelectionMode( (QIconView::SelectionMode) mode ); |
1111 | _listview->setSelectionMode( (QListView::SelectionMode) mode ); | 1100 | _listview->setSelectionMode( (QListView::SelectionMode) mode ); |
1112 | } | 1101 | } |
1113 | OVersatileView::SelectionMode OVersatileView::selectionMode() const | 1102 | OVersatileView::SelectionMode OVersatileView::selectionMode() const |
1114 | { | 1103 | { |
1115 | return (OVersatileView::SelectionMode) _iconview->selectionMode(); | 1104 | return (OVersatileView::SelectionMode) _iconview->selectionMode(); |
1116 | } | 1105 | } |
1117 | 1106 | ||
1118 | void OVersatileView::selectAll( bool select ) | 1107 | void OVersatileView::selectAll( bool select ) |
1119 | { | 1108 | { |
1120 | _iconview->selectAll( select ); | 1109 | _iconview->selectAll( select ); |
1121 | } | 1110 | } |
1122 | void OVersatileView::clearSelection() | 1111 | void OVersatileView::clearSelection() |
1123 | { | 1112 | { |
1124 | _iconview->clearSelection(); | 1113 | _iconview->clearSelection(); |
1125 | _listview->clearSelection(); | 1114 | _listview->clearSelection(); |
1126 | } | 1115 | } |
1127 | void OVersatileView::invertSelection() | 1116 | void OVersatileView::invertSelection() |
1128 | { | 1117 | { |
1129 | _iconview->invertSelection(); | 1118 | _iconview->invertSelection(); |
1130 | _listview->invertSelection(); | 1119 | _listview->invertSelection(); |
1131 | } | 1120 | } |
1132 | 1121 | ||
1133 | void OVersatileView::ensureItemVisible( const OVersatileViewItem * item ) | 1122 | void OVersatileView::ensureItemVisible( const OVersatileViewItem * item ) |
1134 | { | 1123 | { |
1135 | _iconview->ensureItemVisible( const_cast<OVersatileViewItem*>( item ) ); | 1124 | _iconview->ensureItemVisible( const_cast<OVersatileViewItem*>( item ) ); |
1136 | _listview->ensureItemVisible( item ); | 1125 | _listview->ensureItemVisible( item ); |
1137 | } | 1126 | } |
1138 | void OVersatileView::repaintItem( const OVersatileViewItem * item ) const | 1127 | void OVersatileView::repaintItem( const OVersatileViewItem * item ) const |
1139 | { | 1128 | { |
1140 | _iconview->repaintItem( const_cast<OVersatileViewItem*>( item ) ); | 1129 | _iconview->repaintItem( const_cast<OVersatileViewItem*>( item ) ); |
1141 | _listview->repaintItem( item ); | 1130 | _listview->repaintItem( item ); |
1142 | } | 1131 | } |
1143 | 1132 | ||
1144 | void OVersatileView::setCurrentItem( OVersatileViewItem * item ) | 1133 | void OVersatileView::setCurrentItem( OVersatileViewItem * item ) |
1145 | { | 1134 | { |
1146 | _iconview->setCurrentItem( item ); | 1135 | _iconview->setCurrentItem( item ); |
1147 | _listview->setCurrentItem( item ); | 1136 | _listview->setCurrentItem( item ); |
1148 | } | 1137 | } |
1149 | OVersatileViewItem * OVersatileView::currentItem() const | 1138 | OVersatileViewItem * OVersatileView::currentItem() const |
1150 | { | 1139 | { |
1151 | return static_cast<OVersatileViewItem*>( _listview->currentItem() ); | 1140 | return static_cast<OVersatileViewItem*>( _listview->currentItem() ); |
1152 | } | 1141 | } |
1153 | 1142 | ||
1154 | // bool eventFilter( QObject * o, QEvent * ) // use QWidgetStack implementation | 1143 | // bool eventFilter( QObject * o, QEvent * ) // use QWidgetStack implementation |
1155 | 1144 | ||
1156 | // QSize minimumSizeHint() const // use QWidgetStack implementation | 1145 | // QSize minimumSizeHint() const // use QWidgetStack implementation |
1157 | // QSizePolicy sizePolicy() const // use QWidgetStack implementation | 1146 | // QSizePolicy sizePolicy() const // use QWidgetStack implementation |
1158 | // QSize sizeHint() const // use QWidgetStack implementation | 1147 | // QSize sizeHint() const // use QWidgetStack implementation |
1159 | 1148 | ||
1160 | //==============================================================================================// | 1149 | //==============================================================================================// |
1161 | // OVersatileView Case III - APIs which differ slightly | 1150 | // OVersatileView Case III - APIs which differ slightly |
1162 | //==============================================================================================// | 1151 | //==============================================================================================// |
1163 | 1152 | ||
1164 | /* | 1153 | /* |
1165 | 1154 | ||
1166 | void OVersatileView::insertItem( OVersatileViewItem * ) // QListView | 1155 | void OVersatileView::insertItem( OVersatileViewItem * ) // QListView |
1167 | void OVersatileView::insertItem( OVersatileViewItem *item, OVersatileViewItem *after = 0L ) // QIconView | 1156 | void OVersatileView::insertItem( OVersatileViewItem *item, OVersatileViewItem *after = 0L ) // QIconView |
1168 | 1157 | ||
1169 | void OVersatileView::setSelected( OVersatileViewItem *, bool ) // QListView | 1158 | void OVersatileView::setSelected( OVersatileViewItem *, bool ) // QListView |
1170 | void OVersatileView::setSelected( OVersatileViewItem *item, bool s, bool cb = FALSE ) // QIconView | 1159 | void OVersatileView::setSelected( OVersatileViewItem *item, bool s, bool cb = FALSE ) // QIconView |
1171 | 1160 | ||
1172 | void OVersatileView::setSorting( int column, bool increasing = TRUE ) // QListView | 1161 | void OVersatileView::setSorting( int column, bool increasing = TRUE ) // QListView |
1173 | void OVersatileView::setSorting( bool sort, bool ascending = TRUE ) // QIconView | 1162 | void OVersatileView::setSorting( bool sort, bool ascending = TRUE ) // QIconView |
1174 | 1163 | ||
1175 | void OVersatileView::sort() // #### make in next major release // QListView | 1164 | void OVersatileView::sort() // #### make in next major release // QListView |
1176 | void OVersatileView::sort( bool ascending = TRUE ) // QIconView | 1165 | void OVersatileView::sort( bool ascending = TRUE ) // QIconView |
1177 | 1166 | ||
1178 | */ | 1167 | */ |
1179 | 1168 | ||
1180 | 1169 | ||