Skip to content

Commit

Permalink
(Qt) Backward compatibility with Qt5
Browse files Browse the repository at this point in the history
  • Loading branch information
viachaslavic committed Nov 8, 2024
1 parent aaa4104 commit 5528517
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 11 deletions.
10 changes: 9 additions & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ifeq ($(HAVE_NOUNUSED_VARIABLE), 1)
DEF_FLAGS += $(NOUNUSED_VARIABLE_CFLAGS)
endif

ifeq ($(HAVE_CXX17), 1)
ifeq ($(HAVE_QT6), 1)
CXXFLAGS += $(CXX17_CFLAGS)
else ifeq ($(HAVE_CXX11), 1)
CXXFLAGS += $(CXX11_CFLAGS)
Expand Down Expand Up @@ -533,10 +533,18 @@ ifeq ($(HAVE_QT), 1)
endif

DEFINES += -DHAVE_MAIN
ifeq ($(HAVE_QT6), 1)
CXXFLAGS += -DQT_DISABLE_DEPRECATED_BEFORE=0x060000 $(QT6CORE_CFLAGS) $(QT6GUI_CFLAGS) $(QT6WIDGETS_CFLAGS) $(QT6CONCURRENT_CFLAGS) $(QT6NETWORK_CFLAGS)
#DEF_FLAGS += $(QT6WEBENGINE_CFLAGS)
LIBS += $(QT6CORE_LIBS) $(QT6GUI_LIBS) $(QT6WIDGETS_LIBS) $(QT6CONCURRENT_LIBS) $(QT6NETWORK_LIBS)
#LIBS += $(QT6WEBENGINE_LIBS)
else
DEF_FLAGS += $(QT5CORE_CFLAGS) $(QT5GUI_CFLAGS) $(QT5WIDGETS_CFLAGS) $(QT5CONCURRENT_CFLAGS) $(QT5NETWORK_CFLAGS)
#DEF_FLAGS += $(QT5WEBENGINE_CFLAGS)
LIBS += $(QT5CORE_LIBS) $(QT5GUI_LIBS) $(QT5WIDGETS_LIBS) $(QT5CONCURRENT_LIBS) $(QT5NETWORK_LIBS)
#LIBS += $(QT5WEBENGINE_LIBS)
endif

NEED_CXX_LINKER = 1

ifneq ($(findstring Linux,$(OS)),)
Expand Down
30 changes: 26 additions & 4 deletions qb/config.libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,35 @@ if [ "$HAVE_QT" != 'no' ]; then

if [ "$HAVE_QT" != yes ]; then
die : 'Notice: Qt support disabled, required libraries were not found.'
else
HAVE_QT6='yes'
add_define MAKEFILE HAVE_QT6 1
fi
fi
if [ "$HAVE_QT6" != 'yes' ]; then
HAVE_QT='auto'
check_pkgconf QT5CORE Qt5Core 5.2
check_pkgconf QT5GUI Qt5Gui 5.2
check_pkgconf QT5WIDGETS Qt5Widgets 5.2
check_pkgconf QT5CONCURRENT Qt5Concurrent 5.2
check_pkgconf QT5NETWORK Qt5Network 5.2
#check_pkgconf QT5WEBENGINE Qt6WebEngine 5.2

# pkg-config is needed to reliably find Qt5 libraries.

check_enabled QT5CORE QT Qt 'Qt5Core is' true
check_enabled QT5GUI QT Qt 'Qt5GUI is' true
check_enabled QT5WIDGETS QT Qt 'Qt5Widgets is' true
check_enabled QT5CONCURRENT QT Qt 'Qt5Concurrent is' true
check_enabled QT5NETWORK QT Qt 'Qt5Network is' true
#check_enabled QT5WEBENGINE QT Qt 'Qt5Webengine is' true

check_pkgconf OPENSSL openssl 1.0.0
else
HAVE_QT='no'
die : 'Notice: Qt support disabled, required compiler was not found.'
if [ "$HAVE_QT" != yes ]; then
die : 'Notice: Qt support disabled, required libraries were not found.'
fi
fi

check_pkgconf OPENSSL openssl 1.0.0
fi

