1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-13 01:20:34 +02:00

Launcher: Qt6 support. Qt 5.12 required (#746)

* Launcher: Qt6 support. Qt 5.12 required
This commit is contained in:
Konstantin
2022-05-28 16:32:20 +03:00
committed by GitHub
parent 9d06e51631
commit 1a6ee0d697
8 changed files with 33 additions and 25 deletions

View File

@ -249,7 +249,8 @@ find_package(TBB REQUIRED)
if(ENABLE_LAUNCHER) if(ENABLE_LAUNCHER)
# Widgets finds its own dependencies (QtGui and QtCore). # Widgets finds its own dependencies (QtGui and QtCore).
find_package(Qt5 COMPONENTS Widgets Network REQUIRED) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network)
endif() endif()
if(ENABLE_LUA) if(ENABLE_LUA)
@ -389,7 +390,7 @@ if(WIN32)
endif() endif()
if(ENABLE_LAUNCHER) if(ENABLE_LAUNCHER)
get_target_property(QtCore_location Qt5::Core LOCATION) get_target_property(QtCore_location Qt${QT_VERSION_MAJOR}::Core LOCATION)
get_filename_component(Qtbin_folder ${QtCore_location} PATH) get_filename_component(Qtbin_folder ${QtCore_location} PATH)
file(GLOB dep_files file(GLOB dep_files
${dep_files} ${dep_files}
@ -398,9 +399,9 @@ if(WIN32)
${Qtbin_folder}/Qt5Widgets${debug_postfix}.dll ${Qtbin_folder}/Qt5Widgets${debug_postfix}.dll
${Qtbin_folder}/Qt5Network${debug_postfix}.dll ${Qtbin_folder}/Qt5Network${debug_postfix}.dll
${Qtbin_folder}/icu*.dll) ${Qtbin_folder}/icu*.dll)
get_target_property(integration_type Qt5::QWindowsIntegrationPlugin TYPE) get_target_property(integration_type Qt${QT_VERSION_MAJOR}::QWindowsIntegrationPlugin TYPE)
if(NOT(integration_type STREQUAL "INTERFACE_LIBRARY")) if(NOT(integration_type STREQUAL "INTERFACE_LIBRARY"))
get_target_property(integration_loc Qt5::QWindowsIntegrationPlugin LOCATION) get_target_property(integration_loc Qt${QT_VERSION_MAJOR}::QWindowsIntegrationPlugin LOCATION)
install( install(
FILES ${integration_loc} FILES ${integration_loc}
DESTINATION ${BIN_DIR}/platforms DESTINATION ${BIN_DIR}/platforms

View File

@ -63,13 +63,11 @@ endif()
# to always look for includes there: # to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
if("${CMAKE_VERSION}" VERSION_LESS 2.8.12) if(TARGET Qt6::Core)
# Executables fail to build with Qt 5 in the default configuration qt_wrap_ui(launcher_UI_HEADERS ${launcher_FORMS})
# without -fPIE. We add that here. else()
set(CMAKE_CXX_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS} ${CMAKE_CXX_FLAGS}")
endif()
qt5_wrap_ui(launcher_UI_HEADERS ${launcher_FORMS}) qt5_wrap_ui(launcher_UI_HEADERS ${launcher_FORMS})
endif()
if(WIN32) if(WIN32)
set(launcher_ICON VCMI_launcher.rc) set(launcher_ICON VCMI_launcher.rc)
@ -90,7 +88,7 @@ if(WIN32)
# - cmake_policy in all possible places # - cmake_policy in all possible places
# - used NO_POLICY_SCOPE to make sure no other parts reset policies # - used NO_POLICY_SCOPE to make sure no other parts reset policies
# Still nothing worked, warning kept appearing and WinMain didn't link automatically # Still nothing worked, warning kept appearing and WinMain didn't link automatically
target_link_libraries(vcmilauncher Qt5::WinMain) target_link_libraries(vcmilauncher Qt${QT_VERSION_MAJOR}::WinMain)
endif() endif()
if(APPLE) if(APPLE)
@ -98,7 +96,7 @@ if(APPLE)
set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER vcmilauncher) set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER vcmilauncher)
endif() endif()
target_link_libraries(vcmilauncher vcmi Qt5::Widgets Qt5::Network) target_link_libraries(vcmilauncher vcmi Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network)
target_include_directories(vcmilauncher target_include_directories(vcmilauncher
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
) )

View File

