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.

143 lines
3.2KB

  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 "kbfxspinxscrollbar.h"
  22. KbfxSpinxScrollBar::KbfxSpinxScrollBar ( TQWidget * parent, const char *name, int type ) :
  23. TQWidget ( parent, name )
  24. {
  25. if (type == 0){
  26. m_normal = ( *KbfxPlasmaPixmapProvider::pixmap ( "scrollnormal" ) );
  27. } else {
  28. m_normal = ( *KbfxPlasmaPixmapProvider::pixmap ( "scrollnormalbot" ) );
  29. }
  30. TQImage _tmp_img = m_normal.convertToImage();
  31. _tmp_img = _tmp_img.smoothScale ( ConfigInit().m_itemView_w, m_normal.height (),TQ_ScaleFree );
  32. m_normal = TQPixmap ( _tmp_img );
  33. this->resize ( m_normal.width (), m_normal.height () );
  34. _x = this->x () /40;
  35. _y = this->y ();
  36. w = this->width () / 40;
  37. h = this->height () / 2;
  38. _x += ( this->width () - w ) / 2;
  39. _y += ( this->height () - h ) / 2;
  40. m_triAngle = TQPointArray ( 3 );
  41. m_dir = DOWN;
  42. m_timer = new TQTimer ( this,"ScrollTimer" );
  43. connect ( m_timer,TQT_SIGNAL ( timeout() ),this,TQT_SLOT ( timeoutslot() ) );
  44. m_pressed = false;
  45. }
  46. KbfxSpinxScrollBar::~KbfxSpinxScrollBar ()
  47. {}
  48. void
  49. KbfxSpinxScrollBar::paintEvent ( TQPaintEvent * pe )
  50. {
  51. TQRect r = pe->rect();
  52. TQPainter p;
  53. p.begin ( this );
  54. p.drawPixmap ( TQRect ( 0, 0, m_normal.width (), m_normal.height () ),
  55. m_normal );
  56. p.setPen ( TQColor ( 255,255,255 ) );
  57. if ( m_pressed == false )
  58. p.setBrush ( TQColor ( 255,255,255 ) );
  59. else
  60. p.setBrush ( TQColor ( 0,0,0 ) );
  61. p.drawPolygon ( m_triAngle );
  62. p.end ();
  63. }
  64. void
  65. KbfxSpinxScrollBar::setType ( Direction dir )
  66. {
  67. if ( dir == DOWN )
  68. {
  69. m_triAngle.setPoint ( 0, _x, _y );
  70. m_triAngle.setPoint ( 1, _x + w, _y );
  71. m_triAngle.setPoint ( 2, _x + w / 2, _y + h );
  72. }
  73. else if ( dir == UP )
  74. {
  75. m_triAngle.setPoint ( 0, _x, _y + h );
  76. m_triAngle.setPoint ( 1, _x + w, _y + h );
  77. m_triAngle.setPoint ( 2, _x + w / 2, _y );
  78. }
  79. m_dir = dir;
  80. }
  81. void
  82. KbfxSpinxScrollBar::mousePressEvent ( TQMouseEvent * me )
  83. {
  84. me = me;
  85. m_pressed = true;
  86. m_timer->start ( 50,false );
  87. update();
  88. }
  89. void
  90. KbfxSpinxScrollBar::mouseReleaseEvent ( TQMouseEvent * me )
  91. {
  92. me = me;
  93. m_pressed = false;
  94. m_timer->stop();
  95. update();
  96. }
  97. void
  98. KbfxSpinxScrollBar::enterEvent ( TQEvent * e )
  99. {
  100. e = e;
  101. m_pressed = true;
  102. m_timer->start ( 50,false );
  103. update();
  104. }
  105. void
  106. KbfxSpinxScrollBar::leaveEvent ( TQEvent *e )
  107. {
  108. e =e ;
  109. m_pressed = false;
  110. m_timer->stop();
  111. update();
  112. }
  113. void
  114. KbfxSpinxScrollBar::timeoutslot()
  115. {
  116. if ( m_dir == DOWN )
  117. emit scroll ( 0,20 );
  118. else if ( m_dir == UP )
  119. emit scroll ( 0,-20 );
  120. }
  121. #include "kbfxspinxscrollbar.moc"