Diffstat (limited to 'noncore/apps/opie-gutenbrowser/fontDialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-gutenbrowser/fontDialog.cpp | 260 |
1 files changed, 260 insertions, 0 deletions
diff --git a/noncore/apps/opie-gutenbrowser/fontDialog.cpp b/noncore/apps/opie-gutenbrowser/fontDialog.cpp new file mode 100644 index 0000000..a17b1d3 --- a/dev/null +++ b/noncore/apps/opie-gutenbrowser/fontDialog.cpp | |||
@@ -0,0 +1,260 @@ | |||
1 | /**************************************************************************** | ||
2 | ** Created: Sun Jan 27 11:03:24 2002 | ||
3 | copyright 2002 by L.J. Potter ljp@llornkcor.com | ||
4 | copyright : (C) 2000 -2004 by llornkcor | ||
5 | email : ljp@llornkcor.com | ||
6 | ****************************************************************************/ | ||
7 | #include "fontDialog.h" | ||
8 | #include "optionsDialog.h" | ||
9 | |||
10 | #include <qpe/fontdatabase.h> | ||
11 | #include <qpe/config.h> | ||
12 | |||
13 | #include <qstringlist.h> | ||
14 | #include <qfontinfo.h> | ||
15 | #include <qvaluelist.h> | ||
16 | #include <qpe/qpeapplication.h> | ||
17 | |||
18 | #include <qgroupbox.h> | ||
19 | #include <qlabel.h> | ||
20 | #include <qlistbox.h> | ||
21 | #include <qmultilineedit.h> | ||
22 | #include <qpushbutton.h> | ||
23 | #include <qlayout.h> | ||
24 | #include <qvariant.h> | ||
25 | #include <qtooltip.h> | ||
26 | #include <qwhatsthis.h> | ||
27 | #include <qcombobox.h> | ||
28 | |||
29 | //#define BUGGY_SHARP_ZAURUS 0 | ||
30 | |||
31 | static const int nfontsizes = 9; | ||
32 | static const int fontsize[nfontsizes] = {8,9,10,11,12,13,14,18,24}; | ||
33 | |||
34 | |||
35 | FontDialog::FontDialog( QWidget * parent, const char* name /*, bool modal, WFlags fl */) | ||
36 | :/* QDialog*/ QWidget( parent, name /*, modal, fl */) | ||
37 | { | ||
38 | if ( !name ) | ||
39 | setName( "FontDialog" ); | ||
40 | setCaption( tr( "Font Dialog" ) ); | ||
41 | |||
42 | QGridLayout *layout = new QGridLayout( this ); | ||
43 | layout->setSpacing(2); | ||
44 | layout->setMargin(2); | ||
45 | |||
46 | familyListBox = new QListBox( this, "familyListBox" ); | ||
47 | layout->addMultiCellWidget( familyListBox, 0, 2, 0, 0); | ||
48 | |||
49 | QBoxLayout * hbox = new QHBoxLayout(this); | ||
50 | QBoxLayout * vbox = new QVBoxLayout(this); | ||
51 | |||
52 | styleListBox = new QListBox( this, "styleListBox" ); | ||
53 | vbox->addWidget( styleListBox, 0); | ||
54 | |||
55 | FontTextLabel4 = new QLabel( this, "TextLabel4" ); | ||
56 | FontTextLabel4->setText( tr( "Size" ) ); | ||
57 | hbox->addWidget( FontTextLabel4,0); | ||
58 | |||
59 | sizeComboBox = new QComboBox( FALSE, this, "SizeCombo"); | ||
60 | // sizeComboBox->setMaximumWidth(60); | ||
61 | hbox->addWidget( sizeComboBox, 0); | ||
62 | |||
63 | vbox->addLayout(hbox,0); | ||
64 | layout->addLayout( vbox,0,3); | ||
65 | |||
66 | MultiLineEdit1 = new QMultiLineEdit( this, "MultiLineEdit1" ); | ||
67 | MultiLineEdit1->setText( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" ) ); | ||
68 | MultiLineEdit1->setWordWrap( QMultiLineEdit::WidgetWidth); | ||
69 | |||
70 | layout->addMultiCellWidget( MultiLineEdit1, 4, 4, 0, 3); | ||
71 | |||
72 | connect(familyListBox,SIGNAL(highlighted(const QString &)),SLOT(familyListBoxSlot(const QString &))); | ||
73 | connect(styleListBox,SIGNAL(highlighted(const QString &)),SLOT(styleListBoxSlot(const QString &))); | ||
74 | connect(sizeComboBox,SIGNAL(activated(const QString &)),SLOT(sizeComboBoxSlot(const QString &))); | ||
75 | |||
76 | populateLists(); | ||
77 | |||
78 | } | ||
79 | |||
80 | FontDialog::~FontDialog() | ||
81 | { | ||
82 | } | ||
83 | |||
84 | void FontDialog::familyListBoxSlot(const QString & text) | ||
85 | { | ||
86 | int styleInt = styleListBox->currentItem(); | ||
87 | int sizeInt = sizeComboBox->currentText().toInt(); | ||
88 | |||
89 | sizeComboBox->clear(); | ||
90 | styleListBox->clear(); | ||
91 | // clearListBoxes(); | ||
92 | family = text; | ||
93 | // qDebug(family); | ||
94 | QStringList styles = fdb.styles( family ); // string list of styles of our current font family | ||
95 | styleListBox->insertStringList( styles); | ||
96 | QString dstyle;// = "\t" + style + " ("; | ||
97 | |||
98 | #ifdef BUGGY_SHARP_ZAURUS | ||
99 | |||
100 | QValueList<int> smoothies = fdb.smoothSizes( family, styleListBox->text(0) ); | ||
101 | for ( QValueList<int>::Iterator points = smoothies.begin(); points != smoothies.end(); ++points ) { | ||
102 | dstyle = QString::number( *points ); | ||
103 | qDebug(dstyle); | ||
104 | sizeComboBox->insertItem( dstyle.left( dstyle.length() - 1 )); | ||
105 | } | ||
106 | #else | ||
107 | |||
108 | for (int i=0; i<nfontsizes; i++) { | ||
109 | sizeComboBox->insertItem( QString::number(fontsize[i])); | ||
110 | if(fontsize[i] == sizeInt) { | ||
111 | sizeComboBox->setCurrentItem(i); | ||
112 | } | ||
113 | } | ||
114 | #endif | ||
115 | |||
116 | if(styleInt == -1 || styleInt > styleListBox->count() ) | ||
117 | styleListBox->setCurrentItem(0); | ||
118 | else | ||
119 | styleListBox->setCurrentItem(styleInt); | ||
120 | |||
121 | changeText(); | ||
122 | } | ||
123 | |||
124 | void FontDialog::styleListBoxSlot(const QString &text) | ||
125 | { | ||
126 | changeText(); | ||
127 | } | ||
128 | |||
129 | void FontDialog::sizeComboBoxSlot(const QString & text) | ||
130 | { | ||
131 | changeText(); | ||
132 | } | ||
133 | |||
134 | void FontDialog::populateLists() | ||
135 | { | ||
136 | // QFont defaultFont=MultiLineEdit1->font(); | ||
137 | // QFont defaultFont=Lview->font(); | ||
138 | // QFontInfo fontInfo(defaultFont); | ||
139 | Config config("Gutenbrowser"); | ||
140 | config.setGroup("Font"); | ||
141 | QString familyStr = config.readEntry("Family", "fixed"); | ||
142 | QString styleStr = config.readEntry("Style", "Regular"); | ||
143 | QString sizeStr = config.readEntry("Size", "10"); | ||
144 | QString charSetStr = config.readEntry("CharSet", "iso10646-1" ); | ||
145 | bool ok; | ||
146 | int i_size = sizeStr.toInt(&ok,10); | ||
147 | selectedFont = fdb.font(familyStr,styleStr,i_size,charSetStr); | ||
148 | // defaultFont.setItalic(TRUE); | ||
149 | families = fdb.families(); | ||
150 | |||
151 | for ( QStringList::Iterator f = families.begin(); f != families.end();++f ) { | ||
152 | QString family = *f; | ||
153 | // if(family == defaultFont.family()) | ||
154 | // qDebug(family); | ||
155 | familyListBox->insertItem( family); | ||
156 | |||
157 | if( familyListBox->text(0) == family) { | ||
158 | QStringList styles = fdb.styles( family ); | ||
159 | // string list of styles of our current font family | ||
160 | styleListBox->insertStringList( styles); | ||
161 | |||
162 | for ( QStringList::Iterator s = styles.begin(); s != styles.end();++s ) { // for each font style | ||
163 | style = *s; | ||
164 | QString dstyle;// = "\t" + style + " ("; | ||
165 | if(styleListBox->text(0) == style) { | ||
166 | |||
167 | QValueList<int> smoothies = fdb.smoothSizes( family, style ); | ||
168 | for ( QValueList<int>::Iterator points = smoothies.begin(); points != smoothies.end(); ++points ) { | ||
169 | dstyle = QString::number( *points ) + " "; | ||
170 | sizeComboBox ->insertItem( dstyle.left( dstyle.length() - 1 )); | ||
171 | } | ||
172 | dstyle = dstyle.left( dstyle.length() - 1 ) + ")"; | ||
173 | } | ||
174 | } // styles | ||
175 | } | ||
176 | } | ||
177 | for(int i=0;i < familyListBox->count();i++) { | ||
178 | if( familyListBox->text(i) == familyStr) | ||
179 | familyListBox->setSelected( i, TRUE); | ||
180 | } | ||
181 | |||
182 | for(int i=0;i < styleListBox->count();i++) { | ||
183 | if( styleListBox->text(i) == styleStr) | ||
184 | styleListBox->setSelected( i, TRUE); | ||
185 | } | ||
186 | |||
187 | for (int i=0; i<sizeComboBox->count(); i++) { | ||
188 | |||
189 | #ifdef BUGGY_SHARP_ZAURUS | ||
190 | if(sizeComboBox->text(i) == sizeStr) | ||
191 | #else | ||
192 | if(fontsize[i] == i_size) | ||
193 | #endif | ||
194 | sizeComboBox->setCurrentItem(i); | ||
195 | } | ||
196 | changeText(); | ||
197 | } | ||
198 | |||
199 | void FontDialog::clearListBoxes() { | ||
200 | familyListBox->clear(); | ||
201 | sizeComboBox->clear(); | ||
202 | styleListBox->clear(); | ||
203 | } | ||
204 | |||
205 | void FontDialog::changeText() | ||
206 | { | ||
207 | if( familyListBox->currentItem() == -1) | ||
208 | family= familyListBox->text(0); | ||
209 | else { | ||
210 | family = familyListBox->currentText(); | ||
211 | } | ||
212 | // qDebug("Font family is "+family); | ||
213 | if( styleListBox->currentItem() == -1) | ||
214 | style=styleListBox->text(0); | ||
215 | else { | ||
216 | style = styleListBox->currentText(); | ||
217 | } | ||
218 | // qDebug("font style is "+style); | ||
219 | |||
220 | if( sizeComboBox->currentItem() == -1 ) | ||
221 | size = sizeComboBox->text(0); | ||
222 | else { | ||
223 | size = sizeComboBox->currentText(); | ||
224 | } | ||
225 | |||
226 | // qDebug("Font size is "+size); | ||
227 | bool ok; | ||
228 | int i_size = size.toInt(&ok,10); | ||
229 | QStringList charSetList = fdb.charSets(family); | ||
230 | // QStringList styles = fdb.styles( family ); // string list of styles of our current font family | ||
231 | QString charSet; | ||
232 | for ( QStringList::Iterator s = charSetList.begin(); s != charSetList.end();++s ) { // for each font style | ||
233 | charSet = *s; | ||
234 | // qDebug(charSet); | ||
235 | } | ||
236 | selectedFont = fdb.font(family,style,i_size,charSet); | ||
237 | QFontInfo fontInfo( selectedFont); | ||
238 | // if(fontInfo.italic() ) qDebug("italic"); | ||
239 | selectedFont.setWeight(fontInfo.weight() ); | ||
240 | // qDebug("Style are "+style+" %d ",fontInfo.weight()); | ||
241 | Config cfg("Gutenbrowser"); | ||
242 | cfg.setGroup("Font"); | ||
243 | cfg.writeEntry("Family",family); | ||
244 | cfg.writeEntry("Style",style); | ||
245 | cfg.writeEntry("Size",size); | ||
246 | cfg.writeEntry("CharSet",charSet); | ||
247 | |||
248 | if(style.find("Italic",0,TRUE) != -1) { | ||
249 | selectedFont = fdb.font(family,"Regular",i_size,charSet); | ||
250 | selectedFont.setItalic(TRUE); //ya right | ||
251 | cfg.writeEntry("Italic","TRUE"); | ||
252 | // qDebug("Style is "+styleListBox->currentText()); | ||
253 | } else | ||
254 | cfg.writeEntry("Italic","FALSE"); | ||
255 | |||
256 | MultiLineEdit1->setFont( selectedFont); | ||
257 | MultiLineEdit1->update(); | ||
258 | changedFonts=TRUE; | ||
259 | } | ||
260 | |||