Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10559 from shuffle2/qt6
update to Qt6 on windows, support Qt6 elsewhere
  • Loading branch information
JMC47 committed May 8, 2022
2 parents 997754b + 004e8a8 commit 5f04ad5
Show file tree
Hide file tree
Showing 24 changed files with 544 additions and 83 deletions.
2 changes: 1 addition & 1 deletion BuildMacOSUniversalBinary.py
Expand Up @@ -261,7 +261,7 @@ def build(config):
os.mkdir(arch)

env = os.environ.copy()
env["Qt5_DIR"] = config[arch+"_qt5_path"]
env["QT_DIR"] = config[arch+"_qt5_path"]
env["CMAKE_OSX_ARCHITECTURES"] = arch
env["CMAKE_PREFIX_PATH"] = config[arch+"_cmake_prefix"]

Expand Down
16 changes: 8 additions & 8 deletions CMakeSettings.json
Expand Up @@ -10,8 +10,8 @@
"cmakeCommandArgs": "",
"variables": [
{
"name": "Qt5_DIR",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt5.15.0\\msvc2019_64\\lib\\cmake\\Qt5"
"name": "QT_DIR",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt6.3.0\\x64\\lib\\cmake\\Qt6"
}
]
},
Expand All @@ -25,8 +25,8 @@
"cmakeCommandArgs": "",
"variables": [
{
"name": "Qt5_DIR",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt5.15.0\\msvc2019_64\\lib\\cmake\\Qt5"
"name": "QT_DIR",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt6.3.0\\x64\\lib\\cmake\\Qt6"
}
]
},
Expand All @@ -40,8 +40,8 @@
"cmakeCommandArgs": "",
"variables": [
{
"name": "Qt5_DIR",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt5.15.0\\msvc2019_arm64\\lib\\cmake\\Qt5"
"name": "QT_DIR",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt6.3.0\\ARM64\\lib\\cmake\\Qt6"
},
{
"name": "CMAKE_SYSTEM_NAME",
Expand All @@ -63,8 +63,8 @@
"cmakeCommandArgs": "",
"variables": [
{
"name": "Qt5_DIR",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt5.15.0\\msvc2019_arm64\\lib\\cmake\\Qt5"
"name": "QT_DIR",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt6.3.0\\ARM64\\lib\\cmake\\Qt6"
},
{
"name": "CMAKE_SYSTEM_NAME",
Expand Down
2 changes: 1 addition & 1 deletion Externals/Qt
Submodule Qt updated 11014 files
47 changes: 32 additions & 15 deletions Source/Core/DolphinQt/CMakeLists.txt
@@ -1,17 +1,28 @@
if (NOT Qt5_DIR AND MSVC)
if(POLICY CMP0084)
# Disable trying to search for Qt3/4 if what we actually want is not found
cmake_policy(SET CMP0084 NEW)
endif()

if (NOT QT_DIR AND MSVC)
if(_M_ARM_64)
set(Qt5_DIR "${CMAKE_SOURCE_DIR}/Externals/Qt/Qt5.15.0/msvc2019_arm64/lib/cmake/Qt5")
set(QT_DIR "${CMAKE_SOURCE_DIR}/Externals/Qt/Qt6.3.0/ARM64/lib/cmake/Qt6")
else()
set(Qt5_DIR "${CMAKE_SOURCE_DIR}/Externals/Qt/Qt5.15.0/msvc2019_64/lib/cmake/Qt5")
set(QT_DIR "${CMAKE_SOURCE_DIR}/Externals/Qt/Qt6.3.0/x64/lib/cmake/Qt6")
endif()
endif()

find_package(Qt5 5.9 REQUIRED COMPONENTS Gui Widgets)
set(CMAKE_AUTOMOC ON)

set_property(TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_FEATURES "")
message(STATUS "Found Qt version ${Qt5Core_VERSION}")
# For some reason the method in Qt6 documentation is not working (at least on ubuntu jammy)
# When Qt5 and Qt6 are given in same NAMES entry, only Qt5 is ever found.
find_package(QT NAMES Qt6 COMPONENTS Core Gui Widgets)
if(NOT QT_DIR)
find_package(QT NAMES Qt5 COMPONENTS Core Gui Widgets)
endif()
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets)
message(STATUS "Found Qt version ${QT_VERSION}")

set(CMAKE_AUTOMOC ON)
set_property(TARGET Qt${QT_VERSION_MAJOR}::Core PROPERTY INTERFACE_COMPILE_FEATURES "")

add_executable(dolphin-emu
AboutDialog.cpp
Expand Down Expand Up @@ -351,13 +362,13 @@ PRIVATE
target_include_directories(dolphin-emu
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
${Qt5Gui_PRIVATE_INCLUDE_DIRS}
${Qt${QT_VERSION_MAJOR}Gui_PRIVATE_INCLUDE_DIRS}
)

target_link_libraries(dolphin-emu
PRIVATE
core
Qt5::Widgets
Qt${QT_VERSION_MAJOR}::Widgets
uicommon
imgui
)
Expand All @@ -377,9 +388,9 @@ if (MSVC)
set(qtGui "")
set(qtGuiPriv "")
set(qtWidgetsPriv "")
list(TRANSFORM Qt5Gui_INCLUDE_DIRS PREPEND "/external:I" OUTPUT_VARIABLE qtGui)
list(TRANSFORM Qt5Gui_PRIVATE_INCLUDE_DIRS PREPEND "/external:I" OUTPUT_VARIABLE qtGuiPriv)
list(TRANSFORM Qt5Widgets_PRIVATE_INCLUDE_DIRS PREPEND "/external:I" OUTPUT_VARIABLE qtWidgetsPriv)
list(TRANSFORM Qt6Gui_INCLUDE_DIRS PREPEND "/external:I" OUTPUT_VARIABLE qtGui)
list(TRANSFORM Qt6Gui_PRIVATE_INCLUDE_DIRS PREPEND "/external:I" OUTPUT_VARIABLE qtGuiPriv)
list(TRANSFORM Qt6Widgets_PRIVATE_INCLUDE_DIRS PREPEND "/external:I" OUTPUT_VARIABLE qtWidgetsPriv)
target_compile_options(dolphin-emu PRIVATE "${qtGui}")
target_compile_options(dolphin-emu PRIVATE "${qtGuiPriv}")
target_compile_options(dolphin-emu PRIVATE "${qtWidgets}")
Expand Down Expand Up @@ -415,7 +426,7 @@ if(WIN32)
)

# Delegate to Qt's official deployment binary on Windows to copy over the necessary Qt-specific libraries, etc.
get_target_property(MOC_EXECUTABLE_LOCATION Qt5::moc IMPORTED_LOCATION)
get_target_property(MOC_EXECUTABLE_LOCATION Qt${QT_VERSION_MAJOR}::moc IMPORTED_LOCATION)
get_filename_component(QT_BINARY_DIRECTORY "${MOC_EXECUTABLE_LOCATION}" DIRECTORY)
find_program(WINDEPLOYQT_EXE windeployqt HINTS "${QT_BINARY_DIRECTORY}")

Expand Down Expand Up @@ -520,12 +531,18 @@ if(APPLE)
target_sources(dolphin-emu PRIVATE "${CMAKE_SOURCE_DIR}/Data/Dolphin.icns")
set_source_files_properties("${CMAKE_SOURCE_DIR}/Data/Dolphin.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)

# Plugins have to be manually included with Qt 6
if (QT_VERSION_MAJOR EQUAL 6)
find_package(Qt6QMacStylePlugin REQUIRED PATHS ${Qt6Widgets_DIR})
find_package(Qt6QCocoaIntegrationPlugin REQUIRED PATHS ${Qt6Gui_DIR})
endif()

# Copy Qt plugins into the bundle
get_target_property(qtcocoa_location Qt5::QCocoaIntegrationPlugin LOCATION)
get_target_property(qtcocoa_location Qt${QT_VERSION_MAJOR}::QCocoaIntegrationPlugin LOCATION)
target_sources(dolphin-emu PRIVATE "${qtcocoa_location}")
set_source_files_properties("${qtcocoa_location}" PROPERTIES MACOSX_PACKAGE_LOCATION MacOS/platforms)

get_target_property(qtmacstyle_location Qt5::QMacStylePlugin LOCATION)
get_target_property(qtmacstyle_location Qt${QT_VERSION_MAJOR}::QMacStylePlugin LOCATION)
target_sources(dolphin-emu PRIVATE "${qtmacstyle_location}")
set_source_files_properties("${qtmacstyle_location}" PROPERTIES MACOSX_PACKAGE_LOCATION MacOS/styles)

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/CheatSearchFactoryWidget.cpp
Expand Up @@ -55,7 +55,7 @@ void CheatSearchFactoryWidget::CreateWidgets()
label_standard_address_space->setWordWrap(true);

auto* custom_address_space_layout = new QVBoxLayout();
custom_address_space_layout->setMargin(6);
custom_address_space_layout->setContentsMargins(6, 6, 6, 6);
auto* custom_address_space_button_group = new QButtonGroup(this);
m_custom_virtual_address_space = new QRadioButton(tr("Use virtual addresses when possible"));
m_custom_virtual_address_space->setChecked(true);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Config/CommonControllersWidget.cpp
Expand Up @@ -36,7 +36,7 @@ void CommonControllersWidget::CreateLayout()
m_common_box->setLayout(m_common_layout);

auto* layout = new QVBoxLayout;
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setAlignment(Qt::AlignTop);
layout->addWidget(m_common_box);
setLayout(layout);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp
Expand Up @@ -92,7 +92,7 @@ void GamecubeControllersWidget::CreateLayout()
m_gc_box->setLayout(m_gc_layout);

auto* layout = new QVBoxLayout;
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setAlignment(Qt::AlignTop);
layout->addWidget(m_gc_box);
setLayout(layout);
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/DolphinQt/Config/ToolTipControls/ToolTipWidget.h
Expand Up @@ -22,7 +22,11 @@ class ToolTipWidget : public Derived
void SetDescription(QString description) { m_description = std::move(description); }

private:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void enterEvent(QEvent* event) override
#else
void enterEvent(QEnterEvent* event) override
#endif
{
if (m_timer_id)
return;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/Config/WiimoteControllersWidget.cpp
Expand Up @@ -74,7 +74,7 @@ static int GetLayoutHorizontalSpacing(const QGridLayout* layout)
float pixel_ratio = QGuiApplication::primaryScreen()->devicePixelRatio();
#ifdef __APPLE__
// TODO is this still required?
hspacing = pixel_ratio * style->pixelMetric(QStyle::PM_DefaultLayoutSpacing);
hspacing = pixel_ratio * style->pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
if (hspacing >= 0)
return hspacing;
#endif
Expand Down Expand Up @@ -145,7 +145,7 @@ void WiimoteControllersWidget::CreateLayout()
m_wiimote_layout->addWidget(m_wiimote_refresh, continuous_scanning_row, 3);

auto* layout = new QVBoxLayout;
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setAlignment(Qt::AlignTop);
layout->addWidget(m_wiimote_box);
setLayout(layout);
Expand Down
18 changes: 15 additions & 3 deletions Source/Core/DolphinQt/DolphinQt.vcxproj
Expand Up @@ -13,14 +13,11 @@
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VSPropsDir)Base.props" />
<Import Project="$(VSPropsDir)PCHUse.props" />
<Import Project="$(VSPropsDir)QtCompile.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<ClCompile>
<!-- 5054 operator '+': deprecated between enumerations of different types (types defined in Qt headers) -->
<DisableSpecificWarnings>5054;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<AdditionalIncludeDirectories>$(ProjectDir)Config\Graphics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)Config;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)Config\ControllerInterface;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Expand All @@ -33,6 +30,8 @@
<AdditionalIncludeDirectories>$(ProjectDir)Settings;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)TAS;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)VideoInterface;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<!--Ignore warnings in locally-instantiated fmt templates-->
<ExternalTemplatesDiagnostics>false</ExternalTemplatesDiagnostics>
</ClCompile>
<Manifest>
<AdditionalManifestFiles>DolphinQt.manifest;%(AdditionalManifestFiles)</AdditionalManifestFiles>
Expand Down Expand Up @@ -379,6 +378,9 @@
<ItemGroup>
<ResourceCompile Include="DolphinQt.rc" />
</ItemGroup>
<ItemGroup>
<Natvis Include="qt6.natvis" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(CoreDir)DolphinLib.vcxproj">
<Project>{D79392F7-06D6-4B4B-A39F-4D587C215D3A}</Project>
Expand All @@ -389,6 +391,16 @@
<ProjectReference Include="$(DolphinRootDir)Languages\Languages.vcxproj">
<Project>{0e033be3-2e08-428e-9ae9-bc673efa12b5}</Project>
</ProjectReference>
<!--
This project doesn't use PCH during compile (because RTTI setting differs),
but we still must link it for the dependants (DolphinLib)
-->
<ProjectReference Include="$(SourceDir)PCH\pch.vcxproj">
<Project>{76563A7F-1011-4EAD-B667-7BB18D09568E}</Project>
<Private>false</Private>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
</ItemGroup>
<Import Project="$(ExternalsDir)ExternalsReferenceAll.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
8 changes: 7 additions & 1 deletion Source/Core/DolphinQt/GBAWidget.cpp
Expand Up @@ -510,7 +510,13 @@ void GBAWidget::mouseMoveEvent(QMouseEvent* event)
{
if (!m_moving)
return;
move(event->globalPos() - m_move_pos - (geometry().topLeft() - pos()));
auto event_pos =
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
event->globalPosition().toPoint();
#else
event->globalPos();
#endif
move(event_pos - m_move_pos - (geometry().topLeft() - pos()));
}

