author | zautrix <zautrix> | 2005-04-02 12:16:34 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-02 12:16:34 (UTC) |
commit | 997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe (patch) (unidiff) | |
tree | f788b37459574b5cea0d2ab874882c6a396c240d /kaddressbook/views/colorlistbox.cpp | |
parent | e0d51120d2f0c178115746e0c1357af40f95bc77 (diff) | |
download | kdepimpi-997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe.zip kdepimpi-997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe.tar.gz kdepimpi-997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe.tar.bz2 |
more fixes
Diffstat (limited to 'kaddressbook/views/colorlistbox.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/views/colorlistbox.cpp | 7 |
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 | |||
@@ -1,173 +1,178 @@ | |||
1 | /* | 1 | /* |
2 | * kmail: KDE mail client | 2 | * kmail: KDE mail client |
3 | * This file: Copyright (C) 2000 Espen Sand, espen@kde.org | 3 | * This file: Copyright (C) 2000 Espen Sand, espen@kde.org |
4 | * | 4 | * |
5 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or | 7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. | 8 | * (at your option) any later version. |
9 | * | 9 | * |
10 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, |
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 | ||
31 | ColorListBox::ColorListBox( QWidget *parent, const char *name, WFlags f ) | 31 | ColorListBox::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 | ||
39 | void ColorListBox::setEnabled( bool state ) | 40 | void 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 | ||
54 | void ColorListBox::setColor( uint index, const QColor &color ) | 55 | void 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 | ||
65 | QColor ColorListBox::color( uint index ) const | 66 | QColor 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 | 78 | void ColorListBox::slotNewColor(QListBoxItem * i) | |
79 | { | ||
80 | if ( i ) | ||
81 | newColor( index( i ) ); | ||
82 | } | ||
78 | 83 | ||
79 | void ColorListBox::newColor( int index ) | 84 | void 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; |
102 | #endif //KAB_EMBEDDED | 107 | #endif //KAB_EMBEDDED |
103 | 108 | ||
104 | } | 109 | } |
105 | } | 110 | } |
106 | 111 | ||
107 | 112 | ||
108 | void ColorListBox::dragEnterEvent( QDragEnterEvent *e ) | 113 | void ColorListBox::dragEnterEvent( QDragEnterEvent *e ) |
109 | { | 114 | { |
110 | #ifndef KAB_EMBEDDED | 115 | #ifndef KAB_EMBEDDED |
111 | if( KColorDrag::canDecode(e) && isEnabled() ) | 116 | if( KColorDrag::canDecode(e) && isEnabled() ) |
112 | { | 117 | { |
113 | mCurrentOnDragEnter = currentItem(); | 118 | mCurrentOnDragEnter = currentItem(); |
114 | e->accept( true ); | 119 | e->accept( true ); |
115 | } | 120 | } |
116 | else | 121 | else |
117 | { | 122 | { |
118 | mCurrentOnDragEnter = -1; | 123 | mCurrentOnDragEnter = -1; |
119 | e->accept( false ); | 124 | e->accept( false ); |
120 | } | 125 | } |
121 | #else //KAB_EMBEDDED | 126 | #else //KAB_EMBEDDED |
122 | qDebug("ColorListBox::dragEnterEvent drag&drop currently not supported"); | 127 | qDebug("ColorListBox::dragEnterEvent drag&drop currently not supported"); |
123 | #endif //KAB_EMBEDDED | 128 | #endif //KAB_EMBEDDED |
124 | 129 | ||
125 | } | 130 | } |
126 | 131 | ||
127 | 132 | ||
128 | void ColorListBox::dragLeaveEvent( QDragLeaveEvent * ) | 133 | void ColorListBox::dragLeaveEvent( QDragLeaveEvent * ) |
129 | { | 134 | { |
130 | #ifndef KAB_EMBEDDED | 135 | #ifndef KAB_EMBEDDED |
131 | 136 | ||
132 | if( mCurrentOnDragEnter != -1 ) | 137 | if( mCurrentOnDragEnter != -1 ) |
133 | { | 138 | { |
134 | setCurrentItem( mCurrentOnDragEnter ); | 139 | setCurrentItem( mCurrentOnDragEnter ); |
135 | mCurrentOnDragEnter = -1; | 140 | mCurrentOnDragEnter = -1; |
136 | } | 141 | } |
137 | #else //KAB_EMBEDDED | 142 | #else //KAB_EMBEDDED |
138 | qDebug("ColorListBox::dragLeaveEvent drag&drop currently not supported"); | 143 | qDebug("ColorListBox::dragLeaveEvent drag&drop currently not supported"); |
139 | #endif //KAB_EMBEDDED | 144 | #endif //KAB_EMBEDDED |
140 | } | 145 | } |
141 | 146 | ||
142 | 147 | ||
143 | void ColorListBox::dragMoveEvent( QDragMoveEvent *e ) | 148 | void ColorListBox::dragMoveEvent( QDragMoveEvent *e ) |
144 | { | 149 | { |
145 | #ifndef KAB_EMBEDDED | 150 | #ifndef KAB_EMBEDDED |
146 | if( KColorDrag::canDecode(e) && isEnabled() ) | 151 | if( KColorDrag::canDecode(e) && isEnabled() ) |
147 | { | 152 | { |
148 | ColorListItem *item = (ColorListItem*)itemAt( e->pos() ); | 153 | ColorListItem *item = (ColorListItem*)itemAt( e->pos() ); |
149 | if( item != 0 ) | 154 | if( item != 0 ) |
150 | { | 155 | { |
151 | setCurrentItem ( item ); | 156 | setCurrentItem ( item ); |
152 | } | 157 | } |
153 | } | 158 | } |
154 | #else //KAB_EMBEDDED | 159 | #else //KAB_EMBEDDED |
155 | qDebug("ColorListBox::dragMoveEvent drag&drop currently not supported"); | 160 | qDebug("ColorListBox::dragMoveEvent drag&drop currently not supported"); |
156 | #endif //KAB_EMBEDDED | 161 | #endif //KAB_EMBEDDED |
157 | 162 | ||
158 | } | 163 | } |
159 | 164 | ||
160 | 165 | ||
161 | void ColorListBox::dropEvent( QDropEvent *e ) | 166 | void ColorListBox::dropEvent( QDropEvent *e ) |
162 | { | 167 | { |
163 | #ifndef KAB_EMBEDDED | 168 | #ifndef KAB_EMBEDDED |
164 | QColor color; | 169 | QColor color; |
165 | if( KColorDrag::decode( e, color ) ) | 170 | if( KColorDrag::decode( e, color ) ) |
166 | { | 171 | { |
167 | int index = currentItem(); | 172 | int index = currentItem(); |
168 | if( index != -1 ) | 173 | if( index != -1 ) |
169 | { | 174 | { |
170 | ColorListItem *colorItem = (ColorListItem*)item(index); | 175 | ColorListItem *colorItem = (ColorListItem*)item(index); |
171 | colorItem->setColor(color); | 176 | colorItem->setColor(color); |
172 | triggerUpdate( false ); // Redraw item | 177 | triggerUpdate( false ); // Redraw item |
173 | } | 178 | } |