Skip to content

Commit

Permalink
Qt deprecation fix (#5619)
Browse files Browse the repository at this point in the history
Qt6 TODO: Orientation check by comparing angleDelta().x() and y() won't make sense
because the direction is arbitrary in Qt 6.
  • Loading branch information
uthidata authored Sep 13, 2020
1 parent d29066f commit 3d8b310
Show file tree
Hide file tree
Showing 30 changed files with 253 additions and 143 deletions.
63 changes: 63 additions & 0 deletions include/DeprecationHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* DeprecationHelper.h - This file contains the declarations of helper functions
* which helps centralize the #ifdefs preprocessors regarding deprecation based on Qt versions.
* The functions are defined differently based on the callers' Qt versions.
*
* Copyright (c) 2020 Tien Dat Nguyen <ntd.bk.k56/at/gmail.com>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef DEPRECATIONHELPER_H
#define DEPRECATIONHELPER_H

#include <QFontMetrics>
#include <QWheelEvent>

/**
* @brief horizontalAdvance is a backwards-compatible adapter for
* QFontMetrics::horizontalAdvance and width functions.
* @param metrics
* @param text
* @return text's horizontal advance based on metrics.
*/
inline int horizontalAdvance(const QFontMetrics& metrics, const QString& text)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
return metrics.horizontalAdvance(text);
#else
return metrics.width(text);
#endif
}

/**
* @brief position is a backwards-compatible adapter for
* QWheelEvent::position and pos functions.
* @param wheelEvent
* @return the position of wheelEvent
*/
inline QPoint position(QWheelEvent *wheelEvent)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
return wheelEvent->position().toPoint();
#else
return wheelEvent->pos();
#endif
}
#endif // DEPRECATIONHELPER_H
8 changes: 4 additions & 4 deletions include/FadeButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#ifndef FADE_BUTTON_H
#define FADE_BUTTON_H

#include <QtCore/QTime>
#include <QAbstractButton>
#include <QColor>
#include <QElapsedTimer>


class FadeButton : public QAbstractButton
Expand All @@ -55,8 +55,8 @@ public slots:


private:
QTime m_stateTimer;
QTime m_releaseTimer;
QElapsedTimer m_stateTimer;
QElapsedTimer m_releaseTimer;

// the default color of the widget
QColor m_normalColor;
Expand All @@ -66,7 +66,7 @@ public slots:
QColor m_holdColor;
int activeNotes;

QColor fadeToColor(QColor, QColor, QTime, float);
QColor fadeToColor(QColor, QColor, QElapsedTimer, float);

} ;

Expand Down
11 changes: 6 additions & 5 deletions include/Fader.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
#ifndef FADER_H
#define FADER_H

#include <QtCore/QTime>
#include <QWidget>
#include <QElapsedTimer>
#include <QPixmap>
#include <QWidget>


#include "AutomatableModelView.h"

Expand Down Expand Up @@ -130,7 +131,7 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
return height() - ( ( height() - m_knob->height() ) * ( realVal / fRange ) );
}

void setPeak( float fPeak, float &targetPeak, float &persistentPeak, QTime &lastPeakTime );
void setPeak( float fPeak, float &targetPeak, float &persistentPeak, QElapsedTimer &lastPeakTimer );
int calculateDisplayPeak( float fPeak );

void updateTextFloat();
Expand All @@ -144,8 +145,8 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
float m_fMinPeak;
float m_fMaxPeak;

QTime m_lastPeakTime_L;
QTime m_lastPeakTime_R;
QElapsedTimer m_lastPeakTimer_L;
QElapsedTimer m_lastPeakTimer_R;

static QPixmap * s_back;
static QPixmap * s_leds;
Expand Down
3 changes: 1 addition & 2 deletions include/FileDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class LMMS_EXPORT FileDialog : public QFileDialog
const QString &caption = QString(),
const QString &directory = QString(),
const QString &filter = QString(),
QString *selectedFilter = 0,
QFileDialog::Options options = 0);
QString *selectedFilter = 0);
void clearSelection();
};

Expand Down
2 changes: 1 addition & 1 deletion include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MainWindow : public QMainWindow
void addSpacingToToolBar( int _size );

// wrap the widget with a window decoration and add it to the workspace
LMMS_EXPORT SubWindow* addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags=0);
LMMS_EXPORT SubWindow* addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags = QFlag(0));


