summaryrefslogtreecommitdiffstats
path: root/noatun/library/controls.cpp
blob: 1644f7242a19441185d8c9d3268248ca9fc43c4e (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
114
#include <noatun/controls.h>

L33tSlider::L33tSlider(TQWidget * tqparent, const char * name) :
	TQSlider(tqparent,name), pressed(false)
{}
L33tSlider::L33tSlider(Qt::Orientation o, TQWidget * tqparent, const char * name) :
	TQSlider(o,tqparent,name), pressed(false)
{}
L33tSlider::L33tSlider(int minValue, int maxValue, int pageStep, int value,
	                   Qt::Orientation o, TQWidget * tqparent, const char * name) :
	TQSlider(minValue, maxValue, pageStep, value, o, tqparent,name), pressed(false)
{}

bool L33tSlider::currentlyPressed() const
{
	return pressed;
}

void L33tSlider::setValue(int i)
{
	if (!pressed)
		TQSlider::setValue(i);
}

void L33tSlider::mousePressEvent(TQMouseEvent*e)
{
	if (e->button()!=Qt::RightButton)
	{
		pressed=true;
		TQSlider::mousePressEvent(e);
	}
}

void L33tSlider::mouseReleaseEvent(TQMouseEvent*e)
{
	pressed=false;
	TQSlider::mouseReleaseEvent(e);
	emit userChanged(value());
}

void L33tSlider::wheelEvent(TQWheelEvent *e)
{
	TQSlider::wheelEvent(e);
	int newValue=value() /* +e->delta()/120 */;
	if (newValue<minValue())
		newValue=minValue();
	else if (newValue>maxValue())
		newValue=maxValue();
	setValue(newValue);
	emit userChanged(newValue);
}


SliderAction::SliderAction(const TQString& text, int accel, const TQObject *receiver,
                                 const char *member, TQObject* tqparent, const char* name )
	: KAction( text, accel, tqparent, name )
{
	m_receiver = receiver;
	m_member = member;
}

int SliderAction::plug( TQWidget *w, int index )
{
	if (!w->inherits("KToolBar")) return -1;

	KToolBar *toolBar = (KToolBar *)w;
	int id = KAction::getToolButtonID();
	
	//Create it.
	m_slider=new L33tSlider(0, 1000, 100, 0,Qt::Horizontal, toolBar);
	m_slider->setMinimumWidth(10);
	toolBar->insertWidget(id, 10, m_slider, index );


	addContainer( toolBar, id );
	connect( toolBar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
	toolBar->setItemAutoSized( id, true );

	if (w->inherits( "KToolBar" ))
		connect(toolBar, TQT_SIGNAL(moved(KToolBar::BarPosition)), this, TQT_SLOT(toolbarMoved(KToolBar::BarPosition)));
	
	emit plugged();

	return containerCount() - 1;
}

void SliderAction::toolbarMoved(KToolBar::BarPosition)
{
// I wish this worked :)
return;	
/*
	if (pos == KToolBar::Left || pos == KToolBar::Right)
	{
		m_slider->setOrientationVertical);
		m_slider->setFixedWidth(m_slider->height());
	}
	else
	{
		m_slider->setOrientationHorizontal);
		m_slider->resize(m_slider->height(), m_slider->height());
	}
*/
}

void SliderAction::unplug( TQWidget *w )
{
	KToolBar *toolBar = (KToolBar *)w;
	int idx = findContainer( w );

	toolBar->removeItem( menuId( idx ) );
	removeContainer( idx );
}

#include "controls.moc"