summaryrefslogtreecommitdiff
path: root/libopie/ocolorbutton.cpp
authorzecke <zecke>2003-04-13 16:57:28 (UTC)
committer zecke <zecke>2003-04-13 16:57:28 (UTC)
commit0b311079ff19798866291034663757103c6ba935 (patch) (unidiff)
tree70ddccf3a3147475050fa06cc2d807a71ab1d5ee /libopie/ocolorbutton.cpp
parent1537ccb435ca725c793db6e94e0b9e83484b57e7 (diff)
downloadopie-0b311079ff19798866291034663757103c6ba935.zip
opie-0b311079ff19798866291034663757103c6ba935.tar.gz
opie-0b311079ff19798866291034663757103c6ba935.tar.bz2
Jumbo API documentation update
and some API fixed ColorDialog is now OColorDialog!!! keep the namespace tidy! ColorPopupMenu is now OColorPopupMenu!!! keep the namespace tidy ColorDialog TT couldn't break bc we can so make it const QColor& OTimePicker add some convience methods more I might have forgot
Diffstat (limited to 'libopie/ocolorbutton.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ocolorbutton.cpp45
1 files changed, 33 insertions, 12 deletions
diff --git a/libopie/ocolorbutton.cpp b/libopie/ocolorbutton.cpp
index ddb6c4f..113a77a 100644
--- a/libopie/ocolorbutton.cpp
+++ b/libopie/ocolorbutton.cpp
@@ -34,18 +34,26 @@
34 34
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36 36
37class OColorButtonPrivate { 37struct OColorButtonPrivate {
38public: 38 QPopupMenu *m_menu;
39 QPopupMenu *m_menu; 39 QColor m_color;
40 QColor m_color;
41}; 40};
42 41
42
43/**
44 * This concstructs a Color Button with @param color as the start color
45 * It'll use a OColorPopupMenu internally
46 *
47 * @param parent The parent of the Color Button
48 * @param color The color from where to start on
49 * @param name @see QObject
50 */
43OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *name ) 51OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *name )
44 : QPushButton ( parent, name ) 52 : QPushButton ( parent, name )
45{ 53{
46 d = new OColorButtonPrivate; 54 d = new OColorButtonPrivate;
47 55
48 d-> m_menu = new ColorPopupMenu ( color, 0, 0 ); 56 d-> m_menu = new OColorPopupMenu ( color, 0, 0 );
49 setPopup ( d-> m_menu ); 57 setPopup ( d-> m_menu );
50 //setPopupDelay ( 0 ); 58 //setPopupDelay ( 0 );
51 connect ( d-> m_menu, SIGNAL( colorSelected ( const QColor & )), this, SLOT( updateColor ( const QColor & ))); 59 connect ( d-> m_menu, SIGNAL( colorSelected ( const QColor & )), this, SLOT( updateColor ( const QColor & )));
@@ -57,37 +65,50 @@ OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *n
57 setMaximumSize ( s. width ( ) * 2, s. height ( )); 65 setMaximumSize ( s. width ( ) * 2, s. height ( ));
58} 66}
59 67
68/**
69 * This destructs the object
70 */
60OColorButton::~OColorButton ( ) 71OColorButton::~OColorButton ( )
61{ 72{
62 delete d; 73 delete d;
63} 74}
64 75
76/**
77 * @return Returns the current color of the button
78 */
65QColor OColorButton::color ( ) const 79QColor OColorButton::color ( ) const
66{ 80{
67 return d-> m_color; 81 return d-> m_color;
68} 82}
69 83
84/**
85 * This method sets the color of the button
86 * @param c The color to be set.
87 */
70void OColorButton::setColor ( const QColor &c ) 88void OColorButton::setColor ( const QColor &c )
71{ 89{
72 updateColor ( c ); 90 updateColor ( c );
73} 91}
74 92
93/**
94 * @internal
95 */
75void OColorButton::updateColor ( const QColor &c ) 96void OColorButton::updateColor ( const QColor &c )
76{ 97{
77 d-> m_color = c; 98 d-> m_color = c;
78 99
79 QImage img ( 16, 16, 32 ); 100 QImage img ( 16, 16, 32 );
80 img. fill ( 0 ); 101 img. fill ( 0 );
81 102
82 int r, g, b; 103 int r, g, b;
83 c. rgb ( &r, &g, &b ); 104 c. rgb ( &r, &g, &b );
84 105
85 int w = img. width ( ); 106 int w = img. width ( );
86 int h = img. height ( ); 107 int h = img. height ( );
87 108
88 int dx = w * 20 / 100; // 15% 109 int dx = w * 20 / 100; // 15%
89 int dy = h * 20 / 100; 110 int dy = h * 20 / 100;
90 111
91 for ( int y = 0; y < h; y++ ) { 112 for ( int y = 0; y < h; y++ ) {
92 for ( int x = 0; x < w; x++ ) { 113 for ( int x = 0; x < w; x++ ) {
93 double alpha = 1.0; 114 double alpha = 1.0;
@@ -100,7 +121,7 @@ void OColorButton::updateColor ( const QColor &c )
100 alpha *= ( double ( y + 1 ) / dy ); 121 alpha *= ( double ( y + 1 ) / dy );
101 else if ( y >= h - dy ) 122 else if ( y >= h - dy )
102 alpha *= ( double ( h - y ) / dy ); 123 alpha *= ( double ( h - y ) / dy );
103 124
104 int a = int ( alpha * 255.0 ); 125 int a = int ( alpha * 255.0 );
105 if ( a < 0 ) 126 if ( a < 0 )
106 a = 0; 127 a = 0;
@@ -114,7 +135,7 @@ void OColorButton::updateColor ( const QColor &c )
114 135
115 QPixmap pix; 136 QPixmap pix;
116 pix. convertFromImage ( img ); 137 pix. convertFromImage ( img );
117 setPixmap ( pix ); 138 setPixmap ( pix );
118 139
119 emit colorSelected ( c ); 140 emit colorSelected ( c );
120} 141}