///
Expand Down
6 changes: 3 additions & 3 deletions include/StepRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef STEP_RECORDER_H
#define STEP_RECORDER_H

#include <QTime>
#include <QElapsedTimer>
#include <QTimer>
#include <QObject>
#include <QKeyEvent>
Expand Down Expand Up @@ -130,7 +130,7 @@ class StepRecorder : public QObject

private:
bool m_pressed;
QTime releasedTimer;
QElapsedTimer releasedTimer;
} ;

QVector<StepNote*> m_curStepNotes; // contains the current recorded step notes (i.e. while user still press the notes; before they are applied to the pattern)
Expand All @@ -140,4 +140,4 @@ class StepRecorder : public QObject
bool m_isStepInProgress = false;
};

#endif //STEP_RECORDER_H
#endif //STEP_RECORDER_H
2 changes: 1 addition & 1 deletion include/SubWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LMMS_EXPORT SubWindow : public QMdiSubWindow
Q_PROPERTY( QColor borderColor READ borderColor WRITE setBorderColor )

public:
SubWindow( QWidget *parent = NULL, Qt::WindowFlags windowFlags = 0 );
SubWindow( QWidget *parent = NULL, Qt::WindowFlags windowFlags = QFlag(0) );
// same as QWidet::normalGeometry, but works properly under X11 (see https://bugreports.qt.io/browse/QTBUG-256)
QRect getTrueNormalGeometry() const;
QBrush activeColor() const;
Expand Down
2 changes: 1 addition & 1 deletion plugins/GigPlayer/PatchesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PatchesDialog : public QDialog, private Ui::PatchesDialog
public:

// Constructor.
PatchesDialog( QWidget * pParent = 0, Qt::WindowFlags wflags = 0 );
PatchesDialog(QWidget * pParent = 0, Qt::WindowFlags wflags = QFlag(0));

// Destructor.
virtual ~PatchesDialog();
Expand Down
2 changes: 1 addition & 1 deletion plugins/audio_file_processor/audio_file_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ void AudioFileProcessorWaveView::mouseMoveEvent( QMouseEvent * _me )

void AudioFileProcessorWaveView::wheelEvent( QWheelEvent * _we )
{
zoom( _we->delta() > 0 );
zoom( _we->angleDelta().y() > 0 );
update();
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/ladspa_browser/ladspa_port_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ladspaPortDialog::ladspaPortDialog( const ladspa_key_t & _key )
for( int col = 0; col < 7; ++col )
{
QTableWidgetItem * item = new QTableWidgetItem;
item->setFlags( 0 );
item->setFlags(QFlag(0));
settings->setItem( row, col, item );
}

Expand Down
9 changes: 8 additions & 1 deletion plugins/lb302/lb302.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,11 @@ QString lb302Synth::nodeName() const
// OBSOLETE. Break apart once we get Q_OBJECT to work. >:[
void lb302Synth::recalcFilter()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
vcf.loadRelaxed()->recalc();
#else
vcf.load()->recalc();

#endif
// THIS IS OLD 3pole/24dB code, I may reintegrate it. Don't need it
// right now. Should be toggled by LB_24_RES_TRICK at the moment.

Expand Down Expand Up @@ -683,7 +686,11 @@ void lb302Synth::initNote( lb302Note *n)

if(n->dead ==0){
// Swap next two blocks??
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
vcf.loadRelaxed()->playNote();
#else
vcf.load()->playNote();
#endif
// Ensure envelope is recalculated
vcf_envpos = ENVINC;

Expand Down
2 changes: 1 addition & 1 deletion plugins/sf2_player/patches_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class patchesDialog : public QDialog, private Ui::patchesDialog
public:

// Constructor.
patchesDialog(QWidget *pParent = 0, Qt::WindowFlags wflags = 0);
patchesDialog(QWidget *pParent = 0, Qt::WindowFlags wflags = QFlag(0));

// Destructor.
virtual ~patchesDialog();
Expand Down
5 changes: 5 additions & 0 deletions src/core/PluginFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ void PluginFactory::discoverPlugins()
QSet<QFileInfo> files;
for (const QString& searchPath : QDir::searchPaths("plugins"))
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
auto discoveredPluginList = QDir(searchPath).entryInfoList(nameFilters);
files.unite(QSet<QFileInfo>(discoveredPluginList.begin(), discoveredPluginList.end()));
#else
files.unite(QDir(searchPath).entryInfoList(nameFilters).toSet());
#endif
}

// Cheap dependency handling: zynaddsubfx needs ZynAddSubFxCore. By loading
Expand Down
4 changes: 4 additions & 0 deletions src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,11 @@ void Song::loadProject( const QString & fileName )
}
else
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,0))
QTextStream(stderr) << Engine::getSong()->errorSummary() << Qt::endl;
#else
QTextStream(stderr) << Engine::getSong()->errorSummary() << endl;
#endif
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/core/audio/AudioFileOgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

