author | llornkcor <llornkcor> | 2002-08-27 01:36:02 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-08-27 01:36:02 (UTC) |
commit | f7d9d8697c2971b7f512ade7625dfff30d0043d0 (patch) (unidiff) | |
tree | bc6d64427bb616a3c8921089f2f7175e740c6e79 | |
parent | 165a55b0ab411521da724516460ba7fb6e58675e (diff) | |
download | opie-f7d9d8697c2971b7f512ade7625dfff30d0043d0.zip opie-f7d9d8697c2971b7f512ade7625dfff30d0043d0.tar.gz opie-f7d9d8697c2971b7f512ade7625dfff30d0043d0.tar.bz2 |
comments/docs by drw
-rw-r--r-- | libopie/colordialog.h | 12 | ||||
-rw-r--r-- | libopie/colorpopupmenu.cpp | 51 | ||||
-rw-r--r-- | libopie/colorpopupmenu.h | 213 |
3 files changed, 236 insertions, 40 deletions
diff --git a/libopie/colordialog.h b/libopie/colordialog.h index 474bc61..926f8f2 100644 --- a/libopie/colordialog.h +++ b/libopie/colordialog.h | |||
@@ -1,77 +1,89 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Definition of OColorDialog class | 4 | ** Definition of OColorDialog class |
5 | ** | 5 | ** |
6 | ** Created : 990222 | 6 | ** Created : 990222 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the dialogs module of the Qt GUI Toolkit. | 10 | ** This file is part of the dialogs module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
13 | ** as defined by Trolltech AS of Norway and appearing in the file | 13 | ** as defined by Trolltech AS of Norway and appearing in the file |
14 | ** LICENSE.QPL included in the packaging of this file. | 14 | ** LICENSE.QPL included in the packaging of this file. |
15 | ** | 15 | ** |
16 | ** This file may be distributed and/or modified under the terms of the | 16 | ** This file may be distributed and/or modified under the terms of the |
17 | ** GNU General Public License version 2 as published by the Free Software | 17 | ** GNU General Public License version 2 as published by the Free Software |
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | 18 | ** Foundation and appearing in the file LICENSE.GPL included in the |
19 | ** packaging of this file. | 19 | ** packaging of this file. |
20 | ** | 20 | ** |
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition |
22 | ** licenses may use this file in accordance with the Qt Commercial License | 22 | ** licenses may use this file in accordance with the Qt Commercial License |
23 | ** Agreement provided with the Software. | 23 | ** Agreement provided with the Software. |
24 | ** | 24 | ** |
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
27 | ** | 27 | ** |
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
29 | ** information about Qt Commercial License Agreements. | 29 | ** information about Qt Commercial License Agreements. |
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
32 | ** | 32 | ** |
33 | ** Contact info@trolltech.com if any conditions of this licensing are | 33 | ** Contact info@trolltech.com if any conditions of this licensing are |
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | #ifndef OColorDialog_H | 38 | #ifndef OColorDialog_H |
39 | #define OColorDialog_H | 39 | #define OColorDialog_H |
40 | 40 | ||
41 | #ifndef QT_H | 41 | #ifndef QT_H |
42 | #include <qdialog.h> | 42 | #include <qdialog.h> |
43 | #endif // QT_H | 43 | #endif // QT_H |
44 | 44 | ||
45 | class OColorDialogPrivate; | 45 | class OColorDialogPrivate; |
46 | 46 | ||
47 | /** | ||
48 | * @class OColorDialog | ||
49 | * @brief The OColorDialog class is a copy of QColorDialog for use in Opie. | ||
50 | * | ||
51 | * OColorDialog is a copy of TrollTech's QColorDialog for use in Opie. The default | ||
52 | * build of QT/Embedded used by Opie does not include QColorDialog, so it is provided | ||
53 | * here. It is renamed to prevent conflicts in the event the QColorDialog is included | ||
54 | * at a later date in QP/E. | ||
55 | * | ||
56 | * See http://doc.trolltech.com/2.3/qcolordialog.html for complete documentation of | ||
57 | * QColorDialog. | ||
58 | */ | ||
47 | class Q_EXPORT OColorDialog : public QDialog | 59 | class Q_EXPORT OColorDialog : public QDialog |
48 | { | 60 | { |
49 | Q_OBJECT | 61 | Q_OBJECT |
50 | 62 | ||
51 | public: | 63 | public: |
52 | static QColor getColor( QColor, QWidget *parent=0, const char* name=0 ); // ### 3.0: make const QColor& | 64 | static QColor getColor( QColor, QWidget *parent=0, const char* name=0 ); // ### 3.0: make const QColor& |
53 | static QRgb getRgba( QRgb, bool* ok = 0, | 65 | static QRgb getRgba( QRgb, bool* ok = 0, |
54 | QWidget *parent=0, const char* name=0 ); | 66 | QWidget *parent=0, const char* name=0 ); |
55 | 67 | ||
56 | private: | 68 | private: |
57 | ~OColorDialog(); | 69 | ~OColorDialog(); |
58 | 70 | ||
59 | OColorDialog( QWidget* parent=0, const char* name=0, bool modal=FALSE ); | 71 | OColorDialog( QWidget* parent=0, const char* name=0, bool modal=FALSE ); |
60 | void setColor( QColor ); // ### 3.0: make const QColor& | 72 | void setColor( QColor ); // ### 3.0: make const QColor& |
61 | QColor color() const; | 73 | QColor color() const; |
62 | 74 | ||
63 | private: | 75 | private: |
64 | void setSelectedAlpha( int ); | 76 | void setSelectedAlpha( int ); |
65 | int selectedAlpha() const; | 77 | int selectedAlpha() const; |
66 | private: | 78 | private: |
67 | OColorDialogPrivate *d; | 79 | OColorDialogPrivate *d; |
68 | friend class OColorDialogPrivate; | 80 | friend class OColorDialogPrivate; |
69 | 81 | ||
70 | private:// Disabled copy constructor and operator= | 82 | private:// Disabled copy constructor and operator= |
71 | #if defined(Q_DISABLE_COPY) | 83 | #if defined(Q_DISABLE_COPY) |
72 | OColorDialog( const OColorDialog & ); | 84 | OColorDialog( const OColorDialog & ); |
73 | OColorDialog& operator=( const OColorDialog & ); | 85 | OColorDialog& operator=( const OColorDialog & ); |
74 | #endif | 86 | #endif |
75 | }; | 87 | }; |
76 | 88 | ||
77 | #endif | 89 | #endif |
diff --git a/libopie/colorpopupmenu.cpp b/libopie/colorpopupmenu.cpp index 17e2c0a..510a2ad 100644 --- a/libopie/colorpopupmenu.cpp +++ b/libopie/colorpopupmenu.cpp | |||
@@ -1,165 +1,176 @@ | |||
1 | /********************************************************************** | 1 | /* |
2 | ** ColorPopupMenu | 2 | This file is part of the Opie Project |
3 | ** | 3 | |
4 | ** Popup menu for selecting colors | 4 | Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net> |
5 | ** | 5 | Dan Williams <williamsdr@acm.org> |
6 | ** Based on colorpanel by S. Prud'homme <prudhomme@laposte.net> | 6 | =. |
7 | ** | 7 | .=l. |
8 | ** Copyright (C) 2002, Dan Williams | 8 | .>+-= |
9 | ** williamsdr@acm.org | 9 | _;:, .> :=|. This program is free software; you can |
10 | ** http://draknor.net | 10 | .> <`_, > . <= redistribute it and/or modify it under |
11 | ** | 11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
12 | ** This file may be distributed and/or modified under the terms of the | 12 | .="- .-=="i, .._ License as published by the Free Software |
13 | ** GNU General Public License version 2 as published by the Free Software | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ** Foundation and appearing in the file LICENSE.GPL included in the | 14 | ._= =} : or (at your option) any later version. |
15 | ** packaging of this file. | 15 | .%`+i> _;_. |
16 | ** | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 18 | : .. .:, . . . without even the implied warranty of |
19 | ** | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | **********************************************************************/ | 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 | */ | ||
21 | 32 | ||
22 | #include "colorpopupmenu.h" | 33 | #include "colorpopupmenu.h" |
23 | #include "colordialog.h" | 34 | #include "colordialog.h" |
24 | 35 | ||
25 | #include <qaction.h> | 36 | #include <qaction.h> |
26 | #include <qlayout.h> | 37 | #include <qlayout.h> |
27 | #include <qpainter.h> | 38 | #include <qpainter.h> |
28 | 39 | ||
29 | ColorPanelButton::ColorPanelButton( const QColor& color, QWidget* parent, const char* name ) | 40 | ColorPanelButton::ColorPanelButton( const QColor& color, QWidget* parent, const char* name ) |
30 | : QFrame( parent, name ) | 41 | : QFrame( parent, name ) |
31 | { | 42 | { |
32 | m_color = color; | 43 | m_color = color; |
33 | 44 | ||
34 | setFixedSize( 16, 16 ); | 45 | setFixedSize( 16, 16 ); |
35 | setActive( FALSE ); | 46 | setActive( FALSE ); |
36 | } | 47 | } |
37 | 48 | ||
38 | ColorPanelButton::~ColorPanelButton() | 49 | ColorPanelButton::~ColorPanelButton() |
39 | { | 50 | { |
40 | } | 51 | } |
41 | 52 | ||
42 | void ColorPanelButton::setActive( bool active ) | 53 | void ColorPanelButton::setActive( bool active ) |
43 | { | 54 | { |
44 | m_active = active; | 55 | m_active = active; |
45 | 56 | ||
46 | if ( m_active ) { | 57 | if ( m_active ) { |
47 | setFrameStyle( Panel | Sunken ); | 58 | setFrameStyle( Panel | Sunken ); |
48 | } else { | 59 | } else { |
49 | setFrameStyle( NoFrame ); | 60 | setFrameStyle( NoFrame ); |
50 | } | 61 | } |
51 | } | 62 | } |
52 | 63 | ||
53 | void ColorPanelButton::enterEvent( QEvent* e ) | 64 | void ColorPanelButton::enterEvent( QEvent* e ) |
54 | { | 65 | { |
55 | Q_UNUSED( e ) | 66 | Q_UNUSED( e ) |
56 | 67 | ||
57 | if ( !m_active ) { | 68 | if ( !m_active ) { |
58 | setFrameStyle( Panel | Sunken ); | 69 | setFrameStyle( Panel | Sunken ); |
59 | } | 70 | } |
60 | } | 71 | } |
61 | 72 | ||
62 | void ColorPanelButton::leaveEvent( QEvent* e ) | 73 | void ColorPanelButton::leaveEvent( QEvent* e ) |
63 | { | 74 | { |
64 | Q_UNUSED( e ) | 75 | Q_UNUSED( e ) |
65 | 76 | ||
66 | if ( !m_active ) { | 77 | if ( !m_active ) { |
67 | setFrameStyle( NoFrame ); | 78 | setFrameStyle( NoFrame ); |
68 | } | 79 | } |
69 | } | 80 | } |
70 | 81 | ||
71 | void ColorPanelButton::paintEvent( QPaintEvent* e ) | 82 | void ColorPanelButton::paintEvent( QPaintEvent* e ) |
72 | { | 83 | { |
73 | QFrame::paintEvent( e ); | 84 | QFrame::paintEvent( e ); |
74 | 85 | ||
75 | QPainter painter; | 86 | QPainter painter; |
76 | painter.begin( this ); | 87 | painter.begin( this ); |
77 | painter.fillRect( 2, 2, 12, 12, m_color ); | 88 | painter.fillRect( 2, 2, 12, 12, m_color ); |
78 | painter.setPen( Qt::black ); | 89 | painter.setPen( Qt::black ); |
79 | painter.drawRect( 2, 2, 12, 12 ); | 90 | painter.drawRect( 2, 2, 12, 12 ); |
80 | painter.end(); | 91 | painter.end(); |
81 | } | 92 | } |
82 | 93 | ||
83 | void ColorPanelButton::mouseReleaseEvent( QMouseEvent* e ) | 94 | void ColorPanelButton::mouseReleaseEvent( QMouseEvent* e ) |
84 | { | 95 | { |
85 | Q_UNUSED( e ) | 96 | Q_UNUSED( e ) |
86 | 97 | ||
87 | emit selected( m_color ); | 98 | emit selected( m_color ); |
88 | } | 99 | } |
89 | 100 | ||
90 | ColorPopupMenu::ColorPopupMenu( const QColor& color, QWidget* parent, const char* name ) | 101 | ColorPopupMenu::ColorPopupMenu( const QColor& color, QWidget* parent, const char* name ) |
91 | : QPopupMenu( parent, name ) | 102 | : QPopupMenu( parent, name ) |
92 | { | 103 | { |
93 | m_color = color; | 104 | m_color = color; |
94 | 105 | ||
95 | colorPanel = new QWidget( this ); | 106 | colorPanel = new QWidget( this ); |
96 | 107 | ||
97 | colorLayout = new QGridLayout(colorPanel, 5, 6); | 108 | colorLayout = new QGridLayout(colorPanel, 5, 6); |
98 | 109 | ||
99 | addColor(QColor(255, 255, 255), 0, 1); | 110 | addColor(QColor(255, 255, 255), 0, 1); |
100 | addColor(QColor(192, 192, 192), 0, 2); | 111 | addColor(QColor(192, 192, 192), 0, 2); |
101 | addColor(QColor(128, 128, 128), 0, 3); | 112 | addColor(QColor(128, 128, 128), 0, 3); |
102 | addColor(QColor(64, 64, 64), 0, 4); | 113 | addColor(QColor(64, 64, 64), 0, 4); |
103 | addColor(QColor(0, 0, 0), 0, 5); | 114 | addColor(QColor(0, 0, 0), 0, 5); |
104 | 115 | ||
105 | addColor(QColor(255, 0, 0), 1, 0); | 116 | addColor(QColor(255, 0, 0), 1, 0); |
106 | addColor(QColor(255, 128, 0), 1, 1); | 117 | addColor(QColor(255, 128, 0), 1, 1); |
107 | addColor(QColor(255, 255, 0), 1, 2); | 118 | addColor(QColor(255, 255, 0), 1, 2); |
108 | addColor(QColor(128, 255, 0), 1, 3); | 119 | addColor(QColor(128, 255, 0), 1, 3); |
109 | addColor(QColor(0, 255, 0), 1, 4); | 120 | addColor(QColor(0, 255, 0), 1, 4); |
110 | addColor(QColor(0, 255, 128), 1, 5); | 121 | addColor(QColor(0, 255, 128), 1, 5); |
111 | 122 | ||
112 | addColor(QColor(128, 0, 0), 2, 0); | 123 | addColor(QColor(128, 0, 0), 2, 0); |
113 | addColor(QColor(128, 64, 0), 2, 1); | 124 | addColor(QColor(128, 64, 0), 2, 1); |
114 | addColor(QColor(128, 128, 0), 2, 2); | 125 | addColor(QColor(128, 128, 0), 2, 2); |
115 | addColor(QColor(64, 128, 0), 2, 3); | 126 | addColor(QColor(64, 128, 0), 2, 3); |
116 | addColor(QColor(0, 128, 0), 2, 4); | 127 | addColor(QColor(0, 128, 0), 2, 4); |
117 | addColor(QColor(0, 128, 64), 2, 5); | 128 | addColor(QColor(0, 128, 64), 2, 5); |
118 | 129 | ||
119 | addColor(QColor(0, 255, 255), 3, 0); | 130 | addColor(QColor(0, 255, 255), 3, 0); |
120 | addColor(QColor(0, 128, 255), 3, 1); | 131 | addColor(QColor(0, 128, 255), 3, 1); |
121 | addColor(QColor(0, 0, 255), 3, 2); | 132 | addColor(QColor(0, 0, 255), 3, 2); |
122 | addColor(QColor(128, 0, 255), 3, 3); | 133 | addColor(QColor(128, 0, 255), 3, 3); |
123 | addColor(QColor(255, 0, 255), 3, 4); | 134 | addColor(QColor(255, 0, 255), 3, 4); |
124 | addColor(QColor(255, 0, 128), 3, 5); | 135 | addColor(QColor(255, 0, 128), 3, 5); |
125 | 136 | ||
126 | addColor(QColor(0, 128, 128), 4, 0); | 137 | addColor(QColor(0, 128, 128), 4, 0); |
127 | addColor(QColor(0, 64, 128), 4, 1); | 138 | addColor(QColor(0, 64, 128), 4, 1); |
128 | addColor(QColor(0, 0, 128), 4, 2); | 139 | addColor(QColor(0, 0, 128), 4, 2); |
129 | addColor(QColor(64, 0, 128), 4, 3); | 140 | addColor(QColor(64, 0, 128), 4, 3); |
130 | addColor(QColor(128, 0, 128), 4, 4); | 141 | addColor(QColor(128, 0, 128), 4, 4); |
131 | addColor(QColor(128, 0, 64), 4, 5); | 142 | addColor(QColor(128, 0, 64), 4, 5); |
132 | 143 | ||
133 | insertItem( colorPanel ); | 144 | insertItem( colorPanel ); |
134 | insertSeparator(); | 145 | insertSeparator(); |
135 | QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" ); | 146 | QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" ); |
136 | connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) ); | 147 | connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) ); |
137 | chooseColorAction->addTo( this ); | 148 | chooseColorAction->addTo( this ); |
138 | activateItemAt( 0 ); | 149 | activateItemAt( 0 ); |
139 | } | 150 | } |
140 | 151 | ||
141 | ColorPopupMenu::~ColorPopupMenu() | 152 | ColorPopupMenu::~ColorPopupMenu() |
142 | { | 153 | { |
143 | } | 154 | } |
144 | 155 | ||
145 | void ColorPopupMenu::addColor( const QColor& color, int row, int col ) | 156 | void ColorPopupMenu::addColor( const QColor& color, int row, int col ) |
146 | { | 157 | { |
147 | ColorPanelButton* panelButton = new ColorPanelButton( color, colorPanel ); | 158 | ColorPanelButton* panelButton = new ColorPanelButton( color, colorPanel ); |
148 | connect( panelButton, SIGNAL( selected( const QColor& ) ), this, SLOT( buttonSelected( const QColor& ) ) ); | 159 | connect( panelButton, SIGNAL( selected( const QColor& ) ), this, SLOT( buttonSelected( const QColor& ) ) ); |
149 | colorLayout->addWidget( panelButton, row, col ); | 160 | colorLayout->addWidget( panelButton, row, col ); |
150 | } | 161 | } |
151 | 162 | ||
152 | void ColorPopupMenu::buttonSelected( const QColor& color ) | 163 | void ColorPopupMenu::buttonSelected( const QColor& color ) |
153 | { | 164 | { |
154 | m_color = color; | 165 | m_color = color; |
155 | emit colorSelected( color ); | 166 | emit colorSelected( color ); |
156 | hide(); | 167 | hide(); |
157 | } | 168 | } |
158 | 169 | ||
159 | void ColorPopupMenu::moreColorClicked() | 170 | void ColorPopupMenu::moreColorClicked() |
160 | { | 171 | { |
161 | QColor color = OColorDialog::getColor( m_color ); | 172 | QColor color = OColorDialog::getColor( m_color ); |
162 | m_color = color; | 173 | m_color = color; |
163 | emit colorSelected( color ); | 174 | emit colorSelected( color ); |
164 | hide(); | 175 | hide(); |
165 | } | 176 | } |
diff --git a/libopie/colorpopupmenu.h b/libopie/colorpopupmenu.h index 1a6ab08..b0453b2 100644 --- a/libopie/colorpopupmenu.h +++ b/libopie/colorpopupmenu.h | |||
@@ -1,81 +1,254 @@ | |||
1 | /********************************************************************** | 1 | /* |
2 | ** ColorPopupMenu | 2 | This file is part of the Opie Project |
3 | ** | 3 | |
4 | ** Popup menu for selecting colors | 4 | Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net> |
5 | ** | 5 | Dan Williams <williamsdr@acm.org> |
6 | ** Based on colorpanel by S. Prud'homme <prudhomme@laposte.net> | 6 | =. |
7 | ** | 7 | .=l. |
8 | ** Copyright (C) 2002, Dan Williams | 8 | .>+-= |
9 | ** williamsdr@acm.org | 9 | _;:, .> :=|. This program is free software; you can |
10 | ** http://draknor.net | 10 | .> <`_, > . <= redistribute it and/or modify it under |
11 | ** | 11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
12 | ** This file may be distributed and/or modified under the terms of the | 12 | .="- .-=="i, .._ License as published by the Free Software |
13 | ** GNU General Public License version 2 as published by the Free Software | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ** Foundation and appearing in the file LICENSE.GPL included in the | 14 | ._= =} : or (at your option) any later version. |
15 | ** packaging of this file. | 15 | .%`+i> _;_. |
16 | ** | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 18 | : .. .:, . . . without even the implied warranty of |
19 | ** | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | **********************************************************************/ | 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 | */ | ||
21 | 32 | ||
22 | #ifndef COLORPOPUPMENU_H | 33 | #ifndef COLORPOPUPMENU_H |
23 | #define COLORPOPUPMENU_H | 34 | #define COLORPOPUPMENU_H |
24 | 35 | ||
25 | #include <qframe.h> | 36 | #include <qframe.h> |
26 | #include <qpopupmenu.h> | 37 | #include <qpopupmenu.h> |
27 | 38 | ||
28 | class QWidget; | 39 | class QWidget; |
29 | class QGridLayout; | 40 | class QGridLayout; |
30 | 41 | ||
42 | /** | ||
43 | * @class ColorPanelButton | ||
44 | * @brief The ColorPanelButton class provides a button for color selection. | ||
45 | * | ||
46 | * @see ColorPopupMenu | ||
47 | * | ||
48 | * The ColorPanelButton class provides a button for color selection. The button | ||
49 | * is drawn with the desired color and no border. This class is used internally | ||
50 | * by the ColorPopupMenu class to displaying colors in its menu. | ||
51 | */ | ||
31 | class ColorPanelButton : public QFrame | 52 | class ColorPanelButton : public QFrame |
32 | { | 53 | { |
33 | Q_OBJECT | 54 | Q_OBJECT |
34 | 55 | ||
35 | public: | 56 | public: |
57 | |||
58 | /** | ||
59 | * @fn ColorPanelButton( const QColor& color, QWidget* parent = 0, const char* name = 0 ) | ||
60 | * @brief Object constructor. | ||
61 | * | ||
62 | * @param color Desired color. | ||
63 | * @param parent Pointer to parent of this control. | ||
64 | * @param name Name of control. | ||
65 | * | ||
66 | * Constructs a new ColorPanelButton control with parent, name and desired color. | ||
67 | */ | ||
36 | ColorPanelButton(const QColor& color, QWidget* parent = 0, const char* name = 0); | 68 | ColorPanelButton(const QColor& color, QWidget* parent = 0, const char* name = 0); |
69 | |||
70 | /** | ||
71 | * @fn ~ColorPanelButton() | ||
72 | * @brief Object destructor. | ||
73 | */ | ||
37 | ~ColorPanelButton(); | 74 | ~ColorPanelButton(); |
38 | 75 | ||
76 | /** | ||
77 | * @fn setActive( bool active ) | ||
78 | * @brief Sets button selection state. | ||
79 | * | ||
80 | * @param active Boolean indicator of new button state. | ||
81 | * | ||
82 | * Changes button selection state. If button is selected, a highlighted border | ||
83 | * is drawn. | ||
84 | */ | ||
39 | void setActive(bool active); | 85 | void setActive(bool active); |
40 | 86 | ||
87 | /** | ||
88 | * @fn enterEvent( QEvent* e ) | ||
89 | * @brief Reimplemented for internal reasons. | ||
90 | * | ||
91 | * @param e Event currently being processed. | ||
92 | * | ||
93 | * Reimplemented to ensure correct display of button based on whether it is | ||
94 | * active or not. | ||
95 | */ | ||
41 | void enterEvent(QEvent* e); | 96 | void enterEvent(QEvent* e); |
97 | |||
98 | /** | ||
99 | * @fn leaveEvent( QEvent* e ) | ||
100 | * @brief Reimplemented for internal reasons. | ||
101 | * | ||
102 | * @param e Event currently being processed. | ||
103 | * | ||
104 | * Reimplemented to ensure correct display of button based on whether it is | ||
105 | * active or not. | ||
106 | */ | ||
42 | void leaveEvent(QEvent* e); | 107 | void leaveEvent(QEvent* e); |
108 | |||
109 | /** | ||
110 | * @fn paintEvent( QEvent* e ) | ||
111 | * @brief Reimplemented for internal reasons. | ||
112 | * | ||
113 | * @param e Event currently being processed. | ||
114 | * | ||
115 | * Reimplemented to ensure correct display of button. | ||
116 | */ | ||
43 | void paintEvent(QPaintEvent* e); | 117 | void paintEvent(QPaintEvent* e); |
118 | |||
119 | /** | ||
120 | * @fn mouseReleaseEvent( QMouseEvent* e ) | ||
121 | * @brief Slot executed when button is pressed. | ||
122 | * | ||
123 | * @param e Mouse event currently being processed. | ||
124 | * | ||
125 | * @see selected() | ||
126 | * | ||
127 | * This slot executes when the button has been pressed. It emits the selected | ||
128 | * signal as notification that it has been pressed. | ||
129 | */ | ||
44 | void mouseReleaseEvent(QMouseEvent* e); | 130 | void mouseReleaseEvent(QMouseEvent* e); |
45 | 131 | ||
46 | signals: | 132 | signals: |
133 | |||
134 | /** | ||
135 | * @fn selected( const QColor& color ) | ||
136 | * @brief Signal to indicate button has been pressed. | ||
137 | * | ||
138 | * @param color Button color. | ||
139 | * | ||
140 | * This signal is emitted when the button is pressed. It provides the color | ||
141 | * associated to this button. | ||
142 | */ | ||
47 | void selected(const QColor&); | 143 | void selected(const QColor&); |
48 | 144 | ||
49 | private: | 145 | private: |
50 | QColor m_color; | 146 | QColor m_color; |
51 | bool m_active : 1; | 147 | bool m_active : 1; |
52 | class ColorPanelButtonPrivate; | 148 | class ColorPanelButtonPrivate; |
53 | ColorPanelButtonPrivate *d; | 149 | ColorPanelButtonPrivate *d; |
54 | }; | 150 | }; |
55 | 151 | ||
152 | /** | ||
153 | * @class ColorPopupMenu | ||
154 | * @brief The ColorPopupMenu class provides a small color selection | ||
155 | * popup menu. | ||
156 | * | ||
157 | * ColorPopupMenu is a derivation of TrollTech's QPopupMenu and provides | ||
158 | * a small color selection popup menu which can be attached to another control | ||
159 | * such as a toolbar button of menu item. | ||
160 | * | ||
161 | * The popup menu displays 30 default colors available in a grid, and also | ||
162 | * includes an option at the bottom to display a color selection dialog box for | ||
163 | * finer color control. | ||
164 | */ | ||
56 | class ColorPopupMenu : public QPopupMenu | 165 | class ColorPopupMenu : public QPopupMenu |
57 | { | 166 | { |
58 | Q_OBJECT | 167 | Q_OBJECT |
59 | 168 | ||
60 | public: | 169 | public: |
170 | |||
171 | /** | ||
172 | * @fn ColorPopupMenu( const QColor& color, QWidget* parent = 0, const char* name = 0 ) | ||
173 | * @brief Object constructor. | ||
174 | * | ||
175 | * @param color Initial color selected in menu. | ||
176 | * @param parent Pointer to parent of this control. | ||
177 | * @param name Name of control. | ||
178 | * | ||
179 | * Constructs a new ColorPopupMenu control with parent, name and initial color selected. | ||
180 | */ | ||
61 | ColorPopupMenu( const QColor& color, QWidget* parent = 0, const char* name = 0 ); | 181 | ColorPopupMenu( const QColor& color, QWidget* parent = 0, const char* name = 0 ); |
182 | |||
183 | /** | ||
184 | * @fn ~ColorPopupMenu() | ||
185 | * @brief Object destructor. | ||
186 | */ | ||
62 | ~ColorPopupMenu(); | 187 | ~ColorPopupMenu(); |
63 | 188 | ||
64 | private: | 189 | private: |
65 | class ColorPopupMenuPrivate; | 190 | class ColorPopupMenuPrivate; |
66 | ColorPopupMenuPrivate *d; | 191 | ColorPopupMenuPrivate *d; |
67 | QColor m_color; | 192 | QColor m_color; |
68 | QWidget* colorPanel; | 193 | QWidget* colorPanel; |
69 | QGridLayout* colorLayout; | 194 | QGridLayout* colorLayout; |
70 | 195 | ||
196 | /** | ||
197 | * @fn addColor( const QColor& color, int row, int col ) | ||
198 | * @brief Adds color selection option to popup menu. | ||
199 | * | ||
200 | * @param color Color to be displayed in menu. | ||
201 | * @param row Row where color is to appear in menu. | ||
202 | * @param col Column where color is to appear in menu. | ||
203 | * | ||
204 | * Adds a color selection option to popup menu. Used internally when | ||
205 | * initially constructing the menu control. | ||
206 | */ | ||
71 | void addColor( const QColor& color, int row, int col ); | 207 | void addColor( const QColor& color, int row, int col ); |
72 | 208 | ||
73 | signals: | 209 | signals: |
210 | |||
211 | /** | ||
212 | * @fn colorSelected( const QColor& color ) | ||
213 | * @brief Signal to indicate color chosen from the menu. | ||
214 | * | ||
215 | * @param color Color selected from the menu. | ||
216 | * | ||
217 | * This signal is emitted when a color has been selected either directly from | ||
218 | * the menu, or chosen from the color selection dialog. | ||
219 | */ | ||
74 | void colorSelected( const QColor& color ); | 220 | void colorSelected( const QColor& color ); |
75 | 221 | ||
76 | protected slots: | 222 | protected slots: |
223 | |||
224 | /** | ||
225 | * @fn buttonSelected( const QColor& color ) | ||
226 | * @brief Slot to process selected color. | ||
227 | * | ||
228 | * @param color Color selected from the menu. | ||
229 | * | ||
230 | * @see colorSelected() | ||
231 | * | ||
232 | * This slot executes when a color has been selected from the menu. It performs | ||
233 | * two functions: | ||
234 | * - Emit the colorSelected signal with the color selected. | ||
235 | * - Hide the menu. | ||
236 | */ | ||
77 | void buttonSelected( const QColor& color ); | 237 | void buttonSelected( const QColor& color ); |
238 | |||
239 | /** | ||
240 | * @fn moreColorClicked() | ||
241 | * @brief Slot to process display color selection dialog. | ||
242 | * | ||
243 | * @see colorSelected() | ||
244 | * | ||
245 | * This slot executes when the 'More...' option is selected at the bottom of the menu. | ||
246 | * It performs the following functions: | ||
247 | * - Constructs and executes a OColorDialog to allow finer color selection. | ||
248 | * - Emit the colorSelected signal with the color selected. | ||
249 | * - Hide the menu. | ||
250 | */ | ||
78 | void moreColorClicked(); | 251 | void moreColorClicked(); |
79 | }; | 252 | }; |
80 | 253 | ||
81 | #endif // COLORPOPUPMENUANEL_H | 254 | #endif // COLORPOPUPMENUANEL_H |