-rw-r--r-- | libopie/ofontselector.cpp | 132 |
1 files changed, 91 insertions, 41 deletions
diff --git a/libopie/ofontselector.cpp b/libopie/ofontselector.cpp index b905474..c8471cc 100644 --- a/libopie/ofontselector.cpp +++ b/libopie/ofontselector.cpp | |||
@@ -33,81 +33,89 @@ | |||
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; | 47 | bool m_pointbug : 1; |
48 | 48 | ||
49 | FontDatabase m_fdb; | 49 | FontDatabase m_fdb; |
50 | }; | 50 | }; |
51 | 51 | ||
52 | namespace { | ||
52 | 53 | ||
53 | class FontListItem : public QListBoxText { | 54 | class FontListItem : public QListBoxText { |
54 | public: | 55 | public: |
55 | 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 ( ) |
56 | { | 57 | { |
57 | m_name = t; | 58 | m_name = t; |
58 | m_styles = styles; | 59 | m_styles = styles; |
59 | m_sizes = sizes; | 60 | m_sizes = sizes; |
60 | 61 | ||
61 | QString str = t; | 62 | QString str = t; |
62 | str [0] = str [0]. upper ( ); | 63 | str [0] = str [0]. upper ( ); |
63 | setText ( str ); | 64 | setText ( str ); |
64 | } | 65 | } |
65 | 66 | ||
66 | QString family ( ) const | 67 | QString family ( ) const |
67 | { | 68 | { |
68 | return m_name; | 69 | return m_name; |
69 | } | 70 | } |
70 | 71 | ||
71 | const QStringList &styles ( ) const | 72 | const QStringList &styles ( ) const |
72 | { | 73 | { |
73 | return m_styles; | 74 | return m_styles; |
74 | } | 75 | } |
75 | 76 | ||
76 | const QValueList<int> &sizes ( ) const | 77 | const QValueList<int> &sizes ( ) const |
77 | { | 78 | { |
78 | return m_sizes; | 79 | return m_sizes; |
79 | } | 80 | } |
80 | 81 | ||
81 | private: | 82 | private: |
82 | QStringList m_styles; | 83 | QStringList m_styles; |
83 | QValueList<int> m_sizes; | 84 | QValueList<int> m_sizes; |
84 | QString m_name; | 85 | QString m_name; |
85 | }; | 86 | }; |
86 | 87 | ||
87 | 88 | ||
88 | static int findItemCB ( QComboBox *box, const QString &str ) | 89 | static int findItemCB ( QComboBox *box, const QString &str ) |
89 | { | 90 | { |
90 | for ( int i = 0; i < box-> count ( ); i++ ) { | 91 | for ( int i = 0; i < box-> count ( ); i++ ) { |
91 | if ( box-> text ( i ) == str ) | 92 | if ( box-> text ( i ) == str ) |
92 | return i; | 93 | return i; |
93 | } | 94 | } |
94 | return -1; | 95 | return -1; |
95 | } | 96 | } |
96 | 97 | ||
97 | 98 | } | |
99 | /* static same as anon. namespace */ | ||
98 | static int qt_version ( ) | 100 | static int qt_version ( ) |
99 | { | 101 | { |
100 | const char *qver = qVersion ( ); | 102 | const char *qver = qVersion ( ); |
101 | 103 | ||
102 | 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' ); |
103 | } | 105 | } |
104 | 106 | ||
105 | 107 | /** | |
108 | * Constructs the Selector object | ||
109 | * @param withpreview If a font preview should be given | ||
110 | * @param parent The parent of the Font Selector | ||
111 | * @param name The name of the object | ||
112 | * @param fl WidgetFlags | ||
113 | */ | ||
106 | 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 ) |
107 | { | 115 | { |
108 | d = new OFontSelectorPrivate ( ); | 116 | d = new OFontSelectorPrivate ( ); |
109 | 117 | ||
110 | QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); | 118 | QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); |
111 | gridLayout->setRowStretch ( 4, 10 ); | 119 | gridLayout->setRowStretch ( 4, 10 ); |
112 | 120 | ||
113 | d-> m_font_family_list = new QListBox( this, "FontListBox" ); | 121 | d-> m_font_family_list = new QListBox( this, "FontListBox" ); |
@@ -130,48 +138,61 @@ OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *na | |||
130 | gridLayout->addWidget( d-> m_font_size_list, 3, 1 ); | 138 | gridLayout->addWidget( d-> m_font_size_list, 3, 1 ); |
131 | 139 | ||
132 | d-> m_pointbug = ( qt_version ( ) <= 233 ); | 140 | d-> m_pointbug = ( qt_version ( ) <= 233 ); |
133 | 141 | ||
134 | if ( withpreview ) { | 142 | if ( withpreview ) { |
135 | d-> m_preview = new QMultiLineEdit ( this, "Preview" ); | 143 | d-> m_preview = new QMultiLineEdit ( this, "Preview" ); |
136 | d-> m_preview-> setAlignment ( AlignCenter ); | 144 | d-> m_preview-> setAlignment ( AlignCenter ); |
137 | d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth ); | 145 | d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth ); |
138 | d-> m_preview-> setMargin ( 3 ); | 146 | d-> m_preview-> setMargin ( 3 ); |
139 | d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); | 147 | d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); |
140 | gridLayout-> addRowSpacing ( 5, 4 ); | 148 | gridLayout-> addRowSpacing ( 5, 4 ); |
141 | gridLayout-> addMultiCellWidget ( d-> m_preview, 6, 6, 0, 1 ); | 149 | gridLayout-> addMultiCellWidget ( d-> m_preview, 6, 6, 0, 1 ); |
142 | gridLayout-> setRowStretch ( 6, 5 ); | 150 | gridLayout-> setRowStretch ( 6, 5 ); |
143 | } | 151 | } |
144 | else | 152 | else |
145 | d-> m_preview = 0; | 153 | d-> m_preview = 0; |
146 | 154 | ||
147 | loadFonts ( d-> m_font_family_list ); | 155 | loadFonts ( d-> m_font_family_list ); |
148 | } | 156 | } |
149 | 157 | ||
150 | OFontSelector::~OFontSelector ( ) | 158 | OFontSelector::~OFontSelector ( ) |
151 | { | 159 | { |
152 | delete d; | 160 | delete d; |
153 | } | 161 | } |
154 | 162 | ||
163 | /** | ||
164 | * This methods tries to set the font | ||
165 | * @param f The wishes font | ||
166 | * @return success or failure | ||
167 | */ | ||
155 | bool OFontSelector::setSelectedFont ( const QFont &f ) | 168 | bool OFontSelector::setSelectedFont ( const QFont &f ) |
156 | { | 169 | { |
157 | return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( ))); | 170 | return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( ))); |
158 | } | 171 | } |
159 | 172 | ||
160 | bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ ) | 173 | |
174 | /** | ||
175 | * This is an overloaded method @see setSelectedFont | ||
176 | * @param familyStr The family of the font | ||
177 | * @param styleStr The style of the font | ||
178 | * @param sizeVal The size of font | ||
179 | * @param charset The charset to be used. Will be deprecated by QT3 | ||
180 | */ | ||
181 | bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) | ||
161 | { | 182 | { |
162 | QString sizeStr = QString::number ( sizeVal ); | 183 | QString sizeStr = QString::number ( sizeVal ); |
163 | 184 | ||
164 | QListBoxItem *family = d-> m_font_family_list-> findItem ( familyStr ); | 185 | QListBoxItem *family = d-> m_font_family_list-> findItem ( familyStr ); |
165 | if ( !family ) | 186 | if ( !family ) |
166 | family = d-> m_font_family_list-> findItem ( "Helvetica" ); | 187 | family = d-> m_font_family_list-> findItem ( "Helvetica" ); |
167 | if ( !family ) | 188 | if ( !family ) |
168 | family = d-> m_font_family_list-> firstItem ( ); | 189 | family = d-> m_font_family_list-> firstItem ( ); |
169 | d-> m_font_family_list-> setCurrentItem ( family ); | 190 | d-> m_font_family_list-> setCurrentItem ( family ); |
170 | fontFamilyClicked ( d-> m_font_family_list-> index ( family )); | 191 | fontFamilyClicked ( d-> m_font_family_list-> index ( family )); |
171 | 192 | ||
172 | int style = findItemCB ( d-> m_font_style_list, styleStr ); | 193 | int style = findItemCB ( d-> m_font_style_list, styleStr ); |
173 | if ( style < 0 ) | 194 | if ( style < 0 ) |
174 | style = findItemCB ( d-> m_font_style_list, "Regular" ); | 195 | style = findItemCB ( d-> m_font_style_list, "Regular" ); |
175 | if ( style < 0 && d-> m_font_style_list-> count ( ) > 0 ) | 196 | if ( style < 0 && d-> m_font_style_list-> count ( ) > 0 ) |
176 | style = 0; | 197 | style = 0; |
177 | d-> m_font_style_list-> setCurrentItem ( style ); | 198 | d-> m_font_style_list-> setCurrentItem ( style ); |
@@ -179,142 +200,169 @@ bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &s | |||
179 | 200 | ||
180 | int size = findItemCB ( d-> m_font_size_list, sizeStr ); | 201 | int size = findItemCB ( d-> m_font_size_list, sizeStr ); |
181 | if ( size < 0 ) | 202 | if ( size < 0 ) |
182 | size = findItemCB ( d-> m_font_size_list, "10" ); | 203 | size = findItemCB ( d-> m_font_size_list, "10" ); |
183 | if ( size < 0 && d-> m_font_size_list-> count ( ) > 0 ) | 204 | if ( size < 0 && d-> m_font_size_list-> count ( ) > 0 ) |
184 | size = 0; | 205 | size = 0; |
185 | d-> m_font_size_list-> setCurrentItem ( size ); | 206 | d-> m_font_size_list-> setCurrentItem ( size ); |
186 | fontSizeClicked ( size ); | 207 | fontSizeClicked ( size ); |
187 | 208 | ||
188 | return (( family ) && ( style >= 0 ) && ( size >= 0 )); | 209 | return (( family ) && ( style >= 0 ) && ( size >= 0 )); |
189 | } | 210 | } |
190 | 211 | ||
212 | /** | ||
213 | * This method returns the name, style and size of the currently selected | ||
214 | * font or false if no font is selected | ||
215 | * @param family The font family will be written there | ||
216 | * @param style The style will be written there | ||
217 | * @param size The size will be written there | ||
218 | * @return success or failure | ||
219 | */ | ||
191 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) | 220 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) |
192 | { | 221 | { |
193 | QString dummy; | 222 | QString dummy; |
194 | return selectedFont ( family, style, size, dummy ); | 223 | return selectedFont ( family, style, size, dummy ); |
195 | } | 224 | } |
196 | 225 | ||
197 | 226 | ||
227 | /** | ||
228 | * This method does return the font family or QString::null if there is | ||
229 | * no font item selected | ||
230 | * @return the font family | ||
231 | */ | ||
198 | QString OFontSelector::fontFamily ( ) const | 232 | QString OFontSelector::fontFamily ( ) const |
199 | { | 233 | { |
200 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); | 234 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); |
201 | 235 | ||
202 | return fli ? fli-> family ( ) : QString::null; | 236 | return fli ? fli-> family ( ) : QString::null; |
203 | } | 237 | } |
204 | 238 | ||
239 | /** | ||
240 | * This method will return the style of the font or QString::null | ||
241 | * @return the style of the font | ||
242 | */ | ||
205 | QString OFontSelector::fontStyle ( ) const | 243 | QString OFontSelector::fontStyle ( ) const |
206 | { | 244 | { |
207 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); | 245 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); |
208 | int fst = d-> m_font_style_list-> currentItem ( ); | 246 | int fst = d-> m_font_style_list-> currentItem ( ); |
209 | 247 | ||
210 | return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null; | 248 | return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null; |
211 | } | 249 | } |
212 | 250 | ||
251 | /** | ||
252 | * This method will return the font size or 10 if no font size is available | ||
253 | */ | ||
213 | int OFontSelector::fontSize ( ) const | 254 | int OFontSelector::fontSize ( ) const |
214 | { | 255 | { |
215 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); | 256 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); |
216 | int fsi = d-> m_font_size_list-> currentItem ( ); | 257 | int fsi = d-> m_font_size_list-> currentItem ( ); |
217 | 258 | ||
218 | return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10; | 259 | return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10; |
219 | } | 260 | } |
220 | 261 | ||
262 | /** | ||
263 | * returns the charset of the font or QString::null | ||
264 | */ | ||
221 | QString OFontSelector::fontCharSet ( ) const | 265 | QString OFontSelector::fontCharSet ( ) const |
222 | { | 266 | { |
223 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); | 267 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); |
224 | 268 | ||
225 | return fli ? d-> m_fdb. charSets ( fli-> family ( )) [0] : QString::null; | 269 | return fli ? d-> m_fdb. charSets ( fli-> family ( )) [0] : QString::null; |
226 | } | 270 | } |
227 | 271 | ||
272 | /** | ||
273 | * Overloaded member function see above | ||
274 | * @see selectedFont | ||
275 | */ | ||
228 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) | 276 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) |
229 | { | 277 | { |
230 | int ffa = d-> m_font_family_list-> currentItem ( ); | 278 | int ffa = d-> m_font_family_list-> currentItem ( ); |
231 | int fst = d-> m_font_style_list-> currentItem ( ); | 279 | int fst = d-> m_font_style_list-> currentItem ( ); |
232 | int fsi = d-> m_font_size_list-> currentItem ( ); | 280 | int fsi = d-> m_font_size_list-> currentItem ( ); |
233 | 281 | ||
234 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); | 282 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); |
235 | 283 | ||
236 | if ( fli ) { | 284 | if ( fli ) { |
237 | family = fli-> family ( ); | 285 | family = fli-> family ( ); |
238 | style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null; | 286 | style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null; |
239 | size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10; | 287 | size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10; |
240 | charset = d-> m_fdb. charSets ( fli-> family ( )) [0]; | 288 | charset = d-> m_fdb. charSets ( fli-> family ( )) [0]; |
241 | 289 | ||
242 | return true; | 290 | return true; |
243 | } | 291 | } |
244 | else | 292 | else |
245 | return false; | 293 | return false; |
246 | } | 294 | } |
247 | 295 | ||
248 | 296 | ||
249 | 297 | ||
250 | 298 | ||
251 | void OFontSelector::loadFonts ( QListBox *list ) | 299 | void OFontSelector::loadFonts ( QListBox *list ) |
252 | { | 300 | { |
253 | QStringList f = d-> m_fdb. families ( ); | 301 | QStringList f = d-> m_fdb. families ( ); |
254 | 302 | ||
255 | for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) { | 303 | for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) { |
256 | QValueList <int> ps = d-> m_fdb. pointSizes ( *it ); | 304 | QValueList <int> ps = d-> m_fdb. pointSizes ( *it ); |
257 | 305 | ||
258 | if ( d-> m_pointbug ) { | 306 | if ( d-> m_pointbug ) { |
259 | for ( QValueList <int>::Iterator it = ps. begin ( ); it != ps. end ( ); it++ ) | 307 | for ( QValueList <int>::Iterator it = ps. begin ( ); it != ps. end ( ); it++ ) |
260 | *it /= 10; | 308 | *it /= 10; |
261 | } | 309 | } |
262 | 310 | ||
263 | list-> insertItem ( new FontListItem ( *it, d-> m_fdb. styles ( *it ), ps )); | 311 | list-> insertItem ( new FontListItem ( *it, d-> m_fdb. styles ( *it ), ps )); |
264 | } | 312 | } |
265 | } | 313 | } |
266 | 314 | ||
267 | void OFontSelector::fontFamilyClicked ( int index ) | 315 | void OFontSelector::fontFamilyClicked ( int index ) |
268 | { | 316 | { |
269 | QString oldstyle = d-> m_font_style_list-> currentText ( ); | 317 | QString oldstyle = d-> m_font_style_list-> currentText ( ); |
270 | QString oldsize = d-> m_font_size_list-> currentText ( ); | 318 | QString oldsize = d-> m_font_size_list-> currentText ( ); |
271 | 319 | ||
272 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( index ); | 320 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( index ); |
273 | 321 | ||
274 | d-> m_font_style_list-> clear ( ); | 322 | d-> m_font_style_list-> clear ( ); |
275 | d-> m_font_style_list-> insertStringList ( fli-> styles ( )); | 323 | d-> m_font_style_list-> insertStringList ( fli-> styles ( )); |
276 | d-> m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( )); | 324 | d-> m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( )); |
277 | 325 | ||
278 | int i; | 326 | int i; |
279 | 327 | ||
280 | i = findItemCB ( d-> m_font_style_list, oldstyle ); | 328 | i = findItemCB ( d-> m_font_style_list, oldstyle ); |
281 | if ( i < 0 ) | 329 | if ( i < 0 ) |
282 | i = findItemCB ( d-> m_font_style_list, "Regular" ); | 330 | i = findItemCB ( d-> m_font_style_list, "Regular" ); |
283 | if (( i < 0 ) && ( d-> m_font_style_list-> count ( ) > 0 )) | 331 | if (( i < 0 ) && ( d-> m_font_style_list-> count ( ) > 0 )) |
284 | i = 0; | 332 | i = 0; |
285 | 333 | ||
286 | if ( i >= 0 ) { | 334 | if ( i >= 0 ) { |
287 | d-> m_font_style_list-> setCurrentItem ( i ); | 335 | d-> m_font_style_list-> setCurrentItem ( i ); |
288 | fontStyleClicked ( i ); | 336 | fontStyleClicked ( i ); |
289 | } | 337 | } |
290 | 338 | ||
291 | d-> m_font_size_list-> clear ( ); | 339 | d-> m_font_size_list-> clear ( ); |
292 | QValueList<int> sl = fli-> sizes ( ); | 340 | QValueList<int> sl = fli-> sizes ( ); |
293 | 341 | ||
294 | for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) | 342 | for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) |
295 | d-> m_font_size_list-> insertItem ( QString::number ( *it )); | 343 | d-> m_font_size_list-> insertItem ( QString::number ( *it )); |
296 | 344 | ||
297 | i = findItemCB ( d-> m_font_size_list, oldsize ); | 345 | i = findItemCB ( d-> m_font_size_list, oldsize ); |
298 | if ( i < 0 ) | 346 | if ( i < 0 ) |
299 | i = findItemCB ( d-> m_font_size_list, "10" ); | 347 | i = findItemCB ( d-> m_font_size_list, "10" ); |
300 | if (( i < 0 ) && ( d-> m_font_size_list-> count ( ) > 0 )) | 348 | if (( i < 0 ) && ( d-> m_font_size_list-> count ( ) > 0 )) |
301 | i = 0; | 349 | i = 0; |
302 | 350 | ||
303 | if ( i >= 0 ) { | 351 | if ( i >= 0 ) { |
304 | d-> m_font_size_list-> setCurrentItem ( i ); | 352 | d-> m_font_size_list-> setCurrentItem ( i ); |
305 | fontSizeClicked ( i ); | 353 | fontSizeClicked ( i ); |
306 | } | 354 | } |
307 | changeFont ( ); | 355 | changeFont ( ); |
308 | } | 356 | } |
309 | 357 | ||
310 | void OFontSelector::fontStyleClicked ( int /*index*/ ) | 358 | void OFontSelector::fontStyleClicked ( int /*index*/ ) |
311 | { | 359 | { |
312 | changeFont ( ); | 360 | changeFont ( ); |
313 | } | 361 | } |
314 | 362 | ||
315 | void OFontSelector::fontSizeClicked ( int /*index*/ ) | 363 | void OFontSelector::fontSizeClicked ( int /*index*/ ) |
316 | { | 364 | { |
317 | changeFont ( ); | 365 | changeFont ( ); |
318 | } | 366 | } |
319 | 367 | ||
320 | void OFontSelector::changeFont ( ) | 368 | void OFontSelector::changeFont ( ) |
@@ -322,25 +370,27 @@ void OFontSelector::changeFont ( ) | |||
322 | QFont f = selectedFont ( ); | 370 | QFont f = selectedFont ( ); |
323 | 371 | ||
324 | if ( d-> m_preview ) | 372 | if ( d-> m_preview ) |
325 | d-> m_preview-> setFont ( f ); | 373 | d-> m_preview-> setFont ( f ); |
326 | 374 | ||
327 | emit fontSelected ( f ); | 375 | emit fontSelected ( f ); |
328 | } | 376 | } |
329 | 377 | ||
330 | 378 | /** | |
379 | * Return the selected font | ||
380 | */ | ||
331 | QFont OFontSelector::selectedFont ( ) | 381 | QFont OFontSelector::selectedFont ( ) |
332 | { | 382 | { |
333 | int ffa = d-> m_font_family_list-> currentItem ( ); | 383 | int ffa = d-> m_font_family_list-> currentItem ( ); |
334 | int fst = d-> m_font_style_list-> currentItem ( ); | 384 | int fst = d-> m_font_style_list-> currentItem ( ); |
335 | int fsi = d-> m_font_size_list-> currentItem ( ); | 385 | int fsi = d-> m_font_size_list-> currentItem ( ); |
336 | 386 | ||
337 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); | 387 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); |
338 | 388 | ||
339 | if ( fli ) { | 389 | if ( fli ) { |
340 | return d-> m_fdb. font ( fli-> family ( ), \ | 390 | return d-> m_fdb. font ( fli-> family ( ), \ |
341 | fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ | 391 | fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ |
342 | fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ | 392 | fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ |
343 | d-> m_fdb. charSets ( fli-> family ( )) [0] ); | 393 | d-> m_fdb. charSets ( fli-> family ( )) [0] ); |
344 | } | 394 | } |
345 | else | 395 | else |
346 | return QFont ( ); | 396 | return QFont ( ); |
@@ -350,13 +400,13 @@ QFont OFontSelector::selectedFont ( ) | |||
350 | void OFontSelector::resizeEvent ( QResizeEvent *re ) | 400 | void OFontSelector::resizeEvent ( QResizeEvent *re ) |
351 | { | 401 | { |
352 | if ( d-> m_preview ) { | 402 | if ( d-> m_preview ) { |
353 | d-> m_preview-> setMinimumHeight ( 1 ); | 403 | d-> m_preview-> setMinimumHeight ( 1 ); |
354 | d-> m_preview-> setMaximumHeight ( 32767 ); | 404 | d-> m_preview-> setMaximumHeight ( 32767 ); |
355 | } | 405 | } |
356 | 406 | ||
357 | QWidget::resizeEvent ( re ); | 407 | QWidget::resizeEvent ( re ); |
358 | 408 | ||
359 | if ( d-> m_preview ) | 409 | if ( d-> m_preview ) |
360 | d-> m_preview-> setFixedHeight ( d-> m_preview-> height ( )); | 410 | d-> m_preview-> setFixedHeight ( d-> m_preview-> height ( )); |
361 | 411 | ||
362 | } | 412 | } |