Skip to content

Commit

Permalink
Make the minimum code compile for Qt6
Browse files Browse the repository at this point in the history
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<panning_t>` instead of `qBound<int>` 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!
  • Loading branch information
michaelgregorius committed Apr 11, 2024
1 parent 1d6a892 commit bb4d04b
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 49 deletions.
3 changes: 1 addition & 2 deletions include/ColorChooser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/ControlLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private slots:
private:
int doLayout(const QRect &rect, bool testOnly) const;
int smartSpacing(QStyle::PixelMetric pm) const;
QMap<QString, QLayoutItem *>::const_iterator pairAt(int index) const;
QMultiMap<QString, QLayoutItem *>::const_iterator pairAt(int index) const;

QMultiMap<QString, QLayoutItem *> m_itemMap;
int m_hSpace;
Expand Down
2 changes: 1 addition & 1 deletion include/FloatModelEditorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/PluginBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/core/MixHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#endif

#include <cmath>
#include <algorithm>

#include <QtGlobal>

#include "ValueBuffer.h"
Expand Down
6 changes: 3 additions & 3 deletions src/gui/ControlLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int ControlLayout::count() const
return m_itemMap.size() - 1;
}

QMap<QString, QLayoutItem*>::const_iterator
QMultiMap<QString, QLayoutItem*>::const_iterator
ControlLayout::pairAt(int index) const
{
if (index < 0) { return m_itemMap.cend(); }
Expand All @@ -151,7 +151,7 @@ ControlLayout::pairAt(int index) const
return item->widget()->objectName() == s_searchBarName;
};

QMap<QString, QLayoutItem*>::const_iterator itr = m_itemMap.cbegin();
QMultiMap<QString, QLayoutItem*>::const_iterator itr = m_itemMap.cbegin();
for (; itr != m_itemMap.cend() && (index > 0 || skip(itr.value())); ++itr)
{
if(!skip(itr.value())) { index--; }
Expand Down Expand Up @@ -242,7 +242,7 @@ int ControlLayout::doLayout(const QRect &rect, bool testOnly) const
const QString filterText = m_searchBar->text();
bool first = true;

QMapIterator<QString, QLayoutItem*> itr(m_itemMap);
QMultiMapIterator<QString, QLayoutItem*> itr(m_itemMap);
while (itr.hasNext())
{
itr.next();
Expand Down
34 changes: 17 additions & 17 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" ),
Expand All @@ -311,26 +311,26 @@ 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))
project_menu->addSeparator();
#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" ) );
Expand All @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/PluginBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void PluginDescWidget::paintEvent( QPaintEvent * )



void PluginDescWidget::enterEvent( QEvent * _e )
void PluginDescWidget::enterEvent( QEnterEvent * _e )
{
m_mouseOver = true;

Expand Down
1 change: 1 addition & 0 deletions src/gui/ProjectNotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ProjectNotes.h"

#include <QAction>
#include <QActionGroup>
#include <QApplication>
#include <QCloseEvent>
#include <QColorDialog>
Expand Down
2 changes: 1 addition & 1 deletion src/gui/clips/ClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
}

Expand Down
8 changes: 4 additions & 4 deletions src/gui/editors/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 15 additions & 15 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2454,11 +2454,11 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me )
( (float)( noteEditBottom() - noteEditTop() ) ) *
( MaxVolume - MinVolume ),
MaxVolume );
pan = qBound<int>( PanningLeft,
PanningLeft +
pan = qBound<panning_t>( PanningLeft,
static_cast<panning_t>(PanningLeft +
( (float)( noteEditBottom() - me->y() ) ) /
( (float)( noteEditBottom() - noteEditTop() ) ) *
( (float)( PanningRight - PanningLeft ) ),
( (float)( PanningRight - PanningLeft ) )),
PanningRight);
}

Expand Down Expand Up @@ -3788,7 +3788,7 @@ void PianoRoll::wheelEvent(QWheelEvent * we )
{
for ( Note * n : nv )
{
panning_t pan = qBound<int>( PanningLeft, n->getPanning() + step, PanningRight );
panning_t pan = qBound<panning_t>( PanningLeft, n->getPanning() + static_cast<panning_t>(step), PanningRight );
n->setPanning( pan );
}
bool allPansEqual = std::all_of( nv.begin(), nv.end(),
Expand Down Expand Up @@ -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)));

Expand Down Expand Up @@ -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()));
Expand All @@ -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); });
Expand Down
2 changes: 1 addition & 1 deletion src/gui/embed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/FloatModelEditorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void FloatModelEditorBase::mouseReleaseEvent(QMouseEvent* event)
}


void FloatModelEditorBase::enterEvent(QEvent *event)
void FloatModelEditorBase::enterEvent(QEnterEvent *event)
{
showTextFloat(700, 2000);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/SimpleTextFloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bb4d04b

Please sign in to comment.