Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ocolorpopupmenu.cpp

Go to the documentation of this file.
00001 /*
00002                             This file is part of the Opie Project
00003 
00004                  Copyright (c)  2002 S. Prud'homme <prudhomme@laposte.net>
00005                                      Dan Williams <williamsdr@acm.org>
00006               =.
00007             .=l.
00008            .>+-=
00009  _;:,     .>    :=|.         This program is free software; you can
00010 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00011 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00012 .="- .-=="i,     .._         License as published by the Free Software
00013  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00014      ._= =}       :          or (at your option) any later version.
00015     .%`+i>       _;_.
00016     .i_,=:_.      -<s.       This program is distributed in the hope that
00017      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00018     : ..    .:,     . . .    without even the implied warranty of
00019     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00020   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00021 ..}^=.=       =       ;      Library General Public License for more
00022 ++=   -.     .`     .:       details.
00023  :     =  ...= . :.=-
00024  -.   .:....=;==+<;          You should have received a copy of the GNU
00025   -_. . .   )=.  =           Library General Public License along with
00026     --        :-=`           this library; see the file COPYING.LIB.
00027                              If not, write to the Free Software Foundation,
00028                              Inc., 59 Temple Place - Suite 330,
00029                              Boston, MA 02111-1307, USA.
00030 
00031 */
00032 
00033 #include "ocolorpopupmenu.h"
00034 #include "qcolordialog.h"
00035 
00036 /* QT */
00037 #include <qlayout.h>
00038 #include <qpainter.h>
00039 
00040 using namespace Opie;
00041 
00042 OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name )
00043     : QFrame( parent, name )
00044 {
00045     m_color = color;
00046 
00047     setFixedSize( 16, 16 );
00048     setActive( FALSE );
00049 }
00050 
00051 OColorPanelButton::~OColorPanelButton()
00052 {
00053 }
00054 
00055 void OColorPanelButton::setActive( bool active )
00056 {
00057     m_active = active;
00058 
00059     if ( m_active ) {
00060         setFrameStyle( Panel | Sunken );
00061     } else {
00062         setFrameStyle( NoFrame );
00063     }
00064 }
00065 
00066 void OColorPanelButton::enterEvent( QEvent*  )
00067 {
00068     if ( !m_active ) {
00069         setFrameStyle( Panel | Sunken );
00070     }
00071 }
00072 
00073 void OColorPanelButton::leaveEvent( QEvent*  )
00074 {
00075     if ( !m_active ) {
00076         setFrameStyle( NoFrame );
00077     }
00078 }
00079 
00080 void OColorPanelButton::paintEvent( QPaintEvent* e )
00081 {
00082     QFrame::paintEvent( e );
00083 
00084     QPainter painter;
00085     painter.begin( this );
00086     painter.fillRect( 2, 2, 12, 12, m_color );
00087     painter.setPen( Qt::black );
00088     painter.drawRect( 2, 2, 12, 12 );
00089     painter.end();
00090 }
00091 
00092 void OColorPanelButton::mouseReleaseEvent( QMouseEvent*   )
00093 {
00094     emit selected( m_color );
00095 }
00096 
00097 OColorPopupMenu::OColorPopupMenu( const QColor& color, QWidget* parent, const char* name )
00098     : QPopupMenu( parent, name )
00099 {
00100     m_color = color;
00101 
00102     colorPanel = new QWidget( this );
00103 
00104     colorLayout = new QGridLayout(colorPanel, 5, 6);
00105 
00106     addColor(QColor(255, 255, 255), 0, 1);
00107     addColor(QColor(192, 192, 192), 0, 2);
00108     addColor(QColor(128, 128, 128), 0, 3);
00109     addColor(QColor(64, 64, 64), 0, 4);
00110     addColor(QColor(0, 0, 0), 0, 5);
00111 
00112     addColor(QColor(255, 0, 0), 1, 0);
00113     addColor(QColor(255, 128, 0), 1, 1);
00114     addColor(QColor(255, 255, 0), 1, 2);
00115     addColor(QColor(128, 255, 0), 1, 3);
00116     addColor(QColor(0, 255, 0), 1, 4);
00117     addColor(QColor(0, 255, 128), 1, 5);
00118 
00119     addColor(QColor(128, 0, 0), 2, 0);
00120     addColor(QColor(128, 64, 0), 2, 1);
00121     addColor(QColor(128, 128, 0), 2, 2);
00122     addColor(QColor(64, 128, 0), 2, 3);
00123     addColor(QColor(0, 128, 0), 2, 4);
00124     addColor(QColor(0, 128, 64), 2, 5);
00125 
00126     addColor(QColor(0, 255, 255), 3, 0);
00127     addColor(QColor(0, 128, 255), 3, 1);
00128     addColor(QColor(0, 0, 255), 3, 2);
00129     addColor(QColor(128, 0, 255), 3, 3);
00130     addColor(QColor(255, 0, 255), 3, 4);
00131     addColor(QColor(255, 0, 128), 3, 5);
00132 
00133     addColor(QColor(0, 128, 128), 4, 0);
00134     addColor(QColor(0, 64, 128), 4, 1);
00135     addColor(QColor(0, 0, 128), 4, 2);
00136     addColor(QColor(64, 0, 128), 4, 3);
00137     addColor(QColor(128, 0, 128), 4, 4);
00138     addColor(QColor(128, 0, 64), 4, 5);
00139 
00140     insertItem( colorPanel );
00141     insertSeparator();
00142     insertItem(tr("More"),this,SLOT( moreColorClicked()));
00143     /*
00144     QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" );
00145     connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) );
00146     chooseColorAction->addTo( this );
00147     */
00148     activateItemAt( 0 );
00149 }
00150 
00151 OColorPopupMenu::~OColorPopupMenu()
00152 {
00153 }
00154 
00155 void OColorPopupMenu::addColor( const QColor& color, int row, int col )
00156 {
00157     OColorPanelButton* panelButton = new OColorPanelButton( color, colorPanel );
00158     connect( panelButton, SIGNAL( selected(const QColor&) ), this, SLOT( buttonSelected(const QColor&) ) );
00159     colorLayout->addWidget( panelButton, row, col );
00160 }
00161 
00162 void OColorPopupMenu::buttonSelected( const QColor& color )
00163 {
00164     m_color = color;
00165     emit colorSelected( color );
00166     hide();
00167 }
00168 
00169 void OColorPopupMenu::moreColorClicked()
00170 {
00171     QColor color = QColorDialog::getColor( m_color );
00172     m_color = color;
00173     emit colorSelected( color );
00174     hide();
00175 }

Generated on Sat Nov 5 16:16:30 2005 for OPIE by  doxygen 1.4.2