author | sandman <sandman> | 2002-09-23 22:43:28 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-09-23 22:43:28 (UTC) |
commit | 9360d74a24b3ecf1169ad63996adc897004bd73e (patch) (unidiff) | |
tree | 31687c656b8309ccee3fb5ad1334230b31e6c363 | |
parent | 44e815d58c7565eccab2bd585923e343b70ac0f3 (diff) | |
download | opie-9360d74a24b3ecf1169ad63996adc897004bd73e.zip opie-9360d74a24b3ecf1169ad63996adc897004bd73e.tar.gz opie-9360d74a24b3ecf1169ad63996adc897004bd73e.tar.bz2 |
new OFontSelector - used in Appearance and Launcher settings
-rw-r--r-- | libopie/libopie.pro | 6 | ||||
-rw-r--r-- | libopie/ofontselector.cpp | 277 | ||||
-rw-r--r-- | libopie/ofontselector.h | 79 |
3 files changed, 360 insertions, 2 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro index 6c47e86..4b176d0 100644 --- a/libopie/libopie.pro +++ b/libopie/libopie.pro | |||
@@ -8,7 +8,8 @@ HEADERS = ofontmenu.h ofileselector.h \ | |||
8 | oclickablelabel.h oprocctrl.h \ | 8 | oclickablelabel.h oprocctrl.h \ |
9 | oprocess.h odevice.h \ | 9 | oprocess.h odevice.h \ |
10 | otimepicker.h otabwidget.h \ | 10 | otimepicker.h otabwidget.h \ |
11 | otabbar.h otabinfo.h | 11 | otabbar.h otabinfo.h \ |
12 | ofontselector.h | ||
12 | SOURCES = ofontmenu.cc ofileselector.cc \ | 13 | SOURCES = ofontmenu.cc ofileselector.cc \ |
13 | ofiledialog.cc xmltree.cc \ | 14 | ofiledialog.cc xmltree.cc \ |
14 | tododb.cpp todoevent.cpp \ | 15 | tododb.cpp todoevent.cpp \ |
@@ -16,7 +17,8 @@ SOURCES = ofontmenu.cc ofileselector.cc \ | |||
16 | colorpopupmenu.cpp oclickablelabel.cpp \ | 17 | colorpopupmenu.cpp oclickablelabel.cpp \ |
17 | oprocctrl.cpp oprocess.cpp \ | 18 | oprocctrl.cpp oprocess.cpp \ |
18 | odevice.cpp otimepicker.cpp \ | 19 | odevice.cpp otimepicker.cpp \ |
19 | otabwidget.cpp otabbar.cpp | 20 | otabwidget.cpp otabbar.cpp \ |
21 | ofontselector.cpp | ||
20 | TARGET = opie | 22 | TARGET = opie |
21 | INCLUDEPATH += $(OPIEDIR)/include | 23 | INCLUDEPATH += $(OPIEDIR)/include |
22 | DESTDIR = $(QTDIR)/lib$(PROJMAK) | 24 | DESTDIR = $(QTDIR)/lib$(PROJMAK) |
diff --git a/libopie/ofontselector.cpp b/libopie/ofontselector.cpp new file mode 100644 index 0000000..f6fd541 --- a/dev/null +++ b/libopie/ofontselector.cpp | |||
@@ -0,0 +1,277 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | ||
4 | .>+-= | ||
5 | _;:, .> :=|. This library is free software; you can | ||
6 | .> <`_, > . <= redistribute it and/or modify it under | ||
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This library is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
17 | ..}^=.= = ; Library General Public License for more | ||
18 | ++= -. .` .: details. | ||
19 | : = ...= . :.=- | ||
20 | -. .:....=;==+<; You should have received a copy of the GNU | ||
21 | -_. . . )=. = Library General Public License along with | ||
22 | -- :-=` this library; see the file COPYING.LIB. | ||
23 | If not, write to the Free Software Foundation, | ||
24 | Inc., 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include <qlayout.h> | ||
30 | #include <qlistbox.h> | ||
31 | #include <qcombobox.h> | ||
32 | #include <qlabel.h> | ||
33 | #include <qfont.h> | ||
34 | |||
35 | #include "ofontselector.h" | ||
36 | |||
37 | |||
38 | class FontListItem : public QListBoxText { | ||
39 | public: | ||
40 | FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( ) | ||
41 | { | ||
42 | m_name = t; | ||
43 | m_styles = styles; | ||
44 | m_sizes = sizes; | ||
45 | |||
46 | QString str = t; | ||
47 | str [0] = str [0]. upper ( ); | ||
48 | setText ( str ); | ||
49 | } | ||
50 | |||
51 | QString family ( ) const | ||
52 | { | ||
53 | return m_name; | ||
54 | } | ||
55 | |||
56 | const QStringList &styles ( ) const | ||
57 | { | ||
58 | return m_styles; | ||
59 | } | ||
60 | |||
61 | const QValueList<int> &sizes ( ) const | ||
62 | { | ||
63 | return m_sizes; | ||
64 | } | ||
65 | |||
66 | private: | ||
67 | QStringList m_styles; | ||
68 | QValueList<int> m_sizes; | ||
69 | QString m_name; | ||
70 | }; | ||
71 | |||
72 | |||
73 | static int findItemCB ( QComboBox *box, const QString &str ) | ||
74 | { | ||
75 | for ( int i = 0; i < box-> count ( ); i++ ) { | ||
76 | if ( box-> text ( i ) == str ) | ||
77 | return i; | ||
78 | } | ||
79 | return -1; | ||
80 | } | ||
81 | |||
82 | |||
83 | |||
84 | OFontSelector::OFontSelector ( QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) | ||
85 | { | ||
86 | QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); | ||
87 | gridLayout->setRowStretch ( 4, 10 ); | ||
88 | |||
89 | m_font_family_list = new QListBox( this, "FontListBox" ); | ||
90 | gridLayout->addMultiCellWidget( m_font_family_list, 0, 4, 0, 0 ); | ||
91 | connect( m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); | ||
92 | |||
93 | QLabel *label = new QLabel( tr( "Style" ), this ); | ||
94 | gridLayout->addWidget( label, 0, 1 ); | ||
95 | |||
96 | m_font_style_list = new QComboBox( this, "StyleListBox" ); | ||
97 | connect( m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); | ||
98 | gridLayout->addWidget( m_font_style_list, 1, 1 ); | ||
99 | |||
100 | label = new QLabel( tr( "Size" ), this ); | ||
101 | gridLayout->addWidget( label, 2, 1 ); | ||
102 | |||
103 | m_font_size_list = new QComboBox( this, "SizeListBox" ); | ||
104 | connect( m_font_size_list, SIGNAL( activated( int ) ), | ||
105 | this, SLOT( fontSizeClicked( int ) ) ); | ||
106 | gridLayout->addWidget( m_font_size_list, 3, 1 ); | ||
107 | |||
108 | loadFonts ( m_font_family_list ); | ||
109 | } | ||
110 | |||
111 | OFontSelector::~OFontSelector ( ) | ||
112 | { | ||
113 | } | ||
114 | |||
115 | bool OFontSelector::setSelectedFont ( const QString &family, const QString &styleStr, int size, const QString & /*charset*/ ) | ||
116 | { | ||
117 | if ( size <= 0 ) | ||
118 | size = 10; | ||
119 | QString familyStr = family. isEmpty ( ) ? QString ( "Helvetica" ) : family; | ||
120 | QString sizeStr = QString::number ( size ); | ||
121 | |||
122 | m_font_family_list-> setCurrentItem ( m_font_family_list-> findItem ( familyStr )); | ||
123 | if ( m_font_family_list-> currentItem ( ) < 0 ) | ||
124 | m_font_family_list-> setCurrentItem ( 0 ); | ||
125 | |||
126 | fontFamilyClicked ( m_font_family_list-> currentItem ( )); | ||
127 | |||
128 | m_font_style_list-> setCurrentItem ( findItemCB ( m_font_style_list, styleStr )); | ||
129 | fontStyleClicked ( m_font_style_list-> currentItem ( )); | ||
130 | |||
131 | m_font_size_list-> setCurrentItem ( findItemCB ( m_font_size_list, sizeStr )); | ||
132 | fontSizeClicked ( m_font_size_list-> currentItem ( )); | ||
133 | |||
134 | return (( m_font_family_list-> currentItem ( ) >= 0 ) && | ||
135 | ( m_font_style_list-> currentItem ( ) >= 0 ) && | ||
136 | ( m_font_size_list-> currentItem ( ) >= 0 )); | ||
137 | } | ||
138 | |||
139 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) | ||
140 | { | ||
141 | QString dummy; | ||
142 | return selectedFont ( family, style, size, dummy ); | ||
143 | } | ||
144 | |||
145 | |||
146 | QString OFontSelector::fontFamily ( ) const | ||
147 | { | ||
148 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); | ||
149 | |||
150 | return fli ? fli-> family ( ) : QString::null; | ||
151 | } | ||
152 | |||
153 | QString OFontSelector::fontStyle ( ) const | ||
154 | { | ||
155 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); | ||
156 | int fst = m_font_style_list-> currentItem ( ); | ||
157 | |||
158 | return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null; | ||
159 | } | ||
160 | |||
161 | int OFontSelector::fontSize ( ) const | ||
162 | { | ||
163 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); | ||
164 | int fsi = m_font_size_list-> currentItem ( ); | ||
165 | |||
166 | return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10; | ||
167 | } | ||
168 | |||
169 | QString OFontSelector::fontCharSet ( ) const | ||
170 | { | ||
171 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); | ||
172 | |||
173 | return fli ? m_fdb. charSets ( fli-> family ( )) [0] : QString::null; | ||
174 | } | ||
175 | |||
176 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) | ||
177 | { | ||
178 | int ffa = m_font_family_list-> currentItem ( ); | ||
179 | int fst = m_font_style_list-> currentItem ( ); | ||
180 | int fsi = m_font_size_list-> currentItem ( ); | ||
181 | |||
182 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa ); | ||
183 | |||
184 | if ( fli ) { | ||
185 | family = fli-> family ( ); | ||
186 | style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null; | ||
187 | size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10; | ||
188 | charset = m_fdb. charSets ( fli-> family ( )) [0]; | ||
189 | |||
190 | return true; | ||
191 | } | ||
192 | else | ||
193 | return false; | ||
194 | } | ||
195 | |||
196 | |||
197 | |||
198 | |||
199 | void OFontSelector::loadFonts ( QListBox *list ) | ||
200 | { | ||
201 | QStringList f = m_fdb. families ( ); | ||
202 | |||
203 | for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) | ||
204 | list-> insertItem ( new FontListItem ( *it, m_fdb. styles ( *it ), m_fdb. pointSizes ( *it ))); | ||
205 | } | ||
206 | |||
207 | void OFontSelector::fontFamilyClicked ( int index ) | ||
208 | { | ||
209 | QString oldstyle = m_font_style_list-> currentText ( ); | ||
210 | QString oldsize = m_font_size_list-> currentText ( ); | ||
211 | |||
212 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( index ); | ||
213 | |||
214 | m_font_style_list-> clear ( ); | ||
215 | m_font_style_list-> insertStringList ( fli-> styles ( )); | ||
216 | m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( )); | ||
217 | |||
218 | int i; | ||
219 | |||
220 | i = findItemCB ( m_font_style_list, oldstyle ); | ||
221 | if ( i < 0 ) | ||
222 | i = findItemCB ( m_font_style_list, "Regular" ); | ||
223 | if (( i < 0 ) && ( m_font_style_list-> count ( ) > 0 )) | ||
224 | i = 0; | ||
225 | |||
226 | if ( i >= 0 ) { | ||
227 | m_font_style_list-> setCurrentItem ( i ); | ||
228 | fontStyleClicked ( i ); | ||
229 | } | ||
230 | |||
231 | m_font_size_list-> clear ( ); | ||
232 | QValueList<int> sl = fli-> sizes ( ); | ||
233 | |||
234 | for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) | ||
235 | m_font_size_list-> insertItem ( QString::number ( *it )); | ||
236 | |||
237 | i = findItemCB ( m_font_size_list, oldsize ); | ||
238 | if ( i < 0 ) | ||
239 | i = findItemCB ( m_font_size_list, "10" ); | ||
240 | if (( i < 0 ) && ( m_font_size_list-> count ( ) > 0 )) | ||
241 | i = 0; | ||
242 | |||
243 | if ( i >= 0 ) { | ||
244 | m_font_size_list-> setCurrentItem ( i ); | ||
245 | fontSizeClicked ( i ); | ||
246 | } | ||
247 | changeFont ( ); | ||
248 | } | ||
249 | |||
250 | void OFontSelector::fontStyleClicked ( int /*index*/ ) | ||
251 | { | ||
252 | changeFont ( ); | ||
253 | } | ||
254 | |||
255 | void OFontSelector::fontSizeClicked ( int /*index*/ ) | ||
256 | { | ||
257 | changeFont ( ); | ||
258 | } | ||
259 | |||
260 | void OFontSelector::changeFont ( ) | ||
261 | { | ||
262 | int ffa = m_font_family_list-> currentItem ( ); | ||
263 | int fst = m_font_style_list-> currentItem ( ); | ||
264 | int fsi = m_font_size_list-> currentItem ( ); | ||
265 | |||
266 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa ); | ||
267 | |||
268 | if ( fli ) { | ||
269 | emit fontSelected ( m_fdb. font ( fli-> family ( ), \ | ||
270 | fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ | ||
271 | fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ | ||
272 | m_fdb. charSets ( fli-> family ( )) [0] )); | ||
273 | } | ||
274 | } | ||
275 | |||
276 | |||
277 | \ No newline at end of file | ||
diff --git a/libopie/ofontselector.h b/libopie/ofontselector.h new file mode 100644 index 0000000..9227e48 --- a/dev/null +++ b/libopie/ofontselector.h | |||
@@ -0,0 +1,79 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | ||
4 | .>+-= | ||
5 | _;:, .> :=|. This library is free software; you can | ||
6 | .> <`_, > . <= redistribute it and/or modify it under | ||
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This library is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
17 | ..}^=.= = ; Library General Public License for more | ||
18 | ++= -. .` .: details. | ||
19 | : = ...= . :.=- | ||
20 | -. .:....=;==+<; You should have received a copy of the GNU | ||
21 | -_. . . )=. = Library General Public License along with | ||
22 | -- :-=` this library; see the file COPYING.LIB. | ||
23 | If not, write to the Free Software Foundation, | ||
24 | Inc., 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #ifndef __OPIE_FONTSELECTOR_H__ | ||
30 | #define __OPIE_FONTSELECTOR_H__ | ||
31 | |||
32 | #include <qwidget.h> | ||
33 | #include <qpe/fontdatabase.h> | ||
34 | |||
35 | class QComboBox; | ||
36 | class QListBox; | ||
37 | class QFont; | ||
38 | |||
39 | class OFontSelector : public QWidget | ||
40 | { | ||
41 | Q_OBJECT | ||
42 | |||
43 | public: | ||
44 | OFontSelector ( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | ||
45 | virtual ~OFontSelector ( ); | ||
46 | |||
47 | bool selectedFont ( QString &family, QString &style, int &size ); | ||
48 | bool selectedFont ( QString &family, QString &style, int &size, QString &charset ); | ||
49 | |||
50 | bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 ); | ||
51 | |||
52 | QString fontFamily ( ) const; | ||
53 | QString fontStyle ( ) const; | ||
54 | int fontSize ( ) const; | ||
55 | QString fontCharSet ( ) const; | ||
56 | |||
57 | signals: | ||
58 | void fontSelected ( const QFont & ); | ||
59 | |||
60 | protected slots: | ||
61 | virtual void fontFamilyClicked ( int ); | ||
62 | virtual void fontStyleClicked ( int ); | ||
63 | virtual void fontSizeClicked ( int ); | ||
64 | |||
65 | private: | ||
66 | void loadFonts ( QListBox * ); | ||
67 | |||
68 | void changeFont ( ); | ||
69 | |||
70 | private: | ||
71 | QListBox * m_font_family_list; | ||
72 | QComboBox * m_font_style_list; | ||
73 | QComboBox * m_font_size_list; | ||
74 | |||
75 | FontDatabase m_fdb; | ||
76 | }; | ||
77 | |||
78 | #endif | ||
79 | |||