Port to Qt 6

This commit is contained in:
Martchus 2022-12-20 18:16:22 +01:00 committed by Fabien Givors
parent ac4381a75a
commit eb00f18b0c
7 changed files with 48 additions and 32 deletions

View File

@ -71,8 +71,15 @@ if(NO_LANGS)
add_compile_options("-DNO_LANGS")
endif()
# Finds Qt5 libraries
FIND_PACKAGE( Qt5 REQUIRED COMPONENTS Core Gui Widgets LinguistTools OpenGL Xml )
# Finds Qt libraries
set(QT_PACKAGE_NAME Qt5 CACHE STRING "Name of the Qt package to use, set e.g. to \"Qt6\" to use Qt 6")
set(QT_COMPONENTS Core Gui Widgets LinguistTools OpenGL Xml)
set(QT_LIBS ${QT_PACKAGE_NAME}::Core ${QT_PACKAGE_NAME}::Gui ${QT_PACKAGE_NAME}::Widgets ${QT_PACKAGE_NAME}::Xml ${QT_PACKAGE_NAME}::OpenGL)
if (QT_PACKAGE_NAME STREQUAL Qt6)
list(APPEND QT_COMPONENTS OpenGLWidgets Core5Compat)
list(APPEND QT_LIBS ${QT_PACKAGE_NAME}::OpenGLWidgets ${QT_PACKAGE_NAME}::Core5Compat)
endif ()
FIND_PACKAGE( "${QT_PACKAGE_NAME}" REQUIRED COMPONENTS ${QT_COMPONENTS})
add_compile_options(-fPIC)
@ -256,14 +263,12 @@ if(WIN32)
SET_TARGET_PROPERTIES(pianobooster PROPERTIES LINK_FLAGS "-mwindows")
endif(WIN32)
qt5_use_modules(pianobooster Core Gui Widgets LinguistTools OpenGL Xml)
if(${CMAKE_VERSION} VERSION_LESS "3.13.0")
message("Please consider to switch to CMake 3.13.0")
else()
target_link_directories(pianobooster PUBLIC ${FTGL_LIBRARY_DIRS} ${JACK_LIBRARY_DIRS} ${FLUIDSYNTH_LIBRARY_DIRS})
endif()
target_link_libraries (pianobooster Qt5::Widgets Qt5::Xml Qt5::OpenGL ${OPENGL_LIBRARIES} ${FTGL_LIBRARY} ${RTMIDI_LIBRARIES} ${JACK_LIBRARY} ${FLUIDSYNTH_LIBRARY} ${RTMIDI_LIBRARY})
target_link_libraries (pianobooster ${QT_LIBS} ${OPENGL_LIBRARIES} ${FTGL_LIBRARY} ${RTMIDI_LIBRARIES} ${JACK_LIBRARY} ${FLUIDSYNTH_LIBRARY} ${RTMIDI_LIBRARY})
if(NOT APPLE)
INSTALL( FILES ../pianobooster.desktop DESTINATION share/applications )

View File

