-rw-r--r-- | libopie/ocolorbutton.cpp | 20 | ||||
-rw-r--r-- | libopie/ocolorbutton.h | 14 |
2 files changed, 17 insertions, 17 deletions
diff --git a/libopie/ocolorbutton.cpp b/libopie/ocolorbutton.cpp index 4734c0c..ddb6c4f 100644 --- a/libopie/ocolorbutton.cpp +++ b/libopie/ocolorbutton.cpp | |||
@@ -1,105 +1,105 @@ | |||
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 QColor &color, 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 ( color, 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 ( color ); |
54 | 54 | ||
55 | QSize s = sizeHint ( ) + QSize ( 12, 0 ); | 55 | QSize s = sizeHint ( ) + QSize ( 12, 0 ); |
56 | setMinimumSize ( s ); | 56 | setMinimumSize ( s ); |
57 | setMaximumSize ( s. width ( ) * 2, s. height ( )); | 57 | setMaximumSize ( s. width ( ) * 2, s. height ( )); |
58 | } | 58 | } |
59 | 59 | ||
60 | OColorButton::~OColorButton ( ) | 60 | OColorButton::~OColorButton ( ) |
61 | { | 61 | { |
62 | delete d; | 62 | delete d; |
63 | } | 63 | } |
64 | 64 | ||
65 | QColor OColorButton::color ( ) const | 65 | QColor OColorButton::color ( ) const |
66 | { | 66 | { |
67 | return d-> m_color; | 67 | return d-> m_color; |
68 | } | 68 | } |
69 | 69 | ||
70 | void OColorButton::setColor ( const QColor &c ) | 70 | void OColorButton::setColor ( const QColor &c ) |
71 | { | 71 | { |
72 | updateColor ( c ); | 72 | updateColor ( c ); |
73 | } | 73 | } |
74 | 74 | ||
75 | void OColorButton::updateColor ( const QColor &c ) | 75 | void OColorButton::updateColor ( const QColor &c ) |
76 | { | 76 | { |
77 | d-> m_color = c; | 77 | d-> m_color = c; |
78 | 78 | ||
79 | QImage img ( 16, 16, 32 ); | 79 | QImage img ( 16, 16, 32 ); |
80 | img. fill ( 0 ); | 80 | img. fill ( 0 ); |
81 | 81 | ||
82 | int r, g, b; | 82 | int r, g, b; |
83 | c. rgb ( &r, &g, &b ); | 83 | c. rgb ( &r, &g, &b ); |
84 | 84 | ||
85 | int w = img. width ( ); | 85 | int w = img. width ( ); |
86 | int h = img. height ( ); | 86 | int h = img. height ( ); |
87 | 87 | ||
88 | int dx = w * 20 / 100; // 15% | 88 | int dx = w * 20 / 100; // 15% |
89 | int dy = h * 20 / 100; | 89 | int dy = h * 20 / 100; |
90 | 90 | ||
91 | for ( int y = 0; y < h; y++ ) { | 91 | for ( int y = 0; y < h; y++ ) { |
92 | for ( int x = 0; x < w; x++ ) { | 92 | for ( int x = 0; x < w; x++ ) { |
93 | double alpha = 1.0; | 93 | double alpha = 1.0; |
94 | 94 | ||
95 | if ( x < dx ) | 95 | if ( x < dx ) |
96 | alpha *= ( double ( x + 1 ) / dx ); | 96 | alpha *= ( double ( x + 1 ) / dx ); |
97 | else if ( x >= w - dx ) | 97 | else if ( x >= w - dx ) |
98 | alpha *= ( double ( w - x ) / dx ); | 98 | alpha *= ( double ( w - x ) / dx ); |
99 | if ( y < dy ) | 99 | if ( y < dy ) |
100 | alpha *= ( double ( y + 1 ) / dy ); | 100 | alpha *= ( double ( y + 1 ) / dy ); |
101 | else if ( y >= h - dy ) | 101 | else if ( y >= h - dy ) |
102 | alpha *= ( double ( h - y ) / dy ); | 102 | alpha *= ( double ( h - y ) / dy ); |
103 | 103 | ||
104 | int a = int ( alpha * 255.0 ); | 104 | int a = int ( alpha * 255.0 ); |
105 | if ( a < 0 ) | 105 | if ( a < 0 ) |
diff --git a/libopie/ocolorbutton.h b/libopie/ocolorbutton.h index ec04833..fe40fae 100644 --- a/libopie/ocolorbutton.h +++ b/libopie/ocolorbutton.h | |||
@@ -1,59 +1,59 @@ | |||
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_OCOLORBUTTON_H__ | 29 | #ifndef __OPIE_OCOLORBUTTON_H__ |
30 | #define __OPIE_OCOLORBUTTON_H__ | 30 | #define __OPIE_OCOLORBUTTON_H__ |
31 | 31 | ||
32 | #include <qpushbutton.h> | 32 | #include <qpushbutton.h> |
33 | 33 | ||
34 | class OColorButtonPrivate; | 34 | class OColorButtonPrivate; |
35 | class QColor; | 35 | class QColor; |
36 | 36 | ||
37 | class OColorButton : public QPushButton { | 37 | class OColorButton : public QPushButton { |
38 | Q_OBJECT | 38 | Q_OBJECT |
39 | public: | 39 | public: |
40 | OColorButton ( QWidget *parent = 0, const char *name = 0 ); | 40 | OColorButton ( QWidget *parent = 0, const QColor & = black, const char *name = 0 ); |
41 | virtual ~OColorButton ( ); | 41 | virtual ~OColorButton ( ); |
42 | 42 | ||
43 | QColor color ( ) const; | 43 | QColor color ( ) const; |
44 | 44 | ||
45 | signals: | 45 | signals: |
46 | void colorSelected ( const QColor & ); | 46 | void colorSelected ( const QColor & ); |
47 | 47 | ||
48 | public slots: | 48 | public slots: |
49 | virtual void setColor ( const QColor & ); | 49 | virtual void setColor ( const QColor & ); |
50 | 50 | ||
51 | protected slots: | 51 | protected slots: |
52 | virtual void updateColor ( const QColor & ); | 52 | virtual void updateColor ( const QColor & ); |
53 | 53 | ||
54 | private: | 54 | private: |
55 | OColorButtonPrivate *d; | 55 | OColorButtonPrivate *d; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | #endif | 58 | #endif |
59 | 59 | ||