diff --git a/include/InstrumentTrackWindow.h b/include/InstrumentTrackWindow.h index d4b285ccdaa..7dcfdb50f0a 100644 --- a/include/InstrumentTrackWindow.h +++ b/include/InstrumentTrackWindow.h @@ -69,8 +69,6 @@ class InstrumentTrackWindow : public QWidget, public ModelView, InstrumentTrackWindow( InstrumentTrackView * _tv ); ~InstrumentTrackWindow() override; - void resizeEvent(QResizeEvent* event) override; - // parent for all internal tab-widgets TabWidget * tabWidgetParent() diff --git a/include/InstrumentView.h b/include/InstrumentView.h index 40014a11f32..12bcf14b262 100644 --- a/include/InstrumentView.h +++ b/include/InstrumentView.h @@ -64,11 +64,16 @@ class LMMS_EXPORT InstrumentView : public PluginView //! Instrument view with fixed LMMS-default size class LMMS_EXPORT InstrumentViewFixedSize : public InstrumentView { +protected: QSize sizeHint() const override { return QSize(250, 250); } QSize minimumSizeHint() const override { return sizeHint(); } public: - using InstrumentView::InstrumentView; + InstrumentViewFixedSize(Instrument* instrument, QWidget* parent) + : InstrumentView(instrument, parent) + { + setFixedSize(sizeHint()); + } ~InstrumentViewFixedSize() override = default; } ; diff --git a/include/QtHelpers.h b/include/QtHelpers.h new file mode 100644 index 00000000000..51df3882731 --- /dev/null +++ b/include/QtHelpers.h @@ -0,0 +1,38 @@ +/* + * QtHelpers.h - Qt helper functions + * + * Copyright (c) 2025 Johannes Lorenz + * + * This file is part of LMMS - https://lmms.io + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#ifndef QTHELPERS_H +#define QTHELPERS_H + +#include +class QWidget; + +namespace lmms::gui +{ + +void setMinMaxFromChild(QWidget& parent, const QWidget& child, QSize space); + +} + +#endif // QTHELPERS_H diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index fe4a2c462b2..48141379556 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -32,6 +32,7 @@ SET(LMMS_SRCS gui/PeakControllerDialog.cpp gui/PluginBrowser.cpp gui/ProjectNotes.cpp + gui/QtHelpers.cpp gui/RowTableView.cpp gui/SampleLoader.cpp gui/SampleTrackWindow.cpp diff --git a/src/gui/QtHelpers.cpp b/src/gui/QtHelpers.cpp new file mode 100644 index 00000000000..2c9446936f3 --- /dev/null +++ b/src/gui/QtHelpers.cpp @@ -0,0 +1,55 @@ +/* + * QtHelpers.cpp - Qt helper functions + * + * Copyright (c) 2025 Johannes Lorenz + * + * This file is part of LMMS - https://lmms.io + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#include + +#include "QtHelpers.h" + +namespace lmms::gui +{ + +void setMinMaxFromChild(QWidget& parent, const QWidget& child, QSize space) +{ + // If the child has a maximum, we cannot grow larger + if(parent.maximumHeight() > child.maximumHeight() + space.height()) + { + parent.setMaximumHeight(child.maximumHeight() + space.height()); + } + if(parent.maximumWidth() > child.maximumWidth() + space.width()) + { + parent.setMaximumWidth(child.maximumWidth() + space.width()); + } + // If the child has a minimum, we cannot shrink smaller + if(parent.minimumHeight() < child.minimumHeight() + space.height()) + { + parent.setMinimumHeight(child.minimumHeight() + space.height()); + } + if(parent.minimumWidth() < child.minimumWidth() + space.width()) + { + parent.setMinimumWidth(child.minimumWidth() + space.width()); + } +} + +} // namespace lmms::gui + diff --git a/src/gui/SubWindow.cpp b/src/gui/SubWindow.cpp index a76f4055e99..7659e02740d 100644 --- a/src/gui/SubWindow.cpp +++ b/src/gui/SubWindow.cpp @@ -37,6 +37,7 @@ #include #include "embed.h" +#include "QtHelpers.h" namespace lmms::gui { @@ -398,6 +399,10 @@ void SubWindow::focusChanged( QMdiSubWindow *subWindow ) */ void SubWindow::resizeEvent( QResizeEvent * event ) { + if (widget()) { + setMinMaxFromChild(*this, *widget(), QSize(8, m_titleBarHeight + 6)); + } + // When the parent QMdiArea gets resized, maximized subwindows also gets resized, if any. // In that case, we should call QMdiSubWindow::resizeEvent first // to ensure we get the correct window state. diff --git a/src/gui/instrument/InstrumentTrackWindow.cpp b/src/gui/instrument/InstrumentTrackWindow.cpp index f6f30d020af..1ca00d32cd2 100644 --- a/src/gui/instrument/InstrumentTrackWindow.cpp +++ b/src/gui/instrument/InstrumentTrackWindow.cpp @@ -292,15 +292,6 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : subWin->hide(); } -void InstrumentTrackWindow::resizeEvent(QResizeEvent * event) { - /* m_instrumentView->resize(QSize(size().width()-1, maxHeight)); */ - adjustTabSize(m_instrumentView); - adjustTabSize(m_instrumentFunctionsView); - adjustTabSize(m_ssView); - adjustTabSize(m_effectView); - adjustTabSize(m_midiView); - adjustTabSize(m_tuningView); -} @@ -468,16 +459,21 @@ void InstrumentTrackWindow::updateInstrumentView() modelChanged(); // Get the instrument window to refresh m_track->dataChanged(); // Get the text on the trackButton to change - adjustTabSize(m_instrumentView); + m_pianoView->setVisible(m_track->m_instrument->hasNoteInput()); // adjust window size layout()->invalidate(); resize(sizeHint()); - if (parentWidget()) + + if(m_tabWidget->minimumSize() == m_tabWidget->maximumSize()) { - parentWidget()->resize(parentWidget()->sizeHint()); + setFixedSize(sizeHint()); + setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); } + else + resize(sizeHint()); + update(); m_instrumentView->update(); } diff --git a/src/gui/widgets/TabWidget.cpp b/src/gui/widgets/TabWidget.cpp index 81fae1c043a..47ecdd209cb 100644 --- a/src/gui/widgets/TabWidget.cpp +++ b/src/gui/widgets/TabWidget.cpp @@ -34,6 +34,7 @@ #include "DeprecationHelper.h" #include "embed.h" #include "FontHelper.h" +#include "QtHelpers.h" namespace lmms::gui { @@ -68,12 +69,15 @@ TabWidget::TabWidget(const QString& caption, QWidget* parent, bool usePixmap, } + + + void TabWidget::addTab(QWidget* w, const QString& name, const char* pixmap, int idx) { // Append tab when position is not given - if (idx < 0/* || m_widgets.contains(idx) == true*/) + if (idx < 0/* || m_widgets.contains(idx)*/) { - while(m_widgets.contains(++idx) == true) + while(m_widgets.contains(++idx)) { } } @@ -85,9 +89,21 @@ void TabWidget::addTab(QWidget* w, const QString& name, const char* pixmap, int widgetDesc d = {w, pixmap, name, tab_width}; m_widgets[idx] = d; - // Position tab's window - if (!m_resizable) + // Position tab's window and update size + if (m_resizable) + { + // If the child has a maximum, we cannot grow larger + setMinMaxFromChild(*this, *w, QSize(4, m_tabbarHeight)); + + // Now that the size might have changed: resize all widgets + for (const auto& widget : m_widgets) + { + widget.w->resize(width() - 4, height() - m_tabbarHeight); + } + } + else { + // Tab widget is fixed -> child must be fixed w->setFixedSize(width() - 4, height() - m_tabbarHeight); } w->move(2, m_tabbarHeight - 1); @@ -197,9 +213,17 @@ 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) + { + widget.w->resize(width() - 4, height() - m_tabbarHeight); + } + QWidget::resizeEvent(ev); + } + else { for (const auto& widget : m_widgets) {