void GBAWidget::paintEvent(QPaintEvent* event)
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/GameList/GameList.cpp
Expand Up @@ -108,14 +108,14 @@ GameList::GameList(QWidget* parent) : QStackedWidget(parent), m_model(this)
// conceptually as 'control plus' (which is then interpreted as an appropriate zooming action)
// instead of the technically correct 'control equal'. Qt doesn't account for this convention so
// an alternate shortcut is needed to avoid counterintuitive behavior.
const auto* zoom_in_alternate = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Equal), this);
const auto* zoom_in_alternate = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Equal), this);
connect(zoom_in_alternate, &QShortcut::activated, this, &GameList::ZoomIn);

// The above correction introduces a different inconsistency: now zooming in can be done using
// conceptual 'control plus' or 'control shift plus', while zooming out can only be done using
// 'control minus'. Adding an alternate shortcut representing 'control shift minus' restores
// consistency.
const auto* zoom_out_alternate = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Underscore), this);
const auto* zoom_out_alternate = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Underscore), this);
connect(zoom_out_alternate, &QShortcut::activated, this, &GameList::ZoomOut);

connect(&Settings::Instance(), &Settings::MetadataRefreshCompleted, this,
Expand Down
9 changes: 8 additions & 1 deletion Source/Core/DolphinQt/Main.cpp
Expand Up @@ -132,8 +132,15 @@ int main(int argc, char* argv[])
const optparse::Values& options = CommandLineParse::ParseArguments(parser.get(), argc, argv);
const std::vector<std::string> args = parser->args();

// setHighDpiScaleFactorRoundingPolicy was added in 5.14, but default behavior changed in 6.0
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
// Set to the previous default behavior
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round);
#else
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif

