~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to lib/kofficeui/tktoolbarbutton.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040509113300-xi5t1z4yxe7n03x7
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
#include <tktoolbarbutton.h>
20
20
 
21
 
#include <qimage.h>
22
21
#include <qtimer.h>
23
 
#include <qdrawutil.h>
24
22
#include <qtooltip.h>
25
 
#include <qbitmap.h>
26
23
#include <qpopupmenu.h>
 
24
#include <qcursor.h>
 
25
#include <qpainter.h>
 
26
#include <qdrawutil.h>
 
27
#include <qstyle.h>
27
28
 
28
 
#include <kapp.h>
29
 
#include <kglobal.h>
30
 
#include <kstyle.h>
31
 
#include <kglobalsettings.h>
 
29
#include <kdeversion.h>
 
30
#include <kapplication.h>
32
31
#include <kiconeffect.h>
33
32
#include <kiconloader.h>
34
 
 
35
 
// needed to get our instance
36
 
#include <kmainwindow.h>
 
33
#include <kglobalsettings.h>
37
34
 
38
35
// Delay in ms before delayed popup pops up
39
36
#define POPUP_DELAY 500
93
90
TKToolBarButton::TKToolBarButton( const QString& icon, const QString& txt,
94
91
                                        QWidget* parent, const char* name,
95
92
                                        KInstance *instance )
96
 
: QButton(parent,name)
 
93
: QToolButton(parent,name)
97
94
{
98
95
  d = new TKToolBarButtonPrivate;
99
96
  d->m_text = txt;
112
109
}
113
110
 
114
111
TKToolBarButton::TKToolBarButton( const QPixmap& pixmap, const QString& txt, QWidget* parent, const char* name )
115
 
: QButton(parent,name )
 
112
: QToolButton(parent,name )
116
113
{
117
114
  d = new TKToolBarButtonPrivate;
118
115
  d->m_text = txt;
177
174
  if (isEnabled()==enabled)
178
175
    return;
179
176
 
180
 
  QButton::setPixmap( (enabled ? defaultPixmap : disabledPixmap) );
181
 
  QButton::setEnabled( enabled );
 
177
  QToolButton::setPixmap( (enabled ? defaultPixmap : disabledPixmap) );
 
178
  QToolButton::setEnabled( enabled );
182
179
}
183
180
 
184
181
void TKToolBarButton::setText( const QString& text)
238
235
      disabledPixmap = activePixmap;
239
236
  }
240
237
 
241
 
  QButton::setPixmap( isEnabled() ? defaultPixmap : disabledPixmap );
 
238
  QToolButton::setPixmap( isEnabled() ? defaultPixmap : disabledPixmap );
242
239
}
243
240
 
244
241
void TKToolBarButton::setDefaultPixmap( const QPixmap &pixmap )
245
242
{
246
243
  defaultPixmap = pixmap;
247
 
  QButton::setPixmap( isEnabled() ? defaultPixmap : disabledPixmap );
 
244
  QToolButton::setPixmap( isEnabled() ? defaultPixmap : disabledPixmap );
248
245
}
249
246
 
250
247
void TKToolBarButton::setDisabledPixmap( const QPixmap &pixmap )
251
248
{
252
249
  disabledPixmap = pixmap;
253
 
  QButton::setPixmap( isEnabled() ? defaultPixmap : disabledPixmap );
 
250
  QToolButton::setPixmap( isEnabled() ? defaultPixmap : disabledPixmap );
254
251
}
255
252
 
