diff --git a/include/ControllerDialog.h b/include/ControllerDialog.h index fc6e78f84..a8803de60 100644 --- a/include/ControllerDialog.h +++ b/include/ControllerDialog.h @@ -30,7 +30,6 @@ #include "ModelView.h" - namespace lmms { diff --git a/include/ControllerView.h b/include/ControllerView.h index acb522470..03fb1ec32 100644 --- a/include/ControllerView.h +++ b/include/ControllerView.h @@ -84,8 +84,7 @@ private: QMdiSubWindow * m_subWindow; ControllerDialog * m_controllerDlg; QLabel * m_nameLabel; - -} ; +}; } // namespace lmms::gui diff --git a/include/EffectControlDialog.h b/include/EffectControlDialog.h index bce85000f..5f475594c 100644 --- a/include/EffectControlDialog.h +++ b/include/EffectControlDialog.h @@ -30,7 +30,6 @@ #include "ModelView.h" - namespace lmms { diff --git a/include/EffectView.h b/include/EffectView.h index 382f7025a..bb9c91498 100644 --- a/include/EffectView.h +++ b/include/EffectView.h @@ -74,7 +74,6 @@ public slots: void moveDown(); void deletePlugin(); - signals: void movedUp(EffectView* view); void movedDown(EffectView* view); diff --git a/src/gui/ControllerRackView.cpp b/src/gui/ControllerRackView.cpp index 65dea5f0a..508b4197a 100644 --- a/src/gui/ControllerRackView.cpp +++ b/src/gui/ControllerRackView.cpp @@ -40,7 +40,6 @@ #include "MainWindow.h" #include "Song.h" #include "SubWindow.h" -#include "embed.h" namespace lmms::gui { diff --git a/src/gui/ControllerView.cpp b/src/gui/ControllerView.cpp index 21424385f..adf2d2eb7 100644 --- a/src/gui/ControllerView.cpp +++ b/src/gui/ControllerView.cpp @@ -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); diff --git a/src/gui/EffectView.cpp b/src/gui/EffectView.cpp index 3874f0de6..5db377de4 100644 --- a/src/gui/EffectView.cpp +++ b/src/gui/EffectView.cpp @@ -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 { diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index e02497191..577c89efa 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -484,15 +484,10 @@ void MainWindow::finalize() } // Add editor subwindows - for (QWidget* widget : std::list{ - 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(w); // nullptr if not - if (!win && w->parentWidget()) { win = qobject_cast(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(w); + if (!win) + { + // Fall back on parent + win = qobject_cast(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(w); // nullptr if not - if (!win && w->parentWidget()) { win = qobject_cast(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(w); + if (!win) + { + // Fall back on parent + win = qobject_cast(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); diff --git a/src/gui/MixerView.cpp b/src/gui/MixerView.cpp index 5dd8aef16..c7b44bd19 100644 --- a/src/gui/MixerView.cpp +++ b/src/gui/MixerView.cpp @@ -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); diff --git a/src/gui/SampleTrackWindow.cpp b/src/gui/SampleTrackWindow.cpp index 4a38d09b7..872e7ad20 100644 --- a/src/gui/SampleTrackWindow.cpp +++ b/src/gui/SampleTrackWindow.cpp @@ -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); } diff --git a/src/gui/SubWindow.cpp b/src/gui/SubWindow.cpp index 73f5faca8..d65964048 100644 --- a/src/gui/SubWindow.cpp +++ b/src/gui/SubWindow.cpp @@ -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 diff --git a/src/gui/instrument/InstrumentTrackWindow.cpp b/src/gui/instrument/InstrumentTrackWindow.cpp index 455f30077..71d2eadd8 100644 --- a/src/gui/instrument/InstrumentTrackWindow.cpp +++ b/src/gui/instrument/InstrumentTrackWindow.cpp @@ -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(parentWidget()); - SubWindow* target_subwin = static_cast(newView->getInstrumentTrackWindow()->parentWidget()); - QWidget* source_widget; - QWidget* target_widget; + const auto sourceSubwin = static_cast(parentWidget()); + const auto targetSubwin = static_cast(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); diff --git a/src/gui/tracks/InstrumentTrackView.cpp b/src/gui/tracks/InstrumentTrackView.cpp index 40270db40..782b4e6a6 100644 --- a/src/gui/tracks/InstrumentTrackView.cpp +++ b/src/gui/tracks/InstrumentTrackView.cpp @@ -24,6 +24,8 @@ #include "InstrumentTrackView.h" +#include + #include #include #include @@ -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((**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(sw->widget())) + { + return itw; + } + } + + return nullptr; }