Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding pattern editor subwindow horizontal scaling #7409

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions include/ClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class ClipView : public selectableObject, public ModelView

public:
const static int BORDER_WIDTH = 2;
//! only used when fixedClips() is true
const static int MIN_FIXED_WIDTH = 250;

ClipView( Clip * clip, TrackView * tv );
~ClipView() override;
Expand Down
1 change: 1 addition & 0 deletions include/MidiClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class LMMS_EXPORT MidiClip : public Clip

bool empty();

int getSteps() const;

gui::ClipView * createView( gui::TrackView * _tv ) override;

Expand Down
4 changes: 2 additions & 2 deletions include/TrackContainerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class TrackContainerView : public QWidget, public ModelView,
{
Q_OBJECT
public:
TrackContainerView( TrackContainer* tc );
TrackContainerView(TrackContainer* tc, bool canHorizontalScroll = false);
~TrackContainerView() override;

void saveSettings( QDomDocument & _doc, QDomElement & _this ) override;
Expand Down Expand Up @@ -177,7 +177,7 @@ public slots:
class scrollArea : public QScrollArea
{
public:
scrollArea( TrackContainerView* parent );
scrollArea(TrackContainerView* parent, bool canHorizontalScroll);
~scrollArea() override = default;

protected:
Expand Down
14 changes: 10 additions & 4 deletions include/TrackView.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ class FadeButton;
class TrackContainerView;


const int DEFAULT_SETTINGS_WIDGET_WIDTH = 256;
const int TRACK_OP_WIDTH = 78;
static const int DEFAULT_SETTINGS_WIDGET_WIDTH = 256;
static const int TRACK_OP_WIDTH = 78;
// This shaves 150-ish pixels off track buttons,
// ruled from config: ui.compacttrackbuttons
const int DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT = 128;
const int TRACK_OP_WIDTH_COMPACT = 62;
static const int DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT = 128;
static const int TRACK_OP_WIDTH_COMPACT = 62;


class TrackView : public QWidget, public ModelView, public JournallingObject
Expand Down Expand Up @@ -98,6 +98,12 @@ class TrackView : public QWidget, public ModelView, public JournallingObject
return m_action == Action::Move;
}

// returns getTrackFixedSettingsWidth() + getTrackFixedOperationsWidth()
static const int getTrackFixedWidth();
// returns the right compact or not compact width
static const int getTrackFixedSettingsWidth();
static const int getTrackFixedOperationsWidth();

virtual void update();

// Create a menu for assigning/creating channels for this track
Expand Down
2 changes: 1 addition & 1 deletion src/gui/clips/ClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void ClipView::updateLength()
{
if( fixedClips() )
{
setFixedWidth( parentWidget()->width() );
setFixedWidth(MIN_FIXED_WIDTH < parentWidget()->width() ? parentWidget()->width() : MIN_FIXED_WIDTH);
}
else
{
Expand Down
15 changes: 5 additions & 10 deletions src/gui/editors/PatternEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace lmms::gui


PatternEditor::PatternEditor(PatternStore* ps) :
TrackContainerView(ps),
TrackContainerView(ps, true),
m_ps(ps)
{
setModel(ps);
Expand Down Expand Up @@ -79,6 +79,7 @@ void PatternEditor::removeSteps()
p->removeSteps();
}
}
realignTracks();
}


Expand Down Expand Up @@ -192,6 +193,7 @@ void PatternEditor::makeSteps( bool clone )
}
}
}
realignTracks();
}

// Creates a clone of the current pattern track with the same content, but no clips in the song editor
Expand Down Expand Up @@ -234,14 +236,7 @@ PatternEditorWindow::PatternEditorWindow(PatternStore* ps) :
connect(m_toolBar, SIGNAL(dropped(QDropEvent*)), m_editor, SLOT(dropEvent(QDropEvent*)));

