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