~ubuntu-branches/ubuntu/hardy/lmms/hardy

« back to all changes in this revision

Viewing changes to src/widgets/knob.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ragwitz
  • Date: 2005-12-22 16:22:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051222162250-key3p7x0212jy6dn
Tags: 0.1.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * This file is based on the knob-widget of the Qwt Widget Library from
5
5
 * Josef Wilgen
6
6
 *
7
 
 * Linux MultiMedia Studio
8
 
 * Copyright (c) 2004-2005 Tobias Doerffel <tobydox@users.sourceforge.net>
 
7
 * Copyright (c) 2004-2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 
8
 * 
 
9
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
9
10
 *
10
11
 * This program is free software; you can redistribute it and/or
11
12
 * modify it under the terms of the GNU General Public
39
40
#include <QStatusBar>
40
41
#include <QFontMetrics>
41
42
#include <QApplication>
 
43
#include <QInputDialog>
42
44
 
43
45
#else
44
46
 
50
52
#include <qstatusbar.h>
51
53
#include <qfontmetrics.h>
52
54
#include <qapplication.h>
 
55
#include <qinputdialog.h>
53
56
 
54
57
#define addSeparator insertSeparator
55
58
 
62
65
 
63
66
#include "knob.h"
64
67
#include "song_editor.h"
65
 
#include "midi_device.h"
 
68
/*#include "midi_client.h"*/
66
69
#include "embed.h"
67
70
#include "spc_bg_hndl_widget.h"
68
 
//#include "tooltip.h"
69
71
#include "config_mgr.h"
70
72
#include "text_float.h"
71
73
#include "mixer.h"
72
 
 
73
 
 
74
 
const int WHEEL_DELTA = 120;
 
74
#include "gui_templates.h"
 
75
#include "templates.h"
 
76
#include "string_pair_drag.h"
 
77
 
75
78
 
76
79
 
77
80
static double MinRelStep = 1.0e-10;
90
93
                        , _name.ascii()
91
94
#endif
92
95
                ),
93
 
        m_scrollMode( ScrNone ),
94
96
        m_mouseOffset( 0.0f ),
95
 
        m_tracking( TRUE ),
 
97
        m_buttonPressed( FALSE ),
96
98
        m_angle( 0.0f ),
97
 
        m_oldAngle( 0.0f ),
98
 
        m_nTurns( 0.0f ),       
99
99
        m_knobNum( _knob_num ),
100
100
        m_hintTextBeforeValue( "" ),
101
101
        m_hintTextAfterValue( "" ),
113
113
                s_textFloat = new textFloat( this );
114
114
        }
115
115
 
 
116
        setAcceptDrops( TRUE );
 
117
 
116
118
#ifdef QT4
117
119
        setAccessibleName( _name );
118
 
#endif
119
 
        setRange( 0.0, 100.0, 1.0 );
120
 
 
121
 
#ifdef QT4
122
120
        m_knobPixmap = new QPixmap( embed::getIconPixmap( QString( "knob0" +
123
121
                QString::number( m_knobNum + 1 ) ).toAscii().constData() ) );
124
122
#else
 
123
        setBackgroundMode( Qt::NoBackground );
125
124
        m_knobPixmap = new QPixmap( embed::getIconPixmap( "knob0" +
126
125
                                        QString::number( m_knobNum + 1 ) ) );
127
126
#endif
128
 
#ifdef QT4
129
 
//      setAttribute( Qt::WA_NoBackground );
130
 
#else
131
 
        setBackgroundMode( Qt::NoBackground );
132
 
#endif
133
 
 
134
 
        m_knobWidth = m_knobPixmap->width();
 
127
        setRange( 0.0f, 100.0f, 1.0f );
135
128
 
136
129
        setFixedSize( m_knobPixmap->width(), m_knobPixmap->height() );
137
130
        setTotalAngle( 270.0f );