256
253
void TKToolBarButton::setPopup(QPopupMenu *p)
294
291
void TKToolBarButton::leaveEvent(QEvent *)
295
292
{
296
293
  if (!d->m_isToggle && !(d->m_popup && d->m_popup->isVisible()) ) {
297
 
    QButton::setPixmap(isEnabled() ? defaultPixmap : disabledPixmap);
 
294
    QToolButton::setPixmap(isEnabled() ? defaultPixmap : disabledPixmap);
298
295
    if (d->m_autoRaised)
299
296
      setRaised(false);
300
297
  }
304
301
{
305
302
  if (!d->m_isToggle) {
306
303
    if (isEnabled()) {
307
 
      QButton::setPixmap(activePixmap);
 
304
      QToolButton::setPixmap(activePixmap);
308
305
      if (d->m_autoRaised)
309
306
        setRaised(true);
310
307
    } else {
311
 
      QButton::setPixmap(disabledPixmap);
 
308
      QToolButton::setPixmap(disabledPixmap);
312
309
    }
313
310
    repaint(false);
314
311
  }
355
352
#define DRAW_PIXMAP_AND_TEXT \
356
353
  int x = 3;\
357
354
  if (pixmap()) {\
358
 
    style().drawItem( p, x, 0, pixmap()->width(), height(), AlignCenter, colorGroup(), isEnabled(), pixmap(), QString::null );\
 
355
    style().drawItem( p, QRect( x, 0, pixmap()->width(), height() ), AlignCenter, colorGroup(), isEnabled(), pixmap(), QString::null );\
359
356
    if (d->m_iconMode==TK::IconAndText && !d->m_text.isEmpty()) {\
360
357
      x += pixmap()->width() + 3;\
361
358
    }\
362
359
  }\
363
360
  if ((d->m_iconMode==TK::IconAndText||d->m_iconMode==TK::TextOnly) && !d->m_text.isEmpty()) {\
364
 
    QFontMetrics fm(ref_font);\
365
 
    style().drawItem( p, x, 0, fm.width(d->m_text), height(), AlignCenter, colorGroup(), isEnabled(), 0, d->m_text );\
 
361
    QFontMetrics fm(KGlobalSettings::toolBarFont());\
 
362
    style().drawItem( p, QRect( x, 0, fm.width(d->m_text), height() ), AlignCenter, colorGroup(), isEnabled(), 0, d->m_text );\
366
363
  }
367
364
 
368
365
  const char* arrow[] = {
374
371
  "..###..",
375
372
  "...#..."};
376
373
  QPixmap arrow_pix(arrow);
377
 
 
378
 
  KStyle::KToolButtonType iconType = d->m_iconMode != TK::IconOnly ? KStyle::IconTextRight : KStyle::Icon;
379
 
  QFont ref_font(KGlobalSettings::toolBarFont());
380
374
  bool f = d->m_isOn || isDown();
381
375
 
382
 
  if (d->m_popup && !d->m_isToggle)
383
 
  {
384
 
    if (d->m_isPopup)
 
376
    if (d->m_popup && !d->m_isToggle)
385
377
    {
386
 
      if (kapp->kstyle()) {
387
 
        kapp->kstyle()->drawKToolBarButton(p, 0, 0, width()-12, height(),
388
 
          isEnabled()? colorGroup() : palette().disabled(), f && !d->m_arrowPressed,
389
 
          d->m_isRaised, isEnabled(), false, iconType, d->m_text,
390
 
          pixmap(), &ref_font, this);
391
 
        kapp->kstyle()->drawKToolBarButton(p, width()-13, 0, 13, height(),
392
 
          isEnabled()? colorGroup() : palette().disabled(), f && d->m_arrowPressed,
393
 
          d->m_isRaised, isEnabled(), false, KStyle::Icon, "",
394
 
          &arrow_pix, &ref_font, this);
395
 
      } else {
396
 
        style().drawToolButton( p, 0, 0, width()-12, height(), isEnabled() ? colorGroup() : palette().disabled(), f && !d->m_arrowPressed );
 
378
        if (d->m_isPopup)
 
379
        {
 
380
            QStyle::SFlags flags   = QStyle::Style_Default;
 
381
            if (isEnabled())    flags |= QStyle::Style_Enabled;
 
382
            if (isOn())                 flags |= QStyle::Style_On;
 
383
            if (d->m_isRaised)  flags |= QStyle::Style_Raised;
 
384
            if (hasFocus())     flags |= QStyle::Style_HasFocus;
397
385
 
398
 
        style().drawToolButton( p, width()-13, 0, 13, height(), isEnabled() ? colorGroup() : palette().disabled(), f && d->m_arrowPressed );
399
 
        style().drawItem( p, width()-13, 0, 13, height(), AlignCenter, colorGroup(), isEnabled(), &arrow_pix, QString::null );
400
 
        DRAW_PIXMAP_AND_TEXT
401
 
      }
402
 
    } else {
403
 
      if (kapp->kstyle()) {
404
 
        kapp->kstyle()->drawKToolBarButton(p, 0, 0, width(), height(),
405
 
          isEnabled()? colorGroup() : palette().disabled(), f,
406
 
          d->m_isRaised, isEnabled(), false, KStyle::IconTextRight, d->m_iconMode != TK::IconOnly ? d->m_text:QString(""),
407
 
          pixmap(), &ref_font, this);
408
 
      } else {
409
 
        style().drawToolButton( p, 0, 0, width(), height(), isEnabled() ? colorGroup() : palette().disabled(), f );
410
 
        DRAW_PIXMAP_AND_TEXT
411
 
      }
412
 
      int z = f ? 1:0;
413
 
      p->drawPixmap(width()-11+z,(height()-4)/2+z ,arrow_pix);
414
 
    }
415
 
  } else {
416
 
    if (kapp->kstyle()) {
417
 
      kapp->kstyle()->drawKToolBarButton(p, 0, 0, width(), height(),
418
 
        isEnabled()? colorGroup() : palette().disabled(), f,
419
 
        d->m_isRaised, isEnabled(), d->m_popup, iconType, d->m_text,
420
 
        pixmap(), &ref_font, this);
421
 
    } else {
422
 
      style().drawToolButton( p, 0, 0, width(), height(), isEnabled() ? colorGroup() : palette().disabled(), f );
423
 
      DRAW_PIXMAP_AND_TEXT
424
 
    }
425
 
  }
 
386
            style().drawComplexControl( QStyle::CC_ToolButton, p, this, QRect( 0, 0, width()-12, height() ), colorGroup(), flags, QStyle::SC_ToolButton );
 
387
            style().drawComplexControl( QStyle::CC_ToolButton, p, this, QRect( width()-13, 0, 13, height() ), colorGroup(), flags, QStyle::SC_ToolButton );
 
388
            style().drawItem( p, QRect( width()-13, 0, 13, height() ), AlignCenter, colorGroup(), isEnabled(), &arrow_pix, QString::null );
 
389
            if ( d->m_isRaised )
 
390
                qDrawShadeLine( p, width()-12, 0, width()-12, height(), colorGroup(), true );
 
391
            DRAW_PIXMAP_AND_TEXT
 
392
        } else {
 
393
            style().drawControl( QStyle::CE_PushButton, p, this, QRect( 0, 0, width(), height() ), isEnabled() ? colorGroup() : palette().disabled(), f );
 
394
            DRAW_PIXMAP_AND_TEXT
 
395
            int z = f ? 1:0;
 
396
            p->drawPixmap(width()-11+z,(height()-4)/2+z ,arrow_pix);
 
397
        }
 
398
    } else {
 
399
        style().drawControl( QStyle::CE_PushButton, p, this, QRect( 0, 0, width(), height() ), isEnabled() ? colorGroup() : palette().disabled(), f );
 
400
        DRAW_PIXMAP_AND_TEXT
 
401
    }
426
402
}
427
403
 
