Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resize issues #7524

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions include/InstrumentTrackWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion include/InstrumentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
} ;

Expand Down
38 changes: 38 additions & 0 deletions include/QtHelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* QtHelpers.h - Qt helper functions
*
* Copyright (c) 2025 Johannes Lorenz <jlsf2013$users.sourceforge.net, $=@>
*
* 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 <QSize>
class QWidget;

namespace lmms::gui
{

void setMinMaxFromChild(QWidget& parent, const QWidget& child, QSize space);

}

#endif // QTHELPERS_H
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions src/gui/QtHelpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* QtHelpers.cpp - Qt helper functions
*
* Copyright (c) 2025 Johannes Lorenz <jlsf2013$users.sourceforge.net, $=@>
*
* 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 <QWidget>

#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

5 changes: 5 additions & 0 deletions src/gui/SubWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <QStyleOption>

#include "embed.h"
#include "QtHelpers.h"

namespace lmms::gui
{
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 8 additions & 12 deletions src/gui/instrument/InstrumentTrackWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}



Expand Down Expand Up @@ -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();
}
Expand Down
36 changes: 30 additions & 6 deletions src/gui/widgets/TabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "DeprecationHelper.h"
#include "embed.h"
#include "FontHelper.h"
#include "QtHelpers.h"

namespace lmms::gui
{
Expand Down Expand Up @@ -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))
{
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
Loading