1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 25 deletions

View File

@ -249,7 +249,8 @@ find_package(TBB REQUIRED)
if(ENABLE_LAUNCHER)
# 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()
if(ENABLE_LUA)
@ -389,7 +390,7 @@ if(WIN32)
endif()
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)
file(GLOB dep_files
${dep_files}
@ -398,9 +399,9 @@ if(WIN32)
${Qtbin_folder}/Qt5Widgets${debug_postfix}.dll
${Qtbin_folder}/Qt5Network${debug_postfix}.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"))
get_target_property(integration_loc Qt5::QWindowsIntegrationPlugin LOCATION)
get_target_property(integration_loc Qt${QT_VERSION_MAJOR}::QWindowsIntegrationPlugin LOCATION)
install(
FILES ${integration_loc}
DESTINATION ${BIN_DIR}/platforms

View File

@ -63,13 +63,11 @@ endif()
# to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if("${CMAKE_VERSION}" VERSION_LESS 2.8.12)
# Executables fail to build with Qt 5 in the default configuration
# without -fPIE. We add that here.
set(CMAKE_CXX_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS} ${CMAKE_CXX_FLAGS}")
endif()
if(TARGET Qt6::Core)
qt_wrap_ui(launcher_UI_HEADERS ${launcher_FORMS})
else()
qt5_wrap_ui(launcher_UI_HEADERS ${launcher_FORMS})
endif()
if(WIN32)
set(launcher_ICON VCMI_launcher.rc)
@ -90,7 +88,7 @@ if(WIN32)
# - cmake_policy in all possible places
# - used NO_POLICY_SCOPE to make sure no other parts reset policies
# 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()
if(APPLE)
@ -98,7 +96,7 @@ if(APPLE)
set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER vcmilauncher)
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
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)

View File

@ -106,9 +106,9 @@ JsonNode toJson(QVariant object)
ret.Struct() = VariantToMap(object.toMap());
else if(object.canConvert<QVariantList>())
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();
else if(static_cast<QMetaType::Type>(object.type()) == QMetaType::Bool)
else if(object.userType() == QMetaType::Bool)
ret.Bool() = object.toBool();
else if(object.canConvert<double>())
ret.Float() = object.toFloat();

View File

@ -102,7 +102,7 @@ void MainWindow::startExecutable(QString name)
QProcess process;
// Start the executable
if(process.startDetached(name))
if(process.startDetached(name, {}))
{
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++)
{
if(filterMatchesThis(index.child((int)i, 0)))
if(filterMatchesThis(base->index((int)i, 0, index)))
return true;
}

View File

@ -15,6 +15,7 @@
#include <QJsonArray>
#include <QCryptographicHash>
#include <QRegularExpression>
#include "cmodlistmodel_moc.h"
#include "cmodmanager.h"
@ -352,8 +353,16 @@ void CModListView::on_allModsView_activated(const QModelIndex & index)
void CModListView::on_lineEdit_textChanged(const QString & arg1)
{
QRegExp regExp(arg1, Qt::CaseInsensitive, QRegExp::Wildcard);
filterModel->setFilterRegExp(regExp);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
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)

View File

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

View File

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