Bibletime – a bible study tool
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.

cscrollbutton.cpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*********
  2. *
  3. * This file is part of BibleTime's source code, http://www.bibletime.info/.
  4. *
  5. * Copyright 1999-2006 by the BibleTime developers.
  6. * The BibleTime source code is licensed under the GNU General Public License version 2.0.
  7. *
  8. **********/
  9. #include "cscrollbutton.h"
  10. #include "frontend/cbtconfig.h"
  11. #include <stdlib.h>
  12. #include <math.h>
  13. //TQt includes
  14. #include <tqevent.h>
  15. #include <tqapplication.h>
  16. #include <tqcursor.h>
  17. CScrollButton::CScrollButton(TQWidget *parent, const char *name ) : TQToolButton(parent,name) {
  18. setFocusPolicy(TQ_WheelFocus);
  19. setCursor( splitVCursor );
  20. m_isLocked = false;
  21. connect(this, TQT_SIGNAL(pressed() ), TQT_SLOT(was_pressed() ));
  22. connect(this, TQT_SIGNAL(released()), TQT_SLOT(was_released()));
  23. }
  24. const bool CScrollButton::isLocked( ) const {
  25. return m_isLocked;
  26. }
  27. void CScrollButton::was_pressed( ) {
  28. TQApplication::setOverrideCursor( BlankCursor );
  29. m_isLocked = true;
  30. lock_Point = get_lock_Point();
  31. emit lock()
  32. ;
  33. }
  34. void CScrollButton::was_released( ) {
  35. TQApplication::restoreOverrideCursor();
  36. m_isLocked = false;
  37. emit unlock();
  38. }
  39. const TQPoint CScrollButton::get_lock_Point() const {
  40. return mapToGlobal( TQPoint( width()/2, height()/2 ) );
  41. }
  42. void CScrollButton::mouseMoveEvent( TQMouseEvent* e ) {
  43. if (m_isLocked) {
  44. int vchange = (TQCursor::pos().y() - lock_Point.y());
  45. if (abs(vchange) < 10) {
  46. vchange = (int)((vchange>0 ? 1 : -1) * pow(abs(vchange), 0.3));
  47. }
  48. else if (abs(vchange) < 30) {
  49. vchange = (int)((vchange>0 ? 1 : -1) * pow(abs(vchange), 0.6));
  50. }
  51. else if (abs(vchange) < 40) {
  52. vchange = (int)((vchange>0 ? 1 : -1) * pow(abs(vchange), 1.2));
  53. }
  54. else {
  55. vchange = (int)((vchange>0 ? 1 : -1) * pow(abs(vchange), 2.0));
  56. }
  57. if (vchange) { //not emit 0
  58. emit change_requested( vchange );
  59. }
  60. TQCursor::setPos( lock_Point );
  61. }
  62. else {
  63. TQToolButton::mouseMoveEvent(e);
  64. }
  65. }
  66. /** If the wheel of the mouse is used while the mouse stays over our scrollbutton the content is scrolled like the mouse was pressed and moved. */
  67. void CScrollButton::wheelEvent( TQWheelEvent* e ) {
  68. /**
  69. * The problem is, that wheel events do everytime have the delta value 120
  70. */
  71. const int vchange = ((e->delta() > 0) ? (1) : (-1));
  72. if (vchange!=0) {//do not emit a change with value 0
  73. emit change_requested( vchange );
  74. e->accept();
  75. }
  76. else {
  77. e->ignore();
  78. }
  79. }
  80. #include "cscrollbutton.moc"