Skip to content

Commit

Permalink
Fix resize issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesLorenz committed Sep 29, 2024
1 parent 1825208 commit e9827b0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 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
1 change: 1 addition & 0 deletions src/gui/EffectRackView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,5 @@ QSize EffectRackView::sizeHint() const




} // namespace lmms::gui
43 changes: 32 additions & 11 deletions src/gui/instrument/InstrumentTrackWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) :


m_tabWidget = new TabWidget( "", this, true, true );
m_tabWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
// "-1" :
// in "TabWidget::addTab", under "Position tab's window", the widget is
// moved up by 1 pixel
Expand Down Expand Up @@ -264,6 +265,7 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) :
m_tabWidget->addTab(m_midiView, tr("MIDI"), "midi_tab", 4);
m_tabWidget->addTab(m_tuningView, tr("Tuning and transposition"), "tuning_tab", 5);


// setup piano-widget
m_pianoView = new PianoView( this );
m_pianoView->setMinimumHeight( PIANO_HEIGHT );
Expand All @@ -277,23 +279,41 @@ 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() );

updateInstrumentView();

QMdiSubWindow* subWin = getGUI()->mainWindow()->addWindowedWidget( this );
Qt::WindowFlags flags = subWin->windowFlags();
if (!m_instrumentView->isResizable()) {
flags |= Qt::MSWindowsFixedSizeDialogHint;
// any better way than this?
} else {
subWin->setMaximumSize(m_instrumentView->maximumHeight() + 12, m_instrumentView->maximumWidth() + 208);
subWin->setMinimumSize( m_instrumentView->minimumWidth() + 12, m_instrumentView->minimumHeight() + 208);
if (true)
{
subWin->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
if (subWin->layout())
{
subWin->layout()->setSizeConstraint(QLayout::SetNoConstraint);
}
}
else
{
subWin->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
if (subWin->layout())
{
subWin->layout()->setSizeConstraint(QLayout::SetFixedSize);
}
Qt::WindowFlags flags = subWin->windowFlags();
if (!m_instrumentView->isResizable()) {
flags |= Qt::MSWindowsFixedSizeDialogHint;
// any better way than this?
} else {
subWin->setMaximumSize(m_instrumentView->maximumHeight() + 12, m_instrumentView->maximumWidth() + 208);
subWin->setMinimumSize( m_instrumentView->minimumWidth() + 12, m_instrumentView->minimumHeight() + 208);
}
flags &= ~Qt::WindowMaximizeButtonHint;
subWin->setWindowFlags( flags );
}
flags &= ~Qt::WindowMaximizeButtonHint;
subWin->setWindowFlags( flags );


// Hide the Size and Maximize options from the system menu
Expand All @@ -311,7 +331,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 +502,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 e9827b0

Please sign in to comment.