-rw-r--r-- | libopie/ofontselector.cpp | 51 | ||||
-rw-r--r-- | libopie/ofontselector.h | 5 |
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 | |||
@@ -28,26 +28,28 @@ | |||
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 | ||
39 | class OFontSelectorPrivate { | 40 | class OFontSelectorPrivate { |
40 | public: | 41 | public: |
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 | ||
51 | class FontListItem : public QListBoxText { | 53 | class FontListItem : public QListBoxText { |
52 | public: | 54 | public: |
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 ( ) |
@@ -98,13 +100,13 @@ static int qt_version ( ) | |||
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 | ||
104 | OFontSelector::OFontSelector ( QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) | 106 | OFontSelector::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 | ||
@@ -126,12 +128,25 @@ OFontSelector::OFontSelector ( QWidget *parent, const char *name, WFlags fl ) : | |||
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 | ||
135 | OFontSelector::~OFontSelector ( ) | 150 | OFontSelector::~OFontSelector ( ) |
136 | { | 151 | { |
137 | delete d; | 152 | delete d; |
@@ -301,13 +316,18 @@ void OFontSelector::fontSizeClicked ( int /*index*/ ) | |||
301 | { | 316 | { |
302 | changeFont ( ); | 317 | changeFont ( ); |
303 | } | 318 | } |
304 | 319 | ||
305 | void OFontSelector::changeFont ( ) | 320 | void 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 | ||
311 | QFont OFontSelector::selectedFont ( ) | 331 | QFont OFontSelector::selectedFont ( ) |
312 | { | 332 | { |
313 | int ffa = d-> m_font_family_list-> currentItem ( ); | 333 | int ffa = d-> m_font_family_list-> currentItem ( ); |
@@ -322,6 +342,21 @@ QFont OFontSelector::selectedFont ( ) | |||
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 | |||
350 | void 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 | |||
@@ -37,13 +37,13 @@ class OFontSelectorPrivate; | |||
37 | 37 | ||
38 | class OFontSelector : public QWidget | 38 | class OFontSelector : public QWidget |
39 | { | 39 | { |
40 | Q_OBJECT | 40 | Q_OBJECT |
41 | 41 | ||
42 | public: | 42 | public: |
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 ( ); |
@@ -61,12 +61,15 @@ signals: | |||
61 | 61 | ||
62 | protected slots: | 62 | protected 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 | ||
67 | protected: | ||
68 | virtual void resizeEvent ( QResizeEvent *re ); | ||
69 | |||
67 | private: | 70 | private: |
68 | void loadFonts ( QListBox * ); | 71 | void loadFonts ( QListBox * ); |
69 | 72 | ||
70 | void changeFont ( ); | 73 | void changeFont ( ); |
71 | 74 | ||
72 | private: | 75 | private: |