From e3501e79a19c520f63ec4256ed34036a52533835 Mon Sep 17 00:00:00 2001 From: SpomJ Date: Sat, 23 Nov 2024 15:16:03 +0300 Subject: [PATCH] Improve the way size constraints are placed --- src/gui/ControllerRackView.cpp | 7 +------ src/gui/MicrotunerConfig.cpp | 9 +++------ src/gui/MidiCCRackView.cpp | 7 +++---- src/gui/MixerView.cpp | 8 +------- src/gui/SubWindow.cpp | 4 ++++ src/gui/instrument/InstrumentTrackWindow.cpp | 6 +++--- src/gui/widgets/TempoSyncBarModelEditor.cpp | 4 ++-- src/gui/widgets/TempoSyncKnob.cpp | 4 ++-- 8 files changed, 19 insertions(+), 30 deletions(-) diff --git a/src/gui/ControllerRackView.cpp b/src/gui/ControllerRackView.cpp index d7d5ee8dee2..83e2165e130 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..bf191d9e74f 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..cef8898e760 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..0c3808f6a09 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()); 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..31644b72398 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..ced453d10bb 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 ); }