1 /*
2  * AutomatableSlider.cpp - implementation of class AutomatableSlider
3  *
4  * Copyright (c) 2006-2007 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
5  * Copyright (c) 2007-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6  *
7  * This file is part of LMMS - https://lmms.io
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public
20  * License along with this program (see COPYING); if not, write to the
21  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301 USA.
23  *
24  */
25 
26 #include "AutomatableSlider.h"
27 
28 #include <QMouseEvent>
29 
30 #include "CaptionMenu.h"
31 #include "MainWindow.h"
32 
33 
34 
35 
AutomatableSlider(QWidget * _parent,const QString & _name)36 AutomatableSlider::AutomatableSlider( QWidget * _parent,
37 						const QString & _name ) :
38 	QSlider( _parent ),
39 	IntModelView( new IntModel( 0, 0, 0, NULL, _name, true ), this ),
40 	m_showStatus( false )
41 {
42 	setWindowTitle( _name );
43 
44 	connect( this, SIGNAL( valueChanged( int ) ),
45 					this, SLOT( changeValue( int ) ) );
46 	connect( this, SIGNAL( sliderMoved( int ) ),
47 					this, SLOT( moveSlider( int ) ) );
48 }
49 
50 
51 
52 
~AutomatableSlider()53 AutomatableSlider::~AutomatableSlider()
54 {
55 }
56 
57 
58 
59 
contextMenuEvent(QContextMenuEvent * _me)60 void AutomatableSlider::contextMenuEvent( QContextMenuEvent * _me )
61 {
62 	CaptionMenu contextMenu( model()->displayName() );
63 	addDefaultActions( &contextMenu );
64 	contextMenu.exec( QCursor::pos() );
65 }
66 
67 
68 
69 
mousePressEvent(QMouseEvent * _me)70 void AutomatableSlider::mousePressEvent( QMouseEvent * _me )
71 {
72 	if( _me->button() == Qt::LeftButton &&
73 	   ! ( _me->modifiers() & Qt::ControlModifier ) )
74 	{
75 		m_showStatus = true;
76 		QSlider::mousePressEvent( _me );
77 	}
78 	else
79 	{
80 		IntModelView::mousePressEvent( _me );
81 	}
82 }
83 
84 
85 
86 
mouseReleaseEvent(QMouseEvent * _me)87 void AutomatableSlider::mouseReleaseEvent( QMouseEvent * _me )
88 {
89 	m_showStatus = false;
90 	QSlider::mouseReleaseEvent( _me );
91 }
92 
93 
94 
95 
wheelEvent(QWheelEvent * _me)96 void AutomatableSlider::wheelEvent( QWheelEvent * _me )
97 {
98 	bool old_status = m_showStatus;
99 	m_showStatus = true;
100 	QSlider::wheelEvent( _me );
101 	m_showStatus = old_status;
102 }
103 
104 
105 
106 
modelChanged()107 void AutomatableSlider::modelChanged()
108 {
109 	QSlider::setRange( model()->minValue(), model()->maxValue() );
110 	updateSlider();
111 	connect( model(), SIGNAL( dataChanged() ),
112 				this, SLOT( updateSlider() ) );
113 }
114 
115 
116 
117 
changeValue(int _value)118 void AutomatableSlider::changeValue( int _value )
119 {
120 	model()->setValue( _value );
121 	emit logicValueChanged( model()->value() );
122 }
123 
124 
125 
126 
moveSlider(int _value)127 void AutomatableSlider::moveSlider( int _value )
128 {
129 	model()->setValue( _value );
130 	emit logicSliderMoved( model()->value() );
131 }
132 
133 
134 
135 
updateSlider()136 void AutomatableSlider::updateSlider()
137 {
138 	QSlider::setValue( model()->value() );
139 }
140 
141 
142 
143 
144 
145 
146