summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofontselector.cpp51
-rw-r--r--libopie/ofontselector.h5
2 files changed, 47 insertions, 9 deletions
diff --git a/libopie/ofontselector.cpp b/libopie/ofontselector.cpp
index e1090b5..b905474 100644
--- a/libopie/ofontselector.cpp
+++ b/libopie/ofontselector.cpp
@@ -18,46 +18,48 @@
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#include <qlayout.h> 29#include <qlayout.h>
30#include <qlistbox.h> 30#include <qlistbox.h>
31#include <qcombobox.h> 31#include <qcombobox.h>
32#include <qlabel.h> 32#include <qlabel.h>
33#include <qfont.h> 33#include <qfont.h>
34#include <qmultilineedit.h>
34 35
35#include <qpe/fontdatabase.h> 36#include <qpe/fontdatabase.h>
36 37
37#include "ofontselector.h" 38#include "ofontselector.h"
38 39
39class OFontSelectorPrivate { 40class OFontSelectorPrivate {
40public: 41public:
41 QListBox * m_font_family_list; 42 QListBox * m_font_family_list;
42 QComboBox * m_font_style_list; 43 QComboBox * m_font_style_list;
43 QComboBox * m_font_size_list; 44 QComboBox * m_font_size_list;
45 QMultiLineEdit *m_preview;
44 46
45 bool m_pointbug; 47 bool m_pointbug;
46 48
47 FontDatabase m_fdb; 49 FontDatabase m_fdb;
48}; 50};
49 51
50 52
51class FontListItem : public QListBoxText { 53class FontListItem : public QListBoxText {
52public: 54public:
53 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( ) 55 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( )
54 { 56 {
55 m_name = t; 57 m_name = t;
56 m_styles = styles; 58 m_styles = styles;
57 m_sizes = sizes; 59 m_sizes = sizes;
58 60
59 QString str = t; 61 QString str = t;
60 str [0] = str [0]. upper ( ); 62 str [0] = str [0]. upper ( );
61 setText ( str ); 63 setText ( str );
62 } 64 }
63 65
@@ -88,60 +90,73 @@ static int findItemCB ( QComboBox *box, const QString &str )
88 for ( int i = 0; i < box-> count ( ); i++ ) { 90 for ( int i = 0; i < box-> count ( ); i++ ) {
89 if ( box-> text ( i ) == str ) 91 if ( box-> text ( i ) == str )
90 return i; 92 return i;
91 } 93 }
92 return -1; 94 return -1;
93} 95}
94 96
95 97
96static int qt_version ( ) 98static int qt_version ( )
97{ 99{
98 const char *qver = qVersion ( ); 100 const char *qver = qVersion ( );
99 101
100 return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' ); 102 return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' );
101} 103}
102 104
103 105
104OFontSelector::OFontSelector ( QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) 106OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl )
105{ 107{
106 d = new OFontSelectorPrivate ( ); 108 d = new OFontSelectorPrivate ( );
107 109
108 QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); 110 QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 );
109 gridLayout->setRowStretch ( 4, 10 ); 111 gridLayout->setRowStretch ( 4, 10 );
110 112
111 d-> m_font_family_list = new QListBox( this, "FontListBox" ); 113 d-> m_font_family_list = new QListBox( this, "FontListBox" );
112 gridLayout->addMultiCellWidget( d-> m_font_family_list, 0, 4, 0, 0 ); 114 gridLayout->addMultiCellWidget( d-> m_font_family_list, 0, 4, 0, 0 );
113 connect( d-> m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); 115 connect( d-> m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) );
114 116
115 QLabel *label = new QLabel( tr( "Style" ), this ); 117 QLabel *label = new QLabel( tr( "Style" ), this );
116 gridLayout->addWidget( label, 0, 1 ); 118 gridLayout->addWidget( label, 0, 1 );
117 119
118 d-> m_font_style_list = new QComboBox( this, "StyleListBox" ); 120 d-> m_font_style_list = new QComboBox( this, "StyleListBox" );
119 connect( d-> m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); 121 connect( d-> m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) );
120 gridLayout->addWidget( d-> m_font_style_list, 1, 1 ); 122 gridLayout->addWidget( d-> m_font_style_list, 1, 1 );
121 123
122 label = new QLabel( tr( "Size" ), this ); 124 label = new QLabel( tr( "Size" ), this );
123 gridLayout->addWidget( label, 2, 1 ); 125 gridLayout->addWidget( label, 2, 1 );
124 126
125 d-> m_font_size_list = new QComboBox( this, "SizeListBox" ); 127 d-> m_font_size_list = new QComboBox( this, "SizeListBox" );
126 connect( d-> m_font_size_list, SIGNAL( activated( int ) ), 128 connect( d-> m_font_size_list, SIGNAL( activated( int ) ),
127 this, SLOT( fontSizeClicked( int ) ) ); 129 this, SLOT( fontSizeClicked( int ) ) );
128 gridLayout->addWidget( d-> m_font_size_list, 3, 1 ); 130 gridLayout->addWidget( d-> m_font_size_list, 3, 1 );
129 131
130 d-> m_pointbug = ( qt_version ( ) <= 233 ); 132 d-> m_pointbug = ( qt_version ( ) <= 233 );
131 133
134 if ( withpreview ) {
135 d-> m_preview = new QMultiLineEdit ( this, "Preview" );
136 d-> m_preview-> setAlignment ( AlignCenter );
137 d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth );
138 d-> m_preview-> setMargin ( 3 );
139 d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" ));
140 gridLayout-> addRowSpacing ( 5, 4 );
141 gridLayout-> addMultiCellWidget ( d-> m_preview, 6, 6, 0, 1 );
142 gridLayout-> setRowStretch ( 6, 5 );
143 }
144 else
145 d-> m_preview = 0;
146
132 loadFonts ( d-> m_font_family_list ); 147 loadFonts ( d-> m_font_family_list );
133} 148}
134 149
135OFontSelector::~OFontSelector ( ) 150OFontSelector::~OFontSelector ( )
136{ 151{
137 delete d; 152 delete d;
138} 153}
139 154
140bool OFontSelector::setSelectedFont ( const QFont &f ) 155bool OFontSelector::setSelectedFont ( const QFont &f )
141{ 156{
142 return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( ))); 157 return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( )));
143} 158}
144 159
145bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ ) 160bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ )
146{ 161{
147 QString sizeStr = QString::number ( sizeVal ); 162 QString sizeStr = QString::number ( sizeVal );
@@ -291,37 +306,57 @@ void OFontSelector::fontFamilyClicked ( int index )
291 } 306 }
292 changeFont ( ); 307 changeFont ( );
293} 308}
294 309
295void OFontSelector::fontStyleClicked ( int /*index*/ ) 310void OFontSelector::fontStyleClicked ( int /*index*/ )
296{ 311{
297 changeFont ( ); 312 changeFont ( );
298} 313}
299 314
300void OFontSelector::fontSizeClicked ( int /*index*/ ) 315void OFontSelector::fontSizeClicked ( int /*index*/ )
301{ 316{
302 changeFont ( ); 317 changeFont ( );
303} 318}
304 319
305void OFontSelector::changeFont ( ) 320void OFontSelector::changeFont ( )
306{ 321{
307 emit fontSelected ( selectedFont ( )); 322 QFont f = selectedFont ( );
323
324 if ( d-> m_preview )
325 d-> m_preview-> setFont ( f );
326
327 emit fontSelected ( f );
308} 328}
309 329
310 330
311QFont OFontSelector::selectedFont ( ) 331QFont OFontSelector::selectedFont ( )
312{ 332{
313 int ffa = d-> m_font_family_list-> currentItem ( ); 333 int ffa = d-> m_font_family_list-> currentItem ( );
314 int fst = d-> m_font_style_list-> currentItem ( ); 334 int fst = d-> m_font_style_list-> currentItem ( );
315 int fsi = d-> m_font_size_list-> currentItem ( ); 335 int fsi = d-> m_font_size_list-> currentItem ( );
316 336
317 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); 337 FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa );
318 338
319 if ( fli ) { 339 if ( fli ) {
320 return d-> m_fdb. font ( fli-> family ( ), \ 340 return d-> m_fdb. font ( fli-> family ( ), \
321 fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ 341 fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \
322 fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ 342 fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \
323 d-> m_fdb. charSets ( fli-> family ( )) [0] ); 343 d-> m_fdb. charSets ( fli-> family ( )) [0] );
324 } 344 }
325 else 345 else
326 return QFont ( ); 346 return QFont ( );
327} 347}
348
349
350void OFontSelector::resizeEvent ( QResizeEvent *re )
351{
352 if ( d-> m_preview ) {
353 d-> m_preview-> setMinimumHeight ( 1 );
354 d-> m_preview-> setMaximumHeight ( 32767 );
355 }
356
357 QWidget::resizeEvent ( re );
358
359 if ( d-> m_preview )
360 d-> m_preview-> setFixedHeight ( d-> m_preview-> height ( ));
361
362}
diff --git a/libopie/ofontselector.h b/libopie/ofontselector.h
index a9c8a72..10d16f0 100644
--- a/libopie/ofontselector.h
+++ b/libopie/ofontselector.h
@@ -27,51 +27,54 @@
27*/ 27*/
28 28
29#ifndef __OPIE_FONTSELECTOR_H__ 29#ifndef __OPIE_FONTSELECTOR_H__
30#define __OPIE_FONTSELECTOR_H__ 30#define __OPIE_FONTSELECTOR_H__
31 31
32#include <qwidget.h> 32#include <qwidget.h>
33 33
34class QListBox; 34class QListBox;
35class OFontSelectorPrivate; 35class OFontSelectorPrivate;
36 36
37 37
38class OFontSelector : public QWidget 38class OFontSelector : public QWidget
39{ 39{
40 Q_OBJECT 40 Q_OBJECT
41 41
42public: 42public:
43 OFontSelector ( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 43 OFontSelector ( bool withpreview, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
44 virtual ~OFontSelector ( ); 44 virtual ~OFontSelector ( );
45 45
46 bool selectedFont ( QString &family, QString &style, int &size ); 46 bool selectedFont ( QString &family, QString &style, int &size );
47 bool selectedFont ( QString &family, QString &style, int &size, QString &charset ); 47 bool selectedFont ( QString &family, QString &style, int &size, QString &charset );
48 48
49 QFont selectedFont ( ); 49 QFont selectedFont ( );
50 50
51 bool setSelectedFont ( const QFont & ); 51 bool setSelectedFont ( const QFont & );
52 bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 ); 52 bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 );
53 53
54 QString fontFamily ( ) const; 54 QString fontFamily ( ) const;
55 QString fontStyle ( ) const; 55 QString fontStyle ( ) const;
56 int fontSize ( ) const; 56 int fontSize ( ) const;
57 QString fontCharSet ( ) const; 57 QString fontCharSet ( ) const;
58 58
59signals: 59signals:
60 void fontSelected ( const QFont & ); 60 void fontSelected ( const QFont & );
61 61
62protected slots: 62protected slots:
63 virtual void fontFamilyClicked ( int ); 63 virtual void fontFamilyClicked ( int );
64 virtual void fontStyleClicked ( int ); 64 virtual void fontStyleClicked ( int );
65 virtual void fontSizeClicked ( int ); 65 virtual void fontSizeClicked ( int );
66 66
67protected:
68 virtual void resizeEvent ( QResizeEvent *re );
69
67private: 70private:
68 void loadFonts ( QListBox * ); 71 void loadFonts ( QListBox * );
69 72
70 void changeFont ( ); 73 void changeFont ( );
71 74
72private: 75private:
73 OFontSelectorPrivate *d; 76 OFontSelectorPrivate *d;
74}; 77};
75 78
76#endif 79#endif
77 80