Use Qt MacExtras on macOS

This commit is contained in:
Florian Märkl 2019-09-25 13:36:54 +02:00 committed by Florian Märkl
commit 7a7c86e63c
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
5 changed files with 54 additions and 5 deletions

View file

@ -3,6 +3,9 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui Multimedia OpenGL Svg)
if(APPLE)
find_package(Qt5 REQUIRED COMPONENTS MacExtras)
endif()
if(CHIAKI_GUI_ENABLE_QT_GAMEPAD AND CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER)
message(FATAL_ERROR "Only one input method may be enabled. Disable either CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER or CHIAKI_GUI_ENABLE_QT_GAMEPAD.")
endif()
@ -76,6 +79,10 @@ endif()
target_link_libraries(chiaki FFMPEG::avcodec FFMPEG::avutil)
target_link_libraries(chiaki Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Multimedia Qt5::OpenGL Qt5::Svg)
if(APPLE)
target_link_libraries(chiaki Qt5::MacExtras)
target_compile_definitions(chiaki PRIVATE CHIAKI_GUI_ENABLE_QT_MACEXTRAS)
endif()
if(CHIAKI_GUI_ENABLE_QT_GAMEPAD)
target_link_libraries(chiaki Qt5::Gamepad)
target_compile_definitions(chiaki PRIVATE CHIAKI_GUI_ENABLE_QT_GAMEPAD)

View file

@ -46,6 +46,8 @@ class MainWindow : public QMainWindow
private:
Settings *settings;
QIcon discover_action_icon;
QIcon discover_action_off_icon;
QAction *discover_action;
DynamicGridWidget *grid_widget;

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M24 .01c0-.01 0-.01 0 0L0 0v24h24V.01zM0 0h24v24H0V0zm0 0h24v24H0V0z"/><path d="M22.99 9C19.15 5.16 13.8 3.76 8.84 4.78l2.52 2.52c3.47-.17 6.99 1.05 9.63 3.7l2-2zm-4 4c-1.29-1.29-2.84-2.13-4.49-2.56l3.53 3.53.96-.97zM2 3.05L5.07 6.1C3.6 6.82 2.22 7.78 1 9l1.99 2c1.24-1.24 2.67-2.16 4.2-2.77l2.24 2.24C7.81 10.89 6.27 11.73 5 13v.01L6.99 15c1.36-1.36 3.14-2.04 4.92-2.06L18.98 20l1.27-1.26L3.29 1.79 2 3.05zM9 17l3 3 3-3c-1.65-1.66-4.34-1.66-6 0z"/></svg>

After

Width:  |  Height:  |  Size: 559 B

View file

@ -3,6 +3,7 @@
<file>settings-20px.svg</file>
<file>add-24px.svg</file>
<file>discover-24px.svg</file>
<file>discover-off-24px.svg</file>
<file>chiaki.svg</file>
</qresource>
</RCC>

View file

@ -36,6 +36,10 @@
#include <QSvgRenderer>
#include <QApplication>
#ifdef CHIAKI_GUI_ENABLE_QT_MACEXTRAS
#include <QMacToolBar>
#endif
class IconEngine : public QIconEngine
{
private:
@ -99,25 +103,54 @@ MainWindow::MainWindow(Settings *settings, QWidget *parent)
return QIcon(new IconEngine(filename));
};
#ifdef CHIAKI_GUI_ENABLE_QT_MACEXTRAS
auto tool_bar = new QMacToolBar(this);
#else
auto tool_bar = new QToolBar(this);
tool_bar->setMovable(false);
addToolBar(tool_bar);
setUnifiedTitleAndToolBarOnMac(true);
#endif
discover_action = new QAction(tr("Automatically Search for Consoles"), this);
discover_action->setIcon(LoadIcon(":/icons/discover-24px.svg"));
auto AddToolBarAction = [&](QAction *action) {
#ifdef CHIAKI_GUI_ENABLE_QT_MACEXTRAS
auto item = tool_bar->addItem(action->icon(), action->text());
connect(item, &QMacToolBarItem::activated, action, &QAction::trigger);
if(action->isCheckable())
{
connect(action, &QAction::toggled, item, [action, item]() {
item->setIcon(action->icon());
});
}
#else
tool_bar->addAction(action);
#endif
};
discover_action = new QAction(tr("Search for Consoles"), this);
discover_action_icon = LoadIcon(":/icons/discover-24px.svg");
discover_action_off_icon = LoadIcon(":/icons/discover-off-24px.svg");
discover_action->setCheckable(true);
discover_action->setChecked(settings->GetDiscoveryEnabled());
tool_bar->addAction(discover_action);
auto UpdateDiscoverActionIcon = [this]() {
discover_action->setIcon(discover_action->isChecked() ? discover_action_icon : discover_action_off_icon);
};
UpdateDiscoverActionIcon();
connect(discover_action, &QAction::toggled, this, UpdateDiscoverActionIcon);
AddToolBarAction(discover_action);
connect(discover_action, &QAction::triggered, this, &MainWindow::UpdateDiscoveryEnabled);
auto tool_bar_spacer = new QWidget();
tool_bar_spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
#ifdef CHIAKI_GUI_ENABLE_QT_MACEXTRAS
tool_bar->addStandardItem(QMacToolBarItem::StandardItem::FlexibleSpace);
#else
tool_bar->addWidget(tool_bar_spacer);
#endif
auto add_manual_action = new QAction(tr("Add Console manually"), this);
add_manual_action->setIcon(LoadIcon(":/icons/add-24px.svg"));
tool_bar->addAction(add_manual_action);
AddToolBarAction(add_manual_action);
connect(add_manual_action, &QAction::triggered, this, [this]() {
ManualHostDialog dialog(this->settings, -1, this);
dialog.exec();
@ -125,7 +158,7 @@ MainWindow::MainWindow(Settings *settings, QWidget *parent)
auto settings_action = new QAction(tr("Settings"), this);
settings_action->setIcon(LoadIcon(":/icons/settings-20px.svg"));
tool_bar->addAction(settings_action);
AddToolBarAction(settings_action);
connect(settings_action, &QAction::triggered, this, &MainWindow::ShowSettings);
auto scroll_area = new QScrollArea(this);
@ -138,6 +171,11 @@ MainWindow::MainWindow(Settings *settings, QWidget *parent)
scroll_content_widget->setLayout(scroll_content_layout);
scroll_area->setWidget(scroll_content_widget);
#ifdef CHIAKI_GUI_ENABLE_QT_MACEXTRAS
this->window()->winId();
tool_bar->attachToWindow(this->window()->windowHandle());
#endif
grid_widget = new DynamicGridWidget(200, scroll_content_widget);
scroll_content_layout->addWidget(grid_widget);
scroll_content_layout->addStretch(0);