summaryrefslogtreecommitdiffabout
path: root/kaddressbook/views/colorlistbox.cpp
Unidiff
Diffstat (limited to 'kaddressbook/views/colorlistbox.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/views/colorlistbox.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/kaddressbook/views/colorlistbox.cpp b/kaddressbook/views/colorlistbox.cpp
index c243fa0..7386207 100644
--- a/kaddressbook/views/colorlistbox.cpp
+++ b/kaddressbook/views/colorlistbox.cpp
@@ -11,91 +11,96 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * 18 *
19 */ 19 */
20 20
21#include <qpainter.h> 21#include <qpainter.h>
22 22
23#include <kcolordialog.h> 23#include <kcolordialog.h>
24 24
25#ifndef KAB_EMBEDDED 25#ifndef KAB_EMBEDDED
26#include <kcolordrag.h> 26#include <kcolordrag.h>
27#endif //KAB_EMBEDDED 27#endif //KAB_EMBEDDED
28 28
29#include "colorlistbox.h" 29#include "colorlistbox.h"
30 30
31ColorListBox::ColorListBox( QWidget *parent, const char *name, WFlags f ) 31ColorListBox::ColorListBox( QWidget *parent, const char *name, WFlags f )
32 :KListBox( parent, name, f ), mCurrentOnDragEnter(-1) 32 :KListBox( parent, name, f ), mCurrentOnDragEnter(-1)
33{ 33{
34 connect( this, SIGNAL(selected(int)), this, SLOT(newColor(int)) ); 34 connect( this, SIGNAL(selected(int)), this, SLOT(newColor(int)) );
35 connect( this, SIGNAL(clicked(QListBoxItem *)), this, SLOT(slotNewColor(QListBoxItem *)) );
35 setAcceptDrops( true); 36 setAcceptDrops( true);
36} 37}
37 38
38 39
39void ColorListBox::setEnabled( bool state ) 40void ColorListBox::setEnabled( bool state )
40{ 41{
41 if( state == isEnabled() ) 42 if( state == isEnabled() )
42 { 43 {
43 return; 44 return;
44 } 45 }
45 46
46 QListBox::setEnabled( state ); 47 QListBox::setEnabled( state );
47 for( uint i=0; i<count(); i++ ) 48 for( uint i=0; i<count(); i++ )
48 { 49 {
49 updateItem( i ); 50 updateItem( i );
50 } 51 }
51} 52}
52 53
53 54
54void ColorListBox::setColor( uint index, const QColor &color ) 55void ColorListBox::setColor( uint index, const QColor &color )
55{ 56{
56 if( index < count() ) 57 if( index < count() )
57 { 58 {
58 ColorListItem *colorItem = (ColorListItem*)item(index); 59 ColorListItem *colorItem = (ColorListItem*)item(index);
59 colorItem->setColor(color); 60 colorItem->setColor(color);
60 updateItem( colorItem ); 61 updateItem( colorItem );
61 } 62 }
62} 63}
63 64
64 65
65QColor ColorListBox::color( uint index ) const 66QColor ColorListBox::color( uint index ) const
66{ 67{
67 if( index < count() ) 68 if( index < count() )
68 { 69 {
69 ColorListItem *colorItem = (ColorListItem*)item(index); 70 ColorListItem *colorItem = (ColorListItem*)item(index);
70 return( colorItem->color() ); 71 return( colorItem->color() );
71 } 72 }
72 else 73 else
73 { 74 {
74 return( black ); 75 return( black );
75 } 76 }
76} 77}
77 78void ColorListBox::slotNewColor(QListBoxItem * i)
79{
80 if ( i )
81 newColor( index( i ) );
82}
78 83
79void ColorListBox::newColor( int index ) 84void ColorListBox::newColor( int index )
80{ 85{
81 if( isEnabled() == false ) 86 if( isEnabled() == false )
82 { 87 {
83 return; 88 return;
84 } 89 }
85 90
86 if( (uint)index < count() ) 91 if( (uint)index < count() )
87 { 92 {
88 QColor c = color( index ); 93 QColor c = color( index );
89#ifndef KAB_EMBEDDED 94#ifndef KAB_EMBEDDED
90 if( KColorDialog::getColor( c, this ) != QDialog::Rejected ) 95 if( KColorDialog::getColor( c, this ) != QDialog::Rejected )
91 { 96 {
92 setColor( index, c ); 97 setColor( index, c );
93 } 98 }
94#else //KAB_EMBEDDED 99#else //KAB_EMBEDDED
95 KColorDialog* k = new KColorDialog( this ); 100 KColorDialog* k = new KColorDialog( this );
96 k->setColor( c ); 101 k->setColor( c );
97 int res = k->exec(); 102 int res = k->exec();
98 if ( res ) { 103 if ( res ) {
99 setColor( index, k->getColor() ); 104 setColor( index, k->getColor() );
100 } 105 }
101 delete k; 106 delete k;