summaryrefslogtreecommitdiff
path: root/libopie/ofontselector.cpp
Side-by-side diff
Diffstat (limited to 'libopie/ofontselector.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie/ofontselector.cpp60
1 files changed, 55 insertions, 5 deletions
diff --git a/libopie/ofontselector.cpp b/libopie/ofontselector.cpp
index b905474..c8471cc 100644
--- a/libopie/ofontselector.cpp
+++ b/libopie/ofontselector.cpp
@@ -35,29 +35,30 @@
#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;
QMultiLineEdit *m_preview;
- bool m_pointbug;
+ bool m_pointbug : 1;
FontDatabase m_fdb;
};
+namespace {
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 );
@@ -85,33 +86,40 @@ private:
};
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 same as anon. namespace */
static int qt_version ( )
{
const char *qver = qVersion ( );
return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' );
}
-
+/**
+ * Constructs the Selector object
+ * @param withpreview If a font preview should be given
+ * @param parent The parent of the Font Selector
+ * @param name The name of the object
+ * @param fl WidgetFlags
+ */
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 );
@@ -143,30 +151,43 @@ OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *na
}
else
d-> m_preview = 0;
loadFonts ( d-> m_font_family_list );
}
OFontSelector::~OFontSelector ( )
{
delete d;
}
+/**
+ * This methods tries to set the font
+ * @param f The wishes font
+ * @return success or failure
+ */
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*/ )
+
+/**
+ * This is an overloaded method @see setSelectedFont
+ * @param familyStr The family of the font
+ * @param styleStr The style of the font
+ * @param sizeVal The size of font
+ * @param charset The charset to be used. Will be deprecated by QT3
+ */
+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 ));
int style = findItemCB ( d-> m_font_style_list, styleStr );
@@ -179,61 +200,88 @@ bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &s
int size = findItemCB ( d-> m_font_size_list, sizeStr );
if ( size < 0 )
size = findItemCB ( d-> m_font_size_list, "10" );
if ( size < 0 && d-> m_font_size_list-> count ( ) > 0 )
size = 0;
d-> m_font_size_list-> setCurrentItem ( size );
fontSizeClicked ( size );
return (( family ) && ( style >= 0 ) && ( size >= 0 ));
}
+/**
+ * This method returns the name, style and size of the currently selected
+ * font or false if no font is selected
+ * @param family The font family will be written there
+ * @param style The style will be written there
+ * @param size The size will be written there
+ * @return success or failure
+ */
bool OFontSelector::selectedFont ( QString &family, QString &style, int &size )
{
QString dummy;
return selectedFont ( family, style, size, dummy );
}
+/**
+ * This method does return the font family or QString::null if there is
+ * no font item selected
+ * @return the font family
+ */
QString OFontSelector::fontFamily ( ) const
{
FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
return fli ? fli-> family ( ) : QString::null;
}
+/**
+ * This method will return the style of the font or QString::null
+ * @return the style of the font
+ */
QString OFontSelector::fontStyle ( ) const
{
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;
}
+/**
+ * This method will return the font size or 10 if no font size is available
+ */
int OFontSelector::fontSize ( ) const
{
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;
}
+/**
+ * returns the charset of the font or QString::null
+ */
QString OFontSelector::fontCharSet ( ) const
{
FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( ));
return fli ? d-> m_fdb. charSets ( fli-> family ( )) [0] : QString::null;
}
+/**
+ * Overloaded member function see above
+ * @see selectedFont
+ */
bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset )
{
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;
@@ -318,25 +366,27 @@ void OFontSelector::fontSizeClicked ( int /*index*/ )
}
void OFontSelector::changeFont ( )
{
QFont f = selectedFont ( );
if ( d-> m_preview )
d-> m_preview-> setFont ( f );
emit fontSelected ( f );
}
-
+/**
+ * Return the selected font
+ */
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, \