145
138
// Destructor
146
139
knob::~knob()
147
140
{
148
 
        // make sure pointer to this knob isn't used anymore in active
 
141
/*      // make sure pointer to this knob isn't used anymore in active
149
142
        // midi-device-class
150
 
        if( mixer::inst()->getMIDIDevice()->pitchBendKnob() == this )
 
143
        if( mixer::inst()->getMIDIClient()->pitchBendKnob() == this )
151
144
        {
152
 
                mixer::inst()->getMIDIDevice()->setPitchBendKnob( NULL );
153
 
        }
 
145
                mixer::inst()->getMIDIClient()->setPitchBendKnob( NULL );
 
146
        }*/
154
147
}
155
148
 
156
149
 
161
154
{
162
155
        m_hintTextBeforeValue = _txt_before;
163
156
        m_hintTextAfterValue = _txt_after;
164
 
/*      toolTip::add( this, m_hintTextBeforeValue + QString::number( value() ) +
165
 
                                                m_hintTextAfterValue );*/
166
157
}
167
158
 
168
159
 
252
243
{
253
244
        recalcAngle();
254
245
        update();
255
 
/*      toolTip::add( this, m_hintTextBeforeValue + QString::number( value() ) +
256
 
                                                m_hintTextAfterValue );*/
257
 
        if( m_tracking )
258
 
        {
259
 
                emit valueChanged( value() );
260
 
        }
 
246
        emit valueChanged( value() );
261
247
}
262
248
 
263
249
 
276
262
                const float arc = atan2( -dx, dy ) * 180.0 / M_PI;
277
263
 
278
264
                float new_value = 0.5 * ( m_minValue + m_maxValue ) +
279
 
                                        ( arc + m_nTurns * 360.0 ) *
280
 
                                        ( m_maxValue - m_minValue ) /
 
265
                                        arc * ( m_maxValue - m_minValue ) /
281
266
                                                                m_totalAngle;
282
267
 
283
268
                const float oneTurn = tAbs<float>( m_maxValue - m_minValue ) *
297
282
                }
298
283
                return( new_value );
299
284
        }
300
 
        return( ( _p.y() - m_origMousePos.y() ) * m_step );
301
 
}
302
 
 
303
 
 
304
 
 
305
 
 
306
 
void knob::getScrollMode( const QPoint &, int & _scroll_mode, int & _direction )
307
 
{
308
 
        _scroll_mode = ScrMouse;
309
 
        _direction = 0;
 
285
        return( ( _p.y() - m_origMousePos.y() ) * m_pageSize );
310
286
}
311
287
 
312
288
 
321
297
 
322
298
 
323
299
 
324
 
void knob::resizeEvent( QResizeEvent * )
325
 
{
326
 
        layoutKnob( FALSE );
327
 
}
328
 
 
329
 
 
330
 
 
331
 
 
332
300
// Recalculate the slider's geometry and layout based on
333
301
// the current rect and fonts.
334
302
void knob::layoutKnob( bool _update_geometry )
343
311
 
344
312
 
345
313
 
 
314
void knob::recalcAngle( void )
 
315
{
 
316
        //
 
317
        // calculate the angle corresponding to the value
 
318
        //
 
319
        if( m_maxValue == m_minValue )
 
320
        {
 
321
                m_angle = 0;
 
322
        }
 
323
        else
 
324
        {
 
325
                m_angle = ( value() - 0.5 * ( m_minValue + m_maxValue ) ) /
 
326
                                ( m_maxValue - m_minValue ) * m_totalAngle;
 
327
                m_angle = static_cast<int>( m_angle ) % 360;
 
328
        }
 
329
}
 
330
 
 
331
 
 
332
 
 
333
 
 
334
void knob::contextMenuEvent( QContextMenuEvent * )
 