QCoreApplication::setOrganizationName(QStringLiteral("Dolphin Emulator"));
QCoreApplication::setOrganizationDomain(QStringLiteral("dolphin-emu.org"));
QCoreApplication::setApplicationName(QStringLiteral("dolphin-emu"));
Expand All @@ -144,7 +151,7 @@ int main(int argc, char* argv[])
QApplication app(argc, argv);
#endif

#ifdef _WIN32
#if defined(_WIN32) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
// On Windows, Qt 5's default system font (MS Shell Dlg 2) is outdated.
// Interestingly, the QMenu font is correct and comes from lfMenuFont
// (Segoe UI on English computers).
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/MainWindow.cpp
Expand Up @@ -825,7 +825,7 @@ void MainWindow::TogglePause()
void MainWindow::OnStopComplete()
{
m_stop_requested = false;
HideRenderWidget(true, m_exit_requested);
HideRenderWidget(!m_exit_requested, m_exit_requested);
#ifdef USE_DISCORD_PRESENCE
if (!m_netplay_dialog->isVisible())
Discord::UpdateDiscordPresence();
Expand All @@ -834,7 +834,7 @@ void MainWindow::OnStopComplete()
SetFullScreenResolution(false);

if (m_exit_requested || Settings::Instance().IsBatchModeEnabled())
QGuiApplication::instance()->quit();
QGuiApplication::exit(0);

// If the current emulation prevented the booting of another, do that now
if (m_pending_boot != nullptr)
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/MenuBar.cpp
Expand Up @@ -218,7 +218,7 @@ void MenuBar::AddFileMenu()
file_menu->addSeparator();

m_exit_action = file_menu->addAction(tr("E&xit"), this, &MenuBar::Exit);
m_exit_action->setShortcuts({QKeySequence::Quit, QKeySequence(Qt::ALT + Qt::Key_F4)});
m_exit_action->setShortcuts({QKeySequence::Quit, QKeySequence(Qt::ALT | Qt::Key_F4)});
}