@ -547,7 +547,12 @@ static inline GLint qgluProject(GLdouble objx, GLdouble objy, GLdouble objz,
void CGLView::renderText(double x, double y, double z, const QString &str, const QFont & font = QFont()) {
#ifndef QT_OPENGL_ES
auto *const ctx = context();
auto *const gl1funcs = ctx->versionFunctions<QOpenGLFunctions_1_1>();
auto *const gl1funcs =
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_1_1>(ctx);
#else
ctx->versionFunctions<QOpenGLFunctions_1_1>();
#endif
if (!ctx->isOpenGLES() && gl1funcs) {
if (str.isEmpty() || !isValid())
return;

View File

@ -24,6 +24,7 @@
*/
#include <QFileInfo>
#include <QtWidgets>
#include "GuiMidiSetupDialog.h"
@ -298,10 +299,11 @@ void GuiMidiSetupDialog::on_fluidLoadButton_clicked ( bool checked )
}
}
QFileInfo soundFontInfo = QFileDialog::getOpenFileName(this, tr("Open SoundFont File for fluidsynth"),
const auto soundFontFile = QFileDialog::getOpenFileName(this, tr("Open SoundFont File for fluidsynth"),
lastSoundFont, tr("SoundFont Files (*.sf2 *.sf3)"));
if (!soundFontInfo.isFile()) return;
if (soundFontFile.isEmpty()) return;
const auto soundFontInfo = QFileInfo(soundFontFile);
m_settings->setFluidSoundFontNames(soundFontInfo.filePath());
m_settings->setValue("LastSoundFontDir", soundFontInfo.path());

View File

@ -29,6 +29,8 @@
#include <QJsonDocument>
#include <QJsonValue>
#include <QRegExp> // deprecated, from compat module in Qt 6
#include "GuiPreferencesDialog.h"
#include "GlView.h"

View File

@ -54,15 +54,7 @@ int main(int argc, char *argv[]){
}
QApplication app(argc, argv);
if (!QGLFormat::hasOpenGL()) {
QMessageBox::information(nullptr, QMessageBox::tr("OpenGL support"),
QMessageBox::tr("This system does not support OpenGL which is needed to run Piano Booster."));
return -1;
}
QtWindow window;
window.show();
int value = app.exec();

View File

@ -28,6 +28,7 @@
#include "QtWindow.h"
#include "version.h"
#include <QDebug>
#include <QSurfaceFormat>
#ifdef __linux__
@ -645,18 +646,11 @@ void QtWindow::open()
{
m_glWidget->stopTimerEvent();
QFileInfo currentSong = m_settings->getCurrentSongLongFileName();
QString dir;
if (currentSong.isFile())
dir = currentSong.path();
else
dir = QDir::homePath();
QString fileName = QFileDialog::getOpenFileName(this,tr("Open MIDI File"),
const auto currentSong = QFileInfo(m_settings->getCurrentSongLongFileName());
const auto dir = currentSong.isFile() ? currentSong.path() : QDir::homePath();
const auto fileName = QFileDialog::getOpenFileName(this,tr("Open MIDI File"),
dir, tr("MIDI Files") + " (*.mid *.MID *.midi *.MIDI *.kar *.KAR)");
if (!fileName.isEmpty()) {
m_settings->openSongFile(fileName);
setCurrentFile(fileName);
}
@ -730,7 +724,11 @@ void QtWindow::loadTutorHtml(const QString & name)
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return;
QTextStream out(&file);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
out.setEncoding(QStringConverter::Utf8);
#else
out.setCodec("UTF-8");
#endif
QString htmlStart = "<head><style> body{background-color:#FFFFC0;color: black} p{font-size: 18px;} blockquote{color: #ff0000;}</style></head><body>";
QString htmlBody = out.readAll();
@ -795,24 +793,31 @@ void QtWindow::refreshTranslate(){
ppLogInfo("Translations loaded from '%s'", qPrintable(translationsDir));
// set translator for app
auto ok = true;
if (!translator.load(QSTR_APPNAME + QString("_") + locale , translationsDir))
translator.load(QSTR_APPNAME + QString("_") + locale, QApplication::applicationDirPath());
ok = ok & translator.load(QSTR_APPNAME + QString("_") + locale, QApplication::applicationDirPath());
qApp->installTranslator(&translator);
// set translator for music
if (!translatorMusic.load(QString("music_") + locale , translationsDir))
if (!translatorMusic.load(QString("music_") + locale, QApplication::applicationDirPath() + "/translations/"))
translatorMusic.load(QString("music_") + locale, QApplication::applicationDirPath());
ok = ok & translatorMusic.load(QString("music_") + locale, QApplication::applicationDirPath());
qApp->installTranslator(&translatorMusic);
// set translator for default widget's text (for example: QMessageBox's buttons)
#ifdef __WIN32
qtTranslator.load("qt_"+locale, translationsDir);
ok = ok & qtTranslator.load("qt_"+locale, translationsDir);
#elif QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
ok = ok & qtTranslator.load("qt_"+locale, QLibraryInfo::path(QLibraryInfo::TranslationsPath));
#else
qtTranslator.load("qt_"+locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
ok = ok & qtTranslator.load("qt_"+locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
#endif
qApp->installTranslator(&qtTranslator);
if (!ok) {
qDebug() << "Unable to load all translations";
}
// retranslate UI
QList<QWidget*> l2 = this->findChildren<QWidget *>();
for (auto &w:l2){

View File

@ -26,9 +26,14 @@ endif()
get_filename_component(full_path_blank_ts ${CMAKE_CURRENT_SOURCE_DIR}/pianobooster_blank.ts ABSOLUTE)
list(REMOVE_ITEM TRANSLATIONS_FILES ${full_path_blank_ts})
FIND_PACKAGE(Qt5 REQUIRED COMPONENTS LinguistTools)
set(QT_PACKAGE_NAME Qt5 CACHE STRING "Name of the Qt package to use, set e.g. to \"Qt6\" to use Qt 6")
FIND_PACKAGE("${QT_PACKAGE_NAME}" REQUIRED COMPONENTS LinguistTools)
QT5_ADD_TRANSLATION(QM_FILES ${TRANSLATIONS_FILES})
if(COMMAND QT_ADD_TRANSLATION)
QT_ADD_TRANSLATION(QM_FILES ${TRANSLATIONS_FILES})
else()
QT5_ADD_TRANSLATION(QM_FILES ${TRANSLATIONS_FILES})
endif()
ADD_CUSTOM_TARGET(translations ALL DEPENDS ${QM_FILES})
IF (UNIX AND NOT APPLE)