author | sandman <sandman> | 2002-09-27 00:54:58 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-09-27 00:54:58 (UTC) |
commit | dcd5eb6949787321c278b10772bd75a27ec6d508 (patch) (unidiff) | |
tree | 12525523ac676e6b43419f742afb6b1d007d61da | |
parent | aec4806d28c0422e9d0572e9601d6dc41a9cdd61 (diff) | |
download | opie-dcd5eb6949787321c278b10772bd75a27ec6d508.zip opie-dcd5eb6949787321c278b10772bd75a27ec6d508.tar.gz opie-dcd5eb6949787321c278b10772bd75a27ec6d508.tar.bz2 |
- size tweak for OColorButton
- new convenience methods in OFontSelector
-rw-r--r-- | libopie/ocolorbutton.cpp | 5 | ||||
-rw-r--r-- | libopie/ofontselector.cpp | 5 | ||||
-rw-r--r-- | libopie/ofontselector.h | 1 |
3 files changed, 10 insertions, 1 deletions
diff --git a/libopie/ocolorbutton.cpp b/libopie/ocolorbutton.cpp index 96e5612..4734c0c 100644 --- a/libopie/ocolorbutton.cpp +++ b/libopie/ocolorbutton.cpp | |||
@@ -1,118 +1,121 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | 3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This library is free software; you can | 5 | _;:, .> :=|. This library is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This library is distributed in the hope that | 12 | .i_,=:_. -<s. This library is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
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 <opie/colorpopupmenu.h> | 29 | #include <opie/colorpopupmenu.h> |
30 | #include <opie/ocolorbutton.h> | 30 | #include <opie/ocolorbutton.h> |
31 | #include <qcolor.h> | 31 | #include <qcolor.h> |
32 | #include <qpixmap.h> | 32 | #include <qpixmap.h> |
33 | #include <qimage.h> | 33 | #include <qimage.h> |
34 | 34 | ||
35 | #include <qpe/resource.h> | 35 | #include <qpe/resource.h> |
36 | 36 | ||
37 | class OColorButtonPrivate { | 37 | class OColorButtonPrivate { |
38 | public: | 38 | public: |
39 | QPopupMenu *m_menu; | 39 | QPopupMenu *m_menu; |
40 | QColor m_color; | 40 | QColor m_color; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | OColorButton::OColorButton ( QWidget *parent, const char *name ) | 43 | OColorButton::OColorButton ( QWidget *parent, const char *name ) |
44 | : QPushButton ( parent, name ) | 44 | : QPushButton ( parent, name ) |
45 | { | 45 | { |
46 | d = new OColorButtonPrivate; | 46 | d = new OColorButtonPrivate; |
47 | 47 | ||
48 | d-> m_menu = new ColorPopupMenu ( black, 0, 0 ); | 48 | d-> m_menu = new ColorPopupMenu ( black, 0, 0 ); |
49 | setPopup ( d-> m_menu ); | 49 | setPopup ( d-> m_menu ); |
50 | //setPopupDelay ( 0 ); | 50 | //setPopupDelay ( 0 ); |
51 | connect ( d-> m_menu, SIGNAL( colorSelected ( const QColor & )), this, SLOT( updateColor ( const QColor & ))); | 51 | connect ( d-> m_menu, SIGNAL( colorSelected ( const QColor & )), this, SLOT( updateColor ( const QColor & ))); |
52 | 52 | ||
53 | updateColor ( black ); | 53 | updateColor ( black ); |
54 | setMinimumSize ( sizeHint ( ) + QSize ( 8, 0 )); | 54 | |
55 | QSize s = sizeHint ( ) + QSize ( 12, 0 ); | ||
56 | setMinimumSize ( s ); | ||
57 | setMaximumSize ( s. width ( ) * 2, s. height ( )); | ||
55 | } | 58 | } |
56 | 59 | ||
57 | OColorButton::~OColorButton ( ) | 60 | OColorButton::~OColorButton ( ) |
58 | { | 61 | { |
59 | delete d; | 62 | delete d; |
60 | } | 63 | } |
61 | 64 | ||
62 | QColor OColorButton::color ( ) const | 65 | QColor OColorButton::color ( ) const |
63 | { | 66 | { |
64 | return d-> m_color; | 67 | return d-> m_color; |
65 | } | 68 | } |
66 | 69 | ||
67 | void OColorButton::setColor ( const QColor &c ) | 70 | void OColorButton::setColor ( const QColor &c ) |
68 | { | 71 | { |
69 | updateColor ( c ); | 72 | updateColor ( c ); |
70 | } | 73 | } |
71 | 74 | ||
72 | void OColorButton::updateColor ( const QColor &c ) | 75 | void OColorButton::updateColor ( const QColor &c ) |
73 | { | 76 | { |
74 | d-> m_color = c; | 77 | d-> m_color = c; |
75 | 78 | ||
76 | QImage img ( 16, 16, 32 ); | 79 | QImage img ( 16, 16, 32 ); |
77 | img. fill ( 0 ); | 80 | img. fill ( 0 ); |
78 | 81 | ||
79 | int r, g, b; | 82 | int r, g, b; |
80 | c. rgb ( &r, &g, &b ); | 83 | c. rgb ( &r, &g, &b ); |
81 | 84 | ||
82 | int w = img. width ( ); | 85 | int w = img. width ( ); |
83 | int h = img. height ( ); | 86 | int h = img. height ( ); |
84 | 87 | ||
85 | int dx = w * 20 / 100; // 15% | 88 | int dx = w * 20 / 100; // 15% |
86 | int dy = h * 20 / 100; | 89 | int dy = h * 20 / 100; |
87 | 90 | ||
88 | for ( int y = 0; y < h; y++ ) { | 91 | for ( int y = 0; y < h; y++ ) { |
89 | for ( int x = 0; x < w; x++ ) { | 92 | for ( int x = 0; x < w; x++ ) { |
90 | double alpha = 1.0; | 93 | double alpha = 1.0; |
91 | 94 | ||
92 | if ( x < dx ) | 95 | if ( x < dx ) |
93 | alpha *= ( double ( x + 1 ) / dx ); | 96 | alpha *= ( double ( x + 1 ) / dx ); |
94 | else if ( x >= w - dx ) | 97 | else if ( x >= w - dx ) |
95 | alpha *= ( double ( w - x ) / dx ); | 98 | alpha *= ( double ( w - x ) / dx ); |
96 | if ( y < dy ) | 99 | if ( y < dy ) |
97 | alpha *= ( double ( y + 1 ) / dy ); | 100 | alpha *= ( double ( y + 1 ) / dy ); |
98 | else if ( y >= h - dy ) | 101 | else if ( y >= h - dy ) |
99 | alpha *= ( double ( h - y ) / dy ); | 102 | alpha *= ( double ( h - y ) / dy ); |
100 | 103 | ||
101 | int a = int ( alpha * 255.0 ); | 104 | int a = int ( alpha * 255.0 ); |
102 | if ( a < 0 ) | 105 | if ( a < 0 ) |
103 | a = 0; | 106 | a = 0; |
104 | if ( a > 255 ) | 107 | if ( a > 255 ) |
105 | a = 255; | 108 | a = 255; |
106 | 109 | ||
107 | img. setPixel ( x, y, qRgba ( r, g, b, a )); | 110 | img. setPixel ( x, y, qRgba ( r, g, b, a )); |
108 | } | 111 | } |
109 | } | 112 | } |
110 | img. setAlphaBuffer ( true ); | 113 | img. setAlphaBuffer ( true ); |
111 | 114 | ||
112 | QPixmap pix; | 115 | QPixmap pix; |
113 | pix. convertFromImage ( img ); | 116 | pix. convertFromImage ( img ); |
114 | setPixmap ( pix ); | 117 | setPixmap ( pix ); |
115 | 118 | ||
116 | emit colorSelected ( c ); | 119 | emit colorSelected ( c ); |
117 | } | 120 | } |
118 | 121 | ||
diff --git a/libopie/ofontselector.cpp b/libopie/ofontselector.cpp index d32aeb4..39440af 100644 --- a/libopie/ofontselector.cpp +++ b/libopie/ofontselector.cpp | |||
@@ -1,294 +1,299 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | 3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This library is free software; you can | 5 | _;:, .> :=|. This library is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This library is distributed in the hope that | 12 | .i_,=:_. -<s. This library is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
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 | 34 | ||
35 | #include "ofontselector.h" | 35 | #include "ofontselector.h" |
36 | 36 | ||
37 | 37 | ||
38 | class FontListItem : public QListBoxText { | 38 | class FontListItem : public QListBoxText { |
39 | public: | 39 | public: |
40 | FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( ) | 40 | FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( ) |
41 | { | 41 | { |
42 | m_name = t; | 42 | m_name = t; |
43 | m_styles = styles; | 43 | m_styles = styles; |
44 | m_sizes = sizes; | 44 | m_sizes = sizes; |
45 | 45 | ||
46 | QString str = t; | 46 | QString str = t; |
47 | str [0] = str [0]. upper ( ); | 47 | str [0] = str [0]. upper ( ); |
48 | setText ( str ); | 48 | setText ( str ); |
49 | } | 49 | } |
50 | 50 | ||
51 | QString family ( ) const | 51 | QString family ( ) const |
52 | { | 52 | { |
53 | return m_name; | 53 | return m_name; |
54 | } | 54 | } |
55 | 55 | ||
56 | const QStringList &styles ( ) const | 56 | const QStringList &styles ( ) const |
57 | { | 57 | { |
58 | return m_styles; | 58 | return m_styles; |
59 | } | 59 | } |
60 | 60 | ||
61 | const QValueList<int> &sizes ( ) const | 61 | const QValueList<int> &sizes ( ) const |
62 | { | 62 | { |
63 | return m_sizes; | 63 | return m_sizes; |
64 | } | 64 | } |
65 | 65 | ||
66 | private: | 66 | private: |
67 | QStringList m_styles; | 67 | QStringList m_styles; |
68 | QValueList<int> m_sizes; | 68 | QValueList<int> m_sizes; |
69 | QString m_name; | 69 | QString m_name; |
70 | }; | 70 | }; |
71 | 71 | ||
72 | 72 | ||
73 | static int findItemCB ( QComboBox *box, const QString &str ) | 73 | static int findItemCB ( QComboBox *box, const QString &str ) |
74 | { | 74 | { |
75 | for ( int i = 0; i < box-> count ( ); i++ ) { | 75 | for ( int i = 0; i < box-> count ( ); i++ ) { |
76 | if ( box-> text ( i ) == str ) | 76 | if ( box-> text ( i ) == str ) |
77 | return i; | 77 | return i; |
78 | } | 78 | } |
79 | return -1; | 79 | return -1; |
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | 83 | ||
84 | OFontSelector::OFontSelector ( QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) | 84 | OFontSelector::OFontSelector ( QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) |
85 | { | 85 | { |
86 | QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); | 86 | QGridLayout *gridLayout = new QGridLayout ( this, 0, 0, 4, 4 ); |
87 | gridLayout->setRowStretch ( 4, 10 ); | 87 | gridLayout->setRowStretch ( 4, 10 ); |
88 | 88 | ||
89 | m_font_family_list = new QListBox( this, "FontListBox" ); | 89 | m_font_family_list = new QListBox( this, "FontListBox" ); |
90 | gridLayout->addMultiCellWidget( m_font_family_list, 0, 4, 0, 0 ); | 90 | gridLayout->addMultiCellWidget( m_font_family_list, 0, 4, 0, 0 ); |
91 | connect( m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); | 91 | connect( m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); |
92 | 92 | ||
93 | QLabel *label = new QLabel( tr( "Style" ), this ); | 93 | QLabel *label = new QLabel( tr( "Style" ), this ); |
94 | gridLayout->addWidget( label, 0, 1 ); | 94 | gridLayout->addWidget( label, 0, 1 ); |
95 | 95 | ||
96 | m_font_style_list = new QComboBox( this, "StyleListBox" ); | 96 | m_font_style_list = new QComboBox( this, "StyleListBox" ); |
97 | connect( m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); | 97 | connect( m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); |
98 | gridLayout->addWidget( m_font_style_list, 1, 1 ); | 98 | gridLayout->addWidget( m_font_style_list, 1, 1 ); |
99 | 99 | ||
100 | label = new QLabel( tr( "Size" ), this ); | 100 | label = new QLabel( tr( "Size" ), this ); |
101 | gridLayout->addWidget( label, 2, 1 ); | 101 | gridLayout->addWidget( label, 2, 1 ); |
102 | 102 | ||
103 | m_font_size_list = new QComboBox( this, "SizeListBox" ); | 103 | m_font_size_list = new QComboBox( this, "SizeListBox" ); |
104 | connect( m_font_size_list, SIGNAL( activated( int ) ), | 104 | connect( m_font_size_list, SIGNAL( activated( int ) ), |
105 | this, SLOT( fontSizeClicked( int ) ) ); | 105 | this, SLOT( fontSizeClicked( int ) ) ); |
106 | gridLayout->addWidget( m_font_size_list, 3, 1 ); | 106 | gridLayout->addWidget( m_font_size_list, 3, 1 ); |
107 | 107 | ||
108 | loadFonts ( m_font_family_list ); | 108 | loadFonts ( m_font_family_list ); |
109 | } | 109 | } |
110 | 110 | ||
111 | OFontSelector::~OFontSelector ( ) | 111 | OFontSelector::~OFontSelector ( ) |
112 | { | 112 | { |
113 | } | 113 | } |
114 | 114 | ||
115 | bool OFontSelector::setSelectedFont ( const QFont &f ) | ||
116 | { | ||
117 | return setSelectedFont ( f. family ( ), m_fdb. styleString ( f ), f. pointSize ( ), QFont::encodingName ( f. charSet ( ))); | ||
118 | } | ||
119 | |||
115 | bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ ) | 120 | bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ ) |
116 | { | 121 | { |
117 | QString sizeStr = QString::number ( sizeVal ); | 122 | QString sizeStr = QString::number ( sizeVal ); |
118 | 123 | ||
119 | QListBoxItem *family = m_font_family_list-> findItem ( familyStr ); | 124 | QListBoxItem *family = m_font_family_list-> findItem ( familyStr ); |
120 | if ( !family ) | 125 | if ( !family ) |
121 | family = m_font_family_list-> findItem ( "Helvetica" ); | 126 | family = m_font_family_list-> findItem ( "Helvetica" ); |
122 | if ( !family ) | 127 | if ( !family ) |
123 | family = m_font_family_list-> firstItem ( ); | 128 | family = m_font_family_list-> firstItem ( ); |
124 | m_font_family_list-> setCurrentItem ( family ); | 129 | m_font_family_list-> setCurrentItem ( family ); |
125 | fontFamilyClicked ( m_font_family_list-> index ( family )); | 130 | fontFamilyClicked ( m_font_family_list-> index ( family )); |
126 | 131 | ||
127 | int style = findItemCB ( m_font_style_list, styleStr ); | 132 | int style = findItemCB ( m_font_style_list, styleStr ); |
128 | if ( style < 0 ) | 133 | if ( style < 0 ) |
129 | style = findItemCB ( m_font_style_list, "Regular" ); | 134 | style = findItemCB ( m_font_style_list, "Regular" ); |
130 | if ( style < 0 && m_font_style_list-> count ( ) > 0 ) | 135 | if ( style < 0 && m_font_style_list-> count ( ) > 0 ) |
131 | style = 0; | 136 | style = 0; |
132 | m_font_style_list-> setCurrentItem ( style ); | 137 | m_font_style_list-> setCurrentItem ( style ); |
133 | fontStyleClicked ( style ); | 138 | fontStyleClicked ( style ); |
134 | 139 | ||
135 | int size = findItemCB ( m_font_size_list, sizeStr ); | 140 | int size = findItemCB ( m_font_size_list, sizeStr ); |
136 | if ( size < 0 ) | 141 | if ( size < 0 ) |
137 | size = findItemCB ( m_font_size_list, "10" ); | 142 | size = findItemCB ( m_font_size_list, "10" ); |
138 | if ( size < 0 && m_font_size_list-> count ( ) > 0 ) | 143 | if ( size < 0 && m_font_size_list-> count ( ) > 0 ) |
139 | size = 0; | 144 | size = 0; |
140 | m_font_size_list-> setCurrentItem ( size ); | 145 | m_font_size_list-> setCurrentItem ( size ); |
141 | fontSizeClicked ( size ); | 146 | fontSizeClicked ( size ); |
142 | 147 | ||
143 | return (( family ) && | 148 | return (( family ) && |
144 | ( style >= 0 ) && | 149 | ( style >= 0 ) && |
145 | ( size >= 0 )); | 150 | ( size >= 0 )); |
146 | } | 151 | } |
147 | 152 | ||
148 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) | 153 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) |
149 | { | 154 | { |
150 | QString dummy; | 155 | QString dummy; |
151 | return selectedFont ( family, style, size, dummy ); | 156 | return selectedFont ( family, style, size, dummy ); |
152 | } | 157 | } |
153 | 158 | ||
154 | 159 | ||
155 | QString OFontSelector::fontFamily ( ) const | 160 | QString OFontSelector::fontFamily ( ) const |
156 | { | 161 | { |
157 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); | 162 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); |
158 | 163 | ||
159 | return fli ? fli-> family ( ) : QString::null; | 164 | return fli ? fli-> family ( ) : QString::null; |
160 | } | 165 | } |
161 | 166 | ||
162 | QString OFontSelector::fontStyle ( ) const | 167 | QString OFontSelector::fontStyle ( ) const |
163 | { | 168 | { |
164 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); | 169 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); |
165 | int fst = m_font_style_list-> currentItem ( ); | 170 | int fst = m_font_style_list-> currentItem ( ); |
166 | 171 | ||
167 | return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null; | 172 | return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null; |
168 | } | 173 | } |
169 | 174 | ||
170 | int OFontSelector::fontSize ( ) const | 175 | int OFontSelector::fontSize ( ) const |
171 | { | 176 | { |
172 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); | 177 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); |
173 | int fsi = m_font_size_list-> currentItem ( ); | 178 | int fsi = m_font_size_list-> currentItem ( ); |
174 | 179 | ||
175 | return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10; | 180 | return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10; |
176 | } | 181 | } |
177 | 182 | ||
178 | QString OFontSelector::fontCharSet ( ) const | 183 | QString OFontSelector::fontCharSet ( ) const |
179 | { | 184 | { |
180 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); | 185 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); |
181 | 186 | ||
182 | return fli ? m_fdb. charSets ( fli-> family ( )) [0] : QString::null; | 187 | return fli ? m_fdb. charSets ( fli-> family ( )) [0] : QString::null; |
183 | } | 188 | } |
184 | 189 | ||
185 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) | 190 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) |
186 | { | 191 | { |
187 | int ffa = m_font_family_list-> currentItem ( ); | 192 | int ffa = m_font_family_list-> currentItem ( ); |
188 | int fst = m_font_style_list-> currentItem ( ); | 193 | int fst = m_font_style_list-> currentItem ( ); |
189 | int fsi = m_font_size_list-> currentItem ( ); | 194 | int fsi = m_font_size_list-> currentItem ( ); |
190 | 195 | ||
191 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa ); | 196 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa ); |
192 | 197 | ||
193 | if ( fli ) { | 198 | if ( fli ) { |
194 | family = fli-> family ( ); | 199 | family = fli-> family ( ); |
195 | style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null; | 200 | style = fst >= 0 ? fli-> styles ( ) [fst] : QString::null; |
196 | size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10; | 201 | size = fsi >= 0 ? fli-> sizes ( ) [fsi] : 10; |
197 | charset = m_fdb. charSets ( fli-> family ( )) [0]; | 202 | charset = m_fdb. charSets ( fli-> family ( )) [0]; |
198 | 203 | ||
199 | return true; | 204 | return true; |
200 | } | 205 | } |
201 | else | 206 | else |
202 | return false; | 207 | return false; |
203 | } | 208 | } |
204 | 209 | ||
205 | 210 | ||
206 | 211 | ||
207 | 212 | ||
208 | void OFontSelector::loadFonts ( QListBox *list ) | 213 | void OFontSelector::loadFonts ( QListBox *list ) |
209 | { | 214 | { |
210 | QStringList f = m_fdb. families ( ); | 215 | QStringList f = m_fdb. families ( ); |
211 | 216 | ||
212 | for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) | 217 | for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) |
213 | list-> insertItem ( new FontListItem ( *it, m_fdb. styles ( *it ), m_fdb. pointSizes ( *it ))); | 218 | list-> insertItem ( new FontListItem ( *it, m_fdb. styles ( *it ), m_fdb. pointSizes ( *it ))); |
214 | } | 219 | } |
215 | 220 | ||
216 | void OFontSelector::fontFamilyClicked ( int index ) | 221 | void OFontSelector::fontFamilyClicked ( int index ) |
217 | { | 222 | { |
218 | QString oldstyle = m_font_style_list-> currentText ( ); | 223 | QString oldstyle = m_font_style_list-> currentText ( ); |
219 | QString oldsize = m_font_size_list-> currentText ( ); | 224 | QString oldsize = m_font_size_list-> currentText ( ); |
220 | 225 | ||
221 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( index ); | 226 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( index ); |
222 | 227 | ||
223 | m_font_style_list-> clear ( ); | 228 | m_font_style_list-> clear ( ); |
224 | m_font_style_list-> insertStringList ( fli-> styles ( )); | 229 | m_font_style_list-> insertStringList ( fli-> styles ( )); |
225 | m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( )); | 230 | m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( )); |
226 | 231 | ||
227 | int i; | 232 | int i; |
228 | 233 | ||
229 | i = findItemCB ( m_font_style_list, oldstyle ); | 234 | i = findItemCB ( m_font_style_list, oldstyle ); |
230 | if ( i < 0 ) | 235 | if ( i < 0 ) |
231 | i = findItemCB ( m_font_style_list, "Regular" ); | 236 | i = findItemCB ( m_font_style_list, "Regular" ); |
232 | if (( i < 0 ) && ( m_font_style_list-> count ( ) > 0 )) | 237 | if (( i < 0 ) && ( m_font_style_list-> count ( ) > 0 )) |
233 | i = 0; | 238 | i = 0; |
234 | 239 | ||
235 | if ( i >= 0 ) { | 240 | if ( i >= 0 ) { |
236 | m_font_style_list-> setCurrentItem ( i ); | 241 | m_font_style_list-> setCurrentItem ( i ); |
237 | fontStyleClicked ( i ); | 242 | fontStyleClicked ( i ); |
238 | } | 243 | } |
239 | 244 | ||
240 | m_font_size_list-> clear ( ); | 245 | m_font_size_list-> clear ( ); |
241 | QValueList<int> sl = fli-> sizes ( ); | 246 | QValueList<int> sl = fli-> sizes ( ); |
242 | 247 | ||
243 | for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) | 248 | for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) |
244 | m_font_size_list-> insertItem ( QString::number ( *it )); | 249 | m_font_size_list-> insertItem ( QString::number ( *it )); |
245 | 250 | ||
246 | i = findItemCB ( m_font_size_list, oldsize ); | 251 | i = findItemCB ( m_font_size_list, oldsize ); |
247 | if ( i < 0 ) | 252 | if ( i < 0 ) |
248 | i = findItemCB ( m_font_size_list, "10" ); | 253 | i = findItemCB ( m_font_size_list, "10" ); |
249 | if (( i < 0 ) && ( m_font_size_list-> count ( ) > 0 )) | 254 | if (( i < 0 ) && ( m_font_size_list-> count ( ) > 0 )) |
250 | i = 0; | 255 | i = 0; |
251 | 256 | ||
252 | if ( i >= 0 ) { | 257 | if ( i >= 0 ) { |
253 | m_font_size_list-> setCurrentItem ( i ); | 258 | m_font_size_list-> setCurrentItem ( i ); |
254 | fontSizeClicked ( i ); | 259 | fontSizeClicked ( i ); |
255 | } | 260 | } |
256 | changeFont ( ); | 261 | changeFont ( ); |
257 | } | 262 | } |
258 | 263 | ||
259 | void OFontSelector::fontStyleClicked ( int /*index*/ ) | 264 | void OFontSelector::fontStyleClicked ( int /*index*/ ) |
260 | { | 265 | { |
261 | changeFont ( ); | 266 | changeFont ( ); |
262 | } | 267 | } |
263 | 268 | ||
264 | void OFontSelector::fontSizeClicked ( int /*index*/ ) | 269 | void OFontSelector::fontSizeClicked ( int /*index*/ ) |
265 | { | 270 | { |
266 | changeFont ( ); | 271 | changeFont ( ); |
267 | } | 272 | } |
268 | 273 | ||
269 | void OFontSelector::changeFont ( ) | 274 | void OFontSelector::changeFont ( ) |
270 | { | 275 | { |
271 | emit fontSelected ( selectedFont ( )); | 276 | emit fontSelected ( selectedFont ( )); |
272 | } | 277 | } |
273 | 278 | ||
274 | 279 | ||
275 | QFont OFontSelector::selectedFont ( ) | 280 | QFont OFontSelector::selectedFont ( ) |
276 | { | 281 | { |
277 | int ffa = m_font_family_list-> currentItem ( ); | 282 | int ffa = m_font_family_list-> currentItem ( ); |
278 | int fst = m_font_style_list-> currentItem ( ); | 283 | int fst = m_font_style_list-> currentItem ( ); |
279 | int fsi = m_font_size_list-> currentItem ( ); | 284 | int fsi = m_font_size_list-> currentItem ( ); |
280 | 285 | ||
281 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa ); | 286 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa ); |
282 | 287 | ||
283 | if ( fli ) { | 288 | if ( fli ) { |
284 | return m_fdb. font ( fli-> family ( ), \ | 289 | return m_fdb. font ( fli-> family ( ), \ |
285 | fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ | 290 | fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ |
286 | fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ | 291 | fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ |
287 | m_fdb. charSets ( fli-> family ( )) [0] ); | 292 | m_fdb. charSets ( fli-> family ( )) [0] ); |
288 | } | 293 | } |
289 | else | 294 | else |
290 | return QFont ( ); | 295 | return QFont ( ); |
291 | } | 296 | } |
292 | 297 | ||
293 | 298 | ||
294 | \ No newline at end of file | 299 | \ No newline at end of file |
diff --git a/libopie/ofontselector.h b/libopie/ofontselector.h index 2011e43..b3aa862 100644 --- a/libopie/ofontselector.h +++ b/libopie/ofontselector.h | |||
@@ -1,81 +1,82 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | 3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This library is free software; you can | 5 | _;:, .> :=|. This library is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This library is distributed in the hope that | 12 | .i_,=:_. -<s. This library is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
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 | #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 | #include <qpe/fontdatabase.h> | 33 | #include <qpe/fontdatabase.h> |
34 | 34 | ||
35 | class QComboBox; | 35 | class QComboBox; |
36 | class QListBox; | 36 | class QListBox; |
37 | class QFont; | 37 | class QFont; |
38 | 38 | ||
39 | class OFontSelector : public QWidget | 39 | class OFontSelector : public QWidget |
40 | { | 40 | { |
41 | Q_OBJECT | 41 | Q_OBJECT |
42 | 42 | ||
43 | public: | 43 | public: |
44 | OFontSelector ( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 44 | OFontSelector ( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
45 | virtual ~OFontSelector ( ); | 45 | virtual ~OFontSelector ( ); |
46 | 46 | ||
47 | bool selectedFont ( QString &family, QString &style, int &size ); | 47 | bool selectedFont ( QString &family, QString &style, int &size ); |
48 | bool selectedFont ( QString &family, QString &style, int &size, QString &charset ); | 48 | bool selectedFont ( QString &family, QString &style, int &size, QString &charset ); |
49 | 49 | ||
50 | QFont selectedFont ( ); | 50 | QFont selectedFont ( ); |
51 | 51 | ||
52 | bool setSelectedFont ( const QFont & ); | ||
52 | bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 ); | 53 | bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 ); |
53 | 54 | ||
54 | QString fontFamily ( ) const; | 55 | QString fontFamily ( ) const; |
55 | QString fontStyle ( ) const; | 56 | QString fontStyle ( ) const; |
56 | int fontSize ( ) const; | 57 | int fontSize ( ) const; |
57 | QString fontCharSet ( ) const; | 58 | QString fontCharSet ( ) const; |
58 | 59 | ||
59 | signals: | 60 | signals: |
60 | void fontSelected ( const QFont & ); | 61 | void fontSelected ( const QFont & ); |
61 | 62 | ||
62 | protected slots: | 63 | protected slots: |
63 | virtual void fontFamilyClicked ( int ); | 64 | virtual void fontFamilyClicked ( int ); |
64 | virtual void fontStyleClicked ( int ); | 65 | virtual void fontStyleClicked ( int ); |
65 | virtual void fontSizeClicked ( int ); | 66 | virtual void fontSizeClicked ( int ); |
66 | 67 | ||
67 | private: | 68 | private: |
68 | void loadFonts ( QListBox * ); | 69 | void loadFonts ( QListBox * ); |
69 | 70 | ||
70 | void changeFont ( ); | 71 | void changeFont ( ); |
71 | 72 | ||
72 | private: | 73 | private: |
73 | QListBox * m_font_family_list; | 74 | QListBox * m_font_family_list; |
74 | QComboBox * m_font_style_list; | 75 | QComboBox * m_font_style_list; |
75 | QComboBox * m_font_size_list; | 76 | QComboBox * m_font_size_list; |
76 | 77 | ||
77 | FontDatabase m_fdb; | 78 | FontDatabase m_fdb; |
78 | }; | 79 | }; |
79 | 80 | ||
80 | #endif | 81 | #endif |
81 | 82 | ||