335
{
 
336
        // for the case, the user clicked right while pressing left mouse-
 
337
        // button, the context-menu appears while mouse-cursor is still hidden
 
338
        // and it isn't shown again until user does something which causes
 
339
        // an QApplication::restoreOverrideCursor()-call...
 
340
        mouseReleaseEvent( NULL );
 
341
 
 
342
        QMenu contextMenu( this );
 
343
#ifdef QT4
 
344
        contextMenu.setTitle( accessibleName() );
 
345
#else
 
346
        QLabel * caption = new QLabel( "<font color=white><b>" +
 
347
                        QString( accessibleName() ) + "</b></font>", this );
 
348
        caption->setPaletteBackgroundColor( QColor( 0, 0, 192 ) );
 
349
        caption->setAlignment( Qt::AlignCenter );
 
350
        contextMenu.addAction( caption );
 
351
#endif
 
352
        contextMenu.addAction( embed::getIconPixmap( "reload" ),
 
353
                                tr( "&Reset (%1%2)" ).arg( m_initValue ).arg(
 
354
                                                        m_hintTextAfterValue ),
 
355
                                                        this, SLOT( reset() ) );
 
356
        contextMenu.addSeparator();
 
357
        contextMenu.addAction( embed::getIconPixmap( "edit_copy" ),
 
358
                                tr( "&Copy value (%1%2)" ).arg( value() ).arg(
 
359
                                                        m_hintTextAfterValue ),
 
360
                                                this, SLOT( copyValue() ) );
 
361
        contextMenu.addAction( embed::getIconPixmap( "edit_paste" ),
 
362
                                tr( "&Paste value (%1%2)"
 
363
                                                ).arg( s_copiedValue ).arg(
 
364
                                                        m_hintTextAfterValue ),
 
365
                                this, SLOT( pasteValue() ) );
 
366
        contextMenu.addSeparator();
 
367
        contextMenu.addAction( tr( "Connect to MIDI-device" ), this,
 
368
                                                SLOT( connectToMidiDevice() ) );
 
369
        contextMenu.addSeparator();
 
370
        contextMenu.addAction( embed::getIconPixmap( "help" ), tr( "&Help" ),
 
371
                                                this, SLOT( displayHelp() ) );
 
372
        contextMenu.exec( QCursor::pos() );
 
373
}
 
374
 
 
375
 
 
376
 
 
377
 
 
378
void knob::dragEnterEvent( QDragEnterEvent * _dee )
 
379
{
 
380
        stringPairDrag::processDragEnterEvent( _dee, "float_value" );
 
381
}
 
382
 
 
383
 
 
384
 
 
385
 
 
386
void knob::dropEvent( QDropEvent * _de )
 
387
{
 
388
        QString type = stringPairDrag::decodeKey( _de );
 
389
        QString value = stringPairDrag::decodeValue( _de );
 
390
        if( type == "float_value" )
 
391
        {
 
392
                setValue( value.toFloat() );
 
393
                _de->accept();
 
394
        }
 
395
}
 
396
 
 
397
 
 
398
 
 
399
 
 
400
//! Mouse press event handler
 
401
void knob::mousePressEvent( QMouseEvent * _me )
 
402
{
 
403
        if( _me->button() == Qt::LeftButton &&
 
404
                                lmmsMainWin::inst()->isCtrlPressed() == FALSE )
 
405
        {
 
406
                const QPoint & p = _me->pos();
 
407
                m_origMousePos = p;
 
408
 
 
409
                if( configManager::inst()->value( "knobs",
 
410
                                                "classicalusability").toInt() )
 
411
                {
 
412
                        m_mouseOffset = getValue( p ) - value();
 
413
                }
 
414
                emit sliderPressed();
 
415
 
 
416
                if( !configManager::inst()->value( "knobs", "classicalusability"
 
417
                                                                ).toInt() )
 
418
                {
 
419
                        QApplication::setOverrideCursor( Qt::BlankCursor );
 
420
                }
 
421
                s_textFloat->reparent( this );
 
422
                s_textFloat->setText( m_hintTextBeforeValue +
 
423
                                                QString::number( value() ) +
 
424
                                                        m_hintTextAfterValue );
 
425
                s_textFloat->move( mapTo( topLevelWidget(), QPoint( 0, 0 ) ) +
 
426
                                QPoint( m_knobPixmap->width() + 2, 0 ) );
 
427
                s_textFloat->show();
 
428
                m_buttonPressed = TRUE;
 
429
        }
 
430
        else if( _me->button() == Qt::LeftButton &&
 
431
                                        lmmsMainWin::isCtrlPressed() == TRUE )
 
432
        {
 
433
                new stringPairDrag( "float_value", QString::number( value() ),
 
434
                                                        QPixmap(), this );
 
435
        }
 
436
        else if( _me->button() == Qt::MidButton )
 
437
        {
 
438
                reset();
 
439
        }
 
440
}
 
