author | zecke <zecke> | 2004-09-12 16:07:13 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-09-12 16:07:13 (UTC) |
commit | 36a4f75e1f4e5a3858749779ea26a3fe3154d1f0 (patch) (side-by-side diff) | |
tree | 18a61aedb81a9823cbf212cc82662c66101133f7 | |
parent | 12730b959f92a9d601d81bf28ab87fb265effe55 (diff) | |
download | opie-36a4f75e1f4e5a3858749779ea26a3fe3154d1f0.zip opie-36a4f75e1f4e5a3858749779ea26a3fe3154d1f0.tar.gz opie-36a4f75e1f4e5a3858749779ea26a3fe3154d1f0.tar.bz2 |
Do not limit the Image to 16x16 but use width() and height()
+ magic numbers to make the Image fit the button
-rw-r--r-- | libqtaux/ocolorbutton.cpp | 12 | ||||
-rw-r--r-- | libqtaux/ocolorbutton.h | 3 |
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 @@ -48,37 +48,37 @@ struct OColorButtonPrivate * It'll use a OColorPopupMenu internally * * @param parent The parent of the Color Button * @param color The color from where to start on * @param name @see QObject */ OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *name ) : QPushButton ( parent, name ) { d = new OColorButtonPrivate; d-> m_menu = new OColorPopupMenu ( color, 0, 0 ); setPopup ( d-> m_menu ); // setPopupDelay ( 0 ); connect ( d-> m_menu, SIGNAL( colorSelected(const QColor&)), this, SLOT( updateColor(const QColor&))); - updateColor ( color ); QSize s = sizeHint ( ) + QSize ( 12, 0 ); setMinimumSize ( s ); setMaximumSize ( s. width ( ) * 2, s. height ( )); + d->m_color = color; } /** * This destructs the object */ OColorButton::~OColorButton ( ) { delete d; } /** * @return Returns the current color of the button */ QColor OColorButton::color ( ) const { return d-> m_color; @@ -87,33 +87,33 @@ QColor OColorButton::color ( ) const /** * This method sets the color of the button * @param c The color to be set. */ void OColorButton::setColor ( const QColor &c ) { updateColor ( c ); } /** * @internal */ void OColorButton::updateColor ( const QColor &c ) { d-> m_color = c; - QImage img ( 16, 16, 32 ); + QImage img ( width()-14, height()-6, 32 ); img. fill ( 0 ); int r, g, b; c. rgb ( &r, &g, &b ); int w = img. width ( ); int h = img. height ( ); int dx = w * 20 / 100; // 15% int dy = h * 20 / 100; for ( int y = 0; y < h; y++ ) { for ( int x = 0; x < w; x++ ) { double alpha = 1.0; @@ -132,16 +132,24 @@ void OColorButton::updateColor ( const QColor &c ) a = 0; if ( a > 255 ) a = 255; img. setPixel ( x, y, qRgba ( r, g, b, a )); } } img. setAlphaBuffer ( true ); QPixmap pix; pix. convertFromImage ( img ); setPixmap ( pix ); emit colorSelected ( c ); } + +/** + * @internal + */ +void OColorButton::resizeEvent( QResizeEvent *ev ) { + QPushButton::resizeEvent( ev ); + updateColor(d->m_color); +} diff --git a/libqtaux/ocolorbutton.h b/libqtaux/ocolorbutton.h index ca68f1f..10b77d5 100644 --- a/libqtaux/ocolorbutton.h +++ b/libqtaux/ocolorbutton.h @@ -41,32 +41,35 @@ namespace Opie /** * * @short A Button which will show a OColorPopupMenu * @author Robert Griebl ( sandman@handhelds.org ) * @version 1.0 * @see QPushButton */ class OColorButton : public QPushButton { Q_OBJECT public: OColorButton ( QWidget *parent = 0, const QColor & = black, const char *name = 0 ); virtual ~OColorButton ( ); QColor color ( ) const; + +protected: + void resizeEvent( QResizeEvent* ); signals: /** * emitted when a color gets selected */ void colorSelected ( const QColor & ); public slots: virtual void setColor ( const QColor & ); protected slots: /** * @internal */ virtual void updateColor ( const QColor & ); |