author | mickeyl <mickeyl> | 2004-01-13 21:14:51 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-01-13 21:14:51 (UTC) |
commit | ffe47019a96da4e6b7057fca30bb64274443099b (patch) (side-by-side diff) | |
tree | ae203606aee544bec92ac9cc139a713199cf5522 /libqtaux/ocolorpopupmenu.cpp | |
parent | 7f865d5f46330faf3574495cc68093490f896411 (diff) | |
download | opie-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
-rw-r--r-- | libqtaux/ocolorpopupmenu.cpp | 173 |
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 @@ +/* + This file is part of the Opie Project + + Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net> + Dan Williams <williamsdr@acm.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#include "ocolorpopupmenu.h" +#include "qcolordialog.h" + +#include <qaction.h> +#include <qlayout.h> +#include <qpainter.h> + +OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name ) + : QFrame( parent, name ) +{ + m_color = color; + + setFixedSize( 16, 16 ); + setActive( FALSE ); +} + +OColorPanelButton::~OColorPanelButton() +{ +} + +void OColorPanelButton::setActive( bool active ) +{ + m_active = active; + + if ( m_active ) { + setFrameStyle( Panel | Sunken ); + } else { + setFrameStyle( NoFrame ); + } +} + +void OColorPanelButton::enterEvent( QEvent* ) +{ + if ( !m_active ) { + setFrameStyle( Panel | Sunken ); + } +} + +void OColorPanelButton::leaveEvent( QEvent* ) +{ + if ( !m_active ) { + setFrameStyle( NoFrame ); + } +} + +void OColorPanelButton::paintEvent( QPaintEvent* e ) +{ + QFrame::paintEvent( e ); + + QPainter painter; + painter.begin( this ); + painter.fillRect( 2, 2, 12, 12, m_color ); + painter.setPen( Qt::black ); + painter.drawRect( 2, 2, 12, 12 ); + painter.end(); +} + +void OColorPanelButton::mouseReleaseEvent( QMouseEvent* ) +{ + emit selected( m_color ); +} + +OColorPopupMenu::OColorPopupMenu( const QColor& color, QWidget* parent, const char* name ) + : QPopupMenu( parent, name ) +{ + m_color = color; + + colorPanel = new QWidget( this ); + + colorLayout = new QGridLayout(colorPanel, 5, 6); + + addColor(QColor(255, 255, 255), 0, 1); + addColor(QColor(192, 192, 192), 0, 2); + addColor(QColor(128, 128, 128), 0, 3); + addColor(QColor(64, 64, 64), 0, 4); + addColor(QColor(0, 0, 0), 0, 5); + + addColor(QColor(255, 0, 0), 1, 0); + addColor(QColor(255, 128, 0), 1, 1); + addColor(QColor(255, 255, 0), 1, 2); + addColor(QColor(128, 255, 0), 1, 3); + addColor(QColor(0, 255, 0), 1, 4); + addColor(QColor(0, 255, 128), 1, 5); + + addColor(QColor(128, 0, 0), 2, 0); + addColor(QColor(128, 64, 0), 2, 1); + addColor(QColor(128, 128, 0), 2, 2); + addColor(QColor(64, 128, 0), 2, 3); + addColor(QColor(0, 128, 0), 2, 4); + addColor(QColor(0, 128, 64), 2, 5); + + addColor(QColor(0, 255, 255), 3, 0); + addColor(QColor(0, 128, 255), 3, 1); + addColor(QColor(0, 0, 255), 3, 2); + addColor(QColor(128, 0, 255), 3, 3); + addColor(QColor(255, 0, 255), 3, 4); + addColor(QColor(255, 0, 128), 3, 5); + + addColor(QColor(0, 128, 128), 4, 0); + addColor(QColor(0, 64, 128), 4, 1); + addColor(QColor(0, 0, 128), 4, 2); + addColor(QColor(64, 0, 128), 4, 3); + addColor(QColor(128, 0, 128), 4, 4); + addColor(QColor(128, 0, 64), 4, 5); + + insertItem( colorPanel ); + insertSeparator(); + insertItem(tr("More"),this,SLOT( moreColorClicked())); + /* + QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" ); + connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) ); + chooseColorAction->addTo( this ); + */ + activateItemAt( 0 ); +} + +OColorPopupMenu::~OColorPopupMenu() +{ +} + +void OColorPopupMenu::addColor( const QColor& color, int row, int col ) +{ + OColorPanelButton* panelButton = new OColorPanelButton( color, colorPanel ); + connect( panelButton, SIGNAL( selected( const QColor& ) ), this, SLOT( buttonSelected( const QColor& ) ) ); + colorLayout->addWidget( panelButton, row, col ); +} + +void OColorPopupMenu::buttonSelected( const QColor& color ) +{ + m_color = color; + emit colorSelected( color ); + hide(); +} + +void OColorPopupMenu::moreColorClicked() +{ + QColor color = QColorDialog::getColor( m_color ); + m_color = color; + emit colorSelected( color ); + hide(); +} |