#ifdef LMMS_HAVE_OGGVORBIS


#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0))
#include <QRandomGenerator>
#endif
#include <string>
#include <vorbis/vorbisenc.h>

Expand Down Expand Up @@ -136,8 +138,13 @@ bool AudioFileOgg::startEncoding()

// We give our ogg file a random serial number and avoid
// 0 and UINT32_MAX which can get you into trouble.
qsrand( time( 0 ) );
#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0))
QRandomGenerator::global()->seed(time(0));
m_serialNo = 0xD0000000 + QRandomGenerator::global()->generate() % 0x0FFFFFFF;
#else
qsrand(time(0));
m_serialNo = 0xD0000000 + qrand() % 0x0FFFFFFF;
#endif
ogg_stream_init( &m_os, m_serialNo );

// Now, build the three header packets and send through to the stream
Expand Down
6 changes: 3 additions & 3 deletions src/gui/SetupDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ void SetupDialog::openGIGDir()
{
QString new_dir = FileDialog::getExistingDirectory(this,
tr("Choose your GIG directory"), m_gigDir);
if(new_dir != QString::null)
if(!new_dir.isEmpty())
{
m_gigDirLineEdit->setText(new_dir);
}
Expand All @@ -1320,7 +1320,7 @@ void SetupDialog::openThemeDir()
{
QString new_dir = FileDialog::getExistingDirectory(this,
tr("Choose your theme directory"), m_themeDir);
if(new_dir != QString::null)
if(!new_dir.isEmpty())
{
m_themeDirLineEdit->setText(new_dir);
}
Expand Down Expand Up @@ -1355,7 +1355,7 @@ void SetupDialog::openBackgroundPicFile()
QString new_file = FileDialog::getOpenFileName(this,
tr("Choose your background picture"), dir, "Picture files (" + fileTypes + ")");

if(new_file != QString::null)
if(!new_file.isEmpty())
{
m_backgroundPicFileLineEdit->setText(new_file);
}
Expand Down
4 changes: 1 addition & 3 deletions src/gui/dialogs/FileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ QString FileDialog::getOpenFileName(QWidget *parent,
const QString &caption,
const QString &directory,
const QString &filter,
QString *selectedFilter,
QFileDialog::Options options)
QString *selectedFilter)
{
FileDialog dialog(parent, caption, directory, filter);
dialog.setOptions(dialog.options() | options);
if (selectedFilter && !selectedFilter->isEmpty())
dialog.selectNameFilter(*selectedFilter);
if (dialog.exec() == QDialog::Accepted) {
Expand Down
5 changes: 3 additions & 2 deletions src/gui/dialogs/VersionedSaveDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QGroupBox>
#include <QLabel>

#include "DeprecationHelper.h"
#include "VersionedSaveDialog.h"
#include "LedCheckbox.h"

Expand All @@ -50,8 +51,8 @@ VersionedSaveDialog::VersionedSaveDialog( QWidget *parent,
plusButton->setToolTip( tr( "Increment version number" ) );
QPushButton *minusButton( new QPushButton( "-", this ) );
minusButton->setToolTip( tr( "Decrement version number" ) );
plusButton->setFixedWidth( plusButton->fontMetrics().width( "+" ) + 30 );
minusButton->setFixedWidth( minusButton->fontMetrics().width( "+" ) + 30 );
plusButton->setFixedWidth(horizontalAdvance(plusButton->fontMetrics(), "+") + 30);
minusButton->setFixedWidth(horizontalAdvance(minusButton->fontMetrics(), "+") + 30);

// Add buttons to grid layout. For doing this, remove the lineEdit and
// replace it with a HBox containing lineEdit and the buttons.
Expand Down
Loading

0 comments on commit 3d8b310

Please sign in to comment.