-rw-r--r-- | libopie/colorpopupmenu.cpp | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/libopie/colorpopupmenu.cpp b/libopie/colorpopupmenu.cpp index 510a2ad..dac10e9 100644 --- a/libopie/colorpopupmenu.cpp +++ b/libopie/colorpopupmenu.cpp | |||
@@ -16,110 +16,104 @@ | |||
16 | .i_,=:_. -<s. This program is distributed in the hope that | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 18 | : .. .:, . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 21 | ..}^=.= = ; Library General Public License for more |
22 | ++= -. .` .: details. | 22 | ++= -. .` .: details. |
23 | : = ...= . :.=- | 23 | : = ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 24 | -. .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 25 | -_. . . )=. = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 26 | -- :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 27 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 28 | Inc., 59 Temple Place - Suite 330, |
29 | Boston, MA 02111-1307, USA. | 29 | Boston, MA 02111-1307, USA. |
30 | 30 | ||
31 | */ | 31 | */ |
32 | 32 | ||
33 | #include "colorpopupmenu.h" | 33 | #include "colorpopupmenu.h" |
34 | #include "colordialog.h" | 34 | #include "colordialog.h" |
35 | 35 | ||
36 | #include <qaction.h> | 36 | #include <qaction.h> |
37 | #include <qlayout.h> | 37 | #include <qlayout.h> |
38 | #include <qpainter.h> | 38 | #include <qpainter.h> |
39 | 39 | ||
40 | ColorPanelButton::ColorPanelButton( const QColor& color, QWidget* parent, const char* name ) | 40 | OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name ) |
41 | : QFrame( parent, name ) | 41 | : QFrame( parent, name ) |
42 | { | 42 | { |
43 | m_color = color; | 43 | m_color = color; |
44 | 44 | ||
45 | setFixedSize( 16, 16 ); | 45 | setFixedSize( 16, 16 ); |
46 | setActive( FALSE ); | 46 | setActive( FALSE ); |
47 | } | 47 | } |
48 | 48 | ||
49 | ColorPanelButton::~ColorPanelButton() | 49 | OColorPanelButton::~OColorPanelButton() |
50 | { | 50 | { |
51 | } | 51 | } |
52 | 52 | ||
53 | void ColorPanelButton::setActive( bool active ) | 53 | void OColorPanelButton::setActive( bool active ) |
54 | { | 54 | { |
55 | m_active = active; | 55 | m_active = active; |
56 | 56 | ||
57 | if ( m_active ) { | 57 | if ( m_active ) { |
58 | setFrameStyle( Panel | Sunken ); | 58 | setFrameStyle( Panel | Sunken ); |
59 | } else { | 59 | } else { |
60 | setFrameStyle( NoFrame ); | 60 | setFrameStyle( NoFrame ); |
61 | } | 61 | } |
62 | } | 62 | } |
63 | 63 | ||
64 | void ColorPanelButton::enterEvent( QEvent* e ) | 64 | void OColorPanelButton::enterEvent( QEvent* ) |
65 | { | 65 | { |
66 | Q_UNUSED( e ) | ||
67 | |||
68 | if ( !m_active ) { | 66 | if ( !m_active ) { |
69 | setFrameStyle( Panel | Sunken ); | 67 | setFrameStyle( Panel | Sunken ); |
70 | } | 68 | } |
71 | } | 69 | } |
72 | 70 | ||
73 | void ColorPanelButton::leaveEvent( QEvent* e ) | 71 | void OColorPanelButton::leaveEvent( QEvent* ) |
74 | { | 72 | { |
75 | Q_UNUSED( e ) | ||
76 | |||
77 | if ( !m_active ) { | 73 | if ( !m_active ) { |
78 | setFrameStyle( NoFrame ); | 74 | setFrameStyle( NoFrame ); |
79 | } | 75 | } |
80 | } | 76 | } |
81 | 77 | ||
82 | void ColorPanelButton::paintEvent( QPaintEvent* e ) | 78 | void OColorPanelButton::paintEvent( QPaintEvent* e ) |
83 | { | 79 | { |
84 | QFrame::paintEvent( e ); | 80 | QFrame::paintEvent( e ); |
85 | 81 | ||
86 | QPainter painter; | 82 | QPainter painter; |
87 | painter.begin( this ); | 83 | painter.begin( this ); |
88 | painter.fillRect( 2, 2, 12, 12, m_color ); | 84 | painter.fillRect( 2, 2, 12, 12, m_color ); |
89 | painter.setPen( Qt::black ); | 85 | painter.setPen( Qt::black ); |
90 | painter.drawRect( 2, 2, 12, 12 ); | 86 | painter.drawRect( 2, 2, 12, 12 ); |
91 | painter.end(); | 87 | painter.end(); |
92 | } | 88 | } |
93 | 89 | ||
94 | void ColorPanelButton::mouseReleaseEvent( QMouseEvent* e ) | 90 | void OColorPanelButton::mouseReleaseEvent( QMouseEvent* ) |
95 | { | 91 | { |
96 | Q_UNUSED( e ) | ||
97 | |||
98 | emit selected( m_color ); | 92 | emit selected( m_color ); |
99 | } | 93 | } |
100 | 94 | ||
101 | ColorPopupMenu::ColorPopupMenu( const QColor& color, QWidget* parent, const char* name ) | 95 | OColorPopupMenu::OColorPopupMenu( const QColor& color, QWidget* parent, const char* name ) |
102 | : QPopupMenu( parent, name ) | 96 | : QPopupMenu( parent, name ) |
103 | { | 97 | { |
104 | m_color = color; | 98 | m_color = color; |
105 | 99 | ||
106 | colorPanel = new QWidget( this ); | 100 | colorPanel = new QWidget( this ); |
107 | 101 | ||
108 | colorLayout = new QGridLayout(colorPanel, 5, 6); | 102 | colorLayout = new QGridLayout(colorPanel, 5, 6); |
109 | 103 | ||
110 | addColor(QColor(255, 255, 255), 0, 1); | 104 | addColor(QColor(255, 255, 255), 0, 1); |
111 | addColor(QColor(192, 192, 192), 0, 2); | 105 | addColor(QColor(192, 192, 192), 0, 2); |
112 | addColor(QColor(128, 128, 128), 0, 3); | 106 | addColor(QColor(128, 128, 128), 0, 3); |
113 | addColor(QColor(64, 64, 64), 0, 4); | 107 | addColor(QColor(64, 64, 64), 0, 4); |
114 | addColor(QColor(0, 0, 0), 0, 5); | 108 | addColor(QColor(0, 0, 0), 0, 5); |
115 | 109 | ||
116 | addColor(QColor(255, 0, 0), 1, 0); | 110 | addColor(QColor(255, 0, 0), 1, 0); |
117 | addColor(QColor(255, 128, 0), 1, 1); | 111 | addColor(QColor(255, 128, 0), 1, 1); |
118 | addColor(QColor(255, 255, 0), 1, 2); | 112 | addColor(QColor(255, 255, 0), 1, 2); |
119 | addColor(QColor(128, 255, 0), 1, 3); | 113 | addColor(QColor(128, 255, 0), 1, 3); |
120 | addColor(QColor(0, 255, 0), 1, 4); | 114 | addColor(QColor(0, 255, 0), 1, 4); |
121 | addColor(QColor(0, 255, 128), 1, 5); | 115 | addColor(QColor(0, 255, 128), 1, 5); |
122 | 116 | ||
123 | addColor(QColor(128, 0, 0), 2, 0); | 117 | addColor(QColor(128, 0, 0), 2, 0); |
124 | addColor(QColor(128, 64, 0), 2, 1); | 118 | addColor(QColor(128, 64, 0), 2, 1); |
125 | addColor(QColor(128, 128, 0), 2, 2); | 119 | addColor(QColor(128, 128, 0), 2, 2); |
@@ -128,49 +122,49 @@ ColorPopupMenu::ColorPopupMenu( const QColor& color, QWidget* parent, const char | |||
128 | addColor(QColor(0, 128, 64), 2, 5); | 122 | addColor(QColor(0, 128, 64), 2, 5); |
129 | 123 | ||
130 | addColor(QColor(0, 255, 255), 3, 0); | 124 | addColor(QColor(0, 255, 255), 3, 0); |
131 | addColor(QColor(0, 128, 255), 3, 1); | 125 | addColor(QColor(0, 128, 255), 3, 1); |
132 | addColor(QColor(0, 0, 255), 3, 2); | 126 | addColor(QColor(0, 0, 255), 3, 2); |
133 | addColor(QColor(128, 0, 255), 3, 3); | 127 | addColor(QColor(128, 0, 255), 3, 3); |
134 | addColor(QColor(255, 0, 255), 3, 4); | 128 | addColor(QColor(255, 0, 255), 3, 4); |
135 | addColor(QColor(255, 0, 128), 3, 5); | 129 | addColor(QColor(255, 0, 128), 3, 5); |
136 | 130 | ||
137 | addColor(QColor(0, 128, 128), 4, 0); | 131 | addColor(QColor(0, 128, 128), 4, 0); |
138 | addColor(QColor(0, 64, 128), 4, 1); | 132 | addColor(QColor(0, 64, 128), 4, 1); |
139 | addColor(QColor(0, 0, 128), 4, 2); | 133 | addColor(QColor(0, 0, 128), 4, 2); |
140 | addColor(QColor(64, 0, 128), 4, 3); | 134 | addColor(QColor(64, 0, 128), 4, 3); |
141 | addColor(QColor(128, 0, 128), 4, 4); | 135 | addColor(QColor(128, 0, 128), 4, 4); |
142 | addColor(QColor(128, 0, 64), 4, 5); | 136 | addColor(QColor(128, 0, 64), 4, 5); |
143 | 137 | ||
144 | insertItem( colorPanel ); | 138 | insertItem( colorPanel ); |
145 | insertSeparator(); | 139 | insertSeparator(); |
146 | QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" ); | 140 | QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" ); |
147 | connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) ); | 141 | connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) ); |
148 | chooseColorAction->addTo( this ); | 142 | chooseColorAction->addTo( this ); |
149 | activateItemAt( 0 ); | 143 | activateItemAt( 0 ); |
150 | } | 144 | } |
151 | 145 | ||
152 | ColorPopupMenu::~ColorPopupMenu() | 146 | OColorPopupMenu::~OColorPopupMenu() |
153 | { | 147 | { |
154 | } | 148 | } |
155 | 149 | ||
156 | void ColorPopupMenu::addColor( const QColor& color, int row, int col ) | 150 | void OColorPopupMenu::addColor( const QColor& color, int row, int col ) |
157 | { | 151 | { |
158 | ColorPanelButton* panelButton = new ColorPanelButton( color, colorPanel ); | 152 | OColorPanelButton* panelButton = new OColorPanelButton( color, colorPanel ); |
159 | connect( panelButton, SIGNAL( selected( const QColor& ) ), this, SLOT( buttonSelected( const QColor& ) ) ); | 153 | connect( panelButton, SIGNAL( selected( const QColor& ) ), this, SLOT( buttonSelected( const QColor& ) ) ); |
160 | colorLayout->addWidget( panelButton, row, col ); | 154 | colorLayout->addWidget( panelButton, row, col ); |
161 | } | 155 | } |
162 | 156 | ||
163 | void ColorPopupMenu::buttonSelected( const QColor& color ) | 157 | void OColorPopupMenu::buttonSelected( const QColor& color ) |
164 | { | 158 | { |
165 | m_color = color; | 159 | m_color = color; |
166 | emit colorSelected( color ); | 160 | emit colorSelected( color ); |
167 | hide(); | 161 | hide(); |
168 | } | 162 | } |
169 | 163 | ||
170 | void ColorPopupMenu::moreColorClicked() | 164 | void OColorPopupMenu::moreColorClicked() |
171 | { | 165 | { |
172 | QColor color = OColorDialog::getColor( m_color ); | 166 | QColor color = OColorDialog::getColor( m_color ); |
173 | m_color = color; | 167 | m_color = color; |
174 | emit colorSelected( color ); | 168 | emit colorSelected( color ); |
175 | hide(); | 169 | hide(); |
176 | } | 170 | } |