Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions include/SongEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class SongEditor : public TrackContainerView

public slots:
void scrolled( int new_pos );
void updateRubberband();

void setEditMode( EditMode mode );
void setEditModeDraw();
Expand All @@ -85,6 +86,9 @@ public slots:

protected:
virtual void closeEvent( QCloseEvent * ce );
virtual void mousePressEvent( QMouseEvent * _me );
virtual void mouseMoveEvent( QMouseEvent * _me );
virtual void mouseReleaseEvent( QMouseEvent * _me );

private slots:
void setHighQuality( bool );
Expand Down Expand Up @@ -135,6 +139,13 @@ private slots:
bool m_smoothScroll;

EditMode m_mode;
QPoint m_origin;
QPoint m_scrollPos;
QPoint m_mousePos;
int m_rubberBandStartTrackview;
MidiTime m_rubberbandStartMidipos;
int m_currentZoomingValue;
int m_trackHeadWidth;

friend class SongEditorWindow;

Expand Down
12 changes: 7 additions & 5 deletions include/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ class TrackContentObjectView : public selectableObject, public ModelView
{
return m_tco;
}

inline TrackView * getTrackView()
{
return m_trackView;
}

// qproperty access func
QColor mutedColor() const;
QColor mutedBackgroundColor() const;
Expand All @@ -229,7 +235,7 @@ class TrackContentObjectView : public selectableObject, public ModelView
// access needsUpdate member variable
bool needsUpdate();
void setNeedsUpdate( bool b );

public slots:
virtual bool close();
void cut();
Expand All @@ -256,10 +262,6 @@ public slots:

float pixelsPerTact();

inline TrackView * getTrackView()
{
return m_trackView;
}

DataFile createTCODataFiles(const QVector<TrackContentObjectView *> & tcos) const;

Expand Down
8 changes: 4 additions & 4 deletions include/TrackContainerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ public slots:
/// Removes the rubber band from display when finished with.
void stopRubberBand();


protected:
static const int DEFAULT_PIXELS_PER_TACT = 16;

virtual void mousePressEvent( QMouseEvent * _me );
virtual void mouseMoveEvent( QMouseEvent * _me );
virtual void mouseReleaseEvent( QMouseEvent * _me );

virtual void resizeEvent( QResizeEvent * );

MidiTime m_currentPosition;
RubberBand *rubberBand() const;


private:
Expand Down Expand Up @@ -187,7 +187,7 @@ public slots:
float m_ppt;

RubberBand * m_rubberBand;
QPoint m_origin;



