author | llornkcor <llornkcor> | 2002-02-18 14:08:55 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-18 14:08:55 (UTC) |
commit | 9741205aa0b0892b870d2b7df7c5dd7e25b0bb18 (patch) (unidiff) | |
tree | 7f2f3d44ff3215984bd8b487b206d3d958a498da /core/apps/textedit/fontDialog.cpp | |
parent | 0640b30f13beb9d6480d8042ec5397a68e6247fc (diff) | |
download | opie-9741205aa0b0892b870d2b7df7c5dd7e25b0bb18.zip opie-9741205aa0b0892b870d2b7df7c5dd7e25b0bb18.tar.gz opie-9741205aa0b0892b870d2b7df7c5dd7e25b0bb18.tar.bz2 |
added fontDialog, fileBrowserDialog, and fileSave dialog, so we can edit anyfile, save anywhere,
using a user selected name.
Changed what is seen when it opens. It now opens with the texteditor opened to a new
file, instead of the file selector, unless one is specified from commandline, or setDocument message.
FileSelector is still available, but from a menu item.
Diffstat (limited to 'core/apps/textedit/fontDialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/apps/textedit/fontDialog.cpp | 236 |
1 files changed, 236 insertions, 0 deletions
diff --git a/core/apps/textedit/fontDialog.cpp b/core/apps/textedit/fontDialog.cpp new file mode 100644 index 0000000..e7bd924 --- a/dev/null +++ b/core/apps/textedit/fontDialog.cpp | |||
@@ -0,0 +1,236 @@ | |||
1 | /**************************************************************************** | ||
2 | ** Created: Sun Jan 27 11:03:24 2002 fileDialog.cpp | ||
3 | copyright 2002 by L.J. Potter ljp@llornkcor.com | ||
4 | |||
5 | ** This file may be distributed and/or modified under the terms of the | ||
6 | ** GNU General Public License version 2 as published by the Free Software | ||
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
8 | ** packaging of this file. | ||
9 | ** | ||
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
12 | ** | ||
13 | ****************************************************************************/ | ||
14 | #include "fontDialog.h" | ||
15 | |||
16 | #include <qpe/fontdatabase.h> | ||
17 | #include <qpe/config.h> | ||
18 | |||
19 | #include <qstringlist.h> | ||
20 | #include <qfontinfo.h> | ||
21 | #include <qvaluelist.h> | ||
22 | #include <qpe/qpeapplication.h> | ||
23 | |||
24 | #include <qgroupbox.h> | ||
25 | #include <qlabel.h> | ||
26 | #include <qlistbox.h> | ||
27 | #include <qmultilineedit.h> | ||
28 | #include <qpushbutton.h> | ||
29 | #include <qlayout.h> | ||
30 | #include <qvariant.h> | ||
31 | #include <qtooltip.h> | ||
32 | #include <qwhatsthis.h> | ||
33 | |||
34 | FontDialog::FontDialog( QWidget * parent, const char* name , bool modal, WFlags fl ) | ||
35 | :QDialog /*QWidget*/( parent, name , modal, fl ) | ||
36 | { | ||
37 | if ( !name ) | ||
38 | setName( "FontDialog" ); | ||
39 | setCaption( tr( "Font Dialog" ) ); | ||
40 | FontTextLabel4 = new QLabel( this, "TextLabel4" ); | ||
41 | FontTextLabel4->setGeometry( QRect( 145, 100, 30, 19 /*192, 0, 43, 19*/ ) ); | ||
42 | FontTextLabel4->setText( tr( "Size" ) ); | ||
43 | |||
44 | FamilyGroup = new QGroupBox( this, "FamilyGroup" ); | ||
45 | FamilyGroup->setGeometry( QRect( 5, 5, 115, 135 /*0, 6, 185, 131 */) ); | ||
46 | FamilyGroup->setTitle( tr( "Font" ) ); | ||
47 | |||
48 | familyListBox = new QListBox( FamilyGroup, "familyListBox" ); | ||
49 | familyListBox->setGeometry( QRect( 5, 20, 100, 105 /* 6, 18, 170, 105 */) ); | ||
50 | |||
51 | GroupBox2 = new QGroupBox( this, "GroupBox2" ); | ||
52 | GroupBox2->setGeometry( QRect( 120, 5, 100, 90/* 0, 138, 170, 90*/ ) ); | ||
53 | GroupBox2->setTitle( tr( "Font Style" ) ); | ||
54 | |||
55 | styleListBox = new QListBox( GroupBox2, "styleListBox" ); | ||
56 | styleListBox->setGeometry( QRect( 5, 20, 90, 60 /*10, 20, 150, 61*/ ) ); | ||
57 | |||
58 | sizeListBox = new QListBox( this, "sizeListBox" ); | ||
59 | sizeListBox->setGeometry( QRect( 180, 100, 40, 60 /* 192, 24, 40, 108 */) ); | ||
60 | |||
61 | MultiLineEdit1 = new QMultiLineEdit( this, "MultiLineEdit1" ); | ||
62 | MultiLineEdit1->setGeometry( QRect( 5, 165, 215, 45 /* 6, 234, 222, 55*/ ) ); | ||
63 | MultiLineEdit1->setText( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" ) ); | ||
64 | MultiLineEdit1->setWordWrap(QMultiLineEdit::WidgetWidth); | ||
65 | |||
66 | connect( familyListBox,SIGNAL( highlighted( const QString &)),SLOT( familyListBoxSlot(const QString &) )); | ||
67 | connect( styleListBox,SIGNAL( highlighted( const QString &)),SLOT( styleListBoxSlot(const QString &) )); | ||
68 | connect( sizeListBox,SIGNAL( highlighted( const QString &)),SLOT( sizeListBoxSlot(const QString &) )); | ||
69 | |||
70 | populateLists(); | ||
71 | // MultiLineEdit1 | ||
72 | // connect(); | ||
73 | |||
74 | } | ||
75 | |||
76 | FontDialog::~FontDialog() | ||
77 | { | ||
78 | } | ||
79 | |||
80 | void FontDialog::familyListBoxSlot(const QString & text) | ||
81 | { | ||
82 | int styleInt=styleListBox->currentItem(); | ||
83 | int sizeInt=sizeListBox->currentItem(); | ||
84 | |||
85 | styleListBox->clear(); | ||
86 | sizeListBox->clear(); | ||
87 | family= text; | ||
88 | // qDebug(family); | ||
89 | QStringList styles = fdb.styles( family ); // string list of styles of our current font family | ||
90 | styleListBox->insertStringList( styles); | ||
91 | QString dstyle;// = "\t" + style + " ("; | ||
92 | QValueList<int> smoothies = fdb.smoothSizes( family, styleListBox->text(0) ); | ||
93 | for ( QValueList<int>::Iterator points = smoothies.begin(); points != smoothies.end(); ++points ) { | ||
94 | dstyle = QString::number( *points ); | ||
95 | sizeListBox ->insertItem( dstyle.left( dstyle.length() - 1 )); | ||
96 | } | ||
97 | if(styleInt == -1 || styleInt > styleListBox->count() ) | ||
98 | styleListBox->setCurrentItem(0); | ||
99 | else | ||
100 | styleListBox->setCurrentItem(styleInt); | ||
101 | |||
102 | if(sizeInt == -1 || sizeInt > sizeListBox->count()) | ||
103 | sizeListBox->setCurrentItem(0); | ||
104 | else | ||
105 | sizeListBox->setCurrentItem(sizeInt); | ||
106 | |||
107 | changeText(); | ||
108 | } | ||
109 | |||
110 | void FontDialog::styleListBoxSlot(const QString &text) | ||
111 | { | ||
112 | changeText(); | ||
113 | } | ||
114 | |||
115 | void FontDialog::sizeListBoxSlot(const QString & text) | ||
116 | { | ||
117 | changeText(); | ||
118 | } | ||
119 | |||
120 | void FontDialog::populateLists() | ||
121 | { | ||
122 | // QFont defaultFont=MultiLineEdit1->font(); | ||
123 | // QFont defaultFont=Lview->font(); | ||
124 | // QFontInfo fontInfo(defaultFont); | ||
125 | Config config("TextEdit"); | ||
126 | config.setGroup("Font"); | ||
127 | QString familyStr = config.readEntry("Family", "fixed"); | ||
128 | QString styleStr = config.readEntry("Style", "Regular"); | ||
129 | QString sizeStr = config.readEntry("Size", "10"); | ||
130 | QString charSetStr = config.readEntry("CharSet", "iso10646-1" ); | ||
131 | bool ok; | ||
132 | int i_size=sizeStr.toInt(&ok,10); | ||
133 | selectedFont = fdb.font(familyStr,styleStr,i_size,charSetStr); | ||
134 | // defaultFont.setItalic(TRUE); | ||
135 | families = fdb.families(); | ||
136 | for ( QStringList::Iterator f = families.begin(); f != families.end();++f ) { | ||
137 | QString family = *f; | ||
138 | // if(family == defaultFont.family()) | ||
139 | // qDebug(family); | ||
140 | familyListBox->insertItem( family); | ||
141 | |||
142 | if( familyListBox->text(0) == family) { | ||
143 | QStringList styles = fdb.styles( family ); // string list of styles of our current font family | ||
144 | styleListBox->insertStringList( styles); | ||
145 | for ( QStringList::Iterator s = styles.begin(); s != styles.end();++s ) { // for each font style | ||
146 | style = *s; | ||
147 | QString dstyle;// = "\t" + style + " ("; | ||
148 | if(styleListBox->text(0) == style) { | ||
149 | QValueList<int> smoothies = fdb.smoothSizes( family, style ); | ||
150 | for ( QValueList<int>::Iterator points = smoothies.begin(); points != smoothies.end(); ++points ) { | ||
151 | dstyle = QString::number( *points ) + " "; | ||
152 | |||
153 | sizeListBox ->insertItem( dstyle.left( dstyle.length() - 1 )); | ||
154 | } | ||
155 | dstyle = dstyle.left( dstyle.length() - 1 ) + ")"; | ||
156 | } | ||
157 | } // styles | ||
158 | } | ||
159 | } | ||
160 | for(int i=0;i < familyListBox->count();i++) { | ||
161 | if( familyListBox->text(i) == familyStr) | ||
162 | familyListBox->setSelected( i, TRUE); | ||
163 | } | ||
164 | |||
165 | for(int i=0;i < styleListBox->count();i++) { | ||
166 | if( styleListBox->text(i) == styleStr) | ||
167 | styleListBox->setSelected( i, TRUE); | ||
168 | } | ||
169 | |||
170 | for(int i=0;i < sizeListBox->count();i++) { | ||
171 | if( sizeListBox->text(i) == sizeStr) | ||
172 | sizeListBox->setSelected( i, TRUE); | ||
173 | } | ||
174 | changeText(); | ||
175 | } | ||
176 | |||
177 | void FontDialog::clearListBoxes() { | ||
178 | familyListBox->clear(); | ||
179 | sizeListBox->clear(); | ||
180 | styleListBox->clear(); | ||
181 | } | ||
182 | |||
183 | void FontDialog::changeText() | ||
184 | { | ||
185 | if( familyListBox->currentItem() == -1) | ||
186 | family= familyListBox->text(0); | ||
187 | else { | ||
188 | family = familyListBox->currentText(); | ||
189 | } | ||
190 | // qDebug("Font family is "+family); | ||
191 | if( styleListBox->currentItem() == -1) | ||
192 | style=styleListBox->text(0); | ||
193 | else { | ||
194 | style = styleListBox->currentText(); | ||
195 | } | ||
196 | // qDebug("font style is "+style); | ||
197 | if( sizeListBox->currentItem() == -1 ) | ||
198 | size= sizeListBox->text(0); | ||
199 | else { | ||
200 | size = sizeListBox->currentText(); | ||
201 | } | ||
202 | |||
203 | // qDebug("Font size is "+size); | ||
204 | bool ok; | ||
205 | int i_size= size.toInt(&ok,10); | ||
206 | QStringList charSetList= fdb.charSets(family); | ||
207 | // QStringList styles = fdb.styles( family ); // string list of styles of our current font family | ||
208 | QString charSet; | ||
209 | for ( QStringList::Iterator s = charSetList.begin(); s != charSetList.end();++s ) { // for each font style | ||
210 | charSet = *s; | ||
211 | // qDebug(charSet); | ||
212 | } | ||
213 | selectedFont = fdb.font(family,style,i_size,charSet); | ||
214 | QFontInfo fontInfo( selectedFont); | ||
215 | // if(fontInfo.italic() ) qDebug("italic"); | ||
216 | selectedFont.setWeight(fontInfo.weight() ); | ||
217 | // qDebug("Style are "+style+" %d ",fontInfo.weight()); | ||
218 | Config cfg("TextEdit"); | ||
219 | cfg.setGroup("Font"); | ||
220 | cfg.writeEntry("Family",family); | ||
221 | cfg.writeEntry("Style",style); | ||
222 | cfg.writeEntry("Size",size); | ||
223 | cfg.writeEntry("CharSet",charSet); | ||
224 | |||
225 | if(style.find("Italic",0,TRUE) != -1) { | ||
226 | selectedFont = fdb.font(family,"Regular",i_size,charSet); | ||
227 | selectedFont.setItalic(TRUE); //ya right | ||
228 | cfg.writeEntry("Italic","TRUE"); | ||
229 | // qDebug("Style is "+styleListBox->currentText()); | ||
230 | } else | ||
231 | cfg.writeEntry("Italic","FALSE"); | ||
232 | changedFonts=TRUE; | ||
233 | MultiLineEdit1->setFont( selectedFont); | ||
234 | MultiLineEdit1->update(); | ||
235 | } | ||
236 | |||