summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libqtaux/ocolorbutton.cpp50
-rw-r--r--libqtaux/ocolorbutton.h44
2 files changed, 51 insertions, 43 deletions
diff --git a/libqtaux/ocolorbutton.cpp b/libqtaux/ocolorbutton.cpp
index 004fafc..2a87be9 100644
--- a/libqtaux/ocolorbutton.cpp
+++ b/libqtaux/ocolorbutton.cpp
@@ -1,156 +1,162 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Robert Griebl <sandman@handhelds.org> 3 Copyright (C) Robert Griebl <sandman@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6           .>+-= 6 .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7_;:, .> :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11- . .-<_> .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13    .%`+i>       _;_. 13 .%`+i> _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++=   -.     .`     .: details. 20++= -. .` .: details.
21 :     =  ...= . :.=- 21: = ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22-. .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "ocolorpopupmenu.h" 30#include "ocolorpopupmenu.h"
31#include "ocolorbutton.h" 31#include "ocolorbutton.h"
32 32
33/* OPIE */ 33/* OPIE */
34 34
35/* QT */ 35/* QT */
36#include <qimage.h> 36#include <qimage.h>
37 37
38using namespace Opie; 38using namespace Opie;
39 39
40struct OColorButtonPrivate 40struct OColorButtonPrivate
41{ 41{
42 QPopupMenu *m_menu; 42 QPopupMenu *m_menu;
43 QColor m_color; 43 QColor m_color;
44}; 44};
45 45
46/** 46/**
47 * This concstructs a Color Button with @param color as the start color 47 * This concstructs a Color Button with @param color as the start color
48 * It'll use a OColorPopupMenu internally 48 * It'll use a OColorPopupMenu internally
49 * 49 *
50 * @param parent The parent of the Color Button 50 * @param parent The parent of the Color Button
51 * @param color The color from where to start on 51 * @param color The color from where to start on
52 * @param name @see QObject 52 * @param name @see QObject
53 */ 53 */
54OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *name ) 54OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *name )
55 : QPushButton ( parent, name ) 55 : QPushButton ( parent, name )
56{ 56{
57 d = new OColorButtonPrivate; 57 d = new OColorButtonPrivate;
58 58
59 d-> m_menu = new OColorPopupMenu ( color, 0, 0 ); 59 d-> m_menu = new OColorPopupMenu ( color, 0, 0 );
60 setPopup ( d-> m_menu ); 60 setPopup ( d-> m_menu );
61 //setPopupDelay ( 0 ); 61 //setPopupDelay ( 0 );
62 connect ( d-> m_menu, SIGNAL( colorSelected(const QColor&)), this, SLOT( updateColor(const QColor&))); 62 connect ( d-> m_menu, SIGNAL( colorSelected(const QColor&)), this, SLOT( updateColor(const QColor&)));
63 63
64 64
65 QSize s = sizeHint ( ) + QSize ( 12, 0 ); 65 QSize s = sizeHint ( ) + QSize ( 12, 0 );
66 setMinimumSize ( s ); 66 setMinimumSize ( s );
67 setMaximumSize ( s. width ( ) * 2, s. height ( )); 67 setMaximumSize ( s. width ( ) * 2, s. height ( ));
68 d->m_color = color; 68 d->m_color = color;
69} 69}
70 70
71/** 71/**
72 * This destructs the object 72 * This destructs the object
73 */ 73 */
74OColorButton::~OColorButton ( ) 74OColorButton::~OColorButton ( )
75{ 75{
76 delete d->m_menu; 76 delete d->m_menu;
77 delete d; 77 delete d;
78} 78}
79 79
80/** 80/**
81 * @return Returns the current color of the button 81 * @return Returns the current color of the button
82 */ 82 */
83QColor OColorButton::color ( ) const 83QColor OColorButton::color ( ) const
84{ 84{
85 return d-> m_color; 85 return d-> m_color;
86} 86}
87 87
88/** 88/**
89 * This method sets the color of the button 89 * This method sets the color of the button
90 * @param c The color to be set. 90 * @param c The color to be set.
91 */ 91 */
92void OColorButton::setColor ( const QColor &c ) 92void OColorButton::setColor ( const QColor &c )
93{ 93{
94 updateColor ( c ); 94 updateColor ( c, true );
95} 95}
96 96
97/** 97/**
98 * @internal 98 * @internal
99 */ 99 */
100void OColorButton::updateColor ( const QColor &c ) 100void OColorButton::updateColor ( const QColor &c )
101{ 101{
102 updateColor( c, true );
103}
104
105void OColorButton::updateColor ( const QColor &c, bool sendSignal )
106{
102 d-> m_color = c; 107 d-> m_color = c;
103 108
104 QImage img ( width()-14, height()-6, 32 ); 109 QImage img ( width()-14, height()-6, 32 );
105 img. fill ( 0 ); 110 img. fill ( 0 );
106 111
107 int r, g, b; 112 int r, g, b;
108 c. rgb ( &r, &g, &b ); 113 c. rgb ( &r, &g, &b );
109 114
110 int w = img. width ( ); 115 int w = img. width ( );
111 int h = img. height ( ); 116 int h = img. height ( );
112 117
113 int dx = w * 20 / 100; // 15% 118 int dx = w * 20 / 100; // 15%
114 int dy = h * 20 / 100; 119 int dy = h * 20 / 100;
115 120
116 for ( int y = 0; y < h; y++ ) 121 for ( int y = 0; y < h; y++ )
117 { 122 {
118 for ( int x = 0; x < w; x++ ) 123 for ( int x = 0; x < w; x++ )
119 { 124 {
120 double alpha = 1.0; 125 double alpha = 1.0;
121 126
122 if ( x < dx ) 127 if ( x < dx )
123 alpha *= ( double ( x + 1 ) / dx ); 128 alpha *= ( double ( x + 1 ) / dx );
124 else if ( x >= w - dx ) 129 else if ( x >= w - dx )
125 alpha *= ( double ( w - x ) / dx ); 130 alpha *= ( double ( w - x ) / dx );
126 if ( y < dy ) 131 if ( y < dy )
127 alpha *= ( double ( y + 1 ) / dy ); 132 alpha *= ( double ( y + 1 ) / dy );
128 else if ( y >= h - dy ) 133 else if ( y >= h - dy )
129 alpha *= ( double ( h - y ) / dy ); 134 alpha *= ( double ( h - y ) / dy );
130 135
131 int a = int ( alpha * 255.0 ); 136 int a = int ( alpha * 255.0 );
132 if ( a < 0 ) 137 if ( a < 0 )
133 a = 0; 138 a = 0;
134 if ( a > 255 ) 139 if ( a > 255 )
135 a = 255; 140 a = 255;
136 141
137 img. setPixel ( x, y, qRgba ( r, g, b, a )); 142 img. setPixel ( x, y, qRgba ( r, g, b, a ));
138 } 143 }
139 } 144 }
140 img. setAlphaBuffer ( true ); 145 img. setAlphaBuffer ( true );
141 146
142 QPixmap pix; 147 QPixmap pix;
143 pix. convertFromImage ( img ); 148 pix. convertFromImage ( img );
144 setPixmap ( pix ); 149 setPixmap ( pix );
145 150
146 emit colorSelected ( c ); 151 if ( sendSignal )
152 emit colorSelected ( c );
147} 153}
148 154
149 155
150/** 156/**
151 * @internal 157 * @internal
152 */ 158 */
153void OColorButton::resizeEvent( QResizeEvent *ev ) { 159void OColorButton::resizeEvent( QResizeEvent *ev ) {
154 QPushButton::resizeEvent( ev ); 160 QPushButton::resizeEvent( ev );
155 updateColor(d->m_color); 161 updateColor( d->m_color, false );
156} 162}
diff --git a/libqtaux/ocolorbutton.h b/libqtaux/ocolorbutton.h
index 10b77d5..4845c0d 100644
--- a/libqtaux/ocolorbutton.h
+++ b/libqtaux/ocolorbutton.h
@@ -1,83 +1,85 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Robert Griebl <sandman@handhelds.org> 3 Copyright (C) Robert Griebl <sandman@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6           .>+-= 6 .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7_;:, .> :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11- . .-<_> .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13    .%`+i>       _;_. 13 .%`+i> _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++=   -.     .`     .: details. 20++= -. .` .: details.
21 :     =  ...= . :.=- 21: = ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22-. .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#ifndef OCOLORBUTTON_H 30#ifndef OCOLORBUTTON_H
31#define OCOLORBUTTON_H 31#define OCOLORBUTTON_H
32 32
33/* QT*/ 33/* QT*/
34#include <qpushbutton.h> 34#include <qpushbutton.h>
35 35
36class OColorButtonPrivate; 36class OColorButtonPrivate;
37class QColor; 37class QColor;
38 38
39namespace Opie 39namespace Opie
40{ 40{
41 41
42/** 42/**
43 * 43 *
44 * @short A Button which will show a OColorPopupMenu 44 * @short A Button which will show a OColorPopupMenu
45 * @author Robert Griebl ( sandman@handhelds.org ) 45 * @author Robert Griebl ( sandman@handhelds.org )
46 * @version 1.0 46 * @version 1.0
47 * @see QPushButton 47 * @see QPushButton
48 */ 48 */
49class OColorButton : public QPushButton 49class OColorButton : public QPushButton
50{ 50{
51 Q_OBJECT 51 Q_OBJECT
52public: 52public:
53 OColorButton ( QWidget *parent = 0, const QColor & = black, const char *name = 0 ); 53 OColorButton ( QWidget *parent = 0, const QColor & = black, const char *name = 0 );
54 virtual ~OColorButton ( ); 54 virtual ~OColorButton ( );
55 55
56 QColor color ( ) const; 56 QColor color ( ) const;
57 57
58protected: 58protected:
59 void resizeEvent( QResizeEvent* ); 59 void resizeEvent( QResizeEvent* );
60 60
61signals: 61signals:
62 /** 62 /**
63 * emitted when a color gets selected 63 * emitted when a color gets selected
64 */ 64 */
65 void colorSelected ( const QColor & ); 65 void colorSelected ( const QColor & );
66 66
67public slots: 67public slots:
68 virtual void setColor ( const QColor & ); 68 virtual void setColor ( const QColor & );
69 69
70protected slots: 70protected slots:
71 /** 71 /**
72 * @internal 72 * @internal
73 */ 73 */
74 virtual void updateColor ( const QColor & ); 74 virtual void updateColor ( const QColor & );
75 75
76private: 76private:
77 OColorButtonPrivate *d; 77 OColorButtonPrivate *d;
78
79 void updateColor ( const QColor &, bool sendSignal = true );
78}; 80};
79 81
80}; 82};
81 83
82#endif 84#endif
83 85