summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libqtaux/ocolorbutton.cpp12
-rw-r--r--libqtaux/ocolorbutton.h3
2 files changed, 13 insertions, 2 deletions
diff --git a/libqtaux/ocolorbutton.cpp b/libqtaux/ocolorbutton.cpp
index 9e41d93..925df7f 100644
--- a/libqtaux/ocolorbutton.cpp
+++ b/libqtaux/ocolorbutton.cpp
@@ -40,108 +40,116 @@ using namespace Opie;
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 updateColor ( color );
65 64
66 QSize s = sizeHint ( ) + QSize ( 12, 0 ); 65 QSize s = sizeHint ( ) + QSize ( 12, 0 );
67 setMinimumSize ( s ); 66 setMinimumSize ( s );
68 setMaximumSize ( s. width ( ) * 2, s. height ( )); 67 setMaximumSize ( s. width ( ) * 2, s. height ( ));
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; 76 delete d;
77} 77}
78 78
79/** 79/**
80 * @return Returns the current color of the button 80 * @return Returns the current color of the button
81 */ 81 */
82QColor OColorButton::color ( ) const 82QColor OColorButton::color ( ) const
83{ 83{
84 return d-> m_color; 84 return d-> m_color;
85} 85}
86 86
87/** 87/**
88 * This method sets the color of the button 88 * This method sets the color of the button
89 * @param c The color to be set. 89 * @param c The color to be set.
90 */ 90 */
91void OColorButton::setColor ( const QColor &c ) 91void OColorButton::setColor ( const QColor &c )
92{ 92{
93 updateColor ( c ); 93 updateColor ( c );
94} 94}
95 95
96/** 96/**
97 * @internal 97 * @internal
98 */ 98 */
99void OColorButton::updateColor ( const QColor &c ) 99void OColorButton::updateColor ( const QColor &c )
100{ 100{
101 d-> m_color = c; 101 d-> m_color = c;
102 102
103 QImage img ( 16, 16, 32 ); 103 QImage img ( width()-14, height()-6, 32 );
104 img. fill ( 0 ); 104 img. fill ( 0 );
105 105
106 int r, g, b; 106 int r, g, b;
107 c. rgb ( &r, &g, &b ); 107 c. rgb ( &r, &g, &b );
108 108
109 int w = img. width ( ); 109 int w = img. width ( );
110 int h = img. height ( ); 110 int h = img. height ( );
111 111
112 int dx = w * 20 / 100; // 15% 112 int dx = w * 20 / 100; // 15%
113 int dy = h * 20 / 100; 113 int dy = h * 20 / 100;
114 114
115 for ( int y = 0; y < h; y++ ) 115 for ( int y = 0; y < h; y++ )
116 { 116 {
117 for ( int x = 0; x < w; x++ ) 117 for ( int x = 0; x < w; x++ )
118 { 118 {
119 double alpha = 1.0; 119 double alpha = 1.0;
120 120
121 if ( x < dx ) 121 if ( x < dx )
122 alpha *= ( double ( x + 1 ) / dx ); 122 alpha *= ( double ( x + 1 ) / dx );
123 else if ( x >= w - dx ) 123 else if ( x >= w - dx )
124 alpha *= ( double ( w - x ) / dx ); 124 alpha *= ( double ( w - x ) / dx );
125 if ( y < dy ) 125 if ( y < dy )
126 alpha *= ( double ( y + 1 ) / dy ); 126 alpha *= ( double ( y + 1 ) / dy );
127 else if ( y >= h - dy ) 127 else if ( y >= h - dy )
128 alpha *= ( double ( h - y ) / dy ); 128 alpha *= ( double ( h - y ) / dy );
129 129
130 int a = int ( alpha * 255.0 ); 130 int a = int ( alpha * 255.0 );
131 if ( a < 0 ) 131 if ( a < 0 )
132 a = 0; 132 a = 0;
133 if ( a > 255 ) 133 if ( a > 255 )
134 a = 255; 134 a = 255;
135 135
136 img. setPixel ( x, y, qRgba ( r, g, b, a )); 136 img. setPixel ( x, y, qRgba ( r, g, b, a ));
137 } 137 }
138 } 138 }
139 img. setAlphaBuffer ( true ); 139 img. setAlphaBuffer ( true );
140 140
141 QPixmap pix; 141 QPixmap pix;
142 pix. convertFromImage ( img ); 142 pix. convertFromImage ( img );
143 setPixmap ( pix ); 143 setPixmap ( pix );
144 144
145 emit colorSelected ( c ); 145 emit colorSelected ( c );
146} 146}
147 147
148
149/**
150 * @internal
151 */
152void OColorButton::resizeEvent( QResizeEvent *ev ) {
153 QPushButton::resizeEvent( ev );
154 updateColor(d->m_color);
155}
diff --git a/libqtaux/ocolorbutton.h b/libqtaux/ocolorbutton.h
index ca68f1f..10b77d5 100644
--- a/libqtaux/ocolorbutton.h
+++ b/libqtaux/ocolorbutton.h
@@ -33,48 +33,51 @@
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
58protected:
59 void resizeEvent( QResizeEvent* );
57 60
58signals: 61signals:
59 /** 62 /**
60 * emitted when a color gets selected 63 * emitted when a color gets selected
61 */ 64 */
62 void colorSelected ( const QColor & ); 65 void colorSelected ( const QColor & );
63 66
64public slots: 67public slots:
65 virtual void setColor ( const QColor & ); 68 virtual void setColor ( const QColor & );
66 69
67protected slots: 70protected slots:
68 /** 71 /**
69 * @internal 72 * @internal
70 */ 73 */
71 virtual void updateColor ( const QColor & ); 74 virtual void updateColor ( const QColor & );
72 75
73private: 76private:
74 OColorButtonPrivate *d; 77 OColorButtonPrivate *d;
75}; 78};
76 79
77}; 80};
78 81
79#endif 82#endif
80 83