summaryrefslogtreecommitdiffstats
path: root/bibletime/frontend/keychooser/cscrollbutton.cpp
blob: 3f7042f75bac79d5d6e86cccbf93010e9e5b51d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2006 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/



#include "cscrollbutton.h"

#include "frontend/cbtconfig.h"

#include <stdlib.h>
#include <math.h>

//TQt includes
#include <tqevent.h>
#include <tqapplication.h>
#include <tqcursor.h>

CScrollButton::CScrollButton(TQWidget *parent, const char *name ) : TQToolButton(parent,name) {
	setFocusPolicy(TQ_WheelFocus);
	setCursor( splitVCursor );

	m_isLocked = false;
	connect(this, TQT_SIGNAL(pressed() ), TQT_SLOT(was_pressed() ));
	connect(this, TQT_SIGNAL(released()), TQT_SLOT(was_released()));
}

const bool CScrollButton::isLocked( ) const {
	return m_isLocked;
}

void CScrollButton::was_pressed( ) {
	TQApplication::setOverrideCursor( BlankCursor );
	m_isLocked = true;
	lock_Point = get_lock_Point();

	emit lock()
		;
}

void CScrollButton::was_released( ) {
	TQApplication::restoreOverrideCursor();
	m_isLocked = false;

	emit unlock();
}

const TQPoint CScrollButton::get_lock_Point() const {
	return mapToGlobal( TQPoint( width()/2, height()/2 ) );
}

void CScrollButton::mouseMoveEvent( TQMouseEvent* e ) {
	if (m_isLocked) {
		int vchange = (TQCursor::pos().y() - lock_Point.y());

		if (abs(vchange) < 10) {
			vchange = (int)((vchange>0 ? 1 : -1) * pow(abs(vchange), 0.3));
		}
		else if (abs(vchange) < 30) {
			vchange = (int)((vchange>0 ? 1 : -1) * pow(abs(vchange), 0.6));
		}
		else if (abs(vchange) < 40) {
			vchange = (int)((vchange>0 ? 1 : -1) * pow(abs(vchange), 1.2));
		}
		else {
			vchange = (int)((vchange>0 ? 1 : -1) * pow(abs(vchange), 2.0));
		}

		if (vchange) { //not emit 0
			emit change_requested( vchange );
		}

		TQCursor::setPos( lock_Point );
	}
	else {
		TQToolButton::mouseMoveEvent(e);
	}
}



/** 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. */
void CScrollButton::wheelEvent( TQWheelEvent* e ) {
	/**
	* The problem is, that wheel events do everytime have the delta value 120
	*/
	const int vchange = ((e->delta() > 0) ? (1) : (-1));

	if (vchange!=0) {//do not emit a change with value 0
		emit change_requested( vchange );
		e->accept();
	}
	else {
		e->ignore();
	}
}