summaryrefslogtreecommitdiff
path: root/libopie
authorsandman <sandman>2002-10-01 20:58:30 (UTC)
committer sandman <sandman>2002-10-01 20:58:30 (UTC)
commit2906826d9ebc268bc233f97956ee1dc5b338c69b (patch) (unidiff)
treed6af20025d6ac5e9220a3f1458d1985df8a6cc93 /libopie
parent88bef2791f8e4c99e0e9d34ddfe518b5baa2df72 (diff)
downloadopie-2906826d9ebc268bc233f97956ee1dc5b338c69b.zip
opie-2906826d9ebc268bc233f97956ee1dc5b338c69b.tar.gz
opie-2906826d9ebc268bc233f97956ee1dc5b338c69b.tar.bz2
OFontSelector has now an optional builtin preview widget
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofontselector.cpp51
-rw-r--r--libopie/ofontselector.h5
2 files changed, 47 insertions, 9 deletions
diff --git a/libopie/ofontselector.cpp b/libopie/ofontselector.cpp
index e1090b5..b905474 100644
--- a/libopie/ofontselector.cpp
+++ b/libopie/ofontselector.cpp
@@ -1,327 +1,362 @@
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 35
35#include <qpe/fontdatabase.h> 36#include <qpe/fontdatabase.h>
36 37
37#include "ofontselector.h" 38#include "ofontselector.h"
38 39
39class OFontSelectorPrivate { 40class OFontSelectorPrivate {
40public: 41public:
41 QListBox * m_font_family_list; 42 QListBox * m_font_family_list;
42 QComboBox * m_font_style_list; 43 QComboBox * m_font_style_list;
43 QComboBox * m_font_size_list; 44 QComboBox * m_font_size_list;
45 QMultiLineEdit *m_preview;
44 46
45 bool m_pointbug; 47 bool m_pointbug;
46 48
47 FontDatabase m_fdb; 49 FontDatabase m_fdb;
48}; 50};
49 51
50 52
51class FontListItem : public QListBoxText { 53class FontListItem : public QListBoxText {
52public: 54public:
53 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( ) 55 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( )
54 { 56 {
55 m_name = t; 57 m_name = t;
56 m_styles = styles; 58 m_styles = styles;
57 m_sizes = sizes; 59 m_sizes = sizes;
58 60
59 QString str = t; 61 QString str = t;
60 str [0] = str [0]. upper ( ); 62 str [0] = str [0]. upper ( );
61 setText ( str ); 63 setText ( str );
62 } 64 }
63 65
64 QString family ( ) const 66 QString family ( ) const
65 { 67 {
66 return m_name; 68 return m_name;
67 } 69 }
68 70
69 const QStringList &styles ( ) const 71 const QStringList &styles ( ) const
70 { 72 {
71 return m_styles; 73 return m_styles;
72 } 74 }
73 75
74 const QValueList<int> &sizes ( ) const 76 const QValueList<int> &sizes ( ) const
75 { 77 {
76 return m_sizes; 78 return m_sizes;
77 } 79 }
78 80
79private: 81private:
80 QStringList m_styles; 82 QStringList m_styles;
81 QValueList<int> m_sizes; 83 QValueList<int> m_sizes;
82 QString m_name; 84 QString m_name;
83}; 85};
84 86
85 87
86static int findItemCB ( QComboBox *box, const QString &str ) 88static int findItemCB ( QComboBox *box, const QString &str )
87{ 89{
88 for ( int i = 0; i < box-> count ( ); i++ ) { 90 for ( int i = 0; i < box-> count ( ); i++ ) {
89 if ( box-> text ( i ) == str ) 91 if ( box-> text ( i ) == str )
90 return i; 92 return i;
91 } 93 }
92 return -1; 94 return -1;
93} 95}
94 96
95 97
96static int qt_version ( ) 98static int qt_version ( )
97{ 99{
98 const char *qver = qVersion ( ); 100 const char *qver = qVersion ( );
99 101
100 return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' ); 102 return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' );
101} 103}
102 104
103 105
104OFontSelector::OFontSelector ( QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) 106OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl )
105{ 107{
106 d = new OFontSelectorPrivate ( ); 108 d = new OFontSelectorPrivate ( );
107 109
108 QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); 110 QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 );
109 gridLayout->setRowStretch ( 4, 10 ); 111 gridLayout->setRowStretch ( 4, 10 );
110 112
111 d-> m_font_family_list = new QListBox( this, "FontListBox" ); 113 d-> m_font_family_list = new QListBox( this, "FontListBox" );
112 gridLayout->addMultiCellWidget( d-> m_font_family_list, 0, 4, 0, 0 ); 114 gridLayout->addMultiCellWidget( d-> m_font_family_list, 0, 4, 0, 0 );
113 connect( d-> m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); 115 connect( d-> m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) );
114 116
115 QLabel *label = new QLabel( tr( "Style" ), this ); 117 QLabel *label = new QLabel( tr( "Style" ), this );
116 gridLayout->addWidget( label, 0, 1 ); 118 gridLayout->addWidget( label, 0, 1 );
117 119
118 d-> m_font_style_list = new QComboBox( this, "StyleListBox" ); 120 d-> m_font_style_list = new QComboBox( this, "StyleListBox" );
119 connect( d-> m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); 121 connect( d-> m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) );
120 gridLayout->addWidget( d-> m_font_style_list, 1, 1 ); 122 gridLayout->addWidget( d-> m_font_style_list, 1, 1 );
121 123
122 label = new QLabel( tr( "Size" ), this ); 124 label = new QLabel( tr( "Size" ), this );
123 gridLayout->addWidget( label, 2, 1 ); 125 gridLayout->addWidget( label, 2, 1 );
124 126
125 d-> m_font_size_list = new QComboBox( this, "SizeListBox" ); 127 d-> m_font_size_list = new QComboBox( this, "SizeListBox" );
126 connect( d-> m_font_size_list, SIGNAL( activated( int ) ), 128 connect( d-> m_font_size_list, SIGNAL( activated( int ) ),
127 this, SLOT( fontSizeClicked( int ) ) ); 129 this, SLOT( fontSizeClicked( int ) ) );
128 gridLayout->addWidget( d-> m_font_size_list, 3, 1 ); 130 gridLayout->addWidget( d-> m_font_size_list, 3, 1 );
129 131
130 d-> m_pointbug = ( qt_version ( ) <= 233 ); 132 d-> m_pointbug = ( qt_version ( ) <= 233 );
131 133
134 if ( withpreview ) {
135 d-> m_preview = new QMultiLineEdit ( this, "Preview" );
136 d-> m_preview-> setAlignment ( AlignCenter );
137 d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth );
138 d-> m_preview-> setMargin ( 3 );
139 d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" ));
140 gridLayout-> addRowSpacing ( 5, 4 );
141 gridLayout-> addMultiCellWidget ( d-> m_preview, 6, 6, 0, 1 );
142 gridLayout-> setRowStretch ( 6, 5 );
143 }
144 else
145 d-> m_preview = 0;
146
132 loadFonts ( d-> m_font_family_list ); 147 loadFonts ( d-> m_font_family_list );
133} 148}
134 149
135OFontSelector::~OFontSelector ( ) 150OFontSelector::~OFontSelector ( )
136{ 151{
137 delete d; 152 delete d;
138} 153}
139 154
140bool OFontSelector::setSelectedFont ( const QFont &f ) 155bool OFontSelector::setSelectedFont ( const QFont &f )
141{ 156{
142 return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( ))); 157 return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( )));
143} 158}
144 159
145bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ ) 160bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ )
146{ 161{
147 QString sizeStr = QString::number ( sizeVal ); 162 QString sizeStr = QString::number ( sizeVal );
148 163
149 QListBoxItem *family = d-> m_font_family_list-> findItem ( familyStr ); 164 QListBoxItem *family = d-> m_font_family_list-> findItem ( familyStr );
150 if ( !family ) 165 if ( !family )
151 family = d-> m_font_family_list-> findItem ( "Helvetica" ); 166 family = d-> m_font_family_list-> findItem ( "Helvetica" );
152 if ( !family ) 167 if ( !family )
153 family = d-> m_font_family_list-> firstItem ( ); 168 family = d-> m_font_family_list-> firstItem ( );
154 d-> m_font_family_list-> setCurrentItem ( family ); 169 d-> m_font_family_list-> setCurrentItem ( family );
155 fontFamilyClicked ( d-> m_font_family_list-> index ( family )); 170 fontFamilyClicked ( d-> m_font_family_list-> index ( family ));
156 171
157 int style = findItemCB ( d-> m_font_style_list, styleStr ); 172 int style = findItemCB ( d-> m_font_style_list, styleStr );
158 if ( style < 0 ) 173 if ( style < 0 )
159 style = findItemCB ( d-> m_font_style_list, "Regular" ); 174 style = findItemCB ( d-> m_font_style_list, "Regular" );
160 if ( style < 0 && d-> m_font_style_list-> count ( ) > 0 ) 175 if ( style < 0 && d-> m_font_style_list-> count ( ) > 0 )
161 style = 0; 176 style = 0;
162 d-> m_font_style_list-> setCurrentItem ( style ); 177 d-> m_font_style_list-> setCurrentItem ( style );
163 fontStyleClicked ( style ); 178 fontStyleClicked ( style );
164 179
165 int size = findItemCB ( d-> m_font_size_list, sizeStr ); 180 int size = findItemCB ( d-> m_font_size_list, sizeStr );
166 if ( size < 0 ) 181 if ( size < 0 )
167 size = findItemCB ( d-> m_font_size_list, "10" ); 182 size = findItemCB ( d-> m_font_size_list, "10" );
168 if ( size < 0 && d-> m_font_size_list-> count ( ) > 0 ) 183 if ( size < 0 && d-> m_font_size_list-> count ( ) > 0 )
169 size = 0; 184 size = 0;
170 d-> m_font_size_list-> setCurrentItem ( size ); 185 d-> m_font_size_list-> setCurrentItem ( size );
171 fontSizeClicked ( size ); 186 fontSizeClicked ( size );
172 187
173 return (( family ) && ( style >= 0 ) && ( size >= 0 )); 188 return (( family ) && ( style >= 0 ) && ( size >= 0 ));
174} 189}
175 190
176bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) 191bool OFontSelector::selectedFont ( QString &family, QString &style, int &size )
177{ 192{
178 QString dummy; 193 QString dummy;
179 return selectedFont ( family, style, size, dummy ); 194 return selectedFont ( family, style, size, dummy );
180} 195}
181 196
182 197
183QString OFontSelector::fontFamily ( ) const 198QString OFontSelector::fontFamily ( ) const
184{ 199{
185 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); 200 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
186 201
187 return fli ? fli-> family ( ) : QString::null; 202 return fli ? fli-> family ( ) : QString::null;
188} 203}
189 204
190QString OFontSelector::fontStyle ( ) const 205QString OFontSelector::fontStyle ( ) const
191{ 206{
192 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); 207 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
193 int fst = d-> m_font_style_list-> currentItem ( ); 208 int fst = d-> m_font_style_list-> currentItem ( );
194 209
195 return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null; 210 return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null;
196} 211}
197 212
198int OFontSelector::fontSize ( ) const 213int OFontSelector::fontSize ( ) const
199{ 214{
200 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); 215 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
201 int fsi = d-> m_font_size_list-> currentItem ( ); 216 int fsi = d-> m_font_size_list-> currentItem ( );
202 217
203 return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10; 218 return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10;
204} 219}
205 220
206QString OFontSelector::fontCharSet ( ) const 221QString OFontSelector::fontCharSet ( ) const
207{ 222{
208 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); 223 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
209 224
210 return fli ? d-> m_fdb. charSets ( fli-> family ( )) [0] : QString::null; 225 return fli ? d-> m_fdb. charSets ( fli-> family ( )) [0] : QString::null;
211} 226}
212 227
213bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) 228bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset )
214{ 229{
215 int ffa = d-> m_font_family_list-> currentItem ( ); 230 int ffa = d-> m_font_family_list-> currentItem ( );
216 int fst = d-> m_font_style_list-> currentItem ( ); 231 int fst = d-> m_font_style_list-> currentItem ( );
217 int fsi = d-> m_font_size_list-> currentItem ( ); 232 int fsi = d-> m_font_size_list-> currentItem ( );
218 233
219 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); 234 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa );
220 235
221 if ( fli ) { 236 if ( fli ) {
222 family = fli-> family ( ); 237 family = fli-> family ( );
223 style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null; 238 style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null;
224 size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10; 239 size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10;
225 charset = d-> m_fdb. charSets ( fli-> family ( )) [0]; 240 charset = d-> m_fdb. charSets ( fli-> family ( )) [0];
226 241
227 return true; 242 return true;
228 } 243 }
229 else 244 else
230 return false; 245 return false;
231} 246}
232 247
233 248
234 249
235 250
236void OFontSelector::loadFonts ( QListBox *list ) 251void OFontSelector::loadFonts ( QListBox *list )
237{ 252{
238 QStringList f = d-> m_fdb. families ( ); 253 QStringList f = d-> m_fdb. families ( );
239 254
240 for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) { 255 for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) {
241 QValueList <int> ps = d-> m_fdb. pointSizes ( *it ); 256 QValueList <int> ps = d-> m_fdb. pointSizes ( *it );
242 257
243 if ( d-> m_pointbug ) { 258 if ( d-> m_pointbug ) {
244 for ( QValueList <int>::Iterator it = ps. begin ( ); it != ps. end ( ); it++ ) 259 for ( QValueList <int>::Iterator it = ps. begin ( ); it != ps. end ( ); it++ )
245 *it /= 10; 260 *it /= 10;
246 } 261 }
247 262
248 list-> insertItem ( new FontListItem ( *it, d-> m_fdb. styles ( *it ), ps )); 263 list-> insertItem ( new FontListItem ( *it, d-> m_fdb. styles ( *it ), ps ));
249 } 264 }
250} 265}
251 266
252void OFontSelector::fontFamilyClicked ( int index ) 267void OFontSelector::fontFamilyClicked ( int index )
253{ 268{
254 QString oldstyle = d-> m_font_style_list-> currentText ( ); 269 QString oldstyle = d-> m_font_style_list-> currentText ( );
255 QString oldsize = d-> m_font_size_list-> currentText ( ); 270 QString oldsize = d-> m_font_size_list-> currentText ( );
256 271
257 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( index ); 272 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( index );
258 273
259 d-> m_font_style_list-> clear ( ); 274 d-> m_font_style_list-> clear ( );
260 d-> m_font_style_list-> insertStringList ( fli-> styles ( )); 275 d-> m_font_style_list-> insertStringList ( fli-> styles ( ));
261 d-> m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( )); 276 d-> m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( ));
262 277
263 int i; 278 int i;
264 279
265 i = findItemCB ( d-> m_font_style_list, oldstyle ); 280 i = findItemCB ( d-> m_font_style_list, oldstyle );
266 if ( i < 0 ) 281 if ( i < 0 )
267 i = findItemCB ( d-> m_font_style_list, "Regular" ); 282 i = findItemCB ( d-> m_font_style_list, "Regular" );
268 if (( i < 0 ) && ( d-> m_font_style_list-> count ( ) > 0 )) 283 if (( i < 0 ) && ( d-> m_font_style_list-> count ( ) > 0 ))
269 i = 0; 284 i = 0;
270 285
271 if ( i >= 0 ) { 286 if ( i >= 0 ) {
272 d-> m_font_style_list-> setCurrentItem ( i ); 287 d-> m_font_style_list-> setCurrentItem ( i );
273 fontStyleClicked ( i ); 288 fontStyleClicked ( i );
274 } 289 }
275 290
276 d-> m_font_size_list-> clear ( ); 291 d-> m_font_size_list-> clear ( );
277 QValueList<int> sl = fli-> sizes ( ); 292 QValueList<int> sl = fli-> sizes ( );
278 293
279 for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) 294 for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
280 d-> m_font_size_list-> insertItem ( QString::number ( *it )); 295 d-> m_font_size_list-> insertItem ( QString::number ( *it ));
281 296
282 i = findItemCB ( d-> m_font_size_list, oldsize ); 297 i = findItemCB ( d-> m_font_size_list, oldsize );
283 if ( i < 0 ) 298 if ( i < 0 )
284 i = findItemCB ( d-> m_font_size_list, "10" ); 299 i = findItemCB ( d-> m_font_size_list, "10" );
285 if (( i < 0 ) && ( d-> m_font_size_list-> count ( ) > 0 )) 300 if (( i < 0 ) && ( d-> m_font_size_list-> count ( ) > 0 ))
286 i = 0; 301 i = 0;
287 302
288 if ( i >= 0 ) { 303 if ( i >= 0 ) {
289 d-> m_font_size_list-> setCurrentItem ( i ); 304 d-> m_font_size_list-> setCurrentItem ( i );
290 fontSizeClicked ( i ); 305 fontSizeClicked ( i );
291 } 306 }
292 changeFont ( ); 307 changeFont ( );
293} 308}
294 309
295void OFontSelector::fontStyleClicked ( int /*index*/ ) 310void OFontSelector::fontStyleClicked ( int /*index*/ )
296{ 311{
297 changeFont ( ); 312 changeFont ( );
298} 313}
299 314
300void OFontSelector::fontSizeClicked ( int /*index*/ ) 315void OFontSelector::fontSizeClicked ( int /*index*/ )
301{ 316{
302 changeFont ( ); 317 changeFont ( );
303} 318}
304 319
305void OFontSelector::changeFont ( ) 320void OFontSelector::changeFont ( )
306{ 321{
307 emit fontSelected ( selectedFont ( )); 322 QFont f = selectedFont ( );
323
324 if ( d-> m_preview )
325 d-> m_preview-> setFont ( f );
326
327 emit fontSelected ( f );
308} 328}
309 329
310 330
311QFont OFontSelector::selectedFont ( ) 331QFont OFontSelector::selectedFont ( )
312{ 332{
313 int ffa = d-> m_font_family_list-> currentItem ( ); 333 int ffa = d-> m_font_family_list-> currentItem ( );
314 int fst = d-> m_font_style_list-> currentItem ( ); 334 int fst = d-> m_font_style_list-> currentItem ( );
315 int fsi = d-> m_font_size_list-> currentItem ( ); 335 int fsi = d-> m_font_size_list-> currentItem ( );
316 336
317 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); 337 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa );
318 338
319 if ( fli ) { 339 if ( fli ) {
320 return d-> m_fdb. font ( fli-> family ( ), \ 340 return d-> m_fdb. font ( fli-> family ( ), \
321 fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ 341 fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \
322 fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ 342 fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \
323 d-> m_fdb. charSets ( fli-> family ( )) [0] ); 343 d-> m_fdb. charSets ( fli-> family ( )) [0] );
324 } 344 }
325 else 345 else
326 return QFont ( ); 346 return QFont ( );
327} 347}
348
349
350void OFontSelector::resizeEvent ( QResizeEvent *re )
351{
352 if ( d-> m_preview ) {
353 d-> m_preview-> setMinimumHeight ( 1 );
354 d-> m_preview-> setMaximumHeight ( 32767 );
355 }
356
357 QWidget::resizeEvent ( re );
358
359 if ( d-> m_preview )
360 d-> m_preview-> setFixedHeight ( d-> m_preview-> height ( ));
361
362}
diff --git a/libopie/ofontselector.h b/libopie/ofontselector.h
index a9c8a72..10d16f0 100644
--- a/libopie/ofontselector.h
+++ b/libopie/ofontselector.h
@@ -1,77 +1,80 @@
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#ifndef __OPIE_FONTSELECTOR_H__ 29#ifndef __OPIE_FONTSELECTOR_H__
30#define __OPIE_FONTSELECTOR_H__ 30#define __OPIE_FONTSELECTOR_H__
31 31
32#include <qwidget.h> 32#include <qwidget.h>
33 33
34class QListBox; 34class QListBox;
35class OFontSelectorPrivate; 35class OFontSelectorPrivate;
36 36
37 37
38class OFontSelector : public QWidget 38class OFontSelector : public QWidget
39{ 39{
40 Q_OBJECT 40 Q_OBJECT
41 41
42public: 42public:
43 OFontSelector ( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 43 OFontSelector ( bool withpreview, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
44 virtual ~OFontSelector ( ); 44 virtual ~OFontSelector ( );
45 45
46 bool selectedFont ( QString &family, QString &style, int &size ); 46 bool selectedFont ( QString &family, QString &style, int &size );
47 bool selectedFont ( QString &family, QString &style, int &size, QString &charset ); 47 bool selectedFont ( QString &family, QString &style, int &size, QString &charset );
48 48
49 QFont selectedFont ( ); 49 QFont selectedFont ( );
50 50
51 bool setSelectedFont ( const QFont & ); 51 bool setSelectedFont ( const QFont & );
52 bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 ); 52 bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 );
53 53
54 QString fontFamily ( ) const; 54 QString fontFamily ( ) const;
55 QString fontStyle ( ) const; 55 QString fontStyle ( ) const;
56 int fontSize ( ) const; 56 int fontSize ( ) const;
57 QString fontCharSet ( ) const; 57 QString fontCharSet ( ) const;
58 58
59signals: 59signals:
60 void fontSelected ( const QFont & ); 60 void fontSelected ( const QFont & );
61 61
62protected slots: 62protected slots:
63 virtual void fontFamilyClicked ( int ); 63 virtual void fontFamilyClicked ( int );
64 virtual void fontStyleClicked ( int ); 64 virtual void fontStyleClicked ( int );
65 virtual void fontSizeClicked ( int ); 65 virtual void fontSizeClicked ( int );
66 66
67protected:
68 virtual void resizeEvent ( QResizeEvent *re );
69
67private: 70private:
68 void loadFonts ( QListBox * ); 71 void loadFonts ( QListBox * );
69 72
70 void changeFont ( ); 73 void changeFont ( );
71 74
72private: 75private:
73 OFontSelectorPrivate *d; 76 OFontSelectorPrivate *d;
74}; 77};
75 78
76#endif 79#endif
77 80