summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/libopie.pro4
-rw-r--r--libopie/ocolorbutton.cpp118
-rw-r--r--libopie/ocolorbutton.h59
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
@@ -9,7 +9,7 @@ HEADERS = ofontmenu.h ofileselector.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
13SOURCES = ofontmenu.cc ofileselector.cc \ 13SOURCES = ofontmenu.cc ofileselector.cc \
14 ofiledialog.cc xmltree.cc \ 14 ofiledialog.cc xmltree.cc \
15 tododb.cpp todoevent.cpp \ 15 tododb.cpp todoevent.cpp \
@@ -18,7 +18,7 @@ SOURCES = ofontmenu.cc ofileselector.cc \
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
22TARGET = opie 22TARGET = opie
23INCLUDEPATH += $(OPIEDIR)/include 23INCLUDEPATH += $(OPIEDIR)/include
24DESTDIR = $(QTDIR)/lib$(PROJMAK) 24DESTDIR = $(QTDIR)/lib$(PROJMAK)
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
37class OColorButtonPrivate {
38public:
39 QPopupMenu *m_menu;
40 QColor m_color;
41};
42
43OColorButton::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
57OColorButton::~OColorButton ( )
58{
59 delete d;
60}
61
62QColor OColorButton::color ( ) const
63{
64 return d-> m_color;
65}
66
67void OColorButton::setColor ( const QColor &c )
68{
69 updateColor ( c );
70}
71
72void 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
34class OColorButtonPrivate;
35class QColor;
36
37class OColorButton : public QPushButton {
38 Q_OBJECT
39public:
40 OColorButton ( QWidget *parent = 0, const char *name = 0 );
41 virtual ~OColorButton ( );
42
43 QColor color ( ) const;
44
45signals:
46 void colorSelected ( const QColor & );
47
48public slots:
49 virtual void setColor ( const QColor & );
50
51 protected slots:
52 virtual void updateColor ( const QColor & );
53
54private:
55 OColorButtonPrivate *d;
56 };
57
58#endif
59