-rw-r--r-- | libopie/ofontselector.cpp | 202 | ||||
-rw-r--r-- | libopie/ofontselector.h | 11 |
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 | |||
@@ -32,8 +32,21 @@ | |||
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 | ||
39 | class OFontSelectorPrivate { | ||
40 | public: | ||
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 | ||
38 | class FontListItem : public QListBoxText { | 51 | class FontListItem : public QListBoxText { |
39 | public: | 52 | public: |
@@ -80,74 +93,84 @@ static int findItemCB ( QComboBox *box, const QString &str ) | |||
80 | } | 93 | } |
81 | 94 | ||
82 | 95 | ||
96 | static 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 | ||
84 | OFontSelector::OFontSelector ( QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) | 104 | OFontSelector::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 | ||
111 | OFontSelector::~OFontSelector ( ) | 135 | OFontSelector::~OFontSelector ( ) |
112 | { | 136 | { |
137 | delete d; | ||
113 | } | 138 | } |
114 | 139 | ||
115 | bool OFontSelector::setSelectedFont ( const QFont &f ) | 140 | bool 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 | ||
120 | bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ ) | 145 | bool 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 | ||
153 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) | 176 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) |
@@ -159,47 +182,47 @@ bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) | |||
159 | 182 | ||
160 | QString OFontSelector::fontFamily ( ) const | 183 | QString 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 | ||
167 | QString OFontSelector::fontStyle ( ) const | 190 | QString 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 | ||
175 | int OFontSelector::fontSize ( ) const | 198 | int 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 | ||
183 | QString OFontSelector::fontCharSet ( ) const | 206 | QString 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 | ||
190 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) | 213 | bool 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 | } |
@@ -208,54 +231,62 @@ bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, Q | |||
208 | } | 231 | } |
209 | 232 | ||
210 | 233 | ||
211 | 234 | ||
212 | 235 | ||
213 | void OFontSelector::loadFonts ( QListBox *list ) | 236 | void 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 | ||
221 | void OFontSelector::fontFamilyClicked ( int index ) | 252 | void 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 ( ); |
@@ -279,21 +310,18 @@ void OFontSelector::changeFont ( ) | |||
279 | 310 | ||
280 | QFont OFontSelector::selectedFont ( ) | 311 | QFont 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 | |||
@@ -30,11 +30,10 @@ | |||
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 | ||
35 | class QComboBox; | ||
36 | class QListBox; | 34 | class QListBox; |
37 | class QFont; | 35 | class OFontSelectorPrivate; |
36 | |||
38 | 37 | ||
39 | class OFontSelector : public QWidget | 38 | class OFontSelector : public QWidget |
40 | { | 39 | { |
@@ -71,11 +70,7 @@ private: | |||
71 | void changeFont ( ); | 70 | void changeFont ( ); |
72 | 71 | ||
73 | private: | 72 | private: |
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 |