summaryrefslogtreecommitdiff
path: root/libqtaux/ocolorpopupmenu.cpp
authormickeyl <mickeyl>2004-01-13 21:14:51 (UTC)
committer mickeyl <mickeyl>2004-01-13 21:14:51 (UTC)
commitffe47019a96da4e6b7057fca30bb64274443099b (patch) (unidiff)
treeae203606aee544bec92ac9cc139a713199cf5522 /libqtaux/ocolorpopupmenu.cpp
parent7f865d5f46330faf3574495cc68093490f896411 (diff)
downloadopie-ffe47019a96da4e6b7057fca30bb64274443099b.zip
opie-ffe47019a96da4e6b7057fca30bb64274443099b.tar.gz
opie-ffe47019a96da4e6b7057fca30bb64274443099b.tar.bz2
introduce libqtaux in order to get a LGPL clean libopie2 after the merge
with libopie1
Diffstat (limited to 'libqtaux/ocolorpopupmenu.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libqtaux/ocolorpopupmenu.cpp173
1 files changed, 173 insertions, 0 deletions
diff --git a/libqtaux/ocolorpopupmenu.cpp b/libqtaux/ocolorpopupmenu.cpp
new file mode 100644
index 0000000..6a2321e
--- a/dev/null
+++ b/libqtaux/ocolorpopupmenu.cpp
@@ -0,0 +1,173 @@
1/*
2                This file is part of the Opie Project
3
4              Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net>
5              Dan Williams <williamsdr@acm.org>
6 =.
7 .=l.
8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details.
23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA.
30
31*/
32
33#include "ocolorpopupmenu.h"
34#include "qcolordialog.h"
35
36#include <qaction.h>
37#include <qlayout.h>
38#include <qpainter.h>
39
40OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name )
41 : QFrame( parent, name )
42{
43 m_color = color;
44
45 setFixedSize( 16, 16 );
46 setActive( FALSE );
47}
48
49OColorPanelButton::~OColorPanelButton()
50{
51}
52
53void OColorPanelButton::setActive( bool active )
54{
55 m_active = active;
56
57 if ( m_active ) {
58 setFrameStyle( Panel | Sunken );
59 } else {
60 setFrameStyle( NoFrame );
61 }
62}
63
64void OColorPanelButton::enterEvent( QEvent* )
65{
66 if ( !m_active ) {
67 setFrameStyle( Panel | Sunken );
68 }
69}
70
71void OColorPanelButton::leaveEvent( QEvent* )
72{
73 if ( !m_active ) {
74 setFrameStyle( NoFrame );
75 }
76}
77
78void OColorPanelButton::paintEvent( QPaintEvent* e )
79{
80 QFrame::paintEvent( e );
81
82 QPainter painter;
83 painter.begin( this );
84 painter.fillRect( 2, 2, 12, 12, m_color );
85 painter.setPen( Qt::black );
86 painter.drawRect( 2, 2, 12, 12 );
87 painter.end();
88}
89
90void OColorPanelButton::mouseReleaseEvent( QMouseEvent* )
91{
92 emit selected( m_color );
93}
94
95OColorPopupMenu::OColorPopupMenu( const QColor& color, QWidget* parent, const char* name )
96 : QPopupMenu( parent, name )
97{
98 m_color = color;
99
100 colorPanel = new QWidget( this );
101
102 colorLayout = new QGridLayout(colorPanel, 5, 6);
103
104 addColor(QColor(255, 255, 255), 0, 1);
105 addColor(QColor(192, 192, 192), 0, 2);
106 addColor(QColor(128, 128, 128), 0, 3);
107 addColor(QColor(64, 64, 64), 0, 4);
108 addColor(QColor(0, 0, 0), 0, 5);
109
110 addColor(QColor(255, 0, 0), 1, 0);
111 addColor(QColor(255, 128, 0), 1, 1);
112 addColor(QColor(255, 255, 0), 1, 2);
113 addColor(QColor(128, 255, 0), 1, 3);
114 addColor(QColor(0, 255, 0), 1, 4);
115 addColor(QColor(0, 255, 128), 1, 5);
116
117 addColor(QColor(128, 0, 0), 2, 0);
118 addColor(QColor(128, 64, 0), 2, 1);
119 addColor(QColor(128, 128, 0), 2, 2);
120 addColor(QColor(64, 128, 0), 2, 3);
121 addColor(QColor(0, 128, 0), 2, 4);
122 addColor(QColor(0, 128, 64), 2, 5);
123
124 addColor(QColor(0, 255, 255), 3, 0);
125 addColor(QColor(0, 128, 255), 3, 1);
126 addColor(QColor(0, 0, 255), 3, 2);
127 addColor(QColor(128, 0, 255), 3, 3);
128 addColor(QColor(255, 0, 255), 3, 4);
129 addColor(QColor(255, 0, 128), 3, 5);
130
131 addColor(QColor(0, 128, 128), 4, 0);
132 addColor(QColor(0, 64, 128), 4, 1);
133 addColor(QColor(0, 0, 128), 4, 2);
134 addColor(QColor(64, 0, 128), 4, 3);
135 addColor(QColor(128, 0, 128), 4, 4);
136 addColor(QColor(128, 0, 64), 4, 5);
137
138 insertItem( colorPanel );
139 insertSeparator();
140 insertItem(tr("More"),this,SLOT( moreColorClicked()));
141 /*
142 QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" );
143 connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) );
144 chooseColorAction->addTo( this );
145 */
146 activateItemAt( 0 );
147}
148
149OColorPopupMenu::~OColorPopupMenu()
150{
151}
152
153void OColorPopupMenu::addColor( const QColor& color, int row, int col )
154{
155 OColorPanelButton* panelButton = new OColorPanelButton( color, colorPanel );
156 connect( panelButton, SIGNAL( selected( const QColor& ) ), this, SLOT( buttonSelected( const QColor& ) ) );
157 colorLayout->addWidget( panelButton, row, col );
158}
159
160void OColorPopupMenu::buttonSelected( const QColor& color )
161{
162 m_color = color;
163 emit colorSelected( color );
164 hide();
165}
166
167void OColorPopupMenu::moreColorClicked()
168{
169 QColor color = QColorDialog::getColor( m_color );
170 m_color = color;
171 emit colorSelected( color );
172 hide();
173}