signals:
Expand Down
45 changes: 6 additions & 39 deletions src/gui/TrackContainerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ TrackContainerView::TrackContainerView( TrackContainer * _tc ) :
m_trackViews(),
m_scrollArea( new scrollArea( this ) ),
m_ppt( DEFAULT_PIXELS_PER_TACT ),
m_rubberBand( new RubberBand( m_scrollArea ) ),
m_origin()
m_rubberBand( new RubberBand( m_scrollArea ) )
{
m_tc->setHook( this );
//keeps the direction of the widget, undepended on the locale
Expand Down Expand Up @@ -427,50 +426,18 @@ void TrackContainerView::dropEvent( QDropEvent * _de )



void TrackContainerView::mousePressEvent( QMouseEvent * _me )
{
if( allowRubberband() == true )
{
m_origin = m_scrollArea->mapFromParent( _me->pos() );
m_rubberBand->setEnabled( true );
m_rubberBand->setGeometry( QRect( m_origin, QSize() ) );
m_rubberBand->show();
}
QWidget::mousePressEvent( _me );
}




void TrackContainerView::mouseMoveEvent( QMouseEvent * _me )
{
if( rubberBandActive() == true )
{
m_rubberBand->setGeometry( QRect( m_origin,
m_scrollArea->mapFromParent( _me->pos() ) ).
normalized() );
}
QWidget::mouseMoveEvent( _me );
}




void TrackContainerView::mouseReleaseEvent( QMouseEvent * _me )
void TrackContainerView::resizeEvent( QResizeEvent * _re )
{
m_rubberBand->hide();
m_rubberBand->setEnabled( false );
QWidget::mouseReleaseEvent( _me );
realignTracks();
QWidget::resizeEvent( _re );
}





void TrackContainerView::resizeEvent( QResizeEvent * _re )
RubberBand *TrackContainerView::rubberBand() const
{
realignTracks();
QWidget::resizeEvent( _re );
return m_rubberBand;
}


Expand Down
158 changes: 148 additions & 10 deletions src/gui/editors/SongEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
#include "TimeDisplayWidget.h"
#include "AudioDevice.h"
#include "PianoRoll.h"


#include "Track.h"

positionLine::positionLine( QWidget * parent ) :
QWidget( parent )
Expand Down Expand Up @@ -80,15 +79,20 @@ SongEditor::SongEditor( Song * song ) :
m_zoomingModel(new ComboBoxModel()),
m_scrollBack( false ),
m_smoothScroll( ConfigManager::inst()->value( "ui", "smoothscroll" ).toInt() ),
m_mode(DrawMode)
m_mode(DrawMode),
m_origin(),
m_scrollPos(),
m_mousePos(),
m_rubberBandStartTrackview(),
m_rubberbandStartMidipos(),
m_currentZoomingValue(m_zoomingModel->value()),
m_trackHeadWidth(ConfigManager::inst()->value("ui", "compacttrackbuttons").toInt()==1
? DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT + TRACK_OP_WIDTH_COMPACT
: DEFAULT_SETTINGS_WIDGET_WIDTH + TRACK_OP_WIDTH)
{
m_zoomingModel->setParent(this);
// create time-line
int widgetTotal = ConfigManager::inst()->value( "ui",
"compacttrackbuttons" ).toInt()==1 ?
DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT + TRACK_OP_WIDTH_COMPACT :
DEFAULT_SETTINGS_WIDGET_WIDTH + TRACK_OP_WIDTH;
m_timeLine = new TimeLineWidget( widgetTotal, 32,
m_timeLine = new TimeLineWidget( m_trackHeadWidth, 32,
pixelsPerTact(),
m_song->m_playPos[Song::Mode_PlaySong],
m_currentPosition, this );
Expand Down Expand Up @@ -239,6 +243,9 @@ SongEditor::SongEditor( Song * song ) :
this, SLOT( scrolled( int ) ) );
connect( m_song, SIGNAL( lengthChanged( int ) ),
this, SLOT( updateScrollBar( int ) ) );
connect( m_leftRightScroll, SIGNAL(valueChanged(int)),this, SLOT(updateRubberband()));
connect( contentWidget()->verticalScrollBar(), SIGNAL(valueChanged(int)),this, SLOT(updateRubberband()));


// Set up zooming model
for( float const & zoomLevel : m_zoomLevels )
Expand Down Expand Up @@ -293,6 +300,75 @@ void SongEditor::scrolled( int new_pos )



void SongEditor::updateRubberband()
{
if (rubberBandActive())
{
//take care of the zooming
int originX = m_origin.x();
if (m_currentZoomingValue != m_zoomingModel->value())
{
originX = m_trackHeadWidth + (originX - m_trackHeadWidth)
* m_zoomLevels[m_zoomingModel->value()] / m_zoomLevels[m_currentZoomingValue];
}

//take care of the scrollbar position
int hs = (m_leftRightScroll->value() - m_scrollPos.x()) * pixelsPerTact();
int vs = contentWidget()->verticalScrollBar()->value() - m_scrollPos.y();

//the adjusted origin point
QPoint origin = QPoint(qMax(originX - hs, m_trackHeadWidth), m_origin.y() - vs);

//paint the rubber band rect
rubberBand()->setGeometry(QRect( origin,
contentWidget()->mapFromParent(QPoint(m_mousePos.x(), m_mousePos.y()))
).normalized());

//the index of the TrackView the mouse is hover
const TrackView * tv = trackViewAt(m_mousePos.y() - m_timeLine->height());
int rubberBandTrackview = 0;
if (tv)
{
for (auto it : trackViews())
{
if (it == tv) {break;}
rubberBandTrackview++;
}
}
else
{
rubberBandTrackview = (m_mousePos.y() < m_timeLine->height() ? 0 : trackViews().count());
}

//the miditime the mouse is hover
MidiTime rubberbandMidipos = MidiTime((m_mousePos.x() - m_trackHeadWidth) / pixelsPerTact()
* MidiTime::ticksPerTact()) + m_currentPosition ;
//collect all Tcos
auto l = findChildren<selectableObject *>();

//are tcos in the rect of selection?
for (auto &it : l)
{
TrackContentObjectView * tco = dynamic_cast<TrackContentObjectView*>(it);

if (trackViews().indexOf(tco->getTrackView()) >= qMin(m_rubberBandStartTrackview, rubberBandTrackview)
&& trackViews().indexOf(tco->getTrackView()) <= qMax(m_rubberBandStartTrackview, rubberBandTrackview)
&& tco->getTrackContentObject()->endPosition() >= qMin(m_rubberbandStartMidipos, rubberbandMidipos)
&& tco->getTrackContentObject()->startPosition() <= qMax(m_rubberbandStartMidipos, rubberbandMidipos))
{
it->setSelected(true);
}
else
{
it->setSelected(false);
}
}
}
}




void SongEditor::setEditMode( EditMode mode )
{
m_mode = mode;
Expand Down Expand Up @@ -394,7 +470,7 @@ void SongEditor::wheelEvent( QWheelEvent * we )


void SongEditor::closeEvent( QCloseEvent * ce )
{
{
if( parentWidget() )
{
parentWidget()->hide();
Expand All @@ -404,7 +480,68 @@ void SongEditor::closeEvent( QCloseEvent * ce )
hide();
}
ce->ignore();
}
}




void SongEditor::mousePressEvent(QMouseEvent *_me)
{
if (allowRubberband())
{
//we save the position of both scrollbars into a QPoint
m_scrollPos = QPoint(m_leftRightScroll->value(), contentWidget()->verticalScrollBar()->value());
//and the mouse position
m_origin = contentWidget()->mapFromParent(QPoint(_me->pos().x(), _me->pos().y()));
//and the zooming
m_currentZoomingValue = zoomingModel()->value();
//paint the rubberband
rubberBand()->setEnabled(true);
rubberBand()->setGeometry(QRect( m_origin, QSize()));
rubberBand()->show();

//the trackView(index) and the miditime where the mouse has clicked
const TrackView * tv = trackViewAt(_me->pos().y() - m_timeLine->height());
m_rubberBandStartTrackview = 0;
if (tv)
{
for (auto it : trackViews())
{
if it == tv) {break;}
m_rubberBandStartTrackview++;
}
}
else
{
m_rubberBandStartTrackview = (_me->pos().y() < m_timeLine->height() ? 0 : trackViews().count());
}

m_rubberbandStartMidipos = MidiTime((_me->pos().x() - m_trackHeadWidth)
/ pixelsPerTact() * MidiTime::ticksPerTact())
+ m_currentPosition;
}
QWidget::mousePressEvent( _me );
}




void SongEditor::mouseMoveEvent(QMouseEvent *_me)
{
m_mousePos = _me->pos();
updateRubberband();
QWidget::mouseMoveEvent(_me);
}




void SongEditor::mouseReleaseEvent(QMouseEvent *_me)
{
rubberBand()->hide();
rubberBand()->setEnabled( false );
QWidget::mouseReleaseEvent( _me );
}



Expand Down Expand Up @@ -602,6 +739,7 @@ void SongEditor::zoomingChanged()
m_song->m_playPos[Song::Mode_PlaySong].m_timeLine->
setPixelsPerTact( pixelsPerTact() );
realignTracks();
updateRubberband();
}


Expand Down
12 changes: 0 additions & 12 deletions src/gui/widgets/Rubberband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ QVector<selectableObject *> RubberBand::selectedObjects() const
void RubberBand::resizeEvent( QResizeEvent * _re )
{
QRubberBand::resizeEvent( _re );
if( isEnabled() )
{
QVector<selectableObject *> so = selectableObjects();
for( QVector<selectableObject *>::iterator it = so.begin();
it != so.end(); ++it )
{
( *it )->setSelected( QRect( pos(), size() ).intersects(
QRect( ( *it )->mapTo( parentWidget(),
QPoint() ),
( *it )->size() ) ) );
}
}
}


Expand Down