author | sandman <sandman> | 2002-09-24 23:41:04 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-09-24 23:41:04 (UTC) |
commit | 3e0fcd45ea0e177deccd5463b2a754d442c03061 (patch) (unidiff) | |
tree | 40a3e7050907ed082e71e6701849404f3c2ab6a6 /libopie | |
parent | 6398fb2352fd4b53a023ec2884b786b08af8bd9f (diff) | |
download | opie-3e0fcd45ea0e177deccd5463b2a754d442c03061.zip opie-3e0fcd45ea0e177deccd5463b2a754d442c03061.tar.gz opie-3e0fcd45ea0e177deccd5463b2a754d442c03061.tar.bz2 |
button with popup-menu for color selections -- this should be used instead
of the QToolButton + ColorPopupMenu construct
-rw-r--r-- | libopie/libopie.pro | 4 | ||||
-rw-r--r-- | libopie/ocolorbutton.cpp | 118 | ||||
-rw-r--r-- | libopie/ocolorbutton.h | 59 |
3 files changed, 179 insertions, 2 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro index 4b176d0..6a1f1b3 100644 --- a/libopie/libopie.pro +++ b/libopie/libopie.pro | |||
@@ -6,22 +6,22 @@ HEADERS = ofontmenu.h ofileselector.h \ | |||
6 | todovcalresource.h xmltree.h \ | 6 | todovcalresource.h xmltree.h \ |
7 | colordialog.h colorpopupmenu.h \ | 7 | colordialog.h colorpopupmenu.h \ |
8 | oclickablelabel.h oprocctrl.h \ | 8 | oclickablelabel.h oprocctrl.h \ |
9 | oprocess.h odevice.h \ | 9 | oprocess.h odevice.h \ |
10 | otimepicker.h otabwidget.h \ | 10 | otimepicker.h otabwidget.h \ |
11 | otabbar.h otabinfo.h \ | 11 | otabbar.h otabinfo.h \ |
12 | ofontselector.h | 12 | ofontselector.h ocolorbutton.h |
13 | SOURCES = ofontmenu.cc ofileselector.cc \ | 13 | SOURCES = ofontmenu.cc ofileselector.cc \ |
14 | ofiledialog.cc xmltree.cc \ | 14 | ofiledialog.cc xmltree.cc \ |
15 | tododb.cpp todoevent.cpp \ | 15 | tododb.cpp todoevent.cpp \ |
16 | todovcalresource.cpp colordialog.cpp \ | 16 | todovcalresource.cpp colordialog.cpp \ |
17 | colorpopupmenu.cpp oclickablelabel.cpp \ | 17 | colorpopupmenu.cpp oclickablelabel.cpp \ |
18 | oprocctrl.cpp oprocess.cpp \ | 18 | oprocctrl.cpp oprocess.cpp \ |
19 | odevice.cpp otimepicker.cpp \ | 19 | odevice.cpp otimepicker.cpp \ |
20 | otabwidget.cpp otabbar.cpp \ | 20 | otabwidget.cpp otabbar.cpp \ |
21 | ofontselector.cpp | 21 | ofontselector.cpp ocolorbutton.cpp |
22 | TARGET = opie | 22 | TARGET = opie |
23 | INCLUDEPATH += $(OPIEDIR)/include | 23 | INCLUDEPATH += $(OPIEDIR)/include |
24 | DESTDIR = $(QTDIR)/lib$(PROJMAK) | 24 | DESTDIR = $(QTDIR)/lib$(PROJMAK) |
25 | #VERSION = 1.0.0 | 25 | #VERSION = 1.0.0 |
26 | 26 | ||
27 | INTERFACES = otimepickerbase.ui | 27 | INTERFACES = otimepickerbase.ui |
diff --git a/libopie/ocolorbutton.cpp b/libopie/ocolorbutton.cpp new file mode 100644 index 0000000..96e5612 --- a/dev/null +++ b/libopie/ocolorbutton.cpp | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | ||
4 | .>+-= | ||
5 | _;:, .> :=|. This library is free software; you can | ||
6 | .> <`_, > . <= redistribute it and/or modify it under | ||
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This library is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
17 | ..}^=.= = ; Library General Public License for more | ||
18 | ++= -. .` .: details. | ||
19 | : = ...= . :.=- | ||
20 | -. .:....=;==+<; You should have received a copy of the GNU | ||
21 | -_. . . )=. = Library General Public License along with | ||
22 | -- :-=` this library; see the file COPYING.LIB. | ||
23 | If not, write to the Free Software Foundation, | ||
24 | Inc., 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include <opie/colorpopupmenu.h> | ||
30 | #include <opie/ocolorbutton.h> | ||
31 | #include <qcolor.h> | ||
32 | #include <qpixmap.h> | ||
33 | #include <qimage.h> | ||
34 | |||
35 | #include <qpe/resource.h> | ||
36 | |||
37 | class OColorButtonPrivate { | ||
38 | public: | ||
39 | QPopupMenu *m_menu; | ||
40 | QColor m_color; | ||
41 | }; | ||
42 | |||
43 | OColorButton::OColorButton ( QWidget *parent, const char *name ) | ||
44 | : QPushButton ( parent, name ) | ||
45 | { | ||
46 | d = new OColorButtonPrivate; | ||
47 | |||
48 | d-> m_menu = new ColorPopupMenu ( black, 0, 0 ); | ||
49 | setPopup ( d-> m_menu ); | ||
50 | //setPopupDelay ( 0 ); | ||
51 | connect ( d-> m_menu, SIGNAL( colorSelected ( const QColor & )), this, SLOT( updateColor ( const QColor & ))); | ||
52 | |||
53 | updateColor ( black ); | ||
54 | setMinimumSize ( sizeHint ( ) + QSize ( 8, 0 )); | ||
55 | } | ||
56 | |||
57 | OColorButton::~OColorButton ( ) | ||
58 | { | ||
59 | delete d; | ||
60 | } | ||
61 | |||
62 | QColor OColorButton::color ( ) const | ||
63 | { | ||
64 | return d-> m_color; | ||
65 | } | ||
66 | |||
67 | void OColorButton::setColor ( const QColor &c ) | ||
68 | { | ||
69 | updateColor ( c ); | ||
70 | } | ||
71 | |||
72 | void OColorButton::updateColor ( const QColor &c ) | ||
73 | { | ||
74 | d-> m_color = c; | ||
75 | |||
76 | QImage img ( 16, 16, 32 ); | ||
77 | img. fill ( 0 ); | ||
78 | |||
79 | int r, g, b; | ||
80 | c. rgb ( &r, &g, &b ); | ||
81 | |||
82 | int w = img. width ( ); | ||
83 | int h = img. height ( ); | ||
84 | |||
85 | int dx = w * 20 / 100; // 15% | ||
86 | int dy = h * 20 / 100; | ||
87 | |||
88 | for ( int y = 0; y < h; y++ ) { | ||
89 | for ( int x = 0; x < w; x++ ) { | ||
90 | double alpha = 1.0; | ||
91 | |||
92 | if ( x < dx ) | ||
93 | alpha *= ( double ( x + 1 ) / dx ); | ||
94 | else if ( x >= w - dx ) | ||
95 | alpha *= ( double ( w - x ) / dx ); | ||
96 | if ( y < dy ) | ||
97 | alpha *= ( double ( y + 1 ) / dy ); | ||
98 | else if ( y >= h - dy ) | ||
99 | alpha *= ( double ( h - y ) / dy ); | ||
100 | |||
101 | int a = int ( alpha * 255.0 ); | ||
102 | if ( a < 0 ) | ||
103 | a = 0; | ||
104 | if ( a > 255 ) | ||
105 | a = 255; | ||
106 | |||
107 | img. setPixel ( x, y, qRgba ( r, g, b, a )); | ||
108 | } | ||
109 | } | ||
110 | img. setAlphaBuffer ( true ); | ||
111 | |||
112 | QPixmap pix; | ||
113 | pix. convertFromImage ( img ); | ||
114 | setPixmap ( pix ); | ||
115 | |||
116 | emit colorSelected ( c ); | ||
117 | } | ||
118 | |||
diff --git a/libopie/ocolorbutton.h b/libopie/ocolorbutton.h new file mode 100644 index 0000000..ec04833 --- a/dev/null +++ b/libopie/ocolorbutton.h | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | ||
4 | .>+-= | ||
5 | _;:, .> :=|. This library is free software; you can | ||
6 | .> <`_, > . <= redistribute it and/or modify it under | ||
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This library is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
17 | ..}^=.= = ; Library General Public License for more | ||
18 | ++= -. .` .: details. | ||
19 | : = ...= . :.=- | ||
20 | -. .:....=;==+<; You should have received a copy of the GNU | ||
21 | -_. . . )=. = Library General Public License along with | ||
22 | -- :-=` this library; see the file COPYING.LIB. | ||
23 | If not, write to the Free Software Foundation, | ||
24 | Inc., 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #ifndef __OPIE_OCOLORBUTTON_H__ | ||
30 | #define __OPIE_OCOLORBUTTON_H__ | ||
31 | |||
32 | #include <qpushbutton.h> | ||
33 | |||
34 | class OColorButtonPrivate; | ||
35 | class QColor; | ||
36 | |||
37 | class OColorButton : public QPushButton { | ||
38 | Q_OBJECT | ||
39 | public: | ||
40 | OColorButton ( QWidget *parent = 0, const char *name = 0 ); | ||
41 | virtual ~OColorButton ( ); | ||
42 | |||
43 | QColor color ( ) const; | ||
44 | |||
45 | signals: | ||
46 | void colorSelected ( const QColor & ); | ||
47 | |||
48 | public slots: | ||
49 | virtual void setColor ( const QColor & ); | ||
50 | |||
51 | protected slots: | ||
52 | virtual void updateColor ( const QColor & ); | ||
53 | |||
54 | private: | ||
55 | OColorButtonPrivate *d; | ||
56 | }; | ||
57 | |||
58 | #endif | ||
59 | |||