Qt deprecation fix (#5619)

Qt6 TODO: Orientation check by comparing angleDelta().x() and y() won't make sense
because the direction is arbitrary in Qt 6.
This commit is contained in:
Dat Ng
2020-09-13 04:09:46 +02:00
committed by GitHub
parent d29066fa83
commit 3d8b31039f
30 changed files with 255 additions and 145 deletions

View File

@@ -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

View File

@@ -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
@@ -55,8 +55,8 @@ protected:
private:
QTime m_stateTimer;
QTime m_releaseTimer;
QElapsedTimer m_stateTimer;
QElapsedTimer m_releaseTimer;
// the default color of the widget
QColor m_normalColor;
@@ -66,7 +66,7 @@ private:
QColor m_holdColor;
int activeNotes;
QColor fadeToColor(QColor, QColor, QTime, float);
QColor fadeToColor(QColor, QColor, QElapsedTimer, float);
} ;

View File

@@ -48,9 +48,10 @@
#ifndef FADER_H
#define FADER_H
#include <QtCore/QTime>
#include <QWidget>
#include <QElapsedTimer>
#include <QPixmap>
#include <QWidget>
#include "AutomatableModelView.h"
@@ -130,7 +131,7 @@ private:
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();
@@ -144,8 +145,8 @@ private:
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;

View File

@@ -46,8 +46,7 @@ public:
const QString &caption = QString(),
const QString &directory = QString(),
const QString &filter = QString(),
QString *selectedFilter = 0,
QFileDialog::Options options = 0);
QString *selectedFilter = 0);
void clearSelection();
};

View File

@@ -61,7 +61,7 @@ public:
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));
///

View File

@@ -21,7 +21,7 @@
#ifndef STEP_RECORDER_H
#define STEP_RECORDER_H
#include <QTime>
#include <QElapsedTimer>
#include <QTimer>
#include <QObject>
#include <QKeyEvent>
@@ -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)
@@ -140,4 +140,4 @@ class StepRecorder : public QObject
bool m_isStepInProgress = false;
};
#endif //STEP_RECORDER_H
#endif //STEP_RECORDER_H

View File

@@ -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;