441
 
 
442
 
 
443
 
 
444
 
 
445
//! Mouse Move Event handler
 
446
void knob::mouseMoveEvent( QMouseEvent * _me )
 
447
{
 
448
        if( m_buttonPressed == TRUE )
 
449
        {
 
450
                setPosition( _me->pos() );
 
451
                emit sliderMoved( value() );
 
452
                if( !configManager::inst()->value( "knobs",
 
453
                                                "classicalusability").toInt() )
 
454
                {
 
455
                        QCursor::setPos( mapToGlobal( m_origMousePos ) );
 
456
                }
 
457
                songEditor::inst()->setModified();
 
458
        }
 
459
 
 
460
        s_textFloat->setText( m_hintTextBeforeValue +
 
461
                                                QString::number( value() ) +
 
462
                                                        m_hintTextAfterValue );
 
463
}
 
464
 
 
465
 
 
466
 
 
467
 
 
468
//! Mouse Release Event handler
 
469
void knob::mouseReleaseEvent( QMouseEvent * /* _me*/ )
 
470
{
 
471
        if( m_buttonPressed )
 
472
        {
 
473
                m_buttonPressed = TRUE;
 
474
                buttonReleased();
 
475
        }
 
476
 
 
477
        m_mouseOffset = 0;
 
478
        emit sliderReleased();
 
479
 
 
480
        if( !configManager::inst()->value( "knobs", "classicalusability"
 
481
                                                                ).toInt() )
 
482
        {
 
483
                QApplication::restoreOverrideCursor();
 
484
        }
 
485
 
 
486
        s_textFloat->hide();
 
487
}
 
488
 
 
489
 
 
490
 
 
491
 
 
492
void knob::mouseDoubleClickEvent( QMouseEvent * )
 
493
{
 
494
        enterValue();
 
495
}
 
496
 
 
497
 
 
498
 
 
499
 
