Diffstat (limited to 'kaddressbook/views/colorlistbox.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/views/colorlistbox.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/kaddressbook/views/colorlistbox.cpp b/kaddressbook/views/colorlistbox.cpp index 2bddca6..46a59a1 100644 --- a/kaddressbook/views/colorlistbox.cpp +++ b/kaddressbook/views/colorlistbox.cpp | |||
@@ -1,105 +1,110 @@ | |||
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 | //Added by qt3to4: | ||
23 | #include <QDragEnterEvent> | ||
24 | #include <QDropEvent> | ||
25 | #include <QDragMoveEvent> | ||
26 | #include <QDragLeaveEvent> | ||
22 | 27 | ||
23 | #include <kcolordialog.h> | 28 | #include <kcolordialog.h> |
24 | 29 | ||
25 | #ifndef KAB_EMBEDDED | 30 | #ifndef KAB_EMBEDDED |
26 | #include <kcolordrag.h> | 31 | #include <kcolordrag.h> |
27 | #endif //KAB_EMBEDDED | 32 | #endif //KAB_EMBEDDED |
28 | 33 | ||
29 | #include "colorlistbox.h" | 34 | #include "colorlistbox.h" |
30 | #ifdef DESKTOP_VERSION | 35 | #ifdef DESKTOP_VERSION |
31 | #include <qcolordialog.h> | 36 | #include <qcolordialog.h> |
32 | #endif | 37 | #endif |
33 | 38 | ||
34 | ColorListBox::ColorListBox( QWidget *parent, const char *name, WFlags f ) | 39 | ColorListBox::ColorListBox( QWidget *parent, const char *name, Qt::WFlags f ) |
35 | :KListBox( parent, name, f ), mCurrentOnDragEnter(-1) | 40 | :KListBox( parent, name, f ), mCurrentOnDragEnter(-1) |
36 | { | 41 | { |
37 | connect( this, SIGNAL(selected(int)), this, SLOT(newColor(int)) ); | 42 | connect( this, SIGNAL(selected(int)), this, SLOT(newColor(int)) ); |
38 | connect( this, SIGNAL(clicked(QListBoxItem *)), this, SLOT(slotNewColor(QListBoxItem *)) ); | 43 | connect( this, SIGNAL(clicked(Q3ListBoxItem *)), this, SLOT(slotNewColor(Q3ListBoxItem *)) ); |
39 | setAcceptDrops( true); | 44 | setAcceptDrops( true); |
40 | } | 45 | } |
41 | 46 | ||
42 | 47 | ||
43 | void ColorListBox::setEnabled( bool state ) | 48 | void ColorListBox::setEnabled( bool state ) |
44 | { | 49 | { |
45 | if( state == isEnabled() ) | 50 | if( state == isEnabled() ) |
46 | { | 51 | { |
47 | return; | 52 | return; |
48 | } | 53 | } |
49 | 54 | ||
50 | QListBox::setEnabled( state ); | 55 | Q3ListBox::setEnabled( state ); |
51 | for( uint i=0; i<count(); i++ ) | 56 | for( uint i=0; i<count(); i++ ) |
52 | { | 57 | { |
53 | updateItem( i ); | 58 | updateItem( i ); |
54 | } | 59 | } |
55 | } | 60 | } |
56 | 61 | ||
57 | 62 | ||
58 | void ColorListBox::setColor( uint index, const QColor &color ) | 63 | void ColorListBox::setColor( uint index, const QColor &color ) |
59 | { | 64 | { |
60 | if( index < count() ) | 65 | if( index < count() ) |
61 | { | 66 | { |
62 | ColorListItem *colorItem = (ColorListItem*)item(index); | 67 | ColorListItem *colorItem = (ColorListItem*)item(index); |
63 | colorItem->setColor(color); | 68 | colorItem->setColor(color); |
64 | updateItem( colorItem ); | 69 | updateItem( colorItem ); |
65 | } | 70 | } |
66 | } | 71 | } |
67 | 72 | ||
68 | 73 | ||
69 | QColor ColorListBox::color( uint index ) const | 74 | QColor ColorListBox::color( uint index ) const |
70 | { | 75 | { |
71 | if( index < count() ) | 76 | if( index < count() ) |
72 | { | 77 | { |
73 | ColorListItem *colorItem = (ColorListItem*)item(index); | 78 | ColorListItem *colorItem = (ColorListItem*)item(index); |
74 | return( colorItem->color() ); | 79 | return( colorItem->color() ); |
75 | } | 80 | } |
76 | else | 81 | else |
77 | { | 82 | { |
78 | return( black ); | 83 | return( Qt::black ); |
79 | } | 84 | } |
80 | } | 85 | } |
81 | void ColorListBox::slotNewColor(QListBoxItem * i) | 86 | void ColorListBox::slotNewColor(Q3ListBoxItem * i) |
82 | { | 87 | { |
83 | if ( i ) | 88 | if ( i ) |
84 | newColor( index( i ) ); | 89 | newColor( index( i ) ); |
85 | } | 90 | } |
86 | 91 | ||
87 | void ColorListBox::newColor( int index ) | 92 | void ColorListBox::newColor( int index ) |
88 | { | 93 | { |
89 | if( isEnabled() == false ) | 94 | if( isEnabled() == false ) |
90 | { | 95 | { |
91 | return; | 96 | return; |
92 | } | 97 | } |
93 | 98 | ||
94 | if( (uint)index < count() ) | 99 | if( (uint)index < count() ) |
95 | { | 100 | { |
96 | QColor c = color( index ); | 101 | QColor c = color( index ); |
97 | #ifndef KAB_EMBEDDED | 102 | #ifndef KAB_EMBEDDED |
98 | if( KColorDialog::getColor( c, this ) != QDialog::Rejected ) | 103 | if( KColorDialog::getColor( c, this ) != QDialog::Rejected ) |
99 | { | 104 | { |
100 | setColor( index, c ); | 105 | setColor( index, c ); |
101 | } | 106 | } |
102 | #else //KAB_EMBEDDED | 107 | #else //KAB_EMBEDDED |
103 | #ifdef DESKTOP_VERSION | 108 | #ifdef DESKTOP_VERSION |
104 | QColor col = QColorDialog::getColor ( c ); | 109 | QColor col = QColorDialog::getColor ( c ); |
105 | if ( col.isValid () ) { | 110 | if ( col.isValid () ) { |
@@ -177,69 +182,69 @@ void ColorListBox::dropEvent( QDropEvent *e ) | |||
177 | { | 182 | { |
178 | #ifndef KAB_EMBEDDED | 183 | #ifndef KAB_EMBEDDED |
179 | QColor color; | 184 | QColor color; |
180 | if( KColorDrag::decode( e, color ) ) | 185 | if( KColorDrag::decode( e, color ) ) |
181 | { | 186 | { |
182 | int index = currentItem(); | 187 | int index = currentItem(); |
183 | if( index != -1 ) | 188 | if( index != -1 ) |
184 | { | 189 | { |
185 | ColorListItem *colorItem = (ColorListItem*)item(index); | 190 | ColorListItem *colorItem = (ColorListItem*)item(index); |
186 | colorItem->setColor(color); | 191 | colorItem->setColor(color); |
187 | triggerUpdate( false ); // Redraw item | 192 | triggerUpdate( false ); // Redraw item |
188 | } | 193 | } |
189 | mCurrentOnDragEnter = -1; | 194 | mCurrentOnDragEnter = -1; |
190 | } | 195 | } |
191 | 196 | ||
192 | #else //KAB_EMBEDDED | 197 | #else //KAB_EMBEDDED |
193 | qDebug("ColorListBox::dropEvent drag&drop currently not supported"); | 198 | qDebug("ColorListBox::dropEvent drag&drop currently not supported"); |
194 | #endif //KAB_EMBEDDED | 199 | #endif //KAB_EMBEDDED |
195 | 200 | ||
196 | } | 201 | } |
197 | 202 | ||
198 | 203 | ||
199 | 204 | ||
200 | ColorListItem::ColorListItem( const QString &text, const QColor &color ) | 205 | ColorListItem::ColorListItem( const QString &text, const QColor &color ) |
201 | : QListBoxItem(), mColor( color ), mBoxWidth( 30 ) | 206 | : Q3ListBoxItem(), mColor( color ), mBoxWidth( 30 ) |
202 | { | 207 | { |
203 | setText( text ); | 208 | setText( text ); |
204 | } | 209 | } |
205 | 210 | ||
206 | 211 | ||
207 | const QColor &ColorListItem::color( void ) | 212 | const QColor &ColorListItem::color( void ) |
208 | { | 213 | { |
209 | return( mColor ); | 214 | return( mColor ); |
210 | } | 215 | } |
211 | 216 | ||
212 | 217 | ||
213 | void ColorListItem::setColor( const QColor &color ) | 218 | void ColorListItem::setColor( const QColor &color ) |
214 | { | 219 | { |
215 | mColor = color; | 220 | mColor = color; |
216 | } | 221 | } |
217 | 222 | ||
218 | 223 | ||
219 | void ColorListItem::paint( QPainter *p ) | 224 | void ColorListItem::paint( QPainter *p ) |
220 | { | 225 | { |
221 | QFontMetrics fm = p->fontMetrics(); | 226 | QFontMetrics fm = p->fontMetrics(); |
222 | int h = fm.height(); | 227 | int h = fm.height(); |
223 | 228 | ||
224 | p->drawText( mBoxWidth+3*2, fm.ascent() + fm.leading()/2, text() ); | 229 | p->drawText( mBoxWidth+3*2, fm.ascent() + fm.leading()/2, text() ); |
225 | 230 | ||
226 | p->setPen( Qt::black ); | 231 | p->setPen( Qt::black ); |
227 | p->drawRect( 3, 1, mBoxWidth, h-1 ); | 232 | p->drawRect( 3, 1, mBoxWidth, h-1 ); |
228 | p->fillRect( 4, 2, mBoxWidth-2, h-3, mColor ); | 233 | p->fillRect( 4, 2, mBoxWidth-2, h-3, mColor ); |
229 | } | 234 | } |
230 | 235 | ||
231 | 236 | ||
232 | int ColorListItem::height(const QListBox *lb ) const | 237 | int ColorListItem::height(const Q3ListBox *lb ) const |
233 | { | 238 | { |
234 | return( lb->fontMetrics().lineSpacing()+1 ); | 239 | return( lb->fontMetrics().lineSpacing()+1 ); |
235 | } | 240 | } |
236 | 241 | ||
237 | 242 | ||
238 | int ColorListItem::width(const QListBox *lb ) const | 243 | int ColorListItem::width(const Q3ListBox *lb ) const |
239 | { | 244 | { |
240 | return( mBoxWidth + lb->fontMetrics().width( text() ) + 6 ); | 245 | return( mBoxWidth + lb->fontMetrics().width( text() ) + 6 ); |
241 | } | 246 | } |
242 | 247 | ||
243 | #ifndef KAB_EMBEDDED | 248 | #ifndef KAB_EMBEDDED_ |
244 | #include "colorlistbox.moc" | 249 | #include "moc_colorlistbox.cpp" |
245 | #endif //KAB_EMBEDDED | 250 | #endif //KAB_EMBEDDED |