Skip to content

Commit

Permalink
SubWindow: Increase to respect child's sizeHint (LMMS#6956)
Browse files Browse the repository at this point in the history
Before this commit, on creation, `SubWindow` gets resized to exactly the
children's `sizeHint`. This makes the child too small, since the
`SubWindow` already contains a title bar and borders.

With this commit, the `SubWindow` is calculated such that after
rendering, the child window gets exactly the `size` that its `sizeHint`
has previously suggested.

Most of LMMS widgets are not resizable, but the Lv2 help window is a
good example to test this out. The help windows now in most cases
contain enough space to fit the help text. In some cases, it still does
not fit, though debug prints show that the `size` matches the
`sizeHint`.
  • Loading branch information
JohannesLorenz authored Nov 12, 2023
1 parent 5c37aa2 commit 652b1fa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions include/SubWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class LMMS_EXPORT SubWindow : public QMdiSubWindow
void setActiveColor( const QBrush & b );
void setTextShadowColor( const QColor &c );
void setBorderColor( const QColor &c );
int titleBarHeight() const;
int frameWidth() const;

protected:
// hook the QWidget move/resize events to update the tracked geometry
Expand Down
10 changes: 9 additions & 1 deletion src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,21 @@ void MainWindow::addSpacingToToolBar( int _size )
7, _size );
}




SubWindow* MainWindow::addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags)
{
// wrap the widget in our own *custom* window that patches some errors in QMdiSubWindow
auto win = new SubWindow(m_workspace->viewport(), windowFlags);
win->setAttribute(Qt::WA_DeleteOnClose);
win->setWidget(w);
if (w && w->sizeHint().isValid()) {win->resize(w->sizeHint());}
if (w && w->sizeHint().isValid()) {
auto titleBarHeight = win->titleBarHeight();
auto frameWidth = win->frameWidth();
QSize delta(2* frameWidth, titleBarHeight + frameWidth);
win->resize(delta + w->sizeHint());
}
m_workspace->addSubWindow(win);
return win;
}
Expand Down
32 changes: 27 additions & 5 deletions src/gui/SubWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@
#include <QMoveEvent>
#include <QPainter>
#include <QPushButton>
#include <QStyleOption>

#include "embed.h"

namespace lmms::gui
{


SubWindow::SubWindow( QWidget *parent, Qt::WindowFlags windowFlags ) :
QMdiSubWindow( parent, windowFlags ),
m_buttonSize( 17, 17 ),
m_titleBarHeight( 24 ),
m_hasFocus( false )
SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags windowFlags) :
QMdiSubWindow(parent, windowFlags),
m_buttonSize(17, 17),
m_titleBarHeight(titleBarHeight()),
m_hasFocus(false)
{
// initialize the tracked geometry to whatever Qt thinks the normal geometry currently is.
// this should always work, since QMdiSubWindows will not start as maximized
Expand Down Expand Up @@ -240,6 +241,27 @@ void SubWindow::setBorderColor( const QColor &c )




int SubWindow::titleBarHeight() const
{
QStyleOptionTitleBar so;
so.titleBarState = Qt::WindowActive; // kThemeStateActiv
so.titleBarFlags = Qt::Window;
return style()->pixelMetric(QStyle::PM_TitleBarHeight, &so, this);
}




int SubWindow::frameWidth() const
{
QStyleOptionFrame so;
return style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, &so, this);
}




/**
* @brief SubWindow::moveEvent
*
Expand Down

0 comments on commit 652b1fa

Please sign in to comment.