summaryrefslogtreecommitdiffstats
path: root/kaffeine/src/player-parts/xine-part/positionslider.cpp
blob: ba61e65924551db5e3d4d072183ae50f35da2eb9 (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
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * positionslider.cpp
 *
 * Copyright (C) 2004-2005 Giorgos Gousios
 * Copyright (C) 2004-2005 Jürgen Kofler <kaffeine@gmx.net>
 * Copyright (C) 2004-2005 Miguel Freitas
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <math.h>

#include "positionslider.h"
#include "positionslider.moc"


PositionSlider::PositionSlider(Qt::Orientation o, TQWidget *tqparent, const char* name) :
           TQSlider(o, tqparent, name), m_userChange(false)
{
	connect(this, TQT_SIGNAL(sliderPressed()), this ,TQT_SLOT(slotSliderPressed()));
	connect(this, TQT_SIGNAL(sliderReleased()), this, TQT_SLOT(slotSliderReleased()));
	installEventFilter(this);
}



PositionSlider::~PositionSlider()
{
}



void PositionSlider::setPosition(int val, bool changePosition)
{
	if(!m_userChange)
		setValue(val);
	if(changePosition) {
		setValue(val);
		emit sliderMoved(val);
	}
}



void PositionSlider::slotSliderPressed()
{
	m_userChange = true;
	emit signalStartSeeking();
}



void PositionSlider::slotSliderReleased()
{
	emit sliderLastMove(this->value());
	emit signalStopSeeking();
	m_userChange = false;
}



void PositionSlider::wheelEvent(TQWheelEvent* e)
{
	float offset = log10( TQABS(e->delta()) ) / 0.002;
	int newVal = 0;
	if (e->delta()>0)
		newVal = value() - int(offset);
	else
		newVal = value() + int(offset);
	if (newVal < 0) newVal = 0;
		//setPosition(newVal, true);
		emit sliderLastMove( newVal );
	e->accept();
}



bool PositionSlider::eventFilter(TQObject *obj, TQEvent *ev)
{
	if( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(this) && (ev->type() == TQEvent::MouseButtonPress || ev->type() == TQEvent::MouseButtonDblClick) ) {
		TQMouseEvent *e = (TQMouseEvent *)ev;
		TQRect r = sliderRect();

		if( r.tqcontains( e->pos() ) || e->button() != Qt::LeftButton )
			return false;

		int range = maxValue() - minValue();
		int pos = (orientation() ==Qt::Horizontal) ? e->pos().x() : e->pos().y();
		int maxpos = (orientation() ==Qt::Horizontal) ? width() : height();
		int value = pos * range / maxpos + minValue();

		if (TQApplication::reverseLayout())
			value = maxValue() - (value - minValue());

		setPosition(value, true);
		return true;
	}
	else {
		return false;
	}
}