summaryrefslogtreecommitdiffabout
path: root/microkde/kdeui/ktoolbarbutton.cpp
Unidiff
Diffstat (limited to 'microkde/kdeui/ktoolbarbutton.cpp') (more/less context) (show whitespace changes)
-rw-r--r--microkde/kdeui/ktoolbarbutton.cpp106
1 files changed, 60 insertions, 46 deletions
diff --git a/microkde/kdeui/ktoolbarbutton.cpp b/microkde/kdeui/ktoolbarbutton.cpp
index 1d5d0e5..7b98b32 100644
--- a/microkde/kdeui/ktoolbarbutton.cpp
+++ b/microkde/kdeui/ktoolbarbutton.cpp
@@ -1,212 +1,216 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) 2 Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org)
3 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) 3 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org)
4 (C) 1997, 1998 Sven Radej (radej@kde.org) 4 (C) 1997, 1998 Sven Radej (radej@kde.org)
5 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) 5 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org)
6 (C) 1999 Chris Schlaeger (cs@kde.org) 6 (C) 1999 Chris Schlaeger (cs@kde.org)
7 (C) 1999 Kurt Granroth (granroth@kde.org) 7 (C) 1999 Kurt Granroth (granroth@kde.org)
8 8
9 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
11 License version 2 as published by the Free Software Foundation. 11 License version 2 as published by the Free Software Foundation.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
22*/ 22*/
23 23
24//US #include <config.h> 24//US #include <config.h>
25#include <string.h> 25#include <string.h>
26 26
27#include "ktoolbarbutton.h" 27#include "ktoolbarbutton.h"
28#include "ktoolbar.h" 28#include "ktoolbar.h"
29 29
30#include <qstyle.h> 30#include <qstyle.h>
31#include <qimage.h> 31#include <qimage.h>
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qdrawutil.h> 33#include <qdrawutil.h>
34#include <qtooltip.h> 34#include <qtooltip.h>
35#include <qbitmap.h> 35#include <qbitmap.h>
36#include <qpopupmenu.h> 36#include <q3popupmenu.h>
37#include <qcursor.h> 37#include <qcursor.h>
38#include <qpainter.h> 38#include <qpainter.h>
39#include <qlayout.h> 39#include <qlayout.h>
40//Added by qt3to4:
41#include <QPixmap>
42#include <QMouseEvent>
43#include <QEvent>
40 44
41#include <kapplication.h> 45#include <kapplication.h>
42#include <kdebug.h> 46#include <kdebug.h>
43#include <kglobal.h> 47#include <kglobal.h>
44#include <kglobalsettings.h> 48#include <kglobalsettings.h>
45//US #include <kiconeffect.h> 49//US #include <kiconeffect.h>
46#include <kiconloader.h> 50#include <kiconloader.h>
47 51
48// needed to get our instance 52// needed to get our instance
49#include <kmainwindow.h> 53#include <kmainwindow.h>
50 54
51template class QIntDict<KToolBarButton>; 55template class Q3IntDict<KToolBarButton>;
52 56
53class KToolBarButtonPrivate 57class KToolBarButtonPrivate
54{ 58{
55public: 59public:
56 KToolBarButtonPrivate() 60 KToolBarButtonPrivate()
57 { 61 {
58 m_noStyle = false; 62 m_noStyle = false;
59 m_isSeparator = false; 63 m_isSeparator = false;
60 m_isRadio = false; 64 m_isRadio = false;
61 m_highlight = false; 65 m_highlight = false;
62 m_isRaised = false; 66 m_isRaised = false;
63 m_isActive = false; 67 m_isActive = false;
64 68
65 m_iconName = QString::null; 69 m_iconName = QString::null;
66 m_iconText = KToolBar::IconOnly; 70 m_iconText = KToolBar::IconOnly;
67 m_iconSize = 0; 71 m_iconSize = 0;
68 72
69//US m_instance = KGlobal::instance(); 73//US m_instance = KGlobal::instance();
70 } 74 }
71 ~KToolBarButtonPrivate() 75 ~KToolBarButtonPrivate()
72 { 76 {
73 } 77 }
74 78
75 int m_id; 79 int m_id;
76 bool m_noStyle: 1; 80 bool m_noStyle: 1;
77 bool m_isSeparator: 1; 81 bool m_isSeparator: 1;
78 bool m_isRadio: 1; 82 bool m_isRadio: 1;
79 bool m_highlight: 1; 83 bool m_highlight: 1;
80 bool m_isRaised: 1; 84 bool m_isRaised: 1;
81 bool m_isActive: 1; 85 bool m_isActive: 1;
82 86
83 QString m_iconName; 87 QString m_iconName;
84 88
85 KToolBar *m_parent; 89 KToolBar *m_parent;
86 KToolBar::IconText m_iconText; 90 KToolBar::IconText m_iconText;
87 int m_iconSize; 91 int m_iconSize;
88 QSize size; 92 QSize size;
89 93
90 QPoint m_mousePressPos; 94 QPoint m_mousePressPos;
91 95
92//US KInstance *m_instance; 96//US KInstance *m_instance;
93}; 97};
94 98
95// This will construct a separator 99// This will construct a separator
96KToolBarButton::KToolBarButton( QWidget *_parent, const char *_name ) 100KToolBarButton::KToolBarButton( QWidget *_parent, const char *_name )
97 : QToolButton( _parent , _name) 101 : QToolButton( _parent , _name)
98{ 102{
99 d = new KToolBarButtonPrivate; 103 d = new KToolBarButtonPrivate;
100 104
101 resize(6,6); 105 resize(6,6);
102 hide(); 106 hide();
103 d->m_isSeparator = true; 107 d->m_isSeparator = true;
104} 108}
105 109
106KToolBarButton::KToolBarButton( const QString& _icon, int _id, 110KToolBarButton::KToolBarButton( const QString& _icon, int _id,
107 QWidget *_parent, const char *_name, 111 QWidget *_parent, const char *_name,
108 const QString &_txt/*US, KInstance *_instance*/ ) 112 const QString &_txt/*US, KInstance *_instance*/ )
109 : QToolButton( _parent, _name ), d( 0 ) 113 : QToolButton( _parent, _name ), d( 0 )
110{ 114{
111 d = new KToolBarButtonPrivate; 115 d = new KToolBarButtonPrivate;
112 116
113 d->m_id = _id; 117 d->m_id = _id;
114 d->m_parent = (KToolBar*)_parent; 118 d->m_parent = (KToolBar*)_parent;
115 QToolButton::setTextLabel(_txt); 119 QToolButton::setTextLabel(_txt);
116//US d->m_instance = _instance; 120//US d->m_instance = _instance;
117 121
118 setFocusPolicy( NoFocus ); 122 setFocusPolicy( Qt::NoFocus );
119 123
120 // connect all of our slots and start trapping events 124 // connect all of our slots and start trapping events
121 connect(d->m_parent, SIGNAL( modechange() ), 125 connect(d->m_parent, SIGNAL( modechange() ),
122 this, SLOT( modeChange() )); 126 this, SLOT( modeChange() ));
123 127
124 connect(this, SIGNAL( clicked() ), 128 connect(this, SIGNAL( clicked() ),
125 this, SLOT( slotClicked() ) ); 129 this, SLOT( slotClicked() ) );
126 connect(this, SIGNAL( pressed() ), 130 connect(this, SIGNAL( pressed() ),
127 this, SLOT( slotPressed() ) ); 131 this, SLOT( slotPressed() ) );
128 connect(this, SIGNAL( released() ), 132 connect(this, SIGNAL( released() ),
129 this, SLOT( slotReleased() ) ); 133 this, SLOT( slotReleased() ) );
130 installEventFilter(this); 134 installEventFilter(this);
131 135
132 d->m_iconName = _icon; 136 d->m_iconName = _icon;
133 137
134 // do our initial setup 138 // do our initial setup
135 modeChange(); 139 modeChange();
136} 140}
137 141
138KToolBarButton::KToolBarButton( const QPixmap& pixmap, int _id, 142KToolBarButton::KToolBarButton( const QPixmap& pixmap, int _id,
139 QWidget *_parent, const char *name, 143 QWidget *_parent, const char *name,
140 const QString& txt) 144 const QString& txt)
141 : QToolButton( _parent, name ), d( 0 ) 145 : QToolButton( _parent, name ), d( 0 )
142{ 146{
143 d = new KToolBarButtonPrivate; 147 d = new KToolBarButtonPrivate;
144 148
145 d->m_id = _id; 149 d->m_id = _id;
146 d->m_parent = (KToolBar *) _parent; 150 d->m_parent = (KToolBar *) _parent;
147 QToolButton::setTextLabel(txt); 151 QToolButton::setTextLabel(txt);
148 152
149 setFocusPolicy( NoFocus ); 153 setFocusPolicy( Qt::NoFocus );
150 154
151 // connect all of our slots and start trapping events 155 // connect all of our slots and start trapping events
152 connect(d->m_parent, SIGNAL( modechange()), 156 connect(d->m_parent, SIGNAL( modechange()),
153 this, SLOT(modeChange())); 157 this, SLOT(modeChange()));
154 158
155 connect(this, SIGNAL( clicked() ), 159 connect(this, SIGNAL( clicked() ),
156 this, SLOT( slotClicked() )); 160 this, SLOT( slotClicked() ));
157 connect(this, SIGNAL( pressed() ), 161 connect(this, SIGNAL( pressed() ),
158 this, SLOT( slotPressed() )); 162 this, SLOT( slotPressed() ));
159 connect(this, SIGNAL( released() ), 163 connect(this, SIGNAL( released() ),
160 this, SLOT( slotReleased() )); 164 this, SLOT( slotReleased() ));
161 installEventFilter(this); 165 installEventFilter(this);
162 166
163 // set our pixmap and do our initial setup 167 // set our pixmap and do our initial setup
164 setIconSet( QIconSet( pixmap )); 168 setIconSet( QIcon( pixmap ));
165 modeChange(); 169 modeChange();
166} 170}
167 171
168KToolBarButton::~KToolBarButton() 172KToolBarButton::~KToolBarButton()
169{ 173{
170 delete d; d = 0; 174 delete d; d = 0;
171} 175}
172 176
173void KToolBarButton::modeChange() 177void KToolBarButton::modeChange()
174{ 178{
175 QSize mysize; 179 QSize mysize;
176 180
177 // grab a few global variables for use in this function and others 181 // grab a few global variables for use in this function and others
178 d->m_highlight = d->m_parent->highlight(); 182 d->m_highlight = d->m_parent->highlight();
179 d->m_iconText = d->m_parent->iconText(); 183 d->m_iconText = d->m_parent->iconText();
180 184
181 d->m_iconSize = d->m_parent->iconSize(); 185 d->m_iconSize = d->m_parent->iconSize();
182 if (!d->m_iconName.isNull()) 186 if (!d->m_iconName.isNull())
183 setIcon(d->m_iconName); 187 setIcon(d->m_iconName);
184 188
185 // we'll start with the size of our pixmap 189 // we'll start with the size of our pixmap
186 int pix_width = d->m_iconSize; 190 int pix_width = d->m_iconSize;
187 191
188 if ( d->m_iconSize == 0 ) { 192 if ( d->m_iconSize == 0 ) {
189 if (!strcmp(d->m_parent->name(), "mainToolBar")) 193 if (!strcmp(d->m_parent->name(), "mainToolBar"))
190/*US 194/*US
191 pix_width = IconSize( KIcon::MainToolbar ); 195 pix_width = IconSize( KIcon::MainToolbar );
192 else 196 else
193 pix_width = IconSize( KIcon::Toolbar ); 197 pix_width = IconSize( KIcon::Toolbar );
194*/ 198*/
195//qDebug("KToolBarButton::modeChange make iconsize configurable"); 199//qDebug("KToolBarButton::modeChange make iconsize configurable");
196 pix_width = 16; 200 pix_width = 16;
197 } 201 }
198 int pix_height = pix_width; 202 int pix_height = pix_width;
199 203
200 int text_height = 0; 204 int text_height = 0;
201 int text_width = 0; 205 int text_width = 0;
202 206
203 QToolTip::remove(this); 207 QToolTip::remove(this);
204 if (d->m_iconText != KToolBar::IconOnly) 208 if (d->m_iconText != KToolBar::IconOnly)
205 { 209 {
206 // okay, we have to deal with fonts. let's get our information now 210 // okay, we have to deal with fonts. let's get our information now
207/*US 211/*US
208 QFont tmp_font = KGlobalSettings::toolBarFont(); 212 QFont tmp_font = KGlobalSettings::toolBarFont();
209 213
210 // now parse out our font sizes from our chosen font 214 // now parse out our font sizes from our chosen font
211 QFontMetrics fm(tmp_font); 215 QFontMetrics fm(tmp_font);
212 216
@@ -247,422 +251,432 @@ void KToolBarButton::modeChange()
247 mysize = style().sizeFromContents(QStyle::CT_ToolButton, this, mysize). 251 mysize = style().sizeFromContents(QStyle::CT_ToolButton, this, mysize).
248 expandedTo(QApplication::globalStrut()); 252 expandedTo(QApplication::globalStrut());
249*/ 253*/
250 // make sure that this isn't taller then it is wide 254 // make sure that this isn't taller then it is wide
251 if (mysize.height() > mysize.width()) 255 if (mysize.height() > mysize.width())
252 mysize.setWidth(mysize.height()); 256 mysize.setWidth(mysize.height());
253 257
254 d->size = mysize; 258 d->size = mysize;
255 setFixedSize(mysize); 259 setFixedSize(mysize);
256 updateGeometry(); 260 updateGeometry();
257} 261}
258 262
259void KToolBarButton::setTextLabel( const QString& text, bool tipToo) 263void KToolBarButton::setTextLabel( const QString& text, bool tipToo)
260{ 264{
261 if (text.isNull()) 265 if (text.isNull())
262 return; 266 return;
263 267
264 QString txt(text); 268 QString txt(text);
265 if (txt.right(3) == QString::fromLatin1("...")) 269 if (txt.right(3) == QString::fromLatin1("..."))
266 txt.truncate(txt.length() - 3); 270 txt.truncate(txt.length() - 3);
267 271
268 QToolButton::setTextLabel(txt, tipToo); 272 QToolButton::setTextLabel(txt, tipToo);
269 update(); 273 update();
270} 274}
271 275
272void KToolBarButton::setText( const QString& text) 276void KToolBarButton::setText( const QString& text)
273{ 277{
274 setTextLabel(text, true); 278 setTextLabel(text, true);
275 modeChange(); 279 modeChange();
276} 280}
277 281
278void KToolBarButton::setIcon( const QString &icon ) 282void KToolBarButton::setIcon( const QString &icon )
279{ 283{
280 d->m_iconName = icon; 284 d->m_iconName = icon;
281 d->m_iconSize = d->m_parent->iconSize(); 285 d->m_iconSize = d->m_parent->iconSize();
282 // QObject::name() return "const char *" instead of QString. 286 // QObject::name() return "const char *" instead of QString.
283 if (!strcmp(d->m_parent->name(), "mainToolBar")) 287 if (!strcmp(d->m_parent->name(), "mainToolBar"))
284/*US QToolButton::setIconSet( d->m_instance->iconLoader()->loadIconSet( 288/*US QToolButton::setIconSet( d->m_instance->iconLoader()->loadIconSet(
285 d->m_iconName, KIcon::MainToolbar, d->m_iconSize )); 289 d->m_iconName, KIcon::MainToolbar, d->m_iconSize ));
286*/ 290*/
287 QToolButton::setIconSet( KGlobal::iconLoader()->loadIconSet(d->m_iconName )); 291 QToolButton::setIconSet( KGlobal::iconLoader()->loadIconSet(d->m_iconName ));
288 else 292 else
289/*US QToolButton::setIconSet(d->m_instance->iconLoader()->loadIconSet( 293/*US QToolButton::setIconSet(d->m_instance->iconLoader()->loadIconSet(
290 d->m_iconName, KIcon::Toolbar, d->m_iconSize )); 294 d->m_iconName, KIcon::Toolbar, d->m_iconSize ));
291*/ 295*/
292 QToolButton::setIconSet(KGlobal::iconLoader()->loadIconSet(d->m_iconName)); 296 QToolButton::setIconSet(KGlobal::iconLoader()->loadIconSet(d->m_iconName));
293} 297}
294 298
295void KToolBarButton::setIconSet( const QIconSet &iconset ) 299void KToolBarButton::setIconSet( const QIcon &iconset )
296{ 300{
297 QToolButton::setIconSet( iconset ); 301 QToolButton::setIconSet( iconset );
298} 302}
299 303
300// remove? 304// remove?
301void KToolBarButton::setPixmap( const QPixmap &pixmap ) 305void KToolBarButton::setPixmap( const QPixmap &pixmap )
302{ 306{
303 if( pixmap.isNull()) // called by QToolButton 307 if( pixmap.isNull()) // called by QToolButton
304 { 308 {
305 QToolButton::setPixmap( pixmap ); 309 QToolButton::setPixmap( pixmap );
306 return; 310 return;
307 } 311 }
308 QIconSet set = iconSet(); 312 QIcon set = iconSet();
309 set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Active ); 313 set.setPixmap( pixmap, QIcon::Automatic, QIcon::Active );
310 QToolButton::setIconSet( set ); 314 QToolButton::setIconSet( set );
311} 315}
312 316
313void KToolBarButton::setDefaultPixmap( const QPixmap &pixmap ) 317void KToolBarButton::setDefaultPixmap( const QPixmap &pixmap )
314{ 318{
315 QIconSet set = iconSet(); 319 QIcon set = iconSet();
316 set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Normal ); 320 set.setPixmap( pixmap, QIcon::Automatic, QIcon::Normal );
317 QToolButton::setIconSet( set ); 321 QToolButton::setIconSet( set );
318} 322}
319 323
320void KToolBarButton::setDisabledPixmap( const QPixmap &pixmap ) 324void KToolBarButton::setDisabledPixmap( const QPixmap &pixmap )
321{ 325{
322 QIconSet set = iconSet(); 326 QIcon set = iconSet();
323 set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Disabled ); 327 set.setPixmap( pixmap, QIcon::Automatic, QIcon::Disabled );
324 QToolButton::setIconSet( set ); 328 QToolButton::setIconSet( set );
325} 329}
326 330
327void KToolBarButton::setDefaultIcon( const QString& icon ) 331void KToolBarButton::setDefaultIcon( const QString& icon )
328{ 332{
329 QIconSet set = iconSet(); 333 QIcon set = iconSet();
330 QPixmap pm; 334 QPixmap pm;
331 if (!strcmp(d->m_parent->name(), "mainToolBar")) 335 if (!strcmp(d->m_parent->name(), "mainToolBar"))
332 pm = /*US d->m_instance->iconLoader()*/KGlobal::iconLoader()->loadIcon( icon, KIcon::MainToolbar, 336 pm = /*US d->m_instance->iconLoader()*/KGlobal::iconLoader()->loadIcon( icon, KIcon::MainToolbar,
333 d->m_iconSize ); 337 d->m_iconSize );
334 else 338 else
335 pm = /*US d->m_instance->iconLoader()*/KGlobal::iconLoader()->loadIcon( icon, KIcon::Toolbar, 339 pm = /*US d->m_instance->iconLoader()*/KGlobal::iconLoader()->loadIcon( icon, KIcon::Toolbar,
336 d->m_iconSize ); 340 d->m_iconSize );
337 set.setPixmap( pm, QIconSet::Automatic, QIconSet::Normal ); 341 set.setPixmap( pm, QIcon::Automatic, QIcon::Normal );
338 QToolButton::setIconSet( set ); 342 QToolButton::setIconSet( set );
339} 343}
340 344
341void KToolBarButton::setDisabledIcon( const QString& icon ) 345void KToolBarButton::setDisabledIcon( const QString& icon )
342{ 346{
343 QIconSet set = iconSet(); 347 QIcon set = iconSet();
344 QPixmap pm; 348 QPixmap pm;
345 if (!strcmp(d->m_parent->name(), "mainToolBar")) 349 if (!strcmp(d->m_parent->name(), "mainToolBar"))
346 pm = /*US d->m_instance->iconLoader()*/ KGlobal::iconLoader()->loadIcon( icon, KIcon::MainToolbar, 350 pm = /*US d->m_instance->iconLoader()*/ KGlobal::iconLoader()->loadIcon( icon, KIcon::MainToolbar,
347 d->m_iconSize ); 351 d->m_iconSize );
348 else 352 else
349 pm = /*US d->m_instance->iconLoader()*/ KGlobal::iconLoader()->loadIcon( icon, KIcon::Toolbar, 353 pm = /*US d->m_instance->iconLoader()*/ KGlobal::iconLoader()->loadIcon( icon, KIcon::Toolbar,
350 d->m_iconSize ); 354 d->m_iconSize );
351 set.setPixmap( pm, QIconSet::Automatic, QIconSet::Disabled ); 355 set.setPixmap( pm, QIcon::Automatic, QIcon::Disabled );
352 QToolButton::setIconSet( set ); 356 QToolButton::setIconSet( set );
353} 357}
354 358
355QPopupMenu *KToolBarButton::popup() 359QMenu *KToolBarButton::popup()
356{ 360{
357 // obsolete 361 // obsolete
358 // KDE4: remove me 362 // KDE4: remove me
359 return QToolButton::popup(); 363 return QToolButton::popup();
360} 364}
361 365
362void KToolBarButton::setPopup(QPopupMenu *p, bool) 366void KToolBarButton::setPopup(Q3PopupMenu *p, bool)
363{ 367{
364 QToolButton::setPopup(p); 368 QToolButton::setPopup(p);
365 QToolButton::setPopupDelay(1); 369 QToolButton::setPopupDelay(1);
366} 370}
367 371
368 372
369void KToolBarButton::setDelayedPopup (QPopupMenu *p, bool) 373void KToolBarButton::setDelayedPopup (Q3PopupMenu *p, bool)
370{ 374{
371 QToolButton::setPopup(p); 375 QToolButton::setPopup(p);
372//US QToolButton::setPopupDelay(QApplication::startDragTime()); 376//US QToolButton::setPopupDelay(QApplication::startDragTime());
373} 377}
374 378
375void KToolBarButton::leaveEvent(QEvent *) 379void KToolBarButton::leaveEvent(QEvent *)
376{ 380{
377 if( d->m_isRaised || d->m_isActive ) 381 if( d->m_isRaised || d->m_isActive )
378 { 382 {
379 d->m_isRaised = false; 383 d->m_isRaised = false;
380 d->m_isActive = false; 384 d->m_isActive = false;
381 repaint(false); 385 repaint(false);
382 } 386 }
383 387
384 emit highlighted(d->m_id, false); 388 emit highlighted(d->m_id, false);
385} 389}
386 390
387void KToolBarButton::enterEvent(QEvent *) 391void KToolBarButton::enterEvent(QEvent *)
388{ 392{
389 if (d->m_highlight) 393 if (d->m_highlight)
390 { 394 {
391 if (isEnabled()) 395 if (isEnabled())
392 { 396 {
393 d->m_isActive = true; 397 d->m_isActive = true;
394 if (!isToggleButton()) 398 if (!isToggleButton())
395 d->m_isRaised = true; 399 d->m_isRaised = true;
396 } 400 }
397 else 401 else
398 { 402 {
399 d->m_isRaised = false; 403 d->m_isRaised = false;
400 d->m_isActive = false; 404 d->m_isActive = false;
401 } 405 }
402 406
403 repaint(false); 407 repaint(false);
404 } 408 }
405 emit highlighted(d->m_id, true); 409 emit highlighted(d->m_id, true);
406} 410}
407 411
408bool KToolBarButton::eventFilter(QObject *o, QEvent *ev) 412bool KToolBarButton::eventFilter(QObject *o, QEvent *ev)
409{ 413{
410 if ((KToolBarButton *)o == this) 414 if ((KToolBarButton *)o == this)
411 { 415 {
412 416
413 // Popup the menu when the left mousebutton is pressed and the mouse 417 // Popup the menu when the left mousebutton is pressed and the mouse
414 // is moved by a small distance. 418 // is moved by a small distance.
415 if (QToolButton::popup()) 419 if (QToolButton::popup())
416 { 420 {
417 if (ev->type() == QEvent::MouseButtonPress) 421 if (ev->type() == QEvent::MouseButtonPress)
418 { 422 {
419 QMouseEvent* mev = static_cast<QMouseEvent*>(ev); 423 QMouseEvent* mev = static_cast<QMouseEvent*>(ev);
420 d->m_mousePressPos = mev->pos(); 424 d->m_mousePressPos = mev->pos();
421 } 425 }
422 else if (ev->type() == QEvent::MouseMove) 426 else if (ev->type() == QEvent::MouseMove)
423 { 427 {
424 QMouseEvent* mev = static_cast<QMouseEvent*>(ev); 428 QMouseEvent* mev = static_cast<QMouseEvent*>(ev);
425 if ((mev->pos() - d->m_mousePressPos).manhattanLength() 429 if ((mev->pos() - d->m_mousePressPos).manhattanLength()
426//US > KGlobalSettings::dndEventDelay()) 430//US > KGlobalSettings::dndEventDelay())
427 > 5 ) 431 > 5 )
428 { 432 {
429//US openPopup(); 433//US openPopup();
430 return true; 434 return true;
431 } 435 }
432 } 436 }
433 } 437 }
434 438
435 if ((ev->type() == QEvent::MouseButtonPress || 439 if ((ev->type() == QEvent::MouseButtonPress ||
436 ev->type() == QEvent::MouseButtonRelease || 440 ev->type() == QEvent::MouseButtonRelease ||
437 ev->type() == QEvent::MouseButtonDblClick) && d->m_isRadio && isOn()) 441 ev->type() == QEvent::MouseButtonDblClick) && d->m_isRadio && isOn())
438 return true; 442 return true;
439 443
440 // From Kai-Uwe Sattler <kus@iti.CS.Uni-Magdeburg.De> 444 // From Kai-Uwe Sattler <kus@iti.CS.Uni-Magdeburg.De>
441 if (ev->type() == QEvent::MouseButtonDblClick) 445 if (ev->type() == QEvent::MouseButtonDblClick)
442 { 446 {
443 emit doubleClicked(d->m_id); 447 emit doubleClicked(d->m_id);
444 return true; 448 return true;
445 } 449 }
446 } 450 }
447 451
448 return QToolButton::eventFilter(o, ev); 452 return QToolButton::eventFilter(o, ev);
449} 453}
450 454
451void KToolBarButton::drawButton( QPainter *_painter ) 455void KToolBarButton::drawButton( QPainter *_painter )
452{ 456{
453#ifdef DESKTOP_VERSION 457#ifdef DESKTOP_VERSION
454 QStyle::SFlags flags = QStyle::Style_Default; 458 QStyle::State flags = QStyle::State_None;
455 QStyle::SCFlags active = QStyle::SC_None; 459 QStyle::SubControls active = QStyle::SC_None;
456 460
457 if (isDown()) { 461 if (isDown()) {
458 flags |= QStyle::Style_Down; 462 flags |= QStyle::State_DownArrow;
459 active |= QStyle::SC_ToolButton; 463 active |= QStyle::SC_ToolButton;
460 } 464 }
461 if (isEnabled()) flags |= QStyle::Style_Enabled; 465 if (isEnabled()) flags |= QStyle::State_Enabled;
462 if (isOn()) flags |= QStyle::Style_On; 466 if (isOn()) flags |= QStyle::State_On;
463 if (isEnabled() && d->m_isRaised)flags |= QStyle::Style_Raised; 467 if (isEnabled() && d->m_isRaised)flags |= QStyle::State_Raised;
464 if (hasFocus())flags |= QStyle::Style_HasFocus; 468 if (hasFocus())flags |= QStyle::State_HasFocus;
469
470 QStyleOptionToolButton qsotb;
471 qsotb.initFrom(this);
472 qsotb.state = flags;
473 qsotb.activeSubControls = active;
474 qsotb.rect = rect();
475 qsotb.palette = palette();
465 476
466 // Draw a styled toolbutton 477 // Draw a styled toolbutton
467 style().drawComplexControl(QStyle::CC_ToolButton, _painter, this, rect(), 478 style()->drawComplexControl(QStyle::CC_ToolButton, &qsotb, _painter, this);
468 colorGroup(), flags, QStyle::SC_ToolButton, active, QStyleOption());
469 479
470#else 480#else
471 style().drawToolButton(_painter, rect().x(), rect().y(), rect().width(), rect().height(), colorGroup()); 481 style().drawToolButton(_painter, rect().x(), rect().y(), rect().width(), rect().height(), colorGroup());
472#endif 482#endif
473 int dx, dy; 483 int dx, dy;
474 QFont tmp_font(KGlobalSettings::toolBarFont()); 484 QFont tmp_font(KGlobalSettings::toolBarFont());
475 QFontMetrics fm(tmp_font); 485 QFontMetrics fm(tmp_font);
476 QRect textRect; 486 QRect textRect;
477 int textFlags = 0; 487 int textFlags = 0;
478 488
479 if (d->m_iconText == KToolBar::IconOnly) // icon only 489 if (d->m_iconText == KToolBar::IconOnly) // icon only
480 { 490 {
481/*US 491/*US
482 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, 492 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic,
483 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : 493 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) :
484 QIconSet::Disabled, 494 QIconSet::Disabled,
485 isOn() ? QIconSet::On : QIconSet::Off ); 495 isOn() ? QIconSet::On : QIconSet::Off );
486*/ 496*/
487 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, 497 QPixmap pixmap = iconSet().pixmap( QIcon::Automatic,
488 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : 498 isEnabled() ? (d->m_isActive ? QIcon::Active : QIcon::Normal) :
489 QIconSet::Disabled); 499 QIcon::Disabled);
490 500
491 if( !pixmap.isNull()) 501 if( !pixmap.isNull())
492 { 502 {
493 dx = ( width() - pixmap.width() ) / 2; 503 dx = ( width() - pixmap.width() ) / 2;
494 dy = ( height() - pixmap.height() ) / 2; 504 dy = ( height() - pixmap.height() ) / 2;
495 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ ) 505 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ )
496 { 506 {
497 ++dx; 507 ++dx;
498 ++dy; 508 ++dy;
499 } 509 }
500 _painter->drawPixmap( dx, dy, pixmap ); 510 _painter->drawPixmap( dx, dy, pixmap );
501 } 511 }
502 } 512 }
503 else if (d->m_iconText == KToolBar::IconTextRight) // icon and text (if any) 513 else if (d->m_iconText == KToolBar::IconTextRight) // icon and text (if any)
504 { 514 {
505/*US 515/*US
506 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, 516 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic,
507 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : 517 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) :
508 QIconSet::Disabled, 518 QIconSet::Disabled,
509 isOn() ? QIconSet::On : QIconSet::Off ); 519 isOn() ? QIconSet::On : QIconSet::Off );
510*/ 520*/
511 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, 521 QPixmap pixmap = iconSet().pixmap( QIcon::Automatic,
512 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : 522 isEnabled() ? (d->m_isActive ? QIcon::Active : QIcon::Normal) :
513 QIconSet::Disabled); 523 QIcon::Disabled);
514 524
515 if( !pixmap.isNull()) 525 if( !pixmap.isNull())
516 { 526 {
517 dx = 4; 527 dx = 4;
518 dy = ( height() - pixmap.height() ) / 2; 528 dy = ( height() - pixmap.height() ) / 2;
519 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ ) 529 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ )
520 { 530 {
521 ++dx; 531 ++dx;
522 ++dy; 532 ++dy;
523 } 533 }
524 _painter->drawPixmap( dx, dy, pixmap ); 534 _painter->drawPixmap( dx, dy, pixmap );
525 } 535 }
526 536
527 if (!textLabel().isNull()) 537 if (!textLabel().isNull())
528 { 538 {
529 textFlags = AlignVCenter|AlignLeft; 539 textFlags = Qt::AlignVCenter|Qt::AlignLeft;
530 if (!pixmap.isNull()) 540 if (!pixmap.isNull())
531 dx = 4 + pixmap.width() + 2; 541 dx = 4 + pixmap.width() + 2;
532 else 542 else
533 dx = 4; 543 dx = 4;
534 dy = 0; 544 dy = 0;
535 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ ) 545 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ )
536 { 546 {
537 ++dx; 547 ++dx;
538 ++dy; 548 ++dy;
539 } 549 }
540 textRect = QRect(dx, dy, width()-dx, height()); 550 textRect = QRect(dx, dy, width()-dx, height());
541 } 551 }
542 } 552 }
543 else if (d->m_iconText == KToolBar::TextOnly) 553 else if (d->m_iconText == KToolBar::TextOnly)
544 { 554 {
545 if (!textLabel().isNull()) 555 if (!textLabel().isNull())
546 { 556 {
547 textFlags = AlignVCenter|AlignLeft; 557 textFlags = Qt::AlignVCenter|Qt::AlignLeft;
548 dx = (width() - fm.width(textLabel())) / 2; 558 dx = (width() - fm.width(textLabel())) / 2;
549 dy = (height() - fm.lineSpacing()) / 2; 559 dy = (height() - fm.lineSpacing()) / 2;
550 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ ) 560 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ )
551 { 561 {
552 ++dx; 562 ++dx;
553 ++dy; 563 ++dy;
554 } 564 }
555 textRect = QRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() ); 565 textRect = QRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() );
556 } 566 }
557 } 567 }
558 else if (d->m_iconText == KToolBar::IconTextBottom) 568 else if (d->m_iconText == KToolBar::IconTextBottom)
559 { 569 {
560/*US 570/*US
561 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, 571 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic,
562 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : 572 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) :
563 QIconSet::Disabled, 573 QIconSet::Disabled,
564 isOn() ? QIconSet::On : QIconSet::Off ); 574 isOn() ? QIconSet::On : QIconSet::Off );
565*/ 575*/
566 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, 576 QPixmap pixmap = iconSet().pixmap( QIcon::Automatic,
567 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : 577 isEnabled() ? (d->m_isActive ? QIcon::Active : QIcon::Normal) :
568 QIconSet::Disabled); 578 QIcon::Disabled);
569 579
570 if( !pixmap.isNull()) 580 if( !pixmap.isNull())
571 { 581 {
572 dx = (width() - pixmap.width()) / 2; 582 dx = (width() - pixmap.width()) / 2;
573 dy = (height() - fm.lineSpacing() - pixmap.height()) / 2; 583 dy = (height() - fm.lineSpacing() - pixmap.height()) / 2;
574 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ ) 584 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ )
575 { 585 {
576 ++dx; 586 ++dx;
577 ++dy; 587 ++dy;
578 } 588 }
579 _painter->drawPixmap( dx, dy, pixmap ); 589 _painter->drawPixmap( dx, dy, pixmap );
580 } 590 }
581 591
582 if (!textLabel().isNull()) 592 if (!textLabel().isNull())
583 { 593 {
584 textFlags = AlignBottom|AlignHCenter; 594 textFlags = Qt::AlignBottom|Qt::AlignHCenter;
585 dx = (width() - fm.width(textLabel())) / 2; 595 dx = (width() - fm.width(textLabel())) / 2;
586 dy = height() - fm.lineSpacing() - 4; 596 dy = height() - fm.lineSpacing() - 4;
587 597
588 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ ) 598 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ )
589 { 599 {
590 ++dx; 600 ++dx;
591 ++dy; 601 ++dy;
592 } 602 }
593 textRect = QRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() ); 603 textRect = QRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() );
594 } 604 }
595 } 605 }
596 606
597 // Draw the text at the position given by textRect, and using textFlags 607 // Draw the text at the position given by textRect, and using textFlags
598 if (!textLabel().isNull() && !textRect.isNull()) 608 if (!textLabel().isNull() && !textRect.isNull())
599 { 609 {
600 _painter->setFont(KGlobalSettings::toolBarFont()); 610 _painter->setFont(KGlobalSettings::toolBarFont());
601 if (!isEnabled()) 611 if (!isEnabled())
602 _painter->setPen(palette().disabled().dark()); 612 _painter->setPen(palette().disabled().dark());
603 else if(d->m_isRaised) 613 else if(d->m_isRaised)
604 _painter->setPen(KGlobalSettings::toolBarHighlightColor()); 614 _painter->setPen(KGlobalSettings::toolBarHighlightColor());
605 else 615 else
606 _painter->setPen( colorGroup().buttonText() ); 616 _painter->setPen( colorGroup().buttonText() );
607 _painter->drawText(textRect, textFlags, textLabel()); 617 _painter->drawText(textRect, textFlags, textLabel());
608 } 618 }
609 619
610 if (QToolButton::popup()) 620 if (QToolButton::popup())
611 { 621 {
612#ifdef DESKTOP_VERSION 622#ifdef DESKTOP_VERSION
613 QStyle::SFlags arrowFlags = QStyle::Style_Default; 623 QStyle::State arrowFlags = QStyle::State_None;
624
625 if (isDown())arrowFlags |= QStyle::State_DownArrow;
626 if (isEnabled()) arrowFlags |= QStyle::State_Enabled;
614 627
615 if (isDown())arrowFlags |= QStyle::Style_Down; 628 QStyleOption qso;
616 if (isEnabled()) arrowFlags |= QStyle::Style_Enabled; 629 qso.initFrom(this);
630 qso.state = arrowFlags;
631 qso.rect = QRect(width()-7, height()-7, 7, 7);
632 qso.palette = palette();
617 633
618 style().drawPrimitive(QStyle::PE_ArrowDown, _painter, 634 style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &qso, _painter);
619 QRect(width()-7, height()-7, 7, 7), colorGroup(),
620 arrowFlags, QStyleOption() );
621#else 635#else
622 style().drawArrow(_painter, Qt::DownArrow, isDown(), 636 style().drawArrow(_painter, Qt::DownArrow, isDown(),
623 width()-7, height()-7, 7, 7, colorGroup(), isEnabled() ); 637 width()-7, height()-7, 7, 7, colorGroup(), isEnabled() );
624#endif 638#endif
625 639
626 } 640 }
627} 641}
628 642
629void KToolBarButton::paletteChange(const QPalette &) 643void KToolBarButton::paletteChange(const QPalette &)
630{ 644{
631 if(!d->m_isSeparator) 645 if(!d->m_isSeparator)
632 { 646 {
633 modeChange(); 647 modeChange();
634 repaint(false); // no need to delete it first therefore only false 648 repaint(false); // no need to delete it first therefore only false
635 } 649 }
636} 650}
637 651
638void KToolBarButton::showMenu() 652void KToolBarButton::showMenu()
639{ 653{
640 // obsolete 654 // obsolete
641 // KDE4: remove me 655 // KDE4: remove me
642} 656}
643 657
644void KToolBarButton::slotDelayTimeout() 658void KToolBarButton::slotDelayTimeout()
645{ 659{
646 // obsolete 660 // obsolete
647 // KDE4: remove me 661 // KDE4: remove me
648} 662}
649 663
650void KToolBarButton::slotClicked() 664void KToolBarButton::slotClicked()
651{ 665{
652 emit clicked( d->m_id ); 666 emit clicked( d->m_id );
653} 667}
654 668
655void KToolBarButton::slotPressed() 669void KToolBarButton::slotPressed()
656{ 670{
657 emit pressed( d->m_id ); 671 emit pressed( d->m_id );
658} 672}
659 673
660void KToolBarButton::slotReleased() 674void KToolBarButton::slotReleased()
661{ 675{
662 emit released( d->m_id ); 676 emit released( d->m_id );
663} 677}
664 678
665void KToolBarButton::slotToggled() 679void KToolBarButton::slotToggled()
666{ 680{
667 emit toggled( d->m_id ); 681 emit toggled( d->m_id );
668} 682}