summaryrefslogtreecommitdiff
path: root/libopie
authorsandman <sandman>2002-10-01 16:58:13 (UTC)
committer sandman <sandman>2002-10-01 16:58:13 (UTC)
commit1d9e6c252f74bfc8fcf6c80d8ce2a80cbd566d26 (patch) (side-by-side diff)
treee26b890b3b6679e3067f8c1b8a688d0651fbfa22 /libopie
parent541bd9eaebd630a39a9f1df320bf6e46d499c10a (diff)
downloadopie-1d9e6c252f74bfc8fcf6c80d8ce2a80cbd566d26.zip
opie-1d9e6c252f74bfc8fcf6c80d8ce2a80cbd566d26.tar.gz
opie-1d9e6c252f74bfc8fcf6c80d8ce2a80cbd566d26.tar.bz2
Added runtime detection of Qt version, because all qt/e's <= 2.3.3 return
font sizes *10
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofontselector.cpp202
-rw-r--r--libopie/ofontselector.h11
2 files changed, 118 insertions, 95 deletions
diff --git a/libopie/ofontselector.cpp b/libopie/ofontselector.cpp
index 39440af..e1090b5 100644
--- a/libopie/ofontselector.cpp
+++ b/libopie/ofontselector.cpp
@@ -33,6 +33,19 @@
#include <qfont.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;
+
+ bool m_pointbug;
+
+ FontDatabase m_fdb;
+};
+
class FontListItem : public QListBoxText {
@@ -81,39 +94,51 @@ static int findItemCB ( QComboBox *box, const QString &str )
+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 )
{
- QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 );
- gridLayout->setRowStretch ( 4, 10 );
+ d = new OFontSelectorPrivate ( );
+
+ QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 );
+ gridLayout->setRowStretch ( 4, 10 );
- m_font_family_list = new QListBox( this, "FontListBox" );
- gridLayout->addMultiCellWidget( m_font_family_list, 0, 4, 0, 0 );
- connect( m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) );
+ 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 );
+ QLabel *label = new QLabel( tr( "Style" ), this );
+ gridLayout->addWidget( label, 0, 1 );
- m_font_style_list = new QComboBox( this, "StyleListBox" );
- connect( m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) );
- gridLayout->addWidget( m_font_style_list, 1, 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 );
+ label = new QLabel( tr( "Size" ), this );
+ gridLayout->addWidget( label, 2, 1 );
- m_font_size_list = new QComboBox( this, "SizeListBox" );
- connect( m_font_size_list, SIGNAL( activated( int ) ),
- this, SLOT( fontSizeClicked( int ) ) );
- gridLayout->addWidget( m_font_size_list, 3, 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 );
- loadFonts ( m_font_family_list );
+ d-> m_pointbug = ( qt_version ( ) <= 233 );
+
+ loadFonts ( d-> m_font_family_list );
}
OFontSelector::~OFontSelector ( )
{
+ delete d;
}
bool OFontSelector::setSelectedFont ( const QFont &f )
{
- return setSelectedFont ( f. family ( ), m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( )));
+ return setSelectedFont ( f. family ( ), d-> m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( )));
}
@@ -122,31 +147,29 @@ bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &s
QString sizeStr = QString::number ( sizeVal );
- QListBoxItem *family = m_font_family_list-> findItem ( familyStr );
+ QListBoxItem *family = d-> m_font_family_list-> findItem ( familyStr );
if ( !family )
- family = m_font_family_list-> findItem ( "Helvetica" );
+ family = d-> m_font_family_list-> findItem ( "Helvetica" );
if ( !family )
- family = m_font_family_list-> firstItem ( );
- m_font_family_list-> setCurrentItem ( family );
- fontFamilyClicked ( m_font_family_list-> index ( family ));
+ family = d-> m_font_family_list-> firstItem ( );
+ d-> m_font_family_list-> setCurrentItem ( family );
+ fontFamilyClicked ( d-> m_font_family_list-> index ( family ));
- int style = findItemCB ( m_font_style_list, styleStr );
+ int style = findItemCB ( d-> m_font_style_list, styleStr );
if ( style < 0 )
- style = findItemCB ( m_font_style_list, "Regular" );
- if ( style < 0 && m_font_style_list-> count ( ) > 0 )
+ style = findItemCB ( d-> m_font_style_list, "Regular" );
+ if ( style < 0 && d-> m_font_style_list-> count ( ) > 0 )
style = 0;
- m_font_style_list-> setCurrentItem ( style );
+ d-> m_font_style_list-> setCurrentItem ( style );
fontStyleClicked ( style );
- int size = findItemCB ( m_font_size_list, sizeStr );
+ int size = findItemCB ( d-> m_font_size_list, sizeStr );
if ( size < 0 )
- size = findItemCB ( m_font_size_list, "10" );
- if ( size < 0 && m_font_size_list-> count ( ) > 0 )
+ size = findItemCB ( d-> m_font_size_list, "10" );
+ if ( size < 0 && d-> m_font_size_list-> count ( ) > 0 )
size = 0;
- m_font_size_list-> setCurrentItem ( size );
+ d-> m_font_size_list-> setCurrentItem ( size );
fontSizeClicked ( size );
- return (( family ) &&
- ( style >= 0 ) &&
- ( size >= 0 ));
+ return (( family ) && ( style >= 0 ) && ( size >= 0 ));
}
@@ -160,5 +183,5 @@ bool OFontSelector::selectedFont ( QString &family, QString &style, int &size )
QString OFontSelector::fontFamily ( ) const
{
- FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( ));
+ FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
return fli ? fli-> family ( ) : QString::null;
@@ -167,6 +190,6 @@ QString OFontSelector::fontFamily ( ) const
QString OFontSelector::fontStyle ( ) const
{
- FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( ));
- int fst = m_font_style_list-> currentItem ( );
+ FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
+ int fst = d-> m_font_style_list-> currentItem ( );
return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null;
@@ -175,6 +198,6 @@ QString OFontSelector::fontStyle ( ) const
int OFontSelector::fontSize ( ) const
{
- FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( ));
- int fsi = m_font_size_list-> currentItem ( );
+ FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
+ int fsi = d-> m_font_size_list-> currentItem ( );
return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10;
@@ -183,22 +206,22 @@ int OFontSelector::fontSize ( ) const
QString OFontSelector::fontCharSet ( ) const
{
- FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( ));
+ FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
- return fli ? m_fdb. charSets ( fli-> family ( )) [0] : QString::null;
+ return fli ? d-> m_fdb. charSets ( fli-> family ( )) [0] : QString::null;
}
bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset )
{
- int ffa = m_font_family_list-> currentItem ( );
- int fst = m_font_style_list-> currentItem ( );
- int fsi = m_font_size_list-> currentItem ( );
-
- FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa );
-
- if ( fli ) {
- family = fli-> family ( );
- style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null;
- size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10;
- charset = m_fdb. charSets ( fli-> family ( )) [0];
+ 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 ) {
+ family = fli-> family ( );
+ style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null;
+ size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10;
+ charset = d-> m_fdb. charSets ( fli-> family ( )) [0];
return true;
@@ -209,52 +232,60 @@ bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, Q
-
+
void OFontSelector::loadFonts ( QListBox *list )
{
- QStringList f = m_fdb. families ( );
+ QStringList f = d-> m_fdb. families ( );
- for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it )
- list-> insertItem ( new FontListItem ( *it, m_fdb. styles ( *it ), m_fdb. pointSizes ( *it )));
+ for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) {
+ QValueList <int> ps = d-> m_fdb. pointSizes ( *it );
+
+ if ( d-> m_pointbug ) {
+ for ( QValueList <int>::Iterator it = ps. begin ( ); it != ps. end ( ); it++ )
+ *it /= 10;
+ }
+
+ list-> insertItem ( new FontListItem ( *it, d-> m_fdb. styles ( *it ), ps ));
+ }
}
void OFontSelector::fontFamilyClicked ( int index )
{
- QString oldstyle = m_font_style_list-> currentText ( );
- QString oldsize = m_font_size_list-> currentText ( );
+ QString oldstyle = d-> m_font_style_list-> currentText ( );
+ QString oldsize = d-> m_font_size_list-> currentText ( );
- FontListItem *fli = (FontListItem *) m_font_family_list-> item ( index );
-
- m_font_style_list-> clear ( );
- m_font_style_list-> insertStringList ( fli-> styles ( ));
- m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( ));
+ FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( index );
+
+ d-> m_font_style_list-> clear ( );
+ d-> m_font_style_list-> insertStringList ( fli-> styles ( ));
+ d-> m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( ));
int i;
- i = findItemCB ( m_font_style_list, oldstyle );
+ i = findItemCB ( d-> m_font_style_list, oldstyle );
if ( i < 0 )
- i = findItemCB ( m_font_style_list, "Regular" );
- if (( i < 0 ) && ( m_font_style_list-> count ( ) > 0 ))
+ i = findItemCB ( d-> m_font_style_list, "Regular" );
+ if (( i < 0 ) && ( d-> m_font_style_list-> count ( ) > 0 ))
i = 0;
if ( i >= 0 ) {
- m_font_style_list-> setCurrentItem ( i );
+ d-> m_font_style_list-> setCurrentItem ( i );
fontStyleClicked ( i );
}
- m_font_size_list-> clear ( );
+ d-> m_font_size_list-> clear ( );
QValueList<int> sl = fli-> sizes ( );
for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
- m_font_size_list-> insertItem ( QString::number ( *it ));
+ d-> m_font_size_list-> insertItem ( QString::number ( *it ));
- i = findItemCB ( m_font_size_list, oldsize );
+ i = findItemCB ( d-> m_font_size_list, oldsize );
if ( i < 0 )
- i = findItemCB ( m_font_size_list, "10" );
- if (( i < 0 ) && ( m_font_size_list-> count ( ) > 0 ))
+ i = findItemCB ( d-> m_font_size_list, "10" );
+ if (( i < 0 ) && ( d-> m_font_size_list-> count ( ) > 0 ))
i = 0;
if ( i >= 0 ) {
- m_font_size_list-> setCurrentItem ( i );
+ d-> m_font_size_list-> setCurrentItem ( i );
fontSizeClicked ( i );
}
@@ -280,20 +311,17 @@ void OFontSelector::changeFont ( )
QFont OFontSelector::selectedFont ( )
{
- int ffa = m_font_family_list-> currentItem ( );
- int fst = m_font_style_list-> currentItem ( );
- int fsi = m_font_size_list-> currentItem ( );
-
- FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa );
-
- if ( fli ) {
- return m_fdb. font ( fli-> family ( ), \
- fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \
- fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \
- m_fdb. charSets ( fli-> family ( )) [0] );
+ 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 ( );
}
-
-
- \ No newline at end of file
diff --git a/libopie/ofontselector.h b/libopie/ofontselector.h
index b3aa862..a9c8a72 100644
--- a/libopie/ofontselector.h
+++ b/libopie/ofontselector.h
@@ -31,9 +31,8 @@
#include <qwidget.h>
-#include <qpe/fontdatabase.h>
-class QComboBox;
class QListBox;
-class QFont;
+class OFontSelectorPrivate;
+
class OFontSelector : public QWidget
@@ -72,9 +71,5 @@ private:
private:
- QListBox * m_font_family_list;
- QComboBox * m_font_style_list;
- QComboBox * m_font_size_list;
-
- FontDatabase m_fdb;
+ OFontSelectorPrivate *d;
};