author | sandman <sandman> | 2002-10-01 20:58:30 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-10-01 20:58:30 (UTC) |
commit | 2906826d9ebc268bc233f97956ee1dc5b338c69b (patch) (side-by-side diff) | |
tree | d6af20025d6ac5e9220a3f1458d1985df8a6cc93 /libopie | |
parent | 88bef2791f8e4c99e0e9d34ddfe518b5baa2df72 (diff) | |
download | opie-2906826d9ebc268bc233f97956ee1dc5b338c69b.zip opie-2906826d9ebc268bc233f97956ee1dc5b338c69b.tar.gz opie-2906826d9ebc268bc233f97956ee1dc5b338c69b.tar.bz2 |
OFontSelector has now an optional builtin preview widget
-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 @@ -10,62 +10,64 @@ ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This library is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <qlayout.h> #include <qlistbox.h> #include <qcombobox.h> #include <qlabel.h> #include <qfont.h> +#include <qmultilineedit.h> #include <qpe/fontdatabase.h> #include "ofontselector.h" class OFontSelectorPrivate { -public: - QListBox * m_font_family_list; - QComboBox * m_font_style_list; - QComboBox * m_font_size_list; +public: + QListBox * m_font_family_list; + QComboBox * m_font_style_list; + QComboBox * m_font_size_list; + QMultiLineEdit *m_preview; - bool m_pointbug; + bool m_pointbug; - FontDatabase m_fdb; + FontDatabase m_fdb; }; class FontListItem : public QListBoxText { public: FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( ) { m_name = t; m_styles = styles; m_sizes = sizes; QString str = t; str [0] = str [0]. upper ( ); setText ( str ); } QString family ( ) const { return m_name; } const QStringList &styles ( ) const { return m_styles; @@ -80,76 +82,89 @@ private: QStringList m_styles; QValueList<int> m_sizes; QString m_name; }; static int findItemCB ( QComboBox *box, const QString &str ) { for ( int i = 0; i < box-> count ( ); i++ ) { if ( box-> text ( i ) == str ) return i; } return -1; } static int qt_version ( ) { const char *qver = qVersion ( ); return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' ); } -OFontSelector::OFontSelector ( QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) +OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) { d = new OFontSelectorPrivate ( ); QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); gridLayout->setRowStretch ( 4, 10 ); d-> m_font_family_list = new QListBox( this, "FontListBox" ); gridLayout->addMultiCellWidget( d-> m_font_family_list, 0, 4, 0, 0 ); connect( d-> m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); QLabel *label = new QLabel( tr( "Style" ), this ); gridLayout->addWidget( label, 0, 1 ); d-> m_font_style_list = new QComboBox( this, "StyleListBox" ); connect( d-> m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); gridLayout->addWidget( d-> m_font_style_list, 1, 1 ); label = new QLabel( tr( "Size" ), this ); gridLayout->addWidget( label, 2, 1 ); d-> m_font_size_list = new QComboBox( this, "SizeListBox" ); connect( d-> m_font_size_list, SIGNAL( activated( int ) ), this, SLOT( fontSizeClicked( int ) ) ); gridLayout->addWidget( d-> m_font_size_list, 3, 1 ); d-> m_pointbug = ( qt_version ( ) <= 233 ); + if ( withpreview ) { + d-> m_preview = new QMultiLineEdit ( this, "Preview" ); + d-> m_preview-> setAlignment ( AlignCenter ); + d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth ); + d-> m_preview-> setMargin ( 3 ); + d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); + gridLayout-> addRowSpacing ( 5, 4 ); + gridLayout-> addMultiCellWidget ( d-> m_preview, 6, 6, 0, 1 ); + gridLayout-> setRowStretch ( 6, 5 ); + } + else + d-> m_preview = 0; + loadFonts ( d-> m_font_family_list ); } OFontSelector::~OFontSelector ( ) { delete d; } bool OFontSelector::setSelectedFont ( const QFont &f ) { return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( ))); } bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ ) { QString sizeStr = QString::number ( sizeVal ); QListBoxItem *family = d-> m_font_family_list-> findItem ( familyStr ); if ( !family ) family = d-> m_font_family_list-> findItem ( "Helvetica" ); if ( !family ) family = d-> m_font_family_list-> firstItem ( ); d-> m_font_family_list-> setCurrentItem ( family ); fontFamilyClicked ( d-> m_font_family_list-> index ( family )); @@ -283,45 +298,65 @@ void OFontSelector::fontFamilyClicked ( int index ) if ( i < 0 ) i = findItemCB ( d-> m_font_size_list, "10" ); if (( i < 0 ) && ( d-> m_font_size_list-> count ( ) > 0 )) i = 0; if ( i >= 0 ) { d-> m_font_size_list-> setCurrentItem ( i ); fontSizeClicked ( i ); } changeFont ( ); } void OFontSelector::fontStyleClicked ( int /*index*/ ) { changeFont ( ); } void OFontSelector::fontSizeClicked ( int /*index*/ ) { changeFont ( ); } void OFontSelector::changeFont ( ) { - emit fontSelected ( selectedFont ( )); + QFont f = selectedFont ( ); + + if ( d-> m_preview ) + d-> m_preview-> setFont ( f ); + + emit fontSelected ( f ); } QFont OFontSelector::selectedFont ( ) { int ffa = d-> m_font_family_list-> currentItem ( ); int fst = d-> m_font_style_list-> currentItem ( ); int fsi = d-> m_font_size_list-> currentItem ( ); FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); if ( fli ) { return d-> m_fdb. font ( fli-> family ( ), \ fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ d-> m_fdb. charSets ( fli-> family ( )) [0] ); } else return QFont ( ); } + + +void OFontSelector::resizeEvent ( QResizeEvent *re ) +{ + if ( d-> m_preview ) { + d-> m_preview-> setMinimumHeight ( 1 ); + d-> m_preview-> setMaximumHeight ( 32767 ); + } + + QWidget::resizeEvent ( re ); + + if ( d-> m_preview ) + d-> m_preview-> setFixedHeight ( d-> m_preview-> height ( )); + +} diff --git a/libopie/ofontselector.h b/libopie/ofontselector.h index a9c8a72..10d16f0 100644 --- a/libopie/ofontselector.h +++ b/libopie/ofontselector.h @@ -19,59 +19,62 @@ : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __OPIE_FONTSELECTOR_H__ #define __OPIE_FONTSELECTOR_H__ #include <qwidget.h> class QListBox; class OFontSelectorPrivate; class OFontSelector : public QWidget { Q_OBJECT public: - OFontSelector ( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + OFontSelector ( bool withpreview, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); virtual ~OFontSelector ( ); bool selectedFont ( QString &family, QString &style, int &size ); bool selectedFont ( QString &family, QString &style, int &size, QString &charset ); QFont selectedFont ( ); bool setSelectedFont ( const QFont & ); bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 ); QString fontFamily ( ) const; QString fontStyle ( ) const; int fontSize ( ) const; QString fontCharSet ( ) const; signals: void fontSelected ( const QFont & ); protected slots: virtual void fontFamilyClicked ( int ); virtual void fontStyleClicked ( int ); virtual void fontSizeClicked ( int ); +protected: + virtual void resizeEvent ( QResizeEvent *re ); + private: void loadFonts ( QListBox * ); void changeFont ( ); private: OFontSelectorPrivate *d; }; #endif |