-rw-r--r-- | libopie/ofontselector.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/libopie/ofontselector.cpp b/libopie/ofontselector.cpp index 7e07008..87b7869 100644 --- a/libopie/ofontselector.cpp +++ b/libopie/ofontselector.cpp | |||
@@ -26,207 +26,207 @@ | |||
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 <qmultilineedit.h> | 33 | #include <qmultilineedit.h> |
34 | 34 | ||
35 | #include <qpe/fontdatabase.h> | 35 | #include <qpe/fontdatabase.h> |
36 | 36 | ||
37 | #include "ofontselector.h" | 37 | #include "ofontselector.h" |
38 | 38 | ||
39 | class OFontSelectorPrivate { | 39 | class OFontSelectorPrivate { |
40 | public: | 40 | public: |
41 | QListBox * m_font_family_list; | 41 | QListBox * m_font_family_list; |
42 | QComboBox * m_font_style_list; | 42 | QComboBox * m_font_style_list; |
43 | QComboBox * m_font_size_list; | 43 | QComboBox * m_font_size_list; |
44 | QMultiLineEdit *m_preview; | 44 | QMultiLineEdit *m_preview; |
45 | 45 | ||
46 | bool m_pointbug : 1; | 46 | bool m_pointbug : 1; |
47 | 47 | ||
48 | FontDatabase m_fdb; | 48 | FontDatabase m_fdb; |
49 | }; | 49 | }; |
50 | 50 | ||
51 | namespace { | 51 | namespace { |
52 | 52 | ||
53 | class FontListItem : public QListBoxText { | 53 | class FontListItem : public QListBoxText { |
54 | public: | 54 | public: |
55 | 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 ( ) |
56 | { | 56 | { |
57 | m_name = t; | 57 | m_name = t; |
58 | m_styles = styles; | 58 | m_styles = styles; |
59 | m_sizes = sizes; | 59 | m_sizes = sizes; |
60 | 60 | ||
61 | QString str = t; | 61 | QString str = t; |
62 | str [0] = str [0]. upper ( ); | 62 | str [0] = str [0]. upper ( ); |
63 | setText ( str ); | 63 | setText ( str ); |
64 | } | 64 | } |
65 | 65 | ||
66 | QString family ( ) const | 66 | QString family ( ) const |
67 | { | 67 | { |
68 | return m_name; | 68 | return m_name; |
69 | } | 69 | } |
70 | 70 | ||
71 | const QStringList &styles ( ) const | 71 | const QStringList &styles ( ) const |
72 | { | 72 | { |
73 | return m_styles; | 73 | return m_styles; |
74 | } | 74 | } |
75 | 75 | ||
76 | const QValueList<int> &sizes ( ) const | 76 | const QValueList<int> &sizes ( ) const |
77 | { | 77 | { |
78 | return m_sizes; | 78 | return m_sizes; |
79 | } | 79 | } |
80 | 80 | ||
81 | private: | 81 | private: |
82 | QStringList m_styles; | 82 | QStringList m_styles; |
83 | QValueList<int> m_sizes; | 83 | QValueList<int> m_sizes; |
84 | QString m_name; | 84 | QString m_name; |
85 | }; | 85 | }; |
86 | 86 | ||
87 | 87 | ||
88 | static int findItemCB ( QComboBox *box, const QString &str ) | 88 | static int findItemCB ( QComboBox *box, const QString &str ) |
89 | { | 89 | { |
90 | for ( int i = 0; i < box-> count ( ); i++ ) { | 90 | for ( int i = 0; i < box-> count ( ); i++ ) { |
91 | if ( box-> text ( i ) == str ) | 91 | if ( box-> text ( i ) == str ) |
92 | return i; | 92 | return i; |
93 | } | 93 | } |
94 | return -1; | 94 | return -1; |
95 | } | 95 | } |
96 | 96 | ||
97 | } | 97 | } |
98 | /* static same as anon. namespace */ | 98 | /* static same as anon. namespace */ |
99 | static int qt_version ( ) | 99 | static int qt_version ( ) |
100 | { | 100 | { |
101 | const char *qver = qVersion ( ); | 101 | const char *qver = qVersion ( ); |
102 | 102 | ||
103 | return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' ); | 103 | return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' ); |
104 | } | 104 | } |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * Constructs the Selector object | 107 | * Constructs the Selector object |
108 | * @param withpreview If a font preview should be given | 108 | * @param withpreview If a font preview should be given |
109 | * @param parent The parent of the Font Selector | 109 | * @param parent The parent of the Font Selector |
110 | * @param name The name of the object | 110 | * @param name The name of the object |
111 | * @param fl WidgetFlags | 111 | * @param fl WidgetFlags |
112 | */ | 112 | */ |
113 | OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) | 113 | OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) |
114 | { | 114 | { |
115 | d = new OFontSelectorPrivate ( ); | 115 | d = new OFontSelectorPrivate ( ); |
116 | 116 | ||
117 | QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); | 117 | QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); |
118 | gridLayout->setRowStretch ( 4, 10 ); | 118 | gridLayout->setRowStretch ( 4, 10 ); |
119 | 119 | ||
120 | d-> m_font_family_list = new QListBox( this, "FontListBox" ); | 120 | d-> m_font_family_list = new QListBox( this, "FontListBox" ); |
121 | gridLayout->addMultiCellWidget( d-> m_font_family_list, 0, 4, 0, 0 ); | 121 | gridLayout->addMultiCellWidget( d-> m_font_family_list, 0, 4, 0, 0 ); |
122 | connect( d-> m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); | 122 | connect( d-> m_font_family_list, SIGNAL( highlighted(int) ), this, SLOT( fontFamilyClicked(int) ) ); |
123 | 123 | ||
124 | QLabel *label = new QLabel( tr( "Style" ), this ); | 124 | QLabel *label = new QLabel( tr( "Style" ), this ); |
125 | gridLayout->addWidget( label, 0, 1 ); | 125 | gridLayout->addWidget( label, 0, 1 ); |
126 | 126 | ||
127 | d-> m_font_style_list = new QComboBox( this, "StyleListBox" ); | 127 | d-> m_font_style_list = new QComboBox( this, "StyleListBox" ); |
128 | connect( d-> m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); | 128 | connect( d-> m_font_style_list, SIGNAL( activated(int) ), this, SLOT( fontStyleClicked(int) ) ); |
129 | gridLayout->addWidget( d-> m_font_style_list, 1, 1 ); | 129 | gridLayout->addWidget( d-> m_font_style_list, 1, 1 ); |
130 | 130 | ||
131 | label = new QLabel( tr( "Size" ), this ); | 131 | label = new QLabel( tr( "Size" ), this ); |
132 | gridLayout->addWidget( label, 2, 1 ); | 132 | gridLayout->addWidget( label, 2, 1 ); |
133 | 133 | ||
134 | d-> m_font_size_list = new QComboBox( this, "SizeListBox" ); | 134 | d-> m_font_size_list = new QComboBox( this, "SizeListBox" ); |
135 | connect( d-> m_font_size_list, SIGNAL( activated( int ) ), | 135 | connect( d-> m_font_size_list, SIGNAL( activated(int) ), |
136 | this, SLOT( fontSizeClicked( int ) ) ); | 136 | this, SLOT( fontSizeClicked(int) ) ); |
137 | gridLayout->addWidget( d-> m_font_size_list, 3, 1 ); | 137 | gridLayout->addWidget( d-> m_font_size_list, 3, 1 ); |
138 | 138 | ||
139 | d-> m_pointbug = ( qt_version ( ) <= 233 ); | 139 | d-> m_pointbug = ( qt_version ( ) <= 233 ); |
140 | 140 | ||
141 | if ( withpreview ) { | 141 | if ( withpreview ) { |
142 | d-> m_preview = new QMultiLineEdit ( this, "Preview" ); | 142 | d-> m_preview = new QMultiLineEdit ( this, "Preview" ); |
143 | d-> m_preview-> setAlignment ( AlignCenter ); | 143 | d-> m_preview-> setAlignment ( AlignCenter ); |
144 | d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth ); | 144 | d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth ); |
145 | d-> m_preview-> setMargin ( 3 ); | 145 | d-> m_preview-> setMargin ( 3 ); |
146 | d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); | 146 | d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); |
147 | gridLayout-> addRowSpacing ( 5, 4 ); | 147 | gridLayout-> addRowSpacing ( 5, 4 ); |
148 | gridLayout-> addMultiCellWidget ( d-> m_preview, 6, 6, 0, 1 ); | 148 | gridLayout-> addMultiCellWidget ( d-> m_preview, 6, 6, 0, 1 ); |
149 | gridLayout-> setRowStretch ( 6, 5 ); | 149 | gridLayout-> setRowStretch ( 6, 5 ); |
150 | } | 150 | } |
151 | else | 151 | else |
152 | d-> m_preview = 0; | 152 | d-> m_preview = 0; |
153 | 153 | ||
154 | loadFonts ( d-> m_font_family_list ); | 154 | loadFonts ( d-> m_font_family_list ); |
155 | } | 155 | } |
156 | 156 | ||
157 | OFontSelector::~OFontSelector ( ) | 157 | OFontSelector::~OFontSelector ( ) |
158 | { | 158 | { |
159 | delete d; | 159 | delete d; |
160 | } | 160 | } |
161 | 161 | ||
162 | /** | 162 | /** |
163 | * This methods tries to set the font | 163 | * This methods tries to set the font |
164 | * @param f The wishes font | 164 | * @param f The wishes font |
165 | * @return success or failure | 165 | * @return success or failure |
166 | */ | 166 | */ |
167 | bool OFontSelector::setSelectedFont ( const QFont &f ) | 167 | bool OFontSelector::setSelectedFont ( const QFont &f ) |
168 | { | 168 | { |
169 | return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( ))); | 169 | return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( ))); |
170 | } | 170 | } |
171 | 171 | ||
172 | 172 | ||
173 | /** | 173 | /** |
174 | * This is an overloaded method @see setSelectedFont | 174 | * This is an overloaded method @see setSelectedFont |
175 | * @param familyStr The family of the font | 175 | * @param familyStr The family of the font |
176 | * @param styleStr The style of the font | 176 | * @param styleStr The style of the font |
177 | * @param sizeVal The size of font | 177 | * @param sizeVal The size of font |
178 | * @param charset The charset to be used. Will be deprecated by QT3 | 178 | * @param charset The charset to be used. Will be deprecated by QT3 |
179 | */ | 179 | */ |
180 | bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) | 180 | bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) |
181 | { | 181 | { |
182 | QString sizeStr = QString::number ( sizeVal ); | 182 | QString sizeStr = QString::number ( sizeVal ); |
183 | 183 | ||
184 | QListBoxItem *family = d-> m_font_family_list-> findItem ( familyStr ); | 184 | QListBoxItem *family = d-> m_font_family_list-> findItem ( familyStr ); |
185 | if ( !family ) | 185 | if ( !family ) |
186 | family = d-> m_font_family_list-> findItem ( "Helvetica" ); | 186 | family = d-> m_font_family_list-> findItem ( "Helvetica" ); |
187 | if ( !family ) | 187 | if ( !family ) |
188 | family = d-> m_font_family_list-> firstItem ( ); | 188 | family = d-> m_font_family_list-> firstItem ( ); |
189 | d-> m_font_family_list-> setCurrentItem ( family ); | 189 | d-> m_font_family_list-> setCurrentItem ( family ); |
190 | fontFamilyClicked ( d-> m_font_family_list-> index ( family )); | 190 | fontFamilyClicked ( d-> m_font_family_list-> index ( family )); |
191 | 191 | ||
192 | int style = findItemCB ( d-> m_font_style_list, styleStr ); | 192 | int style = findItemCB ( d-> m_font_style_list, styleStr ); |
193 | if ( style < 0 ) | 193 | if ( style < 0 ) |
194 | style = findItemCB ( d-> m_font_style_list, "Regular" ); | 194 | style = findItemCB ( d-> m_font_style_list, "Regular" ); |
195 | if ( style < 0 && d-> m_font_style_list-> count ( ) > 0 ) | 195 | if ( style < 0 && d-> m_font_style_list-> count ( ) > 0 ) |
196 | style = 0; | 196 | style = 0; |
197 | d-> m_font_style_list-> setCurrentItem ( style ); | 197 | d-> m_font_style_list-> setCurrentItem ( style ); |
198 | fontStyleClicked ( style ); | 198 | fontStyleClicked ( style ); |
199 | 199 | ||
200 | int size = findItemCB ( d-> m_font_size_list, sizeStr ); | 200 | int size = findItemCB ( d-> m_font_size_list, sizeStr ); |
201 | if ( size < 0 ) | 201 | if ( size < 0 ) |
202 | size = findItemCB ( d-> m_font_size_list, "10" ); | 202 | size = findItemCB ( d-> m_font_size_list, "10" ); |
203 | if ( size < 0 && d-> m_font_size_list-> count ( ) > 0 ) | 203 | if ( size < 0 && d-> m_font_size_list-> count ( ) > 0 ) |
204 | size = 0; | 204 | size = 0; |
205 | d-> m_font_size_list-> setCurrentItem ( size ); | 205 | d-> m_font_size_list-> setCurrentItem ( size ); |
206 | fontSizeClicked ( size ); | 206 | fontSizeClicked ( size ); |
207 | 207 | ||
208 | return (( family ) && ( style >= 0 ) && ( size >= 0 )); | 208 | return (( family ) && ( style >= 0 ) && ( size >= 0 )); |
209 | } | 209 | } |
210 | 210 | ||
211 | /** | 211 | /** |
212 | * This method returns the name, style and size of the currently selected | 212 | * This method returns the name, style and size of the currently selected |
213 | * font or false if no font is selected | 213 | * font or false if no font is selected |
214 | * @param family The font family will be written there | 214 | * @param family The font family will be written there |
215 | * @param style The style will be written there | 215 | * @param style The style will be written there |
216 | * @param size The size will be written there | 216 | * @param size The size will be written there |
217 | * @return success or failure | 217 | * @return success or failure |
218 | */ | 218 | */ |
219 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) | 219 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) |
220 | { | 220 | { |
221 | QString dummy; | 221 | QString dummy; |
222 | return selectedFont ( family, style, size, dummy ); | 222 | return selectedFont ( family, style, size, dummy ); |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | /** | 226 | /** |
227 | * This method does return the font family or QString::null if there is | 227 | * This method does return the font family or QString::null if there is |
228 | * no font item selected | 228 | * no font item selected |
229 | * @return the font family | 229 | * @return the font family |
230 | */ | 230 | */ |
231 | QString OFontSelector::fontFamily ( ) const | 231 | QString OFontSelector::fontFamily ( ) const |
232 | { | 232 | { |