libopie API Documentation

colorpopupmenu.cpp

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