From bb4d04b5e71bf16ce81d5e22ae3aa3580e222eae Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Thu, 11 Apr 2024 19:47:34 +0200 Subject: [PATCH] Make the minimum code compile for Qt6 The following changes are applied to make the minimum build configuration compile: * Remove usage of a `QKeyEvent` constructor in `ColorChooser.h` by directly forwarding the original event. * Change `QMap` to `QMulitMap` in several places in `ControlLayout.h` because that's what in fact is used. * Change the parameter from `QEvent` to `QEnterEvent` in some `enterEvent` overrides. * Add an include for `algorithm` in `MixHelpers.cpp` * Fix a problem with string argument replacement in `embed.cpp` * Introduce the usage of `QKeySequence` including the replacement of the `+` operator with the `|` operator. * Add an include for `QActionGroup` in `ProjectNotes.cpp`. * Use `QPalette::window` instead of `QPalette::background` in `ClipView.cpp` * Use `qBound` instead of `qBound` in `PianoRoll.cpp`. Add a cast. * Replace the deprecated call to `QLayout::setMargin` with `QLayout::setContentsMargins` Note: there are still lots of warnings when you compile this state with Qt6! --- include/ColorChooser.h | 3 +-- include/ControlLayout.h | 2 +- include/FloatModelEditorBase.h | 2 +- include/PluginBrowser.h | 2 +- src/core/MixHelpers.cpp | 2 ++ src/gui/ControlLayout.cpp | 6 ++--- src/gui/MainWindow.cpp | 34 ++++++++++++------------ src/gui/PluginBrowser.cpp | 2 +- src/gui/ProjectNotes.cpp | 1 + src/gui/clips/ClipView.cpp | 2 +- src/gui/editors/AutomationEditor.cpp | 8 +++--- src/gui/editors/PianoRoll.cpp | 30 ++++++++++----------- src/gui/embed.cpp | 2 +- src/gui/widgets/FloatModelEditorBase.cpp | 2 +- src/gui/widgets/SimpleTextFloat.cpp | 2 +- 15 files changed, 51 insertions(+), 49 deletions(-) diff --git a/include/ColorChooser.h b/include/ColorChooser.h index 0e85ea9bb8b..67b2abc364d 100644 --- a/include/ColorChooser.h +++ b/include/ColorChooser.h @@ -55,8 +55,7 @@ class ColorChooser : public QColorDialog //! Forward key events to the parent to prevent stuck notes when the dialog gets focus void keyReleaseEvent(QKeyEvent *event) override { - QKeyEvent ke(*event); - QApplication::sendEvent(parentWidget(), &ke); + QApplication::sendEvent(parentWidget(), event); } private: //! Copy the current QColorDialog palette into an array diff --git a/include/ControlLayout.h b/include/ControlLayout.h index 568ce1a854d..1ed919d06cb 100644 --- a/include/ControlLayout.h +++ b/include/ControlLayout.h @@ -126,7 +126,7 @@ private slots: private: int doLayout(const QRect &rect, bool testOnly) const; int smartSpacing(QStyle::PixelMetric pm) const; - QMap::const_iterator pairAt(int index) const; + QMultiMap::const_iterator pairAt(int index) const; QMultiMap m_itemMap; int m_hSpace; diff --git a/include/FloatModelEditorBase.h b/include/FloatModelEditorBase.h index 72f1450de5a..aeaaab37095 100644 --- a/include/FloatModelEditorBase.h +++ b/include/FloatModelEditorBase.h @@ -81,7 +81,7 @@ class LMMS_EXPORT FloatModelEditorBase : public QWidget, public FloatModelView void paintEvent(QPaintEvent * me) override; void wheelEvent(QWheelEvent * me) override; - void enterEvent(QEvent *event) override; + void enterEvent(QEnterEvent *event) override; void leaveEvent(QEvent *event) override; virtual float getValue(const QPoint & p); diff --git a/include/PluginBrowser.h b/include/PluginBrowser.h index 2bb1b6d5ccf..153a903b033 100644 --- a/include/PluginBrowser.h +++ b/include/PluginBrowser.h @@ -66,7 +66,7 @@ class PluginDescWidget : public QWidget void openInNewInstrumentTrack(QString value); protected: - void enterEvent( QEvent * _e ) override; + void enterEvent( QEnterEvent * _e ) override; void leaveEvent( QEvent * _e ) override; void mousePressEvent( QMouseEvent * _me ) override; void paintEvent( QPaintEvent * _pe ) override; diff --git a/src/core/MixHelpers.cpp b/src/core/MixHelpers.cpp index 209640b70b2..c589835c6e1 100644 --- a/src/core/MixHelpers.cpp +++ b/src/core/MixHelpers.cpp @@ -29,6 +29,8 @@ #endif #include +#include + #include #include "ValueBuffer.h" diff --git a/src/gui/ControlLayout.cpp b/src/gui/ControlLayout.cpp index 75133c8e3d8..a4b67d76e9e 100644 --- a/src/gui/ControlLayout.cpp +++ b/src/gui/ControlLayout.cpp @@ -141,7 +141,7 @@ int ControlLayout::count() const return m_itemMap.size() - 1; } -QMap::const_iterator +QMultiMap::const_iterator ControlLayout::pairAt(int index) const { if (index < 0) { return m_itemMap.cend(); } @@ -151,7 +151,7 @@ ControlLayout::pairAt(int index) const return item->widget()->objectName() == s_searchBarName; }; - QMap::const_iterator itr = m_itemMap.cbegin(); + QMultiMap::const_iterator itr = m_itemMap.cbegin(); for (; itr != m_itemMap.cend() && (index > 0 || skip(itr.value())); ++itr) { if(!skip(itr.value())) { index--; } @@ -242,7 +242,7 @@ int ControlLayout::doLayout(const QRect &rect, bool testOnly) const const QString filterText = m_searchBar->text(); bool first = true; - QMapIterator itr(m_itemMap); + QMultiMapIterator itr(m_itemMap); while (itr.hasNext()) { itr.next(); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 072edc0ec22..9aec22ad381 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -292,11 +292,11 @@ void MainWindow::finalize() project_menu->addAction( embed::getIconPixmap( "project_save" ), tr( "Save &As..." ), this, SLOT(saveProjectAs()), - Qt::CTRL + Qt::SHIFT + Qt::Key_S ); + QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_S)); project_menu->addAction( embed::getIconPixmap( "project_save" ), tr( "Save as New &Version" ), this, SLOT(saveProjectAsNewVersion()), - Qt::CTRL + Qt::ALT + Qt::Key_S ); + QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_S)); project_menu->addAction( embed::getIconPixmap( "project_save" ), tr( "Save as default template" ), @@ -311,18 +311,18 @@ void MainWindow::finalize() tr( "E&xport..." ), this, SLOT(onExportProject()), - Qt::CTRL + Qt::Key_E ); + QKeySequence(Qt::CTRL | Qt::Key_E)); project_menu->addAction( embed::getIconPixmap( "project_export" ), tr( "E&xport Tracks..." ), this, SLOT(onExportProjectTracks()), - Qt::CTRL + Qt::SHIFT + Qt::Key_E ); + QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_E)); project_menu->addAction( embed::getIconPixmap( "midi_file" ), tr( "Export &MIDI..." ), this, SLOT(onExportProjectMidi()), - Qt::CTRL + Qt::Key_M ); + QKeySequence(Qt::CTRL | Qt::Key_M)); // Prevent dangling separator at end of menu per https://bugreports.qt.io/browse/QTBUG-40071 #if !(defined(LMMS_BUILD_APPLE) && (QT_VERSION < 0x050600)) @@ -330,7 +330,7 @@ void MainWindow::finalize() #endif project_menu->addAction( embed::getIconPixmap( "exit" ), tr( "&Quit" ), qApp, SLOT(closeAllWindows()), - Qt::CTRL + Qt::Key_Q ); + QKeySequence(Qt::CTRL | Qt::Key_Q)); auto edit_menu = new QMenu(this); menuBar()->addMenu( edit_menu )->setText( tr( "&Edit" ) ); @@ -343,13 +343,13 @@ void MainWindow::finalize() this, SLOT(redo()), QKeySequence::Redo ); // Ensure that both (Ctrl+Y) and (Ctrl+Shift+Z) activate redo shortcut regardless of OS defaults - if (QKeySequence(QKeySequence::Redo) != QKeySequence(Qt::CTRL + Qt::Key_Y)) + if (QKeySequence(QKeySequence::Redo) != QKeySequence(Qt::CTRL | Qt::Key_Y)) { - new QShortcut( QKeySequence( Qt::CTRL + Qt::Key_Y ), this, SLOT(redo())); + new QShortcut( QKeySequence( Qt::CTRL | Qt::Key_Y ), this, SLOT(redo())); } - if (QKeySequence(QKeySequence::Redo) != QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z )) + if (QKeySequence(QKeySequence::Redo) != QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Z )) { - new QShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_Z ), this, SLOT(redo())); + new QShortcut( QKeySequence( Qt::CTRL | Qt::SHIFT | Qt::Key_Z ), this, SLOT(redo())); } edit_menu->addSeparator(); @@ -451,31 +451,31 @@ void MainWindow::finalize() // window-toolbar auto song_editor_window = new ToolButton(embed::getIconPixmap("songeditor"), tr("Song Editor") + " (Ctrl+1)", this, SLOT(toggleSongEditorWin()), m_toolBar); - song_editor_window->setShortcut( Qt::CTRL + Qt::Key_1 ); + song_editor_window->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_1)); auto pattern_editor_window = new ToolButton(embed::getIconPixmap("pattern_track_btn"), tr("Pattern Editor") + " (Ctrl+2)", this, SLOT(togglePatternEditorWin()), m_toolBar); - pattern_editor_window->setShortcut(Qt::CTRL + Qt::Key_2); + pattern_editor_window->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_2)); auto piano_roll_window = new ToolButton( embed::getIconPixmap("piano"), tr("Piano Roll") + " (Ctrl+3)", this, SLOT(togglePianoRollWin()), m_toolBar); - piano_roll_window->setShortcut( Qt::CTRL + Qt::Key_3 ); + piano_roll_window->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_3)); auto automation_editor_window = new ToolButton(embed::getIconPixmap("automation"), tr("Automation Editor") + " (Ctrl+4)", this, SLOT(toggleAutomationEditorWin()), m_toolBar); - automation_editor_window->setShortcut( Qt::CTRL + Qt::Key_4 ); + automation_editor_window->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_4)); auto mixer_window = new ToolButton( embed::getIconPixmap("mixer"), tr("Mixer") + " (Ctrl+5)", this, SLOT(toggleMixerWin()), m_toolBar); - mixer_window->setShortcut( Qt::CTRL + Qt::Key_5 ); + mixer_window->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_5)); auto controllers_window = new ToolButton(embed::getIconPixmap("controller"), tr("Show/hide controller rack") + " (Ctrl+6)", this, SLOT(toggleControllerRack()), m_toolBar); - controllers_window->setShortcut( Qt::CTRL + Qt::Key_6 ); + controllers_window->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_6)); auto project_notes_window = new ToolButton(embed::getIconPixmap("project_notes"), tr("Show/hide project notes") + " (Ctrl+7)", this, SLOT(toggleProjectNotesWin()), m_toolBar); - project_notes_window->setShortcut( Qt::CTRL + Qt::Key_7 ); + project_notes_window->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_7)); m_toolBarLayout->addWidget( song_editor_window, 1, 1 ); m_toolBarLayout->addWidget( pattern_editor_window, 1, 2 ); diff --git a/src/gui/PluginBrowser.cpp b/src/gui/PluginBrowser.cpp index 963609c431c..a2bd597ab1d 100644 --- a/src/gui/PluginBrowser.cpp +++ b/src/gui/PluginBrowser.cpp @@ -260,7 +260,7 @@ void PluginDescWidget::paintEvent( QPaintEvent * ) -void PluginDescWidget::enterEvent( QEvent * _e ) +void PluginDescWidget::enterEvent( QEnterEvent * _e ) { m_mouseOver = true; diff --git a/src/gui/ProjectNotes.cpp b/src/gui/ProjectNotes.cpp index a71f146c66e..18dc3d8f4fa 100644 --- a/src/gui/ProjectNotes.cpp +++ b/src/gui/ProjectNotes.cpp @@ -26,6 +26,7 @@ #include "ProjectNotes.h" #include +#include #include #include #include diff --git a/src/gui/clips/ClipView.cpp b/src/gui/clips/ClipView.cpp index 5c8a12b91e3..a0f7f7c53c6 100644 --- a/src/gui/clips/ClipView.cpp +++ b/src/gui/clips/ClipView.cpp @@ -356,7 +356,7 @@ void ClipView::selectColor() // Get a color from the user const auto newColor = ColorChooser{this} .withPalette(ColorChooser::Palette::Track) - ->getColor(m_clip->color().value_or(palette().background().color())); + ->getColor(m_clip->color().value_or(palette().window().color())); if (newColor.isValid()) { setColor(newColor); } } diff --git a/src/gui/editors/AutomationEditor.cpp b/src/gui/editors/AutomationEditor.cpp index 46521b3f02b..eae6d8b7da3 100644 --- a/src/gui/editors/AutomationEditor.cpp +++ b/src/gui/editors/AutomationEditor.cpp @@ -2035,17 +2035,17 @@ AutomationEditorWindow::AutomationEditorWindow() : auto editModeGroup = new ActionGroup(this); m_drawAction = editModeGroup->addAction(embed::getIconPixmap("edit_draw"), tr("Draw mode (Shift+D)")); - m_drawAction->setShortcut(Qt::SHIFT | Qt::Key_D); + m_drawAction->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_D)); m_drawAction->setChecked(true); m_eraseAction = editModeGroup->addAction(embed::getIconPixmap("edit_erase"), tr("Erase mode (Shift+E)")); - m_eraseAction->setShortcut(Qt::SHIFT | Qt::Key_E); + m_eraseAction->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_E)); m_drawOutAction = editModeGroup->addAction(embed::getIconPixmap("edit_draw_outvalue"), tr("Draw outValues mode (Shift+C)")); - m_drawOutAction->setShortcut(Qt::SHIFT | Qt::Key_C); + m_drawOutAction->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_C)); m_editTanAction = editModeGroup->addAction(embed::getIconPixmap("edit_tangent"), tr("Edit tangents mode (Shift+T)")); - m_editTanAction->setShortcut(Qt::SHIFT | Qt::Key_T); + m_editTanAction->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_T)); m_editTanAction->setEnabled(false); m_flipYAction = new QAction(embed::getIconPixmap("flip_y"), tr("Flip vertically"), this); diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 3b9273ade7d..e52cd7bced8 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -2454,11 +2454,11 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me ) ( (float)( noteEditBottom() - noteEditTop() ) ) * ( MaxVolume - MinVolume ), MaxVolume ); - pan = qBound( PanningLeft, - PanningLeft + + pan = qBound( PanningLeft, + static_cast(PanningLeft + ( (float)( noteEditBottom() - me->y() ) ) / ( (float)( noteEditBottom() - noteEditTop() ) ) * - ( (float)( PanningRight - PanningLeft ) ), + ( (float)( PanningRight - PanningLeft ) )), PanningRight); } @@ -3788,7 +3788,7 @@ void PianoRoll::wheelEvent(QWheelEvent * we ) { for ( Note * n : nv ) { - panning_t pan = qBound( PanningLeft, n->getPanning() + step, PanningRight ); + panning_t pan = qBound( PanningLeft, n->getPanning() + static_cast(step), PanningRight ); n->setPanning( pan ); } bool allPansEqual = std::all_of( nv.begin(), nv.end(), @@ -4738,10 +4738,10 @@ PianoRollWindow::PianoRollWindow() : drawAction->setChecked( true ); - drawAction->setShortcut( Qt::SHIFT | Qt::Key_D ); - eraseAction->setShortcut( Qt::SHIFT | Qt::Key_E ); - selectAction->setShortcut( Qt::SHIFT | Qt::Key_S ); - pitchBendAction->setShortcut( Qt::SHIFT | Qt::Key_T ); + drawAction->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_D )); + eraseAction->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_E)); + selectAction->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_S)); + pitchBendAction->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_T)); connect( editModeGroup, SIGNAL(triggered(int)), m_editor, SLOT(setEditMode(int))); @@ -4800,9 +4800,9 @@ PianoRollWindow::PianoRollWindow() : auto pasteAction = new QAction(embed::getIconPixmap("edit_paste"), tr("Paste (%1+V)").arg(UI_CTRL_KEY), this); - cutAction->setShortcut( Qt::CTRL | Qt::Key_X ); - copyAction->setShortcut( Qt::CTRL | Qt::Key_C ); - pasteAction->setShortcut( Qt::CTRL | Qt::Key_V ); + cutAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_X)); + copyAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_C)); + pasteAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_V)); connect( cutAction, SIGNAL(triggered()), m_editor, SLOT(cutSelectedNotes())); connect( copyAction, SIGNAL(triggered()), m_editor, SLOT(copySelectedNotes())); @@ -4823,19 +4823,19 @@ PianoRollWindow::PianoRollWindow() : auto glueAction = new QAction(embed::getIconPixmap("glue"), tr("Glue"), noteToolsButton); connect(glueAction, SIGNAL(triggered()), m_editor, SLOT(glueNotes())); - glueAction->setShortcut( Qt::SHIFT | Qt::Key_G ); + glueAction->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_G)); auto knifeAction = new QAction(embed::getIconPixmap("edit_knife"), tr("Knife"), noteToolsButton); connect(knifeAction, &QAction::triggered, m_editor, &PianoRoll::setKnifeAction); - knifeAction->setShortcut( Qt::SHIFT | Qt::Key_K ); + knifeAction->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_K)); auto fillAction = new QAction(embed::getIconPixmap("fill"), tr("Fill"), noteToolsButton); connect(fillAction, &QAction::triggered, [this](){ m_editor->fitNoteLengths(true); }); - fillAction->setShortcut(Qt::SHIFT | Qt::Key_F); + fillAction->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_F)); auto cutOverlapsAction = new QAction(embed::getIconPixmap("cut_overlaps"), tr("Cut overlaps"), noteToolsButton); connect(cutOverlapsAction, &QAction::triggered, [this](){ m_editor->fitNoteLengths(false); }); - cutOverlapsAction->setShortcut(Qt::SHIFT | Qt::Key_C); + cutOverlapsAction->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_C)); auto minLengthAction = new QAction(embed::getIconPixmap("min_length"), tr("Min length as last"), noteToolsButton); connect(minLengthAction, &QAction::triggered, [this](){ m_editor->constrainNoteLengths(false); }); diff --git a/src/gui/embed.cpp b/src/gui/embed.cpp index d934adcde64..a57d9e7c856 100644 --- a/src/gui/embed.cpp +++ b/src/gui/embed.cpp @@ -37,7 +37,7 @@ QPixmap getIconPixmap(const QString& pixmapName, QString cacheName; if (width > 0 && height > 0) { - cacheName = QString("%1_%2_%3").arg(pixmapName, width, height); + cacheName = QString("%1_%2_%3").arg(pixmapName).arg(width).arg(height); } else { diff --git a/src/gui/widgets/FloatModelEditorBase.cpp b/src/gui/widgets/FloatModelEditorBase.cpp index dd6be89583e..c85ec3430af 100644 --- a/src/gui/widgets/FloatModelEditorBase.cpp +++ b/src/gui/widgets/FloatModelEditorBase.cpp @@ -233,7 +233,7 @@ void FloatModelEditorBase::mouseReleaseEvent(QMouseEvent* event) } -void FloatModelEditorBase::enterEvent(QEvent *event) +void FloatModelEditorBase::enterEvent(QEnterEvent *event) { showTextFloat(700, 2000); } diff --git a/src/gui/widgets/SimpleTextFloat.cpp b/src/gui/widgets/SimpleTextFloat.cpp index e37753229ac..870869fe919 100644 --- a/src/gui/widgets/SimpleTextFloat.cpp +++ b/src/gui/widgets/SimpleTextFloat.cpp @@ -40,7 +40,7 @@ SimpleTextFloat::SimpleTextFloat() : QWidget(getGUI()->mainWindow(), Qt::ToolTip) { QHBoxLayout * layout = new QHBoxLayout(this); - layout->setMargin(3); + layout->setContentsMargins(3, 3, 3, 3); setLayout(layout); m_textLabel = new QLabel(this);