Skip to content

Commit

Permalink
Prevent resizing in detached Mixer and Sample Track windows
Browse files Browse the repository at this point in the history
  • Loading branch information
messmerd committed Dec 18, 2023
1 parent 2043cac commit bf922af
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 17 deletions.
2 changes: 1 addition & 1 deletion include/DetachableWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LMMS_EXPORT DetachableWidget : public QWidget
{
Q_OBJECT
public:
explicit DetachableWidget(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags{});
using QWidget::QWidget;

void closeEvent(QCloseEvent* ce) override;

Expand Down
2 changes: 1 addition & 1 deletion include/DetachableWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LMMS_EXPORT DetachableWindow : public QMainWindow
{
Q_OBJECT
public:
explicit DetachableWindow(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags{});
using QMainWindow::QMainWindow;

void closeEvent(QCloseEvent* ce) override;

Expand Down
6 changes: 0 additions & 6 deletions src/gui/DetachableWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@

#include "DetachableWidget.h"

#include <QWidget>
#include <QCloseEvent>

#include "GuiApplication.h"
#include "MainWindow.h"

namespace lmms::gui {

DetachableWidget::DetachableWidget(QWidget* parent, Qt::WindowFlags f)
: QWidget{parent, f}
{
}

void DetachableWidget::closeEvent(QCloseEvent* ce)
{
if (windowFlags().testFlag(Qt::Window))
Expand Down
6 changes: 0 additions & 6 deletions src/gui/DetachableWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@

#include "DetachableWindow.h"

#include <QWidget>
#include <QCloseEvent>

#include "GuiApplication.h"
#include "MainWindow.h"

namespace lmms::gui {

DetachableWindow::DetachableWindow(QWidget* parent, Qt::WindowFlags f)
: QMainWindow{parent, f}
{
}

void DetachableWindow::closeEvent(QCloseEvent* ce)
{
if (windowFlags().testFlag(Qt::Window))
Expand Down
10 changes: 10 additions & 0 deletions src/gui/MixerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,23 @@ MixerView::MixerView()
this, SLOT(updateFaders()));


// adjust window size
layout()->invalidate();
resize(sizeHint());
if (parentWidget())
{
parentWidget()->resize(parentWidget()->sizeHint());
}
setFixedHeight(height());

// add ourself to workspace
QMdiSubWindow * subWin = getGUI()->mainWindow()->addWindowedWidget( this );
Qt::WindowFlags flags = subWin->windowFlags();
flags &= ~Qt::WindowMaximizeButtonHint;
subWin->setWindowFlags( flags );
layout()->setSizeConstraint( QLayout::SetMinimumSize );
subWin->layout()->setSizeConstraint( QLayout::SetMinAndMaxSize );
subWin->setFixedHeight(subWin->height());

parentWidget()->setAttribute( Qt::WA_DeleteOnClose, false );
parentWidget()->move( 5, 310 );
Expand Down
9 changes: 9 additions & 0 deletions src/gui/SampleTrackWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ SampleTrackWindow::SampleTrackWindow(SampleTrackView* stv)
flags &= ~Qt::WindowMaximizeButtonHint;
subWin->setWindowFlags(flags);

// adjust window size
layout()->invalidate();
resize(sizeHint());
if (parentWidget())
{
parentWidget()->resize(parentWidget()->sizeHint());
}
setFixedSize(size());

// Hide the Size and Maximize options from the system menu
// since the dialog size is fixed.
QMenu * systemMenu = subWin->systemMenu();
Expand Down
34 changes: 31 additions & 3 deletions src/gui/SubWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,24 @@ void SubWindow::setBorderColor( const QColor &c )

void SubWindow::detach()
{
#if QT_VERSION < 0x50C00
// Workaround for a bug in Qt versions below 5.12,
// where argument-dependent-lookup fails for QFlags operators
// declared inside a namepsace.
// This affects the Q_DECLARE_OPERATORS_FOR_FLAGS macro in Instrument.h
// See also: https://codereview.qt-project.org/c/qt/qtbase/+/225348

using ::operator|;
#endif

if (isDetached()) { return; }

auto pos = mapToGlobal(widget()->pos());
widget()->setWindowFlags(Qt::Window);
const auto pos = mapToGlobal(widget()->pos());

auto flags = windowFlags();
flags |= Qt::Window;
flags &= ~Qt::Widget;
widget()->setWindowFlags(flags);
widget()->show();
hide();

Expand All @@ -264,10 +278,24 @@ void SubWindow::detach()

void SubWindow::attach()
{
#if QT_VERSION < 0x50C00
// Workaround for a bug in Qt versions below 5.12,
// where argument-dependent-lookup fails for QFlags operators
// declared inside a namepsace.
// This affects the Q_DECLARE_OPERATORS_FOR_FLAGS macro in Instrument.h
// See also: https://codereview.qt-project.org/c/qt/qtbase/+/225348

using ::operator|;
#endif

if (!isDetached()) { return; }

auto frame = widget()->windowHandle()->frameGeometry();
widget()->setWindowFlags(Qt::Widget);

auto flags = windowFlags();
flags &= ~Qt::Window;
flags |= Qt::Widget;
widget()->setWindowFlags(flags);
widget()->show();
show();

Expand Down

0 comments on commit bf922af

Please sign in to comment.