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