From e9827b0c7025a65e6986a3f1fde4597191050ff4 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Sun, 29 Sep 2024 14:20:10 +0200 Subject: [PATCH] Fix resize issues --- include/InstrumentView.h | 2 + src/gui/EffectRackView.cpp | 1 + src/gui/instrument/InstrumentTrackWindow.cpp | 43 +++++++++++++++----- src/gui/instrument/InstrumentTuningView.cpp | 2 +- src/gui/widgets/TabWidget.cpp | 27 +++++++++++- 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/include/InstrumentView.h b/include/InstrumentView.h index 40014a11f32..885cb602a3a 100644 --- a/include/InstrumentView.h +++ b/include/InstrumentView.h @@ -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() ); diff --git a/src/gui/EffectRackView.cpp b/src/gui/EffectRackView.cpp index d815ea31107..f1fd9d6a221 100644 --- a/src/gui/EffectRackView.cpp +++ b/src/gui/EffectRackView.cpp @@ -284,4 +284,5 @@ QSize EffectRackView::sizeHint() const + } // namespace lmms::gui diff --git a/src/gui/instrument/InstrumentTrackWindow.cpp b/src/gui/instrument/InstrumentTrackWindow.cpp index 1fb8596625e..774ff9343ff 100644 --- a/src/gui/instrument/InstrumentTrackWindow.cpp +++ b/src/gui/instrument/InstrumentTrackWindow.cpp @@ -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 @@ -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 ); @@ -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 @@ -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); } @@ -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(); diff --git a/src/gui/instrument/InstrumentTuningView.cpp b/src/gui/instrument/InstrumentTuningView.cpp index daa361aad6b..d495eb98ae9 100644 --- a/src/gui/instrument/InstrumentTuningView.cpp +++ b/src/gui/instrument/InstrumentTuningView.cpp @@ -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); diff --git a/src/gui/widgets/TabWidget.cpp b/src/gui/widgets/TabWidget.cpp index a370c1ea9fb..98210c0ed54 100644 --- a/src/gui/widgets/TabWidget.cpp +++ b/src/gui/widgets/TabWidget.cpp @@ -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(); @@ -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) {