check_enabled FLAC BUILTINFLAC 'builtin flac' 'flac is' true
Expand Down
4 changes: 2 additions & 2 deletions qb/config.moc.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QT_VERSION=qt6
QT_FLAGS="$CXX17_CFLAGS $QT6CORE_CFLAGS $QT6CORE_LIBS"
[ "$HAVE_QT6" = "yes" ] && QT_VERSION=qt6 || QT_VERSION=qt5
[ "$HAVE_QT6" = "yes" ] && QT_FLAGS="$CXX17_CFLAGS $QT6CORE_CFLAGS $QT6CORE_LIBS" || QT_FLAGS="$CXX11_CFLAGS $QT5CORE_CFLAGS $QT5CORE_LIBS"

add_define MAKEFILE QT_VERSION "$QT_VERSION"
8 changes: 5 additions & 3 deletions qb/qb.moc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ if [ "$HAVE_QT" = "yes" ]; then
>/dev/null 2>&1 &&
moc_works=1
else
for moc in "moc-$QT_VERSION" moc; do
if [ "$QT_VERSION" = "qt6" ]; then
QMAKE="$(exists qmake6)" || QMAKE="qmake"
QT_HOST_LIBEXECS="$($QMAKE -query QT_HOST_LIBEXECS)"
MOC="$(exists "$QT_HOST_LIBEXECS/$moc")" || MOC=""
$QMAKE -query QT_HOST_LIBEXECS && QT_HOST_LIBEXECS="$($QMAKE -query QT_HOST_LIBEXECS)/"
fi
for moc in "${QT_HOST_LIBEXECS}moc-$QT_VERSION" "${QT_HOST_LIBEXECS}moc"; do
MOC="$(exists "$moc")" || MOC=""
if [ "$MOC" ]; then
QT_SELECT="$QT_VERSION" \
"$MOC" -o "$TEMP_CPP" "$TEMP_MOC" >/dev/null 2>&1 ||
Expand Down
4 changes: 4 additions & 0 deletions ui/drivers/qt/gridview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,12 @@ void GridView::paintEvent(QPaintEvent*)
{
QModelIndex index = model()->index(row, 0, rootIndex());
QRectF rect = viewportRectForRow(row);
#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
QStyleOptionViewItem option;
initViewItemOption(&option);
#else
QStyleOptionViewItem option = viewOptions();
#endif

if (!rect.isValid() || rect.bottom() < 0 || rect.y() > viewport()->height())
continue;
Expand Down
8 changes: 8 additions & 0 deletions ui/drivers/qt/qt_dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,11 @@ ViewOptionsDialog::ViewOptionsDialog(MainWindow *mainwindow, QWidget *parent) :
QHBoxLayout *headerHLayout = new QHBoxLayout;
const int leftMargin = QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin);

#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
m_optionsStack->setContentsMargins(0, 0, 0, 0);
#else
m_optionsStack->setMargin(0);
#endif

headerLabelFont.setBold(true);

Expand Down Expand Up @@ -1193,7 +1197,11 @@ void CoreOptionsDialog::buildLayout()
}

for (k = 0; k < option->vals->size; k++)
#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
combo_box->addItem(option->vals->elems[k].data, QVariant::fromValue(option->key));
#else
combo_box->addItem(option->vals->elems[k].data, option->key);
#endif


combo_box->setCurrentText(val);
Expand Down
19 changes: 18 additions & 1 deletion ui/drivers/qt/qt_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,12 @@ QGroupBox *NetplayPage::createMitmServerGroup()

groupBox->add(MENU_ENUM_LABEL_NETPLAY_CUSTOM_MITM_SERVER);

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
connect(buttonGroup, &QButtonGroup::idClicked, this, &NetplayPage::onRadioButtonClicked);
#else
connect(buttonGroup, SIGNAL(buttonClicked(int)), this,
SLOT(onRadioButtonClicked(int)));
#endif

return groupBox;
}
Expand Down Expand Up @@ -1438,7 +1443,12 @@ QWidget *VideoPage::widget()

layout->addStretch();

connect(m_resolutionCombo, &QComboBox::currentIndexChanged, this, &VideoPage::onResolutionComboIndexChanged);
#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
void (VideoPage::*cb)(int) = &VideoPage::onResolutionComboIndexChanged;
connect(m_resolutionCombo, &QComboBox::currentIndexChanged, this, cb);
#else
connect(m_resolutionCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(onResolutionComboIndexChanged(const QString&)));
#endif

