Browse Source

Don't use "Qt Mac Extras" module

"Qt Mac Extras" module is removed in Qt6.
adaptive-webui-19844
Vladimir Golovnev (Glassez) 4 years ago committed by Vladimir Golovnev (glassez)
parent
commit
35032d7eed
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 4
      src/CMakeLists.txt
  2. 1
      src/gui/CMakeLists.txt
  3. 3
      src/gui/macutilities.h
  4. 33
      src/gui/macutilities.mm
  5. 10
      src/gui/mainwindow.cpp
  6. 1
      src/src.pro

4
src/CMakeLists.txt

@ -61,9 +61,7 @@ add_subdirectory(base) @@ -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)

1
src/gui/CMakeLists.txt

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

3
src/gui/macutilities.h

@ -42,4 +42,7 @@ namespace MacUtils @@ -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);
}

33
src/gui/macutilities.mm

@ -35,18 +35,21 @@ @@ -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 @@ -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 @@ -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 @@ -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 @@ -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();
}
}

10
src/gui/mainwindow.cpp

@ -48,10 +48,6 @@ @@ -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() @@ -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)

1
src/src.pro

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

Loading…
Cancel
Save