diff --git a/include/Rubberband.h b/include/Rubberband.h index 894c0ce1b4b..bc9f3c6a200 100644 --- a/include/Rubberband.h +++ b/include/Rubberband.h @@ -79,13 +79,13 @@ class RubberBand : public QRubberBand virtual ~RubberBand(); QVector selectedObjects() const; + QVector selectableObjects() const; protected: virtual void resizeEvent( QResizeEvent * _re ); private: - QVector selectableObjects() const; }; diff --git a/include/SongEditor.h b/include/SongEditor.h index db4d7d78151..0c17d43eb4a 100644 --- a/include/SongEditor.h +++ b/include/SongEditor.h @@ -29,6 +29,7 @@ #include +#include "ActionGroup.h" #include "Editor.h" #include "TrackContainerView.h" @@ -82,6 +83,7 @@ public slots: void updatePosition( const MidiTime & t ); void updatePositionLine(); + void selectAllTcos( bool select ); protected: virtual void closeEvent( QCloseEvent * ce ); @@ -135,6 +137,7 @@ private slots: bool m_smoothScroll; EditMode m_mode; + EditMode m_ctrlMode; // mode they were in before they hit ctrl friend class SongEditorWindow; @@ -169,12 +172,17 @@ protected slots: void resized(); private: + virtual void keyPressEvent( QKeyEvent * ke ); + virtual void keyReleaseEvent( QKeyEvent * ke ); + QAction* m_addBBTrackAction; QAction* m_addSampleTrackAction; QAction* m_addAutomationTrackAction; + ActionGroup * m_editModeGroup; QAction* m_drawModeAction; QAction* m_selectModeAction; + QAction* m_crtlAction; ComboBox * m_zoomingComboBox; }; diff --git a/include/Track.h b/include/Track.h index f0e00d54448..23588d5c843 100644 --- a/include/Track.h +++ b/include/Track.h @@ -370,7 +370,6 @@ public slots: void update(); void changePosition( const MidiTime & newPos = MidiTime( -1 ) ); - protected: virtual void dragEnterEvent( QDragEnterEvent * dee ); virtual void dropEvent( QDropEvent * de ); diff --git a/include/TrackContainerView.h b/include/TrackContainerView.h index bf6ada40934..07e498df463 100644 --- a/include/TrackContainerView.h +++ b/include/TrackContainerView.h @@ -85,11 +85,7 @@ class TrackContainerView : public QWidget, public ModelView, inline QVector selectedObjects() { - if( allowRubberband() == true ) - { - return( m_rubberBand->selectedObjects() ); - } - return( QVector() ); + return( m_rubberBand->selectedObjects() ); } @@ -126,6 +122,8 @@ class TrackContainerView : public QWidget, public ModelView, } + RubberBand *rubberBand() const; + public slots: void realignTracks(); TrackView * createTrackView( Track * _t ); diff --git a/src/core/Track.cpp b/src/core/Track.cpp index f39abb0cca1..163e0efd3b3 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -688,99 +688,87 @@ void TrackContentObjectView::paintTextLabel(QString const & text, QPainter & pai void TrackContentObjectView::mousePressEvent( QMouseEvent * me ) { setInitialMousePos( me->pos() ); - if( m_trackView->trackContainerView()->allowRubberband() == true && - me->button() == Qt::LeftButton ) + if( me->button() == Qt::LeftButton ) { - if( m_trackView->trackContainerView()->rubberBandActive() == true ) - { - // Propagate to trackView for rubberbanding - selectableObject::mousePressEvent( me ); - } - else if ( me->modifiers() & Qt::ControlModifier ) + if( me->modifiers() & Qt::ControlModifier ) { - if( isSelected() == true ) + if( isSelected() ) { m_action = CopySelection; } else { - m_action = ToggleSelected; + gui->songEditor()->m_editor->selectAllTcos( false ); + QVector tcoViews; + tcoViews.push_back( this ); + DataFile dataFile = createTCODataFiles( tcoViews ); + QPixmap thumbnail = QPixmap::grabWidget( this ).scaled( + 128, 128, + Qt::KeepAspectRatio, + Qt::SmoothTransformation ); + new StringPairDrag( QString( "tco_%1" ).arg( + m_tco->getTrack()->type() ), + dataFile.toString(), thumbnail, this ); } } - else if( !me->modifiers() ) + else { - if( isSelected() == true ) + if( isSelected() ) { m_action = MoveSelection; } - } - } - else if( me->button() == Qt::LeftButton && - me->modifiers() & Qt::ControlModifier ) - { - // start drag-action - QVector tcoViews; - tcoViews.push_back( this ); - DataFile dataFile = createTCODataFiles( tcoViews ); - QPixmap thumbnail = QPixmap::grabWidget( this ).scaled( - 128, 128, - Qt::KeepAspectRatio, - Qt::SmoothTransformation ); - new StringPairDrag( QString( "tco_%1" ).arg( - m_tco->getTrack()->type() ), - dataFile.toString(), thumbnail, this ); - } - else if( me->button() == Qt::LeftButton && - /* engine::mainWindow()->isShiftPressed() == false &&*/ - fixedTCOs() == false ) - { - m_tco->addJournalCheckPoint(); + else + { + gui->songEditor()->m_editor->selectAllTcos( false ); + m_tco->addJournalCheckPoint(); - // move or resize - m_tco->setJournalling( false ); + // move or resize + m_tco->setJournalling( false ); - setInitialMousePos( me->pos() ); + setInitialMousePos( me->pos() ); - if( me->x() < width() - RESIZE_GRIP_WIDTH ) - { - m_action = Move; - m_oldTime = m_tco->startPosition(); - QCursor c( Qt::SizeAllCursor ); - QApplication::setOverrideCursor( c ); - s_textFloat->setTitle( tr( "Current position" ) ); - delete m_hint; - m_hint = TextFloat::displayMessage( tr( "Hint" ), - tr( "Press <%1> and drag to make " - "a copy." ).arg( - #ifdef LMMS_BUILD_APPLE - "⌘"), - #else - "Ctrl"), - #endif - embed::getIconPixmap( "hint" ), 0 ); - } - else if( !m_tco->getAutoResize() ) - { - m_action = Resize; - m_oldTime = m_tco->length(); - QCursor c( Qt::SizeHorCursor ); - QApplication::setOverrideCursor( c ); - s_textFloat->setTitle( tr( "Current length" ) ); - delete m_hint; - m_hint = TextFloat::displayMessage( tr( "Hint" ), - tr( "Press <%1> for free " - "resizing." ).arg( - #ifdef LMMS_BUILD_APPLE - "⌘"), - #else - "Ctrl"), - #endif - embed::getIconPixmap( "hint" ), 0 ); + if( me->x() < width() - RESIZE_GRIP_WIDTH ) + { + m_action = Move; + m_oldTime = m_tco->startPosition(); + QCursor c( Qt::SizeAllCursor ); + QApplication::setOverrideCursor( c ); + s_textFloat->setTitle( tr( "Current position" ) ); + delete m_hint; + m_hint = TextFloat::displayMessage( tr( "Hint" ), + tr( "Press <%1> and drag to make " + "a copy." ).arg( + #ifdef LMMS_BUILD_APPLE + "⌘"), + #else + "Ctrl"), + #endif + embed::getIconPixmap( "hint" ), 0 ); + } + else if( !m_tco->getAutoResize() ) + { + m_action = Resize; + m_oldTime = m_tco->length(); + QCursor c( Qt::SizeHorCursor ); + QApplication::setOverrideCursor( c ); + s_textFloat->setTitle( tr( "Current length" ) ); + delete m_hint; + m_hint = TextFloat::displayMessage( tr( "Hint" ), + tr( "Press <%1> for free " + "resizing." ).arg( + #ifdef LMMS_BUILD_APPLE + "⌘"), + #else + "Ctrl"), + #endif + embed::getIconPixmap( "hint" ), 0 ); + } + // s_textFloat->reparent( this ); + // setup text-float as if TCO was already moved/resized + mouseMoveEvent( me ); + s_textFloat->show(); + } } -// s_textFloat->reparent( this ); - // setup text-float as if TCO was already moved/resized - mouseMoveEvent( me ); - s_textFloat->show(); } else if( me->button() == Qt::RightButton ) { @@ -826,10 +814,7 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) { if( m_action == CopySelection ) { - if( mouseMovedDistance( me, 2 ) == true && - m_trackView->trackContainerView()->allowRubberband() == true && - m_trackView->trackContainerView()->rubberBandActive() == false && - ( me->modifiers() & Qt::ControlModifier ) ) + if( mouseMovedDistance( me, 2 ) == true ) { // Clear the action here because mouseReleaseEvent will not get // triggered once we go into drag. @@ -923,7 +908,7 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) t = ( *it )->startPosition() + static_cast( dx *MidiTime::ticksPerTact() / ppt )-smallest_pos; - if( ! ( me->modifiers() & Qt::AltModifier ) + if( ! ( me->modifiers() & Qt::ControlModifier ) && me->button() == Qt::NoButton ) { t = t.toNearestTact(); @@ -1464,11 +1449,9 @@ bool TrackContentWidget::pasteSelection( MidiTime tcoPos, QDropEvent * de ) const TrackContainer::TrackList tracks = getTrack()->trackContainer()->tracks(); const int currentTrackIndex = tracks.indexOf( getTrack() ); - bool allowRubberband = m_trackView->trackContainerView()->allowRubberband(); + bool wasSelection = m_trackView->trackContainerView()->rubberBand()->selectedObjects().count(); // Unselect the old group - if( allowRubberband == true ) - { const QVector so = m_trackView->trackContainerView()->selectedObjects(); for( QVector::const_iterator it = so.begin(); @@ -1476,7 +1459,7 @@ bool TrackContentWidget::pasteSelection( MidiTime tcoPos, QDropEvent * de ) { ( *it )->setSelected( false ); } - } + // TODO -- Need to draw the hovericon either way, or ghost the TCOs // onto their final position. @@ -1501,10 +1484,11 @@ bool TrackContentWidget::pasteSelection( MidiTime tcoPos, QDropEvent * de ) TrackContentObject * tco = t->createTCO( pos ); tco->restoreState( tcoElement ); tco->movePosition( pos ); - if( allowRubberband == true ) + if( wasSelection ) { tco->selectViewOnCreate( true ); } + //check tco name, if the same as source track name dont copy if( tco->name() == tracks[trackIndex]->name() ) { @@ -1551,6 +1535,11 @@ void TrackContentWidget::mousePressEvent( QMouseEvent * me ) else if( me->button() == Qt::LeftButton && !m_trackView->trackContainerView()->fixedTCOs() ) { + QVector so = m_trackView->trackContainerView()->rubberBand()->selectedObjects(); + for( int i = 0; i < so.count(); ++i ) + { + so.at( i )->setSelected( false); + } getTrack()->addJournalCheckPoint(); const MidiTime pos = getPosition( me->x() ).getTact() * MidiTime::ticksPerTact(); diff --git a/src/gui/TrackContainerView.cpp b/src/gui/TrackContainerView.cpp index 0f7d43d4c3f..2b7f4d6565a 100644 --- a/src/gui/TrackContainerView.cpp +++ b/src/gui/TrackContainerView.cpp @@ -472,6 +472,11 @@ void TrackContainerView::resizeEvent( QResizeEvent * _re ) QWidget::resizeEvent( _re ); } +RubberBand *TrackContainerView::rubberBand() const +{ + return m_rubberBand; +} + diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index cf561f17928..a3b187af307 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -33,7 +33,6 @@ #include #include -#include "ActionGroup.h" #include "AutomatableSlider.h" #include "ComboBox.h" #include "ConfigManager.h" @@ -102,7 +101,6 @@ SongEditor::SongEditor( Song * song ) : this, SLOT( stopRubberBand() ) ); m_positionLine = new positionLine( this ); - static_cast( layout() )->insertWidget( 1, m_timeLine ); @@ -312,14 +310,12 @@ void SongEditor::setEditModeSelect() void SongEditor::keyPressEvent( QKeyEvent * ke ) { - if( /*_ke->modifiers() & Qt::ShiftModifier*/ - gui->mainWindow()->isShiftPressed() == true && + if( ke->modifiers() & Qt::ShiftModifier && ke->key() == Qt::Key_Insert ) { m_song->insertBar(); } - else if(/* _ke->modifiers() & Qt::ShiftModifier &&*/ - gui->mainWindow()->isShiftPressed() == true && + else if( ke->modifiers() & Qt::ShiftModifier && ke->key() == Qt::Key_Delete ) { m_song->removeBar(); @@ -344,6 +340,26 @@ void SongEditor::keyPressEvent( QKeyEvent * ke ) { m_song->setPlayPos( 0, Song::Mode_PlaySong ); } + else if( ke->key() == Qt::Key_Delete ) + { + QVector tcoViews; + QVector so = selectedObjects(); + for( QVector::iterator it = so.begin(); + it != so.end(); ++it ) + { + TrackContentObjectView * tcov = + dynamic_cast( *it ); + tcov->remove(); + } + } + else if( ke->key() == Qt::Key_A && ke->modifiers() & Qt::ControlModifier ) + { + selectAllTcos( !(ke->modifiers() & Qt::ShiftModifier) ); + } + else if( ke->key() == Qt::Key_Escape ) + { + selectAllTcos( false ); + } else { QWidget::keyPressEvent( ke ); @@ -355,7 +371,7 @@ void SongEditor::keyPressEvent( QKeyEvent * ke ) void SongEditor::wheelEvent( QWheelEvent * we ) { - if( gui->mainWindow()->isCtrlPressed() == true ) + if( we->modifiers() & Qt::ControlModifier ) { int z = m_zoomingModel->value(); @@ -377,7 +393,7 @@ void SongEditor::wheelEvent( QWheelEvent * we ) // and make sure, all TCO's are resized and relocated realignTracks(); } - else if( gui->mainWindow()->isShiftPressed() == true || we->orientation() == Qt::Horizontal ) + else if( we->modifiers() & Qt::ShiftModifier || we->orientation() == Qt::Horizontal ) { m_leftRightScroll->setValue( m_leftRightScroll->value() - we->delta() / 30 ); @@ -606,6 +622,18 @@ void SongEditor::zoomingChanged() +void SongEditor::selectAllTcos( bool select ) +{ + QVector so = select ? rubberBand()->selectableObjects() : rubberBand()->selectedObjects(); + for( int i = 0; i < so.count(); ++i ) + { + so.at(i)->setSelected( select ); + } +} + + + + bool SongEditor::allowRubberband() const { return m_mode == SelectMode; @@ -674,10 +702,9 @@ SongEditorWindow::SongEditorWindow(Song* song) : // Edit actions DropToolBar *editActionsToolBar = addDropToolBarToTop(tr("Edit actions")); - ActionGroup* editModeGroup = new ActionGroup(this); - m_drawModeAction = editModeGroup->addAction(embed::getIconPixmap("edit_draw"), tr("Draw mode")); - m_selectModeAction = editModeGroup->addAction(embed::getIconPixmap("edit_select"), tr("Edit mode (select and move)")); - + m_editModeGroup = new ActionGroup(this); + m_drawModeAction = m_editModeGroup->addAction(embed::getIconPixmap("edit_draw"), tr("Draw mode")); + m_selectModeAction = m_editModeGroup->addAction(embed::getIconPixmap("edit_select"), tr("Edit mode (select and move)")); m_drawModeAction->setChecked(true); connect(m_drawModeAction, SIGNAL(triggered()), m_editor, SLOT(setEditModeDraw())); @@ -763,3 +790,31 @@ void SongEditorWindow::adjustUiAfterProjectLoad() qobject_cast( parentWidget() ) ); m_editor->scrolled(0); } + + + + +void SongEditorWindow::keyPressEvent( QKeyEvent *ke ) +{ + if( ke->key() == Qt::Key_Control ) + { + m_crtlAction = m_editModeGroup->checkedAction(); + m_selectModeAction->setChecked( true ); + m_selectModeAction->trigger(); + } +} + + + + +void SongEditorWindow::keyReleaseEvent( QKeyEvent *ke ) +{ + if( ke->key() == Qt::Key_Control ) + { + if( m_crtlAction ) + { + m_crtlAction->setChecked( true ); + m_crtlAction->trigger(); + } + } +}