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

colorpopupmenu.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 "colorpopupmenu.h"
00034 #include "colordialog.h"
00035 
00036 #include <qlayout.h>
00037 #include <qpainter.h>
00038 
00039 OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name )
00040     : QFrame( parent, name )
00041 {
00042     m_color = color;
00043 
00044     setFixedSize( 16, 16 );
00045     setActive( FALSE );
00046 }
00047 
00048 OColorPanelButton::~OColorPanelButton()
00049 {
00050 }
00051 
00052 void OColorPanelButton::setActive( bool active )
00053 {
00054     m_active = active;
00055 
00056     if ( m_active ) {
00057         setFrameStyle( Panel | Sunken );
00058     } else {
00059         setFrameStyle( NoFrame );
00060     }
00061 }
00062 
00063 void OColorPanelButton::enterEvent( QEvent*  )
00064 {
00065     if ( !m_active ) {
00066         setFrameStyle( Panel | Sunken );
00067     }
00068 }
00069 
00070 void OColorPanelButton::leaveEvent( QEvent*  )
00071 {
00072     if ( !m_active ) {
00073         setFrameStyle( NoFrame );
00074     }
00075 }
00076 
00077 void OColorPanelButton::paintEvent( QPaintEvent* e )
00078 {
00079     QFrame::paintEvent( e );
00080 
00081     QPainter painter;
00082     painter.begin( this );
00083     painter.fillRect( 2, 2, 12, 12, m_color );
00084     painter.setPen( Qt::black );
00085     painter.drawRect( 2, 2, 12, 12 );
00086     painter.end();
00087 }
00088 
00089 void OColorPanelButton::mouseReleaseEvent( QMouseEvent*   )
00090 {
00091     emit selected( m_color );
00092 }
00093 
00094 OColorPopupMenu::OColorPopupMenu( const QColor& color, QWidget* parent, const char* name )
00095     : QPopupMenu( parent, name )
00096 {
00097     m_color = color;
00098 
00099     colorPanel = new QWidget( this );
00100 
00101     colorLayout = new QGridLayout(colorPanel, 5, 6);
00102 
00103     addColor(QColor(255, 255, 255), 0, 1);
00104     addColor(QColor(192, 192, 192), 0, 2);
00105     addColor(QColor(128, 128, 128), 0, 3);
00106     addColor(QColor(64, 64, 64), 0, 4);
00107     addColor(QColor(0, 0, 0), 0, 5);
00108 
00109     addColor(QColor(255, 0, 0), 1, 0);
00110     addColor(QColor(255, 128, 0), 1, 1);
00111     addColor(QColor(255, 255, 0), 1, 2);
00112     addColor(QColor(128, 255, 0), 1, 3);
00113     addColor(QColor(0, 255, 0), 1, 4);
00114     addColor(QColor(0, 255, 128), 1, 5);
00115 
00116     addColor(QColor(128, 0, 0), 2, 0);
00117     addColor(QColor(128, 64, 0), 2, 1);
00118     addColor(QColor(128, 128, 0), 2, 2);
00119     addColor(QColor(64, 128, 0), 2, 3);
00120     addColor(QColor(0, 128, 0), 2, 4);
00121     addColor(QColor(0, 128, 64), 2, 5);
00122 
00123     addColor(QColor(0, 255, 255), 3, 0);
00124     addColor(QColor(0, 128, 255), 3, 1);
00125     addColor(QColor(0, 0, 255), 3, 2);
00126     addColor(QColor(128, 0, 255), 3, 3);
00127     addColor(QColor(255, 0, 255), 3, 4);
00128     addColor(QColor(255, 0, 128), 3, 5);
00129 
00130     addColor(QColor(0, 128, 128), 4, 0);
00131     addColor(QColor(0, 64, 128), 4, 1);
00132     addColor(QColor(0, 0, 128), 4, 2);
00133     addColor(QColor(64, 0, 128), 4, 3);
00134     addColor(QColor(128, 0, 128), 4, 4);
00135     addColor(QColor(128, 0, 64), 4, 5);
00136 
00137     insertItem( colorPanel );
00138     insertSeparator();
00139     insertItem(tr("More"),this,SLOT( moreColorClicked()));
00140     /*
00141     QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" );
00142     connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) );
00143     chooseColorAction->addTo( this );
00144     */
00145     activateItemAt( 0 );
00146 }
00147 
00148 OColorPopupMenu::~OColorPopupMenu()
00149 {
00150 }
00151 
00152 void OColorPopupMenu::addColor( const QColor& color, int row, int col )
00153 {
00154     OColorPanelButton* panelButton = new OColorPanelButton( color, colorPanel );
00155     connect( panelButton, SIGNAL( selected(const QColor&) ), this, SLOT( buttonSelected(const QColor&) ) );
00156     colorLayout->addWidget( panelButton, row, col );
00157 }
00158 
00159 void OColorPopupMenu::buttonSelected( const QColor& color )
00160 {
00161     m_color = color;
00162     emit colorSelected( color );
00163     hide();
00164 }
00165 
00166 void OColorPopupMenu::moreColorClicked()
00167 {
00168     QColor color = OColorDialog::getColor( m_color );
00169     m_color = color;
00170     emit colorSelected( color );
00171     hide();
00172 }

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