// TODO: Use style sheet
if (ConfigManager::inst()->value("ui", "compacttrackbuttons").toInt())
{
setMinimumWidth(TRACK_OP_WIDTH_COMPACT + DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT + 2 * ClipView::BORDER_WIDTH + 384);
}
else
{
setMinimumWidth(TRACK_OP_WIDTH + DEFAULT_SETTINGS_WIDGET_WIDTH + 2 * ClipView::BORDER_WIDTH + 384);
}
setMinimumWidth(TrackView::getTrackFixedWidth() + 2 * ClipView::BORDER_WIDTH);

m_playAction->setToolTip(tr("Play/pause current pattern (Space)"));
m_stopAction->setToolTip(tr("Stop playback of current pattern (Space)"));
Expand Down Expand Up @@ -323,4 +318,4 @@ void PatternEditorWindow::stop()
}


} // namespace lmms::gui
} // namespace lmms::gui
9 changes: 3 additions & 6 deletions src/gui/editors/SongEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ SongEditor::SongEditor( Song * song ) :
m_rubberBandStartTrackview(0),
m_rubberbandStartTimePos(0),
m_rubberbandPixelsPerBar(DEFAULT_PIXELS_PER_BAR),
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_trackHeadWidth(TrackView::getTrackFixedWidth()),
m_selectRegion(false)
{
m_zoomingModel->setParent(this);
Expand Down Expand Up @@ -752,9 +750,8 @@ static inline void animateScroll( QScrollBar *scrollBar, int newVal, bool smooth

void SongEditor::updatePosition( const TimePos & t )
{
const bool compactTrackButtons = ConfigManager::inst()->value("ui", "compacttrackbuttons").toInt();
const auto widgetWidth = compactTrackButtons ? DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT : DEFAULT_SETTINGS_WIDGET_WIDTH;
const auto trackOpWidth = compactTrackButtons ? TRACK_OP_WIDTH_COMPACT : TRACK_OP_WIDTH;
const auto widgetWidth = TrackView::getTrackFixedSettingsWidth();
const auto trackOpWidth = TrackView::getTrackFixedOperationsWidth();

if( ( m_song->isPlaying() && m_song->m_playMode == Song::PlayMode::Song
&& m_timeLine->autoScroll() == TimeLineWidget::AutoScrollState::Enabled) ||
Expand Down
46 changes: 41 additions & 5 deletions src/gui/editors/TrackContainerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "Song.h"
#include "StringPairDrag.h"
#include "TrackView.h"
#include "ClipView.h"
#include "MidiClip.h"
#include "GuiApplication.h"
#include "PluginFactory.h"

Expand Down Expand Up @@ -74,15 +76,15 @@ void InstrumentLoaderThread::run()
namespace gui
{

TrackContainerView::TrackContainerView( TrackContainer * _tc ) :
TrackContainerView::TrackContainerView(TrackContainer * _tc, bool canHorizontalScroll) :
QWidget(),
ModelView( nullptr, this ),
JournallingObject(),
SerializingObjectHook(),
m_currentPosition( 0, 0 ),
m_tc( _tc ),
m_trackViews(),
m_scrollArea( new scrollArea( this ) ),
m_scrollArea(new scrollArea(this, canHorizontalScroll)),
m_ppb( DEFAULT_PIXELS_PER_BAR ),
m_rubberBand( new RubberBand( m_scrollArea ) )
{
Expand Down Expand Up @@ -254,7 +256,38 @@ void TrackContainerView::scrollToTrackView( TrackView * _tv )

void TrackContainerView::realignTracks()
{
m_scrollArea->widget()->setFixedWidth(width());
if (fixedClips())
{
// if for example this TrackContainerView is a pattern editor
int maxSteps = 16;
// loop through the tracks to find the clip with
// the highest amount of steps
// this should be the same value for all clips, but we never know
for (const auto& trackView : m_trackViews)
{
if (trackView->getTrack()->type() == Track::Type::Instrument)
{
InstrumentTrack* curTrack = static_cast<InstrumentTrack*>(trackView->getTrack());
if (curTrack->getClips().size() > 0)
{
MidiClip* curClip = reinterpret_cast<MidiClip*>(curTrack->getClip(0));
int curSteps = curClip->getSteps();
if (maxSteps < curSteps)
{
maxSteps = curSteps;
}
}
}
}

// calculate minimum width
const int minWidth = TrackView::getTrackFixedWidth() + maxSteps * ClipView::MIN_FIXED_WIDTH / 16;
m_scrollArea->widget()->setFixedWidth(minWidth > width() ? minWidth : width());
}
else
{
m_scrollArea->widget()->setFixedWidth(width());
}
m_scrollArea->widget()->setFixedHeight(
m_scrollArea->widget()->minimumSizeHint().height());

Expand Down Expand Up @@ -464,12 +497,15 @@ RubberBand *TrackContainerView::rubberBand() const



TrackContainerView::scrollArea::scrollArea( TrackContainerView * _parent ) :
TrackContainerView::scrollArea::scrollArea(TrackContainerView * _parent, bool canHorizontalScroll) :
QScrollArea( _parent ),
m_trackContainerView( _parent )
{
setFrameStyle( QFrame::NoFrame );
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
if (canHorizontalScroll == false)
{
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
}


Expand Down
4 changes: 1 addition & 3 deletions src/gui/tracks/SampleTrackView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ void SampleTrackView::dropEvent(QDropEvent *de)

if (type == "samplefile")
{
int trackHeadWidth = ConfigManager::inst()->value("ui", "compacttrackbuttons").toInt()==1
? DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT + TRACK_OP_WIDTH_COMPACT
: DEFAULT_SETTINGS_WIDGET_WIDTH + TRACK_OP_WIDTH;
int trackHeadWidth = TrackView::getTrackFixedWidth();

int xPos = de->pos().x() < trackHeadWidth
? trackHeadWidth
Expand Down
37 changes: 27 additions & 10 deletions src/gui/tracks/TrackView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,40 @@ TrackView::TrackView( Track * track, TrackContainerView * tcv ) :
*/
void TrackView::resizeEvent( QResizeEvent * re )
{
if( ConfigManager::inst()->value( "ui",
"compacttrackbuttons" ).toInt() )
m_trackOperationsWidget.setFixedSize(getTrackFixedOperationsWidth(), height() - 1);
m_trackSettingsWidget.setFixedSize(getTrackFixedSettingsWidth(), height() - 1);
m_trackContentWidget.setFixedHeight(height());
}


const int TrackView::getTrackFixedWidth()
{
return getTrackFixedSettingsWidth() + getTrackFixedOperationsWidth();
}

const int TrackView::getTrackFixedSettingsWidth()
{
if(ConfigManager::inst()->value("ui", "compacttrackbuttons").toInt())
{
m_trackOperationsWidget.setFixedSize( TRACK_OP_WIDTH_COMPACT, height() - 1 );
m_trackSettingsWidget.setFixedSize( DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT, height() - 1 );
// if compact size
return DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT;
}
else
// if not compact
return DEFAULT_SETTINGS_WIDGET_WIDTH;
}

const int TrackView::getTrackFixedOperationsWidth()
{
if(ConfigManager::inst()->value("ui", "compacttrackbuttons").toInt())
{
m_trackOperationsWidget.setFixedSize( TRACK_OP_WIDTH, height() - 1 );
m_trackSettingsWidget.setFixedSize( DEFAULT_SETTINGS_WIDGET_WIDTH, height() - 1 );
// if compact size
return TRACK_OP_WIDTH_COMPACT;
}
m_trackContentWidget.setFixedHeight( height() );
// if not compact
return TRACK_OP_WIDTH;
}




/*! \brief Update this track View and all its content objects.
*
*/
Expand Down
4 changes: 4 additions & 0 deletions src/tracks/MidiClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,10 @@ void MidiClip::removeSteps()
}


int MidiClip::getSteps() const
{
return m_steps;
}


gui::ClipView * MidiClip::createView( gui::TrackView * _tv )
Expand Down
Loading