author | drw <drw> | 2005-03-12 00:45:16 (UTC) |
---|---|---|
committer | drw <drw> | 2005-03-12 00:45:16 (UTC) |
commit | c7cda5d104efd75ab608384215e40a541697392e (patch) (side-by-side diff) | |
tree | 61a9bfc37121a614b49c2941b28f929c6a3132df | |
parent | 31f314346f44706bebf998c58aae8cfe50cba6cf (diff) | |
download | opie-c7cda5d104efd75ab608384215e40a541697392e.zip opie-c7cda5d104efd75ab608384215e40a541697392e.tar.gz opie-c7cda5d104efd75ab608384215e40a541697392e.tar.bz2 |
Fix OColorButton so it does not emit a colorSelected signal inside of resizeEvent
-rw-r--r-- | libqtaux/ocolorbutton.cpp | 50 | ||||
-rw-r--r-- | libqtaux/ocolorbutton.h | 44 |
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,48 +1,48 @@ /* This file is part of the Opie Project Copyright (C) Robert Griebl <sandman@handhelds.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. - .>+-= - _;:, .> :=|. This program is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU Library General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This program is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU -..}^=.= = ; Library General Public License for more -++= -. .` .: details. - : = ...= . :.=- - -. .:....=;==+<; You should have received a copy of the GNU - -_. . . )=. = Library General Public License along with - -- :-=` this library; see the file COPYING.LIB. + .>+-= +_;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- +-. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "ocolorpopupmenu.h" #include "ocolorbutton.h" /* OPIE */ /* QT */ #include <qimage.h> using namespace Opie; struct OColorButtonPrivate { QPopupMenu *m_menu; QColor m_color; }; /** * This concstructs a Color Button with @param color as the start color * It'll use a OColorPopupMenu internally @@ -70,87 +70,93 @@ OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *n /** * This destructs the object */ OColorButton::~OColorButton ( ) { delete d->m_menu; delete d; } /** * @return Returns the current color of the button */ QColor OColorButton::color ( ) const { return d-> m_color; } /** * This method sets the color of the button * @param c The color to be set. */ void OColorButton::setColor ( const QColor &c ) { - updateColor ( c ); + updateColor ( c, true ); } /** * @internal */ void OColorButton::updateColor ( const QColor &c ) { + updateColor( c, true ); +} + +void OColorButton::updateColor ( const QColor &c, bool sendSignal ) +{ d-> m_color = c; 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; if ( x < dx ) alpha *= ( double ( x + 1 ) / dx ); else if ( x >= w - dx ) alpha *= ( double ( w - x ) / dx ); if ( y < dy ) alpha *= ( double ( y + 1 ) / dy ); else if ( y >= h - dy ) alpha *= ( double ( h - y ) / dy ); int a = int ( alpha * 255.0 ); if ( a < 0 ) 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 ); + if ( sendSignal ) + emit colorSelected ( c ); } /** * @internal */ void OColorButton::resizeEvent( QResizeEvent *ev ) { QPushButton::resizeEvent( ev ); - updateColor(d->m_color); + updateColor( d->m_color, false ); } 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 @@ /* This file is part of the Opie Project Copyright (C) Robert Griebl <sandman@handhelds.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. - .>+-= - _;:, .> :=|. This program is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU Library General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This program is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU -..}^=.= = ; Library General Public License for more -++= -. .` .: details. - : = ...= . :.=- - -. .:....=;==+<; You should have received a copy of the GNU - -_. . . )=. = Library General Public License along with - -- :-=` this library; see the file COPYING.LIB. + .>+-= +_;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- +-. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OCOLORBUTTON_H #define OCOLORBUTTON_H /* QT*/ #include <qpushbutton.h> class OColorButtonPrivate; class QColor; 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* ); + 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 & ); private: OColorButtonPrivate *d; + + void updateColor ( const QColor &, bool sendSignal = true ); }; }; #endif |