author | zautrix <zautrix> | 2005-06-07 08:53:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-07 08:53:18 (UTC) |
commit | aa9a9368a7b38e34118b65a4e8efa7ea7ec0e8e4 (patch) (unidiff) | |
tree | 69bcfb2ea1e74fa38bf8c648ecba4501dfbe5690 | |
parent | ff8af7ccdd6346bba1cb871c33931352bbafe40e (diff) | |
download | kdepimpi-aa9a9368a7b38e34118b65a4e8efa7ea7ec0e8e4.zip kdepimpi-aa9a9368a7b38e34118b65a4e8efa7ea7ec0e8e4.tar.gz kdepimpi-aa9a9368a7b38e34118b65a4e8efa7ea7ec0e8e4.tar.bz2 |
color dialog fix
-rw-r--r-- | kaddressbook/views/colorlistbox.cpp | 10 | ||||
-rw-r--r-- | microkde/kcolorbutton.cpp | 13 |
2 files changed, 22 insertions, 1 deletions
diff --git a/kaddressbook/views/colorlistbox.cpp b/kaddressbook/views/colorlistbox.cpp index 7386207..2bddca6 100644 --- a/kaddressbook/views/colorlistbox.cpp +++ b/kaddressbook/views/colorlistbox.cpp | |||
@@ -1,234 +1,244 @@ | |||
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 | #ifdef DESKTOP_VERSION | ||
31 | #include <qcolordialog.h> | ||
32 | #endif | ||
30 | 33 | ||
31 | ColorListBox::ColorListBox( QWidget *parent, const char *name, WFlags f ) | 34 | ColorListBox::ColorListBox( QWidget *parent, const char *name, WFlags f ) |
32 | :KListBox( parent, name, f ), mCurrentOnDragEnter(-1) | 35 | :KListBox( parent, name, f ), mCurrentOnDragEnter(-1) |
33 | { | 36 | { |
34 | connect( this, SIGNAL(selected(int)), this, SLOT(newColor(int)) ); | 37 | connect( this, SIGNAL(selected(int)), this, SLOT(newColor(int)) ); |
35 | connect( this, SIGNAL(clicked(QListBoxItem *)), this, SLOT(slotNewColor(QListBoxItem *)) ); | 38 | connect( this, SIGNAL(clicked(QListBoxItem *)), this, SLOT(slotNewColor(QListBoxItem *)) ); |
36 | setAcceptDrops( true); | 39 | setAcceptDrops( true); |
37 | } | 40 | } |
38 | 41 | ||
39 | 42 | ||
40 | void ColorListBox::setEnabled( bool state ) | 43 | void ColorListBox::setEnabled( bool state ) |
41 | { | 44 | { |
42 | if( state == isEnabled() ) | 45 | if( state == isEnabled() ) |
43 | { | 46 | { |
44 | return; | 47 | return; |
45 | } | 48 | } |
46 | 49 | ||
47 | QListBox::setEnabled( state ); | 50 | QListBox::setEnabled( state ); |
48 | for( uint i=0; i<count(); i++ ) | 51 | for( uint i=0; i<count(); i++ ) |
49 | { | 52 | { |
50 | updateItem( i ); | 53 | updateItem( i ); |
51 | } | 54 | } |
52 | } | 55 | } |
53 | 56 | ||
54 | 57 | ||
55 | void ColorListBox::setColor( uint index, const QColor &color ) | 58 | void ColorListBox::setColor( uint index, const QColor &color ) |
56 | { | 59 | { |
57 | if( index < count() ) | 60 | if( index < count() ) |
58 | { | 61 | { |
59 | ColorListItem *colorItem = (ColorListItem*)item(index); | 62 | ColorListItem *colorItem = (ColorListItem*)item(index); |
60 | colorItem->setColor(color); | 63 | colorItem->setColor(color); |
61 | updateItem( colorItem ); | 64 | updateItem( colorItem ); |
62 | } | 65 | } |
63 | } | 66 | } |
64 | 67 | ||
65 | 68 | ||
66 | QColor ColorListBox::color( uint index ) const | 69 | QColor ColorListBox::color( uint index ) const |
67 | { | 70 | { |
68 | if( index < count() ) | 71 | if( index < count() ) |
69 | { | 72 | { |
70 | ColorListItem *colorItem = (ColorListItem*)item(index); | 73 | ColorListItem *colorItem = (ColorListItem*)item(index); |
71 | return( colorItem->color() ); | 74 | return( colorItem->color() ); |
72 | } | 75 | } |
73 | else | 76 | else |
74 | { | 77 | { |
75 | return( black ); | 78 | return( black ); |
76 | } | 79 | } |
77 | } | 80 | } |
78 | void ColorListBox::slotNewColor(QListBoxItem * i) | 81 | void ColorListBox::slotNewColor(QListBoxItem * i) |
79 | { | 82 | { |
80 | if ( i ) | 83 | if ( i ) |
81 | newColor( index( i ) ); | 84 | newColor( index( i ) ); |
82 | } | 85 | } |
83 | 86 | ||
84 | void ColorListBox::newColor( int index ) | 87 | void ColorListBox::newColor( int index ) |
85 | { | 88 | { |
86 | if( isEnabled() == false ) | 89 | if( isEnabled() == false ) |
87 | { | 90 | { |
88 | return; | 91 | return; |
89 | } | 92 | } |
90 | 93 | ||
91 | if( (uint)index < count() ) | 94 | if( (uint)index < count() ) |
92 | { | 95 | { |
93 | QColor c = color( index ); | 96 | QColor c = color( index ); |
94 | #ifndef KAB_EMBEDDED | 97 | #ifndef KAB_EMBEDDED |
95 | if( KColorDialog::getColor( c, this ) != QDialog::Rejected ) | 98 | if( KColorDialog::getColor( c, this ) != QDialog::Rejected ) |
96 | { | 99 | { |
97 | setColor( index, c ); | 100 | setColor( index, c ); |
98 | } | 101 | } |
99 | #else //KAB_EMBEDDED | 102 | #else //KAB_EMBEDDED |
103 | #ifdef DESKTOP_VERSION | ||
104 | QColor col = QColorDialog::getColor ( c ); | ||
105 | if ( col.isValid () ) { | ||
106 | setColor( index, col ); | ||
107 | } | ||
108 | #else | ||
100 | KColorDialog* k = new KColorDialog( this ); | 109 | KColorDialog* k = new KColorDialog( this ); |
101 | k->setColor( c ); | 110 | k->setColor( c ); |
102 | int res = k->exec(); | 111 | int res = k->exec(); |
103 | if ( res ) { | 112 | if ( res ) { |
104 | setColor( index, k->getColor() ); | 113 | setColor( index, k->getColor() ); |
105 | } | 114 | } |
106 | delete k; | 115 | delete k; |
116 | #endif | ||
107 | #endif //KAB_EMBEDDED | 117 | #endif //KAB_EMBEDDED |
108 | 118 | ||
109 | } | 119 | } |
110 | } | 120 | } |
111 | 121 | ||
112 | 122 | ||
113 | void ColorListBox::dragEnterEvent( QDragEnterEvent *e ) | 123 | void ColorListBox::dragEnterEvent( QDragEnterEvent *e ) |
114 | { | 124 | { |
115 | #ifndef KAB_EMBEDDED | 125 | #ifndef KAB_EMBEDDED |
116 | if( KColorDrag::canDecode(e) && isEnabled() ) | 126 | if( KColorDrag::canDecode(e) && isEnabled() ) |
117 | { | 127 | { |
118 | mCurrentOnDragEnter = currentItem(); | 128 | mCurrentOnDragEnter = currentItem(); |
119 | e->accept( true ); | 129 | e->accept( true ); |
120 | } | 130 | } |
121 | else | 131 | else |
122 | { | 132 | { |
123 | mCurrentOnDragEnter = -1; | 133 | mCurrentOnDragEnter = -1; |
124 | e->accept( false ); | 134 | e->accept( false ); |
125 | } | 135 | } |
126 | #else //KAB_EMBEDDED | 136 | #else //KAB_EMBEDDED |
127 | qDebug("ColorListBox::dragEnterEvent drag&drop currently not supported"); | 137 | qDebug("ColorListBox::dragEnterEvent drag&drop currently not supported"); |
128 | #endif //KAB_EMBEDDED | 138 | #endif //KAB_EMBEDDED |
129 | 139 | ||
130 | } | 140 | } |
131 | 141 | ||
132 | 142 | ||
133 | void ColorListBox::dragLeaveEvent( QDragLeaveEvent * ) | 143 | void ColorListBox::dragLeaveEvent( QDragLeaveEvent * ) |
134 | { | 144 | { |
135 | #ifndef KAB_EMBEDDED | 145 | #ifndef KAB_EMBEDDED |
136 | 146 | ||
137 | if( mCurrentOnDragEnter != -1 ) | 147 | if( mCurrentOnDragEnter != -1 ) |
138 | { | 148 | { |
139 | setCurrentItem( mCurrentOnDragEnter ); | 149 | setCurrentItem( mCurrentOnDragEnter ); |
140 | mCurrentOnDragEnter = -1; | 150 | mCurrentOnDragEnter = -1; |
141 | } | 151 | } |
142 | #else //KAB_EMBEDDED | 152 | #else //KAB_EMBEDDED |
143 | qDebug("ColorListBox::dragLeaveEvent drag&drop currently not supported"); | 153 | qDebug("ColorListBox::dragLeaveEvent drag&drop currently not supported"); |
144 | #endif //KAB_EMBEDDED | 154 | #endif //KAB_EMBEDDED |
145 | } | 155 | } |
146 | 156 | ||
147 | 157 | ||
148 | void ColorListBox::dragMoveEvent( QDragMoveEvent *e ) | 158 | void ColorListBox::dragMoveEvent( QDragMoveEvent *e ) |
149 | { | 159 | { |
150 | #ifndef KAB_EMBEDDED | 160 | #ifndef KAB_EMBEDDED |
151 | if( KColorDrag::canDecode(e) && isEnabled() ) | 161 | if( KColorDrag::canDecode(e) && isEnabled() ) |
152 | { | 162 | { |
153 | ColorListItem *item = (ColorListItem*)itemAt( e->pos() ); | 163 | ColorListItem *item = (ColorListItem*)itemAt( e->pos() ); |
154 | if( item != 0 ) | 164 | if( item != 0 ) |
155 | { | 165 | { |
156 | setCurrentItem ( item ); | 166 | setCurrentItem ( item ); |
157 | } | 167 | } |
158 | } | 168 | } |
159 | #else //KAB_EMBEDDED | 169 | #else //KAB_EMBEDDED |
160 | qDebug("ColorListBox::dragMoveEvent drag&drop currently not supported"); | 170 | qDebug("ColorListBox::dragMoveEvent drag&drop currently not supported"); |
161 | #endif //KAB_EMBEDDED | 171 | #endif //KAB_EMBEDDED |
162 | 172 | ||
163 | } | 173 | } |
164 | 174 | ||
165 | 175 | ||
166 | void ColorListBox::dropEvent( QDropEvent *e ) | 176 | void ColorListBox::dropEvent( QDropEvent *e ) |
167 | { | 177 | { |
168 | #ifndef KAB_EMBEDDED | 178 | #ifndef KAB_EMBEDDED |
169 | QColor color; | 179 | QColor color; |
170 | if( KColorDrag::decode( e, color ) ) | 180 | if( KColorDrag::decode( e, color ) ) |
171 | { | 181 | { |
172 | int index = currentItem(); | 182 | int index = currentItem(); |
173 | if( index != -1 ) | 183 | if( index != -1 ) |
174 | { | 184 | { |
175 | ColorListItem *colorItem = (ColorListItem*)item(index); | 185 | ColorListItem *colorItem = (ColorListItem*)item(index); |
176 | colorItem->setColor(color); | 186 | colorItem->setColor(color); |
177 | triggerUpdate( false ); // Redraw item | 187 | triggerUpdate( false ); // Redraw item |
178 | } | 188 | } |
179 | mCurrentOnDragEnter = -1; | 189 | mCurrentOnDragEnter = -1; |
180 | } | 190 | } |
181 | 191 | ||
182 | #else //KAB_EMBEDDED | 192 | #else //KAB_EMBEDDED |
183 | qDebug("ColorListBox::dropEvent drag&drop currently not supported"); | 193 | qDebug("ColorListBox::dropEvent drag&drop currently not supported"); |
184 | #endif //KAB_EMBEDDED | 194 | #endif //KAB_EMBEDDED |
185 | 195 | ||
186 | } | 196 | } |
187 | 197 | ||
188 | 198 | ||
189 | 199 | ||
190 | ColorListItem::ColorListItem( const QString &text, const QColor &color ) | 200 | ColorListItem::ColorListItem( const QString &text, const QColor &color ) |
191 | : QListBoxItem(), mColor( color ), mBoxWidth( 30 ) | 201 | : QListBoxItem(), mColor( color ), mBoxWidth( 30 ) |
192 | { | 202 | { |
193 | setText( text ); | 203 | setText( text ); |
194 | } | 204 | } |
195 | 205 | ||
196 | 206 | ||
197 | const QColor &ColorListItem::color( void ) | 207 | const QColor &ColorListItem::color( void ) |
198 | { | 208 | { |
199 | return( mColor ); | 209 | return( mColor ); |
200 | } | 210 | } |
201 | 211 | ||
202 | 212 | ||
203 | void ColorListItem::setColor( const QColor &color ) | 213 | void ColorListItem::setColor( const QColor &color ) |
204 | { | 214 | { |
205 | mColor = color; | 215 | mColor = color; |
206 | } | 216 | } |
207 | 217 | ||
208 | 218 | ||
209 | void ColorListItem::paint( QPainter *p ) | 219 | void ColorListItem::paint( QPainter *p ) |
210 | { | 220 | { |
211 | QFontMetrics fm = p->fontMetrics(); | 221 | QFontMetrics fm = p->fontMetrics(); |
212 | int h = fm.height(); | 222 | int h = fm.height(); |
213 | 223 | ||
214 | p->drawText( mBoxWidth+3*2, fm.ascent() + fm.leading()/2, text() ); | 224 | p->drawText( mBoxWidth+3*2, fm.ascent() + fm.leading()/2, text() ); |
215 | 225 | ||
216 | p->setPen( Qt::black ); | 226 | p->setPen( Qt::black ); |
217 | p->drawRect( 3, 1, mBoxWidth, h-1 ); | 227 | p->drawRect( 3, 1, mBoxWidth, h-1 ); |
218 | p->fillRect( 4, 2, mBoxWidth-2, h-3, mColor ); | 228 | p->fillRect( 4, 2, mBoxWidth-2, h-3, mColor ); |
219 | } | 229 | } |
220 | 230 | ||
221 | 231 | ||
222 | int ColorListItem::height(const QListBox *lb ) const | 232 | int ColorListItem::height(const QListBox *lb ) const |
223 | { | 233 | { |
224 | return( lb->fontMetrics().lineSpacing()+1 ); | 234 | return( lb->fontMetrics().lineSpacing()+1 ); |
225 | } | 235 | } |
226 | 236 | ||
227 | 237 | ||
228 | int ColorListItem::width(const QListBox *lb ) const | 238 | int ColorListItem::width(const QListBox *lb ) const |
229 | { | 239 | { |
230 | return( mBoxWidth + lb->fontMetrics().width( text() ) + 6 ); | 240 | return( mBoxWidth + lb->fontMetrics().width( text() ) + 6 ); |
231 | } | 241 | } |
232 | 242 | ||
233 | #ifndef KAB_EMBEDDED | 243 | #ifndef KAB_EMBEDDED |
234 | #include "colorlistbox.moc" | 244 | #include "colorlistbox.moc" |
diff --git a/microkde/kcolorbutton.cpp b/microkde/kcolorbutton.cpp index 433f909..c7c6088 100644 --- a/microkde/kcolorbutton.cpp +++ b/microkde/kcolorbutton.cpp | |||
@@ -1,36 +1,47 @@ | |||
1 | #include "kcolorbutton.h" | 1 | #include "kcolorbutton.h" |
2 | #include "kcolordialog.h" | 2 | #include "kcolordialog.h" |
3 | #include "qapplication.h" | 3 | #include "qapplication.h" |
4 | 4 | ||
5 | 5 | ||
6 | #include "qlayout.h" | 6 | #include "qlayout.h" |
7 | 7 | #ifdef DESKTOP_VERSION | |
8 | #include <qcolordialog.h> | ||
9 | #endif | ||
8 | void KColorButton:: edit() | 10 | void KColorButton:: edit() |
9 | { | 11 | { |
10 | 12 | ||
13 | #ifdef DESKTOP_VERSION | ||
14 | QColor col = QColorDialog::getColor ( mColor ); | ||
15 | if ( col.isValid () ) { | ||
16 | mColor = col; | ||
17 | setColor ( mColor ); | ||
18 | emit changed ( mColor ); | ||
19 | } | ||
20 | #else | ||
11 | KColorDialog* k = new KColorDialog( this ); | 21 | KColorDialog* k = new KColorDialog( this ); |
12 | k->setColor( mColor ); | 22 | k->setColor( mColor ); |
13 | int res = k->exec(); | 23 | int res = k->exec(); |
14 | if ( res ) { | 24 | if ( res ) { |
15 | mColor = k->getColor(); | 25 | mColor = k->getColor(); |
16 | setColor ( mColor ); | 26 | setColor ( mColor ); |
17 | emit changed ( mColor ); | 27 | emit changed ( mColor ); |
18 | } | 28 | } |
19 | delete k; | 29 | delete k; |
30 | #endif | ||
20 | } | 31 | } |
21 | KColorButton::KColorButton( QWidget *p ):QPushButton( p ) | 32 | KColorButton::KColorButton( QWidget *p ):QPushButton( p ) |
22 | { | 33 | { |
23 | int size = 24; | 34 | int size = 24; |
24 | if( QApplication::desktop()->width() < 480 ) | 35 | if( QApplication::desktop()->width() < 480 ) |
25 | size = 18; | 36 | size = 18; |
26 | setFixedSize( size,size ); | 37 | setFixedSize( size,size ); |
27 | connect ( this, SIGNAL( clicked() ), this ,SLOT (edit() )); | 38 | connect ( this, SIGNAL( clicked() ), this ,SLOT (edit() )); |
28 | 39 | ||
29 | } | 40 | } |
30 | void KColorButton::setColor ( const QColor & c) | 41 | void KColorButton::setColor ( const QColor & c) |
31 | { | 42 | { |
32 | mColor = c; | 43 | mColor = c; |
33 | QPixmap pix ( height() - 4, width() - 4 ); | 44 | QPixmap pix ( height() - 4, width() - 4 ); |
34 | pix.fill( c ); | 45 | pix.fill( c ); |
35 | setPixmap ( pix ); | 46 | setPixmap ( pix ); |
36 | } | 47 | } |