From d029c8513a9ccfc60716cf1d5f5927aed7704df5 Mon Sep 17 00:00:00 2001 From: Lukas W Date: Mon, 8 Dec 2014 18:23:01 +0100 Subject: [PATCH] BBEditor: Use Editor superclass --- include/BBEditor.h | 63 ++++++---- include/ComboBox.h | 4 + include/Pattern.h | 2 +- src/core/Song.cpp | 2 +- src/core/Track.cpp | 4 +- src/gui/BBEditor.cpp | 219 ++++++++++++++--------------------- src/gui/widgets/ComboBox.cpp | 20 +++- 7 files changed, 149 insertions(+), 165 deletions(-) diff --git a/include/BBEditor.h b/include/BBEditor.h index 84b99a0da..1e2bda33c 100644 --- a/include/BBEditor.h +++ b/include/BBEditor.h @@ -26,6 +26,7 @@ #ifndef BB_EDITOR_H #define BB_EDITOR_H +#include "Editor.h" #include "TrackContainerView.h" @@ -33,46 +34,60 @@ class BBTrackContainer; class ComboBox; class ToolButton; +class BBTrackContainerView; -class BBEditor : public TrackContainerView +class BBEditor : public Editor { Q_OBJECT public: BBEditor( BBTrackContainer * _tc ); - virtual ~BBEditor(); + ~BBEditor(); - virtual inline bool fixedTCOs() const - { - return( true ); + const BBTrackContainerView* trackContainerView() const { + return m_trackContainerView; + } + BBTrackContainerView* trackContainerView() { + return m_trackContainerView; } - - virtual void dropEvent( QDropEvent * _de ); - - void removeBBView( int _bb ); - - void setPauseIcon( bool pause ); + void removeBBView( int bb ); public slots: void play(); void stop(); - void updatePosition(); - void addAutomationTrack(); - void addSteps(); - void removeSteps(); private: - virtual void keyPressEvent( QKeyEvent * _ke ); - - BBTrackContainer * m_bbtc; - QWidget * m_toolBar; - - ToolButton * m_playButton; - ToolButton * m_stopButton; - + BBTrackContainerView* m_trackContainerView; ComboBox * m_bbComboBox; - } ; + +class BBTrackContainerView : public TrackContainerView +{ + Q_OBJECT +public: + BBTrackContainerView(BBTrackContainer* tc); + + bool fixedTCOs() const + { + return true; + } + + void removeBBView(int bb); + +public slots: + void addSteps(); + void removeSteps(); + void addAutomationTrack(); + +protected slots: + virtual void dropEvent(QDropEvent * de ); + void updatePosition(); + +private: + BBTrackContainer * m_bbtc; +}; + + #endif diff --git a/include/ComboBox.h b/include/ComboBox.h index fdfe12bf3..0c348e53b 100644 --- a/include/ComboBox.h +++ b/include/ComboBox.h @@ -53,6 +53,10 @@ public: virtual QSize sizeHint() const; +public slots: + void selectNext(); + void selectPrevious(); + protected: virtual void contextMenuEvent( QContextMenuEvent* event ); diff --git a/include/Pattern.h b/include/Pattern.h index 163b3429b..840926f51 100644 --- a/include/Pattern.h +++ b/include/Pattern.h @@ -138,7 +138,7 @@ private: int m_steps; friend class PatternView; - friend class BBEditor; + friend class BBTrackContainerView; signals: diff --git a/src/core/Song.cpp b/src/core/Song.cpp index dc19a3d65..a8d3450f8 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -729,7 +729,7 @@ void Song::clearProject() Engine::mixer()->lock(); if( Engine::getBBEditor() ) { - Engine::getBBEditor()->clearAllTracks(); + Engine::getBBEditor()->trackContainerView()->clearAllTracks(); } if( Engine::songEditor() ) { diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 188d57e08..f25623540 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -1134,7 +1134,7 @@ void TrackContentWidget::update() */ void TrackContentWidget::changePosition( const MidiTime & _new_pos ) { - if( m_trackView->trackContainerView() == Engine::getBBEditor() ) + if( m_trackView->trackContainerView() == Engine::getBBEditor()->trackContainerView() ) { const int cur_bb = Engine::getBBTrackContainer()->currentBB(); setUpdatesEnabled( false ); @@ -1466,7 +1466,7 @@ void TrackContentWidget::paintEvent( QPaintEvent * _pe ) int ppt = static_cast( tcv->pixelsPerTact() ); QPainter p( this ); // Don't draw background on BB-Editor - if( m_trackView->trackContainerView() != Engine::getBBEditor() ) + if( m_trackView->trackContainerView() != Engine::getBBEditor()->trackContainerView() ) { p.drawTiledPixmap( rect(), m_background, QPoint( tcv->currentPosition().getTact() * ppt, 0 ) ); diff --git a/src/gui/BBEditor.cpp b/src/gui/BBEditor.cpp index d57da6441..a8d631481 100644 --- a/src/gui/BBEditor.cpp +++ b/src/gui/BBEditor.cpp @@ -22,7 +22,7 @@ * */ - +#include #include #include #include @@ -44,27 +44,13 @@ BBEditor::BBEditor( BBTrackContainer* tc ) : - TrackContainerView( tc ), - m_bbtc( tc ) + Editor(false), + m_trackContainerView( new BBTrackContainerView(tc) ) { - // create toolbar - m_toolBar = new QWidget; - m_toolBar->setFixedHeight( 32 ); - m_toolBar->move( 0, 0 ); - m_toolBar->setAutoFillBackground( true ); - QPalette pal; - pal.setBrush( m_toolBar->backgroundRole(), - embed::getIconPixmap( "toolbar_bg" ) ); - m_toolBar->setPalette( pal ); - static_cast( layout() )->insertWidget( 0, m_toolBar ); - - QHBoxLayout * tb_layout = new QHBoxLayout( m_toolBar ); - tb_layout->setSpacing( 0 ); - tb_layout->setMargin( 0 ); - - setWindowIcon( embed::getIconPixmap( "bb_track_btn" ) ); setWindowTitle( tr( "Beat+Bassline Editor" ) ); + setCentralWidget(m_trackContainerView); + // TODO: Use style sheet if( ConfigManager::inst()->value( "ui", "compacttrackbuttons" ).toInt() ) @@ -79,16 +65,8 @@ BBEditor::BBEditor( BBTrackContainer* tc ) : } - m_playButton = new ToolButton( embed::getIconPixmap( "play" ), - tr( "Play/pause current beat/bassline (Space)" ), - this, SLOT( play() ), m_toolBar ); - - m_stopButton = new ToolButton( embed::getIconPixmap( "stop" ), - tr( "Stop playback of current beat/bassline (Space)" ), - this, SLOT( stop() ), m_toolBar ); - - m_playButton->setObjectName( "playButton" ); - m_stopButton->setObjectName( "stopButton" ); + m_playButton->setToolTip(tr( "Play/pause current beat/bassline (Space)" )); + m_stopButton->setToolTip(tr( "Stop playback of current beat/bassline (Space)" )); ToolButton * add_bb_track = new ToolButton( embed::getIconPixmap( "add_bb_track" ), @@ -99,18 +77,17 @@ BBEditor::BBEditor( BBTrackContainer* tc ) : ToolButton * add_automation_track = new ToolButton( embed::getIconPixmap( "add_automation" ), tr( "Add automation-track" ), - this, SLOT( addAutomationTrack() ), m_toolBar ); + m_trackContainerView, SLOT( addAutomationTrack() ), m_toolBar ); ToolButton * remove_bar = new ToolButton( embed::getIconPixmap( "step_btn_remove" ), tr( "Remove steps" ), - this, SLOT( removeSteps() ), m_toolBar ); + m_trackContainerView, SLOT( removeSteps() ), m_toolBar ); ToolButton * add_bar = new ToolButton( embed::getIconPixmap( "step_btn_add" ), tr( "Add steps" ), - this, SLOT( addSteps() ), m_toolBar ); - + m_trackContainerView, SLOT( addSteps() ), m_toolBar ); m_playButton->setWhatsThis( @@ -125,30 +102,35 @@ BBEditor::BBEditor( BBTrackContainer* tc ) : m_bbComboBox->setFixedSize( 200, 22 ); m_bbComboBox->setModel( &tc->m_bbComboBoxModel ); - tb_layout->addSpacing( 5 ); - tb_layout->addWidget( m_playButton ); - tb_layout->addWidget( m_stopButton ); - tb_layout->addSpacing( 20 ); - tb_layout->addWidget( m_bbComboBox ); - tb_layout->addSpacing( 10 ); - tb_layout->addWidget( add_bb_track ); - tb_layout->addWidget( add_automation_track ); - tb_layout->addStretch(); - tb_layout->addWidget( remove_bar ); - tb_layout->addWidget( add_bar ); - tb_layout->addSpacing( 15 ); + m_toolBar->addSeparator(); + m_toolBar->addWidget( m_bbComboBox ); + m_toolBar->addSeparator(); + m_toolBar->addWidget( add_bb_track ); + m_toolBar->addWidget( add_automation_track ); + QWidget* stretch = new QWidget(m_toolBar); + stretch->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_toolBar->addWidget(stretch); + m_toolBar->addWidget( remove_bar ); + m_toolBar->addWidget( add_bar ); + m_toolBar->addSeparator(); - Engine::mainWindow()->workspace()->addSubWindow( this ); - parentWidget()->setAttribute( Qt::WA_DeleteOnClose, false ); parentWidget()->layout()->setSizeConstraint( QLayout::SetMinimumSize ); parentWidget()->resize( minimumWidth(), 300 ); parentWidget()->move( 610, 5 ); parentWidget()->show(); - - setModel( tc ); connect( &tc->m_bbComboBoxModel, SIGNAL( dataChanged() ), - this, SLOT( updatePosition() ) ); + m_trackContainerView, SLOT( updatePosition() ) ); + + QAction* viewNext = new QAction(this); + connect(viewNext, SIGNAL(triggered()), m_bbComboBox, SLOT(selectNext())); + viewNext->setShortcut(Qt::Key_Plus); + addAction(viewNext); + + QAction* viewPrevious = new QAction(this); + connect(viewPrevious, SIGNAL(triggered()), m_bbComboBox, SLOT(selectPrevious())); + viewPrevious->setShortcut(Qt::Key_Minus); + addAction(viewPrevious); } @@ -159,49 +141,11 @@ BBEditor::~BBEditor() } -void BBEditor::dropEvent( QDropEvent * de ) + + +void BBEditor::removeBBView( int bb ) { - QString type = StringPairDrag::decodeKey( de ); - QString value = StringPairDrag::decodeValue( de ); - - if( type.left( 6 ) == "track_" ) - { - DataFile dataFile( value.toUtf8() ); - Track * t = Track::create( dataFile.content().firstChild().toElement(), model() ); - - t->deleteTCOs(); - m_bbtc->updateAfterTrackAdd(); - - de->accept(); - } - else - { - TrackContainerView::dropEvent( de ); - } -} - - -void BBEditor::removeBBView( int _bb ) -{ - foreach( TrackView* view, trackViews() ) - { - view->getTrackContentWidget()->removeTCOView( _bb ); - } -} - - - - -void BBEditor::setPauseIcon( bool pause ) -{ - if( pause == true ) - { - m_playButton->setIcon( embed::getIconPixmap( "pause" ) ); - } - else - { - m_playButton->setIcon( embed::getIconPixmap( "play" ) ); - } + m_trackContainerView->removeBBView(bb); } @@ -230,24 +174,21 @@ void BBEditor::stop() -void BBEditor::updatePosition() + + +BBTrackContainerView::BBTrackContainerView(BBTrackContainer* tc) : + TrackContainerView(tc), + m_bbtc(tc) { - //realignTracks(); - emit positionChanged( m_currentPosition ); + setModel( tc ); } -void BBEditor::addAutomationTrack() -{ - (void) Track::create( Track::AutomationTrack, model() ); -} - - -void BBEditor::addSteps() +void BBTrackContainerView::addSteps() { TrackContainer::TrackList tl = model()->tracks(); @@ -265,7 +206,7 @@ void BBEditor::addSteps() -void BBEditor::removeSteps() +void BBTrackContainerView::removeSteps() { TrackContainer::TrackList tl = model()->tracks(); @@ -283,43 +224,51 @@ void BBEditor::removeSteps() -void BBEditor::keyPressEvent( QKeyEvent * _ke ) +void BBTrackContainerView::addAutomationTrack() { - if ( _ke->key() == Qt::Key_Space ) - { - if( Engine::getSong()->isPlaying() ) - { - stop(); - } - else - { - play(); - } - } - else if ( _ke->key() == Qt::Key_Plus ) - { - if( m_bbtc->currentBB()+ 1 < m_bbtc->numOfBBs() ) - { - m_bbtc->setCurrentBB( m_bbtc->currentBB() + 1 ); - } - } - else if ( _ke->key() == Qt::Key_Minus ) - { - if( m_bbtc->currentBB() > 0 ) - { - m_bbtc->setCurrentBB( m_bbtc->currentBB() - 1 ); - } - } - else - { - // ignore event and pass to parent-widget - _ke->ignore(); - } - + (void) Track::create( Track::AutomationTrack, model() ); } +void BBTrackContainerView::removeBBView(int bb) +{ + foreach( TrackView* view, trackViews() ) + { + view->getTrackContentWidget()->removeTCOView( bb ); + } +} + + +void BBTrackContainerView::dropEvent(QDropEvent* de) +{ + QString type = StringPairDrag::decodeKey( de ); + QString value = StringPairDrag::decodeValue( de ); + + if( type.left( 6 ) == "track_" ) + { + DataFile dataFile( value.toUtf8() ); + Track * t = Track::create( dataFile.content().firstChild().toElement(), model() ); + + t->deleteTCOs(); + m_bbtc->updateAfterTrackAdd(); + + de->accept(); + } + else + { + TrackContainerView::dropEvent( de ); + } +} + + + + +void BBTrackContainerView::updatePosition() +{ + //realignTracks(); + emit positionChanged( m_currentPosition ); +} diff --git a/src/gui/widgets/ComboBox.cpp b/src/gui/widgets/ComboBox.cpp index 950dbf70f..86294a863 100644 --- a/src/gui/widgets/ComboBox.cpp +++ b/src/gui/widgets/ComboBox.cpp @@ -105,6 +105,22 @@ QSize ComboBox::sizeHint() const + +void ComboBox::selectNext() +{ + model()->setInitValue( model()->value() + 1 ); +} + + + + +void ComboBox::selectPrevious() +{ + model()->setInitValue( model()->value() - 1 ); +} + + + void ComboBox::contextMenuEvent( QContextMenuEvent * event ) { if( model() == NULL || event->x() <= width() - CB_ARROW_BTN_WIDTH ) @@ -157,13 +173,13 @@ void ComboBox::mousePressEvent( QMouseEvent* event ) } else if( event->button() == Qt::LeftButton ) { - model()->setInitValue( model()->value() + 1 ); + selectNext(); update(); } } else if( event->button() == Qt::RightButton ) { - model()->setInitValue( model()->value() - 1 ); + selectPrevious(); update(); } else