346
500
void knob::paintEvent( QPaintEvent * _me )
347
501
{
348
 
        // Use double-buffering
349
502
        QRect ur = _me->rect();
350
503
#ifndef QT4
351
504
        if( ur.isValid() )
378
531
 
379
532
 
380
533
 
381
 
void knob::recalcAngle( void )
 
534
 
 
535
void knob::resizeEvent( QResizeEvent * )
382
536
{
383
 
        m_oldAngle = m_angle;
384
 
 
385
 
        //
386
 
        // calculate the angle corresponding to the value
387
 
        //
388
 
        if( m_maxValue == m_minValue )
389
 
        {
390
 
                m_angle = 0;
391
 
                m_nTurns = 0;
392
 
        }
393
 
        else
394
 
        {
395
 
                m_angle = ( value() - 0.5 * ( m_minValue + m_maxValue ) ) /
396
 
                                ( m_maxValue - m_minValue ) * m_totalAngle;
397
 
                m_nTurns = floor( ( m_angle + 180.0 ) / 360.0 );
398
 
                m_angle = m_angle - m_nTurns * 360.0;
399
 
        }
 
537
        layoutKnob( FALSE );
400
538
}
401
539
 
402
540
 
403
541
 
404
542
 
405
 
//! Mouse press event handler
406
 
void knob::mousePressEvent( QMouseEvent * _me )
 
543
//! Qt wheel event
 
544
void knob::wheelEvent( QWheelEvent * _we )
407
545
{
408
 
        const QPoint & p = _me->pos();
409
 
        m_origMousePos = p;
410
 
 
411
 
        getScrollMode( p, m_scrollMode, m_direction );
412
 
 
413
 
        switch( m_scrollMode )
414
 
        {
415
 
                case ScrMouse:
416
 
                        m_mouseOffset = getValue( p ) - value();
417
 
                        emit sliderPressed();
418
 
                        break;
419
 
 
420
 
                default:
421
 
                        m_mouseOffset = 0;
422
 
                        m_direction = 0;
423
 
                        break;
424
 
        }
425
 
 
426
 
        if( _me->button() == Qt::LeftButton )
427
 
        {
428
 
                if( !configManager::inst()->value( "knobs", "classicalusability"
429
 
                                                                ).toInt() )
430
 
                {
431
 
                        QApplication::setOverrideCursor( Qt::BlankCursor );
432
 
                }
433
 
                s_textFloat->reparent( this );
434
 
                s_textFloat->setText( m_hintTextBeforeValue +
435
 
                                                QString::number( value() ) +
436
 
                                                        m_hintTextAfterValue );
437
 
                s_textFloat->move( mapTo( topLevelWidget(), QPoint( 0, 0 ) ) +
 
546
        _we->accept();
 
547
        const int inc = ( _we->delta() > 0 ) ? 1 : -1;
 
548
        incValue( inc );
 
549
        songEditor::inst()->setModified();
 
550
 
 
551
 
 
552
        s_textFloat->reparent( this );
 
553
        s_textFloat->setText( m_hintTextBeforeValue +
 
554
                                        QString::number( value() ) +
 
555
                                                m_hintTextAfterValue );
 
556
        s_textFloat->move( mapTo( topLevelWidget(), QPoint( 0, 0 ) ) +
438
557
                                QPoint( m_knobPixmap->width() + 2, 0 ) );
439
 
                s_textFloat->show();
 
558
        s_textFloat->setVisibilityTimeOut( 1000 );
 
559
 
 
560
        if( value() != m_prevValue )
 
561
        {
 
562
                emit sliderMoved( value() );
440
563
        }
441
564
}
442
565
 
446
569
//! Emits a valueChanged() signal if necessary
447
570
void knob::buttonReleased( void )
448
571
{
449
 
        if( ( !m_tracking ) || ( value() != m_prevValue ) )
 
572
        if( value() != m_prevValue )
450
573
        {
451
574
                emit valueChanged( value() );
452
575
        }
455
578
 
456
579
 
457
580
 
458
 
//! Mouse Release Event handler
459
 
void knob::mouseReleaseEvent( QMouseEvent * _me )
460
 
{
461
 
        m_scrollMode = ScrNone;
462
 
        buttonReleased();
463
 
 
464
 
        switch( m_scrollMode )
465
 
        {
466
 
                case ScrMouse:
467
 
                        setPosition( _me->pos() );
468
 
                        m_direction = 0;
469
 
                        m_mouseOffset = 0;
470
 
                        emit sliderReleased ();
471
 
                        break;
472
 
 
473
 
                case ScrDirect:
474
 
                        setPosition( _me->pos() );
475
 
                        m_direction = 0;
476
 
                        m_mouseOffset = 0;
477
 
                        break;
478
 
 
479
 
                default:
480
 
                        break;
481
 
        }
482
 
 
483
 
        if( !configManager::inst()->value( "knobs", "classicalusability"
484
 
                                                                ).toInt() )
485
 
        {
486
 
                QApplication::restoreOverrideCursor();
487
 
        }
488
 
 
489
 
        s_textFloat->hide();
490
 
}
491
 
 
492
 
 
493
 
 
494
 
 
495
581
void knob::setPosition( const QPoint & _p )
496
582
{
497
583
        if( configManager::inst()->value( "knobs", "classicalusability"
498
584
                                                                ).toInt() )
499
585
        {
500
 
                setNewValue( getValue( _p ) - m_mouseOffset, 1 );
 
586
                setValue( getValue( _p ) - m_mouseOffset );
501
587
        }
502
588
        else
503
589
        {
504
 
                setNewValue( m_value - getValue( _p ), 1 );
505
 
        }
506
 
}
507
 
 
508
 
 
509
 
 
510
 
 
511
 
void knob::setTracking( bool _enable )
512
 
{
513
 
        m_tracking = _enable;
514
 
}
515
 
 
516
 
 
517
 
 
518
 
 
519
 
//! Mouse Move Event handler
520
 
void knob::mouseMoveEvent( QMouseEvent * _me )
521
 
{
522
 
        if( m_scrollMode == ScrMouse )
523
 
        {
524
 
                setPosition( _me->pos() );
525
 
                if( value() != m_prevValue )
526
 
                {
527
 
                        emit sliderMoved( value() );
528
 
                }
529
 
                if( !configManager::inst()->value( "knobs", "classicalusability"
530
 
                                                                ).toInt() )
531
 
                {
532
 
                        QCursor::setPos( mapToGlobal( m_origMousePos ) );
533
 
                }
534
 
        }
535
 
        songEditor::inst()->setModified();
536
 
 
537
 
        s_textFloat->setText( m_hintTextBeforeValue +
538
 
                                                QString::number( value() ) +
539
 
                                                        m_hintTextAfterValue );
540
 
 
541
 
}
542
 
 
543
 
 
544
 
 
545
 
//! Qt wheel event
546
 
void knob::wheelEvent( QWheelEvent * _me )
547
 
{
548
 
        _me->accept();
549
 
        const int inc = _me->delta() / WHEEL_DELTA;
550
 
        incPages( inc );
551
 
 
552
 
        songEditor::inst()->setModified();
553
 
 
554
 
        s_textFloat->reparent( this );
555
 
        s_textFloat->setText( m_hintTextBeforeValue +
556
 
                                        QString::number( value() ) +
557
 
                                                m_hintTextAfterValue );
558
 
        s_textFloat->move( mapTo( topLevelWidget(), QPoint( 0, 0 ) ) +
559
 
                                QPoint( m_knobPixmap->width() + 2, 0 ) );
560
 
        s_textFloat->setVisibilityTimeOut( 1000 );
561
 
 
562
 
/*      toolTip::add( this, m_hintTextBeforeValue+QString::number( value() ) +
563
 
                                                m_hintTextAfterValue );*/
564
 
 
565
 
        if( value() != m_prevValue )
566
 
        {
567
 
                emit sliderMoved( value() );
 
590
                setValue( m_value - getValue( _p ) );
568
591
        }
569
592
}
570
593
 
578
601
                m_initValue = _val;
579
602
        }
580
603
 
581
 
        setNewValue( _val, 0 );
 
604
        setNewValue( _val, TRUE );
582
605
}
583
606
 
584
607
 
586
609
 
587
610
void knob::fitValue( float _val )
588
611
{
589
 
        setNewValue( _val, 1 );
 
612
        setValue( _val );
590
613
}
591
614
 
592
615
 
594
617
 
595
618
void knob::incValue( int _steps )
596
619
{
597
 
        setNewValue( m_value + float( _steps ) * m_step, 1 );
 
620
        setValue( m_value + float( _steps ) * m_step );
598
621
}
599
622
 
600
623
 
621
644
        //
622
645
/*      m_pageSize = tLimit( pageSize, 0, int( tAbs<float>( ( m_maxValue -
623
646
                                                m_minValue ) / m_step ) ) ); */
624
 
        m_pageSize = tMax<float>( ( m_maxValue - m_minValue ) / 40.0f, _vstep );
 
647
        m_pageSize = tMax<float>( ( m_maxValue - m_minValue ) / 100.0f,
 
648
                                                                m_step );
625
649
 
626
650
        // 
627
651
        // If the value lies out of the range, it 
628
652
        // will be changed. Note that it will not be adjusted to 
629
653
        // the new step width.
630
 
        setNewValue( m_value, 0 );
 
654
        setNewValue( m_value, FALSE );
631
655
 
632
656
        // call notifier after the step width has been 
633
657
        // adjusted.
640
664
 
641
665
 
642
666
 
643
 
void knob::setNewValue( float _x, int _align )
 
667
void knob::setNewValue( float _x, bool _align )
644
668
{
645
669
        m_prevValue = m_value;
646
670
 
720
744
 
721
745
 
722
746
 
723
 
void knob::contextMenuEvent( QContextMenuEvent * )
724
 
{
725
 
        QMenu contextMenu( this );
726
 
#ifdef QT4
727
 
        contextMenu.setTitle( accessibleName() );
728
 
#else
729
 
        QLabel * caption = new QLabel( "<font color=white><b>" +
730
 
                        QString( accessibleName() ) + "</b></font>", this );
731
 
        caption->setPaletteBackgroundColor( QColor( 0, 0, 192 ) );
732
 
        caption->setAlignment( Qt::AlignCenter );
733
 
        contextMenu.addAction( caption );
734
 
#endif
735
 
        contextMenu.addAction( embed::getIconPixmap( "reload" ),
736
 
                                tr( "&Reset (%1%2)" ).arg( m_initValue ).arg(
737
 
                                                        m_hintTextAfterValue ),
738
 
                                                        this, SLOT( reset() ) );
739
 
        contextMenu.addSeparator();
740
 
        contextMenu.addAction( embed::getIconPixmap( "edit_copy" ),
741
 
                                tr( "&Copy value (%1%2)" ).arg( value() ).arg(
742
 
                                                        m_hintTextAfterValue ),
743
 
                                                this, SLOT( copyValue() ) );
744
 
        contextMenu.addAction( embed::getIconPixmap( "edit_paste" ),
745
 
                                tr( "&Paste value (%1%2)"
746
 
                                                ).arg( s_copiedValue ).arg(
747
 
                                                        m_hintTextAfterValue ),
748
 
                                this, SLOT( pasteValue() ) );
749
 
        contextMenu.addSeparator();
750
 
        contextMenu.addAction( tr( "Connect to MIDI-device" ), this,
751
 
                                                SLOT( connectToMidiDevice() ) );
752
 
        contextMenu.addSeparator();
753
 
        contextMenu.addAction( embed::getIconPixmap( "help" ), tr( "&Help" ),
754
 
                                                this, SLOT( displayHelp() ) );
755
 
        contextMenu.exec( QCursor::pos() );
756
 
}
757
 
 
758
 
 
759
 
 
760
 
 
761
747
void knob::reset( void )
762
748
{
763
749
        setValue( m_initValue );
 
750
        songEditor::inst()->setModified();
 
751
        s_textFloat->reparent( this );
 
752
        s_textFloat->setText( m_hintTextBeforeValue +
 
753
                                        QString::number( value() ) +
 
754
                                                m_hintTextAfterValue );
 
755
        s_textFloat->move( mapTo( topLevelWidget(), QPoint( 0, 0 ) ) +
 
756
                                QPoint( m_knobPixmap->width() + 2, 0 ) );
 
757
        s_textFloat->setVisibilityTimeOut( 1000 );
764
758
}
765
759
 
766
760
 
777
771
void knob::pasteValue( void )
778
772
{
779
773
        setValue( s_copiedValue );
 
774
        songEditor::inst()->setModified();
 
775
        s_textFloat->reparent( this );
 
776
        s_textFloat->setText( m_hintTextBeforeValue +
 
777
                                        QString::number( value() ) +
 
778
                                                m_hintTextAfterValue );
 
779
        s_textFloat->move( mapTo( topLevelWidget(), QPoint( 0, 0 ) ) +
 
780
                                QPoint( m_knobPixmap->width() + 2, 0 ) );
 
781
        s_textFloat->setVisibilityTimeOut( 1000 );
 
782
}
 
783
 
 
784
 
 
785
 
 
786
 
 
787
void knob::enterValue( void )
 
788
{
 
789
        bool ok;
 
790
        float new_val = QInputDialog::getDouble(
 
791
#ifdef QT4
 
792
                                        this,
 
793
#endif
 
794
                                        accessibleName(),
 
795
                                        tr( "Please enter a new value between "
 
796
                                                "%1 and %2:" ).arg(
 
797
                                                minValue() ).arg( maxValue() ),
 
798
                                        value(), minValue(), maxValue(),
 
799
                                        4, &ok
 
800
#ifndef QT4
 
801
                                        , this
 
802
#endif
 
803
                                                );
 
804
        if( ok )
 
805
        {
 
806
                setValue( new_val );
 
807
        }
780
808
}
781
809
 
782
810
 
784
812
 
785
813
void knob::connectToMidiDevice( void )
786
814
{
787
 
        mixer::inst()->getMIDIDevice()->setPitchBendKnob( this );
 
815
        //mixer::inst()->getMIDIDevice()->setPitchBendKnob( this );
788
816
}
789
817
 
790
818