43#ifndef QT_NO_SYSTEMTRAYICON
49#include <QtCore/private/qcore_mac_p.h>
57#include <QtGui/private/qcoregraphics_p.h>
59#warning NSUserNotification was deprecated in macOS 11. \
60We should be using UserNotifications.framework instead. \
61See QTBUG-110998 for more information.
62#define NSUserNotificationCenter QT_IGNORE_DEPRECATIONS(NSUserNotificationCenter)
63#define NSUserNotification QT_IGNORE_DEPRECATIONS(NSUserNotification)
67void QCocoaSystemTrayIcon::init()
69 m_statusItem = [[NSStatusBar.systemStatusBar statusItemWithLength:NSSquareStatusItemLength] retain];
76 m_statusItem.button.action =
@selector(statusItemClicked);
77 [m_statusItem.button sendActionOn:NSEventMaskLeftMouseDown | NSEventMaskRightMouseDown | NSEventMaskOtherMouseDown];
80void QCocoaSystemTrayIcon::cleanup()
86 [NSStatusBar.systemStatusBar removeStatusItem:m_statusItem];
94QRect QCocoaSystemTrayIcon::geometry()
const
99 if (NSWindow *
window = m_statusItem.button.window) {
115void QCocoaSystemTrayIcon::updateIcon(
const QIcon &
icon)
124 const int padding = 4;
125 const int menuHeight = NSStatusBar.systemStatusBar.thickness;
126 const int maxImageHeight = menuHeight - padding;
132 qreal devicePixelRatio =
qApp->devicePixelRatio();
133 const int maxPixmapHeight = maxImageHeight * devicePixelRatio;
140 if (
size.height() <= maxPixmapHeight) {
157 if (devicePixelRatio > 1.0 && selectedSize.
height() < maxPixmapHeight / 2)
158 devicePixelRatio = 1.0;
161 if (
pixmap.height() > maxPixmapHeight)
167 menuHeight * devicePixelRatio,
168 menuHeight * devicePixelRatio);
169 QPixmap fullHeightPixmap(fullHeightSize);
174 r.moveCenter(fullHeightPixmap.rect().center());
177 fullHeightPixmap.setDevicePixelRatio(devicePixelRatio);
179 auto *nsimage = [NSImage imageFromQImage:fullHeightPixmap.toImage()];
181 m_statusItem.button.image = nsimage;
182 m_statusItem.button.imageScaling = NSImageScaleProportionallyDown;
189 if (m_statusItem.menu) {
195 [NSNotificationCenter.defaultCenter addObserver:
m_delegate
196 selector:
@selector(statusItemMenuBeganTracking:)
197 name:NSMenuDidBeginTrackingNotification
203void QCocoaSystemTrayIcon::updateToolTip(
const QString &toolTip)
208 m_statusItem.button.toolTip = toolTip.toNSString();
211bool QCocoaSystemTrayIcon::isSystemTrayAvailable()
const
216bool QCocoaSystemTrayIcon::supportsMessages()
const
222 const QIcon&
icon, MessageIcon,
int msecs)
228 notification.title =
title.toNSString();
229 notification.informativeText =
message.toNSString();
230 notification.contentImage = [NSImage imageFromQIcon:
icon];
235 [
center deliverNotification:[notification autorelease]];
238 NSTimeInterval
timeout = msecs / 1000.0;
239 [
center performSelector:
@selector(removeDeliveredNotification:) withObject:notification afterDelay:
timeout];
243void QCocoaSystemTrayIcon::emitActivated()
245 auto *mouseEvent = NSApp.currentEvent;
249 if (mouseEvent.clickCount == 2) {
261 emit activated(activationReason);
268- (instancetype)initWithSysTray:(QCocoaSystemTrayIcon *)platformSystemTray
270 if ((self = [super
init]))
271 self.platformSystemTray = platformSystemTray;
278 self.platformSystemTray =
nullptr;
282- (
void)statusItemClicked
284 self.platformSystemTray->emitActivated();
287- (
void)statusItemMenuBeganTracking:(NSNotification*)notification
289 self.platformSystemTray->emitActivated();
301 [center removeDeliveredNotification:notification];
302 emit self.platformSystemTray->messageClicked();
DarwinBluetooth::DeviceInquiryDelegate * m_delegate
static QCocoaScreen * get(NSScreen *nsScreen)
The QIcon class provides scalable icons in different modes and states.
QSize actualSize(const QSize &size, Mode mode=Normal, State state=Off) const
Returns the actual size of the icon for the requested size, mode, and state.
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
The QPainter class performs low-level painting on widgets and other paint devices.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height.
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Combined button and popup list for selecting options.
QTextStream & center(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream.
Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum)
Returns the Qt::Button that corresponds to an NSEvent.buttonNumber.
static bool heightCompareFunction(QSize a, QSize b)
#define NSUserNotificationCenter
static QList< QSize > sortByHeight(const QList< QSize > &sizes)
#define NSUserNotification
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLbitfield GLuint64 timeout
[4]
GLuint GLsizei const GLchar * message
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
QFileSelector selector
[1]