widget->setLayout(layout);

Expand Down Expand Up @@ -1566,6 +1576,13 @@ QWidget *CrtSwitchresPage::widget()
return widget;
}

void VideoPage::onResolutionComboIndexChanged(const QString &text)
{
const char *path = text.toUtf8().constData();
action_cb_push_dropdown_item_resolution(path,
NULL, 0, 0, 0);
}

void VideoPage::onResolutionComboIndexChanged(int index)
{
const QString& text = m_resolutionCombo->itemText(index);
Expand Down
1 change: 1 addition & 0 deletions ui/drivers/qt/qt_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class VideoPage : public OptionsPage
VideoPage(QObject *parent = nullptr);
QWidget *widget();
private slots:
Q_DECL_DEPRECATED void onResolutionComboIndexChanged(const QString& value);
void onResolutionComboIndexChanged(int index);
private:
QComboBox *m_resolutionCombo;
Expand Down
8 changes: 8 additions & 0 deletions ui/drivers/qt/qt_playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ void PlaylistModel::loadThumbnail(const QModelIndex &index)
if (!m_pendingImages.contains(path) && !m_cache.contains(path))
{
m_pendingImages.insert(path);
#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
QtConcurrent::run(&PlaylistModel::loadImage, this, index, path);
#else
QtConcurrent::run(this, &PlaylistModel::loadImage, index, path);
#endif
}
}

Expand Down Expand Up @@ -874,7 +878,11 @@ void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
for (j = 0; j < m_listWidget->count(); j++)
{
QListWidgetItem *item = m_listWidget->item(j);
#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
bool hidden = item->isHidden();
#else
bool hidden = m_listWidget->isItemHidden(item);
#endif

if (hidden)
{
Expand Down
4 changes: 4 additions & 0 deletions ui/drivers/qt/qt_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,11 @@ UIntRadioButtons::UIntRadioButtons(rarch_setting_t *setting, QWidget *parent) :
*setting->value.target.unsigned_integer = orig_value;
}
add_sublabel_and_whats_this(this, m_setting);
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
connect(m_buttonGroup, &QButtonGroup::idClicked, this, &UIntRadioButtons::onButtonClicked);
#else
connect(m_buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(onButtonClicked(int)));
#endif
}

UIntRadioButtons::UIntRadioButtons(msg_hash_enums enum_idx, QWidget *parent) :
Expand Down
18 changes: 18 additions & 0 deletions ui/drivers/ui_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3107,8 +3107,13 @@ void MainWindow::setCoreActions()
if (!found_existing)
{
QVariantMap comboBoxMap;
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
comboBoxMap["core_name"] = QVariant::fromValue(coreInfo->core_name);
comboBoxMap["core_path"] = QVariant::fromValue(coreInfo->path);
#else
comboBoxMap["core_name"] = coreInfo->core_name;
comboBoxMap["core_path"] = coreInfo->path;
#endif
comboBoxMap["core_selection"] = CORE_SELECTION_PLAYLIST_DEFAULT;
m_launchWithComboBox->addItem(coreInfo->core_name, QVariant::fromValue(comboBoxMap));
}
Expand Down Expand Up @@ -4216,6 +4221,11 @@ static void* ui_application_qt_initialize(void)

app_handler = new AppHandler();

#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
/* HiDpi supported since Qt 5.6 */
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

/* Create QApplication() before calling QApplication::setStyle()
* to ensure that plugin path is determined correctly */
ui_application.app = new QApplication(app_argc, app_argv);
Expand Down Expand Up @@ -4255,6 +4265,10 @@ static void* ui_application_qt_initialize(void)

static void ui_application_qt_process_events(void)
{
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QAbstractEventDispatcher *dispatcher = QApplication::eventDispatcher();
if (dispatcher && dispatcher->hasPendingEvents())
#endif
QApplication::processEvents();
}

Expand Down Expand Up @@ -5147,7 +5161,11 @@ void LoadCoreWindow::onCoreEnterPressed()
Qt::UserRole).toHash();
QString path = hash["path"].toString();

#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
pathArray.append(path.toStdString());
#else
pathArray.append(path);
#endif
pathData = pathArray.constData();

loadCore(pathData);
Expand Down

0 comments on commit 5528517

Please sign in to comment.