@ -106,9 +106,9 @@ JsonNode toJson(QVariant object)
ret.Struct() = VariantToMap(object.toMap()); ret.Struct() = VariantToMap(object.toMap());
else if(object.canConvert<QVariantList>()) else if(object.canConvert<QVariantList>())
ret.Vector() = VariantToList(object.toList()); ret.Vector() = VariantToList(object.toList());
else if(static_cast<QMetaType::Type>(object.type()) == QMetaType::QString) else if(object.userType() == QMetaType::QString)
ret.String() = object.toString().toUtf8().data(); ret.String() = object.toString().toUtf8().data();
else if(static_cast<QMetaType::Type>(object.type()) == QMetaType::Bool) else if(object.userType() == QMetaType::Bool)
ret.Bool() = object.toBool(); ret.Bool() = object.toBool();
else if(object.canConvert<double>()) else if(object.canConvert<double>())
ret.Float() = object.toFloat(); ret.Float() = object.toFloat();

View File

@ -102,7 +102,7 @@ void MainWindow::startExecutable(QString name)
QProcess process; QProcess process;
// Start the executable // Start the executable
if(process.startDetached(name)) if(process.startDetached(name, {}))
{ {
close(); // exit launcher close(); // exit launcher
} }

View File

@ -253,7 +253,7 @@ bool CModFilterModel::filterAcceptsRow(int source_row, const QModelIndex & sourc
for(size_t i = 0; i < base->rowCount(index); i++) for(size_t i = 0; i < base->rowCount(index); i++)
{ {
if(filterMatchesThis(index.child((int)i, 0))) if(filterMatchesThis(base->index((int)i, 0, index)))
return true; return true;
} }

View File

@ -15,6 +15,7 @@
#include <QJsonArray> #include <QJsonArray>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QRegularExpression>
#include "cmodlistmodel_moc.h" #include "cmodlistmodel_moc.h"
#include "cmodmanager.h" #include "cmodmanager.h"
@ -352,8 +353,16 @@ void CModListView::on_allModsView_activated(const QModelIndex & index)
void CModListView::on_lineEdit_textChanged(const QString & arg1) void CModListView::on_lineEdit_textChanged(const QString & arg1)
{ {
QRegExp regExp(arg1, Qt::CaseInsensitive, QRegExp::Wildcard); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
filterModel->setFilterRegExp(regExp); auto baseStr = QRegularExpression::wildcardToRegularExpression(arg1, QRegularExpression::UnanchoredWildcardConversion);
#else
auto baseStr = QRegularExpression::wildcardToRegularExpression(arg1);
//Hack due to lack QRegularExpression::UnanchoredWildcardConversion in Qt5
baseStr.chop(3);
baseStr.remove(0,5);
#endif
QRegularExpression regExp{baseStr, QRegularExpression::CaseInsensitiveOption};
filterModel->setFilterRegularExpression(regExp);
} }
void CModListView::on_comboBox_currentIndexChanged(int index) void CModListView::on_comboBox_currentIndexChanged(int index)

View File

@ -9,7 +9,7 @@
*/ */
#include "StdInc.h" #include "StdInc.h"
#include <QDesktopWidget> #include <QGuiApplication>
#include "imageviewer_moc.h" #include "imageviewer_moc.h"
#include "ui_imageviewer_moc.h" #include "ui_imageviewer_moc.h"
@ -27,8 +27,7 @@ ImageViewer::~ImageViewer()
QSize ImageViewer::calculateWindowSize() QSize ImageViewer::calculateWindowSize()
{ {
QDesktopWidget desktop; return QGuiApplication::primaryScreen()->availableGeometry().size() * 0.8;
return desktop.availableGeometry(desktop.primaryScreen()).size() * 0.8;
} }
void ImageViewer::showPixmap(QPixmap & pixmap, QWidget * parent) void ImageViewer::showPixmap(QPixmap & pixmap, QWidget * parent)

View File

@ -12,6 +12,7 @@
#include "ui_csettingsview_moc.h" #include "ui_csettingsview_moc.h"
#include <QFileInfo> #include <QFileInfo>
#include <QGuiApplication>
#include "../../lib/CConfigHandler.h" #include "../../lib/CConfigHandler.h"
#include "../../lib/VCMIDirs.h" #include "../../lib/VCMIDirs.h"
@ -34,12 +35,12 @@ static const std::string knownEncodingsList[] = //TODO: remove hardcode
void CSettingsView::setDisplayList() void CSettingsView::setDisplayList()
{ {
QStringList list; QStringList list;
QDesktopWidget * widget = QApplication::desktop();
for(int display = 0; display < widget->screenCount(); display++) for (const auto screen : QGuiApplication::screens())
{ {
QString string; QString string;
auto rect = widget->screenGeometry(display); const auto & rect = screen->geometry();
QTextStream(&string) << display << " - " << rect.width() << "x" << rect.height(); QTextStream(&string) << screen->name() << " - " << rect.width() << "x" << rect.height();
list << string; list << string;
} }