summaryrefslogtreecommitdiff
path: root/libqtaux
Unidiff
Diffstat (limited to 'libqtaux') (more/less context) (ignore whitespace changes)
-rw-r--r--libqtaux/libqtaux.pro6
-rw-r--r--libqtaux/ocolorbutton.cpp150
-rw-r--r--libqtaux/ocolorbutton.h80
-rw-r--r--libqtaux/ocolorpopupmenu.cpp3
-rw-r--r--libqtaux/ocolorpopupmenu.h11
5 files changed, 246 insertions, 4 deletions
diff --git a/libqtaux/libqtaux.pro b/libqtaux/libqtaux.pro
index 2f7aa91..56ccc65 100644
--- a/libqtaux/libqtaux.pro
+++ b/libqtaux/libqtaux.pro
@@ -5,14 +5,16 @@ HEADERS = qcolordialog.h \
5 qsplitter.h \ 5 qsplitter.h \
6 qinputdialog.h \ 6 qinputdialog.h \
7 \ 7 \
8 ocolorpopupmenu.h 8 ocolorpopupmenu.h \
9 ocolorbutton.h
9 10
10 11
11SOURCES = qcolordialog.cpp \ 12SOURCES = qcolordialog.cpp \
12 qsplitter.cpp \ 13 qsplitter.cpp \
13 qinputdialog.cpp \ 14 qinputdialog.cpp \
14 \ 15 \
15 ocolorpopupmenu.cpp 16 ocolorpopupmenu.cpp \
17 ocolorbutton.cpp
16 18
17TARGET = qtaux2 19TARGET = qtaux2
18INCLUDEPATH += $(OPIEDIR)/include 20INCLUDEPATH += $(OPIEDIR)/include
diff --git a/libqtaux/ocolorbutton.cpp b/libqtaux/ocolorbutton.cpp
new file mode 100644
index 0000000..d2ad873
--- a/dev/null
+++ b/libqtaux/ocolorbutton.cpp
@@ -0,0 +1,150 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Robert Griebl <sandman@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "ocolorpopupmenu.h"
31#include "ocolorbutton.h"
32
33/* OPIE */
34#include <qpe/resource.h>
35
36/* QT */
37#include <qcolor.h>
38#include <qpixmap.h>
39#include <qimage.h>
40
41using namespace Opie;
42
43struct OColorButtonPrivate
44{
45 QPopupMenu *m_menu;
46 QColor m_color;
47};
48
49/**
50 * This concstructs a Color Button with @param color as the start color
51 * It'll use a OColorPopupMenu internally
52 *
53 * @param parent The parent of the Color Button
54 * @param color The color from where to start on
55 * @param name @see QObject
56 */
57OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *name )
58 : QPushButton ( parent, name )
59{
60 d = new OColorButtonPrivate;
61
62 d-> m_menu = new OColorPopupMenu ( color, 0, 0 );
63 setPopup ( d-> m_menu );
64 //setPopupDelay ( 0 );
65 connect ( d-> m_menu, SIGNAL( colorSelected ( const QColor & )), this, SLOT( updateColor ( const QColor & )));
66
67 updateColor ( color );
68
69 QSize s = sizeHint ( ) + QSize ( 12, 0 );
70 setMinimumSize ( s );
71 setMaximumSize ( s. width ( ) * 2, s. height ( ));
72}
73
74/**
75 * This destructs the object
76 */
77OColorButton::~OColorButton ( )
78{
79 delete d;
80}
81
82/**
83 * @return Returns the current color of the button
84 */
85QColor OColorButton::color ( ) const
86{
87 return d-> m_color;
88}
89
90/**
91 * This method sets the color of the button
92 * @param c The color to be set.
93 */
94void OColorButton::setColor ( const QColor &c )
95{
96 updateColor ( c );
97}
98
99/**
100 * @internal
101 */
102void OColorButton::updateColor ( const QColor &c )
103{
104 d-> m_color = c;
105
106 QImage img ( 16, 16, 32 );
107 img. fill ( 0 );
108
109 int r, g, b;
110 c. rgb ( &r, &g, &b );
111
112 int w = img. width ( );
113 int h = img. height ( );
114
115 int dx = w * 20 / 100; // 15%
116 int dy = h * 20 / 100;
117
118 for ( int y = 0; y < h; y++ )
119 {
120 for ( int x = 0; x < w; x++ )
121 {
122 double alpha = 1.0;
123
124 if ( x < dx )
125 alpha *= ( double ( x + 1 ) / dx );
126 else if ( x >= w - dx )
127 alpha *= ( double ( w - x ) / dx );
128 if ( y < dy )
129 alpha *= ( double ( y + 1 ) / dy );
130 else if ( y >= h - dy )
131 alpha *= ( double ( h - y ) / dy );
132
133 int a = int ( alpha * 255.0 );
134 if ( a < 0 )
135 a = 0;
136 if ( a > 255 )
137 a = 255;
138
139 img. setPixel ( x, y, qRgba ( r, g, b, a ));
140 }
141 }
142 img. setAlphaBuffer ( true );
143
144 QPixmap pix;
145 pix. convertFromImage ( img );
146 setPixmap ( pix );
147
148 emit colorSelected ( c );
149}
150
diff --git a/libqtaux/ocolorbutton.h b/libqtaux/ocolorbutton.h
new file mode 100644
index 0000000..ca68f1f
--- a/dev/null
+++ b/libqtaux/ocolorbutton.h
@@ -0,0 +1,80 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Robert Griebl <sandman@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef OCOLORBUTTON_H
31#define OCOLORBUTTON_H
32
33/* QT*/
34#include <qpushbutton.h>
35
36class OColorButtonPrivate;
37class QColor;
38
39namespace Opie
40{
41
42/**
43 *
44 * @short A Button which will show a OColorPopupMenu
45 * @author Robert Griebl ( sandman@handhelds.org )
46 * @version 1.0
47 * @see QPushButton
48 */
49class OColorButton : public QPushButton
50{
51 Q_OBJECT
52public:
53 OColorButton ( QWidget *parent = 0, const QColor & = black, const char *name = 0 );
54 virtual ~OColorButton ( );
55
56 QColor color ( ) const;
57
58signals:
59 /**
60 * emitted when a color gets selected
61 */
62 void colorSelected ( const QColor & );
63
64public slots:
65 virtual void setColor ( const QColor & );
66
67protected slots:
68 /**
69 * @internal
70 */
71 virtual void updateColor ( const QColor & );
72
73private:
74 OColorButtonPrivate *d;
75};
76
77};
78
79#endif
80
diff --git a/libqtaux/ocolorpopupmenu.cpp b/libqtaux/ocolorpopupmenu.cpp
index 6a2321e..6c5f99c 100644
--- a/libqtaux/ocolorpopupmenu.cpp
+++ b/libqtaux/ocolorpopupmenu.cpp
@@ -33,10 +33,13 @@
33#include "ocolorpopupmenu.h" 33#include "ocolorpopupmenu.h"
34#include "qcolordialog.h" 34#include "qcolordialog.h"
35 35
36/* QT */
36#include <qaction.h> 37#include <qaction.h>
37#include <qlayout.h> 38#include <qlayout.h>
38#include <qpainter.h> 39#include <qpainter.h>
39 40
41using namespace Opie;
42
40OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name ) 43OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name )
41 : QFrame( parent, name ) 44 : QFrame( parent, name )
42{ 45{
diff --git a/libqtaux/ocolorpopupmenu.h b/libqtaux/ocolorpopupmenu.h
index 90cfbed..7ab3ca6 100644
--- a/libqtaux/ocolorpopupmenu.h
+++ b/libqtaux/ocolorpopupmenu.h
@@ -30,8 +30,10 @@
30 30
31*/ 31*/
32 32
33#ifndef COLORPOPUPMENU_H 33#ifndef OCOLORPOPUPMENU_H
34#define COLORPOPUPMENU_H 34#define OCOLORPOPUPMENU_H
35
36/* QT */
35 37
36#include <qframe.h> 38#include <qframe.h>
37#include <qpopupmenu.h> 39#include <qpopupmenu.h>
@@ -39,6 +41,9 @@
39class QWidget; 41class QWidget;
40class QGridLayout; 42class QGridLayout;
41 43
44namespace Opie
45{
46
42/** 47/**
43 * @class OColorPanelButton 48 * @class OColorPanelButton
44 * @brief The OColorPanelButton class provides a button for color selection. 49 * @brief The OColorPanelButton class provides a button for color selection.
@@ -252,4 +257,6 @@ protected slots:
252 void moreColorClicked(); 257 void moreColorClicked();
253}; 258};
254 259
260};
261
255#endif // COLORPOPUPMENUANEL_H 262#endif // COLORPOPUPMENUANEL_H