diff --git a/include/SubWindow.h b/include/SubWindow.h index fdda6de42..d1cc6a7af 100644 --- a/include/SubWindow.h +++ b/include/SubWindow.h @@ -68,6 +68,8 @@ public: 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 diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 145467ed7..6acaa4b86 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -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; } diff --git a/src/gui/SubWindow.cpp b/src/gui/SubWindow.cpp index 78e4f586c..dc6e49297 100644 --- a/src/gui/SubWindow.cpp +++ b/src/gui/SubWindow.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "embed.h" @@ -41,11 +42,11 @@ 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 @@ -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 *