summaryrefslogtreecommitdiff
path: root/libopie2
authorzecke <zecke>2004-09-18 13:13:37 (UTC)
committer zecke <zecke>2004-09-18 13:13:37 (UTC)
commit721dbd6d4cfc2bfdede82a937b921e6f454da7d1 (patch) (unidiff)
tree1ea55ee2a6a938f77c5e1ae93716f5be8836862e /libopie2
parente657f4e105ba8b0a0be174add45d008ebb140455 (diff)
downloadopie-721dbd6d4cfc2bfdede82a937b921e6f454da7d1.zip
opie-721dbd6d4cfc2bfdede82a937b921e6f454da7d1.tar.gz
opie-721dbd6d4cfc2bfdede82a937b921e6f454da7d1.tar.bz2
Hint the NameSpace of OFileDialog and OFontSelector
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.cpp5
-rw-r--r--libopie2/opieui/ofontselector.cpp3
2 files changed, 7 insertions, 1 deletions
diff --git a/libopie2/opieui/fileselector/ofiledialog.cpp b/libopie2/opieui/fileselector/ofiledialog.cpp
index ebce0ef..4c6b800 100644
--- a/libopie2/opieui/fileselector/ofiledialog.cpp
+++ b/libopie2/opieui/fileselector/ofiledialog.cpp
@@ -1,255 +1,258 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) Holger Freyther <zecke@handhelds.org> 3             .=l. Copyright (C) Holger Freyther <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29 29
30/* OPIE */ 30/* OPIE */
31#include <opie2/ofiledialog.h> 31#include <opie2/ofiledialog.h>
32#include <qpe/applnk.h> 32#include <qpe/applnk.h>
33#include <qpe/config.h> 33#include <qpe/config.h>
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35 35
36/* QT */ 36/* QT */
37#include <qfileinfo.h> 37#include <qfileinfo.h>
38#include <qstring.h> 38#include <qstring.h>
39#include <qapplication.h> 39#include <qapplication.h>
40#include <qlayout.h> 40#include <qlayout.h>
41 41
42
43/* TRANSLATOR Opie::Ui::OFileDialog */
44
42using namespace Opie::Ui; 45using namespace Opie::Ui;
43 46
44namespace 47namespace
45{ 48{
46/* 49/*
47 * helper functions to load the start dir 50 * helper functions to load the start dir
48 * and to save it 51 * and to save it
49 * helper to extract the dir out of a file name 52 * helper to extract the dir out of a file name
50 */ 53 */
51/** 54/**
52 * This method will use Config( argv[0] ); 55 * This method will use Config( argv[0] );
53 * @param key The group key used 56 * @param key The group key used
54 */ 57 */
55QString lastUsedDir( const QString& key ) 58QString lastUsedDir( const QString& key )
56{ 59{
57 if ( qApp->argc() < 1 ) 60 if ( qApp->argc() < 1 )
58 return QString::null; 61 return QString::null;
59 62
60 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname 63 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname
61 cfg.setGroup( key ); 64 cfg.setGroup( key );
62 return cfg.readEntry("LastDir", QPEApplication::documentDir() ); 65 return cfg.readEntry("LastDir", QPEApplication::documentDir() );
63} 66}
64 67
65void saveLastDir( const QString& key, const QString& file ) 68void saveLastDir( const QString& key, const QString& file )
66{ 69{
67 if ( qApp->argc() < 1 ) 70 if ( qApp->argc() < 1 )
68 return; 71 return;
69 72
70 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); 73 Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
71 cfg.setGroup( key ); 74 cfg.setGroup( key );
72 QFileInfo inf( file ); 75 QFileInfo inf( file );
73 if ( inf.isFile() ) 76 if ( inf.isFile() )
74 cfg.writeEntry("LastDir", inf.dirPath( true ) ); 77 cfg.writeEntry("LastDir", inf.dirPath( true ) );
75 else 78 else
76 cfg.writeEntry("LastDir", file ); 79 cfg.writeEntry("LastDir", file );
77} 80}
78}; 81};
79 82
80/** 83/**
81 * This constructs a modal dialog 84 * This constructs a modal dialog
82 * 85 *
83 * @param caption The caption of the dialog 86 * @param caption The caption of the dialog
84 * @param wid The parent widget 87 * @param wid The parent widget
85 * @param mode The mode of the OFileSelector @see OFileSelector 88 * @param mode The mode of the OFileSelector @see OFileSelector
86 * @param selector The selector of the OFileSelector 89 * @param selector The selector of the OFileSelector
87 * @param dirName the dir or resource to start from 90 * @param dirName the dir or resource to start from
88 * @param fileName a proposed or existing filename 91 * @param fileName a proposed or existing filename
89 * @param mimetypes The mimeTypes 92 * @param mimetypes The mimeTypes
90 */ 93 */
91OFileDialog::OFileDialog(const QString &caption, 94OFileDialog::OFileDialog(const QString &caption,
92 QWidget *wid, int mode, int selector, 95 QWidget *wid, int mode, int selector,
93 const QString &dirName, 96 const QString &dirName,
94 const QString &fileName, 97 const QString &fileName,
95 const QMap<QString,QStringList>& mimetypes ) 98 const QMap<QString,QStringList>& mimetypes )
96 : QDialog( wid, "OFileDialog", true ) 99 : QDialog( wid, "OFileDialog", true )
97{ 100{
98 // QVBoxLayout *lay = new QVBoxLayout(this); 101 // QVBoxLayout *lay = new QVBoxLayout(this);
99 //showMaximized(); 102 //showMaximized();
100 QVBoxLayout *lay = new QVBoxLayout(this ); 103 QVBoxLayout *lay = new QVBoxLayout(this );
101 file = new OFileSelector(this , mode, selector, 104 file = new OFileSelector(this , mode, selector,
102 dirName, fileName, 105 dirName, fileName,
103 mimetypes ); 106 mimetypes );
104 lay->addWidget( file ); 107 lay->addWidget( file );
105 108
106 //lay->addWidget( file ); 109 //lay->addWidget( file );
107 //showFullScreen(); 110 //showFullScreen();
108 setCaption( caption.isEmpty() ? tr("FileDialog") : caption ); 111 setCaption( caption.isEmpty() ? tr("FileDialog") : caption );
109 connect(file, SIGNAL(fileSelected(const QString&) ), 112 connect(file, SIGNAL(fileSelected(const QString&) ),
110 this, SLOT(slotFileSelected(const QString&) ) ); 113 this, SLOT(slotFileSelected(const QString&) ) );
111 connect(file, SIGNAL(ok() ), 114 connect(file, SIGNAL(ok() ),
112 this, SLOT(slotSelectorOk()) ) ; 115 this, SLOT(slotSelectorOk()) ) ;
113 116
114 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) ); 117 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) );
115 118
116#if 0 119#if 0
117 connect(file, SIGNAL(dirSelected(const QString&) ), 120 connect(file, SIGNAL(dirSelected(const QString&) ),
118 this, SLOT(slotDirSelected(const QString&) ) ); 121 this, SLOT(slotDirSelected(const QString&) ) );
119#endif 122#endif
120} 123}
121/** 124/**
122 * @returns the mimetype of the selected 125 * @returns the mimetype of the selected
123 * currently it return QString::null 126 * currently it return QString::null
124 */ 127 */
125QString OFileDialog::mimetype()const 128QString OFileDialog::mimetype()const
126{ 129{
127 return QString::null; 130 return QString::null;
128} 131}
129 132
130/** 133/**
131 * @return the fileName 134 * @return the fileName
132 */ 135 */
133QString OFileDialog::fileName()const 136QString OFileDialog::fileName()const
134{ 137{
135 return file->selectedName(); 138 return file->selectedName();
136} 139}
137 140
138/** 141/**
139 * return a DocLnk to the current file 142 * return a DocLnk to the current file
140 */ 143 */
141DocLnk OFileDialog::selectedDocument()const 144DocLnk OFileDialog::selectedDocument()const
142{ 145{
143 return file->selectedDocument(); 146 return file->selectedDocument();
144} 147}
145 148
146/** 149/**
147 * This opens up a filedialog in Open mode 150 * This opens up a filedialog in Open mode
148 * 151 *
149 * @param selector the Selector Mode 152 * @param selector the Selector Mode
150 * @param startDir Where to start from 153 * @param startDir Where to start from
151 * @param file A proposed filename 154 * @param file A proposed filename
152 * @param mimes A list of MimeTypes 155 * @param mimes A list of MimeTypes
153 * @param wid the parent 156 * @param wid the parent
154 * @param caption of the dialog if QString::null tr("Open") will be used 157 * @param caption of the dialog if QString::null tr("Open") will be used
155 * @return the fileName or QString::null 158 * @return the fileName or QString::null
156 */ 159 */
157QString OFileDialog::getOpenFileName(int selector, 160QString OFileDialog::getOpenFileName(int selector,
158 const QString &_startDir, 161 const QString &_startDir,
159 const QString &file, 162 const QString &file,
160 const MimeTypes &mimes, 163 const MimeTypes &mimes,
161 QWidget *wid, 164 QWidget *wid,
162 const QString &caption ) 165 const QString &caption )
163{ 166{
164 QString ret; 167 QString ret;
165 QString startDir = _startDir; 168 QString startDir = _startDir;
166 if (startDir.isEmpty() ) 169 if (startDir.isEmpty() )
167 startDir = lastUsedDir( "FileDialog-OPEN" ); 170 startDir = lastUsedDir( "FileDialog-OPEN" );
168 171
169 172
170 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, 173 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
171 wid, OFileSelector::Open, selector, startDir, file, mimes); 174 wid, OFileSelector::Open, selector, startDir, file, mimes);
172 dlg.showMaximized(); 175 dlg.showMaximized();
173 if( dlg.exec() ) 176 if( dlg.exec() )
174 { 177 {
175 ret = dlg.fileName(); 178 ret = dlg.fileName();
176 saveLastDir( "FileDialog-OPEN", ret ); 179 saveLastDir( "FileDialog-OPEN", ret );
177 } 180 }
178 181
179 return ret; 182 return ret;
180} 183}
181 184
182/** 185/**
183 * This opens up a file dialog in save mode 186 * This opens up a file dialog in save mode
184 * @see getOpenFileName 187 * @see getOpenFileName
185 */ 188 */
186QString OFileDialog::getSaveFileName(int selector, 189QString OFileDialog::getSaveFileName(int selector,
187 const QString &_startDir, 190 const QString &_startDir,
188 const QString &file, 191 const QString &file,
189 const MimeTypes &mimes, 192 const MimeTypes &mimes,
190 QWidget *wid, 193 QWidget *wid,
191 const QString &caption ) 194 const QString &caption )
192{ 195{
193 QString ret; 196 QString ret;
194 QString startDir = _startDir; 197 QString startDir = _startDir;
195 if (startDir.isEmpty() ) 198 if (startDir.isEmpty() )
196 startDir = lastUsedDir( "FileDialog-SAVE" ); 199 startDir = lastUsedDir( "FileDialog-SAVE" );
197 200
198 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, 201 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
199 wid, OFileSelector::Save, selector, startDir, file, mimes); 202 wid, OFileSelector::Save, selector, startDir, file, mimes);
200 dlg.showMaximized(); 203 dlg.showMaximized();
201 if( dlg.exec() ) 204 if( dlg.exec() )
202 { 205 {
203 ret = dlg.fileName(); 206 ret = dlg.fileName();
204 saveLastDir( "FileDialog-SAVE", ret ); 207 saveLastDir( "FileDialog-SAVE", ret );
205 } 208 }
206 209
207 return ret; 210 return ret;
208} 211}
209 212
210/** 213/**
211 * This opens up a filedialog in select directory mode 214 * This opens up a filedialog in select directory mode
212 * 215 *
213 * @param selector the Selector Mode 216 * @param selector the Selector Mode
214 * @param startDir Where to start from 217 * @param startDir Where to start from
215 * @param wid the parent 218 * @param wid the parent
216 * @param caption of the dialog if QString::null tr("Open") will be used 219 * @param caption of the dialog if QString::null tr("Open") will be used
217 * @return the directoryName or QString::null 220 * @return the directoryName or QString::null
218 */ 221 */
219QString OFileDialog::getDirectory(int selector, 222QString OFileDialog::getDirectory(int selector,
220 const QString &_startDir, 223 const QString &_startDir,
221 QWidget *wid, 224 QWidget *wid,
222 const QString &caption ) 225 const QString &caption )
223{ 226{
224 QString ret; 227 QString ret;
225 QString startDir = _startDir; 228 QString startDir = _startDir;
226 if ( startDir.isEmpty() ) 229 if ( startDir.isEmpty() )
227 startDir = lastUsedDir( "FileDialog-SELECTDIR" ); 230 startDir = lastUsedDir( "FileDialog-SELECTDIR" );
228 231
229 OFileDialog dlg( caption.isEmpty() ? tr( "Select Directory" ) : caption, 232 OFileDialog dlg( caption.isEmpty() ? tr( "Select Directory" ) : caption,
230 wid, OFileSelector::DirectorySelector, selector, startDir ); 233 wid, OFileSelector::DirectorySelector, selector, startDir );
231 dlg.showMaximized(); 234 dlg.showMaximized();
232 if ( dlg.exec() ) 235 if ( dlg.exec() )
233 { 236 {
234 ret = dlg.fileName(); 237 ret = dlg.fileName();
235 saveLastDir( "FileDialog-SELECTDIR", ret ); 238 saveLastDir( "FileDialog-SELECTDIR", ret );
236 } 239 }
237 return ret; 240 return ret;
238} 241}
239 242
240void OFileDialog::slotFileSelected(const QString & ) 243void OFileDialog::slotFileSelected(const QString & )
241{ 244{
242 accept(); 245 accept();
243} 246}
244 247
245void OFileDialog::slotSelectorOk( ) 248void OFileDialog::slotSelectorOk( )
246{ 249{
247 accept(); 250 accept();
248} 251}
249 252
250void OFileDialog::slotDirSelected(const QString &dir ) 253void OFileDialog::slotDirSelected(const QString &dir )
251{ 254{
252 setCaption( dir ); 255 setCaption( dir );
253 // if mode 256 // if mode
254 //accept(); 257 //accept();
255} 258}
diff --git a/libopie2/opieui/ofontselector.cpp b/libopie2/opieui/ofontselector.cpp
index 4870cd9..6c24f14 100644
--- a/libopie2/opieui/ofontselector.cpp
+++ b/libopie2/opieui/ofontselector.cpp
@@ -1,430 +1,433 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Robert Griebl <sandman@handhelds.org> 3 Copyright (C) Robert Griebl <sandman@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30/* OPIE */ 30/* OPIE */
31#include <opie2/ofontselector.h> 31#include <opie2/ofontselector.h>
32#include <qpe/fontdatabase.h> 32#include <qpe/fontdatabase.h>
33 33
34/* QT */ 34/* QT */
35#include <qlayout.h> 35#include <qlayout.h>
36#include <qlistbox.h> 36#include <qlistbox.h>
37#include <qcombobox.h> 37#include <qcombobox.h>
38#include <qlabel.h> 38#include <qlabel.h>
39#include <qmultilineedit.h> 39#include <qmultilineedit.h>
40 40
41 41
42/* TRANSLATOR Opie::Ui::OFontSelector */
43
44
42namespace Opie { 45namespace Opie {
43namespace Ui { 46namespace Ui {
44namespace Internal { 47namespace Internal {
45 48
46class OFontSelectorPrivate 49class OFontSelectorPrivate
47{ 50{
48public: 51public:
49 QListBox * m_font_family_list; 52 QListBox * m_font_family_list;
50 QComboBox * m_font_style_list; 53 QComboBox * m_font_style_list;
51 QComboBox * m_font_size_list; 54 QComboBox * m_font_size_list;
52 QMultiLineEdit *m_preview; 55 QMultiLineEdit *m_preview;
53 56
54 bool m_pointbug : 1; 57 bool m_pointbug : 1;
55 58
56 FontDatabase m_fdb; 59 FontDatabase m_fdb;
57}; 60};
58 61
59class FontListItem : public QListBoxText 62class FontListItem : public QListBoxText
60{ 63{
61public: 64public:
62 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText() 65 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText()
63 { 66 {
64 m_name = t; 67 m_name = t;
65 m_styles = styles; 68 m_styles = styles;
66 m_sizes = sizes; 69 m_sizes = sizes;
67 70
68 QString str = t; 71 QString str = t;
69 str [0] = str [0]. upper(); 72 str [0] = str [0]. upper();
70 setText ( str ); 73 setText ( str );
71 } 74 }
72 75
73 QString family() const 76 QString family() const
74 { 77 {
75 return m_name; 78 return m_name;
76 } 79 }
77 80
78 const QStringList &styles() const 81 const QStringList &styles() const
79 { 82 {
80 return m_styles; 83 return m_styles;
81 } 84 }
82 85
83 const QValueList<int> &sizes() const 86 const QValueList<int> &sizes() const
84 { 87 {
85 return m_sizes; 88 return m_sizes;
86 } 89 }
87 90
88private: 91private:
89 QStringList m_styles; 92 QStringList m_styles;
90 QValueList<int> m_sizes; 93 QValueList<int> m_sizes;
91 QString m_name; 94 QString m_name;
92}; 95};
93} 96}
94} 97}
95} 98}
96 99
97 100
98using namespace Opie::Ui; 101using namespace Opie::Ui;
99using namespace Opie::Ui::Internal; 102using namespace Opie::Ui::Internal;
100 103
101static int findItemCB( QComboBox *box, const QString &str ) 104static int findItemCB( QComboBox *box, const QString &str )
102{ 105{
103 for ( int i = 0; i < box->count(); i++ ) 106 for ( int i = 0; i < box->count(); i++ )
104 { 107 {
105 if ( box->text ( i ) == str ) 108 if ( box->text ( i ) == str )
106 return i; 109 return i;
107 } 110 }
108 return -1; 111 return -1;
109} 112}
110 113
111/* static same as anon. namespace */ 114/* static same as anon. namespace */
112static int qt_version() 115static int qt_version()
113{ 116{
114 const char *qver = qVersion(); 117 const char *qver = qVersion();
115 118
116 return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' ); 119 return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' );
117} 120}
118 121
119/** 122/**
120 * Constructs the Selector object 123 * Constructs the Selector object
121 * @param withpreview If a font preview should be given 124 * @param withpreview If a font preview should be given
122 * @param parent The parent of the Font Selector 125 * @param parent The parent of the Font Selector
123 * @param name The name of the object 126 * @param name The name of the object
124 * @param fl WidgetFlags 127 * @param fl WidgetFlags
125 */ 128 */
126OFontSelector::OFontSelector( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) 129OFontSelector::OFontSelector( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl )
127{ 130{
128 d = new OFontSelectorPrivate(); 131 d = new OFontSelectorPrivate();
129 132
130 QGridLayout *gridLayout = new QGridLayout( this, 0, 0, 4, 4 ); 133 QGridLayout *gridLayout = new QGridLayout( this, 0, 0, 4, 4 );
131 gridLayout->setRowStretch( 4, 10 ); 134 gridLayout->setRowStretch( 4, 10 );
132 135
133 d->m_font_family_list = new QListBox( this, "FontListBox" ); 136 d->m_font_family_list = new QListBox( this, "FontListBox" );
134 gridLayout->addMultiCellWidget( d->m_font_family_list, 0, 4, 0, 0 ); 137 gridLayout->addMultiCellWidget( d->m_font_family_list, 0, 4, 0, 0 );
135 connect( d->m_font_family_list, SIGNAL( highlighted(int) ), this, SLOT( fontFamilyClicked(int) ) ); 138 connect( d->m_font_family_list, SIGNAL( highlighted(int) ), this, SLOT( fontFamilyClicked(int) ) );
136 139
137 QLabel *label = new QLabel( tr( "Style" ), this ); 140 QLabel *label = new QLabel( tr( "Style" ), this );
138 gridLayout->addWidget( label, 0, 1 ); 141 gridLayout->addWidget( label, 0, 1 );
139 142
140 d->m_font_style_list = new QComboBox( this, "StyleListBox" ); 143 d->m_font_style_list = new QComboBox( this, "StyleListBox" );
141 connect( d->m_font_style_list, SIGNAL( activated(int) ), this, SLOT( fontStyleClicked(int) ) ); 144 connect( d->m_font_style_list, SIGNAL( activated(int) ), this, SLOT( fontStyleClicked(int) ) );
142 gridLayout->addWidget( d->m_font_style_list, 1, 1 ); 145 gridLayout->addWidget( d->m_font_style_list, 1, 1 );
143 146
144 label = new QLabel( tr( "Size" ), this ); 147 label = new QLabel( tr( "Size" ), this );
145 gridLayout->addWidget( label, 2, 1 ); 148 gridLayout->addWidget( label, 2, 1 );
146 149
147 d->m_font_size_list = new QComboBox( this, "SizeListBox" ); 150 d->m_font_size_list = new QComboBox( this, "SizeListBox" );
148 connect( d->m_font_size_list, SIGNAL( activated(int) ), 151 connect( d->m_font_size_list, SIGNAL( activated(int) ),
149 this, SLOT( fontSizeClicked(int) ) ); 152 this, SLOT( fontSizeClicked(int) ) );
150 gridLayout->addWidget( d->m_font_size_list, 3, 1 ); 153 gridLayout->addWidget( d->m_font_size_list, 3, 1 );
151 154
152 d->m_pointbug = ( qt_version() <= 233 ); 155 d->m_pointbug = ( qt_version() <= 233 );
153 156
154 if ( withpreview ) 157 if ( withpreview )
155 { 158 {
156 d->m_preview = new QMultiLineEdit ( this, "Preview" ); 159 d->m_preview = new QMultiLineEdit ( this, "Preview" );
157 d->m_preview->setAlignment ( AlignCenter ); 160 d->m_preview->setAlignment ( AlignCenter );
158 d->m_preview->setWordWrap ( QMultiLineEdit::WidgetWidth ); 161 d->m_preview->setWordWrap ( QMultiLineEdit::WidgetWidth );
159 d->m_preview->setMargin ( 3 ); 162 d->m_preview->setMargin ( 3 );
160 d->m_preview->setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); 163 d->m_preview->setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" ));
161 gridLayout->addRowSpacing ( 5, 4 ); 164 gridLayout->addRowSpacing ( 5, 4 );
162 gridLayout->addMultiCellWidget ( d->m_preview, 6, 6, 0, 1 ); 165 gridLayout->addMultiCellWidget ( d->m_preview, 6, 6, 0, 1 );
163 gridLayout->setRowStretch ( 6, 5 ); 166 gridLayout->setRowStretch ( 6, 5 );
164 } 167 }
165 else 168 else
166 d->m_preview = 0; 169 d->m_preview = 0;
167 170
168 loadFonts ( d->m_font_family_list ); 171 loadFonts ( d->m_font_family_list );
169} 172}
170 173
171OFontSelector::~OFontSelector() 174OFontSelector::~OFontSelector()
172{ 175{
173 delete d; 176 delete d;
174} 177}
175 178
176/** 179/**
177 * This methods tries to set the font 180 * This methods tries to set the font
178 * @param f The wishes font 181 * @param f The wishes font
179 * @return success or failure 182 * @return success or failure
180 */ 183 */
181bool OFontSelector::setSelectedFont ( const QFont &f ) 184bool OFontSelector::setSelectedFont ( const QFont &f )
182{ 185{
183 return setSelectedFont ( f. family(), d->m_fdb. styleString ( f ), f. pointSize(), QFont::encodingName ( f. charSet())); 186 return setSelectedFont ( f. family(), d->m_fdb. styleString ( f ), f. pointSize(), QFont::encodingName ( f. charSet()));
184} 187}
185 188
186 189
187/** 190/**
188 * This is an overloaded method @see setSelectedFont 191 * This is an overloaded method @see setSelectedFont
189 * @param familyStr The family of the font 192 * @param familyStr The family of the font
190 * @param styleStr The style of the font 193 * @param styleStr The style of the font
191 * @param sizeVal The size of font 194 * @param sizeVal The size of font
192 * @param charset The charset to be used. Will be deprecated by QT3 195 * @param charset The charset to be used. Will be deprecated by QT3
193 */ 196 */
194bool OFontSelector::setSelectedFont( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) 197bool OFontSelector::setSelectedFont( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset )
195{ 198{
196 Q_CONST_UNUSED( charset ) 199 Q_CONST_UNUSED( charset )
197 QString sizeStr = QString::number ( sizeVal ); 200 QString sizeStr = QString::number ( sizeVal );
198 201
199 QListBoxItem *family = d->m_font_family_list->findItem ( familyStr ); 202 QListBoxItem *family = d->m_font_family_list->findItem ( familyStr );
200 if ( !family ) 203 if ( !family )
201 family = d->m_font_family_list->findItem ( "Helvetica" ); 204 family = d->m_font_family_list->findItem ( "Helvetica" );
202 if ( !family ) 205 if ( !family )
203 family = d->m_font_family_list->firstItem(); 206 family = d->m_font_family_list->firstItem();
204 d->m_font_family_list->setCurrentItem ( family ); 207 d->m_font_family_list->setCurrentItem ( family );
205 fontFamilyClicked ( d->m_font_family_list->index ( family )); 208 fontFamilyClicked ( d->m_font_family_list->index ( family ));
206 209
207 int style = findItemCB ( d->m_font_style_list, styleStr ); 210 int style = findItemCB ( d->m_font_style_list, styleStr );
208 if ( style < 0 ) 211 if ( style < 0 )
209 style = findItemCB ( d->m_font_style_list, "Regular" ); 212 style = findItemCB ( d->m_font_style_list, "Regular" );
210 if ( style < 0 && d->m_font_style_list->count() > 0 ) 213 if ( style < 0 && d->m_font_style_list->count() > 0 )
211 style = 0; 214 style = 0;
212 d->m_font_style_list->setCurrentItem ( style ); 215 d->m_font_style_list->setCurrentItem ( style );
213 fontStyleClicked ( style ); 216 fontStyleClicked ( style );
214 217
215 int size = findItemCB ( d->m_font_size_list, sizeStr ); 218 int size = findItemCB ( d->m_font_size_list, sizeStr );
216 if ( size < 0 ) 219 if ( size < 0 )
217 size = findItemCB ( d->m_font_size_list, "10" ); 220 size = findItemCB ( d->m_font_size_list, "10" );
218 if ( size < 0 && d->m_font_size_list->count() > 0 ) 221 if ( size < 0 && d->m_font_size_list->count() > 0 )
219 size = 0; 222 size = 0;
220 d->m_font_size_list->setCurrentItem ( size ); 223 d->m_font_size_list->setCurrentItem ( size );
221 fontSizeClicked ( size ); 224 fontSizeClicked ( size );
222 225
223 return (( family ) && ( style >= 0 ) && ( size >= 0 )); 226 return (( family ) && ( style >= 0 ) && ( size >= 0 ));
224} 227}
225 228
226/** 229/**
227 * This method returns the name, style and size of the currently selected 230 * This method returns the name, style and size of the currently selected
228 * font or false if no font is selected 231 * font or false if no font is selected
229 * @param family The font family will be written there 232 * @param family The font family will be written there
230 * @param style The style will be written there 233 * @param style The style will be written there
231 * @param size The size will be written there 234 * @param size The size will be written there
232 * @return success or failure 235 * @return success or failure
233 */ 236 */
234bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) 237bool OFontSelector::selectedFont ( QString &family, QString &style, int &size )
235{ 238{
236 QString dummy; 239 QString dummy;
237 return selectedFont ( family, style, size, dummy ); 240 return selectedFont ( family, style, size, dummy );
238} 241}
239 242
240 243
241/** 244/**
242 * This method does return the font family or QString::null if there is 245 * This method does return the font family or QString::null if there is
243 * no font item selected 246 * no font item selected
244 * @return the font family 247 * @return the font family
245 */ 248 */
246QString OFontSelector::fontFamily() const 249QString OFontSelector::fontFamily() const
247{ 250{
248 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); 251 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
249 252
250 return fli ? fli->family() : QString::null; 253 return fli ? fli->family() : QString::null;
251} 254}
252 255
253/** 256/**
254 * This method will return the style of the font or QString::null 257 * This method will return the style of the font or QString::null
255 * @return the style of the font 258 * @return the style of the font
256 */ 259 */
257QString OFontSelector::fontStyle() const 260QString OFontSelector::fontStyle() const
258{ 261{
259 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); 262 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
260 int fst = d->m_font_style_list->currentItem(); 263 int fst = d->m_font_style_list->currentItem();
261 264
262 return ( fli && fst >= 0 ) ? fli->styles() [fst] : QString::null; 265 return ( fli && fst >= 0 ) ? fli->styles() [fst] : QString::null;
263} 266}
264 267
265/** 268/**
266 * This method will return the font size or 10 if no font size is available 269 * This method will return the font size or 10 if no font size is available
267 */ 270 */
268int OFontSelector::fontSize() const 271int OFontSelector::fontSize() const
269{ 272{
270 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); 273 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
271 int fsi = d->m_font_size_list->currentItem(); 274 int fsi = d->m_font_size_list->currentItem();
272 275
273 return ( fli && fsi >= 0 ) ? fli->sizes() [fsi] : 10; 276 return ( fli && fsi >= 0 ) ? fli->sizes() [fsi] : 10;
274} 277}
275 278
276/** 279/**
277 * returns the charset of the font or QString::null 280 * returns the charset of the font or QString::null
278 */ 281 */
279QString OFontSelector::fontCharSet() const 282QString OFontSelector::fontCharSet() const
280{ 283{
281 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); 284 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
282 285
283 return fli ? d->m_fdb. charSets ( fli->family()) [0] : QString::null; 286 return fli ? d->m_fdb. charSets ( fli->family()) [0] : QString::null;
284} 287}
285 288
286/** 289/**
287 * Overloaded member function see above 290 * Overloaded member function see above
288 * @see selectedFont 291 * @see selectedFont
289 */ 292 */
290bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) 293bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset )
291{ 294{
292 int ffa = d->m_font_family_list->currentItem(); 295 int ffa = d->m_font_family_list->currentItem();
293 int fst = d->m_font_style_list->currentItem(); 296 int fst = d->m_font_style_list->currentItem();
294 int fsi = d->m_font_size_list->currentItem(); 297 int fsi = d->m_font_size_list->currentItem();
295 298
296 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa ); 299 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa );
297 300
298 if ( fli ) 301 if ( fli )
299 { 302 {
300 family = fli->family(); 303 family = fli->family();
301 style = fst >= 0 ? fli->styles() [fst] : QString::null; 304 style = fst >= 0 ? fli->styles() [fst] : QString::null;
302 size = fsi >= 0 ? fli->sizes() [fsi] : 10; 305 size = fsi >= 0 ? fli->sizes() [fsi] : 10;
303 charset = d->m_fdb. charSets ( fli->family()) [0]; 306 charset = d->m_fdb. charSets ( fli->family()) [0];
304 307
305 return true; 308 return true;
306 } 309 }
307 else 310 else
308 return false; 311 return false;
309} 312}
310 313
311void OFontSelector::loadFonts ( QListBox *list ) 314void OFontSelector::loadFonts ( QListBox *list )
312{ 315{
313 QStringList f = d->m_fdb. families(); 316 QStringList f = d->m_fdb. families();
314 317
315 for ( QStringList::ConstIterator it = f. begin(); it != f. end(); ++it ) 318 for ( QStringList::ConstIterator it = f. begin(); it != f. end(); ++it )
316 { 319 {
317 QValueList <int> ps = d->m_fdb. pointSizes ( *it ); 320 QValueList <int> ps = d->m_fdb. pointSizes ( *it );
318 321
319 if ( d->m_pointbug ) 322 if ( d->m_pointbug )
320 { 323 {
321 for ( QValueList <int>::Iterator it = ps. begin(); it != ps. end(); it++ ) 324 for ( QValueList <int>::Iterator it = ps. begin(); it != ps. end(); it++ )
322 *it /= 10; 325 *it /= 10;
323 } 326 }
324 327
325 list->insertItem ( new FontListItem ( *it, d->m_fdb. styles ( *it ), ps )); 328 list->insertItem ( new FontListItem ( *it, d->m_fdb. styles ( *it ), ps ));
326 } 329 }
327} 330}
328 331
329void OFontSelector::fontFamilyClicked ( int index ) 332void OFontSelector::fontFamilyClicked ( int index )
330{ 333{
331 QString oldstyle = d->m_font_style_list->currentText(); 334 QString oldstyle = d->m_font_style_list->currentText();
332 QString oldsize = d->m_font_size_list->currentText(); 335 QString oldsize = d->m_font_size_list->currentText();
333 336
334 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( index ); 337 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( index );
335 338
336 d->m_font_style_list->clear(); 339 d->m_font_style_list->clear();
337 d->m_font_style_list->insertStringList ( fli->styles()); 340 d->m_font_style_list->insertStringList ( fli->styles());
338 d->m_font_style_list->setEnabled ( !fli->styles(). isEmpty()); 341 d->m_font_style_list->setEnabled ( !fli->styles(). isEmpty());
339 342
340 int i; 343 int i;
341 344
342 i = findItemCB ( d->m_font_style_list, oldstyle ); 345 i = findItemCB ( d->m_font_style_list, oldstyle );
343 if ( i < 0 ) 346 if ( i < 0 )
344 i = findItemCB ( d->m_font_style_list, "Regular" ); 347 i = findItemCB ( d->m_font_style_list, "Regular" );
345 if (( i < 0 ) && ( d->m_font_style_list->count() > 0 )) 348 if (( i < 0 ) && ( d->m_font_style_list->count() > 0 ))
346 i = 0; 349 i = 0;
347 350
348 if ( i >= 0 ) 351 if ( i >= 0 )
349 { 352 {
350 d->m_font_style_list->setCurrentItem ( i ); 353 d->m_font_style_list->setCurrentItem ( i );
351 fontStyleClicked ( i ); 354 fontStyleClicked ( i );
352 } 355 }
353 356
354 d->m_font_size_list->clear(); 357 d->m_font_size_list->clear();
355 QValueList<int> sl = fli->sizes(); 358 QValueList<int> sl = fli->sizes();
356 359
357 for ( QValueList<int>::Iterator it = sl. begin(); it != sl. end(); ++it ) 360 for ( QValueList<int>::Iterator it = sl. begin(); it != sl. end(); ++it )
358 d->m_font_size_list->insertItem ( QString::number ( *it )); 361 d->m_font_size_list->insertItem ( QString::number ( *it ));
359 362
360 i = findItemCB ( d->m_font_size_list, oldsize ); 363 i = findItemCB ( d->m_font_size_list, oldsize );
361 if ( i < 0 ) 364 if ( i < 0 )
362 i = findItemCB ( d->m_font_size_list, "10" ); 365 i = findItemCB ( d->m_font_size_list, "10" );
363 if (( i < 0 ) && ( d->m_font_size_list->count() > 0 )) 366 if (( i < 0 ) && ( d->m_font_size_list->count() > 0 ))
364 i = 0; 367 i = 0;
365 368
366 if ( i >= 0 ) 369 if ( i >= 0 )
367 { 370 {
368 d->m_font_size_list->setCurrentItem ( i ); 371 d->m_font_size_list->setCurrentItem ( i );
369 fontSizeClicked ( i ); 372 fontSizeClicked ( i );
370 } 373 }
371 changeFont(); 374 changeFont();
372} 375}
373 376
374void OFontSelector::fontStyleClicked ( int /*index*/ ) 377void OFontSelector::fontStyleClicked ( int /*index*/ )
375{ 378{
376 changeFont(); 379 changeFont();
377} 380}
378 381
379void OFontSelector::fontSizeClicked ( int /*index*/ ) 382void OFontSelector::fontSizeClicked ( int /*index*/ )
380{ 383{
381 changeFont(); 384 changeFont();
382} 385}
383 386
384void OFontSelector::changeFont() 387void OFontSelector::changeFont()
385{ 388{
386 QFont f = selectedFont(); 389 QFont f = selectedFont();
387 390
388 if ( d->m_preview ) 391 if ( d->m_preview )
389 d->m_preview->setFont ( f ); 392 d->m_preview->setFont ( f );
390 393
391 emit fontSelected ( f ); 394 emit fontSelected ( f );
392} 395}
393 396
394/** 397/**
395 * Return the selected font 398 * Return the selected font
396 */ 399 */
397QFont OFontSelector::selectedFont() 400QFont OFontSelector::selectedFont()
398{ 401{
399 int ffa = d->m_font_family_list->currentItem(); 402 int ffa = d->m_font_family_list->currentItem();
400 int fst = d->m_font_style_list->currentItem(); 403 int fst = d->m_font_style_list->currentItem();
401 int fsi = d->m_font_size_list->currentItem(); 404 int fsi = d->m_font_size_list->currentItem();
402 405
403 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa ); 406 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa );
404 407
405 if ( fli ) 408 if ( fli )
406 { 409 {
407 return d->m_fdb. font ( fli->family(), \ 410 return d->m_fdb. font ( fli->family(), \
408 fst >= 0 ? fli->styles() [fst] : QString::null, \ 411 fst >= 0 ? fli->styles() [fst] : QString::null, \
409 fsi >= 0 ? fli->sizes() [fsi] : 10, \ 412 fsi >= 0 ? fli->sizes() [fsi] : 10, \
410 d->m_fdb. charSets ( fli->family()) [0] ); 413 d->m_fdb. charSets ( fli->family()) [0] );
411 } 414 }
412 else 415 else
413 return QFont(); 416 return QFont();
414} 417}
415 418
416void OFontSelector::resizeEvent ( QResizeEvent *re ) 419void OFontSelector::resizeEvent ( QResizeEvent *re )
417{ 420{
418 if ( d->m_preview ) 421 if ( d->m_preview )
419 { 422 {
420 d->m_preview->setMinimumHeight ( 1 ); 423 d->m_preview->setMinimumHeight ( 1 );
421 d->m_preview->setMaximumHeight ( 32767 ); 424 d->m_preview->setMaximumHeight ( 32767 );
422 } 425 }
423 426
424 QWidget::resizeEvent ( re ); 427 QWidget::resizeEvent ( re );
425 428
426 if ( d->m_preview ) 429 if ( d->m_preview )
427 d->m_preview->setFixedHeight ( d->m_preview->height()); 430 d->m_preview->setFixedHeight ( d->m_preview->height());
428 431
429} 432}
430 433