void MenuBar::AddToolsMenu()
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DolphinQt/QtUtils/ParallelProgressDialog.h
Expand Up @@ -16,6 +16,11 @@ class ParallelProgressDialog final : public QObject
Q_OBJECT

public:
ParallelProgressDialog(const ParallelProgressDialog&) = delete;
ParallelProgressDialog& operator=(const ParallelProgressDialog&) = delete;
ParallelProgressDialog(ParallelProgressDialog&&) = delete;
ParallelProgressDialog& operator=(ParallelProgressDialog&&) = delete;

// Only use this from the main thread
template <typename... Args>
ParallelProgressDialog(Args&&... args) : m_dialog{std::forward<Args>(args)...}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/RenderWidget.cpp
Expand Up @@ -502,8 +502,8 @@ void RenderWidget::PassEventToImGui(const QEvent* event)
// coordinates (as if the screen was standard dpi). We need to update the mouse position in
// native coordinates, as the UI (and game) is rendered at native resolution.
const float scale = devicePixelRatio();
ImGui::GetIO().MousePos.x = static_cast<const QMouseEvent*>(event)->x() * scale;
ImGui::GetIO().MousePos.y = static_cast<const QMouseEvent*>(event)->y() * scale;
ImGui::GetIO().MousePos.x = static_cast<const QMouseEvent*>(event)->pos().x() * scale;
ImGui::GetIO().MousePos.y = static_cast<const QMouseEvent*>(event)->pos().y() * scale;
}
break;

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/TAS/IRWidget.cpp
Expand Up @@ -87,8 +87,8 @@ void IRWidget::handleMouseEvent(QMouseEvent* event)
else
{
// convert from widget space to value space
int new_x = ir_max_x - (event->x() * ir_max_x) / width();
int new_y = (event->y() * ir_max_y) / height();
int new_x = ir_max_x - (event->pos().x() * ir_max_x) / width();
int new_y = (event->pos().y() * ir_max_y) / height();

m_x = std::max(0, std::min(static_cast<int>(ir_max_x), new_x));
m_y = std::max(0, std::min(static_cast<int>(ir_max_y), new_y));
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/TAS/StickWidget.cpp
Expand Up @@ -90,8 +90,8 @@ void StickWidget::handleMouseEvent(QMouseEvent* event)
else
{
// convert from widget space to value space
int new_x = (event->x() * m_max_x) / width();
int new_y = m_max_y - (event->y() * m_max_y) / height();
int new_x = (event->pos().x() * m_max_x) / width();
int new_y = m_max_y - (event->pos().y() * m_max_y) / height();

m_x = std::max(0, std::min(static_cast<int>(m_max_x), new_x));
m_y = std::max(0, std::min(static_cast<int>(m_max_y), new_y));
Expand Down

0 comments on commit 5f04ad5

Please sign in to comment.