KBFX – an alternative to T-Menu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

140 lines
3.3 KiB

  1. /*
  2. * Copyright (C) 2006
  3. * Siraj Razick <siraj@kdemail.net>
  4. * PhobosK <phobosk@mail.kbfx.net>
  5. * see Also AUTHORS
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Library General Public License version 2 as
  9. * published by the Free Software Foundation
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this program; if not, write to the
  18. * Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. */
  21. #include "kbfxspinxtoolbutton.h"
  22. KbfxSpinxToolButton::KbfxSpinxToolButton ( TQWidget * parent , const char * name ) :TQLabel ( parent,name,TQt::WStaticContents | TQt::WNoAutoErase |TQt::WPaintDesktop )
  23. {
  24. m_dataSource = 0;
  25. m_dataGroup = 0;
  26. m_fadeTime = ConfigInit().m_fadeTime;
  27. fade_timer = new TQTimer ( this,"Fade Timer" );
  28. connect ( fade_timer,TQT_SIGNAL ( timeout() ),this,TQT_SLOT ( fade() ) );
  29. }
  30. KbfxSpinxToolButton::~KbfxSpinxToolButton()
  31. {}
  32. void KbfxSpinxToolButton::fade ( )
  33. {
  34. if ( m_fadeTime == 0 )
  35. {
  36. m_current = m_fadePix;
  37. }
  38. else
  39. {
  40. TQImage _final = m_fadePix.convertToImage ();
  41. TQImage _current = m_current.convertToImage ();
  42. if ( !fade_timer->isActive ())
  43. {
  44. m_opacity = 0;
  45. fade_timer->start( m_fadeTime, false);
  46. }
  47. if ( m_opacity > 0.9 )
  48. fade_timer->stop();
  49. m_opacity += 0.1;
  50. KImageEffect::blend ( _final, _current, m_opacity);
  51. m_current = TQPixmap ( _current );
  52. }
  53. this->resize ( m_current.size() );
  54. this->update();
  55. }
  56. void
  57. KbfxSpinxToolButton::enterEvent ( TQEvent * e )
  58. {
  59. e = e;
  60. m_fadePix = m_hover;
  61. fade();
  62. this->setCursor ( TQCursor ( TQt::PointingHandCursor ) );
  63. }
  64. void
  65. KbfxSpinxToolButton::leaveEvent ( TQEvent * e )
  66. {
  67. e = e;
  68. m_fadePix = m_normal;
  69. fade();
  70. this->setCursor ( TQCursor ( TQt::ArrowCursor ) );
  71. }
  72. void
  73. KbfxSpinxToolButton::setPixmaps ( TQPixmap normal, TQPixmap hover )
  74. {
  75. TQSize _sizeNormal = normal.size();
  76. TQImage _tmpHover = hover.convertToImage ();
  77. _tmpHover = _tmpHover.smoothScale ( _sizeNormal, TQ_ScaleFree );
  78. m_normal = normal;
  79. m_hover = TQPixmap ( _tmpHover );
  80. m_current = m_normal;
  81. resize ( m_current.size () );
  82. this->repaint();
  83. this->update();
  84. }
  85. void
  86. KbfxSpinxToolButton::setDataSource ( KbfxDataSource * src )
  87. {
  88. m_name = src->name();
  89. m_icon = src->icon();
  90. m_exe = src->command();
  91. m_dataSource = new KbfxDataSource();
  92. *m_dataSource = *src; // copy
  93. TDEIconLoader *iconload = TDEGlobal::iconLoader ();
  94. TQString m_iconPath = iconload->iconPath ( m_icon, TDEIcon::Desktop, false );
  95. m_iconPixmap = TQPixmap ( m_iconPath );
  96. }
  97. void
  98. KbfxSpinxToolButton::paintEvent ( TQPaintEvent * e )
  99. {
  100. TQRect r = e->rect();
  101. TQPainter p;
  102. TQPixmap buffer ( m_current.size() );
  103. buffer.fill();
  104. p.begin ( this );
  105. p.setPen ( TQColor ( 255,255,255 ) );
  106. p.drawPixmap ( TQRect ( 0, 0, m_current.width(), m_current.height() ), m_current );
  107. p.end();
  108. }
  109. void
  110. KbfxSpinxToolButton::mouseReleaseEvent ( TQMouseEvent * me )
  111. {
  112. me = me;
  113. if ( m_dataSource == 0 )
  114. return;
  115. else
  116. KRun::runCommand ( m_dataSource->command() );
  117. emit clicked();
  118. }
  119. #include "kbfxspinxtoolbutton.moc"