428
404
void TKToolBarButton::paletteChange(const QPalette &)
429
405
{
430
406
  makeDisabledPixmap();
431
407
  if ( !isEnabled() )
432
 
    QButton::setPixmap( disabledPixmap );
 
408
    QToolButton::setPixmap( disabledPixmap );
433
409
  else
434
 
    QButton::setPixmap( defaultPixmap );
 
410
    QToolButton::setPixmap( defaultPixmap );
435
411
  repaint(false);
436
412
}
437
413
 
453
429
  disabledPixmap = effect.apply(activePixmap, KIcon::Toolbar, KIcon::DisabledState);
454
430
}
455
431
 
 
432
QSize TKToolBarButton::sizeHint() const
 
433
{
 
434
    return minimumSize();
 
435
}
 
436
 
 
437
QSize TKToolBarButton::minimumSizeHint() const
 
438
{
 
439
    return minimumSize();
 
440
}
 
441
 
456
442
void TKToolBarButton::showMenu()
457
443
{
458
444
  QPoint p ( mapToGlobal( QPoint( 0, 0 ) ) );
459
 
  if ( p.y() + height() + d->m_popup->height() > KApplication::desktop()->height() )
 
445
#if KDE_IS_VERSION(3,1,90)
 
446
  const int deskHeight = KGlobalSettings::desktopGeometry(this).height();
 
447
#else
 
448
  const int deskHeight = QApplication::desktop()->height();
 
449
#endif
 
450
  if ( p.y() + height() + d->m_popup->height() > deskHeight )
460
451
      p.setY( p.y() - d->m_popup->height() );
461
452
  else
462
453
      p.setY( p.y() + height( ));