author | zecke <zecke> | 2004-09-12 23:47:11 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-09-12 23:47:11 (UTC) |
commit | 03d8f31d45fa569d944ff635428ad9a946f077b9 (patch) (unidiff) | |
tree | 9e1bdc54778581577a16be570c133a9693b4a47d | |
parent | f05a19bd1e248ea8cea29d361a1a8085ca145c6a (diff) | |
download | opie-03d8f31d45fa569d944ff635428ad9a946f077b9.zip opie-03d8f31d45fa569d944ff635428ad9a946f077b9.tar.gz opie-03d8f31d45fa569d944ff635428ad9a946f077b9.tar.bz2 |
OColorButton::~OColorButton ( )
{
+ delete d->m_menu;
delete d;
}
That was a tricky one to find. If a dynamically loaded shared object (dso)
creates QObjects/QWidgets on the destruction of QApplication they will
be freed. For normal applications these dso's have already been removed
from the address-space leading to calling delete to or from a bogus
part of memory leading to segfaults
-rw-r--r-- | libqtaux/ocolorbutton.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/libqtaux/ocolorbutton.cpp b/libqtaux/ocolorbutton.cpp index 925df7f..004fafc 100644 --- a/libqtaux/ocolorbutton.cpp +++ b/libqtaux/ocolorbutton.cpp | |||
@@ -1,155 +1,156 @@ | |||
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 | ||
38 | using namespace Opie; | 38 | using namespace Opie; |
39 | 39 | ||
40 | struct OColorButtonPrivate | 40 | struct 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 | */ |
54 | OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *name ) | 54 | OColorButton::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 | */ |
74 | OColorButton::~OColorButton ( ) | 74 | OColorButton::~OColorButton ( ) |
75 | { | 75 | { |
76 | delete d->m_menu; | ||
76 | delete d; | 77 | delete d; |
77 | } | 78 | } |
78 | 79 | ||
79 | /** | 80 | /** |
80 | * @return Returns the current color of the button | 81 | * @return Returns the current color of the button |
81 | */ | 82 | */ |
82 | QColor OColorButton::color ( ) const | 83 | QColor OColorButton::color ( ) const |
83 | { | 84 | { |
84 | return d-> m_color; | 85 | return d-> m_color; |
85 | } | 86 | } |
86 | 87 | ||
87 | /** | 88 | /** |
88 | * This method sets the color of the button | 89 | * This method sets the color of the button |
89 | * @param c The color to be set. | 90 | * @param c The color to be set. |
90 | */ | 91 | */ |
91 | void OColorButton::setColor ( const QColor &c ) | 92 | void OColorButton::setColor ( const QColor &c ) |
92 | { | 93 | { |
93 | updateColor ( c ); | 94 | updateColor ( c ); |
94 | } | 95 | } |
95 | 96 | ||
96 | /** | 97 | /** |
97 | * @internal | 98 | * @internal |
98 | */ | 99 | */ |
99 | void OColorButton::updateColor ( const QColor &c ) | 100 | void OColorButton::updateColor ( const QColor &c ) |
100 | { | 101 | { |
101 | d-> m_color = c; | 102 | d-> m_color = c; |
102 | 103 | ||
103 | QImage img ( width()-14, height()-6, 32 ); | 104 | QImage img ( width()-14, height()-6, 32 ); |
104 | img. fill ( 0 ); | 105 | img. fill ( 0 ); |
105 | 106 | ||
106 | int r, g, b; | 107 | int r, g, b; |
107 | c. rgb ( &r, &g, &b ); | 108 | c. rgb ( &r, &g, &b ); |
108 | 109 | ||
109 | int w = img. width ( ); | 110 | int w = img. width ( ); |
110 | int h = img. height ( ); | 111 | int h = img. height ( ); |
111 | 112 | ||
112 | int dx = w * 20 / 100; // 15% | 113 | int dx = w * 20 / 100; // 15% |
113 | int dy = h * 20 / 100; | 114 | int dy = h * 20 / 100; |
114 | 115 | ||
115 | for ( int y = 0; y < h; y++ ) | 116 | for ( int y = 0; y < h; y++ ) |
116 | { | 117 | { |
117 | for ( int x = 0; x < w; x++ ) | 118 | for ( int x = 0; x < w; x++ ) |
118 | { | 119 | { |
119 | double alpha = 1.0; | 120 | double alpha = 1.0; |
120 | 121 | ||
121 | if ( x < dx ) | 122 | if ( x < dx ) |
122 | alpha *= ( double ( x + 1 ) / dx ); | 123 | alpha *= ( double ( x + 1 ) / dx ); |
123 | else if ( x >= w - dx ) | 124 | else if ( x >= w - dx ) |
124 | alpha *= ( double ( w - x ) / dx ); | 125 | alpha *= ( double ( w - x ) / dx ); |
125 | if ( y < dy ) | 126 | if ( y < dy ) |
126 | alpha *= ( double ( y + 1 ) / dy ); | 127 | alpha *= ( double ( y + 1 ) / dy ); |
127 | else if ( y >= h - dy ) | 128 | else if ( y >= h - dy ) |
128 | alpha *= ( double ( h - y ) / dy ); | 129 | alpha *= ( double ( h - y ) / dy ); |
129 | 130 | ||
130 | int a = int ( alpha * 255.0 ); | 131 | int a = int ( alpha * 255.0 ); |
131 | if ( a < 0 ) | 132 | if ( a < 0 ) |
132 | a = 0; | 133 | a = 0; |
133 | if ( a > 255 ) | 134 | if ( a > 255 ) |
134 | a = 255; | 135 | a = 255; |
135 | 136 | ||
136 | img. setPixel ( x, y, qRgba ( r, g, b, a )); | 137 | img. setPixel ( x, y, qRgba ( r, g, b, a )); |
137 | } | 138 | } |
138 | } | 139 | } |
139 | img. setAlphaBuffer ( true ); | 140 | img. setAlphaBuffer ( true ); |
140 | 141 | ||
141 | QPixmap pix; | 142 | QPixmap pix; |
142 | pix. convertFromImage ( img ); | 143 | pix. convertFromImage ( img ); |
143 | setPixmap ( pix ); | 144 | setPixmap ( pix ); |
144 | 145 | ||
145 | emit colorSelected ( c ); | 146 | emit colorSelected ( c ); |
146 | } | 147 | } |
147 | 148 | ||
148 | 149 | ||
149 | /** | 150 | /** |
150 | * @internal | 151 | * @internal |
151 | */ | 152 | */ |
152 | void OColorButton::resizeEvent( QResizeEvent *ev ) { | 153 | void OColorButton::resizeEvent( QResizeEvent *ev ) { |
153 | QPushButton::resizeEvent( ev ); | 154 | QPushButton::resizeEvent( ev ); |
154 | updateColor(d->m_color); | 155 | updateColor(d->m_color); |
155 | } | 156 | } |