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.

311 lines
7.7KB

  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 "config.h"
  22. #include "kbfxtooltip.h"
  23. KbfxToolTip::KbfxToolTip ( TQWidget * parent, const char *name, WFlags fl ) :
  24. TQWidget ( parent, name,
  25. fl | WStyle_Customize | WRepaintNoErase | WStyle_NoBorder |
  26. WDestructiveClose | TQt::WPaintDesktop | TQt::WType_Popup | TQt::
  27. WPaintClever | TQt::WNoAutoErase | TQt::WResizeNoErase | TQt::
  28. WStaticContents | TQt::WNoAutoErase )
  29. {
  30. _animate = ConfigInit ().m_ToolTipAnimation;
  31. m_fontTooltipFont = ConfigInit ().m_fontTooltipFont;
  32. logo = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit().m_SpinxTooltipLogo ) ) ?
  33. TQImage ( ConfigInit().m_SpinxTooltipLogo )
  34. : TQImage ( ConfigInit().m_SpinxTooltipLogoDefault );
  35. tooltip_win = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_SpinxTooltipWindow ) ) ?
  36. TQImage ( ConfigInit ().m_SpinxTooltipWindow )
  37. : TQImage ( ConfigInit ().m_SpinxTooltipWindowDefault );
  38. tooltip_mask = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit().m_SpinxTooltipMask ) ) ?
  39. TQImage ( ConfigInit().m_SpinxTooltipMask )
  40. : TQImage ( ConfigInit().m_SpinxTooltipMaskDefault );
  41. dude_img = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_SpinxDudeImage ) ) ?
  42. TQImage ( ConfigInit ().m_SpinxDudeImage )
  43. : TQImage ( ConfigInit ().m_SpinxDudeImageDefault );
  44. setUserImage ();
  45. setBoundBox ();
  46. setBackground ( TQPixmap () );
  47. setWindow ( TQPixmap () );
  48. KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_ToolTipAvatar ) ?
  49. setAnimationImage ( ConfigInit ().m_ToolTipAvatar )
  50. : setAnimationImage ( ConfigInit ().m_ToolTipAvatarDefault );
  51. _hide_timer = new TQTimer ( this );
  52. _update_timer = new TQTimer ( this );
  53. _move_timer = new TQTimer ( this );
  54. connect ( _hide_timer, TQT_SIGNAL ( timeout () ), this, TQT_SLOT ( hide () ) );
  55. connect ( _hide_timer, TQT_SIGNAL ( timeout () ), _agent, TQT_SLOT ( hide () ) );
  56. connect ( _update_timer, TQT_SIGNAL ( timeout () ), this, TQT_SLOT ( logoMove () ) );
  57. TQCursor kbfxCursor;
  58. kbfxCursor.setShape ( Qt::PointingHandCursor );
  59. this->setCursor ( ( const TQCursor ) kbfxCursor );
  60. }
  61. KbfxToolTip::~KbfxToolTip ()
  62. {
  63. delete _hide_timer;
  64. delete _move_timer;
  65. delete _update_timer;
  66. delete _window;
  67. delete _agent;
  68. delete _agent_anim;
  69. }
  70. void
  71. KbfxToolTip::setWindow ( TQPixmap win )
  72. {
  73. TQImage m_win_img;
  74. ( win.isNull () ) ?
  75. m_win_img = tooltip_win
  76. : m_win_img = win.convertToImage ();
  77. m_win_img = m_win_img.smoothScale ( _bg.width (), 13 );
  78. // _window = new TQLabel (this, "", TQt::WStaticContents | TQt::WNoAutoErase);
  79. _window = new TQLabel ( this, "" );
  80. _window->resize ( _bg.width (), 13 );
  81. TQPixmap pm;
  82. pm.convertFromImage(m_win_img);
  83. _window->setBackgroundPixmap ( pm );
  84. if ( _animate )
  85. _window->show ();
  86. else
  87. _window->hide ();
  88. }
  89. void
  90. KbfxToolTip::setAnimationImage ( TQString path )
  91. {
  92. /*
  93. _agent = new TQLabel (this, "",
  94. TQt::WStaticContents |
  95. TQt::WNoAutoErase | TQt::WPaintDesktop);
  96. */
  97. _agent = new TQLabel ( this,"" );
  98. _agent->resize ( 100, 100 );
  99. _agent_anim = new TQMovie ( path );
  100. TQPixmap agent_mask = _agent_anim->framePixmap ();
  101. _agent->setBackgroundPixmap ( agent_mask );
  102. if ( agent_mask.mask () )
  103. _agent->setMask ( *agent_mask.mask () );
  104. _agent->repaint ();
  105. /*FIXME:Need to remove Hard Coded Values */
  106. _agent->move ( 200, 0 );
  107. if ( _animate )
  108. _agent->show ();
  109. else
  110. _agent->close ();
  111. }
  112. void
  113. KbfxToolTip::setBackground ( TQPixmap bg )
  114. {
  115. ( bg.isNull () ) ?
  116. _bg = tooltip_mask
  117. : _bg = bg.convertToImage ();
  118. /* animation check : Auto streatch */
  119. if ( _animate )
  120. {
  121. TQImage m_tmp = _bg;
  122. _bg = m_tmp.smoothScale ( _bg.width () + 100, _bg.height () );
  123. }
  124. TQPixmap pm;
  125. pm.convertFromImage(_bg);
  126. this->setBackgroundPixmap ( pm );
  127. TQPixmap m_tmp ( _bg );
  128. if ( m_tmp.mask () )
  129. this->setMask ( ( *m_tmp.mask () ) );
  130. this->resize ( _bg.width (), _bg.height () );
  131. _maxW = _bg.width ();
  132. }
  133. void
  134. KbfxToolTip::setStartPos ( int _x_, int _y_ )
  135. {
  136. _x = _x_;
  137. _y = _y_;
  138. _logo_move_x = 100;
  139. if ( _animate )
  140. {
  141. _logo_move_x = 0;
  142. _hide_timer->start ( 10000, TRUE );
  143. _move_timer->start ( _agent_anim->speed (), FALSE );
  144. _update_timer->start ( 2, FALSE );
  145. }
  146. move ( _x, _y );
  147. }
  148. void
  149. KbfxToolTip::logoMove ()
  150. {
  151. TQPainter p;
  152. if ( _logo_move_x < _bg.width () - 68 )
  153. {
  154. _logo_move_x += 1;
  155. _window->repaint ();
  156. p.begin ( _window );
  157. p.drawPixmap ( TQRect ( _logo_move_x, 0, logo.width (), logo.height () ),
  158. TQPixmap ( logo ) );
  159. p.end ();
  160. }
  161. else
  162. {
  163. p.begin ( _window );
  164. p.drawPixmap ( TQRect ( _bg.width () - 68, 0, logo.width (), logo.height () ),
  165. TQPixmap ( logo ) );
  166. p.end ();
  167. }
  168. TQPixmap agent_mask = _agent_anim->framePixmap ();
  169. _agent->setBackgroundPixmap ( agent_mask );
  170. if ( agent_mask.mask () )
  171. _agent->setMask ( *agent_mask.mask () );
  172. _agent->repaint ();
  173. }
  174. void
  175. KbfxToolTip::setAnimated ( bool b )
  176. {
  177. _animate = b;
  178. }
  179. void
  180. KbfxToolTip::setLabelText ( TQString str )
  181. {
  182. _label_text = str;
  183. }
  184. void
  185. KbfxToolTip::setHeadingText ( TQString str )
  186. {
  187. _heading_text = str;
  188. }
  189. void
  190. KbfxToolTip::setVersionText ( TQString str )
  191. {
  192. _version_text = str;
  193. }
  194. void
  195. KbfxToolTip::hideToolTip ()
  196. {
  197. _move_timer->stop ();
  198. _hide_timer->stop ();
  199. _agent->close ();
  200. this->hide ();
  201. this->close ();
  202. }
  203. void
  204. KbfxToolTip::setUserImage ()
  205. {
  206. TQImage userimage = dude_img;
  207. userimage = userimage.smoothScale ( 48, 48 );
  208. _dude = TQPixmap ( userimage );
  209. }
  210. void
  211. KbfxToolTip::setBoundBox ()
  212. {
  213. _dude_box = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_SpinxTooltipDudebox ) ) ?
  214. TQPixmap ( ConfigInit ().m_SpinxTooltipDudebox )
  215. : TQPixmap ( ConfigInit ().m_SpinxTooltipDudeboxDefault );
  216. }
  217. void
  218. KbfxToolTip::paintEvent ( TQPaintEvent * pe )
  219. {
  220. const TQRect r = pe->rect ();
  221. TQFont *let = new TQFont (m_fontTooltipFont);
  222. TQPainter p;
  223. p.begin ( this );
  224. p.setBackgroundMode ( Qt::TransparentMode );
  225. p.drawPixmap ( TQRect ( 7, 16, _dude_box.width (), _dude_box.height () ),
  226. _dude_box );
  227. int _paddingX = ( ( _dude_box.height () - _dude.height () ) / 2 ) + 16;
  228. p.drawPixmap ( TQRect
  229. ( _paddingX - ( 55 - 48 ), _paddingX, _dude.width (),
  230. _dude.height () ), _dude );
  231. if ( _animate )
  232. {}
  233. else
  234. {
  235. p.drawPixmap ( TQRect ( 126, 0, logo.width (), logo.height () ),
  236. TQPixmap ( TQImage (ConfigInit ().m_SpinxTooltipLogo ) ) );
  237. }
  238. let->setBold ( TRUE );
  239. let->setPointSize ( 10 );
  240. p.setFont ( *let );
  241. p.setPen ( TQColor ( 61, 94, 129 ) );
  242. p.drawText ( _dude_box.width () + 15, 30, TQString("KBFX") );
  243. p.setPen ( TQColor ( 0, 0, 0 ) );
  244. let->setBold ( FALSE );
  245. let->setPointSize ( 8 );
  246. p.setFont ( *let );
  247. p.drawText ( ( _animate ) ? _dude_box.width () + 50 : _dude_box.width () + 4,
  248. _dude_box.height () + 30, TQString ( "Version " ).append ( APPLICATION_VERSION ) );
  249. p.setPen ( ConfigInit ().m_fontTooltipColor );
  250. let->setBold ( TRUE );
  251. let->setPointSize ( 8 );
  252. p.setFont ( *let );
  253. p.drawText ( _dude_box.width () + 15, 43, ConfigInit ().m_ToolTipText );
  254. p.end ();
  255. delete let;
  256. }
  257. #include "kbfxtooltip.moc"