Don't use "Qt Mac Extras" module

"Qt Mac Extras" module is removed in Qt6.
This commit is contained in:
Vladimir Golovnev (Glassez) 2021-04-12 13:15:30 +03:00 committed by Vladimir Golovnev (glassez)
parent d82a1d7198
commit 35032d7eed
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7
6 changed files with 32 additions and 20 deletions

View file

@ -61,9 +61,7 @@ add_subdirectory(base)
if (GUI)
find_package(Qt5 ${minQtVersion} REQUIRED COMPONENTS Widgets Svg)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_package(Qt5 ${minQtVersion} REQUIRED COMPONENTS MacExtras)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
find_package(Qt5 ${minQtVersion} REQUIRED COMPONENTS WinExtras)
endif()
add_subdirectory(gui)

View file

@ -228,7 +228,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
macutilities.mm
)
target_link_libraries(qbt_gui PRIVATE
Qt5::MacExtras
objc
)
endif()

View file

@ -42,4 +42,7 @@ namespace MacUtils
void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...));
void displayNotification(const QString &title, const QString &message);
void openFiles(const QSet<QString> &pathsList);
QString badgeLabelText();
void setBadgeLabelText(const QString &text);
}

View file

@ -35,18 +35,21 @@
#include <QSet>
#include <QSize>
#include <QString>
#include <QtMac>
QImage qt_mac_toQImage(CGImageRef image);
namespace MacUtils
{
QPixmap pixmapForExtension(const QString &ext, const QSize &size)
{
@autoreleasepool {
@autoreleasepool
{
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:ext.toNSString()];
if (image) {
if (image)
{
NSRect rect = NSMakeRect(0, 0, size.width(), size.height());
CGImageRef cgImage = [image CGImageForProposedRect:&rect context:nil hints:nil];
return QtMac::fromCGImageRef(cgImage);
return QPixmap::fromImage(qt_mac_toQImage(cgImage));
}
return QPixmap();
@ -63,13 +66,15 @@ namespace MacUtils
Class delClass = [[appInst delegate] class];
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
if (class_getInstanceMethod(delClass, shouldHandle)) {
if (class_getInstanceMethod(delClass, shouldHandle))
{
if (class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:"))
qDebug("Registered dock click handler (replaced original method)");
else
qWarning("Failed to replace method for dock click handler");
}
else {
else
{
if (class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:"))
qDebug("Registered dock click handler");
else
@ -79,7 +84,8 @@ namespace MacUtils
void displayNotification(const QString &title, const QString &message)
{
@autoreleasepool {
@autoreleasepool
{
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = title.toNSString();
notification.informativeText = message.toNSString();
@ -91,7 +97,8 @@ namespace MacUtils
void openFiles(const QSet<QString> &pathsList)
{
@autoreleasepool {
@autoreleasepool
{
NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()];
for (const auto &path : pathsList)
@ -100,4 +107,14 @@ namespace MacUtils
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs];
}
}
QString badgeLabelText()
{
return QString::fromNSString(NSApp.dockTile.badgeLabel);
}
void setBadgeLabelText(const QString &text)
{
NSApp.dockTile.badgeLabel = text.toNSString();
}
}

View file

@ -48,10 +48,6 @@
#include <QtGlobal>
#include <QTimer>
#ifdef Q_OS_MACOS
#include <QtMac>
#include <QtMacExtras>
#endif
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
#include <QDBusConnection>
#include "qtnotify/notifications.h"
@ -1612,12 +1608,12 @@ void MainWindow::reloadSessionStats()
#ifdef Q_OS_MACOS
if (status.payloadDownloadRate > 0)
{
QtMac::setBadgeLabelText(tr("%1/s", "s is a shorthand for seconds")
MacUtils::setBadgeLabelText(tr("%1/s", "s is a shorthand for seconds")
.arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate)));
}
else if (!QtMac::badgeLabelText().isEmpty())
else if (!MacUtils::badgeLabelText().isEmpty())
{
QtMac::setBadgeLabelText("");
MacUtils::setBadgeLabelText("");
}
#else
if (m_systrayIcon)

View file

@ -27,7 +27,6 @@ nogui {
QT += winextras
}
macx {
QT += macextras
LIBS += -lobjc
}
}