-rw-r--r-- | microkde/ofontselector.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/microkde/ofontselector.cpp b/microkde/ofontselector.cpp index c8471cc..05095f3 100644 --- a/microkde/ofontselector.cpp +++ b/microkde/ofontselector.cpp | |||
@@ -1,412 +1,413 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | 3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This library is free software; you can | 5 | _;:, .> :=|. This library is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This library is distributed in the hope that | 12 | .i_,=:_. -<s. This library is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. .` .: details. | 18 | ++= -. .` .: details. |
19 | : = ...= . :.=- | 19 | : = ...= . :.=- |
20 | -. .:....=;==+<; You should have received a copy of the GNU | 20 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 21 | -_. . . )=. = Library General Public License along with |
22 | -- :-=` this library; see the file COPYING.LIB. | 22 | -- :-=` this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qlistbox.h> | 30 | #include <qlistbox.h> |
31 | #include <qcombobox.h> | 31 | #include <qcombobox.h> |
32 | #include <qlabel.h> | 32 | #include <qlabel.h> |
33 | #include <qfont.h> | 33 | #include <qfont.h> |
34 | #include <qmultilineedit.h> | 34 | #include <qmultilineedit.h> |
35 | 35 | ||
36 | #include <qpe/fontdatabase.h> | 36 | #include <qpe/fontdatabase.h> |
37 | 37 | ||
38 | #include "ofontselector.h" | 38 | #include "ofontselector.h" |
39 | 39 | ||
40 | class OFontSelectorPrivate { | 40 | class OFontSelectorPrivate { |
41 | public: | 41 | public: |
42 | QListBox * m_font_family_list; | 42 | QListBox * m_font_family_list; |
43 | QComboBox * m_font_style_list; | 43 | QComboBox * m_font_style_list; |
44 | QComboBox * m_font_size_list; | 44 | QComboBox * m_font_size_list; |
45 | QMultiLineEdit *m_preview; | 45 | QMultiLineEdit *m_preview; |
46 | 46 | ||
47 | bool m_pointbug : 1; | 47 | bool m_pointbug : 1; |
48 | 48 | ||
49 | FontDatabase m_fdb; | 49 | FontDatabase m_fdb; |
50 | }; | 50 | }; |
51 | 51 | ||
52 | namespace { | 52 | namespace { |
53 | 53 | ||
54 | class FontListItem : public QListBoxText { | 54 | class FontListItem : public QListBoxText { |
55 | public: | 55 | public: |
56 | FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( ) | 56 | FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( ) |
57 | { | 57 | { |
58 | m_name = t; | 58 | m_name = t; |
59 | m_styles = styles; | 59 | m_styles = styles; |
60 | m_sizes = sizes; | 60 | m_sizes = sizes; |
61 | 61 | ||
62 | QString str = t; | 62 | QString str = t; |
63 | str [0] = str [0]. upper ( ); | 63 | str [0] = str [0]. upper ( ); |
64 | setText ( str ); | 64 | setText ( str ); |
65 | } | 65 | } |
66 | 66 | ||
67 | QString family ( ) const | 67 | QString family ( ) const |
68 | { | 68 | { |
69 | return m_name; | 69 | return m_name; |
70 | } | 70 | } |
71 | 71 | ||
72 | const QStringList &styles ( ) const | 72 | const QStringList &styles ( ) const |
73 | { | 73 | { |
74 | return m_styles; | 74 | return m_styles; |
75 | } | 75 | } |
76 | 76 | ||
77 | const QValueList<int> &sizes ( ) const | 77 | const QValueList<int> &sizes ( ) const |
78 | { | 78 | { |
79 | return m_sizes; | 79 | return m_sizes; |
80 | } | 80 | } |
81 | 81 | ||
82 | private: | 82 | private: |
83 | QStringList m_styles; | 83 | QStringList m_styles; |
84 | QValueList<int> m_sizes; | 84 | QValueList<int> m_sizes; |
85 | QString m_name; | 85 | QString m_name; |
86 | }; | 86 | }; |
87 | 87 | ||
88 | 88 | ||
89 | static int findItemCB ( QComboBox *box, const QString &str ) | 89 | static int findItemCB ( QComboBox *box, const QString &str ) |
90 | { | 90 | { |
91 | for ( int i = 0; i < box-> count ( ); i++ ) { | 91 | for ( int i = 0; i < box-> count ( ); i++ ) { |
92 | if ( box-> text ( i ) == str ) | 92 | if ( box-> text ( i ) == str ) |
93 | return i; | 93 | return i; |
94 | } | 94 | } |
95 | return -1; | 95 | return -1; |
96 | } | 96 | } |
97 | 97 | ||
98 | } | 98 | } |
99 | /* static same as anon. namespace */ | 99 | /* static same as anon. namespace */ |
100 | static int qt_version ( ) | 100 | static int qt_version ( ) |
101 | { | 101 | { |
102 | const char *qver = qVersion ( ); | 102 | const char *qver = qVersion ( ); |
103 | 103 | ||
104 | return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' ); | 104 | return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' ); |
105 | } | 105 | } |
106 | 106 | ||
107 | /** | 107 | /** |
108 | * Constructs the Selector object | 108 | * Constructs the Selector object |
109 | * @param withpreview If a font preview should be given | 109 | * @param withpreview If a font preview should be given |
110 | * @param parent The parent of the Font Selector | 110 | * @param parent The parent of the Font Selector |
111 | * @param name The name of the object | 111 | * @param name The name of the object |
112 | * @param fl WidgetFlags | 112 | * @param fl WidgetFlags |
113 | */ | 113 | */ |
114 | OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) | 114 | OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) |
115 | { | 115 | { |
116 | d = new OFontSelectorPrivate ( ); | 116 | d = new OFontSelectorPrivate ( ); |
117 | 117 | ||
118 | QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); | 118 | QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); |
119 | gridLayout->setRowStretch ( 4, 10 ); | 119 | gridLayout->setRowStretch ( 4, 10 ); |
120 | 120 | ||
121 | d-> m_font_family_list = new QListBox( this, "FontListBox" ); | 121 | d-> m_font_family_list = new QListBox( this, "FontListBox" ); |
122 | gridLayout->addMultiCellWidget( d-> m_font_family_list, 0, 4, 0, 0 ); | 122 | gridLayout->addMultiCellWidget( d-> m_font_family_list, 0, 4, 0, 0 ); |
123 | connect( d-> m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); | 123 | connect( d-> m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); |
124 | 124 | ||
125 | QLabel *label = new QLabel( tr( "Style" ), this ); | 125 | QLabel *label = new QLabel( tr( "Style" ), this ); |
126 | gridLayout->addWidget( label, 0, 1 ); | 126 | gridLayout->addWidget( label, 0, 1 ); |
127 | 127 | ||
128 | d-> m_font_style_list = new QComboBox( this, "StyleListBox" ); | 128 | d-> m_font_style_list = new QComboBox( this, "StyleListBox" ); |
129 | connect( d-> m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); | 129 | connect( d-> m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); |
130 | gridLayout->addWidget( d-> m_font_style_list, 1, 1 ); | 130 | gridLayout->addWidget( d-> m_font_style_list, 1, 1 ); |
131 | 131 | ||
132 | label = new QLabel( tr( "Size" ), this ); | 132 | label = new QLabel( tr( "Size" ), this ); |
133 | gridLayout->addWidget( label, 2, 1 ); | 133 | gridLayout->addWidget( label, 2, 1 ); |
134 | 134 | ||
135 | d-> m_font_size_list = new QComboBox( this, "SizeListBox" ); | 135 | d-> m_font_size_list = new QComboBox( this, "SizeListBox" ); |
136 | connect( d-> m_font_size_list, SIGNAL( activated( int ) ), | 136 | connect( d-> m_font_size_list, SIGNAL( activated( int ) ), |
137 | this, SLOT( fontSizeClicked( int ) ) ); | 137 | this, SLOT( fontSizeClicked( int ) ) ); |
138 | gridLayout->addWidget( d-> m_font_size_list, 3, 1 ); | 138 | gridLayout->addWidget( d-> m_font_size_list, 3, 1 ); |
139 | 139 | ||
140 | d-> m_pointbug = ( qt_version ( ) <= 233 ); | 140 | //d-> m_pointbug = ( qt_version ( ) <= 233 ); |
141 | d->m_pointbug = ( qt_version() == 232 || qt_version() == 233 ); // SharpROM uses 2.3.2 | ||
141 | 142 | ||
142 | if ( withpreview ) { | 143 | if ( withpreview ) { |
143 | d-> m_preview = new QMultiLineEdit ( this, "Preview" ); | 144 | d-> m_preview = new QMultiLineEdit ( this, "Preview" ); |
144 | d-> m_preview-> setAlignment ( AlignCenter ); | 145 | d-> m_preview-> setAlignment ( AlignCenter ); |
145 | d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth ); | 146 | d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth ); |
146 | d-> m_preview-> setMargin ( 3 ); | 147 | d-> m_preview-> setMargin ( 3 ); |
147 | d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); | 148 | d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); |
148 | gridLayout-> addRowSpacing ( 5, 4 ); | 149 | gridLayout-> addRowSpacing ( 5, 4 ); |
149 | gridLayout-> addMultiCellWidget ( d-> m_preview, 6, 6, 0, 1 ); | 150 | gridLayout-> addMultiCellWidget ( d-> m_preview, 6, 6, 0, 1 ); |
150 | gridLayout-> setRowStretch ( 6, 5 ); | 151 | gridLayout-> setRowStretch ( 6, 5 ); |
151 | } | 152 | } |
152 | else | 153 | else |
153 | d-> m_preview = 0; | 154 | d-> m_preview = 0; |
154 | 155 | ||
155 | loadFonts ( d-> m_font_family_list ); | 156 | loadFonts ( d-> m_font_family_list ); |
156 | } | 157 | } |
157 | 158 | ||
158 | OFontSelector::~OFontSelector ( ) | 159 | OFontSelector::~OFontSelector ( ) |
159 | { | 160 | { |
160 | delete d; | 161 | delete d; |
161 | } | 162 | } |
162 | 163 | ||
163 | /** | 164 | /** |
164 | * This methods tries to set the font | 165 | * This methods tries to set the font |
165 | * @param f The wishes font | 166 | * @param f The wishes font |
166 | * @return success or failure | 167 | * @return success or failure |
167 | */ | 168 | */ |
168 | bool OFontSelector::setSelectedFont ( const QFont &f ) | 169 | bool OFontSelector::setSelectedFont ( const QFont &f ) |
169 | { | 170 | { |
170 | return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( ))); | 171 | return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( ))); |
171 | } | 172 | } |
172 | 173 | ||
173 | 174 | ||
174 | /** | 175 | /** |
175 | * This is an overloaded method @see setSelectedFont | 176 | * This is an overloaded method @see setSelectedFont |
176 | * @param familyStr The family of the font | 177 | * @param familyStr The family of the font |
177 | * @param styleStr The style of the font | 178 | * @param styleStr The style of the font |
178 | * @param sizeVal The size of font | 179 | * @param sizeVal The size of font |
179 | * @param charset The charset to be used. Will be deprecated by QT3 | 180 | * @param charset The charset to be used. Will be deprecated by QT3 |
180 | */ | 181 | */ |
181 | bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) | 182 | bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) |
182 | { | 183 | { |
183 | QString sizeStr = QString::number ( sizeVal ); | 184 | QString sizeStr = QString::number ( sizeVal ); |
184 | 185 | ||
185 | QListBoxItem *family = d-> m_font_family_list-> findItem ( familyStr ); | 186 | QListBoxItem *family = d-> m_font_family_list-> findItem ( familyStr ); |
186 | if ( !family ) | 187 | if ( !family ) |
187 | family = d-> m_font_family_list-> findItem ( "Helvetica" ); | 188 | family = d-> m_font_family_list-> findItem ( "Helvetica" ); |
188 | if ( !family ) | 189 | if ( !family ) |
189 | family = d-> m_font_family_list-> firstItem ( ); | 190 | family = d-> m_font_family_list-> firstItem ( ); |
190 | d-> m_font_family_list-> setCurrentItem ( family ); | 191 | d-> m_font_family_list-> setCurrentItem ( family ); |
191 | fontFamilyClicked ( d-> m_font_family_list-> index ( family )); | 192 | fontFamilyClicked ( d-> m_font_family_list-> index ( family )); |
192 | 193 | ||
193 | int style = findItemCB ( d-> m_font_style_list, styleStr ); | 194 | int style = findItemCB ( d-> m_font_style_list, styleStr ); |
194 | if ( style < 0 ) | 195 | if ( style < 0 ) |
195 | style = findItemCB ( d-> m_font_style_list, "Regular" ); | 196 | style = findItemCB ( d-> m_font_style_list, "Regular" ); |
196 | if ( style < 0 && d-> m_font_style_list-> count ( ) > 0 ) | 197 | if ( style < 0 && d-> m_font_style_list-> count ( ) > 0 ) |
197 | style = 0; | 198 | style = 0; |
198 | d-> m_font_style_list-> setCurrentItem ( style ); | 199 | d-> m_font_style_list-> setCurrentItem ( style ); |
199 | fontStyleClicked ( style ); | 200 | fontStyleClicked ( style ); |
200 | 201 | ||
201 | int size = findItemCB ( d-> m_font_size_list, sizeStr ); | 202 | int size = findItemCB ( d-> m_font_size_list, sizeStr ); |
202 | if ( size < 0 ) | 203 | if ( size < 0 ) |
203 | size = findItemCB ( d-> m_font_size_list, "10" ); | 204 | size = findItemCB ( d-> m_font_size_list, "10" ); |
204 | if ( size < 0 && d-> m_font_size_list-> count ( ) > 0 ) | 205 | if ( size < 0 && d-> m_font_size_list-> count ( ) > 0 ) |
205 | size = 0; | 206 | size = 0; |
206 | d-> m_font_size_list-> setCurrentItem ( size ); | 207 | d-> m_font_size_list-> setCurrentItem ( size ); |
207 | fontSizeClicked ( size ); | 208 | fontSizeClicked ( size ); |
208 | 209 | ||
209 | return (( family ) && ( style >= 0 ) && ( size >= 0 )); | 210 | return (( family ) && ( style >= 0 ) && ( size >= 0 )); |
210 | } | 211 | } |
211 | 212 | ||
212 | /** | 213 | /** |
213 | * This method returns the name, style and size of the currently selected | 214 | * This method returns the name, style and size of the currently selected |
214 | * font or false if no font is selected | 215 | * font or false if no font is selected |
215 | * @param family The font family will be written there | 216 | * @param family The font family will be written there |
216 | * @param style The style will be written there | 217 | * @param style The style will be written there |
217 | * @param size The size will be written there | 218 | * @param size The size will be written there |
218 | * @return success or failure | 219 | * @return success or failure |
219 | */ | 220 | */ |
220 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) | 221 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) |
221 | { | 222 | { |
222 | QString dummy; | 223 | QString dummy; |
223 | return selectedFont ( family, style, size, dummy ); | 224 | return selectedFont ( family, style, size, dummy ); |
224 | } | 225 | } |
225 | 226 | ||
226 | 227 | ||
227 | /** | 228 | /** |
228 | * This method does return the font family or QString::null if there is | 229 | * This method does return the font family or QString::null if there is |
229 | * no font item selected | 230 | * no font item selected |
230 | * @return the font family | 231 | * @return the font family |
231 | */ | 232 | */ |
232 | QString OFontSelector::fontFamily ( ) const | 233 | QString OFontSelector::fontFamily ( ) const |
233 | { | 234 | { |
234 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); | 235 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); |
235 | 236 | ||
236 | return fli ? fli-> family ( ) : QString::null; | 237 | return fli ? fli-> family ( ) : QString::null; |
237 | } | 238 | } |
238 | 239 | ||
239 | /** | 240 | /** |
240 | * This method will return the style of the font or QString::null | 241 | * This method will return the style of the font or QString::null |
241 | * @return the style of the font | 242 | * @return the style of the font |
242 | */ | 243 | */ |
243 | QString OFontSelector::fontStyle ( ) const | 244 | QString OFontSelector::fontStyle ( ) const |
244 | { | 245 | { |
245 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); | 246 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); |
246 | int fst = d-> m_font_style_list-> currentItem ( ); | 247 | int fst = d-> m_font_style_list-> currentItem ( ); |
247 | 248 | ||
248 | return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null; | 249 | return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null; |
249 | } | 250 | } |
250 | 251 | ||
251 | /** | 252 | /** |
252 | * This method will return the font size or 10 if no font size is available | 253 | * This method will return the font size or 10 if no font size is available |
253 | */ | 254 | */ |
254 | int OFontSelector::fontSize ( ) const | 255 | int OFontSelector::fontSize ( ) const |
255 | { | 256 | { |
256 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); | 257 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); |
257 | int fsi = d-> m_font_size_list-> currentItem ( ); | 258 | int fsi = d-> m_font_size_list-> currentItem ( ); |
258 | 259 | ||
259 | return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10; | 260 | return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10; |
260 | } | 261 | } |
261 | 262 | ||
262 | /** | 263 | /** |
263 | * returns the charset of the font or QString::null | 264 | * returns the charset of the font or QString::null |
264 | */ | 265 | */ |
265 | QString OFontSelector::fontCharSet ( ) const | 266 | QString OFontSelector::fontCharSet ( ) const |
266 | { | 267 | { |
267 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); | 268 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); |
268 | 269 | ||
269 | return fli ? d-> m_fdb. charSets ( fli-> family ( )) [0] : QString::null; | 270 | return fli ? d-> m_fdb. charSets ( fli-> family ( )) [0] : QString::null; |
270 | } | 271 | } |
271 | 272 | ||
272 | /** | 273 | /** |
273 | * Overloaded member function see above | 274 | * Overloaded member function see above |
274 | * @see selectedFont | 275 | * @see selectedFont |
275 | */ | 276 | */ |
276 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) | 277 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) |
277 | { | 278 | { |
278 | int ffa = d-> m_font_family_list-> currentItem ( ); | 279 | int ffa = d-> m_font_family_list-> currentItem ( ); |
279 | int fst = d-> m_font_style_list-> currentItem ( ); | 280 | int fst = d-> m_font_style_list-> currentItem ( ); |
280 | int fsi = d-> m_font_size_list-> currentItem ( ); | 281 | int fsi = d-> m_font_size_list-> currentItem ( ); |
281 | 282 | ||
282 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); | 283 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); |
283 | 284 | ||
284 | if ( fli ) { | 285 | if ( fli ) { |
285 | family = fli-> family ( ); | 286 | family = fli-> family ( ); |
286 | style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null; | 287 | style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null; |
287 | size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10; | 288 | size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10; |
288 | charset = d-> m_fdb. charSets ( fli-> family ( )) [0]; | 289 | charset = d-> m_fdb. charSets ( fli-> family ( )) [0]; |
289 | 290 | ||
290 | return true; | 291 | return true; |
291 | } | 292 | } |
292 | else | 293 | else |
293 | return false; | 294 | return false; |
294 | } | 295 | } |
295 | 296 | ||
296 | 297 | ||
297 | 298 | ||
298 | 299 | ||
299 | void OFontSelector::loadFonts ( QListBox *list ) | 300 | void OFontSelector::loadFonts ( QListBox *list ) |
300 | { | 301 | { |
301 | QStringList f = d-> m_fdb. families ( ); | 302 | QStringList f = d-> m_fdb. families ( ); |
302 | 303 | ||
303 | for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) { | 304 | for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) { |
304 | QValueList <int> ps = d-> m_fdb. pointSizes ( *it ); | 305 | QValueList <int> ps = d-> m_fdb. pointSizes ( *it ); |
305 | 306 | ||
306 | if ( d-> m_pointbug ) { | 307 | if ( d-> m_pointbug ) { |
307 | for ( QValueList <int>::Iterator it = ps. begin ( ); it != ps. end ( ); it++ ) | 308 | for ( QValueList <int>::Iterator it = ps. begin ( ); it != ps. end ( ); it++ ) |
308 | *it /= 10; | 309 | *it /= 10; |
309 | } | 310 | } |
310 | 311 | ||
311 | list-> insertItem ( new FontListItem ( *it, d-> m_fdb. styles ( *it ), ps )); | 312 | list-> insertItem ( new FontListItem ( *it, d-> m_fdb. styles ( *it ), ps )); |
312 | } | 313 | } |
313 | } | 314 | } |
314 | 315 | ||
315 | void OFontSelector::fontFamilyClicked ( int index ) | 316 | void OFontSelector::fontFamilyClicked ( int index ) |
316 | { | 317 | { |
317 | QString oldstyle = d-> m_font_style_list-> currentText ( ); | 318 | QString oldstyle = d-> m_font_style_list-> currentText ( ); |
318 | QString oldsize = d-> m_font_size_list-> currentText ( ); | 319 | QString oldsize = d-> m_font_size_list-> currentText ( ); |
319 | 320 | ||
320 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( index ); | 321 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( index ); |
321 | 322 | ||
322 | d-> m_font_style_list-> clear ( ); | 323 | d-> m_font_style_list-> clear ( ); |
323 | d-> m_font_style_list-> insertStringList ( fli-> styles ( )); | 324 | d-> m_font_style_list-> insertStringList ( fli-> styles ( )); |
324 | d-> m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( )); | 325 | d-> m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( )); |
325 | 326 | ||
326 | int i; | 327 | int i; |
327 | 328 | ||
328 | i = findItemCB ( d-> m_font_style_list, oldstyle ); | 329 | i = findItemCB ( d-> m_font_style_list, oldstyle ); |
329 | if ( i < 0 ) | 330 | if ( i < 0 ) |
330 | i = findItemCB ( d-> m_font_style_list, "Regular" ); | 331 | i = findItemCB ( d-> m_font_style_list, "Regular" ); |
331 | if (( i < 0 ) && ( d-> m_font_style_list-> count ( ) > 0 )) | 332 | if (( i < 0 ) && ( d-> m_font_style_list-> count ( ) > 0 )) |
332 | i = 0; | 333 | i = 0; |
333 | 334 | ||
334 | if ( i >= 0 ) { | 335 | if ( i >= 0 ) { |
335 | d-> m_font_style_list-> setCurrentItem ( i ); | 336 | d-> m_font_style_list-> setCurrentItem ( i ); |
336 | fontStyleClicked ( i ); | 337 | fontStyleClicked ( i ); |
337 | } | 338 | } |
338 | 339 | ||
339 | d-> m_font_size_list-> clear ( ); | 340 | d-> m_font_size_list-> clear ( ); |
340 | QValueList<int> sl = fli-> sizes ( ); | 341 | QValueList<int> sl = fli-> sizes ( ); |
341 | 342 | ||
342 | for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) | 343 | for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) |
343 | d-> m_font_size_list-> insertItem ( QString::number ( *it )); | 344 | d-> m_font_size_list-> insertItem ( QString::number ( *it )); |
344 | 345 | ||
345 | i = findItemCB ( d-> m_font_size_list, oldsize ); | 346 | i = findItemCB ( d-> m_font_size_list, oldsize ); |
346 | if ( i < 0 ) | 347 | if ( i < 0 ) |
347 | i = findItemCB ( d-> m_font_size_list, "10" ); | 348 | i = findItemCB ( d-> m_font_size_list, "10" ); |
348 | if (( i < 0 ) && ( d-> m_font_size_list-> count ( ) > 0 )) | 349 | if (( i < 0 ) && ( d-> m_font_size_list-> count ( ) > 0 )) |
349 | i = 0; | 350 | i = 0; |
350 | 351 | ||
351 | if ( i >= 0 ) { | 352 | if ( i >= 0 ) { |
352 | d-> m_font_size_list-> setCurrentItem ( i ); | 353 | d-> m_font_size_list-> setCurrentItem ( i ); |
353 | fontSizeClicked ( i ); | 354 | fontSizeClicked ( i ); |
354 | } | 355 | } |
355 | changeFont ( ); | 356 | changeFont ( ); |
356 | } | 357 | } |
357 | 358 | ||
358 | void OFontSelector::fontStyleClicked ( int /*index*/ ) | 359 | void OFontSelector::fontStyleClicked ( int /*index*/ ) |
359 | { | 360 | { |
360 | changeFont ( ); | 361 | changeFont ( ); |
361 | } | 362 | } |
362 | 363 | ||
363 | void OFontSelector::fontSizeClicked ( int /*index*/ ) | 364 | void OFontSelector::fontSizeClicked ( int /*index*/ ) |
364 | { | 365 | { |
365 | changeFont ( ); | 366 | changeFont ( ); |
366 | } | 367 | } |
367 | 368 | ||
368 | void OFontSelector::changeFont ( ) | 369 | void OFontSelector::changeFont ( ) |
369 | { | 370 | { |
370 | QFont f = selectedFont ( ); | 371 | QFont f = selectedFont ( ); |
371 | 372 | ||
372 | if ( d-> m_preview ) | 373 | if ( d-> m_preview ) |
373 | d-> m_preview-> setFont ( f ); | 374 | d-> m_preview-> setFont ( f ); |
374 | 375 | ||
375 | emit fontSelected ( f ); | 376 | emit fontSelected ( f ); |
376 | } | 377 | } |
377 | 378 | ||
378 | /** | 379 | /** |
379 | * Return the selected font | 380 | * Return the selected font |
380 | */ | 381 | */ |
381 | QFont OFontSelector::selectedFont ( ) | 382 | QFont OFontSelector::selectedFont ( ) |
382 | { | 383 | { |
383 | int ffa = d-> m_font_family_list-> currentItem ( ); | 384 | int ffa = d-> m_font_family_list-> currentItem ( ); |
384 | int fst = d-> m_font_style_list-> currentItem ( ); | 385 | int fst = d-> m_font_style_list-> currentItem ( ); |
385 | int fsi = d-> m_font_size_list-> currentItem ( ); | 386 | int fsi = d-> m_font_size_list-> currentItem ( ); |
386 | 387 | ||
387 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); | 388 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); |
388 | 389 | ||
389 | if ( fli ) { | 390 | if ( fli ) { |
390 | return d-> m_fdb. font ( fli-> family ( ), \ | 391 | return d-> m_fdb. font ( fli-> family ( ), \ |
391 | fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ | 392 | fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ |
392 | fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ | 393 | fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ |
393 | d-> m_fdb. charSets ( fli-> family ( )) [0] ); | 394 | d-> m_fdb. charSets ( fli-> family ( )) [0] ); |
394 | } | 395 | } |
395 | else | 396 | else |
396 | return QFont ( ); | 397 | return QFont ( ); |
397 | } | 398 | } |
398 | 399 | ||
399 | 400 | ||
400 | void OFontSelector::resizeEvent ( QResizeEvent *re ) | 401 | void OFontSelector::resizeEvent ( QResizeEvent *re ) |
401 | { | 402 | { |
402 | if ( d-> m_preview ) { | 403 | if ( d-> m_preview ) { |
403 | d-> m_preview-> setMinimumHeight ( 1 ); | 404 | d-> m_preview-> setMinimumHeight ( 1 ); |
404 | d-> m_preview-> setMaximumHeight ( 32767 ); | 405 | d-> m_preview-> setMaximumHeight ( 32767 ); |
405 | } | 406 | } |
406 | 407 | ||
407 | QWidget::resizeEvent ( re ); | 408 | QWidget::resizeEvent ( re ); |
408 | 409 | ||
409 | if ( d-> m_preview ) | 410 | if ( d-> m_preview ) |
410 | d-> m_preview-> setFixedHeight ( d-> m_preview-> height ( )); | 411 | d-> m_preview-> setFixedHeight ( d-> m_preview-> height ( )); |
411 | 412 | ||
412 | } | 413 | } |