Skip to content

Commit

Permalink
Fix instrument resize issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesLorenz committed Nov 23, 2024
1 parent 1825208 commit 0b57f4a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/InstrumentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class LMMS_EXPORT InstrumentView : public PluginView
InstrumentView( Instrument * _instrument, QWidget * _parent );
~InstrumentView() override;

virtual bool isResizable() const { return false; }

Instrument * model()
{
return( castModel<Instrument>() );
Expand Down
17 changes: 15 additions & 2 deletions src/gui/instrument/InstrumentTrackWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) :
vlayout->addWidget( generalSettingsWidget );
// Use QWidgetItem explicitly to make the size hint change on instrument changes
// QLayout::addWidget() uses QWidgetItemV2 with size hint caching
vlayout->insertItem(1, new QWidgetItem(m_tabWidget));

vlayout->addWidget( m_tabWidget, 1 );
m_tabWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
vlayout->addWidget( m_pianoView );
setModel( _itv->model() );

Expand All @@ -288,9 +290,19 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) :
if (!m_instrumentView->isResizable()) {
flags |= Qt::MSWindowsFixedSizeDialogHint;
// any better way than this?
subWin->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
if (subWin->layout())
{
subWin->layout()->setSizeConstraint(QLayout::SetFixedSize);
}
} else {
subWin->setMaximumSize(m_instrumentView->maximumHeight() + 12, m_instrumentView->maximumWidth() + 208);
subWin->setMinimumSize( m_instrumentView->minimumWidth() + 12, m_instrumentView->minimumHeight() + 208);
subWin->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
if (subWin->layout())
{
subWin->layout()->setSizeConstraint(QLayout::SetNoConstraint);
}
}
flags &= ~Qt::WindowMaximizeButtonHint;
subWin->setWindowFlags( flags );
Expand All @@ -311,7 +323,7 @@ void InstrumentTrackWindow::resizeEvent(QResizeEvent * event) {
adjustTabSize(m_instrumentView);
adjustTabSize(m_instrumentFunctionsView);
adjustTabSize(m_ssView);
adjustTabSize(m_effectView);
// EffectRackView has sizeHint to be QSize(EffectRackView::DEFAULT_WIDTH, INSTRUMENT_HEIGHT - 4 - 1)
adjustTabSize(m_midiView);
adjustTabSize(m_tuningView);
}
Expand Down Expand Up @@ -482,6 +494,7 @@ void InstrumentTrackWindow::updateInstrumentView()
m_track->dataChanged(); // Get the text on the trackButton to change

adjustTabSize(m_instrumentView);
m_instrumentView->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
m_pianoView->setVisible(m_track->m_instrument->hasNoteInput());
// adjust window size
layout()->invalidate();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/instrument/InstrumentTuningView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ InstrumentTuningView::InstrumentTuningView(InstrumentTrack *it, QWidget *parent)
masterPitchLayout->addWidget(tlabel);

// Microtuner settings
m_microtunerNotSupportedLabel = new QLabel(tr("Microtuner is not available for MIDI-based instruments."));
m_microtunerNotSupportedLabel = new QLabel(tr("Microtuner is not available\nfor MIDI-based instruments."));
m_microtunerNotSupportedLabel->setWordWrap(true);
m_microtunerNotSupportedLabel->hide();
layout->addWidget(m_microtunerNotSupportedLabel);
Expand Down
27 changes: 25 additions & 2 deletions src/gui/widgets/TabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ void TabWidget::addTab(QWidget* w, const QString& name, const char* pixmap, int
{
w->setFixedSize(width() - 4, height() - m_tabbarHeight);
}
else
{
w->setSizePolicy(sizePolicy());
}
if(w->minimumHeight() > minimumHeight() || w->minimumSizeHint().height() > minimumHeight()) { setMinimumHeight(w->minimumHeight()); }
if(w->minimumWidth() > minimumWidth() || w->minimumSizeHint().width() > minimumWidth()) { setMinimumWidth(w->minimumWidth()); }
w->move(2, m_tabbarHeight - 1);
w->hide();

Expand Down Expand Up @@ -197,9 +203,26 @@ void TabWidget::mousePressEvent(QMouseEvent* me)



void TabWidget::resizeEvent(QResizeEvent*)
void TabWidget::resizeEvent(QResizeEvent* ev)
{
if (!m_resizable)
if (m_resizable)
{
for (const auto& widget : m_widgets)
{
if(widget.w->minimumSize().height() > ev->size().height() - 4 ||
widget.w->minimumSize().width() > ev->size().width() - m_tabbarHeight)
{
ev->ignore();
return;
}
}
for (const auto& widget : m_widgets)
{
widget.w->resize(width() - 4, height() - m_tabbarHeight);
}
QWidget::resizeEvent(ev);
}
else
{
for (const auto& widget : m_widgets)
{
Expand Down

0 comments on commit 0b57f4a

Please sign in to comment.