Minor adjustments

This commit is contained in:
Dalton Messmer
2025-11-24 02:16:13 -05:00
parent 59bf2b085f
commit dfa91db232
13 changed files with 122 additions and 93 deletions

View File

@@ -30,7 +30,6 @@
#include "ModelView.h"
namespace lmms
{

View File

@@ -84,8 +84,7 @@ private:
QMdiSubWindow * m_subWindow;
ControllerDialog * m_controllerDlg;
QLabel * m_nameLabel;
} ;
};
} // namespace lmms::gui

View File

@@ -30,7 +30,6 @@
#include "ModelView.h"
namespace lmms
{

View File

@@ -74,7 +74,6 @@ public slots:
void moveDown();
void deletePlugin();
signals:
void movedUp(EffectView* view);
void movedDown(EffectView* view);

View File

@@ -40,7 +40,6 @@
#include "MainWindow.h"
#include "Song.h"
#include "SubWindow.h"
#include "embed.h"
namespace lmms::gui
{

View File

@@ -50,8 +50,8 @@ ControllerView::ControllerView(Controller* model, QWidget* parent)
, m_subWindow{nullptr}
, m_controllerDlg{nullptr}
{
this->setFrameStyle(QFrame::StyledPanel);
this->setFrameShadow(QFrame::Raised);
setFrameStyle(QFrame::StyledPanel);
setFrameShadow(QFrame::Raised);
setFocusPolicy(Qt::StrongFocus);
auto vBoxLayout = new QVBoxLayout(this);

View File

@@ -118,11 +118,11 @@ void EffectView::editControls()
{
if( m_subWindow )
{
if( !m_controlView->isVisible() )
if (!m_controlView->isVisible())
{
m_subWindow->show();
m_subWindow->raise();
effect()->controls()->setViewVisible( true ); // TODO is this even needed?
effect()->controls()->setViewVisible(true); // TODO is this even needed?
}
else
{

View File

@@ -484,15 +484,10 @@ void MainWindow::finalize()
}
// Add editor subwindows
for (QWidget* widget : std::list<QWidget*>{
getGUI()->automationEditor(),
getGUI()->patternEditor(),
getGUI()->pianoRoll(),
getGUI()->songEditor()
})
{
addWindowedWidget(widget);
}
addWindowedWidget(getGUI()->automationEditor());
addWindowedWidget(getGUI()->patternEditor());
addWindowedWidget(getGUI()->pianoRoll());
addWindowedWidget(getGUI()->songEditor());
getGUI()->automationEditor()->parentWidget()->hide();
getGUI()->patternEditor()->parentWidget()->move(610, 5);
@@ -542,22 +537,30 @@ SubWindow* MainWindow::addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags
auto win = new SubWindow(m_workspace->viewport(), windowFlags);
connect(this, &MainWindow::detachAllSubWindows, win, &SubWindow::setDetached);
win->setWidget(w);
if (w) { connect(w, &QWidget::destroyed, win, &SubWindow::deleteLater); } // TODO somehow make this work on any setWidget
if (w && w->sizeHint().isValid()) {
auto titleBarHeight = win->titleBarHeight();
auto frameWidth = win->frameWidth();
QSize delta(2* frameWidth, titleBarHeight + frameWidth);
win->resize(delta + w->sizeHint());
if (w)
{
// TODO: somehow make this work on any setWidget
connect(w, &QWidget::destroyed, win, &SubWindow::deleteLater);
if (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;
}
void MainWindow::setAllSubWindowsDetached(bool detachState)
void MainWindow::setAllSubWindowsDetached(bool detached)
{
emit detachAllSubWindows(detachState);
emit detachAllSubWindows(detached);
}
@@ -657,10 +660,18 @@ void MainWindow::clearKeyModifiers()
void MainWindow::saveWidgetState(QWidget* w, QDomElement& de)
{
// TODO only use one of these
SubWindow* win = qobject_cast<SubWindow*>(w); // nullptr if not
if (!win && w->parentWidget()) { win = qobject_cast<SubWindow*>(w->parentWidget()); } // try parent instead
if (!win) { return; } // finally, soft-fail if neither can find the window
// TODO: Only use one of these
auto win = qobject_cast<SubWindow*>(w);
if (!win)
{
// Fall back on parent
win = qobject_cast<SubWindow*>(w->parentWidget());
if (!win)
{
// Still could not find the window - soft fail
return;
}
}
de.setAttribute("visible", bool{win->widget() && win->widget()->isVisible()});
de.setAttribute("maximized", win->isMaximized());
@@ -677,15 +688,25 @@ void MainWindow::saveWidgetState(QWidget* w, QDomElement& de)
void MainWindow::restoreWidgetState(QWidget* w, const QDomElement& de)
{
// TODO only use one of these
SubWindow* win = qobject_cast<SubWindow*>(w); // nullptr if not
if (!win && w->parentWidget()) { win = qobject_cast<SubWindow*>(w->parentWidget()); } // try parent instead
if (!win) { return; } // finally, soft-fail if neither can find the window
// TODO: Only use one of these
auto win = qobject_cast<SubWindow*>(w);
if (!win)
{
// Fall back on parent
win = qobject_cast<SubWindow*>(w->parentWidget());
if (!win)
{
// Still could not find the window - soft fail
return;
}
}
QRect normalGeometry(de.attribute("x").toInt(),
de.attribute("y").toInt(),
de.attribute("width").toInt(),
de.attribute("height").toInt());
const auto normalGeometry = QRect {
de.attribute("x").toInt(),
de.attribute("y").toInt(),
de.attribute("width").toInt(),
de.attribute("height").toInt()
};
if (normalGeometry.isValid())
{
@@ -697,12 +718,15 @@ void MainWindow::restoreWidgetState(QWidget* w, const QDomElement& de)
// set the window to its correct minimized/maximized/restored state
Qt::WindowStates winState = win->windowState();
winState = de.attribute("maximized").toInt()
? (winState | Qt::WindowMaximized)
: (winState & ~Qt::WindowMaximized);
? (winState | Qt::WindowMaximized)
: (winState & ~Qt::WindowMaximized);
win->setWindowState(winState);
}
if (de.hasAttribute("visible")) { win->setVisible(de.attribute("visible").toInt()); }
if (const auto visible = de.attribute("visible"); !visible.isEmpty())
{
win->setVisible(visible.toInt());
}
}
@@ -1062,15 +1086,15 @@ void MainWindow::updateViewMenu()
m_viewMenu->addSeparator();
auto detachAllAction = m_viewMenu->addAction(embed::getIconPixmap("detach"),
tr("Detach all subwindows"),
this, [this](){setAllSubWindowsDetached(true);},
QKeySequence {Qt::CTRL | Qt::SHIFT | Qt::Key_D}
);
tr("Detach all subwindows"),
this, [this](){ setAllSubWindowsDetached(true); },
QKeySequence{Qt::CTRL | Qt::SHIFT | Qt::Key_D}
);
auto attachAllAction = m_viewMenu->addAction(embed::getIconPixmap("detach"),
tr("Attach all subwindows"),
this, [this](){setAllSubWindowsDetached(false);},
QKeySequence {Qt::CTRL | Qt::ALT | Qt::SHIFT | Qt::Key_D}
);
tr("Attach all subwindows"),
this, [this](){ setAllSubWindowsDetached(false); },
QKeySequence{Qt::CTRL | Qt::ALT | Qt::SHIFT | Qt::Key_D}
);
detachAllAction->setShortcutContext(Qt::ApplicationShortcut);
attachAllAction->setShortcutContext(Qt::ApplicationShortcut);

View File

@@ -56,9 +56,9 @@ namespace lmms::gui
MixerView::MixerView(Mixer* mixer) :
QWidget{},
ModelView{nullptr, this},
SerializingObjectHook{},
QWidget(),
ModelView(nullptr, this),
SerializingObjectHook(),
m_mixer(mixer)
{
mixer->setHook(this);
@@ -165,7 +165,7 @@ MixerView::MixerView(Mixer* mixer) :
layout()->setSizeConstraint(QLayout::SetMinimumSize);
// add ourself to workspace
[[maybe_unused]] SubWindow* subWin = mainWindow->addWindowedWidget(this);
mainWindow->addWindowedWidget(this);
parentWidget()->setAttribute(Qt::WA_DeleteOnClose, false);
parentWidget()->move(5, 310);

View File

@@ -249,7 +249,7 @@ void SampleTrackWindow::closeEvent(QCloseEvent* ce)
void SampleTrackWindow::saveSettings([[maybe_unused]] QDomDocument& doc, QDomElement& element)
void SampleTrackWindow::saveSettings(QDomDocument& doc, QDomElement& element)
{
MainWindow::saveWidgetState(this, element);
}

View File

@@ -50,7 +50,7 @@ namespace lmms::gui
{
SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags windowFlags)
SubWindow::SubWindow(QWidget* parent, Qt::WindowFlags windowFlags)
: QMdiSubWindow{parent, windowFlags}
, m_buttonSize{17, 17}
, m_titleBarHeight{titleBarHeight()}
@@ -67,7 +67,7 @@ SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags windowFlags)
m_borderColor = Qt::black;
// close, maximize, restore, and detach buttons
auto createButton = [this](const std::string& iconName, const QString& tooltip) -> QPushButton* {
auto createButton = [this](std::string_view iconName, const QString& tooltip) -> QPushButton* {
auto button = new QPushButton{embed::getIconPixmap(iconName), QString{}, this};
button->resize(m_buttonSize);
button->setFocusPolicy(Qt::NoFocus);
@@ -199,7 +199,6 @@ bool SubWindow::isDetachable() const
void SubWindow::setDetachable(bool on)
{
m_isDetachable = on;
}
@@ -336,15 +335,15 @@ void SubWindow::attach()
frame += decorationMargins();
// Make sure the window fully fits on screen
frame.setSize({std::min(frame.width(), mdiArea()->width()),
std::min(frame.height(), mdiArea()->height())});
frame.setSize({
std::min(frame.width(), mdiArea()->width()),
std::min(frame.height(), mdiArea()->height())
});
frame.moveTo(std::clamp(frame.left(),
0,
mdiArea()->rect().width() - frame.width()),
std::clamp(frame.top(),
0,
mdiArea()->rect().height() - frame.height()));
frame.moveTo(
std::clamp(frame.left(), 0, mdiArea()->rect().width() - frame.width()),
std::clamp(frame.top(), 0, mdiArea()->rect().height() - frame.height())
);
auto flags = windowFlags();
flags &= ~Qt::Window;
@@ -360,7 +359,9 @@ void SubWindow::attach()
if (QGuiApplication::platformName() == "wayland")
{
resize(frame.size()); // Workaround for wayland reporting position as 0-0, see https://doc.qt.io/qt-6.9/application-windows.html#wayland-peculiarities
// Workaround for wayland reporting position as 0-0
// See https://doc.qt.io/qt-6.9/application-windows.html#wayland-peculiarities
resize(frame.size());
}
else
{
@@ -392,10 +393,12 @@ int SubWindow::frameWidth() const
QMargins SubWindow::decorationMargins() const
{
return QMargins(frameWidth(), // left
titleBarHeight(), // top
frameWidth(), // right
frameWidth()); // bottom
return {
frameWidth(), // left
titleBarHeight(), // top
frameWidth(), // right
frameWidth() // bottom
};
}
@@ -468,8 +471,8 @@ void SubWindow::adjustTitleBar()
const int buttonGap = 1;
const int menuButtonSpace = 24;
QPoint buttonPos(width() - rightSpace - m_buttonSize.width(), 3);
const QPoint buttonStep( m_buttonSize.width() + buttonGap, 0 );
auto buttonPos = QPoint{width() - rightSpace - m_buttonSize.width(), 3};
const auto buttonStep = QPoint{m_buttonSize.width() + buttonGap, 0};
// the buttonBarWidth depends on the number of buttons.
// we need it to calculate the width of window title label

View File

@@ -669,34 +669,34 @@ void InstrumentTrackWindow::viewInstrumentInDirection(int d)
// avoid reloading the window if there is only one instrument, as that will just change the active tab
if (idxOfNext != idxOfMe)
{
SubWindow* source_subwin = static_cast<SubWindow*>(parentWidget());
SubWindow* target_subwin = static_cast<SubWindow*>(newView->getInstrumentTrackWindow()->parentWidget());
QWidget* source_widget;
QWidget* target_widget;
const auto sourceSubwin = static_cast<SubWindow*>(parentWidget());
const auto targetSubwin = static_cast<SubWindow*>(newView->getInstrumentTrackWindow()->parentWidget());
QWidget* sourceWidget;
QWidget* targetWidget;
// set widgets we move and get our position from
if (source_subwin->isDetached())
if (sourceSubwin->isDetached())
{
source_widget = this;
target_widget = newView->getInstrumentTrackWindow();
sourceWidget = this;
targetWidget = newView->getInstrumentTrackWindow();
}
else
{
source_widget = parentWidget();
target_widget = newView->getInstrumentTrackWindow()->parentWidget();
sourceWidget = parentWidget();
targetWidget = newView->getInstrumentTrackWindow()->parentWidget();
}
// save current window pos and then hide the window by unchecking its button in the track list
QPoint curPos = source_widget->pos();
QPoint curPos = sourceWidget->pos();
m_itv->m_tlb->setChecked(false);
// enable the new window by checking its track list button & moving it to where our window just was
newView->m_tlb->setChecked(true);
// sync detached state with current widget like we do with position
target_subwin->setDetached(source_subwin->isDetached());
targetSubwin->setDetached(sourceSubwin->isDetached());
target_widget->move(curPos);
targetWidget->move(curPos);
// scroll the SongEditor/PatternEditor to make sure the new trackview label is visible
bringToFront->trackContainerView()->scrollToTrackView(bringToFront);

View File

@@ -24,6 +24,8 @@
#include "InstrumentTrackView.h"
#include <ranges>
#include <QAction>
#include <QApplication>
#include <QDragEnterEvent>
@@ -207,14 +209,19 @@ void InstrumentTrackView::toggleMidiCCRack()
InstrumentTrackWindow* InstrumentTrackView::topLevelInstrumentTrackWindow()
{
auto subWindowList = getGUI()->mainWindow()->workspace()->subWindowList(QMdiArea::ActivationHistoryOrder);
auto winIt = std::find_if(subWindowList.rbegin(), subWindowList.rend(),
[](QMdiSubWindow* sw){return sw->widget()
&& sw->widget()->isVisible()
&& sw->widget()->inherits("lmms::gui::InstrumentTrackWindow");});
return winIt != subWindowList.rend() && (**winIt).widget()
? qobject_cast<InstrumentTrackWindow*>((**winIt).widget())
: nullptr;
const auto subWindows = getGUI()->mainWindow()->workspace()->subWindowList(QMdiArea::ActivationHistoryOrder);
for (QMdiSubWindow* sw : subWindows | std::views::reverse)
{
if (!sw->widget() || !sw->widget()->isVisible()) { continue; }
if (auto itw = qobject_cast<InstrumentTrackWindow*>(sw->widget()))
{
return itw;
}
}
return nullptr;
}