00001
00002
00003
00004
00005
00006
00007 #include "fontDialog.h"
00008 #include "optionsDialog.h"
00009
00010 #include <qpe/fontdatabase.h>
00011 #include <qpe/config.h>
00012
00013 #include <qstringlist.h>
00014 #include <qfontinfo.h>
00015 #include <qvaluelist.h>
00016 #include <qpe/qpeapplication.h>
00017
00018 #include <qgroupbox.h>
00019 #include <qlabel.h>
00020 #include <qlistbox.h>
00021 #include <qmultilineedit.h>
00022 #include <qpushbutton.h>
00023 #include <qlayout.h>
00024 #include <qvariant.h>
00025 #include <qtooltip.h>
00026 #include <qwhatsthis.h>
00027 #include <qcombobox.h>
00028
00029
00030
00031 static const int nfontsizes = 9;
00032 static const int fontsize[nfontsizes] = {8,9,10,11,12,13,14,18,24};
00033
00034
00035 FontDialog::FontDialog( QWidget * parent, const char* name )
00036 : QWidget( parent, name )
00037 {
00038 if ( !name )
00039 setName( "FontDialog" );
00040 setCaption( tr( "Font Dialog" ) );
00041
00042 QGridLayout *layout = new QGridLayout( this );
00043 layout->setSpacing(2);
00044 layout->setMargin(2);
00045
00046 familyListBox = new QListBox( this, "familyListBox" );
00047 layout->addMultiCellWidget( familyListBox, 0, 2, 0, 0);
00048
00049 QBoxLayout * hbox = new QHBoxLayout(this);
00050 QBoxLayout * vbox = new QVBoxLayout(this);
00051
00052 styleListBox = new QListBox( this, "styleListBox" );
00053 vbox->addWidget( styleListBox, 0);
00054
00055 FontTextLabel4 = new QLabel( this, "TextLabel4" );
00056 FontTextLabel4->setText( tr( "Size" ) );
00057 hbox->addWidget( FontTextLabel4,0);
00058
00059 sizeComboBox = new QComboBox( FALSE, this, "SizeCombo");
00060
00061 hbox->addWidget( sizeComboBox, 0);
00062
00063 vbox->addLayout(hbox,0);
00064 layout->addLayout( vbox,0,3);
00065
00066 MultiLineEdit1 = new QMultiLineEdit( this, "MultiLineEdit1" );
00067 MultiLineEdit1->setText( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" ) );
00068 MultiLineEdit1->setWordWrap( QMultiLineEdit::WidgetWidth);
00069
00070 layout->addMultiCellWidget( MultiLineEdit1, 4, 4, 0, 3);
00071
00072 connect(familyListBox,SIGNAL(highlighted(const QString &)),SLOT(familyListBoxSlot(const QString &)));
00073 connect(styleListBox,SIGNAL(highlighted(const QString &)),SLOT(styleListBoxSlot(const QString &)));
00074 connect(sizeComboBox,SIGNAL(activated(const QString &)),SLOT(sizeComboBoxSlot(const QString &)));
00075
00076 populateLists();
00077
00078 }
00079
00080 FontDialog::~FontDialog()
00081 {
00082 }
00083
00084 void FontDialog::familyListBoxSlot(const QString & text)
00085 {
00086 int styleInt = styleListBox->currentItem();
00087 int sizeInt = sizeComboBox->currentText().toInt();
00088
00089 sizeComboBox->clear();
00090 styleListBox->clear();
00091
00092 family = text;
00093
00094 QStringList styles = fdb.styles( family );
00095 styleListBox->insertStringList( styles);
00096 QString dstyle;
00097
00098 #ifdef BUGGY_SHARP_ZAURUS
00099
00100 QValueList<int> smoothies = fdb.smoothSizes( family, styleListBox->text(0) );
00101 for ( QValueList<int>::Iterator points = smoothies.begin(); points != smoothies.end(); ++points ) {
00102 dstyle = QString::number( *points );
00103 odebug << dstyle << oendl;
00104 sizeComboBox->insertItem( dstyle.left( dstyle.length() - 1 ));
00105 }
00106 #else
00107
00108 for (int i=0; i<nfontsizes; i++) {
00109 sizeComboBox->insertItem( QString::number(fontsize[i]));
00110 if(fontsize[i] == sizeInt) {
00111 sizeComboBox->setCurrentItem(i);
00112 }
00113 }
00114 #endif
00115
00116 if(styleInt == -1 || styleInt > static_cast<int>(styleListBox->count()) )
00117 styleListBox->setCurrentItem(0);
00118 else
00119 styleListBox->setCurrentItem(styleInt);
00120
00121 changeText();
00122 }
00123
00124 void FontDialog::styleListBoxSlot(const QString &)
00125 {
00126 changeText();
00127 }
00128
00129 void FontDialog::sizeComboBoxSlot(const QString &)
00130 {
00131 changeText();
00132 }
00133
00134 void FontDialog::populateLists()
00135 {
00136
00137
00138
00139 Config config("Gutenbrowser");
00140 config.setGroup("Font");
00141 QString familyStr = config.readEntry("Family", "fixed");
00142 QString styleStr = config.readEntry("Style", "Regular");
00143 QString sizeStr = config.readEntry("Size", "10");
00144 QString charSetStr = config.readEntry("CharSet", "iso10646-1" );
00145 bool ok;
00146 int i_size = sizeStr.toInt(&ok,10);
00147 selectedFont = fdb.font(familyStr,styleStr,i_size,charSetStr);
00148
00149 families = fdb.families();
00150
00151 for ( QStringList::Iterator f = families.begin(); f != families.end();++f ) {
00152 QString family = *f;
00153
00154
00155 familyListBox->insertItem( family);
00156
00157 if( familyListBox->text(0) == family) {
00158 QStringList styles = fdb.styles( family );
00159
00160 styleListBox->insertStringList( styles);
00161
00162 for ( QStringList::Iterator s = styles.begin(); s != styles.end();++s ) {
00163 style = *s;
00164 QString dstyle;
00165 if(styleListBox->text(0) == style) {
00166
00167 QValueList<int> smoothies = fdb.smoothSizes( family, style );
00168 for ( QValueList<int>::Iterator points = smoothies.begin(); points != smoothies.end(); ++points ) {
00169 dstyle = QString::number( *points ) + " ";
00170 sizeComboBox ->insertItem( dstyle.left( dstyle.length() - 1 ));
00171 }
00172 dstyle = dstyle.left( dstyle.length() - 1 ) + ")";
00173 }
00174 }
00175 }
00176 }
00177 for(uint i=0;i < familyListBox->count();i++) {
00178 if( familyListBox->text(i) == familyStr)
00179 familyListBox->setSelected( i, TRUE);
00180 }
00181
00182 for(uint i=0;i < styleListBox->count();i++) {
00183 if( styleListBox->text(i) == styleStr)
00184 styleListBox->setSelected( i, TRUE);
00185 }
00186
00187 for (int i=0; i<sizeComboBox->count(); i++) {
00188
00189 #ifdef BUGGY_SHARP_ZAURUS
00190 if(sizeComboBox->text(i) == sizeStr)
00191 #else
00192 if(fontsize[i] == i_size)
00193 #endif
00194 sizeComboBox->setCurrentItem(i);
00195 }
00196 changeText();
00197 }
00198
00199 void FontDialog::clearListBoxes() {
00200 familyListBox->clear();
00201 sizeComboBox->clear();
00202 styleListBox->clear();
00203 }
00204
00205 void FontDialog::changeText()
00206 {
00207 if( familyListBox->currentItem() == -1)
00208 family= familyListBox->text(0);
00209 else {
00210 family = familyListBox->currentText();
00211 }
00212
00213 if( styleListBox->currentItem() == -1)
00214 style=styleListBox->text(0);
00215 else {
00216 style = styleListBox->currentText();
00217 }
00218
00219
00220 if( sizeComboBox->currentItem() == -1 )
00221 size = sizeComboBox->text(0);
00222 else {
00223 size = sizeComboBox->currentText();
00224 }
00225
00226
00227 bool ok;
00228 int i_size = size.toInt(&ok,10);
00229 QStringList charSetList = fdb.charSets(family);
00230
00231 QString charSet;
00232 for ( QStringList::Iterator s = charSetList.begin(); s != charSetList.end();++s ) {
00233 charSet = *s;
00234
00235 }
00236 selectedFont = fdb.font(family,style,i_size,charSet);
00237 QFontInfo fontInfo( selectedFont);
00238
00239 selectedFont.setWeight(fontInfo.weight() );
00240
00241 Config cfg("Gutenbrowser");
00242 cfg.setGroup("Font");
00243 cfg.writeEntry("Family",family);
00244 cfg.writeEntry("Style",style);
00245 cfg.writeEntry("Size",size);
00246 cfg.writeEntry("CharSet",charSet);
00247
00248 if(style.find("Italic",0,TRUE) != -1) {
00249 selectedFont = fdb.font(family,"Regular",i_size,charSet);
00250 selectedFont.setItalic(TRUE);
00251 cfg.writeEntry("Italic","TRUE");
00252
00253 } else
00254 cfg.writeEntry("Italic","FALSE");
00255
00256 MultiLineEdit1->setFont( selectedFont);
00257 MultiLineEdit1->update();
00258 changedFonts=TRUE;
00259 }
00260