From c85b4982b048d4067ed5470788febd6f451c7de9 Mon Sep 17 00:00:00 2001 From: SpomJ <75751809+SpomJ@users.noreply.github.com> Date: Tue, 3 Dec 2024 23:19:25 +0300 Subject: [PATCH] [feature/detach-window] Transfer size restrictions to embedded widget from SubWindow (#7596) * Improve the way size constraints are placed * Transition VeSTige to patched SubWindow (fix missing minimize button and constraint issues) * Move window constraints to embed in LadspaBrowser (fix resizing) * Fix detached window resizeability for TapTempo * Codestyle --- plugins/LadspaBrowser/LadspaBrowser.cpp | 9 ++------- plugins/TapTempo/TapTempoView.cpp | 2 +- plugins/Vestige/Vestige.cpp | 9 +++------ plugins/Vestige/Vestige.h | 3 ++- src/gui/ControllerRackView.cpp | 7 +------ src/gui/MicrotunerConfig.cpp | 9 +++------ src/gui/MidiCCRackView.cpp | 7 +++---- src/gui/MixerView.cpp | 10 ++-------- src/gui/SubWindow.cpp | 4 ++++ src/gui/instrument/InstrumentTrackWindow.cpp | 6 +++--- src/gui/widgets/TempoSyncBarModelEditor.cpp | 4 ++-- src/gui/widgets/TempoSyncKnob.cpp | 4 ++-- 12 files changed, 28 insertions(+), 46 deletions(-) diff --git a/plugins/LadspaBrowser/LadspaBrowser.cpp b/plugins/LadspaBrowser/LadspaBrowser.cpp index e6a31e15a3c..6f2111234dc 100644 --- a/plugins/LadspaBrowser/LadspaBrowser.cpp +++ b/plugins/LadspaBrowser/LadspaBrowser.cpp @@ -140,18 +140,13 @@ LadspaBrowserView::LadspaBrowserView( ToolPlugin * _tool ) : hlayout->addWidget( ws ); hlayout->addSpacing( 10 ); hlayout->addStretch(); + + layout()->setSizeConstraint(QLayout::SetFixedSize); hide(); if( parentWidget() ) { parentWidget()->hide(); - parentWidget()->layout()->setSizeConstraint( - QLayout::SetFixedSize ); - - Qt::WindowFlags flags = parentWidget()->windowFlags(); - flags |= Qt::MSWindowsFixedSizeDialogHint; - flags &= ~Qt::WindowMaximizeButtonHint; - parentWidget()->setWindowFlags( flags ); } } diff --git a/plugins/TapTempo/TapTempoView.cpp b/plugins/TapTempo/TapTempoView.cpp index ed451eaa50e..9d6c58fa8c7 100644 --- a/plugins/TapTempo/TapTempoView.cpp +++ b/plugins/TapTempo/TapTempoView.cpp @@ -129,10 +129,10 @@ TapTempoView::TapTempoView(TapTempo* plugin) }); hide(); + layout()->setSizeConstraint(QLayout::SetFixedSize); if (parentWidget()) { parentWidget()->hide(); - parentWidget()->layout()->setSizeConstraint(QLayout::SetFixedSize); Qt::WindowFlags flags = parentWidget()->windowFlags(); flags |= Qt::MSWindowsFixedSizeDialogHint; diff --git a/plugins/Vestige/Vestige.cpp b/plugins/Vestige/Vestige.cpp index 552f76406de..7c916f3a06b 100644 --- a/plugins/Vestige/Vestige.cpp +++ b/plugins/Vestige/Vestige.cpp @@ -937,12 +937,9 @@ ManageVestigeInstrumentView::ManageVestigeInstrumentView( Instrument * _instrume widget = new QWidget(this); l = new QGridLayout( this ); - m_vi->m_subWindow = getGUI()->mainWindow()->addWindowedWidget(nullptr, Qt::SubWindow | - Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint); - m_vi->m_subWindow->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::MinimumExpanding ); - m_vi->m_subWindow->setFixedWidth( 960 ); - m_vi->m_subWindow->setMinimumHeight( 300 ); - m_vi->m_subWindow->setWidget(m_vi->m_scrollArea); + m_vi->m_subWindow = getGUI()->mainWindow()->addWindowedWidget(m_vi->m_scrollArea); + m_vi->m_scrollArea->setFixedWidth(960); + m_vi->m_scrollArea->setMinimumHeight(300); m_vi->m_subWindow->setWindowTitle( m_vi->instrumentTrack()->name() + tr( " - VST plugin control" ) ); m_vi->m_subWindow->setWindowIcon( PLUGIN_NAME::getIconPixmap( "logo" ) ); diff --git a/plugins/Vestige/Vestige.h b/plugins/Vestige/Vestige.h index 6a308ad2c20..4dcc0b8e5d8 100644 --- a/plugins/Vestige/Vestige.h +++ b/plugins/Vestige/Vestige.h @@ -32,6 +32,7 @@ #include "Instrument.h" #include "InstrumentView.h" +#include "SubWindow.h" class QPixmap; @@ -87,7 +88,7 @@ protected slots: QMutex m_pluginMutex; QString m_pluginDLL; - QMdiSubWindow * m_subWindow; + gui::SubWindow* m_subWindow; QScrollArea * m_scrollArea; FloatModel ** knobFModel; QObject * p_subWindow; diff --git a/src/gui/ControllerRackView.cpp b/src/gui/ControllerRackView.cpp index d7d5ee8dee2..9b49dd47cca 100644 --- a/src/gui/ControllerRackView.cpp +++ b/src/gui/ControllerRackView.cpp @@ -78,15 +78,10 @@ ControllerRackView::ControllerRackView() layout->addWidget( m_addButton ); this->setLayout( layout ); - QMdiSubWindow * subWin = getGUI()->mainWindow()->addWindowedWidget( this ); + SubWindow* subWin = getGUI()->mainWindow()->addWindowedWidget(this); - // TODO: Automate setting one of these, stop hardcoding title bar height - // Set dimensions for detached mode setFixedWidth(350); setMinimumHeight(200); - // Set dimensions for embedded mode - subWin->setFixedWidth(350); - subWin->setMinimumHeight(230); // No maximize button Qt::WindowFlags flags = subWin->windowFlags(); diff --git a/src/gui/MicrotunerConfig.cpp b/src/gui/MicrotunerConfig.cpp index 783c65e2870..0fa1f09eeeb 100644 --- a/src/gui/MicrotunerConfig.cpp +++ b/src/gui/MicrotunerConfig.cpp @@ -202,13 +202,10 @@ MicrotunerConfig::MicrotunerConfig() : this->setLayout(microtunerLayout); // Add to the main window and setup fixed size etc. - QMdiSubWindow *subWin = getGUI()->mainWindow()->addWindowedWidget(this); - + SubWindow* subWin = getGUI()->mainWindow()->addWindowedWidget(this); subWin->setAttribute(Qt::WA_DeleteOnClose, false); - subWin->setMinimumWidth(300); - subWin->setMinimumHeight(300); - subWin->setMaximumWidth(500); - subWin->setMaximumHeight(700); + setMinimumSize(300, 300); + setMaximumSize(500, 700); subWin->hide(); // No maximize button diff --git a/src/gui/MidiCCRackView.cpp b/src/gui/MidiCCRackView.cpp index a0b1496fb54..84d377d5ff9 100644 --- a/src/gui/MidiCCRackView.cpp +++ b/src/gui/MidiCCRackView.cpp @@ -49,7 +49,7 @@ MidiCCRackView::MidiCCRackView(InstrumentTrack * track) : setWindowIcon(embed::getIconPixmap("midi_cc_rack")); setWindowTitle(tr("MIDI CC Rack - %1").arg(m_track->name())); - QMdiSubWindow * subWin = getGUI()->mainWindow()->addWindowedWidget(this); + SubWindow* subWin = getGUI()->mainWindow()->addWindowedWidget(this); // Remove maximize button Qt::WindowFlags flags = subWin->windowFlags(); @@ -58,9 +58,8 @@ MidiCCRackView::MidiCCRackView(InstrumentTrack * track) : // Adjust window attributes, sizing and position subWin->setAttribute(Qt::WA_DeleteOnClose, false); - subWin->resize(350, 300); - subWin->setFixedWidth(350); - subWin->setMinimumHeight(300); + setFixedWidth(350); + setMinimumHeight(300); subWin->hide(); // Main window layout diff --git a/src/gui/MixerView.cpp b/src/gui/MixerView.cpp index e34e4ecbb97..d38b07330da 100644 --- a/src/gui/MixerView.cpp +++ b/src/gui/MixerView.cpp @@ -169,17 +169,11 @@ MixerView::MixerView(Mixer* mixer) : // adjust window size layout()->invalidate(); resize(sizeHint()); - if (parentWidget()) - { - parentWidget()->resize(parentWidget()->sizeHint()); - } setFixedHeight(height()); + layout()->setSizeConstraint(QLayout::SetMinimumSize); // add ourself to workspace - QMdiSubWindow* subWin = mainWindow->addWindowedWidget(this); - layout()->setSizeConstraint(QLayout::SetMinimumSize); - subWin->layout()->setSizeConstraint(QLayout::SetMinAndMaxSize); - subWin->setFixedHeight(subWin->height()); + [[maybe_unused]] SubWindow* subWin = mainWindow->addWindowedWidget(this); parentWidget()->setAttribute(Qt::WA_DeleteOnClose, false); parentWidget()->move(5, 310); diff --git a/src/gui/SubWindow.cpp b/src/gui/SubWindow.cpp index 533777d32ac..05d240aed63 100644 --- a/src/gui/SubWindow.cpp +++ b/src/gui/SubWindow.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include "embed.h" @@ -93,6 +94,8 @@ SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags windowFlags) : m_windowTitle->setAttribute( Qt::WA_TransparentForMouseEvents, true ); m_windowTitle->setGraphicsEffect( m_shadow ); + layout()->setSizeConstraint(QLayout::SetMinAndMaxSize); + // Disable the minimize button and make sure that the custom window hint is set setWindowFlags((this->windowFlags() & ~Qt::WindowMinimizeButtonHint) | Qt::CustomizeWindowHint); @@ -518,4 +521,5 @@ bool SubWindow::eventFilter(QObject* obj, QEvent* event) } } + } // namespace lmms::gui diff --git a/src/gui/instrument/InstrumentTrackWindow.cpp b/src/gui/instrument/InstrumentTrackWindow.cpp index 7f598636534..f98a985d98c 100644 --- a/src/gui/instrument/InstrumentTrackWindow.cpp +++ b/src/gui/instrument/InstrumentTrackWindow.cpp @@ -283,7 +283,7 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : updateInstrumentView(); - QMdiSubWindow* subWin = getGUI()->mainWindow()->addWindowedWidget( this ); + SubWindow* subWin = getGUI()->mainWindow()->addWindowedWidget( this ); Qt::WindowFlags flags = subWin->windowFlags(); if (!m_instrumentView->isResizable()) { flags |= Qt::MSWindowsFixedSizeDialogHint; @@ -293,8 +293,8 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : // Does the same thing, for detached detached windows, for other OSs. } else { - subWin->setMaximumSize(m_instrumentView->maximumWidth() + 12, m_instrumentView->maximumHeight() + 208); - subWin->setMinimumSize(m_instrumentView->minimumWidth() + 12, m_instrumentView->minimumHeight() + 208); + setMaximumSize(m_instrumentView->maximumWidth() + 12, m_instrumentView->maximumHeight() + 208); + setMinimumSize(m_instrumentView->minimumWidth() + 12, m_instrumentView->minimumHeight() + 208); } flags &= ~Qt::WindowMaximizeButtonHint; subWin->setWindowFlags( flags ); diff --git a/src/gui/widgets/TempoSyncBarModelEditor.cpp b/src/gui/widgets/TempoSyncBarModelEditor.cpp index 5ff2332e051..acf8dde6210 100644 --- a/src/gui/widgets/TempoSyncBarModelEditor.cpp +++ b/src/gui/widgets/TempoSyncBarModelEditor.cpp @@ -202,11 +202,11 @@ void TempoSyncBarModelEditor::showCustom() if(m_custom == nullptr) { m_custom = new MeterDialog(getGUI()->mainWindow()->workspace()); - QMdiSubWindow * subWindow = getGUI()->mainWindow()->addWindowedWidget(m_custom); + SubWindow* subWindow = getGUI()->mainWindow()->addWindowedWidget(m_custom); Qt::WindowFlags flags = subWindow->windowFlags(); flags &= ~Qt::WindowMaximizeButtonHint; subWindow->setWindowFlags(flags); - subWindow->setFixedSize(subWindow->size()); + setFixedSize(size()); m_custom->setWindowTitle("Meter"); m_custom->setModel(&model()->getCustomMeterModel()); } diff --git a/src/gui/widgets/TempoSyncKnob.cpp b/src/gui/widgets/TempoSyncKnob.cpp index 473cee28ca9..df9b50eb2f8 100644 --- a/src/gui/widgets/TempoSyncKnob.cpp +++ b/src/gui/widgets/TempoSyncKnob.cpp @@ -295,11 +295,11 @@ void TempoSyncKnob::showCustom() if( m_custom == nullptr ) { m_custom = new MeterDialog( getGUI()->mainWindow()->workspace() ); - QMdiSubWindow * subWindow = getGUI()->mainWindow()->addWindowedWidget( m_custom ); + SubWindow* subWindow = getGUI()->mainWindow()->addWindowedWidget(m_custom); Qt::WindowFlags flags = subWindow->windowFlags(); flags &= ~Qt::WindowMaximizeButtonHint; subWindow->setWindowFlags( flags ); - subWindow->setFixedSize( subWindow->size() ); + setFixedSize(size()); m_custom->setWindowTitle( "Meter" ); m_custom->setModel( &model()->m_custom ); }